diff --git a/AGENTS.md b/AGENTS.md index 1bcb59f76..1c8822dd3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -46,6 +46,30 @@ base. This file holds what you must not get wrong. - After extraction: `python3 xtask/scripts/gen_const_specs.py proofs` and `python3 xtask/scripts/gen_p0.py proofs`, then commit `proofs/Fl4Core/*` with the regenerated P0 files. +## Proof records (extension cost) + +Adding a field to an invariant/keep record must cost O(1) files, not O(construction sites). Rules for `proofs/Fl4ProofsA64`: +The patterns to copy are `DomKeepA.ofKey` (`Stage3SortA`), `SpecGlobA.ofKey` (`FrameA`), `VcpuSpecStepA.ofKey` +(`VcpuDelFrameA`) and `MFrA.ofParts` / `MFrDA.ofParts` (`ScSWrA`); `handoff`-style codemods are compile-driven and idempotent. + +1. A **keep/frame record** (`σ'.f = σ.f` per field, e.g. `DomKeepA`, `SpecGlobA`, `VcpuSpecStepA`) ships with a key + (`DomKeyA σ`, a tuple of the kept components), `ofKey`, `key`, `refl`, `trans`. Call sites use `X.ofKey rfl`, + `X.ofKey (by rw [e])`, `X.ofKey (congrArg XKey e)`, `X.refl _`, `X.trans`; a key is an `abbrev` (a `def` makes the kernel compare the large state + arguments of two key applications first and can hit deep recursion); adding a kept component edits the structure, + the key, `ofKey` and `key` in the one defining file. +2. No anonymous-constructor literal `⟨…⟩` of a record with 4 or more fields outside its defining module: use `{ x with … }`, + `where`, a smart constructor, or `keep_rfl`. Never write `⟨rfl, rfl, rfl, rfl⟩` for a record. +3. Hypotheses that travel together (3 or more parameters in 3 or more signatures) get a bundle structure (`ArchTieA` is the + pattern); a new fact is a new field. No new positional store-fact parameters on `ArchSwFA`-style interfaces. +4. A record extension is a Step-0 item: count its construction sites (`git grep -wc`) and state the expected churn in + files in the line's contract. More than 20 files means the smart-constructor refactor comes first. +5. Context such as the MCS state `m` or `Z` is never a new binder on existing theorems (`m : McState` is bound in about + 800 files): add it as a field of the bundle that already carries it (`MFrA`, `JStage3A`'s nested records). +6. Range/disjunction sets (`DomW`, `SKsA`, `inKs*`) are consumed through membership lemmas, not by hand-counted + `Or.inl`/`Or.inr` chains. +7. A record-extension commit carries no statement changes beyond the record itself: check with + `git diff -U0 | grep -E '^[-+](theorem|lemma|def|structure)'` before pushing. + ## Commands ```sh diff --git a/DESIGN.md b/DESIGN.md index 0848a37e6..8337624bc 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -448,13 +448,23 @@ The proof is staged so each level is useful by itself and later levels build on - Stage 2's [S] scope is the serial core entry after the gate, with one scheduling domain and the single-core IRQ view. Host interrupts use the native fresh-read `IrqHw` contract and `ValidIrqMasks`. Both fresh host and saved guest-exit vectors exclude remote-call IPI 126 and reschedule IPI 127. `VirtExitIrqF` covers an absent saved vector, active and inactive device lines, and saved non-IPI vectors above the device range. The trusted boundary includes entry/exit assembly, hardware guest execution, and the captured vector and VCPU image. Native syscall numbers are −11 through −1 with the trap flag clear. VMEnter (−23) requires a clear trap flag, an agreed enabled backend, and a bound VCPU. The ordinary unknown syscall theorem uses `UnkSys` (out-of-range number or set trap flag), `NoDbgSys` (excludes debug/TLS calls and requires a disabled backend or lack of a VCPU binding for −23), and the spec's ordinary-fault selection guard. Trap vectors are below 256 and follow FL4's zero-extended payload convention. The joint-state, native-capability, IPC and finish premises are listed in the entry and dispatcher modules. - AArch64 P3's delete finaliser hooks for Notification, Endpoint and IrqHandler are [S] scoped to `numNodes = 1` (FL4's `possible_switch_to` branches on the affinity and the current core, the spec's is single-core); under it the waiters' locality follows from the per-step record. The Reply and thread / SchedContext hooks, not yet proved, take the same scope. - AArch64 P3's Reply to a faulted caller (`JSyscallA.replyFaultA`, `P3/Stage3ReplyFaultArmA`; spec `fl4HandleFaultReply`) is [S] scoped to: an `UnknownSyscall` reply shorter than `TRAP_FULL_LENGTH` (37 words), or a fault not sent in the long form (`fault_w1 = 0`, as for every thread with `TRAP_SYSCALLS` clear): the long form's extra registers (x8–x30, TPIDR_EL0) are not in the spec; a caller whose timeout handler is not an endpoint cap; `numNodes = 1`. - - AArch64 P3 Stage 3 (`proofs/Fl4ProofsA64/P3/Stage3*`), proved: the syscall kernel-entry top `kernelEntry_recGA` / `kernelEntry_stage3A` (ghost sets float existentially in the exit record `A64RelS3`), over the dispatch groups CNode, VSpace, SchedContext, TCB, IPC, IRQ, flush, reply, domain, error and VCPU (Untyped: no constructor yet; see the scope-limit bullet) (labels 60–69, at the body and dispatch level: `VcpuScopeA`); the receive family and the combined syscalls (`kernelEntryComb_recGA`, `syscallComb_refinesA`); the preempted exit without the callers' `hPre` premise (`hPre_ofA`, from `HPreEnvA`: `hX` and `T` are derived from the record, and the `Clock` the delete/revoke loop carries to its `Preempted` exit is threaded through `DispPostRA`); and the VM-exit entries end to end (`kernelEntry_runExitA`, `kernelEntry_runVppiA`). The blocking receive with a reply object is proved for a reply object linked to another thread as well (case B of `take_reply`: the link is cancelled first, `Stage3RecvPushCancelA`), so the receive scope no longer assumes an unlinked reply object. The IRQ-control decode's node count is a record fact (`NdOKA.nodes`: the kernel-state word `NUM_NODES` equals the platform's `numNodes`, and every write set keeps it), not a [P] premise over store memory (`IrqPlatA.nodes` is gone). TCB SetIPCBuffer is proved for a zero address (`JSyscallA.setIpcBufZeroA`) and a non-zero one (`JSyscallA.setIpcBufNzA`, `P3/Stage3LiftTcbBufNzA`) on any target thread (the current thread included, with its `reschedule_required`) from a non-device Frame source; a device-frame source or a misaligned or invalid buffer is a decode error, covered by `DecErrSpecPA.thread` (`decErrSpecA`, `sendBodyErrAllA`). - - AArch64 P3 Stage 3, dispatch scope limits ([S]): the scope premise of the syscall tops (`hArm`) holds only for the invocations of `DispScopeA`. A decode that succeeds outside it is not covered, so the tops say nothing about: Untyped Retype / RetypeShared (`UtScopeA` has no constructor yet; first in line for the next stage); TCB Configure, SetSpace, ReadRegisters, WriteRegisters, CopyRegisters, SetTimer, SetHighVSpace, the breakpoint labels and single stepping; SetSchedParams with a changed SC or another handler cap kind; DomainScheduleConfigure / SetStart; ARMASIDControlMakePool; ARMPageDeriveSubframe; the Stage-2 frame map, the page-table map into a high window or Stage-2, and the T2 unmap shrink; Notification send to a bound thread running a VCPU. Their decode `Err` returns are covered (`decErrSpecA`, `ErrScopeA`). + - AArch64 P3 Stage 3 (`proofs/Fl4ProofsA64/P3/Stage3*`), proved: the syscall kernel-entry top `kernelEntry_recGA` / `kernelEntry_stage3A` (ghost sets float existentially in the exit record `A64RelS3`), over the dispatch groups CNode, VSpace, SchedContext, TCB, IPC, IRQ, flush, reply, domain, error and VCPU (Untyped: see the `ut` bullet below) (labels 60–69, at the body and dispatch level: `VcpuScopeA`); the receive family and the combined syscalls (`kernelEntryComb_recGA`, `syscallComb_refinesA`); the preempted exit without the callers' `hPre` premise (`hPre_ofA`, from `HPreEnvA`: `hX` and `T` are derived from the record, and the `Clock` the delete/revoke loop carries to its `Preempted` exit is threaded through `DispPostRA`); and the VM-exit entries end to end (`kernelEntry_runExitA`, `kernelEntry_runVppiA`). The blocking receive with a reply object is proved for a reply object linked to another thread as well (case B of `take_reply`: the link is cancelled first, `Stage3RecvPushCancelA`), so the receive scope no longer assumes an unlinked reply object. The IRQ-control decode's node count is a record fact (`NdOKA.nodes`: the kernel-state word `NUM_NODES` equals the platform's `numNodes`, and every write set keeps it), not a [P] premise over store memory (`IrqPlatA.nodes` is gone). TCB SetIPCBuffer is proved for a zero address (`JSyscallA.setIpcBufZeroA`) and a non-zero one (`JSyscallA.setIpcBufNzA`, `P3/Stage3LiftTcbBufNzA`) on any target thread (the current thread included, with its `reschedule_required`) from a non-device Frame source; a device-frame source or a misaligned or invalid buffer is a decode error, covered by `DecErrSpecPA.thread` (`decErrSpecA`, `sendBodyErrAllA`). + - AArch64 P3 Stage 3, dispatch scope limits ([S]): the scope premise of the syscall tops (`hArm`) holds only for the invocations of `DispScopeA`. A decode that succeeds outside it is not covered, so the tops say nothing about: the preempting Untyped reset (a Retype whose reset runs the chunk loop: `UtScopeA.retypeRst` covers only a reset that never runs it, `sb < 16 ∨ fi = 0`; the preempted reset needs `A64RelPS3` at the hidden `m'`), a device Untyped (`UntypedRetypeShared` is a decode `Err`); the Stage-1 / high-window shrink; ARMASIDControlMakePool (declared cut: the assembly over the ASID-pool heap is not done; its pool bundles `Stage3Pool*` and `MakePoolExpoA` stay on the branch `par/a64-p4-vsxd-h` as groundwork for a post-Stage-4 PR); ARMPageDeriveSubframe. Their decode `Err` returns are covered (`decErrSpecA`, `ErrScopeA`). SetSchedParams with a fault-handler cap other than Null or an endpoint with send ∧ (grant ∨ grant_reply) is not a gap: it is a decode `Err` (`faults::valid_fault_handler` and the spec's `validFaultHandler` agree: `InvalidCapability`), covered by `hErr` (`Stage3DecErrTcb*`). - AArch64 P3 Stage 3, architecture switch (`ArchSwFA`, `P3/ScArchSwA`): the `KERNEL_ROOT` word of the kernel-state block is a record fact (`NdOKA.kroot`: it names the spec's global user VSpace `armUsGlobalVspace`, kept by every write set), and `execIdle` / `execThread` take it, the no-high-window-at-address-0 fact, the run links (`RunLinkA`) and "the current core is core 0" from the record (`ArchTieA`, `JStage3A.archRestA`) instead of quantifying over every store. `ArchSwFA` is therefore single-core (`c = 0`, from `numNodes = 1`): its multicore form belongs to the SMP stage, which must restate the per-core root views. The [P] has a Lean inhabitant for the model architecture: `witArchSwOf : ArchSwFA st AR1` (`P3/A64ArchSwH`, with `P3/A64ArchSwA`–`G`) proves `set_vm_root` and `set_kernel_vm_root` against `threadRootWritesA` / `kernelRootWritesA` on core 0, so the `ArchSwFA` premise is satisfiable. - AArch64 P3 Stage 3, the scheduler premise of the tops (`hGap`, `SchedGapFreeA` at the body's reached record, `P3/Stage3SysTopA`): [S] `oneDomain`, [P] `minAgree` (`fl4MinBudget = MIN_BUDGET`), [P] `ticks` (`ScCfgTimeAgreeA`), [J] `timer` (the schedule-timer inputs and `SniHypA` after `switch_sched_context`, guarded by the run that reaches it: awaken, select the action, switch). - - AArch64 P3 Stage 3 non-vacuity (mechanized): `Wit.wit_send_nonvacuous` (`P3/A64Wit2TopA`) shows that the premises of `kernelEntrySend_recGA` are jointly satisfiable. It exhibits, for a concrete model architecture (`P3/A64Wit2ArchA`) and the w1 boot state, a store, an arch state, a spec state and the ghost sets satisfying every premise of the theorem (`SendEntryHyps` is the theorem's binder list; `wit_top_send` also derives its conclusion there), with `witArchSwOf` as the `ArchSwFA`. Everything is existential except one hypothesis, `OpaqueWA` (witness-world [P]; it is not a premise of any top): facts about `opaque` spec constants that no Lean term proves or refutes (any value of the constant's type is a model; `P3/A64Wit2PlatA` gives the model values): one domain, `maxIRQ = 5375`, GICv2, `numNodes = 1`, `maxTicksToUs = U64::MAX`, kernel WCET 10 µs, 1000 ticks per timer unit, timer unit 1, a 10^9 Hz counter, `fl4MaxPeriodUs = MAX_PERIOD_US`, a monotone raw counter, and two facts that are properties of the witness world rather than of FL4's platform: `irq` (the IRQ oracle only yields the VGIC maintenance line, a non-kernel IRQ) and `hNow` (the spec's clock and the raw counter agree at a state whose last observation is the next raw sample; both oracles are `0`). The witness also discharges `hGap` (`wit2b_hGapA`, proved at any record state). Only the Send / NBSend / Call top has a mechanized witness; the Recv, Comb and VM-exit tops share its platform premises but are not instantiated yet. + - AArch64 P3 Stage 3 non-vacuity (mechanized): `Wit.wit_send_nonvacuous` (`P3/A64Wit2TopA`) shows that the premises of `kernelEntrySend_recGA` are jointly satisfiable. It exhibits, for a concrete model architecture (`P3/A64Wit2ArchA`) and the w1 boot state, a store, an arch state, a spec state and the ghost sets satisfying every premise of the theorem (`SendEntryHyps` is the theorem's binder list; `wit_top_send` also derives its conclusion there), with `witArchSwOf` as the `ArchSwFA`. Everything is existential except one hypothesis, `OpaqueWA` (witness-world [P]; it is not a premise of any top): facts about `opaque` spec constants that no Lean term proves or refutes (any value of the constant's type is a model; `P3/A64Wit2PlatA` gives the model values): one domain, `maxIRQ = 5375`, GICv2, `numNodes = 1`, `maxTicksToUs = U64::MAX`, kernel WCET 10 µs, 1000 ticks per timer unit, timer unit 1, a 10^9 Hz counter, `fl4MaxPeriodUs = MAX_PERIOD_US`, a monotone raw counter, and one fact that is a property of the witness world rather than of FL4's platform: `hNow` (the spec's clock and the raw counter agree at a state whose last observation is the next raw sample; both oracles are `0`). The witness also discharges `hGap` (`wit2b_hGapA`, proved at any record state). The Send witness takes one more witness-world hypothesis, `hI` (the IRQ oracle only yields the VGIC maintenance line, a non-kernel IRQ: the preemption poll never takes an interrupt). The interrupt top has its own witness, `Wit.wit_irq_nonvacuous` (`P3/A64WitIrqA`): at the same store `witS`, with the spec's machine state having line 5 unmasked (A64-Boot's `init_irq_states` leaves lines 0–31 `IRQ_RESERVED`), under `OpaqueWA` and the witness world `hL` (the IRQ oracle yields line 5: incompatible with `hI`, hence two worlds); `wit_top_irq` derives the conclusion there. The two VM-exit tops have a mechanized witness too (`Wit.wit_runexit_nonvacuous`, `Wit.wit_runvppi_nonvacuous`, `P3/A64Wit3TopA`, with `A64Wit3ClockA` / `A64Wit3ExitA` / `A64Wit3RunA`), Tier 0: a VCPU-less, budget-sufficient exit (the thread has no run VCPU, so `complete_run` takes the no-VCPU arm; the `some vc` arm, with its flush, `read_state_to_frame` and register transfer, is not exercised), under `OpaqueWA` and the same `hI` world. The Recv and Comb tops have witnesses too (`Wit.wit_recv_nonvacuous`, `P3/A64WitRcA`; `Wit.wit_comb_nonvacuous`, `P3/A64WitRcCombA`), under `OpaqueWA`: the receive scope is instantiated at its cap-fault arm (`RecvScopeA.capFaultNull`: the CSpace walk of the endpoint cptr fails), and the combined call at a first half that is a no-op (`FirstScopeA.lookupFail`: the REPLY walk fails too) followed by the same receive arm. `w1` has no endpoint or notification, so no send / receive / wait-block arm is witnessed yet (Tier 1). + - AArch64 P4 (`par/a64-p4-int`), tcbcfg / tcbsv / tcbdom / vsxc: **TCB Configure and SetSpace** (null or endpoint fault handler, native or Stage-2 roots, zero or non-zero IPC buffer; `Stage3LiftTcbSpaceA`, `Stage3InvSpecTcbSpaceA`, `Stage3InvSpecTcbCfgA`; `TcbScopeA.setSpace` / `configureBufZero` / `configureBuf`) and their `Err Preempted` outcomes (`TcbPreScopeA`, `Stage3DispTcbPreA`; every TCB cap-write arm, including SetSchedParams with a changed SC, exports `PreExitA` and `Clock`) are proved, so the cap-write Preempted hole is closed; `InvSpecA` for the TCB arms now takes the outcome `eo` and `TcbDoneA done eo` (`InvSpecA.ofTcbNilE`). **TCB SetTimer**, the breakpoint and single-step labels (decode `Err`), and **Notification send to a thread running a VCPU** (`IpcScopeA.signalRunningVm`) are covered (tcbsv). **DomainScheduleConfigure / SetStart** are covered by `DomScopeA` (`Stage3DomSchedA`, via the `QKeepN` lift; tcbdom). vsxc replaces the Err-side `∀ cap` premises of `DecErrSpecPA.archVs` / `sendBodyErrAllA` by per-slot `PtMapSiteA` / `FrMapSiteA` / `FrSubSiteA` and adds `pt_map_mappedA`. + - AArch64 P4 `vsxa`: the **Stage-2 frame map** is proved (`VsScopeA.frameMapS2`; `Stage3ArmFrMapS2A`, `Stage3MapS2UnmA`, `Stage3PinVsS2A`, `Stage3T3ArmS2A`). + - AArch64 P4 `vsxb` / `vsxc`: the **page-table map into a high window** (`VsScopeA.ptMapHi`, `Stage3ArmPtMapHiA`) and **into Stage-2** (`VsScopeA.ptMapS2`, `Stage3ArmPtMapS2A`) and the **T2 unmap shrink** (`JStage3A.ptUnmapT2A`, `Stage3ArmPtUnmT2A`, `Stage3T3ArmT2A`: the Stage-2 table leaves the ghost `T2`) are proved; `ptUnmap_runA` / `ptUnmapBodyA` select the shrink arm for `ptr ∈ Z.T2` with the selector `hT2`. + - AArch64 P4, [J] case premises (record-invariant candidates): `PtUniqT2A` (`Stage3ArmPtUnmT2A`): at the restart state of an `ARMPageTableUnmap` of a Stage-2 table `ptr`, a valid table descriptor naming `ptr` that is reachable from an active Stage-2 root is zeroed by the unmap run ("a mapped table is referenced by exactly one reachable entry"); it is guarded by the unmap run (`vspace.unmap_page_table … = ok (s2, a2)`) and by Stage-2 reachability, and is carried by `ptUnmapBodyA.hSel → ptUnmap_runA.hT2` for `ptr ∈ Z.T2`. Its companion root-kind fact in the same selector: the ASID of the cap names a root of a kind other than Stage-1 (`asidRootKind σ asid = some k ∧ k ≠ .stage1`). Both are discharged by a record invariant in a later stage. + - AArch64 P4 `tcbregr`: **TCB ReadRegisters** is proved for Send and Call, with and without suspend (`Stage3TcbReadRegsA`, `Stage3TcbReadRegsSuspA`, `Stage3TcbReadCallSpecA`, `Stage3TcbReadCallSuspA`, `TcbInvokeReadCallFineA`; `suspendMidA`); `JSyscallA.tcbSuspendA` is kept as a corollary with the same statement. + - AArch64 P4 `tcbregw`: **TCB WriteRegisters** (with or without resume) and **CopyRegisters** (registers, restart bit, suspend bit; the destination may be the caller) are proved (`Stage3TcbRegWriteArmA`, `Stage3TcbRegWriteFrA`, `TcbWriteBridgeA`). + - AArch64 P4 `ut`: **Untyped Retype is proved at the record**, for every object type including TCB creation, with a CDT child (`UtScopeA.retype`) and without one (`UtScopeA.retypeRst`: the non-preempting reset, whose chunk loop never runs: `sb < 16 ∨ fi = 0` on one core) (`JSyscallA.untypedRetypeA`, `untypedRetypeRstA`, `Stage3UtArmA`, `Stage3DispUtA`, `UtKeepA`, `UtKeepCurA`, `UtRt*A`, `UtResetNoErrA`, `McGrowUtA`). The entry relation carries the mc-state of the reached state as a hidden `m'` (R1: `A64RelS3at`, `McGrowA m m'`; `hGap` is stated `∀ m'` guarded by the reached run), because Retype grows it (a Retype that creates a TCB changes `McState.tcbAffinity`). **R1 weakens the conclusion of the seven entry tops**: `KExitA` is now `∃ m', McGrowA m m' ∧ KExitAt … m'`, and `McGrowA` keeps only `curCore`, `idleThreadOf`, `idleScOf` and `WF`, so the next entry's record holds at a grown multi-core view, not at the entry's `m`. Premises: [P] `ArchTotal`, `ArchPlat`, `A64FrameMasks`, `hvi`/`hvirt`, `hfan` (`retypeFanOutLimit = 256`), `hVP`, `hKt`/`hK0`, the Stage-2 IPA width, `resetChunkBits = 16`, the post-reset barriers; [S] the reset never runs the chunk loop and one core; [J] `JSyscallA`. Premise-level witness: `wit_ut_prems` (`P3/A64WitUtA`): the RAM Untyped slot `53` of the Send witness state with free index 0 and no CDT child, `numNodes = 1`, `hCs`, `hIpa`, `hchunk`, `hS`; the message-dependent fields (`hlbl`, `hargs`, `hex`, `hdecS`, `hpin`) are not instantiated (they need a witness world with an UntypedRetype message: backlog), so there is no end-to-end Untyped `*_nonvacuous` theorem. + - AArch64 P4 `tcbsched`: **SetSchedParams** is proved for a changed scheduling context as well (`P3/Stage3TcbSchedScA`, `Stage3TcbSchedFrameA`, `Stage3TcbSchedMidA`, `Stage3TcbSchedCurA`, `Stage3TcbPrioCurA`): `thread_control_sched` unbinds the target's SC (`JStage3A.sspUnbindA`) or binds the new one (`sspBindA`) after the fault handler, `set_mcp` and `set_priority`, for a target other than the caller and for the caller, with a null fault handler or an endpoint one. Still outside the dispatch scope: another handler cap kind. + - AArch64 P4 (`par/a64-p4-int`), TCB capability installs: `install_tcb_cap` is proved at the record for a TCB slot `i ≠ 2` (CSpace root, VSpace root, fault handler, timeout handler, HighVSpace; `P3/Stage3TcbInstallA`: `JStage3A.installTcbCapA`, `TcbMidA.installTcbCapA`, `tcbInstallCap_preemptedA`; the CNode insert variant `capInsertTcbSlotGA`), and **TCB SetHighVSpace** is proved at the record (`P3/Stage3LiftTcbHighA`: `JSyscallA.setHighVSpaceA`, the `TcbScopeA` arms `setHighVSpaceNull` / `setHighVSpaceLive`; the target may be the caller) for a `Null` source or a mapped `HighVSpace` window whose ASID still names it; the arm does not lift the `Err` returns before the deletion. + - AArch64 P3 Stage 3, VM-exit tops (`kernelEntry_runExitA`, `kernelEntry_runVppiA`): they cover **budget-sufficient exits only** ([S]). `VcpuExitInA.hScPost` assumes, at the exit's post state, an active current SC with a sufficient head refill (`getScRefillSufficient … = true`), guarded by the run: the FL4 `vcpu.complete_run` that produced the concrete state, `updateTimeStamp σ = σ1` and `DrA σ1 σ2`. A guest run that exhausts the budget (the charge branch of `check_budget`) is outside the tops. The concrete pre-state `(sp, ap)` of that `complete_run` is not tied to the time-stamped `(s1, a1)` in the field (for `runVppi` the VPPI masking sits between them); the spec side is pinned. - AArch64 P3 Stage 3, declared Stage-4 limits ([S4]): the guest-resume `finish` (`hNative` / `hNat`: an `ARMVCPU_Run` that resumes the guest, so the caller stays current in `runningVM`, is outside the top), and the guest entries `vgic`, `vppi`, `vcpuExit` and `vcpuFault`, which are deferred to the S4 guest-lifecycle follow-up. - - AArch64 P3 Stage 3, still open (work in progress, not limits): the last premise duplication in the top assembly (the interrupt entry's IRQ set against the preempted exit's, once the interrupt top exists). The preempted exit takes its platform facts from the entry's `FaultEnvA` (`ExitPlatA`), its timeout-send premise (`SendPA`) is guarded by the run that reaches the preempted state, and the polled line's `reserved` clause is a [P] clause of `PollAgreeA` (fl4-kernel#154). + - AArch64 P4 `irqtop`, the interrupt kernel-entry top (`P3/Stage3KEntryIrqBodyA`, `P3/Stage3KEntryIrqTopA`): `kernelEntryIrq_recGA` is `kernelEntry_recGA` at `KEventA.interrupt`: FL4's `handle_interrupt_entry` (`update_timestamp`, `check_budget`, `handle_interrupt`, `finish`) refines the spec's `call_kernel` for an interrupt (`fl4CallKernel_interruptA`: `fl4AcceptedIrqBody (fl4MaybeHandleInterrupt false)`, then `fl4Finish`), and the next entry's record holds (`KExitA`). The body (`interruptBodyA`) ends in `A64RelS3` with `BodyOKA` (`JStage3A.irqBudgetEndA`, `take_ofA`'s transport). The IRQ set is one record, `IrqEnvA` (`IrqArchA` at the trivial machine relation, `maxIRQ = 5375`), shared by the preempted exit (`HPreEnvA.irq`) and this top; the exit's other platform facts come from `ExitPlatA`, its timeout-send premise `SendPA` is guarded by the run that reaches the preempted state, and the polled line's `reserved` clause is a [P] clause of `PollAgreeA` (losfair/FL4#154). New named premises: [P] the oracle agreement `OracleIrqA` (the line `entry.rs` `classify_irq_under_gate` acknowledged is the spec's `getActiveIRQ false`, with [J] the line unmasked), [P] `EntryIrqAgreeA` (the accepted line is neither the VGIC maintenance interrupt nor the virtual timer; it replaces the [S] `reserved` at the entry), [J] `line` (`IrqLineBaseA`, guarded by the budget prefix), `hct` (a resuming current thread is in an activatable state), `hsch` (an exhausted head only at a schedulable current thread: an idle current thread's head is sufficient), `hCharge` (the exhausted-budget branch, as the fault entries'). Not covered by this top: an interrupt that `entry.rs` classifies as spurious or unsupported (no kernel entry runs), the VGIC maintenance and virtual-timer PPI entries and an interrupt taken while a guest-run caller is current ([S4]), the multicore local timer path (`numNodes = 1`), and a notification signalled by an IRQ to a bound thread running a VCPU (`JStage3A.sigVmA`). The `FAULT_IP` write of `fl4_entry` precedes the top (it is the saved trap state of the record). - x86 VM Stage 3 replaces Stage 2's arm premises. `VEAnyX.outerS3` is one theorem over the nine concrete entries (`S3Ev`), from `VEAnyX` and the event's `S3Pre` to an extended-spec outcome at `VEAnyX`. Its syscall case, `VmEptState.kernel_entryS3`, takes the start record `StartS3` in place of `KEntryArmsV`, `VDispNativeAt` and the finish premises; the other cases take no `EventFinishVE` / `VcpuExitFinishVE`. The Stage 2 theorems are kept. The extended spec's FrameBatch (`performFrameBatchWith`) is parameterized by the deletion it uses, and the VM-aware step uses `capDeleteVF`. - Stage 3's remaining premises. [J] `StartS3`: `X : SInvXV` (the native carried bundle without `NativeScopeS`), current thread not idle, `SpecIoPorts`, `SpecUtZ`, `DevRangeS`, `GpmOutV`, `UtInv''`, `RV`, `IdleVtS`; `S3Fault` and the scheduler, domain, FPU-owner, idle and clock facts of the other events. [P] `StartS3.air` (`ArchIrqRel`), the platform arguments of `outerS3` (including `FpuImplDet`, `FpuWriteDet`, `StoreExt`) and the hardware arguments of each event. [S] `StartS3.core` (`SelectedCoreScope` for the invoked capability of the current thread on the executing core: SchedControl names that core, Untyped only on core 0), and Stage 2's event guards above. - Stage 3 non-vacuity: `JBootQ.VWit.witness_schedControl` and `witness_untyped` (`P3/VmWitS3`) give a concrete store, arch and spec state satisfying `VEAnyX ∧ S3Pre` for `SysCall` on a SchedControl cap and `SysNBSendWait` on an Untyped cap, with a `runningVM` TCB and its VCPU in the CSpace. The quantified fields `air` and `core` are not vacuous there: a dispatch pair exists (`w_dispatch`: the `FaultIP` write and a passing `budget_ok` on the FL4 side, a passing budget check on the spec side), and at it the invoked slot is looked up and decodes to the SchedControl / Untyped cap and `SelectedCoreScope` holds (`w_core_exercised`). The witness clock sits at the cap of `getCurrentTime` (`tW = -(getCurrentTime_buffer + 1)`), so the entry's time read is `tW` whatever the opaque `timeOracle` gives and the consumed time is 0; with the clock at 0 the budget check would depend on `timeOracle 1`. `air` asks for at least one IOAPIC (`ArchIrqRel`, as real x86): the witness arch `warV` is `warI1` (one IOAPIC of 24 pins, as the spec's `init_arch_state`) with the platform's `virtualization` code and VMX capability words. Premises: [P] `virtKind = .vmx ∨ .svm` (a running guest forces a backend) and [P] one scheduling domain. [J] `SInvXV` is an entry premise, as `SInvX` was; the witness satisfies it. diff --git a/README.md b/README.md index 79676e1be..eecfed4ea 100644 --- a/README.md +++ b/README.md @@ -248,13 +248,13 @@ guest's hardware writes included, so the runtime's executions from `w0` / `w1` are serializable (`w0_serializable_impl`, `w1_serializable_impl`), from four memory-model and IPI premises. `cargo xtask gate` checks the x86_64 extraction; the AArch64 one is extracted and checked on its own -(`lake build Fl4ProofsA64`). AArch64 P3 Stage 3 proves the syscall -kernel-entry top (`kernelEntry_recGA`), the receive family and combined -syscalls, the preempted exit and the VM-exit entries `runExit` / `runVppi`; -the guest-resume `finish` and the other guest entries are declared Stage-4 -limits, `ArchSwFA` is single-core (the SMP stage restates it per core), and -the premises of the Send top are shown jointly satisfiable (`wit_send_nonvacuous`, -under the witness-world hypothesis `OpaqueWA`) (DESIGN.md §9). P3 also covers the x86_64 VCPU/EPT +(`lake build Fl4ProofsA64`). AArch64 P3 Stages 3 and 4 prove the syscall +kernel-entry top (`kernelEntry_recGA`) over the CNode, VSpace (incl. the Stage-2 and high-window maps and the T2 unmap shrink), +SchedContext, TCB (installs, SetSpace, Configure, SetSchedParams, SetTimer, Read-, Write- and CopyRegisters), IPC, IRQ, Domain, VCPU and Untyped (Retype, TCB creation and the non-preempting reset) groups, +the receive family and combined syscalls, the preempted exit, the interrupt entry (`kernelEntryIrq_recGA`) and the VM-exit entries `runExit` / `runVppi`; +the preempting Untyped reset, a device Untyped, DeriveSubframe, ASIDControl MakePool, the Stage-1 / high-window shrink, the guest-resume `finish` and the other guest entries are declared limits, +`ArchSwFA` is single-core (the SMP stage restates it per core), and +the premises of every top are shown jointly satisfiable (`wit_send_nonvacuous`, `wit_recv_nonvacuous`, `wit_comb_nonvacuous`, `wit_runexit_nonvacuous` / `wit_runvppi_nonvacuous` (a VCPU-less exit), `wit_irq_nonvacuous`, under the witness-world hypotheses `OpaqueWA` and the IRQ-oracle fact of each; the Untyped arm has a premise-level witness) (DESIGN.md §9). P3 also covers the x86_64 VCPU/EPT extension on a joint VM state (`VmEptState`): retype and untyped, the EPT syscalls through the dispatcher, the VCPU report and detach, the IO-port cap's owner, revoke and delete, capability delete of every cap diff --git a/proofs/Fl4ProofsA64.lean b/proofs/Fl4ProofsA64.lean index 8696b012b..7892d5c2d 100644 --- a/proofs/Fl4ProofsA64.lean +++ b/proofs/Fl4ProofsA64.lean @@ -1684,6 +1684,10 @@ import Fl4ProofsA64.P3.Stage3ArmFrMapA import Fl4ProofsA64.P3.Stage3MapExtA import Fl4ProofsA64.P3.Stage3MapExtCoreA import Fl4ProofsA64.P3.Stage3ArmFrMapHiA +import Fl4ProofsA64.P3.Stage3MapS2UnmA +import Fl4ProofsA64.P3.Stage3ArmFrMapS2A +import Fl4ProofsA64.P3.Stage3T3ArmS2A +import Fl4ProofsA64.P3.Stage3PinVsS2A import Fl4ProofsA64.P3.Stage3ArmPtUnmUA import Fl4ProofsA64.P3.Stage3ArmPtUnmMA import Fl4ProofsA64.P3.Stage3ArmPtUnmXA @@ -1691,6 +1695,20 @@ import Fl4ProofsA64.P3.Stage3TcbSuspFrA import Fl4ProofsA64.P3.Stage3TcbRestartFr2A import Fl4ProofsA64.P3.Stage3TcbSuspResA import Fl4ProofsA64.P3.Stage3TcbRegsFrA +import Fl4ProofsA64.P3.TcbWriteBridgeA +import Fl4ProofsA64.P3.Stage3TcbRegWriteFrA +import Fl4ProofsA64.P3.Stage3TcbRegWriteA +import Fl4ProofsA64.P3.Stage3TcbRegWriteArmA +import Fl4ProofsA64.P3.Stage3TcbRegResumeA +import Fl4ProofsA64.P3.Stage3TcbRegCopyRsA +import Fl4ProofsA64.P3.Stage3TcbRegCopySelfA +import Fl4ProofsA64.P3.Stage3TcbRegCopySuspA +import Fl4ProofsA64.P3.Stage3TcbRegCopyA +import Fl4ProofsA64.P3.Stage3TcbRegCopyArmA +import Fl4ProofsA64.P3.Stage3TcbRegInvA +import Fl4ProofsA64.P3.Stage3TcbRegMidA +import Fl4ProofsA64.P3.Stage3InvSpecTcbRegsA +import Fl4ProofsA64.P3.Stage3InvSpecTcbRegsWA import Fl4ProofsA64.P3.Stage3CapVsFrameGA import Fl4ProofsA64.P3.Stage3VsTyPostA import Fl4ProofsA64.P3.Stage3ArmAssignA @@ -1755,6 +1773,10 @@ import Fl4ProofsA64.P1.S1aStepPool import Fl4ProofsA64.P3.Stage3FinA import Fl4ProofsA64.P3.Stage3T3ArmsA import Fl4ProofsA64.P3.Stage3T3ArmHiA +import Fl4ProofsA64.P3.Stage3ArmPtMapHiA +import Fl4ProofsA64.P3.Stage3T3ArmPtHiA +import Fl4ProofsA64.P3.Stage3ArmPtMapS2A +import Fl4ProofsA64.P3.Stage3T3ArmPtS2A import Fl4ProofsA64.P3.Stage3T3DecEqA import Fl4ProofsA64.P3.Stage3T3ArmCoreA import Fl4ProofsA64.P3.Stage3T3ArmsCnA @@ -1845,6 +1867,8 @@ import Fl4ProofsA64.P3.Stage3TcbUnbindA import Fl4ProofsA64.P3.Stage3TcbMcpA import Fl4ProofsA64.P3.Stage3TcbBindA import Fl4ProofsA64.P3.Stage3DispTcbA +import Fl4ProofsA64.P3.Stage3TcbPreExitA +import Fl4ProofsA64.P3.Stage3DispTcbPreA import Fl4ProofsA64.P3.Stage3CancelLoopA import Fl4ProofsA64.P3.Stage3CancelBadgedA import Fl4ProofsA64.P3.Stage3SigWakeFootA @@ -1949,6 +1973,12 @@ import Fl4ProofsA64.P3.UtApSys2A import Fl4ProofsA64.P3.UtAsmAllA import Fl4ProofsA64.P3.UtAsmAll0A import Fl4ProofsA64.P3.UtRtRecA +import Fl4ProofsA64.P3.UtRtExA +import Fl4ProofsA64.P3.UtRtLastA +import Fl4ProofsA64.P3.UtKeepA +import Fl4ProofsA64.P3.McGrowUtA +import Fl4ProofsA64.P3.UtRtNewPlaceA +import Fl4ProofsA64.P3.Stage3UtArmA import Fl4ProofsA64.P3.UtRtRecTopA import Fl4ProofsA64.P1.S1aRtTopK import Fl4ProofsA64.P3.UtDecRecA @@ -1970,6 +2000,10 @@ import Fl4ProofsA64.P3.UtPpScA import Fl4ProofsA64.P3.UtPpTsA import Fl4ProofsA64.P3.UtPpHookA import Fl4ProofsA64.P3.UtRtResetPpA +import Fl4ProofsA64.P3.UtKeepCurA +import Fl4ProofsA64.P3.UtResetNoErrA +import Fl4ProofsA64.P3.UtRtResetNpA +import Fl4ProofsA64.P3.A64WitUtA import Fl4ProofsA64.P3.UtClrA import Fl4ProofsA64.P3.UtChunkA import Fl4ProofsA64.P3.UtMakePoolA @@ -1978,6 +2012,7 @@ import Fl4ProofsA64.P3.UtResetA import Fl4ProofsA64.P1.S1aRtTopRst import Fl4ProofsA64.P3.UtRtRecRstA import Fl4ProofsA64.P3.UtDecRecRstA +import Fl4ProofsA64.P3.UtDecExA import Fl4ProofsA64.P3.UtApRec5A import Fl4ProofsA64.P3.UtRec6KeepA import Fl4ProofsA64.P3.UtVcInitA @@ -2173,6 +2208,21 @@ import Fl4ProofsA64.P3.VcpuDelHookA import Fl4ProofsA64.P3.VcpuDelFinHookA import Fl4ProofsA64.P3.Stage3DelAsmTopA import Fl4ProofsA64.P3.Stage3TcbDelStepA +import Fl4ProofsA64.P3.Stage3TcbChainIfaceA +import Fl4ProofsA64.P3.Stage3TcbChainA +import Fl4ProofsA64.P3.Stage3TcbChainStartA +import Fl4ProofsA64.P3.Stage3TcbSetSpaceSelA +import Fl4ProofsA64.P3.Stage3TcbConfigSelA +import Fl4ProofsA64.P3.Stage3TcbChainHelpA +import Fl4ProofsA64.P3.Stage3DecErrTcbValA +import Fl4ProofsA64.P3.Stage3LiftTcbSpaceA +import Fl4ProofsA64.P3.Stage3InvSpecTcbSpaceA +import Fl4ProofsA64.P3.Stage3InvSpecTcbCfgA +import Fl4ProofsA64.P3.Stage3InvSpecTcbBufDecA +import Fl4ProofsA64.P3.Stage3InvSpecTcbPerfA +import Fl4ProofsA64.P3.Stage3InvSpecTcbPreA +import Fl4ProofsA64.P3.Stage3LiftTcbCfgFrontA +import Fl4ProofsA64.P3.Stage3LiftTcbCfgA import Fl4ProofsA64.P3.Stage3TcbBufStepA import Fl4ProofsA64.P3.Stage3LiftTcbBufA import Fl4ProofsA64.P3.Stage3LiftTcbTimeoutA @@ -2182,6 +2232,7 @@ import Fl4ProofsA64.P3.Stage3CapInsertBufA import Fl4ProofsA64.P3.Stage3TcbDelGA import Fl4ProofsA64.P3.Stage3TcbBufStepsA import Fl4ProofsA64.P3.Stage3TcbReschedA +import Fl4ProofsA64.P3.Stage3TcbBufMidA import Fl4ProofsA64.P3.Stage3LiftTcbBufNzA import Fl4ProofsA64.P3.Stage3LiftTcbTimeoutNnA import Fl4ProofsA64.P3.Stage3P1StepA @@ -2190,6 +2241,14 @@ import Fl4ProofsA64.P3.Stage3TcbPrioAnyA import Fl4ProofsA64.P3.Stage3LiftTcbSspA import Fl4ProofsA64.P3.Stage3InsP1A import Fl4ProofsA64.P3.Stage3LiftTcbSspEpA +import Fl4ProofsA64.P3.Stage3TcbInstallA +import Fl4ProofsA64.P3.Stage3LiftTcbHighA +import Fl4ProofsA64.P3.Stage3InvSpecTcbHighA +import Fl4ProofsA64.P3.Stage3TcbSchedFrameA +import Fl4ProofsA64.P3.Stage3TcbPrioCurA +import Fl4ProofsA64.P3.Stage3TcbSchedCurA +import Fl4ProofsA64.P3.Stage3TcbSchedMidA +import Fl4ProofsA64.P3.Stage3TcbSchedScA import Fl4ProofsA64.P3.Stage3LiftFlushA import Fl4ProofsA64.P3.Stage3DispFlushA import Fl4ProofsA64.P3.Stage3DispIrqA @@ -2199,6 +2258,7 @@ import Fl4ProofsA64.P3.Stage3LiftTestClearA import Fl4ProofsA64.P3.Stage3DispReplyA import Fl4ProofsA64.P3.Stage3LiftDomainA import Fl4ProofsA64.P3.Stage3DispDomA +import Fl4ProofsA64.P3.Stage3DomSchedA import Fl4ProofsA64.P3.Stage3ErrPreA import Fl4ProofsA64.P3.Stage3ErrKeepA import Fl4ProofsA64.P3.Stage3ErrKeep2A @@ -2277,6 +2337,7 @@ import Fl4ProofsA64.P3.Stage3DecErrTcbRegsA import Fl4ProofsA64.P3.Stage3DecErrTcbAuthA import Fl4ProofsA64.P3.Stage3DecErrTcbPacA import Fl4ProofsA64.P3.Stage3DecErrTcbBufA +import Fl4ProofsA64.P3.Stage3DecErrTcbRootsCoreA import Fl4ProofsA64.P3.Stage3DecErrTcbRootsA import Fl4ProofsA64.P3.Stage3DecErrTcbSpaceA import Fl4ProofsA64.P3.Stage3DecErrTcbA @@ -2305,6 +2366,10 @@ import Fl4ProofsA64.P3.Stage3T3ArmsVcpuRunA import Fl4ProofsA64.P3.Stage3VcpuExitA import Fl4ProofsA64.P3.Stage3VcpuExitWireA import Fl4ProofsA64.P3.Stage3SignalVmA +import Fl4ProofsA64.P3.Stage3TcbDebugLabelsA +import Fl4ProofsA64.P3.Stage3TcbTimerRecA +import Fl4ProofsA64.P3.Stage3TcbTimerA +import Fl4ProofsA64.P3.Stage3InvSpecTcbTimerA import Fl4ProofsA64.P3.Stage3SigVmArmA import Fl4ProofsA64.P3.Stage3YieldBodyA import Fl4ProofsA64.P3.Stage3RecvScopeA @@ -2329,6 +2394,12 @@ import Fl4ProofsA64.P3.A64Wit2BudgetA import Fl4ProofsA64.P3.A64Wit2EntryA import Fl4ProofsA64.P3.A64Wit2TierA import Fl4ProofsA64.P3.A64Wit2TopA +import Fl4ProofsA64.P3.A64Wit3ClockA +import Fl4ProofsA64.P3.A64Wit3ExitA +import Fl4ProofsA64.P3.A64Wit3RunA +import Fl4ProofsA64.P3.A64Wit3TopA +import Fl4ProofsA64.P3.A64WitRcA +import Fl4ProofsA64.P3.A64WitRcCombA import Fl4ProofsA64.P3.Stage3DomIpiA import Fl4ProofsA64.P3.A64ArchSwA import Fl4ProofsA64.P3.A64ArchSwB @@ -2338,3 +2409,14 @@ import Fl4ProofsA64.P3.A64ArchSwE import Fl4ProofsA64.P3.A64ArchSwF import Fl4ProofsA64.P3.A64ArchSwG import Fl4ProofsA64.P3.A64ArchSwH +import Fl4ProofsA64.P3.Stage3KEntryIrqBodyA +import Fl4ProofsA64.P3.Stage3KEntryIrqTopA +import Fl4ProofsA64.P3.A64WitIrqA +import Fl4ProofsA64.P3.Stage3TcbReadRegsA +import Fl4ProofsA64.P3.Stage3InvSpecTcbRegsA +import Fl4ProofsA64.P3.TcbInvokeReadCallFineA +import Fl4ProofsA64.P3.Stage3TcbReadCallSpecA +import Fl4ProofsA64.P3.Stage3TcbReadCallA +import Fl4ProofsA64.P3.Stage3SuspOffQA +import Fl4ProofsA64.P3.Stage3TcbReadRegsSuspA +import Fl4ProofsA64.P3.Stage3TcbReadCallSuspA diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2ArchA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2ArchA.lean index 3f136a70e..b014beb20 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2ArchA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2ArchA.lean @@ -134,6 +134,10 @@ structure OpaqueWA : Prop where gic : kernelConfig.configArmGicV3 = false /-- `numNodes = 1` (`opaque fl4A64Platform`; [S]) -/ nodes : fl4A64Platform.numNodes = 1 + /-- the reset chunk size is 16 bits (`opaque kernelConfig`; the Untyped reset arm's `hchunk`) -/ + chunk : resetChunkBits = 16 + /-- the Stage-2 IPA width is 40 (`opaque fl4A64Platform`; `ar1_plat`'s width; the Untyped reset arm's `hIpa`) -/ + ipaBits : fl4A64Platform.s2IpaBits = 40 /-- `maxTicksToUs = U64::MAX` (`opaque maxTicksToUs`) -/ max : maxTicksToUs = core.num.U64.MAX.bv /-- kernel WCET 10 µs (`opaque timeConsts`; FL4's build) -/ @@ -146,8 +150,6 @@ structure OpaqueWA : Prop where freq : fl4TimerFrequencyHz = 1000000000 /-- `fl4MaxPeriodUs = MAX_PERIOD_US` (`opaque fl4MaxPeriodUs`) -/ period : fl4MaxPeriodUs = MAX_PERIOD_US - /-- the IRQ oracle only yields the VGIC maintenance line, a non-kernel IRQ (`opaque irqOracleAx`; witness world) -/ - irq : ∀ n, irqOracle n = irqVGICMaintenance /-- the raw counter oracle is monotone (`opaque fl4RawCounterOracle`) -/ hC : ∀ i, fl4RawCounterOracle i ≤ fl4RawCounterOracle (i + 1) /-- the spec's clock and the raw counter agree at a state whose last observation is the next raw sample (`opaque diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2EntryA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2EntryA.lean index a231e79a9..dea8c12d5 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2EntryA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2EntryA.lean @@ -22,9 +22,9 @@ noncomputable section open Fl4ProofsA64.P3.Wit2 (WA AR1) -variable {r now mt sl : U64} {uw : U64 → U64} +variable {c0 r now mt sl : U64} {uw : U64 → U64} -local notation "S2" => witS r now mt sl uw +local notation "S2" => witSc c0 r now mt sl uw local notation "RT" => (bwv RTb) theorem bwr_self (s : BS) (b : U64) : bL.wr s b (bL.mem s b) = s := by @@ -34,7 +34,7 @@ theorem bwr_self (s : BS) (b : U64) : bL.wr s b (bL.mem s b) = s := by rw [Function.update_eq_self] /-- Any register word of the root TCB. -/ -theorem wit_regWord (i : U64) (hi : i.val < 37) : bL.mem S2 (regWA RT i) = witRtW (256 + 8 * i.val) := by +theorem wit_regWord (i : U64) (hi : i.val < 37) : bL.mem S2 (regWA RT i) = witRtW c0 (256 + 8 * i.val) := by have v : (regWA RT i).val = RTb + (256 + 8 * i.val) := by have h := Endp.regA_val (t := RT) (i := i) rtAddr hi rw [vRT] at h @@ -51,7 +51,7 @@ theorem wit_faultIP_id : rw [wit_regWord _ (by simp)] simp [witRtW, rtW] have e2 : bL.mem S2 (Endp.regA RT layout.reg.FAULT_IP) = 4194300#u64 := by - have := wit_regWord (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) layout.reg.FAULT_IP (by simp) + have := wit_regWord (c0 := c0) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) layout.reg.FAULT_IP (by simp) exact this.trans (by simp [witRtW]) have e3 : core.num.U64.wrapping_sub (bwv 4194304) 4#u64 = 4194300#u64 := by first | decide | rfl @@ -68,16 +68,16 @@ def wTick : Fl4SpecA64.Ticks := /-- The witness's `now`: the stored `CUR_TIME` and the last observation are the next raw sample. -/ def wNow : U64 := ⟨wTick⟩ -theorem wit_rawNext {mt sl : U64} {uw : U64 → U64} : - Sched.rawNextA (witSA wNow mt sl uw).machineState = wTick := rfl +theorem wit_rawNext {c0 mt sl : U64} {uw : U64 → U64} : + Sched.rawNextA (witSAc c0 wNow mt sl uw).machineState = wTick := rfl -theorem wit_counterStep {mt sl : U64} {uw : U64 → U64} : Sched.CounterStepA (witSA wNow mt sl uw) := by +theorem wit_counterStep {c0 mt sl : U64} {uw : U64 → U64} : Sched.CounterStepA (witSAc c0 wNow mt sl uw) := by unfold Sched.CounterStepA exact BitVec.le_refl _ -theorem wit_hNow (O : Wit2.OpaqueWA) {mt sl : U64} {uw : U64 → U64} : - Fl4SpecA64.fl4ReadRawCounter (witSA wNow mt sl uw).machineState = - Fl4SpecA64.getCurrentTime (witSA wNow mt sl uw).machineState := +theorem wit_hNow (O : Wit2.OpaqueWA) {c0 mt sl : U64} {uw : U64 → U64} : + Fl4SpecA64.fl4ReadRawCounter (witSAc c0 wNow mt sl uw).machineState = + Fl4SpecA64.getCurrentTime (witSAc c0 wNow mt sl uw).machineState := O.hNow _ rfl /-! ## The sufficient head refill -/ @@ -89,14 +89,14 @@ theorem sc_ne_rt : specPtr (bwv SCb) ≠ specPtr (bwv RTb) := fun h => by norm_num /-- **The head refill is sufficient** at every state the timestamp reaches from the witness. -/ -theorem wit_hsuf (O : Wit2.OpaqueWA) {mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) +theorem wit_hsuf (O : Wit2.OpaqueWA) {c0 mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) {σ1 : Fl4SpecA64.State Unit} - (e : Fl4SpecA64.fl4UpdateTimestamp (Z := Unit) (witSA wNow mt sl uw) = ({((), σ1)}, False)) : + (e : Fl4SpecA64.fl4UpdateTimestamp (Z := Unit) (witSAc c0 wNow mt sl uw) = ({((), σ1)}, False)) : Fl4SpecA64.fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(true, σ1)}, False) := by - have eτ := Sched.fl4UpdateTimestamp_eqA (witSA wNow mt sl uw) + have eτ := Sched.fl4UpdateTimestamp_eqA (witSAc c0 wNow mt sl uw) rw [e] at eτ - have h : σ1 = Fl4SpecA64.fl4TimestampState (Sched.rawNextA (witSA wNow mt sl uw).machineState) - { witSA wNow mt sl uw with machineState := Sched.rawStateA (witSA wNow mt sl uw).machineState } := + have h : σ1 = Fl4SpecA64.fl4TimestampState (Sched.rawNextA (witSAc c0 wNow mt sl uw).machineState) + { witSAc c0 wNow mt sl uw with machineState := Sched.rawStateA (witSAc c0 wNow mt sl uw).machineState } := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst eτ))).2 have hk : σ1.kheap (specPtr (bwv SCb)) = some (.schedContext (rootScA wNow sl) 0) := by rw [h] @@ -104,7 +104,7 @@ theorem wit_hsuf (O : Wit2.OpaqueWA) {mt sl : U64} {uw : U64 → U64} (hsl : Fl4 have hcs : σ1.curSc = specPtr (bwv SCb) := by rw [h]; rfl have hu : σ1.consumedTime = 0 := by rw [h] - show (witSA wNow mt sl uw).consumedTime + (wTick - wNow.bv) = 0 + show (witSAc c0 wNow mt sl uw).consumedTime + (wTick - wNow.bv) = 0 show (0 : Fl4SpecA64.Ticks) + (wTick - wTick) = 0 simp rw [hcs, hu, Sched.fl4GetScRefillSufficient_eqA hk (by simp [rootScA]) 0] @@ -113,20 +113,20 @@ theorem wit_hsuf (O : Wit2.OpaqueWA) {mt sl : U64} {uw : U64 → U64} (hsl : Fl4 /-! ## The VSpace words are not the preemption point's -/ -theorem wit_hvp {r now mt sl : U64} {uw : U64 → U64} : - ∀ b, VsR (bL.ksb (witS r now mt sl uw)) +theorem wit_hvp {c0 r now mt sl : U64} {uw : U64 → U64} : + ∀ b, VsR (bL.ksb (witSc c0 r now mt sl uw)) (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r now mt sl uw ∪ w1Tb) b → - Aligned b ∧ ¬ PPW bst (witS r now mt sl uw) b := by + Aligned b ∧ ¬ PPW bst (witSc c0 r now mt sl uw) b := by intro b hb - have vW : (core.num.U64.wrapping_add (bL.ksb (witS r now mt sl uw)) layout.ks.WORK_UNITS).val = KBn + 40 := by + have vW : (core.num.U64.wrapping_add (bL.ksb (witSc c0 r now mt sl uw)) layout.ks.WORK_UNITS).val = KBn + 40 := by have oW : layout.ks.WORK_UNITS.val = 40 := by simp [layout.ks.WORK_UNITS] rw [ksb2, wa_valm, kbv, oW] exact Nat.mod_eq_of_lt (by norm_num) have vN : ∀ o : U64, o.val = 48 ∨ o.val = 40 → o.val < 4288 → - (bL.nodeA (witS r now mt sl uw) o).val = KBn + 223488 + o.val := by + (bL.nodeA (witSc c0 r now mt sl uw) o).val = KBn + 223488 + o.val := by intro o _ ho have v := nodeV (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (c := 0#u64) (o := o) (by simp) ho - show (bL.nodeAt (witS r now mt sl uw) (bL.cpu (witS r now mt sl uw)) o).val = _ + show (bL.nodeAt (witSc c0 r now mt sl uw) (bL.cpu (witSc c0 r now mt sl uw)) o).val = _ rw [cpu2, nodeAt21, v] simp have vT := vN layout.node.CUR_TIME (Or.inl (by simp [layout.node.CUR_TIME])) (by simp [layout.node.CUR_TIME]) @@ -136,7 +136,7 @@ theorem wit_hvp {r now mt sl : U64} {uw : U64 → U64} : rw [oT] at vT rw [oC] at vC have npp : ∀ x : U64, x.val ≠ KBn + 40 → x.val ≠ KBn + 223488 + 48 → x.val ≠ KBn + 223488 + 40 → - ¬ PPW bst (witS r now mt sl uw) x := by + ¬ PPW bst (witSc c0 r now mt sl uw) x := by rintro x h1 h2 h3 (e | e | e) · exact h1 (e ▸ vW) · exact h2 (e ▸ vT) @@ -164,15 +164,15 @@ theorem wit_hvp {r now mt sl : U64} {uw : U64 → U64} : /-! ## The entry record at the witness -/ /-- **The budget prefix is the identity at the witness.** -/ -theorem wit_budget_id (O : Wit2.OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) +theorem wit_budget_id (O : Wit2.OpaqueWA) {c0 r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) - (a : WA) (ha : Wit2.WClock a (witSA wNow mt sl uw).machineState) : - ∃ a1, syscall.budget_ok bst AR1 (witS r wNow mt sl uw) a = ok (true, witS r wNow mt sl uw, a1) ∧ - sched.update_timestamp bst AR1 (witS r wNow mt sl uw) a = ok (witS r wNow mt sl uw, a1) := by + (a : WA) (ha : Wit2.WClock a (witSAc c0 wNow mt sl uw).machineState) : + ∃ a1, syscall.budget_ok bst AR1 (witSc c0 r wNow mt sl uw) a = ok (true, witSc c0 r wNow mt sl uw, a1) ∧ + sched.update_timestamp bst AR1 (witSc c0 r wNow mt sl uw) a = ok (witSc c0 r wNow mt sl uw, a1) := by have J : JSyscallA bst (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) Fl4SpecA64.fl4A64Platform.numNodes (J5A bst) - (J7A bst (J7R2A bst AR1 Wit2.ar1_plat.ipa)) (witS r wNow mt sl uw) a (witSA wNow mt sl uw) (w1MA IB 1) := by + (J7A bst (J7R2A bst AR1 Wit2.ar1_plat.ipa)) (witSc c0 r wNow mt sl uw) a (witSAc c0 wNow mt sl uw) (w1MA IB 1) := by rw [O.nodes] exact wit_syscallA (fun _ _ => True) Wit2.witArA (a := a) r wNow mt sl uw Wit2.ar1_plat.ipa trivial O.nodes hsl hr exact J.budgetOkIdA (AR' := fun _ _ => True) wit_hvp Wit2.ar1_now ha O.nd wit_counterStep (wit_hNow O) diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2PlatA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2PlatA.lean index 8e704e673..9b4c32a36 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2PlatA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2PlatA.lean @@ -37,12 +37,13 @@ open Fl4SpecA64 noncomputable section /-- A `KernelConfig` with one domain, `maxIRQ = 5375` and GICv2. -/ -theorem kernelConfig_ex : ∃ kc : KernelConfig, kc.numDomains = 1 ∧ kc.maxIRQ = 5375 ∧ kc.configArmGicV3 = false := +theorem kernelConfig_ex : ∃ kc : KernelConfig, kc.numDomains = 1 ∧ kc.maxIRQ = 5375 ∧ kc.configArmGicV3 = false ∧ + kc.resetChunkBits = 16 := ⟨{ numDomains := 1, numDomains_not_zero := by decide, numDomains_fits_domainBits := by decide, - resetChunkBits := 8, retypeFanOutLimit := 256, maxIRQ := 5375, maxIRQ_less_2p_irqBits := by decide, + resetChunkBits := 16, retypeFanOutLimit := 256, maxIRQ := 5375, maxIRQ_less_2p_irqBits := by decide, irqVTimerEvent_le_maxIRQ := by decide, physBase := 0x40000000, configArmGicV3 := false, configDisableWfiWfeTraps := false, l1CacheLineSizeBits := 6, cacheLineBits_sanity := by decide }, - rfl, rfl, rfl⟩ + rfl, rfl, rfl, rfl⟩ /-- A `TimeConsts` with FL4's WCET (10 µs), 1000 ticks per µs and timer unit 1. -/ def wTCA : TimeConsts := @@ -78,7 +79,7 @@ theorem oracle_ex (h : kernelConfig.maxIRQ = 5375) : ∃ o : IrqOracle, ∀ n, o theorem counter_ex : ∃ f : Nat → Ticks, ∀ i, f i ≤ f (i + 1) := ⟨fun _ => 0, fun _ => BitVec.le_refl _⟩ /-- The default platform has one node. -/ -theorem platform_ex : ∃ p : Fl4A64Platform, p.numNodes = 1 := ⟨default, rfl⟩ +theorem platform_ex : ∃ p : Fl4A64Platform, p.numNodes = 1 ∧ p.s2IpaBits = 40 := ⟨default, rfl, rfl⟩ end diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2TierA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2TierA.lean index b14522463..d34eefcfd 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2TierA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2TierA.lean @@ -36,16 +36,16 @@ def witPoll : Fl4SpecA64.SMonad Unit (Option Fl4SpecA64.Word) := do pure (r.map fun i => BitVec.ofNat 64 i.toNat) /-- The oracle yields a non-kernel line, so `getActiveIRQ true` reports none and counts the read. -/ -theorem getActiveIRQ_none (O : OpaqueWA) (ms : Fl4SpecA64.MachineState) : +theorem getActiveIRQ_none (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) (ms : Fl4SpecA64.MachineState) : Fl4SpecA64.getActiveIRQ true ms = ({(none, { ms with irqState := ms.irqState + 1 })}, False) := by unfold Fl4SpecA64.getActiveIRQ simp only [nd_gets_bindSc, nd_modify_bindA] have hm : Fl4SpecA64.irqOracle (ms.irqState + 1) ∈ Fl4SpecA64.nonKernelIRQs := by - rw [O.irq] + rw [hI] simp [Fl4SpecA64.nonKernelIRQs] simp [Function.comp, hm] -theorem witPoll_eq (O : OpaqueWA) (τ : Fl4SpecA64.State Unit) : +theorem witPoll_eq (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) (τ : Fl4SpecA64.State Unit) : witPoll τ = ({(none, { τ with machineState := { τ.machineState with irqState := τ.machineState.irqState + 1 } })}, False) := by unfold witPoll @@ -55,7 +55,7 @@ theorem witPoll_eq (O : OpaqueWA) (τ : Fl4SpecA64.State Unit) : rw [nd_gets_bindSc] have sel : Fl4Spec.NonDet.selectF (Fl4SpecA64.getActiveIRQ true τ.machineState) τ = ({((none, { τ.machineState with irqState := τ.machineState.irqState + 1 }), τ)}, False) := by - rw [getActiveIRQ_none O]; exact selectF_oneA _ _ + rw [getActiveIRQ_none hI]; exact selectF_oneA _ _ rw [nd_bind_oneSc sel] dsimp only rw [nd_modify_bindA] @@ -93,20 +93,20 @@ theorem witPoll_pending : pendingIrqA witPoll preemptServiceA = | simp [Nat.mod_eq_of_lt h64, Nat.mod_eq_of_lt h13] rw [this] -theorem wit_pollAgree (O : OpaqueWA) : PollAgreeA AR1 (fun _ _ => True) witPoll := by +theorem wit_pollAgree (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) : PollAgreeA AR1 (fun _ _ => True) witPoll := by intro a c τ _ have hv : AR1.take_pending_irq a = ok (syscall.NO_IRQ, a) := rfl rw [hv] refine (WP.spec_ok _).2 ⟨{ τ with machineState := { τ.machineState with irqState := τ.machineState.irqState + 1 } }, ?_, ⟨_, rfl, rfl, rfl⟩, trivial, fun h => absurd rfl h⟩ simp only [if_pos rfl] - rw [witPoll_eq O τ] + rw [witPoll_eq hI τ] exact Set.mem_singleton _ /-! ## The fault handler of the root thread is `Null` -/ -theorem wit_faultCap {r now mt sl : U64} {uw : U64 → U64} : - capA bst (witS r now mt sl uw) (slotIdx (bL.curW (witS r now mt sl uw)) layout.tcb.SLOT_FAULT_HANDLER) = .Null := by +theorem wit_faultCap {c0 r now mt sl : U64} {uw : U64 → U64} : + capA bst (witSc c0 r now mt sl uw) (slotIdx (bL.curW (witSc c0 r now mt sl uw)) layout.tcb.SLOT_FAULT_HANDLER) = .Null := by rw [curW2] have h3 : layout.tcb.SLOT_FAULT_HANDLER.val = 3 := by unfold layout.tcb.SLOT_FAULT_HANDLER; rfl have v0 : (slotIdx (bwv RTb) layout.tcb.SLOT_FAULT_HANDLER).val = RTb + 96 := by @@ -114,35 +114,35 @@ theorem wit_faultCap {r now mt sl : U64} {uw : U64 → U64} : have v1 : (core.num.U64.wrapping_add (slotIdx (bwv RTb) layout.tcb.SLOT_FAULT_HANDLER) 8#u64).val = RTb + 104 := by rw [wa_valm, v0] exact Nat.mod_eq_of_lt (by simp) - have w0 : bL.mem (witS r now mt sl uw) (slotIdx (bwv RTb) layout.tcb.SLOT_FAULT_HANDLER) = 0#u64 := by - have := wit_rtWords (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) _ 96 (by norm_num) (by norm_num) + have w0 : bL.mem (witSc c0 r now mt sl uw) (slotIdx (bwv RTb) layout.tcb.SLOT_FAULT_HANDLER) = 0#u64 := by + have := wit_rtWords (c0 := c0) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) _ 96 (by norm_num) (by norm_num) (by rw [v0, vRT]) rw [this]; simp [witRtW, rtW] - have w1 : bL.mem (witS r now mt sl uw) + have w1 : bL.mem (witSc c0 r now mt sl uw) (core.num.U64.wrapping_add (slotIdx (bwv RTb) layout.tcb.SLOT_FAULT_HANDLER) 8#u64) = 0#u64 := by - have := wit_rtWords (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) _ 104 (by norm_num) (by norm_num) + have := wit_rtWords (c0 := c0) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) _ 104 (by norm_num) (by norm_num) (by rw [v1, vRT]) rw [this]; simp [witRtW, rtW] - show CapRt.decodeF (bL.mem (witS r now mt sl uw) _).bv (bL.mem (witS r now mt sl uw) _).bv = _ + show CapRt.decodeF (bL.mem (witSc c0 r now mt sl uw) _).bv (bL.mem (witSc c0 r now mt sl uw) _).bv = _ rw [w0, w1] first | rfl | decide | simp [CapRt.decodeF] /-! ## The entry record and the charge -/ /-- The record at the entry of the witness. -/ -abbrev WitJ (Z : XSetsA) (r now mt sl : U64) (uw : U64 → U64) (s : BS) (a : WA) (σ : Fl4SpecA64.State Unit) : Prop := +abbrev WitJ (Z : XSetsA) (c0 r now mt sl : U64) (uw : U64 → U64) (s : BS) (a : WA) (σ : Fl4SpecA64.State Unit) : Prop := JSyscallA bst (fun _ _ => True) Z (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r now mt sl uw) w1Tb w1Lv (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) Fl4SpecA64.fl4A64Platform.numNodes (J5A bst) (J7A bst (J7R2A bst AR1 Wit2.ar1_plat.ipa)) s a σ (w1MA IB 1) -theorem wit_entryIn (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) +theorem wit_entryIn (O : OpaqueWA) {c0 r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) - (ha : WClock a (witSA wNow mt sl uw).machineState) : + (ha : WClock a (witSAc c0 wNow mt sl uw).machineState) : KEntryFaultInA bst AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) Wit2.ar1_plat.ipa (w1MA IB 1) WClock - (witS r wNow mt sl uw) a (witSA wNow mt sl uw) where + (witSc c0 r wNow mt sl uw) a (witSAc c0 wNow mt sl uw) where J := by rw [O.nodes] exact wit_syscallA (fun _ _ => True) Wit2.witArA (a := a) r wNow mt sl uw Wit2.ar1_plat.ipa trivial O.nodes hsl hr @@ -157,21 +157,24 @@ theorem wit_entryIn (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (hsl : Fl4 hmb := Wit2.ar1_fl4MinBudget O /-- The `FAULT_IP` write leaves the spec state alone: the witness's `FAULT_IP` register is `NEXT_IP - 4`. -/ -theorem wit_pc {mt sl : U64} {uw : U64 → U64} : - Fl4SpecA64.fl4SyscallFaultIP (Z := Unit) (witSA wNow mt sl uw).curThread (witSA wNow mt sl uw) = - ({((), witSA wNow mt sl uw)}, False) := by - have hk : (witSA wNow mt sl uw).kheap (witSA wNow mt sl uw).curThread = some (.tcb witTcbA) := +theorem wit_pc {c0 mt sl : U64} {uw : U64 → U64} : + Fl4SpecA64.fl4SyscallFaultIP (Z := Unit) (witSAc c0 wNow mt sl uw).curThread (witSAc c0 wNow mt sl uw) = + ({((), witSAc c0 wNow mt sl uw)}, False) := by + have hk : (witSAc c0 wNow mt sl uw).kheap (witSAc c0 wNow mt sl uw).curThread = some (.tcb (witTcbA c0)) := Function.update_self _ _ _ rw [faultIP_eqA hk] - have e : setReg witTcbA Fl4SpecA64.faultRegister - (witTcbA.tcbArch.tcbContext.userRegs Fl4SpecA64.nextInstructionRegister - 4) = witTcbA := by - have h : witTcbA.tcbArch.tcbContext.userRegs Fl4SpecA64.nextInstructionRegister - 4 = - witTcbA.tcbArch.tcbContext.userRegs Fl4SpecA64.faultRegister := by decide + have e : setReg (witTcbA c0) Fl4SpecA64.faultRegister + ((witTcbA c0).tcbArch.tcbContext.userRegs Fl4SpecA64.nextInstructionRegister - 4) = (witTcbA c0) := by + have h : (witTcbA c0).tcbArch.tcbContext.userRegs Fl4SpecA64.nextInstructionRegister - 4 = + (witTcbA c0).tcbArch.tcbContext.userRegs Fl4SpecA64.faultRegister := by + have hn : (witTcbA c0).tcbArch.tcbContext.userRegs Fl4SpecA64.nextInstructionRegister = 4194304#64 := rfl + have hf : (witTcbA c0).tcbArch.tcbContext.userRegs Fl4SpecA64.faultRegister = 4194300#64 := rfl + rw [hn, hf]; decide rw [h] unfold setReg - have hr : Function.update (Fl4SpecA64.archTcbContextGet witTcbA.tcbArch).userRegs Fl4SpecA64.faultRegister - (witTcbA.tcbArch.tcbContext.userRegs Fl4SpecA64.faultRegister) = - (Fl4SpecA64.archTcbContextGet witTcbA.tcbArch).userRegs := Function.update_eq_self _ _ + have hr : Function.update (Fl4SpecA64.archTcbContextGet (witTcbA c0).tcbArch).userRegs Fl4SpecA64.faultRegister + ((witTcbA c0).tcbArch.tcbContext.userRegs Fl4SpecA64.faultRegister) = + (Fl4SpecA64.archTcbContextGet (witTcbA c0).tcbArch).userRegs := Function.update_eq_self _ _ simp only [setRegUc, hr] rfl rw [e] @@ -179,19 +182,19 @@ theorem wit_pc {mt sl : U64} {uw : U64 → U64} : rw [Function.update_eq_self_iff.2 hk.symm] /-- **`SysChargeA` at the witness**: the head refill is sufficient, so the exhausted-budget branch is vacuous. -/ -theorem wit_hCharge (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (a : WA) : +theorem wit_hCharge (O : OpaqueWA) {c0 r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (a : WA) : SysChargeA bst AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) Wit2.ar1_plat.ipa (w1MA IB 1) WClock - (witS r wNow mt sl uw) a (witSA wNow mt sl uw) := by + (witSc c0 r wNow mt sl uw) a (witSAc c0 wNow mt sl uw) := by unfold SysChargeA intro Q Rl τPC hpc J - have hτ : τPC = witSA wNow mt sl uw := by + have hτ : τPC = witSAc c0 wNow mt sl uw := by have := hpc.symm.trans wit_pc exact (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst this))).2 subst hτ unfold KEntryChargeA - intro s1 a1 σ1 e _ _ _ _ _ _ _ suf + intro s1 a1 σ1 _ e _ _ _ _ _ _ _ suf have h := wit_hsuf O hsl e rw [h] at suf exact absurd (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst suf))).1 (by decide) @@ -203,21 +206,21 @@ theorem wit_hCs (O : OpaqueWA) : ∀ c ∈ witZA.Cs, c.val < Fl4SpecA64.fl4A64Pl rw [O.nodes]; exact hc /-- The root thread's fault handler is `Null` at the spec's state too (`getCap` of the handler slot). -/ -theorem wit_faultHandler_null {Z : XSetsA} {r mt sl : U64} {uw : U64 → U64} {ab : WA} {τ : Fl4SpecA64.State Unit} - (Jr : WitJ Z r wNow mt sl uw (witS r wNow mt sl uw) ab τ) : +theorem wit_faultHandler_null {Z : XSetsA} {c0 r mt sl : U64} {uw : U64 → U64} {ab : WA} {τ : Fl4SpecA64.State Unit} + (Jr : WitJ Z c0 r wNow mt sl uw (witSc c0 r wNow mt sl uw) ab τ) : Fl4SpecA64.getCap (Z := Unit) (Fl4SpecA64.getTcbFaultHandlerPtr τ.curThread) τ = ({(Fl4SpecA64.Cap.nullCap, τ)}, False) := by - have ct : τ.curThread = specPtr (bL.curW (witS r wNow mt sl uw)) := Jr.j.1.sch.curThread - have htZ : bL.curW (witS r wNow mt sl uw) ∈ Z.T := Jr.sr.curT + have ct : τ.curThread = specPtr (bL.curW (witSc c0 r wNow mt sl uw)) := Jr.j.1.sch.curThread + have htZ : bL.curW (witSc c0 r wNow mt sl uw) ∈ Z.T := Jr.sr.curT obtain ⟨x, hk, hs⟩ := Jr.j.1.st.tcb _ ((Jr.j.1.thT _).2 htZ) obtain ⟨ac, e, hrel⟩ := hs 3 (by unfold tcbSlotsA; omega) have h3 : layout.tcb.SLOT_FAULT_HANDLER.val = 3 := by unfold layout.tcb.SLOT_FAULT_HANDLER; rfl - have ev : slotIdx (bL.curW (witS r wNow mt sl uw)) layout.tcb.SLOT_FAULT_HANDLER = - slotAddrA (specPtr (bL.curW (witS r wNow mt sl uw))) (BitVec.ofNat 64 3) := by + have ev : slotIdx (bL.curW (witSc c0 r wNow mt sl uw)) layout.tcb.SLOT_FAULT_HANDLER = + slotAddrA (specPtr (bL.curW (witSc c0 r wNow mt sl uw))) (BitVec.ofNat 64 3) := by rw [slotIdx_addrA, h3] - have hc := wit_faultCap (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) + have hc := wit_faultCap (c0 := c0) (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) rw [ev] at hc - have hrel' : CapRelA (capA bst (witS r wNow mt sl uw) (slotAddrA (specPtr (bL.curW (witS r wNow mt sl uw))) (BitVec.ofNat 64 3))) ac := hrel + have hrel' : CapRelA (capA bst (witSc c0 r wNow mt sl uw) (slotAddrA (specPtr (bL.curW (witSc c0 r wNow mt sl uw))) (BitVec.ofNat 64 3))) ac := hrel rw [hc] at hrel' have hrel := hrel' have hac : ac = Fl4SpecA64.Cap.nullCap := hrel.2.symm @@ -226,10 +229,10 @@ theorem wit_faultHandler_null {Z : XSetsA} {r mt sl : U64} {uw : U64 → U64} {a exact getCap_tcb_eqA hk e /-- **`SendScopeA` at the witness** (module docstring). -/ -theorem wit_scope (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (U : WitUw uw) (rep : Bool) +theorem wit_scope (O : OpaqueWA) (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) {r mt sl : U64} {uw : U64 → U64} (U : WitUw uw) (rep : Bool) (call : Fl4SpecA64.Syscall) {Q : U64 → U64 → List U64} {Rl : U64 → List U64} {ab : WA} {τ : Fl4SpecA64.State Unit} - (Jr : WitJ { witZA with Q := Q, R := Rl } r wNow mt sl uw (witS r wNow mt sl uw) ab τ) : + (Jr : WitJ { witZA with Q := Q, R := Rl } 2#u64 r wNow mt sl uw (witS r wNow mt sl uw) ab τ) : SendScopeA bst AR1 (fun _ _ => True) { witZA with Q := Q, R := Rl } (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) Fl4SpecA64.fl4A64Platform.numNodes @@ -267,12 +270,11 @@ theorem wit_scope (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (U : WitUw u · intro calling blocking donate _ info buf r1 e x s' a' h1 h2 h3 h4 hdec _ exact (wit_noDecodeErr U h1 h2 h3 h4 hdec).elim · refine - { K := Wit2.ar1_irqArch O - hMax := O.maxIRQ + { irq := ⟨Wit2.ar1_irqArch O, O.maxIRQ⟩ hn := rfl hLimit := fun a' => Wit2.ar1_limit O a' hSend := fun calling blocking donate s' a' τ' _ hh => (wit_notPreempted U hh).elim - poll := ⟨witPoll, wit_pollAgree O, witPoll_pending, ?_⟩ } + poll := ⟨witPoll, wit_pollAgree hI, witPoll_pending, ?_⟩ } intro s' a' r' τ' irq a'' τ'' _ _ ht hne _ have hv : AR1.take_pending_irq r'.2 = ok (syscall.NO_IRQ, r'.2) := rfl rw [hv] at ht @@ -282,34 +284,34 @@ theorem wit_scope (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (U : WitUw u /-- **`kRuns` at the witness**: the syscall number is in range and the entry's `FAULT_IP` write finds the thread's `TRAP_SYSCALLS` flag clear (its flags word is zero). -/ -theorem wit_kRuns {r mt sl : U64} {uw : U64 → U64} (number : I64) (rep : Bool) (call : Fl4SpecA64.Syscall) +theorem wit_kRuns {c0 r mt sl : U64} {uw : U64 → U64} (number : I64) (rep : Bool) (call : Fl4SpecA64.Syscall) (hnum : number = syscallNumberA call) (hc : call = .sysSend ∨ call = .sysNBSend ∨ call = .sysCall) : - kRuns bst (witS r wNow mt sl uw) (.syscall number rep call) := by + kRuns bst (witSc c0 r wNow mt sl uw) (.syscall number rep call) := by have rng : ¬ number < fl4_abi.syscall.SYSCALL_MIN ∧ ¬ number > fl4_abi.syscall.SYSCALL_MAX := by subst hnum rcases hc with rfl | rfl | rfl <;> simp only [syscallNumberA] <;> first | decide | scalar_tac | (constructor <;> simp [fl4_abi.syscall.SYSCALL_MIN, fl4_abi.syscall.SYSCALL_MAX, fl4_abi.syscall.SysSend, fl4_abi.syscall.SysNBSend, fl4_abi.syscall.SysCall] <;> decide) - have ct : sched.cur_thread bst (witS r wNow mt sl uw) = ok (bwv RTb) := by rw [cur_thread_ok, curW2] - have hset : obj.Tcb.set_reg bst (bwv RTb) (witS r wNow mt sl uw) layout.reg.FAULT_IP - (core.num.U64.wrapping_sub (bL.mem (witS r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64) = - ok (bL.wr (witS r wNow mt sl uw) (Endp.regA (bwv RTb) layout.reg.FAULT_IP) - (core.num.U64.wrapping_sub (bL.mem (witS r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64)) := by - obtain ⟨q, hq, e⟩ := spec_existsA (obj.Tcb.set_reg.spec (st := bst) (witS r wNow mt sl uw) (bwv RTb) - layout.reg.FAULT_IP (core.num.U64.wrapping_sub (bL.mem (witS r wNow mt sl uw) + have ct : sched.cur_thread bst (witSc c0 r wNow mt sl uw) = ok (bwv RTb) := by rw [cur_thread_ok, curW2] + have hset : obj.Tcb.set_reg bst (bwv RTb) (witSc c0 r wNow mt sl uw) layout.reg.FAULT_IP + (core.num.U64.wrapping_sub (bL.mem (witSc c0 r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64) = + ok (bL.wr (witSc c0 r wNow mt sl uw) (Endp.regA (bwv RTb) layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (bL.mem (witSc c0 r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64)) := by + obtain ⟨q, hq, e⟩ := spec_existsA (obj.Tcb.set_reg.spec (st := bst) (witSc c0 r wNow mt sl uw) (bwv RTb) + layout.reg.FAULT_IP (core.num.U64.wrapping_sub (bL.mem (witSc c0 r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64)) rw [hq, e] - have fid : bL.wr (witS r wNow mt sl uw) (Endp.regA (bwv RTb) layout.reg.FAULT_IP) - (core.num.U64.wrapping_sub (bL.mem (witS r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64) = - witS r wNow mt sl uw := by - have := wit_faultIP_id (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) + have fid : bL.wr (witSc c0 r wNow mt sl uw) (Endp.regA (bwv RTb) layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (bL.mem (witSc c0 r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64) = + witSc c0 r wNow mt sl uw := by + have := wit_faultIP_id (c0 := c0) (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) rwa [curW2] at this - have hf : bL.mem (witS r wNow mt sl uw) (core.num.U64.wrapping_add (bwv RTb) 3456#u64) = 0#u64 := by + have hf : bL.mem (witSc c0 r wNow mt sl uw) (core.num.U64.wrapping_add (bwv RTb) 3456#u64) = 0#u64 := by have v : (core.num.U64.wrapping_add (bwv RTb) 3456#u64).val = (bwv RTb).val + 3456 := by rw [wa_valm, vRT]; exact Nat.mod_eq_of_lt (by simp) - have := wit_rtWords (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) _ 3456 (by norm_num) (by norm_num) v + have := wit_rtWords (c0 := c0) (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) _ 3456 (by norm_num) (by norm_num) v rw [this]; simp [witRtW, rtW] - refine ⟨rng.1, rng.2, bwv RTb, _, witS r wNow mt sl uw, 0#u64, ct, tcb_reg_eqA _ _ _, hset.trans (by rw [fid]), ?_, ?_⟩ + refine ⟨rng.1, rng.2, bwv RTb, _, witSc c0 r wNow mt sl uw, 0#u64, ct, tcb_reg_eqA _ _ _, hset.trans (by rw [fid]), ?_, ?_⟩ · rw [flags_ok, hf] · first | simp | (apply UScalar.eq_of_val_eq; simp) @@ -323,7 +325,7 @@ theorem wit_r_ex : ∃ r : U64, specPtr r = Fl4SpecA64.armGlobalPtPtr := set_option maxHeartbeats 4000000 in /-- **`syscallSend_refinesA` at the witness**, for `Send`, `NBSend` and `Call`. -/ -theorem wit_tierA (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (U : WitUw uw) +theorem wit_tierA (O : OpaqueWA) (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) {r mt sl : U64} {uw : U64 → U64} (U : WitUw uw) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) (ha : WClock a (witSA wNow mt sl uw).machineState) (number : I64) (rep : Bool) (call : Fl4SpecA64.Syscall) (hnum : number = syscallNumberA call) (hc : call = .sysSend ∨ call = .sysNBSend ∨ call = .sysCall) : @@ -340,7 +342,7 @@ theorem wit_tierA (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (U : WitUw u have e := ok_inj_ff eb have hsb : sb = witS r wNow mt sl uw := (congrArg (fun p => p.2.1) e).symm subst hsb - exact wit_scope O U rep call Jr) + exact wit_scope O hI U rep call Jr) end diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2TopA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2TopA.lean index c35a3376a..aff440afe 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2TopA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2TopA.lean @@ -60,7 +60,7 @@ structure SendEntryHyps (st : machine.Store S) [L : LawfulStore st] (ar : machin fl4A64Platform.numNodes sb ab τ m Clock hPl rep (maybeHandleInterrupt true) call hGap : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → - A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → SchedGapFreeA st m s' a' τ ar tm view + ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view hNat : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → ∀ τ1 τ2, @@ -98,7 +98,7 @@ noncomputable section set_option maxHeartbeats 4000000 in /-- **`kernelEntrySend_recGA` at the witness** (module docstring): the premises and the conclusion at one state. -/ -theorem wit_top_send (O : Wit2.OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (U : WitUw uw) +theorem wit_top_send (O : Wit2.OpaqueWA) (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) {r mt sl : U64} {uw : U64 → U64} (U : WitUw uw) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : Wit2.WA) (ha : Wit2.WClock a (witSA wNow mt sl uw).machineState) (number : I64) (rep : Bool) (call : Fl4SpecA64.Syscall) (hnum : number = syscallNumberA call) (hc : call = .sysSend ∨ call = .sysNBSend ∨ call = .sysCall) : @@ -140,7 +140,7 @@ theorem wit_top_send (O : Wit2.OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (U : have e := ok_inj_ff eb have hsb : sb = witS r wNow mt sl uw := (congrArg (fun p => p.2.1) e).symm subst hsb - exact wit_scope O U rep call Jr + exact wit_scope O hI U rep call Jr hGap := Wit2.wit2b_hGapA O Wit2.witArchSwOf (wit_hCs O) _ a _ (.syscall number rep call) hNat := wit2b_hNatA O U hsl hr a ha number rep call hc } exact ⟨Hy, Hy.concl⟩ @@ -162,7 +162,7 @@ def witA0 (ms : MachineState) : Wit2.WA where /-- **Non-vacuity of `kernelEntrySend_recGA`** (module docstring): with `OpaqueWA` the only hypothesis, every witness-side parameter is existential and instantiated by a concrete value: `r` from `wit_r_ex`, `uw` from `witUw_ex`, `sl = MIN_BUDGET`, `mt = 0`, the arch state `witA0` of `witSA`'s machine state, `call = Send`, `number = syscallNumberA .sysSend`. -/ -theorem wit_send_nonvacuous (O : Wit2.OpaqueWA) : +theorem wit_send_nonvacuous (O : Wit2.OpaqueWA) (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) : ∃ (r mt sl : U64) (uw : U64 → U64) (a : Wit2.WA) (number : I64) (rep : Bool) (call : Syscall), Nonempty (SendEntryHyps bst Wit2.AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv @@ -172,7 +172,7 @@ theorem wit_send_nonvacuous (O : Wit2.OpaqueWA) : number rep call) := by obtain ⟨r, hr⟩ := wit_r_ex obtain ⟨uw, U⟩ := witUw_ex - obtain ⟨Hy, -⟩ := wit_top_send O (r := r) (mt := 0#u64) (sl := ⟨Fl4SpecA64.MIN_BUDGET⟩) (uw := uw) U + obtain ⟨Hy, -⟩ := wit_top_send O hI (r := r) (mt := 0#u64) (sl := ⟨Fl4SpecA64.MIN_BUDGET⟩) (uw := uw) U (BitVec.le_refl _) hr (witA0 (witSA wNow 0#u64 ⟨Fl4SpecA64.MIN_BUDGET⟩ uw).machineState) rfl (syscallNumberA .sysSend) true .sysSend rfl (Or.inl rfl) exact ⟨r, 0#u64, ⟨Fl4SpecA64.MIN_BUDGET⟩, uw, _, syscallNumberA .sysSend, true, .sysSend, ⟨Hy⟩⟩ diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2bBodyA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2bBodyA.lean index c80cbf1d3..bc7eb924a 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2bBodyA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2bBodyA.lean @@ -172,7 +172,7 @@ local notation "RC" => capability.Cap.CNode (bwv RRb) 13#u64 51#u64 0#u64 /-- No thread of the witness's spec state runs a guest: its TCBs are the running root and the idle ones. -/ theorem wit_noVm {now mt sl : U64} {uw : U64 → U64} : NoVmA (witSA now mt sl uw) := by intro p x hp v - change Function.update (w1KA KB IB 1 now mt sl) (specPtr (bwv RTb)) (some (.tcb witTcbA)) p = some (.tcb x) at hp + change Function.update (w1KA KB IB 1 now mt sl) (specPtr (bwv RTb)) (some (.tcb (witTcbA 2#u64))) p = some (.tcb x) at hp by_cases c : p = specPtr (bwv RTb) · subst c rw [Function.update_self] at hp @@ -185,7 +185,7 @@ theorem wit_noVm {now mt sl : U64} {uw : U64 → U64} : NoVmA (witSA now mt sl u set_option maxHeartbeats 4000000 in /-- **Every outcome of the CNode Copy invocation at the witness** creates no `runningVM` thread and does not throw. -/ theorem wit_invoke_okVm {Z : XSetsA} {r mt sl : U64} {uw : U64 → U64} (U : WitUw uw) {ab : WA} - {τ : Fl4SpecA64.State Unit} (Jr : WitJ Z r wNow mt sl uw (witS r wNow mt sl uw) ab τ) + {τ : Fl4SpecA64.State Unit} (Jr : WitJ Z 2#u64 r wNow mt sl uw (witS r wNow mt sl uw) ab τ) (rep calling blocking donate : Bool) {x : Tcb} (hk : τ.kheap (specPtr (bL.curW (witS r wNow mt sl uw))) = some (.tcb x)) : ∀ y, y ∈ ((fl4HandleInvocationR (Z := Unit) rep calling blocking donate false @@ -280,7 +280,7 @@ theorem wit_bodyNoVm (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (U : WitU have I := wit_entryIn O (r := r) (mt := mt) (uw := uw) hsl hr a ha obtain ⟨a1, hb, -⟩ := wit_budget_id O hsl hr a ha (uw := uw) (mt := mt) (r := r) have budget := JSyscallA.budgetOkSysA (AR' := fun _ _ => True) I.J I.hvp I.P I.hClock I.hnd I.C I.hC I.hNow I.hAr I.hmb - (fun s1 a1 σ1 e _ _ _ _ _ _ _ suf => by + (fun s1 a1 σ1 _ e _ _ _ _ _ _ _ suf => by rw [wit_hsuf O hsl e] at suf exact absurd (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst suf))).1 (by decide)) obtain ⟨⟨b, sb, ab⟩, eb, τ, e1, -, tr⟩ := spec_existsA budget diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2bGapA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2bGapA.lean index 3fe1698d0..105bb664d 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2bGapA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2bGapA.lean @@ -157,7 +157,7 @@ theorem switch_factsA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS rw [wake] at er obtain rfl := ok_inj_ff er obtain ⟨a1, Qf, Rf, ef, J1, R1, B1⟩ := FFh rfl fires - have steps := JStage3A.selectionA (Z := Z) (Q := Qf) (R := Rf) J1 hCs h1 R1 waking wakeRel ⟨Fa.wr, Fa.keep, Fa.sz⟩ SF + have steps := JStage3A.selectionA (Z := Z) (Q := Qf) (R := Rf) J1 hCs h1 R1 waking wakeRel (MFrA.ofParts Fa.wr Fa.keep Fa.sz) SF (awaken_archA ef wake) (JStage3A.vsRootOK J1) (JStage3A.idleVtOf J1 J1.idleGapA.1 J1.idleGapA.2.1) obtain ⟨r2, er2, σ3, Q', _, selection, _, H3, _, _⟩ := spec_ex_fd (select_action_refinesA wakeRel arch steps.action steps.domain steps.roots) @@ -223,7 +223,7 @@ theorem schedGapFreeA_recA {AR : A → HwRootA → Prop} {Cs : Set U64} {s : S} (oneDomain : numDomains = 1) (minAgree : fl4MinBudget = MIN_BUDGET) (ticks : ∀ a', ScCfgTimeAgreeA ar a') (hmax : maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) (sni : ∀ a', SniHypA ar tm a' 0) (hb : body = ok (s, a)) - (R : A64RelS3 st AR ar hPl.ipa fl4A64Platform.numNodes Cs s a σ m) : + (R : A64RelS3fx st AR ar hPl.ipa fl4A64Platform.numNodes Cs s a σ m) : SchedGapFreeA st m s a σ ar tm (gapViewA st ar body) := by obtain ⟨Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, hZ, J, B⟩ := R refine ⟨oneDomain, minAgree, ticks, ?_⟩ @@ -274,10 +274,10 @@ theorem wit2b_hGapA (O : OpaqueWA) {AR' : WA → HwRootA → Prop} (arch : ArchS (hCs : ∀ c ∈ Cs, c.val < fl4A64Platform.numNodes) {m : McState} (s : S) (a : WA) (σ : State Unit) (e : KEventA) : ∀ s' a' τ, kBodyA st AR1 s a e = ok (s', a') → ((), τ) ∈ (kOpA e σ).1 → - A64RelS3 st AR' AR1 ar1_plat.ipa fl4A64Platform.numNodes Cs s' a' τ m → - SchedGapFreeA st m s' a' τ AR1 witTm (gapViewA st AR1 (kBodyA st AR1 s a e)) := - fun _ _ _ eb _ R => schedGapFreeA_recA ar1_total ar1_plat arch hCs O.nodes O.nd O.hag (ar1_cfgTime O) O.max - ar1_ticksToUs ar1_sni eb R + ∀ m', A64RelS3at st AR' AR1 ar1_plat.ipa fl4A64Platform.numNodes Cs s' a' τ m m' → + SchedGapFreeA st m' s' a' τ AR1 witTm (gapViewA st AR1 (kBodyA st AR1 s a e)) := + fun _ _ _ eb _ _ R => schedGapFreeA_recA ar1_total ar1_plat arch hCs O.nodes O.nd O.hag (ar1_cfgTime O) O.max + ar1_ticksToUs ar1_sni eb R.2 end diff --git a/proofs/Fl4ProofsA64/P3/A64Wit3ClockA.lean b/proofs/Fl4ProofsA64/P3/A64Wit3ClockA.lean new file mode 100644 index 000000000..f0a986d24 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64Wit3ClockA.lean @@ -0,0 +1,230 @@ +/- +P3 (aarch64, A64-P4 non-vacuity witness for the VM-exit tops, part 1): **the clock and arch premises of +`VcpuExitInA` at the model arch.** + +* `WClock'`: the clock relation of the VM-exit witness. `Wit2.WClock` (`a.ms = ms`) is too strong for `VcpuExitInA.hClFr` + (a relation that forgets everything but `timeState` / `lastMachineTime`); `WClock'` keeps exactly those two fields, + and `ar1_now'` is `NowAgreeA` at it. The Send witness keeps `WClock`. +* `ArchKeepPi` / `set_vm_root_pi`: **`set_vm_root` keeps a projection of the arch state** when the three arch writes + (`set_vspace`, `set_high_vspace`, `set_stage2_vspace`) do, for *every* store and thread pointer (no record guard), and + leaves the store alone. Generalises `P1/QueueSwitch.set_vm_root_same`. +* `ar1_clVm` (`hClVm`), `ar1_clFlushState`, `ar1_clMask`, `ar1_vcpuPlat` (`VcpuPlatAgreeA`), `ar1_vcpuKeeps` + (`VcpuArchKeepsA`), `ar1_vcpuVmRoot` (`VcpuVmRootA`): the [P] premises of the exit tops, at `AR := True`. + +Named premises: [P] `OpaqueWA` (only for `VcpuPlatAgreeA.gic`: GICv2). New module. +-/ +import Fl4ProofsA64.P3.A64Wit2ArchA +import Fl4ProofsA64.P3.VcpuPremisesA +import Fl4ProofsA64.P1.QueueSwitch +import Fl4ProofsA64.P1.QueueVsFin +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Wit3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P3 Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4ProofsA64.P3.Wit2 Fl4SpecA64 + +noncomputable section + +section generic +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {π : A → MachineState} + +/-- The three arch writes `set_vm_root` makes keep the projection `π`. -/ +structure ArchKeepPi (ar : machine.Arch A) (π : A → MachineState) : Prop where + set_vspace : ∀ a r i, ar.set_vspace a r i ⦃ a' => π a' = π a ⦄ + set_high_vspace : ∀ a r i, ar.set_high_vspace a r i ⦃ a' => π a' = π a ⦄ + set_stage2_vspace : ∀ a r i, ar.set_stage2_vspace a r i ⦃ a' => π a' = π a ⦄ + +theorem one_of_two {m : Result (S × A)} {s : S} (h : m ⦃ s' _ => s' = s ⦄) : m ⦃ r => r.1 = s ⦄ := + WP.spec_mono h fun r e => by + obtain ⟨s', a'⟩ := r + simpa only [WP.uncurry'_pair] using e + +/-- Sequencing: a first step that keeps the store and `π`, then a continuation that does so at every arch state. -/ +theorem bind_both {m : Result (S × A)} {f : S × A → Result (S × A)} {s : S} {a : A} + (hm : m ⦃ r => r.1 = s ∧ π r.2 = π a ⦄) + (hf : ∀ a1, f (s, a1) ⦃ r => r.1 = s ∧ π r.2 = π a1 ⦄) : + (m >>= f) ⦃ r => r.1 = s ∧ π r.2 = π a ⦄ := by + refine WP.spec_bind hm ?_ + rintro ⟨s1, a1⟩ ⟨e1, e2⟩ + simp only at e1 e2 + subst e1 + exact WP.spec_mono (hf a1) fun r h => ⟨h.1, h.2.trans e2⟩ + +include L in +theorem set_kernel_vm_root_both (K : ArchKeepPi ar π) (hA : P0.ArchTotal ar) (s : S) (a : A) : + vspace.set_kernel_vm_root st ar s a ⦃ r => r.1 = s ∧ π r.2 = π a ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold vspace.set_kernel_vm_root + refine WP.spec_bind (P0.vspace.kernel_root.p0 st s hS) fun k _ => ?_ + refine WP.spec_bind (K.set_high_vspace a 0#u64 0#u64) fun a1 e1 => ?_ + refine WP.spec_bind (K.set_vspace a1 k 0#u64) fun a2 e2 => ?_ + exact (WP.spec_ok _).2 ⟨rfl, e2.trans e1⟩ + +theorem stage2_leaf (K : ArchKeepPi ar π) (s : S) (a : A) (x y : U64) : + (do let a1 ← ar.set_stage2_vspace a x y; ok (s, a1) : Result (S × A)) ⦃ r => r.1 = s ∧ π r.2 = π a ⦄ := + WP.spec_bind (K.set_stage2_vspace a x y) fun _ h => (WP.spec_ok _).2 ⟨rfl, h⟩ + +include L in +theorem set_stage2_root_both (K : ArchKeepPi ar π) (hA : P0.ArchTotal ar) (s : S) (a : A) (t : obj.Tcb) : + vspace.set_stage2_root st ar s a t ⦃ r => r.1 = s ∧ π r.2 = π a ⦄ := by + have := L.total + unfold vspace.set_stage2_root + refine WP.spec_bind (P0.obj.Tcb.slot.p0 t layout.tcb.SLOT_VTABLE) fun s1 _ => ?_ + refine WP.spec_bind (P0.obj.Slot.cap.p0 st s1 s this) fun c _ => ?_ + cases c <;> first | exact stage2_leaf K s a _ _ | skip + all_goals (dsimp only; repeat' (first | exact stage2_leaf K s a _ _ | step | split)) + all_goals (trace_state; fail "arm") + +include L in +theorem set_vm_root_pml4_both (K : ArchKeepPi ar π) (hA : P0.ArchTotal ar) (s : S) (a : A) (t : obj.Tcb) + (ptr asid : U64) : + (do + let i1 ← obj.Tcb.state st t s + let high ← + if i1 = sched.TS_RUNNING_VM + then ok 0#u64 + else vspace.high_root_of st s t + let t1 ← + if high = 0#u64 + then + do + let a2 ← ar.set_high_vspace a 0#u64 asid + ar.set_vspace a2 ptr asid + else + do + let a2 ← ar.set_vspace a ptr asid + ar.set_high_vspace a2 high asid + ok (s, t1)) ⦃ r => r.1 = s ∧ π r.2 = π a ⦄ := by + refine WP.spec_bind (P0.obj.Tcb.state.p0 st t s L.total) fun i1 _ => ?_ + refine WP.spec_bind (show (if i1 = sched.TS_RUNNING_VM then ok 0#u64 else vspace.high_root_of st s t) + ⦃ _ => True ⦄ from ?_) fun high _ => ?_ + · by_cases hi : i1 = sched.TS_RUNNING_VM + · rw [if_pos hi]; exact (WP.spec_ok _).2 trivial + · rw [if_neg hi]; exact high_root_of_ro s t + · refine WP.spec_bind ?_ fun t1 (e : π t1 = π a) => (WP.spec_ok _).2 ⟨rfl, e⟩ + by_cases hh : high = 0#u64 + · rw [if_pos hh] + refine WP.spec_bind (K.set_high_vspace _ _ _) fun a2 e1 => ?_ + exact WP.spec_mono (K.set_vspace a2 ptr asid) fun a3 e2 => e2.trans e1 + · rw [if_neg hh] + refine WP.spec_bind (K.set_vspace _ _ _) fun a2 e1 => ?_ + exact WP.spec_mono (K.set_high_vspace a2 high asid) fun a3 e2 => e2.trans e1 + +set_option maxHeartbeats 4000000 in +include L in +/-- **`set_vm_root` keeps the store and a projection of the arch state, at every store and thread pointer.** -/ +theorem set_vm_root_pi (K : ArchKeepPi ar π) (hA : P0.ArchTotal ar) (s : S) (a : A) (t : obj.Tcb) : + vspace.set_vm_root st ar s a t ⦃ r => r.1 = s ∧ π r.2 = π a ⦄ := by + have := L.total + unfold vspace.set_vm_root + refine WP.spec_bind (P0.vcpu.bound.p0 st s t this) fun i _ => ?_ + by_cases hi : (i != 0#u64) = true + · rw [if_pos hi] + exact bind_both (set_kernel_vm_root_both K hA s a) fun a1 => set_stage2_root_both K hA s a1 t + · rw [if_neg hi] + refine WP.spec_bind (P0.obj.Tcb.slot.p0 t layout.tcb.SLOT_VTABLE) fun s1 _ => ?_ + refine WP.spec_bind (P0.obj.Slot.cap.p0 st s1 s this) fun c _ => ?_ + refine bind_both ?_ ?_ + · repeat' (first + | exact set_kernel_vm_root_both K hA s a + | exact set_vm_root_pml4_both K hA s a t _ _ + | step + | split) + · intro a1 + try dsimp only + repeat' (first + | exact set_stage2_root_both K hA s a1 _ + | exact (WP.spec_ok _).2 ⟨rfl, rfl⟩ + | step + | split) + +end generic + +/-! ## The model arch -/ + +/-- **The clock relation of the VM-exit witness**: the arch state's clock agrees with the spec's on the two fields the +raw counter reads and writes. -/ +def WClock' (a : WA) (ms : MachineState) : Prop := + a.ms.timeState = ms.timeState ∧ a.ms.lastMachineTime = ms.lastMachineTime + +theorem WClock'.of_eq {a : WA} {ms : MachineState} (h : WClock a ms) : WClock' a ms := + ⟨by rw [h], by rw [h]⟩ + +/-- **`NowAgreeA` at `WClock'`.** -/ +theorem ar1_now' : NowAgreeA AR1 WClock' := by + intro a ms h + obtain ⟨h1, h2⟩ := h + refine (WP.spec_ok _).2 ⟨?_, ?_, ?_⟩ + · show fl4RawCounterOracle (a.ms.timeState + 1) = rawNextA ms + simp only [rawNextA, h1] + · show a.ms.timeState + 1 = ms.timeState + 1 + rw [h1] + · show rawNextA a.ms = rawNextA ms + simp only [rawNextA, h1] + +/-- The model arch's three root writes leave the machine state alone. -/ +theorem ar1_keepPi : ArchKeepPi AR1 (fun a : WA => a.ms) where + set_vspace a r i := by + show (ok (if r = a.s1.1 ∧ i = a.s1.2 then a else { a with s1 := (r, i), hi := (0#u64, 0#u64) }) : Result WA) + ⦃ a' => a'.ms = a.ms ⦄ + rw [WP.spec_ok] + split <;> rfl + set_high_vspace a r i := by + show (ok { a with hi := (r, i) } : Result WA) ⦃ a' => a'.ms = a.ms ⦄ + exact (WP.spec_ok _).2 rfl + set_stage2_vspace a r i := by + show (ok { a with s2 := (r, i) } : Result WA) ⦃ a' => a'.ms = a.ms ⦄ + exact (WP.spec_ok _).2 rfl + +/-- **`VcpuExitInA.hClVm` at the model arch** (every store, every thread pointer). -/ +theorem ar1_clVm {S : Type} {st : machine.Store S} [LawfulStore st] : + ∀ (s' : S) (a' : WA) (ms : MachineState) (u : U64), WClock' a' ms → + vspace.set_vm_root st AR1 s' a' u ⦃ r => WClock' r.2 ms ⦄ := by + intro s a ms u h + refine WP.spec_mono (set_vm_root_pi (π := fun a : WA => a.ms) ar1_keepPi ar1_total s a u) ?_ + intro r e + have e' : r.2.ms = a.ms := e.2 + exact ⟨by rw [e']; exact h.1, by rw [e']; exact h.2⟩ + +/-- **`VcpuExitInA.hClFlushState`.** -/ +theorem ar1_clFlushState : ∀ (a' : WA) (ms : MachineState) (vc om : U64), WClock' a' ms → + AR1.vcpu_flush_state a' vc om ⦃ a'' => WClock' a'' ms ⦄ := + fun _ _ _ _ h => (WP.spec_ok _).2 h + +/-- **`kernelEntry_runVppiA.hClMask`.** -/ +theorem ar1_clMask : ∀ (a' : WA) (ms : MachineState) (irq : U64) (b : Bool), WClock' a' ms → + AR1.mask_irq a' irq b ⦃ a'' => WClock' a'' ms ⦄ := + fun _ _ _ _ h => (WP.spec_ok _).2 h + +/-- **`VcpuExitInA.hClFr`**: `WClock'` forgets everything but the two clock fields. -/ +theorem wclock'_fr : ∀ (a' : WA) (ms ms' : MachineState), WClock' a' ms → ms'.timeState = ms.timeState → + ms'.lastMachineTime = ms.lastMachineTime → WClock' a' ms' := + fun _ _ _ h h1 h2 => ⟨h.1.trans h1.symm, h.2.trans h2.symm⟩ + +/-- **`VcpuPlatAgreeA` at the model arch** (GICv2). -/ +theorem ar1_vcpuPlat (O : OpaqueWA) : VcpuPlatAgreeA AR1 where + midr _ := rfl + vtr _ := rfl + gic _ := ⟨0#u64, rfl, by rw [O.v2]; decide⟩ + +/-- **`VcpuArchKeepsA` at the model arch** (the trivial root relation). -/ +theorem ar1_vcpuKeeps : VcpuArchKeepsA AR1 (fun (_ : WA) (_ : HwRootA) => True) where + vcpu_flush := by intros; exact (WP.spec_ok _).2 trivial + vcpu_flush_state := by intros; exact (WP.spec_ok _).2 trivial + fpu_flush := by intros; exact (WP.spec_ok _).2 trivial + fpu_release := by intros; exact (WP.spec_ok _).2 trivial + mask_irq := by intros; exact (WP.spec_ok _).2 trivial + +/-- **`VcpuVmRootA` at the model arch.** -/ +theorem ar1_vcpuVmRoot {S : Type} {st : machine.Store S} [LawfulStore st] : + VcpuVmRootA st AR1 (fun (_ : WA) (_ : HwRootA) => True) where + set_vm_root s a h t _ := + WP.spec_mono (vspace.set_vm_root.same ar1_total s a t) fun r e => ⟨e, h, trivial⟩ + +/-- **`VcpuExitInA.hNowAR`** at the trivial root relation. -/ +theorem ar1_nowAR : ∀ (a0 : WA) (h : HwRootA), True → AR1.now a0 ⦃ r => True ⦄ := + fun _ _ _ => (WP.spec_ok _).2 trivial + +end + +end Fl4ProofsA64.P3.Wit3 diff --git a/proofs/Fl4ProofsA64/P3/A64Wit3ExitA.lean b/proofs/Fl4ProofsA64/P3/A64Wit3ExitA.lean new file mode 100644 index 000000000..0b0242ff2 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64Wit3ExitA.lean @@ -0,0 +1,151 @@ +/- +P3 (aarch64, A64-P4 non-vacuity witness for the VM-exit tops, part 2): **`ExitEntryHyps` / `VppiEntryHyps`, and +`VcpuExitInA` from the Send witness's entry record.** + +* `ExitEntryHyps` / `VppiEntryHyps`: *every* premise of `kernelEntry_runExitA` / `kernelEntry_runVppiA` as a structure (the + theorems' binders, copied verbatim, `tm` / `view` / `Cs` explicit); `.concl` applies the theorem to it, so the bundle is + exactly the theorems' premises (the pattern of `SendEntryHyps`). +* `VcpuExitInA.ofWit`: the `VcpuExitInA` of the model arch from a `KEntryFaultInA` at `WClock` (the Send witness's entry + record, `Wit.wit_entryIn`): every field but `hScPost` is proved from the record and `A64Wit3ClockA`; `hScPost` and the + current thread's activation state (`ctAct`) are its two hypotheses (`hScPost` is the V1 premise of the Step 0 audit). + +Named premises: [P] `OpaqueWA`. New module. +-/ +import Fl4ProofsA64.P3.A64Wit2TopA +import Fl4ProofsA64.P3.A64Wit3ClockA +import Fl4ProofsA64.P3.Stage3VcpuExitWireA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **The premises of `kernelEntry_runExitA`** (module docstring). -/ +structure ExitEntryHyps (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) + (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) + (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (m : McState) + (Clock : A → MachineState → Prop) (s : S) (a : A) (σ : State Unit) (Cs : Set U64) + (tm : A → Nat → DeadlineViewA) (view : State Unit → Fl4TimerView) (stop : U64) (stopSpec : RunStop) + (w1 w2 w3 : U64) : Type where + hA : P0.ArchTotal ar + hPl : ArchPlat ar + arch : ArchSwFA st ar + hCs : ∀ c ∈ Cs, c.val < fl4A64Platform.numNodes + P : FinPlatA ar AR + J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s a σ m + I : VcpuExitInA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m Clock s a σ + hZ : Z.Cs = Cs + hstop : stop.bv = stopSpec.word + hne : stopSpec ≠ .vppi + hGap : ∀ s' a' τ, kBodyA st ar s a (kRunExitE stop w1 w2 w3 stopSpec) = ok (s', a') → + ((), τ) ∈ (kOpA (kRunExitE stop w1 w2 w3 stopSpec) σ).1 → + ∀ m', A64RelS3at st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view + hNat : ∀ s' a' τ, kBodyA st ar s a (kRunExitE stop w1 w2 w3 stopSpec) = ok (s', a') → + ((), τ) ∈ (kOpA (kRunExitE stop w1 w2 w3 stopSpec) σ).1 → + A64RelS3 st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → ∀ τ1 τ2, + ((), τ1) ∈ (fl4Schedule kLimitA view τ).1 → ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → + ∀ y, τ2.kheap τ2.curThread = some (.tcb y) → y.tcbState ≠ .ext .runningVM + +/-- The premises give `kernelEntry_runExitA`'s conclusion. -/ +theorem ExitEntryHyps.concl {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {m : McState} {Clock : A → MachineState → Prop} {s : S} {a : A} + {σ : State Unit} {Cs : Set U64} {tm : A → Nat → DeadlineViewA} {view : State Unit → Fl4TimerView} + {stop : U64} {stopSpec : RunStop} {w1 w2 w3 : U64} + (h : ExitEntryHyps st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ m Clock s a σ Cs tm view stop stopSpec + w1 w2 w3) : + kCodeA st ar s a (kRunExitE stop w1 w2 w3 stopSpec) ⦃ out => + StepPostA (KExitA st ar AR h.hPl.ipa m) + (kOpA (kRunExitE stop w1 w2 w3 stopSpec) >>= fun _ => fl4Finish kLimitA view) σ out ⦄ := + kernelEntry_runExitA h.hA h.hPl h.arch h.hCs h.P h.J h.I h.hZ h.hstop h.hne w1 w2 w3 h.hGap h.hNat + +/-- **The premises of `kernelEntry_runVppiA`** (module docstring). -/ +structure VppiEntryHyps (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) + (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) + (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (m : McState) + (Clock : A → MachineState → Prop) (s : S) (a : A) (σ : State Unit) (Cs : Set U64) + (tm : A → Nat → DeadlineViewA) (view : State Unit → Fl4TimerView) (irq : U64) : Type where + hA : P0.ArchTotal ar + hPl : ArchPlat ar + arch : ArchSwFA st ar + hCs : ∀ c ∈ Cs, c.val < fl4A64Platform.numNodes + P : FinPlatA ar AR + J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s a σ m + I : VcpuExitInA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m Clock s a σ + hZ : Z.Cs = Cs + hClMask : ∀ a' ms (irq : U64) (b : Bool), Clock a' ms → ar.mask_irq a' irq b ⦃ a'' => Clock a'' ms ⦄ + hGap : ∀ s' a' τ, kBodyA st ar s a (kRunVppiE irq) = ok (s', a') → ((), τ) ∈ (kOpA (kRunVppiE irq) σ).1 → + ∀ m', A64RelS3at st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view + hNat : ∀ s' a' τ, kBodyA st ar s a (kRunVppiE irq) = ok (s', a') → ((), τ) ∈ (kOpA (kRunVppiE irq) σ).1 → + A64RelS3 st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → ∀ τ1 τ2, + ((), τ1) ∈ (fl4Schedule kLimitA view τ).1 → ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → + ∀ y, τ2.kheap τ2.curThread = some (.tcb y) → y.tcbState ≠ .ext .runningVM + +/-- The premises give `kernelEntry_runVppiA`'s conclusion. -/ +theorem VppiEntryHyps.concl {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {m : McState} {Clock : A → MachineState → Prop} {s : S} {a : A} + {σ : State Unit} {Cs : Set U64} {tm : A → Nat → DeadlineViewA} {view : State Unit → Fl4TimerView} {irq : U64} + (h : VppiEntryHyps st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ m Clock s a σ Cs tm view irq) : + kCodeA st ar s a (kRunVppiE irq) ⦃ out => + StepPostA (KExitA st ar AR h.hPl.ipa m) (kOpA (kRunVppiE irq) >>= fun _ => fl4Finish kLimitA view) σ out ⦄ := + kernelEntry_runVppiA h.hA h.hPl h.arch h.hCs h.P h.J h.I h.hZ h.hClMask irq h.hGap h.hNat + +end + +/-! ## `VcpuExitInA` at the model arch -/ + +section ofWit +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} + {κ : U64 → U64} {m : McState} {s : S} {a : Wit2.WA} {σ : State Unit} + +/-- **`VcpuExitInA` at the model arch** (module docstring): all fields from the Send witness's entry record `E`, but +`hScPost` and `ctAct`. -/ +theorem VcpuExitInA.ofWit (O : Wit2.OpaqueWA) + (Ew : KEntryFaultInA st Wit2.AR1 (fun _ _ => True) (fun _ _ => True) Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ + Wit2.ar1_plat.ipa m Wit2.WClock s a σ) + (ctAct : ∀ x, σ.kheap σ.curThread = some (.tcb x) → ActivateStateOKA x.tcbState) + (hScPost : ∀ (sp : S) (ap : Wit2.WA) (ct stop w1 w2 w3 : U64) (s2 : S) (a2 : Wit2.WA) (hw2 : HwRootA) + (σ1 σa σ2 : State Unit) (ss : RunStop), + vcpu.complete_run st Wit2.AR1 sp ap ct stop w1 w2 w3 = ok (s2, a2) → + updateTimeStamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4CompleteRun (Z := Unit) (specPtr ct) ss w1.bv w2.bv w3.bv σa = ({((), σ2)}, False) → DrA σ1 σ2 → + JStage3A st (fun _ _ => True) { Z with hw := hw2 } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ + fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st Wit2.AR1 Wit2.ar1_plat.ipa)) s2 a2 σ2 m → + ScStateRelA st Z.C m s2 σ2 ∧ + (∃ xsc nsc, σ2.kheap σ2.curSc = some (.schedContext xsc nsc) ∧ scActive xsc = true) ∧ + sporadic.min_budget Wit2.AR1 a2 ⦃ mb => mb.bv = MIN_BUDGET ⦄ ∧ + getScRefillSufficient (Z := Unit) σ2.curSc σ2.consumedTime σ2 = ({(true, σ2)}, False)) : + VcpuExitInA st Wit2.AR1 (fun _ _ => True) Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ Wit2.ar1_plat.ipa m + Wit3.WClock' s a σ where + en := ⟨JStage3EntryA.toBase Ew.J.toJStage3EntryA, ctAct⟩ + hNoSw := Ew.J.noSwitch + hNow := Wit3.ar1_now' + hNowAR := fun _ _ _ => (WP.spec_ok _).2 trivial + hClock := Wit3.WClock'.of_eq Ew.hClock + hClVm := fun s' a' ms u h => Wit3.ar1_clVm s' a' ms u h + hClFlushState := Wit3.ar1_clFlushState + hClFr := Wit3.wclock'_fr + hnd := O.nd + hVMT := Ew.J.validTime + hCS := Ew.C + hNowEq := Ew.hNow + hP := Wit3.ar1_vcpuPlat O + hAK := Wit3.ar1_vcpuKeeps + hVR := Wit3.ar1_vcpuVmRoot + hMin := O.hag + hScPost := hScPost + +end ofWit + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/A64Wit3RunA.lean b/proofs/Fl4ProofsA64/P3/A64Wit3RunA.lean new file mode 100644 index 000000000..ed03b5799 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64Wit3RunA.lean @@ -0,0 +1,227 @@ +/- +P3 (aarch64, A64-P4 non-vacuity witness for the VM-exit tops, part 3): **the reached state of the `runExit` entry at the +witness.** + +At `witSA` (the root task running, no VCPU anywhere) the spec body `fl4HandleVcpuRunExit ⟨stopSpec, w1, w2, w3⟩` has one +outcome: + +* `witTs`: the time stamp (`wit_ts`: `updateTimeStamp witSA = witTs`; heap, current thread and SC unchanged, consumed `0`); +* `WitLike σ`: a state that agrees with `witTs` on those (`witTs` itself, `witMk irq` = after the VPPI's IRQ mask); on it + `complete_run` is the identity (no run VCPU), the head refill is sufficient (`sl ≥ MIN_BUDGET`), `checkBudget = true` + and no thread runs a guest (`WitLike.completeRun`, `.getScSuff`, `.checkBudget`, `.noVm`); +* `wit_exitOp` / `wit_vppiOp`: each body has one outcome (`witTs` / `witMk`); `wit_exit_noVm` / `wit_vppi_noVm`: no + thread of it runs a guest (`hNat`'s input, via `hNat_of_noVmA`); +* `wit_scPostD`: **the run-guarded `hScPost`** at the reached state: from `updateTimeStamp witSA = σ1` and `DrA σ1 σ2` (which + pins `curSc`, `consumedTime` and the SC objects to `witTs`), `ScStateRelA`, an active current SC, `min_budget` and a + sufficient head refill hold at `σ2`. + +Named premises: [P] `OpaqueWA`, the witness parameters. New module. +-/ +import Fl4ProofsA64.P3.A64Wit3ExitA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Wit +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P1.W7.R.ST.BootWit Fl4ProofsA64.P3 + Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 + +noncomputable section + +variable {mt sl : U64} {uw : U64 → U64} + +/-- **The time-stamp state at the witness** (the spec's `update_timestamp` on `witSA`). -/ +def witTs (mt sl : U64) (uw : U64 → U64) : State Unit := + fl4TimestampState (rawNextA (witSA wNow mt sl uw).machineState) + { witSA wNow mt sl uw with machineState := rawStateA (witSA wNow mt sl uw).machineState } + +theorem wit_ts (O : Wit2.OpaqueWA) : + updateTimeStamp (Z := Unit) (witSA wNow mt sl uw) = ({((), witTs mt sl uw)}, False) := + (fl4UpdateTimestamp_eq_l4vA _ O.nd (wit_hNow O)).symm.trans (fl4UpdateTimestamp_eqA _) + +theorem witTs_curThread : (witTs mt sl uw).curThread = specPtr (bwv RTb) := rfl + +theorem witTs_curSc : (witTs mt sl uw).curSc = specPtr (bwv SCb) := rfl + +theorem witTs_consumed : (witTs mt sl uw).consumedTime = 0 := by + show (witSA wNow mt sl uw).consumedTime + (wTick - wNow.bv) = 0 + show (0 : Fl4SpecA64.Ticks) + (wTick - wTick) = 0 + simp + +theorem witTs_sc : + (witTs mt sl uw).kheap (specPtr (bwv SCb)) = some (.schedContext (rootScA wNow sl) 0) := + (Function.update_of_ne sc_ne_rt _ _).trans w1KA_sc + +theorem witTs_tcb : (witTs mt sl uw).kheap (witTs mt sl uw).curThread = some (.tcb (witTcbA 2#u64)) := + Function.update_self _ _ _ + +/-- **A state that agrees with the time-stamp state on the heap, the current thread and SC, and has consumed `0`** +(the time-stamp state itself, and the state after the VPPI mask). -/ +def WitLike (mt sl : U64) (uw : U64 → U64) (σ : State Unit) : Prop := + σ.kheap = (witTs mt sl uw).kheap ∧ σ.curSc = (witTs mt sl uw).curSc ∧ σ.curThread = (witTs mt sl uw).curThread ∧ + σ.consumedTime = 0 + +theorem witTs_like : WitLike mt sl uw (witTs mt sl uw) := ⟨rfl, rfl, rfl, witTs_consumed⟩ + +variable {σ : State Unit} + +theorem WitLike.sc (h : WitLike mt sl uw σ) : + σ.kheap (specPtr (bwv SCb)) = some (.schedContext (rootScA wNow sl) 0) := by + rw [h.1]; exact witTs_sc + +theorem WitLike.tcb (h : WitLike mt sl uw σ) : + σ.kheap (witTs mt sl uw).curThread = some (.tcb (witTcbA 2#u64)) := by + rw [h.1]; exact witTs_tcb + +/-- **The head refill is sufficient** (the spec's `getScRefillSufficient`). -/ +theorem WitLike.getScSuff (h : WitLike mt sl uw σ) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) : + getScRefillSufficient (Z := Unit) σ.curSc σ.consumedTime σ = ({(true, σ)}, False) := by + rw [h.2.1, h.2.2.2, witTs_curSc, getScRefillSufficient_eqA h.sc (by simp [rootScA]) 0] + simp [Fl4SpecA64.refillSufficient, Fl4SpecA64.refillCapacity, Fl4SpecA64.refillHd, rootScA, hsl, Fl4SpecA64.the] + +/-- **`complete_run` of a thread with no run VCPU is the identity** (the root TCB has none). -/ +theorem WitLike.completeRun (h : WitLike mt sl uw σ) (stop : RunStop) (w1 w2 w3 : Fl4SpecA64.Word) : + fl4CompleteRun (Z := Unit) (witTs mt sl uw).curThread stop w1 w2 w3 σ = ({((), σ)}, False) := by + have hr : getRunVcpu (Z := Unit) (witTs mt sl uw).curThread σ = ({(none, σ)}, False) := by + rw [getRunVcpu_eqA h.tcb] + rfl + unfold fl4CompleteRun + rw [nd_bind_oneSc hr] + rfl + +theorem WitLike.getRunVcpu (h : WitLike mt sl uw σ) : + getRunVcpu (Z := Unit) (witTs mt sl uw).curThread σ = ({(none, σ)}, False) := by + rw [getRunVcpu_eqA h.tcb] + rfl + +/-- **`checkBudget` answers `true` and keeps the state.** -/ +theorem WitLike.checkBudget (h : WitLike mt sl uw σ) (O : Wit2.OpaqueWA) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) : + checkBudget (Z := Unit) σ = ({(true, σ)}, False) := by + unfold Fl4SpecA64.checkBudget + rw [nd_gets_bindSc, nd_gets_bindSc, nd_bind_oneSc (h.getScSuff hsl), if_pos rfl, nd_gets_bindSc] + simp only [Fl4SpecA64.isCurDomainExpired, O.nd] + rfl + +theorem WitLike.noVm (h : WitLike mt sl uw σ) : NoVmA σ := by + intro p x hp v + rw [h.1] at hp + exact wit_noVm (uw := uw) p x hp v + +/-- **The `runExit` body at the witness has one outcome: the time-stamp state.** -/ +theorem wit_exitOp (O : Wit2.OpaqueWA) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) {stopSpec : RunStop} + (hne : stopSpec ≠ .vppi) (w1 w2 w3 : Fl4SpecA64.Word) : + fl4HandleVcpuRunExit (Z := Unit) ⟨stopSpec, w1, w2, w3⟩ (witSA wNow mt sl uw) = + ({((), witTs mt sl uw)}, False) := by + unfold fl4HandleVcpuRunExit + rw [nd_bind_oneSc (wit_ts O), nd_bind_oneSc (m := NonDet.gets _) rfl] + rw [nd_bind_oneSc (by unfold NonDet.when; rw [if_neg hne]; rfl)] + rw [nd_bind_oneSc (witTs_like.completeRun _ _ _ _), nd_bind_oneSc (witTs_like.checkBudget O hsl)] + rfl + +/-- **No thread of the `runExit` body's outcome runs a guest** (the input of `hNat_of_noVmA`). -/ +theorem wit_exit_noVm (O : Wit2.OpaqueWA) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) {stop : U64} {stopSpec : RunStop} + (hne : stopSpec ≠ .vppi) (w1 w2 w3 : U64) {τ : State Unit} + (op : ((), τ) ∈ (kOpA (kRunExitE stop w1 w2 w3 stopSpec) (witSA wNow mt sl uw)).1) : NoVmA τ := by + have op' : ((), τ) ∈ (fl4HandleVcpuRunExit (Z := Unit) ⟨stopSpec, w1.bv, w2.bv, w3.bv⟩ + (witSA wNow mt sl uw)).1 := op + rw [wit_exitOp O hsl hne] at op' + have e : τ = witTs mt sl uw := (Prod.mk.inj (Set.mem_singleton_iff.1 op')).2 + subst e + exact witTs_like.noVm + +/-- **The root SC's head refill is sufficient.** -/ +theorem rootSc_suff (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) : + refillSufficient 0 (refillHd (rootScA wNow sl)) = true := by + simp [Fl4SpecA64.refillSufficient, Fl4SpecA64.refillCapacity, Fl4SpecA64.refillHd, rootScA, hsl, Fl4SpecA64.the] + +/-- **The guarded `hScPost` at the witness** (`VcpuExitInA.hScPost`, both exits): from the time stamp at `witSA` and +`DrA σ1 σ2` (which pins `curSc`, `consumedTime` and the SC objects to the time-stamp state). -/ +theorem wit_scPostD {S : Type} {st : machine.Store S} [L : LawfulStore st] (O : Wit2.OpaqueWA) + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {m : McState} {s2 : S} {a2 : Wit2.WA} {hw2 : HwRootA} {σ1 σ2 : State Unit} + (hts : updateTimeStamp (Z := Unit) (witSA wNow mt sl uw) = ({((), σ1)}, False)) (K : DrA σ1 σ2) + (J2 : JStage3A st (fun _ _ => True) { Z with hw := hw2 } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ + fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st Wit2.AR1 Wit2.ar1_plat.ipa)) s2 a2 σ2 m) : + ScStateRelA st Z.C m s2 σ2 ∧ + (∃ xsc nsc, σ2.kheap σ2.curSc = some (.schedContext xsc nsc) ∧ scActive xsc = true) ∧ + sporadic.min_budget Wit2.AR1 a2 ⦃ mb => mb.bv = MIN_BUDGET ⦄ ∧ + getScRefillSufficient (Z := Unit) σ2.curSc σ2.consumedTime σ2 = ({(true, σ2)}, False) := by + have e1 : σ1 = witTs mt sl uw := + (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (hts.symm.trans (wit_ts O))))).2 + subst e1 + have hcs : σ2.curSc = specPtr (bwv SCb) := K.csc + obtain ⟨y, k, hk⟩ := J2.sinv.curSc + have hk1 := K.sc _ y k hk + rw [hcs] at hk hk1 + rw [witTs_sc] at hk1 + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hk1) + refine ⟨J2.sr.scr, ⟨_, _, by rw [hcs]; exact hk, by simp [rootScA, scActive, activeSc]⟩, + Wit2.ar1_minBudget _, ?_⟩ + rw [hcs, K.cons, witTs_consumed, getScRefillSufficient_eqA hk (by simp [rootScA]) 0, rootSc_suff hsl] + +/-! ## `runVppi` -/ + +/-- **The state after the VPPI's IRQ mask** (the time-stamp state with `irq` masked). -/ +abbrev witMk (mt sl : U64) (uw : U64 → U64) (irq : Fl4SpecA64.Word) : State Unit := + { witTs mt sl uw with machineState := + { (witTs mt sl uw).machineState with + irqMasks := Function.update (witTs mt sl uw).machineState.irqMasks (ucast irqLen irq) true } } + +theorem witMk_like (irq : Fl4SpecA64.Word) : WitLike mt sl uw (witMk mt sl uw irq) := + ⟨rfl, rfl, rfl, witTs_consumed⟩ + +theorem witVppi_when_eq (ct : ObjRef) (irq : Word) (σ1 : State Unit) : + (do let vcOpt ← getRunVcpu (Z := Unit) ct + match vcOpt with + | some vc => NonDet.when (irq = 27) do + let v ← getVcpu vc + let mk := Function.update v.vcpuVppiMasked .vppiEventIRQ_VTimer true + setVcpu vc { v with vcpuVppiMasked := mk } + | none => pure () + doMachineOp (maskInterrupt true (ucast irqLen irq))) σ1 = + ((do let vcOpt ← getRunVcpu (Z := Unit) ct + match vcOpt with + | some vc => NonDet.when (irq = 27) do + let v ← getVcpu vc + let mk := Function.update v.vcpuVppiMasked .vppiEventIRQ_VTimer true + setVcpu vc { v with vcpuVppiMasked := mk } + | none => pure ()) >>= fun _ => doMachineOp (maskInterrupt true (ucast irqLen irq))) σ1 := by + rw [nd_bind_assocSc] + apply congrFun; apply congrArg (Bind.bind (getRunVcpu ct)); funext vcOpt + cases vcOpt with + | some vc => rfl + | none => funext s; rw [nd_bind_oneSc (m := pure ()) rfl] + +/-- **The `runVppi` body at the witness has one outcome: the masked time-stamp state.** -/ +theorem wit_vppiOp (O : Wit2.OpaqueWA) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (irq : Fl4SpecA64.Word) : + fl4HandleVcpuRunExit (Z := Unit) ⟨.vppi, irq, 0, 0⟩ (witSA wNow mt sl uw) = + ({((), witMk mt sl uw irq)}, False) := by + have hsp_vp : (do let vcOpt ← getRunVcpu (Z := Unit) (witTs mt sl uw).curThread + match vcOpt with + | some vc => NonDet.when (irq = 27) do + let v ← getVcpu vc + let mk := Function.update v.vcpuVppiMasked .vppiEventIRQ_VTimer true + setVcpu vc { v with vcpuVppiMasked := mk } + | none => pure ()) (witTs mt sl uw) = ({((), witTs mt sl uw)}, False) := by + rw [nd_bind_oneSc witTs_like.getRunVcpu] + rfl + unfold fl4HandleVcpuRunExit + rw [nd_bind_oneSc (wit_ts O), nd_bind_oneSc (m := NonDet.gets _) rfl] + rw [nd_bind_oneSc (by + rw [NonDet.when, if_pos rfl] + exact (witVppi_when_eq (witTs mt sl uw).curThread irq (witTs mt sl uw)).trans + (by rw [nd_bind_oneSc hsp_vp, maskInterrupt_stateA]))] + rw [nd_bind_oneSc ((witMk_like irq).completeRun _ _ _ _), nd_bind_oneSc ((witMk_like irq).checkBudget O hsl)] + rfl + +/-- **No thread of the `runVppi` body's outcome runs a guest.** -/ +theorem wit_vppi_noVm (O : Wit2.OpaqueWA) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (irq : U64) {τ : State Unit} + (op : ((), τ) ∈ (kOpA (kRunVppiE irq) (witSA wNow mt sl uw)).1) : NoVmA τ := by + have op' : ((), τ) ∈ (fl4HandleVcpuRunExit (Z := Unit) ⟨.vppi, irq.bv, 0, 0⟩ (witSA wNow mt sl uw)).1 := op + rw [wit_vppiOp O hsl] at op' + have e : τ = witMk mt sl uw irq.bv := (Prod.mk.inj (Set.mem_singleton_iff.1 op')).2 + subst e + exact (witMk_like _).noVm + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64Wit3TopA.lean b/proofs/Fl4ProofsA64/P3/A64Wit3TopA.lean new file mode 100644 index 000000000..39cf7f2fe --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64Wit3TopA.lean @@ -0,0 +1,123 @@ +/- +P3 (aarch64, A64-P4 non-vacuity witness for the VM-exit tops, part 4): **`kernelEntry_runExitA` and +`kernelEntry_runVppiA` at the witness.** + +* `wit_exitHyps` / `wit_vppiHyps`: an inhabitant of `ExitEntryHyps` / `VppiEntryHyps` (the tops' binders) at the Send + witness's state `witS` / `witSA` (the root task running, no VCPU), for every `stop`, `w1 w2 w3`, `irq`: the model arch + `AR1` and `witArchSwOf`, `WClock'` (`A64Wit3ClockA`), the entry record of `wit_entryIn`, `VcpuExitInA.ofWit` with the + run-guarded `hScPost` from `wit_scPostD` and the activation state of the root TCB, `hGap` from `wit2b_hGapA` and `hNat` + from `NoVmA` at the body's one outcome (`A64Wit3RunA`). `.concl` is the tops' conclusion there. +* `wit_runexit_nonvacuous` / `wit_runvppi_nonvacuous`: with `OpaqueWA` the only hypothesis, every witness-side parameter + is existential. + +Scope: the witness covers the budget-sufficient exit of a current thread with no VCPU (`complete_run`'s `none` arm). A +guest entry with a VCPU object (Tier 1: the `some vc` arm and the VCPU clauses of `JStage3A`) is not witnessed. + +Named premises: [P] `OpaqueWA`. New module. +-/ +import Fl4ProofsA64.P3.A64Wit3RunA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Wit +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P1.W7.R.ST.BootWit Fl4ProofsA64.P3 + Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry + Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 + +noncomputable section + +/-- The root TCB's state is one activation accepts (`running`). -/ +theorem wit_ctAct {mt sl : U64} {uw : U64 → U64} : + ∀ x, (witSA wNow mt sl uw).kheap (witSA wNow mt sl uw).curThread = some (.tcb x) → + ActivateStateOKA x.tcbState := by + intro x hx + have hk : (witSA wNow mt sl uw).kheap (witSA wNow mt sl uw).curThread = some (.tcb (witTcbA 2#u64)) := + Function.update_self _ _ _ + rw [hk] at hx + obtain rfl := KernelObject.tcb.inj (Option.some.inj hx) + exact Or.inl rfl + +/-- **The premises of `kernelEntry_runExitA` at the witness** (`ExitEntryHyps`'s type). -/ +abbrev WExitHyps (r mt sl : U64) (uw : U64 → U64) (a : Wit2.WA) (stop : U64) (stopSpec : RunStop) + (w1 w2 w3 : U64) : Type := + ExitEntryHyps bst Wit2.AR1 (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U + (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv (IB : U64).val + ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) Wit3.WClock' + (witS r wNow mt sl uw) a (witSA wNow mt sl uw) witZA.Cs Wit2.witTm + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witS r wNow mt sl uw) a (kRunExitE stop w1 w2 w3 stopSpec))) + stop stopSpec w1 w2 w3 + +/-- **The premises of `kernelEntry_runVppiA` at the witness** (`VppiEntryHyps`'s type). -/ +abbrev WVppiHyps (r mt sl : U64) (uw : U64 → U64) (a : Wit2.WA) (irq : U64) : Type := + VppiEntryHyps bst Wit2.AR1 (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U + (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv (IB : U64).val + ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) Wit3.WClock' + (witS r wNow mt sl uw) a (witSA wNow mt sl uw) witZA.Cs Wit2.witTm + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witS r wNow mt sl uw) a (kRunVppiE irq))) irq + +/-- **`kernelEntry_runExitA`'s premises at the witness** (module docstring). -/ +def wit_exitHyps (O : Wit2.OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) + (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : Wit2.WA) + (ha : Wit2.WClock a (witSA wNow mt sl uw).machineState) {stop : U64} {stopSpec : RunStop} + (hstop : stop.bv = stopSpec.word) (hne : stopSpec ≠ .vppi) (w1 w2 w3 : U64) : + WExitHyps r mt sl uw a stop stopSpec w1 w2 w3 := + let Ew := wit_entryIn O hsl hr a ha + { hA := Wit2.ar1_total + hPl := Wit2.ar1_plat + arch := Wit2.witArchSwOf + hCs := wit_hCs O + P := Wit2.ar1_finPlat O + J := Ew.J.toJStage3EntryA.toJStage3A + I := VcpuExitInA.ofWit O Ew wit_ctAct + (fun _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ hts _ K J2 => wit_scPostD O hsl hts K J2) + hZ := rfl + hstop := hstop + hne := hne + hGap := Wit2.wit2b_hGapA O Wit2.witArchSwOf (wit_hCs O) _ a _ (kRunExitE stop w1 w2 w3 stopSpec) + hNat := hNat_of_noVmA fun _ _ _ _ op _ => wit_exit_noVm O hsl hne w1 w2 w3 op } + +/-- **`kernelEntry_runVppiA`'s premises at the witness** (module docstring). -/ +def wit_vppiHyps (O : Wit2.OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) + (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : Wit2.WA) + (ha : Wit2.WClock a (witSA wNow mt sl uw).machineState) (irq : U64) : + WVppiHyps r mt sl uw a irq := + let Ew := wit_entryIn O hsl hr a ha + { hA := Wit2.ar1_total + hPl := Wit2.ar1_plat + arch := Wit2.witArchSwOf + hCs := wit_hCs O + P := Wit2.ar1_finPlat O + J := Ew.J.toJStage3EntryA.toJStage3A + I := VcpuExitInA.ofWit O Ew wit_ctAct + (fun _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ hts _ K J2 => wit_scPostD O hsl hts K J2) + hZ := rfl + hClMask := Wit3.ar1_clMask + hGap := Wit2.wit2b_hGapA O Wit2.witArchSwOf (wit_hCs O) _ a _ (kRunVppiE irq) + hNat := hNat_of_noVmA fun _ _ _ _ op _ => wit_vppi_noVm O hsl irq op } + +set_option maxHeartbeats 1000000 in +/-- **Non-vacuity of `kernelEntry_runExitA`**: with `OpaqueWA` the only hypothesis, every witness-side parameter is +existential and instantiated by a concrete value. -/ +theorem wit_runexit_nonvacuous (O : Wit2.OpaqueWA) : + ∃ (r mt sl : U64) (uw : U64 → U64) (a : Wit2.WA) (stop : U64) (stopSpec : RunStop) (w1 w2 w3 : U64), + Nonempty (WExitHyps r mt sl uw a stop stopSpec w1 w2 w3) := by + obtain ⟨r, hr⟩ := wit_r_ex + obtain ⟨uw, -⟩ := witUw_ex + exact ⟨r, 0#u64, ⟨Fl4SpecA64.MIN_BUDGET⟩, uw, + witA0 (witSA wNow 0#u64 ⟨Fl4SpecA64.MIN_BUDGET⟩ uw).machineState, ⟨RunStop.vmFault.word⟩, .vmFault, 0#u64, 0#u64, 0#u64, + ⟨wit_exitHyps O (BitVec.le_refl _) hr (witA0 (witSA wNow 0#u64 ⟨Fl4SpecA64.MIN_BUDGET⟩ uw).machineState) rfl + (stop := ⟨RunStop.vmFault.word⟩) (stopSpec := .vmFault) rfl (by decide) 0#u64 0#u64 0#u64⟩⟩ + +set_option maxHeartbeats 1000000 in +/-- **Non-vacuity of `kernelEntry_runVppiA`.** -/ +theorem wit_runvppi_nonvacuous (O : Wit2.OpaqueWA) : + ∃ (r mt sl : U64) (uw : U64 → U64) (a : Wit2.WA) (irq : U64), Nonempty (WVppiHyps r mt sl uw a irq) := by + obtain ⟨r, hr⟩ := wit_r_ex + obtain ⟨uw, -⟩ := witUw_ex + exact ⟨r, 0#u64, ⟨Fl4SpecA64.MIN_BUDGET⟩, uw, + witA0 (witSA wNow 0#u64 ⟨Fl4SpecA64.MIN_BUDGET⟩ uw).machineState, 27#u64, + ⟨wit_vppiHyps O (BitVec.le_refl _) hr (witA0 (witSA wNow 0#u64 ⟨Fl4SpecA64.MIN_BUDGET⟩ uw).machineState) rfl + 27#u64⟩⟩ + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitCopyA.lean b/proofs/Fl4ProofsA64/P3/A64WitCopyA.lean index 17acdb3c3..353e5ee3a 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitCopyA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitCopyA.lean @@ -56,7 +56,7 @@ local notation "RC" => capability.Cap.CNode (bwv RRb) 13#u64 51#u64 0#u64 /-! ## Reads -/ theorem regW2 (i : U64) (hi : i.val < 6) : - obj.Tcb.reg bst RT S2 i = ok (witRtW (256 + 8 * i.val)) := by + obj.Tcb.reg bst RT S2 i = ok (witRtW 2#u64 (256 + 8 * i.val)) := by rw [tcb_reg_eqA] have v : (regWA RT i).val = RTb + (256 + 8 * i.val) := by have h := Endp.regA_val (t := RT) (i := i) rtAddr (by omega) @@ -123,7 +123,7 @@ theorem tcbSlot_ok (i : U64) (hi : i.val < 7) : obj.Tcb.slot RT i = ok (slotIdx theorem wit_msgInfo : msg.msg_info bst S2 RT = ok { label := 24#u64, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := 5#u64 } := by have e : layout.reg.MSG_INFO = 1#u64 := by simp [layout.reg.MSG_INFO, layout.reg.X1] - have v : witRtW (256 + 8 * (1#u64 : U64).val) = 98437#u64 := by simp [witRtW] + have v : witRtW 2#u64 (256 + 8 * (1#u64 : U64).val) = 98437#u64 := by simp [witRtW] have s12 : (98437#u64 : U64) >>> 12#i32 = ok 24#u64 := by rfl have s9 : (98437#u64 : U64) >>> 9#i32 = ok 192#u64 := by rfl have s7 : (98437#u64 : U64) >>> 7#i32 = ok 769#u64 := by rfl @@ -345,7 +345,7 @@ theorem wit_decodeOk (U : WitUw uw) {A : Type} (ar : machine.Arch A) (a : A) (bl ok (.Ok (), s', a) := by have ct : sched.cur_thread bst S2 = ok RT := by rw [cur_thread_ok, curW2] have arg : ∀ (i k : U64), i.val < 4 → msg.msg_register i = ok k → k.val < 6 → - msg.syscall_arg bst S2 RT (bwv IPb) i = ok (witRtW (256 + 8 * k.val)) := fun i k hi e hk => by + msg.syscall_arg bst S2 RT (bwv IPb) i = ok (witRtW 2#u64 (256 + 8 * k.val)) := fun i k hi e hk => by unfold msg.syscall_arg have n : msg.N_MSG_REGISTERS = 4#u64 := by simp [msg.N_MSG_REGISTERS] rw [n, if_pos (by scalar_tac), e, bind_ok, regW2 k hk] diff --git a/proofs/Fl4ProofsA64/P3/A64WitIrqA.lean b/proofs/Fl4ProofsA64/P3/A64WitIrqA.lean new file mode 100644 index 000000000..63baeae29 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitIrqA.lean @@ -0,0 +1,483 @@ +/- +P3 (aarch64, A64-P4 irqtop, S6 part 1): **the interrupt-entry witness state.** + +The interrupt top (`kernelEntryIrq_recGA`) needs an accepted line that FL4's state does not call inactive (`IrqLineA.active`). +A64-Boot's `init_irq_states` already leaves the SGI / PPI lines `0 .. 31` at `IRQ_RESERVED` (`irqW`, word 4), so the +witness takes line `wIrq = 5` at the *same store* `witS` as the Send witness. The spec's machine state differs only by the +mask of that line (initially every line is masked; the accepted line must be unmasked: `OracleIrqA`), which is +`JStage3A.of_machA` away. + +* `witISA`: `witSA` with line `wIrq` unmasked; `wit_irqJ`: the entry record `JSyscallA` there. +* `wit_hsufI`: the head refill is sufficient at the state the timestamp reaches (as `wit_hsuf`), so the exhausted-budget + branch (`hCharge`, `hsch`) is vacuous. +* `wit_budgetIdI`: the budget prefix is the identity on the store, and its spec state. + +Named premises: `OpaqueWA` [P]. New module; no existing statement changed. +-/ +import Fl4ProofsA64.P3.A64Wit2TopA +import Fl4ProofsA64.P3.Stage3KEntryIrqTopA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Wit +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P1.W7.R.ST.BootWit Fl4ProofsA64.P3 + Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 + +noncomputable section + +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA WClock) + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR AR' : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {nA : U64} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 2000000 in +/-- **A sufficient `check_budget` after a fixpoint of the timestamp is the identity** (`JSyscallA.budgetOkIdA` for the +interrupt entry's `check_budget`). -/ +theorem _root_.Fl4ProofsA64.P3.JSyscallA.checkBudgetIdA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar nA)) s a σ m) + (hvp : ∀ b, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ ¬ PPW st s b) + {Clock : A → MachineState → Prop} (P : NowAgreeA ar Clock) (hClock : Clock a σ.machineState) + (hnd : numDomains = 1) (C : CounterStepA σ) + (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) + (hAr : sched.update_timestamp st ar s a ⦃ r => AR' r.2 Z.hw ⦄) + (hmb : ∀ a', Fl4MinBudgetAgreeA ar a') {a1 : A} + (e1 : sched.update_timestamp st ar s a = ok (s, a1)) + (hsuf : ∀ σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(true, σ1)}, False)) : + sched.check_budget st ar s a1 = ok (true, s, a1) ∧ + ∀ σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4CheckBudget (Z := Unit) σ1 = ({(true, σ1)}, False) := by + have ts := J.toJStage3A.timestampA J.sact J.noSwitch hvp P hClock hnd J.validTime C J.curInv J.offReady J.actIdle + hNow hAr + obtain ⟨⟨s2, a2⟩, e2, σ1, e1σ, J1, sa1, -, V1, CI1, R1, Act1, Cl1, Ent1⟩ := spec_existsA ts + have eq2 : (s2, a2) = (s, a1) := ok_inj_ff (e2.symm.trans e1) + obtain ⟨hs2, ha2⟩ := Prod.mk.inj eq2 + obtain ⟨b, dec, spec, off⟩ := spec_existsA (entryBudgetDecisionA J1.sr.toSchedSRN CI1 J1.sinv.mc a2 (hmb a2)) + have hb : b = true := by + have h := hsuf σ1 e1σ + rw [spec] at h + exact (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst h))).1 + subst hb + rw [hs2, ha2] at dec + obtain ⟨code, cb⟩ := budgetSuffA (st := st) (ar := ar) dec spec hnd + refine ⟨code, fun σ1' h => ?_⟩ + have : σ1' = σ1 := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (h.symm.trans e1σ)))).2 + subst this + exact cb + +end + +/-- **The accepted line of the interrupt witness**: an SGI / PPI, `IRQ_RESERVED` after boot. -/ +def wIrq : U64 := 5#u64 + +/-- **The spec state of the interrupt witness**: `witSA` with line `wIrq` unmasked. -/ +def witISA (mt sl : U64) (uw : U64 → U64) : Fl4SpecA64.State Unit := + { witSA wNow mt sl uw with machineState := irqUnmaskedMsA (witSA wNow mt sl uw).machineState wIrq } + +variable {r mt sl : U64} {uw : U64 → U64} + +/-- **The entry record of the interrupt witness**: the Send witness's, at the machine state with the line unmasked. -/ +theorem wit_irqJ (O : OpaqueWA) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) + (a : WA) : + JSyscallA bst (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U (w1H KB IB 1).scs + (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv (IB : U64).val ((IB : U64).val + 1 * 8192) + ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) Fl4SpecA64.fl4A64Platform.numNodes (J5A bst) + (J7A bst (J7R2A bst AR1 Wit2.ar1_plat.ipa)) (witS r wNow mt sl uw) a (witISA mt sl uw) (w1MA IB 1) := by + have Jo : JSyscallA bst (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U (w1H KB IB 1).scs + (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv (IB : U64).val ((IB : U64).val + 1 * 8192) + ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) Fl4SpecA64.fl4A64Platform.numNodes (J5A bst) + (J7A bst (J7R2A bst AR1 Wit2.ar1_plat.ipa)) (witS r wNow mt sl uw) a (witSA wNow mt sl uw) (w1MA IB 1) := by + rw [O.nodes] + exact wit_syscallA (fun _ _ => True) Wit2.witArA (a := a) r wNow mt sl uw Wit2.ar1_plat.ipa trivial O.nodes hsl hr + have Jn := Jo.toJStage3A.of_machA (a2 := a) trivial (irqUnmaskedMsA (witSA wNow mt sl uw).machineState wIrq) rfl + obtain ⟨c1, c2, c3, c4⟩ := Jo.curInv + obtain ⟨s1, s2⟩ := Jo.sact + exact + { toJStage3EntryA := + { toJStage3A := Jn, curInv := ⟨c1, c2, c3, c4⟩, offOK := Jo.offOK, offReady := Jo.offReady, + actIdle := Jo.actIdle, curScNotIdle := Jo.curScNotIdle, validTime := Jo.validTime, sact := ⟨s1, s2⟩ } + act := Jo.act, running := Jo.running, curSc := Jo.curSc, cur := Jo.cur } + +/-- **The head refill is sufficient** at every state the timestamp reaches from the interrupt witness. -/ +theorem wit_hsufI (O : OpaqueWA) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) {σ1 : Fl4SpecA64.State Unit} + (e : fl4UpdateTimestamp (Z := Unit) (witISA mt sl uw) = ({((), σ1)}, False)) : + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(true, σ1)}, False) := by + have eτ := Sched.fl4UpdateTimestamp_eqA (witISA mt sl uw) + rw [e] at eτ + have h : σ1 = fl4TimestampState (Sched.rawNextA (witISA mt sl uw).machineState) + { witISA mt sl uw with machineState := Sched.rawStateA (witISA mt sl uw).machineState } := + (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst eτ))).2 + have hk : σ1.kheap (specPtr (bwv SCb)) = some (.schedContext (rootScA wNow sl) 0) := by + rw [h] + exact (Function.update_of_ne sc_ne_rt _ _).trans w1KA_sc + have hcs : σ1.curSc = specPtr (bwv SCb) := by rw [h]; rfl + have hu : σ1.consumedTime = 0 := by + rw [h] + show (witSA wNow mt sl uw).consumedTime + (wTick - wNow.bv) = 0 + show (0 : Fl4SpecA64.Ticks) + (wTick - wTick) = 0 + simp + rw [hcs, hu, Sched.fl4GetScRefillSufficient_eqA hk (by simp [rootScA]) 0] + have hmin := O.hag + simp [fl4RefillSufficient, refillCapacity, refillHd, rootScA, hmin, hsl, Fl4SpecA64.the] + +/-- **The budget prefix at the interrupt witness**: the timestamp and the sufficient `check_budget` are the identity on +the store. -/ +theorem wit_budgetIdI (O : OpaqueWA) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) + (a : WA) (ha : WClock a (witISA mt sl uw).machineState) : + ∃ a1, sched.update_timestamp bst AR1 (witS r wNow mt sl uw) a = ok (witS r wNow mt sl uw, a1) ∧ + sched.check_budget bst AR1 (witS r wNow mt sl uw) a1 = ok (true, witS r wNow mt sl uw, a1) ∧ + ∀ σ1, fl4UpdateTimestamp (Z := Unit) (witISA mt sl uw) = ({((), σ1)}, False) → + fl4CheckBudget (Z := Unit) σ1 = ({(true, σ1)}, False) := by + have J := wit_irqJ O hsl hr a (uw := uw) (mt := mt) (r := r) + have C : Sched.CounterStepA (witISA mt sl uw) := BitVec.le_refl _ + have hNow : fl4ReadRawCounter (witISA mt sl uw).machineState = getCurrentTime (witISA mt sl uw).machineState := + O.hNow _ rfl + have hAr : sched.update_timestamp bst AR1 (witS r wNow mt sl uw) a ⦃ r => (fun _ _ => True) r.2 witZA.hw ⦄ := + WP.spec_mono (Fl4ProofsA64.P0.sched.update_timestamp.p0 bst AR1 _ a bstTotal Wit2.ar1_total) fun _ _ => trivial + obtain ⟨a1, -, e1⟩ := J.budgetOkIdA (AR' := fun _ _ => True) wit_hvp Wit2.ar1_now ha O.nd C hNow hAr + (Wit2.ar1_fl4MinBudget O) ((J.sr.sch.time).symm.trans rfl) (fun _ e => wit_hsufI O hsl e) (fun b => bwr_self _ b) + obtain ⟨c1, c2⟩ := J.checkBudgetIdA (AR' := fun _ _ => True) wit_hvp Wit2.ar1_now ha O.nd C hNow hAr + (Wit2.ar1_fl4MinBudget O) e1 (fun _ e => wit_hsufI O hsl e) + exact ⟨a1, e1, c1, c2⟩ + +/-- **[P] `EntryIrqAgreeA` at the witness line**: line 5 is neither the VGIC maintenance interrupt nor the virtual timer. -/ +theorem wit_hres : EntryIrqAgreeA wIrq := fun _ => + ⟨by + intro h + have h5 := congrArg BitVec.toNat h + simp [wIrq, irqVGICMaintenance, irqLen, irqBits] at h5, by + simp only [irqVppiEventIndex, irqVTimerEvent, wIrq] + refine if_neg ?_ + intro h + have h5 := congrArg BitVec.toNat h + simp [irqLen, irqBits] at h5⟩ + +/-- `irq::id` of the witness line is the line. -/ +theorem wit_id : layout.irq.id wIrq = ok wIrq := by + obtain ⟨b, hb, vb⟩ := spec_existsA Fl4ProofsA64.P0.Consts.layout.irq.LPI_BASE.spec + unfold layout.irq.id + rw [hb, bind_ok] + have h1 : ¬ (wIrq ≥ b) := by rw [vb]; decide + have h2 : ¬ (wIrq ≥ layout.irq.BANKED_BASE) := by + intro h + simp only [wIrq] at h + scalar_tac + rw [if_neg h1, if_neg h2] + +/-- **The accepted line is not inactive** (`IrqLineBaseA` at the witness store): A64-Boot leaves line 5 `IRQ_RESERVED`. -/ +theorem wit_lineBase (O : OpaqueWA) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) + (a : WA) : IrqLineBaseA bst (witS r wNow mt sl uw) wIrq := by + have J := wit_irqJ O hsl hr a (uw := uw) (mt := mt) (r := r) + have hi : wIrq.val < 5376 := by decide + have e := J.toJStage3A.j.1.irq.st wIrq hi + have e0 : (witISA mt sl uw).interruptStates (BitVec.ofNat 13 wIrq.val) = .irqReserved := by + show irqStOfA (Fl4ProofsA64.P1.W7.R.ST.BootWit.irqW (BitVec.ofNat 13 wIrq.val).toNat) = .irqReserved + first | decide | simp [irqStOfA, Fl4ProofsA64.P1.W7.R.ST.BootWit.irqW, wIrq] + rw [e0] at e + refine ⟨by decide, fun _ hz => ?_, fun _ h3 => ?_⟩ + · rw [hz] at e + simp [irqStOfA] at e + · rw [wit_id] + intro h + have := ok_inj_ff h + revert this + decide + +/-- **The accepted interrupt is the oracle's** at the state the budget prefix reaches. -/ +theorem wit_orc (hL : ∀ n, irqOracle n = BitVec.ofNat 13 wIrq.val) {σ1 : Fl4SpecA64.State Unit} + (e1σ : fl4UpdateTimestamp (Z := Unit) (witISA mt sl uw) = ({((), σ1)}, False)) : OracleIrqA wIrq σ1 := by + refine ⟨hL _, ?_⟩ + have eτ := Sched.fl4UpdateTimestamp_eqA (witISA mt sl uw) + rw [e1σ] at eτ + have h : σ1 = fl4TimestampState (Sched.rawNextA (witISA mt sl uw).machineState) + { witISA mt sl uw with machineState := Sched.rawStateA (witISA mt sl uw).machineState } := + (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst eτ))).2 + rw [h] + simp [fl4TimestampState, Sched.rawStateA, witISA, irqUnmaskedMsA] + exact Function.update_self .. + +/-! ## No guest runs after the interrupt body -/ + +/-- The outcomes of a machine operation embedded in the kernel state. -/ +theorem mem_doMachineOpA {α : Type} (mop : MachineMonad α) (σ : State Unit) {o : α} {σ2 : State Unit} + (h : (o, σ2) ∈ (doMachineOp (Z := Unit) mop σ).1) : + ∃ ms', (o, ms') ∈ (mop σ.machineState).1 ∧ σ2 = { σ with machineState := ms' } := by + unfold doMachineOp at h + rw [nd_gets_bindA] at h + obtain ⟨⟨⟨r, ms'⟩, σ'⟩, h1, h2⟩ := mem_bindA.1 h + obtain ⟨hm, e⟩ := h1 + have e' : σ' = σ := e + rw [e'] at h2 + change (o, σ2) ∈ ((NonDet.modify (fun state : State Unit => { state with machineState := ms' }) >>= fun _ => + NonDet.pure r) σ).1 at h2 + rw [nd_modify_bindA] at h2 + have h3 : (o, σ2) = (r, { σ with machineState := ms' }) := h2 + obtain ⟨rfl, rfl⟩ := Prod.mk.inj h3 + exact ⟨ms', hm, rfl⟩ + +/-- **The oracle's only outcome**: with the oracle at `i` and the line unmasked, `getActiveIRQ false` yields `i` and +only counts the read. -/ +theorem getActiveIRQ_eqA (ms : MachineState) (i : Irq) (ho : irqOracle (ms.irqState + 1) = i) + (hm : ms.irqMasks i = false) : (getActiveIRQ false ms).1 = {(some i, irqBumpA ms)} := by + unfold getActiveIRQ irqBumpA + simp [NonDet.gets, NonDet.modify, NonDet.bind, NonDet.pure, Function.comp, ho, hm, Bind.bind, Pure.pure] + +theorem handleReservedIrq_vm {i : Irq} (h1 : i ≠ irqVGICMaintenance) (h2 : irqVppiEventIndex i = none) : + PresR VmKA (handleReservedIrq (Z := Unit) i) := by + have e : handleReservedIrq (Z := Unit) i = pure () := by + unfold handleReservedIrq NonDet.when + simp [h1, h2] + first | done | exact nd_pure_bindA () (fun _ => pure ()) + rw [e] + exact PresR.pure _ + +instance (i : Irq) : VPresInst (getIrqState (Z := Unit) i) := ⟨by unfold getIrqState; exact PresR.gets _⟩ +instance (i : Irq) : VPresInst (getIrqSlot (Z := Unit) i) := ⟨by unfold getIrqSlot; exact PresR.gets _⟩ + +instance (n : ObjRef) (b : Badge) : VPresInst (sendSignal (Z := Unit) n b) := ⟨sendSignal_vm n b⟩ + +theorem fl4HandleInterrupt_vm {i : Irq} (h1 : i ≠ irqVGICMaintenance) (h2 : irqVppiEventIndex i = none) : + PresR VmKA (fl4HandleInterrupt (Z := Unit) i) := by + haveI : VPresInst (handleReservedIrq (Z := Unit) i) := ⟨handleReservedIrq_vm h1 h2⟩ + unfold fl4HandleInterrupt fl4ArchMaskIrqSignal + vmpres + +/-- The service `fl4MaybeHandleInterrupt false` creates no `runningVM` thread when the oracle yields `i`. -/ +theorem maybeHandle_vm (σ : State Unit) (i : Irq) + (hg : (getActiveIRQ false σ.machineState).1 = {(some i, irqBumpA σ.machineState)}) + (h1 : i ≠ irqVGICMaintenance) (h2 : irqVppiEventIndex i = none) {τ : State Unit} + (h : ((), τ) ∈ (fl4MaybeHandleInterrupt (Z := Unit) false σ).1) : VmKA σ τ := by + unfold fl4MaybeHandleInterrupt at h + obtain ⟨⟨o, σ3⟩, h5, h6⟩ := mem_bindA.1 h + obtain ⟨ms', hms', rfl⟩ := mem_doMachineOpA _ _ h5 + rw [hg] at hms' + have hms'' : (o, ms') = (some i, irqBumpA σ.machineState) := hms' + obtain ⟨rfl, rfl⟩ := Prod.mk.inj hms'' + have := fl4HandleInterrupt_vm (i := i) h1 h2 _ ((), τ) (by simpa using h6) + exact fun p y hy v => this p y hy v + +/-- **No thread runs a guest after any outcome of the witness's interrupt body.** -/ +theorem wit_bodyNoVmI (hL : ∀ n, irqOracle n = BitVec.ofNat 13 wIrq.val) (O : OpaqueWA) + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) + (ha : WClock a (witISA mt sl uw).machineState) {τ : State Unit} + (h : ((), τ) ∈ (kOpA (.interrupt wIrq (fl4MaybeHandleInterrupt (Z := Unit) false)) (witISA mt sl uw)).1) : + NoVmA τ := by + obtain ⟨a1, e1, ecb, cbσ⟩ := wit_budgetIdI O hsl hr a ha (uw := uw) (mt := mt) (r := r) + have eX := Sched.fl4UpdateTimestamp_eqA (witISA mt sl uw) + have nv : NoVmA (witISA mt sl uw) := fun p x hp v => + wit_noVm (now := wNow) (mt := mt) (sl := sl) (uw := uw) p x hp v + change ((), τ) ∈ ((fl4AcceptedIrqBody (fl4MaybeHandleInterrupt (Z := Unit) false)) (witISA mt sl uw)).1 at h + unfold fl4AcceptedIrqBody at h + obtain ⟨⟨u, σ1⟩, h1, h2⟩ := mem_bindA.1 h + rw [eX] at h1 + have h1' : (u, σ1) = ((), _) := h1 + obtain ⟨rfl, rfl⟩ := Prod.mk.inj h1' + have T : APres (fl4UpdateTimestamp (Z := Unit)) := by + unfold fl4UpdateTimestamp + exact PresR.bind (doMachineOp_apres _) fun _ => APres.modify_fix _ (fun _ => + ⟨rfl, rfl, rfl, fun _ _ => Iff.rfl, rfl, rfl, fun _ y _ h => ⟨y, h, rfl⟩⟩) + have K := T (witISA mt sl uw) ((), _) (by rw [eX]; exact Set.mem_singleton _) + have nv1 : NoVmA _ := fun p y hy v => nv p y ((K.2.2.2.1 p y).1 hy) v + obtain ⟨⟨b, σ2⟩, h3, h4⟩ := mem_bindA.1 h2 + rw [cbσ _ eX] at h3 + have h3' : (b, σ2) = (true, _) := h3 + obtain ⟨rfl, rfl⟩ := Prod.mk.inj h3' + have hm := (wit_orc hL eX).2 + have hres := wit_hres (by decide : wIrq.val < 5376) + exact (show NoVmA _ from fun p y hy v => nv1 p y hy v).of_vm + (maybeHandle_vm _ _ (getActiveIRQ_eqA _ _ (hL _) hm) hres.1 hres.2 h4) + + +section +variable {S : Type} {A : Type} + +/-- **The premises of `kernelEntryIrq_recGA`** (module docstring). -/ +structure IrqEntryHyps (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) + (AR AR' : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) + (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (m : McState) + (Cs : Set U64) (Clock : A → MachineState → Prop) (s : S) (a : A) (σ : State Unit) (tm : A → Nat → DeadlineViewA) + (view : State Unit → Fl4TimerView) (irq : U64) : Type where + hA : P0.ArchTotal ar + hPl : ArchPlat ar + IE : IrqEnvA ar AR' + h1 : fl4A64Platform.numNodes = 1 + hCs : ∀ c ∈ Cs, c.val < fl4A64Platform.numNodes + hZ : Z.Cs = Cs + hmbA : ∀ a', Fl4MinBudgetAgreeA ar a' + hag : fl4MinBudget = MIN_BUDGET + hmax : maxTicksToUs = core.num.U64.MAX.bv + htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄ + v2 : config_ARM_GIC_V3 = false + J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s a σ m + sact : SActA σ + noSwitch : ∀ u, σ.schedulerAction ≠ .switchThread u + hvp : ∀ b, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ ¬ PPW st s b + P : NowAgreeA ar Clock + hClock : Clock a σ.machineState + hnd : numDomains = 1 + V : ValidMachineTimeA σ + C : CounterStepA σ + CI : CurInvA σ + R : OffReadyA σ + Act : ActIdleA σ + hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState + hAr : sched.update_timestamp st ar s a ⦃ r => AR' r.2 Z.hw ⦄ + hEnt : ChargeEntryA st Ac s + hni : σ.curSc ≠ idleScPtr → NotIdleScA m σ.curSc + hct : σ.schedulerAction = .resumeCurThread → ∀ x, σ.kheap σ.curThread = some (.tcb x) → + ActivateStateOKA x.tcbState + hsch : ∀ σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(false, σ1)}, False) → + schedulable σ1.curThread σ1 = true + hCharge : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → + fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → + ValidMachineTimeA σ1 → CurInvA σ1 → OffReadyA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(false, σ1)}, False) → + sched.check_budget st ar s1 a1 ⦃ r => ∃ τ, + fl4CheckBudget (Z := Unit) σ1 = ({(r.1, τ)}, False) ∧ + JStage3QA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes hPl.ipa m + r.2.1 r.2.2 τ ⦄ + line : ∀ b s' a' τ, + (do let (s0, a0) ← sched.update_timestamp st ar s a; sched.check_budget st ar s0 a0) = ok (b, s', a') → + ((fl4UpdateTimestamp (Z := Unit)) >>= fun _ => fl4CheckBudget) σ = ({(b, τ)}, False) → + IrqLineBaseA st s' irq + hres : EntryIrqAgreeA irq + orc : ∀ b s' a' τ, + (do let (s0, a0) ← sched.update_timestamp st ar s a; sched.check_budget st ar s0 a0) = ok (b, s', a') → + ((fl4UpdateTimestamp (Z := Unit)) >>= fun _ => fl4CheckBudget) σ = ({(b, τ)}, False) → + OracleIrqA irq τ + arch : ArchSwFA st ar + PF : FinPlatA ar AR' + hGap : ∀ s' a' τ, kBodyA st ar s a (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) = ok (s', a') → + ((), τ) ∈ (kOpA (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) σ).1 → + ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view + hNat : ∀ s' a' τ, kBodyA st ar s a (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) = ok (s', a') → + ((), τ) ∈ (kOpA (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) σ).1 → + A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → ∀ τ1 τ2, + ((), τ1) ∈ (fl4Schedule kLimitA view τ).1 → ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → + ∀ y, τ2.kheap τ2.curThread = some (.tcb y) → y.tcbState ≠ .ext .runningVM + +/-- The premises give `kernelEntryIrq_recGA`'s conclusion. -/ +theorem IrqEntryHyps.concl {st : machine.Store S} [L : LawfulStore st] {ar : machine.Arch A} + {AR AR' : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} + {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {m : McState} + {Cs : Set U64} {Clock : A → MachineState → Prop} {s : S} {a : A} {σ : State Unit} + {tm : A → Nat → DeadlineViewA} {view : State Unit → Fl4TimerView} {irq : U64} + (h : IrqEntryHyps st ar AR AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ m Cs Clock s a σ tm view irq) : + kCodeA st ar s a (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) ⦃ out => + StepPostA (KExitA st ar AR' h.hPl.ipa m) (fl4CallKernel kLimitA view false .interrupt) σ out ⦄ := + kernelEntryIrq_recGA h.hA h.hPl h.IE h.h1 h.hCs h.hZ h.hmbA h.hag h.hmax h.htu h.v2 irq h.J h.sact h.noSwitch h.hvp h.P h.hClock h.hnd h.V h.C h.CI h.R h.Act h.hNow h.hAr h.hEnt h.hni h.hct h.hsch h.hCharge h.line h.hres h.orc h.arch h.PF h.hGap h.hNat + +end + +section + +/-- **`kernelEntryIrq_recGA` at the witness** (module docstring): the premises and the conclusion at one state. -/ +theorem wit_top_irq (hL : ∀ n, irqOracle n = BitVec.ofNat 13 wIrq.val) (O : OpaqueWA) + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) + (ha : WClock a (witISA mt sl uw).machineState) : + ∃ Hy : IrqEntryHyps bst AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) + (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv + (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) + witZA.Cs WClock (witS r wNow mt sl uw) a (witISA mt sl uw) Wit2.witTm + (gapViewA bst AR1 (kBodyA bst AR1 (witS r wNow mt sl uw) a + (.interrupt wIrq (fl4MaybeHandleInterrupt (Z := Unit) false)))) wIrq, + kCodeA bst AR1 (witS r wNow mt sl uw) a (.interrupt wIrq (fl4MaybeHandleInterrupt (Z := Unit) false)) ⦃ out => + StepPostA (KExitA bst AR1 (fun _ _ => True) Wit2.ar1_plat.ipa (w1MA IB 1)) + (fl4CallKernel kLimitA + (gapViewA bst AR1 (kBodyA bst AR1 (witS r wNow mt sl uw) a + (.interrupt wIrq (fl4MaybeHandleInterrupt (Z := Unit) false)))) false .interrupt) + (witISA mt sl uw) out ⦄ := by + have J := wit_irqJ O hsl hr a (uw := uw) (mt := mt) (r := r) + let Hy : IrqEntryHyps bst AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) + (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv + (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) + witZA.Cs WClock (witS r wNow mt sl uw) a (witISA mt sl uw) Wit2.witTm + (gapViewA bst AR1 (kBodyA bst AR1 (witS r wNow mt sl uw) a + (.interrupt wIrq (fl4MaybeHandleInterrupt (Z := Unit) false)))) wIrq := + { hA := Wit2.ar1_total + hPl := Wit2.ar1_plat + IE := ⟨Wit2.ar1_irqArch O, O.maxIRQ⟩ + h1 := O.nodes + hCs := wit_hCs O + hZ := rfl + hmbA := Wit2.ar1_fl4MinBudget O + hag := O.hag + hmax := O.max + htu := (Wit2.ar1_faultEnv (st := bst) O witZA (wit_hCs O)).htu + v2 := O.v2 + J := J.toJStage3A + sact := J.sact + noSwitch := J.noSwitch + hvp := wit_hvp + P := Wit2.ar1_now + hClock := ha + hnd := O.nd + V := J.validTime + C := BitVec.le_refl _ + CI := J.curInv + R := J.offReady + Act := J.actIdle + hNow := O.hNow _ rfl + hAr := WP.spec_mono (Fl4ProofsA64.P0.sched.update_timestamp.p0 bst AR1 _ a bstTotal Wit2.ar1_total) + fun _ _ => trivial + hEnt := J.chargeEntryA + hni := J.curScNotIdle + hct := fun _ x hx => (J.curRunA hx).elim Or.inl fun h => Or.inr (Or.inl h) + hsch := fun σ1 e suf => by + rw [wit_hsufI O hsl e] at suf + exact absurd (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst suf))).1 (by decide) + hCharge := fun s1 a1 σ1 _ e _ _ _ _ _ _ _ suf => by + rw [wit_hsufI O hsl e] at suf + exact absurd (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst suf))).1 (by decide) + line := fun b s' a' τ eb _ => by + obtain ⟨a1, e1, ecb, -⟩ := wit_budgetIdI O hsl hr a ha (uw := uw) (mt := mt) (r := r) + have hb : (do let (s0, a0) ← sched.update_timestamp bst AR1 (witS r wNow mt sl uw) a + sched.check_budget bst AR1 s0 a0) = ok (true, witS r wNow mt sl uw, a1) := by + simp only [e1, bind_ok, uncurry_apply_pair]; exact ecb + have e := ok_inj_ff (eb.symm.trans hb) + have hs : s' = witS r wNow mt sl uw := congrArg (fun p => p.2.1) e + subst hs + exact wit_lineBase O hsl hr a + hres := wit_hres + orc := fun b s' a' τ eb ebs => by + obtain ⟨a1, e1, ecb, cbσ⟩ := wit_budgetIdI O hsl hr a ha (uw := uw) (mt := mt) (r := r) + have eX := Sched.fl4UpdateTimestamp_eqA (witISA mt sl uw) + rw [nd_bind_oneSc eX, cbσ _ eX] at ebs + have hτ := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst ebs))).2 + subst hτ + exact wit_orc hL eX + arch := Wit2.witArchSwOf + PF := Wit2.ar1_finPlat O + hGap := Wit2.wit2b_hGapA (st := bst) (AR' := fun _ _ => True) (m := w1MA IB 1) O Wit2.witArchSwOf (wit_hCs O) + (witS r wNow mt sl uw) a (witISA mt sl uw) + (.interrupt wIrq (fl4MaybeHandleInterrupt (Z := Unit) false)) + hNat := hNat_of_noVmA fun _ _ _ _ op _ => wit_bodyNoVmI hL O hsl hr a ha op } + exact ⟨Hy, Hy.concl⟩ + +/-- **Non-vacuity of `kernelEntryIrq_recGA`**: with `OpaqueWA` and the oracle fact `hL` (the witness world `OpaqueWIrqA`), +every premise is satisfied at one state: the root TCB's entry, line 5 accepted. -/ +theorem wit_irq_nonvacuous (O : OpaqueWA) (hL : ∀ n, irqOracle n = BitVec.ofNat 13 wIrq.val) : + ∃ (r mt sl : U64) (uw : U64 → U64) (a : WA), + Nonempty (IrqEntryHyps bst AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) + (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv + (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) + witZA.Cs WClock (witS r wNow mt sl uw) a (witISA mt sl uw) Wit2.witTm + (gapViewA bst AR1 (kBodyA bst AR1 (witS r wNow mt sl uw) a + (.interrupt wIrq (fl4MaybeHandleInterrupt (Z := Unit) false)))) wIrq) := by + obtain ⟨r, hr⟩ := wit_r_ex + obtain ⟨Hy, -⟩ := wit_top_irq hL O (r := r) (mt := 0#u64) (sl := ⟨Fl4SpecA64.MIN_BUDGET⟩) (uw := fun _ => 0#u64) + (BitVec.le_refl _) hr (witA0 (witISA 0#u64 ⟨Fl4SpecA64.MIN_BUDGET⟩ (fun _ => 0#u64)).machineState) rfl + exact ⟨r, 0#u64, ⟨Fl4SpecA64.MIN_BUDGET⟩, fun _ => 0#u64, _, ⟨Hy⟩⟩ + +end + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitJA.lean b/proofs/Fl4ProofsA64/P3/A64WitJA.lean index a364fbb5d..2243b66cf 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitJA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitJA.lean @@ -26,42 +26,45 @@ local notation "wa" => core.num.U64.wrapping_add /-! ## The spec state and the ghosts -/ /-- The root TCB's registers: the CNode Copy message over `rootRegsA`. -/ -def witRegs : Fl4SpecA64.Register → Fl4SpecA64.Word - | .x0 => 2 | .x1 => 98437 | .x2 => 1000 | .x3 => 64 | .x4 => 2 | .x5 => 64 | .faultIP => 4194300 +def witRegs (c0 : U64) : Fl4SpecA64.Register → Fl4SpecA64.Word + | .x0 => c0.bv | .x1 => 98437 | .x2 => 1000 | .x3 => 64 | .x4 => 2 | .x5 => 64 | .x6 => (v6 c0).bv | .faultIP => 4194300 | r => rootRegsA r -def witTcbA : Fl4SpecA64.Tcb := +def witTcbA (c0 : U64) : Fl4SpecA64.Tcb := { rootTcbA with tcbArch := { rootTcbA.tcbArch with - tcbContext := { rootTcbA.tcbArch.tcbContext with userRegs := witRegs } } } + tcbContext := { rootTcbA.tcbArch.tcbContext with userRegs := witRegs c0 } } } /-- **The spec state of the witness** (module docstring). -/ -def witSA (now mt sl : U64) (uw : U64 → U64) : Fl4SpecA64.State Unit := +def witSAc (c0 : U64) (now mt sl : U64) (uw : U64 → U64) : Fl4SpecA64.State Unit := { w1SUA KB IB 1 now mt sl uw with - kheap := Function.update (w1KA KB IB 1 now mt sl) (specPtr (bwv RTb)) (some (.tcb witTcbA)) + kheap := Function.update (w1KA KB IB 1 now mt sl) (specPtr (bwv RTb)) (some (.tcb (witTcbA c0))) curThread := specPtr (bwv RTb) curSc := specPtr (bwv SCb) schedulerAction := .resumeCurThread } +/-- **The spec state of the Send witness** (`x0` = 2). -/ +abbrev witSA (now mt sl : U64) (uw : U64 → U64) : Fl4SpecA64.State Unit := witSAc 2#u64 now mt sl uw + /-- **The ghosts of the witness**: `w1`'s with core 0's current thread and SC. -/ def witZA : XSetsA := { w1ZA KB IB 1 with curOf := Function.update (w1ZA KB IB 1).curOf 0 (specPtr (bwv RTb)) curScOf := Function.update (w1ZA KB IB 1).curScOf 0 (specPtr (bwv SCb)) } -variable {r now mt sl : U64} {uw : U64 → U64} +variable {c0 : U64} {r now mt sl : U64} {uw : U64 → U64} local notation "S1" => w1S KB IB 1 r now mt sl uw -local notation "S2" => witS r now mt sl uw +local notation "S2" => witSc c0 r now mt sl uw local notation "H1" => w1H KB IB 1 local notation "σ1" => w1SUA KB IB 1 now mt sl uw -local notation "σ2" => witSA now mt sl uw +local notation "σ2" => witSAc c0 now mt sl uw local notation "M1" => w1MA IB 1 /-- The two heaps agree off the root TCB. -/ theorem kh_cases (p : Fl4SpecA64.ObjRef) : (σ2).kheap p = (σ1).kheap p ∨ - (p = specPtr (bwv RTb) ∧ (σ1).kheap p = some (.tcb rootTcbA) ∧ (σ2).kheap p = some (.tcb witTcbA)) := by + (p = specPtr (bwv RTb) ∧ (σ1).kheap p = some (.tcb rootTcbA) ∧ (σ2).kheap p = some (.tcb (witTcbA c0))) := by by_cases h : p = specPtr (bwv RTb) · subst h exact Or.inr ⟨rfl, w1KA_rt, Function.update_self _ _ _⟩ @@ -76,7 +79,7 @@ theorem kh_obj {p : Fl4SpecA64.ObjRef} {ko : Fl4SpecA64.KernelObject} (hk : ∀ /-- A TCB of `σ2` is `σ1`'s, or the root TCB with the new registers. -/ theorem kh_back {p : Fl4SpecA64.ObjRef} {y : Fl4SpecA64.Tcb} (h : (σ2).kheap p = some (.tcb y)) : - ∃ x, (σ1).kheap p = some (.tcb x) ∧ (y = x ∨ (x = rootTcbA ∧ y = witTcbA)) := by + ∃ x, (σ1).kheap p = some (.tcb x) ∧ (y = x ∨ (x = rootTcbA ∧ y = witTcbA c0)) := by rcases kh_cases (now := now) (mt := mt) (sl := sl) (uw := uw) p with e | ⟨-, e1, e2⟩ · exact ⟨y, e ▸ h, Or.inl rfl⟩ · rw [e2] at h @@ -84,14 +87,14 @@ theorem kh_back {p : Fl4SpecA64.ObjRef} {y : Fl4SpecA64.Tcb} (h : (σ2).kheap p exact ⟨_, e1, Or.inr ⟨rfl, rfl⟩⟩ theorem kh_fwd {p : Fl4SpecA64.ObjRef} {x : Fl4SpecA64.Tcb} (h : (σ1).kheap p = some (.tcb x)) : - ∃ y, (σ2).kheap p = some (.tcb y) ∧ (y = x ∨ (x = rootTcbA ∧ y = witTcbA)) := by + ∃ y, (σ2).kheap p = some (.tcb y) ∧ (y = x ∨ (x = rootTcbA ∧ y = witTcbA c0)) := by rcases kh_cases (now := now) (mt := mt) (sl := sl) (uw := uw) p with e | ⟨-, e1, e2⟩ · exact ⟨x, e.trans h, Or.inl rfl⟩ · rw [e1] at h cases h exact ⟨_, e2, Or.inr ⟨rfl, rfl⟩⟩ -theorem kh_rt : (σ2).kheap (specPtr (bwv RTb)) = some (.tcb witTcbA) := Function.update_self _ _ _ +theorem kh_rt : (σ2).kheap (specPtr (bwv RTb)) = some (.tcb (witTcbA c0)) := Function.update_self _ _ _ /-- The caps of every spec slot are kept. -/ theorem capAt_eq (c : Fl4SpecA64.CslotPtr) : specCapAtA σ2 c = specCapAtA σ1 c := by @@ -122,7 +125,7 @@ theorem qkeep : QKeepA σ1 σ2 where ntfn p x h := ⟨x, (kh_obj (fun _ e => by cases e)).1 h, List.Sublist.refl _⟩ sc p y k h := ⟨y, k, (kh_obj (fun _ e => by cases e)).1 h, fun h => ⟨h, id⟩⟩ rt p y h := ⟨y, (kh_obj (fun _ e => by cases e)).1 h, id⟩ - dom := ⟨rfl, rfl, rfl, rfl⟩ + dom := DomKeepA.ofKey rfl /-! ## The heap has no endpoint, notification or reply -/ diff --git a/proofs/Fl4ProofsA64/P3/A64WitRcA.lean b/proofs/Fl4ProofsA64/P3/A64WitRcA.lean new file mode 100644 index 000000000..27bdc72b9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitRcA.lean @@ -0,0 +1,459 @@ +/- +P3 (aarch64, A64-P3 non-vacuity witness, line witrc, part 1): **the receive witness state and its scope.** + +At `witSc c0` with `c0 = 8192` the CAP register names a cptr whose CSpace walk fails (the root CNode cap has a 51-bit zero +guard, `8192 = 2^13` has a bit in the guard window: `GuardMismatch`), and the root thread has no fault handler. So every +receive call (`Recv`, `NBRecv`, `Wait`, `NBWait`) takes the **cap-fault arm** (`RecvScopeA.capFaultNull`): the cap fault +goes to the `Null` handler and the thread becomes `Inactive`. + +**Arm exercised**: `capFaultNull` only. The blocking, polling and notification arms are not instantiated: `w1` has no +endpoint or notification object (the root CNode holds TCB / CNode / VSpace / IRQ / ASID / frame / untyped caps), and +adding one needs a new object, a cap and an extended `JSyscallA` record. The gate here is joint satisfiability of every +premise of `kernelEntryRecv_recGA`; the arm is the cheapest member of `RecvScopeA`. + +* `wit_lookupCap_fail`: `cspace.lookup_cap` of the CAP word fails with `GuardMismatch 0 64 51`; +* `wit_recvScope`: `RecvScopeA` at the post-budget state, for every `(blocking, canReply)`; +* `JSyscallA.recvCapFault_vmA`, `wit_recvNoVm`: every outcome of the cap-fault receive creates no `runningVM` thread + (`hNat`); +* `RecvEntryHyps` (the exact binder list of `kernelEntryRecv_recGA`), `wit_recv_top`, `wit_recv_nonvacuous`. + +Named premises: `OpaqueWA` [P], the witness parameters (`sl >= MIN_BUDGET`, `hr`). New module. +-/ +import Fl4ProofsA64.P3.A64Wit2TopA +import Fl4ProofsA64.P3.Stage3SysRecvA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Wit +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P1.W7.R.ST.BootWit Fl4ProofsA64.P3 + Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 + +noncomputable section + +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA WClock) + +/-- **The CAP register word of the receive witness**: a cptr outside the root CNode's 13-bit window. -/ +abbrev cFail : U64 := 8192#u64 + +variable {r now mt sl : U64} {uw : U64 → U64} {c0 : U64} + +local notation "wa" => core.num.U64.wrapping_add +local notation "S3" => witSc c0 r now mt sl uw +local notation "S1" => w1S KB IB 1 r now mt sl uw +local notation "RT" => (bwv RTb) +local notation "RC" => capability.Cap.CNode (bwv RRb) 13#u64 51#u64 0#u64 + +/-- A root TCB slot is not changed. -/ +theorem capS3_ts {i : U64} (hi : i.val < 7) : capA bst S3 (slotIdx RT i) = capA bst S1 (slotIdx RT i) := by + have v : (slotIdx RT i).val = RTb + 32 * i.val := by + have e : slotIdx RT i = ts i := rfl + rw [e, ts_val (by omega)] + omega + have h8 : (wa (slotIdx RT i) 8#u64).val = RTb + 32 * i.val + 8 := by + rw [wa_valm, v]; simp; omega + have e1 : bL.mem S3 (slotIdx RT i) = bL.mem S1 (slotIdx RT i) := + ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) + have e2 : bL.mem S3 (wa (slotIdx RT i) 8#u64) = bL.mem S1 (wa (slotIdx RT i) 8#u64) := + ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) + unfold capA + rw [e1, e2] + +theorem tcbSlot_okc (i : U64) (hi : i.val < 7) : obj.Tcb.slot RT i = ok (slotIdx RT i) := by + have z : layout.cte.SIZE = 32#u64 := by simp [layout.cte.SIZE] + unfold obj.Tcb.slot slotIdx + simp only [lift, bind_ok, z] + +/-- **The CSpace walk of the root CNode fails on `8192`**: its 13 index bits are fine, the guard window is not zero. -/ +theorem wit_resolve_fail : + cspace.resolve_address_bits bst S3 RC 8192#u64 64#u64 = + ok (.Err (error.LookupFault.GuardMismatch 0#u64 64#u64 51#u64)) := by + have body : cspace.resolve_address_bits_loop.body bst S3 8192#u64 RC 64#u64 65#u64 = + ok (ControlFlow.done (.Err (error.LookupFault.GuardMismatch 0#u64 64#u64 51#u64))) := by + have l : core.num.U64.wrapping_add 13#u64 51#u64 = 64#u64 := by rfl + have f : (65#u64 : U64) - 1#u64 = ok 64#u64 := by rfl + have sh : (core.num.U64.wrapping_sub 64#u64 51#u64) &&& 63#u64 = 13#u64 := by rfl + have c13 : (8192#u64 : U64) >>> (13#u64 : U64) = ok 1#u64 := by rfl + have m51 : cspace.mask 51#u64 = ok 2251799813685247#u64 := by + have a : (51#u64 : U64) &&& 63#u64 = 51#u64 := by rfl + have b : (1#u64 : U64) <<< (51#u64 : U64) = ok 2251799813685248#u64 := by rfl + unfold cspace.mask + rw [if_neg (by scalar_tac)] + simp only [lift, bind_ok, a] + rw [b, bind_ok] + rfl + have g : (1#u64 : U64) &&& 2251799813685247#u64 = 1#u64 := by rfl + unfold cspace.resolve_address_bits_loop.body + simp only [lift, bind_ok, l, f, sh, c13, m51, g] + simp + unfold cspace.resolve_address_bits + rw [rabLoop_unfold, body, bind_ok] + +theorem wit_lookupSlot_fail : + cspace.lookup_slot bst S3 RT 8192#u64 = + ok (.Err (error.LookupFault.GuardMismatch 0#u64 64#u64 51#u64)) := by + have ct : layout.tcb.SLOT_CTABLE = 0#u64 := by simp [layout.tcb.SLOT_CTABLE] + have c : capA bst S3 (slotIdx RT 0#u64) = RC := by + rw [capS3_ts (by simp), cap_rt lay1 (by simp)] + simp + have w : cspace.WORD_BITS = 64#u64 := by simp [cspace.WORD_BITS] + unfold cspace.lookup_slot + rw [ct, tcbSlot_okc 0#u64 (by simp), bind_ok, capA_eq, c, bind_ok, w] + exact wit_resolve_fail + +/-- **The CAP word of the receive witness fails to look up.** -/ +theorem wit_lookupCap_fail (h0 : c0 = cFail) : + cspace.lookup_cap bst S3 (bL.curW S3) (bL.mem S3 (regWA (bL.curW S3) layout.reg.CAP)) = + ok (.Err (.Lookup (error.LookupFault.GuardMismatch 0#u64 64#u64 51#u64))) := by + have cp : bL.mem S3 (regWA (bL.curW S3) layout.reg.CAP) = 8192#u64 := by + rw [curW2] + have e : layout.reg.CAP = 0#u64 := by simp [layout.reg.CAP, layout.reg.X0] + rw [e, wit_regWord (c0 := c0) 0#u64 (by simp)] + simp [witRtW, h0] + rw [cp, curW2] + unfold cspace.lookup_cap + rw [wit_lookupSlot_fail] + simp only [bind_ok] + + +/-! ## The scope: the cap-fault arm -/ + +/-- The same record as `WitJ`, at `witSc c0`. -/ +abbrev RcJ (Z : XSetsA) (c0 r now mt sl : U64) (uw : U64 → U64) (ab : WA) (τ : Fl4SpecA64.State Unit) : Prop := + WitJ Z c0 r now mt sl uw (witSc c0 r now mt sl uw) ab τ + +/-- **`RecvScopeA` at the post-budget state of the receive witness**, for every `(blocking, canReply)`. -/ +theorem wit_recvScope {Z : XSetsA} {ab : WA} {τ : Fl4SpecA64.State Unit} + (Jr : RcJ Z cFail r wNow mt sl uw ab τ) (blocking canReply : Bool) : + RecvScopeA bst (w1OS KB IB 1) ∅ ∅ ∅ Z.T (witSc cFail r wNow mt sl uw) τ blocking canReply := + .capFaultNull (wit_lookupCap_fail (c0 := cFail) rfl) wit_faultCap (wit_faultHandler_null Jr) + +/-! ## The outcomes of the cap-fault receive -/ + +theorem recvLookupFaultW {m : LFMonad Unit Cap} {σ : State Unit} {e : LookupFailure} + (h : m.run σ = ({(.error e, σ)}, False)) (p : Word) : + (capFaultOnFailure p true m).run σ = ({(.error (.capFault p true e), σ)}, False) := by + unfold capFaultOnFailure + rw [run_handleE_errA h] + rfl + +/-- **The spec's `handle_fault` with no handler has one outcome.** -/ +theorem handleFault_null_eqW {σ : State Unit} {t : ObjRef} {x : Tcb} {f : Fault} (hk : σ.kheap t = some (.tcb x)) + (hc : getCap (Z := Unit) (getTcbFaultHandlerPtr t) σ = ({(.nullCap, σ)}, False)) : + handleFault (Z := Unit) t f σ = + ({((), stsAct (updK σ t (.tcb { x with tcbState := .inactive })) t)}, False) := by + unfold handleFault + rw [nd_pure_bindSc, nd_bind_oneSc hc, nd_bind_oneSc (threadGet_eq _ hk)] + simp only [sendFaultIpc] + rw [nd_pure_bindSc] + unfold NonDet.unless + simp only [Bool.false_eq_true, ↓reduceIte] + unfold handleNoFault + rw [nd_bind_oneSc (setThreadState_eq _ hk)] + rfl + +theorem stsAct_inactive_vm {σ : State Unit} {t : ObjRef} {x : Tcb} (hk : σ.kheap t = some (.tcb x)) : + VmKA σ (stsAct (updK σ t (.tcb { x with tcbState := .inactive })) t) := by + intro p y hy v + rw [stsAct_kheap, updK_kheap] at hy + by_cases e : p = t + · subst e + rw [Function.update_self] at hy + obtain rfl := KernelObject.tcb.inj (Option.some.inj hy) + cases v + · rw [Function.update_of_ne e] at hy + exact ⟨y, hy, v⟩ + +section generic +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +/-- **Every outcome of a receive with a failing lookup and no fault handler creates no `runningVM` thread.** -/ +theorem JSyscallA.recvCapFault_vmA (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + {blocking canReply : Bool} {lf : error.LookupFault} + (hcap : cspace.lookup_cap st s (L.curW s) (L.mem s (regWA (L.curW s) layout.reg.CAP)) = + ok (.Err (.Lookup lf))) + (hgc : getCap (Z := Unit) (getTcbFaultHandlerPtr σ.curThread) σ = ({(.nullCap, σ)}, False)) : + ∀ τ', ((), τ') ∈ (handleRecv (Z := Unit) blocking canReply σ).1 → VmKA σ τ' := by + intro τ' hτ + have htZ : L.curW s ∈ Z.T := J.sr.curT + set t := L.curW s with ht_def + have ct : σ.curThread = specPtr t := J.j.1.sch.curThread + obtain ⟨xt, hkt, r⟩ := J.ep.tcb t htZ + have hkc : σ.kheap σ.curThread = some (.tcb xt) := by rw [ct]; exact hkt + have hthT : Z.th t = some .tcb := (J.sr.thT t).2 htZ + set cp := L.mem s (regWA t layout.reg.CAP) with hcp + have l := post_of_okA (lookup_cap_recv_refinesA (st := st) _ s σ J.j.1.st J.j.1.cv t hthT cp) hcap + obtain ⟨e, he, hrel⟩ := l + cases e with + | ok _ => exact hrel.elim + | error fault => + have capReg : cp.bv = xt.tcbArch.tcbContext.userRegs cap_register := by + rw [hcp, ← r.regs cap_register, regIdxA_capA]; rfl + have capRead : NonDet.liftM dataToCptr (asUser (Z := Unit) (specPtr t) (getRegister cap_register)) σ = + ({(toBl cp.bv, σ)}, False) := by + unfold NonDet.liftM + rw [nd_bind_singleA' (asUser_getRegister_eqA hkt _), ← capReg] + rfl + rw [handleRecv, nd_gets_bindSc, ct, nd_bind_oneSc capRead] at hτ + obtain ⟨⟨v, σ1⟩, hv, hτ⟩ := mem_bindA.1 hτ + simp only [ofBl_toBlA] at hv + rw [run_bind_errorA (recvLookupFaultW he cp.bv)] at hv + obtain ⟨hv1, hv2⟩ := Prod.mk.inj (Set.mem_singleton_iff.1 hv) + subst hv1 + rw [hv2] at hτ + rw [ct] at hgc + have hτ2 : ((), τ') ∈ (handleFault (Z := Unit) (specPtr t) (.capFault cp.bv true fault) σ).1 := hτ + rw [handleFault_null_eqW hkt hgc] at hτ2 + obtain ⟨-, hτ3⟩ := Prod.mk.inj (Set.mem_singleton_iff.1 hτ2) + subst hτ3 + exact stsAct_inactive_vm hkt + +end generic + + +/-- No thread of `witSAc c0` runs a guest. -/ +theorem wit_noVmC {c0 now mt sl : U64} {uw : U64 → U64} : NoVmA (witSAc c0 now mt sl uw) := by + intro p x hp v + change Function.update (w1KA KB IB 1 now mt sl) (specPtr (bwv RTb)) (some (.tcb (witTcbA c0))) p = some (.tcb x) at hp + by_cases c : p = specPtr (bwv RTb) + · subst c + rw [Function.update_self] at hp + obtain rfl := KernelObject.tcb.inj (Option.some.inj hp) + cases v + rw [Function.update_of_ne c] at hp + unfold w1KA bootKA at hp + split_ifs at hp <;> cases hp <;> cases v + +set_option maxHeartbeats 4000000 in +/-- **No thread runs a guest after any outcome of the witness's receive calls.** -/ +theorem wit_recvNoVm (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) + (ha : WClock a (witSAc cFail wNow mt sl uw).machineState) (number : I64) (rep : Bool) (call : Syscall) + (hc : call = .sysRecv ∨ call = .sysNBRecv ∨ call = .sysWait ∨ call = .sysNBWait) {τf : Fl4SpecA64.State Unit} + (h : ((), τf) ∈ (kOpA (.syscall number rep call) (witSAc cFail wNow mt sl uw)).1) : NoVmA τf := by + have I := wit_entryIn O (c0 := cFail) (r := r) (mt := mt) (uw := uw) hsl hr a ha + obtain ⟨a1, hb, -⟩ := wit_budget_id O (c0 := cFail) hsl hr a ha (uw := uw) (mt := mt) (r := r) + have budget := JSyscallA.budgetOkSysA (AR' := fun _ _ => True) I.J I.hvp I.P I.hClock I.hnd I.C I.hC I.hNow I.hAr I.hmb + (fun s1 a1 σ1 _ e _ _ _ _ _ _ _ suf => by + rw [wit_hsuf O hsl e] at suf + exact absurd (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst suf))).1 (by decide)) + obtain ⟨⟨b, sb, ab⟩, eb, τ, e1, -, tr⟩ := spec_existsA budget + have ee := ok_inj_ff (eb.symm.trans hb) + have hsb : sb = witSc cFail r wNow mt sl uw := congrArg (fun p => p.2.1) ee + have hb1 : b = true := congrArg Prod.fst ee + obtain ⟨Jr, -⟩ := tr hb1 + rw [hsb] at Jr + have e1' : fl4BudgetOk (Z := Unit) (witSAc cFail wNow mt sl uw) = ({(true, τ)}, False) := by + rw [hb1] at e1; exact e1 + have nvτ : NoVmA τ := wit_noVmC.of_vm (budgetOk_vm (by rw [e1']; exact Set.mem_singleton _)) + have hcap := wit_lookupCap_fail (c0 := cFail) (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) rfl + have rv : ∀ b c τ', ((), τ') ∈ (handleRecv (Z := Unit) b c τ).1 → VmKA τ τ' := fun b c => + JSyscallA.recvCapFault_vmA Wit2.ar1_plat Jr (blocking := b) (canReply := c) hcap (wit_faultHandler_null Jr) + have body : ∀ y, y ∈ ((fl4HandleEvent (Z := Unit) rep (.syscallEvent call)).run + (witSAc cFail wNow mt sl uw)).1 → y.1 = .ok () ∧ VmKA τ y.2 := fun y hy => by + unfold fl4HandleEvent at hy + dsimp only at hy + rw [run_lift_bindA e1'] at hy + simp only [Fl4Spec.NonDetE.whenE, ↓reduceIte, fl4HandleSyscall] at hy + rcases hc with rfl | rfl | rfl | rfl <;> simp only [fl4HandleSyscallWith, withoutPreemption] at hy <;> + (unfold NonDetE.liftE at hy; rw [ExceptT.run_lift] at hy + obtain ⟨y', hy', hx⟩ := mem_bindA.1 hy + obtain rfl := mem_pureA hx + exact ⟨rfl, rv _ _ y'.2 hy'⟩) + unfold kOpA at h + dsimp only at h + rw [nd_gets_bindSc, nd_bind_oneSc (wit_pc (c0 := cFail))] at h + obtain ⟨⟨v, σ1⟩, hv, h⟩ := mem_bindA.1 h + obtain ⟨-, rfl⟩ := Prod.mk.inj (mem_pureA h) + unfold Fl4Spec.NonDetE.handleE at hv + rw [ExceptT.run_mk] at hv + obtain ⟨y, hy, hv⟩ := mem_bindA.1 hv + obtain ⟨ey, ky⟩ := body y hy + rw [ey] at hv + obtain ⟨-, es⟩ := Prod.mk.inj (mem_pureA hv) + subst es + exact nvτ.of_vm ky + + +/-- **`kRuns` of the receive witness**: the syscall number is in range and the entry's `FAULT_IP` write finds the +`TRAP_SYSCALLS` flag clear. -/ +theorem wit_kRunsR {r mt sl : U64} {uw : U64 → U64} (number : I64) (rep : Bool) (call : Fl4SpecA64.Syscall) + (hnum : number = syscallNumberA call) + (hc : call = .sysRecv ∨ call = .sysNBRecv ∨ call = .sysWait ∨ call = .sysNBWait) : + kRuns bst (witSc cFail r wNow mt sl uw) (.syscall number rep call) := by + have rng : ¬ number < fl4_abi.syscall.SYSCALL_MIN ∧ ¬ number > fl4_abi.syscall.SYSCALL_MAX := by + subst hnum + rcases hc with rfl | rfl | rfl | rfl <;> simp only [syscallNumberA] <;> + first | decide | scalar_tac | (constructor <;> simp [fl4_abi.syscall.SYSCALL_MIN, fl4_abi.syscall.SYSCALL_MAX, + fl4_abi.syscall.SysRecv, fl4_abi.syscall.SysNBRecv, fl4_abi.syscall.SysWait, fl4_abi.syscall.SysNBWait] + <;> decide) + have ct : sched.cur_thread bst (witSc cFail r wNow mt sl uw) = ok (bwv RTb) := by rw [cur_thread_ok, curW2] + have hset : obj.Tcb.set_reg bst (bwv RTb) (witSc cFail r wNow mt sl uw) layout.reg.FAULT_IP + (core.num.U64.wrapping_sub (bL.mem (witSc cFail r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64) = + ok (bL.wr (witSc cFail r wNow mt sl uw) (Endp.regA (bwv RTb) layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (bL.mem (witSc cFail r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64)) := by + obtain ⟨q, hq, e⟩ := spec_existsA (obj.Tcb.set_reg.spec (st := bst) (witSc cFail r wNow mt sl uw) (bwv RTb) + layout.reg.FAULT_IP (core.num.U64.wrapping_sub (bL.mem (witSc cFail r wNow mt sl uw) + (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64)) + rw [hq, e] + have fid : bL.wr (witSc cFail r wNow mt sl uw) (Endp.regA (bwv RTb) layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (bL.mem (witSc cFail r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64) = + witSc cFail r wNow mt sl uw := by + have := wit_faultIP_id (c0 := cFail) (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) + rwa [curW2] at this + have hf : bL.mem (witSc cFail r wNow mt sl uw) (core.num.U64.wrapping_add (bwv RTb) 3456#u64) = 0#u64 := by + have v : (core.num.U64.wrapping_add (bwv RTb) 3456#u64).val = (bwv RTb).val + 3456 := by + rw [wa_valm, vRT]; exact Nat.mod_eq_of_lt (by simp) + have := wit_rtWords (c0 := cFail) (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) _ 3456 (by norm_num) + (by norm_num) v + rw [this]; simp [witRtW, rtW] + refine ⟨rng.1, rng.2, bwv RTb, _, witSc cFail r wNow mt sl uw, 0#u64, ct, tcb_reg_eqA _ _ _, + hset.trans (by rw [fid]), ?_, ?_⟩ + · rw [flags_ok, hf] + · first | simp | (apply UScalar.eq_of_val_eq; simp) + +end + +end Fl4ProofsA64.P3.Wit + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **The premises of `kernelEntryRecv_recGA`** (exact binder list; module docstring of `P3/A64WitRcA`). -/ +structure RecvEntryHyps (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) + (AR AR' : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) + (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (m : McState) + (Clock : A → MachineState → Prop) (s : S) (a : A) (σ : State Unit) (tm : A → Nat → DeadlineViewA) + (view : State Unit → Fl4TimerView) (number : I64) (rep : Bool) (call : Syscall) : Type where + hPl : ArchPlat ar + Env : FaultEnvA st ar Z + hlimit : fl4MaxReleaseTime = MAX_RELEASE_TIME + hag : fl4MinBudget = MIN_BUDGET + hconv : Fl4TicksToUsLegacyAgree + v2 : config_ARM_GIC_V3 = false + arch : ArchSwFA st ar + P : FinPlatA ar AR' + hnum : number = syscallNumberA call + hc : call = .sysRecv ∨ call = .sysNBRecv ∨ call = .sysWait ∨ call = .sysNBWait + run : kRuns st s (.syscall number rep call) + I : KEntryFaultInA st ar AR AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m Clock s a σ + hCharge : SysChargeA st ar AR AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m Clock s a σ + hScope : ∀ (Q : U64 → U64 → List U64) (Rl : U64 → List U64) sb ab τ (τPC : State Unit), + fl4SyscallFaultIP (Z := Unit) σ.curThread σ = ({((), τPC)}, False) → + syscall.budget_ok st ar (L.wr s (Endp.regA (L.curW s) layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (L.mem s (regWA (L.curW s) layout.reg.NEXT_IP)) 4#u64)) a = ok (true, sb, ab) → + fl4BudgetOk (Z := Unit) τPC = ({(true, τ)}, False) → + JSyscallA st AR' { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) sb ab τ m → CounterStepA τ → + ∀ blocking canReply, DispatchRecvAtA call blocking canReply → + RecvScopeA st OS N E Rp Z.T sb τ blocking canReply + hGap : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → + ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → + ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view + hNat : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → + ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → + A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → ∀ τ1 τ2, + ((), τ1) ∈ (fl4Schedule kLimitA view τ).1 → ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → + ∀ y, τ2.kheap τ2.curThread = some (.tcb y) → y.tcbState ≠ .ext .runningVM + +variable {AR AR' : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {m : McState} {Clock : A → MachineState → Prop} {s : S} {a : A} {σ : State Unit} + {tm : A → Nat → DeadlineViewA} {view : State Unit → Fl4TimerView} {number : I64} {rep : Bool} {call : Syscall} + +/-- The premises give `kernelEntryRecv_recGA`'s conclusion. -/ +theorem RecvEntryHyps.concl (h : RecvEntryHyps st ar AR AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ m Clock s a σ + tm view number rep call) : + kCodeA st ar s a (.syscall number rep call) ⦃ out => + StepPostA (KExitA st ar AR' h.hPl.ipa m) + (kOpA (.syscall number rep call) >>= fun _ => fl4Finish kLimitA view) σ out ⦄ := + kernelEntryRecv_recGA h.hPl h.Env h.hlimit h.hag h.hconv h.v2 h.arch h.P number rep call h.hnum h.hc h.run h.I + h.hCharge h.hScope h.hGap h.hNat + +end + +end + +end Fl4ProofsA64.P3 + +namespace Fl4ProofsA64.P3.Wit +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P1.W7.R.ST.BootWit Fl4ProofsA64.P3 + Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 + +noncomputable section + +set_option maxHeartbeats 4000000 in +/-- **`kernelEntryRecv_recGA` at the receive witness**: the premises and the conclusion at one state. -/ +theorem wit_recv_top (O : Wit2.OpaqueWA) {r mt sl : U64} {uw : U64 → U64} + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : Wit2.WA) + (ha : Wit2.WClock a (witSAc cFail wNow mt sl uw).machineState) (number : I64) (rep : Bool) + (call : Fl4SpecA64.Syscall) (hnum : number = syscallNumberA call) + (hc : call = .sysRecv ∨ call = .sysNBRecv ∨ call = .sysWait ∨ call = .sysNBWait) : + ∃ Hy : RecvEntryHyps bst Wit2.AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) + (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv + (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) + Wit2.WClock (witSc cFail r wNow mt sl uw) a (witSAc cFail wNow mt sl uw) Wit2.witTm + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a (.syscall number rep call))) + number rep call, + kCodeA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a (.syscall number rep call) ⦃ out => + StepPostA (KExitA bst Wit2.AR1 (fun _ _ => True) Wit2.ar1_plat.ipa (w1MA IB 1)) + (kOpA (.syscall number rep call) >>= fun _ => fl4Finish kLimitA + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a (.syscall number rep call)))) + (witSAc cFail wNow mt sl uw) out ⦄ := by + let Hy : RecvEntryHyps bst Wit2.AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) + (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv + (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) + Wit2.WClock (witSc cFail r wNow mt sl uw) a (witSAc cFail wNow mt sl uw) Wit2.witTm + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a (.syscall number rep call))) + number rep call := + { hPl := Wit2.ar1_plat + Env := Wit2.ar1_faultEnv O witZA (wit_hCs O) + hlimit := O.hlimit + hag := O.hag + hconv := O.hconv + v2 := O.v2 + arch := Wit2.witArchSwOf + P := Wit2.ar1_finPlat O + hnum := hnum + hc := hc + run := wit_kRunsR number rep call hnum hc + I := wit_entryIn O hsl hr a ha + hCharge := wit_hCharge O hsl a + hScope := fun Q Rl sb ab τ τPC _ eb _ Jr _ blocking canReply _ => by + obtain ⟨a1, hb, -⟩ := wit_budget_id O (c0 := cFail) hsl hr a ha + rw [wit_faultIP_id, hb] at eb + have e := ok_inj_ff eb + have hsb : sb = witSc cFail r wNow mt sl uw := (congrArg (fun p => p.2.1) e).symm + subst hsb + exact wit_recvScope Jr blocking canReply + hGap := Wit2.wit2b_hGapA O Wit2.witArchSwOf (wit_hCs O) _ a _ (.syscall number rep call) + hNat := hNat_of_noVmA fun _ _ _ _ op _ => wit_recvNoVm O hsl hr a ha number rep call hc op } + exact ⟨Hy, Hy.concl⟩ + +/-- **Non-vacuity of `kernelEntryRecv_recGA`**: with `OpaqueWA` the only hypothesis, every witness-side parameter is +existential (`r` from `wit_r_ex`, `sl = MIN_BUDGET`, `mt = 0`, `uw = 0`, the arch state `witA0`, `call = Recv`). -/ +theorem wit_recv_nonvacuous (O : Wit2.OpaqueWA) : + ∃ (r mt sl : U64) (uw : U64 → U64) (a : Wit2.WA) (number : I64) (rep : Bool) (call : Syscall), + Nonempty (RecvEntryHyps bst Wit2.AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) + (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv + (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) + Wit2.WClock (witSc cFail r wNow mt sl uw) a (witSAc cFail wNow mt sl uw) Wit2.witTm + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a (.syscall number rep call))) + number rep call) := by + obtain ⟨r, hr⟩ := wit_r_ex + obtain ⟨Hy, -⟩ := wit_recv_top O (r := r) (mt := 0#u64) (sl := ⟨Fl4SpecA64.MIN_BUDGET⟩) (uw := fun _ => 0#u64) + (BitVec.le_refl _) hr (witA0 (witSAc cFail wNow 0#u64 ⟨Fl4SpecA64.MIN_BUDGET⟩ (fun _ => 0#u64)).machineState) rfl + (syscallNumberA .sysRecv) true .sysRecv rfl (Or.inl rfl) + exact ⟨r, 0#u64, ⟨Fl4SpecA64.MIN_BUDGET⟩, fun _ => 0#u64, _, syscallNumberA .sysRecv, true, .sysRecv, ⟨Hy⟩⟩ + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitRcCombA.lean b/proofs/Fl4ProofsA64/P3/A64WitRcCombA.lean new file mode 100644 index 000000000..2518a35e8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitRcCombA.lean @@ -0,0 +1,380 @@ +/- +P3 (aarch64, A64-P3 non-vacuity witness, line witrc, part 2): **the combined witness (`ReplyRecv`).** + +The receive witness state `witSc cFail` (`P3/A64WitRcA`) with its REPLY register also `cFail` (`v6`): the CSpace walk of the +REPLY cptr fails as well. So + +* the first half of `ReplyRecv` is a no-op on both sides (`FirstScopeA.lookupFail`, `JSyscallA.lookupFailA`; the spec's + outcome is unique, `lookupFail_uniqueW`), and +* the receive half is the cap-fault arm (`RecvScopeA.capFaultNull`) at the state the first half reached (`= sb`, `τ`). + +**Arm exercised**: first half `lookupFail`, second half `capFaultNull`; no endpoint or notification exists in `w1`, so no +send/receive arm is instantiated (see `P3/A64WitRcA`). `R1` of the Step-0 note (the first half's reached state) is the +no-op, so the cheap variant applies. + +Named premises: `OpaqueWA` [P], the witness parameters. New module. +-/ +import Fl4ProofsA64.P3.A64WitRcA +import Fl4ProofsA64.P3.Stage3SysCombA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Wit +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P1.W7.R.ST.BootWit Fl4ProofsA64.P3 + Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 + +noncomputable section + +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA WClock) + +local notation "wa" => core.num.U64.wrapping_add + +/-- **The REPLY register word of the receive witness is `cFail`.** -/ +theorem wit_replyWord {r now mt sl : U64} {uw : U64 → U64} : + bL.mem (witSc cFail r now mt sl uw) (regWA (bL.curW (witSc cFail r now mt sl uw)) layout.reg.REPLY) = cFail := by + rw [curW2] + have e : layout.reg.REPLY = 6#u64 := by simp [layout.reg.REPLY, layout.reg.X6] + rw [e, wit_regWord (c0 := cFail) 6#u64 (by simp)] + simp [witRtW, v6] + +/-- **The REPLY cptr fails to look up.** -/ +theorem wit_replyLookup_fail {r now mt sl : U64} {uw : U64 → U64} : + cspace.lookup_slot bst (witSc cFail r now mt sl uw) (bL.curW (witSc cFail r now mt sl uw)) + (bL.mem (witSc cFail r now mt sl uw) (regWA (bL.curW (witSc cFail r now mt sl uw)) layout.reg.REPLY)) = + ok (.Err (error.LookupFault.GuardMismatch 0#u64 64#u64 51#u64)) := by + rw [wit_replyWord, curW2] + exact wit_lookupSlot_fail + +section generic +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {J7 : JSlotA S} {s : S} {a : A} {σ : State Unit} {m : McState} + +/-- **A failing slot lookup of a non-blocking invocation has one spec outcome**: `(.ok (), σ)`. -/ +theorem lookupFail_uniqueW + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) + (rep : Bool) {cptr : U64} {lf : error.LookupFault} + (hl : cspace.lookup_slot st s (L.curW s) cptr = ok (.Err lf)) : + ∀ y, y ∈ ((fl4HandleInvocationR (Z := Unit) rep false false true true (Fl4SpecA64.toBl cptr.bv)).run σ).1 → + y = (.ok (), σ) := by + intro y hy + have ct : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have htZ : L.curW s ∈ Z.T := J.sr.curT + have hth : Z.th (L.curW s) = some .tcb := (J.j.1.thT _).2 htZ + obtain ⟨x, hk, -⟩ := J.ep.tcb (L.curW s) htZ + have gmi : getMessageInfo (Z := Unit) σ.curThread σ = + ({(Fl4SpecA64.dataToMessageInfo (x.tcbArch.tcbContext.userRegs Fl4SpecA64.msg_info_register), σ)}, False) := by + rw [ct]; exact getMessageInfo_eqA hk + have gc : (NonDet.gets fun s : Fl4SpecA64.State Unit => s.curThread) σ = ({(σ.curThread, σ)}, False) := rfl + rw [fl4HandleInvocationR_firstA, run_bind_okA (run_liftEA gc)] at hy + unfold withoutPreemption at hy + rw [run_bind_okA (run_liftEA gmi)] at hy + obtain ⟨lr, elr', se, hse, hrel⟩ := spec_existsA (lookup_slot_refinesA Z.th s σ J.j.1.st J.j.1.cv _ hth cptr) + have el : lr = .Err lf := okinj (elr'.symm.trans hl) + subst el + cases se with + | ok _ => exact hrel.1.elim + | error lf' => + rw [← ct] at hse + have front : (frontSpecA σ.curThread (Fl4SpecA64.toBl cptr.bv) + (Fl4SpecA64.dataToMessageInfo (x.tcbArch.tcbContext.userRegs Fl4SpecA64.msg_info_register))).run σ = + ({(.error (.capFault (ofBl (Fl4SpecA64.toBl cptr.bv)) false lf'), σ)}, False) := by + unfold frontSpecA + rw [run_bind_errorA (lcs_errA (ofBl (Fl4SpecA64.toBl cptr.bv)) hse)] + unfold syscall withoutPreemption at hy + rw [run_bind_okA (run_liftEA (show (ExceptT.run (frontSpecA σ.curThread (Fl4SpecA64.toBl cptr.bv) + (Fl4SpecA64.dataToMessageInfo (x.tcbArch.tcbContext.userRegs Fl4SpecA64.msg_info_register))) : + SMonad Unit _) σ = _ from front))] at hy + unfold NonDetE.liftE at hy + rw [ExceptT.run_lift] at hy + obtain ⟨y', hy', hx⟩ := mem_bindA.1 hy + obtain rfl := mem_pureA hx + simp only [Fl4Spec.NonDet.when, Bool.false_eq_true, ↓reduceIte] at hy' + rw [mem_pureA hy'] + +end generic + + +/-! ## The combined scope at the witness -/ + +/-- **`CombScopeA` at the post-budget state of the combined witness** (`ReplyRecv`): the first half's slot lookup +fails (a no-op), the receive half is the cap-fault arm at the same state. -/ +theorem wit_combScope {Z : XSetsA} {r mt sl : U64} {uw : U64 → U64} {ab : WA} {τ : Fl4SpecA64.State Unit} + (Jr : RcJ Z cFail r wNow mt sl uw ab τ) (rep : Bool) : + CombScopeA bst Wit2.AR1 (w1OS KB IB 1) ∅ ∅ ∅ Z.T rep .sysReplyRecv (witSc cFail r wNow mt sl uw) ab τ := by + have hl : cspace.lookup_slot bst (witSc cFail r wNow mt sl uw) (bL.curW (witSc cFail r wNow mt sl uw)) + (CombCptrA bst (witSc cFail r wNow mt sl uw) .sysReplyRecv) = + ok (.Err (error.LookupFault.GuardMismatch 0#u64 64#u64 51#u64)) := by + unfold CombCptrA + rw [if_neg (by decide)] + exact wit_replyLookup_fail + refine ⟨.lookupFail hl, fun receiveReply _ s3 σ3 e1 e2 => ?_⟩ + obtain ⟨e1', -⟩ := Jr.lookupFailA rep hl + obtain ⟨-, h2⟩ := Prod.mk.inj (ok_inj_ff (e1.symm.trans e1')) + obtain ⟨hs, -⟩ := Prod.mk.inj h2 + obtain ⟨-, hs3⟩ := Prod.mk.inj (lookupFail_uniqueW Jr rep hl _ e2) + subst hs + subst hs3 + exact .capFaultNull (wit_lookupCap_fail (c0 := cFail) rfl) wit_faultCap (wit_faultHandler_null Jr) + +/-! ## `hNat`: every outcome of the combined call creates no `runningVM` thread -/ + +set_option maxHeartbeats 4000000 in +theorem wit_combNoVm (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) + (ha : WClock a (witSAc cFail wNow mt sl uw).machineState) (number : I64) (rep : Bool) {τf : Fl4SpecA64.State Unit} + (h : ((), τf) ∈ (kOpA (.syscall number rep .sysReplyRecv) (witSAc cFail wNow mt sl uw)).1) : NoVmA τf := by + have I := wit_entryIn O (c0 := cFail) (r := r) (mt := mt) (uw := uw) hsl hr a ha + obtain ⟨a1, hb, -⟩ := wit_budget_id O (c0 := cFail) hsl hr a ha (uw := uw) (mt := mt) (r := r) + have budget := JSyscallA.budgetOkSysA (AR' := fun _ _ => True) I.J I.hvp I.P I.hClock I.hnd I.C I.hC I.hNow I.hAr I.hmb + (fun s1 a1 σ1 _ e _ _ _ _ _ _ _ suf => by + rw [wit_hsuf O hsl e] at suf + exact absurd (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst suf))).1 (by decide)) + obtain ⟨⟨b, sb, ab⟩, eb, τ, e1, -, tr⟩ := spec_existsA budget + have ee := ok_inj_ff (eb.symm.trans hb) + have hsb : sb = witSc cFail r wNow mt sl uw := congrArg (fun p => p.2.1) ee + have hb1 : b = true := congrArg Prod.fst ee + obtain ⟨Jr, -⟩ := tr hb1 + rw [hsb] at Jr + have e1' : fl4BudgetOk (Z := Unit) (witSAc cFail wNow mt sl uw) = ({(true, τ)}, False) := by + rw [hb1] at e1; exact e1 + have nvτ : NoVmA τ := wit_noVmC.of_vm (budgetOk_vm (by rw [e1']; exact Set.mem_singleton _)) + have hcap := wit_lookupCap_fail (c0 := cFail) (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) rfl + have hl := wit_replyLookup_fail (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) + have rv : ∀ b c τ', ((), τ') ∈ (handleRecv (Z := Unit) b c τ).1 → VmKA τ τ' := fun b c => + JSyscallA.recvCapFault_vmA Wit2.ar1_plat Jr (blocking := b) (canReply := c) hcap (wit_faultHandler_null Jr) + have htZ : bL.curW (witSc cFail r wNow mt sl uw) ∈ witZA.T := Jr.sr.curT + obtain ⟨x, hk, -⟩ := Jr.ep.tcb _ htZ + have ct : τ.curThread = specPtr (bL.curW (witSc cFail r wNow mt sl uw)) := Jr.j.1.sch.curThread + have reg : x.tcbArch.tcbContext.userRegs replyRegister = + (bL.mem (witSc cFail r wNow mt sl uw) (regWA (bL.curW (witSc cFail r wNow mt sl uw)) layout.reg.REPLY)).bv := by + have e : Endp.regA (bL.curW (witSc cFail r wNow mt sl uw)) (regIdxA replyRegister) = + regWA (bL.curW (witSc cFail r wNow mt sl uw)) layout.reg.REPLY := by + unfold Endp.regA regWA + rw [regIdxA_replyA] + rw [← e] + exact ((Jr.ep.at_tcb htZ hk).regs replyRegister).symm + have capRead : withoutPreemption (getCapReg (Z := Unit) replyRegister) = NonDetE.liftE (getCapReg replyRegister) := rfl + have capRead' : getCapReg (Z := Unit) replyRegister τ = ({(toBl + (bL.mem (witSc cFail r wNow mt sl uw) (regWA (bL.curW (witSc cFail r wNow mt sl uw)) layout.reg.REPLY)).bv, τ)}, + False) := by + unfold getCapReg NonDet.liftM + rw [nd_gets_bindSc, ct, nd_bind_singleA' (asUser_getRegister_eqA hk _), reg] + rfl + have body : ∀ y, y ∈ ((fl4HandleEvent (Z := Unit) rep (.syscallEvent .sysReplyRecv)).run + (witSAc cFail wNow mt sl uw)).1 → y.1 = .ok () ∧ VmKA τ y.2 := fun y hy => by + unfold fl4HandleEvent at hy + dsimp only at hy + rw [run_lift_bindA e1'] at hy + simp only [Fl4Spec.NonDetE.whenE, ↓reduceIte, fl4HandleSyscall, fl4HandleSyscallWith, withoutPreemption] at hy + rw [ExceptT.run_bind] at hy + obtain ⟨y0, hy0, hy⟩ := mem_bindA.1 hy + rw [run_liftEA capRead'] at hy0 + obtain rfl := Set.mem_singleton_iff.1 hy0 + dsimp only at hy + rw [ExceptT.run_bind] at hy + obtain ⟨y1, hy1, hy⟩ := mem_bindA.1 hy + obtain rfl := lookupFail_uniqueW Jr rep hl y1 hy1 + dsimp only at hy + unfold NonDetE.liftE at hy + rw [ExceptT.run_lift] at hy + obtain ⟨y', hy', hx⟩ := mem_bindA.1 hy + obtain rfl := mem_pureA hx + exact ⟨rfl, rv _ _ y'.2 hy'⟩ + unfold kOpA at h + dsimp only at h + rw [nd_gets_bindSc, nd_bind_oneSc (wit_pc (c0 := cFail))] at h + obtain ⟨⟨v, σ1⟩, hv, h⟩ := mem_bindA.1 h + obtain ⟨-, rfl⟩ := Prod.mk.inj (mem_pureA h) + unfold Fl4Spec.NonDetE.handleE at hv + rw [ExceptT.run_mk] at hv + obtain ⟨y, hy, hv⟩ := mem_bindA.1 hv + obtain ⟨ey, ky⟩ := body y hy + rw [ey] at hv + obtain ⟨-, es⟩ := Prod.mk.inj (mem_pureA hv) + subst es + exact nvτ.of_vm ky + + +/-- **`kRuns` of the combined witness.** -/ +theorem wit_kRunsC {r mt sl : U64} {uw : U64 → U64} (number : I64) (rep : Bool) (call : Fl4SpecA64.Syscall) + (hnum : number = syscallNumberA call) + (hc : call = .sysReplyRecv ∨ call = .sysNBSendRecv ∨ call = .sysNBSendWait) : + kRuns bst (witSc cFail r wNow mt sl uw) (.syscall number rep call) := by + have rng : ¬ number < fl4_abi.syscall.SYSCALL_MIN ∧ ¬ number > fl4_abi.syscall.SYSCALL_MAX := by + subst hnum + rcases hc with rfl | rfl | rfl <;> simp only [syscallNumberA] <;> + first | decide | scalar_tac | (constructor <;> simp [fl4_abi.syscall.SYSCALL_MIN, fl4_abi.syscall.SYSCALL_MAX, + fl4_abi.syscall.SysReplyRecv, fl4_abi.syscall.SysNBSendRecv, fl4_abi.syscall.SysNBSendWait] <;> decide) + have ct : sched.cur_thread bst (witSc cFail r wNow mt sl uw) = ok (bwv RTb) := by rw [cur_thread_ok, curW2] + have hset : obj.Tcb.set_reg bst (bwv RTb) (witSc cFail r wNow mt sl uw) layout.reg.FAULT_IP + (core.num.U64.wrapping_sub (bL.mem (witSc cFail r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64) = + ok (bL.wr (witSc cFail r wNow mt sl uw) (Endp.regA (bwv RTb) layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (bL.mem (witSc cFail r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64)) := by + obtain ⟨q, hq, e⟩ := spec_existsA (obj.Tcb.set_reg.spec (st := bst) (witSc cFail r wNow mt sl uw) (bwv RTb) + layout.reg.FAULT_IP (core.num.U64.wrapping_sub (bL.mem (witSc cFail r wNow mt sl uw) + (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64)) + rw [hq, e] + have fid : bL.wr (witSc cFail r wNow mt sl uw) (Endp.regA (bwv RTb) layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (bL.mem (witSc cFail r wNow mt sl uw) (regWA (bwv RTb) layout.reg.NEXT_IP)) 4#u64) = + witSc cFail r wNow mt sl uw := by + have := wit_faultIP_id (c0 := cFail) (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) + rwa [curW2] at this + have hf : bL.mem (witSc cFail r wNow mt sl uw) (core.num.U64.wrapping_add (bwv RTb) 3456#u64) = 0#u64 := by + have v : (core.num.U64.wrapping_add (bwv RTb) 3456#u64).val = (bwv RTb).val + 3456 := by + rw [wa_valm, vRT]; exact Nat.mod_eq_of_lt (by simp) + have := wit_rtWords (c0 := cFail) (r := r) (now := wNow) (mt := mt) (sl := sl) (uw := uw) _ 3456 (by norm_num) + (by norm_num) v + rw [this]; simp [witRtW, rtW] + refine ⟨rng.1, rng.2, bwv RTb, _, witSc cFail r wNow mt sl uw, 0#u64, ct, tcb_reg_eqA _ _ _, + hset.trans (by rw [fid]), ?_, ?_⟩ + · rw [flags_ok, hf] + · simp + +end + +end Fl4ProofsA64.P3.Wit + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **The premises of `kernelEntryComb_recGA`** (exact binder list; module docstring). -/ +structure CombEntryHyps (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) + (AR AR' : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) + (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (m : McState) + (Clock : A → MachineState → Prop) (s : S) (a : A) (σ : State Unit) (tm : A → Nat → DeadlineViewA) + (view : State Unit → Fl4TimerView) (number : I64) (rep : Bool) (call : Syscall) : Type where + plain : PlainStore st + hM : MaxSpi ar + hPl : ArchPlat ar + Env : FaultEnvA st ar Z + hlimit : fl4MaxReleaseTime = MAX_RELEASE_TIME + hag : fl4MinBudget = MIN_BUDGET + hconv : Fl4TicksToUsLegacyAgree + v2 : config_ARM_GIC_V3 = false + arch : ArchSwFA st ar + P : FinPlatA ar AR' + hnum : number = syscallNumberA call + hc : call = .sysReplyRecv ∨ call = .sysNBSendRecv ∨ call = .sysNBSendWait + run : kRuns st s (.syscall number rep call) + I : KEntryFaultInA st ar AR AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m Clock s a σ + hCharge : SysChargeA st ar AR AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m Clock s a σ + hScope : ∀ (Q : U64 → U64 → List U64) (Rl : U64 → List U64) sb ab τ (τPC : State Unit), + fl4SyscallFaultIP (Z := Unit) σ.curThread σ = ({((), τPC)}, False) → + syscall.budget_ok st ar (L.wr s (Endp.regA (L.curW s) layout.reg.FAULT_IP) + (core.num.U64.wrapping_sub (L.mem s (regWA (L.curW s) layout.reg.NEXT_IP)) 4#u64)) a = ok (true, sb, ab) → + fl4BudgetOk (Z := Unit) τPC = ({(true, τ)}, False) → + JSyscallA st AR' { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) sb ab τ m → CounterStepA τ → + CombScopeA st ar OS N E Rp Z.T rep call sb ab τ + hGap : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → + ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → + ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view + hNat : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → + ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → + A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → ∀ τ1 τ2, + ((), τ1) ∈ (fl4Schedule kLimitA view τ).1 → ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → + ∀ y, τ2.kheap τ2.curThread = some (.tcb y) → y.tcbState ≠ .ext .runningVM + +variable {AR AR' : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {m : McState} {Clock : A → MachineState → Prop} {s : S} {a : A} {σ : State Unit} + {tm : A → Nat → DeadlineViewA} {view : State Unit → Fl4TimerView} {number : I64} {rep : Bool} {call : Syscall} + +/-- The premises give `kernelEntryComb_recGA`'s conclusion. -/ +theorem CombEntryHyps.concl (h : CombEntryHyps st ar AR AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ m Clock s a σ + tm view number rep call) : + kCodeA st ar s a (.syscall number rep call) ⦃ out => + StepPostA (KExitA st ar AR' h.hPl.ipa m) + (kOpA (.syscall number rep call) >>= fun _ => fl4Finish kLimitA view) σ out ⦄ := by + haveI := h.plain + exact kernelEntryComb_recGA h.hM h.hPl h.Env h.hlimit h.hag h.hconv h.v2 h.arch h.P number rep call h.hnum h.hc h.run + h.I h.hCharge h.hScope h.hGap h.hNat + +end + +end + +end Fl4ProofsA64.P3 + +namespace Fl4ProofsA64.P3.Wit +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P1.W7.R.ST.BootWit Fl4ProofsA64.P3 + Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 + +noncomputable section + +set_option maxHeartbeats 4000000 in +/-- **`kernelEntryComb_recGA` at the combined witness** (`ReplyRecv`): the premises and the conclusion at one state. -/ +theorem wit_comb_top (O : Wit2.OpaqueWA) {r mt sl : U64} {uw : U64 → U64} + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : Wit2.WA) + (ha : Wit2.WClock a (witSAc cFail wNow mt sl uw).machineState) (number : I64) (rep : Bool) + (hnum : number = syscallNumberA .sysReplyRecv) : + ∃ Hy : CombEntryHyps bst Wit2.AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) + (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv + (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) + Wit2.WClock (witSc cFail r wNow mt sl uw) a (witSAc cFail wNow mt sl uw) Wit2.witTm + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a + (.syscall number rep .sysReplyRecv))) number rep .sysReplyRecv, + kCodeA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a (.syscall number rep .sysReplyRecv) ⦃ out => + StepPostA (KExitA bst Wit2.AR1 (fun _ _ => True) Wit2.ar1_plat.ipa (w1MA IB 1)) + (kOpA (.syscall number rep .sysReplyRecv) >>= fun _ => fl4Finish kLimitA + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a + (.syscall number rep .sysReplyRecv)))) + (witSAc cFail wNow mt sl uw) out ⦄ := by + let Hy : CombEntryHyps bst Wit2.AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) + (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv + (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) + Wit2.WClock (witSc cFail r wNow mt sl uw) a (witSAc cFail wNow mt sl uw) Wit2.witTm + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a + (.syscall number rep .sysReplyRecv))) number rep .sysReplyRecv := + { plain := ⟨fun _ => rfl⟩ + hM := Wit2.ar1_spi + hPl := Wit2.ar1_plat + Env := Wit2.ar1_faultEnv O witZA (wit_hCs O) + hlimit := O.hlimit + hag := O.hag + hconv := O.hconv + v2 := O.v2 + arch := Wit2.witArchSwOf + P := Wit2.ar1_finPlat O + hnum := hnum + hc := Or.inl rfl + run := wit_kRunsC number rep _ hnum (Or.inl rfl) + I := wit_entryIn O hsl hr a ha + hCharge := wit_hCharge O hsl a + hScope := fun Q Rl sb ab τ τPC _ eb _ Jr _ => by + obtain ⟨a1, hb, -⟩ := wit_budget_id O (c0 := cFail) hsl hr a ha + rw [wit_faultIP_id, hb] at eb + have e := ok_inj_ff eb + have hsb : sb = witSc cFail r wNow mt sl uw := (congrArg (fun p => p.2.1) e).symm + subst hsb + exact wit_combScope Jr rep + hGap := Wit2.wit2b_hGapA O Wit2.witArchSwOf (wit_hCs O) _ a _ (.syscall number rep .sysReplyRecv) + hNat := hNat_of_noVmA fun _ _ _ _ op _ => wit_combNoVm O hsl hr a ha number rep op } + exact ⟨Hy, Hy.concl⟩ + +/-- **Non-vacuity of `kernelEntryComb_recGA`**: with `OpaqueWA` the only hypothesis, every witness-side parameter is +existential (`call = ReplyRecv`). -/ +theorem wit_comb_nonvacuous (O : Wit2.OpaqueWA) : + ∃ (r mt sl : U64) (uw : U64 → U64) (a : Wit2.WA) (number : I64) (rep : Bool) (call : Syscall), + Nonempty (CombEntryHyps bst Wit2.AR1 (fun _ _ => True) (fun _ _ => True) witZA (KtH (w1H KB IB 1) {bwv KTb}) + (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r wNow mt sl uw) w1Tb w1Lv + (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) (w1MA IB 1) + Wit2.WClock (witSc cFail r wNow mt sl uw) a (witSAc cFail wNow mt sl uw) Wit2.witTm + (gapViewA bst Wit2.AR1 (kBodyA bst Wit2.AR1 (witSc cFail r wNow mt sl uw) a (.syscall number rep call))) + number rep call) := by + obtain ⟨r, hr⟩ := wit_r_ex + obtain ⟨Hy, -⟩ := wit_comb_top O (r := r) (mt := 0#u64) (sl := ⟨Fl4SpecA64.MIN_BUDGET⟩) (uw := fun _ => 0#u64) + (BitVec.le_refl _) hr (witA0 (witSAc cFail wNow 0#u64 ⟨Fl4SpecA64.MIN_BUDGET⟩ (fun _ => 0#u64)).machineState) rfl + (syscallNumberA .sysReplyRecv) true rfl + exact ⟨r, 0#u64, ⟨Fl4SpecA64.MIN_BUDGET⟩, fun _ => 0#u64, _, syscallNumberA .sysReplyRecv, true, .sysReplyRecv, ⟨Hy⟩⟩ + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitRecA.lean b/proofs/Fl4ProofsA64/P3/A64WitRecA.lean index c9c3a6b60..327beef4d 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitRecA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitRecA.lean @@ -20,13 +20,13 @@ noncomputable section local notation "wa" => core.num.U64.wrapping_add -variable {r now mt sl : U64} {uw : U64 → U64} +variable {cw r now mt sl : U64} {uw : U64 → U64} local notation "S1" => w1S KB IB 1 r now mt sl uw -local notation "S2" => witS r now mt sl uw +local notation "S2" => witSc cw r now mt sl uw local notation "H1" => w1H KB IB 1 local notation "σ1" => w1SUA KB IB 1 now mt sl uw -local notation "σ2" => witSA now mt sl uw +local notation "σ2" => witSAc cw now mt sl uw local notation "M1" => w1MA IB 1 local notation "KTH" => KtH (w1H KB IB 1) {bwv KTb} local notation "OS1" => w1OS KB IB 1 @@ -103,7 +103,7 @@ theorem osk2 : OSKeep bst OS1 S1 S2 := J.toJStage3A.osKeep_stepNA (wstep J) theorem j72 : J7A bst (J7R2A bst (w1Ar ar) n) (w1ZA KB IB 1) KTH OS1 S2 σ2 M1 := by have hk : bL.ksb S2 = bL.ksb S1 := rfl - have bx := bxi2 AR ar n J + have bx := bxi2 (c0 := cw) AR ar n J have hΩ : ∀ b, WitW b → b ∉ (KTH).omega := fun b w hb => omega_keep AR ar n J hb w have hAs : ∀ b, WitW b → ¬ AsW (bL.ksb S1) b := fun b w h => by obtain ⟨o, o1, o2, -, e⟩ := h @@ -249,12 +249,12 @@ theorem sr2 : SchedSRA bst witZA M1 (w1SchedScCoreA IB) S2 σ2 := by · have : 2 ^ (k + Fl4SpecA64.minSchedContextBits) ≤ 2 ^ 7 := Nat.pow_le_pow_right (by omega) (by omega) rw [l.1, vSC] at o1 o2 omega - obtain ⟨⟨Q, Rq, q⟩, -⟩ := bxi2 AR ar n J + obtain ⟨⟨Q, Rq, q⟩, -⟩ := bxi2 (c0 := cw) AR ar n J have q0 : SchedQueuesInv bst (KTH).tcbs (bootCs 1) (KTH).omega (KTH) S1 witZA.Q witZA.R := by obtain ⟨⟨Q', R', q'⟩, -⟩ := J.sys.ent.bxi exact SchedQueuesInv.reCoreA q' (by rw [J.tcbs]; exact R.core) have core : SchedCoreA bst witZA.T witZA.Cs S2 witZA.Q witZA.R := by - have c := (sqi2 AR ar n J q0).toCoreA + have c := (sqi2 (c0 := cw) AR ar n J q0).toCoreA rw [J.tcbs] at c exact c have run : RunQA σ2 := by diff --git a/proofs/Fl4ProofsA64/P3/A64WitStA.lean b/proofs/Fl4ProofsA64/P3/A64WitStA.lean index 60c7e30c4..8b0d48ac9 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitStA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitStA.lean @@ -26,37 +26,45 @@ noncomputable section local notation "wa" => core.num.U64.wrapping_add /-! ## The state -/ +/-- The REPLY register (`x6`) of the witness: `0` for the Send witness (`c0 = 2`), the CAP word itself otherwise (the +receive/combined witness: both cptrs fail to look up). -/ +def v6 (c0 : U64) : U64 := if c0 = 2#u64 then 0#u64 else c0 + /-- **The nine changed words** (module docstring). -/ -def witM (mem : U64 → U64) (b : U64) : U64 := +def witM (c0 : U64) (mem : U64 → U64) (b : U64) : U64 := if b.val = KBn + 223488 then bwv RTb else if b.val = KBn + 223504 then 0#u64 else if b.val = KBn + 223512 then bwv SCb - else if b.val = RTb + 256 then 2#u64 + else if b.val = RTb + 256 then c0 else if b.val = RTb + 264 then 98437#u64 else if b.val = RTb + 272 then 1000#u64 else if b.val = RTb + 280 then 64#u64 else if b.val = RTb + 288 then 2#u64 else if b.val = RTb + 296 then 64#u64 + else if b.val = RTb + 304 then v6 c0 else if b.val = RTb + 528 then 4194300#u64 else mem b /-- **The witness state.** -/ -def witS (r now mt sl : U64) (uw : U64 → U64) : BS := ⟨witM (w1M KB IB 1 r now mt sl uw), KB, 0#u64⟩ +def witSc (c0 r now mt sl : U64) (uw : U64 → U64) : BS := ⟨witM c0 (w1M KB IB 1 r now mt sl uw), KB, 0#u64⟩ + +/-- **The Send witness**: the CAP register names slot 2 (the root CNode cap, a CNode Copy message). -/ +abbrev witS (r now mt sl : U64) (uw : U64 → U64) : BS := witSc 2#u64 r now mt sl uw /-- The words `witM` may change. -/ def WitW (b : U64) : Prop := b.val = KBn + 223488 ∨ b.val = KBn + 223504 ∨ b.val = KBn + 223512 ∨ (RTb + 256 ≤ b.val ∧ b.val < RTb + 552) -theorem witM_keep {mem : U64 → U64} {b : U64} (h : ¬ WitW b) : witM mem b = mem b := by +theorem witM_keep {c0 : U64} {mem : U64 → U64} {b : U64} (h : ¬ WitW b) : witM c0 mem b = mem b := by unfold WitW at h unfold witM rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega), - if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] + if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] -variable {r now mt sl : U64} {uw : U64 → U64} +variable {c0 r now mt sl : U64} {uw : U64 → U64} local notation "S1" => w1S KB IB 1 r now mt sl uw -local notation "S2" => witS r now mt sl uw +local notation "S2" => witSc c0 r now mt sl uw local notation "H1" => w1H KB IB 1 theorem mem2 {b : U64} (h : ¬ WitW b) : bL.mem S2 b = bL.mem S1 b := witM_keep h @@ -163,7 +171,7 @@ theorem scW_keep {c o : U64} (hc : c ∈ (H1).scs) (ho : o.val < 128) : bL.mem S theorem curW2 : bL.curW S2 = bwv RTb := by have v := nodeV (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (c := 0#u64) (o := layout.node.CUR_THREAD) (by simp) (by simp [layout.node.CUR_THREAD]) - change witM _ (bL.nodeAt S2 0#u64 layout.node.CUR_THREAD) = _ + change witM c0 _ (bL.nodeAt S2 0#u64 layout.node.CUR_THREAD) = _ rw [nodeAt21] unfold witM rw [if_pos (by rw [v]; simp [layout.node.CUR_THREAD])] @@ -173,7 +181,7 @@ theorem actW2 : bL.actionW S2 = 0#u64 := by (o := layout.node.SCHED_ACTION) (by simp) (by simp [layout.node.SCHED_ACTION]) have e : (bL.nodeAt S1 0#u64 layout.node.SCHED_ACTION).val = KBn + 223504 := by rw [v]; simp [layout.node.SCHED_ACTION] - change witM _ (bL.nodeAt S2 0#u64 layout.node.SCHED_ACTION) = _ + change witM c0 _ (bL.nodeAt S2 0#u64 layout.node.SCHED_ACTION) = _ rw [nodeAt21] unfold witM rw [if_neg (by omega), if_pos e] @@ -183,7 +191,7 @@ theorem cscW2 : bL.cscW S2 = bwv SCb := by (o := layout.node.CUR_SC) (by simp) (by simp [layout.node.CUR_SC]) have e : (bL.nodeAt S1 0#u64 layout.node.CUR_SC).val = KBn + 223512 := by rw [v]; simp [layout.node.CUR_SC] - change witM _ (bL.nodeAt S2 0#u64 layout.node.CUR_SC) = _ + change witM c0 _ (bL.nodeAt S2 0#u64 layout.node.CUR_SC) = _ rw [nodeAt21] unfold witM rw [if_neg (by omega), if_neg (by omega), if_pos e] diff --git a/proofs/Fl4ProofsA64/P3/A64WitSyscA.lean b/proofs/Fl4ProofsA64/P3/A64WitSyscA.lean index 9c0cc7e24..b42c00a78 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitSyscA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitSyscA.lean @@ -22,13 +22,13 @@ noncomputable section local notation "wa" => core.num.U64.wrapping_add -variable {r now mt sl : U64} {uw : U64 → U64} +variable {c0 r now mt sl : U64} {uw : U64 → U64} local notation "S1" => w1S KB IB 1 r now mt sl uw -local notation "S2" => witS r now mt sl uw +local notation "S2" => witSc c0 r now mt sl uw local notation "H1" => w1H KB IB 1 local notation "σ1" => w1SUA KB IB 1 now mt sl uw -local notation "σ2" => witSA now mt sl uw +local notation "σ2" => witSAc c0 now mt sl uw local notation "M1" => w1MA IB 1 local notation "KTH" => KtH (w1H KB IB 1) {bwv KTb} local notation "OS1" => w1OS KB IB 1 @@ -36,15 +36,15 @@ local notation "OS1" => w1OS KB IB 1 /-! ## The thread relations -/ /-- The root TCB's words at the witness. -/ -def witRtW (o : Nat) : U64 := - if o = 256 then 2#u64 else if o = 264 then 98437#u64 else if o = 272 then 1000#u64 else - if o = 280 then 64#u64 else if o = 288 then 2#u64 else if o = 296 then 64#u64 else if o = 528 then 4194300#u64 else rtW IB o +def witRtW (c0 : U64) (o : Nat) : U64 := + if o = 256 then c0 else if o = 264 then 98437#u64 else if o = 272 then 1000#u64 else + if o = 280 then 64#u64 else if o = 288 then 2#u64 else if o = 296 then 64#u64 else if o = 304 then v6 c0 else if o = 528 then 4194300#u64 else rtW IB o -theorem wit_rtWords : TcbWordsA (bL.mem S2) (bwv RTb) witRtW := by +theorem wit_rtWords : TcbWordsA (bL.mem S2) (bwv RTb) (witRtW c0) := by intro x o ho _ hx rw [vRT] at hx have h1 : bL.mem S1 x = rtW IB o := w1M_rt lay1 ho hx - change witM (w1M KB IB 1 r now mt sl uw) x = _ + change witM c0 (w1M KB IB 1 r now mt sl uw) x = _ change w1M KB IB 1 r now mt sl uw x = _ at h1 unfold witM witRtW rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), h1] @@ -52,7 +52,7 @@ theorem wit_rtWords : TcbWordsA (bL.mem S2) (bwv RTb) witRtW := by simp only [e] theorem wit_rtRegs (q : Fl4SpecA64.Register) : - (witRtW (256 + 8 * (regIdxA q).val)).bv = witTcbA.tcbArch.tcbContext.userRegs q := by + (witRtW c0 (256 + 8 * (regIdxA q).val)).bv = (witTcbA c0).tcbArch.tcbContext.userRegs q := by cases q <;> rfl theorem rtAddr : TcbAddr (bwv RTb) := w1_tcbPlaced (kb := KB) (ib := IB) (nc := 1) lay1 _ rtMem1 @@ -139,7 +139,7 @@ theorem wit_stage3A : JStage3A bst AR witZA KTH OS1 w1U (H1).scs have ep : EpStateRel (w1ZA KB IB 1).T ∅ ∅ w1BfA (bL.mem S2) σ2 := by refine ⟨fun e h => absurd h (Set.notMem_empty _), fun e h => absurd h (Set.notMem_empty _), fun t ht => ?_, fun bp h k hk => ?_⟩ - · obtain ⟨x, hx, e, -⟩ := wit_tcbs (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) t (tT t ht) + · obtain ⟨x, hx, e, -⟩ := wit_tcbs (c0 := c0) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) t (tT t ht) exact ⟨x, hx, e⟩ · have B := J.ep.buf bp h k hk change bp ∈ ({(bwv IPb, specPtr (bwv IPb))} : Set (U64 × Fl4SpecA64.Word)) at h @@ -151,7 +151,7 @@ theorem wit_stage3A : JStage3A bst AR witZA KTH OS1 w1U (H1).scs rw [e]; exact B have ntfn : NtfnStateRel ∅ (w1ZA KB IB 1).T (bL.mem S2) σ2 := by refine ⟨fun e h => absurd h (Set.notMem_empty _), fun t ht => ?_⟩ - obtain ⟨x, hx, -, e⟩ := wit_tcbs (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) t (tT t ht) + obtain ⟨x, hx, -, e⟩ := wit_tcbs (c0 := c0) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) t (tT t ht) exact ⟨x, hx, e⟩ have reply : ReplyStackRelA (bL.mem S2) ∅ (w1ZA KB IB 1).C σ2 (scNameA M1) (fun _ => []) := by refine ⟨fun c hc => ?_, fun _ _ _ _ _ h => absurd h List.not_mem_nil, fun _ h => absurd h (Set.notMem_empty _), @@ -167,7 +167,7 @@ theorem wit_stage3A : JStage3A bst AR witZA KTH OS1 w1U (H1).scs unfold sbWordA slotIdx; rw [z] have hy : IsSlotA (w1ZA KB IB 1).th (sbWordA t) := by rw [e]; exact isSlot_tcbA ((J.sr.thT t).2 ht) (by simp [layout.tcb.SLOT_BUFFER]) - have o := osk2 J _ (J.j5.2.1 _ hy) + have o := osk2 (cw := c0) J _ (J.j5.2.1 _ hy) unfold capA; rw [o.1, o.2.1] · obtain ⟨x, hx, -⟩ := J.ep.tcb t ht exact ⟨x, hx⟩ @@ -242,7 +242,7 @@ theorem wit_stage3A : JStage3A bst AR witZA KTH OS1 w1U (H1).scs obtain ⟨x', hx', d⟩ := kh_fwd hx refine ⟨x', y, k, hx', ?_, (sck _ _ _).2 e2, e3⟩ rcases d with rfl | ⟨rfl, rfl⟩ <;> exact e1 - · exact SpecIrqA.of_eq (SpecIrqA.updTcbA (x' := witTcbA) I.irqN w1KA_rt rfl) rfl rfl + · exact SpecIrqA.of_eq (SpecIrqA.updTcbA (x' := witTcbA c0) I.irqN w1KA_rt rfl) rfl rfl have sidle : SIdleA σ2 M1 1 := by have D := J.sidle have ik : ∀ c < 1, (σ2).kheap ((M1).idleThreadOf c) = (σ1).kheap ((M1).idleThreadOf c) := fun c hc => @@ -278,7 +278,7 @@ theorem wit_stage3A : JStage3A bst AR witZA KTH OS1 w1U (H1).scs have schedValid : SchedValidA σ2 := by refine ⟨fun d p t h => (by rw [rq0] at h; cases h), fun _ _ => ?_, fun t x c hx hb hs => ?_, fun t h => (by rw [rl0] at h; cases h)⟩ - · exact ⟨⟨witTcbA, specPtr (bwv SCb), kh_rt, rfl, _, _, (sck _ _ _).2 w1KA_sc, rfl⟩, + · exact ⟨⟨witTcbA c0, specPtr (bwv SCb), kh_rt, rfl, _, _, (sck _ _ _).2 w1KA_sc, rfl⟩, by rw [rl0]; exact List.not_mem_nil⟩ · obtain ⟨x0, h0, d⟩ := kh_back hx rcases d with rfl | ⟨rfl, rfl⟩ @@ -287,7 +287,7 @@ theorem wit_stage3A : JStage3A bst AR witZA KTH OS1 w1U (H1).scs have h := stage3_curA (Z := w1ZA KB IB 1) (f := Function.update (w1ZA KB IB 1).curOf 0 (specPtr (bwv RTb))) (g := Function.update (w1ZA KB IB 1).curScOf 0 (specPtr (bwv SCb))) (s' := S2) (σ' := σ2) J.toJStage3A - (wstep J) specSched ssz qkeep rfl hcurOf (bxi2 AR ar n J) (sys2 AR ar n J).1 (sys2 AR ar n J).2 userOK (j72 J) + (wstep (cw := c0) J) specSched ssz qkeep rfl hcurOf (bxi2 (c0 := c0) AR ar n J) (sys2 (c0 := c0) AR ar n J).1 (sys2 (c0 := c0) AR ar n J).2 userOK (j72 (cw := c0) J) (sr2 J) ep ntfn reply bufCover bufAl idle mcp yr sinv sidle runVcpu blkQ schedValid exact h @@ -303,7 +303,7 @@ theorem wit_syscallA_of (h1 : Fl4SpecA64.fl4A64Platform.numNodes = 1) : JSyscall cases h' rfl have curInv : CurInvA σ2 := - { tcb := ⟨witTcbA, kh_rt, rfl, rfl⟩ + { tcb := ⟨witTcbA c0, kh_rt, rfl, rfl⟩ sc := ⟨_, _, (sck _ _ _).2 w1KA_sc⟩ active := fun _ y k h => by rw [rsc y k h]; rfl notRel := List.not_mem_nil } @@ -327,8 +327,8 @@ theorem wit_syscallA_of (h1 : Fl4SpecA64.fl4A64Platform.numNodes = 1) : JSyscall have := congrArg UScalar.val (specPtr_inj (show specPtr (bwv SCb) = specPtr (idleSA IB c) from e)) rw [vSC, idleSA_val layA hc', ibv] at this omega - have sact : SActA σ2 := ⟨fun u h => (by cases h), witTcbA, kh_rt, Or.inl rfl⟩ - have J3 := wit_stage3A J + have sact : SActA σ2 := ⟨fun u h => (by cases h), witTcbA c0, kh_rt, Or.inl rfl⟩ + have J3 := wit_stage3A (c0 := c0) J refine { toJStage3EntryA := { toJStage3A := J3 @@ -364,7 +364,7 @@ theorem wit_syscallA {A : Type} (AR : A → HwRootA → Prop) (ar : machine.Arch JSyscallA bst AR witZA (KtH (w1H KB IB 1) {bwv KTb}) (w1OS KB IB 1) w1U (w1H KB IB 1).scs (Fl4ProofsA64.P2.BootEpB.w1Pp KB IB 1 r now mt sl uw) w1Tb w1Lv (IB : U64).val ((IB : U64).val + 1 * 8192) ∅ ∅ ∅ w1BfA (fun _ => []) (w1SchedScCoreA IB) 1 (J5A bst) (J7A bst (J7R2A bst (w1Ar ar) n)) - (witS r now mt sl uw) a (witSA now mt sl uw) (w1MA IB 1) := + (witSc c0 r now mt sl uw) a (witSAc c0 now mt sl uw) (w1MA IB 1) := wit_syscallA_of (w1_stage3_one AR ar r now mt sl uw n hAR h1 hsl hr) h1 end diff --git a/proofs/Fl4ProofsA64/P3/A64WitUtA.lean b/proofs/Fl4ProofsA64/P3/A64WitUtA.lean new file mode 100644 index 000000000..308544306 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitUtA.lean @@ -0,0 +1,58 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line ut): **the premise-level witness of the Untyped Retype-with-reset arm** (`UtScopeA.retypeRst`). + +At the A64 witness world (`P3/A64Wit2*`; `resetChunkBits = 16` in `P3/A64Wit2PlatA`) the new [S]/[P] premises and the +state-level fields of the arm are satisfiable: + +* `wit_ut_cap`: the root CNode slot `53` of the Send witness state `witS` holds the RAM untyped `Untyped (UTb) 20 0 false` (free + index 0), so the `fi = 0` reset (`hS`) applies and no chunk is cleared; +* `wit_ut_nochild`: the spec CDT of the witness has no child of that slot (`hnochild`); +* `wit_ut_prems`: `n = numNodes ≤ numNodes`, `numNodes = 1`, `hCs`, `hIpa` (`S2IpaE`), `hchunk`, and `hS`; `hPost` is + vacuous (`fi = 0`). + +Not instantiated here (post-Stage-4 backlog, needs its own `witSu` world with an UntypedRetype message): the message-dependent +fields (`hlbl`, `hargs`, `hex`, `hdecS`, `hpin`). + +Named premises: `OpaqueWA` [P]. New module. +-/ +import Fl4ProofsA64.P3.A64Wit2TierA +import Fl4ProofsA64.P3.A64WitCopyA +import Fl4ProofsA64.P3.Stage3UtArmA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Wit +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P1.W7.R.ST.BootWit Fl4ProofsA64.P3 + +noncomputable section + +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA) + +/-- **The RAM untyped of the witness state**: root CNode slot `53`, free index `0`. -/ +theorem wit_ut_cap {r now mt sl : U64} {uw : U64 → U64} : + capA bst (witS r now mt sl uw) (rs 53) = .Untyped (bwv UTb) 20#u64 0#u64 false := by + rw [capS2_rs (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (i := 53) (by norm_num) + (by unfold rs; rw [bwv_val (by norm_num)])] + rfl + +/-- **No CDT child of the untyped** at the witness (the spec CDT is `w1CdtA`). -/ +theorem wit_ut_nochild : ¬ ∃ x, w1CdtA x = some (w1RrSlotA 53) := by + rintro ⟨x, h⟩ + unfold w1CdtA at h + split_ifs at h <;> first | cases h | (obtain h' := Option.some.inj h; simp [w1RrSlotA, bitsOfA] at h') + +/-- **The Untyped reset arm's new premises hold at the witness world.** -/ +theorem wit_ut_prems (O : OpaqueWA) (a : WA) : + Fl4SpecA64.fl4A64Platform.numNodes ≤ Fl4SpecA64.fl4A64Platform.numNodes ∧ Fl4SpecA64.fl4A64Platform.numNodes = 1 ∧ + (∀ c ∈ witZA.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) ∧ S2IpaE AR1 a ∧ + Fl4SpecA64.resetChunkBits = 16 ∧ + (∀ {r now mt sl : U64} {uw : U64 → U64} (p sb fi : U64), + capA bst (witS r now mt sl uw) (rs 53) = .Untyped p sb fi false → sb.val < 16 ∨ fi = 0#u64) := by + refine ⟨le_refl _, O.nodes, wit_hCs O, ⟨40#u64, rfl, by rw [O.ipaBits]; rfl⟩, O.chunk, ?_⟩ + intro r now mt sl uw p sb fi h + rw [wit_ut_cap] at h + obtain ⟨-, -, rfl, -⟩ := capability.Cap.Untyped.inj h + exact Or.inr rfl + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/ArchTopA.lean b/proofs/Fl4ProofsA64/P3/ArchTopA.lean index 3e9439edd..5d7afcfeb 100644 --- a/proofs/Fl4ProofsA64/P3/ArchTopA.lean +++ b/proofs/Fl4ProofsA64/P3/ArchTopA.lean @@ -129,7 +129,7 @@ theorem decInv_arch_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (hex : ExtraOKA Z.th (L.mem s) ex exs) (firstPhase : Bool) (bufOpt : Option Fl4SpecA64.ObjRef) (hPtMap : ∀ ptr mp asid va, cap = .PageTable ptr mp asid va → - lbl = fl4_abi.label.ARMPageTableMap → + lbl = fl4_abi.label.ARMPageTableMap → mp = false → UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr ∧ ptr ∉ S2PgE Z.X Z.T2 ∧ ptr ∉ Z.Y) (hFrMap : ∀ fp sz rt dev mp e asid va, cap = .Frame fp sz rt dev mp e asid va → lbl = fl4_abi.label.ARMPageMap → FrPlA sz fp mp asid) diff --git a/proofs/Fl4ProofsA64/P3/AsidCtrlTopA.lean b/proofs/Fl4ProofsA64/P3/AsidCtrlTopA.lean index d933e6542..26282eea3 100644 --- a/proofs/Fl4ProofsA64/P3/AsidCtrlTopA.lean +++ b/proofs/Fl4ProofsA64/P3/AsidCtrlTopA.lean @@ -1733,7 +1733,7 @@ theorem makePool_perform_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s domT := hSS5.domT.trans (hSS3.domT) vcur := hSS5.vcur.trans (hSS3.vcur) asid := hSS5.asid.trans (hSS3.asid) - domk := DomKeepA.trans (σ2 := σ2) ⟨rfl, rfl, rfl, rfl⟩ (hSS3.domk.trans (DomKeepA.trans (σ2 := σ4) ⟨rfl, rfl, rfl, rfl⟩ hSS5.domk)) } + domk := DomKeepA.trans (σ2 := σ2) (DomKeepA.ofKey rfl) (hSS3.domk.trans (DomKeepA.trans (σ2 := σ4) (DomKeepA.ofKey rfl) hSS5.domk)) } have hTcbKeep6 : TcbKeepA Z.T σ1 σ6 := by intro t ht x hx1 have hth : Z.th t = some .tcb := (E1.j.1.thT t).2 ht diff --git a/proofs/Fl4ProofsA64/P3/CancelIpcReplyA.lean b/proofs/Fl4ProofsA64/P3/CancelIpcReplyA.lean index 8a3638ab4..b2bb49af7 100644 --- a/proofs/Fl4ProofsA64/P3/CancelIpcReplyA.lean +++ b/proofs/Fl4ProofsA64/P3/CancelIpcReplyA.lean @@ -255,7 +255,7 @@ theorem replyArmHeadA exact ⟨z, by rw [hm1, updK_kheap, Function.update_of_ne e2, hσa, repStA_ne e1]; exact h, rfl, rfl, rfl⟩ -- the endpoint relation across the SC word and the spec updates have hscOff : FootEq Z.T E R Bf (L.mem s1) (L.mem s2) := - (epFrameOfMcsA H1'.toSchedSRN P (σ := σ1) (σ' := σ1) ⟨wm, SKeepA.refl _, SSzA.refl _⟩ rfl).1 + (epFrameOfMcsA H1'.toSchedSRN P (σ := σ1) (σ' := σ1) (MFrA.ofParts wm (SKeepA.refl _) (SSzA.refl _)) rfl).1 have E2 : EpStateRel Z.T E R Bf (L.mem s2) σm := by have Ea : EpStateRel Z.T E R Bf (L.mem s2) σa := by refine HE1.frame hPE hscOff ?_ diff --git a/proofs/Fl4ProofsA64/P3/DelAsidA.lean b/proofs/Fl4ProofsA64/P3/DelAsidA.lean index b67fbe818..420a97625 100644 --- a/proofs/Fl4ProofsA64/P3/DelAsidA.lean +++ b/proofs/Fl4ProofsA64/P3/DelAsidA.lean @@ -210,7 +210,7 @@ theorem pool_write_jointA (E : JEntTA st AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) have hER := J.1.ext.of_storePoolE (Lv := Z.Lv) (i := i) hp hk hkind (fun b hb => hmem b (hall b (.nslot b (.ext b hb))) (hExt b hb)) hunmS2 refine ⟨J.of_sameVsA (σ' := poolSetA σ2 p (Function.update f (BitVec.ofNat 9 i.val) (poolEntA word))) - (P0 := ∅) Hm (by constructor <;> first | rfl | exact ⟨rfl, rfl, rfl, rfl⟩) + (P0 := ∅) Hm (by constructor <;> first | rfl | exact DomKeepA.ofKey rfl) (fun q r hq => ?_) (fun q hq => ?_) (fun t ht => ?_) (fun c hc' => ?_) (fun v hv => ?_) rfl rfl (fun q v h => ?_) (fun q es h => ?_) (fun q l1 h => ?_) (fun _ h1 h2 => ⟨h1, h2⟩) (by rw [L.ksb_wr]; exact hVR) hER, @@ -243,7 +243,7 @@ theorem pool_write_jointA (E : JEntTA st AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) theorem JAtZAX.of_vmA (J : JAtZAX (L := L) AR Z s a σ m) {σ' : Fl4SpecA64.State Unit} (h : VmA σ σ') : JAtZAX (L := L) AR Z s a σ' m := by obtain ⟨mr, am, vt, nv, rfl⟩ := h - exact J.of_spec { toSpecGlobA := (by constructor <;> first | rfl | exact ⟨rfl, rfl, rfl, rfl⟩), kh := fun _ _ => rfl, ext := fun _ _ e _ => e, + exact J.of_spec { toSpecGlobA := (by constructor <;> first | rfl | exact DomKeepA.ofKey rfl), kh := fun _ _ => rfl, ext := fun _ _ e _ => e, cdt := rfl, orig := rfl } theorem JAtZAX.of_hwA (J : JAtZAX (L := L) AR Z s a σ m) {a' : A} {hw : HwRootA} (h : AR a' hw) : diff --git a/proofs/Fl4ProofsA64/P3/DelIrqWriteA.lean b/proofs/Fl4ProofsA64/P3/DelIrqWriteA.lean index 6da1ba9cb..ce6ac6245 100644 --- a/proofs/Fl4ProofsA64/P3/DelIrqWriteA.lean +++ b/proofs/Fl4ProofsA64/P3/DelIrqWriteA.lean @@ -242,7 +242,7 @@ theorem JStage3TA.irqWriteA [J7PpA st J7] [J7PpKA st J7] (fun t ht => by rw [stA_eq]; exact tK t ht _ (by simp) (by simp)) exact JStage3TA.of_irqWr (blkQ := J.blkQ.keepA (fun t ht => tK t ht 3336#u64 (by simp) (by simp)) (fun _ _ x' hx => Or.inr ⟨x', by rwa [kh] at hx, rfl⟩) (fun _ _ h => by rw [kh]; exact h) - (fun _ _ h => by rw [kh]; exact h)) J (Q := Z.Q) (Rl := Z.R) (curOf := Z.curOf) (curScOf := Z.curScOf) hi w HS SSz (QKeepA.of_kheap kh ⟨by rw [e2], by rw [e2], by rw [e2], by rw [e2]⟩) hirq um har + (fun _ _ h => by rw [kh]; exact h)) J (Q := Z.Q) (Rl := Z.R) (curOf := Z.curOf) (curScOf := Z.curScOf) hi w HS SSz (QKeepA.of_kheap kh (DomKeepA.ofKey (by rw [e2]))) hirq um har (fun _ _ => rfl) (fun t ht y hy => J.bufAl t ht y (by rw [← kh]; exact hy)) (ppEntA3 J.ent blk2 kb hvsT) sq2 (poolOff_keepTableA (Z := Z) J.poolOff kb hTable) (utFrI_schedSRA hw hW H2 J.sr) (utCnI_scCovA J.scCov H2) (utFrI_epA hw hW H2 J.ep J.iplaced.e) diff --git a/proofs/Fl4ProofsA64/P3/DelScInactA.lean b/proofs/Fl4ProofsA64/P3/DelScInactA.lean index a6eced9fc..9519b4b1e 100644 --- a/proofs/Fl4ProofsA64/P3/DelScInactA.lean +++ b/proofs/Fl4ProofsA64/P3/DelScInactA.lean @@ -229,7 +229,7 @@ theorem sc_set_inactiveA {Z : XSetsA} {m : Fl4SpecA64.McState} {κ : U64 → U64 exact keep _ (by simp) (by simp) (by simp) (by simp) have H' := H.scInactA hc hk (hnt x n hk) wrO rel hcc refine ⟨x, n, hk, schedContextSetInactive_eqA hk, H', wr, ?_, z72, z64⟩ - refine ⟨wrO.mono fun b hb => mwr_scObj hc hk hb, SKeepA.of_obj fun q o hq ho => ?_, SSzA.of_upd hk rfl⟩ + refine MFrA.ofParts (wrO.mono fun b hb => mwr_scObj hc hk hb) (SKeepA.of_obj fun q o hq ho => ?_) (SSzA.of_upd hk rfl) have hne : q ≠ scNameA m sc := fun e => by rw [e, hk] at hq; cases hq; exact ho x n rfl simp [updKSc, hne, hq] diff --git a/proofs/Fl4ProofsA64/P3/DelSuspendA.lean b/proofs/Fl4ProofsA64/P3/DelSuspendA.lean index e6b96c2e6..710b58ab3 100644 --- a/proofs/Fl4ProofsA64/P3/DelSuspendA.lean +++ b/proofs/Fl4ProofsA64/P3/DelSuspendA.lean @@ -399,7 +399,7 @@ theorem JStage3TA.suspend_recA [J7PpA st J7] [J7PpKA st J7] SchedFrameA σ σ' ∧ OSKeep st OS s out.1 ∧ (∃ y, σ'.kheap (specPtr t) = some (.tcb y) ∧ y.tcbState = .inactive) ∧ JStage3TA st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack' κ n (J5A st) J7 - out.1 out.2 σ' m ⦄ := by + out.1 out.2 σ' m ∧ BlkOthA (specPtr t) σ σ' ⦄ := by have htH : t ∈ H.tcbs := by rw [J.tcbs]; exact ht have hna : L.actionW s ≠ t := by intro e @@ -509,7 +509,7 @@ theorem JStage3TA.suspend_recA [J7PpA st J7] [J7PpKA st J7] have J' := JStage3TA.of_schedWrSN (blkQ := bq) J (stack' := stk) hsub (Ac' := Ac) (Q := Q) (Rl := Rl) (curOf := Z.curOf) (curScOf := Z.curScOf) (s' := s') (a' := a) (σ' := σ') w HS SSz (Sched.qk_of hsus) hum J.j.1.ar (fun _ _ => rfl) bufAl ent sq poolOff sr scCov ep rn rs buf idle mcp yr sinv sidle rv hvr nsw sact j.1 (by rw [hQ7]; exact j.2) - exact ⟨rfl, σ', stk, Q, Rl, hspec, w, ⟨HS, SSz, hum⟩, osk, hy, J'⟩ + exact ⟨rfl, σ', stk, Q, Rl, hspec, w, ⟨HS, SSz, hum⟩, osk, hy, J', KB⟩ end diff --git a/proofs/Fl4ProofsA64/P3/DelSuspendLiveA.lean b/proofs/Fl4ProofsA64/P3/DelSuspendLiveA.lean index 0e4320045..0e740e234 100644 --- a/proofs/Fl4ProofsA64/P3/DelSuspendLiveA.lean +++ b/proofs/Fl4ProofsA64/P3/DelSuspendLiveA.lean @@ -58,6 +58,63 @@ theorem fl4CancelRun_detA subst e exact ⟨h, rfl⟩ +/-- **`fl4CancelRun t` changes no TCB other than `t`'s** (tcbregr). -/ +theorem fl4CancelRun_blkOthA + (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m) + {t : U64} (ht : t ∈ Z.T) {σ1 : Fl4SpecA64.State Unit} + (hcan : ((), σ1) ∈ (fl4CancelRun (Z := Unit) (specPtr t) σ).1) : BlkOthA (specPtr t) σ σ1 := by + obtain ⟨xt, hkt, -, hrv⟩ := J.j.2.1.tcb t ht + by_cases hr0 : L.mem s (runVcpuA t) = 0#u64 + · have h := fl4CancelRun_noneA hkt (by rw [hrv, hr0]; unfold optRefA; simp) + rw [h] at hcan + have e : σ1 = σ := congrArg Prod.snd (show ((), σ1) = ((), σ) from hcan) + subst e + exact PreO.refl σ1 + · have hvcV : L.mem s (runVcpuA t) ∈ Z.V := (J.vcRun.run t ht).resolve_left hr0 + obtain ⟨xv, hkv, -, -⟩ := J.j.2.1.obj _ hvcV + have h := fl4CancelRun_someA hkt hkv (by rw [hrv]; unfold optRefA; simp [hr0]) + rw [h] at hcan + have e := congrArg Prod.snd (show ((), σ1) = ((), _) from hcan) + subst e + have hne' : ∀ p, σ.kheap p = some (.archObj (.vcpu xv)) → specPtr t ≠ p := fun p hp c => by + rw [c, hp] at hkt; cases hkt + have hne := hne' _ hkv + refine PreO.trans (BlkOthA.updA (t := specPtr t) + (o := .archObj (.vcpu { xv with vcpuExt := { xv.vcpuExt with runCaller := none } })) hkv + (fun _ h => by cases h) (fun _ h => by cases h) (fun _ h => by cases h)) ?_ + exact BlkOthA.updA (t := specPtr t) + (o := .tcb { xt with tcbExt := { xt.tcbExt with tcbRunVcpu := none } }) + (by simp only [Function.update_of_ne hne]; exact hkt) + (fun _ _ => rfl) (fun _ h => by cases h) (fun _ h => by cases h) + +/-- **`fl4CancelRun t` keeps the queues and the scheduler action** (tcbregr). -/ +theorem fl4CancelRun_sameQ + (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m) + {t : U64} (ht : t ∈ Z.T) {σ1 : Fl4SpecA64.State Unit} + (hcan : ((), σ1) ∈ (fl4CancelRun (Z := Unit) (specPtr t) σ).1) : + σ1.readyQueues = σ.readyQueues ∧ σ1.releaseQueue = σ.releaseQueue ∧ σ1.schedulerAction = σ.schedulerAction ∧ + ∀ p b sz, σ.kheap p = some (.archObj (.dataPage b sz)) → σ1.kheap p = some (.archObj (.dataPage b sz)) := by + obtain ⟨xt, hkt, -, hrv⟩ := J.j.2.1.tcb t ht + by_cases hr0 : L.mem s (runVcpuA t) = 0#u64 + · have h := fl4CancelRun_noneA hkt (by rw [hrv, hr0]; unfold optRefA; simp) + rw [h] at hcan + have e : σ1 = σ := congrArg Prod.snd (show ((), σ1) = ((), σ) from hcan) + subst e + exact ⟨rfl, rfl, rfl, fun _ _ _ h => h⟩ + · have hvcV : L.mem s (runVcpuA t) ∈ Z.V := (J.vcRun.run t ht).resolve_left hr0 + obtain ⟨xv, hkv, -, -⟩ := J.j.2.1.obj _ hvcV + have h := fl4CancelRun_someA hkt hkv (by rw [hrv]; unfold optRefA; simp [hr0]) + rw [h] at hcan + have e := congrArg Prod.snd (show ((), σ1) = ((), _) from hcan) + subst e + have hne' : ∀ p, σ.kheap p = some (.archObj (.vcpu xv)) → ∀ q b sz, σ.kheap q = some (.archObj (.dataPage b sz)) → + q ≠ p := fun p hp q b sz hq c => by rw [c, hp] at hq; cases hq + refine ⟨rfl, rfl, rfl, fun q b sz hq => ?_⟩ + have n1 : q ≠ specPtr t := fun c => by rw [c, hkt] at hq; cases hq + have n2 := hne' _ hkv q b sz hq + simp only [updKSc_kheap, Function.update_of_ne n1, Function.update_of_ne n2] + exact hq + set_option maxHeartbeats 1600000 in /-- **`sched.suspend` at the record, live VCPU run allowed** (module docstring). -/ theorem JStage3TA.suspend_liveRecA {ar : machine.Arch A} [J7PpA st J7] [J7PpKA st J7] [J7FrA st J7] @@ -83,7 +140,8 @@ theorem JStage3TA.suspend_liveRecA {ar : machine.Arch A} [J7PpA st J7] [J7PpKA s out.1 out.2 σ' m ∧ SchedValidA σ' ∧ (∀ R7 : Set U64 → JSlotA S, J7 = J7LA st R7 → (∀ y, IsSlotA Z.th y → y ∈ OS) → - Std6A st Z H OS Bf s σ → Std6A st Z H OS Bf out.1 σ') ⦄ := by + Std6A st Z H OS Bf s σ → Std6A st Z H OS Bf out.1 σ') ∧ + BlkOthA (specPtr t) σ σ' ⦄ := by have hcr := vcpu_cancel_run_stage3TA (ar := ar) (Clock := fun _ _ => True) J hSV R6 trivial ht unfold sched.suspend refine WP.spec_bind hcr ?_ @@ -96,12 +154,12 @@ theorem JStage3TA.suspend_liveRecA {ar : machine.Arch A} [J7PpA st J7] [J7PpKA s unfold sched.suspend at key rw [cancel_run_quietA s1 a t hrw1, bind_ok] at key refine WP.spec_mono key ?_ - rintro ⟨s', a'⟩ ⟨ea, σ', stk', Q, Rl, sp, w, F, osk, hy, J'⟩ + rintro ⟨s', a'⟩ ⟨ea, σ', stk', Q, Rl, sp, w, F, osk, hy, J', KB'⟩ have hq1 : fl4CancelRun (Z := Unit) (specPtr t) σ1 = ({((), σ1)}, False) := by obtain ⟨x', hx', -, hrv⟩ := J1.j.2.1.tcb t ht exact fl4CancelRun_quietA hx' (by rw [hrv, hrw1]; unfold optRefA; simp) rw [nd_bind_oneSc hq1] at sp - refine ⟨ea, s1, σ1, σ', stk', Q, Rl, ?_, hcan, w1, w, F, OSKeep.transA osk1 osk, hy, J', ?_, ?_⟩ + refine ⟨ea, s1, σ1, σ', stk', Q, Rl, ?_, hcan, w1, w, F, OSKeep.transA osk1 osk, hy, J', ?_, ?_, PreO.trans (fl4CancelRun_blkOthA J ht hcan) KB'⟩ · rw [nd_bind_oneSc hdet] exact sp · exact suspend_schedValid (specPtr t) σ1 hSV1 ((), σ') (by rw [sp]; rfl) diff --git a/proofs/Fl4ProofsA64/P3/DelSuspendSpecA.lean b/proofs/Fl4ProofsA64/P3/DelSuspendSpecA.lean index 5ae0b321c..c6672c1e6 100644 --- a/proofs/Fl4ProofsA64/P3/DelSuspendSpecA.lean +++ b/proofs/Fl4ProofsA64/P3/DelSuspendSpecA.lean @@ -328,18 +328,21 @@ theorem suspend_sstepA (t : ObjRef) : PresR SStepA (Fl4SpecA64.suspend (Z := Uni /-- Every TCB other than `t` keeps its state, and stays queued on the endpoints and notifications it was queued on. -/ structure BlkOthA (t : ObjRef) (σ σ' : State Unit) : Prop where tcb : ∀ u x, u ≠ t → σ.kheap u = some (.tcb x) → ∃ y, σ'.kheap u = some (.tcb y) ∧ y.tcbState = x.tcbState + /-- (tcbregr) Every TCB other than `t` is unchanged. -/ + tcbEq : ∀ u x, u ≠ t → σ.kheap u = some (.tcb x) → σ'.kheap u = some (.tcb x) ep : ∀ r y u, u ≠ t → σ.kheap r = some (.endpoint y) → u ∈ y.epQueue → ∃ y', σ'.kheap r = some (.endpoint y') ∧ u ∈ y'.epQueue ntfn : ∀ r y q u, u ≠ t → σ.kheap r = some (.notification y) → y.ntfnObj = .waitingNtfn q → u ∈ q → ∃ y' q', σ'.kheap r = some (.notification y') ∧ y'.ntfnObj = .waitingNtfn q' ∧ u ∈ q' theorem BlkOthA.of_kheap {t : ObjRef} {σ σ' : State Unit} (hk : σ'.kheap = σ.kheap) : BlkOthA t σ σ' := - ⟨fun _ x _ h => ⟨x, by rw [hk]; exact h, rfl⟩, fun _ y _ _ h m => ⟨y, by rw [hk]; exact h, m⟩, + ⟨fun _ x _ h => ⟨x, by rw [hk]; exact h, rfl⟩, fun _ x _ h => by rw [hk]; exact h, fun _ y _ _ h m => ⟨y, by rw [hk]; exact h, m⟩, fun _ y q _ _ h e m => ⟨y, q, by rw [hk]; exact h, e, m⟩⟩ instance (t : ObjRef) : PreO (BlkOthA t) := ⟨fun _ => BlkOthA.of_kheap rfl, fun {a b c} h1 h2 => by - refine ⟨fun u x ne h => ?_, fun r y u ne h m => ?_, fun r y q u ne h e m => ?_⟩ + refine ⟨fun u x ne h => ?_, fun u x ne h => h2.tcbEq u x ne (h1.tcbEq u x ne h), fun r y u ne h m => ?_, + fun r y q u ne h e m => ?_⟩ · obtain ⟨y, hy, e⟩ := h1.tcb u x ne h obtain ⟨z, hz, e'⟩ := h2.tcb u y ne hy exact ⟨z, hz, e'.trans e⟩ @@ -355,9 +358,12 @@ theorem BlkOthA.updA {t p : ObjRef} {σ : State Unit} {o0 o : KernelObject} (hp (hn : ∀ y, o0 = .notification y → ∃ y', o = .notification y' ∧ ∀ q u, u ≠ t → y.ntfnObj = .waitingNtfn q → u ∈ q → ∃ q', y'.ntfnObj = .waitingNtfn q' ∧ u ∈ q') : BlkOthA t σ { σ with kheap := Function.update σ.kheap p (some o) } := by - refine ⟨fun u x ne h => ?_, fun r y u ne h m => ?_, fun r y q u ne h e m => ?_⟩ - · have c : u ≠ p := fun c => ne (c.trans (ht x (Option.some.inj ((c ▸ hp).symm.trans h)))) - exact ⟨x, (Function.update_of_ne c _ _).trans h, rfl⟩ + have hT : ∀ u x, u ≠ t → σ.kheap u = some (.tcb x) → + { σ with kheap := Function.update σ.kheap p (some o) }.kheap u = some (.tcb x) := fun u x ne h => by + have c : u ≠ p := fun c => ne (c.trans (ht x (Option.some.inj ((c ▸ hp).symm.trans h)))) + exact (Function.update_of_ne c _ _).trans h + refine ⟨fun u x ne h => ?_, hT, fun r y u ne h m => ?_, fun r y q u ne h e m => ?_⟩ + · exact ⟨x, hT u x ne h, rfl⟩ · by_cases c : r = p · subst c obtain ⟨y', rfl, f⟩ := he y (Option.some.inj (hp.symm.trans h)) diff --git a/proofs/Fl4ProofsA64/P3/DelThrFpuA.lean b/proofs/Fl4ProofsA64/P3/DelThrFpuA.lean index 54a895d40..2762706e8 100644 --- a/proofs/Fl4ProofsA64/P3/DelThrFpuA.lean +++ b/proofs/Fl4ProofsA64/P3/DelThrFpuA.lean @@ -67,7 +67,7 @@ theorem qkeep : QKeepA σ σ' := by fun _ x h => ⟨x, F.back h (fun _ e => by cases e), List.Sublist.refl _⟩, fun _ y k h => ⟨y, k, F.back h (fun _ e => by cases e), fun r => ⟨r, id⟩⟩, fun _ y h => ⟨y, F.back h (fun _ e => by cases e), id⟩, - ⟨congrArg (·.domainIndex) F.eq, congrArg (·.domainStartIndex) F.eq, congrArg (·.domainList) F.eq, (by rw [F.arch])⟩⟩ + DomKeepA.ofKey (by unfold DomKeyA; rw [F.eq, F.arch])⟩ obtain ⟨x, hx, e⟩ := F.tcbBack h rcases e with rfl | ⟨f, rfl⟩ · exact ⟨_, hx, rfl⟩ diff --git a/proofs/Fl4ProofsA64/P3/DelThrSusA.lean b/proofs/Fl4ProofsA64/P3/DelThrSusA.lean index 7b73755eb..077227797 100644 --- a/proofs/Fl4ProofsA64/P3/DelThrSusA.lean +++ b/proofs/Fl4ProofsA64/P3/DelThrSusA.lean @@ -134,7 +134,7 @@ theorem JStage3TA.thrMid_recA {ar : machine.Arch A} [J7PpA st J7] [J7PpKA st J7] J7 { Z with Q := Q, R := R } := fun Q' Rl' => (hQ7 Q' Rl').trans (hQ7 Q R).symm refine WP.spec_mono (J5'.suspend_recA (J.curCore_lt hCs) hmb hmax htu ht X hQ7' (by rw [id5]; exact hti) hidles) ?_ - rintro ⟨s6, a6⟩ ⟨ea6, σ6, stack', Q', Rl', sp6, w6, F6, osk6, hy6, J6⟩ + rintro ⟨s6, a6⟩ ⟨ea6, σ6, stack', Q', Rl', sp6, w6, F6, osk6, hy6, J6, -⟩ dsimp only at ea6 sp6 w6 F6 osk6 hy6 J6 ⊢ rw [ea6] at J6 refine ⟨ea6, σ5, σ6, Q', Rl', Ac', stack', m5, F5, sp6, J6, OSKeep.transA osk4 (OSKeep.transA osk5 osk6), diff --git a/proofs/Fl4ProofsA64/P3/EmptyA.lean b/proofs/Fl4ProofsA64/P3/EmptyA.lean index 4b7243b6b..680acb914 100644 --- a/proofs/Fl4ProofsA64/P3/EmptyA.lean +++ b/proofs/Fl4ProofsA64/P3/EmptyA.lean @@ -457,7 +457,7 @@ theorem setCap_tcb_memA {σ : State Unit} {t : ObjRef} {x : Tcb} {i : Nat} (a : /-- (gen 8) A TCB's cap slot replaced is a slot-only spec step. -/ theorem SpecSlotA.setTcbA {σ : State Unit} {t : ObjRef} {x : Tcb} (hk : σ.kheap t = some (.tcb x)) (i : Nat) (a : Cap) : SpecSlotA σ (setObjA σ t (.tcb (tcbSetA x i a))) := by - refine ⟨⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, fun q => ?_⟩ + refine ⟨SpecGlobA.ofKey rfl, fun q => ?_⟩ by_cases e : q = t · subst e; exact Or.inr (Or.inr ⟨x, tcbSetA x i a, hk, by simp [setObjA], tcbNcA_setA x i a⟩) · exact Or.inl (by simp [setObjA, Function.update_of_ne e]) @@ -541,7 +541,7 @@ theorem StateRelA.setAbsA {th : TypedHeapA} {kb : U64} {mem mem' : U64 → U64} · simp only at e1 hc; subst e1 obtain ⟨cs, hk, hwf, -⟩ := hR.cnode p _ hc exact ⟨.cnode idx.length (Function.update cs idx (some a)), setCap_cnode_memA a hk hwf rfl, StateRelA.setCn hR hP hc hk rfl hca hcap rfl, - SpecSlotA.setCn hk rfl ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩⟩ + SpecSlotA.setCn hk rfl (SpecGlobA.ofKey rfl)⟩ · simp only at e1 e2; subst e1 e2 obtain ⟨x, hk, -⟩ := hR.tcb p ht exact ⟨.tcb (tcbSetA x i a), setCap_tcb_memA a hk hi, StateRelA.setTcbA hR hP ht hk hi hca hcap rfl, SpecSlotA.setTcbA hk i a⟩ @@ -723,7 +723,7 @@ theorem empty_slot_refinesA {A : Type} {ar : machine.Arch A} {T Ω Sg OS : Set U obtain ⟨o, hm, hR', hS'⟩ := StateRelA.setAbsA (σ := emptySlotCdtStateA σ xs) (hR.of_kheap rfl) hP hxs hnull hcap refine ⟨har, _, emptySlot_memA hg hacn hm, hR', CdtRelA.removeA hP hC hxs ?_ rfl rfl ?_, hT', hRO', hK', (SpecSlotA.ofKh (σ := σ) (σ' := emptySlotCdtStateA σ xs) rfl - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩).trans hS', fun y hy => ?_⟩ + (SpecGlobA.ofKey rfl)).trans hS', fun y hy => ?_⟩ · refine hT'.sub (fun y hy => hsub y hy) fun y hy hn => ?_ rw [hcr y hy (fun e => hn (e ▸ hxS))]; exact hnul y hy hn · intro sl hsl diff --git a/proofs/Fl4ProofsA64/P3/ExtMapPtA.lean b/proofs/Fl4ProofsA64/P3/ExtMapPtA.lean index 003fb16b2..9b0222912 100644 --- a/proofs/Fl4ProofsA64/P3/ExtMapPtA.lean +++ b/proofs/Fl4ProofsA64/P3/ExtMapPtA.lean @@ -242,7 +242,7 @@ end tabExt section helpers -private theorem extWalkN_shift_pt {Z : Type} (s : State Z) (va : Word) : +theorem extWalkN_shift_pt {Z : Type} (s : State Z) (va : Word) : ∀ (n : Nat) (p : ExtPos), ∃ k, k ≤ n ∧ (extWalkN s va n p).shift = p.shift - 9 * k := by intro n @@ -260,7 +260,7 @@ private theorem extWalkN_shift_pt {Z : Type} (s : State Z) (va : Word) : omega · exact ⟨0, Nat.zero_le _, by simp⟩ -private theorem s2Lookup_shift_pt (σ : State Unit) (r : ObjRef) (va : Word) : +theorem s2Lookup_shift_pt (σ : State Unit) (r : ObjRef) (va : Word) : let sh := (extLookupSlot σ s2Geom r va).shift sh = 39 ∨ sh = 30 ∨ sh = 21 ∨ sh = 12 := by obtain ⟨k, hk, heq⟩ := extWalkN_shift_pt σ va (s2Geom.levels - 1) (extTopPos s2Geom r va) @@ -275,7 +275,7 @@ private theorem s2Lookup_shift_pt (σ : State Unit) (r : ObjRef) (va : Word) : · rw [hl] at hk; rw [ht]; interval_cases k <;> simp · rw [hl] at hk; rw [ht]; interval_cases k <;> simp -private theorem hiLookup_shift_pt (σ : State Unit) (r : ObjRef) (va : Word) : +theorem hiLookup_shift_pt (σ : State Unit) (r : ObjRef) (va : Word) : let sh := (extLookupSlot σ highGeom r va).shift sh = 30 ∨ sh = 21 ∨ sh = 12 := by obtain ⟨k, hk, heq⟩ := extWalkN_shift_pt σ va (highGeom.levels - 1) (extTopPos highGeom r va) @@ -287,7 +287,7 @@ private theorem hiLookup_shift_pt (σ : State Unit) (r : ObjRef) (va : Word) : rw [hl] at hk interval_cases k <;> simp -private theorem s2LimitEq_pt {n : U64} (h : n.val = fl4A64Platform.s2IpaBits) : +theorem s2LimitEq_pt {n : U64} (h : n.val = fl4A64Platform.s2IpaBits) : ept.ipa_limit n = ok (⟨s2IpaLimit⟩ : U64) := by unfold ept.ipa_limit ept.geom s2IpaLimit s2IpaBitsOf by_cases h42 : n ≤ 42#u64 @@ -304,11 +304,11 @@ private theorem s2LimitEq_pt {n : U64} (h : n.val = fl4A64Platform.s2IpaBits) : rw [if_neg h44, if_neg h44', bind_ok, CapRt.shl_u64_eq 1#u64 48#u64 (by decide), bind_ok] rfl -private theorem s2IpaLimit_lt48_pt : s2IpaLimit.toNat < 2 ^ 48 := by +theorem s2IpaLimit_lt48_pt : s2IpaLimit.toNat < 2 ^ 48 := by unfold s2IpaLimit s2IpaBitsOf split_ifs <;> decide -private theorem hi_idx39_eq_pt (va : U64) (hlo : fl4_abi.consts.HIGH_VSPACE_BASE ≤ va) : +theorem hi_idx39_eq_pt (va : U64) (hlo : fl4_abi.consts.HIGH_VSPACE_BASE ≤ va) : idxA va 39#u64 = 511#u64 := by have h1 : 18446743936270598144 ≤ va.val := by have hb : fl4_abi.consts.HIGH_VSPACE_BASE.val = 18446743936270598144 := by @@ -320,7 +320,7 @@ private theorem hi_idx39_eq_pt (va : U64) (hlo : fl4_abi.consts.HIGH_VSPACE_BASE show (va.val / 2 ^ 39) % 512 = 511 omega -private theorem hi_base_ge_pt (va : U64) (hlo : fl4_abi.consts.HIGH_VSPACE_BASE ≤ va) {sh : Nat} (hsh : sh ≤ 30) : +theorem hi_base_ge_pt (va : U64) (hlo : fl4_abi.consts.HIGH_VSPACE_BASE ≤ va) {sh : Nat} (hsh : sh ≤ 30) : fl4_abi.consts.HIGH_VSPACE_BASE ≤ (va &&& ~~~(⟨BitVec.ofNat 64 (2 ^ sh - 1)⟩ : U64)) := by have hlo' : (18446743936270598144 : Nat) ≤ va.val := by have hb : fl4_abi.consts.HIGH_VSPACE_BASE.val = 18446743936270598144 := by @@ -378,7 +378,7 @@ private theorem hi_base_ge_pt (va : U64) (hlo : fl4_abi.consts.HIGH_VSPACE_BASE show fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ _ rw [hb, hbase]; exact hge -private theorem hi_can_pt (va : U64) (hlo : fl4_abi.consts.HIGH_VSPACE_BASE ≤ va) : CapRt.Canonical va := by +theorem hi_can_pt (va : U64) (hlo : fl4_abi.consts.HIGH_VSPACE_BASE ≤ va) : CapRt.Canonical va := by have h1 : 18446743936270598144 ≤ va.val := by have hb : fl4_abi.consts.HIGH_VSPACE_BASE.val = 18446743936270598144 := by unfold fl4_abi.consts.HIGH_VSPACE_BASE; rfl @@ -407,11 +407,11 @@ private theorem hi_can_pt (va : U64) (hlo : fl4_abi.consts.HIGH_VSPACE_BASE ≤ omega simp [hodd] -private theorem mask_eq_ofNat_pt {sh : Nat} (hsh : sh = 39 ∨ sh = 30 ∨ sh = 21) : +theorem mask_eq_ofNat_pt {sh : Nat} (hsh : sh = 39 ∨ sh = 30 ∨ sh = 21) : Fl4SpecA64.mask sh = BitVec.ofNat 64 (2 ^ sh - 1) := by rcases hsh with rfl | rfl | rfl <;> decide -private theorem performExtMap_mem_pt {σ1 σ2 : State Unit} {cap : ArchCap} {cte : CslotPtr} {pte : PTE} +theorem performExtMap_mem_pt {σ1 σ2 : State Unit} {cap : ArchCap} {cte : CslotPtr} {pte : PTE} {sl : ExtSlot} (hset : ((), σ2) ∈ (setCap (Z := Unit) (.archObjectCap cap) cte σ1).1) (hok : ExtSlotOkX σ2 sl) : @@ -424,7 +424,7 @@ private theorem performExtMap_mem_pt {σ1 σ2 : State Unit} {cap : ArchCap} {cte rw [nd_bind_oneD (storeExtSlot_runX hok pte)]; rfl exact ⟨((), σ2), hset, by dsimp only; rw [hst]; rfl⟩ -private theorem extSlotOk_of_s2Slot_pt {Pp Tb X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {σ : State Unit} +theorem extSlotOk_of_s2Slot_pt {Pp Tb X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {σ : State Unit} (E : ExtVsRelA Pp Tb X Y T2 Sh2 mem σ) {luSl : U64} {sl : ExtSlot} {sh : Nat} (hsl : SlotRelE (G2E T2 Sh2) (TopS2E X) luSl sl sh) : ExtSlotOkX σ sl := by rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, rfl, rfl⟩ | ⟨r0, j0, hr0, hj0, rfl, rfl, -⟩ @@ -437,7 +437,7 @@ private theorem extSlotOk_of_s2Slot_pt {Pp Tb X Y T2 : Set U64} {Sh2 : U64 → N · obtain ⟨es, hk, -⟩ := E.s2root r0 hr0 exact ⟨.stage2Root es, extObjAt_someX.2 hk⟩ -private theorem extSlotOk_of_hiSlot_pt {Pp Tb X Y : Set U64} {Lv : U64 → Nat} {mem : U64 → U64} {ksb : U64} +theorem extSlotOk_of_hiSlot_pt {Pp Tb X Y : Set U64} {Lv : U64 → Nat} {mem : U64 → U64} {ksb : U64} {σ : State Unit} (R : VsRelA Pp Tb Lv X Y mem ksb σ) {luSl : U64} {sl : ExtSlot} {sh : Nat} (hsl : SlotRelE (G1E Tb Lv) (TopHiE Y) luSl sl sh) : ExtSlotOkX σ sl := by rcases hsl with ⟨t, i, ⟨ht, h1, -⟩, hi, rfl, rfl⟩ | ⟨y, j, hy, hj, rfl, rfl, -⟩ @@ -451,7 +451,7 @@ private theorem extSlotOk_of_hiSlot_pt {Pp Tb X Y : Set U64} {Lv : U64 → Nat} · obtain ⟨l1, hk, -⟩ := R.high y hy exact ⟨.highVSpace l1, extObjAt_someX.2 hk⟩ -private theorem extSlotRead_of_s2Slot_pt {Pp Tb X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {σ : State Unit} +theorem extSlotRead_of_s2Slot_pt {Pp Tb X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {σ : State Unit} (E : ExtVsRelA Pp Tb X Y T2 Sh2 mem σ) {luSl : U64} {sl : ExtSlot} {sh : Nat} (hsl : SlotRelE (G2ReachE Pp X T2 Sh2 mem σ) (TopS2ReachE Pp X σ) luSl sl sh) : DescRelE (G2E T2 Sh2) sh (mem luSl) (sl.read σ) := by @@ -468,7 +468,7 @@ private theorem extSlotRead_of_s2Slot_pt {Pp Tb X Y T2 : Set U64} {Sh2 : U64 → rw [hread] exact (he hact j0 hj1024 hj0).1 -private theorem extSlotRead_of_hiSlot_pt {Pp Tb X Y : Set U64} {Lv : U64 → Nat} {mem : U64 → U64} {ksb : U64} +theorem extSlotRead_of_hiSlot_pt {Pp Tb X Y : Set U64} {Lv : U64 → Nat} {mem : U64 → U64} {ksb : U64} {σ : State Unit} (R : VsRelA Pp Tb Lv X Y mem ksb σ) {luSl : U64} {sl : ExtSlot} {sh : Nat} (hsl : SlotRelE (G1ReachE Pp Tb Y Lv mem ksb) (TopHiReachE Pp Y mem ksb) luSl sl sh) : DescRelE (G1E Tb Lv) sh (mem luSl) (sl.read σ) := by @@ -485,25 +485,25 @@ private theorem extSlotRead_of_hiSlot_pt {Pp Tb X Y : Set U64} {Lv : U64 → Nat rw [hread] exact descE_of_pteRel (k := 1) (by omega) (by omega) (he hact j hj) -private theorem run_liftME_congr_pt {α β : Type} {f : α → β} {m1 m2 : SEMonad Unit α} {σ : State Unit} +theorem run_liftME_congr_pt {α β : Type} {f : α → β} {m1 m2 : SEMonad Unit α} {σ : State Unit} (h : m1.run σ = m2.run σ) : (NonDetE.liftME f m1).run σ = (NonDetE.liftME f m2).run σ := by unfold NonDetE.liftME change (NonDet.bind (m1.run) _ σ) = (NonDet.bind (m2.run) _ σ) simp only [NonDet.bind, h] -private theorem liftE_gets_pt {α : Type} (f : State Unit → α) (σ : State Unit) : +theorem liftE_gets_pt {α : Type} (f : State Unit → α) (σ : State Unit) : (NonDetE.liftE (ε := SyscallError) (NonDet.gets f)).run σ = ({(Except.ok (f σ), σ)}, False) := by unfold NonDetE.liftE ExceptT.lift NonDet.gets simp [Functor.map, NonDet.bind, NonDet.pure] -private theorem unm_not_pp_pt {Pp Tb X Y : Set U64} {Lv : U64 → Nat} {mem : U64 → U64} {ksb : U64} +theorem unm_not_pp_pt {Pp Tb X Y : Set U64} {Lv : U64 → Nat} {mem : U64 → U64} {ksb : U64} {σ : State Unit} {ptr : U64} (R : VsRelA Pp Tb Lv X Y mem ksb σ) {pt : PT} (hk : σ.kheap (specPtr ptr) = some (.archObj (.pageTable pt))) : ptr ∉ Pp := by intro hpp obtain ⟨f, hf, -⟩ := R.pool ptr hpp rw [hk] at hf; cases hf -private theorem unm_mem_keep_pt {S : Type} {st : machine.Store S} [L : LawfulStore st] +theorem unm_mem_keep_pt {S : Type} {st : machine.Store S} [L : LawfulStore st] {Z : XSetsA} {H : Heap} {OS : Set U64} {s s2 : S} {ptr : U64} (hcurT : L.curW s ∈ H.tcbs) (hfitT : ∀ t ∈ H.tcbs, t.val + 4096 ≤ 2 ^ 64) (sA : Aligned (stA (L.curW s))) @@ -804,7 +804,7 @@ theorem s2_map_pt_jA {ar : machine.Arch A} · exact J2.2.2.2.back p l1 (by rwa [kheap_writeX hp] at e) -- Construct JAtZAX at Z' directly from J2's components obtain ⟨J, V, X0, Y0⟩ := J2 - have HG : SpecGlobA σ2 (extSlotWriteX σ2 pos.slot pte) := (by constructor <;> first | rfl | exact ⟨rfl, rfl, rfl, rfl⟩) + have HG : SpecGlobA σ2 (extSlotWriteX σ2 pos.slot pte) := (by constructor <;> first | rfl | exact DomKeepA.ofKey rfl) have hT' : TcbKeepA Z.T σ2 (extSlotWriteX σ2 pos.slot pte) := TcbKeepA.of_eq fun t h => hkh _ (Or.inr (Or.inl ⟨t, h, rfl⟩)) have hC' : ∀ c ∈ Z.C, (extSlotWriteX σ2 pos.slot pte).kheap (scRenA m c) = σ2.kheap (scRenA m c) := @@ -1210,7 +1210,7 @@ theorem hi_map_pt_jA by_cases hp : p = extSlotObjX pos.slot · subst hp; obtain ⟨_, -, r, hr, hreq⟩ := hobj _ e (Or.inr (Or.inr ⟨l1, rfl⟩)); exact ⟨r, hr, hreq⟩ · exact J2.2.2.2.back p l1 (by rwa [kheap_writeX hp] at e) - exact J2.of_sameXA hSame (by constructor <;> first | rfl | exact ⟨rfl, rfl, rfl, rfl⟩) hkh rfl rfl hv' hx' hy' + exact J2.of_sameXA hSame (by constructor <;> first | rfl | exact DomKeepA.ofKey rfl) hkh rfl rfl hv' hx' hy' (fun q hq hl => ⟨Set.mem_insert_of_mem _ hq, by have hne : q ≠ ptr := fun e => UP.nt (e ▸ hq) show Function.update Z.Lv ptr n q = 0 @@ -1297,6 +1297,96 @@ private theorem dec_ptMap_noExtRootA (calling : Bool) (args : List Data) (xSlot | _ => rfl · simp only [hcond, and_false, ↓reduceIte, show archL .armPageTableMap ≠ archL .armPageTableUnmap by decide] +/-- **F-E: the spec's decode of `ARMPageTableMap` on a mapped normal page-table cap** with a first extra cap and at +least two arguments is `InvalidCapability 0` (the Ext branch checks `mapped` first; the rest is l4v's). -/ +private theorem dec_ptMapMapped_errA (calling : Bool) (args : List Data) (xSlot : CapRef) (cte : CslotPtr) + (p : ObjRef) (m0 : Asid × VSpaceRef) (vc : Cap) (sl : CslotPtr) (rest : List (Cap × CslotPtr)) + (σ : State Unit) (h1 : args.length > 1) : + (fl4ArchDecodeInvocation (Z := Unit) calling (archL .armPageTableMap) args xSlot cte + (.pageTableCap p .normalPtT (some m0)) ((vc, sl) :: rest)).run σ = + ({(.error (.invalidCapability 0), σ)}, False) := by + by_cases hext : ∃ e, vc = .archObjectCap (.ext e) + · obtain ⟨e, rfl⟩ := hext + unfold fl4ArchDecodeInvocation + simp only [List.length_cons, gt_iff_lt, Nat.zero_lt_succ, h1, and_self, ↓reduceIte, List.getElem?_cons_zero, + Fl4SpecA64.the, NonDetE.whenE, NonDetE.throwError] + exact run_bind_errorA (by simp) _ + · have hN : ∀ e, vc ≠ .archObjectCap (.ext e) := fun e h => hext ⟨e, h⟩ + rw [dec_ptMap_specA calling args xSlot cte ((vc, sl) :: rest) p (some m0) + (fun c sl' rest' hh e he => by + simp only [List.cons.injEq, Prod.mk.injEq] at hh + obtain ⟨⟨rfl, rfl⟩, -⟩ := hh + exact hN e he)] + apply run_liftME_errA + show (decodePageTableInvocation (specLabelWord (archL .armPageTableMap)) args cte + (.pageTableCap p .normalPtT (some m0)) ((vc, sl) :: rest)).run σ = _ + rw [ptInv_mapA invType_ptMapA] + exact ptDec_mappedA _ _ _ _ _ _ _ σ ⟨h1, by simp⟩ (by simp) + +set_option maxHeartbeats 4000000 in +/-- **F-E: `ARMPageTableMap` on a MAPPED page-table cap** (every path is an error, so no `UnmPtA` fresh-table fact is +needed): `pt_map_all_jA` without its fresh-table premises, for `mp = true`. -/ +theorem pt_map_mappedA {ar : machine.Arch A} + (cte : CslotPtr) (ptr asid va : U64) + (length buf : U64) (calling : Bool) (ex : Aeneas.Std.Array obj.Slot 3#usize) + (args : List U64) (hlen : length.val = args.length) + (x0 : U64) (hx0 : Aeneas.Std.Array.index_usize ex 0#usize = ok x0) + (xSlot : CapRef) (exs : List (Cap × CslotPtr)) + (hex : ExtraRelA Z.th (L.mem s) x0 (exs.map Prod.fst)) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableMap length (cslotAddrA cte) + (.PageTable ptr true asid va) buf ex ⦃ res => VsTopPostA (L := L) AR Z OS m σ + ((fl4ArchDecodeInvocation (Z := Unit) calling (archL .armPageTableMap) (args.map UScalar.bv) + xSlot cte (.pageTableCap (specPtr ptr) .normalPtT (mapDataA true asid va)) exs).run σ) s a res ⦄ := by + have hct : sched.cur_thread st s = ok (L.curW s) := cur_thread_ok s + have hne48 : ¬ fl4_abi.label.ARMPageTableMap = fl4_abi.label.ARMPageTableUnmap := by + unfold fl4_abi.label.ARMPageTableMap fl4_abi.label.ARMPageTableUnmap; decide + unfold vspace.decode_page_table + simp only [hct, bind_ok, hne48, ↓reduceIte, bne_self_eq_false, Bool.false_eq_true, extra0_eqA hx0] + rcases hex with ⟨rfl, hnil⟩ | ⟨hx0n, -, vc', vrest, ⟨hvwf, habsX⟩, hmap⟩ + · have he : exs = [] := List.map_eq_nil_iff.1 hnil + subst he + rw [if_pos rfl] + simp only [error.truncated, bind_ok] + refine (WP.spec_ok _).2 ⟨rfl, rfl, .truncatedMessage, ?_, Or.inl trivial⟩ + rw [dec_ptMap_noExtRootA calling _ xSlot cte [] _ _ (fun _ _ _ h => by cases h)] + apply run_liftME_errA + show (decodePageTableInvocation (specLabelWord (archL .armPageTableMap)) (args.map UScalar.bv) cte + (.pageTableCap (specPtr ptr) .normalPtT (mapDataA true asid va)) []).run σ = _ + rw [ptInv_mapA invType_ptMapA] + exact ptDec_truncA _ _ _ _ _ _ _ σ (fun ⟨_, h⟩ => by simp at h) + rw [if_neg hx0n] + obtain ⟨⟨vc, xsl⟩, rest, rfl⟩ : ∃ e rest, exs = e :: rest := by + cases exs with + | nil => simp at hmap + | cons e rest => exact ⟨e, rest, rfl⟩ + simp only [List.map_cons, List.cons.injEq] at hmap + obtain ⟨rfl, -⟩ := hmap + dsimp only + by_cases h2 : length >= 2#u64 + swap + · rw [if_neg h2] + simp only [error.truncated, bind_ok] + have hlt2 : ¬ ((args.map UScalar.bv).length > 1) := by + simp only [List.length_map, ← hlen]; intro h; exact h2 (by scalar_tac) + refine (WP.spec_ok _).2 ⟨rfl, rfl, .truncatedMessage, ?_, Or.inl trivial⟩ + unfold fl4ArchDecodeInvocation + simp only [hlt2, false_and, ↓reduceIte, show archL .armPageTableMap ≠ archL .armPageTableUnmap by decide] + apply run_liftME_errA + show (decodePageTableInvocation (specLabelWord (archL .armPageTableMap)) (args.map UScalar.bv) cte + (.pageTableCap (specPtr ptr) .normalPtT (mapDataA true asid va)) ((vc, xsl) :: rest)).run σ = _ + rw [ptInv_mapA invType_ptMapA] + exact ptDec_truncA _ _ _ _ _ _ _ σ (fun ⟨h, _⟩ => hlt2 h) + rw [if_pos h2] + have h2' : 2 ≤ args.length := by + have : 2 ≤ length.val := by scalar_tac + omega + obtain ⟨a0, a1, r', rfl⟩ : ∃ a0 a1 r', args = a0 :: a1 :: r' := by + match args, h2' with + | a0 :: a1 :: r', _ => exact ⟨_, _, _, rfl⟩ + simp only [List.map_cons, ↓reduceIte, error.invalid_cap, bind_ok] + refine (WP.spec_ok _).2 ⟨rfl, rfl, .invalidCapability 0, ?_, Or.inr ⟨0#u64, rfl, rfl⟩⟩ + exact dec_ptMapMapped_errA calling _ xSlot cte _ _ vc xsl rest σ (by simp) + set_option maxHeartbeats 4000000 in /-- **All `ARMPageTableMap` cases** (Stage-1, Stage-2, `ArmHighVSpace`, and all error/rejection paths), retiring `NoExtXA`. -/ @@ -1505,7 +1595,7 @@ theorem decInv_pt_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (x0 : U64) (hx0 : Aeneas.Std.Array.index_usize ex 0#usize = ok x0) (xSlot : CapRef) (exs : List (Cap × CslotPtr)) (hex : ExtraRelA Z.th (L.mem s) x0 (exs.map Prod.fst)) - (hMap : lbl = fl4_abi.label.ARMPageTableMap → + (hMap : lbl = fl4_abi.label.ARMPageTableMap → mp = false → UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr ∧ ptr ∉ S2PgE Z.X Z.T2 ∧ ptr ∉ Z.Y) : syscall.decode_invocation st ar s a lbl length (cslotAddrA cte) (.PageTable ptr mp asid va) block call cd fp buf ex ⦃ res => VsTopPostA (L := L) AR Z OS m σ ((fl4ArchDecodeInvocation (Z := Unit) calling @@ -1554,10 +1644,13 @@ theorem decInv_pt_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) exact vsTop_ofFaA hD hset (mem_archExtA hp) hJ T3 C3 by_cases h47 : lbl = fl4_abi.label.ARMPageTableMap · subst h47 - obtain ⟨UP, hS2, hY⟩ := hMap rfl have hlab : fl4LabelOf fl4_abi.label.ARMPageTableMap.bv = archL .armPageTableMap := by rw [fl4LabelOf_bvA, show fl4_abi.label.ARMPageTableMap.val = 47 by simp [fl4_abi.label.ARMPageTableMap]]; rfl rw [hlab] + by_cases hmp : mp = true + · subst hmp + exact pt_map_mappedA cte ptr asid va length buf calling ex args hlen x0 hx0 xSlot exs hex + obtain ⟨UP, hS2, hY⟩ := hMap rfl (by simpa using hmp) exact pt_map_all_jA E RS hTO hEO hK hT hIpa hTr hnul cte hab hos ptr asid va mp hcap UP hS2 hY length buf calling ex args hlen hargs x0 hx0 xSlot exs hex rw [decode_pt_otherA lbl length _ buf ex ptr asid va mp h48 h47] diff --git a/proofs/Fl4ProofsA64/P3/FinVsJA.lean b/proofs/Fl4ProofsA64/P3/FinVsJA.lean index 3017f34be..238926c04 100644 --- a/proofs/Fl4ProofsA64/P3/FinVsJA.lean +++ b/proofs/Fl4ProofsA64/P3/FinVsJA.lean @@ -51,7 +51,7 @@ theorem KmA.trans {σ1 σ2 σ3 : Fl4SpecA64.State Unit} (h1 : KmA σ1 σ2) (h2 : theorem KmA.globA {σ σ' : Fl4SpecA64.State Unit} (h : KmA σ σ') : SpecGlobA σ σ' ∧ σ'.cdt = σ.cdt ∧ σ'.isOriginalCap = σ.isOriginalCap := by obtain ⟨kh, ms, rfl⟩ := h - exact ⟨(by constructor <;> first | rfl | exact ⟨rfl, rfl, rfl, rfl⟩), rfl, rfl⟩ + exact ⟨(by constructor <;> first | rfl | exact DomKeepA.ofKey rfl), rfl, rfl⟩ /-- **Every outcome is `KmA`-related to its start** (module docstring). -/ def OutKmA {α : Type} (m : NonDet (Fl4SpecA64.State Unit) α) : Prop := diff --git a/proofs/Fl4ProofsA64/P3/FinVsXA.lean b/proofs/Fl4ProofsA64/P3/FinVsXA.lean index a5a902e31..9ad07f0ae 100644 --- a/proofs/Fl4ProofsA64/P3/FinVsXA.lean +++ b/proofs/Fl4ProofsA64/P3/FinVsXA.lean @@ -109,7 +109,7 @@ theorem JAtZAX.of_extPageA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, Foo · cases h · exact ⟨p0, h, rfl⟩ · exact J.2.2.2.back p l1 (by rwa [hkh p hp] at e) - exact J.of_sameXA (σ' := { σ with kheap := kh }) H (by constructor <;> first | rfl | exact ⟨rfl, rfl, rfl, rfl⟩) (fun p hp => hkh p (hne p hp)) rfl rfl + exact J.of_sameXA (σ' := { σ with kheap := kh }) H (by constructor <;> first | rfl | exact DomKeepA.ofKey rfl) (fun p hp => hkh p (hne p hp)) rfl rfl hv hx hy (fun _ hq hl => ⟨hq, hl⟩) VR ER /-- **`JAtZAX` across an Ext unmap's zero write and its spec outcome** (module docstring). -/ diff --git a/proofs/Fl4ProofsA64/P3/FrameA.lean b/proofs/Fl4ProofsA64/P3/FrameA.lean index 59832c8a2..459131f52 100644 --- a/proofs/Fl4ProofsA64/P3/FrameA.lean +++ b/proofs/Fl4ProofsA64/P3/FrameA.lean @@ -498,8 +498,25 @@ structure SpecSlotA (σ σ' : Fl4SpecA64.State Unit) : Prop extends SpecGlobA σ section spec variable {Z : XSetsA} {s : S} {σ σ' : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} -theorem SpecGlobA.refl (σ : Fl4SpecA64.State Unit) : SpecGlobA σ σ := - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ +/-- **The key of `SpecGlobA`**: the kept components as one tuple (record-extension convention, `AGENTS.md`, "Proof +records": adding a kept component edits this key, `SpecGlobA.ofKey`, `SpecGlobA.key` and the structure, nothing else). -/ +abbrev SpecGlobKeyA (σ : Fl4SpecA64.State Unit) := + (σ.curThread, σ.idleThread, σ.curSc, σ.schedulerAction, σ.curTime, σ.interruptStates, σ.interruptIrqNode, + σ.readyQueues, σ.releaseQueue, σ.consumedTime, σ.reprogramTimer, σ.curDomain, σ.domainTime, + σ.archState.armAsidTable, σ.archState.armCurrentVcpu, DomKeyA σ) + +/-- The one constructor of `SpecGlobA` to use at call sites: `ofKey rfl`, `ofKey (by rw [e])`. -/ +theorem SpecGlobA.ofKey {σ σ' : Fl4SpecA64.State Unit} (h : SpecGlobKeyA σ' = SpecGlobKeyA σ) : SpecGlobA σ σ' := by + simp only [SpecGlobKeyA, Prod.mk.injEq] at h + obtain ⟨h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, h14, h15, h16⟩ := h + exact ⟨h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, h14, h15, DomKeepA.ofKey (by simp only [DomKeyA, Prod.mk.injEq]; exact h16)⟩ + +theorem SpecGlobA.key {σ σ' : Fl4SpecA64.State Unit} (h : SpecGlobA σ σ') : SpecGlobKeyA σ' = SpecGlobKeyA σ := by + unfold SpecGlobKeyA + rw [h.cur, h.idle, h.csc, h.act, h.time, h.irqS, h.irqN, h.rq, h.rls, h.cons, h.repr, h.dom, h.domT, h.asid, + h.vcur, h.domk.key] + +theorem SpecGlobA.refl (σ : Fl4SpecA64.State Unit) : SpecGlobA σ σ := SpecGlobA.ofKey rfl theorem SpecSlotA.refl (σ : Fl4SpecA64.State Unit) : SpecSlotA σ σ := ⟨SpecGlobA.refl σ, fun _ => Or.inl rfl⟩ @@ -571,9 +588,7 @@ theorem ExtVsRelA.of_specSlot {Pp Tb : Set U64} {Lv : U64 → Nat} {X Y T2 : Set theorem SpecGlobA.trans {σ1 σ2 σ3 : Fl4SpecA64.State Unit} (h1 : SpecGlobA σ1 σ2) (h2 : SpecGlobA σ2 σ3) : SpecGlobA σ1 σ3 := - ⟨h2.cur.trans h1.cur, h2.idle.trans h1.idle, h2.csc.trans h1.csc, h2.act.trans h1.act, h2.time.trans h1.time, - h2.irqS.trans h1.irqS, h2.irqN.trans h1.irqN, h2.rq.trans h1.rq, h2.rls.trans h1.rls, h2.cons.trans h1.cons, - h2.repr.trans h1.repr, h2.dom.trans h1.dom, h2.domT.trans h1.domT, h2.asid.trans h1.asid, h2.vcur.trans h1.vcur, h1.domk.trans h2.domk⟩ + SpecGlobA.ofKey (h2.key.trans h1.key) /-- Slot-only spec steps compose (gen 5, `MoveA`; gen 8: moved here, with the TCB case). -/ theorem SpecSlotA.trans {σ1 σ2 σ3 : Fl4SpecA64.State Unit} (h1 : SpecSlotA σ1 σ2) (h2 : SpecSlotA σ2 σ3) : diff --git a/proofs/Fl4ProofsA64/P3/InsertA.lean b/proofs/Fl4ProofsA64/P3/InsertA.lean index 7c7fbb584..2f93c4cd9 100644 --- a/proofs/Fl4ProofsA64/P3/InsertA.lean +++ b/proofs/Fl4ProofsA64/P3/InsertA.lean @@ -470,7 +470,7 @@ theorem capInsert_memA {σ σ1 σ2 : State Unit} {a asc : Fl4SpecA64.Cap} {src d exact mem_bindA.2 ⟨(_, _), rfl, rfl⟩ theorem SpecSlotA.insFin (σ : State Unit) (src dst : CslotPtr) (b v : Bool) : SpecSlotA σ (insFinA σ src dst b v) := - ⟨⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, fun _ => Or.inl rfl⟩ + ⟨SpecGlobA.ofKey rfl, fun _ => Or.inl rfl⟩ /-- `StateRelA` across a memory with the same caps at every slot word. -/ theorem StateRelA.congrA {th : TypedHeapA} {mem mem' : U64 → U64} {σ : State Unit} (h : StateRelA th mem σ) diff --git a/proofs/Fl4ProofsA64/P3/IpcScPushA.lean b/proofs/Fl4ProofsA64/P3/IpcScPushA.lean index 93a6195ed..95ced3c1f 100644 --- a/proofs/Fl4ProofsA64/P3/IpcScPushA.lean +++ b/proofs/Fl4ProofsA64/P3/IpcScPushA.lean @@ -729,7 +729,7 @@ theorem bindReplyLinksFpA {s : S} {σ : State Unit} {stack : U64 → List U64} obtain ⟨H4, F4⟩ := writeLinkFrames (v := sc ||| 1#u64) H3 P PE hr na (by omega) (by omega) have F3 : FootEq Z.T E R Bf (L.mem (L.wr s1 (rPrevA r) old)) (L.mem s3) := (epFrameOfMcsA H2.toSchedSRN P - (σ' := σ) ⟨w3, SKeepA.refl _, SSzA.refl _⟩ rfl).1 + (σ' := σ) (MFrA.ofParts w3 (SKeepA.refl _) (SSzA.refl _)) rfl).1 have ws (d : U64) (hd : d ∈ R) (b : U64) (ha : Aligned b) (hl : d.val ≤ b.val) (hh : b.val < d.val + 32) : L.mem s3 b = L.mem (L.wr s1 (rPrevA r) old) b := w3.mem_eq ha (replyWordOffSchedA H2.toSchedSRN P hd hl hh).2 diff --git a/proofs/Fl4ProofsA64/P3/IpcScSendRunningA.lean b/proofs/Fl4ProofsA64/P3/IpcScSendRunningA.lean index 6af8bc275..bb2ce8694 100644 --- a/proofs/Fl4ProofsA64/P3/IpcScSendRunningA.lean +++ b/proofs/Fl4ProofsA64/P3/IpcScSendRunningA.lean @@ -53,7 +53,7 @@ private theorem sendPushSetRunningRawA {s : S} {σ : State Unit} {stack : U64 rintro s' ⟨w, H'⟩ have hHeap := stsAct_kheap (updK σ (specPtr d) (.tcb { x with tcbState := .running })) (specPtr d) have F : MFrA (st := st) Z m _ s' _ _ := - ⟨w.mono (fun _ eq => eq.symm ▸ swAction H1), SKeepA.of_kheap hHeap, SSzA.of_kheap hHeap⟩ + MFrA.ofParts (w.mono (fun _ eq => eq.symm ▸ swAction H1)) (SKeepA.of_kheap hHeap) (SSzA.of_kheap hHeap) have hMem := (KView.stsAct' (updK σ (specPtr d) (.tcb { x with tcbState := .running })) (specPtr d)).2.2.2 obtain ⟨foot, view⟩ := epFrameOfMcsA H1.toSchedSRN P F hMem exact ⟨H', E1.frame PE foot view, diff --git a/proofs/Fl4ProofsA64/P3/IpcXferOrthA.lean b/proofs/Fl4ProofsA64/P3/IpcXferOrthA.lean index f631cc1bc..d3cc92737 100644 --- a/proofs/Fl4ProofsA64/P3/IpcXferOrthA.lean +++ b/proofs/Fl4ProofsA64/P3/IpcXferOrthA.lean @@ -172,7 +172,7 @@ theorem xcOrth_ipcA {H : Heap} {OS : Set U64} {s0 : S} {σ0 : State Unit} have := hx.symm.trans (show σ.kheap p = some (.tcb y) from hy) cases this; rfl subst e; exact Or.inl ⟨rfl, fun h => h⟩) - exact ⟨hE', hsr, q.tcb, (L.ksb_wr _ _ _).trans q.ksb, { q.frame with kh := q.frame.kh, domk := ⟨q.frame.domk.index, q.frame.domk.start, q.frame.domk.table, q.frame.domk.gvs⟩ }⟩ + exact ⟨hE', hsr, q.tcb, (L.ksb_wr _ _ _).trans q.ksb, { q.frame with kh := q.frame.kh, domk := DomKeepA.ofKey q.frame.domk.key }⟩ · have hfoot : FootEq Z.T E R Bf (L.mem s) (L.mem s') := fun a ha hf => hw.mem_eq ha (fun h => hE a h hf) obtain ⟨hSS, hNB⟩ := SpecSlotA.sstepA hS diff --git a/proofs/Fl4ProofsA64/P3/McGrowA.lean b/proofs/Fl4ProofsA64/P3/McGrowA.lean new file mode 100644 index 000000000..8aab21f20 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/McGrowA.lean @@ -0,0 +1,39 @@ +/- +P3 (aarch64, A64-P3 Stage 4, R1): **the multi-core view after an Untyped Retype** (`McGrowA`). + +A Retype that creates a TCB gives the new TCB the affinity `some 0` (`utRtMA`), and one that resets drops the affinities of +the dead threads of the region (`dropMA`). The spec's `McState` is a ghost beside `σ`, and `SchedRelA.affT` ties its +`tcbAffinity` entries to the live threads, so the post-state record holds at a *grown* view. `McGrowA m m'` is the +relation between the views the dispatch composes across kernel entries: + +* the current core and the idle threads and SCs of every core are kept; +* a well-formed view stays well-formed (any core count). + +It is reflexive and transitive and says nothing about `Z.T`, so it composes across entry chains. The affinities of the +live threads are the record's business (`SchedRelA` at `m'`), not this relation's. + +Named premises: none. New definitions and theorems only. The Retype lemmas are in `P3/McGrowUtA`. +-/ +import Fl4SpecA64.Ext.MultiCore + + +namespace Fl4ProofsA64.P3 +open Fl4SpecA64 + +noncomputable section + +/-- **The multi-core view grows** (module docstring). -/ +structure McGrowA (m m' : McState) : Prop where + core : m'.curCore = m.curCore + idle : m'.idleThreadOf = m.idleThreadOf + idleSc : m'.idleScOf = m.idleScOf + wf : ∀ n, m.WF n → m'.WF n + +theorem McGrowA.refl (m : McState) : McGrowA m m := ⟨rfl, rfl, rfl, fun _ h => h⟩ + +theorem McGrowA.trans {m1 m2 m3 : McState} (h1 : McGrowA m1 m2) (h2 : McGrowA m2 m3) : McGrowA m1 m3 := + ⟨h2.core.trans h1.core, h2.idle.trans h1.idle, h2.idleSc.trans h1.idleSc, fun n h => h2.wf n (h1.wf n h)⟩ + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/McGrowUtA.lean b/proofs/Fl4ProofsA64/P3/McGrowUtA.lean new file mode 100644 index 000000000..e23b2da12 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/McGrowUtA.lean @@ -0,0 +1,39 @@ +/- +P3 (aarch64, A64-P3 Stage 4, R1): **Retype's views grow** (`McGrowA`): the TCB a creation adds (`utRtMA`) and the dead +threads a reset forgets (`dropMA`). + +Named premises: none. New theorems only. +-/ +import Fl4ProofsA64.P3.McGrowA +import Fl4ProofsA64.P3.UtDropA +import Fl4ProofsA64.P3.UtRtSchedA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open Fl4SpecA64 Classical + +noncomputable section + +/-- A TCB created by Retype joins the view at affinity `0`. -/ +theorem utRtMA_growA (m : McState) (Tn : Set U64) : McGrowA m (utRtMA m Tn) := by + refine ⟨rfl, rfl, rfl, fun n h => ⟨h.curCore_lt, h.idleThread_inj, h.idleSc_inj, fun t c hc => ?_⟩⟩ + change (if ∃ x ∈ Tn, specPtr x = t then some 0 else m.tcbAffinity t) = some c at hc + split_ifs at hc with h0 + · have : 0 = c := Option.some.inj hc + subst this + exact lt_of_le_of_lt (Nat.zero_le _) h.curCore_lt + · exact h.affinity_lt t c hc + +/-- The reset forgets the affinities of the dropped threads. -/ +theorem dropMA_growA (D : Set ObjRef) (m : McState) : McGrowA m (dropMA D m) := by + refine ⟨rfl, rfl, rfl, fun n h => ⟨h.curCore_lt, h.idleThread_inj, h.idleSc_inj, fun t c hc => ?_⟩⟩ + change (if t ∈ D then none else m.tcbAffinity t) = some c at hc + by_cases h0 : t ∈ D + · simp [h0] at hc + · simp [h0] at hc + exact h.affinity_lt t c hc + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/MoveA.lean b/proofs/Fl4ProofsA64/P3/MoveA.lean index a90270049..4375c7a97 100644 --- a/proofs/Fl4ProofsA64/P3/MoveA.lean +++ b/proofs/Fl4ProofsA64/P3/MoveA.lean @@ -220,10 +220,10 @@ theorem capMove_memA {σ σ1 σ2 : State Unit} {a : Cap} {src dst : CslotPtr} theorem SpecSlotA.ofSetCnA {σ : State Unit} {p : ObjRef} {r : Nat} {cs : CnodeContents} (idx : List Bool) (a : Cap) (hk : σ.kheap p = some (.cnode r cs)) : SpecSlotA σ (setCnA σ p r cs idx a) := - SpecSlotA.setCn hk rfl ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + SpecSlotA.setCn hk rfl (SpecGlobA.ofKey rfl) theorem SpecSlotA.fin (σ : State Unit) (src dst : CslotPtr) : SpecSlotA σ (moveFinA σ src dst) := - ⟨⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, fun _ => Or.inl rfl⟩ + ⟨SpecGlobA.ofKey rfl, fun _ => Or.inl rfl⟩ /-! ## Two slots updated -/ diff --git a/proofs/Fl4ProofsA64/P3/ScCfgPrepA.lean b/proofs/Fl4ProofsA64/P3/ScCfgPrepA.lean index d74b8e05c..8ed3237d1 100644 --- a/proofs/Fl4ProofsA64/P3/ScCfgPrepA.lean +++ b/proofs/Fl4ProofsA64/P3/ScCfgPrepA.lean @@ -33,7 +33,7 @@ theorem cfgPrepFrameA {Z : XSetsA} {m : McState} {s s' : S} {σ : State Unit} (h : σ'.kheap = (updKSc σ (scNameA m sc) (.schedContext y n)).kheap) (w : WritesIn st s s' (MWrA (st := st) Z m σ s)) : MFrA (st := st) Z m s s' σ σ' := by - refine ⟨w, SKeepA.of_obj ?_, SSzA.of_upd hk h⟩ + refine MFrA.ofParts w (SKeepA.of_obj ?_) (SSzA.of_upd hk h) intro q o hq ho have ne : q ≠ scNameA m sc := by intro e diff --git a/proofs/Fl4ProofsA64/P3/ScConsumeMsgA.lean b/proofs/Fl4ProofsA64/P3/ScConsumeMsgA.lean index 5460438ce..393c16ac9 100644 --- a/proofs/Fl4ProofsA64/P3/ScConsumeMsgA.lean +++ b/proofs/Fl4ProofsA64/P3/ScConsumeMsgA.lean @@ -143,7 +143,7 @@ theorem sc_consumed_msg_frameWithA {Z : XSetsA} {m : McState} {κ : U64 → U64} rw [show σ1.kheap = _ from updKSc_kheap _ _ _, Function.update_of_ne hne] exact hq have F : MFrA (st := st) Z m s s1 σ σ1 := - ⟨hw.mono fun _ h => mwr_scObj hc hks h, SKeepA.of_obj hkeep, SSzA.of_upd hks (updKSc_kheap _ _ _)⟩ + MFrA.ofParts (hw.mono fun _ h => mwr_scObj hc hks h) (SKeepA.of_obj hkeep) (SSzA.of_upd hks (updKSc_kheap _ _ _)) have hi : returnConsumedWith (Z := Unit) cap toUs (scNameA m sc) σ = ({(wordsFromTime time.bv, σ1)}, False) := by unfold returnConsumedWith diff --git a/proofs/Fl4ProofsA64/P3/ScDomKeepA.lean b/proofs/Fl4ProofsA64/P3/ScDomKeepA.lean index 76d758f4e..c6fe05b78 100644 --- a/proofs/Fl4ProofsA64/P3/ScDomKeepA.lean +++ b/proofs/Fl4ProofsA64/P3/ScDomKeepA.lean @@ -19,7 +19,7 @@ noncomputable section instance (eop : DetExtMonad Unit) : QInst (doExtendedOp (Z := Unit) eop) := ⟨by unfold doExtendedOp - exact PresR.bind PresR.get fun _ => PresR.bind (PresR.selectF _) fun _ => QPresA.modify_fix _ (fun _ => rfl) fun _ => ⟨rfl, rfl, rfl, rfl⟩⟩ + exact PresR.bind PresR.get fun _ => PresR.bind (PresR.selectF _) fun _ => QPresA.modify_fix _ (fun _ => rfl) fun _ => DomKeepA.ofKey rfl⟩ instance : QInst (fl4ChooseThread (Z := Unit)) := ⟨by unfold fl4ChooseThread; qpres⟩ instance (t : ObjRef) : QInst (fl4SwitchToThread (Z := Unit) t) := ⟨by unfold fl4SwitchToThread; qpres⟩ diff --git a/proofs/Fl4ProofsA64/P3/ScDomainA.lean b/proofs/Fl4ProofsA64/P3/ScDomainA.lean index a8574dae5..16f76d16c 100644 --- a/proofs/Fl4ProofsA64/P3/ScDomainA.lean +++ b/proofs/Fl4ProofsA64/P3/ScDomainA.lean @@ -353,7 +353,7 @@ theorem writeDomainGlobalA {Z : XSetsA} {m : McState} {κ : U64 → U64} change addr.val = (scCoreA c).val at eq rcases outside with h | h <;> omega)).trans (hold.scCore c hc) obtain ⟨states, mcp, links⟩ := yieldQueueFrameDA (σ' := τ) H.sched H.states H.mcp H.links rfl W - exact ⟨⟨⟨R, RdA.of_eq H.sched.rd rfl rfl rfl⟩, states, mcp, links⟩, ⟨W, SKeepA.of_kheap rfl, SSzA.of_kheap rfl⟩⟩ + exact ⟨⟨⟨R, RdA.of_eq H.sched.rd rfl rfl rfl⟩, states, mcp, links⟩, MFrDA.ofParts W (SKeepA.of_kheap rfl) (SSzA.of_kheap rfl)⟩ diff --git a/proofs/Fl4ProofsA64/P3/ScEntryBudgetA.lean b/proofs/Fl4ProofsA64/P3/ScEntryBudgetA.lean index 4fa992cef..1e85f1505 100644 --- a/proofs/Fl4ProofsA64/P3/ScEntryBudgetA.lean +++ b/proofs/Fl4ProofsA64/P3/ScEntryBudgetA.lean @@ -130,7 +130,7 @@ theorem entryRescheduleFrA {Z : XSetsA} {m : McState} {κ : U64 → U64} {s : S} (fun _ h => Or.inr (h ▸ H'.sched.toSchedSRN.repr_swr)) obtain ⟨E, M, Y⟩ := yieldQueueFrameA H'.sched H'.states H'.mcp H'.links (show τ.kheap = v.kheap from rfl) w refine ⟨τ, Q', ?_, ⟨out, E, M, Y⟩, hkv, hrv, fix.idleThread, hm, fix.curTime, fix.consumedTime, ha, - f.trans (Z' := { Z with Q := Q' }) ⟨w, SKeepA.of_kheap rfl, SSzA.of_kheap rfl⟩ rfl rfl⟩ + f.trans (Z' := { Z with Q := Q' }) (MFrA.ofParts w (SKeepA.of_kheap rfl) (SSzA.of_kheap rfl)) rfl rfl⟩ rw [nd_bind_oneSc he] rfl diff --git a/proofs/Fl4ProofsA64/P3/ScFrameA.lean b/proofs/Fl4ProofsA64/P3/ScFrameA.lean index 1316dbddb..4306754b2 100644 --- a/proofs/Fl4ProofsA64/P3/ScFrameA.lean +++ b/proofs/Fl4ProofsA64/P3/ScFrameA.lean @@ -82,8 +82,7 @@ theorem update_consumed_frameA {Z : XSetsA} {m : Fl4SpecA64.McState} {κ : U64 SchedSRA st Z m κ r.2 σ' ∧ MFrA (st := st) Z m s r.2 σ σ' ∧ σ' = { σ with kheap := σ'.kheap } ⦄ := by refine WP.spec_mono (update_consumed_refinesA H a hc hmax htu) ?_ rintro r ⟨x, n, v, hk, hsp, -, hw, H'⟩ - refine ⟨_, hsp, H', ⟨hw.mono fun b hb => mwr_scObj hc hk hb, SKeepA.of_obj fun q o hq ho => ?_, - SSzA.of_upd hk rfl⟩, rfl⟩ + refine ⟨_, hsp, H', MFrA.ofParts (hw.mono fun b hb => mwr_scObj hc hk hb) (SKeepA.of_obj fun q o hq ho => ?_) (SSzA.of_upd hk rfl), rfl⟩ have hne : q ≠ scNameA m sc := fun e => by rw [e, hk] at hq; cases hq; exact ho x n rfl simp [updKSc, hne, hq] diff --git a/proofs/Fl4ProofsA64/P3/ScSWrA.lean b/proofs/Fl4ProofsA64/P3/ScSWrA.lean index 3ebbd25ef..41d14ca96 100644 --- a/proofs/Fl4ProofsA64/P3/ScSWrA.lean +++ b/proofs/Fl4ProofsA64/P3/ScSWrA.lean @@ -164,9 +164,16 @@ structure MFrA (Z : XSetsA) (m : Fl4SpecA64.McState) (s s' : S) (σ σ' : Fl4Spe keep : SKeepA σ σ' sz : SSzA σ σ' +/-- The one constructor of `MFrA` to use at call sites (`ofParts wr keep sz`): a new field of the bundle gets a default +here, so the literal sites do not change (record-extension convention, `AGENTS.md`, "Proof records"). -/ +theorem MFrA.ofParts {Z : XSetsA} {m : Fl4SpecA64.McState} {s s' : S} {σ σ' : Fl4SpecA64.State Unit} + (wr : WritesIn st s s' (MWrA (st := st) Z m σ s)) (keep : SKeepA σ σ') (sz : SSzA σ σ') : + MFrA (st := st) Z m s s' σ σ' := + ⟨wr, keep, sz⟩ + theorem MFrA.refl (Z : XSetsA) (m : Fl4SpecA64.McState) (s : S) (σ : Fl4SpecA64.State Unit) : MFrA (st := st) Z m s s σ σ := - ⟨WritesIn.refl _ _, SKeepA.refl σ, SSzA.refl σ⟩ + MFrA.ofParts (WritesIn.refl _ _) (SKeepA.refl σ) (SSzA.refl σ) theorem MFrA.trans {Z Z' : XSetsA} {m : Fl4SpecA64.McState} {s s1 s2 : S} {σ σ1 σ2 : Fl4SpecA64.State Unit} (F1 : MFrA (st := st) Z m s s1 σ σ1) (F2 : MFrA (st := st) Z' m s1 s2 σ1 σ2) (hC : Z'.C = Z.C) @@ -177,7 +184,7 @@ theorem MFrA.trans {Z Z' : XSetsA} {m : Fl4SpecA64.McState} {s s1 s2 : S} {σ σ /-- A scheduler step (heap kept, writing scheduler words). -/ theorem MFrA.of_sw {Z : XSetsA} {m : Fl4SpecA64.McState} {s s' : S} {σ σ' : Fl4SpecA64.State Unit} (hk : σ'.kheap = σ.kheap) (hw : WritesIn st s s' (SWrA (st := st) Z s)) : MFrA (st := st) Z m s s' σ σ' := - ⟨hw.mono fun _ h => Or.inr h, SKeepA.of_kheap hk, SSzA.of_kheap hk⟩ + MFrA.ofParts (hw.mono fun _ h => Or.inr h) (SKeepA.of_kheap hk) (SSzA.of_kheap hk) /-- **The write set of a scheduler step that advances the domain schedule** (`MWrA` and the words `DomW`). -/ def MWrDA (Z : XSetsA) (m : Fl4SpecA64.McState) (σ : Fl4SpecA64.State Unit) (s : S) (b : U64) : Prop := @@ -189,9 +196,15 @@ structure MFrDA (Z : XSetsA) (m : Fl4SpecA64.McState) (s s' : S) (σ σ' : Fl4Sp keep : SKeepA σ σ' sz : SSzA σ σ' +/-- The one constructor of `MFrDA` to use at call sites (see `MFrA.ofParts`). -/ +theorem MFrDA.ofParts {Z : XSetsA} {m : Fl4SpecA64.McState} {s s' : S} {σ σ' : Fl4SpecA64.State Unit} + (wr : WritesIn st s s' (MWrDA (st := st) Z m σ s)) (keep : SKeepA σ σ') (sz : SSzA σ σ') : + MFrDA (st := st) Z m s s' σ σ' := + ⟨wr, keep, sz⟩ + theorem MFrA.toD {Z : XSetsA} {m : Fl4SpecA64.McState} {s s' : S} {σ σ' : Fl4SpecA64.State Unit} (F : MFrA (st := st) Z m s s' σ σ') : MFrDA (st := st) Z m s s' σ σ' := - ⟨F.wr.mono fun _ h => Or.inl h, F.keep, F.sz⟩ + MFrDA.ofParts (F.wr.mono fun _ h => Or.inl h) F.keep F.sz theorem MFrDA.refl (Z : XSetsA) (m : Fl4SpecA64.McState) (s : S) (σ : Fl4SpecA64.State Unit) : MFrDA (st := st) Z m s s σ σ := diff --git a/proofs/Fl4ProofsA64/P3/ScSchedChargeA.lean b/proofs/Fl4ProofsA64/P3/ScSchedChargeA.lean index 48810f4b6..62220772e 100644 --- a/proofs/Fl4ProofsA64/P3/ScSchedChargeA.lean +++ b/proofs/Fl4ProofsA64/P3/ScSchedChargeA.lean @@ -110,7 +110,7 @@ theorem commit_time_quietA {Z : XSetsA} {m : McState} {κ : U64 → U64} rintro s' ⟨hs, w⟩ let τ := {σ with consumedTime := 0} obtain ⟨states, mcp, links⟩ := yieldQueueFrameA (σ' := τ) H.sched H.states H.mcp H.links rfl w - exact ⟨τ, abs, ⟨hs, states, mcp, links⟩, ⟨w, SKeepA.of_kheap rfl, SSzA.of_kheap rfl⟩⟩ + exact ⟨τ, abs, ⟨hs, states, mcp, links⟩, MFrA.ofParts w (SKeepA.of_kheap rfl) (SSzA.of_kheap rfl)⟩ /-- The incoming SC's constant-bandwidth refresh preserves the owner's yield link and any unrelated outstanding yield. -/ diff --git a/proofs/Fl4ProofsA64/P3/ScScheduleA.lean b/proofs/Fl4ProofsA64/P3/ScScheduleA.lean index 638dc8f3b..43c3dee5a 100644 --- a/proofs/Fl4ProofsA64/P3/ScScheduleA.lean +++ b/proofs/Fl4ProofsA64/P3/ScScheduleA.lean @@ -198,7 +198,7 @@ private theorem schedulerPushA {Z : XSetsA} {m : McState} {κ : U64 → U64} · rw [← tau] exact ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ · rw [← tau] - exact ⟨rfl, rfl, rfl, rfl⟩ + exact DomKeepA.ofKey rfl · simp only [↓reduceIte] refine WP.spec_mono (append_refines_localA H.sched ht hon (fun _ => linked) runnable) ?_ rintro s' ⟨τ, abs, heap, queue, action, fix, hs, w⟩ @@ -210,7 +210,7 @@ private theorem schedulerPushA {Z : XSetsA} {m : McState} {κ : U64 → U64} rw [eq] at abs have tau := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst abs))).2 rw [← tau] - exact ⟨rfl, rfl, rfl, rfl⟩ + exact DomKeepA.ofKey rfl private def candidateThenChooseA (limit : Nat) (t : ObjRef) (tail : Bool) : SMonad Unit Unit := do @@ -382,7 +382,7 @@ private theorem candidate_refinesA {Z : XSetsA} {m : McState} {κ : U64 → U64} (inferInstance : SPresInst (tcbSchedAction (Z := Unit) (if tail then tcbSchedAppend else tcbSchedEnqueue) (specPtr t))).pres σ ((), σ1) (by rw [push]; exact Set.mem_singleton _) have S2 : SchedFrameA σ σ2 := PreO.trans S1 (SchedFrameA.of_eq rfl rfl rfl rfl rfl rfl rfl rfl) - have D2 : DomKeepA σ σ2 := D1.trans ⟨rfl, rfl, rfl, rfl⟩ + have D2 : DomKeepA σ σ2 := D1.trans (DomKeepA.ofKey rfl) have spec := schedule_choose_new_refinesA H2 P (domain Q1 s2 σ2 H2 frame S2 D2) (fun s3 σ3 H3 F3 S3 => roots Q1 s3 σ3 H3 (frame.transD F3 rfl rfl) (PreO.trans S2 S3)) refine WP.spec_mono spec ?_ @@ -390,7 +390,7 @@ private theorem candidate_refinesA {Z : XSetsA} {m : McState} {κ : U64 → U64} rw [frame.wr.2.1] at root refine ⟨τ, Q, writes, ?_, Or.inl root, rel, frame.transD frame' rfl rfl, fun N0 => nd' (NdOKA.keepF (st := st) (NdOKA.keepF (st := st) N0 D1 H.sched.toSchedSRN F1) - ⟨rfl, rfl, rfl, rfl⟩ H1.sched.toSchedSRN F2)⟩ + (DomKeepA.ofKey rfl) H1.sched.toSchedSRN F2)⟩ unfold candidateThenChooseA rw [nd_bind_oneSc push, nd_bind_oneSc (actionSetChooseA σ1)] exact abs diff --git a/proofs/Fl4ProofsA64/P3/ScScheduleTimerA.lean b/proofs/Fl4ProofsA64/P3/ScScheduleTimerA.lean index 26607e283..5c57f77e1 100644 --- a/proofs/Fl4ProofsA64/P3/ScScheduleTimerA.lean +++ b/proofs/Fl4ProofsA64/P3/ScScheduleTimerA.lean @@ -180,7 +180,7 @@ theorem set_next_interrupt_refinesA {Z : XSetsA} {m : McState} {κ : U64 → U64 have eq : {τ with reprogramTimer := repr} = τ := by simp only [repr, if_neg noRepr] exact eq ▸ out.1 · rw [hw] - exact ⟨out.2.wr, SKeepA.of_kheap rfl, SSzA.of_kheap rfl⟩ + exact MFrA.ofParts out.2.wr (SKeepA.of_kheap rfl) (SSzA.of_kheap rfl) /-- [J] The local timer-queue minimum and the installed live SC at the point where the scheduler may program the timer. -/ diff --git a/proofs/Fl4ProofsA64/P3/ScTailA.lean b/proofs/Fl4ProofsA64/P3/ScTailA.lean index c61cdbfc7..29577a557 100644 --- a/proofs/Fl4ProofsA64/P3/ScTailA.lean +++ b/proofs/Fl4ProofsA64/P3/ScTailA.lean @@ -147,7 +147,7 @@ theorem UnbFrA.switch_pre {Z : XSetsA} {m : Fl4SpecA64.McState} {κ : U64 → U6 /-- (gen 10) **The sporadic unblock's frame as the bundle `MFrA`** (`REPROGRAM` is a block word). -/ theorem UnbFrA.mfr {Z : XSetsA} {m : Fl4SpecA64.McState} {κ : U64 → U64} {s s' : S} {σ σ' : Fl4SpecA64.State Unit} (H : SchedSRN st Z m κ s σ) (F : UnbFrA (st := st) Z m s s' σ σ') : MFrA (st := st) Z m s s' σ σ' := - ⟨F.wr.mono fun _ hb => hb.elim Or.inl fun e => Or.inr (by rw [e]; exact H.repr_swr), SKeepA.of_obj F.obj, F.sz⟩ + MFrA.ofParts (F.wr.mono fun _ hb => hb.elim Or.inl fun e => Or.inr (by rw [e]; exact H.repr_swr)) (SKeepA.of_obj F.obj) F.sz /-- **The local restart tail** (`SchedOpsA.restartTail` / `SchedOpsEA.restartTail`, local case; module docstring): `unblock_sporadic t` then `possible_switch_to t` refines the spec's sporadic check then `possible_switch_to t`; diff --git a/proofs/Fl4ProofsA64/P3/ScTimeA.lean b/proofs/Fl4ProofsA64/P3/ScTimeA.lean index 5c102965c..a437dcfc0 100644 --- a/proofs/Fl4ProofsA64/P3/ScTimeA.lean +++ b/proofs/Fl4ProofsA64/P3/ScTimeA.lean @@ -246,7 +246,7 @@ theorem update_timestamp_refinesA {Z : XSetsA} {m : McState} {κ : U64 → U64} H.actOn (H.inv.of_kheap rfl rfl) hcore H.rest.rq H.rest.rqDom H.rest.rel H.run (fun c hc => (keepSC _ (H.scCoreFoot hc).1 (H.scCoreFoot hc).2).trans (H.scCore c hc)) have M : MFrA (st := st) Z m s s2 σ τ := by - refine ⟨w.mono (fun b h => Or.inr (Or.inl ?_)), SKeepA.of_kheap rfl, SSzA.of_kheap rfl⟩ + refine MFrA.ofParts (w.mono (fun b h => Or.inr (Or.inl ?_))) (SKeepA.of_kheap rfl) (SSzA.of_kheap rfl) rcases h with rfl | rfl · exact H.node_sks H.sch.cpuCs (by rw [oT]; decide) · exact H.node_sks H.sch.cpuCs (by rw [oC]; decide) diff --git a/proofs/Fl4ProofsA64/P3/Stage3AfterPreemptA.lean b/proofs/Fl4ProofsA64/P3/Stage3AfterPreemptA.lean index 93e153e8e..9a4f4a73f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3AfterPreemptA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3AfterPreemptA.lean @@ -85,9 +85,9 @@ variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : /-- **`SendPA` gives `kentryChargeIrqSendA`'s `hSendO`.** -/ theorem hSendO_of_hSendP {Clock : A → MachineState → Prop} (noSwitch : ∀ u, σ.schedulerAction ≠ .switchThread u) - (h : ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + (h : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → SendPA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s1 a1 σ1) : - ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → CurInvA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → @@ -96,12 +96,12 @@ theorem hSendO_of_hSendP {Clock : A → MachineState → Prop} sched.check_budget st ar s1 a1 ⦃ r => ∃ τ, fl4CheckBudget (Z := Unit) σ1 = ({(r.1, τ)}, False) ∧ JStage3QA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes nA m r.2.1 r.2.2 τ ⦄ := by - intro s1 a1 σ1 e1 J1 En1 CI1 Act1 Cl1 hex hns hR + intro s1 a1 σ1 hu e1 J1 En1 CI1 Act1 Cl1 hex hns hR have eσ1 : σ1 = fl4TimestampState (rawNextA σ.machineState) { σ with machineState := rawStateA σ.machineState } := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst ((fl4UpdateTimestamp_eqA σ).symm.trans e1)))).2.symm have sw1 : ∀ u, σ1.schedulerAction ≠ .switchThread u := by rw [eσ1]; exact noSwitch - exact h s1 a1 σ1 e1 J1 ⟨En1.cA, fun r => ⟨(En1.run r).1, (En1.run r).2.1⟩⟩ sw1 (J1.sinv.ctQ (J1.resumeA En1.act)) + exact h s1 a1 σ1 hu e1 J1 ⟨En1.cA, fun r => ⟨(En1.run r).1, (En1.run r).2.1⟩⟩ sw1 (J1.sinv.ctQ (J1.resumeA En1.act)) CI1 Act1 Cl1 hex hns hR set_option maxHeartbeats 4000000 in @@ -138,8 +138,7 @@ theorem afterPreemptA {Cs : Set U64} {Clock : A → MachineState → Prop} {poll have rec_ : ∀ s' a' τ, JStage3QA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes nA m s' a' τ → BodyOKA τ m → A64RelS3 st AR ar nA fl4A64Platform.numNodes Cs s' a' τ m := by rintro s' a' τ ⟨Q, Rl, co, cs, J1⟩ B - exact ⟨{ Z with Q := Q, R := Rl, curOf := co, curScOf := cs }, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, - stack, κ, eCs, J1, B⟩ + exact A64RelS3.ofJ J1 B eCs have htZ : L.curW s ∈ Z.T := J.sr.curT have hon : L.mem s (affA (L.curW s)) = L.cpu s := J.sr.curOn have ct : σ.curThread = specPtr (L.curW s) := J.sr.sch.curThread diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmAssignA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmAssignA.lean index c3f6a8d45..c582ee093 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmAssignA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmAssignA.lean @@ -412,7 +412,7 @@ theorem JStage3A.asidAssignA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea | stage1 => exact .pml4 .. | stage2 => exact .ept .. | high => exact .hv .. - have main := JStage3A.of_capVsFrameGA (hS := fun _ h => h) (hT2 := fun _ h => h) (hpt := fun _ _ _ h => by cases k <;> cases h) (J := J1) (S1' := Z.S1) (T2' := Z.T2) (Zl' := Z.Lv) (Sh2' := Z.Sh2) + have main := JStage3A.of_capVsFrameGA (hS := fun _ h => h) (hT2 := fun _ _ _ _ _ _ _ h => h) (hpt := fun _ _ _ h => by cases k <;> cases h) (J := J1) (S1' := Z.S1) (T2' := Z.T2) (Zl' := Z.Lv) (Sh2' := Z.Sh2) (Tb' := Z.S1 ∪ T) (Lv' := Lv') (Q := fun s' a' σ' hw => s' = L.wr s2 (peAF p i) (root ||| assignTagWordA k) ∧ a' = a ∧ (.ok ([] : List Fl4SpecA64.Data), σ') ∈ ((fl4ArchPerformInvocation (Z := Unit) diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapS2A.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapS2A.lean new file mode 100644 index 000000000..dbc3e0148 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapS2A.lean @@ -0,0 +1,466 @@ +/- +P3 (AArch64, Stage 4 line vsx-A): **`JStage3A` across a successful Stage-2 `ARMPageMap`** (`JStage3A.frameMapS2A`, at +`vspace::decode_page_map` with an `Ept` extra cap, i.e. `ept::map_frame`): the Stage-2 sibling of +`Stage3ArmFrMapHiA`. It inverts the code (`ept_map_invA`), takes the spec decode from `s2_map_frame_jA` / `s2At_memA`, +the lookup from `ept_lookup_slot_mapA`, the leaf descriptor from `s2_leaf_relA`, P1's `ept.map_frame.exactEffect` and +`frameMapExtCoreA` (cap write + one descriptor write into a Stage-2 table or root page), and J9 across the valid write +from `UnmPtSpecA.ofS2WrA` (words of unmapped caps are zero at the final state, P1's `unmZ`). The rights-denied branch +(`vm = kernel-only`, descriptor `0`) leaves the cap an unmapped plain frame. + +Named premises: the arm's decode-site facts (`hrt`, `hres`, `hCn`); [P] `P0.ArchTotal`, `ArchPlat`, `S2IpaE`, +`ArchKeepsA`; `fin` (final-state facts owed at T3). The mapped cap's slot is a CNode slot (`hCn`, as for CNode Copy): +it is not a TCB's IPC-buffer slot, which keeps `BufNativeA`. No new premise kind. New module. +-/ +import Fl4ProofsA64.P3.Stage3BodyKeepA +import Fl4ProofsA64.P3.Stage3MapExtCoreA +import Fl4ProofsA64.P3.Stage3MapS2UnmA +import Fl4ProofsA64.P3.CnSlotSbA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + + +private theorem s2IpaLimit_lt48A : s2IpaLimit.toNat < 2 ^ 48 := by + unfold s2IpaLimit s2IpaBitsOf + split_ifs <;> decide + +private theorem mem_when_negD {P : Prop} [Decidable P] {e : SyscallError} {s s' : State Unit} {u : Unit} + (h : (Except.ok u, s') ∈ ((NonDetE.whenE P (NonDetE.throwError e)).run s).1) : ¬ P := by + unfold NonDetE.whenE at h + split at h + · have := Set.mem_singleton_iff.1 h + simp at this + · assumption + +/-- **What a successful `decodeS2PageMapAt` checked**: an unmapped frame's last byte is inside the IPA space without +wrapping, a mapped frame's saved address is the one asked for. -/ +private theorem s2At_boundA {cte : CslotPtr} {p : Fl4SpecA64.ObjRef} {R : CapRights} {sz : VMPageSize} {dev : Bool} + {mapped : Option (Asid × Fl4SpecA64.VSpaceRef)} {r : Fl4SpecA64.ObjRef} {asid : Asid} {va rm attr : Data} + {σ σ' : State Unit} {iv : ExtVSpaceInvocation} + (h : (Except.ok iv, σ') ∈ ((decodeS2PageMapAt (Z := Unit) cte p R sz dev mapped r asid va rm attr).run σ).1) : + (mapped = none → ¬ (va + mask (pageBitsForSize sz) > s2IpaLimit ∨ va + mask (pageBitsForSize sz) < va)) ∧ + (∀ a v, mapped = some (a, v) → v = va) := by + unfold decodeS2PageMapAt at h + obtain ⟨u0, s0, h0, g⟩ := mem_bind_invD h + obtain rfl := checkAlign_keepA h0 + cases mapped with + | some w => + obtain ⟨a', v'⟩ := w + dsimp only at g + obtain ⟨u1, s1, h1, g1⟩ := mem_bind_invD g + obtain rfl := mem_when_invD h1 + obtain ⟨u2, s2, h2, g2⟩ := mem_bind_invD g1 + have hn := mem_when_negD h2 + exact ⟨(fun h => by cases h), (fun a v e => by cases e; exact not_not.1 hn)⟩ + | none => + dsimp only at g + obtain ⟨u1, s1, h1, g1⟩ := mem_bind_invD g + exact ⟨(fun _ => mem_when_negD h1), (fun a v e => by cases e)⟩ + +private theorem s2SlotOkA {Pp Tb X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {σ : State Unit} + (E : ExtVsRelA Pp Tb X Y T2 Sh2 mem σ) {x : U64} {sl : ExtSlot} {sh : Nat} + (h : SlotRelE (G2E T2 Sh2) (TopS2E X) x sl sh) : ExtSlotOkX σ sl := by + rcases h with ⟨t, i, ⟨ht, -⟩, hi, rfl, rfl⟩ | ⟨r, j, hr, hj, rfl, rfl, -⟩ + · obtain ⟨pt, hk, hty, -⟩ := E.s2pt t ht + cases pt with + | vsRootPT _ => cases hty + | normalPT f => + obtain ⟨hal, hb, -⟩ := slot_geomA .normalPtT (Nat.mod_eq_zero_of_dvd (E.tal t ht)) hi + exact ⟨hal, f, by rw [hb]; exact hk⟩ + · obtain ⟨es, hk, -⟩ := E.s2root r hr + exact ⟨.stage2Root es, extObjAt_someX.2 hk⟩ + +set_option maxHeartbeats 8000000 in +/-- **`JStage3A` across a successful Stage-2 `ARMPageMap`** (module docstring). -/ +theorem JStage3A.frameMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {ar : machine.Arch A} {s : S} {a : A} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + (K : ArchKeepsA ar AR) (hA : Fl4ProofsA64.P0.ArchTotal ar) (hPl : ArchPlat ar) (hIpa : S2IpaE ar a) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) + (hK : Aligned (L.ksb s)) (hT : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s)) + (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) + (hCn : ∃ pc, cte.1 = specPtr pc ∧ Z.th pc = some (.cnode cte.2.length)) + (fp rt asid va : U64) (sz : capability.FrameSize) + (dev mp e : Bool) (hcap : capAtA (L.mem s) (cslotAddrA cte) = .Frame fp sz rt dev mp e asid va) + (FP : FrPlA sz fp mp asid) (hemp : e = mp) (p1 asid1 va1 : U64) (mp1 : Bool) (h16 : asid1.val < 2 ^ 16) + {x0 : U64} (hx0 : x0 ∈ OS) (hx0c : capA st s x0 = .Ept p1 0#u64 mp1 asid1 va1) + (hrt : ept.root st s (.Ept p1 0#u64 mp1 asid1 va1) 1#u64 = ok (core.result.Result.Ok (p1, asid1))) + (vaddr rightsMask vm attr : U64) + (hvmRange : vm = capability.VM_KERNEL_ONLY ∨ vm = capability.VM_READ_ONLY ∨ vm = capability.VM_READ_WRITE) + (hvmEq : vmRightsOfA vm = maskVmRights (vmRightsOfA rt) (dataToRights rightsMask.bv)) + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageMapAt (Z := Unit) cte (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev + (mapDataA mp asid va) (specPtr p1) (asidOfA asid1) vaddr.bv rightsMask.bv attr.bv)).run σ) + {dc : capability.Cap} {ex : Aeneas.Std.Array obj.Slot 3#usize} + (d : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s dc ex) + {s3 : S} {a3 : A} + (hres : ept.map_frame st ar s a p1 asid1 vaddr vm attr fp sz rt dev asid va (cslotAddrA cte) = + ok (core.result.Result.Ok (), s3, a3)) + (fin : ∀ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit), + σ.kheap σ.curThread = some (.tcb x) → (.ok (.extVSpace iv), σ) ∈ D.1 → + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 → + ∃ Ac' : Set U64, SysL st H Z.Cs OS ia ie s3 ∧ SymL st H Z.Cs s3 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s3 ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s3 ∧ + J7A st (J7R2A st ar hPl.ipa) Z H OS s3 σ3 m) : + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) (Ac' : Set U64), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR Z H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s3 a3 σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + have E0 := J.toJEntA + have hos : cslotAddrA cte ∈ OS := RS.sub _ (hab.isSlot J.j.1.place) + have hTr : TreeA st OS Z.G.chains Z.G.par s := J.j.1.cdt.tree.grow J.j5.2.1 (fun x hx hn => J.j5.2.2 x hx hn) + have hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null := J.j5.2.2 + have hcap0 : capA st s (cslotAddrA cte) = .Frame fp sz rt dev mp e asid va := by rw [← capAtA_eq]; exact hcap + obtain ⟨c0', -, hrel0⟩ := StateRelA.getAbsA E0.j.1.st hab + rw [hcap] at hrel0 + obtain ⟨⟨hr1, hr3, ⟨has16, hmz0, hmz1, _⟩, hov⟩, -⟩ := hrel0 + have hcanP : CapRt.Canonical fp := by + have := CapRt.decodeF_encWf (L.mem s (cslotAddrA cte)).bv (L.mem s (wa (cslotAddrA cte) 8#u64)).bv + change CapRt.EncWf (capAtA (L.mem s) (cslotAddrA cte)) at this + rw [hcap] at this + cases e <;> exact this.1 + -- the code + obtain ⟨shift, ipaB, lu, cr, pa, ew, s1, s2', hsh, hib, hlu, hlsh, hcr, hpa, hew, hst1, hsc1, hinst⟩ := + ept_map_invA hres + have h16_of_mp : mp = true → va.val < 2 ^ 48 := by + intro hmp + have he1 : e = true := hemp.trans hmp + have := CapRt.decodeF_encWf (L.mem s (cslotAddrA cte)).bv (L.mem s (wa (cslotAddrA cte) 8#u64)).bv + change CapRt.EncWf (capAtA (L.mem s) (cslotAddrA cte)) at this + rw [hcap, he1] at this + exact this.2.2.2 + have hshE : sz.bits = ok (psA sz) := by cases sz <;> rfl + rw [hshE] at hsh + obtain rfl := ok_inj_ff hsh + rw [rights_readableA] at hcr + have ecr := ok_inj_ff hcr + have epa : core.num.U64.wrapping_sub fp layout.PPTR_BASE = pa := ok_inj_ff hpa + subst epa + have hX : ∀ r ∈ Z.X, ∃ es, σ.kheap (specPtr r) = some (.archObj (.ext (.stage2Root es))) := + fun r hr => let ⟨es, hk, _⟩ := E0.j.1.ext.s2root r hr; ⟨es, hk⟩ + have hr0 := ept_rootA E0.j.1.vs hX p1 asid1 va1 1#u64 mp1 (lt_of_lt_of_eq h16 (by norm_num)) + rw [hrt] at hr0 + obtain ⟨-, hrX, ha1nz, hchk⟩ := (WP.spec_ok _).1 hr0 + have hactR := activeS2RootA_of_vspaceForAsid E0.j.1.vs hrX (vspaceForAsid_of_checkExtRootA (by decide) hchk) + obtain ⟨nIpa, hnIpa, hnvIpa⟩ := hIpa + obtain rfl : ipaB = nIpa := ok_inj_ff (hib.symm.trans hnIpa) + -- the spec decode + have h3 := s2_map_frame_jA K E0 RS hTO hEO hK hT ⟨ipaB, hnIpa, hnvIpa⟩ hTr hnul cte hab hos fp rt asid va sz dev mp e + hcap FP hemp p1 asid1 vaddr vm attr hrX hactR ha1nz h16 hvmRange hvmEq hD + rw [hres] at h3 + obtain ⟨inv, ⟨hmem, -⟩, -⟩ := (WP.spec_ok _).1 h3 + have hmem0 := hmem + rw [hD] at hmem + unfold NonDetE.liftME at hmem + obtain ⟨iv, s4, hm1, hm2⟩ := mem_bind_invD hmem + have einv : inv = .extVSpace iv := Except.ok.inj (Prod.mk.inj (Set.mem_singleton_iff.1 hm2)).1 + have hiv := s2At_memA hm1 + -- the lookup + have hc1 := ept_lookup_slot_mapA E0.j.1.ext hrX hactR hnvIpa vaddr + rw [hlu] at hc1 + obtain ⟨hlsh', hslR⟩ := (WP.spec_ok _).1 hc1 + have hsl : SlotRelE (G2E Z.T2 Z.Sh2) (TopS2E Z.X) lu.slot + (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).shift := + hslR.mono (fun _ _ g => g.1) (fun _ _ _ ht => ht.toTopS2E) + have hpsEq : (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).shift = pageBitsForSize (frameSizeOfA sz) := by + rw [← hlsh', hlsh, pbfs_eqA] + -- the descriptor, the new cap and the invocation, in one shape for both vm cases + have hipa48 : vaddr.val < 2 ^ 48 := by + have hb := s2At_boundA hm1 + cases mp + · have hn := hb.1 rfl + have h3 := s2IpaLimit_lt48A + have a1 := BitVec.le_def.1 (BitVec.not_lt.1 (fun h => hn (Or.inl h))) + have a2 := BitVec.le_def.1 (BitVec.not_lt.1 (fun h => hn (Or.inr h))) + show vaddr.bv.toNat < 2 ^ 48 + omega + · have hv : va.bv = vaddr.bv := hb.2 _ _ rfl + have : va = vaddr := UScalar.eq_of_val_eq (congrArg BitVec.toNat hv) + rw [← this]; exact h16_of_mp rfl + obtain ⟨newC, newSC, pte, hEnc, hca, hnn, hUA, hok, hbn, hsc1', hinvEq, hpte, hnotPt, hewcase⟩ : + ∃ (newC : capability.Cap) (newSC : Fl4SpecA64.ArchCap) (pte : PTE), CapRt.EncWf newC ∧ + CapRelA newC (.archObjectCap newSC) ∧ newC ≠ .Null ∧ UA newC (.Frame fp sz rt dev mp e asid va) ∧ + CapObjOkA Z newC ∧ + (∃ mp' e' a' v', newC = .Frame fp sz rt dev mp' e' a' v' ∧ + (e' = false ∨ ∀ t ∈ Z.T, sbWordA t ≠ cslotAddrA cte)) ∧ + obj.Slot.set_cap st (cslotAddrA cte) s1 newC = ok s2' ∧ + iv = .map newSC cte pte (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot ∧ + (DescRelE (G2E Z.T2 Z.Sh2) (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).shift ew pte ∧ + S2AttrE (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).shift ew pte) ∧ + (∀ ppn, pte ≠ .pageTablePTE ppn) ∧ (ew ≠ 0#u64 ∨ (ew = 0#u64 ∧ pte = .invalidPTE)) := by + rcases hvmRange with rfl | hvm23 + · have hew0 : ew = 0#u64 := ok_inj_ff (hew.symm.trans (make_s2_leaf_zeroA _ _ _ _ _ + (by unfold capability.VM_KERNEL_ONLY capability.VM_READ_WRITE; decide) + (by unfold capability.VM_KERNEL_ONLY capability.VM_READ_ONLY; decide))) + subst hew0 + have hvmEmpty : maskVmRights (vmRightsOfA rt) (dataToRights rightsMask.bv) = ∅ := by + rw [← hvmEq]; unfold capability.VM_KERNEL_ONLY vmRightsOfA; rfl + have hiv' := ((s2At_memA hm1).resolve_right (fun h => h.1 hvmEmpty)).2 + refine ⟨.Frame fp sz rt dev false false 0#u64 0#u64, + .frameCap (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev none, .invalidPTE, ?_, ?_, (by intro h; cases h), + UA.of_shapeA rfl (by simp [isUtA]), ?_, ⟨_, _, _, _, rfl, Or.inl rfl⟩, ?_, hiv', ⟨descRelE_zero _ _, trivial⟩, + (fun _ h => by cases h), Or.inr ⟨rfl, rfl⟩⟩ + · simp only [CapRt.EncWf]; exact ⟨hcanP, by omega, by decide, Or.inl (fun _ _ _ => by simp)⟩ + · exact ⟨⟨hr1, hr3, ⟨by decide, fun _ => rfl, by simp, by simp⟩, hov⟩, rfl⟩ + · exact ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), + fun _ _ _ h => (by cases h), fun h _ => (by cases h)⟩ + · simpa using hsc1 + · have hvmNE : maskVmRights (vmRightsOfA rt) (dataToRights rightsMask.bv) ≠ ∅ := by + rw [← hvmEq] + intro h + have hm : Rights.allowRead ∈ (∅ : Set Rights) := by + rw [← h] + rcases hvm23 with rfl | rfl <;> simp [vmRO_litA, vmRW_litA, vmRightsOfA, vmReadOnly, vmReadWrite] + simp at hm + have hiv' := ((s2At_memA hm1).resolve_left (fun h => hvmNE h.1)).2 + have hm := make_s2_leaf_valA (core.num.U64.wrapping_sub fp layout.PPTR_BASE) vm attr (psA sz) cr hvm23.symm + rw [hew] at hm + have hewv := (WP.spec_ok _).1 hm + obtain ⟨hne0, hDesc, hAttr⟩ := s2_leaf_relA (G := G2E Z.T2 Z.Sh2) (R := vmRightsOfA rt) ecr.symm hvm23.symm hewv + FP.al FP.pa + have hpaSpec : (core.num.U64.wrapping_sub fp layout.PPTR_BASE).bv = addrFromPPtr (specPtr fp) := + (addr_specA fp).symm + rw [hpaSpec, ← hlsh, hlsh'] at hDesc hAttr + have hsb : ∀ t ∈ Z.T, sbWordA t ≠ cslotAddrA cte := fun t ht => + cnSlot_ne_sbA J.j.1.place hCn.choose_spec.1 hCn.choose_spec.2 ((J.j.1.thT t).2 ht) + have hb : (ew != 0#u64) = true := bne_iff_ne.2 hne0 + refine ⟨.Frame fp sz rt dev true true asid1 vaddr, + .ext (.stage2FrameCap (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev (some (asidOfA asid1, vaddr.bv))), + makeUserPte (addrFromPPtr (specPtr fp)) (attribsFromWord attr.bv) (vmRightsOfA vm) (vmRightsOfA rt) + (frameSizeOfA sz), ?_, ?_, (by intro h; cases h), UA.of_shapeA rfl (by simp [isUtA]), ?_, + ⟨_, _, _, _, rfl, Or.inr hsb⟩, ?_, ?_, ⟨hDesc, hAttr⟩, (fun _ h => by unfold makeUserPte at h; cases h), + Or.inl hne0⟩ + · simp only [CapRt.EncWf]; exact ⟨hcanP, by omega, by omega, hipa48⟩ + · exact ⟨⟨hr1, hr3, ⟨h16, by simp, fun _ => ha1nz, fun _ => rfl⟩, hov⟩, rfl⟩ + · exact ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), + fun _ _ _ h => (by cases h), fun _ h => (by cases h)⟩ + · simp only [hb, if_neg hne0] at hsc1; exact hsc1 + · rw [hiv', ← hvmEq] + -- the restart, the cap write and the install + obtain ⟨x, s2, σ2, hk, hst, hset, hsc, hσ2, HSs, hksb2, -, hcpu2, -, hJ2, -⟩ := + restart_setcapJA E0 RS cte hab hos hEnc hca + have es1 := ok_inj_ff (hst.symm.trans hst1) + subst es1 + have es2 := ok_inj_ff (hsc.symm.trans hsc1') + subst es2 + obtain ⟨J2, -⟩ := hJ2 hTr hnul hnn (by rw [hcap0]; intro h; cases h) (by rw [hcap0]; exact hUA) hok + have hSlotAl : Aligned lu.slot := by + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨r0, j0, hr0, hj0, hluEq, -, -⟩ + · rw [hluEq]; exact peAF_alignedA (Nat.mod_eq_zero_of_dvd (E0.j.1.ext.tal t ht)) hi + · rw [hluEq]; exact E0.j.1.ext.foot_alignedE E0.j.1.vs.yal _ (rootFootE hr0 (E0.j.1.ext.xal r0 hr0) (by + have := s2GeomNumE.2.2.1; omega)) + have hI := install_s2_leaf_mapA (st := st) (s := s2) K J2.1.ar lu ew p1 asid1 vaddr fp attr dev hSlotAl + rw [hinst] at hI + obtain ⟨hW, hAR'⟩ := (WP.spec_ok _).1 hI + have hExtOk : ExtSlotOkX σ2 (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot := s2SlotOkA J2.1.ext hsl + have hfa2 : ∀ w, FootA (L := L) Z s2 w → Aligned w := + FootA.aligned J2.1 (fun c hc o h1 h2 => by rw [nodeAt_ksb hksb2]; exact bxi_nodes E0.sys.ent.bxi c hc o h1 h2) + E0.scAl E0.ap.vcAl + have hEO2 : ExtTabOffA (L := L) Z m s2 := hEO.of_ksA hksb2 hcpu2 + have hTO2 : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s2 q := fun q hq => (hTO q hq).of_ksA hksb2 hcpu2 + have hK2 : Aligned (L.ksb s2) := hksb2 ▸ hK + have hT2 : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s2) := hksb2 ▸ hT + -- J7's exact frame map + have ev : ∀ (Pt Pp' Tb' Hr Te Kt : Set U64) (Lv' Re bits : U64 → Nat), + S1aR2 st H OS Pt Pp' Tb' Hr Te Kt Lv' Re bits hPl.ipa s → + (Ub : Set U64) → VrOK H.omega H.frame H.scs H.scBits OS Z.V Ub (L.ksb s) Pt → + s3 = s ∨ ∃ tag f, S1aFrameMap st OS Pt Pp' hPl.ipa tag s s3 (cslotAddrA cte) f := by + intro Pt Pp' Tb' Hr Te Kt Lv' Re bits R2 Ub vr + have hp := ept.root.path R2 (.Ept p1 0#u64 mp1 asid1 va1) 1#u64 + rw [hrt] at hp + have path : S1aPath st Pp' hPl.ipa s 1#u64 asid1 (s1aTopShift 1#u64 hPl.ipa) 0 p1 := + (WP.spec_ok _).1 hp (p1, asid1) rfl + have h := ept.map_frame.exactEffect (ar := ar) (a := a) hA hPl R2 vr J.sys.ent.os hos d + { ptr := fp, size := sz, rights := rt, is_device := dev, mapped := mp, is_ept := e, asid := asid, vaddr := va } + hcanP (by show rt.val < 4; omega) (fun sh hsh => by + rw [hshE] at hsh + obtain rfl := ok_inj_ff hsh + have hal := FP.al + have h12 : (psA sz).val = 12 ∨ (psA sz).val = 21 ∨ (psA sz).val = 30 := psA_valA sz + dsimp only + rcases h12 with h | h | h <;> rw [h, ws_valA] at hal <;> rw [h] <;> omega) + (fun hne => by + have hmp : mp = true := FP.mz.2 hne + exact ⟨hemp.trans hmp, h16_of_mp hmp⟩) path vaddr vm attr + rw [hres] at h + rcases (WP.spec_ok _).1 h with e | e + · exact Or.inl e + · exact Or.inr ⟨_, _, e⟩ + have fin' : ∃ Ac' : Set U64, SysL st H Z.Cs OS ia ie s3 ∧ SymL st H Z.Cs s3 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s3 ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s3 ∧ + J7A st (J7R2A st ar hPl.ipa) Z H OS s3 + (extSlotWriteX σ2 (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte) m := by + refine fin x iv _ hk (einv ▸ hmem0) ?_ + rw [hinvEq] + unfold Fl4SpecA64.performExtVSpace + have hst' : (Fl4SpecA64.storeExtSlot (Z := Unit) (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte >>= + fun _ => pure ([] : List Fl4SpecA64.Data)) σ2 = + ({([], extSlotWriteX σ2 (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte)}, False) := by + rw [nd_bind_oneD (storeExtSlot_runX hExtOk pte)]; rfl + exact ⟨((), σ2), hσ2, by dsimp only; rw [hst']; rfl⟩ + have hj7f := fin'.choose_spec.2.2.2.2 + have hz : ∀ u ∈ OS, ∀ (p : U64) (n : Nat), UnmCap (capA st s3 u) p n → + ∀ k : U64, k.val < n → k.val % 8 = 0 → L.mem s3 (wa p k) = 0#u64 := by + obtain ⟨_, _, _, -, -, -, -, -, -, -, -, -, -, -, r2f⟩ := hj7f + obtain ⟨_, _, _, _, _, _, _, _, R2f, -, -⟩ := r2f + exact fun u hu p n hu' k hk' h8 => R2f.core.lookup.zr u hu p n hu' k hk' h8 + have coreK := fun (q j : U64) (hq : XqA Z q) (hj : j.val < 512) (hal : Aligned (peAF q j)) + (hW' : ExtWordWriteA (st := st) s2 s3 (peAF q j) ew) + (hJ3 : JAtZAX (L := L) AR Z s3 a3 + (extSlotWriteX σ2 (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte) m) hunm => + J.frameMapExtCoreA (s3 := s3) (a3 := a3) RS hnvm hK hT cte hab hcap0 (c := newC) hbn hEnc hca hok hq hj hal + (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte hk hsc hσ2 hW' hJ3 hExtOk ev hunm + fin' + have hobjAt : ∀ s1 : S, JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s1 a (stUpdA σ σ.curThread x .restart) m → + ∀ u ∈ OS, CapObjOkA Z (capA st s1 u) := + fun s1 J1 u hu => by + by_cases h : IsSlotA Z.th u + · exact J1.j.capObj h + · rw [J1.j5.2.2 u hu h]; exact CapObjOkA.null Z + have done : ∀ (pr : Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (([] : List Fl4SpecA64.Data), extSlotWriteX σ2 (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) (.map newSC cte pte + (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot) (stUpdA σ σ.curThread x .restart)).1 ∧ + ∃ Ac' : Set U64, JStage3A st AR Z H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s3 a3 + (extSlotWriteX σ2 (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte) m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) + (extSlotWriteX σ2 (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte)), + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) (Ac' : Set U64), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR Z H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s3 a3 σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := + fun ⟨h0, hp, Ac', Jf, Kf⟩ => ⟨x, iv, _, Ac', hk, hset, einv ▸ hmem0, by rw [hinvEq]; exact hp, Jf, Kf⟩ + rcases hsl with ⟨t, i, ⟨ht, hst'⟩, hi, hluEq, hslEq⟩ | ⟨r0, j0, hr0, hj0, hluEq, hslEq, hshEq⟩ + · -- a Stage-2 table + have hW' : ExtWordWriteA (st := st) s2 s3 (peAF t i) ew := by rw [← hluEq]; exact hW + have hpte' := hpte + rw [← hst'] at hpte' + have hta : t.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd (E0.j.1.ext.tal t ht) + have hsl' : extSlotObjX (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot = specPtr t := by + rw [hslEq]; exact slotObjPtE hta hi + have hJ3 : JAtZAX (L := L) AR Z s3 a3 + (extSlotWriteX σ2 (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte) m := by + rw [hslEq] + have hE3 := J2.1.ext.of_ptWriteMapE J2.1.vs.yal ht hi hpte' hW'.2.2 (fun ppn h => absurd h (hnotPt ppn)) + have hV3 := J2.1.vs.of_s2WriteE (mem' := L.mem s3) J2.1.ext (Or.inl ht) (J2.1.ext.tal t ht) hi + (hT2 t i hi (Or.inl (Or.inl ht))) hK2 (fun b hb hne => by rw [hW'.2.2 b hb, if_neg (Ne.symm hne)]) + (Or.inl ht) (slotObjPtE hta hi) pte + have hJ' := J2.of_extPageA hfa2 hTO2 hEO2 (Or.inl (Or.inl ht)) hW'.1 hW'.2.1 + (fun w hw hne => by rw [hW'.2.2 w hw, if_neg (Ne.symm (hne i hi))]) + (Or.inr (Or.inr (Or.inl ht))) (fun p hp => + kheap_writeX (by rw [slotObjPtE hta hi]; exact hp)) + (by rw [hW'.1]; exact hV3) hE3 + exact hJ'.of_arA hAR' + have main := coreK t i (Or.inl (Or.inl ht)) hi (peAF_alignedA hta hi) hW' hJ3 + (fun s1 hOS1 hks hcpu J1 Pt link hbk hword hk31 hcpu31 hset' => by + have hpgd := E0.j.1.ext.pgd t (Or.inl ht) + refine UnmPtSpecA.ofS2WrA (Z := Z) (Pt := Pt) (o := specPtr t) (q := t) (j := i) hi hta hpgd + (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨t, ht, rfl⟩)))))))) + (fun y hy e => hpgd.2 (specPtr_inj e ▸ hy)) (fun p hp => E0.j.1.vs.al_mod hp) E0.j.1.vs.yal + (hobjAt s1 J1) hbk hz link hword hk31 hcpu31 + (fun x' ao hne h => hset' x' ao (by rw [hsl']; exact hne) h) + (fun u hu p a' v hc ⟨es, k1, k2⟩ => by + have old := hbk u hu _ hc (fun _ _ _ _ _ _ _ _ f => by cases f) + have hpX : p ∈ Z.X := (hobjAt s1 J1 u hu).2.1 p 0#u64 false a' v old + have hne : specPtr p ≠ specPtr t := fun e' => (E0.j.1.ext.t2x t ht p hpX).1 (specPtr_inj e').symm + exact ⟨es, hset' _ _ (by rw [hsl']; exact hne) k1, k2⟩) + J1.unmPt) + exact done ⟨main.1, main.2.1, main.2.2⟩ + · -- a Stage-2 root page + have hj1k : j0.val < 1024 := by have := s2GeomNumE.2.2.1; omega + obtain ⟨q, j', hq, hj', hpeq⟩ := rootWordE (E0.j.1.ext.xal r0 hr0) hj1k + have hqa : 4096 ∣ q.val := by + rcases hq with h | h <;> rw [h] + · exact al4kE (E0.j.1.ext.xal r0 hr0) + · exact al4kHiE (E0.j.1.ext.xal r0 hr0) + have hqm : q.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd hqa + have hW0 : ExtWordWriteA (st := st) s2 s3 (peAF r0 j0) ew := by rw [← hluEq]; exact hW + have hW' : ExtWordWriteA (st := st) s2 s3 (peAF q j') ew := by rw [← hpeq]; exact hW0 + have hpte' := hpte + rw [hshEq] at hpte' + have hsl' : extSlotObjX (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot = specPtr r0 := by + rw [hslEq]; rfl + have hJ3 : JAtZAX (L := L) AR Z s3 a3 + (extSlotWriteX σ2 (extLookupSlot σ s2Geom (specPtr p1) vaddr.bv).slot pte) m := by + rw [hslEq] + have hE3 := J2.1.ext.of_rootWriteMapE J2.1.vs.yal hr0 hj1k hpte' hW0.2.2 (fun ppn h => absurd h (hnotPt ppn)) + have hV3 := J2.1.vs.of_s2WriteE (mem' := L.mem s3) J2.1.ext (Or.inr ⟨r0, hr0, hq⟩) hqa hj' + (hT2 q j' hj' (Or.inl (Or.inr ⟨r0, hr0, hq⟩))) hK2 + (fun b hb hne => by rw [hW0.2.2 b hb, if_neg (by rw [hpeq]; exact Ne.symm hne)]) + (Or.inr ⟨r0, hr0, Or.inl rfl⟩) (sl := .root (specPtr r0) j0.val) rfl pte + have hJ' := J2.of_extPageA hfa2 hTO2 hEO2 (Or.inl (Or.inr ⟨r0, hr0, hq⟩)) hW'.1 hW'.2.1 + (fun w hw hne => by rw [hW0.2.2 w hw, if_neg (by rw [hpeq]; exact Ne.symm (hne j' hj'))]) + (Or.inl hr0) (fun p hp => kheap_writeX (sl := .root (specPtr r0) j0.val) (pte := pte) hp) + (by rw [hW0.1]; exact hV3) hE3 + exact hJ'.of_arA hAR' + have main := coreK q j' (Or.inl (Or.inr ⟨r0, hr0, hq⟩)) hj' (peAF_alignedA hqm hj') hW' hJ3 + (fun s1 hOS1 hks hcpu J1 Pt link hbk hword hk31 hcpu31 hset' => by + have hpgd := E0.j.1.ext.pgd q (Or.inr ⟨r0, hr0, hq⟩) + have hr0Y := (E0.j.1.ext.pgd r0 (Or.inr ⟨r0, hr0, Or.inl rfl⟩)).2 + refine UnmPtSpecA.ofS2WrA (Z := Z) (Pt := Pt) (o := specPtr r0) (q := q) (j := j') hj' hqm hpgd + (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨r0, hr0, rfl⟩))))) + (fun y hy e => hr0Y (specPtr_inj e ▸ hy)) (fun p hp => E0.j.1.vs.al_mod hp) E0.j.1.vs.yal + (hobjAt s1 J1) hbk hz link hword hk31 hcpu31 + (fun x' ao hne h => hset' x' ao (by rw [hsl']; exact hne) h) + (fun u hu p a' v hc ⟨es, k1, k2⟩ => by + have old := hbk u hu _ hc (fun _ _ _ _ _ _ _ _ f => by cases f) + have hpX : p ∈ Z.X := (hobjAt s1 J1 u hu).2.1 p 0#u64 false a' v old + by_cases hpr : p = r0 + · rcases hewcase with hne0 | ⟨hew0, hpte0⟩ + · exfalso + have hal0 : Aligned (peAF r0 j0) := by rw [hpeq]; exact peAF_alignedA hqm hj' + have hb : L.mem s3 (peAF r0 j0) = ew := by + have := hW0.2.2 _ hal0 + rw [if_pos rfl] at this + exact this + have hc' : capA st s3 u = .Ept r0 0#u64 false a' v := hpr ▸ hc + have wm : (core.num.U64.wrapping_mul j0 8#u64).val = j0.val * 8 := by + simp [core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits]; omega + have hz0 := hz u hu r0 8192 (Or.inr ⟨rfl, a', v, hc'⟩) (core.num.U64.wrapping_mul j0 8#u64) + (by rw [wm]; omega) (by rw [wm]; omega) + exact hne0 (hb.symm.trans hz0) + · have k1' : σ2.kheap (specPtr r0) = some (.archObj (.ext (.stage2Root es))) := + HSs.keep (hpr ▸ k1) (fun _ _ e => by cases e) (fun _ e => by cases e) + refine ⟨fun j => if j.val = j0.val then pte else es j, ?_, fun i' => ?_⟩ + · rw [hpr, hslEq]; exact extRootSetE k1' j0.val pte + · by_cases h : i'.val = j0.val + · simp only [h, if_true]; exact hpte0 + · simp only [h, if_false]; exact k2 i' + · have hne : specPtr p ≠ specPtr r0 := fun e' => hpr (specPtr_inj e') + exact ⟨es, hset' _ _ (by rw [hsl']; exact hne) k1, k2⟩) + J1.unmPt) + exact done ⟨main.1, main.2.1, main.2.2⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapA.lean index f22b5ace2..23dd5557f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapA.lean @@ -364,7 +364,7 @@ theorem JStage3A.ptMapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} by_cases e : q0 = ptr · subst e; rw [Function.update_self]; omega · rw [Function.update_of_ne e]; exact hq.2) - (hT2 := fun _ h => h) + (hT2 := fun _ _ _ _ _ _ _ h => h) (hpt := fun q0 _ _ h => by injection h with h1 subst h1 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapHiA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapHiA.lean new file mode 100644 index 000000000..d1bcdc0dd --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapHiA.lean @@ -0,0 +1,902 @@ +/- +P3 (AArch64, Stage 4, line vsx-B, CP B1): **`JStage3A` across a successful `ARMPageTableMap` into an +`ArmHighVSpace` window** (`JStage3A.ptMapHiA`, at `vspace::map_high_page_table`). The twin of +`P3/Stage3ArmPtMapA` (Stage-1 root): FL4 restarts the thread, rewrites the invoked cap as mapped and writes one table +descriptor, here into a window page (a level-1 root page of `Z.Y`, or a Stage-1 table of `Z.S1` below it). The new +table joins **`Z.S1`** at depth `n = (39 - (shift - 9)) / 9` (`shift ∈ {30, 21}`: `lu.shift ≠ 39` because the window's +level-0 entry 511 is always a table, `lu.shift ≠ 12` is FL4's `DeleteFirst`). + +* `UnmPtSpecA.ofValidWrA`: J9 across one *valid* descriptor write into a footprint word (`ofFootWrA`) when the cap + rewrite makes an unmapped page-table cap mapped and the ghost sets grow. +* **`JStage3A.ptMapHiA`**: arm hypotheses are `hi_map_pt_jA`'s decode-site facts (`UnmPtA`, `ptr ∉ S2PgE`, `ptr ∉ Y`, + the window root cap and the spec decode `D`), FL4's `map_high_page_table` succeeds, and `fin`: `SysL`, `BXI` at some + `Ac'`, `UserOK` and J7 at the final state (the T3 wrapper's `decodeFinA`). + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3ArmPtMapA +import Fl4ProofsA64.P3.Stage3ArmFrMapHiA +import Fl4ProofsA64.P3.Stage3MapExtA +import Fl4ProofsA64.P3.ExtMapPtA +import Fl4ProofsA64.P3.Stage3T3DecEqA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +/-- **J9 across one valid write into a footprint word while the ghost tables grow** (module docstring): `ofFootWrA` +with the cap rewrite allowed to make an unmapped page-table cap mapped (`hbk` only keeps the unmapped table-root caps) +and the `TabOffA` transfer `hoff` to the grown ghosts `Z'`. -/ +theorem UnmPtSpecA.ofValidWrA {Z Z' : XSetsA} {OS : Set U64} {s s' : S} {σ σ' : State Unit} {m : McState} + {Pt : Set U64} {b : U64} {o : Fl4SpecA64.ObjRef} + (hfoot : FootA (L := L) { Z with S1 := ∅ } s b) (hobj : RelPA { Z with S1 := ∅ } m o) + (hbk : ∀ u ∈ OS, ∀ c, capA st s' u = c → (∀ q a v, c = .PageTable q false a v ∨ c = .Pml4 q false a ∨ + c = .Ept q 0#u64 false a v ∨ c = .HighVSpace q false a → capA st s u = c)) + (hword : ∀ q ∈ Pt, ∀ j : U64, j.val < 512 → peAF q j ≠ b → L.mem s' (peAF q j) = L.mem s (peAF q j)) + (link : ∀ q, SchedPageA st Z OS s q → q ∈ Pt) + (hoff : ∀ u ∈ OS, ∀ q, ((∃ a v, capA st s' u = .PageTable q false a v) ∨ ∃ a, capA st s' u = .Pml4 q false a) → + TabOffA (L := L) Z m s q → TabOffA (L := L) Z' m s' q) + (hset : ∀ q ao, q ≠ o → σ.kheap q = some (.archObj ao) → σ'.kheap q = some (.archObj ao)) + (hs2 : ∀ u ∈ OS, ∀ p a v, capA st s u = .Ept p 0#u64 false a v → + (∀ j : U64, j.val < 512 → peAF p j ≠ b ∧ peAF (wa p 4096#u64) j ≠ b) ∧ specPtr p ≠ o) + (hhv : ∀ u ∈ OS, ∀ p a, capA st s u = .HighVSpace p false a → + (∀ j : U64, j.val < 512 → peAF (wa p 4096#u64) j ≠ b) ∧ specPtr p ≠ o) + (h : UnmPtSpecA st Z m OS s σ) : UnmPtSpecA st Z' m OS s' σ' := by + have tab : ∀ ty q, q ∈ Pt → TabOffA (L := L) Z' m s' q → UnmTabA st Z m s σ ty q → + UnmTabA st Z' m s' σ' ty q := fun ty q hq hoq h0 => by + obtain ⟨t, k1, k2, k3⟩ := h0.spec + refine ⟨fun j hj => ?_, ⟨t, hset _ _ (h0.off.obj o hobj).symm k1, k2, k3⟩, hoq⟩ + rw [hword q hq j hj (fun e => h0.off.mem j hj (e ▸ hfoot))] + exact h0.inv j hj + refine ⟨fun u hu q asid va hc => ?_, fun u hu q asid hc => ?_, fun u hu q asid va hc => ?_, + fun u hu q asid hc => ?_⟩ + · have old := hbk u hu _ hc q asid va (Or.inl rfl) + exact tab _ _ (link q (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr + ⟨u, hu, Or.inl ⟨_, _, _, old⟩⟩)))))))) (hoff u hu q (Or.inl ⟨asid, va, hc⟩) (h.pt u hu q asid va old).off) + (h.pt u hu q asid va old) + · have old := hbk u hu _ hc q asid 0#u64 (Or.inr (Or.inl rfl)) + exact tab _ _ (link q (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr + ⟨u, hu, Or.inr (Or.inl ⟨_, _, old⟩)⟩)))))))) (hoff u hu q (Or.inr ⟨asid, hc⟩) (h.vs u hu q asid old).off) + (h.vs u hu q asid old) + · have old := hbk u hu _ hc q asid va (Or.inr (Or.inr (Or.inl rfl))) + obtain ⟨nw, no⟩ := hs2 u hu q asid va old + have l0 : q ∈ Pt := link q (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr + ⟨u, hu, Or.inr (Or.inr (Or.inl ⟨_, _, old⟩))⟩))))))) + have l1 : wa q 4096#u64 ∈ Pt := link _ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr + ⟨u, hu, Or.inr (Or.inr (Or.inr (Or.inl ⟨q, _, _, old, rfl⟩)))⟩))))))) + have h0 := h.s2 u hu q asid va old + obtain ⟨es, k1, k2⟩ := h0.spec + refine ⟨fun j hj => ?_, es, hset _ _ no k1, k2⟩ + by_cases hlo : j.val < 512 + · rw [hword q l0 j hlo (nw j hlo).1]; exact h0.inv j hj + · obtain ⟨j', hj', ej⟩ := peAF_hiA q j (by omega) hj + have := h0.inv j hj + rw [ej] at this ⊢ + rw [hword _ l1 j' hj' (nw j' hj').2]; exact this + · have old := hbk u hu _ hc q asid 0#u64 (Or.inr (Or.inr (Or.inr rfl))) + obtain ⟨nw, no⟩ := hhv u hu q asid old + have l1 : wa q 4096#u64 ∈ Pt := link _ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr + ⟨u, hu, Or.inr (Or.inr (Or.inr (Or.inr ⟨q, _, old, rfl⟩)))⟩))))))) + have h0 := h.hv u hu q asid old + obtain ⟨l, k1, k2⟩ := h0.spec + refine ⟨fun j hj => ?_, l, hset _ _ no k1, k2⟩ + rw [hword _ l1 j hj (nw j hj)]; exact h0.inv j hj + +set_option maxHeartbeats 8000000 in +/-- **`JStage3A` across a successful `ARMPageTableMap` into a high window** (module docstring). -/ +theorem JStage3A.ptMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {ar : machine.Arch A} {nA : U64} {s s3 : S} {a : A} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) + (hK : Aligned (L.ksb s)) (hT : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s)) + (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) {ptr asid0 va0 : U64} + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr false asid0 va0) + (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (hS2 : ptr ∉ S2PgE Z.X Z.T2) (hY : ptr ∉ Z.Y) + (vp vasid vaddr : U64) (vmp : Bool) (hvwf : CapWfA (.HighVSpace vp vmp vasid)) + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeHighPageTableMap (Z := Unit) cte (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .high (specPtr vp) (asidDataA vmp vasid)) vaddr.bv)).run σ) + (hres : vspace.map_high_page_table st s (cslotAddrA cte) ptr (.HighVSpace vp vmp vasid) vaddr = + ok (core.result.Result.Ok (), s3)) + (fin : ∀ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit), + σ.kheap σ.curThread = some (.tcb x) → (.ok (.extVSpace iv), σ) ∈ D.1 → + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 → + ∃ Ac' : Set U64, SysL st H Z.Cs OS ia ie s3 ∧ SymL st H Z.Cs s3 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s3 ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s3 ∧ + J7A st (J7R2A st ar nA) Z H OS s3 σ3 m) : + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) + (Ac' Tb' : Set U64) (Lv' : U64 → Nat) (nL : Nat), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with S1 := insert ptr Z.S1, Lv := Function.update Z.Lv ptr nL } H OS U Ac' Pp Tb' Lv' ia ie N E + Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s3 a σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + have E0 := J.toJEntA + have hx : cslotAddrA cte ∈ OS := RS.sub _ (hab.isSlot J.j.1.place) + have hO : OSOK H.tcbs H.omega H.frame OS := J.sys.ent.os + have hTr0 : TreeA st OS Z.G.chains Z.G.par s := + J.j.1.cdt.tree.grow J.j5.2.1 (fun x hx hn => J.j5.2.2 x hx hn) + have hnul0 : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null := J.j5.2.2 + have hX : ∀ r ∈ Z.X, ∃ es, σ.kheap (specPtr r) = some (.archObj (.ext (.stage2Root es))) := + fun r hr => ⟨(E0.j.1.ext.s2root r hr).choose, (E0.j.1.ext.s2root r hr).choose_spec.1⟩ + suffices W : vspace.map_high_page_table st s (cslotAddrA cte) ptr (.HighVSpace vp vmp vasid) vaddr ⦃ res => + res = (core.result.Result.Ok (), s3) → + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) + (Ac' Tb' : Set U64) (Lv' : U64 → Nat) (nL : Nat), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with S1 := insert ptr Z.S1, Lv := Function.update Z.Lv ptr nL } H OS U Ac' Pp Tb' Lv' ia ie N E + Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s3 a σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 ⦄ by + rw [hres] at W + exact (WP.spec_ok _).1 W rfl + unfold vspace.map_high_page_table + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (check_high_vspaceA E0.j.1.vs hX vp vasid 1#u64 vmp hvwf) fun rchk hchk => ?_ + rcases rchk with ⟨root, asid1⟩ | err + 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, WP.spec_ok] + exact fun h => by cases h + obtain ⟨hpair, hrootY, ha1ne, hchkOk⟩ := hchk + have h1 : root = vp := congrArg Prod.fst hpair + have h2 : asid1 = vasid := congrArg Prod.snd hpair + subst root; subst asid1 + have hactY : ActiveHighRootA (L.mem s) (L.ksb s) Z.Pp vp := + activeHighRootA_of_vspaceForAsid E0.j.1.vs hX hrootY (vspaceForAsid_of_checkExtRootA (by decide) hchkOk) + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + have ha16 : vasid.val < 2 ^ 16 := hvwf + have hD1 : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace (do + NonDetE.whenE (vaddr.bv < highVSpaceBase ∨ vaddr.bv ≥ highVSpaceTop) (NonDetE.throwError (.invalidArgument 0)) + let pos ← NonDetE.liftE (NonDet.gets fun s : State Unit => extLookupSlot s highGeom (specPtr vp) vaddr.bv) + let old ← NonDetE.liftE (NonDet.gets fun s : State Unit => pos.slot.read s) + NonDetE.whenE (pos.shift = pageBits ∨ old ≠ .invalidPTE) (NonDetE.throwError .deleteFirst) + NonDetE.returnOk (.map (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, vaddr.bv &&& ~~~(mask pos.shift)))) + cte (.pageTablePTE (ppnFromPptr (specPtr ptr))) pos.slot))).run σ := by + rw [hD]; unfold decodeHighPageTableMap + dsimp only + apply run_liftME_congr_pt + exact run_bind_okA hchkOk _ + by_cases hlt : vaddr < fl4_abi.consts.HIGH_VSPACE_BASE + · simp only [if_pos hlt, error.invalid_arg, bind_ok] + exact (WP.spec_ok _).2 fun h => by cases h + simp only [if_neg hlt] + have hlo : fl4_abi.consts.HIGH_VSPACE_BASE ≤ vaddr := by scalar_tac + have hlt' : ¬ (vaddr.bv < highVSpaceBase) := by + intro h; apply hlt + show vaddr.val < fl4_abi.consts.HIGH_VSPACE_BASE.val + have hb : highVSpaceBase.toNat = fl4_abi.consts.HIGH_VSPACE_BASE.val := by + unfold highVSpaceBase fl4_abi.consts.HIGH_VSPACE_BASE; rfl + rw [← hb]; exact h + by_cases hge : vaddr >= fl4_abi.consts.HIGH_VSPACE_TOP + · simp only [if_pos hge, error.invalid_arg, bind_ok] + exact (WP.spec_ok _).2 fun h => by cases h + simp only [if_neg hge] + have hge' : ¬ (vaddr.bv ≥ highVSpaceTop) := by + intro h; apply hge + show fl4_abi.consts.HIGH_VSPACE_TOP.val ≤ vaddr.val + have ht : highVSpaceTop.toNat = fl4_abi.consts.HIGH_VSPACE_TOP.val := by + unfold highVSpaceTop fl4_abi.consts.HIGH_VSPACE_TOP; rfl + rw [← ht]; exact h + let pos := extLookupSlot σ highGeom (specPtr vp) vaddr.bv + refine WP.spec_bind (lookup_pt_slot_hiA E0.j.1.vs E0.j.1.ext hrootY hactY (hi_idx39_eq_pt vaddr hlo)) fun lu ⟨hlsh, hslR⟩ => ?_ + have hsl : SlotRelE (G1E Z.S1 Z.Lv) (TopHiE Z.Y) lu.slot pos.slot pos.shift := + hslR.mono (fun _ _ g => g.1) (fun _ _ _ ht => ht.toTopHiE) + have hD2 : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace (do + NonDetE.whenE (pos.shift = pageBits ∨ pos.slot.read σ ≠ .invalidPTE) (NonDetE.throwError .deleteFirst) + NonDetE.returnOk (.map (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, vaddr.bv &&& ~~~(mask pos.shift)))) + cte (.pageTablePTE (ppnFromPptr (specPtr ptr))) pos.slot))).run σ := by + rw [hD1] + apply run_liftME_congr_pt + rw [run_bind_okA (by simp only [NonDetE.whenE, if_neg (not_or.2 ⟨hlt', hge'⟩)]; rfl)] + rw [run_bind_okA (liftE_gets_pt (fun s : State Unit => extLookupSlot s highGeom (specPtr vp) vaddr.bv) σ)] + rw [run_bind_okA (liftE_gets_pt (fun s : State Unit => pos.slot.read s) σ)] + have hpb : vspace.PAGE_BITS = 12#u64 := by unfold vspace.PAGE_BITS; rfl + by_cases h12 : lu.shift = vspace.PAGE_BITS + · rw [if_pos h12] + simp only [WP.spec_ok] + exact fun h => by cases h + rw [if_neg h12] + have hp12 : pos.shift ≠ pageBits := by + intro h; apply h12; apply UScalar.eq_of_val_eq; rw [hlsh, h, hpb]; rfl + have hshCases : pos.shift = 30 ∨ pos.shift = 21 := by + rcases hiLookup_shift_pt σ (specPtr vp) vaddr.bv with h | h | h + · exact Or.inl h + · exact Or.inr h + · exact (hp12 h).elim + have hlsh' : lu.shift.val = pos.shift := hlsh + have hneTop : lu.shift ≠ vspace.TOP_LEVEL_SHIFT := by + intro h + have hv39 : lu.shift.val = 39 := by rw [h]; unfold vspace.TOP_LEVEL_SHIFT; rfl + rcases hshCases with h' | h' <;> omega + rw [if_neg hneTop] + rw [L.read_eq, bind_ok, eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, bind_ok] + simp only [lift, bind_ok, valid_bitA] + have hDescRead := extSlotRead_of_hiSlot_pt E0.j.1.vs hslR + by_cases hv : dBitA (L.mem s lu.slot) 0 = true + · rw [if_pos hv] + simp only [WP.spec_ok] + exact fun h => by cases h + have hvf : dBitA (L.mem s lu.slot) 0 = false := by simpa using hv + rw [if_neg hv] + have hInvEq : pos.slot.read σ = .invalidPTE := (descRelE_invA hDescRead).2 hvf + have hs64 : lu.shift.val < 64 := by rcases hshCases with h | h <;> omega + have e63 : (lu.shift &&& 63#u64) = lu.shift := + UScalar.eq_of_val_eq (by + rw [and_maskA lu.shift 6 _ rfl]; exact Nat.mod_eq_of_lt (by simp only [Nat.reducePow]; omega)) + rw [e63, CapRt.shl_u64_eq 1#u64 lu.shift hs64, bind_ok] + try simp only [lift, bind_ok] + rw [ws1A lu.shift hs64] + generalize hbase : vaddr &&& ~~~(⟨BitVec.ofNat 64 (2 ^ lu.shift.val - 1)⟩ : U64) = base + have hbv : base.bv = vaddr.bv &&& ~~~(Fl4SpecA64.mask pos.shift) := by + rw [← hbase, ← hlsh, mask_eq_ofNat_pt (by omega)]; rfl + have hbaseGe : fl4_abi.consts.HIGH_VSPACE_BASE ≤ base := by + rw [← hbase]; exact hi_base_ge_pt vaddr hlo (by omega) + have hbv48 : 2 ^ 48 ≤ base.val := by + have hb : fl4_abi.consts.HIGH_VSPACE_BASE.val = 18446743936270598144 := by + unfold fl4_abi.consts.HIGH_VSPACE_BASE; rfl + have h' : fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ base.val := by scalar_tac + omega + have hbaseCan : CapRt.Canonical base := by + rw [← hbase]; exact hi_can_pt _ (hi_base_ge_pt vaddr hlo (by omega)) + have hcanon : CapRt.Canonical ptr := by + have h : CapRt.EncWf (capAtA (L.mem s) (cslotAddrA cte)) := CapRt.decodeF_encWf _ _ + rw [hcap] at h; exact h.1 + have hEnc : CapRt.EncWf (.PageTable ptr true vasid base) := ⟨hcanon, by omega, hbaseCan⟩ + have hca : CapRelA (.PageTable ptr true vasid base) + (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, base.bv)))) := + ⟨ha16, rfl, rfl, Or.inl rfl⟩ + obtain ⟨xc, s2, σ2, hkx, hst, hset, hsc, hσ2, HS, hksb2, R2, hcpu2, hw2, hJ2, hFr2⟩ := + restart_setcapJA E0 RS cte hab hx hEnc hca + rw [hst, bind_ok, hsc, bind_ok] + rw [show layout.paddr ptr = ok (core.num.U64.wrapping_sub ptr layout.PPTR_BASE) from rfl, bind_ok] + have hpaMod : (core.num.U64.wrapping_sub ptr layout.PPTR_BASE).val % 4096 = 0 := by + rw [ws_valA]; have := Nat.mod_eq_zero_of_dvd UP.al; omega + have hpa48 : (core.num.U64.wrapping_sub ptr layout.PPTR_BASE).val < 2 ^ 48 := by + have := UP.pa; omega + refine WP.spec_bind (s1tab_v _ hpaMod hpa48) fun ew ⟨hv3, hvm⟩ => ?_ + rw [L.write_eq, bind_ok] + refine (WP.spec_ok _).2 fun hEq => ?_ + have es3 : L.wr s2 lu.slot ew = s3 := (Prod.mk.inj hEq).2 + subst es3 + have hco : capA st s (cslotAddrA cte) = .PageTable ptr false asid0 va0 := by rw [← capAtA_eq, hcap] + let nL : Nat := (39 - (pos.shift - 9)) / 9 + have hnBounds : 1 ≤ nL ∧ nL ≤ 3 ∧ 39 - 9 * nL = pos.shift - 9 := by + rcases hshCases with h | h <;> simp [nL, h] + let S1' : Set U64 := insert ptr Z.S1 + let Zl : U64 → Nat := Function.update Z.Lv ptr nL + let Z' : XSetsA := { Z with S1 := S1', Lv := Zl } + let pte : PTE := .pageTablePTE (ppnFromPptr (specPtr ptr)) + obtain ⟨J2, hT2⟩ := hJ2 hTr0 hnul0 (by simp) (by rw [hco]; simp) + (UA.of_shapeA (by rw [hco]; rfl) fun h => by rw [hco] at h; simp [isUtA] at h) + ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), + fun _ _ _ h => (by cases h), trivial⟩ + have hmem2 := unm_mem_keep_pt E0.sq.curT + (fun t ht => by have := (E0.sq.tcbs t ht).fits; simp only [Nat.reducePow] at this; exact this) + (by rw [stA_eq]; exact field_aligned (E0.sq.tcbs _ E0.sq.curT) (by simp) (by simp)) UP hw2 + obtain ⟨tp, hkp, htp, hep⟩ := UP.spec + have hkp1 : (stUpdA σ σ.curThread xc .restart).kheap (specPtr ptr) = some (.archObj (.pageTable tp)) := + stUpd_keep hkx hkp (fun _ h => by cases h) + have hkp2 := HS.keep hkp1 (fun _ _ h => by cases h) (fun _ h => by cases h) + have R2Add : VsRelA Z.Pp S1' Zl Z.X Z.Y (L.mem s2) (L.ksb s2) σ2 := + J2.1.vs.addPtA UP.nt UP.al UP.ytb (fun i hi => by rw [hmem2 i hi]; exact UP.inv i hi) hkp2 htp hep + (by omega) hnBounds.2.1 + have E2Add : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s2) σ2 := + J2.1.ext.addS1PtE hS2 hY + have hAlLu : Aligned lu.slot := by + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨y, j, hy, hj, hluEq, -, -⟩ + · rw [hluEq]; exact peAF_alignedA (E0.j.1.vs.al_mod ht) hi + · rw [hluEq]; exact peAF_alignedA (waWin_modA (E0.j.1.vs.yal y hy)) hj + have hW := extWordWriteA (st := st) (s := s2) (slot := lu.slot) (word := ew) hAlLu + have hExtOk : ExtSlotOkX σ2 pos.slot := extSlotOk_of_hiSlot_pt J2.1.vs hsl + have hInv : D = ({(.ok (.extVSpace (.map (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, base.bv))) + cte pte pos.slot)), σ)}, False) := by + rw [hD2] + apply run_liftME_okA + have hokW : (NonDetE.whenE (pos.shift = pageBits ∨ pos.slot.read σ ≠ .invalidPTE) + (NonDetE.throwError SyscallError.deleteFirst)).run σ = ({(Except.ok (), σ)}, False) := by + unfold NonDetE.whenE + rw [if_neg (by rintro (h | h); exact hp12 h; exact h hInvEq)]; rfl + rw [run_bind_okA hokW, hbv] + rfl + have hmemD : (.ok (.extVSpace (.map (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, base.bv))) + cte pte pos.slot)), σ) ∈ D.1 := by rw [hInv]; exact rfl + have hperfV : (([] : List Fl4SpecA64.Data), extSlotWriteX σ2 pos.slot pte) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) (.map (.pageTableCap (specPtr ptr) .normalPtT + (some (asidOfA vasid, base.bv))) cte pte pos.slot) (stUpdA σ σ.curThread xc .restart)).1 := by + unfold Fl4SpecA64.performExtVSpace + have hst' : (Fl4SpecA64.storeExtSlot (Z := Unit) pos.slot pte >>= + fun _ => pure ([] : List Fl4SpecA64.Data)) σ2 = + ({([], extSlotWriteX σ2 pos.slot pte)}, False) := by + rw [nd_bind_oneD (storeExtSlot_runX hExtOk pte)]; rfl + exact ⟨((), σ2), hσ2, by dsimp only; rw [hst']; rfl⟩ + have hfa2 : ∀ w, FootA (L := L) Z s2 w → Aligned w := + FootA.aligned J2.1 (fun c hc o h1 h2 => by rw [nodeAt_ksb hksb2]; exact bxi_nodes E0.sys.ent.bxi c hc o h1 h2) + E0.scAl E0.ap.vcAl + have hEO2 : ExtTabOffA (L := L) Z m s2 := hEO.of_ksA hksb2 hcpu2 + have hTO2 : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s2 q := fun q hq => (hTO q hq).of_ksA hksb2 hcpu2 + have hK2 : Aligned (L.ksb s2) := hksb2 ▸ hK + have hT2' : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s2) := hksb2 ▸ hT + have hdTab : dTabA ew = ptr := by + unfold dTabA dAddrA + have hmask : (281474976706560#u64 : U64) = vspace.ADDR_MASK := by unfold vspace.ADDR_MASK; rfl + rw [hmask, hvm, ← pptrBase_litA] + exact wa_ws ptr layout.PPTR_BASE + have hchEmpty : ∀ j : U64, j.val < 512 → dBitA (L.mem s2 (peAF (dTabA ew) j)) 0 = false ∧ + ∀ t1, σ2.kheap (specPtr (dTabA ew)) = some (.archObj (.pageTable t1)) → + Fl4SpecA64.ptApply t1 j.bv = .invalidPTE := by + rw [hdTab] + intro j hj + refine ⟨by rw [hmem2 j hj]; exact UP.inv j hj, fun t1 hk1 => ?_⟩ + rw [hkp2] at hk1 + cases hk1 + exact hep j hj + have hV3 : VsRelA Z.Pp S1' Zl Z.X Z.Y (L.mem (L.wr s2 lu.slot ew)) (L.ksb (L.wr s2 lu.slot ew)) + (extSlotWriteX σ2 pos.slot pte) := by + rcases hsl with ⟨t, i, ⟨ht, h1t, hst⟩, hi, hluEq, hslEq⟩ | ⟨y, j, hy, hj, hluEq, hslEq, hshEq⟩ + · rw [hluEq] at hW ⊢; rw [hslEq] + have hne : t ≠ ptr := fun e => UP.nt (e ▸ ht) + have hLvt : Zl t = Z.Lv t := Function.update_of_ne hne _ _ + have h3t : Z.Lv t < 3 := by omega + have hnEq : nL = Z.Lv t + 1 := by omega + have hPte := pteRel_mutA (Tb := S1') (Lv := Zl) (k := Z.Lv t) h3t hv3 hvm UP.pa + (Set.mem_insert _ _) (by show Function.update Z.Lv ptr nL ptr = Z.Lv t + 1; rw [Function.update_self, hnEq]) + have hV' := R2Add.of_ptWriteMapE hK2 (Set.mem_insert_of_mem _ ht) (by rw [hLvt]; exact h1t) hi + (hT2' t i hi (Or.inr (Or.inr (Or.inl ht)))) (by rw [hLvt]; exact hPte) hW.2.2 + (fun _ _ => ⟨by rw [hdTab]; exact hne.symm, hchEmpty⟩) + rw [hW.1]; exact hV' + · rw [hluEq] at hW ⊢; rw [hslEq] + have hnEq : nL = 2 := by + have h30 : pos.shift = 30 := hshEq + simp [nL, h30] + have hPte := pteRel_mutA (Tb := S1') (Lv := Zl) (k := 1) (by omega) hv3 hvm UP.pa + (Set.mem_insert _ _) (by show Function.update Z.Lv ptr nL ptr = 1 + 1; rw [Function.update_self, hnEq]) + have hV' := R2Add.of_hiRootWriteMapE hK2 hy hj + (hT2' (wa y 4096#u64) j hj (Or.inr (Or.inr (Or.inr ⟨y, hy, rfl⟩)))) hPte (J2.1.ext.ypp y hy) hW.2.2 + (fun _ _ => hchEmpty) + rw [hW.1]; exact hV' + have hE3 : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem (L.wr s2 lu.slot ew)) (extSlotWriteX σ2 pos.slot pte) := by + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, hslEq⟩ | ⟨y, j, hy, hj, hluEq, hslEq, -⟩ + · rw [hluEq] at hW ⊢; rw [hslEq] + exact E2Add.of_vsWriteE (mem' := L.mem (L.wr s2 (peAF t i) ew)) J2.1.vs.yal + (Or.inr (Or.inl (Set.mem_insert_of_mem _ ht))) (J2.1.vs.al t ht) hi + (fun b hb hne => by rw [hW.2.2 b hb, if_neg (Ne.symm hne)]) + (Or.inl (Set.mem_insert_of_mem _ ht)) (unm_not_pp_pt J2.1.vs (J2.1.vs.pt t ht).choose_spec.1) + (slotObjPtE (J2.1.vs.al_mod ht) hi) pte + · rw [hluEq] at hW ⊢; rw [hslEq] + exact E2Add.of_vsWriteE (mem' := L.mem (L.wr s2 (peAF (wa y 4096#u64) j) ew)) J2.1.vs.yal + (Or.inr (Or.inr ⟨y, hy, rfl⟩)) (Nat.dvd_of_mod_eq_zero (waWin_modA (J2.1.vs.yal y hy))) hj + (fun b hb hne => by rw [hW.2.2 b hb, if_neg (Ne.symm hne)]) + (sl := .root (specPtr y) j.val) (Or.inr hy) (fun hyP => J2.1.ext.ypg y hy (Or.inl hyP)) rfl pte + have hJ3 : JAtZAX (L := L) AR Z' (L.wr s2 lu.slot ew) a (extSlotWriteX σ2 pos.slot pte) m := by + have hSame : SameA (L := L) (extZA Z) s2 (L.wr s2 lu.slot ew) := by + refine ⟨hW.1, hW.2.1, fun w hw => ?_⟩ + have hne : lu.slot ≠ w := by + intro heq; subst heq + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨y, j, hy, hj, hluEq, -, -⟩ + · rw [hluEq] at hw; exact (hTO2 t ht).mem i hi hw.extMonoA + · rw [hluEq] at hw; exact hEO2.mem (wa y 4096#u64) (Or.inr ⟨y, hy, rfl⟩) j hj hw + rw [hW.2.2 w (hfa2 w (FootA.s1_monoA hw.extMonoA)), if_neg hne] + have hkh : ∀ p, RelPA (extZA Z) m p → (extSlotWriteX σ2 pos.slot pte).kheap p = σ2.kheap p := by + intro p hp + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, -, hslEq⟩ | ⟨y, j, hy, hj, -, hslEq, -⟩ + · rw [hslEq]; exact kheap_writeX (by + rw [slotObjPtE (J2.1.vs.al_mod ht) hi] + intro e; subst e; exact (hTO2 t ht).obj _ hp.extMonoA rfl) + · rw [hslEq]; exact kheap_writeX (by + intro e; subst e; exact hEO2.obj y (Or.inr (Or.inl hy)) hp) + have hobj : ∀ ko, (extSlotWriteX σ2 pos.slot pte).kheap (extSlotObjX pos.slot) = some ko → ExtObjA ko → + (∃ l1, ko = .archObj (.ext (.highVSpace l1)) ∧ ∃ r ∈ Z.Y, specPtr r = extSlotObjX pos.slot) := by + intro ko e hx + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, -, hslEq⟩ | ⟨y, j, hy, hj, -, hslEq, -⟩ + · rw [hslEq] at e ⊢ + have hso : extSlotObjX (ExtSlot.pt (specPtr (peAF t i))) = specPtr t := slotObjPtE (J2.1.vs.al_mod ht) hi + rw [hso] at e + obtain ⟨pt', hk', -, -⟩ := hV3.pt t (Set.mem_insert_of_mem _ ht) + rw [hslEq] at hk' + obtain rfl := hk'.symm.trans e |> Option.some.inj + rcases hx with ⟨_, h'⟩ | ⟨_, h'⟩ | ⟨_, h'⟩ <;> cases h' + · rw [hslEq] at e ⊢ + obtain ⟨l1, hk', -⟩ := hV3.high y hy + rw [hslEq] at hk' + obtain rfl := hk'.symm.trans e |> Option.some.inj + exact ⟨l1, rfl, y, hy, rfl⟩ + have hv' : ∀ p x, (extSlotWriteX σ2 pos.slot pte).kheap p = some (.archObj (.vcpu x)) → + σ2.kheap p = some (.archObj (.vcpu x)) := fun p x e => by + by_cases hp : p = extSlotObjX pos.slot + · subst hp; obtain ⟨_, h, -⟩ := hobj _ e (Or.inl ⟨x, rfl⟩); cases h + · rwa [kheap_writeX hp] at e + have hx' : ∀ p es, (extSlotWriteX σ2 pos.slot pte).kheap p = some (.archObj (.ext (.stage2Root es))) → + ∃ r ∈ Z.X, specPtr r = p := fun p es e => by + by_cases hp : p = extSlotObjX pos.slot + · subst hp; obtain ⟨_, h, -⟩ := hobj _ e (Or.inr (Or.inl ⟨es, rfl⟩)); cases h + · exact J2.2.2.1.back p es (by rwa [kheap_writeX hp] at e) + have hy' : ∀ p l1, (extSlotWriteX σ2 pos.slot pte).kheap p = some (.archObj (.ext (.highVSpace l1))) → + ∃ r ∈ Z.Y, specPtr r = p := fun p l1 e => by + by_cases hp : p = extSlotObjX pos.slot + · subst hp; obtain ⟨_, -, r, hr, hreq⟩ := hobj _ e (Or.inr (Or.inr ⟨l1, rfl⟩)); exact ⟨r, hr, hreq⟩ + · exact J2.2.2.2.back p l1 (by rwa [kheap_writeX hp] at e) + exact J2.of_sameXA hSame (by constructor <;> first | rfl | exact ⟨rfl, rfl, rfl, rfl⟩) hkh rfl rfl hv' hx' hy' + (fun q hq hl => ⟨Set.mem_insert_of_mem _ hq, by + have hne : q ≠ ptr := fun e => UP.nt (e ▸ hq) + show Function.update Z.Lv ptr nL q = 0 + rw [Function.update_of_ne hne]; exact hl⟩) hV3 hE3 + obtain ⟨x1, hk1, -, -, J1, -, hOS1, -⟩ := J.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have exc : xc = x1 := by + have hkx' := hkx + rw [hk1] at hkx' + injection hkx' with h + injection h with h + exact h.symm + subst exc + have hks1 : L.ksb (L.wr s (stA (L.curW s)) sched.TS_RESTART) = L.ksb s := L.ksb_wr _ _ _ + have hcpu1 : L.cpu (L.wr s (stA (L.curW s)) sched.TS_RESTART) = L.cpu s := L.cpu_wr _ _ _ + have sA : Aligned (stA (L.curW s)) := by + rw [stA_eq]; exact field_aligned (E0.sq.tcbs _ E0.sq.curT) (by simp) (by simp) + generalize hs1 : L.wr s (stA (L.curW s)) sched.TS_RESTART = s1 at J1 hOS1 hks1 hcpu1 hsc hw2 hFr2 hst + have c1 : capA st s1 (cslotAddrA cte) = .PageTable ptr false asid0 va0 := (hOS1.capA hx).trans hco + have E1 := J1.toJEntA + have R0 := J.j.1.vs + have al_x : Aligned (cslotAddrA cte) := hO.al0 hx + have al_x8 : Aligned (wa (cslotAddrA cte) 8#u64) := hO.al hx (k := 8#u64) (by simp) (by simp) + have hpa : ptr.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd UP.al + have wS := writesIn_setCapA al_x al_x8 hsc + obtain ⟨PtJ, UbJ, vrJ, -, -, -, -, -, -, linkJ, -, -, -, -, R7⟩ := J.j7 + obtain ⟨PpJ, TbJ, HrJ, TeJ, KtJ, LvJ, ReJ, bitsJ, R2J, -, -⟩ := R7 + have hH12 : H ptr = some (.other 12) := by + have hunm : UnmCap (capA st s (cslotAddrA cte)) ptr 4096 := Or.inl ⟨rfl, asid0, va0, hco⟩ + obtain ⟨z, hz, hh⟩ := R2J.core.lookup.vh.1 _ hx ptr 4096 hunm + have hz12 : z = 12 := Nat.pow_right_injective (le_refl 2) (hz.symm.trans (by norm_num)) + rw [hz12] at hh + exact hh + obtain ⟨Ac', hsys, hsy, hbx, hus, hj7⟩ := fin xc _ _ hkx hmemD hperfV + have vo : VrOK H.omega H.frame H.scs H.scBits OS Z.V ∅ (L.ksb s) (utVsPtA st Pp Tb Lv s) := J.vsOk + have hN := bxi_nodes E1.sys.ent.bxi + have hnul1 : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s1 y = .Null := J1.j5.2.2 + have hTr1 : TreeA st OS Z.G.chains Z.G.par s1 := + J1.j.1.cdt.tree.grow J1.j5.2.1 (fun x hx hn => J1.j5.2.2 x hx hn) + have hok : CapObjOkA Z (.PageTable ptr true vasid base) := + ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), + fun _ _ _ h => (by cases h), trivial⟩ + have hM : MapAlikeA (.PageTable ptr true vasid base) (capA st s1 (cslotAddrA cte)) := by rw [c1]; exact .pt .. + have hirq : CapOkA (stUpdA σ σ.curThread xc .restart).interruptIrqNode cte + (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, base.bv)))) := by + refine ⟨fun irq hlt e => ?_, fun ⟨_, _, _, _, e⟩ => by cases e⟩ + have obj : ∃ o ac, (stUpdA σ σ.curThread xc .restart).kheap cte.1 = some o ∧ + Fl4SpecA64.capOf o cte.2 = some ac ∧ CapRelA (capAtA (L.mem s1) (cslotAddrA cte)) ac := by + obtain ⟨o, idx⟩ := cte + obtain ⟨p0, e1, hc | ⟨ht, i0, hi0, e2⟩⟩ := hab + · simp only at e1 hc; subst e1 + obtain ⟨cs, hk0, -, hr⟩ := J1.j.1.st.cnode p0 _ hc + obtain ⟨ac, hac, hrel⟩ := hr idx rfl + exact ⟨_, ac, hk0, hac, hrel⟩ + · simp only at e1 e2; subst e1 e2 + obtain ⟨y, hk0, hr⟩ := J1.j.1.st.tcb p0 ht + obtain ⟨ac, hac, hrel⟩ := hr i0 hi0 + refine ⟨_, ac, hk0, hac, ?_⟩ + unfold cslotAddrA; rw [ofBl_tcbIdx i0 (by unfold tcbSlotsA at hi0; omega)]; exact hrel + obtain ⟨o, ac, hko, hco', hrel⟩ := obj + have c1' : capAtA (L.mem s1) (cslotAddrA cte) = .PageTable ptr false asid0 va0 := c1 + rw [e] at hko + rw [c1'] at hrel + rcases J1.sinv.irqN.slot irq hlt o _ ac hko hco' with rfl | ⟨_, _, _, rfl⟩ + · cases hrel.2 + · cases hrel.2 + have hsci : NoIdleCapV m n (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT + (some (asidOfA vasid, base.bv)))) := + ⟨fun _ _ e => (by cases e), fun _ e => (by cases e), + fun _ _ _ e => by + cases e + exact fun h => by have h2 : base.val < 2 ^ 48 := h.2; omega⟩ + -- the written word is in a window page: the shared tail + have hv0 : ew ≠ 0#u64 := fun h => by rw [h] at hv3; exact absurd hv3 (by decide) + have coreK : ∀ (q j : U64), XqA Z q → j.val < 512 → q.val % 4096 = 0 → q ≠ ptr → lu.slot = peAF q j → + (∀ (Pt : Set U64), (∀ p, SchedPageA st Z OS s1 p → p ∈ Pt) → + (∀ u ∈ OS, u ≠ cslotAddrA cte → capA st (L.wr s2 (peAF q j) ew) u = capA st s1 u) → + capA st (L.wr s2 (peAF q j) ew) (cslotAddrA cte) = .PageTable ptr true vasid base → + (∀ p0 ∈ Pt, ∀ i : U64, i.val < 512 → peAF p0 i ≠ peAF q j → + L.mem (L.wr s2 (peAF q j) ew) (peAF p0 i) = L.mem s1 (peAF p0 i)) → + L.mem (L.wr s2 (peAF q j) ew) (peAF q j) = ew → + L.ksb (L.wr s2 (peAF q j) ew) = L.ksb s1 → L.cpu (L.wr s2 (peAF q j) ew) = L.cpu s1 → + UnmPtSpecA st Z' m OS (L.wr s2 (peAF q j) ew) (extSlotWriteX σ2 pos.slot pte)) → + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) + (Ac'' Tb' : Set U64) (Lv' : U64 → Nat) (nL' : Nat), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with S1 := insert ptr Z.S1, Lv := Function.update Z.Lv ptr nL' } H OS U Ac'' Pp Tb' Lv' ia ie N E + Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) (L.wr s2 lu.slot ew) a σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + intro q j hq hj hqal hqne hlu hunm + rw [hlu] at hsys hsy hbx hus hj7 ⊢ + have hal : Aligned (peAF q j) := peAF_alignedA hqal hj + have J3 : JAtZAX (L := L) AR Z' (L.wr s2 (peAF q j) ew) a (extSlotWriteX σ2 pos.slot pte) m := by + rw [← hlu]; exact hJ3 + have hks2 := hksb2 + have hA : ¬ AsW (L.ksb s2) (peAF q j) := by rw [hksb2]; exact XqA.offAs hT hj hq + have hks3 : L.ksb (L.wr s2 (peAF q j) ew) = L.ksb s := (L.ksb_wr _ _ _).trans hks2 + have hcpu3 : L.cpu (L.wr s2 (peAF q j) ew) = L.cpu s := (L.cpu_wr _ _ _).trans hcpu2 + have wP : WritesIn st s2 (L.wr s2 (peAF q j) ew) (fun b => b = peAF q j) := writesIn_wr hal + have hAsK : ∀ b, AsW (L.ksb s) b → L.mem (L.wr s2 (peAF q j) ew) b = L.mem s b := by + intro b hb + have hb1 : Aligned b := vo.al b (Or.inr hb) + have hns : ¬ SlotWordA (cslotAddrA cte) b := fun h => vo.os b (Or.inr hb) (slotWord_inOS hO hx h) + have hvsR := RS.vs b (Or.inr hb) + rw [mem_wr_ne' hal hb1 (fun e => hA (by rw [e, hks2]; exact hb)), wS.mem_eq hb1 hns, ← hs1, + mem_wr_ne' sA hb1 (Ne.symm hvsR.2)] + have htbl : ∀ o : U64, 772352 ≤ o.val → o.val < 773376 → o.val % 8 = 0 → + L.mem (L.wr s2 (peAF q j) ew) (wa (L.ksb (L.wr s2 (peAF q j) ew)) o) ≠ 0#u64 → + L.mem (L.wr s2 (peAF q j) ew) (wa (L.ksb (L.wr s2 (peAF q j) ew)) o) ∈ Pp := by + intro o h1 h2 h8 hne + have e : L.mem (L.wr s2 (peAF q j) ew) (wa (L.ksb (L.wr s2 (peAF q j) ew)) o) = + L.mem s (wa (L.ksb s) o) := by + rw [hks3]; exact hAsK _ ⟨o, h1, h2, h8, rfl⟩ + rw [e] at hne ⊢ + exact (J.sys.ent.vs.tbl o h1 h2 h8 hne).1 + obtain ⟨T, LvR, hty, hvok⟩ := vsPost_of_j7A (S1 := insert ptr Z.S1) hj7 htbl + have hbufv : ∀ b, BufW Bf b → ¬ VsR (L.ksb (L.wr s2 (peAF q j) ew)) + (utVsPtA st Pp (insert ptr Z.S1 ∪ T) LvR (L.wr s2 (peAF q j) ew)) b := by + have x : L.mem (L.wr s2 (peAF q j) ew) (peAF q j) = ew := L.mem_wr_same hal + refine bufVs_leafA (x := peAF q j) (r := ptr) J.bufOff J.bufVs J.sys.ent.vs hty hks3 hAsK + (fun b hb ne => ?_) ?_ (fun _ h => ?_) (fun h => ?_) (fun _ => ?_) (fun j' hj' => ?_) + · have hb1 : Aligned b := vo.al b hb + have hns : ¬ SlotWordA (cslotAddrA cte) b := fun h => vo.os b hb (slotWord_inOS hO hx h) + have hvsR := RS.vs b hb + rw [mem_wr_ne' hal hb1 (Ne.symm ne), wS.mem_eq hb1 hns, ← hs1, mem_wr_ne' sA hb1 (Ne.symm hvsR.2)] + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr + ⟨_, hx, Or.inl ⟨_, _, _, hco⟩⟩)))))) + · rw [x, hv3] at h + exact absurd h (by decide) + · rw [x, hv3] at h + exact absurd h (by decide) + · rw [x, ← hdTab] + unfold vspace.ADDR_MASK dTabA dAddrA layout.PPTR_BASE + rfl + · have hne : peAF q j ≠ peAF ptr j' := fun e => + hqne (peAF_injA hqal hpa hj hj' e).1 + rw [mem_wr_ne' hal (peAF_alignedA hpa hj') hne, hmem2 j' hj'] + exact UP.inv j' hj' + have main := JStage3A.of_capVsFrameGA (J := J1) + (hS := fun q0 hq0 => by + refine ⟨Set.mem_insert_of_mem _ hq0.1, ?_⟩ + by_cases e : q0 = ptr + · subst e; rw [Function.update_self]; omega + · rw [Function.update_of_ne e]; exact hq0.2) + (hT2 := fun _ _ _ _ _ _ _ h => h) + (hpt := fun q0 _ _ h => by + injection h with h1 + subst h1 + exact Or.inl ⟨Set.mem_insert _ _, by rw [Function.update_self]; omega⟩) (S1' := insert ptr Z.S1) (T2' := Z.T2) + (Zl' := Function.update Z.Lv ptr nL) (Sh2' := Z.Sh2) (Tb' := insert ptr Z.S1 ∪ T) (Lv' := LvR) + (Q := fun s' a' σ'' hw => s' = L.wr s2 (peAF q j) ew ∧ a' = a ∧ σ'' = extSlotWriteX σ2 pos.slot pte ∧ hw = Z.hw) + RS.sub (footNOff_ksA rfl rfl (footN_offA E1)) (footNAl_ksA rfl rfl (FootNA.aligned E1.j.1 hN E1.scAl E1.ap.vcAl)) + cte hab hEnc hca hTr1 hnul1 (fun h => by cases h) (by rw [c1]; exact fun h => by cases h) hM hok hirq hsci + (fun s2' σ2' hs2 hσ2' HSs' wc jx hcx => by + have es : s2' = s2 := okinj (hs2.symm.trans hsc) + subst es + have eσ : σ2' = σ2 := setCap_detA hσ2' hσ2 + subst eσ + obtain ⟨Pt, Ub, vr, -, -, -, -, -, -, link, -, -⟩ := J1.j7 + obtain ⟨Qb, Rb, q0⟩ := J1.sys.ent.bxi.1 + have vP : VsR (L.ksb s1) Pt (peAF q j) := vsW_pageA link hq.sched hj + have offT : ∀ t ∈ Z.T, (peAF q j).val < t.val ∨ t.val + 4096 ≤ (peAF q j).val := fun t ht => by + have hth : t ∈ H.tcbs := by rw [J1.tcbs]; exact ht + exact (q0.omega _ (vr.om _ vP)).2.1 t hth + have osk3 : OSKeep st OS s2' (L.wr s2' (peAF q j) ew) := + osKeep_ofA hO fun w' hw' hin => wP.mem_eq hw' (fun e => vr.os w' (e ▸ vP) hin) + obtain ⟨hcx', hco2⟩ := capA_setCapA hO hx hEnc hs2 + have hnew : capA st (L.wr s2' (peAF q j) ew) (cslotAddrA cte) = .PageTable ptr true vasid base := by + rw [osk3.capA hx, hcx'] + have hkeep : ∀ u ∈ OS, u ≠ cslotAddrA cte → + capA st (L.wr s2' (peAF q j) ew) u = capA st s1 u := fun u hu e => by + rw [osk3.capA hu, hco2 u hu e] + have hMs2 : ∀ u ∈ OS, MapAlikeA (capA st s2' u) (capA st s1 u) := fun u hu => by + by_cases e : u = cslotAddrA cte + · subst e; rw [hcx']; exact hM + · rw [hco2 u hu e]; exact .refl _ + have sbS : ∀ t ∈ Z.T, sbWordA t ∈ OS := fun t ht => + RS.sub _ ⟨t, Or.inr ⟨(J1.j.1.thT t).2 ht, 2, by simp [tcbSlotsA], (bufSlot_eqA t).symm⟩⟩ + have wA : WritesIn st s1 s2' (fun b => Aligned b ∧ W7.CapW H.tcbs {b | InOS OS b} ∅ b) := writesIn_alAG wc + have hB : ∀ b, (Aligned b ∧ W7.CapW H.tcbs {b | InOS OS b} ∅ b) → W7.CapW H.tcbs H.omega H.frame b := + fun b hb => os_capw hO hb.1 hb.2 + obtain ⟨-, -, -, -, -, fld, -, -⟩ := W7.blk_of_capw (BXI.blk J1.sys.ent.bxi) wA hB + have ib : ∀ t ∈ Z.T, L.mem s2' (ibWordA t) = L.mem s1 (ibWordA t) := fun t ht => + fld t (by rw [J1.tcbs]; exact ht) 3512#u64 (by simp) (by simp) (by simp) + obtain ⟨HS2, hdp⟩ := extWrite_vsA σ2' pos.slot pte + have tw : ∀ t ∈ Z.T, ∀ K : U64, K.val + 8 ≤ 4096 → K.val % 8 = 0 → + L.mem (L.wr s2' (peAF q j) ew) (wa t K) = L.mem s2' (wa t K) := by + intro t ht K hK' h8 + have hta := J1.sr.core.tcbs t ht + have hvv : (wa t K).val = t.val + K.val := field_val hta (K := K) (by omega) + refine wP.mem_eq (field_aligned hta (by omega) h8) (fun e => ?_) + have := offT t ht + rw [← e] at this + omega + have hib : ∀ t ∈ Z.T, IbSame (L := L) s2' (L.wr s2' (peAF q j) ew) t := fun t ht => by + refine ⟨tw t ht _ (by simp) (by simp), ?_, ?_⟩ + · rw [sbWordA_eq]; exact tw t ht _ (by simp) (by simp) + · rw [sbWordA8_eq]; exact tw t ht _ (by simp) (by simp) + have hj7' := hj7 + obtain ⟨Pt', Ub', vr', -, ac', -⟩ := hj7' + have hBw : ∀ b, (SlotWordA (cslotAddrA cte) b ∨ b = peAF q j) → + L.Free s1 H.omega Z.Cs b ∨ W7.TLow H.tcbs b := fun b hb => by + rcases hb with hsl' | rfl + · have hal' : Aligned b := by rcases hsl' with rfl | rfl; exact al_x; exact al_x8 + exact (os_capw hO hal' (Or.inr ⟨slotWord_inOS hO hx hsl', Set.notMem_empty _⟩)).elim Or.inr + fun h' => Or.inl (Or.inl h'.1) + · exact Or.inl (Or.inl (vr.om _ vP)) + have hsp : ∀ q', SchedPageA st { Z with S1 := insert ptr Z.S1, Lv := Function.update Z.Lv ptr nL } OS + (L.wr s2' (peAF q j) ew) q' → SchedPageA st Z OS s1 q' := + fun q' h => SchedPageA.backPtMapA hx c1 hnew hkeep h + have hks31 : L.ksb (L.wr s2' (peAF q j) ew) = L.ksb s1 := hks3.trans hks1.symm + have hcpu31 : L.cpu (L.wr s2' (peAF q j) ew) = L.cpu s1 := hcpu3.trans hcpu1.symm + have G := JStage3A.keepGhostA (hw := Z.hw) (s' := L.wr s2' (peAF q j) ew) J1 hks31 hcpu31 + have hptr : ptr ∈ Pt := link ptr (by + unfold SchedPageA + exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨_, hx, Or.inl ⟨_, _, _, c1⟩⟩))))))) + have hptrV : ∀ j' : U64, j'.val < 512 → VsR (L.ksb s1) Pt (peAF ptr j') := fun j' hj' => + Or.inl ⟨ptr, hptr, core.num.U64.wrapping_mul j' 8#u64, by rw [wm8_valA hj']; omega, + by rw [wm8_valA hj']; omega, rfl⟩ + have hvsF : ∀ b, VsFootA Z.Pp (insert ptr Z.S1) Z.Y (L.ksb s1) b → + VsFootA Z.Pp Z.S1 Z.Y (L.ksb s1) b ∨ ∃ j' : U64, j'.val < 512 ∧ b = peAF ptr j' := by + intro b hb + cases hb with + | asid j' hj' => exact Or.inl (.asid j' hj') + | pool q0' j' hq hj' => exact Or.inl (.pool q0' j' hq hj') + | pt q0' j' hq hj' => + rcases Set.mem_insert_iff.1 hq with rfl | hq + · exact Or.inr ⟨j', hj', rfl⟩ + · exact Or.inl (.pt q0' j' hq hj') + | high q0' j' hq hj' => exact Or.inl (.high q0' j' hq hj') + have h12 : ∃ q0' z, H q0' = some (.other z) ∧ q0'.val ≤ ptr.val ∧ ptr.val + 4096 ≤ q0'.val + 2 ^ z := + ⟨ptr, 12, hH12, le_refl _, by norm_num⟩ + have hword : ∀ p0 ∈ Pt, ∀ i : U64, i.val < 512 → peAF p0 i ≠ peAF q j → + L.mem (L.wr s2' (peAF q j) ew) (peAF p0 i) = L.mem s1 (peAF p0 i) := fun p0 hp0 i hi hne => by + have hv : VsR (L.ksb s1) Pt (peAF p0 i) := Or.inl ⟨p0, hp0, core.num.U64.wrapping_mul i 8#u64, + (wm8_offA hi).1, (wm8_offA hi).2, rfl⟩ + have hbal : Aligned (peAF p0 i) := vr.al _ hv + have hns : ¬ SlotWordA (cslotAddrA cte) (peAF p0 i) := fun h => vr.os _ hv (slotWord_inOS hO hx h) + exact (wP.mem_eq hbal hne).trans (wS.mem_eq hbal hns) + have hU9 := hunm Pt link hkeep hnew hword (L.mem_wr_same hal) hks31 hcpu31 + refine ⟨_, a, extSlotWriteX σ2' pos.slot pte, Z.hw, fun b => b = peAF q j, Ac', + ⟨wP, fun Pt'' Ub'' vr'' link'' b e => by rw [e]; exact vsW_pageA link'' hq.sched hj, + fun b e hbuf => J1.bufOff.page b hbuf q hq.sched (core.num.U64.wrapping_mul j 8#u64) + (by rw [wm8_valA hj]; omega) (by rw [wm8_valA hj]; omega) (by rw [e]; rfl), + HS2, rfl, hdp, J3, + ⟨⟨J1.sys.ent.heap, hbx, hO, hus, hty, by rw [hks3]; exact E0.sys.ent.ksw⟩, hsys⟩, hvok, hbufv, + W7.inv_of_capw J1.sq (wS.trans wP) hBw, ac'.case.po, ?_, ?_, hU9, + ⟨J1.bufOff.os, fun b hb hf => ?_, fun b hb q' hq' => J1.bufOff.page b hb q' (hsp q' hq'), + J1.bufOff.vcw, + fun bp hbp => (J1.bufOff.pin bp hbp).keepF fun t ht hO' _ _ r x1 x2 x3 x4 e => + ⟨ht, hO', r, x1, x2, x3, x4, by + rw [hkeep _ hO' (fun e1 => by rw [e1, c1] at e; cases e)]; exact e⟩⟩, + J7A.growPtMapA hx hnew (fun _ h => h) hj7, + fun h p0 bytes hp0 => h p0 bytes (JointObjectA.shrinkS1A hH12 hp0), + fun h => ⟨h.vcpu, h.reply, h.asid, h.tvcpu, h.vcDeadRun, h.replyTcb⟩, + fun h => ⟨fun u hu q0' b0 fi hc p0 bytes hp0 => + h.obj u hu q0' b0 fi hc p0 bytes (JointObjectA.shrinkS1A hH12 hp0), h.ks, h.idle, h.sep⟩, + fun h => h, + ⟨G.1.sca, G.1.irqSt, G.1.vcAl, G.1.vc, fun b hb => ?_, G.1.ext⟩, Set.subset_union_left, + fun p0 hp0 => ?_, ⟨fun p0 hp0 => ?_, G.2.2.1.roots⟩, fun b hb => ?_, fun q0' hq0' => ?_, + ⟨fun q0' hq0' j' hj' hf => G.2.2.2.2.2.mem q0' hq0' j' hj' (FootA.monoA + (Z := extZA { Z with hw := Z.hw, S1 := insert ptr Z.S1, Lv := Function.update Z.Lv ptr nL }) + rfl rfl (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) + (fun _ h => h) (fun _ h => h) (fun _ h => h) hf), G.2.2.2.2.2.obj⟩, hsy⟩, + rfl, rfl, rfl, rfl⟩ + · exact BufCover.vsA (BufCover.mapA J1.bufCover J1.bufNative J1.j.1.st jx.1.st + (fun t ht => (J1.j.1.thT t).2 ht) HSs' ib (fun t ht => hMs2 _ (sbS t ht))) HS2 hib + · exact BufNativeA.mapA J1.bufNative (fun t ht q' sz' rr dv' m' e' a'' v' h => by + by_cases e1 : sbWordA t = cslotAddrA cte + · rw [e1, hnew] at h; cases h + · rw [hkeep _ (sbS t ht) e1] at h + have hn := J1.bufNative t ht + rw [bufSlot_eqA, capAtA_eq (st := st), h] at hn + exact hn) + · rw [hks31] at hf + rcases hvsF b hf with hf | ⟨j', hj', e⟩ + · exact J1.bufOff.vs b hb hf + · exact J1.bufOff.page b hb ptr (by + unfold SchedPageA + exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨_, hx, Or.inl ⟨_, _, _, c1⟩⟩))))))) + (core.num.U64.wrapping_mul j' 8#u64) (by rw [wm8_valA hj']; omega) (by rw [wm8_valA hj']; omega) + (by rw [e]; rfl) + · rw [hks31] at hb + rcases hvsF b hb with hf | ⟨j', hj', e⟩ + · have := G.1.vs b (by rw [hks31]; exact hf) + exact this + · subst e + exact ⟨fun h => UP.os j' hj' h, fun t ht => UP.tcb j' hj' t ht⟩ + · rcases hp0 with hp0 | hp0 + · exact J1.ptH p0 (Or.inl hp0) + · rcases Set.mem_insert_iff.1 hp0 with rfl | hp0 + · exact h12 + · exact J1.ptH p0 (Or.inr hp0) + · rcases hp0 with ((hp0 | hp0) | hp0) | hp0 + · exact G.2.2.1.pages p0 (Or.inl (Or.inl (Or.inl hp0))) + · rcases Set.mem_insert_iff.1 hp0 with rfl | hp0 + · exact h12 + · exact G.2.2.1.pages p0 (Or.inl (Or.inl (Or.inr hp0))) + · exact G.2.2.1.pages p0 (Or.inl (Or.inr hp0)) + · exact G.2.2.1.pages p0 (Or.inr hp0) + · rw [hks31] at hb + rcases hvsF b hb with hf | ⟨j', hj', e⟩ + · exact J1.vsVc b hf + · rw [e]; exact vr.vc _ (hptrV j' hj') + · rcases Set.mem_insert_iff.1 hq0' with e | hq0' + · rw [e]; exact TabOffA.regrowA hks3 hcpu3 ((J.unmPt.pt _ hx ptr asid0 va0 hco).off) + · exact TabOffA.regrowA hks31 hcpu31 (J1.tabS1 q0' hq0')) + obtain ⟨_, _, s3', a3', σ3', hw, P, Ac'', -, hσk, HSsk, HSvk, -, -, Jf, e1, e2, e3, e4⟩ := main + subst e1 e2 e3 e4 + exact ⟨_, _, _, Ac'', insert ptr Z.S1 ∪ T, LvR, nL, hkx, hset, hmemD, hperfV, Jf, + (Sched.BodyKeepA.ofSlot HSsk (setCap_keepsA hσk).2.2).trans (Sched.BodyKeepA.ofVs HSvk)⟩ + -- the two places the descriptor can be written + rcases hslR with ⟨t, i, ⟨⟨ht, h1t, hst'⟩, hreach⟩, hi, hluEq, hslEq⟩ | ⟨y, j, hy, hyr, hj, hluEq, hslEq, hshEq⟩ + · have hj7c := hj7 + rw [hluEq] at hj7c + have hne : t ≠ ptr := fun e => UP.nt (e ▸ ht) + refine coreK t i (Or.inr (Or.inr ht)) hi (R0.al_mod ht) hne hluEq ?_ + intro Pt link hkeep hnew hword hv' hk31 hcpu31 + have hz : ∀ u ∈ OS, ∀ q, ((∃ a w, capA st (L.wr s2 (peAF t i) ew) u = .PageTable q false a w) ∨ + ∃ a, capA st (L.wr s2 (peAF t i) ew) u = .Pml4 q false a) → q ≠ t := by + intro u hu q hc e + subst e + apply hv0 + obtain ⟨_, _, -, -, -, -, -, -, -, -, -, -, -, -, R7f⟩ := hj7c + obtain ⟨_, _, _, _, _, _, _, _, R2f, -, -⟩ := R7f + have ho : (core.num.U64.wrapping_mul i 8#u64).val < 4096 ∧ + (core.num.U64.wrapping_mul i 8#u64).val % 8 = 0 := by rw [wm8_valA hi]; omega + rw [← hv'] + rcases hc with ⟨a', w', hc⟩ | ⟨a', hc⟩ + · exact R2f.core.lookup.zr u hu q 4096 (Or.inl ⟨rfl, a', w', hc⟩) _ ho.1 ho.2 + · exact R2f.capRefs.nativeEmpty u hu q a' hc _ ho.1 ho.2 + have keepC : ∀ u ∈ OS, ∀ c, capA st (L.wr s2 (peAF t i) ew) u = c → (∀ q a w, c = .PageTable q false a w ∨ + c = .Pml4 q false a ∨ c = .Ept q 0#u64 false a w ∨ c = .HighVSpace q false a → capA st s1 u = c) := by + intro u hu c hc q a' w hk0 + by_cases e : u = cslotAddrA cte + · subst e + rw [hnew] at hc + rw [← hc] at hk0 + rcases hk0 with h | h | h | h <;> cases h + · rw [← hkeep u hu e]; exact hc + obtain ⟨tp1, kp1, -⟩ := R0.pt t ht + have hpk1 : (stUpdA σ σ.curThread xc .restart).kheap (specPtr t) = some (.archObj (.pageTable tp1)) := + stUpd_keep hkx kp1 (fun _ h => by cases h) + refine UnmPtSpecA.ofOneTableA (Z := Z) (Z' := Z') (Pt := Pt) (p := t) (i := i) (R0.al_mod ht) hi + J.j.1.ext.xal R0.yal + (fun r hr e => (J.j.1.ext.pgd _ (Or.inr ⟨r, hr, Or.inr rfl⟩)).1 (Or.inr (Or.inl (e ▸ ht)))) + (fun y hy e => R0.ytb y hy (e ▸ ht)) (fun u hu => ?_) (fun u hu q a' w hc => ?_) + (fun u hu q a' hc => ?_) keepC hword link (fun q h => TabOffA.regrowA hk31 hcpu31 h) + (fun q ao hne' h => ?_) hpk1 (fun u hu q a' hc => ?_) + (fun r hr e => (J.j.1.ext.pgd _ (Or.inr ⟨r, hr, Or.inl rfl⟩)).1 (Or.inr (Or.inl (e ▸ ht)))) J1.unmPt + · by_cases hs0 : IsSlotA Z.th u + · exact J1.j.capObj hs0 + · rw [hnul1 u hu hs0] + exact CapObjOkA.null Z + · by_cases e : u = cslotAddrA cte + · subst e + rw [c1] at hc + injection hc with h1 + subst h1 + exact ⟨hpa, hne.symm⟩ + · have hc3 : capA st (L.wr s2 (peAF t i) ew) u = .PageTable q false a' w := by rw [hkeep u hu e]; exact hc + refine ⟨?_, hz u hu q (Or.inl ⟨a', w, hc3⟩)⟩ + rw [hOS1.capA hu] at hc + have hunm' : UnmCap (capA st s u) q 4096 := Or.inl ⟨rfl, a', w, hc⟩ + obtain ⟨z, hzz, hh⟩ := R2J.core.lookup.vh.1 u hu q 4096 hunm' + have hz12 : z = 12 := Nat.pow_right_injective (le_refl 2) (hzz.symm.trans (by norm_num)) + have := J.sys.ent.heap.align q _ hh + rw [hz12] at this + exact this + · have hs0 : IsSlotA Z.th u := Classical.byContradiction fun h => by rw [hnul1 u hu h] at hc; cases hc + have hok0 : CapObjOkA Z (capA st s1 u) := J1.j.capObj hs0 + rw [hc] at hok0 + exact R0.al_mod (hok0.2.2.2.1 q false a' rfl).1 + · rw [kheap_writeX (by rw [hslEq, slotObjPtE (R0.al_mod ht) hi]; exact hne')] + exact HS.keep h (fun _ _ e => by cases e) (fun _ e => by cases e) + · by_cases e : u = cslotAddrA cte + · subst e; rw [c1] at hc; cases hc + · exact hz u hu q (Or.inr ⟨a', by rw [hkeep u hu e]; exact hc⟩) + · have hym : (wa y 4096#u64).val % 4096 = 0 := waWin_modA (R0.yal y hy) + refine coreK (wa y 4096#u64) j (Or.inr (Or.inl ⟨y, hy, rfl⟩)) hj hym (UP.ytb y hy) hluEq ?_ + intro Pt link hkeep hnew hword hv' hk31 hcpu31 + have keepC : ∀ u ∈ OS, ∀ c, capA st (L.wr s2 (peAF (wa y 4096#u64) j) ew) u = c → (∀ q a w, + c = .PageTable q false a w ∨ c = .Pml4 q false a ∨ c = .Ept q 0#u64 false a w ∨ + c = .HighVSpace q false a → capA st s1 u = c) := by + intro u hu c hc q a' w hk0 + by_cases e : u = cslotAddrA cte + · subst e + rw [hnew] at hc + rw [← hc] at hk0 + rcases hk0 with h | h | h | h <;> cases h + · rw [← hkeep u hu e]; exact hc + have uniq : ∀ y', ActiveHighRootA (L.mem s) (L.ksb s) Z.Pp y' → ∀ u ∈ OS, ∀ a', capA st s u = .HighVSpace y' false a' → + False := by + intro y' ⟨asid0', raw, ⟨hi', lo, hhi, hlo, hasid, pool, hpool, hpne, htab, hw, hrne⟩, htag, hun⟩ u hu a' hc' + obtain ⟨_, _, _, -, -, -, -, -, -, -, -, -, -, -, r2⟩ := J.j7 + obtain ⟨PpJ', _, _, _, _, _, _, _, R2, -, -⟩ := r2 + have hksF : (L.ksb s).val + 788736 ≤ 2 ^ 64 := by + have := J.sr.ksFit + unfold ksSizeA at this + omega + have hP : pool ∈ PoolSet st Z.Pp s := PoolSet.ofActiveA hpool ⟨hpne, hi', hhi, htab⟩ hksF + have hP7 : pool ∈ PoolSet st PpJ' s := by + obtain ⟨-, o, h1, h2, h3, h4, h5⟩ := hP + rw [← h4] + have hty : VsTyR st (L.ksb s) (PoolSet st Z.Pp s) ∅ Tb Lv s := by rw [J.pp]; exact J.sys.ent.vs + exact R2.core.stage1.tbl o h1 h2 h3 (by rw [h4]; exact h5) + have act : ActiveAsidRoot st PpJ' s asid0' raw := by + have h127 : (hi' &&& 127#u64) = hi' := UScalar.eq_of_val_eq (by + rw [and_maskA hi' 7 _ rfl]; exact Nat.mod_eq_of_lt (by omega)) + have hat : wa (L.ksb s) (AtOff hi') = atAF (L.ksb s) hi' := by unfold AtOff atAF; rw [h127] + have ho : (core.num.U64.wrapping_mul lo 8#u64).val = 8 * lo.val := wm8_valA hlo + exact ⟨hi', core.num.U64.wrapping_mul lo 8#u64, hhi, by omega, by omega, by omega, pool, hP7, + by rw [hat]; exact htab, hw, hrne⟩ + obtain ⟨x', hx', cap⟩ := R2.core.root.backed asid0' raw act + have t2 : raw &&& 3#u64 = 2#u64 := UScalar.eq_of_val_eq (by rw [and3_valA]; exact htag) + rcases cap with ⟨bad, -⟩ | ⟨bad, -⟩ | ⟨-, cap⟩ + · rw [t2] at bad; exact absurd bad (by decide) + · rw [t2] at bad; exact absurd bad (by decide) + have er : raw &&& ~~~3#u64 = y' := hun + rw [er] at cap + have e := R2.capRefs.unique u hu x' hx' (3, y') (by rw [hc']; rfl) (by rw [cap]; rfl) (by rw [hc']; rfl) + rw [e, hc'] at cap + cases cap + refine UnmPtSpecA.ofValidWrA (Z := Z) (Z' := Z') (Pt := Pt) (b := peAF (wa y 4096#u64) j) (o := specPtr y) + (.nslot _ (.vs _ (.high y j hy hj))) + (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨y, hy, rfl⟩)))))) keepC hword link + (fun _ _ q _ h => TabOffA.regrowA hk31 hcpu31 h) + (fun q ao hq h => ?_) (fun u hu p a' v hc => ?_) (fun u hu p a' hc => ?_) J1.unmPt + · rw [kheap_writeX (by rw [hslEq]; exact hq)] + exact HS.keep h (fun _ _ e => by cases e) (fun _ e => by cases e) + · have hpX : p ∈ Z.X := (J1.j.capObj (by + by_contra h + rw [hnul1 u hu h] at hc; cases hc)).2.1 p 0#u64 false a' v hc + have pa8 := J1.j.1.ext.xal p hpX + have g1 := J1.j.1.ext.pgd p (Or.inr ⟨p, hpX, Or.inl rfl⟩) + have g2 := J1.j.1.ext.pgd (wa p 4096#u64) (Or.inr ⟨p, hpX, Or.inr rfl⟩) + refine ⟨fun k hk' => ⟨peAF_ne_tabA hym (by have := al4kE pa8; omega) hj hk' + (fun e => g1.1 (Or.inr (Or.inr ⟨y, hy, e⟩))), peAF_ne_tabA hym (by have := al4kHiE pa8; omega) hj hk' + (fun e => g2.1 (Or.inr (Or.inr ⟨y, hy, e⟩)))⟩, fun e => g1.2 (specPtr_inj e ▸ hy)⟩ + · have hpY : p ∈ Z.Y := (J1.j.capObj (by + by_contra h + rw [hnul1 u hu h] at hc; cases hc)).2.2.1 p false a' hc + have ne : p ≠ y := fun e => uniq y hyr u hu a' (by rw [← e, ← hOS1.capA hu]; exact hc) + refine ⟨fun k hk' => peAF_ne_tabA hym (waWin_modA (R0.yal p hpY)) hj hk' (fun e => ne ?_), + fun e => ne (specPtr_inj e)⟩ + refine UScalar.eq_of_val_eq ?_ + have := congrArg UScalar.val e + rw [waWin_valA (R0.yal p hpY), waWin_valA (R0.yal y hy)] at this + omega + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapS2A.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapS2A.lean new file mode 100644 index 000000000..3f401e033 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapS2A.lean @@ -0,0 +1,1036 @@ +/- +P3 (AArch64, Stage 4, line vsx-B, CP B2): **`JStage3A` across a successful `ARMPageTableMap` into a Stage-2 root** +(`JStage3A.ptMapS2A`, at `ept::map_table`). The twin of `P3/Stage3ArmPtMapHiA`: FL4 restarts the thread, rewrites the +invoked cap as mapped (the address is written through `unpack48A`, `set_cap_pt_unpack48A`) and writes one table +descriptor, here into a Stage-2 table (`Z.T2`) or one of a root's two pages. The new table joins **`Z.T2`** with +`Z.Sh2 ptr := lu.shift - 9`; the Stage-1 ghosts are kept. + +* `FootA.growT2A`, `RelPA.growT2A`, `TabOffA.growT2A`, `ExtTabOffA.growT2A`, `SchedPageA.backPtMapS2A`, + `JointObjectA.shrinkT2insA`, `J7A.growPtMapS2A`: the T2 ghost-growth transfers (the Stage-1 twins are in + `P3/Stage3ArmPtMapA`). +* `vspaceForAsid_of_activeS2A`, `activeEptRootA_of_vspaceForAsid`: an active Stage-2 root is an active ASID entry of tag + 1 (to show no unmapped `Ept` cap names it: the J9 clause of a valid root write). + +Named premise [P] `hIpa47 : s2IpaLimit.toNat < 2 ^ 47` (platform bound, satisfiable: the 40-bit IPA of the default +platform): the new table's cap address `base ≤ ipa` is then no mapped Stage-1 page-table cap in `[2^47, 2^48)` +(`NoHiPtV`). New module. +-/ +import Fl4ProofsA64.P3.Stage3ArmPtMapHiA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +/-- A footprint word after listing a table among the Stage-2 tables is an old one or a word of that table. -/ +theorem FootA.growT2A {Z0 : XSetsA} {ptr : U64} {Sh2' : U64 → Nat} {s : S} {w : U64} + (h : FootA (L := L) { Z0 with T2 := insert ptr Z0.T2, Sh2 := Sh2' } s w) : + FootA (L := L) Z0 s w ∨ ∃ j : U64, j.val < 512 ∧ w = peAF ptr j := by + cases h with + | slot y w hy hw => exact Or.inl (.slot y w hy hw) + | nslot w h => + cases h with + | node c w hc hw => exact Or.inl (.nslot w (.node c w hc hw)) + | cur w hw => exact Or.inl (.nslot w (.cur w hw)) + | tcb t w ht hw => exact Or.inl (.nslot w (.tcb t w ht hw)) + | sc c hc => exact Or.inl (.nslot _ (.sc c hc)) + | vcpu v w hv hw => exact Or.inl (.nslot w (.vcpu v w hv hw)) + | irq i hi => exact Or.inl (.nslot _ (.irq i hi)) + | cur2 w hw => exact Or.inl (.nslot w (.cur2 w hw)) + | glob w hw => exact Or.inl (.nslot w (.glob w hw)) + | tcb2 t w ht hw => exact Or.inl (.nslot w (.tcb2 t w ht hw)) + | sc2 c hc => exact Or.inl (.nslot _ (.sc2 c hc)) + | vs w hw => exact Or.inl (.nslot w (.vs w hw)) + | ext w hw => + cases hw with + | s2lo r i hr hi => exact Or.inl (.nslot _ (.ext _ (.s2lo r i hr hi))) + | s2hi r i hr hi => exact Or.inl (.nslot _ (.ext _ (.s2hi r i hr hi))) + | s2pt t i ht hi => + rcases Set.mem_insert_iff.1 ht with rfl | ht + · exact Or.inr ⟨i, hi, rfl⟩ + · exact Or.inl (.nslot _ (.ext _ (.s2pt t i ht hi))) + | wl0 y hy => exact Or.inl (.nslot _ (.ext _ (.wl0 y hy))) + | wlo y i hy hi => exact Or.inl (.nslot _ (.ext _ (.wlo y i hy hi))) + +/-- An object related after listing a table among the Stage-2 tables is an old one or that table. -/ +theorem RelPA.growT2A {Z0 : XSetsA} {ptr : U64} {Sh2' : U64 → Nat} {m : Fl4SpecA64.McState} {q : U64} + (h : RelPA { Z0 with T2 := insert ptr Z0.T2, Sh2 := Sh2' } m q) : RelPA Z0 m q ∨ q = specPtr ptr := by + unfold RelPA at h ⊢ + rcases h with h | h | h | h | h | h | h | h | ⟨t, ht, e⟩ + · exact Or.inl (Or.inl h) + · exact Or.inl (Or.inr (Or.inl h)) + · exact Or.inl (Or.inr (Or.inr (Or.inl h))) + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inl h)))) + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))) + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))))) + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))))) + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))))))) + · rcases Set.mem_insert_iff.1 ht with rfl | ht + · exact Or.inr e.symm + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨t, ht, e⟩)))))))) + +/-- **`TabOffA` of a table other than the new one** after listing a table among the Stage-2 tables. -/ +theorem TabOffA.growT2A {Z : XSetsA} {m : Fl4SpecA64.McState} {s s' : S} {q ptr : U64} {Sh2' : U64 → Nat} + (T : TabOffA (L := L) Z m s q) (hks : L.ksb s' = L.ksb s) (hcpu : L.cpu s' = L.cpu s) + (hq : q.val % 4096 = 0) (hp : ptr.val % 4096 = 0) (hne : q ≠ ptr) : + TabOffA (L := L) { Z with T2 := insert ptr Z.T2, Sh2 := Sh2' } m s' q := by + refine ⟨fun i hi h => ?_, fun q' hq' => ?_⟩ + · have h1 := FootA.of_ksA hks.symm hcpu.symm h + rcases FootA.growT2A (Z0 := { Z with S1 := ∅ }) (ptr := ptr) (Sh2' := Sh2') h1 with h2 | ⟨j, hj, e⟩ + · exact T.mem i hi h2 + · exact hne (peAF_injA hq hp hi hj e).1 + · unfold RelPA at hq' + rcases hq' with h | h | h | h | h | h | h | h | ⟨t, ht, e⟩ + · exact T.obj q' (Or.inl h) + · exact T.obj q' (Or.inr (Or.inl h)) + · exact T.obj q' (Or.inr (Or.inr (Or.inl h))) + · exact T.obj q' (Or.inr (Or.inr (Or.inr (Or.inl h)))) + · exact T.obj q' (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))) + · exact T.obj q' (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))))) + · exact T.obj q' (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))))) + · exact T.obj q' (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))))))) + · rcases Set.mem_insert_iff.1 ht with rfl | ht + · rw [← e]; exact fun h => hne (specPtr_inj h).symm + · exact T.obj q' (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨t, ht, e⟩)))))))) + +/-- **`ExtTabOffA`** after listing a table among the Stage-2 tables, given the table's own `TabOffA`-style facts. -/ +theorem ExtTabOffA.growT2A {Z : XSetsA} {m : Fl4SpecA64.McState} {s s' : S} {ptr : U64} {Sh2' : U64 → Nat} + (T : ExtTabOffA (L := L) Z m s) (hks : L.ksb s' = L.ksb s) (hcpu : L.cpu s' = L.cpu s) + (hnf : ∀ i : U64, i.val < 512 → ¬ FootA (L := L) (extZA Z) s (peAF ptr i)) + (hno : ¬ RelPA (extZA Z) m (specPtr ptr)) : + ExtTabOffA (L := L) { Z with T2 := insert ptr Z.T2, Sh2 := Sh2' } m s' := by + have tr : ∀ w, FootA (L := L) (extZA { Z with T2 := insert ptr Z.T2, Sh2 := Sh2' }) s' w → + FootA (L := L) (extZA Z) s w := fun w h => + FootA.monoA (Z := extZA { Z with T2 := insert ptr Z.T2, Sh2 := Sh2' }) (Z' := extZA Z) rfl rfl + (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) + (fun _ h => h) (FootA.of_ksA hks.symm hcpu.symm h) + refine ⟨fun q hq i hi h => ?_, fun p hp h => ?_⟩ + · rcases hq with (hq | ⟨r, hr, e⟩) | hq + · rcases Set.mem_insert_iff.1 hq with rfl | hq + · exact hnf i hi (tr _ h) + · exact T.mem q (Or.inl (Or.inl hq)) i hi (tr _ h) + · exact T.mem q (Or.inl (Or.inr ⟨r, hr, e⟩)) i hi (tr _ h) + · exact T.mem q (Or.inr hq) i hi (tr _ h) + · rcases hp with hp | hp | hp + · exact T.obj p (Or.inl hp) h + · exact T.obj p (Or.inr (Or.inl hp)) h + · rcases Set.mem_insert_iff.1 hp with rfl | hp + · exact hno h + · exact T.obj p (Or.inr (Or.inr hp)) h + +/-- No scheduler page is added by mapping a page-table cap and listing its table among the Stage-2 tables. -/ +theorem SchedPageA.backPtMapS2A {Z : XSetsA} {OS : Set U64} {s s' : S} {x ptr a0 v0 asid va q : U64} + {Sh2' : U64 → Nat} (hx : x ∈ OS) (hold : capA st s x = .PageTable ptr false a0 v0) + (hnew : capA st s' x = .PageTable ptr true asid va) (hkeep : ∀ u ∈ OS, u ≠ x → capA st s' u = capA st s u) + (h : SchedPageA st { Z with T2 := insert ptr Z.T2, Sh2 := Sh2' } OS s' q) : SchedPageA st Z OS s q := by + have own : SchedPageA st Z OS s ptr := by + unfold SchedPageA + exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨x, hx, Or.inl ⟨_, _, _, hold⟩⟩)))))) + unfold SchedPageA at h + rcases h with h | h | h | h | h | h | h | ⟨u, hu, h⟩ + · exact Or.inl h + · exact Or.inr (Or.inl h) + · rcases Set.mem_insert_iff.1 h with rfl | h + · exact own + · exact Or.inr (Or.inr (Or.inl h)) + · exact Or.inr (Or.inr (Or.inr (Or.inl h))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))))) + · by_cases e : u = x + · subst e + rw [hnew] at h + rcases h with ⟨m, a', v', h⟩ | ⟨m, a', h⟩ | ⟨a', v', h⟩ | ⟨q', a', v', h, -⟩ | ⟨y, a', h, -⟩ + · injection h with h1 + subst h1 + exact own + · cases h + · cases h + · cases h + · cases h + · rw [hkeep u hu e] at h + unfold SchedPageA + exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨u, hu, h⟩)))))) + +/-- A new Stage-2 table that is a heap `other 12` object adds no joint object. -/ +theorem JointObjectA.shrinkT2insA {Z : XSetsA} {H : Heap} {ptr p : U64} {Sh2' : U64 → Nat} {bytes : Nat} + (hH : H ptr = some (.other 12)) (h : JointObjectA { Z with T2 := insert ptr Z.T2, Sh2 := Sh2' } H p bytes) : + JointObjectA Z H p bytes := by + rcases h with ⟨hb, h⟩ | h | h | h + · rcases h with h | h | h | h | h + · exact Or.inl ⟨hb, Or.inl h⟩ + · exact Or.inl ⟨hb, Or.inr (Or.inl h)⟩ + · rcases Set.mem_insert_iff.1 h with rfl | h + · exact Or.inr (Or.inr (Or.inr ⟨_, hH, by rw [hb]; rfl⟩)) + · exact Or.inl ⟨hb, Or.inr (Or.inr (Or.inl h))⟩ + · exact Or.inl ⟨hb, Or.inr (Or.inr (Or.inr (Or.inl h)))⟩ + · exact Or.inl ⟨hb, Or.inr (Or.inr (Or.inr (Or.inr h)))⟩ + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr (Or.inl h)) + · exact Or.inr (Or.inr (Or.inr h)) + +/-- Listing the table of a page-table cap among the Stage-2 tables keeps J7. -/ +theorem J7A.growPtMapS2A {R : Set U64 → JSlotA S} {Z : XSetsA} {H : Heap} {OS : Set U64} {s : S} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} {x ptr asid va : U64} {Sh2' : U64 → Nat} (hx : x ∈ OS) + (hcap : capA st s x = .PageTable ptr true asid va) + (hR : ∀ Pt, R Pt Z H OS s σ m → R Pt { Z with T2 := insert ptr Z.T2, Sh2 := Sh2' } H OS s σ m) + (h : J7A st R Z H OS s σ m) : J7A st R { Z with T2 := insert ptr Z.T2, Sh2 := Sh2' } H OS s σ m := by + obtain ⟨Pt, Ub, vr, pn, ac, cc, vc, df, hi, link, sa, fu, ual, vcu, r⟩ := h + have own : ptr ∈ Pt := link ptr (by + unfold SchedPageA + exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨x, hx, Or.inl ⟨_, _, _, hcap⟩⟩))))))) + refine ⟨Pt, Ub, vr, pn, ac, cc, vc, df, hi, fun p hp => ?_, sa, fu, ual, vcu, hR Pt r⟩ + unfold SchedPageA at hp + rcases hp with h | h | h | h + · exact link p (by unfold SchedPageA; exact Or.inl h) + · exact link p (by unfold SchedPageA; exact Or.inr (Or.inl h)) + · rcases Set.mem_insert_iff.1 h with rfl | h + · exact own + · exact link p (by unfold SchedPageA; exact Or.inr (Or.inr (Or.inl h))) + · exact link p (by unfold SchedPageA; exact Or.inr (Or.inr (Or.inr h))) + +/-- The spec's active Stage-2 root is `vspaceForAsid` of its ASID. -/ +theorem vspaceForAsid_of_activeS2A {σ : Fl4SpecA64.State Unit} {Pp X : Set U64} {r : U64} + (h : ActiveS2RootA Pp X σ r) : ∃ a, 0 < a ∧ Fl4SpecA64.vspaceForAsid a σ = some (specPtr r) := by + obtain ⟨-, asid, p, f, h0, -, ht, hk, hf⟩ := h + refine ⟨asid, h0, ?_⟩ + rw [vspaceForAsid_posA h0, specVsA_eqA ht hk, hf] + rfl + +/-- **An active Stage-2 root is an active ASID entry of tag 1** (the memory form). -/ +theorem activeEptRootA_of_vspaceForAsid {Pp Tb : Set U64} {Lv : U64 → Nat} {X Y : Set U64} {mem : U64 → U64} + {ksb : U64} {σ : Fl4SpecA64.State Unit} (hR : VsRelA Pp Tb Lv X Y mem ksb σ) + (hX : ∀ r ∈ X, ∃ es, σ.kheap (specPtr r) = some (.archObj (.ext (.stage2Root es)))) {a : Fl4SpecA64.Asid} + {r : U64} (hr : r ∈ X) (hv : Fl4SpecA64.vspaceForAsid a σ = some (specPtr r)) : + ∃ asid raw, ActiveAsidRootA mem ksb Pp asid raw ∧ tagA raw = 1 ∧ untagA raw = r := by + obtain ⟨-, raw, hact, hun⟩ := activeAsidRootA_of_vspaceForAsid hR hv + obtain ⟨pool, hP, hactP, lo, hlo, hw, hrne⟩ := hact.activePool + have hk := hR.kind pool hP hactP lo hlo + rw [hw] at hk + rcases hk with rfl | ⟨-, htb, -⟩ | ⟨ht1, -⟩ | ⟨-, hy⟩ + · exact absurd rfl hrne + · rw [hun] at htb + obtain ⟨t, hpt, -⟩ := hR.pt r htb + obtain ⟨es, hes⟩ := hX r hr + rw [hes] at hpt; cases hpt + · exact ⟨_, raw, hact, ht1, hun⟩ + · rw [hun] at hy + obtain ⟨l1, hl1, -⟩ := hR.high r hy + obtain ⟨es, hes⟩ := hX r hr + rw [hes] at hl1; cases hl1 + +set_option maxHeartbeats 8000000 in +/-- **`JStage3A` across a successful `ARMPageTableMap` into a Stage-2 root** (module docstring). -/ +theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {ar : machine.Arch A} {nA : U64} {s s3 : S} {a a3 : A} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) + (hK : Aligned (L.ksb s)) (hT : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s)) (hIpa : S2IpaE ar a) + (hIpa47 : s2IpaLimit.toNat < 2 ^ 47) + (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) {ptr asid0 va0 : U64} + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr false asid0 va0) + (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (hS2 : ptr ∉ S2PgE Z.X Z.T2) (hY : ptr ∉ Z.Y) + (vp vasid vva vaddr : U64) (ha16 : vasid.val < 65536) + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageTableMap (Z := Unit) cte (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .stage2 (specPtr vp) (asidDataA true vasid)) vaddr.bv)).run σ) + (hrt : ept.root st s (.Ept vp 0#u64 true vasid vva) 1#u64 = ok (core.result.Result.Ok (vp, vasid))) + (hres : ept.map_table st ar s a vp vasid vaddr ptr (cslotAddrA cte) = ok (core.result.Result.Ok (), s3, a3)) + (fin : ∀ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit), + σ.kheap σ.curThread = some (.tcb x) → (.ok (.extVSpace iv), σ) ∈ D.1 → + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 → + ∃ Ac' : Set U64, SysL st H Z.Cs OS ia ie s3 ∧ SymL st H Z.Cs s3 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s3 ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s3 ∧ + J7A st (J7R2A st ar nA) Z H OS s3 σ3 m) : + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) + (Ac' Tb' : Set U64) (Lv' : U64 → Nat) (nS : Nat), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with T2 := insert ptr Z.T2, Sh2 := Function.update Z.Sh2 ptr nS } H OS U Ac' Pp Tb' Lv' ia ie N E + Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s3 a3 σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + have E0 := J.toJEntA + have hx : cslotAddrA cte ∈ OS := RS.sub _ (hab.isSlot J.j.1.place) + have hO : OSOK H.tcbs H.omega H.frame OS := J.sys.ent.os + have hTr0 : TreeA st OS Z.G.chains Z.G.par s := + J.j.1.cdt.tree.grow J.j5.2.1 (fun x hx hn => J.j5.2.2 x hx hn) + have hnul0 : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null := J.j5.2.2 + have hX : ∀ r ∈ Z.X, ∃ es, σ.kheap (specPtr r) = some (.archObj (.ext (.stage2Root es))) := + fun r hr => ⟨(E0.j.1.ext.s2root r hr).choose, (E0.j.1.ext.s2root r hr).choose_spec.1⟩ + have hroot0 := ept_rootA E0.j.1.vs hX vp vasid vva 1#u64 true ha16 + rw [hrt] at hroot0 + obtain ⟨-, hrootX, ha1ne, hchkOk⟩ := (WP.spec_ok _).1 hroot0 + have hvs := vspaceForAsid_of_checkExtRootA (by decide) hchkOk + have hactR : ActiveS2RootA Z.Pp Z.X σ vp := activeS2RootA_of_vspaceForAsid E0.j.1.vs hrootX hvs + suffices W : ept.map_table st ar s a vp vasid vaddr ptr (cslotAddrA cte) ⦃ res => + res = (core.result.Result.Ok (), s3, a3) → + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) + (Ac' Tb' : Set U64) (Lv' : U64 → Nat) (nS : Nat), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with T2 := insert ptr Z.T2, Sh2 := Function.update Z.Sh2 ptr nS } H OS U Ac' Pp Tb' Lv' ia ie N E + Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s3 a3 σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 ⦄ by + rw [hres] at W + exact (WP.spec_ok _).1 W rfl + have hD1 : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace (do + NonDetE.whenE (vaddr.bv > s2IpaLimit) (NonDetE.throwError (.invalidArgument 0)) + let pos ← NonDetE.liftE (NonDet.gets fun s : State Unit => extLookupSlot s s2Geom (specPtr vp) vaddr.bv) + let old ← NonDetE.liftE (NonDet.gets fun s : State Unit => pos.slot.read s) + NonDetE.whenE (pos.shift = pageBits ∨ old ≠ .invalidPTE) (NonDetE.throwError .deleteFirst) + NonDetE.returnOk (.map (.pageTableCap (specPtr ptr) .normalPtT + (some (asidOfA vasid, vaddr.bv &&& ~~~(mask pos.shift)))) + cte (.pageTablePTE (ppnFromPptr (specPtr ptr))) pos.slot))).run σ := by + rw [hD]; unfold decodeS2PageTableMap; dsimp only + exact run_liftME_congr_pt (run_bind_okA hchkOk _) + obtain ⟨nIpa, hnIpa, hnvIpa⟩ := hIpa + unfold ept.map_table + rw [hnIpa, bind_ok, s2LimitEq_pt hnvIpa, bind_ok] + by_cases hgt : vaddr > (⟨s2IpaLimit⟩ : U64) + · rw [if_pos hgt] + simp only [error.invalid_arg, bind_ok] + exact (WP.spec_ok _).2 fun h => by cases h + rw [if_neg hgt] + have hgt' : ¬ (vaddr.bv > s2IpaLimit) := hgt + have hle : vaddr.val ≤ s2IpaLimit.toNat := by + have : ¬ (s2IpaLimit.toNat < vaddr.val) := hgt + omega + have hipa48 : vaddr.val < 2 ^ 48 := lt_of_le_of_lt hle s2IpaLimit_lt48_pt + have hipa47 : vaddr.val < 2 ^ 47 := lt_of_le_of_lt hle hIpa47 + let pos := extLookupSlot σ s2Geom (specPtr vp) vaddr.bv + obtain ⟨lu, hlu, hlsh, hslR⟩ := spec_ex_fd (ept_lookup_slot_mapA E0.j.1.ext hrootX hactR hnvIpa vaddr) + have hsl : SlotRelE (G2E Z.T2 Z.Sh2) (TopS2E Z.X) lu.slot pos.slot pos.shift := + hslR.mono (fun _ _ g => g.1) (fun _ _ _ ht => ht.toTopS2E) + rw [hlu, bind_ok] + have hD2 : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace (do + NonDetE.whenE (pos.shift = pageBits ∨ pos.slot.read σ ≠ .invalidPTE) (NonDetE.throwError .deleteFirst) + NonDetE.returnOk (.map (.pageTableCap (specPtr ptr) .normalPtT + (some (asidOfA vasid, vaddr.bv &&& ~~~(mask pos.shift)))) + cte (.pageTablePTE (ppnFromPptr (specPtr ptr))) pos.slot))).run σ := by + rw [hD1] + apply run_liftME_congr_pt + rw [run_bind_okA (by simp only [NonDetE.whenE, if_neg hgt']; rfl)] + rw [run_bind_okA (liftE_gets_pt (fun s : State Unit => extLookupSlot s s2Geom (specPtr vp) vaddr.bv) σ)] + rw [run_bind_okA (liftE_gets_pt (fun s : State Unit => pos.slot.read s) σ)] + have hpb : ept.PAGE_BITS = 12#u64 := by unfold ept.PAGE_BITS; rfl + by_cases h12 : lu.shift = ept.PAGE_BITS + · rw [if_pos h12] + exact (WP.spec_ok _).2 fun h => by cases h + rw [if_neg h12] + have hp12 : pos.shift ≠ pageBits := by + intro h; apply h12; apply UScalar.eq_of_val_eq + rw [hlsh, h, hpb]; rfl + rw [L.read_eq, bind_ok, eq_of_spec_fd P0.Consts.ept.D_VALID.spec, bind_ok] + simp only [lift, bind_ok, valid_bitA] + have hDescRead := extSlotRead_of_s2Slot_pt E0.j.1.ext hslR + by_cases hv : dBitA (L.mem s lu.slot) 0 = true + · rw [if_pos hv] + exact (WP.spec_ok _).2 fun h => by cases h + have hvf : dBitA (L.mem s lu.slot) 0 = false := by simpa using hv + rw [if_neg hv] + have hInvEq : pos.slot.read σ = .invalidPTE := (descRelE_invA hDescRead).2 hvf + have hshCases : pos.shift = 39 ∨ pos.shift = 30 ∨ pos.shift = 21 := by + rcases s2Lookup_shift_pt σ (specPtr vp) vaddr.bv with h | h | h | h + · exact Or.inl h + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr h) + · exact (hp12 h).elim + have hlsh' : lu.shift.val = pos.shift := hlsh + have hs64 : lu.shift.val < 64 := by rcases hshCases with h | h | h <;> omega + have e63 : (lu.shift &&& 63#u64) = lu.shift := + UScalar.eq_of_val_eq (by + rw [and_maskA lu.shift 6 _ rfl]; exact Nat.mod_eq_of_lt (by simp only [Nat.reducePow]; omega)) + rw [e63, CapRt.shl_u64_eq 1#u64 lu.shift hs64, bind_ok] + try simp only [lift, bind_ok] + rw [ws1A lu.shift hs64] + generalize hbase : vaddr &&& ~~~(⟨BitVec.ofNat 64 (2 ^ lu.shift.val - 1)⟩ : U64) = base + have hbv : base.bv = vaddr.bv &&& ~~~(Fl4SpecA64.mask pos.shift) := by + rw [← hbase, ← hlsh, mask_eq_ofNat_pt (by omega)]; rfl + have hbase48 : base.val < 2 ^ 48 := by + rw [← hbase, UScalar.val_and]; exact lt_of_le_of_lt Nat.and_le_left hipa48 + have hbase47 : base.val < 2 ^ 47 := by + rw [← hbase, UScalar.val_and]; exact lt_of_le_of_lt Nat.and_le_left hipa47 + have hcanon : CapRt.Canonical ptr := by + have h : CapRt.EncWf (capAtA (L.mem s) (cslotAddrA cte)) := CapRt.decodeF_encWf _ _ + rw [hcap] at h; exact h.1 + let baseU : U64 := ⟨unpack48A base.bv⟩ + have hEnc : CapRt.EncWf (.PageTable ptr true vasid baseU) := + ⟨hcanon, by omega, unpack48A_canonical hbase48⟩ + have hca : CapRelA (.PageTable ptr true vasid baseU) + (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, base.bv)))) := + ⟨ha16, rfl, rfl, Or.inr ⟨rfl, hbase48⟩⟩ + obtain ⟨xc, s2, σ2, hkx, hst, hset, hsc, hσ2, HS, hksb2, R2, hcpu2, hw2, hJ2, hFr2⟩ := + restart_setcapJA E0 RS cte hab hx hEnc hca + rw [cur_thread_ok, bind_ok, hst, bind_ok, set_cap_pt_unpack48A _ _ _ _ _ _ hbase48, hsc, bind_ok] + rw [show layout.paddr ptr = ok (core.num.U64.wrapping_sub ptr layout.PPTR_BASE) from rfl, bind_ok] + have hpaMod : (core.num.U64.wrapping_sub ptr layout.PPTR_BASE).val % 4096 = 0 := by + rw [ws_valA]; have := Nat.mod_eq_zero_of_dvd UP.al; omega + have hpa48 : (core.num.U64.wrapping_sub ptr layout.PPTR_BASE).val < 2 ^ 48 := by + have := UP.pa; omega + refine WP.spec_bind (s2tab_v _ hpaMod hpa48) fun ew ⟨hv3, hvm⟩ => ?_ + rw [L.write_eq, bind_ok] + refine (WP.spec_ok _).2 fun hEq => ?_ + obtain ⟨-, h23⟩ := Prod.mk.inj hEq + obtain ⟨es3, ea⟩ := Prod.mk.inj h23 + subst es3 + subst ea + have hco : capA st s (cslotAddrA cte) = .PageTable ptr false asid0 va0 := by rw [← capAtA_eq, hcap] + let nS : Nat := pos.shift - 9 + let T2' : Set U64 := insert ptr Z.T2 + let Sh2' : U64 → Nat := Function.update Z.Sh2 ptr nS + let Z' : XSetsA := { Z with T2 := T2', Sh2 := Sh2' } + let pte : PTE := .pageTablePTE (ppnFromPptr (specPtr ptr)) + obtain ⟨J2, hT2⟩ := hJ2 hTr0 hnul0 (by simp) (by rw [hco]; simp) + (UA.of_shapeA (by rw [hco]; rfl) fun h => by rw [hco] at h; simp [isUtA] at h) + ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), + fun _ _ _ h => (by cases h), trivial⟩ + have hmem2 := unm_mem_keep_pt E0.sq.curT + (fun t ht => by have := (E0.sq.tcbs t ht).fits; simp only [Nat.reducePow] at this; exact this) + (by rw [stA_eq]; exact field_aligned (E0.sq.tcbs _ E0.sq.curT) (by simp) (by simp)) UP hw2 + obtain ⟨tp, hkp, htp, hep⟩ := UP.spec + have hkp1 : (stUpdA σ σ.curThread xc .restart).kheap (specPtr ptr) = some (.archObj (.pageTable tp)) := + stUpd_keep hkx hkp (fun _ h => by cases h) + have hkp2 := HS.keep hkp1 (fun _ _ h => by cases h) (fun _ h => by cases h) + have hnp : ptr ∉ Z.Pp := unm_not_pp_pt J2.1.vs hkp2 + have hE2Add : ExtVsRelA Z.Pp Z.S1 Z.X Z.Y T2' Sh2' (L.mem s2) σ2 := + J2.1.ext.addS2PtE hnp UP.nt hS2 hY UP.al UP.ytb (by omega) + (fun i hi => by rw [hmem2 i hi]; exact UP.inv i hi) hkp2 htp hep + have hAlLu : Aligned lu.slot := by + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨r0, j0, hr0, hj0, hluEq, -, -⟩ + · rw [hluEq]; exact peAF_alignedA (Nat.mod_eq_zero_of_dvd (E0.j.1.ext.tal t ht)) hi + · rw [hluEq]; exact E0.j.1.ext.foot_alignedE E0.j.1.vs.yal _ + (rootFootE hr0 (E0.j.1.ext.xal r0 hr0) (by have := s2GeomNumE.2.2.1; omega)) + have hW := extWordWriteA (st := st) (s := s2) (slot := lu.slot) (word := ew) hAlLu + have hDescNew := descRelE_s2tabA (G := G2E T2' Sh2') (sh := pos.shift) (by omega) hv3 hvm UP.pa + ⟨Set.mem_insert _ _, Function.update_self _ _ _⟩ + have hExtOk : ExtSlotOkX σ2 pos.slot := extSlotOk_of_s2Slot_pt J2.1.ext hsl + have hInv : D = ({(.ok (.extVSpace (.map (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, base.bv))) + cte pte pos.slot)), σ)}, False) := by + rw [hD2] + apply run_liftME_okA + have hokW : (NonDetE.whenE (pos.shift = pageBits ∨ pos.slot.read σ ≠ .invalidPTE) + (NonDetE.throwError SyscallError.deleteFirst)).run σ = ({(Except.ok (), σ)}, False) := by + unfold NonDetE.whenE + rw [if_neg (by rintro (h | h); exact hp12 h; exact h hInvEq)]; rfl + rw [run_bind_okA hokW, hbv] + rfl + have hmemD : (.ok (.extVSpace (.map (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, base.bv))) + cte pte pos.slot)), σ) ∈ D.1 := by rw [hInv]; exact rfl + have hperfV : (([] : List Fl4SpecA64.Data), extSlotWriteX σ2 pos.slot pte) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) (.map (.pageTableCap (specPtr ptr) .normalPtT + (some (asidOfA vasid, base.bv))) cte pte pos.slot) (stUpdA σ σ.curThread xc .restart)).1 := by + unfold Fl4SpecA64.performExtVSpace + have hst' : (Fl4SpecA64.storeExtSlot (Z := Unit) pos.slot pte >>= + fun _ => pure ([] : List Fl4SpecA64.Data)) σ2 = + ({([], extSlotWriteX σ2 pos.slot pte)}, False) := by + rw [nd_bind_oneD (storeExtSlot_runX hExtOk pte)]; rfl + exact ⟨((), σ2), hσ2, by dsimp only; rw [hst']; rfl⟩ + have hfa2 : ∀ w, FootA (L := L) Z s2 w → Aligned w := + FootA.aligned J2.1 (fun c hc o h1 h2 => by rw [nodeAt_ksb hksb2]; exact bxi_nodes E0.sys.ent.bxi c hc o h1 h2) + E0.scAl E0.ap.vcAl + have hEO2 : ExtTabOffA (L := L) Z m s2 := hEO.of_ksA hksb2 hcpu2 + have hK2 : Aligned (L.ksb s2) := hksb2 ▸ hK + have hT2' : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s2) := hksb2 ▸ hT + have hdTab : dTabA ew = ptr := by + unfold dTabA dAddrA + have hmask : (281474976706560#u64 : U64) = ept.ADDR_MASK := by unfold ept.ADDR_MASK; rfl + rw [hmask, hvm, show (18446603336221196288#u64 : U64) = layout.PPTR_BASE by unfold layout.PPTR_BASE; rfl] + exact wa_ws ptr layout.PPTR_BASE + have hchEmpty : ∀ j : U64, j.val < 512 → dBitA (L.mem s2 (peAF (dTabA ew) j)) 0 = false ∧ + ∀ pt1, σ2.kheap (specPtr (dTabA ew)) = some (.archObj (.pageTable pt1)) → + Fl4SpecA64.ptApply pt1 j.bv = .invalidPTE := by + rw [hdTab] + intro j hj + refine ⟨by rw [hmem2 j hj]; exact UP.inv j hj, fun pt1 hk1 => ?_⟩ + rw [hkp2] at hk1 + cases hk1 + exact hep j hj + have hJ3 : JAtZAX (L := L) AR Z' (L.wr s2 lu.slot ew) a (extSlotWriteX σ2 pos.slot pte) m := by + have hER3 : ExtVsRelA Z.Pp Z.S1 Z.X Z.Y T2' Sh2' (L.mem (L.wr s2 lu.slot ew)) (extSlotWriteX σ2 pos.slot pte) := by + rcases hsl with ⟨t, i, ⟨ht, hst⟩, hi, hluEq, hslEq⟩ | ⟨r0, j0, hr0, hj0, hluEq, hslEq, hshEq⟩ + · rw [hluEq] at hW ⊢; rw [hslEq] + have hne : t ≠ ptr := fun e => hS2 (Or.inl (e ▸ ht)) + have hst' : Sh2' t = pos.shift := by show Function.update Z.Sh2 ptr (pos.shift - 9) t = pos.shift; rw [Function.update_of_ne hne]; exact hst + exact hE2Add.of_ptWriteMapE J2.1.vs.yal (Set.mem_insert_of_mem _ ht) hi (by rw [hst']; exact hDescNew) hW.2.2 + (fun _ _ => ⟨by rw [hdTab]; exact hne.symm, hchEmpty⟩) + · rw [hluEq] at hW ⊢; rw [hslEq] + have hj1024 : j0.val < 1024 := by have := s2GeomNumE.2.2.1; omega + exact hE2Add.of_rootWriteMapE J2.1.vs.yal hr0 hj1024 (by rw [← hshEq]; exact hDescNew) hW.2.2 + (fun _ _ => hchEmpty) + have hV3 : VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem (L.wr s2 lu.slot ew)) (L.ksb (L.wr s2 lu.slot ew)) + (extSlotWriteX σ2 pos.slot pte) := by + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, hslEq⟩ | ⟨r0, j0, hr0, hj0, hluEq, hslEq, -⟩ + · rw [hluEq] at hW ⊢; rw [hslEq, hW.1] + exact J2.1.vs.of_s2WriteE (mem' := L.mem (L.wr s2 (peAF t i) ew)) J2.1.ext (Or.inl ht) + (J2.1.ext.tal t ht) hi (hT2' t i hi (Or.inl (Or.inl ht))) hK2 + (fun b hb hne => by rw [hW.2.2 b hb, if_neg (Ne.symm hne)]) + (Or.inl ht) (slotObjPtE (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) hi) pte + · rw [hluEq] at hW ⊢; rw [hslEq, hW.1] + have hj1024 : j0.val < 1024 := by have := s2GeomNumE.2.2.1; omega + obtain ⟨q, j, hq, hj, hpe⟩ := rootWordE (J2.1.ext.xal r0 hr0) hj1024 + have hqal : 4096 ∣ q.val := hq.elim (fun e => e ▸ al4kE (J2.1.ext.xal r0 hr0)) + (fun e => e ▸ al4kHiE (J2.1.ext.xal r0 hr0)) + exact J2.1.vs.of_s2WriteE (mem' := L.mem (L.wr s2 (peAF r0 j0) ew)) J2.1.ext + (Or.inr ⟨r0, hr0, hq⟩) hqal hj (hT2' q j hj (Or.inl (Or.inr ⟨r0, hr0, hq⟩))) hK2 + (fun b hb hne => by rw [hW.2.2 b hb, if_neg (by rw [hpe]; exact Ne.symm hne)]) + (Or.inr ⟨r0, hr0, Or.inl rfl⟩) (sl := .root (specPtr r0) j0.val) rfl pte + -- Build JAtZAX at Z' using J2.of_sameXA-style proof (only J.1.ext changes to Z'.T2 / Z'.Sh2) + have hSame : SameA (L := L) (extZA Z) s2 (L.wr s2 lu.slot ew) := by + refine ⟨hW.1, hW.2.1, fun w hw => ?_⟩ + have hne : lu.slot ≠ w := by + intro heq; subst heq + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨r0, j0, hr0, hj0, hluEq, -, -⟩ + · rw [hluEq] at hw; exact hEO2.mem t (Or.inl (Or.inl ht)) i hi hw + · have hj1024 : j0.val < 1024 := by have := s2GeomNumE.2.2.1; omega + obtain ⟨q, j, hq, hj, hpe⟩ := rootWordE (J2.1.ext.xal r0 hr0) hj1024 + rw [hluEq, hpe] at hw; exact hEO2.mem q (Or.inl (Or.inr ⟨r0, hr0, hq⟩)) j hj hw + rw [hW.2.2 w (hfa2 w (FootA.s1_monoA hw.extMonoA)), if_neg hne] + have hkh : ∀ p, RelPA (extZA Z) m p → (extSlotWriteX σ2 pos.slot pte).kheap p = σ2.kheap p := by + intro p hp + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, -, hslEq⟩ | ⟨r0, j0, hr0, hj0, -, hslEq, -⟩ + · rw [hslEq]; exact kheap_writeX (by + rw [slotObjPtE (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) hi] + intro e; subst e; exact hEO2.obj t (Or.inr (Or.inr ht)) hp) + · rw [hslEq]; exact kheap_writeX (by + intro e; subst e; exact hEO2.obj r0 (Or.inl hr0) hp) + have hobj : ∀ ko, (extSlotWriteX σ2 pos.slot pte).kheap (extSlotObjX pos.slot) = some ko → ExtObjA ko → + (∃ es, ko = .archObj (.ext (.stage2Root es)) ∧ ∃ r ∈ Z.X, specPtr r = extSlotObjX pos.slot) := by + intro ko e hx + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, -, hslEq⟩ | ⟨r0, j0, hr0, hj0, -, hslEq, -⟩ + · rw [hslEq] at e ⊢ + have hso : extSlotObjX (ExtSlot.pt (specPtr (peAF t i))) = specPtr t := + slotObjPtE (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) hi + rw [hso] at e + obtain ⟨pt', hk', -, -⟩ := hER3.s2pt t (Set.mem_insert_of_mem _ ht) + rw [hslEq] at hk' + obtain rfl := hk'.symm.trans e |> Option.some.inj + rcases hx with ⟨_, h'⟩ | ⟨_, h'⟩ | ⟨_, h'⟩ <;> cases h' + · rw [hslEq] at e ⊢ + obtain ⟨es, hk', -⟩ := hER3.s2root r0 hr0 + rw [hslEq] at hk' + obtain rfl := hk'.symm.trans e |> Option.some.inj + exact ⟨es, rfl, r0, hr0, rfl⟩ + have hv' : ∀ p x, (extSlotWriteX σ2 pos.slot pte).kheap p = some (.archObj (.vcpu x)) → + σ2.kheap p = some (.archObj (.vcpu x)) := fun p x e => by + by_cases hp : p = extSlotObjX pos.slot + · subst hp; obtain ⟨_, h, -⟩ := hobj _ e (Or.inl ⟨x, rfl⟩); cases h + · rwa [kheap_writeX hp] at e + have hx' : ∀ p es, (extSlotWriteX σ2 pos.slot pte).kheap p = some (.archObj (.ext (.stage2Root es))) → + ∃ r ∈ Z.X, specPtr r = p := fun p es e => by + by_cases hp : p = extSlotObjX pos.slot + · subst hp; obtain ⟨_, -, r, hr, hreq⟩ := hobj _ e (Or.inr (Or.inl ⟨es, rfl⟩)); exact ⟨r, hr, hreq⟩ + · exact J2.2.2.1.back p es (by rwa [kheap_writeX hp] at e) + have hy' : ∀ p l1, (extSlotWriteX σ2 pos.slot pte).kheap p = some (.archObj (.ext (.highVSpace l1))) → + ∃ r ∈ Z.Y, specPtr r = p := fun p l1 e => by + by_cases hp : p = extSlotObjX pos.slot + · subst hp; obtain ⟨_, h, -⟩ := hobj _ e (Or.inr (Or.inr ⟨l1, rfl⟩)); cases h + · exact J2.2.2.2.back p l1 (by rwa [kheap_writeX hp] at e) + -- Construct JAtZAX at Z' directly from J2's components + obtain ⟨J, V, X0, Y0⟩ := J2 + have HG : SpecGlobA σ2 (extSlotWriteX σ2 pos.slot pte) := (by constructor <;> first | rfl | exact ⟨rfl, rfl, rfl, rfl⟩) + have hT' : TcbKeepA Z.T σ2 (extSlotWriteX σ2 pos.slot pte) := + TcbKeepA.of_eq fun t h => hkh _ (Or.inr (Or.inl ⟨t, h, rfl⟩)) + have hC' : ∀ c ∈ Z.C, (extSlotWriteX σ2 pos.slot pte).kheap (scRenA m c) = σ2.kheap (scRenA m c) := + fun c h => hkh _ (Or.inr (Or.inr (Or.inl ⟨c, h, rfl⟩))) + have hV' : ∀ v ∈ Z.V, (extSlotWriteX σ2 pos.slot pte).kheap (specPtr v) = σ2.kheap (specPtr v) := + fun v h => hkh _ (Or.inr (Or.inr (Or.inr (Or.inl ⟨v, h, rfl⟩)))) + have hcn' : ∀ p r, Z.th p = some (.cnode r) → + (extSlotWriteX σ2 pos.slot pte).kheap (specPtr p) = σ2.kheap (specPtr p) := + fun p _ h => hkh _ (Or.inl ⟨p, by rw [h]; exact Option.some_ne_none _, rfl⟩) + have htc' : ∀ p, Z.th p = some .tcb → + (extSlotWriteX σ2 pos.slot pte).kheap (specPtr p) = σ2.kheap (specPtr p) := + fun p h => hkh _ (Or.inl ⟨p, by rw [h]; exact Option.some_ne_none _, rfl⟩) + have R0 : SchedRestA (L := L) (extZA Z) s2 σ2 m := + ⟨J.rest.rq, J.rest.rqDom, J.rest.rel, J.rest.consumed, J.rest.repr, J.rest.curDom, J.rest.domTime, + J.rest.prio, J.rest.scMem, J.rest.refillMax⟩ + have hR := (R0.of_mem hSame.toN).of_spec hT' hC' HG + have S0 := StateRelA.of_mem (Z := extZA Z) J.st hSame + have C0 := CdtRelA.of_mem (Z := extZA Z) J.cdt hSame + refine ⟨{ st := ⟨fun p r hp => by rw [hcn' p r hp]; exact S0.cnode p r hp, + fun t' h => by rw [htc' t' h]; exact S0.tcb t' h⟩ + cdt := ⟨C0.tree, C0.cdt, C0.cdt_slot, C0.orig, C0.par_slot, C0.prev⟩ + sch := (SchedRelA.of_mem (Z := extZA Z) J.sch hSame.toN).of_spec hT' hC' HG + ar := J.ar + place := by rw [hSame.ksb]; exact J.place + irq := (IrqRelA.of_mem (Z := extZA Z) J.irq hSame.toN).of_spec HG + rest := ⟨hR.rq, hR.rqDom, hR.rel, hR.consumed, hR.repr, hR.curDom, hR.domTime, hR.prio, + hR.scMem, hR.refillMax⟩ + thT := J.thT, csN := J.csN + idleT := fun c hc => by rw [(hSame.toN.node hc).2.1]; exact J.idleT c hc + idleC := fun c hc => by rw [(hSame.toN.node hc).2.2.2]; exact J.idleC c hc + curT := fun c hc => by rw [(hSame.toN.node hc).1]; exact J.curT c hc + cscC := fun c hc => by rw [(hSame.toN.node hc).2.2.1]; exact J.cscC c hc + ksFit := by rw [hSame.ksb]; exact J.ksFit + scOffD := J.scOffD + cv := fun y hy => by rw [hSame.cap (Or.inl hy)]; exact J.cv y hy + pml := fun y hy q mp asid e => by rw [hSame.cap (Or.inl hy)] at e; exact J.pml y hy q mp asid e + vs := hV3 + ext := hER3 }, ?_, ?_, ?_⟩ + · refine ⟨fun v hv'' => ?_, fun q x e => V.back q x (hv' q x e), fun t h => ?_, + fun y hy q e => V.cap y hy q (by rw [← hSame.cap (Or.inl hy)]; exact e)⟩ + · obtain ⟨x, e, h2⟩ := V.obj v hv'' + rw [(hSame.toN.vcW hv'').1, (hSame.toN.vcW hv'').2, hV' v hv''] + exact ⟨x, e, h2⟩ + · obtain ⟨x, e, h1, h2⟩ := V.tcb t h + rw [(hSame.toN.tcbW h).2.2.2.1, (hSame.toN.tcbW h).2.2.2.2, hkh _ (Or.inr (Or.inl ⟨t, h, rfl⟩))] + exact ⟨x, e, h1, h2⟩ + · refine ⟨fun r hr => ?_, hx', fun y hy q l mp asid va e => X0.cap y hy q l mp asid va + (by rw [← hSame.cap (Or.inl hy)]; exact e)⟩ + obtain ⟨es, e, -⟩ := hER3.s2root r hr + exact ⟨es, e⟩ + · refine ⟨fun r hr => ?_, hy', fun y hy q mp asid e => Y0.cap y hy q mp asid + (by rw [← hSame.cap (Or.inl hy)]; exact e)⟩ + obtain ⟨l1, e, -⟩ := hV3.high r hr + exact ⟨l1, e⟩ + obtain ⟨x1, hk1, -, -, J1, -, hOS1, -⟩ := J.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have exc : xc = x1 := by + have hkx' := hkx + rw [hk1] at hkx' + injection hkx' with h + injection h with h + exact h.symm + subst exc + have hks1 : L.ksb (L.wr s (stA (L.curW s)) sched.TS_RESTART) = L.ksb s := L.ksb_wr _ _ _ + have hcpu1 : L.cpu (L.wr s (stA (L.curW s)) sched.TS_RESTART) = L.cpu s := L.cpu_wr _ _ _ + have sA : Aligned (stA (L.curW s)) := by + rw [stA_eq]; exact field_aligned (E0.sq.tcbs _ E0.sq.curT) (by simp) (by simp) + generalize hs1 : L.wr s (stA (L.curW s)) sched.TS_RESTART = s1 at J1 hOS1 hks1 hcpu1 hsc hw2 hFr2 hst + have c1 : capA st s1 (cslotAddrA cte) = .PageTable ptr false asid0 va0 := (hOS1.capA hx).trans hco + have E1 := J1.toJEntA + have R0 := J.j.1.vs + have al_x : Aligned (cslotAddrA cte) := hO.al0 hx + have al_x8 : Aligned (wa (cslotAddrA cte) 8#u64) := hO.al hx (k := 8#u64) (by simp) (by simp) + have hpa : ptr.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd UP.al + have wS := writesIn_setCapA al_x al_x8 hsc + obtain ⟨PtJ, UbJ, vrJ, -, -, -, -, -, -, linkJ, -, -, -, -, R7⟩ := J.j7 + obtain ⟨PpJ, TbJ, HrJ, TeJ, KtJ, LvJ, ReJ, bitsJ, R2J, -, -⟩ := R7 + have hH12 : H ptr = some (.other 12) := by + have hunm : UnmCap (capA st s (cslotAddrA cte)) ptr 4096 := Or.inl ⟨rfl, asid0, va0, hco⟩ + obtain ⟨z, hz, hh⟩ := R2J.core.lookup.vh.1 _ hx ptr 4096 hunm + have hz12 : z = 12 := Nat.pow_right_injective (le_refl 2) (hz.symm.trans (by norm_num)) + rw [hz12] at hh + exact hh + obtain ⟨Ac', hsys, hsy, hbx, hus, hj7⟩ := fin xc _ _ hkx hmemD hperfV + have vo : VrOK H.omega H.frame H.scs H.scBits OS Z.V ∅ (L.ksb s) (utVsPtA st Pp Tb Lv s) := J.vsOk + have hN := bxi_nodes E1.sys.ent.bxi + have hnul1 : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s1 y = .Null := J1.j5.2.2 + have hTr1 : TreeA st OS Z.G.chains Z.G.par s1 := + J1.j.1.cdt.tree.grow J1.j5.2.1 (fun x hx hn => J1.j5.2.2 x hx hn) + have hok : CapObjOkA Z (.PageTable ptr true vasid baseU) := + ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), + fun _ _ _ h => (by cases h), trivial⟩ + have hM : MapAlikeA (.PageTable ptr true vasid baseU) (capA st s1 (cslotAddrA cte)) := by rw [c1]; exact .pt .. + have hirq : CapOkA (stUpdA σ σ.curThread xc .restart).interruptIrqNode cte + (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, base.bv)))) := by + refine ⟨fun irq hlt e => ?_, fun ⟨_, _, _, _, e⟩ => by cases e⟩ + have obj : ∃ o ac, (stUpdA σ σ.curThread xc .restart).kheap cte.1 = some o ∧ + Fl4SpecA64.capOf o cte.2 = some ac ∧ CapRelA (capAtA (L.mem s1) (cslotAddrA cte)) ac := by + obtain ⟨o, idx⟩ := cte + obtain ⟨p0, e1, hc | ⟨ht, i0, hi0, e2⟩⟩ := hab + · simp only at e1 hc; subst e1 + obtain ⟨cs, hk0, -, hr⟩ := J1.j.1.st.cnode p0 _ hc + obtain ⟨ac, hac, hrel⟩ := hr idx rfl + exact ⟨_, ac, hk0, hac, hrel⟩ + · simp only at e1 e2; subst e1 e2 + obtain ⟨y, hk0, hr⟩ := J1.j.1.st.tcb p0 ht + obtain ⟨ac, hac, hrel⟩ := hr i0 hi0 + refine ⟨_, ac, hk0, hac, ?_⟩ + unfold cslotAddrA; rw [ofBl_tcbIdx i0 (by unfold tcbSlotsA at hi0; omega)]; exact hrel + obtain ⟨o, ac, hko, hco', hrel⟩ := obj + have c1' : capAtA (L.mem s1) (cslotAddrA cte) = .PageTable ptr false asid0 va0 := c1 + rw [e] at hko + rw [c1'] at hrel + rcases J1.sinv.irqN.slot irq hlt o _ ac hko hco' with rfl | ⟨_, _, _, rfl⟩ + · cases hrel.2 + · cases hrel.2 + have hsci : NoIdleCapV m n (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT + (some (asidOfA vasid, base.bv)))) := + ⟨fun _ _ e => (by cases e), fun _ e => (by cases e), + fun _ _ _ e => by + cases e + exact fun h => by have h2 : 2 ^ 47 ≤ base.val := h.1; omega⟩ + have hnf : ∀ i : U64, i.val < 512 → ¬ FootA (L := L) (extZA Z) s1 (peAF ptr i) := fun i hi h => + (J1.unmPt.pt _ hx ptr asid0 va0 c1).off.mem i hi (FootA.extMonoA h) + have hno : ¬ RelPA (extZA Z) m (specPtr ptr) := fun h => + (J1.unmPt.pt _ hx ptr asid0 va0 c1).off.obj _ (RelPA.extMonoA h) rfl + -- the written word is in a window page: the shared tail + have hv0 : ew ≠ 0#u64 := fun h => by rw [h] at hv3; exact absurd hv3 (by decide) + have coreK : ∀ (q j : U64), XqA Z q → j.val < 512 → q.val % 4096 = 0 → q ≠ ptr → lu.slot = peAF q j → + (∀ (Pt : Set U64), (∀ p, SchedPageA st Z OS s1 p → p ∈ Pt) → + (∀ u ∈ OS, u ≠ cslotAddrA cte → capA st (L.wr s2 (peAF q j) ew) u = capA st s1 u) → + capA st (L.wr s2 (peAF q j) ew) (cslotAddrA cte) = .PageTable ptr true vasid baseU → + (∀ p0 ∈ Pt, ∀ i : U64, i.val < 512 → peAF p0 i ≠ peAF q j → + L.mem (L.wr s2 (peAF q j) ew) (peAF p0 i) = L.mem s1 (peAF p0 i)) → + L.mem (L.wr s2 (peAF q j) ew) (peAF q j) = ew → + L.ksb (L.wr s2 (peAF q j) ew) = L.ksb s1 → L.cpu (L.wr s2 (peAF q j) ew) = L.cpu s1 → + UnmPtSpecA st Z' m OS (L.wr s2 (peAF q j) ew) (extSlotWriteX σ2 pos.slot pte)) → + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) + (Ac'' Tb' : Set U64) (Lv' : U64 → Nat) (nL' : Nat), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with T2 := insert ptr Z.T2, Sh2 := Function.update Z.Sh2 ptr nL' } H OS U Ac'' Pp Tb' Lv' ia ie N E + Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) (L.wr s2 lu.slot ew) a σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + intro q j hq hj hqal hqne hlu hunm + rw [hlu] at hsys hsy hbx hus hj7 ⊢ + have hal : Aligned (peAF q j) := peAF_alignedA hqal hj + have J3 : JAtZAX (L := L) AR Z' (L.wr s2 (peAF q j) ew) a (extSlotWriteX σ2 pos.slot pte) m := by + rw [← hlu]; exact hJ3 + have hks2 := hksb2 + have hA : ¬ AsW (L.ksb s2) (peAF q j) := by rw [hksb2]; exact XqA.offAs hT hj hq + have hks3 : L.ksb (L.wr s2 (peAF q j) ew) = L.ksb s := (L.ksb_wr _ _ _).trans hks2 + have hcpu3 : L.cpu (L.wr s2 (peAF q j) ew) = L.cpu s := (L.cpu_wr _ _ _).trans hcpu2 + have wP : WritesIn st s2 (L.wr s2 (peAF q j) ew) (fun b => b = peAF q j) := writesIn_wr hal + have hAsK : ∀ b, AsW (L.ksb s) b → L.mem (L.wr s2 (peAF q j) ew) b = L.mem s b := by + intro b hb + have hb1 : Aligned b := vo.al b (Or.inr hb) + have hns : ¬ SlotWordA (cslotAddrA cte) b := fun h => vo.os b (Or.inr hb) (slotWord_inOS hO hx h) + have hvsR := RS.vs b (Or.inr hb) + rw [mem_wr_ne' hal hb1 (fun e => hA (by rw [e, hks2]; exact hb)), wS.mem_eq hb1 hns, ← hs1, + mem_wr_ne' sA hb1 (Ne.symm hvsR.2)] + have htbl : ∀ o : U64, 772352 ≤ o.val → o.val < 773376 → o.val % 8 = 0 → + L.mem (L.wr s2 (peAF q j) ew) (wa (L.ksb (L.wr s2 (peAF q j) ew)) o) ≠ 0#u64 → + L.mem (L.wr s2 (peAF q j) ew) (wa (L.ksb (L.wr s2 (peAF q j) ew)) o) ∈ Pp := by + intro o h1 h2 h8 hne + have e : L.mem (L.wr s2 (peAF q j) ew) (wa (L.ksb (L.wr s2 (peAF q j) ew)) o) = + L.mem s (wa (L.ksb s) o) := by + rw [hks3]; exact hAsK _ ⟨o, h1, h2, h8, rfl⟩ + rw [e] at hne ⊢ + exact (J.sys.ent.vs.tbl o h1 h2 h8 hne).1 + obtain ⟨T, LvR, hty, hvok⟩ := vsPost_of_j7A (S1 := Z.S1) hj7 htbl + have hbufv : ∀ b, BufW Bf b → ¬ VsR (L.ksb (L.wr s2 (peAF q j) ew)) + (utVsPtA st Pp (Z.S1 ∪ T) LvR (L.wr s2 (peAF q j) ew)) b := by + have x : L.mem (L.wr s2 (peAF q j) ew) (peAF q j) = ew := L.mem_wr_same hal + refine bufVs_leafA (x := peAF q j) (r := ptr) J.bufOff J.bufVs J.sys.ent.vs hty hks3 hAsK + (fun b hb ne => ?_) ?_ (fun _ h => ?_) (fun h => ?_) (fun _ => ?_) (fun j' hj' => ?_) + · have hb1 : Aligned b := vo.al b hb + have hns : ¬ SlotWordA (cslotAddrA cte) b := fun h => vo.os b hb (slotWord_inOS hO hx h) + have hvsR := RS.vs b hb + rw [mem_wr_ne' hal hb1 (Ne.symm ne), wS.mem_eq hb1 hns, ← hs1, mem_wr_ne' sA hb1 (Ne.symm hvsR.2)] + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr + ⟨_, hx, Or.inl ⟨_, _, _, hco⟩⟩)))))) + · rw [x, hv3] at h + exact absurd h (by decide) + · rw [x, hv3] at h + exact absurd h (by decide) + · rw [x, ← hdTab] + unfold vspace.ADDR_MASK dTabA dAddrA layout.PPTR_BASE + rfl + · have hne : peAF q j ≠ peAF ptr j' := fun e => + hqne (peAF_injA hqal hpa hj hj' e).1 + rw [mem_wr_ne' hal (peAF_alignedA hpa hj') hne, hmem2 j' hj'] + exact UP.inv j' hj' + have main := JStage3A.of_capVsFrameGA (J := J1) + (hS := fun _ h => h) + (hT2 := fun _ _ _ _ _ _ _ h => Set.mem_insert_of_mem _ h) + (hpt := fun q0 _ _ h => by + injection h with h1 + subst h1 + exact Or.inr (Set.mem_insert _ _)) (S1' := Z.S1) (T2' := insert ptr Z.T2) + (Zl' := Z.Lv) (Sh2' := Function.update Z.Sh2 ptr nS) (Tb' := Z.S1 ∪ T) (Lv' := LvR) + (Q := fun s' a' σ'' hw => s' = L.wr s2 (peAF q j) ew ∧ a' = a ∧ σ'' = extSlotWriteX σ2 pos.slot pte ∧ hw = Z.hw) + RS.sub (footNOff_ksA rfl rfl (footN_offA E1)) (footNAl_ksA rfl rfl (FootNA.aligned E1.j.1 hN E1.scAl E1.ap.vcAl)) + cte hab hEnc hca hTr1 hnul1 (fun h => by cases h) (by rw [c1]; exact fun h => by cases h) hM hok hirq hsci + (fun s2' σ2' hs2 hσ2' HSs' wc jx hcx => by + have es : s2' = s2 := okinj (hs2.symm.trans hsc) + subst es + have eσ : σ2' = σ2 := setCap_detA hσ2' hσ2 + subst eσ + obtain ⟨Pt, Ub, vr, -, -, -, -, -, -, link, -, -⟩ := J1.j7 + obtain ⟨Qb, Rb, q0⟩ := J1.sys.ent.bxi.1 + have vP : VsR (L.ksb s1) Pt (peAF q j) := vsW_pageA link hq.sched hj + have offT : ∀ t ∈ Z.T, (peAF q j).val < t.val ∨ t.val + 4096 ≤ (peAF q j).val := fun t ht => by + have hth : t ∈ H.tcbs := by rw [J1.tcbs]; exact ht + exact (q0.omega _ (vr.om _ vP)).2.1 t hth + have osk3 : OSKeep st OS s2' (L.wr s2' (peAF q j) ew) := + osKeep_ofA hO fun w' hw' hin => wP.mem_eq hw' (fun e => vr.os w' (e ▸ vP) hin) + obtain ⟨hcx', hco2⟩ := capA_setCapA hO hx hEnc hs2 + have hnew : capA st (L.wr s2' (peAF q j) ew) (cslotAddrA cte) = .PageTable ptr true vasid baseU := by + rw [osk3.capA hx, hcx'] + have hkeep : ∀ u ∈ OS, u ≠ cslotAddrA cte → + capA st (L.wr s2' (peAF q j) ew) u = capA st s1 u := fun u hu e => by + rw [osk3.capA hu, hco2 u hu e] + have hMs2 : ∀ u ∈ OS, MapAlikeA (capA st s2' u) (capA st s1 u) := fun u hu => by + by_cases e : u = cslotAddrA cte + · subst e; rw [hcx']; exact hM + · rw [hco2 u hu e]; exact .refl _ + have sbS : ∀ t ∈ Z.T, sbWordA t ∈ OS := fun t ht => + RS.sub _ ⟨t, Or.inr ⟨(J1.j.1.thT t).2 ht, 2, by simp [tcbSlotsA], (bufSlot_eqA t).symm⟩⟩ + have wA : WritesIn st s1 s2' (fun b => Aligned b ∧ W7.CapW H.tcbs {b | InOS OS b} ∅ b) := writesIn_alAG wc + have hB : ∀ b, (Aligned b ∧ W7.CapW H.tcbs {b | InOS OS b} ∅ b) → W7.CapW H.tcbs H.omega H.frame b := + fun b hb => os_capw hO hb.1 hb.2 + obtain ⟨-, -, -, -, -, fld, -, -⟩ := W7.blk_of_capw (BXI.blk J1.sys.ent.bxi) wA hB + have ib : ∀ t ∈ Z.T, L.mem s2' (ibWordA t) = L.mem s1 (ibWordA t) := fun t ht => + fld t (by rw [J1.tcbs]; exact ht) 3512#u64 (by simp) (by simp) (by simp) + obtain ⟨HS2, hdp⟩ := extWrite_vsA σ2' pos.slot pte + have tw : ∀ t ∈ Z.T, ∀ K : U64, K.val + 8 ≤ 4096 → K.val % 8 = 0 → + L.mem (L.wr s2' (peAF q j) ew) (wa t K) = L.mem s2' (wa t K) := by + intro t ht K hK' h8 + have hta := J1.sr.core.tcbs t ht + have hvv : (wa t K).val = t.val + K.val := field_val hta (K := K) (by omega) + refine wP.mem_eq (field_aligned hta (by omega) h8) (fun e => ?_) + have := offT t ht + rw [← e] at this + omega + have hib : ∀ t ∈ Z.T, IbSame (L := L) s2' (L.wr s2' (peAF q j) ew) t := fun t ht => by + refine ⟨tw t ht _ (by simp) (by simp), ?_, ?_⟩ + · rw [sbWordA_eq]; exact tw t ht _ (by simp) (by simp) + · rw [sbWordA8_eq]; exact tw t ht _ (by simp) (by simp) + have hj7' := hj7 + obtain ⟨Pt', Ub', vr', -, ac', -⟩ := hj7' + have hBw : ∀ b, (SlotWordA (cslotAddrA cte) b ∨ b = peAF q j) → + L.Free s1 H.omega Z.Cs b ∨ W7.TLow H.tcbs b := fun b hb => by + rcases hb with hsl' | rfl + · have hal' : Aligned b := by rcases hsl' with rfl | rfl; exact al_x; exact al_x8 + exact (os_capw hO hal' (Or.inr ⟨slotWord_inOS hO hx hsl', Set.notMem_empty _⟩)).elim Or.inr + fun h' => Or.inl (Or.inl h'.1) + · exact Or.inl (Or.inl (vr.om _ vP)) + have hsp : ∀ q', SchedPageA st { Z with T2 := insert ptr Z.T2, Sh2 := Function.update Z.Sh2 ptr nS } OS + (L.wr s2' (peAF q j) ew) q' → SchedPageA st Z OS s1 q' := + fun q' h => SchedPageA.backPtMapS2A hx c1 hnew hkeep h + have hks31 : L.ksb (L.wr s2' (peAF q j) ew) = L.ksb s1 := hks3.trans hks1.symm + have hcpu31 : L.cpu (L.wr s2' (peAF q j) ew) = L.cpu s1 := hcpu3.trans hcpu1.symm + have G := JStage3A.keepGhostA (hw := Z.hw) (s' := L.wr s2' (peAF q j) ew) J1 hks31 hcpu31 + have hptr : ptr ∈ Pt := link ptr (by + unfold SchedPageA + exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨_, hx, Or.inl ⟨_, _, _, c1⟩⟩))))))) + have h12 : ∃ q0' z, H q0' = some (.other z) ∧ q0'.val ≤ ptr.val ∧ ptr.val + 4096 ≤ q0'.val + 2 ^ z := + ⟨ptr, 12, hH12, le_refl _, by norm_num⟩ + have hword : ∀ p0 ∈ Pt, ∀ i : U64, i.val < 512 → peAF p0 i ≠ peAF q j → + L.mem (L.wr s2' (peAF q j) ew) (peAF p0 i) = L.mem s1 (peAF p0 i) := fun p0 hp0 i hi hne => by + have hv : VsR (L.ksb s1) Pt (peAF p0 i) := Or.inl ⟨p0, hp0, core.num.U64.wrapping_mul i 8#u64, + (wm8_offA hi).1, (wm8_offA hi).2, rfl⟩ + have hbal : Aligned (peAF p0 i) := vr.al _ hv + have hns : ¬ SlotWordA (cslotAddrA cte) (peAF p0 i) := fun h => vr.os _ hv (slotWord_inOS hO hx h) + exact (wP.mem_eq hbal hne).trans (wS.mem_eq hbal hns) + have hU9 := hunm Pt link hkeep hnew hword (L.mem_wr_same hal) hks31 hcpu31 + refine ⟨_, a, extSlotWriteX σ2' pos.slot pte, Z.hw, fun b => b = peAF q j, Ac', + ⟨wP, fun Pt'' Ub'' vr'' link'' b e => by rw [e]; exact vsW_pageA link'' hq.sched hj, + fun b e hbuf => J1.bufOff.page b hbuf q hq.sched (core.num.U64.wrapping_mul j 8#u64) + (by rw [wm8_valA hj]; omega) (by rw [wm8_valA hj]; omega) (by rw [e]; rfl), + HS2, rfl, hdp, J3, + ⟨⟨J1.sys.ent.heap, hbx, hO, hus, hty, by rw [hks3]; exact E0.sys.ent.ksw⟩, hsys⟩, hvok, hbufv, + W7.inv_of_capw J1.sq (wS.trans wP) hBw, ac'.case.po, ?_, ?_, hU9, + ⟨J1.bufOff.os, fun b hb hf => ?_, fun b hb q' hq' => J1.bufOff.page b hb q' (hsp q' hq'), + J1.bufOff.vcw, + fun bp hbp => (J1.bufOff.pin bp hbp).keepF fun t ht hO' _ _ r x1 x2 x3 x4 e => + ⟨ht, hO', r, x1, x2, x3, x4, by + rw [hkeep _ hO' (fun e1 => by rw [e1, c1] at e; cases e)]; exact e⟩⟩, + J7A.growPtMapS2A hx hnew (fun _ h => h) hj7, + fun h p0 bytes hp0 => h p0 bytes (JointObjectA.shrinkT2insA hH12 hp0), + fun h => ⟨h.vcpu, h.reply, h.asid, h.tvcpu, h.vcDeadRun, h.replyTcb⟩, + fun h => ⟨fun u hu q0' b0 fi hc p0 bytes hp0 => + h.obj u hu q0' b0 fi hc p0 bytes (JointObjectA.shrinkT2insA hH12 hp0), h.ks, h.idle, h.sep⟩, + fun h => h, + ⟨G.1.sca, G.1.irqSt, G.1.vcAl, G.1.vc, G.1.vs, fun b hb => ?_⟩, Set.subset_union_left, + J1.ptH, ⟨fun p0 hp0 => ?_, G.2.2.1.roots⟩, + fun b hb => J1.vsVc b (by rw [hks31] at hb; exact hb), + fun q0' hq0' => TabOffA.growT2A (J1.tabS1 q0' hq0') hks31 hcpu31 (R0.al_mod hq0') hpa + (fun e => UP.nt (e ▸ hq0')), + ExtTabOffA.growT2A J1.tabExt hks31 hcpu31 hnf hno, hsy⟩, + rfl, rfl, rfl, rfl⟩ + · exact BufCover.vsA (BufCover.mapA J1.bufCover J1.bufNative J1.j.1.st jx.1.st + (fun t ht => (J1.j.1.thT t).2 ht) HSs' ib (fun t ht => hMs2 _ (sbS t ht))) HS2 hib + · exact BufNativeA.mapA J1.bufNative (fun t ht q' sz' rr dv' m' e' a'' v' h => by + by_cases e1 : sbWordA t = cslotAddrA cte + · rw [e1, hnew] at h; cases h + · rw [hkeep _ (sbS t ht) e1] at h + have hn := J1.bufNative t ht + rw [bufSlot_eqA, capAtA_eq (st := st), h] at hn + exact hn) + · rw [hks31] at hf + exact J1.bufOff.vs b hb hf + · -- the ext words of the grown ghosts + cases hb with + | s2lo r i hr hi => exact G.1.ext _ (.s2lo r i hr hi) + | s2hi r i hr hi => exact G.1.ext _ (.s2hi r i hr hi) + | s2pt t i ht hi => + rcases Set.mem_insert_iff.1 ht with rfl | ht + · exact ⟨fun h => UP.os i hi h, fun t' ht' => UP.tcb i hi t' ht'⟩ + · exact G.1.ext _ (.s2pt t i ht hi) + | wl0 y hy => exact G.1.ext _ (.wl0 y hy) + | wlo y i hy hi => exact G.1.ext _ (.wlo y i hy hi) + · rcases hp0 with ((hp0 | hp0) | hp0) | hp0 + · exact G.2.2.1.pages p0 (Or.inl (Or.inl (Or.inl hp0))) + · exact G.2.2.1.pages p0 (Or.inl (Or.inl (Or.inr hp0))) + · rcases Set.mem_insert_iff.1 hp0 with rfl | hp0 + · exact h12 + · exact G.2.2.1.pages p0 (Or.inl (Or.inr hp0)) + · exact G.2.2.1.pages p0 (Or.inr hp0)) + obtain ⟨_, _, s3', a3', σ3', hw, P, Ac'', -, hσk, HSsk, HSvk, -, -, Jf, e1, e2, e3, e4⟩ := main + subst e1 e2 e3 e4 + exact ⟨_, _, _, Ac'', Z.S1 ∪ T, LvR, nS, hkx, hset, hmemD, hperfV, Jf, + (Sched.BodyKeepA.ofSlot HSsk (setCap_keepsA hσk).2.2).trans (Sched.BodyKeepA.ofVs HSvk)⟩ + have hoffG : ∀ (s3x : S), (∀ u ∈ OS, u ≠ cslotAddrA cte → capA st s3x u = capA st s1 u) → + capA st s3x (cslotAddrA cte) = .PageTable ptr true vasid baseU → L.ksb s3x = L.ksb s1 → + L.cpu s3x = L.cpu s1 → ∀ u ∈ OS, ∀ q, ((∃ a v, capA st s3x u = .PageTable q false a v) ∨ + ∃ a, capA st s3x u = .Pml4 q false a) → TabOffA (L := L) Z m s1 q → TabOffA (L := L) Z' m s3x q := by + intro s3x hkeep hnew hk hc u hu q hcu T + rcases hcu with ⟨a', v', hc3⟩ | ⟨a', hc3⟩ + · by_cases e : u = cslotAddrA cte + · subst e; rw [hnew] at hc3; cases hc3 + · have hc1 : capA st s1 u = .PageTable q false a' v' := by rw [← hkeep u hu e]; exact hc3 + have hc1s : capA st s u = .PageTable q false a' v' := by rw [← hOS1.capA hu]; exact hc1 + have hunm' : UnmCap (capA st s u) q 4096 := Or.inl ⟨rfl, a', v', hc1s⟩ + obtain ⟨z, hzz, hh⟩ := R2J.core.lookup.vh.1 u hu q 4096 hunm' + have hz12 : z = 12 := Nat.pow_right_injective (le_refl 2) (hzz.symm.trans (by norm_num)) + have hq4 := J.sys.ent.heap.align q _ hh + rw [hz12] at hq4 + have hne : q ≠ ptr := fun h => e (R2J.capRefs.unique (cslotAddrA cte) hx u hu (0, ptr) + (by rw [hco]; rfl) (by rw [hc1s, h]; rfl) (by rw [hco]; rfl)) + exact TabOffA.growT2A T hk hc hq4 hpa hne + · by_cases e : u = cslotAddrA cte + · subst e; rw [hnew] at hc3; cases hc3 + · have hc1 : capA st s1 u = .Pml4 q false a' := by rw [← hkeep u hu e]; exact hc3 + have hs0 : IsSlotA Z.th u := Classical.byContradiction fun h => by rw [hnul1 u hu h] at hc1; cases hc1 + have hok0 : CapObjOkA Z (capA st s1 u) := J1.j.capObj hs0 + rw [hc1] at hok0 + have hqS := (hok0.2.2.2.1 q false a' rfl).1 + exact TabOffA.growT2A T hk hc (R0.al_mod hqS) hpa (fun h => UP.nt (h ▸ hqS)) + have keepCG : ∀ (s3x : S), (∀ u ∈ OS, u ≠ cslotAddrA cte → capA st s3x u = capA st s1 u) → + capA st s3x (cslotAddrA cte) = .PageTable ptr true vasid baseU → + ∀ u ∈ OS, ∀ c, capA st s3x u = c → (∀ q a w, c = .PageTable q false a w ∨ c = .Pml4 q false a ∨ + c = .Ept q 0#u64 false a w ∨ c = .HighVSpace q false a → capA st s1 u = c) := by + intro s3x hkeep hnew u hu c hc q a' w hk0 + by_cases e : u = cslotAddrA cte + · subst e + rw [hnew] at hc + rw [← hc] at hk0 + rcases hk0 with h | h | h | h <;> cases h + · rw [← hkeep u hu e]; exact hc + -- the two places the descriptor can be written + rcases hslR with ⟨t, i, ⟨⟨ht, hst'⟩, hreach⟩, hi, hluEq, hslEq⟩ | ⟨r0, j0, hr0, hact, hj0, hluEq, hslEq, hshEq⟩ + · have hqal : t.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd (J.j.1.ext.tal t ht) + have hne : t ≠ ptr := fun e => hS2 (Or.inl (e ▸ ht)) + refine coreK t i (Or.inl (Or.inl ht)) hi hqal hne hluEq ?_ + intro Pt link hkeep hnew hword hv' hk31 hcpu31 + refine UnmPtSpecA.ofValidWrA (Z := Z) (Z' := Z') (Pt := Pt) (b := peAF t i) (o := specPtr t) + (.nslot _ (.ext _ (.s2pt t i ht hi))) + (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨t, ht, rfl⟩)))))))) + (keepCG _ hkeep hnew) hword link (hoffG _ hkeep hnew hk31 hcpu31) + (fun q ao hq h => ?_) (fun u hu p a' v hc => ?_) (fun u hu p a' hc => ?_) J1.unmPt + · rw [kheap_writeX (by rw [hslEq, slotObjPtE hqal hi]; exact hq)] + exact HS.keep h (fun _ _ e => by cases e) (fun _ e => by cases e) + · have hpX : p ∈ Z.X := (J1.j.capObj (by + by_contra h + rw [hnul1 u hu h] at hc; cases hc)).2.1 p 0#u64 false a' v hc + have pa8 := J1.j.1.ext.xal p hpX + have h2 := J1.j.1.ext.t2x t ht p hpX + exact ⟨fun k hk' => ⟨peAF_ne_tabA hqal (Nat.mod_eq_zero_of_dvd (al4kE pa8)) hi hk' (fun e => h2.1 e.symm), + peAF_ne_tabA hqal (waWin_modA pa8) hi hk' (fun e => h2.2 e.symm)⟩, + fun e => h2.1 (specPtr_inj e).symm⟩ + · have hpY : p ∈ Z.Y := (J1.j.capObj (by + by_contra h + rw [hnul1 u hu h] at hc; cases hc)).2.2.1 p false a' hc + have hpg := J.j.1.ext.pgd t (Or.inl ht) + exact ⟨fun k hk' => peAF_ne_tabA hqal (waWin_modA (R0.yal p hpY)) hi hk' + (fun e => hpg.1 (Or.inr (Or.inr ⟨p, hpY, e.symm⟩))), fun e => hpg.2 (by rw [← specPtr_inj e]; exact hpY)⟩ + · have hr8 := J.j.1.ext.xal r0 hr0 + have hj1024 : j0.val < 1024 := by have := s2GeomNumE.2.2.1; omega + obtain ⟨q, j, hq, hj, hpe⟩ := rootWordE hr8 hj1024 + have hqal : q.val % 4096 = 0 := hq.elim (fun e => e ▸ Nat.mod_eq_zero_of_dvd (al4kE hr8)) + (fun e => e ▸ waWin_modA hr8) + have hqne : q ≠ ptr := fun e => hS2 (Or.inr ⟨r0, hr0, by rw [← e]; exact hq⟩) + have hqS : q ∈ S2PgE Z.X Z.T2 := Or.inr ⟨r0, hr0, hq⟩ + refine coreK q j (Or.inl hqS) hj hqal hqne (hluEq.trans hpe) ?_ + intro Pt link hkeep hnew hword hv' hk31 hcpu31 + -- no unmapped `Ept` cap names the active root `r0` + have uniqE : ∀ u ∈ OS, ∀ p a' v', capA st s u = .Ept p 0#u64 false a' v' → p ≠ r0 := by + intro u hu p a' v' hc' e + subst e + obtain ⟨a0, -, hvs0⟩ := vspaceForAsid_of_activeS2A hact + obtain ⟨asid0', raw, ⟨hi', lo, hhi, hlo, hasid, pool, hpool, hpne, htab, hw, hrne⟩, ht1, hun⟩ := + activeEptRootA_of_vspaceForAsid E0.j.1.vs hX hr0 hvs0 + have hksF : (L.ksb s).val + 788736 ≤ 2 ^ 64 := by + have := J.sr.ksFit + unfold ksSizeA at this + omega + have hP : pool ∈ PoolSet st Z.Pp s := PoolSet.ofActiveA hpool ⟨hpne, hi', hhi, htab⟩ hksF + have hP7 : pool ∈ PoolSet st PpJ s := by + obtain ⟨-, o, h1, h2, h3, h4, h5⟩ := hP + rw [← h4] + have hty : VsTyR st (L.ksb s) (PoolSet st Z.Pp s) ∅ Tb Lv s := by rw [J.pp]; exact J.sys.ent.vs + exact R2J.core.stage1.tbl o h1 h2 h3 (by rw [h4]; exact h5) + have act : ActiveAsidRoot st PpJ s asid0' raw := by + have h127 : (hi' &&& 127#u64) = hi' := UScalar.eq_of_val_eq (by + rw [and_maskA hi' 7 _ rfl]; exact Nat.mod_eq_of_lt (by omega)) + have hat : wa (L.ksb s) (AtOff hi') = atAF (L.ksb s) hi' := by unfold AtOff atAF; rw [h127] + have ho : (core.num.U64.wrapping_mul lo 8#u64).val = 8 * lo.val := wm8_valA hlo + exact ⟨hi', core.num.U64.wrapping_mul lo 8#u64, hhi, by omega, by omega, by omega, pool, hP7, + by rw [hat]; exact htab, hw, hrne⟩ + obtain ⟨x', hx', cap⟩ := R2J.core.root.backed asid0' raw act + have t1 : raw &&& 3#u64 = 1#u64 := UScalar.eq_of_val_eq (by rw [and3_valA]; exact ht1) + rcases cap with ⟨bad, -⟩ | ⟨-, va', cap⟩ | ⟨bad, -⟩ + · rw [t1] at bad; exact absurd bad (by decide) + · have er : raw &&& ~~~3#u64 = p := hun + rw [er] at cap + have e := R2J.capRefs.unique u hu x' hx' (2, p) (by rw [hc']; rfl) (by rw [cap]; rfl) (by rw [hc']; rfl) + rw [e, hc'] at cap + cases cap + · rw [t1] at bad; exact absurd bad (by decide) + refine UnmPtSpecA.ofValidWrA (Z := Z) (Z' := Z') (Pt := Pt) (b := peAF q j) (o := specPtr r0) + (by rcases hq with e | e <;> rw [e] + · exact .nslot _ (.ext _ (.s2lo r0 j hr0 hj)) + · exact .nslot _ (.ext _ (.s2hi r0 j hr0 hj))) + (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨r0, hr0, rfl⟩))))) + (keepCG _ hkeep hnew) hword link (hoffG _ hkeep hnew hk31 hcpu31) + (fun q' ao hq' h => ?_) (fun u hu p a' v hc => ?_) (fun u hu p a' hc => ?_) J1.unmPt + · rw [kheap_writeX (by rw [hslEq]; exact hq')] + exact HS.keep h (fun _ _ e => by cases e) (fun _ e => by cases e) + · have hpX : p ∈ Z.X := (J1.j.capObj (by + by_contra h + rw [hnul1 u hu h] at hc; cases hc)).2.1 p 0#u64 false a' v hc + have pa8 := J1.j.1.ext.xal p hpX + have hpne : p ≠ r0 := uniqE u hu p a' v (by rw [hOS1.capA hu] at hc; exact hc) + have hr0p : r0 ≠ wa p 4096#u64 := fun e => hiNeE pa8 hr8 e.symm + have hwr : wa r0 4096#u64 ≠ p := hiNeE hr8 pa8 + have hww : wa r0 4096#u64 ≠ wa p 4096#u64 := fun e => hpne (UScalar.eq_of_val_eq (by + have := congrArg UScalar.val e + rw [waWin_valA hr8, waWin_valA pa8] at this + omega)).symm + have hpq : q ≠ p ∧ q ≠ wa p 4096#u64 := by + rcases hq with e | e <;> rw [e] + · exact ⟨fun h => hpne h.symm, hr0p⟩ + · exact ⟨hwr, hww⟩ + exact ⟨fun k hk' => ⟨peAF_ne_tabA hqal (Nat.mod_eq_zero_of_dvd (al4kE pa8)) hj hk' (Ne.symm hpq.1), + peAF_ne_tabA hqal (waWin_modA pa8) hj hk' (Ne.symm hpq.2)⟩, + fun e => hpne (specPtr_inj e)⟩ + · have hpY : p ∈ Z.Y := (J1.j.capObj (by + by_contra h + rw [hnul1 u hu h] at hc; cases hc)).2.2.1 p false a' hc + have hpg := J.j.1.ext.pgd q hqS + have hpg0 := J.j.1.ext.pgd r0 (Or.inr ⟨r0, hr0, Or.inl rfl⟩) + exact ⟨fun k hk' => peAF_ne_tabA hqal (waWin_modA (R0.yal p hpY)) hj hk' + (fun e => hpg.1 (Or.inr (Or.inr ⟨p, hpY, e.symm⟩))), fun e => hpg0.2 (by rw [← specPtr_inj e]; exact hpY)⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmT2A.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmT2A.lean new file mode 100644 index 000000000..293309bdc --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmT2A.lean @@ -0,0 +1,709 @@ +/- +P3 (AArch64, vsx line C): **the T2 unmap shrink** — generic lemmas for dropping a Stage-2 table `p` from the ghost `T2` +after `ARMPageTableUnmap` of its (final) mapped page-table cap, and the arm `JStage3A.ptUnmapT2A` (module end). + +* `S2EntryA`, `S2ReachA.backE`, `ExtVsRelA.shrinkT2E`: `ExtVsRelA` at `T2 \ {p}` from `ExtVsRelA` at `T2` when no + reachable valid table descriptor names `p`. +* `JAtZAX.shrinkT2A`: `JAtZAX` at `{ Z with T2 := T2' }` (only `ext` reads `T2`). +* Monotonicity of the `T2`-reading records (`FootA`, `RelPA`, `TabOffA`, `ExtTabOffA`, `SchedPageA`, `UnmPtSpecA`, + `BufOffA`, `SetsInHA`, `JointObjectA`, `ExtFootE`) under `T2' ⊆ T2`, and `TabOffA.ofExtT2` (the unmapped table is off the + shrunk footprint). + +Named premise (arm): [J] `hUniq` = `PtUniqT2A`, a **candidate record invariant** ("a mapped table is referenced by +exactly one reachable entry"; see `JStage3A.ptUnmapT2A`). New module. +-/ +import Fl4ProofsA64.P3.Stage3ArmPtUnmXA +import Fl4ProofsA64.P3.Stage3ArmPtMapA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- **The entry words of the reachable Stage-2 tables** (root entries of an active root, entries of a reachable +table `t ∈ T2` above the leaf level). -/ +def S2EntryA (Pp X T2 : Set U64) (Sh2 : U64 → Nat) (mem : U64 → U64) (σ : Fl4SpecA64.State Unit) (w : U64) : Prop := + (∃ r i : U64, ActiveS2RootA Pp X σ r ∧ i.val < Fl4SpecA64.s2Geom.topMask + 1 ∧ w = peAF r i) ∨ + (∃ t i : U64, S2ReachA Pp X T2 Sh2 mem σ t ∧ t ∈ T2 ∧ 12 < Sh2 t ∧ i.val < 512 ∧ w = peAF t i) + +section uniq +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +variable (st) in +/-- **[J] `PtUniqT2A`** — **candidate record invariant** ("a mapped table is referenced by exactly one reachable +entry"): at the restart state of an `ARMPageTableUnmap` of the Stage-2 table `ptr`, a valid table descriptor named +`ptr` that is reachable from an active Stage-2 root at `σ` is zeroed by the unmap run. Guarded by the reached run and +by reachability; it is the arm premise `hUniq` of `JStage3A.ptUnmapT2A`. -/ +def PtUniqT2A (ar : machine.Arch A) (Z : XSetsA) (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (asid va ptr : U64) : + Prop := + ∀ (s2 : S) (a2 : A), + vspace.unmap_page_table st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a asid va ptr = ok (s2, a2) → + ∀ w, S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART)) σ w → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 0 = true → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 1 = true → + dTabA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) = ptr → L.mem s2 w = 0#u64 + +end uniq + +/-- Reachability at fewer tables, at a state whose valid descriptors are the old ones, is old reachability. -/ +theorem S2ReachA.backE {Pp X T2 T2' : Set U64} {Sh2 : U64 → Nat} {mem mem' : U64 → U64} + {σ σ' : Fl4SpecA64.State Unit} (hT : T2' ⊆ T2) (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (hA : ∀ r, ActiveS2RootA Pp X σ' r → ActiveS2RootA Pp X σ r) + (hM : ∀ q ∈ S2PgE X T2, ∀ j : U64, j.val < 512 → mem' (peAF q j) ≠ 0#u64 → + mem (peAF q j) = mem' (peAF q j)) {t : U64} (h : S2ReachA Pp X T2' Sh2 mem' σ' t) : + S2ReachA Pp X T2 Sh2 mem σ t := by + have hMr : ∀ r ∈ X, ∀ i : U64, i.val < 1024 → (mem' (peAF r i) &&& 3#u64) = 3#u64 → + mem (peAF r i) = mem' (peAF r i) := fun r hr i hi h3 => by + obtain ⟨q, j, hq, hj, e⟩ := rootWordE (hxal r hr) hi + rw [e] at h3 ⊢ + exact hM q (Or.inr ⟨r, hr, hq⟩) j hj (fun h0 => by rw [h0] at h3; exact absurd h3 (by decide)) + induction h with + | root hr => exact .root (hA _ hr) + | @stepRoot r i hr hi h3 hd => + have e := hMr r hr.1 i (by have := s2GeomNumE.2.2.1; omega) h3 + rw [← e] + exact .stepRoot (hA r hr) hi (by rw [e]; exact h3) (by rw [e]; exact hT hd) + | @stepPt t i _ ht h12 hi h3 hd ih => + have e := hM t (Or.inl (hT ht)) i hi (fun h0 => by rw [h0] at h3; exact absurd h3 (by decide)) + rw [← e] + exact .stepPt ih (hT ht) h12 hi (by rw [e]; exact h3) (by rw [e]; exact hT hd) + +/-- **`ExtVsRelA` at `T2 \ {p}`**: no reachable valid table descriptor names `p`. -/ +theorem ExtVsRelA.shrinkT2E {Pp Tb X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} + {σ : Fl4SpecA64.State Unit} (E : ExtVsRelA Pp Tb X Y T2 Sh2 mem σ) {p : U64} + (hno : ∀ w, S2EntryA Pp X (T2 \ {p}) Sh2 mem σ w → dBitA (mem w) 0 = true → dBitA (mem w) 1 = true → + dTabA (mem w) ≠ p) : + ExtVsRelA Pp Tb X Y (T2 \ {p}) Sh2 mem σ := by + have hS : ∀ q, q ∈ S2PgE X (T2 \ {p}) → q ∈ S2PgE X T2 := fun q hq => by + rcases hq with h | h + · exact Or.inl h.1 + · exact Or.inr h + refine ⟨fun r hr => ?_, fun t ht => ?_, fun t ht => E.tsh t ht.1, E.wl0, E.wlo, E.xal, + fun t ht => E.tal t ht.1, fun q hq => E.pgd q (hS q hq), fun t ht r hr => E.t2x t ht.1 r hr, E.ypg, E.ypp⟩ + · obtain ⟨es, hk, hd⟩ := E.s2root r hr + refine ⟨es, hk, fun hact i hi hi2 => ?_⟩ + obtain ⟨h1, h2⟩ := hd hact i hi hi2 + refine ⟨h1.mono (fun hb0 hb1 _ hg => ⟨⟨hg.1, fun e => ?_⟩, hg.2⟩), h2⟩ + exact hno (peAF r i) (Or.inl ⟨r, i, hact, hi2, rfl⟩) hb0 hb1 (Set.mem_singleton_iff.1 e) + · obtain ⟨pt, hk, hty, hd⟩ := E.s2pt t ht.1 + refine ⟨pt, hk, hty, fun hreach i hi => ?_⟩ + have hr2 : S2ReachA Pp X T2 Sh2 mem σ t := + S2ReachA.backE (show T2 \ {p} ⊆ T2 from fun _ hx => hx.1) E.xal (fun _ h => h) (fun _ _ _ _ _ => rfl) hreach + obtain ⟨h1, h2⟩ := hd hr2 i hi + refine ⟨h1.mono (fun hb0 hb1 h12 hg => ⟨⟨hg.1, fun e => ?_⟩, hg.2⟩), h2⟩ + exact hno (peAF t i) (Or.inr ⟨t, i, hreach, ht, h12, hi, rfl⟩) hb0 hb1 (Set.mem_singleton_iff.1 e) + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +/-- **`JAtZAX` at a smaller `T2`** (only `ext` reads it). -/ +theorem JAtZAX.shrinkT2A {AR : A → HwRootA → Prop} {Z : XSetsA} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} + {m : Fl4SpecA64.McState} {T2' : Set U64} (J : JAtZAX (L := L) AR Z s a σ m) + (ER : ExtVsRelA Z.Pp Z.S1 Z.X Z.Y T2' Z.Sh2 (L.mem s) σ) : + JAtZAX (L := L) AR { Z with T2 := T2' } s a σ m := + ⟨({ J.1 with ext := ER, rest := ⟨J.1.rest.rq, J.1.rest.rqDom, J.1.rest.rel, J.1.rest.consumed, J.1.rest.repr, + J.1.rest.curDom, J.1.rest.domTime, J.1.rest.prio, J.1.rest.scMem, J.1.rest.refillMax⟩ } : + JAtZA (L := L) AR { Z with T2 := T2' } s a σ m), + ⟨J.2.1.obj, J.2.1.back, J.2.1.tcb, J.2.1.cap⟩, ⟨J.2.2.1.obj, J.2.2.1.back, J.2.2.1.cap⟩, + ⟨J.2.2.2.obj, J.2.2.2.back, J.2.2.2.cap⟩⟩ + +/-! ## Monotonicity under `T2' ⊆ T2` -/ + +theorem RelPA.monoA2 {Z Z' : XSetsA} {m : Fl4SpecA64.McState} {p : Fl4SpecA64.ObjRef} (hth : Z'.th = Z.th) + (hT : Z'.T ⊆ Z.T) (hC : Z'.C ⊆ Z.C) (hV : Z'.V ⊆ Z.V) (hX : Z'.X ⊆ Z.X) (hY : Z'.Y ⊆ Z.Y) + (hP : Z'.Pp ⊆ Z.Pp) (hS : Z'.S1 ⊆ Z.S1) (h2 : Z'.T2 ⊆ Z.T2) (h : RelPA Z' m p) : RelPA Z m p := by + rcases h with ⟨q, hq, e⟩ | ⟨t, ht, e⟩ | ⟨c, hc, e⟩ | ⟨v, hv, e⟩ | ⟨r, hr, e⟩ | ⟨r, hr, e⟩ | ⟨q, hq, e⟩ | + ⟨q, hq, e⟩ | ⟨q, hq, e⟩ + · exact Or.inl ⟨q, by rw [← hth]; exact hq, e⟩ + · exact Or.inr (Or.inl ⟨t, hT ht, e⟩) + · exact Or.inr (Or.inr (Or.inl ⟨c, hC hc, e⟩)) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨v, hV hv, e⟩))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨r, hX hr, e⟩)))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨r, hY hr, e⟩))))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨q, hP hq, e⟩)))))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨q, hS hq, e⟩))))))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨q, h2 hq, e⟩))))))) + +variable {Z : XSetsA} {T2' : Set U64} + +theorem FootA.shrinkT2A {s : S} {w : U64} (hT : T2' ⊆ Z.T2) (h : FootA (L := L) { Z with T2 := T2' } s w) : + FootA (L := L) Z s w := + FootA.monoA (Z := { Z with T2 := T2' }) rfl rfl (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) + (fun _ h => h) (fun _ h => h) (fun _ h => h) hT h + +theorem TabOffA.shrinkT2A {m : Fl4SpecA64.McState} {s : S} {q : U64} (hT : T2' ⊆ Z.T2) + (h : TabOffA (L := L) Z m s q) : TabOffA (L := L) { Z with T2 := T2' } m s q := + ⟨fun i hi hf => h.mem i hi (FootA.monoA (Z := { { Z with T2 := T2' } with S1 := ∅ }) rfl rfl (fun _ h => h) + (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) hT hf), + fun q' hq => h.obj q' (RelPA.monoA2 (Z := { Z with S1 := ∅ }) (Z' := { { Z with T2 := T2' } with S1 := ∅ }) + rfl (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) (fun _ h => h) + (fun _ h => h) hT hq)⟩ + +theorem ExtTabOffA.shrinkT2A {m : Fl4SpecA64.McState} {s : S} (hT : T2' ⊆ Z.T2) + (h : ExtTabOffA (L := L) Z m s) : ExtTabOffA (L := L) { Z with T2 := T2' } m s := + ⟨fun q hq i hi hf => h.mem q (hq.imp (fun h' => by + rcases h' with h' | h' + · exact Or.inl (hT h') + · exact Or.inr h') id) i hi hf, + fun p hp => h.obj p (hp.imp id (fun h' => h'.imp id (fun h'' => hT h'')))⟩ + +theorem ExtFootE.shrinkT2A {X Y T2 T2' : Set U64} {b : U64} (hT : T2' ⊆ T2) (h : ExtFootE X Y T2' b) : + ExtFootE X Y T2 b := by + cases h with + | s2lo r i hr hi => exact .s2lo r i hr hi + | s2hi r i hr hi => exact .s2hi r i hr hi + | s2pt t i ht hi => exact .s2pt t i (hT ht) hi + | wl0 y hy => exact .wl0 y hy + | wlo y i hy hi => exact .wlo y i hy hi + +variable (st) in +theorem SchedPageA.shrinkT2A {OS : Set U64} {s : S} {q : U64} (hT : T2' ⊆ Z.T2) + (h : SchedPageA st { Z with T2 := T2' } OS s q) : SchedPageA st Z OS s q := by + unfold SchedPageA at h ⊢ + rcases h with h | h | h | h + · exact Or.inl h + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr (Or.inl (hT h))) + · exact Or.inr (Or.inr (Or.inr h)) + +theorem JointObjectA.shrinkT2A {H : Heap} {p : U64} {bytes : Nat} (hT : T2' ⊆ Z.T2) + (h : JointObjectA { Z with T2 := T2' } H p bytes) : JointObjectA Z H p bytes := by + rcases h with ⟨hb, h⟩ | h | h | h + · rcases h with h | h | h | h | h + · exact Or.inl ⟨hb, Or.inl h⟩ + · exact Or.inl ⟨hb, Or.inr (Or.inl h)⟩ + · exact Or.inl ⟨hb, Or.inr (Or.inr (Or.inl (hT h)))⟩ + · exact Or.inl ⟨hb, Or.inr (Or.inr (Or.inr (Or.inl h)))⟩ + · exact Or.inl ⟨hb, Or.inr (Or.inr (Or.inr (Or.inr h)))⟩ + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr (Or.inl h)) + · exact Or.inr (Or.inr (Or.inr h)) + +theorem SetsInHA.shrinkT2A {H : Heap} (hT : T2' ⊆ Z.T2) (h : SetsInHA Z H) : SetsInHA { Z with T2 := T2' } H := + ⟨fun p hp => h.pages p (by + rcases hp with ((hp | hp) | hp) | hp + · exact Or.inl (Or.inl (Or.inl hp)) + · exact Or.inl (Or.inl (Or.inr hp)) + · exact Or.inl (Or.inr (hT hp)) + · exact Or.inr hp), h.roots⟩ + +theorem UnmPtSpecA.shrinkT2A {m : Fl4SpecA64.McState} {OS : Set U64} {s : S} {σ : Fl4SpecA64.State Unit} + (hT : T2' ⊆ Z.T2) (h : UnmPtSpecA st Z m OS s σ) : UnmPtSpecA st { Z with T2 := T2' } m OS s σ := + ⟨fun u hu p asid va hc => let t := h.pt u hu p asid va hc; ⟨t.inv, t.spec, t.off.shrinkT2A hT⟩, + fun u hu p asid hc => let t := h.vs u hu p asid hc; ⟨t.inv, t.spec, t.off.shrinkT2A hT⟩, h.s2, h.hv⟩ + +theorem BufOffA.shrinkT2A {OS : Set U64} {s : S} {Bf : Set (U64 × Fl4SpecA64.Word)} (hT : T2' ⊆ Z.T2) + (h : BufOffA st Z OS s Bf) : BufOffA st { Z with T2 := T2' } OS s Bf := + ⟨h.os, h.vs, fun b hb p hp => h.page b hb p (SchedPageA.shrinkT2A st hT hp), h.vcw, h.pin⟩ + +end + +section arm +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +theorem ArchInvA.notPool {o : Fl4SpecA64.ArchKernelObj} {f : Fl4SpecA64.AsidPool} + (h : ArchInvA o (.asidPool f)) : False := by + cases o with + | asidPool g => simp [ArchInvA] at h + | pageTable t => obtain ⟨t', e, -⟩ := ArchInvA.pt h; cases e + | dataPage dv sz => simp [ArchInvA] at h + | vcpu v => simp [ArchInvA] at h + | ext x => + cases x with + | stage2Root e => obtain ⟨e', e2, -⟩ := ArchInvA.s2 h; cases e2 + | highVSpace e => obtain ⟨e', e2, -⟩ := ArchInvA.hi h; cases e2 + +/-- The footprint of `{ Z with S1 := ∅ }` is that of `extZA Z`, an Ext word, or a window's level-1 page word. -/ +theorem FootA.splitExtA {Z : XSetsA} {s : S} {w : U64} (h : FootA (L := L) { Z with S1 := ∅ } s w) : + FootA (L := L) (extZA Z) s w ∨ ExtFootE Z.X Z.Y Z.T2 w ∨ + ∃ y ∈ Z.Y, ∃ i : U64, i.val < 512 ∧ w = peAF (wa y 4096#u64) i := by + cases h with + | slot y w hy hw => exact Or.inl (.slot y w hy hw) + | nslot w h => + cases h with + | node c w hc hw => exact Or.inl (.nslot w (.node c w hc hw)) + | cur w hw => exact Or.inl (.nslot w (.cur w hw)) + | tcb t w ht hw => exact Or.inl (.nslot w (.tcb t w ht hw)) + | sc c hc => exact Or.inl (.nslot _ (.sc c hc)) + | vcpu v w hv hw => exact Or.inl (.nslot w (.vcpu v w hv hw)) + | irq i hi => exact Or.inl (.nslot _ (.irq i hi)) + | cur2 w hw => exact Or.inl (.nslot w (.cur2 w hw)) + | glob w hw => exact Or.inl (.nslot w (.glob w hw)) + | tcb2 t w ht hw => exact Or.inl (.nslot w (.tcb2 t w ht hw)) + | sc2 c hc => exact Or.inl (.nslot _ (.sc2 c hc)) + | vs w hw => + cases hw with + | asid hi h => exact Or.inl (.nslot _ (.vs _ (.asid hi h))) + | pool p lo hp h => exact Or.inl (.nslot _ (.vs _ (.pool p lo hp h))) + | pt p i hp h => exact absurd hp (Set.notMem_empty _) + | high y i hy h => exact Or.inr (Or.inr ⟨y, hy, i, h, rfl⟩) + | ext w hw => exact Or.inr (Or.inl hw) + +/-- **The unmapped Stage-2 table is off the shrunk footprint**: its pages are distinct from every other Stage-2 / +window page of the relation (`t2x`, `pgd`, `tal`), and off the rest of the footprint (`ExtTabOffA`). -/ +theorem TabOffA.ofExtT2 {Z : XSetsA} {m : Fl4SpecA64.McState} {s : S} {mem : U64 → U64} + {σ : Fl4SpecA64.State Unit} {p : U64} (hEO : ExtTabOffA (L := L) Z m s) + (E : ExtVsRelA Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 mem σ) (hyal : ∀ y ∈ Z.Y, 8192 ∣ y.val) (hp : p ∈ Z.T2) : + TabOffA (L := L) { Z with T2 := Z.T2 \ {p} } m s p := by + have hpa : 4096 ∣ p.val := E.tal p hp + have hy4 : ∀ y ∈ Z.Y, 4096 ∣ y.val := fun y hy => Nat.dvd_trans (by norm_num) (hyal y hy) + have hpY : p ∉ Z.Y := (E.pgd p (Or.inl hp)).2 + refine ⟨fun i hi hf => ?_, fun q hq hqe => ?_⟩ + · rcases FootA.splitExtA (Z := { Z with T2 := Z.T2 \ {p} }) hf with h | h | ⟨y, hy, j, hj, e⟩ + · exact hEO.mem p (Or.inl (Or.inl hp)) i hi h + · have key : ∀ b, ExtFootE Z.X Z.Y (Z.T2 \ {p}) b → b = peAF p i → False := by + intro b hb + cases hb with + | s2lo r j hr hj => + exact fun e => pgNeE hpa (al4kE (E.xal r hr)) hi hj (E.t2x p hp r hr).1 e.symm + | s2hi r j hr hj => + exact fun e => pgNeE hpa (al4kHiE (E.xal r hr)) hi hj (E.t2x p hp r hr).2 e.symm + | s2pt t j ht hj => + exact fun e => pgNeE hpa (E.tal t ht.1) hi hj (fun e' => ht.2 e'.symm) e.symm + | wl0 y hy => + exact fun e => pgNeE hpa (hy4 y hy) hi (by decide) (fun e' => hpY (by rw [e']; exact hy)) e.symm + | wlo y j hy hj => + exact fun e => pgNeE hpa (hy4 y hy) hi (by omega) (fun e' => hpY (by rw [e']; exact hy)) e.symm + exact key _ h rfl + · exact pgNeE hpa (al4kHiE (hyal y hy)) hi hj + (fun e' => (E.pgd p (Or.inl hp)).1 (by + show p ∈ VsPtA Z.Pp Z.S1 Z.Y + exact Or.inr (Or.inr ⟨y, hy, e'⟩))) e + · subst hqe + rcases hq with ⟨q', hq', e⟩ | ⟨t, ht, e⟩ | ⟨c, hc, e⟩ | ⟨v, hv, e⟩ | ⟨r, hr, e⟩ | ⟨y, hy, e⟩ | + ⟨q', hq', e⟩ | ⟨q', hq', e⟩ | ⟨t, ht, e⟩ + · exact hEO.obj p (Or.inr (Or.inr hp)) (Or.inl ⟨q', hq', e⟩) + · exact hEO.obj p (Or.inr (Or.inr hp)) (Or.inr (Or.inl ⟨t, ht, e⟩)) + · exact hEO.obj p (Or.inr (Or.inr hp)) (Or.inr (Or.inr (Or.inl ⟨c, hc, e⟩))) + · exact hEO.obj p (Or.inr (Or.inr hp)) (Or.inr (Or.inr (Or.inr (Or.inl ⟨v, hv, e⟩)))) + · exact (E.t2x p hp r hr).1 (specPtr_inj e).symm + · exact hpY ((specPtr_inj e) ▸ hy) + · exact hEO.obj p (Or.inr (Or.inr hp)) + (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨q', hq', e⟩))))))) + · exact absurd hq' (Set.notMem_empty _) + · exact ht.2 (specPtr_inj e) + +theorem SchedPageA.backPtT2A {Z : XSetsA} {T2' OS : Set U64} {s s' : S} {q x p : U64} + (hnew : capA st s' x = .PageTable p false 0#u64 0#u64) + (hkeep : ∀ u ∈ OS, u ≠ x → capA st s' u = capA st s u) (hp : p ∈ Z.T2) (hT : T2' ⊆ Z.T2) + (h : SchedPageA st { Z with T2 := T2' } OS s' q) : SchedPageA st Z OS s q := by + have h := SchedPageA.shrinkT2A st hT h + unfold SchedPageA at h ⊢ + rcases h with h | h | h | h | h | h | h | ⟨u, hu, h⟩ + · exact Or.inl h + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr (Or.inl h)) + · exact Or.inr (Or.inr (Or.inr (Or.inl h))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))))) + · by_cases e : u = x + · subst e + rcases h with ⟨m, a', v', h⟩ | ⟨m, a', h⟩ | ⟨a', v', h⟩ | ⟨q', a', v', h, e'⟩ | ⟨y, a', h, e'⟩ <;> + rw [hnew] at h <;> cases h + exact Or.inr (Or.inr (Or.inl hp)) + · rw [hkeep u hu e] at h + exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨u, hu, h⟩)))))) + +set_option maxHeartbeats 8000000 in +/-- **`JStage3A` across the `ARMPageTableUnmap` arm of a final mapped page-table cap of a Stage-2 table +(`ptr ∈ Z.T2`)**: FL4's decode succeeds, the spec performs `performExtVSpace`'s `tableUnmap` (512 invalid `storePte`s, +the cap write), and the record holds at the final state **with the ghost `T2` shrunk to `Z.T2 \ {ptr}`** (so J9's +`UnmTabA.off` of the new unmapped cap's table holds). The final-state facts owed at T3 (`SysL`, `BXI` at some `Ac'`, +`UserOK`, J7 at the shrunk ghost) are the arm hypothesis `fin`. + +* `hno` (derived at the site, `JSyscallA.finPtOtherA`): no other slot names the table (the cap is final). +* **[J] `hUniq`** (case premise, guarded by the reached run: the unmap run `vspace.unmap_page_table` from the restart + state returns `(s2, a2)`; the word is an entry of a table reachable from an active Stage-2 root at the entry + state `σ`): a reachable valid table descriptor naming `ptr` is zeroed by the unmap (the unique-reference fact J7's + `S2Ty` does not give; the reachability guard is needed for stale roots after `delete_asid`). -/ +theorem JStage3A.ptUnmapT2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + (K : ArchKeepsA ar AR) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) + (hEO : ExtTabOffA (L := L) Z m s) + (hK : Aligned (L.ksb s)) (hT : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s)) (hIpa : S2IpaE ar a) + (length buf : U64) (ex : Aeneas.Std.Array obj.Slot 3#usize) + (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (ptr asid va : U64) + (hpT : ptr ∈ Z.T2) + (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) + (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (k : Fl4SpecA64.ExtRootKind) (hkR : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some k) + (hkR1 : k ≠ .stage1) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) + (hUniq : ∀ (s2 : S) (a2 : A), + vspace.unmap_page_table st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a asid va ptr = ok (s2, a2) → + ∀ w, S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART)) σ w → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 0 = true → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 1 = true → + dTabA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) = ptr → L.mem s2 w = 0#u64) + (fin : ∀ (x : Fl4SpecA64.Tcb) (s3 : S) (σ3 : Fl4SpecA64.State Unit) (a' : A), + σ.kheap σ.curThread = some (.tcb x) → + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap length (cslotAddrA cte) + (.PageTable ptr true asid va) buf ex = ok (core.result.Result.Ok (), s3, a') → + (([] : List Fl4SpecA64.Data), σ3) ∈ (Fl4SpecA64.performExtVSpace (Z := Unit) (.tableUnmap k (.pageTableCap + (specPtr ptr) .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte) (stUpdA σ σ.curThread x .restart)).1 → + ∃ Ac' : Set U64, SysL st H Z.Cs OS ia ie s3 ∧ SymL st H Z.Cs s3 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s3 ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s3 ∧ + J7A st (J7R2A st ar nA) { Z with T2 := Z.T2 \ {ptr} } H OS s3 σ3 m) : + ∃ (x : Fl4SpecA64.Tcb) (s3 : S) (a' : A) (σ3 : Fl4SpecA64.State Unit) (Ac' : Set U64), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap length (cslotAddrA cte) + (.PageTable ptr true asid va) buf ex = ok (core.result.Result.Ok (), s3, a') ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ (Fl4SpecA64.performExtVSpace (Z := Unit) (.tableUnmap k (.pageTableCap + (specPtr ptr) .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte) (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with T2 := Z.T2 \ {ptr} } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s3 a' σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + have hx : cslotAddrA cte ∈ OS := RS.sub _ (hab.isSlot J.j.1.place) + have hO : OSOK H.tcbs H.omega H.frame OS := J.sys.ent.os + have E0 := J.toJEntA + have hp4 : ptr.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd (J.j.1.ext.tal ptr hpT) + have hT' : Z.T2 \ {ptr} ⊆ Z.T2 := fun _ hx => hx.1 + have hxp : XqA Z ptr := Or.inl (Or.inl hpT) + obtain ⟨x, hk, heq, hset, J1, -, hOS1, -⟩ := J.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have hks : L.ksb (L.wr s (stA (L.curW s)) sched.TS_RESTART) = L.ksb s := L.ksb_wr _ _ _ + have hcpu : L.cpu (L.wr s (stA (L.curW s)) sched.TS_RESTART) = L.cpu s := L.cpu_wr _ _ _ + generalize L.wr s (stA (L.curW s)) sched.TS_RESTART = s1 at heq J1 hOS1 hks hcpu hUniq + have c1 : capA st s1 (cslotAddrA cte) = .PageTable ptr true asid va := (hOS1.capA hx).trans hcap + obtain ⟨c0, -, hrel0⟩ := StateRelA.getAbsA J1.j.1.st hab + have c1' : capAtA (L.mem s1) (cslotAddrA cte) = .PageTable ptr true asid va := c1 + rw [c1'] at hrel0 + obtain ⟨h16a, -⟩ := hrel0 + have h16 : asid.val < 65536 := lt_of_lt_of_eq h16a (by norm_num) + have hEnc0 : CapRt.EncWf (capAtA (L.mem s1) (cslotAddrA cte)) := CapRt.decodeF_encWf _ _ + rw [c1'] at hEnc0 + simp only [CapRt.EncWf] at hEnc0 + have hEnc : CapRt.EncWf (.PageTable ptr false 0#u64 0#u64) := by + simp only [CapRt.EncWf]; exact ⟨hEnc0.1, by simp, Or.inl fun j hj _ => by simp⟩ + have hca : CapRelA (.PageTable ptr false 0#u64 0#u64) + (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT none)) := + ⟨show (0#u64 : U64).val < 2 ^ 16 by simp, rfl⟩ + have hok : CapObjOkA Z (.PageTable ptr false 0#u64 0#u64) := + ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), + fun _ _ _ h => (by cases h), trivial⟩ + have hTr : TreeA st OS Z.G.chains Z.G.par s1 := + J1.j.1.cdt.tree.grow J1.j5.2.1 (fun x hx hn => J1.j5.2.2 x hx hn) + have hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s1 y = .Null := J1.j5.2.2 + have hTr0 : TreeA st OS Z.G.chains Z.G.par s := + J.j.1.cdt.tree.grow J.j5.2.1 (fun x hx hn => J.j5.2.2 x hx hn) + have hnul0 : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null := J.j5.2.2 + have E1 := J1.toJEntA + have hN := bxi_nodes E1.sys.ent.bxi + have hpOS := VsPgOffOSA.of_apA E1.ap + have hirq : CapOkA (stUpdA σ σ.curThread x .restart).interruptIrqNode cte + (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT none)) := by + refine ⟨fun irq hlt e => ?_, fun ⟨_, _, _, _, e⟩ => by cases e⟩ + have obj : ∃ o ac, (stUpdA σ σ.curThread x .restart).kheap cte.1 = some o ∧ + Fl4SpecA64.capOf o cte.2 = some ac ∧ CapRelA (capAtA (L.mem s1) (cslotAddrA cte)) ac := by + obtain ⟨o, idx⟩ := cte + obtain ⟨p, e1, hc | ⟨ht, i, hi, e2⟩⟩ := hab + · simp only at e1 hc; subst e1 + obtain ⟨cs, hk, -, hr⟩ := J1.j.1.st.cnode p _ hc + obtain ⟨ac, hac, hrel⟩ := hr idx rfl + exact ⟨_, ac, hk, hac, hrel⟩ + · simp only at e1 e2; subst e1 e2 + obtain ⟨y, hk, hr⟩ := J1.j.1.st.tcb p ht + obtain ⟨ac, hac, hrel⟩ := hr i hi + refine ⟨_, ac, hk, hac, ?_⟩ + unfold cslotAddrA; rw [ofBl_tcbIdx i (by unfold tcbSlotsA at hi; omega)]; exact hrel + obtain ⟨o, ac, hko, hco, hrel⟩ := obj + rw [e] at hko + rw [c1'] at hrel + rcases J1.sinv.irqN.slot irq hlt o _ ac hko hco with rfl | ⟨_, _, _, rfl⟩ + · cases hrel.2 + · cases hrel.2 + have hsci : NoIdleCapV m n (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT none)) := + ⟨fun _ _ e => (by cases e), fun _ e => (by cases e), fun _ _ _ e => (by cases e)⟩ + have hno1 : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s1 y ≠ .PageTable ptr mp a0 v0 := + fun y hy e mp a0 v0 h => hno y hy e mp a0 v0 ((hOS1.capA hy).symm.trans h) + have main := J1.of_capVsFrameGA (hS := fun _ h => h) + (hT2 := fun y hy e p0 a0' v0' hc hp0 => ⟨hp0, fun h => by + have e0 := Set.mem_singleton_iff.1 h + subst e0 + exact hno1 y (RS.sub y hy) e true a0' v0' hc⟩) + (hpt := fun _ _ _ h => by cases h) (S1' := Z.S1) (T2' := Z.T2 \ {ptr}) (Zl' := Z.Lv) (Sh2' := Z.Sh2) + (Tb' := Tb) (Lv' := Lv) + (Q := fun s' a' σ' hw => vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap length + (cslotAddrA cte) (.PageTable ptr true asid va) buf ex = ok (core.result.Result.Ok (), s', a') ∧ + (([] : List Fl4SpecA64.Data), σ') ∈ (Fl4SpecA64.performExtVSpace (Z := Unit) (.tableUnmap k (.pageTableCap + (specPtr ptr) .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte) (stUpdA σ σ.curThread x .restart)).1 ∧ hw = Z.hw) + RS.sub (footNOff_ksA rfl rfl (footN_offA E1)) (footNAl_ksA rfl rfl (FootNA.aligned E1.j.1 hN E1.scAl E1.ap.vcAl)) + cte hab hEnc hca hTr hnul (fun h => by cases h) (by rw [c1]; exact fun h => by cases h) + (c := .PageTable ptr false 0#u64 0#u64) (by rw [c1]; exact .pt ..) hok hirq hsci + (fun s2 σ2 hs2 hσ2 HSs w jx hcx => by + have hkR' : Fl4SpecA64.asidRootKind (stUpdA σ σ.curThread x .restart) (BitVec.ofNat 16 asid.val) = some k := by + rw [asidRootKind_stUpdA hk]; exact hkR + obtain ⟨σu, fk, hfk, hperfE, hU, QU, IU⟩ := perform_tabUnmapXB (ar := ar) (a := a) E1.j.1.vs E1.j.1.ext + (by rw [hks]; exact hK) (by rw [hks]; exact hT) E1.j.2.2.1.obj hIpa h16 va ptr k hkR' hkR1 cte + obtain ⟨s2u, fa, hfl, hu, J2, hk2, hks2, hcpu2, hcase⟩ := unmap_post2JA hfk E1.j + (FootA.aligned E1.j.1 hN E1.scAl E1.ap.vcAl) (fun q hq => (hTO q hq).of_ksA hks hcpu) + (hEO.of_ksA hks hcpu) E1.sys.ent.os hpOS hU + have hks2' : L.ksb s2u = L.ksb s := hks2.trans hks + have hcpu2' : L.cpu s2u = L.cpu s := hcpu2.trans hcpu + have hN2 : ∀ c ∈ Z.Cs, ∀ o : U64, o.val < 4288 → o.val % 8 = 0 → Aligned (L.nodeAt s2u c o) := + fun c hc o h1 h2 => by rw [nodeAt_ksb hks2]; exact hN c hc o h1 h2 + obtain ⟨t', hty', hinv', hrun0, hz0, J5, hk3, hks3, hcpu3⟩ := zero_post2A J2 + (FootA.aligned J2.1 hN2 E1.scAl E1.ap.vcAl) (fun q hq => (hTO q hq).of_ksA hks2' hcpu2') + (hEO.of_ksA hks2' hcpu2') (by rw [hks2']; exact hK) (by rw [hks2']; exact hT) hO hpOS (Or.inr hpT) + have UQz : UnQ σu (ptSetA σu (specPtr ptr) t') := by + have hm0 := OutQ.mapMx UnQ.refl trQ (fun sl => storePte_unQ .normalPtT sl) + (Fl4SpecA64.uptoEnumStep (specPtr ptr) (specPtr ptr + ((1 : Fl4SpecA64.Word) <<< Fl4SpecA64.pteBits)) + (specPtr ptr + Fl4SpecA64.mask (Fl4SpecA64.ptBits .normalPtT))) σu ((), ptSetA σu (specPtr ptr) t') + rw [hrun0] at hm0 + exact hm0 (Set.mem_singleton _) + have Q5 : QvA (stUpdA σ σ.curThread x .restart) (ptSetA σu (specPtr ptr) t') := QU.trans UQz.1 + have I5 : InvXA (stUpdA σ σ.curThread x .restart) (ptSetA σu (specPtr ptr) t') := IU.trans UQz.2.toX + obtain ⟨s5, σ6, hsc, -, hσ6, HSu, J6, T6⟩ := setcap_core2A E0 RS J5 + ((hOS1.trans' hk2).trans' hk3) (hks3.trans hks2') (hcpu3.trans hcpu2') cte hab hcap hEnc hca + (UA.of_shapeA rfl fun h => by cases h) hok (fun h => by cases h) (fun h => by cases h) hTr0 hnul0 + have hperf : (([] : List Fl4SpecA64.Data), σ6) ∈ (Fl4SpecA64.performExtVSpace (Z := Unit) (.tableUnmap k + (.pageTableCap (specPtr ptr) .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte) + (stUpdA σ σ.curThread x .restart)).1 := by + rw [hperfE, nd_bind_oneD hrun0] + exact ⟨((), σ6), hσ6, rfl⟩ + obtain ⟨a', hfa', hAR⟩ := spec_ex_fd (hfl.arA K J6.1.ar) + have J6' := J6.of_arA hAR + have hdec' : vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap length (cslotAddrA cte) + (.PageTable ptr true asid va) buf ex = ok (core.result.Result.Ok (), s5, a') := by + rw [pt_unmap_eqA ar s a length (cslotAddrA cte) ptr asid va buf ex hf, heq, bind_ok] + refine (then_setcapA (then_zeroA hu ptr) hsc).trans ?_ + rw [hfa', bind_ok] + obtain ⟨Ac', hsl, hsy, hbx, hus, hj7⟩ := fin x s5 σ6 a' hk hdec' hperf + have al_x : Aligned (cslotAddrA cte) := hO.al0 hx + have al_x8 : Aligned (wa (cslotAddrA cte) 8#u64) := hO.al hx (k := 8#u64) (by simp) (by simp) + obtain ⟨w0, w1, hen, -⟩ := CapRt.decode_encode _ hEnc + have hpl : ptr.val < 2 ^ 64 := ptr.bv.isLt + have hfit : ptr.val + (4096#u64 : U64).val ≤ 2 ^ 64 := by + show ptr.val + 4096 ≤ 2 ^ 64; simp only [Nat.reducePow] at hpl ⊢; omega + have wU : WritesIn st s1 s2u (fun b => ∃ q j : U64, XqA Z q ∧ j.val < 512 ∧ b = peAF q j) := by + rcases hcase with rfl | ⟨q, j, hq, hj, hal, rfl⟩ + · exact WritesIn.refl _ _ + · exact (writesIn_wr hal).mono fun b hb => ⟨q, j, hq, hj, hb⟩ + have wZ : WritesIn st s2u (L.zr s2u ptr 4096#u64) (fun b => ∃ q j : U64, XqA Z q ∧ j.val < 512 ∧ b = peAF q j) := + WritesIn.monoA (writesIn_zrV (st := st) (s := s2u) (show ptr.val % 8 = 0 by omega) (by simp) hfit) fun b hb h => by + obtain ⟨i, hi, e⟩ := peAF_ofRangeA hp4 hb h.1 h.2 + exact ⟨ptr, i, hxp, hi, e⟩ + have wV := wU.trans1 wZ + have wS := writesIn_setCapA al_x al_x8 hsc + have w2 := WritesIn.setCapCommA al_x al_x8 hen hs2 hsc wV + have hk3' : L.ksb s5 = L.ksb s1 := wS.1.trans (hks3.trans hks2) + have hcpu5 : L.cpu s5 = L.cpu s1 := wS.2.1.trans (hcpu3.trans hcpu2) + obtain ⟨Pt, Ub, vr, -, -, -, -, -, -, link, -, -⟩ := J1.j7 + obtain ⟨Qb, Rb, q⟩ := J1.sys.ent.bxi.1 + have vo : VrOK H.omega H.frame H.scs H.scBits OS Z.V ∅ (L.ksb s1) (utVsPtA st Pp Tb Lv s1) := J1.vsOk + have Psp : ∀ b, (∃ q j : U64, XqA Z q ∧ j.val < 512 ∧ b = peAF q j) → VsR (L.ksb s1) Pt b := + fun b ⟨q, j, hq, hj, e⟩ => by rw [e]; exact vsW_pageA link hq.sched hj + have hzG : ∀ Pt' : Set U64, (∀ b, VsR (L.ksb s1) Pt' b → Aligned b) → + (∀ b, VsR (L.ksb s1) Pt' b → ¬ InOS OS b) → VsZ st (L.ksb s1) Pt' s1 s5 := fun Pt' hal hos b hb => by + have hb1 := hal b hb + have hns : ¬ SlotWordA (cslotAddrA cte) b := fun h => hos b hb (slotWord_inOS hO hx h) + rw [wS.mem_eq hb1 hns] + rcases zr_caseA (st := st) (s := s2u) hp4 hb1 with e | e + · exact Or.inr e + · rw [e] + rcases hcase with rfl | ⟨q, j, hq, hj, hal', rfl⟩ + · exact Or.inl rfl + · by_cases e : peAF q j = b + · subst e; exact Or.inr (L.mem_wr_same hal') + · exact Or.inl (L.mem_wr_ne hal' hb1 (fun h => e (UScalar.eq_of_val_eq h))) + have hAsK : ∀ b, AsW (L.ksb s1) b → L.mem s5 b = L.mem s1 b := fun b hb => by + have hnP : ¬ ∃ q j : U64, XqA Z q ∧ j.val < 512 ∧ b = peAF q j := fun ⟨q, j, hq, hj, e⟩ => + hq.offAs hT hj (by rw [← e, ← hks]; exact hb) + have hns : ¬ SlotWordA (cslotAddrA cte) b := fun h => vo.os b (Or.inr hb) (slotWord_inOS hO hx h) + exact (wS.mem_eq (vo.al b (Or.inr hb)) hns).trans (wV.mem_eq (vo.al b (Or.inr hb)) hnP) + have vsT := VsTyR.zeroStepA hk3' hAsK (hzG _ vo.al vo.os) J1.sys.ent.vs + have osk3 : OSKeep st OS s2 s5 := + osKeep_ofA hO fun w' hw' hin => w2.mem_eq hw' (fun hp => vr.os w' (Psp w' hp) hin) + obtain ⟨hcx', hco⟩ := capA_setCapA hO hx hEnc hs2 + have capE3 : ∀ u ∈ OS, capA st s5 u = capA st s2 u := fun u hu => osk3.capA hu + have hnew : capA st s5 (cslotAddrA cte) = .PageTable ptr false 0#u64 0#u64 := by rw [capE3 _ hx, hcx] + have hkeep : ∀ u ∈ OS, u ≠ cslotAddrA cte → capA st s5 u = capA st s1 u := fun u hu e => by + rw [capE3 u hu, hco u hu e] + have hMs2 : ∀ u ∈ OS, MapAlikeA (capA st s2 u) (capA st s1 u) := fun u hu => by + by_cases e : u = cslotAddrA cte + · subst e; rw [hcx, c1]; exact .pt .. + · rw [hco u hu e]; exact .refl _ + have sbS : ∀ t ∈ Z.T, sbWordA t ∈ OS := fun t ht => + RS.sub _ ⟨t, Or.inr ⟨(J1.j.1.thT t).2 ht, 2, by simp [tcbSlotsA], (bufSlot_eqA t).symm⟩⟩ + have wA : WritesIn st s1 s2 (fun b => Aligned b ∧ W7.CapW H.tcbs {b | InOS OS b} ∅ b) := writesIn_alAG w + have hB : ∀ b, (Aligned b ∧ W7.CapW H.tcbs {b | InOS OS b} ∅ b) → W7.CapW H.tcbs H.omega H.frame b := + fun b hb => os_capw hO hb.1 hb.2 + obtain ⟨-, -, -, -, -, fld, -, -⟩ := W7.blk_of_capw (BXI.blk J1.sys.ent.bxi) wA hB + have ib : ∀ t ∈ Z.T, L.mem s2 (ibWordA t) = L.mem s1 (ibWordA t) := fun t ht => + fld t (by rw [J1.tcbs]; exact ht) 3512#u64 (by simp) (by simp) (by simp) + have HS2 : VsSpecA σ2 σ6 := (VsSpecA.of_invX Q5 I5).setCapCommA hσ2 hσ6 + have offT : ∀ b, (∃ q j : U64, XqA Z q ∧ j.val < 512 ∧ b = peAF q j) → ∀ t ∈ Z.T, + b.val < t.val ∨ t.val + 4096 ≤ b.val := fun b hb t ht => by + have hth : t ∈ H.tcbs := by rw [J1.tcbs]; exact ht + have := (q.omega b (vr.om b (Psp b hb))).2.1 t hth + omega + have tw : ∀ t ∈ Z.T, ∀ K : U64, K.val + 8 ≤ 4096 → K.val % 8 = 0 → + L.mem s5 (wa t K) = L.mem s2 (wa t K) := by + intro t ht K hK' h8 + have hta := J1.sr.core.tcbs t ht + have hv : (wa t K).val = t.val + K.val := field_val hta (K := K) (by omega) + refine w2.mem_eq (field_aligned hta (by omega) h8) (fun h => ?_) + have := offT _ h t ht + omega + have hib : ∀ t ∈ Z.T, IbSame (L := L) s2 s5 t := fun t ht => by + refine ⟨tw t ht _ (by simp) (by simp), ?_, ?_⟩ + · rw [sbWordA_eq]; exact tw t ht _ (by simp) (by simp) + · rw [sbWordA8_eq]; exact tw t ht _ (by simp) (by simp) + have hj7' := hj7 + obtain ⟨Pt', Ub', vr', -, ac', -⟩ := hj7' + have hBw : ∀ b, ((∃ q j : U64, XqA Z q ∧ j.val < 512 ∧ b = peAF q j) ∨ SlotWordA (cslotAddrA cte) b) → + L.Free s1 H.omega Z.Cs b ∨ W7.TLow H.tcbs b := fun b hb => by + rcases hb with hp | hsl + · exact Or.inl (Or.inl (vr.om b (Psp b hp))) + · have hal : Aligned b := by rcases hsl with rfl | rfl; exact al_x; exact al_x8 + exact (os_capw hO hal (Or.inr ⟨slotWord_inOS hO hx hsl, Set.notMem_empty _⟩)).elim Or.inr + fun h' => Or.inl (Or.inl h'.1) + have hsp : ∀ q', SchedPageA st { Z with T2 := Z.T2 \ {ptr} } OS s5 q' → SchedPageA st Z OS s1 q' := + fun q' h => SchedPageA.backPtT2A (Z := Z) hnew hkeep hpT hT' h + have G := JStage3A.keepGhostA (hw := Z.hw) (s' := s5) J1 hk3' hcpu5 + have hrel5 : ∀ q, XqA Z q → ∀ j : U64, j.val < 512 → + L.mem s5 (peAF q j) = L.mem s1 (peAF q j) ∨ L.mem s5 (peAF q j) = 0#u64 := fun q hq j hj => + hzG Pt vr.al vr.os _ (Or.inl ⟨q, link q hq.sched, core.num.U64.wrapping_mul j 8#u64, + by rw [wm8_valA hj]; omega, by rw [wm8_valA hj]; omega, rfl⟩) + have hs5 : ∀ q, XqA Z q → ∀ j : U64, j.val < 512 → + L.mem s5 (peAF q j) = 0#u64 ∨ L.mem s5 (peAF q j) = L.mem s2u (peAF q j) := by + intro q hq j hj + have hv : VsR (L.ksb s1) Pt (peAF q j) := Psp _ ⟨q, j, hq, hj, rfl⟩ + have hb1 := vr.al _ hv + have hns : ¬ SlotWordA (cslotAddrA cte) (peAF q j) := fun h => vr.os _ hv (slotWord_inOS hO hx h) + rw [wS.mem_eq hb1 hns] + exact zr_caseA (st := st) (s := s2u) hp4 hb1 + have hAT : σ6.archState.armAsidTable = σ.archState.armAsidTable := by + rw [setCap_archA hσ6]; exact Q5.asidTable + have hpool : ∀ (p : U64) f, σ6.kheap (specPtr p) = some (.archObj (.asidPool f)) → + σ.kheap (specPtr p) = some (.archObj (.asidPool f)) := fun p f hk6 => by + have h1 := HSu.back hk6 (fun _ _ e => by cases e) (fun _ e => by cases e) + have h2 : (stUpdA σ σ.curThread x .restart).kheap (specPtr p) = some (.archObj (.asidPool f)) := by + rcases I5 (specPtr p) with e | ⟨o, o', a0, b0, hn⟩ + · exact e.symm.trans h1 + · rw [h1] at b0 + have e2 : o' = .asidPool f := by + have := Option.some.inj b0 + injection this with h4 + exact h4.symm + subst e2 + exact (ArchInvA.notPool hn).elim + exact stUpd_back h2 (fun y e => by cases e) + have hAct : ∀ r, ActiveS2RootA Z.Pp Z.X σ6 r → ActiveS2RootA Z.Pp Z.X σ r := + fun r ⟨hr, asid', p, f, h0, hp, ht, hk6, hf'⟩ => + ⟨hr, asid', p, f, h0, hp, by rw [← hAT]; exact ht, hpool p f hk6, hf'⟩ + have hMq : ∀ q ∈ S2PgE Z.X Z.T2, ∀ j : U64, j.val < 512 → L.mem s5 (peAF q j) ≠ 0#u64 → + L.mem s1 (peAF q j) = L.mem s5 (peAF q j) := fun q hq j hj hne => by + rcases hrel5 q (Or.inl hq) j hj with e | e + · exact e.symm + · exact absurd e hne + have hzd0 : dBitA (0#u64) 0 = false := by unfold dBitA; rfl + have hunm : vspace.unmap_page_table st ar s1 a asid va ptr = ok (s2u, a') := by + rw [hu, hfa', bind_ok] + have hno5 : ∀ w, S2EntryA Z.Pp Z.X (Z.T2 \ {ptr}) Z.Sh2 (L.mem s5) σ6 w → + dBitA (L.mem s5 w) 0 = true → dBitA (L.mem s5 w) 1 = true → dTabA (L.mem s5 w) ≠ ptr := by + intro w hw hb0 hb1' hn + have M5ne : L.mem s5 w ≠ 0#u64 := fun h0 => by rw [h0, hzd0] at hb0; cases hb0 + have key : ∃ q j : U64, q ∈ S2PgE Z.X Z.T2 ∧ j.val < 512 ∧ w = peAF q j ∧ + S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem s1) σ w := by + rcases hw with ⟨r, i, hact, hi, hwe⟩ | ⟨t, i, hreach, ht', h12, hi, hwe⟩ + · obtain ⟨q, j, hq, hj, e⟩ := rootWordE (J.j.1.ext.xal r hact.1) + (show i.val < 1024 by have := s2GeomNumE.2.2.1; omega) + exact ⟨q, j, Or.inr ⟨r, hact.1, hq⟩, hj, hwe.trans e, Or.inl ⟨r, i, hAct r hact, hi, hwe⟩⟩ + · refine ⟨t, i, Or.inl ht'.1, hi, hwe, Or.inr ⟨t, i, ?_, ht'.1, h12, hi, hwe⟩⟩ + exact S2ReachA.backE hT' J.j.1.ext.xal hAct (fun q hq j hj hne => hMq q hq j hj hne) hreach + obtain ⟨q, j, hXq, hj, hwq, hent⟩ := key + have M5q : L.mem s5 (peAF q j) ≠ 0#u64 := by rw [← hwq]; exact M5ne + have e1 : L.mem s1 w = L.mem s5 w := by rw [hwq]; exact hMq q hXq j hj M5q + have hu0 := hUniq s2u a' hunm w hent (by rw [e1]; exact hb0) (by rw [e1]; exact hb1') (by rw [e1]; exact hn) + rcases hs5 q (Or.inl hXq) j hj with e5 | e5 + · exact M5ne (by rw [hwq]; exact e5) + · exact M5ne (by rw [hwq, e5, ← hwq]; exact hu0) + have ER' := ExtVsRelA.shrinkT2E J6'.1.ext hno5 + -- the new cap's table + have hz5 : ∀ i : U64, i.val < 512 → L.mem s5 (peAF ptr i) = 0#u64 := fun i hi => by + have hv : VsR (L.ksb s1) Pt (peAF ptr i) := vsW_pageA link hxp.sched hi + rw [wS.mem_eq (vr.al _ hv) (fun h => vr.os _ hv (slotWord_inOS hO hx h))] + exact hz0 i hi + have htab : UnmTabA st { Z with T2 := Z.T2 \ {ptr} } m s5 σ6 .normalPtT ptr := by + refine ⟨fun i hi => by rw [hz5 i hi]; unfold dBitA; rfl, ⟨t', ?_, hty', hinv'⟩, + (TabOffA.ofExtT2 hEO E1.j.1.ext J.j.1.vs.yal hpT).of_ksA (hk3'.trans hks) (hcpu5.trans hcpu)⟩ + have h1 : (ptSetA σu (specPtr ptr) t').kheap (specPtr ptr) = some (.archObj (.pageTable t')) := by + rw [ptSetA_kheap, if_pos rfl] + exact HSu.keep h1 (fun _ _ e => by cases e) (fun _ e => by cases e) + refine ⟨s5, a', σ6, Z.hw, fun b => ∃ q j : U64, XqA Z q ∧ j.val < 512 ∧ b = peAF q j, Ac', + ⟨w2, fun Pt'' Ub'' vr'' link'' b ⟨q, j, hq, hj, e⟩ => by rw [e]; exact vsW_pageA link'' hq.sched hj, + fun b ⟨q, j, hq, hj, e⟩ hbuf => J1.bufOff.page b hbuf q hq.sched + (core.num.U64.wrapping_mul j 8#u64) (by rw [wm8_valA hj]; omega) (by rw [wm8_valA hj]; omega) + (by rw [e]; rfl), + HS2, ?_, ?_, J6'.shrinkT2A ER', ⟨⟨J1.sys.ent.heap, hbx, hO, hus, vsT.1, by rw [hk3']; exact J1.sys.ent.ksw⟩, hsl⟩, + UtVsOkA.zeroStepA hk3' vsT.2 J1.vsOk, bufVs_subA J1.bufVs hk3' vsT.2, + W7.inv_of_capw J1.sq (wV.trans wS) hBw, ac'.case.po, + ?_, ?_, ?_, ?_, hj7, + fun h p0 bytes hp0 => h p0 bytes (JointObjectA.shrinkT2A (Z := Z) hT' hp0), + fun h => ⟨h.vcpu, h.reply, h.asid, h.tvcpu, h.vcDeadRun, h.replyTcb⟩, + fun h => ⟨fun u hu q0 b0 fi hc p0 bytes hp0 => + h.obj u hu q0 b0 fi hc p0 bytes (JointObjectA.shrinkT2A (Z := Z) hT' hp0), h.ks, h.idle, h.sep⟩, + fun h => h, + ⟨G.1.sca, G.1.irqSt, G.1.vcAl, G.1.vc, G.1.vs, fun b hb => G.1.ext b (ExtFootE.shrinkT2A hT' hb)⟩, + J1.s1, J1.ptH, SetsInHA.shrinkT2A (Z := Z) hT' G.2.2.1, G.2.2.2.1, + fun q hq => TabOffA.shrinkT2A (Z := Z) hT' (G.2.2.2.2.1 q hq), + ExtTabOffA.shrinkT2A (Z := Z) hT' G.2.2.2.2.2, hsy⟩, hdec', hperf, rfl⟩ + · rw [setCap_archA hσ6, setCap_archA hσ2]; exact Q5.asidTable + · intro p dv pg h + have h1 : (stUpdA σ σ.curThread x .restart).kheap p = some (.archObj (.dataPage dv pg)) := + HSs.back h (fun _ _ e => by cases e) (fun _ e => by cases e) + have h2 : (ptSetA σu (specPtr ptr) t').kheap p = some (.archObj (.dataPage dv pg)) := by + rcases I5 p with e | ⟨o, o', a0, b0, hn⟩ + · exact e.trans h1 + · rw [h1] at a0 + have h3 : o = .dataPage dv pg := by + have := Option.some.inj a0 + injection this with h4 + exact h4.symm + subst h3 + exact absurd hn (by simp [ArchInvA]) + exact HSu.keep h2 (fun _ _ e => by cases e) (fun _ e => by cases e) + · exact BufCover.vsA (BufCover.mapA J1.bufCover J1.bufNative J1.j.1.st jx.1.st (fun t ht => (J1.j.1.thT t).2 ht) + HSs ib (fun t ht => hMs2 _ (sbS t ht))) HS2 hib + · exact BufNativeA.mapA J1.bufNative (fun t ht q' sz' rr dv' m' e' a'' v' h => by + by_cases e1 : sbWordA t = cslotAddrA cte + · rw [e1, hnew] at h; cases h + · rw [hkeep _ (sbS t ht) e1] at h + have hn := J1.bufNative t ht + rw [bufSlot_eqA, capAtA_eq (st := st), h] at hn + exact hn) + · exact UnmPtSpecA.ofPtUnmMA (Z := { Z with T2 := Z.T2 \ {ptr} }) (Pt := Pt) hnew hkeep + (fun q' hq i hi => hzG Pt vr.al vr.os _ (Or.inl ⟨q', hq, core.num.U64.wrapping_mul i 8#u64, + by rw [wm8_valA hi]; omega, by rw [wm8_valA hi]; omega, rfl⟩)) + (fun q hq => link q (SchedPageA.shrinkT2A st hT' hq)) hk3' hcpu5 I5 + (fun q' ao h => HSu.keep h (fun _ _ e => by cases e) (fun _ e => by cases e)) + htab (J1.unmPt.shrinkT2A hT') + · exact ⟨J1.bufOff.os, fun b hb => by rw [hk3']; exact J1.bufOff.vs b hb, + fun b hb q' hq => J1.bufOff.page b hb q' (hsp q' hq), J1.bufOff.vcw, + fun bp hbp => (J1.bufOff.pin bp hbp).keepM fun u hu => by rw [capE3 u hu]; exact hMs2 u hu⟩) + obtain ⟨s2, σ2, s3, a3, σ3, hw, P, Ac', hs2, hσk, HSsk, HSvk, HSc, wT, Jf, hdec, hperf, hhw⟩ := main + subst hhw + exact ⟨x, s3, a3, σ3, Ac', hk, hset, hdec, hperf, Jf, + (Sched.BodyKeepA.ofSlot HSsk (setCap_keepsA hσk).2.2).trans (Sched.BodyKeepA.ofVs HSvk)⟩ + + + +end arm + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3BodyOKA.lean b/proofs/Fl4ProofsA64/P3/Stage3BodyOKA.lean index 53739702b..fd49cda75 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3BodyOKA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3BodyOKA.lean @@ -198,9 +198,9 @@ theorem BodyOKA.ofRestart (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp /-- **The `CUR_THREAD` word from the spec current thread** (module docstring). -/ theorem curW_keptA {Z' : XSetsA} {H' : Heap} {OS' U' Ac' Pp' Tb' : Set U64} {Lv' : U64 → Nat} {ia' ie' : Nat} {N' E' Rp' : Set U64} {Bf' : Set (U64 × Fl4SpecA64.Word)} {stack' : U64 → List U64} {κ' : U64 → U64} {n' : Nat} - {AR' : A → HwRootA → Prop} {J5' J7' : JSlotA S} {s' : S} {a' : A} + {AR' : A → HwRootA → Prop} {J5' J7' : JSlotA S} {s' : S} {a' : A} {m' : McState} (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m) - (J' : JStage3A st AR' Z' H' OS' U' Ac' Pp' Tb' Lv' ia' ie' N' E' Rp' Bf' stack' κ' n' J5' J7' s' a' σ' m) + (J' : JStage3A st AR' Z' H' OS' U' Ac' Pp' Tb' Lv' ia' ie' N' E' Rp' Bf' stack' κ' n' J5' J7' s' a' σ' m') (h : σ'.curThread = σ.curThread) : L.curW s' = L.curW s := by have e := J.sr.sch.curThread have e' := J'.sr.sch.curThread diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapInsertTA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapInsertTA.lean index 812e3b242..853da0dc8 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapInsertTA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapInsertTA.lean @@ -373,18 +373,18 @@ theorem JStage3A.capInsertPartsA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : set_option maxHeartbeats 4000000 in -/-- **`JStage3A` across a `cap_insert` of a derived cap into slot `i ∉ {1, 2}` of a TCB** (the CSpace root, the fault -handler, the timeout handler): the buffer and idle-slot relations are kept and the fault-handler slots stay `Null` or -endpoint (`hfh3`), so `of_capDerivFhA` finishes (module docstring). -/ -theorem JStage3A.capInsertTcbSlotA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} +/-- **`JStage3A` across a `cap_insert` of a derived cap into slot `i ≠ 2` of a TCB that is no idle thread's VTable +slot** (`hsd1`): `capInsertTcbSlotA` without `i ≠ 1`, also exporting the spec slot frame and the written caps (A64-P4 +CP0b). -/ +theorem JStage3A.capInsertTcbSlotGA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) (ss sd : Fl4SpecA64.CslotPtr) {ps : U64} (hCs : ss.1 = specPtr ps ∧ Z.th ps = some (.cnode ss.2.length)) - {t0 : U64} (ht0 : Z.th t0 = some .tcb) {i : Nat} (hi : i < tcbSlotsA) (hi1 : i ≠ 1) (hi2 : i ≠ 2) - (hsd : sd = (specPtr t0, tcbCnodeIndex i)) + {t0 : U64} (ht0 : Z.th t0 = some .tcb) {i : Nat} (hi : i < tcbSlotsA) (hi2 : i ≠ 2) + (hsd : sd = (specPtr t0, tcbCnodeIndex i)) (hsd1 : ∀ c < n, sd ≠ (m.idleThreadOf c, tcbCnodeIndex 1)) (hsn : capA st s (cslotAddrA ss) ≠ .Null) (hdn : capA st s (cslotAddrA sd) = .Null) (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) {nc : capability.Cap} {anc : Fl4SpecA64.Cap} (hfh3 : i = 3 → NullOrEp H nc) (hwf : CapWfA nc) (hanc : CapEqA nc anc) @@ -417,13 +417,14 @@ theorem JStage3A.capInsertTcbSlotA {AR : A → HwRootA → Prop} {Z : XSetsA} {H (∀ p y k, σ.kheap p = some (.schedContext y k) → σ2.kheap p = some (.schedContext y k)) ∧ JStage3A st AR { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA sd) (insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))))) } - H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s2 a σ2 m := by + H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s2 a σ2 m ∧ + SpecSlotA σ σ2 ∧ WritesIn st s s2 (W7.CapW H.tcbs {b | InOS OS b} ∅) ∧ + (∀ y ∈ OS, y ≠ cslotAddrA ss → y ≠ cslotAddrA sd → capA st s2 y = capA st s y) ∧ + capA st s2 (cslotAddrA sd) = nc ∧ FullA (capA st s2 (cslotAddrA ss)) (capA st s (cslotAddrA ss)) := by have hAd : AbsSlotA Z.th sd := by subst hsd; exact ⟨t0, rfl, Or.inr ⟨ht0, i, hi, rfl⟩⟩ have hkd : σ.kheap sd.1 ≠ none := by obtain ⟨x', hk', -⟩ := J.j.1.st.tcb t0 ht0 rw [hsd]; simp [hk'] - have hsd1 : ∀ c < n, sd ≠ (m.idleThreadOf c, tcbCnodeIndex 1) := fun c hc e => - hi1 ((tcbIdx_eq (by unfold tcbSlotsA at hi; omega) (by omega)).1 (by rw [hsd] at e; exact congrArg Prod.snd e)) obtain ⟨s2, σ2, hs2, hm, hbk, scF, P⟩ := JStage3A.capInsertPartsA (J := J) ss sd hCs hAd hkd hsd1 hsn hdn hdc hwf hanc hw hn hD hal hk hsh hsh1 hbd1 hbd hirqB hirqN hirqA hz hut hdo hcv hsci symL sysl j7 obtain ⟨w, F, HS, W, hms, hcdtS, horig, origLive, nullOrig, hsc, jx, sinv, j5', hvt, ek, ed, hfull⟩ := P @@ -504,9 +505,61 @@ theorem JStage3A.capInsertTcbSlotA {AR : A → HwRootA → Prop} {Z : XSetsA} {H rw [ek _ (J.j5.2.1 _ (isSlot_fhA ((J.j.1.thT t).2 ht))) (cnSlot_ne_fhA J.j.1.place hCs.1 hCs.2 ((J.j.1.thT t).2 ht)) ne] exact J.fhOK t ht - exact ⟨s2, σ2, hs2, hm, hbk, scF, J.of_capDerivFhA (hsub := J.j5.2.1) (hnul := J.j5.2.2) (fhOK' := hfh) (hvt := hvt) + refine ⟨s2, σ2, hs2, hm, hbk, scF, J.of_capDerivFhA (hsub := J.j5.2.1) (hnul := J.j5.2.2) (fhOK' := hfh) (hvt := hvt) (symL := symL s2 hs2) w F HS W hms hoff hfal hcdtS horig origLive nullOrig hsc (sysl s2 hs2) jx sinv bufCover - bufNative unmPt bufOff j5' (j7 s2 σ2 hs2 hm)⟩ + bufNative unmPt bufOff j5' (j7 s2 σ2 hs2 hm), HS, w, ek, ed, hfull⟩ + +set_option maxHeartbeats 4000000 in +/-- **`JStage3A` across a `cap_insert` of a derived cap into slot `i ∉ {1, 2}` of a TCB** (the CSpace root, the fault +handler, the timeout handler): the buffer and idle-slot relations are kept and the fault-handler slots stay `Null` or +endpoint (`hfh3`), so `of_capDerivFhA` finishes (module docstring). -/ +theorem JStage3A.capInsertTcbSlotA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (ss sd : Fl4SpecA64.CslotPtr) {ps : U64} + (hCs : ss.1 = specPtr ps ∧ Z.th ps = some (.cnode ss.2.length)) + {t0 : U64} (ht0 : Z.th t0 = some .tcb) {i : Nat} (hi : i < tcbSlotsA) (hi1 : i ≠ 1) (hi2 : i ≠ 2) + (hsd : sd = (specPtr t0, tcbCnodeIndex i)) + (hsn : capA st s (cslotAddrA ss) ≠ .Null) (hdn : capA st s (cslotAddrA sd) = .Null) + (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) + {nc : capability.Cap} {anc : Fl4SpecA64.Cap} (hfh3 : i = 3 → NullOrEp H nc) (hwf : CapWfA nc) (hanc : CapEqA nc anc) + (hw : CapRt.EncWf nc) (hn : nc ≠ .Null) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hal : UA nc (capA st s (cslotAddrA ss))) + (hk : SameBadgeKindA nc (capA st s (cslotAddrA ss))) + (hsh : Fl4ProofsA64.P3.shapeA nc = Fl4ProofsA64.P3.shapeA (capA st s (cslotAddrA ss))) + (hsh1 : Fl4ProofsA64.P1.W7.R.ST.shapeA nc = Fl4ProofsA64.P1.W7.R.ST.shapeA (capA st s (cslotAddrA ss))) + (hbd1 : badgeA nc = badgeA (capA st s (cslotAddrA ss)) ∨ badgeA (capA st s (cslotAddrA ss)) = 0#u64) + (hbd : ∀ r b rs, (absCapA (capA st s (cslotAddrA ss)) = .endpointCap r b rs ∨ + absCapA (capA st s (cslotAddrA ss)) = .notificationCap r b rs) → b ≠ 0 → + Fl4SpecA64.capEpBadge (absCapA nc) = b) + (hirqB : ∀ i, capA st s (cslotAddrA ss) = .IrqHandler i → nc = .IrqHandler i) + (hirqN : ∀ i, nc = .IrqHandler i → capA st s (cslotAddrA ss) = .IrqHandler i ∨ + ∀ y ∈ Z.G.chains.flatten, capA st s y ≠ .IrqHandler i) + (hirqA : ∀ i, nc = .IrqHandler i → capA st s (cslotAddrA ss) = .IrqHandler i ∨ + (i.val < 5376 ∧ L.mem s (irqStAddrA (L.ksb s) i) ≠ 0#u64)) + (hz : ∀ p t k, capA st s (cslotAddrA ss) ≠ .Zombie p t k) + (hut : isUtA (capA st s (cslotAddrA ss)) = true → ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc Z.G.par y (cslotAddrA ss)) + (hdo : ¬ IrqNodeA (L.ksb s) (fl4Ptr sd.1) ∨ IrqCapA (absCapA nc)) + (hcv : CapValidA Z.th (capA st s (cslotAddrA ss)) → CapValidA Z.th nc) (hsci : NoIdleCapV m n anc) + (symL : ∀ s2, cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) = ok s2 → SymL st H Z.Cs s2) + (sysl : ∀ s2, cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) = ok s2 → SysL st H Z.Cs OS ia ie s2) + (j7 : ∀ s2 σ2, cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) = ok s2 → + ((), σ2) ∈ (Fl4SpecA64.capInsert (Z := Unit) anc ss sd σ).1 → + J7A st (J7R2A st ar nA) { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA sd) + (insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))))) } H OS s2 σ2 m) : + ∃ s2 σ2, cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) = ok s2 ∧ + ((), σ2) ∈ (Fl4SpecA64.capInsert (Z := Unit) anc ss sd σ).1 ∧ Sched.BodyKeepA σ σ2 ∧ + (∀ p y k, σ.kheap p = some (.schedContext y k) → σ2.kheap p = some (.schedContext y k)) ∧ + JStage3A st AR { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA sd) + (insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))))) } + H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s2 a σ2 m := by + have hsd1 : ∀ c < n, sd ≠ (m.idleThreadOf c, tcbCnodeIndex 1) := fun c hc e => + hi1 ((tcbIdx_eq (by unfold tcbSlotsA at hi; omega) (by omega)).1 (by rw [hsd] at e; exact congrArg Prod.snd e)) + obtain ⟨s2, σ2, h1, h2, h3, h4, h5, -⟩ := JStage3A.capInsertTcbSlotGA (J := J) ss sd hCs ht0 hi hi2 hsd hsd1 hsn hdn + hdc hfh3 hwf hanc hw hn hD hal hk hsh hsh1 hbd1 hbd hirqB hirqN hirqA hz hut hdo hcv hsci symL sysl j7 + exact ⟨s2, σ2, h1, h2, h3, h4, h5⟩ end diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameGA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameGA.lean index b85ba3216..137d8521c 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameGA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameGA.lean @@ -77,7 +77,8 @@ theorem JStage3A.of_capVsFrameGA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) (hcn : c ≠ .Null) (hc0 : capA st s (cslotAddrA cte) ≠ .Null) (hM : MapAlikeA c (capA st s (cslotAddrA cte))) (hok : CapObjOkA Z c) (hirq : CapOkA σ.interruptIrqNode cte sc) (hsci : NoIdleCapV m n sc) - (hS : ∀ p0, p0 ∈ Z.S1 ∧ 1 ≤ Z.Lv p0 → p0 ∈ S1' ∧ 1 ≤ Zl' p0) (hT2 : ∀ p0 ∈ Z.T2, p0 ∈ T2') + (hS : ∀ p0, p0 ∈ Z.S1 ∧ 1 ≤ Z.Lv p0 → p0 ∈ S1' ∧ 1 ≤ Zl' p0) (hT2 : ∀ y, IsSlotA Z.th y → y ≠ cslotAddrA cte → ∀ p0 a0' v0', capA st s y = .PageTable p0 true a0' v0' → + p0 ∈ Z.T2 → p0 ∈ T2') (hpt : ∀ p0 a0' v0', c = .PageTable p0 true a0' v0' → (p0 ∈ S1' ∧ 1 ≤ Zl' p0) ∨ p0 ∈ T2') (arm : ∀ s2 σ2, obj.Slot.set_cap st (cslotAddrA cte) s c = ok s2 → ((), σ2) ∈ (setCap (Z := Unit) sc cte σ).1 → SpecSlotA σ σ2 → WritesIn st s s2 (fun b => W7.CapW H.tcbs {b | InOS OS b} ∅ b) → @@ -224,7 +225,7 @@ theorem JStage3A.of_capVsFrameGA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : · rw [e, hcx] at h exact hpt p0 a0' v0' h · rw [hco y (hsub y hy) e] at h - exact (J.ptCapIn y hy p0 a0' v0' h).imp (hS p0) (hT2 p0) + exact (J.ptCapIn y hy p0 a0' v0' h).imp (hS p0) (hT2 y hy e p0 a0' v0' h) have fin := JStage3A.of_capVsGA (symL := F.symL) (zwf := zwf2) (fhOK := fh2) (ptCapIn := pt2) (J := J) (hw := hw) (P := P) (S1' := S1') (Zl' := Zl') (T2' := T2') (Sh2' := Sh2') (Tb' := Tb') (Lv' := Lv') (w := wT) F.hP F.hbf HS hms' F.HS F.hasid hdp' hoff F.jx F.sys F.vsOk F.bufVs F.sq F.poolOff sinv diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrAllA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrAllA.lean index 71b62adc2..954ef8bf8 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrAllA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrAllA.lean @@ -53,18 +53,7 @@ theorem _root_.Fl4ProofsA64.P3.JSyscallA.decErrSpecA (hFI : FinInvA Z.th (L.mem s) σ Z.G) (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) (hD : ∀ u frame fi, capA st s u = .Untyped frame 12#u64 fi false → cdt.ensure_no_children st s u = ok (core.result.Result.Ok ()) → DeadDrop4KA Z H frame fi) - (hPtMap : ∀ (cap : capability.Cap) (lbl ptr : U64) (mp : Bool) (asid va : U64), cap = .PageTable ptr mp asid va → - lbl = fl4_abi.label.ARMPageTableMap → - UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr ∧ ptr ∉ S2PgE Z.X Z.T2 ∧ ptr ∉ Z.Y) - (hFrMap : ∀ (cap : capability.Cap) (lbl fp : U64) (sz : capability.FrameSize) (rt : U64) (dev mp e : Bool) - (asid va : U64), cap = .Frame fp sz rt dev mp e asid va → lbl = fl4_abi.label.ARMPageMap → FrPlA sz fp mp asid) - (hFrSub : ∀ (cap : capability.Cap) (lbl : U64) (cte : CslotPtr) (fp : U64) (sz : capability.FrameSize) (rt : U64) - (dev mp e : Bool) (asid va : U64), cap = .Frame fp sz rt dev mp e asid va → - lbl = fl4_abi.label.ARMPageDeriveSubframe → sz = capability.FrameSize.Large → dev = false → - (fp.val % 2 ^ 21 = 0 ∧ CapRt.Canonical fp) ∧ - ∀ w ∈ Z.G.chains.flatten, ∀ (q vm' : U64), fp.val ≤ q.val → q.val < fp.val + 2 ^ 21 → - OvlA (absCapA (.Frame q .Small vm' false false false 0#u64 0#u64)) (absCapA (capAtA (L.mem s) w)) → - isFrameA (capAtA (L.mem s) w) = true ∧ ∃ ch ∈ Z.G.chains, cslotAddrA cte ∈ ch ∧ w ∈ ch) + (hPtMap : PtMapSiteA st Z H OS σ s) (hFrMap : FrMapSiteA st OS s) (hFrSub : FrSubSiteA st Z OS s) (hAsidAssign : ∀ (cap : capability.Cap) (lbl p base : U64), cap = .AsidPool p base → lbl = fl4_abi.label.ARMASIDPoolAssign → ∀ u ∈ OS, ∀ k root oldAsid oldVa, capA st s u = assignUnmappedA k root oldAsid oldVa → diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrBaseA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrBaseA.lean index d8abb2209..15700f808 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrBaseA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrBaseA.lean @@ -20,6 +20,38 @@ open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3 Fl4Pro noncomputable section +/-! ## F-E (Stage 4 `vsx`): the decode-site facts of the VSpace arms, at the slots of the record + +`DecErrSpecPA.archVs` / `.pageTable` and the `Err` tops used to take these facts as `∀ cap lbl …` (any cap value, any +address): unsatisfiable (`UnmPtA` of every `ptr`). They are facts about the caps *held in the record's slots*, and the +fresh-table fact only about an **unmapped** cap (a mapped table is in `Z.S1`). -/ + +section feSites +variable {S : Type} (st : machine.Store S) [L : LawfulStore st] + +/-- **[J] Fresh-table facts of an unmapped page-table cap in a slot** (`ARMPageTableMap`'s decode site). -/ +def PtMapSiteA (Z : XSetsA) (H : Heap) (OS : Set U64) (σ : Fl4SpecA64.State Unit) (s : S) : Prop := + ∀ u ∈ OS, ∀ (ptr asid va : U64), capA st s u = .PageTable ptr false asid va → + UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr ∧ ptr ∉ S2PgE Z.X Z.T2 ∧ ptr ∉ Z.Y + +/-- **[J] Placement of a frame cap in a slot** (`ARMPageMap`'s decode site). -/ +def FrMapSiteA (OS : Set U64) (s : S) : Prop := + ∀ u ∈ OS, ∀ (fp : U64) (sz : capability.FrameSize) (rt : U64) (dev mp e : Bool) (asid va : U64), + capA st s u = .Frame fp sz rt dev mp e asid va → FrPlA sz fp mp asid + +/-- **[J] Alignment and chain ownership of a large RAM frame cap in a slot** (`ARMPageDeriveSubframe`'s decode +site). -/ +def FrSubSiteA (Z : XSetsA) (OS : Set U64) (s : S) : Prop := + ∀ (cte : CslotPtr), cslotAddrA cte ∈ OS → ∀ (fp : U64) (sz : capability.FrameSize) (rt : U64) (dev mp e : Bool) + (asid va : U64), capA st s (cslotAddrA cte) = .Frame fp sz rt dev mp e asid va → + sz = capability.FrameSize.Large → dev = false → + (fp.val % 2 ^ 21 = 0 ∧ CapRt.Canonical fp) ∧ + ∀ w ∈ Z.G.chains.flatten, ∀ (q vm' : U64), fp.val ≤ q.val → q.val < fp.val + 2 ^ 21 → + OvlA (absCapA (.Frame q .Small vm' false false false 0#u64 0#u64)) (absCapA (capAtA (L.mem s) w)) → + isFrameA (capAtA (L.mem s) w) = true ∧ ∃ ch ∈ Z.G.chains, cslotAddrA cte ∈ ch ∧ w ∈ ch + +end feSites + /-- The Untyped caps. -/ def UtCapA : capability.Cap → Prop | .Untyped .. => True diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrPtA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrPtA.lean index 4bcf9ff95..3375c8d50 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrPtA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrPtA.lean @@ -124,8 +124,7 @@ theorem DecErrSpecPA.pageTable (K : ArchKeepsA ar AR) (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) (hD : ∀ u frame fi, capA st s u = .Untyped frame 12#u64 fi false → cdt.ensure_no_children st s u = ok (core.result.Result.Ok ()) → DeadDrop4KA Z H frame fi) - (hPtMap : ∀ (cap : capability.Cap) (lbl ptr : U64) (mp : Bool) (asid va : U64), cap = .PageTable ptr mp asid va → lbl = fl4_abi.label.ARMPageTableMap → - UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr ∧ ptr ∉ S2PgE Z.X Z.T2 ∧ ptr ∉ Z.Y) + (hPtMap : PtMapSiteA st Z H OS σ s) {calling blocking donate : Bool} {cptr : U64} : DecErrSpecPA st ar Z.th s a σ calling blocking donate cptr PtCapA := by intro info buf r1 e x s' a' mi sl c excaps buffer args einfo ebuf elr eex hd hne hP hlab hsl hcr hok hab hbv @@ -149,7 +148,10 @@ theorem DecErrSpecPA.pageTable (K : ArchKeepsA ar AR) have K1 := decInv_arch_jA K Je RS hvcR J.tabS1 J.tabExt J3.ksbAligned J3.offAsE hYAs hIpa hPC hFI hTr (fun y hy hn => J3.j5.2.2 y hy hn) hcO hD sl hab hslO (.PageTable ptr mp asid va) trivial hcap info.label (msgLenA info buf) buf blocking calling donate false e argsU hlen hargsU (Fl4SpecA64.toBl cptr.bv) excaps hok - false buffer (hPtMap _ _) (fun _ _ _ _ _ _ _ _ h => by cases h) (fun _ _ _ _ _ _ _ _ h => by cases h) + false buffer + (fun ptr' mp' asid' va' hc _ hmp => hPtMap (cslotAddrA sl) hslO ptr' asid' va' + (by cases hc; subst hmp; rw [← hsl]; exact hcp)) + (fun _ _ _ _ _ _ _ _ h => by cases h) (fun _ _ _ _ _ _ _ _ h => by cases h) (fun _ _ h => by cases h) have hd' : syscall.decode_invocation st ar s a info.label (msgLenA info buf) (cslotAddrA sl) (.PageTable ptr mp asid va) blocking calling donate false buf e = ok (.Err x, s', a') := by diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbRootsA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbRootsA.lean index 663ec96b5..3e9077e27 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbRootsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbRootsA.lean @@ -1,377 +1,7 @@ /- -P3 (aarch64, A64-P3 Lift 1b, part C3): **`derive_roots` against the spec's CSpace / VSpace root decode** (shared by -SetSpace and Configure). - -* `slotLongRun_relA`: `slot_cap_long_running_delete` is `slotCapLongRunningDelete`. -* `deriveData_relA`: `derive_with_data` is `deriveCap` of the updated cap. -* `cvProg P`: the spec's root decode with VTable root predicate `P` (`decodeCvSpace`, `fl4DecodeCvSpace`). -* `deriveRoots_relA`: `derive_roots`' outcome against `cvProg`. - -`F` the finality state facts; `hnc`: `ensure_no_children` at an untyped source. New module. +P3 (aarch64, A64-P3 Lift 1b, part C3): **`derive_roots` against the spec's CSpace / VSpace root decode**: re-export of +`Stage3DecErrTcbRootsCoreA` (the lemmas moved there) with the decode-error chain's buffer module, as the importers of the +old module expect. -/ +import Fl4ProofsA64.P3.Stage3DecErrTcbRootsCoreA import Fl4ProofsA64.P3.Stage3DecErrTcbBufA -import Fl4ProofsA64.P3.TcbInvokeRootsA -import Fl4ProofsA64.P3.CnodeDelDefA -import Fl4ProofsA64.P3.FrontEndExtraA -open Aeneas Aeneas.Std Result - -namespace Fl4ProofsA64.P3.ReplyErr -open fl4_core_a64 Fl4ProofsA64.P0 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P2.PathObl Fl4ProofsA64.P3 - Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Endp Fl4Spec Fl4SpecA64 Classical - -noncomputable section - -section -variable {S : Type} {st : machine.Store S} [L : LawfulStore st] -variable {s : S} {σ : Fl4SpecA64.State Unit} {th : TypedHeapA} - -theorem tcb_slot1A (t : U64) : - obj.Tcb.slot t layout.tcb.SLOT_VTABLE = ok (cslotAddrA (specPtr t, tcbCnodeIndex 1)) := by - have e : cslotAddrA (specPtr t, tcbCnodeIndex 1) = ⟨t.bv + 1#64 * 32#64⟩ := by - unfold cslotAddrA - rw [ofBl_tcbIdx 1 (by omega), slotAddrA_sp] - rw [e] - unfold obj.Tcb.slot - simp only [lift, bind_ok] - congr 1 - apply UScalar.eq_of_val_eq - have hv : (⟨t.bv + 1#64 * 32#64⟩ : U64).val = (t.val + 32) % 2 ^ 64 := by - show (t.bv + 1#64 * 32#64).toNat = _ - rw [BitVec.toNat_add]; rfl - rw [hv] - simp [core.num.U64.wrapping_add_val_eq, core.num.U64.wrapping_mul_val_eq, layout.tcb.SLOT_VTABLE, U64.size_def, - U64.numBits] - -theorem cslot0A (t : U64) : cslotAddrA (specPtr t, tcbCnodeIndex 0) = t := by - unfold cslotAddrA - rw [ofBl_tcbIdx 0 (by omega), slotAddrA_sp] - apply UScalar.eq_of_val_eq; simp - -theorem slotLongRun_relA {OS : Set U64} {G : List (List U64)} (F : FinStA st th OS G s σ) {sl : Fl4SpecA64.CslotPtr} - (hsl : AbsSlotA th sl) : - ∃ b, cdt.slot_cap_long_running_delete st s (cslotAddrA sl) = ok b ∧ - slotCapLongRunningDelete (Z := Unit) sl σ = ({(b, σ)}, False) := by - obtain ⟨ac, hg, hace⟩ := getCapOne_eqA F.rel hsl - obtain ⟨c, hc⟩ : ∃ c, capA st s (cslotAddrA sl) = c := ⟨_, rfl⟩ - rw [hc] at hace - have hwf : CapWfA c := hc ▸ F.wf (F.sub _ (hsl.isSlot F.place)) - unfold cdt.slot_cap_long_running_delete slotCapLongRunningDelete - simp only [capA_eq, hc, bind_ok] - rw [nd_bind_singleA hg] - by_cases hcn : c = .Null - · subst hcn - have hacn : ac = Fl4SpecA64.Cap.nullCap := (hace.eq_abs fun _ _ _ e => by cases e).symm - subst hacn - exact ⟨false, by simp only [cap_is_null_nullA, bind_ok, ↓reduceIte], rfl⟩ - have hcan : ac ≠ .nullCap := hace.ne_null hcn hwf - rw [cap_is_null_neA hcn] - simp only [bind_ok, Bool.false_eq_true, ↓reduceIte] - have hspec : ∀ (b : Bool), (decide (isFinalCap' ac σ) && longRunningDelete ac) = b → - (isFinalCap ac >>= fun final => (pure (final && longRunningDelete ac) : SMonad Unit Bool)) σ = - ({(b, σ)}, False) := by - intro b hb - subst hb - unfold isFinalCap - rw [nd_bind_singleA (a := decide (isFinalCap' ac σ)) (by rfl)] - rfl - by_cases hk : (∃ p r gs g, c = .CNode p r gs g) ∨ (∃ p, c = .Thread p) ∨ (∃ p t n, c = .Zombie p t n) - · have hN : NeedsFinCA c := by - rcases hk with ⟨_, _, _, _, rfl⟩ | ⟨_, rfl⟩ | ⟨_, _, _, rfl⟩ <;> trivial - obtain ⟨⟨b, hb, e⟩, -⟩ := finalHypA th OS G s σ sl c F hsl hc hN - have hld : longRunningDelete ac = true := by - have ha : ac = absCapA c := (hace.eq_abs (by - intro p asid va e; subst e - rcases hk with ⟨_, _, _, _, h⟩ | ⟨_, h⟩ | ⟨_, _, _, h⟩ <;> cases h)).symm - rw [ha] - rcases hk with ⟨_, _, _, _, rfl⟩ | ⟨_, rfl⟩ | ⟨_, _, _, rfl⟩ <;> rfl - refine ⟨b, ?_, hspec b ?_⟩ - · rw [hb] - simp only [bind_ok] - cases b - · rfl - · rcases hk with ⟨_, _, _, _, rfl⟩ | ⟨_, rfl⟩ | ⟨_, _, _, rfl⟩ <;> rfl - · rw [hld, Bool.and_true] - have := e.trans (isFinalCap'_eqA hace σ).symm - cases b <;> simp_all - · obtain ⟨b, hb, -⟩ := spec_existsA (P0.cdt.is_final_capability_with_cap.p0 st s (cslotAddrA sl) c L.total) - have hld : longRunningDelete ac = false := by - rcases hace.eq_or_pt with e | ⟨_, _, _, e⟩ - · rw [e] - cases c - case CNode => exact absurd (Or.inl ⟨_, _, _, _, rfl⟩) hk - case Thread => exact absurd (Or.inr (Or.inl ⟨_, rfl⟩)) hk - case Zombie => exact absurd (Or.inr (Or.inr ⟨_, _, _, rfl⟩)) hk - case Frame => simp only [absCapA, absFrameE]; split <;> rfl - all_goals rfl - · rw [e]; rfl - refine ⟨false, ?_, hspec false (by rw [hld, Bool.and_false])⟩ - rw [hb] - simp only [bind_ok] - cases b - · rfl - · cases c - case CNode => exact absurd (Or.inl ⟨_, _, _, _, rfl⟩) hk - case Thread => exact absurd (Or.inr (Or.inl ⟨_, rfl⟩)) hk - case Zombie => exact absurd (Or.inr (Or.inr ⟨_, _, _, rfl⟩)) hk - all_goals rfl - -theorem deriveData_relA {slot : obj.Slot} {sl : Fl4SpecA64.CslotPtr} {y : Fl4SpecA64.Cap} (d : U64) - (hcr : CapRelA (capA st s slot) y) - (hnc : isUtA (capA st s slot) = true → NoChildrenRelA (st := st) s σ slot sl) : - ∃ r r', tcb.derive_with_data st s slot d = ok r ∧ - (deriveCap (Z := Unit) sl ((if d.bv = 0 then id else updateCapData false d.bv) y)).run σ = ({(r', σ)}, False) ∧ - (match r, r' with - | .Ok c', .ok a => CapWfA c' ∧ CapEqA c' a - | .Err e, .error e' => SysErrRelA e e' - | _, _ => False) := by - have fin : ∀ (c : capability.Cap) (z : Fl4SpecA64.Cap), CapRelA c z → CapRt.EncWf c → - (isUtA c = true → NoChildrenRelA (st := st) s σ slot sl) → - ∃ r r', objects.derive_cap st s slot c = ok r ∧ (deriveCap (Z := Unit) sl z).run σ = ({(r', σ)}, False) ∧ - (match r, r' with - | .Ok c', .ok a => CapWfA c' ∧ CapEqA c' a - | .Err e, .error e' => SysErrRelA e e' - | _, _ => False) := by - intro c z hz he hn - obtain ⟨r, hr, r', hr', hrel⟩ := derive_relEqA (st := st) s σ slot sl c z hz he hn - refine ⟨r, r', hr, hr', ?_⟩ - cases r <;> cases r' <;> first | exact ⟨hrel.1, hrel.2.1⟩ | exact hrel - have hcap := capA_eq (st := st) s slot - have hew : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ - unfold tcb.derive_with_data - simp only [hcap, bind_ok] - by_cases hd : d = 0#u64 - · have hd' : d.bv = 0 := by rw [hd]; rfl - have : (d != 0#u64) = false := by rw [hd]; rfl - simp only [this, Bool.false_eq_true, ite_false, bind_ok, if_pos hd', id_eq] - exact fin _ y hcr hew hnc - have hd' : d.bv ≠ 0 := fun c => hd (UScalar.eq_equiv_bv_eq _ _ |>.2 c) - have : (d != 0#u64) = true := bne_iff_ne.2 hd - simp only [this, ite_true, if_neg hd'] - obtain ⟨c2, hu, hw2, ha2, he2, -, -, hs2⟩ := update_relA false d _ hcr.1 hew - rw [hu] - simp only [bind_ok] - have hut : isUtA c2 = true → isUtA (capA st s slot) = true := by - intro h - obtain ⟨p, b, i, e, hc2⟩ := isUtA_ut h - have hs := hs2 (by rw [hc2]; exact fun c => by cases c) - rw [hc2] at hs - revert hs - cases capA st s slot <;> simp [shapeA, isUtA] - have h2 : CapRelA c2 (updateCapData false d.bv y) := by - refine ⟨hw2, ?_⟩ - by_cases hpt : ∃ p asid va, capA st s slot = .PageTable p true asid va - · obtain ⟨p, asid, va, e⟩ := hpt - have hq := hcr.2 - rw [e] at hq hu - have hc2 : c2 = .PageTable p true asid va := (ok_inj_ff hu).symm - obtain ⟨asid', va', hy, -, -⟩ := CapEqA.pt_mapped_iff.mp hq - have : updateCapData false d.bv y = y := by rw [hy]; rfl - rw [this, hc2] - exact hq - · have hab : absCapA (capA st s slot) = y := by - have hq := hcr.2 - unfold CapEqA at hq - split at hq - · exact absurd ⟨_, _, _, by assumption⟩ hpt - · exact hq - exact CapEqA.of_abs (by rw [ha2, hab]) - exact fin c2 _ h2 he2 (fun h => hnc (hut h)) - -/-- The spec's CSpace / VSpace root decode, with VTable root predicate `P`. -/ -def cvProg (P : Fl4SpecA64.Cap → Bool) (args : List Fl4SpecA64.Data) (cap : Fl4SpecA64.Cap) - (slot : Fl4SpecA64.CslotPtr) (excaps : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) : - SEMonad Unit TcbInvocation := do - NonDetE.whenE (args.length < 2 ∨ excaps.length < 2) <| NonDetE.throwError .truncatedMessage - let canChgCr ← NonDetE.liftE <| NonDet.liftM not <| slotCapLongRunningDelete (getTcbCtablePtr (objRefOf cap)) - let canChgVr ← NonDetE.liftE <| NonDet.liftM not <| slotCapLongRunningDelete (getTcbVtablePtr (objRefOf cap)) - NonDetE.unlessE (canChgCr ∧ canChgVr) <| NonDetE.throwError .illegalOperation - let croot ← deriveCap (the excaps[0]?).2 - ((if the args[0]? = 0 then id else updateCapData false (the args[0]?)) (the excaps[0]?).1) - NonDetE.unlessE (isCnodeCap croot) <| NonDetE.throwError .illegalOperation - let vroot ← deriveCap (the excaps[1]?).2 - ((if the args[1]? = 0 then id else updateCapData false (the args[1]?)) (the excaps[1]?).1) - NonDetE.unlessE (P vroot) <| NonDetE.throwError .illegalOperation - NonDetE.returnOk <| .threadControlCaps (objRefOf cap) slot none none - (some (croot, (the excaps[0]?).2)) (some (vroot, (the excaps[1]?).2)) none - -theorem isCnode_relA {c : capability.Cap} {y : Fl4SpecA64.Cap} (hw : CapWfA c) (h : CapEqA c y) : - tcb.is_cnode c = ok (isCnodeCap y) := by - rcases h.eq_or_pt with e | ⟨_, _, _, e⟩ - · subst e - cases c <;> first | rfl | exact hw.elim | skip - · have : ∃ p a v, c = .PageTable p true a v := by - unfold CapEqA at h - split at h - · exact ⟨_, _, _, rfl⟩ - · rw [e] at h - cases c with - | PageTable p m asid va => - cases m with - | false => simp [absCapA, mapDataA] at h - | true => exact ⟨_, _, _, rfl⟩ - | Frame => - simp only [absCapA, absFrameE] at h - split at h <;> cases h - | _ => simp [absCapA] at h - obtain ⟨p, a, v, rfl⟩ := this - rw [e]; rfl - -theorem deriveRoots_relA {OS : Set U64} {G : List (List U64)} (F : FinStA st th OS G s σ) {t : U64} - (ht : th t = some .tcb) {cdata vdata : U64} {cs vs : obj.Slot} {sl slot : Fl4SpecA64.CslotPtr} - {sl1 : Fl4SpecA64.CslotPtr} {y y1 : Fl4SpecA64.Cap} {rest : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)} - {args : List Fl4SpecA64.Data} (hcr : CapRelA (capA st s cs) y) (hcr1 : CapRelA (capA st s vs) y1) - (hnc : isUtA (capA st s cs) = true → NoChildrenRelA (st := st) s σ cs sl) - (hnc1 : isUtA (capA st s vs) = true → NoChildrenRelA (st := st) s σ vs sl1) - (P : Fl4SpecA64.Cap → Bool) - (hP : ∀ c z, tcb.derive_with_data st s vs vdata = ok (.Ok c) → CapWfA c → CapEqA c z → - (deriveCap (Z := Unit) sl1 ((if vdata.bv = 0 then id else updateCapData false vdata.bv) y1)).run σ = - ({(.ok z, σ)}, False) → vspace.is_valid_vtable_root c = ok (P z)) - {r : core.result.Result (capability.Cap × capability.Cap) error.Exc} - (h : tcb.derive_roots st s t cdata vdata cs vs = ok r) : - match r with - | .Ok _ => ∃ v, (cvProg P (cdata.bv :: vdata.bv :: args) (.threadCap (specPtr t)) slot - ((y, sl) :: (y1, sl1) :: rest)).run σ = ({(.ok v, σ)}, False) - | .Err x => ∃ e', (cvProg P (cdata.bv :: vdata.bv :: args) (.threadCap (specPtr t)) slot - ((y, sl) :: (y1, sl1) :: rest)).run σ = ({(.error e', σ)}, False) ∧ VsErrRelA x e' := by - have hA0 : AbsSlotA th (specPtr t, tcbCnodeIndex 0) := ⟨t, rfl, Or.inr ⟨ht, 0, by decide, rfl⟩⟩ - have hA1 : AbsSlotA th (specPtr t, tcbCnodeIndex 1) := ⟨t, rfl, Or.inr ⟨ht, 1, by decide, rfl⟩⟩ - obtain ⟨b0, hb0, hs0⟩ := slotLongRun_relA F hA0 - obtain ⟨b1, hb1, hs1⟩ := slotLongRun_relA F hA1 - rw [cslot0A] at hb0 - have hr0 : (NonDetE.liftE (ε := SyscallError) <| NonDet.liftM not <| - slotCapLongRunningDelete (Z := Unit) (getTcbCtablePtr (specPtr t))).run σ = ({(.ok (!b0), σ)}, False) := - run_liftE_stD (by - show (slotCapLongRunningDelete (Z := Unit) (specPtr t, tcbCnodeIndex 0) >>= fun x => pure (!x)) σ = _ - rw [nd_bind_singleA hs0]; rfl) - have hr1 : (NonDetE.liftE (ε := SyscallError) <| NonDet.liftM not <| - slotCapLongRunningDelete (Z := Unit) (getTcbVtablePtr (specPtr t))).run σ = ({(.ok (!b1), σ)}, False) := - run_liftE_stD (by - show (slotCapLongRunningDelete (Z := Unit) (specPtr t, tcbCnodeIndex 1) >>= fun x => pure (!x)) σ = _ - rw [nd_bind_singleA hs1]; rfl) - have hskip : NonDetE.whenE (σ := Fl4SpecA64.State Unit) - ((cdata.bv :: vdata.bv :: args).length < 2 ∨ ((y, sl) :: (y1, sl1) :: rest).length < 2) - (NonDetE.throwError SyscallError.truncatedMessage) = pure () := if_neg (by simp) - have head : ∀ (g : Bool → Bool → SEMonad Unit TcbInvocation) (R), - (g (!b0) (!b1)).run σ = R → - (NonDetE.whenE ((cdata.bv :: vdata.bv :: args).length < 2 ∨ ((y, sl) :: (y1, sl1) :: rest).length < 2) - (NonDetE.throwError SyscallError.truncatedMessage) >>= fun _ => - NonDetE.liftE (NonDet.liftM not (slotCapLongRunningDelete (getTcbCtablePtr (specPtr t)))) >>= fun a => - NonDetE.liftE (NonDet.liftM not (slotCapLongRunningDelete (getTcbVtablePtr (specPtr t)))) >>= fun b => - g a b).run σ = R := by - intro g R hg - rw [hskip, run_bind_okD (a := ()) (s' := σ) rfl, run_bind_okD hr0, run_bind_okD hr1] - exact hg - have ill : ∀ x : error.Exc, x = .Sys .IllegalOperation → VsErrRelA x .illegalOperation := - fun x hx => Or.inl (by rw [hx]; exact trivial) - unfold tcb.derive_roots at h - rw [tcb_slot0A, bind_ok, hb0, bind_ok] at h - unfold cvProg - simp only [show objRefOf (.threadCap (specPtr t)) = specPtr t from rfl] - cases b0 with - | true => - simp only [ite_true, error.illegal] at h - have := ok_inj_ff h - subst this - refine ⟨_, head _ _ ?_, ill _ rfl⟩ - exact unlessE_neg_runX (by simp) _ _ σ - | false => - simp only [Bool.false_eq_true, ite_false] at h - rw [tcb_slot1A, bind_ok, hb1, bind_ok] at h - cases b1 with - | true => - simp only [ite_true, error.illegal] at h - have := ok_inj_ff h - subst this - refine ⟨_, head _ _ ?_, ill _ rfl⟩ - exact unlessE_neg_runX (by simp) _ _ σ - | false => - simp only [Bool.false_eq_true, ite_false] at h - have hgo : NonDetE.unlessE (σ := Fl4SpecA64.State Unit) ((!false) = true ∧ (!false) = true) - (NonDetE.throwError SyscallError.illegalOperation) = pure () := if_pos (by simp) - obtain ⟨rc, rc', hrc, hsc, hrelc⟩ := deriveData_relA (σ := σ) (sl := sl) cdata hcr hnc - obtain ⟨rv, rv', hrv, hsv, hrelv⟩ := deriveData_relA (σ := σ) (sl := sl1) vdata hcr1 hnc1 - rw [hrc, bind_ok] at h - simp only [List.getElem?_cons_zero, List.getElem?_cons_succ] - cases rc with - | Err e => - cases rc' with - | ok _ => exact hrelc.elim - | error e' => - simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, - core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, - core.convert.FromSame.from, Std.bind_tc_ok] at h - have := ok_inj_ff h - subst this - refine ⟨e', head _ _ ?_, Or.inl hrelc⟩ - rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] - exact run_bind_errorD hsc _ - | Ok cc => - cases rc' with - | error _ => exact hrelc.elim - | ok zc => - simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] at h - rw [isCnode_relA hrelc.1 hrelc.2, bind_ok] at h - cases hcn : isCnodeCap zc with - | false => - simp only [hcn, Bool.false_eq_true, ite_false, error.illegal] at h - have := ok_inj_ff h - subst this - refine ⟨_, head _ _ ?_, ill _ rfl⟩ - rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] - refine (run_bind_okD (a := zc) (s' := σ) hsc _).trans ?_ - exact unlessE_neg_runX (by simp [hcn]) _ _ σ - | true => - simp only [hcn, ite_true] at h - have hgc : NonDetE.unlessE (σ := Fl4SpecA64.State Unit) (isCnodeCap zc = true) - (NonDetE.throwError SyscallError.illegalOperation) = pure () := if_pos hcn - rw [hrv, bind_ok] at h - cases rv with - | Err e => - cases rv' with - | ok _ => exact hrelv.elim - | error e' => - simp only [bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, - core.convert.FromSame.from, Std.bind_tc_ok] at h - have := ok_inj_ff h - subst this - refine ⟨e', head _ _ ?_, Or.inl hrelv⟩ - rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] - refine (run_bind_okD (a := zc) (s' := σ) hsc _).trans ?_ - rw [hgc, run_bind_okD (a := ()) (s' := σ) rfl] - exact run_bind_errorD hsv _ - | Ok vc => - cases rv' with - | error _ => exact hrelv.elim - | ok zv => - simp only [bind_ok] at h - rw [hP vc zv hrv hrelv.1 hrelv.2 hsv, bind_ok] at h - cases hv : P zv with - | false => - simp only [hv, Bool.false_eq_true, ite_false, error.illegal] at h - have := ok_inj_ff h - subst this - refine ⟨_, head _ _ ?_, ill _ rfl⟩ - rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] - refine (run_bind_okD (a := zc) (s' := σ) hsc _).trans ?_ - rw [hgc, run_bind_okD (a := ()) (s' := σ) rfl] - refine (run_bind_okD (a := zv) (s' := σ) hsv _).trans ?_ - exact unlessE_neg_runX (by simp [hv]) _ _ σ - | true => - simp only [hv, ite_true] at h - have := ok_inj_ff h - subst this - refine ⟨.threadControlCaps (specPtr t) slot none none (some (zc, sl)) (some (zv, sl1)) none, head _ _ ?_⟩ - rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] - refine (run_bind_okD (a := zc) (s' := σ) hsc _).trans ?_ - rw [hgc, run_bind_okD (a := ()) (s' := σ) rfl] - refine (run_bind_okD (a := zv) (s' := σ) hsv _).trans ?_ - rw [show NonDetE.unlessE (σ := Fl4SpecA64.State Unit) (P zv = true) - (NonDetE.throwError SyscallError.illegalOperation) = pure () from if_pos hv, - run_bind_okD (a := ()) (s' := σ) rfl] - rfl - -end - -end - -end Fl4ProofsA64.P3.ReplyErr diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbRootsCoreA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbRootsCoreA.lean new file mode 100644 index 000000000..db1f2c039 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbRootsCoreA.lean @@ -0,0 +1,500 @@ +/- +P3 (aarch64, A64-P3 Lift 1b, part C3): **`derive_roots` against the spec's CSpace / VSpace root decode** (shared by +SetSpace and Configure). + +* `slotLongRun_relA`: `slot_cap_long_running_delete` is `slotCapLongRunningDelete`. +* `deriveData_relA`: `derive_with_data` is `deriveCap` of the updated cap. +* `cvProg P`: the spec's root decode with VTable root predicate `P` (`decodeCvSpace`, `fl4DecodeCvSpace`). +* `deriveRoots_relA`: `derive_roots`' outcome against `cvProg`. + +`F` the finality state facts; `hnc`: `ensure_no_children` at an untyped source. New module (the shared part of `Stage3DecErrTcbRootsA`, split off so that the InvSpec group can use it without importing the decode-error chain; `Stage3DecErrTcbRootsA` re-exports it). +-/ +import Fl4ProofsA64.P3.IpcXferDeriveA +import Fl4ProofsA64.P3.Stage3DispBaseA +import Fl4ProofsA64.P3.TcbInvokeRootsA +import Fl4ProofsA64.P3.CnodeDelDefA +import Fl4ProofsA64.P3.FrontEndExtraA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.ReplyErr +open fl4_core_a64 Fl4ProofsA64.P0 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P2.PathObl Fl4ProofsA64.P3 + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Endp Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {s : S} {σ : Fl4SpecA64.State Unit} {th : TypedHeapA} + +theorem tcb_slot1A (t : U64) : + obj.Tcb.slot t layout.tcb.SLOT_VTABLE = ok (cslotAddrA (specPtr t, tcbCnodeIndex 1)) := by + have e : cslotAddrA (specPtr t, tcbCnodeIndex 1) = ⟨t.bv + 1#64 * 32#64⟩ := by + unfold cslotAddrA + rw [ofBl_tcbIdx 1 (by omega), slotAddrA_sp] + rw [e] + unfold obj.Tcb.slot + simp only [lift, bind_ok] + congr 1 + apply UScalar.eq_of_val_eq + have hv : (⟨t.bv + 1#64 * 32#64⟩ : U64).val = (t.val + 32) % 2 ^ 64 := by + show (t.bv + 1#64 * 32#64).toNat = _ + rw [BitVec.toNat_add]; rfl + rw [hv] + simp [core.num.U64.wrapping_add_val_eq, core.num.U64.wrapping_mul_val_eq, layout.tcb.SLOT_VTABLE, U64.size_def, + U64.numBits] + +theorem cslot0A (t : U64) : cslotAddrA (specPtr t, tcbCnodeIndex 0) = t := by + unfold cslotAddrA + rw [ofBl_tcbIdx 0 (by omega), slotAddrA_sp] + apply UScalar.eq_of_val_eq; simp + +theorem slotLongRun_relA {OS : Set U64} {G : List (List U64)} (F : FinStA st th OS G s σ) {sl : Fl4SpecA64.CslotPtr} + (hsl : AbsSlotA th sl) : + ∃ b, cdt.slot_cap_long_running_delete st s (cslotAddrA sl) = ok b ∧ + slotCapLongRunningDelete (Z := Unit) sl σ = ({(b, σ)}, False) := by + obtain ⟨ac, hg, hace⟩ := getCapOne_eqA F.rel hsl + obtain ⟨c, hc⟩ : ∃ c, capA st s (cslotAddrA sl) = c := ⟨_, rfl⟩ + rw [hc] at hace + have hwf : CapWfA c := hc ▸ F.wf (F.sub _ (hsl.isSlot F.place)) + unfold cdt.slot_cap_long_running_delete slotCapLongRunningDelete + simp only [capA_eq, hc, bind_ok] + rw [nd_bind_singleA hg] + by_cases hcn : c = .Null + · subst hcn + have hacn : ac = Fl4SpecA64.Cap.nullCap := (hace.eq_abs fun _ _ _ e => by cases e).symm + subst hacn + exact ⟨false, by simp only [cap_is_null_nullA, bind_ok, ↓reduceIte], rfl⟩ + have hcan : ac ≠ .nullCap := hace.ne_null hcn hwf + rw [cap_is_null_neA hcn] + simp only [bind_ok, Bool.false_eq_true, ↓reduceIte] + have hspec : ∀ (b : Bool), (decide (isFinalCap' ac σ) && longRunningDelete ac) = b → + (isFinalCap ac >>= fun final => (pure (final && longRunningDelete ac) : SMonad Unit Bool)) σ = + ({(b, σ)}, False) := by + intro b hb + subst hb + unfold isFinalCap + rw [nd_bind_singleA (a := decide (isFinalCap' ac σ)) (by rfl)] + rfl + by_cases hk : (∃ p r gs g, c = .CNode p r gs g) ∨ (∃ p, c = .Thread p) ∨ (∃ p t n, c = .Zombie p t n) + · have hN : NeedsFinCA c := by + rcases hk with ⟨_, _, _, _, rfl⟩ | ⟨_, rfl⟩ | ⟨_, _, _, rfl⟩ <;> trivial + obtain ⟨⟨b, hb, e⟩, -⟩ := finalHypA th OS G s σ sl c F hsl hc hN + have hld : longRunningDelete ac = true := by + have ha : ac = absCapA c := (hace.eq_abs (by + intro p asid va e; subst e + rcases hk with ⟨_, _, _, _, h⟩ | ⟨_, h⟩ | ⟨_, _, _, h⟩ <;> cases h)).symm + rw [ha] + rcases hk with ⟨_, _, _, _, rfl⟩ | ⟨_, rfl⟩ | ⟨_, _, _, rfl⟩ <;> rfl + refine ⟨b, ?_, hspec b ?_⟩ + · rw [hb] + simp only [bind_ok] + cases b + · rfl + · rcases hk with ⟨_, _, _, _, rfl⟩ | ⟨_, rfl⟩ | ⟨_, _, _, rfl⟩ <;> rfl + · rw [hld, Bool.and_true] + have := e.trans (isFinalCap'_eqA hace σ).symm + cases b <;> simp_all + · obtain ⟨b, hb, -⟩ := spec_existsA (P0.cdt.is_final_capability_with_cap.p0 st s (cslotAddrA sl) c L.total) + have hld : longRunningDelete ac = false := by + rcases hace.eq_or_pt with e | ⟨_, _, _, e⟩ + · rw [e] + cases c + case CNode => exact absurd (Or.inl ⟨_, _, _, _, rfl⟩) hk + case Thread => exact absurd (Or.inr (Or.inl ⟨_, rfl⟩)) hk + case Zombie => exact absurd (Or.inr (Or.inr ⟨_, _, _, rfl⟩)) hk + case Frame => simp only [absCapA, absFrameE]; split <;> rfl + all_goals rfl + · rw [e]; rfl + refine ⟨false, ?_, hspec false (by rw [hld, Bool.and_false])⟩ + rw [hb] + simp only [bind_ok] + cases b + · rfl + · cases c + case CNode => exact absurd (Or.inl ⟨_, _, _, _, rfl⟩) hk + case Thread => exact absurd (Or.inr (Or.inl ⟨_, rfl⟩)) hk + case Zombie => exact absurd (Or.inr (Or.inr ⟨_, _, _, rfl⟩)) hk + all_goals rfl + +theorem deriveData_relA {slot : obj.Slot} {sl : Fl4SpecA64.CslotPtr} {y : Fl4SpecA64.Cap} (d : U64) + (hcr : CapRelA (capA st s slot) y) + (hnc : isUtA (capA st s slot) = true → NoChildrenRelA (st := st) s σ slot sl) : + ∃ r r', tcb.derive_with_data st s slot d = ok r ∧ + (deriveCap (Z := Unit) sl ((if d.bv = 0 then id else updateCapData false d.bv) y)).run σ = ({(r', σ)}, False) ∧ + (match r, r' with + | .Ok c', .ok a => CapWfA c' ∧ CapEqA c' a + | .Err e, .error e' => SysErrRelA e e' + | _, _ => False) := by + have fin : ∀ (c : capability.Cap) (z : Fl4SpecA64.Cap), CapRelA c z → CapRt.EncWf c → + (isUtA c = true → NoChildrenRelA (st := st) s σ slot sl) → + ∃ r r', objects.derive_cap st s slot c = ok r ∧ (deriveCap (Z := Unit) sl z).run σ = ({(r', σ)}, False) ∧ + (match r, r' with + | .Ok c', .ok a => CapWfA c' ∧ CapEqA c' a + | .Err e, .error e' => SysErrRelA e e' + | _, _ => False) := by + intro c z hz he hn + obtain ⟨r, hr, r', hr', hrel⟩ := derive_relEqA (st := st) s σ slot sl c z hz he hn + refine ⟨r, r', hr, hr', ?_⟩ + cases r <;> cases r' <;> first | exact ⟨hrel.1, hrel.2.1⟩ | exact hrel + have hcap := capA_eq (st := st) s slot + have hew : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ + unfold tcb.derive_with_data + simp only [hcap, bind_ok] + by_cases hd : d = 0#u64 + · have hd' : d.bv = 0 := by rw [hd]; rfl + have : (d != 0#u64) = false := by rw [hd]; rfl + simp only [this, Bool.false_eq_true, ite_false, bind_ok, if_pos hd', id_eq] + exact fin _ y hcr hew hnc + have hd' : d.bv ≠ 0 := fun c => hd (UScalar.eq_equiv_bv_eq _ _ |>.2 c) + have : (d != 0#u64) = true := bne_iff_ne.2 hd + simp only [this, ite_true, if_neg hd'] + obtain ⟨c2, hu, hw2, ha2, he2, -, -, hs2⟩ := update_relA false d _ hcr.1 hew + rw [hu] + simp only [bind_ok] + have hut : isUtA c2 = true → isUtA (capA st s slot) = true := by + intro h + obtain ⟨p, b, i, e, hc2⟩ := isUtA_ut h + have hs := hs2 (by rw [hc2]; exact fun c => by cases c) + rw [hc2] at hs + revert hs + cases capA st s slot <;> simp [shapeA, isUtA] + have h2 : CapRelA c2 (updateCapData false d.bv y) := by + refine ⟨hw2, ?_⟩ + by_cases hpt : ∃ p asid va, capA st s slot = .PageTable p true asid va + · obtain ⟨p, asid, va, e⟩ := hpt + have hq := hcr.2 + rw [e] at hq hu + have hc2 : c2 = .PageTable p true asid va := (ok_inj_ff hu).symm + obtain ⟨asid', va', hy, -, -⟩ := CapEqA.pt_mapped_iff.mp hq + have : updateCapData false d.bv y = y := by rw [hy]; rfl + rw [this, hc2] + exact hq + · have hab : absCapA (capA st s slot) = y := by + have hq := hcr.2 + unfold CapEqA at hq + split at hq + · exact absurd ⟨_, _, _, by assumption⟩ hpt + · exact hq + exact CapEqA.of_abs (by rw [ha2, hab]) + exact fin c2 _ h2 he2 (fun h => hnc (hut h)) + +/-- The spec's CSpace / VSpace root decode, with VTable root predicate `P`. -/ +def cvProg (P : Fl4SpecA64.Cap → Bool) (args : List Fl4SpecA64.Data) (cap : Fl4SpecA64.Cap) + (slot : Fl4SpecA64.CslotPtr) (excaps : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) : + SEMonad Unit TcbInvocation := do + NonDetE.whenE (args.length < 2 ∨ excaps.length < 2) <| NonDetE.throwError .truncatedMessage + let canChgCr ← NonDetE.liftE <| NonDet.liftM not <| slotCapLongRunningDelete (getTcbCtablePtr (objRefOf cap)) + let canChgVr ← NonDetE.liftE <| NonDet.liftM not <| slotCapLongRunningDelete (getTcbVtablePtr (objRefOf cap)) + NonDetE.unlessE (canChgCr ∧ canChgVr) <| NonDetE.throwError .illegalOperation + let croot ← deriveCap (the excaps[0]?).2 + ((if the args[0]? = 0 then id else updateCapData false (the args[0]?)) (the excaps[0]?).1) + NonDetE.unlessE (isCnodeCap croot) <| NonDetE.throwError .illegalOperation + let vroot ← deriveCap (the excaps[1]?).2 + ((if the args[1]? = 0 then id else updateCapData false (the args[1]?)) (the excaps[1]?).1) + NonDetE.unlessE (P vroot) <| NonDetE.throwError .illegalOperation + NonDetE.returnOk <| .threadControlCaps (objRefOf cap) slot none none + (some (croot, (the excaps[0]?).2)) (some (vroot, (the excaps[1]?).2)) none + +theorem isCnode_relA {c : capability.Cap} {y : Fl4SpecA64.Cap} (hw : CapWfA c) (h : CapEqA c y) : + tcb.is_cnode c = ok (isCnodeCap y) := by + rcases h.eq_or_pt with e | ⟨_, _, _, e⟩ + · subst e + cases c <;> first | rfl | exact hw.elim | skip + · have : ∃ p a v, c = .PageTable p true a v := by + unfold CapEqA at h + split at h + · exact ⟨_, _, _, rfl⟩ + · rw [e] at h + cases c with + | PageTable p m asid va => + cases m with + | false => simp [absCapA, mapDataA] at h + | true => exact ⟨_, _, _, rfl⟩ + | Frame => + simp only [absCapA, absFrameE] at h + split at h <;> cases h + | _ => simp [absCapA] at h + obtain ⟨p, a, v, rfl⟩ := this + rw [e]; rfl + +theorem deriveRoots_relA {OS : Set U64} {G : List (List U64)} (F : FinStA st th OS G s σ) {t : U64} + (ht : th t = some .tcb) {cdata vdata : U64} {cs vs : obj.Slot} {sl slot : Fl4SpecA64.CslotPtr} + {sl1 : Fl4SpecA64.CslotPtr} {y y1 : Fl4SpecA64.Cap} {rest : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)} + {args : List Fl4SpecA64.Data} (hcr : CapRelA (capA st s cs) y) (hcr1 : CapRelA (capA st s vs) y1) + (hnc : isUtA (capA st s cs) = true → NoChildrenRelA (st := st) s σ cs sl) + (hnc1 : isUtA (capA st s vs) = true → NoChildrenRelA (st := st) s σ vs sl1) + (P : Fl4SpecA64.Cap → Bool) + (hP : ∀ c z, tcb.derive_with_data st s vs vdata = ok (.Ok c) → CapWfA c → CapEqA c z → + (deriveCap (Z := Unit) sl1 ((if vdata.bv = 0 then id else updateCapData false vdata.bv) y1)).run σ = + ({(.ok z, σ)}, False) → vspace.is_valid_vtable_root c = ok (P z)) + {r : core.result.Result (capability.Cap × capability.Cap) error.Exc} + (h : tcb.derive_roots st s t cdata vdata cs vs = ok r) : + match r with + | .Ok _ => ∃ v, (cvProg P (cdata.bv :: vdata.bv :: args) (.threadCap (specPtr t)) slot + ((y, sl) :: (y1, sl1) :: rest)).run σ = ({(.ok v, σ)}, False) + | .Err x => ∃ e', (cvProg P (cdata.bv :: vdata.bv :: args) (.threadCap (specPtr t)) slot + ((y, sl) :: (y1, sl1) :: rest)).run σ = ({(.error e', σ)}, False) ∧ VsErrRelA x e' := by + have hA0 : AbsSlotA th (specPtr t, tcbCnodeIndex 0) := ⟨t, rfl, Or.inr ⟨ht, 0, by decide, rfl⟩⟩ + have hA1 : AbsSlotA th (specPtr t, tcbCnodeIndex 1) := ⟨t, rfl, Or.inr ⟨ht, 1, by decide, rfl⟩⟩ + obtain ⟨b0, hb0, hs0⟩ := slotLongRun_relA F hA0 + obtain ⟨b1, hb1, hs1⟩ := slotLongRun_relA F hA1 + rw [cslot0A] at hb0 + have hr0 : (NonDetE.liftE (ε := SyscallError) <| NonDet.liftM not <| + slotCapLongRunningDelete (Z := Unit) (getTcbCtablePtr (specPtr t))).run σ = ({(.ok (!b0), σ)}, False) := + run_liftE_stD (by + show (slotCapLongRunningDelete (Z := Unit) (specPtr t, tcbCnodeIndex 0) >>= fun x => pure (!x)) σ = _ + rw [nd_bind_singleA hs0]; rfl) + have hr1 : (NonDetE.liftE (ε := SyscallError) <| NonDet.liftM not <| + slotCapLongRunningDelete (Z := Unit) (getTcbVtablePtr (specPtr t))).run σ = ({(.ok (!b1), σ)}, False) := + run_liftE_stD (by + show (slotCapLongRunningDelete (Z := Unit) (specPtr t, tcbCnodeIndex 1) >>= fun x => pure (!x)) σ = _ + rw [nd_bind_singleA hs1]; rfl) + have hskip : NonDetE.whenE (σ := Fl4SpecA64.State Unit) + ((cdata.bv :: vdata.bv :: args).length < 2 ∨ ((y, sl) :: (y1, sl1) :: rest).length < 2) + (NonDetE.throwError SyscallError.truncatedMessage) = pure () := if_neg (by simp) + have head : ∀ (g : Bool → Bool → SEMonad Unit TcbInvocation) (R), + (g (!b0) (!b1)).run σ = R → + (NonDetE.whenE ((cdata.bv :: vdata.bv :: args).length < 2 ∨ ((y, sl) :: (y1, sl1) :: rest).length < 2) + (NonDetE.throwError SyscallError.truncatedMessage) >>= fun _ => + NonDetE.liftE (NonDet.liftM not (slotCapLongRunningDelete (getTcbCtablePtr (specPtr t)))) >>= fun a => + NonDetE.liftE (NonDet.liftM not (slotCapLongRunningDelete (getTcbVtablePtr (specPtr t)))) >>= fun b => + g a b).run σ = R := by + intro g R hg + rw [hskip, run_bind_okD (a := ()) (s' := σ) rfl, run_bind_okD hr0, run_bind_okD hr1] + exact hg + have ill : ∀ x : error.Exc, x = .Sys .IllegalOperation → VsErrRelA x .illegalOperation := + fun x hx => Or.inl (by rw [hx]; exact trivial) + unfold tcb.derive_roots at h + rw [tcb_slot0A, bind_ok, hb0, bind_ok] at h + unfold cvProg + simp only [show objRefOf (.threadCap (specPtr t)) = specPtr t from rfl] + cases b0 with + | true => + simp only [ite_true, error.illegal] at h + have := ok_inj_ff h + subst this + refine ⟨_, head _ _ ?_, ill _ rfl⟩ + exact unlessE_neg_runX (by simp) _ _ σ + | false => + simp only [Bool.false_eq_true, ite_false] at h + rw [tcb_slot1A, bind_ok, hb1, bind_ok] at h + cases b1 with + | true => + simp only [ite_true, error.illegal] at h + have := ok_inj_ff h + subst this + refine ⟨_, head _ _ ?_, ill _ rfl⟩ + exact unlessE_neg_runX (by simp) _ _ σ + | false => + simp only [Bool.false_eq_true, ite_false] at h + have hgo : NonDetE.unlessE (σ := Fl4SpecA64.State Unit) ((!false) = true ∧ (!false) = true) + (NonDetE.throwError SyscallError.illegalOperation) = pure () := if_pos (by simp) + obtain ⟨rc, rc', hrc, hsc, hrelc⟩ := deriveData_relA (σ := σ) (sl := sl) cdata hcr hnc + obtain ⟨rv, rv', hrv, hsv, hrelv⟩ := deriveData_relA (σ := σ) (sl := sl1) vdata hcr1 hnc1 + rw [hrc, bind_ok] at h + simp only [List.getElem?_cons_zero, List.getElem?_cons_succ] + cases rc with + | Err e => + cases rc' with + | ok _ => exact hrelc.elim + | error e' => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, + core.convert.FromSame.from, Std.bind_tc_ok] at h + have := ok_inj_ff h + subst this + refine ⟨e', head _ _ ?_, Or.inl hrelc⟩ + rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] + exact run_bind_errorD hsc _ + | Ok cc => + cases rc' with + | error _ => exact hrelc.elim + | ok zc => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] at h + rw [isCnode_relA hrelc.1 hrelc.2, bind_ok] at h + cases hcn : isCnodeCap zc with + | false => + simp only [hcn, Bool.false_eq_true, ite_false, error.illegal] at h + have := ok_inj_ff h + subst this + refine ⟨_, head _ _ ?_, ill _ rfl⟩ + rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] + refine (run_bind_okD (a := zc) (s' := σ) hsc _).trans ?_ + exact unlessE_neg_runX (by simp [hcn]) _ _ σ + | true => + simp only [hcn, ite_true] at h + have hgc : NonDetE.unlessE (σ := Fl4SpecA64.State Unit) (isCnodeCap zc = true) + (NonDetE.throwError SyscallError.illegalOperation) = pure () := if_pos hcn + rw [hrv, bind_ok] at h + cases rv with + | Err e => + cases rv' with + | ok _ => exact hrelv.elim + | error e' => + simp only [bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, + core.convert.FromSame.from, Std.bind_tc_ok] at h + have := ok_inj_ff h + subst this + refine ⟨e', head _ _ ?_, Or.inl hrelv⟩ + rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] + refine (run_bind_okD (a := zc) (s' := σ) hsc _).trans ?_ + rw [hgc, run_bind_okD (a := ()) (s' := σ) rfl] + exact run_bind_errorD hsv _ + | Ok vc => + cases rv' with + | error _ => exact hrelv.elim + | ok zv => + simp only [bind_ok] at h + rw [hP vc zv hrv hrelv.1 hrelv.2 hsv, bind_ok] at h + cases hv : P zv with + | false => + simp only [hv, Bool.false_eq_true, ite_false, error.illegal] at h + have := ok_inj_ff h + subst this + refine ⟨_, head _ _ ?_, ill _ rfl⟩ + rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] + refine (run_bind_okD (a := zc) (s' := σ) hsc _).trans ?_ + rw [hgc, run_bind_okD (a := ()) (s' := σ) rfl] + refine (run_bind_okD (a := zv) (s' := σ) hsv _).trans ?_ + exact unlessE_neg_runX (by simp [hv]) _ _ σ + | true => + simp only [hv, ite_true] at h + have := ok_inj_ff h + subst this + refine ⟨.threadControlCaps (specPtr t) slot none none (some (zc, sl)) (some (zv, sl1)) none, head _ _ ?_⟩ + rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] + refine (run_bind_okD (a := zc) (s' := σ) hsc _).trans ?_ + rw [hgc, run_bind_okD (a := ()) (s' := σ) rfl] + refine (run_bind_okD (a := zv) (s' := σ) hsv _).trans ?_ + rw [show NonDetE.unlessE (σ := Fl4SpecA64.State Unit) (P zv = true) + (NonDetE.throwError SyscallError.illegalOperation) = pure () from if_pos hv, + run_bind_okD (a := ()) (s' := σ) rfl] + rfl + + +theorem decodeCvSpace_progA (args : List Fl4SpecA64.Data) (cap : Fl4SpecA64.Cap) (slot : Fl4SpecA64.CslotPtr) + (excaps : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) : + decodeCvSpace (Z := Unit) args cap slot excaps = cvProg isValidVtableRoot args cap slot excaps := by + unfold decodeCvSpace cvProg + simp only [Fl4Spec.NonDetE.returnOk, ndE_pure_bindD] + +theorem fl4CvSpace_progA (args : List Fl4SpecA64.Data) (cap : Fl4SpecA64.Cap) (slot : Fl4SpecA64.CslotPtr) + (excaps : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) : + fl4DecodeCvSpace (Z := Unit) args cap slot excaps = + cvProg (fun v => isValidVtableRoot v || fl4MappedStage2Root v) args cap slot excaps := by + have hor : ∀ (a b : Bool) (m : Fl4Spec.NonDetE (Fl4SpecA64.State Unit) Fl4SpecA64.SyscallError Unit), + Fl4Spec.NonDetE.unlessE (a = true ∨ b = true) m = Fl4Spec.NonDetE.unlessE ((a || b) = true) m := by + intro a b m + cases a <;> cases b <;> rfl + unfold fl4DecodeCvSpace cvProg + simp only [Fl4Spec.NonDetE.returnOk, ndE_pure_bindD, hor] + try rfl + +/-- A derived updated cap is a mapped Stage-2 root only if the source cap is. -/ +theorem stage2_deriveA {σ : Fl4SpecA64.State Unit} {sl : Fl4SpecA64.CslotPtr} {d : Fl4SpecA64.Data} + {y z : Fl4SpecA64.Cap} + (h : (deriveCap (Z := Unit) sl ((if d = 0 then id else updateCapData false d) y)).run σ = ({(.ok z, σ)}, False)) + (hz : fl4MappedStage2Root z = true) : fl4MappedStage2Root y = true := by + obtain ⟨p, a, rfl⟩ : ∃ p a, z = .archObjectCap (.ext (.stage2VSpaceCap p (some a))) := by + cases z with + | archObjectCap c => + cases c with + | ext e => + cases e with + | stage2VSpaceCap p m => + cases m with + | none => cases hz + | some a => exact ⟨p, a, rfl⟩ + | _ => cases hz + | _ => cases hz + | _ => cases hz + have key : ∀ w : Fl4SpecA64.Cap, + (deriveCap (Z := Unit) sl w).run σ = + ({(.ok (.archObjectCap (.ext (.stage2VSpaceCap p (some a)))), σ)}, False) → + w = .archObjectCap (.ext (.stage2VSpaceCap p (some a))) := by + intro w hw + cases w with + | untypedCap => + simp only [deriveCap] at hw + rw [ExceptT.run_bind, nd_bind_singleA (ensureNoChildren_runA σ sl)] at hw + by_cases hc : ∃ x, σ.cdt x = some sl + · simp only [hc, ↓reduceIte] at hw + exact (run_single_errA hw).elim + · simp only [hc, ↓reduceIte] at hw + exact absurd (run_single_okA hw) (by simp) + | zombie => exact absurd (run_single_okA hw) (by simp) + | irqControlCap => exact absurd (run_single_okA hw) (by simp) + | archObjectCap c => + cases c with + | pageTableCap r t m => + cases m + · exact (run_single_errA hw).elim + · exact absurd (run_single_okA hw) (by simp) + | frameCap => exact absurd (run_single_okA hw) (by simp) + | ext e => + cases e with + | stage2VSpaceCap q m => + cases m + · exact (run_single_errA hw).elim + · exact (run_single_okA hw) + | highVSpaceCap q m => + cases m + · exact (run_single_errA hw).elim + · exact absurd (run_single_okA hw) (by simp) + | _ => exact absurd (run_single_okA hw) (by simp) + | _ => exact absurd (run_single_okA hw) (by simp) + | _ => exact absurd (run_single_okA hw) (by simp) + have hw := key _ h + by_cases hd : d = 0 + · rw [if_pos hd] at hw + simp only [id_eq] at hw + rw [hw]; rfl + rw [if_neg hd] at hw + revert hw + cases y with + | endpointCap => + simp only [updateCapData, isEpCap, ite_true] + split <;> simp [badgeUpdate] + | notificationCap => + simp only [updateCapData, isEpCap, isNtfnCap, Bool.false_eq_true, ite_false, ite_true] + split <;> simp [badgeUpdate] + | cnodeCap => + simp only [updateCapData, isEpCap, isNtfnCap, isCnodeCap, Bool.false_eq_true, ite_false, ite_true] + split <;> simp + | archObjectCap c => + simp only [updateCapData, isEpCap, isNtfnCap, isCnodeCap, isArchCap, Bool.false_eq_true, ite_false, ite_true, + archUpdateCapData, Fl4SpecA64.Cap.theArchCap] + split + · split <;> simp + · intro hw; rw [hw]; rfl + | _ => simp [updateCapData, isEpCap, isNtfnCap, isCnodeCap, isArchCap] + +/-- The VTable predicate of the Ext decode is FL4's. -/ +theorem vtP_extA {c : capability.Cap} {z : Fl4SpecA64.Cap} (hw : CapWfA c) (he : CapEqA c z) : + vspace.is_valid_vtable_root c = ok (isValidVtableRoot z || fl4MappedStage2Root z) := by + rw [tcbVtableRoot_eqA c hw] + rcases he.eq_or_pt with e | ⟨_, _, _, e⟩ + · rw [e] + · have : ∃ p a v, c = .PageTable p true a v := by + unfold CapEqA at he + split at he + · exact ⟨_, _, _, rfl⟩ + · rw [e] at he + cases c with + | PageTable p m asid va => + cases m with + | false => simp [absCapA, mapDataA] at he + | true => exact ⟨_, _, _, rfl⟩ + | Frame => + simp only [absCapA, absFrameE] at he + split at he <;> cases he + | _ => simp [absCapA] at he + obtain ⟨p, a, v, rfl⟩ := this + obtain ⟨_, _, hz, -, -⟩ := CapEqA.pt_mapped_iff.mp he + rw [hz]; rfl + +end + +end + +end Fl4ProofsA64.P3.ReplyErr diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbSpaceA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbSpaceA.lean index 95ec04061..a184a3315 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbSpaceA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbSpaceA.lean @@ -18,103 +18,6 @@ open fl4_core_a64 Fl4ProofsA64.P0 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4Pro noncomputable section -theorem decodeCvSpace_progA (args : List Fl4SpecA64.Data) (cap : Fl4SpecA64.Cap) (slot : Fl4SpecA64.CslotPtr) - (excaps : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) : - decodeCvSpace (Z := Unit) args cap slot excaps = cvProg isValidVtableRoot args cap slot excaps := by - unfold decodeCvSpace cvProg - simp only [Fl4Spec.NonDetE.returnOk, ndE_pure_bindD] - -theorem fl4CvSpace_progA (args : List Fl4SpecA64.Data) (cap : Fl4SpecA64.Cap) (slot : Fl4SpecA64.CslotPtr) - (excaps : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) : - fl4DecodeCvSpace (Z := Unit) args cap slot excaps = - cvProg (fun v => isValidVtableRoot v || fl4MappedStage2Root v) args cap slot excaps := by - have hor : ∀ (a b : Bool) (m : Fl4Spec.NonDetE (Fl4SpecA64.State Unit) Fl4SpecA64.SyscallError Unit), - Fl4Spec.NonDetE.unlessE (a = true ∨ b = true) m = Fl4Spec.NonDetE.unlessE ((a || b) = true) m := by - intro a b m - cases a <;> cases b <;> rfl - unfold fl4DecodeCvSpace cvProg - simp only [Fl4Spec.NonDetE.returnOk, ndE_pure_bindD, hor] - try rfl - -/-- A derived updated cap is a mapped Stage-2 root only if the source cap is. -/ -theorem stage2_deriveA {σ : Fl4SpecA64.State Unit} {sl : Fl4SpecA64.CslotPtr} {d : Fl4SpecA64.Data} - {y z : Fl4SpecA64.Cap} - (h : (deriveCap (Z := Unit) sl ((if d = 0 then id else updateCapData false d) y)).run σ = ({(.ok z, σ)}, False)) - (hz : fl4MappedStage2Root z = true) : fl4MappedStage2Root y = true := by - obtain ⟨p, a, rfl⟩ : ∃ p a, z = .archObjectCap (.ext (.stage2VSpaceCap p (some a))) := by - cases z with - | archObjectCap c => - cases c with - | ext e => - cases e with - | stage2VSpaceCap p m => - cases m with - | none => cases hz - | some a => exact ⟨p, a, rfl⟩ - | _ => cases hz - | _ => cases hz - | _ => cases hz - have key : ∀ w : Fl4SpecA64.Cap, - (deriveCap (Z := Unit) sl w).run σ = - ({(.ok (.archObjectCap (.ext (.stage2VSpaceCap p (some a)))), σ)}, False) → - w = .archObjectCap (.ext (.stage2VSpaceCap p (some a))) := by - intro w hw - cases w with - | untypedCap => - simp only [deriveCap] at hw - rw [ExceptT.run_bind, nd_bind_singleA (ensureNoChildren_runA σ sl)] at hw - by_cases hc : ∃ x, σ.cdt x = some sl - · simp only [hc, ↓reduceIte] at hw - exact (run_single_errA hw).elim - · simp only [hc, ↓reduceIte] at hw - exact absurd (run_single_okA hw) (by simp) - | zombie => exact absurd (run_single_okA hw) (by simp) - | irqControlCap => exact absurd (run_single_okA hw) (by simp) - | archObjectCap c => - cases c with - | pageTableCap r t m => - cases m - · exact (run_single_errA hw).elim - · exact absurd (run_single_okA hw) (by simp) - | frameCap => exact absurd (run_single_okA hw) (by simp) - | ext e => - cases e with - | stage2VSpaceCap q m => - cases m - · exact (run_single_errA hw).elim - · exact (run_single_okA hw) - | highVSpaceCap q m => - cases m - · exact (run_single_errA hw).elim - · exact absurd (run_single_okA hw) (by simp) - | _ => exact absurd (run_single_okA hw) (by simp) - | _ => exact absurd (run_single_okA hw) (by simp) - | _ => exact absurd (run_single_okA hw) (by simp) - have hw := key _ h - by_cases hd : d = 0 - · rw [if_pos hd] at hw - simp only [id_eq] at hw - rw [hw]; rfl - rw [if_neg hd] at hw - revert hw - cases y with - | endpointCap => - simp only [updateCapData, isEpCap, ite_true] - split <;> simp [badgeUpdate] - | notificationCap => - simp only [updateCapData, isEpCap, isNtfnCap, Bool.false_eq_true, ite_false, ite_true] - split <;> simp [badgeUpdate] - | cnodeCap => - simp only [updateCapData, isEpCap, isNtfnCap, isCnodeCap, Bool.false_eq_true, ite_false, ite_true] - split <;> simp - | archObjectCap c => - simp only [updateCapData, isEpCap, isNtfnCap, isCnodeCap, isArchCap, Bool.false_eq_true, ite_false, ite_true, - archUpdateCapData, Fl4SpecA64.Cap.theArchCap] - split - · split <;> simp - · intro hw; rw [hw]; rfl - | _ => simp [updateCapData, isEpCap, isNtfnCap, isCnodeCap, isArchCap] - section variable {S A : Type} {st : machine.Store S} {ar : machine.Arch A} [L : LawfulStore st] variable {s s' : S} {a a' : A} {t : U64} {ctx : tcb.Ctx} {x : error.Exc} {σ : Fl4SpecA64.State Unit} @@ -220,30 +123,6 @@ theorem ipcDec_okA {v : U64} {y cap : Fl4SpecA64.Cap} {sl slot : Fl4SpecA64.Cslo rw [if_neg h0', run_bind_okD hr', run_bind_okD hck] rfl -/-- The VTable predicate of the Ext decode is FL4's. -/ -theorem vtP_extA {c : capability.Cap} {z : Fl4SpecA64.Cap} (hw : CapWfA c) (he : CapEqA c z) : - vspace.is_valid_vtable_root c = ok (isValidVtableRoot z || fl4MappedStage2Root z) := by - rw [tcbVtableRoot_eqA c hw] - rcases he.eq_or_pt with e | ⟨_, _, _, e⟩ - · rw [e] - · have : ∃ p a v, c = .PageTable p true a v := by - unfold CapEqA at he - split at he - · exact ⟨_, _, _, rfl⟩ - · rw [e] at he - cases c with - | PageTable p m asid va => - cases m with - | false => simp [absCapA, mapDataA] at he - | true => exact ⟨_, _, _, rfl⟩ - | Frame => - simp only [absCapA, absFrameE] at he - split at he <;> cases he - | _ => simp [absCapA] at he - obtain ⟨p, a, v, rfl⟩ := this - obtain ⟨_, _, hz, -, -⟩ := CapEqA.pt_mapped_iff.mp he - rw [hz]; rfl - /-- `derive_roots` against the root decode the spec runs at the VTable source `y1`. -/ theorem roots_corrA {OS : Set U64} {G : List (List U64)} (F : FinStA st th OS G s σ) (ht : th t = some .tcb) {cdata vdata : U64} {cs vs : obj.Slot} {sl sl1 slot : Fl4SpecA64.CslotPtr} {y y1 : Fl4SpecA64.Cap} diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbValA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbValA.lean new file mode 100644 index 000000000..f7efe1944 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrTcbValA.lean @@ -0,0 +1,148 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP2): **`derive_roots` of an accepted SetSpace / Configure, with its values**: the twin of +`deriveRoots_relA` whose `Ok` conclusion names the spec's two derived caps (`CapEqA` to FL4's) and the invocation the root +decode returns (`deriveRoots_relA` hides them in an existential). New module; no premise. +-/ +import Fl4ProofsA64.P3.Stage3DecErrTcbRootsCoreA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.ReplyErr +open fl4_core_a64 Fl4ProofsA64.P0 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P2.PathObl Fl4ProofsA64.P3 + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Endp Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {s : S} {σ : Fl4SpecA64.State Unit} {th : TypedHeapA} + +theorem deriveRoots_valA {OS : Set U64} {G : List (List U64)} (F : FinStA st th OS G s σ) {t : U64} + (ht : th t = some .tcb) {cdata vdata : U64} {cs vs : obj.Slot} {sl slot : Fl4SpecA64.CslotPtr} + {sl1 : Fl4SpecA64.CslotPtr} {y y1 : Fl4SpecA64.Cap} {rest : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)} + {args : List Fl4SpecA64.Data} (hcr : CapRelA (capA st s cs) y) (hcr1 : CapRelA (capA st s vs) y1) + (hnc : isUtA (capA st s cs) = true → NoChildrenRelA (st := st) s σ cs sl) + (hnc1 : isUtA (capA st s vs) = true → NoChildrenRelA (st := st) s σ vs sl1) + (P : Fl4SpecA64.Cap → Bool) + (hP : ∀ c z, tcb.derive_with_data st s vs vdata = ok (.Ok c) → CapWfA c → CapEqA c z → + (deriveCap (Z := Unit) sl1 ((if vdata.bv = 0 then id else updateCapData false vdata.bv) y1)).run σ = + ({(.ok z, σ)}, False) → vspace.is_valid_vtable_root c = ok (P z)) + {c v : capability.Cap} + (h : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (c, v))) : + ∃ zc zv, CapEqA c zc ∧ CapEqA v zv ∧ (cvProg P (cdata.bv :: vdata.bv :: args) (.threadCap (specPtr t)) slot + ((y, sl) :: (y1, sl1) :: rest)).run σ = + ({(.ok (.threadControlCaps (specPtr t) slot none none (some (zc, sl)) (some (zv, sl1)) none), σ)}, False) := by + have hA0 : AbsSlotA th (specPtr t, tcbCnodeIndex 0) := ⟨t, rfl, Or.inr ⟨ht, 0, by decide, rfl⟩⟩ + have hA1 : AbsSlotA th (specPtr t, tcbCnodeIndex 1) := ⟨t, rfl, Or.inr ⟨ht, 1, by decide, rfl⟩⟩ + obtain ⟨b0, hb0, hs0⟩ := slotLongRun_relA F hA0 + obtain ⟨b1, hb1, hs1⟩ := slotLongRun_relA F hA1 + rw [cslot0A] at hb0 + have hr0 : (NonDetE.liftE (ε := SyscallError) <| NonDet.liftM not <| + slotCapLongRunningDelete (Z := Unit) (getTcbCtablePtr (specPtr t))).run σ = ({(.ok (!b0), σ)}, False) := + run_liftE_stD (by + show (slotCapLongRunningDelete (Z := Unit) (specPtr t, tcbCnodeIndex 0) >>= fun x => pure (!x)) σ = _ + rw [nd_bind_singleA hs0]; rfl) + have hr1 : (NonDetE.liftE (ε := SyscallError) <| NonDet.liftM not <| + slotCapLongRunningDelete (Z := Unit) (getTcbVtablePtr (specPtr t))).run σ = ({(.ok (!b1), σ)}, False) := + run_liftE_stD (by + show (slotCapLongRunningDelete (Z := Unit) (specPtr t, tcbCnodeIndex 1) >>= fun x => pure (!x)) σ = _ + rw [nd_bind_singleA hs1]; rfl) + have hskip : NonDetE.whenE (σ := Fl4SpecA64.State Unit) + ((cdata.bv :: vdata.bv :: args).length < 2 ∨ ((y, sl) :: (y1, sl1) :: rest).length < 2) + (NonDetE.throwError SyscallError.truncatedMessage) = pure () := if_neg (by simp) + have head : ∀ (g : Bool → Bool → SEMonad Unit TcbInvocation) (R), + (g (!b0) (!b1)).run σ = R → + (NonDetE.whenE ((cdata.bv :: vdata.bv :: args).length < 2 ∨ ((y, sl) :: (y1, sl1) :: rest).length < 2) + (NonDetE.throwError SyscallError.truncatedMessage) >>= fun _ => + NonDetE.liftE (NonDet.liftM not (slotCapLongRunningDelete (getTcbCtablePtr (specPtr t)))) >>= fun a => + NonDetE.liftE (NonDet.liftM not (slotCapLongRunningDelete (getTcbVtablePtr (specPtr t)))) >>= fun b => + g a b).run σ = R := by + intro g R hg + rw [hskip, run_bind_okD (a := ()) (s' := σ) rfl, run_bind_okD hr0, run_bind_okD hr1] + exact hg + have ill : ∀ x : error.Exc, x = .Sys .IllegalOperation → VsErrRelA x .illegalOperation := + fun x hx => Or.inl (by rw [hx]; exact trivial) + unfold tcb.derive_roots at h + rw [tcb_slot0A, bind_ok, hb0, bind_ok] at h + unfold cvProg + simp only [show objRefOf (.threadCap (specPtr t)) = specPtr t from rfl] + cases b0 with + | true => + simp only [ite_true, error.illegal] at h + cases ok_inj_ff h + | false => + simp only [Bool.false_eq_true, ite_false] at h + rw [tcb_slot1A, bind_ok, hb1, bind_ok] at h + cases b1 with + | true => + simp only [ite_true, error.illegal] at h + cases ok_inj_ff h + | false => + simp only [Bool.false_eq_true, ite_false] at h + have hgo : NonDetE.unlessE (σ := Fl4SpecA64.State Unit) ((!false) = true ∧ (!false) = true) + (NonDetE.throwError SyscallError.illegalOperation) = pure () := if_pos (by simp) + obtain ⟨rc, rc', hrc, hsc, hrelc⟩ := deriveData_relA (σ := σ) (sl := sl) cdata hcr hnc + obtain ⟨rv, rv', hrv, hsv, hrelv⟩ := deriveData_relA (σ := σ) (sl := sl1) vdata hcr1 hnc1 + rw [hrc, bind_ok] at h + simp only [List.getElem?_cons_zero, List.getElem?_cons_succ] + cases rc with + | Err e => + cases rc' with + | ok _ => exact hrelc.elim + | error e' => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, + core.convert.FromSame.from, Std.bind_tc_ok] at h + cases ok_inj_ff h + | Ok cc => + cases rc' with + | error _ => exact hrelc.elim + | ok zc => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] at h + rw [isCnode_relA hrelc.1 hrelc.2, bind_ok] at h + cases hcn : isCnodeCap zc with + | false => + simp only [hcn, Bool.false_eq_true, ite_false, error.illegal] at h + cases ok_inj_ff h + | true => + simp only [hcn, ite_true] at h + have hgc : NonDetE.unlessE (σ := Fl4SpecA64.State Unit) (isCnodeCap zc = true) + (NonDetE.throwError SyscallError.illegalOperation) = pure () := if_pos hcn + rw [hrv, bind_ok] at h + cases rv with + | Err e => + cases rv' with + | ok _ => exact hrelv.elim + | error e' => + simp only [bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, + core.convert.FromSame.from, Std.bind_tc_ok] at h + cases ok_inj_ff h + | Ok vc => + cases rv' with + | error _ => exact hrelv.elim + | ok zv => + simp only [bind_ok] at h + rw [hP vc zv hrv hrelv.1 hrelv.2 hsv, bind_ok] at h + cases hv : P zv with + | false => + simp only [hv, Bool.false_eq_true, ite_false, error.illegal] at h + cases ok_inj_ff h + | true => + simp only [hv, ite_true] at h + have e := core.result.Result.Ok.inj (ok_inj_ff h) + obtain ⟨rfl, rfl⟩ := Prod.mk.inj e + refine ⟨zc, zv, hrelc.2, hrelv.2, head _ _ ?_⟩ + rw [hgo, run_bind_okD (a := ()) (s' := σ) rfl] + refine (run_bind_okD (a := zc) (s' := σ) hsc _).trans ?_ + rw [hgc, run_bind_okD (a := ()) (s' := σ) rfl] + refine (run_bind_okD (a := zv) (s' := σ) hsv _).trans ?_ + rw [show NonDetE.unlessE (σ := Fl4SpecA64.State Unit) (P zv = true) + (NonDetE.throwError SyscallError.illegalOperation) = pure () from if_pos hv, + run_bind_okD (a := ()) (s' := σ) rfl] + rfl + +end + +end + +end Fl4ProofsA64.P3.ReplyErr diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrVsA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrVsA.lean index c41302847..77ed36537 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrVsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrVsA.lean @@ -38,17 +38,7 @@ theorem DecErrSpecPA.archVs (K : ArchKeepsA ar AR) (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) (hD : ∀ u frame fi, capA st s u = .Untyped frame 12#u64 fi false → cdt.ensure_no_children st s u = ok (core.result.Result.Ok ()) → DeadDrop4KA Z H frame fi) - (hPtMap : ∀ (cap : capability.Cap) (lbl ptr : U64) (mp : Bool) (asid va : U64), cap = .PageTable ptr mp asid va → lbl = fl4_abi.label.ARMPageTableMap → - UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr ∧ ptr ∉ S2PgE Z.X Z.T2 ∧ ptr ∉ Z.Y) - (hFrMap : ∀ (cap : capability.Cap) (lbl fp : U64) (sz : capability.FrameSize) (rt : U64) (dev mp e : Bool) (asid va : U64), cap = .Frame fp sz rt dev mp e asid va → - lbl = fl4_abi.label.ARMPageMap → FrPlA sz fp mp asid) - (hFrSub : ∀ (cap : capability.Cap) (lbl : U64) (cte : CslotPtr) (fp : U64) (sz : capability.FrameSize) (rt : U64) - (dev mp e : Bool) (asid va : U64), cap = .Frame fp sz rt dev mp e asid va → - lbl = fl4_abi.label.ARMPageDeriveSubframe → sz = capability.FrameSize.Large → dev = false → - (fp.val % 2 ^ 21 = 0 ∧ CapRt.Canonical fp) ∧ - ∀ w ∈ Z.G.chains.flatten, ∀ (q vm' : U64), fp.val ≤ q.val → q.val < fp.val + 2 ^ 21 → - OvlA (absCapA (.Frame q .Small vm' false false false 0#u64 0#u64)) (absCapA (capAtA (L.mem s) w)) → - isFrameA (capAtA (L.mem s) w) = true ∧ ∃ ch ∈ Z.G.chains, cslotAddrA cte ∈ ch ∧ w ∈ ch) + (hPtMap : PtMapSiteA st Z H OS σ s) (hFrMap : FrMapSiteA st OS s) (hFrSub : FrSubSiteA st Z OS s) (hAsidAssign : ∀ (cap : capability.Cap) (lbl p base : U64), cap = .AsidPool p base → lbl = fl4_abi.label.ARMASIDPoolAssign → ∀ u ∈ OS, ∀ k root oldAsid oldVa, capA st s u = assignUnmappedA k root oldAsid oldVa → UnmRootAssignA k (L.mem s) σ root) @@ -71,7 +61,11 @@ theorem DecErrSpecPA.archVs (K : ArchKeepsA ar AR) have K1 := decInv_arch_jA K Je RS hvcR J.tabS1 J.tabExt J3.ksbAligned J3.offAsE hYAs hIpa hPC hFI hTr (fun y hy hn => J3.j5.2.2 y hy hn) hcO hD sl hab hslO (capA st s r1.slot) hP.1 hcap info.label (msgLenA info buf) buf blocking calling donate false e argsU hlen hargsU (Fl4SpecA64.toBl cptr.bv) excaps hok false buffer - (hPtMap _ _) (hFrMap _ _) (hFrSub _ _ sl) (hAsidAssign _ _) + (fun ptr' mp' asid' va' hc _ hmp => hPtMap (cslotAddrA sl) hslO ptr' asid' va' (by subst hmp; rw [← hsl]; exact hc)) + (fun fp sz rt dev mp e asid va hc _ => hFrMap (cslotAddrA sl) hslO fp sz rt dev mp e asid va (by rw [← hsl]; exact hc)) + (fun fp sz rt dev mp e asid va hc _ hsz hdev => + hFrSub sl hslO fp sz rt dev mp e asid va (by rw [← hsl]; exact hc) hsz hdev) + (hAsidAssign _ _) have hd' : syscall.decode_invocation st ar s a info.label (msgLenA info buf) (cslotAddrA sl) (capA st s r1.slot) blocking calling donate false buf e = ok (.Err x, s', a') := by rw [← hsl]; exact hd rw [hd', WP.spec_ok] at K1 diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispBaseA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispBaseA.lean index c6b132f27..df53810d2 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispBaseA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispBaseA.lean @@ -30,6 +30,7 @@ import Fl4SpecA64.Ext.Invocation import Fl4ProofsA64.P3.FrontEndExtraA import Fl4ProofsA64.P3.EmptyA import Fl4ProofsA64.P3.CnodeCopyA +import Fl4ProofsA64.P3.McGrowA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -196,7 +197,7 @@ variable {S : Type} (st : machine.Store S) [L : LawfulStore st] {A : Type} /-- **The record at a body's end** (module docstring). `n` is the core bound (`finish` uses `fl4A64Platform.numNodes`); `Cs` the entry's kernel cores (`XSetsA.Cs`, which no body changes). -/ -def A64RelS3 (AR : A → HwRootA → Prop) (ar : machine.Arch A) (nA : U64) (n : Nat) (Cs : Set U64) (s : S) (a : A) +def A64RelS3fx (AR : A → HwRootA → Prop) (ar : machine.Arch A) (nA : U64) (n : Nat) (Cs : Set U64) (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) : Prop := ∃ (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64), @@ -204,6 +205,17 @@ def A64RelS3 (AR : A → HwRootA → Prop) (ar : machine.Arch A) (nA : U64) (n : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m ∧ Sched.BodyOKA σ m +/-- **The record at a body's end, at the view the body left** (R1): `A64RelS3at … m m'` is `A64RelS3fx` at the grown +view `m'` (`McGrowA m m'`: a Retype that creates a TCB or resets changes the ghost `McState`). -/ +def A64RelS3at (AR : A → HwRootA → Prop) (ar : machine.Arch A) (nA : U64) (n : Nat) (Cs : Set U64) (s : S) (a : A) + (σ : Fl4SpecA64.State Unit) (m m' : Fl4SpecA64.McState) : Prop := + McGrowA m m' ∧ A64RelS3fx st AR ar nA n Cs s a σ m' + +/-- **The record at a body's end** (module docstring): `A64RelS3 … m` hides the view `m'` the body left. -/ +def A64RelS3 (AR : A → HwRootA → Prop) (ar : machine.Arch A) (nA : U64) (n : Nat) (Cs : Set U64) (s : S) (a : A) + (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) : Prop := + ∃ m' : Fl4SpecA64.McState, A64RelS3at st AR ar nA n Cs s a σ m m' + /-- **The record at a preempted invocation's end** (integration): `A64RelS3` with `BodyPPA` for `BodyOKA`. -/ def A64RelPS3 (AR : A → HwRootA → Prop) (ar : machine.Arch A) (nA : U64) (n : Nat) (Cs : Set U64) (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) : Prop := @@ -272,16 +284,11 @@ theorem VsErrRelA.ne_preempted {e : error.Exc} {e' : Fl4SpecA64.SyscallError} (h · exact h · cases h -theorem A64RelS3.toPS {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U64} {n : Nat} {Cs : Set U64} {s : S} - {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (R : A64RelS3 st AR ar nA n Cs s a σ m) : - A64RelPS3 st AR ar nA n Cs s a σ m := - let ⟨Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, hCs, J, B⟩ := R - ⟨Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, hCs, J, B.toPP⟩ - theorem A64RelS3.toR {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U64} {n : Nat} {Cs : Set U64} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (R : A64RelS3 st AR ar nA n Cs s a σ m) - (r : core.result.Result Unit error.Exc) : A64RelRS3 st AR ar nA n Cs r s a σ m := by - rcases r with _ | (_ | _ | _ | _) <;> first | exact R | exact R.toPS + (r : core.result.Result Unit error.Exc) (hnp : r ≠ .Err error.Exc.Preempted) : + A64RelRS3 st AR ar nA n Cs r s a σ m := by + rcases r with _ | (_ | _ | _ | _) <;> first | exact R | exact absurd rfl hnp theorem DispPostA.toR {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U64} {n : Nat} {Cs : Set U64} {s : S} {a : A} {m : Fl4SpecA64.McState} {lbl len slot : U64} {blk call don fp : Bool} {buf : U64} @@ -290,7 +297,7 @@ theorem DispPostA.toR {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : (h : DispPostA st AR ar nA n Cs s a m lbl len slot blk call don fp buf extra Out) : DispPostRA st AR ar nA n Cs s a m Clock lbl len slot blk call don fp buf extra Out := let ⟨r, s', a', σ', e, o, c, R, hnp⟩ := h - ⟨r, s', a', σ', e, o, c, R.toR r, fun h => absurd h hnp⟩ + ⟨r, s', a', σ', e, o, c, R.toR r hnp, fun h => absurd h hnp⟩ theorem A64RelS3.ofJ {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} @@ -298,8 +305,30 @@ theorem A64RelS3.ofJ {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {Cs : Set U64} (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) (B : Sched.BodyOKA σ m) (hCs : Z.Cs = Cs := by rfl) : A64RelS3 st AR ar nA n Cs s a σ m := + ⟨m, McGrowA.refl m, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, hCs, J, B⟩ + +theorem A64RelS3.ofJg {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} + {σ : Fl4SpecA64.State Unit} {m m' : Fl4SpecA64.McState} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {Cs : Set U64} (hg : McGrowA m m') + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m') + (B : Sched.BodyOKA σ m') (hCs : Z.Cs = Cs := by rfl) : A64RelS3 st AR ar nA n Cs s a σ m := + ⟨m', hg, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, hCs, J, B⟩ + +theorem A64RelS3fx.ofJ {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {Cs : Set U64} + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (B : Sched.BodyOKA σ m) (hCs : Z.Cs = Cs := by rfl) : A64RelS3fx st AR ar nA n Cs s a σ m := ⟨_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, hCs, J, B⟩ +/-- A record at the grown view `m'` is a record at `m`. -/ +theorem A64RelS3fx.toS3 {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} + {σ : Fl4SpecA64.State Unit} {m m' : Fl4SpecA64.McState} {n : Nat} {Cs : Set U64} (hg : McGrowA m m') + (R : A64RelS3fx st AR ar nA n Cs s a σ m') : A64RelS3 st AR ar nA n Cs s a σ m := + ⟨m', hg, R⟩ + end end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispDomA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispDomA.lean index 365503efd..2e98ecccc 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispDomA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispDomA.lean @@ -1,15 +1,18 @@ /- P3 (aarch64, A64-P3 Lift 1b, T3 dispatch): **the Domain dispatch group** (`Stage3DispBaseA`): `DomainSetSet` on any -thread, the caller included (`P3/Stage3LiftDomainA`'s `setDomainA`). +thread, the caller included (`P3/Stage3LiftDomainA`'s `setDomainA`), and `DomainScheduleConfigure` / +`DomainScheduleSetStart` (`P3/Stage3DomSchedA`'s `domConfigureA`, `domSetStartA`). -Named premises: [P] `hCs`; [S] `h1` (`numNodes = 1`: the target is on this core and its stall stalls nothing, -`P3/Stage3StallA`). +Named premises: `set`: [P] `hCs`; [S] `h1` (`numNodes = 1`: the target is on this core and its stall stalls nothing, +`P3/Stage3StallA`). `configure` and `setStart`: none beyond the accepted decode's conditions on the message words and +the schedule words. -/ import Fl4ProofsA64.P3.Stage3LiftDomainA import Fl4ProofsA64.P3.Stage3DispBaseA import Fl4ProofsA64.P3.Stage3StallA import Fl4ProofsA64.P3.Stage3LiftBodyA import Fl4ProofsA64.P3.DelNtfnRecA +import Fl4ProofsA64.P3.Stage3DomSchedA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -36,6 +39,28 @@ inductive DomScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (a (fun σ' => ∃ σ1, Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ Fl4SpecA64.invokeDomain (Z := Unit) (.invokeDomainSet (specPtr t) 0) σ1 = ({((), σ')}, False)) + | configure (slot : U64) (hsl : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Domain) + (len buf dur : U64) (blk call don : Bool) (extra : Aeneas.Std.Array obj.Slot 3#usize) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hl : ¬ len < 3#u64) (hi : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok 0#u64) + (hd : msg.syscall_arg st s (L.curW s) buf 1#u64 = ok 0#u64) + (hu : msg.syscall_arg st s (L.curW s) buf 2#u64 = ok dur) (hmax : dur.val < 2 ^ 56) + (hend : dur = 0#u64 → Sched.domStartWordA (st := st) s ≠ 0#u64) : + DomScopeA AR Z OS ar s a σ fl4_abi.label.DomainScheduleConfigure len slot blk call don false buf extra + (fun σ' => ∃ σ1, + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + Fl4SpecA64.invokeDomain (Z := Unit) + (.invokeDomainScheduleConfigure 0 0 (Fl4SpecA64.ucast Fl4SpecA64.domainDurationLen dur.bv)) σ1 = + ({((), σ')}, False)) + | setStart (slot : U64) (hsl : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Domain) + (len buf idx w : U64) (blk call don : Bool) (extra : Aeneas.Std.Array obj.Slot 3#usize) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hl : ¬ len < 1#u64) (hi : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok idx) + (hidx : idx < layout.NUM_DOMAIN_SCHEDULES) (hw : sched.dom_sched_duration st s idx = ok w) (hw0 : w ≠ 0#u64) : + DomScopeA AR Z OS ar s a σ fl4_abi.label.DomainScheduleSetStart len slot blk call don false buf extra + (fun σ' => ∃ σ1, + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + Fl4SpecA64.invokeDomain (Z := Unit) (.invokeDomainScheduleSetStart idx.val) σ1 = ({((), σ')}, False)) variable {st} variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} @@ -63,6 +88,17 @@ theorem DomScopeA.sound (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat obtain ⟨f, h | h⟩ := hra <;> rw [h] <;> rfl exact ⟨_, s2, a, σ2, hdec, ⟨σ1, h1, h2⟩, Sched.curW_keptA J.toJStage3A J2 hcur, A64RelS3.ofJ J2 (Sched.BodyOKA.ofRqAct J hxc hra), (by intro e; cases e)⟩ + | configure slot hsl hcov hcap len buf dur blk call don extra hext hSC hl hi hd hu hmax hend => + obtain ⟨σ1, σ2, s2, h1, h2, hdec, B, hcur, Q, J2⟩ := + J.domConfigureA hA hM hPl hfm hsl hcov hcap hext hSC hl hi hd hu hmax hend (blk := blk) (call := call) + (don := don) + exact ⟨_, s2, a, σ2, hdec, ⟨σ1, h1, h2⟩, Sched.curW_keptA J.toJStage3A J2 hcur, A64RelS3.ofJ J2 B, + (by intro e; cases e)⟩ + | setStart slot hsl hcov hcap len buf idx w blk call don extra hext hSC hl hi hidx hw hw0 => + obtain ⟨σ1, σ2, s2, h1, h2, hdec, B, hcur, Q, J2⟩ := + J.domSetStartA hA hM hPl hfm hsl hcov hcap hext hSC hl hi hidx hw hw0 (blk := blk) (call := call) (don := don) + exact ⟨_, s2, a, σ2, hdec, ⟨σ1, h1, h2⟩, Sched.curW_keptA J.toJStage3A J2 hcur, A64RelS3.ofJ J2 B, + (by intro e; cases e)⟩ end diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispIpcA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispIpcA.lean index 77e08677c..3bb410614 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispIpcA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispIpcA.lean @@ -8,7 +8,8 @@ Endpoint send / call (the `*DispA` wrappers of `P3/Stage3IpcBodyA`): non-blockin receiver, to a waiting receiver (plain or call without grant; donating call; non-donating call); Reply (detached, live, to a faulted caller). -Pending lift: Notification send to a bound thread running a VCPU, the `Err` returns. +Notification send to a bound thread running a VCPU (`JSyscallA.signalRunningVmA`). +Pending lift: the `Err` returns. A new arm is a constructor of `IpcScopeA` and a case of `IpcScopeA.sound`. Named premises: [P] `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `hc`, `hCs`, `hmb`, `hmax`, `htu`; [S] `h1` @@ -17,6 +18,7 @@ New module. -/ import Fl4ProofsA64.P3.Stage3DispBaseA import Fl4ProofsA64.P3.Stage3SignalIdleA +import Fl4ProofsA64.P3.Stage3SignalVmA import Fl4ProofsA64.P3.Stage3SigBoundRecA import Fl4ProofsA64.P3.Stage3CancelBadgedA import Fl4ProofsA64.P3.Stage3IpcBodyA @@ -79,6 +81,22 @@ inductive IpcScopeA (Z : XSetsA) (OS N E Rp : Set U64) (ar : machine.Arch A) (s (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ ((), σ') ∈ (sendSignal (Z := Unit) (specPtr p) badge.bv σ1).1) + | signalRunningVm + {p badge slot lbl len buf : U64} {recv blk call don fp : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {x : Notification} {t : ObjRef} {xt : Tcb} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Notification p badge true recv) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hp : p ∈ N) (hk : σ.kheap (specPtr p) = some (.notification x)) (hidle : x.ntfnObj = .idleNtfn) + (hb : x.ntfnBoundTcb = some t) (hkt : σ.kheap t = some (.tcb xt)) + (hs : xt.tcbState = .ext .runningVM) : + IpcScopeA Z OS N E Rp ar s σ m lbl len slot blk call don fp buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + ((), σ') ∈ (sendSignal (Z := Unit) (specPtr p) badge.bv σ1).1) | cancelBadged {slot lbl len buf index depth dest p b c0 cr cgs cg : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -281,6 +299,13 @@ theorem IpcScopeA.sound {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {O subst e1 have B := Sched.BodyEndA.ofSignalA J hkc hspec hI hD hid hQ J2.sr.inv J2.sinv.zc exact ⟨_, _, _, σ2, hdec, ⟨xc, _, hkc, rfl, hsp, hspec⟩, curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1, (by intro e; cases e)⟩ + | signalRunningVm hCs h1 hmb hmax htu hslot hcov hcap hext hSC hp hk hidle hb hkt hs => + have hc : m.curCore < fl4A64Platform.numNodes := by + rw [J.sr.sch.core]; exact hCs _ J.sr.sch.cpuCs + obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, ⟨B, hcur⟩, Q, Rl, J2⟩ := + J.signalRunningVmA hA hM hPl hfm hc hmb hmax htu hCs h1 hslot hcov hcap hext hSC hp hk hidle hb hkt hs + exact ⟨_, _, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, by rw [hspec]; exact Set.mem_singleton _⟩, + curW_keptA J.toJStage3A J2 hcur, A64RelS3.ofJ J2 B, (by intro e; cases e)⟩ | cancelBadged hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl hl2 hi hd hres hdc hdOS => obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, ⟨B, hcur⟩, Q, Rl, J2⟩ := J.cancelBadgedA hA hM hPl hfm hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl hl2 hi hd hres hdc hdOS diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispTcbA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispTcbA.lean index b4f45f036..479809991 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispTcbA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispTcbA.lean @@ -1,11 +1,13 @@ /- P3 (aarch64, A64-P3 Stage 3, Lift 3): **the TCB dispatch group** (`Stage3DispBaseA`): UnbindNotification on a bound thread (`JSyscallA.unbindNtfnA`), SetMCPriority (`JSyscallA.setMcpA`), SetPriority of an inactive thread (`JSyscallA.setPrioInactiveA`), SetPriority writing only the priority word (`JSyscallA.setPrioPlainA`), of an endpoint-blocked thread (`JSyscallA.setPrioEpA`), of a notification-blocked thread (`JSyscallA.setPrioNtfnA`), of a runnable queued or current thread (`JSyscallA.setPrioQueuedA`), BindNotification (`JSyscallA.bindNtfnA`), -SetTLSBase on another thread (`JSyscallA.setTlsA`), SetPACKeys (`JSyscallA.setPacKeysA`), Resume of a runnable +SetTLSBase on another thread (`JSyscallA.setTlsA`), SetTimer (`JSyscallA.setTimerA`), SetPACKeys (`JSyscallA.setPacKeysA`), Resume of a runnable thread (`JSyscallA.resumeRunnableA`), Resume of a stopped thread (`JSyscallA.resumeStoppedA`), WriteFPU (`JSyscallA.writeFpuA`), ReadFPU (`JSyscallA.readFpuA`), SetFlags (`JSyscallA.setFlagsA`), Suspend with a live VCPU run (`JSyscallA.tcbSuspendA`, ending in `BodyEndA`: the cancel and the suspension are one `DelStepA` step, `Stage3DelFinThrA`), SetSchedParams with a -null fault handler and an unchanged SC (`JSyscallA.setSchedParamsNullA`), SetSchedParams with an endpoint fault handler -and an unchanged SC (`JSyscallA.setSchedParamsEpA`). +null fault handler and any SC change (`JSyscallA.setSchedParamsEpA`), SetSchedParams with an endpoint fault handler +with any SC change (`JSyscallA.setSchedParamsEpA`), SetHighVSpace with a null or a live window cap +(`JSyscallA.setHighVSpaceA`; the perform is `invoke_set_high_vspace`, not `invoke_tcb`), SetSpace with a null or +endpoint fault handler and native or Stage-2 roots (`JSyscallA.setSpaceA`). A new arm is a constructor of `TcbScopeA` and a case of `TcbScopeA.sound`. @@ -29,19 +31,33 @@ import Fl4ProofsA64.P3.Stage3TcbPrioQArmA import Fl4ProofsA64.P3.Stage3TcbBindA import Fl4ProofsA64.P3.Stage3TcbTlsA import Fl4ProofsA64.P3.Stage3TcbTlsSelfA +import Fl4ProofsA64.P3.Stage3TcbTimerA import Fl4ProofsA64.P3.Stage3TcbPacA import Fl4ProofsA64.P3.Stage3TcbResumeNoopA import Fl4ProofsA64.P3.Stage3TcbResumeRqA import Fl4ProofsA64.P3.Stage3TcbFpuA import Fl4ProofsA64.P3.Stage3TcbFpuRdA import Fl4ProofsA64.P3.Stage3TcbFlagsA +import Fl4ProofsA64.P3.Stage3TcbReadRegsA +import Fl4ProofsA64.P3.Stage3TcbReadCallA +import Fl4ProofsA64.P3.Stage3TcbReadRegsSuspA +import Fl4ProofsA64.P3.Stage3TcbReadCallSuspA import Fl4ProofsA64.P3.Stage3TcbSuspendArmA +import Fl4ProofsA64.P3.Stage3TcbRegWriteArmA +import Fl4ProofsA64.P3.Stage3TcbRegCopyArmA +import Fl4ProofsA64.P3.Stage3TcbRegResumeA +import Fl4ProofsA64.P3.Stage3TcbRegCopyRsA +import Fl4ProofsA64.P3.Stage3TcbRegCopySelfA +import Fl4ProofsA64.P3.Stage3TcbRegCopySuspA import Fl4ProofsA64.P3.Stage3LiftTcbBufA import Fl4ProofsA64.P3.Stage3LiftTcbBufNzA import Fl4ProofsA64.P3.Stage3LiftTcbTimeoutA import Fl4ProofsA64.P3.Stage3LiftTcbTimeoutNnA import Fl4ProofsA64.P3.Stage3LiftTcbSspA import Fl4ProofsA64.P3.Stage3LiftTcbSspEpA +import Fl4ProofsA64.P3.Stage3LiftTcbHighA +import Fl4ProofsA64.P3.Stage3LiftTcbSpaceA +import Fl4ProofsA64.P3.Stage3LiftTcbCfgA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -201,6 +217,18 @@ inductive TcbScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (a (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ (.ok [], σ') ∈ ((fl4InvokeTcb (.setTLSBase (specPtr t) v.bv)).run σ1).1) + | setTimer + {slot lbl len buf t d bd : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetTimer) (hlen : ¬ len < 2#u64) + (hd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok d) + (hbd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok bd) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((invokeFl4Tcb (.setTimer (specPtr t) d.bv bd.bv)).run σ1).1) | setTlsSelf {slot lbl len buf t v : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) @@ -433,9 +461,8 @@ inductive TcbScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (a (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none (some (absCapA (capA st s src), κsrc)) none none none)).run σ1).1) - /-- SetSchedParams with a null fault handler, the SC unchanged (`target.sc = sc`, no SC step) and a target other - than the caller (`JSyscallA.setSchedParamsNullA`). Not covered by this constructor: an endpoint fault handler (the - insert after the deletion), `sc ≠ target.sc` (the SC `bind_tcb` / `unbind_tcb` steps), the caller as target. -/ + /-- SetSchedParams with a null fault handler (the deletion of slot 3 only), any target and any accepted SC change + (`JSyscallA.setSchedParamsEpA` with the `Null` case of its install). -/ | setSchedParamsNull {slot lbl len buf t authSlot scSlot fhSlot mcp prio auth v : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -456,8 +483,8 @@ inductive TcbScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (a (hprio : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok prio) (harg : authSlot ∈ OS) (hac : capA st s authSlot = .Thread auth) (hle1 : ¬ L.mem s (mcpA auth) < mcp) (hle2 : ¬ L.mem s (mcpA auth) < prio) - (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hold : obj.Tcb.sc st t s = ok v) - (hfh : capA st s fhSlot = .Null) (hne : t ≠ L.curW s) + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hmin : fl4MinBudget = MIN_BUDGET) + (hfh : capA st s fhSlot = .Null) (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (rr, s3, a3)) (hrr : rr = .Ok ()) : @@ -465,12 +492,12 @@ inductive TcbScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (a (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs (some (.nullCap, κsrc)) - (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) none)).run - σ1).1) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v))).run σ1).1) /-- SetSchedParams with an endpoint fault handler (installed into slot 3 after the deletion when `still_valid`), - the SC unchanged and a target other than the caller (`JSyscallA.setSchedParamsEpA`). Not covered: `sc ≠ target.sc`, - the caller as target. -/ + any target (the caller included) and any accepted SC change (`JSyscallA.setSchedParamsEpA`; `scUpdC`). Not covered: + the null handler with the caller as target or with a changed SC. -/ | setSchedParamsEp {slot lbl len buf t authSlot scSlot fhSlot mcp prio auth v : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -491,9 +518,8 @@ inductive TcbScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (a (hprio : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok prio) (harg : authSlot ∈ OS) (hac : capA st s authSlot = .Thread auth) (hle1 : ¬ L.mem s (mcpA auth) < mcp) (hle2 : ¬ L.mem s (mcpA auth) < prio) - (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hold : obj.Tcb.sc st t s = ok v) + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hmin : fl4MinBudget = MIN_BUDGET) (hnn : capA st s fhSlot ≠ .Null) (hValid : faults.valid_fault_handler (capA st s fhSlot) = ok true) - (hne : t ≠ L.curW s) (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = fhSlot) (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = @@ -503,8 +529,373 @@ inductive TcbScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (a setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs (some (absCapA (capA st s fhSlot), κsrc)) - (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) none)).run - σ1).1) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v))).run σ1).1) + + /-- SetHighVSpace with a null cap: slot 6 is deleted (`Preempted` not covered). -/ + | setHighVSpaceNull + {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Clock : A → Fl4SpecA64.MachineState → Prop} {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {κs κsrc : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetHighVSpace) + (he : tcb.extra ⟨len, buf, call, slot, extra⟩ 0#usize = ok (some src)) + (hn : capA st s src = .Null) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Ok ()) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok (), σ') ∈ ((invokeSetHighVSpace (Z := Unit) + ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩).run σ1).1) + + /-- SetHighVSpace with a mapped window its ASID still names, copied into slot 6 (`Preempted` not covered). -/ + | setHighVSpaceLive + {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Clock : A → Fl4SpecA64.MachineState → Prop} {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {κs κsrc : CslotPtr} + {p asid : U64} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetHighVSpace) + (he : tcb.extra ⟨len, buf, call, slot, extra⟩ 0#usize = ok (some src)) + (hc : capA st s src = .HighVSpace p true asid) (hfind : vspace.find_high_asid st s asid = ok (.Ok p)) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Ok ()) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok (), σ') ∈ ((invokeSetHighVSpace (Z := Unit) + ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩).run σ1).1) + + /-- **ReadRegisters, `Call` clear, no source suspension** (tcbregr): the caller's `Restart`, the source read (no state + change) and the caller's `Running`. [S] `h1`; decode-site facts `hlen`, `hf`, `hn`, `hlo`, `hhi`, `hself`, `hsuspend`. -/ + | readRegsSend + {slot lbl len buf t flags count : U64} {blk don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, false, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, false, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) + (hsuspend : (flags &&& 1#u64) = 0#u64) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk false don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4PerformInvocation blk false don + (.invokeTCB (.readRegisters (specPtr t) false count.bv ArchDefaultExtraRegisters))).run σ1).1) + + /-- **ReadRegisters, `Call` set, no source suspension** (tcbregr): the caller's `Restart`, the register reply (badge, + words in the message registers and the caller's IPC buffer, message info) and the caller's `Running`. **[S] `hu`** + (F2): the caller's receive-buffer frames are user frames (a selector at the reached state). -/ + | readRegsCall + {slot lbl len buf t flags count : U64} {blk don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, true, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, true, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) + (hsuspend : (flags &&& 1#u64) = 0#u64) + (hu : ∀ x, σ.kheap σ.curThread = some (.tcb x) → ∀ rp, ipcBufOfA true x = some rp → ∀ k, k < 128 → + inUserFrame (bufAddr rp k) σ) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk true don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4PerformInvocation blk true don + (.invokeTCB (.readRegisters (specPtr t) false count.bv ArchDefaultExtraRegisters))).run σ1).1) + + /-- **ReadRegisters, `Call` clear, source suspended** (tcbregr): `readRegsSend` with the suspension bit set. The source's + VCPU run is cancelled and it is suspended (`JSyscallA.suspendMidA`) between the caller's `Restart` and `Running`. + [P] `hmb`, `hmax`, `htu` (the Suspend arm's). -/ + | readRegsSendSusp + {slot lbl len buf t flags count : U64} {blk don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, false, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, false, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) + (hsuspend : (flags &&& 1#u64) ≠ 0#u64) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk false don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4PerformInvocation blk false don + (.invokeTCB (.readRegisters (specPtr t) true count.bv ArchDefaultExtraRegisters))).run σ1).1) + + /-- **ReadRegisters, `Call` set, source suspended** (tcbregr): `readRegsCall` with the suspension bit set. The source's + VCPU run is cancelled and it is suspended (`JSyscallA.suspendMidA`) between the caller's `Restart` and `Running`. + [P] `hmb`, `hmax`, `htu` (the Suspend arm's). **[S] `hu`** as `readRegsCall`. -/ + | readRegsCallSusp + {slot lbl len buf t flags count : U64} {blk don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, true, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, true, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) + (hsuspend : (flags &&& 1#u64) ≠ 0#u64) + (hu : ∀ x, σ.kheap σ.curThread = some (.tcb x) → ∀ rp, ipcBufOfA true x = some rp → ∀ k, k < 128 → + inUserFrame (bufAddr rp k) σ) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk true don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4PerformInvocation blk true don + (.invokeTCB (.readRegisters (specPtr t) true count.bv ArchDefaultExtraRegisters))).run σ1).1) + /-- WriteRegisters without resume on another thread (Stage 4, line tcbregw). -/ + | writeRegs + {slot lbl len buf t flags count tl : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {sbo : Option ObjRef} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBWriteRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok count) + (htail : len - 2#u64 = ok tl) (henough : ¬ tl < count) (hself : t ≠ L.curW s) + (hres : flags &&& 1#u64 = 0#u64) (hlen120 : len.val ≤ 120) + (hBN : sbo = none → buf = 0#u64) + (hBS : ∀ sb, sbo = some sb → (buf, sb) ∈ Bf ∧ buf ≠ 0#u64) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4InvokeTcb (.writeRegisters (specPtr t) false + ((List.range count.val).map fun i => + specArgA xc.tcbArch.tcbContext.userRegs sbo σ.machineState.underlyingMemory (i + 2)) + ArchDefaultExtraRegisters)).run σ1).1) + + /-- CopyRegisters, register transfer only (`flags & 3 = 0`), Stage 4 line tcbregw. -/ + | copyRegs + {slot lbl len buf t src srcSlot flags : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBCopyRegisters) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok srcSlot)) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (harg : srcSlot ∈ OS) (hsc : capA st s srcSlot = .Thread src) (hself : t ≠ L.curW s) + (hres1 : flags &&& 1#u64 = 0#u64) (hres2 : flags &&& 2#u64 = 0#u64) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4InvokeTcb (.copyRegisters (specPtr t) (specPtr src) false false + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1) + + /-- WriteRegisters with `resume` of a stopped thread other than the caller (Stage 4, line tcbregw). -/ + | writeRegsResume + {slot lbl len buf t flags count tl : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {sbo : Option ObjRef} {y : Tcb} {sl : CslotPtr} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = MIN_BUDGET ⦄) (hmbF : ∀ a, Fl4MinBudgetAgreeA ar a) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBWriteRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok count) + (htail : len - 2#u64 = ok tl) (henough : ¬ tl < count) (hself : t ≠ L.curW s) + (hres : flags &&& 1#u64 ≠ 0#u64) (hlen120 : len.val ≤ 120) + (hBN : sbo = none → buf = 0#u64) + (hBS : ∀ sb, sbo = some sb → (buf, sb) ∈ Bf ∧ buf ≠ 0#u64) + (hsl : specCapAtA σ sl = some (.threadCap (specPtr t))) + (hy : σ.kheap (specPtr t) = some (.tcb y)) (hstop : ¬ runnable y.tcbState = true ∧ ¬ idle y.tcbState) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4InvokeTcb (.writeRegisters (specPtr t) true + ((List.range count.val).map fun i => + specArgA xc.tcbArch.tcbContext.userRegs sbo σ.machineState.underlyingMemory (i + 2)) + ArchDefaultExtraRegisters)).run σ1).1) + + /-- CopyRegisters with the restart bit (`flags & 2`) of a stopped destination other than the caller. -/ + | copyRegsRestart + {slot lbl len buf t src srcSlot flags : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {y : Tcb} {sl : CslotPtr} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = MIN_BUDGET ⦄) (hmbF : ∀ a, Fl4MinBudgetAgreeA ar a) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBCopyRegisters) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok srcSlot)) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (harg : srcSlot ∈ OS) (hsc : capA st s srcSlot = .Thread src) (hself : t ≠ L.curW s) + (hres1 : flags &&& 1#u64 = 0#u64) (hres2 : flags &&& 2#u64 ≠ 0#u64) + (hsl : specCapAtA σ sl = some (.threadCap (specPtr t))) + (hy : σ.kheap (specPtr t) = some (.tcb y)) (hstop : ¬ runnable y.tcbState = true ∧ ¬ idle y.tcbState) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4InvokeTcb (.copyRegisters (specPtr t) (specPtr src) false true + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1) + + /-- CopyRegisters (`flags & 3 = 0`) into the caller itself (reschedule). -/ + | copyRegsSelf + {slot lbl len buf t src srcSlot flags : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBCopyRegisters) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok srcSlot)) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (harg : srcSlot ∈ OS) (hsc : capA st s srcSlot = .Thread src) (hself : t = L.curW s) + (hres1 : flags &&& 1#u64 = 0#u64) (hres2 : flags &&& 2#u64 = 0#u64) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4InvokeTcb (.copyRegisters (specPtr t) (specPtr src) false false + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1) + /-- CopyRegisters with the suspend bit (`flags & 1`, no restart bit): the source (an extra Thread cap, not the caller) + is suspended first (`suspendMidA`), then the registers are transferred to the destination (not the caller). -/ + | copyRegsSusp + {slot lbl len buf t src srcSlot flags : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBCopyRegisters) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok srcSlot)) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (harg : srcSlot ∈ OS) (hcovS : SlotCov st OS s srcSlot) (hsc : capA st s srcSlot = .Thread src) + (hself : t ≠ L.curW s) (hsrcne : src ≠ L.curW s) + (hres1 : flags &&& 1#u64 ≠ 0#u64) (hres2 : flags &&& 2#u64 = 0#u64) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4InvokeTcb (.copyRegisters (specPtr t) (specPtr src) true false + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1) + /-- SetSpace: the fault handler (`Null` or an endpoint), the CSpace root (a CNode with its new guard) and the VSpace + root (a native `Pml4` or a Stage-2 `Ept` level-0 root) installed into slots 3, 0, 1 after the caller's restart + (`JSyscallA.setSpaceA`); the target may be the caller. The decode's derive facts (`hcc`, `hccap`, `hwfc`, `hencc`, + `hvc`, `hvk`, `hvdr`) are state facts implied by `hRoots`. Both outcomes of the three deletions are in + `TcbChainOutA` (`Preempted` not covered by this constructor). -/ + | setSpace + {slot lbl len buf t fs cs vs cdata vdata : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Clock : A → Fl4SpecA64.MachineState → Prop} {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {ccap vcap : capability.Cap} {p r gs g gs' g' : U64} {κs κfs κcs κvs : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetSpace) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 2#u64 = ok (.Ok fs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 2#u64 = ok (.Ok cs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 2#u64 = ok (.Ok vs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hfhv : faults.valid_fault_handler (capA st s fs) = ok true) + (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hwfc : CapWfA ccap) (hencc : CapRt.EncWf ccap) + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hvdr : ∀ s' : S, objects.derive_cap st s' vs vcap = ok (.Ok vcap)) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAf : AbsSlotA Z.th κfs) (hκf : cslotAddrA κfs = fs) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Ok ()) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs (some (absCapA (capA st s fs), κfs)) + none (some (absCapA ccap, κcs)) (some (absCapA vcap, κvs)) none)).run σ1).1) + + /-- Configure with buffer address 0: the roots installed into slots 0 and 1 after the caller's restart, the buffer + cleared (`JSyscallA.configureA`, `TcbMidA.bufStepA`); the target may be the caller. -/ + | configureBufZero + {slot lbl len buf t cs vs bs cdata vdata : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Clock : A → Fl4SpecA64.MachineState → Prop} {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {ccap vcap : capability.Cap} {p r gs g gs' g' : U64} {κs κcs κvs κbs : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBConfigure) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 3#u64 = ok (.Ok cs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 3#u64 = ok (.Ok vs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 3#u64 = ok (.Ok bs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hwfc : CapWfA ccap) (hencc : CapRt.EncWf ccap) + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hvdr : ∀ s' : S, objects.derive_cap st s' vs vcap = ok (.Ok vcap)) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) + (hAb : AbsSlotA Z.th κbs) (hκb : cslotAddrA κbs = bs) + (hba : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 2#u64 = ok 0#u64) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Ok ()) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none (some (absCapA ccap, κcs)) + (some (absCapA vcap, κvs)) (some (Fl4SpecA64.dataToVref (0#u64).bv, none)))).run σ1).1) + + /-- Configure with a non-zero 1024-aligned buffer address and a non-device Frame source; `hag` is the entry agreement + of the 128 words of the new buffer ([S]). -/ + | configureBuf + {baddr ptr rights asid va bits : U64} {size : capability.FrameSize} {mp ep : Bool} + {slot lbl len buf t cs vs bs cdata vdata : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Clock : A → Fl4SpecA64.MachineState → Prop} {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {ccap vcap : capability.Cap} {p r gs g gs' g' : U64} {κs κcs κvs κbs : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBConfigure) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 3#u64 = ok (.Ok cs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 3#u64 = ok (.Ok vs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 3#u64 = ok (.Ok bs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hwfc : CapWfA ccap) (hencc : CapRt.EncWf ccap) + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hvdr : ∀ s' : S, objects.derive_cap st s' vs vcap = ok (.Ok vcap)) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) + (hAb : AbsSlotA Z.th κbs) (hκb : cslotAddrA κbs = bs) + (hba : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 2#u64 = ok baddr) (hbn : baddr ≠ 0#u64) + (hbal : baddr.val % 1024 = 0) + (hsrcF : capA st s bs = .Frame ptr size rights false mp ep asid va) (hbits : size.bits = ok bits) + (hag : FrAgA st OS {b | ∃ k : U64, k.val < 128 ∧ b = bufW (bufAddrOfA ptr baddr bits) k} s σ) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Ok ()) : + TcbScopeA AR Z OS ar s a σ Bf lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none (some (absCapA ccap, κcs)) + (some (absCapA vcap, κvs)) (some (Fl4SpecA64.dataToVref baddr.bv, + some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), κbs))))).run σ1).1) variable {st} @@ -573,10 +964,41 @@ theorem TcbScopeA.soundOk [PlainStore st] {AR : A → HwRootA → Prop} {Z : XSe obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, J2⟩ := J.bindNtfnA hA hM hPl hfm hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he hns hncap hfree hq hnfree exact ⟨_, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2.1 J2.2.2, A64RelS3.ofJ J2.1 J2.2.1⟩ + | @writeRegs _ _ _ _ _ _ _ _ _ _ _ _ sbo hCs h1 hslot hcov hcap hext hSC hlbl hlen hf hn htail henough hself hres hlen120 hBN hBS => + obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, J2⟩ := + J.writeRegsA hA hM hPl hfm hCs h1 hslot hcov hcap hext hSC hlbl hlen hf hn htail henough hself hres (sbo := sbo) hBN hBS + exact ⟨_, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2.1 J2.2.2, A64RelS3.ofJ J2.1 J2.2.1⟩ + | copyRegs hCs h1 hslot hcov hcap hext hSC hlbl he hf harg hsc hself hres1 hres2 => + obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, J2⟩ := + J.copyRegsA hA hM hPl hfm hCs h1 hslot hcov hcap hext hSC hlbl he hf harg hsc hself hres1 hres2 + exact ⟨_, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2.1 J2.2.2, A64RelS3.ofJ J2.1 J2.2.1⟩ + | @writeRegsResume _ _ _ _ _ _ _ _ _ _ _ _ sbo _ _ hCs h1 hmb hmbF hmax htu hslot hcov hcap hext hSC hlbl hlen hf hn htail henough hself hres hlen120 hBN hBS hsl hy hstop => + obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, stk, J2, B⟩ := + J.writeRegsResumeA hA hM hPl hfm hCs h1 hmb hmbF hmax htu hslot hcov hcap hext hSC hlbl hlen hf hn htail henough + hself hres (sbo := sbo) hBN hBS hsl hy hstop + exact ⟨_, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1⟩ + | copyRegsRestart hCs h1 hmb hmbF hmax htu hslot hcov hcap hext hSC hlbl he hf harg hsc hself hres1 hres2 hsl hy hstop => + obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, stk, J2, B⟩ := + J.copyRegsRestartA hA hM hPl hfm hCs h1 hmb hmbF hmax htu hslot hcov hcap hext hSC hlbl he hf harg hsc hself hres1 + hres2 hsl hy hstop + exact ⟨_, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1⟩ + | copyRegsSelf hCs h1 hslot hcov hcap hext hSC hlbl he hf harg hsc hself hres1 hres2 => + obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, J2, B⟩ := + J.copyRegsSelfA hA hM hPl hfm hCs h1 hslot hcov hcap hext hSC hlbl he hf harg hsc hself hres1 hres2 + exact ⟨_, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1⟩ + | copyRegsSusp hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he hf harg hcovS hsc hself hsrcne hres1 hres2 => + obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, stk, J2, B⟩ := + J.copyRegsSuspA hA hM hPl hfm hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he hf harg hcovS hsc hself hsrcne + hres1 hres2 + exact ⟨_, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1⟩ | setTls hCs h1 hslot hcov hcap hext hSC hlbl hlen hv hne => obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, J2⟩ := J.setTlsA hA hM hPl hfm hCs h1 hslot hcov hcap hext hSC hlbl hlen hv hne exact ⟨_, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2.1 J2.2.2, A64RelS3.ofJ J2.1 J2.2.1⟩ + | setTimer hCs h1 hslot hcov hcap hext hSC hlbl hlen hd hbd => + obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, J2⟩ := + J.setTimerA hA hM hPl hfm hCs h1 hslot hcov hcap hext hSC hlbl hlen hd hbd + exact ⟨_, _, σ2, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2.1 J2.2.2, A64RelS3.ofJ J2.1 J2.2.1⟩ | setTlsSelf hCs h1 hslot hcov hcap hext hSC hlbl hlen hv hself => obtain ⟨xc, σ1, σ2, s2, hkc, e1, hsp, hspec, hdec, Q, Rl, J2⟩ := J.setTlsSelfA hA hM hPl hfm hCs h1 hslot hcov hcap hext hSC hlbl hlen hv hself @@ -655,25 +1077,34 @@ theorem TcbScopeA.soundOk [PlainStore st] {AR : A → HwRootA → Prop} {Z : XSe · rw [hrr] at hr; cases hr | @setSchedParamsNull slot lbl len buf t authSlot scSlot fhSlot mcp prio auth v blk call don extra Clock rr s3 a3 κs κsrc hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 he2 hmcp hprio harg hac hle1 hle2 hsc - hold hfh hne hAκ hκ hdec hrr => + hmin hfh hAκ hκ hdec hrr => + obtain ⟨hsrcM, hsrc0⟩ := tcbExtra2_memA he2 + obtain ⟨ss', ps, hss1, hss2, hss3, -⟩ := J.toJStage3A.cnSlot_of_covA (hSC _ hsrcM hsrc0) obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := - J.setSchedParamsNullA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 - he2 hmcp hprio harg hac hle1 hle2 hsc hold hfh hne hAκ hκ κsrc + J.setSchedParamsEpA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 + he2 hmcp hprio harg hac hle1 hle2 hsc hmin (by rw [hfh]; rfl) hAκ hκ ⟨ps, hss1, Or.inl hss2⟩ hss3 have e := okinj (hdec.symm.trans hdec') simp only [Prod.mk.injEq] at e obtain ⟨e1', e2', e3'⟩ := e subst e1' e2' e3' rcases hres with ⟨-, hspec, B⟩ | ⟨hr, -⟩ - · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hspec κs⟩, Sched.curW_keptA J.toJStage3A J2 B.2, + · have hs : (.ok [], σ3) ∈ ((fl4InvokeTcb (Z := Unit) (.threadControlSched (specPtr t) κs (some (.nullCap, κsrc)) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v))).run σ1).1 := by + have h0 := hspec κs + rw [hfh] at h0 + simp only [fl4InvokeTcb] at h0 ⊢ + rwa [fl4InstallTcbCap_nullA (specPtr t) κs κs κsrc ss' 3] + exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hs⟩, Sched.curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1⟩ · rw [hrr] at hr; cases hr | @setSchedParamsEp slot lbl len buf t authSlot scSlot fhSlot mcp prio auth v blk call don extra Clock rr s3 a3 κs κsrc hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 he2 hmcp hprio harg hac hle1 hle2 hsc - hold hnn hValid hne hAκ hκ hAsrc hκsrc hdec hrr => + hmin hnn hValid hAκ hκ hAsrc hκsrc hdec hrr => obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := J.setSchedParamsEpA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 - he2 hmcp hprio harg hac hle1 hle2 hsc hold hnn hValid hne hAκ hκ hAsrc hκsrc + he2 hmcp hprio harg hac hle1 hle2 hsc hmin hValid hAκ hκ hAsrc hκsrc have e := okinj (hdec.symm.trans hdec') simp only [Prod.mk.injEq] at e obtain ⟨e1', e2', e3'⟩ := e @@ -683,6 +1114,100 @@ theorem TcbScopeA.soundOk [PlainStore st] {AR : A → HwRootA → Prop} {Z : XSe A64RelS3.ofJ J2 B.1⟩ · rw [hrr] at hr; cases hr + | @setHighVSpaceNull slot lbl len buf t src blk call don extra Clock rr s3 a3 κs κsrc hCnt P hCl hCs h1 hslot hcov hcap + hext hSC hlbl he hn hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setHighVSpaceA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he + (Or.inl hn) hAκ hκ hAsrc hκsrc + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨-, hspec, B⟩ | ⟨hr, -⟩ + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, + A64RelS3.ofJ J2 B.1⟩ + · rw [hrr] at hr; cases hr + + | @setHighVSpaceLive slot lbl len buf t src blk call don extra Clock rr s3 a3 κs κsrc p asid hCnt P hCl hCs h1 hslot hcov hcap + hext hSC hlbl he hc hfind hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setHighVSpaceA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he + (Or.inr ⟨p, asid, hc, hfind⟩) hAκ hκ hAsrc hκsrc + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨-, hspec, B⟩ | ⟨hr, -⟩ + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, + A64RelS3.ofJ J2 B.1⟩ + · rw [hrr] at hr; cases hr + + | readRegsSend hCs h1 hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend => + obtain ⟨xc, σ1, σ3, s3, hkc, e1, hsp, hspec, hdec, Q, Rl, J2, B⟩ := + J.readRegsSendA hA hM hPl hfm hCs h1 hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend + exact ⟨_, _, σ3, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1⟩ + + | readRegsCall hCs h1 hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend hu => + obtain ⟨xc, σ1, σ3, s3, hkc, e1, hsp, hspec, hdec, Ac', Q, Rl, J2, B⟩ := + J.readRegsCallA hA hM hPl hfm hCs h1 hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend hu + exact ⟨_, _, σ3, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1⟩ + | readRegsSendSusp hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend => + obtain ⟨xc, σ1, σ3, s3, hkc, e1, hsp, hspec, hdec, Q, Rl, stk', J2, B⟩ := + J.readRegsSendSuspA hA hM hPl hfm hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend + exact ⟨_, _, σ3, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1⟩ + + | readRegsCallSusp hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend hu => + obtain ⟨xc, σ1, σ3, s3, hkc, e1, hsp, hspec, hdec, Ac', Q, Rl, stk', J2, B⟩ := + J.readRegsCallSuspA hA hM hPl hfm hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend hu + exact ⟨_, _, σ3, hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, A64RelS3.ofJ J2 B.1⟩ + | @setSpace slot lbl len buf t fs cs vs cdata vdata blk call don extra Clock rr s3 a3 ccap vcap p r gs g gs' g' κs κfs κcs + κvs hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hfhv hcc hccap hwfc hencc hvc hvk hvdr + hAκ hκ hAf hκf hAc hκc hAv hκv hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, hkc, e1, hsp, σ3, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setSpaceA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hfhv + hcc hccap hwfc hencc hvc hvk hvdr hAκ hκ hAf hκf hAc hκc hAv hκv + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨-, hspec, B⟩ | ⟨hr, -⟩ + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, + A64RelS3.ofJ J2 B.1⟩ + · rw [hrr] at hr; cases hr + + | @configureBufZero slot lbl len buf t cs vs bs cdata vdata blk call don extra Clock rr s3 a3 ccap vcap p r gs g gs' g' κs + κcs κvs κbs hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hcc hccap hwfc hencc hvc hvk + hvdr hAκ hκ hAc hκc hAv hκv hAb hκb hba hdec hrr => + have hag0 : FrAgA st OS (∅ : Set U64) s σ := fun _ h => absurd h (Set.notMem_empty _) + obtain ⟨r', s3', a3', hdec', xc, σ1, hkc, e1, hsp, σ3, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.configureA hA hM hPl s a σ m hCnt hCl hag0 P hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hba + (tcbDeriveBuffer_zeroA (capA_eq s bs)) (fun h => absurd rfl h) (by decide) hRoots hcc hccap hwfc hencc hvc hvk hvdr + hAκ hκ hAc hκc hAv hκv (Or.inl ⟨rfl, rfl, rfl⟩) + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨-, hspec, B⟩ | ⟨hr, -⟩ + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, + A64RelS3.ofJ J2 B.1⟩ + · rw [hrr] at hr; cases hr + | @configureBuf baddr ptr rights asid va bits size mp ep slot lbl len buf t cs vs bs cdata vdata blk call don extra Clock + rr s3 a3 ccap vcap p r gs g gs' g' κs κcs κvs κbs hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd + hvd hRoots hcc hccap hwfc hencc hvc hvk hvdr hAκ hκ hAc hκc hAv hκv hAb hκb hba hbn hbal hsrcF hbits hag hdec hrr => + obtain ⟨hbM, hb0⟩ := tcbExtra2_memA he2 + obtain ⟨r', s3', a3', hdec', xc, σ1, hkc, e1, hsp, σ3, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.configureA hA hM hPl s a σ m hCnt hCl hag P hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hba + (cfgDeriveBufNzA hbn hbal hsrcF) (fun _ => rfl) hbal hRoots hcc hccap hwfc hencc hvc hvk hvdr hAκ hκ hAc hκc hAv hκv + (J.cfgHBnzA hslot hcov hcap hb0 (hext _ hbM hb0) (hSC _ hbM hb0) hbn hsrcF hbits Set.Subset.rfl hAκ hκ hAb hκb) + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨-, hspec, B⟩ | ⟨hr, -⟩ + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hspec⟩, Sched.curW_keptA J.toJStage3A J2 B.2, + A64RelS3.ofJ J2 B.1⟩ + · rw [hrr] at hr; cases hr + /-- **The TCB group is sound** (module docstring). -/ theorem TcbScopeA.sound [PlainStore st] {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispTcbPreA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispTcbPreA.lean new file mode 100644 index 000000000..34fc78921 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3DispTcbPreA.lean @@ -0,0 +1,547 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP5): **the TCB cap-write arms' `Preempted` outcomes** (`TcbPreScopeA`). + +The `Ok` arms are `TcbScopeA` (`P3/Stage3DispTcbA`). Each constructor here has the same hypotheses as its `Ok` twin, with +`hrr : rr = .Err .Preempted`: the decode returns `Err Preempted` at the state of the preempted deletion or install. The +`Out` is the restart and the spec's preempted `invoke_tcb` (`(.error (), σ') ∈ …`, `PreExitA σ'`). `TcbPreScopeA.soundPre`: +the record is `A64RelPS3` (`BodyPreA.toPP`) and the clock holds; `TcbPreScopeA.sound` is `DispPostRA`. + +Arms: SetIPCBuffer (zero and non-zero address), SetTimeoutEndpoint (null and non-null), SetSchedParams (null and endpoint +handler), SetHighVSpace (null and live), SetSpace, Configure (zero and non-zero address). The older arms' outcome is +`PreExitA σ' ∧ …` (the restart, then the preempted perform). Named premises: those of the arms. New module. +-/ +import Fl4ProofsA64.P3.Stage3LiftTcbCfgA +import Fl4ProofsA64.P3.Stage3LiftTcbBufNzA +import Fl4ProofsA64.P3.Stage3LiftTcbTimeoutA +import Fl4ProofsA64.P3.Stage3LiftTcbTimeoutNnA +import Fl4ProofsA64.P3.Stage3LiftTcbSspA +import Fl4ProofsA64.P3.Stage3LiftTcbSspEpA +import Fl4ProofsA64.P3.Stage3LiftTcbHighA +import Fl4ProofsA64.P3.Stage3DispCnA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 + +noncomputable section + +section +variable {S : Type} (st : machine.Store S) [L : LawfulStore st] {A : Type} + +/-- **The TCB arms' preempted outcomes in scope** (module docstring). -/ +inductive TcbPreScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (ar : machine.Arch A) (s : S) (a : A) + (σ : State Unit) (Clock : A → Fl4SpecA64.MachineState → Prop) : + U64 → U64 → U64 → Bool → Bool → Bool → Bool → U64 → Aeneas.Std.Array obj.Slot 3#usize → + (State Unit → Prop) → Prop + /-- SetSpace preempted at slot 3, 0 or 1 (`JSyscallA.setSpaceA`'s `Preempted` outcome): the fault handler (`Null` or an endpoint), the CSpace root (a CNode with its new guard) and the VSpace + root (a native `Pml4` or a Stage-2 `Ept` level-0 root) installed into slots 3, 0, 1 after the caller's restart + (`JSyscallA.setSpaceA`); the target may be the caller. The decode's derive facts (`hcc`, `hccap`, `hwfc`, `hencc`, + `hvc`, `hvk`, `hvdr`) are state facts implied by `hRoots`. Both outcomes of the three deletions are in + `TcbChainOutA` (`Preempted` not covered by this constructor). -/ + | setSpacePre + {slot lbl len buf t fs cs vs cdata vdata : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {ccap vcap : capability.Cap} {p r gs g gs' g' : U64} {κs κfs κcs κvs : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetSpace) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 2#u64 = ok (.Ok fs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 2#u64 = ok (.Ok cs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 2#u64 = ok (.Ok vs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hfhv : faults.valid_fault_handler (capA st s fs) = ok true) + (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hwfc : CapWfA ccap) (hencc : CapRt.EncWf ccap) + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hvdr : ∀ s' : S, objects.derive_cap st s' vs vcap = ok (.Ok vcap)) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAf : AbsSlotA Z.th κfs) (hκf : cslotAddrA κfs = fs) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs (some (absCapA (capA st s fs), κfs)) + none (some (absCapA ccap, κcs)) (some (absCapA vcap, κvs)) none)).run σ1).1 ∧ PreExitA σ') + + /-- Configure with buffer address 0, preempted at a root or the buffer step (`JSyscallA.configureA`). -/ + | configureBufZeroPre + {slot lbl len buf t cs vs bs cdata vdata : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {ccap vcap : capability.Cap} {p r gs g gs' g' : U64} {κs κcs κvs κbs : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBConfigure) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 3#u64 = ok (.Ok cs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 3#u64 = ok (.Ok vs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 3#u64 = ok (.Ok bs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hwfc : CapWfA ccap) (hencc : CapRt.EncWf ccap) + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hvdr : ∀ s' : S, objects.derive_cap st s' vs vcap = ok (.Ok vcap)) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) + (hAb : AbsSlotA Z.th κbs) (hκb : cslotAddrA κbs = bs) + (hba : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 2#u64 = ok 0#u64) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none (some (absCapA ccap, κcs)) + (some (absCapA vcap, κvs)) (some (Fl4SpecA64.dataToVref (0#u64).bv, none)))).run σ1).1 ∧ PreExitA σ') + + /-- Configure with a non-zero 1024-aligned buffer address, preempted (`JSyscallA.configureA`); `hag` as in `TcbScopeA.configureBuf`. -/ + | configureBufPre + {baddr ptr rights asid va bits : U64} {size : capability.FrameSize} {mp ep : Bool} + {slot lbl len buf t cs vs bs cdata vdata : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {ccap vcap : capability.Cap} {p r gs g gs' g' : U64} {κs κcs κvs κbs : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBConfigure) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 3#u64 = ok (.Ok cs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 3#u64 = ok (.Ok vs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 3#u64 = ok (.Ok bs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hwfc : CapWfA ccap) (hencc : CapRt.EncWf ccap) + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hvdr : ∀ s' : S, objects.derive_cap st s' vs vcap = ok (.Ok vcap)) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) + (hAb : AbsSlotA Z.th κbs) (hκb : cslotAddrA κbs = bs) + (hba : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 2#u64 = ok baddr) (hbn : baddr ≠ 0#u64) + (hbal : baddr.val % 1024 = 0) + (hsrcF : capA st s bs = .Frame ptr size rights false mp ep asid va) (hbits : size.bits = ok bits) + (hag : FrAgA st OS {b | ∃ k : U64, k.val < 128 ∧ b = bufW (bufAddrOfA ptr baddr bits) k} s σ) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none (some (absCapA ccap, κcs)) + (some (absCapA vcap, κvs)) (some (Fl4SpecA64.dataToVref baddr.bv, + some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), κbs))))).run σ1).1 ∧ PreExitA σ') + + | setIpcBufZeroPre + {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetIPCBuffer) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok src)) + (harg : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok 0#u64) (hne : t ≠ L.curW s) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + PreExitA σ' ∧ ∀ κs : CslotPtr, (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none + (some (Fl4SpecA64.dataToVref (0#u64).bv, none)))).run σ1).1) + | setIpcBufPre + {slot lbl len buf t src baddr ptr rights asid va bits : U64} {size : capability.FrameSize} {mp ep : Bool} + {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {κs κsrc : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetIPCBuffer) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok src)) + (harg : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok baddr) (hbn : baddr ≠ 0#u64) + (hbal : baddr.val % 1024 = 0) + (hsrcF : capA st s src = .Frame ptr size rights false mp ep asid va) (hbits : size.bits = ok bits) + (hag : FrAgA st OS {b | ∃ k : U64, k.val < 128 ∧ b = bufW (bufAddrOfA ptr baddr bits) k} s σ) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + PreExitA σ' ∧ (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none + (some (Fl4SpecA64.dataToVref baddr.bv, + some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), κsrc))))).run σ1).1) + | setTimeoutNullPre + {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {κsrc : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) + (hlbl : lbl = fl4_abi.label.TCBSetTimeoutEndpoint) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 0#u64 = ok (.Ok src)) + (hnullh : capA st s src = .Null) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + PreExitA σ' ∧ ∀ κs : CslotPtr, (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none + (some (.nullCap, κsrc)) none none none)).run σ1).1) + + | setTimeoutNonNullPre + {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {κs κsrc : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetTimeoutEndpoint) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 0#u64 = ok (.Ok src)) + (hnn : capA st s src ≠ .Null) (hValid : faults.valid_fault_handler (capA st s src) = ok true) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + PreExitA σ' ∧ (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none + (some (absCapA (capA st s src), κsrc)) none none none)).run σ1).1) + + | setSchedParamsNullPre + {slot lbl len buf t authSlot scSlot fhSlot mcp prio auth v : U64} {blk call don : Bool} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {κs κsrc : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetSchedParams) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 2#u64 = ok (.Ok authSlot)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 2#u64 = ok (.Ok scSlot)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 2#u64 = ok (.Ok fhSlot)) + (hmcp : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok mcp) + (hprio : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok prio) + (harg : authSlot ∈ OS) (hac : capA st s authSlot = .Thread auth) + (hle1 : ¬ L.mem s (mcpA auth) < mcp) (hle2 : ¬ L.mem s (mcpA auth) < prio) + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hmin : fl4MinBudget = MIN_BUDGET) + (hfh : capA st s fhSlot = .Null) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + PreExitA σ' ∧ (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs (some (.nullCap, κsrc)) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v))).run + σ1).1) + + | setSchedParamsEpPre + {slot lbl len buf t authSlot scSlot fhSlot mcp prio auth v : U64} {blk call don : Bool} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {κs κsrc : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetSchedParams) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 2#u64 = ok (.Ok authSlot)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 2#u64 = ok (.Ok scSlot)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 2#u64 = ok (.Ok fhSlot)) + (hmcp : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok mcp) + (hprio : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok prio) + (harg : authSlot ∈ OS) (hac : capA st s authSlot = .Thread auth) + (hle1 : ¬ L.mem s (mcpA auth) < mcp) (hle2 : ¬ L.mem s (mcpA auth) < prio) + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hmin : fl4MinBudget = MIN_BUDGET) + (hnn : capA st s fhSlot ≠ .Null) (hValid : faults.valid_fault_handler (capA st s fhSlot) = ok true) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = fhSlot) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + PreExitA σ' ∧ (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs + (some (absCapA (capA st s fhSlot), κsrc)) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v))).run + σ1).1) + + | setHighVSpaceNullPre + {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {κs κsrc : CslotPtr} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetHighVSpace) + (he : tcb.extra ⟨len, buf, call, slot, extra⟩ 0#usize = ok (some src)) + (hn : capA st s src = .Null) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + PreExitA σ' ∧ (.error (), σ') ∈ ((invokeSetHighVSpace (Z := Unit) + ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩).run σ1).1) + + | setHighVSpaceLivePre + {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {rr : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + {κs κsrc : CslotPtr} + {p asid : U64} + (hCnt : CounterStepA σ) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetHighVSpace) + (he : tcb.extra ⟨len, buf, call, slot, extra⟩ 0#usize = ok (some src)) + (hc : capA st s src = .HighVSpace p true asid) (hfind : vspace.find_high_asid st s asid = ok (.Ok p)) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) + (hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (rr, s3, a3)) (hrr : rr = .Err .Preempted) : + TcbPreScopeA AR Z OS ar s a σ Clock lbl len slot blk call don false buf extra + (fun σ' => ∃ xc σ1, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + PreExitA σ' ∧ (.error (), σ') ∈ ((invokeSetHighVSpace (Z := Unit) + ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩).run σ1).1) + +variable {st} + +theorem A64RelPS3.ofJ {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {Cs : Set U64} + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (B : Sched.BodyPPA σ m) (hCs : Z.Cs = Cs := by rfl) : A64RelPS3 st AR ar nA n Cs s a σ m := + ⟨_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, hCs, J, B⟩ + +/-- **The preempted TCB arms run and keep the record** (module docstring). -/ +theorem TcbPreScopeA.soundPre [PlainStore st] {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} + {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {ar : machine.Arch A} {s : S} {a : A} {σ : State Unit} + {m : McState} {Clock : A → Fl4SpecA64.MachineState → Prop} + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + {lbl len slot : U64} {blk call don fp : Bool} {buf : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Out : State Unit → Prop} + (h : TcbPreScopeA st AR Z OS ar s a σ Clock lbl len slot blk call don fp buf extra Out) : + ∃ (s' : S) (a' : A) (σ' : State Unit), + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don fp buf extra = + ok (.Err .Preempted, s', a') ∧ Out σ' ∧ L.curW s' = L.curW s ∧ + A64RelPS3 st AR ar hPl.ipa n Z.Cs s' a' σ' m ∧ Clock a' σ'.machineState := by + cases h with + | @setSpacePre slot lbl len buf t fs cs vs cdata vdata blk call don extra rr s3 a3 ccap vcap p r gs g gs' g' κs κfs κcs + κvs hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hfhv hcc hccap hwfc hencc hvc hvk hvdr + hAκ hκ hAf hκf hAc hκc hAv hκv hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, hkc, e1, hsp, σ3, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setSpaceA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hfhv + hcc hccap hwfc hencc hvc hvk hvdr hAκ hκ hAf hκf hAc hκc hAv hκv + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hpre, hclk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hspec, hpre⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hclk⟩ + | @configureBufZeroPre slot lbl len buf t cs vs bs cdata vdata blk call don extra rr s3 a3 ccap vcap p r gs g gs' g' κs + κcs κvs κbs hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hcc hccap hwfc hencc hvc hvk + hvdr hAκ hκ hAc hκc hAv hκv hAb hκb hba hdec hrr => + have hag0 : FrAgA st OS (∅ : Set U64) s σ := fun _ h => absurd h (Set.notMem_empty _) + obtain ⟨r', s3', a3', hdec', xc, σ1, hkc, e1, hsp, σ3, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.configureA hA hM hPl s a σ m hCnt hCl hag0 P hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hba + (tcbDeriveBuffer_zeroA (capA_eq s bs)) (fun h => absurd rfl h) (by decide) hRoots hcc hccap hwfc hencc hvc hvk hvdr + hAκ hκ hAc hκc hAv hκv (Or.inl ⟨rfl, rfl, rfl⟩) + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hpre, hclk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hspec, hpre⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hclk⟩ + | @configureBufPre baddr ptr rights asid va bits size mp ep slot lbl len buf t cs vs bs cdata vdata blk call don extra + rr s3 a3 ccap vcap p r gs g gs' g' κs κcs κvs κbs hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd + hvd hRoots hcc hccap hwfc hencc hvc hvk hvdr hAκ hκ hAc hκc hAv hκv hAb hκb hba hbn hbal hsrcF hbits hag hdec hrr => + obtain ⟨hbM, hb0⟩ := tcbExtra2_memA he2 + obtain ⟨r', s3', a3', hdec', xc, σ1, hkc, e1, hsp, σ3, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.configureA hA hM hPl s a σ m hCnt hCl hag P hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hba + (cfgDeriveBufNzA hbn hbal hsrcF) (fun _ => rfl) hbal hRoots hcc hccap hwfc hencc hvc hvk hvdr hAκ hκ hAc hκc hAv hκv + (J.cfgHBnzA hslot hcov hcap hb0 (hext _ hbM hb0) (hSC _ hbM hb0) hbn hsrcF hbits Set.Subset.rfl hAκ hκ hAb hκb) + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hpre, hclk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hspec, hpre⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hclk⟩ + + | @setIpcBufZeroPre slot lbl len buf t src blk call don extra rr s3 a3 hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl + he harg hne hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setIpcBufZeroA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he harg hne + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hx, hk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hx, hspec⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hk⟩ + | @setIpcBufPre slot lbl len buf t src baddr ptr rights asid va bits size mp ep blk call don extra rr s3 a3 κs κsrc + hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he harg hbn hbal hsrcF hbits hag hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setIpcBufNzA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he harg hbn hbal hsrcF + hbits hag hAκ hκ hAsrc hκsrc + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hx, hk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hx, hspec κs⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hk⟩ + | @setTimeoutNullPre slot lbl len buf t src blk call don extra rr s3 a3 κsrc hCnt P hCl hCs h1 hslot hcov hcap hext hlbl + he hnullh hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setTimeoutNullA hA hM hPl s a σ m hCnt P hCl hCs h1 hslot hcov hcap hext hlbl he hnullh κsrc + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hx, hk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hx, hspec⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hk⟩ + | @setTimeoutNonNullPre slot lbl len buf t src blk call don extra rr s3 a3 κs κsrc hCnt P hCl hCs h1 hslot hcov hcap + hext hSC hlbl he hnn hValid hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setTimeoutNonNullA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he hnn hValid + hAκ hκ hAsrc hκsrc + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hx, hk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hx, hspec κs⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hk⟩ + | @setSchedParamsNullPre slot lbl len buf t authSlot scSlot fhSlot mcp prio auth v blk call don extra rr s3 a3 κs + κsrc hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 he2 hmcp hprio harg hac hle1 hle2 hsc + hmin hfh hAκ hκ hdec hrr => + obtain ⟨ss', ps, hss1, hss2, hss3, -⟩ := J.toJStage3A.cnSlot_of_covA (hSC _ (tcbExtra2_memA he2).1 (tcbExtra2_memA he2).2) + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setSchedParamsEpA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 + he2 hmcp hprio harg hac hle1 hle2 hsc hmin (by rw [hfh]; rfl) hAκ hκ ⟨ps, hss1, Or.inl hss2⟩ hss3 + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hx, hk⟩ + · rw [hrr] at hr; cases hr + · have hs : (.error (), σ3) ∈ ((fl4InvokeTcb (Z := Unit) (.threadControlSched (specPtr t) κs (some (.nullCap, κsrc)) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v))).run σ1).1 := by + have h0 := hspec κs + rw [hfh] at h0 + simp only [fl4InvokeTcb] at h0 ⊢ + rwa [fl4InstallTcbCap_nullA (specPtr t) κs κs κsrc ss' 3] + exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hx, hs⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hk⟩ + + | @setSchedParamsEpPre slot lbl len buf t authSlot scSlot fhSlot mcp prio auth v blk call don extra rr s3 a3 κs + κsrc hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 he2 hmcp hprio harg hac hle1 hle2 hsc + hmin hnn hValid hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setSchedParamsEpA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 + he2 hmcp hprio harg hac hle1 hle2 hsc hmin hValid hAκ hκ hAsrc hκsrc + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hx, hk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hx, hspec κs⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hk⟩ + + | @setHighVSpaceNullPre slot lbl len buf t src blk call don extra rr s3 a3 κs κsrc hCnt P hCl hCs h1 hslot hcov hcap + hext hSC hlbl he hn hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setHighVSpaceA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he + (Or.inl hn) hAκ hκ hAsrc hκsrc + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hx, hk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hx, hspec⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hk⟩ + + | @setHighVSpaceLivePre slot lbl len buf t src blk call don extra rr s3 a3 κs κsrc p asid hCnt P hCl hCs h1 hslot hcov hcap + hext hSC hlbl he hc hfind hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨r', s3', a3', hdec', xc, σ1, σ3, hkc, e1, hsp, G', Q, R, hw, Ac', Bf', stack', J2, hres⟩ := + J.setHighVSpaceA hA hM hPl s a σ m hfm hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he + (Or.inr ⟨p, asid, hc, hfind⟩) hAκ hκ hAsrc hκsrc + have e := okinj (hdec.symm.trans hdec') + simp only [Prod.mk.injEq] at e + obtain ⟨e1', e2', e3'⟩ := e + subst e1' e2' e3' + rcases hres with ⟨hr, -, -⟩ | ⟨-, hspec, hpp, hcur, hx, hk⟩ + · rw [hrr] at hr; cases hr + · exact ⟨_, _, σ3, hrr ▸ hdec, ⟨xc, σ1, hkc, e1, hsp, hx, hspec⟩, Sched.curW_keptA J.toJStage3A J2 hcur, + A64RelPS3.ofJ J2 hpp.toPP, hk⟩ + +/-- **The preempted TCB arms, as the dispatch post** (module docstring). -/ +theorem TcbPreScopeA.sound [PlainStore st] {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} + {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {ar : machine.Arch A} {s : S} {a : A} {σ : State Unit} + {m : McState} {Clock : A → Fl4SpecA64.MachineState → Prop} + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + {lbl len slot : U64} {blk call don fp : Bool} {buf : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Out : State Unit → Prop} + (h : TcbPreScopeA st AR Z OS ar s a σ Clock lbl len slot blk call don fp buf extra Out) : + DispPostRA st AR ar hPl.ipa n Z.Cs s a m Clock lbl len slot blk call don fp buf extra Out := + let ⟨s', a', σ', e, o, c, R, hc⟩ := TcbPreScopeA.soundPre hA hM hPl J hfm h + ⟨.Err .Preempted, s', a', σ', e, o, c, R, fun _ => hc⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispTopA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispTopA.lean index 2e5f44e21..9bd74dcec 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispTopA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispTopA.lean @@ -4,15 +4,15 @@ P3 (aarch64, A64-P3 Stage 3, T3): **the system-call dispatch top** over the arms cap returns, the spec outcome holds, and the Stage-3 record holds again. Scope (`DispScopeA`): the VSpace group (`VsScopeA`), the CNode group (`CnScopeA`), the Untyped group -(`UtScopeA`, an empty slot until the Untyped line is merged), the IPC group (`IpcScopeA`), the SchedContext group (`ScScopeA`), the TCB group (`TcbScopeA`), the cache-maintenance +(`UtScopeA`: Retype on a RAM Untyped with a child, no TCB created), the IPC group (`IpcScopeA`), the SchedContext group (`ScScopeA`), the TCB group (`TcbScopeA`), the cache-maintenance group (`FlScopeA`), the IRQ group (`IrqScopeA`: `IRQAckIRQ`, `IRQSetIRQHandler`, `IRQClearIRQHandler`), the one-word reply group (`ReplyScopeA`: -`ARMPageGetAddress`, `ARMPageTestAndClearAccessed`), the Domain group (`DomScopeA`: `DomainSetSet`), the VCPU group (`VcpuScopeA`: labels 61–64, 67, 68 of a VCPU cap with a successful decode), or the non-arch `Err` group (`ErrScopeA`: an `Err` other than `Preempted` of a non-arch, +`ARMPageGetAddress`, `ARMPageTestAndClearAccessed`), the Domain group (`DomScopeA`: `DomainSetSet`, `DomainScheduleConfigure`, `DomainScheduleSetStart`), the VCPU group (`VcpuScopeA`: labels 61–64, 67, 68 of a VCPU cap with a successful decode), or the non-arch `Err` group (`ErrScopeA`: an `Err` other than `Preempted` of a non-arch, non-IRQ-control cap, or any `Err` of the IRQ control cap). **Not in scope** (an invocation whose decode succeeds outside `DispScopeA` makes the top's scope premise `hArm` false at that -state: [S] limits, listed in DESIGN §9): Untyped Retype / RetypeShared (`UtScopeA` has -no constructor); TCB Configure, SetSpace, ReadRegisters, WriteRegisters, CopyRegisters, SetTimer, SetHighVSpace, the breakpoint labels and -single stepping, SetSchedParams with a changed SC or another handler cap; -DomainScheduleConfigure / SetStart; ARMASIDControlMakePool; ARMPageDeriveSubframe; the Stage-2 frame map, the PT map into a high +state: [S] limits, listed in DESIGN §9): Untyped Retype that resets, creates a TCB or uses a device Untyped (`UtScopeA` covers only the other Retypes; +RetypeShared is an `Err`); TCB Configure, SetSpace, ReadRegisters, WriteRegisters, CopyRegisters, SetTimer, the breakpoint labels and +single stepping, SetSchedParams with another handler cap kind; +ARMASIDControlMakePool; ARMPageDeriveSubframe; the Stage-2 frame map, the PT map into a high window or Stage-2, the T2 unmap shrink; Notification send to a bound thread running a VCPU. The `Err` returns (other than `Preempted`) are not in this scope: they are `hErr`'s (`decErrSpecA`) and `ErrScopeA`'s. @@ -20,6 +20,7 @@ Named premises: [J] `JSyscallA`; [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64Fram -/ import Fl4ProofsA64.P3.Stage3DispVsA import Fl4ProofsA64.P3.Stage3DispTcbA +import Fl4ProofsA64.P3.Stage3DispTcbPreA import Fl4ProofsA64.P3.Stage3DispCnA import Fl4ProofsA64.P3.Stage3DispUtA import Fl4ProofsA64.P3.Stage3DispFlushA @@ -52,10 +53,11 @@ def DispScope4A (nA lbl len slot : U64) (blk call don fp : Bool) (buf : U64) Out ∨ CnScopeA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar nA s a σ m Clock lbl len slot blk call don fp buf extra Out ∨ - UtScopeA lbl len slot blk call don fp buf extra Out ∨ + UtScopeA st AR n Z OS ar s a σ lbl len slot blk call don fp buf extra Out ∨ IpcScopeA st Z OS N E Rp ar s σ m lbl len slot blk call don fp buf extra Out ∨ ScScopeA st AR Z OS ar s a σ m lbl len slot blk call don fp buf extra Out ∨ - TcbScopeA st AR Z OS ar s a σ Bf lbl len slot blk call don fp buf extra Out + TcbScopeA st AR Z OS ar s a σ Bf lbl len slot blk call don fp buf extra Out ∨ + TcbPreScopeA st AR Z OS ar s a σ Clock lbl len slot blk call don fp buf extra Out variable (st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar s a σ m Clock) in /-- **The dispatch scope** (module docstring): Plan B's four groups, then one disjunct per Lift 1 group. -/ @@ -82,9 +84,9 @@ theorem JSyscallA.dispatchA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSpi DispPostRA st AR ar hPl.ipa n Z.Cs s a m Clock lbl len slot blk call don fp buf extra Out := h.elim (fun h => h.elim (fun h => (VsScopeA.sound hA hM hPl J hfm h).toR) fun h => h.elim (CnScopeA.sound hA hM hPl J hfm) fun h => - h.elim (fun h => (UtScopeA.sound h).toR) fun h => + h.elim (fun h => (UtScopeA.sound hA hPl J hfm h).toR) fun h => h.elim (fun h => (IpcScopeA.sound hA hM hPl J hfm h).toR) fun h => - h.elim (fun h => (ScScopeA.sound hA hM hPl J hfm h).toR) fun h => (TcbScopeA.sound hA hM hPl J hfm h).toR) + h.elim (fun h => (ScScopeA.sound hA hM hPl J hfm h).toR) fun h => h.elim (fun h => (TcbScopeA.sound hA hM hPl J hfm h).toR) fun h => TcbPreScopeA.sound hA hM hPl J hfm h) fun h => h.elim (fun h => (FlScopeA.sound J h).toR) fun h => h.elim (fun h => (IrqScopeA.sound (hCnt := hCnt) hA hM hPl J hfm h).toR) fun h => h.elim (fun h => (ReplyScopeA.sound hA hM hPl J hfm h).toR) fun h => diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispUtA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispUtA.lean index f31bcbf7a..16c700edb 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispUtA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispUtA.lean @@ -1,31 +1,161 @@ /- -P3 (aarch64, A64-P3 Stage 3, T3 dispatch): **the Untyped dispatch group's slot**, empty. `UtScopeA` has no -constructor until the Untyped line is on record edit #6 and merged; its constructors then carry that line's record -tops (Untyped Retype), each with a case of `sound`. Until then no Untyped invocation is in scope. +P3 (aarch64, A64-P3 Stage 4, T3 dispatch): **the Untyped dispatch group** (`Stage3DispBaseA`): `UntypedRetype` on a RAM +Untyped cap whose slot already has a CDT child (so no reset), every object type. -Named premises: none. +* `UtScopeA.retype`: the arm in scope, carrying the arm's case hypotheses (`JSyscallA.untypedRetypeA`, `P3/Stage3UtArmA`). +* `UtScopeA.retypeRst`: the same Retype on an Untyped without a CDT child, so it resets first: [S] the reset never runs the + chunk loop (`sb < 16 ∨ fi = 0`, one core), [P] the Stage-2 IPA width, `resetChunkBits = 16` and the post-reset barriers + (`JSyscallA.untypedRetypeRstA`). + The spec outcome is `fl4InvokeUntypedA64` of the decoded invocation from the restarted state. +* `UtScopeA.soundOk`, `UtScopeA.sound`: the decode succeeds and the record holds again. +* `UtScopeA.invSpecA`: the spec side, from the pinned operation. + +Still outside the scope (the tops are vacuous there): a Retype whose reset runs the chunk loop (the preempted reset needs +`A64RelPS3` at a hidden view: post-Stage-4 backlog) and a device Untyped. `UntypedRetypeShared` is an `Err` (`A64FrameMasks`): +`ErrScopeA`. + +Named premises: [P] `ArchTotal`, `ArchPlat`, `A64FrameMasks`, `hvi`/`hvirt` (the virtualization word), `hfan`, `hVP`, +`hKt`/`hK0`; [J] `JSyscallA`. -/ -import Fl4ProofsA64.P3.Stage3DispBaseA +import Fl4ProofsA64.P3.Stage3UtArmA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 -open fl4_core_a64 Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical noncomputable section -/-- **The Untyped arms in scope**: none yet (module docstring). Indexed as the other groups. -/ -inductive UtScopeA : U64 → U64 → U64 → Bool → Bool → Bool → Bool → U64 → Aeneas.Std.Array obj.Slot 3#usize → +section +variable {S : Type} (st : machine.Store S) [L : LawfulStore st] {A : Type} + +/-- **The Untyped arms in scope** (module docstring). Indexed as the other groups. -/ +inductive UtScopeA (AR : A → HwRootA → Prop) (n : Nat) (Z : XSetsA) (OS : Set U64) (ar : machine.Arch A) (s : S) (a : A) + (σ : Fl4SpecA64.State Unit) : + U64 → U64 → U64 → Bool → Bool → Bool → Bool → U64 → Aeneas.Std.Array obj.Slot 3#usize → (Fl4SpecA64.State Unit → Prop) → Prop + | retype (slot p sb fi : U64) (extra : Aeneas.Std.Array obj.Slot 3#usize) (lbl length buf : U64) + (blk call don : Bool) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) + (hslc : capA st s slot = .Untyped p sb fi false) + (sl : Fl4SpecA64.CslotPtr) (hsl : slot = cslotAddrA sl) + (hsrc : ∃ q, sl.1 = specPtr q ∧ Z.th q = some (.cnode sl.2.length)) + (vi : U64) (hvi : ar.virtualization a = ok vi) (hvirt : vi = 0#u64 ↔ Fl4SpecA64.fl4A64Virt = false) + (hfan : Fl4SpecA64.retypeFanOutLimit = 256#64) + (slbl : Fl4SpecA64.Data) + (hlbl : Fl4SpecA64.genInvocationType slbl = .untypedRetype ↔ lbl = fl4_abi.label.UntypedRetype) + (args : List U64) (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s (L.curW s) buf i = ok x) + (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) (hex : ExtraOKA Z.th (L.mem s) extra exs) + (hchild : ∃ x, σ.cdt x = some sl) + (inv : Fl4SpecA64.UntypedInvocation) + (hdecS : (Fl4SpecA64.fl4DecodeUntypedInvocationVirt (Z := Unit) slbl (args.map UScalar.bv) sl + (absCapA (.Untyped p sb fi false)) (exs.map Prod.fst)).run σ = ({(.ok inv, σ)}, False)) + (hVP : ∀ a1 : A, UtVcpuPlatA ar a1) (k : U64 → U64) + (hKt : ∀ (a1 : A) (i : U64), i.val < 511 → ar.kernel_ttbr1_entry a1 0#u64 i = ok (k i)) + (hK0 : ∀ i : U64, i.val < 256 → k i = 0#u64) + (hpin : DecPinA call Z.th σ slot (.invokeUntyped inv)) : + UtScopeA AR n Z OS ar s a σ lbl length slot blk call don false buf extra + (fun σ' => ∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + (.ok (), σ') ∈ ((Fl4SpecA64.fl4InvokeUntypedA64 (Z := Unit) inv).run + (stUpdA σ σ.curThread xT .restart)).1) + | retypeRst (slot p sb fi : U64) (extra : Aeneas.Std.Array obj.Slot 3#usize) (lbl length buf : U64) + (blk call don : Bool) + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) + (hslc : capA st s slot = .Untyped p sb fi false) + (sl : Fl4SpecA64.CslotPtr) (hsl : slot = cslotAddrA sl) + (hsrc : ∃ q, sl.1 = specPtr q ∧ Z.th q = some (.cnode sl.2.length)) + (vi : U64) (hvi : ar.virtualization a = ok vi) (hvirt : vi = 0#u64 ↔ Fl4SpecA64.fl4A64Virt = false) + (hfan : Fl4SpecA64.retypeFanOutLimit = 256#64) + (slbl : Fl4SpecA64.Data) + (hlbl : Fl4SpecA64.genInvocationType slbl = .untypedRetype ↔ lbl = fl4_abi.label.UntypedRetype) + (args : List U64) (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s (L.curW s) buf i = ok x) + (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) (hex : ExtraOKA Z.th (L.mem s) extra exs) + (hnochild : ¬ ∃ x, σ.cdt x = some sl) + (inv : Fl4SpecA64.UntypedInvocation) + (hdecS : (Fl4SpecA64.fl4DecodeUntypedInvocationVirt (Z := Unit) slbl (args.map UScalar.bv) sl + (absCapA (.Untyped p sb fi false)) (exs.map Prod.fst)).run σ = ({(.ok inv, σ)}, False)) + (hVP : ∀ a1 : A, UtVcpuPlatA ar a1) (k : U64 → U64) + (hKt : ∀ (a1 : A) (i : U64), i.val < 511 → ar.kernel_ttbr1_entry a1 0#u64 i = ok (k i)) + (hK0 : ∀ i : U64, i.val < 256 → k i = 0#u64) + -- [S] one core; the reset never runs the chunk loop (a free index of zero, or a block below the chunk size) + (hnN : n ≤ Fl4SpecA64.fl4A64Platform.numNodes) (h1 : Fl4SpecA64.fl4A64Platform.numNodes = 1) + (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) (hS : sb.val < 16 ∨ fi = 0#u64) + -- [P] the Stage-2 IPA width, the reset chunk size, the post-reset barriers of a used untyped + (hIpa : S2IpaE ar a) (hchunk : resetChunkBits = 16) + (hPost : fi ≠ 0#u64 → ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + (hpin : DecPinA call Z.th σ slot (.invokeUntyped inv)) : + UtScopeA AR n Z OS ar s a σ lbl length slot blk call don false buf extra + (fun σ' => ∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + (.ok (), σ') ∈ ((Fl4SpecA64.fl4InvokeUntypedA64 (Z := Unit) inv).run + (stUpdA σ σ.curThread xT .restart)).1) + +variable {st} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} -variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +/-- **Every Untyped arm in scope runs (its decode succeeds) and keeps the record.** -/ +theorem UtScopeA.soundOk (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) + s a σ m) + (hfm : A64FrameMasks st s) + {lbl len slot : U64} {blk call don fp : Bool} {buf : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Out : Fl4SpecA64.State Unit → Prop} + (h : UtScopeA st AR n Z OS ar s a σ lbl len slot blk call don fp buf extra Out) : + DispPostOkA st AR ar hPl.ipa n Z.Cs s a m lbl len slot blk call don fp buf extra Out := by + cases h with + | retype slot p sb fi extra lbl length buf blk call don hslot hcov hext hslc sl hsl hsrc vi hvi hvirt hfan slbl hlbl + args hlen hargs exs hex hchild inv hdecS hVP k hKt hK0 hpin => + exact JSyscallA.untypedRetypeA hA hPl J hfm hslot hcov hext hslc sl hsl hsrc vi hvi hvirt hfan lbl slbl hlbl len + buf args hlen hargs exs hex hchild inv hdecS hVP hKt hK0 + | retypeRst slot p sb fi extra lbl length buf blk call don hslot hcov hext hslc sl hsl hsrc vi hvi hvirt hfan slbl hlbl + args hlen hargs exs hex hnochild inv hdecS hVP k hKt hK0 hnN h1 hCs hS hIpa hchunk hPost hpin => + exact JSyscallA.untypedRetypeRstA hA hPl J hfm hslot hcov hext hslc sl hsl hsrc vi hvi hvirt hfan lbl slbl hlbl len + buf args hlen hargs exs hex hnochild inv hdecS hVP hKt hK0 hnN h1 hCs hS hIpa hchunk hPost -/-- The empty group's `sound`. -/ -theorem UtScopeA.sound {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : U64} {n : Nat} {Cs : Set U64} {s : S} {a : A} - {m : Fl4SpecA64.McState} {lbl len slot : U64} {blk call don fp : Bool} {buf : U64} - {extra : Aeneas.Std.Array obj.Slot 3#usize} {Out : Fl4SpecA64.State Unit → Prop} - (h : UtScopeA lbl len slot blk call don fp buf extra Out) : - DispPostA st AR ar nA n Cs s a m lbl len slot blk call don fp buf extra Out := by - cases h +/-- **The Untyped group is sound.** -/ +theorem UtScopeA.sound (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) + s a σ m) + (hfm : A64FrameMasks st s) + {lbl len slot : U64} {blk call don fp : Bool} {buf : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Out : Fl4SpecA64.State Unit → Prop} + (h : UtScopeA st AR n Z OS ar s a σ lbl len slot blk call don fp buf extra Out) : + DispPostA st AR ar hPl.ipa n Z.Cs s a m lbl len slot blk call don fp buf extra Out := + (UtScopeA.soundOk hA hPl J hfm h).post + +/-- **The Untyped group's `InvSpecA`**, from the pinned operation. -/ +theorem UtScopeA.invSpecA + {lbl len slot : U64} {blk call don fp : Bool} {buf : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Out : Fl4SpecA64.State Unit → Prop} {σ' : Fl4SpecA64.State Unit} + (hP : PlaceA Z.th (L.ksb s)) + (h : UtScopeA st AR n Z OS ar s a σ lbl len slot blk call don fp buf extra Out) + (hst : ∀ x, σ.kheap σ.curThread = some (.tcb x) → + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), stUpdA σ σ.curThread x .restart)}, False)) + (hOut : Out σ') {mi : MessageInfo} {sl : CslotPtr} {c : Cap} {excaps : List (Cap × CslotPtr)} + {buffer : Option ObjRef} {args : List Data} (F : FrontPinA Z.th σ slot mi sl c excaps buffer args) + (cptr : CapRef) : + InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + cases h with + | retype slot p sb fi extra lbl length buf blk call don hslot hcov hext hslc sl' hsl hsrc vi hvi hvirt hfan slbl hlbl + args' hlen hargs exs hex hchild inv hdecS hVP k hKt hK0 hpin => + obtain ⟨xT, hk, hperf⟩ := hOut + refine InvSpecA.ofPin hP hpin F cptr (hst xT hk) ?_ + have e : Fl4SpecA64.fl4PerformInvocation (Z := Unit) blk call don (.invokeUntyped inv) = + (do Fl4SpecA64.fl4InvokeUntypedA64 (Z := Unit) inv; Fl4Spec.NonDetE.returnOk ([] : List Data)) := rfl + rw [e] + exact perform_thenNilA hperf + | retypeRst slot p sb fi extra lbl length buf blk call don hslot hcov hext hslc sl' hsl hsrc vi hvi hvirt hfan slbl hlbl + args' hlen hargs exs hex hnochild inv hdecS hVP k hKt hK0 hnN h1 hCs hS hIpa hchunk hPost hpin => + obtain ⟨xT, hk, hperf⟩ := hOut + refine InvSpecA.ofPin hP hpin F cptr (hst xT hk) ?_ + have e : Fl4SpecA64.fl4PerformInvocation (Z := Unit) blk call don (.invokeUntyped inv) = + (do Fl4SpecA64.fl4InvokeUntypedA64 (Z := Unit) inv; Fl4Spec.NonDetE.returnOk ([] : List Data)) := rfl + rw [e] + exact perform_thenNilA hperf + +end end diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispVsA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispVsA.lean index 83e448402..d4cc6cad0 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispVsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispVsA.lean @@ -4,14 +4,18 @@ lifted arm; its premises are the arm's (`JSyscallA.`): the cap of the invok FL4's decode-site results (`hK` / `hT` come from the record: `ksbAligned`, `offAsE`). Generated (WS/handoff/tools/gen_t3disp.py). Pending lift (not in scope): page / VSpace flush, GetAddress, TestAndClearAccessed, the `Err` returns. -Deferred (backlog): PT map into a high window or Stage-2, frame map Stage-2, the T2 unmap shrink, `derive_subframe`. +Deferred (backlog): PT map into a high window or Stage-2, the T2 unmap shrink, `derive_subframe` (the Stage-2 frame map is `frameMapS2`, vsx-A). -/ import Fl4ProofsA64.P3.Stage3OffAsEA import Fl4ProofsA64.P3.Stage3T3ArmsA import Fl4ProofsA64.P3.Stage3T3ArmHiA +import Fl4ProofsA64.P3.Stage3T3ArmS2A +import Fl4ProofsA64.P3.Stage3T3ArmPtHiA +import Fl4ProofsA64.P3.Stage3T3ArmPtS2A import Fl4ProofsA64.P3.Stage3DispBaseA import Fl4ProofsA64.P3.VsArmA import Fl4ProofsA64.P3.Stage3T3DecEqA +import Fl4ProofsA64.P3.Stage3T3ArmT2A open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -425,6 +429,193 @@ inductive VsScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U A (.ok (.extVSpace iv), σ) ∈ D.1 ∧ (([] : List Fl4SpecA64.Data), σ') ∈ (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1) + | frameMapS2 + {x0 : U64} + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + {dc : capability.Cap} + {ex : Aeneas.Std.Array obj.Slot 3#usize} + {s3 : S} + {a3 : A} + {callD : Bool} + {lenD bufD : U64} + {rr : capability.Rights} + {bB bD bF : Bool} + (K : ArchKeepsA ar AR) + (hIpa : S2IpaE ar a) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) + (hEO : ExtTabOffA (L := L) Z m s) + (cte : Fl4SpecA64.CslotPtr) + (hab : AbsSlotA Z.th cte) + (hCn : ∃ pc, cte.1 = specPtr pc ∧ Z.th pc = some (.cnode cte.2.length)) + (fp rt asid va : U64) + (sz : capability.FrameSize) + (dev mp e : Bool) + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .Frame fp sz rt dev mp e asid va) + (FP : FrPlA sz fp mp asid) + (hemp : e = mp) + (p1 asid1 va1 : U64) + (mp1 : Bool) + (h16 : asid1.val < 2 ^ 16) + (hx0 : x0 ∈ OS) + (hx0c : capA st s x0 = .Ept p1 0#u64 mp1 asid1 va1) + (hrt : ept.root st s (.Ept p1 0#u64 mp1 asid1 va1) 1#u64 = ok (core.result.Result.Ok (p1, asid1))) + (vaddr rightsMask vm attr : U64) + (hvmRange : vm = capability.VM_KERNEL_ONLY ∨ vm = capability.VM_READ_ONLY ∨ vm = capability.VM_READ_WRITE) + (hvmEq : vmRightsOfA vm = maskVmRights (vmRightsOfA rt) (dataToRights rightsMask.bv)) + (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageMapAt (Z := Unit) cte (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev + (mapDataA mp asid va) (specPtr p1) (asidOfA asid1) vaddr.bv rightsMask.bv attr.bv)).run σ) + (d : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s dc ex) + (hres : ept.map_frame st ar s a p1 asid1 vaddr vm attr fp sz rt dev asid va (cslotAddrA cte) = + ok (core.result.Result.Ok (), s3, a3)) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (hext : ∀ x ∈ ex.val, x ≠ 0#u64 → x ∈ OS) + (hSC : ∀ x ∈ ex.val, x ≠ 0#u64 → SlotCov st OS s x) + (hx : vspace.extra ex 0#usize = ok (some x0)) + (hlen : lenD ≥ 3#u64) + (h0 : msg.syscall_arg st s (L.curW s) bufD 0#u64 = ok vaddr) + (h1 : msg.syscall_arg st s (L.curW s) bufD 1#u64 = ok rightsMask) + (h2 : msg.syscall_arg st s (L.curW s) bufD 2#u64 = ok attr) + (hr : capability.Rights.from_word rightsMask = ok rr) + (hvm : capability.mask_vm_rights rt rr = ok vm) + (hpin : ∀ iv, (.ok (.extVSpace iv), σ) ∈ D.1 → DecPinA callD Z.th σ (cslotAddrA cte) (.invokeArchObject (.extVSpace iv))) : + VsScopeA AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar nA s a σ m fl4_abi.label.ARMPageMap lenD (cslotAddrA cte) bB callD bD bF bufD ex + (fun σ' => ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ') ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1) + + | ptMapHi + {x0 : U64} + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + {s3 : S} + {ptr asid0 va0 : U64} + {bB bC bD bF : Bool} + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) + (hEO : ExtTabOffA (L := L) Z m s) + (cte : Fl4SpecA64.CslotPtr) + (hab : AbsSlotA Z.th cte) + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr false asid0 va0) + (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) + (hS2 : ptr ∉ S2PgE Z.X Z.T2) + (hY : ptr ∉ Z.Y) + (length buf : U64) + (extra : Aeneas.Std.Array obj.Slot 3#usize) + (hx : vspace.extra extra 0#usize = ok (some x0)) + (hlen : length ≥ 2#u64) + (p1 asid1 : U64) + (mp1 : Bool) + (h16 : asid1.val < 2 ^ 16) + (hx0c : capA st s x0 = .HighVSpace p1 mp1 asid1) + (vaddr : U64) + (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeHighPageTableMap (Z := Unit) cte (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .high (specPtr p1) (asidDataA mp1 asid1)) vaddr.bv)).run σ) + (hres : vspace.map_high_page_table st s (cslotAddrA cte) ptr (.HighVSpace p1 mp1 asid1) vaddr = + ok (core.result.Result.Ok (), s3)) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hpin : ∀ iv, (.ok (.extVSpace iv), σ) ∈ D.1 → DecPinA bC Z.th σ (cslotAddrA cte) (.invokeArchObject (.extVSpace iv))) : + VsScopeA AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar nA s a σ m fl4_abi.label.ARMPageTableMap length (cslotAddrA cte) bB bC bD bF buf extra + (fun σ' => ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ') ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1) + + + | ptMapS2 + {x0 : U64} + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + {s3 : S} + {a3 : A} + {ptr asid0 va0 : U64} + {bB bC bD bF : Bool} + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) + (hEO : ExtTabOffA (L := L) Z m s) + (hIpa : S2IpaE ar a) + (hIpa47 : s2IpaLimit.toNat < 2 ^ 47) + (cte : Fl4SpecA64.CslotPtr) + (hab : AbsSlotA Z.th cte) + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr false asid0 va0) + (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) + (hS2 : ptr ∉ S2PgE Z.X Z.T2) + (hY : ptr ∉ Z.Y) + (length buf : U64) + (extra : Aeneas.Std.Array obj.Slot 3#usize) + (hx : vspace.extra extra 0#usize = ok (some x0)) + (hlen : length ≥ 2#u64) + (vp vasid vva : U64) + (ha16 : vasid.val < 65536) + (hx0c : capA st s x0 = .Ept vp 0#u64 true vasid vva) + (vaddr : U64) + (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageTableMap (Z := Unit) cte (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .stage2 (specPtr vp) (asidDataA true vasid)) vaddr.bv)).run σ) + (hrt : ept.root st s (.Ept vp 0#u64 true vasid vva) 1#u64 = ok (core.result.Result.Ok (vp, vasid))) + (hres : ept.map_table st ar s a vp vasid vaddr ptr (cslotAddrA cte) = ok (core.result.Result.Ok (), s3, a3)) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hpin : ∀ iv, (.ok (.extVSpace iv), σ) ∈ D.1 → DecPinA bC Z.th σ (cslotAddrA cte) (.invokeArchObject (.extVSpace iv))) : + VsScopeA AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar nA s a σ m fl4_abi.label.ARMPageTableMap length (cslotAddrA cte) bB bC bD bF buf extra + (fun σ' => ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ') ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1) + + + | ptUnmapT2 + {bB bC bD bF : Bool} + (K : ArchKeepsA ar AR) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) + (hEO : ExtTabOffA (L := L) Z m s) + (hIpa : S2IpaE ar a) + (length buf : U64) + (ex : Aeneas.Std.Array obj.Slot 3#usize) + (cte : Fl4SpecA64.CslotPtr) + (hab : AbsSlotA Z.th cte) + (ptr asid va : U64) + (hpT : ptr ∈ Z.T2) + (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) + (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (k : Fl4SpecA64.ExtRootKind) + (hkR : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some k) + (hkR1 : k ≠ .stage1) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) + -- [J] the unmapped table is named by no reachable valid descriptor that the unmap does not clear + (hUniq : ∀ (s2 : S) (a2 : A), + vspace.unmap_page_table st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a asid va ptr = ok (s2, a2) → + ∀ w, S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART)) σ w → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 0 = true → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 1 = true → + dTabA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) = ptr → L.mem s2 w = 0#u64) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (hext : ∀ x ∈ ex.val, x ≠ 0#u64 → x ∈ OS) + (hSC : ∀ x ∈ ex.val, x ≠ 0#u64 → SlotCov st OS s x) + (hpin : DecPinA bC Z.th σ (cslotAddrA cte) (.invokeArchObject (.extVSpace (.tableUnmap k (.pageTableCap (specPtr ptr) .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte)))) : + VsScopeA AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar nA s a σ m fl4_abi.label.ARMPageTableUnmap length (cslotAddrA cte) bB bC bD bF buf ex + (fun σ' => ∃ (x : Fl4SpecA64.Tcb), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (([] : List Fl4SpecA64.Data), σ') ∈ (Fl4SpecA64.performExtVSpace (Z := Unit) (.tableUnmap k (.pageTableCap + (specPtr ptr) .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte) (stUpdA σ σ.curThread x .restart)).1) variable {st} @@ -504,6 +695,34 @@ theorem VsScopeA.soundOk {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} { decInv_frameA ar s a _ lenD _ fp sz rt dev mp false asid va bB callD bD bF bufD ex, decFrame_hiA hx hlen h0 h1 h2 hr hvm (by rw [capA_eq, hx0c])] exact hres + | @ptMapHi x0 D s3 ptr asid0 va0 bB bC bD bF hnvm hTO hEO cte hab hcap UP hS2 hY length buf extra hx hlen p1 asid1 mp1 h16 hx0c vaddr h0 hD hres hcov hext hSC hpin => + obtain ⟨x, iv, σ3, Ac', Tb', Lv', nL, hc0, hc1, hc2, hc3, J3, K3⟩ := JSyscallA.ptMapHiA (J := J) (hA := hA) (hM := hM) (hPl := hPl) (hfm := hfm) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (cte := cte) (hab := hab) (hcap := hcap) (UP := UP) (hS2 := hS2) (hY := hY) (length := length) (buf := buf) (extra := extra) (x0 := x0) (hx := hx) (hlen := hlen) (p1 := p1) (asid1 := asid1) (mp1 := mp1) (h16 := h16) (hx0c := hx0c) (vaddr := vaddr) (h0 := h0) (hD := hD) (hres := hres) (hcov := hcov) (hext := hext) (hSC := hSC) + refine ⟨s3, a, σ3, ?_, ⟨x, iv, hc0, hc1, hc2, hc3⟩, curW_keptA J.toJStage3A J3 K3.cur, A64RelS3.ofJ J3 (Sched.BodyOKA.ofKeep J hc0 K3)⟩ + rw [show capA st s (cslotAddrA cte) = (.PageTable ptr false asid0 va0) from (capAtA_eq (st := st) _ _).symm.trans hcap] + refine (decInv_ptA ar s a _ length _ ptr false asid0 va0 bB bC bD bF buf extra).trans ?_ + rw [decPt_hiA hx hlen h0 (by rw [capA_eq, hx0c]), hres] + first | (simp only [bind_ok]; done) | (simp only [bind_ok]; rfl) | simp [bind_ok] + + | @ptMapS2 x0 D s3 a3 ptr asid0 va0 bB bC bD bF hnvm hTO hEO hIpa hIpa47 cte hab hcap UP hS2 hY length buf extra hx hlen vp vasid vva ha16 hx0c vaddr h0 hD hrt hres hcov hext hSC hpin => + obtain ⟨x, iv, σ3, Ac', Tb', Lv', nS, hc0, hc1, hc2, hc3, J3, K3⟩ := JSyscallA.ptMapS2A (J := J) (hA := hA) (hM := hM) (hPl := hPl) (hfm := hfm) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (hIpa := hIpa) (hIpa47 := hIpa47) (cte := cte) (hab := hab) (hcap := hcap) (UP := UP) (hS2 := hS2) (hY := hY) (length := length) (buf := buf) (extra := extra) (x0 := x0) (hx := hx) (hlen := hlen) (vp := vp) (vasid := vasid) (vva := vva) (ha16 := ha16) (hx0c := hx0c) (vaddr := vaddr) (h0 := h0) (hD := hD) (hrt := hrt) (hres := hres) (hcov := hcov) (hext := hext) (hSC := hSC) + refine ⟨s3, a3, σ3, ?_, ⟨x, iv, hc0, hc1, hc2, hc3⟩, curW_keptA J.toJStage3A J3 K3.cur, A64RelS3.ofJ J3 (Sched.BodyOKA.ofKeep J hc0 K3)⟩ + rw [show capA st s (cslotAddrA cte) = (.PageTable ptr false asid0 va0) from (capAtA_eq (st := st) _ _).symm.trans hcap] + refine (decInv_ptA ar s a _ length _ ptr false asid0 va0 bB bC bD bF buf extra).trans ?_ + rw [decPt_s2A hx hlen h0 (by rw [capA_eq, hx0c]) hrt, hres] + + | @frameMapS2 x0 D dc ex s3 a3 callD lenD bufD rr bB bD bF K hIpa hnvm hTO hEO cte hab hCn fp rt asid va sz dev mp e hcap FP hemp p1 asid1 va1 mp1 h16 hx0 hx0c hrt vaddr rightsMask vm attr hvmRange hvmEq hD d hres hcov hext hSC hx hlen h0 h1 h2 hr hvm hpin => + obtain ⟨x, iv, σ3, Ac', hc0, hc1, hc2, hc3, J3, K3⟩ := JSyscallA.frameMapS2A (J := J) (callD := callD) (hA := hA) (hM := hM) (hPl := hPl) (hIpa := hIpa) (hfm := hfm) (hK := J.toJStage3A.ksbAligned) (hT := J.toJStage3A.offAsE) (K := K) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (cte := cte) (hab := hab) (hCn := hCn) (fp := fp) (rt := rt) (asid := asid) (va := va) (sz := sz) (dev := dev) (mp := mp) (e := e) (hcap := hcap) (FP := FP) (hemp := hemp) (p1 := p1) (asid1 := asid1) (va1 := va1) (mp1 := mp1) (h16 := h16) (hx0 := hx0) (hx0c := hx0c) (hrt := hrt) (vaddr := vaddr) (rightsMask := rightsMask) (vm := vm) (attr := attr) (hvmRange := hvmRange) (hvmEq := hvmEq) (hD := hD) (d := d) (hres := hres) (hcov := hcov) (hext := hext) (hSC := hSC) (hx := hx) (hlen := hlen) (h0 := h0) (h1 := h1) (h2 := h2) (hr := hr) (hvm := hvm) + refine ⟨s3, a3, σ3, ?_, ⟨x, iv, hc0, hc1, hc2, hc3⟩, curW_keptA J.toJStage3A J3 K3.cur, A64RelS3.ofJ J3 (Sched.BodyOKA.ofKeep J hc0 K3)⟩ + rw [show capA st s (cslotAddrA cte) = (.Frame fp sz rt dev mp e asid va) from (capAtA_eq (st := st) _ _).symm.trans hcap, + decInv_frameA ar s a _ lenD _ fp sz rt dev mp e asid va bB callD bD bF bufD ex, + decFrame_s2A hx hlen h0 h1 h2 hr hvm (by rw [capA_eq, hx0c]) hrt (fun hz => hemp.trans (FP.mz.2 hz))] + exact hres + + | @ptUnmapT2 bB bC bD bF K hnvm hTO hEO hIpa length buf ex cte hab ptr asid va hpT hcap hf k hkR hkR1 hno hUniq hcov hext hSC hpin => + obtain ⟨x, s3, a', σ3, Ac', hc0, hc1, hdec1, hc3, J3, K3⟩ := JSyscallA.ptUnmapT2A (J := J) (hA := hA) (hM := hM) (hPl := hPl) (hfm := hfm) (hK := J.toJStage3A.ksbAligned) (hT := J.toJStage3A.offAsE) (K := K) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (hIpa := hIpa) (length := length) (buf := buf) (ex := ex) (cte := cte) (hab := hab) (ptr := ptr) (asid := asid) (va := va) (hpT := hpT) (hcap := hcap) (hf := hf) (k := k) (hkR := hkR) (hkR1 := hkR1) (hno := hno) (hUniq := hUniq) (hcov := hcov) (hext := hext) (hSC := hSC) + refine ⟨s3, a', σ3, ?_, ⟨x, hc0, hc1, hc3⟩, curW_keptA J.toJStage3A J3 K3.cur, A64RelS3.ofJ J3 (Sched.BodyOKA.ofKeep J hc0 K3)⟩ + rw [show capA st s (cslotAddrA cte) = (.PageTable ptr true asid va) from hcap] + exact (decInv_ptA ar s a _ length _ ptr true asid va bB bC bD bF buf ex).trans hdec1 /-- **Every Vs arm in scope runs and keeps the record.** -/ theorem VsScopeA.sound {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} diff --git a/proofs/Fl4ProofsA64/P3/Stage3DomSchedA.lean b/proofs/Fl4ProofsA64/P3/Stage3DomSchedA.lean new file mode 100644 index 000000000..25cc3b0b4 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3DomSchedA.lean @@ -0,0 +1,749 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbdom): **`DomainScheduleConfigure` and `DomainScheduleSetStart` at record level.** + +Both arms rewrite spec domain-schedule fields (`domainList`, `domainStartIndex`, `domainIndex`, `domainTime`), so +`QKeepA` (with its `dom : DomKeepA` field) is false across them. The step is taken over `QKeepN` +(`JStage3A.of_schedWrD`), with `NdOKA` re-proved at the new state: + +* `JStage3A.of_domStepA`: the record across a step that keeps the spec heap and may move the domain-schedule fields + (`MFrDA` frame; the caller gives the scheduler relation, the spec invariants and `NdOKA` at the new state). +* `NdOKA.configureA`, `NdOKA.setStartA`: `NdOKA` after the table-entry write and after the start / position writes. +* `YieldQueueRelA.domSpecA`: the scheduler relations do not read `domainList` / `domainStartIndex`. +* `JSyscallA.domConfigureA`, `JSyscallA.domSetStartA`: `decode_invocation` of the two labels on the Domain cap at a + syscall entry (the caller's `Restart`, then the schedule words, then `of_domStepA`). + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks` (through `decodeFinA`). Only the accepted decodes +are lifted. New module. +-/ +import Fl4ProofsA64.P3.Stage3LiftDomainA +import Fl4ProofsA64.P3.Stage3LiftBodyA +import Fl4ProofsA64.P3.Stage3KEntrySchedA +import Fl4ProofsA64.P3.DelNtfnRecA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3 Fl4ProofsA64.P3.Endp + Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4SpecA64 Fl4Spec + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +/-! ## Kernel-state words -/ + +/-- A write of the kernel-state word at offset `o`. -/ +abbrev domWrA (s : S) (o v : U64) : S := L.wr s (wa (L.ksb s) o) v + +theorem domKsOffA {k o : U64} (fit : k.val + ksSizeA ≤ 2 ^ 64) (h : o.val < 224) : + (wa k o).val = k.val + o.val := by + unfold ksSizeA at fit + rw [wa_valm] + omega + +theorem domWrA_ksb (s : S) (o v : U64) : L.ksb (domWrA (st := st) s o v) = L.ksb s := L.ksb_wr _ _ _ + +theorem domWrA_cpu (s : S) (o v : U64) : L.cpu (domWrA (st := st) s o v) = L.cpu s := L.cpu_wr _ _ _ + +/-- A kernel-state word after a write of another (or the same) kernel-state word. -/ +theorem domWrA_mem {s : S} (fit : (L.ksb s).val + ksSizeA ≤ 2 ^ 64) (al : (L.ksb s).val % 8 = 0) {o v p : U64} + (ho : o.val < 224) (ho8 : o.val % 8 = 0) (hp : p.val < 224) (hp8 : p.val % 8 = 0) : + L.mem (domWrA (st := st) s o v) (wa (L.ksb (domWrA (st := st) s o v)) p) = + if o = p then v else L.mem s (wa (L.ksb s) p) := by + rw [domWrA_ksb] + have vo := domKsOffA fit ho + have vp := domKsOffA fit hp + have ao : Aligned (wa (L.ksb s) o) := by unfold Aligned; rw [vo]; omega + have ap : Aligned (wa (L.ksb s) p) := by unfold Aligned; rw [vp]; omega + by_cases e : o = p + · subst p + rw [if_pos rfl] + exact L.mem_wr_same ao + · rw [if_neg e] + exact L.mem_wr_ne ao ap (by rw [vo, vp]; intro h; exact e (UScalar.eq_of_val_eq (by omega))) + +/-- The four table words read by `dom_sched_duration` / `dom_sched_domain` (the two entries of the table). -/ +theorem domReadWordsA (x : S) : + sched.dom_sched_duration st x 0#u64 = ok (L.mem x (wa (L.ksb x) 200#u64)) ∧ + sched.dom_sched_domain st x 0#u64 = ok (L.mem x (wa (L.ksb x) 192#u64)) ∧ + sched.dom_sched_duration st x 1#u64 = ok (L.mem x (wa (L.ksb x) 216#u64)) ∧ + sched.dom_sched_domain st x 1#u64 = ok (L.mem x (wa (L.ksb x) 208#u64)) := by + have table : layout.ks.DOM_SCHEDULE = ok 192#u64 := by + unfold layout.ks.DOM_SCHEDULE layout.WORD + rfl + have get (off : U64) : obj.ks_get st x off = ok (L.mem x (wa (L.ksb x) off)) := + eq_of_spec_fd (obj.ks_get.spec x off) + have o00 : wa 192#u64 (core.num.U64.wrapping_mul 0#u64 16#u64) = 192#u64 := by decide + have o01 : wa (192#u64 : U64) 8#u64 = 200#u64 := by decide + have o10 : wa 192#u64 (core.num.U64.wrapping_mul 1#u64 16#u64) = 208#u64 := by decide + have o11 : wa (208#u64 : U64) 8#u64 = 216#u64 := by decide + refine ⟨?_, ?_, ?_, ?_⟩ <;> + simp only [sched.dom_sched_duration, sched.dom_sched_domain, table, lift, bind_ok, get, o00, o01, o10, o11] + +/-- The next-domain prefix writes leave the table words alone. -/ +theorem domPrefixKeepA {x : S} (fit : (L.ksb x).val + ksSizeA ≤ 2 ^ 64) (al : (L.ksb x).val % 8 = 0) + (cpu : (L.cpu x).val < 128) (j : U64) {p : U64} (lo : 192 ≤ p.val) (hi : p.val < 224) (p8 : p.val % 8 = 0) : + L.mem (nextDomainPrefixA (st := st) x j) (wa (L.ksb (nextDomainPrefixA (st := st) x j)) p) = + L.mem x (wa (L.ksb x) p) := by + have kb : L.ksb (nextDomainPrefixA (st := st) x j) = L.ksb x := by + show L.ksb (L.wr _ _ _) = L.ksb x + rw [L.ksb_wr] + show L.ksb (L.wr _ _ _) = L.ksb x + rw [L.ksb_wr] + exact L.ksb_wr _ _ _ + rw [kb] + have vp := domKsOffA fit hi + generalize hb : wa (L.ksb x) p = b at vp ⊢ + have ba : b.val % 8 = 0 := by rw [vp]; omega + have blo : (L.ksb x).val + 192 ≤ b.val := by omega + have bhi : b.val < (L.ksb x).val + 224 := by omega + have v24 := domKsOffA (o := layout.ks.DOM_SCHED_IDX) fit (by simp [layout.ks.DOM_SCHED_IDX]) + have v40 := domKsOffA (o := layout.ks.WORK_UNITS) fit (by simp [layout.ks.WORK_UNITS]) + have e24 : (layout.ks.DOM_SCHED_IDX).val = 24 := by simp [layout.ks.DOM_SCHED_IDX] + have e40 : (layout.ks.WORK_UNITS).val = 40 := by simp [layout.ks.WORK_UNITS] + have vn := nodeAt_valSc (s := x) (c := L.cpu x) (o := layout.node.REPROGRAM) fit cpu + (by simp [layout.node.REPROGRAM]) + have er : (layout.node.REPROGRAM).val = 56 := by simp [layout.node.REPROGRAM] + have unf : nextDomainPrefixA (st := st) x j = + L.wr (L.wr (L.wr x (wa (L.ksb x) layout.ks.DOM_SCHED_IDX) j) + (L.nodeA (L.wr x (wa (L.ksb x) layout.ks.DOM_SCHED_IDX) j) layout.node.REPROGRAM) 1#u64) + (wa (L.ksb (L.wr (L.wr x (wa (L.ksb x) layout.ks.DOM_SCHED_IDX) j) + (L.nodeA (L.wr x (wa (L.ksb x) layout.ks.DOM_SCHED_IDX) j) layout.node.REPROGRAM) 1#u64)) + layout.ks.WORK_UNITS) 0#u64 := rfl + rw [unf] + simp only [LawfulStore.nodeA, L.cpu_wr, L.ksb_wr, nodeAt_of_ksb (L.ksb_wr _ _ _)] + rw [L.mem_wr_ne, L.mem_wr_ne, L.mem_wr_ne] + all_goals first + | (unfold Aligned; omega) + | omega + +/-! ## `NdOKA` after the schedule writes -/ + +private theorem domTwoA : (layout.NUM_DOMAIN_SCHEDULES).val = 2 := by + simp [layout.NUM_DOMAIN_SCHEDULES, fl4_abi.config.NUM_DOMAIN_SCHEDULES] + +private theorem domIdxCasesA {i : U64} (hi : i < layout.NUM_DOMAIN_SCHEDULES) : i = 0#u64 ∨ i = 1#u64 := by + have h2 := domTwoA + have : i.val = 0 ∨ i.val = 1 := by + have : i.val < layout.NUM_DOMAIN_SCHEDULES.val := hi + omega + rcases this with e | e + · exact Or.inl (UScalar.eq_of_val_eq (by simp [e])) + · exact Or.inr (UScalar.eq_of_val_eq (by simp [e])) + +/-- `NdOKA` after `set_dom_sched` of entry 0 to the (zero) domain and a duration of at most `maxDomainDuration`. -/ +theorem Sched.NdOKA.configureA {s : S} {σ : State Unit} (H : NdOKA (st := st) s σ) + (fit : (L.ksb s).val + ksSizeA ≤ 2 ^ 64) (al : (L.ksb s).val % 8 = 0) (cpu : (L.cpu s).val < 128) + {dur : U64} (hmax : dur.val < 2 ^ 56) : + NdOKA (st := st) (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur) + { σ with domainList := σ.domainList.set 0 (0, ucast domainDurationLen dur.bv) } := by + have fit1 : (L.ksb (domWrA (st := st) s 192#u64 0#u64)).val + ksSizeA ≤ 2 ^ 64 := by rw [domWrA_ksb]; exact fit + have al1 : (L.ksb (domWrA (st := st) s 192#u64 0#u64)).val % 8 = 0 := by rw [domWrA_ksb]; exact al + have word (p : U64) (hp : p.val < 224) (hp8 : p.val % 8 = 0) : + L.mem (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur) + (wa (L.ksb (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur)) p) = + if 200#u64 = p then dur else if 192#u64 = p then 0#u64 else L.mem s (wa (L.ksb s) p) := by + rw [domWrA_mem fit1 al1 (by decide) (by decide) hp hp8, + domWrA_mem fit al (by decide) (by decide) hp hp8] + have other (p : U64) (hp : p.val < 224) (hp8 : p.val % 8 = 0) (n1 : 192#u64 ≠ p) (n2 : 200#u64 ≠ p) : + L.mem (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur) + (wa (L.ksb (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur)) p) = + L.mem s (wa (L.ksb s) p) := by + rw [word p hp hp8, if_neg n2, if_neg n1] + have kb : L.ksb (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur) = L.ksb s := by + simp only [domWrA_ksb] + have cp : L.cpu (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur) = L.cpu s := by + simp only [domWrA_cpu] + have fit2 : (L.ksb (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur)).val + ksSizeA ≤ + 2 ^ 64 := by rw [kb]; exact fit + have al2 : (L.ksb (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur)).val % 8 = 0 := by + rw [kb]; exact al + have cpu2 : (L.cpu (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur)).val < 128 := by + rw [cp]; exact cpu + have a24 : layout.ks.DOM_SCHED_IDX = 24#u64 := by unfold layout.ks.DOM_SCHED_IDX; rfl + have a32 : layout.ks.DOM_SCHED_START = 32#u64 := by unfold layout.ks.DOM_SCHED_START; rfl + have idx : domIndexWordA (st := st) (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur) = + domIndexWordA (st := st) s := by + unfold domIndexWordA; rw [a24]; exact other _ (by decide) (by decide) (by decide) (by decide) + have start : domStartWordA (st := st) (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur) = + domStartWordA (st := st) s := by + unfold domStartWordA; rw [a32]; exact other _ (by decide) (by decide) (by decide) (by decide) + have len2 : σ.domainList.length = 2 := H.len.trans domTwoA + have bv0 : (0#u64 : U64).bv = ucast 64 (0 : Domain) := by decide + have bvd : dur.bv = ucast 64 (ucast domainDurationLen dur.bv) := by + have hl : domainDurationLen = 56 := rfl + apply BitVec.eq_of_toNat_eq + show dur.val = ((dur.bv.setWidth domainDurationLen).setWidth 64).toNat + rw [BitVec.toNat_setWidth, BitVec.toNat_setWidth, hl] + have e : dur.bv.toNat = dur.val := rfl + rw [e, Nat.mod_eq_of_lt hmax, Nat.mod_eq_of_lt (by omega)] + refine + { index := by rw [idx]; exact H.index + start := by rw [start]; exact H.start + table := fun i hi => ?_ + startBound := by rw [start]; exact H.startBound + dom := domain_list_set_zeroA H.dom 0 _ + len := by + show (σ.domainList.set 0 _).length = _ + rw [List.length_set]; exact H.len + nodes := by rw [other 0#u64 (by decide) (by decide) (by decide) (by decide)]; exact H.nodes + kroot := by + rw [krA_eq48A, other 48#u64 (by decide) (by decide) (by decide) (by decide), ← krA_eq48A] + exact H.kroot } + have R := domReadWordsA (st := st) + (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur) + have P (j : U64) := domReadWordsA (st := st) (nextDomainPrefixA (st := st) + (domWrA (st := st) (domWrA (st := st) s 192#u64 0#u64) 200#u64 dur) j) + have K (j p : U64) (lo : 192 ≤ p.val) (h : p.val < 224) (p8 : p.val % 8 = 0) := + domPrefixKeepA (st := st) fit2 al2 cpu2 j lo h p8 + rcases domIdxCasesA hi with rfl | rfl + · have w192 := word 192#u64 (by decide) (by decide) + have w200 := word 200#u64 (by decide) (by decide) + rw [if_neg (by decide), if_pos rfl] at w192 + rw [if_pos rfl] at w200 + refine ⟨(0, ucast domainDurationLen dur.bv), 0#u64, dur, ?_, bv0, bvd, ?_, ?_, ?_⟩ + · show (σ.domainList.set 0 _)[0]? = _ + rw [List.getElem?_set_self (by omega)] + · rw [R.1, w200] + · rw [(P _).2.1, K _ 192#u64 (by decide) (by decide) (by decide), w192] + · rw [(P _).1, K _ 200#u64 (by decide) (by decide) (by decide), w200] + · obtain ⟨p, d, w, hp, hd, hw, r1, r2, r3⟩ := H.table 1#u64 hi + have w208 := other 208#u64 (by decide) (by decide) (by decide) (by decide) + have w216 := other 216#u64 (by decide) (by decide) (by decide) (by decide) + have O := domReadWordsA (st := st) s + have Q := domReadWordsA (st := st) (nextDomainPrefixA (st := st) s 1#u64) + refine ⟨p, d, w, ?_, hd, hw, ?_, ?_, ?_⟩ + · show (σ.domainList.set 0 _)[1]? = _ + rw [List.getElem?_set_ne (by omega)] + exact hp + · rw [R.2.2.1, w216, ← O.2.2.1]; exact r1 + · rw [(P _).2.2.2, K _ 208#u64 (by decide) (by decide) (by decide), w208, + ← domPrefixKeepA (st := st) fit al cpu 1#u64 (p := 208#u64) (by decide) (by decide) (by decide), ← Q.2.2.2] + exact r2 + · rw [(P _).2.2.1, K _ 216#u64 (by decide) (by decide) (by decide), w216, + ← domPrefixKeepA (st := st) fit al cpu 1#u64 (p := 216#u64) (by decide) (by decide) (by decide), ← Q.2.2.1] + exact r3 + +/-- `NdOKA` after the three `DomainScheduleSetStart` writes: the start word is `idx`, `DOMAIN_TIME` and the position +are 0; the table is as before. -/ +theorem Sched.NdOKA.setStartA {s : S} {σ : State Unit} (H : NdOKA (st := st) s σ) + (fit : (L.ksb s).val + ksSizeA ≤ 2 ^ 64) (al : (L.ksb s).val % 8 = 0) (cpu : (L.cpu s).val < 128) + {idx : U64} (hidx : idx < layout.NUM_DOMAIN_SCHEDULES) : + NdOKA (st := st) (domWrA (st := st) (domWrA (st := st) (domWrA (st := st) s 32#u64 idx) 16#u64 0#u64) 24#u64 0#u64) + { σ with domainStartIndex := idx.val, domainTime := 0, domainIndex := 0 } := by + have fit1 : (L.ksb (domWrA (st := st) s 32#u64 idx)).val + ksSizeA ≤ 2 ^ 64 := by rw [domWrA_ksb]; exact fit + have al1 : (L.ksb (domWrA (st := st) s 32#u64 idx)).val % 8 = 0 := by rw [domWrA_ksb]; exact al + have fit2 : (L.ksb (domWrA (st := st) (domWrA (st := st) s 32#u64 idx) 16#u64 0#u64)).val + ksSizeA ≤ 2 ^ 64 := by + rw [domWrA_ksb]; exact fit1 + have al2 : (L.ksb (domWrA (st := st) (domWrA (st := st) s 32#u64 idx) 16#u64 0#u64)).val % 8 = 0 := by + rw [domWrA_ksb]; exact al1 + generalize hs3 : domWrA (st := st) (domWrA (st := st) (domWrA (st := st) s 32#u64 idx) 16#u64 0#u64) 24#u64 0#u64 = + s3 + have word (p : U64) (hp : p.val < 224) (hp8 : p.val % 8 = 0) : + L.mem s3 (wa (L.ksb s3) p) = + if 24#u64 = p then 0#u64 else if 16#u64 = p then 0#u64 else if 32#u64 = p then idx + else L.mem s (wa (L.ksb s) p) := by + rw [← hs3, domWrA_mem fit2 al2 (by decide) (by decide) hp hp8, + domWrA_mem fit1 al1 (by decide) (by decide) hp hp8, domWrA_mem fit al (by decide) (by decide) hp hp8] + have other (p : U64) (hp : p.val < 224) (hp8 : p.val % 8 = 0) (n1 : 32#u64 ≠ p) (n2 : 16#u64 ≠ p) + (n3 : 24#u64 ≠ p) : L.mem s3 (wa (L.ksb s3) p) = L.mem s (wa (L.ksb s) p) := by + rw [word p hp hp8, if_neg n3, if_neg n2, if_neg n1] + have kb : L.ksb s3 = L.ksb s := by rw [← hs3]; simp only [domWrA_ksb] + have cp : L.cpu s3 = L.cpu s := by rw [← hs3]; simp only [domWrA_cpu] + have fit3 : (L.ksb s3).val + ksSizeA ≤ 2 ^ 64 := by rw [kb]; exact fit + have al3 : (L.ksb s3).val % 8 = 0 := by rw [kb]; exact al + have cpu3 : (L.cpu s3).val < 128 := by rw [cp]; exact cpu + have a24 : layout.ks.DOM_SCHED_IDX = 24#u64 := by unfold layout.ks.DOM_SCHED_IDX; rfl + have a32 : layout.ks.DOM_SCHED_START = 32#u64 := by unfold layout.ks.DOM_SCHED_START; rfl + have idxW : domIndexWordA (st := st) s3 = 0#u64 := by + unfold domIndexWordA; rw [a24, word _ (by decide) (by decide), if_pos rfl] + have start : domStartWordA (st := st) s3 = idx := by + unfold domStartWordA + rw [a32, word _ (by decide) (by decide), if_neg (by decide), if_neg (by decide), if_pos rfl] + refine + { index := by rw [idxW]; rfl + start := by rw [start] + table := fun i hi => ?_ + startBound := by rw [start]; exact hidx + dom := H.dom + len := H.len + nodes := by rw [other 0#u64 (by decide) (by decide) (by decide) (by decide) (by decide)]; exact H.nodes + kroot := by + rw [krA_eq48A, other 48#u64 (by decide) (by decide) (by decide) (by decide) (by decide), ← krA_eq48A] + exact H.kroot } + obtain ⟨p, d, w, hp, hd, hw, r1, r2, r3⟩ := H.table i hi + have R := domReadWordsA (st := st) s3 + have O := domReadWordsA (st := st) s + have P := domReadWordsA (st := st) (nextDomainPrefixA (st := st) s3 i) + have Q := domReadWordsA (st := st) (nextDomainPrefixA (st := st) s i) + have same (q : U64) (lo : 192 ≤ q.val) (h : q.val < 224) (q8 : q.val % 8 = 0) : + L.mem s3 (wa (L.ksb s3) q) = L.mem s (wa (L.ksb s) q) := + other q h q8 (fun e => by subst e; simp at lo) (fun e => by subst e; simp at lo) + (fun e => by subst e; simp at lo) + have pre (q : U64) (lo : 192 ≤ q.val) (h : q.val < 224) (q8 : q.val % 8 = 0) : + L.mem (nextDomainPrefixA (st := st) s3 i) (wa (L.ksb (nextDomainPrefixA (st := st) s3 i)) q) = + L.mem (nextDomainPrefixA (st := st) s i) (wa (L.ksb (nextDomainPrefixA (st := st) s i)) q) := by + rw [domPrefixKeepA fit3 al3 cpu3 i lo h q8, domPrefixKeepA fit al cpu i lo h q8, same q lo h q8] + refine ⟨p, d, w, hp, hd, hw, ?_, ?_, ?_⟩ + all_goals rcases domIdxCasesA hi with rfl | rfl + · rw [R.1, same _ (by decide) (by decide) (by decide), ← O.1]; exact r1 + · rw [R.2.2.1, same _ (by decide) (by decide) (by decide), ← O.2.2.1]; exact r1 + · rw [P.2.1, pre _ (by decide) (by decide) (by decide), ← Q.2.1]; exact r2 + · rw [P.2.2.2, pre _ (by decide) (by decide) (by decide), ← Q.2.2.2]; exact r2 + · rw [P.1, pre _ (by decide) (by decide) (by decide), ← Q.1]; exact r3 + · rw [P.2.2.1, pre _ (by decide) (by decide) (by decide), ← Q.2.2.1]; exact r3 + +/-! ## The scheduler relations and the spec invariants across the schedule fields -/ + +/-- The scheduler relations read neither `domainList` nor `domainStartIndex`. -/ +theorem Sched.YieldQueueRelA.domSpecA {Z : XSetsA} {m : McState} {κ : U64 → U64} {s : S} {σ : State Unit} + (E : YieldQueueRelA (st := st) Z m κ s σ) (l : List (Domain × DomainDuration)) (start : Nat) : + YieldQueueRelA (st := st) Z m κ s { σ with domainList := l, domainStartIndex := start } := by + have R := E.sched.stableR (σ' := { σ with domainList := l, domainStartIndex := start }) (W := fun _ => False) + (WritesIn.refl _ _) (fun _ h => h.elim) + ⟨{ SFixA.refl σ with }, rfl, rfl, rfl, fun _ _ _ _ => rfl, fun _ x h => ⟨x, h, rfl, rfl, rfl⟩, + fun _ _ _ _ => rfl, fun _ x h => ⟨x, h⟩, fun _ x h => ⟨x, h, rfl⟩⟩ E.sched.run E.sched.rd + exact ⟨R, E.states, E.mcp, { E.links with }⟩ + +/-! ## The record across a domain-schedule step -/ + +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {s s' : S} {a : A} {σ σ' : State Unit} {m : McState} + {ar : machine.Arch A} + +set_option maxHeartbeats 2000000 in +/-- **The record across a step that may move the domain-schedule fields** (module docstring): the spec heap is kept, +the write set is the scheduler words and `DomW`, and `NdOKA` is given at the new state. -/ +theorem JStage3A.of_domStepA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {Q : U64 → U64 → List U64} + (FD : MFrDA (st := st) Z m s s' σ σ') (hk : σ'.kheap = σ.kheap) (HS : SpecSchedA σ σ') + (hum : σ'.machineState.underlyingMemory = σ.machineState.underlyingMemory) + (hidle : σ'.idleThread = σ.idleThread) (htime : σ.curTime ≤ σ'.curTime) + (blk : BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s') + (sysl : SysL st H Z.Cs OS ia ie s') (symL : SymL st H Z.Cs s') + (userOK : Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s') + (Y : YieldQueueRelA (st := st) { Z with Q := Q } m κ s' σ') + (sinv : SInvXA σ' m n) (schedValid : SchedValidA σ') (hdom : NdOKA (st := st) s' σ') : + JStage3A st AR { Z with Q := Q } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s' a σ' m := by + have w : WritesIn st s s' (fun b => SchedStepWA (st := st) Z m σ s b ∨ DomW (L.ksb s) b) := + FD.wr.mono fun _ h => h.elim (fun h => Or.inl (schedStepW_mwr h)) Or.inr + have N1 := J.sr.toSchedSRN + have kb : L.ksb s' = L.ksb s := FD.wr.1 + have SSz : SSzA σ σ' := SSzA.of_kheap hk + have tw : ∀ t ∈ Z.T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → + (K.val ≠ 3464 ∧ K.val ≠ 3480 ∧ K.val ≠ 3488 ∧ K.val ≠ 3592) → L.mem s' (wa t K) = L.mem s (wa t K) := + fun t ht K h1 h2 h3 => FD.wr.mem_eq (field_aligned (N1.core.tcbs t ht) h1 h2) + (fun h => h.elim (tcbK_offMWrA N1 ht h1 h3) (tcbK_domSA N1 ht h1)) + have sq : SchedQueuesInv st H.tcbs Z.Cs H.omega H s' Q Z.R := by + obtain ⟨Q0, R0, h⟩ := blk.1 + exact SchedQueuesInv.reQA h (by rw [J.tcbs]; exact Y.sched.core) + have poolOff : PoolOff st H Z.Cs OS s' := fun i => by + have h0 := J.poolOff i + rw [vspace.asid_table.eq] at h0 ⊢ + have v := AtOff.v i + have hks : (L.ksb s).val + 788736 ≤ 2 ^ 64 := J.sys.ent.ksw + have ev : (wa (L.ksb s) (AtOff i)).val = (L.ksb s).val + (AtOff i).val := by + rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) + have e : L.mem s' (wa (L.ksb s') (AtOff i)) = L.mem s (wa (L.ksb s) (AtOff i)) := by + rw [kb] + refine w.mem_eq ?_ (fun h => h.elim (J.asid_offStepA (by omega) (by omega)) (asid_domA (by omega))) + have h32 := J.j.1.ksbAl + show (wa (L.ksb s) (AtOff i)).val % 8 = 0 + omega + rw [e] + refine (WP.spec_ok _).2 fun hne asid => ?_ + have q := (WP.spec_ok _).1 h0 hne asid + exact ⟨q.al, q.om, q.sg, q.os, RegionOffNodes.ksb kb q.ks⟩ + have hP := J.iplaced + have ep : EpStateRel Z.T E Rp Bf (L.mem s') σ' := + J.ep.frame hP.e (fun b ha hb => FD.wr.mem_eq ha fun h => + h.elim (endpFootOffWrite N1 J.ipcPlace hb) (efoot_domA N1 J.ipcPlace hb)) + (epFrameOfMcsA (st := st) (s' := s) N1 J.ipcPlace (MFrA.ofParts (WritesIn.refl _ _) FD.keep FD.sz) hum).2 + have kv : Notif.KView σ σ' := by + refine ⟨fun p x hx => by rw [hk]; exact hx, fun p x hx => ⟨x, by rw [hk]; exact hx, rfl, rfl, rfl⟩⟩ + have ntfn : NtfnStateRel N Z.T (L.mem s') σ' := + J.ntfn.frame hP.n (fun b hb hf => FD.wr.mem_eq hb fun h => + h.elim (nfoot_offMWrA N1 J.ipcPlace.notification hf) (nfoot_domA N1 J.ipcPlace.notification hf)) kv + have reply : ReplyStackRelA (L.mem s') Rp Z.C σ' (scNameA m) stack := by + refine J.reply.frame (fun r hr => ?_) (fun c _ x k h => ?_) (fun r hr x hx => ?_) + · obtain ⟨r32, -, rfit⟩ := hP.e.rep r hr + have one : ∀ o : U64, o.val < 32 → o.val % 8 = 0 → L.mem s' (wa r o) = L.mem s (wa r o) := by + intro o o1 o2 + have v : (wa r o).val = r.val + o.val := by rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) + refine FD.wr.mem_eq ?_ (fun h => h.elim + (other_offMWrA N1 (J.ipcPlace.reply r hr) (by omega) (by omega)) + (th_domA N1 (J.ipcPlace.reply r hr) (by intro e; cases e) (by omega) + (show (wa r o).val < r.val + 32 by omega))) + show (wa r o).val % 8 = 0 + omega + have n16 : (layout.reply.NEXT).val = 16 := by unfold layout.reply.NEXT; rfl + have p8 : (layout.reply.PREV).val = 8 := by unfold layout.reply.PREV; rfl + exact ⟨one _ (by omega) (by omega), one _ (by omega) (by omega)⟩ + · exact ⟨x, k, by rw [hk]; exact h, rfl⟩ + · obtain ⟨x0, h0⟩ := J.ep.reply r hr + have h1 : σ'.kheap (specPtr r) = some (.reply x0) := by rw [hk]; exact h0.1 + rw [h1] at hx + obtain rfl := KernelObject.reply.inj (Option.some.inj hx) + exact ⟨x0, h0.1, rfl⟩ + have bufCover : BufCover st Z.T Bf s' σ' := + J.bufCover_wA FD.wr (fun t ht K hK h => h.elim (tcbK_offMWrA N1 ht (by omega) (by omega)) + (tcbK_domSA N1 ht (by omega))) + (fun p x h => ⟨x, by rw [hk]; exact h, rfl, rfl⟩) + have bq : BlkQueuedA Z.T E N (L.mem s') σ' := + J.blkQ.keepA (fun u hu => by + rw [Notif.tBlockA_eq]; exact tw u hu 3336#u64 (by simp) (by simp) (by simp)) + (fun u _ x h => Or.inr ⟨x, by rw [← hk]; exact h, rfl⟩) + (fun p y h => by rw [hk]; exact h) (fun p y h => by rw [hk]; exact h) + have rv : RunVcpuInv st Z.T s' := J.runVcpu.rvSt fun y hy => by + refine ⟨?_, ?_⟩ + · rw [stA_eq]; exact tw y hy 3328#u64 (by simp) (by simp) (by simp) + · exact tw y hy 3672#u64 (by simp) (by simp) (by simp) + have scCov : ScCovA Z.C m σ' := fun p x k h => J.scCov p x k (by rw [← hk]; exact h) + have j := JStage3A.j57_stepDA J w σ' + exact JStage3A.of_schedWrD (J5 := J5A st) (Rj := J7R2A st ar nA) J (Q := Q) (Rl := Z.R) (curOf := Z.curOf) + (curScOf := Z.curScOf) (s' := s') (a' := a) (σ' := σ') w HS SSz (QKeepN.of_kheap hk) hum J.j.1.ar (fun _ _ => rfl) + (fun t ht y hy => J.bufAl t ht y (by rw [← hk]; exact hy)) + ⟨JStage3A.ent_stepDA J w blk, sysl⟩ sq poolOff Y.sched scCov ep ntfn reply bufCover + (J.idleNoFault.of_skeep FD.keep) Y.mcp Y.links sinv (J.sidle.congr hk hidle htime) rv bq symL schedValid j.1 j.2 + hdom + +end + +/-! ## The spec decodes of the accepted messages -/ + +private theorem domGetsA {α β : Type} (g : Fl4SpecA64.State Unit → α) (σ : State Unit) + (f : α → SEMonad Unit β) : + ((Fl4Spec.NonDetE.liftE <| Fl4Spec.NonDet.gets g) >>= f).run σ = (f (g σ)).run σ := + run_bind_okD (run_liftEA (show Fl4Spec.NonDet.gets g σ = ({(g σ, σ)}, False) from rfl)) f + +/-- The accepted `DomainScheduleConfigure` message: index 0, domain 0, a duration of at most `maxDomainDuration` +that is non-zero when the schedule starts at index 0. -/ +theorem domainConfigure_okA {σ : State Unit} (hlen : σ.domainList.length = 2) (rest : List U64) {dur : U64} + (hmax : dur.val < 2 ^ 56) (hst : dur = 0#u64 → σ.domainStartIndex ≠ 0) : + (decodeDomainScheduleConfigure (Z := Unit) (((0#u64 : U64) :: 0#u64 :: dur :: rest).map UScalar.bv)).run σ = + ({(.ok (.invokeDomainScheduleConfigure 0 0 (ucast domainDurationLen dur.bv)), σ)}, False) := by + unfold decodeDomainScheduleConfigure + simp only [Fl4Spec.NonDetE.whenE] + rw [if_neg (show ¬ (((0#u64 : U64) :: 0#u64 :: dur :: rest).map UScalar.bv).length < 2 + timeArgLen by + simp [timeArgLen]), ndE_pure_bindD] + have a0 : unat (Fl4SpecA64.the (((0#u64 : U64) :: 0#u64 :: dur :: rest).map UScalar.bv)[0]?) = 0 := rfl + have a1 : Fl4SpecA64.the (((0#u64 : U64) :: 0#u64 :: dur :: rest).map UScalar.bv)[1]? = (0#u64 : U64).bv := rfl + have a2 : parseTimeArg 2 (((0#u64 : U64) :: 0#u64 :: dur :: rest).map UScalar.bv) = dur.bv := rfl + simp only [Fl4Spec.NonDetE.returnOk, ndE_pure_bindD, a0, a1, a2] + rw [domGetsA] + have u0 : unat (0#u64 : U64).bv = 0 := rfl + have ndom : ¬ (0 : Nat) ≥ numDomains := by + have := numDomains_not_zero + omega + have ndur : ¬ dur.bv > maxDomainDuration := by + intro h + have h' := BitVec.lt_def.1 h + have mxs : maxDomainDuration.toNat = 2 ^ 56 - 1 := by decide + rw [mxs] at h' + change 2 ^ 56 - 1 < dur.val at h' + omega + have nz : ¬ (dur.bv = 0 ∧ (0#u64 : U64).bv ≠ 0) := fun h => h.2 rfl + rw [if_neg (show ¬ (0 : Nat) ≥ σ.domainList.length - 1 by omega), ndE_pure_bindD, u0, if_neg ndom, + ndE_pure_bindD, if_neg ndur, ndE_pure_bindD, if_neg nz, ndE_pure_bindD, domGetsA] + have ns : ¬ ((0 : Nat) = σ.domainStartIndex ∧ dur.bv = 0) := fun h => + hst (UScalar.eq_of_val_eq (show dur.val = 0 by + have := congrArg BitVec.toNat h.2 + exact this)) h.1.symm + rw [if_neg ns, ndE_pure_bindD] + rfl + +/-- The accepted `DomainScheduleSetStart` message: an index in the table whose entry is not the end marker. -/ +theorem domainSetStart_okA {σ : State Unit} (hlen : σ.domainList.length = 2) (rest : List U64) {idx : U64} + (hidx : idx.val < 2) (hne : Fl4SpecA64.the σ.domainList[idx.val]? ≠ domainEndMarker) : + (decodeDomainScheduleSetStart (Z := Unit) ((idx :: rest).map UScalar.bv)).run σ = + ({(.ok (.invokeDomainScheduleSetStart idx.val), σ)}, False) := by + unfold decodeDomainScheduleSetStart + simp only [Fl4Spec.NonDetE.whenE] + rw [if_neg (show ¬ ((idx :: rest).map UScalar.bv).length = 0 by simp), ndE_pure_bindD] + have a0 : unat (Fl4SpecA64.the ((idx :: rest).map UScalar.bv)[0]?) = idx.val := rfl + simp only [Fl4Spec.NonDetE.returnOk, ndE_pure_bindD, a0] + rw [domGetsA, if_neg (show ¬ idx.val ≥ σ.domainList.length by omega), ndE_pure_bindD, if_neg hne, + ndE_pure_bindD] + rfl + +/-! ## The two arms at a syscall entry -/ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +private theorem domNumA : (layout.NUM_DOMAINS).val = 1 := by + simp [layout.NUM_DOMAINS, fl4_abi.config.NUM_DOMAINS] + +set_option maxHeartbeats 4000000 in +/-- **`DomainScheduleConfigure` at a syscall entry** (module docstring): the only accepted index and domain are 0. -/ +theorem JSyscallA.domConfigureA (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + {slot len buf dur : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Domain) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hl : ¬ len < 3#u64) (hi : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok 0#u64) + (hd : msg.syscall_arg st s (L.curW s) buf 1#u64 = ok 0#u64) + (hu : msg.syscall_arg st s (L.curW s) buf 2#u64 = ok dur) (hmax : dur.val < 2 ^ 56) + (hend : dur = 0#u64 → domStartWordA (st := st) s ≠ 0#u64) : + ∃ σ1 σ2 s2, + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + invokeDomain (Z := Unit) (.invokeDomainScheduleConfigure 0 0 (ucast domainDurationLen dur.bv)) σ1 = + ({((), σ2)}, False) ∧ + syscall.decode_invocation st ar s a fl4_abi.label.DomainScheduleConfigure len slot (capA st s slot) blk call don + false buf extra = ok (.Ok (), s2, a) ∧ + Sched.BodyOKA σ2 m ∧ σ2.curThread = σ.curThread ∧ + ∃ Q, JStage3A st AR { Z with Q := Q } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + obtain ⟨xc, hxc, hst, hsp, J1, -, -, -⟩ := J.toJStage3A.of_restartCurA + RS.pl.choose_spec.choose_spec.choose_spec.choose_spec RS.sym RS.run J.toJStage3EntryA.curNotVmA RS.cur RS.vs + RS.vc + generalize L.wr s (stA (L.curW s)) sched.TS_RESTART = s1 at hst J1 + have N1 := J1.sr.toSchedSRN + have fit := N1.ksFit + have al := N1.ksb_al + have cpu : (L.cpu s1).val < 128 := by + obtain ⟨k, -, hk, hcs⟩ := N1.csN + exact lt_of_lt_of_le ((hcs _).1 N1.sch.cpuCs) hk + have nd := J1.domOK + -- the schedule words + have a192 : layout.ks.DOM_SCHEDULE = ok 192#u64 := by + unfold layout.ks.DOM_SCHEDULE layout.WORD + rfl + have o0 : wa 192#u64 (core.num.U64.wrapping_mul 0#u64 16#u64) = 192#u64 := by decide + have o8 : wa (192#u64 : U64) 8#u64 = 200#u64 := by decide + have eset : sched.set_dom_sched st s1 0#u64 0#u64 dur = + ok (domWrA (st := st) (domWrA (st := st) s1 192#u64 0#u64) 200#u64 dur) := by + unfold sched.set_dom_sched + simp only [lift, bind_ok, a192, o0, o8, eq_of_spec_fd (obj.ks_set.spec (L := L) _ _ _)] + -- the decode + have hdec : syscall.decode_invocation st ar s a fl4_abi.label.DomainScheduleConfigure len slot (capA st s slot) blk + call don false buf extra = + ok (.Ok (), domWrA (st := st) (domWrA (st := st) s1 192#u64 0#u64) 200#u64 dur, a) := by + rw [hcap, decodeDomain_programA, if_neg Bool.false_ne_true] + unfold domain.decode + have ne : fl4_abi.label.DomainScheduleConfigure ≠ fl4_abi.label.DomainSetSet := by + intro h + have := congrArg UScalar.val h + rw [Fl4ProofsA64.P0.Consts.fl4_abi.label.DomainScheduleConfigure.val_eq, + Fl4ProofsA64.P0.Consts.fl4_abi.label.DomainSetSet.val_eq] at this + omega + simp only [cur_thread_ok, bind_ok, if_neg ne, if_pos rfl, if_true, if_neg hl, hi, hd, hu] + obtain ⟨i, ei, iv⟩ := spec_existsA (U64.sub_spec (x := layout.NUM_DOMAIN_SCHEDULES) (y := 1#u64) + (by have := domTwoA; scalar_tac)) + have iv1 : i.val = 1 := by have := domTwoA; scalar_tac + have c1 : ¬ (0#u64 : U64) ≥ i := by + have z : (0#u64 : U64).val = 0 := rfl + scalar_tac + have c2 : ¬ (0#u64 : U64) ≥ layout.NUM_DOMAINS := by + have z : (0#u64 : U64).val = 0 := rfl + have := domNumA + scalar_tac + obtain ⟨mx, emx, mxv⟩ := spec_existsA + (WP.spec_mono Fl4ProofsA64.P0.Consts.domain.MAX_DURATION.spec + (fun v (h : _) => (show v.val = 2 ^ 56 - 1 by subst h; rfl))) + have c3 : ¬ dur > mx := by + intro h + have : mx.val < dur.val := by scalar_tac + omega + have es : obj.ks_get st s layout.ks.DOM_SCHED_START = ok (domStartWordA (st := st) s) := + eq_of_spec_fd (obj.ks_get.spec (L := L) s _) + simp only [ei, bind_ok, if_neg c1, if_neg c2, emx, if_neg c3, es] + have hz : (0#u64 != 0#u64) = false := by simp + by_cases h0 : dur = 0#u64 + · have ne0 : ¬ (0#u64 : U64) = domStartWordA (st := st) s := fun h => hend h0 h.symm + simp only [if_pos h0, hz, Bool.false_eq_true, ↓reduceIte, if_neg ne0, hst, bind_ok, eset] + · simp only [if_neg h0] + split <;> simp only [if_neg h0, hst, bind_ok, eset] + -- the spec state + have Y1 : YieldQueueRelA (st := st) Z m κ s1 _ := + ⟨J1.sr, fun _ hu _ hx => (J1.ep.at_tcb hu hx).st, J1.mcp, J1.yieldRel⟩ + obtain ⟨Y2, F2⟩ := writeDomainGlobalA Y1 (o := 192#u64) (by decide) (by decide) 0#u64 + (fun h => absurd h (by decide)) (stUpdA σ σ.curThread xc .restart).domainIndex + rw [if_neg (show (192#u64 : U64) ≠ 16#u64 by decide)] at Y2 F2 + obtain ⟨Y3, F3⟩ := writeDomainGlobalA Y2 (o := 200#u64) (by decide) (by decide) dur + (fun h => absurd h (by decide)) (stUpdA σ σ.curThread xc .restart).domainIndex + rw [if_neg (show (200#u64 : U64) ≠ 16#u64 by decide)] at Y3 F3 + have F23 := F2.trans F3 rfl rfl + have Y4 := Y3.domSpecA ((stUpdA σ σ.curThread xc .restart).domainList.set 0 (0, ucast domainDurationLen dur.bv)) + (stUpdA σ σ.curThread xc .restart).domainStartIndex + have nd2 := nd.configureA fit al cpu hmax + -- the record + have blk := (post_of_okA (domain.decode.dfK (st := st) (ar := ar) hA s a fl4_abi.label.DomainScheduleConfigure len + buf extra (hcap ▸ J.decPreA hslot hext)) (by + have h := hdec + rw [hcap, decodeDomain_programA, if_neg Bool.false_ne_true] at h + exact h)).2 + obtain ⟨-, -, sysl, symL, -, userOK, -⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := fl4_abi.label.DomainScheduleConfigure) + (by rw [hcap]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdec σ m + have J2 := J1.of_domStepA (Q := Z.Q) + (σ' := { stUpdA σ σ.curThread xc .restart with + domainList := (stUpdA σ σ.curThread xc .restart).domainList.set 0 (0, ucast domainDurationLen dur.bv) }) + ⟨F23.wr, SKeepA.of_kheap rfl, SSzA.of_kheap rfl⟩ rfl + { kh := fun _ => Or.inl rfl, irqS := rfl, irqN := rfl, asid := rfl, vcur := rfl, cdt := rfl, orig := rfl } + rfl rfl (BitVec.le_refl _) blk sysl symL userOK Y4 { J1.sinv with irqN := { J1.sinv.irqN with } } { J1.schedValid with } nd2 + have B : Sched.BodyOKA (stUpdA σ σ.curThread xc .restart) m := + Sched.BodyOKA.ofRqAct J hxc ⟨(stUpdA σ σ.curThread xc .restart).readyQueues, Or.inl rfl⟩ + refine ⟨_, { stUpdA σ σ.curThread xc .restart with + domainList := (stUpdA σ σ.curThread xc .restart).domainList.set 0 (0, ucast domainDurationLen dur.bv) }, _, hsp, + ?_, hdec, { B with }, rfl, Z.Q, J2⟩ + rfl + +set_option maxHeartbeats 4000000 in +/-- **`DomainScheduleSetStart` at a syscall entry** (module docstring): the entry at `idx` has a non-zero duration. -/ +theorem JSyscallA.domSetStartA (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + {slot len buf idx w : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Domain) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hl : ¬ len < 1#u64) (hi : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok idx) + (hidx : idx < layout.NUM_DOMAIN_SCHEDULES) (hw : sched.dom_sched_duration st s idx = ok w) (hw0 : w ≠ 0#u64) : + ∃ σ1 σ2 s2, + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + invokeDomain (Z := Unit) (.invokeDomainScheduleSetStart idx.val) σ1 = ({((), σ2)}, False) ∧ + syscall.decode_invocation st ar s a fl4_abi.label.DomainScheduleSetStart len slot (capA st s slot) blk call don + false buf extra = ok (.Ok (), s2, a) ∧ + Sched.BodyOKA σ2 m ∧ σ2.curThread = σ.curThread ∧ + ∃ Q, JStage3A st AR { Z with Q := Q } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + obtain ⟨xc, hxc, hst, hsp, J1, -, -, -⟩ := J.toJStage3A.of_restartCurA + RS.pl.choose_spec.choose_spec.choose_spec.choose_spec RS.sym RS.run J.toJStage3EntryA.curNotVmA RS.cur RS.vs + RS.vc + generalize L.wr s (stA (L.curW s)) sched.TS_RESTART = s1 at hst J1 + have N1 := J1.sr.toSchedSRN + have fit := N1.ksFit + have al := N1.ksb_al + have cpu : (L.cpu s1).val < 128 := by + obtain ⟨k, -, hk, hcs⟩ := N1.csN + exact lt_of_lt_of_le ((hcs _).1 N1.sch.cpuCs) hk + have nd := J1.domOK + have Y1 : YieldQueueRelA (st := st) Z m κ s1 (stUpdA σ σ.curThread xc .restart) := + ⟨J1.sr, fun _ hu _ hx => (J1.ep.at_tcb hu hx).st, J1.mcp, J1.yieldRel⟩ + obtain ⟨Y2, F2⟩ := writeDomainGlobalA Y1 (o := 32#u64) (by decide) (by decide) idx + (fun h => absurd h (by decide)) (stUpdA σ σ.curThread xc .restart).domainIndex + rw [if_neg (show (32#u64 : U64) ≠ 16#u64 by decide)] at Y2 F2 + obtain ⟨Y3, F3⟩ := writeDomainGlobalA Y2 (o := 16#u64) (by decide) (by decide) 0#u64 + (fun h => absurd h (by decide)) (stUpdA σ σ.curThread xc .restart).domainIndex + rw [if_pos rfl] at Y3 F3 + obtain ⟨Y4, F4⟩ := writeDomainGlobalA Y3 (o := 24#u64) (by decide) (by decide) 0#u64 + (fun h => absurd h (by decide)) 0 + rw [if_neg (show (24#u64 : U64) ≠ 16#u64 by decide)] at Y4 F4 + have F24 := (F2.trans F3 rfl rfl).trans F4 rfl rfl + have Y5 := Y4.domSpecA (stUpdA σ σ.curThread xc .restart).domainList idx.val + have nd2 := nd.setStartA fit al cpu hidx + -- `reschedule_required` + have Yw : YieldQueueRelA (st := st) Z m κ + (domWrA (st := st) (domWrA (st := st) (domWrA (st := st) s1 32#u64 idx) 16#u64 0#u64) 24#u64 0#u64) + { stUpdA σ σ.curThread xc .restart with domainStartIndex := idx.val, domainTime := 0, domainIndex := 0 } := Y5 + have Fw : MFrDA (st := st) Z m s1 + (domWrA (st := st) (domWrA (st := st) (domWrA (st := st) s1 32#u64 idx) 16#u64 0#u64) 24#u64 0#u64) + (stUpdA σ σ.curThread xc .restart) + { stUpdA σ σ.curThread xc .restart with domainStartIndex := idx.val, domainTime := 0, domainIndex := 0 } := + ⟨F24.wr, SKeepA.of_kheap rfl, SSzA.of_kheap rfl⟩ + obtain ⟨s5, e5, σ5, Q5, hres, hk5, -, Y6, F6⟩ := spec_existsA (yieldRescheduleA Yw) + have hact : (stUpdA σ σ.curThread xc .restart).schedulerAction = .resumeCurThread := J.act + have e5σ : σ5 = { stUpdA σ σ.curThread xc .restart with + domainStartIndex := idx.val, domainTime := 0, domainIndex := 0, schedulerAction := .chooseNewThread } := by + have h := rescheduleRequired_noswitchA (σ := { stUpdA σ σ.curThread xc .restart with + domainStartIndex := idx.val, domainTime := 0, domainIndex := 0 }) (fun t h => by + change (stUpdA σ σ.curThread xc .restart).schedulerAction = .switchThread t at h + rw [hact] at h; cases h) + exact (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (hres.symm.trans h)))).2 + subst e5σ + have nd5 : NdOKA (st := st) s5 { stUpdA σ σ.curThread xc .restart with + domainStartIndex := idx.val, domainTime := 0, domainIndex := 0, schedulerAction := .chooseNewThread } := by + refine nd2.keepS Yw.sched.toSchedSRN (DomKeepA.ofKey rfl) F6.wr.1 F6.wr.2.1 (fun b hb hd => F6.wr.mem_eq hb ?_) + intro h + have kb : L.ksb (domWrA (st := st) (domWrA (st := st) (domWrA (st := st) s1 32#u64 idx) 16#u64 0#u64) 24#u64 + 0#u64) = L.ksb s1 := by simp only [domWrA_ksb] + rw [kb] at hd + exact J1.dom_offStepA hd (schedStepW_mwr (mwr_back rfl rfl (SSzA.of_kheap rfl) kb h)) + -- the decode + have a32 : layout.ks.DOM_SCHED_START = 32#u64 := by unfold layout.ks.DOM_SCHED_START; rfl + have a16 : layout.ks.DOMAIN_TIME = 16#u64 := by unfold layout.ks.DOMAIN_TIME; rfl + have a24 : layout.ks.DOM_SCHED_IDX = 24#u64 := by unfold layout.ks.DOM_SCHED_IDX; rfl + have hdec : syscall.decode_invocation st ar s a fl4_abi.label.DomainScheduleSetStart len slot (capA st s slot) blk + call don false buf extra = ok (.Ok (), s5, a) := by + rw [hcap, decodeDomain_programA, if_neg Bool.false_ne_true] + unfold domain.decode + have ne1 : fl4_abi.label.DomainScheduleSetStart ≠ fl4_abi.label.DomainSetSet := by + intro h + have := congrArg UScalar.val h + rw [Fl4ProofsA64.P0.Consts.fl4_abi.label.DomainScheduleSetStart.val_eq, + Fl4ProofsA64.P0.Consts.fl4_abi.label.DomainSetSet.val_eq] at this + omega + have ne2 : fl4_abi.label.DomainScheduleSetStart ≠ fl4_abi.label.DomainScheduleConfigure := by + intro h + have := congrArg UScalar.val h + rw [Fl4ProofsA64.P0.Consts.fl4_abi.label.DomainScheduleSetStart.val_eq, + Fl4ProofsA64.P0.Consts.fl4_abi.label.DomainScheduleConfigure.val_eq] at this + omega + have c1 : ¬ idx ≥ layout.NUM_DOMAIN_SCHEDULES := by scalar_tac + obtain ⟨i1, ei, iv⟩ := spec_existsA (U64.sub_spec (x := layout.NUM_DOMAIN_SCHEDULES) (y := 2#u64) + (by have := domTwoA; scalar_tac)) + have iv1 : i1 = 0#u64 := by + apply UScalar.eq_of_val_eq + have := domTwoA + show i1.val = 0 + scalar_tac + simp only [cur_thread_ok, bind_ok, if_neg ne1, if_neg ne2, if_pos rfl, if_true, if_neg hl, hi, if_neg c1, hw, + if_neg hw0, hst, a32, a16, a24, eq_of_spec_fd (obj.ks_set.spec (L := L) _ _ _), ei, iv1, e5] + have blk := (post_of_okA (domain.decode.dfK (st := st) (ar := ar) hA s a fl4_abi.label.DomainScheduleSetStart len + buf extra (hcap ▸ J.decPreA hslot hext)) (by + have h := hdec + rw [hcap, decodeDomain_programA, if_neg Bool.false_ne_true] at h + exact h)).2 + obtain ⟨-, -, sysl, symL, -, userOK, -⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := fl4_abi.label.DomainScheduleSetStart) + (by rw [hcap]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdec σ m + have F := Fw.transA F6 rfl rfl + have SI : SInvXA { stUpdA σ σ.curThread xc .restart with + readyQueues := (stUpdA σ σ.curThread xc .restart).readyQueues, schedulerAction := .chooseNewThread } m n := + J1.sinv.chooseRqA _ fun _ _ _ h => Or.inl h + have V : SchedValidA { stUpdA σ σ.curThread xc .restart with + readyQueues := (stUpdA σ σ.curThread xc .restart).readyQueues, schedulerAction := .chooseNewThread } := + J1.schedValid.chooseRqA _ fun _ _ _ h => Or.inl h + have J2 := J1.of_domStepA (Q := Q5) + (σ' := { stUpdA σ σ.curThread xc .restart with + domainStartIndex := idx.val, domainTime := 0, domainIndex := 0, schedulerAction := .chooseNewThread }) + F rfl { kh := fun _ => Or.inl rfl, irqS := rfl, irqN := rfl, asid := rfl, vcur := rfl, cdt := rfl, orig := rfl } + rfl rfl (BitVec.le_refl _) blk sysl symL userOK Y6 { SI with irqN := { SI.irqN with } } { V with } nd5 + have B : Sched.BodyOKA { stUpdA σ σ.curThread xc .restart with schedulerAction := .chooseNewThread } m := + Sched.BodyOKA.ofRqAct J hxc ⟨(stUpdA σ σ.curThread xc .restart).readyQueues, Or.inr rfl⟩ + have espec : domainSetStart (Z := Unit) idx.val (stUpdA σ σ.curThread xc .restart) = + ({((), { stUpdA σ σ.curThread xc .restart with + domainStartIndex := idx.val, domainTime := 0, domainIndex := 0, schedulerAction := .chooseNewThread })}, + False) := by + have len2 : (stUpdA σ σ.curThread xc .restart).domainList.length = 2 := nd.len.trans domTwoA + unfold domainSetStart + rw [nd_bind_oneSc (a := ()) (s' := { stUpdA σ σ.curThread xc .restart with domainStartIndex := idx.val }) (by rfl), + nd_bind_oneSc (a := ()) (s' := { stUpdA σ σ.curThread xc .restart with + domainStartIndex := idx.val, domainTime := 0 }) (by rfl), + nd_gets_bindSc] + change (Fl4Spec.NonDet.modify (fun s : State Unit => { s with + domainIndex := (stUpdA σ σ.curThread xc .restart).domainList.length - 2 }) >>= fun _ => + rescheduleRequired (Z := Unit)) _ = _ + rw [len2, nd_bind_oneSc (a := ()) (s' := { stUpdA σ σ.curThread xc .restart with + domainStartIndex := idx.val, domainTime := 0, domainIndex := 0 }) (by rfl)] + exact hres + exact ⟨_, _, _, hsp, espec, hdec, { B with }, rfl, Q5, J2⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3FaultTailA.lean b/proofs/Fl4ProofsA64/P3/Stage3FaultTailA.lean index 6cc82e12a..d95b412e8 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3FaultTailA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3FaultTailA.lean @@ -187,7 +187,7 @@ theorem JSyscallA.faultTailA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) orig := rfl } have Q01 : QBlkA (specPtr '' E) (specPtr '' N) σ σ1 := QSendA.toBlk J.ipcSorted ((QKeepA.upd hkx (QObjA.ofTcb (y := x1) rfl)).trans - (QKeepA.of_kheap (by rw [hσ1]; rfl) (by rw [hσ1]; exact ⟨rfl, rfl, rfl, rfl⟩))).toSend + (QKeepA.of_kheap (by rw [hσ1]; rfl) (by rw [hσ1]; exact DomKeepA.ofKey rfl))).toSend have Q12 := Qk Q01.sorted have Q02 : QBlkA (specPtr '' E) (specPtr '' N) σ σ2 := ⟨Q12.sorted, fun h => Q12.act (Q01.act h), fun p y h => by diff --git a/proofs/Fl4ProofsA64/P3/Stage3FireReprA.lean b/proofs/Fl4ProofsA64/P3/Stage3FireReprA.lean index 90a31592f..4c5e61d87 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3FireReprA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3FireReprA.lean @@ -182,7 +182,7 @@ theorem JStage3A.reprog_recA (fun u hu x' hx' => Or.inr ⟨x', hx', rfl⟩) (fun _ _ h => h) (fun _ _ h => h) have j := J.j57_stepNWA w { σ with reprogramTimer := true } exact JStage3A.of_schedWrN (blkQ := bq) (symL := symL) (schedValid := { J.schedValid with }) J (Q := Z.Q) (Rl := Z.R) (curOf := Z.curOf) (curScOf := Z.curScOf) - (s' := s') (a' := a) (σ' := { σ with reprogramTimer := true }) w HS SSz (QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩) rfl J.j.1.ar (fun _ _ => rfl) J.bufAl + (s' := s') (a' := a) (σ' := { σ with reprogramTimer := true }) w HS SSz (QKeepA.of_kheap rfl (DomKeepA.ofKey rfl)) rfl J.j.1.ar (fun _ _ => rfl) J.bufAl ⟨J.ent_stepNWA w blk', sysl⟩ sq poolOff H2 J.scCov ep ntfn reply buf J.idleNoFault mcp yr { J.sinv with irqN := by cases J.sinv.irqN; constructor <;> assumption } { J.sidle with } rv' j.1 j.2 diff --git a/proofs/Fl4ProofsA64/P3/Stage3HPreA.lean b/proofs/Fl4ProofsA64/P3/Stage3HPreA.lean index 07a1b3457..dcf522b0e 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3HPreA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3HPreA.lean @@ -89,8 +89,8 @@ variable (st) in /-- **The premises of `HPreA`, lifted once to the top** (module docstring), without the platform facts of `ExitPlatA`. -/ structure HPreEnvA (AR : A → HwRootA → Prop) (ar : machine.Arch A) (hPl : ArchPlat ar) (n : Nat) (Cs : Set U64) (m : McState) (Clock : A → MachineState → Prop) (pending : SMonad Unit Unit) (s : S) (a : A) (call : Fl4SpecA64.Syscall) : Prop where - K : IrqArchA ar AR (fun _ _ => True) - hMax : kernelConfig.maxIRQ = 5375 + /-- [P] the interrupt controller facts shared with the interrupt entry -/ + irq : IrqEnvA ar AR hn : n = fl4A64Platform.numNodes hLimit : ∀ a', sporadic.max_release_time ar a' ⦃ v => v.bv = fl4MaxReleaseTime ⦄ /-- [J] the timeout send without a waiting receiver, at the preempted state a run of this call reaches. -/ @@ -120,7 +120,7 @@ theorem HPreA.ofEnv {Z : XSetsA} {Clock : A → MachineState → Prop} {pending obtain ⟨poll, hpoll, hpend, line⟩ := E.poll subst hpend exact hPre_ofA (Rch := fun s2 a2 => syscall.handle_invocation st ar s a calling blocking donate false - (L.mem s (regWA (L.curW s) layout.reg.CAP)) = ok (.Err error.Exc.Preempted, s2, a2)) hA hPl rfl E.K E.hMax hpoll XP.env.hCs XP.env.h1 XP.hnd E.hn XP.hag + (L.mem s (regWA (L.curW s) layout.reg.CAP)) = ok (.Err error.Exc.Preempted, s2, a2)) hA hPl rfl E.irq.K E.irq.hMax hpoll XP.env.hCs XP.env.h1 XP.hnd E.hn XP.hag (fun a' => WP.spec_mono (XP.env.hmb a') fun mb h => h.trans XP.hag.symm) E.hLimit XP.env.hmax XP.env.htu XP.hconv (fun s2 a2 τ2 hr2 hR hP clk => E.hSend calling blocking donate s2 a2 τ2 hd hr2 hR hP clk) line s' a' τ hh h.1 h.2.1 h.2.2 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InsP1A.lean b/proofs/Fl4ProofsA64/P3/Stage3InsP1A.lean index 08ab4f3e3..625c431bb 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InsP1A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InsP1A.lean @@ -14,6 +14,9 @@ facts the record and the decode site do not give. `JStage3A.p1StepA` handles a s `UserOK`, `BXI` and `J7A` at any spec state (`ArmQIAt.ofXC`, `S1aStepFix.ofXfer2` with `XferSlots2` the one transfer, `J7A.of_stepFixedA`; as `J7A.of_rpPostA`, but the `OS` slots change). +* **`insertP1G`** takes the two copy facts (`S1aCopyRel`, `S1aDerived`) instead of a `derive_cap` witness; + **`insertP1A`** (the derived cap) and **`insertP1CnodeA`** (a CNode cap with a new guard) are its instances. + No named premise. New module. -/ import Fl4ProofsA64.P3.Stage3P1StepA @@ -33,7 +36,8 @@ variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : {H : Heap} {Cs OS Vc Ub Pt Ac : Set U64} {ia ie : Nat} set_option maxHeartbeats 4000000 in -/-- **`cdt::insert` of a derived cap: `SysL`, `SymL`, `BlkOK` and the carries** (module docstring). -/ +/-- **`cdt::insert` of a derived cap: `SysL`, `SymL`, `BlkOK`, the carries and the written slots** (module +docstring). -/ theorem cdt.insert.p1A (hO : OSOK H.tcbs H.omega H.frame OS) {s : S} (hb : BXI st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (hH : HeapOK H) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (V : VcCap st Vc OS s) @@ -41,11 +45,11 @@ theorem cdt.insert.p1A (hO : OSOK H.tcbs H.omega H.frame OS) {s : S} {x y : U64} {nc : capability.Cap} (hx : x ∈ OS) (hy : y ∈ OS) (hxy : x ≠ y) (hyc : obj.sext48 y = ok y) (hy0 : capA st s y = .Null) (hyB : y ∉ BufS H.tcbs ∨ (BufCap nc ∧ CnOP H nc)) (hyE : y ∉ EptS H.tcbs) (hcd : ∃ z ∈ OS, CovZ (capA st s z) y) (hw : CapRt.EncWf nc) (hnc : nc ≠ .Null) - (C : InsC nc (capA st s x)) (hE : ApE nc (capA st s x)) - (hdv : objects.derive_cap st s x (capA st s x) = ok (.Ok nc)) : + (C : InsC nc (capA st s x)) (hE : ApE nc (capA st s x)) : cdt.insert st s nc x y ⦃ s2 => (SysL st H Cs OS ia ie s2 ∧ SymL st H Cs s2) ∧ BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s2 ∧ - XC st OS Vc s s2 ∧ XV st H OS Vc s s2 ∧ XferSlots st OS s s2 ⦄ := by + XC st OS Vc s s2 ∧ XV st H OS Vc s s2 ∧ capA st s2 y = nc ∧ FullA (capA st s2 x) (capA st s x) ∧ + (∀ z ∈ OS, z ≠ x → z ≠ y → capA st s2 z = capA st s z) ⦄ := by have hm := B.sys.stz.1.1.mdbS have nn := (hm.lnk hO hx).2 have R : cdt.insert st s nc x y ⦃ s2 => (SysL st H Cs OS ia ie s2 ∧ SymL st H Cs s2) ∧ @@ -98,11 +102,66 @@ theorem cdt.insert.p1A (hO : OSOK H.tcbs H.omega H.frame OS) {s : S} · rw [ek z hz e2 e1]; exact V' z hz refine WP.spec_mono (WP.spec_and R (cdt.insert.slots hO hm hx hy hxy hyc C.nn hw)) ?_ rintro s2 ⟨hR, new, turned, others⟩ - exact ⟨hR.1, hR.2.1, hR.2.2.1, hR.2.2.2, - Or.inr ⟨x, hx, y, hy, hxy, hy0, ⟨s, nc, hdv, new⟩, turned, others⟩⟩ + exact ⟨hR.1, hR.2.1, hR.2.2.1, hR.2.2.2, new, turned, others⟩ end +end + +end Fl4ProofsA64.P3 + +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} + +/-- **One insert's Untyped separation**, from the inserted cap's `FE` (`XferSlots.ktUt` without the derivation). -/ +theorem insKtUtA {s r : S} {x y : U64} {nc : capability.Cap} (fe : FE nc (capA st s x)) (hx : x ∈ OS) + (new : capA st r y = nc) (turned : FullA (capA st r x) (capA st s x)) + (others : ∀ z ∈ OS, z ≠ x → z ≠ y → capA st r z = capA st s z) (sep : S1aKtUt st OS Kt s) : + S1aKtUt st OS Kt r := by + have old := S1aKtUt.iff_capInv.mp sep + refine S1aKtUt.iff_capInv.mpr fun z hz => ?_ + by_cases at_dest : z = y + · rw [at_dest, new] + exact S1aKtUtCap.fe fe (old x hx) + by_cases at_src : z = x + · rw [at_src] + rcases turned with same | ⟨p, b, i, d, i', before, after, -⟩ + · rw [same] + exact old x hx + · intro p' b' j d' cap + rw [after] at cap + cases cap + exact old x hx p b i d before + rw [others z hz at_src at_dest] + exact old z hz + +/-- **`S1aStepFix.ofXfer2` for one transfer given by its slot image** (no `derive_cap` witness). -/ +theorem S1aStepFix.ofImageK {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) + (v : XV st H OS Vc s q) (img : S1aSlotImage st OS s q) (sep : S1aKtUt st OS Kt 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) + (Df : DevFrAl st OS s) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (KC : S1aHiK st OS Kt KLv s) : + S1aStepFix st H Cs OS Vc Ub Pt Kt KLv ia ie n q := by + obtain ⟨arm, tab, mem⟩ := 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 v.1.1 (v.1.2 Ub Pt vr fu) img + have col : S1aHiK st OS Kt KLv q := KC.keep ⟨EdgeKeepOn.ofVsKeep R vs, arm.hiRoots R.highHeaders⟩ + exact S1aStepFix.mk arm.1 arm.2.1 (S1aArmCol.ofTZ tab C) (arm.frUb fu) (arm.2.2.2.1 vcc) (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 R'.ex col + +end Fl4ProofsA64.P1.W7.R.ST + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 + +noncomputable section + section variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} @@ -111,13 +170,13 @@ variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : set_option maxHeartbeats 8000000 in /-- **The P1 facts at the state a `cdt::insert` reaches** (module docstring). -/ -theorem JStage3A.insertP1A (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) +theorem JStage3A.insertP1G (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) {x y : U64} {nc : capability.Cap} (hx : x ∈ OS) (hy : y ∈ OS) (hxy : x ≠ y) (hyc : obj.sext48 y = ok y) (hy0 : capA st s y = .Null) (hyB : y ∉ BufS H.tcbs ∨ (BufCap nc ∧ CnOP H nc)) (hyE : y ∉ EptS H.tcbs) (hcd : ∃ z ∈ OS, CovZ (capA st s z) y) (hw : CapRt.EncWf nc) (hnc : nc ≠ .Null) (C : InsC nc (capA st s x)) (hE : ApE nc (capA st s x)) - (hdv : objects.derive_cap st s x (capA st s x) = ok (.Ok nc)) (G' : MdbGhostA) : + (hcopy : S1aCopyRel nc (capA st s x)) (hder : S1aDerived nc) (G' : MdbGhostA) : cdt.insert st s nc x y ⦃ s2 => SysL st H Z.Cs OS ia ie s2 ∧ SymL st H Z.Cs s2 ∧ Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s2 ∧ BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s2 ∧ @@ -125,12 +184,14 @@ theorem JStage3A.insertP1A (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits, KLv, W⟩ := J7A.unp J.j7 have I := J.delIn hA hPl W refine WP.spec_mono (cdt.insert.p1A (Ub := Ub) (Pt := Pt) J.sys.ent.os J.sys.ent.bxi J.sys.ent.heap J.sys.sysl J.symL - W.vcc W.vr hx hy hxy hyc hy0 hyB hyE hcd hw hnc C hE hdv) ?_ - rintro s2 ⟨⟨sysl2, symL2⟩, blk2, xc, xv, xs⟩ + W.vcc W.vr hx hy hxy hyc hy0 hyB hyE hcd hw hnc C hE) ?_ + rintro s2 ⟨⟨sysl2, symL2⟩, blk2, xc, xv, new, turned, others⟩ have kb : L.ksb s2 = L.ksb s := xv.1.1 have A2 := ArmQIAt.ofXC (ia := ia) (ie := ie) ⟨sysl2, symL2⟩ ⟨Ac, blk2⟩ xc xv.1.toVs - have Fx := S1aStepFix.ofXfer2 ⟨A2.1, A2.2, xv.1, s2, xs, xv, XferSlots.refl s2, XV.refl s2⟩ W.vr W.fu W.vcc W.col W.df - W.r2 W.sep W.hiK + have img : S1aSlotImage st OS s s2 := + .copy W.r2.capRefs.refs hx hy hxy hy0 new (hder.same hcopy) hder.2 (S1aCapSame.insertSource turned) others + have sep2 : S1aKtUt st OS _ s2 := insKtUtA C.fe hx new turned others W.sep + have Fx := S1aStepFix.ofImageK ⟨A2.1, A2.2, xv.1⟩ xv img sep2 W.vr W.fu W.vcc W.col W.df W.r2 W.hiK have pn : PoolNamed st OS s2 := A2.1.2.2.2.2.2.1 W.pn have hsp : ∀ p, SchedPageA st { Z with G := G' } OS s2 p → p ∈ Pt := by obtain ⟨_, -, -, -, ⟨_, _, _, _, _, _, _, R'⟩, -⟩ := id Fx @@ -139,6 +200,43 @@ theorem JStage3A.insertP1A (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) exact J7A.of_stepFixedA (Z := { Z with G := G' }) Fx W.vr kb W.al W.vu pn hsp (fun b hb o ho => by rw [kb]; exact W.ks b hb o ho) (J7R2K.of_stepFixedA (σ' := σ') (m := m') Fx W.ktK) +/-- **The P1 facts across a `cdt::insert` of the source's derived cap** (`insertP1G`). -/ +theorem JStage3A.insertP1A (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + {x y : U64} {nc : capability.Cap} (hx : x ∈ OS) (hy : y ∈ OS) (hxy : x ≠ y) (hyc : obj.sext48 y = ok y) + (hy0 : capA st s y = .Null) (hyB : y ∉ BufS H.tcbs ∨ (BufCap nc ∧ CnOP H nc)) (hyE : y ∉ EptS H.tcbs) + (hcd : ∃ z ∈ OS, CovZ (capA st s z) y) (hw : CapRt.EncWf nc) (hnc : nc ≠ .Null) + (C : InsC nc (capA st s x)) (hE : ApE nc (capA st s x)) + (hdv : objects.derive_cap st s x (capA st s x) = ok (.Ok nc)) (G' : MdbGhostA) : + cdt.insert st s nc x y ⦃ s2 => SysL st H Z.Cs OS ia ie s2 ∧ SymL st H Z.Cs s2 ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s2 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s2 ∧ + ∀ σ' m', J7A st (J7R2A st ar hPl.ipa) { Z with G := G' } H OS s2 σ' m' ⦄ := by + have rel := objects.derive_cap.s1aRel (st := st) s x (capA st s x) + rw [hdv, WP.spec_ok] at rel + obtain ⟨copied, fresh⟩ := rel nc rfl + exact J.insertP1G hA hPl hx hy hxy hyc hy0 hyB hyE hcd hw hnc C hE copied fresh G' + +/-- **The P1 facts across a `cdt::insert` of a CNode cap with a new guard** (`update_cap_data` of the source's): an +intermediate install of a derived-with-data CSpace root, which `derive_cap` of the source does not give. -/ +theorem JStage3A.insertP1CnodeA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + {x y p r gs g gs' g' : U64} (hx : x ∈ OS) (hy : y ∈ OS) (hxy : x ≠ y) (hyc : obj.sext48 y = ok y) + (hy0 : capA st s y = .Null) (hyB : y ∉ BufS H.tcbs) (hyE : y ∉ EptS H.tcbs) + (hcd : ∃ z ∈ OS, CovZ (capA st s z) y) (hw : CapRt.EncWf (.CNode p r gs' g')) + (hsrc : capA st s x = .CNode p r gs g) (G' : MdbGhostA) : + cdt.insert st s (.CNode p r gs' g') x y ⦃ s2 => SysL st H Z.Cs OS ia ie s2 ∧ SymL st H Z.Cs s2 ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s2 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s2 ∧ + ∀ σ' m', J7A st (J7R2A st ar hPl.ipa) { Z with G := G' } H OS s2 σ' m' ⦄ := by + have C : InsC (.CNode p r gs' g') (capA st s x) := by + rw [hsrc] + exact InsC.of_soa (Or.inr (Or.inl ⟨_, _, _, _, rfl⟩)) (by simp [objects.same_object_as, objects.same_region_as]) + exact J.insertP1G hA hPl hx hy hxy hyc hy0 (Or.inl hyB) hyE hcd hw (by simp) C + (fun _ _ h => by rw [hsrc] at h; cases h) + (by rw [hsrc]; exact ⟨Iff.rfl, fun _ h => h.elim⟩) + ⟨fun h => h.elim, fun _ h => by cases h⟩ G' + end end diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecIpcA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecIpcA.lean index c82d3fd3d..cfc8c2dee 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InvSpecIpcA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecIpcA.lean @@ -220,6 +220,15 @@ theorem IpcScopeA.invSpecA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (lbl := info.label) (len := msgLenA info buf) (buf := buf) hslot hcov hcap hext hSC hp hk hidle hb hkt hs obtain ⟨xc', σ1', -, -, hsp, hspec⟩ := hOut exact sigTail p badge recv σ1' hcap (Prod.mk.inj (okinj (hd.symm.trans hdec))).1 hsp hspec + | @signalRunningVm p badge _ _ _ _ recv _ _ _ _ _ x t xt hCs h1 hmb hmax htu hslot hcov hcap hext hSC hp hk + hidle hb hkt hs => + have hc : m.curCore < fl4A64Platform.numNodes := by + rw [J.sr.sch.core]; exact hCs _ J.sr.sch.cpuCs + obtain ⟨xc, σ1, σ2, s2, -, -, -, -, hdec, -⟩ := + J.signalRunningVmA hA hM hPl hfm hc hmb hmax htu hCs h1 (blk := blk) (call := call) (don := don) (fp := fp) + (lbl := info.label) (len := msgLenA info buf) (buf := buf) hslot hcov hcap hext hSC hp hk hidle hb hkt hs + obtain ⟨xc', σ1', -, -, hsp, hspec⟩ := hOut + exact sigTail p badge recv σ1' hcap (Prod.mk.inj (okinj (hd.symm.trans hdec))).1 hsp hspec | @signalQuiet p badge _ _ _ _ recv _ _ _ _ _ x hcc hmb hmax htu hslot hcov hcap hext hSC hp hk hq => obtain ⟨xc, σ1, σ2, s2, -, -, -, -, hdec, -⟩ := J.signalQuietA hA hM hPl hfm hcc hmb hmax htu (blk := blk) (call := call) (don := don) (fp := fp) diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecL1A.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecL1A.lean index 8ed4614ee..9758fd948 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InvSpecL1A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecL1A.lean @@ -159,6 +159,134 @@ theorem DomScopeA.invSpecA (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPl cases blk <;> cases call <;> cases don <;> rfl rw [run] exact perform_liftThenNilA e2' + | configure slot hsl hcov hcap len buf dur blk call don extra hext hSC hl0 hi0 hd0 hu0 hmax hend => + obtain ⟨σ1, σ2, s2, -, -, hdec, -⟩ := + J.domConfigureA hA hM hPl hfm hsl hcov hcap hext hSC hl0 hi0 hd0 hu0 hmax hend (blk := blk) (call := call) + (don := don) + have hr : r = .Ok () := (Prod.mk.inj (okinj (hd.symm.trans hdec))).1 + have hdn : done = true := by + rcases hdone with ⟨h2, -⟩ | ⟨-, h2⟩ + · exact h2 + · rw [hr] at h2; cases h2 + subst hdn + obtain ⟨σ1', e1', e2'⟩ := hOut + obtain ⟨hlab, argsU, hae, hlen, hargs⟩ := B + have hc2 : CapEqA .Domain c := by rw [← hcap]; exact hc.2 + have ec : c = .domainCap := (show absCapA .Domain = c from hc2).symm + have h3 : 3 ≤ argsU.length := by + rw [← hlen, ← hlnI]; scalar_tac + obtain ⟨y0, y1, y2, rest, rfl⟩ : ∃ y0 y1 y2 rest, argsU = y0 :: y1 :: y2 :: rest := by + match argsU, h3 with + | y0 :: y1 :: y2 :: rest, _ => exact ⟨y0, y1, y2, rest, rfl⟩ + have e0 : y0 = 0#u64 := okinj ((hargs 0#u64 y0 rfl).symm.trans hi0) + have e1 : y1 = 0#u64 := okinj ((hargs 1#u64 y1 rfl).symm.trans hd0) + have e2 : y2 = dur := okinj ((hargs 2#u64 y2 rfl).symm.trans hu0) + subst e0 e1 e2 + have hnd := J.toJStage3A.domOK + have hlen2 : σ.domainList.length = 2 := hnd.len.trans (by + simp [layout.NUM_DOMAIN_SCHEDULES, fl4_abi.config.NUM_DOMAIN_SCHEDULES]) + have hst : y2 = 0#u64 → σ.domainStartIndex ≠ 0 := fun h e => hend h (UScalar.eq_of_val_eq (by + rw [hnd.start, e]; rfl)) + have hg : genInvocationType (specLabelWord (fl4LabelOf mi.miLabel)) = .domainScheduleConfigure := by + rw [hlab, ← hlI] + refine genLabel_specA ?_ + rw [fl4_abi.label.DomainScheduleConfigure] + rfl + have hsp : (decodeDomainInvocation (Z := Unit) (specLabelWord (fl4LabelOf mi.miLabel)) + (((0#u64 : U64) :: 0#u64 :: y2 :: rest).map UScalar.bv) excaps).run σ = + ({(.ok (.invokeDomainScheduleConfigure 0 0 (ucast domainDurationLen y2.bv)), σ)}, False) := by + unfold decodeDomainInvocation + rw [hg] + exact domainConfigure_okA hlen2 rest hmax hst + refine ⟨.invokeDomain (.invokeDomainScheduleConfigure 0 0 (ucast domainDurationLen y2.bv)), σ1', ?_, e1', ?_, + fun h => by first | cases h | simp_all⟩ + · rw [hae, ec] + have : fl4DecodeInvocation (Z := Unit) call false mi.miLabel + (((0#u64 : U64) :: 0#u64 :: y2 :: rest).map UScalar.bv) cptr sl .domainCap excaps buffer = + Fl4Spec.NonDetE.liftME Fl4Invocation.invokeDomain (decodeDomainInvocation + (specLabelWord (fl4LabelOf mi.miLabel)) (((0#u64 : U64) :: 0#u64 :: y2 :: rest).map UScalar.bv) + excaps) := rfl + rw [this, run_liftME_okA hsp] + exact rfl + · unfold PerfSpecA + rw [if_pos rfl] + refine ⟨[], Or.inl ⟨?_, fun _ _ _ => rfl⟩⟩ + have run : fl4PerformInvocation (Z := Unit) blk call don + (.invokeDomain (.invokeDomainScheduleConfigure 0 0 (ucast domainDurationLen y2.bv))) = + Fl4Spec.NonDetE.liftE (do + invokeDomain (Z := Unit) (.invokeDomainScheduleConfigure 0 0 (ucast domainDurationLen y2.bv)) + return ([] : List Data)) := by + cases blk <;> cases call <;> cases don <;> rfl + rw [run] + exact perform_liftThenNilA e2' + | setStart slot hsl hcov hcap len buf idx w blk call don extra hext hSC hl0 hi0 hidx hw hw0 => + obtain ⟨σ1, σ2, s2, -, -, hdec, -⟩ := + J.domSetStartA hA hM hPl hfm hsl hcov hcap hext hSC hl0 hi0 hidx hw hw0 (blk := blk) (call := call) (don := don) + have hr : r = .Ok () := (Prod.mk.inj (okinj (hd.symm.trans hdec))).1 + have hdn : done = true := by + rcases hdone with ⟨h2, -⟩ | ⟨-, h2⟩ + · exact h2 + · rw [hr] at h2; cases h2 + subst hdn + obtain ⟨σ1', e1', e2'⟩ := hOut + obtain ⟨hlab, argsU, hae, hlen, hargs⟩ := B + have hc2 : CapEqA .Domain c := by rw [← hcap]; exact hc.2 + have ec : c = .domainCap := (show absCapA .Domain = c from hc2).symm + have h1 : 1 ≤ argsU.length := by + rw [← hlen, ← hlnI]; scalar_tac + obtain ⟨y0, rest, rfl⟩ : ∃ y0 rest, argsU = y0 :: rest := by + match argsU, h1 with + | y0 :: rest, _ => exact ⟨y0, rest, rfl⟩ + have e0 : y0 = idx := okinj ((hargs 0#u64 y0 rfl).symm.trans hi0) + subst e0 + have hnd := J.toJStage3A.domOK + have two : (layout.NUM_DOMAIN_SCHEDULES).val = 2 := by + simp [layout.NUM_DOMAIN_SCHEDULES, fl4_abi.config.NUM_DOMAIN_SCHEDULES] + have hlen2 : σ.domainList.length = 2 := hnd.len.trans two + have hlt : y0.val < 2 := by + have : y0.val < layout.NUM_DOMAIN_SCHEDULES.val := hidx + omega + have hne : Fl4SpecA64.the σ.domainList[y0.val]? ≠ domainEndMarker := by + obtain ⟨p, d, w', hp, -, hw', r1, -, -⟩ := hnd.table y0 hidx + have ew : w' = w := okinj (r1.symm.trans hw) + rw [hp] + intro h + have hp2 : p.2 = 0 := by + have h' : p = domainEndMarker := h + rw [h']; rfl + apply hw0 + rw [← ew] + apply UScalar.eq_of_val_eq + have := congrArg BitVec.toNat hw' + rw [hp2] at this + exact this + have hg : genInvocationType (specLabelWord (fl4LabelOf mi.miLabel)) = .domainScheduleSetStart := by + rw [hlab, ← hlI] + refine genLabel_specA ?_ + rw [fl4_abi.label.DomainScheduleSetStart] + rfl + have hsp : (decodeDomainInvocation (Z := Unit) (specLabelWord (fl4LabelOf mi.miLabel)) + ((y0 :: rest).map UScalar.bv) excaps).run σ = ({(.ok (.invokeDomainScheduleSetStart y0.val), σ)}, False) := by + unfold decodeDomainInvocation + rw [hg] + exact domainSetStart_okA hlen2 rest hlt hne + refine ⟨.invokeDomain (.invokeDomainScheduleSetStart y0.val), σ1', ?_, e1', ?_, + fun h => by first | cases h | simp_all⟩ + · rw [hae, ec] + have : fl4DecodeInvocation (Z := Unit) call false mi.miLabel ((y0 :: rest).map UScalar.bv) cptr sl .domainCap + excaps buffer = Fl4Spec.NonDetE.liftME Fl4Invocation.invokeDomain (decodeDomainInvocation + (specLabelWord (fl4LabelOf mi.miLabel)) ((y0 :: rest).map UScalar.bv) excaps) := rfl + rw [this, run_liftME_okA hsp] + exact rfl + · unfold PerfSpecA + rw [if_pos rfl] + refine ⟨[], Or.inl ⟨?_, fun _ _ _ => rfl⟩⟩ + have run : fl4PerformInvocation (Z := Unit) blk call don (.invokeDomain (.invokeDomainScheduleSetStart y0.val)) = + Fl4Spec.NonDetE.liftE (do invokeDomain (Z := Unit) (.invokeDomainScheduleSetStart y0.val) + return ([] : List Data)) := by + cases blk <;> cases call <;> cases don <;> rfl + rw [run] + exact perform_liftThenNilA e2' end diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcb3A.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcb3A.lean index 10d92a737..82dda9210 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcb3A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcb3A.lean @@ -9,6 +9,8 @@ Per arm: the spec decode of the actual thread cap, label, message words and extr Named premises: those of the arms. New module. -/ import Fl4ProofsA64.P3.Stage3InvSpecTcb2A +import Fl4ProofsA64.P3.Stage3TcbSchedScA +import Fl4ProofsA64.P3.Stage3InvSpecTcbPerfA import Fl4ProofsA64.P3.TcbInvokeTimeoutA import Fl4ProofsA64.P3.TcbInvokeSchedSelectA import Fl4ProofsA64.P3.ScBindTopA @@ -21,12 +23,6 @@ open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp F noncomputable section -/-- A null-cap install is the deletion alone: neither the invoked slot nor the source slot matters. -/ -theorem fl4InstallTcbCap_nullA (t : ObjRef) (κ κ' a b : CslotPtr) (n : Nat) : - fl4InstallTcbCap (Z := Unit) t κ n (some (.nullCap, a)) = fl4InstallTcbCap t κ' n (some (.nullCap, b)) := by - unfold fl4InstallTcbCap - simp [NonDetE.unlessE] - /-- A valid FL4 fault handler is represented by its abstract cap, which is a valid spec handler. -/ theorem tcbHandlerA {c : capability.Cap} {y : Fl4SpecA64.Cap} (h : CapRelA c y) (hv : faults.valid_fault_handler c = ok true) : absCapA c = y ∧ validFaultHandler y := by @@ -103,10 +99,10 @@ theorem JSyscallA.tcbSetIpcBufZero_invSpecA (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBSetIPCBuffer) (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok src)) (harg : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok 0#u64) - {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) - (hperf : ∀ κs : CslotPtr, (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none - (some (Fl4SpecA64.dataToVref (0#u64).bv, none)))).run σ1).1) (cptr : CapRef) : - InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + {σ1 : State Unit} {eo : Except Unit (List Data)} {done : Bool} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : ∀ κs : CslotPtr, (eo, σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none + (some (Fl4SpecA64.dataToVref (0#u64).bv, none)))).run σ1).1) (hdn : TcbDoneA done eo σ') (cptr : CapRef) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc obtain ⟨hex, hn, -⟩ := tcbExtraAtA (st := st) hx (by simp) he have hl1 : 1 ≤ len.val := by scalar_tac @@ -115,9 +111,9 @@ theorem JSyscallA.tcbSetIpcBufZero_invSpecA have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbSetIPCBuffer) := by rw [hlbl, fl4_abi.label.TCBSetIPCBuffer]; rfl obtain ⟨hl, hg⟩ := tcbLabel_genA hlab e - refine InvSpecA.ofTcbNil (i := .threadControlCaps (specPtr t) sl none none none none + refine InvSpecA.ofTcbNilE (i := .threadControlCaps (specPtr t) sl none none none none (some (Fl4SpecA64.dataToVref (0#u64).bv, none))) ?_ hsp - (by cases blk <;> cases call <;> cases don <;> rfl) (hperf sl) + (by cases blk <;> cases call <;> cases don <;> rfl) (hperf sl) hdn rw [ec] refine tcbDec_genA hl rfl hg fun h => ?_ unfold decodeTcbInvocation @@ -145,10 +141,10 @@ theorem JSyscallA.tcbSetTimeoutNull_invSpecA (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBSetTimeoutEndpoint) (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 0#u64 = ok (.Ok src)) (hnullh : capA st s src = .Null) - {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) - (hperf : ∀ κs : CslotPtr, (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none - (some (.nullCap, κsrc)) none none none)).run σ1).1) (cptr : CapRef) : - InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + {σ1 : State Unit} {eo : Except Unit (List Data)} {done : Bool} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : ∀ κs : CslotPtr, (eo, σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none + (some (.nullCap, κsrc)) none none none)).run σ1).1) (hdn : TcbDoneA done eo σ') (cptr : CapRef) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc obtain ⟨hex, -, es⟩ := tcbExtraAtA (st := st) hx (by simp) he simp only [UScalar.ofNatCore_val_eq] at hex es @@ -163,13 +159,13 @@ theorem JSyscallA.tcbSetTimeoutNull_invSpecA have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbSetTimeoutEndpoint) := by rw [hlbl, fl4_abi.label.TCBSetTimeoutEndpoint]; rfl obtain ⟨hl, hg⟩ := tcbLabel_genA hlab e - have hp : (.ok [], σ') ∈ ((fl4InvokeTcb (Z := Unit) (.threadControlCaps (specPtr t) sl none + have hp : (eo, σ') ∈ ((fl4InvokeTcb (Z := Unit) (.threadControlCaps (specPtr t) sl none (some (.nullCap, y0.2)) none none none)).run σ1).1 := by have h := hperf sl simp only [fl4InvokeTcb] at h ⊢ rwa [fl4InstallTcbCap_nullA (specPtr t) sl sl κsrc y0.2 4] at h - refine InvSpecA.ofTcbNil (i := .threadControlCaps (specPtr t) sl none (some (.nullCap, y0.2)) none none none) - ?_ hsp (by cases blk <;> cases call <;> cases don <;> rfl) hp + refine InvSpecA.ofTcbNilE (i := .threadControlCaps (specPtr t) sl none (some (.nullCap, y0.2)) none none none) + ?_ hsp (by cases blk <;> cases call <;> cases don <;> rfl) hp hdn rw [ec] refine tcbDec_genA hl rfl hg fun h => ?_ unfold decodeTcbInvocation @@ -201,10 +197,10 @@ theorem JSyscallA.tcbSetTimeoutNonNull_invSpecA (hsl : slot = cslotAddrA sl) (hab : AbsSlotA Z.th sl) (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) - {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) - (hperf : (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none - (some (absCapA (capA st s src), κsrc)) none none none)).run σ1).1) (cptr : CapRef) : - InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + {σ1 : State Unit} {eo : Except Unit (List Data)} {done : Bool} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (eo, σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none + (some (absCapA (capA st s src), κsrc)) none none none)).run σ1).1) (hdn : TcbDoneA done eo σ') (cptr : CapRef) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc obtain ⟨hex, -, es⟩ := tcbExtraAtA (st := st) hx (by simp) he simp only [UScalar.ofNatCore_val_eq] at hex es @@ -224,8 +220,8 @@ theorem JSyscallA.tcbSetTimeoutNonNull_invSpecA have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbSetTimeoutEndpoint) := by rw [hlbl, fl4_abi.label.TCBSetTimeoutEndpoint]; rfl obtain ⟨hl, hg⟩ := tcbLabel_genA hlab e - refine InvSpecA.ofTcbNil (i := .threadControlCaps (specPtr t) κs none (some y0) none none none) - ?_ hsp (by cases blk <;> cases call <;> cases don <;> rfl) hperf + refine InvSpecA.ofTcbNilE (i := .threadControlCaps (specPtr t) κs none (some y0) none none none) + ?_ hsp (by cases blk <;> cases call <;> cases don <;> rfl) hperf hdn rw [ec] refine tcbDec_genA hl rfl hg fun h => ?_ unfold decodeTcbInvocation @@ -306,12 +302,12 @@ theorem JSyscallA.tcbSetIpcBuf_invSpecA (hsl : slot = cslotAddrA sl) (hab : AbsSlotA Z.th sl) (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) - {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) - (hperf : (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none + {σ1 : State Unit} {eo : Except Unit (List Data)} {done : Bool} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (eo, σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none (some (Fl4SpecA64.dataToVref baddr.bv, some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), κsrc))))).run σ1).1) - (cptr : CapRef) : - InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + (hdn : TcbDoneA done eo σ') (cptr : CapRef) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc obtain ⟨hex, hlen1, es⟩ := tcbExtraAtA (st := st) hx (by simp) he simp only [UScalar.ofNatCore_val_eq] at hex es @@ -336,10 +332,10 @@ theorem JSyscallA.tcbSetIpcBuf_invSpecA have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbSetIPCBuffer) := by rw [hlbl, fl4_abi.label.TCBSetIPCBuffer]; rfl obtain ⟨hl, hg⟩ := tcbLabel_genA hlab e - refine InvSpecA.ofTcbNil (i := .threadControlCaps (specPtr t) κs none none none none + refine InvSpecA.ofTcbNilE (i := .threadControlCaps (specPtr t) κs none none none none (some (Fl4SpecA64.dataToVref baddr.bv, some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), y0.2)))) ?_ hsp - (by cases blk <;> cases call <;> cases don <;> rfl) hperf + (by cases blk <;> cases call <;> cases don <;> rfl) hperf hdn rw [ec] refine tcbDec_genA hl rfl hg fun h => ?_ unfold decodeTcbInvocation @@ -366,19 +362,20 @@ theorem JSyscallA.tcbSetIpcBuf_invSpecA simp only [ndE_pure_bindA] rfl -/-- `decode_update_sc` of an accepted `sched_params_sc` that keeps the target's SC: no SC change. -/ -theorem JSyscallA.tcbUpdateScKeepA +/-- `decode_update_sc` of an accepted `sched_params_sc`: the SC change it decodes (`none` when the SC is kept, +`some none` for a detach, `some (some sc)` for a bind). -/ +theorem JSyscallA.tcbUpdateScA (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) {scSlot v : U64} {y : Cap} (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hOS : scSlot ≠ 0#u64 → scSlot ∈ OS) (hnz : scSlot ≠ 0#u64) (hy : CapRelA (capA st s scSlot) y) - (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hold : obj.Tcb.sc st t s = ok v) - (hne : t ≠ L.curW s) : - (decodeUpdateSc (Z := Unit) (.threadCap (specPtr t)) sl y).run σ = ({(.ok none, σ)}, False) := by + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) : + (decodeUpdateSc (Z := Unit) (.threadCap (specPtr t)) sl y).run σ = + ({(.ok (scUpdC (L.mem s (scA t)) v), σ)}, False) := by have htT : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap obtain ⟨u, hk, hks⟩ := J.sr.sch.tcb t htT + have hold : obj.Tcb.sc st t s = ok (L.mem s (scA t)) := eq_of_spec_fd (obj.Tcb.sc.spec (L := L) s t) have hbl := Sched.bind_isBlockedA (st := st) (J.stEqA _ htT u hk) have hcur : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread - have hv : v = L.mem s (scA t) := ok_inj_ff (hold.symm.trans (eq_of_spec_fd (obj.Tcb.sc.spec (L := L) s t))) have htcb : (Fl4Spec.NonDetE.liftE (getTcbObjRef Fl4SpecA64.Tcb.tcbSchedContext (specPtr t)) : Fl4SpecA64.SEMonad Unit _).run σ = ({(.ok u.tcbSchedContext, σ)}, False) := run_liftEA (threadGet_eqSc Fl4SpecA64.Tcb.tcbSchedContext hk) @@ -389,9 +386,12 @@ theorem JSyscallA.tcbUpdateScKeepA rw [h0] at e exact e.symm subst ey + have hne : t ≠ L.curW s := fun hc => by + rw [tcbSchedParamsSc_nullA (h0 ▸ hcapA), if_pos hc] at hsc + cases ok_inj_ff hsc rw [tcbSchedParamsSc_nullA (h0 ▸ hcapA), if_neg hne] at hsc have v0 : v = 0#u64 := (core.result.Result.Ok.inj (ok_inj_ff hsc)).symm - have hn : u.tcbSchedContext = none := by rw [hks, ← hv, v0, optScA, if_pos rfl] + subst v0 have hct : (Fl4Spec.NonDetE.liftE (Fl4Spec.NonDet.gets fun s : Fl4SpecA64.State Unit => s.curThread) : Fl4SpecA64.SEMonad Unit _).run σ = ({(.ok σ.curThread, σ)}, False) := run_liftEA rfl unfold decodeUpdateSc @@ -402,8 +402,13 @@ theorem JSyscallA.tcbUpdateScKeepA rw [show Fl4Spec.NonDetE.whenE (σ := Fl4SpecA64.State Unit) (specPtr t = σ.curThread) (Fl4Spec.NonDetE.throwError Fl4SpecA64.SyscallError.illegalOperation) = pure () from if_neg (by rw [hcur]; exact fun c => hne (specPtr_inj c)), ndE_pure_bindA] - simp only [ndE_pure_bindA, hn, ne_eq, not_true_eq_false, ↓reduceIte] - rfl + by_cases ho : L.mem s (scA t) = 0#u64 + · have hn : u.tcbSchedContext = none := by rw [hks, ho, optScA, if_pos rfl] + simp only [ndE_pure_bindA, hn, ne_eq, not_true_eq_false, ↓reduceIte, scUpdC, ho] + rfl + · have hn : u.tcbSchedContext ≠ none := by rw [hks, optScA, if_neg ho]; exact fun h => by cases h + simp only [ndE_pure_bindA, ne_eq, hn, not_false_eq_true, ↓reduceIte, scUpdC, ho] + rfl by_cases hS : ∃ p b, capA st s scSlot = .SchedContext p b swap · have hk' : ∀ p b, capA st s scSlot ≠ .SchedContext p b := fun p b c => hS ⟨p, b, c⟩ @@ -416,7 +421,7 @@ theorem JSyscallA.tcbUpdateScKeepA have hni : specPtr p ≠ m.idleScOf m.curCore := (J.toJStage3A.toTA J.sact J.noSwitch).ciSc _ hxO p b hq have hname : scNameA m p = specPtr p := by unfold scNameA; exact if_neg hni have hren : scRenA m p = specPtr p := by unfold scRenA; exact if_neg hni - obtain ⟨z, k, hz, -⟩ := J.sr.scr.sc p hp + obtain ⟨z, k, hz, hzr⟩ := J.sr.scr.sc p hp have hrel := Sched.bind_scReleasedA J.sr.toSchedSRN hp hz rw [hname] at hz have hgr := tcbGetScReleasedA hz (J.sr.inv.ne hz) @@ -450,26 +455,26 @@ theorem JSyscallA.tcbUpdateScKeepA · rw [hrl] at h simp only [ite_true] at h exact ⟨(core.result.Result.Ok.inj (ok_inj_ff h)).symm, fun c => c.2 rfl⟩ - have hvp : v = p ∧ ¬ (ipcQueuedThreadState u.tcbState = true ∧ ¬ scReleased σ.curTime z = true) := by - by_cases h1 : v = p + have hvp : v = p ∧ ¬ (ipcQueuedThreadState u.tcbState = true ∧ ¬ scReleased σ.curTime z = true) ∧ + (L.mem s (scA t) = p ∨ (L.mem s (scA t) = 0#u64 ∧ z.scTcb = none)) := by + by_cases h1 : L.mem s (scA t) = p · rw [if_pos h1] at hsc - exact rel hsc + exact ⟨(rel hsc).1, (rel hsc).2, Or.inl h1⟩ rw [if_neg h1] at hsc - by_cases h2 : v = 0#u64 - · rw [if_pos h2] at hsc - rw [show obj.Sc.tcb st p s = ok (L.mem s (scTcbA p)) from eq_of_spec_fd (obj.Sc.tcb.spec (L := L) s p), + by_cases h2 : L.mem s (scA t) = 0#u64 + · rw [if_pos h2, show obj.Sc.tcb st p s = ok (L.mem s (scTcbA p)) from eq_of_spec_fd (obj.Sc.tcb.spec (L := L) s p), bind_ok] at hsc split at hsc - · exact rel hsc + · rename_i hb0 + exact ⟨(rel hsc).1, (rel hsc).2, Or.inr ⟨h2, by rw [hzr.tcb, ← scTcbA_eqSc, hb0, optRefS_zero]⟩⟩ · simp only [error.illegal] at hsc cases ok_inj_ff hsc · rw [if_neg h2] at hsc simp only [error.illegal] at hsc cases ok_inj_ff hsc - obtain ⟨vp, hB⟩ := hvp - have hsome : u.tcbSchedContext = some (specPtr p) := by - rw [hks, ← hv, vp, optScA, if_neg (J.scNZ p hp), hren] - have hsct : getScObjRef (Z := Unit) Fl4SpecA64.SchedContext.scTcb (specPtr p) σ = ({(z.scTcb, σ)}, False) := by + obtain ⟨vp, hB, hch⟩ := hvp + subst vp + have hsct : getScObjRef (Z := Unit) Fl4SpecA64.SchedContext.scTcb (specPtr v) σ = ({(z.scTcb, σ)}, False) := by unfold getScObjRef rw [nd_bind_oneSc (Sched.getSchedContext_eqA hz)] rfl @@ -479,22 +484,31 @@ theorem JSyscallA.tcbUpdateScKeepA show (getThreadState (Z := Unit) (specPtr t) >>= fun x => pure (ipcQueuedThreadState x)) σ = _ rw [nd_bind_oneSc h] rfl - have hst : (Fl4Spec.NonDetE.liftE (getScObjRef Fl4SpecA64.SchedContext.scTcb (specPtr p)) : + have hst : (Fl4Spec.NonDetE.liftE (getScObjRef Fl4SpecA64.SchedContext.scTcb (specPtr v)) : Fl4SpecA64.SEMonad Unit _).run σ = ({(.ok z.scTcb, σ)}, False) := run_liftEA hsct have hib : (Fl4Spec.NonDetE.liftE (isBlocked (specPtr t)) : Fl4SpecA64.SEMonad Unit _).run σ = ({(.ok (ipcQueuedThreadState u.tcbState), σ)}, False) := run_liftEA hibk - have hgr' : (Fl4Spec.NonDetE.liftE (getScReleased (specPtr p)) : Fl4SpecA64.SEMonad Unit _).run σ = + have hgr' : (Fl4Spec.NonDetE.liftE (getScReleased (specPtr v)) : Fl4SpecA64.SEMonad Unit _).run σ = ({(.ok (scReleased σ.curTime z), σ)}, False) := run_liftEA hgr + have hv0 : v ≠ 0#u64 := J.scNZ v hp unfold decodeUpdateSc simp only [Fl4Spec.NonDetE.returnOk, ndE_pure_bindA, show objRefOf (.threadCap (specPtr t)) = specPtr t from rfl] rw [run_bind_okA htcb] try dsimp only dsimp only [objRefOf] rw [run_bind_okA hst] - simp only [NonDetE.whenE, hsome, ne_eq, not_true_eq_false, false_and, ↓reduceIte, ndE_pure_bindA] - rw [run_bind_okA hib, run_bind_okA hgr'] - simp only [hB, ↓reduceIte, ndE_pure_bindA] - rfl + rcases hch with h1 | ⟨h2, hzn⟩ + · have hsome : u.tcbSchedContext = some (specPtr v) := by + rw [hks, h1, optScA, if_neg hv0, hren] + simp only [NonDetE.whenE, hsome, ne_eq, not_true_eq_false, false_and, ↓reduceIte, ndE_pure_bindA] + rw [run_bind_okA hib, run_bind_okA hgr'] + simp only [hB, ↓reduceIte, ndE_pure_bindA, scUpdC, h1] + rfl + · have hnone : u.tcbSchedContext = none := by rw [hks, h2, optScA, if_pos rfl] + simp only [NonDetE.whenE, hnone, hzn, ne_eq, not_true_eq_false, or_self, and_false, ↓reduceIte, ndE_pure_bindA] + rw [run_bind_okA hib, run_bind_okA hgr'] + simp only [hB, ↓reduceIte, ndE_pure_bindA, scUpdC, h2, hv0.symm, hv0, ne_eq, reduceCtorEq, not_false_eq_true] + rfl /-- **The spec decode of SetSchedParams with an unchanged SC**, up to the fault handler's check. -/ theorem JSyscallA.tcbSspDecodeA @@ -510,13 +524,12 @@ theorem JSyscallA.tcbSspDecodeA (hprio : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok prio) (harg : authSlot ∈ OS) (hac : capA st s authSlot = .Thread auth) (hle1 : ¬ L.mem s (mcpA auth) < mcp) (hle2 : ¬ L.mem s (mcpA auth) < prio) - (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hold : obj.Tcb.sc st t s = ok v) - (hne : t ≠ L.curW s) : + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) : ∃ y : Cap × CslotPtr, CapRelA (capA st s fhSlot) y.1 ∧ fhSlot = cslotAddrA y.2 ∧ AbsSlotA Z.th y.2 ∧ (validFaultHandler y.1 → (decodeSetSchedParams (Z := Unit) args (.threadCap (specPtr t)) sl excaps).run σ = ({(.ok (.threadControlSched (specPtr t) sl (some y) (some (BitVec.ofNat 8 mcp.val, specPtr auth)) - (some (BitVec.ofNat 8 prio.val, specPtr auth)) none), σ)}, False)) := by + (some (BitVec.ofNat 8 prio.val, specPtr auth)) (scUpdC (L.mem s (scA t)) v)), σ)}, False)) := by have hP := J.j.1.place obtain ⟨-, hn, es0⟩ := tcbExtraAtA (st := st) hx (by simp) he0 obtain ⟨-, -, es1⟩ := tcbExtraAtA (st := st) hx (by simp) he1 @@ -567,7 +580,7 @@ theorem JSyscallA.tcbSspDecodeA have : exAtA extra 1 = extra.val[1]'(by omega) := by simp [exAtA, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem (show 1 < extra.val.length by omega)] rw [es1, this]; exact List.getElem_mem _ - have U := J.tcbUpdateScKeepA (sl := sl) (y := y1.1) hslot hcap (fun h => hext _ hmem h) n1 c1 hsc hold hne + have U := J.tcbUpdateScA (sl := sl) (y := y1.1) hslot hcap (fun h => hext _ hmem h) n1 c1 hsc refine ⟨y2, c2, hx2, ⟨ps, hy1, Or.inl hth⟩, fun hv => ?_⟩ have ha : ¬ args.length < 2 := by omega have h3 : ¬ (y0 :: y1 :: y2 :: ys).length < 3 := by simp @@ -597,30 +610,33 @@ theorem JSyscallA.tcbSspNull_invSpecA (hprio : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok prio) (harg : authSlot ∈ OS) (hac : capA st s authSlot = .Thread auth) (hle1 : ¬ L.mem s (mcpA auth) < mcp) (hle2 : ¬ L.mem s (mcpA auth) < prio) - (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hold : obj.Tcb.sc st t s = ok v) - (hfh : capA st s fhSlot = .Null) (hne : t ≠ L.curW s) - {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) - (hperf : (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs (some (.nullCap, κsrc)) - (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) none)).run σ1).1) - (cptr : CapRef) : - InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) + (hfh : capA st s fhSlot = .Null) + {σ1 : State Unit} {eo : Except Unit (List Data)} {done : Bool} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (eo, σ') ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs (some (.nullCap, κsrc)) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v))).run σ1).1) + (hdn : TcbDoneA done eo σ') (cptr : CapRef) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc obtain ⟨y, cy, -, -, hdec⟩ := J.tcbSspDecodeA (sl := sl) hslot hcap hx B hlnI hext he0 he1 he2 hmcp hprio harg hac - hle1 hle2 hsc hold hne + hle1 hle2 hsc rw [hfh] at cy have ey : y.1 = .nullCap := (show absCapA .Null = y.1 from cy.2).symm have ep : y = (.nullCap, y.2) := Prod.ext ey rfl have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbSetSchedParams) := by rw [hlbl, fl4_abi.label.TCBSetSchedParams]; rfl obtain ⟨hl, hg⟩ := tcbLabel_genA hlab e - have hp : (.ok [], σ') ∈ ((fl4InvokeTcb (Z := Unit) (.threadControlSched (specPtr t) sl (some y) - (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) none)).run σ1).1 := by + have hp : (eo, σ') ∈ ((fl4InvokeTcb (Z := Unit) (.threadControlSched (specPtr t) sl (some y) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v))).run σ1).1 := by rw [ep] simp only [fl4InvokeTcb] at hperf ⊢ rwa [fl4InstallTcbCap_nullA (specPtr t) κs sl κsrc y.2 3] at hperf - refine InvSpecA.ofTcbNil (i := .threadControlSched (specPtr t) sl (some y) - (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) none) ?_ hsp - (by cases blk <;> cases call <;> cases don <;> rfl) hp + refine InvSpecA.ofTcbNilE (i := .threadControlSched (specPtr t) sl (some y) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v)) ?_ hsp + (by cases blk <;> cases call <;> cases don <;> rfl) hp hdn rw [ec] refine tcbDec_genA hl rfl hg fun h => ?_ unfold decodeTcbInvocation @@ -642,20 +658,21 @@ theorem JSyscallA.tcbSspEp_invSpecA (hprio : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok prio) (harg : authSlot ∈ OS) (hac : capA st s authSlot = .Thread auth) (hle1 : ¬ L.mem s (mcpA auth) < mcp) (hle2 : ¬ L.mem s (mcpA auth) < prio) - (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hold : obj.Tcb.sc st t s = ok v) - (hValid : faults.valid_fault_handler (capA st s fhSlot) = ok true) (hne : t ≠ L.curW s) + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) + (hValid : faults.valid_fault_handler (capA st s fhSlot) = ok true) (hsl : slot = cslotAddrA sl) (hab : AbsSlotA Z.th sl) (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = fhSlot) - {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) - (hperf : (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs + {σ1 : State Unit} {eo : Except Unit (List Data)} {done : Bool} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (eo, σ') ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs (some (absCapA (capA st s fhSlot), κsrc)) - (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) none)).run σ1).1) - (cptr : CapRef) : - InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v))).run σ1).1) + (hdn : TcbDoneA done eo σ') (cptr : CapRef) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc obtain ⟨y, cy, hys, hya, hdec⟩ := J.tcbSspDecodeA (sl := sl) hslot hcap hx B hlnI hext he0 he1 he2 hmcp hprio harg - hac hle1 hle2 hsc hold hne + hac hle1 hle2 hsc obtain ⟨ey, hv⟩ := tcbHandlerA cy hValid have eκ : κs = sl := cslotAddrA_inj J.j.1.place hAκ hab (hκ.trans hsl) have eκs : κsrc = y.2 := cslotAddrA_inj J.j.1.place hAsrc hya (hκsrc.trans hys) @@ -663,9 +680,10 @@ theorem JSyscallA.tcbSspEp_invSpecA have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbSetSchedParams) := by rw [hlbl, fl4_abi.label.TCBSetSchedParams]; rfl obtain ⟨hl, hg⟩ := tcbLabel_genA hlab e - refine InvSpecA.ofTcbNil (i := .threadControlSched (specPtr t) sl (some y) - (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) none) ?_ hsp - (by cases blk <;> cases call <;> cases don <;> rfl) hperf + refine InvSpecA.ofTcbNilE (i := .threadControlSched (specPtr t) sl (some y) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v)) ?_ hsp + (by cases blk <;> cases call <;> cases don <;> rfl) hperf hdn rw [ec] refine tcbDec_genA hl rfl hg fun h => ?_ unfold decodeTcbInvocation diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbBufDecA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbBufDecA.lean new file mode 100644 index 000000000..d1b01b69a --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbBufDecA.lean @@ -0,0 +1,63 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP3): **the spec's buffer decode of SetIPCBuffer / Configure**, as lemmas on their own +(`decodeSetIpcBuffer` of one address word and one extra cap): address 0 (no cap), and a non-zero 1024-aligned address with +a native non-device Frame source. They are the cut-outs of `tcbSetIpcBufZero_invSpecA` / `tcbSetIpcBuf_invSpecA`'s inline +computations, so that the Configure `InvSpec` (`tcbConfigure_invSpecA`'s hypothesis `hbd`) can use them. + +New module; no premise. +-/ +import Fl4ProofsA64.P3.Stage3InvSpecTcbCfgA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical Fl4ProofsA64.P3.ReplyErr + +noncomputable section + +theorem bufDecZeroA {σ : State Unit} {t : ObjRef} {sl : CslotPtr} (y : Cap × CslotPtr) : + (decodeSetIpcBuffer (Z := Unit) [(0#u64 : U64).bv] (.threadCap t) sl [y]).run σ = + ({(.ok (.threadControlCaps t sl none none none none (some (Fl4SpecA64.dataToVref (0#u64 : U64).bv, none))), σ)}, + False) := by + unfold decodeSetIpcBuffer + have hz : Fl4SpecA64.dataToVref (0#u64 : U64).bv = 0 := rfl + have ha : ¬ ([(0#u64 : U64).bv] : List Data).length = 0 := by simp + have hx0 : ¬ ([y] : List (Cap × CslotPtr)).length = 0 := by simp + simp only [ha, hx0, NonDetE.whenE, ↓reduceIte, NonDetE.returnOk, ndE_pure_bindA, List.getElem?_cons_zero] + dsimp only [Fl4SpecA64.the, Option.getD_some] + simp only [hz, ↓reduceIte, ndE_pure_bindA] + rfl + + +theorem bufDecNzA {σ : State Unit} {t : ObjRef} {sl : CslotPtr} {ptr rights asid va baddr : U64} + {size : capability.FrameSize} {mp ep : Bool} (y : Cap × CslotPtr) + (hy : absCapA (.Frame ptr size rights false mp ep asid va) = y.1) (hbn : baddr ≠ 0#u64) + (hbal : baddr.val % 1024 = 0) : + (decodeSetIpcBuffer (Z := Unit) [baddr.bv] (.threadCap t) sl [y]).run σ = + ({(.ok (.threadControlCaps t sl none none none none (some (Fl4SpecA64.dataToVref baddr.bv, + some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), y.2)))), σ)}, False) := by + unfold decodeSetIpcBuffer + have ha : ¬ ([baddr.bv] : List Data).length = 0 := by simp + have hx0 : ¬ ([y] : List (Cap × CslotPtr)).length = 0 := by simp + have hz : ¬ Fl4SpecA64.dataToVref baddr.bv = 0 := fun h0 => hbn (UScalar.eq_of_val_eq (by + have := congrArg BitVec.toNat h0 + simpa [Fl4SpecA64.dataToVref] using this)) + have hder := deriveFrameSpecA σ y.2 ptr rights asid va size mp ep + rw [hy] at hder + have hchk : (checkValidIpcBuffer (Z := Unit) (Fl4SpecA64.dataToVref baddr.bv) + (absCapA (.Frame ptr size rights false false false 0#u64 0#u64))).run σ = ({(.ok (), σ)}, False) := by + show (checkValidIpcBuffer (Z := Unit) baddr.bv _).run σ = _ + rw [tcbBufferCheck_specA] + simp [bufAligned_ofModA baddr hbal] + simp only [ha, hx0, NonDetE.whenE, ↓reduceIte, NonDetE.returnOk, ndE_pure_bindA, List.getElem?_cons_zero] + dsimp only [Fl4SpecA64.the, Option.getD_some] + simp only [hz, ↓reduceIte, ndE_pure_bindA] + simp only [nonDetE_assocBufA] + rw [run_bind_okA hder, run_bind_okA hchk] + simp only [ndE_pure_bindA] + rfl + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbCfgA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbCfgA.lean new file mode 100644 index 000000000..fad734120 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbCfgA.lean @@ -0,0 +1,166 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP3): **`InvSpecA` for Configure** (`TcbScopeA.configure*`). + +The spec decode of the actual thread cap, label, message words and three extra caps (CSpace root, VSpace root, buffer +frame) is `fl4DecodeTcbConfigure`'s: the buffer decode (`decodeSetIpcBuffer`, a hypothesis of the lemma, proved per +buffer variant by its caller) and then the root decode (`roots_valA`, native or Stage-2 branch). + +Named premises: those of the Configure arms. New module. +-/ +import Fl4ProofsA64.P3.Stage3InvSpecTcbSpaceA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical Fl4ProofsA64.P3.ReplyErr + +noncomputable section + +/-- The spec decode of a thread cap under the Configure label. -/ +theorem tcbDec_cfgA {call : Bool} {label : Data} {args : List Data} {cptr : CapRef} {sl : CslotPtr} + {p : ObjRef} {excaps : List (Cap × CslotPtr)} {buffer : Option ObjRef} {σ : State Unit} {i : TcbInvocation} + (hl : fl4LabelOf label = .spec (.genInvocationLabel .tcbConfigure)) + (h : (fl4DecodeTcbConfigure (Z := Unit) args (.threadCap p) sl excaps).run σ = ({(.ok i, σ)}, False)) : + (.ok (Fl4Invocation.invokeTCB i), σ) ∈ + ((fl4DecodeInvocation (Z := Unit) call false label args cptr sl (.threadCap p) excaps buffer).run σ).1 := by + have e : fl4DecodeInvocation (Z := Unit) call false label args cptr sl (.threadCap p) excaps buffer = + fl4DecodeTcbInvocation (fl4LabelOf label) args (.threadCap p) sl excaps buffer := rfl + rw [e, hl] + show (.ok (Fl4Invocation.invokeTCB i), σ) ∈ + ((Fl4Spec.NonDetE.liftME Fl4Invocation.invokeTCB (fl4DecodeTcbConfigure (Z := Unit) args (.threadCap p) sl excaps)).run σ).1 + rw [run_liftME_okA h] + exact Set.mem_singleton _ + +section arm +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} {σ σ' : State Unit} {m : McState} + {call blk don : Bool} {mi : MessageInfo} {sl : CslotPtr} {c : Cap} {excaps : List (Cap × CslotPtr)} + {buffer : Option ObjRef} {args : List Data} {lbl len slot buf t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {info : msginfo.MessageInfo} + +set_option maxHeartbeats 16000000 in +/-- **Configure** (the buffer part is the hypothesis `hbd`, discharged per variant). -/ +theorem JSyscallA.tcbConfigure_invSpecA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {cs vs bs cdata vdata baddr : U64} {ccap vcap : capability.Cap} {κs κcs κvs κbs : CslotPtr} + {p r gs g gs' g' : U64} {bsp : CslotPtr → Option (VSpaceRef × Option (Cap × CslotPtr))} + (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hc : CapRelA (capA st s slot) c) + (hx : ExtraOKA Z.th (L.mem s) extra excaps) (B : ArgsLabA st s info buf mi args) (hlnI : len = msgLenA info buf) + (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBConfigure) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 3#u64 = ok (.Ok cs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 3#u64 = ok (.Ok vs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 3#u64 = ok (.Ok bs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + (hba : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 2#u64 = ok baddr) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hbd : ∀ y2 : Cap × CslotPtr, CapRelA (capA st s bs) y2.1 → + (decodeSetIpcBuffer (Z := Unit) [baddr.bv] (.threadCap (specPtr t)) sl [y2]).run σ = + ({(.ok (.threadControlCaps (specPtr t) sl none none none none (bsp y2.2)), σ)}, False)) + (hsl : slot = cslotAddrA sl) (hab : AbsSlotA Z.th sl) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) + (hAb : AbsSlotA Z.th κbs) (hκb : cslotAddrA κbs = bs) + {σ1 : State Unit} {done : Bool} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : TcbPerfA done σ' ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none + (some (absCapA ccap, κcs)) (some (absCapA vcap, κvs)) (bsp κbs))).run σ1).1) (cptr : CapRef) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by + subst hccap + obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc + have eκ : κs = sl := cslotAddrA_inj J.j.1.place hAκ hab (hκ.trans hsl) + subst eκ + have htT : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + obtain ⟨hex0, hl0, es0⟩ := tcbExtraAtA (st := st) hx (i := 0#usize) (by simp) he0 + obtain ⟨hex1, -, es1⟩ := tcbExtraAtA (st := st) hx (i := 1#usize) (by simp) he1 + obtain ⟨hex2, -, es2⟩ := tcbExtraAtA (st := st) hx (i := 2#usize) (by simp) he2 + simp only [UScalar.ofNatCore_val_eq] at hex0 hex1 hex2 es0 es1 es2 + obtain ⟨y0, y1, y2, ys, rfl⟩ : ∃ y0 y1 y2 ys, excaps = y0 :: y1 :: y2 :: ys := by + match excaps, hex2 with + | y0 :: y1 :: y2 :: ys, _ => exact ⟨y0, y1, y2, ys, rfl⟩ + obtain ⟨-, -, hx0, c0, ps0, hth0, hy0⟩ := srcOK_factsA J.j.1.place (hx.2.1 0 (by simp)) + obtain ⟨-, -, hx1, c1, ps1, hth1, hy1⟩ := srcOK_factsA J.j.1.place (hx.2.1 1 (by simp)) + obtain ⟨-, -, hx2, c2, ps2, hth2, hy2⟩ := srcOK_factsA J.j.1.place (hx.2.1 2 (by simp)) + rw [capAtA_eq (st := st)] at c0 c1 c2 + simp only [List.getElem_cons_zero, List.getElem_cons_succ] at c0 c1 c2 hx0 hx1 hx2 hth0 hth1 hth2 hy0 hy1 hy2 + rw [← es0] at c0 hx0 + rw [← es1] at c1 hx1 + rw [← es2] at c2 hx2 + have eκc : κcs = y0.2 := cslotAddrA_inj J.j.1.place hAc ⟨ps0, hy0, Or.inl hth0⟩ (hκc.trans hx0) + have eκv : κvs = y1.2 := cslotAddrA_inj J.j.1.place hAv ⟨ps1, hy1, Or.inl hth1⟩ (hκv.trans hx1) + have eκb : κbs = y2.2 := cslotAddrA_inj J.j.1.place hAb ⟨ps2, hy2, Or.inl hth2⟩ (hκb.trans hx2) + have hl2 : 2 < len.val := by scalar_tac + obtain ⟨hal, g0'⟩ := tcbArgA B hlnI (i := 0#u64) (by simp; omega) hcd + obtain ⟨-, g1'⟩ := tcbArgA B hlnI (i := 1#u64) (by simp; omega) hvd + obtain ⟨-, g2'⟩ := tcbArgA B hlnI (i := 2#u64) (by simp; omega) hba + obtain ⟨cc, vv, bb, rest, rfl⟩ : ∃ cc vv bb rest, args = cc :: vv :: bb :: rest := by + match args, hal.symm ▸ hl2 with + | cc :: vv :: bb :: rest, _ => exact ⟨cc, vv, bb, rest, rfl⟩ + simp at g0' g1' g2' + subst g0' g1' g2' + have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbConfigure) := by + rw [hlbl, fl4_abi.label.TCBConfigure]; rfl + obtain ⟨hl, -⟩ := tcbLabel_genA hlab e + have hnc1 : isUtA (capA st s cs) = true → NoChildrenRelA (st := st) s σ cs y0.2 := fun h => by + rw [hcc] at h; simp [isUtA] at h + have hnc2 : isUtA (capA st s vs) = true → NoChildrenRelA (st := st) s σ vs y1.2 := fun h => by + rw [hvc] at h + rcases hvk with ⟨p', b, s', r', g'', gr, e'⟩ | ⟨p', r', g'', b, e'⟩ | ⟨p', m', a', e'⟩ | + ⟨p', l, m', ad, v', e'⟩ | ⟨p', m', a', e'⟩ <;> (rw [e'] at h; simp [isUtA] at h) + have hw1 : Fl4Spec.NonDetE.whenE (σ := State Unit) ((cdata.bv :: vdata.bv :: baddr.bv :: rest).length < 3) + (Fl4Spec.NonDetE.throwError SyscallError.truncatedMessage) = pure () := if_neg (by simp) + have hw2 : Fl4Spec.NonDetE.whenE (σ := State Unit) ((y0 :: y1 :: y2 :: ys).length < 3) + (Fl4Spec.NonDetE.throwError SyscallError.truncatedMessage) = pure () := if_neg (by simp) + have e1 : (cdata.bv :: vdata.bv :: baddr.bv :: rest).take 2 = [cdata.bv, vdata.bv] := by simp + have e2 : (y0 :: y1 :: y2 :: ys).take 2 = [(y0.1, y0.2), (y1.1, y1.2)] := by simp + have e3 : (the (y0 :: y1 :: y2 :: ys)[2]?) = y2 := by simp [the] + have e5 : (the (cdata.bv :: vdata.bv :: baddr.bv :: rest)[2]?) = baddr.bv := by simp [the] + have e6 : (the (y0 :: y1 :: y2 :: ys)[1]?) = y1 := by simp [the] + have hbd' := hbd y2 c2 + have hdecS : ∃ zc zv, CapEqA (.CNode p r gs' g') zc ∧ CapEqA vcap zv ∧ + (fl4DecodeTcbConfigure (Z := Unit) (cdata.bv :: vdata.bv :: baddr.bv :: rest) (.threadCap (specPtr t)) κs + (y0 :: y1 :: y2 :: ys)).run σ = + ({(.ok (.threadControlCaps (specPtr t) κs none none (some (zc, y0.2)) (some (zv, y1.2)) (bsp y2.2)), σ)}, + False) := by + have F := J.finStA + have ht : Z.th t = some .tcb := (J.j.1.thT t).2 htT + unfold fl4DecodeTcbConfigure + cases hq : fl4MappedStage2Root y1.1 with + | true => + obtain ⟨zc, zv, hzc, hzv, hrun⟩ := roots_valA (σ := σ) (slot := κs) (rest := []) F ht c0 c1 hnc1 hnc2 hRoots [] + _ (Or.inl rfl) + refine ⟨zc, zv, hzc, hzv, ?_⟩ + rw [if_pos (by rw [e6]; exact hq), hw1, run_bind_okD (a := ()) (s' := σ) rfl, hw2, + run_bind_okD (a := ()) (s' := σ) rfl, e5, e3, run_bind_okD hbd', e1, e2, fl4CvSpace_progA, run_bind_okD hrun] + rfl + | false => + obtain ⟨zc, zv, hzc, hzv, hrun⟩ := roots_valA (σ := σ) (slot := κs) (rest := []) F ht c0 c1 hnc1 hnc2 hRoots [] + _ (Or.inr ⟨rfl, hq⟩) + refine ⟨zc, zv, hzc, hzv, ?_⟩ + rw [if_neg (by rw [e6, hq]; simp)] + unfold decodeTcbConfigure + rw [hw1, run_bind_okD (a := ()) (s' := σ) rfl, hw2, run_bind_okD (a := ()) (s' := σ) rfl, e5, e3] + simp only [Fl4Spec.NonDetE.returnOk, ndE_pure_bindD] + rw [run_bind_okD hbd', e1, e2, decodeCvSpace_progA, run_bind_okD hrun] + rfl + obtain ⟨zc, zv, hzc, hzv, hdecS⟩ := hdecS + have ezc : absCapA (.CNode p r gs' g') = zc := CapEqA.eq_abs hzc (fun _ _ _ e => by cases e) + have ezv : absCapA vcap = zv := by + rcases hvk with ⟨p', b, s', r', g'', gr, e'⟩ | ⟨p', r', g'', b, e'⟩ | ⟨p', m', a', e'⟩ | + ⟨p', l, m', ad, v', e'⟩ | ⟨p', m', a', e'⟩ <;> (subst e'; exact CapEqA.eq_abs hzv (fun _ _ _ e => by cases e)) + rw [eκc, ezc, eκv, ezv, eκb] at hperf + refine InvSpecA.ofTcbNilD (i := .threadControlCaps (specPtr t) κs none none (some (zc, y0.2)) + (some (zv, y1.2)) (bsp y2.2)) ?_ hsp (by cases blk <;> cases call <;> cases don <;> rfl) hperf + rw [ec] + exact tcbDec_cfgA hl hdecS + +end arm + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbHighA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbHighA.lean new file mode 100644 index 000000000..9b40bfb50 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbHighA.lean @@ -0,0 +1,143 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP1): **`InvSpecA` for the SetHighVSpace arms** (`TcbScopeA.setHighVSpaceNull`, +`setHighVSpaceLive`): the spec decode (`decode_set_high_vspace`) of the actual thread cap, label and extra cap has the +invocation the arm's `Out` performs, `Fl4Invocation.invokeSetHighVSpace` (not `invoke_tcb`). + +Named premises: those of the arms. New module. +-/ +import Fl4ProofsA64.P3.Stage3InvSpecTcb3A +import Fl4ProofsA64.P3.Stage3LiftTcbHighA +import Fl4ProofsA64.P3.ExtMapFrA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} {σ σ' : State Unit} {m : McState} + +set_option maxHeartbeats 4000000 in +/-- **SetHighVSpace** (`TcbScopeA.setHighVSpaceNull` / `setHighVSpaceLive`). -/ +theorem JSyscallA.tcbSetHighVSpace_invSpecA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {slot lbl len buf t src : U64} {call blk don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {excaps : List (Cap × CslotPtr)} {c : Cap} {sl : CslotPtr} {mi : MessageInfo} {args : List Data} + {buffer : Option ObjRef} {κs κsrc : CslotPtr} + (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hc : CapRelA (capA st s slot) c) + (hx : ExtraOKA Z.th (L.mem s) extra excaps) + (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBSetHighVSpace) + (he : tcb.extra ⟨len, buf, call, slot, extra⟩ 0#usize = ok (some src)) + (hsrc : setHighVSpaceCapA st s src) + (hsl : slot = cslotAddrA sl) (hab : AbsSlotA Z.th sl) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) + {σ1 : State Unit} {done : Bool} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : TcbHighPerfA done σ' ((invokeSetHighVSpace (Z := Unit) + ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩).run σ1).1) (cptr : CapRef) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by + obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc + have eκ : κs = sl := cslotAddrA_inj J.j.1.place hAκ hab (hκ.trans hsl) + subst eκ + -- the first extra cap is the source + have ex : exAtA extra 0 = src ∧ src ≠ 0#u64 := by + have h0 := (tcbExtraSome_memA he).2 + refine ⟨?_, h0⟩ + have h03 : ¬ (0#usize ≥ 3#usize) := by decide + unfold tcb.extra at he + simp only [h03, ↓reduceIte, exAtA_idx0, bind_ok, obj.Slot.is_null] at he + by_cases h : exAtA extra 0 = 0#u64 + · simp only [h, decide_true, ↓reduceIte] at he + cases ok_inj_ff he + · simp only [h, decide_false, Bool.false_eq_true, ↓reduceIte, bind_ok] at he + exact Option.some.inj (ok_inj_ff he) + have hlt : 0 < excaps.length := Nat.pos_of_ne_zero fun h => ex.2 (ex.1.symm.trans (hx.2.2 0 (by omega) (by omega))) + match excaps, hx, hlt with + | y0 :: ys, hx, _ => + have f := srcOK_factsA J.j.1.place (hx.2.1 0 (by simp)) + obtain ⟨-, -, hx0, c0, ps, hth, hy1⟩ := f + rw [capAtA_eq (st := st)] at c0 + simp only [List.getElem_cons_zero] at c0 hx0 hth hy1 + rw [ex.1] at c0 hx0 + have eκs : κsrc = y0.2 := + cslotAddrA_inj J.j.1.place hAsrc ⟨ps, hy1, Or.inl hth⟩ (hκsrc.trans hx0) + have hl : fl4LabelOf mi.miLabel = .ext .tcbSetHighVSpace := by + rw [hlab, hlbl, fl4_abi.label.TCBSetHighVSpace]; rfl + have ey : y0.1 = absCapA (capA st s src) := by + have h := c0.2 + rcases hsrc with hn | ⟨p, asid, hc', -⟩ + · rw [hn] at h ⊢; exact (CapEqA.eq_abs h (fun _ _ _ e => by cases e)).symm + · rw [hc'] at h ⊢; exact (CapEqA.eq_abs h (fun _ _ _ e => by cases e)).symm + have hdec : (decodeSetHighVSpace (Z := Unit) (specPtr t) κs (y0 :: ys)).run σ = + ({(.ok ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩, σ)}, False) := by + obtain ⟨y, q⟩ := y0 + subst eκs + simp only at ey + subst ey + rcases hsrc with hn | ⟨p, asid, hc', hfind⟩ + · rw [hn] + simp only [decodeSetHighVSpace, absCapA] + rfl + · have h16 : asid.val < 65536 := by + have h := c0.1 + rw [hc'] at h + exact lt_of_lt_of_eq h (by norm_num) + have hf := find_high_asidA (st := st) J.j.1.vs + (fun r hr => let ⟨es, hk, _⟩ := J.j.1.ext.s2root r hr; ⟨es, hk⟩) h16 + rw [hfind, WP.spec_ok] at hf + have hrun := findExtRoot_runX .high (asidOfA asid) σ + have hcatch : (NonDetE.catch (do + let r ← findExtRoot (Z := Unit) .high (asidOfA asid) + NonDetE.returnOk (some r)) (fun _ => pure none)) σ = ({(some (specPtr p), σ)}, False) := by + refine catch_okX (s' := σ) ?_ + rw [run_bind_okD (a := specPtr p) (s' := σ) (by rw [hrun, hf.2])] + rfl + rw [hc'] + simp only [decodeSetHighVSpace, absCapA, asidDataA, ite_true] + have hder : deriveCap (Z := Unit) κsrc + (.archObjectCap (.ext (.highVSpaceCap (specPtr p) (some (asidOfA asid))))) = + NonDetE.returnOk (.archObjectCap (.ext (.highVSpaceCap (specPtr p) (some (asidOfA asid))))) := rfl + rw [run_bind_okD (run_liftE_stD hcatch), unlessE_pos_bindX rfl, hder] + unfold NonDetE.returnOk + rw [ndE_pure_bindD] + rfl + have hD : (.ok (Fl4Invocation.invokeSetHighVSpace ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩), σ) ∈ + ((fl4DecodeInvocation (Z := Unit) call false mi.miLabel args cptr κs (.threadCap (specPtr t)) (y0 :: ys) + buffer).run σ).1 := by + have e : fl4DecodeInvocation (Z := Unit) call false mi.miLabel args cptr κs (.threadCap (specPtr t)) (y0 :: ys) + buffer = fl4DecodeTcbInvocation (fl4LabelOf mi.miLabel) args (.threadCap (specPtr t)) κs (y0 :: ys) + buffer := rfl + have e2 : fl4DecodeTcbInvocation (Z := Unit) (.ext .tcbSetHighVSpace) args (.threadCap (specPtr t)) κs + (y0 :: ys) buffer = NonDetE.liftME Fl4Invocation.invokeSetHighVSpace + (decodeSetHighVSpace (specPtr t) κs (y0 :: ys)) := rfl + rw [e, hl, e2, run_liftME_okA hdec] + exact Set.mem_singleton _ + rw [← ec] at hD + have e : fl4PerformInvocation (Z := Unit) blk call don + (.invokeSetHighVSpace ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩) = + (do invokeSetHighVSpace (Z := Unit) ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩; NonDetE.returnOk []) := rfl + rcases hperf with ⟨rfl, hperf⟩ | ⟨rfl, hperf, pre⟩ + · refine ⟨_, σ1, hD, hsp, ?_, fun h => by cases h⟩ + unfold PerfSpecA + rw [if_pos rfl] + refine ⟨[], Or.inl ⟨?_, fun _ _ _ => rfl⟩⟩ + rw [e] + refine mem_bindE_okD hperf ?_ + rw [run_returnOkD] + exact Set.mem_singleton _ + · refine ⟨_, σ1, hD, hsp, ?_, fun _ => pre⟩ + unfold PerfSpecA + rw [if_neg Bool.false_ne_true, e] + exact mem_bindE_errD hperf + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbPerfA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbPerfA.lean new file mode 100644 index 000000000..33ad45abd --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbPerfA.lean @@ -0,0 +1,63 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP5): **`InvSpecA` of a TCB invocation for either outcome of its perform**. + +`TcbPerfA done σ' R`: the perform's result set `R` (of `fl4InvokeTcb i` run from the restarted state) contains the end state +`σ'` of the invocation, `ok` with `done = true`, or `error` with `done = false` and `PreExitA σ'` (a preempted +perform). `InvSpecA.ofTcbNilD` is `InvSpecA.ofTcbNil` for both. New module; no premise. +-/ +import Fl4ProofsA64.P3.Stage3InvSpecTcbA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +/-- The perform's outcome for `done` (module docstring). -/ +def TcbPerfA (done : Bool) (σ' : State Unit) (R : Set (Except Unit (List Data) × State Unit)) : Prop := + (done = true ∧ (.ok [], σ') ∈ R) ∨ (done = false ∧ (.error (), σ') ∈ R ∧ PreExitA σ') + +/-- `InvSpecA.ofTcbNil` for both outcomes (module docstring). -/ +theorem InvSpecA.ofTcbNilD {blk call don done : Bool} {label : Data} {args : List Data} {cptr : CapRef} {sl : CslotPtr} + {c : Cap} {excaps : List (Cap × CslotPtr)} {buffer : Option ObjRef} {σ σ1 σ' : State Unit} + {i : TcbInvocation} + (hdec : (.ok (Fl4Invocation.invokeTCB i), σ) ∈ + ((fl4DecodeInvocation (Z := Unit) call false label args cptr sl c excaps buffer).run σ).1) + (hset : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hrun : fl4PerformInvocation (Z := Unit) blk call don (.invokeTCB i) = fl4InvokeTcb i) + (hperf : TcbPerfA done σ' ((fl4InvokeTcb (Z := Unit) i).run σ1).1) : + InvSpecA call blk don done label args cptr sl c excaps buffer σ σ' := by + rcases hperf with ⟨rfl, h⟩ | ⟨rfl, h, pre⟩ + · exact InvSpecA.ofTcbNil hdec hset hrun h + · refine ⟨_, σ1, hdec, hset, ?_, fun _ => pre⟩ + unfold PerfSpecA + rw [if_neg Bool.false_ne_true, hrun] + exact h + +/-- The invocation's outcome `e` for `done` (module docstring). -/ +def TcbDoneA (done : Bool) (e : Except Unit (List Data)) (σ' : State Unit) : Prop := + (done = true ∧ e = .ok []) ∨ (done = false ∧ e = .error () ∧ PreExitA σ') + +/-- `InvSpecA.ofTcbNil` for the outcome `e` (module docstring). -/ +theorem InvSpecA.ofTcbNilE {blk call don done : Bool} {label : Data} {args : List Data} {cptr : CapRef} {sl : CslotPtr} + {c : Cap} {excaps : List (Cap × CslotPtr)} {buffer : Option ObjRef} {σ σ1 σ' : State Unit} + {i : TcbInvocation} {e : Except Unit (List Data)} + (hdec : (.ok (Fl4Invocation.invokeTCB i), σ) ∈ + ((fl4DecodeInvocation (Z := Unit) call false label args cptr sl c excaps buffer).run σ).1) + (hset : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hrun : fl4PerformInvocation (Z := Unit) blk call don (.invokeTCB i) = fl4InvokeTcb i) + (hperf : (e, σ') ∈ ((fl4InvokeTcb (Z := Unit) i).run σ1).1) (hdn : TcbDoneA done e σ') : + InvSpecA call blk don done label args cptr sl c excaps buffer σ σ' := by + rcases hdn with ⟨rfl, rfl⟩ | ⟨rfl, rfl, pre⟩ + · exact InvSpecA.ofTcbNilD hdec hset hrun (.inl ⟨rfl, hperf⟩) + · exact InvSpecA.ofTcbNilD hdec hset hrun (.inr ⟨rfl, hperf, pre⟩) + +/-- The preempted-or-done outcome of a `Unit`-valued perform (SetHighVSpace). -/ +def TcbHighPerfA (done : Bool) (σ' : State Unit) (R : Set (Except Unit Unit × State Unit)) : Prop := + (done = true ∧ (.ok (), σ') ∈ R) ∨ (done = false ∧ (.error (), σ') ∈ R ∧ PreExitA σ') + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbPreA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbPreA.lean new file mode 100644 index 000000000..0f1cf41e0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbPreA.lean @@ -0,0 +1,111 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP5): **`TcbPreScopeA.invSpecA`**, `InvSpecA` of the TCB cap-write arms' `Preempted` +outcomes (`done = false`): the arm's `Out` gives the restart, the spec's preempted `invoke_tcb` and `PreExitA`; the arm's +lemma (`tcbSetSpace_invSpecA`, `tcbConfigure_invSpecA`) gives the spec decode of the actual cap, label, words and extra +caps. New module; named premises: those of the arms. +-/ +import Fl4ProofsA64.P3.Stage3InvSpecTcbTopA +import Fl4ProofsA64.P3.Stage3DispTcbPreA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} {s : S} {a : A} {σ : State Unit} {m : McState} + {Clock : A → Fl4SpecA64.MachineState → Prop} + +set_option maxHeartbeats 4000000 in +/-- **The preempted TCB arms' `InvSpecA`** (module docstring). -/ +theorem TcbPreScopeA.invSpecA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) + s a σ m) + (hfm : A64FrameMasks st s) + {lbl len slot : U64} {blk call don fp : Bool} {buf : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {Out : State Unit → Prop} + (h : TcbPreScopeA st AR Z OS ar s a σ Clock lbl len slot blk call don fp buf extra Out) + {r : core.result.Result Unit error.Exc} {s' : S} {a' : A} {σ' : State Unit} + (hd : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don fp buf extra = + ok (r, s', a')) (hOut : Out σ') + {done : Bool} (hdone : (done = true ∧ r = .Ok ()) ∨ (done = false ∧ r = .Err error.Exc.Preempted)) + {info : msginfo.MessageInfo} {mi : MessageInfo} (hlab : mi.miLabel = lbl.bv) {sl : CslotPtr} {c : Cap} + {excaps : List (Cap × CslotPtr)} {buffer : Option ObjRef} {args : List Data} + (hc : CapRelA (capA st s slot) c) (hx : ExtraOKA Z.th (L.mem s) extra excaps) + (B : ArgsLabA st s info buf mi args) (hlnI : len = msgLenA info buf) + (cptr : CapRef) (hsl : slot = cslotAddrA sl) (hab : AbsSlotA Z.th sl) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by + have hdn : done = false := by + obtain ⟨s0, a0, σ0, e0, -⟩ := TcbPreScopeA.soundPre hA hM hPl J hfm h + have e : r = .Err .Preempted := (Prod.mk.inj (okinj (hd.symm.trans e0))).1 + rcases hdone with ⟨-, h2⟩ | ⟨h2, -⟩ + · rw [e] at h2; cases h2 + · exact h2 + subst hdn + cases h with + | setSpacePre hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hfhv hcc hccap hwfc hencc hvc hvk + hvdr hAκ hκ hAf hκf hAc hκc hAv hκv hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, hperf, pre⟩ := hOut + exact J.tcbSetSpace_invSpecA hslot hcap hc hx B hlnI hlab hlbl he0 he1 he2 hcd hvd hRoots hfhv hcc hccap hvc hvk + hsl hab hAκ hκ hAf hκf hAc hκc hAv hκv hsp (.inr ⟨rfl, hperf, pre⟩) cptr + | configureBufZeroPre hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hcc hccap hwfc hencc hvc + hvk hvdr hAκ hκ hAc hκc hAv hκv hAb hκb hba hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, hperf, pre⟩ := hOut + exact J.tcbConfigure_invSpecA (bsp := fun _ => some (Fl4SpecA64.dataToVref (0#u64).bv, none)) hslot hcap hc hx B hlnI + hlab hlbl he0 he1 he2 hcd hvd hba hRoots hcc hccap hvc hvk (fun y _ => bufDecZeroA y) hsl hab hAκ hκ hAc hκc hAv hκv + hAb hκb hsp (.inr ⟨rfl, hperf, pre⟩) cptr + | @configureBufPre baddr ptr rights asid va bits size mp ep _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hcc hccap hwfc hencc hvc hvk + hvdr hAκ hκ hAc hκc hAv hκv hAb hκb hba hbn hbal hsrcF hbits hag hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, hperf, pre⟩ := hOut + exact J.tcbConfigure_invSpecA (bsp := fun y2 => some (Fl4SpecA64.dataToVref baddr.bv, + some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), y2))) hslot hcap hc hx B hlnI + hlab hlbl he0 he1 he2 hcd hvd hba hRoots hcc hccap hvc hvk + (fun y hy => by + rw [hsrcF] at hy + exact bufDecNzA y (CapEqA.eq_abs hy.2 (fun _ _ _ h => by cases h)) hbn hbal) + hsl hab hAκ hκ hAc hκc hAv hκv hAb hκb hsp (.inr ⟨rfl, hperf, pre⟩) cptr + + | setIpcBufZeroPre hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he harg hne hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, pre, hperf⟩ := hOut + exact J.tcbSetIpcBufZero_invSpecA hslot hcap hc hx B hlnI hlab hlbl he harg hsp hperf (.inr ⟨rfl, rfl, pre⟩) cptr + | setIpcBufPre hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he harg hbn hbal hsrcF hbits hag hAκ hκ hAsrc hκsrc + hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, pre, hperf⟩ := hOut + exact J.tcbSetIpcBuf_invSpecA hslot hcap hc hx B hlnI hlab hlbl he harg hbn hbal hsrcF hsl hab hAκ hκ hAsrc hκsrc + hsp hperf (.inr ⟨rfl, rfl, pre⟩) cptr + | setTimeoutNullPre hCnt P hCl hCs h1 hslot hcov hcap hext hlbl he hnullh hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, pre, hperf⟩ := hOut + exact J.tcbSetTimeoutNull_invSpecA hslot hcap hc hx hlab hlbl he hnullh hsp hperf (.inr ⟨rfl, rfl, pre⟩) cptr + | setTimeoutNonNullPre hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he hnn hValid hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, pre, hperf⟩ := hOut + exact J.tcbSetTimeoutNonNull_invSpecA hslot hcap hc hx hlab hlbl he hValid hsl hab hAκ hκ hAsrc hκsrc hsp hperf (.inr ⟨rfl, rfl, pre⟩) cptr + | setSchedParamsNullPre hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 he2 hmcp hprio harg hac + hle1 hle2 hsc hmin hfh hAκ hκ hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, pre, hperf⟩ := hOut + exact J.tcbSspNull_invSpecA hslot hcap hc hx B hlnI hlab hlbl hext he0 he1 he2 hmcp hprio harg hac hle1 hle2 hsc + hfh hsp hperf (.inr ⟨rfl, rfl, pre⟩) cptr + | setSchedParamsEpPre hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 he2 hmcp hprio harg hac + hle1 hle2 hsc hmin hnn hValid hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, pre, hperf⟩ := hOut + exact J.tcbSspEp_invSpecA hslot hcap hc hx B hlnI hlab hlbl hext he0 he1 he2 hmcp hprio harg hac hle1 hle2 hsc + hValid hsl hab hAκ hκ hAsrc hκsrc hsp hperf (.inr ⟨rfl, rfl, pre⟩) cptr + | setHighVSpaceNullPre hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he hn hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, pre, hperf⟩ := hOut + exact J.tcbSetHighVSpace_invSpecA hslot hcap hc hx hlab hlbl he (Or.inl hn) hsl hab hAκ hκ hAsrc hκsrc hsp (.inr ⟨rfl, hperf, pre⟩) cptr + | setHighVSpaceLivePre hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he hcsrc hfind hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, pre, hperf⟩ := hOut + exact J.tcbSetHighVSpace_invSpecA hslot hcap hc hx hlab hlbl he (Or.inr ⟨_, _, hcsrc, hfind⟩) hsl hab hAκ hκ hAsrc + hκsrc hsp (.inr ⟨rfl, hperf, pre⟩) cptr + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbRegsA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbRegsA.lean new file mode 100644 index 000000000..564181b47 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbRegsA.lean @@ -0,0 +1,141 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregr): **`InvSpecA` of TCB ReadRegisters** (`TcbScopeA.readRegsSend`). + +* **`JSyscallA.tcbReadRegs_invSpecA`**: the spec decode of the actual Thread cap and message words (`flags`, `count`) + is `.readRegisters t (testBit flags 0) count ArchDefaultExtraRegisters` (`tcbReadRegisters_selectedSpecA`), and the + arm's `Out` (the perform from the post-`Restart` state, reply `[]`) is the `PerfSpecA` of that invocation. + +Named premises: those of the arm. New module. +-/ +import Fl4ProofsA64.P3.Stage3InvSpecTcb3A +import Fl4ProofsA64.P3.TcbInvokeReadPostA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {J7 : JSlotA S} {s : S} {a : A} {σ σ' : State Unit} {m : McState} + {slot lbl len buf t : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {mi : MessageInfo} {args : List Data} {sl : CslotPtr} {c : Cap} {excaps : List (Cap × CslotPtr)} + {buffer : Option ObjRef} + +/-- A count in `[1, 36]` as bit-vector bounds. -/ +theorem readRegsRangeA {count : U64} (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) : + count.bv ≥ 1 ∧ count.bv ≤ 36 := by + constructor + · show (1 : BitVec 64) ≤ count.bv + rw [BitVec.le_def]; simp; scalar_tac + · rw [BitVec.le_def]; simp; scalar_tac + +/-- **ReadRegisters with the suspension bit `sp`** (the base of `tcbReadRegs_invSpecA` and `tcbReadRegsSusp_invSpecA`). -/ +theorem JSyscallA.tcbReadRegs_invSpecGA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) + {info : msginfo.MessageInfo} {flags count : U64} (sp : Bool) (hbit : testBit flags.bv 0 = sp) + (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hc : CapRelA (capA st s slot) c) + (B : ArgsLabA st s info buf mi args) (hlnI : len = msgLenA info buf) + (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) + {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (.ok [], σ') ∈ ((fl4PerformInvocation blk call don + (.invokeTCB (.readRegisters (specPtr t) sp count.bv ArchDefaultExtraRegisters))).run σ1).1) + (cptr : CapRef) : + InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc + have hl2 : 2 ≤ len.val := by scalar_tac + obtain ⟨hal, g0'⟩ := tcbArgA (call := call) B hlnI (i := 0#u64) (by simp; omega) hf + obtain ⟨-, g1'⟩ := tcbArgA (call := call) B hlnI (i := 1#u64) (by simp; omega) hn + have g0 : args[0]? = some flags.bv := by simpa using g0' + have g1 : args[1]? = some count.bv := by simpa using g1' + obtain ⟨rest, ea⟩ : ∃ rest, args = flags.bv :: count.bv :: rest := by + match args, g0, g1 with + | _ :: _ :: r, g0, g1 => + simp only [List.getElem?_cons_zero, List.getElem?_cons_succ, Option.some.injEq] at g0 g1 + exact ⟨r, by rw [g0, g1]⟩ + have hother : specPtr t ≠ σ.curThread := fun e => + hself (specPtr_inj (e.trans J.j.1.sch.curThread)) + have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbReadRegisters) := by + rw [hlbl, fl4_abi.label.TCBReadRegisters]; rfl + obtain ⟨hl, hg⟩ := tcbLabel_genA hlab e + have hdec : (.ok (Fl4Invocation.invokeTCB (.readRegisters (specPtr t) sp count.bv ArchDefaultExtraRegisters)), σ) + ∈ ((fl4DecodeInvocation (Z := Unit) call false mi.miLabel args cptr sl c excaps buffer).run σ).1 := by + rw [ec] + refine tcbDec_genA hl rfl hg fun h => ?_ + unfold decodeTcbInvocation + rw [h] + dsimp only + rw [ea, ← hbit] + exact tcbReadRegisters_selectedSpecA (readRegsRangeA hlo hhi) hother + refine ⟨_, σ1, hdec, hsp, ?_, fun h => by cases h⟩ + unfold PerfSpecA + rw [if_pos rfl] + exact ⟨[], Or.inl ⟨hperf, fun _ _ _ => rfl⟩⟩ + + +/-- **ReadRegisters (no suspension, `call` the invocation's `Call` flag)** (`TcbScopeA.readRegsSend`, `readRegsCall`). -/ +theorem JSyscallA.tcbReadRegs_invSpecA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) + {info : msginfo.MessageInfo} {flags count : U64} + (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hc : CapRelA (capA st s slot) c) + (B : ArgsLabA st s info buf mi args) (hlnI : len = msgLenA info buf) + (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) (hsuspend : (flags &&& 1#u64) = 0#u64) + {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (.ok [], σ') ∈ ((fl4PerformInvocation blk call don + (.invokeTCB (.readRegisters (specPtr t) false count.bv ArchDefaultExtraRegisters))).run σ1).1) + (cptr : CapRef) : + InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + have hbit : testBit flags.bv 0 = false := by + have h0 : flags.bv &&& 1 = 0 := by + have := congrArg UScalar.bv hsuspend + simpa using this + have h1 : (flags.bv &&& 1).getLsbD 0 = false := by rw [h0]; rfl + simpa [testBit, BitVec.getLsbD_and] using h1 + exact J.tcbReadRegs_invSpecGA false hbit hslot hcap hc B hlnI hlab hlbl hlen hf hn hlo hhi hself hsp hperf cptr + +/-- **ReadRegisters with the suspension bit set** (`TcbScopeA.readRegsSendSusp`, `readRegsCallSusp`). -/ +theorem JSyscallA.tcbReadRegsSusp_invSpecA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) + {info : msginfo.MessageInfo} {flags count : U64} + (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hc : CapRelA (capA st s slot) c) + (B : ArgsLabA st s info buf mi args) (hlnI : len = msgLenA info buf) + (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) (hsuspend : (flags &&& 1#u64) ≠ 0#u64) + {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (.ok [], σ') ∈ ((fl4PerformInvocation blk call don + (.invokeTCB (.readRegisters (specPtr t) true count.bv ArchDefaultExtraRegisters))).run σ1).1) + (cptr : CapRef) : + InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + have hbit : testBit flags.bv 0 = true := by + by_contra hb + have hb' : testBit flags.bv 0 = false := by simpa using hb + have h0 : flags.bv &&& 1 = 0 := by + apply BitVec.eq_of_getLsbD_eq + intro i hi + by_cases hi0 : i = 0 + · subst hi0 + have hb'' : flags.bv.getLsbD 0 = false := hb' + rw [BitVec.getLsbD_and, hb''] + rfl + · simp [BitVec.getLsbD_and, BitVec.getLsbD_one, hi0] + have ueq : ∀ {x y : U64}, x.bv = y.bv → x = y := fun {x y} h => by cases x; cases y; cases h; rfl + exact hsuspend (ueq (by simpa using h0)) + exact J.tcbReadRegs_invSpecGA true hbit hslot hcap hc B hlnI hlab hlbl hlen hf hn hlo hhi hself hsp hperf cptr + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbRegsWA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbRegsWA.lean new file mode 100644 index 000000000..ffb7e0c76 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbRegsWA.lean @@ -0,0 +1,192 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **`InvSpecA` for the TCB WriteRegisters arms** (`TcbScopeA.writeRegs`). + +The spec decode of the actual Thread cap, label and message words (`flags`, `count`, then the register values) has the +invocation `Out` performs: the spec's `values` (`args` from word 2, `count` of them) are the argument words the front +end read from the caller's registers and IPC buffer (`specArgA` at the tracked buffer `sbo`). + +Named premises: those of the arm (`JSyscallA.writeRegsA`). New module. +-/ +import Fl4ProofsA64.P3.Stage3InvSpecTcbA +import Fl4ProofsA64.P3.Stage3InvSpecTcb2A +import Fl4ProofsA64.P3.Stage3TcbRegWriteArmA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +theorem testBit0_of_andA {f : U64} (h : f &&& 1#u64 = 0#u64) : testBit f.bv 0 = false := by + have h1 : f.bv &&& 1#64 = 0#64 := by + have := congrArg UScalar.bv h + simpa [UScalar.bv_and] using this + have h2 := congrArg (fun b : BitVec 64 => b.getLsbD 0) h1 + simpa [BitVec.getLsbD_and] using h2 + +theorem testBit1_of_andA {f : U64} (h : f &&& 2#u64 = 0#u64) : testBit f.bv 1 = false := by + rw [← (tcbCopyRegisters_flagBitsA f).2.1] + simp [h] + +theorem testBit0_of_neA {f : U64} (h : f &&& 1#u64 ≠ 0#u64) : testBit f.bv 0 = true := by + rw [← (tcbCopyRegisters_flagBitsA f).1] + simp [h] + +theorem testBit1_of_neA {f : U64} (h : f &&& 2#u64 ≠ 0#u64) : testBit f.bv 1 = true := by + rw [← (tcbCopyRegisters_flagBitsA f).2.1] + simp [h] + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {J5 J7 : JSlotA S} {s : S} {a : A} {σ σ' : State Unit} {m : McState} + {call blk don : Bool} {mi : MessageInfo} {sl : CslotPtr} {c : Cap} {excaps : List (Cap × CslotPtr)} + {buffer : Option ObjRef} {args : List Data} {lbl len slot buf t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +/-- **WriteRegisters** (`TcbScopeA.writeRegs`). -/ +theorem JSyscallA.tcbWriteRegs_invSpecA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) + {info : msginfo.MessageInfo} {flags count tl : U64} {sbo : Option ObjRef} {xc : Tcb} + (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hc : CapRelA (capA st s slot) c) + (B : ArgsLabA st s info buf mi args) (hlnI : len = msgLenA info buf) + (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBWriteRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok count) + (htail : len - 2#u64 = ok tl) (henough : ¬ tl < count) (hself : t ≠ L.curW s) + {res : Bool} (hres : testBit flags.bv 0 = res) (hlen120 : len.val ≤ 120) + (hBN : sbo = none → buf = 0#u64) + (hBS : ∀ sb, sbo = some sb → (buf, sb) ∈ Bf ∧ buf ≠ 0#u64) + (hkc : σ.kheap σ.curThread = some (.tcb xc)) {σ1 : State Unit} + (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (.ok [], σ') ∈ ((fl4InvokeTcb (.writeRegisters (specPtr t) res + ((List.range count.val).map fun i => + specArgA xc.tcbArch.tcbContext.userRegs sbo σ.machineState.underlyingMemory (i + 2)) + ArchDefaultExtraRegisters)).run σ1).1) (cptr : CapRef) : + InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + obtain ⟨ec, ht, -⟩ := J.tcbTargetA hslot hcap hc + have hl2 : 2 ≤ len.val := by scalar_tac + obtain ⟨hal, g0'⟩ := tcbArgA B hlnI (i := 0#u64) (by simp; omega) hf + obtain ⟨-, g1'⟩ := tcbArgA B hlnI (i := 1#u64) (by simp; omega) hn + have g0 : args[0]? = some flags.bv := by simpa using g0' + have g1 : args[1]? = some count.bv := by simpa using g1' + -- the tail length + obtain ⟨z, hz, hzv⟩ := spec_existsA (UScalar.sub_spec (x := len) (y := 2#u64) (by scalar_tac)) + have hzt : tl = z := ok_inj_ff (htail.symm.trans hz) + subst hzt + have htlv : tl.val = len.val - 2 := by simpa using hzv.1 + have hcle : count.val ≤ tl.val := by + have : ¬ tl.val < count.val := henough + omega + obtain ⟨r, hr⟩ : ∃ r, args = flags.bv :: count.bv :: r := by + rcases args with _ | ⟨a0, _ | ⟨b0, r0⟩⟩ + · simp at hal; omega + · simp at hal; omega + · simp at g0 g1 + exact ⟨r0, by rw [g0, g1]⟩ + have hrl : r.length = tl.val := by rw [hr] at hal; simp at hal; omega + -- the argument words are the spec's + have hct : L.curW s ∈ Z.T := J.sr.curT + have hcur : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have hkc' : σ.kheap (specPtr (L.curW s)) = some (.tcb xc) := hcur ▸ hkc + have hBV' : BufViewA (L.mem s) σ.machineState.underlyingMemory buf sbo := by + cases sbo with + | none => rw [hBN rfl]; exact bufViewA_none _ _ + | some sb => exact J.ep.bufView (hBS sb rfl).1 (hBS sb rfl).2 + have hmr := (J.ep.regView hct xc hkc').2 + have hword : ∀ k, 2 ≤ k → k < len.val → + args[k]? = some (specArgA xc.tcbArch.tcbContext.userRegs sbo σ.machineState.underlyingMemory k) := by + intro k hk2 hk + obtain ⟨-, argsU, hae, hl, hargs⟩ := B + have hlt : k < argsU.length := by rw [← hl, ← hlnI]; exact hk + obtain ⟨y0, hy0⟩ : ∃ y0, argsU[k]? = some y0 := ⟨_, List.getElem?_eq_getElem hlt⟩ + have hkv : (⟨BitVec.ofNat 64 k⟩ : U64).val = k := by + show (BitVec.ofNat 64 k).toNat = k + simp only [BitVec.toNat_ofNat] + exact Nat.mod_eq_of_lt (by have := len.hBounds; simp [U64.size_def, U64.numBits] at this; omega) + have h := hargs ⟨BitVec.ofNat 64 k⟩ y0 (by rw [hkv]; exact hy0) + obtain ⟨x, hx, hxv⟩ := syscall_arg_relA (st := st) hmr hBV' ⟨BitVec.ofNat 64 k⟩ + (by rw [hkv]; omega) + have e : y0 = x := ok_inj_ff (h.symm.trans hx) + subst e + rw [hae, List.getElem?_map, hy0] + exact congrArg some (hxv.trans (by rw [hkv])) + have hvals : r.take count.val = (List.range count.val).map fun i => + specArgA xc.tcbArch.tcbContext.userRegs sbo σ.machineState.underlyingMemory (i + 2) := by + apply List.ext_getElem? + intro i + by_cases hi : i < count.val + · have hk : args[i + 2]? = some (specArgA xc.tcbArch.tcbContext.userRegs sbo σ.machineState.underlyingMemory (i + 2)) := + hword (i + 2) (by omega) (by omega) + rw [hr] at hk + simp only [List.getElem?_cons_succ] at hk + rw [List.getElem?_take, if_pos hi, List.getElem?_map, List.getElem?_range hi] + simpa using hk + · rw [List.getElem?_take, if_neg hi, List.getElem?_map, List.getElem?_eq_none (by simp; omega)] + rfl + have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbWriteRegisters) := by + rw [hlbl, fl4_abi.label.TCBWriteRegisters]; rfl + obtain ⟨hl, hg⟩ := tcbLabel_genA hlab e + refine InvSpecA.ofTcbNil (i := .writeRegisters (specPtr t) res (r.take count.val) ArchDefaultExtraRegisters) ?_ hsp + (by cases blk <;> cases call <;> cases don <;> rfl) (by rw [hvals]; exact hperf) + rw [ec] + refine tcbDec_genA hl rfl hg fun h => ?_ + unfold decodeTcbInvocation + rw [h] + dsimp only + unfold decodeWriteRegisters + rw [hr] + have hnl : ¬ r.length < unat count.bv := by + show ¬ r.length < count.val + omega + have hne : ¬ specPtr t = σ.curThread := by rw [hcur]; exact fun e => hself (specPtr_inj e) + simp only [NonDetE.whenE, hnl, ↓reduceIte, NonDetE.returnOk, ndE_pure_bindA] + rw [run_bind_okD (run_liftE_stD (show (Fl4Spec.NonDet.gets fun s : State Unit => s.curThread) σ = + ({(σ.curThread, σ)}, False) from rfl))] + simp only [NonDetE.whenE, hne, ↓reduceIte, ndE_pure_bindA, hres] + rfl + + +/-- **CopyRegisters, register transfer only** (`TcbScopeA.copyRegs`). -/ +theorem JSyscallA.tcbCopyRegs_invSpecA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) + {info : msginfo.MessageInfo} {flags src srcSlot : U64} + (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hc : CapRelA (capA st s slot) c) + (hx : ExtraOKA Z.th (L.mem s) extra excaps) (B : ArgsLabA st s info buf mi args) (hlnI : len = msgLenA info buf) + (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBCopyRegisters) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok srcSlot)) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (hsc : capA st s srcSlot = .Thread src) + {r1 : Bool} (hres1 : testBit flags.bv 0 = r1) {r2 : Bool} (hres2 : testBit flags.bv 1 = r2) + {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (.ok [], σ') ∈ ((fl4InvokeTcb (.copyRegisters (specPtr t) (specPtr src) r1 r2 + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1) (cptr : CapRef) : + InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc + obtain ⟨he', hlen⟩ := tcbExtraLenA he + obtain ⟨arest, ea⟩ := tcbArg0A B hlnI hlen hf + obtain ⟨y1, rest, ex, hrel⟩ := tcbExtraHeadA hx he' + have hc2 : CapEqA (.Thread src) y1.1 := by rw [← hsc]; exact hrel.2 + have hy1 : y1.1 = .threadCap (specPtr src) := (show absCapA (.Thread src) = y1.1 from hc2).symm + have hbits := tcbCopyRegisters_flagBitsA flags + have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbCopyRegisters) := by + rw [hlbl, fl4_abi.label.TCBCopyRegisters]; rfl + obtain ⟨hl, hg⟩ := tcbLabel_genA hlab e + refine InvSpecA.ofTcbNil (i := .copyRegisters (specPtr t) (specPtr src) (testBit flags.bv 0) (testBit flags.bv 1) + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters) ?_ hsp + (by cases blk <;> cases call <;> cases don <;> rfl) (by rw [hres1, hres2]; exact hperf) + rw [ec] + refine tcbDec_genA hl rfl hg fun h => ?_ + unfold decodeTcbInvocation + rw [h] + dsimp only + rw [ea, ex, List.map_cons, hy1] + exact tcbCopyRegisters_selectedSpecA σ (specPtr t) (specPtr src) flags.bv arest (rest.map Prod.fst) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbSpaceA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbSpaceA.lean new file mode 100644 index 000000000..aaddb61df --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbSpaceA.lean @@ -0,0 +1,198 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP2): **`InvSpecA` for SetSpace** (`TcbScopeA.setSpace`). + +The spec decode of the actual thread cap, label, message words and three extra caps (fault handler, CSpace root, VSpace +root) is `fl4DecodeSetSpace`'s: the invocation the arm's `Out` performs. The roots' derivation is `deriveRoots_valA` +(native or Stage-2 branch of `fl4DecodeSetSpace`), the fault handler's validity `tcbHandlerA`. + +Named premises: those of `JSyscallA.setSpaceA`. New module. +-/ +import Fl4ProofsA64.P3.Stage3InvSpecTcb3A +import Fl4ProofsA64.P3.Stage3InvSpecTcbPerfA +import Fl4ProofsA64.P3.Stage3DecErrTcbValA +import Fl4ProofsA64.P3.Stage3PinVsA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical Fl4ProofsA64.P3.ReplyErr + +noncomputable section + +/-- The spec decode of a thread cap under the SetSpace label. -/ +theorem tcbDec_spaceA {call : Bool} {label : Data} {args : List Data} {cptr : CapRef} {sl : CslotPtr} + {p : ObjRef} {excaps : List (Cap × CslotPtr)} {buffer : Option ObjRef} {σ : State Unit} {i : TcbInvocation} + (hl : fl4LabelOf label = .spec (.genInvocationLabel .tcbSetSpace)) + (h : (fl4DecodeSetSpace (Z := Unit) args (.threadCap p) sl excaps).run σ = ({(.ok i, σ)}, False)) : + (.ok (Fl4Invocation.invokeTCB i), σ) ∈ + ((fl4DecodeInvocation (Z := Unit) call false label args cptr sl (.threadCap p) excaps buffer).run σ).1 := by + have e : fl4DecodeInvocation (Z := Unit) call false label args cptr sl (.threadCap p) excaps buffer = + fl4DecodeTcbInvocation (fl4LabelOf label) args (.threadCap p) sl excaps buffer := rfl + rw [e, hl] + show (.ok (Fl4Invocation.invokeTCB i), σ) ∈ + ((Fl4Spec.NonDetE.liftME Fl4Invocation.invokeTCB (fl4DecodeSetSpace (Z := Unit) args (.threadCap p) sl excaps)).run σ).1 + rw [run_liftME_okA h] + exact Set.mem_singleton _ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {s : S} {σ : Fl4SpecA64.State Unit} {th : TypedHeapA} + +/-- `derive_roots` of an accepted SetSpace against the root decode the spec runs, with the derived caps +(`roots_corrA`'s twin over `deriveRoots_valA`). -/ +theorem roots_valA {OS : Set U64} {G : List (List U64)} (F : FinStA st th OS G s σ) {t : U64} + (ht : th t = some .tcb) {cdata vdata : U64} {cs vs : obj.Slot} {sl sl1 slot : Fl4SpecA64.CslotPtr} + {y y1 : Fl4SpecA64.Cap} {rest : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)} + (hcr : CapRelA (capA st s cs) y) (hcr1 : CapRelA (capA st s vs) y1) + (hnc : isUtA (capA st s cs) = true → NoChildrenRelA (st := st) s σ cs sl) + (hnc1 : isUtA (capA st s vs) = true → NoChildrenRelA (st := st) s σ vs sl1) + {c v : capability.Cap} (h : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (c, v))) + (args : List Fl4SpecA64.Data) (P : Fl4SpecA64.Cap → Bool) + (hP : (P = fun v => isValidVtableRoot v || fl4MappedStage2Root v) ∨ + (P = isValidVtableRoot ∧ fl4MappedStage2Root y1 = false)) : + ∃ zc zv, CapEqA c zc ∧ CapEqA v zv ∧ (cvProg P (cdata.bv :: vdata.bv :: args) (.threadCap (specPtr t)) slot + ((y, sl) :: (y1, sl1) :: rest)).run σ = + ({(.ok (.threadControlCaps (specPtr t) slot none none (some (zc, sl)) (some (zv, sl1)) none), σ)}, False) := by + refine deriveRoots_valA F ht hcr hcr1 hnc hnc1 P (fun c z _ hw he hd => ?_) h + rw [vtP_extA hw he] + rcases hP with rfl | ⟨rfl, hs⟩ + · rfl + have : fl4MappedStage2Root z = false := by + cases hz : fl4MappedStage2Root z with + | false => rfl + | true => rw [stage2_deriveA hd hz] at hs; exact absurd hs (by simp) + rw [this, Bool.or_false] + +end + +section arm +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} {nA : U64} {s : S} {a : A} {σ σ' : State Unit} {m : McState} + {call blk don : Bool} {mi : MessageInfo} {sl : CslotPtr} {c : Cap} {excaps : List (Cap × CslotPtr)} + {buffer : Option ObjRef} {args : List Data} {lbl len slot buf t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {info : msginfo.MessageInfo} + +set_option maxHeartbeats 16000000 in +/-- **SetSpace** (`TcbScopeA.setSpace`). -/ +theorem JSyscallA.tcbSetSpace_invSpecA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {fs cs vs cdata vdata : U64} {ccap vcap : capability.Cap} {κs κfs κcs κvs : CslotPtr} + {p r gs g gs' g' : U64} + (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hc : CapRelA (capA st s slot) c) + (hx : ExtraOKA Z.th (L.mem s) extra excaps) (B : ArgsLabA st s info buf mi args) (hlnI : len = msgLenA info buf) + (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBSetSpace) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 2#u64 = ok (.Ok fs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 2#u64 = ok (.Ok cs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 2#u64 = ok (.Ok vs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hfhv : faults.valid_fault_handler (capA st s fs) = ok true) + (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hsl : slot = cslotAddrA sl) (hab : AbsSlotA Z.th sl) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAf : AbsSlotA Z.th κfs) (hκf : cslotAddrA κfs = fs) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) + {σ1 : State Unit} {done : Bool} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : TcbPerfA done σ' ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs (some (absCapA (capA st s fs), κfs)) + none (some (absCapA ccap, κcs)) (some (absCapA vcap, κvs)) none)).run σ1).1) (cptr : CapRef) : + InvSpecA call blk don done mi.miLabel args cptr sl c excaps buffer σ σ' := by + subst hccap + obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc + have eκ : κs = sl := cslotAddrA_inj J.j.1.place hAκ hab (hκ.trans hsl) + subst eκ + have htT : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + obtain ⟨hex0, hl0, es0⟩ := tcbExtraAtA (st := st) hx (i := 0#usize) (by simp) he0 + obtain ⟨hex1, -, es1⟩ := tcbExtraAtA (st := st) hx (i := 1#usize) (by simp) he1 + obtain ⟨hex2, -, es2⟩ := tcbExtraAtA (st := st) hx (i := 2#usize) (by simp) he2 + simp only [UScalar.ofNatCore_val_eq] at hex0 hex1 hex2 es0 es1 es2 + obtain ⟨y0, y1, y2, ys, rfl⟩ : ∃ y0 y1 y2 ys, excaps = y0 :: y1 :: y2 :: ys := by + match excaps, hex2 with + | y0 :: y1 :: y2 :: ys, _ => exact ⟨y0, y1, y2, ys, rfl⟩ + obtain ⟨-, -, hx0, c0, ps0, hth0, hy0⟩ := srcOK_factsA J.j.1.place (hx.2.1 0 (by simp)) + obtain ⟨-, -, hx1, c1, ps1, hth1, hy1⟩ := srcOK_factsA J.j.1.place (hx.2.1 1 (by simp)) + obtain ⟨-, -, hx2, c2, ps2, hth2, hy2⟩ := srcOK_factsA J.j.1.place (hx.2.1 2 (by simp)) + rw [capAtA_eq (st := st)] at c0 c1 c2 + simp only [List.getElem_cons_zero, List.getElem_cons_succ] at c0 c1 c2 hx0 hx1 hx2 hth0 hth1 hth2 hy0 hy1 hy2 + rw [← es0] at c0 hx0 + rw [← es1] at c1 hx1 + rw [← es2] at c2 hx2 + have eκf : κfs = y0.2 := cslotAddrA_inj J.j.1.place hAf ⟨ps0, hy0, Or.inl hth0⟩ (hκf.trans hx0) + have eκc : κcs = y1.2 := cslotAddrA_inj J.j.1.place hAc ⟨ps1, hy1, Or.inl hth1⟩ (hκc.trans hx1) + have eκv : κvs = y2.2 := cslotAddrA_inj J.j.1.place hAv ⟨ps2, hy2, Or.inl hth2⟩ (hκv.trans hx2) + have hl1 : 1 < len.val := by scalar_tac + obtain ⟨hal, g0'⟩ := tcbArgA B hlnI (i := 0#u64) (by simp; omega) hcd + obtain ⟨-, g1'⟩ := tcbArgA B hlnI (i := 1#u64) (by simp; omega) hvd + obtain ⟨cc, vv, rest, rfl⟩ : ∃ cc vv rest, args = cc :: vv :: rest := by + match args, hal.symm ▸ hl1 with + | cc :: vv :: rest, _ => exact ⟨cc, vv, rest, rfl⟩ + simp at g0' g1' + subst g0' g1' + have e : fl4LabelOf lbl.bv = .spec (.genInvocationLabel .tcbSetSpace) := by + rw [hlbl, fl4_abi.label.TCBSetSpace]; rfl + obtain ⟨hl, -⟩ := tcbLabel_genA hlab e + obtain ⟨ey0, hv⟩ := tcbHandlerA c0 hfhv + have hnc1 : isUtA (capA st s cs) = true → NoChildrenRelA (st := st) s σ cs y1.2 := fun h => by + rw [hcc] at h; simp [isUtA] at h + have hnc2 : isUtA (capA st s vs) = true → NoChildrenRelA (st := st) s σ vs y2.2 := fun h => by + rw [hvc] at h + rcases hvk with ⟨p', b, s', r', g'', gr, e'⟩ | ⟨p', r', g'', b, e'⟩ | ⟨p', m', a', e'⟩ | + ⟨p', l, m', ad, v', e'⟩ | ⟨p', m', a', e'⟩ <;> (rw [e'] at h; simp [isUtA] at h) + have hfh : (checkHandlerEp (Z := Unit) 1 y0).run σ = ({(.ok y0, σ)}, False) := by + unfold checkHandlerEp + rw [show Fl4Spec.NonDetE.unlessE (σ := State Unit) (validFaultHandler y0.1) + (Fl4Spec.NonDetE.throwError (SyscallError.invalidCapability 1)) = pure () from if_pos hv] + simp only [ndE_pure_bindD] + rfl + have hw : Fl4Spec.NonDetE.whenE (σ := State Unit) + ((cdata.bv :: vdata.bv :: rest).length < 2 ∨ (y0 :: y1 :: y2 :: ys).length < 3) + (Fl4Spec.NonDetE.throwError SyscallError.truncatedMessage) = pure () := if_neg (by simp) + have e1 : (cdata.bv :: vdata.bv :: rest).take 2 = [cdata.bv, vdata.bv] := by simp + have e2 : ((y0 :: y1 :: y2 :: ys).drop 1).take 2 = [(y1.1, y1.2), (y2.1, y2.2)] := by simp + have e3 : (the (y0 :: y1 :: y2 :: ys)[2]?) = y2 := by simp [the] + have e4 : (the (y0 :: y1 :: y2 :: ys)[0]?) = y0 := by simp [the] + have hdecS : ∃ zc zv, CapEqA (.CNode p r gs' g') zc ∧ CapEqA vcap zv ∧ + (fl4DecodeSetSpace (Z := Unit) (cdata.bv :: vdata.bv :: rest) (.threadCap (specPtr t)) κs (y0 :: y1 :: y2 :: ys)).run σ = + ({(.ok (.threadControlCaps (specPtr t) κs (some y0) none (some (zc, y1.2)) (some (zv, y2.2)) none), σ)}, + False) := by + have F := J.finStA + have ht : Z.th t = some .tcb := (J.j.1.thT t).2 htT + unfold fl4DecodeSetSpace + cases hq : fl4MappedStage2Root y2.1 with + | true => + obtain ⟨zc, zv, hzc, hzv, hrun⟩ := roots_valA (σ := σ) (slot := κs) (rest := []) F ht c1 c2 hnc1 hnc2 hRoots [] + _ (Or.inl rfl) + refine ⟨zc, zv, hzc, hzv, ?_⟩ + rw [if_pos (by rw [e3]; exact hq), hw, run_bind_okD (a := ()) (s' := σ) rfl, e1, e2, fl4CvSpace_progA, + run_bind_okD hrun, e4, run_bind_okD hfh] + rfl + | false => + obtain ⟨zc, zv, hzc, hzv, hrun⟩ := roots_valA (σ := σ) (slot := κs) (rest := []) F ht c1 c2 hnc1 hnc2 hRoots [] + _ (Or.inr ⟨rfl, hq⟩) + refine ⟨zc, zv, hzc, hzv, ?_⟩ + rw [if_neg (by rw [e3, hq]; simp)] + unfold decodeSetSpace + rw [hw, run_bind_okD (a := ()) (s' := σ) rfl, e1, e2, decodeCvSpace_progA, run_bind_okD hrun, e4, + run_bind_okD (a := y0) (s' := σ) rfl, run_bind_okD hfh] + rfl + obtain ⟨zc, zv, hzc, hzv, hdecS⟩ := hdecS + have ezc : absCapA (.CNode p r gs' g') = zc := CapEqA.eq_abs hzc (fun _ _ _ e => by cases e) + have ezv : absCapA vcap = zv := by + rcases hvk with ⟨p', b, s', r', g'', gr, e'⟩ | ⟨p', r', g'', b, e'⟩ | ⟨p', m', a', e'⟩ | + ⟨p', l, m', ad, v', e'⟩ | ⟨p', m', a', e'⟩ <;> (subst e'; exact CapEqA.eq_abs hzv (fun _ _ _ e => by cases e)) + rw [ey0, eκf, ezc, eκc, ezv, eκv] at hperf + refine InvSpecA.ofTcbNilD (i := .threadControlCaps (specPtr t) κs (some y0) none (some (zc, y1.2)) + (some (zv, y2.2)) none) ?_ hsp (by cases blk <;> cases call <;> cases don <;> rfl) hperf + rw [ec] + exact tcbDec_spaceA hl hdecS + +end arm + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbTimerA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbTimerA.lean new file mode 100644 index 000000000..731151406 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbTimerA.lean @@ -0,0 +1,71 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbtimer): **`InvSpecA` for SetTimer** (`TcbScopeA.setTimer`). + +The spec decode (`decodeFl4SetTimer`) of the two message words (deadline, badge); the perform is `invokeFl4Tcb` +alone (no reply: the caller stays `Restart`). + +Named premises: those of the arm. New module. +-/ +import Fl4ProofsA64.P3.Stage3InvSpecTcb2A +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {J5 J7 : JSlotA S} {s : S} {a : A} {σ σ' : State Unit} {m : McState} + {call blk don : Bool} {mi : MessageInfo} {sl : CslotPtr} {c : Cap} {excaps : List (Cap × CslotPtr)} + {buffer : Option ObjRef} {args : List Data} {lbl len slot buf t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +/-- **SetTimer** (`TcbScopeA.setTimer`). -/ +theorem JSyscallA.tcbSetTimer_invSpecA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) + {info : msginfo.MessageInfo} {d bd : U64} + (hslot : slot ∈ OS) (hcap : capA st s slot = .Thread t) (hc : CapRelA (capA st s slot) c) + (B : ArgsLabA st s info buf mi args) (hlnI : len = msgLenA info buf) + (hlab : mi.miLabel = lbl.bv) (hlbl : lbl = fl4_abi.label.TCBSetTimer) (hlen : ¬ len < 2#u64) + (hd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok d) + (hbd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok bd) + {σ1 : State Unit} (hsp : setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False)) + (hperf : (.ok [], σ') ∈ ((invokeFl4Tcb (Z := Unit) (.setTimer (specPtr t) d.bv bd.bv)).run σ1).1) + (cptr : CapRef) : + InvSpecA call blk don true mi.miLabel args cptr sl c excaps buffer σ σ' := by + obtain ⟨ec, -, -⟩ := J.tcbTargetA hslot hcap hc + have hl2 : 2 ≤ len.val := by scalar_tac + obtain ⟨hal, g0'⟩ := tcbArgA B hlnI (i := 0#u64) (by simp; omega) hd + obtain ⟨-, g1'⟩ := tcbArgA B hlnI (i := 1#u64) (by simp; omega) hbd + have g0 : args[0]? = some d.bv := by simpa using g0' + have g1 : args[1]? = some bd.bv := by simpa using g1' + have e : fl4LabelOf lbl.bv = .ext .tcbSetTimer := by + rw [hlbl, fl4_abi.label.TCBSetTimer]; rfl + have hdec : (.ok (Fl4Invocation.invokeFl4TCB (.setTimer (specPtr t) d.bv bd.bv)), σ) ∈ + ((fl4DecodeInvocation (Z := Unit) call false mi.miLabel args cptr sl c excaps buffer).run σ).1 := by + rw [ec, hlab] + show (_ ∈ ((fl4DecodeTcbInvocation (fl4LabelOf lbl.bv) args (.threadCap (specPtr t)) sl excaps buffer).run σ).1) + rw [e] + show (_ ∈ ((NonDetE.liftME Fl4Invocation.invokeFl4TCB (decodeFl4SetTimer (Z := Unit) args (specPtr t))).run σ).1) + have hd' : (decodeFl4SetTimer (Z := Unit) args (specPtr t)).run σ = + ({(.ok (.setTimer (specPtr t) d.bv bd.bv), σ)}, False) := by + unfold decodeFl4SetTimer + have : ¬ args.length < 2 := by omega + simp only [NonDetE.whenE, this, ↓reduceIte, NonDetE.returnOk, ndE_pure_bindA, g0, g1, the_someA] + rfl + rw [run_liftME_okA hd'] + exact Set.mem_singleton _ + refine ⟨_, σ1, hdec, hsp, ?_, fun h => by cases h⟩ + unfold PerfSpecA + rw [if_pos rfl] + exact ⟨[], Or.inl ⟨hperf, fun _ _ _ => rfl⟩⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbTopA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbTopA.lean index 5f8615e2f..f69c62213 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbTopA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTcbTopA.lean @@ -2,7 +2,7 @@ P3 (aarch64, A64-P3 Lift 1c, TCB assembly): **`TcbScopeA.invSpecA`**, the TCB group's `InvSpecA` over the whole of `TcbScopeA` (slice 1: `P3/Stage3InvSpecTcbA`; slice 2: `P3/Stage3InvSpecTcb2A`; Resume of a stopped thread, ReadFPU and Suspend reuse the Resume, FPU-transfer and Suspend lemmas there; SetIPCBuffer, SetTimeoutEndpoint and SetSchedParams: -`P3/Stage3InvSpecTcb3A`). +`P3/Stage3InvSpecTcb3A`; SetHighVSpace: `P3/Stage3InvSpecTcbHighA`). Each arm: its decode succeeds (`TcbScopeA.soundOk`, so the invocation is done), the arm's `Out` gives the restart and the perform, and the arm's theorem gives the spec decode of the actual cap, label, message words and extra cap. @@ -12,6 +12,12 @@ registers and buffer words), and `slot`'s spec name `sl` (the arms that name the Named premises: those of the arms. New module. -/ import Fl4ProofsA64.P3.Stage3InvSpecTcb3A +import Fl4ProofsA64.P3.Stage3InvSpecTcbHighA +import Fl4ProofsA64.P3.Stage3InvSpecTcbRegsA +import Fl4ProofsA64.P3.Stage3InvSpecTcbRegsWA +import Fl4ProofsA64.P3.Stage3InvSpecTcbSpaceA +import Fl4ProofsA64.P3.Stage3InvSpecTcbBufDecA +import Fl4ProofsA64.P3.Stage3InvSpecTcbTimerA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -81,6 +87,9 @@ theorem TcbScopeA.invSpecA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSpi a | setTls hCs h1 hslot hcov hcap hext hSC hlbl hlen hv hne => obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut exact J.tcbSetTls_invSpecA hslot hcap hc B hlnI hlab hlbl hlen hv hsp hperf cptr + | setTimer hCs h1 hslot hcov hcap hext hSC hlbl hlen hd hbd => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbSetTimer_invSpecA hslot hcap hc B hlnI hlab hlbl hlen hd hbd hsp hperf cptr | setTlsSelf hCs h1 hslot hcov hcap hext hSC hlbl hlen hv hself => obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut exact J.tcbSetTls_invSpecA hslot hcap hc B hlnI hlab hlbl hlen hv hsp hperf cptr @@ -95,6 +104,27 @@ theorem TcbScopeA.invSpecA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSpi a obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut exact J.tcbFpu_invSpecA hslot hcap hc hx B hlnI hlab (hlbl.trans (if_neg Bool.false_ne_true).symm) he hlen hoff hfcap hread (fun h => nomatch h) halign hroom hsp hperf cptr + | @writeRegs _ _ _ _ _ _ _ _ _ _ _ _ sbo hCs h1 hslot hcov hcap hext hSC hlbl hlen hf hn htail henough hself hres hlen120 hBN hBS => + obtain ⟨xc, σ1, hkc, -, hsp, hperf⟩ := hOut + exact J.tcbWriteRegs_invSpecA (sbo := sbo) hslot hcap hc B hlnI hlab hlbl hlen hf hn htail henough hself (testBit0_of_andA hres) hlen120 hBN hBS + hkc hsp hperf cptr + | copyRegs hCs h1 hslot hcov hcap hext hSC hlbl he hf harg hsc hself hres1 hres2 => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbCopyRegs_invSpecA hslot hcap hc hx B hlnI hlab hlbl he hf hsc (testBit0_of_andA hres1) (testBit1_of_andA hres2) hsp hperf cptr + | @writeRegsResume _ _ _ _ _ _ _ _ _ _ _ _ sbo _ _ hCs h1 hmb hmbF hmax htu hslot hcov hcap hext hSC hlbl hlen hf hn htail henough hself hres hlen120 hBN hBS hsl hy hstop => + obtain ⟨xc, σ1, hkc, -, hsp, hperf⟩ := hOut + exact J.tcbWriteRegs_invSpecA (sbo := sbo) hslot hcap hc B hlnI hlab hlbl hlen hf hn htail henough hself + (testBit0_of_neA hres) hlen120 hBN hBS hkc hsp hperf cptr + | copyRegsRestart hCs h1 hmb hmbF hmax htu hslot hcov hcap hext hSC hlbl he hf harg hsc hself hres1 hres2 hsl hy hstop => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbCopyRegs_invSpecA hslot hcap hc hx B hlnI hlab hlbl he hf hsc (testBit0_of_andA hres1) (testBit1_of_neA hres2) hsp hperf cptr + | copyRegsSelf hCs h1 hslot hcov hcap hext hSC hlbl he hf harg hsc hself hres1 hres2 => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbCopyRegs_invSpecA hslot hcap hc hx B hlnI hlab hlbl he hf hsc (testBit0_of_andA hres1) (testBit1_of_andA hres2) hsp hperf cptr + | copyRegsSusp hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he hf harg hcovS hsc hself hsrcne hres1 hres2 => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbCopyRegs_invSpecA hslot hcap hc hx B hlnI hlab hlbl he hf hsc (testBit0_of_neA hres1) + (testBit1_of_andA hres2) hsp hperf cptr | setFlags hCs h1 hX hslot hcov hcap hext hSC hlbl hlen hclear hset hfl hrel hk howner => obtain ⟨xc, σ1, σ2, d, -, -, hsp, hinv, hcur, hrun⟩ := hOut exact J.tcbSetFlags_invSpecA hslot hcap hc B hlnI hlab hlbl hlen hclear hset hsp hinv hcur hrun cptr @@ -118,29 +148,70 @@ theorem TcbScopeA.invSpecA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSpi a exact J.tcbSuspend_invSpecA hslot hcap hc hlab hlbl hsp hperf cptr | setIpcBufZero hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he harg hne hdec hrr => obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut - exact J.tcbSetIpcBufZero_invSpecA hslot hcap hc hx B hlnI hlab hlbl he harg hsp hperf cptr + exact J.tcbSetIpcBufZero_invSpecA hslot hcap hc hx B hlnI hlab hlbl he harg hsp hperf (.inl ⟨rfl, rfl⟩) cptr | setIpcBuf hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he harg hbn hbal hsrcF hbits hag hAκ hκ hAsrc hκsrc hdec hrr => obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut exact J.tcbSetIpcBuf_invSpecA hslot hcap hc hx B hlnI hlab hlbl he harg hbn hbal hsrcF hsl hab hAκ hκ hAsrc hκsrc - hsp hperf cptr + hsp hperf (.inl ⟨rfl, rfl⟩) cptr | setTimeoutNull hCnt P hCl hCs h1 hslot hcov hcap hext hlbl he hnullh hdec hrr => obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut - exact J.tcbSetTimeoutNull_invSpecA hslot hcap hc hx hlab hlbl he hnullh hsp hperf cptr + exact J.tcbSetTimeoutNull_invSpecA hslot hcap hc hx hlab hlbl he hnullh hsp hperf (.inl ⟨rfl, rfl⟩) cptr | setTimeoutNonNull hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he hnn hValid hAκ hκ hAsrc hκsrc hdec hrr => obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut - exact J.tcbSetTimeoutNonNull_invSpecA hslot hcap hc hx hlab hlbl he hValid hsl hab hAκ hκ hAsrc hκsrc hsp hperf - cptr + exact J.tcbSetTimeoutNonNull_invSpecA hslot hcap hc hx hlab hlbl he hValid hsl hab hAκ hκ hAsrc hκsrc hsp hperf (.inl ⟨rfl, rfl⟩) cptr | setSchedParamsNull hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 he2 hmcp hprio harg hac - hle1 hle2 hsc hold hfh hne hAκ hκ hdec hrr => + hle1 hle2 hsc hmin hfh hAκ hκ hdec hrr => obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut exact J.tcbSspNull_invSpecA hslot hcap hc hx B hlnI hlab hlbl hext he0 he1 he2 hmcp hprio harg hac hle1 hle2 hsc - hold hfh hne hsp hperf cptr + hfh hsp hperf (.inl ⟨rfl, rfl⟩) cptr | setSchedParamsEp hCnt P hCl hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl he0 he1 he2 hmcp hprio harg hac - hle1 hle2 hsc hold hnn hValid hne hAκ hκ hAsrc hκsrc hdec hrr => + hle1 hle2 hsc hmin hnn hValid hAκ hκ hAsrc hκsrc hdec hrr => obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut exact J.tcbSspEp_invSpecA hslot hcap hc hx B hlnI hlab hlbl hext he0 he1 he2 hmcp hprio harg hac hle1 hle2 hsc - hold hValid hne hsl hab hAκ hκ hAsrc hκsrc hsp hperf cptr + hValid hsl hab hAκ hκ hAsrc hκsrc hsp hperf (.inl ⟨rfl, rfl⟩) cptr + | setHighVSpaceNull hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he hn hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbSetHighVSpace_invSpecA hslot hcap hc hx hlab hlbl he (Or.inl hn) hsl hab hAκ hκ hAsrc hκsrc hsp (.inl ⟨rfl, hperf⟩) cptr + | setHighVSpaceLive hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he hcsrc hfind hAκ hκ hAsrc hκsrc hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbSetHighVSpace_invSpecA hslot hcap hc hx hlab hlbl he (Or.inr ⟨_, _, hcsrc, hfind⟩) hsl hab hAκ hκ hAsrc + hκsrc hsp (.inl ⟨rfl, hperf⟩) cptr + | readRegsSend hCs h1 hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbReadRegs_invSpecA hslot hcap hc B hlnI hlab hlbl hlen hf hn hlo hhi hself hsuspend hsp hperf cptr + | readRegsCall hCs h1 hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend hu => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbReadRegs_invSpecA hslot hcap hc B hlnI hlab hlbl hlen hf hn hlo hhi hself hsuspend hsp hperf cptr + | readRegsSendSusp hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbReadRegsSusp_invSpecA hslot hcap hc B hlnI hlab hlbl hlen hf hn hlo hhi hself hsuspend hsp hperf cptr + | readRegsCallSusp hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl hlen hf hn hlo hhi hself hsuspend hu => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbReadRegsSusp_invSpecA hslot hcap hc B hlnI hlab hlbl hlen hf hn hlo hhi hself hsuspend hsp hperf cptr + + | setSpace hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hfhv hcc hccap hwfc hencc hvc hvk + hvdr hAκ hκ hAf hκf hAc hκc hAv hκv hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbSetSpace_invSpecA hslot hcap hc hx B hlnI hlab hlbl he0 he1 he2 hcd hvd hRoots hfhv hcc hccap hvc hvk + hsl hab hAκ hκ hAf hκf hAc hκc hAv hκv hsp (.inl ⟨rfl, hperf⟩) cptr + | configureBufZero hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hcc hccap hwfc hencc hvc + hvk hvdr hAκ hκ hAc hκc hAv hκv hAb hκb hba hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbConfigure_invSpecA (bsp := fun _ => some (Fl4SpecA64.dataToVref (0#u64).bv, none)) hslot hcap hc hx B hlnI + hlab hlbl he0 he1 he2 hcd hvd hba hRoots hcc hccap hvc hvk (fun y _ => bufDecZeroA y) hsl hab hAκ hκ hAc hκc hAv hκv + hAb hκb hsp (.inl ⟨rfl, hperf⟩) cptr + | @configureBuf baddr ptr rights asid va bits size mp ep _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + hCnt P hCl hCs h1 hslot hcov hcap hext hSC hlbl he0 he1 he2 hcd hvd hRoots hcc hccap hwfc hencc hvc hvk + hvdr hAκ hκ hAc hκc hAv hκv hAb hκb hba hbn hbal hsrcF hbits hag hdec hrr => + obtain ⟨xc, σ1, -, -, hsp, hperf⟩ := hOut + exact J.tcbConfigure_invSpecA (bsp := fun y2 => some (Fl4SpecA64.dataToVref baddr.bv, + some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), y2))) hslot hcap hc hx B hlnI + hlab hlbl he0 he1 he2 hcd hvd hba hRoots hcc hccap hvc hvk + (fun y hy => by + rw [hsrcF] at hy + exact bufDecNzA y (CapEqA.eq_abs hy.2 (fun _ _ _ h => by cases h)) hbn hbal) + hsl hab hAκ hκ hAc hκc hAv hκv hAb hκb hsp (.inl ⟨rfl, hperf⟩) cptr end end diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTopA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTopA.lean index be4259585..985ba154f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTopA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTopA.lean @@ -11,6 +11,7 @@ import Fl4ProofsA64.P3.Stage3InvSpecCnA import Fl4ProofsA64.P3.Stage3InvSpecIpcA import Fl4ProofsA64.P3.Stage3InvSpecScA import Fl4ProofsA64.P3.Stage3InvSpecTcbTopA +import Fl4ProofsA64.P3.Stage3InvSpecTcbPreA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -102,7 +103,7 @@ theorem DispScope4A.invSpecA [PlainStore st] {ar : machine.Arch A} (hA : P0.Arch · exact h · rw [e] at h; cases h have B := J.argsLabA hinfo hBV hmi gargs - rcases h with h | h | h | h | h | h + rcases h with h | h | h | h | h | h | h · obtain ⟨s0, a0, σ0, e0, -⟩ := VsScopeA.soundOk hA hM hPl J hfm h rw [done_of (Prod.mk.inj (okinj (hd.symm.trans e0))).1] exact VsScopeA.invSpecA J.j.1.place h hst hOut F cptr @@ -125,10 +126,13 @@ theorem DispScope4A.invSpecA [PlainStore st] {ar : machine.Arch A} (hA : P0.Arch cases blk <;> cases call <;> cases don <;> rfl rw [cn, ExceptT.run_bind] exact mem_bindA.2 ⟨(.error (), σ'), hperf, Set.mem_singleton _⟩ - · cases h + · obtain ⟨s0, a0, σ0, e0, -⟩ := UtScopeA.soundOk hA hPl J hfm h + rw [done_of (Prod.mk.inj (okinj (hd.symm.trans e0))).1] + exact UtScopeA.invSpecA J.j.1.place h hst hOut F cptr · exact IpcScopeA.invSpecA hA hM hPl J hfm h hinfo hBV hd hOut hdone F hc cptr · exact ScScopeA.invSpecA hA hM hPl J hfm h hd hOut hdone B.1 hc _hok B rfl cptr · exact TcbScopeA.invSpecA hA hM hPl J hfm h hd hOut hdone B.1 hc _hok B rfl hBV gargs cptr hsl hab + · exact TcbPreScopeA.invSpecA hA hM hPl J hfm h hd hOut hdone B.1 hc _hok B rfl cptr hsl hab end diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecVsA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecVsA.lean index 0fac04dad..8b1727866 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InvSpecVsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecVsA.lean @@ -104,6 +104,11 @@ theorem VsScopeA.invSpecA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} refine InvSpecA.ofPin hP hpin F cptr hset ?_ rw [flags] exact liftE_memA hperf + | @ptUnmapT2 bB bC bD bF K hnvm hTO hEO hIpa length buf ex cte hab ptr asid va hpT hcap hf k hkR hkR1 hno hUniq hcov hext hSC hpin => + obtain ⟨x, -, hset, hperf⟩ := hOut + refine InvSpecA.ofPin hP hpin F cptr hset ?_ + rw [flags] + exact liftE_memA hperf | @ptUnmapU bB bC bD bF hnvm length buf ex cte hab ptr asid va hcap hf hcov hext hSC hpin => obtain ⟨x, -, hset, hperf⟩ := hOut refine InvSpecA.ofPin hP hpin F cptr hset ?_ @@ -120,6 +125,22 @@ theorem VsScopeA.invSpecA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} refine InvSpecA.ofPin hP (hpin iv hD) F cptr hset ?_ rw [flags] exact liftE_memA hperf + | @ptMapHi x0 D s3 ptr asid0 va0 bB bC bD bF hnvm hTO hEO cte hab hcap UP hS2 hY length buf extra hx hlen p1 asid1 mp1 h16 hx0c vaddr h0 hD hres hcov hext hSC hpin => + obtain ⟨x, iv, -, hset, hD', hperf⟩ := hOut + refine InvSpecA.ofPin hP (hpin iv hD') F cptr hset ?_ + rw [flags] + exact liftE_memA hperf + | @ptMapS2 x0 D s3 a3 ptr asid0 va0 bB bC bD bF hnvm hTO hEO hIpa hIpa47 cte hab hcap UP hS2 hY length buf extra hx hlen vp vasid vva ha16 hx0c vaddr h0 hD hrt hres hcov hext hSC hpin => + obtain ⟨x, iv, -, hset, hD', hperf⟩ := hOut + refine InvSpecA.ofPin hP (hpin iv hD') F cptr hset ?_ + rw [flags] + exact liftE_memA hperf + + | @frameMapS2 x0 D dc ex s3 a3 callD lenD bufD rr bB bD bF K hIpa hnvm hTO hEO cte hab hCn fp rt asid va sz dev mp e hcap FP hemp p1 asid1 va1 mp1 h16 hx0 hx0c hrt vaddr rightsMask vm attr hvmRange hvmEq hD d hres hcov hext hSC hx hlen h0 h1 h2 hr hvm hpin => + obtain ⟨x, iv, -, hset, hD, hperf⟩ := hOut + refine InvSpecA.ofPin hP (hpin iv hD) F cptr hset ?_ + rw [flags] + exact liftE_memA hperf end diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryActRecA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryActRecA.lean index 309bfe606..c2b2a54e5 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryActRecA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryActRecA.lean @@ -717,7 +717,7 @@ theorem JStage3A.activateA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} subst e exact ⟨y0, n, h0, fun r => ⟨r, id⟩⟩, fun p y h => ⟨y, objB p _ h (by intro _ c; cases c) (by intro _ _ c; cases c), id⟩, - ⟨congrArg (·.domainIndex) eτ, congrArg (·.domainStartIndex) eτ, congrArg (·.domainList) eτ, congrArg (·.archState.armUsGlobalVspace) eτ⟩⟩ + DomKeepA.ofKey (congrArg DomKeyA eτ :)⟩ have j := J.j57_stepNWA wN τ have J2 := JStage3A.of_schedWr (J5 := J5A st) (Rj := J7R2A st ar hPl.ipa) J (Q := Z.Q) (Rl := Z.R) (curOf := Z.curOf) (curScOf := Z.curScOf) (s' := s') (a' := a) (σ' := τ) w HS SSz Qk hum J.j.1.ar @@ -800,7 +800,7 @@ theorem JStage3A.finishEA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → ∀ y, τ2.kheap τ2.curThread = some (.tcb y) → y.tcbState ≠ .ext .runningVM) : syscall.finish st ar s a ⦃ r => - StepPostA (KExitA st ar AR hPl.ipa m) (fl4Finish kLimitA view) σ r ⦄ := by + StepPostA (KExitAt st ar AR hPl.ipa m) (fl4Finish kLimitA view) σ r ⦄ := by refine JStage3A.finishFA hA hPl arch hCs h1 J hSw B hSig G arK toUs hNative ?_ intro f out σ1 τ1 τ2 Q Rl ef eout J1 hf tail hact facts atExit obtain ⟨s1, a1, Q', Rl', Tcur, Ccur, hw, sch, J2⟩ := atExit diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryArmsA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryArmsA.lean index e96135ab5..b548587c4 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryArmsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryArmsA.lean @@ -53,7 +53,7 @@ def KEntryChargeA (st : machine.Store S) [LawfulStore st] (ar : machine.Arch A) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (nA : U64) (m : McState) (Clock : A → MachineState → Prop) (s : S) (a : A) (σ : State Unit) (code : S → A → Result (Bool × S × A)) (spec : Fl4Spec.NonDet (State Unit) Bool) : Prop := - ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → ValidMachineTimeA σ1 → CurInvA σ1 → OffReadyA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryBudgetRecA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryBudgetRecA.lean index b6f0a3698..e011f5a96 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryBudgetRecA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryBudgetRecA.lean @@ -338,7 +338,7 @@ theorem JStage3A.budgetOkA (Act : ActIdleA σ) (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) (hAr : sched.update_timestamp st ar s a ⦃ r => AR' r.2 Z.hw ⦄) (hmb : ∀ a', Fl4MinBudgetAgreeA ar a') (hEnt : ChargeEntryA st Ac s) - (hCharge : ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + (hCharge : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → ValidMachineTimeA σ1 → CurInvA σ1 → OffReadyA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → @@ -351,9 +351,10 @@ theorem JStage3A.budgetOkA JStage3QA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes nA m r.2.1 r.2.2 τ ⦄ := by unfold syscall.budget_ok - refine WP.spec_bind (J.timestampA sact noSwitch hvp P hClock hnd V C CI R Act hNow hAr) ?_ - rintro ⟨s1, a1⟩ ⟨σ1, e1, J1, -, -, V1, CI1, R1, Act1, Cl1, Ent1⟩ - simp only [uncurry_apply_pair] + obtain ⟨⟨s1, a1⟩, hu, σ1, e1, J1, -, -, V1, CI1, R1, Act1, Cl1, Ent1⟩ := + spec_existsA (J.timestampA sact noSwitch hvp P hClock hnd V C CI R Act hNow hAr) + rw [hu, bind_ok] + try simp only [uncurry_apply_pair] obtain ⟨b, dec, spec, -⟩ := spec_existsA (entryBudgetDecisionA J1.sr.toSchedSRN CI1 J1.sinv.mc a1 (hmb a1)) have lift' : ∀ (r : Bool) (τ : State Unit), fl4CheckBudgetRestart (Z := Unit) σ1 = ({(r, τ)}, False) → @@ -362,7 +363,7 @@ theorem JStage3A.budgetOkA rw [nd_bind_oneSc e1] exact h cases b - · refine WP.spec_mono (hCharge s1 a1 σ1 e1 J1 (Ent1 hEnt) V1 CI1 R1 Act1 Cl1 spec) ?_ + · refine WP.spec_mono (hCharge s1 a1 σ1 hu e1 J1 (Ent1 hEnt) V1 CI1 R1 Act1 Cl1 spec) ?_ rintro r ⟨τ, h, Q⟩ exact ⟨τ, lift' _ _ h, Q⟩ · obtain ⟨code, cb⟩ := budgetSuffA (st := st) (ar := ar) dec spec hnd @@ -392,7 +393,7 @@ theorem JStage3A.irqBudgetA (Act : ActIdleA σ) (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) (hAr : sched.update_timestamp st ar s a ⦃ r => AR' r.2 Z.hw ⦄) (hmb : ∀ a', Fl4MinBudgetAgreeA ar a') (hEnt : ChargeEntryA st Ac s) - (hCharge : ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + (hCharge : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → ValidMachineTimeA σ1 → CurInvA σ1 → OffReadyA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → @@ -405,13 +406,14 @@ theorem JStage3A.irqBudgetA ((fl4UpdateTimestamp (Z := Unit)) >>= fun _ => fl4CheckBudget) σ = ({(r.1, τ)}, False) ∧ JStage3QA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes nA m r.2.1 r.2.2 τ ⦄ := by - refine WP.spec_bind (J.timestampA sact noSwitch hvp P hClock hnd V C CI R Act hNow hAr) ?_ - rintro ⟨s1, a1⟩ ⟨σ1, e1, J1, -, -, V1, CI1, R1, Act1, Cl1, Ent1⟩ - simp only [uncurry_apply_pair] + obtain ⟨⟨s1, a1⟩, hu, σ1, e1, J1, -, -, V1, CI1, R1, Act1, Cl1, Ent1⟩ := + spec_existsA (J.timestampA sact noSwitch hvp P hClock hnd V C CI R Act hNow hAr) + rw [hu, bind_ok] + try simp only [uncurry_apply_pair] obtain ⟨b, dec, spec, -⟩ := spec_existsA (entryBudgetDecisionA J1.sr.toSchedSRN CI1 J1.sinv.mc a1 (hmb a1)) cases b - · refine WP.spec_mono (hCharge s1 a1 σ1 e1 J1 (Ent1 hEnt) V1 CI1 R1 Act1 Cl1 spec) ?_ + · refine WP.spec_mono (hCharge s1 a1 σ1 hu e1 J1 (Ent1 hEnt) V1 CI1 R1 Act1 Cl1 spec) ?_ rintro r ⟨τ, h, Q⟩ exact ⟨τ, by rw [nd_bind_oneSc e1]; exact h, Q⟩ · obtain ⟨code, cb⟩ := budgetSuffA (st := st) (ar := ar) dec spec hnd diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryBudgetSysA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryBudgetSysA.lean index c35731ef9..e80c8701f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryBudgetSysA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryBudgetSysA.lean @@ -96,7 +96,7 @@ theorem JSyscallA.budgetOkSysA (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) (hAr : sched.update_timestamp st ar s a ⦃ r => AR' r.2 Z.hw ⦄) (hmb : ∀ a', Fl4MinBudgetAgreeA ar a') - (hCharge : ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + (hCharge : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → ValidMachineTimeA σ1 → CurInvA σ1 → OffReadyA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → @@ -111,10 +111,11 @@ theorem JSyscallA.budgetOkSysA (r.1 = true → JSyscallA st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) r.2.1 r.2.2 τ m ∧ CounterStepA τ) ⦄ := by unfold syscall.budget_ok - refine WP.spec_bind (J.toJStage3A.timestampA J.sact J.noSwitch hvp P hClock hnd J.validTime C J.curInv - J.offReady J.actIdle hNow hAr) ?_ - rintro ⟨s1, a1⟩ ⟨σ1, e1, J1, sa1, -, V1, CI1, R1, Act1, Cl1, Ent1⟩ - simp only [uncurry_apply_pair] + obtain ⟨⟨s1, a1⟩, hu, σ1, e1, J1, sa1, -, V1, CI1, R1, Act1, Cl1, Ent1⟩ := + spec_existsA (J.toJStage3A.timestampA J.sact J.noSwitch hvp P hClock hnd J.validTime C J.curInv + J.offReady J.actIdle hNow hAr) + rw [hu, bind_ok] + try simp only [uncurry_apply_pair] obtain ⟨b, dec, spec, off⟩ := spec_existsA (entryBudgetDecisionA J1.sr.toSchedSRN CI1 J1.sinv.mc a1 (hmb a1)) have lift' : ∀ (r : Bool) (τ : State Unit), fl4CheckBudgetRestart (Z := Unit) σ1 = ({(r, τ)}, False) → @@ -123,7 +124,7 @@ theorem JSyscallA.budgetOkSysA rw [nd_bind_oneSc e1] exact h cases b - · refine WP.spec_mono (hCharge s1 a1 σ1 e1 J1 (Ent1 J.chargeEntryA) V1 CI1 R1 Act1 Cl1 spec) ?_ + · refine WP.spec_mono (hCharge s1 a1 σ1 hu e1 J1 (Ent1 J.chargeEntryA) V1 CI1 R1 Act1 Cl1 spec) ?_ rintro r ⟨τ, h, Q⟩ refine ⟨τ, lift' _ _ h, Q, fun hr => ?_⟩ have := fl4CheckBudgetRestart_falseA spec (r := (r.1, τ)) (by rw [h]; exact Set.mem_singleton _) @@ -180,7 +181,7 @@ theorem JSyscallA.budgetOkTrueA (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) (hAr : sched.update_timestamp st ar s a ⦃ r => AR' r.2 Z.hw ⦄) (hmb : ∀ a', Fl4MinBudgetAgreeA ar a') - (hCharge : ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + (hCharge : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → ValidMachineTimeA σ1 → CurInvA σ1 → OffReadyA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryChargeA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryChargeA.lean index f8aaf2a72..812881687 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryChargeA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryChargeA.lean @@ -198,7 +198,7 @@ theorem chargeSteps_shapeA {σ τ : State Unit} (hS : ChargeStepsA σ τ) obtain ⟨y, n, hy, hS, hR⟩ := hS rcases hS with ⟨hsch, σ3, hreq, hres⟩ | ⟨-, rfl⟩ swap - · exact ⟨rfl, rfl, rfl, rfl, ⟨y, n, rfl⟩, Or.inl ⟨rfl, rfl, rfl⟩, fun g => hR g, ⟨rfl, rfl, rfl, rfl⟩⟩ + · exact ⟨rfl, rfl, rfl, rfl, ⟨y, n, rfl⟩, Or.inl ⟨rfl, rfl, rfl⟩, fun g => hR g, DomKeepA.ofKey rfl⟩ have hp : ∀ z k, (updKSc σ σ.curSc (.schedContext y n)).kheap σ.curSc = some (.schedContext z k) → z.scTcb = some σ.curThread := by intro z k hz @@ -223,7 +223,7 @@ theorem chargeSteps_shapeA {σ τ : State Unit} (hS : ChargeStepsA σ τ) have Q4 : QKeepA σ3 { σ4 with reprogramTimer := true } := (show PresR QKeepA reschedReprogA by unfold reschedReprogA; qpres) σ3 _ hmem0 have hD : DomKeepA σ { σ4 with reprogramTimer := true } := - (⟨rfl, rfl, rfl, rfl⟩ : DomKeepA σ { updKSc σ σ.curSc (.schedContext y n) with consumedTime := 0 }).trans + (DomKeepA.ofKey rfl : DomKeepA σ { updKSc σ σ.curSc (.schedContext y n) with consumedTime := 0 }).trans (Q3.dom.trans Q4.dom) have hQ1 : σ4 = { σ3 with readyQueues := σ4.readyQueues, schedulerAction := σ4.schedulerAction } := hQ.1 have k4 : σ4.kheap = σ3.kheap := by rw [hQ1] @@ -674,7 +674,7 @@ theorem kentryChargeIrqA {AR' : A → HwRootA → Prop} {Clock : A → MachineSt (T : ∀ s1 a1 σ1, JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → EntryValidFromA (st := st) Z m κ Clock s1 σ1) (hA : P0.ArchTotal ar) - (hSend : ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + (hSend : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → CurInvA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → @@ -685,7 +685,7 @@ theorem kentryChargeIrqA {AR' : A → HwRootA → Prop} {Clock : A → MachineSt r.2.1 r.2.2 τ ⦄) : KEntryChargeA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s a σ (sched.check_budget st ar) fl4CheckBudget := by - intro s1 a1 σ1 e1 J1 En1 V1 CI1 R1 Act1 Cl1 hex + intro s1 a1 σ1 hu e1 J1 En1 V1 CI1 R1 Act1 Cl1 hex have eσ1 : σ1 = fl4TimestampState (rawNextA σ.machineState) { σ with machineState := rawStateA σ.machineState } := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst ((fl4UpdateTimestamp_eqA σ).symm.trans e1)))).2.symm have sw1 : ∀ u, σ1.schedulerAction ≠ .switchThread u := by rw [eσ1]; exact noSwitch @@ -695,7 +695,7 @@ theorem kentryChargeIrqA {AR' : A → HwRootA → Prop} {Clock : A → MachineSt (hmb a1) (hLimit a1) hex hns hA En1) ?_ rintro r ⟨τ, h, Q, -⟩ exact ⟨τ, h, Q⟩ - · exact hSend s1 a1 σ1 e1 J1 En1 CI1 Act1 Cl1 hex hns + · exact hSend s1 a1 σ1 hu e1 J1 En1 CI1 Act1 Cl1 hex hns end rec @@ -744,7 +744,7 @@ theorem ChargeShapeA.consumedA {σ τ1 τ : State Unit} (S : ChargeShapeA σ τ1 exact g z j h obtain ⟨y, n, hkh⟩ := S.kh refine ⟨S.cur, S.idle, S.csc, S.irq, ⟨y', n', ?_⟩, ?_, fun g => rdy (S.rdy g), - ⟨S.dom.index, S.dom.start, S.dom.table, S.dom.gvs⟩⟩ + DomKeepA.ofKey S.dom.key⟩ · simp only [updKSc_kheap] at hkh ⊢ rw [hkh, Function.update_idem] · rcases S.q with h | ⟨h1, act, nrel, ⟨x, hx, hr⟩, h5⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryFaultA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryFaultA.lean index 8b75da0ac..bddacfa22 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryFaultA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryFaultA.lean @@ -231,7 +231,7 @@ private theorem faultBudgetA (hPl : ArchPlat ar) syscall.budget_ok st ar s a ⦃ r => ∃ τ, fl4BudgetOk (Z := Unit) σ = ({(r.1, τ)}, False) ∧ FaultEndA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m r.2.1 r.2.2 τ ⦄ := WP.spec_mono (I.J.budgetOkSysA I.hvp I.P I.hClock I.hnd I.C I.hC I.hNow I.hAr I.hmb - (fun s1 a1 σ1 e J1 En V CI R Act Cl suf => hCharge s1 a1 σ1 e J1 En V CI R Act Cl suf)) fun r h => by + (fun s1 a1 σ1 hu e J1 En V CI R Act Cl suf => hCharge s1 a1 σ1 hu e J1 En V CI R Act Cl suf)) fun r h => by obtain ⟨τ, e, Q, hs⟩ := h refine ⟨τ, e, ⟨stack, Q⟩, ?_⟩ obtain ⟨b, s1, a1⟩ := r @@ -259,7 +259,7 @@ theorem userException_recFA (hPl : ArchPlat ar) (Env : FaultEnvA st ar Z) (numbe userExceptionEntry_refinesA number code limit view (faultBudgetA hPl I hCharge) (fun s' a' τ eq bspec _ => by have JS := I.J.budgetOkTrueA I.hvp I.P I.hClock I.hnd I.C I.hC I.hNow I.hAr I.hmb - (fun s1 a1 σ1 e J1 En V CI R Act Cl suf => hCharge s1 a1 σ1 e J1 En V CI R Act Cl suf) eq bspec |>.1 + (fun s1 a1 σ1 hu e J1 En V CI R Act Cl suf => hCharge s1 a1 σ1 hu e J1 En V CI R Act Cl suf) eq bspec |>.1 exact WP.spec_mono (JS.deliverFaultA hPl Env (usrFault_userA (L.curW s') number code) (fun _ _ => trivial) (hcase s' a' τ JS)) fun _ ⟨υ, mem, h, B⟩ => ⟨υ, mem, h, B.1⟩) (fun s' a' τ mem h => finish s' a' τ mem h.1 h.2) @@ -284,7 +284,7 @@ theorem vmFault_recFA (hPl : ArchPlat ar) (Env : FaultEnvA st ar Z) (addr esr : vmFaultEntry_refinesA addr esr limit view (faultBudgetA hPl I hCharge) (fun s' a' τ eq bspec _ => by have JS := I.J.budgetOkTrueA I.hvp I.P I.hClock I.hnd I.C I.hC I.hNow I.hAr I.hmb - (fun s1 a1 σ1 e J1 En V CI R Act Cl suf => hCharge s1 a1 σ1 e J1 En V CI R Act Cl suf) eq bspec |>.1 + (fun s1 a1 σ1 hu e J1 En V CI R Act Cl suf => hCharge s1 a1 σ1 hu e J1 En V CI R Act Cl suf) eq bspec |>.1 exact WP.spec_mono (JS.deliverFaultA hPl Env (usrFault_vmA (L.curW s') addr esr) (fun _ _ => trivial) (hcase s' a' τ JS)) fun _ ⟨υ, mem, h, B⟩ => ⟨υ, mem, h, B.1⟩) (fun s' a' τ mem h => finish s' a' τ mem h.1 h.2) @@ -314,7 +314,7 @@ theorem unknownSyscall_recFA (hPl : ArchPlat ar) (Env : FaultEnvA st ar Z) (numb unknownSyscallFault_refinesA number limit view (faultBudgetA hPl I hCharge) (fun s' a' τ eq bspec _ => by have JS := I.J.budgetOkTrueA I.hvp I.P I.hClock I.hnd I.C I.hC I.hNow I.hAr I.hmb - (fun s1 a1 σ1 e J1 En V CI R Act Cl suf => hCharge s1 a1 σ1 e J1 En V CI R Act Cl suf) eq bspec |>.1 + (fun s1 a1 σ1 hu e J1 En V CI R Act Cl suf => hCharge s1 a1 σ1 hu e J1 En V CI R Act Cl suf) eq bspec |>.1 refine WP.spec_mono (JS.deliverFaultA hPl Env (usrFault_unkA (L.curW s') number) (fun rbo x => Or.inr ?_) (hcase s' a' τ JS)) fun _ ⟨υ, mem, h, B⟩ => ⟨υ, mem, h, B.1⟩ rw [faultWords_tflA JS.sr.core.tcbs JS.sr.curT] diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryFaultFinA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryFaultFinA.lean index 09a3cc4d3..761781850 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryFaultFinA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryFaultFinA.lean @@ -77,8 +77,10 @@ theorem FaultRelA.finishA {tm : A → Nat → DeadlineViewA} {view : State Unit have I := F stack' Q Rl curOf curScOf J have hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = MIN_BUDGET ⦄ := fun a => WP.spec_mono (I.hGap.ticks a).minBudget fun _ h => h.trans I.hGap.minAgree - exact JStage3A.finishEA (Z := { Z with Q := Q, R := Rl, curOf := curOf, curScOf := curScOf }) hA hPl arch hCs P.h1 J - B.sw B.toBodyExitA (JStage3A.fireSigA hA hPl hCs P.h1 hmb P.hmax P.htu) I.hGap P.arK P.toUs I.hNative + refine WP.spec_mono (JStage3A.finishEA (Z := { Z with Q := Q, R := Rl, curOf := curOf, curScOf := curScOf }) hA hPl arch hCs P.h1 J + B.sw B.toBodyExitA (JStage3A.fireSigA hA hPl hCs P.h1 hmb P.hmax P.htu) I.hGap P.arK P.toUs I.hNative) ?_ + rintro r ⟨τ, hm, k⟩ + exact ⟨τ, hm, KExitA.ofSame st ar k⟩ end finish @@ -167,12 +169,12 @@ theorem kernelEntry_recA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (arch : Arch (hbody : kBodyA st ar s a e ⦃ r => StepPostA (fun s' a' τ => FaultRelA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m s' a' τ ∧ BodyOKA τ m) (kOpA e) σ r ⦄) - (hFin : ∀ s' a' τ, ((), τ) ∈ (kOpA e σ).1 → + (hFin : ∀ s' a' τ, kBodyA st ar s a e = ok (s', a') → ((), τ) ∈ (kOpA e σ).1 → FinishAtA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf κ m tm view hPl s' a' τ) : kCodeA st ar s a e ⦃ out => StepPostA (KExitA st ar AR hPl.ipa m) (kOpA e >>= fun _ => fl4Finish kLimitA view) σ out ⦄ := - kernelEntry_stage3A s a σ e run hbody fun r τ _ op RB => - FaultRelA.finishA hA hPl arch hCs P RB.1 RB.2 (hFin r.1 r.2 τ op) + kernelEntry_stage3A s a σ e run hbody fun r τ eb op RB => + FaultRelA.finishA hA hPl arch hCs P RB.1 RB.2 (hFin r.1 r.2 τ eb op) end top diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryFinishA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryFinishA.lean index 4041a6d47..8c69e49be 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryFinishA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryFinishA.lean @@ -21,6 +21,7 @@ New module. import Fl4ProofsA64.P3.Stage3FireRecordA import Fl4ProofsA64.P3.Stage3SchedSchedA import Fl4ProofsA64.P3.Stage3ExitAtA +import Fl4ProofsA64.P3.McGrowA import Fl4ProofsA64.P3.OuterEntryA open Aeneas Aeneas.Std Result @@ -79,7 +80,7 @@ variable (st) (ar) /-- **The next entry's record**: `JStage3EntryA` at some ghost sets, and `JSyscallA` when the current thread is not the idle thread. -/ -def KExitA (AR : A → HwRootA → Prop) (nA : U64) (m : McState) (s : S) (a : A) (σ : State Unit) : Prop := +def KExitAt (AR : A → HwRootA → Prop) (nA : U64) (m : McState) (s : S) (a : A) (σ : State Unit) : Prop := ∃ (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64), JStage3EntryA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) @@ -88,6 +89,17 @@ def KExitA (AR : A → HwRootA → Prop) (nA : U64) (m : McState) (s : S) (a : A JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) +/-- **The next entry's record at some grown view** (R1): `KExitAt` at a `McGrowA`-grown `m'`. A Retype that creates +a TCB changes the ghost `McState`; every other body keeps it (`McGrowA.refl`). -/ +def KExitA (AR : A → HwRootA → Prop) (nA : U64) (m : McState) (s : S) (a : A) (σ : State Unit) : Prop := + ∃ m' : McState, McGrowA m m' ∧ KExitAt st ar AR nA m' s a σ + +theorem KExitA.ofAt {AR : A → HwRootA → Prop} {nA : U64} {m m' : McState} {s : S} {a : A} {σ : State Unit} + (hg : McGrowA m m') (h : KExitAt st ar AR nA m' s a σ) : KExitA st ar AR nA m s a σ := ⟨m', hg, h⟩ + +theorem KExitA.ofSame {AR : A → HwRootA → Prop} {nA : U64} {m : McState} {s : S} {a : A} {σ : State Unit} + (h : KExitAt st ar AR nA m s a σ) : KExitA st ar AR nA m s a σ := ⟨m, McGrowA.refl m, h⟩ + end /-- **`syscall.finish` at the record** (module docstring). -/ @@ -131,7 +143,7 @@ theorem JStage3A.finishA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} { (τ2.curThread ≠ τ2.idleThread → ∀ y, τ1.kheap τ1.curThread = some (.tcb y) → y.tcbState ≠ .idleThreadState)) : syscall.finish st ar s a ⦃ r => - StepPostA (KExitA st ar AR hPl.ipa m) (fl4Finish kLimitA view) σ r ⦄ := by + StepPostA (KExitAt st ar AR hPl.ipa m) (fl4Finish kLimitA view) σ r ⦄ := by have hcore : m.curCore < fl4A64Platform.numNodes := by rw [J.sr.sch.core]; exact hCs _ J.sr.sch.cpuCs have F := JStage3A.fire_recA hA hPl J hcore hSw hSig diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryFinishFA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryFinishFA.lean index 5e3b2e8fa..319442d75 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryFinishFA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryFinishFA.lean @@ -71,7 +71,7 @@ theorem JStage3A.finishFA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (τ2.curThread ≠ τ2.idleThread → ∀ y, τ1.kheap τ1.curThread = some (.tcb y) → y.tcbState ≠ .idleThreadState)) : syscall.finish st ar s a ⦃ r => - StepPostA (KExitA st ar AR hPl.ipa m) (fl4Finish kLimitA view) σ r ⦄ := by + StepPostA (KExitAt st ar AR hPl.ipa m) (fl4Finish kLimitA view) σ r ⦄ := by have hcore : m.curCore < fl4A64Platform.numNodes := by rw [J.sr.sch.core]; exact hCs _ J.sr.sch.cpuCs have T := JStage3A.scheduleRecFFA hA hPl arch hCs h1 J (JStage3A.fire_budgetA hA hPl J hcore hSw B hSig) G arK diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryIrqBodyA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryIrqBodyA.lean new file mode 100644 index 000000000..2b0745d02 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryIrqBodyA.lean @@ -0,0 +1,230 @@ +/- +P3 (aarch64, A64-P4 irqtop, S1-S2): **the interrupt entry's body at the record, ending in `A64RelS3`.** + +* `JStage3A.irqBudgetEndA`: `irqBudgetA` (`update_timestamp`, `check_budget`) with `Sched.BodyOKA` at the state it + reaches: a sufficient head leaves the timestamped state (`BodyOKA` from the entry's `OffReadyA`, `SActA`'s + successor facts and `JStage3A.ownerA`); an exhausted head is the charge (`bodyOKA_chargedA`). +* `OracleIrqA`, `getActiveIRQ_memA`: the spec's `getActiveIRQ false` yields `irq` at the post-budget state. +* `interruptBodyA`: `kBodyA (.interrupt irq (fl4MaybeHandleInterrupt false))` refines `kOpA` and ends in the record + `A64RelS3` (with `BodyOKA`), so `kernelEntry_recGA` applies at `.interrupt` (`P3/Stage3KEntryIrqTopA`). + +Named premises: [P] `IrqArchA ar AR' True`, `hMax`, `ArchTotal`, `ArchPlat`, `v2`, `hmb`, `hmax`, `htu`; [S] `hCs`, +`numNodes = 1`; [J] `hCharge` (`KEntryChargeA` at `check_budget`), `hct` (the entry's current thread is in an +activatable state when resuming), `hsch` (an exhausted head only at a schedulable current thread); `line` ([J] +`active`, [S] `noResched`, [P]/[J] `reserved`), `orc` ([P] the oracle yields `irq`; [J] the line is unmasked). +New module. +-/ +import Fl4ProofsA64.P3.Stage3AfterPreemptA +import Fl4ProofsA64.P3.Stage3KEntryArmsA +import Fl4ProofsA64.P3.Stage3SysTopA +import Fl4ProofsA64.P3.Stage3YieldBodyA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR AR' : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {nA : U64} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 2000000 in +/-- **The interrupt entry's budget prefix ends in the body-end facts** (module docstring). -/ +theorem JStage3A.irqBudgetEndA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar nA)) s a σ m) + (sact : SActA σ) (noSwitch : ∀ u, σ.schedulerAction ≠ .switchThread u) + (hvp : ∀ b, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ ¬ PPW st s b) + {Clock : A → MachineState → Prop} (P : NowAgreeA ar Clock) (hClock : Clock a σ.machineState) + (hnd : numDomains = 1) (V : ValidMachineTimeA σ) (C : CounterStepA σ) (CI : CurInvA σ) (R : OffReadyA σ) + (Act : ActIdleA σ) (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) + (hAr : sched.update_timestamp st ar s a ⦃ r => AR' r.2 Z.hw ⦄) + (hmb : ∀ a', Fl4MinBudgetAgreeA ar a') (hEnt : ChargeEntryA st Ac s) + (hni : σ.curSc ≠ idleScPtr → NotIdleScA m σ.curSc) + (hct : σ.schedulerAction = .resumeCurThread → ∀ x, σ.kheap σ.curThread = some (.tcb x) → + ActivateStateOKA x.tcbState) + (hsch : ∀ σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(false, σ1)}, False) → + schedulable σ1.curThread σ1 = true) + (hCharge : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → + fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → + ValidMachineTimeA σ1 → CurInvA σ1 → OffReadyA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(false, σ1)}, False) → + sched.check_budget st ar s1 a1 ⦃ r => ∃ τ, + fl4CheckBudget (Z := Unit) σ1 = ({(r.1, τ)}, False) ∧ + JStage3QA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes nA m + r.2.1 r.2.2 τ ⦄) : + (do let (s1, a1) ← sched.update_timestamp st ar s a; sched.check_budget st ar s1 a1) ⦃ r => ∃ τ, + ((fl4UpdateTimestamp (Z := Unit)) >>= fun _ => fl4CheckBudget) σ = ({(r.1, τ)}, False) ∧ + JStage3QA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes nA m + r.2.1 r.2.2 τ ∧ BodyOKA τ m ⦄ := by + obtain ⟨⟨s1, a1⟩, hu, σ1, e1, J1, sact1, sw1, V1, CI1, R1, Act1, Cl1, Ent1⟩ := + spec_existsA (J.timestampA sact noSwitch hvp P hClock hnd V C CI R Act hNow hAr) + rw [hu, bind_ok] + try simp only [uncurry_apply_pair] + have eσ1 : σ1 = fl4TimestampState (rawNextA σ.machineState) { σ with machineState := rawStateA σ.machineState } := + (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst ((fl4UpdateTimestamp_eqA σ).symm.trans + e1)))).2.symm + have csc : σ1.curSc = σ.curSc := by rw [eσ1]; rfl + have act1 : σ1.schedulerAction = σ.schedulerAction := by rw [eσ1]; rfl + have ct1 : σ1.curThread = σ.curThread := by rw [eσ1]; rfl + have kh1 : σ1.kheap = σ.kheap := by rw [eσ1]; rfl + have hni1 : σ1.curSc ≠ idleScPtr → NotIdleScA m σ1.curSc := by rw [csc]; exact hni + obtain ⟨b, dec, spec, off⟩ := spec_existsA (entryBudgetDecisionA J1.sr.toSchedSRN CI1 J1.sinv.mc a1 (hmb a1)) + cases b + · refine WP.spec_mono (hCharge s1 a1 σ1 hu e1 J1 (Ent1 hEnt) V1 CI1 R1 Act1 Cl1 spec) ?_ + rintro r ⟨τ, h, Q⟩ + exact ⟨τ, by rw [nd_bind_oneSc e1]; exact h, Q, + bodyOKA_chargedA V1 hni1 (fl4CheckBudget_chargedA (hsch σ1 e1 spec) spec h)⟩ + · obtain ⟨code, cb⟩ := budgetSuffA (st := st) (ar := ar) dec spec hnd + rw [code, WP.spec_ok] + refine ⟨σ1, by rw [nd_bind_oneSc e1]; exact cb, J1.toQA, ?_⟩ + exact ⟨⟨V1, fun y n _ _ _ => ⟨R1, off rfl R1⟩, fun hr x hx => + hct (by rw [← act1]; exact hr) x (by rw [← kh1, ← ct1]; exact hx)⟩, + fun t e => absurd e (sw1 t), fun h => hni1 h, + fun y k hk _ _ hc o ho => J1.ownerA y k hk hc o ho⟩ + +end + +/-! ## The oracle -/ + +/-- [P] / [J] **The accepted interrupt is the spec's active IRQ** at the post-budget state: the oracle's next value +is `irq` ([P], the hardware's acknowledge is the spec's oracle) and the line is not masked ([J]). -/ +def OracleIrqA (irq : U64) (σ : State Unit) : Prop := + irqOracle (σ.machineState.irqState + 1) = BitVec.ofNat 13 irq.val ∧ + σ.machineState.irqMasks (BitVec.ofNat 13 irq.val) = false + +/-- [P] **The accepted line is neither VGIC maintenance nor a virtual-timer event** (the entry glue: `entry.rs` +`classify_irq_under_gate` hands only the other lines to `handle_interrupt_entry`; ratified A64 P4, replaces the [S] +`IrqLineA.reserved` at the interrupt entry). A statement about the number alone. -/ +def EntryIrqAgreeA (irq : U64) : Prop := + irq.val < 5376 → (BitVec.ofNat 13 irq.val : Irq) ≠ irqVGICMaintenance ∧ + irqVppiEventIndex (BitVec.ofNat 13 irq.val) = none + +/-- The machine state after `getActiveIRQ false` accepted a line: only the oracle counter moved. -/ +def irqBumpA (ms : MachineState) : MachineState := { ms with irqState := ms.irqState + 1 } + +theorem getActiveIRQ_evalA (ms : MachineState) (i : Irq) (ho : irqOracle (ms.irqState + 1) = i) + (hm : ms.irqMasks i = false) : + ((some i, irqBumpA ms) ∈ (getActiveIRQ false ms).1) := by + unfold getActiveIRQ irqBumpA + simp [NonDet.gets, NonDet.modify, NonDet.bind, NonDet.pure, Function.comp, ho, hm, Bind.bind, Pure.pure] + +theorem getActiveIRQ_memA (σ : State Unit) (i : Irq) (ho : irqOracle (σ.machineState.irqState + 1) = i) + (hm : σ.machineState.irqMasks i = false) : + (some i, { σ with machineState := irqBumpA σ.machineState }) ∈ (doMachineOp (Z := Unit) (getActiveIRQ false) σ).1 := by + unfold doMachineOp + rw [nd_gets_bindA] + refine mem_bind_ndD (x := ((some i, irqBumpA σ.machineState), σ)) ?_ ?_ + · exact ⟨getActiveIRQ_evalA _ i ho hm, rfl⟩ + · change (some i, {σ with machineState := irqBumpA σ.machineState}) ∈ + ((NonDet.modify (fun state : State Unit => {state with machineState := irqBumpA σ.machineState}) >>= fun _ => + NonDet.pure (some i)) σ).1 + rw [nd_modify_bindA] + rfl + +/-! ## The body -/ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR AR' : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 4000000 in +/-- **The interrupt entry's body at the record** (module docstring). -/ +theorem interruptBodyA {Cs : Set U64} {Clock : A → MachineState → Prop} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (IE : IrqEnvA ar AR') + (h1 : fl4A64Platform.numNodes = 1) + (hCs : ∀ c ∈ Cs, c.val < fl4A64Platform.numNodes) (hZ : Z.Cs = Cs) + (hmbA : ∀ a', Fl4MinBudgetAgreeA ar a') (hag : fl4MinBudget = MIN_BUDGET) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (v2 : config_ARM_GIC_V3 = false) (irq : U64) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (sact : SActA σ) (noSwitch : ∀ u, σ.schedulerAction ≠ .switchThread u) + (hvp : ∀ b, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ ¬ PPW st s b) + (P : NowAgreeA ar Clock) (hClock : Clock a σ.machineState) + (hnd : numDomains = 1) (V : ValidMachineTimeA σ) (C : CounterStepA σ) (CI : CurInvA σ) (R : OffReadyA σ) + (Act : ActIdleA σ) (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) + (hAr : sched.update_timestamp st ar s a ⦃ r => AR' r.2 Z.hw ⦄) + (hEnt : ChargeEntryA st Ac s) + (hni : σ.curSc ≠ idleScPtr → NotIdleScA m σ.curSc) + (hct : σ.schedulerAction = .resumeCurThread → ∀ x, σ.kheap σ.curThread = some (.tcb x) → + ActivateStateOKA x.tcbState) + (hsch : ∀ σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(false, σ1)}, False) → + schedulable σ1.curThread σ1 = true) + (hCharge : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → + fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → + ValidMachineTimeA σ1 → CurInvA σ1 → OffReadyA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(false, σ1)}, False) → + sched.check_budget st ar s1 a1 ⦃ r => ∃ τ, + fl4CheckBudget (Z := Unit) σ1 = ({(r.1, τ)}, False) ∧ + JStage3QA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes hPl.ipa m + r.2.1 r.2.2 τ ⦄) + (line : ∀ b s' a' τ, + (do let (s0, a0) ← sched.update_timestamp st ar s a; sched.check_budget st ar s0 a0) = ok (b, s', a') → + ((fl4UpdateTimestamp (Z := Unit)) >>= fun _ => fl4CheckBudget) σ = ({(b, τ)}, False) → + IrqLineBaseA st s' irq) + (hres : EntryIrqAgreeA irq) + (orc : ∀ b s' a' τ, + (do let (s0, a0) ← sched.update_timestamp st ar s a; sched.check_budget st ar s0 a0) = ok (b, s', a') → + ((fl4UpdateTimestamp (Z := Unit)) >>= fun _ => fl4CheckBudget) σ = ({(b, τ)}, False) → + OracleIrqA irq τ) : + kBodyA st ar s a (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) ⦃ r => + StepPostA (fun s' a' τ => A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m) + (kOpA (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false))) σ r ⦄ := by + have budget := J.irqBudgetEndA sact noSwitch hvp P hClock hnd V C CI R Act hNow hAr hmbA hEnt hni hct hsch hCharge + have e : kBodyA st ar s a (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) = + (do let (_, s', a') ← (do let (s0, a0) ← sched.update_timestamp st ar s a; sched.check_budget st ar s0 a0) + interrupt.handle_interrupt st ar s' a' irq) := by + simp only [kBodyA, Std.bind_assoc, uncurry_apply_pair] + first | (congr 1; done) | (congr 1; funext x; obtain ⟨_, _⟩ := x; rfl) + rw [e] + refine WP.spec_bind (reachedResultA budget) ?_ + rintro ⟨b, s', a'⟩ ⟨budgetEq, τ, bspec, JQ, B0⟩ + simp only [uncurry_apply_pair] + obtain ⟨Q1, Rl1, co1, cs1, J0⟩ := JQ + have Ln : IrqLineA st s' irq := (line b s' a' τ budgetEq bspec).toLine hres + obtain ⟨hor, hom⟩ := orc b s' a' τ budgetEq bspec + have hCs' : ∀ c ∈ ({ Z with Q := Q1, R := Rl1, curOf := co1, curScOf := cs1 } : XSetsA).Cs, + c.val < fl4A64Platform.numNodes := fun c hc => hCs c (hZ ▸ hc) + have J1 := J0.of_machA J0.j.1.ar (irqBumpA τ.machineState) rfl + have J' := J1.arSwapA (AR' := withMRA AR' (fun _ _ => True) (irqBumpA τ.machineState)) ⟨J0.j.1.ar, trivial⟩ + have B1 : BodyOKA { τ with machineState := irqBumpA τ.machineState } m := B0.msA rfl + refine WP.spec_mono (J'.handleInterruptA hA hPl IE.K hCs' h1 IE.hMax + (fun a'' => WP.spec_mono (hmbA a'') fun mb h => h.trans hag) hmax htu irq Ln) ?_ + rintro r ⟨σ'', mem2, ⟨Q2, Rl2, co2, cs2, J2⟩, sw, bd, hcs⟩ + have B2 : BodyOKA σ'' m := + ⟨bd B1.toBodyExitA, sw B1.sw, fun h => by rw [hcs] at h ⊢; exact B1.scNotIdle h, + fun y k hk _ _ hc o ho => J2.ownerA y k hk hc o ho⟩ + refine ⟨σ'', ?_, A64RelS3.ofJ (J2.arSwapA (AR' := AR') J2.j.1.ar.1) B2 hZ⟩ + show ((), σ'') ∈ ((fl4AcceptedIrqBody (fl4MaybeHandleInterrupt (Z := Unit) false)) σ).1 + unfold fl4AcceptedIrqBody + rw [← nd_bind_assocSc, nd_bind_oneSc bspec] + unfold fl4MaybeHandleInterrupt + refine mem_bind_ndD (x := (some (BitVec.ofNat 13 irq.val), + ({ τ with machineState := irqBumpA τ.machineState } : State Unit))) + (getActiveIRQ_memA τ _ hor hom) ?_ + have e := congrFun (fl4HandleInterrupt_eq_l4v (Z := Unit) v2 (BitVec.ofNat 13 irq.val)) + ({ τ with machineState := irqBumpA τ.machineState } : State Unit) + show ((), σ'') ∈ (fl4HandleInterrupt (Z := Unit) (BitVec.ofNat 13 irq.val) + ({ τ with machineState := irqBumpA τ.machineState } : State Unit)).1 + rw [e] + exact mem2 + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryIrqTopA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryIrqTopA.lean new file mode 100644 index 000000000..b32fca128 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryIrqTopA.lean @@ -0,0 +1,107 @@ +/- +P3 (aarch64, A64-P4 irqtop, S3-S4): **the interrupt kernel-entry top.** + +* `fl4CallKernel_interruptA`: the spec's `call_kernel` for the interrupt event is `fl4AcceptedIrqBody` of + `fl4MaybeHandleInterrupt false` followed by `fl4Finish` (`handleE` of a `liftE` is the body; the handler is dead). +* `kernelEntryIrq_recGA`: `kernelEntry_recGA` at `.interrupt`: FL4's `handle_interrupt_entry` refines the spec's + `call_kernel` interrupt path and the next entry's record holds (`KExitA`). Its `hbody` is `interruptBodyA`. + +Named premises: those of `interruptBodyA` (`P3/Stage3KEntryIrqBodyA`) and of `kernelEntry_recGA` ([P] `ArchSwFA`, +`FinPlatA`; [J] `hGap`; [S4] `hNat`). New module. +-/ +import Fl4ProofsA64.P3.Stage3KEntryIrqBodyA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +/-- **The spec's interrupt `call_kernel`** (module docstring). -/ +theorem fl4CallKernel_interruptA (limit : Nat) (view : State Unit → Fl4TimerView) : + fl4CallKernel (Z := Unit) limit view false .interrupt = + (fl4AcceptedIrqBody (fl4MaybeHandleInterrupt (Z := Unit) false) >>= fun _ => fl4Finish limit view) := by + funext σ + unfold fl4CallKernel fl4HandleEvent withoutPreemption fl4AcceptedIrqBody fl4Finish + simp only [NonDetE.handleE, NonDetE.liftE, ExceptT.run_mk, ExceptT.run_lift] + have bb : ∀ {α β : Type} (m : NonDet (State Unit) α) (f : α → NonDet (State Unit) β), + NonDet.bind m f = (m >>= f) := fun _ _ => rfl + have mm : ∀ {α β : Type} (f : α → β) (m : NonDet (State Unit) α), + (f <$> m) = (m >>= fun a => pure (f a)) := fun _ _ => rfl + simp only [bb, mm] + rw [nd_bind_assocSc, nd_bind_assocSc] + have pp : ∀ {α : Type} (a : α), (NonDet.pure a : NonDet (State Unit) α) = pure a := fun _ => rfl + simp only [pp, nd_pure_bindA] + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR AR' : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 4000000 in +/-- **The interrupt kernel-entry top** (module docstring). -/ +theorem kernelEntryIrq_recGA {Cs : Set U64} {Clock : A → MachineState → Prop} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (IE : IrqEnvA ar AR') + (h1 : fl4A64Platform.numNodes = 1) + (hCs : ∀ c ∈ Cs, c.val < fl4A64Platform.numNodes) (hZ : Z.Cs = Cs) + (hmbA : ∀ a', Fl4MinBudgetAgreeA ar a') (hag : fl4MinBudget = MIN_BUDGET) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (v2 : config_ARM_GIC_V3 = false) (irq : U64) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (sact : SActA σ) (noSwitch : ∀ u, σ.schedulerAction ≠ .switchThread u) + (hvp : ∀ b, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ ¬ PPW st s b) + (P : NowAgreeA ar Clock) (hClock : Clock a σ.machineState) + (hnd : numDomains = 1) (V : ValidMachineTimeA σ) (C : CounterStepA σ) (CI : CurInvA σ) (R : OffReadyA σ) + (Act : ActIdleA σ) (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) + (hAr : sched.update_timestamp st ar s a ⦃ r => AR' r.2 Z.hw ⦄) + (hEnt : ChargeEntryA st Ac s) + (hni : σ.curSc ≠ idleScPtr → NotIdleScA m σ.curSc) + (hct : σ.schedulerAction = .resumeCurThread → ∀ x, σ.kheap σ.curThread = some (.tcb x) → + ActivateStateOKA x.tcbState) + (hsch : ∀ σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(false, σ1)}, False) → + schedulable σ1.curThread σ1 = true) + (hCharge : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → + fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → + ValidMachineTimeA σ1 → CurInvA σ1 → OffReadyA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → + fl4GetScRefillSufficient (Z := Unit) σ1.curSc σ1.consumedTime σ1 = ({(false, σ1)}, False) → + sched.check_budget st ar s1 a1 ⦃ r => ∃ τ, + fl4CheckBudget (Z := Unit) σ1 = ({(r.1, τ)}, False) ∧ + JStage3QA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes hPl.ipa m + r.2.1 r.2.2 τ ⦄) + (line : ∀ b s' a' τ, + (do let (s0, a0) ← sched.update_timestamp st ar s a; sched.check_budget st ar s0 a0) = ok (b, s', a') → + ((fl4UpdateTimestamp (Z := Unit)) >>= fun _ => fl4CheckBudget) σ = ({(b, τ)}, False) → + IrqLineBaseA st s' irq) + (hres : EntryIrqAgreeA irq) + (orc : ∀ b s' a' τ, + (do let (s0, a0) ← sched.update_timestamp st ar s a; sched.check_budget st ar s0 a0) = ok (b, s', a') → + ((fl4UpdateTimestamp (Z := Unit)) >>= fun _ => fl4CheckBudget) σ = ({(b, τ)}, False) → + OracleIrqA irq τ) + (arch : ArchSwFA st ar) (PF : FinPlatA ar AR') {tm : A → Nat → DeadlineViewA} {view : State Unit → Fl4TimerView} + (hGap : ∀ s' a' τ, kBodyA st ar s a (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) = ok (s', a') → + ((), τ) ∈ (kOpA (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) σ).1 → + ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view) + (hNat : ∀ s' a' τ, kBodyA st ar s a (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) = ok (s', a') → + ((), τ) ∈ (kOpA (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) σ).1 → + A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → ∀ τ1 τ2, + ((), τ1) ∈ (fl4Schedule kLimitA view τ).1 → ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → + ∀ y, τ2.kheap τ2.curThread = some (.tcb y) → y.tcbState ≠ .ext .runningVM) : + kCodeA st ar s a (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) ⦃ out => + StepPostA (KExitA st ar AR' hPl.ipa m) (fl4CallKernel kLimitA view false .interrupt) σ out ⦄ := by + rw [fl4CallKernel_interruptA] + exact kernelEntry_recGA hA hPl arch hCs PF s a σ (.interrupt irq (fl4MaybeHandleInterrupt (Z := Unit) false)) trivial + (interruptBodyA hA hPl IE h1 hCs hZ hmbA hag hmax htu v2 irq J sact noSwitch hvp P hClock hnd V C CI R Act hNow + hAr hEnt hni hct hsch hCharge line hres orc) hGap hNat + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryRestartA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryRestartA.lean index 4cd395846..8a66daf98 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryRestartA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryRestartA.lean @@ -227,7 +227,7 @@ theorem kentryChargeRestartA {AR' : A → HwRootA → Prop} {Clock : A → Machi (T : ∀ s1 a1 σ1, JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → EntryValidFromA (st := st) Z m κ Clock s1 σ1) (hA : P0.ArchTotal ar) - (hSend : ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + (hSend : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → CurInvA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → @@ -238,7 +238,7 @@ theorem kentryChargeRestartA {AR' : A → HwRootA → Prop} {Clock : A → Machi r.2.1 r.2.2 τ ⦄) : KEntryChargeA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s a σ (sched.check_budget_restart st ar) fl4CheckBudgetRestart := by - intro s1 a1 σ1 e1 J1 En1 V1 CI1 R1 Act1 Cl1 hex + intro s1 a1 σ1 hu e1 J1 En1 V1 CI1 R1 Act1 Cl1 hex have eσ1 : σ1 = fl4TimestampState (rawNextA σ.machineState) { σ with machineState := rawStateA σ.machineState } := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst ((fl4UpdateTimestamp_eqA σ).symm.trans e1)))).2.symm have sw1 : ∀ u, σ1.schedulerAction ≠ .switchThread u := by rw [eσ1]; exact noSwitch @@ -246,7 +246,7 @@ theorem kentryChargeRestartA {AR' : A → HwRootA → Prop} {Clock : A → Machi by_cases hns : NoTimeoutA σ1.consumedTime σ1 · exact J1.checkBudgetRestartNoSendA sw1 CI1 Act1 (J1.curScOnCoreA hCs one) ni1 Cl1 (T s1 a1 σ1 J1) hag (hmb a1) (hLimit a1) hex hns hA En1 - · exact hSend s1 a1 σ1 e1 J1 En1 CI1 Act1 Cl1 hex hns + · exact hSend s1 a1 σ1 hu e1 J1 En1 CI1 Act1 Cl1 hex hns end rec diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntrySchedA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntrySchedA.lean index b688950fb..e5448a814 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntrySchedA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntrySchedA.lean @@ -606,7 +606,7 @@ theorem JStage3A.acrossSchedA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He have hP := J1.iplaced have ep : EpStateRel Z.T E Rp Bf (L.mem s') τ := by exact J1.ep.frame hP.e (fun b ha hb => FD.wr.mem_eq ha fun h => - h.elim (endpFootOffWrite N1 J1.ipcPlace hb) (efoot_domA N1 J1.ipcPlace hb)) (epFrameOfMcsA (st := st) (s' := s1) N1 J1.ipcPlace ⟨WritesIn.refl _ _, FD.keep, FD.sz⟩ hum).2 + h.elim (endpFootOffWrite N1 J1.ipcPlace hb) (efoot_domA N1 J1.ipcPlace hb)) (epFrameOfMcsA (st := st) (s' := s1) N1 J1.ipcPlace (MFrA.ofParts (WritesIn.refl _ _) FD.keep FD.sz) hum).2 have kv : Notif.KView σ1 τ := by refine ⟨fun p x hx => SK.obj p _ hx (by intro _ _ e; cases e) (by intro _ e; cases e), fun p x hx => ?_⟩ exact ⟨x, tK p x hx, rfl, rfl, rfl⟩ @@ -864,7 +864,7 @@ theorem JStage3A.scheduleRecFA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : H rintro r ⟨run, s1, σ1, τ, Q, Rl, Tcur, Ccur, ⟨a1, Qf, Rf, ef, J1, R1, X1⟩, hf, tail, H3, F, SF, hcur, nd⟩ obtain ⟨hw, har⟩ := arK.schedule st ef ⟨_, J1.j.1.ar⟩ run have J2 := JStage3A.acrossSchedA hA hPl hcore J J1 R1 J1.sinv.ctQ run tail H3 - ⟨F.wr, F.keep, F.sz⟩ SF (nd _ _ J1.sr.toSchedSRN J1.domOK) hcur har + (MFrDA.ofParts F.wr F.keep F.sz) SF (nd _ _ J1.sr.toSchedSRN J1.domOK) hcur har exact ⟨(s1, a1), σ1, τ, Qf, Rf, Q, Rl, Tcur, Ccur, hw, ef, J1, R1, X1, hf, tail, fl4Schedule_of_tail kLimitA view hf tail, H3, J2⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntrySendA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntrySendA.lean index 74abf2d4f..ac8bda49b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntrySendA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntrySendA.lean @@ -594,8 +594,8 @@ theorem JStage3A.chargeSendRecvCoreA have Qs : QSendA σ τ3 := by have Qh : QKeepA σ τ := (QKeepA.upd hx0 (QObjA.ofSc (y := yh) fun h => - ⟨by rwa [hrep'] at h, fun a => (scActive_of_maxA hrm').trans a⟩)).trans (QKeepA.of_kheap τkh ⟨by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl⟩) - have Qf : QKeepA τ σ1 := (QKeepA.upd hkτ (QObjA.ofTcb (y := x1) rfl)).trans (QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩) + ⟨by rwa [hrep'] at h, fun a => (scActive_of_maxA hrm').trans a⟩)).trans (QKeepA.of_kheap τkh (DomKeepA.ofKey (by rw [hτ]; rfl))) + have Qf : QKeepA τ σ1 := (QKeepA.upd hkτ (QObjA.ofTcb (y := x1) rfl)).trans (QKeepA.of_kheap rfl (DomKeepA.ofKey rfl)) have Q2 : QSendA σ1 τ3 := sendIpc_recv_qsA (i := σ.idleThread) (M := M) (N := Nq) J.sr.place s2 hSt1 hV2 hdth hk1 hkt1 hkd1 hal true false hbg.bv g gr false (Or.inr ⟨_, rfl⟩) (Or.inl rfl) (Or.inr rfl) rfl hnI hdI hD1 @@ -615,7 +615,7 @@ theorem JStage3A.chargeSendRecvCoreA have SH : ChargeShapeA σ τ := ⟨CH.cur, by rw [hτ]; rfl, CH.csc, by rw [hτ]; rfl, ⟨yh, nh, τkh⟩, Or.inl ⟨by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl⟩, rdy, - ⟨by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl⟩⟩ + DomKeepA.ofKey (by rw [hτ]; rfl)⟩ have SV1 : SchedValidA σ1 := Sched.SchedValidA.faultA (J.schedValid.chargeA SH CH.keep FR) hkτ _ have RQ1 : RqDomPrio σ1 := rqDomPrio_faultA (fun g' d' q'' y' hy' hm => rqDomPrio_of_schedA J.sr g' d' q'' y' (chargeTcbBackA CH.keep FR hy') (by rw [hτ] at hm; exact hm)) hkτ _ diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntrySendBlkA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntrySendBlkA.lean index a875453ee..30dfddfdb 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntrySendBlkA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntrySendBlkA.lean @@ -547,7 +547,7 @@ theorem JStage3A.chargeSendBlkA have SH : ChargeShapeA σ τ := ⟨CH.cur, by rw [hτ]; rfl, CH.csc, by rw [hτ]; rfl, ⟨yh, nh, τkh⟩, Or.inl ⟨by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl⟩, rdy, - ⟨by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl⟩⟩ + DomKeepA.ofKey (by rw [hτ]; rfl)⟩ have SV1 : SchedValidA σ1 := Sched.SchedValidA.faultA (J.schedValid.chargeA SH CH.keep FR) hkτ _ have actT1 : ScActiveAtA σ1 σ.curSc := ⟨yh, nh, by rw [far1 _ hctcs.symm]; exact τcsc, (scActive_of_maxA hrm').trans hact0⟩ @@ -557,8 +557,8 @@ theorem JStage3A.chargeSendBlkA have Qs : QBlkA (specPtr '' E) (specPtr '' N) σ τ3 := by have Qh : QKeepA σ τ := (QKeepA.upd hx0 (QObjA.ofSc (y := yh) fun h => - ⟨by rwa [hrep'] at h, fun a => (scActive_of_maxA hrm').trans a⟩)).trans (QKeepA.of_kheap τkh ⟨by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl, by rw [hτ]; rfl⟩) - have Qf : QKeepA τ σ1 := (QKeepA.upd hkτ (QObjA.ofTcb (y := x1) rfl)).trans (QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩) + ⟨by rwa [hrep'] at h, fun a => (scActive_of_maxA hrm').trans a⟩)).trans (QKeepA.of_kheap τkh (DomKeepA.ofKey (by rw [hτ]; rfl))) + have Qf : QKeepA τ σ1 := (QKeepA.upd hkτ (QObjA.ofTcb (y := x1) rfl)).trans (QKeepA.of_kheap rfl (DomKeepA.ofKey rfl)) have Q01 : QBlkA (specPtr '' E) (specPtr '' N) σ σ1 := QSendA.toBlk J.ipcSorted (Qh.trans Qf).toSend have hq1 : ∀ a ∈ xe.epQueue, ∃ y, σ1.kheap a = some (.tcb y) := fun a ha => by by_cases e : a = specPtr t @@ -777,13 +777,13 @@ theorem kentryChargeIrqSendAllA {AR' : A → HwRootA → Prop} {Clock : A → Ma (hLimit : ∀ a', sporadic.max_release_time ar a' ⦃ v => v.bv = fl4MaxReleaseTime ⦄) (hA : P0.ArchTotal ar) (hmax : maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) (hconv : Fl4TicksToUsLegacyAgree) - (hX : ∀ s1 a1 σ1, JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes + (hX : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → BufOffXA st Z H OS Pp Tb Lv Bf s1) : KEntryChargeA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s a σ (sched.check_budget st ar) fl4CheckBudget := by refine kentryChargeIrqSendA noSwitch hni hCs one hag hmb hLimit hA hmax htu hconv hX - fun s1 a1 σ1 e1 J1 En1 CI1 Act1 Cl1 hex hns hR => ?_ + fun s1 a1 σ1 hu e1 J1 En1 CI1 Act1 Cl1 hex hns hR => ?_ have eσ1 : σ1 = fl4TimestampState (rawNextA σ.machineState) { σ with machineState := rawStateA σ.machineState } := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst ((fl4UpdateTimestamp_eqA σ).symm.trans e1)))).2.symm @@ -791,7 +791,7 @@ theorem kentryChargeIrqSendAllA {AR' : A → HwRootA → Prop} {Clock : A → Ma have ni1 : σ1.curSc ≠ idleScPtr → NotIdleScA m σ1.curSc := by rw [eσ1]; exact hni have B := J1.timeoutSelA hns hR refine WP.spec_mono (J1.checkBudgetSendBlkA sw1 CI1 Act1 (J1.curScOnCoreA hCs one) ni1 hCs one hag (hmb a1) - (hLimit a1) hmax htu hconv hA En1 (hX s1 a1 σ1 J1) hex hns B) ?_ + (hLimit a1) hmax htu hconv hA En1 (hX s1 a1 σ1 hu e1 J1) hex hns B) ?_ rintro r ⟨τ, h, Q, -⟩ exact ⟨τ, h, Q⟩ @@ -804,13 +804,13 @@ theorem kentryChargeRestartSendAllA {AR' : A → HwRootA → Prop} {Clock : A (hLimit : ∀ a', sporadic.max_release_time ar a' ⦃ v => v.bv = fl4MaxReleaseTime ⦄) (hA : P0.ArchTotal ar) (hmax : maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) (hconv : Fl4TicksToUsLegacyAgree) - (hX : ∀ s1 a1 σ1, JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes + (hX : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → BufOffXA st Z H OS Pp Tb Lv Bf s1) : KEntryChargeA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s a σ (sched.check_budget_restart st ar) fl4CheckBudgetRestart := by refine kentryChargeRestartSendA noSwitch hni hCs one hag hmb hLimit hA hmax htu hconv hX - fun s1 a1 σ1 e1 J1 En1 CI1 Act1 Cl1 hex hns hR => ?_ + fun s1 a1 σ1 hu e1 J1 En1 CI1 Act1 Cl1 hex hns hR => ?_ have eσ1 : σ1 = fl4TimestampState (rawNextA σ.machineState) { σ with machineState := rawStateA σ.machineState } := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst ((fl4UpdateTimestamp_eqA σ).symm.trans e1)))).2.symm @@ -818,7 +818,7 @@ theorem kentryChargeRestartSendAllA {AR' : A → HwRootA → Prop} {Clock : A have ni1 : σ1.curSc ≠ idleScPtr → NotIdleScA m σ1.curSc := by rw [eσ1]; exact hni have B := J1.timeoutSelA hns hR exact J1.checkBudgetRestartSendBlkA sw1 CI1 Act1 (J1.curScOnCoreA hCs one) ni1 hCs one hag (hmb a1) - (hLimit a1) hmax htu hconv hA En1 (hX s1 a1 σ1 J1) hex hns B + (hLimit a1) hmax htu hconv hA En1 (hX s1 a1 σ1 hu e1 J1) hex hns B end rec diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntrySendWireA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntrySendWireA.lean index ebddb04f7..17712c436 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntrySendWireA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntrySendWireA.lean @@ -198,9 +198,9 @@ theorem kentryChargeIrqSendA {AR' : A → HwRootA → Prop} {Clock : A → Machi (hLimit : ∀ a', sporadic.max_release_time ar a' ⦃ v => v.bv = fl4MaxReleaseTime ⦄) (hA : P0.ArchTotal ar) (hmax : maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) (hconv : Fl4TicksToUsLegacyAgree) - (hX : ∀ s1 a1 σ1, JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes + (hX : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → BufOffXA st Z H OS Pp Tb Lv Bf s1) - (hSendO : ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + (hSendO : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → CurInvA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → @@ -211,7 +211,7 @@ theorem kentryChargeIrqSendA {AR' : A → HwRootA → Prop} {Clock : A → Machi r.2.1 r.2.2 τ ⦄) : KEntryChargeA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s a σ (sched.check_budget st ar) fl4CheckBudget := by - refine kentryChargeIrqA noSwitch hni hCs one hag hmb hLimit (fun s1 a1 σ1 J1 => J1.entryValidA) hA fun s1 a1 σ1 e1 J1 En1 CI1 Act1 Cl1 hex hns => ?_ + refine kentryChargeIrqA noSwitch hni hCs one hag hmb hLimit (fun s1 a1 σ1 J1 => J1.entryValidA) hA fun s1 a1 σ1 hu e1 J1 En1 CI1 Act1 Cl1 hex hns => ?_ by_cases hR : TimeoutRecvA st Z E s1 σ1 · have eσ1 : σ1 = fl4TimestampState (rawNextA σ.machineState) { σ with machineState := rawStateA σ.machineState } := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst ((fl4UpdateTimestamp_eqA σ).symm.trans @@ -219,10 +219,10 @@ theorem kentryChargeIrqSendA {AR' : A → HwRootA → Prop} {Clock : A → Machi have sw1 : ∀ u, σ1.schedulerAction ≠ .switchThread u := by rw [eσ1]; exact noSwitch have ni1 : σ1.curSc ≠ idleScPtr → NotIdleScA m σ1.curSc := by rw [eσ1]; exact hni refine WP.spec_mono (J1.checkBudgetSendRecvA sw1 CI1 Act1 (J1.curScOnCoreA hCs one) ni1 hCs one hag (hmb a1) - (hLimit a1) hmax htu hconv hA En1 (hX s1 a1 σ1 J1) hex hns hR) ?_ + (hLimit a1) hmax htu hconv hA En1 (hX s1 a1 σ1 hu e1 J1) hex hns hR) ?_ rintro r ⟨τ, h, Q, -⟩ exact ⟨τ, h, Q⟩ - · exact hSendO s1 a1 σ1 e1 J1 En1 CI1 Act1 Cl1 hex hns hR + · exact hSendO s1 a1 σ1 hu e1 J1 En1 CI1 Act1 Cl1 hex hns hR set_option maxHeartbeats 1000000 in /-- **The syscall and fault entries' exhausted-budget branch with the waiting-receiver timeout send** (module @@ -234,9 +234,9 @@ theorem kentryChargeRestartSendA {AR' : A → HwRootA → Prop} {Clock : A → M (hLimit : ∀ a', sporadic.max_release_time ar a' ⦃ v => v.bv = fl4MaxReleaseTime ⦄) (hA : P0.ArchTotal ar) (hmax : maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) (hconv : Fl4TicksToUsLegacyAgree) - (hX : ∀ s1 a1 σ1, JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes + (hX : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → BufOffXA st Z H OS Pp Tb Lv Bf s1) - (hSendO : ∀ s1 a1 σ1, fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → + (hSendO : ∀ s1 a1 σ1, sched.update_timestamp st ar s a = ok (s1, a1) → fl4UpdateTimestamp (Z := Unit) σ = ({((), σ1)}, False) → JStage3A st AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s1 a1 σ1 m → ChargeEntryA st Ac s1 → CurInvA σ1 → ActIdleA σ1 → Clock a1 σ1.machineState → @@ -248,7 +248,7 @@ theorem kentryChargeRestartSendA {AR' : A → HwRootA → Prop} {Clock : A → M KEntryChargeA st ar AR' Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s a σ (sched.check_budget_restart st ar) fl4CheckBudgetRestart := by refine kentryChargeRestartA noSwitch hni hCs one hag hmb hLimit (fun s1 a1 σ1 J1 => J1.entryValidA) hA - fun s1 a1 σ1 e1 J1 En1 CI1 Act1 Cl1 hex hns => ?_ + fun s1 a1 σ1 hu e1 J1 En1 CI1 Act1 Cl1 hex hns => ?_ by_cases hR : TimeoutRecvA st Z E s1 σ1 · have eσ1 : σ1 = fl4TimestampState (rawNextA σ.machineState) { σ with machineState := rawStateA σ.machineState } := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst ((fl4UpdateTimestamp_eqA σ).symm.trans @@ -256,8 +256,8 @@ theorem kentryChargeRestartSendA {AR' : A → HwRootA → Prop} {Clock : A → M have sw1 : ∀ u, σ1.schedulerAction ≠ .switchThread u := by rw [eσ1]; exact noSwitch have ni1 : σ1.curSc ≠ idleScPtr → NotIdleScA m σ1.curSc := by rw [eσ1]; exact hni exact J1.checkBudgetRestartSendRecvA sw1 CI1 Act1 (J1.curScOnCoreA hCs one) ni1 hCs one hag (hmb a1) - (hLimit a1) hmax htu hconv hA En1 (hX s1 a1 σ1 J1) hex hns hR - · exact hSendO s1 a1 σ1 e1 J1 En1 CI1 Act1 Cl1 hex hns hR + (hLimit a1) hmax htu hconv hA En1 (hX s1 a1 σ1 hu e1 J1) hex hns hR + · exact hSendO s1 a1 σ1 hu e1 J1 En1 CI1 Act1 Cl1 hex hns hR end rec diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryTailA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryTailA.lean index 813e9b171..140133b9a 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryTailA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryTailA.lean @@ -295,11 +295,11 @@ theorem JStage3A.schedFiredA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea obtain ⟨a1, Qf, Rf, ef, J1, R1, -⟩ := FF rfl fires have SF : SchedFrameA σ1 σ2 := (inferInstance : SPresInst (awaken (Z := Unit))).pres σ1 ((), σ2) (by rw [waking]; exact Set.mem_singleton _) - exact JStage3A.selectionA (Z := Z) (Q := Qf) (R := Rf) J1 hCs h1 R1 waking H2 ⟨F.wr, F.keep, F.sz⟩ SF + exact JStage3A.selectionA (Z := Z) (Q := Qf) (R := Rf) J1 hCs h1 R1 waking H2 (MFrA.ofParts F.wr F.keep F.sz) SF (awaken_archA ef wake) (JStage3A.vsRootOK J1) (JStage3A.idleVtOf J1 J1.idleGapA.1 J1.idleGapA.2.1) · intro start selected s1 σ1 σ2 σ3 Q R Q' FF wake sel fires waking Fa selection Fs H3 obtain ⟨a1, Qf, Rf, -, J1, R1, B1⟩ := FF rfl fires - have Fa' : MFrA (st := st) { Z with Q := Qf, R := Rf } m s1 start.1 σ1 σ2 := ⟨Fa.wr, Fa.keep, Fa.sz⟩ + have Fa' : MFrA (st := st) { Z with Q := Qf, R := Rf } m s1 start.1 σ1 σ2 := MFrA.ofParts Fa.wr Fa.keep Fa.sz exact JStage3A.tailA J1 R1 B1 h1 G.oneDomain waking selection H3 (G.ticks _) (G.timer start selected _ σ3 wake sel) (J1.sr.toSchedSRN.ipiKeepMD (Fa'.transD Fs rfl rfl) J1.ipiZero) @@ -351,7 +351,7 @@ theorem JStage3A.scheduleRecFFA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : obtain ⟨a1, Qf, Rf, ef, J1, R1, B1⟩ := FF rfl hf obtain ⟨hw, har⟩ := arK.schedule st ef ⟨_, J1.j.1.ar⟩ run have J2 := JStage3A.acrossSchedA hA hPl hcore J J1 R1 J1.sinv.ctQ run tail H3 - ⟨F.wr, F.keep, F.sz⟩ SF (nd _ _ J1.sr.toSchedSRN J1.domOK) hcur har + (MFrDA.ofParts F.wr F.keep F.sz) SF (nd _ _ J1.sr.toSchedSRN J1.domOK) hcur har exact ⟨(s1, a1), σ1, τ, Qf, Rf, Q, Rl, Tcur, Ccur, hw, ef, J1, R1, B1, hf, tail, fl4Schedule_of_tail kLimitA view hf tail, H3, J2⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3KEntryTimerIrqA.lean b/proofs/Fl4ProofsA64/P3/Stage3KEntryTimerIrqA.lean index 90344f08e..9177a06ea 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KEntryTimerIrqA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KEntryTimerIrqA.lean @@ -224,7 +224,7 @@ theorem JStage3A.timerIrq_recA (fun u hu x' hx' => Or.inr ⟨x', hx', rfl⟩) (fun _ _ h => h) (fun _ _ h => h) have j := J.j57_stepNWA w { σ with reprogramTimer := true } exact JStage3A.of_schedWrN (blkQ := bq) (symL := symL) (schedValid := { J.schedValid with }) J (Q := Z.Q) (Rl := Z.R) (curOf := Z.curOf) (curScOf := Z.curScOf) - (s' := s') (a' := a) (σ' := { σ with reprogramTimer := true }) w HS SSz (QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩) rfl J.j.1.ar (fun _ _ => rfl) J.bufAl + (s' := s') (a' := a) (σ' := { σ with reprogramTimer := true }) w HS SSz (QKeepA.of_kheap rfl (DomKeepA.ofKey rfl)) rfl J.j.1.ar (fun _ _ => rfl) J.bufAl ⟨J.ent_stepNWA w blk', sysl⟩ sq poolOff H2 J.scCov ep ntfn reply buf J.idleNoFault mcp yr { J.sinv with irqN := by cases J.sinv.irqN; constructor <;> assumption } { J.sidle with } rv' j.1 j.2 diff --git a/proofs/Fl4ProofsA64/P3/Stage3Lift3QA.lean b/proofs/Fl4ProofsA64/P3/Stage3Lift3QA.lean index 29251695b..d717bf923 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3Lift3QA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3Lift3QA.lean @@ -19,7 +19,7 @@ theorem QObjA.refl (o : KernelObject) : QObjA o o := /-- `QKeepA` from a backward object relation. -/ theorem QKeepA.ofBwd {σ σ' : State Unit} (bw : ∀ q o', σ'.kheap q = some o' → ∃ o, σ.kheap q = some o ∧ QObjA o o') - (D : DomKeepA σ σ' := by first | exact ⟨rfl, rfl, rfl, rfl⟩ | exact DomKeepA.refl _) : QKeepA σ σ' := by + (D : DomKeepA σ σ' := by first | exact DomKeepA.ofKey rfl | exact DomKeepA.refl _) : QKeepA σ σ' := by refine ⟨fun q y e => ?_, fun q y e => ?_, fun q y e => ?_, fun q y k e => ?_, fun q y e => ?_, D⟩ · obtain ⟨o, ho, R⟩ := bw q _ e obtain ⟨x, hx, k⟩ := R.prio y rfl diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftBodyA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftBodyA.lean index 953a507d3..aa6ee6ba6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftBodyA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftBodyA.lean @@ -32,7 +32,7 @@ theorem Sched.BodyKeepA.ofSlotL {σ σ' : State Unit} (H : SpecSlotA σ σ') (hl : σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime) : Sched.BodyKeepA σ σ' := by have K := Sched.BodyKeepA.ofSlot (σ := σ) (σ' := { σ' with machineState := σ.machineState }) (H := by refine ⟨⟨H.cur, H.idle, H.csc, H.act, H.time, H.irqS, H.irqN, H.rq, H.rls, H.cons, H.repr, H.dom, H.domT, - H.asid, H.vcur, ⟨H.domk.index, H.domk.start, H.domk.table, H.domk.gvs⟩⟩, H.kh⟩) rfl + H.asid, H.vcur, DomKeepA.ofKey H.domk.key⟩, H.kh⟩) rfl exact ⟨K.act, K.time, hl, K.cur, K.csc, K.cons, K.rel, K.sc, K.tcb⟩ section @@ -102,7 +102,7 @@ theorem A64RelS3.curW_eq {S A : Type} {st : machine.Store S} [L : LawfulStore st (R : A64RelS3 st AR ar nA n Cs s' a' σ' m) (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) (h : σ'.curThread = σ.curThread) : L.curW s' = L.curW s := by - obtain ⟨Z', H', OS', U', Ac', Pp', Tb', Lv', ia', ie', N', E', Rp', Bf', stack', κ', -, J', -⟩ := R + obtain ⟨m', -, Z', H', OS', U', Ac', Pp', Tb', Lv', ia', ie', N', E', Rp', Bf', stack', κ', -, J', -⟩ := R exact Sched.curW_keptA J J' h /-- The caller's TCB after a one-word reply: its context replaced and its state `Running`. -/ diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftDomainA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftDomainA.lean index 015a35a44..8764abb54 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftDomainA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftDomainA.lean @@ -247,7 +247,7 @@ theorem setDomain_otherA {Z : XSetsA} {m : McState} {κ : U64 → U64} {s : S} { have M2 := yieldQueueFrameA E1.sched E1.states E1.mcp E1.links rfl (w2.mono fun _ h => h.elim) have E2 : YieldQueueRelA (st := st) { Z with Q := Q1 } m κ s2 σ1 := ⟨H2, hs2, M2.2.1, M2.2.2⟩ have F2 : MFrA (st := st) { Z with Q := Q1 } m s1 s2 σ1 σ1 := - ⟨w2.mono fun _ h => h.elim, SKeepA.refl _, SSzA.refl _⟩ + MFrA.ofParts (w2.mono fun _ h => h.elim) (SKeepA.refl _) (SSzA.refl _) have F12 : MFrA (st := st) Z m s s2 σ σ1 := F1.trans F2 rfl rfl have hon2 : L.mem s2 (affA t) = L.cpu s2 := yieldAffKeepA E.sched H2 ht ht hon have hc1 : σ1.curThread = σ.curThread := by rw [O1] @@ -360,7 +360,7 @@ theorem setDomain_selfA {Z : XSetsA} {m : McState} {κ : U64 → U64} {s : S} { have M2 := yieldQueueFrameA E1.sched E1.states E1.mcp E1.links rfl (w2.mono fun _ h => h.elim) have E2 : YieldQueueRelA (st := st) { Z with Q := Q1 } m κ s2 σ1 := ⟨H2, hs2, M2.2.1, M2.2.2⟩ have F2 : MFrA (st := st) { Z with Q := Q1 } m s1 s2 σ1 σ1 := - ⟨w2.mono fun _ h => h.elim, SKeepA.refl _, SSzA.refl _⟩ + MFrA.ofParts (w2.mono fun _ h => h.elim) (SKeepA.refl _) (SSzA.refl _) have F12 : MFrA (st := st) Z m s s2 σ σ1 := F1.trans F2 rfl rfl have hon2 : L.mem s2 (affA t) = L.cpu s2 := yieldAffKeepA E.sched H2 ht ht hon rw [is_schedulable_eqA, bind_ok, schedulable_eqA H2.toSchedSRN ht (H2.relOn ht hon2) hs2] @@ -500,7 +500,7 @@ theorem JStage3A.setDomain_stepA (fun q z h => by rw [hk]; exact h) (fun q z h => by rw [hk]; exact h) exact J.of_stepFinA (Q := Q') (Rl := Z.R) (curOf := Z.curOf) (curScOf := Z.curScOf) (F.wr.mono fun _ h => Or.inl (Or.inl h)) O (SSzA.of_kheap hk) - (QKeepA.of_kheap hk (by obtain ⟨f, h | h⟩ := hra <;> (subst h; exact ⟨rfl, rfl, rfl, rfl⟩))) hum (fun _ _ => rfl) + (QKeepA.of_kheap hk (by obtain ⟨f, h | h⟩ := hra <;> (subst h; exact DomKeepA.ofKey rfl))) hum (fun _ _ => rfl) (BlkOK.bxi blk') sysl symL userOK j7 E'.sched ep ntfn reply bufCover bufAl idle E'.mcp E'.links SI' (J.sidle.congr hk hidle (by obtain ⟨f, h | h⟩ := hra <;> (subst h; exact Nat.le_refl _))) rv blkQ V' diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftMachA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftMachA.lean index 3605d4280..3ea4bc10e 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftMachA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftMachA.lean @@ -78,7 +78,7 @@ theorem JStage3A.of_machA {ar : machine.Arch A} {nA : U64} have kh : σ2.kheap = σ.kheap := by rw [e2] have um : σ2.machineState.underlyingMemory = σ.machineState.underlyingMemory := by rw [e2]; exact hm have H2 : UtCnStepA σ σ2 := - ⟨by rw [e2]; exact ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, + ⟨by rw [e2]; exact SpecGlobA.ofKey rfl, fun q => Or.inl (by rw [kh]), um⟩ have HS : SpecSchedA σ σ2 := { kh := fun q => Or.inl (by rw [kh]) @@ -123,7 +123,7 @@ theorem JStage3A.of_machA {ar : machine.Arch A} {nA : U64} (fun _ x h => ⟨x, by rwa [kh] at h, rfl, rfl⟩) exact JStage3A.of_schedWr (Q := Z.Q) (Rl := Z.R) (curOf := Z.curOf) (curScOf := Z.curScOf) J - (WritesIn.refl _ _) HS SSz (QKeepA.of_kheap kh ⟨by rw [e2], by rw [e2], by rw [e2], by rw [e2]⟩) um har (fun _ _ => rfl) + (WritesIn.refl _ _) HS SSz (QKeepA.of_kheap kh (DomKeepA.ofKey (by rw [e2]))) um har (fun _ _ => rfl) (fun t ht y hy => J.bufAl t ht y (by rw [← kh]; exact hy)) J.sys J.sq J.poolOff (utFr_schedSRA hw hW H2 J.sr) (utCn_scCovA J.scCov H2) (utFr_epA hw hW H2 J.ep J.iplaced.e) (utFr_ntfnA hw hW H2 J.ntfn J.iplaced.n) (utFr_replyA hw hW H2 J.reply rAl) diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbBufA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbBufA.lean index 766b8debb..de2f7ebe3 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbBufA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbBufA.lean @@ -1,21 +1,16 @@ /- -P3 (aarch64, A64-P3 Lift 3b labels): **TCB SetIPCBuffer with address 0 on another thread, at the record**. +P3 (aarch64, A64-P3 Lift 3b labels): **the outcome shape of the TCB slot-delete labels**. * **`TcbDelOutA`**: the outcome shape of the TCB labels that first delete a TCB slot (DelBodyA frozen clauses): the caller's restart, then `Ok` with the spec's invocation, `JStage3A` and `BodyEndA`, or `Preempted` with the spec's error, `JStage3A` and `BodyPreA`. * **`ipcBufNone_ofNullA`**: an emptied buffer slot leaves no usable IPC buffer in the spec TCB. -* **`setIpcBuf_invokeA`**: the spec's `fl4InvokeTcb (.threadControlCaps ..)` with only the buffer part, from its - `fl4CapDelete` outcome. -* **`JSyscallA.setIpcBufZeroA`**: `decode_invocation` on a Thread cap with the SetIPCBuffer label and buffer address 0 - at a syscall entry: `restartDelA`, the delete of slot 2, `set_ipc_buffer 0` (`setIpcBuf_stepA`), no insert, no - `reschedule_required` (the target is not the current thread). +* `JSyscallA.setIpcBufZeroA` is in `Stage3LiftTcbBufNzA`. -Named premises: those of `JSyscallA.restartDelA` (`DelPlatA`, `hCl`, `hCs`, `hCnt`), [P] -`ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`; [S] `h1` (`numNodes = 1`, the remote stall). The decode reads -extra slot 0 and the address 0 (`he`, `harg`); the `Err` returns before the delete are not lifted. New module. +No named premise. -/ import Fl4ProofsA64.P3.Stage3TcbDelStepA +import Fl4ProofsA64.P3.Stage3TcbPreExitA import Fl4ProofsA64.P3.Stage3TcbBufStepA import Fl4ProofsA64.P3.Stage3TcbTlsA import Fl4ProofsA64.P3.Stage3LiftMachA @@ -37,7 +32,7 @@ variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : variable (st) in /-- **The outcome of a TCB label that deletes a TCB slot** (module docstring), for the invocation `Inv κs` (`κs` the invoked slot). -/ -def TcbDelOutA (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) +def TcbDelOutA (AR : A → HwRootA → Prop) (Clock : A → Fl4SpecA64.MachineState → Prop) (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (n : Nat) (m : Fl4SpecA64.McState) (ar : machine.Arch A) (ipa : U64) (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (Inv : CslotPtr → TcbInvocation) (r : core.result.Result Unit error.Exc) (s3 : S) (a3 : A) : Prop := @@ -49,7 +44,7 @@ def TcbDelOutA (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U Ac Pp (J5A st) (J7A st (J7R2A st ar ipa)) s3 a3 σ3 m ∧ ((r = .Ok () ∧ (∀ κs, (.ok [], σ3) ∈ ((fl4InvokeTcb (Inv κs)).run σ1).1) ∧ Sched.BodyEndA σ σ3 m) ∨ (r = .Err .Preempted ∧ (∀ κs, (.error (), σ3) ∈ ((fl4InvokeTcb (Inv κs)).run σ1).1) ∧ - BodyPreA σ3 m ∧ σ3.curThread = σ.curThread)) + BodyPreA σ3 m ∧ σ3.curThread = σ.curThread ∧ PreExitA σ3 ∧ Clock a3 σ3.machineState)) /-- **An emptied buffer slot leaves no usable IPC buffer** (module docstring). -/ theorem ipcBufNone_ofNullA {th : TypedHeapA} {s : S} {σ : Fl4SpecA64.State Unit} (hR : StateRelA th (L.mem s) σ) @@ -67,175 +62,6 @@ theorem ipcBufNone_ofNullA {th : TypedHeapA} {s : S} {σ : Fl4SpecA64.State Unit unfold ipcBufOfA rw [e] -/-- **The spec's buffer-only `invoke_tcb`**, from the outcome of its `cap_delete`. -/ -theorem setIpcBuf_invokeA {σ1 σd : Fl4SpecA64.State Unit} {t : U64} {y : Tcb} (κs : CslotPtr) - (hdel : (.ok (), σd) ∈ ((fl4CapDelete (Z := Unit) (specPtr t, tcbCnodeIndex 2)).run σ1).1) - (hy : σd.kheap (specPtr t) = some (.tcb y)) (hne : σd.curThread ≠ specPtr t) : - (.ok [], bufStateA σd (specPtr t) y) ∈ - ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none - (some (Fl4SpecA64.dataToVref (0#u64).bv, none)))).run σ1).1 := by - have hset : threadSet (Z := Unit) (fun x : Tcb => { x with tcbIpcBuffer := Fl4SpecA64.dataToVref (0#u64).bv }) - (specPtr t) σd = ({((), bufStateA σd (specPtr t) y)}, False) := threadSet_eqSc _ hy - have hrk : ∀ σ : Fl4SpecA64.State Unit, (.ok (), σ) ∈ ((NonDetE.returnOk (ε := Unit) ()).run σ).1 := fun σ => by - rw [run_returnOkD]; simp - have hs1 : ((), bufStateA σd (specPtr t) y) ∈ ((threadSet (Z := Unit) - (fun x : Tcb => { x with tcbIpcBuffer := Fl4SpecA64.dataToVref (0#u64).bv }) (specPtr t)) σd).1 := by - rw [hset]; simp - have hs2 : ((), bufStateA σd (specPtr t) y) ∈ ((Fl4Spec.NonDet.pure () : Fl4Spec.NonDet (State Unit) Unit) (bufStateA σd (specPtr t) y)).1 := by - have h : (Fl4Spec.NonDet.pure () : Fl4Spec.NonDet (State Unit) Unit) (bufStateA σd (specPtr t) y) = - ({((), bufStateA σd (specPtr t) y)}, False) := rfl - rw [h]; exact Set.mem_singleton _ - simp only [fl4InvokeTcb, fl4InstallTcbCap, fl4InstallTcbFrameCap] - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := bufStateA σd (specPtr t) y) ?_ (by rw [run_returnOkD]; simp) - refine mem_bindE_okD (a := ()) (s' := σd) hdel ?_ - refine mem_bindE_okD (a := ()) (s' := bufStateA σd (specPtr t) y) (mem_liftED hs1) ?_ - refine mem_bindE_okD (a := ()) (s' := bufStateA σd (specPtr t) y) (mem_liftED hs2) ?_ - refine mem_bindE_okD (a := σd.curThread) (s' := bufStateA σd (specPtr t) y) (mem_liftED ?_) ?_ - · simp [Fl4Spec.NonDet.gets, bufStateA, updKSc] - · refine mem_liftED ?_ - simp [Fl4Spec.NonDet.when, if_neg (Ne.symm hne)] - all_goals first | exact Set.mem_singleton _ | exact rfl | simp [Fl4Spec.NonDet.pure] - - -/-- **The spec's buffer-only `invoke_tcb` when its `cap_delete` fails** (`Preempted`). -/ -theorem setIpcBuf_invokeErrA {σ1 σd : Fl4SpecA64.State Unit} {t : U64} (κs : CslotPtr) - (hdel : (.error (), σd) ∈ ((fl4CapDelete (Z := Unit) (specPtr t, tcbCnodeIndex 2)).run σ1).1) : - (.error (), σd) ∈ - ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none - (some (Fl4SpecA64.dataToVref (0#u64).bv, none)))).run σ1).1 := by - have hrk : ∀ σ : Fl4SpecA64.State Unit, (.ok (), σ) ∈ ((NonDetE.returnOk (ε := Unit) ()).run σ).1 := fun σ => by - rw [run_returnOkD]; simp - simp only [fl4InvokeTcb, fl4InstallTcbCap, fl4InstallTcbFrameCap] - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - exact mem_bindE_errD (mem_bindE_errD hdel) - -section -variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} - {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} - {n : Nat} {Clock : A → Fl4SpecA64.MachineState → Prop} - -set_option maxHeartbeats 4000000 in -/-- **TCB SetIPCBuffer with address 0 on another thread at a syscall entry** (module docstring). -/ -theorem JSyscallA.setIpcBufZeroA [PlainStore st] - (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) - (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) - (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) - (hfm : A64FrameMasks st s) (hCnt : CounterStepA σ) - (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) - (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) - {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} - (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) - (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) - (hlbl : lbl = fl4_abi.label.TCBSetIPCBuffer) - (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok src)) - (harg : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok 0#u64) (hne : t ≠ L.curW s) : - ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (r, s3, a3) ∧ - TcbDelOutA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ - (fun κs => .threadControlCaps (specPtr t) κs none none none none - (some (Fl4SpecA64.dataToVref (0#u64).bv, none))) r s3 a3 := by - have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap - have htT : t ∈ H.tcbs := by rw [J.tcbs]; exact ht - have hthT : Z.th t = some .tcb := (J.j.1.thT t).2 ht - have T0 := J.toJStage3A.toTA J.sact J.noSwitch - have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht - set sl : Fl4SpecA64.CslotPtr := (specPtr t, tcbCnodeIndex 2) with hsl - have hAd : AbsSlotA Z.th sl := ⟨t, rfl, Or.inr ⟨hthT, 2, by decide, rfl⟩⟩ - have sbw : cslotAddrA sl = sbWordA t := by - unfold cslotAddrA - show slotAddrA (specPtr t) (Fl4SpecA64.ofBl (tcbCnodeIndex 2)) = _ - rw [ofBl_tcbIdx 2 (by decide), bufSlot_eqA] - have hdest : obj.Tcb.slot t layout.tcb.SLOT_BUFFER = ok (cslotAddrA sl) := by - rw [sbw]; simp [obj.Tcb.slot, lift, sbWordA] - have hslotIdx : slotIdx t layout.tcb.SLOT_BUFFER = cslotAddrA sl := - ok_inj_ff ((tcb_slot_val t _).symm.trans hdest) - obtain ⟨xr, heq, hset, D1, hdelWP⟩ := J.restartDelA s a σ m hPl hCnt hslot hcov hext P hCl hCs sl hAd - obtain ⟨x', hx', -, hset', -⟩ := J.restartMachA hslot hcov hext - have e1 : stUpdA σ σ.curThread xr .restart = stUpdA σ σ.curThread x' .restart := by - have := Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (hset.symm.trans hset')) - exact (Prod.mk.inj this).2 - have hr : tcb.restart_caller st s = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) := by - unfold tcb.restart_caller - rw [cur_thread_ok, bind_ok, heq] - obtain ⟨⟨r, sd, ad⟩, hdel0, σd, Gd, Dd, hres, hW⟩ := spec_existsA hdelWP - have sysd := J.sysDelSlotA hA hPl hslot hcov hext hcap layout.tcb.SLOT_BUFFER (by simp [layout.tcb.SLOT_BUFFER]) - hstall hr (r := r) (sd := sd) (ad := ad) (by rw [hslotIdx]; exact hdel0) - have hcur0 : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread - have hdecFin := fun (rr : core.result.Result Unit error.Exc) (s3 : S) (a3 : A) - (hd : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (rr, s3, a3)) (σ3 : Fl4SpecA64.State Unit) => - J.decodeFinA hA hM hPl hfm hslot hcov (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) - (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmDelQ]) - (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hd σ3 m - have hdecBase : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - tcb.install_buffer st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot 0#u64 (capA st s src, 0#u64) := by - rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, - tcbSetIPCBuffer_selectedA (sel := (capA st s src, 0#u64)) hstall he harg - (tcbDeriveBuffer_zeroA (capA_eq s src)) hr] - rcases hres with ⟨hr1, hnull, hspec, -⟩ | ⟨hr1, hspec⟩ - · subst hr1 - obtain ⟨⟨⟨-, X, sv⟩, -⟩, Binv, Own⟩ := hW - obtain ⟨Q, R, hw, Ac', Bf', stack', Jd⟩ := X.toStage3A sysd.1 sysd.2 sv - have ht' : t ∈ ({ Z with G := Gd, Q := Q, R := R, hw := hw } : XSetsA).T := ht - obtain ⟨yd, hyd, -⟩ := Jd.mcp t ht' - have hnb := ipcBufNone_ofNullA Dd.rel hthT hyd (by rw [← sbw]; exact hnull) - obtain ⟨blk', K⟩ := Jd.setIpcBuf_stepA (t := t) ht' hyd hnb - have hcurd : L.curW sd = L.curW s := - specPtr_inj ((Jd.j.1.sch.curThread).symm.trans (Binv.2.1.trans hcur0)) - have hcurw : L.curW (L.wr sd (wa t 3512#u64) 0#u64) = L.curW sd := by - have hq := Jd.sys.ent.bxi.1.choose_spec.choose_spec - have hn : NodePlaced st H.tcbs sd (L.cpu sd) := hq.nodes _ hq.cur - have hta : TcbAddr t := Jd.sr.core.tcbs t ht' - have c0 : layout.node.CUR_THREAD.val < 4288 := by simp - have al : Aligned (wa t 3512#u64) := field_aligned hta (K := 3512#u64) (by simp) (by simp) - have hw' : WritesIn st sd (L.wr sd (wa t 3512#u64) 0#u64) (· = wa t 3512#u64) := writesIn_wr al - have ecpu : L.cpu (L.wr sd (wa t 3512#u64) 0#u64) = L.cpu sd := L.cpu_wr _ _ _ - unfold LawfulStore.curW - rw [ecpu, nodeAt_of_ksb hw'.1] - refine hw'.mem_eq (nodeAt_aligned hn c0 (by simp)) fun e => ?_ - exact node_ne_field hn c0 htT hta (K := 3512#u64) (by simp) e - have hBuf : obj.Tcb.set_ipc_buffer st t sd 0#u64 = ok (L.wr sd (wa t 3512#u64) 0#u64) := - eq_of_spec_fd (Fl4ProofsA64.P1.obj.Tcb.set_ipc_buffer.wr sd t 0#u64) - have hneW : ¬ t = L.curW (L.wr sd (wa t 3512#u64) 0#u64) := by rw [hcurw, hcurd]; exact hne - have hdecOk : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (.Ok (), L.wr sd (wa t 3512#u64) 0#u64, ad) := by - rw [hdecBase, tcbInstallBuffer_clearA hdest hdel0 hBuf, if_neg hneW]; simp only [bind_ok] - obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := hdecFin _ _ _ hdecOk (bufStateA σd (specPtr t) yd) - have J2 := K sysl symL userOK j7 - have dsk : DSkA σd (bufStateA σd (specPtr t) yd) := - DSkA.upd (p := specPtr t) (o := .tcb yd) (o' := .tcb { yd with tcbIpcBuffer := 0 }) hyd - (fun y k h => by cases h) (fun y k h => by cases h) (fun x'' h => ⟨yd, rfl, by rw [← KernelObject.tcb.inj h]; exact ⟨rfl, Or.inl rfl, rfl⟩⟩) - have kstep : DelStepA σd (bufStateA σd (specPtr t) yd) := DelStepA.ofWk Jd.sinv.curSc dsk.toDWkA (Or.inl dsk) dsk.ch - have B2 := BodyOKA.stepA Binv kstep - have hne2 : σd.curThread ≠ specPtr t := fun e => hne (specPtr_inj (e.symm.trans (Binv.2.1.trans hcur0))) - refine ⟨.Ok (), _, ad, hdecOk, x', stUpdA σ σ.curThread x' .restart, _, hx', rfl, hset', Gd, Q, R, hw, Ac', Bf', - stack', J2, Or.inl ⟨rfl, fun κs => ?_, B2.1, B2.2.1⟩⟩ - rw [e1] at hspec - exact setIpcBuf_invokeA κs hspec hyd hne2 - · subst hr1 - obtain ⟨⟨⟨-, X, sv⟩, -⟩, hpre⟩ := hW - obtain ⟨Q, R, hw, Ac', Bf', stack', Jd⟩ := X.toStage3A sysd.1 sysd.2 sv - have hdecP : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (.Err .Preempted, sd, ad) := by - rw [hdecBase] - simp only [tcb.install_buffer, hdest, hdel0, bind_ok, uncurry_apply_pair, - core.result.Result.Insts.CoreOpsTry.branch, - core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, - bind_tc_ok] - refine ⟨.Err .Preempted, sd, ad, hdecP, x', stUpdA σ σ.curThread x' .restart, σd, hx', rfl, hset', Gd, Q, R, hw, - Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun κs => ?_, hpre.1, hpre.2.1⟩⟩ - rw [e1] at hspec - exact setIpcBuf_invokeErrA κs hspec - -end - end end diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbBufNzA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbBufNzA.lean index b97c74d8b..d1bab953d 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbBufNzA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbBufNzA.lean @@ -1,24 +1,17 @@ /- -P3 (aarch64, A64-P3 setipcbuf): **TCB SetIPCBuffer with a non-zero address on another thread, at the record**. +P3 (aarch64, A64-P3 setipcbuf): **TCB SetIPCBuffer at a syscall entry**, address 0 on another thread and a non-zero +address, both from the chain start (`JSyscallA.tcbChainStartA`) and the mid-state buffer step (`TcbMidA.bufStepA`). -* **`bufLiveOfFrameA`**: a live non-device frame cap of an `OS` slot, with a 1024-aligned user address `baddr ≠ 0`, gives the - kernel address `bufAddrOfA ptr baddr bits` of the buffer: `BufLiveA` (non-zero because the heap has no object at 0) - and the frame's alignment `ptr % 2^bits = 0` (from `FrameOK` and `HeapOK.align`). -* **`frameWord_ne_ibA`**: a live frame word is not the IPC-buffer word `[t + 3512]` of a TCB. -* **`bufMid*A`**: the middle of the spec's `invoke_tcb` for the buffer (the two `check_cap_at`s and `cap_insert`), - for the three outcomes (source changed, invoked slot changed, insert). -* **`JSyscallA.setIpcBufNzA`**: `decode_invocation` on a Thread cap with the SetIPCBuffer label, a non-zero 1024-aligned - address and a non-device Frame source: `restartDelGA` on `Ag` = the 128 words of the new buffer, the delete of slot 2, - `set_ipc_buffer baddr` (`setIpcBuf_stepVA`), `still_valid`, then `cdt::insert` of the unmapped copy - (`capInsertTcbBufA`, growing `Bf`; the P1 facts at the post-insert state from `JStage3A.insertP1A`) when it holds; - then `reschedule_required` when the target is the current thread (`JStage3A.reschedSelf_stepA`). +* **`JSyscallA.setIpcBufZeroA`**: buffer address 0 (no frame-word agreement, no insert). +* **`JSyscallA.setIpcBufNzA`**: a non-zero 1024-aligned address and a non-device Frame source. -Named premises: those of `JSyscallA.setIpcBufZeroA`, and the entry agreement `hag` ([S], Architect ruling (b'): the 128 -words of the new buffer agree between the store and the spec's user memory at entry). New module. +Named premises: those of `JSyscallA.restartDelA` (`DelPlatA`, `hCl`, `hCs`, `hCnt`), [P] `ArchTotal`, `ArchPlat`; +[S] `h1` (`numNodes = 1`, the remote stall), and for a non-zero address the entry agreement `hag` ([S], Architect +ruling (b'): the 128 words of the new buffer agree between the store and the spec's user memory at entry). `MaxSpi`, +`A64FrameMasks` (and for address 0 `hSC`, `hne`) are kept in the statements and not used. -/ -import Fl4ProofsA64.P3.Stage3TcbBufStepsA -import Fl4ProofsA64.P3.Stage3TcbReschedA -import Fl4ProofsA64.P3.Stage3InsP1A +import Fl4ProofsA64.P3.Stage3TcbBufMidA +import Fl4ProofsA64.P3.Stage3TcbChainStartA open Aeneas Aeneas.Std Result @@ -28,100 +21,52 @@ open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp F noncomputable section -local notation "wa" => core.num.U64.wrapping_add - -section -variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} - -/-- **The buffer of a live frame cap** (module docstring). -/ -theorem bufLiveOfFrameA {H : Heap} {OS : Set U64} {s : S} (hH : HeapOK H) (h0 : H 0#u64 = none) - (hfo : FrameOK st H OS s) {src ptr rights asid va baddr bits : U64} {size : capability.FrameSize} {mp ep : Bool} - (hsrc : src ∈ OS) (hc : capA st s src = .Frame ptr size rights false mp ep asid va) (hbits : size.bits = ok bits) - (hbal : baddr.val % 1024 = 0) (hbn : baddr ≠ 0#u64) : - ptr.val % 2 ^ bits.val = 0 ∧ BufLiveA st OS s (bufAddrOfA ptr baddr bits) := by - have hfp : H ptr = some (.other bits.val) := hfo src hsrc ptr size rights mp ep asid va hc bits hbits - have hal : ptr.val % 2 ^ bits.val = 0 := by - have h := hH.align ptr _ hfp - simpa [HKind.bits] using h - obtain ⟨-, h1024, hle, hlt⟩ := bufAddr_rangeA (frame_bitsLtA hbits) hal hbal - have hp0 : ptr.val ≠ 0 := fun e => by - have : ptr = 0#u64 := UScalar.eq_of_val_eq e - rw [this, h0] at hfp - cases hfp - refine ⟨hal, fun e => ?_, h1024, fun k hk => ⟨src, hsrc, ptr, size, rights, mp, ep, asid, va, bits, hc, hbits, ?_, ?_⟩⟩ - · have := congrArg UScalar.val e - rw [show (0#u64 : U64).val = 0 from rfl] at this - omega - · rw [bufW_valLiveA h1024 hk]; omega - · rw [bufW_valLiveA h1024 hk]; omega - -/-- **A live frame word is not the IPC-buffer word of a TCB.** -/ -theorem frameWord_ne_ibA {H : Heap} {OS : Set U64} {s : S} (hH : HeapOK H) (hfo : FrameOK st H OS s) {t b : U64} - (hta : TcbAddr t) (htH : H t = some .tcb) (lv : FrameWordLive st OS s b) : wa t 3512#u64 ≠ b := by - obtain ⟨u, hu, ptr, size, rights, x1, x2, x3, x4, bits, hc, hb, h1, h2⟩ := lv - have hfp : H ptr = some (.other bits.val) := hfo u hu ptr size rights x1 x2 x3 x4 hc bits hb - have := frameWord_offA hH hfp htH (fun z => by simp) h1 h2 - have vM : (wa t 3512#u64).val = t.val + 3512 := by - show (wa t 3512#u64).val = _ - rw [Notif.tfield_val hta (by decide : (3512#u64 : U64).val < 4096)]; rfl - intro e - have ev := congrArg UScalar.val e - simp only [HKind.bits] at this - omega - -end - -section spec - -/-- The spec's two `check_cap_at`s and `cap_insert` when the source's cap is no longer the new cap's object. -/ -theorem bufMidSrcA {σ : State Unit} {target : ObjRef} {κs κsrc : CslotPtr} {newCap source : Cap} - (hsource : (source, σ) ∈ (getCap (Z := Unit) κsrc σ).1) (hmatch : ¬ fl4TcbSameObject newCap source) : - ((), σ) ∈ ((getCap (Z := Unit) κsrc >>= fun live => - Fl4Spec.NonDet.when (fl4TcbSameObject newCap live) (getCap (Z := Unit) κs >>= fun cap => - Fl4Spec.NonDet.when (fl4TcbSameObject (.threadCap target) cap) - (capInsert (Z := Unit) newCap κsrc (target, tcbCnodeIndex 2)))) σ).1 := by - refine mem_bind_ndD hsource ?_ - rw [Fl4Spec.NonDet.when, if_neg hmatch] - exact Set.mem_singleton _ - -/-- … when the invoked slot no longer holds the thread's cap. -/ -theorem bufMidInvA {σ : State Unit} {target : ObjRef} {κs κsrc : CslotPtr} {newCap source current : Cap} - (hsource : (source, σ) ∈ (getCap (Z := Unit) κsrc σ).1) (hmatch : fl4TcbSameObject newCap source) - (hinvoked : (current, σ) ∈ (getCap (Z := Unit) κs σ).1) (htarget : ¬ fl4TcbSameObject (.threadCap target) current) : - ((), σ) ∈ ((getCap (Z := Unit) κsrc >>= fun live => - Fl4Spec.NonDet.when (fl4TcbSameObject newCap live) (getCap (Z := Unit) κs >>= fun cap => - Fl4Spec.NonDet.when (fl4TcbSameObject (.threadCap target) cap) - (capInsert (Z := Unit) newCap κsrc (target, tcbCnodeIndex 2)))) σ).1 := by - refine mem_bind_ndD hsource ?_ - rw [Fl4Spec.NonDet.when, if_pos hmatch] - refine mem_bind_ndD hinvoked ?_ - rw [Fl4Spec.NonDet.when, if_neg htarget] - exact Set.mem_singleton _ - -/-- … when both hold and the insert runs. -/ -theorem bufMidInsA {σ σ' : State Unit} {target : ObjRef} {κs κsrc : CslotPtr} {newCap source current : Cap} - (hsource : (source, σ) ∈ (getCap (Z := Unit) κsrc σ).1) (hmatch : fl4TcbSameObject newCap source) - (hinvoked : (current, σ) ∈ (getCap (Z := Unit) κs σ).1) (htarget : fl4TcbSameObject (.threadCap target) current) - (hinsert : ((), σ') ∈ (capInsert (Z := Unit) newCap κsrc (target, tcbCnodeIndex 2) σ).1) : - ((), σ') ∈ ((getCap (Z := Unit) κsrc >>= fun live => - Fl4Spec.NonDet.when (fl4TcbSameObject newCap live) (getCap (Z := Unit) κs >>= fun cap => - Fl4Spec.NonDet.when (fl4TcbSameObject (.threadCap target) cap) - (capInsert (Z := Unit) newCap κsrc (target, tcbCnodeIndex 2)))) σ).1 := by - refine mem_bind_ndD hsource ?_ - rw [Fl4Spec.NonDet.when, if_pos hmatch] - refine mem_bind_ndD hinvoked ?_ - rw [Fl4Spec.NonDet.when, if_pos htarget] - exact hinsert - -end spec - section variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {Clock : A → Fl4SpecA64.MachineState → Prop} -set_option maxHeartbeats 16000000 in +set_option maxHeartbeats 4000000 in +/-- **TCB SetIPCBuffer with address 0 on another thread at a syscall entry** (module docstring). -/ +theorem JSyscallA.setIpcBufZeroA [PlainStore st] + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) (hCnt : CounterStepA σ) + (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetIPCBuffer) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok src)) + (harg : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok 0#u64) (hne : t ≠ L.curW s) : + ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (r, s3, a3) ∧ + TcbDelOutA st AR Clock Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ + (fun κs => .threadControlCaps (specPtr t) κs none none none none + (some (Fl4SpecA64.dataToVref (0#u64).bv, none))) r s3 a3 := by + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have hthT : Z.th t = some .tcb := (J.j.1.thT t).2 ht + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := + (J.toJStage3A.toTA J.sact J.noSwitch).stall_singleA hCs h1 ht + obtain ⟨x, hkx, hr, -, hset, Md, Vc, Ub, Pt, Ac1, K0, Ty, I, R⟩ := J.tcbChainStartA (Ag := ∅) hA hPl hCnt hCl + FrAgA.nilA hslot hcov hext hcap hstall + have hdecBase : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + tcb.install_buffer st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot 0#u64 (capA st s src, 0#u64) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + tcbSetIPCBuffer_selectedA (sel := (capA st s src, 0#u64)) hstall he harg + (tcbDeriveBuffer_zeroA (capA_eq s src)) hr] + obtain ⟨r, s3, a3, σ3, hR, G', Q, Rl, hw, Ac', Bf', stack', J3, h⟩ := Md.bufStepA hA hPl P hCs I R (slot := slot) + (src := 0#u64) (baddr := 0#u64) (bc := capA st s src) (frame := none) hthT (κs := (specPtr t, [])) (by simp) + (Or.inl ⟨rfl, rfl, rfl⟩) + refine ⟨r, s3, a3, hdecBase.trans hR, x, _, σ3, hkx, rfl, hset, G', Q, Rl, hw, Ac', Bf', stack', J3, ?_⟩ + rcases h with ⟨hr', hs, hb, hc⟩ | ⟨hr', hs, hb, hc, hx, hk⟩ + · exact Or.inl ⟨hr', fun κs => (bufSpec_invokeA κs _ none).1 hs, hb, hc⟩ + · exact Or.inr ⟨hr', fun κs => (bufSpec_invokeA κs _ none).2 hs, hb, hc, hx, hk⟩ + +set_option maxHeartbeats 4000000 in /-- **TCB SetIPCBuffer with a non-zero address on another thread at a syscall entry** (module docstring). -/ theorem JSyscallA.setIpcBufNzA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) @@ -144,12 +89,11 @@ theorem JSyscallA.setIpcBufNzA [PlainStore st] (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) : ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (r, s3, a3) ∧ - TcbDelOutA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ + TcbDelOutA st AR Clock Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ (fun _ => .threadControlCaps (specPtr t) κs none none none none (some (Fl4SpecA64.dataToVref baddr.bv, some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), κsrc)))) r s3 a3 := by have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap - have htT : t ∈ H.tcbs := by rw [J.tcbs]; exact ht have hthT : Z.th t = some .tcb := (J.j.1.thT t).2 ht have T0 := J.toJStage3A.toTA J.sact J.noSwitch have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht @@ -165,14 +109,6 @@ theorem JSyscallA.setIpcBufNzA [PlainStore st] subst esi set sl : Fl4SpecA64.CslotPtr := (specPtr t, tcbCnodeIndex 2) with hsl have hAd : AbsSlotA Z.th sl := ⟨t, rfl, Or.inr ⟨hthT, 2, by decide, rfl⟩⟩ - have sbw : cslotAddrA sl = sbWordA t := by - unfold cslotAddrA - show slotAddrA (specPtr t) (Fl4SpecA64.ofBl (tcbCnodeIndex 2)) = _ - rw [ofBl_tcbIdx 2 (by decide), bufSlot_eqA] - have hdest : obj.Tcb.slot t layout.tcb.SLOT_BUFFER = ok (cslotAddrA sl) := by - rw [sbw]; simp [obj.Tcb.slot, lift, sbWordA] - have hslotIdx : slotIdx t layout.tcb.SLOT_BUFFER = cslotAddrA sl := - ok_inj_ff ((tcb_slot_val t _).symm.trans hdest) have hneS : src ≠ cslotAddrA sl := fun e => by have h := cslotAddrA_inj J.j.1.place hAsrc hAd (hκsrc.trans e) have e1 : specPtr ps = specPtr t := by rw [← hss1, h] @@ -183,25 +119,8 @@ theorem JSyscallA.setIpcBufNzA [PlainStore st] have e1 : specPtr pi = specPtr t := by rw [← hsi1, h] rw [specPtr_inj e1, hthT] at hsi2 cases hsi2 - obtain ⟨xr, heq, hset, D1, hdelWP⟩ := J.restartDelGA s a σ m hPl hCnt hslot hcov hext P hCl hCs hag sl hAd - obtain ⟨x', hx', -, hset', -⟩ := J.restartMachA hslot hcov hext - have e1 : stUpdA σ σ.curThread xr .restart = stUpdA σ σ.curThread x' .restart := by - have := Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (hset.symm.trans hset')) - exact (Prod.mk.inj this).2 - have hr : tcb.restart_caller st s = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) := by - unfold tcb.restart_caller - rw [cur_thread_ok, bind_ok, heq] - obtain ⟨⟨r, sd, ad⟩, hdel0, σd, Gd, Dd, hres, hW⟩ := spec_existsA hdelWP - have sysd := J.sysDelSlotA hA hPl hslot hcov hext hcap layout.tcb.SLOT_BUFFER (by simp [layout.tcb.SLOT_BUFFER]) - hstall hr (r := r) (sd := sd) (ad := ad) (by rw [hslotIdx]; exact hdel0) - have hcur0 : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread - have hdecFin := fun (rr : core.result.Result Unit error.Exc) (s3 : S) (a3 : A) - (hd : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (rr, s3, a3)) (σ3 : Fl4SpecA64.State Unit) => - J.decodeFinA hA hM hPl hfm hslot hcov (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) - (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmDelQ]) - (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hd σ3 m - -- the derived frame + obtain ⟨x, hkx, hr, hcapK, hset, Md, Vc, Ub, Pt, Ac1, K0, Ty, I, R⟩ := J.tcbChainStartA hA hPl hCnt hCl hag hslot + hcov hext hcap hstall set fr : capability.Cap := .Frame ptr size rights false false false 0#u64 0#u64 with hfr have hCapF : obj.Slot.cap st src s = ok (.Frame ptr size rights false mp ep asid va) := (capA_eq s src).trans (by rw [hsrcF]) @@ -213,311 +132,15 @@ theorem JSyscallA.setIpcBufNzA [PlainStore st] tcb.install_buffer st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot baddr (fr, src) := by rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, tcbSetIPCBuffer_selectedA (sel := (fr, src)) hstall he harg hder hr] - rcases hres with ⟨hr1, hnull, hspec, hch⟩ | ⟨hr1, hspec⟩ - swap - · subst hr1 - obtain ⟨⟨⟨-, X, sv⟩, -⟩, hpre⟩ := hW - obtain ⟨Q, R, hw, Ac', Bf', stack', Jd, -⟩ := X.toStage3FrA sysd.1 sysd.2 sv - have hdecP : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (.Err .Preempted, sd, ad) := by - rw [hdecBase] - simp only [tcb.install_buffer, hdest, hdel0, bind_ok, uncurry_apply_pair, - core.result.Result.Insts.CoreOpsTry.branch, - core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, - bind_tc_ok] - refine ⟨.Err .Preempted, sd, ad, hdecP, x', stUpdA σ σ.curThread x' .restart, σd, hx', rfl, hset', Gd, Q, R, hw, - Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun _ => ?_, hpre.1, hpre.2.1⟩⟩ - rw [e1] at hspec - exact setIpcBufG_invokeErrA _ _ _ hspec - subst hr1 - obtain ⟨⟨⟨-, X, sv⟩, -⟩, Binv, Own⟩ := hW - have sactd : SActA σd := by - obtain ⟨⟨_, _, _, _, _, _, JT, -⟩, -⟩ := X - exact JT.sact - obtain ⟨Q, R, hw, Ac', Bf', stack', Jd, fa⟩ := X.toStage3FrA sysd.1 sysd.2 sv - rw [e1] at hspec - have ht' : t ∈ ({ Z with G := Gd, Q := Q, R := R, hw := hw } : XSetsA).T := ht - obtain ⟨yd, hyd, -⟩ := Jd.mcp t ht' - have hnb := ipcBufNone_ofNullA Dd.rel hthT hyd (by rw [← sbw]; exact hnull) - obtain ⟨blk', K⟩ := Jd.setIpcBuf_stepVA (t := t) ht' hyd hnb baddr hbal - have hcurd : L.curW sd = L.curW s := - specPtr_inj ((Jd.j.1.sch.curThread).symm.trans (Binv.2.1.trans hcur0)) - have hta : TcbAddr t := Jd.sr.core.tcbs t ht' - have aM : Aligned (wa t 3512#u64) := field_aligned hta (K := 3512#u64) (by simp) (by simp) - have vM : (wa t 3512#u64).val = t.val + 3512 := by - show (wa t 3512#u64).val = _ - rw [Notif.tfield_val hta (by decide : (3512#u64 : U64).val < 4096)]; rfl - have hcurw : L.curW (L.wr sd (wa t 3512#u64) baddr) = L.curW sd := by - have hq := Jd.sys.ent.bxi.1.choose_spec.choose_spec - have hn : NodePlaced st H.tcbs sd (L.cpu sd) := hq.nodes _ hq.cur - have c0 : layout.node.CUR_THREAD.val < 4288 := by simp - have al : Aligned (wa t 3512#u64) := aM - have hw' : WritesIn st sd (L.wr sd (wa t 3512#u64) baddr) (· = wa t 3512#u64) := writesIn_wr al - have ecpu : L.cpu (L.wr sd (wa t 3512#u64) baddr) = L.cpu sd := L.cpu_wr _ _ _ - unfold LawfulStore.curW - rw [ecpu, nodeAt_of_ksb hw'.1] - refine hw'.mem_eq (nodeAt_aligned hn c0 (by simp)) fun e => ?_ - exact node_ne_field hn c0 htT hta (K := 3512#u64) (by simp) e - have hBuf : obj.Tcb.set_ipc_buffer st t sd baddr = ok (L.wr sd (wa t 3512#u64) baddr) := - eq_of_spec_fd (Fl4ProofsA64.P1.obj.Tcb.set_ipc_buffer.wr sd t baddr) - set sB := L.wr sd (wa t 3512#u64) baddr with hsB - set σB := bufStateVA σd (specPtr t) yd baddr with hσB - have hcurB : L.curW sB = L.curW s := hcurw.trans hcurd - -- the P1 facts at the state after the buffer write - have wW : WritesIn st sd sB (SchedStepNWA (st := st) N E Rp - ({ Z with G := Gd, Q := Q, R := R, hw := hw } : XSetsA) m σd sd) := - (writesIn_wr aM).mono fun b hb => by - subst hb - exact Or.inl (Or.inr (tcbStepWA_of_off Jd.iplaced.e.tcb ht' 3512 (by omega) (by omega) (by omega) - (by omega) vM)) - obtain ⟨syslB, symLB⟩ := J.sysDelBufSetA hA hPl hslot hcov hext hcap hstall hr - (by rw [hslotIdx]; exact hdel0) baddr hbal - obtain ⟨userB, -, j7B⟩ := Jd.p1StepSyA hA hPl wW ⟨syslB, symLB⟩ blk' - have JB := K syslB symLB userB (j7B σB m) - have hkeepB : ∀ y ∈ OS, capA st sB y = capA st sd y := fun y hy => (OSKeep.capA (Jd.osKeep_stepNA wW) hy) - -- the source, the invoked slot and the destination after the delete - have hkeepS : capA st sd src = .Frame ptr size rights false mp ep asid va ∨ capA st sd src = .Null ∨ - HomeZA st sd src := by - rcases hch src hsrcOS hneS with h | h | h - · exact Or.inl (h.trans hsrcF) - · exact Or.inr (Or.inl h) - · exact Or.inr (Or.inr h) - have hkeepI : capA st sd slot = .Thread t ∨ capA st sd slot = .Null ∨ HomeZA st sd slot := by - rcases hch slot hslot hneI with h | h | h - · exact Or.inl (h.trans hcap) - · exact Or.inr (Or.inl h) - · exact Or.inr (Or.inr h) - have hkeepSB : capA st sB src = .Frame ptr size rights false mp ep asid va ∨ capA st sB src = .Null ∨ - HomeZA st sB src := by - rcases hkeepS with h | h | ⟨zt, k, h⟩ - · exact Or.inl ((hkeepB src hsrcOS).trans h) - · exact Or.inr (Or.inl ((hkeepB src hsrcOS).trans h)) - · exact Or.inr (Or.inr ⟨zt, k, (hkeepB src hsrcOS).trans h⟩) - have hkeepIB : capA st sB slot = .Thread t ∨ capA st sB slot = .Null ∨ HomeZA st sB slot := by - rcases hkeepI with h | h | ⟨zt, k, h⟩ - · exact Or.inl ((hkeepB slot hslot).trans h) - · exact Or.inr (Or.inl ((hkeepB slot hslot).trans h)) - · exact Or.inr (Or.inr ⟨zt, k, (hkeepB slot hslot).trans h⟩) - have hSV := tcbStillValidFr_keptA (st := st) sB t slot src hsrc0 ptr rights asid va size mp ep hkeepSB hkeepIB - have hdOS : cslotAddrA sl ∈ OS := J.j5.2.1 _ (hAd.isSlot J.j.1.place) - have hnullB : capA st sB (cslotAddrA sl) = .Null := (hkeepB _ hdOS).trans hnull - have hsrcSlot : IsSlotA Z.th (cslotAddrA κsrc) := hAsrc.isSlot J.j.1.place - -- the spec's two reads at the state after the buffer write - obtain ⟨cS, hgS, hcS⟩ := getCap_eqA JB.j.1.st (show AbsSlotA Z.th κsrc from hAsrc) - obtain ⟨cI, hgI, hcI⟩ := getCap_eqA JB.j.1.st (show AbsSlotA Z.th κs from hAκ) - rw [capAtA_eq (st := st), hκsrc] at hcS - rw [capAtA_eq (st := st), hκ] at hcI - have mS : (cS, σB) ∈ (getCap (Z := Unit) κsrc σB).1 := by rw [hgS]; exact Set.mem_singleton _ - have mI : (cI, σB) ∈ (getCap (Z := Unit) κs σB).1 := by rw [hgI]; exact Set.mem_singleton _ - have eS : capA st sB src = .Frame ptr size rights false mp ep asid va → - cS = absCapA (.Frame ptr size rights false mp ep asid va) := fun h => by - rw [h] at hcS - exact (CapEqA.eq_abs hcS (fun _ _ _ h => by cases h)).symm - have eI : capA st sB slot = .Thread t → cI = .threadCap (specPtr t) := fun h => by - rw [h] at hcI - exact (CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)).symm - have hnSpec : absCapA fr ≠ .nullCap := by simp [hfr, absCapA, absFrameE] - have hsameT : fl4TcbSameObject (.threadCap (specPtr t)) (.threadCap (specPtr t)) := by - simp [fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] - have hsameF : fl4TcbSameObject (absCapA fr) (absCapA (.Frame ptr size rights false mp ep asid va)) := by - cases ep <;> simp [ExtArchCap.stage2FrameCap, ExtArchCap.objRef, hfr, absCapA, absFrameE, ArchCap.isFrameCap, ArchCap.acapObj, ArchCap.acapRights, ArchCap.acapFsize, archCapIsDevice, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, - isThreadCap, objRefOf] - have kstep : DelStepA σd σB := by - have dsk : DSkA σd σB := - DSkA.upd (p := specPtr t) (o := .tcb yd) (o' := .tcb { yd with tcbIpcBuffer := baddr.bv }) hyd - (fun y k h => by cases h) (fun y k h => by cases h) - (fun x'' h => ⟨yd, rfl, by rw [← KernelObject.tcb.inj h]; exact ⟨rfl, Or.inl rfl, rfl⟩⟩) - exact (DelStepA.ofWk Jd.sinv.curSc dsk.toDWkA (Or.inl dsk) dsk.ch).1 - have B1 := BodyOKA.stepA Binv kstep - have dskB : DSkA σd σB := - DSkA.upd (p := specPtr t) (o := .tcb yd) (o' := .tcb { yd with tcbIpcBuffer := baddr.bv }) hyd - (fun y k h => by cases h) (fun y k h => by cases h) - (fun x'' h => ⟨yd, rfl, by rw [← KernelObject.tcb.inj h]; exact ⟨rfl, Or.inl rfl, rfl⟩⟩) - -- the conditional reschedule, from the record before it - have tail : ∀ (G2 : MdbGhostA) (Ac2 : Set U64) (Bf2 : Set (U64 × Fl4SpecA64.Word)) (stack2 : U64 → List U64) - (sf : S) (σf : Fl4SpecA64.State Unit), - JStage3A st AR { Z with G := G2, Q := Q, R := R, hw := hw } H OS U Ac2 Pp Tb Lv ia ie N E Rp Bf2 stack2 κ n - (J5A st) (J7A st (J7R2A st ar hPl.ipa)) sf ad σf m → - L.curW sf = L.curW s → DelBodyInvA σ.curThread m σf → DSkA σd σf → - (∀ s', (if t = L.curW sf then sched.reschedule_required st sf else ok sf) = ok s' → - syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (.Ok (), s', ad)) → - ∃ s' σ' Ac' Bf' stack', - syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (.Ok (), s', ad) ∧ - ((σf.curThread ≠ specPtr t ∧ σ' = σf) ∨ - (σf.curThread = specPtr t ∧ ((), σ') ∈ (rescheduleRequired (Z := Unit) σf).1)) ∧ - JStage3A st AR { Z with G := G2, Q := Q, R := R, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' κ n - (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s' ad σ' m ∧ - DelBodyInvA σ.curThread m σ' := by - intro G2 Ac2 Bf2 stack2 sf σf Jf hcf Bd dsk hd - have hct : σf.curThread = specPtr (L.curW sf) := Jf.sr.sch.curThread - by_cases hself : t = L.curW sf - swap - · refine ⟨sf, σf, _, _, _, hd sf (if_neg hself), Or.inl ⟨fun e => hself ?_, rfl⟩, Jf, Bd⟩ - exact specPtr_inj (e.symm.trans hct) - have nsw := Bd.2.2.1 - have sact : SActA σf := by - refine ⟨fun u e => absurd e (nsw u), ?_⟩ - obtain ⟨y, hy, -⟩ := Jf.mcp _ Jf.sr.curT - rw [← hct] at hy - obtain ⟨x, hx, e⟩ := dsk.tcb _ y hy - obtain ⟨x0, hx0, hs0⟩ := sactd.f2 - have ec : σf.curThread = σd.curThread := Bd.2.1.trans Binv.2.1.symm - rw [ec] at hx hy ⊢ - rw [hx0] at hx - cases hx - exact ⟨y, hy, by rw [e]; exact hs0⟩ - obtain ⟨s', σ', hr', -, hres', eσ, K⟩ := Jf.reschedSelf_stepA sact nsw - have hd' := hd s' ((if_pos hself).trans hr') - obtain ⟨-, Ac', sysl', symL', -, userOK', j7'⟩ := hdecFin _ s' ad hd' σ' - have k : DelStepA σf σ' := by - subst eσ - exact - { cur := rfl, time := rfl, last := rfl, csc := rfl, cons := rfl - rel := fun _ h => h - sc := fun y k h => ⟨y, h, Or.inl ⟨rfl, rfl, rfl⟩⟩ - act := Or.inr rfl - ctSt := fun h => by cases h - off := fun h => ⟨h.1, fun u e => by cases e⟩ - ctSc := CtScKA.refl _ σf } - exact ⟨s', σ', _, _, _, hd', Or.inr ⟨hct.trans (by rw [← hself]), by rw [hres']; exact Set.mem_singleton _⟩, - K sysl' symL' userOK' j7', BodyOKA.stepA Bd k⟩ - by_cases hv : capA st sB src = .Frame ptr size rights false mp ep asid va ∧ capA st sB slot = .Thread t - swap - · -- `still_valid` fails: no insert - rw [decide_eq_false hv] at hSV - obtain ⟨s', σ', Ac2, Bf2, stack2, hdecOk, hlast, J2, B2⟩ := tail Gd Ac' Bf' stack' sB σB JB hcurB B1 dskB - (fun s' h => by rw [hdecBase, tcbInstallBuffer_skipA hdest hdel0 hBuf hSV, h]; simp only [bind_ok]) - refine ⟨.Ok (), s', ad, hdecOk, x', stUpdA σ σ.curThread x' .restart, σ', hx', rfl, hset', Gd, Q, R, hw, Ac2, Bf2, - stack2, J2, Or.inl ⟨rfl, fun _ => ?_, B2.1, B2.2.1⟩⟩ - refine setIpcBufG_invokeA _ baddr hspec hyd ?_ hlast - by_cases hS : capA st sB src = .Frame ptr size rights false mp ep asid va - · have hI : capA st sB slot ≠ .Thread t := fun h => hv ⟨hS, h⟩ - have hnT : ¬ fl4TcbSameObject (.threadCap (specPtr t)) cI := by - rcases hkeepIB with h | h | ⟨zt, k, h⟩ - · exact absurd h hI - all_goals - rw [h] at hcI - rw [← CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)] - simp [absCapA, absFrameE, ArchCap.isFrameCap, ArchCap.acapObj, ArchCap.acapRights, ArchCap.acapFsize, archCapIsDevice, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] - exact bufMidInvA mS (by rw [eS hS]; exact hsameF) mI hnT - · have hnE : ¬ fl4TcbSameObject (absCapA fr) cS := by - rcases hkeepSB with h | h | ⟨zt, k, h⟩ - · exact absurd h hS - all_goals - rw [h] at hcS - rw [← CapEqA.eq_abs hcS (fun _ _ _ h => by cases h)] - simp [hfr, absCapA, absFrameE, ArchCap.isFrameCap, ArchCap.acapObj, ArchCap.acapRights, ArchCap.acapFsize, archCapIsDevice, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, - isThreadCap, objRefOf] - exact bufMidSrcA mS hnE - rw [decide_eq_true hv] at hSV - obtain ⟨hS, hI⟩ := hv - have hS' : capA st sB (cslotAddrA κsrc) = .Frame ptr size rights false mp ep asid va := by rw [hκsrc]; exact hS - have hP := JB.j.1.place - have hwf : CapWfA fr := by - have h := JB.capWfA (y := cslotAddrA κsrc) hsrcSlot - rw [hS'] at h - obtain ⟨hr1', hr3', -, hsp⟩ := h - exact ⟨hr1', hr3', by simp, hsp⟩ - have hw' : CapRt.EncWf fr := by - have h : CapRt.EncWf (capAtA (L.mem sB) (cslotAddrA κsrc)) := CapRt.decodeF_encWf _ _ - rw [capAtA_eq (st := st), hS'] at h - have hc0 : CapRt.Canonical 0#u64 := Or.inl fun j hj _ => by simp - have h' : CapRt.EncWf (.Frame ptr size rights false mp ep asid va) := h - show CapRt.EncWf (.Frame ptr size rights false false false 0#u64 0#u64) - cases ep <;> (simp only [CapRt.EncWf] at h' ⊢; exact ⟨h'.1, h'.2.1, by simp, hc0⟩) - have hno : ¬ IrqNodeA (L.ksb sB) (fl4Ptr sl.1) := by - change ¬ IrqNodeA (L.ksb sB) (fl4Ptr (specPtr t)) - rw [fl4Ptr_specPtr] - intro h - have := JB.j.1.place.irqK hthT h - cases this - -- the buffer's kernel address: liveness, alignment and the 128-word agreement - obtain ⟨hptrAl, hl⟩ := bufLiveOfFrameA JB.sys.ent.heap JB.sys.sysl.ly.h0 JB.sys.sysl.sys.fr hsrcOS hS hbits hbal hbn - have hw1024 := hl.2.1 - have faB : FrAgA st OS {b | ∃ k : U64, k.val < 128 ∧ b = bufW (bufAddrOfA ptr baddr bits) k} sB σB := - FrAgA.stepA fa (fun b lv => FrameWordLive.keepA hkeepB lv) - (fun b al lv => mem_wr_ne' aM al fun e => - frameWord_ne_ibA Jd.sys.ent.heap Jd.sys.sysl.sys.fr hta htT lv e) rfl - have hagB : ∀ k : U64, k.val < 128 → (L.mem sB (bufW (bufAddrOfA ptr baddr bits) k)).bv = - loadWordAt σB.machineState.underlyingMemory (specPtr (bufW (bufAddrOfA ptr baddr bits) k)) := - fun k hk => faB _ ⟨k, hk, rfl⟩ (bufW_alignedLiveA hw1024 hk) (hl.2.2 k hk) - have hdOS' : cslotAddrA sl ∈ OS := hdOS - have hxOS : cslotAddrA κsrc ∈ OS := by rw [hκsrc]; exact hsrcOS - have hxy : cslotAddrA κsrc ≠ cslotAddrA sl := by rw [hκsrc]; exact hneS - have hsc0 : capA st sB (cslotAddrA κsrc) ≠ .Null := by rw [hS']; simp - have hdecIns : ∀ s2, cdt.insert st sB fr (cslotAddrA κsrc) (cslotAddrA sl) = ok s2 → - L.curW s2 = L.curW sB ∧ - ∀ s', (if t = L.curW s2 then sched.reschedule_required st s2 else ok s2) = ok s' → - syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (.Ok (), s', ad) := fun s2 h2 => by - have hc2 : L.curW s2 = L.curW sB := by - have h := cdt.insert.curWA J.sys.ent.os syslB.sys.stz.1.1.mdbS blk' hxOS hdOS' hxy (J.delCanA _ hdOS') - hsc0 hw' - rw [h2, WP.spec_ok] at h - exact h - refine ⟨hc2, fun s' h => ?_⟩ - rw [hκsrc] at h2 - rw [hdecBase, tcbInstallBuffer_liveA hdest hdel0 hBuf hSV h2, h] - simp only [bind_ok] - have hIP : ∀ G', cdt.insert st sB fr (cslotAddrA κsrc) (cslotAddrA sl) ⦃ s2 => SysL st H Z.Cs OS ia ie s2 ∧ - SymL st H Z.Cs s2 ∧ Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s2 ∧ - BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s2 ∧ - ∀ σ' m', J7A st (J7R2A st ar hPl.ipa) { Z with G := G' } H OS s2 σ' m' ⦄ := fun G' => by - have hi : layout.tcb.SLOT_BUFFER.val < 7 := by simp [layout.tcb.SLOT_BUFFER] - have hhp := JB.sys.ent.heap - exact JB.insertP1A hA hPl (x := cslotAddrA κsrc) (y := cslotAddrA sl) (nc := fr) hxOS hdOS' hxy - (J.delCanA _ hdOS') hnullB - (Or.inr ⟨Or.inr ⟨ptr, size, rights, false, false, 0#u64, 0#u64, hfr⟩, - ⟨fun _ _ _ _ h => (by rw [hfr] at h; cases h), fun _ _ _ h => (by rw [hfr] at h; cases h)⟩⟩) - (by rw [← hslotIdx]; exact tcb_slot_notEptS hhp htT hi (by simp [layout.tcb.SLOT_BUFFER])) - ⟨slot, hslot, by rw [hI, ← hslotIdx]; exact CovZ.tcbSlot hhp htT hi⟩ hw' (by simp [hfr]) - (by rw [hS']; exact InsC.frame) (fun _ _ h => by rw [hS'] at h; cases h) (by rw [hS']; rfl) G' - have hibw : L.mem sB (ibWordA t) = baddr := by rw [ibWordA_eq]; exact L.mem_wr_same aM - have hspecB : ∀ x, σB.kheap (specPtr t) = some (.tcb x) → x.tcbIpcBuffer = baddr.bv := fun x hx => by - have e : σB.kheap (specPtr t) = some (.tcb { yd with tcbIpcBuffer := baddr.bv }) := by - simp [hσB, bufStateVA, updKSc_kheap, Function.update_apply] - rw [e] at hx - cases hx - rfl - obtain ⟨s2, σ2, hs2, hm, hbk, -, J2⟩ := JStage3A.capInsertTcbBufA (J := JB) κsrc sl (ps := ps) ⟨hss1, hss2⟩ - (t0 := t) hthT hsl (by rw [hS']; simp) hnullB (J.delCanA _ hdOS') - (nc := fr) (anc := absCapA fr) hwf (CapEqA.of_abs rfl) hw' (by simp [hfr]) - (by rw [hS']; exact Fl4ProofsA64.P3.DerivA.frame ptr size rights false mp ep asid va rights false false 0#u64 0#u64) - (by rw [hS']; exact ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by simp [hfr] at h⟩) - (by rw [hS']; trivial) (by rw [hS']; rfl) (by rw [hS']; rfl) (by rw [hS']; exact Or.inl rfl) - (fun r b' rs h _ => by - rw [hS'] at h - rcases h with h | h <;> simp [absCapA, absFrameE] at h) - (fun i h => by rw [hS'] at h; cases h) (fun i h => by simp [hfr] at h) (fun i h => by simp [hfr] at h) - (fun q k j h => by rw [hS'] at h; cases h) (fun h => by rw [hS'] at h; simp [isUtA] at h) (Or.inl hno) - (fun _ => by simp [hfr, CapValidA]) - ⟨fun _ _ h => by simp [hfr, absCapA, absFrameE] at h, fun _ h => by simp [hfr, absCapA, absFrameE] at h, - by simp [NoHiPtV, hfr, absCapA, absFrameE]⟩ - hl hagB ⟨ptr, size, rights, false, 0#u64, 0#u64, bits, rfl, hbits, hptrAl, rfl, hbal⟩ hibw hspecB - (fun s2 h2 => by - have h := hIP Z.G - rw [h2, WP.spec_ok] at h - exact h.2.1) - (fun s2 h2 => by - have h := hIP Z.G - rw [h2, WP.spec_ok] at h - exact h.1) - (fun s2 σ2 h2 _ => by - have h := hIP (insGA Gd (cslotAddrA κsrc) (cslotAddrA sl) - (insBA σB κsrc (absCapA fr) (absCapA (capA st sB (cslotAddrA κsrc))))) - rw [h2, WP.spec_ok] at h - exact h.2.2.2.2 σ2 m) - have wk := (capInsert_skA _ _ _ σB ((), σ2) hm).toDWkA - have B2 := BodyOKA.stepA B1 (delStep_ofKeepA hbk wk.off wk.ctSc) - obtain ⟨hc2, hd2⟩ := hdecIns s2 hs2 - obtain ⟨s', σ', Ac2, Bf2, stack2, hdecOk, hlast, J3, B3⟩ := tail _ _ _ _ s2 σ2 J2 (hc2.trans hcurB) B2 - (PreO.trans (R := DSkA) dskB (capInsert_skA _ _ _ σB ((), σ2) hm)) hd2 - refine ⟨.Ok (), s', ad, hdecOk, x', stUpdA σ σ.curThread x' .restart, σ', hx', rfl, hset', _, Q, R, hw, Ac2, Bf2, - stack2, J3, Or.inl ⟨rfl, fun _ => ?_, B3.1, B3.2.1⟩⟩ - refine setIpcBufG_invokeA _ baddr hspec hyd ?_ hlast - exact bufMidInsA mS (by rw [eS hS]; exact hsameF) mI (by rw [eI hI]; exact hsameT) hm + obtain ⟨r, s3, a3, σ3, hR, G', Q, Rl, hw, Ac', Bf', stack', J3, h⟩ := Md.bufStepA hA hPl P hCs I R (slot := slot) + (src := src) (baddr := baddr) (bc := fr) (frame := some (absCapA fr, κsrc)) hthT (κs := κs) hbal + (Or.inr ⟨hbn, hsrc0, ptr, rights, asid, va, bits, size, mp, ep, κsrc, hfr, hbits, rfl, hAκ, hκ, ⟨ps, hss1, hss2⟩, + hκsrc, hslot, hsrcOS, hneI, hneS, Or.inl ((hcapK src hsrcOS).trans hsrcF), Or.inl ((hcapK slot hslot).trans hcap), + subset_rfl⟩) + refine ⟨r, s3, a3, hdecBase.trans hR, x, _, σ3, hkx, rfl, hset, G', Q, Rl, hw, Ac', Bf', stack', J3, ?_⟩ + rcases h with ⟨hr', hs, hb, hc⟩ | ⟨hr', hs, hb, hc, hx, hk⟩ + · exact Or.inl ⟨hr', fun _ => (bufSpec_invokeA κs _ _).1 hs, hb, hc⟩ + · exact Or.inr ⟨hr', fun _ => (bufSpec_invokeA κs _ _).2 hs, hb, hc, hx, hk⟩ end diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgA.lean new file mode 100644 index 000000000..b8ba5a3d5 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgA.lean @@ -0,0 +1,179 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP3): **TCB Configure at the record**. + +`decode_configure` with three extra slots (CSpace root `cs`, VSpace root `vs`, buffer frame `bs`) and the buffer address +`baddr` (zero or a non-zero frame address, one statement through `TcbBufSrcA`): `JSyscallA.configFrontA` (restart and +the two root installs), then `TcbMidA.bufStepA` (`install_buffer`), assembled into the outcome `TcbChainOutA`. + +* **`TcbBufSrcA.transA`**: the buffer source's entry facts hold again after the two root installs (the root slots are + neither the buffer source nor the invoked slot). +* **`JSyscallA.configureA`**: the arm. + +Named premises as for `JSyscallA.setSpaceA` and `TcbMidA.bufStepA`. New module. +-/ +import Fl4ProofsA64.P3.Stage3LiftTcbCfgFrontA +import Fl4ProofsA64.P3.Stage3TcbBufMidA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **The buffer source's facts survive the two root installs** (module docstring). -/ +theorem TcbBufSrcA.transA {th : TypedHeapA} {OS Ag : Set U64} {s0 s6 : S} {t slot src baddr : U64} {bc : capability.Cap} + {κs : CslotPtr} {frame : Option (Fl4SpecA64.Cap × CslotPtr)} + (hB : TcbBufSrcA st th OS Ag s0 t slot src baddr bc κs frame) + (hK : ∀ y ∈ OS, y ≠ cslotAddrA (specPtr t, tcbCnodeIndex 0) → y ≠ cslotAddrA (specPtr t, tcbCnodeIndex 1) → + ChgZA st s0 s6 y) + (hnS : baddr ≠ 0#u64 → src ≠ cslotAddrA (specPtr t, tcbCnodeIndex 0) ∧ src ≠ cslotAddrA (specPtr t, tcbCnodeIndex 1)) + (hnI : baddr ≠ 0#u64 → slot ≠ cslotAddrA (specPtr t, tcbCnodeIndex 0) ∧ slot ≠ cslotAddrA (specPtr t, tcbCnodeIndex 1)) : + TcbBufSrcA st th OS Ag s6 t slot src baddr bc κs frame := by + rcases hB with h | ⟨hb, hs, ptr, rights, asid, va, bits, size, mp, ep, κsrc, hbc, hsz, hfr, hAκ, hκ, hCs', hκs, hslOS, + hsrOS, hn2s, hn2i, hcs, hci, hag⟩ + · exact Or.inl h + · exact Or.inr ⟨hb, hs, ptr, rights, asid, va, bits, size, mp, ep, κsrc, hbc, hsz, hfr, hAκ, hκ, hCs', hκs, hslOS, hsrOS, + hn2s, hn2i, chgZ_keepA (hK src hsrOS (hnS hb).1 (hnS hb).2) hcs, + chgZ_keepA (hK slot hslOS (hnI hb).1 (hnI hb).2) hci, hag⟩ + +/-- **The derived buffer frame for a non-zero aligned address** (module docstring). -/ +theorem cfgDeriveBufNzA {s : S} {bs baddr ptr rights asid va : U64} {size : capability.FrameSize} {mp ep : Bool} + (hbn : baddr ≠ 0#u64) (hbal : baddr.val % 1024 = 0) (hsrcF : capA st s bs = .Frame ptr size rights false mp ep asid va) : + tcb.derive_for_buffer st s baddr bs = ok (.Ok (.Frame ptr size rights false false false 0#u64 0#u64, bs)) := by + have hCapF : obj.Slot.cap st bs s = ok (.Frame ptr size rights false mp ep asid va) := + (capA_eq s bs).trans (by rw [hsrcF]) + have hal : isAligned baddr.bv msgAlignBits := bufAligned_ofModA baddr hbal + rw [tcbDeriveBuffer_frameA hbn hCapF] + simp only [tcbBufferCheck_nativeA, bind_ok, Bool.false_eq_true, ite_false, hal, ite_true] + + +end + +section arm +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {Clock : A → Fl4SpecA64.MachineState → Prop} {Ag : Set U64} + +set_option maxHeartbeats 32000000 in +/-- **TCB Configure at a syscall entry** (module docstring). -/ +theorem JSyscallA.configureA [PlainStore st] + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hCnt : CounterStepA σ) (hCl : Clock a σ.machineState) (hag : FrAgA st OS Ag s σ) + (P : DelPlatA st ar AR Clock) (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t cs vs bs cdata vdata baddr src : U64} {blk call don : Bool} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBConfigure) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 3#u64 = ok (.Ok cs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 3#u64 = ok (.Ok vs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 3#u64 = ok (.Ok bs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + (hba : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 2#u64 = ok baddr) + {bc : capability.Cap} (hbuf : tcb.derive_for_buffer st s baddr bs = ok (.Ok (bc, src))) + (hsrcX : baddr ≠ 0#u64 → src = bs) (hbal : baddr.val % 1024 = 0) + {ccap vcap : capability.Cap} + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + {p r gs g gs' g' : U64} (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hwfc : CapWfA ccap) (hencc : CapRt.EncWf ccap) + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hvdr : ∀ s' : S, objects.derive_cap st s' vs vcap = ok (.Ok vcap)) + {κs κcs κvs : CslotPtr} {frame : Option (Fl4SpecA64.Cap × CslotPtr)} + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) + (hB : TcbBufSrcA st Z.th OS Ag s t slot src baddr bc κs frame) : + ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (r, s3, a3) ∧ + ∃ (xc : Fl4SpecA64.Tcb) (σ1 : Fl4SpecA64.State Unit), σ.kheap σ.curThread = some (.tcb xc) ∧ + σ1 = stUpdA σ σ.curThread xc .restart ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + TcbChainOutA st AR Clock Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa σ σ1 + (.threadControlCaps (specPtr t) κs none none (some (absCapA ccap, κcs)) (some (absCapA vcap, κvs)) + (some (Fl4SpecA64.dataToVref baddr.bv, frame))) r s3 a3 := by + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have hthT : Z.th t = some .tcb := (J.j.1.thT t).2 ht + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + obtain ⟨x, σ1, hkx, e1, hset, hr, o⟩ := J.configFrontA hA hPl s a σ m hCnt hCl hag P hCs h1 hslot hcov hcap hext hSC he0 he1 + ⟨p, r, gs, g, gs', g', hcc, hccap⟩ hwfc hencc hvc hvk hvdr hAκ hκ hAc hκc hAv hκv + have hdecBase : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + tcb.thread_control_caps st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot (capability.Cap.Null, 0#u64) + (capability.Cap.Null, 0#u64) (ccap, cs) (vcap, vs) baddr (bc, src) + (tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl] + exact tcbConfigure_selectedA hstall he0 he1 he2 hcd hvd hba hbuf hRoots hr + have hnbs : baddr ≠ 0#u64 → (src ≠ cslotAddrA (specPtr t, tcbCnodeIndex 0) ∧ src ≠ cslotAddrA (specPtr t, tcbCnodeIndex 1)) ∧ + (slot ≠ cslotAddrA (specPtr t, tcbCnodeIndex 0) ∧ slot ≠ cslotAddrA (specPtr t, tcbCnodeIndex 1)) := by + intro hb + rcases hB with h | ⟨-, -, ptr, rights, asid, va, bits, size, mp, ep, κsrc, hbc, hsz, hfr, hAκ', hκ', hCs', hκs, hslOS, + hsrOS, -⟩ + · exact absurd h.1 hb + · obtain ⟨psb, hCb1, hCb2⟩ := hCs' + have hAs : AbsSlotA Z.th κsrc := ⟨psb, hCb1, Or.inl hCb2⟩ + have hCb : κsrc.1 = specPtr psb ∧ Z.th psb = some (.cnode κsrc.2.length) := ⟨hCb1, hCb2⟩ + obtain ⟨psI, hCI⟩ := J.toJStage3A.tcbSrcCnA hcov hAκ hκ + have hP := J.j.1.place + refine ⟨⟨?_, ?_⟩, ?_, ?_⟩ + · rw [← hκs]; exact tcbSlotNeA hP (by decide) hAs hCb hthT + · rw [← hκs]; exact tcbSlotNeA hP (by decide) hAs hCb hthT + · rw [← hκ]; exact tcbSlotNeA hP (by decide) hAκ hCI hthT + · rw [← hκ]; exact tcbSlotNeA hP (by decide) hAκ hCI hthT + rcases o with hpre | ⟨s4, s6, a2, a3, σ2, σ4, G', Q, R1, hw, Ac', Bf', stack', Vc, Ub, Pt, Ac1, K0, Ty, I, h0, h1', hs0, hs1, + Md1, R1', hch⟩ + · obtain ⟨s', a', σ', G', Q, R, hw, Ac', Bf', stack', hc, Jd, hpp, hcur, hpre, hclk, hsp⟩ := + hpre _ baddr (bc, src) rfl + exact ⟨.Err .Preempted, s', a', hdecBase.trans hc, x, σ1, hkx, e1, hset, σ', G', Q, R, hw, Ac', Bf', stack', Jd, + Or.inr ⟨rfl, hsp _, hpp, hcur, hpre, hclk⟩⟩ + · have hB6 := hB.transA hch (fun hb => (hnbs hb).1) (fun hb => (hnbs hb).2) + obtain ⟨rb, s2, a5, σ', hinst, Gi, Q, Rl, hw, Ac2, Bf2, stack2, J2, ob⟩ := + Md1.bufStepA hA hPl P hCs I R1' hthT hbal hB6 + refine ⟨rb, s2, a5, hdecBase.trans (tcbCaps_cfg_bufA h0 h1' hinst), x, σ1, hkx, e1, hset, σ', Gi, Q, Rl, hw, Ac2, Bf2, + stack2, J2, ?_⟩ + rcases ob with ⟨rfl, hf, hok, hcur⟩ | ⟨rfl, hf, hp, hcur, hpre, hclk⟩ + · exact Or.inl ⟨rfl, configure_specA hs0 hs1 hf, hok, hcur.trans Md1.body.2.1⟩ + · exact Or.inr ⟨rfl, configure_specPreFA hs0 hs1 hf, hp, hcur.trans Md1.body.2.1, hpre, hclk⟩ + +end arm + +section arm2 +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} + +/-- **The buffer source of a non-zero-address Configure** (module docstring). -/ +theorem JSyscallA.cfgHBnzA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} {hPlipa : U64} + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPlipa)) s a σ m) + {slot t bs baddr ptr rights asid va bits : U64} {size : capability.FrameSize} {mp ep : Bool} + {κs κbs : CslotPtr} (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hbs0 : bs ≠ 0#u64) (hbsOS : bs ∈ OS) (hSCb : SlotCov st OS s bs) (hbn : baddr ≠ 0#u64) + (hsrcF : capA st s bs = .Frame ptr size rights false mp ep asid va) (hbits : size.bits = ok bits) + {Ag : Set U64} (hag : {b | ∃ k : U64, k.val < 128 ∧ b = bufW (bufAddrOfA ptr baddr bits) k} ⊆ Ag) + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) (hAb : AbsSlotA Z.th κbs) (hκb : cslotAddrA κbs = bs) : + TcbBufSrcA st Z.th OS Ag s t slot bs baddr (.Frame ptr size rights false false false 0#u64 0#u64) κs + (some (absCapA (.Frame ptr size rights false false false 0#u64 0#u64), κbs)) := by + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have hthT : Z.th t = some .tcb := (J.j.1.thT t).2 ht + obtain ⟨psb, hCb⟩ := J.toJStage3A.tcbSrcCnA hSCb hAb hκb + obtain ⟨psI, hCI⟩ := J.toJStage3A.tcbSrcCnA hcov hAκ hκ + have hP := J.j.1.place + refine Or.inr ⟨hbn, hbs0, ptr, rights, asid, va, bits, size, mp, ep, κbs, rfl, hbits, rfl, hAκ, hκ, ⟨psb, hCb⟩, hκb, + hslot, hbsOS, ?_, ?_, Or.inl hsrcF, Or.inl hcap, hag⟩ + · rw [← hκ]; exact tcbSlotNeA hP (by decide) hAκ hCI hthT + · rw [← hκb]; exact tcbSlotNeA hP (by decide) hAb hCb hthT + +end arm2 + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgFrontA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgFrontA.lean new file mode 100644 index 000000000..cd6d08724 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgFrontA.lean @@ -0,0 +1,211 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP3): **TCB Configure, the front of the chain**. + +`decode_configure` with extra slots (CSpace root `cs`, VSpace root `vs`, buffer frame `bs`): `restart_caller`, then the +slot-0 and slot-1 `install_tcb_cap`s (`thread_control_caps` flags `SPACE | IPC_BUFFER`), chained by `TcbMidA.chainStepA` +from `JSyscallA.tcbChainStartA`; the buffer step (`install_buffer`) follows in `TcbMidA.bufStepA`. + +* `configure_spec{Pre0,Pre1,}A`: the spec's `invoke_tcb` of a Configure from the outcomes of its two root installs (and the + frame-cap install). +* **`JSyscallA.configFrontA`**: the front. Either a root install is preempted (the whole decode is `Err Preempted`, with the + spec's error), or both succeed and the record is at the mid state `Md1` with the install equations. + +Named premises as for `JSyscallA.setSpaceA`. New module. +-/ +import Fl4ProofsA64.P3.Stage3LiftTcbSpaceA +import Fl4ProofsA64.P3.Stage3TcbConfigSelA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section spec +variable {σ1 σ2 σ3 σ4 σ5 : Fl4SpecA64.State Unit} {t : ObjRef} {κs : CslotPtr} {c0 v0 : Cap × CslotPtr} + {bf : Option (VSpaceRef × Option (Cap × CslotPtr))} + +theorem configure_specPre0A + (h0 : (.error (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 0 (some c0)).run σ1).1) : + (.error (), σ2) ∈ ((fl4InvokeTcb (.threadControlCaps t κs none none (some c0) (some v0) bf)).run σ1).1 := by + have hSkip (n : Nat) : fl4InstallTcbCap (Z := Unit) t κs n none = Fl4Spec.NonDetE.returnOk () := rfl + simp only [fl4InvokeTcb, hSkip] + rw [run_bind_okD (run_returnOkD () σ1), run_bind_okD (run_returnOkD () σ1)] + exact mem_bindE_errD h0 + +theorem configure_specPre1A + (h0 : (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 0 (some c0)).run σ1).1) + (h1 : (.error (), σ3) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 1 (some v0)).run σ2).1) : + (.error (), σ3) ∈ ((fl4InvokeTcb (.threadControlCaps t κs none none (some c0) (some v0) bf)).run σ1).1 := by + have hSkip (n : Nat) : fl4InstallTcbCap (Z := Unit) t κs n none = Fl4Spec.NonDetE.returnOk () := rfl + simp only [fl4InvokeTcb, hSkip] + rw [run_bind_okD (run_returnOkD () σ1), run_bind_okD (run_returnOkD () σ1)] + refine mem_bindE_okD h0 ?_ + exact mem_bindE_errD h1 + +/-- Both roots installed, the frame cap installed (`hf`): the whole `invoke_tcb` succeeds. -/ +theorem configure_specA + (h0 : (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 0 (some c0)).run σ1).1) + (h1 : (.ok (), σ3) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 1 (some v0)).run σ2).1) + (hf : (.ok (), σ4) ∈ ((fl4InstallTcbFrameCap (Z := Unit) t κs bf).run σ3).1) : + (.ok [], σ4) ∈ ((fl4InvokeTcb (.threadControlCaps t κs none none (some c0) (some v0) bf)).run σ1).1 := by + have hSkip (n : Nat) : fl4InstallTcbCap (Z := Unit) t κs n none = Fl4Spec.NonDetE.returnOk () := rfl + simp only [fl4InvokeTcb, hSkip] + rw [run_bind_okD (run_returnOkD () σ1), run_bind_okD (run_returnOkD () σ1)] + refine mem_bindE_okD h0 ?_ + refine mem_bindE_okD h1 ?_ + refine mem_bindE_okD hf ?_ + rw [run_returnOkD] + simp + +/-- The frame-cap install fails (`Preempted`). -/ +theorem configure_specPreFA + (h0 : (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 0 (some c0)).run σ1).1) + (h1 : (.ok (), σ3) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 1 (some v0)).run σ2).1) + (hf : (.error (), σ4) ∈ ((fl4InstallTcbFrameCap (Z := Unit) t κs bf).run σ3).1) : + (.error (), σ4) ∈ ((fl4InvokeTcb (.threadControlCaps t κs none none (some c0) (some v0) bf)).run σ1).1 := by + have hSkip (n : Nat) : fl4InstallTcbCap (Z := Unit) t κs n none = Fl4Spec.NonDetE.returnOk () := rfl + simp only [fl4InvokeTcb, hSkip] + rw [run_bind_okD (run_returnOkD () σ1), run_bind_okD (run_returnOkD () σ1)] + refine mem_bindE_okD h0 ?_ + refine mem_bindE_okD h1 ?_ + exact mem_bindE_errD hf + +end spec + +section arm +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {Clock : A → Fl4SpecA64.MachineState → Prop} {Ag : Set U64} + +set_option maxHeartbeats 32000000 in +/-- **The front of TCB Configure at a syscall entry** (module docstring). -/ +theorem JSyscallA.configFrontA [PlainStore st] + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hCnt : CounterStepA σ) (hCl : Clock a σ.machineState) (hag : FrAgA st OS Ag s σ) + (P : DelPlatA st ar AR Clock) (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot len buf t cs vs : U64} {call : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 3#u64 = ok (.Ok cs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 3#u64 = ok (.Ok vs)) + {ccap vcap : capability.Cap} + (hcc : ∃ p r gs g gs' g', capA st s cs = .CNode p r gs g ∧ ccap = .CNode p r gs' g') + (hwfc : CapWfA ccap) (hencc : CapRt.EncWf ccap) + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hvdr : ∀ s' : S, objects.derive_cap st s' vs vcap = ok (.Ok vcap)) + {κs κcs κvs : CslotPtr} + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) : + ∃ (x : Fl4SpecA64.Tcb) (σ1 : Fl4SpecA64.State Unit), σ.kheap σ.curThread = some (.tcb x) ∧ + σ1 = stUpdA σ σ.curThread x .restart ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + tcb.restart_caller st s = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) ∧ + -- a root install is preempted + ((∀ (flags : U64) (baddr : U64) (bufCap : capability.Cap × obj.Slot), + flags = (tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) → + ∃ (s' : S) (a' : A) (σ' : Fl4SpecA64.State Unit) (G' : MdbGhostA) (Q : U64 → U64 → List U64) (R : U64 → List U64) + (hw : HwRootA) (Ac' : Set U64) (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64), + tcb.thread_control_caps st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot + (capability.Cap.Null, 0#u64) (capability.Cap.Null, 0#u64) (ccap, cs) (vcap, vs) baddr bufCap flags = + ok (.Err .Preempted, s', a') ∧ + JStage3A st AR { Z with G := G', Q := Q, R := R, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' κ n + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s' a' σ' m ∧ + BodyPreA σ' m ∧ σ'.curThread = σ.curThread ∧ PreExitA σ' ∧ Clock a' σ'.machineState ∧ + ∀ bf, (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none + (some (absCapA ccap, κcs)) (some (absCapA vcap, κvs)) bf)).run σ1).1) ∨ + -- both roots installed + (∃ (s4 s6 : S) (a2 a3 : A) (σ2 σ4 : Fl4SpecA64.State Unit) (G' : MdbGhostA) (Q : U64 → U64 → List U64) + (R1 : U64 → List U64) (hw : HwRootA) (Ac' : Set U64) (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64) + (Vc Ub Pt Ac1 : Set U64) (K0 : capability.Cap → Prop) (Ty : S → Prop) + (I : DelIn st ar H Z.Cs OS Vc Ub Pt K0 Ty s), + tcb.install_tcb_cap st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot layout.tcb.SLOT_CTABLE ccap cs = + ok (.Ok (), s4, a2) ∧ + tcb.install_tcb_cap st ar s4 a2 t slot layout.tcb.SLOT_VTABLE vcap vs = ok (.Ok (), s6, a3) ∧ + (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs 0 (some (absCapA ccap, κcs))).run σ1).1 ∧ + (.ok (), σ4) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs 1 (some (absCapA vcap, κvs))).run σ2).1 ∧ + TcbMidA st AR Clock σ.curThread { Z with G := G', Q := Q, R := R1, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' + stack' κ n ar hPl.ipa Ag s6 a3 σ4 m ∧ + DelR st H Z.Cs OS Vc Ub Ac1 Ty ia ie s s6 ∧ + (∀ y ∈ OS, y ≠ cslotAddrA (specPtr t, tcbCnodeIndex 0) → y ≠ cslotAddrA (specPtr t, tcbCnodeIndex 1) → + ChgZA st s s6 y))) := by + obtain ⟨p, r, gs, g, gs', g', hcc, hccap⟩ := hcc + subst hccap + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have hthT : Z.th t = some .tcb := (J.j.1.thT t).2 ht + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t := by + obtain ⟨cI, hgI, hcI⟩ := getCap_eqA J.j.1.st hAκ + rw [capAtA_eq (st := st), hκ, hcap] at hcI + have eI : cI = .threadCap (specPtr t) := (CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)).symm + have hcapS : specCapAtA σ κs = some (.threadCap (specPtr t)) := by + rw [← eI]; exact (getCap_outA (c := cI) (σ' := σ) (by rw [hgI]; exact rfl)).2 + exact fun c hc e => (J.sidle.f6 κs).1 c hc (e ▸ hcapS) + obtain ⟨hcM, hc0⟩ := tcbExtra0_memA he1 + obtain ⟨hvM, hv0⟩ := tcbExtra1_memA he2 + have hcOS : cs ∈ OS := hext _ hcM hc0 + have hvOS : vs ∈ OS := hext _ hvM hv0 + obtain ⟨psc, hCc⟩ := J.toJStage3A.tcbSrcCnA (hSC _ hcM hc0) hAc hκc + obtain ⟨psv, hCv⟩ := J.toJStage3A.tcbSrcCnA (hSC _ hvM hv0) hAv hκv + obtain ⟨psI, hCI⟩ := J.toJStage3A.tcbSrcCnA hcov hAκ hκ + have hP := J.j.1.place + have nec : ∀ i : Nat, i < 7 → cs ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) := fun i hi => by + rw [← hκc]; exact tcbSlotNeA hP hi hAc hCc hthT + have nev : ∀ i : Nat, i < 7 → vs ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) := fun i hi => by + rw [← hκv]; exact tcbSlotNeA hP hi hAv hCv hthT + have neI : ∀ i : Nat, i < 7 → slot ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) := fun i hi => by + rw [← hκ]; exact tcbSlotNeA hP hi hAκ hCI hthT + obtain ⟨x, hkx, hr, hcapK, hset, Md0, Vc, Ub, Pt, Ac1, K0, Ty, I, R0⟩ := + J.tcbChainStartA hA hPl hCnt hCl hag hslot hcov hext hcap hstall + refine ⟨x, stUpdA σ σ.curThread x .restart, hkx, rfl, hset, hr, ?_⟩ + -- slot 0: the CSpace root + obtain ⟨r0, s4, a2, σ3, h0, R0', o0⟩ := Md0.chainStepA (t := t) (idx := layout.tcb.SLOT_CTABLE) (slot := slot) + (src := cs) (i := 0) hA hPl P hCs I R0 hthT (by simp [layout.tcb.SLOT_CTABLE]) (by decide) (by decide) + (by decide) hidles (tcbSlotRootA t _ 0 (by simp [layout.tcb.SLOT_CTABLE]) (by decide)) hAκ hκ (ps := psc) + hCc hκc hc0 hcOS hslot (nec 0 (by decide)) (neI 0 (by decide)) (c0 := .CNode p r gs g) + (fun h => by cases h) (fun _ => tcbInsKA_cnodeA (by decide) hwfc hencc) + (fun _ _ => Or.inr ⟨p, r, gs, g, gs', g', rfl, rfl⟩) + (fun _ => ⟨Or.inr (Or.inl ⟨_, _, _, _, rfl⟩), hencc⟩) + (Or.inl ((hcapK cs hcOS).trans hcc)) (Or.inl ((hcapK slot hslot).trans hcap)) + rcases o0 with ⟨hr0, hspec0, hch0, hdd0, Gi0, Q0, Rl0, hw0, Ac0, Bf0, stack0, Md0'⟩ | + ⟨hr0, hspec0, hpp0, hcur0, hpre0, hclk0, Gi0, Q0, Rl0, hw0, Ac0, Bf0, stack0, Jd0⟩ + swap + · subst hr0 + refine Or.inl fun flags baddr bufCap hfl => ?_ + subst hfl + exact ⟨s4, a2, σ3, Gi0, Q0, Rl0, hw0, Ac0, Bf0, stack0, tcbCaps_cfg_pre0A h0, Jd0, hpp0, hcur0, hpre0, hclk0, + fun bf => configure_specPre0A hspec0⟩ + subst hr0 + -- slot 1: the VSpace root + obtain ⟨r1, s6, a3, σ4, h1', R1', o1⟩ := Md0'.chainStepA (t := t) (idx := layout.tcb.SLOT_VTABLE) (slot := slot) + (src := vs) (i := 1) hA hPl P hCs I R0' hthT (by simp [layout.tcb.SLOT_VTABLE]) (by decide) (by decide) + (by decide) hidles (tcbSlotRootA t _ 1 (by simp [layout.tcb.SLOT_VTABLE]) (by decide)) hAκ hκ (ps := psv) + hCv hκv hv0 hvOS hslot (nev 1 (by decide)) (neI 1 (by decide)) (c0 := vcap) + (fun h => by rw [h]; rfl) (fun _ => tcbInsKA_selfA hvk (fun h => absurd h (by decide))) + (fun _ s' => Or.inl (hvdr s')) (fun _ => ⟨hvk, capEnc_ofA s vs hvc⟩) + (chgZ_keepA (hch0 vs hvOS (nev 0 (by decide))) (Or.inl ((hcapK vs hvOS).trans hvc))) + (chgZ_keepA (hch0 slot hslot (neI 0 (by decide))) (Or.inl ((hcapK slot hslot).trans hcap))) + rcases o1 with ⟨hr1, hspec1, hch1, hdd1, Gi1, Q1, Rl1, hw1, Acx, Bf1, stack1, Md1⟩ | + ⟨hr1, hspec1, hpp1, hcur1, hpre1, hclk1, Gi1, Q1, Rl1, hw1, Acx, Bf1, stack1, Jd1⟩ + swap + · subst hr1 + refine Or.inl fun flags baddr bufCap hfl => ?_ + subst hfl + exact ⟨s6, a3, σ4, Gi1, Q1, Rl1, hw1, Acx, Bf1, stack1, tcbCaps_cfg_pre1A h0 h1', Jd1, hpp1, + hcur1.trans Md0'.body.2.1, hpre1, hclk1, fun bf => configure_specPre1A hspec0 hspec1⟩ + subst hr1 + exact Or.inr ⟨s4, s6, a2, a3, σ3, σ4, Gi1, Q1, Rl1, hw1, Acx, Bf1, stack1, Vc, Ub, Pt, Ac1, K0, Ty, I, h0, h1', + hspec0, hspec1, Md1, R1', fun y hy h0' h1'' => (ChgZA.of_eq (hcapK y hy)).trans ((hch0 y hy h0').trans (hch1 y hy h1''))⟩ + +end arm + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbHighA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbHighA.lean new file mode 100644 index 000000000..233ecbc80 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbHighA.lean @@ -0,0 +1,233 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP1): **TCB SetHighVSpace at the record**. + +`decode_set_high_vspace` with extra slot 0 holding `Null` or a mapped `HighVSpace` cap whose ASID still names it: +`restart_caller`, then `install_tcb_cap` of TCB slot 6 (`restartDelA`'s deletion, `installTcbCapA`). + +* **`setHighVSpaceCapA`**: the two admitted source caps (`Null`, or the live window), with the `find_high_asid` hit. +* **`TcbHighOutA`**: `TcbDelOutA`'s shape for the spec's `invoke_set_high_vspace` (`fl4Invocation`'s own constructor, not + `invoke_tcb`). +* **`JSyscallA.setHighVSpaceA`**: the arm. The target may be the caller. + +Named premises: those of `JSyscallA.restartDelA`, [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, [S] `h1`. +The `Err` returns before the deletion are not lifted. New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbInstallA +import Fl4ProofsA64.P3.Stage3TcbPreExitA +import Fl4ProofsA64.P3.TcbInvokeHighSelectA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +theorem tcbExtraSome_memA {c : tcb.Ctx} {src : U64} (he : tcb.extra c 0#usize = ok (some src)) : + src ∈ c.extra.val ∧ src ≠ 0#u64 := by + unfold tcb.extra at he + split at he + · cases okinj he + obtain ⟨y, hy, he⟩ := bind_eq_ok he + obtain ⟨b, hb, he⟩ := bind_eq_ok he + have hlen : c.extra.val.length = 3 := by simp + have hm : y ∈ c.extra.val := by + obtain ⟨v, hv, e⟩ := spec_existsA (Aeneas.Std.Array.index_usize_spec c.extra 0#usize (by simp [hlen])) + have ev : v = y := okinj (hv.symm.trans hy) + rw [← ev, e] + exact List.getElem_mem _ + unfold obj.Slot.is_null at hb + have hb' : b = decide (y = 0#u64) := (okinj hb).symm + by_cases h0 : y = 0#u64 + · rw [hb', decide_eq_true h0, if_pos rfl] at he + cases okinj he + · rw [hb', decide_eq_false h0] at he + simp only [Bool.false_eq_true, ↓reduceIte] at he + have e := Option.some.inj (okinj he) + exact e ▸ ⟨hm, h0⟩ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **The source caps SetHighVSpace admits** (module docstring): `Null`, or a mapped window whose ASID names it. -/ +def setHighVSpaceCapA (st : machine.Store S) [L : LawfulStore st] (s : S) (src : U64) : Prop := + capA st s src = .Null ∨ + ∃ p asid, capA st s src = .HighVSpace p true asid ∧ vspace.find_high_asid st s asid = ok (.Ok p) + +/-- **`TcbDelOutA` for the spec's `invoke_set_high_vspace`** (module docstring), `Inv κs` the invocation at the invoked +slot `κs`. -/ +def TcbHighOutA (st : machine.Store S) [L : LawfulStore st] (AR : A → HwRootA → Prop) + (Clock : A → Fl4SpecA64.MachineState → Prop) (Z : XSetsA) (H : Heap) + (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) (N E Rp : Set U64) + (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (n : Nat) (m : McState) + (ar : machine.Arch A) (ipa : U64) (s : S) (a : A) (σ : State Unit) + (Inv : CslotPtr → SetHighVSpaceInvocation) (κs : CslotPtr) (r : core.result.Result Unit error.Exc) (s3 : S) + (a3 : A) : Prop := + ∃ xc σ1 σ3, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + ∃ (G' : MdbGhostA) (Q : U64 → U64 → List U64) (R : U64 → List U64) (hw : HwRootA) (Ac' : Set U64) + (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64), + JStage3A st AR { Z with G := G', Q := Q, R := R, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' κ n + (J5A st) (J7A st (J7R2A st ar ipa)) s3 a3 σ3 m ∧ + ((r = .Ok () ∧ (.ok (), σ3) ∈ ((invokeSetHighVSpace (Z := Unit) (Inv κs)).run σ1).1 ∧ + Sched.BodyEndA σ σ3 m) ∨ + (r = .Err .Preempted ∧ (.error (), σ3) ∈ ((invokeSetHighVSpace (Z := Unit) (Inv κs)).run σ1).1 ∧ + BodyPreA σ3 m ∧ σ3.curThread = σ.curThread ∧ PreExitA σ3 ∧ Clock a3 σ3.machineState)) + +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {Clock : A → Fl4SpecA64.MachineState → Prop} + +set_option maxHeartbeats 8000000 in +/-- **TCB SetHighVSpace at a syscall entry** (module docstring). -/ +theorem JSyscallA.setHighVSpaceA [PlainStore st] + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) (hCnt : CounterStepA σ) + (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t src : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetHighVSpace) + (he : tcb.extra ⟨len, buf, call, slot, extra⟩ 0#usize = ok (some src)) + (hsrc : setHighVSpaceCapA st s src) + {κs κsrc : CslotPtr} (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) : + ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (r, s3, a3) ∧ + TcbHighOutA st AR Clock Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ + (fun κs => ⟨specPtr t, κs, absCapA (capA st s src), κsrc⟩) κs r s3 a3 := by + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have hthT : Z.th t = some .tcb := (J.j.1.thT t).2 ht + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t := by + obtain ⟨cI, hgI, hcI⟩ := getCap_eqA J.j.1.st hAκ + rw [capAtA_eq (st := st), hκ, hcap] at hcI + have eI : cI = .threadCap (specPtr t) := (CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)).symm + have hcapS : specCapAtA σ κs = some (.threadCap (specPtr t)) := by + rw [← eI]; exact (getCap_outA (c := cI) (σ' := σ) (by rw [hgI]; exact rfl)).2 + exact fun c hc e => (J.sidle.f6 κs).1 c hc (e ▸ hcapS) + obtain ⟨hsrcM, hsrc0⟩ := tcbExtraSome_memA he + have hsrcOS : src ∈ OS := hext _ hsrcM hsrc0 + obtain ⟨ss', ps, hss1, hss2, hss3, -⟩ := J.toJStage3A.cnSlot_of_covA (hSC _ hsrcM hsrc0) + have ess : κsrc = ss' := + cslotAddrA_inj J.j.1.place hAsrc ⟨ps, hss1, Or.inl hss2⟩ (hκsrc.trans hss3.symm) + subst ess + set sl : Fl4SpecA64.CslotPtr := (specPtr t, tcbCnodeIndex 6) with hsl + have hAd : AbsSlotA Z.th sl := ⟨t, rfl, Or.inr ⟨hthT, 6, by decide, rfl⟩⟩ + have h6 : layout.tcb.SLOT_HIGH_VSPACE.val = 6 := by simp [layout.tcb.SLOT_HIGH_VSPACE] + have hslotIdx : slotIdx t layout.tcb.SLOT_HIGH_VSPACE = cslotAddrA sl := by + rw [slotIdx_addrA, h6] + unfold cslotAddrA + show _ = slotAddrA (specPtr t) (Fl4SpecA64.ofBl (tcbCnodeIndex 6)) + rw [ofBl_tcbIdx 6 (by decide)] + have hdest : obj.Tcb.slot t layout.tcb.SLOT_HIGH_VSPACE = ok (cslotAddrA sl) := by + rw [← hslotIdx]; exact tcb_slot_val _ _ + have hneS : src ≠ cslotAddrA sl := fun e => by + have h := cslotAddrA_inj J.j.1.place hAsrc hAd (hκsrc.trans e) + have e1 : specPtr ps = specPtr t := by rw [← hss1, h] + rw [specPtr_inj e1, hthT] at hss2 + cases hss2 + have hneI : slot ≠ cslotAddrA sl := fun e => by + obtain ⟨si', pi, hsi1, hsi2, hsi3, -⟩ := J.toJStage3A.cnSlot_of_covA hcov + have h := cslotAddrA_inj J.j.1.place (show AbsSlotA Z.th si' from ⟨pi, hsi1, Or.inl hsi2⟩) hAd (hsi3.trans e) + have e1 : specPtr pi = specPtr t := by rw [← hsi1, h] + rw [specPtr_inj e1, hthT] at hsi2 + cases hsi2 + obtain ⟨xr, heq, hset, D1, hdelWP⟩ := J.restartDelA s a σ m hPl hCnt hslot hcov hext P hCl hCs sl hAd + obtain ⟨x', hx', -, hset', -⟩ := J.restartMachA hslot hcov hext + have e1 : stUpdA σ σ.curThread xr .restart = stUpdA σ σ.curThread x' .restart := by + have := Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (hset.symm.trans hset')) + exact (Prod.mk.inj this).2 + have hr : tcb.restart_caller st s = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, heq] + obtain ⟨⟨r, sd, ad⟩, hdel0, σd, Gd, Dd, hres, hW⟩ := spec_existsA hdelWP + have sysd := J.sysDelSlotA hA hPl hslot hcov hext hcap layout.tcb.SLOT_HIGH_VSPACE + (by rw [h6]; decide) hstall hr (r := r) (sd := sd) (ad := ad) (by rw [hslotIdx]; exact hdel0) + have hCap : obj.Slot.cap st src s = ok (capA st s src) := capA_eq s src + have hdecBase : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + tcb.install_tcb_cap st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot layout.tcb.SLOT_HIGH_VSPACE + (capA st s src) src := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl] + rcases hsrc with hn | ⟨p, asid, hc, hfind⟩ + · rw [hn] + exact tcbSetHighVSpace_clearA hstall he (hCap.trans (by rw [hn])) hr + · rw [hc] + exact tcbSetHighVSpace_liveA hstall he (hCap.trans (by rw [hc])) hfind + (by simp [objects.derive_cap]) hr + rcases hres with ⟨hr1, hnull, hspec, hch⟩ | ⟨hr1, hspec⟩ + swap + · subst hr1 + obtain ⟨⟨⟨-, X, sv⟩, tm⟩, hpre⟩ := hW + obtain ⟨Q, R, hw, Ac', Bf', stack', Jd⟩ := X.toStage3A sysd.1 sysd.2 sv + rw [e1] at hspec + obtain ⟨hR, hS⟩ := tcbInstallCap_preemptedA (target := t) (src := src) (nc := capA st s src) (κs := κs) + (κsrc := κsrc) (anc := absCapA (capA st s src)) hdest hdel0 hspec + refine ⟨.Err .Preempted, sd, ad, hdecBase.trans hR, x', stUpdA σ σ.curThread x' .restart, σd, hx', rfl, hset', + Gd, Q, R, hw, Ac', Bf', stack', Jd, Or.inr ⟨rfl, hS, hpre.1, hpre.2.1, hpre.preExitA, tm.2.1⟩⟩ + subst hr1 + obtain ⟨⟨⟨-, X, sv⟩, -⟩, Binv, -⟩ := hW + obtain ⟨Q, R, hw, Ac', Bf', stack', Jd⟩ := X.toStage3A sysd.1 sysd.2 sv + rw [e1] at hspec + have hkeep : ∀ y ∈ OS, y ≠ cslotAddrA sl → ∀ c, capA st s y = c → + capA st sd y = c ∨ capA st sd y = .Null ∨ HomeZA st sd y := fun y hy hne c e => by + rcases hch y hy hne with h | h | h + · exact Or.inl (h.trans e) + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr h) + have hK : capA st s src ≠ .Null → + TcbInsKA H Z.th m n 6 (capA st s src) (capA st s src) (absCapA (capA st s src)) := fun hn => by + rcases hsrc with h | ⟨p, asid, hc, -⟩ + · exact absurd h hn + · rw [hc] + exact tcbInsKA_selfA (Or.inr (Or.inr (Or.inr (Or.inr ⟨_, _, _, rfl⟩)))) (fun h => by cases h) + have hdecOk := fun (s3 : S) + (hR : tcb.install_tcb_cap st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot + layout.tcb.SLOT_HIGH_VSPACE (capA st s src) src = ok (.Ok (), s3, ad)) => hdecBase.trans hR + have hdecFin := fun (s3 : S) + (hd : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s3, ad)) (σ3 : Fl4SpecA64.State Unit) => + J.decodeFinA hA hM hPl hfm hslot hcov (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmDelQ]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hd σ3 m + have hP1 : capA st s src ≠ .Null → capA st sd src = capA st s src → capA st sd slot = .Thread t → + TcbInsP1A st ar hPl.ipa { Z with G := Gd, Q := Q, R := R, hw := hw } H OS ia ie m sd σd (capA st s src) + (absCapA (capA st s src)) κsrc sl := by + intro hn hS hI s2 h2 + rw [hκsrc] at h2 + have hnotnull : capability.Cap.is_null (capA st s src) = ok false := by + generalize capA st s src = c at hn + cases c <;> first | rfl | exact absurd rfl hn + have hSV : tcb.still_valid st sd t slot (capA st s src) src = ok true := by + have hnl : obj.Slot.is_null src = ok false := by unfold obj.Slot.is_null; rw [decide_eq_false hsrc0] + rw [tcbStillValid_liveA sd t slot src _ (capA st sd src) hnl (capA_eq sd src), capA_eq sd slot, hS, + (hK hn).same, bind_ok, if_pos rfl, bind_ok, hI] + simp [objects.same_object_as, objects.same_region_as] + have hd : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, ad) := hdecOk s2 (by + simp only [tcb.install_tcb_cap, hdest, hdel0, bind_ok, uncurry_apply_pair, + core.result.Result.Insts.CoreOpsTry.branch, hnotnull, hSV, h2, Bool.false_eq_true, ite_false, ite_true]) + obtain ⟨-, -, hsys, hsym, -, -, -⟩ := hdecFin s2 hd σd + refine ⟨hsym, hsys, fun σ2 _ => ?_⟩ + obtain ⟨-, -, -, -, -, -, j7⟩ := hdecFin s2 hd σ2 + exact j7 + obtain ⟨s2, σ2, Gi, hR, hS, J2, hbk, dsk, -⟩ := Jd.installTcbCapA (t := t) (i := 6) (slot := slot) (src := src) + hthT (by decide) (by decide) hidles hdest hdel0 hspec hnull (J.delCanA _ (J.j5.2.1 _ (hAd.isSlot J.j.1.place))) + (κs := κs) (κsrc := κsrc) hAκ hκ (ps := ps) ⟨hss1, hss2⟩ hκsrc hsrc0 + (nc := capA st s src) (c0 := capA st s src) (anc := absCapA (capA st s src)) + (fun h => by rw [h]; rfl) hK (hkeep src hsrcOS hneS _ rfl) (hkeep slot hslot hneI _ hcap) hP1 + have wk := dsk.toDWkA + have B2 := BodyOKA.stepA Binv (delStep_ofKeepA hbk wk.off wk.ctSc) + exact ⟨.Ok (), s2, ad, hdecOk s2 hR, x', stUpdA σ σ.curThread x' .restart, σ2, hx', rfl, hset', Gi, Q, R, hw, Ac', Bf', + stack', J2, Or.inl ⟨rfl, hS, B2.1, B2.2.1⟩⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSpaceA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSpaceA.lean new file mode 100644 index 000000000..9523929d6 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSpaceA.lean @@ -0,0 +1,244 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP2): **TCB SetSpace at the record**. + +`decode_set_space` with three extra slots (fault handler `fs`, CSpace root `cs`, VSpace root `vs`), both roots derived and a +valid fault handler: `restart_caller`, then the three `install_tcb_cap`s (slot 3 fault handler, slot 0 CSpace root, slot 1 +VSpace root; `thread_control_caps` flags `SPACE | FAULT`), chained by `TcbMidA.chainStepA` from the chain start +`JSyscallA.tcbChainStartA`. + +* **`JSyscallA.setSpaceA`**: the arm. The target may be the caller. `TcbChainOutA`'s `Ok` outcome carries `BodyEndA`; its + `Preempted` outcome (at slot 3, 0 or 1) carries `BodyPreA`, `PreExitA`, `Clock` and the record at the preempted state. + +The three new caps: `fs` itself (`Null`, or an endpoint handler), the CNode root with its new guard (`tcbInsKA_cnodeA`), the +VSpace root (`tcbInsKA_selfA`, a native or Stage-2 root). Named premises: those of `JSyscallA.restartDelA`, [P] +`ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, [S] `h1`. The `Err` returns before the restart are not lifted. The +decode's derive facts (`hcc`, `hccap`, `hvc`, `hvdr`) are state facts implied by `hRoots`. New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbChainHelpA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +theorem tcbExtra1_memA {c : tcb.Ctx} {n : U64} {src : U64} + (he : tcb.extra_with_length c 1#usize n = ok (.Ok src)) : src ∈ c.extra.val ∧ src ≠ 0#u64 := by + unfold tcb.extra_with_length at he + obtain ⟨o, ho, he⟩ := bind_eq_ok he + cases o with + | none => + exfalso + simp only [error.truncated] at he + cases okinj he + | some x => + simp only at he + have ex : x = src := by + split at he + · exact core.result.Result.Ok.inj (okinj he) + · exfalso + simp only [error.truncated] at he + cases okinj he + subst ex + unfold tcb.extra at ho + split at ho + · cases okinj ho + obtain ⟨y, hy, ho⟩ := bind_eq_ok ho + obtain ⟨b, hb, ho⟩ := bind_eq_ok ho + have hlen : c.extra.val.length = 3 := by simp + have hm : y ∈ c.extra.val := by + obtain ⟨v, hv, e⟩ := spec_existsA (Aeneas.Std.Array.index_usize_spec c.extra 1#usize (by simp [hlen])) + have ev : v = y := okinj (hv.symm.trans hy) + rw [← ev, e] + exact List.getElem_mem _ + unfold obj.Slot.is_null at hb + have hb' : b = decide (y = 0#u64) := (okinj hb).symm + by_cases h0 : y = 0#u64 + · rw [hb', decide_eq_true h0, if_pos rfl] at ho + cases okinj ho + · rw [hb', decide_eq_false h0] at ho + simp only [Bool.false_eq_true, ↓reduceIte] at ho + have e := Option.some.inj (okinj ho) + exact e ▸ ⟨hm, h0⟩ + +theorem capEnc_ofA (s : S) (x : U64) {c : capability.Cap} (h : capA st s x = c) : CapRt.EncWf c := by + have h' : CapRt.EncWf (capAtA (L.mem s) x) := CapRt.decodeF_encWf _ _ + rwa [capAtA_eq (st := st), h] at h' + +theorem tcbSlotRootA (t idx : U64) (i : Nat) (hi : idx.val = i) (hi7 : i < 7) : + obj.Tcb.slot t idx = ok (cslotAddrA (specPtr t, tcbCnodeIndex i)) := by + have hslotIdx : slotIdx t idx = cslotAddrA (specPtr t, tcbCnodeIndex i) := by + rw [slotIdx_addrA, hi] + unfold cslotAddrA + show _ = slotAddrA (specPtr t) (Fl4SpecA64.ofBl (tcbCnodeIndex i)) + rw [ofBl_tcbIdx i (by omega)] + rw [← hslotIdx] + exact tcb_slot_val _ _ + +section arm +variable {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {Clock : A → Fl4SpecA64.MachineState → Prop} + +set_option maxHeartbeats 32000000 in +/-- **TCB SetSpace at a syscall entry** (module docstring). -/ +theorem JSyscallA.setSpaceA [PlainStore st] + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) (hCnt : CounterStepA σ) + (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t fs cs vs cdata vdata : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetSpace) + (he0 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 2#u64 = ok (.Ok fs)) + (he1 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 1#usize 2#u64 = ok (.Ok cs)) + (he2 : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 2#usize 2#u64 = ok (.Ok vs)) + (hcd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok cdata) + (hvd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok vdata) + {ccap vcap : capability.Cap} + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hfhv : faults.valid_fault_handler (capA st s fs) = ok true) + {p r gs g gs' g' : U64} (hcc : capA st s cs = .CNode p r gs g) (hccap : ccap = .CNode p r gs' g') + (hwfc : CapWfA ccap) (hencc : CapRt.EncWf ccap) + (hvc : capA st s vs = vcap) (hvk : TcbK vcap) + (hvdr : ∀ s' : S, objects.derive_cap st s' vs vcap = ok (.Ok vcap)) + {κs κfs κcs κvs : CslotPtr} + (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) + (hAf : AbsSlotA Z.th κfs) (hκf : cslotAddrA κfs = fs) + (hAc : AbsSlotA Z.th κcs) (hκc : cslotAddrA κcs = cs) + (hAv : AbsSlotA Z.th κvs) (hκv : cslotAddrA κvs = vs) : + ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (r, s3, a3) ∧ + ∃ (xc : Fl4SpecA64.Tcb) (σ1 : Fl4SpecA64.State Unit), σ.kheap σ.curThread = some (.tcb xc) ∧ + σ1 = stUpdA σ σ.curThread xc .restart ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + TcbChainOutA st AR Clock Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa σ σ1 + (.threadControlCaps (specPtr t) κs (some (absCapA (capA st s fs), κfs)) none + (some (absCapA ccap, κcs)) (some (absCapA vcap, κvs)) none) r s3 a3 := by + subst hccap + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have hthT : Z.th t = some .tcb := (J.j.1.thT t).2 ht + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t := by + obtain ⟨cI, hgI, hcI⟩ := getCap_eqA J.j.1.st hAκ + rw [capAtA_eq (st := st), hκ, hcap] at hcI + have eI : cI = .threadCap (specPtr t) := (CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)).symm + have hcapS : specCapAtA σ κs = some (.threadCap (specPtr t)) := by + rw [← eI]; exact (getCap_outA (c := cI) (σ' := σ) (by rw [hgI]; exact rfl)).2 + exact fun c hc e => (J.sidle.f6 κs).1 c hc (e ▸ hcapS) + obtain ⟨hfM, hf0⟩ := tcbExtra0_memA he0 + obtain ⟨hcM, hc0⟩ := tcbExtra1_memA he1 + obtain ⟨hvM, hv0⟩ := tcbExtra2_memA he2 + have hfOS : fs ∈ OS := hext _ hfM hf0 + have hcOS : cs ∈ OS := hext _ hcM hc0 + have hvOS : vs ∈ OS := hext _ hvM hv0 + obtain ⟨psf, hCf⟩ := J.toJStage3A.tcbSrcCnA (hSC _ hfM hf0) hAf hκf + obtain ⟨psc, hCc⟩ := J.toJStage3A.tcbSrcCnA (hSC _ hcM hc0) hAc hκc + obtain ⟨psv, hCv⟩ := J.toJStage3A.tcbSrcCnA (hSC _ hvM hv0) hAv hκv + obtain ⟨psI, hCI⟩ := J.toJStage3A.tcbSrcCnA hcov hAκ hκ + have hP := J.j.1.place + have nef : ∀ i : Nat, i < 7 → fs ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) := fun i hi => by + rw [← hκf]; exact tcbSlotNeA hP hi hAf hCf hthT + have nec : ∀ i : Nat, i < 7 → cs ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) := fun i hi => by + rw [← hκc]; exact tcbSlotNeA hP hi hAc hCc hthT + have nev : ∀ i : Nat, i < 7 → vs ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) := fun i hi => by + rw [← hκv]; exact tcbSlotNeA hP hi hAv hCv hthT + have neI : ∀ i : Nat, i < 7 → slot ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) := fun i hi => by + rw [← hκ]; exact tcbSlotNeA hP hi hAκ hCI hthT + have hag0 : FrAgA st OS (∅ : Set U64) s σ := fun _ h => absurd h (Set.notMem_empty _) + obtain ⟨x, hkx, hr, hcapK, hset, Md0, Vc, Ub, Pt, Ac1, K0, Ty, I, R0⟩ := + J.tcbChainStartA hA hPl hCnt hCl hag0 hslot hcov hext hcap hstall + have hCapf : obj.Slot.cap st fs s = ok (capA st s fs) := capA_eq s fs + have hdecBase : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + tcb.thread_control_caps st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot (capA st s fs, fs) + (capability.Cap.Null, 0#u64) (.CNode p r gs' g', cs) (vcap, vs) 0#u64 (capability.Cap.Null, 0#u64) + (tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl] + exact tcbSetSpace_selectedA hstall he0 he1 he2 hcd hvd hRoots hCapf hfhv hr + have hfhK := nullOrEp_validFhA J.toJStage3A.capTy hfOS hfhv + have hdrvF : capA st s fs ≠ .Null → ∀ s' : S, objects.derive_cap st s' fs (capA st s fs) = ok (.Ok (capA st s fs)) ∨ + ∃ p r gs g gs' g', capA st s fs = .CNode p r gs g ∧ capA st s fs = .CNode p r gs' g' := fun hn s' => by + rcases hfhK with h | ⟨ep, b0, b1, b2, b3, b4, h, -⟩ + · exact absurd h hn + · exact Or.inl (by rw [h]; simp [objects.derive_cap]) + have hKf : capA st s fs ≠ .Null → + TcbInsKA H Z.th m n 3 (capA st s fs) (capA st s fs) (absCapA (capA st s fs)) := fun hn => by + have hk : TcbK (capA st s fs) := by + rcases hfhK with h | ⟨ep, b0, b1, b2, b3, b4, h, -⟩ + · exact absurd h hn + · rw [h]; exact Or.inl ⟨_, _, _, _, _, _, rfl⟩ + exact tcbInsKA_selfA hk (fun _ => hfhK) + have hncf : capA st s fs ≠ .Null → TcbK (capA st s fs) ∧ CapRt.EncWf (capA st s fs) := fun hn => + ⟨(hKf hn).kind, capEnc_ofA s fs rfl⟩ + -- the three steps + obtain ⟨r3, s2, a1, σ2, h3, R3, o3⟩ := Md0.chainStepA (t := t) (idx := layout.tcb.SLOT_FAULT_HANDLER) (slot := slot) + (src := fs) (i := 3) hA hPl P hCs I R0 hthT (by simp [layout.tcb.SLOT_FAULT_HANDLER]) (by decide) (by decide) + (by decide) hidles (tcbSlotRootA t _ 3 (by simp [layout.tcb.SLOT_FAULT_HANDLER]) (by decide)) hAκ hκ (ps := psf) + hCf hκf hf0 hfOS hslot (nef 3 (by decide)) (neI 3 (by decide)) + (fun h => by rw [h]; rfl) hKf hdrvF hncf (Or.inl (hcapK fs hfOS)) (Or.inl ((hcapK slot hslot).trans hcap)) + rcases o3 with ⟨hr3, hspec3, hch3, hdd3, Gi3, Q3, Rl3, hw3, Ac3, Bf3, stack3, Md3⟩ | + ⟨hr3, hspec3, hpp3, hcur3, hpre3, hclk3, Gi3, Q3, Rl3, hw3, Ac3, Bf3, stack3, Jd3⟩ + swap + · subst hr3 + refine ⟨.Err .Preempted, s2, a1, hdecBase.trans (tcbCaps_space_pre3A h3), x, stUpdA σ σ.curThread x .restart, hkx, + rfl, hset, σ2, Gi3, Q3, Rl3, hw3, Ac3, Bf3, stack3, Jd3, Or.inr ⟨rfl, ?_, hpp3, hcur3, hpre3, hclk3⟩⟩ + exact setSpace_specPre3A hspec3 + subst hr3 + -- slot 0: the CSpace root + obtain ⟨r0, s4, a2, σ3, h0, R0', o0⟩ := Md3.chainStepA (t := t) (idx := layout.tcb.SLOT_CTABLE) (slot := slot) + (src := cs) (i := 0) hA hPl P hCs I R3 hthT (by simp [layout.tcb.SLOT_CTABLE]) (by decide) (by decide) + (by decide) hidles (tcbSlotRootA t _ 0 (by simp [layout.tcb.SLOT_CTABLE]) (by decide)) hAκ hκ (ps := psc) + hCc hκc hc0 hcOS hslot (nec 0 (by decide)) (neI 0 (by decide)) (c0 := .CNode p r gs g) + (fun h => by cases h) (fun _ => tcbInsKA_cnodeA (by decide) hwfc hencc) + (fun _ _ => Or.inr ⟨p, r, gs, g, gs', g', rfl, rfl⟩) + (fun _ => ⟨Or.inr (Or.inl ⟨_, _, _, _, rfl⟩), hencc⟩) + (chgZ_keepA (hch3 cs hcOS (nec 3 (by decide))) (Or.inl ((hcapK cs hcOS).trans hcc))) + (chgZ_keepA (hch3 slot hslot (neI 3 (by decide))) (Or.inl ((hcapK slot hslot).trans hcap))) + rcases o0 with ⟨hr0, hspec0, hch0, hdd0, Gi0, Q0, Rl0, hw0, Ac0, Bf0, stack0, Md0'⟩ | + ⟨hr0, hspec0, hpp0, hcur0, hpre0, hclk0, Gi0, Q0, Rl0, hw0, Ac0, Bf0, stack0, Jd0⟩ + swap + · subst hr0 + refine ⟨.Err .Preempted, s4, a2, hdecBase.trans (tcbCaps_space_pre0A h3 h0), x, stUpdA σ σ.curThread x .restart, + hkx, rfl, hset, σ3, Gi0, Q0, Rl0, hw0, Ac0, Bf0, stack0, Jd0, Or.inr ⟨rfl, ?_, hpp0, hcur0.trans Md3.body.2.1, hpre0, hclk0⟩⟩ + exact setSpace_specPre0A hspec3 hspec0 + subst hr0 + -- slot 1: the VSpace root + obtain ⟨r1, s6, a3, σ4, h1', R1', o1⟩ := Md0'.chainStepA (t := t) (idx := layout.tcb.SLOT_VTABLE) (slot := slot) + (src := vs) (i := 1) hA hPl P hCs I R0' hthT (by simp [layout.tcb.SLOT_VTABLE]) (by decide) (by decide) + (by decide) hidles (tcbSlotRootA t _ 1 (by simp [layout.tcb.SLOT_VTABLE]) (by decide)) hAκ hκ (ps := psv) + hCv hκv hv0 hvOS hslot (nev 1 (by decide)) (neI 1 (by decide)) (c0 := vcap) + (fun h => by rw [h]; rfl) (fun _ => tcbInsKA_selfA hvk (fun h => absurd h (by decide))) + (fun _ s' => Or.inl (hvdr s')) (fun _ => ⟨hvk, capEnc_ofA s vs hvc⟩) + (chgZ_keepA ((hch3 vs hvOS (nev 3 (by decide))).trans (hch0 vs hvOS (nev 0 (by decide)))) + (Or.inl ((hcapK vs hvOS).trans hvc))) + (chgZ_keepA ((hch3 slot hslot (neI 3 (by decide))).trans (hch0 slot hslot (neI 0 (by decide)))) + (Or.inl ((hcapK slot hslot).trans hcap))) + rcases o1 with ⟨hr1, hspec1, hch1, hdd1, Gi1, Q1, Rl1, hw1, Acx, Bf1, stack1, Md1⟩ | + ⟨hr1, hspec1, hpp1, hcur1, hpre1, hclk1, Gi1, Q1, Rl1, hw1, Acx, Bf1, stack1, Jd1⟩ + swap + · subst hr1 + refine ⟨.Err .Preempted, s6, a3, hdecBase.trans (tcbCaps_space_pre1A h3 h0 h1'), x, + stUpdA σ σ.curThread x .restart, hkx, rfl, hset, σ4, Gi1, Q1, Rl1, hw1, Acx, Bf1, stack1, Jd1, + Or.inr ⟨rfl, ?_, hpp1, hcur1.trans Md0'.body.2.1, hpre1, hclk1⟩⟩ + exact setSpace_specPre1A hspec3 hspec0 hspec1 + subst hr1 + refine ⟨.Ok (), s6, a3, hdecBase.trans (tcbCaps_space_okA h3 h0 h1'), x, stUpdA σ σ.curThread x .restart, hkx, rfl, + hset, σ4, Gi1, Q1, Rl1, hw1, Acx, Bf1, stack1, Md1.J, Or.inl ⟨rfl, setSpace_specA hspec3 hspec0 hspec1, ?_⟩⟩ + exact ⟨Md1.body.1, Md1.body.2.1⟩ + +end arm + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspA.lean index 27f5cc85a..74b8810f8 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspA.lean @@ -99,7 +99,7 @@ theorem JSyscallA.setSchedParamsNullA [PlainStore st] {κs : CslotPtr} (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) (κsrc : CslotPtr) : ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (r, s3, a3) ∧ - TcbDelOutA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ + TcbDelOutA st AR Clock Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ (fun κs' => .threadControlSched (specPtr t) κs' (some (.nullCap, κsrc)) (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) none) r s3 a3 := by @@ -162,7 +162,7 @@ theorem JSyscallA.setSchedParamsNullA [PlainStore st] swap · -- preempted deletion subst hr1 - obtain ⟨⟨⟨-, X, sv⟩, -⟩, hpre⟩ := hW + obtain ⟨⟨⟨-, X, sv⟩, tm⟩, hpre⟩ := hW obtain ⟨Q, R, hw', Ac', Bf', stack', Jd⟩ := X.toStage3A sysd.1 sysd.2 sv have hdecP : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (.Err .Preempted, sd, ad) := by @@ -172,7 +172,7 @@ theorem JSyscallA.setSchedParamsNullA [PlainStore st] core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] refine ⟨.Err .Preempted, sd, ad, hdecP, x', stUpdA σ σ.curThread x' .restart, σd, hx', rfl, hset', Gd, Q, R, hw', - Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun κs' => ?_, hpre.1, hpre.2.1⟩⟩ + Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun κs' => ?_, hpre.1, hpre.2.1, hpre.preExitA, tm.2.1⟩⟩ rw [e1] at hspec exact sspNull_invokeErrA κs' κsrc _ _ hspec subst hr1 diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspEpA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspEpA.lean index 338bbe399..d840a6f2c 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspEpA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspEpA.lean @@ -1,27 +1,32 @@ /- -P3 (aarch64, A64-P3 Lift 3b labels): **TCB SetSchedParams with an endpoint fault handler and an unchanged SC, at the -record**. +P3 (aarch64, A64-P3 Stage 4, tcbsched): **TCB SetSchedParams with an endpoint or a null fault handler, at the record**: the +target may be the caller, and the SC may change (detach or bind). A null handler is the deletion alone (`key`'s `Null` case). -`decode_set_sched_params` with the SC unchanged (flags `FAULT | MCP | PRIO`) and a valid endpoint fault handler in -extra slot 2, on a thread other than the caller: `restart_caller`, the deletion of TCB slot 3 (`restartDelA`), the -`still_valid` check and `cdt::insert` of the handler into slot 3, `set_mcp`, `set_priority`. +`decode_set_sched_params` with a valid endpoint fault handler in extra slot 2: `restart_caller`, the deletion of TCB slot 3 +(`restartDelA`), the `still_valid` check and `cdt::insert` of the handler into slot 3, `set_mcp`, `set_priority`, then the SC +step selected by `sched_params_sc` (flags `FAULT | MCP | PRIO`, `| SC` when the SC changes). -* **`JStage3A.sspTailA`**: `set_mcp` then `set_priority` of a non-current, non-idle thread from any record state (the - tail of `JSyscallA.setSchedParamsNullA`, factored): `setMcp_stepA`, its post state's P1 facts by - `JStage3A.p1StepA`, `JStage3A.prioAnyA`. -* **`sspEp_invokeA`** / **`sspEp_invokeErrA`**: the spec's `fl4InvokeTcb (.threadControlSched ..)` from the outcome of - `fl4InstallTcbCap` of slot 3, `set_mcpriority` and `set_priority`. -* **`JSyscallA.setSchedParamsEpA`**: the arm. After the deletion, the insert (when `still_valid` holds) is - `JStage3A.capInsertTcbSlotA` with the P1 facts at the post-insert state (an intermediate state) from - `JStage3A.insertP1A`; otherwise the install is a no-op. The tail is `sspTailA`; the final P1 facts are +* **`JStage3A.sspTailA`**: `set_mcp` then `set_priority` of a non-current, non-idle thread from any record state, ending in + the record at the post-priority state (P1 facts over the `SusW` footprint, `Stage3TcbSchedMidA`). +* **`sspEp_invokeA`** / **`sspEp_invokeErrA`** / **`sspScStep_unbindA`**: the spec's `fl4InvokeTcb (.threadControlSched ..)` + from the outcomes of `fl4InstallTcbCap` of slot 3, `set_mcpriority`, `set_priority` and the SC step. +* **`JSyscallA.setSchedParamsEpA`**: the arm. The caller as target keeps its state across the deletion (`LkA`) and takes + `sspTailCurA` (its SC cannot change: it has one); another target takes `sspTailA`, then nothing (`scUpdC = none`), + `JStage3A.sspUnbindA` (new SC null) or `JStage3A.sspBindA` (new SC `v`; the target has none, `v` no thread; the frame + `LkA (scNameA m v)` carries both facts and the release check to the post-priority state). The final P1 facts are `JSyscallA.decodeFinA`. -Not covered: `sc ≠ target.sc`; the target being the caller; the `Err` returns before the deletion. +Not covered: the `Err` returns before the deletion. -Named premises: those of `JSyscallA.setSchedParamsNullA`. New module. +Named premises: those of `JSyscallA.setSchedParamsNullA`; [P] `hmin : fl4MinBudget = MIN_BUDGET` (the bind step's spec +bridge `fl4TcbBindSc_eq_l4v`; `OpaqueWA.hag` is its model). New module. -/ import Fl4ProofsA64.P3.Stage3LiftTcbSspA import Fl4ProofsA64.P3.Stage3InsP1A +import Fl4ProofsA64.P3.Stage3TcbSchedCurA +import Fl4ProofsA64.P3.Stage3TcbSchedMidA +import Fl4ProofsA64.P3.Stage3TcbSchedScA +import Fl4ProofsA64.P3.Stage3KEntryRestartA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -32,8 +37,8 @@ noncomputable section local notation "wa" => core.num.U64.wrapping_add -theorem tcbExtra2_memA {c : tcb.Ctx} {n : U64} {src : U64} - (he : tcb.extra_with_length c 2#usize n = ok (.Ok src)) : src ∈ c.extra.val ∧ src ≠ 0#u64 := by +theorem tcbExtraI_memA {c : tcb.Ctx} {n : U64} {src : U64} (i : Usize) (hi : i.val < 3) + (he : tcb.extra_with_length c i n = ok (.Ok src)) : src ∈ c.extra.val ∧ src ≠ 0#u64 := by unfold tcb.extra_with_length at he obtain ⟨o, ho, he⟩ := bind_eq_ok he cases o with @@ -57,7 +62,7 @@ theorem tcbExtra2_memA {c : tcb.Ctx} {n : U64} {src : U64} obtain ⟨b, hb, ho⟩ := bind_eq_ok ho have hlen : c.extra.val.length = 3 := by simp have hm : y ∈ c.extra.val := by - obtain ⟨v, hv, e⟩ := spec_existsA (Aeneas.Std.Array.index_usize_spec c.extra 2#usize (by simp [hlen])) + obtain ⟨v, hv, e⟩ := spec_existsA (Aeneas.Std.Array.index_usize_spec c.extra i (by first | (simp [hlen]; omega) | simp [hlen])) have ev : v = y := okinj (hv.symm.trans hy) rw [← ev, e] exact List.getElem_mem _ @@ -71,6 +76,10 @@ theorem tcbExtra2_memA {c : tcb.Ctx} {n : U64} {src : U64} have e := Option.some.inj (okinj ho) exact e ▸ ⟨hm, h0⟩ +theorem tcbExtra2_memA {c : tcb.Ctx} {n : U64} {src : U64} + (he : tcb.extra_with_length c 2#usize n = ok (.Ok src)) : src ∈ c.extra.val ∧ src ≠ 0#u64 := + tcbExtraI_memA 2#usize (by decide) he + section variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} @@ -96,10 +105,8 @@ theorem JStage3A.sspTailA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4S (mcpStateA σ (specPtr t) yd (BitVec.ofNat 8 mcp.val)) = ({((), σ3)}, False) ∧ Sched.BodyKeepA σ (mcpStateA σ (specPtr t) yd (BitVec.ofNat 8 mcp.val)) ∧ DelStepA (mcpStateA σ (specPtr t) yd (BitVec.ofNat 8 mcp.val)) σ3 ∧ - (SysL st H Z.Cs OS ia ie s3 → SymL st H Z.Cs s3 → Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s3 → - J7A st (J7R2A st ar hPl.ipa) Z H OS s3 σ3 m → - ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) - (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 m) := by + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 m := by have htT : t ∈ H.tcbs := by rw [J.tcbs]; exact ht obtain ⟨yd, hyd, -⟩ := J.mcp t ht set sm := L.wr s (mcpA t) mcp with hsm @@ -133,7 +140,24 @@ theorem JStage3A.sspTailA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4S have htcM : specPtr t ≠ σm.curThread := htc obtain ⟨s3, σ3, hsp3, hSet3, DS3, blk3, J3⟩ := Jm.prioAnyA (st := st) (ar := ar) hCs h1 hmb hmax htu hnsM sactM ht hwp htcM hidles - exact ⟨sm, s3, σ3, yd, hMcp, hsp3, hyd, hSet3, BodyKeepA.ofTcbUpd (y' := { yd with tcbMcpriority := BitVec.ofNat 8 mcp.val }) hyd rfl, DS3, J3⟩ + -- the P1 facts after `set_priority`, so the record there + have hnaM : ∀ y ∈ H.tcbs, L.actionW sm ≠ y := fun y hy e => by + have hyT : y ∈ Z.T := by rw [← J.tcbs]; exact hy + have h01 := tcb_ne01Sc (Jm.sr.core.tcbs y hyT) + refine hnsM (specPtr y) ?_ + rw [Jm.sr.sch.act, e] + unfold actOfA + rw [if_neg h01.1, if_neg h01.2] + have hcurM : t ≠ L.mem sm (L.nodeAt sm (L.cpu sm) layout.node.CUR_THREAD) := fun e => htcM (by + rw [show L.mem sm (L.nodeAt sm (L.cpu sm) layout.node.CUR_THREAD) = L.curW sm from rfl] at e + rw [e, ← Jm.sr.sch.curThread]) + have hdm := setPriority_dm0A (p := 0#u64) t prio (BXI.blk Jm.sys.ent.bxi) htT h0 Jm.sys.sysl.vr Jm.symL hwp hcurM hnaM + rw [hsp3, WP.spec_ok] at hdm + obtain ⟨blk3m, d3⟩ := hdm + obtain ⟨sysl3, symL3, user3, -, j73⟩ := Jm.p1StepSusA hA hPl + ((SspW.ofD (Vc := Z.V) d3.toDMD.w).mono fun _ h => Or.inl h) d3.toDMD (fun k hk => by rw [h0] at hk; cases hk) blk3m + obtain ⟨Q3, R3, J3m⟩ := J3 sysl3 symL3 user3 (j73 σ3 m) + exact ⟨sm, s3, σ3, yd, hMcp, hsp3, hyd, hSet3, BodyKeepA.ofTcbUpd (y' := { yd with tcbMcpriority := BitVec.ofNat 8 mcp.val }) hyd rfl, DS3, Q3, R3, J3m⟩ theorem sactKeepA {σd σ2 : Fl4SpecA64.State Unit} (S0 : SActA σd) (hns : ∀ u, σd.schedulerAction ≠ .switchThread u) @@ -147,28 +171,51 @@ theorem sactKeepA {σd σ2 : Fl4SpecA64.State Unit} (S0 : SActA σd) (hns : ∀ cases hx0 exact ⟨x', hx', by rw [he]; exact hs⟩ -/-- **The spec's `invoke_tcb` of SetSchedParams** (endpoint handler installed), from the install's outcome. -/ -theorem sspEp_invokeA {σ1 σi σ3 : Fl4SpecA64.State Unit} {t auth : U64} (κs κsrc : CslotPtr) (nc : Cap) - (mp pr : Priority) {y : Tcb} +/-- The SC step of `invoke_tcb` of SetSchedParams (a detach or a bind, or nothing). -/ +abbrev sspScStepA (t : ObjRef) : Option (Option ObjRef) → SMonad Unit Unit := fun sc => + Fl4Spec.NonDet.maybeM (fun scopt => match scopt with + | none => do + let scPtrOpt ← getTcbObjRef Fl4SpecA64.Tcb.tcbSchedContext t + Fl4Spec.NonDet.maybeM schedContextUnbindTcb scPtrOpt + | some scPtr => fl4TcbBindSc scPtr t) sc + +/-- **The spec's `invoke_tcb` of SetSchedParams** (endpoint handler installed), from the install's outcome and the SC +step's (`sc = none`: no SC step). -/ +theorem sspEp_invokeA {σ1 σi σ3 σ4 : Fl4SpecA64.State Unit} {t auth : U64} (κs κsrc : CslotPtr) (nc : Cap) + (mp pr : Priority) {y : Tcb} {sc : Option (Option ObjRef)} (hinst : (.ok (), σi) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs 3 (some (nc, κsrc))).run σ1).1) (hy : σi.kheap (specPtr t) = some (.tcb y)) - (hSet : setPriority (Z := Unit) (specPtr t) pr (mcpStateA σi (specPtr t) y mp) = ({((), σ3)}, False)) : - (.ok [], σ3) ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs (some (nc, κsrc)) - (some (mp, specPtr auth)) (some (pr, specPtr auth)) none)).run σ1).1 := by + (hSet : setPriority (Z := Unit) (specPtr t) pr (mcpStateA σi (specPtr t) y mp) = ({((), σ3)}, False)) + (hsc : sspScStepA (specPtr t) sc σ3 = ({((), σ4)}, False)) : + (.ok [], σ4) ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs (some (nc, κsrc)) + (some (mp, specPtr auth)) (some (pr, specPtr auth)) sc)).run σ1).1 := by have hset : setMcpriority (Z := Unit) (specPtr t) mp σi = ({((), mcpStateA σi (specPtr t) y mp)}, False) := threadSet_eqSc _ hy simp only [fl4InvokeTcb] refine mem_bindE_okD (a := ()) (s' := σi) hinst ?_ simp only [Fl4Spec.NonDet.maybeM] - rw [run_bind_okD (run_liftE_stD hset), run_bind_okD (run_liftE_stD hSet), - run_bind_okD (run_liftE_stD (m := Fl4Spec.NonDet.pure ()) rfl)] - simp [run_returnOkD] + rw [run_bind_okD (run_liftE_stD hset), run_bind_okD (run_liftE_stD hSet)] + simp only [sspScStepA, Fl4Spec.NonDet.maybeM] at hsc + rcases sc with _ | _ | p <;> (try dsimp only at hsc ⊢) <;> rw [run_bind_okD (run_liftE_stD hsc)] <;> + simp [run_returnOkD] + +/-- The SC step of a detach: the target's SC link is `p` and `unbind` of it runs. -/ +theorem sspScStep_unbindA {σ3 σ4 : Fl4SpecA64.State Unit} {t : U64} {p : ObjRef} {y : Tcb} + (hy : σ3.kheap (specPtr t) = some (.tcb y)) (hp : y.tcbSchedContext = some p) + (hU : schedContextUnbindTcb (Z := Unit) p σ3 = ({((), σ4)}, False)) : + sspScStepA (specPtr t) (some none) σ3 = ({((), σ4)}, False) := by + show (getTcbObjRef Fl4SpecA64.Tcb.tcbSchedContext (specPtr t) >>= fun o => + Fl4Spec.NonDet.maybeM schedContextUnbindTcb o) σ3 = _ + have h : getTcbObjRef (Z := Unit) Fl4SpecA64.Tcb.tcbSchedContext (specPtr t) σ3 = ({(y.tcbSchedContext, σ3)}, False) := + threadGet_eqSc _ hy + rw [nd_bind_oneSc h, hp] + exact hU theorem sspEp_invokeErrA {σ1 σd : Fl4SpecA64.State Unit} {t auth : U64} (κs κsrc : CslotPtr) (nc : Cap) - (mp pr : Priority) + (mp pr : Priority) {sc : Option (Option ObjRef)} (hdel : (.error (), σd) ∈ ((fl4CapDelete (Z := Unit) (specPtr t, tcbCnodeIndex 3)).run σ1).1) : (.error (), σd) ∈ ((fl4InvokeTcb (.threadControlSched (specPtr t) κs (some (nc, κsrc)) - (some (mp, specPtr auth)) (some (pr, specPtr auth)) none)).run σ1).1 := by + (some (mp, specPtr auth)) (some (pr, specPtr auth)) sc)).run σ1).1 := by simp only [fl4InvokeTcb, fl4InstallTcbCap] exact mem_bindE_errD (mem_bindE_errD hdel) @@ -196,23 +243,17 @@ theorem JSyscallA.setSchedParamsEpA [PlainStore st] (hprio : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok prio) (harg : authSlot ∈ OS) (hac : capA st s authSlot = .Thread auth) (hle1 : ¬ L.mem s (mcpA auth) < mcp) (hle2 : ¬ L.mem s (mcpA auth) < prio) - (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hold : obj.Tcb.sc st t s = ok v) - (hnn : capA st s fhSlot ≠ .Null) (hValid : faults.valid_fault_handler (capA st s fhSlot) = ok true) - (hne : t ≠ L.curW s) + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) (hmin : fl4MinBudget = MIN_BUDGET) + (hValid : faults.valid_fault_handler (capA st s fhSlot) = ok true) {κs κsrc : CslotPtr} (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = fhSlot) : ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (r, s3, a3) ∧ - TcbDelOutA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ + TcbDelOutA st AR Clock Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ (fun _ => .threadControlSched (specPtr t) κs (some (absCapA (capA st s fhSlot), κsrc)) - (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) none) + (some (BitVec.ofNat 8 mcp.val, specPtr auth)) (some (BitVec.ofNat 8 prio.val, specPtr auth)) + (scUpdC (L.mem s (scA t)) v)) r s3 a3 := by - obtain ⟨p, b, sn, rv, g, gr, hnc⟩ : ∃ p b sn rv g gr, capA st s fhSlot = .Endpoint p b sn rv g gr := by - generalize capA st s fhSlot = c at hnn hValid - cases c with - | Null => exact absurd rfl hnn - | Endpoint p b sn rv g gr => exact ⟨p, b, sn, rv, g, gr, rfl⟩ - | _ => exact absurd (okinj hValid) Bool.false_ne_true have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap have htT : t ∈ H.tcbs := by rw [J.tcbs]; exact ht have hthT : Z.th t = some .tcb := (J.j.1.thT t).2 ht @@ -279,18 +320,20 @@ theorem JSyscallA.setSchedParamsEpA [PlainStore st] (by simp [layout.tcb.SLOT_FAULT_HANDLER]) hstall hr (r := r) (sd := sd) (ad := ad) (by rw [hslotIdx]; exact hdel0) have hCap : obj.Slot.cap st fhSlot s = ok (capA st s fhSlot) := capA_eq s fhSlot + have hold0 : obj.Tcb.sc st t s = ok (L.mem s (scA t)) := eq_of_spec_fd (obj.Tcb.sc.spec (L := L) s t) + have hscOS : scSlot ∈ OS := hext _ (tcbExtraI_memA 1#usize (by decide) he1).1 (tcbExtraI_memA 1#usize (by decide) he1).2 have hdecBase : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = tcb.thread_control_sched st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot - (capA st s fhSlot, fhSlot) mcp prio v 14#u64 := by + (capA st s fhSlot, fhSlot) mcp prio v (if L.mem s (scA t) = v then 14#u64 else 15#u64) := by rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, - tcbSetSchedParams_controlA hstall he0 he1 he2 hmcp hprio hAuth (hck _ hle1) (hck _ hle2) hsc hold hCap hValid - hr, if_pos rfl] - have hfl : ((14#u64 &&& tcb.SCHED_UPDATE_FAULT) != 0#u64) = true := by rw [tcb.SCHED_UPDATE_FAULT]; decide + tcbSetSchedParams_controlA hstall he0 he1 he2 hmcp hprio hAuth (hck _ hle1) (hck _ hle2) hsc hold0 hCap hValid hr] + have hfl : (((if L.mem s (scA t) = v then 14#u64 else 15#u64) &&& tcb.SCHED_UPDATE_FAULT) != 0#u64) = true := by + split <;> (rw [tcb.SCHED_UPDATE_FAULT]; decide) rcases hres with ⟨hr1, hnull, hspec, hch⟩ | ⟨hr1, hspec⟩ swap · -- preempted deletion subst hr1 - obtain ⟨⟨⟨-, X, sv⟩, -⟩, hpre⟩ := hW + obtain ⟨⟨⟨-, X, sv⟩, tm⟩, hpre⟩ := hW obtain ⟨Q, R, hw', Ac', Bf', stack', Jd⟩ := X.toStage3A sysd.1 sysd.2 sv have hdecP : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (.Err .Preempted, sd, ad) := by @@ -300,7 +343,7 @@ theorem JSyscallA.setSchedParamsEpA [PlainStore st] core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] refine ⟨.Err .Preempted, sd, ad, hdecP, x', stUpdA σ σ.curThread x' .restart, σd, hx', rfl, hset', Gd, Q, R, hw', - Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun κs' => ?_, hpre.1, hpre.2.1⟩⟩ + Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun κs' => ?_, hpre.1, hpre.2.1, hpre.preExitA, tm.2.1⟩⟩ rw [e1] at hspec exact sspEp_invokeErrA κs _ _ _ _ hspec subst hr1 @@ -309,50 +352,67 @@ theorem JSyscallA.setSchedParamsEpA [PlainStore st] obtain ⟨⟨-, X, sv⟩, -⟩ := hWT obtain ⟨Q, R, hw', Ac', Bf', stack', Jd⟩ := X.toStage3A sysd.1 sysd.2 sv rw [e1] at hspec - have hkeepS : capA st sd fhSlot = .Endpoint p b sn rv g gr ∨ capA st sd fhSlot = .Null ∨ HomeZA st sd fhSlot := by - rcases hch fhSlot hsrcOS hneS with h | h | h - · exact Or.inl (h.trans hnc) - · exact Or.inr (Or.inl h) - · exact Or.inr (Or.inr h) - have hkeepI : capA st sd slot = .Thread t ∨ capA st sd slot = .Null ∨ HomeZA st sd slot := by - rcases hch slot hslot hneI with h | h | h - · exact Or.inl (h.trans hcap) - · exact Or.inr (Or.inl h) - · exact Or.inr (Or.inr h) - have hSV := tcbStillValid_keptA (st := st) sd t slot fhSlot hsrc0 p b sn rv g gr hkeepS hkeepI - have hnotnull : capability.Cap.is_null (.Endpoint p b sn rv g gr) = ok false := rfl - have hnSpec : absCapA (.Endpoint p b sn rv g gr) ≠ .nullCap := by simp [absCapA] - obtain ⟨cS, hgS, hcS⟩ := getCap_eqA Jd.j.1.st (show AbsSlotA Z.th κsrc from hAsrc) - obtain ⟨cI, hgI, hcI⟩ := getCap_eqA Jd.j.1.st (show AbsSlotA Z.th κs from hAκ) - rw [capAtA_eq (st := st), hκsrc] at hcS - rw [capAtA_eq (st := st), hκ] at hcI - have mS : (cS, σd) ∈ (getCap (Z := Unit) κsrc σd).1 := by rw [hgS]; exact Set.mem_singleton _ - have mI : (cI, σd) ∈ (getCap (Z := Unit) κs σd).1 := by rw [hgI]; exact Set.mem_singleton _ - have eS : capA st sd fhSlot = .Endpoint p b sn rv g gr → cS = absCapA (.Endpoint p b sn rv g gr) := fun h => by - rw [h] at hcS - exact (CapEqA.eq_abs hcS (fun _ _ _ h => by cases h)).symm - have eI : capA st sd slot = .Thread t → cI = .threadCap (specPtr t) := fun h => by - rw [h] at hcI - exact (CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)).symm - have hsameT : fl4TcbSameObject (.threadCap (specPtr t)) (.threadCap (specPtr t)) := by - simp [fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] - have hsameE : fl4TcbSameObject (absCapA (.Endpoint p b sn rv g gr)) (absCapA (.Endpoint p b sn rv g gr)) := by - simp [absCapA, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] have hcurd : σd.curThread = σ.curThread := Binv.2.1 - have htcS : specPtr t ≠ σ.curThread := fun e => hne (specPtr_inj (e.trans J.sr.sch.curThread)) -- the install: either it inserts (still valid) or it does nothing have key : ∃ (s2 : S) (σ2 : Fl4SpecA64.State Unit) (Gi : MdbGhostA), tcb.install_tcb_cap st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t slot layout.tcb.SLOT_FAULT_HANDLER (capA st s fhSlot) fhSlot = ok (.Ok (), s2, ad) ∧ (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs 3 (some (absCapA (capA st s fhSlot), κsrc))).run (stUpdA σ σ.curThread x' .restart)).1 ∧ - Sched.BodyKeepA σd σ2 ∧ DWkA σd σ2 ∧ + Sched.BodyKeepA σd σ2 ∧ DWkA σd σ2 ∧ (∀ p0, LkA σ.curThread p0 σd σ2) ∧ JStage3A st AR { { Z with G := Gd, Q := Q, R := R, hw := hw' } with G := Gi } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s2 ad σ2 m := by + by_cases hN : capA st s fhSlot = .Null + · refine ⟨sd, σd, Gd, ?_, ?_, Sched.BodyKeepA.refl σd, PreO.refl (R := DWkA) σd, + fun _ => PreO.refl (R := LkA σ.curThread _) σd, Jd⟩ + · rw [hN] + simp only [tcb.install_tcb_cap, hdest, hdel0, bind_ok, uncurry_apply_pair, + core.result.Result.Insts.CoreOpsTry.branch, cap_is_null_nullA, if_true] + · rw [hN] + show (.ok (), σd) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs 3 (some (.nullCap, κsrc))).run _).1 + simp only [fl4InstallTcbCap] + refine mem_bindE_okD (a := ()) (s' := σd) hspec ?_ + simp [Fl4Spec.NonDetE.unlessE, run_returnOkD] + obtain ⟨p, b, sn, rv, g, gr, hnc⟩ : ∃ p b sn rv g gr, capA st s fhSlot = .Endpoint p b sn rv g gr := by + generalize capA st s fhSlot = c at hN hValid + cases c with + | Null => exact absurd rfl hN + | Endpoint p b sn rv g gr => exact ⟨p, b, sn, rv, g, gr, rfl⟩ + | _ => exact absurd (okinj hValid) Bool.false_ne_true + have hkeepS : capA st sd fhSlot = .Endpoint p b sn rv g gr ∨ capA st sd fhSlot = .Null ∨ HomeZA st sd fhSlot := by + rcases hch fhSlot hsrcOS hneS with h | h | h + · exact Or.inl (h.trans hnc) + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr h) + have hkeepI : capA st sd slot = .Thread t ∨ capA st sd slot = .Null ∨ HomeZA st sd slot := by + rcases hch slot hslot hneI with h | h | h + · exact Or.inl (h.trans hcap) + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr h) + have hSV := tcbStillValid_keptA (st := st) sd t slot fhSlot hsrc0 p b sn rv g gr hkeepS hkeepI + have hnotnull : capability.Cap.is_null (.Endpoint p b sn rv g gr) = ok false := rfl + have hnSpec : absCapA (.Endpoint p b sn rv g gr) ≠ .nullCap := by simp [absCapA] + obtain ⟨cS, hgS, hcS⟩ := getCap_eqA Jd.j.1.st (show AbsSlotA Z.th κsrc from hAsrc) + obtain ⟨cI, hgI, hcI⟩ := getCap_eqA Jd.j.1.st (show AbsSlotA Z.th κs from hAκ) + rw [capAtA_eq (st := st), hκsrc] at hcS + rw [capAtA_eq (st := st), hκ] at hcI + have mS : (cS, σd) ∈ (getCap (Z := Unit) κsrc σd).1 := by rw [hgS]; exact Set.mem_singleton _ + have mI : (cI, σd) ∈ (getCap (Z := Unit) κs σd).1 := by rw [hgI]; exact Set.mem_singleton _ + have eS : capA st sd fhSlot = .Endpoint p b sn rv g gr → cS = absCapA (.Endpoint p b sn rv g gr) := fun h => by + rw [h] at hcS + exact (CapEqA.eq_abs hcS (fun _ _ _ h => by cases h)).symm + have eI : capA st sd slot = .Thread t → cI = .threadCap (specPtr t) := fun h => by + rw [h] at hcI + exact (CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)).symm + have hsameT : fl4TcbSameObject (.threadCap (specPtr t)) (.threadCap (specPtr t)) := by + simp [fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] + have hsameE : fl4TcbSameObject (absCapA (.Endpoint p b sn rv g gr)) (absCapA (.Endpoint p b sn rv g gr)) := by + simp [absCapA, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] by_cases hv : capA st sd fhSlot = .Endpoint p b sn rv g gr ∧ capA st sd slot = .Thread t swap · rw [decide_eq_false hv] at hSV - refine ⟨sd, σd, Gd, ?_, ?_, Sched.BodyKeepA.refl σd, PreO.refl (R := DWkA) σd, Jd⟩ + refine ⟨sd, σd, Gd, ?_, ?_, Sched.BodyKeepA.refl σd, PreO.refl (R := DWkA) σd, + fun _ => PreO.refl (R := LkA σ.curThread _) σd, Jd⟩ · rw [hnc] simp only [tcb.install_tcb_cap, hdest, hdel0, bind_ok, uncurry_apply_pair, core.result.Result.Insts.CoreOpsTry.branch, hnotnull, hSV, Bool.false_eq_true, ite_false] @@ -449,34 +509,270 @@ theorem JSyscallA.setSchedParamsEpA [PlainStore st] (fun s2' h2 => by rw [hFs s2' h2]; exact hF.2.1) (fun s2' h2 => by rw [hFs s2' h2]; exact hF.1) (fun s2' σ2' h2 _ => by rw [hFs s2' h2]; exact hF.2.2.2.2 σ2' m) - refine ⟨s2, σ2, _, hIns s2 hs2, ?_, hbk, (capInsert_skA _ _ _ σd ((), σ2) hm).toDWkA, J2⟩ + refine ⟨s2, σ2, _, hIns s2 hs2, ?_, hbk, (capInsert_skA _ _ _ σd ((), σ2) hm).toDWkA, + fun _ => capInsert_lkA _ _ _ σd ((), σ2) hm, J2⟩ rw [hnc] exact tcbSlotInsert_specA hspec hnSpec mS (by rw [eS hS]; exact hsameE) mI (by rw [eI hI]; exact hsameT) hm - obtain ⟨s2, σ2, Gi, hInst, hInstSpec, hbk, wk, J2⟩ := key + obtain ⟨s2, σ2, Gi, hInst, hInstSpec, hbk, wk, lkI, J2⟩ := key have hnsd : ∀ u, σd.schedulerAction ≠ .switchThread u := fun u => Binv.2.2.1 u have sact2 : SActA σ2 := by refine sactKeepA Pr.2.1 hnsd hbk ?_ obtain ⟨x, hx, -⟩ := J2.ep.tcb _ J2.sr.curT exact ⟨x, by rw [J2.sr.sch.curThread]; exact hx⟩ - have htc2 : specPtr t ≠ σ2.curThread := by rw [hbk.cur, hcurd]; exact htcS - have hns2 : ∀ u, σ2.schedulerAction ≠ .switchThread u := fun u h => hnsd u (hbk.act ▸ h) - obtain ⟨sm, s3, σ3, yd, hMcp, hsp3, hyd, hSet3, Bkm, DS3, J3⟩ := J2.sspTailA hA hPl hCs h1 hmb hmax htu hns2 sact2 - ht (hw mcp hle1) (hw prio hle2) htc2 hidles - have hdecOk : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = - ok (.Ok (), s3, ad) := by - rw [hdecBase] - exact tcbSetSchedParams_effectsA false hInst hMcp hsp3 - obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov - (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) - (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, - DecArmS1aC, capFam]) - (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdecOk σ3 m - obtain ⟨Q3, R3, J3'⟩ := J3 sysl symL userOK j7 - have B2 := BodyOKA.stepA (BodyOKA.stepA (BodyOKA.stepA Binv (delStep_ofKeepA hbk wk.off wk.ctSc)) - (delStep_ofKeepA Bkm (CtOffA.keep rfl (Or.inl rfl)) (CtScKA.ofUpd rfl (fun _ _ c => absurd c.symm htc2)))) DS3 - refine ⟨.Ok (), s3, ad, hdecOk, x', stUpdA σ σ.curThread x' .restart, σ3, hx', rfl, hset', Gi, Q3, R3, hw', Ac', Bf', - stack', J3', Or.inl ⟨rfl, fun κs' => ?_, B2.1, B2.2.1⟩⟩ - exact sspEp_invokeA κs κsrc _ _ _ hInstSpec hyd hSet3 + -- the caller's frame across the deletion of slot 3 (it holds Null or an endpoint; the caller is in no queue) + have hfh := J.fhOK t ht + rw [hslotIdx] at hfh + have hk1 : (stUpdA σ σ.curThread x' .restart).kheap σ.curThread = some (.tcb { x' with tcbState := .restart }) := by + simp [stUpdA, setObjA] + have hkeepST : ∀ q, q ≠ σ.curThread → (stUpdA σ σ.curThread x' .restart).kheap q = σ.kheap q := fun q hq => by + simp [stUpdA, setObjA, Function.update_of_ne hq] + have epNe1 : ∀ r, EpQNeA r σ → EpQNeA r (stUpdA σ σ.curThread x' .restart) := fun r h z hz => by + by_cases e : r = σ.curThread + · subst e; simp [stUpdA, setObjA] at hz + · have hz' : σ.kheap r = some (.endpoint z) := by simpa [stUpdA, setObjA, Function.update_of_ne e] using hz + exact h z hz' + obtain ⟨xs, hxs1, hxs2⟩ := J.j.1.st.tcb t hthT + obtain ⟨ac, hac, hca⟩ := hxs2 3 (by decide) + obtain ⟨-, hab⟩ := hca + rw [capAtA_eq (st := st)] at hab + have hcs : cslotAddrA sl = slotAddrA (specPtr t) 3#64 := by + unfold cslotAddrA + show slotAddrA (specPtr t) (Fl4SpecA64.ofBl (tcbCnodeIndex 3)) = _ + rw [ofBl_tcbIdx 3 (by decide)] + rw [← hcs] at hab + have hc3 : ac = .nullCap ∨ ∃ r b rs, ac = .endpointCap r b rs ∧ + EpQNeA r (stUpdA σ σ.curThread x' .restart) := by + rcases hfh with hn | ⟨p, b0, b1, b2, b3, b4, hcp, hHp⟩ + · left; rw [hn] at hab + have := CapEqA.eq_abs hab (fun _ _ _ h => by cases h) + simpa [absCapA] using this.symm + · right + refine ⟨specPtr p, b0.bv, rightsOfA b1 b2 b3 b4, ?_, ?_⟩ + · rw [hcp] at hab; exact (CapEqA.eq_abs hab (fun _ _ _ h => by cases h)).symm + · exact epNe1 _ (epQNe_ofRecA J.ep J.sact (J.ipcHeapCov.ep p hHp)) + have hg3 : getCap (Z := Unit) sl (stUpdA σ σ.curThread x' .restart) = + ({(ac, stUpdA σ σ.curThread x' .restart)}, False) := by + by_cases hcur : t = L.curW s + · have htcC : specPtr t = σ.curThread := by rw [hcur]; exact J.sr.sch.curThread.symm + have exs : x' = xs := KernelObject.tcb.inj (Option.some.inj (by rw [htcC, hx'] at hxs1; exact hxs1)) + exact getCap_tcb_eqA (σ := stUpdA σ σ.curThread x' .restart) (t := specPtr t) + (x := { x' with tcbState := .restart }) (idx := tcbCnodeIndex 3) (c := ac) (by rw [htcC]; exact hk1) + (by rw [exs] at *; exact hac) + · exact getCap_tcb_eqA (σ := stUpdA σ σ.curThread x' .restart) (t := specPtr t) (x := xs) + (idx := tcbCnodeIndex 3) (c := ac) + ((hkeepST _ fun e => hcur (specPtr_inj (e.trans J.sr.sch.curThread))).trans hxs1) hac + have lkAll : ∀ p0, LkA σ.curThread p0 (stUpdA σ σ.curThread x' .restart) σ2 := fun p0 => + PreO.trans (capDelete_noe_lkA (sl := sl) hg3 hc3 rfl hspec) (lkI p0) + by_cases hcur : t = L.curW s + · have htcC : specPtr t = σ.curThread := by rw [hcur]; exact J.sr.sch.curThread.symm + obtain ⟨x0, hx0, hxsc, -⟩ := J.curInv.tcb + rw [hx'] at hx0 + have ex0 : x' = x0 := KernelObject.tcb.inj (Option.some.inj hx0) + have hxsc' : x'.tcbSchedContext = some σ.curSc := by rw [ex0]; exact hxsc + have hch : L.mem s (scA t) = v := by + obtain ⟨hv0, hvs⟩ := J.scParamsFactsA hCs h1 ht hscOS hsc + obtain ⟨-, -, z, k, -, hh, -⟩ := hvs fun e => hv0 e hcur + rcases hh with h | ⟨h0, -⟩ + · exact h + · exfalso + obtain ⟨u, hku, hu⟩ := J.sr.sch.tcb t ht + rw [htcC, hx'] at hku + obtain rfl := KernelObject.tcb.inj (Option.some.inj hku).symm + rw [hxsc', h0, optScA, if_pos rfl] at hu + cases hu + -- the caller at the post-insert state: restarting, with its active SC, outside the release queue + obtain ⟨hAct, -⟩ := schedulable_actA (J.toJStage3A.curSchedulableA J.chargeEntryA J.running) + obtain ⟨xa, sca, hxa, hsca, y0, k0, hy0, hact0⟩ := hAct + rw [hx'] at hxa + have exa : x' = xa := (KernelObject.tcb.inj (Option.some.inj hxa)) + have scE : sca = σ.curSc := by + rw [← exa, hxsc'] at hsca; exact (Option.some.inj hsca).symm + obtain ⟨y2, hy2, hy2sc, -⟩ := (lkAll σ.curSc).fwd σ.curThread _ hk1 + have hy2st : y2.tcbState = .restart := (lkAll σ.curSc).stc _ _ hk1 hy2 + have hrelq : σ.curThread ∉ σ2.releaseQueue := by rw [hbk.rel]; exact Binv.2.2.2.2.2.2.1 + have hT2 : TgtA (specPtr t) σ2 := by + refine ⟨⟨y2, sca, by rw [htcC]; exact hy2, hy2sc.trans (by show x'.tcbSchedContext = some sca; rw [hxsc', scE]), y0, k0, ?_, hact0⟩, + by rw [htcC]; exact hrelq⟩ + have hne : sca ≠ σ.curThread := fun e => by rw [e, hx'] at hy0; cases hy0 + rw [scE] at hne hy0 + have := (lkAll σ.curSc).sc (Or.inl rfl) y0 k0 (by rw [hkeepST σ.curSc hne]; exact hy0) + rw [scE]; exact this + have hrun2 : ∀ y, σ2.kheap (specPtr t) = some (.tcb y) → runnable y.tcbState = true := fun y hy => by + rw [htcC, hy2] at hy + obtain rfl := KernelObject.tcb.inj (Option.some.inj hy) + rw [hy2st]; rfl + have htc2 : specPtr t = σ2.curThread := by rw [hbk.cur, hcurd]; exact htcC + obtain ⟨sm, s3, σ3, yd, hMcp, hsp3, hyd, hSet3, Bkm, hobj3, act3, time3, last3, cur3, csc3, cons3, rel3, J3⟩ := + J2.sspTailCurA hA hPl hCs h1 sact2 ht (hw mcp hle1) (hw prio hle2) htc2 hidles hrun2 hT2 + have hdecOk : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s3, ad) := by + rw [hdecBase, if_pos hch] + exact tcbSetSchedParams_effectsA false hInst hMcp hsp3 + obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdecOk σ3 m + obtain ⟨Q3, R3, J3'⟩ := J3 sysl symL userOK j7 + have B3 := BodyOKA.stepA (BodyOKA.stepA Binv (delStep_ofKeepA hbk wk.off wk.ctSc)) + (delStep_ofKeepA Bkm (CtOffA.keep rfl (Or.inl rfl)) + (CtScKA.ofUpd rfl (fun x1 e c => ⟨yd, hyd, Or.inl (by cases e; rfl)⟩))) + have hB : Sched.BodyEndA σ σ3 m := + ⟨Sched.BodyOKA.ofChooseA B3.1 act3 time3 last3 csc3 cons3 rel3 hobj3, cur3.trans B3.2.1⟩ + refine ⟨.Ok (), s3, ad, hdecOk, x', stUpdA σ σ.curThread x' .restart, σ3, hx', rfl, hset', Gi, Q3, R3, hw', Ac', Bf', + stack', J3', Or.inl ⟨rfl, fun κs' => ?_, hB.1, hB.2⟩⟩ + rw [show scUpdC (L.mem s (scA t)) v = none by unfold scUpdC; rw [if_pos hch]] + exact sspEp_invokeA κs κsrc _ _ _ hInstSpec hyd hSet3 (sc := none) rfl + · have htcS : specPtr t ≠ σ.curThread := fun e => hcur (specPtr_inj (e.trans J.sr.sch.curThread)) + have htc2 : specPtr t ≠ σ2.curThread := by rw [hbk.cur, hcurd]; exact htcS + have hns2 : ∀ u, σ2.schedulerAction ≠ .switchThread u := fun u h => hnsd u (hbk.act ▸ h) + obtain ⟨sm, s3, σ3, yd, hMcp, hsp3, hyd, hSet3, Bkm, DS3, Q3, R3, J3'⟩ := J2.sspTailA hA hPl hCs h1 hmb hmax htu + hns2 sact2 ht (hw mcp hle1) (hw prio hle2) htc2 hidles + have B2 := BodyOKA.stepA (BodyOKA.stepA (BodyOKA.stepA Binv (delStep_ofKeepA hbk wk.off wk.ctSc)) + (delStep_ofKeepA Bkm (CtOffA.keep rfl (Or.inl rfl)) (CtScKA.ofUpd rfl (fun _ _ c => absurd c.symm htc2)))) DS3 + by_cases hch : L.mem s (scA t) = v + · have hdecOk : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s3, ad) := by + rw [hdecBase, if_pos hch] + exact tcbSetSchedParams_effectsA false hInst hMcp hsp3 + refine ⟨.Ok (), s3, ad, hdecOk, x', stUpdA σ σ.curThread x' .restart, σ3, hx', rfl, hset', Gi, Q3, R3, hw', Ac', + Bf', stack', J3', Or.inl ⟨rfl, fun κs' => ?_, B2.1, B2.2.1⟩⟩ + rw [show scUpdC (L.mem s (scA t)) v = none by unfold scUpdC; rw [if_pos hch]] + exact sspEp_invokeA κs κsrc _ _ _ hInstSpec hyd hSet3 (sc := none) rfl + -- the SC changes: a detach or a bind, after `set_priority` + obtain ⟨-, hfull⟩ := J.scParamsFactsA hCs h1 ht hscOS hsc + have hset : setMcpriority (Z := Unit) (specPtr t) (BitVec.ofNat 8 mcp.val) σ2 = + ({((), mcpStateA σ2 (specPtr t) yd (BitVec.ofNat 8 mcp.val))}, False) := threadSet_eqSc _ hyd + have lk3 : ∀ p0, LkA σ.curThread p0 (stUpdA σ σ.curThread x' .restart) σ3 := fun p0 => by + have lkm : LkA σ.curThread p0 σ2 (mcpStateA σ2 (specPtr t) yd (BitVec.ofNat 8 mcp.val)) := + (threadSet_lkA (ct := σ.curThread) (p0 := p0) (fun tcb => { tcb with tcbMcpriority := BitVec.ofNat 8 mcp.val }) + (specPtr t) (fun _ => ⟨rfl, Or.inl rfl⟩) (fun _ _ => rfl)) σ2 + ((), mcpStateA σ2 (specPtr t) yd (BitVec.ofNat 8 mcp.val)) + (by unfold setMcpriority at hset; rw [hset]; exact Set.mem_singleton _) + have lkp : LkA σ.curThread p0 (mcpStateA σ2 (specPtr t) yd (BitVec.ofNat 8 mcp.val)) σ3 := + (setPriority_lkA (ct := σ.curThread) (p0 := p0) (specPtr t) (BitVec.ofNat 8 prio.val)) + (mcpStateA σ2 (specPtr t) yd (BitVec.ofNat 8 mcp.val)) ((), σ3) (by rw [hSet3]; exact Set.mem_singleton _) + exact PreO.trans (lkAll p0) (PreO.trans lkm lkp) + -- the caller at the post-priority state: restarting, bound to its SC + obtain ⟨x0, hx0, hxsc, -⟩ := J.curInv.tcb + rw [hx'] at hx0 + have ex0 : x' = x0 := KernelObject.tcb.inj (Option.some.inj hx0) + have hxsc' : x'.tcbSchedContext = some σ.curSc := by rw [ex0]; exact hxsc + obtain ⟨y3, hy3, hy3sc, -⟩ := (lk3 σ.curSc).fwd σ.curThread _ hk1 + have hy3st : y3.tcbState = .restart := (lk3 σ.curSc).stc _ _ hk1 hy3 + have hcur3 : σ3.curThread = σ.curThread := (lk3 σ.curSc).cur + have hcb3 : CurBA σ3 := ⟨y3, by rw [hcur3]; exact hy3, by rw [(lk3 σ.curSc).csc]; exact hy3sc.trans hxsc'⟩ + have hcr3 : ∀ x, σ3.kheap σ3.curThread = some (.tcb x) → x.tcbState = .running ∨ x.tcbState = .restart := + fun x hx => by + rw [hcur3, hy3] at hx + obtain rfl := KernelObject.tcb.inj (Option.some.inj hx).symm + exact Or.inr hy3st + have hns3 : ∀ u, σ3.schedulerAction ≠ .switchThread u := fun u e => by + rcases DS3.act with h | h + · exact hns2 u (h.symm.trans e) + · rw [h] at e; cases e + have sact3 : SActA σ3 := + ⟨fun u hu => absurd hu (hns3 u), ⟨y3, by rw [hcur3]; exact hy3, Or.inr (Or.inl hy3st)⟩⟩ + have htc3 : specPtr t ≠ σ3.curThread := by rw [hcur3]; exact htcS + obtain ⟨u, hku, hu⟩ := J.sr.sch.tcb t ht + obtain ⟨y, hy, hysc, hyst⟩ := (lk3 σ.curSc).fwd (specPtr t) u ((hkeepST _ htcS).trans hku) + obtain ⟨u3, hk3, hu3⟩ := J3'.sr.sch.tcb t ht + rw [hy] at hk3 + obtain rfl := KernelObject.tcb.inj (Option.some.inj hk3) + have hsc3 : obj.Tcb.sc st t s3 = ok (L.mem s3 (scA t)) := eq_of_spec_fd (obj.Tcb.sc.spec (L := L) s3 t) + by_cases hv0 : v = 0#u64 + · subst hv0 + have hold3 : L.mem s3 (scA t) ≠ 0#u64 := fun e => by + rw [e, optScA, if_pos rfl, hysc, hu, optScA, if_neg hch] at hu3 + cases hu3 + obtain ⟨s4, σ4, hu4, hUs, ⟨y4, hy4, hy4sc⟩, hcur4, hImp⟩ := + J3'.sspUnbindA sact3 hns3 hCs h1 B2.1 ht hidles htc3 hold3 hcb3 hcr3 + have hdecOk : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s4, ad) := by + rw [hdecBase, if_neg hch] + refine Eq.trans (tcbSetSchedParams_effectsA (sc := 0#u64) true hInst hMcp hsp3) ?_ + simp only [eq_self_iff_true, if_true, ↓reduceIte, ite_true, hsc3, bind_ok, if_neg hold3, hu4] + obtain ⟨-, Ac'', sysl, symL, bxi, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdecOk σ4 m + obtain ⟨Q4, R4, J4, B4⟩ := hImp Ac'' bxi sysl symL userOK j7 + refine ⟨.Ok (), s4, ad, hdecOk, x', stUpdA σ σ.curThread x' .restart, σ4, hx', rfl, hset', Gi, Q4, R4, hw', + Ac'', Bf', stack', J4, Or.inl ⟨rfl, fun κs' => ?_, B4, hcur4.trans hcur3⟩⟩ + rw [show scUpdC (L.mem s (scA t)) 0#u64 = some none by unfold scUpdC; rw [if_neg hch]; simp] + exact sspEp_invokeA κs κsrc _ _ _ hInstSpec hyd hSet3 (sc := some none) (sspScStep_unbindA hy4 hy4sc hUs) + · obtain ⟨hvC, hvni, z, k, hz, hzc, hzrel⟩ := hfull hv0 + obtain ⟨ho, hzn⟩ := hzc.resolve_left hch + have hname : scNameA m v = specPtr v := by + unfold scNameA at hvni ⊢ + by_cases c : specPtr v = m.idleScOf m.curCore + · rw [if_pos c] at hvni; exact absurd rfl hvni.1 + · rw [if_neg c] + have ht0 : L.mem s3 (scA t) = 0#u64 := by + by_contra hne + rw [hysc, hu, ho, optScA, if_pos rfl, optScA, if_neg hne] at hu3 + cases hu3 + have hzne : scNameA m v ≠ σ.curThread := fun e => by rw [e, hx'] at hz; cases hz + have hcond : scNameA m v = σ.curSc ∨ ∀ p x, (stUpdA σ σ.curThread x' .restart).kheap p = some (.tcb x) → + x.tcbSchedContext ≠ some (scNameA m v) := by + right + intro p x hp hxs + by_cases hpc : p = σ.curThread + · subst hpc + rw [hk1] at hp + obtain rfl := KernelObject.tcb.inj (Option.some.inj hp) + obtain ⟨y', n, hy', hyt⟩ := J.sr.inv.back _ x' _ hx' hxs + rw [hz] at hy' + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hy') + rw [hzn] at hyt; cases hyt + · rw [hkeepST p hpc] at hp + obtain ⟨y', n, hy', hyt⟩ := J.sr.inv.back _ x _ hp hxs + rw [hz] at hy' + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hy') + rw [hzn] at hyt; cases hyt + have hzk := (lk3 (scNameA m v)).sc hcond z k (by rw [hkeepST _ hzne]; exact hz) + have hs0 : L.mem s3 (scTcbA v) = 0#u64 := by + obtain ⟨z3, k3, hz3, hzr3⟩ := J3'.sr.scr.sc v hvC + rw [hzk] at hz3 + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz3) + by_contra hne + rw [hzr3.tcb, ← scTcbA_eqSc, optRefS_ne hne] at hzn + cases hzn + have hb3 : ∀ x y' k', σ3.kheap (specPtr t) = some (.tcb x) → σ3.kheap (scNameA m v) = some (.schedContext y' k') → + ipcQueuedThreadState x.tcbState = true → scReleased σ3.curTime y' = true := by + intro x y' k' hx hy' hq + rw [hzk] at hy' + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hy') + rw [hy] at hx + obtain rfl := KernelObject.tcb.inj (Option.some.inj hx) + have hq' : ipcQueuedThreadState u.tcbState = true := by + rcases hyst with e | e + · rw [← e]; exact hq + · rw [e] at hq; cases hq + rw [(lk3 σ.curSc).time] + exact hzrel u hku hq' + obtain ⟨s4, σ4, hb4, hBs, hcur4, hImp⟩ := + J3'.sspBindA sact3 hns3 hCs h1 (hmb ad) B2.1 ht hvC hvni hidles htc3 ht0 hs0 hcb3 hcr3 hb3 + have hdecOk : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s4, ad) := by + rw [hdecBase, if_neg hch] + refine Eq.trans (tcbSetSchedParams_effectsA true hInst hMcp hsp3) ?_ + simp only [eq_self_iff_true, if_true, ↓reduceIte, ite_true, if_neg hv0, hb4, bind_ok, uncurry_apply_pair] + try rfl + obtain ⟨-, Ac'', sysl, symL, bxi, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdecOk σ4 m + obtain ⟨Q4, R4, J4, B4⟩ := hImp Ac'' bxi sysl symL userOK j7 + refine ⟨.Ok (), s4, ad, hdecOk, x', stUpdA σ σ.curThread x' .restart, σ4, hx', rfl, hset', Gi, Q4, R4, hw', + Ac'', Bf', stack', J4, Or.inl ⟨rfl, fun κs' => ?_, B4, hcur4.trans hcur3⟩⟩ + rw [show scUpdC (L.mem s (scA t)) v = some (some (specPtr v)) by unfold scUpdC; rw [if_neg hch, if_neg hv0]] + refine sspEp_invokeA κs κsrc _ _ _ hInstSpec hyd hSet3 (sc := some (some (specPtr v))) ?_ + show fl4TcbBindSc (specPtr v) (specPtr t) σ3 = _ + rw [fl4TcbBindSc_eq_l4v hmin, ← hname] + exact hBs end end diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutA.lean index 078dafd19..2253080c5 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutA.lean @@ -66,7 +66,7 @@ theorem JSyscallA.setTimeoutNullA [PlainStore st] (hnullh : capA st s src = .Null) (κsrc : CslotPtr) : ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (r, s3, a3) ∧ - TcbDelOutA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ + TcbDelOutA st AR Clock Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ (fun κs => .threadControlCaps (specPtr t) κs none (some (.nullCap, κsrc)) none none none) r s3 a3 := by have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap have htT : t ∈ H.tcbs := by rw [J.tcbs]; exact ht @@ -118,7 +118,7 @@ theorem JSyscallA.setTimeoutNullA [PlainStore st] rw [e1] at hspec exact setTimeoutNull_invokeA κs κsrc hspec · subst hr1 - obtain ⟨⟨⟨-, X, sv⟩, -⟩, hpre⟩ := hW + obtain ⟨⟨⟨-, X, sv⟩, tm⟩, hpre⟩ := hW obtain ⟨Q, R, hw, Ac', Bf', stack', Jd⟩ := X.toStage3A sysd.1 sysd.2 sv have hdecP : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (.Err .Preempted, sd, ad) := by @@ -128,7 +128,7 @@ theorem JSyscallA.setTimeoutNullA [PlainStore st] core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] refine ⟨.Err .Preempted, sd, ad, hdecP, x', stUpdA σ σ.curThread x' .restart, σd, hx', rfl, hset', Gd, Q, R, hw, - Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun κs => ?_, hpre.1, hpre.2.1⟩⟩ + Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun κs => ?_, hpre.1, hpre.2.1, hpre.preExitA, tm.2.1⟩⟩ rw [e1] at hspec exact setTimeoutNull_invokeErrA κs κsrc hspec diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutNnA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutNnA.lean index 227d5939b..e100a7310 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutNnA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutNnA.lean @@ -168,7 +168,7 @@ theorem JSyscallA.setTimeoutNonNullA [PlainStore st] (hAsrc : AbsSlotA Z.th κsrc) (hκsrc : cslotAddrA κsrc = src) : ∃ r s3 a3, syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (r, s3, a3) ∧ - TcbDelOutA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ + TcbDelOutA st AR Clock Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n m ar hPl.ipa s a σ (fun _ => .threadControlCaps (specPtr t) κs none (some (absCapA (capA st s src), κsrc)) none none none) r s3 a3 := by obtain ⟨p, b, sn, rv, g, gr, hnc⟩ : ∃ p b sn rv g gr, capA st s src = .Endpoint p b sn rv g gr := by @@ -235,7 +235,7 @@ theorem JSyscallA.setTimeoutNonNullA [PlainStore st] rcases hres with ⟨hr1, hnull, hspec, hch⟩ | ⟨hr1, hspec⟩ swap · subst hr1 - obtain ⟨⟨⟨-, X, sv⟩, -⟩, hpre⟩ := hW + obtain ⟨⟨⟨-, X, sv⟩, tm⟩, hpre⟩ := hW obtain ⟨Q, R, hw, Ac', Bf', stack', Jd⟩ := X.toStage3A sysd.1 sysd.2 sv have hdecP : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (.Err .Preempted, sd, ad) := by @@ -245,7 +245,7 @@ theorem JSyscallA.setTimeoutNonNullA [PlainStore st] core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] refine ⟨.Err .Preempted, sd, ad, hdecP, x', stUpdA σ σ.curThread x' .restart, σd, hx', rfl, hset', Gd, Q, R, hw, - Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun _ => ?_, hpre.1, hpre.2.1⟩⟩ + Ac', Bf', stack', Jd, Or.inr ⟨rfl, fun _ => ?_, hpre.1, hpre.2.1, hpre.preExitA, tm.2.1⟩⟩ rw [e1] at hspec have hSkip (k : Nat) : fl4InstallTcbCap (Z := Unit) (specPtr t) κs k none = Fl4Spec.NonDetE.returnOk () := rfl have hrk : (.ok (), stUpdA σ σ.curThread x' .restart) ∈ diff --git a/proofs/Fl4ProofsA64/P3/Stage3MapS2UnmA.lean b/proofs/Fl4ProofsA64/P3/Stage3MapS2UnmA.lean new file mode 100644 index 000000000..e77611ebf --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3MapS2UnmA.lean @@ -0,0 +1,91 @@ +/- +P3 (AArch64, Stage 4 line vsx-A): **J9 (`UnmPtSpecA`) across one *valid* descriptor write into a Stage-2 page**. + +`UnmPtSpecA.ofS2WrA`: the write changes one word `peAF q j` of a Stage-2 table or root page `q ∈ S2PgE Z.X Z.T2` and +the spec heap at one object `o` only. Unmapped page-table and Stage-2-root caps keep their all-invalid tables because +P1's `unmZ` at the final state (`hz`, from the `fin` record) says their words are zero; unmapped Stage-1 roots and +windows keep theirs because their pages are not the written page (`pgd`: Stage-2 pages are no `VsPtA` page, no window). +The unmapped Stage-2 roots' spec objects are all-invalid after the write by `hs2` (the caller's case split: other +object, or a root written with an invalid descriptor). + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3MapExtA +import Fl4ProofsA64.P3.DelZeroKeepA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] + +/-- **J9 across one valid Stage-2 page write** (module docstring). -/ +theorem UnmPtSpecA.ofS2WrA {Z : XSetsA} {OS Pt : Set U64} {s s' : S} {σ σ' : State Unit} {m : McState} + {o : ObjRef} {q j : U64} (hj : j.val < 512) (hqal : q.val % 4096 = 0) + (hpgd : q ∉ VsPtA Z.Pp Z.S1 Z.Y ∧ q ∉ Z.Y) (hrel : RelPA { Z with S1 := ∅ } m o) + (hoY : ∀ y ∈ Z.Y, specPtr y ≠ o) (hS1al : ∀ p ∈ Z.S1, p.val % 4096 = 0) + (hYal : ∀ y ∈ Z.Y, 8192 ∣ y.val) + (hobj : ∀ u ∈ OS, CapObjOkA Z (capA st s u)) + (hbk : ∀ u ∈ OS, ∀ c, capA st s' u = c → (∀ p sz r d mp e a v, c ≠ .Frame p sz r d mp e a v) → + capA st s u = c) + (hz : ∀ u ∈ OS, ∀ (p : U64) (n : Nat), UnmCap (capA st s' u) p n → + ∀ k : U64, k.val < n → k.val % 8 = 0 → L.mem s' (wa p k) = 0#u64) + (link : ∀ p, SchedPageA st Z OS s p → p ∈ Pt) + (hword : ∀ p ∈ Pt, ∀ i : U64, i.val < 512 → peAF p i ≠ peAF q j → L.mem s' (peAF p i) = L.mem s (peAF p i)) + (hk : L.ksb s' = L.ksb s) (hcpu : L.cpu s' = L.cpu s) + (hset : ∀ x ao, x ≠ o → σ.kheap x = some (.archObj ao) → σ'.kheap x = some (.archObj ao)) + (hs2 : ∀ u ∈ OS, ∀ (p a v : U64), capA st s' u = .Ept p 0#u64 false a v → + (∃ es, σ.kheap (specPtr p) = some (.archObj (.ext (.stage2Root es))) ∧ ∀ i : Fin 1024, es i = .invalidPTE) → + ∃ es, σ'.kheap (specPtr p) = some (.archObj (.ext (.stage2Root es))) ∧ ∀ i : Fin 1024, es i = .invalidPTE) + (h : UnmPtSpecA st Z m OS s σ) : UnmPtSpecA st Z m OS s' σ' := by + have wm : ∀ i : U64, i.val < 1024 → (core.num.U64.wrapping_mul i 8#u64).val = i.val * 8 := fun i hi => by + simp [core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits]; omega + refine ⟨fun u hu p asid va hc => ?_, fun u hu p asid hc => ?_, fun u hu p asid va hc => ?_, + fun u hu p asid hc => ?_⟩ + · have old := hbk u hu _ hc (fun _ _ _ _ _ _ _ _ f => by cases f) + have h0 := h.pt u hu p asid va old + obtain ⟨t, k1, k2, k3⟩ := h0.spec + have hne : specPtr p ≠ o := fun e => h0.off.obj o hrel e.symm + refine ⟨fun i hi => ?_, ⟨t, hset _ _ hne k1, k2, k3⟩, h0.off.of_ksA hk hcpu⟩ + have e0 := hz u hu p 4096 (Or.inl ⟨rfl, asid, va, hc⟩) (core.num.U64.wrapping_mul i 8#u64) + (wm8_offA hi).1 (wm8_offA hi).2 + have e1 : L.mem s' (peAF p i) = 0#u64 := e0 + rw [e1]; exact dBitA_zeroA + · have old := hbk u hu _ hc (fun _ _ _ _ _ _ _ _ f => by cases f) + have h0 := h.vs u hu p asid old + obtain ⟨t, k1, k2, k3⟩ := h0.spec + have hne : specPtr p ≠ o := fun e => h0.off.obj o hrel e.symm + have hp : p ∈ Z.S1 := ((hobj u hu).2.2.2.1 p false asid (by rw [old])).1 + have hqp : q ≠ p := fun e => hpgd.1 (e ▸ Or.inr (Or.inl hp)) + refine ⟨fun i hi => ?_, ⟨t, hset _ _ hne k1, k2, k3⟩, h0.off.of_ksA hk hcpu⟩ + rw [hword p (link p (Or.inr (Or.inl hp))) i hi (Ne.symm (peAF_ne_tabA (hS1al p hp) hqal hi hj hqp))] + exact h0.inv i hi + · have old := hbk u hu _ hc (fun _ _ _ _ _ _ _ _ f => by cases f) + have h0 := h.s2 u hu p asid va old + refine ⟨fun i hi => ?_, hs2 u hu p asid va hc h0.spec⟩ + have e0 := hz u hu p 8192 (Or.inr ⟨rfl, asid, va, hc⟩) (core.num.U64.wrapping_mul i 8#u64) + (by rw [wm i hi]; omega) (by rw [wm i hi]; omega) + have e1 : L.mem s' (peAF p i) = 0#u64 := e0 + rw [e1]; exact dBitA_zeroA + · have old := hbk u hu _ hc (fun _ _ _ _ _ _ _ _ f => by cases f) + have h0 := h.hv u hu p asid old + obtain ⟨l, k1, k2⟩ := h0.spec + have hy : p ∈ Z.Y := (hobj u hu).2.2.1 p false asid (by rw [old]) + have hqp : q ≠ wa p 4096#u64 := fun e => hpgd.1 (e ▸ Or.inr (Or.inr ⟨p, hy, rfl⟩)) + refine ⟨fun i hi => ?_, l, hset _ _ (hoY p hy) k1, k2⟩ + have hm := waWin_modA (hYal p hy) + have hl : wa p 4096#u64 ∈ Pt := link _ (Or.inr <| Or.inr <| Or.inr <| Or.inr <| Or.inr <| Or.inr <| + Or.inl ⟨p, hy, rfl⟩) + rw [hword _ hl i hi (Ne.symm (peAF_ne_tabA hm hqal hi hj hqp))] + exact h0.inv i hi + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PinVsA.lean b/proofs/Fl4ProofsA64/P3/Stage3PinVsA.lean index 35f6005d6..456eee3c6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3PinVsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3PinVsA.lean @@ -483,6 +483,122 @@ theorem frameMapHi_pinA (hlab : info.label = fl4_abi.label.ARMPageMap) {fp rt as rw [e, ← hD] exact hiv +/-- `VsScopeA.ptMapHi`'s pin. -/ +theorem ptMapHi_pinA (hlab : info.label = fl4_abi.label.ARMPageTableMap) {ptr asid0 va0 : U64} {call : Bool} + (hcap : capA st s slot = .PageTable ptr false asid0 va0) + {x0 p1 asid1 : U64} {mp1 : Bool} (hx : vspace.extra extra 0#usize = ok (some x0)) + (hx0c : capA st s x0 = .HighVSpace p1 mp1 asid1) {vaddr : U64} (hlen : msgLenA info buf ≥ 2#u64) + (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hD : D = (Fl4Spec.NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeHighPageTableMap (Z := Unit) sl (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .high (specPtr p1) (asidDataA mp1 asid1)) vaddr.bv)).run σ) : + ∀ iv, (.ok (.extVSpace iv), σ) ∈ D.1 → DecPinA call Z.th σ slot (.invokeArchObject (.extVSpace iv)) := by + intro iv hiv + have hc : c = .archObjectCap (.pageTableCap (specPtr ptr) .normalPtT none) := + F.absA hcap (fun _ _ _ e => by cases e) + have h2 : 2 ≤ argsU.length := by + have := F.len + have : (2#u64 : U64).val ≤ (msgLenA info buf).val := by scalar_tac + have : (2#u64 : U64).val = 2 := rfl + omega + obtain ⟨y0, y1, rest, rfl⟩ : ∃ y0 y1 rest, argsU = y0 :: y1 :: rest := by + match argsU, h2 with + | y0 :: y1 :: rest, _ => exact ⟨y0, y1, rest, rfl⟩ + have e0 : y0 = vaddr := okinj ((F.args 0#u64 y0 rfl).symm.trans h0) + subst e0 + have hread := extra0_eqA (exAtA_idx0 extra) + rw [hx] at hread + have hne : exAtA extra 0 ≠ 0#u64 ∧ x0 = exAtA extra 0 := by + by_cases h : exAtA extra 0 = 0#u64 + · rw [if_pos h] at hread; cases okinj hread + · rw [if_neg h] at hread; exact ⟨h, Option.some.inj (okinj hread)⟩ + obtain ⟨y, erest, hexc⟩ : ∃ y erest, excaps = y :: erest := by + cases h : excaps with + | nil => exact absurd (F.extra.2.2 0 (by simp [h]) (by omega)) hne.1 + | cons y erest => exact ⟨y, erest, rfl⟩ + have hy : y.1 = extRootCapA .high (specPtr p1) (asidDataA mp1 asid1) := by + obtain ⟨ps, -, -, -, hrel⟩ := F.extra.2.1 0 (by simp [hexc]) + simp only [hexc, List.getElem_cons_zero] at hrel + rw [← hne.2, capAtA_eq (st := st), hx0c] at hrel + exact (hrel.2.eq_abs (fun _ _ _ e => by cases e)).symm + refine DecPinA.of_archA F.pin hc (F.labelA hlab (v := 47) (l := archL .armPageTableMap) + (by simp [fl4_abi.label.ARMPageTableMap]) (by decide)) fun cptr => ?_ + have e : fl4ArchDecodeInvocation (Z := Unit) call (archL .armPageTableMap) ((y0 :: y1 :: rest).map UScalar.bv) + cptr sl (.pageTableCap (specPtr ptr) .normalPtT none) excaps = + Fl4Spec.NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeHighPageTableMap (Z := Unit) sl (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .high (specPtr p1) (asidDataA mp1 asid1)) y0.bv) := by + unfold fl4ArchDecodeInvocation + subst hexc + obtain ⟨vc, xsl⟩ := y + simp only at hy + subst hy + simp only [List.length_cons, List.length_map, gt_iff_lt, Nat.zero_lt_succ, show 1 < rest.length + 1 + 1 by omega, + and_self, ↓reduceIte, List.getElem?_cons_zero, Fl4SpecA64.the, NonDetE.whenE, ne_self_iff_false, + ndE_pure_bindA, extRootCapA] + rfl + rw [e, ← hD] + exact hiv + +/-- `VsScopeA.ptMapS2`'s pin. -/ +theorem ptMapS2_pinA (hlab : info.label = fl4_abi.label.ARMPageTableMap) {ptr asid0 va0 : U64} {call : Bool} + (hcap : capA st s slot = .PageTable ptr false asid0 va0) + {x0 vp vasid vva : U64} (hx : vspace.extra extra 0#usize = ok (some x0)) + (hx0c : capA st s x0 = .Ept vp 0#u64 true vasid vva) {vaddr : U64} (hlen : msgLenA info buf ≥ 2#u64) + (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hD : D = (Fl4Spec.NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageTableMap (Z := Unit) sl (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .stage2 (specPtr vp) (asidDataA true vasid)) vaddr.bv)).run σ) : + ∀ iv, (.ok (.extVSpace iv), σ) ∈ D.1 → DecPinA call Z.th σ slot (.invokeArchObject (.extVSpace iv)) := by + intro iv hiv + have hc : c = .archObjectCap (.pageTableCap (specPtr ptr) .normalPtT none) := + F.absA hcap (fun _ _ _ e => by cases e) + have h2 : 2 ≤ argsU.length := by + have := F.len + have : (2#u64 : U64).val ≤ (msgLenA info buf).val := by scalar_tac + have : (2#u64 : U64).val = 2 := rfl + omega + obtain ⟨y0, y1, rest, rfl⟩ : ∃ y0 y1 rest, argsU = y0 :: y1 :: rest := by + match argsU, h2 with + | y0 :: y1 :: rest, _ => exact ⟨y0, y1, rest, rfl⟩ + have e0 : y0 = vaddr := okinj ((F.args 0#u64 y0 rfl).symm.trans h0) + subst e0 + have hread := extra0_eqA (exAtA_idx0 extra) + rw [hx] at hread + have hne : exAtA extra 0 ≠ 0#u64 ∧ x0 = exAtA extra 0 := by + by_cases h : exAtA extra 0 = 0#u64 + · rw [if_pos h] at hread; cases okinj hread + · rw [if_neg h] at hread; exact ⟨h, Option.some.inj (okinj hread)⟩ + obtain ⟨y, erest, hexc⟩ : ∃ y erest, excaps = y :: erest := by + cases h : excaps with + | nil => exact absurd (F.extra.2.2 0 (by simp [h]) (by omega)) hne.1 + | cons y erest => exact ⟨y, erest, rfl⟩ + have hy : y.1 = extRootCapA .stage2 (specPtr vp) (asidDataA true vasid) := by + obtain ⟨ps, -, -, -, hrel⟩ := F.extra.2.1 0 (by simp [hexc]) + simp only [hexc, List.getElem_cons_zero] at hrel + rw [← hne.2, capAtA_eq (st := st), hx0c] at hrel + exact (hrel.2.eq_abs (fun _ _ _ e => by cases e)).symm + refine DecPinA.of_archA F.pin hc (F.labelA hlab (v := 47) (l := archL .armPageTableMap) + (by simp [fl4_abi.label.ARMPageTableMap]) (by decide)) fun cptr => ?_ + have e : fl4ArchDecodeInvocation (Z := Unit) call (archL .armPageTableMap) ((y0 :: y1 :: rest).map UScalar.bv) + cptr sl (.pageTableCap (specPtr ptr) .normalPtT none) excaps = + Fl4Spec.NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageTableMap (Z := Unit) sl (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .stage2 (specPtr vp) (asidDataA true vasid)) y0.bv) := by + unfold fl4ArchDecodeInvocation + subst hexc + obtain ⟨vc, xsl⟩ := y + simp only at hy + subst hy + simp only [List.length_cons, List.length_map, gt_iff_lt, Nat.zero_lt_succ, show 1 < rest.length + 1 + 1 by omega, + and_self, ↓reduceIte, List.getElem?_cons_zero, Fl4SpecA64.the, NonDetE.whenE, ne_self_iff_false, + ndE_pure_bindA, extRootCapA] + rfl + rw [e, ← hD] + exact hiv + omit F /-- `VsScopeA.asidAssign`'s pin (from the arm's own spec decode; any free ASID is one outcome). -/ diff --git a/proofs/Fl4ProofsA64/P3/Stage3PinVsS2A.lean b/proofs/Fl4ProofsA64/P3/Stage3PinVsS2A.lean new file mode 100644 index 000000000..6e0786fc6 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PinVsS2A.lean @@ -0,0 +1,123 @@ +/- +P3 (aarch64, Stage 4 line vsx-A): **the pin of `VsScopeA.frameMapS2`** at the real decode (`DecPinA`): the Stage-2 frame +map's spec decode `fl4ArchDecodeInvocation` is `decodeS2PageMap` (plain frame: unmapped; mapped: a Stage-2 frame cap), which +after `checkExtRoot` (from `ept_rootA` at the extra cap) is the constructor's `decodeS2PageMapAt`. + +Named premises: [J] `JSyscallA`; the constructor's decode-site facts. New module (kept apart from `Stage3PinVsA` so the +other vsx lines' appends do not conflict). +-/ +import Fl4ProofsA64.P3.Stage3PinVsA +import Fl4ProofsA64.P3.ExtMapFrA +import Fl4ProofsA64.P3.FrFlushA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} +variable {info : msginfo.MessageInfo} {buf slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {mi : MessageInfo} + {sl : CslotPtr} {c : Cap} {excaps : List (Cap × CslotPtr)} {buffer : Option ObjRef} {argsU : List U64} + +/-- **`VsScopeA.frameMapS2`'s pin.** -/ +theorem frameMapS2_pinA {ar : machine.Arch A} {R : Set U64 → JSlotA S} + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st R) s a σ m) + (F : FrontJA st Z.th s σ info buf slot extra mi sl c excaps buffer argsU) + (hlab : info.label = fl4_abi.label.ARMPageMap) {fp rt asid va : U64} + {sz : capability.FrameSize} {dev mp e call : Bool} (hemp : e = mp) + (hcap : capA st s slot = .Frame fp sz rt dev mp e asid va) + {x0 p1 asid1 va1 : U64} {mp1 : Bool} (hx : vspace.extra extra 0#usize = ok (some x0)) + (hx0c : capA st s x0 = .Ept p1 0#u64 mp1 asid1 va1) (h16 : asid1.val < 2 ^ 16) + (hrt : ept.root st s (.Ept p1 0#u64 mp1 asid1 va1) 1#u64 = ok (core.result.Result.Ok (p1, asid1))) + {vaddr rightsMask attr : U64} (hlen : msgLenA info buf ≥ 3#u64) + (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + (h1 : msg.syscall_arg st s (L.curW s) buf 1#u64 = ok rightsMask) + (h2 : msg.syscall_arg st s (L.curW s) buf 2#u64 = ok attr) + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hD : D = (Fl4Spec.NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageMapAt (Z := Unit) sl (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev + (mapDataA mp asid va) (specPtr p1) (asidOfA asid1) vaddr.bv rightsMask.bv attr.bv)).run σ) : + ∀ iv, (.ok (.extVSpace iv), σ) ∈ D.1 → DecPinA call Z.th σ slot (.invokeArchObject (.extVSpace iv)) := by + intro iv hiv + have hc : c = .archObjectCap (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev + (mapDataA mp asid va)) := F.absA hcap (fun _ _ _ e' => by cases e') + -- the root check + have E0 := J.toJEntA + have hX : ∀ r ∈ Z.X, ∃ es, σ.kheap (specPtr r) = some (.archObj (.ext (.stage2Root es))) := + fun r hr => let ⟨es, hk, _⟩ := E0.j.1.ext.s2root r hr; ⟨es, hk⟩ + have hr0 := ept_rootA E0.j.1.vs hX p1 asid1 va1 1#u64 mp1 (lt_of_lt_of_eq h16 (by norm_num)) + rw [hrt] at hr0 + obtain ⟨-, -, -, hchk⟩ := (WP.spec_ok _).1 hr0 + -- the three words + have h3 : 3 ≤ argsU.length := by + have := F.len + have : (3#u64 : U64).val ≤ (msgLenA info buf).val := by scalar_tac + have : (3#u64 : U64).val = 3 := rfl + omega + obtain ⟨y0, y1, y2, rest, rfl⟩ : ∃ y0 y1 y2 rest, argsU = y0 :: y1 :: y2 :: rest := by + match argsU, h3 with + | y0 :: y1 :: y2 :: rest, _ => exact ⟨y0, y1, y2, rest, rfl⟩ + have e0 : y0 = vaddr := okinj ((F.args 0#u64 y0 rfl).symm.trans h0) + have e1 : y1 = rightsMask := okinj ((F.args 1#u64 y1 rfl).symm.trans h1) + have e2 : y2 = attr := okinj ((F.args 2#u64 y2 rfl).symm.trans h2) + subst e0 e1 e2 + -- the extra cap + have hread := extra0_eqA (exAtA_idx0 extra) + rw [hx] at hread + have hne : exAtA extra 0 ≠ 0#u64 ∧ x0 = exAtA extra 0 := by + by_cases h : exAtA extra 0 = 0#u64 + · rw [if_pos h] at hread; cases okinj hread + · rw [if_neg h] at hread; exact ⟨h, Option.some.inj (okinj hread)⟩ + obtain ⟨⟨vc, xs⟩, erest, hexc⟩ : ∃ y erest, excaps = y :: erest := by + cases h : excaps with + | nil => exact absurd (F.extra.2.2 0 (by simp [h]) (by omega)) hne.1 + | cons y erest => exact ⟨y, erest, rfl⟩ + have hy : vc = extRootCapA .stage2 (specPtr p1) (asidDataA mp1 asid1) := by + obtain ⟨ps, -, -, -, hrel⟩ := F.extra.2.1 0 (by simp [hexc]) + simp only [hexc, List.getElem_cons_zero] at hrel + rw [← hne.2, capAtA_eq (st := st), hx0c] at hrel + exact (hrel.2.eq_abs (fun _ _ _ e' => by cases e')).symm + subst hexc hy + refine DecPinA.of_archA F.pin hc (F.labelA hlab (v := 49) (l := archL .armPageMap) (by simp [fl4_abi.label.ARMPageMap]) (by decide)) fun cptr => ?_ + have ed : fl4ArchDecodeInvocation (Z := Unit) call (archL .armPageMap) ((y0 :: y1 :: y2 :: rest).map UScalar.bv) + cptr sl (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev (mapDataA mp asid va)) + ((extRootCapA .stage2 (specPtr p1) (asidDataA mp1 asid1), xs) :: erest) = + Fl4Spec.NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageMap (Z := Unit) sl + (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev (mapDataA mp asid va)) + (extRootCapA .stage2 (specPtr p1) (asidDataA mp1 asid1)) y0.bv y1.bv y2.bv) := by + have a1 : ¬ (archL .armPageMap = Fl4Label.ext .armPageDeriveSubframe) := fun h => by cases h + have a2 : ¬ (archL .armPageMap = Fl4Label.ext .armPageTestAndClearAccessed) := fun h => by cases h + cases e <;> ( + unfold fl4ArchDecodeInvocation + simp only [absFrameE, Bool.false_eq_true, ↓reduceIte, if_neg a1, if_neg a2, flushLbl_pgMapA, + List.map_cons, List.length_cons, gt_iff_lt, Nat.zero_lt_succ, show 2 < rest.length + 1 + 1 + 1 by omega, + and_self, List.getElem?_cons_zero, List.getElem?_cons_succ, Fl4SpecA64.the, extRootCapA] + rfl) + rw [ed] + have hAt : (Fl4Spec.NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageMap (Z := Unit) sl + (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev (mapDataA mp asid va)) + (extRootCapA .stage2 (specPtr p1) (asidDataA mp1 asid1)) y0.bv y1.bv y2.bv)).run σ = D := by + rw [hD] + subst hemp + cases e + · unfold decodeS2PageMap absFrameE + exact run_liftME_congrA ((run_bind_okA hchk _).trans + (run_bind_okA (by simp [mapDataA, NonDetE.whenE]; rfl) _)) + · unfold decodeS2PageMap absFrameE + exact run_liftME_congrA (run_bind_okA hchk _) + rw [← hAt] at hiv + exact hiv + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PreSchedA.lean b/proofs/Fl4ProofsA64/P3/Stage3PreSchedA.lean index 366ba462a..aa6328026 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3PreSchedA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3PreSchedA.lean @@ -378,7 +378,7 @@ theorem preschedA_keepA (σ : State Unit) : PreSchedKeepA σ (preschedA σ) := b obtain ⟨q, a, h, hq, hna, -⟩ := preschedA_casesA σ rw [h] refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, hna, ⟨fun _ => Or.inl rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩, - QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩, fun t h1 h2 d p hm => ?_⟩ + QKeepA.of_kheap rfl (DomKeepA.ofKey rfl), fun t h1 h2 d p hm => ?_⟩ rcases hq d p t hm with c | ⟨c, -⟩ exacts [h1 d p c, h2 c] diff --git a/proofs/Fl4ProofsA64/P3/Stage3PreemptChargeA.lean b/proofs/Fl4ProofsA64/P3/Stage3PreemptChargeA.lean index c1ef70fbf..cd28048fd 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3PreemptChargeA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3PreemptChargeA.lean @@ -439,7 +439,7 @@ theorem JStage3A.chargeUnschedPreA (by rw [he]; try exact Set.mem_singleton _) have SH : ChargeShapeA σ τ := by subst eτ - exact ⟨rfl, rfl, rfl, rfl, ⟨y, n, by rw [hcur]⟩, Or.inl ⟨rfl, rfl, rfl⟩, rdy, ⟨rfl, rfl, rfl, rfl⟩⟩ + exact ⟨rfl, rfl, rfl, rfl, ⟨y, n, by rw [hcur]⟩, Or.inl ⟨rfl, rfl, rfl⟩, rdy, DomKeepA.ofKey rfl⟩ have hc0 : τ.consumedTime = 0 := by rw [eτ] refine ⟨τ, he, J.of_chargeStepA (Q' := Z.Q) (R' := Z.R) Y Fr FR KS SH sysl symL bxi hc0, hc0, ?_, ?_, ?_, ?_⟩ <;> rw [eτ] <;> rfl @@ -471,7 +471,7 @@ theorem JStage3A.clearConsumedRecA have KS : ScChargeKeepA σ τ := ⟨fun q z j hz => ⟨z, hz, rfl, rfl, rfl, rfl, fun _ h => h⟩, fun q y h => h⟩ have SH : ChargeShapeA σ τ := ⟨rfl, rfl, rfl, rfl, ⟨x, k, by rw [J.sr.toSchedSRN.currentScA, updKSc_selfA hk]⟩, Or.inl ⟨rfl, rfl, rfl⟩, fun g => g, - ⟨rfl, rfl, rfl, rfl⟩⟩ + DomKeepA.ofKey rfl⟩ -- A64 P1's invariants across the node word have nd := J.sq.nodes _ J.sq.cur have d40 : layout.node.CONSUMED.val < 4288 := by simp [layout.node.CONSUMED] diff --git a/proofs/Fl4ProofsA64/P3/Stage3PreemptIrqA.lean b/proofs/Fl4ProofsA64/P3/Stage3PreemptIrqA.lean index e9dec261c..d5ad996d3 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3PreemptIrqA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3PreemptIrqA.lean @@ -56,6 +56,14 @@ theorem Sched.BodyOKA.msA {σ : State Unit} {m : McState} (B : BodyOKA σ m) {ms ⟨⟨by unfold ValidMachineTimeA; show σ.curTime ≤ ms.lastMachineTime; rw [h]; exact B.validTime, B.budget, B.ctAct⟩, B.sw, B.scNotIdle, B.owner⟩ +/-- [P] **The interrupt-controller facts the preempted exit and the interrupt entry share** (A64 P4 irqtop): `mask_irq` / +`ack_irq` keep the root relation and step the (trivial) machine relation as the spec's mask / ack (`IrqArchA` at +`MR := True`), and the platform's `maxIRQ` is 5375. One record, passed once: `HPreEnvA.irq` (the preemption poll's +`take_ofA`, `afterPreemptA`) and the interrupt top (`P3/Stage3KEntryIrqTopA`) both take it. -/ +structure IrqEnvA {A : Type} (ar : machine.Arch A) (AR : A → HwRootA → Prop) : Prop where + K : IrqArchA ar AR (fun _ _ => True) + hMax : kernelConfig.maxIRQ = 5375 + /-- [P] **The poll** (module docstring): `take_pending_irq` observes the spec's poll, whose successor changes the machine state only, keeping memory and clock, and the arch relation survives. -/ def PollAgreeA {A : Type} (ar : machine.Arch A) (AR : A → HwRootA → Prop) @@ -112,17 +120,17 @@ theorem take_ofA {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Typ refine pendingIrq_refinesA (Rel := fun s' a' υ => A64RelS3 st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' υ m) ?take ?handle case take => - obtain ⟨Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, eCs, J, B⟩ := R + obtain ⟨m', hg, Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, eCs, J, B⟩ := R refine WP.spec_mono (hpoll r.2 Z.hw τ J.j.1.ar) ?_ rintro r' ⟨τ', mem, ⟨ms, rfl, hm, hl⟩, har, -⟩ - exact ⟨_, mem, Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, eCs, + exact ⟨_, mem, m', hg, Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, eCs, J.of_machA har ms hm, B.msA hl⟩ case handle => intro irq a' τ' e1 hne mem R' - obtain ⟨Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, eCs, J, B⟩ := R' + obtain ⟨m', hg, Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, eCs, J, B⟩ := R' have hres : irq.val < 5376 → (BitVec.ofNat 13 irq.val : Irq) ≠ irqVGICMaintenance ∧ irqVppiEventIndex (BitVec.ofNat 13 irq.val) = none := by - obtain ⟨Z0, H0, OS0, U0, Ac0, Pp0, Tb0, Lv0, ia0, ie0, N0, E0, Rp0, Bf0, stack0, κ0, eCs0, J0, B0⟩ := R + obtain ⟨m0, hg0, Z0, H0, OS0, U0, Ac0, Pp0, Tb0, Lv0, ia0, ie0, N0, E0, Rp0, Bf0, stack0, κ0, eCs0, J0, B0⟩ := R have hq := hpoll r.2 Z0.hw τ J0.j.1.ar rw [e1, WP.spec_ok] at hq exact hq.choose_spec.2.2.2 hne @@ -130,10 +138,10 @@ theorem take_ofA {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Typ have J' := J.arSwapA (AR' := withMRA AR (fun _ _ => True) τ'.machineState) ⟨J.j.1.ar, trivial⟩ refine WP.spec_mono (J'.handleInterruptA hA hPl K (eCs ▸ hCs) h1 hMax hmb hmax htu irq Ln) ?_ rintro r' ⟨σ'', mem2, ⟨Q, Rl, co, cs, J1⟩, sw, bd, hcs⟩ - have B' : BodyOKA σ'' m := + have B' : BodyOKA σ'' m' := ⟨bd B.toBodyExitA, sw B.sw, fun h => by rw [hcs] at h ⊢; exact B.scNotIdle h, fun y k hk _ _ hc o ho => J1.ownerA y k hk hc o ho⟩ - exact ⟨σ'', mem2, { Z with Q := Q, R := Rl, curOf := co, curScOf := cs }, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, + exact ⟨σ'', mem2, m', hg, { Z with Q := Q, R := Rl, curOf := co, curScOf := cs }, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, eCs, J1.arSwapA (AR' := AR) J1.j.1.ar.1, B'⟩ end diff --git a/proofs/Fl4ProofsA64/P3/Stage3PreemptTA.lean b/proofs/Fl4ProofsA64/P3/Stage3PreemptTA.lean index 4de0a1954..9c40a1110 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3PreemptTA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3PreemptTA.lean @@ -142,7 +142,7 @@ theorem update_timestamp_refinesTA {Z : XSetsA} {m : McState} {κ : U64 → U64} H.actOn (H.inv.of_kheap rfl rfl) hcore H.rest.rq H.rest.rqDom H.rest.rel H.run (fun c hc => (keepSC _ (H.scCoreFoot hc).1 (H.scCoreFoot hc).2).trans (H.scCore c hc)) have M : MFrA (st := st) Z m s s2 σ τ := by - refine ⟨w.mono (fun b h => Or.inr (Or.inl ?_)), SKeepA.of_kheap rfl, SSzA.of_kheap rfl⟩ + refine MFrA.ofParts (w.mono (fun b h => Or.inr (Or.inl ?_))) (SKeepA.of_kheap rfl) (SSzA.of_kheap rfl) rcases h with rfl | rfl · exact H.node_sks H.sch.cpuCs (by rw [oT]; decide) · exact H.node_sks H.sch.cpuCs (by rw [oC]; decide) @@ -1112,7 +1112,7 @@ theorem JStage3TA.machineA [J7PpA st J7] [J7PpKA st J7] have kh : σ2.kheap = σ.kheap := by rw [e2] have um : σ2.machineState.underlyingMemory = σ.machineState.underlyingMemory := by rw [e2]; exact hm have H2 : UtCnStepA σ σ2 := - ⟨by rw [e2]; exact ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, + ⟨by rw [e2]; exact SpecGlobA.ofKey rfl, fun q => Or.inl (by rw [kh]), um⟩ have HS : SpecSchedA σ σ2 := { kh := fun q => Or.inl (by rw [kh]) diff --git a/proofs/Fl4ProofsA64/P3/Stage3QKeepPresA.lean b/proofs/Fl4ProofsA64/P3/Stage3QKeepPresA.lean index 5951983aa..c8374e725 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3QKeepPresA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3QKeepPresA.lean @@ -145,7 +145,7 @@ theorem doMachineOp_qA {α : Type} (mop : NonDet MachineState α) : QPresA (doMa subst e3 have e4 : r = (a, { s2 with machineState := ms' }) := hr rw [e4] - exact QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩ + exact QKeepA.of_kheap rfl (DomKeepA.ofKey rfl) /-- What `get_simple_ko` returns. -/ theorem getSimpleKo_memQA {α : Type} [Nonempty α] (C : α → KernelObject) (hC : Function.Injective C) (ptr : ObjRef) @@ -240,7 +240,7 @@ macro "qpres" : tactic => `(tactic| | refine PresR.when ?_ | refine PresR.unless' ?_ | refine PresR.ite' ?_ ?_ - | (refine QPresA.modify_fix _ (fun _ => rfl) (fun _ => ⟨rfl, rfl, rfl, rfl⟩)) + | (refine QPresA.modify_fix _ (fun _ => rfl) (fun _ => DomKeepA.ofKey rfl)) | dsimp only | split)) diff --git a/proofs/Fl4ProofsA64/P3/Stage3RecvBlkSpecA.lean b/proofs/Fl4ProofsA64/P3/Stage3RecvBlkSpecA.lean index ed197d2b2..1f6dc2c32 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3RecvBlkSpecA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3RecvBlkSpecA.lean @@ -215,7 +215,7 @@ theorem RcvStepA.qblk (S : RcvStepA σ σ' t e x xt) {E N : Set ObjRef} (h : Ipc · cases ho; exact ⟨xt, hkt, rfl⟩ · cases ho · exact ⟨y, h0, rfl⟩ - refine ⟨h.of_ins hkt hp back (fun p _ z hz => ?_) (fun p _ z hz => ?_), fun A p y k hy => ?_, fun p y hy => ?_, ⟨by rw [S.frame], by rw [S.frame], by rw [S.frame], by rw [S.frame]⟩⟩ + refine ⟨h.of_ins hkt hp back (fun p _ z hz => ?_) (fun p _ z hz => ?_), fun A p y k hy => ?_, fun p y hy => ?_, DomKeepA.ofKey (by rw [S.frame])⟩ · rcases S.cases hz with ⟨-, ho⟩ | ⟨ep, ho⟩ | ⟨-, -, h0⟩ · cases ho · cases ho diff --git a/proofs/Fl4ProofsA64/P3/Stage3RecvBlkSpecRA.lean b/proofs/Fl4ProofsA64/P3/Stage3RecvBlkSpecRA.lean index bdd1110b4..4815970b8 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3RecvBlkSpecRA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3RecvBlkSpecRA.lean @@ -243,7 +243,7 @@ theorem RcvStepRA.qblkR (S : RcvStepRA σ σ' t e r x xr xt) {E N : Set ObjRef} · cases ho · exact ⟨y, h0, rfl⟩ refine ⟨h.of_ins hkt hp back (fun p _ z hz => ?_) (fun p _ z hz => ?_), fun A p y k hy => ?_, - ⟨by rw [S.frame], by rw [S.frame], by rw [S.frame], by rw [S.frame]⟩⟩ + DomKeepA.ofKey (by rw [S.frame])⟩ · rcases S.cases hz with ⟨-, ho⟩ | ⟨-, ho⟩ | ⟨ep, ho⟩ | ⟨-, -, -, h0⟩ · cases ho · cases ho diff --git a/proofs/Fl4ProofsA64/P3/Stage3RecvSendQA.lean b/proofs/Fl4ProofsA64/P3/Stage3RecvSendQA.lean index 2d927ad0d..b3e33cd1f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3RecvSendQA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3RecvSendQA.lean @@ -126,7 +126,7 @@ theorem recvSend_run_qsA {i : ObjRef} {M N : ObjRef → Prop} {th : TypedHeapA} have Q : QStepA none none σ x.2 := recvSend_run_stepA (i := i) (M := M) (N := N) hPl sf hR hV htr hk hkt hks hal none hst (fun _ _ h _ => absurd rfl h) hcase hMt hMs hNs x hx - refine ⟨Q.prio, Q.ep, Q.ntfn, fun A p y' k hp hr => ?_, fun p y hp => ?_, ⟨by rw [K.frame], by rw [K.frame], by rw [K.frame], by rw [K.frame]⟩⟩ + refine ⟨Q.prio, Q.ep, Q.ntfn, fun A p y' k hp hr => ?_, fun p y hp => ?_, DomKeepA.ofKey (by rw [K.frame])⟩ · obtain ⟨y, k0, hy, a⟩ := Q.sc p y' k hp obtain ⟨y1, hy1, s⟩ := SIKA.scF K hy have rm : y'.scRefillMax = y.scRefillMax := by diff --git a/proofs/Fl4ProofsA64/P3/Stage3RecvWaitA.lean b/proofs/Fl4ProofsA64/P3/Stage3RecvWaitA.lean index eb5fc8934..1caf95a09 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3RecvWaitA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3RecvWaitA.lean @@ -214,7 +214,7 @@ theorem WaitStepA.qblk (S : WaitStepA σ σ' t n x' xt) {E N : Set ObjRef} (h : · cases ho · exact ⟨y, h0, rfl⟩ refine ⟨h.of_ins hkt hp back (fun p _ z hz => ?_) (fun p _ z hz => ?_), fun A p y k hy => ?_, fun p y hy => ?_, - ⟨by rw [S.frame], by rw [S.frame], by rw [S.frame], by rw [S.frame]⟩⟩ + DomKeepA.ofKey (by rw [S.frame])⟩ · rcases S.cases hz with ⟨-, ho⟩ | ⟨-, ho⟩ | ⟨-, -, h0⟩ · cases ho · cases ho diff --git a/proofs/Fl4ProofsA64/P3/Stage3RecvWaitScA.lean b/proofs/Fl4ProofsA64/P3/Stage3RecvWaitScA.lean index 7bf723560..f61337902 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3RecvWaitScA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3RecvWaitScA.lean @@ -541,7 +541,7 @@ theorem RecvPreA.waitBlockScA obtain ⟨y1, h1⟩ := ssz45 q y k h obtain ⟨y2, h2⟩ := ssz q y1 k h1 exact ⟨y2, h2⟩ - have Qp : QKeepA σ' (preschedA σ') := QKeepA.of_kheap kh_p (by rw [epre]; exact ⟨rfl, rfl, rfl, rfl⟩) + have Qp : QKeepA σ' (preschedA σ') := QKeepA.of_kheap kh_p (by rw [epre]; exact DomKeepA.ofKey rfl) have Q45 := Qp.trans (unbWait_qkeepA hNT hkt4 hks4) have Qb04 := B.qblk J.ipcSorted hkt hk (by rw [hyq]; rfl) hq have Qb45 := QSendA.toBlk Qb04.sorted Q45.toSend diff --git a/proofs/Fl4ProofsA64/P3/Stage3RecvWaitUnbA.lean b/proofs/Fl4ProofsA64/P3/Stage3RecvWaitUnbA.lean index e2dd6b1a5..b60d45c9a 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3RecvWaitUnbA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3RecvWaitUnbA.lean @@ -93,7 +93,7 @@ theorem unbWait_qkeepA (hNT : sc ≠ t) (hkt : σ4.kheap t = some (.tcb xt')) (hks : σ4.kheap sc = some (.schedContext xs ns)) : QKeepA σ4 (unbWaitA σ4 t sc xs ns xt') := by refine ⟨fun u y hy => ?_, fun p x' hy => ?_, fun p x' hy => ?_, fun p y' k hy => ?_, fun p y hy => ?_, - ⟨rfl, rfl, rfl, rfl⟩⟩ + DomKeepA.ofKey rfl⟩ · rcases unbWait_casesA hNT hy with ⟨rfl, h⟩ | ⟨rfl, h⟩ | ⟨-, -, h⟩ · cases h; exact ⟨xt', hkt, rfl⟩ · cases h diff --git a/proofs/Fl4ProofsA64/P3/Stage3ReplyErrGlueA.lean b/proofs/Fl4ProofsA64/P3/Stage3ReplyErrGlueA.lean index 3318c1726..95c5e8eb5 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ReplyErrGlueA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ReplyErrGlueA.lean @@ -21,7 +21,7 @@ local notation "wa" => core.num.U64.wrapping_add section variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} -variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} +variable {Ac' : Set U64} {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {ar : machine.Arch A} {nA : U64} {s s' : S} {a : A} {σ σ' : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} {Q : U64 → U64 → List U64} {Rl : U64 → List U64} @@ -35,7 +35,7 @@ theorem JStage3A.of_replyFinA (hz : ∀ x : Fl4SpecA64.Word, UtFreeA st OS s (fun d => d = false) (fl4Ptr x).val → σ'.machineState.underlyingMemory x = σ.machineState.underlyingMemory x) (hcurOf : ∀ k, k ≠ m.curCore → curOf k = Z.curOf k) - (bxi : BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s') + (bxi : BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') (sysl : SysL st H Z.Cs OS ia ie s') (symL : SymL st H Z.Cs s') (userOK : Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s') (j7 : J7A st (J7R2A st ar nA) Z H OS s' σ' m) @@ -49,8 +49,7 @@ theorem JStage3A.of_replyFinA (sinv : SInvXA σ' m n) (sidle : SIdleA σ' m n) (runVcpu : RunVcpuInv st Z.T s') (blkQ : BlkQueuedA Z.T E N (L.mem s') σ') (schedValid : SchedValidA σ') : - JStage3A st AR { Z with Q := Q, R := Rl, curOf := curOf, curScOf := curScOf } H OS U Ac Pp Tb Lv ia ie N E Rp - Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s' a σ' m := by + JStage3A st AR { Z with Q := Q, R := Rl, curOf := curOf, curScOf := curScOf } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s' a σ' m := by have kb : L.ksb s' = L.ksb s := w.1 have bks : ∀ b, (L.ksb s).val ≤ b.val → b.val < (L.ksb s).val + 788736 → ¬ BufW Bf b := fun b h1 h2 hb => by have hksz : ksSizeA = 788736 := rfl @@ -76,7 +75,7 @@ theorem JStage3A.of_replyFinA rw [e, wa_valm]; exact Nat.mod_eq_of_lt (by omega) exact J.asid_offStepNA (by omega) (by omega) · exact J.vsr_offStepNA J.vsOk hb h - have sys : SysInvA st H Z.Cs OS U Ac Pp Tb Lv ia ie s' := + have sys : SysInvA st H Z.Cs OS U Ac' Pp Tb Lv ia ie s' := ⟨⟨J.sys.ent.heap, bxi, J.sys.ent.os, userOK, (utVsPt_keepA J.sys.ent.vs kb vsr).1, by rw [kb]; exact J.sys.ent.ksw⟩, sysl⟩ have sq : SchedQueuesInv st H.tcbs Z.Cs H.omega H s' Q Rl := by @@ -129,7 +128,7 @@ theorem JStage3A.of_replyStepA (hz : ∀ x : Fl4SpecA64.Word, UtFreeA st OS s (fun d => d = false) (fl4Ptr x).val → σ'.machineState.underlyingMemory x = σ.machineState.underlyingMemory x) (hcurOf : ∀ k, k ≠ m.curCore → curOf k = Z.curOf k) - (bxi : BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s') + (bxi : BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') (sysl : SysL st H Z.Cs OS ia ie s') (symL : SymL st H Z.Cs s') (userOK : Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s') (j7 : J7A st (J7R2A st ar nA) Z H OS s' σ' m) @@ -143,8 +142,7 @@ theorem JStage3A.of_replyStepA (sinv : SInvXA σ' m n) (sidle : SIdleA σ' m n) (runVcpu : RunVcpuInv st Z.T s') (blkQ : BlkQueuedA Z.T E N (L.mem s') σ') (schedValid : SchedValidA σ') : - JStage3A st AR { Z with Q := Q, R := Rl, curOf := curOf, curScOf := curScOf } H OS U Ac Pp Tb Lv ia ie N E Rp - Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s' a σ' m := by + JStage3A st AR { Z with Q := Q, R := Rl, curOf := curOf, curScOf := curScOf } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s' a σ' m := by have at_ : ∀ t ∈ Z.T, ∃ x, σ.kheap (specPtr t) = some (.tcb x) := fun t ht => by obtain ⟨x, hx, -⟩ := J.ntfn.tcb t ht exact ⟨x, hx⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3ReplyErrTopA.lean b/proofs/Fl4ProofsA64/P3/Stage3ReplyErrTopA.lean index 9257e70a8..299608b35 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ReplyErrTopA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ReplyErrTopA.lean @@ -328,7 +328,7 @@ theorem _root_.Fl4ProofsA64.P3.JSyscallA.replyErrA (hA : P0.ArchTotal ar) (hPl : have SSz : SSzA σ σ' := fun p y k h => ⟨y, backK p _ h (fun _ e => by cases e)⟩ have Qk : QKeepA σ σ' := by have h := QKeepA.upd (o' := .tcb x') hk (QObjA.ofTcb rfl) - rw [hσ']; exact ⟨h.prio, h.ep, h.ntfn, h.sc, h.rt, ⟨rfl, rfl, rfl, rfl⟩⟩ + rw [hσ']; exact ⟨h.prio, h.ep, h.ntfn, h.sc, h.rt, DomKeepA.ofKey rfl⟩ have K : IpcKeepA σ σ' := ⟨fun p y h => by obtain ⟨y', h', e⟩ := tcbF p y h diff --git a/proofs/Fl4ProofsA64/P3/Stage3ReplyTmoBlkA.lean b/proofs/Fl4ProofsA64/P3/Stage3ReplyTmoBlkA.lean index 69e4a458a..72b030ce1 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ReplyTmoBlkA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ReplyTmoBlkA.lean @@ -179,7 +179,7 @@ theorem JStage3A.replyTmoBlkA have Qf : QKeepA σ4 σf := by rw [eσf, ex1] exact (QKeepA.upd hx4 (QObjA.ofTcb (y := { x with tcbFault := some (.timeout badge.bv) }) rfl)).trans - (QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩) + (QKeepA.of_kheap rfl (DomKeepA.ofKey rfl)) have Qs : QBlkA (specPtr '' E) (specPtr '' N) σ1 τ := by have Q01 : QBlkA (specPtr '' E) (specPtr '' N) σ1 σf := QSendA.toBlk J.ipcSorted (MD.qs.trans Qf.toSend) have hq1 : ∀ a ∈ xe.epQueue, ∃ y, σf.kheap a = some (.tcb y) := fun a ha => by diff --git a/proofs/Fl4ProofsA64/P3/Stage3ReplyTmoRecvA.lean b/proofs/Fl4ProofsA64/P3/Stage3ReplyTmoRecvA.lean index d842d42be..6b99f8887 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ReplyTmoRecvA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ReplyTmoRecvA.lean @@ -369,7 +369,7 @@ theorem JStage3A.replyTmoRecvA have Qf : QKeepA σ4 σf := by rw [eσf, ex1] exact (QKeepA.upd hx4 (QObjA.ofTcb (y := { x with tcbFault := some (.timeout badge.bv) }) rfl)).trans - (QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩) + (QKeepA.of_kheap rfl (DomKeepA.ofKey rfl)) have Qs : QSendA σ1 τ := MD.qs.trans (Qf.toSend.trans Q2) have fault5 : ∀ p, p ≠ specPtr t → ∀ x', σ1.kheap p = some (.tcb x') → ∃ y', τ.kheap p = some (.tcb y') ∧ y'.tcbFault = x'.tcbFault := fun p hp x' hx' => by diff --git a/proofs/Fl4ProofsA64/P3/Stage3RestartA.lean b/proofs/Fl4ProofsA64/P3/Stage3RestartA.lean index 5055c0b6b..9baa6b4a6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3RestartA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3RestartA.lean @@ -34,7 +34,7 @@ theorem QKeepA.of_stUpdA {σ : Fl4SpecA64.State Unit} {t : ObjRef} {x : Tcb} {ts refine ⟨fun p y hy => ?_, fun p y hp => ⟨y, stUpd_back hp (fun _ e => by cases e), List.Sublist.refl _⟩, fun p y hp => ⟨y, stUpd_back hp (fun _ e => by cases e), List.Sublist.refl _⟩, fun p y k hp => ⟨y, k, stUpd_back hp (fun _ e => by cases e), fun r => ⟨r, id⟩⟩, - fun p y hp => ⟨y, stUpd_back hp (fun _ e => by cases e), id⟩, ⟨rfl, rfl, rfl, rfl⟩⟩ + fun p y hp => ⟨y, stUpd_back hp (fun _ e => by cases e), id⟩, DomKeepA.ofKey rfl⟩ by_cases e : p = t · subst e have h2 : (stUpdA σ p x ts).kheap p = some (.tcb { x with tcbState := ts }) := by simp [setObjA] diff --git a/proofs/Fl4ProofsA64/P3/Stage3ScCfgSpecA.lean b/proofs/Fl4ProofsA64/P3/Stage3ScCfgSpecA.lean index d27741311..ccf80e72b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ScCfgSpecA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ScCfgSpecA.lean @@ -738,7 +738,7 @@ theorem cfgResume_walkA {p t : ObjRef} {σ : State Unit} {m : McState} {n : Nat} · rw [e]; exact ActTcbA.ofKh ek (schedulable_actA hs).1 · exact ActTcbA.ofKh ek (V.rls u h) refine ⟨ek, ec, ea.trans ha, Q, fun ne => ⟨Q.rq, fun h1 h2 => ?_, Q.blk, Q.rls⟩, - ⟨by rw [eq], by rw [eq], by rw [eq], by rw [eq]⟩⟩ + DomKeepA.ofKey (by rw [eq])⟩ rw [ea] at h1 rw [ect, ei] at h2 obtain ⟨c1, c2⟩ := V.act h1 h2 @@ -762,7 +762,7 @@ theorem cfgResume_walkA {p t : ObjRef} {σ : State Unit} {m : McState} {n : Nat} refine ⟨R.inv.reschedule hr, ⟨fun d p' u hu => ?_, fun h => ?_, fun u z sc hz hb hs => ?_, fun u hu => ?_⟩, ek2.trans ek, (show r.2.consumedTime = a.2.consumedTime by rw [eq]).trans ec, (show r.2.curSc = a.2.curSc by rw [eq]).trans R.csc, - D1.trans ⟨by rw [eq], by rw [eq], by rw [eq], by rw [eq]⟩⟩ + D1.trans (DomKeepA.ofKey (by rw [eq]))⟩ · obtain ⟨c1, c2⟩ := Q.rq d p' u (noP d p' u hu) exact ⟨ActTcbA.ofKh ek2 c1, by rw [el]; exact c2⟩ · rw [e] at h; cases h @@ -796,7 +796,7 @@ theorem cfgResume_walkA {p t : ObjRef} {σ : State Unit} {m : McState} {n : Nat} have act : ActTcbA a.2 t := ⟨x, p, hx', hxp, y, k, by rw [ek]; exact hk, hact⟩ have F := possibleSwitchTo_fia t a.2 ⟨Sched.SchedValidA.toFIA V2, act⟩ _ hr exact ⟨L2, F.1.toA F.2, ek2.trans ek, ec2.trans ec, cs2.trans R.csc, - D1.trans ⟨by rw [qq.1], by rw [qq.1], by rw [qq.1], by rw [qq.1]⟩⟩ + D1.trans (DomKeepA.ofKey (by rw [qq.1]))⟩ /-! ## The walk -/ @@ -1042,7 +1042,7 @@ theorem cfg_spec_walkA (hmin : fl4MinBudget = MIN_BUDGET) {p : ObjRef} {x : Sche exact ⟨y4, hy4, F2.trans F4, act4, ne4 hne⟩ · have : r.2.consumedTime = u3.2.consumedTime := by rw [s4.rest] rw [this, c3, hcdef] - · exact d3.trans ⟨by rw [s4.rest], by rw [s4.rest], by rw [s4.rest], by rw [s4.rest]⟩ + · exact d3.trans (DomKeepA.ofKey (by rw [s4.rest])) end diff --git a/proofs/Fl4ProofsA64/P3/Stage3ScConsumedA.lean b/proofs/Fl4ProofsA64/P3/Stage3ScConsumedA.lean index dccfe01e2..5de91e277 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ScConsumedA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ScConsumedA.lean @@ -364,8 +364,7 @@ theorem JSyscallA.consumedMidA (hA : P0.ArchTotal ar) have haf := J.sq.inR _ J.sq.cur _ hq exact ((J.sq.released _ (by rw [J.tcbs]; exact htZ)).2 (by rw [haf]; exact hq)) RS.cur.1 -- the reply - have Qb : QKeepA σ1 σu := QKeepA.ofBwd (D := ⟨congrArg (fun z => z.domainIndex) eqσ, - congrArg (fun z => z.domainStartIndex) eqσ, congrArg (fun z => z.domainList) eqσ, congrArg (fun z => z.archState.armUsGlobalVspace) eqσ⟩) fun q o h => by + have Qb : QKeepA σ1 σu := QKeepA.ofBwd (D := DomKeepA.ofKey (congrArg DomKeyA eqσ :)) fun q o h => by rw [← kq] simp only [hσu, updKSc_kheap, Function.update_apply] at h split at h diff --git a/proofs/Fl4ProofsA64/P3/Stage3ScYieldSwA.lean b/proofs/Fl4ProofsA64/P3/Stage3ScYieldSwA.lean index 5eb2b14d4..6d932a8de 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ScYieldSwA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ScYieldSwA.lean @@ -491,8 +491,7 @@ theorem JSyscallA.scYieldSwitchRecA (congrArg (fun z => z.machineState.underlyingMemory) eqq) (congrArg (fun z => z.archState.armCurrentVcpu) eqq) exact PreO.trans e1 (PreO.trans e2 e3) - have Qk : QKeepA σ1 σq := QKeepA.ofBwd (D := ⟨congrArg (fun z => z.domainIndex) eqq, - congrArg (fun z => z.domainStartIndex) eqq, congrArg (fun z => z.domainList) eqq, congrArg (fun z => z.archState.armUsGlobalVspace) eqq⟩) fun q o h => by + have Qk : QKeepA σ1 σq := QKeepA.ofBwd (D := DomKeepA.ofKey (congrArg DomKeyA eqq :)) fun q o h => by rw [kqK] at h split at h · rename_i e diff --git a/proofs/Fl4ProofsA64/P3/Stage3ScopeA.lean b/proofs/Fl4ProofsA64/P3/Stage3ScopeA.lean index 2e780aa9d..a63532db4 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ScopeA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ScopeA.lean @@ -127,7 +127,7 @@ theorem JSyscallA.invocationScopeA [PlainStore st] (hA : P0.ArchTotal ar) (hM : r.1 = (match e with | .ok _ => .Ok () | .error _ => .Err error.Exc.Preempted) ∧ A64RelES3 st AR ar hPl.ipa n Z.Cs e r.2.1 r.2.2 τ m Clock ⦄ := J.invocationA (hCnt := hCnt) hA hM hPl hfm rep calling blocking donate cptr hFault - (J.hScopeA (hCnt := hCnt) hA hM hPl hfm hIP calling blocking donate cptr hArm) hErr (epiP1A hA hPl calling) + (J.hScopeA (hCnt := hCnt) hA hM hPl hfm hIP calling blocking donate cptr hArm) hErr (fun _ => epiP1A hA hPl calling) /-- **Send, NBSend and Call from the syscall-entry record** (module docstring). -/ theorem JSyscallA.sendBodyScopeA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) diff --git a/proofs/Fl4ProofsA64/P3/Stage3ScopeArmsA.lean b/proofs/Fl4ProofsA64/P3/Stage3ScopeArmsA.lean index 933a06e2b..1b6984f13 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ScopeArmsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ScopeArmsA.lean @@ -213,6 +213,33 @@ theorem JSyscallA.ptUnmapS1_scopeA subst hsl exact ⟨_, Or.inl (VsScopeA.ptUnmapS1 (bB := bB) (bC := bC) (bD := bD) (bF := bF) (K := K) (hnvm := Q.nvm) (hTO := hTO) (hEO := hEO) (length := (msgLenA info buf)) (buf := buf) (ex := extra) (cte := sl) (hab := Q.F.pin.habs) (ptr := ptr) (asid := asid) (va := va) (hpS := hpS) (hcap := hcap) (hf := hf) (hS1 := hS1) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hpin := (ptUnmapS1_pinA Q.F J hlab hcap hcan hf hS1)))⟩ +omit hA hM hPl hfm in +/-- **No other slot names a page table whose cap is final**: the finality test read on the slots (the spec's +`is_final_cap'`, `JSyscallA.finPtA`, as `finalHypA` for a key cap). -/ +theorem JSyscallA.finPtOtherA {R : Set U64 → JSlotA S} + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st R) s a σ m) + {sl : CslotPtr} (hab : AbsSlotA Z.th sl) {ptr asid va : U64} + (hcap : capA st s (cslotAddrA sl) = .PageTable ptr true asid va) + (hf : cdt.is_final_capability st s (cslotAddrA sl) = ok true) : + ∀ y ∈ OS, y ≠ cslotAddrA sl → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0 := by + have F := J.finStA + have hfS := J.finPtA hab hcap hf + have hx : cslotAddrA sl ∈ OS := F.sub _ (hab.isSlot F.place) + have hwf : CapWfA (.PageTable ptr true asid va) := hcap ▸ F.wf hx + have hk : RngKeyA (.PageTable ptr true asid va) := (rngKeyA_iffA _).2 rfl + let Q : capability.Cap → Prop := fun d => RngKeyA d ∧ ptrA d = ptrA (.PageTable ptr true asid va) + have habs : isFinalCap' (absCapA (.PageTable ptr true asid va)) σ ↔ + ∀ w ∈ OS, w ≠ cslotAddrA sl → ¬ Q (capA st s w) := by + refine isFinalCap_iffA F hab hcap Q (fun y hy => ?_) ⟨hk, rfl⟩ (fun h => RngKeyA.not_null h.1) + rw [genRefs_keyA hk hwf, overlap_objA (F.wf hy), specPtr_iff] + refine ⟨fun ⟨h, e⟩ => ?_, fun ⟨h, e⟩ => ⟨Or.inl h, e⟩⟩ + rcases h with h | h + · exact ⟨h, e⟩ + · exact absurd (hcap.symm ▸ e.symm : ptrA (capA st s (cslotAddrA sl)) = ptrA (capA st s y)) + (F.fr y hy _ hx h (hcap.symm ▸ hk)) + intro y hy hne mp a0 v0 h + exact (habs.1 hfS y hy hne) ⟨(rngKeyA_iffA _).2 (by rw [h]; rfl), by rw [h]; rfl⟩ + /-- `VsScopeA.ptUnmapX` at the invocation site. -/ theorem JSyscallA.ptUnmapX_scopeA (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) @@ -239,6 +266,38 @@ theorem JSyscallA.ptUnmapX_scopeA subst hsl exact ⟨_, Or.inl (VsScopeA.ptUnmapX (bB := bB) (bC := bC) (bD := bD) (bF := bF) (K := K) (hnvm := Q.nvm) (hTO := hTO) (hEO := hEO) (hIpa := hIpa) (length := (msgLenA info buf)) (buf := buf) (ex := extra) (cte := sl) (hab := Q.F.pin.habs) (ptr := ptr) (asid := asid) (va := va) (hpS := hpS) (hcap := hcap) (hf := hf) (k := k) (hkR := hkR) (hkR1 := hkR1) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hpin := (ptUnmapX_pinA Q.F J hlab hcap hcan hf hkR hkR1)))⟩ +/-- `VsScopeA.ptUnmapT2` at the invocation site: `hno` is the finality test read on the slots. [J] `hUniq`. -/ +theorem JSyscallA.ptUnmapT2_scopeA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (Q : SiteA st Z OS s σ info buf slot extra mi sl c excaps buffer argsU) + (hlab : info.label = fl4_abi.label.ARMPageTableUnmap) + {bB bC bD bF : Bool} + (K : ArchKeepsA ar AR) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) + (hEO : ExtTabOffA (L := L) Z m s) + (hIpa : S2IpaE ar a) + (ptr asid va : U64) + (hpT : ptr ∈ Z.T2) + (hcap : capA st s slot = .PageTable ptr true asid va) + (hf : cdt.is_final_capability st s slot = ok true) + (k : Fl4SpecA64.ExtRootKind) + (hkR : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some k) + (hkR1 : k ≠ .stage1) + (hUniq : ∀ (s2 : S) (a2 : A), + vspace.unmap_page_table st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a asid va ptr = ok (s2, a2) → + ∀ w, S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART)) σ w → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 0 = true → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 1 = true → + dTabA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) = ptr → L.mem s2 w = 0#u64) + -- [J] as `ptUnmapS1` + (hcan : c = absCapA (capA st s slot)) : + ∃ Out, DispScope4A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar s a σ m Clock hPl.ipa info.label + (msgLenA info buf) slot bB bC bD bF buf extra Out := by + rw [hlab] + have hsl := Q.F.pin.hslot + subst hsl + exact ⟨_, Or.inl (VsScopeA.ptUnmapT2 (bB := bB) (bC := bC) (bD := bD) (bF := bF) (K := K) (hnvm := Q.nvm) (hTO := hTO) (hEO := hEO) (hIpa := hIpa) (length := (msgLenA info buf)) (buf := buf) (ex := extra) (cte := sl) (hab := Q.F.pin.habs) (ptr := ptr) (asid := asid) (va := va) (hpT := hpT) (hcap := hcap) (hf := hf) (k := k) (hkR := hkR) (hkR1 := hkR1) (hno := J.finPtOtherA Q.F.pin.habs hcap hf) (hUniq := hUniq) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hpin := (ptUnmapX_pinA Q.F J hlab hcap hcan hf hkR hkR1)))⟩ + /-- `VsScopeA.ptUnmapU` at the invocation site. -/ theorem JSyscallA.ptUnmapU_scopeA (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) @@ -886,6 +945,32 @@ theorem JSyscallA.signalBoundRecv_scopeA rw [hlab] exact ⟨_, Or.inr (Or.inr (Or.inr (Or.inl (IpcScopeA.signalBoundRecv (p := p) (badge := badge) (slot := slot) (lbl := lbl) (len := (msgLenA info buf)) (buf := buf) (recv := recv) (blk := blk) (call := call) (don := don) (fp := fp) (extra := extra) (x := x) (t := t) (e' := e') (xt := xt) (ro := ro) (d := d) (hCs := hCs) (h1 := h1) (hmb := hmb) (hmax := hmax) (htu := htu) (hslot := Q.hOS) (hcov := Q.cov) (hcap := hcap) (hext := Q.hext) (hSC := Q.hSC) (hp := (J.ntfnOfCapA Q.hOS hcap)) (hk := hk) (hidle := hidle) (hb := hb) (hkt := hkt) (hs := hs)))))⟩ +/-- `IpcScopeA.signalRunningVm` at the invocation site. -/ +theorem JSyscallA.signalRunningVm_scopeA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (Q : SiteA st Z OS s σ info buf slot extra mi sl c excaps buffer argsU) + {p badge lbl : U64} + {recv blk call don fp : Bool} + {x : Notification} + {t : ObjRef} + {xt : Tcb} + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) + (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + (hcap : capA st s slot = .Notification p badge true recv) + (hk : σ.kheap (specPtr p) = some (.notification x)) + (hidle : x.ntfnObj = .idleNtfn) + (hb : x.ntfnBoundTcb = some t) + (hkt : σ.kheap t = some (.tcb xt)) + (hs : xt.tcbState = .ext .runningVM) + (hlab : info.label = lbl) : + ∃ Out, DispScope4A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar s a σ m Clock hPl.ipa info.label + (msgLenA info buf) slot blk call don fp buf extra Out := by + rw [hlab] + exact ⟨_, Or.inr (Or.inr (Or.inr (Or.inl (IpcScopeA.signalRunningVm (p := p) (badge := badge) (slot := slot) (lbl := lbl) (len := (msgLenA info buf)) (buf := buf) (recv := recv) (blk := blk) (call := call) (don := don) (fp := fp) (extra := extra) (x := x) (t := t) (xt := xt) (hCs := hCs) (h1 := h1) (hmb := hmb) (hmax := hmax) (htu := htu) (hslot := Q.hOS) (hcov := Q.cov) (hcap := hcap) (hext := Q.hext) (hSC := Q.hSC) (hp := (J.ntfnOfCapA Q.hOS hcap)) (hk := hk) (hidle := hidle) (hb := hb) (hkt := hkt) (hs := hs)))))⟩ + /-- **CNode Copy's arm inputs** at one invocation site: `JSyscallA.cnodeCopy_scopeA`'s hypotheses past `hlab`. -/ structure CnCopyArmA (st : machine.Store S) [L : LawfulStore st] (Z : XSetsA) (OS : Set U64) (n : Nat) (s : S) (σ : State Unit) (m : McState) (buf slot : U64) (info : msginfo.MessageInfo) diff --git a/proofs/Fl4ProofsA64/P3/Stage3SendBlkSpecA.lean b/proofs/Fl4ProofsA64/P3/Stage3SendBlkSpecA.lean index 0cf65ae40..74ee64761 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SendBlkSpecA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SendBlkSpecA.lean @@ -185,7 +185,7 @@ theorem BlkStepA.qblk (S : BlkStepA σ σ' t e x xt pl) {E N : Set ObjRef} (h : · cases ho · exact ⟨y, h0, rfl⟩ refine ⟨h.of_ins hkt hp back (fun p _ z hz => ?_) (fun p _ z hz => ?_), fun A p y k hy => ?_, fun p y hy => ?_, - ⟨congrArg (·.domainIndex) S.frame, congrArg (·.domainStartIndex) S.frame, congrArg (·.domainList) S.frame, congrArg (·.archState.armUsGlobalVspace) S.frame⟩⟩ + DomKeepA.ofKey (congrArg DomKeyA S.frame :)⟩ · rcases S.cases hz with ⟨-, ho⟩ | ⟨ep, ho⟩ | ⟨-, -, h0⟩ · cases ho · cases ho diff --git a/proofs/Fl4ProofsA64/P3/Stage3SendErrAllA.lean b/proofs/Fl4ProofsA64/P3/Stage3SendErrAllA.lean index f65746eb8..08eb47baa 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SendErrAllA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SendErrAllA.lean @@ -67,18 +67,7 @@ theorem _root_.Fl4ProofsA64.P3.JSyscallA.sendBodyErrAllA [PlainStore st] (hA : P (hFI : FinInvA Z.th (L.mem s) σ Z.G) (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) (hD : ∀ u frame fi, capA st s u = .Untyped frame 12#u64 fi false → cdt.ensure_no_children st s u = ok (core.result.Result.Ok ()) → DeadDrop4KA Z H frame fi) - (hPtMap : ∀ (cap : capability.Cap) (lbl ptr : U64) (mp : Bool) (asid va : U64), cap = .PageTable ptr mp asid va → - lbl = fl4_abi.label.ARMPageTableMap → - UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr ∧ ptr ∉ S2PgE Z.X Z.T2 ∧ ptr ∉ Z.Y) - (hFrMap : ∀ (cap : capability.Cap) (lbl fp : U64) (sz : capability.FrameSize) (rt : U64) (dev mp e : Bool) - (asid va : U64), cap = .Frame fp sz rt dev mp e asid va → lbl = fl4_abi.label.ARMPageMap → FrPlA sz fp mp asid) - (hFrSub : ∀ (cap : capability.Cap) (lbl : U64) (cte : CslotPtr) (fp : U64) (sz : capability.FrameSize) (rt : U64) - (dev mp e : Bool) (asid va : U64), cap = .Frame fp sz rt dev mp e asid va → - lbl = fl4_abi.label.ARMPageDeriveSubframe → sz = capability.FrameSize.Large → dev = false → - (fp.val % 2 ^ 21 = 0 ∧ CapRt.Canonical fp) ∧ - ∀ w ∈ Z.G.chains.flatten, ∀ (q vm' : U64), fp.val ≤ q.val → q.val < fp.val + 2 ^ 21 → - OvlA (absCapA (.Frame q .Small vm' false false false 0#u64 0#u64)) (absCapA (capAtA (L.mem s) w)) → - isFrameA (capAtA (L.mem s) w) = true ∧ ∃ ch ∈ Z.G.chains, cslotAddrA cte ∈ ch ∧ w ∈ ch) + (hPtMap : PtMapSiteA st Z H OS σ s) (hFrMap : FrMapSiteA st OS s) (hFrSub : FrSubSiteA st Z OS s) (hAsidAssign : ∀ (cap : capability.Cap) (lbl p base : U64), cap = .AsidPool p base → lbl = fl4_abi.label.ARMASIDPoolAssign → ∀ u ∈ OS, ∀ k root oldAsid oldVa, capA st s u = assignUnmappedA k root oldAsid oldVa → diff --git a/proofs/Fl4ProofsA64/P3/Stage3SendQA.lean b/proofs/Fl4ProofsA64/P3/Stage3SendQA.lean index c75bddaa9..c3f3112b1 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SendQA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SendQA.lean @@ -324,8 +324,7 @@ theorem scActive_of_actTcbA {σ : State Unit} {t : ObjRef} (h : ActTcbA σ t) {x theorem SIKA.domk {i : ObjRef} {M N : ObjRef → Prop} {don : Bool} {σ σ' : State Unit} (K : SIKA i M N don σ σ') : DomKeepA σ σ' := - ⟨congrArg (·.domainIndex) K.frame, congrArg (·.domainStartIndex) K.frame, congrArg (·.domainList) K.frame, - congrArg (·.archState.armUsGlobalVspace) K.frame⟩ + DomKeepA.ofKey (congrArg DomKeyA K.frame :) /-- **Every outcome of `send_ipc` to a waiting receiver is `QSendA`** (module docstring). The receiver's reply object has a caller; a donating send's SC is active. -/ diff --git a/proofs/Fl4ProofsA64/P3/Stage3SignalVmA.lean b/proofs/Fl4ProofsA64/P3/Stage3SignalVmA.lean index 4afc01399..47c6f5d54 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SignalVmA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SignalVmA.lean @@ -192,6 +192,7 @@ theorem JSyscallA.signalRunningVmA sendSignal (Z := Unit) (specPtr p) badge.bv σ1 = ({((), σ2)}, False) ∧ syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don fp buf extra = ok (.Ok (), s2, a) ∧ + (Sched.BodyOKA σ2 m ∧ σ2.curThread = σ.curThread) ∧ ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m := by have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur @@ -257,7 +258,8 @@ theorem JSyscallA.signalRunningVmA have bx := BlkOK.bxi blk' have rv2 : RunVcpuInv st Z.T s2 := J1.tcbs ▸ rvi' obtain ⟨Q, Rl, J2⟩ := J1.of_ntfnQuietA hc hmb hmax htu hp hk1 hnw badge.bv w R2 bx rv2 sysl symL userOK j7 - refine ⟨xc, σ1, _, s2, hkc, rfl, hsp, hspec, hdec, Q, Rl, J2⟩ + refine ⟨xc, σ1, _, s2, hkc, rfl, hsp, hspec, hdec, ?_, Q, Rl, J2⟩ + exact ⟨Sched.BodyOKA.ofKeep J hkc (Sched.BodyKeepA.ofOther _ (specPtr p) (fun _ _ e => by cases e) (fun _ e => by cases e)), rfl⟩ /-- **Notification send, all non-receiving arms (idle + active, including `TS_RUNNING_VM`), at a syscall entry.** -/ theorem JSyscallA.signalNonRecvA @@ -295,8 +297,10 @@ theorem JSyscallA.signalNonRecvA | some t => obtain ⟨y, hy, hrb⟩ := hb t hbt0 by_cases hvm : y.tcbState = .ext .runningVM - · exact J.signalRunningVmA hA hM hPl hfm hc hmb hmax htu hCs h1 hslot hcov hcap hext hSC hp hk - hidle hbt0 hy hvm + · obtain ⟨xc, σ1, σ2, s2, h1', h2', h3', h4', h5', -, h6'⟩ := + J.signalRunningVmA hA hM hPl hfm hc hmb hmax htu hCs h1 hslot hcov hcap hext hSC hp hk + hidle hbt0 hy hvm + exact ⟨xc, σ1, σ2, s2, h1', h2', h3', h4', h5', h6'⟩ · obtain ⟨xc, σ1, σ2, s2, h1', h2', h3', h4', h5', -, h6'⟩ := J.signalQuietA hA hM hPl hfm hc hmb hmax htu (lbl := lbl) (len := len) (buf := buf) (blk := blk) (call := call) (don := don) (fp := fp) hslot hcov hcap hext hSC hp hk diff --git a/proofs/Fl4ProofsA64/P3/Stage3SortA.lean b/proofs/Fl4ProofsA64/P3/Stage3SortA.lean index 2f4c55d47..de6b0aa7b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SortA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SortA.lean @@ -70,10 +70,26 @@ structure DomKeepA (σ σ' : State Unit) : Prop where /-- (record edit F4, `NdOKA.kroot`) The global user VSpace root is kept: no spec step assigns `armUsGlobalVspace`. -/ gvs : σ'.archState.armUsGlobalVspace = σ.archState.armUsGlobalVspace -theorem DomKeepA.refl (σ : State Unit) : DomKeepA σ σ := ⟨rfl, rfl, rfl, rfl⟩ +/-- **The key of `DomKeepA`**: the kept components as one tuple. Adding a kept component means editing this tuple, +`DomKeepA.ofKey` and `DomKeepA.key` (and the structure) here, and nothing at the construction sites +(record-extension convention, `AGENTS.md`, "Proof records"). An `abbrev` on purpose: the kernel then unfolds it at once +instead of first comparing the (large) state arguments of two `DomKeyA` applications. -/ +abbrev DomKeyA (σ : State Unit) := + (σ.domainIndex, σ.domainStartIndex, σ.domainList, σ.archState.armUsGlobalVspace) + +/-- The one constructor of `DomKeepA` to use at call sites: `ofKey rfl`, `ofKey (by rw [e])`, `ofKey (congrArg DomKeyA e)`. -/ +theorem DomKeepA.ofKey {σ σ' : State Unit} (h : DomKeyA σ' = DomKeyA σ) : DomKeepA σ σ' := by + simp only [DomKeyA, Prod.mk.injEq] at h + exact ⟨h.1, h.2.1, h.2.2.1, h.2.2.2⟩ + +theorem DomKeepA.key {σ σ' : State Unit} (h : DomKeepA σ σ') : DomKeyA σ' = DomKeyA σ := by + unfold DomKeyA + rw [h.index, h.start, h.table, h.gvs] + +theorem DomKeepA.refl (σ : State Unit) : DomKeepA σ σ := DomKeepA.ofKey rfl theorem DomKeepA.trans {σ1 σ2 σ3 : State Unit} (h1 : DomKeepA σ1 σ2) (h2 : DomKeepA σ2 σ3) : DomKeepA σ1 σ3 := - ⟨h2.index.trans h1.index, h2.start.trans h1.start, h2.table.trans h1.table, h2.gvs.trans h1.gvs⟩ + DomKeepA.ofKey (h2.key.trans h1.key) /-- **What a step must show for the record's two queue invariants** (`IpcSortedA`, `ActRepA`): TCB priorities kept, endpoint and notification queues shrunk to sublists, SC reply stacks not grown and SC activity kept; for @@ -219,7 +235,7 @@ theorem QKeepA.upd {σ : State Unit} {p : ObjRef} {o o' : KernelObject} (h : σ. by_cases hq : q = p · subst hq; rw [Function.update_self] at e; exact Or.inl ⟨rfl, (Option.some.inj e).symm⟩ · rw [Function.update_of_ne hq] at e; exact Or.inr ⟨hq, e⟩ - refine ⟨fun q y e => ?_, fun q y e => ?_, fun q y e => ?_, fun q y k e => ?_, fun q y e => ?_, ⟨rfl, rfl, rfl, rfl⟩⟩ + refine ⟨fun q y e => ?_, fun q y e => ?_, fun q y e => ?_, fun q y k e => ?_, fun q y e => ?_, DomKeepA.ofKey rfl⟩ · rcases key q _ e with ⟨rfl, ho⟩ | ⟨-, e'⟩ · obtain ⟨x, hx, k⟩ := R.prio y ho.symm; exact ⟨x, by rw [h, hx], k⟩ · exact ⟨y, e', rfl⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3SuspOffQA.lean b/proofs/Fl4ProofsA64/P3/Stage3SuspOffQA.lean new file mode 100644 index 000000000..3737dd1d0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3SuspOffQA.lean @@ -0,0 +1,159 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregr): **`suspend` keeps `OffQ0A c`** (`c` in no ready or release queue and not the +pending switch target: `OffQA` of `Stage3NBSignalWakeA`, restated here because that module is downstream of the TCB +dispatch) for every `c`: `cancel_ipc`, the restart-pc write, the dequeue, the release-queue removal, the yield cancel and +`set_thread_state Inactive` only remove queue members. Used for the caller at the mid state of a ReadRegisters / +CopyRegisters with the suspension bit. + +Named premises: none. New module. +-/ +import Fl4ProofsA64.P3.Stage3DelSvSuspendA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Sched +open Fl4SpecA64 Fl4Spec Fl4ProofsA64.P3 Fl4ProofsA64.P3.Notif Classical + +noncomputable section + +/-- `c` is in no ready or release queue and is not the pending switch target. -/ +def OffQ0A (c : ObjRef) (σ : State Unit) : Prop := + (∀ d p, c ∉ σ.readyQueues d p) ∧ c ∉ σ.releaseQueue ∧ ∀ u, σ.schedulerAction = .switchThread u → u ≠ c + +theorem OffQ0A.congr {c : ObjRef} {σ σ' : State Unit} (h : OffQ0A c σ) (hq : σ'.readyQueues = σ.readyQueues) + (hr : σ'.releaseQueue = σ.releaseQueue) (ha : σ'.schedulerAction = σ.schedulerAction) : OffQ0A c σ' := + ⟨fun d p => by rw [hq]; exact h.1 d p, by rw [hr]; exact h.2.1, fun u e => h.2.2 u (ha ▸ e)⟩ + +theorem OffQ0A.tkeep {c : ObjRef} {σ σ' : State Unit} (k : TKeepA σ σ') (h : OffQ0A c σ) : OffQ0A c σ' := by + obtain ⟨-, er, eq, -, ea, -⟩ := k + exact h.congr eq er ea + +theorem HT.off0T {α : Type} {m : SMonad Unit α} (h : TPres m) (c : ObjRef) : HT (OffQ0A c) m (fun _ => OffQ0A c) := + fun σ hσ r hr => hσ.tkeep (h σ r hr) + +theorem threadSet_off0 (c d : ObjRef) (f : Tcb → Tcb) : + HT (OffQ0A c) (threadSet (Z := Unit) f d) (fun _ => OffQ0A c) := + fun σ hσ r hr => by + obtain ⟨x, -, e⟩ := threadSet_spec hr + rw [e] + exact hσ.congr rfl rfl rfl + +theorem setThreadState_off0 (c d : ObjRef) (ts : ThreadState) : + HT (OffQ0A c) (setThreadState (Z := Unit) d ts) (fun _ => OffQ0A c) := by + unfold setThreadState setThreadStateAct + refine HT.bind (Q := fun _ => OffQ0A c) (threadSet_off0 c d _) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.gets _ fun σ h => h) fun cur => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.gets _ fun σ h => h) fun act => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.gets _ fun σ h => h) fun sch => ?_ + refine HT.when (fun _ => ?_) (fun _ σ h => h) + unfold setSchedulerAction + refine HT.modify _ fun σ h => ⟨h.1, h.2.1, fun u e => ?_⟩ + cases e + +theorem replyUnlinkTcb_off0 (c d r : ObjRef) : + HT (OffQ0A c) (replyUnlinkTcb (Z := Unit) d r) (fun _ => OffQ0A c) := by + unfold replyUnlinkTcb + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + exact setThreadState_off0 c d _ + +theorem replyRemoveTcb_off0 (c t r : ObjRef) : + HT (OffQ0A c) (replyRemoveTcb (Z := Unit) t r) (fun _ => OffQ0A c) := by + unfold replyRemoveTcb + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.gets _ fun _ h => h) fun o => ?_ + cases o with + | none => exact replyUnlinkTcb_off0 c t r + | some sc => + dsimp only + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun _ => ?_ + exact replyUnlinkTcb_off0 c t r + +/-- A dequeue only removes ready-queue members. -/ +theorem dequeue_off0 (c t : ObjRef) : + HT (OffQ0A c) (tcbSchedAction (Z := Unit) tcbSchedDequeue t) (fun _ => OffQ0A c) := by + unfold Fl4SpecA64.tcbSchedAction + refine HT.bind (Q := fun _ => OffQ0A c) (HT.threadGet _ t fun _ h _ _ => h) fun d => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.threadGet _ t fun _ h _ _ => h) fun p => ?_ + unfold Fl4SpecA64.getTcbQueue + refine HT.bind (Q := fun q σ => OffQ0A c σ ∧ q = σ.readyQueues d p) + (HT.bind (Q := fun qs σ => OffQ0A c σ ∧ qs = σ.readyQueues) (HT.gets _ fun _ h => ⟨h, rfl⟩) fun qs => + HT.pure _ fun σ h => ⟨h.1, by rw [h.2]⟩) fun queue => ?_ + refine HT.bind (Q := fun q' σ => (OffQ0A c σ ∧ queue = σ.readyQueues d p) ∧ q' = tcbSchedDequeue t queue) + (HT.pure _ fun _ h => ⟨h, rfl⟩) fun queue' => ?_ + unfold Fl4SpecA64.setTcbQueue + refine HT.modify _ fun σ h => ?_ + obtain ⟨⟨hI, hq⟩, hq'⟩ := h + refine ⟨fun d' p' hm => ?_, hI.2.1, hI.2.2⟩ + by_cases e : d' = d ∧ p' = p + · simp only [if_pos e] at hm + rw [hq'] at hm + have h1 := (List.mem_filter.1 hm).1 + rw [hq, ← e.1, ← e.2] at h1 + exact hI.1 d' p' h1 + · simp only [if_neg e] at hm + exact hI.1 d' p' hm + +/-- The release-queue removal only removes release-queue members. -/ +theorem relRemove_off0 (c t : ObjRef) : + HT (OffQ0A c) (tcbReleaseRemove (Z := Unit) t) (fun _ => OffQ0A c) := by + unfold Fl4SpecA64.tcbReleaseRemove + refine HT.bind (Q := fun qs σ => OffQ0A c σ ∧ qs = σ.releaseQueue) (HT.gets _ fun σ hσ => ⟨hσ, rfl⟩) fun qs => ?_ + refine HT.bind (Q := fun _ σ => OffQ0A c σ ∧ qs = σ.releaseQueue) + (HT.when (fun _ => HT.modify _ fun σ hσ => ⟨⟨hσ.1.1, hσ.1.2.1, hσ.1.2.2⟩, hσ.2⟩) (fun _ σ hσ => hσ)) fun _ => ?_ + refine HT.bind (Q := fun qs' σ => OffQ0A c σ ∧ qs = σ.releaseQueue ∧ qs' = tcbSchedDequeue t qs) + (HT.pure _ fun σ hσ => ⟨hσ.1, hσ.2, rfl⟩) fun qs' => ?_ + refine HT.modify _ fun σ hσ => ?_ + obtain ⟨hI, hq, hq'⟩ := hσ + refine ⟨hI.1, fun hm => ?_, hI.2.2⟩ + have h2 : c ∈ qs' := hm + rw [hq'] at h2 + exact hI.2.1 (hq ▸ (List.mem_filter.1 h2).1) + +theorem blockedCancelIpc_off0 (c : ObjRef) (st : ThreadState) (t : ObjRef) (ro : Option ObjRef) : + HT (OffQ0A c) (blockedCancelIpc (Z := Unit) st t ro) (fun _ => OffQ0A c) := by + unfold blockedCancelIpc getBlockingObject + refine HT.bind (Q := fun _ => OffQ0A c) (HT.assertOpt _ fun _ _ _ h => h) fun ep => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by unfold tcbEpDequeue; tpres) c) fun _ => ?_ + cases ro with + | none => exact setThreadState_off0 c t _ + | some r => exact HT.bind (Q := fun _ => OffQ0A c) (replyUnlinkTcb_off0 c t r) fun _ => setThreadState_off0 c t _ + +/-- **`cancel_ipc` keeps `OffQ0A c`**, every arm. -/ +theorem cancelIpc_off0 (c t : ObjRef) : HT (OffQ0A c) (cancelIpc (Z := Unit) t) (fun _ => OffQ0A c) := by + unfold cancelIpc + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun st => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (threadSet_off0 c t _) fun _ => ?_ + cases st with + | blockedOnSend _ _ => exact blockedCancelIpc_off0 c _ t _ + | blockedOnReceive _ _ _ => exact blockedCancelIpc_off0 c _ t _ + | blockedOnNotification e => + dsimp only + unfold cancelSignal + exact HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by unfold tcbNtfnDequeue; tpres) c) fun _ => + setThreadState_off0 c t _ + | blockedOnReply r => exact replyRemoveTcb_off0 c t r + | _ => exact HT.pure _ fun _ h => h + +/-- **`suspend` keeps `OffQ0A c`.** -/ +theorem suspend_off0 (c t : ObjRef) : HT (OffQ0A c) (Fl4SpecA64.suspend (Z := Unit) t) (fun _ => OffQ0A c) := by + unfold Fl4SpecA64.suspend + refine HT.bind (Q := fun _ => OffQ0A c) (cancelIpc_off0 c t) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by tpres) c) fun st => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (HT.off0T (by unfold updateRestartPc; tpres) c) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (dequeue_off0 c t) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) (relRemove_off0 c t) fun _ => ?_ + refine HT.bind (Q := fun _ => OffQ0A c) + (HT.off0T (by unfold schedContextCancelYieldTo NonDet.maybeM; tpres) c) fun _ => ?_ + exact setThreadState_off0 c t _ + +end + +end Fl4ProofsA64.P3.Sched diff --git a/proofs/Fl4ProofsA64/P3/Stage3SysCombA.lean b/proofs/Fl4ProofsA64/P3/Stage3SysCombA.lean index 882dae965..64d8e74a0 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SysCombA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SysCombA.lean @@ -124,7 +124,7 @@ theorem kernelEntryComb_recGA [PlainStore st] (hM : MaxSpi ar) (hPl : ArchPlat a CombScopeA st ar OS N E Rp Z.T rep call sb ab τ) (hGap : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → - A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → SchedGapFreeA st m s' a' τ ar tm view) + ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view) (hNat : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → ∀ τ1 τ2, diff --git a/proofs/Fl4ProofsA64/P3/Stage3SysFrontA.lean b/proofs/Fl4ProofsA64/P3/Stage3SysFrontA.lean index 34edb9db6..fce02b122 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SysFrontA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SysFrontA.lean @@ -287,7 +287,7 @@ theorem syscallFront_refinesA {Fin : S → A → State Unit → Prop} rw [hq, e] rw [hset, bind_ok] have budget := JSyscallA.budgetOkSysA I2.J I2.hvp I2.P I2.hClock I2.hnd I2.C I2.hC I2.hNow I2.hAr I2.hmb - (fun s1 a1 σ1 e J1 En V CI R Act Cl suf => hCharge Q1 R1 _ pc I2.J s1 a1 σ1 e J1 En V CI R Act Cl suf) + (fun s1 a1 σ1 hu e J1 En V CI R Act Cl suf => hCharge Q1 R1 _ pc I2.J s1 a1 σ1 hu e J1 En V CI R Act Cl suf) obtain ⟨⟨b, sb, ab⟩, eb, τ, e1, Jq, tr⟩ := spec_existsA budget rw [eb, bind_ok] simp only [uncurry_apply_pair] diff --git a/proofs/Fl4ProofsA64/P3/Stage3SysRecvA.lean b/proofs/Fl4ProofsA64/P3/Stage3SysRecvA.lean index c2c2124f5..a314b9d38 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SysRecvA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SysRecvA.lean @@ -90,7 +90,7 @@ theorem kernelEntryRecv_recGA (hPl : ArchPlat ar) (Env : FaultEnvA st ar Z) RecvScopeA st OS N E Rp Z.T sb τ blocking canReply) (hGap : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → - A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → SchedGapFreeA st m s' a' τ ar tm view) + ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view) (hNat : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → ∀ τ1 τ2, diff --git a/proofs/Fl4ProofsA64/P3/Stage3SysSendA.lean b/proofs/Fl4ProofsA64/P3/Stage3SysSendA.lean index cd6d77db6..2396521e3 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SysSendA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SysSendA.lean @@ -151,7 +151,7 @@ theorem kernelEntrySend_recGA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSp fl4A64Platform.numNodes sb ab τ m Clock hPl rep (maybeHandleInterrupt true) call) (hGap : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → - A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → SchedGapFreeA st m s' a' τ ar tm view) + ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view) (hNat : ∀ s' a' τ, kBodyA st ar s a (.syscall number rep call) = ok (s', a') → ((), τ) ∈ (kOpA (.syscall number rep call) σ).1 → A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Z.Cs s' a' τ m → ∀ τ1 τ2, diff --git a/proofs/Fl4ProofsA64/P3/Stage3SysTopA.lean b/proofs/Fl4ProofsA64/P3/Stage3SysTopA.lean index bdda615d9..0015e457c 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SysTopA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SysTopA.lean @@ -62,19 +62,22 @@ set_option maxHeartbeats 2000000 in /-- **`syscall.finish` from a record at some ghost sets** (module docstring): `FaultRelA.finishA` for `A64RelS3`. -/ theorem A64RelS3.finishA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (arch : ArchSwFA st ar) (hCs : ∀ c ∈ Cs, c.val < fl4A64Platform.numNodes) (P : FinPlatA ar AR') - (G : SchedGapFreeA st m s a σ ar tm view) + (G : ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s a σ m m' → SchedGapFreeA st m' s a σ ar tm view) (hNat : ∀ τ1 τ2, ((), τ1) ∈ (fl4Schedule kLimitA view σ).1 → ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → ∀ y, τ2.kheap τ2.curThread = some (.tcb y) → y.tcbState ≠ .ext .runningVM) (R : A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s a σ m) : syscall.finish st ar s a ⦃ r => StepPostA (KExitA st ar AR' hPl.ipa m) (fl4Finish kLimitA view) σ r ⦄ := by - obtain ⟨Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, hZ, J, B⟩ := R + obtain ⟨m', hg, Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, hZ, J, B⟩ := R + have G' := G m' ⟨hg, Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, hZ, J, B⟩ have hCs' : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes := fun c hc => hCs c (hZ ▸ hc) have hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = MIN_BUDGET ⦄ := fun a => - WP.spec_mono (G.ticks a).minBudget fun _ h => h.trans G.minAgree - exact JStage3A.finishEA hA hPl arch hCs' P.h1 J B.sw B.toBodyExitA + WP.spec_mono (G'.ticks a).minBudget fun _ h => h.trans G'.minAgree + refine WP.spec_mono (JStage3A.finishEA hA hPl arch hCs' P.h1 J B.sw B.toBodyExitA (JStage3A.fireSigA hA hPl hCs' P.h1 hmb P.hmax P.htu) - (G.toGap Z κ) P.arK P.toUs hNat + (G'.toGap Z κ) P.arK P.toUs hNat) ?_ + rintro r ⟨τ, hm, k⟩ + exact ⟨τ, hm, KExitA.ofAt st ar hg k⟩ /-- **The unified kernel-entry top for entries whose body changes the ghost sets** (module docstring). @@ -89,7 +92,7 @@ theorem kernelEntry_recGA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (arch : Arc (hbody : kBodyA st ar s a e ⦃ r => StepPostA (fun s' a' τ => A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m) (kOpA e) σ r ⦄) (hGap : ∀ s' a' τ, kBodyA st ar s a e = ok (s', a') → ((), τ) ∈ (kOpA e σ).1 → - A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → SchedGapFreeA st m s' a' τ ar tm view) + ∀ m', A64RelS3at st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view) (hNat : ∀ s' a' τ, kBodyA st ar s a e = ok (s', a') → ((), τ) ∈ (kOpA e σ).1 → A64RelS3 st AR' ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → ∀ τ1 τ2, ((), τ1) ∈ (fl4Schedule kLimitA view τ).1 → ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → @@ -97,7 +100,7 @@ theorem kernelEntry_recGA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (arch : Arc kCodeA st ar s a e ⦃ out => StepPostA (KExitA st ar AR' hPl.ipa m) (kOpA e >>= fun _ => fl4Finish kLimitA view) σ out ⦄ := kernelEntry_stage3A s a σ e run hbody fun r τ eb op RB => - A64RelS3.finishA hA hPl arch hCs P (hGap r.1 r.2 τ eb op RB) (hNat r.1 r.2 τ eb op RB) RB + A64RelS3.finishA hA hPl arch hCs P (hGap r.1 r.2 τ eb op) (hNat r.1 r.2 τ eb op RB) RB end diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmPtHiA.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmPtHiA.lean new file mode 100644 index 000000000..a5850b8b6 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmPtHiA.lean @@ -0,0 +1,106 @@ +/- +P3 (aarch64, Stage 4, line vsx-B, CP B1): **the high-window page-table map at a syscall entry** (`Stage3T3ArmsA`'s +twin of `Stage3T3ArmHiA`): `decPt_hiA` (`decode_page_table` with a `HighVSpace` extra cap is `map_high_page_table`) and +`JSyscallA.ptMapHiA`, whose final-state facts come from `decodeFinA`. + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`; the arm's; `hinv` (decode site). +-/ +import Fl4ProofsA64.P3.Stage3BodyKeepA +import Fl4ProofsA64.P3.Stage3ArmPtMapHiA +import Fl4ProofsA64.P3.Stage3T3DecEqA +import Fl4ProofsA64.P3.Stage3FinA +import Fl4ProofsA64.P3.Stage3RsSiteA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +/-- **A page-table map with a `HighVSpace` extra cap** is `map_high_page_table`. -/ +theorem decPt_hiA {ar : machine.Arch A} {s : S} {a : A} {length slot buf x0 vaddr ptr asid va p1 asid1 : U64} + {mp1 : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hx : vspace.extra extra 0#usize = ok (some x0)) (hlen : length ≥ 2#u64) + (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + (hc : obj.Slot.cap st x0 s = ok (.HighVSpace p1 mp1 asid1)) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableMap length slot (.PageTable ptr false asid va) + buf extra = + (do let (r, s1) ← vspace.map_high_page_table st s slot ptr (.HighVSpace p1 mp1 asid1) vaddr + ok (r, s1, a)) := by + have hne : ¬ fl4_abi.label.ARMPageTableMap = fl4_abi.label.ARMPageTableUnmap := by + unfold fl4_abi.label.ARMPageTableMap fl4_abi.label.ARMPageTableUnmap; decide + unfold vspace.decode_page_table + simp only [cur_thread_ok, bind_ok, hne, ↓reduceIte, bne_self_eq_false, Bool.false_eq_true, hx, if_pos hlen, h0, + hc] + +set_option maxHeartbeats 4000000 in +/-- **Page-table map into a high window**, at a syscall entry. -/ +theorem JSyscallA.ptMapHiA + {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} + {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} + {s s3 : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + {ptr asid0 va0 : U64} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) + (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr false asid0 va0) + (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (hS2 : ptr ∉ S2PgE Z.X Z.T2) (hY : ptr ∉ Z.Y) + (length buf : U64) (extra : Aeneas.Std.Array obj.Slot 3#usize) (x0 : U64) + (hx : vspace.extra extra 0#usize = ok (some x0)) (hlen : length ≥ 2#u64) + (p1 asid1 : U64) (mp1 : Bool) (h16 : asid1.val < 2 ^ 16) (hx0c : capA st s x0 = .HighVSpace p1 mp1 asid1) + (vaddr : U64) (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeHighPageTableMap (Z := Unit) cte (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .high (specPtr p1) (asidDataA mp1 asid1)) vaddr.bv)).run σ) + (hres : vspace.map_high_page_table st s (cslotAddrA cte) ptr (.HighVSpace p1 mp1 asid1) vaddr = + ok (core.result.Result.Ok (), s3)) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) : + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) + (Ac' Tb' : Set U64) (Lv' : U64 → Nat) (nL : Nat), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with S1 := insert ptr Z.S1, Lv := Function.update Z.Lv ptr nL } H OS U Ac' Pp Tb' Lv' ia ie N E + Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + have hslot : (cslotAddrA cte) ∈ OS := J.j5.2.1 _ (hab.isSlot J.j.1.place) + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have D' : ∀ {bB bC bD bF : Bool} {len buf' : U64} {rX : core.result.Result Unit error.Exc} {sX : S} {aX : A}, + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableMap len (cslotAddrA cte) + (.PageTable ptr false asid0 va0) bB bC bD bF buf' extra = ok (rX, sX, aX) → + ∀ σX : Fl4SpecA64.State Unit, ∃ Ac' : Set U64, SysL st H Z.Cs OS ia ie sX ∧ SymL st H Z.Cs sX ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' sX ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U sX ∧ + J7A st (J7R2A st ar hPl.ipa) Z H OS sX σX m := fun hd σX => + (J.decodeFinA hA hM hPl hfm hslot hcov ((capAtA_eq (st := st) _ _).symm.trans hcap) hext hSC + (lbl := fl4_abi.label.ARMPageTableMap) (by simp [DecArmS1aEnt, DecArmQH]) + (fun _ h => by cases h) (fun _ h => by cases h) hd σX m).2 + have hinv : syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableMap length (cslotAddrA cte) + (.PageTable ptr false asid0 va0) false false false false buf extra = ok (core.result.Result.Ok (), s3, a) := by + rw [decInv_ptA ar s a _ length _ ptr false asid0 va0 false false false false buf extra, + decPt_hiA hx hlen h0 (by rw [capA_eq, hx0c]), hres] + first | (simp only [bind_ok]; done) | (simp only [bind_ok]; rfl) | simp [bind_ok] + exact JStage3A.ptMapHiA (ar := ar) (nA := hPl.ipa) (J := J.toJStage3A) (RS := RS) (hnvm := hnvm) (hTO := hTO) + (hEO := hEO) (hK := J.toJStage3A.ksbAligned) (hT := J.toJStage3A.offAsE) (cte := cte) (hab := hab) + (hcap := hcap) (UP := UP) (hS2 := hS2) (hY := hY) (vp := p1) (vasid := asid1) (vaddr := vaddr) (vmp := mp1) + (hvwf := h16) (hD := hD) (hres := hres) + (fin := fun _ _ σ3 _ _ _ => D' hinv σ3) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmPtS2A.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmPtS2A.lean new file mode 100644 index 000000000..0b71860df --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmPtS2A.lean @@ -0,0 +1,105 @@ +/- +P3 (aarch64, Stage 4, line vsx-B, CP B2): **the Stage-2 page-table map at a syscall entry** (`Stage3T3ArmPtHiA`'s +twin): `decPt_s2A` (`decode_page_table` with an `Ept` extra cap is `ept::map_table`) and `JSyscallA.ptMapS2A`, whose +final-state facts come from `decodeFinA`. + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `S2IpaE`, `hIpa47`; the arm's; `hinv` (decode site). +-/ +import Fl4ProofsA64.P3.Stage3BodyKeepA +import Fl4ProofsA64.P3.Stage3ArmPtMapS2A +import Fl4ProofsA64.P3.Stage3T3ArmPtHiA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +/-- **A page-table map with an `Ept` extra cap** is `ept::map_table`. -/ +theorem decPt_s2A {ar : machine.Arch A} {s : S} {a : A} {length slot buf x0 vaddr ptr asid va vp vasid vva : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hx : vspace.extra extra 0#usize = ok (some x0)) (hlen : length ≥ 2#u64) + (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + (hc : obj.Slot.cap st x0 s = ok (.Ept vp 0#u64 true vasid vva)) + (hrt : ept.root st s (.Ept vp 0#u64 true vasid vva) 1#u64 = ok (core.result.Result.Ok (vp, vasid))) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableMap length slot (.PageTable ptr false asid va) + buf extra = ept.map_table st ar s a vp vasid vaddr ptr slot := by + have hne : ¬ fl4_abi.label.ARMPageTableMap = fl4_abi.label.ARMPageTableUnmap := by + unfold fl4_abi.label.ARMPageTableMap fl4_abi.label.ARMPageTableUnmap; decide + unfold vspace.decode_page_table + simp only [cur_thread_ok, bind_ok, hne, ↓reduceIte, bne_self_eq_false, Bool.false_eq_true, hx, if_pos hlen, h0, + hc, show vspace.is_valid_vtable_root (.Ept vp 0#u64 true vasid vva) = ok true from rfl, hrt, + core.result.Result.Insts.CoreOpsTry.branch] + rfl + +set_option maxHeartbeats 4000000 in +/-- **Page-table map into a Stage-2 root**, at a syscall entry. -/ +theorem JSyscallA.ptMapS2A + {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} + {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} + {s s3 : S} {a a3 : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + {ptr asid0 va0 : U64} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) + (hIpa : S2IpaE ar a) (hIpa47 : s2IpaLimit.toNat < 2 ^ 47) + (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr false asid0 va0) + (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (hS2 : ptr ∉ S2PgE Z.X Z.T2) (hY : ptr ∉ Z.Y) + (length buf : U64) (extra : Aeneas.Std.Array obj.Slot 3#usize) (x0 : U64) + (hx : vspace.extra extra 0#usize = ok (some x0)) (hlen : length ≥ 2#u64) + (vp vasid vva : U64) (ha16 : vasid.val < 65536) (hx0c : capA st s x0 = .Ept vp 0#u64 true vasid vva) + (vaddr : U64) (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageTableMap (Z := Unit) cte (.pageTableCap (specPtr ptr) .normalPtT none) + (extRootCapA .stage2 (specPtr vp) (asidDataA true vasid)) vaddr.bv)).run σ) + (hrt : ept.root st s (.Ept vp 0#u64 true vasid vva) 1#u64 = ok (core.result.Result.Ok (vp, vasid))) + (hres : ept.map_table st ar s a vp vasid vaddr ptr (cslotAddrA cte) = ok (core.result.Result.Ok (), s3, a3)) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) : + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) + (Ac' Tb' : Set U64) (Lv' : U64 → Nat) (nS : Nat), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with T2 := insert ptr Z.T2, Sh2 := Function.update Z.Sh2 ptr nS } H OS U Ac' Pp Tb' Lv' ia ie N E + Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s3 a3 σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + have hslot : (cslotAddrA cte) ∈ OS := J.j5.2.1 _ (hab.isSlot J.j.1.place) + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have D' : ∀ {bB bC bD bF : Bool} {len buf' : U64} {rX : core.result.Result Unit error.Exc} {sX : S} {aX : A}, + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableMap len (cslotAddrA cte) + (.PageTable ptr false asid0 va0) bB bC bD bF buf' extra = ok (rX, sX, aX) → + ∀ σX : Fl4SpecA64.State Unit, ∃ Ac' : Set U64, SysL st H Z.Cs OS ia ie sX ∧ SymL st H Z.Cs sX ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' sX ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U sX ∧ + J7A st (J7R2A st ar hPl.ipa) Z H OS sX σX m := fun hd σX => + (J.decodeFinA hA hM hPl hfm hslot hcov ((capAtA_eq (st := st) _ _).symm.trans hcap) hext hSC + (lbl := fl4_abi.label.ARMPageTableMap) (by simp [DecArmS1aEnt, DecArmQH]) + (fun _ h => by cases h) (fun _ h => by cases h) hd σX m).2 + have hinv : syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableMap length (cslotAddrA cte) + (.PageTable ptr false asid0 va0) false false false false buf extra = ok (core.result.Result.Ok (), s3, a3) := by + rw [decInv_ptA ar s a _ length _ ptr false asid0 va0 false false false false buf extra, + decPt_s2A hx hlen h0 (by rw [capA_eq, hx0c]) hrt, hres] + exact JStage3A.ptMapS2A (ar := ar) (nA := hPl.ipa) (J := J.toJStage3A) (RS := RS) (hnvm := hnvm) (hTO := hTO) + (hEO := hEO) (hK := J.toJStage3A.ksbAligned) (hT := J.toJStage3A.offAsE) (hIpa := hIpa) (hIpa47 := hIpa47) + (cte := cte) (hab := hab) (hcap := hcap) (UP := UP) (hS2 := hS2) (hY := hY) (vp := vp) (vasid := vasid) + (vva := vva) (vaddr := vaddr) (ha16 := ha16) (hD := hD) (hrt := hrt) (hres := hres) + (fin := fun _ _ σ3 _ _ _ => D' hinv σ3) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmS2A.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmS2A.lean new file mode 100644 index 000000000..74eaab5c5 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmS2A.lean @@ -0,0 +1,141 @@ +/- +P3 (aarch64, Stage 4 line vsx-A): **the Stage-2 frame map at a syscall entry** (twin of `Stage3T3ArmHiA`). + +`decFrame_s2A`: `vspace::decode_frame` of an `ARMPageMap` with an `Ept` extra cap is `ept::map_frame` (after +`ept::root`), and `JSyscallA.frameMapS2A`: the invocation equation from the decode-site results. + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `S2IpaE`; the arm's; `hinv` (decode site). +-/ +import Fl4ProofsA64.P3.Stage3BodyKeepA +import Fl4ProofsA64.P3.Stage3ArmFrMapS2A +import Fl4ProofsA64.P3.Stage3T3DecEqA +import Fl4ProofsA64.P3.Stage3FinA +import Fl4ProofsA64.P3.Stage3RsSiteA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +section +variable {ar : machine.Arch A} {s : S} {a : A} {length slot buf : U64} {call : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {x0 : U64} + +/-- **A frame map with an `Ept` extra cap** is `ept::map_frame` at the root and ASID `ept::root` returned. -/ +theorem decFrame_s2A {fp rt asid va : U64} {sz : capability.FrameSize} {dev mp e : Bool} + (hx : vspace.extra extra 0#usize = ok (some x0)) (hlen : length ≥ 3#u64) + {vaddr rmask attr vm : U64} (h0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok vaddr) + (h1 : msg.syscall_arg st s (L.curW s) buf 1#u64 = ok rmask) + (h2 : msg.syscall_arg st s (L.curW s) buf 2#u64 = ok attr) + {rr : capability.Rights} (hr : capability.Rights.from_word rmask = ok rr) + (hvm : capability.mask_vm_rights rt rr = ok vm) + {p1 asid1 va1 : U64} {mp1 : Bool} (hc : obj.Slot.cap st x0 s = ok (.Ept p1 0#u64 mp1 asid1 va1)) + (hrt : ept.root st s (.Ept p1 0#u64 mp1 asid1 va1) 1#u64 = ok (core.result.Result.Ok (p1, asid1))) + (hg : asid ≠ 0#u64 → e = true) : + vspace.decode_frame st ar s a fl4_abi.label.ARMPageMap length slot (.Frame fp sz rt dev mp e asid va) call buf + extra = + ept.map_frame st ar s a p1 asid1 vaddr vm attr fp sz rt dev asid va slot := by + unfold vspace.decode_frame + simp only [vspace.as_frame, cur_thread_ok, bind_ok, ↓reduceIte] + unfold vspace.decode_page_map + simp only [cur_thread_ok, bind_ok, hx, if_pos hlen, h0, h1, h2, hr, hvm, hc, hrt, + core.result.Result.Insts.CoreOpsTry.branch, Bool.false_eq_true, ↓reduceIte, ite_self] + by_cases hz : asid = 0#u64 + · subst hz + simp + · have := hg hz + subst this + simp [bne_iff_ne.2 hz] + +end + +section +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4Spec Fl4SpecA64 Classical + +set_option maxHeartbeats 4000000 in +/-- **Frame map into a Stage-2 root**, at a syscall entry (the invocation equation from the decode-site results). -/ +theorem JSyscallA.frameMapS2A + {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} + {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} + {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} {x0 : U64} + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + {dc : capability.Cap} {ex : Aeneas.Std.Array obj.Slot 3#usize} {s3 : S} {a3 : A} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) (hIpa : S2IpaE ar a) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) (K : ArchKeepsA ar AR) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) + (hK : Aligned (L.ksb s)) (hT : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s)) + (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) + (hCn : ∃ pc, cte.1 = specPtr pc ∧ Z.th pc = some (.cnode cte.2.length)) + (fp rt asid va : U64) (sz : capability.FrameSize) (dev mp e : Bool) + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .Frame fp sz rt dev mp e asid va) + (FP : FrPlA sz fp mp asid) (hemp : e = mp) (p1 asid1 va1 : U64) (mp1 : Bool) (h16 : asid1.val < 2 ^ 16) + (hx0 : x0 ∈ OS) (hx0c : capA st s x0 = .Ept p1 0#u64 mp1 asid1 va1) + (hrt : ept.root st s (.Ept p1 0#u64 mp1 asid1 va1) 1#u64 = ok (core.result.Result.Ok (p1, asid1))) + (vaddr rightsMask vm attr : U64) + (hvmRange : vm = capability.VM_KERNEL_ONLY ∨ vm = capability.VM_READ_ONLY ∨ vm = capability.VM_READ_WRITE) + (hvmEq : vmRightsOfA vm = maskVmRights (vmRightsOfA rt) (dataToRights rightsMask.bv)) + (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace + (decodeS2PageMapAt (Z := Unit) cte (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev + (mapDataA mp asid va) (specPtr p1) (asidOfA asid1) vaddr.bv rightsMask.bv attr.bv)).run σ) + (d : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s dc ex) + (hres : ept.map_frame st ar s a p1 asid1 vaddr vm attr fp sz rt dev asid va (cslotAddrA cte) = + ok (core.result.Result.Ok (), s3, a3)) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (hext : ∀ x ∈ ex.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ ex.val, x ≠ 0#u64 → SlotCov st OS s x) + {callD : Bool} {lenD bufD : U64} + (hx : vspace.extra ex 0#usize = ok (some x0)) (hlen : lenD ≥ 3#u64) + (h0 : msg.syscall_arg st s (L.curW s) bufD 0#u64 = ok vaddr) + (h1 : msg.syscall_arg st s (L.curW s) bufD 1#u64 = ok rightsMask) + (h2 : msg.syscall_arg st s (L.curW s) bufD 2#u64 = ok attr) + {rr : capability.Rights} (hr : capability.Rights.from_word rightsMask = ok rr) + (hvm : capability.mask_vm_rights rt rr = ok vm) : + ∃ (x : Fl4SpecA64.Tcb) (iv : ExtVSpaceInvocation) (σ3 : Fl4SpecA64.State Unit) (Ac' : Set U64), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.extVSpace iv), σ) ∈ D.1 ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ + (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR Z H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s3 a3 σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + have hslot : (cslotAddrA cte) ∈ OS := J.j5.2.1 _ (hab.isSlot J.j.1.place) + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have D' : ∀ {bB bC bD bF : Bool} {len buf' : U64} {rX : core.result.Result Unit error.Exc} {sX : S} {aX : A}, + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageMap len (cslotAddrA cte) + (.Frame fp sz rt dev mp e asid va) bB bC bD bF buf' ex = ok (rX, sX, aX) → + ∀ σX : Fl4SpecA64.State Unit, ∃ Ac' : Set U64, SysL st H Z.Cs OS ia ie sX ∧ SymL st H Z.Cs sX ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' sX ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U sX ∧ + J7A st (J7R2A st ar hPl.ipa) Z H OS sX σX m := fun hd σX => + (J.decodeFinA hA hM hPl hfm hslot hcov ((capAtA_eq (st := st) _ _).symm.trans hcap) hext hSC + (lbl := fl4_abi.label.ARMPageMap) (by simp [DecArmS1aEnt, DecArmQH]) + (fun _ h => by cases h) (fun _ h => by cases h) hd σX m).2 + have hg : asid ≠ 0#u64 → e = true := fun hz => hemp.trans (FP.mz.2 hz) + have hinv : syscall.decode_invocation st ar s a fl4_abi.label.ARMPageMap lenD (cslotAddrA cte) + (.Frame fp sz rt dev mp e asid va) false callD false false bufD ex = ok (core.result.Result.Ok (), s3, a3) := by + rw [decInv_frameA ar s a _ lenD _ fp sz rt dev mp e asid va false callD false false bufD ex, + decFrame_s2A hx hlen h0 h1 h2 hr hvm (by rw [capA_eq, hx0c]) hrt hg] + exact hres + refine JStage3A.frameMapS2A (ar := ar) (J := J.toJStage3A) (RS := RS) (hA := hA) (hPl := hPl) (hIpa := hIpa) + (K := K) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (hK := J.toJStage3A.ksbAligned) (hT := J.toJStage3A.offAsE) + (cte := cte) (hab := hab) (hCn := hCn) (fp := fp) (rt := rt) (asid := asid) (va := va) (sz := sz) (dev := dev) + (mp := mp) (e := e) (hcap := hcap) (FP := FP) (hemp := hemp) (p1 := p1) (asid1 := asid1) (va1 := va1) + (mp1 := mp1) (h16 := h16) (hx0 := hx0) (hx0c := hx0c) (hrt := hrt) (vaddr := vaddr) (rightsMask := rightsMask) + (vm := vm) (attr := attr) (hvmRange := hvmRange) (hvmEq := hvmEq) (hD := hD) (d := d) (hres := hres) + (fin := fun _ _ σ3 _ _ _ => D' hinv σ3) + +end + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmT2A.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmT2A.lean new file mode 100644 index 000000000..466aaafb5 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmT2A.lean @@ -0,0 +1,115 @@ +/- +P3 (AArch64, vsx line C): **the T2 unmap shrink at a syscall entry** — `JSyscallA.ptUnmapT2A`, the T3 wrapper of +`JStage3A.ptUnmapT2A` (`P3/Stage3ArmPtUnmT2A`), and `J7A.shrinkT2A` (J7 at the shrunk ghost `T2 \ {ptr}`: only the +`link` clause reads `T2`). + +Named premises: [J] `hUniq` (`JStage3A.ptUnmapT2A`); `hno` (no other slot names the table: derived at the site from +the finality test, `P3/Stage3ScopeArmsA`). New module. +-/ +import Fl4ProofsA64.P3.Stage3T3ArmsA +import Fl4ProofsA64.P3.Stage3ArmPtUnmT2A +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +/-- **J7 at a smaller `T2`**: only the `link` clause reads it. -/ +theorem J7A.shrinkT2A {R : Set U64 → JSlotA S} {Z : XSetsA} {T2' : Set U64} {H : Heap} {OS : Set U64} {s : S} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (hT : T2' ⊆ Z.T2) + (hR : ∀ Pt, R Pt Z H OS s σ m → R Pt { Z with T2 := T2' } H OS s σ m) (h : J7A st R Z H OS s σ m) : + J7A st R { Z with T2 := T2' } H OS s σ m := by + obtain ⟨Pt, Ub, vr, pn, ac, cc, vc, df, hi, link, sa, fu, ual, vcu, r⟩ := h + exact ⟨Pt, Ub, vr, pn, ac, cc, vc, df, hi, fun p hp => link p (SchedPageA.shrinkT2A st hT hp), sa, fu, ual, + vcu, hR Pt r⟩ + +set_option maxHeartbeats 4000000 in +/-- **Page-table unmap of a Stage-2 table (`ptr ∈ Z.T2`)**, at a syscall entry; the ghost `T2` loses `ptr`. -/ +theorem JSyscallA.ptUnmapT2A + {AR : A → HwRootA → Prop} + {Z : XSetsA} + {H : Heap} + {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} + {ia ie : Nat} + {N E Rp : Set U64} + {Bf : Set (U64 × Fl4SpecA64.Word)} + {stack : U64 → List U64} + {κ : U64 → U64} + {n : Nat} + + {s : S} + {a : A} + {σ : Fl4SpecA64.State Unit} + {m : Fl4SpecA64.McState} + {ar : machine.Arch A} + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (K : ArchKeepsA ar AR) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) + (hEO : ExtTabOffA (L := L) Z m s) + (hK : Aligned (L.ksb s)) + (hT : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s)) + (hIpa : S2IpaE ar a) + (length buf : U64) + (ex : Aeneas.Std.Array obj.Slot 3#usize) + (cte : Fl4SpecA64.CslotPtr) + (hab : AbsSlotA Z.th cte) + (ptr asid va : U64) + (hpT : ptr ∈ Z.T2) + (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) + (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (k : Fl4SpecA64.ExtRootKind) + (hkR : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some k) + (hkR1 : k ≠ .stage1) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) + (hUniq : ∀ (s2 : S) (a2 : A), + vspace.unmap_page_table st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a asid va ptr = ok (s2, a2) → + ∀ w, S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART)) σ w → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 0 = true → + dBitA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) 1 = true → + dTabA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) w) = ptr → L.mem s2 w = 0#u64) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (hext : ∀ x ∈ ex.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ ex.val, x ≠ 0#u64 → SlotCov st OS s x) : + ∃ (x : Fl4SpecA64.Tcb) (s3 : S) (a' : A) (σ3 : Fl4SpecA64.State Unit) (Ac' : Set U64), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap length (cslotAddrA cte) + (.PageTable ptr true asid va) buf ex = ok (core.result.Result.Ok (), s3, a') ∧ + (([] : List Fl4SpecA64.Data), σ3) ∈ (Fl4SpecA64.performExtVSpace (Z := Unit) (.tableUnmap k (.pageTableCap + (specPtr ptr) .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte) (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with T2 := Z.T2 \ {ptr} } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s3 a' σ3 m ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 := by + have hslot : (cslotAddrA cte) ∈ OS := J.j5.2.1 _ (hab.isSlot J.j.1.place) + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have D : ∀ {bB bC bD bF : Bool} {len buf' : U64} {rX : core.result.Result Unit error.Exc} {sX : S} {aX : A}, + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableUnmap len (cslotAddrA cte) (.PageTable ptr true asid va) bB bC bD bF buf' ex = ok (rX, sX, aX) → + ∀ σX : Fl4SpecA64.State Unit, ∃ Ac' : Set U64, SysL st H Z.Cs OS ia ie sX ∧ SymL st H Z.Cs sX ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' sX ∧ + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U sX ∧ + J7A st (J7R2A st ar hPl.ipa) Z H OS sX σX m := fun hd σX => + (J.decodeFinA hA hM hPl hfm hslot hcov (hcap) hext hSC (lbl := fl4_abi.label.ARMPageTableUnmap) (by simp [DecArmS1aEnt, DecArmQH]) + (fun _ h => by cases h) (fun _ h => by cases h) hd σX m).2 + refine JStage3A.ptUnmapT2A (ar := ar) (nA := hPl.ipa) (J := J.toJStage3A) (RS := RS) (K := K) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (hK := hK) (hT := hT) (hIpa := hIpa) (length := length) (buf := buf) (ex := ex) (cte := cte) (hab := hab) (ptr := ptr) (asid := asid) (va := va) (hpT := hpT) (hcap := hcap) (hf := hf) (k := k) (hkR := hkR) (hkR1 := hkR1) (hno := hno) (hUniq := hUniq) + (fin := fun _ _ σ3 _ _ hd _ => by + obtain ⟨Ac', h1, h2, h3, h4, h5⟩ := D (bB := false) (bC := false) (bD := false) (bF := false) + ((decInv_ptA ar s a _ length _ ptr true asid va false false false false buf ex).trans hd) σ3 + exact ⟨Ac', h1, h2, h3, h4, J7A.shrinkT2A (fun _ hx => hx.1) (fun _ h => h) h5⟩) + + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpu2A.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpu2A.lean index b1647fff3..7e71b6c62 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpu2A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpu2A.lean @@ -452,12 +452,10 @@ private theorem vcpu_unbind_ext_stage3TA rw [nd_bind_oneSc (getVcpu_eqA hkv')] exact setVcpu_eqA hkv' have hHS : VcpuSpecStepA H σ' σ'' := - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, - fun p => by + VcpuSpecStepA.ofKey rfl (fun p => by by_cases hp : p = specPtr vc · subst hp; exact Or.inr (Or.inr ⟨v', v'', hkv', updKSc_same _ _ _, rfl, rfl, rfl, rfl, rfl, rfl⟩) - · exact Or.inl (updKSc_other _ hp), - fun _ hne => absurd rfl hne⟩ + · exact Or.inl (updKSc_other _ hp)) (fun _ hne => absurd rfl hne) have hw_refl : WritesIn st s' s' (VcpuWrNoStA st { Z with hw := hw' } OS s') := ⟨rfl, rfl, fun _ _ _ => rfl⟩ have hVcCore'' : VcpuCoreA (L := L) { Z with hw := hw' } s' σ'' := by @@ -572,8 +570,7 @@ private theorem vcpu_assoc_stage3TA obtain ⟨c, hc, heq⟩ := J.sinv.onlyIdle (specPtr ptr) xt0 hkt0 hi exact hptr_not_idle c hc heq have hHS : VcpuSpecStepA H σ σ' := by - refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, - fun p => ?_, fun _ h => absurd rfl h⟩ + refine VcpuSpecStepA.ofKey rfl (fun p => ?_) (fun _ h => absurd rfl h) by_cases hp1 : p = specPtr vc · subst hp1; exact Or.inr (Or.inr ⟨v0, v1, hkv0, updKSc_same _ _ _, rfl, rfl, rfl, rfl, rfl, rfl⟩) · by_cases hp2 : p = specPtr ptr @@ -1214,8 +1211,7 @@ theorem JSyscallA.vcpuSetTcbA {ar : machine.Arch A} have ha3_eq := (Prod.mk.inj hp).2 rw [← hs3_eq, ← ha3_eq] have hHS_refl : VcpuSpecStepA H σ3 σ3 := - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, - fun _ => Or.inl rfl, fun _ h => absurd rfl h⟩ + VcpuSpecStepA.ofKey rfl (fun _ => Or.inl rfl) (fun _ h => absurd rfl h) have hw_refl : WritesIn st s_a s_a (VcpuWrNoStA st { Z with hw := hw_r } OS s_a) := ⟨rfl, rfl, fun _ _ _ => rfl⟩ have J_vr := JStage3TA.of_vcpuStepA (hw' := hw_fin) J_a R6_a hw_refl hHS_refl hAR_fin (fun _ _ => rfl) { J_a.j.2.1 with } J_a.vcRun J_a.runVcpu J_a.ep.tcb J_a.ep.buf @@ -1439,12 +1435,10 @@ private theorem wfInv_step_vcpu {s0 s1 s2 : S} {σ0 σ1 : Fl4SpecA64.State Unit} (hreg_eq : ∀ t ∈ Z.T, ∀ r : Register, L.mem s2 (Endp.regA t (regIdxA r)) = L.mem s1 (Endp.regA t (regIdxA r))) : WfInv st Z H s0 σ0 vc v_tcb s2 (updKSc σ1 (specPtr vc) (.archObj (.vcpu v2))) := by have h12 : VcpuSpecStepA H σ1 (updKSc σ1 (specPtr vc) (.archObj (.vcpu v2))) true := - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, - fun p => by + VcpuSpecStepA.ofKey rfl (fun p => by by_cases hp : p = specPtr vc · subst hp; exact Or.inr (Or.inr ⟨v1, v2, hkv1, updKSc_same _ _ _, trivial⟩) - · exact Or.inl (updKSc_other _ hp), - fun _ hne => absurd rfl hne⟩ + · exact Or.inl (updKSc_other _ hp)) (fun _ hne => absurd rfl hne) refine ⟨wf_trans inv.hw hw12, hC2, hS2, fun t ht xt hkt r => ?_, vcpuSpecStep_trans inv.hHS h12, inv.um⟩ have hne : specPtr t ≠ specPtr vc := fun e => by rw [e, updKSc_same] at hkt; cases hkt rw [updKSc_other _ hne] at hkt @@ -1836,14 +1830,12 @@ private theorem wfInv_write_gprs {Ub : Set U64} {s0 s1 : S} {σ0 σ1 : Fl4SpecA6 · have hne_s : specPtr v ≠ specPtr v_tcb := fun e => by rw [e, hkh_ctx, if_pos rfl] at hkx; cases hkx rw [hkh_ctx, if_neg hne_s] at hkx; exact invc.snap.mask v hv x hkx have h12 : VcpuSpecStepA H σc (ctxUpdA σc (specPtr v_tcb) xc uc') true := - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, - fun p => by + VcpuSpecStepA.ofKey rfl (fun p => by by_cases hp : p = specPtr v_tcb · subst hp; exact Or.inr (Or.inl ⟨xc, { xc with tcbArch := { xc.tcbArch with tcbContext := uc' } }, hkc, by rw [hkh_ctx, if_pos rfl], ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, fun _ => id⟩⟩) - · exact Or.inl (by rw [hkh_ctx, if_neg hp]), - fun _ hne => absurd rfl hne⟩ + · exact Or.inl (by rw [hkh_ctx, if_neg hp])) (fun _ hne => absurd rfl hne) refine ⟨ctxUpdA σc (specPtr v_tcb) xc uc', hasu, wf_trans invc.hw hw12, hC2, hS2, fun t ht xt hkt reg => ?_, vcpuSpecStep_trans invc.hHS h12, invc.um⟩ by_cases ht_eq : t = v_tcb diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuA.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuA.lean index ca13a7d4f..de8b1a994 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuA.lean @@ -568,7 +568,7 @@ private theorem JStage3A.of_reply1A {ar : machine.Arch A} {nA : U64} by_cases e : p = σ1.curThread · subst e; rw [hkh_ct] at h; cases h · rw [hne_ct_other p e] at h; exact ⟨r, h, id⟩ - dom := ⟨rfl, rfl, rfl, rfl⟩ } + dom := DomKeepA.ofKey rfl } have hK : IpcKeepA σ1 σ3 := { tcb := fun p x hx => by by_cases e : p = σ1.curThread diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuRunA.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuRunA.lean index ea35e059f..517a8a71f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuRunA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuRunA.lean @@ -750,7 +750,7 @@ theorem set_thread_state_running_vm_stage3A {ar : machine.Arch A} {nA : U64} · subst ep; rw [updKSc_same] at h; cases h · exact ⟨y, by rwa [updKSc_other _ ep] at h⟩ have hQk : QKeepA σ σ_vm := by - refine ⟨fun p y hy => ?_, fun p x0 hp => ?_, fun p x0 hp => ?_, fun p y k hp => ?_, fun p y hp => ?_, ⟨rfl, rfl, rfl, rfl⟩⟩ + refine ⟨fun p y hy => ?_, fun p x0 hp => ?_, fun p x0 hp => ?_, fun p y k hp => ?_, fun p y hp => ?_, DomKeepA.ofKey rfl⟩ · by_cases ep : p = specPtr ct · subst ep; rw [updKSc_same] at hy; cases hy; exact ⟨x, hk, rfl⟩ · exact ⟨y, by rwa [updKSc_other _ ep] at hy, rfl⟩ @@ -1047,8 +1047,7 @@ theorem vcpu_enter_run_vm_stage3A {ar : machine.Arch A} {nA : U64} {Ub : Set U64 (fun e => hnf (e ▸ Or.inr (Or.inl ⟨ct, hct, 3672#u64, by decide, Or.inr (Or.inr rfl), rfl⟩))) have hHS_vm_10 : VcpuSpecStepA H σ_vm σ10 true := by rw [hσ10_eq] - refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, - fun p => ?_, fun _ h => absurd rfl h⟩ + refine VcpuSpecStepA.ofKey rfl (fun p => ?_) (fun _ h => absurd rfl h) by_cases h1 : p = specPtr ct · subst h1; exact Or.inr (Or.inl ⟨{ x0 with tcbState := .ext .runningVM }, x1, updKSc_same _ _ _, updKSc_same _ _ _, ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, fun hs => by cases hs⟩⟩) @@ -2008,7 +2007,7 @@ theorem ntfn_set_idle_stage3A {ar : machine.Arch A} {nA : U64} {Ub : Set U64} by_cases e : p = specPtr nf · rw [e, updKSc_same] at hy; cases hy · rw [updKSc_other _ e] at hy; exact ⟨y, hy, id⟩, - ⟨rfl, rfl, rfl, rfl⟩⟩ + DomKeepA.ofKey rfl⟩ obtain ⟨-, hB0, hX0, hSg0, hS0⟩ := J.sys.ent.bxi have hst_act : L.epState s nf = 2#u64 := by obtain ⟨x0, hx0, hr0⟩ := J.ntfn.ntfn nf hnf diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbBufMidA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbBufMidA.lean new file mode 100644 index 000000000..ea5d7ee35 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbBufMidA.lean @@ -0,0 +1,503 @@ +/- +P3 (aarch64, A64-P4 `tcbbuf`): **the `install_buffer` step from a chain's mid state**, for a zero and a non-zero buffer +address; the shared core of `JSyscallA.setIpcBuf{Zero,Nz}A` and of the Configure arm. + +* **`bufLiveOfFrameA`**, **`frameWord_ne_ibA`**, **`bufMid*A`**: the buffer of a live frame cap; the spec's two + `check_cap_at`s and `cap_insert`. +* **`JStage3A.reschedP1_stepA`**: `reschedule_required` at a record state, its P1 facts from `JStage3A.p1StepA`. +* **`TcbBufSrcA`**: the source of the step: none (address 0, source slot `0`), or the unmapped copy of a source Frame cap. +* **`TcbMidA.bufStepA`**: `delChainA` on slot 2, `set_ipc_buffer`, `cdt::insert` iff `still_valid` + (`capInsertTcbBufA`), `reschedule_required` iff the target is the current thread; the spec's `fl4InstallTcbFrameCap`. + +Named premises: those of `TcbMidA.delChainA`; [S] the agreement `Md.fr` on the 128 words of a new buffer (`TcbBufSrcA`'s +`⊆ Ag`). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbChainHelpA +import Fl4ProofsA64.P3.Stage3TcbBufStepsA +import Fl4ProofsA64.P3.Stage3TcbReschedA +import Fl4ProofsA64.P3.TcbInvokeSlotA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **The buffer of a live frame cap** (module docstring). -/ +theorem bufLiveOfFrameA {H : Heap} {OS : Set U64} {s : S} (hH : HeapOK H) (h0 : H 0#u64 = none) + (hfo : FrameOK st H OS s) {src ptr rights asid va baddr bits : U64} {size : capability.FrameSize} {mp ep : Bool} + (hsrc : src ∈ OS) (hc : capA st s src = .Frame ptr size rights false mp ep asid va) (hbits : size.bits = ok bits) + (hbal : baddr.val % 1024 = 0) (hbn : baddr ≠ 0#u64) : + ptr.val % 2 ^ bits.val = 0 ∧ BufLiveA st OS s (bufAddrOfA ptr baddr bits) := by + have hfp : H ptr = some (.other bits.val) := hfo src hsrc ptr size rights mp ep asid va hc bits hbits + have hal : ptr.val % 2 ^ bits.val = 0 := by + have h := hH.align ptr _ hfp + simpa [HKind.bits] using h + obtain ⟨-, h1024, hle, hlt⟩ := bufAddr_rangeA (frame_bitsLtA hbits) hal hbal + have hp0 : ptr.val ≠ 0 := fun e => by + have : ptr = 0#u64 := UScalar.eq_of_val_eq e + rw [this, h0] at hfp + cases hfp + refine ⟨hal, fun e => ?_, h1024, fun k hk => ⟨src, hsrc, ptr, size, rights, mp, ep, asid, va, bits, hc, hbits, ?_, ?_⟩⟩ + · have := congrArg UScalar.val e + rw [show (0#u64 : U64).val = 0 from rfl] at this + omega + · rw [bufW_valLiveA h1024 hk]; omega + · rw [bufW_valLiveA h1024 hk]; omega + +/-- **A live frame word is not the IPC-buffer word of a TCB.** -/ +theorem frameWord_ne_ibA {H : Heap} {OS : Set U64} {s : S} (hH : HeapOK H) (hfo : FrameOK st H OS s) {t b : U64} + (hta : TcbAddr t) (htH : H t = some .tcb) (lv : FrameWordLive st OS s b) : wa t 3512#u64 ≠ b := by + obtain ⟨u, hu, ptr, size, rights, x1, x2, x3, x4, bits, hc, hb, h1, h2⟩ := lv + have hfp : H ptr = some (.other bits.val) := hfo u hu ptr size rights x1 x2 x3 x4 hc bits hb + have := frameWord_offA hH hfp htH (fun z => by simp) h1 h2 + have vM : (wa t 3512#u64).val = t.val + 3512 := by + show (wa t 3512#u64).val = _ + rw [Notif.tfield_val hta (by decide : (3512#u64 : U64).val < 4096)]; rfl + intro e + have ev := congrArg UScalar.val e + simp only [HKind.bits] at this + omega + +end + +section spec + +/-- The spec's two `check_cap_at`s and `cap_insert` when the source's cap is no longer the new cap's object. -/ +theorem bufMidSrcA {σ : State Unit} {target : ObjRef} {κs κsrc : CslotPtr} {newCap source : Cap} + (hsource : (source, σ) ∈ (getCap (Z := Unit) κsrc σ).1) (hmatch : ¬ fl4TcbSameObject newCap source) : + ((), σ) ∈ ((getCap (Z := Unit) κsrc >>= fun live => + Fl4Spec.NonDet.when (fl4TcbSameObject newCap live) (getCap (Z := Unit) κs >>= fun cap => + Fl4Spec.NonDet.when (fl4TcbSameObject (.threadCap target) cap) + (capInsert (Z := Unit) newCap κsrc (target, tcbCnodeIndex 2)))) σ).1 := by + refine mem_bind_ndD hsource ?_ + rw [Fl4Spec.NonDet.when, if_neg hmatch] + exact Set.mem_singleton _ + +/-- … when the invoked slot no longer holds the thread's cap. -/ +theorem bufMidInvA {σ : State Unit} {target : ObjRef} {κs κsrc : CslotPtr} {newCap source current : Cap} + (hsource : (source, σ) ∈ (getCap (Z := Unit) κsrc σ).1) (hmatch : fl4TcbSameObject newCap source) + (hinvoked : (current, σ) ∈ (getCap (Z := Unit) κs σ).1) (htarget : ¬ fl4TcbSameObject (.threadCap target) current) : + ((), σ) ∈ ((getCap (Z := Unit) κsrc >>= fun live => + Fl4Spec.NonDet.when (fl4TcbSameObject newCap live) (getCap (Z := Unit) κs >>= fun cap => + Fl4Spec.NonDet.when (fl4TcbSameObject (.threadCap target) cap) + (capInsert (Z := Unit) newCap κsrc (target, tcbCnodeIndex 2)))) σ).1 := by + refine mem_bind_ndD hsource ?_ + rw [Fl4Spec.NonDet.when, if_pos hmatch] + refine mem_bind_ndD hinvoked ?_ + rw [Fl4Spec.NonDet.when, if_neg htarget] + exact Set.mem_singleton _ + +/-- … when both hold and the insert runs. -/ +theorem bufMidInsA {σ σ' : State Unit} {target : ObjRef} {κs κsrc : CslotPtr} {newCap source current : Cap} + (hsource : (source, σ) ∈ (getCap (Z := Unit) κsrc σ).1) (hmatch : fl4TcbSameObject newCap source) + (hinvoked : (current, σ) ∈ (getCap (Z := Unit) κs σ).1) (htarget : fl4TcbSameObject (.threadCap target) current) + (hinsert : ((), σ') ∈ (capInsert (Z := Unit) newCap κsrc (target, tcbCnodeIndex 2) σ).1) : + ((), σ') ∈ ((getCap (Z := Unit) κsrc >>= fun live => + Fl4Spec.NonDet.when (fl4TcbSameObject newCap live) (getCap (Z := Unit) κs >>= fun cap => + Fl4Spec.NonDet.when (fl4TcbSameObject (.threadCap target) cap) + (capInsert (Z := Unit) newCap κsrc (target, tcbCnodeIndex 2)))) σ).1 := by + refine mem_bind_ndD hsource ?_ + rw [Fl4Spec.NonDet.when, if_pos hmatch] + refine mem_bind_ndD hinvoked ?_ + rw [Fl4Spec.NonDet.when, if_pos htarget] + exact hinsert + +end spec + + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {Clock : A → Fl4SpecA64.MachineState → Prop} {Ag : Set U64} {m : McState} + +/-- **`reschedule_required` at a record state** (module docstring). -/ +theorem JStage3A.reschedP1_stepA {s : S} {a : A} {σ : State Unit} (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (sact : SActA σ) (nsw : ∀ u, σ.schedulerAction ≠ .switchThread u) : + ∃ s' σ', sched.reschedule_required st s = ok s' ∧ + rescheduleRequired (Z := Unit) σ = ({((), σ')}, False) ∧ σ' = { σ with schedulerAction := .chooseNewThread } ∧ + ∃ Ac' : Set U64, + JStage3A st AR Z H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s' a σ' m := by + obtain ⟨s', σ', hr, -, hres, eσ, W, K⟩ := J.reschedSelf_stepA sact nsw + have hb : BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s := BXI.blk J.sys.ent.bxi + have h0 : H 0#u64 = none := J.sys.sysl.ly.h0 + have F := sched.reschedule_required.dfK s hb + rw [hr, WP.spec_ok] at F + obtain ⟨⟨Q, R, q⟩, -⟩ := id hb + have F2 := K8.sched.reschedule_required.kw8 (Sg := H.frame) (Scs := H.scs) (Z := H.scBits) (Es := ∅) s q + rw [hr, WP.spec_ok] at F2 + have d : DMD st H Z.Cs 0#u64 s s' := DMD.ofNone hb h0 J.symL J.sys.sysl.vr (K8.Foot.d F2) F.2.2 + obtain ⟨sysl, symL, userOK, -, j7⟩ := J.p1StepA hA hPl (W.mono fun _ hb => Or.inl (Or.inl (Or.inr hb))) d + (fun k hk => by rw [h0] at hk; cases hk) F.1 + exact ⟨s', σ', hr, hres, eσ, _, K sysl symL userOK (j7 σ' m)⟩ + +/-- **The source of a chain's buffer step** (module docstring), at the state `s` before the slot-2 delete. -/ +def TcbBufSrcA {S : Type} (st : machine.Store S) [L : LawfulStore st] (th : TypedHeapA) (OS Ag : Set U64) (s : S) + (t slot src baddr : U64) (bc : capability.Cap) (κs : CslotPtr) (frame : Option (Fl4SpecA64.Cap × CslotPtr)) : Prop := + (baddr = 0#u64 ∧ src = 0#u64 ∧ frame = none) ∨ + (baddr ≠ 0#u64 ∧ src ≠ 0#u64 ∧ ∃ (ptr rights asid va bits : U64) (size : capability.FrameSize) (mp ep : Bool) + (κsrc : CslotPtr), + bc = .Frame ptr size rights false false false 0#u64 0#u64 ∧ size.bits = ok bits ∧ frame = some (absCapA bc, κsrc) ∧ + AbsSlotA th κs ∧ cslotAddrA κs = slot ∧ + (∃ ps : U64, κsrc.1 = specPtr ps ∧ th ps = some (.cnode κsrc.2.length)) ∧ cslotAddrA κsrc = src ∧ slot ∈ OS ∧ src ∈ OS ∧ + slot ≠ cslotAddrA (specPtr t, tcbCnodeIndex 2) ∧ src ≠ cslotAddrA (specPtr t, tcbCnodeIndex 2) ∧ + (capA st s src = .Frame ptr size rights false mp ep asid va ∨ capA st s src = .Null ∨ HomeZA st s src) ∧ + (capA st s slot = .Thread t ∨ capA st s slot = .Null ∨ HomeZA st s slot) ∧ + {b | ∃ k : U64, k.val < 128 ∧ b = bufW (bufAddrOfA ptr baddr bits) k} ⊆ Ag) + + +set_option maxHeartbeats 16000000 in +/-- **The `install_buffer` step from a chain's mid state** (module docstring). `s0` is the chain's entry state. -/ +theorem TcbMidA.bufStepA [PlainStore st] {ct : ObjRef} {s : S} {a : A} {σ : State Unit} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (Md : TcbMidA st AR Clock ct Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar hPl.ipa Ag s a σ m) + (P : DelPlatA st ar AR Clock) (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) + {s0 : S} {Vc Ub Pt Ac1 : Set U64} {K0 : capability.Cap → Prop} {Ty : S → Prop} + (I : DelIn st ar H Z.Cs OS Vc Ub Pt K0 Ty s0) (R : DelR st H Z.Cs OS Vc Ub Ac1 Ty ia ie s0 s) + {t slot src baddr : U64} (ht : Z.th t = some .tcb) {κs : CslotPtr} {bc : capability.Cap} + {frame : Option (Fl4SpecA64.Cap × CslotPtr)} (hbal : baddr.val % 1024 = 0) + (hB : TcbBufSrcA st Z.th OS Ag s t slot src baddr bc κs frame) : + ∃ (r : core.result.Result Unit error.Exc) (s2 : S) (a2 : A) (σ' : State Unit), + tcb.install_buffer st ar s a t slot baddr (bc, src) = ok (r, s2, a2) ∧ + ∃ (Gi : MdbGhostA) (Q : U64 → U64 → List U64) (Rl : U64 → List U64) (hw : HwRootA) (Ac' : Set U64) + (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64), + JStage3A st AR { Z with G := Gi, Q := Q, R := Rl, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' κ n + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s2 a2 σ' m ∧ + ((r = .Ok () ∧ (.ok (), σ') ∈ ((fl4InstallTcbFrameCap (Z := Unit) (specPtr t) κs + (some (Fl4SpecA64.dataToVref baddr.bv, frame))).run σ).1 ∧ + BodyOKA σ' m ∧ σ'.curThread = σ.curThread) ∨ + (r = .Err .Preempted ∧ (.error (), σ') ∈ ((fl4InstallTcbFrameCap (Z := Unit) (specPtr t) κs + (some (Fl4SpecA64.dataToVref baddr.bv, frame))).run σ).1 ∧ + BodyPreA σ' m ∧ σ'.curThread = σ.curThread ∧ PreExitA σ' ∧ Clock a2 σ'.machineState)) := by + have htT : t ∈ H.tcbs := by rw [Md.J.tcbs]; exact (Md.J.j.1.thT t).1 ht + set sl : Fl4SpecA64.CslotPtr := (specPtr t, tcbCnodeIndex 2) with hsl + have hAd : AbsSlotA Z.th sl := ⟨t, rfl, Or.inr ⟨ht, 2, by decide, rfl⟩⟩ + have sbw : cslotAddrA sl = sbWordA t := by + unfold cslotAddrA + show slotAddrA (specPtr t) (Fl4SpecA64.ofBl (tcbCnodeIndex 2)) = _ + rw [ofBl_tcbIdx 2 (by decide), bufSlot_eqA] + have hdest : obj.Tcb.slot t layout.tcb.SLOT_BUFFER = ok (cslotAddrA sl) := by + rw [sbw]; simp [obj.Tcb.slot, lift, sbWordA] + have hslotIdx : slotIdx t layout.tcb.SLOT_BUFFER = cslotAddrA sl := + ok_inj_ff ((tcb_slot_val t _).symm.trans hdest) + have hdOS : cslotAddrA sl ∈ OS := Md.J.j5.2.1 _ (hAd.isSlot Md.J.j.1.place) + have hdelP := Md.delChainA hPl P hCs I R sl hAd htT (i := layout.tcb.SLOT_BUFFER) + (by simp [layout.tcb.SLOT_BUFFER]) hslotIdx.symm + obtain ⟨⟨r, sd, ad⟩, hdel0, hRd, σd, Gd, Dd, hres⟩ := spec_existsA hdelP + rcases hres with ⟨h1, hnull, hspec, hch, Q, Rl, hw, Ac', Bf', stack', Md2⟩ | + ⟨h1, hspec, hpre, hcur, hexit, hclk, Q, Rl, hw, Ac', Bf', stack', Jd⟩ + swap + · subst h1 + have hdecP : tcb.install_buffer st ar s a t slot baddr (bc, src) = ok (.Err .Preempted, sd, ad) := by + simp only [tcb.install_buffer, hdest, hdel0, bind_ok, uncurry_apply_pair, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact ⟨_, _, _, σd, hdecP, Gd, Q, Rl, hw, Ac', Bf', stack', Jd, + Or.inr ⟨rfl, bufSpec_errA _ _ _ hspec, hpre, hcur, hexit, hclk⟩⟩ + subst h1 + have Jd := Md2.J + have Binv := Md2.body + have sactd := Md2.sact + have fa := Md2.fr + have hct0 : σ.curThread = specPtr (L.curW s) := Md.J.j.1.sch.curThread + have hcd : σd.curThread = σ.curThread := Binv.2.1.trans Md.body.2.1.symm + have hcurd : L.curW sd = L.curW s := specPtr_inj ((Jd.j.1.sch.curThread).symm.trans (hcd.trans hct0)) + have ht' : t ∈ ({ Z with G := Gd, Q := Q, R := Rl, hw := hw } : XSetsA).T := (Md.J.j.1.thT t).1 ht + obtain ⟨yd, hyd, -⟩ := Jd.mcp t ht' + have hnb := ipcBufNone_ofNullA Dd.rel ht hyd (by rw [← sbw]; exact hnull) + obtain ⟨blk', K⟩ := Jd.setIpcBuf_stepVA (t := t) ht' hyd hnb baddr hbal + have hta : TcbAddr t := Jd.sr.core.tcbs t ht' + have aM : Aligned (wa t 3512#u64) := field_aligned hta (K := 3512#u64) (by simp) (by simp) + have vM : (wa t 3512#u64).val = t.val + 3512 := by + show (wa t 3512#u64).val = _ + rw [Notif.tfield_val hta (by decide : (3512#u64 : U64).val < 4096)]; rfl + have hcurw : L.curW (L.wr sd (wa t 3512#u64) baddr) = L.curW sd := by + have hq := Jd.sys.ent.bxi.1.choose_spec.choose_spec + have hn : NodePlaced st H.tcbs sd (L.cpu sd) := hq.nodes _ hq.cur + have c0 : layout.node.CUR_THREAD.val < 4288 := by simp + have hw' : WritesIn st sd (L.wr sd (wa t 3512#u64) baddr) (· = wa t 3512#u64) := writesIn_wr aM + have ecpu : L.cpu (L.wr sd (wa t 3512#u64) baddr) = L.cpu sd := L.cpu_wr _ _ _ + unfold LawfulStore.curW + rw [ecpu, nodeAt_of_ksb hw'.1] + refine hw'.mem_eq (nodeAt_aligned hn c0 (by simp)) fun e => ?_ + exact node_ne_field hn c0 htT hta (K := 3512#u64) (by simp) e + have hBuf : obj.Tcb.set_ipc_buffer st t sd baddr = ok (L.wr sd (wa t 3512#u64) baddr) := + eq_of_spec_fd (Fl4ProofsA64.P1.obj.Tcb.set_ipc_buffer.wr sd t baddr) + set sB := L.wr sd (wa t 3512#u64) baddr with hsB + set σB := bufStateVA σd (specPtr t) yd baddr with hσB + have hcurB : L.curW sB = L.curW s := hcurw.trans hcurd + have wW : WritesIn st sd sB (SchedStepNWA (st := st) N E Rp + ({ Z with G := Gd, Q := Q, R := Rl, hw := hw } : XSetsA) m σd sd) := + (writesIn_wr aM).mono fun b hb => by + subst hb + exact Or.inl (Or.inr (tcbStepWA_of_off Jd.iplaced.e.tcb ht' 3512 (by omega) (by omega) (by omega) + (by omega) vM)) + have R3 := obj.Tcb.set_ipc_buffer.delR I hRd htT hbal + rw [hBuf, WP.spec_ok] at R3 + have syslB := R3.1.sys + have symLB := R3.1.sym + obtain ⟨userB, -, j7B⟩ := Jd.p1StepSyA hA hPl wW ⟨syslB, symLB⟩ blk' + have JB := K syslB symLB userB (j7B σB m) + have hkeepB : ∀ y ∈ OS, capA st sB y = capA st sd y := fun y hy => (OSKeep.capA (Jd.osKeep_stepNA wW) hy) + have dskB : DSkA σd σB := + DSkA.upd (p := specPtr t) (o := .tcb yd) (o' := .tcb { yd with tcbIpcBuffer := baddr.bv }) hyd + (fun y k h => by cases h) (fun y k h => by cases h) + (fun x'' h => ⟨yd, rfl, by rw [← KernelObject.tcb.inj h]; exact ⟨rfl, Or.inl rfl, rfl⟩⟩) + have kstep : DelStepA σd σB := (DelStepA.ofWk Jd.sinv.curSc dskB.toDWkA (Or.inl dskB) dskB.ch).1 + have B1 := BodyOKA.stepA Binv kstep + -- the conditional reschedule, from the record before it + have tail : ∀ (G2 : MdbGhostA) (Ac2 : Set U64) (Bf2 : Set (U64 × Fl4SpecA64.Word)) (stack2 : U64 → List U64) + (sf : S) (σf : State Unit), + JStage3A st AR { Z with G := G2, Q := Q, R := Rl, hw := hw } H OS U Ac2 Pp Tb Lv ia ie N E Rp Bf2 stack2 κ n + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) sf ad σf m → + L.curW sf = L.curW s → DelBodyInvA ct m σf → DSkA σd σf → + ∃ s' σ' Ac3, + (if t = L.curW sf then sched.reschedule_required st sf else ok sf) = ok s' ∧ + ((σf.curThread ≠ specPtr t ∧ σ' = σf) ∨ + (σf.curThread = specPtr t ∧ ((), σ') ∈ (rescheduleRequired (Z := Unit) σf).1)) ∧ + JStage3A st AR { Z with G := G2, Q := Q, R := Rl, hw := hw } H OS U Ac3 Pp Tb Lv ia ie N E Rp Bf2 stack2 κ n + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s' ad σ' m ∧ + BodyOKA σ' m ∧ σ'.curThread = σ.curThread := by + intro G2 Ac2 Bf2 stack2 sf σf Jf hcf Bd dsk + have hct : σf.curThread = specPtr (L.curW sf) := Jf.sr.sch.curThread + have hcf' : σf.curThread = σ.curThread := Bd.2.1.trans Md.body.2.1.symm + by_cases hself : t = L.curW sf + swap + · refine ⟨sf, σf, _, if_neg hself, Or.inl ⟨fun e => hself ?_, rfl⟩, Jf, Bd.1, hcf'⟩ + exact specPtr_inj (e.symm.trans hct) + have nsw := Bd.2.2.1 + have sact : SActA σf := by + refine ⟨fun u e => absurd e (nsw u), ?_⟩ + obtain ⟨y, hy, -⟩ := Jf.mcp _ Jf.sr.curT + rw [← hct] at hy + obtain ⟨x, hx, e⟩ := dsk.tcb _ y hy + obtain ⟨x0, hx0, hs0⟩ := sactd.f2 + have ec : σf.curThread = σd.curThread := Bd.2.1.trans Binv.2.1.symm + rw [ec] at hx hy ⊢ + rw [hx0] at hx + cases hx + exact ⟨y, hy, by rw [e]; exact hs0⟩ + obtain ⟨s', σ', hr', hres', eσ, Ac3, J'⟩ := Jf.reschedP1_stepA hA hPl sact nsw + have k : DelStepA σf σ' := by + subst eσ + exact + { cur := rfl, time := rfl, last := rfl, csc := rfl, cons := rfl + rel := fun _ h => h + sc := fun y k h => ⟨y, h, Or.inl ⟨rfl, rfl, rfl⟩⟩ + act := Or.inr rfl + ctSt := fun h => by cases h + off := fun h => ⟨h.1, fun u e => by cases e⟩ + ctSc := CtScKA.refl _ σf } + have B' := BodyOKA.stepA Bd k + exact ⟨s', σ', _, (if_pos hself).trans hr', + Or.inr ⟨hct.trans (by rw [← hself]), by rw [hres']; exact Set.mem_singleton _⟩, J', B'.1, + B'.2.1.trans Md.body.2.1.symm⟩ + -- `still_valid` fails: no insert + have skip : tcb.still_valid st sB t slot bc src = ok false → + ((), σB) ∈ ((match frame with + | none => Fl4Spec.NonDet.pure () + | some (newCap, κsrc) => getCap (Z := Unit) κsrc >>= fun live => + Fl4Spec.NonDet.when (fl4TcbSameObject newCap live) (getCap (Z := Unit) κs >>= fun cap => + Fl4Spec.NonDet.when (fl4TcbSameObject (.threadCap (specPtr t)) cap) + (capInsert (Z := Unit) newCap κsrc (specPtr t, tcbCnodeIndex 2)))) σB).1 → + ∃ (r : core.result.Result Unit error.Exc) (s2 : S) (a2 : A) (σ' : State Unit), + tcb.install_buffer st ar s a t slot baddr (bc, src) = ok (r, s2, a2) ∧ + ∃ (Gi : MdbGhostA) (Q : U64 → U64 → List U64) (Rl : U64 → List U64) (hw : HwRootA) (Ac' : Set U64) + (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64), + JStage3A st AR { Z with G := Gi, Q := Q, R := Rl, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' κ n + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s2 a2 σ' m ∧ + ((r = .Ok () ∧ (.ok (), σ') ∈ ((fl4InstallTcbFrameCap (Z := Unit) (specPtr t) κs + (some (Fl4SpecA64.dataToVref baddr.bv, frame))).run σ).1 ∧ + BodyOKA σ' m ∧ σ'.curThread = σ.curThread) ∨ + (r = .Err .Preempted ∧ (.error (), σ') ∈ ((fl4InstallTcbFrameCap (Z := Unit) (specPtr t) κs + (some (Fl4SpecA64.dataToVref baddr.bv, frame))).run σ).1 ∧ + BodyPreA σ' m ∧ σ'.curThread = σ.curThread ∧ PreExitA σ' ∧ Clock a2 σ'.machineState)) := by + intro hSV hmid + obtain ⟨s', σ', Ac3, hs', hlast, J2, B2, c2⟩ := tail Gd Ac' Bf' stack' sB σB JB hcurB B1 dskB + have hP : tcb.install_buffer st ar s a t slot baddr (bc, src) = ok (.Ok (), s', ad) := by + rw [tcbInstallBuffer_skipA hdest hdel0 hBuf hSV, hs']; simp only [bind_ok] + exact ⟨_, _, _, σ', hP, Gd, Q, Rl, hw, Ac3, Bf', stack', J2, + Or.inl ⟨rfl, bufSpec_okA κs baddr frame hspec hyd hmid hlast, B2, c2⟩⟩ + rcases hB with ⟨-, hs0, rfl⟩ | ⟨hbn, hsrc0, ptr, rights, asid, va, bits, size, mp, ep, κsrc, hbc, hbits, rfl, hAκ, hκ, + hCsrc, hκsrc, hslot, hsrcOS, hneI, hneS, hS0, hI0, hsub⟩ + · have hn : obj.Slot.is_null src = ok true := by subst hs0; rfl + exact skip (tcbStillValid_nullA sB t slot src bc hn) (Set.mem_singleton _) + subst hbc + set fr : capability.Cap := .Frame ptr size rights false false false 0#u64 0#u64 with hfr + have hkeepSB : capA st sB src = .Frame ptr size rights false mp ep asid va ∨ capA st sB src = .Null ∨ + HomeZA st sB src := by + rcases chgZ_keepA (hch src hsrcOS hneS) hS0 with h | h | ⟨zt, k, h⟩ + · exact Or.inl ((hkeepB src hsrcOS).trans h) + · exact Or.inr (Or.inl ((hkeepB src hsrcOS).trans h)) + · exact Or.inr (Or.inr ⟨zt, k, (hkeepB src hsrcOS).trans h⟩) + have hkeepIB : capA st sB slot = .Thread t ∨ capA st sB slot = .Null ∨ HomeZA st sB slot := by + rcases chgZ_keepA (hch slot hslot hneI) hI0 with h | h | ⟨zt, k, h⟩ + · exact Or.inl ((hkeepB slot hslot).trans h) + · exact Or.inr (Or.inl ((hkeepB slot hslot).trans h)) + · exact Or.inr (Or.inr ⟨zt, k, (hkeepB slot hslot).trans h⟩) + have hSV := tcbStillValidFr_keptA (st := st) sB t slot src hsrc0 ptr rights asid va size mp ep hkeepSB hkeepIB + have hnullB : capA st sB (cslotAddrA sl) = .Null := (hkeepB _ hdOS).trans hnull + obtain ⟨ps, hss1, hss2⟩ := hCsrc + have hAsrc : AbsSlotA Z.th κsrc := ⟨ps, hss1, Or.inl hss2⟩ + have hsrcSlot : IsSlotA Z.th (cslotAddrA κsrc) := hAsrc.isSlot Md.J.j.1.place + -- the spec's two reads at the state after the buffer write + obtain ⟨cS, hgS, hcS⟩ := getCap_eqA JB.j.1.st (show AbsSlotA Z.th κsrc from hAsrc) + obtain ⟨cI, hgI, hcI⟩ := getCap_eqA JB.j.1.st (show AbsSlotA Z.th κs from hAκ) + rw [capAtA_eq (st := st), hκsrc] at hcS + rw [capAtA_eq (st := st), hκ] at hcI + have mS : (cS, σB) ∈ (getCap (Z := Unit) κsrc σB).1 := by rw [hgS]; exact Set.mem_singleton _ + have mI : (cI, σB) ∈ (getCap (Z := Unit) κs σB).1 := by rw [hgI]; exact Set.mem_singleton _ + have eS : capA st sB src = .Frame ptr size rights false mp ep asid va → + cS = absCapA (.Frame ptr size rights false mp ep asid va) := fun h => by + rw [h] at hcS + exact (CapEqA.eq_abs hcS (fun _ _ _ h => by cases h)).symm + have eI : capA st sB slot = .Thread t → cI = .threadCap (specPtr t) := fun h => by + rw [h] at hcI + exact (CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)).symm + have hsameT : fl4TcbSameObject (.threadCap (specPtr t)) (.threadCap (specPtr t)) := by + simp [fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] + have hsameF : fl4TcbSameObject (absCapA fr) (absCapA (.Frame ptr size rights false mp ep asid va)) := by + cases ep <;> simp [ExtArchCap.stage2FrameCap, ExtArchCap.objRef, hfr, absCapA, absFrameE, ArchCap.isFrameCap, ArchCap.acapObj, ArchCap.acapRights, ArchCap.acapFsize, archCapIsDevice, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, + isThreadCap, objRefOf] + by_cases hv : capA st sB src = .Frame ptr size rights false mp ep asid va ∧ capA st sB slot = .Thread t + swap + · rw [decide_eq_false hv] at hSV + refine skip hSV ?_ + by_cases hS : capA st sB src = .Frame ptr size rights false mp ep asid va + · have hI : capA st sB slot ≠ .Thread t := fun h => hv ⟨hS, h⟩ + have hnT : ¬ fl4TcbSameObject (.threadCap (specPtr t)) cI := by + rcases hkeepIB with h | h | ⟨zt, k, h⟩ + · exact absurd h hI + all_goals + rw [h] at hcI + rw [← CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)] + simp [absCapA, absFrameE, ArchCap.isFrameCap, ArchCap.acapObj, ArchCap.acapRights, ArchCap.acapFsize, archCapIsDevice, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] + exact bufMidInvA mS (by rw [eS hS]; exact hsameF) mI hnT + · have hnE : ¬ fl4TcbSameObject (absCapA fr) cS := by + rcases hkeepSB with h | h | ⟨zt, k, h⟩ + · exact absurd h hS + all_goals + rw [h] at hcS + rw [← CapEqA.eq_abs hcS (fun _ _ _ h => by cases h)] + simp [hfr, absCapA, absFrameE, ArchCap.isFrameCap, ArchCap.acapObj, ArchCap.acapRights, ArchCap.acapFsize, archCapIsDevice, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, + isThreadCap, objRefOf] + exact bufMidSrcA mS hnE + rw [decide_eq_true hv] at hSV + obtain ⟨hS, hI⟩ := hv + have hS' : capA st sB (cslotAddrA κsrc) = .Frame ptr size rights false mp ep asid va := by rw [hκsrc]; exact hS + have hwf : CapWfA fr := by + have h := JB.capWfA (y := cslotAddrA κsrc) hsrcSlot + rw [hS'] at h + obtain ⟨hr1', hr3', -, hsp⟩ := h + exact ⟨hr1', hr3', by simp, hsp⟩ + have hw' : CapRt.EncWf fr := by + have h : CapRt.EncWf (capAtA (L.mem sB) (cslotAddrA κsrc)) := CapRt.decodeF_encWf _ _ + rw [capAtA_eq (st := st), hS'] at h + have hc0 : CapRt.Canonical 0#u64 := Or.inl fun j hj _ => by simp + have h' : CapRt.EncWf (.Frame ptr size rights false mp ep asid va) := h + show CapRt.EncWf (.Frame ptr size rights false false false 0#u64 0#u64) + cases ep <;> (simp only [CapRt.EncWf] at h' ⊢; exact ⟨h'.1, h'.2.1, by simp, hc0⟩) + have hno : ¬ IrqNodeA (L.ksb sB) (fl4Ptr sl.1) := by + change ¬ IrqNodeA (L.ksb sB) (fl4Ptr (specPtr t)) + rw [fl4Ptr_specPtr] + intro h + have := JB.j.1.place.irqK ht h + cases this + -- the buffer's kernel address: liveness, alignment and the 128-word agreement + obtain ⟨hptrAl, hl⟩ := bufLiveOfFrameA JB.sys.ent.heap JB.sys.sysl.ly.h0 JB.sys.sysl.sys.fr hsrcOS hS hbits hbal hbn + have hw1024 := hl.2.1 + have faB : FrAgA st OS Ag sB σB := + FrAgA.stepA fa (fun b lv => FrameWordLive.keepA hkeepB lv) + (fun b al lv => mem_wr_ne' aM al fun e => + frameWord_ne_ibA Jd.sys.ent.heap Jd.sys.sysl.sys.fr hta htT lv e) rfl + have hagB : ∀ k : U64, k.val < 128 → (L.mem sB (bufW (bufAddrOfA ptr baddr bits) k)).bv = + loadWordAt σB.machineState.underlyingMemory (specPtr (bufW (bufAddrOfA ptr baddr bits) k)) := + fun k hk => faB _ (hsub ⟨k, hk, rfl⟩) (bufW_alignedLiveA hw1024 hk) (hl.2.2 k hk) + have hxOS : cslotAddrA κsrc ∈ OS := by rw [hκsrc]; exact hsrcOS + have hxy : cslotAddrA κsrc ≠ cslotAddrA sl := by rw [hκsrc]; exact hneS + have hsc0 : capA st sB (cslotAddrA κsrc) ≠ .Null := by rw [hS']; simp + have hdecIns : ∀ s2, cdt.insert st sB fr (cslotAddrA κsrc) (cslotAddrA sl) = ok s2 → + L.curW s2 = L.curW sB ∧ + ∀ s', (if t = L.curW s2 then sched.reschedule_required st s2 else ok s2) = ok s' → + tcb.install_buffer st ar s a t slot baddr (fr, src) = ok (.Ok (), s', ad) := fun s2 h2 => by + have hc2 : L.curW s2 = L.curW sB := by + have h := cdt.insert.curWA JB.sys.ent.os syslB.sys.stz.1.1.mdbS blk' hxOS hdOS hxy (JB.delCanG _ hdOS) + hsc0 hw' + rw [h2, WP.spec_ok] at h + exact h + refine ⟨hc2, fun s' h => ?_⟩ + rw [hκsrc] at h2 + rw [tcbInstallBuffer_liveA hdest hdel0 hBuf hSV h2, h] + simp only [bind_ok] + have hIP : ∀ G', cdt.insert st sB fr (cslotAddrA κsrc) (cslotAddrA sl) ⦃ s2 => SysL st H Z.Cs OS ia ie s2 ∧ + SymL st H Z.Cs s2 ∧ Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s2 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s2 ∧ + ∀ σ' m', J7A st (J7R2A st ar hPl.ipa) { Z with G := G', Q := Q, R := Rl, hw := hw } H OS s2 σ' m' ⦄ := fun G' => by + have hi : layout.tcb.SLOT_BUFFER.val < 7 := by simp [layout.tcb.SLOT_BUFFER] + have hhp := JB.sys.ent.heap + exact JB.insertP1A hA hPl (x := cslotAddrA κsrc) (y := cslotAddrA sl) (nc := fr) hxOS hdOS hxy + (JB.delCanG _ hdOS) hnullB + (Or.inr ⟨Or.inr ⟨ptr, size, rights, false, false, 0#u64, 0#u64, hfr⟩, + ⟨fun _ _ _ _ h => (by rw [hfr] at h; cases h), fun _ _ _ h => (by rw [hfr] at h; cases h)⟩⟩) + (by rw [← hslotIdx]; exact tcb_slot_notEptS hhp htT hi (by simp [layout.tcb.SLOT_BUFFER])) + ⟨slot, hslot, by rw [hI, ← hslotIdx]; exact CovZ.tcbSlot hhp htT hi⟩ hw' (by simp [hfr]) + (by rw [hS']; exact InsC.frame) (fun _ _ h => by rw [hS'] at h; cases h) (by rw [hS']; rfl) G' + have hibw : L.mem sB (ibWordA t) = baddr := by rw [ibWordA_eq]; exact L.mem_wr_same aM + have hspecB : ∀ x, σB.kheap (specPtr t) = some (.tcb x) → x.tcbIpcBuffer = baddr.bv := fun x hx => by + have e : σB.kheap (specPtr t) = some (.tcb { yd with tcbIpcBuffer := baddr.bv }) := by + simp [hσB, bufStateVA, updKSc_kheap, Function.update_apply] + rw [e] at hx + cases hx + rfl + obtain ⟨s2, σ2, hs2, hm, hbk, -, J2⟩ := JStage3A.capInsertTcbBufA (J := JB) κsrc sl (ps := ps) ⟨hss1, hss2⟩ + (t0 := t) ht hsl (by rw [hS']; simp) hnullB (JB.delCanG _ hdOS) + (nc := fr) (anc := absCapA fr) hwf (CapEqA.of_abs rfl) hw' (by simp [hfr]) + (by rw [hS']; exact Fl4ProofsA64.P3.DerivA.frame ptr size rights false mp ep asid va rights false false 0#u64 0#u64) + (by rw [hS']; exact ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by simp [hfr] at h⟩) + (by rw [hS']; trivial) (by rw [hS']; rfl) (by rw [hS']; rfl) (by rw [hS']; exact Or.inl rfl) + (fun r b' rs h _ => by + rw [hS'] at h + rcases h with h | h <;> simp [absCapA, absFrameE] at h) + (fun i h => by rw [hS'] at h; cases h) (fun i h => by simp [hfr] at h) (fun i h => by simp [hfr] at h) + (fun q k j h => by rw [hS'] at h; cases h) (fun h => by rw [hS'] at h; simp [isUtA] at h) (Or.inl hno) + (fun _ => by simp [hfr, CapValidA]) + ⟨fun _ _ h => by simp [hfr, absCapA, absFrameE] at h, fun _ h => by simp [hfr, absCapA, absFrameE] at h, + by simp [NoHiPtV, hfr, absCapA, absFrameE]⟩ + hl hagB ⟨ptr, size, rights, false, 0#u64, 0#u64, bits, rfl, hbits, hptrAl, rfl, hbal⟩ hibw hspecB + (fun s2 h2 => by + have h := hIP Gd + rw [h2, WP.spec_ok] at h + exact h.2.1) + (fun s2 h2 => by + have h := hIP Gd + rw [h2, WP.spec_ok] at h + exact h.1) + (fun s2 σ2 h2 _ => by + have h := hIP (insGA Gd (cslotAddrA κsrc) (cslotAddrA sl) + (insBA σB κsrc (absCapA fr) (absCapA (capA st sB (cslotAddrA κsrc))))) + rw [h2, WP.spec_ok] at h + exact h.2.2.2.2 σ2 m) + have wk := (capInsert_skA _ _ _ σB ((), σ2) hm).toDWkA + have B2 := BodyOKA.stepA B1 (delStep_ofKeepA hbk wk.off wk.ctSc) + obtain ⟨hc2, hd2⟩ := hdecIns s2 hs2 + obtain ⟨s', σ', Ac3, hs', hlast, J3, B3, c3⟩ := tail _ _ _ _ s2 σ2 J2 (hc2.trans hcurB) B2 + (PreO.trans (R := DSkA) dskB (capInsert_skA _ _ _ σB ((), σ2) hm)) + exact ⟨_, _, _, σ', hd2 s' hs', _, Q, Rl, hw, Ac3, _, _, J3, Or.inl ⟨rfl, + bufSpec_okA κs baddr (some (absCapA fr, κsrc)) hspec hyd + (bufMidInsA mS (by rw [eS hS]; exact hsameF) mI (by rw [eI hI]; exact hsameT) hm) hlast, B3, c3⟩⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbBufStepsA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbBufStepsA.lean index b8a9f032d..139af7f5a 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbBufStepsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbBufStepsA.lean @@ -2,14 +2,12 @@ P3 (aarch64, A64-P3 setipcbuf): **step lemmas of the SetIPCBuffer ≠ 0 arm** (`Stage3LiftTcbBufNzA`). * **`JStage3A.p1StepSyA`**: `JStage3A.p1StepA` with the `SysL ∧ SymL` at the post state given (not from a `DMD` step). -* **`JSyscallA.sysDelBufSetA`**: the `SysL ∧ SymL` after the caller's restart, the delete of slot 2 and the word write - `[t + 3512] := v` (`DelR` chain, as `tcb.install_buffer.sysL`). * **`tcbStillValidFr_keptA`**: after the delete, `still_valid` of the derived (unmapped) copy of a source Frame cap holds exactly when the source still holds that Frame cap and the invoked slot still holds the thread's cap. * **`tcbInstallBuffer_skipA`**: `install_buffer` when `still_valid` fails. -* **`setIpcBufG_invokeErrA`** / **`setIpcBufG_invokeA`**: the spec's `fl4InvokeTcb (.threadControlCaps .. (some (ptr, some - (newCap, src))))` from the outcome of its `cap_delete` (Preempted), and from the outcome `σm` of its two - `check_cap_at`s and `cap_insert` at the state after the `threadSet`. +* **`bufSpec_errA`** / **`bufSpec_okA`**: the spec's `fl4InstallTcbFrameCap` from the outcome of its `cap_delete` + (Preempted), and from the outcome `σm` of its two `check_cap_at`s and `cap_insert` at the state after the `threadSet`. +* **`bufSpec_invokeA`**: the buffer-only `fl4InvokeTcb` is that step. No named premise. New module. -/ @@ -70,34 +68,6 @@ theorem JStage3A.p1StepSyA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) variable {Clock : A → Fl4SpecA64.MachineState → Prop} -/-- **`SysL ∧ SymL` after the caller's restart, the delete of slot 2 of `t` and the write `[t + 3512] := v`** -(module docstring). -/ -theorem JSyscallA.sysDelBufSetA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) - (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) - {slot : U64} (hsl : slot ∈ OS) (hcov : SlotCov st OS s slot) - {extra : Aeneas.Std.Array obj.Slot 3#usize} - (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) - {t : U64} (hcap : capA st s slot = .Thread t) - (hstall : smp.remote_tcb_stall st ar s a t = ok (s, a)) {s1 : S} - (hr : tcb.restart_caller st s = ok s1) {sd : S} {ad : A} - (hdel : cdt.delete st ar s1 a (slotIdx t layout.tcb.SLOT_BUFFER) true = ok (.Ok (), sd, ad)) - (v : U64) (hv : v.val % 1024 = 0) : - SysL st H Z.Cs OS ia ie (L.wr sd (wa t 3512#u64) v) ∧ SymL st H Z.Cs (L.wr sd (wa t 3512#u64) v) := by - obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits, KLv, W⟩ := J7A.unp J.j7 - have I := J.toJStage3A.delIn hA hPl W - have D : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra := by - have := J.decPreA hsl hext - rwa [hcap] at this - have P := J.toJStage3A.sysPlace hext hsl hcov - have st1 := (WP.spec_ok _).1 (hstall ▸ smp.remote_tcb_stall.delS hA D I a t) - have R1 := (WP.spec_ok _).1 (hr ▸ tcb.restart_caller.delR I D P J.sys.sysl J.symL st1.1.1 st1.1.2 st1.2.1 st1.2.2) - have ht : t ∈ H.tcbs := D.cap.2.1 t rfl - have hx := R1.2.slot I ht (show layout.tcb.SLOT_BUFFER.val < 7 by simp [layout.tcb.SLOT_BUFFER]) - have R2 := (WP.spec_ok _).1 (hdel ▸ cdt.delete.delR (a := a) I R1.2 hx) - have R3 := obj.Tcb.set_ipc_buffer.delR I R2 ht hv - rw [eq_of_spec_fd (Fl4ProofsA64.P1.obj.Tcb.set_ipc_buffer.wr sd t v), WP.spec_ok] at R3 - exact ⟨R3.1.sys, R3.1.sym⟩ - end section @@ -148,51 +118,40 @@ end section spec -/-- **The spec's `invoke_tcb` for the buffer, when its `cap_delete` fails** (`Preempted`). -/ -theorem setIpcBufG_invokeErrA {σ1 σd : State Unit} {t : U64} (κs : CslotPtr) (ptr : VSpaceRef) +/-- **The spec's buffer step, when its `cap_delete` fails** (`Preempted`). -/ +theorem bufSpec_errA {σ σd : State Unit} {t : U64} (κs : CslotPtr) (ptr : VSpaceRef) (frame : Option (Cap × CslotPtr)) - (hdel : (.error (), σd) ∈ ((fl4CapDelete (Z := Unit) (specPtr t, tcbCnodeIndex 2)).run σ1).1) : - (.error (), σd) ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none (some (ptr, frame)))).run σ1).1 := by - have hrk : ∀ σ : State Unit, (.ok (), σ) ∈ ((NonDetE.returnOk (ε := Unit) ()).run σ).1 := fun σ => by - rw [run_returnOkD]; simp - simp only [fl4InvokeTcb, fl4InstallTcbCap, fl4InstallTcbFrameCap] - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - exact mem_bindE_errD (mem_bindE_errD hdel) - -/-- **The spec's `invoke_tcb` for the buffer from the outcome `σm` of its `check_cap_at`s and `cap_insert`** at the -state after the `threadSet`, then its `reschedule_required` when the target is the current thread. -/ -theorem setIpcBufG_invokeA {σ1 σd σm : State Unit} {t : U64} {y : Tcb} (κs : CslotPtr) {newCap : Cap} - {κsrc : CslotPtr} (v : U64) - (hdel : (.ok (), σd) ∈ ((fl4CapDelete (Z := Unit) (specPtr t, tcbCnodeIndex 2)).run σ1).1) + (hdel : (.error (), σd) ∈ ((fl4CapDelete (Z := Unit) (specPtr t, tcbCnodeIndex 2)).run σ).1) : + (.error (), σd) ∈ ((fl4InstallTcbFrameCap (Z := Unit) (specPtr t) κs (some (ptr, frame))).run σ).1 := by + simp only [fl4InstallTcbFrameCap] + exact mem_bindE_errD hdel + +/-- **The spec's buffer step** from the outcome `σm` of its `check_cap_at`s and `cap_insert` at the state after the +`threadSet`, then its `reschedule_required` when the target is the current thread. -/ +theorem bufSpec_okA {σ σd σm : State Unit} {t : U64} {y : Tcb} (κs : CslotPtr) (v : U64) + (frame : Option (Cap × CslotPtr)) + (hdel : (.ok (), σd) ∈ ((fl4CapDelete (Z := Unit) (specPtr t, tcbCnodeIndex 2)).run σ).1) (hy : σd.kheap (specPtr t) = some (.tcb y)) - (hmid : ((), σm) ∈ ((getCap (Z := Unit) κsrc >>= fun live => - Fl4Spec.NonDet.when (fl4TcbSameObject newCap live) (getCap (Z := Unit) κs >>= fun cap => - Fl4Spec.NonDet.when (fl4TcbSameObject (.threadCap (specPtr t)) cap) - (capInsert (Z := Unit) newCap κsrc (specPtr t, tcbCnodeIndex 2)))) (bufStateVA σd (specPtr t) y v)).1) + (hmid : ((), σm) ∈ ((match frame with + | none => Fl4Spec.NonDet.pure () + | some (newCap, κsrc) => getCap (Z := Unit) κsrc >>= fun live => + Fl4Spec.NonDet.when (fl4TcbSameObject newCap live) (getCap (Z := Unit) κs >>= fun cap => + Fl4Spec.NonDet.when (fl4TcbSameObject (.threadCap (specPtr t)) cap) + (capInsert (Z := Unit) newCap κsrc (specPtr t, tcbCnodeIndex 2)))) (bufStateVA σd (specPtr t) y v)).1) {σf : State Unit} (hlast : (σm.curThread ≠ specPtr t ∧ σf = σm) ∨ (σm.curThread = specPtr t ∧ ((), σf) ∈ (rescheduleRequired (Z := Unit) σm).1)) : - (.ok [], σf) ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none - (some (Fl4SpecA64.dataToVref v.bv, some (newCap, κsrc))))).run σ1).1 := by + (.ok (), σf) ∈ ((fl4InstallTcbFrameCap (Z := Unit) (specPtr t) κs + (some (Fl4SpecA64.dataToVref v.bv, frame))).run σ).1 := by have hset : threadSet (Z := Unit) (fun x : Tcb => { x with tcbIpcBuffer := Fl4SpecA64.dataToVref v.bv }) (specPtr t) σd = ({((), bufStateVA σd (specPtr t) y v)}, False) := threadSet_eqSc _ hy - have hrk : ∀ σ : State Unit, (.ok (), σ) ∈ ((NonDetE.returnOk (ε := Unit) ()).run σ).1 := fun σ => by - rw [run_returnOkD]; simp have hs1 : ((), bufStateVA σd (specPtr t) y v) ∈ ((threadSet (Z := Unit) (fun x : Tcb => { x with tcbIpcBuffer := Fl4SpecA64.dataToVref v.bv }) (specPtr t)) σd).1 := by rw [hset]; simp - simp only [fl4InvokeTcb, fl4InstallTcbCap, fl4InstallTcbFrameCap] - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σ1) (hrk σ1) ?_ - refine mem_bindE_okD (a := ()) (s' := σf) ?_ (by rw [run_returnOkD]; simp) + simp only [fl4InstallTcbFrameCap] refine mem_bindE_okD (a := ()) (s' := σd) hdel ?_ refine mem_bindE_okD (a := ()) (s' := bufStateVA σd (specPtr t) y v) (mem_liftED hs1) ?_ - refine mem_bindE_okD (a := ()) (s' := σm) (mem_liftED hmid) ?_ + refine mem_bindE_okD (a := ()) (s' := σm) (mem_liftED (by cases frame <;> exact hmid)) ?_ refine mem_bindE_okD (a := σm.curThread) (s' := σm) (mem_liftED ?_) ?_ · simp [Fl4Spec.NonDet.gets] · refine mem_liftED ?_ @@ -201,6 +160,25 @@ theorem setIpcBufG_invokeA {σ1 σd σm : State Unit} {t : U64} {y : Tcb} (κs : all_goals first | exact Set.mem_singleton _ | exact rfl | simp [Fl4Spec.NonDet.pure] · simpa [Fl4Spec.NonDet.when, if_pos he.symm] using hm +/-- **The spec's buffer-only `invoke_tcb`** is its buffer step. -/ +theorem bufSpec_invokeA {σ σ' : State Unit} {t : U64} (κs : CslotPtr) (ptr : VSpaceRef) + (frame : Option (Cap × CslotPtr)) : + ((.ok (), σ') ∈ ((fl4InstallTcbFrameCap (Z := Unit) (specPtr t) κs (some (ptr, frame))).run σ).1 → + (.ok [], σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none (some (ptr, frame)))).run σ).1) ∧ + ((.error (), σ') ∈ ((fl4InstallTcbFrameCap (Z := Unit) (specPtr t) κs (some (ptr, frame))).run σ).1 → + (.error (), σ') ∈ ((fl4InvokeTcb (.threadControlCaps (specPtr t) κs none none none none + (some (ptr, frame)))).run σ).1) := by + have hrk : ∀ σ : State Unit, (.ok (), σ) ∈ ((NonDetE.returnOk (ε := Unit) ()).run σ).1 := fun σ => by + rw [run_returnOkD]; simp + have e0 : ∀ i, fl4InstallTcbCap (Z := Unit) (specPtr t) κs i none = NonDetE.returnOk () := fun _ => rfl + refine ⟨fun h => ?_, fun h => ?_⟩ <;> simp only [fl4InvokeTcb, e0] <;> + refine mem_bindE_okD (a := ()) (s' := σ) (hrk σ) ?_ <;> + refine mem_bindE_okD (a := ()) (s' := σ) (hrk σ) ?_ <;> + refine mem_bindE_okD (a := ()) (s' := σ) (hrk σ) ?_ <;> + refine mem_bindE_okD (a := ()) (s' := σ) (hrk σ) ?_ + · exact mem_bindE_okD (a := ()) (s' := σ') h (by rw [run_returnOkD]; simp) + · exact mem_bindE_errD h + end spec section frag diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbChainA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbChainA.lean new file mode 100644 index 000000000..3ff963beb --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbChainA.lean @@ -0,0 +1,319 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP0a): **the delete engine re-entered from a mid-invocation record**. + +The syscall-entry lemmas `JSyscallA.delTreeA` / `delSiteA` / `delCanA` / `delHypsBaseA` / `delHypsTopA` read only fields of +`JStage3A` (the entry record's extra facts `act`, `running`, `curSc`, `cur` are not used), so here they are restated at an +arbitrary `JStage3A` state (`…G`), and + +* **`TcbMidA.delChainA`**: `cdt::delete` of a TCB slot `slotIdx t i` (`i < 7`) from a chain's mid state `TcbMidA`: the post of + `JSyscallA.restartDelGA` without the restart, plus P1's `DelR` kept (`cdt.delete.delR`, from the chain's `DelIn` / `DelR` + at its entry state `s0`). At `Ok` the record `TcbMidA` is re-established at the post state; at `Preempted` the exit facts + `BodyPreA`, `PreExitA` and `Clock` (the hpre carry) are exported. + +Named premises: `DelPlatA` [P], `hCs` [S], `ArchPlat`, `ArchTotal`; the chain's `Clock` / `CounterStepA` come from `TcbMidA.time` +(kept by `WPostA`'s exit), so there is no state-quantified premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbInstallA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {m : Fl4SpecA64.McState} +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {Clock : A → Fl4SpecA64.MachineState → Prop} {Ag : Set U64} + +/-- The CDT tree over the `OS` slots at a record state. -/ +theorem JStage3A.delTreeG {J7 : JSlotA S} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) : + TreeA st OS Z.G.chains Z.G.par s := + J.j.1.cdt.tree.grow J.j5.2.1 fun y hy hn => J.j5.2.2 y hy hn + +/-- The deletion's decode-site record at a record state. -/ +theorem JStage3A.delSiteG {J7 : JSlotA S} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) : + DelSiteA st Z.th OS s σ Z.G.chains := + ⟨J.finCov, J.frBase, ⟨J.j5.1.2.1.one, J.j5.1.2.1.chunk⟩, J.zwf⟩ + +/-- Every `OS` slot is a canonical address, at a record state. -/ +theorem JStage3A.delCanG {J7 : JSlotA S} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) : + ∀ x ∈ OS, obj.sext48 x = ok x := + fun _ hx => OSOK.canon J.sys.ent.os J.winOK hx + +/-- **`DelHypsA` at a syscall entry's own state** (no body facts). -/ +theorem JStage3A.delHypsBaseG [PlainStore st] {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (P : DelPlatA st ar AR Clock) (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) : + DelHypsA st ar H.tcbs Z.th OS Fl4SpecA64.fl4FinaliseCap + (DelWTopGA st Ag AR Z H OS U Pp Tb Lv ia ie N E Rp κ n m ar hPl.ipa Clock s) + (DelWxTopGA st Ag AR Z H OS U Pp Tb Lv ia ie N E Rp κ n m Clock s) + (DelWTopGA st Ag AR Z H OS U Pp Tb Lv ia ie N E Rp κ n m ar hPl.ipa Clock s) + (DelRdXA st ar Z H OS hPl.ipa (RvVcA st OS fun _ _ _ _ _ => True)) (DelRzA st) := by + have hY : PtHA H Z.Y := by + intro y hy + obtain ⟨q', z, hq', h1, h2⟩ := J.setsInH.roots y (Or.inr hy) + obtain ⟨g1, g2, -, -⟩ := root_pageA J.sys.ent.heap hq' h1 h2 (Or.inl rfl) + exact ⟨q', z, hq', g1, g2⟩ + exact delHypsA_topGA hPl P s (DelFootA.of_entA J.toJEntA) J.offAsE + (fun y hy j hj => ptHA_not_asW J.sys.ent.heap J.ko J.sys.ent.ksw hY hy hj) hCs + (Vcpu.vcpuHookA s P hCs) (DelS4A.ofHookA (Vcpu.vcpuHookA s P hCs)) + + +/-- **`DelHypsA` with the body facts** (module docstring). -/ +theorem JStage3A.delHypsTopG [PlainStore st] {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (P : DelPlatA st ar AR Clock) (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) + : + DelHypsA st ar H.tcbs Z.th OS Fl4SpecA64.fl4FinaliseCap + (DelWBodyA (DelWTopGA st Ag AR Z H OS U Pp Tb Lv ia ie N E Rp κ n m ar hPl.ipa Clock s) σ.curThread m) + (DelWBodyA (DelWxTopGA st Ag AR Z H OS U Pp Tb Lv ia ie N E Rp κ n m Clock s) σ.curThread m) + (DelWBodyPA (DelWTopGA st Ag AR Z H OS U Pp Tb Lv ia ie N E Rp κ n m ar hPl.ipa Clock s) σ.curThread m) + (DelRdXA st ar Z H OS hPl.ipa (RvVcA st OS fun _ _ _ _ _ => True)) (DelRzA st) := by + have H0 := J.delHypsBaseG (Ag := Ag) hPl P hCs + have step : ∀ {σ0 σ1 : Fl4SpecA64.State Unit}, DelBodyInvA σ.curThread m σ0 ∧ DelOwnA σ0 → DelStepCA σ0 σ1 → + DelBodyInvA σ.curThread m σ1 ∧ DelOwnA σ1 := fun h k => ⟨BodyOKA.stepA h.1 k, h.2.stepA k⟩ + have sk : ∀ {σ0 σ1 : Fl4SpecA64.State Unit}, CurScA σ0 → DSkA σ0 σ1 → DelStepCA σ0 σ1 := + fun h k => DelStepA.ofWk h k.toDWkA (Or.inl k) k.ch + refine + { agree := H0.agree + fin := finHookA_of_kinds fun k => ?_ + triv := fun s1 a1 σ1 G sl c D hW => H0.triv s1 a1 σ1 G sl c D hW.1 + pp := ?_ + post := ?_ + zomb := ?_ + swap := ?_ + empty := ?_ + wx := fun s1 a1 σ1 G hW => ⟨H0.wx s1 a1 σ1 G hW.1, hW.2⟩ } + · have H1 := H0.fin.kind k + cases k + case endpoint => + exact H1.bodyCapA finBodySpec_epA fun _ _ _ _ _ D h hsl => delW_epPrA D h hsl + case notification => + exact H1.bodyCapA finBodySpec_ntfnA fun _ _ _ _ _ D h hsl => delW_ntfnPrA D h hsl + case reply => + exact H1.bodyA finBodySpec_replyA fun _ _ _ _ h => + ⟨(delW_prA h).1.curSc, (delW_prA h).1.1.rlsRun, (delW_prA h).1.2.1⟩ + case irqHandler => + exact H1.bodyCapA finBodySpec_irqA fun _ _ _ _ _ D h hsl => delW_irqPrA D h hsl + case vcpu => + exact H1.bodyA finBodySpec_vcpuA fun _ _ _ _ h => (delW_prA h).1.notRunVm + case thread => + exact H1.bodyA finBodySpec_threadA fun _ _ _ _ h => ⟨(delW_prA h).1.curSc, (delW_prA h).1.notRunVm⟩ + case schedContext => exact H1.bodyCapA finBodySpec_scA fun _ _ _ _ _ D h hsl => delW_scPrA D h hsl + all_goals + exact H1.bodyA (Pr := fun _ => True) (finBodySpec_vsA (by simp)) fun _ _ _ _ _ => trivial + · intro s1 a1 σ1 G D hW + refine WP.spec_mono (H0.pp s1 a1 σ1 G D hW.1) ?_ + rintro r ⟨hc, σ2, D', hr⟩ + refine ⟨hc, σ2, D', ?_⟩ + have T := (delW_prA hW.1).2 + have mono : σ1.curTime ≤ rawNextA σ1.machineState := BitVec.le_trans T.1 T.2.2.1 + rcases hr with ⟨e, hm, hW'⟩ | ⟨e, hm, hW'⟩ + · refine Or.inl ⟨e, hm, hW', ?_⟩ + rcases preemptionPoint_casesA P.numDomains1 (P.rawNow σ1) hm with ⟨-, rfl⟩ | ⟨t, F⟩ + · exact hW.2 + · have own := hW.2.2.tickA t + exact ⟨ppBody_okA hW.2.1 t mono P.minAgree (F rfl) (delW_prA hW').2.1 own, own⟩ + · refine Or.inr ⟨e, hm, hW', ?_⟩ + rcases preemptionPoint_casesA P.numDomains1 (P.rawNow σ1) hm with ⟨c, -⟩ | ⟨t, -⟩ + · cases c + · exact ppBody_preA hW.2.1 t mono (delW_prA hW').2.1 (hW.2.2.tickA t) + · intro s1 a1 σ1 G cl D hW hcl hne hwf hno + refine WP.spec_mono (H0.post s1 a1 σ1 G cl D hW.1 hcl hne hwf hno) ?_ + rintro r ⟨hc, σ2, hm, D', hW'⟩ + obtain ⟨i, rfl⟩ : ∃ i, cl = .IrqHandler i := by + cases cl <;> simp [CleanCapA] at hcl hne + exact ⟨_, rfl⟩ + exact ⟨hc, σ2, hm, D', hW', step hW.2 (postCapIrq_dlA _ σ1 _ hm).step⟩ + · intro s1 s2 a1 σ1 σ2 G sl p zt k hW hRz hZ hNZ D D' w HS hset hA hne hz hcap M + refine ⟨H0.zomb s1 s2 a1 σ1 σ2 G sl p zt k hW.1 hRz hZ hNZ D D' w HS hset hA hne hz hcap M, step hW.2 ?_⟩ + refine sk (delW_prA hW.1).1.curSc (setCap_skA (absCapA (.Zombie p zt k)) sl σ1 ((), σ2) ?_) + rw [hset]; exact rfl + · intro s1 s2 a1 σ1 σ2 G sl p zt k hW h1 D D' w HS hm hA hz hne hcap M + exact ⟨H0.swap s1 s2 a1 σ1 σ2 G sl p zt k hW.1 h1 D D' w HS hm hA hz hne hcap M, + step hW.2 (sk (delW_prA hW.1).1.curSc (capSwapForDelete_skA _ _ σ1 _ hm))⟩ + · intro s1 s2 a1 σ1 σ2 G sl hW hRd D D' w HS hm hA hne h0 hcap M + exact ⟨H0.empty s1 s2 a1 σ1 σ2 G sl hW.1 hRd D D' w HS hm hA hne h0 hcap M, + step hW.2 (sk (delWx_prA hW.1).curSc (emptySlot_skA _ σ1 _ hm))⟩ + +set_option maxHeartbeats 8000000 in +/-- **`cdt::delete` of a TCB slot from a chain's mid state** (module docstring). `s0` is the chain's entry state with its +`DelIn`; `R` is P1's `DelR` from `s0` to the mid state `s`. -/ +theorem TcbMidA.delChainA [PlainStore st] {ct : ObjRef} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} + (hPl : ArchPlat ar) + (Md : TcbMidA st AR Clock ct Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar hPl.ipa Ag s a σ m) + (P : DelPlatA st ar AR Clock) (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) + {s0 : S} {Vc Ub Pt Ac1 : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} + (I : DelIn st ar H Z.Cs OS Vc Ub Pt K Ty s0) (R : DelR st H Z.Cs OS Vc Ub Ac1 Ty ia ie s0 s) + (sl : Fl4SpecA64.CslotPtr) (hAd : AbsSlotA Z.th sl) {t i : U64} (ht : t ∈ H.tcbs) (hi : i.val < 7) + (hsl : cslotAddrA sl = slotIdx t i) : + cdt.delete st ar s a (cslotAddrA sl) true ⦃ res => + DelR st H Z.Cs OS Vc Ub Ac1 Ty ia ie s0 res.2.1 ∧ + ∃ σ' G', DStateA st Z.th OS res.2.1 σ' G' ∧ + ((res.1 = .Ok () ∧ capA st res.2.1 (cslotAddrA sl) = .Null ∧ + ((.ok (), σ') ∈ ((capDeleteGA Fl4SpecA64.fl4FinaliseCap sl).run σ).1) ∧ + (∀ y ∈ OS, y ≠ cslotAddrA sl → ChgZA st s res.2.1 y) ∧ + ∃ (Q : U64 → U64 → List U64) (Rl : U64 → List U64) (hw : HwRootA) (Ac' : Set U64) + (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64), + TcbMidA st AR Clock ct { Z with G := G', Q := Q, R := Rl, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' + κ n ar hPl.ipa Ag res.2.1 res.2.2 σ' m) ∨ + (res.1 = .Err .Preempted ∧ + ((.error (), σ') ∈ ((capDeleteGA Fl4SpecA64.fl4FinaliseCap sl).run σ).1) ∧ + BodyPreA σ' m ∧ σ'.curThread = σ.curThread ∧ PreExitA σ' ∧ Clock res.2.2 σ'.machineState ∧ + ∃ (Q : U64 → U64 → List U64) (Rl : U64 → List U64) (hw : HwRootA) (Ac' : Set U64) + (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64), + JStage3A st AR { Z with G := G', Q := Q, R := Rl, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' κ n + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) res.2.1 res.2.2 σ' m)) ⦄ := by + obtain rfl : ct = σ.curThread := Md.body.2.1.symm + have hT := Md.J.delTreeG + have D1 : DStateA st Z.th OS s σ Z.G := + DStateA.ofEntA Md.J.toJEntA hT Md.J.j5.2.1 Md.J.j5.2.2 Md.J.delSiteG + have JT := Md.J.toTA Md.sact Md.nsw + have JL : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7LA st (J7R2A st ar hPl.ipa)) + s a σ m := { JT with j7 := J7A.toLA JT.j7 } + have fx : DelCapFxA st Z H s := + { fhSlot := fun t ht => isSlot_fhA ((Md.J.sr.thT t).2 ht) + fhOK := Md.J.fhOK + ptCapIn := Md.J.ptCapIn } + have X : DelXA6G st Ag AR Z H OS U Pp Tb Lv ia ie N E Rp κ n m (J5A st) (J7LA st (J7R2A st ar hPl.ipa)) s a σ Z.G := + ⟨⟨Z.Q, Z.R, Z.hw, Ac, Bf, stack, JL, Std6GA.ofJA Md.J Md.fr⟩, Md.J.j5.1.1.parentAdj, Md.J.zombieNoVcpu, + Md.J.sys.sysl.bh, Md.J.sys.sysl.ct, fx⟩ + have hW1 : DelWBodyA (DelWTopGA st Ag AR Z H OS U Pp Tb Lv ia ie N E Rp κ n m ar hPl.ipa Clock s) σ.curThread m s a σ Z.G := + ⟨⟨⟨⟨rfl, rfl⟩, X, Md.J.schedValid⟩, Md.time⟩, Md.body, Md.own⟩ + have hx : slotIdx t i ∈ OSN OS (L.ksb s0) := R.slot I ht hi + have hdel := delete_exposedGA Md.J.sys.ent.os Md.J.delCanG (Md.J.delHypsTopG (Ag := Ag) hPl P hCs) sl hAd s a σ Z.G D1 + hW1 + have hdR : cdt.delete st ar s a (cslotAddrA sl) true ⦃ r => DelR st H Z.Cs OS Vc Ub Ac1 Ty ia ie s0 r.2.1 ⦄ := by + rw [hsl]; exact cdt.delete.delR I R hx + refine WP.spec_mono (WP.spec_and hdel hdR) ?_ + rintro ⟨r1, s1, a1⟩ ⟨⟨σ', G', D', -, -, hres, hW'⟩, hR⟩ + refine ⟨hR, σ', G', D', ?_⟩ + rcases hres with ⟨h1, ⟨v, hv⟩, hnul, -, hch⟩ | ⟨h1, hv⟩ + · subst h1 + have Pr := delW_prA hW'.1 + obtain ⟨⟨⟨-, X', sv⟩, tm⟩, Binv, Own⟩ := hW' + obtain ⟨Q, Rl, hw, Ac', Bf', stack', Jd⟩ := X'.toStage3A hR.sys hR.sym sv + obtain ⟨⟨Q0, R0, hw0, Ac0, Bf0, stack0, J0, Φ⟩, -⟩ := X' + exact Or.inl ⟨rfl, hnul, capDeleteGA_ok hv, fun y hy hne => hch y hy hne, Q, Rl, hw, Ac', Bf', stack', + { J := Jd, sact := Pr.1.2.1, nsw := Binv.2.2.1, body := Binv, own := Own, time := Pr.2, fr := Φ.frAg }⟩ + · subst h1 + obtain ⟨hWt, hpp, hcur, hns, hps, hown⟩ := hW' + have Pr := delW_prA hWt + obtain ⟨⟨-, X', sv⟩, tm⟩ := hWt + obtain ⟨Q, Rl, hw, Ac', Bf', stack', Jd⟩ := X'.toStage3A hR.sys hR.sym sv + refine Or.inr ⟨rfl, capDeleteGA_err hv, hpp, hcur, ⟨hns, fun d p => ?_, fun x hx => ?_, ?_, fun hr x hx => ?_, + hown.1, hown.2⟩, Pr.2.2.1, Q, Rl, hw, Ac', Bf', stack', Jd⟩ + · rw [hcur]; exact hps.1 d p + · exact hps.2.1 x (by rw [← hcur]; exact hx) + · rw [hcur]; exact hps.2.2.1 + · exact hps.2.2.2 hr x (by rw [← hcur]; exact hx) + + +set_option maxHeartbeats 16000000 in +/-- **One chain step: `install_tcb_cap` of TCB slot `i ≠ 2, 5` from a mid state** (module docstring): `delChainA`, then +`TcbMidA.installTcbCapA` with the P1 facts from the record (`JStage3A.tcbInsP1A`), and P1's `DelR` kept across the call +(`tcb.install_tcb_cap.delR`). `hS` / `hI` say the source slot and the invoked slot still hold (or lost, by this chain) +the caps the decode read (`c0`, the thread cap). -/ +theorem TcbMidA.chainStepA [PlainStore st] {ct : ObjRef} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (Md : TcbMidA st AR Clock ct Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar hPl.ipa Ag s a σ m) + (P : DelPlatA st ar AR Clock) (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) + {s0 : S} {Vc Ub Pt Ac1 : Set U64} {K0 : capability.Cap → Prop} {Ty : S → Prop} + (I : DelIn st ar H Z.Cs OS Vc Ub Pt K0 Ty s0) (R : DelR st H Z.Cs OS Vc Ub Ac1 Ty ia ie s0 s) + {t idx slot src : U64} {i : Nat} (ht : Z.th t = some .tcb) (hidx : idx.val = i) (hi : i < 7) (hi2 : i ≠ 2) + (hi5 : i ≠ 5) (hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t) + (hroot : obj.Tcb.slot t idx = ok (cslotAddrA (specPtr t, tcbCnodeIndex i))) + {κs κsrc : CslotPtr} (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) {ps : U64} + (hCs' : κsrc.1 = specPtr ps ∧ Z.th ps = some (.cnode κsrc.2.length)) (hκsrc : cslotAddrA κsrc = src) + (hsrc0 : src ≠ 0#u64) (hsrcOS : src ∈ OS) (hslotOS : slot ∈ OS) + (hneS : src ≠ cslotAddrA (specPtr t, tcbCnodeIndex i)) (hneI : slot ≠ cslotAddrA (specPtr t, tcbCnodeIndex i)) + {nc c0 : capability.Cap} {anc : Fl4SpecA64.Cap} + (hnn : nc = .Null → anc = .nullCap) (Kn : nc ≠ .Null → TcbInsKA H Z.th m n i nc c0 anc) + (hder : nc ≠ .Null → ∀ s' : S, objects.derive_cap st s' src c0 = ok (.Ok nc) ∨ + ∃ p r gs g gs' g', c0 = .CNode p r gs g ∧ nc = .CNode p r gs' g') + (hnc : nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) + (hS : capA st s src = c0 ∨ capA st s src = .Null ∨ HomeZA st s src) + (hI : capA st s slot = .Thread t ∨ capA st s slot = .Null ∨ HomeZA st s slot) : + ∃ (r : core.result.Result Unit error.Exc) (s2 : S) (a2 : A) (σ' : Fl4SpecA64.State Unit), + tcb.install_tcb_cap st ar s a t slot idx nc src = ok (r, s2, a2) ∧ + DelR st H Z.Cs OS Vc Ub Ac1 Ty ia ie s0 s2 ∧ + ((r = .Ok () ∧ (.ok (), σ') ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs i (some (anc, κsrc))).run σ).1 ∧ + (∀ y ∈ OS, y ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) → ChgZA st s s2 y) ∧ + (capA st s2 (cslotAddrA (specPtr t, tcbCnodeIndex i)) = .Null ∨ + capA st s2 (cslotAddrA (specPtr t, tcbCnodeIndex i)) = nc) ∧ + ∃ (Gi : MdbGhostA) (Q : U64 → U64 → List U64) (Rl : U64 → List U64) (hw : HwRootA) (Ac' : Set U64) + (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64), + TcbMidA st AR Clock ct { Z with G := Gi, Q := Q, R := Rl, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' + κ n ar hPl.ipa Ag s2 a2 σ' m) ∨ + (r = .Err .Preempted ∧ + (.error (), σ') ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs i (some (anc, κsrc))).run σ).1 ∧ + BodyPreA σ' m ∧ σ'.curThread = σ.curThread ∧ PreExitA σ' ∧ Clock a2 σ'.machineState ∧ + ∃ (Gi : MdbGhostA) (Q : U64 → U64 → List U64) (Rl : U64 → List U64) (hw : HwRootA) (Ac' : Set U64) + (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64), + JStage3A st AR { Z with G := Gi, Q := Q, R := Rl, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' κ n + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s2 a2 σ' m)) := by + set sl : Fl4SpecA64.CslotPtr := (specPtr t, tcbCnodeIndex i) with hsl + have hAd : AbsSlotA Z.th sl := ⟨t, rfl, Or.inr ⟨ht, i, hi, rfl⟩⟩ + have htT : t ∈ H.tcbs := by rw [Md.J.tcbs]; exact (Md.J.j.1.thT t).1 ht + have hAs' : AbsSlotA Z.th κsrc := ⟨ps, hCs'.1, Or.inl hCs'.2⟩ + have hi' : idx.val < 7 := by rw [hidx]; exact hi + have hslotIdx : slotIdx t idx = cslotAddrA sl := okinj ((tcb_slot_val _ _).symm.trans hroot) + have hdOS : cslotAddrA sl ∈ OS := Md.J.j5.2.1 _ (hAd.isSlot Md.J.j.1.place) + have hcan : obj.sext48 (cslotAddrA sl) = ok (cslotAddrA sl) := Md.J.delCanG _ hdOS + have hdelP := Md.delChainA hPl P hCs I R sl hAd htT hi' hslotIdx.symm + have hdR : tcb.install_tcb_cap st ar s a t slot idx nc src ⦃ r => DelR st H Z.Cs OS Vc Ub Ac1 Ty ia ie s0 r.2.1 ⦄ := + tcb.install_tcb_cap.delR I R htT hi' (by rw [hidx]; exact hi2) hslotOS (fun h => hsrcOS) hnc (by rw [hidx]; exact hi5) + obtain ⟨⟨r, sd, ad⟩, hdel0, hRd, σd, Gd, Dd, hres⟩ := spec_existsA hdelP + rcases hres with ⟨h1, hnull, hspec, hch, Q, Rl, hw, Ac', Bf', stack', Md2⟩ | ⟨h1, hspec, hpp, hcur, hpre, hclk, Q, Rl, hw, Ac', Bf', stack', Jd⟩ + · subst h1 + have hdel1 : cdt.delete st ar s a (cslotAddrA sl) true = ok (.Ok (), sd, ad) := hdel0 + have hkS : capA st sd src = c0 ∨ capA st sd src = .Null ∨ HomeZA st sd src := by + rcases hch src hsrcOS hneS with h | h | h + · rcases hS with e | e | e + · exact Or.inl (h.trans e) + · exact Or.inr (Or.inl (h.trans e)) + · exact Or.inr (Or.inr (by obtain ⟨zt, k, e'⟩ := e; exact ⟨zt, k, h.trans e'⟩)) + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr h) + have hkI : capA st sd slot = .Thread t ∨ capA st sd slot = .Null ∨ HomeZA st sd slot := by + rcases hch slot hslotOS hneI with h | h | h + · rcases hI with e | e | e + · exact Or.inl (h.trans e) + · exact Or.inr (Or.inl (h.trans e)) + · exact Or.inr (Or.inr (by obtain ⟨zt, k, e'⟩ := e; exact ⟨zt, k, h.trans e'⟩)) + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr h) + have hP1 : nc ≠ .Null → capA st sd src = c0 → capA st sd slot = .Thread t → + TcbInsP1A st ar hPl.ipa { Z with G := Gd, Q := Q, R := Rl, hw := hw } H OS ia ie m sd σd nc anc κsrc sl := + fun hn hSd hId => Md2.J.tcbInsP1A hA hPl ht hidx hi hi2 hi5 hroot hslotOS hId hAs' hκsrc hsrcOS hneS hnull hcan + (Kn hn) hSd (hder hn sd) + obtain ⟨s2, σ2, Gi, hR, hS2, Md3, hbk, ek, hdd⟩ := Md2.installTcbCapA ht hi hi2 hidles hroot hdel1 hspec hnull hcan + hAκ hκ hCs' hκsrc hsrc0 hnn Kn hkS hkI hP1 + have hDR := hdR + rw [hR] at hDR + refine ⟨.Ok (), s2, ad, σ2, hR, (by have h := (WP.spec_ok _).1 hDR; exact h), Or.inl ⟨rfl, hS2, fun y hy hne => ?_, hdd, ?_⟩⟩ + · exact (hch y hy hne).trans (ChgZA.of_eq (ek y hy hne)) + · exact ⟨Gi, Q, Rl, hw, Ac', Bf', stack', Md3⟩ + · subst h1 + obtain ⟨hR, hS⟩ := tcbInstallCap_preemptedA (target := t) (src := src) (nc := nc) (slot := slot) (κs := κs) + (κsrc := κsrc) (anc := anc) hroot (hdel0) hspec + have hDR := hdR + rw [hR] at hDR + exact ⟨.Err .Preempted, sd, ad, σd, hR, (by have h := (WP.spec_ok _).1 hDR; exact h), + Or.inr ⟨rfl, hS, hpp, hcur, hpre, hclk, Gd, Q, Rl, hw, Ac', Bf', stack', Jd⟩⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbChainHelpA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbChainHelpA.lean new file mode 100644 index 000000000..ad983b328 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbChainHelpA.lean @@ -0,0 +1,114 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP2): **small helpers of the SetSpace / Configure chains**. + +* `chgZ_keepA`: a slot that held `c` (or was lost to this chain: null, a zombie's home) keeps that disjunction across a + `ChgZA` step. +* `JStage3A.tcbSrcCnA`: an extra-slot address of the decode is a CNode slot of the typed heap. +* `tcbSlotNeA`: a CNode slot is no TCB cap slot. +* `setSpace_specA`, `setSpace_specPre{3,0,1}A`: the spec's `invoke_tcb` of a SetSpace (`threadControlCaps` with fault + handler, CSpace and VSpace roots) from the outcomes of its three `fl4InstallTcbCap`s. + +New module; no premise. +-/ +import Fl4ProofsA64.P3.Stage3TcbSetSpaceSelA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +theorem chgZ_keepA {s0 s1 : S} {y : U64} {c : capability.Cap} (h : ChgZA st s0 s1 y) + (hy : capA st s0 y = c ∨ capA st s0 y = .Null ∨ HomeZA st s0 y) : + capA st s1 y = c ∨ capA st s1 y = .Null ∨ HomeZA st s1 y := by + rcases h with e | e | e + · rcases hy with h | h | ⟨zt, k, h⟩ + · exact Or.inl (e.trans h) + · exact Or.inr (Or.inl (e.trans h)) + · exact Or.inr (Or.inr ⟨zt, k, e.trans h⟩) + · exact Or.inr (Or.inl e) + · exact Or.inr (Or.inr e) + +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {J7 : JSlotA S} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + +/-- **An extra-slot address of the decode is a CNode slot** (module docstring). -/ +theorem JStage3A.tcbSrcCnA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) + {x : U64} (hSC : SlotCov st OS s x) {κx : CslotPtr} (hAx : AbsSlotA Z.th κx) (hκx : cslotAddrA κx = x) : + ∃ ps, κx.1 = specPtr ps ∧ Z.th ps = some (.cnode κx.2.length) := by + obtain ⟨ss', ps, hss1, hss2, hss3, -⟩ := J.cnSlot_of_covA hSC + have ess : κx = ss' := cslotAddrA_inj J.j.1.place hAx ⟨ps, hss1, Or.inl hss2⟩ (hκx.trans hss3.symm) + subst ess + exact ⟨ps, hss1, hss2⟩ + +/-- **A CNode slot is no TCB cap slot** (module docstring). -/ +theorem tcbSlotNeA {th : TypedHeapA} {kb : U64} (hP : PlaceA th kb) {κ0 : CslotPtr} {ps t : U64} {i : Nat} + (hi : i < 7) (hA0 : AbsSlotA th κ0) (hc : κ0.1 = specPtr ps ∧ th ps = some (.cnode κ0.2.length)) + (hthT : th t = some .tcb) : cslotAddrA κ0 ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) := fun e => by + have hAd : AbsSlotA th (specPtr t, tcbCnodeIndex i) := ⟨t, rfl, Or.inr ⟨hthT, i, hi, rfl⟩⟩ + have h := cslotAddrA_inj hP hA0 hAd e + have e1 : specPtr ps = specPtr t := by rw [← hc.1, h] + have h2 := hc.2 + rw [specPtr_inj e1, hthT] at h2 + cases h2 + +section spec +variable {σ1 σ2 σ3 σ4 : Fl4SpecA64.State Unit} {t : ObjRef} {κs : CslotPtr} {fh0 c0 v0 : Cap × CslotPtr} + +theorem setSpace_specA + (h3 : (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 3 (some fh0)).run σ1).1) + (h0 : (.ok (), σ3) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 0 (some c0)).run σ2).1) + (h1 : (.ok (), σ4) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 1 (some v0)).run σ3).1) : + (.ok [], σ4) ∈ ((fl4InvokeTcb (.threadControlCaps t κs (some fh0) none (some c0) (some v0) none)).run σ1).1 := by + have hSkip (n : Nat) : fl4InstallTcbCap (Z := Unit) t κs n none = Fl4Spec.NonDetE.returnOk () := rfl + have hFrame : fl4InstallTcbFrameCap (Z := Unit) t κs none = Fl4Spec.NonDetE.returnOk () := rfl + simp only [fl4InvokeTcb, hSkip, hFrame] + refine mem_bindE_okD h3 ?_ + rw [run_bind_okD (run_returnOkD () σ2)] + refine mem_bindE_okD h0 ?_ + refine mem_bindE_okD h1 ?_ + rw [run_bind_okD (run_returnOkD () σ4)] + rfl + +theorem setSpace_specPre3A + (h3 : (.error (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 3 (some fh0)).run σ1).1) : + (.error (), σ2) ∈ ((fl4InvokeTcb (.threadControlCaps t κs (some fh0) none (some c0) (some v0) none)).run σ1).1 := by + simp only [fl4InvokeTcb] + exact mem_bindE_errD h3 + +theorem setSpace_specPre0A + (h3 : (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 3 (some fh0)).run σ1).1) + (h0 : (.error (), σ3) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 0 (some c0)).run σ2).1) : + (.error (), σ3) ∈ ((fl4InvokeTcb (.threadControlCaps t κs (some fh0) none (some c0) (some v0) none)).run σ1).1 := by + have hSkip (n : Nat) : fl4InstallTcbCap (Z := Unit) t κs n none = Fl4Spec.NonDetE.returnOk () := rfl + simp only [fl4InvokeTcb, hSkip] + refine mem_bindE_okD h3 ?_ + rw [run_bind_okD (run_returnOkD () σ2)] + exact mem_bindE_errD h0 + +theorem setSpace_specPre1A + (h3 : (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 3 (some fh0)).run σ1).1) + (h0 : (.ok (), σ3) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 0 (some c0)).run σ2).1) + (h1 : (.error (), σ4) ∈ ((fl4InstallTcbCap (Z := Unit) t κs 1 (some v0)).run σ3).1) : + (.error (), σ4) ∈ ((fl4InvokeTcb (.threadControlCaps t κs (some fh0) none (some c0) (some v0) none)).run σ1).1 := by + have hSkip (n : Nat) : fl4InstallTcbCap (Z := Unit) t κs n none = Fl4Spec.NonDetE.returnOk () := rfl + simp only [fl4InvokeTcb, hSkip] + refine mem_bindE_okD h3 ?_ + rw [run_bind_okD (run_returnOkD () σ2)] + refine mem_bindE_okD h0 ?_ + exact mem_bindE_errD h1 + +end spec + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbChainIfaceA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbChainIfaceA.lean new file mode 100644 index 000000000..d38ef9cd0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbChainIfaceA.lean @@ -0,0 +1,66 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP0a): **the interface of a chain of TCB slot installs** (Configure, SetSpace, SetHighVSpace, +SetSchedParams): two definitions only, so that `JStage3A.delChainA` (CP0a) and `JStage3A.installTcbCapA` (CP0b) are written +against fixed statements. + +* **`TcbMidA`**: the data at a *mid-invocation* state `(s, a, σ)` (after the caller's restart and `k ≥ 0` complete installs) that + re-enters the delete engine: the unified record `JStage3A`, the scheduler facts (`SActA`, no pending switch), the delete body + invariant against the chain's *entry* thread `ct` (`DelBodyInvA ct m σ`, `DelOwnA σ`), the time / clock facts + (`DelPpTimeA Clock a σ` = `ValidMachineTimeA ∧ Clock ∧ CounterStepA ∧ CurEntryGA`) and the frame agreement `FrAgA st OS Ag s σ` + (`Ag = ∅` when no buffer is installed). Every field is exported at `Ok` by `WPostA` (`DelWBodyA (DelWTopGA …)`) and kept by an + install (`DelStepA`), so it is never a premise at a mid state. +* **`TcbChainOutA`**: the outcome of the *rest* of a chain from a state `σ`: `Ok` with the spec's invocation performed from the + restarted state `σ1`, the record and `BodyEndA`; or `Preempted` with the spec's error, the record, `BodyPreA`, the exit facts + `PreExitA` and `Clock` (the hpre carry; `TcbDelOutA` lacked the last two). + +`JStage3A.delChainA` (CP0a): from `TcbMidA … s a σ` and a slot `sl` of the target, `cdt::delete st ar s a (cslotAddrA sl) true` +returns the post of `restartDelGA` at `(s, a, σ)` and the `TcbMidA` at the post state at `Ok`. `JStage3A.installTcbCapA` (CP0b): +`tcb.install_tcb_cap` at a `TcbMidA` state returns `TcbMidA` at the post state at `Ok` and the preempted exit at `Preempted`. +New module; no premise. +-/ +import Fl4ProofsA64.P3.Stage3TcbDelGA +import Fl4ProofsA64.P3.Stage3LiftTcbBufA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} (st : machine.Store S) [L : LawfulStore st] {A : Type} + +/-- **The mid-invocation state of a TCB install chain** (module docstring). `ct` is the chain's entry thread. -/ +structure TcbMidA (AR : A → HwRootA → Prop) (Clock : A → Fl4SpecA64.MachineState → Prop) (ct : ObjRef) + (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) (N E Rp : Set U64) + (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (n : Nat) (ar : machine.Arch A) + (ipa : U64) (Ag : Set U64) (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) : Prop where + J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar ipa)) s a σ m + sact : SActA σ + nsw : ∀ u, σ.schedulerAction ≠ .switchThread u + body : DelBodyInvA ct m σ + own : DelOwnA σ + time : DelPpTimeA Clock a σ + fr : FrAgA st OS Ag s σ + +/-- **The outcome of the rest of a chain** (module docstring), for the invocation `Inv` (the invoked slot's ghost name fixed) run from the restarted state `σ1`. -/ +def TcbChainOutA (AR : A → HwRootA → Prop) (Clock : A → Fl4SpecA64.MachineState → Prop) + (Z : XSetsA) (H : Heap) (OS U Ac Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) (N E Rp : Set U64) + (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (κ : U64 → U64) (n : Nat) (m : Fl4SpecA64.McState) + (ar : machine.Arch A) (ipa : U64) (σ σ1 : Fl4SpecA64.State Unit) (Inv : TcbInvocation) + (r : core.result.Result Unit error.Exc) (s3 : S) (a3 : A) : Prop := + ∃ (σ3 : Fl4SpecA64.State Unit) (G' : MdbGhostA) (Q : U64 → U64 → List U64) (R : U64 → List U64) (hw : HwRootA) (Ac' : Set U64) + (Bf' : Set (U64 × Fl4SpecA64.Word)) (stack' : U64 → List U64), + JStage3A st AR { Z with G := G', Q := Q, R := R, hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf' stack' κ n + (J5A st) (J7A st (J7R2A st ar ipa)) s3 a3 σ3 m ∧ + ((r = .Ok () ∧ ((.ok [], σ3) ∈ ((fl4InvokeTcb Inv).run σ1).1) ∧ Sched.BodyEndA σ σ3 m) ∨ + (r = .Err .Preempted ∧ ((.error (), σ3) ∈ ((fl4InvokeTcb Inv).run σ1).1) ∧ + BodyPreA σ3 m ∧ σ3.curThread = σ.curThread ∧ PreExitA σ3 ∧ Clock a3 σ3.machineState)) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbChainStartA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbChainStartA.lean new file mode 100644 index 000000000..b3ee467a8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbChainStartA.lean @@ -0,0 +1,101 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP2): **the start of a TCB install chain at a syscall entry**: the (quiet) remote stall, the +caller's restart, and the chain's records at the restarted state. + +* **`JSyscallA.tcbChainStartA`**: from the entry record and the entry agreement `hag` of the frame words `Ag`: + `tcb::restart_caller` and the spec's `setThreadState cur .restart` (the same step `restartDelGA` takes), the chain record + `TcbMidA` at the restarted state, and P1's `DelIn` (at the entry state `s`) with `DelR s s1` (`tcb.restart_caller.delR` + after the stall), the inputs `TcbMidA.chainStepA` carries along the chain. + +Named premises: those of `JSyscallA.restartDelGA` (`hCl`, `hCnt`, `hag` [S]), [P] `ArchTotal`, `ArchPlat`; [S] the stall +`hstall` (`numNodes = 1`). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbChainA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {Clock : A → Fl4SpecA64.MachineState → Prop} {Ag : Set U64} + +set_option maxHeartbeats 8000000 in +/-- **The start of a chain** (module docstring). -/ +theorem JSyscallA.tcbChainStartA [PlainStore st] (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hCnt : CounterStepA σ) (hCl : Clock a σ.machineState) (hag : FrAgA st OS Ag s σ) + {slot : U64} (hsl : slot ∈ OS) (hcov : SlotCov st OS s slot) + {extra : Aeneas.Std.Array obj.Slot 3#usize} (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) + {t : U64} (hcap : capA st s slot = .Thread t) (hstall : smp.remote_tcb_stall st ar s a t = ok (s, a)) : + ∃ (x : Fl4SpecA64.Tcb), + σ.kheap σ.curThread = some (.tcb x) ∧ + tcb.restart_caller st s = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) ∧ + (∀ y ∈ OS, capA st (L.wr s (stA (L.curW s)) sched.TS_RESTART) y = capA st s y) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + TcbMidA st AR Clock σ.curThread Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar hPl.ipa Ag + (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (stUpdA σ σ.curThread x .restart) m ∧ + ∃ (Vc Ub Pt Ac1 : Set U64) (K0 : capability.Cap → Prop) (Ty : S → Prop) + (I : DelIn st ar H Z.Cs OS Vc Ub Pt K0 Ty s), + DelR st H Z.Cs OS Vc Ub Ac1 Ty ia ie s (L.wr s (stA (L.curW s)) sched.TS_RESTART) := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hsl hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨x, hkx, -, -, J', -, hOK, -⟩ := J.toJStage3A.of_restartCurA (J.toJStage3A.sysPlace hext hsl hcov) + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + obtain ⟨x2, hkx2, heq, hset, -, -, -, -, -⟩ := J.toJEntA.restartA (J.toJStage3A.sysPlace hext hsl hcov) J.symL + J.running RS.cur RS.vs RS.vc + obtain rfl : x = x2 := by + rw [hkx] at hkx2 + cases hkx2 + rfl + have hr : tcb.restart_caller st s = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, heq] + have noSw : ∀ u, (stUpdA σ σ.curThread x .restart).schedulerAction ≠ .switchThread u := fun u h => by + have h' : σ.schedulerAction = .switchThread u := h + rw [J.act] at h' + cases h' + have sact : SActA (stUpdA σ σ.curThread x .restart) := + { f1 := fun u h => absurd h (noSw u) + f2 := ⟨{ x with tcbState := .restart }, by simp [stUpdA, setObjA], Or.inr (Or.inl rfl)⟩ } + have V : ValidMachineTimeA (stUpdA σ σ.curThread x .restart) := J.validTime + have CE : CurEntryGA (stUpdA σ σ.curThread x .restart) := + (CurEntryGA.of_cur J.toJStage3EntryA.curInv J.toJStage3EntryA.offReady J.sr.inv).keepA + (tcbW_tmA (x' := { x with tcbState := .restart }) hkx (fun _ h => h)).2.2.2 (BitVec.le_refl _) + have htZ : L.curW s ∈ Z.T := J.sr.curT + have hta : TcbAddr (L.curW s) := J.sr.core.tcbs _ htZ + have sA : Aligned (stA (L.curW s)) := by rw [stA_eq]; exact field_aligned hta (by simp) (by simp) + have JT0 := J.toJStage3A.toTA J.sact J.noSwitch + have JL0 : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7LA st (J7R2A st ar hPl.ipa)) + s a σ m := { JT0 with j7 := J7A.toLA JT0.j7 } + have fa : FrAgA st OS Ag (L.wr s (stA (L.curW s)) sched.TS_RESTART) (stUpdA σ σ.curThread x .restart) := + FrAgA.stepA hag (fun b lv => FrameWordLive.keepA (fun u hu => hOK.capA hu) lv) + (fun b al lv => mem_wr_ne' sA al fun e => + JL0.frw_offStepNA J.sys.sysl.fo al lv + (e ▸ Or.inl (Or.inr (stA_tcbStepWA (fun t ht => J.sr.core.tcbs t ht) htZ)))) rfl + have B := J.delRestartBodyA x hkx + refine ⟨x, hkx, hr, fun y hy => hOK.capA hy, hset, + { J := J', sact := sact, nsw := noSw, body := B.1, own := B.2, time := ⟨V, hCl, hCnt, CE⟩, fr := fa }, ?_⟩ + obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits, KLv, W⟩ := J7A.unp J.j7 + have I := J.toJStage3A.delIn hA hPl W + have D : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra := by + have := J.decPreA hsl hext + rwa [hcap] at this + have P := J.toJStage3A.sysPlace hext hsl hcov + have st1 := (WP.spec_ok _).1 (hstall ▸ smp.remote_tcb_stall.delS hA D I a t) + have R1 := (WP.spec_ok _).1 (hr ▸ tcb.restart_caller.delR I D P J.sys.sysl J.symL st1.1.1 st1.1.2 st1.2.1 st1.2.2) + exact ⟨_, _, _, _, _, _, I, R1.2⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbConfigSelA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbConfigSelA.lean new file mode 100644 index 000000000..edd410903 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbConfigSelA.lean @@ -0,0 +1,97 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP3): **the actual Configure program after its decode**. + +* **`tcbConfigure_selectedA`**: an accepted Configure (three extra slots, the buffer derived, both roots derived) is + `tcb::thread_control_caps` with flags `SPACE | IPC_BUFFER` at the restarted state. +* **`tcbCaps_cfg_{pre0,pre1,bufOk,bufErr}A`**: that call's outcomes from the results of its installs (slot 0 CSpace + root, slot 1 VSpace root) and of `install_buffer`. + +New module; no premise. +-/ +import Fl4ProofsA64.P3.Stage3TcbSetSpaceSelA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S A : Type} {st : machine.Store S} {ar : machine.Arch A} [L : LawfulStore st] +variable {s sR : S} {a : A} {t cs vs bs cdata vdata baddr : U64} {ctx : tcb.Ctx} {ccap vcap : capability.Cap} + {sel : capability.Cap × obj.Slot} + +theorem tcbConfigure_selectedA + (hSt : smp.remote_tcb_stall st ar s a t = ok (s, a)) + (he0 : tcb.extra_with_length ctx 0#usize 3#u64 = ok (.Ok cs)) + (he1 : tcb.extra_with_length ctx 1#usize 3#u64 = ok (.Ok vs)) + (he2 : tcb.extra_with_length ctx 2#usize 3#u64 = ok (.Ok bs)) + (hcd : tcb.arg st s ctx 0#u64 = ok cdata) (hvd : tcb.arg st s ctx 1#u64 = ok vdata) + (hba : tcb.arg st s ctx 2#u64 = ok baddr) + (hbuf : tcb.derive_for_buffer st s baddr bs = ok (.Ok sel)) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hRestart : tcb.restart_caller st s = ok sR) : + tcb.decode st ar s a fl4_abi.label.TCBConfigure t ctx = + tcb.thread_control_caps st ar sR a t ctx.slot (capability.Cap.Null, 0#u64) (capability.Cap.Null, 0#u64) + (ccap, cs) (vcap, vs) baddr sel (tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) := by + rw [tcbConfigure_programA hSt] + simp only [tcb.decode_configure, he0, he1, he2, hcd, hvd, hba, hbuf, hRoots, hRestart, bind_ok, + core.result.Result.Insts.CoreOpsTry.branch, ite_true, lift] + rfl + +theorem tcbFlagsCfgA : + (((tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) &&& tcb.UPDATE_FAULT) != 0#u64) = false ∧ + (((tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) &&& tcb.UPDATE_TIMEOUT) != 0#u64) = false ∧ + (((tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) &&& tcb.UPDATE_SPACE) != 0#u64) = true ∧ + (((tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) &&& tcb.UPDATE_IPC_BUFFER) != 0#u64) = true := by + rw [tcb.UPDATE_SPACE, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_IPC_BUFFER] + decide + +variable {slot : obj.Slot} {c0 c1 : capability.Cap} {src0 src1 : obj.Slot} {target : obj.Tcb} + {s4 s6 s9 : S} {a2 a3 a5 : A} {bufCap : capability.Cap × obj.Slot} + +/-- The slot-0 install is preempted. -/ +theorem tcbCaps_cfg_pre0A + (h0 : tcb.install_tcb_cap st ar sR a target slot layout.tcb.SLOT_CTABLE c0 src0 = ok (.Err .Preempted, s4, a2)) : + tcb.thread_control_caps st ar sR a target slot (capability.Cap.Null, 0#u64) (capability.Cap.Null, 0#u64) + (c0, src0) (c1, src1) baddr bufCap (tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) = ok (.Err .Preempted, s4, a2) := by + obtain ⟨f3, f4, f0, f5⟩ := tcbFlagsCfgA + simp [tcb.thread_control_caps, lift, f3, f4, f0, f5, h0, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + +/-- The slot-1 install is preempted. -/ +theorem tcbCaps_cfg_pre1A + (h0 : tcb.install_tcb_cap st ar sR a target slot layout.tcb.SLOT_CTABLE c0 src0 = ok (.Ok (), s4, a2)) + (h1 : tcb.install_tcb_cap st ar s4 a2 target slot layout.tcb.SLOT_VTABLE c1 src1 = ok (.Err .Preempted, s6, a3)) : + tcb.thread_control_caps st ar sR a target slot (capability.Cap.Null, 0#u64) (capability.Cap.Null, 0#u64) + (c0, src0) (c1, src1) baddr bufCap (tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) = ok (.Err .Preempted, s6, a3) := by + obtain ⟨f3, f4, f0, f5⟩ := tcbFlagsCfgA + simp [tcb.thread_control_caps, lift, f3, f4, f0, f5, h0, h1, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + +/-- Both root installs succeed and `install_buffer` returns `r` (`Ok` or `Preempted`). -/ +theorem tcbCaps_cfg_bufA {r : core.result.Result Unit error.Exc} + (h0 : tcb.install_tcb_cap st ar sR a target slot layout.tcb.SLOT_CTABLE c0 src0 = ok (.Ok (), s4, a2)) + (h1 : tcb.install_tcb_cap st ar s4 a2 target slot layout.tcb.SLOT_VTABLE c1 src1 = ok (.Ok (), s6, a3)) + (hb : tcb.install_buffer st ar s6 a3 target slot baddr bufCap = ok (r, s9, a5)) : + tcb.thread_control_caps st ar sR a target slot (capability.Cap.Null, 0#u64) (capability.Cap.Null, 0#u64) + (c0, src0) (c1, src1) baddr bufCap (tcb.UPDATE_SPACE ||| tcb.UPDATE_IPC_BUFFER) = ok (r, s9, a5) := by + obtain ⟨f3, f4, f0, f5⟩ := tcbFlagsCfgA + rcases r with u | e + · cases u + simp [tcb.thread_control_caps, lift, f3, f4, f0, f5, h0, h1, hb, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + · simp [tcb.thread_control_caps, lift, f3, f4, f0, f5, h0, h1, hb, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbDebugLabelsA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbDebugLabelsA.lean new file mode 100644 index 000000000..9e3ad3352 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbDebugLabelsA.lean @@ -0,0 +1,45 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbsigvm): **the debug labels are absent on this configuration** (no dispatch arm). + +`TCBConfigureSingleStepping`, `TCBSetBreakpoint`, `TCBGetBreakpoint`, `TCBUnsetBreakpoint` are `u64::MAX` in +`fl4_abi::label` (the hardware-debug API is off on AArch64), and a message label has 52 bits +(`msg_info_label_ltA`), so `tcb.decode` never matches them: they fall to the unknown-label `Err IllegalOperation` +that `DecErrSpecPA.thread` (`Stage3DecErrTcbA`) already covers, and the spec numbering `fl4Numbering` has no such +label. Decision: **decode-`Err`, no arm.** + +* `tcbDebugLabels_maxA`: the four constants are `U64::MAX`. +* `tcbDebugLabels_neA`: a decoded message label is none of them. + +No premises beyond `msg.msg_info … = ok info`. New module. +-/ +import Fl4ProofsA64.P3.Stage3DecErrTcbA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.ReplyErr +open fl4_core_a64 + +noncomputable section + +theorem tcbDebugLabels_maxA : + fl4_abi.label.TCBConfigureSingleStepping = core.num.U64.MAX ∧ + fl4_abi.label.TCBSetBreakpoint = core.num.U64.MAX ∧ + fl4_abi.label.TCBGetBreakpoint = core.num.U64.MAX ∧ + fl4_abi.label.TCBUnsetBreakpoint = core.num.U64.MAX := + ⟨by rw [fl4_abi.label.TCBConfigureSingleStepping], by rw [fl4_abi.label.TCBSetBreakpoint], + by rw [fl4_abi.label.TCBGetBreakpoint], by rw [fl4_abi.label.TCBUnsetBreakpoint]⟩ + +theorem tcbDebugLabels_neA {S : Type} {st : machine.Store S} {s : S} {t : U64} {info : msginfo.MessageInfo} + (h : msg.msg_info st s t = ok info) : + info.label ≠ fl4_abi.label.TCBConfigureSingleStepping ∧ info.label ≠ fl4_abi.label.TCBSetBreakpoint ∧ + info.label ≠ fl4_abi.label.TCBGetBreakpoint ∧ info.label ≠ fl4_abi.label.TCBUnsetBreakpoint := by + have hl := msg_info_label_ltA h + obtain ⟨a, b, c, d⟩ := tcbDebugLabels_maxA + have key : info.label ≠ core.num.U64.MAX := fun e => by + rw [e] at hl + have : (core.num.U64.MAX).val = 2 ^ 64 - 1 := by decide + omega + exact ⟨a ▸ key, b ▸ key, c ▸ key, d ▸ key⟩ + +end + +end Fl4ProofsA64.P3.ReplyErr diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbFpuRdA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbFpuRdA.lean index 5f0b3f5e2..cc5e67e10 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbFpuRdA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbFpuRdA.lean @@ -562,7 +562,7 @@ theorem JStage3A.fpuRead_stepA omega exact JStage3A.of_schedWrX (symL := symL) (schedValid := sv) (vcX := vcwOff) J XO hXvs J.bufAl (wr.mono fun _ h => Or.inr h) (σ' := σ') ⟨fun _ => Or.inl rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ - (SSzA.of_kheap rfl) (QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩) hz har (fun _ _ => rfl) sys sq poolOff SR scCov ep ntfn reply + (SSzA.of_kheap rfl) (QKeepA.of_kheap rfl (DomKeepA.ofKey rfl)) hz har (fun _ _ => rfl) sys sq poolOff SR scCov ep ntfn reply bufCover J.idleNoFault mcp yr sinv sidle rv blkQ j5 j7 set_option maxHeartbeats 2000000 in diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbInstallA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbInstallA.lean new file mode 100644 index 000000000..3f5118e61 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbInstallA.lean @@ -0,0 +1,453 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP0b): **one `install_tcb_cap` at the record**, for a TCB slot `i ≠ 2` (CSpace root 0, +VSpace root 1, fault handler 3, timeout handler 4, HighVSpace 6), generic in the new cap `nc` and its source. + +The deletion of the slot is the caller's (`restartDelA`, or `delChainA` mid-chain): these lemmas start from its result. + +* **`TcbInsKA`**: what a non-null `nc` owes against `c0`, the cap its source slot held before the deletion: P1's object + check, the derivation facts `cap_insert` needs and the spec cap `anc`. +* **`TcbInsP1A`**: the P1 facts at the state the insert reaches (`SymL`, `SysL`, `J7A`): from `decodeFinA` for a last + install, from `JStage3A.tcbInsP1A` (`insertP1A` / `insertP1CnodeA`) for an intermediate one. +* **`tcbInstallCap_preemptedA`**: a preempted deletion is a preempted install, on both sides. +* **`JStage3A.installTcbCapA`**: the `Ok` deletion: the install skips (`nc` null, or `still_valid` false) or inserts + (`capInsertTcbSlotGA`). +* **`TcbMidA.installTcbCapA`**: the same from a chain's mid state, re-establishing `TcbMidA`. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbChainIfaceA +import Fl4ProofsA64.P3.Stage3LiftTcbSspEpA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +/-- **A non-null cap to install in a TCB slot**, against the cap `c0` of its source slot (module docstring). -/ +structure TcbInsKA (H : Heap) (th : TypedHeapA) (m : McState) (n i : Nat) (nc c0 : capability.Cap) + (anc : Fl4SpecA64.Cap) : Prop where + kind : TcbK nc + same : objects.same_object_as nc c0 = ok true + hD : Fl4ProofsA64.P3.DerivA nc c0 + hal : UA nc c0 + hk : SameBadgeKindA nc c0 + hsh : Fl4ProofsA64.P3.shapeA nc = Fl4ProofsA64.P3.shapeA c0 + hsh1 : Fl4ProofsA64.P1.W7.R.ST.shapeA nc = Fl4ProofsA64.P1.W7.R.ST.shapeA c0 + hbd1 : badgeA nc = badgeA c0 ∨ badgeA c0 = 0#u64 + hbd : ∀ r b rs, (absCapA c0 = .endpointCap r b rs ∨ absCapA c0 = .notificationCap r b rs) → b ≠ 0 → + Fl4SpecA64.capEpBadge (absCapA nc) = b + hcv : CapValidA th c0 → CapValidA th nc + wf : CapWfA c0 → CapWfA nc + enc : CapRt.EncWf c0 → CapRt.EncWf nc + anc_eq : anc = absCapA nc + sameS : ∀ x, CapEqA c0 x → fl4TcbSameObject anc x + idle : NoIdleCapV m n anc + fh : i = 3 → NullOrEp H nc + +/-- **The P1 facts at the state the insert reaches** (module docstring). -/ +def TcbInsP1A {S : Type} (st : machine.Store S) [L : LawfulStore st] {A : Type} (ar : machine.Arch A) (ipa : U64) + (Z : XSetsA) (H : Heap) (OS : Set U64) (ia ie : Nat) (m : McState) (sd : S) (σd : State Unit) + (nc : capability.Cap) (anc : Fl4SpecA64.Cap) (ss dd : CslotPtr) : Prop := + ∀ s2, cdt.insert st sd nc (cslotAddrA ss) (cslotAddrA dd) = ok s2 → + SymL st H Z.Cs s2 ∧ SysL st H Z.Cs OS ia ie s2 ∧ + ∀ σ2, ((), σ2) ∈ (Fl4SpecA64.capInsert (Z := Unit) anc ss dd σd).1 → + J7A st (J7R2A st ar ipa) { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA dd) + (insBA σd ss (absCapA nc) (absCapA (capA st sd (cslotAddrA ss))))) } H OS s2 σ2 m + +/-- A `TcbK` cap names neither an emptied slot nor a zombie, on both sides. -/ +theorem tcbSame_deadA {nc c : capability.Cap} (hk : TcbK nc) (hc : c = .Null ∨ ∃ p t k, c = .Zombie p t k) : + objects.same_object_as nc c = ok false ∧ ∀ x, CapEqA c x → ¬ fl4TcbSameObject (absCapA nc) x := by + have ex : ∀ x, CapEqA c x → x = absCapA c := fun x h => by + rcases hc with rfl | ⟨p, t, k, rfl⟩ <;> exact (CapEqA.eq_abs h (fun _ _ _ e => by cases e)).symm + refine ⟨?_, fun x h => ?_⟩ + · rcases hk with ⟨p, b, s, r, g, gr, rfl⟩ | ⟨p, r, g, b, rfl⟩ | ⟨p, m, a, rfl⟩ | ⟨p, l, m, ad, v, rfl⟩ | + ⟨p, m, a, rfl⟩ <;> rcases hc with rfl | ⟨q, t, k, rfl⟩ <;> + simp [objects.same_object_as, objects.same_region_as] + · rw [ex x h] + rcases hk with ⟨p, b, s, r, g, gr, rfl⟩ | ⟨p, r, g, b, rfl⟩ | ⟨p, m, a, rfl⟩ | ⟨p, l, m, ad, v, rfl⟩ | + ⟨p, m, a, rfl⟩ <;> rcases hc with rfl | ⟨q, t, k, rfl⟩ <;> + simp [absCapA, fl4TcbSameObject, fl4TcbFrame, ArchCap.isFrameCap, sameObjectAs, sameRegionAs, sameAobjectAs, + archSameRegionAs, ExtArchCap.sameAobjectWith, ExtArchCap.sameRegionWith, isEpCap, isCnodeCap, isThreadCap] + +/-- A cap of a TCB-slot kind is the same object as itself, on the spec side. -/ +theorem tcbSame_selfA {c : capability.Cap} (hk : TcbK c) : fl4TcbSameObject (absCapA c) (absCapA c) := by + rcases hk with ⟨p, b, s, r, g, gr, rfl⟩ | ⟨p, r, g, b, rfl⟩ | ⟨p, m, a, rfl⟩ | ⟨p, l, m, ad, v, rfl⟩ | + ⟨p, m, a, rfl⟩ <;> + simp [absCapA, fl4TcbSameObject, fl4TcbFrame, ArchCap.isFrameCap, sameObjectAs, sameRegionAs, sameAobjectAs, + archSameRegionAs, ExtArchCap.sameAobjectWith, ExtArchCap.sameRegionWith, ExtArchCap.sameObject, isEpCap, + isCnodeCap, bitsOf, objRefOf] + +theorem tcbNoIdle_absA {c : capability.Cap} (hk : TcbK c) (m : McState) (n : Nat) : NoIdleCapV m n (absCapA c) := by + refine ⟨fun _ _ => ?_, fun _ => ?_, fun _ _ _ => ?_⟩ <;> + rcases hk with ⟨p, b, s, r, g, gr, rfl⟩ | ⟨p, r, g, b, rfl⟩ | ⟨p, m, a, rfl⟩ | ⟨p, l, m, ad, v, rfl⟩ | + ⟨p, m, a, rfl⟩ <;> simp [absCapA] + +/-- **The discharge for an unchanged cap** (`nc` the source's own cap: a CNode root without data, a `Pml4` or Stage-2 +`Ept` VSpace root, a HighVSpace window, an endpoint handler). -/ +theorem tcbInsKA_selfA {H : Heap} {th : TypedHeapA} {m : McState} {n i : Nat} {c : capability.Cap} (hk : TcbK c) + (hfh : i = 3 → NullOrEp H c) : TcbInsKA H th m n i c c (absCapA c) where + kind := hk + same := by + rcases hk with ⟨p, b, s, r, g, gr, rfl⟩ | ⟨p, r, g, b, rfl⟩ | ⟨p, m, a, rfl⟩ | ⟨p, l, m, ad, v, rfl⟩ | + ⟨p, m, a, rfl⟩ <;> simp [objects.same_object_as, objects.same_region_as] + hD := .refl _ + hal := UA.refl _ + hk := by cases c <;> trivial + hsh := rfl + hsh1 := rfl + hbd1 := Or.inl rfl + hbd := fun r b rs h _ => by rcases h with h | h <;> rw [h] <;> rfl + hcv := id + wf := id + enc := id + anc_eq := rfl + sameS := fun x h => by + have e : x = absCapA c := by + rcases hk with ⟨p, b, s, r, g, gr, rfl⟩ | ⟨p, r, g, b, rfl⟩ | ⟨p, m, a, rfl⟩ | ⟨p, l, m, ad, v, rfl⟩ | + ⟨p, m, a, rfl⟩ <;> exact (CapEqA.eq_abs h (fun _ _ _ e => by cases e)).symm + rw [e] + exact tcbSame_selfA hk + idle := tcbNoIdle_absA hk m n + fh := hfh + +/-- **The discharge for a CNode cap with a new guard** (the CSpace root derived with data): `hwf`, `henc` come from the +decode (`deriveData_relA`, `objects.update_cap_data.wf`). -/ +theorem tcbInsKA_cnodeA {H : Heap} {th : TypedHeapA} {m : McState} {n i : Nat} {p r g gs g' gs' : U64} + (hi : i ≠ 3) (hwf : CapWfA (.CNode p r g' gs')) (henc : CapRt.EncWf (.CNode p r g' gs')) : + TcbInsKA H th m n i (.CNode p r g' gs') (.CNode p r g gs) (absCapA (.CNode p r g' gs')) := by + have hk : TcbK (.CNode p r g' gs') := Or.inr (Or.inl ⟨_, _, _, _, rfl⟩) + refine + { kind := hk, same := by simp [objects.same_object_as, objects.same_region_as], hD := .cnode .., hal := ?_, + hk := trivial, hsh := rfl, hsh1 := rfl, hbd1 := Or.inl rfl, hbd := ?_, hcv := id, wf := fun _ => hwf, + enc := fun _ => henc, anc_eq := rfl, sameS := ?_, idle := tcbNoIdle_absA hk m n, fh := fun h => absurd h hi } + · exact UA.of_shapeA rfl (fun h => by cases h) + · intro r b rs h + rcases h with h | h <;> simp [absCapA] at h + · intro x h + have e : x = absCapA (.CNode p r g gs) := (CapEqA.eq_abs h (fun _ _ _ e => by cases e)).symm + rw [e] + simp [absCapA, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isCnodeCap, bitsOf, objRefOf] + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **A preempted deletion is a preempted install** (module docstring). -/ +theorem tcbInstallCap_preemptedA {s sd : S} {a ad : A} {σ σd : State Unit} {target idx slot src : U64} + {nc : capability.Cap} {t : ObjRef} {i : Nat} {κs κsrc : CslotPtr} {anc : Fl4SpecA64.Cap} + (hroot : obj.Tcb.slot target idx = ok (cslotAddrA (t, tcbCnodeIndex i))) + (hdel : cdt.delete st ar s a (cslotAddrA (t, tcbCnodeIndex i)) true = ok (.Err .Preempted, sd, ad)) + (hspec : (.error (), σd) ∈ ((fl4CapDelete (Z := Unit) (t, tcbCnodeIndex i)).run σ).1) : + tcb.install_tcb_cap st ar s a target slot idx nc src = ok (.Err .Preempted, sd, ad) ∧ + (.error (), σd) ∈ ((fl4InstallTcbCap (Z := Unit) t κs i (some (anc, κsrc))).run σ).1 := by + refine ⟨?_, ?_⟩ + · simp only [tcb.install_tcb_cap, hroot, hdel, bind_ok, uncurry_apply_pair, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + · simp only [fl4InstallTcbCap] + exact mem_bindE_errD hspec + +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ipa : U64} {m : McState} {Clock : A → MachineState → Prop} {Ag : Set U64} + +set_option maxHeartbeats 4000000 in +/-- **`TcbInsP1A` from the record, for an intermediate install**: the P1 facts of the insert into TCB slot `i ∉ {2, 5}`, +of the source's derived cap (`insertP1A`) or of a CNode cap with a new guard (`insertP1CnodeA`). The invoked slot still +holds the thread's cap and the source slot `c0` (`still_valid`). -/ +theorem JStage3A.tcbInsP1A {s : S} {a : A} {σ : State Unit} {m : McState} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + {t idx slot src : U64} {i : Nat} (ht : Z.th t = some .tcb) (hidx : idx.val = i) (hi : i < 7) (hi2 : i ≠ 2) + (hi5 : i ≠ 5) (hroot : obj.Tcb.slot t idx = ok (cslotAddrA (specPtr t, tcbCnodeIndex i))) + (hslot : slot ∈ OS) (hI : capA st s slot = .Thread t) {κsrc : CslotPtr} (hAs : AbsSlotA Z.th κsrc) + (hκsrc : cslotAddrA κsrc = src) (hsrc : src ∈ OS) (hne : src ≠ cslotAddrA (specPtr t, tcbCnodeIndex i)) + (hnull : capA st s (cslotAddrA (specPtr t, tcbCnodeIndex i)) = .Null) + (hcan : obj.sext48 (cslotAddrA (specPtr t, tcbCnodeIndex i)) = + ok (cslotAddrA (specPtr t, tcbCnodeIndex i))) + {nc c0 : capability.Cap} {anc : Fl4SpecA64.Cap} (K : TcbInsKA H Z.th m n i nc c0 anc) + (hS : capA st s src = c0) + (hder : objects.derive_cap st s src c0 = ok (.Ok nc) ∨ + ∃ p r gs g gs' g', c0 = .CNode p r gs g ∧ nc = .CNode p r gs' g') : + TcbInsP1A st ar hPl.ipa Z H OS ia ie m s σ nc anc κsrc (specPtr t, tcbCnodeIndex i) := by + have hAd : AbsSlotA Z.th (specPtr t, tcbCnodeIndex i) := + ⟨t, rfl, Or.inr ⟨ht, i, by unfold tcbSlotsA; omega, rfl⟩⟩ + have htT : t ∈ H.tcbs := by rw [J.tcbs]; exact (J.j.1.thT t).1 ht + have hslotIdx : slotIdx t idx = cslotAddrA (specPtr t, tcbCnodeIndex i) := + okinj ((tcb_slot_val _ _).symm.trans hroot) + have hhp := J.sys.ent.heap + have hi3 : idx.val < 7 := by rw [hidx]; exact hi + have hyB : cslotAddrA (specPtr t, tcbCnodeIndex i) ∉ BufS H.tcbs := by + rw [← hslotIdx]; exact tcb_slot_notBufS hhp htT hi3 (by rw [hidx]; exact hi2) + have hyE : cslotAddrA (specPtr t, tcbCnodeIndex i) ∉ EptS H.tcbs := by + rw [← hslotIdx]; exact tcb_slot_notEptS hhp htT hi3 (by rw [hidx]; exact hi5) + have hcd : ∃ z ∈ OS, CovZ (capA st s z) (cslotAddrA (specPtr t, tcbCnodeIndex i)) := + ⟨slot, hslot, by rw [hI, ← hslotIdx]; exact CovZ.tcbSlot hhp htT hi3⟩ + have hdOS : cslotAddrA (specPtr t, tcbCnodeIndex i) ∈ OS := J.j5.2.1 _ (hAd.isSlot J.j.1.place) + have hxOS : cslotAddrA κsrc ∈ OS := by rw [hκsrc]; exact hsrc + have hxy : cslotAddrA κsrc ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) := by rw [hκsrc]; exact hne + have hS' : capA st s (cslotAddrA κsrc) = c0 := by rw [hκsrc]; exact hS + have henc : CapRt.EncWf nc := by + refine K.enc ?_ + have h : CapRt.EncWf (capAtA (L.mem s) (cslotAddrA κsrc)) := CapRt.decodeF_encWf _ _ + rwa [capAtA_eq (st := st), hS'] at h + have hnn : nc ≠ .Null := fun h => by + rcases K.kind with ⟨p, b, x, r, g, gr, e⟩ | ⟨p, r, g, b, e⟩ | ⟨p, m', a', e⟩ | ⟨p, l, m', ad, v, e⟩ | + ⟨p, m', a', e⟩ <;> rw [e] at h <;> cases h + have wp : cdt.insert st s nc (cslotAddrA κsrc) (cslotAddrA (specPtr t, tcbCnodeIndex i)) ⦃ s2 => + SysL st H Z.Cs OS ia ie s2 ∧ SymL st H Z.Cs s2 ∧ Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s2 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s2 ∧ + ∀ σ' m', J7A st (J7R2A st ar hPl.ipa) { Z with G := (insGA Z.G (cslotAddrA κsrc) + (cslotAddrA (specPtr t, tcbCnodeIndex i)) (insBA σ κsrc (absCapA nc) + (absCapA (capA st s (cslotAddrA κsrc))))) } H OS s2 σ' m' ⦄ := by + rcases hder with hdv | ⟨p, r, gs, g, gs', g', e0, e1⟩ + · have C : InsC nc (capA st s (cslotAddrA κsrc)) := by rw [hS']; exact InsC.of_soa K.kind K.same + have hE : ApE nc (capA st s (cslotAddrA κsrc)) := fun p' b' h => by + rw [hS'] at h + have hsh := K.hsh + rw [h] at hsh + rcases K.kind with ⟨p, b, x, r, g, gr, e⟩ | ⟨p, r, g, b, e⟩ | ⟨p, m', a', e⟩ | ⟨p, l, m', ad, v, e⟩ | + ⟨p, m', a', e⟩ <;> rw [e] at hsh <;> simp [Fl4ProofsA64.P3.shapeA] at hsh + refine J.insertP1A hA hPl hxOS hdOS hxy hcan hnull (Or.inl hyB) hyE hcd henc hnn C hE ?_ _ + rw [hS', hκsrc]; exact hdv + · subst e1 + exact J.insertP1CnodeA hA hPl hxOS hdOS hxy hcan hnull hyB hyE hcd henc (hS'.trans e0) _ + intro s2 h2 + obtain ⟨s2', h2', sys, sym, -, -, j7⟩ := spec_existsA wp + obtain rfl : s2' = s2 := okinj (h2'.symm.trans h2) + exact ⟨sym, sys, fun σ2 _ => j7 σ2 m⟩ + +set_option maxHeartbeats 8000000 in +/-- **One `install_tcb_cap` at the record, after its deletion** (module docstring). `s`, `σ` are the state before the +deletion; `Jd` is the record after it. The install skips or inserts. -/ +theorem JStage3A.installTcbCapA {s sd : S} {a ad : A} {σ σd : State Unit} + (Jd : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar ipa)) sd ad σd m) + {t idx slot src : U64} {i : Nat} (ht : Z.th t = some .tcb) (hi : i < tcbSlotsA) (hi2 : i ≠ 2) + (hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t) + (hroot : obj.Tcb.slot t idx = ok (cslotAddrA (specPtr t, tcbCnodeIndex i))) + (hdel : cdt.delete st ar s a (cslotAddrA (specPtr t, tcbCnodeIndex i)) true = ok (.Ok (), sd, ad)) + (hspec : (.ok (), σd) ∈ ((fl4CapDelete (Z := Unit) (specPtr t, tcbCnodeIndex i)).run σ).1) + (hnull : capA st sd (cslotAddrA (specPtr t, tcbCnodeIndex i)) = .Null) + (hcan : obj.sext48 (cslotAddrA (specPtr t, tcbCnodeIndex i)) = + ok (cslotAddrA (specPtr t, tcbCnodeIndex i))) + {κs κsrc : CslotPtr} (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) {ps : U64} + (hCs : κsrc.1 = specPtr ps ∧ Z.th ps = some (.cnode κsrc.2.length)) (hκsrc : cslotAddrA κsrc = src) + (hsrc0 : src ≠ 0#u64) {nc c0 : capability.Cap} {anc : Fl4SpecA64.Cap} + (hnn : nc = .Null → anc = .nullCap) (K : nc ≠ .Null → TcbInsKA H Z.th m n i nc c0 anc) + (hkeepS : capA st sd src = c0 ∨ capA st sd src = .Null ∨ HomeZA st sd src) + (hkeepI : capA st sd slot = .Thread t ∨ capA st sd slot = .Null ∨ HomeZA st sd slot) + (P1 : nc ≠ .Null → capA st sd src = c0 → capA st sd slot = .Thread t → + TcbInsP1A st ar ipa Z H OS ia ie m sd σd nc anc κsrc (specPtr t, tcbCnodeIndex i)) : + ∃ s2 σ2 Gi, tcb.install_tcb_cap st ar s a t slot idx nc src = ok (.Ok (), s2, ad) ∧ + (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs i (some (anc, κsrc))).run σ).1 ∧ + JStage3A st AR { Z with G := Gi } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar ipa)) s2 ad σ2 m ∧ + Sched.BodyKeepA σd σ2 ∧ DSkA σd σ2 ∧ SpecSlotA σd σ2 ∧ σ2.machineState = σd.machineState ∧ + WritesIn st sd s2 (W7.CapW H.tcbs {b | InOS OS b} ∅) ∧ + (∀ y ∈ OS, y ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) → capA st s2 y = capA st sd y) ∧ + (capA st s2 (cslotAddrA (specPtr t, tcbCnodeIndex i)) = .Null ∨ + capA st s2 (cslotAddrA (specPtr t, tcbCnodeIndex i)) = nc) := by + set dd : CslotPtr := (specPtr t, tcbCnodeIndex i) with hdd + have skip : (.ok (), σd) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs i (some (anc, κsrc))).run σ).1 → + tcb.install_tcb_cap st ar s a t slot idx nc src = ok (.Ok (), sd, ad) → _ := fun hS hR => + (⟨sd, σd, Z.G, hR, hS, Jd, Sched.BodyKeepA.refl σd, PreO.refl (R := DSkA) σd, SpecSlotA.refl σd, rfl, + WritesIn.refl _ _, fun _ _ _ => rfl, Or.inl hnull⟩ : + ∃ s2 σ2 Gi, tcb.install_tcb_cap st ar s a t slot idx nc src = ok (.Ok (), s2, ad) ∧ + (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs i (some (anc, κsrc))).run σ).1 ∧ + JStage3A st AR { Z with G := Gi } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar ipa)) s2 ad σ2 m ∧ + Sched.BodyKeepA σd σ2 ∧ DSkA σd σ2 ∧ SpecSlotA σd σ2 ∧ σ2.machineState = σd.machineState ∧ + WritesIn st sd s2 (W7.CapW H.tcbs {b | InOS OS b} ∅) ∧ + (∀ y ∈ OS, y ≠ cslotAddrA dd → capA st s2 y = capA st sd y) ∧ + (capA st s2 (cslotAddrA dd) = .Null ∨ capA st s2 (cslotAddrA dd) = nc)) + by_cases hN : nc = .Null + · refine skip ?_ ?_ + · unfold fl4InstallTcbCap + refine mem_bindE_okD hspec ?_ + rw [Fl4Spec.NonDetE.unlessE, if_pos (hnn hN)] + exact Set.mem_singleton _ + · simp only [tcb.install_tcb_cap, hroot, hdel, hN, capability.Cap.is_null, bind_ok, uncurry_apply_pair, + core.result.Result.Insts.CoreOpsTry.branch, ite_true] + have k := K hN + have hnotnull : capability.Cap.is_null nc = ok false := by + cases nc <;> first | rfl | exact absurd rfl hN + have hnSpec : anc ≠ .nullCap := by + rw [k.anc_eq] + rcases k.kind with ⟨p, b, s, r, g, gr, rfl⟩ | ⟨p, r, g, b, rfl⟩ | ⟨p, m, a, rfl⟩ | ⟨p, l, m, ad, v, rfl⟩ | + ⟨p, m, a, rfl⟩ <;> simp [absCapA] + have hsameT : objects.same_object_as (.Thread t) (.Thread t) = ok true := by + simp [objects.same_object_as, objects.same_region_as] + have hsameTS : fl4TcbSameObject (.threadCap (specPtr t)) (.threadCap (specPtr t)) := by + simp [fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] + -- the two reads, on both sides + have deadS : capA st sd src = .Null ∨ HomeZA st sd src → capA st sd src = .Null ∨ + ∃ p z k, capA st sd src = .Zombie p z k := fun h => h.imp id fun ⟨z, k, e⟩ => ⟨_, z, k, e⟩ + have hSV : tcb.still_valid st sd t slot nc src = + ok (decide (capA st sd src = c0 ∧ capA st sd slot = .Thread t)) := by + have hn : obj.Slot.is_null src = ok false := by unfold obj.Slot.is_null; rw [decide_eq_false hsrc0] + rw [tcbStillValid_liveA sd t slot src _ (capA st sd src) hn (capA_eq sd src), capA_eq sd slot] + have key : objects.same_object_as (.Thread t) (capA st sd slot) = + ok (decide (capA st sd slot = .Thread t)) := by + rcases hkeepI with e | e | ⟨z, k, e⟩ <;> rw [e] <;> + simp [objects.same_object_as, objects.same_region_as] + by_cases hS : capA st sd src = c0 + · rw [hS, k.same, bind_ok, if_pos rfl, bind_ok, key] + simp + · have hd := (tcbSame_deadA k.kind (deadS (hkeepS.resolve_left hS))).1 + rw [hd, bind_ok, if_neg Bool.false_ne_true] + simp [hS] + obtain ⟨cS, hgS, hcS⟩ := getCap_eqA Jd.j.1.st (show AbsSlotA Z.th κsrc from ⟨ps, hCs.1, Or.inl hCs.2⟩) + obtain ⟨cI, hgI, hcI⟩ := getCap_eqA Jd.j.1.st hAκ + rw [capAtA_eq (st := st), hκsrc] at hcS + rw [capAtA_eq (st := st), hκ] at hcI + have mS : (cS, σd) ∈ (getCap (Z := Unit) κsrc σd).1 := by rw [hgS]; exact Set.mem_singleton _ + have mI : (cI, σd) ∈ (getCap (Z := Unit) κs σd).1 := by rw [hgI]; exact Set.mem_singleton _ + have eI : capA st sd slot = .Thread t → cI = .threadCap (specPtr t) := fun h => by + rw [h] at hcI + exact (CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)).symm + by_cases hv : capA st sd src = c0 ∧ capA st sd slot = .Thread t + swap + · rw [decide_eq_false hv] at hSV + refine skip ?_ ?_ + swap + · simp only [tcb.install_tcb_cap, hroot, hdel, bind_ok, uncurry_apply_pair, + core.result.Result.Insts.CoreOpsTry.branch, hnotnull, hSV, Bool.false_eq_true, ite_false] + by_cases hS : capA st sd src = c0 + · have hI : capA st sd slot ≠ .Thread t := fun h => hv ⟨hS, h⟩ + have hnT : ¬ fl4TcbSameObject (.threadCap (specPtr t)) cI := by + rcases hkeepI with h | h | ⟨z, q, h⟩ + · exact absurd h hI + all_goals + rw [h] at hcI + rw [← CapEqA.eq_abs hcI (fun _ _ _ h => by cases h)] + simp [absCapA, fl4TcbSameObject, fl4TcbFrame, sameObjectAs, sameRegionAs, isEpCap, isThreadCap, objRefOf] + rw [hS] at hcS + exact tcbSlotSkip_invA hspec hnSpec mS (k.sameS _ hcS) mI hnT + · rw [k.anc_eq] at hnSpec ⊢ + exact tcbSlotSkip_srcA hspec hnSpec mS + ((tcbSame_deadA k.kind (deadS (hkeepS.resolve_left hS))).2 _ hcS) + rw [decide_eq_true hv] at hSV + obtain ⟨hS, hI⟩ := hv + have hS' : capA st sd (cslotAddrA κsrc) = c0 := by rw [hκsrc]; exact hS + have hAs : AbsSlotA Z.th κsrc := ⟨ps, hCs.1, Or.inl hCs.2⟩ + have hsrcSlot : IsSlotA Z.th (cslotAddrA κsrc) := hAs.isSlot Jd.j.1.place + have hwf0 : CapWfA c0 := by + have h := Jd.capWfA (y := cslotAddrA κsrc) hsrcSlot + rwa [hS'] at h + have henc0 : CapRt.EncWf c0 := by + have h : CapRt.EncWf (capAtA (L.mem sd) (cslotAddrA κsrc)) := CapRt.decodeF_encWf _ _ + rwa [capAtA_eq (st := st), hS'] at h + have hno : ¬ IrqNodeA (L.ksb sd) (fl4Ptr dd.1) := by + change ¬ IrqNodeA (L.ksb sd) (fl4Ptr (specPtr t)) + rw [fl4Ptr_specPtr] + intro h + have := Jd.j.1.place.irqK ht h + cases this + have hc0 : c0 ≠ .Null ∧ (∀ p z q, c0 ≠ .Zombie p z q) ∧ (∀ v, c0 ≠ .IrqHandler v) ∧ isUtA c0 = false := by + have hsh := k.hsh + rcases k.kind with ⟨p, b, s, r, g, gr, e⟩ | ⟨p, r, g, b, e⟩ | ⟨p, m, a, e⟩ | ⟨p, l, m, ad, v, e⟩ | + ⟨p, m, a, e⟩ <;> rw [e] at hsh <;> cases c0 <;> simp [Fl4ProofsA64.P3.shapeA] at hsh <;> + exact ⟨fun h => (by cases h), fun _ _ _ h => (by cases h), fun _ h => (by cases h), rfl⟩ + have hirqnc : ∀ v, nc ≠ .IrqHandler v := fun v h => by + rcases k.kind with ⟨p, b, s, r, g, gr, e⟩ | ⟨p, r, g, b, e⟩ | ⟨p, m, a, e⟩ | ⟨p, l, m, ad, x, e⟩ | + ⟨p, m, a, e⟩ <;> rw [e] at h <;> cases h + have p1 := P1 hN hS hI + have hsd1 : ∀ c < n, dd ≠ (m.idleThreadOf c, tcbCnodeIndex 1) := fun c hc e => + hidles c hc (congrArg Prod.fst e).symm + obtain ⟨s2, σ2, hs2, hm, hbk, -, J2, HS, w, ek0, ed, hfull⟩ := JStage3A.capInsertTcbSlotGA (J := Jd) κsrc dd (ps := ps) + hCs (t0 := t) ht hi hi2 hdd hsd1 (by rw [hS']; exact hc0.1) hnull hcan + (nc := nc) (anc := anc) k.fh (k.wf hwf0) (by rw [k.anc_eq]; exact CapEqA.of_abs rfl) (k.enc henc0) hN + (by rw [hS']; exact k.hD) (by rw [hS']; exact k.hal) (by rw [hS']; exact k.hk) (by rw [hS']; exact k.hsh) + (by rw [hS']; exact k.hsh1) (by rw [hS']; exact k.hbd1) (by rw [hS']; exact k.hbd) + (fun v h => absurd (hS'.symm.trans h) (hc0.2.2.1 v)) (fun v h => absurd h (hirqnc v)) + (fun v h => absurd h (hirqnc v)) (by rw [hS']; exact hc0.2.1) + (fun h => by rw [hS', hc0.2.2.2] at h; cases h) (Or.inl hno) (by rw [hS']; exact k.hcv) k.idle + (fun s2 h2 => (p1 s2 h2).1) (fun s2 h2 => (p1 s2 h2).2.1) (fun s2 σ2 h2 h3 => (p1 s2 h2).2.2 σ2 h3) + have ek : ∀ y ∈ OS, y ≠ cslotAddrA dd → capA st s2 y = capA st sd y := by + intro y hy hne + by_cases e : y = cslotAddrA κsrc + · rw [e] + rcases hfull with h | ⟨p, b, j, d, -, h, -, -⟩ + · exact h + · rw [hS'] at h + have := hc0.2.2.2 + rw [h] at this + cases this + · exact ek0 y hy e hne + have hR : tcb.install_tcb_cap st ar s a t slot idx nc src = ok (.Ok (), s2, ad) := by + rw [hκsrc] at hs2 + simp only [tcb.install_tcb_cap, hroot, hdel, bind_ok, uncurry_apply_pair, + core.result.Result.Insts.CoreOpsTry.branch, hnotnull, hSV, hs2, Bool.false_eq_true, ite_false, ite_true] + refine ⟨s2, σ2, _, hR, ?_, J2, hbk, capInsert_skA _ _ _ σd ((), σ2) hm, HS, capInsert_msA _ _ _ _ _ hm, w, ek, + Or.inr ed⟩ + rw [hS] at hcS + exact tcbSlotInsert_specA hspec hnSpec mS (k.sameS _ hcS) mI (by rw [eI hI]; exact hsameTS) hm + +set_option maxHeartbeats 4000000 in +/-- **One `install_tcb_cap` at a chain's mid state, after its deletion** (module docstring): `TcbMidA` at the +post-deletion state `(sd, ad, σd)` is re-established at the state the install reaches. `s`, `σ` are the state before +the deletion. -/ +theorem TcbMidA.installTcbCapA {ct : ObjRef} {s sd : S} {a ad : A} {σ σd : State Unit} + (Md : TcbMidA st AR Clock ct Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar ipa Ag sd ad σd m) + {t idx slot src : U64} {i : Nat} (ht : Z.th t = some .tcb) (hi : i < tcbSlotsA) (hi2 : i ≠ 2) + (hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t) + (hroot : obj.Tcb.slot t idx = ok (cslotAddrA (specPtr t, tcbCnodeIndex i))) + (hdel : cdt.delete st ar s a (cslotAddrA (specPtr t, tcbCnodeIndex i)) true = ok (.Ok (), sd, ad)) + (hspec : (.ok (), σd) ∈ ((fl4CapDelete (Z := Unit) (specPtr t, tcbCnodeIndex i)).run σ).1) + (hnull : capA st sd (cslotAddrA (specPtr t, tcbCnodeIndex i)) = .Null) + (hcan : obj.sext48 (cslotAddrA (specPtr t, tcbCnodeIndex i)) = + ok (cslotAddrA (specPtr t, tcbCnodeIndex i))) + {κs κsrc : CslotPtr} (hAκ : AbsSlotA Z.th κs) (hκ : cslotAddrA κs = slot) {ps : U64} + (hCs : κsrc.1 = specPtr ps ∧ Z.th ps = some (.cnode κsrc.2.length)) (hκsrc : cslotAddrA κsrc = src) + (hsrc0 : src ≠ 0#u64) {nc c0 : capability.Cap} {anc : Fl4SpecA64.Cap} + (hnn : nc = .Null → anc = .nullCap) (K : nc ≠ .Null → TcbInsKA H Z.th m n i nc c0 anc) + (hkeepS : capA st sd src = c0 ∨ capA st sd src = .Null ∨ HomeZA st sd src) + (hkeepI : capA st sd slot = .Thread t ∨ capA st sd slot = .Null ∨ HomeZA st sd slot) + (P1 : nc ≠ .Null → capA st sd src = c0 → capA st sd slot = .Thread t → + TcbInsP1A st ar ipa Z H OS ia ie m sd σd nc anc κsrc (specPtr t, tcbCnodeIndex i)) : + ∃ s2 σ2 Gi, tcb.install_tcb_cap st ar s a t slot idx nc src = ok (.Ok (), s2, ad) ∧ + (.ok (), σ2) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) κs i (some (anc, κsrc))).run σ).1 ∧ + TcbMidA st AR Clock ct { Z with G := Gi } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n ar ipa Ag s2 ad σ2 m ∧ + Sched.BodyKeepA σd σ2 ∧ + (∀ y ∈ OS, y ≠ cslotAddrA (specPtr t, tcbCnodeIndex i) → capA st s2 y = capA st sd y) ∧ + (capA st s2 (cslotAddrA (specPtr t, tcbCnodeIndex i)) = .Null ∨ + capA st s2 (cslotAddrA (specPtr t, tcbCnodeIndex i)) = nc) := by + obtain ⟨s2, σ2, Gi, hR, hS, J2, hbk, dsk, HS, hms, w, ek, hdd⟩ := Md.J.installTcbCapA ht hi hi2 hidles hroot hdel hspec + hnull hcan hAκ hκ hCs hκsrc hsrc0 hnn K hkeepS hkeepI P1 + have wk := dsk.toDWkA + have dk : DelStepCA σd σ2 := ⟨delStep_ofKeepA hbk wk.off wk.ctSc, dsk.ch⟩ + have sact2 : SActA σ2 := by + refine sactKeepA Md.sact Md.nsw hbk ?_ + obtain ⟨x, hx, -⟩ := J2.ep.tcb _ J2.sr.curT + exact ⟨x, by rw [J2.sr.sch.curThread]; exact hx⟩ + -- the frame words are no cap words + have JT := Md.J.toTA Md.sact Md.nsw + have JL : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7LA st (J7R2A st ar ipa)) + sd ad σd m := { JT with j7 := J7A.toLA JT.j7 } + have hdest : ∀ b, FrameWordLive st OS s2 b → FrameWordLive st OS sd b := by + rintro b ⟨u, hu, ptr, size, rights, x1, x2, x3, x4, bits, hc, r⟩ + by_cases e : u = cslotAddrA (specPtr t, tcbCnodeIndex i) + · exfalso + rw [e] at hc + rcases hdd with h | h + · rw [h] at hc; cases hc + · rw [h] at hc + by_cases hN : nc = .Null + · rw [hN] at hc; cases hc + · rcases (K hN).kind with ⟨p, b', s', r', g, gr, h'⟩ | ⟨p, r', g, b', h'⟩ | ⟨p, m', a', h'⟩ | + ⟨p, l, m', ad', v, h'⟩ | ⟨p, m', a', h'⟩ <;> rw [h'] at hc <;> cases hc + · exact ⟨u, hu, ptr, size, rights, x1, x2, x3, x4, bits, (ek u hu e).symm.trans hc, r⟩ + have fr2 : FrAgA st OS Ag s2 σ2 := + FrAgA.stepA Md.fr hdest (fun b al lv => w.mem_eq al (JL.frw_offCapWA Md.J.sys.sysl.fo lv)) (by rw [hms]) + exact ⟨s2, σ2, Gi, hR, hS, + { J := J2, sact := sact2, nsw := fun u h => Md.nsw u (hbk.act ▸ h), body := BodyOKA.stepA Md.body dk.toDelStepA, + own := Md.own.stepA dk, time := Md.time.keepA hbk.time hms HS.curKeepA, fr := fr2 }, hbk, ek, hdd⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbPreExitA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbPreExitA.lean new file mode 100644 index 000000000..b17f02764 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbPreExitA.lean @@ -0,0 +1,25 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP5): **`PreExitA` from a preempted deletion's exit facts** (`DelBodyPreA`). The deletion +loop's `Preempted` exit carries the body facts the dispatch's preemption path needs; this is the conversion the lift lemmas +of the cap-write arms use. New module; no premise. +-/ +import Fl4ProofsA64.P3.Stage3DelFrameA +import Fl4ProofsA64.P3.Stage3DispBaseA + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P3.Sched Fl4SpecA64 + +noncomputable section + +theorem DelBodyPreA.preExitA {ct : ObjRef} {m : McState} {σ' : Fl4SpecA64.State Unit} (h : DelBodyPreA ct m σ') : + PreExitA σ' := by + obtain ⟨-, hcur, hns, hps, hown⟩ := h + refine ⟨hns, fun d p => ?_, fun x hx => ?_, ?_, fun hr x hx => ?_, hown.1, hown.2⟩ + · rw [hcur]; exact hps.1 d p + · exact hps.2.1 x (by rw [← hcur]; exact hx) + · rw [hcur]; exact hps.2.2.1 + · exact hps.2.2.2 hr x (by rw [← hcur]; exact hx) + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbPrioA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbPrioA.lean index 5e440c450..e12c54229 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbPrioA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbPrioA.lean @@ -103,7 +103,7 @@ theorem JStage3A.prioG_stepA refine ⟨J.ipcSorted.of_reorder (t := specPtr t) (yt := y') (by rw [key, if_pos rfl]) (fun q z e h => ?_) (fun q w e h => ?_) (fun p hp x' h => ?_) (fun p hp x' h => ?_), fun hA p z k h ne => hA p z k (backO _ _ h (fun _ c => by cases c)) ne, - fun p z h => ⟨z, backO _ _ h (fun _ c => by cases c), id⟩, by rw [eσ]; exact ⟨rfl, rfl, rfl, rfl⟩⟩ + fun p z h => ⟨z, backO _ _ h (fun _ c => by cases c), id⟩, by rw [eσ]; exact DomKeepA.ofKey rfl⟩ · exact ⟨z, by rw [key, if_neg e]; exact h, rfl⟩ · rw [key, if_neg e] at h exact ⟨w, h, rfl⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbPrioCurA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbPrioCurA.lean new file mode 100644 index 000000000..dd8512847 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbPrioCurA.lean @@ -0,0 +1,147 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbsched): **`set_priority` of the current thread from any record state**. + +SetSchedParams on the caller runs `set_priority` on the current thread after the fault-handler deletion and `set_mcp`. + +* **`JStage3A.prioCurA`**: from `J` at any record state, for the current thread while runnable and enqueueable + (`TgtA`: an active SC, outside the release queue): the concrete and spec `set_priority` (dequeue, write, enqueue, + reschedule), the post state (the target's priority written, `choose_new_thread`, the scalars kept), `BlkOK`, and the + record at the post state given the P1 facts there (`prioQ_stepA`, as `JSyscallA.setPrioQueuedA`). + +Named premises: [P] `hCs`; [S] `h1` (`numNodes = 1`). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbPrioAnyA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 8000000 in +/-- **`set_priority` of the current thread from any record state** (module docstring). -/ +theorem JStage3A.prioCurA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (sact : SActA σ) {t p : U64} (ht : t ∈ Z.T) (hWidth : p.val < 256) (htc : specPtr t = σ.curThread) + (hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t) {y : Tcb} (hy : σ.kheap (specPtr t) = some (.tcb y)) + (hrun : runnable y.tcbState = true) (hT : TgtA (specPtr t) σ) + (hrel : (L.mem s (inqA t) &&& sched.Q_RELEASE) = 0#u64) (hsc0 : L.mem s (scA t) ≠ 0#u64) + (hscA : L.mem s (scA t) ∈ Ac) : + ∃ s3 σ3, sched.set_priority st s t p = ok s3 ∧ + setPriority (Z := Unit) (specPtr t) (BitVec.ofNat 8 p.val) σ = ({((), σ3)}, False) ∧ + σ3.kheap = Function.update σ.kheap (specPtr t) + (some (.tcb { y with tcbPriority := BitVec.ofNat 8 p.val })) ∧ + σ3.schedulerAction = .chooseNewThread ∧ σ3.curTime = σ.curTime ∧ + σ3.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ σ3.curThread = σ.curThread ∧ + σ3.curSc = σ.curSc ∧ σ3.consumedTime = σ.consumedTime ∧ σ3.releaseQueue = σ.releaseQueue ∧ + BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s3 ∧ + (SysL st H Z.Cs OS ia ie s3 → SymL st H Z.Cs s3 → Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s3 → + J7A st (J7R2A st ar nA) Z H OS s3 σ3 m → + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s3 a σ3 m) := by + have htT : t ∈ H.tcbs := by rw [J.tcbs]; exact ht + have hSt : StEqA Z.T (L.mem s) σ := fun u hu z hz => (J.ep.at_tcb hu hz).st + have hon : L.mem s (affA t) = L.cpu s := by + have x := hCs _ (J.sr.core.aff t ht) + have y := hCs _ J.sr.sch.cpuCs + exact UScalar.eq_of_val_eq (by omega) + have hcw : t = L.curW s := specPtr_inj (htc.trans J.sr.sch.curThread) + have hcq : tsCode y.tcbState ≠ 3 ∧ tsCode y.tcbState ≠ 4 := by + revert hrun + cases y.tcbState <;> simp [Notif.tsCode, runnable] + have hnb : ∀ q, y.tcbState ≠ .blockedOnNotification q := fun q h => by + rw [h] at hrun; simp [runnable] at hrun + have hqc1 : specPtr t ∈ σ.readyQueues y.tcbDomain y.tcbPriority ∨ specPtr t = σ.curThread := Or.inr htc + have hqcC : (L.mem s (inqA t) &&& sched.Q_QUEUED) ≠ 0#u64 ∨ t = L.curW s := Or.inr hcw + have L1 : LoopInvA σ m n := ⟨J.sinv, J.sidle, sact⟩ + obtain ⟨sd, ed, σd, d, kd, rd, -, SRd, Fd⟩ := exists_of_specA (dequeue_refines_localA J.sr ht hon) + have hond := yieldAffKeepA J.sr SRd ht ht hon + have dm : ((), σd) ∈ (tcbSchedAction (Z := Unit) tcbSchedDequeue (specPtr t) σ).1 := by + rw [d]; exact Set.mem_singleton _ + have hnqd : NoQ (specPtr t) σd := + (deqD (specPtr t) (fun _ => True) (fun _ _ _ => trivial) σ + ⟨Sched.SchedValidA.toFIA J.schedValid, rqDomPrio_of_schedA J.sr, trivial⟩ _ dm).2.2 + have hq0 : (L.mem sd (inqA t) &&& sched.Q_QUEUED) = 0#u64 := SRd.toSchedSRN.qBit0 ht hond hnqd + have Sd := tcbSchedAction_shapeA tcbSchedDequeue (fun _ _ _ h => Or.inr (List.mem_filter.1 h).1) (specPtr t) dm + have hyd : σd.kheap (specPtr t) = some (.tcb y) := by rw [congrArg (fun z => z.kheap) Sd.1.1]; exact hy + have states_d : StEqA Z.T (L.mem sd) σd := + hSt.keep (fun u hu => by + rw [stA_eq] + exact yieldWordKeepA J.sr.toSchedSRN J.sr.curT (Fd.wr.mono fun _ h => Or.inl h) hu (Or.inl rfl)) + (fun u x hx => ⟨x, by rw [← congrArg (fun z => z.kheap) Sd.1.1]; exact hx, rfl⟩) + obtain ⟨SR2, S2⟩ := prioStageA SRd states_d ht hyd hq0 hWidth + have hon2 := yieldAffKeepA SRd SR2 ht ht hond + have hrunp : ∀ x, (prioStateA σd (specPtr t) y (BitVec.ofNat 8 p.val)).kheap (specPtr t) = some (.tcb x) → + runnable x.tcbState = true := fun x hx => by + rw [prioKhA, if_pos rfl] at hx + obtain rfl := KernelObject.tcb.inj (Option.some.inj hx) + exact hrun + have hnrp : specPtr t ∉ (prioStateA σd (specPtr t) y (BitVec.ofNat 8 p.val)).releaseQueue := by + show specPtr t ∉ σd.releaseQueue + rw [rd]; exact hT.2 + obtain ⟨se, ee, σe, e, ke, re, hae, wE, SRe⟩ := exists_of_specA + (enqueue_refines_localA SR2 t ht hon2 (fun _ => (SR2.relOn ht hon2).2 hnrp) hrunp) + have FE := MFrA.of_sw (Z := { Z with Q := deqQA (st := st) s t Z.Q }) (m := m) ke + (wE.mono fun _ h => SR2.toSchedSRN.enq_swr ht h) + have states_e : StEqA Z.T (L.mem se) σe := + S2.keep (fun u hu => by + rw [stA_eq] + exact yieldWordKeepA SR2.toSchedSRN SR2.curT (FE.wr.mono fun _ h => Or.inl h) hu (Or.inl rfl)) + (fun u x hx => ⟨x, by rw [ke] at hx; exact hx, rfl⟩) + obtain ⟨sr, er, σr, Qr, r, kr, rr, wR, SRr⟩ := exists_of_specA (reschedule_required_refinesA SRe states_e) + have FR := MFrA.of_sw (Z := { Z with Q := enqQA st (L.wr sd (prioA t) p) t (deqQA (st := st) s t Z.Q) }) (m := m) + kr wR + have F2 := FE.trans FR rfl rfl + have em : ((), σe) ∈ (tcbSchedAction (Z := Unit) tcbSchedEnqueue (specPtr t) + (prioStateA σd (specPtr t) y (BitVec.ofNat 8 p.val))).1 := by rw [e]; exact Set.mem_singleton _ + have rm : ((), σr) ∈ (rescheduleRequired (Z := Unit) σe).1 := by rw [r]; exact Set.mem_singleton _ + have Se := tcbSchedAction_enq_memA (specPtr t) em + have Rs := rescheduleRequired_memA rm + have eqd : σd = { σ with readyQueues := σd.readyQueues, schedulerAction := σd.schedulerAction } := Sd.1.1 + have hσe : σe = { prioStateA σd (specPtr t) y (BitVec.ofNat 8 p.val) with + readyQueues := σe.readyQueues, schedulerAction := σe.schedulerAction } := Se.1.1 + have hσr : σr = { σe with readyQueues := σr.readyQueues, schedulerAction := σr.schedulerAction } := Rs.1.1 + have eqr : σr = { prioStateA σd (specPtr t) y (BitVec.ofNat 8 p.val) with + readyQueues := σr.readyQueues, schedulerAction := σr.schedulerAction } := + hσr.trans (by rw [hσe]) + obtain ⟨LI, sv, -, -⟩ := prioQ_specInvA L1 J.schedValid (rqDomPrio_of_schedA J.sr) hy hrun hT hidles d rfl e r + have hsp1 : sched.set_priority st s t p = ok sr := + setPriority_queuedA (hSt t ht y hy) hrun hqcC ed ee er + have hSet := setPriority_queuedSpecA (σp := prioStateA σd (specPtr t) y (BitVec.ofNat 8 p.val)) + (BitVec.ofNat 8 p.val) hy hrun hqc1 d (congrArg (fun z => z.kheap) eqd) rfl e r + have blk : BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac sr := by + have h := sched.set_priority.blk (st := st) s t p (BXI.blk J.sys.ent.bxi) htT hWidth + (fun _ => hrel) (fun _ => hsc0) (fun _ => hscA) + rw [hsp1, WP.spec_ok] at h + exact h.1 + have kh : σr.kheap = Function.update σ.kheap (specPtr t) + (some (.tcb { y with tcbPriority := BitVec.ofNat 8 p.val })) := by + have h := congrArg (fun z => z.kheap) eqr + simp only [prioStateA, updKSc] at h + rw [h, kd] + exact ⟨sr, σr, hsp1, hSet, kh, Rs.2, + (congrArg (fun z => z.curTime) eqr).trans (congrArg (fun z => z.curTime) eqd), + (congrArg (fun z => z.machineState.lastMachineTime) eqr).trans + (congrArg (fun z => z.machineState.lastMachineTime) eqd), + (congrArg (fun z => z.curThread) eqr).trans (congrArg (fun z => z.curThread) eqd), + (congrArg (fun z => z.curSc) eqr).trans (congrArg (fun z => z.curSc) eqd), + (congrArg (fun z => z.consumedTime) eqr).trans (congrArg (fun z => z.consumedTime) eqd), + (congrArg (fun z => z.releaseQueue) eqr).trans (congrArg (fun z => z.releaseQueue) eqd), blk, + fun sysl symL userOK j7 => ⟨Qr, Z.R, + J.prioQ_stepA ht hWidth hy hcq hnb SRd Fd eqd hq0 F2 SRr eqr LI sv (BlkOK.bxi blk) sysl symL userOK j7⟩⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbPrioEpA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbPrioEpA.lean index 99e889244..3db86cbdd 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbPrioEpA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbPrioEpA.lean @@ -283,7 +283,7 @@ theorem JStage3A.prioEp_stepA (fun q z c h => ?_) (fun q w c h => ?_) (fun q hq x' h => ?_) (fun q hq x' h => ?_), fun hA q z k h ne => hA q z k (backO _ _ h (fun _ c => by cases c) (fun _ c => by cases c)) ne, fun q z h => ⟨z, backO _ _ h (fun _ c => by cases c) (fun _ c => by cases c), id⟩, - by rw [eσ3]; exact ⟨rfl, rfl, rfl, rfl⟩⟩ + by rw [eσ3]; exact DomKeepA.ofKey rfl⟩ · have ne : q ≠ specPtr e := fun d => by rw [d, hk] at h; cases h exact ⟨z, by rw [key3, if_neg ne, if_neg c]; exact h, rfl⟩ · have ne : q ≠ specPtr e := fun d => by rw [d, hE3] at h; cases h diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbPrioNtfnA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbPrioNtfnA.lean index 1137583e0..6b6b25770 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbPrioNtfnA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbPrioNtfnA.lean @@ -418,7 +418,7 @@ theorem JStage3A.prioNtfn_stepA (fun q z c h => ?_) (fun q w c h => ?_) (fun q hq x' h => ?_) (fun q hq x' h => ?_), fun hA q z k h ne => hA q z k (backO _ _ h (fun _ c => by cases c) (fun _ c => by cases c)) ne, fun q z h => ⟨z, backO _ _ h (fun _ c => by cases c) (fun _ c => by cases c), id⟩, - by rw [eσ3]; exact ⟨rfl, rfl, rfl, rfl⟩⟩ + by rw [eσ3]; exact DomKeepA.ofKey rfl⟩ · have ne : q ≠ specPtr e := fun d => by rw [d, hk] at h; cases h exact ⟨z, by rw [key3, if_neg ne, if_neg c]; exact h, rfl⟩ · have ne : q ≠ specPtr e := fun d => by rw [d, hE3] at h; cases h diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbReadCallA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbReadCallA.lean new file mode 100644 index 000000000..58ea15e56 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbReadCallA.lean @@ -0,0 +1,461 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregr): **TCB ReadRegisters, Call, no source suspension, at the record**. + +* **`JSyscallA.readRegsCallA`**: `decode_invocation` on a Thread cap with the ReadRegisters label, `Call` flag set, + suspension bit clear, at a syscall entry: the caller's `Restart`, the reply (badge `0`, the register words in the message + registers and the caller's IPC buffer, the message info; `tcbReadRegisters_callReplyFA`) and the caller's `Running`. + The record is rebuilt once, at the final state, from the entry's J-state after the `Restart` by `of_replyStepA`; the + relations come from the spec step being `SIKA` / `UQBA` (`Stage3TcbReadCallSpecA`) and the fine write set + `RcvRegA caller ∨ BufW Bf` (registers of the caller and tracked buffer words). + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `hCs`; [S] `h1`; decode-site facts `hlen`, `hf`, `hn`, +`hlo`, `hhi`, `hself`; **[S] `hu`** (F2: the caller's receive-buffer frames are user frames, the S3 user-memory relation; +a selector at the reached state, not an all-states premise). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbReadRegsA +import Fl4ProofsA64.P3.TcbInvokeReadCallFineA +import Fl4ProofsA64.P3.Stage3TcbReadCallSpecA +import Fl4ProofsA64.P3.TcbReadJointA +import Fl4ProofsA64.P3.Stage3ReplyErrGlueA +import Fl4ProofsA64.P3.Stage3IpcFl4KeepA +import Fl4ProofsA64.P3.Stage3RecvBufA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 8000000 in +/-- **TCB ReadRegisters (Call, no suspension) at a syscall entry** (module docstring). -/ +theorem JSyscallA.readRegsCallA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t flags count : U64} {blk don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, true, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, true, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) (hsuspend : (flags &&& 1#u64) = 0#u64) + (hu : ∀ x, σ.kheap σ.curThread = some (.tcb x) → ∀ rp, ipcBufOfA true x = some rp → ∀ k, k < 128 → + inUserFrame (bufAddr rp k) σ) : + ∃ xc σ1 σ3 s3, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ3) ∈ ((fl4PerformInvocation blk true don + (.invokeTCB (.readRegisters (specPtr t) false count.bv ArchDefaultExtraRegisters))).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk true don false buf extra = + ok (.Ok (), s3, a) ∧ + ∃ Ac' Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 m ∧ Sched.BodyEndA σ σ3 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J1, -, -, -⟩ := J.toJStage3A.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + set s1 := L.wr s (stA (L.curW s)) sched.TS_RESTART with hs1 + set σ1 := stUpdA σ σ.curThread xc .restart with hσ1 + have ct : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + set c0 := L.curW s with hc0 + have hcZ : c0 ∈ Z.T := J.sr.curT + have hca : TcbAddr c0 := J.sr.core.tcbs _ hcZ + have hcur1 : L.curW s1 = c0 := specPtr_inj (J1.j.1.sch.curThread.symm.trans ct) + have hr : tcb.restart_caller st s = ok s1 := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + obtain ⟨y, hy, -⟩ := J1.mcp t ht + have hkc1 : σ1.kheap (specPtr c0) = some (.tcb { xc with tcbState := .restart }) := by + simp only [hσ1, stUpdA, setObjA, ← ct, Function.update_self] + have hfar : ∀ q, q ≠ specPtr c0 → σ1.kheap q = σ.kheap q := fun q hq => by + simp only [hσ1, stUpdA, setObjA, ← ct, Function.update_of_ne (ct ▸ hq)] + have hu1 : ∀ rp, ipcBufOfA true { xc with tcbState := .restart } = some rp → ∀ k, k < 128 → + inUserFrame (bufAddr rp k) σ1 := by + intro rp hrp k hk + have h := hu xc hkc rp hrp k hk + unfold inUserFrame at h ⊢ + obtain ⟨sz, hsz⟩ := h + refine ⟨sz, ?_⟩ + have hq : (bufAddr rp k &&& ~~~(mask (pageBitsForSize sz))) ≠ specPtr c0 := by + intro e + rw [e, ← ct, hkc] at hsz + cases hsz + rw [hfar _ hq] + exact hsz + have hN : count.val ≤ 36 := by + have h : ¬ 36 < count.val := hhi + omega + -- the current thread's scheduling facts at the state after the Restart (as in the Send arm) + have hscx1 : L.mem s (scA c0) ≠ 0#u64 := RS.cur.2.1 + set w := L.mem s (scA c0) with hw + have hwC : w ∈ Z.C := J.j.1.rest.scMem c0 hcZ hscx1 + have farA : ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3328 → + L.mem s1 (wa c0 K) = L.mem s (wa c0 K) := by + have sA : Aligned (stA c0) := by rw [stA_eq]; exact field_aligned hca (by simp) (by simp) + intro K k1 k2 k3 + exact mem_wr_ne' sA (field_aligned hca k1 k2) + (by rw [stA_eq]; exact field_ne (K2 := K) hca hca (by simp) k1 (fun _ => by simpa using Ne.symm k3)) + have hscU : L.mem s1 (scA c0) = w := farA 3464#u64 (by simp) (by simp) (by simp) + have hiqU : L.mem s1 (inqA c0) = L.mem s (inqA c0) := farA 3592#u64 (by simp) (by simp) (by simp) + have hscx : xc.tcbSchedContext = some (scRenA m w) := by + obtain ⟨z, hz, -, hsx⟩ := J.j.1.sch.tcb c0 hcZ + rw [← ct, hkc] at hz; cases hz + rw [hsx]; unfold optScA; rw [← hw, if_neg hscx1] + have hpos : ∃ z k, σ1.kheap (scRenA m w) = some (.schedContext z k) ∧ 0 < z.scRefillMax := by + have hbx := J.sys.ent.bxi + obtain ⟨-, -, -, -, hS⟩ := hbx + have hwH : w ∈ H.scs := by rw [J.scs]; exact hwC + have hrm : L.rmax s w ≠ 0#u64 := (hS.act w hwH).1 RS.cur.2.2 + obtain ⟨z, k, ez, ezr⟩ := J.j.1.rest.refillMax w hwC + have e3 : L.rmax s w = L.mem s (wa w 72#u64) := by unfold LawfulStore.rmax; rw [maxA_eqA] + rw [e3] at hrm + have hp0 : 0 < z.scRefillMax := by + rw [ezr]; exact Nat.pos_of_ne_zero (fun e => hrm (UScalar.eq_of_val_eq (by simpa using e))) + refine ⟨z, k, ?_, hp0⟩ + simp only [hσ1, stUpdA, setObjA] + rw [Function.update_of_ne (fun e => by rw [e, hkc] at ez; cases ez)]; exact ez + have hrq : specPtr c0 ∉ σ1.releaseQueue := by + show specPtr c0 ∉ σ.releaseQueue + rw [J.j.1.rest.rel]; intro hm + obtain ⟨q, hq, eq⟩ := List.mem_map.1 hm + have e' : q = c0 := specPtr_inj eq + subst e' + have haf := J.sq.inR _ J.sq.cur _ hq + exact ((J.sq.released _ (by rw [J.tcbs]; exact hcZ)).2 (by rw [haf]; exact hq)) RS.cur.1 + have hneSC : scRenA m w ≠ specPtr c0 := by + obtain ⟨z, k, ez, -⟩ := hpos + intro e; rw [e, hkc1] at ez; cases ez + have hcsc1 : σ1.curSc ≠ specPtr c0 := by + intro e + obtain ⟨y0, j, h0⟩ := J.curInv.sc + rw [show σ1.curSc = σ.curSc from rfl, ← ct] at e + rw [e, hkc] at h0; cases h0 + have hdecEq : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk true don false buf extra = + tcb.decode st ar s a fl4_abi.label.TCBReadRegisters t ⟨len, buf, true, slot, extra⟩ := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl] + have hcall : (⟨len, buf, true, slot, extra⟩ : tcb.Ctx).call = true := rfl + have hWP : tcb.decode st ar s a fl4_abi.label.TCBReadRegisters t ⟨len, buf, true, slot, extra⟩ ⦃ r => + r.1 = .Ok () ∧ r.2.2 = a ∧ ∃ σ3 Q2 R2, (.ok [], σ3) ∈ ((fl4PerformInvocation blk true don + (.invokeTCB (.readRegisters (specPtr t) false count.bv ArchDefaultExtraRegisters))).run σ1).1 ∧ + Sched.BodyEndA σ σ3 m ∧ + ∀ Ac', BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' r.2.1 → + SysL st H Z.Cs OS ia ie r.2.1 → SymL st H Z.Cs r.2.1 → + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U r.2.1 → + J7A st (J7R2A st ar hPl.ipa) Z H OS r.2.1 σ3 m → + JStage3A st AR { Z with Q := Q2, R := R2 } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) r.2.1 a σ3 m ⦄ := by + rw [tcbReadRegisters_acceptedA hstall hlen hf hn hlo hhi hself hr, hcall, hsuspend] + refine WP.spec_bind (Pₘ := fun r : S × A => r.2 = a ∧ ∃ σ3 Q2 R2, (.ok [], σ3) ∈ ((fl4PerformInvocation blk true don + (.invokeTCB (.readRegisters (specPtr t) false count.bv ArchDefaultExtraRegisters))).run σ1).1 ∧ + Sched.BodyEndA σ σ3 m ∧ + ∀ Ac', BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' r.1 → + SysL st H Z.Cs OS ia ie r.1 → SymL st H Z.Cs r.1 → + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U r.1 → + J7A st (J7R2A st ar hPl.ipa) Z H OS r.1 σ3 m → + JStage3A st AR { Z with Q := Q2, R := R2 } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) r.1 a σ3 m) ?_ ?_ + swap + · rintro ⟨sFinal, aFinal⟩ ⟨h1, h2⟩ + exact (WP.spec_ok _).2 ⟨rfl, h1, h2⟩ + rw [tcbReadRegisters_callProgramA] + simp only [bne_self_eq_false, Bool.false_eq_true, ite_false, bind_ok] + rw [hcur1] + have hne : t ≠ c0 := hself + have hs1c : L.curW s1 = c0 := hcur1 + refine tcbReadRegisters_callReplyFA (schedOpsEAOfPlacementA (st := st) (m := m) (κ := κ) J1.ipcPlace) + J1.iplaced.e s1 σ1 J1.ep ⟨Z.Q, Z.R, J1.sr⟩ J1.j.1.st J1.bufCover J1.bufNative ht hcZ hne + ((J1.sr.thT c0).2 hcZ) hy hkc1 hu1 hN _ ?_ + rintro sTag ⟨σT, hReply, hET, ⟨Q2, R2, hST⟩, hWT, ⟨xT, hkT, hxT⟩, hOth⟩ + have sA : Aligned (stA c0) := by rw [stA_eq]; exact field_aligned hca (by simp) (by simp) + have hxTst : xT.tcbState = .restart := congrArg Tcb.tcbState hxT + have hxTsc : xT.tcbSchedContext = some (scRenA m w) := (congrArg Tcb.tcbSchedContext hxT).trans hscx + -- the words the reply keeps + have keepT : ∀ u ∈ Z.T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → (K.val < 256 ∨ 552 ≤ K.val) → + L.mem sTag (wa u K) = L.mem s1 (wa u K) := by + intro u hu K k1 k8 kr + have hua := J1.sr.core.tcbs u hu + refine hWT.mem_eq (field_aligned hua k1 k8) ?_ + have hv := field_val hua k1 + rintro (⟨r, hr⟩ | hb) + · have hrv := regA_val hca (regIdxA_lt r) + have hlt := regIdxA_lt r + have ev : (wa u K).val = (Endp.regA c0 (regIdxA r)).val := hr + rw [hv, hrv] at ev + by_cases e : u = c0 + · subst e; omega + · have hf := hua.fits + have hf' := hca.fits + have h1' := hua.align + have h2' := hca.align + have hne : u.val ≠ c0.val := fun h => e (UScalar.eq_of_val_eq h) + omega + · have := J1.iplaced.e.bt _ hb u hu + omega + have hscT : L.mem sTag (scA c0) = w := (keepT c0 hcZ 3464#u64 (by simp) (by simp) (Or.inr (by simp))).trans hscU + have hiqT : L.mem sTag (inqA c0) = L.mem s (inqA c0) := + (keepT c0 hcZ 3592#u64 (by simp) (by simp) (Or.inr (by simp))).trans hiqU + have hwH : w ∈ H.scs := by rw [J.scs]; exact hwC + obtain ⟨-, -, -, -, hS1⟩ := J1.sys.ent.bxi + have hcH : c0 ∈ H.tcbs := by rw [J.tcbs]; exact hcZ + have hmΩ : maxA w ∈ H.omega := hS1.sub _ (hS1.all _ hwH).2.1 + have hma : Aligned (maxA w) := (J1.sq.omega _ hmΩ).1 + have hrmT : L.rmax sTag w ≠ 0#u64 := by + obtain ⟨z, k, ez, ezr⟩ := hST.rest.refillMax w hwC + obtain ⟨z0, k0, ez0, hp0⟩ := hpos + rw [hOth _ hneSC, ez0] at ez + cases ez + have e3' : L.rmax sTag w = L.mem sTag (wa w 72#u64) := by unfold LawfulStore.rmax; rw [maxA_eqA] + rw [e3'] + intro h + rw [h] at ezr + simp at ezr + omega + have hmxT : stA c0 ≠ maxA w := fun h => + out_ne_field (J1.sq.omega _ hmΩ) hcH hca (K := 3328#u64) (by simp) + (by rw [← stA_eq]; exact congrArg UScalar.val h) + have eRun : sched.set_thread_state st sTag c0 sched.TS_RUNNING = ok (L.wr sTag (stA c0) sched.TS_RUNNING) := + set_thread_state_run_wrA hca (by rw [hscT]; exact hscx1) (by rw [hscT]; exact hrmT) + (by rw [hiqT]; exact RS.cur.1) (by rw [hscT]; exact hma) (by rw [hscT]; exact hmxT) + -- the spec: the reply and the caller's Running + have hKT : SIKA σ1.idleThread (fun p => p = specPtr c0) (fun _ => False) false σ1 σT := + (replyFromKernel_sikA (i := σ1.idleThread) (M := fun p => p = specPtr c0) (N := fun _ => False) (don := false) + (specPtr c0) _) σ1 ((), σT) (by rw [hReply]; rfl) + have hrqT : specPtr c0 ∉ σT.releaseQueue := fun h => hrq (hKT.rls _ h) + have hsch : schedulable (specPtr c0) (setObjA σT (specPtr c0) (.tcb { xT with tcbState := .running })) = true := by + obtain ⟨ysc, nsc, hysc, hpos'⟩ := hpos + refine schedulable_ofA (x := { xT with tcbState := .running }) (n := nsc) (by simp [setObjA]) rfl hxTsc + (y := ysc) ?_ hpos' hrqT + simpa [setObjA, Function.update_of_ne hneSC, hOth _ hneSC] using hysc + have hscneT : σT.curSc ≠ specPtr c0 := by + have e : σT.curSc = σ1.curSc := by rw [hKT.frame] + rw [e]; exact hcsc1 + obtain ⟨σ3, hset, e3, KT, Uq⟩ := finishCall_specA hkc1 hReply hkT hsch hscneT + rw [eRun] + simp only [bind_ok] + rw [WP.spec_ok] + set s3 := L.wr sTag (stA c0) sched.TS_RUNNING with hs3 + have same3 : ∀ p, p ≠ specPtr c0 → σ3.kheap p = σ1.kheap p := fun p e => by + rw [e3]; simp [stUpdA, setObjA, Function.update_of_ne e, hOth p e] + have at3 : σ3.kheap (specPtr c0) = some (.tcb { xT with tcbState := .running }) := by + rw [e3]; simp [stUpdA, setObjA] + have hstv : (stA c0).val = c0.val + 3328 := by + rw [stA_eq, field_val hca (by decide)]; simp + -- the write sets + have ewR : ∀ b, RcvRegA c0 b → EWrite Z.T E Rp Bf b := fun b ⟨r, hr⟩ => by + have hrv := regA_val hca (regIdxA_lt r) + have hlt := regIdxA_lt r + rw [hrv] at hr + exact Or.inr (Or.inr (Or.inl ⟨c0, hcZ, Or.inl ⟨by omega, by unfold TWOffN; omega⟩⟩)) + have ewS : EWrite Z.T E Rp Bf (stA c0) := + Or.inr (Or.inr (Or.inl ⟨c0, hcZ, Or.inl ⟨by omega, by unfold TWOffN; omega⟩⟩)) + have w3 := hWT.trans (writesIn_wr (s := sTag) (v := sched.TS_RUNNING) sA) + have w3I0 : WritesIn st s1 s3 (fun b => IpcFpA st Z E Rp Bf m σ1 s1 b) := + w3.mono fun b h => by + rcases h with (h | h) | h + · exact Or.inl (ewR b h) + · exact Or.inl (Or.inr (Or.inr (Or.inr h))) + · rw [h]; exact Or.inl ewS + have w3I : WritesIn st s1 s3 (fun b => IpcFpA st Z E Rp Bf m σ1 s1 b ∨ RepWA Rp b) := + w3I0.mono fun _ h => Or.inl h + have wN3 : WritesIn st s1 s3 (fun b => SchedStepNWA (st := st) N E Rp Z m σ1 s1 b ∨ BufW Bf b) := + w3.mono fun b h => by + rcases h with (h | h) | h + · exact ewrite_stepNA_buf J1.sr.core.tcbs (ewR b h) + · exact Or.inr h + · rw [h]; exact Or.inl (stA_stepNA J1.sr.core.tcbs hcZ) + have keep3 : ∀ u ∈ Z.T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → (K.val < 256 ∨ 552 ≤ K.val) → + K.val ≠ 3328 → L.mem s3 (wa u K) = L.mem s1 (wa u K) := by + intro u hu K k1 k8 kr k3 + have hua := J1.sr.core.tcbs u hu + refine (mem_wr_ne' sA (field_aligned hua k1 k8) ?_).trans (keepT u hu K k1 k8 kr) + intro e + have ev := congrArg UScalar.val e + rw [hstv, field_val hua k1] at ev + by_cases eu : u = c0 + · subst eu; omega + · have hf := hua.fits + have hf' := hca.fits + have h1' := hua.align + have h2' := hca.align + have hne : u.val ≠ c0.val := fun h => eu (UScalar.eq_of_val_eq h) + omega + refine ⟨rfl, σ3, Q2, R2, ?_, ?_, ?_⟩ + · -- the spec's perform + have hFinish : fl4FinishTcbReply true (((frame_registers ++ gp_registers).take count.bv.toNat).map + y.tcbArch.tcbContext.userRegs) σ1 = ({((), σ3)}, False) := by + unfold fl4FinishTcbReply + rw [nd_bind_oneSc (show (Fl4Spec.NonDet.gets fun s : State Unit => s.curThread) σ1 = + ({(σ1.curThread, σ1)}, False) from rfl)] + rw [show σ1.curThread = specPtr c0 from ct] + rw [nd_bind_oneSc (show (Fl4Spec.NonDet.when true (replyFromKernel (Z := Unit) (specPtr c0) + (0, ((frame_registers ++ gp_registers).take count.bv.toNat).map y.tcbArch.tcbContext.userRegs))) σ1 = + ({((), σT)}, False) from hReply)] + exact hset + unfold fl4PerformInvocation + rw [run_bind_okD (readRegsSpec_noSuspendA hy count.bv), run_bind_okD (run_liftE_stD hFinish)] + rfl + · -- the body-end facts + have hact : σ3.schedulerAction = .resumeCurThread ∨ σ3.schedulerAction = .chooseNewThread := by + rcases KT.act with h | h | ⟨y', hy', -⟩ + · left; rw [h]; exact J.act + · right; exact h + · exact hy'.elim + have hsw : SwA σ3 := fun u h => by rcases hact with e | e <;> rw [e] at h <;> cases h + have hcurS : σ3.curThread = σ.curThread := Uq.2.ct + refine Sched.BodyEndA.ofRestartSw J hkc hsw Uq.2.time Uq.2.lmt hcurS Uq.2.csc Uq.2.used ?_ ?_ ?_ + · rw [ct]; exact fun h => hrq (KT.rls _ h) + · intro y' k h + have e : σ3.kheap σ.curSc = σ1.kheap σ.curSc := same3 _ hcsc1 + exact ⟨y', by rw [← e]; exact h, rfl, rfl, rfl⟩ + · intro _ x' hx' + rw [ct, at3] at hx' + cases hx' + exact Or.inl rfl + · intro Ac' bx sysl symL userOK j7 + have T2 : StEqA Z.T (L.mem sTag) σT := fun u hu y' hy' => (hET.at_tcb hu hy').st + have hrunT : runnable xT.tcbState = true := by rw [hxTst]; rfl + have hvn : sched.TS_RUNNING.val = tsCodeA .running := by rw [ts_vals.1]; rfl + have srh := sc_set_runnable_stateA (Z := { Z with Q := Q2, R := R2 }) hST T2 hcZ hkT hrunT (ts := .running) + rfl hvn + rw [eRun, WP.spec_ok] at srh + obtain ⟨τ, hτ, sr3, -, -, -⟩ := srh + have eτ : τ = σ3 := by + rw [hset] at hτ + exact ((Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst hτ))).2).symm + rw [eτ] at sr3 + have notQ : ∀ e ∈ E, ∀ z, σT.kheap (specPtr e) = some (.endpoint z) → specPtr c0 ∉ z.epQueue := by + intro e he z hz hq + obtain ⟨z', hz', rel⟩ := hET.ep e he + rw [hz] at hz' + obtain rfl := KernelObject.endpoint.inj (Option.some.inj hz') + obtain ⟨qs, _, hqs, members⟩ := rel.queue + rw [hqs, List.mem_map] at hq + obtain ⟨u, hu, hEq⟩ := hq + have eu : u = c0 := specPtr_inj hEq + subst eu + have state := (members c0 hu).2 + rw [(hET.at_tcb hcZ hkT).st] at state + simp [hxTst] at state + exact absurd state (by decide) + have code : sched.TS_RUNNING.val = Notif.tsCode .running := by rw [ts_vals.1]; rfl + have eσ : Notif.updK σT (specPtr c0) (.tcb { xT with tcbState := .running }) = σ3 := by rw [e3]; rfl + have ep3 : EpStateRel Z.T E Rp Bf (L.mem s3) σ3 := by + have h := (Endp.write_state_rel J1.iplaced.e sTag σT hET hcZ hkT notQ .running (by decide) _ code).1 + rw [eσ] at h; exact h + have hMs : ∀ u ∈ Z.T, specPtr u = specPtr c0 → ∀ x, σ1.kheap (specPtr u) = some (.tcb x) → + ∀ p, x.tcbState ≠ .blockedOnNotification p := by + intro u hu hm x hx p h + rw [hm, hkc1] at hx; cases hx; cases h + have hMs' : ∀ u ∈ Z.T, specPtr u = specPtr c0 → ∀ x, σ3.kheap (specPtr u) = some (.tcb x) → + ∀ p, x.tcbState ≠ .blockedOnNotification p := by + intro u hu hm x hx p h + rw [hm, at3] at hx; cases hx; cases h + have wk : NtfnWaitKeepA Z.T N (L.mem s1) (L.mem s3) := by + intro u hu _ + simp only [Notif.tBlockA_eq, Notif.prevEp_eq, Notif.nextEp_eq] + exact ⟨keep3 u hu _ (by simp) (by simp) (Or.inr (by simp)) (by simp), + keep3 u hu _ (by simp) (by simp) (Or.inr (by simp)) (by simp), + keep3 u hu _ (by simp) (by simp) (Or.inr (by simp)) (by simp)⟩ + have ntfn3 := J1.ntfn_ipcA w3I KT ep3 wk hMs hMs' + have rp3 := J1.reply_ipcA w3I0 KT + have tw : ∀ u ∈ Z.T, ∀ O : U64, O.val < 224 ∨ O.val = 3440 ∨ O.val = 3472 ∨ O.val = 3512 ∨ O.val = 3456 → + O.val % 8 = 0 → L.mem s3 (wa u O) = L.mem s1 (wa u O) := + fun u hu O hO h8 => keep3 u hu O (by omega) h8 (by omega) (by omega) + have notM : ∀ c < n, ¬ (m.idleThreadOf c = specPtr c0) := by + intro c hc e + obtain ⟨y1, hy1, hs1⟩ := J1.sidle.f3 c hc + rw [e, hkc1] at hy1; cases hy1; cases hs1 + have hMI : ¬ (σ1.idleThread = specPtr c0) := by + intro e + obtain ⟨y1, hy1, hs1⟩ := J1.sinv.idleTcb + rw [e, hkc1] at hy1; cases hy1; cases hs1 + have hMq : ∀ y, y = specPtr c0 → ∀ d p, y ∉ σ1.readyQueues d p := by + intro y hy d p hm + subst hy + exact (J1.sinv.ctQ J.act d p) (by rw [show σ1.curThread = specPtr c0 from ct]; exact hm) + have hMf : ∀ p, p = specPtr c0 → ∀ x y', σ1.kheap p = some (.tcb x) → σ3.kheap p = some (.tcb y') → + y'.tcbFault ≠ none → FaultStA y'.tcbState := by + intro p hp x y' hx hy' hf + subst hp + rw [hkc1] at hx; cases hx + rw [at3] at hy'; cases hy' + exfalso; apply hf + have h0 : ({ xc with tcbState := .restart } : Tcb).tcbFault = none := + FaultStOkA.none J1.sinv.faultSt hkc1 (by rintro (⟨_, _, h⟩ | ⟨_, h⟩ | h) <;> cases h) + exact (congrArg Tcb.tcbFault hxT).trans h0 + have sinv3 : SInvXA σ3 m n := + KT.sinv J1.sinv notM hMI hMq (fun y hy => hy.elim) (fun y hy => hy.elim) J.noSwitch + (fun y hy => by rw [hy]; exact hrq) (J1.sidle.rdyA J1.sinv) hMf + have sidle3 : SIdleA σ3 m n := KT.sidle J1.sidle notM (J1.sidle.rdyA J1.sinv) + have hMv : ∀ u ∈ Z.T, specPtr u = specPtr c0 → L.mem s1 (stA u) ≠ sched.TS_RUNNING_VM := by + intro u hu hm h + rw [specPtr_inj hm, hs1, L.mem_wr_same sA] at h + revert h; unfold sched.TS_RESTART sched.TS_RUNNING_VM; decide + have rv3 := J1.runVcpu_ipcA w3I KT ep3 hMv + have bq3 := J1.blkQ_ipcA KT ep3 wk (fun u hu hm x hx => by + rw [show specPtr u = specPtr c0 from hm, at3] at hx; cases hx + exact ⟨rfl, fun _ h => by cases h⟩) + have sc' : ∀ p, ScActiveAtA σ1 p → ScActiveAtA σ3 p := fun p ⟨y1, k1, e1, act⟩ => by + have hne : p ≠ specPtr c0 := fun h => by rw [h, hkc1] at e1; cases e1 + exact ⟨y1, k1, by rw [same3 p hne]; exact e1, act⟩ + have tcbAct : ∀ u, (∃ y c, σ1.kheap u = some (.tcb y) ∧ y.tcbSchedContext = some c ∧ ScActiveAtA σ1 c) → + ∃ y c, σ3.kheap u = some (.tcb y) ∧ y.tcbSchedContext = some c ∧ ScActiveAtA σ3 c := by + intro u ⟨y1, c, e1, es, act⟩ + by_cases hu : u = specPtr c0 + · subst hu + rw [hkc1] at e1; cases e1 + exact ⟨{ xT with tcbState := .running }, c, at3, (congrArg Tcb.tcbSchedContext hxT).trans es, sc' _ act⟩ + · exact ⟨y1, c, by rw [same3 u hu]; exact e1, es, sc' _ act⟩ + have hrl' : ∀ u ∈ σ3.releaseQueue, u ∈ σ1.releaseQueue := KT.rls + have sv3 : SchedValidA σ3 := by + refine ⟨fun d p u hm => ?_, fun e1 e2 => ?_, fun u y' c e1 e2 e3' => ?_, fun u hu => ?_⟩ + · have hm1 : u ∈ σ1.readyQueues d p := by + rcases KT.rq d p u hm with h | h | h + · exact h + · exact h.elim + · exact absurd h (J.noSwitch u) + obtain ⟨act, nr⟩ := J1.schedValid.rq d p u hm1 + exact ⟨tcbAct u act, fun h => nr (hrl' u h)⟩ + · have e1' := Uq.2.act e1 + have e2' : σ1.curThread ≠ σ1.idleThread := by + rw [← Uq.2.ct, ← Uq.2.idle]; exact e2 + obtain ⟨act, nr⟩ := J1.schedValid.act e1' e2' + refine ⟨by rw [Uq.2.ct]; exact tcbAct _ act, fun h => nr ?_⟩ + rw [← Uq.2.ct]; exact hrl' _ h + · by_cases h : u = specPtr c0 + · rw [h, at3] at e1; cases e1; simp [BlockedTsA] at e2 + · rw [same3 u h] at e1 + exact sc' _ (J1.schedValid.blk u y' c e1 e2 e3') + · exact tcbAct u (J1.schedValid.rls u (hrl' u hu)) + exact J1.of_replyStepA (Q := Q2) (Rl := R2) (curOf := Z.curOf) (curScOf := Z.curScOf) (s' := s3) (σ' := σ3) + wN3 Uq.1.1.1 Uq.1.1.2.1 Uq.1.2 (J1.specZero_of_recvBufA hcZ hkc1 Uq.1.1.2.2) (fun _ _ => rfl) + bx sysl symL userOK j7 sr3 ep3 ntfn3 rp3 KT.ipcKeep tw sinv3 sidle3 rv3 bq3 sv3 + obtain ⟨⟨res, s3, a3⟩, hdec', hP⟩ := exists_of_specA hWP + obtain ⟨h1', h2', σ3, Q2, R2, hperf, hB, hJ⟩ := hP + simp only at h1' h2' hJ + have hd : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk true don false buf extra = + ok (.Ok (), s3, a) := by rw [hdecEq, hdec', h1', h2'] + obtain ⟨-, Ac', sysl, symL, bx, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hd σ3 m + exact ⟨xc, σ1, σ3, s3, hkc, rfl, hsp, hperf, hd, Ac', Q2, R2, hJ Ac' bx sysl symL userOK j7, hB⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbReadCallSpecA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbReadCallSpecA.lean new file mode 100644 index 000000000..23374f7ad --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbReadCallSpecA.lean @@ -0,0 +1,141 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregr): **the spec's `replyFromKernel` of an arbitrary message** (the Call reply of +ReadRegisters) as an `SIKA` step and a `UFrA` step. + +* `storeWordOffs_sikA`, `setMrs_sikA`, `replyFromKernel_sikA`: the caller's TCB changes only in its `tcbArch` (the + register context), the heap shape, queues, scheduler action and SCs are kept (`SIKA` for any `i M N don`). +* `replyFromKernel_ufrA`: from a state where `t` is a TCB `x`, `replyFromKernel t _` is a `UFrA` step of the bytes of + `x`'s IPC buffer (`ipcBufOfA true x`): user memory changes only inside the receive buffer's 128 words. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3IpcKeepSA +import Fl4ProofsA64.P3.Stage3SendFaultSpecA +import Fl4ProofsA64.P3.Stage3SendSpecFrA +import Fl4ProofsA64.P3.DelSinvLoopA +import Fl4ProofsA64.P3.Stage3SendQA +import Fl4ProofsA64.P3.RestartA +import Fl4ProofsA64.P3.Stage3QKeepPresA +import Fl4ProofsA64.P3.Stage3SendBudgetA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Sched +open Fl4SpecA64 Fl4Spec Fl4ProofsA64.P3 Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Classical + +noncomputable section + +section +variable {i : ObjRef} {M N : ObjRef → Prop} {don : Bool} + +theorem storeWordOffs_sikA (p : ObjRef) (x : Nat) (v : Word) : + PresR (SIKA i M N don) (storeWordOffs (Z := Unit) p x v) := by + unfold storeWordOffs + refine PresR.bind (eqPres_sikA (by eqpres)) (fun _ => ?_) + exact PresR.bind (eqPres_sikA (by eqpres)) (fun _ => doMachineOp_sikA _) + +theorem setMrs_sikA (t : ObjRef) (buf : Option ObjRef) (msgs : List Message) : + PresR (SIKA i M N don) (setMrs (Z := Unit) t buf msgs) := + setMrs_genA t buf msgs + (fun s x regs hk => (SIKA.upd hk (.tcb _ _ ⟨rfl, rfl, rfl, rfl, rfl, rfl, Or.inl rfl, Or.inl rfl, rfl, rfl⟩) + (idleRdy_nscA (by intro _ _ c; cases c)))) + (fun rb _ k _ v => storeWordOffs_sikA rb k v) + +theorem replyFromKernel_sikA (t : ObjRef) (x : Data × List Data) : + PresR (SIKA i M N don) (replyFromKernel (Z := Unit) t x) := by + unfold replyFromKernel + refine PresR.bind_pure _ _ ?_ + refine PresR.bind (eqPres_sikA (by unfold lookupIpcBuffer; eqpres)) (fun buf => ?_) + refine PresR.bind (asUser_sikA t _) (fun _ => ?_) + refine PresR.bind (setMrs_sikA t buf _) (fun len => ?_) + unfold setMessageInfo + exact asUser_sikA t _ + + +/-- `replyFromKernel` of any message from a state where `t` is a TCB `x`: `UFrA` of `x`'s receive buffer's bytes and +`QKeepA` (`UQA`). -/ +theorem replyFromKernel_uqA {σ : State Unit} {t : ObjRef} {x : Tcb} (hk : σ.kheap t = some (.tcb x)) + (l : Data) (msg : List Data) : + ∀ r ∈ (replyFromKernel (Z := Unit) t (l, msg) σ).1, UQA (BufBytesA (ipcBufOfA true x)) σ r.2 := by + intro r hr + unfold replyFromKernel at hr + rw [Notif.nd_pure_bind'] at hr + dsimp only at hr + rw [Notif.nd_bind_one (lookupIpcBuffer_eqA hk true)] at hr + have hU : ∀ {α : Type} (f : UserMonad α), PresR (UQA (BufBytesA (ipcBufOfA true x))) (asUser (Z := Unit) t f) := + fun f s y hy => ⟨UFrA.of_fr (asUser_presA t f s y hy), asUser_qA t f s y hy⟩ + refine (?_ : PresR (UQA (BufBytesA (ipcBufOfA true x))) _) σ r hr + refine PresR.bind (hU _) (fun _ => ?_) + refine PresR.bind (setMrs_genA (R := UQA (BufBytesA (ipcBufOfA true x))) t (ipcBufOfA true x) _ + (fun s x' regs hx' => ⟨UFrA.of_fr (SchedFrameA.upd_tcb hx' ⟨rfl, rfl, rfl⟩), QKeepA.upd hx' (QObjA.ofTcb rfl)⟩) + (fun rb e k hk' v s y hy => ⟨e ▸ storeWordOffs_ufrA rb hk' v s y hy, storeWordOffs_qA rb k v s y hy⟩)) + (fun len => ?_) + unfold setMessageInfo + exact hU _ + +/-- `UQA` with the budget frame `BLA`. -/ +def UQBA (B : Word → Prop) (σ σ' : State Unit) : Prop := UQA B σ σ' ∧ BLA σ σ' + +instance (B : Word → Prop) : PreO (UQBA B) where + refl σ := ⟨PreO.refl σ, PreO.refl σ⟩ + trans h1 h2 := ⟨PreO.trans h1.1 h2.1, PreO.trans h1.2 h2.2⟩ + +/-- `replyFromKernel` of any message is a `UQBA` step of the caller's receive buffer. -/ +theorem replyFromKernel_uqbA {σ : State Unit} {t : ObjRef} {x : Tcb} (hk : σ.kheap t = some (.tcb x)) + (l : Data) (msg : List Data) : + ∀ r ∈ (replyFromKernel (Z := Unit) t (l, msg) σ).1, UQBA (BufBytesA (ipcBufOfA true x)) σ r.2 := by + intro r hr + unfold replyFromKernel at hr + rw [Notif.nd_pure_bind'] at hr + dsimp only at hr + rw [Notif.nd_bind_one (lookupIpcBuffer_eqA hk true)] at hr + have hU : ∀ {α : Type} (f : UserMonad α), PresR (UQBA (BufBytesA (ipcBufOfA true x))) (asUser (Z := Unit) t f) := + fun f s y hy => ⟨⟨UFrA.of_fr (asUser_presA t f s y hy), asUser_qA t f s y hy⟩, + (PresR.blA (asUser_bkA t f)) s y hy⟩ + refine (?_ : PresR (UQBA (BufBytesA (ipcBufOfA true x))) _) σ r hr + refine PresR.bind (hU _) (fun _ => ?_) + refine PresR.bind (setMrs_genA (R := UQBA (BufBytesA (ipcBufOfA true x))) t (ipcBufOfA true x) _ + (fun s x' regs hx' => ⟨⟨UFrA.of_fr (SchedFrameA.upd_tcb hx' ⟨rfl, rfl, rfl⟩), QKeepA.upd hx' (QObjA.ofTcb rfl)⟩, + ⟨rfl, rfl, rfl, rfl, rfl, rfl, id, fun y' n h => by + by_cases e : s.curSc = t + · rw [e] at h; simp only [Function.update_self] at h; cases h + · exact ⟨y', by simpa [Function.update_of_ne e] using h, rfl, rfl⟩⟩⟩) + (fun rb e k hk' v s y hy => ⟨⟨e ▸ storeWordOffs_ufrA rb hk' v s y hy, storeWordOffs_qA rb k v s y hy⟩, + storeWordOffs_blA rb k v s y hy⟩)) + (fun len => ?_) + unfold setMessageInfo + exact hU _ + +/-- **The Call reply and the caller's `Running`** (the spec side of ReadRegisters Call from the post-`Restart` state): +the caller `c` is the current thread with TCB `x1`; after `replyFromKernel` its TCB is `xT` (the same but for the register +context); setting it `Running` gives `σ3`, an `SIKA` step (the caller the only mover) and a `UQA` step of `x1`'s buffer. -/ +theorem finishCall_specA {σ1 σT : State Unit} {c : ObjRef} {x1 xT : Tcb} {l : Data} {words : List Data} + (hk : σ1.kheap c = some (.tcb x1)) + (hReply : replyFromKernel (Z := Unit) c (l, words) σ1 = ({((), σT)}, False)) + (hkT : σT.kheap c = some (.tcb xT)) + (hsch : schedulable c (setObjA σT c (.tcb { xT with tcbState := .running })) = true) + (hscne : σT.curSc ≠ c) : + ∃ σ3, setThreadState (Z := Unit) c .running σT = ({((), σ3)}, False) ∧ σ3 = stUpdA σT c xT .running ∧ + SIKA σ1.idleThread (fun p => p = c) (fun _ => False) false σ1 σ3 ∧ + UQBA (BufBytesA (ipcBufOfA true x1)) σ1 σ3 := by + have hset : setThreadState (Z := Unit) c .running σT = ({((), stUpdA σT c xT .running)}, False) := + setThreadState_eqA σT c xT hkT .running (fun _ _ => hsch) + refine ⟨_, hset, rfl, ?_, ?_⟩ + · have h1 := (replyFromKernel_sikA (i := σ1.idleThread) (M := fun p => p = c) (N := fun _ => False) (don := false) + c (l, words)) σ1 ((), σT) (by rw [hReply]; rfl) + have h2 := (setThreadState_sikA (i := σ1.idleThread) (M := fun p => p = c) (N := fun _ => False) (don := false) + c rfl .running (by intro e; cases e)) σT ((), stUpdA σT c xT .running) (by rw [hset]; rfl) + exact SIKA.trans h1 h2 + · have h1 := replyFromKernel_uqbA hk l words ((), σT) (by rw [hReply]; rfl) + have h2 : UQBA (BufBytesA (ipcBufOfA true x1)) σT (stUpdA σT c xT .running) := + ⟨⟨UFrA.of_fr ((inferInstance : SPresInst (setThreadState (Z := Unit) c .running)).pres σT ((), _) + (by rw [hset]; rfl)), + (inferInstance : QInst (setThreadState (Z := Unit) c .running)).pres σT ((), _) (by rw [hset]; rfl)⟩, + ⟨rfl, rfl, rfl, rfl, rfl, rfl, id, fun y' n h => ⟨y', by + simpa [stUpdA, setObjA, Function.update_of_ne hscne] using h, rfl, rfl⟩⟩⟩ + exact PreO.trans h1 h2 + +end + +end + +end Fl4ProofsA64.P3.Sched diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbReadCallSuspA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbReadCallSuspA.lean new file mode 100644 index 000000000..01e54deb9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbReadCallSuspA.lean @@ -0,0 +1,440 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregr): **TCB ReadRegisters, Call, with source suspension, at the record**. + +* **`JSyscallA.readRegsCallSuspA`**: `readRegsCallA` with the suspension bit set (target not the caller): the caller's + `Restart`, the suspension of the source (`JSyscallA.suspendMidA`), then the reply and `Running` from the mid state, + whose record `J1` is the suspension's. The caller's facts at the mid state are `SuspCallerA`'s (TCB still `Restart`, + its SC word and release flag, off every queue by `suspend_offq`, user frames kept). The body-end facts continue the + suspension's `BodyOKA` across the reply (`BodyOKA.step`). + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `hCs`, `hmb`, `hmax`, `htu`; [S] `h1`; +decode-site facts `hlen`, `hf`, `hn`, `hlo`, `hhi`, `hself`; **[S] `hu`** (as `readRegsCallA`). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbReadCallA +import Fl4ProofsA64.P3.Stage3TcbSuspendArmA +import Fl4ProofsA64.P3.Stage3RecvPreA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4SpecA64 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 8000000 in +/-- **TCB ReadRegisters (Call, source suspended) at a syscall entry** (module docstring). -/ +theorem JSyscallA.readRegsCallSuspA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + {slot lbl len buf t flags count : U64} {blk don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, true, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, true, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) (hsuspend : (flags &&& 1#u64) ≠ 0#u64) + (hu : ∀ x, σ.kheap σ.curThread = some (.tcb x) → ∀ rp, ipcBufOfA true x = some rp → ∀ k, k < 128 → + inUserFrame (bufAddr rp k) σ) : + ∃ xc σ1 σ3 s3, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ3) ∈ ((fl4PerformInvocation blk true don + (.invokeTCB (.readRegisters (specPtr t) true count.bv ArchDefaultExtraRegisters))).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk true don false buf extra = + ok (.Ok (), s3, a) ∧ + ∃ Ac' Q Rl stack', JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack' κ n + (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 m ∧ Sched.BodyEndA σ σ3 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J0, -, -, -⟩ := J.toJStage3A.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have ct : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have hcurR : L.curW (L.wr s (stA (L.curW s)) sched.TS_RESTART) = L.curW s := + specPtr_inj (J0.j.1.sch.curThread.symm.trans ct) + have hr : tcb.restart_caller st s = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + have hb : ((flags &&& 1#u64) != 0#u64) = true := bne_iff_ne.2 hsuspend + obtain ⟨xc', σR, σ1, s1, a2, hkc', eR, hsp', -, -, -, Q0, R0, stk', J1, hBm, hsus, ⟨σx, hdetx, hsuspx⟩, hcal⟩ := + J.suspendMidA hA hM hPl hfm hCs h1 hmb hmax htu hslot hcov hcap hext hSC (lbl := fl4_abi.label.TCBSuspend) rfl + (blk := blk) (call := true) (don := don) (len := len) (buf := buf) + have hxx : xc = xc' := by rw [hkc] at hkc'; exact KernelObject.tcb.inj (Option.some.inj hkc') + subst hxx + have hcur1 : L.curW s1 = L.curW s := Sched.curW_keptA J.toJStage3A J1 hBm.2 + set c0 := L.curW s with hc0 + have hcZ : c0 ∈ Z.T := J.sr.curT + have hca : TcbAddr c0 := J.sr.core.tcbs _ hcZ + have hct2 : σ1.curThread = specPtr c0 := hBm.2.trans ct + obtain ⟨hkc1, hscU, hiq1, hrq, hns2, offq, hfr⟩ := hcal hself + obtain ⟨y, hy, -⟩ := J1.mcp t ht + have hu1 : ∀ rp, ipcBufOfA true { xc with tcbState := .restart } = some rp → ∀ k, k < 128 → + inUserFrame (bufAddr rp k) σ1 := by + intro rp hrp k hk + obtain ⟨sz, hsz⟩ := hu xc hkc rp hrp k hk + exact ⟨sz, hfr _ false sz hsz⟩ + have hN : count.val ≤ 36 := by + have h : ¬ 36 < count.val := hhi + omega + have hscx1 : L.mem s (scA c0) ≠ 0#u64 := RS.cur.2.1 + set w := L.mem s (scA c0) with hw + have hwC : w ∈ Z.C := J.j.1.rest.scMem c0 hcZ hscx1 + have hscx : xc.tcbSchedContext = some (scRenA m w) := by + obtain ⟨z, hz, -, hsx⟩ := J.j.1.sch.tcb c0 hcZ + rw [← ct, hkc] at hz; cases hz + rw [hsx]; unfold optScA; rw [← hw, if_neg hscx1] + have hpos : ∃ z k, σ1.kheap (scRenA m w) = some (.schedContext z k) ∧ 0 < z.scRefillMax := by + have hbx := J1.sys.ent.bxi + obtain ⟨-, -, -, -, hS⟩ := hbx + have hwH : w ∈ H.scs := by rw [J1.scs]; exact hwC + have hrm : L.rmax s1 w ≠ 0#u64 := (hS.act w hwH).1 RS.cur.2.2 + obtain ⟨z, k, ez, ezr⟩ := J1.j.1.rest.refillMax w hwC + have e3 : L.rmax s1 w = L.mem s1 (wa w 72#u64) := by unfold LawfulStore.rmax; rw [maxA_eqA] + rw [e3] at hrm + have hp0 : 0 < z.scRefillMax := by + rw [ezr]; exact Nat.pos_of_ne_zero (fun e => hrm (UScalar.eq_of_val_eq (by simpa using e))) + exact ⟨z, k, ez, hp0⟩ + have hcsc1 : σ1.curSc ≠ specPtr c0 := by + intro e + obtain ⟨y0, j, h0⟩ := J1.sinv.curSc + rw [e, hkc1] at h0; cases h0 + have hneSC : scRenA m w ≠ specPtr c0 := by + obtain ⟨z, k, ez, -⟩ := hpos + intro e; rw [e, hkc1] at ez; cases ez + have hdecEq : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk true don false buf extra = + tcb.decode st ar s a fl4_abi.label.TCBReadRegisters t ⟨len, buf, true, slot, extra⟩ := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl] + have hcall : (⟨len, buf, true, slot, extra⟩ : tcb.Ctx).call = true := rfl + have hWP : tcb.decode st ar s a fl4_abi.label.TCBReadRegisters t ⟨len, buf, true, slot, extra⟩ ⦃ r => + r.1 = .Ok () ∧ r.2.2 = a ∧ ∃ σ3 Q2 R2, (.ok [], σ3) ∈ ((fl4PerformInvocation blk true don + (.invokeTCB (.readRegisters (specPtr t) true count.bv ArchDefaultExtraRegisters))).run σR).1 ∧ + Sched.BodyEndA σ σ3 m ∧ + ∀ Ac', BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' r.2.1 → + SysL st H Z.Cs OS ia ie r.2.1 → SymL st H Z.Cs r.2.1 → + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U r.2.1 → + J7A st (J7R2A st ar hPl.ipa) Z H OS r.2.1 σ3 m → + JStage3A st AR { Z with Q := Q2, R := R2 } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stk' κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) r.2.1 a σ3 m ⦄ := by + rw [tcbReadRegisters_acceptedA hstall hlen hf hn hlo hhi hself hr, hcall, hb] + refine WP.spec_bind (Pₘ := fun r : S × A => r.2 = a ∧ ∃ σ3 Q2 R2, (.ok [], σ3) ∈ ((fl4PerformInvocation blk true don + (.invokeTCB (.readRegisters (specPtr t) true count.bv ArchDefaultExtraRegisters))).run σR).1 ∧ + Sched.BodyEndA σ σ3 m ∧ + ∀ Ac', BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' r.1 → + SysL st H Z.Cs OS ia ie r.1 → SymL st H Z.Cs r.1 → + Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U r.1 → + J7A st (J7R2A st ar hPl.ipa) Z H OS r.1 σ3 m → + JStage3A st AR { Z with Q := Q2, R := R2 } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stk' κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) r.1 a σ3 m) ?_ ?_ + swap + · rintro ⟨sFinal, aFinal⟩ ⟨h1, h2⟩ + exact (WP.spec_ok _).2 ⟨rfl, h1, h2⟩ + rw [tcbReadRegisters_callProgramA] + simp only [↓reduceIte, bind_ok, hsus, uncurry_apply_pair, Std.bind_assoc, hcurR] + have hne : t ≠ c0 := hself + have hs1c : L.curW s1 = c0 := hcur1 + refine tcbReadRegisters_callReplyFA (schedOpsEAOfPlacementA (st := st) (m := m) (κ := κ) J1.ipcPlace) + J1.iplaced.e s1 σ1 J1.ep ⟨Q0, R0, J1.sr⟩ J1.j.1.st J1.bufCover J1.bufNative ht hcZ hne + ((J1.sr.thT c0).2 hcZ) hy hkc1 hu1 hN _ ?_ + rintro sTag ⟨σT, hReply, hET, ⟨Q2, R2, hST⟩, hWT, ⟨xT, hkT, hxT⟩, hOth⟩ + have sA : Aligned (stA c0) := by rw [stA_eq]; exact field_aligned hca (by simp) (by simp) + have hxTst : xT.tcbState = .restart := congrArg Tcb.tcbState hxT + have hxTsc : xT.tcbSchedContext = some (scRenA m w) := (congrArg Tcb.tcbSchedContext hxT).trans hscx + -- the words the reply keeps + have keepT : ∀ u ∈ Z.T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → (K.val < 256 ∨ 552 ≤ K.val) → + L.mem sTag (wa u K) = L.mem s1 (wa u K) := by + intro u hu K k1 k8 kr + have hua := J1.sr.core.tcbs u hu + refine hWT.mem_eq (field_aligned hua k1 k8) ?_ + have hv := field_val hua k1 + rintro (⟨r, hr⟩ | hb) + · have hrv := regA_val hca (regIdxA_lt r) + have hlt := regIdxA_lt r + have ev : (wa u K).val = (Endp.regA c0 (regIdxA r)).val := hr + rw [hv, hrv] at ev + by_cases e : u = c0 + · subst e; omega + · have hf := hua.fits + have hf' := hca.fits + have h1' := hua.align + have h2' := hca.align + have hne : u.val ≠ c0.val := fun h => e (UScalar.eq_of_val_eq h) + omega + · have := J1.iplaced.e.bt _ hb u hu + omega + have hscT : L.mem sTag (scA c0) = w := (keepT c0 hcZ 3464#u64 (by simp) (by simp) (Or.inr (by simp))).trans hscU + have hiqT : L.mem sTag (inqA c0) = L.mem s1 (inqA c0) := + keepT c0 hcZ 3592#u64 (by simp) (by simp) (Or.inr (by simp)) + have hwH : w ∈ H.scs := by rw [J1.scs]; exact hwC + obtain ⟨-, -, -, -, hS1⟩ := J1.sys.ent.bxi + have hcH : c0 ∈ H.tcbs := by rw [J1.tcbs]; exact hcZ + have hmΩ : maxA w ∈ H.omega := hS1.sub _ (hS1.all _ hwH).2.1 + have hma : Aligned (maxA w) := (J1.sq.omega _ hmΩ).1 + have hrmT : L.rmax sTag w ≠ 0#u64 := by + obtain ⟨z, k, ez, ezr⟩ := hST.rest.refillMax w hwC + obtain ⟨z0, k0, ez0, hp0⟩ := hpos + rw [hOth _ hneSC, ez0] at ez + cases ez + have e3' : L.rmax sTag w = L.mem sTag (wa w 72#u64) := by unfold LawfulStore.rmax; rw [maxA_eqA] + rw [e3'] + intro h + rw [h] at ezr + simp at ezr + omega + have hmxT : stA c0 ≠ maxA w := fun h => + out_ne_field (J1.sq.omega _ hmΩ) hcH hca (K := 3328#u64) (by simp) + (by rw [← stA_eq]; exact congrArg UScalar.val h) + have eRun : sched.set_thread_state st sTag c0 sched.TS_RUNNING = ok (L.wr sTag (stA c0) sched.TS_RUNNING) := + set_thread_state_run_wrA hca (by rw [hscT]; exact hscx1) (by rw [hscT]; exact hrmT) + (by rw [hiqT]; exact hiq1) (by rw [hscT]; exact hma) (by rw [hscT]; exact hmxT) + -- the spec: the reply and the caller's Running + have hKT : SIKA σ1.idleThread (fun p => p = specPtr c0) (fun _ => False) false σ1 σT := + (replyFromKernel_sikA (i := σ1.idleThread) (M := fun p => p = specPtr c0) (N := fun _ => False) (don := false) + (specPtr c0) _) σ1 ((), σT) (by rw [hReply]; rfl) + have hrqT : specPtr c0 ∉ σT.releaseQueue := fun h => hrq (hKT.rls _ h) + have hsch : schedulable (specPtr c0) (setObjA σT (specPtr c0) (.tcb { xT with tcbState := .running })) = true := by + obtain ⟨ysc, nsc, hysc, hpos'⟩ := hpos + refine schedulable_ofA (x := { xT with tcbState := .running }) (n := nsc) (by simp [setObjA]) rfl hxTsc + (y := ysc) ?_ hpos' hrqT + simpa [setObjA, Function.update_of_ne hneSC, hOth _ hneSC] using hysc + have hscneT : σT.curSc ≠ specPtr c0 := by + have e : σT.curSc = σ1.curSc := by rw [hKT.frame] + rw [e]; exact hcsc1 + obtain ⟨σ3, hset, e3, KT, Uq⟩ := finishCall_specA hkc1 hReply hkT hsch hscneT + rw [eRun] + simp only [bind_ok] + rw [WP.spec_ok] + set s3 := L.wr sTag (stA c0) sched.TS_RUNNING with hs3 + have same3 : ∀ p, p ≠ specPtr c0 → σ3.kheap p = σ1.kheap p := fun p e => by + rw [e3]; simp [stUpdA, setObjA, Function.update_of_ne e, hOth p e] + have at3 : σ3.kheap (specPtr c0) = some (.tcb { xT with tcbState := .running }) := by + rw [e3]; simp [stUpdA, setObjA] + have hstv : (stA c0).val = c0.val + 3328 := by + rw [stA_eq, field_val hca (by decide)]; simp + -- the write sets + have ewR : ∀ b, RcvRegA c0 b → EWrite Z.T E Rp Bf b := fun b ⟨r, hr⟩ => by + have hrv := regA_val hca (regIdxA_lt r) + have hlt := regIdxA_lt r + rw [hrv] at hr + exact Or.inr (Or.inr (Or.inl ⟨c0, hcZ, Or.inl ⟨by omega, by unfold TWOffN; omega⟩⟩)) + have ewS : EWrite Z.T E Rp Bf (stA c0) := + Or.inr (Or.inr (Or.inl ⟨c0, hcZ, Or.inl ⟨by omega, by unfold TWOffN; omega⟩⟩)) + have w3 := hWT.trans (writesIn_wr (s := sTag) (v := sched.TS_RUNNING) sA) + have w3I0 : WritesIn st s1 s3 (fun b => IpcFpA st Z E Rp Bf m σ1 s1 b) := + w3.mono fun b h => by + rcases h with (h | h) | h + · exact Or.inl (ewR b h) + · exact Or.inl (Or.inr (Or.inr (Or.inr h))) + · rw [h]; exact Or.inl ewS + have w3I : WritesIn st s1 s3 (fun b => IpcFpA st Z E Rp Bf m σ1 s1 b ∨ RepWA Rp b) := + w3I0.mono fun _ h => Or.inl h + have wN3 : WritesIn st s1 s3 (fun b => SchedStepNWA (st := st) N E Rp Z m σ1 s1 b ∨ BufW Bf b) := + w3.mono fun b h => by + rcases h with (h | h) | h + · exact ewrite_stepNA_buf J1.sr.core.tcbs (ewR b h) + · exact Or.inr h + · rw [h]; exact Or.inl (stA_stepNA J1.sr.core.tcbs hcZ) + have keep3 : ∀ u ∈ Z.T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → (K.val < 256 ∨ 552 ≤ K.val) → + K.val ≠ 3328 → L.mem s3 (wa u K) = L.mem s1 (wa u K) := by + intro u hu K k1 k8 kr k3 + have hua := J1.sr.core.tcbs u hu + refine (mem_wr_ne' sA (field_aligned hua k1 k8) ?_).trans (keepT u hu K k1 k8 kr) + intro e + have ev := congrArg UScalar.val e + rw [hstv, field_val hua k1] at ev + by_cases eu : u = c0 + · subst eu; omega + · have hf := hua.fits + have hf' := hca.fits + have h1' := hua.align + have h2' := hca.align + have hne : u.val ≠ c0.val := fun h => eu (UScalar.eq_of_val_eq h) + omega + refine ⟨rfl, σ3, Q2, R2, ?_, ?_, ?_⟩ + · -- the spec's perform + have hFinish : fl4FinishTcbReply true (((frame_registers ++ gp_registers).take count.bv.toNat).map + y.tcbArch.tcbContext.userRegs) σ1 = ({((), σ3)}, False) := by + unfold fl4FinishTcbReply + rw [nd_bind_oneSc (show (Fl4Spec.NonDet.gets fun s : State Unit => s.curThread) σ1 = + ({(σ1.curThread, σ1)}, False) from rfl)] + rw [show σ1.curThread = specPtr c0 from hct2] + rw [nd_bind_oneSc (show (Fl4Spec.NonDet.when true (replyFromKernel (Z := Unit) (specPtr c0) + (0, ((frame_registers ++ gp_registers).take count.bv.toNat).map y.tcbArch.tcbContext.userRegs))) σ1 = + ({((), σT)}, False) from hReply)] + exact hset + unfold fl4PerformInvocation + rw [run_bind_okD (tcbReadRegisters_specA true count.bv hdetx hsuspx hy), run_bind_okD (run_liftE_stD hFinish)] + rfl + · -- the body-end facts + have hsw : SwA σ3 := fun u h => by + rcases KT.act with e | e | ⟨y', hy', -⟩ + · exact absurd (e.symm.trans h) (hns2 u) + · rw [e] at h; cases h + · exact hy'.elim + have hcurS : σ3.curThread = σ1.curThread := Uq.2.ct + refine ⟨hBm.1.step hsw Uq.2.time Uq.2.lmt hcurS Uq.2.csc Uq.2.used ?_ ?_ ?_ ?_, hcurS.trans hBm.2⟩ + · exact fun y k _ o _ hm => KT.rls _ hm + · intro y' k h + have e : σ3.kheap σ1.curSc = σ1.kheap σ1.curSc := same3 _ hcsc1 + exact ⟨y', by rw [← e]; exact h, rfl, rfl, Or.inl rfl⟩ + · intro _ x' hx' + rw [hct2, at3] at hx' + cases hx' + exact Or.inl rfl + · intro h + rcases KT.act with e | e | ⟨y', hy', -⟩ + · exact e.symm.trans h + · rw [e] at h; cases h + · exact hy'.elim + · intro Ac' bx sysl symL userOK j7 + have T2 : StEqA Z.T (L.mem sTag) σT := fun u hu y' hy' => (hET.at_tcb hu hy').st + have hrunT : runnable xT.tcbState = true := by rw [hxTst]; rfl + have hvn : sched.TS_RUNNING.val = tsCodeA .running := by rw [ts_vals.1]; rfl + have srh := sc_set_runnable_stateA (Z := { Z with Q := Q2, R := R2 }) hST T2 hcZ hkT hrunT (ts := .running) + rfl hvn + rw [eRun, WP.spec_ok] at srh + obtain ⟨τ, hτ, sr3, -, -, -⟩ := srh + have eτ : τ = σ3 := by + rw [hset] at hτ + exact ((Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst hτ))).2).symm + rw [eτ] at sr3 + have notQ : ∀ e ∈ E, ∀ z, σT.kheap (specPtr e) = some (.endpoint z) → specPtr c0 ∉ z.epQueue := by + intro e he z hz hq + obtain ⟨z', hz', rel⟩ := hET.ep e he + rw [hz] at hz' + obtain rfl := KernelObject.endpoint.inj (Option.some.inj hz') + obtain ⟨qs, _, hqs, members⟩ := rel.queue + rw [hqs, List.mem_map] at hq + obtain ⟨u, hu, hEq⟩ := hq + have eu : u = c0 := specPtr_inj hEq + subst eu + have state := (members c0 hu).2 + rw [(hET.at_tcb hcZ hkT).st] at state + simp [hxTst] at state + exact absurd state (by decide) + have code : sched.TS_RUNNING.val = Notif.tsCode .running := by rw [ts_vals.1]; rfl + have eσ : Notif.updK σT (specPtr c0) (.tcb { xT with tcbState := .running }) = σ3 := by rw [e3]; rfl + have ep3 : EpStateRel Z.T E Rp Bf (L.mem s3) σ3 := by + have h := (Endp.write_state_rel J1.iplaced.e sTag σT hET hcZ hkT notQ .running (by decide) _ code).1 + rw [eσ] at h; exact h + have hMs : ∀ u ∈ Z.T, specPtr u = specPtr c0 → ∀ x, σ1.kheap (specPtr u) = some (.tcb x) → + ∀ p, x.tcbState ≠ .blockedOnNotification p := by + intro u hu hm x hx p h + rw [hm, hkc1] at hx; cases hx; cases h + have hMs' : ∀ u ∈ Z.T, specPtr u = specPtr c0 → ∀ x, σ3.kheap (specPtr u) = some (.tcb x) → + ∀ p, x.tcbState ≠ .blockedOnNotification p := by + intro u hu hm x hx p h + rw [hm, at3] at hx; cases hx; cases h + have wk : NtfnWaitKeepA Z.T N (L.mem s1) (L.mem s3) := by + intro u hu _ + simp only [Notif.tBlockA_eq, Notif.prevEp_eq, Notif.nextEp_eq] + exact ⟨keep3 u hu _ (by simp) (by simp) (Or.inr (by simp)) (by simp), + keep3 u hu _ (by simp) (by simp) (Or.inr (by simp)) (by simp), + keep3 u hu _ (by simp) (by simp) (Or.inr (by simp)) (by simp)⟩ + have ntfn3 := J1.ntfn_ipcA w3I KT ep3 wk hMs hMs' + have rp3 := J1.reply_ipcA w3I0 KT + have tw : ∀ u ∈ Z.T, ∀ O : U64, O.val < 224 ∨ O.val = 3440 ∨ O.val = 3472 ∨ O.val = 3512 ∨ O.val = 3456 → + O.val % 8 = 0 → L.mem s3 (wa u O) = L.mem s1 (wa u O) := + fun u hu O hO h8 => keep3 u hu O (by omega) h8 (by omega) (by omega) + have notM : ∀ c < n, ¬ (m.idleThreadOf c = specPtr c0) := by + intro c hc e + obtain ⟨y1, hy1, hs1⟩ := J1.sidle.f3 c hc + rw [e, hkc1] at hy1; cases hy1; cases hs1 + have hMI : ¬ (σ1.idleThread = specPtr c0) := by + intro e + obtain ⟨y1, hy1, hs1⟩ := J1.sinv.idleTcb + rw [e, hkc1] at hy1; cases hy1; cases hs1 + have hMq : ∀ y, y = specPtr c0 → ∀ d p, y ∉ σ1.readyQueues d p := by + intro y hy d p hm + subst hy + exact offq.1 d p hm + have hMf : ∀ p, p = specPtr c0 → ∀ x y', σ1.kheap p = some (.tcb x) → σ3.kheap p = some (.tcb y') → + y'.tcbFault ≠ none → FaultStA y'.tcbState := by + intro p hp x y' hx hy' hf + subst hp + rw [hkc1] at hx; cases hx + rw [at3] at hy'; cases hy' + exfalso; apply hf + have h0 : ({ xc with tcbState := .restart } : Tcb).tcbFault = none := + FaultStOkA.none J1.sinv.faultSt hkc1 (by rintro (⟨_, _, h⟩ | ⟨_, h⟩ | h) <;> cases h) + exact (congrArg Tcb.tcbFault hxT).trans h0 + have sinv3 : SInvXA σ3 m n := + KT.sinv J1.sinv notM hMI hMq (fun y hy => hy.elim) (fun y hy => hy.elim) hns2 + (fun y hy => by rw [hy]; exact hrq) (J1.sidle.rdyA J1.sinv) hMf + have sidle3 : SIdleA σ3 m n := KT.sidle J1.sidle notM (J1.sidle.rdyA J1.sinv) + have hMv : ∀ u ∈ Z.T, specPtr u = specPtr c0 → L.mem s1 (stA u) ≠ sched.TS_RUNNING_VM := by + intro u hu hm h + have hst := (J1.ep.at_tcb hcZ hkc1).st + rw [specPtr_inj hm] at h + rw [h] at hst + revert hst; simp [tsCode, sched.TS_RUNNING_VM] + have rv3 := J1.runVcpu_ipcA w3I KT ep3 hMv + have bq3 := J1.blkQ_ipcA KT ep3 wk (fun u hu hm x hx => by + rw [show specPtr u = specPtr c0 from hm, at3] at hx; cases hx + exact ⟨rfl, fun _ h => by cases h⟩) + have sc' : ∀ p, ScActiveAtA σ1 p → ScActiveAtA σ3 p := fun p ⟨y1, k1, e1, act⟩ => by + have hne : p ≠ specPtr c0 := fun h => by rw [h, hkc1] at e1; cases e1 + exact ⟨y1, k1, by rw [same3 p hne]; exact e1, act⟩ + have tcbAct : ∀ u, (∃ y c, σ1.kheap u = some (.tcb y) ∧ y.tcbSchedContext = some c ∧ ScActiveAtA σ1 c) → + ∃ y c, σ3.kheap u = some (.tcb y) ∧ y.tcbSchedContext = some c ∧ ScActiveAtA σ3 c := by + intro u ⟨y1, c, e1, es, act⟩ + by_cases hu : u = specPtr c0 + · subst hu + rw [hkc1] at e1; cases e1 + exact ⟨{ xT with tcbState := .running }, c, at3, (congrArg Tcb.tcbSchedContext hxT).trans es, sc' _ act⟩ + · exact ⟨y1, c, by rw [same3 u hu]; exact e1, es, sc' _ act⟩ + have hrl' : ∀ u ∈ σ3.releaseQueue, u ∈ σ1.releaseQueue := KT.rls + have sv3 : SchedValidA σ3 := by + refine ⟨fun d p u hm => ?_, fun e1 e2 => ?_, fun u y' c e1 e2 e3' => ?_, fun u hu => ?_⟩ + · have hm1 : u ∈ σ1.readyQueues d p := by + rcases KT.rq d p u hm with h | h | h + · exact h + · exact h.elim + · exact absurd h (hns2 u) + obtain ⟨act, nr⟩ := J1.schedValid.rq d p u hm1 + exact ⟨tcbAct u act, fun h => nr (hrl' u h)⟩ + · have e1' := Uq.2.act e1 + have e2' : σ1.curThread ≠ σ1.idleThread := by + rw [← Uq.2.ct, ← Uq.2.idle]; exact e2 + obtain ⟨act, nr⟩ := J1.schedValid.act e1' e2' + refine ⟨by rw [Uq.2.ct]; exact tcbAct _ act, fun h => nr ?_⟩ + rw [← Uq.2.ct]; exact hrl' _ h + · by_cases h : u = specPtr c0 + · rw [h, at3] at e1; cases e1; simp [BlockedTsA] at e2 + · rw [same3 u h] at e1 + exact sc' _ (J1.schedValid.blk u y' c e1 e2 e3') + · exact tcbAct u (J1.schedValid.rls u (hrl' u hu)) + exact J1.of_replyStepA (Q := Q2) (Rl := R2) (curOf := Z.curOf) (curScOf := Z.curScOf) (s' := s3) (σ' := σ3) + wN3 Uq.1.1.1 Uq.1.1.2.1 Uq.1.2 (J1.specZero_of_recvBufA hcZ hkc1 Uq.1.1.2.2) (fun _ _ => rfl) + bx sysl symL userOK j7 sr3 ep3 ntfn3 rp3 KT.ipcKeep tw sinv3 sidle3 rv3 bq3 sv3 + obtain ⟨⟨res, s3, a3⟩, hdec', hP⟩ := exists_of_specA hWP + obtain ⟨h1', h2', σ3, Q2, R2, hperf, hB, hJ⟩ := hP + simp only at h1' h2' hJ + have hd : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk true don false buf extra = + ok (.Ok (), s3, a) := by rw [hdecEq, hdec', h1', h2'] + obtain ⟨-, Ac', sysl, symL, bx, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hd σ3 m + exact ⟨xc, σR, σ3, s3, hkc, eR, hsp', hperf, hd, Ac', Q2, R2, stk', hJ Ac' bx sysl symL userOK j7, hB⟩ + + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbReadRegsA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbReadRegsA.lean new file mode 100644 index 000000000..4b1fa760f --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbReadRegsA.lean @@ -0,0 +1,172 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregr): **TCB ReadRegisters (Send, no source suspension) at the record**. + +* **`JSyscallA.readRegsSendA`**: `decode_invocation` on a Thread cap with the ReadRegisters label, `Call` flag clear, + suspension bit clear, at a syscall entry: the caller's `Restart`, no further write (the spec's source read is the + identity on the state), then the caller's `Running` (`vspace.reply1 … false`, i.e. `replyOneMidA` with an empty body + between `Restart` and `Running`; the shape SetFlags uses). + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `hCs`; [S] `h1` (`numNodes = 1`, the remote +stall); decode-site facts `hlen`, `hf`, `hn`, `hlo`, `hhi`, `hself` (the target is not the caller). The decode +succeeds; the `Err` returns are not lifted (`Stage3DecErrTcbRegsA`). New module. +-/ +import Fl4ProofsA64.P3.Stage3Lift3QA +import Fl4ProofsA64.P3.Stage3ReplyMidA +import Fl4ProofsA64.P3.Stage3TcbBodyA +import Fl4ProofsA64.P3.TcbReadJointA +import Fl4ProofsA64.P3.TcbInvokeReadPostA +import Fl4ProofsA64.P3.TcbInvokeRegisterSelectA +import Fl4ProofsA64.P3.DelScStallA +import Fl4ProofsA64.P3.Stage3SignalIdleA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} {s : S} {a : A} {σ : State Unit} {m : McState} + +/-- **The spec's Send ReadRegisters** from the state after the caller's `Restart`: the source read does not change +the state and the finish sets the caller `Running`; `σ3` is any state the finish (`Call` clear) reaches. -/ +theorem readRegsSend_performA {σ1 σ3 : State Unit} {t : ObjRef} {src : Tcb} {count : Word} {blk don : Bool} + {words : List Data} (hsrc : σ1.kheap t = some (.tcb src)) + (h : ((), σ3) ∈ ((do + Fl4Spec.NonDet.when false (Fl4SpecA64.replyFromKernel (Z := Unit) σ1.curThread (0, words)) + Fl4SpecA64.setThreadState (Z := Unit) σ1.curThread .running) σ1).1) : + (.ok [], σ3) ∈ ((fl4PerformInvocation blk false don + (.invokeTCB (.readRegisters t false count ArchDefaultExtraRegisters))).run σ1).1 := by + unfold fl4PerformInvocation + rw [run_bind_okD (readRegsSpec_noSuspendA hsrc count)] + refine mem_bindE_okD (a := ()) (s' := σ3) (mem_liftED ?_) ?_ + · unfold fl4FinishTcbReply + exact mem_bind_ndD (x := (σ1.curThread, σ1)) (by rfl) h + · rw [run_returnOkD]; exact Set.mem_singleton _ + +set_option maxHeartbeats 4000000 in +/-- **TCB ReadRegisters (Send, no suspension) at a syscall entry** (module docstring). -/ +theorem JSyscallA.readRegsSendA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t flags count : U64} {blk don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, false, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, false, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) (hsuspend : (flags &&& 1#u64) = 0#u64) : + ∃ xc σ1 σ3 s3, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ3) ∈ ((fl4PerformInvocation blk false don + (.invokeTCB (.readRegisters (specPtr t) false count.bv ArchDefaultExtraRegisters))).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk false don false buf extra = + ok (.Ok (), s3, a) ∧ + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 m ∧ Sched.BodyEndA σ σ3 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J1, -, -, -⟩ := J.toJStage3A.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + set s1 := L.wr s (stA (L.curW s)) sched.TS_RESTART with hs1 + set σ1 := stUpdA σ σ.curThread xc .restart with hσ1 + have ct : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + set c0 := L.curW s with hc0 + have hcZ : c0 ∈ Z.T := J.sr.curT + have hcur1 : L.curW s1 = c0 := specPtr_inj (J1.j.1.sch.curThread.symm.trans ct) + have hr : tcb.restart_caller st s = ok s1 := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + obtain ⟨y, hy, -⟩ := J1.mcp t ht + -- the current thread's facts at the state after the Restart + have hscx1 : L.mem s (scA c0) ≠ 0#u64 := RS.cur.2.1 + set w := L.mem s (scA c0) with hw + have hwC : w ∈ Z.C := J.j.1.rest.scMem c0 hcZ hscx1 + have farA : ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → K.val ≠ 3328 → + L.mem s1 (wa c0 K) = L.mem s (wa c0 K) := by + have hca : TcbAddr c0 := J.sr.core.tcbs _ hcZ + have sA : Aligned (stA c0) := by rw [stA_eq]; exact field_aligned hca (by simp) (by simp) + intro K k1 k2 k3 + exact mem_wr_ne' sA (field_aligned hca k1 k2) + (by rw [stA_eq]; exact field_ne (K2 := K) hca hca (by simp) k1 (fun _ => by simpa using Ne.symm k3)) + have hscU : L.mem s1 (scA c0) = w := farA 3464#u64 (by simp) (by simp) (by simp) + have hiqU : L.mem s1 (inqA c0) = L.mem s (inqA c0) := farA 3592#u64 (by simp) (by simp) (by simp) + have hscx : xc.tcbSchedContext = some (scRenA m w) := by + obtain ⟨z, hz, -, hsx⟩ := J.j.1.sch.tcb c0 hcZ + rw [← ct, hkc] at hz; cases hz + rw [hsx]; unfold optScA; rw [← hw, if_neg hscx1] + have hpos : ∃ z k, σ1.kheap (scRenA m w) = some (.schedContext z k) ∧ 0 < z.scRefillMax := by + have hbx := J.sys.ent.bxi + obtain ⟨-, -, -, -, hS⟩ := hbx + have hwH : w ∈ H.scs := by rw [J.scs]; exact hwC + have hrm : L.rmax s w ≠ 0#u64 := (hS.act w hwH).1 RS.cur.2.2 + obtain ⟨z, k, ez, ezr⟩ := J.j.1.rest.refillMax w hwC + have e3 : L.rmax s w = L.mem s (wa w 72#u64) := by unfold LawfulStore.rmax; rw [maxA_eqA] + rw [e3] at hrm + have hp0 : 0 < z.scRefillMax := by + rw [ezr]; exact Nat.pos_of_ne_zero (fun e => hrm (UScalar.eq_of_val_eq (by simpa using e))) + refine ⟨z, k, ?_, hp0⟩ + simp only [hσ1, stUpdA, setObjA] + rw [Function.update_of_ne (fun e => by rw [e, hkc] at ez; cases ez)]; exact ez + have hrq : σ1.curThread ∉ σ1.releaseQueue := by + show σ.curThread ∉ σ.releaseQueue + rw [ct, J.j.1.rest.rel]; intro hm + obtain ⟨q, hq, eq⟩ := List.mem_map.1 hm + have e' : q = c0 := specPtr_inj eq + subst e' + have haf := J.sq.inR _ J.sq.cur _ hq + exact ((J.sq.released _ (by rw [J.tcbs]; exact hcZ)).2 (by rw [haf]; exact hq)) RS.cur.1 + have h10 : σ1.kheap σ1.curThread = some (.tcb { xc with tcbState := .restart }) := by + simp only [hσ1, stUpdA, setObjA, Function.update_self] + -- the program + have hprog : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk false don false buf extra = + (do let s4 ← vspace.reply1 st s1 c0 false 0#u64; ok (core.result.Result.Ok (), s4, a)) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + tcbReadRegisters_acceptedA hstall hlen hf hn hlo hhi hself hr] + have hcall : (⟨len, buf, false, slot, extra⟩ : tcb.Ctx).call = false := rfl + rw [hcall, hsuspend] + simp only [bne_self_eq_false, tcbReadRegisters_sendA, Bool.false_eq_true, ite_false, bind_ok, + uncurry_apply_pair, Std.bind_assoc, hcur1] + simp only [vspace.reply1, Bool.false_eq_true, ite_false, bind_ok] + have R := J1.replyOneMidA (Q0 := Z.Q) (R0 := Z.R) (WritesIn.refl _ _) (PreO.refl σ1) + ⟨fun p x h => ⟨x, h, rfl, rfl, rfl, rfl, rfl⟩, fun p z k h => ⟨z, k, h, rfl⟩, fun p z k h => ⟨z, k, h, rfl⟩⟩ + (QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩) (fun _ _ _ _ _ => rfl) + J1.sr J1.ep J1.ntfn J1.reply J1.mcp J1.yieldRel J1.sinv J1.sidle J1.runVcpu J1.blkQ J1.schedValid + (BXI.blk J1.sys.ent.bxi) + J1.sr.sch.curThread h10 rfl (by rw [hcur1, hscU]; exact hscx1) (by rw [hcur1, hscU]; exact RS.cur.2.2) + (by rw [hcur1, hiqU]; exact RS.cur.1) hrq (by rw [hcur1, hscU]; exact hwC) + (by rw [hcur1, hscU]; exact hscx) (by rw [hcur1, hscU]; exact hpos) false 0#u64 + (fun s' h2 σX => by + have hd : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk false don false buf extra = + ok (core.result.Result.Ok (), s', a) := by rw [hprog, ← hcur1, h2, bind_ok] + obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hd σX m + exact ⟨sysl, symL, userOK, j7⟩) + rw [hcur1] at R + obtain ⟨s3, e3, σ3, hrun, hsh, Q, Rl, J2⟩ := exists_of_specA R + have hsrc : σ1.kheap (specPtr t) = some (.tcb y) := hy + have same : updKSc σ1 (specPtr t) (.tcb y) = σ1 := by + unfold updKSc; rw [← hy, Function.update_eq_self] + refine ⟨xc, σ1, σ3, s3, hkc, rfl, hsp, readRegsSend_performA hsrc hrun, ?_, Q, Rl, J2, + Sched.BodyEndA.ofTcbReply J hkc hy same.symm hsh⟩ + rw [hprog, e3, bind_ok] + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbReadRegsSuspA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbReadRegsSuspA.lean new file mode 100644 index 000000000..02cff7f26 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbReadRegsSuspA.lean @@ -0,0 +1,141 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregr): **TCB ReadRegisters (Send) with source suspension at the record**. + +* **`JSyscallA.readRegsSendSuspA`**: `decode_invocation` on a Thread cap with the ReadRegisters label, `Call` flag clear, + suspension bit set, target not the caller, at a syscall entry: the caller's `Restart`, the suspension of the source + (`JSyscallA.suspendMidA`: cancel the VCPU run, then `sched.suspend`), then the caller's `Running` + (`JStage3A.replyOneA` at the mid state, whose caller facts are `SuspCallerA`'s). +* `BodyEndA.ofReplyMid`: the body-end facts across a one-word reply from a mid state with the body-end facts. + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `hCs`, `hmb`, `hmax`, `htu`; [S] `h1` +(`numNodes = 1`, the remote stall); decode-site facts `hlen`, `hf`, `hn`, `hlo`, `hhi`, `hself`. The `Err` returns are +not lifted. New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbReadRegsA +import Fl4ProofsA64.P3.Stage3TcbSuspendArmA +import Fl4ProofsA64.P3.Stage3RecvPreA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4SpecA64 + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +/-- **`BodyEndA` across a one-word reply from a mid state** (module docstring). -/ +theorem Sched.BodyEndA.ofReplyMid {σ2 σ3 : State Unit} {x : Tcb} (hB : BodyEndA σ σ2 m) + (hns : ∀ u, σ2.schedulerAction ≠ .switchThread u) (hsc : ∃ y k, σ2.kheap σ2.curSc = some (.schedContext y k)) + (hk : σ2.kheap σ2.curThread = some (.tcb x)) (hS : ReplyShapeA σ2 σ3 x) : BodyEndA σ σ3 m := by + obtain ⟨uc, e3⟩ := hS + subst e3 + obtain ⟨y0, j, h0⟩ := hsc + have ne : σ2.curSc ≠ σ2.curThread := fun e => by rw [e, hk] at h0; cases h0 + refine ⟨hB.1.stepEq (fun u h => absurd h (hns u)) rfl rfl rfl rfl rfl rfl (fun y' k' h => ?_) (fun _ x' hx' => ?_), hB.2⟩ + · simp only [setObjA, Function.update_of_ne ne] at h + exact ⟨y', h, rfl, rfl, rfl⟩ + · simp only [setObjA, Function.update_self, Option.some.injEq, KernelObject.tcb.injEq, replyTcbA] at hx' + subst hx' + exact Or.inl rfl + +/-- **The spec's Send ReadRegisters with suspension** from the state after the caller's `Restart`. -/ +theorem readRegsSend_performSuspA {σ1 σx σ2 σ3 : State Unit} {t : ObjRef} {src : Tcb} {count : Word} {blk don : Bool} + {words : List Data} (hc : fl4CancelRun (Z := Unit) t σ1 = ({((), σx)}, False)) + (hs : Fl4SpecA64.suspend (Z := Unit) t σx = ({((), σ2)}, False)) (hsrc : σ2.kheap t = some (.tcb src)) + (h : ((), σ3) ∈ ((do + Fl4Spec.NonDet.when false (Fl4SpecA64.replyFromKernel (Z := Unit) σ2.curThread (0, words)) + Fl4SpecA64.setThreadState (Z := Unit) σ2.curThread .running) σ2).1) : + (.ok [], σ3) ∈ ((fl4PerformInvocation blk false don + (.invokeTCB (.readRegisters t true count ArchDefaultExtraRegisters))).run σ1).1 := by + unfold fl4PerformInvocation + rw [run_bind_okD (tcbReadRegisters_specA true count hc hs hsrc)] + refine mem_bindE_okD (a := ()) (s' := σ3) (mem_liftED ?_) ?_ + · unfold fl4FinishTcbReply + exact mem_bind_ndD (x := (σ2.curThread, σ2)) (by rfl) h + · rw [run_returnOkD]; exact Set.mem_singleton _ + +set_option maxHeartbeats 4000000 in +/-- **TCB ReadRegisters (Send, source suspended) at a syscall entry** (module docstring). -/ +theorem JSyscallA.readRegsSendSuspA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + {slot lbl len buf t flags count : U64} {blk don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBReadRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, false, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, false, slot, extra⟩ 1#u64 = ok count) + (hlo : ¬ count < 1#u64) (hhi : ¬ 36#u64 < count) (hself : t ≠ L.curW s) (hsuspend : (flags &&& 1#u64) ≠ 0#u64) : + ∃ xc σ1 σ3 s3, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ3) ∈ ((fl4PerformInvocation blk false don + (.invokeTCB (.readRegisters (specPtr t) true count.bv ArchDefaultExtraRegisters))).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk false don false buf extra = + ok (.Ok (), s3, a) ∧ + ∃ Q Rl stack', JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack' κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 m ∧ Sched.BodyEndA σ σ3 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J1, -, -, -⟩ := J.toJStage3A.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have ct : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have hcur1 : L.curW (L.wr s (stA (L.curW s)) sched.TS_RESTART) = L.curW s := + specPtr_inj (J1.j.1.sch.curThread.symm.trans ct) + have hr : tcb.restart_caller st s = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + have hb : ((flags &&& 1#u64) != 0#u64) = true := bne_iff_ne.2 hsuspend + obtain ⟨xc', σ1, σ2, s2, a2, hkc', e1, hsp', -, -, -, Q, Rl, stk', Jm, hB, hsus, ⟨σx, hdetx, hsuspx⟩, hcal⟩ := + J.suspendMidA hA hM hPl hfm hCs h1 hmb hmax htu hslot hcov hcap hext hSC (lbl := fl4_abi.label.TCBSuspend) rfl + (blk := blk) (call := false) (don := don) (len := len) (buf := buf) + have hxx : xc = xc' := by rw [hkc] at hkc'; exact KernelObject.tcb.inj (Option.some.inj hkc') + subst hxx + obtain ⟨hx2, hsc2, hiq2, hrq2, hns2, -, -⟩ := hcal hself + have hcur2 : L.curW s2 = L.curW s := Sched.curW_keptA J.toJStage3A Jm hB.2 + have hct2 : σ2.curThread = specPtr (L.curW s) := hB.2.trans ct + have hprog : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk false don false buf extra = + (do let s4 ← vspace.reply1 st s2 (L.curW s) false 0#u64; ok (core.result.Result.Ok (), s4, a)) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + tcbReadRegisters_acceptedA hstall hlen hf hn hlo hhi hself hr] + have hcall : (⟨len, buf, false, slot, extra⟩ : tcb.Ctx).call = false := rfl + rw [hcall, hb] + simp only [tcbReadRegisters_sendA, ↓reduceIte, bind_ok, hsus, uncurry_apply_pair, Std.bind_assoc, hcur1] + simp only [vspace.reply1, Bool.false_eq_true, ite_false, bind_ok] + have hkx : σ2.kheap σ2.curThread = some (.tcb { xc with tcbState := .restart }) := by rw [hct2]; exact hx2 + have R := Jm.replyOneA (x := { xc with tcbState := .restart }) hkx (Or.inl rfl) + (by rw [hcur2, hsc2]; exact RS.cur.2.1) (by rw [hcur2, hsc2]; exact RS.cur.2.2) + (by rw [hcur2]; exact hiq2) (by rw [hct2]; exact hrq2) false 0#u64 + (fun s' h2 σX => by + have hd : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk false don false buf extra = + ok (core.result.Result.Ok (), s', a) := by rw [hprog, ← hcur2, h2, bind_ok] + obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hd σX m + exact ⟨sysl, symL, userOK, j7⟩) + rw [hcur2] at R + obtain ⟨s3, e3, σ3, hrun, hsh, Q', Rl', J3⟩ := exists_of_specA R + obtain ⟨y, hy, -⟩ := Jm.mcp t ht + refine ⟨xc, σ1, σ3, s3, hkc, e1, hsp', readRegsSend_performSuspA hdetx hsuspx hy hrun, ?_, Q', Rl', stk', J3, + Sched.BodyEndA.ofReplyMid hB hns2 Jm.sinv.curSc hkx hsh⟩ + rw [hprog, e3, bind_ok] + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopyA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopyA.lean new file mode 100644 index 000000000..6b332bef7 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopyA.lean @@ -0,0 +1,221 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **TCB CopyRegisters (register part) at the record: the register transfer**. + +* `ArchOnlyA`, `mapMx_archA`, `copyBlock_archA`: the spec's copy transfer (frame registers, `FaultIP -> NextIP`, GP registers) + changes the destination TCB's architecture part only (the pinned state `updKSc σ dest {y with tcbArch := g}`). +* **`JStage3A.copyRegs_stepA`**: the concrete transfer (optional frame loop + `NextIP` copy, optional GP loop) on a destination + other than the current thread keeps the record (`of_plainTcbA` + `tcbCopyRegisters_viewsTransferA`); writes are `PlainRegW`. + +Named premises: [S] none beyond the arm's; [J] `hVcpu` (the concrete bound-VCPU link). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbRegWriteA +import Fl4ProofsA64.P3.TcbCopyViewA +import Fl4ProofsA64.P3.TcbInvokeCopySpecA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 +open Fl4Spec (NonDet) + +noncomputable section + +/-- The spec state `σ` differs from `σ0` only in the architecture part (VCPU link kept) of the TCB `x` at `d`. -/ +def ArchOnlyA (σ0 : State Unit) (d : ObjRef) (x : Tcb) (σ : State Unit) : Prop := + ∃ g : ArchTcb, g.tcbVcpu = x.tcbArch.tcbVcpu ∧ σ = updKSc σ0 d (.tcb { x with tcbArch := g }) + +theorem updK_updKSc_idemA (σ0 : State Unit) (d : ObjRef) (o1 o2 : KernelObject) : + Notif.updK (updKSc σ0 d o1) d o2 = updKSc σ0 d o2 := by + unfold Notif.updK updKSc + simp only [Function.update_idem] + +theorem ArchOnlyA.refl {σ0 : State Unit} {d : ObjRef} {x : Tcb} (hk : σ0.kheap d = some (.tcb x)) : + ArchOnlyA σ0 d x σ0 := by + refine ⟨x.tcbArch, rfl, ?_⟩ + unfold updKSc + have e : Function.update σ0.kheap d (some (.tcb { x with tcbArch := x.tcbArch })) = σ0.kheap := by + rw [show some (KernelObject.tcb { x with tcbArch := x.tcbArch }) = σ0.kheap d from by rw [hk]] + exact Function.update_eq_self _ _ + rw [e] + +theorem ArchOnlyA.kheap_dest {σ0 : State Unit} {d : ObjRef} {x : Tcb} {σ : State Unit} (h : ArchOnlyA σ0 d x σ) : + ∃ g, g.tcbVcpu = x.tcbArch.tcbVcpu ∧ σ.kheap d = some (.tcb { x with tcbArch := g }) := by + obtain ⟨g, hv, rfl⟩ := h + exact ⟨g, hv, by simp [updKSc]⟩ + +theorem ArchOnlyA.kheap_other {σ0 : State Unit} {d s : ObjRef} {x : Tcb} {σ : State Unit} (h : ArchOnlyA σ0 d x σ) + (hne : s ≠ d) : σ.kheap s = σ0.kheap s := by + obtain ⟨g, -, rfl⟩ := h + simp [updKSc, Function.update_of_ne hne] + +/-- One register copy changes the destination's architecture part only. -/ +theorem copyRegister_archA {σ0 : State Unit} {d s : ObjRef} {x xs : Tcb} (hs : σ0.kheap s = some (.tcb xs)) + {g : Bool} {r : Register} {σ σ1 : State Unit} (h : ArchOnlyA σ0 d x σ) + (h1 : ((), σ1) ∈ (tcbCopyRegisterA d s g r σ).1) : ArchOnlyA σ0 d x σ1 := by + obtain ⟨g', hv', hkd⟩ := h.kheap_dest + obtain ⟨xs', hks⟩ : ∃ xs', σ.kheap s = some (.tcb xs') := by + by_cases e : s = d + · subst e; exact ⟨_, hkd⟩ + · exact ⟨xs, by rw [h.kheap_other e]; exact hs⟩ + unfold tcbCopyRegisterA at h1 + rw [Notif.nd_bind_one (asUser_getRegister_eqA hks r), Notif.asUser_setRegister_eq r _ hkd] at h1 + have e1 : σ1 = _ := (Prod.mk.inj (Set.mem_singleton_iff.1 h1)).2 + obtain ⟨g0, hv0, hσ⟩ := h + refine ⟨(Notif.setReg { x with tcbArch := g' } r + (fl4SanitiseRegister g r (xs'.tcbArch.tcbContext.userRegs r))).tcbArch, hv', ?_⟩ + rw [e1, hσ, updK_updKSc_idemA] + rfl + +/-- The spec's `mapMx` of register copies keeps the shape. -/ +theorem mapMx_archA {σ0 : State Unit} {d s : ObjRef} {x xs : Tcb} (hs : σ0.kheap s = some (.tcb xs)) {g : Bool} + (rs : List Register) : + ∀ {σ σ1 : State Unit}, ArchOnlyA σ0 d x σ → + ((), σ1) ∈ (NonDet.mapMx (tcbCopyRegisterA d s g) rs σ).1 → ArchOnlyA σ0 d x σ1 := by + induction rs with + | nil => + intro σ σ1 h h1 + have e : NonDet.mapMx (tcbCopyRegisterA d s g) [] σ = ({((), σ)}, False) := rfl + rw [e] at h1 + have := (Prod.mk.inj (Set.mem_singleton_iff.1 h1)).2 + rw [this]; exact h + | cons r rs ih => + intro σ σ1 h h1 + obtain ⟨⟨u, σm⟩, hm, hrest⟩ := h1 + exact ih (copyRegister_archA hs h hm) hrest + +/-- The spec's copy transfer (frame, `NextIP`, GP) keeps the shape. -/ +theorem copyBlock_archA {σ0 : State Unit} {d s : ObjRef} {x xs : Tcb} (hk : σ0.kheap d = some (.tcb x)) + (hs : σ0.kheap s = some (.tcb xs)) (g : Bool) (frame gp : Bool) {σ1 : State Unit} + (h1 : ((), σ1) ∈ ((do + NonDet.when frame (do + NonDet.mapMx (tcbCopyRegisterA d s g) frameRegisters + let pc ← asUser d getRestartPC + asUser d (setNextPC pc)) + NonDet.when gp (NonDet.mapMx (tcbCopyRegisterA d s g) gpRegisters)) σ0).1) : + ArchOnlyA σ0 d x σ1 := by + obtain ⟨⟨u, σF⟩, hF, hG⟩ := h1 + have hFr : ArchOnlyA σ0 d x σF := by + unfold NonDet.when at hF + by_cases hf : frame = true + · rw [if_pos hf] at hF + obtain ⟨⟨u2, σM⟩, hM, hN⟩ := hF + have hM' := mapMx_archA hs frameRegisters (ArchOnlyA.refl hk) hM + obtain ⟨g', hv', hkd⟩ := hM'.kheap_dest + have e : (do + let word ← asUser d getRestartPC + asUser d (setNextPC word)) σM = + ({((), Notif.updK σM d (.tcb (Notif.setReg { x with tcbArch := g' } .nextIP + ({ x with tcbArch := g' }.tcbArch.tcbContext.userRegs .faultIP))))}, False) := by + change ((asUser d (getRegister .faultIP)) >>= fun word => asUser d (setRegister .nextIP word)) σM = _ + rw [Notif.nd_bind_one (asUser_getRegister_eqA hkd .faultIP)] + exact Notif.asUser_setRegister_eq .nextIP _ hkd + have hN' : ((), σF) ∈ ((do + let word ← asUser d getRestartPC + asUser d (setNextPC word)) σM).1 := hN + rw [e] at hN' + have e1 := (Prod.mk.inj (Set.mem_singleton_iff.1 hN')).2 + obtain ⟨g0, hv0, hσM⟩ := hM' + refine ⟨(Notif.setReg { x with tcbArch := g' } .nextIP + ({ x with tcbArch := g' }.tcbArch.tcbContext.userRegs .faultIP)).tcbArch, hv', ?_⟩ + rw [e1, hσM, updK_updKSc_idemA] + rfl + · rw [if_neg hf] at hF + have := (Prod.mk.inj (Set.mem_singleton_iff.1 hF)).2 + rw [this]; exact ArchOnlyA.refl hk + have hG' : ((), σ1) ∈ (NonDet.when gp (NonDet.mapMx (tcbCopyRegisterA d s g) gpRegisters) σF).1 := hG + unfold NonDet.when at hG' + by_cases hg : gp = true + · rw [if_pos hg] at hG' + exact mapMx_archA hs gpRegisters hFr hG' + · rw [if_neg hg] at hG' + have := (Prod.mk.inj (Set.mem_singleton_iff.1 hG')).2 + rw [this]; exact hFr + + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 4000000 in +/-- **The CopyRegisters register transfer at the record** (module docstring). -/ +theorem JStage3A.copyRegs_stepA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {dest src p : U64} (frame gp : Bool) (ht : dest ∈ Z.T) (hs : src ∈ Z.T) + {y xs : Tcb} (hy : σ.kheap (specPtr dest) = some (.tcb y)) (hsrc : σ.kheap (specPtr src) = some (.tcb xs)) + (hVcpu : vcpu.bound st s dest = ok p) : + (do + let sFrame ← if frame then do + let s' ← tcb.copy_registers_loop0 st s dest src 0#u64 + let pc := L.mem s' (Endp.regA dest layout.reg.FAULT_IP) + ok (L.wr s' (Endp.regA dest layout.reg.NEXT_IP) pc) + else ok s + if gp then tcb.copy_registers_loop1 st sFrame dest src 0#u64 else ok sFrame) ⦃ s' => ∃ σ', + ((), σ') ∈ ((do + NonDet.when frame (do + NonDet.mapMx (tcbCopyRegisterA (specPtr dest) (specPtr src) (p != 0#u64)) frameRegisters + let pc ← asUser (specPtr dest) getRestartPC + asUser (specPtr dest) (setNextPC pc)) + NonDet.when gp + (NonDet.mapMx (tcbCopyRegisterA (specPtr dest) (specPtr src) (p != 0#u64)) gpRegisters)) σ).1 ∧ + ArchOnlyA σ (specPtr dest) y σ' ∧ WritesIn st s s' (PlainRegW Z.T) ∧ L.curW s' = L.curW s ∧ + BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ∧ + (SysL st H Z.Cs OS ia ie s' → SymL st H Z.Cs s' → Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s' → + J7A st (J7R2A st ar nA) Z H OS s' σ' m → + JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) + s' a σ' m) ⦄ := by + have hP := J.iplaced + have hT : TcbPlaced Z.T := hP.e.tcb + have hta : TcbAddr dest := hP.e.tcb dest ht + have V0 : TcbIpcViewsA st Z m κ N E Rp Bf stack s σ := + ⟨⟨Z.Q, Z.R, J.sr⟩, J.ntfn, J.ep, J.reply, J.mcp, J.yieldRel⟩ + have hViews := tcbCopyRegisters_viewsTransferA hP J.ipcPlace V0 ht hs hVcpu frame gp + have hPlain : (do + let sFrame ← if frame then do + let s' ← tcb.copy_registers_loop0 st s dest src 0#u64 + let pc := L.mem s' (Endp.regA dest layout.reg.FAULT_IP) + ok (L.wr s' (Endp.regA dest layout.reg.NEXT_IP) pc) + else ok s + if gp then tcb.copy_registers_loop1 st sFrame dest src 0#u64 else ok sFrame) ⦃ sG => + WritesIn st s sG (PlainRegW Z.T) ⦄ := by + refine WP.spec_bind (Pₘ := fun sF => WritesIn st s sF (PlainRegW Z.T)) ?_ fun sF wF => ?_ + · by_cases hf : frame = true + · rw [if_pos hf] + refine WP.spec_bind (tcb.copy_registers_loop0.plainA hT ht (WritesIn.refl _ _)) fun s1 w1 => ?_ + have hlt : (regIdxA .nextIP).val < 37 := regIdxA_lt _ + have al : Aligned (Endp.regA dest layout.reg.NEXT_IP) := by + have eN : layout.reg.NEXT_IP = regIdxA .nextIP := by + unfold layout.reg.NEXT_IP layout.reg.ELR_EL1 + rfl + rw [eN]; exact (Endp.regA_tf hta hlt).1 + have vb : (Endp.regA dest layout.reg.NEXT_IP).val = dest.val + 256 + 8 * (regIdxA .nextIP).val := by + have eN : layout.reg.NEXT_IP = regIdxA .nextIP := by + unfold layout.reg.NEXT_IP layout.reg.ELR_EL1 + rfl + rw [eN]; exact Endp.regA_val hta hlt + refine (WP.spec_ok _).2 ?_ + refine (w1.trans (writesIn_wr al)).mono fun b hb => hb.elim id fun hb => ?_ + exact ⟨dest, ht, by rw [hb, vb]; omega, by rw [hb, vb]; omega⟩ + · rw [if_neg hf] + exact (WP.spec_ok _).2 (WritesIn.refl _ _) + · by_cases hg : gp = true + · rw [if_pos hg] + exact tcb.copy_registers_loop1.plainA hT ht wF + · rw [if_neg hg] + exact (WP.spec_ok _).2 wF + refine WP.spec_mono (WP.spec_and hViews hPlain) ?_ + rintro s' ⟨⟨σ', hmem, V'⟩, w⟩ + obtain ⟨g, hv, hσ'⟩ := copyBlock_archA hy hsrc (p != 0#u64) frame gp hmem + subst hσ' + have w' : WritesIn st s s' (XferFoot H.tcbs ∅) := by + rw [J.tcbs]; exact WritesIn.plain_xferA hT w + have hblk := blk_rf (BXI.blk J.sys.ent.bxi) w' + refine ⟨_, hmem, ⟨g, hv, rfl⟩, w, hblk.2.2.1, hblk.1, fun sysl symL userOK j7 => ?_⟩ + exact J.of_plainTcbA ht hy g hv w hblk.1 sysl symL userOK j7 V'.ep V'.ntfn + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopyArmA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopyArmA.lean new file mode 100644 index 000000000..95f2fc0b2 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopyArmA.lean @@ -0,0 +1,144 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **TCB CopyRegisters (register transfer only) at a syscall entry**. + +* **`JSyscallA.copyRegsA`**: `decode_invocation` on a Thread cap with the CopyRegisters label, an extra Thread cap as the source, + `flags & 3 = 0` (no source suspension, no destination restart), a destination other than the caller; the frame (bit 2, with the + `FaultIP -> NextIP` copy) and GP (bit 3) transfers are the spec's `copyRegisters`. + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `hCs`; [S] `h1` (`numNodes = 1`, the remote stalls). +The source may be any thread (the caller included). The decode succeeds; the `Err` returns are not lifted. New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbRegCopyA +import Fl4ProofsA64.P3.Stage3TcbRegWriteArmA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 +open Fl4Spec (NonDet) + +noncomputable section + +/-- The spec's CopyRegisters (no suspend, no restart) of a thread other than the current one. -/ +theorem copyRegs_specA {σ1 : State Unit} {t src : ObjRef} {y : Tcb} {g : ArchTcb} {guest : Bool} {flags : U64} + (hy : σ1.kheap t = some (.tcb y)) (hOther : t ≠ σ1.curThread) + (hg : decide (y.tcbArch.tcbVcpu ≠ none) = guest) + (hbits : (flags &&& 1#u64 != 0#u64) = testBit flags.bv 0 ∧ (flags &&& 2#u64 != 0#u64) = testBit flags.bv 1 ∧ + (flags &&& 4#u64 != 0#u64) = testBit flags.bv 2 ∧ (flags &&& 8#u64 != 0#u64) = testBit flags.bv 3) + (hmem : ((), updKSc σ1 t (.tcb { y with tcbArch := g })) ∈ ((do + NonDet.when (flags &&& 4#u64 != 0#u64) (do + NonDet.mapMx (tcbCopyRegisterA t src guest) frameRegisters + let pc ← asUser t getRestartPC + asUser t (setNextPC pc)) + NonDet.when (flags &&& 8#u64 != 0#u64) (NonDet.mapMx (tcbCopyRegisterA t src guest) gpRegisters)) σ1).1) : + (.ok [], updKSc σ1 t (.tcb { y with tcbArch := g })) ∈ + ((fl4InvokeTcb (.copyRegisters t src false false (testBit flags.bv 2) (testBit flags.bv 3) + ArchDefaultExtraRegisters)).run σ1).1 := by + rw [hbits.2.2.1, hbits.2.2.2] at hmem + refine tcbCopyRegisters_specA (σSuspend := σ1) (σRestart := σ1) + (σTransfer := updKSc σ1 t (.tcb { y with tcbArch := g })) (guest := guest) ?_ ?_ ?_ hmem ?_ + · unfold NonDet.when + rw [if_neg Bool.false_ne_true] + exact Set.mem_singleton _ + · unfold NonDet.when + rw [if_neg Bool.false_ne_true] + exact Set.mem_singleton _ + · rw [tcbCopyRegisters_guestA hy, hg] + · unfold NonDet.when + have hn : ¬ t = (updKSc σ1 t (.tcb { y with tcbArch := g })).curThread := hOther + rw [if_neg hn] + exact Set.mem_singleton _ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxRecDepth 100000 in +set_option maxHeartbeats 4000000 in +/-- **TCB CopyRegisters (register transfer only) at a syscall entry** (module docstring). -/ +theorem JSyscallA.copyRegsA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t src srcSlot flags : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBCopyRegisters) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok srcSlot)) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (harg : srcSlot ∈ OS) (hsc : capA st s srcSlot = .Thread src) (hself : t ≠ L.curW s) + (hres1 : flags &&& 1#u64 = 0#u64) (hres2 : flags &&& 2#u64 = 0#u64) : + ∃ xc σ1 σ2 s2, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ2) ∈ ((fl4InvokeTcb (.copyRegisters (specPtr t) (specPtr src) false false + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, a) ∧ + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m ∧ Sched.BodyEndA σ σ2 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J1, -, -, -⟩ := J.toJStage3A.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have hsT : src ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy harg).1.2.2.2.2.2 src hsc + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have hstallS : smp.remote_tcb_stall st ar s a src = ok (s, a) := T0.stall_singleA hCs h1 hsT + set s1 := L.wr s (stA (L.curW s)) sched.TS_RESTART with hs1 + set σ1 := stUpdA σ σ.curThread xc .restart with hσ1 + have hr : tcb.restart_caller st s = ok s1 := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + have hcur1 : σ1.curThread = specPtr (L.curW s1) := J1.j.1.sch.curThread + have hcur0 : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have eq1 : L.curW s1 = L.curW s := specPtr_inj (hcur1.symm.trans hcur0) + have hne1 : t ≠ L.curW s1 := by rw [eq1]; exact hself + obtain ⟨y, hy, -⟩ := J1.mcp t ht + obtain ⟨xs, hxs, -⟩ := J1.mcp src hsT + have hbound : vcpu.bound st s1 t = ok (L.mem s1 (tVcpuA t)) := eq_of_spec_fd (vcpu.bound.spec (L := L) s1 t) + have hg : decide (y.tcbArch.tcbVcpu ≠ none) = (L.mem s1 (tVcpuA t) != 0#u64) := by + obtain ⟨z, hz, h, -⟩ := J1.j.2.1.tcb t ht + rw [hy] at hz + cases hz + have h' : y.tcbArch.tcbVcpu = optRefA (L.mem s1 (tVcpuA t)) := h + rw [h'] + unfold optRefA + by_cases e : L.mem s1 (tVcpuA t) = 0#u64 <;> simp [e] + have hbits := tcbCopyRegisters_flagBitsA flags + have K := J1.copyRegs_stepA (dest := t) (src := src) (p := L.mem s1 (tVcpuA t)) (flags &&& 4#u64 != 0#u64) + (flags &&& 8#u64 != 0#u64) ht hsT hy hxs hbound + obtain ⟨sG, hrun, σ', hmem, ⟨g, hv, hσ'⟩, w2, hcw2, blk2, KJ⟩ := spec_existsA K + subst hσ' + have hcsrc : obj.Slot.cap st srcSlot s = ok (.Thread src) := by rw [← hsc]; exact capA_eq s srcSlot + have hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), sG, a) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + tcbCopyRegisters_acceptedA hstall he hf hcsrc hstallS hr, tcbCopyRegisters_effectsA] + have hb1 : (flags &&& 1#u64 != 0#u64) = false := by simp [hres1] + have hb2 : (flags &&& 2#u64 != 0#u64) = false := by simp [hres2] + have hne2 : ¬ t = L.curW sG := fun e => hself (e.trans (hcw2.trans eq1)) + simp only [hb1, hb2, Bool.false_eq_true, ite_false, bind_ok, uncurry_apply_pair] + rw [← Std.bind_assoc, hrun, bind_ok] + simp only [if_neg hne2] + obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdec + (updKSc σ1 (specPtr t) (.tcb { y with tcbArch := g })) m + have J2 := KJ sysl symL userOK j7 + have hspec := copyRegs_specA (σ1 := σ1) (t := specPtr t) (src := specPtr src) hy + (by rw [hcur1]; exact fun e => hne1 (specPtr_inj e)) (guest := (L.mem s1 (tVcpuA t) != 0#u64)) hg + (flags := flags) hbits hmem + exact ⟨xc, σ1, _, sG, hkc, rfl, hsp, hspec, hdec, Z.Q, Z.R, J2, + Sched.BodyEndA.ofTcbUpd J hkc (y := y) (y' := { y with tcbArch := g }) hy rfl⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopyRsA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopyRsA.lean new file mode 100644 index 000000000..25e56da77 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopyRsA.lean @@ -0,0 +1,249 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **TCB CopyRegisters with the restart bit (`flags & 2`), at a syscall entry**. + +CopyRegisters restarts the destination *before* the register transfer, so the facts `SysL/SymL/UserOK/J7A` at the restart's +end state (which `restartStopped_stepA` needs) cannot come from the final `decodeFinA`; they come from P1's own step on the +restart (`sched.restart.dm`, a `K8` footprint ⊆ `SusW`, through `p1StepSusA`). + +* `JStage3A.restartMidA`: the five P1 facts and `OSKeep` after `sched.restart t`. +* `schedulable_archA` / `swa_archA`: an architecture-only TCB update keeps `SwA`. +* `copyRegsRestart_specA`: the spec's CopyRegisters with the restart bit on a stopped thread other than the current one. +* **`JSyscallA.copyRegsRestartA`**: `decode_invocation` on a Thread cap with the CopyRegisters label, `flags & 1 = 0`, + `flags & 2 ≠ 0`, a stopped destination other than the caller. + +Named premises: those of `copyRegsA`, plus [P] `hmb/hmbF/hmax/htu`, [S] `hsl`, `hstop` (as `writeRegsResumeA`). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbRegCopyArmA +import Fl4ProofsA64.P3.Stage3TcbRegMidA +import Fl4ProofsA64.P3.Stage3TcbSchedMidA +import Fl4ProofsA64.P3.Stage3TcbResumeRqA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 +open Fl4Spec (NonDet) + +noncomputable section + +/-- An architecture-only TCB update keeps `TKeepA`. -/ +theorem tkeep_archA {σ : State Unit} {p : ObjRef} {y : Tcb} (hy : σ.kheap p = some (.tcb y)) (g : ArchTcb) : + TKeepA σ (updKSc σ p (.tcb { y with tcbArch := g })) := by + refine ⟨rfl, rfl, rfl, rfl, rfl, fun t x' h => ?_, fun t x h => ?_, fun q z k h => ?_, rfl⟩ + · by_cases e : t = p + · subst e + simp only [updKSc, Function.update_self, Option.some.injEq, KernelObject.tcb.injEq] at h + subst h + exact ⟨y, hy, rfl, rfl⟩ + · exact ⟨x', by simpa [updKSc, Function.update_of_ne e] using h, rfl, rfl⟩ + · by_cases e : t = p + · subst e + rw [hy] at h + cases h + exact ⟨{ y with tcbArch := g }, by simp [updKSc], rfl⟩ + · exact ⟨x, by simpa [updKSc, Function.update_of_ne e] using h, rfl⟩ + · by_cases e : q = p + · subst e + rw [hy] at h + cases h + · exact ⟨z, by simpa [updKSc, Function.update_of_ne e] using h, rfl⟩ + +theorem swa_archA {σ : State Unit} {p : ObjRef} {y : Tcb} (hy : σ.kheap p = some (.tcb y)) (g : ArchTcb) + (h : SwA σ) : SwA (updKSc σ p (.tcb { y with tcbArch := g })) := + SwA.tkeep (tkeep_archA hy g) h + +/-- The spec's CopyRegisters with the restart bit of a thread other than the current one. -/ +theorem copyRegsRestart_specA {σ1 σr : State Unit} {t src : ObjRef} {yr : Tcb} {g : ArchTcb} {guest : Bool} + {flags : U64} + (hy : σr.kheap t = some (.tcb yr)) (hOther : t ≠ σr.curThread) + (hg : decide (yr.tcbArch.tcbVcpu ≠ none) = guest) + (hbits : (flags &&& 4#u64 != 0#u64) = testBit flags.bv 2 ∧ (flags &&& 8#u64 != 0#u64) = testBit flags.bv 3) + (hr : fl4TcbRestart (Z := Unit) t σ1 = ({((), σr)}, False)) + (hmem : ((), updKSc σr t (.tcb { yr with tcbArch := g })) ∈ ((do + NonDet.when (flags &&& 4#u64 != 0#u64) (do + NonDet.mapMx (tcbCopyRegisterA t src guest) frameRegisters + let pc ← asUser t getRestartPC + asUser t (setNextPC pc)) + NonDet.when (flags &&& 8#u64 != 0#u64) (NonDet.mapMx (tcbCopyRegisterA t src guest) gpRegisters)) σr).1) : + (.ok [], updKSc σr t (.tcb { yr with tcbArch := g })) ∈ + ((fl4InvokeTcb (.copyRegisters t src false true (testBit flags.bv 2) (testBit flags.bv 3) + ArchDefaultExtraRegisters)).run σ1).1 := by + rw [hbits.1, hbits.2] at hmem + refine tcbCopyRegisters_specA (σSuspend := σ1) (σRestart := σr) + (σTransfer := updKSc σr t (.tcb { yr with tcbArch := g })) (guest := guest) ?_ ?_ ?_ hmem ?_ + · unfold NonDet.when + rw [if_neg Bool.false_ne_true] + exact Set.mem_singleton _ + · unfold NonDet.when + rw [if_pos rfl] + show ((), σr) ∈ (fl4TcbRestart (Z := Unit) t σ1).1 + rw [hr] + exact Set.mem_singleton _ + · rw [tcbCopyRegisters_guestA hy, hg] + · unfold NonDet.when + have hn : ¬ t = (updKSc σr t (.tcb { yr with tcbArch := g })).curThread := hOther + rw [if_neg hn] + exact Set.mem_singleton _ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 4000000 in +/-- **The P1 facts after `sched.restart t`, from the record state before it** (module docstring). -/ +theorem JStage3A.restartMidA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + {t : U64} (ht : t ∈ H.tcbs) (hcap : ∃ x ∈ OS, capA st s x = .Thread t) : + sched.restart st ar s a t ⦃ out => + SysL st H Z.Cs OS ia ie out.1 ∧ SymL st H Z.Cs out.1 ∧ Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U out.1 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac out.1 ∧ + (∀ σ' m', J7A st (J7R2A st ar hPl.ipa) Z H OS out.1 σ' m') ∧ OSKeep st OS s out.1 ⦄ := by + have hb : BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s := by + obtain ⟨q, b, x, sg, sc⟩ := J.sys.ent.bxi + exact ⟨q, b, x, sc, sg⟩ + obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits, KLv, W⟩ := J7A.unp J.j7 + have I := J.delIn hA hPl W + refine WP.spec_mono (sched.restart.dm hA a t hb ht J.sys.sysl.ly.h0 J.sys.sysl.vr J.symL) ?_ + rintro ⟨s', a'⟩ hh + simp only [WP.uncurry'_pair] at hh ⊢ + obtain ⟨b', foot, dm⟩ := hh + have w : WritesIn st s s' (SusW st H Z.Cs Z.V s) := + (SspW.ofD (K8.Foot.d foot)).mono fun _ hb => Or.inl hb + have hp : ∀ k, H t = some k → ∃ x ∈ OS, NamesA (capA st s x) t k := by + intro k hk + have e : H t = some .tcb := ht + rw [e] at hk + cases hk + obtain ⟨x, hx, hc⟩ := hcap + exact ⟨x, hx, by rw [hc]; exact names_thread⟩ + obtain ⟨sysl, symL, userOK, bxi, j7⟩ := J.p1StepSusA hA hPl w (DM.toDMD dm) hp b' + obtain ⟨-, -, osk⟩ := armVsK_ofSusW0A I J.ko J.sys.ent.ksw J.core0 (BXI.blk J.sys.ent.bxi) w + exact ⟨sysl, symL, userOK, bxi, j7, osk⟩ + +set_option maxHeartbeats 8000000 in +set_option maxRecDepth 100000 in +/-- **TCB CopyRegisters with the restart bit at a syscall entry** (module docstring). -/ +theorem JSyscallA.copyRegsRestartA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) + (hmbF : ∀ a, Fl4MinBudgetAgreeA ar a) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + {slot lbl len buf t src srcSlot flags : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBCopyRegisters) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok srcSlot)) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (harg : srcSlot ∈ OS) (hsc : capA st s srcSlot = .Thread src) (hself : t ≠ L.curW s) + (hres1 : flags &&& 1#u64 = 0#u64) (hres2 : flags &&& 2#u64 ≠ 0#u64) + {sl : CslotPtr} (hsl : specCapAtA σ sl = some (.threadCap (specPtr t))) + {y : Tcb} (hy : σ.kheap (specPtr t) = some (.tcb y)) + (hstop : ¬ runnable y.tcbState = true ∧ ¬ idle y.tcbState) : + ∃ xc σ1 σ2 s2, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ2) ∈ ((fl4InvokeTcb (.copyRegisters (specPtr t) (specPtr src) false true + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, a) ∧ + ∃ Q Rl stack', JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack' κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m ∧ Sched.BodyEndA σ σ2 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J1, -, hosk, -⟩ := J.toJStage3A.of_restartCurA + RS.pl.choose_spec.choose_spec.choose_spec.choose_spec RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have htH : t ∈ H.tcbs := by rw [J.tcbs]; exact ht + have hsT : src ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy harg).1.2.2.2.2.2 src hsc + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have hstallS : smp.remote_tcb_stall st ar s a src = ok (s, a) := T0.stall_singleA hCs h1 hsT + have hni := T0.notIdle_of_capA J.sinv.mc.curCore_lt hsl + set s1 := L.wr s (stA (L.curW s)) sched.TS_RESTART with hs1 + set σ1 := stUpdA σ σ.curThread xc .restart with hσ1 + have hr : tcb.restart_caller st s = ok s1 := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + have hcur1 : σ1.curThread = specPtr (L.curW s1) := J1.j.1.sch.curThread + have hcur0 : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have eq1 : L.curW s1 = L.curW s := specPtr_inj (hcur1.symm.trans hcur0) + have hne1 : t ≠ L.curW s1 := by rw [eq1]; exact hself + have htc : specPtr t ≠ σ.curThread := fun e => hself (specPtr_inj (e.trans hcur0)) + have far : ∀ q, q ≠ σ.curThread → σ1.kheap q = σ.kheap q := fun q hq => by + rw [hσ1]; simp [stUpdA, setObjA, Function.update_of_ne hq] + have hy1 : σ1.kheap (specPtr t) = some (.tcb y) := (far _ htc).trans hy + have hcap1 : ∃ x ∈ OS, capA st s1 x = .Thread t := ⟨slot, hslot, by rw [hosk.capA hslot]; exact hcap⟩ + have hkc1 : σ1.kheap σ.curThread = some (.tcb { xc with tcbState := .restart }) := by + simp [hσ1, stUpdA, setObjA] + have sact1 : SActA σ1 := ⟨fun u h => J.sact.f1 u h, ⟨{ xc with tcbState := .restart }, hkc1, Or.inr (Or.inl rfl)⟩⟩ + have R := J1.restartStopped_stepA sact1 (fun u h => J.noSwitch u h) hA hCs h1 hmb hmbF hmax htu ht hy1 hstop + htc hni.1 hni.2 ⟨{ xc with tcbState := .restart }, hkc1, + by obtain ⟨t0, ht0, hs0, -⟩ := J.toJStage3EntryA.curInv.tcb; rw [hkc] at ht0; cases ht0; exact hs0⟩ + have M := J1.restartMidA hA hPl htH hcap1 + obtain ⟨⟨sr, a2⟩, hrs, ⟨ha, hcwr, σr, stk', Q, Rl, hspecR, hsw, KB, fin⟩, sysl, symL, userOK, bxi, j7, oskr⟩ := + Fl4ProofsA64.P1.W7.R.ST.ok_of_spec (WP.spec_and R M) + simp only at ha hcwr sysl symL userOK bxi j7 oskr + subst a2 + have J1r := fin sysl symL userOK (j7 _ _) + have hne_r : t ≠ L.curW sr := by rw [hcwr, eq1]; exact hself + obtain ⟨yr, hyr, -⟩ := J1r.mcp t ht + obtain ⟨xs, hxs, -⟩ := J1r.mcp src hsT + have hbound : vcpu.bound st sr t = ok (L.mem sr (tVcpuA t)) := eq_of_spec_fd (vcpu.bound.spec (L := L) sr t) + have hg : decide (yr.tcbArch.tcbVcpu ≠ none) = (L.mem sr (tVcpuA t) != 0#u64) := by + obtain ⟨z, hz, h, -⟩ := J1r.j.2.1.tcb t ht + rw [hyr] at hz + cases hz + have h' : yr.tcbArch.tcbVcpu = optRefA (L.mem sr (tVcpuA t)) := h + rw [h'] + unfold optRefA + by_cases e : L.mem sr (tVcpuA t) = 0#u64 <;> simp [e] + have hbits := tcbCopyRegisters_flagBitsA flags + have K := J1r.copyRegs_stepA (dest := t) (src := src) (p := L.mem sr (tVcpuA t)) (flags &&& 4#u64 != 0#u64) + (flags &&& 8#u64 != 0#u64) ht hsT hyr hxs hbound + obtain ⟨sG, hrun, σ', hmem, ⟨g, hv, hσ'⟩, w2, hcw2, blk2, KJ⟩ := spec_existsA K + subst hσ' + have hcsrc : obj.Slot.cap st srcSlot s = ok (.Thread src) := by rw [← hsc]; exact capA_eq s srcSlot + have hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), sG, a) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + tcbCopyRegisters_acceptedA hstall he hf hcsrc hstallS hr, tcbCopyRegisters_effectsA] + have hb1 : (flags &&& 1#u64 != 0#u64) = false := by simp [hres1] + have hb2 : (flags &&& 2#u64 != 0#u64) = true := by simp [hres2] + have hne2 : ¬ t = L.curW sG := fun e => hself (e.trans (hcw2.trans (hcwr.trans eq1))) + simp only [hb1, hb2, Bool.false_eq_true, ite_false, ite_true, bind_ok, uncurry_apply_pair, hrs] + rw [← Std.bind_assoc, hrun, bind_ok] + simp only [if_neg hne2] + obtain ⟨-, -, sysl2, symL2, -, userOK2, j72⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdec + (updKSc σr (specPtr t) (.tcb { yr with tcbArch := g })) m + have J2 := KJ sysl2 symL2 userOK2 j72 + have hcr : σr.curThread = specPtr (L.curW sr) := J1r.j.1.sch.curThread + have hspec := copyRegsRestart_specA (σ1 := σ1) (σr := σr) (t := specPtr t) (src := specPtr src) hyr + (fun e => hne_r (specPtr_inj (e.trans hcr))) (guest := (L.mem sr (tVcpuA t) != 0#u64)) hg + ⟨hbits.2.2.1, hbits.2.2.2⟩ hspecR hmem + -- the end of the body + have ne : σ.curSc ≠ σ.curThread := fun e => by + obtain ⟨y0, j, h0⟩ := J.curInv.sc + rw [e, hkc] at h0; cases h0 + have e1 : σ1.kheap σ.curSc = σ.kheap σ.curSc := by + simp [hσ1, stUpdA, setObjA, Function.update_of_ne ne] + have hm1 : ((), σr) ∈ (fl4TcbRestart (Z := Unit) (specPtr t) σ1).1 := by rw [hspecR]; exact Set.mem_singleton _ + have B := Sched.BodyEndA.ofRestartFromA (σW := σ1) J ⟨rfl, rfl, rfl, rfl, rfl, rfl, fun h => h⟩ hkc htc hkc1 e1 hy1 hstop hm1 KB + (updKSc σr (specPtr t) (.tcb { yr with tcbArch := g })).kheap + (fun q hq => by simp [updKSc, Function.update_of_ne hq]) + (swa_archA hyr g hsw) J2.sr.inv J2.sinv.zc + exact ⟨xc, σ1, _, sG, hkc, rfl, hsp, hspec, hdec, Q, Rl, stk', J2, B⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopySelfA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopySelfA.lean new file mode 100644 index 000000000..2e75caf27 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopySelfA.lean @@ -0,0 +1,210 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **TCB CopyRegisters into the caller itself (reschedule), at a syscall entry**. + +CopyRegisters of the current thread ends with `reschedule_required`, so the record is needed at the state after the register +loops (a mid state): its P1 facts come from the loops' Reply-walk run (`copyRegsRpA`, as `writeRegsRpA`), and +`reschedSelf_stepA` carries the record over the reschedule. + +* `JStage3A.copyRegsRpA`: the optional frame loop + `NextIP` copy and the optional GP loop as a Reply-walk run. +* `copyRegsSelf_specA` is inlined: the spec's transfer, then `rescheduleRequired` (the destination is the current thread). +* **`JSyscallA.copyRegsSelfA`**: `decode_invocation` on a Thread cap with the CopyRegisters label, `flags & 3 = 0`, the + destination the caller itself. + +Named premises: those of `copyRegsA` (without `hself`). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbRegCopyArmA +import Fl4ProofsA64.P3.Stage3TcbRegMidA +import Fl4ProofsA64.P3.Stage3TcbReschedA +import Fl4ProofsA64.P3.Stage3TcbBodyA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 +open Fl4Spec (NonDet) + +noncomputable section + +/-- The spec's CopyRegisters (no suspend, no restart) into the current thread: the transfer, then the reschedule. -/ +theorem copyRegsSelf_specA {σ1 σ3 : State Unit} {t src : ObjRef} {y : Tcb} {g : ArchTcb} {guest : Bool} {flags : U64} + (hy : σ1.kheap t = some (.tcb y)) (hcur : t = σ1.curThread) + (hg : decide (y.tcbArch.tcbVcpu ≠ none) = guest) + (hbits : (flags &&& 4#u64 != 0#u64) = testBit flags.bv 2 ∧ (flags &&& 8#u64 != 0#u64) = testBit flags.bv 3) + (hmem : ((), updKSc σ1 t (.tcb { y with tcbArch := g })) ∈ ((do + NonDet.when (flags &&& 4#u64 != 0#u64) (do + NonDet.mapMx (tcbCopyRegisterA t src guest) frameRegisters + let pc ← asUser t getRestartPC + asUser t (setNextPC pc)) + NonDet.when (flags &&& 8#u64 != 0#u64) (NonDet.mapMx (tcbCopyRegisterA t src guest) gpRegisters)) σ1).1) + (hres : rescheduleRequired (Z := Unit) (updKSc σ1 t (.tcb { y with tcbArch := g })) = ({((), σ3)}, False)) : + (.ok [], σ3) ∈ ((fl4InvokeTcb (.copyRegisters t src false false (testBit flags.bv 2) (testBit flags.bv 3) + ArchDefaultExtraRegisters)).run σ1).1 := by + rw [hbits.1, hbits.2] at hmem + refine tcbCopyRegisters_specA (σSuspend := σ1) (σRestart := σ1) + (σTransfer := updKSc σ1 t (.tcb { y with tcbArch := g })) (guest := guest) ?_ ?_ ?_ hmem ?_ + · unfold NonDet.when + rw [if_neg Bool.false_ne_true] + exact Set.mem_singleton _ + · unfold NonDet.when + rw [if_neg Bool.false_ne_true] + exact Set.mem_singleton _ + · rw [tcbCopyRegisters_guestA hy, hg] + · unfold NonDet.when + have hn : t = (updKSc σ1 t (.tcb { y with tcbArch := g })).curThread := hcur + rw [if_pos hn] + show ((), σ3) ∈ (rescheduleRequired (Z := Unit) _).1 + rw [hres] + exact Set.mem_singleton _ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 8000000 in +/-- **CopyRegisters' register block as a Reply-walk run** (module docstring). -/ +theorem JStage3A.copyRegsRpA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + {dest src : U64} (frame gp : Bool) (ht : dest ∈ H.tcbs) : + (do + let sFrame ← if frame then do + let s' ← tcb.copy_registers_loop0 st s dest src 0#u64 + let pc := L.mem s' (Endp.regA dest layout.reg.FAULT_IP) + ok (L.wr s' (Endp.regA dest layout.reg.NEXT_IP) pc) + else ok s + if gp then tcb.copy_registers_loop1 st sFrame dest src 0#u64 else ok sFrame) ⦃ s2 => + RpPost st H Z.Cs OS Z.V ia ie Ac s s2 ∧ ∀ z ∈ OS, capA st s2 z = capA st s z ⦄ := by + have hR := J.regClosureA hA hPl ht + refine WP.spec_bind (Pₘ := fun sF => XKoQ st H Z.Cs OS ia ie Ac ∅ s sF ∧ XV st H OS Z.V s sF) ?_ fun sF hF => ?_ + · by_cases hf : frame = true + · rw [if_pos hf] + refine WP.spec_bind (Pₘ := fun sF => XKoQ st H Z.Cs OS ia ie Ac ∅ s sF ∧ XV st H OS Z.V s sF) + (tcb.copy_registers_loop0.invA _ hR J.regStartA) fun s' hs' => ?_ + rw [← Endp.set_reg_eqA] + exact hR s' _ (L.mem s' (Endp.regA dest layout.reg.FAULT_IP)) hs' (by simp [layout.reg.NEXT_IP, layout.reg.ELR_EL1]) + · rw [if_neg hf] + exact (WP.spec_ok _).2 J.regStartA + · by_cases hg : gp = true + · rw [if_pos hg] + exact WP.spec_mono (tcb.copy_registers_loop1.invA _ hR hF) fun s2 hf => J.regEndA hf + · rw [if_neg hg] + exact (WP.spec_ok _).2 (J.regEndA hF) + +set_option maxHeartbeats 8000000 in +set_option maxRecDepth 100000 in +/-- **TCB CopyRegisters into the caller at a syscall entry** (module docstring). -/ +theorem JSyscallA.copyRegsSelfA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t src srcSlot flags : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBCopyRegisters) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok srcSlot)) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (harg : srcSlot ∈ OS) (hsc : capA st s srcSlot = .Thread src) (hself : t = L.curW s) + (hres1 : flags &&& 1#u64 = 0#u64) (hres2 : flags &&& 2#u64 = 0#u64) : + ∃ xc σ1 σ2 s2, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ2) ∈ ((fl4InvokeTcb (.copyRegisters (specPtr t) (specPtr src) false false + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, a) ∧ + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m ∧ Sched.BodyEndA σ σ2 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J1, -, hosk, -⟩ := J.toJStage3A.of_restartCurA + RS.pl.choose_spec.choose_spec.choose_spec.choose_spec RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have htH : t ∈ H.tcbs := by rw [J.tcbs]; exact ht + have hsT : src ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy harg).1.2.2.2.2.2 src hsc + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have hstallS : smp.remote_tcb_stall st ar s a src = ok (s, a) := T0.stall_singleA hCs h1 hsT + set s1 := L.wr s (stA (L.curW s)) sched.TS_RESTART with hs1 + set σ1 := stUpdA σ σ.curThread xc .restart with hσ1 + have hr : tcb.restart_caller st s = ok s1 := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + have hcur1 : σ1.curThread = specPtr (L.curW s1) := J1.j.1.sch.curThread + have hcur0 : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have eq1 : L.curW s1 = L.curW s := specPtr_inj (hcur1.symm.trans hcur0) + have hts1 : t = L.curW s1 := by rw [eq1]; exact hself + have hy1 : σ1.kheap (specPtr t) = some (.tcb { xc with tcbState := .restart }) := by + rw [hself, ← hcur0] + simp [hσ1, stUpdA, setObjA] + obtain ⟨xs, hxs, -⟩ := J1.mcp src hsT + have hbound : vcpu.bound st s1 t = ok (L.mem s1 (tVcpuA t)) := eq_of_spec_fd (vcpu.bound.spec (L := L) s1 t) + have hg : decide (({ xc with tcbState := .restart } : Tcb).tcbArch.tcbVcpu ≠ none) = + (L.mem s1 (tVcpuA t) != 0#u64) := by + obtain ⟨z, hz, h, -⟩ := J1.j.2.1.tcb t ht + rw [hy1] at hz + cases hz + have h' : ({ xc with tcbState := .restart } : Tcb).tcbArch.tcbVcpu = optRefA (L.mem s1 (tVcpuA t)) := h + rw [h'] + unfold optRefA + by_cases e : L.mem s1 (tVcpuA t) = 0#u64 <;> simp [e] + have hbits := tcbCopyRegisters_flagBitsA flags + have K := J1.copyRegs_stepA (dest := t) (src := src) (p := L.mem s1 (tVcpuA t)) (flags &&& 4#u64 != 0#u64) + (flags &&& 8#u64 != 0#u64) ht hsT hy1 hxs hbound + have Rpf := J1.copyRegsRpA hA hPl (dest := t) (src := src) (flags &&& 4#u64 != 0#u64) (flags &&& 8#u64 != 0#u64) htH + obtain ⟨sG, hrun, σ', hmem, ⟨g, hv, hσ'⟩, w2, hcw2, blk2, KJ⟩ := spec_existsA K + subst hσ' + rw [hrun, WP.spec_ok] at Rpf + obtain ⟨hRp, hcaps⟩ := Rpf + have hcap2 : ∃ x ∈ OS, capA st sG x = .Thread t := + ⟨slot, hslot, by rw [hcaps slot hslot, hosk.capA hslot]; exact hcap⟩ + obtain ⟨sysl2, symL2, userOK2, -, j72⟩ := J1.midFactsA hA hPl htH hRp hcap2 + have J2 := KJ sysl2 symL2 userOK2 (j72 _ _) + -- the reschedule at the mid state + have hkcm : (updKSc σ1 (specPtr t) (.tcb { ({ xc with tcbState := .restart } : Tcb) with tcbArch := g })).kheap + σ.curThread = some (.tcb { ({ xc with tcbState := .restart } : Tcb) with tcbArch := g }) := by + rw [hself, ← hcur0] + simp [updKSc, hσ1, stUpdA, setObjA] + have sact2 : SActA (updKSc σ1 (specPtr t) (.tcb { ({ xc with tcbState := .restart } : Tcb) with tcbArch := g })) := + ⟨fun u h => J.sact.f1 u h, ⟨_, hkcm, Or.inr (Or.inl rfl)⟩⟩ + obtain ⟨s3, σ3, hrs, hcw3, hresc, eσ3, W3, K3⟩ := J2.reschedSelf_stepA sact2 (fun u h => J.noSwitch u h) + have hcsrc : obj.Slot.cap st srcSlot s = ok (.Thread src) := by rw [← hsc]; exact capA_eq s srcSlot + have hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s3, a) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + tcbCopyRegisters_acceptedA hstall he hf hcsrc hstallS hr, tcbCopyRegisters_effectsA] + have hb1 : (flags &&& 1#u64 != 0#u64) = false := by simp [hres1] + have hb2 : (flags &&& 2#u64 != 0#u64) = false := by simp [hres2] + have hdest : t = L.curW sG := hts1.trans hcw2.symm + simp only [hb1, hb2, Bool.false_eq_true, ite_false, bind_ok, uncurry_apply_pair] + rw [← Std.bind_assoc, hrun, bind_ok] + simp only [if_pos hdest, hrs, bind_ok] + obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdec σ3 m + have J3 := K3 sysl symL userOK j7 + -- the spec + have hbits' : (flags &&& 4#u64 != 0#u64) = testBit flags.bv 2 ∧ (flags &&& 8#u64 != 0#u64) = testBit flags.bv 3 := + ⟨hbits.2.2.1, hbits.2.2.2⟩ + have hspec := copyRegsSelf_specA (σ1 := σ1) (σ3 := σ3) (t := specPtr t) (src := specPtr src) hy1 + (by rw [hts1]; exact hcur1.symm) (guest := (L.mem s1 (tVcpuA t) != 0#u64)) hg hbits' hmem hresc + -- the end of the body + have ne : σ.curSc ≠ σ.curThread := fun e => by + obtain ⟨y0, j, h0⟩ := J.curInv.sc + rw [e, hkc] at h0; cases h0 + have hne2 : σ.curSc ≠ specPtr t := by rw [hself, ← hcur0]; exact ne + have e1 : σ3.kheap σ.curSc = σ1.kheap σ.curSc := by + rw [eσ3] + simp [updKSc, Function.update_of_ne hne2] + refine ⟨xc, σ1, σ3, s3, hkc, rfl, hsp, hspec, hdec, Z.Q, Z.R, J3, ?_⟩ + refine Sched.BodyEndA.ofRestartSw J hkc (swa_of_choose (by rw [eσ3])) (by rw [eσ3]; rfl) (by rw [eσ3]; rfl) + (by rw [eσ3]; rfl) (by rw [eσ3]; rfl) (by rw [eσ3]; rfl) (by rw [eσ3]; exact J.curInv.notRel) + (fun y' k h => ⟨y', by rw [← e1]; exact h, rfl, rfl, rfl⟩) (fun h => by rw [eσ3] at h; cases h) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopySuspA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopySuspA.lean new file mode 100644 index 000000000..9561b748e --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegCopySuspA.lean @@ -0,0 +1,192 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **TCB CopyRegisters with the suspend bit (`flags & 1`), at a syscall entry**. + +CopyRegisters first suspends the *source* thread (`sched.suspend src`), then restarts the destination (bit 1), then +transfers registers. The suspend prefix is `JSyscallA.suspendMidA` (tcbregr) on the source's Thread cap (the extra +capability slot): it returns the exact record at the state after the source's suspension, so the register transfer +(`copyRegs_stepA`) continues from it and only the final facts come from `decodeFinA`. + +* **`JSyscallA.copyRegsSuspA`**: `decode_invocation` on a Thread cap with the CopyRegisters label, `flags & 1 ≠ 0`, + `flags & 2 = 0`, a source other than the caller and a destination other than the caller. The body-end facts are + `BodyOKA.stepOwn` from the suspend prefix's, across the destination's architecture-only update. + +Named premises: those of `copyRegsA`, plus [P] `hmb/hmax/htu` (the suspend's budget contracts) and [S] `hcovS` +(the source slot is covered, as `hSC` for the extra capabilities). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbRegCopyRsA +import Fl4ProofsA64.P3.Stage3TcbSuspendArmA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 +open Fl4Spec (NonDet) + +noncomputable section + +/-- The spec's CopyRegisters with the suspend bit (no restart) of a destination other than the current thread. -/ +theorem copyRegsSusp_specA {σ1 σm : State Unit} {t src : ObjRef} {y : Tcb} {g : ArchTcb} {guest : Bool} {flags : U64} + (hsusp : ((), σm) ∈ (NonDet.when true (do fl4CancelRun (Z := Unit) src; Fl4SpecA64.suspend (Z := Unit) src) σ1).1) + (hy : σm.kheap t = some (.tcb y)) (hOther : t ≠ σm.curThread) + (hg : decide (y.tcbArch.tcbVcpu ≠ none) = guest) + (hbits : (flags &&& 4#u64 != 0#u64) = testBit flags.bv 2 ∧ (flags &&& 8#u64 != 0#u64) = testBit flags.bv 3) + (hmem : ((), updKSc σm t (.tcb { y with tcbArch := g })) ∈ ((do + NonDet.when (flags &&& 4#u64 != 0#u64) (do + NonDet.mapMx (tcbCopyRegisterA t src guest) frameRegisters + let pc ← asUser t getRestartPC + asUser t (setNextPC pc)) + NonDet.when (flags &&& 8#u64 != 0#u64) (NonDet.mapMx (tcbCopyRegisterA t src guest) gpRegisters)) σm).1) : + (.ok [], updKSc σm t (.tcb { y with tcbArch := g })) ∈ ((fl4InvokeTcb (.copyRegisters t src true false + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1 := by + rw [hbits.1, hbits.2] at hmem + refine tcbCopyRegisters_specA (σSuspend := σm) (σRestart := σm) + (σTransfer := updKSc σm t (.tcb { y with tcbArch := g })) (guest := guest) hsusp ?_ ?_ hmem ?_ + · unfold NonDet.when + rw [if_neg Bool.false_ne_true] + exact Set.mem_singleton _ + · rw [tcbCopyRegisters_guestA hy, hg] + · unfold NonDet.when + have hn : ¬ t = (updKSc σm t (.tcb { y with tcbArch := g })).curThread := hOther + rw [if_neg hn] + exact Set.mem_singleton _ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 8000000 in +set_option maxRecDepth 100000 in +/-- **TCB CopyRegisters with the suspend bit at a syscall entry** (module docstring). -/ +theorem JSyscallA.copyRegsSuspA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + {slot lbl len buf t src srcSlot flags : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBCopyRegisters) + (he : tcb.extra_with_length ⟨len, buf, call, slot, extra⟩ 0#usize 1#u64 = ok (.Ok srcSlot)) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (harg : srcSlot ∈ OS) (hcovS : SlotCov st OS s srcSlot) (hsc : capA st s srcSlot = .Thread src) + (hself : t ≠ L.curW s) (hsrcne : src ≠ L.curW s) + (hres1 : flags &&& 1#u64 ≠ 0#u64) (hres2 : flags &&& 2#u64 = 0#u64) : + ∃ xc σ1 σ2 s2, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ2) ∈ ((fl4InvokeTcb (.copyRegisters (specPtr t) (specPtr src) true false + (testBit flags.bv 2) (testBit flags.bv 3) ArchDefaultExtraRegisters)).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, a) ∧ + ∃ Q Rl stack', JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack' κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m ∧ Sched.BodyEndA σ σ2 m := by + obtain ⟨xc, σ1, σm, sm, am, hkc, e1, hsp, hspecM, -, ea, Q, Rl, stk', JM, BM, hsus, ⟨σx, hcx, hsx⟩, hcall⟩ := + J.suspendMidA hA hM hPl hfm hCs h1 hmb hmax htu (slot := srcSlot) (lbl := fl4_abi.label.TCBSuspend) (len := len) + (buf := buf) (blk := blk) (call := call) (don := don) (extra := extra) harg hcovS hsc hext hSC rfl + have ea' := ea.symm + subst ea' + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have hsT : src ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy harg).1.2.2.2.2.2 src hsc + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have hstallS : smp.remote_tcb_stall st ar s a src = ok (s, a) := T0.stall_singleA hCs h1 hsT + set s1 := L.wr s (stA (L.curW s)) sched.TS_RESTART with hs1 + have hr : tcb.restart_caller st s = ok s1 := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok] + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + obtain ⟨xc', hkc', hst', -⟩ := J.toJStage3A.of_restartCurA + RS.pl.choose_spec.choose_spec.choose_spec.choose_spec RS.sym RS.run J.toJStage3EntryA.curNotVmA RS.cur RS.vs RS.vc + exact hst' + have hsus' : sched.suspend st ar s1 a src = ok (sm, a) := hsus + have hcur0 : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have hcurM : L.curW sm = L.curW s := + specPtr_inj ((JM.j.1.sch.curThread).symm.trans (BM.2.trans hcur0)) + have hne_m : t ≠ L.curW sm := by rw [hcurM]; exact hself + obtain ⟨y, hy, -⟩ := JM.mcp t ht + obtain ⟨xs, hxs, -⟩ := JM.mcp src hsT + have hbound : vcpu.bound st sm t = ok (L.mem sm (tVcpuA t)) := eq_of_spec_fd (vcpu.bound.spec (L := L) sm t) + have hg : decide (y.tcbArch.tcbVcpu ≠ none) = (L.mem sm (tVcpuA t) != 0#u64) := by + obtain ⟨z, hz, h, -⟩ := JM.j.2.1.tcb t ht + rw [hy] at hz + cases hz + have h' : y.tcbArch.tcbVcpu = optRefA (L.mem sm (tVcpuA t)) := h + rw [h'] + unfold optRefA + by_cases e : L.mem sm (tVcpuA t) = 0#u64 <;> simp [e] + have hbits := tcbCopyRegisters_flagBitsA flags + have K := JM.copyRegs_stepA (dest := t) (src := src) (p := L.mem sm (tVcpuA t)) (flags &&& 4#u64 != 0#u64) + (flags &&& 8#u64 != 0#u64) ht hsT hy hxs hbound + obtain ⟨sG, hrun, σ', hmem, ⟨g, hv, hσ'⟩, w2, hcw2, blk2, KJ⟩ := spec_existsA K + subst hσ' + have hcsrc : obj.Slot.cap st srcSlot s = ok (.Thread src) := by rw [← hsc]; exact capA_eq s srcSlot + have hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), sG, a) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + tcbCopyRegisters_acceptedA hstall he hf hcsrc hstallS hr, tcbCopyRegisters_effectsA] + have hb1 : (flags &&& 1#u64 != 0#u64) = true := by simp [hres1] + have hb2 : (flags &&& 2#u64 != 0#u64) = false := by simp [hres2] + have hne2 : ¬ t = L.curW sG := fun e => hself (e.trans (hcw2.trans hcurM)) + simp only [hb1, hb2, Bool.false_eq_true, ite_false, ite_true, bind_ok, uncurry_apply_pair, hsus'] + rw [← Std.bind_assoc, hrun, bind_ok] + simp only [if_neg hne2] + obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, + DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdec + (updKSc σm (specPtr t) (.tcb { y with tcbArch := g })) m + have J2 := KJ sysl symL userOK j7 + -- the spec + have hsusp : ((), σm) ∈ (NonDet.when true (do fl4CancelRun (Z := Unit) (specPtr src); Fl4SpecA64.suspend (Z := Unit) (specPtr src)) σ1).1 := by + unfold NonDet.when + rw [if_pos rfl] + refine mem_bind_ndD (x := ((), σx)) (by rw [hcx]; exact Set.mem_singleton _) ?_ + show ((), σm) ∈ (Fl4SpecA64.suspend (Z := Unit) (specPtr src) σx).1 + rw [hsx] + exact Set.mem_singleton _ + have hbits' : (flags &&& 4#u64 != 0#u64) = testBit flags.bv 2 ∧ (flags &&& 8#u64 != 0#u64) = testBit flags.bv 3 := + ⟨hbits.2.2.1, hbits.2.2.2⟩ + have hcm : σm.curThread = specPtr (L.curW sm) := JM.j.1.sch.curThread + have hspec := copyRegsSusp_specA (σ1 := σ1) (σm := σm) (t := specPtr t) (src := specPtr src) hsusp hy + (fun e => hne_m (specPtr_inj (e.trans hcm))) (guest := (L.mem sm (tVcpuA t) != 0#u64)) hg hbits' hmem + -- the end of the body + have hcr : (updKSc σm (specPtr t) (.tcb { y with tcbArch := g })).kheap σm.curThread = + σm.kheap σm.curThread := by + simp only [updKSc, Function.update_of_ne (show σm.curThread ≠ specPtr t from fun e => + hne_m (specPtr_inj (e.symm.trans hcm)))] + have hB : BodyOKA (updKSc σm (specPtr t) (.tcb { y with tcbArch := g })) m := by + refine BM.1.stepOwn (swa_archA hy g BM.1.sw) rfl rfl rfl rfl rfl (fun y' k h => ?_) (fun y' k h act hni hpos o ho => ?_) + (fun hrs x hx => ?_) + · have hne : σm.curSc ≠ specPtr t := fun e => by + have h' : (updKSc σm (specPtr t) (.tcb { y with tcbArch := g })).kheap σm.curSc = _ := h + rw [e] at h' + simp [updKSc] at h' + refine ⟨y', ?_, rfl, rfl⟩ + have h' : (updKSc σm (specPtr t) (.tcb { y with tcbArch := g })).kheap σm.curSc = _ := h + simpa [updKSc, Function.update_of_ne hne] using h' + · have hne : σm.curSc ≠ specPtr t := fun e => by + have h' : (updKSc σm (specPtr t) (.tcb { y with tcbArch := g })).kheap σm.curSc = _ := h + rw [e] at h' + simp [updKSc] at h' + have h' : (updKSc σm (specPtr t) (.tcb { y with tcbArch := g })).kheap σm.curSc = _ := h + have h'' : σm.kheap σm.curSc = some (.schedContext y' k) := by + simpa [updKSc, Function.update_of_ne hne] using h' + exact BM.1.owner y' k h'' act hni hpos o ho + · have hsc' := (hcall hsrcne).tcb + have hx' : σm.kheap σm.curThread = some (.tcb x) := by rw [← hcr]; exact hx + rw [hcm, hcurM] at hx' + rw [hsc'] at hx' + cases hx' + exact Or.inr rfl + exact ⟨xc, σ1, _, sG, hkc, e1, hsp, hspec, hdec, Q, Rl, stk', J2, ⟨hB, BM.2⟩⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegInvA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegInvA.lean new file mode 100644 index 000000000..e9393f3b9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegInvA.lean @@ -0,0 +1,164 @@ +/- +P3 (AArch64, A64-P3 Stage 4, line tcbregw): **invariant-carrying versions of the WriteRegisters / CopyRegisters loops** +(generated from the P1 `rf` lemmas of `QueueDecTcb`: the footprint invariant becomes any `I` closed under `set_reg` of +the destination). Used with `I := XKoQ ∧ XV` for the mid-state P1 facts (`Stage3TcbRegMidA`). + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.TcbWriteBridgeA +import Fl4ProofsA64.P1.QueueDecTcb +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4ProofsA64.P1 + +noncomputable section + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + +theorem tcb.write_registers_loop0.invA {dest buf ct n i : U64} (I : S → Prop) + (hR : ∀ s1 r v, I s1 → r.val < 384 → obj.Tcb.set_reg st dest s1 r v ⦃ s2 => I s2 ⦄) (h : I s) : + tcb.write_registers_loop0 st s dest buf ct n i ⦃ s' => I s' ⦄ := 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 => I y.1) + · 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 (hR s1 r v5 h1 hr') fun s2 w2 => ?_ + step as ⟨j2, hj2⟩ + exact ⟨w2, by omega⟩ + · exact h + + +theorem tcb.write_registers_loop1.invA {dest buf ct n i : U64} (I : S → Prop) + (hR : ∀ s1 r v, I s1 → r.val < 384 → obj.Tcb.set_reg st dest s1 r v ⦃ s2 => I s2 ⦄) (h : I s) : + tcb.write_registers_loop1 st s dest buf ct n i ⦃ s' => I s' ⦄ := 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 => I y.1) + · 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 (hR s1 r v5 h1 hr') fun s2 w2 => ?_ + step as ⟨j2, hj2⟩ + exact ⟨w2, by omega⟩ + · exact h + + +theorem tcb.copy_registers_loop0.invA {dest src i : U64} (I : S → Prop) + (hR : ∀ s1 r v, I s1 → r.val < 384 → obj.Tcb.set_reg st dest s1 r v ⦃ s2 => I s2 ⦄) (h : I s) : + tcb.copy_registers_loop0 st s dest src i ⦃ s' => I 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 => I 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 r 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 (hR s1 r v5 h1 hr') fun s2 w2 => ?_ + step as ⟨j2, hj2⟩ + exact ⟨w2, by omega⟩ + · exact h + + +theorem tcb.copy_registers_loop1.invA {dest src i : U64} (I : S → Prop) + (hR : ∀ s1 r v, I s1 → r.val < 384 → obj.Tcb.set_reg st dest s1 r v ⦃ s2 => I s2 ⦄) (h : I s) : + tcb.copy_registers_loop1 st s dest src i ⦃ s' => I 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 => I 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] -- a64: A64 GP_REGISTERS + ) _ (List.getElem_mem _) + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st src s1 r 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 (hR s1 r v5 h1 hr') fun s2 w2 => ?_ + step as ⟨j2, hj2⟩ + exact ⟨w2, by omega⟩ + · exact h + + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegMidA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegMidA.lean new file mode 100644 index 000000000..724a0a125 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegMidA.lean @@ -0,0 +1,137 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **the P1 facts at the mid state of a register-writing invocation**. + +WriteRegisters / CopyRegisters with a restart or a reschedule continue after their register writes, so the record at the mid +state needs `SysL/SymL/UserOK/BXI/J7A` there (`decodeFinA` only gives them at the final decode state). The register writes +are A64 P1's Reply-walk steps (`XJX.regT`); this module turns their `RpPost` into the five facts exactly as `epiP1A` does for +the epilogue, with the `DMD` step the identity (no state write). + +* **`JStage3A.midFactsA`**. + +Named premises: [P] `ArchTotal`, `ArchPlat`. New module. +-/ +import Fl4ProofsA64.P3.Stage3P1StepA +import Fl4ProofsA64.P1.S1aCReplyTo +import Fl4ProofsA64.P1.S1aCBudget +import Fl4ProofsA64.P3.Stage3TcbRegInvA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.OuterEntry Fl4Spec Fl4SpecA64 + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {s s2 : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 8000000 in +/-- **`SysL/SymL/UserOK/BXI/J7A` after a run of register writes** (module docstring). -/ +theorem JStage3A.midFactsA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + {t : U64} (ht : t ∈ H.tcbs) (P2 : RpPost st H Z.Cs OS Z.V ia ie Ac s s2) + (hcap2 : ∃ x ∈ OS, capA st s2 x = .Thread t) : + SysL st H Z.Cs OS ia ie s2 ∧ SymL st H Z.Cs s2 ∧ Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s2 ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s2 ∧ + ∀ σ' m', J7A st (J7R2A st ar hPl.ipa) Z H OS s2 σ' m' := by + obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits, KLv, W⟩ := J7A.unp J.j7 + have I := J.delIn hA hPl W + have hH := I.del.heap + have hO := I.del.os + have hc0 := J.core0 + have P2' := P2 + obtain ⟨B2, Y2, h2, -, xv2, -⟩ := P2' + have bx2 : BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s2 := by + obtain ⟨q, b, x, sc, sg⟩ := h2 + exact ⟨q, b, x, sg, sc⟩ + have d : DMD st H Z.Cs t s2 s2 := DMD.refl t h2 B2.ly.h0 Y2 B2.vr + have hp : ∀ k, H t = some k → ¬ (ia ≤ t.val ∧ t.val < ie) → ∃ x ∈ OS, NamesA (capA st s2 x) t k := by + intro k hk hia + have e : H t = some .tcb := ht + rw [e] at hk + cases hk + obtain ⟨x, hx, hc⟩ := hcap2 + exact ⟨x, hx, by rw [hc]; exact names_thread⟩ + have hvr' := I.del.vr + obtain ⟨P3, k3⟩ := P2.dmdK hH hO I.del.sca hc0 hvr' J.ko hp d h2 + have d3 := (fun q => ⟨q.1, q.2, P3.2.2.2.2.1.1, P3.2.2.2.2.2⟩ : + ArmQIAt st H Z.Cs OS Z.V ia ie s s2 ∧ TabKeepOrZero st s s2 → + ArmQIAt st H Z.Cs OS Z.V ia ie s s2 ∧ TabKeepOrZero st s s2 ∧ ArmVsK st H OS Z.V s s2 ∧ + XferSlots2 st H OS Z.V s s2) + (ArmQIAt.ofXC (Vc := Z.V) ⟨P3.1, P3.2.1⟩ ⟨Ac, P3.2.2.1⟩ P3.2.2.2.1 P3.2.2.2.2.1.1.toVs) + have Fx := S1aStepFix.ofXfer2 (n := hPl.ipa) d3 I.del.vr I.fu I.vcc W.col W.df W.r2 W.sep W.hiK + have hk : L.ksb s2 = L.ksb s := P3.2.2.2.2.1.1.1 + have hPN : PoolNamed st OS s2 := d3.1.2.2.2.2.2.1 W.pn + have hsp : ∀ p, SchedPageA st Z OS s2 p → p ∈ Pt := by + have Fx' := Fx + obtain ⟨_, -, -, -, ⟨_, _, _, _, _, _, _, R'⟩, -⟩ := Fx' + exact schedPage_ptA R' W.sp + refine ⟨P3.1, P3.2.1, J.sys.ent.user.ksb hk, bx2, fun σ' m' => ?_⟩ + exact J7A.of_stepFixedA Fx W.vr hk W.al W.vu hPN hsp (fun b hb o ho => by rw [hk]; exact W.ks b hb o ho) + (J7R2K.of_stepFixedA (σ' := σ') (m := m') Fx W.ktK) + + +set_option maxHeartbeats 8000000 in +/-- **The register-write invariant's closure under `set_reg` of one thread** (as `epiP1A`'s `hR`). -/ +theorem JStage3A.regClosureA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + {t : U64} (ht : t ∈ H.tcbs) : + ∀ s1 r v, (XKoQ st H Z.Cs OS ia ie Ac ∅ s s1 ∧ XV st H OS Z.V s s1) → r.val < 384 → + obj.Tcb.set_reg st t s1 r v ⦃ s3 => XKoQ st H Z.Cs OS ia ie Ac ∅ s s3 ∧ XV st H OS Z.V s s3 ⦄ := by + obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits, KLv, W⟩ := J7A.unp J.j7 + have I := J.delIn hA hPl W + have hH := I.del.heap + have hO := I.del.os + have hc0 := J.core0 + intro s1 r v ⟨h1, x1⟩ hr' + have hvr1 : VrOK H.omega H.frame H.scs H.scBits OS Z.V Ub (L.ksb s1) Pt := by + rw [h1.2.1]; exact I.del.vr + exact WP.spec_mono (XJX.regT (Vc := Z.V) hH hO hc0 h1.1.1 hvr1 ht hr') + fun _ ⟨h3, k3, t3, a3⟩ => ⟨⟨⟨h3, OSKeep.trans' h1.1.2 k3⟩, h1.2.trans t3⟩, x1.trans (XV.keep a3 k3)⟩ + +/-- The invariant at the start. -/ +theorem JStage3A.regStartA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) : + XKoQ st H Z.Cs OS ia ie Ac ∅ s s ∧ XV st H OS Z.V s s := by + have h : BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s := by + obtain ⟨q, b, x, sg, sc⟩ := J.sys.ent.bxi + exact ⟨q, b, x, sc, sg⟩ + exact ⟨⟨⟨XJX.start J.sys.sysl J.symL h, OSKeep.rfl' _⟩, TabKeep.refl s⟩, XV.refl s⟩ + +/-- The closing of a run of register writes into the Reply-walk post. -/ +theorem JStage3A.regEndA {s2 : S} + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (hf : XKoQ st H Z.Cs OS ia ie Ac ∅ s s2 ∧ XV st H OS Z.V s s2) : + RpPost st H Z.Cs OS Z.V ia ie Ac s s2 ∧ ∀ z ∈ OS, capA st s2 z = capA st s z := by + obtain ⟨⟨⟨Jx, k⟩, tk⟩, x⟩ := hf + exact ⟨RpW.post ⟨Jx.sys, Jx.sym, Jx.blk, XC.keep k tk, x, (XferSlots.refl s).keep fun z hz => k.capA hz⟩, + fun z hz => k.capA hz⟩ + +set_option maxHeartbeats 8000000 in +/-- **WriteRegisters' register block as a Reply-walk run** (module docstring). -/ +theorem JStage3A.writeRegsRpA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + {dest buf count caller : U64} (ht : dest ∈ H.tcbs) : + (do + let sGp ← (do + let sFrame ← tcb.write_registers_loop0 st s dest buf caller count 0#u64 + tcb.write_registers_loop1 st sFrame dest buf caller count 0#u64) + ok (L.wr sGp (Endp.regA dest layout.reg.NEXT_IP) (L.mem sGp (Endp.regA dest layout.reg.FAULT_IP)))) ⦃ s2 => + RpPost st H Z.Cs OS Z.V ia ie Ac s s2 ∧ ∀ z ∈ OS, capA st s2 z = capA st s z ⦄ := by + have hR := J.regClosureA hA hPl ht + refine WP.spec_bind (Pₘ := fun sGp => XKoQ st H Z.Cs OS ia ie Ac ∅ s sGp ∧ XV st H OS Z.V s sGp) ?_ fun sGp hG => ?_ + · exact WP.spec_bind (Pₘ := fun sF => XKoQ st H Z.Cs OS ia ie Ac ∅ s sF ∧ XV st H OS Z.V s sF) + (tcb.write_registers_loop0.invA _ hR J.regStartA) + fun sF hF => tcb.write_registers_loop1.invA _ hR hF + · rw [← Endp.set_reg_eqA] + exact WP.spec_mono (hR sGp _ (L.mem sGp (Endp.regA dest layout.reg.FAULT_IP)) hG + (by simp [layout.reg.NEXT_IP, layout.reg.ELR_EL1])) fun s2 hf => J.regEndA hf + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegResumeA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegResumeA.lean new file mode 100644 index 000000000..d10921e25 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegResumeA.lean @@ -0,0 +1,214 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **TCB WriteRegisters with `resume`, at a syscall entry**. + +* `writeRegsResume_specA`: the spec's WriteRegisters with resume of a stopped thread other than the current one writes the + loops' register prefix and `NextIP`, then `fl4TcbRestart`s the target (no reschedule). +* **`JSyscallA.writeRegsResumeA`**: `decode_invocation` on a Thread cap with the WriteRegisters label, `flags & 1 ≠ 0`, + a stopped target other than the caller. The record is carried over the register block by `writeRegs_stepA`; its + `SysL/SymL/UserOK/J7A` at the mid state come from `midFactsA` (the register writes' Reply-walk run), which lets + `restartStopped_stepA` run at the mid state; the final facts come from `decodeFinA` at the end (the tail test + `dest = cur_thread` is decided by `restartStopped_stepA`'s `curW` frame). + +Named premises: those of `writeRegsA`, plus [P] `hmb/hmbF/hmax/htu` (the min-budget and tick conversion contracts, as +`resumeStoppedA`), [S] `hsl` (the target's cap is a Thread cap at a spec slot, so it is not an idle thread), [S] `hstop` +(the target is stopped). New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbRegWriteArmA +import Fl4ProofsA64.P3.Stage3TcbRegMidA +import Fl4ProofsA64.P3.Stage3TcbResumeRqA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 + +noncomputable section + +/-- The spec's WriteRegisters with resume of a thread other than the current one, from the restart's outcome. -/ +theorem writeRegsResume_specA {σ σ3 : State Unit} {t : ObjRef} {y : Tcb} (hk : σ.kheap t = some (.tcb y)) + (hOther : t ≠ σ.curThread) {g : Bool} (hg : decide (y.tcbArch.tcbVcpu ≠ none) = g) (args : Nat → Word) + (c c' : Nat) (h1 : min 17 c' = min 17 c) (h2 : min 19 (c' - 17) = min 19 (c - 17)) + (hr : fl4TcbRestart (Z := Unit) t (updKSc σ t (.tcb (writeRegsTcbA g args y c'))) = ({((), σ3)}, False)) : + (.ok [], σ3) ∈ + ((fl4InvokeTcb (Z := Unit) (.writeRegisters t true ((List.range c).map fun i => args (i + 2)) + ArchDefaultExtraRegisters)).run σ).1 := by + have hW := tcbWriteRegisters_userA hk g ((List.range c).map fun i => args (i + 2)) + set X := updKSc σ t (.tcb (writeRegsTcbA g args y c')) with hX + refine tcbWriteRegisters_specOutcomeA (σIp := X) (σRestart := σ3) (σFinal := σ3) hk hg + (by rw [hX, writeRegsTcbA_eq g args y c c' h1 h2]; exact hW) ?_ ?_ + · unfold Fl4Spec.NonDet.when + rw [if_pos rfl] + show ((), σ3) ∈ (fl4TcbRestart (Z := Unit) t X).1 + rw [hr] + exact Set.mem_singleton _ + · unfold Fl4Spec.NonDet.when + rw [if_neg hOther] + exact Set.mem_singleton _ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 8000000 in +set_option maxRecDepth 4000 in +/-- **TCB WriteRegisters with resume at a syscall entry** (module docstring). -/ +theorem JSyscallA.writeRegsResumeA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) + (hmbF : ∀ a, Fl4MinBudgetAgreeA ar a) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + {slot lbl len buf t flags count tl : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBWriteRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok count) + (htail : len - 2#u64 = ok tl) (henough : ¬ tl < count) (hself : t ≠ L.curW s) + (hres : flags &&& 1#u64 ≠ 0#u64) {sbo : Option ObjRef} + (hBN : sbo = none → buf = 0#u64) + (hBS : ∀ sb, sbo = some sb → (buf, sb) ∈ Bf ∧ buf ≠ 0#u64) + {sl : CslotPtr} (hsl : specCapAtA σ sl = some (.threadCap (specPtr t))) + {y : Tcb} (hy : σ.kheap (specPtr t) = some (.tcb y)) + (hstop : ¬ runnable y.tcbState = true ∧ ¬ idle y.tcbState) : + ∃ xc σ1 σ3 s3, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ3) ∈ ((fl4InvokeTcb (.writeRegisters (specPtr t) true + ((List.range count.val).map fun i => + specArgA xc.tcbArch.tcbContext.userRegs sbo σ.machineState.underlyingMemory (i + 2)) + ArchDefaultExtraRegisters)).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s3, a) ∧ + ∃ Q Rl stack', JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack' κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 m ∧ Sched.BodyEndA σ σ3 m := by + have hBuf := bufMatchA hBN hBS + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J1, -, hosk, -⟩ := J.toJStage3A.of_restartCurA + RS.pl.choose_spec.choose_spec.choose_spec.choose_spec RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have htH : t ∈ H.tcbs := by rw [J.tcbs]; exact ht + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + have hni := T0.notIdle_of_capA J.sinv.mc.curCore_lt hsl + set s1 := L.wr s (stA (L.curW s)) sched.TS_RESTART with hs1 + set σ1 := stUpdA σ σ.curThread xc .restart with hσ1 + have hr : tcb.restart_caller st s = ok s1 := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + have hcur1 : σ1.curThread = specPtr (L.curW s1) := J1.j.1.sch.curThread + have hcur0 : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have eq1 : L.curW s1 = L.curW s := specPtr_inj (hcur1.symm.trans hcur0) + have hne1 : t ≠ L.curW s1 := by rw [eq1]; exact hself + have htc : specPtr t ≠ σ.curThread := fun e => hself (specPtr_inj (e.trans hcur0)) + have far : ∀ q, q ≠ σ.curThread → σ1.kheap q = σ.kheap q := fun q hq => by + rw [hσ1]; simp [stUpdA, setObjA, Function.update_of_ne hq] + have hy1 : σ1.kheap (specPtr t) = some (.tcb y) := (far _ htc).trans hy + have hsrc : σ1.kheap (specPtr (L.curW s1)) = some (.tcb { xc with tcbState := .restart }) := by + rw [← hcur1] + simp [hσ1, stUpdA, setObjA] + have hbound : vcpu.bound st s1 t = ok (L.mem s1 (tVcpuA t)) := eq_of_spec_fd (vcpu.bound.spec (L := L) s1 t) + have hg : decide (y.tcbArch.tcbVcpu ≠ none) = (L.mem s1 (tVcpuA t) != 0#u64) := by + obtain ⟨z, hz, h, -⟩ := J1.j.2.1.tcb t ht + rw [hy1] at hz + cases hz + have h' : y.tcbArch.tcbVcpu = optRefA (L.mem s1 (tVcpuA t)) := h + rw [h'] + unfold optRefA + by_cases e : L.mem s1 (tVcpuA t) = 0#u64 <;> simp [e] + -- the loops + have hT : TcbPlaced Z.T := J1.iplaced.e.tcb + set c' : U64 := if 36#u64 < count then 36#u64 else count with hc' + have hcv : c'.val = min 36 count.val := by + by_cases h : 36#u64 < count + · have h' : (36#u64 : U64).val < count.val := h + have e36 : (36#u64 : U64).val = 36 := by simp + rw [hc', if_pos h] + omega + · have h' : ¬ (36#u64 : U64).val < count.val := h + have e36 : (36#u64 : U64).val = 36 := by simp + rw [hc', if_neg h] + omega + obtain ⟨sFrame, hF, -⟩ := spec_existsA (tcb.write_registers_loop0.plainA (st := st) (T := Z.T) (s0 := s1) (s := s1) + (dest := t) (buf := buf) (ct := L.curW s1) (n := c') (i := 0#u64) hT ht (WritesIn.refl _ _)) + obtain ⟨sGp, hG, -⟩ := spec_existsA (tcb.write_registers_loop1.plainA (st := st) (T := Z.T) (s0 := sFrame) + (s := sFrame) (dest := t) (buf := buf) (ct := L.curW s1) (n := c') (i := 0#u64) hT ht (WritesIn.refl _ _)) + have K := J1.writeRegs_stepA (dest := t) (buf := buf) (count := c') (p := L.mem s1 (tVcpuA t)) (sbo := sbo) ht hne1 + hy1 hsrc hBuf hbound + have Rpf := J1.writeRegsRpA hA hPl (dest := t) (buf := buf) (count := c') (caller := L.curW s1) htH + rw [hF, bind_ok, hG, bind_ok, WP.spec_ok] at K Rpf + set s2 := L.wr sGp (Endp.regA t layout.reg.NEXT_IP) (L.mem sGp (Endp.regA t layout.reg.FAULT_IP)) with hs2 + obtain ⟨w2, hcw2, blk2, KJ⟩ := K + obtain ⟨hRp, hcaps⟩ := Rpf + have hcap2 : ∃ x ∈ OS, capA st s2 x = .Thread t := + ⟨slot, hslot, by rw [hcaps slot hslot, hosk.capA hslot]; exact hcap⟩ + obtain ⟨sysl2, symL2, userOK2, -, j72⟩ := J1.midFactsA hA hPl htH hRp hcap2 + set args := specArgA ({ xc with tcbState := .restart } : Tcb).tcbArch.tcbContext.userRegs sbo + σ1.machineState.underlyingMemory with hargs + set y' := writeRegsTcbA (L.mem s1 (tVcpuA t) != 0#u64) args y c'.val with hy' + have J2 := KJ sysl2 symL2 userOK2 (j72 _ _) + have hst' : y'.tcbState = y.tcbState := writeRegsTcbA_state _ _ _ _ + -- the restart at the mid state + have hkm : (updKSc σ1 (specPtr t) (.tcb y')).kheap (specPtr t) = some (.tcb y') := by simp [updKSc] + have hcm : ∀ q, q ≠ specPtr t → (updKSc σ1 (specPtr t) (.tcb y')).kheap q = σ1.kheap q := fun q hq => by + simp [updKSc, Function.update_of_ne hq] + have hkcm : (updKSc σ1 (specPtr t) (.tcb y')).kheap σ.curThread = some (.tcb { xc with tcbState := .restart }) := by + rw [hcm _ htc.symm] + simp [hσ1, stUpdA, setObjA] + have sact1 : SActA (updKSc σ1 (specPtr t) (.tcb y')) := + ⟨fun u h => J.sact.f1 u h, ⟨{ xc with tcbState := .restart }, hkcm, Or.inr (Or.inl rfl)⟩⟩ + have hsm : ¬ runnable y'.tcbState = true ∧ ¬ idle y'.tcbState := by rw [hst']; exact hstop + have R := J2.restartStopped_stepA sact1 (fun u h => J.noSwitch u h) hA hCs h1 hmb hmbF hmax htu ht hkm hsm + htc hni.1 hni.2 + ⟨{ xc with tcbState := .restart }, hkcm, + by obtain ⟨t0, ht0, hs0, -⟩ := J.toJStage3EntryA.curInv.tcb; rw [hkc] at ht0; cases ht0; exact hs0⟩ + obtain ⟨⟨s3, a3⟩, hrs, ha, hcw3, σ3, stk', Q, Rl, hspec3, hsw, KB, fin⟩ := Fl4ProofsA64.P1.W7.R.ST.ok_of_spec R + simp only at ha hcw3 + subst a3 + have hne3 : ¬ t = L.curW s3 := fun e => hself (e.trans (hcw3.trans (hcw2.trans eq1))) + have hwr := tcbWriteRegisters_afterLoopsA (ar := ar) (a := a) (s := s1) (sFrame := sFrame) (sGp := sGp) + (dest := t) (count := count) (buf := buf) true hF hG + have hrs' : sched.restart st ar (L.wr sGp (Endp.regA t layout.reg.NEXT_IP) + (L.mem sGp (Endp.regA t layout.reg.FAULT_IP))) a t = ok (s3, a) := hrs + have hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s3, a) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + tcbWriteRegisters_acceptedA hstall hlen hf hn htail henough hself hr] + have hres' : (flags &&& 1#u64 != 0#u64) = true := by simp [hres] + dsimp only + rw [hres', hwr] + simp only [ite_true, bind_ok, uncurry_apply_pair, hrs', if_neg hne3] + obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdec σ3 m + have J3 := fin sysl symL userOK j7 + have hcnt1 : min 17 c'.val = min 17 count.val := by rw [hcv]; omega + have hcnt2 : min 19 (c'.val - 17) = min 19 (count.val - 17) := by rw [hcv]; omega + have hspec := writeRegsResume_specA (σ := σ1) (t := specPtr t) hy1 + (by rw [hcur1]; exact fun e => hne1 (specPtr_inj e)) hg args count.val c'.val hcnt1 hcnt2 hspec3 + -- the end of the body + have ne : σ.curSc ≠ specPtr t := fun e => by + obtain ⟨y0, j, h0⟩ := J.curInv.sc + rw [e, hy] at h0; cases h0 + have e1 : (updKSc σ1 (specPtr t) (.tcb y')).kheap σ.curSc = σ.kheap σ.curSc := by + have ne2 : σ.curSc ≠ σ.curThread := fun e => by + obtain ⟨y0, j, h0⟩ := J.curInv.sc + rw [e, hkc] at h0; cases h0 + rw [hcm _ ne] + simp [hσ1, stUpdA, setObjA, Function.update_of_ne ne2] + have hm3 : ((), σ3) ∈ (fl4TcbRestart (Z := Unit) (specPtr t) (updKSc σ1 (specPtr t) (.tcb y'))).1 := by + rw [hspec3]; exact Set.mem_singleton _ + have B := Sched.BodyEndA.ofRestartFromA (σW := updKSc σ1 (specPtr t) (.tcb y')) J ⟨rfl, rfl, rfl, rfl, rfl, rfl, fun h => h⟩ hkc htc hkcm e1 hkm hsm hm3 KB σ3.kheap (fun _ _ => rfl) hsw J3.sr.inv J3.sinv.zc + exact ⟨xc, σ1, σ3, s3, hkc, rfl, hsp, hspec, hdec, Q, Rl, stk', J3, B⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegWriteA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegWriteA.lean new file mode 100644 index 000000000..6f5287839 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegWriteA.lean @@ -0,0 +1,113 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **TCB WriteRegisters at the record: the register writes**. + +* **`JStage3A.writeRegs_stepA`**: both `write_registers` loops and the `FaultIP -> NextIP` copy, on a thread `dest` + other than the current one, keep the record: the abstract state is the destination TCB with the exact register prefix + (`tcbWritePrefixA`) and `NextIP` written. The writes are `PlainRegW` words (register range of a TCB in `Z.T`). + +Named premises: [S] `hBuf` (the caller's argument buffer word is 0 or tracked in `Bf` with its spec buffer; same kind as +`readFpuA`'s `hbuf`), [J] `hVcpu` (the concrete bound-VCPU link, read at the entry state). New module. +-/ +import Fl4ProofsA64.P3.TcbWriteBridgeA +import Fl4ProofsA64.P3.Stage3TcbRegWriteFrA +import Fl4ProofsA64.P3.TcbWriteViewA +import Fl4ProofsA64.P3.Stage3TcbWordsA +import Fl4ProofsA64.P3.Stage3TcbBodyA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 4000000 in +/-- **WriteRegisters' register writes at the record** (module docstring). -/ +theorem JStage3A.writeRegs_stepA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {dest buf count p : U64} {sbo : Option ObjRef} (ht : dest ∈ Z.T) (hne : dest ≠ L.curW s) + {y src : Tcb} (hy : σ.kheap (specPtr dest) = some (.tcb y)) + (hsrc : σ.kheap (specPtr (L.curW s)) = some (.tcb src)) + (hBuf : match sbo with | none => buf = 0#u64 | some sb => (buf, sb) ∈ Bf ∧ buf ≠ 0#u64) + (hVcpu : vcpu.bound st s dest = ok p) : + let args := specArgA src.tcbArch.tcbContext.userRegs sbo σ.machineState.underlyingMemory + let y' := writeRegsTcbA (p != 0#u64) args y count.val + (do + let sGp ← (do + let sFrame ← tcb.write_registers_loop0 st s dest buf (L.curW s) count 0#u64 + tcb.write_registers_loop1 st sFrame dest buf (L.curW s) count 0#u64) + ok (L.wr sGp (Endp.regA dest layout.reg.NEXT_IP) (L.mem sGp (Endp.regA dest layout.reg.FAULT_IP)))) ⦃ s' => + WritesIn st s s' (PlainRegW Z.T) ∧ L.curW s' = L.curW s ∧ + BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ∧ + (SysL st H Z.Cs OS ia ie s' → SymL st H Z.Cs s' → Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s' → + J7A st (J7R2A st ar nA) Z H OS s' (updKSc σ (specPtr dest) (.tcb y')) m → + JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) + s' a (updKSc σ (specPtr dest) (.tcb y')) m) ⦄ := by + intro args y' + have hP := J.iplaced + have hT : TcbPlaced Z.T := hP.e.tcb + have hc : L.curW s ∈ Z.T := J.sr.curT + have V0 : TcbIpcViewsA st Z m κ N E Rp Bf stack s σ := + ⟨⟨Z.Q, Z.R, J.sr⟩, J.ntfn, J.ep, J.reply, J.mcp, J.yieldRel⟩ + have hViews := tcbWriteRegisters_viewsLoopA hP J.ipcPlace V0 (dest := dest) (caller := L.curW s) (buf := buf) + (p := p) (count := count) (sbo := sbo) ht hc (Ne.symm hne) hy hsrc hBuf hVcpu + have hPlain : (do + let sFrame ← tcb.write_registers_loop0 st s dest buf (L.curW s) count 0#u64 + tcb.write_registers_loop1 st sFrame dest buf (L.curW s) count 0#u64) ⦃ sGp => + WritesIn st s sGp (PlainRegW Z.T) ⦄ := + WP.spec_bind (tcb.write_registers_loop0.plainA hT ht (WritesIn.refl _ _)) fun s1 w1 => + tcb.write_registers_loop1.plainA hT ht w1 + refine WP.spec_bind (WP.spec_and hViews hPlain) ?_ + rintro sGp ⟨V1, w1⟩ + set gp := tcbWritePrefixA (p != 0#u64) gpRegisters 19 args (tcbWritePrefixA (p != 0#u64) frameRegisters 2 args y + (min frameRegisters.length count.val)) (min gpRegisters.length (count.val - 17)) with hgp + have hk1 : (Notif.updK σ (specPtr dest) (.tcb gp)).kheap (specPtr dest) = some (.tcb gp) := by + simp [Notif.updK] + have hreg := (V1.ep.at_tcb ht hk1).regs .faultIP + have hta : TcbAddr dest := hP.e.tcb dest ht + have eN : layout.reg.NEXT_IP = regIdxA .nextIP := by + unfold layout.reg.NEXT_IP layout.reg.ELR_EL1 + rfl + have eF : layout.reg.FAULT_IP = regIdxA .faultIP := by + unfold layout.reg.FAULT_IP + rfl + rw [eN, eF, WP.spec_ok] + set v : U64 := L.mem sGp (Endp.regA dest (regIdxA .faultIP)) with hv + have V2 := tcbRegWrite_viewsA hP J.ipcPlace V1 ht hk1 .nextIP v + have hlt : (regIdxA .nextIP).val < 37 := regIdxA_lt _ + have al : Aligned (Endp.regA dest (regIdxA .nextIP)) := (Endp.regA_tf hta hlt).1 + have vb : (Endp.regA dest (regIdxA .nextIP)).val = dest.val + 256 + 8 * (regIdxA .nextIP).val := + Endp.regA_val hta hlt + have wN : WritesIn st sGp (L.wr sGp (Endp.regA dest (regIdxA .nextIP)) v) (PlainRegW Z.T) := + (writesIn_wr al).mono fun b hb => ⟨dest, ht, by rw [hb, vb]; omega, by rw [hb, vb]; omega⟩ + have w := (w1.trans wN).mono fun b hb => hb.elim id id + have w' : WritesIn st s (L.wr sGp (Endp.regA dest (regIdxA .nextIP)) v) (XferFoot H.tcbs ∅) := by + rw [J.tcbs]; exact WritesIn.plain_xferA hT w + have hblk := blk_rf (BXI.blk J.sys.ent.bxi) w' + have blk' := hblk.1 + refine ⟨w, hblk.2.2.1, blk', fun sysl symL userOK j7 => ?_⟩ + have hy' : ({ y with tcbArch := y'.tcbArch } : Tcb) = y' := (writeRegsTcbA_arch _ _ _ _).symm + have ey' : Notif.setReg gp .nextIP v.bv = y' := by + show Notif.setReg gp .nextIP v.bv = Notif.setReg gp .nextIP (gp.tcbArch.tcbContext.userRegs .faultIP) + rw [hreg] + have eY : Notif.updK (Notif.updK σ (specPtr dest) (.tcb gp)) (specPtr dest) (.tcb (Notif.setReg gp .nextIP v.bv)) = + updKSc σ (specPtr dest) (.tcb y') := by + rw [ey'] + unfold Notif.updK updKSc + simp only [Function.update_idem] + have R := J.of_plainTcbA ht hy y'.tcbArch (by rw [← writeRegsTcbA_vcpu (p != 0#u64) args y count.val]) w blk' sysl symL + userOK (by rw [hy']; exact j7) (by rw [hy', ← eY]; exact V2.ep) (by rw [hy', ← eY]; exact V2.ntfn) + rw [hy'] at R + exact R + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegWriteArmA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegWriteArmA.lean new file mode 100644 index 000000000..7b302135e --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegWriteArmA.lean @@ -0,0 +1,173 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregw): **TCB WriteRegisters without resume, at a syscall entry**. + +* `writeRegsNoResume_specA`: the spec's WriteRegisters (no resume) of a thread other than the current one writes the + loops' exact register prefix and `NextIP`. +* **`JSyscallA.writeRegsA`**: `decode_invocation` on a Thread cap with the WriteRegisters label, `flags & 1 = 0`, a + target other than the caller, and the argument count within the message: the caller's `Restart`, both loops, the + `NextIP` copy. The spec `values` are the argument words `2 ..` read from the caller's registers and IPC buffer. + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `hCs`; [S] `h1` (`numNodes = 1`, the remote +stall); [S] `hBuf` (the caller's IPC buffer word is 0, or tracked in `Bf` with its spec buffer `sbo`). The decode +succeeds; the `Err` returns are not lifted. New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbRegWriteA +import Fl4ProofsA64.P3.Stage3TcbTlsA +import Fl4ProofsA64.P3.TcbWriteContA +import Fl4ProofsA64.P3.TcbInvokeRegOrderA +import Fl4ProofsA64.P3.EpFaultReplyA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 + +noncomputable section + +/-- The two-implication buffer premise as the `match` the loop lemmas take. -/ +theorem bufMatchA {Bf : Set (U64 × Word)} {buf : U64} {sbo : Option ObjRef} (hN : sbo = none → buf = 0#u64) + (hS : ∀ sb, sbo = some sb → (buf, sb) ∈ Bf ∧ buf ≠ 0#u64) : + match sbo with | none => buf = 0#u64 | some sb => (buf, sb) ∈ Bf ∧ buf ≠ 0#u64 := by + cases sbo with + | none => exact hN rfl + | some sb => exact hS sb rfl + +/-- The spec's WriteRegisters without resume, of a thread other than the current one. -/ +theorem writeRegsNoResume_specA {σ : State Unit} {t : ObjRef} {y : Tcb} (hk : σ.kheap t = some (.tcb y)) + (hOther : t ≠ σ.curThread) {g : Bool} (hg : decide (y.tcbArch.tcbVcpu ≠ none) = g) (args : Nat → Word) + (c c' : Nat) (h1 : min 17 c' = min 17 c) (h2 : min 19 (c' - 17) = min 19 (c - 17)) : + (.ok [], updKSc σ t (.tcb (writeRegsTcbA g args y c'))) ∈ + ((fl4InvokeTcb (Z := Unit) (.writeRegisters t false ((List.range c).map fun i => args (i + 2)) + ArchDefaultExtraRegisters)).run σ).1 := by + have hW := tcbWriteRegisters_userA hk g ((List.range c).map fun i => args (i + 2)) + set X := updKSc σ t (.tcb (writeRegsTcbA g args y c')) with hX + refine tcbWriteRegisters_specOutcomeA (σIp := X) (σRestart := X) (σFinal := X) hk hg + (by rw [hX, writeRegsTcbA_eq g args y c c' h1 h2]; exact hW) ?_ ?_ + · unfold Fl4Spec.NonDet.when + rw [if_neg Bool.false_ne_true] + exact Set.mem_singleton _ + · unfold Fl4Spec.NonDet.when + rw [if_neg hOther] + exact Set.mem_singleton _ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 4000000 in +/-- **TCB WriteRegisters without resume at a syscall entry** (module docstring). -/ +theorem JSyscallA.writeRegsA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t flags count tl : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBWriteRegisters) (hlen : ¬ len < 2#u64) + (hf : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok flags) + (hn : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok count) + (htail : len - 2#u64 = ok tl) (henough : ¬ tl < count) (hself : t ≠ L.curW s) + (hres : flags &&& 1#u64 = 0#u64) {sbo : Option ObjRef} + (hBN : sbo = none → buf = 0#u64) + (hBS : ∀ sb, sbo = some sb → (buf, sb) ∈ Bf ∧ buf ≠ 0#u64) : + ∃ xc σ1 σ2 s2, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ2) ∈ ((fl4InvokeTcb (.writeRegisters (specPtr t) false + ((List.range count.val).map fun i => + specArgA xc.tcbArch.tcbContext.userRegs sbo σ.machineState.underlyingMemory (i + 2)) + ArchDefaultExtraRegisters)).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, a) ∧ + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m ∧ Sched.BodyEndA σ σ2 m := by + have hBuf := bufMatchA hBN hBS + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J1, -, -, -⟩ := J.toJStage3A.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + set s1 := L.wr s (stA (L.curW s)) sched.TS_RESTART with hs1 + set σ1 := stUpdA σ σ.curThread xc .restart with hσ1 + have hr : tcb.restart_caller st s = ok s1 := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + have hcur1 : σ1.curThread = specPtr (L.curW s1) := J1.j.1.sch.curThread + have hcur0 : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread + have eq1 : L.curW s1 = L.curW s := specPtr_inj (hcur1.symm.trans hcur0) + have hne1 : t ≠ L.curW s1 := by rw [eq1]; exact hself + obtain ⟨y, hy, -⟩ := J1.mcp t ht + have hsrc : σ1.kheap (specPtr (L.curW s1)) = some (.tcb { xc with tcbState := .restart }) := by + rw [← hcur1] + simp [hσ1, stUpdA, setObjA] + -- the bound-VCPU link and the guest bit + have hbound : vcpu.bound st s1 t = ok (L.mem s1 (tVcpuA t)) := eq_of_spec_fd (vcpu.bound.spec (L := L) s1 t) + have hg : decide (y.tcbArch.tcbVcpu ≠ none) = (L.mem s1 (tVcpuA t) != 0#u64) := by + obtain ⟨z, hz, h, -⟩ := J1.j.2.1.tcb t ht + rw [hy] at hz + cases hz + have h' : y.tcbArch.tcbVcpu = optRefA (L.mem s1 (tVcpuA t)) := h + rw [h'] + unfold optRefA + by_cases e : L.mem s1 (tVcpuA t) = 0#u64 <;> simp [e] + -- the loops + have hT : TcbPlaced Z.T := J1.iplaced.e.tcb + set c' : U64 := if 36#u64 < count then 36#u64 else count with hc' + have hcv : c'.val = min 36 count.val := by + by_cases h : 36#u64 < count + · have h' : (36#u64 : U64).val < count.val := h + have e36 : (36#u64 : U64).val = 36 := by simp + rw [hc', if_pos h] + omega + · have h' : ¬ (36#u64 : U64).val < count.val := h + have e36 : (36#u64 : U64).val = 36 := by simp + rw [hc', if_neg h] + omega + obtain ⟨sFrame, hF, -⟩ := spec_existsA (tcb.write_registers_loop0.plainA (st := st) (T := Z.T) (s0 := s1) (s := s1) (dest := t) + (buf := buf) (ct := L.curW s1) (n := c') (i := 0#u64) hT ht (WritesIn.refl _ _)) + obtain ⟨sGp, hG, -⟩ := spec_existsA (tcb.write_registers_loop1.plainA (st := st) (T := Z.T) (s0 := sFrame) (s := sFrame) (dest := t) + (buf := buf) (ct := L.curW s1) (n := c') (i := 0#u64) hT ht (WritesIn.refl _ _)) + have K := J1.writeRegs_stepA (dest := t) (buf := buf) (count := c') (p := L.mem s1 (tVcpuA t)) (sbo := sbo) ht hne1 + hy hsrc hBuf hbound + rw [hF, bind_ok, hG, bind_ok, WP.spec_ok] at K + set s2 := L.wr sGp (Endp.regA t layout.reg.NEXT_IP) (L.mem sGp (Endp.regA t layout.reg.FAULT_IP)) with hs2 + obtain ⟨w2, hcw2, blk2, KJ⟩ := K + have hwr := tcbWriteRegisters_afterLoopsA (ar := ar) (a := a) (s := s1) (sFrame := sFrame) (sGp := sGp) + (dest := t) (count := count) (buf := buf) false hF hG + have hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, a) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + tcbWriteRegisters_acceptedA hstall hlen hf hn htail henough hself hr] + have hres' : (flags &&& 1#u64 != 0#u64) = false := by simp [hres] + dsimp only + rw [hres', hwr] + have hne2 : ¬ t = L.curW (L.wr sGp (Endp.regA t layout.reg.NEXT_IP) + (L.mem sGp (Endp.regA t layout.reg.FAULT_IP))) := fun e => hself (e.trans (hcw2.trans eq1)) + simp only [Bool.false_eq_true, ite_false, bind_ok, uncurry_apply_pair, if_neg hne2] + rfl + set args := specArgA ({ xc with tcbState := .restart } : Tcb).tcbArch.tcbContext.userRegs sbo + σ1.machineState.underlyingMemory with hargs + set y' := writeRegsTcbA (L.mem s1 (tVcpuA t) != 0#u64) args y c'.val with hy' + obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH, DecArmQZ2, DecArmKQ2, DecArmKQ, DecArmKQ3, DecArmDelQ, DecArmS1aC, capFam]) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdec + (updKSc σ1 (specPtr t) (.tcb y')) m + have J2 := KJ sysl symL userOK j7 + have hcnt1 : min 17 c'.val = min 17 count.val := by rw [hcv]; omega + have hcnt2 : min 19 (c'.val - 17) = min 19 (count.val - 17) := by rw [hcv]; omega + have hspec := writeRegsNoResume_specA (σ := σ1) (t := specPtr t) hy + (by rw [hcur1]; exact fun e => hne1 (specPtr_inj e)) hg args count.val c'.val hcnt1 hcnt2 + refine ⟨xc, σ1, _, s2, hkc, rfl, hsp, ?_, hdec, Z.Q, Z.R, J2, ?_⟩ + · exact hspec + · exact Sched.BodyEndA.ofTcbUpd J hkc (y := y) (y' := y') hy (writeRegsTcbA_state _ _ _ _) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbRegWriteFrA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbRegWriteFrA.lean new file mode 100644 index 000000000..f2f53ee26 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbRegWriteFrA.lean @@ -0,0 +1,188 @@ +/- +P3 (AArch64, A64-P3 Stage 4, line tcbregw): **the register-range write footprint of `write_registers`' loops**: +`set_reg`, both WriteRegisters loops and both CopyRegisters loops write only `PlainRegW T` words (the TCB words `[256, 3328)` of a thread in `T`). +Generated from the P1 `rf` lemmas of `QueueDecTcb` / `QueueReplyX` (`XferFoot` -> `PlainRegW`). + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.TcbWriteBridgeA +import Fl4ProofsA64.P3.Stage3TcbWordsA +import Fl4ProofsA64.P1.QueueDecTcb +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4ProofsA64.P1 + +noncomputable section + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {T : Set U64} + +theorem obj.Tcb.set_reg.plainA {s : S} {t r v : U64} (hT : TcbPlaced T) (ht : t ∈ T) (hr : r.val < 384) : + obj.Tcb.set_reg st t s r v ⦃ s' => WritesIn st s s' (PlainRegW T) ⦄ := + WP.spec_mono (obj.Tcb.set_reg.wrK s t r v (hT t ht) hr) fun s' ⟨K, hK, e⟩ => by + subst e + exact (writesIn_wr (field_aligned (hT t ht) (by omega) (by omega))).mono fun b e => by + refine ⟨t, ht, ?_, ?_⟩ <;> rw [e, field_val (hT t ht) (by omega)] <;> omega + +/-- Register-range writes are message-transfer writes (`XferFoot`): the aligned words of `PlainRegW`. -/ +theorem WritesIn.plain_xferA {s s' : S} (hT : TcbPlaced T) (w : WritesIn st s s' (PlainRegW T)) : + WritesIn st s s' (XferFoot T ∅) := + ⟨w.1, w.2.1, fun b hb hn => w.2.2 b hb fun hp => hn (by + obtain ⟨t, ht, h1, h2⟩ := hp + have hb' : b.val < 2 ^ 64 := by have := b.hBounds; simpa [U64.size_def, U64.numBits] using this + have hta := (hT t ht).align + have hk : (⟨BitVec.ofNat 64 (b.val - t.val)⟩ : U64).val = b.val - t.val := by + show (BitVec.ofNat 64 (b.val - t.val)).toNat = _ + simp only [BitVec.toNat_ofNat] + exact Nat.mod_eq_of_lt (by omega) + refine Or.inl ⟨t, ht, ⟨BitVec.ofNat 64 (b.val - t.val)⟩, by omega, by unfold Aligned at hb; omega, ?_⟩ + apply UScalar.eq_of_val_eq + rw [field_val (hT t ht) (by omega), hk] + omega)⟩ + +theorem tcb.write_registers_loop0.plainA {s0 s : S} {dest buf ct n i : U64} (hT : TcbPlaced T) (hd : dest ∈ T) + (h : WritesIn st s0 s (PlainRegW T)) : + tcb.write_registers_loop0 st s dest buf ct n i ⦃ s' => WritesIn st s0 s' (PlainRegW T) ⦄ := 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 => WritesIn st s0 y.1 (PlainRegW T)) + · 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.plainA (v := v5) (s := s1) hT hd hr') fun s2 w2 => ?_ + step as ⟨j2, hj2⟩ + exact ⟨(h1.trans w2).mono (fun _ hb => hb.elim id id), by omega⟩ + · exact h + + +theorem tcb.write_registers_loop1.plainA {s0 s : S} {dest buf ct n i : U64} (hT : TcbPlaced T) (hd : dest ∈ T) + (h : WritesIn st s0 s (PlainRegW T)) : + tcb.write_registers_loop1 st s dest buf ct n i ⦃ s' => WritesIn st s0 s' (PlainRegW T) ⦄ := 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 => WritesIn st s0 y.1 (PlainRegW T)) + · 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.plainA (v := v5) (s := s1) hT hd hr') fun s2 w2 => ?_ + step as ⟨j2, hj2⟩ + exact ⟨(h1.trans w2).mono (fun _ hb => hb.elim id id), by omega⟩ + · exact h + + +theorem tcb.copy_registers_loop0.plainA {s0 s : S} {dest src i : U64} (hT : TcbPlaced T) (hd : dest ∈ T) + (h : WritesIn st s0 s (PlainRegW T)) : + tcb.copy_registers_loop0 st s dest src i ⦃ s' => WritesIn st s0 s' (PlainRegW T) ⦄ := 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 => WritesIn st s0 y.1 (PlainRegW T)) + · 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 r 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.plainA (v := v5) (s := s1) hT hd hr') fun s2 w2 => ?_ + step as ⟨j2, hj2⟩ + exact ⟨(h1.trans w2).mono (fun _ hb => hb.elim id id), by omega⟩ + · exact h + + +theorem tcb.copy_registers_loop1.plainA {s0 s : S} {dest src i : U64} (hT : TcbPlaced T) (hd : dest ∈ T) + (h : WritesIn st s0 s (PlainRegW T)) : + tcb.copy_registers_loop1 st s dest src i ⦃ s' => WritesIn st s0 s' (PlainRegW T) ⦄ := 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 => WritesIn st s0 y.1 (PlainRegW T)) + · 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] -- a64: A64 GP_REGISTERS + ) _ (List.getElem_mem _) + refine WP.spec_bind (P0.obj.Tcb.reg.p0 st src s1 r 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.plainA (v := v5) (s := s1) hT hd hr') fun s2 w2 => ?_ + step as ⟨j2, hj2⟩ + exact ⟨(h1.trans w2).mono (fun _ hb => hb.elim id id), by omega⟩ + · exact h + + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbReschedA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbReschedA.lean index d9699556e..0e3a1a379 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbReschedA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbReschedA.lean @@ -31,6 +31,7 @@ theorem JStage3A.reschedSelf_stepA ∃ s' σ', sched.reschedule_required st s = ok s' ∧ L.curW s' = L.curW s ∧ rescheduleRequired (Z := Unit) σ = ({((), σ')}, False) ∧ σ' = { σ with schedulerAction := .chooseNewThread } ∧ + WritesIn st s s' (SWrA (st := st) Z s) ∧ (SysL st H Z.Cs OS ia ie s' → SymL st H Z.Cs s' → Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s' → J7A st (J7R2A st ar nA) Z H OS s' σ' m → JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s' a σ' m) := by @@ -69,7 +70,7 @@ theorem JStage3A.reschedSelf_stepA have e := SR.sch.curThread.symm.trans (show σ'.curThread = specPtr t from hcur) exact specPtr_inj e have hres : rescheduleRequired (Z := Unit) σ = ({((), σ')}, False) := rescheduleRequired_noswitchA nsw - refine ⟨s', σ', heq, hcurW, hres, rfl, fun sysl symL userOK j7 => ?_⟩ + refine ⟨s', σ', heq, hcurW, hres, rfl, W, fun sysl symL userOK j7 => ?_⟩ have hT : TcbPlaced Z.T := hP.e.tcb have tw : ∀ u ∈ Z.T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → L.mem s' (wa u K) = L.mem s (wa u K) := fun u hu K h1 h2 => by diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbResumeRqA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbResumeRqA.lean index cb00e47ee..189e22e02 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbResumeRqA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbResumeRqA.lean @@ -43,27 +43,24 @@ instance (p : ObjRef) : KPresBInst (fl4SchedContextResume (Z := Unit) p) := ⟨by unfold fl4SchedContextResume; kbres⟩ instance (t : ObjRef) : KPresBInst (testPossibleSwitchTo (Z := Unit) t) := ⟨by unfold testPossibleSwitchTo; kbres⟩ -/-- **`BodyEndA` after the caller's `Restart` and the Resume of a stopped thread** (dispatch restore): the budget +/-- **`BodyEndA` after a restart of a stopped thread from a state `σW` that agrees with the caller-`Restart` state on the caller's TCB and SC** (generalizes `ofRestartCurA`): the budget frame from `KPresB`, the current thread's binding from `SvKA` (`cancel_ipc`, `Restart`) and `TailSA` (the tail keeps every non-SC object), its state from `BlkOthA`; `SwA` and `BlkOthA` are `restartStopped_stepA`'s. -/ -theorem Sched.BodyEndA.ofRestartCurA {S A : Type} {st : machine.Store S} [L : LawfulStore st] +theorem Sched.BodyEndA.ofRestartFromA {S A : Type} {st : machine.Store S} [L : LawfulStore st] {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {J5 J7 : JSlotA S} {s : S} {a : A} {σ σ2 : State Unit} {m : McState} (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m) - {xc : Tcb} (hkc : σ.kheap σ.curThread = some (.tcb xc)) {t : ObjRef} (htc : t ≠ σ.curThread) {y : Tcb} - (hy : (stUpdA σ σ.curThread xc .restart).kheap t = some (.tcb y)) + {σW : State Unit} (hB : BScalA σ σW) {xc : Tcb} (hkc : σ.kheap σ.curThread = some (.tcb xc)) {t : ObjRef} (htc : t ≠ σ.curThread) {y : Tcb} + (hk1 : σW.kheap σ.curThread = some (.tcb { xc with tcbState := .restart })) + (e1 : σW.kheap σ.curSc = σ.kheap σ.curSc) + (hy : σW.kheap t = some (.tcb y)) (hs : ¬ runnable y.tcbState = true ∧ ¬ idle y.tcbState) - (hm : ((), σ2) ∈ (fl4TcbRestart (Z := Unit) t (stUpdA σ σ.curThread xc .restart)).1) - (hsw : SwA σ2) (KB : BlkOthA t (stUpdA σ σ.curThread xc .restart) σ2) - (hinv : ScInvA m σ2) (hzc : ZeroConsA σ2) : BodyEndA σ σ2 m := by - have hk1 : (stUpdA σ σ.curThread xc .restart).kheap σ.curThread = - some (.tcb { xc with tcbState := .restart }) := by simp [stUpdA, setObjA] - have ne : σ.curSc ≠ σ.curThread := fun e => by - obtain ⟨y0, j, h0⟩ := J.curInv.sc - rw [e, hkc] at h0; cases h0 - have e1 : (stUpdA σ σ.curThread xc .restart).kheap σ.curSc = σ.kheap σ.curSc := by - simp [stUpdA, setObjA, Function.update_of_ne ne] + (hm : ((), σ2) ∈ (fl4TcbRestart (Z := Unit) t σW).1) + (KB : BlkOthA t σW σ2) + (k3 : ObjRef → Option KernelObject) (hF : ∀ q, q ≠ t → k3 q = σ2.kheap q) + (hsw : SwA ({ σ2 with kheap := k3 } : State Unit)) (hinv : ScInvA m ({ σ2 with kheap := k3 } : State Unit)) + (hzc : ZeroConsA ({ σ2 with kheap := k3 } : State Unit)) : BodyEndA σ ({ σ2 with kheap := k3 } : State Unit) m := by obtain ⟨t0, ht0, hts, -⟩ := J.curInv.tcb rw [hkc] at ht0 obtain rfl := KernelObject.tcb.inj (Option.some.inj ht0) @@ -76,23 +73,71 @@ theorem Sched.BodyEndA.ofRestartCurA {S A : Type} {st : machine.Store S} [L : La PresR.bind KPresBInst.pres fun _ => PresR.bind KPresBInst.pres fun _ => PresR.bind KPresBInst.pres fun _ => KPresBInst.pres have T2 : KPresB (setThreadState (Z := Unit) t .restart) := by unfold setThreadState setThreadStateAct; kbres - have BK : BKeepA (stUpdA σ σ.curThread xc .restart) σ2 := + have BK : BKeepA σW σ2 := PreO.trans ((inferInstance : KPresBInst (cancelIpc (Z := Unit) t)).pres _ _ h1) (PreO.trans (T2 _ _ h2) (T3 _ _ h3)) - have SV : SvKA (stUpdA σ σ.curThread xc .restart) σb := + have SV : SvKA σW σb := PreO.trans (cancelIpc_svkA t _ _ h1) (setThreadState_svkA t .restart rfl _ _ h2) obtain ⟨yb, hyb, esb, -⟩ := SV.tcb _ _ hk1 have hk2 : σ2.kheap σ.curThread = some (.tcb yb) := (restartTail_tailSA t _ _ h3).obj _ _ hyb (fun _ _ e => by cases e) - refine BodyEndA.ofCurBA J hinv hzc hsw BK.time (by rw [BK.ms]; rfl) BK.ct BK.csc BK.used (fun y' k h => ?_) - ⟨yb, by rw [BK.ct]; exact hk2, by rw [esb, BK.csc]; exact hts⟩ (fun _ x hx => ?_) - · obtain ⟨y, hy, h1, h2⟩ := BK.sc y' k h - exact ⟨y, by rw [← e1]; exact hy, h1, h2⟩ + have hne : σ.curSc ≠ t := fun e => by + obtain ⟨y0, j, h0⟩ := J.curInv.sc + rw [e] at h0 e1 + rw [hy, h0] at e1 + cases e1 + have BK3 : BKeepA σW ({ σ2 with kheap := k3 } : State Unit) := + PreO.trans BK ⟨⟨rfl, rfl, rfl, rfl, rfl, rfl, fun h => h⟩, fun y' n h => ⟨y', by + have e2 : σ2.curSc ≠ t := fun e => hne (hB.csc.symm.trans (BK.csc.symm.trans e)) + have h' : k3 σ2.curSc = some (.schedContext y' n) := h + rw [hF _ e2] at h' + exact h', rfl, rfl⟩⟩ + have hk3 : k3 σ.curThread = some (.tcb yb) := by rw [hF _ htc.symm]; exact hk2 + refine BodyEndA.ofCurBA J hinv hzc hsw (BK3.time.trans hB.time) (by rw [BK3.ms, hB.ms]) (BK3.ct.trans hB.ct) (BK3.csc.trans hB.csc) + (BK3.used.trans hB.used) (fun y' k h => ?_) + ⟨yb, by rw [BK3.ct, hB.ct]; exact hk3, by rw [esb, BK3.csc, hB.csc]; exact hts⟩ (fun _ x hx => ?_) + · obtain ⟨y, hy, h1, h2⟩ := BK3.sc y' k (by rw [hB.csc]; exact h) + exact ⟨y, by rw [← e1, ← hB.csc]; exact hy, h1, h2⟩ · obtain ⟨z, hz, ez⟩ := KB.tcb _ _ htc.symm hk1 - rw [hx] at hz - obtain rfl := KernelObject.tcb.inj (Option.some.inj hz) + have hx' : k3 σ.curThread = some (.tcb x) := hx + rw [hF _ htc.symm, hz] at hx' + obtain rfl := KernelObject.tcb.inj (Option.some.inj hx') exact Or.inr ez +/-- **`BodyEndA` after the caller's `Restart` and the Resume of a stopped thread** (dispatch restore). -/ +theorem Sched.BodyEndA.ofRestartCurA {S A : Type} {st : machine.Store S} [L : LawfulStore st] + {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {J5 J7 : JSlotA S} {s : S} {a : A} {σ σ2 : State Unit} {m : McState} + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m) + {xc : Tcb} (hkc : σ.kheap σ.curThread = some (.tcb xc)) {t : ObjRef} (htc : t ≠ σ.curThread) {y : Tcb} + (hy : (stUpdA σ σ.curThread xc .restart).kheap t = some (.tcb y)) + (hs : ¬ runnable y.tcbState = true ∧ ¬ idle y.tcbState) + (hm : ((), σ2) ∈ (fl4TcbRestart (Z := Unit) t (stUpdA σ σ.curThread xc .restart)).1) + (hsw : SwA σ2) (KB : BlkOthA t (stUpdA σ σ.curThread xc .restart) σ2) + (hinv : ScInvA m σ2) (hzc : ZeroConsA σ2) : BodyEndA σ σ2 m := by + have ne : σ.curSc ≠ σ.curThread := fun e => by + obtain ⟨y0, j, h0⟩ := J.curInv.sc + rw [e, hkc] at h0; cases h0 + exact Sched.BodyEndA.ofRestartFromA (σW := stUpdA σ σ.curThread xc .restart) J ⟨rfl, rfl, rfl, rfl, rfl, rfl, fun h => h⟩ hkc htc (by simp [stUpdA, setObjA]) + (by simp [stUpdA, setObjA, Function.update_of_ne ne]) hy hs hm KB σ2.kheap (fun _ _ => rfl) hsw hinv hzc + +/-- The budget-and-time frame (`BKeepA`) across a restart of a stopped thread. -/ +theorem restart_bkeepA {σ σ2 : State Unit} {t : ObjRef} {y : Tcb} (hy : σ.kheap t = some (.tcb y)) + (hs : ¬ runnable y.tcbState = true ∧ ¬ idle y.tcbState) (hm : ((), σ2) ∈ (fl4TcbRestart (Z := Unit) t σ).1) : + BKeepA σ σ2 := by + obtain ⟨σa, σb, h1, h2, h3⟩ := restart_partsA hy hs hm + have T3 : KPresB (do + let sc ← getTcbObjRef Tcb.tcbSchedContext t + ifSporadicCurScTestRefillUnblockCheck sc + NonDet.maybeM fl4SchedContextResume sc + testPossibleSwitchTo (Z := Unit) t : SMonad Unit Unit) := + PresR.bind KPresBInst.pres fun _ => PresR.bind KPresBInst.pres fun _ => PresR.bind KPresBInst.pres + fun _ => KPresBInst.pres + have T2 : KPresB (setThreadState (Z := Unit) t .restart) := by unfold setThreadState setThreadStateAct; kbres + exact PreO.trans ((inferInstance : KPresBInst (cancelIpc (Z := Unit) t)).pres _ _ h1) + (PreO.trans (T2 _ _ h2) (T3 _ _ h3)) + section variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} @@ -344,7 +389,7 @@ theorem JStage3A.restartStopped_stepA (hs : ¬ runnable x.tcbState = true ∧ ¬ idle x.tcbState) (htc : specPtr t ≠ σ.curThread) (hti : specPtr t ≠ σ.idleThread) (hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t) (hcsc : ∃ xc, σ.kheap σ.curThread = some (.tcb xc) ∧ xc.tcbSchedContext = some σ.curSc) : - sched.restart st ar s a t ⦃ out => out.2 = a ∧ ∃ σ' stack' Q Rl, + sched.restart st ar s a t ⦃ out => out.2 = a ∧ L.curW out.1 = L.curW s ∧ ∃ σ' stack' Q Rl, fl4TcbRestart (Z := Unit) (specPtr t) σ = ({((), σ')}, False) ∧ SwA σ' ∧ BlkOthA (specPtr t) σ σ' ∧ (SysL st H Z.Cs OS ia ie out.1 → SymL st H Z.Cs out.1 → Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U out.1 → @@ -477,7 +522,9 @@ theorem JStage3A.restartStopped_stepA exact ⟨z, hz⟩ have idl : IdleNoFaultA m σ2 := K.idleNoFaultA J.idleNoFault have buf : BufCover st Z.T Bf s' σ2 := T.toBA.bufCover_susA w' (Fl4ProofsA64.P1.K8.Foot.d foot) K - refine ⟨rfl, σ2, stk', Q, Rl, hspec, Isw, KB, fun sysl symL userOK j7 => ?_⟩ + have hcw : L.curW s' = L.curW s := + specPtr_inj (sr.sch.curThread.symm.trans ((restart_bkeepA hk hs hmem).ct.trans J.sr.sch.curThread)) + refine ⟨rfl, hcw, σ2, stk', Q, Rl, hspec, Isw, KB, fun sysl symL userOK j7 => ?_⟩ exact J.of_stepStkA (Q := Q) (Rl := Rl) (curOf := Z.curOf) (curScOf := Z.curScOf) w' HS SSz (Sched.qk_of hmem) hum (fun _ _ => rfl) (BlkOK.bxi blk) sysl symL userOK j7 sr ep rn rs (fun r hr hd c hc' h => J.deadExt.reply r hr hd c hc' (K.stackSubA J.reply rs c hc' r h)) buf bufAl idl mcp yr @@ -553,7 +600,7 @@ theorem JSyscallA.resumeStoppedA have R := J1.restartStopped_stepA sact1 (fun u h => J.noSwitch u h) hA hCs h1 hmb hmbF hmax htu ht hy1 hstop htc hni.1 hni.2 ⟨{ xc with tcbState := .restart }, by simp only [hσ1, stUpdA, setObjA, Function.update_self], by obtain ⟨t0, ht0, hs0, -⟩ := J.toJStage3EntryA.curInv.tcb; rw [hkc] at ht0; cases ht0; exact hs0⟩ - obtain ⟨⟨s2, a2⟩, hrs, ha, σ2, stk', Q, Rl, hspec, hsw, KB, fin⟩ := Fl4ProofsA64.P1.W7.R.ST.ok_of_spec R + obtain ⟨⟨s2, a2⟩, hrs, ha, -, σ2, stk', Q, Rl, hspec, hsw, KB, fin⟩ := Fl4ProofsA64.P1.W7.R.ST.ok_of_spec R simp only at ha subst a2 have hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbResumeSpecA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbResumeSpecA.lean index f585d9245..2e588a3b6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbResumeSpecA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbResumeSpecA.lean @@ -325,6 +325,7 @@ theorem TailSA.sstepA {σ σ' : State Unit} (h : TailSA σ σ') : SStepA σ σ' theorem TailSA.blkOthA {σ σ' : State Unit} (t : ObjRef) (h : TailSA σ σ') : BlkOthA t σ σ' := ⟨fun _ x _ e => ⟨x, h.obj _ _ e (fun _ _ c => by cases c), rfl⟩, + fun _ x _ e => h.obj _ _ e (fun _ _ c => by cases c), fun _ y _ _ e m => ⟨y, h.obj _ _ e (fun _ _ c => by cases c), m⟩, fun _ y q _ _ e w m => ⟨y, q, h.obj _ _ e (fun _ _ c => by cases c), w, m⟩⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbSchedCurA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbSchedCurA.lean new file mode 100644 index 000000000..15c37a419 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbSchedCurA.lean @@ -0,0 +1,189 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbsched): **the tail of SetSchedParams on the caller**. + +* **`BodyOKA.ofChooseA`**: the body-end facts across a step that ends in `choose_new_thread` and keeps the clock, the + current thread / SC / SC object, the consumed time and the release queue (a `set_priority` of the current thread). +* **`JStage3A.tgtConcA`**: a thread with an active SC outside the release queue has the concrete facts + `set_priority` of the current thread reads (release bit clear, SC word non-zero and active). + +Named premises: none. New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbSchedFrameA +import Fl4ProofsA64.P3.Stage3TcbPrioCurA +import Fl4ProofsA64.P3.Stage3BodyOKA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 + +local notation "wa" => core.num.U64.wrapping_add + +noncomputable section + +/-- **`BodyOKA` across a step ending in `choose_new_thread`** (module docstring). -/ +theorem Sched.BodyOKA.ofChooseA {σ σ' : State Unit} {m : McState} (B : Sched.BodyOKA σ m) + (hact : σ'.schedulerAction = .chooseNewThread) (htime : σ'.curTime = σ.curTime) + (hlast : σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime) + (hcsc : σ'.curSc = σ.curSc) (hcons : σ'.consumedTime = σ.consumedTime) + (hrel : σ'.releaseQueue = σ.releaseQueue) + (hobj : ∀ y' k, σ'.kheap σ.curSc = some (.schedContext y' k) → σ.kheap σ.curSc = some (.schedContext y' k)) : + Sched.BodyOKA σ' m := by + refine ⟨⟨?_, fun y' k hk h1 h2 => ?_, fun h x hx => absurd h (by rw [hact]; intro e; cases e)⟩, + fun t e => ?_, fun h => ?_, fun y' k hk h1 h2 h3 o ho => ?_⟩ + · have := B.validTime + unfold ValidMachineTimeA at this ⊢ + rw [htime, hlast]; exact this + · rw [hcsc] at hk h1 + have hk0 := hobj y' k hk + have hc : σ.consumedTime ≠ 0 := by + rcases h2 with h | h + · rwa [hcons] at h + · rw [hact] at h; cases h + obtain ⟨b1, b2⟩ := B.budget y' k hk0 h1 (Or.inl hc) + refine ⟨fun z j hz => ?_, fun hpos z j hz hna => ?_⟩ + · rw [hcsc, hk] at hz + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + rw [hcons, htime]; exact b1 y' k hk0 + · rw [hcsc, hk] at hz + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + rw [hcsc] at hna + rw [hcons] at hpos + rw [hcons, htime]; exact b2 hpos y' k hk0 hna + · rw [hact] at e; cases e + · rw [hcsc] at h ⊢; exact B.scNotIdle h + · rw [hcsc] at hk h2 + rw [hcons] at h3 + rw [hrel] + exact B.owner y' k (hobj y' k hk) h1 h2 h3 o ho + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {s : S} {a : A} {σ : State Unit} {m : McState} + +/-- **A thread with an active SC outside the release queue has the concrete scheduling facts** (module docstring). -/ +theorem JStage3A.tgtConcA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {t : U64} (ht : t ∈ Z.T) (hT : TgtA (specPtr t) σ) (hon : L.mem s (affA t) = L.cpu s) : + (L.mem s (inqA t) &&& sched.Q_RELEASE) = 0#u64 ∧ L.mem s (scA t) ≠ 0#u64 ∧ L.mem s (scA t) ∈ Ac := by + obtain ⟨⟨x, sc, hx, hsc, y0, k0, hy0, hact⟩, hnr⟩ := hT + refine ⟨(J.sr.toSchedSRN.relOn ht hon).2 hnr, ?_⟩ + obtain ⟨x', hx', hxo⟩ := J.sr.sch.tcb t ht + rw [hx] at hx' + have ex : x = x' := KernelObject.tcb.inj (Option.some.inj hx') + subst ex + have hw0 : L.mem s (scA t) ≠ 0#u64 := fun e => by + rw [hsc, optScA, if_pos e] at hxo; cases hxo + refine ⟨hw0, ?_⟩ + have hwC : L.mem s (scA t) ∈ Z.C := J.sr.rest.scMem t ht hw0 + have hwH : L.mem s (scA t) ∈ H.scs := by rw [J.scs]; exact hwC + rw [hsc, optScA, if_neg hw0] at hxo + have esc : sc = scRenA m (L.mem s (scA t)) := Option.some.inj hxo + obtain ⟨y, k, ey, eyr⟩ := J.sr.rest.refillMax _ hwC + rw [← esc] at ey + rw [hy0] at ey + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj ey) + have hpos : 0 < y0.scRefillMax := by simpa [scActive, activeSc] using hact + have hrm : L.rmax s (L.mem s (scA t)) ≠ 0#u64 := by + have e2 : L.rmax s (L.mem s (scA t)) = L.mem s (wa (L.mem s (scA t)) 72#u64) := by + unfold LawfulStore.rmax; rw [maxA_eqA] + rw [e2] + intro e + rw [e] at eyr + simp at eyr + omega + obtain ⟨-, -, -, -, hS⟩ := J.sys.ent.bxi + exact (hS.act _ hwH).2 hrm + + +set_option maxHeartbeats 8000000 in +/-- **`set_mcp`, then `set_priority`, of the current thread from any record state** (the tail of SetSchedParams on +the caller; module docstring). -/ +theorem JStage3A.sspTailCurA {s : S} {a : A} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (sact : SActA σ) {t mcp prio : U64} (ht : t ∈ Z.T) (hwm : mcp.val < 256) (hwp : prio.val < 256) + (htc : specPtr t = σ.curThread) (hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t) + (hrun : ∀ y, σ.kheap (specPtr t) = some (.tcb y) → runnable y.tcbState = true) (hT : TgtA (specPtr t) σ) : + ∃ sm s3 σ3 yd, obj.Tcb.set_mcp st t s mcp = ok sm ∧ sched.set_priority st sm t prio = ok s3 ∧ + σ.kheap (specPtr t) = some (.tcb yd) ∧ + setPriority (Z := Unit) (specPtr t) (BitVec.ofNat 8 prio.val) + (mcpStateA σ (specPtr t) yd (BitVec.ofNat 8 mcp.val)) = ({((), σ3)}, False) ∧ + Sched.BodyKeepA σ (mcpStateA σ (specPtr t) yd (BitVec.ofNat 8 mcp.val)) ∧ + (∀ y' k, σ3.kheap σ.curSc = some (.schedContext y' k) → + (mcpStateA σ (specPtr t) yd (BitVec.ofNat 8 mcp.val)).kheap σ.curSc = some (.schedContext y' k)) ∧ + σ3.schedulerAction = .chooseNewThread ∧ + σ3.curTime = σ.curTime ∧ σ3.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ + σ3.curThread = σ.curThread ∧ σ3.curSc = σ.curSc ∧ σ3.consumedTime = σ.consumedTime ∧ + σ3.releaseQueue = σ.releaseQueue ∧ + (SysL st H Z.Cs OS ia ie s3 → SymL st H Z.Cs s3 → Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s3 → + J7A st (J7R2A st ar hPl.ipa) Z H OS s3 σ3 m → + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 m) := by + have htT : t ∈ H.tcbs := by rw [J.tcbs]; exact ht + obtain ⟨yd, hyd, -⟩ := J.mcp t ht + set sm := L.wr s (mcpA t) mcp with hsm + set σm := mcpStateA σ (specPtr t) yd (BitVec.ofNat 8 mcp.val) with hσm + have hta : TcbAddr t := J.sr.core.tcbs t ht + have hMcp : obj.Tcb.set_mcp st t s mcp = ok sm := eq_of_spec_fd (Fl4ProofsA64.P1.obj.Tcb.set_mcp.wr s t mcp) + obtain ⟨blkM, KM⟩ := J.setMcp_stepA (st := st) ht hwm hyd + have hbd : BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s := BXI.blk J.sys.ent.bxi + have h0 : H 0#u64 = none := J.sys.sysl.ly.h0 + have dM : DMD st H Z.Cs 0#u64 s sm := by + have ha := field_aligned (K := 3440#u64) hta (by simp) (by simp) + exact DMD.ofNone hbd h0 J.symL J.sys.sysl.vr ((writesIn_wr ha).mono fun b e => by + subst e + exact Or.inl (Or.inl ⟨t, htT, 3440#u64, by simp, by simp, by simp, ⟨by simp, by simp, by simp, by simp⟩, + rfl⟩)) + ((LvF.wrT (LvC.of_blk hbd) htT (K0 := 3440#u64) (v := mcp) (by simp) (by simp) (j := 3440) (by simp)).junk + (fun _ _ e => by obtain ⟨-, rfl⟩ := e; unfold LvO; omega) (fun _ _ e => False.elim e) + (fun _ _ e => False.elim e) (fun _ _ e => False.elim e)) + have wM : WritesIn st s sm (SchedStepNWA (st := st) N E Rp _ m σ s) := + (tcbSetMCPriority_partA (PartFrA.refl N E Rp _ m s σ) J.iplaced.e.tcb ht mcp + (BitVec.ofNat 8 mcp.val) hyd).wr + obtain ⟨syslM, symLM, userM, -, j7M⟩ := J.p1StepA hA hPl wM dM (fun k hk => by rw [h0] at hk; cases hk) blkM + have Jm := KM syslM symLM userM (j7M σm m) + have khm : ∀ q, q ≠ specPtr t → σm.kheap q = σ.kheap q := fun q hq => by + simp only [hσm, mcpStateA, updKSc_kheap, Function.update_of_ne hq] + have khT : σm.kheap (specPtr t) = some (.tcb { yd with tcbMcpriority := BitVec.ofNat 8 mcp.val }) := by + simp only [hσm, mcpStateA, updKSc_kheap, Function.update_self] + have sactM : SActA σm := + ⟨fun u hu => sact.f1 u hu, by + obtain ⟨x, hx, hs⟩ := sact.f2 + refine ⟨{ yd with tcbMcpriority := BitVec.ofNat 8 mcp.val }, ?_, ?_⟩ + · show σm.kheap σ.curThread = _ + rw [← htc]; exact khT + · rw [htc] at hyd; rw [hyd] at hx + obtain rfl := KernelObject.tcb.inj (Option.some.inj hx) + exact hs⟩ + have hrunM : runnable ({ yd with tcbMcpriority := BitVec.ofNat 8 mcp.val } : Tcb).tcbState = true := hrun yd hyd + have hTM : TgtA (specPtr t) σm := by + obtain ⟨⟨x, sc, hx, hsc, y0, k0, hy0, hact⟩, hnr⟩ := hT + rw [hyd] at hx + obtain rfl := KernelObject.tcb.inj (Option.some.inj hx) + have hne : sc ≠ specPtr t := fun e => by rw [e, hyd] at hy0; cases hy0 + exact ⟨⟨{ yd with tcbMcpriority := BitVec.ofNat 8 mcp.val }, sc, khT, hsc, y0, k0, by rw [khm sc hne]; exact hy0, hact⟩, + hnr⟩ + have hon : L.mem sm (affA t) = L.cpu sm := by + have x1 : (L.mem sm (affA t)).val < 1 := lt_of_lt_of_eq (hCs _ (Jm.sr.core.aff t ht)) h1 + have y1 : (L.cpu sm).val < 1 := lt_of_lt_of_eq (hCs _ Jm.sr.sch.cpuCs) h1 + exact UScalar.eq_of_val_eq (by rw [Nat.lt_one_iff.mp x1, Nat.lt_one_iff.mp y1]) + obtain ⟨hrel, hsc0, hscA⟩ := Jm.tgtConcA ht hTM hon + have htcM : specPtr t = σm.curThread := htc + obtain ⟨s3, σ3, hsp3, hSet3, kh3, act3, time3, last3, cur3, csc3, cons3, rel3, blk3, J3⟩ := + Jm.prioCurA (st := st) (ar := ar) hCs h1 sactM ht hwp htcM hidles khT hrunM hTM hrel hsc0 hscA + refine ⟨sm, s3, σ3, yd, hMcp, hsp3, hyd, hSet3, ?_, fun y' k h => ?_, act3, time3, last3, cur3, csc3, cons3, rel3, J3⟩ + · exact Sched.BodyKeepA.ofTcbUpd (y' := { yd with tcbMcpriority := BitVec.ofNat 8 mcp.val }) hyd rfl + · have hne : σ.curSc ≠ specPtr t := fun e => by + rw [e, kh3, Function.update_self] at h; cases h + rw [kh3, Function.update_of_ne hne] at h + exact h + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbSchedFrameA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbSchedFrameA.lean new file mode 100644 index 000000000..b6fb6d2c4 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbSchedFrameA.lean @@ -0,0 +1,592 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbsched): **the SC-link frame of the fault-handler deletion and of `set_priority`**. + +SetSchedParams with a changed SC (or with the caller as target) runs its SC step / reschedule after the deletion of TCB +slot 3 and after `set_priority`, so the decode-time checks must survive them. + +* `LkA ct p0`: the current thread, SC and time are kept; every TCB keeps its scheduling context (no TCB appears or + disappears) and enters no IPC queue; the SC at `p0` is the same object when `p0` is the current SC or no TCB is + bound to it (the refill unblock checks touch only a woken thread's non-current SC). +* **`capDelete_noe_lkA`**: `cap_delete` of a slot holding a null or an endpoint cap is `LkA`. +* **`setPriority_lkA`**: `set_priority` is `LkA`. +* **`fl4TcbBindSc_eq_l4v`**: FL4's local TCB bind is l4v's `schedContextBindTcb`. + +Named premises: the bridge's [P] `hmin`; the frame lemmas have none. New module. +-/ +import Fl4ProofsA64.P3.Stage3LiftTcbSspA +import Fl4ProofsA64.P3.Stage3SetPrioFrA +import Fl4ProofsA64.P3.Stage3CancelBodyA +import Fl4ProofsA64.P3.Stage3TcbResumeSpecA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4Spec Fl4SpecA64 Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Notif Classical + +noncomputable section + +/-- FL4's local TCB bind is l4v's `sched_context_bind_tcb`; [P] `hmin` (the two minimum budgets agree). -/ +theorem fl4TcbBindSc_eq_l4v (hmin : fl4MinBudget = MIN_BUDGET) (sc t : ObjRef) : + fl4TcbBindSc (Z := Unit) sc t = schedContextBindTcb sc t := by + unfold fl4TcbBindSc schedContextBindTcb + rw [fl4SchedContextResume_eq_l4v (Z := Unit) hmin] + +/-- Module docstring. -/ +structure LkA (ct p0 : ObjRef) (σ σ' : State Unit) : Prop where + cur : σ'.curThread = σ.curThread + csc : σ'.curSc = σ.curSc + time : σ'.curTime = σ.curTime + fwd : ∀ p x, σ.kheap p = some (.tcb x) → ∃ y, σ'.kheap p = some (.tcb y) ∧ + y.tcbSchedContext = x.tcbSchedContext ∧ (y.tcbState = x.tcbState ∨ ipcQueuedThreadState y.tcbState = false) + bwd : ∀ p y, σ'.kheap p = some (.tcb y) → ∃ x, σ.kheap p = some (.tcb x) ∧ y.tcbSchedContext = x.tcbSchedContext + sc : (p0 = σ.curSc ∨ ∀ p x, σ.kheap p = some (.tcb x) → x.tcbSchedContext ≠ some p0) → + ∀ y k, σ.kheap p0 = some (.schedContext y k) → σ'.kheap p0 = some (.schedContext y k) + stc : ∀ x y, σ.kheap ct = some (.tcb x) → σ'.kheap ct = some (.tcb y) → y.tcbState = x.tcbState + +instance (ct p0 : ObjRef) : PreO (LkA ct p0) where + refl _ := ⟨rfl, rfl, rfl, fun _ x h => ⟨x, h, rfl, Or.inl rfl⟩, fun _ y h => ⟨y, h, rfl⟩, fun _ _ _ h => h, + fun x y hx hy => by rw [hx] at hy; cases hy; rfl⟩ + trans {a b c} h1 h2 := by + refine ⟨h2.cur.trans h1.cur, h2.csc.trans h1.csc, h2.time.trans h1.time, fun p x h => ?_, fun p z h => ?_, + fun g y k h => ?_, fun x z hx hz => ?_⟩ + · obtain ⟨y, hy, s1, t1⟩ := h1.fwd p x h + obtain ⟨z, hz, s2, t2⟩ := h2.fwd p y hy + refine ⟨z, hz, s2.trans s1, ?_⟩ + rcases t2 with t2 | t2 + · rcases t1 with t1 | t1 + · exact Or.inl (t2.trans t1) + · exact Or.inr (by rw [t2]; exact t1) + · exact Or.inr t2 + · obtain ⟨y, hy, s2⟩ := h2.bwd p z h + obtain ⟨x, hx, s1⟩ := h1.bwd p y hy + exact ⟨x, hx, s2.trans s1⟩ + · refine h2.sc ?_ y k (h1.sc g y k h) + rcases g with g | g + · exact Or.inl (g.trans h1.csc.symm) + · refine Or.inr fun p x hx => ?_ + obtain ⟨x0, hx0, e⟩ := h1.bwd p x hx + rw [e]; exact g p x0 hx0 + · obtain ⟨y, hy, -⟩ := h2.bwd ct z hz + exact (h2.stc y z hy hz).trans (h1.stc x y hx hy) + +namespace LkA +variable {ct p0 : ObjRef} {σ σ' : State Unit} + +theorem of_kheap (h : σ'.kheap = σ.kheap) (c : σ'.curThread = σ.curThread) (s : σ'.curSc = σ.curSc) + (t : σ'.curTime = σ.curTime) : LkA ct p0 σ σ' := + ⟨c, s, t, fun _ x hx => ⟨x, by rw [h]; exact hx, rfl, Or.inl rfl⟩, fun _ y hy => ⟨y, by rw [← h]; exact hy, rfl⟩, + fun _ _ _ hy => by rw [h]; exact hy, fun x y hx hy => by rw [h, hx] at hy; cases hy; rfl⟩ + +/-- One object replaced that was not an SC; a TCB stays a TCB with the same scheduling context. -/ +theorem upd {q : ObjRef} {o o' : KernelObject} (hq : σ.kheap q = some o) + (ht : ∀ x, o = .tcb x → ∃ y, o' = .tcb y ∧ y.tcbSchedContext = x.tcbSchedContext ∧ + (y.tcbState = x.tcbState ∨ ipcQueuedThreadState y.tcbState = false)) + (htb : ∀ y, o' = .tcb y → ∃ x, o = .tcb x) (hs : ∀ y k, o ≠ .schedContext y k) + (hc : q = ct → ∀ x y, o = .tcb x → o' = .tcb y → y.tcbState = x.tcbState) : + LkA ct p0 σ { σ with kheap := Function.update σ.kheap q (some o') } := by + refine ⟨rfl, rfl, rfl, fun p x h => ?_, fun p y h => ?_, fun _ y k h => ?_, fun x y hx hy => ?_⟩ + · by_cases e : p = q + · subst e; rw [hq] at h + obtain ⟨y, rfl, r⟩ := ht x (Option.some.inj h) + exact ⟨y, Function.update_self _ _ _, r⟩ + · exact ⟨x, by show Function.update σ.kheap q _ p = _; rw [Function.update_of_ne e]; exact h, rfl, Or.inl rfl⟩ + · change Function.update σ.kheap q (some o') p = _ at h + by_cases e : p = q + · subst e; rw [Function.update_self] at h + obtain ⟨x, rfl⟩ := htb y (Option.some.inj h) + obtain ⟨y', e', r⟩ := ht x rfl + rw [e'] at h + cases h + exact ⟨x, hq, r.1⟩ + · rw [Function.update_of_ne e] at h; exact ⟨y, h, rfl⟩ + · have e : p0 ≠ q := fun e => by + rw [e, hq] at h + exact hs y k (Option.some.inj h) + show Function.update σ.kheap q _ p0 = _ + rw [Function.update_of_ne e]; exact h + · change Function.update σ.kheap q (some o') ct = _ at hy + by_cases e : ct = q + · subst e + rw [Function.update_self] at hy + rw [hq] at hx + exact hc rfl x y (Option.some.inj hx) (Option.some.inj hy) + · rw [Function.update_of_ne e] at hy + rw [hx] at hy; cases hy; rfl + +end LkA + +abbrev LkPresA (ct p0 : ObjRef) {α : Type} (m : SMonad Unit α) : Prop := PresR (LkA ct p0) m + +section prims +variable {ct p0 : ObjRef} + +theorem eq_lkA {α : Type} {m : NonDet (State Unit) α} (h : PresR (@Eq (State Unit)) m) : PresR (LkA ct p0) m := + fun σ r hr => by rw [← h σ r hr]; exact PreO.refl σ + +theorem threadSet_lkA (f : Tcb → Tcb) (t : ObjRef) + (hf : ∀ x, (f x).tcbSchedContext = x.tcbSchedContext ∧ + ((f x).tcbState = x.tcbState ∨ ipcQueuedThreadState (f x).tcbState = false)) + (hc : t = ct → ∀ x, (f x).tcbState = x.tcbState) : + LkPresA ct p0 (threadSet (Z := Unit) f t) := fun σ r hr => by + obtain ⟨x, hx, e⟩ := threadSet_memA f t hr + rw [e] + exact LkA.upd hx (fun z hz => by cases hz; exact ⟨_, rfl, hf x⟩) (fun _ _ => ⟨x, rfl⟩) (fun _ _ h => by cases h) + (fun e x1 y1 h1 h2 => by cases h1; cases h2; exact hc e x) + +theorem setSimpleKo_lkA {α : Type} [Nonempty α] (C : α → KernelObject) (p : ObjRef) (v : α) + (ht : ∀ a x, C a ≠ .tcb x) (hs : ∀ a x n, C a ≠ .schedContext x n) : + LkPresA ct p0 (setSimpleKo (Z := Unit) C p v) := fun σ r hr => by + unfold setSimpleKo at hr + obtain ⟨o, ho, hr⟩ := eqPres_mem (getObject_eqPres p) hr + obtain ⟨_, -, hr⟩ := eqPres_mem (PresR.assert _) hr + obtain ⟨_, hpi, hr⟩ := eqPres_mem (PresR.assert _) hr + obtain ⟨ko, -, e⟩ := setObject_memA hr + have hgo : σ.kheap p = some o := by + have ho' : (o, σ) ∈ (NonDet.assertOpt (σ.kheap p) σ).1 := ho + cases hk : σ.kheap p with + | none => rw [hk] at ho'; exact absurd ho' (Set.notMem_empty _) + | some o' => + rw [hk] at ho' + have := congrArg Prod.fst (show (o, σ) = (o', σ) from ho') + exact congrArg some this.symm + have hn : ∃ a, C a = o := by + have h1 := hpi.1 + unfold partialInv at h1 + split_ifs at h1 with hu + · obtain ⟨a, ha, -⟩ := hu + exact ⟨a, ha⟩ + · exact absurd rfl h1 + obtain ⟨a, ea⟩ := hn + rw [e] + exact LkA.upd hgo (fun x h => absurd (ea.trans h) (ht a x)) (fun y h => absurd h (ht _ y)) + (fun x n h => absurd (ea.trans h) (hs a x n)) (fun _ x _ h1 _ => absurd (ea.trans h1) (ht a x)) + +theorem getSimpleKo_lkA {α : Type} [Nonempty α] (C : α → KernelObject) (p : ObjRef) : + LkPresA ct p0 (getSimpleKo (Z := Unit) C p) := by + refine eq_lkA ?_ + unfold getSimpleKo + refine PresR.bind (getObject_eqPres p) (fun _ => ?_) + eqpres + +theorem getThreadState_lkA (t : ObjRef) : LkPresA ct p0 (getThreadState (Z := Unit) t) := by + unfold getThreadState + exact eq_lkA (threadGet_eqPres _ t) + +theorem setSchedulerAction_lkA (a : SchedulerAction) : LkPresA ct p0 (setSchedulerAction (Z := Unit) a) := by + unfold setSchedulerAction + exact PresR.modify _ fun _ => LkA.of_kheap rfl rfl rfl rfl + +theorem setThreadState_lkA (t : ObjRef) (ts : ThreadState) (hts : ipcQueuedThreadState ts = false) + (hne : t ≠ ct) : LkPresA ct p0 (setThreadState (Z := Unit) t ts) := by + unfold setThreadState + refine PresR.bind (threadSet_lkA _ t (fun _ => ⟨rfl, Or.inr hts⟩) (fun e => absurd e hne)) (fun _ σ r hr => ?_) + rw [setThreadStateAct_eq] at hr + have e : r = ((), stsAct σ t) := hr + rw [e] + show LkA ct p0 σ (stsAct σ t) + unfold stsAct + split_ifs + · exact LkA.of_kheap rfl rfl rfl rfl + · exact PreO.refl _ + +theorem schedShape_lkA {σ σ' : State Unit} + (h : σ' = { σ with readyQueues := σ'.readyQueues, schedulerAction := σ'.schedulerAction }) : LkA ct p0 σ σ' := by + rw [h] + exact LkA.of_kheap rfl rfl rfl rfl + +theorem enq_lkA (t : ObjRef) : LkPresA ct p0 (tcbSchedAction (Z := Unit) tcbSchedEnqueue t) := fun _ _ hr => + schedShape_lkA (tcbSchedAction_enq_memA t hr).1.1 + +theorem deq_lkA (t : ObjRef) : LkPresA ct p0 (tcbSchedAction (Z := Unit) tcbSchedDequeue t) := fun _ _ hr => + schedShape_lkA (tcbSchedAction_shapeA tcbSchedDequeue (fun _ _ _ h => Or.inr (List.mem_filter.1 h).1) t hr).1.1 + +theorem resched_lkA : LkPresA ct p0 (rescheduleRequired (Z := Unit)) := fun _ _ hr => + schedShape_lkA (rescheduleRequired_memA hr).1.1 + +theorem pst_lkA (t : ObjRef) : LkPresA ct p0 (possibleSwitchTo (Z := Unit) t) := fun _ _ hr => + schedShape_lkA (possibleSwitchTo_memA t hr).1.1 + +theorem tcbAppend_lkA (t : ObjRef) (qs : List ObjRef) : LkPresA ct p0 (tcbAppend (Z := Unit) t qs) := fun σ r hr => by + unfold tcbAppend at hr + rw [(orderedInsert_spec t qs _ _ hr).1] + exact PreO.refl (R := LkA ct p0) σ + +end prims + +macro "lkres" : tactic => `(tactic| + repeat' (first + | exact getSimpleKo_lkA _ _ + | exact getThreadState_lkA _ + | exact eq_lkA (threadGet_eqPres _ _) + | exact tcbAppend_lkA _ _ + | exact setSimpleKo_lkA _ _ _ (fun _ _ h => by cases h) (fun _ _ _ h => by cases h) + | exact setThreadState_lkA _ _ rfl + | exact enq_lkA _ + | exact deq_lkA _ + | exact resched_lkA + | exact pst_lkA _ + | exact PresR.pure _ + | exact PresR.assert _ + | exact PresR.assertOpt _ + | exact PresR.gets _ + | refine PresR.bind ?_ (fun _ => ?_) + | refine PresR.when ?_ + | refine PresR.ite' ?_ ?_ + | dsimp only + | split)) + +section +variable {ct p0 : ObjRef} + +/-- `set_priority` is `LkA` (module docstring). -/ +theorem setPriority_lkA (t : ObjRef) (p : Priority) : LkPresA ct p0 (setPriority (Z := Unit) t p) := by + have hp : LkPresA ct p0 (threadSetPriority (Z := Unit) t p) := by + unfold threadSetPriority + exact threadSet_lkA _ _ (fun _ => ⟨rfl, Or.inl rfl⟩) (fun _ _ => rfl) + have he : ∀ e, LkPresA ct p0 (reorderEp (Z := Unit) e t) := fun e => by + unfold reorderEp getEndpoint setEndpoint + lkres + have hn : ∀ n, LkPresA ct p0 (reorderNtfn (Z := Unit) n t) := fun n => by + unfold reorderNtfn getNotification setNotification + lkres + have hq : ∀ d q, LkPresA ct p0 (getTcbQueue (Z := Unit) d q) := fun d q => eq_lkA (by unfold getTcbQueue; eqpres) + unfold setPriority + refine PresR.bind (getThreadState_lkA t) (fun ts => ?_) + refine PresR.ite' ?_ ?_ + · refine PresR.bind (eq_lkA (threadGet_eqPres _ _)) (fun _ => ?_) + refine PresR.bind (eq_lkA (threadGet_eqPres _ _)) (fun _ => ?_) + refine PresR.bind (hq _ _) (fun _ => PresR.bind (PresR.gets _) fun _ => PresR.ite' ?_ hp) + exact PresR.bind (deq_lkA _) fun _ => PresR.bind hp fun _ => PresR.bind (enq_lkA _) fun _ => resched_lkA + · refine PresR.bind hp (fun _ => PresR.bind ?_ (fun _ => ?_)) + · cases epBlocked ts + · exact PresR.pure _ + · exact he _ + · cases ntfnBlocked ts + · exact PresR.pure _ + · exact hn _ + +theorem mapMx_lkA {α : Type} (f : α → SMonad Unit Unit) : + ∀ l : List α, (∀ x ∈ l, LkPresA ct p0 (f x)) → LkPresA ct p0 (NonDet.mapMx f l) + | [], _ => by unfold NonDet.mapMx; exact PresR.pure _ + | x :: l, hf => by + unfold NonDet.mapMx + exact PresR.bind (hf x (List.mem_cons_self ..)) fun _ => mapMx_lkA f l fun y hy => hf y (List.mem_cons_of_mem _ hy) + +/-- The sporadic refill check of a woken thread's SC: it skips the current SC, and its SC is bound to a TCB. -/ +theorem wakeRefill_lkA (t : ObjRef) {σ : State Unit} {x : Tcb} (hx : σ.kheap t = some (.tcb x)) + {r : Unit × State Unit} + (hr : r ∈ (ifCondRefillUnblockCheck (Z := Unit) x.tcbSchedContext (some false) (some true) σ).1) : + LkA ct p0 σ r.2 := by + unfold ifCondRefillUnblockCheck at hr + cases ho : x.tcbSchedContext with + | none => + rw [ho] at hr + have e : r = ((), σ) := hr + rw [e]; exact PreO.refl _ + | some p => + rw [ho] at hr + simp only [NonDet.maybeM] at hr + obtain ⟨⟨sc, σ1⟩, h1, hr⟩ := mem_bindA.1 hr + have e1 : σ1 = σ := (getSchedContext_mem h1).1 + have hk : ∃ y k, σ.kheap p = some (.schedContext y k) := by + have := (getSchedContext_mem h1).2 + exact ⟨_, _, this.choose_spec⟩ + rw [e1] at hr + dsimp only at hr + rw [nd_gets_bindSc, nd_pure_bindSc] at hr + try dsimp only at hr + unfold NonDet.when at hr + split at hr + · split at hr + · rename_i c + have ne : p ≠ σ.curSc := c rfl + have O := refillUnblockCheck_onlyCkA p σ r hr + obtain ⟨y0, k0, hk⟩ := hk + have nt : ∀ q z, σ.kheap q = some (.tcb z) → q ≠ p := fun q z h e => by + rw [e, hk] at h; cases h + refine ⟨O.cur, O.csc, O.time, fun q z h => ⟨z, by rw [O.other q (nt q z h)]; exact h, rfl, Or.inl rfl⟩, + fun q z h => ⟨z, O.tcb q z h, rfl⟩, fun g y k h => ?_, fun x' y' hx' hy' => ?_⟩ + swap + · have := O.tcb ct y' hy' + rw [hx'] at this; cases this; rfl + have np : p0 ≠ p := fun e => by + rcases g with g | g + · exact ne (e.symm.trans g) + · exact g t x hx (by rw [ho, e]) + rw [O.other p0 np]; exact h + · have : r = ((), σ) := hr + rw [this]; exact PreO.refl _ + · have : r = ((), σ) := hr + rw [this]; exact PreO.refl _ + +theorem restartThreadIfNoFault_lkA (t : ObjRef) (hne : t ≠ ct) : + LkPresA ct p0 (restartThreadIfNoFault (Z := Unit) t) := by + unfold restartThreadIfNoFault + refine PresR.bind (eq_lkA (threadGet_eqPres _ _)) (fun _ => PresR.ite' ?_ (setThreadState_lkA _ _ rfl hne)) + refine PresR.bind (setThreadState_lkA _ _ rfl hne) (fun _ σ r hr => ?_) + unfold getTcbObjRef at hr + obtain ⟨scOpt, hs, hr⟩ := eqPres_mem (threadGet_eqPres _ t) hr + obtain ⟨⟨u, σ2⟩, h2, h3⟩ := mem_bindA.1 hr + obtain ⟨x, hx⟩ : ∃ x, σ.kheap t = some (.tcb x) := by + have hs' := hs + unfold threadGet at hs' + obtain ⟨y1, hy1, -⟩ := hs' + have hy1' : y1 ∈ (NonDet.assertOpt (getTcb (Z := Unit) t σ) σ).1 := hy1 + cases hg : getTcb (Z := Unit) t σ with + | none => rw [hg] at hy1'; exact absurd hy1' (Set.notMem_empty _) + | some x => + refine ⟨x, ?_⟩ + unfold getTcb readObject at hg + cases hk : σ.kheap t with + | none => simp [hk] at hg + | some o => cases o <;> simp [hk] at hg ⊢ <;> exact hg + have ex : scOpt = x.tcbSchedContext := (Prod.mk.inj (threadGet_valA _ hx hs)).1 + rw [ex] at h2 + exact PreO.trans (wakeRefill_lkA t hx h2) (pst_lkA t σ2 r h3) + + +theorem finaliseEp_lkA {ct p0 r : ObjRef} {b : Badge} {rs : CapRights} (f : Bool) {σ : State Unit} + {y : (Cap × Cap) × State Unit} (h : y ∈ (fl4FinaliseCap (Z := Unit) (.endpointCap r b rs) f σ).1) + (hne : EpQNeA r σ) (hct : ct = σ.curThread) : LkA ct p0 σ y.2 := by + have hu : ∀ t q, t ≠ ct → LkPresA ct p0 (replyUnlinkTcb (Z := Unit) t q) := fun t q htc => by + unfold replyUnlinkTcb + refine PresR.bind (eq_lkA (getReply_eqPres q)) (fun _ => ?_) + refine PresR.bind (PresR.assert _) (fun _ => ?_) + refine PresR.bind (getThreadState_lkA t) (fun _ => ?_) + refine PresR.bind (PresR.assert _) (fun _ => ?_) + refine PresR.bind ?_ (fun _ => setThreadState_lkA _ _ rfl htc) + unfold setReplyObjRef updateSkObjRef + exact PresR.bind (getSimpleKo_lkA _ _) (fun _ => + setSimpleKo_lkA _ _ _ (fun _ _ h => by cases h) (fun _ _ _ h => by cases h)) + have hd : ∀ t, LkPresA ct p0 (tcbEpDequeue (Z := Unit) t r) := fun t => by + unfold tcbEpDequeue + refine PresR.bind (getSimpleKo_lkA _ _) (fun _ => ?_) + refine PresR.bind (PresR.pure _) (fun _ => ?_) + refine PresR.bind (PresR.assert _) (fun _ => ?_) + refine PresR.bind (PresR.pure _) (fun _ => ?_) + refine PresR.bind (PresR.pure _) (fun _ => ?_) + exact setSimpleKo_lkA _ _ _ (fun _ _ h => by cases h) (fun _ _ _ h => by cases h) + have hr : ∀ t, t ≠ ct → LkPresA ct p0 (removeAndRestartEpQueuedThread (Z := Unit) t r) := fun t htc => by + unfold removeAndRestartEpQueuedThread + refine PresR.bind (hd t) fun _ => PresR.bind (getThreadState_lkA t) fun _ => + PresR.bind (PresR.pure _) fun o => PresR.bind ?_ fun _ => restartThreadIfNoFault_lkA t htc + cases o + · exact PresR.pure _ + · exact hu _ _ htc + have hc : ∀ {σ' : State Unit}, ((), σ') ∈ (cancelAllIpc (Z := Unit) r σ).1 → LkA ct p0 σ σ' := fun {σ'} h => by + unfold cancelAllIpc at h + obtain ⟨⟨ep, σ1⟩, h1, h⟩ := mem_bindA.1 h + have hk : σ.kheap r = some (.endpoint ep) := (getEndpoint_mem h1).1 + have e1 : σ1 = σ := (getEndpoint_mem h1).2 + rw [e1] at h + cases ep with + | idleEP => rw [(Prod.mk.inj h).2]; exact PreO.refl σ + | _ => + obtain ⟨⟨q, σ0⟩, hq, h⟩ := mem_bindA.1 h + have eqq : q = _ := (Prod.mk.inj hq).1 + have eq0 : σ0 = σ := (Prod.mk.inj hq).2 + rw [eq0] at h + obtain ⟨⟨u, σ2⟩, h2, h3⟩ := mem_bindA.1 h + have k1 : LkA ct p0 σ σ2 := mapMx_lkA _ q (fun t ht => hr t fun e => hne _ hk (by + rw [eqq] at ht; rw [← hct, ← e]; exact ht)) σ _ h2 + exact PreO.trans k1 (resched_lkA σ2 _ h3) + change y ∈ (NonDet.liftM (fun _ => (Cap.nullCap, Cap.nullCap)) + (NonDet.when (f = true) (cancelAllIpc (Z := Unit) r)) σ).1 at h + unfold NonDet.liftM at h + obtain ⟨⟨u, σ1⟩, h1, h2⟩ := mem_bindA.1 h + rw [(Prod.mk.inj h2).2] + unfold NonDet.when at h1 + split at h1 + · exact hc h1 + · rw [(Prod.mk.inj h1).2]; exact PreO.refl σ + +theorem setCap_lkA {ct p0 : ObjRef} (c : Cap) (sl : CslotPtr) : LkPresA ct p0 (setCap (Z := Unit) c sl) := fun σ r hr => by + obtain ⟨o, cref⟩ := sl + unfold setCap at hr + dsimp only at hr + obtain ⟨obj, hobj, hr⟩ := eqPres_mem (getObject_eqPres o) hr + have hk : σ.kheap o = some obj := by + have ho' : (obj, σ) ∈ (NonDet.assertOpt (σ.kheap o) σ).1 := hobj + cases hk : σ.kheap o with + | none => rw [hk] at ho'; exact absurd ho' (Set.notMem_empty _) + | some o' => + rw [hk] at ho' + have := congrArg Prod.fst (show (obj, σ) = (o', σ) from ho') + exact congrArg some this.symm + have fin : ∀ obj' : KernelObject, r ∈ ((NonDet.pure obj' >>= fun x => setObject (Z := Unit) o x) σ).1 → + (∀ x, obj = .tcb x → ∃ y, obj' = .tcb y ∧ y.tcbSchedContext = x.tcbSchedContext ∧ y.tcbState = x.tcbState) → + (∀ y, obj' = .tcb y → ∃ x, obj = .tcb x) → (∀ y k, obj ≠ .schedContext y k) → LkA ct p0 σ r.2 := by + intro obj' h k1 k2 k3 + obtain ⟨x, hx, h⟩ := mem_bindA.1 h + have ex : x = (obj', σ) := hx + subst ex + obtain ⟨ko, -, e⟩ := setObject_memA h + rw [e] + exact LkA.upd hk (fun x h => by + obtain ⟨y, a, b, c⟩ := k1 x h + exact ⟨y, a, b, Or.inl c⟩) k2 k3 + (fun _ x y h1 h2 => by + obtain ⟨y', e', -, hs⟩ := k1 x h1 + rw [e'] at h2; cases h2; exact hs) + have bad : ∀ {α : Type} (f : α → SMonad Unit Unit), ¬ r ∈ ((NonDet.fail >>= f) σ).1 := fun f h => by + obtain ⟨x, hx, -⟩ := mem_bindA.1 h + exact absurd hx (Set.notMem_empty _) + cases obj with + | cnode sz cn => + dsimp only at hr + split at hr + · exact fin _ hr (fun x h => by cases h) (fun y h => by cases h) (fun y k h => by cases h) + · exact absurd hr (bad _) + | tcb t => + dsimp only at hr + repeat' split at hr + all_goals + first + | exact absurd hr (bad _) + | exact fin _ hr (fun x h => by cases h; exact ⟨_, rfl, rfl, rfl⟩) (fun y _ => ⟨t, rfl⟩) + (fun y k h => by cases h) + | _ => exact absurd hr (bad _) + +theorem setCdt_lkA {ct p0 : ObjRef} (t : Cdt) : LkPresA ct p0 (setCdt (Z := Unit) t) := fun σ r hr => by + unfold setCdt at hr + obtain ⟨x, hx, h⟩ := mem_bindA.1 hr + have ex : x = (σ, σ) := hx + subst ex + have e : r = ((), { σ with cdt := t }) := h + rw [e] + exact LkA.of_kheap rfl rfl rfl rfl + +theorem emptySlot_lkA {ct p0 : ObjRef} (sl : CslotPtr) : LkPresA ct p0 (emptySlot (Z := Unit) sl .nullCap) := by + unfold emptySlot postCapDeletion setOriginal doExtendedOp + repeat' (first + | exact eq_lkA (getCap_eqPres _) + | exact setCap_lkA _ _ + | exact setCdt_lkA _ + | exact PresR.selectF _ + | exact PresR.get + | exact PresR.pure _ + | exact PresR.gets _ + | exact PresR.assert _ + | refine PresR.modify _ (fun _ => LkA.of_kheap rfl rfl rfl rfl) + | refine PresR.bind ?_ (fun _ => ?_) + | refine PresR.ite' ?_ ?_ + | dsimp only + | split) + +/-- **`cap_delete` of a slot holding a null or an endpoint cap is `LkA`** (module docstring). -/ +theorem capDelete_noe_lkA {ct p0 : ObjRef} {sl : CslotPtr} {σ σ' : State Unit} {c : Cap} + (hg : getCap (Z := Unit) sl σ = ({(c, σ)}, False)) + (hc : c = .nullCap ∨ ∃ r b rs, c = .endpointCap r b rs ∧ EpQNeA r σ) (hct : ct = σ.curThread) + (h : (.ok (), σ') ∈ ((fl4CapDelete (Z := Unit) sl).run σ).1) : LkA ct p0 σ σ' := by + rw [← capDeleteGA_fl4] at h + unfold capDeleteGA at h + rw [ExceptT.run_bind] at h + obtain ⟨⟨x, τ⟩, h1, h2⟩ := mem_bindA.1 h + obtain v | v := x + · cases (Set.mem_singleton_iff.mp h2) + have e2 : σ' = τ := by + change _ ∈ ((NonDetE.returnOk () : PMonad Unit Unit).run τ).1 at h2 + rw [run_returnOkD] at h2 + exact (Prod.mk.inj (Set.mem_singleton_iff.1 h2)).2 + rw [e2] + let G : State Unit → Prop := fun s => ct = s.curThread ∧ ∃ c, getCap (Z := Unit) sl s = ({(c, s)}, False) ∧ + (c = .nullCap ∨ ∃ r b rs, c = .endpointCap r b rs ∧ EpQNeA r s) + have main := rd_inductGA (Fn := fl4FinaliseCap) + (fun d s y => (d = .finaliseSlotCall sl true → G s → LkA ct p0 s y.2 ∧ ∀ w, y.1 = .ok w → w.2 = .nullCap) ∧ + (d = .cTEDeleteCall sl true → G s → LkA ct p0 s y.2)) + (fun d s y hy => ?_) h1 + · exact main.2 rfl ⟨hct, c, hg, hc⟩ + refine ⟨fun ed hG => ?_, fun ed hG => ?_⟩ + · subst ed + obtain ⟨hct, c, hg, hc⟩ := hG + unfold recDelFGA withoutPreemption at hy + dsimp only at hy + rw [ExceptT.run_bind] at hy + obtain ⟨⟨r1, s1⟩, h1, hy⟩ := mem_bindA.1 hy + rw [run_liftE_stD hg] at h1 + obtain ⟨rfl, e1⟩ := Prod.mk.inj (Set.mem_singleton_iff.1 h1) + subst s1 + dsimp only at hy + rcases hc with rfl | ⟨r, b, rs, rfl, hEq⟩ + · simp only [↓reduceIte] at hy + rw [run_returnOkD] at hy + rw [Set.mem_singleton_iff.1 hy] + exact ⟨PreO.refl _, fun w e => by cases e; rfl⟩ + · rw [if_neg (by simp), ExceptT.run_bind] at hy + obtain ⟨⟨r2, s2⟩, h2, hy⟩ := mem_bindA.1 hy + rw [liftE_runD] at h2 + obtain ⟨⟨f, s3⟩, h3, h4⟩ := mem_bindA.1 h2 + have e4 := Prod.mk.inj h4 + have e3 : s = s3 := (show PresR (@Eq (State Unit)) (isFinalCap (Z := Unit) _) by unfold isFinalCap; eqpres) s _ h3 + obtain ⟨rfl, e5⟩ := e4 + subst e5 + subst e3 + dsimp only at hy + rw [ExceptT.run_bind] at hy + obtain ⟨⟨r6, s6⟩, h6, hy⟩ := mem_bindA.1 hy + rw [liftE_runD] at h6 + obtain ⟨⟨rc, s7⟩, h7, h8⟩ := mem_bindA.1 h6 + have e8 := Prod.mk.inj h8 + have L7 : LkA ct p0 s s7 := finaliseEp_lkA (r := r) (b := b) (rs := rs) _ h7 hEq hct + have erc : rc = (Cap.nullCap, Cap.nullCap) := by + change (rc, s7) ∈ (NonDet.liftM (fun _ => (Cap.nullCap, Cap.nullCap)) + (NonDet.when (f = true) (cancelAllIpc (Z := Unit) r)) s).1 at h7 + unfold NonDet.liftM at h7 + obtain ⟨u, -, hu⟩ := mem_bindA.1 h7 + exact (Prod.mk.inj hu).1 + obtain ⟨rfl, e9⟩ := e8 + subst e9 + subst erc + dsimp only at hy + rw [if_pos (show capRemoveable Cap.nullCap sl from trivial), run_returnOkD] at hy + rw [Set.mem_singleton_iff.1 hy] + exact ⟨L7, fun w e => by cases e; rfl⟩ + · subst ed + unfold recDelFGA withoutPreemption at hy + dsimp only at hy + erw [ExceptT.run_bind] at hy + obtain ⟨⟨r1, s1⟩, h1, hy⟩ := mem_bindA.1 hy + have P := h1.1 rfl hG + cases r1 with + | error e => + rw [Set.mem_singleton_iff.1 hy] + exact P.1 + | ok w => + have ew := P.2 w rfl + obtain ⟨succ, cl⟩ := w + dsimp only at ew hy + subst ew + erw [ExceptT.run_bind] at hy + obtain ⟨⟨r2, s2⟩, h2, hy⟩ := mem_bindA.1 hy + rw [liftE_runD] at h2 + obtain ⟨⟨u, s3⟩, h3, h4⟩ := mem_bindA.1 h2 + obtain ⟨rfl, e5⟩ := Prod.mk.inj h4 + subst e5 + have L3 : LkA ct p0 s1 s2 := PresR.when (emptySlot_lkA sl) s1 _ h3 + dsimp only at hy + rw [run_returnOkD] at hy + rw [Set.mem_singleton_iff.1 hy] + exact PreO.trans P.1 L3 + +/-- **`cap_insert` is `LkA`.** -/ +theorem capInsert_lkA {ct p0 : ObjRef} (c : Cap) (s d : CslotPtr) : LkPresA ct p0 (capInsert (Z := Unit) c s d) := by + unfold capInsert setUntypedCapAsFull updateCdt setOriginal doExtendedOp + repeat' (first + | exact eq_lkA (getCap_eqPres _) + | exact setCap_lkA _ _ + | exact setCdt_lkA _ + | exact PresR.selectF _ + | exact PresR.get + | exact PresR.pure _ + | exact PresR.gets _ + | exact PresR.assert _ + | refine PresR.modify _ (fun _ => LkA.of_kheap rfl rfl rfl rfl) + | refine PresR.bind ?_ (fun _ => ?_) + | refine PresR.ite' ?_ ?_ + | dsimp only + | split) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbSchedMidA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbSchedMidA.lean new file mode 100644 index 000000000..9bd7d4102 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbSchedMidA.lean @@ -0,0 +1,123 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbsched): **the P1 facts after `set_priority`, from the record state before it**. + +SetSchedParams with a changed SC runs `unbind_tcb` / `bind_tcb` after `set_mcp` and `set_priority`, so those steps need +the record (`JStage3A`) at the state after `set_priority`, which is not the final state. + +* **`setPriority_dm0A`**: `set_priority t` of a non-current thread from a `BlkOK` state is a `DM 0` step with `BlkOK` at + its end (P1's `sched.set_priority.dmK` with the label free: it writes no liveness word, `DM.ofNoneE`). +* **`armVsK_ofSusW0A`**: P1's `ArmVsK.ofSusW` at the state the footprint starts from (`R3` only gave `ksb s3 = ksb s0`). +* **`JStage3A.p1StepSusA`**: `JStage3A.p1StepA` over a `SusW` footprint (`K8` words, debug words, `RUN_VCPU` words). + +Named premises: [P] `ArchTotal`, `ArchPlat`. New module. +-/ +import Fl4ProofsA64.P3.Stage3P1StepA +import Fl4ProofsA64.P1.MdbPrioArm +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s s' : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 2000000 in +/-- **`set_priority` of a non-current thread is a `DM p` step for any `p`** (module docstring). -/ +theorem setPriority_dm0A {Cs : Set U64} {p : U64} (t prio : 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) (hv : prio.val < 256) + (hcur : t ≠ L.mem s (L.nodeAt s (L.cpu s) layout.node.CUR_THREAD)) + (hna : ∀ y ∈ H.tcbs, L.actionW s ≠ y) : + sched.set_priority st s t prio ⦃ s' => + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s' ∧ DM st H Cs p s s' ⦄ := by + have C := LvC.of_blk h + obtain ⟨⟨Q, R, q⟩, -⟩ := id h + refine WP.spec_mono (WP.spec_and (sched.set_priority.blk s t prio h ht hv + (fun e => absurd e hcur) (fun e => absurd e hcur) (fun e => absurd e hcur)) + (sched.set_priority.spk s t prio Q R q ht hv (fun e => absurd e hcur) hna)) ?_ + rintro s' ⟨⟨h', f, pf⟩, k⟩ + have f8 : K8.Foot st H.tcbs Cs H.frame H.scs H.scBits (EH H) s s' := + K8.Foot.ofQ C.tcb f fun y hy K h1 h2 h3 => + k.fld y hy K h1 h2 (by omega) (by omega) (by omega) (by omega) (by omega) (by omega) + have g : LvF st H.tcbs Cs H.replies H.scs H.ntfns LvX.none s s' := + ⟨f.1, f.2.1, pf.idle, fun c hc => by rw [nodeAt_of_ksb f.1]; exact k.hd c hc, + fun y hy K hK _ => k.fld y hy K hK.lt.1 hK.lt.2 (by unfold LvO at hK; omega) (by unfold LvO at hK; omega) + (by unfold LvO at hK; omega) (by unfold LvO at hK; omega) (by unfold LvO at hK; omega) + (by unfold LvO at hK; omega), + fun c hc o hO _ => pf.sig _ (C.sgC c hc o hO), fun n hn o hO _ => pf.sig _ (C.sgN n hn o hO), + fun r hr o hO _ => pf.sig _ (C.obj.rword hr hO.lt.1 hO.lt.2)⟩ + have M : EpM st H s s' := epS_mono h h' fun y hy _ => + ⟨pf.st y hy, k.fld y hy 3336#u64 (by simp) (by simp) (by simp) (by simp) (by simp) (by simp) (by simp) + (by simp)⟩ + exact ⟨h', DM.ofNoneE h h0 Y VR f8 g M⟩ + +set_option maxHeartbeats 4000000 in +/-- **`ArmVsK.ofSusW` at the state the footprint starts from** (module docstring). -/ +theorem armVsK_ofSusW0A {Cs Vc : Set U64} {Ub Pt : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} {Ac3 : Set U64} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hks : HeapKsOff H (L.ksb s)) + (hksw : (L.ksb s).val + 788736 ≤ 2 ^ 64) (hc0 : 0#u64 ∈ Cs) + (h3 : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac3 s) + (w : WritesIn st s s' (SusW st H Cs Vc s)) : + (∀ b, SusW st H Cs Vc s b → ¬ AsW (L.ksb s) b) ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' := by + obtain ⟨Q, Rq, q⟩ := h3.1 + have hSg := h3.2.2.2.2 + have hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt := I.del.vr + have F : TabF st H Cs OS s := TabF.of hvr q hksw hc0 + have k : OSKeep st OS s s' := OSKeep.of_in I.del.os w fun x hx b hb h1 h2 hF => by + rcases hF with (hk | hd | hv) | ⟨y, hy, e⟩ + · exact kw7_not_os (Es := EH H) q hSg.sub I.del.sca (fun _ he => he) hx hb h1 h2 (K8.KW.to7 hk) + · exact dbg_not_capw q hb hd + · exact I.del.vc.os b hv ⟨x, hx, h1, h2⟩ + · exact kw7_not_os (Es := EH H) q hSg.sub I.del.sca (fun _ he => he) hx hb h1 h2 + (Or.inl ⟨y, hy, 3672#u64, by simp, by simp, by simp, by simp, e⟩) + have hA : ∀ b, SusW st H Cs Vc s b → ¬ AsW (L.ksb s) b := fun b hd => by + rcases hd with (hd | hd | hv) | ⟨y, hy, e⟩ + · exact fun ha => K8.KW.notAsWE I.del.heap F hvr hks (fun _ he => he) (fun c hc => q.nodes c hc) hd ha + · intro ha + rcases hd with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ + · exact F.tcb I.del.heap hy (K := 3576#u64) (by simp) ha e.symm + · exact F.tcb I.del.heap hy (K := 3584#u64) (by simp) ha e.symm + · exact F.node rfl hc (q.nodes c hc) (by rw [debug_val]; omega) ha e.symm + · exact fun ha => hvr.vc b (Or.inr ha) hv + · exact fun ha => F.tcb I.del.heap hy (K := 3672#u64) (by simp) ha e.symm + exact ⟨hA, ArmVsK.ofFoot (Ko := ∅) I.del.heap q w (fun b hb => Or.inr (Or.inl (SusW.tk hb))) hA, k⟩ + +/-- **The P1 facts across a `SusW` `DMD` step from a record state** (module docstring; `JStage3A.p1StepA`'s body with +`armVsK_ofSusW0A` for the footprint facts). -/ +theorem JStage3A.p1StepSusA (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (w : WritesIn st s s' (SusW st H Z.Cs Z.V s)) + {p : U64} (d : DMD st H Z.Cs p s s') (hp : ∀ k, H p = some k → ∃ x ∈ OS, NamesA (capA st s x) p k) + {Ac' : Set U64} (hb : BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : + SysL st H Z.Cs OS ia ie s' ∧ SymL st H Z.Cs s' ∧ Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s' ∧ + BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s' ∧ + ∀ σ' m', J7A st (J7R2A st ar hPl.ipa) Z H OS s' σ' m' := by + obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits, KLv, W⟩ := J7A.unp J.j7 + have I := J.delIn hA hPl W + have kb : L.ksb s' = L.ksb s := w.1 + have SY : SysL st H Z.Cs OS ia ie s' ∧ SymL st H Z.Cs s' := + SysL.dfMDO I.del.heap I.del.os (BXI.blk J.sys.ent.bxi) I.del.sca hp J.sys.sysl d + obtain ⟨notAs, hvk, osk⟩ := armVsK_ofSusW0A I J.ko J.sys.ent.ksw J.core0 (BXI.blk J.sys.ent.bxi) w + obtain ⟨arm, tk⟩ := ArmQIAt.ofWK W.vr w notAs osk SY hb hvk.toVs + have Fx := S1aStepFix.ofKeep ⟨arm, tk.toDel, hvk, osk⟩ W.vr W.fu W.vcc W.col W.df W.r2 W.sep W.hiK + have pn : PoolNamed st OS s' := PoolNamed.ofTab kb tk.2 osk W.pn + have hsp : ∀ p, SchedPageA st Z OS s' p → p ∈ Pt := by + obtain ⟨_, -, -, -, ⟨_, _, _, _, _, _, _, R'⟩, -⟩ := id Fx + exact schedPage_ptA R' W.sp + refine ⟨SY.1, SY.2, J.sys.ent.user.ksb kb, BlkOK.bxi hb, fun σ' m' => ?_⟩ + exact J7A.of_stepFixedA Fx W.vr kb W.al W.vu pn hsp + (fun b hb o ho => by rw [kb]; exact W.ks b hb o ho) (J7R2K.of_stepFixedA (σ' := σ') (m := m') Fx W.ktK) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbSchedScA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbSchedScA.lean new file mode 100644 index 000000000..95d0c97a4 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbSchedScA.lean @@ -0,0 +1,273 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbsched): **the SC step of SetSchedParams with a changed SC**, at the record after +`set_priority`. + +`thread_control_sched` unbinds the target's SC (new SC null) or binds the new one after the fault handler, `set_mcp` and +`set_priority`; both start from the record at that state (`JStage3A.sspTailA`'s result), not the syscall entry. + +* `BodyOKA.ofScStepA`: `BodyOKA` across a budget-keeping SC step (`BKeepA`), from the record's `ScInvA` / `ZeroConsA` at + its end (`BodyEndA.ofCurBA` relative to a `BodyOKA` state instead of the entry record). +* `JStage3A.sspUnbindA`: `unbind_tcb` of the target's SC (a thread other than the caller): concrete and spec step, the + target's SC link read by the spec, and the record plus `BodyOKA` at the end given the P1 facts there. +* `JStage3A.sspBindA`: `bind_tcb` of an unbound target and an unbound SC, the same. + +Named premises: those of `JStage3A.scUnbindTcbA` / `scBindTcbA` ([P] `hmb`, [S] `h1`, `hCs`). New module. +-/ +import Fl4ProofsA64.P3.Stage3ScBindArmA +import Fl4ProofsA64.P3.ScBindTopA +import Fl4ProofsA64.P3.TcbInvokeSchedSelectA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +/-- A null-cap install is the deletion alone: neither the invoked slot nor the source slot matters. -/ +theorem fl4InstallTcbCap_nullA (t : ObjRef) (κ κ' a b : CslotPtr) (n : Nat) : + fl4InstallTcbCap (Z := Unit) t κ n (some (.nullCap, a)) = fl4InstallTcbCap t κ' n (some (.nullCap, b)) := by + unfold fl4InstallTcbCap + simp [NonDetE.unlessE] + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {s : S} {a : A} {σ σ4 : State Unit} {m : McState} + +/-- **The SC change `decode_update_sc` returns** for an old SC word `old` and a selected SC word `v`: none when equal, +else the new SC (`none` for a detach). -/ +def scUpdC (old v : U64) : Option (Option Fl4SpecA64.ObjRef) := + if old = v then none else some (if v = 0#u64 then none else some (specPtr v)) + +/-- **`BodyOKA` across a budget-keeping SC step** (module docstring). -/ +theorem BodyOKA.ofScStepA (B : BodyOKA σ m) (K : BKeepA σ σ4) (hinv : ScInvA m σ4) (hzc : ZeroConsA σ4) + (hsw : NoSwA σ4) (hb : CurBA σ4) + (hrun : σ4.schedulerAction = .resumeCurThread → ∀ x, σ4.kheap σ.curThread = some (.tcb x) → + x.tcbState = .running ∨ x.tcbState = .restart) : BodyOKA σ4 m := by + have hd : ∀ y' y : SchedContext, y'.scRefills = y.scRefills → refillHd y' = refillHd y := fun y' y e => by + unfold refillHd; rw [e] + have ha : ∀ y' y : SchedContext, y'.scRefillMax = y.scRefillMax → scActive y' = scActive y := fun y' y e => by + unfold scActive; rw [e] + refine ⟨⟨?_, fun y' k hk h1 h2 => ?_, fun h x hx => ?_⟩, fun u e => absurd e (hsw u), fun h => ?_, + fun y' k hk _ _ hc0 o ho => ?_⟩ + · have := B.validTime + unfold ValidMachineTimeA at this ⊢ + rw [K.time, K.ms]; exact this + · rw [K.csc] at hk + obtain ⟨y, hy, e1, e2⟩ := K.sc y' k hk + have h1' : σ.curSc = idleScPtr ∨ scActive y = true := by + rcases h1 with h | h + · exact Or.inl (K.csc ▸ h) + · exact Or.inr (by rw [← ha _ _ e2]; exact h) + have h2' : σ.consumedTime ≠ 0 ∨ σ.schedulerAction = .resumeCurThread := by + rcases h2 with h | h + · exact Or.inl (K.used ▸ h) + · exact Or.inr (K.act h) + obtain ⟨R, O⟩ := B.budget y k hy h1' h2' + constructor + · intro z j hz + rw [K.csc, hk] at hz + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + rw [hd _ _ e1, K.used, K.time] + exact R y k hy + · intro hpos z j hz hactive + rw [K.csc, hk] at hz + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + rw [hd _ _ e1, K.used, K.time] + rw [K.used] at hpos + refine O hpos y k hy fun h => ?_ + rw [← ha _ _ e2]; exact hactive (K.csc ▸ h) + · rcases hrun h x (K.ct ▸ hx) with h | h <;> rw [h] + · exact Or.inl rfl + · exact Or.inr (Or.inl rfl) + · rw [K.csc] at h ⊢; exact B.scNotIdle h + · obtain ⟨xb, hxb, hbs⟩ := hb + obtain ⟨y, j, hy, hyt⟩ := hinv.back _ _ _ hxb hbs + rw [hk] at hy + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hy) + rw [hyt] at ho + rw [← Option.some.inj ho] + exact fun hm => hc0 (hzc _ _ hxb hbs hm) + +/-- **`unbind_tcb` of the target's SC at the record** (module docstring). The target's SC word `old` is nonzero. -/ +theorem JStage3A.sspUnbindA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (sact : SActA σ) (nsw : NoSwA σ) (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) + (h1 : fl4A64Platform.numNodes = 1) (B : BodyOKA σ m) {t : U64} (ht : t ∈ Z.T) + (hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t) (htc : specPtr t ≠ σ.curThread) + (hold : L.mem s (scA t) ≠ 0#u64) (hcb : CurBA σ) + (hcr : ∀ x, σ.kheap σ.curThread = some (.tcb x) → x.tcbState = .running ∨ x.tcbState = .restart) : + ∃ s4 σ4, schedcontext.unbind_tcb st s (L.mem s (scA t)) = ok s4 ∧ + schedContextUnbindTcb (Z := Unit) (scNameA m (L.mem s (scA t))) σ = ({((), σ4)}, False) ∧ + (∃ y, σ.kheap (specPtr t) = some (.tcb y) ∧ y.tcbSchedContext = some (scNameA m (L.mem s (scA t)))) ∧ + σ4.curThread = σ.curThread ∧ + ∀ Ac', BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s4 → + SysL st H Z.Cs OS ia ie s4 → SymL st H Z.Cs s4 → Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s4 → + J7A st (J7R2A st ar nA) Z H OS s4 σ4 m → + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s4 a σ4 m ∧ BodyOKA σ4 m := by + have htH : t ∈ H.tcbs := by rw [J.tcbs]; exact ht + obtain ⟨x, hk, hxo⟩ := J.sr.sch.tcb t ht + obtain ⟨hiS, hit, -⟩ := (BXI.blk J.sys.ent.bxi).2.2.1.2.2.bound t htH hold + have hc : L.mem s (scA t) ∈ Z.C := by rw [← J.scs]; exact hiS + have hxsc : x.tcbSchedContext = some (scNameA m (L.mem s (scA t))) := by + rw [hxo, optScA, if_neg hold]; rfl + have hni : NotIdleScA m (scNameA m (L.mem s (scA t))) := + J.sr.inv.tcbScNotIdle _ x _ hk hxsc (fun c hcn e => hidles c (by + have h0n : 0 < n := lt_of_le_of_lt (Nat.zero_le _) J.sinv.mc.curCore_lt + rw [h1] at hcn + exact lt_of_lt_of_le hcn h0n) e.symm) + have ht0 : L.mem s (scTcbA (L.mem s (scA t))) ≠ 0#u64 := by + rw [hit]; exact (tcb_ne01Sc (J.sr.core.tcbs t ht)).1 + obtain ⟨s4, prog, σ4, Q, Rl, hspec, LI, NS, SV, hcur, OT, K⟩ := + exists_of_specA (J.scUnbindTcbA sact nsw hCs h1 hc hni ht0) + have hm : ((), σ4) ∈ (schedContextUnbindTcb (Z := Unit) (scNameA m (L.mem s (scA t))) σ).1 := by + rw [hspec]; exact rfl + have BK : BKeepA σ σ4 := + (inferInstance : KPresBInst (schedContextUnbindTcb (Z := Unit) (scNameA m (L.mem s (scA t))))).pres _ _ hm + obtain ⟨xc, hxc, hcs⟩ := hcb + have hxc4 : σ4.kheap σ.curThread = some (.tcb xc) := OT _ _ (by rw [hit]; exact Ne.symm htc) hxc + refine ⟨s4, σ4, prog, hspec, ⟨x, hk, hxsc⟩, hcur, fun Ac' bxi sysl symL userOK j7 => ?_⟩ + have J4 := K Ac' bxi sysl symL userOK j7 + refine ⟨Q, Rl, J4, BodyOKA.ofScStepA B BK J4.sr.inv J4.sinv.zc NS + ⟨xc, by rw [BK.ct]; exact hxc4, by rw [BK.csc]; exact hcs⟩ fun _ x' hx' => ?_⟩ + obtain rfl := KernelObject.tcb.inj (Option.some.inj (hxc4.symm.trans hx')) + exact hcr _ hxc + +/-- **`bind_tcb` of an unbound target and an unbound SC at the record** (module docstring). -/ +theorem JStage3A.sspBindA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (sact : SActA σ) (nsw : NoSwA σ) (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) + (h1 : fl4A64Platform.numNodes = 1) (hmb : sporadic.min_budget ar a ⦃ mb => mb.bv = MIN_BUDGET ⦄) + (B : BodyOKA σ m) {t sc : U64} (ht : t ∈ Z.T) (hc : sc ∈ Z.C) (hni : NotIdleScA m (scNameA m sc)) + (hidles : ∀ c < n, m.idleThreadOf c ≠ specPtr t) (htc : specPtr t ≠ σ.curThread) + (ht0 : L.mem s (scA t) = 0#u64) (hs0 : L.mem s (scTcbA sc) = 0#u64) (hcb : CurBA σ) + (hcr : ∀ x, σ.kheap σ.curThread = some (.tcb x) → x.tcbState = .running ∨ x.tcbState = .restart) + (hb : ∀ x y k, σ.kheap (specPtr t) = some (.tcb x) → σ.kheap (scNameA m sc) = some (.schedContext y k) → + ipcQueuedThreadState x.tcbState = true → scReleased σ.curTime y = true) : + ∃ s4 σ4, schedcontext.bind_tcb st ar s a sc t = ok (s4, a) ∧ + schedContextBindTcb (Z := Unit) (scNameA m sc) (specPtr t) σ = ({((), σ4)}, False) ∧ + σ4.curThread = σ.curThread ∧ + ∀ Ac', BXI st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s4 → + SysL st H Z.Cs OS ia ie s4 → SymL st H Z.Cs s4 → Fl4ProofsA64.P1.UserOK st H.tcbs Z.Cs H.omega H U s4 → + J7A st (J7R2A st ar nA) Z H OS s4 σ4 m → + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s4 a σ4 m ∧ BodyOKA σ4 m := by + have hti : specPtr t ≠ σ.idleThread := fun e => hidles m.curCore J.sinv.mc.curCore_lt (by + rw [show σ.idleThread = m.idleThreadOf m.curCore from J.sinv.view] at e; exact e.symm) + obtain ⟨xc, hxc, hcs⟩ := hcb + obtain ⟨⟨s4, a4⟩, prog, ea, σ4, Q, Rl, hspec, LI, NS, SV, RY, OT, K⟩ := + exists_of_specA (J.scBindTcbA sact nsw hCs h1 hmb hc ht hni hti hidles ht0 hs0 ⟨xc, hxc, hcs⟩ hb) + simp only at ea + subst a4 + have hm : ((), σ4) ∈ (schedContextBindTcb (Z := Unit) (scNameA m sc) (specPtr t) σ).1 := by + rw [hspec]; exact rfl + have BK : BKeepA σ σ4 := + (inferInstance : KPresBInst (schedContextBindTcb (Z := Unit) (scNameA m sc) (specPtr t))).pres _ _ hm + have hxc4 : σ4.kheap σ.curThread = some (.tcb xc) := OT _ _ (Ne.symm htc) hxc + refine ⟨s4, σ4, prog, hspec, BK.ct, fun Ac' bxi sysl symL userOK j7 => ?_⟩ + have J4 := K Ac' bxi sysl symL userOK j7 + refine ⟨Q, Rl, J4, BodyOKA.ofScStepA B BK J4.sr.inv J4.sinv.zc NS + ⟨xc, by rw [BK.ct]; exact hxc4, by rw [BK.csc]; exact hcs⟩ fun _ x' hx' => ?_⟩ + obtain rfl := KernelObject.tcb.inj (Option.some.inj (hxc4.symm.trans hx')) + exact hcr _ hxc + +/-- **What an accepted `sched_params_sc` says about the SC change** (module docstring): the null selection is for a thread +other than the caller; a selected SC `v` is a non-idle SC of the record that the target already holds, or that the target +may take (it has none, `v` has no thread), and a blocked target's wait is over (`v` released). -/ +theorem JSyscallA.scParamsFactsA + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {scSlot v t : U64} (htT : t ∈ Z.T) (hOS : scSlot ∈ OS) + (hsc : tcb.sched_params_sc st s t scSlot = ok (.Ok v)) : + (v = 0#u64 → t ≠ L.curW s) ∧ + (v ≠ 0#u64 → v ∈ Z.C ∧ NotIdleScA m (scNameA m v) ∧ ∃ z k, σ.kheap (scNameA m v) = some (.schedContext z k) ∧ + (L.mem s (scA t) = v ∨ (L.mem s (scA t) = 0#u64 ∧ z.scTcb = none)) ∧ + ∀ x, σ.kheap (specPtr t) = some (.tcb x) → ipcQueuedThreadState x.tcbState = true → + scReleased σ.curTime z = true) := by + obtain ⟨u, hk, hks⟩ := J.sr.sch.tcb t htT + have hold : obj.Tcb.sc st t s = ok (L.mem s (scA t)) := eq_of_spec_fd (obj.Tcb.sc.spec (L := L) s t) + have hbl := Sched.bind_isBlockedA (st := st) (J.stEqA _ htT u hk) + have hcapA : obj.Slot.cap st scSlot s = ok (capA st s scSlot) := capA_eq (st := st) s scSlot + by_cases h0 : capA st s scSlot = .Null + · rw [tcbSchedParamsSc_nullA (h0 ▸ hcapA)] at hsc + by_cases hc : t = L.curW s + · rw [if_pos hc] at hsc; cases ok_inj_ff hsc + · rw [if_neg hc] at hsc + have v0 : v = 0#u64 := (core.result.Result.Ok.inj (ok_inj_ff hsc)).symm + exact ⟨fun _ => hc, fun h => absurd v0 h⟩ + by_cases hS : ∃ p b, capA st s scSlot = .SchedContext p b + swap + · have hk' : ∀ p b, capA st s scSlot ≠ .SchedContext p b := fun p b c => hS ⟨p, b, c⟩ + rw [tcbSchedParamsSc_badCapA hcapA h0 hk'] at hsc + cases ok_inj_ff hsc + obtain ⟨p, b, hq⟩ := hS + have hH : H p = some (.sc b.val) := (J.capTy _ hOS).2.2.2.1 p b hq + have hp : p ∈ Z.C := by rw [← J.scs]; exact ⟨_, hH⟩ + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hci : specPtr p ≠ m.idleScOf m.curCore := T0.ciSc _ hOS p b hq + have hname : scNameA m p = specPtr p := by unfold scNameA; exact if_neg hci + have hni : NotIdleScA m (scNameA m p) := by + rw [hname] + refine ⟨J.sr.sch.scOff p hp hci, fun c hcN => ?_⟩ + have hcc : m.curCore = 0 := Nat.lt_one_iff.mp (lt_of_lt_of_eq (T0.curCore_lt hCs) h1) + have hc1 : c = 0 := Nat.lt_one_iff.mp (lt_of_lt_of_eq hcN h1) + rw [hc1.trans hcc.symm] + exact hci + obtain ⟨z, k, hz, hzr⟩ := J.sr.scr.sc p hp + have hrel := Sched.bind_scReleasedA J.sr.toSchedSRN hp hz + rw [tcbSchedParamsSc_contextA (show obj.Slot.cap st scSlot s = ok (.SchedContext p b) by rw [hcapA, hq]) hold] at hsc + have rel : (do + let blocked ← sched.is_blocked st s t + if blocked then + let released ← sporadic.sc_released st s p + if released then ok (.Ok p) else error.illegal obj.Sc + else ok (.Ok p)) = ok (core.result.Result.Ok v) → + v = p ∧ (ipcQueuedThreadState u.tcbState = true → scReleased σ.curTime z = true) := by + intro h + rw [hbl, bind_ok] at h + cases hb : ipcQueuedThreadState u.tcbState + · rw [hb] at h + simp only [Bool.false_eq_true, ite_false] at h + exact ⟨(core.result.Result.Ok.inj (ok_inj_ff h)).symm, fun c => absurd c Bool.false_ne_true⟩ + · rw [hb] at h + simp only [ite_true] at h + rw [hrel, bind_ok] at h + cases hrl : scReleased σ.curTime z + · rw [hrl] at h + simp only [Bool.false_eq_true, ite_false, error.illegal] at h + cases ok_inj_ff h + · rw [hrl] at h + simp only [ite_true] at h + exact ⟨(core.result.Result.Ok.inj (ok_inj_ff h)).symm, fun _ => rfl⟩ + have hvp : v = p ∧ (ipcQueuedThreadState u.tcbState = true → scReleased σ.curTime z = true) ∧ + (L.mem s (scA t) = p ∨ (L.mem s (scA t) = 0#u64 ∧ z.scTcb = none)) := by + by_cases h1' : L.mem s (scA t) = p + · rw [if_pos h1'] at hsc + exact ⟨(rel hsc).1, (rel hsc).2, Or.inl h1'⟩ + rw [if_neg h1'] at hsc + by_cases h2 : L.mem s (scA t) = 0#u64 + · rw [if_pos h2, show obj.Sc.tcb st p s = ok (L.mem s (scTcbA p)) from eq_of_spec_fd (obj.Sc.tcb.spec (L := L) s p), + bind_ok] at hsc + split at hsc + · rename_i hb0 + exact ⟨(rel hsc).1, (rel hsc).2, Or.inr ⟨h2, by rw [hzr.tcb, ← scTcbA_eqSc, hb0, optRefS_zero]⟩⟩ + · simp only [error.illegal] at hsc + cases ok_inj_ff hsc + · rw [if_neg h2] at hsc + simp only [error.illegal] at hsc + cases ok_inj_ff hsc + obtain ⟨vp, hB, hch⟩ := hvp + subst vp + refine ⟨fun h => absurd h (J.scNZ v hp), fun _ => ⟨hp, hni, z, k, hz, hch, fun x hx hq' => ?_⟩⟩ + rw [hk] at hx + obtain rfl := KernelObject.tcb.inj (Option.some.inj hx).symm + exact hB hq' + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbSetSpaceSelA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbSetSpaceSelA.lean new file mode 100644 index 000000000..10558ec80 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbSetSpaceSelA.lean @@ -0,0 +1,106 @@ +/- +P3 (aarch64, A64-P4 `tcbcfg`, CP2): **the actual SetSpace program after its decode**. + +* **`tcbSetSpace_selectedA`**: an accepted SetSpace (three extra slots, both roots derived, a valid fault handler) is + `tcb::thread_control_caps` with flags `SPACE | FAULT` at the restarted state. +* **`tcbCaps_space_{ok,pre3,pre0,pre1}A`**: that call's four outcomes from the results of its three installs (slot 3 fault + handler, slot 0 CSpace root, slot 1 VSpace root): all `Ok`, or the first preempted one. + +New module; no premise. +-/ +import Fl4ProofsA64.P3.Stage3TcbChainStartA +import Fl4ProofsA64.P3.TcbInvokeTimeoutA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Vcpu Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +theorem let_pair_eqA {α β γ : Type} (x : α) (y : β) (f : α → β → Result γ) : + (let (a, b) := (x, y); f a b) = f x y := rfl + +section +variable {S A : Type} {st : machine.Store S} {ar : machine.Arch A} [L : LawfulStore st] +variable {s sR : S} {a : A} {t fs cs vs cdata vdata : U64} {ctx : tcb.Ctx} {fh ccap vcap : capability.Cap} + +theorem tcbSetSpace_selectedA + (hSt : smp.remote_tcb_stall st ar s a t = ok (s, a)) + (he0 : tcb.extra_with_length ctx 0#usize 2#u64 = ok (.Ok fs)) + (he1 : tcb.extra_with_length ctx 1#usize 2#u64 = ok (.Ok cs)) + (he2 : tcb.extra_with_length ctx 2#usize 2#u64 = ok (.Ok vs)) + (hcd : tcb.arg st s ctx 0#u64 = ok cdata) (hvd : tcb.arg st s ctx 1#u64 = ok vdata) + (hRoots : tcb.derive_roots st s t cdata vdata cs vs = ok (.Ok (ccap, vcap))) + (hCap : obj.Slot.cap st fs s = ok fh) (hValid : faults.valid_fault_handler fh = ok true) + (hRestart : tcb.restart_caller st s = ok sR) : + tcb.decode st ar s a fl4_abi.label.TCBSetSpace t ctx = + tcb.thread_control_caps st ar sR a t ctx.slot (fh, fs) (capability.Cap.Null, 0#u64) (ccap, cs) (vcap, vs) 0#u64 + (capability.Cap.Null, 0#u64) (tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) := by + rw [tcbSetSpace_programA hSt] + simp only [tcb.decode_set_space, he0, he1, he2, hcd, hvd, hRoots, hCap, hValid, hRestart, bind_ok, + core.result.Result.Insts.CoreOpsTry.branch, ite_true, lift] + rfl + +theorem tcbFlagsSpaceA : + (((tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) &&& tcb.UPDATE_FAULT) != 0#u64) = true ∧ + (((tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) &&& tcb.UPDATE_TIMEOUT) != 0#u64) = false ∧ + (((tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) &&& tcb.UPDATE_SPACE) != 0#u64) = true ∧ + (((tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) &&& tcb.UPDATE_IPC_BUFFER) != 0#u64) = false := by + rw [tcb.UPDATE_SPACE, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_IPC_BUFFER] + decide + +variable {slot : obj.Slot} {c3 c0 c1 : capability.Cap} {src3 src0 src1 : obj.Slot} {target : obj.Tcb} + {s2 s4 s6 : S} {a1 a2 a3 : A} + +/-- All three installs succeed. -/ +theorem tcbCaps_space_okA + (h3 : tcb.install_tcb_cap st ar sR a target slot layout.tcb.SLOT_FAULT_HANDLER c3 src3 = ok (.Ok (), s2, a1)) + (h0 : tcb.install_tcb_cap st ar s2 a1 target slot layout.tcb.SLOT_CTABLE c0 src0 = ok (.Ok (), s4, a2)) + (h1 : tcb.install_tcb_cap st ar s4 a2 target slot layout.tcb.SLOT_VTABLE c1 src1 = ok (.Ok (), s6, a3)) : + tcb.thread_control_caps st ar sR a target slot (c3, src3) (capability.Cap.Null, 0#u64) (c0, src0) (c1, src1) 0#u64 + (capability.Cap.Null, 0#u64) (tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) = ok (.Ok (), s6, a3) := by + obtain ⟨f3, f4, f0, f5⟩ := tcbFlagsSpaceA + simp [tcb.thread_control_caps, lift, f3, f4, f0, f5, h3, h0, h1, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + +/-- The slot-3 install is preempted. -/ +theorem tcbCaps_space_pre3A + (h3 : tcb.install_tcb_cap st ar sR a target slot layout.tcb.SLOT_FAULT_HANDLER c3 src3 = ok (.Err .Preempted, s2, a1)) : + tcb.thread_control_caps st ar sR a target slot (c3, src3) (capability.Cap.Null, 0#u64) (c0, src0) (c1, src1) 0#u64 + (capability.Cap.Null, 0#u64) (tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) = ok (.Err .Preempted, s2, a1) := by + obtain ⟨f3, f4, f0, f5⟩ := tcbFlagsSpaceA + simp [tcb.thread_control_caps, lift, f3, f4, f0, f5, h3, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + +/-- The slot-0 install is preempted. -/ +theorem tcbCaps_space_pre0A + (h3 : tcb.install_tcb_cap st ar sR a target slot layout.tcb.SLOT_FAULT_HANDLER c3 src3 = ok (.Ok (), s2, a1)) + (h0 : tcb.install_tcb_cap st ar s2 a1 target slot layout.tcb.SLOT_CTABLE c0 src0 = ok (.Err .Preempted, s4, a2)) : + tcb.thread_control_caps st ar sR a target slot (c3, src3) (capability.Cap.Null, 0#u64) (c0, src0) (c1, src1) 0#u64 + (capability.Cap.Null, 0#u64) (tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) = ok (.Err .Preempted, s4, a2) := by + obtain ⟨f3, f4, f0, f5⟩ := tcbFlagsSpaceA + simp [tcb.thread_control_caps, lift, f3, f4, f0, f5, h3, h0, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + +/-- The slot-1 install is preempted. -/ +theorem tcbCaps_space_pre1A + (h3 : tcb.install_tcb_cap st ar sR a target slot layout.tcb.SLOT_FAULT_HANDLER c3 src3 = ok (.Ok (), s2, a1)) + (h0 : tcb.install_tcb_cap st ar s2 a1 target slot layout.tcb.SLOT_CTABLE c0 src0 = ok (.Ok (), s4, a2)) + (h1 : tcb.install_tcb_cap st ar s4 a2 target slot layout.tcb.SLOT_VTABLE c1 src1 = ok (.Err .Preempted, s6, a3)) : + tcb.thread_control_caps st ar sR a target slot (c3, src3) (capability.Cap.Null, 0#u64) (c0, src0) (c1, src1) 0#u64 + (capability.Cap.Null, 0#u64) (tcb.UPDATE_SPACE ||| tcb.UPDATE_FAULT) = ok (.Err .Preempted, s6, a3) := by + obtain ⟨f3, f4, f0, f5⟩ := tcbFlagsSpaceA + simp [tcb.thread_control_caps, lift, f3, f4, f0, f5, h3, h0, h1, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbSuspFrA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbSuspFrA.lean index 39cfd0d56..d2c2f5d45 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbSuspFrA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbSuspFrA.lean @@ -205,7 +205,7 @@ theorem suspend_footA (hP : IPlacedA N Z.T E R Bf) (P : IpcSchedPlacementA Z.th · rcases hK with rfl | rfl | rfl <;> simp refine ⟨RN0.frame hP.n (fun b hb hf => w.mem_eq hb fun h => notifFootOffMWrA H9 P.notification hf h) ⟨fun _ _ h => by rw [hkh]; exact h, fun _ z h => ⟨z, by rw [hkh]; exact h, rfl, rfl, rfl⟩⟩, - E0.frame PE (epFrameOfMcsA H9 P (σ := σ0) (σ' := σ0) ⟨w, SKeepA.refl _, SSzA.refl _⟩ rfl).1 KV, + E0.frame PE (epFrameOfMcsA H9 P (σ := σ0) (σ' := σ0) (MFrA.ofParts w (SKeepA.refl _) (SSzA.refl _)) rfl).1 KV, S0.frame (fun d hd => ?_) (fun c _ y k hy => ⟨y, k, by rw [hkh]; exact hy, rfl⟩) (fun d _ y hy => ⟨y, by rw [hkh] at hy; exact hy, rfl⟩), fun u hu y hy => ?_, fun u hu K hK => ?_, fun u hu => w.mem_eq (field_aligned (H9.core.tcbs u hu) (K := 3456#u64) (by decide) (by decide)) diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbSuspendArmA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbSuspendArmA.lean index 589eb0d7a..2ba737fd1 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbSuspendArmA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbSuspendArmA.lean @@ -7,6 +7,11 @@ P3 (aarch64, A64-P3 Stage 3, contract §94): **TCB Suspend at the record**, live facts (`SysL`, `SymL`, `J7A`) are `JSyscallA.decodeFinA`'s (its Suspend arm is P1's `suspendQAt`, which allows a live run), the loop facts `Std6A` and `SchedValidA` are `suspend_liveRecA`'s. +**tcbregr refactor**: the proof is `JSyscallA.suspendMidA`, which also exports the decode program's `hsus`, the spec +membership of the cancel+suspend and, when the target is not the caller, `SuspCallerA` (the caller's facts at the mid +state: its TCB still `Restart`, its SC word, its release flag and queue). `tcbSuspendA` is its corollary (statement +unchanged), the mid state starts the Send / Call tails of ReadRegisters with the suspension bit. + Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `hCs`, `hmb`, `hmax`, `htu`; [S] `h1` (`numNodes = 1`, the remote stall). New module. @@ -24,6 +29,7 @@ import Fl4ProofsA64.P3.Stage3SignalIdleA import Fl4ProofsA64.P3.Stage3DelAsmA import Fl4ProofsA64.P3.Stage3DelAsmTopA import Fl4ProofsA64.P3.TcbInvokeDispatchA +import Fl4ProofsA64.P3.Stage3SuspOffQA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -38,9 +44,20 @@ variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} +/-- **The caller's facts after `Restart` and the suspension of another thread** (module docstring). -/ +structure SuspCallerA (st : machine.Store S) [L : LawfulStore st] (σ σ2 : State Unit) (s s2 : S) (c0 : U64) + (xc : Fl4SpecA64.Tcb) : Prop where + tcb : σ2.kheap (specPtr c0) = some (.tcb { xc with tcbState := .restart }) + sc : L.mem s2 (scA c0) = L.mem s (scA c0) + iq : (L.mem s2 (inqA c0) &&& sched.Q_RELEASE) = 0#u64 + rq : specPtr c0 ∉ σ2.releaseQueue + noSw : ∀ u, σ2.schedulerAction ≠ .switchThread u + offq : OffQ0A (specPtr c0) σ2 + frames : ∀ p b sz, σ.kheap p = some (.archObj (.dataPage b sz)) → σ2.kheap p = some (.archObj (.dataPage b sz)) + set_option maxHeartbeats 4000000 in -/-- **TCB Suspend at a syscall entry** (module docstring). -/ -theorem JSyscallA.tcbSuspendA +/-- **TCB Suspend at a syscall entry, with the mid-state facts** (module docstring). -/ +theorem JSyscallA.suspendMidA (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) (hfm : A64FrameMasks st s) @@ -58,7 +75,11 @@ theorem JSyscallA.tcbSuspendA syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = ok (.Ok (), s2, a2) ∧ a2 = a ∧ ∃ Q Rl stack', JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack' κ n (J5A st) - (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m ∧ BodyEndA σ σ2 m := by + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m ∧ BodyEndA σ σ2 m ∧ + sched.suspend st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a t = ok (s2, a) ∧ + (∃ σx, fl4CancelRun (Z := Unit) (specPtr t) σ1 = ({((), σx)}, False) ∧ + Fl4SpecA64.suspend (Z := Unit) (specPtr t) σx = ({((), σ2)}, False)) ∧ + (t ≠ L.curW s → SuspCallerA st σ σ2 s s2 (L.curW s) xc) := by have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA obtain ⟨xc, hkc, hst, hsp, J1, -, osk0, -⟩ := J.toJStage3A.of_restartCurA @@ -101,7 +122,7 @@ theorem JSyscallA.tcbSuspendA exact (getCap_outA (c := c) (σ' := σ1) hg).2 obtain ⟨hti, hidles⟩ := JL.notIdle_of_capA JL.sinv.mc.curCore_lt hspec have key := JL.suspend_liveRecA (ar := ar) J1.schedValid R6 hCs h1 hmb hmax htu ht (fun _ _ => rfl) hti hidles - obtain ⟨⟨s2, a2⟩, hsus, ea, sc, σc, σ2, stk', Q, Rl, sp, -, -, -, F, osk, -, J2, sv2, k6⟩ := exists_of_specA key + obtain ⟨⟨s2, a2⟩, hsus, ea, sc, σc, σ2, stk', Q, Rl, sp, hcan, -, -, F, osk, -, J2, sv2, k6, KB⟩ := exists_of_specA key simp only at ea hsus osk J2 k6 subst a2 have hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = @@ -112,17 +133,21 @@ theorem JSyscallA.tcbSuspendA have hm : ((), σ2) ∈ ((fl4CancelRun (Z := Unit) (specPtr t) >>= fun _ => Fl4SpecA64.suspend (specPtr t)) σ1).1 := by rw [sp]; rfl -- the body-end facts: the cancel and the suspension are an `RsA` step, a `DelStepA` step + obtain ⟨⟨_, σx⟩, hcx, hsx⟩ := id hm + have K : DelStepA σ1 σ2 := by + have R1 : RsA σ1 σx := (fl4CancelRun_dlA (specPtr t) σ1 _ hcx).rs + have R2 : RsA σx σ2 := suspend_rsA (specPtr t) σx _ hsx + exact ((PreO.trans R1 R2).step JL.sinv.curSc).toDelStepA + have hdetx : fl4CancelRun (Z := Unit) (specPtr t) σ1 = ({((), σx)}, False) := (fl4CancelRun_detA JL ht hcx).1 + have eσ : σc = σx := congrArg Prod.snd (Set.mem_singleton_iff.1 (by rw [hdetx] at hcan; exact hcan)) + have hsuspx : Fl4SpecA64.suspend (Z := Unit) (specPtr t) σx = ({((), σ2)}, False) := by + rw [nd_bind_oneSc hdetx] at sp; exact sp have hBody : BodyEndA σ σ2 m := by - obtain ⟨⟨_, σx⟩, hc, hs⟩ := hm - have R1 : RsA σ1 σx := (fl4CancelRun_dlA (specPtr t) σ1 _ hc).rs - have R2 : RsA σx σ2 := suspend_rsA (specPtr t) σx _ hs - have K : DelStepA σ1 σ2 := (PreO.trans R1 R2).step JL.sinv.curSc obtain ⟨hB, hcur, -⟩ := BodyOKA.stepA (J.delRestartBodyA xc hkc).1 K exact ⟨hB, hcur⟩ have hspecI : (.ok [], σ2) ∈ ((fl4InvokeTcb (.suspend (specPtr t))).run σ1).1 := by - obtain ⟨⟨_, σx⟩, hc, hs⟩ := hm simp only [fl4InvokeTcb, invokeTcb] - exact mem_bindE_okD (mem_liftED hc) (mem_liftED (mem_bind_ndD hs rfl)) + exact mem_bindE_okD (mem_liftED hcx) (mem_liftED (mem_bind_ndD hsx rfl)) obtain ⟨-, -, sysl, symL, -, -, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) (by rw [hcap, hlbl]; simp [DecArmS1aEnt, DecArmQH]) @@ -135,9 +160,108 @@ theorem JSyscallA.tcbSuspendA have fx2 : DelCapFxA st Z H s2 := fx.keepA st J1.j5.2.1 fun y hy => osk.capA hy have J3 : JStage3TA st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stk' κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m := { J2 with j7 := j7 } - exact ⟨xc, σ1, σ2, s2, a, hkc, rfl, hsp, hspecI, hdec, rfl, Q, Rl, stk', + have Jmid : JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stk' κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m := J3.toJA sysl X.vcSym1 X.vcSym2 X.heapWin X.coresAll fx2.ptCapIn symL fx2.fhOK X.zwf sv2 X.utWin X.devWin X.vcBack - X.runBack X.vcSnap X.vcOS X.userFr X.frTh X.bfSpec, hBody⟩ + X.runBack X.vcSnap X.vcOS X.userFr X.frTh X.bfSpec + refine ⟨xc, σ1, σ2, s2, a, hkc, rfl, hsp, hspecI, hdec, rfl, Q, Rl, stk', Jmid, hBody, hsus, ⟨σx, hdetx, hsuspx⟩, fun hself => ?_⟩ + -- the caller's facts at the mid state + set c0 := L.curW s with hc0 + have ct : σ.curThread = specPtr c0 := J.j.1.sch.curThread + have hcZ : c0 ∈ Z.T := J.sr.curT + have hct : c0 ∈ H.tcbs := by rw [J.tcbs]; exact hcZ + have hne : specPtr t ≠ σ.curThread := fun e => hself (specPtr_inj (e.trans ct)) + have h10 : σ1.kheap σ.curThread = some (.tcb { xc with tcbState := .restart }) := by + simp only [hσ1, stUpdA, setObjA, Function.update_self] + have hx2 : σ2.kheap (specPtr c0) = some (.tcb { xc with tcbState := .restart }) := by + rw [← ct]; exact KB.tcbEq _ _ hne.symm h10 + have hrq1 : specPtr c0 ∉ σ1.releaseQueue := by + show specPtr c0 ∉ σ.releaseQueue + rw [J.j.1.rest.rel]; intro hm' + obtain ⟨q, hq, eq⟩ := List.mem_map.1 hm' + have e' : q = c0 := specPtr_inj eq + subst e' + have haf := J.sq.inR _ J.sq.cur _ hq + exact ((J.sq.released _ (by rw [J.tcbs]; exact hcZ)).2 (by rw [haf]; exact hq)) RS.cur.1 + have hrq2 : specPtr c0 ∉ σ2.releaseQueue := fun h => hrq1 (K.rel _ h) + have hscx : xc.tcbSchedContext = optScA m (L.mem s (scA c0)) := by + obtain ⟨z, hz, -, hsx0⟩ := J.j.1.sch.tcb c0 hcZ + rw [← ct, hkc] at hz; cases hz + exact hsx0 + have hsc2 : L.mem s2 (scA c0) = L.mem s (scA c0) := by + obtain ⟨z, hz, -, hsx2⟩ := Jmid.j.1.sch.tcb c0 hcZ + rw [hx2] at hz; cases hz + have hw0 := RS.cur.2.1 + have e : optScA m (L.mem s2 (scA c0)) = optScA m (L.mem s (scA c0)) := by + rw [← hsx2]; exact hscx + have hw20 : L.mem s2 (scA c0) ≠ 0#u64 := fun h0 => by + rw [h0] at e; unfold optScA at e; rw [if_pos rfl, if_neg hw0] at e; cases e + unfold optScA at e + rw [if_neg hw20, if_neg hw0] at e + have hC := J.j.1.rest.scMem c0 hcZ hw0 + have hC2 := Jmid.j.1.rest.scMem c0 hcZ hw20 + exact scRenA_inj m (J.j.1.sch.scOff _ hC2) (J.j.1.sch.scOff _ hC) (Option.some.inj e) + have hiq2 : (L.mem s2 (inqA c0) &&& sched.Q_RELEASE) = 0#u64 := by + by_contra hne0 + have hm' := (Jmid.sq.released c0 (by rw [Jmid.tcbs]; exact hcZ)).1 hne0 + have haf : L.mem s2 (affA c0) = L.cpu s2 := by + have a1 := hCs _ (Jmid.sq.aff c0 (by rw [Jmid.tcbs]; exact hcZ)) + have b1 := hCs _ Jmid.sq.cur + rw [h1] at a1 b1 + exact UScalar.eq_of_val_eq (by simp at a1 b1; omega) + rw [haf] at hm' + apply hrq2 + rw [Jmid.j.1.rest.rel] + exact List.mem_map_of_mem hm' + have noSw2 : ∀ u, σ2.schedulerAction ≠ .switchThread u := fun u e => by + rcases K.act with h | h + · exact noSw u (h.symm.trans e) + · rw [h] at e; cases e + have offq1 : OffQ0A (specPtr c0) σ1 := + ⟨fun d p => by rw [← ct]; exact J1.sinv.ctQ J.act d p, hrq1, + fun u e => absurd e (noSw u)⟩ + have hq1 := fl4CancelRun_sameQ JL ht hcx + have offqx : OffQ0A (specPtr c0) σx := offq1.congr hq1.1 hq1.2.1 hq1.2.2.1 + have offq2 : OffQ0A (specPtr c0) σ2 := + suspend_off0 (specPtr c0) (specPtr t) σx offqx ((), σ2) (by rw [hsuspx]; exact Set.mem_singleton _) + have hfr : ∀ p b sz, σ.kheap p = some (.archObj (.dataPage b sz)) → σ2.kheap p = some (.archObj (.dataPage b sz)) := by + intro p b sz hp + have hpc : p ≠ σ.curThread := fun c => by rw [c, hkc] at hp; cases hp + have h1 : σ1.kheap p = some (.archObj (.dataPage b sz)) := by + simp only [hσ1, stUpdA, setObjA, Function.update_of_ne hpc]; exact hp + have h2 := hq1.2.2.2 p b sz h1 + rcases (eσ ▸ F : SchedFrameA σx σ2).1.kh p with e | ⟨x, x', e1, -⟩ | ⟨o, o', e1, e2, hs⟩ + · rw [e]; exact h2 + · rw [h2] at e1; cases e1 + · rw [h2] at e1; cases e1 + rcases hs with ⟨_, _, _, _, e, _⟩ | ⟨_, _, e, _⟩ | ⟨_, _, e, _⟩ | ⟨_, _, e, _⟩ <;> cases e + exact ⟨hx2, hsc2, hiq2, hrq2, noSw2, offq2, hfr⟩ + +set_option maxHeartbeats 4000000 in +/-- **TCB Suspend at a syscall entry** (module docstring). -/ +theorem JSyscallA.tcbSuspendA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + (hmb : ∀ a, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) + (hmax : maxTicksToUs = core.num.U64.MAX.bv) + (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) + {slot lbl len buf t : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSuspend) : + ∃ xc σ1 σ2 s2 a2, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ2) ∈ ((fl4InvokeTcb (.suspend (specPtr t))).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, a2) ∧ a2 = a ∧ + ∃ Q Rl stack', JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack' κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m ∧ BodyEndA σ σ2 m := by + obtain ⟨xc, σ1, σ2, s2, a2, h1', h2', h3', h4', h5', h6', Q, Rl, stk', Jm, hB, -⟩ := + J.suspendMidA hA hM hPl hfm hCs h1 hmb hmax htu hslot hcov hcap hext hSC hlbl (blk := blk) (call := call) + (don := don) (len := len) (buf := buf) + exact ⟨xc, σ1, σ2, s2, a2, h1', h2', h3', h4', h5', h6', Q, Rl, stk', Jm, hB⟩ end diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbTimerA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbTimerA.lean new file mode 100644 index 000000000..8e8443518 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbTimerA.lean @@ -0,0 +1,122 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbtimer): **TCB SetTimer at the record**. + +* **`JSyscallA.setTimerA`**: `decode_invocation` on a Thread cap with the `TCBSetTimer` label at a syscall entry: the + caller's `Restart`, then `timer.insert target deadline badge` (`tcb::decode`; no reply, no `Running`). The spec is + `invokeFl4Tcb (.setTimer ..)` (`fl4SetTcbTimer` on the queue read from the tree), whose only visible effect is + `reprogramTimer := reprogramTimer || earliest`; the record follows `JStage3A.rec_tdrA` + (`Stage3TcbTimerRecA`: the timer words and the current core's `REPROGRAM` word). + +Named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat`, `A64FrameMasks`, `hCs`; [S] `h1` (`numNodes = 1`: the remote +stall is a no-op and a previously armed target is owned by the current core). The timer-tree invariant comes from +the record (`BlkOK`, `TInv.rb`); `TimerRB` needs no new field. The decode succeeds (`2 ≤ len`); the `Err` returns are +not lifted. New module. +-/ +import Fl4ProofsA64.P3.Stage3TcbTimerRecA +import Fl4ProofsA64.P3.TcbInvokeTimerSpecA +import Fl4ProofsA64.P3.Stage3TcbTlsA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif + Fl4ProofsA64.P3.Sched Fl4SpecA64 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 4000000 in +/-- **TCB SetTimer at a syscall entry** (module docstring). -/ +theorem JSyscallA.setTimerA + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + (hCs : ∀ c ∈ Z.Cs, c.val < fl4A64Platform.numNodes) (h1 : fl4A64Platform.numNodes = 1) + {slot lbl len buf t d bd : U64} {blk call don : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hcap : capA st s slot = .Thread t) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (hlbl : lbl = fl4_abi.label.TCBSetTimer) (hlen : ¬ len < 2#u64) + (hd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 0#u64 = ok d) + (hbd : tcb.arg st s ⟨len, buf, call, slot, extra⟩ 1#u64 = ok bd) : + ∃ xc σ1 σ2 s2, σ.kheap σ.curThread = some (.tcb xc) ∧ σ1 = stUpdA σ σ.curThread xc .restart ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (.ok [], σ2) ∈ ((invokeFl4Tcb (.setTimer (specPtr t) d.bv bd.bv)).run σ1).1 ∧ + syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, a) ∧ + ∃ Q Rl, JStage3A st AR { Z with Q := Q, R := Rl } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar hPl.ipa)) s2 a σ2 m ∧ Sched.BodyEndA σ σ2 m := by + have RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM := J.toJStage3EntryA.curNotVmA + obtain ⟨xc, hkc, hst, hsp, J1, -, -, -⟩ := J.toJStage3A.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS.sym RS.run hnvm RS.cur RS.vs RS.vc + have ht : t ∈ Z.T := J.tcbs ▸ (J.toJStage3A.slotCapTy hslot).1.2.2.2.2.2 t hcap + have T0 := J.toJStage3A.toTA J.sact J.noSwitch + have hstall : smp.remote_tcb_stall st ar s a t = ok (s, a) := T0.stall_singleA hCs h1 ht + set s1 := L.wr s (stA (L.curW s)) sched.TS_RESTART with hs1 + set σ1 := stUpdA σ σ.curThread xc .restart with hσ1 + have hr : tcb.restart_caller st s = ok s1 := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok, hst] + have htT : t ∈ H.tcbs := by rw [J1.tcbs]; exact ht + have blk1 := J1.blkA + have hcpu : L.cpu s1 ∈ Z.Cs := J1.sr.sch.cpuCs + have hT := TInv.tcbs blk1 + have hR := TInv.rb blk1 + have hN := TInv.nodes blk1 + obtain ⟨W, hW⟩ := hR.tree (L.cpu s1) hcpu + have hlocal : L.mem s1 (tdA t) ≠ 0#u64 → (L.mem s1 (thA t)).val >>> 8 = (L.cpu s1).val := by + intro hne + obtain ⟨c, hc, W', hW', hyW⟩ := hR.armed t htT hne + rw [hW'.core t hyW] + have e1 := hCs c hc + have e2 := hCs (L.cpu s1) hcpu + rw [h1] at e1 e2 + omega + have both := WP.spec_and (timer.insert.foot s1 t d bd blk1 htT) + (tcbTimerInsert_queueA (T := H.tcbs) (Cs := Z.Cs) s1 t d bd hT htT hR hN hcpu hW hlocal) + obtain ⟨s2, hins, ⟨blk2, -, w0, -⟩, hStore⟩ := exists_of_specA both + have hdec : syscall.decode_invocation st ar s a lbl len slot (capA st s slot) blk call don false buf extra = + ok (.Ok (), s2, a) := by + rw [hcap, decodeTcb_programA, if_neg Bool.false_ne_true, hlbl, + Fl4ProofsA64.P1.decode_set_timer ar hstall hlen] + simp only [hd, hbd, hr, bind_ok, hins] + -- the spec: the reprogram bit + set pb : Bool := decide (L.mem s2 (L.nodeAt s1 (L.cpu s1) layout.node.REPROGRAM) ≠ 0#u64) with hpbd + have hprog : σ1.reprogramTimer = decide (L.mem s1 (L.nodeAt s1 (L.cpu s1) layout.node.REPROGRAM) ≠ 0#u64) := + J1.sr.rest.repr + have hbit : pb = (σ1.reprogramTimer || + (fl4SetTcbTimer (tcbTimerQueueOfA st s1 W) (specPtr t) d.bv bd.bv).2) := by + have e := hStore.reprogram + rw [nodeAt_of_ksb w0.1] at e + rw [hpbd, e, timerReprogram_wordA, hprog] + have hspec : (.ok [], { σ1 with reprogramTimer := pb }) ∈ + ((invokeFl4Tcb (.setTimer (specPtr t) d.bv bd.bv)).run σ1).1 := by + rw [hbit] + exact tcbSetTimer_specA σ1 (specPtr t) d.bv bd.bv (tcbTimerQueueOfA st s1 W) + obtain ⟨-, -, sysl, symL, -, userOK, j7⟩ := J.decodeFinA hA hM hPl hfm hslot hcov + (rfl : capA st s slot = capA st s slot) hext hSC (lbl := lbl) + (by rw [hcap, hlbl]; exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨t, rfl, Or.inr (Or.inl rfl)⟩))))))) + (fun _ h => by rw [hcap] at h; cases h) (fun _ h => by rw [hcap] at h; cases h) hdec + { σ1 with reprogramTimer := pb } m + rw [J1.tcbs] at w0 + have w0' : WritesIn st s1 s2 (TDRA st Z s1) := w0.mono fun b hb => by + rcases hb with (⟨y, hy, K, k1, k2, e⟩ | ⟨c, hc, o, ho, e⟩) | e + · exact Or.inl (Or.inl ⟨y, hy, K, k1, by omega, e⟩) + · exact Or.inl (Or.inr ⟨c, hc, o, by omega, e⟩) + · exact Or.inr e + have J2 := J1.rec_tdrA blk2 w0' (pb := pb) hpbd sysl symL + exact ⟨xc, σ1, _, s2, hkc, rfl, hsp, hspec, hdec, Z.Q, Z.R, J2, + Sched.BodyEndA.ofKeep J hkc + ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, fun _ _ _ h => h, fun _ x h => ⟨x, h, rfl⟩⟩⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbTimerRecA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbTimerRecA.lean new file mode 100644 index 000000000..0d4855b68 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbTimerRecA.lean @@ -0,0 +1,281 @@ +/- +P3 (aarch64, A64-P3 Stage 4, tcbtimer): **the record across `timer.insert`** (TCB SetTimer). + +FL4's TCB timers have no spec counterpart (`Ext/Timer`), but `timer.insert t d bd` also writes the current core's +`REPROGRAM` word, and the spec's `reprogramTimer` bit mirrors it (`SchedSRA`'s `repr`). +`timer.insert.foot` (P1) puts the writes in `TW` and the current core's `REPROGRAM` word. + +* `TDRA`: the `TDWA` words and the current core's `REPROGRAM` word (`RPWA`). +* `JStage3A.td_*A`: a `TDRA` word misses every word the record reads other than the three node words + (the `tw_*A` of `Stage3FireTwinsA` and the `rp_*A` of `Stage3FireReprA`, combined). +* `JStage3A.sr_tdrA`: `SchedSRA` across `TDRA` writes with the spec's `reprogramTimer := pb`, `pb` the new word's bit + (`SchedSRN.rebuildG` with the explicit `hrepr`). +* `JStage3A.rec_tdrA`: the record across `TDRA` writes, given P1's `BlkOK` at the end; the spec state is + `{ σ with reprogramTimer := pb }`. + +No new premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3FireTwinsA +import Fl4ProofsA64.P3.Stage3FireReprA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4Spec Fl4SpecA64 Fl4ProofsA64.P3.Endp +open Fl4ProofsA64.P3.Sched Fl4ProofsA64.P3.Notif + +local notation "wa" => core.num.U64.wrapping_add + +noncomputable section + +/-- The timer and debug-list words together with the current core's `REPROGRAM` word. -/ +def TDRA {S : Type} (st : machine.Store S) [L : LawfulStore st] (Z : XSetsA) (s : S) (b : U64) : Prop := + TDWA st Z s b ∨ RPWA st s b + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {ar : machine.Arch A} {nA : U64} {s s' : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + +section +variable (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) +include J + +theorem JStage3A.td_tcbA {b : U64} (hb : TDRA st Z s b) {u : U64} (hu : u ∈ Z.T) (h1 : u.val ≤ b.val) + (h2 : b.val < u.val + 3528 ∨ (u.val + 3592 ≤ b.val ∧ b.val < u.val + 4096)) : False := by + rcases hb with hb | hb + · exact J.tw_tcbA hb hu h1 h2 + · exact J.rp_tcbA hb hu h1 (by omega) + +theorem JStage3A.td_tcbKA {u : U64} (hu : u ∈ Z.T) {K : U64} (hK : K.val < 4096) (hK' : K.val < 3528 ∨ 3592 ≤ K.val) + (hb : TDRA st Z s (wa u K)) : False := by + rcases hb with hb | hb + · exact J.tw_tcbKA hu hK hK' hb + · exact J.rp_tcbKA hu hK hb + +theorem JStage3A.td_ipcA {b : U64} (hb : TDRA st Z s b) (h : IpcObjWA N E Rp b) : False := by + rcases hb with hb | hb + · exact J.tw_ipcObjA hb h + · exact J.rp_ipcA hb h + +theorem JStage3A.td_bufA {b : U64} (hb : TDRA st Z s b) (h : BufW Bf b) : False := by + rcases hb with hb | hb + · exact J.tw_bufA hb h + · exact J.rp_bufA hb h + +theorem JStage3A.td_ksLowA {b : U64} (hb : TDRA st Z s b) (h1 : (L.ksb s).val ≤ b.val) + (h2 : b.val < (L.ksb s).val + 223488) : False := by + rcases hb with hb | hb + · exact J.tw_ksLowA hb h1 h2 + · have := J.rp_valA hb + omega + +theorem JStage3A.td_scA {b : U64} (hb : TDRA st Z s b) (h : ScFootA Z.C m σ b) : False := by + rcases hb with hb | hb + · exact J.tw_scA hb h + · have hksz : ksSizeA = 788736 := rfl + have := J.sr.scp.ks_out h + have := J.rp_valA hb + omega + +theorem JStage3A.td_nodeA {b : U64} (hb : TDRA st Z s b) {c o : U64} (hc : c ∈ Z.Cs) (ho : o.val < 4288) + (h0 : o.val ≠ 88) (h1 : o.val ≠ 104) (h2 : o.val ≠ 112) (h3 : o.val ≠ 56) (e : b = L.nodeAt s c o) : False := by + rcases hb with hb | hb + · exact J.tw_nodeA hb hc ho h0 h1 h2 e + · obtain ⟨nn, -, hn, hcs⟩ := J.sr.csN + have hcl : c.val < 128 := by have := (hcs c).1 hc; omega + have hcl2 : (L.cpu s).val < 128 := by have := (hcs (L.cpu s)).1 J.sr.sch.cpuCs; omega + have hr56 : layout.node.REPROGRAM.val = 56 := by simp [layout.node.REPROGRAM] + have hv := nodeAt_valSc (s := s) J.sr.ksFit hcl ho + have hv2 := nodeAt_valSc (s := s) J.sr.ksFit hcl2 (o := layout.node.REPROGRAM) (by omega) + have ee : L.nodeAt s c o = L.nodeAt s (L.cpu s) layout.node.REPROGRAM := e.symm.trans hb + have := congrArg UScalar.val ee + omega + +end + +set_option maxHeartbeats 2000000 in +/-- **`SchedSRA` across `TDRA` writes** (module docstring). -/ +theorem JStage3A.sr_tdrA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {pb : Bool} (w : WritesIn st s s' (TDRA st Z s)) + (hpb : pb = decide (L.mem s' (L.nodeAt s (L.cpu s) layout.node.REPROGRAM) ≠ 0#u64)) : + SchedSRA st Z m κ s' { σ with reprogramTimer := pb } := by + have H := J.sr + have kp : ∀ b, Aligned b → (TDRA st Z s b → False) → L.mem s' b = L.mem s b := + fun b hb hn => w.mem_eq hb hn + have tK : ∀ t ∈ Z.T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → (K.val < 3528 ∨ 3592 ≤ K.val) → + L.mem s' (wa t K) = L.mem s (wa t K) := fun t ht K h1 h8 h2 => + kp _ (field_aligned (H.core.tcbs t ht) h1 h8) (J.td_tcbKA ht h1 h2) + have nK : ∀ c ∈ Z.Cs, ∀ o : U64, o.val < 4288 → o.val % 8 = 0 → o.val ≠ 88 → o.val ≠ 104 → o.val ≠ 112 → + o.val ≠ 56 → L.mem s' (L.nodeAt s c o) = L.mem s (L.nodeAt s c o) := + fun c hc o ho h8 h0 h1 h2 h3 => kp _ (nodeAt_aligned (H.core.nodes c hc) ho h8) fun hb => + J.td_nodeA hb hc ho h0 h1 h2 h3 rfl + have hkb := H.ksb_al + have hf := H.ksFit + have gK : ∀ K : U64, (K = 8#u64 ∨ K = 16#u64) → L.mem s' (wa (L.ksb s) K) = L.mem s (wa (L.ksb s) K) := by + intro K hK + have hK' : K.val = 8 ∨ K.val = 16 := by rcases hK with rfl | rfl <;> simp + have hv : (wa (L.ksb s) K).val = (L.ksb s).val + K.val := by rw [wa_valm]; unfold ksSizeA at hf; omega + exact kp _ (by unfold Aligned; rw [hv]; omega) fun hb => J.td_ksLowA hb (by omega) (by omega) + have scK : ∀ b, Aligned b → ScFootA Z.C m σ b → L.mem s' b = L.mem s b := + fun b hb hs => kp b hb fun h => J.td_scA h hs + have hcore : SchedCoreA st Z.T Z.Cs s' Z.Q Z.R := + H.core.agree w.1 (fun y hy => ⟨tK y hy 3480#u64 (by simp) (by simp) (by simp), + tK y hy 3488#u64 (by simp) (by simp) (by simp)⟩) + (fun c hc o h1 h2 h3 => nK c hc o h1 h2 (by omega) (by omega) (by omega) (by omega)) + (fun y hy => tK y hy 3592#u64 (by simp) (by simp) (by simp)) + (fun y hy => tK y hy 3520#u64 (by simp) (by simp) (by simp)) + (fun y hy => tK y hy 3448#u64 (by simp) (by simp) (by simp)) + have e3464 : ∀ t ∈ Z.T, L.mem s' (scA t) = L.mem s (scA t) := + fun t ht => tK t ht 3464#u64 (by simp) (by simp) (by simp) + refine ⟨H.toSchedSRN.rebuildG (Q' := Z.Q) (R' := Z.R) w.1 w.2.1 + (fun c hc o h1 h2 _ e56 => nK c hc o (by omega) h2 (by omega) (by omega) (by omega) e56) gK + (fun t ht K hK => by + rcases hK with rfl | rfl | rfl + · exact tK t ht _ (by simp) (by simp) (by simp) + · exact tK t ht _ (by simp) (by simp) (by simp) + · exact tK t ht _ (by simp) (by simp) (by simp)) + (H.scr.frame scK (fun _ _ => rfl)) (ScPlacedA.of_kheap H.scp (fun _ _ => rfl)) (fun t ht x hx => ⟨x, hx, rfl, rfl⟩) + (fun t ht => by + obtain ⟨x, h1, h3⟩ := H.sch.tcb t ht + exact ⟨x, h1, by rw [e3464 t ht]; exact h3⟩) + (fun t ht h => by + rw [e3464 t ht] at h ⊢ + exact H.rest.scMem t ht h) + (SFixA.refl σ) hpb ?_ H.actOn (H.inv.of_kheap rfl rfl) hcore H.rest.rq H.rest.rqDom H.rest.rel H.run + (fun c hc => scK _ (H.scCoreFoot hc).1 (H.scCoreFoot hc).2), H.rd⟩ + · rw [nK _ H.sch.cpuCs layout.node.SCHED_ACTION (by simp [layout.node.SCHED_ACTION]) + (by simp [layout.node.SCHED_ACTION]) (by simp [layout.node.SCHED_ACTION]) (by simp [layout.node.SCHED_ACTION]) (by simp [layout.node.SCHED_ACTION]) (by simp [layout.node.SCHED_ACTION])] + exact H.sch.act + +set_option maxHeartbeats 2000000 in +/-- **The record across `TDRA` writes** (module docstring). -/ +theorem JStage3A.rec_tdrA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {pb : Bool} (blk' : BlkOK st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s') + (w0 : WritesIn st s s' (TDRA st Z s)) + (hpb : pb = decide (L.mem s' (L.nodeAt s (L.cpu s) layout.node.REPROGRAM) ≠ 0#u64)) + (sysl : SysL st H Z.Cs OS ia ie s') (symL : SymL st H Z.Cs s') : + JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s' a + { σ with reprogramTimer := pb } m := by + have H2 : SchedSRA st Z m κ s' { σ with reprogramTimer := pb } := J.sr_tdrA w0 hpb + have hP := J.iplaced + have kp : ∀ b, Aligned b → (TDRA st Z s b → False) → L.mem s' b = L.mem s b := + fun b hb hn => w0.mem_eq hb hn + have tK : ∀ u ∈ Z.T, ∀ K : U64, K.val < 4096 → K.val % 8 = 0 → (K.val < 3528 ∨ 3592 ≤ K.val) → + L.mem s' (wa u K) = L.mem s (wa u K) := fun u hu K h1 h8 h2 => + kp _ (field_aligned (J.sr.core.tcbs u hu) h1 h8) (J.td_tcbKA hu h1 h2) + have w : WritesIn st s s' (SchedStepNWA (st := st) N E Rp Z m σ s) := w0.mono fun b hb => by + rcases hb with (⟨y, hy, K, k1, k2, rfl⟩ | ⟨c, hc, o, ho, rfl⟩) | hb + · have hfit := (J.sr.core.tcbs y hy).fits + have hv : ∀ K' : U64, K'.val < 4096 → (wa y K').val = y.val + K'.val := fun K' h => by + rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) + have v1 := hv K (by omega) + have v2 := hv 3664#u64 (by simp) + have v3 := hv 3672#u64 (by simp) + have c1 : (3664#u64 : U64).val = 3664 := by simp + have c2 : (3672#u64 : U64).val = 3672 := by simp + refine Or.inl (Or.inr ⟨y, hy, by omega, by omega, fun e => ?_, fun e => ?_⟩) + · have := congrArg UScalar.val e + omega + · unfold runVcpuA at e + have := congrArg UScalar.val e + omega + · exact Or.inl (Or.inl (Or.inr (Or.inl (J.sr.node_sks hc (by omega))))) + · rw [hb] + exact Or.inl (Or.inl (Or.inr (Or.inl (J.sr.node_sks J.sr.sch.cpuCs (by simp [layout.node.REPROGRAM]))))) + have kb : L.ksb s' = L.ksb s := w.1 + have HS : SpecSchedA σ { σ with reprogramTimer := pb } := + ⟨fun _ => Or.inl rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ + have SSz : SSzA σ { σ with reprogramTimer := pb } := SSzA.refl σ + have rv : RvSt st Z.T s s' := fun y hy => + ⟨by rw [stA_eq]; exact tK y hy _ (by simp) (by simp) (by simp), + by unfold runVcpuA; exact tK y hy _ (by simp) (by simp) (by simp)⟩ + have rv' : RunVcpuInv st Z.T s' := J.runVcpu.rvSt rv + have sq : SchedQueuesInv st H.tcbs Z.Cs H.omega H s' Z.Q Z.R := by + obtain ⟨Q0, R0, h⟩ := blk'.1 + exact SchedQueuesInv.reQA h (by rw [J.tcbs]; exact H2.core) + have poolOff : PoolOff st H Z.Cs OS s' := fun i => by + have h0 := J.poolOff i + rw [vspace.asid_table.eq] at h0 ⊢ + have v := AtOff.v i + have hks : (L.ksb s).val + 788736 ≤ 2 ^ 64 := J.sys.ent.ksw + have ev : (wa (L.ksb s) (AtOff i)).val = (L.ksb s).val + (AtOff i).val := by + rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) + have e : L.mem s' (wa (L.ksb s') (AtOff i)) = L.mem s (wa (L.ksb s) (AtOff i)) := by + rw [kb] + refine w.mem_eq ?_ (J.asid_offStepNA (by omega) (by omega)) + have h32 := J.j.1.ksbAl + show (wa (L.ksb s) (AtOff i)).val % 8 = 0 + omega + rw [e] + refine (WP.spec_ok _).2 fun hne asid => ?_ + have q := (WP.spec_ok _).1 h0 hne asid + exact ⟨q.al, q.om, q.sg, q.os, RegionOffNodes.ksb kb q.ks⟩ + have ep : EpStateRel Z.T E Rp Bf (L.mem s') { σ with reprogramTimer := pb } := by + refine J.ep.frame hP.e (fun b hb hf => kp b hb fun htw => ?_) + ⟨fun p x hk => hk, fun p x hk => ⟨x, hk, rfl⟩, fun p x hk => ⟨x, hk, rfl, rfl, rfl, rfl, rfl⟩, rfl⟩ + rcases hf with ⟨e, he, h⟩ | ⟨r, hr, h⟩ | ⟨u, hu, ⟨h1, h2⟩ | h⟩ | h + · exact J.td_ipcA htw (Or.inr (Or.inl ⟨e, he, by omega, by omega⟩)) + · exact J.td_ipcA htw (Or.inr (Or.inr ⟨r, hr, by omega, by omega⟩)) + · unfold TOffN at h2 + exact J.td_tcbA htw hu h1 (Or.inl (by omega)) + · unfold TL at h + exact J.td_tcbA htw hu (by omega) (Or.inl (by omega)) + · exact J.td_bufA htw h + have ntfn : NtfnStateRel N Z.T (L.mem s') { σ with reprogramTimer := pb } := by + refine J.ntfn.frame hP.n (fun b hb hf => kp b hb fun htw => ?_) + ⟨fun p x hk => hk, fun p x hk => ⟨x, hk, rfl, rfl, rfl⟩⟩ + rcases hf with ⟨q, hq, h1, h2⟩ | ⟨u, hu, e⟩ + · exact J.td_ipcA htw (Or.inl ⟨q, hq, h1, by omega⟩) + · rcases e with rfl | rfl | rfl | rfl | rfl | rfl + · rw [stA_eq] at htw; exact J.td_tcbKA hu (by simp) (Or.inl (by simp)) htw + · rw [tBlockA_eq] at htw; exact J.td_tcbKA hu (by simp) (Or.inl (by simp)) htw + · rw [badgeRegA_eq] at htw; exact J.td_tcbKA hu (by simp) (Or.inl (by simp)) htw + · rw [prioA_eq'] at htw; exact J.td_tcbKA hu (by simp) (Or.inl (by simp)) htw + · rw [nextEp_eq] at htw; exact J.td_tcbKA hu (by simp) (Or.inl (by simp)) htw + · rw [prevEp_eq] at htw; exact J.td_tcbKA hu (by simp) (Or.inl (by simp)) htw + have reply : ReplyStackRelA (L.mem s') Rp Z.C { σ with reprogramTimer := pb } (scNameA m) stack := by + refine J.reply.frame (fun r hr => ?_) (fun c _ x n hk => ⟨x, n, hk, rfl⟩) (fun r _ x hk => ⟨x, hk, rfl⟩) + obtain ⟨r32, -, rfit⟩ := hP.e.rep r hr + have one : ∀ o : U64, o.val < 32 → o.val % 8 = 0 → L.mem s' (wa r o) = L.mem s (wa r o) := by + intro o o1 o2 + have v : (wa r o).val = r.val + o.val := by rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) + refine kp _ ?_ fun htw => J.td_ipcA htw (Or.inr (Or.inr ⟨r, hr, by omega, by omega⟩)) + show (wa r o).val % 8 = 0 + omega + have n16 : (layout.reply.NEXT).val = 16 := by unfold layout.reply.NEXT; rfl + have p8 : (layout.reply.PREV).val = 8 := by unfold layout.reply.PREV; rfl + exact ⟨one _ (by omega) (by omega), one _ (by omega) (by omega)⟩ + have buf : BufCover st Z.T Bf s' { σ with reprogramTimer := pb } := + J.bufCover_wA w0 (fun u hu K hK htw => J.td_tcbKA hu (by omega) (Or.inl (by omega)) htw) + (fun q z h => ⟨z, h, rfl, rfl⟩) + have mcp : McpRelA Z.T m (L.mem s') { σ with reprogramTimer := pb } := + J.mcp.congrA (fun u hu => ⟨tK u hu 3440#u64 (by simp) (by simp) (by simp), + tK u hu 3456#u64 (by simp) (by simp) (by simp)⟩) (fun u hu x hx => ⟨x, hx, rfl, rfl⟩) + have yr : YieldRelA Z.T Z.C m (L.mem s') { σ with reprogramTimer := pb } := by + have k : ∀ u ∈ Z.T, L.mem s' (yieldA u) = L.mem s (yieldA u) := + fun u hu => tK u hu 3472#u64 (by simp) (by simp) (by simp) + refine ⟨fun u hu => ?_, fun u hu hnz => ?_, fun c hc y n hy p hp => ?_⟩ + · obtain ⟨x, hx, he⟩ := J.yieldRel.tcb u hu + exact ⟨x, hx, by rw [k u hu]; exact he⟩ + · rw [k u hu] at hnz ⊢ + exact J.yieldRel.toSc u hu hnz + · obtain ⟨u, hu, e1, e2⟩ := J.yieldRel.frm c hc y n hy p hp + exact ⟨u, hu, e1, by rw [k u hu]; exact e2⟩ + have bq : BlkQueuedA Z.T E N (L.mem s') { σ with reprogramTimer := pb } := + J.blkQ.keepA (fun u hu => by rw [Notif.tBlockA_eq]; exact tK u hu 3336#u64 (by simp) (by simp) (by simp)) + (fun u hu x' hx' => Or.inr ⟨x', hx', rfl⟩) (fun _ _ h => h) (fun _ _ h => h) + have j := J.j57_stepNWA w { σ with reprogramTimer := pb } + exact JStage3A.of_schedWrN (blkQ := bq) (symL := symL) (schedValid := { J.schedValid with }) J (Q := Z.Q) (Rl := Z.R) (curOf := Z.curOf) (curScOf := Z.curScOf) + (s' := s') (a' := a) (σ' := { σ with reprogramTimer := pb }) w HS SSz (QKeepA.of_kheap rfl ⟨rfl, rfl, rfl, rfl⟩) rfl J.j.1.ar (fun _ _ => rfl) J.bufAl + ⟨J.ent_stepNWA w blk', sysl⟩ sq poolOff H2 J.scCov ep ntfn reply buf J.idleNoFault mcp yr { J.sinv with irqN := by cases J.sinv.irqN; constructor <;> assumption } { J.sidle with } rv' + j.1 j.2 + + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3UtArmA.lean b/proofs/Fl4ProofsA64/P3/Stage3UtArmA.lean new file mode 100644 index 000000000..1cf7ae37a --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3UtArmA.lean @@ -0,0 +1,251 @@ +/- +P3 (aarch64, A64-P3 Stage 4, Untyped dispatch): **the Retype arm at the syscall-entry record** (RAM Untyped cap, a +child exists so no reset, no TCB created). + +* `utRtMA_noTcbA`: with no TCB created the grown multi-core view is the old one (`utRtMA m ∅ = m`), so the record + holds at the dispatch's fixed `m`. (TCB creation needs the `∃ m'` relation, step S6.) +* `Sched.BodyOKA.ofUtKeepA`: the body-end facts from `UtKeepA` (`P3/UtKeepA`): `BodyOKA.ofEntry` across `Restart` and a + Retype that keeps the globals, the last machine time and every TCB and SC. +* **`JSyscallA.untypedRetypeA`**: from the entry record and the decode-site facts, `syscall.decode_invocation` at the + invoked slot's own Untyped cap returns `Ok`, the spec's `fl4InvokeUntypedA64` of the decoded invocation has the outcome + `σ'`, the current thread word is kept and `A64RelS3` holds. + +The decode-site facts (`DecPre`, `SysPlace`, `RsSiteA`) come from the record as in `DecErrSpecPA.untyped`. + +Named premises: [P] `ArchTotal`, `ArchPlat`, `A64FrameMasks`, the virtualization word (`hvi`/`hvirt`), `retypeFanOutLimit = 256` +(`hfan`), the platform's VCPU registers `hVP` and the kernel TTBR1 constants `hKt` / `hK0`; the placement of the grown heap is `utRt_newPlaceA` (proved) and the grown `McState` is `utRtMA` (`McGrowA`). Case hypotheses: the cap, the label and the arguments. +-/ +import Fl4ProofsA64.P3.Stage3DispBaseA +import Fl4ProofsA64.P3.UtDecRecA +import Fl4ProofsA64.P3.UtKeepA +import Fl4ProofsA64.P3.Stage3RsSiteA +import Fl4ProofsA64.P3.Stage3SysPlaceA +import Fl4ProofsA64.P3.McGrowUtA +import Fl4ProofsA64.P3.UtDecExA +import Fl4ProofsA64.P3.UtKeepCurA +import Fl4ProofsA64.P3.ExtVsTopA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4SpecA64 Classical + +noncomputable section + +/-- **No TCB created: the multi-core view is kept.** -/ +theorem utRtMA_noTcbA (m : McState) {nt us aligned : U64} {win : Nat} (h : nt.val ≠ 1) : + utRtMA m (UtOfTyA 1 nt us aligned win) = m := by + have e : (fun p => if ∃ t ∈ UtOfTyA 1 nt us aligned win, specPtr t = p then some 0 else m.tcbAffinity p) = + m.tcbAffinity := by + funext p + rw [if_neg] + rintro ⟨t, ⟨ht, -⟩, -⟩ + exact h ht + unfold utRtMA + rw [e] + +namespace Sched + +section +variable {S A : Type} {st : machine.Store S} [L : LawfulStore st] +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {J5 J7 : JSlotA S} {s : S} {a : A} {σ : State Unit} {m : McState} + +/-- **The body-end facts at a grown view**: `NotIdleScA` reads the view's idle SCs only (`McGrowA.idleSc`). -/ +theorem BodyOKA.ofGrow {σ : State Unit} {m m' : McState} (hg : McGrowA m m') (B : BodyOKA σ m) : BodyOKA σ m' := by + refine { B with scNotIdle := fun h => ?_ } + obtain ⟨h1, h2⟩ := B.scNotIdle h + exact ⟨h1, fun c hc => by rw [hg.idleSc]; exact h2 c hc⟩ + +/-- **The body-end facts across `Restart` and a Retype** (module docstring). -/ +theorem BodyOKA.ofUtKeepCurA (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m) + {x : Tcb} (hk : σ.kheap σ.curThread = some (.tcb x)) {σ' : State Unit} + (K : UtKeepCurA (stUpdA σ σ.curThread x .restart) σ') : BodyOKA σ' m := by + obtain ⟨y0, k0, hy0⟩ := J.curInv.sc + have ne : σ.curSc ≠ σ.curThread := fun e => by rw [e, hk] at hy0; cases hy0 + have h0 : (stUpdA σ σ.curThread x .restart).kheap σ.curSc = some (.schedContext y0 k0) := by + simp only [stUpdA, setObjA, Function.update_of_ne ne]; exact hy0 + have h1 : σ'.kheap σ.curSc = some (.schedContext y0 k0) := K.sc y0 k0 h0 + refine BodyOKA.ofEntry J (Or.inl K.glob.act) K.glob.time K.last K.glob.cur K.glob.csc K.glob.cons K.glob.rls + (fun y' k h => ?_) (fun _ y h => ?_) + · rw [h1] at h + obtain ⟨rfl, rfl⟩ := KernelObject.schedContext.inj (Option.some.inj h) + exact ⟨y0, hy0, rfl, rfl, rfl⟩ + · have hq : σ'.kheap σ.curThread = some (.tcb { x with tcbState := .restart }) := + K.tcb { x with tcbState := .restart } (by simp [stUpdA, setObjA]) + obtain rfl := KernelObject.tcb.inj (Option.some.inj (hq.symm.trans h)) + exact Or.inr rfl + + +/-- **The body-end facts across `Restart` and a Retype that keeps every TCB and SC** (module docstring). -/ +theorem BodyOKA.ofUtKeepA (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m) + {x : Tcb} (hk : σ.kheap σ.curThread = some (.tcb x)) {σ' : State Unit} + (K : UtKeepA (stUpdA σ σ.curThread x .restart) σ') : BodyOKA σ' m := + BodyOKA.ofUtKeepCurA J hk K.cur + +end + +end Sched + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 8000000 in +/-- **The Retype arm without a reset** (module docstring). -/ +theorem JSyscallA.untypedRetypeA {ar : machine.Arch A} (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {p sb fi : U64} {blk call don fp : Bool} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) + (hslc : capA st s slot = .Untyped p sb fi false) + (sl : CslotPtr) (hsl : slot = cslotAddrA sl) (hsrc : ∃ q, sl.1 = specPtr q ∧ Z.th q = some (.cnode sl.2.length)) + (vi : U64) (hvi : ar.virtualization a = ok vi) (hvirt : vi = 0#u64 ↔ fl4A64Virt = false) + (hfan : Fl4SpecA64.retypeFanOutLimit = 256#64) + (lbl : U64) (slbl : Fl4SpecA64.Data) + (hlbl : Fl4SpecA64.genInvocationType slbl = .untypedRetype ↔ lbl = fl4_abi.label.UntypedRetype) + (length buf : U64) (args : List U64) (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s (L.curW s) buf i = ok x) + (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) (hex : ExtraOKA Z.th (L.mem s) extra exs) + (hchild : ∃ x, σ.cdt x = some sl) + (inv : UntypedInvocation) + (hdecS : (fl4DecodeUntypedInvocationVirt (Z := Unit) slbl (args.map UScalar.bv) sl + (absCapA (.Untyped p sb fi false)) (exs.map Prod.fst)).run σ = ({(.ok inv, σ)}, False)) + (hVP : ∀ a1 : A, UtVcpuPlatA ar a1) {k : U64 → U64} + (hKt : ∀ (a1 : A) (i : U64), i.val < 511 → ar.kernel_ttbr1_entry a1 0#u64 i = ok (k i)) + (hK0 : ∀ i : U64, i.val < 256 → k i = 0#u64) : + ∃ (s' : S) (a' : A) (σ' : State Unit), + syscall.decode_invocation st ar s a lbl length slot (capA st s slot) blk call don fp buf extra = + ok (core.result.Result.Ok (), s', a') ∧ + (∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + (.ok (), σ') ∈ ((fl4InvokeUntypedA64 (Z := Unit) inv).run (stUpdA σ σ.curThread xT .restart)).1) ∧ + L.curW s' = L.curW s ∧ A64RelS3 st AR ar hPl.ipa n Z.Cs s' a' σ' m := by + subst hsl + have hcapF : obj.Slot.cap st (cslotAddrA sl) s = ok (.Untyped p sb fi false) := by + rw [capA_eq]; exact congrArg ok hslc + have D := J.decPreA hslot hext + rw [hslc] at D + have P := J.toJStage3A.sysPlace hext hslot hcov + have RS := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have K := utDecode_recNoResetA hA J.toJStage3A extra sl hsrc D P hcapF RS hfm vi hvi hvirt hfan lbl slbl hlbl + length buf args hlen hargs exs hex hchild hVP hKt hK0 + obtain ⟨⟨r1, s1, a1⟩, hdec, hpost⟩ := spec_existsA K + have hdc : syscall.decode_invocation st ar s a lbl length (cslotAddrA sl) (capA st s (cslotAddrA sl)) blk call don fp + buf extra = untyped.decode st ar s a lbl length (cslotAddrA sl) (.Untyped p sb fi false) buf extra := by + rw [hslc] + simp only [syscall.decode_invocation, cur_thread_ok, bind_ok] + rcases hpost with ⟨e, e', -, hrun, -⟩ | ⟨inv', hrun, hq⟩ + · exfalso + obtain ⟨h1, -⟩ := Prod.mk.inj (hdecS.symm.trans hrun) + cases (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 h1)).1 + · have hi : inv' = inv := by + obtain ⟨h1, -⟩ := Prod.mk.inj (hdecS.symm.trans hrun) + exact (Except.ok.inj (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 h1)).1).symm + subst hi + obtain ⟨base, retypeBase, t, us, slots, rfl, hok, xT, hkT, aligned, nt, usF, dest, off, win, hU, ⟨r, hr⟩, Kr⟩ := hq + simp only at hok + subst hok + obtain ⟨vm, kp, H'', Z'', OS'', U'', Ac', Pp'', Tb'', N'', E'', Rp'', stack'', κ'', m'', J', eZ, eO, eM⟩ := + Kr r hr + have hg : McGrowA m m'' := eM ▸ utRtMA_growA m _ + obtain ⟨⟨⟩, σ1⟩ := r + have B := Sched.BodyOKA.ofGrow hg (Sched.BodyOKA.ofUtKeepA J hkT kp) + have hcur : (utInvStA t retypeBase us slots σ1).curThread = σ.curThread := kp.glob.cur + refine ⟨s1, a1, utInvStA t retypeBase us slots σ1, ?_, ⟨xT, hkT, vm _ _ _ _ _ (utInvoke_noReset_memA hr)⟩, + curW_keptA J.toJStage3A J' hcur, A64RelS3.ofJg hg J' B (by rw [eZ]; rfl)⟩ + rw [hdc, hdec] + +set_option maxHeartbeats 8000000 in +/-- **The Retype arm with a reset that does not run the chunk loop** (`P3/UtDecExA`): the untyped has no CDT child, so +the decode restarts the caller and resets the untyped (nothing to clear when its free index is zero; a block below the chunk +size is cleared at once). The spec's `fl4InvokeUntypedA64` of the decoded invocation has the outcome `σ'`, the current +thread word is kept and `A64RelS3` holds at the grown view (`dropMA` of the dropped threads, then `utRtMA`). -/ +theorem JSyscallA.untypedRetypeRstA {ar : machine.Arch A} (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (J : JSyscallA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s a σ m) + (hfm : A64FrameMasks st s) + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {p sb fi : U64} {blk call don fp : Bool} + (hslot : slot ∈ OS) (hcov : SlotCov st OS s slot) (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) + (hslc : capA st s slot = .Untyped p sb fi false) + (sl : CslotPtr) (hsl : slot = cslotAddrA sl) (hsrc : ∃ q, sl.1 = specPtr q ∧ Z.th q = some (.cnode sl.2.length)) + (vi : U64) (hvi : ar.virtualization a = ok vi) (hvirt : vi = 0#u64 ↔ fl4A64Virt = false) + (hfan : Fl4SpecA64.retypeFanOutLimit = 256#64) + (lbl : U64) (slbl : Fl4SpecA64.Data) + (hlbl : Fl4SpecA64.genInvocationType slbl = .untypedRetype ↔ lbl = fl4_abi.label.UntypedRetype) + (length buf : U64) (args : List U64) (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s (L.curW s) buf i = ok x) + (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) (hex : ExtraOKA Z.th (L.mem s) extra exs) + (hnochild : ¬ ∃ x, σ.cdt x = some sl) + (inv : UntypedInvocation) + (hdecS : (fl4DecodeUntypedInvocationVirt (Z := Unit) slbl (args.map UScalar.bv) sl + (absCapA (.Untyped p sb fi false)) (exs.map Prod.fst)).run σ = ({(.ok inv, σ)}, False)) + (hVP : ∀ a1 : A, UtVcpuPlatA ar a1) {k : U64 → U64} + (hKt : ∀ (a1 : A) (i : U64), i.val < 511 → ar.kernel_ttbr1_entry a1 0#u64 i = ok (k i)) + (hK0 : ∀ i : U64, i.val < 256 → k i = 0#u64) + -- [S] one core; the reset never runs the chunk loop + (hnN : n ≤ Fl4SpecA64.fl4A64Platform.numNodes) (h1 : Fl4SpecA64.fl4A64Platform.numNodes = 1) + (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) + (hS : sb.val < 16 ∨ fi = 0#u64) + -- [P] the platform's Stage-2 IPA width, the chunk size, and the post-reset barriers (a used untyped only) + (hIpa : S2IpaE ar a) (hchunk : resetChunkBits = 16) + (hPost : fi ≠ 0#u64 → ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) : + ∃ (s' : S) (a' : A) (σ' : State Unit), + syscall.decode_invocation st ar s a lbl length slot (capA st s slot) blk call don fp buf extra = + ok (core.result.Result.Ok (), s', a') ∧ + (∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + (.ok (), σ') ∈ ((fl4InvokeUntypedA64 (Z := Unit) inv).run (stUpdA σ σ.curThread xT .restart)).1) ∧ + L.curW s' = L.curW s ∧ A64RelS3 st AR ar hPl.ipa n Z.Cs s' a' σ' m := by + haveI : Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes) := ⟨hnN⟩ + subst hsl + have hcapF : obj.Slot.cap st (cslotAddrA sl) s = ok (.Untyped p sb fi false) := by + rw [capA_eq]; exact congrArg ok hslc + have D := J.decPreA hslot hext + rw [hslc] at D + have P := J.toJStage3A.sysPlace hext hslot hcov + have RS := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have hn : hPl.ipa.val = Fl4SpecA64.fl4A64Platform.s2IpaBits := by + obtain ⟨n0, e0, hv⟩ := hIpa + have e1 := hPl.ipa_eq a + rw [e0] at e1 + rw [← okinj e1] + exact hv + have hcpu : L.cpu s ∈ Z.Cs := J.j.1.sch.cpuCs + have hone : ∀ c ∈ Z.Cs, c = L.cpu s := fun c hc => + UScalar.eq_of_val_eq (by have := hCs c hc; have := hCs _ hcpu; omega) + have K := utDecode_recResetExA hA J.sact J.toJStage3A extra sl hsrc D P hcapF RS hfm vi hvi hvirt hfan lbl slbl hlbl + length buf args hlen hargs exs hex hnochild + (fun c hc hne => absurd (hone c hc) hne) (fun c hc hne => absurd (hone c hc) hne) + (fun c hc hne => absurd (hone c hc) hne) (fun c hc hne => absurd (hone c hc) hne) hn hPost hchunk hS hVP hKt hK0 + obtain ⟨⟨r1, s1, a1⟩, hdec, hpost⟩ := spec_existsA K + have hdc : syscall.decode_invocation st ar s a lbl length (cslotAddrA sl) (capA st s (cslotAddrA sl)) blk call don fp + buf extra = untyped.decode st ar s a lbl length (cslotAddrA sl) (.Untyped p sb fi false) buf extra := by + rw [hslc] + simp only [syscall.decode_invocation, cur_thread_ok, bind_ok] + rcases hpost with ⟨e, e', -, hrun, -⟩ | ⟨inv', hrun, hq⟩ + · exfalso + obtain ⟨h1', -⟩ := Prod.mk.inj (hdecS.symm.trans hrun) + cases (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 h1')).1 + · have hi : inv' = inv := by + obtain ⟨h1', -⟩ := Prod.mk.inj (hdecS.symm.trans hrun) + exact (Except.ok.inj (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 h1')).1).symm + subst hi + obtain ⟨xT, hkT, aligned, nt, usF, dest, off, win, hU, hok, σ3, hm, kc, σ', hmem, Z0, m0, hZ, kp, H'', OS'', U'', + Ac', Pp'', Tb'', N'', E'', Rp'', Bf'', stack'', κ'', J'⟩ := hq + simp only at hok + subst hok + have hg : McGrowA m (utRtMA m0 (UtOfTyA 1 nt usF aligned win.val)) := by + rcases hZ with ⟨-, h0⟩ | ⟨-, h0⟩ + · rw [h0]; exact utRtMA_growA m _ + · rw [h0]; exact (dropMA_growA _ m).trans (utRtMA_growA _ _) + have hcur : σ'.curThread = σ.curThread := kp.glob.cur.trans kc.glob.cur + have B := Sched.BodyOKA.ofGrow hg (Sched.BodyOKA.ofUtKeepCurA J hkT (kc.trans kp.cur)) + refine ⟨s1, a1, σ', ?_, ⟨xT, hkT, hmem⟩, curW_keptA J.toJStage3A J' hcur, + A64RelS3.ofJg hg J' B (by rcases hZ with ⟨h0, -⟩ | ⟨h0, -⟩ <;> rw [h0] <;> rfl)⟩ + rw [hdc, hdec] + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3VcpuBridgeA.lean b/proofs/Fl4ProofsA64/P3/Stage3VcpuBridgeA.lean index a615a5058..ec1abd8aa 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VcpuBridgeA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VcpuBridgeA.lean @@ -1292,7 +1292,7 @@ theorem JStage3A.of_vcpuNonLinkWrA {ar : machine.Arch A} {nA : U64} activeReplyScs := ActRepA.of_keep J.activeReplyScs (fun p y k hy => ⟨y, k, Eq.khBack _ _ hy (fun _ e => by cases e), fun h => ⟨h, id⟩⟩) bufVs := fun b hb => by rw [Eq.hk, utVsEq]; exact J.bufVs b hb - domOK := J.domOK.keepS J.sr.toSchedSRN ⟨rfl, rfl, rfl, rfl⟩ Eq.hk Eq.hc fun b ha hb => by + domOK := J.domOK.keepS J.sr.toSchedSRN (DomKeepA.ofKey rfl) Eq.hk Eq.hc fun b ha hb => by obtain ⟨o, ho, rfl⟩ := Sched.DomW.wa_exists J.j.1.ksFit hb have ho8 : o.val % 8 = 0 := by have hk8 := J.sr.toSchedSRN.ksb_al; have hb8 : (wa (L.ksb s) o).val % 8 = 0 := ha; rw [wa_valm] at hb8 diff --git a/proofs/Fl4ProofsA64/P3/Stage3VcpuExitA.lean b/proofs/Fl4ProofsA64/P3/Stage3VcpuExitA.lean index de46b9f73..b6c3f9c1b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VcpuExitA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VcpuExitA.lean @@ -394,12 +394,10 @@ private theorem vcpu_mask_vppi_stage3A {ar : machine.Arch A} {nA : U64} ⟨L.ksb_wr _ _ _, L.cpu_wr _ _ _, fun q hqa hnf => mem_wr_neA hal16 hqa (fun e => hnf (Or.inl ⟨vc, hvc, 16#u64, by decide, by decide, e.symm⟩))⟩ have hHS : VcpuSpecStepA H σ σ1 true := - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, - fun p => by + VcpuSpecStepA.ofKey rfl (fun p => by by_cases e : p = specPtr vc · subst e; exact Or.inr (Or.inr ⟨v0, _, hkv0, updKSc_same _ _ _, trivial⟩) - · exact Or.inl (updKSc_other _ e), - fun _ h => absurd rfl h⟩ + · exact Or.inl (updKSc_other _ e)) (fun _ h => absurd rfl h) have osk : OSKeep st OS s s1 := osKeep_of_vcpuWrCoreA (J.toVcpuCoreA hNoSw) R6.vcOS R6.frOff hw have hne_vc : ∀ v ∈ Z.V, ∀ o : U64, o.val < 64 → (v = vc → o.val ≠ 16) → wa vc 16#u64 ≠ wa v o := fun v hv o ho hne => by by_cases hvv : v = vc @@ -585,7 +583,7 @@ private theorem jstage3A_of_maskInterruptA {Rj : Set U64 → JSlotA S} ⟨fun _ => Or.inl rfl, rfl, rfl, rfl, rfl, rfl, rfl⟩ (fun _ y _ h => ⟨y, h⟩) ⟨fun _ x h => ⟨x, h, rfl⟩, fun _ x h => ⟨x, h, List.Sublist.refl _⟩, fun _ x h => ⟨x, h, List.Sublist.refl _⟩, fun _ y k h => ⟨y, k, h, fun r => ⟨r, id⟩⟩, - fun _ y h => ⟨y, h, id⟩, ⟨rfl, rfl, rfl, rfl⟩⟩ + fun _ y h => ⟨y, h, id⟩, DomKeepA.ofKey rfl⟩ rfl hAR2 (fun _ _ => rfl) J.bufAl J.sys J.sq J.poolOff (hZ.symm ▸ hsr_m) J.scCov ⟨J.ep.1, J.ep.2, J.ep.3, J.ep.4⟩ ⟨J.ntfn.1, J.ntfn.2⟩ (by cases J.reply; constructor <;> assumption) J.bufCover @@ -643,7 +641,11 @@ theorem JStage3A.vcpuRunExitA {ar : machine.Arch A} (hPl : ArchPlat ar) (hNowEq : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) (hE : CurEntryGA σ) (hP : VcpuPlatAgreeA ar) (hAK : VcpuArchKeepsA ar AR) (hVR : VcpuVmRootA st ar AR) - (hScPost : ∀ (s2 : S) (a2 : A) (hw2 : HwRootA) (σ2 : Fl4SpecA64.State Unit), + (hScPost : ∀ (sp : S) (ap : A) (ct stop w1 w2 w3 : U64) (s2 : S) (a2 : A) (hw2 : HwRootA) + (σ1 σa σ2 : Fl4SpecA64.State Unit) (ss : RunStop), + vcpu.complete_run st ar sp ap ct stop w1 w2 w3 = ok (s2, a2) → + updateTimeStamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4CompleteRun (Z := Unit) (specPtr ct) ss w1.bv w2.bv w3.bv σa = ({((), σ2)}, False) → DrA σ1 σ2 → JStage3A st AR { Z with hw := hw2 } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s2 a2 σ2 m → ScStateRelA st Z.C m s2 σ2 ∧ @@ -662,7 +664,10 @@ theorem JStage3A.vcpuRunExitA {ar : machine.Arch A} (hPl : ArchPlat ar) fl4HandleVcpuRunExit (Z := Unit) ⟨stopSpec, w1.bv, w2.bv, w3.bv⟩ σ = ({((), σ')}, False) ∧ updateTimeStamp (Z := Unit) σ = ({((), σ1)}, False) ∧ DrA σ1 σ' ∧ JStage3A st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) - (J7A st (J7R2A st ar hPl.ipa)) res.1 res.2 σ' m ⦄ := by + (J7A st (J7R2A st ar hPl.ipa)) res.1 res.2 σ' m ∧ + ∃ (sp : S) (ap : A) (ct : U64) (σa : State Unit) (ss : RunStop), + vcpu.complete_run st ar sp ap ct stop w1 w2 w3 = ok (res.1, res.2) ∧ + fl4CompleteRun (Z := Unit) (specPtr ct) ss w1.bv w2.bv w3.bv σa = ({((), σ')}, False) ⦄ := by have hArTs : sched.update_timestamp st ar s a ⦃ r => AR r.2 Z.hw ⦄ := by have hct : sched.cur_time st s = ok (L.curTime s) := by unfold sched.cur_time LawfulStore.curTime LawfulStore.nodeA @@ -692,10 +697,16 @@ theorem JStage3A.vcpuRunExitA {ar : machine.Arch A} (hPl : ArchPlat ar) ok (s3, a3)) ⦃ _ ⦄ rw [show sched.cur_thread st s1 = ok (L.curW s1) from eq_of_spec_fd (sched.cur_thread.spec s1), bind_ok] have hct1 : L.curW s1 ∈ Z.T := J1.sr.curT - refine WP.spec_bind (vcpu_complete_run_stage3A (Clock := Clock) J1 hNoSw1 hCl1 hClVm hClFlushState hClFr - hP hAK hVR hct1 hstop w1 w2 w3) ?_ - rintro ⟨s2, a2⟩ ⟨hw2, σ2, hsp_cr, J2, -, -, -, -, -, -, -, -⟩ - obtain ⟨hSc2, ⟨xsc, nsc, hks2, hact2⟩, hmb2, hsuf2⟩ := hScPost s2 a2 hw2 σ2 J2 + obtain ⟨⟨s2, a2⟩, e_cr, hw2, σ2, hsp_cr, J2, -, -, -, -, -, -, -, -⟩ := + spec_existsA (vcpu_complete_run_stage3A (Clock := Clock) J1 hNoSw1 hCl1 hClVm hClFlushState hClFr + hP hAK hVR hct1 hstop w1 w2 w3) + rw [e_cr, bind_ok] + try simp only [uncurry_apply_pair] + have hDr2 : DrA σ1 σ2 := + fl4CompleteRun_drC (specPtr (L.curW s1)) stopSpec w1.bv w2.bv w3.bv σ1 hσ1_ct.symm ((), σ2) + (by rw [hsp_cr]; exact Set.mem_singleton _) + obtain ⟨hSc2, ⟨xsc, nsc, hks2, hact2⟩, hmb2, hsuf2⟩ := hScPost s1 a1 (L.curW s1) stop w1 w2 w3 s2 a2 hw2 σ1 σ1 σ2 stopSpec + e_cr hsp_ts hsp_cr hDr2 J2 have hks2' : σ2.kheap (scNameA m (L.cscW s2)) = some (.schedContext xsc nsc) := by have hcw : σ2.curSc = scNameA m (L.cscW s2) := J2.j.1.sch.curScW rw [← hcw]; exact hks2 @@ -705,9 +716,8 @@ theorem JStage3A.vcpuRunExitA {ar : machine.Arch A} (hPl : ArchPlat ar) have ha3 : a3 = a2 := congrArg (fun t => t.2.2) heq3 rw [hs3, ha3] exact (WP.spec_ok (s2, a2)).2 ⟨hw2, σ2, σ1, - fl4HandleVcpuRunExit_nonvppi_stage3A hne_vppi hsp_ts hσ1_ct hsp_cr hcb_sp, hsp_ts, - fl4CompleteRun_drC (specPtr (L.curW s1)) stopSpec w1.bv w2.bv w3.bv σ1 hσ1_ct.symm ((), σ2) - (by rw [hsp_cr]; exact Set.mem_singleton _), J2⟩ + fl4HandleVcpuRunExit_nonvppi_stage3A hne_vppi hsp_ts hσ1_ct hsp_cr hcb_sp, hsp_ts, hDr2, J2, + s1, a1, L.curW s1, σ1, stopSpec, e_cr, hsp_cr⟩ set_option maxHeartbeats 1000000 in /-- **§3 VM-exit refinement (VPPI, pre-`syscall.finish`) on `JStage3A`**: @@ -731,7 +741,11 @@ theorem JStage3A.vcpuRunVppiA {ar : machine.Arch A} (hPl : ArchPlat ar) (hNowEq : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) (hE : CurEntryGA σ) (hP : VcpuPlatAgreeA ar) (hAK : VcpuArchKeepsA ar AR) (hVR : VcpuVmRootA st ar AR) - (hScPost : ∀ (s3 : S) (a3 : A) (hw3 : HwRootA) (σ3 : Fl4SpecA64.State Unit), + (hScPost : ∀ (sp : S) (ap : A) (ct stop w1 w2 w3 : U64) (s3 : S) (a3 : A) (hw3 : HwRootA) + (σ1 σa σ3 : Fl4SpecA64.State Unit) (ss : RunStop), + vcpu.complete_run st ar sp ap ct stop w1 w2 w3 = ok (s3, a3) → + updateTimeStamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4CompleteRun (Z := Unit) (specPtr ct) ss w1.bv w2.bv w3.bv σa = ({((), σ3)}, False) → DrA σ1 σ3 → JStage3A st AR { Z with hw := hw3 } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s3 a3 σ3 m → ScStateRelA st Z.C m s3 σ3 ∧ @@ -764,7 +778,10 @@ theorem JStage3A.vcpuRunVppiA {ar : machine.Arch A} (hPl : ArchPlat ar) fl4HandleVcpuRunExit (Z := Unit) ⟨.vppi, irq_id.bv, 0, 0⟩ σ = ({((), σ')}, False) ∧ updateTimeStamp (Z := Unit) σ = ({((), σ1)}, False) ∧ DrA σ1 σ' ∧ JStage3A st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) - (J7A st (J7R2A st ar hPl.ipa)) res.1 res.2 σ' m ⦄ := by + (J7A st (J7R2A st ar hPl.ipa)) res.1 res.2 σ' m ∧ + ∃ (sp : S) (ap : A) (ct : U64) (σa : State Unit) (ss : RunStop), + vcpu.complete_run st ar sp ap ct fl4_abi.consts.vcpu_run_stop.VPPI irq_id 0#u64 0#u64 = ok (res.1, res.2) ∧ + fl4CompleteRun (Z := Unit) (specPtr ct) ss irq_id.bv (0#u64).bv (0#u64).bv σa = ({((), σ')}, False) ⦄ := by have hArTs : sched.update_timestamp st ar s a ⦃ r => AR r.2 Z.hw ⦄ := by have hct : sched.cur_time st s = ok (L.curTime s) := by unfold sched.cur_time LawfulStore.curTime LawfulStore.nodeA @@ -874,10 +891,17 @@ theorem JStage3A.vcpuRunVppiA {ar : machine.Arch A} (hPl : ArchPlat ar) (by change σ2.machineState.lastMachineTime = σ1.machineState.lastMachineTime; rw [hms2]) have hvppi_bv : fl4_abi.consts.vcpu_run_stop.VPPI.bv = RunStop.vppi.word := by unfold fl4_abi.consts.vcpu_run_stop.VPPI RunStop.word; rfl - refine WP.spec_bind (vcpu_complete_run_stage3A (Clock := Clock) J2m hNoSw2 hCl2m hClVm hClFlushState hClFr - hP hAK hVR hct1 hvppi_bv irq_id 0#u64 0#u64) ?_ - rintro ⟨s3, a3⟩ ⟨hw3, σ3, hsp_cr, J3, -, -, -, -, -, -, -, -⟩ - obtain ⟨hSc3, ⟨xsc, nsc, hks3, hact3⟩, hmb3, hsuf3⟩ := hScPost s3 a3 hw3 σ3 J3 + obtain ⟨⟨s3, a3⟩, e_cr, hw3, σ3, hsp_cr, J3, -, -, -, -, -, -, -, -⟩ := + spec_existsA (vcpu_complete_run_stage3A (Clock := Clock) J2m hNoSw2 hCl2m hClVm hClFlushState hClFr + hP hAK hVR hct1 hvppi_bv irq_id 0#u64 0#u64) + rw [e_cr, bind_ok] + try simp only [uncurry_apply_pair] + have K1 : DlA σ1 σ2 := vppiBlock_dlA (specPtr ct) irq_id.bv σ1 ((), σ2) (by rw [hsp_vp]; exact Set.mem_singleton _) + have K2 : DlA σ2 σ2m := dlA_eqA rfl rfl rfl rfl rfl rfl rfl rfl rfl + have hDr3 : DrA σ1 σ3 := (DlA.toDr (dlA_trans K1 K2)).trans (fl4CompleteRun_drC (specPtr ct) RunStop.vppi irq_id.bv + (0#u64).bv (0#u64).bv σ2m ((K1.cur.trans hσ1_ct).symm) ((), σ3) (by rw [hsp_cr]; exact Set.mem_singleton _)) + obtain ⟨hSc3, ⟨xsc, nsc, hks3, hact3⟩, hmb3, hsuf3⟩ := hScPost s2 a2 ct fl4_abi.consts.vcpu_run_stop.VPPI irq_id + 0#u64 0#u64 s3 a3 hw3 σ1 σ2m σ3 RunStop.vppi e_cr hsp_ts hsp_cr hDr3 J3 have hks3' : σ3.kheap (scNameA m (L.cscW s3)) = some (.schedContext xsc nsc) := by have hcw : σ3.curSc = scNameA m (L.cscW s3) := J3.j.1.sch.curScW rw [← hcw]; exact hks3 @@ -886,12 +910,8 @@ theorem JStage3A.vcpuRunVppiA {ar : machine.Arch A} (hPl : ArchPlat ar) have hs4 : s4 = s3 := congrArg (fun t => t.2.1) heq4 have ha4 : a4 = a3 := congrArg (fun t => t.2.2) heq4 rw [hs4, ha4] - have K1 : DlA σ1 σ2 := vppiBlock_dlA (specPtr ct) irq_id.bv σ1 ((), σ2) (by rw [hsp_vp]; exact Set.mem_singleton _) - have K2 : DlA σ2 σ2m := dlA_eqA rfl rfl rfl rfl rfl rfl rfl rfl rfl exact (WP.spec_ok (s3, a3)).2 ⟨hw3, σ3, σ1, - fl4HandleVcpuRunExit_vppi_stage3A hsp_ts hσ1_ct hsp_vp hsp_cr hcb_sp, hsp_ts, - (DlA.toDr (dlA_trans K1 K2)).trans (fl4CompleteRun_drC (specPtr ct) RunStop.vppi irq_id.bv (0#u64).bv (0#u64).bv - σ2m ((K1.cur.trans hσ1_ct).symm) ((), σ3) (by rw [hsp_cr]; exact Set.mem_singleton _)), J3⟩ + fl4HandleVcpuRunExit_vppi_stage3A hsp_ts hσ1_ct hsp_vp hsp_cr hcb_sp, hsp_ts, hDr3, J3, s2, a2, ct, σ2m, RunStop.vppi, e_cr, hsp_cr⟩ end vcpuExit diff --git a/proofs/Fl4ProofsA64/P3/Stage3VcpuExitWireA.lean b/proofs/Fl4ProofsA64/P3/Stage3VcpuExitWireA.lean index c83ba47e7..cbc3dde87 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VcpuExitWireA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VcpuExitWireA.lean @@ -75,7 +75,13 @@ structure VcpuExitInA (st : machine.Store S) [L : LawfulStore st] (ar : machine. hAK : VcpuArchKeepsA ar AR hVR : VcpuVmRootA st ar AR hMin : fl4MinBudget = MIN_BUDGET - hScPost : ∀ (s2 : S) (a2 : A) (hw2 : HwRootA) (σ2 : State Unit), + /-- [J] the budget facts after the exit's `complete_run`, guarded by the run: the FL4 `complete_run` that produced + `(s2, a2)` and the spec time-stamp and `DrA` steps from the entry state `σ`. -/ + hScPost : ∀ (sp : S) (ap : A) (ct stop w1 w2 w3 : U64) (s2 : S) (a2 : A) (hw2 : HwRootA) + (σ1 σa σ2 : State Unit) (ss : RunStop), + vcpu.complete_run st ar sp ap ct stop w1 w2 w3 = ok (s2, a2) → + updateTimeStamp (Z := Unit) σ = ({((), σ1)}, False) → + fl4CompleteRun (Z := Unit) (specPtr ct) ss w1.bv w2.bv w3.bv σa = ({((), σ2)}, False) → DrA σ1 σ2 → JStage3A st AR { Z with hw := hw2 } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes (J5A st) (J7A st (J7R2A st ar nA)) s2 a2 σ2 m → ScStateRelA st Z.C m s2 σ2 ∧ @@ -162,12 +168,15 @@ theorem exitRelA {nA : U64} {hw' : HwRootA} {s' : S} {a' : A} (I : VcpuExitInA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s a σ) (hCs : Z.Cs = Cs) (hts : updateTimeStamp (Z := Unit) σ = ({((), σ1)}, False)) (K : DrA σ1 σ') (J' : JStage3A st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ fl4A64Platform.numNodes - (J5A st) (J7A st (J7R2A st ar nA)) s' a' σ' m) : + (J5A st) (J7A st (J7R2A st ar nA)) s' a' σ' m) + (sp : S) (ap : A) (ct stop w1 w2 w3 : U64) (σa : State Unit) (ss : RunStop) + (hcr : vcpu.complete_run st ar sp ap ct stop w1 w2 w3 = ok (s', a')) + (hsr : fl4CompleteRun (Z := Unit) (specPtr ct) ss w1.bv w2.bv w3.bv σa = ({((), σ')}, False)) : A64RelS3 st AR ar nA fl4A64Platform.numNodes Cs s' a' σ' m := by obtain ⟨V1, CI1, R1, hkh, hcur, hcsc, hact⟩ := tsFactsA J I hts - obtain ⟨-, hsc, -, hsuf⟩ := I.hScPost s' a' hw' σ' J' - exact ⟨{ Z with hw := hw' }, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, hCs, J', - Sched.BodyOKA.ofExitA J I.en I.hNoSw V1 CI1 R1 hkh hcur hcsc hact K I.hMin hsc hsuf⟩ + obtain ⟨-, hsc, -, hsuf⟩ := I.hScPost sp ap ct stop w1 w2 w3 s' a' hw' σ1 σa σ' ss hcr hts hsr K J' + exact A64RelS3.ofJ J' + (Sched.BodyOKA.ofExitA J I.en I.hNoSw V1 CI1 R1 hkh hcur hcsc hact K I.hMin hsc hsuf) hCs /-- The guest entry `runExit`. -/ abbrev kRunExitE (stop w1 w2 w3 : U64) (stopSpec : RunStop) : KEventA := @@ -188,10 +197,10 @@ theorem kBody_runExitA (hPl : ArchPlat ar) have hE := CurEntryGA.of_cur I.en.curInv I.en.offReady J.sr.inv refine WP.spec_mono (JStage3A.vcpuRunExitA hPl J I.hNoSw I.hNow I.hNowAR I.hClock I.hClVm I.hClFlushState I.hClFr I.hnd I.hVMT I.hCS I.hNowEq hE I.hP I.hAK I.hVR I.hScPost hstop hne w1 w2 w3) ?_ - rintro ⟨s', a'⟩ ⟨hw', σ', σ1, hspec, hts, K, J'⟩ + rintro ⟨s', a'⟩ ⟨hw', σ', σ1, hspec, hts, K, J', sp, ap, ct, σa, ss, hcr, hsr⟩ have hm : ((), σ') ∈ (fl4HandleVcpuRunExit (Z := Unit) ⟨stopSpec, w1.bv, w2.bv, w3.bv⟩ σ).1 := by rw [hspec]; exact Set.mem_singleton _ - exact ⟨σ', hm, exitRelA J I hCs hts K J'⟩ + exact ⟨σ', hm, exitRelA J I hCs hts K J' sp ap ct stop w1 w2 w3 σa ss hcr hsr⟩ /-- **`hbody` of `kernelEntry_recGA` for `runVppi`** (module docstring). -/ theorem kBody_runVppiA (hPl : ArchPlat ar) @@ -205,10 +214,10 @@ theorem kBody_runVppiA (hPl : ArchPlat ar) have hE := CurEntryGA.of_cur I.en.curInv I.en.offReady J.sr.inv refine WP.spec_mono (JStage3A.vcpuRunVppiA hPl J I.hNoSw I.hNow I.hNowAR I.hClock hClMask I.hClVm I.hClFlushState I.hClFr I.hnd I.hVMT I.hCS I.hNowEq hE I.hP I.hAK I.hVR I.hScPost irq) ?_ - rintro ⟨s', a'⟩ ⟨hw', σ', σ1, hspec, hts, K, J'⟩ + rintro ⟨s', a'⟩ ⟨hw', σ', σ1, hspec, hts, K, J', sp, ap, ct, σa, ss, hcr, hsr⟩ have hm : ((), σ') ∈ (fl4HandleVcpuRunExit (Z := Unit) ⟨.vppi, irq.bv, 0, 0⟩ σ).1 := by rw [hspec]; exact Set.mem_singleton _ - exact ⟨σ', hm, exitRelA J I hCs hts K J'⟩ + exact ⟨σ', hm, exitRelA J I hCs hts K J' sp ap ct _ _ _ _ σa ss hcr hsr⟩ /-- **The `runExit` entry at the unified top** (module docstring): `kernelEntry_recGA` with `hbody` from `kBody_runExitA`; `hGap` and `hNat` (the ratified [S4] `hNative`) are the top's. -/ @@ -221,7 +230,7 @@ theorem kernelEntry_runExitA {tm : A → Nat → DeadlineViewA} {view : State Un {stop : U64} {stopSpec : RunStop} (hstop : stop.bv = stopSpec.word) (hne : stopSpec ≠ .vppi) (w1 w2 w3 : U64) (hGap : ∀ s' a' τ, kBodyA st ar s a (kRunExitE stop w1 w2 w3 stopSpec) = ok (s', a') → ((), τ) ∈ (kOpA (kRunExitE stop w1 w2 w3 stopSpec) σ).1 → - A64RelS3 st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → SchedGapFreeA st m s' a' τ ar tm view) + ∀ m', A64RelS3at st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view) (hNat : ∀ s' a' τ, kBodyA st ar s a (kRunExitE stop w1 w2 w3 stopSpec) = ok (s', a') → ((), τ) ∈ (kOpA (kRunExitE stop w1 w2 w3 stopSpec) σ).1 → A64RelS3 st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → ∀ τ1 τ2, @@ -244,7 +253,7 @@ theorem kernelEntry_runVppiA {tm : A → Nat → DeadlineViewA} {view : State Un (hClMask : ∀ a' ms (irq : U64) (b : Bool), Clock a' ms → ar.mask_irq a' irq b ⦃ a'' => Clock a'' ms ⦄) (irq : U64) (hGap : ∀ s' a' τ, kBodyA st ar s a (kRunVppiE irq) = ok (s', a') → ((), τ) ∈ (kOpA (kRunVppiE irq) σ).1 → - A64RelS3 st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → SchedGapFreeA st m s' a' τ ar tm view) + ∀ m', A64RelS3at st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m m' → SchedGapFreeA st m' s' a' τ ar tm view) (hNat : ∀ s' a' τ, kBodyA st ar s a (kRunVppiE irq) = ok (s', a') → ((), τ) ∈ (kOpA (kRunVppiE irq) σ).1 → A64RelS3 st AR ar hPl.ipa fl4A64Platform.numNodes Cs s' a' τ m → ∀ τ1 τ2, ((), τ1) ∈ (fl4Schedule kLimitA view τ).1 → ((), τ2) ∈ (fl4ActivateThread (Z := Unit) τ1).1 → diff --git a/proofs/Fl4ProofsA64/P3/Stage3VsBodyA.lean b/proofs/Fl4ProofsA64/P3/Stage3VsBodyA.lean index c68c34754..d04706f7b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VsBodyA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VsBodyA.lean @@ -139,7 +139,9 @@ theorem JSyscallA.ptUnmapBodyA [PlainStore st] (K : ArchKeepsA ar AR) (hIpa : ipc.lookup_extra_caps st s (L.curW s) buf info = ok (.Ok e) → SiteA st Z OS s σ info buf r1.slot e mi sl c excaps buffer argsU → info.label = fl4_abi.label.ARMPageTableUnmap ∧ - ∃ ptr mp asid va, capA st s r1.slot = .PageTable ptr mp asid va ∧ (mp = true → ptr ∉ Z.T2) ∧ + ∃ ptr mp asid va, capA st s r1.slot = .PageTable ptr mp asid va ∧ (mp = true → ptr ∈ Z.T2 → + (∃ k, asidRootKind σ (BitVec.ofNat 16 asid.val) = some k ∧ k ≠ .stage1) ∧ + PtUniqT2A st ar Z s a σ asid va ptr) ∧ (mp = true → 0xffff000000000000 ≤ va.val → c = absCapA (capA st s r1.slot))) : syscall.dispatch_syscall st ar s a (syscallNumberA call) ⦃ r => StepPostA (fun s a τ => A64RelS3 st AR ar hPl.ipa n Z.Cs s a τ m) diff --git a/proofs/Fl4ProofsA64/P3/Stage3VsRunA.lean b/proofs/Fl4ProofsA64/P3/Stage3VsRunA.lean index ca54292cd..39b2674f8 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VsRunA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VsRunA.lean @@ -96,7 +96,9 @@ theorem JSyscallA.ptUnmap_runA (hlab : info.label = fl4_abi.label.ARMPageTableUn {mp bB bC bD : Bool} (K : ArchKeepsA ar AR) (hIpa : S2IpaE ar a) (hcap : capA st s slot = .PageTable ptr mp asid va) -- open: Stage-2 tables (tracked in `Z.T2`) - (hT2 : mp = true → ptr ∉ Z.T2) + -- a Stage-2 table (`ptr ∈ Z.T2`) is mapped on a Stage-2 / high root and satisfies [J] `PtUniqT2A` + (hT2 : mp = true → ptr ∈ Z.T2 → (∃ k, asidRootKind σ (BitVec.ofNat 16 asid.val) = some k ∧ k ≠ .stage1) ∧ + PtUniqT2A st ar Z s a σ asid va ptr) -- [J] the canonical spec cap of a mapped high-window table (record edit #8b part C) (hcan : mp = true → 0xffff000000000000 ≤ va.val → c = absCapA (capA st s slot)) {s' : S} {a' : A} @@ -121,8 +123,18 @@ theorem JSyscallA.ptUnmap_runA (hlab : info.label = fl4_abi.label.ARMPageTableUn exact J.ptUnmapU_scopeA hA hM hPl hfm Q hlab (bB := bB) (bC := bC) (bD := bD) (bF := false) (ptr := ptr) (asid := asid) (va := va) (hcap := hcap) (hf := hf) | true => + by_cases hmem : ptr ∈ Z.T2 + · obtain ⟨⟨k, hk, hk1⟩, hU⟩ := hT2 rfl hmem + have hc : c = absCapA (capA st s slot) := by + by_cases h : va.val < 0xffff000000000000 + · have e : CapEqA (.PageTable ptr true asid va) c := hcap ▸ Q.F.cap.2 + rw [hcap]; exact ptCanon_loA e h + · exact hcan rfl (by omega) + exact J.ptUnmapT2_scopeA hA hM hPl hfm Q hlab (bB := bB) (bC := bC) (bD := bD) (bF := false) (K := K) + (hTO := J.tabS1) (hEO := J.tabExt) (hIpa := hIpa) (ptr := ptr) (asid := asid) (va := va) (hpT := hmem) + (hcap := hcap) (hf := hf) (k := k) (hkR := hk) (hkR1 := hk1) (hUniq := hU) (hcan := hc) have hpS : ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr := - J.ptMappedA Q.F.pin.habs (by rw [← Q.F.pin.hslot]; exact hcap) (hT2 rfl) + J.ptMappedA Q.F.pin.habs (by rw [← Q.F.pin.hslot]; exact hcap) hmem have hc : c = absCapA (capA st s slot) := by by_cases h : va.val < 0xffff000000000000 · have e : CapEqA (.PageTable ptr true asid va) c := hcap ▸ Q.F.cap.2 diff --git a/proofs/Fl4ProofsA64/P3/Stage3VsWriteA.lean b/proofs/Fl4ProofsA64/P3/Stage3VsWriteA.lean index 9c8657bcc..1ff54593b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VsWriteA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VsWriteA.lean @@ -45,8 +45,7 @@ structure VsSpecA (σ σ' : Fl4SpecA64.State Unit) : Prop where /-- (record edit #8b-B1) A `VsSpecA` step keeps the domain schedule. -/ theorem VsSpecA.domk {σ σ' : Fl4SpecA64.State Unit} (H : VsSpecA σ σ') : DomKeepA σ σ' := - ⟨congrArg (·.domainIndex) H.eq, congrArg (·.domainStartIndex) H.eq, congrArg (·.domainList) H.eq, - congrArg (·.archState.armUsGlobalVspace) H.eq⟩ + DomKeepA.ofKey (congrArg DomKeyA H.eq :) /-- A `VsSpecA` step keeps `arm_current_vcpu`. -/ theorem VsSpecA.vcur {σ σ' : Fl4SpecA64.State Unit} (H : VsSpecA σ σ') : diff --git a/proofs/Fl4ProofsA64/P3/Stage3WrapA.lean b/proofs/Fl4ProofsA64/P3/Stage3WrapA.lean index 1242eec11..6ae010427 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3WrapA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3WrapA.lean @@ -147,7 +147,7 @@ theorem Sched.BodyOKA.ofSame {J5 J7 : JSlotA S} /-- **The success epilogue after a decode that returned** (`set Running`, with the empty reply for a call), at the record at a body's end. -/ -theorem A64RelS3.epilogueA {Cs : Set U64} (R : A64RelS3 st AR ar nA n Cs s a σ m) (calling : Bool) +theorem A64RelS3fx.epilogueA {Cs : Set U64} (R : A64RelS3fx st AR ar nA n Cs s a σ m) (calling : Bool) (hP1 : EpiP1A st AR ar nA n m calling) {x : Fl4SpecA64.Tcb} (hx : σ.kheap σ.curThread = some (.tcb x)) (hr : x.tcbState = .restart) : ∃ s2 σ', epiRegsA st calling s (L.curW s) = ok s2 ∧ @@ -155,7 +155,7 @@ theorem A64RelS3.epilogueA {Cs : Set U64} (R : A64RelS3 st AR ar nA n Cs s a σ ((), σ') ∈ ((do Fl4Spec.NonDet.when (calling = true) (replyFromKernel (Z := Unit) σ.curThread (0, [])) setThreadState (Z := Unit) σ.curThread .running) σ).1 ∧ - A64RelS3 st AR ar nA n Cs (L.wr s2 (stA (L.curW s)) sched.TS_RUNNING) a σ' m := by + A64RelS3fx st AR ar nA n Cs (L.wr s2 (stA (L.curW s)) sched.TS_RUNNING) a σ' m := by obtain ⟨Z, H, OS, U, Ac, Pp, Tb, Lv, ia, ie, N, E, Rp, Bf, stack, κ, hCs, J, B⟩ := R have ct : σ.curThread = specPtr (L.curW s) := J.j.1.sch.curThread have htZ : L.curW s ∈ Z.T := J.sr.curT @@ -181,7 +181,7 @@ theorem A64RelS3.epilogueA {Cs : Set U64} (R : A64RelS3 st AR ar nA n Cs s a σ ((), σ') ∈ ((do Fl4Spec.NonDet.when (calling = true) (replyFromKernel (Z := Unit) σ.curThread (0, [])) setThreadState (Z := Unit) σ.curThread .running) σ).1 ∧ - A64RelS3 st AR ar nA n Cs (L.wr s2 (stA (L.curW s)) sched.TS_RUNNING) a σ' m := by + A64RelS3fx st AR ar nA n Cs (L.wr s2 (stA (L.curW s)) sched.TS_RUNNING) a σ' m := by intro uc s2 e2 V2 w2 spec have fin := fun σX : Fl4SpecA64.State Unit => hP1 Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ s a σ J hw s2 e2 σX @@ -193,7 +193,7 @@ theorem A64RelS3.epilogueA {Cs : Set U64} (R : A64RelS3 st AR ar nA n Cs s a σ e'.trans (congrArg (fun p => setObjA σ p (.tcb { x with tcbArch := { x.tcbArch with tcbContext := uc }, tcbState := .running })) ct.symm) have B' : Sched.BodyOKA σ' m := Sched.BodyOKA.runA (uc := uc) B hx hr e'' - exact ⟨s2, σ', e2, eRun, mem, A64RelS3.ofJ J' B' hCs⟩ + exact ⟨s2, σ', e2, eRun, mem, A64RelS3fx.ofJ J' B' hCs⟩ cases calling with | false => have e : setObjA σ (specPtr (L.curW s)) (.tcb { x with tcbArch := { x.tcbArch with tcbContext := x.tcbArch.tcbContext } }) = @@ -356,7 +356,7 @@ theorem JSyscallA.invocationA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSp ⦃ r => r.1 = .Ok () ∧ ∃ τ, (.ok (), τ) ∈ ((fl4HandleInvocationR (Z := Unit) rep calling blocking donate false (Fl4SpecA64.toBl cptr.bv)).run σ).1 ∧ A64RelS3 st AR ar hPl.ipa n Z.Cs r.2.1 r.2.2 τ m ⦄) - (hP1 : EpiP1A st AR ar hPl.ipa n m calling) : + (hP1 : ∀ m', EpiP1A st AR ar hPl.ipa n m' calling) : syscall.handle_invocation st ar s a calling blocking donate false cptr ⦃ r => ∃ e τ, (e, τ) ∈ ((fl4HandleInvocationR (Z := Unit) rep calling blocking donate false (Fl4SpecA64.toBl cptr.bv)).run σ).1 ∧ @@ -553,7 +553,8 @@ theorem JSyscallA.invocationA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSp unfold PerfSpecA at perfs rw [if_pos rfl] at perfs obtain ⟨reply, hcase⟩ := perfs - obtain ⟨Z', H', OS', U', Ac', Pp', Tb', Lv', ia', ie', N', E', Rp', Bf', stack', κ', hCs, J', B⟩ := id R + obtain ⟨m', hg, R'⟩ := id R + obtain ⟨Z', H', OS', U', Ac', Pp', Tb', Lv', ia', ie', N', E', Rp', Bf', stack', κ', hCs, J', B⟩ := id R' have htZ' : t ∈ Z'.T := by have h := J'.sr.curT rw [hcw] at h; exact h @@ -584,12 +585,12 @@ theorem JSyscallA.invocationA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSp · exact h · exact absurd yr (epiSpec_notRestartA hep y hy) have er := empty y hy yr - obtain ⟨s2, τ, e2, eRun, mem, R2⟩ := A64RelS3.epilogueA R calling hP1 (ct' ▸ hy) yr + obtain ⟨s2, τ, e2, eRun, mem, R2⟩ := A64RelS3fx.epilogueA R' calling (hP1 m') (ct' ▸ hy) yr rw [hcw] at e2 eRun R2 unfold epiRegsA at e2 rw [show (if calling = true then msg.reply_success_empty st s' t else ok s') = ok s2 from e2, bind_ok, eRun, bind_ok, WP.spec_ok] - refine ⟨.ok (), τ, finish σ' τ perf ?_, rfl, R2⟩ + refine ⟨.ok (), τ, finish σ' τ perf ?_, rfl, R2.toS3 hg⟩ unfold epiSpecA rw [nd_bind_oneA getSt, yr, er] rw [ct'] at mem diff --git a/proofs/Fl4ProofsA64/P3/SwapA.lean b/proofs/Fl4ProofsA64/P3/SwapA.lean index 69e94e1ad..a1ca19288 100644 --- a/proofs/Fl4ProofsA64/P3/SwapA.lean +++ b/proofs/Fl4ProofsA64/P3/SwapA.lean @@ -209,7 +209,7 @@ theorem swap_io_eqA (σ : State Unit) (s1 s2 : CslotPtr) (hne : s1 ≠ s2) : · simp [Function.update_of_ne h1, Function.update_of_ne h2, Equiv.swap_apply_of_ne_of_ne h1 h2] theorem SpecSlotA.swFin (σ : State Unit) (s1 s2 : CslotPtr) : SpecSlotA σ (swapFinA σ s1 s2) := - ⟨⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, fun _ => Or.inl rfl⟩ + ⟨SpecGlobA.ofKey rfl, fun _ => Or.inl rfl⟩ /-! ## The CDT after `cap_swap` -/ diff --git a/proofs/Fl4ProofsA64/P3/TcbInvokeReadCallFineA.lean b/proofs/Fl4ProofsA64/P3/TcbInvokeReadCallFineA.lean new file mode 100644 index 000000000..f34f810ab --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/TcbInvokeReadCallFineA.lean @@ -0,0 +1,182 @@ +/- +P3 (aarch64, A64-P3 Stage 4, line tcbregr): **`tcbReadRegisters_callReplyKA` with the fine write set**. + +GENERATED by `handoff/tools/gen_callFine.py` from `P3/TcbInvokeReadCallPostA` / `P3/TcbInvokeReadReplyA`: the concrete +Call reply (badge, payload loop, message tag) writes only the caller's register words and tracked IPC-buffer words +(`RcvRegA caller b ∨ BufW Bf b`), not the coarse `EWrite` (which includes endpoint and reply-object words). The record +lift of ReadRegisters Call needs the fine form (reply stacks, notification fields). Same hypotheses as `callReplyKA`. +No named premise. New module. +-/ +import Fl4ProofsA64.P3.TcbInvokeReadCallPostA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4SpecA64 Endp + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {T E R : Set U64} {Bf : Set (U64 × Word)} {SR : S → State Unit → Prop} +variable {s : S} {σ : State Unit} {caller : U64} {x : Tcb} + +private theorem readWordsLengthFA (regs : Register → Word) (n : Nat) (hN : n ≤ 36) : + (((frameRegisters ++ gpRegisters).take n).map regs).length = n := by + simp only [List.length_map, List.length_take, List.length_append, + show frameRegisters.length = 17 from rfl, show gpRegisters.length = 19 from rfl] + omega + +private theorem countBvFA {count : U64} {k : Nat} (h : count.val = k) (hk : k < 2 ^ 64) : + count.bv = natToLen k := by + apply BitVec.eq_of_toNat_eq + unfold natToLen + rw [BitVec.toNat_ofNat, Nat.mod_eq_of_lt hk] + exact h + +theorem tcbReadRegisters_tagPostFA (O : SchedOpsEA st T E R Bf SR) (P : EPlaced T E R Bf) + (hc : caller ∈ T) (hk : σ.kheap (specPtr caller) = some (.tcb x)) + (hE : EpStateRel T E R Bf (L.mem s) σ) (hS : SR s σ) (count : U64) (hn : count.val < 128) + {X : Type} {Q : X → Prop} (K : S → Result X) + (hK : ∀ s', (∃ σ', + setMessageInfo (specPtr caller) ⟨count.bv, 0, 0, 0⟩ σ = ({((), σ')}, False) ∧ + EpStateRel T E R Bf (L.mem s') σ' ∧ SR s' σ' ∧ WritesIn st s s' (fun b => RcvRegA caller b ∨ BufW Bf b) ∧ + (∃ x', σ'.kheap (specPtr caller) = some (.tcb x') ∧ x' = { x with tcbArch := x'.tcbArch }) ∧ + (∀ p, p ≠ specPtr caller → σ'.kheap p = σ.kheap p)) → K s' ⦃ Q ⦄) : + (do + let tag ← msginfo.MessageInfo.new 0#u64 0#u64 0#u64 count + let sTag ← msg.set_msg_info st s caller tag + K sTag) ⦃ Q ⦄ := by + simp only [msginfo.MessageInfo.new, bind_ok] + refine WP.spec_bind (set_msg_info_specA s caller 0#u64 count hn) ?_ + rintro s' ⟨v, rfl, hv⟩ + have hZero : (0#u64 : U64).bv &&& mask msgLabelBits = (0 : Word) := by rfl + have hWord := hv.trans (congrArg (fun label : Word => + messageInfoToData ⟨count.bv, 0, 0, label⟩) hZero) + obtain ⟨hRel, hWrite, hStep⟩ := Endp.write_reg_rel P s σ hE hc hk msg_info_register v + have hSR := O.stable _ _ _ _ hS hWrite hStep (NoBlockE.tcbK hk _ rfl rfl) + rw [regIdxA_msgInfo] at hRel hSR hWrite + have hfine : WritesIn st s (L.wr s (Endp.regA caller layout.reg.MSG_INFO) v) (fun b => RcvRegA caller b ∨ BufW Bf b) := by + have ha := (a_reg (P.tcb caller hc) msg_info_register).1 + rw [regIdxA_msgInfo] at ha + exact (writesIn_wr (s := s) (v := v) ha).mono fun b hb => Or.inl ⟨msg_info_register, by rw [hb, regIdxA_msgInfo]⟩ + refine hK _ ⟨_, ?_, hRel, hSR, hfine, ⟨Notif.setReg x msg_info_register v.bv, ?_, rfl⟩, fun p hp => ?_⟩ + · unfold setMessageInfo + rw [← hWord] + exact Notif.asUser_setRegister_eq msg_info_register v.bv hk + · rw [Notif.updK_kheap, Function.update_self] + · rw [Notif.updK_kheap, Function.update_of_ne hp] + +theorem tcbReadRegisters_callReplyFA {X : Type} {Q : X → Prop} (O : SchedOpsEA st T E R Bf SR) (P : EPlaced T E R Bf) + {th : TypedHeapA} (s : S) (σ : State Unit) + (hE : EpStateRel T E R Bf (L.mem s) σ) (hS : SR s σ) + (hSt : StateRelA th (L.mem s) σ) (hC : BufCover st T Bf s σ) (hNative : BufNativeA T (L.mem s)) + {src caller n : U64} (hs : src ∈ T) (hc : caller ∈ T) (hne : src ≠ caller) + (htc : th caller = some .tcb) {xs xc : Tcb} + (hks : σ.kheap (specPtr src) = some (.tcb xs)) (hkc : σ.kheap (specPtr caller) = some (.tcb xc)) + (hu : ∀ rp, ipcBufOfA true xc = some rp → ∀ k, k < 128 → inUserFrame (bufAddr rp k) σ) + (hN : n.val ≤ 36) (K : S → Result X) + (hK : ∀ s', (∃ σ', + replyFromKernel (specPtr caller) + (0, ((frameRegisters ++ gpRegisters).take n.val).map xs.tcbArch.tcbContext.userRegs) σ = + ({((), σ')}, False) ∧ + EpStateRel T E R Bf (L.mem s') σ' ∧ SR s' σ' ∧ WritesIn st s s' (fun b => RcvRegA caller b ∨ BufW Bf b) ∧ + (∃ xc', σ'.kheap (specPtr caller) = some (.tcb xc') ∧ xc' = { xc with tcbArch := xc'.tcbArch }) ∧ + (∀ p, p ≠ specPtr caller → σ'.kheap p = σ.kheap p)) → K s' ⦃ Q ⦄) : + (do + let buf ← msg.lookup_ipc_buffer st s true caller + let sBadge ← obj.Tcb.set_reg st caller s layout.reg.BADGE 0#u64 + let (sGp, count) ← tcbReadRegisters_dataProgramA (st := st) sBadge src caller n buf + let tag ← msginfo.MessageInfo.new 0#u64 0#u64 0#u64 count + let sTag ← msg.set_msg_info st sGp caller tag + K sTag) ⦃ Q ⦄ := by + have hu' : ∀ rp, ipcBufOfA true xc = some rp → ∀ k, k < 128 → + inUserFrame (bufAddr rp k) + (Notif.updK σ (specPtr caller) (.tcb (Notif.setReg xc badge_register 0))) := + fun rp h k hk => inUserFrame_updK hkc (fun _ h => by cases h) _ (hu rp h k hk) + have hOther : specPtr caller ≠ specPtr src := fun h => hne (specPtr_inj h).symm + have hksB : (Notif.updK σ (specPtr caller) (.tcb (Notif.setReg xc badge_register 0))).kheap + (specPtr src) = some (.tcb xs) := by + rw [Notif.updK_kheap, Function.update_of_ne (Ne.symm hOther)] + exact hks + have hxB : ∃ a, Notif.setReg xc badge_register 0 = { xc with tcbArch := a } := ⟨_, rfl⟩ + refine WP.spec_bind (lookup_buf_full s σ hSt htc hc hkc hC hNative true) ?_ + rintro w ⟨hw0, hwB⟩ + refine WP.spec_bind (tcbReadRegisters_badgePostA O P hc hkc hE hS) ?_ + rintro sB ⟨hsB, hBadge, hkB, hEB, hSB, hWB⟩ + have fB : WritesIn st s sB (fun b => RcvRegA caller b ∨ BufW Bf b) := by + have ha := (a_reg (P.tcb caller hc) badge_register).1 + rw [regIdxA_badge] at ha + rw [hsB] + exact (writesIn_wr (s := s) (v := 0#u64) ha).mono fun b hb => Or.inl ⟨badge_register, by rw [hb, regIdxA_badge]⟩ + obtain ⟨aB, hxBdef⟩ := hxB + generalize hσB : Notif.updK σ (specPtr caller) (.tcb (Notif.setReg xc badge_register 0)) = σB at * + generalize Notif.setReg xc badge_register 0 = xB at * + have hOthers : ∀ p, p ≠ specPtr caller → σB.kheap p = σ.kheap p := by + intro p hp + rw [← hσB, Notif.updK_kheap, Function.update_of_ne hp] + have hRegs : ∀ r, (L.mem sB (Endp.regA src (regIdxA r))).bv = xs.tcbArch.tcbContext.userRegs r := + fun r => (hEB.at_tcb hs hksB).regs r + rcases buf_caseA hw0 hwB with ⟨hnone, rfl⟩ | ⟨bp, hbp, hsome, rfl, hbp0⟩ + · -- no receive buffer: the message is truncated to the four inline registers + have hM := (msgLaw_nobuf O.to0 P hEB hSB hc hkB).withW P hc (Or.inl rfl) + refine WP.spec_bind (tcbReadRegisters_dataA P hs hc hne hM hRegs hN) ?_ + rintro ⟨sGp, count⟩ ⟨hCount, hI, hWI⟩ + have fI : WritesIn st sB sGp (fun b => RcvRegA caller b ∨ BufW Bf b) := + ⟨hWI.1, hWI.2.1, fun b hb hn => hI.2.2 b hb ⟨fun h => hn (Or.inl h), fun h => hn (Or.inr h)⟩⟩ + have hCount' : count.val = min n.val 4 := by simpa using hCount + set ms := ((frameRegisters ++ gpRegisters).take n.val).map xs.tcbArch.tcbContext.userRegs with hms + have hlen : ms.length = n.val := readWordsLengthFA _ _ hN + have hcountBv : count.bv = natToLen (min 4 ms.length) := by + rw [hlen, Nat.min_comm] + exact countBvFA hCount' (by omega) + refine tcbReadRegisters_tagPostFA O P hc + (mrStateNA_kheap σB (specPtr caller) xB ms) hI.1 hI.2.1 count (by omega) K ?_ + rintro sT ⟨σT, hTag, hET, hST, hWT, ⟨xT, hkT, hxT⟩, hOth⟩ + refine hK sT ⟨σT, ?_, hET, hST, (fB.trans1 fI).trans1 hWT, ⟨xT, hkT, ?_⟩, fun p hp => ?_⟩ + · refine tcbReadRegisters_replySpecA (σBadge := σB) + (σData := mrStateNA σB (specPtr caller) xB ms) (buf := none) (len := natToLen (min 4 ms.length)) ?_ hBadge ?_ ?_ + · rw [lookupIpcBuffer_eqA hkc true, hnone] + · exact setMrs_eqNA hkB ms + · rw [hcountBv] at hTag + exact hTag + · exact hxT.trans (by rw [hxBdef]; rfl) + · rw [hOth p hp] + unfold mrStateNA + rw [Notif.updK_kheap, Function.update_of_ne hp, hOthers p hp] + · -- a tracked receive buffer + have hM := (msgLaw_buf O.to0 P hEB hSB hc hkB hbp hbp0).withW P hc (Or.inr ⟨bp, hbp, rfl⟩) + refine WP.spec_bind (tcbReadRegisters_dataA P hs hc hne hM hRegs hN) ?_ + rintro ⟨sGp, count⟩ ⟨hCount, hI, hWI⟩ + have fI : WritesIn st sB sGp (fun b => RcvRegA caller b ∨ BufW Bf b) := + ⟨hWI.1, hWI.2.1, fun b hb hn => hI.2.2 b hb ⟨fun h => hn (Or.inl h), fun h => hn (Or.inr h)⟩⟩ + have hCount' : count.val = n.val := by simpa [hbp0] using hCount + set ms := ((frameRegisters ++ gpRegisters).take n.val).map xs.tcbArch.tcbContext.userRegs with hms + have hlen : ms.length = n.val := readWordsLengthFA _ _ hN + have hcountBv : count.bv = natToLen (min ms.length msgMaxLength) := by + rw [hlen, Nat.min_eq_left (show n.val ≤ msgMaxLength by unfold msgMaxLength; omega)] + exact countBvFA hCount' (by omega) + have hal : ∀ q ∈ mrPairs ms, (bufAddr bp.2 q.1).toNat % 8 = 0 ∧ + inUserFrame (bufAddr bp.2 q.1) σB := by + intro q hq + have := (List.of_mem_zip hq).1 + simp [List.mem_range'] at this + exact ⟨bufAddr_align (hEB.buf bp hbp 0#u64 (by decide)).2 _ (by omega), + hu' bp.2 hsome _ (by omega)⟩ + refine tcbReadRegisters_tagPostFA O P hc + (mrState_kheap σB (specPtr caller) xB bp.2 ms) hI.1 hI.2.1 count (by omega) K ?_ + rintro sT ⟨σT, hTag, hET, hST, hWT, ⟨xT, hkT, hxT⟩, hOth⟩ + refine hK sT ⟨σT, ?_, hET, hST, (fB.trans1 fI).trans1 hWT, ⟨xT, hkT, ?_⟩, fun p hp => ?_⟩ + · refine tcbReadRegisters_replySpecA (σBadge := σB) + (σData := mrState σB (specPtr caller) xB bp.2 ms) (buf := some bp.2) (len := natToLen (min ms.length msgMaxLength)) ?_ hBadge ?_ ?_ + · rw [lookupIpcBuffer_eqA hkc true, hsome] + · exact setMrs_eq hkB bp.2 ms hal + · rw [hcountBv] at hTag + exact hTag + · exact hxT.trans (by rw [hxBdef]; rfl) + · rw [hOth p hp] + show (Notif.updK σB (specPtr caller) _).kheap p = _ + rw [Notif.updK_kheap, Function.update_of_ne hp, hOthers p hp] + + + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/TcbInvokeTimerSpecA.lean b/proofs/Fl4ProofsA64/P3/TcbInvokeTimerSpecA.lean index b0043d587..1a6a668c8 100644 --- a/proofs/Fl4ProofsA64/P3/TcbInvokeTimerSpecA.lean +++ b/proofs/Fl4ProofsA64/P3/TcbInvokeTimerSpecA.lean @@ -28,7 +28,7 @@ theorem tcbSetTimer_specA (σ : State Unit) (target : ObjRef) (deadline : Time) have hm : ((), update σ) ∈ (Fl4Spec.NonDet.modify update σ).1 := by rfl exact mem_bind_ndD hm rfl -private theorem timerReprogram_wordA (old : U64) (earliest : Bool) : +theorem timerReprogram_wordA (old : U64) (earliest : Bool) : decide ((if earliest then 1#u64 else old) ≠ 0#u64) = (decide (old ≠ 0#u64) || earliest) := by cases earliest diff --git a/proofs/Fl4ProofsA64/P3/TcbSuspendA.lean b/proofs/Fl4ProofsA64/P3/TcbSuspendA.lean index a35383804..ba8d472c4 100644 --- a/proofs/Fl4ProofsA64/P3/TcbSuspendA.lean +++ b/proofs/Fl4ProofsA64/P3/TcbSuspendA.lean @@ -483,7 +483,7 @@ theorem suspend_refinesA (hP : IPlacedA N Z.T E R Bf) (P : IpcSchedPlacementA Z. · rcases hK with rfl | rfl | rfl <;> simp refine ⟨RN0.frame hP.n (fun b hb hf => w.mem_eq hb fun h => notifFootOffMWrA H9 P.notification hf h) ⟨fun _ _ h => by rw [hkh]; exact h, fun _ z h => ⟨z, by rw [hkh]; exact h, rfl, rfl, rfl⟩⟩, - E0.frame PE (epFrameOfMcsA H9 P (σ := σ0) (σ' := σ0) ⟨w, SKeepA.refl _, SSzA.refl _⟩ rfl).1 KV, + E0.frame PE (epFrameOfMcsA H9 P (σ := σ0) (σ' := σ0) (MFrA.ofParts w (SKeepA.refl _) (SSzA.refl _)) rfl).1 KV, S0.frame (fun d hd => ?_) (fun c _ y k hy => ⟨y, k, by rw [hkh]; exact hy, rfl⟩) (fun d _ y hy => ⟨y, by rw [hkh] at hy; exact hy, rfl⟩), fun u hu y hy => ?_, fun u hu K hK => ?_, fun u hu => w.mem_eq (field_aligned (H9.core.tcbs u hu) (K := 3456#u64) (by decide) (by decide)) diff --git a/proofs/Fl4ProofsA64/P3/TcbWriteBridgeA.lean b/proofs/Fl4ProofsA64/P3/TcbWriteBridgeA.lean new file mode 100644 index 000000000..a7eb41003 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/TcbWriteBridgeA.lean @@ -0,0 +1,129 @@ +/- +P3 (AArch64, A64-P3 Stage 4, line tcbregw): **the bridge between the WriteRegisters loops' exact register prefix +(`tcbWritePrefixA`, Tcb level) and the abstract register body (`tcbWriteRegisters_userA`, user-context fold)**. + +* **`tcbWriteTcb_eqA`**: the frame prefix, the GP prefix and the `FaultIP -> NextIP` copy of the loops are the TCB + `tcbWriteRegisters_userA` produces, when the abstract `values` are the argument words `2 ..` of the snapshot. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.TcbWriteViewA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open Fl4SpecA64 + +noncomputable section + +/-- The (register, raw word) pairs of the first `n` writes of one loop. -/ +def wrPairsA (rs : List Register) (off : Nat) (arg : Nat → Word) (n : Nat) : List (Register × Word) := + (List.range n).map fun k => (rs.getD k .faultIP, arg (k + off)) + +/-- Apply sanitised register writes to a TCB, in order. -/ +def wrFoldA (g : Bool) (l : List (Register × Word)) (x : Tcb) : Tcb := + l.foldl (fun x p => Notif.setReg x p.1 (fl4SanitiseRegister g p.1 p.2)) x + +theorem tcbWritePrefixA_eq_foldA (g : Bool) (rs : List Register) (off : Nat) (arg : Nat → Word) (x : Tcb) + (n : Nat) : tcbWritePrefixA g rs off arg x n = wrFoldA g (wrPairsA rs off arg n) x := by + induction n with + | zero => rfl + | succ n ih => + rw [tcbWritePrefixA, ih] + simp only [wrPairsA, wrFoldA, List.range_succ, List.map_append, List.foldl_append, List.map_cons, + List.map_nil, List.foldl_cons, List.foldl_nil] + +/-- The user context after sanitised register writes, in order. -/ +def wrCtxA (g : Bool) (l : List (Register × Word)) (uc : UserContext) : UserContext := + l.foldl (fun c rv => Notif.setRegUc c rv.1 (fl4SanitiseRegister g rv.1 rv.2)) uc + +theorem wrFold_ctxA (g : Bool) (l : List (Register × Word)) (x : Tcb) : + wrFoldA g l x = + { x with tcbArch := archTcbContextSet (wrCtxA g l (archTcbContextGet x.tcbArch)) x.tcbArch } := by + induction l generalizing x with + | nil => cases x; rfl + | cons p l ih => + simp only [wrFoldA, wrCtxA, List.foldl_cons] at ih ⊢ + rw [ih] + rfl + +theorem wrPairs_zipA (args : Nat → Word) (c : Nat) : + wrPairsA frameRegisters 2 args (min 17 c) ++ wrPairsA gpRegisters 19 args (min 19 (c - 17)) = + (frameRegisters ++ gpRegisters).zip ((List.range c).map fun i => args (i + 2)) := by + have hf : frameRegisters.length = 17 := rfl + have hg : gpRegisters.length = 19 := rfl + apply List.ext_getElem + · simp only [wrPairsA, List.length_append, List.length_map, List.length_range, List.length_zip, hf, hg] + omega + · intro i h1 h2 + have hlen1 : i < min 17 c + min 19 (c - 17) := by simpa [wrPairsA] using h1 + by_cases hi : i < 17 + · have hm : i < min 17 c := by omega + have hmf : i < frameRegisters.length := by omega + simp only [List.getElem_append, wrPairsA, List.length_map, List.length_range, List.getElem_map, + List.getElem_range, List.getElem_zip, dif_pos hm, dif_pos hmf] + rw [List.getD_eq_getElem _ _ hmf] + · have hm : ¬ i < min 17 c := by omega + have hmf : ¬ i < frameRegisters.length := by omega + have e : min 17 c = frameRegisters.length := by omega + have hj : i - frameRegisters.length < gpRegisters.length := by omega + simp only [List.getElem_append, wrPairsA, List.length_map, List.length_range, List.getElem_map, + List.getElem_range, List.getElem_zip, dif_neg hm, dif_neg hmf, e] + rw [List.getD_eq_getElem _ _ hj] + refine Prod.ext rfl ?_ + show args (i - frameRegisters.length + 19) = args (i + 2) + congr 1 + omega + +/-- The destination TCB after the two loops and the `NextIP` copy (the loops' exact register prefix). -/ +def writeRegsTcbA (g : Bool) (args : Nat → Word) (y : Tcb) (count : Nat) : Tcb := + let gp := tcbWritePrefixA g gpRegisters 19 args (tcbWritePrefixA g frameRegisters 2 args y + (min frameRegisters.length count)) (min gpRegisters.length (count - 17)) + Notif.setReg gp .nextIP (gp.tcbArch.tcbContext.userRegs .faultIP) + +theorem writeRegsTcbA_arch (g : Bool) (args : Nat → Word) (y : Tcb) (count : Nat) : + writeRegsTcbA g args y count = { y with tcbArch := (writeRegsTcbA g args y count).tcbArch } := by + unfold writeRegsTcbA + simp only [tcbWritePrefixA_eq_foldA, wrFold_ctxA] + rfl + +theorem writeRegsTcbA_vcpu (g : Bool) (args : Nat → Word) (y : Tcb) (count : Nat) : + (writeRegsTcbA g args y count).tcbArch.tcbVcpu = y.tcbArch.tcbVcpu := by + unfold writeRegsTcbA + simp only [tcbWritePrefixA_eq_foldA, wrFold_ctxA] + rfl + +theorem writeRegsTcbA_state (g : Bool) (args : Nat → Word) (y : Tcb) (count : Nat) : + (writeRegsTcbA g args y count).tcbState = y.tcbState := by + unfold writeRegsTcbA + simp only [tcbWritePrefixA_eq_foldA, wrFold_ctxA] + rfl + +/-- The frame prefix, the GP prefix and the `FaultIP -> NextIP` copy of the loops (run with the clamped count `c'`) +are the abstract register body's TCB (`tcbWriteRegisters_userA`) for the argument words `2 ..` of the snapshot `args` +(`c` words, `c' = min 36 c`). -/ +theorem writeRegsTcbA_eq (g : Bool) (args : Nat → Word) (x : Tcb) (c c' : Nat) + (h1 : min 17 c' = min 17 c) (h2 : min 19 (c' - 17) = min 19 (c - 17)) : + let values := (List.range c).map fun i => args (i + 2) + let written := tcbWrittenContextA g (frameRegisters ++ gpRegisters) values (archTcbContextGet x.tcbArch) + writeRegsTcbA g args x c' = + { x with tcbArch := archTcbContextSet (Notif.setRegUc written .nextIP (written.userRegs .faultIP)) x.tcbArch } := by + intro values written + have hf : frameRegisters.length = 17 := rfl + have hg : gpRegisters.length = 19 := rfl + unfold writeRegsTcbA + simp only [hf, hg, h1, h2] + set gp := tcbWritePrefixA g gpRegisters 19 args (tcbWritePrefixA g frameRegisters 2 args x (min 17 c)) + (min 19 (c - 17)) with hgp + have e1 : gp = wrFoldA g (wrPairsA frameRegisters 2 args (min 17 c) ++ wrPairsA gpRegisters 19 args (min 19 (c - 17))) x := by + simp only [hgp, tcbWritePrefixA_eq_foldA, wrFoldA, List.foldl_append] + rw [wrPairs_zipA] at e1 + have e2 : gp = { x with tcbArch := archTcbContextSet written x.tcbArch } := by + rw [e1, wrFold_ctxA] + rfl + rw [e2] + rfl + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtChunkA.lean b/proofs/Fl4ProofsA64/P3/UtChunkA.lean index 7e6d2b463..90e37cafe 100644 --- a/proofs/Fl4ProofsA64/P3/UtChunkA.lean +++ b/proofs/Fl4ProofsA64/P3/UtChunkA.lean @@ -91,7 +91,7 @@ theorem JAtZAX.of_lowerA {AR : A → HwRootA → Prop} {Z : XSetsA} {s : S} {a : have hSR := StateRelA.setCn (σ' := setObjA σ (specPtr q) (.cnode idx.length (Function.update cs idx (some sc)))) J.1.st hP1 hth hk rfl hca' hcapo rfl have HS : SpecSlotA σ (setObjA σ (specPtr q) (.cnode idx.length (Function.update cs idx (some sc)))) := - SpecSlotA.setCn hk rfl ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + SpecSlotA.setCn hk rfl (SpecGlobA.ofKey rfl) have C1 := J.1.cdt have hC : CdtRelA st Z.th (L.wr (L.wr s (cslotAddrA (specPtr q, idx)) w0) (wa (cslotAddrA (specPtr q, idx)) 8#u64) w1) (setObjA σ (specPtr q) (.cnode idx.length (Function.update cs idx (some sc)))) Z.G := diff --git a/proofs/Fl4ProofsA64/P3/UtDecExA.lean b/proofs/Fl4ProofsA64/P3/UtDecExA.lean new file mode 100644 index 000000000..94f5373f0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtDecExA.lean @@ -0,0 +1,161 @@ +/- +P3 (aarch64, A64-P3 Untyped): **the decode-level tops with a spec outcome**: FL4's result matches an existing outcome of +the spec's invocation (`fl4InvokeUntypedA64`) from the restarted state, and the record holds at that outcome. + +* `utDecode_recNoResetExA`: no reset. +* `utDecode_recResetExA`: with a reset, the preempted outcome included. + +From `utDecode_recNoResetA` / `utDecode_recResetA` and their premises. MakePool's top (`makePool_perform_dropA`) +already concludes a spec outcome. No named premise. New theorems only. +-/ +import Fl4ProofsA64.P3.UtDecRecA +import Fl4ProofsA64.P3.UtDecRecRstA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4SpecA64 Fl4Spec Classical + +noncomputable section + +/-- `Q` may be weakened in `UPostA`. -/ +theorem UPostA.monoQ {S A : Type} {σ : Fl4SpecA64.State Unit} + {m : Fl4SpecA64.SEMonad Unit Fl4SpecA64.UntypedInvocation} {s : S} {a : A} + {Q Q' : Fl4SpecA64.UntypedInvocation → core.result.Result Unit error.Exc × S × A → Prop} + {res : core.result.Result Unit error.Exc × S × A} (h : UPostA σ m s a Q res) (g : ∀ inv, Q inv res → Q' inv res) : + UPostA σ m s a Q' res := + h.imp id fun ⟨inv, r, q⟩ => ⟨inv, r, g inv q⟩ + +/-- A preempted reset preempts FL4's untyped invocation. -/ +theorem utInvokeA64_preempted_memA {srcSlot : CslotPtr} {base retypeBase : Word} {t : ApiObjectType} {objSz : Nat} + {slots : List CslotPtr} {dev : Bool} {σ σr : State Unit} + (hr : (.error (), σr) ∈ ((resetUntypedCap (Z := Unit) srcSlot).run σ).1) : + (.error (), σr) ∈ ((fl4InvokeUntypedA64 (Z := Unit) + (.retype srcSlot true base retypeBase t objSz slots dev)).run σ).1 := by + unfold fl4InvokeUntypedA64 + exact mem_bindE_errD (utInvoke_preempted_memA hr) + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rq : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {s : S} {a : A} {σ : State Unit} {m : McState} + +set_option maxHeartbeats 1000000 in +/-- **The decode-level top, no reset, with its spec outcome** (module docstring). -/ +theorem utDecode_recNoResetExA (hA : P0.ArchTotal ar) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rq Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {p sb fi : U64} (ex : Aeneas.Std.Array obj.Slot 3#usize) + (sl : CslotPtr) (hsrc : ∃ q, sl.1 = specPtr q ∧ Z.th q = some (.cnode sl.2.length)) + {Ud Acd : Set U64} + (D : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ud Acd s (.Untyped p sb fi false) ex) + (P : SysPlace st H Z.Cs H.frame H.replies H.ntfns OS s ex (cslotAddrA sl)) + (hcapF : obj.Slot.cap st (cslotAddrA sl) s = ok (.Untyped p sb fi false)) + (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) + (hfm : A64FrameMasks st s) + (vi : U64) (hvi : ar.virtualization a = ok vi) (hvirt : vi = 0#u64 ↔ fl4A64Virt = false) + (hfan : Fl4SpecA64.retypeFanOutLimit = 256#64) + (lbl : U64) (slbl : Fl4SpecA64.Data) + (hlbl : Fl4SpecA64.genInvocationType slbl = .untypedRetype ↔ lbl = fl4_abi.label.UntypedRetype) + (length buf : U64) (args : List U64) (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s (L.curW s) buf i = ok x) + (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) (hex : ExtraOKA Z.th (L.mem s) ex exs) + (hchild : ∃ x, σ.cdt x = some sl) + -- the arch facts of the creation + (hVP : ∀ a1 : A, UtVcpuPlatA ar a1) {k : U64 → U64} + (hKt : ∀ (a1 : A) (i : U64), i.val < 511 → ar.kernel_ttbr1_entry a1 0#u64 i = ok (k i)) + (hK0 : ∀ i : U64, i.val < 256 → k i = 0#u64) : + untyped.decode st ar s a lbl length (cslotAddrA sl) (.Untyped p sb fi false) buf ex ⦃ res => + UPostA σ (fl4DecodeUntypedInvocationVirt (Z := Unit) slbl (args.map UScalar.bv) sl + (absCapA (.Untyped p sb fi false)) (exs.map Prod.fst)) s a + (fun inv res => res.1 = .Ok () ∧ ∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + ∃ σ', (.ok (), σ') ∈ ((fl4InvokeUntypedA64 (Z := Unit) inv).run (stUpdA σ σ.curThread xT .restart)).1 ∧ + ∃ aligned nt usF dest off win : U64, + UtArgs st s ex (cslotAddrA sl) p sb fi false false aligned nt usF dest off win ∧ + ∃ (H'' : Heap) (Z'' : XSetsA) (OS'' U'' Ac' Pp'' Tb'' N'' E'' Rp'' : Set U64) + (stack'' : U64 → List U64) (κ'' : U64 → U64) (m'' : McState), + JStage3A st AR Z'' H'' OS'' U'' Ac' Pp'' Tb'' Lv ia ie N'' E'' Rp'' Bf stack'' κ'' n (J5A st) + (J7A st (J7R2A st ar nA)) res.2.1 res.2.2 σ' m'' ∧ + Z'' = utRecZA Z (cslotAddrA sl) nt usF aligned dest off win ∧ + OS'' = OS ∪ NewSl false nt usF aligned win ∧ + m'' = utRtMA m (UtOfTyA 1 nt usF aligned win.val)) res ⦄ := by + refine WP.spec_mono (utDecode_recNoResetA hA J ex sl hsrc D P hcapF RS hfm vi hvi hvirt hfan lbl slbl hlbl length buf + args hlen hargs exs hex hchild hVP hKt hK0) fun res h => h.monoQ fun inv g => ?_ + obtain ⟨base, retypeBase, t, us, slots, rfl, hok, xT, hkT, aligned, nt, usF, dest, off, win, hU, ⟨r, hr⟩, K⟩ := g + obtain ⟨vm, -, H'', Z'', OS'', U'', Ac', Pp'', Tb'', N'', E'', Rp'', stack'', κ'', m'', J', eZ, eO, eM⟩ := K r hr + obtain ⟨⟨⟩, σ1⟩ := r + exact ⟨hok, xT, hkT, _, vm _ _ _ _ _ (utInvoke_noReset_memA hr), aligned, nt, usF, dest, off, win, hU, H'', Z'', + OS'', U'', Ac', Pp'', Tb'', N'', E'', Rp'', stack'', κ'', m'', J', eZ, eO, eM⟩ + +set_option maxHeartbeats 1000000 in +/-- **The decode-level top, with a reset, with its spec outcome** (module docstring). -/ +theorem utDecode_recResetExA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA : P0.ArchTotal ar) + (sact : SActA σ) + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rq Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + {p sb fi : U64} (ex : Aeneas.Std.Array obj.Slot 3#usize) + (sl : CslotPtr) (hsrc : ∃ q, sl.1 = specPtr q ∧ Z.th q = some (.cnode sl.2.length)) + {Ud Acd : Set U64} + (D : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ud Acd s (.Untyped p sb fi false) ex) + (P : SysPlace st H Z.Cs H.frame H.replies H.ntfns OS s ex (cslotAddrA sl)) + (hcapF : obj.Slot.cap st (cslotAddrA sl) s = ok (.Untyped p sb fi false)) + (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) + (hfm : A64FrameMasks st s) + (vi : U64) (hvi : ar.virtualization a = ok vi) (hvirt : vi = 0#u64 ↔ fl4A64Virt = false) + (hfan : Fl4SpecA64.retypeFanOutLimit = 256#64) + (lbl : U64) (slbl : Fl4SpecA64.Data) + (hlbl : Fl4SpecA64.genInvocationType slbl = .untypedRetype ↔ lbl = fl4_abi.label.UntypedRetype) + (length buf : U64) (args : List U64) (hlen : length.val = args.length) + (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s (L.curW s) buf i = ok x) + (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) (hex : ExtraOKA Z.th (L.mem s) ex exs) + (hnochild : ¬ ∃ x, σ.cdt x = some sl) + (othT : ∀ c ∈ Z.Cs, c ≠ L.cpu s → specPtr (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) + (L.nodeAt (L.wr s (stA (L.curW s)) sched.TS_RESTART) c layout.node.CUR_THREAD)) ∉ utDA p sb.val) + (othC : ∀ c ∈ Z.Cs, c ≠ L.cpu s → specPtr (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) + (L.nodeAt (L.wr s (stA (L.curW s)) sched.TS_RESTART) c layout.node.CUR_SC)) ∉ utDA p sb.val) + -- the decode-site's own state has no other core's current thread or SC in the region either + (othT0 : ∀ c ∈ Z.Cs, c ≠ L.cpu s → specPtr (L.mem s (L.nodeAt s c layout.node.CUR_THREAD)) ∉ utDA p sb.val) + (othC0 : ∀ c ∈ Z.Cs, c ≠ L.cpu s → specPtr (L.mem s (L.nodeAt s c layout.node.CUR_SC)) ∉ utDA p sb.val) + -- the reset + (hn : nA.val = fl4A64Platform.s2IpaBits) + (hPost : fi ≠ 0#u64 → ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + (hchunk : resetChunkBits = 16) + -- [S] the reset never runs the chunk loop: nothing to clear, or a block below the chunk size + (hS : sb.val < 16 ∨ fi = 0#u64) + -- the arch facts of the creation + (hVP : ∀ a1 : A, UtVcpuPlatA ar a1) {k : U64 → U64} + (hKt : ∀ (a1 : A) (i : U64), i.val < 511 → ar.kernel_ttbr1_entry a1 0#u64 i = ok (k i)) + (hK0 : ∀ i : U64, i.val < 256 → k i = 0#u64) : + untyped.decode st ar s a lbl length (cslotAddrA sl) (.Untyped p sb fi false) buf ex ⦃ res => + UPostA σ (fl4DecodeUntypedInvocationVirt (Z := Unit) slbl (args.map UScalar.bv) sl + (absCapA (.Untyped p sb fi false)) (exs.map Prod.fst)) s a + (fun inv res => ∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + ∃ (aligned nt usF dest off win : U64), + UtArgs st s ex (cslotAddrA sl) p sb fi false true aligned nt usF dest off win ∧ + (res.1 = .Ok () ∧ + ∃ σ3, (.ok (), σ3) ∈ ((resetUntypedCap (Z := Unit) sl).run (stUpdA σ σ.curThread xT .restart)).1 ∧ + UtKeepCurA (stUpdA σ σ.curThread xT .restart) σ3 ∧ + ∃ σ', (.ok (), σ') ∈ ((fl4InvokeUntypedA64 (Z := Unit) inv).run + (stUpdA σ σ.curThread xT .restart)).1 ∧ + ∃ (Z0 : XSetsA) (m0 : McState), + (Z0 = Z ∧ m0 = m ∨ Z0 = dropZA (utDA p sb.val) Z ∧ m0 = dropMA (utDA p sb.val) m) ∧ + UtKeepA σ3 σ' ∧ + ∃ (H'' : Heap) (OS'' U'' Ac' Pp'' Tb'' N'' E'' Rp'' : Set U64) + (Bf'' : Set (U64 × Fl4SpecA64.Word)) (stack'' : U64 → List U64) (κ'' : U64 → U64), + JStage3A st AR (utRecZA Z0 (cslotAddrA sl) nt usF aligned dest off win) H'' OS'' U'' Ac' Pp'' + Tb'' Lv ia ie N'' E'' Rp'' Bf'' stack'' κ'' n (J5A st) (J7A st (J7R2A st ar nA)) res.2.1 + res.2.2 σ' (utRtMA m0 (UtOfTyA 1 nt usF aligned win.val)))) res ⦄ := by + refine WP.spec_mono (utDecode_recResetA hA sact J ex sl hsrc D P hcapF RS hfm vi hvi hvirt hfan lbl slbl hlbl length + buf args hlen hargs exs hex hnochild othT othC othT0 othC0 hn hPost hchunk hS hVP hKt hK0) fun res h => + h.monoQ fun inv g => ?_ + obtain ⟨base, retypeBase, t, us, slots, rfl, xT, hkT, aligned, nt, usF, dest, off, win, rd, hU, rfl, rfl, rfl, rfl, + hok, σ3, hm, kc, Z0, m0, hZ, ⟨r, hr⟩, K⟩ := g + obtain ⟨vm, kp, H'', OS'', U'', Ac', Pp'', Tb'', N'', E'', Rp'', Bf'', stack'', κ'', J'⟩ := K r hr + obtain ⟨⟨⟩, σ1⟩ := r + exact ⟨xT, hkT, aligned, nt, usF, dest, off, win, hU, hok, σ3, hm, kc, _, vm _ _ _ _ _ (utInvoke_reset_memA hm hr), + Z0, m0, hZ, kp, H'', OS'', U'', Ac', Pp'', Tb'', N'', E'', Rp'', Bf'', stack'', κ'', J'⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtDecRecA.lean b/proofs/Fl4ProofsA64/P3/UtDecRecA.lean index b0fca4ff3..f12aa8664 100644 --- a/proofs/Fl4ProofsA64/P3/UtDecRecA.lean +++ b/proofs/Fl4ProofsA64/P3/UtDecRecA.lean @@ -16,6 +16,7 @@ import Fl4ProofsA64.P1.S1aKtRetype import Fl4ProofsA64.P3.UtFullJ7A import Fl4ProofsA64.P3.UtRtTopA import Fl4ProofsA64.P3.UtRtRecTopA +import Fl4ProofsA64.P3.UtRtNewPlaceA import Fl4ProofsA64.P1.S1aRtTopK open Aeneas Aeneas.Std Result @@ -132,10 +133,6 @@ theorem utDecode_recNoResetA (hA : P0.ArchTotal ar) (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s (L.curW s) buf i = ok x) (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) (hex : ExtraOKA Z.th (L.mem s) ex exs) (hchild : ∃ x, σ.cdt x = some sl) - (hnew : ∀ aligned nt us dest off win : U64, - UtArgs st s ex (cslotAddrA sl) p sb fi false false aligned nt us dest off win → - PlaceA (utRtThA Z.th false nt us aligned win.val) (L.ksb s) ∧ - ∀ j, j < win.val → utRangedA nt.val → SpNoOvA (bjA aligned (zA nt.val us) j) (zOfA nt.val us.val)) -- the arch facts of the creation (hVP : ∀ a1 : A, UtVcpuPlatA ar a1) {k : U64 → U64} (hKt : ∀ (a1 : A) (i : U64), i.val < 511 → ar.kernel_ttbr1_entry a1 0#u64 i = ok (k i)) @@ -148,13 +145,16 @@ theorem utDecode_recNoResetA (hA : P0.ArchTotal ar) ∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ ∃ aligned nt usF dest off win : U64, UtArgs st s ex (cslotAddrA sl) p sb fi false false aligned nt usF dest off win ∧ + (∃ r, r ∈ (utRtBodyA sl base retypeBase t us slots false (stUpdA σ σ.curThread xT .restart)).1) ∧ ∀ r ∈ (utRtBodyA sl base retypeBase t us slots false (stUpdA σ σ.curThread xT .restart)).1, - UtInvVcA t retypeBase us slots r.2 ∧ ∃ (H'' : Heap) (Z'' : XSetsA) (OS'' U'' Ac' Pp'' Tb'' N'' E'' Rp'' : Set U64) + UtInvVcA t retypeBase us slots r.2 ∧ + UtKeepA (stUpdA σ σ.curThread xT .restart) (utInvStA t retypeBase us slots r.2) ∧ ∃ (H'' : Heap) (Z'' : XSetsA) (OS'' U'' Ac' Pp'' Tb'' N'' E'' Rp'' : Set U64) (stack'' : U64 → List U64) (κ'' : U64 → U64) (m'' : McState), JStage3A st AR Z'' H'' OS'' U'' Ac' Pp'' Tb'' Lv ia ie N'' E'' Rp'' Bf stack'' κ'' n (J5A st) (J7A st (J7R2A st ar nA)) res.2.1 res.2.2 (utInvStA t retypeBase us slots r.2) m'' ∧ Z'' = utRecZA Z (cslotAddrA sl) nt usF aligned dest off win ∧ - OS'' = OS ∪ NewSl false nt usF aligned win) res ⦄ := by + OS'' = OS ∪ NewSl false nt usF aligned win ∧ + m'' = utRtMA m (UtOfTyA 1 nt usF aligned win.val)) res ⦄ := by have Je := J.toJEntA have hV : SlotsValidA Z.th (L.mem s) := Je.j.1.cv have hpos : ∀ p k, Z.th p = some k → 0 < k.size := fun p k h => by @@ -207,7 +207,6 @@ theorem utDecode_recNoResetA (hA : P0.ArchTotal ar) unfold revA at h0 ⊢ rw [e24]; exact h0 have hc2 : capA st s2 (cslotAddrA sl) = .Untyped p sb fi false := by rw [hOS1.capA hsO]; exact hcap - obtain ⟨hP', hno⟩ := hnew aligned nt us dest off win hU have hb0 : 0 < aligned.val := by have hp0 : 0 < p.val := J.sys.sysl.ly.ut0 _ hsO p sb fi hcap have g := (CrtA.of_args R hU).pa @@ -233,6 +232,8 @@ theorem utDecode_recNoResetA (hA : P0.ArchTotal ar) rw [g] exact Nat.mul_mod_left _ _ have hpf : aligned.val + win.val * 2 ^ (zA nt.val us).val ≤ 2 ^ 64 := le_trans h2 CA.pf + obtain ⟨hP', hno⟩ := utRt_newPlaceA J hsO hcap + (utWinZ_decA C.hn X.size.1 C.hz hpf hal2) h1 h2 C.hn X.size.1 hb0 have hks : L.ksb s2 = L.ksb s := L.ksb_wr _ _ _ have sA : Aligned (stA (L.curW s)) := by rw [stA_eq]; exact field_aligned (J.sq.tcbs _ J.sq.curT) (by simp) (by simp) @@ -248,10 +249,10 @@ theorem utDecode_recNoResetA (hA : P0.ArchTotal ar) refine WP.spec_mono (WP.spec_and (utCreate_recA hA J J2 C X hcap hsrc hUe hb0 hal8 hpf hal2 (by rw [hks]; exact hP') hno hVP hKt hK0 hkw noch RS.vs (fun b hb hne => mem_wr_ne' sA hb hne.symm)) hJ7) fun res g => ?_ - obtain ⟨⟨hok, K⟩, Vn, lo, hi, rt, arm, ko', j7at⟩ := g - refine ⟨_, _, _, _, _, rfl, hok, xT, hkT, aligned, nt, us, dest, off, win, hU, fun r hr => ?_⟩ - obtain ⟨vm, Ac', g⟩ := K r hr H' Vn _ _ lo hi _ rt arm ko' j7at - exact ⟨vm, _, _, _, _, _, _, _, _, _, _, _, _, _, g, rfl, rfl⟩ + obtain ⟨⟨hok, ne, K⟩, Vn, lo, hi, rt, arm, ko', j7at⟩ := g + refine ⟨_, _, _, _, _, rfl, hok, xT, hkT, aligned, nt, us, dest, off, win, hU, ne, fun r hr => ?_⟩ + obtain ⟨vm, kp, Ac', g⟩ := K r hr H' Vn _ _ lo hi _ rt arm ko' j7at + exact ⟨vm, kp, _, _, _, _, _, _, _, _, _, _, _, _, _, g, rfl, rfl, rfl⟩ end site2 diff --git a/proofs/Fl4ProofsA64/P3/UtDecRecRstA.lean b/proofs/Fl4ProofsA64/P3/UtDecRecRstA.lean index 001bff763..ec1a0e129 100644 --- a/proofs/Fl4ProofsA64/P3/UtDecRecRstA.lean +++ b/proofs/Fl4ProofsA64/P3/UtDecRecRstA.lean @@ -16,6 +16,8 @@ Premises: those of `utDecode_resetPostA`. New theorems only. import Fl4ProofsA64.P1.S1aKtRetype import Fl4ProofsA64.P3.UtRtRecRstA import Fl4ProofsA64.P3.UtRtResetCrtA +import Fl4ProofsA64.P3.UtRtResetNpA +import Fl4ProofsA64.P3.UtRtNewPlaceA import Fl4ProofsA64.P3.UtFullJ7A import Fl4ProofsA64.P1.S1aRtTopRst @@ -105,12 +107,16 @@ variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : {ia ie : Nat} {N E Rq : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {nA : U64} {s : S} {a : A} {σ : State Unit} {m : McState} -/-- The record after a creation over the sets `Z0` and view `m0`: for every outcome of the spec body from `σ3`. -/ +/-- The record after a creation over the sets `Z0` and view `m0`: the spec body has an outcome from `σ3`, and the record +holds for every one. -/ def UtRstRecA (AR : A → HwRootA → Prop) (Z0 : XSetsA) (m0 : McState) (sl : CslotPtr) (p aligned nt us dest off win : U64) (t : ApiObjectType) (rd : Nat) (σ3 : State Unit) (s' : S) (a' : A) (Lv : U64 → Nat) (ia ie n : Nat) (ar : machine.Arch A) (nA : U64) (st' : machine.Store S) [LawfulStore st'] : Prop := + (∃ r, r ∈ (utRtBodyA sl (specPtr p) (specPtr aligned) t us.val (windowSlotsA dest rd off.val win.val) false + σ3).1) ∧ ∀ r ∈ (utRtBodyA sl (specPtr p) (specPtr aligned) t us.val (windowSlotsA dest rd off.val win.val) false σ3).1, UtInvVcA t (specPtr aligned) us.val (windowSlotsA dest rd off.val win.val) r.2 ∧ + UtKeepA σ3 (utInvStA t (specPtr aligned) us.val (windowSlotsA dest rd off.val win.val) r.2) ∧ ∃ (H'' : Heap) (OS'' U'' Ac' Pp'' Tb'' N'' E'' Rp'' : Set U64) (Bf'' : Set (U64 × Fl4SpecA64.Word)) (stack'' : U64 → List U64) (κ'' : U64 → U64), JStage3A (S := S) st' AR (utRecZA Z0 (cslotAddrA sl) nt us aligned dest off win) H'' OS'' U'' Ac' Pp'' Tb'' Lv ia @@ -139,11 +145,6 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA (hargs : ∀ (i : U64) x, args[i.val]? = some x → msg.syscall_arg st s (L.curW s) buf i = ok x) (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) (hex : ExtraOKA Z.th (L.mem s) ex exs) (hnochild : ¬ ∃ x, σ.cdt x = some sl) - (hnew : ∀ aligned nt us dest off win : U64, - UtArgs st s ex (cslotAddrA sl) p sb fi false true aligned nt us dest off win → - PlaceA (utRtThA (dropThA (utDA p sb.val) Z.th) false nt us aligned win.val) (L.ksb s) ∧ - PlaceA (utRtThA Z.th false nt us aligned win.val) (L.ksb s) ∧ - ∀ j, j < win.val → utRangedA nt.val → SpNoOvA (bjA aligned (zA nt.val us) j) (zOfA nt.val us.val)) (othT : ∀ c ∈ Z.Cs, c ≠ L.cpu s → specPtr (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) (L.nodeAt (L.wr s (stA (L.curW s)) sched.TS_RESTART) c layout.node.CUR_THREAD)) ∉ utDA p sb.val) (othC : ∀ c ∈ Z.Cs, c ≠ L.cpu s → specPtr (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) @@ -153,27 +154,10 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA (othC0 : ∀ c ∈ Z.Cs, c ≠ L.cpu s → specPtr (L.mem s (L.nodeAt s c layout.node.CUR_SC)) ∉ utDA p sb.val) -- the reset (hn : nA.val = fl4A64Platform.s2IpaBits) - (hPost : ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + (hPost : fi ≠ 0#u64 → ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) (hchunk : resetChunkBits = 16) - (hnd : numDomains = 1) {Clock : A → MachineState → Prop} (Pc : NowAgreeA ar Clock) - (hvp : ∀ (s : S) (a : A) (σ : State Unit), - JStage3A st AR (dropZA (utDA p sb.val) Z) (dropHA (utDA p sb.val) H) (dropSetA (utDA p sb.val) OS) U Ac - (dropSetA (utDA p sb.val) Pp) Tb Lv ia ie (dropSetA (utDA p sb.val) N) (dropSetA (utDA p sb.val) E) - (dropSetA (utDA p sb.val) Rq) (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n (J5A st) - (J7A st (J7R2A st ar nA)) s a σ (dropMA (utDA p sb.val) m) → - ∀ b, VsR (L.ksb s) (dropSetA (utDA p sb.val) Pp ∪ Tb) b → Aligned b ∧ ¬ PPW st s b) - (hC : ∀ i, fl4RawCounterOracle i ≤ fl4RawCounterOracle (i + 1)) - (hNow : ∀ σ : State Unit, fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) - (hAr : ∀ (s : S) (a : A), AR a Z.hw → sched.update_timestamp st ar s a ⦃ r => AR r.2 Z.hw ⦄) - (hirq : ∀ (a : A) (σ : State Unit), AR a Z.hw → Clock a σ.machineState → - ar.irq_pending a ⦃ r => ∃ o ms, (o, { σ with machineState := ms }) ∈ - (doMachineOp (getActiveIRQ true) σ).1 ∧ (r.1 = true ↔ ¬ o = none) ∧ - ms.underlyingMemory = σ.machineState.underlyingMemory ∧ - ms.lastMachineTime = σ.machineState.lastMachineTime ∧ ms.timeState = σ.machineState.timeState ∧ - Clock r.2 ms ∧ AR r.2 Z.hw ⦄) - (hmb : ∀ a : A, sporadic.min_budget ar a ⦃ mb => mb.bv = Fl4SpecA64.MIN_BUDGET ⦄) - (hT0 : ∀ xT, σ.kheap σ.curThread = some (.tcb xT) → - UtPpTimeA Clock a (utDelStA (specPtr p) sb.val (stUpdA σ σ.curThread xT .restart))) + -- [S] the reset never runs the chunk loop: nothing to clear, or a block below the chunk size + (hS : sb.val < 16 ∨ fi = 0#u64) -- the arch facts of the creation (hVP : ∀ a1 : A, UtVcpuPlatA ar a1) {k : U64 → U64} (hKt : ∀ (a1 : A) (i : U64), i.val < 511 → ar.kernel_ttbr1_entry a1 0#u64 i = ok (k i)) @@ -188,18 +172,12 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA UtArgs st s ex (cslotAddrA sl) p sb fi false true aligned nt usF dest off win ∧ base = specPtr p ∧ retypeBase = specPtr aligned ∧ us = usF.val ∧ slots = windowSlotsA dest rd off.val win.val ∧ - ((res.1 = .Ok () ∧ ∃ σ3, + (res.1 = .Ok () ∧ ∃ σ3, (.ok (), σ3) ∈ ((resetUntypedCap (Z := Unit) sl).run (stUpdA σ σ.curThread xT .restart)).1 ∧ + UtKeepCurA (stUpdA σ σ.curThread xT .restart) σ3 ∧ ∃ (Z0 : XSetsA) (m0 : McState), (Z0 = Z ∧ m0 = m ∨ Z0 = dropZA (utDA p sb.val) Z ∧ m0 = dropMA (utDA p sb.val) m) ∧ - UtRstRecA AR Z0 m0 sl p aligned nt usF dest off win t rd σ3 res.2.1 res.2.2 Lv ia ie n ar nA st) - ∨ (res.1 = .Err .Preempted ∧ ∃ σ3, - (.error (), σ3) ∈ ((resetUntypedCap (Z := Unit) sl).run (stUpdA σ σ.curThread xT .restart)).1 ∧ - JStage3A st AR (dropZA (utDA p sb.val) Z) (dropHA (utDA p sb.val) H) (dropSetA (utDA p sb.val) OS) - U Ac (dropSetA (utDA p sb.val) Pp) Tb Lv ia ie (dropSetA (utDA p sb.val) N) - (dropSetA (utDA p sb.val) E) (dropSetA (utDA p sb.val) Rq) - (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n (J5A st) (J7A st (J7R2A st ar nA)) - res.2.1 res.2.2 σ3 (dropMA (utDA p sb.val) m)))) res ⦄ := by + UtRstRecA AR Z0 m0 sl p aligned nt usF dest off win t rd σ3 res.2.1 res.2.2 Lv ia ie n ar nA st)) res ⦄ := by have hsub : ∀ y, IsSlotA Z.th y → y ∈ OS := J.j5.2.1 have hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null := J.j5.2.2 obtain ⟨qc, hq, hth⟩ := hsrc @@ -254,7 +232,6 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA have g := align_up_valA hv64 (by rw [fw]; omega) eal rw [g] exact Nat.mul_mod_left _ _ - obtain ⟨hPd, hPk, hno⟩ := hnew aligned nt us dest off win hU -- a new `HighVSpace` window is in the kernel window: its untyped is ([J] `utWin`) have hkw' : nt.val = 14 → 18446603336221196288 ≤ aligned.val := fun _ => by have w := (J.utWin _ hsO p sb fi hcap).1 @@ -307,7 +284,10 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA exact this have X' : UtCtxA st (dropZA (utDA p sb.val) Z).th s σ sl p sb fi false nt us dest off win t rd true fiv := { X with cnode := ⟨dropThA_someA.2 ⟨destK, hdest⟩, hrd, hrd0, yc, rr, gs, g, yS', ycap⟩ } - obtain ⟨-, -, -, -, hth', -⟩ := utReset_startA J D P hcapF he RS.sym othT0 othC0 hn sl hq hth rfl + obtain ⟨J2d, -, Cl0, -, hth', -⟩ := utReset_startA J D P hcapF he RS.sym othT0 othC0 hn sl hq hth rfl + obtain ⟨hPd, hno⟩ := utRt_newPlaceGenA (Z0 := dropZA (utDA p sb.val) Z) (H0 := dropHA (utDA p sb.val) H) + J2d.j.1.place (UtClrA.mono Cl0 (by have := hA0; omega) (by have := hAw; omega)) J.sys.ent.ksw + (J.utWin _ hsO p sb fi hcap) (utWinZ_decA C.hn X.size.1 C.hz hpf hal2) (by have := hA0; omega) hAw C.hn X.size.1 hb0 obtain ⟨H', hUe, hJ7⟩ := utRt_j7RstA hA J.sys D P RS.sym hcapF J.j7 J.ko e hU eres rw [C0.heapB, C0.slotsB] at hUe hJ7 obtain ⟨offr, offr2⟩ := utRt_offSetsA (st := st) (s := s) (slot := cslotAddrA sl) (p := p) (sb := sb) J3.setsInH @@ -316,25 +296,18 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA (by rw [kb3]; exact hPd) hno hVP hKt hK0 hkw' (Z0 := dropZA (utDA p sb.val) Z) rfl (fun _ h => h.1) (fun _ h => h.1) (fun _ h => h.1) (fun _ h => h.1) (fun _ h => h.1) (fun _ h => h.1) offr offr2 vcD) hJ7) fun res g => ?_ obtain ⟨⟨hok, K⟩, Vn, lo, hi, rt, arm, ko', j7at⟩ := g - refine ⟨hok, fun r hr => ?_⟩ - obtain ⟨vm, Ac', g⟩ := K r hr _ Vn _ _ lo hi _ rt arm ko' j7at - exact ⟨vm, _, _, _, _, _, _, _, _, _, _, _, _, g⟩ - refine utRetype_resetPpA ar sl hq hth Y hn hPost hchunk hnd Pc hvp hC hNow hAr hirq hmb (hT0 y hkT) aligned nt us dest - off win _ ?hnoop ?hsmall ?hbig ?hpre - case hpre => - intro s3 a3 σ3 hm J3 - exact ⟨_, _, _, _, _, rfl, y, hkT, aligned, nt, us, dest, off, win, rd, hU, rfl, rfl, rfl, rfl, - Or.inr ⟨rfl, σ3, hm, J3⟩⟩ + have ne := utRt_neA J3 C.src C.cap (utWinZ_decA C.hn X'.size.1 C.hz hpf hal2) C.ar.2.2.2.1 C.ar.2.2.2.2.1 + X'.ty X'.size.1 ⟨qc, hq, hth'⟩ (utWindow_lengthA dest rd off.val win.val) + (fun d hd => let ⟨q, e, hq', _⟩ := (utCtx_dstLenA X').1 d hd; ⟨q, e, hq'⟩) (specPtr p) + refine ⟨hok, ne, fun r hr => ?_⟩ + obtain ⟨vm, kp', Ac', g⟩ := K r hr _ Vn _ _ lo hi _ rt arm ko' j7at + exact ⟨vm, kp', _, _, _, _, _, _, _, _, _, _, _, _, g⟩ + refine utRetype_resetNpA ar sl hq hth Y hn hPost hchunk hS aligned nt us dest off win _ ?hnoop ?hsmall case hsmall => - intro _ _ s3 σ3 eres hm J3 _ _ + intro _ _ s3 σ3 eres hm J3 _ _ kp refine WP.spec_mono (drop s3 a σ3 eres J3) fun res h => ?_ exact ⟨_, _, _, _, _, rfl, y, hkT, aligned, nt, us, dest, off, win, rd, hU, rfl, rfl, rfl, rfl, - Or.inl ⟨h.1, σ3, hm, _, _, Or.inr ⟨rfl, rfl⟩, h.2⟩⟩ - case hbig => - intro _ _ s3 a3 σ3 _ _ eres hm I _ - refine WP.spec_mono (drop s3 a3 σ3 eres I.rec_) fun res h => ?_ - exact ⟨_, _, _, _, _, rfl, y, hkT, aligned, nt, us, dest, off, win, rd, hU, rfl, rfl, rfl, rfl, - Or.inl ⟨h.1, σ3, hm, _, _, Or.inr ⟨rfl, rfl⟩, h.2⟩⟩ + h.1, σ3, hm, kp, _, _, Or.inr ⟨rfl, rfl⟩, h.2⟩ case hnoop => intro h0 eres hm obtain ⟨C1, -, -⟩ := utCrtP_resetA hA R e a a hU eres @@ -368,6 +341,10 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA rw [eH, eO] at C1 obtain ⟨H', hUe, hJ7⟩ := utRt_j7RstA hA J.sys D P RS.sym hcapF J.j7 J.ko e hU eres rw [eH, eO] at hUe hJ7 + have hfi0 : fi.val = 0 := by rw [h0]; rfl + obtain ⟨hPk, hno⟩ := utRt_newPlaceGenA (Z0 := Z) (H0 := H) J.j.1.place + (utRt_winClrA J hsO hcap (by have := hA0; omega) hAw) J.sys.ent.ksw (J.utWin _ hsO p sb fi hcap) + (utWinZ_decA C1.hn X.size.1 C1.hz hpf hal2) (by have := hA0; omega) hAw C1.hn X.size.1 hb0 obtain ⟨offr, offr2⟩ := utRt_offSetsA (st := st) (s := s) (slot := cslotAddrA sl) (p := p) (sb := sb) J2.setsInH J2.sys.ent.heap offH refine WP.spec_mono (WP.spec_and (utCreate_recRstA hA J J2 C1 X hcap ⟨qc, hq, hth⟩ hUe hb0 hal8 hpf hal2 @@ -375,9 +352,13 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA subset_rfl subset_rfl offr offr2 vc) hJ7) fun res g => ?_ obtain ⟨⟨hok, K⟩, Vn, lo, hi, rt, arm, ko', j7at⟩ := g refine ⟨_, _, _, _, _, rfl, y, hkT, aligned, nt, us, dest, off, win, rd, hU, rfl, rfl, rfl, rfl, - Or.inl ⟨hok, σ2, hm, Z, m, Or.inl ⟨rfl, rfl⟩, fun r hr => ?_⟩⟩ - obtain ⟨vm, Ac', g⟩ := K r hr _ Vn _ _ lo hi _ rt arm ko' j7at - exact ⟨vm, _, _, _, _, _, _, _, _, _, _, _, _, g⟩ + ⟨hok, σ2, hm, UtKeepCurA.refl σ2, Z, m, Or.inl ⟨rfl, rfl⟩, + utRt_neA J2 C1.src C1.cap (utWinZ_decA C1.hn X.size.1 C1.hz hpf hal2) C1.ar.2.2.2.1 C1.ar.2.2.2.2.1 + X.ty X.size.1 ⟨qc, hq, hth⟩ (utWindow_lengthA dest rd off.val win.val) + (fun d hd => let ⟨q, e, hq', _⟩ := (utCtx_dstLenA X).1 d hd; ⟨q, e, hq'⟩) (specPtr p), + fun r hr => ?_⟩⟩ + obtain ⟨vm, kp', Ac', g⟩ := K r hr _ Vn _ _ lo hi _ rt arm ko' j7at + exact ⟨vm, kp', _, _, _, _, _, _, _, _, _, _, _, _, g⟩ end diff --git a/proofs/Fl4ProofsA64/P3/UtDropTopA.lean b/proofs/Fl4ProofsA64/P3/UtDropTopA.lean index ea1a99a86..c97f508fd 100644 --- a/proofs/Fl4ProofsA64/P3/UtDropTopA.lean +++ b/proofs/Fl4ProofsA64/P3/UtDropTopA.lean @@ -599,8 +599,8 @@ theorem utDrop_genA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] ipiZero := J.ipiZero ipcSorted := (J.ipcSorted.mono (Set.image_mono (show dropSetA D E ⊆ E from fun _ h => h.1)) (Set.image_mono (show dropSetA D N ⊆ N from fun _ h => h.1))).of_q - (QKeepA.of_back (fun _ _ h => (detype_someA.1 h).2) ⟨rfl, rfl, rfl, rfl⟩) - activeReplyScs := J.activeReplyScs.of_q (QKeepA.of_back (fun _ _ h => (detype_someA.1 h).2) ⟨rfl, rfl, rfl, rfl⟩) + (QKeepA.of_back (fun _ _ h => (detype_someA.1 h).2) (DomKeepA.ofKey rfl)) + activeReplyScs := J.activeReplyScs.of_q (QKeepA.of_back (fun _ _ h => (detype_someA.1 h).2) (DomKeepA.ofKey rfl)) bufVs := fun b ⟨bp, hbp, e⟩ => by have eP : utVsPtA st (dropSetA D Pp) Tb Lv s = utVsPtA st Pp Tb Lv s := by unfold utVsPtA diff --git a/proofs/Fl4ProofsA64/P3/UtFrA.lean b/proofs/Fl4ProofsA64/P3/UtFrA.lean index a55d3aecf..0a893801a 100644 --- a/proofs/Fl4ProofsA64/P3/UtFrA.lean +++ b/proofs/Fl4ProofsA64/P3/UtFrA.lean @@ -59,7 +59,7 @@ theorem UtCnStepA.refl (σ : State Unit) : UtCnStepA σ σ := ⟨SpecGlobA.refl /-- Rewriting one CNode's slots. -/ theorem UtCnStepA.set {σ : State Unit} {p : ObjRef} {r : Nat} {cs cs' : CnodeContents} (h : σ.kheap p = some (.cnode r cs)) : UtCnStepA σ (setObjA σ p (.cnode r cs')) := by - refine ⟨⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, fun q => ?_, rfl⟩ + refine ⟨SpecGlobA.ofKey rfl, fun q => ?_, rfl⟩ by_cases e : q = p · subst e; exact Or.inr ⟨r, cs, cs', h, Function.update_self ..⟩ · exact Or.inl (Function.update_of_ne e ..) diff --git a/proofs/Fl4ProofsA64/P3/UtKeepA.lean b/proofs/Fl4ProofsA64/P3/UtKeepA.lean new file mode 100644 index 000000000..72c9569f3 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtKeepA.lean @@ -0,0 +1,51 @@ +/- +P3 (aarch64, A64-P3 Untyped, Stage 4 dispatch): **what the whole Retype invocation keeps of the spec state the +dispatch reads** (`Sched.BodyOKA`): the globals (`SpecGlobA`), the last machine time, and every TCB and SC object. + +* `UtKeepA σ σ'`: the four facts. +* `UtKeepA.ofNew`: from the body's `UtNewObjA` (`utRtBody_newObjA`) and `utRtBody_lastA`. +* `UtKeepA.vcInit`: across `vcpu::init` on the new VCPUs (`utVcInitA` only rewrites VCPU objects). + +No named premise. New definitions and theorems only. +-/ +import Fl4ProofsA64.P3.UtRtLastA +import Fl4ProofsA64.P3.UtFullIpcA +import Fl4ProofsA64.P3.UtVcInitA +import Fl4ProofsA64.P3.UtKeepCurA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open Fl4SpecA64 Classical + +noncomputable section + +/-- The facts of a Retype invocation `BodyOKA` reads (module docstring). -/ +structure UtKeepA (σ σ' : State Unit) : Prop where + glob : SpecGlobA σ σ' + last : σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime + tcb : ∀ p x, σ.kheap p = some (.tcb x) → σ'.kheap p = some (.tcb x) + sc : ∀ p y k, σ.kheap p = some (.schedContext y k) → σ'.kheap p = some (.schedContext y k) + +theorem UtKeepA.cur {σ σ' : State Unit} (K : UtKeepA σ σ') : UtKeepCurA σ σ' := + ⟨K.glob, K.last, fun x h => K.tcb _ x h, fun y k h => K.sc _ y k h⟩ + +theorem UtKeepA.ofNew {σ σ' : State Unit} {P : ObjRef → Prop} {d : KernelObject} (O : UtNewObjA σ σ' P d) + (h : σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime) : UtKeepA σ σ' := + ⟨O.glob, h, fun p x g => O.keep p _ g (fun _ _ e => by cases e), + fun p y k g => O.keep p _ g (fun _ _ e => by cases e)⟩ + +theorem UtKeepA.vcInit {σ σ' : State Unit} (K : UtKeepA σ σ') (Q : ObjRef → Prop) : + UtKeepA σ (utVcInitA Q σ') := by + refine ⟨K.glob.trans ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, + K.last, fun p x g => ?_, fun p y k g => ?_⟩ + · have h := K.tcb p x g + show (if Q p then (σ'.kheap p).map utVcObjA else σ'.kheap p) = _ + split_ifs <;> simp [h, utVcObjA] + · have h := K.sc p y k g + show (if Q p then (σ'.kheap p).map utVcObjA else σ'.kheap p) = _ + split_ifs <;> simp [h, utVcObjA] + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtKeepCurA.lean b/proofs/Fl4ProofsA64/P3/UtKeepCurA.lean new file mode 100644 index 000000000..624ca7c86 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtKeepCurA.lean @@ -0,0 +1,90 @@ +/- +P3 (aarch64, A64-P3 Untyped, Stage 4 dispatch, reset arm): **what a Retype that resets keeps of the caller's spec state** +(`Sched.BodyOKA`): the globals (`SpecGlobA`), the last machine time, and the *current* thread's TCB and the *current* +SC. `UtKeepA` keeps every TCB and SC, which a reset does not (it deletes the objects of the untyped's region). + +* `UtKeepCurA σ σ'`: the four facts; `refl`, `trans`. +* `UtKeepCurA.ofDelStep`: from `delete_objects` of a region (`utDelStA`) followed by CNode writes (`UtCnStepA`), given that + the current thread and SC exist afterwards (the record at the dropped sets). + +No named premise. New definitions and theorems only. +-/ +import Fl4ProofsA64.P3.UtFrA +import Fl4ProofsA64.P3.UtResetSpecA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open Fl4SpecA64 Classical + +noncomputable section + +/-- The facts of a Retype invocation that resets that `BodyOKA` reads (module docstring). -/ +structure UtKeepCurA (σ σ' : State Unit) : Prop where + glob : SpecGlobA σ σ' + last : σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime + tcb : ∀ x, σ.kheap σ.curThread = some (.tcb x) → σ'.kheap σ.curThread = some (.tcb x) + sc : ∀ y k, σ.kheap σ.curSc = some (.schedContext y k) → σ'.kheap σ.curSc = some (.schedContext y k) + +theorem UtKeepCurA.refl (σ : State Unit) : UtKeepCurA σ σ := + ⟨SpecGlobA.refl σ, rfl, fun _ h => h, fun _ _ h => h⟩ + +theorem UtKeepCurA.trans {σ1 σ2 σ3 : State Unit} (h1 : UtKeepCurA σ1 σ2) (h2 : UtKeepCurA σ2 σ3) : + UtKeepCurA σ1 σ3 where + glob := h1.glob.trans h2.glob + last := h2.last.trans h1.last + tcb x h := by + have h' := h2.tcb x (by rw [h1.glob.cur]; exact h1.tcb x h) + rwa [h1.glob.cur] at h' + sc y k h := by + have h' := h2.sc y k (by rw [h1.glob.csc]; exact h1.sc y k h) + rwa [h1.glob.csc] at h' + +theorem utDelStA_lastA (pu : Fl4SpecA64.Word) (sz : Nat) (σ : State Unit) : + (utDelStA pu sz σ).machineState.lastMachineTime = σ.machineState.lastMachineTime := rfl + +/-- **`delete_objects` of a region and CNode writes keep the current thread and SC** (module docstring). -/ +theorem UtKeepCurA.ofDelStep {σ σ3 : State Unit} {pu : Fl4SpecA64.Word} {sz : Nat} + (hS : UtCnStepA (utDelStA pu sz σ) σ3) + (hl : σ3.machineState.lastMachineTime = σ.machineState.lastMachineTime) + (hT : ∃ y, σ3.kheap σ3.curThread = some (.tcb y)) + (hC : ∃ y k, σ3.kheap σ3.curSc = some (.schedContext y k)) : UtKeepCurA σ σ3 := by + have hg : SpecGlobA σ σ3 := + (SpecGlobA.ofKey rfl : SpecGlobA σ (utDelStA pu sz σ)).trans hS.toSpecGlobA + have key : ∀ q o, (∀ r cs, o ≠ KernelObject.cnode r cs) → σ3.kheap q = some o → σ.kheap q = some o := by + intro q o ho h + rcases hS.kh q with e | ⟨r, cs, cs', h1, h2⟩ + · rw [e] at h + by_cases hq : q ∈ {x | pu ≤ x ∧ x ≤ pu + 2 ^ sz - 1} + · have e3 : (utDelStA pu sz σ).kheap q = none := by + unfold utDelStA detype + dsimp only + exact if_pos hq + rw [e3] at h + cases h + · have e3 : (utDelStA pu sz σ).kheap q = σ.kheap q := by + unfold utDelStA detype + dsimp only + exact if_neg hq + rw [e3] at h + exact h + · rw [h2] at h + cases h + exact absurd rfl (ho _ _) + refine ⟨hg, hl, fun x hx => ?_, fun y k hk => ?_⟩ + · obtain ⟨y, hy⟩ := hT + rw [hg.cur] at hy + have h := key _ _ (fun r cs e => by cases e) hy + rw [hx] at h + cases h + exact hy + · obtain ⟨y', k', hy⟩ := hC + rw [hg.csc] at hy + have h := key _ _ (fun r cs e => by cases e) hy + rw [hk] at h + cases h + exact hy + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtResetA.lean b/proofs/Fl4ProofsA64/P3/UtResetA.lean index d2365eed7..cf41f1a15 100644 --- a/proofs/Fl4ProofsA64/P3/UtResetA.lean +++ b/proofs/Fl4ProofsA64/P3/UtResetA.lean @@ -29,6 +29,7 @@ import Fl4ProofsA64.P3.UtSbufA import Fl4ProofsA64.P3.UtSysPlaceA import Fl4ProofsA64.P3.UtResetRunA import Fl4ProofsA64.P3.UtResetLoopA +import Fl4ProofsA64.P3.UtKeepCurA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -203,6 +204,42 @@ theorem utReset_startA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] exact ⟨J2, Y1, Cl, hslots, dropThA_someA.2 ⟨qcK, hth⟩, ⟨hx, xK⟩, hheap, hlink, horig, hz, hsp, hzn, utSysPlace_recA J Dp P hcap he zb C.heapB C.slotsB⟩ +/-- `set_cap` keeps the spec machine state. -/ +theorem ut_setCap_msA {cap : Cap} {sl : CslotPtr} {σ : State Unit} {r : Unit × State Unit} + (hr : r ∈ (setCap (Z := Unit) cap sl σ).1) : r.2.machineState = σ.machineState := by + obtain ⟨oref, cref⟩ := sl + obtain ⟨x, hx, hr⟩ := mem_bindA.1 hr + obtain ⟨e1, -⟩ := getObject_mem hx + obtain ⟨obj, σ1⟩ := x + simp only at e1 hr + subst e1 + have key : ∀ o : KernelObject, r ∈ ((Pure.pure o >>= fun o' => setObject (Z := Unit) oref o') σ1).1 → + r.2.machineState = σ1.machineState := by + intro o h + obtain ⟨y, hy, h⟩ := mem_bindA.1 h + obtain rfl : y = (o, σ1) := hy + obtain ⟨o0, -, hr2⟩ := setObject_mem h + rw [hr2] + have kfail : ∀ f : KernelObject → NonDet (State Unit) Unit, r ∈ ((NonDet.fail >>= f) σ1).1 → False := by + intro f h + obtain ⟨y, hy, -⟩ := mem_bindA.1 h + exact absurd hy (Set.notMem_empty _) + cases obj with + | cnode sz cn => + simp only at hr + split_ifs at hr + · exact key _ hr + · exact (kfail _ hr).elim + | tcb t => + simp only at hr + split_ifs at hr <;> + first + | exact (kfail _ hr).elim + | exact key _ hr + | _ => + try simp only at hr + exact (kfail _ hr).elim + set_option maxHeartbeats 1000000 in /-- **A used RAM untyped below the chunk size** (module docstring). -/ theorem utReset_smallA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar : machine.Arch A) @@ -226,7 +263,8 @@ theorem utReset_smallA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar : m (dropSetA (utDA p sb.val) Pp) Tb Lv ia ie (dropSetA (utDA p sb.val) N) (dropSetA (utDA p sb.val) E) (dropSetA (utDA p sb.val) Rp) (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s2 a σ2 (dropMA (utDA p sb.val) m) ∧ - SymL st (dropHA (utDA p sb.val) H) Z.Cs s2 ∧ capA st s2 x = .Untyped p sb 0#u64 false := by + SymL st (dropHA (utDA p sb.val) H) Z.Cs s2 ∧ capA st s2 x = .Untyped p sb 0#u64 false ∧ + UtKeepCurA σ σ2 := by have hsal := J.bufAl have zb := J.zombieBnd have hcx : capA st s x = .Untyped p sb fi false := okinj ((capA_eq s x).symm.trans hcap) @@ -258,12 +296,15 @@ theorem utReset_smallA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar : m have step := utChunk_stepA (c := p) (off := 0#u64) (len := len) J2 (p := p) (sb := sb) (i := fi) (x := x) Cl P' Y1 Dp.run hcx he cte hq hth' hxc hslots hal (by rw [e0]; omega) (by rw [hlv]; exact Nat.mod_eq_zero_of_dvd h8) (by rw [e0, hlv]; omega) (by rw [e0, hlv]; omega) hheap hlink horig hz - obtain ⟨s2, σ2, hset, hsc, J3, Y3, -, -, -, hc2, -⟩ := step + obtain ⟨s2, σ2, hset, hsc, J3, Y3, -, -, -, hc2, -, hstep, -⟩ := step have hsbchunk : sb < untyped.RESET_CHUNK_BITS := by unfold untyped.RESET_CHUNK_BITS show sb.val < 16 exact hsm - refine ⟨s2, σ2, ut_reset_smallA ar hcx hfi0 hsbchunk hlen hset, ?_, J3, Y3, hc2⟩ + have hkeep : UtKeepCurA σ σ2 := by + have hm : σ2.machineState = (utDelStA (specPtr p) sb.val σ).machineState := ut_setCap_msA hsc + exact UtKeepCurA.ofDelStep (pu := specPtr p) (sz := sb.val) hstep (by rw [hm]; exact utDelStA_lastA _ _ σ) J3.sinv.curTcb J3.sinv.curSc + refine ⟨s2, σ2, ut_reset_smallA ar hcx hfi0 hsbchunk hlen hset, ?_, J3, Y3, hc2, hkeep⟩ -- the spec have hab : AbsSlotA Z.th cte := ⟨qc, hq, Or.inl hth⟩ obtain ⟨ac, hg, hr⟩ := J.j.1.st.getAbsA hab @@ -298,42 +339,6 @@ theorem ut_setCap_ksbA {s1 s2 : S} {x p sb off : U64} {d : Bool} (hw : CapRt.Enc have e : s2 = L.wr (L.wr s1 x w0) (wa x 8#u64) w1 := okinj (h.symm.trans (set_cap_eq hen)) rw [e, L.ksb_wr, L.ksb_wr] -/-- `set_cap` keeps the spec machine state. -/ -theorem ut_setCap_msA {cap : Cap} {sl : CslotPtr} {σ : State Unit} {r : Unit × State Unit} - (hr : r ∈ (setCap (Z := Unit) cap sl σ).1) : r.2.machineState = σ.machineState := by - obtain ⟨oref, cref⟩ := sl - obtain ⟨x, hx, hr⟩ := mem_bindA.1 hr - obtain ⟨e1, -⟩ := getObject_mem hx - obtain ⟨obj, σ1⟩ := x - simp only at e1 hr - subst e1 - have key : ∀ o : KernelObject, r ∈ ((Pure.pure o >>= fun o' => setObject (Z := Unit) oref o') σ1).1 → - r.2.machineState = σ1.machineState := by - intro o h - obtain ⟨y, hy, h⟩ := mem_bindA.1 h - obtain rfl : y = (o, σ1) := hy - obtain ⟨o0, -, hr2⟩ := setObject_mem h - rw [hr2] - have kfail : ∀ f : KernelObject → NonDet (State Unit) Unit, r ∈ ((NonDet.fail >>= f) σ1).1 → False := by - intro f h - obtain ⟨y, hy, -⟩ := mem_bindA.1 h - exact absurd hy (Set.notMem_empty _) - cases obj with - | cnode sz cn => - simp only at hr - split_ifs at hr - · exact key _ hr - · exact (kfail _ hr).elim - | tcb t => - simp only at hr - split_ifs at hr <;> - first - | exact (kfail _ hr).elim - | exact key _ hr - | _ => - try simp only at hr - exact (kfail _ hr).elim - theorem utDelSt_actA (σ : State Unit) (pu : Fl4SpecA64.Word) (sz : Nat) : (utDelStA pu sz σ).schedulerAction = σ.schedulerAction := rfl diff --git a/proofs/Fl4ProofsA64/P3/UtResetNoErrA.lean b/proofs/Fl4ProofsA64/P3/UtResetNoErrA.lean new file mode 100644 index 000000000..822921fea --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtResetNoErrA.lean @@ -0,0 +1,118 @@ +/- +P3 (aarch64, A64-P3 Untyped, reset arm): **a reset that does not run the chunk loop never fails.** The spec's +`reset_untyped_cap` (`resetUntypedCap`) of a RAM untyped whose free index is zero, or whose block is below the chunk size, +has no `.error` outcome (its only failing step is the loop's `preemptionPoint`). + +* `NoErrA`: a monadic program with no `.error` outcome from any state; `NoErrA.liftE`, `.returnOk`, `.bind`. +* `utReset_noErrA`: `resetUntypedCap` has no `.error` outcome from `σ` when the slot holds `untypedCap false pu sz fi` and + `sz < resetChunkBits ∨ fi = 0`. + +No named premise. New definitions and theorems only. +-/ +import Fl4ProofsA64.P3.UtResetLoopA +import Fl4ProofsA64.P3.FinDefsA +import Fl4ProofsA64.P3.DelSpecA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open Fl4SpecA64 Fl4Spec Classical + +noncomputable section + +/-- A program of the preemptible monad with no `.error` outcome from any state. -/ +def NoErrA {α : Type} (m : PMonad Unit α) : Prop := ∀ (σ σ' : State Unit) (e : Unit), (.error e, σ') ∉ (m.run σ).1 + +theorem mem_bindE_err_invA {α β : Type} {m : PMonad Unit α} {f : α → PMonad Unit β} {σ σ' : State Unit} {e : Unit} + (h : (.error e, σ') ∈ ((m >>= f).run σ).1) : + (.error e, σ') ∈ (m.run σ).1 ∨ ∃ a τ, (.ok a, τ) ∈ (m.run σ).1 ∧ (.error e, σ') ∈ ((f a).run τ).1 := by + rw [ExceptT.run_bind] at h + obtain ⟨⟨r, τ⟩, h1, h2⟩ := mem_bindA.1 h + cases r with + | error e' => + have h3 := Set.mem_singleton_iff.mp h2 + obtain ⟨h4, h5⟩ := Prod.mk.inj h3 + cases h4 + cases h5 + exact Or.inl h1 + | ok a => exact Or.inr ⟨a, τ, h1, h2⟩ + +theorem NoErrA.liftE {α : Type} (m : NonDet (State Unit) α) : NoErrA (NonDetE.liftE m : PMonad Unit α) := by + intro σ σ' e h + rw [liftE_runD] at h + obtain ⟨x, -, hx⟩ := mem_bindA.1 h + have h3 := Set.mem_singleton_iff.mp hx + obtain ⟨h4, -⟩ := Prod.mk.inj h3 + cases h4 + +theorem NoErrA.returnOk {α : Type} (a : α) : NoErrA ((NonDetE.returnOk a : PMonad Unit α)) := by + intro σ σ' e h + rw [run_returnOkD] at h + have h3 := Set.mem_singleton_iff.mp h + obtain ⟨h4, -⟩ := Prod.mk.inj h3 + cases h4 + +theorem mem_returnOk_invA {α : Type} {a a' : α} {σ τ : State Unit} + (h : (.ok a', τ) ∈ (((NonDetE.returnOk a : PMonad Unit α)).run σ).1) : a' = a ∧ τ = σ := by + rw [run_returnOkD] at h + have h3 := Set.mem_singleton_iff.mp h + obtain ⟨h4, h5⟩ := Prod.mk.inj h3 + exact ⟨Except.ok.inj h4, h5⟩ + +theorem mem_liftE_invA {α : Type} {m : NonDet (State Unit) α} {a : α} {σ τ : State Unit} + (h : (.ok a, τ) ∈ ((NonDetE.liftE m : PMonad Unit α).run σ).1) : (a, τ) ∈ (m σ).1 := by + rw [liftE_runD] at h + obtain ⟨x, hx, h2⟩ := mem_bindA.1 h + have h3 := Set.mem_singleton_iff.mp h2 + obtain ⟨h4, h5⟩ := Prod.mk.inj h3 + have h6 := Except.ok.inj h4 + subst h6 + subst h5 + exact hx + +/-- **A reset without the chunk loop never fails** (module docstring). -/ +theorem utReset_noErrA {sl : CslotPtr} {σ σ3 : State Unit} {pu : Word} {sz fi : Nat} + (hg : (.untypedCap false pu sz fi, σ) ∈ (getCap (Z := Unit) sl σ).1) + (hS : sz < resetChunkBits ∨ fi = 0) : + (.error (), σ3) ∉ ((resetUntypedCap (Z := Unit) sl).run σ).1 := by + intro h + unfold resetUntypedCap at h + rcases mem_bindE_err_invA h with h1 | ⟨cap, τ, h1, h2⟩ + · exact NoErrA.liftE _ σ σ3 () h1 + · have hc := mem_liftE_invA h1 + rw [getCap_singleA hg] at hc + obtain ⟨hc1, hc2⟩ := Prod.mk.inj (Set.mem_singleton_iff.mp hc) + subst hc1 + subst hc2 + rcases mem_bindE_err_invA h2 with h3 | ⟨a1, τ1, h3, h4⟩ + · exact NoErrA.returnOk _ _ _ () h3 + · obtain ⟨e1, e2⟩ := mem_returnOk_invA h3 + subst e2 + rw [e1] at h4 + rcases mem_bindE_err_invA h4 with h5 | ⟨a2, τ2, h5, h6⟩ + · exact NoErrA.returnOk _ _ _ () h5 + · obtain ⟨e1, e2⟩ := mem_returnOk_invA h5 + subst e2 + rw [e1] at h6 + by_cases hf : fi = 0 + · rw [ite_eq_left (show freeIndexOf (.untypedCap false pu sz fi) = 0 from hf)] at h6 + exact NoErrA.returnOk _ _ _ () h6 + · have hs : sz < resetChunkBits := hS.resolve_right hf + rw [ite_eq_right (show ¬ freeIndexOf (.untypedCap false pu sz fi) = 0 from hf)] at h6 + rcases mem_bindE_err_invA h6 with h7 | ⟨a3, τ3, h7, h8⟩ + · exact NoErrA.liftE _ _ _ () h7 + · rcases mem_bindE_err_invA h8 with h9 | ⟨a4, τ4, h9, h10⟩ + · exact NoErrA.returnOk _ _ _ () h9 + · obtain ⟨e1, e2⟩ := mem_returnOk_invA h9 + subst e2 + rw [e1] at h10 + have hc : isDeviceUntypedCap (.untypedCap false pu sz fi) = true ∨ + bitsOf (.untypedCap false pu sz fi) < resetChunkBits := Or.inr hs + rw [if_pos hc] at h10 + rcases mem_bindE_err_invA h10 with h11 | ⟨a5, τ5, h11, h12⟩ + · exact NoErrA.liftE _ _ _ () h11 + · exact NoErrA.liftE _ _ _ () h12 + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtRtExA.lean b/proofs/Fl4ProofsA64/P3/UtRtExA.lean new file mode 100644 index 000000000..2616d3c73 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtRtExA.lean @@ -0,0 +1,210 @@ +/- +P3 (aarch64, A64-P3 Untyped, non-emptiness): **the spec's `invoke_untyped` body has an outcome**. + +The decode-level tops say of every outcome of `utRtBodyA` that the record holds after it; these lemmas give an outcome, +so those statements are not vacuous. + +* `utRtBody_exA`: from CNode source and destination slots (`UtSlotOkA`) and, for a type that creates objects, free new + addresses. +* `utRt_neA`: those inputs from the record `JStage3A` at the creation start and the decode's facts. + +The cache maintenance of `init_arch_objects` needs no premise: `machine_op_lift` ignores failure. No named premise. +New definitions and theorems only. +-/ +import Fl4ProofsA64.P3.UtRtRecA +import Fl4ProofsA64.P3.UtRtFrontA +import Fl4ProofsA64.P3.EmptyA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4SpecA64 Fl4Spec Classical + +noncomputable section + +/-- A CNode slot of the spec heap: `get_cap` and `set_cap` on it have outcomes. -/ +def UtSlotOkA (σ : State Unit) (sl : CslotPtr) : Prop := + ∃ cs, σ.kheap sl.1 = some (.cnode sl.2.length cs) ∧ wellFormedCnodeN sl.2.length cs + +/-- `set_cap` of a CNode slot has an outcome: it keeps every CNode slot and every empty address. -/ +theorem utSlotOk_setCapA {σ : State Unit} {sl : CslotPtr} (h : UtSlotOkA σ sl) (a : Cap) : + ∃ σ', ((), σ') ∈ (setCap (Z := Unit) a sl σ).1 ∧ (∀ d, UtSlotOkA σ d → UtSlotOkA σ' d) ∧ + (∀ q, σ.kheap q = none → σ'.kheap q = none) := by + obtain ⟨cs, hk, hwf⟩ := h + refine ⟨_, setCap_cnode_memA a hk hwf rfl, fun d hd => ?_, fun q hq => ?_⟩ + · obtain ⟨cs', hk', hwf'⟩ := hd + by_cases e : d.1 = sl.1 + · have g := hk' + rw [e, hk] at g + injection g with g + injection g with el ec + refine ⟨Function.update cs sl.2 (some a), ?_, ?_⟩ + · show Function.update σ.kheap sl.1 _ d.1 = _ + rw [e, Function.update_self, el] + · rw [← el]; exact wf_updA a hwf rfl + · exact ⟨cs', by show Function.update σ.kheap sl.1 _ d.1 = _; rw [Function.update_of_ne e]; exact hk', hwf'⟩ + · have e : q ≠ sl.1 := fun e => by rw [e, hk] at hq; cases hq + show Function.update σ.kheap sl.1 _ q = none + rw [Function.update_of_ne e]; exact hq + +/-- `create_cap` into a CNode slot has an outcome, which keeps every CNode slot. -/ +theorem utCreateCap_exA (t : ApiObjectType) (bits : Nat) (src : CslotPtr) (dev : Bool) {σ : State Unit} + {x : CslotPtr × ObjRef} (h : UtSlotOkA σ x.1) : + ∃ σ', ((), σ') ∈ (createCap (Z := Unit) t bits src dev x σ).1 ∧ ∀ d, UtSlotOkA σ d → UtSlotOkA σ' d := by + obtain ⟨dest, oref⟩ := x + let σ1 : State Unit := { σ with cdt := Function.update σ.cdt dest (some src) } + let σ2 : State Unit := { σ1 with isOriginalCap := Function.update σ1.isOriginalCap dest true } + have h2 : UtSlotOkA σ2 dest := h + obtain ⟨σ3, m, keep, -⟩ := utSlotOk_setCapA h2 (defaultCap t oref bits dev) + refine ⟨σ3, ?_, fun d hd => keep d hd⟩ + unfold createCap + refine mem_bindA.2 ⟨(σ.cdt dest, σ), rfl, ?_⟩ + refine mem_bindA.2 ⟨(σ.cdt, σ), rfl, ?_⟩ + refine mem_bindA.2 ⟨((), σ1), mem_bindA.2 ⟨(σ, σ), rfl, rfl⟩, ?_⟩ + refine mem_bindA.2 ⟨((), σ1), doExtendedOp_memA _ _, ?_⟩ + refine mem_bindA.2 ⟨((), σ2), mem_bindA.2 ⟨(σ1.isOriginalCap, σ1), rfl, rfl⟩, ?_⟩ + exact m + +/-- The `create_cap` loop over CNode slots has an outcome. -/ +theorem utCreateCaps_exA (t : ApiObjectType) (bits : Nat) (src : CslotPtr) (dev : Bool) + (l : List (CslotPtr × ObjRef)) : ∀ σ : State Unit, (∀ x ∈ l, UtSlotOkA σ x.1) → + ∃ r, r ∈ (NonDet.mapMx (createCap (Z := Unit) t bits src dev) l σ).1 := by + induction l with + | nil => exact fun σ _ => ⟨((), σ), rfl⟩ + | cons a l ih => + intro σ h + obtain ⟨σ', m, keep⟩ := utCreateCap_exA t bits src dev (h a List.mem_cons_self) + obtain ⟨r, hr⟩ := ih σ' fun x hx => keep _ (h x (List.mem_cons_of_mem _ hx)) + exact ⟨r, mem_bindA.2 ⟨((), σ'), m, hr⟩⟩ + +/-- A lifted machine operation has an outcome, which keeps the heap (`ignore_failure`). -/ +theorem utMachineOp_exA (f : MachineRestMonad Unit) (σ : State Unit) : + ∃ σ', ((), σ') ∈ (doMachineOp (Z := Unit) (machineOpLift f) σ).1 ∧ σ'.kheap = σ.kheap := by + have ne : ∀ s, ∃ x, x ∈ (ignoreFailure f s).1 := fun s => by + unfold ignoreFailure + split_ifs with h + · exact ⟨_, rfl⟩ + · exact Set.nonempty_iff_ne_empty.2 h + have lift : ∀ ms : MachineState, ∃ ms', ((), ms') ∈ (machineOpLift f ms).1 := fun ms => by + obtain ⟨⟨⟨⟩, mr⟩, h⟩ := ne ms.machineStateRest + refine ⟨{ ms with machineStateRest := mr }, ?_⟩ + unfold machineOpLift machineRestLift + refine ⟨(ms.machineStateRest, ms), rfl, ?_⟩ + refine ⟨(((), mr), ms), ⟨h, rfl⟩, ?_⟩ + exact ⟨((), { ms with machineStateRest := mr }), rfl, rfl⟩ + obtain ⟨ms', h⟩ := lift σ.machineState + refine ⟨{ σ with machineState := ms' }, ?_, rfl⟩ + unfold doMachineOp + refine mem_bindA.2 ⟨(σ.machineState, σ), rfl, ?_⟩ + refine mem_bindA.2 ⟨(((), ms'), σ), ⟨h, rfl⟩, ?_⟩ + exact mem_bindA.2 ⟨((), { σ with machineState := ms' }), rfl, rfl⟩ + +private theorem utMapMx_heap_exA {α : Type} {g : α → NonDet (State Unit) Unit} + (h : ∀ a σ, ∃ σ', ((), σ') ∈ (g a σ).1 ∧ σ'.kheap = σ.kheap) (l : List α) : + ∀ σ : State Unit, ∃ σ', ((), σ') ∈ (NonDet.mapMx g l σ).1 ∧ σ'.kheap = σ.kheap := by + induction l with + | nil => exact fun σ => ⟨σ, rfl, rfl⟩ + | cons a l ih => + intro σ + obtain ⟨σ1, m1, e1⟩ := h a σ + obtain ⟨σ2, m2, e2⟩ := ih σ1 + exact ⟨σ2, mem_bindA.2 ⟨((), σ1), m1, m2⟩, e2.trans e1⟩ + +/-- `init_arch_objects` has an outcome, which keeps the heap. -/ +theorem utInitArch_exA (t : ApiObjectType) (dev : Bool) (ptr : ObjRef) (n sz : Nat) (refs : List ObjRef) + (σ : State Unit) : + ∃ σ', ((), σ') ∈ (initArchObjects (Z := Unit) t dev ptr n sz refs σ).1 ∧ σ'.kheap = σ.kheap := by + unfold initArchObjects + split_ifs + · exact utMapMx_heap_exA (fun _ s => utMachineOp_exA _ s) _ _ + · exact utMapMx_heap_exA (fun _ s => utMachineOp_exA _ s) _ _ + · exact ⟨σ, rfl, rfl⟩ + +/-- **The body has an outcome.** -/ +theorem utRtBody_exA {srcSlot : CslotPtr} {base retypeBase : Word} {t : ApiObjectType} {objSz : Nat} + {slots : List CslotPtr} {dev : Bool} {σ : State Unit} (hS : UtSlotOkA σ srcSlot) + (hD : ∀ d ∈ slots, UtSlotOkA σ d) + (hfree : t ≠ .untyped → ∀ q ∈ fl4RetypeAddrs fl4ObjBitsApi retypeBase slots.length objSz t, σ.kheap q = none) : + ∃ r, r ∈ (utRtBodyA srcSlot base retypeBase t objSz slots dev σ).1 := by + obtain ⟨csS, hkS, hwfS⟩ := id hS + obtain ⟨cap, hcap⟩ : ∃ c, csS srcSlot.2 = some c := by + have g : srcSlot.2 ∈ dom csS := by rw [hwfS]; exact rfl + exact Option.ne_none_iff_exists'.1 g + have hg := getCap_cnode_memA (σ := σ) (idx := srcSlot.2) hkS hwfS hcap + obtain ⟨σ1, m1, keep1, free1⟩ := utSlotOk_setCapA hS (.untypedCap dev base (bitsOf cap) + (unat (retypeBase + BitVec.ofNat 64 slots.length <<< fl4ObjBitsApi t objSz - base))) + -- `retype_region` + obtain ⟨orefs, σ2, m2, keep2⟩ : ∃ orefs σ2, + (orefs, σ2) ∈ (retypeRegionWith (Z := Unit) fl4ObjBitsApi retypeBase slots.length objSz t dev σ1).1 ∧ + ∀ d, d ∈ slots → UtSlotOkA σ2 d := by + by_cases ht : t = .untyped + · refine ⟨fl4RetypeAddrs fl4ObjBitsApi retypeBase slots.length objSz t, σ1, ?_, fun d hd => keep1 _ (hD d hd)⟩ + unfold retypeRegionWith + refine mem_bindA.2 ⟨(_, σ1), rfl, mem_bindA.2 ⟨(_, σ1), rfl, ?_⟩⟩ + refine mem_bindA.2 ⟨((), σ1), ?_, rfl⟩ + unfold NonDet.when + rw [ite_eq_right (fun g => g ht)] + rfl + · refine ⟨_, _, utRetRegion_memA ht _ _ _ _ σ1, fun d hd => ?_⟩ + obtain ⟨cs, hk, hwf⟩ := keep1 _ (hD d hd) + refine ⟨cs, ?_, hwf⟩ + rw [utRetSt_kheapA, ite_eq_right (fun g => ?_)] + · exact hk + · rw [free1 _ (hfree ht _ g)] at hk; cases hk + obtain ⟨σ3, m3, e3⟩ := utInitArch_exA t dev retypeBase slots.length objSz orefs σ2 + obtain ⟨r, m4⟩ := utCreateCaps_exA t objSz srcSlot dev (slots.zip orefs) σ3 fun x hx => by + obtain ⟨cs, hk, hwf⟩ := keep2 _ (List.of_mem_zip hx).1 + exact ⟨cs, by rw [e3]; exact hk, hwf⟩ + refine ⟨r, ?_⟩ + unfold utRtBodyA + refine mem_bindA.2 ⟨(cap, σ), hg, ?_⟩ + refine mem_bindA.2 ⟨(_, σ), rfl, mem_bindA.2 ⟨(_, σ), rfl, ?_⟩⟩ + refine mem_bindA.2 ⟨((), σ1), m1, ?_⟩ + refine mem_bindA.2 ⟨(orefs, σ2), m2, ?_⟩ + exact mem_bindA.2 ⟨((), σ3), m3, m4⟩ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N Ep Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {J5 J7 : JSlotA S} {s : S} {a : A} {σ : State Unit} {m : McState} + +/-- **The body has an outcome at a creation start**: the record there, the untyped cap in slot `x`, a window above its +free index, and CNode source and destination slots. -/ +theorem utRt_neA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N Ep Rp Bf stack κ n J5 J7 s a σ m) + {x : obj.Slot} {p sb fi nt us aligned : U64} {win : Nat} (hx : x ∈ OS) + (hc : capA st s x = .Untyped p sb fi false) (W : UtWinZA nt aligned (zA nt.val us) win) + (h1 : p.val + fi.val ≤ aligned.val) (h2 : aligned.val + win * 2 ^ (zA nt.val us).val ≤ p.val + 2 ^ sb.val) + {t : ApiObjectType} (htt : objTypeOfA nt.val = some t) (hus : us.val < 64) + {srcSlot : CslotPtr} (hsrc : ∃ q, srcSlot.1 = specPtr q ∧ Z.th q = some (.cnode srcSlot.2.length)) + {slots : List CslotPtr} (hlen : slots.length = win) + (hdst : ∀ d ∈ slots, ∃ q, d.1 = specPtr q ∧ Z.th q = some (.cnode d.2.length)) (base : Word) : + ∃ r, r ∈ (utRtBodyA srcSlot base (specPtr aligned) t us.val slots false σ).1 := by + have ok : ∀ d : CslotPtr, (∃ q, d.1 = specPtr q ∧ Z.th q = some (.cnode d.2.length)) → UtSlotOkA σ d := by + rintro d ⟨q, e, hq⟩ + obtain ⟨cs, hk, hwf, -⟩ := J.j.1.st.cnode q _ hq + exact ⟨cs, by rw [e]; exact hk, hwf⟩ + refine utRtBody_exA (ok _ hsrc) (fun d hd => ok _ (hdst d hd)) fun _ q hq => ?_ + rw [hlen, utRet_addrs_memA htt hus] at hq + obtain ⟨j, hj, rfl⟩ := hq + have v := utRt_newValA W hj + exact J.specFree.heap _ ⟨x, hx, p, sb, fi, false, hc, trivial, by omega, by omega⟩ + +end + +/-- The creation window of a decode: aligned to the object size, and table and page objects at least a page. -/ +theorem utWinZ_decA {nt us aligned : U64} {win : Nat} (hn : nt.val < 15) (hus : us.val < 64) + (hz : (zA nt.val us).val < 64) (hpf : aligned.val + win * 2 ^ (zA nt.val us).val ≤ 2 ^ 64) + (hal : aligned.val % 2 ^ (zA nt.val us).val = 0) : UtWinZA nt aligned (zA nt.val us) win := by + refine ⟨hz, hpf, hal, fun h => ?_, fun h => ?_⟩ + · rw [zA_valA nt us hn hus] + unfold zOfA + rcases h with h | h <;> rw [h] <;> simp + · rw [zA_valA nt us hn hus] + unfold zOfA + rcases h with h | h <;> rw [h] <;> simp + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtRtGlobA.lean b/proofs/Fl4ProofsA64/P3/UtRtGlobA.lean index 656caeacf..652bd5d1a 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtGlobA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtGlobA.lean @@ -69,7 +69,7 @@ theorem ut_setCap_gA (cap : Cap) (sl : CslotPtr) : UtGA (setCap (Z := Unit) cap obtain rfl : y = (o, σ1) := hy obtain ⟨o0, -, hr2⟩ := setObject_mem h rw [hr2] - exact ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + exact SpecGlobA.ofKey rfl have kfail : ∀ f : KernelObject → NonDet (State Unit) Unit, r ∈ ((NonDet.fail >>= f) σ1).1 → False := by intro f h obtain ⟨y, hy, -⟩ := mem_bindA.1 h @@ -94,7 +94,7 @@ theorem ut_setCdt_gA (t : Cdt) : UtGA (setCdt (Z := Unit) t) := fun σ r hr => b obtain ⟨x, hx, hr⟩ := mem_bindA.1 hr obtain rfl : x = (σ, σ) := hx obtain rfl : r = ((), { σ with cdt := t }) := hr - exact ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + exact SpecGlobA.ofKey rfl theorem ut_modify_gA {g : State Unit → State Unit} (h : ∀ σ, SpecGlobA σ (g σ)) : UtGA (NonDet.modify g) := fun σ r hr => by @@ -103,13 +103,13 @@ theorem ut_modify_gA {g : State Unit → State Unit} (h : ∀ σ, SpecGlobA σ ( theorem ut_setOriginal_gA (sl : CslotPtr) (v : Bool) : UtGA (setOriginal (Z := Unit) sl v) := UtGA.bind (UtGA.gets _) fun _ => ut_modify_gA fun _ => - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + SpecGlobA.ofKey rfl theorem ut_doExtendedOp_gA (eop : DetExtMonad Unit) : UtGA (doExtendedOp (Z := Unit) eop) := by unfold doExtendedOp refine UtGA.bind (.state fun σ r h => by obtain rfl : r = (σ, σ) := h; rfl) fun _ => ?_ refine UtGA.bind (.state fun σ r h => by rw [h.2]) fun _ => ut_modify_gA fun _ => - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + SpecGlobA.ofKey rfl theorem ut_createCap_gA (t : ApiObjectType) (bits : Nat) (src : CslotPtr) (dev : Bool) (x : CslotPtr × ObjRef) : UtGA (createCap (Z := Unit) t bits src dev x) := by @@ -127,7 +127,7 @@ theorem ut_mapMx_gA {α : Type} {f : α → NonDet (State Unit) Unit} (h : ∀ a theorem ut_doMachineOp_gA {α : Type} (mop : NonDet MachineState α) : UtGA (doMachineOp (Z := Unit) mop) := by unfold doMachineOp exact UtGA.bind (UtGA.gets _) fun _ => UtGA.bind (.state fun σ r h => by rw [h.2]) fun _ => - UtGA.bind (ut_modify_gA fun _ => ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩) fun _ => + UtGA.bind (ut_modify_gA fun _ => SpecGlobA.ofKey rfl) fun _ => UtGA.pure _ theorem ut_initArch_gA (t : ApiObjectType) (dev : Bool) (ptr : ObjRef) (n sz : Nat) (refs : List ObjRef) : @@ -143,7 +143,7 @@ theorem ut_retRegion_gA (t : ApiObjectType) (ptr : ObjRef) (n bits : Nat) (dev : rw [(utRetRegion_invA _ _ _ _ _ _ hr).2] split_ifs · exact SpecGlobA.refl σ - · exact ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + · exact SpecGlobA.ofKey rfl /-- **The body keeps the globals.** -/ theorem utRtBody_globA {srcSlot : CslotPtr} {base retypeBase : Word} {t : ApiObjectType} {objSz : Nat} diff --git a/proofs/Fl4ProofsA64/P3/UtRtLastA.lean b/proofs/Fl4ProofsA64/P3/UtRtLastA.lean new file mode 100644 index 000000000..df0c23453 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtRtLastA.lean @@ -0,0 +1,176 @@ +/- +P3 (aarch64, A64-P3 Untyped, Stage 4 dispatch): **the body of `invoke_untyped` keeps the spec's last machine time** +(the sibling of `UtRtUmA`'s walk for `underlyingMemory`; the dispatch's `BodyOKA` reads it). Its only machine operations +are cache cleans, which `machineOpLift` confines to the rest of the machine state. + +* `utRtBody_lastA`: every outcome of `utRtBodyA` keeps `lastMachineTime`. + +No named premise. New definitions and theorems only. +-/ +import Fl4ProofsA64.P3.UtRtGlobA +import Fl4ProofsA64.P3.DelAsidSpecA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Classical + +noncomputable section + +open Fl4SpecA64 Fl4Spec + +/-- Every outcome of `m` keeps the last machine time. -/ +def UtLA {α : Type} (m : NonDet (State Unit) α) : Prop := ∀ σ r, r ∈ (m σ).1 → r.2.machineState.lastMachineTime = σ.machineState.lastMachineTime + +theorem UtLA.bind {α β : Type} {m : NonDet (State Unit) α} {f : α → NonDet (State Unit) β} (hm : UtLA m) + (hf : ∀ a, UtLA (f a)) : UtLA (m >>= f) := fun σ r hr => by + obtain ⟨x, hx, hr⟩ := mem_bindA.1 hr + exact (hf x.1 x.2 r hr).trans (hm σ x hx) + +theorem UtLA.state {α : Type} {m : NonDet (State Unit) α} (h : ∀ σ r, r ∈ (m σ).1 → r.2 = σ) : UtLA m := + fun σ r hr => by rw [h σ r hr] + +theorem UtLA.pure {α : Type} (a : α) : UtLA (Pure.pure a : NonDet (State Unit) α) := + .state fun σ r h => by obtain rfl : r = (a, σ) := h; rfl + +theorem UtLA.gets {α : Type} (g : State Unit → α) : UtLA (NonDet.gets g) := + .state fun σ r h => by obtain rfl : r = (g σ, σ) := h; rfl + +theorem UtLA.fail {α : Type} : UtLA (NonDet.fail : NonDet (State Unit) α) := + fun _ _ h => absurd h (Set.notMem_empty _) + +theorem UtLA.assert (P : Prop) : UtLA (NonDet.assert P : NonDet (State Unit) Unit) := + .state fun _ _ h => by obtain ⟨-, rfl⟩ := h; rfl + +theorem UtLA.assertOpt {α : Type} (o : Option α) : UtLA (NonDet.assertOpt o : NonDet (State Unit) α) := by + cases o + · exact UtLA.fail + · exact .state fun σ r h => by obtain rfl : r = (_, σ) := h; rfl + +theorem ut_getCap_lmA (sl : CslotPtr) : UtLA (getCap (Z := Unit) sl) := by + obtain ⟨oref, cref⟩ := sl + have go : UtLA (getObject (Z := Unit) oref) := .state fun _ _ h => (getObject_mem h).1 + refine UtLA.bind go fun obj => ?_ + cases obj <;> dsimp only <;> first + | exact UtLA.bind UtLA.fail fun _ => UtLA.assertOpt _ + | exact UtLA.bind (UtLA.pure _) fun _ => UtLA.assertOpt _ + | exact UtLA.bind (UtLA.assert _) fun _ => UtLA.bind (UtLA.pure _) fun _ => UtLA.assertOpt _ + +theorem ut_setCap_lmA (cap : Cap) (sl : CslotPtr) : UtLA (setCap (Z := Unit) cap sl) := fun σ r hr => by + obtain ⟨oref, cref⟩ := sl + obtain ⟨x, hx, hr⟩ := mem_bindA.1 hr + obtain ⟨e1, -⟩ := getObject_mem hx + obtain ⟨obj, σ1⟩ := x + simp only at e1 hr + subst e1 + have key : ∀ o : KernelObject, r ∈ ((Pure.pure o >>= fun o' => setObject (Z := Unit) oref o') σ1).1 → + r.2.machineState.lastMachineTime = σ1.machineState.lastMachineTime := by + intro o h + obtain ⟨y, hy, h⟩ := mem_bindA.1 h + obtain rfl : y = (o, σ1) := hy + obtain ⟨o0, -, hr2⟩ := setObject_mem h + rw [hr2] + have kfail : ∀ f : KernelObject → NonDet (State Unit) Unit, r ∈ ((NonDet.fail >>= f) σ1).1 → False := by + intro f h + obtain ⟨y, hy, -⟩ := mem_bindA.1 h + exact absurd hy (Set.notMem_empty _) + cases obj with + | cnode sz cn => + simp only at hr + split_ifs at hr + · exact key _ hr + · exact (kfail _ hr).elim + | tcb t => + simp only at hr + split_ifs at hr <;> + first + | exact (kfail _ hr).elim + | exact key _ hr + | _ => + try simp only at hr + exact (kfail _ hr).elim + +theorem ut_setCdt_lmA (t : Cdt) : UtLA (setCdt (Z := Unit) t) := fun σ r hr => by + obtain ⟨x, hx, hr⟩ := mem_bindA.1 hr + obtain rfl : x = (σ, σ) := hx + obtain rfl : r = ((), { σ with cdt := t }) := hr + exact rfl + +theorem ut_modify_lmA {g : State Unit → State Unit} (h : ∀ σ, (g σ).machineState.lastMachineTime = σ.machineState.lastMachineTime) : + UtLA (NonDet.modify g) := fun σ r hr => by + obtain rfl : r = ((), g σ) := hr + exact h σ + +theorem ut_setOriginal_lmA (sl : CslotPtr) (v : Bool) : UtLA (setOriginal (Z := Unit) sl v) := + UtLA.bind (UtLA.gets _) fun _ => ut_modify_lmA fun _ => + rfl + +theorem ut_doExtendedOp_lmA (eop : DetExtMonad Unit) : UtLA (doExtendedOp (Z := Unit) eop) := by + unfold doExtendedOp + refine UtLA.bind (.state fun σ r h => by obtain rfl : r = (σ, σ) := h; rfl) fun _ => ?_ + refine UtLA.bind (.state fun σ r h => by rw [h.2]) fun _ => ut_modify_lmA fun _ => + rfl + +theorem ut_createCap_lmA (t : ApiObjectType) (bits : Nat) (src : CslotPtr) (dev : Bool) (x : CslotPtr × ObjRef) : + UtLA (createCap (Z := Unit) t bits src dev x) := by + obtain ⟨dest, oref⟩ := x + unfold createCap + exact UtLA.bind (UtLA.gets _) fun _ => UtLA.bind (UtLA.gets _) fun _ => UtLA.bind (ut_setCdt_lmA _) fun _ => + UtLA.bind (ut_doExtendedOp_lmA _) fun _ => UtLA.bind (ut_setOriginal_lmA _ _) fun _ => ut_setCap_lmA _ _ + +theorem ut_mapMx_lmA {α : Type} {f : α → NonDet (State Unit) Unit} (h : ∀ a, UtLA (f a)) (l : List α) : + UtLA (NonDet.mapMx f l) := by + induction l with + | nil => unfold NonDet.mapMx; exact UtLA.pure _ + | cons a l ih => unfold NonDet.mapMx; exact UtLA.bind (h a) fun _ => ih + +/-- A machine operation confined to the rest of the machine state keeps the last machine time. -/ +def UtMopLA {α : Type} (mop : NonDet MachineState α) : Prop := + ∀ ms r, r ∈ (mop ms).1 → r.2.lastMachineTime = ms.lastMachineTime + +theorem ut_machineOpLift_keepLA (f : MachineRestMonad Unit) : UtMopLA (machineOpLift f) := fun ms r hr => by + obtain ⟨mr, e⟩ := (machineOpLift_restA f ms).2.2 r hr + rw [e] + +theorem ut_doMachineOp_lmA {α : Type} {mop : NonDet MachineState α} (h : UtMopLA mop) : + UtLA (doMachineOp (Z := Unit) mop) := fun σ r hr => by + unfold doMachineOp at hr + obtain ⟨x, hx, hr⟩ := mem_bindA.1 hr + obtain rfl : x = (σ.machineState, σ) := hx + obtain ⟨y, hy, hr⟩ := mem_bindA.1 hr + have ey : y.2 = σ := hy.2 + have hm : y.1 ∈ (mop σ.machineState).1 := hy.1 + obtain ⟨z, hz, hr⟩ := mem_bindA.1 hr + obtain rfl : z = ((), { y.2 with machineState := y.1.2 }) := hz + obtain rfl : r = (y.1.1, { y.2 with machineState := y.1.2 }) := hr + exact h _ _ hm + +theorem ut_initArch_lmA (t : ApiObjectType) (dev : Bool) (ptr : ObjRef) (n sz : Nat) (refs : List ObjRef) : + UtLA (initArchObjects (Z := Unit) t dev ptr n sz refs) := by + unfold initArchObjects + split_ifs + · exact ut_mapMx_lmA (fun _ => ut_doMachineOp_lmA (ut_machineOpLift_keepLA _)) _ + · exact ut_mapMx_lmA (fun _ => ut_doMachineOp_lmA (ut_machineOpLift_keepLA _)) _ + · exact UtLA.pure _ + +theorem ut_retRegion_lmA (t : ApiObjectType) (ptr : ObjRef) (n bits : Nat) (dev : Bool) : + UtLA (retypeRegionWith (Z := Unit) fl4ObjBitsApi ptr n bits t dev) := fun σ r hr => by + rw [(utRetRegion_invA _ _ _ _ _ _ hr).2] + split_ifs + · rfl + · exact rfl + +/-- **The body keeps the last machine time.** -/ +theorem utRtBody_lastA {srcSlot : CslotPtr} {base retypeBase : Word} {t : ApiObjectType} {objSz : Nat} + {slots : List CslotPtr} {dev : Bool} {σ : State Unit} {r : Unit × State Unit} + (hr : r ∈ (utRtBodyA srcSlot base retypeBase t objSz slots dev σ).1) : r.2.machineState.lastMachineTime = σ.machineState.lastMachineTime := by + have h : UtLA (utRtBodyA srcSlot base retypeBase t objSz slots dev) := by + unfold utRtBodyA + exact UtLA.bind (ut_getCap_lmA _) fun _ => UtLA.bind (UtLA.pure _) fun _ => UtLA.bind (UtLA.pure _) fun _ => + UtLA.bind (ut_setCap_lmA _ _) fun _ => UtLA.bind (ut_retRegion_lmA _ _ _ _ _) fun _ => + UtLA.bind (ut_initArch_lmA _ _ _ _ _ _) fun _ => ut_mapMx_lmA (fun x => ut_createCap_lmA _ _ _ _ x) _ + exact h σ r hr + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtRtNewPlaceA.lean b/proofs/Fl4ProofsA64/P3/UtRtNewPlaceA.lean new file mode 100644 index 000000000..24a6ab0d9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtRtNewPlaceA.lean @@ -0,0 +1,189 @@ +/- +P3 (aarch64, A64-P3 Untyped, Stage 4): **the grown typed heap is placed** (discharges the tops' `hnew`). + +For a RAM retype of the window `[aligned, aligned + win * 2^z)` inside the untyped (`UtWinZA`; `UtClrA`: no joint object +and not the kernel-state block meets it) the typed heap `utRtThA Z.th false nt us aligned win` is placed (`PlaceA`) +and the new untyped / frame ranges do not wrap under `specPtr` (`SpNoOvA`, from [J] `utWin`: the untyped lies in the +kernel window). + +* `spNoOvA_winA`: a kernel-window range within `2^46` does not wrap. +* **`utRt_newPlaceA`**: both facts. + +No named premise. New definitions and theorems only. +-/ +import Fl4ProofsA64.P3.UtRtKeptA +import Fl4ProofsA64.P3.UtApIpcA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- A kernel-window range within `2^46` does not wrap under `specPtr`. -/ +theorem spNoOvA_winA {p : U64} {n : Nat} (h0 : 18446603336221196288 ≤ p.val) + (h : p.val + 2 ^ n ≤ 18446603336221196288 + 2 ^ 46) : SpNoOvA p n := by + unfold SpNoOvA + have h1 : 1 ≤ 2 ^ n := Nat.one_le_two_pow + have e1 : (1 : BitVec 64).toNat = 1 := rfl + have hp : (specPtr p).toNat = p.val - 18446603336221196288 + 549755813888 := by + rw [specPtr_toNat] + have hb : p.val < 2 ^ 64 := p.bv.isLt + omega + have hs : ((1 : BitVec 64) <<< n).toNat = 2 ^ n := by + rw [BitVec.toNat_shiftLeft, Nat.shiftLeft_eq, e1, one_mul]; exact Nat.mod_eq_of_lt (by omega) + have ha : (specPtr p + (1 : BitVec 64) <<< n).toNat = p.val - 18446603336221196288 + 549755813888 + 2 ^ n := by + rw [BitVec.toNat_add, hp, hs]; exact Nat.mod_eq_of_lt (by omega) + have hb : (specPtr p + (1 : BitVec 64) <<< n - 1).toNat = + p.val - 18446603336221196288 + 549755813888 + 2 ^ n - 1 := by + rw [BitVec.toNat_sub, ha, e1]; omega + rw [BitVec.le_def, hb, hp]; omega + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {J5 J7 : JSlotA S} {s : S} {a : A} {σ : State Unit} {m : McState} {x p sb fi : U64} + {nt us aligned : U64} {win : Nat} + +/-- A clear region stays clear on a sub-range. -/ +theorem UtClrA.mono {Z0 : XSetsA} {H0 : Heap} {s : S} {lo hi lo' hi' : Nat} (C : UtClrA st Z0 H0 s lo hi) + (h1 : lo ≤ lo') (h2 : hi' ≤ hi) : UtClrA st Z0 H0 s lo' hi' := + ⟨fun q b h => (C.obj q b h).imp (fun g => by omega) (fun g => by omega), + fun c hc => (C.nodes c hc).imp (fun g => by omega) (fun g => by omega), + C.ks.imp (fun g => by omega) (fun g => by omega)⟩ + +/-- **The grown typed heap is placed, and no new range wraps** over any record-shaped typed heap `Z0.th` that is +placed, clear of the window (`UtClrA`) and inside the kernel window (module docstring). -/ +theorem utRt_newPlaceGenA {Z0 : XSetsA} {H0 : Heap} {s : S} {p sb : U64} {nt us aligned : U64} {win : Nat} + (hP0 : PlaceA Z0.th (L.ksb s)) + (Cl : UtClrA st Z0 H0 s aligned.val (aligned.val + win * 2 ^ (zA nt.val us).val)) + (hksw0 : (L.ksb s).val + 788736 ≤ 2 ^ 64) + (hw0 : layout.PPTR_BASE.val ≤ p.val ∧ p.val + 2 ^ sb.val ≤ layout.PPTR_BASE.val + 2 ^ 44) + (W : UtWinZA nt aligned (zA nt.val us) win) + (h1 : p.val ≤ aligned.val) (h2 : aligned.val + win * 2 ^ (zA nt.val us).val ≤ p.val + 2 ^ sb.val) + (hn : nt.val < 15) (hus : us.val < 64) (hb0 : 0 < aligned.val) : + PlaceA (utRtThA Z0.th false nt us aligned win) (L.ksb s) ∧ + ∀ j, j < win → utRangedA nt.val → SpNoOvA (bjA aligned (zA nt.val us) j) (zOfA nt.val us.val) := by + have hP := hP0 + have hksw : (L.ksb s).val + 788736 ≤ 2 ^ 64 := hksw0 + have hz : 0 < 2 ^ (zA nt.val us).val := Nat.two_pow_pos _ + have hbv : ∀ j, j < win → (bjA aligned (zA nt.val us) j).val = aligned.val + j * 2 ^ (zA nt.val us).val := + fun j hj => bjA_val (by + have h1 : (j + 1) * 2 ^ (zA nt.val us).val ≤ win * 2 ^ (zA nt.val us).val := Nat.mul_le_mul_right _ hj + rw [Nat.add_mul, Nat.one_mul] at h1 + have := W.fit + omega) + -- a new object: its value, size and place in the window + have newv : ∀ q, UtNewA false nt us aligned win q → ∃ j, j < win ∧ q = bjA aligned (zA nt.val us) j ∧ + (utKindA nt us).size = 2 ^ (zA nt.val us).val ∧ + aligned.val + j * 2 ^ (zA nt.val us).val = q.val ∧ + q.val + 2 ^ (zA nt.val us).val ≤ aligned.val + win * 2 ^ (zA nt.val us).val ∧ aligned.val ≤ q.val := by + rintro q ⟨-, h0, ⟨h5, h8, h11, h13, h14⟩, j, hj, rfl⟩ + have hsz := utKind_sizeA hn h0 hus + have e := hbv j hj + have h1 : (j + 1) * 2 ^ (zA nt.val us).val ≤ win * 2 ^ (zA nt.val us).val := Nat.mul_le_mul_right _ hj + rw [Nat.add_mul, Nat.one_mul] at h1 + exact ⟨j, hj, rfl, hsz, e.symm, by omega, by omega⟩ + have ksz : ksSizeA = 788736 := rfl + refine ⟨⟨?_, ?_, ?_, ?_, ?_, ?_⟩, ?_⟩ + · -- align + intro q k hq + rcases utRtTh_splitA hq with ⟨-, h⟩ | ⟨hn, rfl⟩ + · exact hP.align q k h + · obtain ⟨j, hj, -, hsz, e, -, -⟩ := newv q hn + rw [hsz, ← e, Nat.add_mul_mod_self_right] + exact W.al + · -- fit + intro q k hq + rcases utRtTh_splitA hq with ⟨-, h⟩ | ⟨hn, rfl⟩ + · exact hP.fit q k h + · obtain ⟨j, hj, -, hsz, e, hle, -⟩ := newv q hn + rw [hsz] + have := W.fit + omega + · -- apart + intro q r kq kr hq hr hqr + rcases utRtTh_splitA hq with ⟨nq, hq'⟩ | ⟨nq, rfl⟩ <;> rcases utRtTh_splitA hr with ⟨nr, hr'⟩ | ⟨nr, rfl⟩ + · exact hP.apart q r kq kr hq' hr' hqr + · obtain ⟨j, hj, -, hsz, e, hle, hge⟩ := newv r nr + have o := Cl.obj q kq.size (Or.inr (Or.inr (Or.inl ⟨kq, hq', rfl⟩))) + rw [hsz] + omega + · obtain ⟨j, hj, -, hsz, e, hle, hge⟩ := newv q nq + have o := Cl.obj r kr.size (Or.inr (Or.inr (Or.inl ⟨kr, hr', rfl⟩))) + rw [hsz] + omega + · obtain ⟨j, hj, hqj, hsz, e, hle, hge⟩ := newv q nq + obtain ⟨j', hj', hrj, hsz', e', hle', hge'⟩ := newv r nr + rw [hsz] + have hne : j ≠ j' := fun h => hqr (by rw [hqj, hrj, h]) + rcases Nat.lt_or_gt_of_ne hne with h | h + · have := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt h) + rw [Nat.succ_mul] at this + omega + · have := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt h) + rw [Nat.succ_mul] at this + omega + · -- the kernel-state block + intro q k hq hnI + rcases utRtTh_splitA hq with ⟨-, h⟩ | ⟨hn, rfl⟩ + · exact hP.ks q k h hnI + · obtain ⟨j, hj, -, hsz, e, hle, hge⟩ := newv q hn + have o := Cl.ks + rw [hsz, ksz] + omega + · -- the IRQ-node slots + intro i hi + have hnn : ¬ UtNewA false nt us aligned win (Fl4ProofsA64.P1.irqSlotA (L.ksb s) i) := by + intro hn + obtain ⟨j, hj, -, hsz, e, hle, hge⟩ := newv _ hn + have o := Cl.ks + have hv := irqSlotA_val (kb := L.ksb s) (by rw [ksz]; exact hksw) hi + omega + unfold utRtThA + rw [if_neg hnn] + exact hP.irq i hi + · -- nothing at address 0 + intro q k hq + rcases utRtTh_splitA hq with ⟨-, h⟩ | ⟨hn, rfl⟩ + · exact hP.nz q k h + · obtain ⟨j, hj, -, hsz, e, hle, hge⟩ := newv q hn + intro h0 + have : q.val = 0 := by rw [h0]; rfl + omega + · -- no new range wraps + intro j hj hr + have hbj := hbv j hj + have e1 := utRt_newValA W hj + have hzz : (zA nt.val us).val = zOfA nt.val us.val := zA_valA nt us hn hus + have hw := hw0 + have e44 : (2 : Nat) ^ 44 = 17592186044416 := by norm_num + have e46 : (2 : Nat) ^ 46 = 70368744177664 := by norm_num + have ePB : layout.PPTR_BASE.val = 18446603336221196288 := by simp [layout.PPTR_BASE] + rw [← hzz] + refine spNoOvA_winA (by omega) ?_ + have h1' : (j + 1) * 2 ^ (zA nt.val us).val ≤ win * 2 ^ (zA nt.val us).val := Nat.mul_le_mul_right _ hj + rw [Nat.add_mul, Nat.one_mul] at h1' + omega + + +/-- **The grown typed heap is placed, and no new range wraps** (module docstring). -/ +theorem utRt_newPlaceA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m) + (hx : x ∈ OS) (hc : capA st s x = .Untyped p sb fi false) (W : UtWinZA nt aligned (zA nt.val us) win) + (h1 : p.val + fi.val ≤ aligned.val) (h2 : aligned.val + win * 2 ^ (zA nt.val us).val ≤ p.val + 2 ^ sb.val) + (hn : nt.val < 15) (hus : us.val < 64) (hb0 : 0 < aligned.val) : + PlaceA (utRtThA Z.th false nt us aligned win) (L.ksb s) ∧ + ∀ j, j < win → utRangedA nt.val → SpNoOvA (bjA aligned (zA nt.val us) j) (zOfA nt.val us.val) := by + exact utRt_newPlaceGenA J.j.1.place (utRt_winClrA J hx hc h1 h2) J.sys.ent.ksw (J.utWin x hx p sb fi hc) W + (by omega) h2 hn hus hb0 + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtRtRecA.lean b/proofs/Fl4ProofsA64/P3/UtRtRecA.lean index 7e20bea7e..b5752834b 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtRecA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtRecA.lean @@ -24,6 +24,7 @@ import Fl4ProofsA64.P3.UtApSys2A import Fl4ProofsA64.P3.UtAsmAllA import Fl4ProofsA64.P3.UtFullJ5A import Fl4ProofsA64.P3.UtRtDomA +import Fl4ProofsA64.P3.UtKeepA open Aeneas Aeneas.Std Result @@ -106,7 +107,8 @@ theorem utRt_recNoResetA -- record edit #5 (nodeHi : ∀ i : Fl4SpecA64.Irq, 5376 ≤ i.toNat → σ2.interruptIrqNode i = irqNodeOfA (L.ksb s2) i) (coresAll : ∀ k < Fl4SpecA64.fl4A64Platform.numNodes, ∃ c ∈ Z.Cs, c.val = k) : - UtInvVcA t (specPtr aligned) us.val slots r.2 ∧ ∃ Ac', JStage3A st AR (utRecZA Z slot nt us aligned dest off win) H' (OS ∪ NewSl false nt us aligned win) + UtInvVcA t (specPtr aligned) us.val slots r.2 ∧ UtKeepA σ2 (utInvStA t (specPtr aligned) us.val slots r.2) ∧ + ∃ Ac', JStage3A st AR (utRecZA Z slot nt us aligned dest off win) H' (OS ∪ NewSl false nt us aligned win) (utUserA H' U) Ac' Pp (Tb ∪ UtSchedNewA nt us aligned win.val) Lv ia ie (N ∪ UtOfTyA 3 nt us aligned win.val) (Ep ∪ UtOfTyA 2 nt us aligned win.val) (Rp ∪ UtOfTyA 6 nt us aligned win.val) Bf @@ -172,7 +174,7 @@ theorem utRt_recNoResetA have vcS := utRt_vcSnapA J2 hx hc W h1 h2 hn hus w VW htt KI.spec obtain ⟨eτ, Hτ, vmem⟩ := utRt_vcStepA W hn hus htt hlen KI.spec rw [← eτ] at vcS - exact ⟨vmem, utRt_asmAllA J J2 IC KSp KI KH KSc KS rfl K j5 R5 Hτ R6 vcS + exact ⟨vmem, UtKeepA.vcInit (UtKeepA.ofNew KI.spec (utRtBody_lastA hr')) _, utRt_asmAllA J J2 IC KSp KI KH KSc KS rfl K j5 R5 Hτ R6 vcS (utRt_domA J2 hx hc (by omega) h2 w ((utRtBody_globA hr').domk.trans Hτ.domk)) (utRt_ipiA J2 hx hc (by omega) h2 w) (bufVs_subA J.bufVs KS.ksb hVs)⟩ diff --git a/proofs/Fl4ProofsA64/P3/UtRtRecRstA.lean b/proofs/Fl4ProofsA64/P3/UtRtRecRstA.lean index 80d285a4b..c34c6c2fe 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtRecRstA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtRecRstA.lean @@ -15,6 +15,7 @@ Premises: those of `utCreate_postA` ([P] `hVP`, `hKt` / `hK0`; [J] `hkw`). New t import Fl4ProofsA64.P3.UtApRstA import Fl4ProofsA64.P3.UtRtRecTopA import Fl4ProofsA64.P3.UtRtDomA +import Fl4ProofsA64.P3.UtKeepA open Aeneas Aeneas.Std Result @@ -125,7 +126,8 @@ theorem utRt_recRstA -- record edit #5 (nodeHi : ∀ i : Fl4SpecA64.Irq, 5376 ≤ i.toNat → σ3.interruptIrqNode i = irqNodeOfA (L.ksb s3) i) (coresAll : ∀ k < Fl4SpecA64.fl4A64Platform.numNodes, ∃ c ∈ Z0.Cs, c.val = k) : - UtInvVcA t (specPtr aligned) us.val slots r.2 ∧ ∃ Ac', JStage3A st AR (utRecZA Z0 slot nt us aligned dest off win) H' (s1aRtSlots OS1 false nt us aligned win) + UtInvVcA t (specPtr aligned) us.val slots r.2 ∧ UtKeepA σ3 (utInvStA t (specPtr aligned) us.val slots r.2) ∧ + ∃ Ac', JStage3A st AR (utRecZA Z0 slot nt us aligned dest off win) H' (s1aRtSlots OS1 false nt us aligned win) (utUserA H' U) Ac' Pp0 (Tb0 ∪ UtSchedNewA nt us aligned win.val) Lv0 ia ie (N1 ∪ UtOfTyA 3 nt us aligned win.val) (E1 ∪ UtOfTyA 2 nt us aligned win.val) (Rp1 ∪ UtOfTyA 6 nt us aligned win.val) Bf1 @@ -191,7 +193,7 @@ theorem utRt_recRstA have vcS := utRt_vcSnapA J2 hx hc W h1' h2 hn hus w VW htt KI.spec obtain ⟨eτ, Hτ, vmem⟩ := utRt_vcStepA W hn hus htt hlen KI.spec rw [← eτ] at vcS - exact ⟨vmem, utRt_asmAll0A J J2 IC KSp KI KH KSc KS rfl K j5 R5 Hτ R6 vcS + exact ⟨vmem, UtKeepA.vcInit (UtKeepA.ofNew KI.spec (utRtBody_lastA hr')) _, utRt_asmAll0A J J2 IC KSp KI KH KSc KS rfl K j5 R5 Hτ R6 vcS (utRt_domA J2 hx hc h1' h2 w ((utRtBody_globA hr').domk.trans Hτ.domk)) (utRt_ipiA J2 hx hc h1' h2 w) (bufVs_subA J2.bufVs KSc.hks hVs)⟩ @@ -241,6 +243,7 @@ theorem utCreate_recRstA (hA : P0.ArchTotal ar) win.val → J7A st (J7R2A st ar nA) Z'' H'' (s1aRtSlots OS1 false nt us aligned win) res.2.1 σ'' m'') → UtInvVcA t (specPtr aligned) us.val (windowSlotsA dest rd off.val win.val) r.2 ∧ + UtKeepA σ3 (utInvStA t (specPtr aligned) us.val (windowSlotsA dest rd off.val win.val) r.2) ∧ ∃ Ac', JStage3A st AR (utRecZA Z0 (cslotAddrA sl) nt us aligned dest off win) H'' (s1aRtSlots OS1 false nt us aligned win) (utUserA H'' U) Ac' Pp0 (Tb0 ∪ UtSchedNewA nt us aligned win.val) Lv0 diff --git a/proofs/Fl4ProofsA64/P3/UtRtRecTopA.lean b/proofs/Fl4ProofsA64/P3/UtRtRecTopA.lean index 17bba403d..c921b0dde 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtRecTopA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtRecTopA.lean @@ -3,7 +3,7 @@ P3 (aarch64, A64-P3 Untyped, full-record post): **the creation of a RAM retype w after it**, relation level, from the creation start (after the caller's restart write). * **`utCreate_recA`**: from the record at the decode's state and at the creation start, A64 P1's `CrtP` there and the - decode's context (`UtCtxA`), `retype` succeeds, and for every outcome of the spec body and every A64 P1 creation end + decode's context (`UtCtxA`), `retype` succeeds, the spec body has an outcome (`utRt_neA`), and for every outcome of the spec body and every A64 P1 creation end at the decode's parameters (`S1aRtIn` with `utRt_j7TopA`'s `ArmQIVAt`, `HeapKsOff` and `J7A` hook) the whole record `JStage3A` holds at the grown heap, slots and sets (`utRt_recNoResetA`). @@ -17,6 +17,7 @@ Premises: those of `utCreate_postA` ([P] `hVP`, `hKt` / `hK0`; [J] `hkw`). No ne -/ import Fl4ProofsA64.P3.UtRtRecA import Fl4ProofsA64.P3.UtRtCreateA +import Fl4ProofsA64.P3.UtRtExA open Aeneas Aeneas.Std Result @@ -88,6 +89,8 @@ theorem utCreate_recA (hA : P0.ArchTotal ar) (hrw : ∀ b, Aligned b → b ≠ stA (L.curW s) → L.mem s2 b = L.mem s b) : untyped.retype st ar s2 a (cslotAddrA sl) false aligned nt us dest off win false ⦃ res => res.1 = .Ok () ∧ + (∃ r, r ∈ (utRtBodyA sl (specPtr p) (specPtr aligned) t us.val (windowSlotsA dest rd off.val win.val) + false σ2).1) ∧ ∀ r ∈ (utRtBodyA sl (specPtr p) (specPtr aligned) t us.val (windowSlotsA dest rd off.val win.val) false σ2).1, ∀ (H'' : Heap) (Vn U0 Ac0 : Set U64) (lo hi : Nat) (extra : Aeneas.Std.Array obj.Slot 3#usize), S1aRtIn st H Z.Cs OS U0 Ac0 s ia ie (cslotAddrA sl) p sb fi false extra H H'' OS s2 res.2.1 lo hi aligned @@ -99,6 +102,7 @@ theorem utCreate_recA (hA : P0.ArchTotal ar) win.val → J7A st (J7R2A st ar nA) Z'' H'' (OS ∪ NewSl false nt us aligned win) res.2.1 σ'' m'') → UtInvVcA t (specPtr aligned) us.val (windowSlotsA dest rd off.val win.val) r.2 ∧ + UtKeepA σ2 (utInvStA t (specPtr aligned) us.val (windowSlotsA dest rd off.val win.val) r.2) ∧ ∃ Ac', JStage3A st AR (utRecZA Z (cslotAddrA sl) nt us aligned dest off win) H'' (OS ∪ NewSl false nt us aligned win) (utUserA H'' U) Ac' Pp (Tb ∪ UtSchedNewA nt us aligned win.val) Lv ia ie (N ∪ UtOfTyA 3 nt us aligned win.val) (Ep ∪ UtOfTyA 2 nt us aligned win.val) @@ -194,7 +198,9 @@ theorem utCreate_recA (hA : P0.ArchTotal ar) (WP.spec_and tcbW (WP.spec_and vcW (WP.spec_and hiW (WP.spec_and (utRetype_nfiA (ar := ar) hA C a) (utRt_j5LoopA hA C hTr2 J2.j5.1.1 J2.j5.1.2.1 hrev a)))))))) ?_ rintro res ⟨⟨hok, Kall⟩, w, ⟨-, -, WT, -⟩, TR, VW, HW, ⟨nfi, hnv, cap'⟩, L5⟩ - refine ⟨hok, fun r hr H'' Vn U0 Ac0 lo hi extra ER arm ko j7at => ?_⟩ + have ne := utRt_neA J2 hsO hc2 W h1 h2 X.ty hus hsrc hlen + (fun d hd => let ⟨q, e, hq, _⟩ := hdst d hd; ⟨q, e, hq⟩) (specPtr p) + refine ⟨hok, ne, fun r hr H'' Vn U0 Ac0 lo hi extra ER arm ko j7at => ?_⟩ exact utRt_recNoResetA J ER noch arm ko j7at hvs hrw J2 hc2 W h1 h2 pos us39 hb0 hc47 C.dn w WT (fun h => (TR h).1) (fun h => (TR h).2) VW HW hnv cap' L5 X.ty hus hsc rfl hsrc hlen hdst hdstA hr (Kall r hr) J2.utWin J2.j.1.irq.nodeHi J2.coresAll diff --git a/proofs/Fl4ProofsA64/P3/UtRtResetA.lean b/proofs/Fl4ProofsA64/P3/UtRtResetA.lean index ddb3aac35..52277c64a 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtResetA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtResetA.lean @@ -102,13 +102,13 @@ theorem utRetype_resetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar : (Y : UtRstReadyA (ar := ar) st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n nA m Ud Acd Rq Nt ex (cslotAddrA cte) p sb fi s a σ) (hn : nA.val = fl4A64Platform.s2IpaBits) - (hPost : ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + (hPost : fi ≠ 0#u64 → ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) (hchunk : resetChunkBits = 16) (Rpre : U64 → S → A → State Unit → Prop) (T : A → State Unit → Prop) (hT : ∀ (a : A) (σ σ' : State Unit), T a σ → UtCnStepA σ σ' → σ'.machineState = σ.machineState → T a σ') (hT0 : T a (utDelStA (specPtr p) sb.val σ)) - (hpp : ∀ (Rq' Nt' : Set U64) (o : U64), o ≠ 0#u64 → PPHypUtA st ar (dropSetA (utDA p sb.val) OS) + (hpp : (fi ≠ 0#u64 ∧ 16 ≤ sb.val) → ∀ (Rq' Nt' : Set U64) (o : U64), o ≠ 0#u64 → PPHypUtA st ar (dropSetA (utDA p sb.val) OS) (fun s a σ => UtRstInvA (ar := ar) st AR (dropZA (utDA p sb.val) Z) (dropHA (utDA p sb.val) H) (dropSetA (utDA p sb.val) OS) U Ac (dropSetA (utDA p sb.val) Pp) Tb Lv ia ie (dropSetA (utDA p sb.val) N) (dropSetA (utDA p sb.val) E) (dropSetA (utDA p sb.val) Rp) @@ -130,6 +130,7 @@ theorem utRetype_resetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar : (dropSetA (utDA p sb.val) Rp) (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s3 a σ3 (dropMA (utDA p sb.val) m) → SymL st (dropHA (utDA p sb.val) H) Z.Cs s3 → capA st s3 (cslotAddrA cte) = .Untyped p sb 0#u64 false → + UtKeepCurA σ σ3 → untyped.retype st ar s3 a (cslotAddrA cte) false base nt us dest off win false ⦃ r => K r ⦄) -- used, a chunk or more (hbig : fi ≠ 0#u64 → 16 ≤ sb.val → ∀ (s3 : S) (a3 : A) (σ3 : State Unit) (Rq' Nt' : Set U64), @@ -167,14 +168,14 @@ theorem utRetype_resetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar : show fi.val = 0 rw [h0]; rfl by_cases hs : sb.val < 16 - · obtain ⟨s3, σ3, e, hm, J3, Y3, hc3⟩ := utReset_smallA ar J Y.dec Y.place Y.cap Y.noch Y.symL Y.othT Y.othC hn - cte hq hth rfl hPost h0 hs hchunk + · obtain ⟨s3, σ3, e, hm, J3, Y3, hc3, kp⟩ := utReset_smallA ar J Y.dec Y.place Y.cap Y.noch Y.symL Y.othT Y.othC hn + cte hq hth rfl (hPost h0) h0 hs hchunk rw [e, bind_ok] simp only [Aeneas.Std.uncurry_apply_pair, core.result.Result.Insts.CoreOpsTry.branch, bind_ok] - exact hsmall h0 hs s3 σ3 e hm J3 Y3 hc3 + exact hsmall h0 hs s3 σ3 e hm J3 Y3 hc3 kp · have hb : 16 ≤ sb.val := by omega have R := utReset_bigA ar Y.sact J Y.dec Y.place Y.cap Y.noch Y.symL Y.othT Y.othC hn cte hq hth rfl - hPost Rpre T hT hT0 hpp h0 hb hchunk + (hPost h0) Rpre T hT hT0 (hpp ⟨h0, hb⟩) h0 hb hchunk obtain ⟨⟨r1, s3, a3⟩, eR, h⟩ := spec_exists_dut R rw [eR, bind_ok] rcases h with ⟨hok, σ3, Rq', Nt', hm, I, TI⟩ | ⟨herr, σ3, o, hm, hR⟩ diff --git a/proofs/Fl4ProofsA64/P3/UtRtResetCrtA.lean b/proofs/Fl4ProofsA64/P3/UtRtResetCrtA.lean index af2b65a69..df7e1e267 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtResetCrtA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtResetCrtA.lean @@ -244,7 +244,7 @@ theorem utDecode_resetPostA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (h exact ⟨_, _, _, _, _, rfl, y, hkT, aligned, nt, us, dest, off, win, rd, hU, rfl, rfl, rfl, rfl, Or.inr ⟨rfl, σ3, hm, J3⟩⟩ case hsmall => - intro _ _ s3 σ3 eres hm J3 _ _ + intro _ _ s3 σ3 eres hm J3 _ _ _ refine WP.spec_mono (drop s3 a σ3 eres J3) fun res h => ?_ exact ⟨_, _, _, _, _, rfl, y, hkT, aligned, nt, us, dest, off, win, rd, hU, rfl, rfl, rfl, rfl, Or.inl ⟨h.1, σ3, hm, _, _, Or.inr ⟨rfl, rfl⟩, h.2⟩⟩ diff --git a/proofs/Fl4ProofsA64/P3/UtRtResetNpA.lean b/proofs/Fl4ProofsA64/P3/UtRtResetNpA.lean new file mode 100644 index 000000000..69ea93c41 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtRtResetNpA.lean @@ -0,0 +1,85 @@ +/- +P3 (aarch64, A64-P3 Untyped, M3): **`utRetype_resetA` without a preempting reset** ([S], lead's ruling for Stage 4): a retype +that resets its RAM untyped first, where the reset never runs the chunk loop: the free index is zero (nothing to clear) or +the block is below the chunk size. + +* **`utRetype_resetNpA`**: from `utRetype_resetA` with the preemption point's premises removed; the preempted outcome is + impossible (`utReset_noErrA`) and the chunked case is excluded by the [S] premise. + +Named premises: `utRetype_resetA`'s other than `hpp` / `hT` / `hT0` / `Rpre`; [S] `hS : sb < 16 ∨ fi = 0` (no preempting +chunk loop; the preempted reset is post-Stage-4 backlog). +-/ +import Fl4ProofsA64.P3.UtRtResetA +import Fl4ProofsA64.P3.UtResetNoErrA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4ProofsA64.P3.Notif Fl4ProofsA64.P3.Sched Fl4SpecA64 Fl4Spec Classical + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {N E Rp : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} + {n : Nat} {nA : U64} {m : McState} + +variable {Ud Acd Rq Nt : Set U64} {ex : Aeneas.Std.Array obj.Slot 3#usize} {p sb fi : U64} + +set_option maxHeartbeats 1000000 in +/-- **A retype that resets its RAM untyped first, without a chunk loop** (module docstring). -/ +theorem utRetype_resetNpA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar : machine.Arch A) {s : S} {a : A} + {σ : State Unit} + (cte : CslotPtr) {qc : U64} (hq : cte.1 = specPtr qc) (hth : Z.th qc = some (.cnode cte.2.length)) + (Y : UtRstReadyA (ar := ar) st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n nA m Ud Acd Rq Nt ex (cslotAddrA cte) + p sb fi s a σ) + (hn : nA.val = fl4A64Platform.s2IpaBits) + (hPost : fi ≠ 0#u64 → ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + (hchunk : resetChunkBits = 16) + (hS : sb.val < 16 ∨ fi = 0#u64) + (base nt us dest off win : U64) + (K : core.result.Result Unit error.Exc × S × A → Prop) + -- an unused untyped: the creation from the same state + (hnoop : fi = 0#u64 → untyped.reset_untyped st ar s a (cslotAddrA cte) = ok (core.result.Result.Ok (), s, a) → + (.ok (), σ) ∈ ((resetUntypedCap (Z := Unit) cte).run σ).1 → + untyped.retype st ar s a (cslotAddrA cte) false base nt us dest off win false ⦃ r => K r ⦄) + -- used, below a chunk + (hsmall : fi ≠ 0#u64 → sb.val < 16 → ∀ (s3 : S) (σ3 : State Unit), + untyped.reset_untyped st ar s a (cslotAddrA cte) = ok (core.result.Result.Ok (), s3, a) → + (.ok (), σ3) ∈ ((resetUntypedCap (Z := Unit) cte).run σ).1 → + JStage3A st AR (dropZA (utDA p sb.val) Z) (dropHA (utDA p sb.val) H) (dropSetA (utDA p sb.val) OS) U Ac + (dropSetA (utDA p sb.val) Pp) Tb Lv ia ie (dropSetA (utDA p sb.val) N) (dropSetA (utDA p sb.val) E) + (dropSetA (utDA p sb.val) Rp) (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s3 a σ3 (dropMA (utDA p sb.val) m) → + SymL st (dropHA (utDA p sb.val) H) Z.Cs s3 → capA st s3 (cslotAddrA cte) = .Untyped p sb 0#u64 false → + UtKeepCurA σ σ3 → + untyped.retype st ar s3 a (cslotAddrA cte) false base nt us dest off win false ⦃ r => K r ⦄) : + untyped.retype st ar s a (cslotAddrA cte) true base nt us dest off win false ⦃ r => K r ⦄ := by + have hcx : capA st s (cslotAddrA cte) = .Untyped p sb fi false := okinj ((capA_eq s _).symm.trans Y.cap) + have hab : AbsSlotA Z.th cte := ⟨qc, hq, Or.inl hth⟩ + obtain ⟨ac, hg, hr⟩ := Y.rec_.j.1.st.getAbsA hab + have eac : ac = .untypedCap false (specPtr p) sb.val fi.val := by + have h := hr.2 + rw [show capAtA (L.mem s) (cslotAddrA cte) = capA st s (cslotAddrA cte) from rfl, hcx] at h + exact (show absCapA (.Untyped p sb fi false) = ac from h).symm + rw [eac] at hg + have hS' : sb.val < resetChunkBits ∨ fi.val = 0 := by + rcases hS with h | h + · exact Or.inl (by rw [hchunk]; exact h) + · exact Or.inr (by rw [h]; rfl) + have hnS : ¬ (fi ≠ 0#u64 ∧ 16 ≤ sb.val) := fun h => by + rcases hS with h' | h' + · have := h.2; omega + · exact h.1 h' + exact utRetype_resetA ar cte hq hth Y hn hPost hchunk (fun _ _ _ _ => False) (fun _ _ => True) + (fun _ _ _ _ _ _ => trivial) trivial (fun h => (hnS h).elim) base nt us dest off win K hnoop hsmall + (fun h0 hb => (hnS ⟨h0, hb⟩).elim) + (fun s3 a3 σ3 o hm _ => (utReset_noErrA hg hS' hm).elim) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtRtResetPpA.lean b/proofs/Fl4ProofsA64/P3/UtRtResetPpA.lean index 1178c832e..ef299d1cc 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtResetPpA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtResetPpA.lean @@ -73,6 +73,7 @@ theorem utRetype_resetPpA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar (dropSetA (utDA p sb.val) Rp) (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s3 a σ3 (dropMA (utDA p sb.val) m) → SymL st (dropHA (utDA p sb.val) H) Z.Cs s3 → capA st s3 (cslotAddrA cte) = .Untyped p sb 0#u64 false → + UtKeepCurA σ σ3 → untyped.retype st ar s3 a (cslotAddrA cte) false base nt us dest off win false ⦃ r => K r ⦄) -- used, a chunk or more (hbig : fi ≠ 0#u64 → 16 ≤ sb.val → ∀ (s3 : S) (a3 : A) (σ3 : State Unit) (Rq' Nt' : Set U64), @@ -92,14 +93,14 @@ theorem utRetype_resetPpA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar (dropSetA (utDA p sb.val) Rp) (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s3 a3 σ3 (dropMA (utDA p sb.val) m) → K (.Err .Preempted, s3, a3)) : untyped.retype st ar s a (cslotAddrA cte) true base nt us dest off win false ⦃ r => K r ⦄ := by - refine utRetype_resetA ar cte hq hth Y hn hPost hchunk + refine utRetype_resetA ar cte hq hth Y hn (fun _ => hPost) hchunk (fun _ s a σ => JStage3A st AR (dropZA (utDA p sb.val) Z) (dropHA (utDA p sb.val) H) (dropSetA (utDA p sb.val) OS) U Ac (dropSetA (utDA p sb.val) Pp) Tb Lv ia ie (dropSetA (utDA p sb.val) N) (dropSetA (utDA p sb.val) E) (dropSetA (utDA p sb.val) Rp) (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ (dropMA (utDA p sb.val) m)) (UtPpTimeA Clock) (fun a σ σ' T H h => T.cnStep H h) hT0 ?_ base nt us dest off win K hnoop hsmall hbig (fun s3 a3 σ3 _ hm hR => hpre s3 a3 σ3 hm hR) - intro Rq' Nt' o _ s a σ h + intro _ Rq' Nt' o _ s a σ h refine WP.spec_mono (utPp_hookA (AR := AR) (Z := dropZA (utDA p sb.val) Z) ar hnd P hvp hC hNow hAr hirq hmb s a σ h) ?_ rintro r ⟨k, σ', g⟩ diff --git a/proofs/Fl4ProofsA64/P3/UtVcTrA.lean b/proofs/Fl4ProofsA64/P3/UtVcTrA.lean index 224d47c91..b54eb0a3a 100644 --- a/proofs/Fl4ProofsA64/P3/UtVcTrA.lean +++ b/proofs/Fl4ProofsA64/P3/UtVcTrA.lean @@ -34,7 +34,7 @@ structure UtVcStepA (σ τ : State Unit) : Prop extends SpecGlobA σ τ where theorem utVcStepA_of {Q : ObjRef → Prop} {σ : State Unit} (h : ∀ p, Q p → σ.kheap p = some (.archObj (.vcpu defaultVcpu))) : UtVcStepA σ (utVcInitA Q σ) := by - refine ⟨⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, fun p => ?_, rfl, rfl, rfl, rfl⟩ + refine ⟨SpecGlobA.ofKey rfl, fun p => ?_, rfl, rfl, rfl, rfl⟩ by_cases q : Q p · exact Or.inr ⟨h p q, utVcInit_vcpuA q (h p q)⟩ · exact Or.inl (utVcInit_offA q) diff --git a/proofs/Fl4ProofsA64/P3/VcpuDelFrameA.lean b/proofs/Fl4ProofsA64/P3/VcpuDelFrameA.lean index d58769819..bf033ada5 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuDelFrameA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuDelFrameA.lean @@ -223,8 +223,35 @@ structure VcpuSpecStepA (H : Heap) (σ σ' : Fl4SpecA64.State Unit) (regWr : Boo σ'.machineState.underlyingMemory a ≠ σ.machineState.underlyingMemory a → ∃ p bits, H p = some (.other bits) ∧ p.val ≤ (fl4Ptr a).val ∧ (fl4Ptr a).val < p.val + 2 ^ bits +/-- **The key of `VcpuSpecStepA`**: the kept components as one tuple (record-extension convention, `AGENTS.md`, "Proof +records"): adding a kept component edits this key, `VcpuSpecStepA.ofKey` and the structure. -/ +abbrev VcpuKeyA (σ : Fl4SpecA64.State Unit) := + (σ.readyQueues, σ.releaseQueue, σ.curThread, σ.idleThread, σ.curSc, σ.schedulerAction, σ.cdt, σ.isOriginalCap, + σ.interruptIrqNode, σ.interruptStates, σ.curDomain, σ.domainTime, σ.domainIndex, σ.domainList, σ.curTime, + σ.consumedTime, σ.reprogramTimer, σ.archState.armAsidTable, σ.archState.armCurrentVcpu, + σ.machineState.timeState, σ.machineState.lastMachineTime, σ.domainStartIndex, σ.archState.armUsGlobalVspace) + +/-- The one constructor of `VcpuSpecStepA` to use at call sites: `ofKey rfl kh umOff`. -/ +theorem VcpuSpecStepA.ofKey {H : Heap} {σ σ' : Fl4SpecA64.State Unit} {regWr : Bool} + (h : VcpuKeyA σ' = VcpuKeyA σ) + (kh : ∀ p, σ'.kheap p = σ.kheap p ∨ + (∃ x x', σ.kheap p = some (.tcb x) ∧ σ'.kheap p = some (.tcb x') ∧ TcbKeepFieldsA x x') ∨ + (∃ v v', σ.kheap p = some (.archObj (.vcpu v)) ∧ σ'.kheap p = some (.archObj (.vcpu v')) ∧ + (if regWr then True else + v'.vcpuRegs = v.vcpuRegs ∧ v'.vcpuVppiMasked = v.vcpuVppiMasked ∧ + v'.vcpuVgic = v.vcpuVgic ∧ v'.vcpuExt.regs = v.vcpuExt.regs ∧ + v'.vcpuExt.runOffset = v.vcpuExt.runOffset ∧ + v'.vcpuExt.runOutMask = v.vcpuExt.runOutMask))) + (umOff : ∀ a : Fl4SpecA64.Word, + σ'.machineState.underlyingMemory a ≠ σ.machineState.underlyingMemory a → + ∃ p bits, H p = some (.other bits) ∧ p.val ≤ (fl4Ptr a).val ∧ (fl4Ptr a).val < p.val + 2 ^ bits) : VcpuSpecStepA H σ σ' regWr := by + simp only [VcpuKeyA, Prod.mk.injEq] at h + obtain ⟨h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, h14, h15, h16, h17, h18, h19, h20, h21, h22, h23⟩ := h + exact ⟨h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, h14, h15, h16, h17, h18, h19, h20, h21, h22, h23, kh, + umOff⟩ + theorem VcpuSpecStepA.domk {H : Heap} {σ σ' : Fl4SpecA64.State Unit} {regWr : Bool} (HS : VcpuSpecStepA H σ σ' regWr) : DomKeepA σ σ' := - ⟨HS.domI, HS.domS, HS.domL, HS.gvs⟩ + DomKeepA.ofKey (by unfold DomKeyA; rw [HS.domI, HS.domS, HS.domL, HS.gvs]) /-- (record edit #8c) A VCPU / TCB-register spec step keeps priorities, the IPC queues, the SCs and the replies. -/ theorem QKeepA.of_vcpuStepA {H : Heap} {σ σ' : Fl4SpecA64.State Unit} {regWr : Bool} (HS : VcpuSpecStepA H σ σ' regWr) : QKeepA σ σ' := by @@ -251,8 +278,7 @@ theorem QKeepA.of_vcpuStepA {H : Heap} {σ σ' : Fl4SpecA64.State Unit} {regWr : · rw [hp] at h2; cases h2 theorem VcpuSpecStepA.refl (H : Heap) (σ : Fl4SpecA64.State Unit) (regWr : Bool := false) : VcpuSpecStepA H σ σ regWr := - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, - fun _ => Or.inl rfl, fun _ h => absurd rfl h⟩ + VcpuSpecStepA.ofKey rfl (fun _ => Or.inl rfl) (fun _ h => absurd rfl h) theorem VcpuSpecStepA.keepObj {H : Heap} {σ σ' : Fl4SpecA64.State Unit} {regWr : Bool} (HS : VcpuSpecStepA H σ σ' regWr) {p : ObjRef} {o : KernelObject} (h : σ.kheap p = some o) diff --git a/proofs/Fl4ProofsA64/P3/VcpuDelHookA.lean b/proofs/Fl4ProofsA64/P3/VcpuDelHookA.lean index a7353e9fc..754c01f77 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuDelHookA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuDelHookA.lean @@ -1342,7 +1342,7 @@ private theorem vcpu_clear_run_pair_coreA subst e; exact Or.inr (Or.inl ⟨ct, hct, 3672#u64, by decide, Or.inr (Or.inr rfl), rfl⟩)) have hw : WritesIn st s s2 (VcpuWrNoStA st Z OS s) := (hw1.trans hw2).mono (fun _ h => h.elim id id) have hHS : VcpuSpecStepA H σ σ' := by - refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ?_, fun _ h => absurd rfl h⟩ + refine VcpuSpecStepA.ofKey rfl ?_ (fun _ h => absurd rfl h) intro p by_cases ept : p = specPtr ct · subst ept @@ -1639,7 +1639,7 @@ private theorem vcpu_tcb_reg_wr_coreA have hw : WritesIn st s s' (VcpuWrNoStA st Z OS s) := (writesIn_wr hal_reg).mono fun _ e => by subst e; exact tcb_reg_in_vcpuWrH hct hft hr have hHS : VcpuSpecStepA H σ σ' := by - refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ?_, fun _ h => absurd rfl h⟩ + refine VcpuSpecStepA.ofKey rfl (?_) (fun _ h => absurd rfl h) intro p by_cases ep : p = specPtr ct · subst ep @@ -2036,7 +2036,7 @@ private theorem vcpu_dissoc_bind_stage3TA have hw : WritesIn st s s4 (VcpuWrNoStA st Z OS s) := (((hw1.trans hw2).mono (fun _ h => h.elim id id)).trans hw3 |>.mono (fun _ h => h.elim id id)).trans hw4 |>.mono (fun _ h => h.elim id id) have hHS : VcpuSpecStepA H σ σ' := by - refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ?_, fun _ h => absurd rfl h⟩ + refine VcpuSpecStepA.ofKey rfl (?_) (fun _ h => absurd rfl h) intro p by_cases epv : p = specPtr vc · subst epv diff --git a/proofs/Fl4ProofsA64/P3/VcpuDelStepsA.lean b/proofs/Fl4ProofsA64/P3/VcpuDelStepsA.lean index 942d4d404..5ba6419d5 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuDelStepsA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuDelStepsA.lean @@ -122,7 +122,7 @@ private theorem fl4CancelRun_vcpuStepA {H : Heap} {σ : Fl4SpecA64.State Unit} { (Function.update σ.kheap vc (some (.archObj (.vcpu { xv with vcpuExt := { xv.vcpuExt with runCaller := none } })))) t (some (.tcb { xt with tcbExt := { xt.tcbExt with tcbRunVcpu := none } }))) } := by have hne : t ≠ vc := fun e => by rw [e, hkv] at hkt; cases hkt - refine ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ?_, fun _ h => absurd rfl h⟩ + refine VcpuSpecStepA.ofKey rfl ?_ (fun _ h => absurd rfl h) intro p by_cases ept : p = t · subst ept diff --git a/proofs/Fl4ProofsA64/P3/VcpuRegJA.lean b/proofs/Fl4ProofsA64/P3/VcpuRegJA.lean index f52118be9..1d33b8f7d 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuRegJA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuRegJA.lean @@ -333,7 +333,7 @@ theorem JAtZAX.of_specVcpuNonLinkA {AR : A → HwRootA → Prop} {Z : XSetsA} {s obtain ⟨y, n, hkc, -⟩ := J.1.sch.sc c hc exact hkh_other _ (hne_nonV _ (by rw [hkc]; simp)) have hG : SpecGlobA σ (updKSc σ (specPtr vc) (.archObj (.vcpu v'))) := - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + SpecGlobA.ofKey rfl have hst' : StateRelA Z.th (L.mem s) (updKSc σ (specPtr vc) (.archObj (.vcpu v'))) := { cnode := fun p r hp => by obtain ⟨cs, hkcs, hrest⟩ := J.1.st.cnode p r hp diff --git a/proofs/Fl4ProofsA64/P3/VcpuRunBaseA.lean b/proofs/Fl4ProofsA64/P3/VcpuRunBaseA.lean index fa2c84fc5..ef291c421 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuRunBaseA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuRunBaseA.lean @@ -763,7 +763,7 @@ theorem VcpuXferStateA.enter_run_vm {AR : A → HwRootA → Prop} {Z : XSetsA} (fun e => X.vcpu.place.disj_ub _ (hvc_page 32#u64 (by decide) (by decide)) (e ▸ hb)) (fun e => X.vcpu.place.disj_ub _ (hvc_page 40#u64 (by decide) (by decide)) (e ▸ hb)) (fun e => X.fmem.disj_tcb b hb ct hct 3672#u64 (by decide) (by rw [← runVcpuA_eq]; exact e))) - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + (SpecGlobA.ofKey rfl) rfl rfl ⟨rfl, rfl⟩ (fun p hpv hpt => by rw [updKSc_other _ (hpt ct hct).symm, updKSc_other _ (hpv vc hvc).symm]) (fun t ht x hkx => by @@ -912,7 +912,7 @@ theorem VcpuXferStateA.enter_run_vm {AR : A → HwRootA → Prop} {Z : XSetsA} scOff := h0.scOff } have hIrq5 : IrqRelA (L.mem s5) (L.ksb s5) σ5 := by have h0 : IrqRelA (L.mem s4) (L.ksb s4) σ5 := - hJ4.irq.of_spec ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + hJ4.irq.of_spec (SpecGlobA.ofKey rfl) exact { st := fun i hi => by rw [hksb5, ← hksb4] diff --git a/proofs/Fl4ProofsA64/P3/VcpuRunLinkJA.lean b/proofs/Fl4ProofsA64/P3/VcpuRunLinkJA.lean index 20c0b9c9a..81656b266 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuRunLinkJA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuRunLinkJA.lean @@ -757,7 +757,7 @@ theorem VcpuXferStateA.clear_run_link {AR : A → HwRootA → Prop} {Z : XSetsA} (fun b hb => hmem_other _ (X.fmem.aligned b hb) (vc_disj_ubA X.vcpu.place (vcpuHdr_in_vcPage hvc (by decide) (by decide)) hb).symm (fun e => X.fmem.disj_tcb b hb ct hct 3672#u64 (by decide) (by rw [← hrun_eq]; exact e))) - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ rfl rfl ⟨rfl, rfl⟩ + (SpecGlobA.ofKey rfl) rfl rfl ⟨rfl, rfl⟩ (fun p hnv hnt => by change (updKSc (updKSc σ (specPtr vc) _) (specPtr ct) _).kheap p = σ.kheap p rw [updKSc_other _ (fun e => hnt ct hct e.symm), updKSc_other _ (fun e => hnv vc hvc e.symm)]) @@ -1219,7 +1219,7 @@ theorem VcpuXferStateA.set_state_running_from_vm {AR : A → HwRootA → Prop} { scOff := h0.scOff } have hIrq : IrqRelA (L.mem s') (L.ksb s') σ' := by have h0 : IrqRelA (L.mem s) (L.ksb s) σ' := - X.j.1.irq.of_spec ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ + X.j.1.irq.of_spec (SpecGlobA.ofKey rfl) exact { st := fun i hi => by rw [hksb', mem_wr_neA hal_st (hfa _ (.nslot _ (.irq i hi))) (hKs_st (irqOffA i) (by diff --git a/proofs/Fl4ProofsA64/P3/VcpuUnbindJA.lean b/proofs/Fl4ProofsA64/P3/VcpuUnbindJA.lean index 8f68b8011..a87b2d694 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuUnbindJA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuUnbindJA.lean @@ -229,7 +229,7 @@ theorem VcpuXferStateA.dissoc_bind {AR : A → HwRootA → Prop} {Z : XSetsA} (vc_disj_ubA X.vcpu.place hvp0 hb).symm (vc_disj_ubA X.vcpu.place hvp8 hb).symm (fun e => X.fmem.disj_tcb b hb t ht 3664#u64 (by decide) e)) - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ rfl rfl ⟨rfl, rfl⟩ + (SpecGlobA.ofKey rfl) rfl rfl ⟨rfl, rfl⟩ (fun p hnv hnt => by rw [updKSc_other _ (fun e => hnv vc hvc e.symm), updKSc_other _ (fun e => hnt t ht e.symm)]) hspec_tcb3 hspec_ty3 @@ -635,7 +635,7 @@ theorem VcpuXferStateA.assoc_bind {AR : A → HwRootA → Prop} {Z : XSetsA} (fun b hb => hmem2 _ (X.fmem.aligned b hb) (vc_disj_ubA X.vcpu.place hvp0 hb).symm (fun e => X.fmem.disj_tcb b hb t ht 3664#u64 (by decide) e)) - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ rfl rfl ⟨rfl, rfl⟩ + (SpecGlobA.ofKey rfl) rfl rfl ⟨rfl, rfl⟩ (fun p hnv hnt => by rw [updKSc_other _ (fun e => hnv vc hvc e.symm), updKSc_other _ (fun e => hnt t ht e.symm)]) hspec_tcb hspec_ty diff --git a/proofs/Fl4ProofsA64/P3/VcpuXferBaseA.lean b/proofs/Fl4ProofsA64/P3/VcpuXferBaseA.lean index fb6f6c33b..580ca8719 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuXferBaseA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuXferBaseA.lean @@ -399,7 +399,7 @@ theorem JAtZAX.of_setUm {AR : A → HwRootA → Prop} {Z : XSetsA} {s : S} {a : {σ : State Unit} {m : Fl4SpecA64.McState} (J : JAtZAX (L := L) AR Z s a σ m) (um' : Word → Word8) : JAtZAX (L := L) AR Z s a (setUm σ um') m := - J.of_spec ⟨⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩, + J.of_spec ⟨SpecGlobA.ofKey rfl, fun _ _ => rfl, fun _ _ h _ => h, rfl, rfl⟩ /-- **Atomic user-frame word store on `VcpuXferStateA`**: writing `w` at `b ∈ Ub` paired with diff --git a/proofs/Fl4ProofsA64/P3/VsAssignA.lean b/proofs/Fl4ProofsA64/P3/VsAssignA.lean index ab91fad9b..278206178 100644 --- a/proofs/Fl4ProofsA64/P3/VsAssignA.lean +++ b/proofs/Fl4ProofsA64/P3/VsAssignA.lean @@ -730,7 +730,7 @@ theorem assign_write_jointA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s have hER := J.1.ext.of_storePoolE (Lv := Z.Lv) (i := i) hp hk hkind (fun b hb => hmem b (hall b (.nslot b (.ext b hb))) (hExt b hb)) hunmS2 refine ⟨J.of_sameVsA (σ' := poolSetA σ2 p (Function.update f (BitVec.ofNat 9 i.val) (poolEntA word))) - (P0 := ∅) Hm (by constructor <;> first | rfl | exact ⟨rfl, rfl, rfl, rfl⟩) + (P0 := ∅) Hm (by constructor <;> first | rfl | exact DomKeepA.ofKey rfl) (fun q r hq => ?_) (fun q hq => ?_) (fun t ht => ?_) (fun c hc' => ?_) (fun v hv => ?_) rfl rfl (fun q v h => ?_) (fun q es h => ?_) (fun q l1 h => ?_) (fun _ h1 h2 => ⟨h1, h2⟩) (by rw [L.ksb_wr]; exact hVR) hER, diff --git a/proofs/Fl4ProofsA64/P3/VsTabJA.lean b/proofs/Fl4ProofsA64/P3/VsTabJA.lean index f5feb640c..688e3a5ec 100644 --- a/proofs/Fl4ProofsA64/P3/VsTabJA.lean +++ b/proofs/Fl4ProofsA64/P3/VsTabJA.lean @@ -561,7 +561,7 @@ theorem JAtZAX.of_pteWriteA (J : JAtZAX (L := L) AR Z s a σ m) {p i : U64} (hp obtain ⟨_, h2, -⟩ := J.1.vs.pt p hp rw [h1] at h2; cases h2 refine JAtZAX.of_tabWriteA (σ' := { ptSetA σ (specPtr p) t' with machineState := ms }) J T hi (fun w h => hfa w (FootA.s1_monoA h)) hks hcpu hm - ⟨rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, rfl, ⟨rfl, rfl, rfl, rfl⟩⟩ rfl rfl hk ?_ hroot VR + (SpecGlobA.ofKey rfl) rfl rfl hk ?_ hroot VR (J.1.ext.of_tabWriteA (fun b hb => hm b (hfa b (.nslot b (.ext b hb))) fun e => T.mem i hi (e ▸ .nslot b (.ext b hb))) hpS hpP rfl hk hT) intro ko e hx diff --git a/proofs/Fl4ProofsA64/P3/W1UserBytesA.lean b/proofs/Fl4ProofsA64/P3/W1UserBytesA.lean index dffcc44d5..f872b4283 100644 --- a/proofs/Fl4ProofsA64/P3/W1UserBytesA.lean +++ b/proofs/Fl4ProofsA64/P3/W1UserBytesA.lean @@ -129,7 +129,7 @@ theorem SpecSameA_withUmA (Z : XSetsA) (m : Fl4SpecA64.McState) (σ : Fl4SpecA64 domT := rfl asid := rfl vcur := rfl - domk := ⟨rfl, rfl, rfl, rfl⟩ + domk := DomKeepA.ofKey rfl kh _ _ := rfl ext _ _ h _ := h cdt := rfl