diff --git a/DESIGN.md b/DESIGN.md index 8337624bc..b2edeb962 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -423,7 +423,7 @@ The proof is staged so each level is useful by itself and later levels build on - Write footprints and frames for the native operations used by P3: cap-slot writes, installs, delete and finalisation, and VSpace operations. The native thread-finalisation leaf requires an unbound VCPU link. None of them breaks the invariant, and finalisation writes no cap slot. - The two conditions seL4's C code relies on without checking are P1 invariants, kept by every kernel entry: the current thread has an SC when `switch_sched_context` runs (`BoundInv.resume`, l4v `active_sc_tcb_at`), and a thread blocked on reply has a reply object (`ReplyInv0.reply`). - Typed-heap layout, object alignment and non-overlap appear as hypotheses (the sets P1 is parameterised by). CDT and untyped invariants are proved in P3 (`MdbOK`), not yet as P1 invariants. - - AArch64 (`proofs/Fl4ProofsA64/P1`, in progress): one capability invocation at a time, from P1's syscall-level bundle `SysL` (with `SymL`, the deletion input `DelIn` and the decode's placement facts). `syscall.decode_invocation.armQHAt` (`MdbArmQHD`) proves that every arm of `DecArmQH` ends in `ArmQIAt` (`SysL`, `SymL` and `BlkOK` at the result, plus the cap-only carries, including the page-table cap placement `PtCap`) and keeps the ASID table or zeroes an entry: CNode and deletion arms, TCB SetSchedParams / Suspend / ReadRegisters, IRQ control, Notification and Endpoint send, every VCPU invocation, and the VSpace arms (Stage-1 and `HighVSpace` Page / PageTable Map and Unmap, TestAndClearAccessed, the flushes, GetAddress, and every Stage-2 (EPT) operation). The step theorem is `syscall.decode_invocation.s1aStepR2K` (`S1aStepR2K`): on every arm of `DecArmS1aH` (`DecArmQH` plus Untyped Retype, ASIDPool Assign and ASIDControl MakePool) it takes, at entry, `S1aR2` (the VSpace record over the tables reachable from the ASID table: lookup, walks, root agreement, the Stage-1 and Stage-2 typings narrowed to reachable tables, exact path backing, footprint and placement), `S1aKtUt` (the kernel TTBR1 tables outside every Untyped) and `S1aHiK` (the levels of the kernel tables `Kt` and of the `HighVSpace` headers' copied descriptors, at the levels `KLv` of the platform contract `KTab`), and returns all three at the end, with `S1aStep`'s columns (`SysL`, `SymL`, the arm and cap columns, `PtCap`, `PtHG`, `HiCap511`, …; `S1aStepR2K.toR2` is `s1aStepR2`'s post). The boot witnesses give the entry (`w0_s1aStepEntryK`, `w1K_s1aStepEntryK`). Full typing of every live table is false on reachable states: `delete_asid_pool` leaves a mapped `HighVSpace` root whose private table still names a page table that can then be deleted and its memory retyped. So the deletion typing is the reachable one (`HiDelTyR`, a projection of `S1aR2`), and the tables an ASIDPool Assign makes reachable are typed by relabelling `S1aR2`'s levels on unreachable tables (`S1aR2.relabel`). Named premises: [P] `P0.ArchTotal`, `MaxSpi`, `ArchPlat` (the IPA width), `KTab`, `A64FrameMasks`, and at boot `BootCanon` (the boot objects lie in the kernel window). Covered arms of `DecArmS1aH`: Null and Zombie caps, Endpoint and Notification sends, Domain, Untyped, IrqControl, IRQ handler Ack / Clear / Set, CNode Copy / Mint / Move / Mutate / Rotate / Revoke / Delete, the TCB labels SetSpace, SetHighVSpace, SetIPCBuffer, Configure, SetEPTRoot, SetTimeoutEndpoint, SetSchedParams, SetPriority, SetMCPriority, Suspend, ReadRegisters, SetTLSBase, SetPACKeys, SetFlags, ReadFPU and UnbindNotification, SchedContext Unbind / UnbindObject / Consumed, every VCPU label, every Stage-2 (`Ept`) invocation, Frame Map / Unmap / GetAddress / TestAndClearAccessed and the four cache operations, PageTable Map / Unmap, the `Pml4`, `PageDirectory` and `Pdpt` invocations, ASIDPool Assign and ASIDControl MakePool. The sibling `syscall.decode_invocation.s1aStepR2All` (`S1aCAll`, same hypotheses and post) covers `DecArmS1aAll` = `DecArmS1aH` plus `DecArmS1aC`: the rejected invocations (direct `HighVSpace`, the unknown CNode / IRQ-handler / Frame / PageTable / ASID / VCPU labels, `IoPortControl` and `TdxControl` under `lbl < 2^52`, `IoPort` by `SysL.ci`), the unknown TCB and SchedContext labels (a stall only), TCB WriteFPU, SetTimer, BindNotification, Resume, WriteRegisters and CopyRegisters, CNode CancelBadgedSends, SchedContext Bind and YieldTo, SchedControl ConfigureFlags and the Reply cap. Each new arm but Reply exports `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ OSKeep` and is closed by `S1aStepR2K.ofKeep'`; `migrate_tcb`'s debug-list and `OWNER_CPU` writes (SchedContext Bind, ConfigureFlags) go through the Suspend footprint `SusW` (`DMR`, `ArmQIAt.ofSusW`). ConfigureFlags (`S1aCSchedCtlD`) takes two case facts, [J] cap well-formedness for a future cap-typing column: the SchedControl cap's core is a core (`cpu ∈ Cs`) and an extra SchedContext cap carries its object's size (`sz.val = H.scBits p`); neither follows from `SlotTy` / `CapTy`. The Reply arm (`S1aCReplyA`) exports `XferSlots2` (the reply's transfer, then the timeout fault IPC's) instead of `OSKeep` and is closed by `S1aStepR2K.ofXfer2`; the timeout IPC's placement after the first transfer comes from `SlotTy.ofXfer` (`S1aCXferTy`: a derived copy is the source cap, `Null`, `Domain` or a frame cap, the source keeps its cap or turns full). ConfigureSingleStepping and Set / Get / UnsetBreakpoint share SetEPTRoot's label `U64::MAX` and decode as it. Not covered on AArch64: Frame DeriveSubframe, by ruling: `FrameOK` requires every frame object to be the exact size of its cap (`FrObj`), which a 4 KiB subframe beside its 2 MiB source violates (MdbVsGaQ's `SysL.sub_false`); generalising `FrObj` to containment is a backlog item with its own review. Boot (`S1aCBootSym`, `S1aBootDel0`, `S1aBootDel1`): `boot_symL`, `w1_symL` and `w1K_symL` give `SymL` at w0, w1 and the kernel-table extension; `w0_delIn` / `w1_delIn` give `DelIn` from [P] `BootCanon` (non-vacuous: `bootCanon_ex` exhibits `BootLay1 ∧ BootCanon` at `kb = PPTR_BASE`), so `w1K_bundleU` is the boot bundle with no further input. Non-decode steps: each kernel function has its own theorem from the same per-state inputs to `S1aStepR2K`: `update_timestamp`, `commit_time`, `postpone`, `end_timeslice`, `charge_budget` (`S1aCTime`, `S1aCBudget`), `check_budget` / `check_budget_restart` (`.rpw` to the Reply-walk post `RpPost`, `.s1a` by `S1aStepR2K.ofRpPost`; `S1aCBudget`, `S1aCYield`), `schedule`, `activate_thread`, `vcpu::check` and `syscall::finish` (`S1aCSched`, `S1aCFinish`), `handle_fault` / `handle_timeout` (`S1aCFault`), `handle_yield` and `mcs_preemption_point` (`S1aCYield`), and `handle_recv` (`S1aCRecv`: `receive_ipc` with `take_reply`, the wait, `receive_from_sender` and `complete_signal`; `receive_signal`; the cap faults; a looked-up cap is a typed `OS` slot's cap, `cspace.lookup_cap.os`; the notification states are the existing [J] of `recvOK`), and the interrupt side (`S1aCIrq`): `handle_interrupt` (the IRQ slot's notification typed and named by its `OS` slot), `vcpu::complete_run`, `handle_vgic_maintenance` and `handle_vppi_event` (the `VPPI_MASKED` word as a VCPU-word step); `reply_error` and `msg.reply_success_empty` (`S1aCReplyErr`: registers and IPC-buffer words over the normal transfer's carry). The entry wrappers (`budget_ok` / `update_timestamp` / `check_budget`, a kernel function, `finish`; the fault, interrupt, VGIC, vPPI and VCPU-run entries, `set_tls_base_self`, the debug syscalls) are not composed on this line: by ruling they are composed at entry level, from the per-function theorems, whose inputs are stated at each function's own start state. The entry facts after a decode arm (`S1aCEnt`): `syscall.decode_invocation.s1aStepEntAll` gives, beside `s1aStepR2All`'s post, `S1aStepEnt` at the decode's heap and slot set (`SysL`, `HeapOK`, `BXI`, `OSOK`, `UserOK` of the entry's user words, `VsTy` of the reachable tables via `VsTyR.toVsTy`, the state block's width), the fields of P2's `EntryInvA` and P3's `SysInvA`, on the arms that keep the heap (`DecArmS1aEnt`). Untyped Retype and ASIDControl MakePool are not covered: `UserOK` leaves the user words an arbitrary set disjoint from the heap objects, with nothing tying them to frame caps, so it does not follow over the grown heap. The non-decode steps' per-state facts are the queue-level ones (`CurOK`, the current thread's SC and blocking facts, [J] `RunVcpuInv`, on the receive side [J] `nvm` and the notification states of `recvOK`); `schedule` is walked with a bundle `SW` (`RpW` with every slot kept and the VCPU words kept, `VKeep`), each step a `DMD` step or a queue step writing low state-block words. Boundary: the decode theorems (`s1aStepR2All`, `s1aStepEntAll`) are about one `decode_invocation` of a `DecArmS1aAll` arm, not `kernel_entry`, and they still take entry-layer inputs their posts do not return (`DelIn`, `DecPre`, `SysPlace`, the IRQ and slot-coverage facts `hIq` / `hSC`, the thread facts `mcp`, `cs`, `fh`, and the SchedControl case fact `hScC`). The earlier tops `s1aStepH` / `s1aStepPt` / `s1aStepR2` remain, with their per-step inputs. + - AArch64 (`proofs/Fl4ProofsA64/P1`, in progress): one capability invocation at a time, from P1's syscall-level bundle `SysL` (with `SymL`, the deletion input `DelIn` and the decode's placement facts). `syscall.decode_invocation.armQHAt` (`MdbArmQHD`) proves that every arm of `DecArmQH` ends in `ArmQIAt` (`SysL`, `SymL` and `BlkOK` at the result, plus the cap-only carries, including the page-table cap placement `PtCap`) and keeps the ASID table or zeroes an entry: CNode and deletion arms, TCB SetSchedParams / Suspend / ReadRegisters, IRQ control, Notification and Endpoint send, every VCPU invocation, and the VSpace arms (Stage-1 and `HighVSpace` Page / PageTable Map and Unmap, TestAndClearAccessed, the flushes, GetAddress, and every Stage-2 (EPT) operation). The step theorem is `syscall.decode_invocation.s1aStepR2K` (`S1aStepR2K`): on every arm of `DecArmS1aH` (`DecArmQH` plus Untyped Retype, ASIDPool Assign and ASIDControl MakePool) it takes, at entry, `S1aR2` (the VSpace record over the tables reachable from the ASID table: lookup, walks, root agreement, the Stage-1 and Stage-2 typings narrowed to reachable tables, exact path backing, footprint and placement), `S1aKtUt` (the kernel TTBR1 tables outside every Untyped) and `S1aHiK` (the levels of the kernel tables `Kt` and of the `HighVSpace` headers' copied descriptors, at the levels `KLv` of the platform contract `KTab`), and returns all three at the end, with `S1aStep`'s columns (`SysL`, `SymL`, the arm and cap columns, `PtCap`, `PtHG`, `HiCap511`, …; `S1aStepR2K.toR2` is `s1aStepR2`'s post). The boot witnesses give the entry (`w0_s1aStepEntryK`, `w1K_s1aStepEntryK`). Full typing of every live table is false on reachable states: `delete_asid_pool` leaves a mapped `HighVSpace` root whose private table still names a page table that can then be deleted and its memory retyped. So the deletion typing is the reachable one (`HiDelTyR`, a projection of `S1aR2`), and the tables an ASIDPool Assign makes reachable are typed by relabelling `S1aR2`'s levels on unreachable tables (`S1aR2.relabel`). Named premises: [P] `P0.ArchTotal`, `MaxSpi`, `ArchPlat` (the IPA width), `KTab`, `A64FrameMasks`, and at boot `BootCanon` (the boot objects lie in the kernel window). Covered arms of `DecArmS1aH`: Null and Zombie caps, Endpoint and Notification sends, Domain, Untyped, IrqControl, IRQ handler Ack / Clear / Set, CNode Copy / Mint / Move / Mutate / Rotate / Revoke / Delete, the TCB labels SetSpace, SetHighVSpace, SetIPCBuffer, Configure, SetEPTRoot, SetTimeoutEndpoint, SetSchedParams, SetPriority, SetMCPriority, Suspend, ReadRegisters, SetTLSBase, SetPACKeys, SetFlags, ReadFPU and UnbindNotification, SchedContext Unbind / UnbindObject / Consumed, every VCPU label, every Stage-2 (`Ept`) invocation, Frame Map / Unmap / GetAddress / TestAndClearAccessed and the four cache operations, PageTable Map / Unmap, the `Pml4`, `PageDirectory` and `Pdpt` invocations, ASIDPool Assign and ASIDControl MakePool. The sibling `syscall.decode_invocation.s1aStepR2All` (`S1aCAll`, same hypotheses and post) covers `DecArmS1aAll` = `DecArmS1aH` plus `DecArmS1aC`: the rejected invocations (direct `HighVSpace`, the unknown CNode / IRQ-handler / Frame / PageTable / ASID / VCPU labels, `IoPortControl` and `TdxControl` under `lbl < 2^52`, `IoPort` by `SysL.ci`), the unknown TCB and SchedContext labels (a stall only), TCB WriteFPU, SetTimer, BindNotification, Resume, WriteRegisters and CopyRegisters, CNode CancelBadgedSends, SchedContext Bind and YieldTo, SchedControl ConfigureFlags and the Reply cap. Each new arm but Reply exports `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ OSKeep` and is closed by `S1aStepR2K.ofKeep'`; `migrate_tcb`'s debug-list and `OWNER_CPU` writes (SchedContext Bind, ConfigureFlags) go through the Suspend footprint `SusW` (`DMR`, `ArmQIAt.ofSusW`). ConfigureFlags (`S1aCSchedCtlD`) takes two case facts, [J] cap well-formedness for a future cap-typing column: the SchedControl cap's core is a core (`cpu ∈ Cs`) and an extra SchedContext cap carries its object's size (`sz.val = H.scBits p`); neither follows from `SlotTy` / `CapTy`. The Reply arm (`S1aCReplyA`) exports `XferSlots2` (the reply's transfer, then the timeout fault IPC's) instead of `OSKeep` and is closed by `S1aStepR2K.ofXfer2`; the timeout IPC's placement after the first transfer comes from `SlotTy.ofXfer` (`S1aCXferTy`: a derived copy is the source cap, `Null`, `Domain` or a frame cap, the source keeps its cap or turns full). ConfigureSingleStepping and Set / Get / UnsetBreakpoint share SetEPTRoot's label `U64::MAX` and decode as it. Frame DeriveSubframe was not covered at this stage, by ruling: `FrameOK` then required every frame object to be the exact size of its cap (`FrObj`), which a 4 KiB subframe beside its 2 MiB source violates (MdbVsGaQ's `SysL.sub_false`). Stage 5 (`e0`, `lam`, `VsScopeA.frameDeriveSub`, see §9 P5 below) generalised `FrObj` to containment and covers the arm. Boot (`S1aCBootSym`, `S1aBootDel0`, `S1aBootDel1`): `boot_symL`, `w1_symL` and `w1K_symL` give `SymL` at w0, w1 and the kernel-table extension; `w0_delIn` / `w1_delIn` give `DelIn` from [P] `BootCanon` (non-vacuous: `bootCanon_ex` exhibits `BootLay1 ∧ BootCanon` at `kb = PPTR_BASE`), so `w1K_bundleU` is the boot bundle with no further input. Non-decode steps: each kernel function has its own theorem from the same per-state inputs to `S1aStepR2K`: `update_timestamp`, `commit_time`, `postpone`, `end_timeslice`, `charge_budget` (`S1aCTime`, `S1aCBudget`), `check_budget` / `check_budget_restart` (`.rpw` to the Reply-walk post `RpPost`, `.s1a` by `S1aStepR2K.ofRpPost`; `S1aCBudget`, `S1aCYield`), `schedule`, `activate_thread`, `vcpu::check` and `syscall::finish` (`S1aCSched`, `S1aCFinish`), `handle_fault` / `handle_timeout` (`S1aCFault`), `handle_yield` and `mcs_preemption_point` (`S1aCYield`), and `handle_recv` (`S1aCRecv`: `receive_ipc` with `take_reply`, the wait, `receive_from_sender` and `complete_signal`; `receive_signal`; the cap faults; a looked-up cap is a typed `OS` slot's cap, `cspace.lookup_cap.os`; the notification states are the existing [J] of `recvOK`), and the interrupt side (`S1aCIrq`): `handle_interrupt` (the IRQ slot's notification typed and named by its `OS` slot), `vcpu::complete_run`, `handle_vgic_maintenance` and `handle_vppi_event` (the `VPPI_MASKED` word as a VCPU-word step); `reply_error` and `msg.reply_success_empty` (`S1aCReplyErr`: registers and IPC-buffer words over the normal transfer's carry). The entry wrappers (`budget_ok` / `update_timestamp` / `check_budget`, a kernel function, `finish`; the fault, interrupt, VGIC, vPPI and VCPU-run entries, `set_tls_base_self`, the debug syscalls) are not composed on this line: by ruling they are composed at entry level, from the per-function theorems, whose inputs are stated at each function's own start state. The entry facts after a decode arm (`S1aCEnt`): `syscall.decode_invocation.s1aStepEntAll` gives, beside `s1aStepR2All`'s post, `S1aStepEnt` at the decode's heap and slot set (`SysL`, `HeapOK`, `BXI`, `OSOK`, `UserOK` of the entry's user words, `VsTy` of the reachable tables via `VsTyR.toVsTy`, the state block's width), the fields of P2's `EntryInvA` and P3's `SysInvA`, on the arms that keep the heap (`DecArmS1aEnt`). Untyped Retype and ASIDControl MakePool are not covered: `UserOK` leaves the user words an arbitrary set disjoint from the heap objects, with nothing tying them to frame caps, so it does not follow over the grown heap. The non-decode steps' per-state facts are the queue-level ones (`CurOK`, the current thread's SC and blocking facts, [J] `RunVcpuInv`, on the receive side [J] `nvm` and the notification states of `recvOK`); `schedule` is walked with a bundle `SW` (`RpW` with every slot kept and the VCPU words kept, `VKeep`), each step a `DMD` step or a queue step writing low state-block words. Boundary: the decode theorems (`s1aStepR2All`, `s1aStepEntAll`) are about one `decode_invocation` of a `DecArmS1aAll` arm, not `kernel_entry`, and they still take entry-layer inputs their posts do not return (`DelIn`, `DecPre`, `SysPlace`, the IRQ and slot-coverage facts `hIq` / `hSC`, the thread facts `mcp`, `cs`, `fh`, and the SchedControl case fact `hScC`). The earlier tops `s1aStepH` / `s1aStepPt` / `s1aStepR2` remain, with their per-step inputs. - **P2**: for x86_64, not started. The transaction-soundness theorem it replaces (`proofs/Fl4Proofs/P2/Runtime.lean`, `sound` and `snapshot`) is complete, but about the transactional runtime removed on 2026-11-21 (§7); the Lean tree still builds it. - AArch64: the architecture-independent gate model (`Serial`, `SerialSafe`, `SafeCert`, and the hardware-step model `SerialHw`) is one library, `proofs/Fl4P2Base`, shared by both trees (the x86_64 `Fl4Proofs/P2` modules of the same names re-export it); the core-generic x86_64 guard and local-path modules are copied into `Fl4ProofsA64/P2` only by `xtask/scripts/port_p2_a64.py` (`--check` verifies the copies). - AArch64 serializability, first form: `serializable_fl4_localVXb` (`Fl4ProofsA64/P2/E2EFl4VXS.lean`). Every execution that starts with an empty log and no local path in progress, made of core steps (serial entries under the gate, and local paths) and hardware steps (a running guest's VCPU words, rules 7 and 8), and that ends with no local path in progress, has a log whose entries, run one after another from the initial memory, give the final memory (`RunAll`). Its local paths are each an `E2E.LocalPath` (refinement of the general path, footprint, read-once), cut and lifted to the VCPU ownership map: the VM fault, the VM ReplyRecv, `TCB_SetTimer`, the timer interrupt (including the fire case), the local syscall path, NBWait, the `ARMVCPURun` exit, the VM-timer interrupt and `arm_vm_entry_ready`. The run is under an epoch predicate, `EpochA`: the boot layout and every serial entry's result are a typed layout linked to memory on the aligned non-user words, and a local path starts in that epoch (`StartAtE`). @@ -449,17 +449,25 @@ The proof is staged so each level is useful by itself and later levels build on - 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: 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, 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: a device Untyped (`UntypedRetypeShared` is a decode `Err`); the Stage-1 / high-window shrink (ARMPageDeriveSubframe is in the scope since Stage 5 `VsScopeA.frameDeriveSub`). 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, DeriveSubframe (E0): `FrBaseApartA` (the `frBase` record field) is in containment form and carries `FrLamA`, the frame `caps_no_overlap` hierarchy (every physical cap of an `OS` slot is disjoint from a large RAM frame cap, a non-revocable frame cap, or contains it; x86 `NoOverlap.hno`), maintained by every cap-changing step through `RevFromA` (the new field of `CapsFromA`) and `FrBaseApartA.keepOS`. `hfr` (a frame cap inside a large frame is in the large frame's chain) was **removed, not derived**: it was read only by `finMA_insFrameA`, i.e. the `CarryA`/`FinInvA` half of `derive_subframe_jA`'s post, which no success path consumes (`decInv_arch_jA` keeps `Err` outcomes only), so `derive_subframe_jA` now concludes `ArchTopErrA` and `FinInvA` stays out of `JStage3A`. The success path is `JStage3A.subframesA` (`Stage3ArmSubframeA`): the `n` insertions with the J5 slot, `FrLamA` and a transitive spec-side record (`insert_subframes_j5A`, `SubQA`), then one `of_capDerivA` over the composite CNode-slot writes (`of_capDerivCnA`, the generalised tail of the Copy arm). `FrSubSiteA` is **removed, derived**: the 2 MiB alignment of a large RAM frame cap is `FrAt.al` (`HeapOK`) for the `FrAt` of the `J7` frame-object record, and its canonicality is the `EncWf` of any cap decoded from memory (`CapRt.decodeF_encWf`); no `utWin` frame clause was needed. `FrMapSiteA` (placement of a mapped frame) remains a site premise: its removal needs a RAM `Frame` window clause on `UtWinCapA` (about +250 lines touching the retype / boot window producers) and is in the backlog (Architect, 2026-12-06: it did not fit Wave 1's budget). Backlog (refactor, no proof gain): the Copy arm's tail (`capInsertGenA`) can call `of_capDerivCnA`. The `ARMPageDeriveSubframe` arm is in the Vs scope: `VsScopeA.frameDeriveSub` (`Stage3DispVsA`), its pin (`frameDeriveSub_pinA`), scope lemma (`frameDeriveSub_scopeA`), `InvSpecA` case and `JSyscallA.frameDeriveSubA` (`Stage3T3ArmSubA`: the Ok view of `derive_subframe_jA` (`ArchTopSubA`), `decodeFinSubA` over `subFin` (`S1aSubFin`), then `JStage3A.deriveSubframeA`: the caller's restart, `subframesA`). `hdo` (the destination CNode is no IRQ node: those are `cnode 0` of `th`) and the 2 MiB alignment / canonicality of the source frame are derived, not premises; `hcO` is derived from the record (`OSOK.canon`, `JStage3A.winOK`) at the scope arm, not a field of `frameDeriveSub`; likewise `ptUnmapT2Stale` derives `hTO`/`hEO` from `JStage3A.tabS1`/`tabExt`. - 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 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 `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`. The unmap of a mapped Stage-2 table whose ASID names no Stage-2 root (kind none after `delete_asid`, or `stage1`) was covered by no dispatch arm before Stage 5 (`hT2` demanded a Stage-2 kind); its core, "no reachable valid descriptor names `ptr`", is `VsUniqA.no_reach_stale` (`P3/VsUniqStaleA`, from `VsUniqA.t2`), and the `T2` shrink of the record is `VsUniqA.shrinkT2`; the arm is `VsScopeA.ptUnmapT2Stale` (`JStage3A.ptUnmapT2StaleA`, `JSyscallA.ptUnmapT2StaleA`, `Stage3ArmPtUnmStaleA`, `Stage3T3ArmStaleA`; `ptUnmap_runA` splits the `ptr ∈ Z.T2` case on the ASID's kind: none / Stage-1 take it, a Stage-2 or window root keeps `ptUnmapT2` and its [J] `PtUniqT2A`). In `ptUnmapT2A` the `T2` shrink now happens after the zero and before the cap write (`VsUniqA.shrinkT2`, `setcap_core2TA`), as `VsUniqA.out` requires. - 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 `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`. End-to-end witness: `Wit.wit_ut_nonvacuous` (`P3/A64WitUtTopA`, with `A64WitUtMsgA` / `A64WitUtScopeA`): the Send witness world with an `UntypedRetype` message (a RAM Untyped, slot 53, free index 0 and no CDT child, into one Endpoint of the root CNode), at `UtScopeA.retypeRst`: the decode is `Ok`, the arm's premises (`hdecS`, `hargs`, `hex`, `hpin`, `hCs`, `hIpa`, `hchunk`) are all discharged from the message, and `wit_top_ut` derives the conclusion. Witness-world premises: `OpaqueWA`, `hI` as for Send, and `OpaqueUtWA` (witness-world [P]: `fl4A64Virt = false`, `retypeFanOutLimit = 256`); `wit_ut_prems` (`P3/A64WitUtA`) is the arm's premise bundle. + - AArch64 P5 `prst`: the preempted record is stated at a hidden view like the entry record (`A64RelPS3 := ∃ m', McGrowA m m' ∧ A64RelPS3fx`; `A64RelPS3at` carries `m'`): only `HPreEnvA.hSend` and `hPre_ofA.hSend` move to the hidden `m'`. This is a statement generalisation of the premise side (the preempted-exit relation holds at a grown mc-state, as R1 does for `KExitA`), needed for the preempting Untyped reset (next line). + - AArch64 P3 Stage 5 `prst`: **the chunk-loop Untyped reset is in the dispatch**, preempted (`UtPreScopeA.retypeRstPre`, landing in `A64RelPS3`) and completed (`UtScopeA.retypeRstBig`, landing in `A64RelS3`; `BodyOKA` after the clock moved comes from `DelBudA` at each passed preemption point). `A64RelPS3` now hides the view the invocation left (`∃ m', McGrowA m m' ∧ A64RelPS3fx … m'`), so the timeout-send premise of the preempted exit (`HPreEnvA.hSend`) is stated `∀ m'` guarded by that record. The preemption point's VSpace-word premise ranges over `utVsPtA` and is discharged from the record (`utRst_hvpA`). Which arm applies is a case hypothesis on the `reset_untyped` run. Premises: those of the other Untyped arms, plus [P] `DelPlatA`, the entry clock and `CounterStepA` (the creation's premises are not needed on the preempted arm). Premise-level witness only (`wit_utChunk_prems`: platform facts and the untyped's size); a run witness of a used untyped, a preempted or completed chunk loop and the preempted exit does not exist yet. + - AArch64 P5 `pool`: **ARMASIDControlMakePool is in the dispatch** (`VsScopeA.asidMakePool`, `JSyscallA.asidMakePoolA` at the entry, `JStage3A.asidMakePoolA` at `syscall.decode_invocation`; `Stage3PoolTopA` assembles the whole record after the call from the field-group modules `Stage3Pool{Shape,Mem,SysEnd,Rec}A`, the shared context `PoolCtxA` and A64 P1's end facts, which `poolFinA` discharges). The Stage-4 cut is lifted and `hnoDeadTcb` is gone. **Derived from the record, not constructor fields:** `hT` (`JStage3A.offAsE`), `hYAs` (`JStage3A.yNotAsW`: the first page of a high-window root is off the ASID-table block, from `setsInH.roots` and `ptHA_not_asW`) and `hcO` (`OSOK.canon`, `JStage3A.winOK`). Premises of the arm (the constructor fields): [P] the platform facts (`ArchTotal`, `ArchPlat`, `A64FrameMasks`; `hn`: the arch's `s2_ipa_bits` is the spec's `s2IpaBits`, not derivable from `ArchPlat`, which only says the value is constant), [P] `hCs` (every core of `Z.Cs` is below `numNodes`; the record has only the converse, `coresAll`), [S] one core (`h1`, `hnN`; the same premises as the IPC, SchedContext and Domain groups, which no other VSpace arm needs), [W] the tracked-CNode facts of the destination and parent (`hdc`, `hCp`, `hCd`: a CNode cap in `OS` and a `th` CNode of the slot's length; the same shape as `CnScopeA.cnodeCopy`'s `hCs`/`hCd`; deriving them from `hlt` and the record was not attempted), and the decode-determined facts (the destination CNode radix is not `0`, `hdr`; a free table index; no CDT children; an empty destination). **Backlog:** the producer side of the pool bundles and an arm witness: the premise-level witness of the VS arms (`A64WitVs*`) does not cover `asidMakePool`. + - AArch64 P5 `e0` (FrObj containment): a non-device Frame cap no longer names an exact-size object at its base; it names a range **contained in a heap `other` object** (`FrAt H ptr bits`: `b ≤ ptr`, `ptr + 2^bits ≤ b + 2^k`, plus an offset-alignment conjunct; accessor layer `FrAt.def`/`FrAt.drop`/`FrAt.undrop` in `MdbNHO`/`MdbFrC`; `FrObj`, `FrameOK` state it per live frame cap). Reset and retype of an Untyped no longer need a frame-specific laminarity premise: the heap drop/undrop is derived from `RegionIn H lo hi` (l4v `valid_untyped`: every heap object meeting the region lies inside it), which `UtRV.rin` extracts from the live Untyped cap, so a frame inside a kept object is kept and a frame in the dropped region is off it. On the P3 side `UserFrSpecA` takes the heap, `FrThA` is `∃ b len`, and `BufPinA` gains a 1 KiB alignment conjunct; `Stage3Pool*`, `UtSbufA` and the Untyped reset chain are adapted. No new premise kind: the old exact-size-at-base fact is replaced by a derived one. Checked at the integration tip: root build, AX scan and premise linter. + - AArch64 P5 `vsinv`: **`VsUniqA` carries the uniqueness of roots and page tables** (`P3/VsUniqA`). Two new fields: `rootOnce` (`RootOnceA`: an unmapped root-kind cap of `r` (Stage-1 `Pml4`, level-zero `Ept`, `HighVSpace`) is the only root-kind cap of `r`, and `r` is installed at no ASID, so ASIDPoolAssign keeps `rootInj1/2`) and `ptOnce` (`PtOnceA`: an unmapped `PageTable` cap of `r` is the only `PageTable` cap of `r`). The step obligation `PtClosedA` is now the record `{pt, root, ptu}` (`PtCapClosedA`, `RootClosedA`, `PtUClosedA`); the setcap family takes the defaulted arguments `hrt`/`hpt`/`hptw` (the tactic defaults `root_nr`/`pt_nr` cover cap writes that are neither roots nor page tables). Producers: `VsUniqA.of_poolGrow` (`VsUniqGrowA`, MakePool), `of_assign`, `of_clearPool`/`of_clearTab`, `of_descEqA` (leaf writes), the retype/creation and drop (`UtRtVsUniqA`, `UtDropVsUniqA`), and the Stage-1 table links (`VsPtMapVsuA`, `VsHiMapVsuA`, `VsS2ArmVsuA`). These facts replace the earlier per-arm [J] case premises for the unmap arms by record invariants only where the arm needs them: `ptUnmapT2Stale` needs none (`VsUniqA.no_reach_stale`), but `ptUnmapT2` **still carries [J] `hUniq`** (`PtUniqT2A`, `Stage3ArmPtUnmT2A`), see `witvs` below. **The stale-ASID coverage hole is closed:** the unmap of a mapped Stage-2 table whose ASID names no Stage-2 root had no dispatch arm before Stage 5; it is `VsScopeA.ptUnmapT2Stale` (see `vsxb`/`vsxc` above). **Deferred (backlog):** the Stage-1 shrink together with the `PtFreshA` TIGHTEN, `vsx-P`, and `ptUnmapT2Z`. + - AArch64 P5 `lam` (E0.5a, frame `caps_no_overlap`): **`FrLamA` is in the record** as the third conjunct of `FrBaseApartA` (`FrBaseOnlyA ∧ FrIntApartA ∧ FrLamA`, `P3/CnodeFinalA`), tagged [J] as the A64 counterpart of x86 `LargeFrOK` / `NoOverlap.hno` and l4v `caps_no_overlap` for a large frame: every physical cap of an `OS` slot is disjoint from a large RAM frame cap of an `OS` slot, or is a non-revocable frame cap, or contains it. It is **maintained at every cap writer, retype, pool and boot**: the keep/map/swap/remove/derive steps (`FrLamA.keepA`, `mapA`, `swapped`, `removed`, `derivA`, `tr`; the revocable bit of the new state is traced by `RevFromA`, `revA_of_rvbA`, `moveCap_revA`), the Untyped retype (`utRt_newRngCapA`, `utRt_lamHeapA`, `utRt_revKA`, `utEnd_newRngA`), MakePool and boot. `DerivA` now tracks the frame range (`DerivA.range`, `large_range`, `same_or_sub`; `DerivA.ptr` takes `isFrA d = false`), and `UtInvA.insSub` is re-derived from `insSubGen`. `VsScopeA.frameDeriveSub` (`JSyscallA.frameDeriveSubA`) is wired in Stage 5. Under b′, `hfr` is removed (not derived), and `FrSubSiteA` is derived and removed. `FrMapSiteA` and the arm-level run witness remain backlog. `FrLamA` stays a [J] record conjunct (E0.5b in its docstring). + - AArch64 P5 `witvs`: **the VSpace arms `ptMapHi`, `ptMapS2`, `frameMapS2` and `ptUnmapT2` have a premise-level witness only** (`Wit.wit_ptMapHi_prems`, `wit_ptMapS2_prems`, `wit_frameMapS2_prems`, `wit_ptUnmapT2_prems`, `P3/A64WitVsArmsA`). At a concrete state (`w1` plus a Stage-2 root, a Stage-2 table, a high window, an unmapped page table, a 2 MiB frame and their five caps; `P3/A64WitVs*`) and the model arch `AR1`, per arm the caps, the extra root cap, the root lookup, the message registers, the unmapped-table / frame facts and FL4's map run (for `ptUnmapT2`: the finality run, the spec root kind, `hno`) hold jointly; `VsRelA` and `ExtVsRelA` hold there with non-empty `X`, `Y`, `T2`, as do the VCPU / Stage-2 / high-window cores, `cv` and `pml` (at the state without the message). **Not shown:** the whole record (`JStage3A` / `JSyscallA`) is not proved satisfiable with non-empty Stage-2 roots, high windows or Stage-2 tables; hence not `TabOffA` / `ExtTabOffA`, `DecPre`, `DecPinA`, the success of the spec decode, nor an application of the `VsScopeA` constructors; and not `ptUnmapT2`'s [J] `hUniq`. There is no end-to-end `*_nonvacuous` theorem for these arms. Premises of the witness: `BootLayA` / `BootKsA` / `BootLay1` and [P] `OpaqueWA` (`ipaBits`). Backlog: the full VS-world witness, measured projection ≈ 6,600 changed lines (4,900–8,300). `witsub` (`P3/A64WitSubA`): the decode site of `ARMPageDeriveSubframe` at the same witness world (a 2 MiB `Large` frame cap in root CNode slot `57 + nc`, root CNode as extra cap, `first = 60 + nc`, `count = 2`, mask `3`): the cap readings, the message words, `subframe_dest`, the whole `vspace::derive_subframe` decode up to `insert_subframes`, and the pure inputs of `JStage3A.subframesA` (`wit_sub_ins`) hold. **Not shown:** `SubInv` (needs `SysL`/`SymL`/`BlkOK` at `w1vS`) and the arm-level witness of `VsScopeA.frameDeriveSub`; both are backlog. - 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. diff --git a/README.md b/README.md index eecfed4ea..bbd3e5852 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 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, +(`lake build Fl4ProofsA64`). AArch64 P3 Stages 3–5 prove the syscall +kernel-entry top (`kernelEntry_recGA`) over the CNode, VSpace (incl. the Stage-2 and high-window maps, the T2 unmap shrink and the stale-ASID unmap, ASIDControl MakePool and DeriveSubframe), +SchedContext, TCB (installs, SetSpace, Configure, SetSchedParams, SetTimer, Read-, Write- and CopyRegisters), IPC, IRQ, Domain, VCPU and Untyped (Retype, TCB creation and reset, preempted or not) 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, +a device Untyped, 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 +the premises of every top are shown jointly satisfiable (`wit_send_nonvacuous`, `wit_ut_nonvacuous` (an Untyped Retype into the root CNode), `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) (DESIGN.md §9); the Stage-5 arms (MakePool, DeriveSubframe, the Stage-2 / high-window VSpace arms) have premise-level witnesses at most, not end-to-end ones (the Untyped chunk-loop resets are premise-level only; `ptUnmapT2Stale` has no arm witness). 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 7892d5c2d..081a22517 100644 --- a/proofs/Fl4ProofsA64.lean +++ b/proofs/Fl4ProofsA64.lean @@ -251,6 +251,7 @@ import Fl4ProofsA64.P1.MdbTreeF import Fl4ProofsA64.P1.MdbTreeR import Fl4ProofsA64.P1.MdbTreeL import Fl4ProofsA64.P1.MdbTreeD +import Fl4ProofsA64.P1.MdbRoot import Fl4ProofsA64.P1.MdbTreeS import Fl4ProofsA64.P1.MdbTreeK import Fl4ProofsA64.P1.MdbTreeU @@ -909,6 +910,18 @@ import Fl4ProofsA64.P3.InsertA import Fl4ProofsA64.P3.JEntW0A import Fl4ProofsA64.P3.JBootW1A import Fl4ProofsA64.P3.JBootW1SA +import Fl4ProofsA64.P3.VsUniqShrinkA +import Fl4ProofsA64.P3.VsUniqLinkA +import Fl4ProofsA64.P3.VsUniqGrowA +import Fl4ProofsA64.P3.VsWalkHiA +import Fl4ProofsA64.P3.VsWalkS2A +import Fl4ProofsA64.P3.VsUniqLinkS2A +import Fl4ProofsA64.P3.VsS2MapVsuA +import Fl4ProofsA64.P3.VsS2ArmVsuA +import Fl4ProofsA64.P3.VsHiMapVsuA +import Fl4ProofsA64.P3.VsWalkSlotA +import Fl4ProofsA64.P3.VsPtMapVsuA +import Fl4ProofsA64.P3.VsW1A import Fl4ProofsA64.P3.JEntW1A import Fl4ProofsA64.P3.InsDisA import Fl4ProofsA64.P3.LookupA @@ -1194,6 +1207,8 @@ import Fl4ProofsA64.P3.VsMakePoolA import Fl4ProofsA64.P3.PtCapBootA import Fl4ProofsA64.P3.ExtVsPerfA import Fl4ProofsA64.P3.ExtVsDefA +import Fl4ProofsA64.P3.VsUClosedA +import Fl4ProofsA64.P3.VsUniqA import Fl4ProofsA64.P3.ScRelA import Fl4ProofsA64.P3.ScSpecA import Fl4ProofsA64.P3.ScRefillA @@ -1736,6 +1751,17 @@ import Fl4ProofsA64.P1.S1aCReplyTl import Fl4ProofsA64.P1.S1aCReplyM import Fl4ProofsA64.P1.S1aCReplyA import Fl4ProofsA64.P1.S1aCAll +import Fl4ProofsA64.P1.S1aSubTree +import Fl4ProofsA64.P1.S1aSubIns +import Fl4ProofsA64.P1.S1aSubDest +import Fl4ProofsA64.P1.S1aSubRun +import Fl4ProofsA64.P1.S1aSubLoop +import Fl4ProofsA64.P1.S1aSubGeo +import Fl4ProofsA64.P1.S1aSubArm +import Fl4ProofsA64.P1.S1aSubTop +import Fl4ProofsA64.P1.S1aSubFin +import Fl4ProofsA64.P1.MdbSubFrA +import Fl4ProofsA64.P1.MdbInvSubA import Fl4ProofsA64.P1.S1aBootDel0 import Fl4ProofsA64.P1.S1aBootDel1 import Fl4ProofsA64.P1.S1aCStepD @@ -1760,6 +1786,12 @@ import Fl4ProofsA64.P3.Stage3ArmCnMoveA import Fl4ProofsA64.P3.Stage3ArmCnRotA import Fl4ProofsA64.P3.Stage3ArmCnSwapA import Fl4ProofsA64.P3.Stage3CnInsA +import Fl4ProofsA64.P3.Stage3CnInsSubA +import Fl4ProofsA64.P3.FrSubframeJ5A +import Fl4ProofsA64.P3.CapInsSpecQA +import Fl4ProofsA64.P3.Stage3CapDerivCnA +import Fl4ProofsA64.P3.Stage3ArmSubframeA +import Fl4ProofsA64.P3.Stage3T3ArmSubA import Fl4ProofsA64.P3.Stage3ArmCnCopyA import Fl4ProofsA64.P3.Stage3Rec5A import Fl4ProofsA64.P3.Stage3SchedValidA @@ -2018,6 +2050,14 @@ import Fl4ProofsA64.P3.UtRec6KeepA import Fl4ProofsA64.P3.UtVcInitA import Fl4ProofsA64.P3.UtApRec6A import Fl4ProofsA64.P3.UtVcTrA +import Fl4ProofsA64.P3.UtPreCarryA +import Fl4ProofsA64.P3.UtPreDecA +import Fl4ProofsA64.P3.UtPreExitA +import Fl4ProofsA64.P3.Stage3UtPreArmA +import Fl4ProofsA64.P3.Stage3DispUtPreA +import Fl4ProofsA64.P3.UtBigCarryA +import Fl4ProofsA64.P3.UtBigDecA +import Fl4ProofsA64.P3.Stage3UtBigArmA import Fl4ProofsA64.P3.Stage3IpcGlueA import Fl4ProofsA64.P3.Stage3SignalIdleA import Fl4ProofsA64.P3.Stage3TcbWordsA @@ -2384,11 +2424,16 @@ import Fl4ProofsA64.P3.A64Wit2bNatA import Fl4ProofsA64.P3.A64Wit2bBodyA import Fl4ProofsA64.P3.A64Wit2PlatA import Fl4ProofsA64.P3.A64WitW1A +import Fl4ProofsA64.P3.A64WitMsgA import Fl4ProofsA64.P3.A64WitStA import Fl4ProofsA64.P3.A64WitJA import Fl4ProofsA64.P3.A64WitRecA import Fl4ProofsA64.P3.A64WitSyscA +import Fl4ProofsA64.P3.A64WitReadA import Fl4ProofsA64.P3.A64WitCopyA +import Fl4ProofsA64.P3.A64WitUtMsgA +import Fl4ProofsA64.P3.A64WitUtScopeA +import Fl4ProofsA64.P3.A64WitUtTopA import Fl4ProofsA64.P3.A64WitTopA import Fl4ProofsA64.P3.A64Wit2BudgetA import Fl4ProofsA64.P3.A64Wit2EntryA @@ -2412,6 +2457,13 @@ import Fl4ProofsA64.P3.A64ArchSwH import Fl4ProofsA64.P3.Stage3KEntryIrqBodyA import Fl4ProofsA64.P3.Stage3KEntryIrqTopA import Fl4ProofsA64.P3.A64WitIrqA +import Fl4ProofsA64.P3.A64WitVsLayA +import Fl4ProofsA64.P3.A64WitVsArchA +import Fl4ProofsA64.P3.A64WitVsStA +import Fl4ProofsA64.P3.A64WitVsExtA +import Fl4ProofsA64.P3.A64WitVsPremA +import Fl4ProofsA64.P3.A64WitVsArmsA +import Fl4ProofsA64.P3.A64WitSubA import Fl4ProofsA64.P3.Stage3TcbReadRegsA import Fl4ProofsA64.P3.Stage3InvSpecTcbRegsA import Fl4ProofsA64.P3.TcbInvokeReadCallFineA @@ -2420,3 +2472,20 @@ import Fl4ProofsA64.P3.Stage3TcbReadCallA import Fl4ProofsA64.P3.Stage3SuspOffQA import Fl4ProofsA64.P3.Stage3TcbReadRegsSuspA import Fl4ProofsA64.P3.Stage3TcbReadCallSuspA +import Fl4ProofsA64.P3.Stage3PoolCapsA +import Fl4ProofsA64.P3.Stage3PoolHeapA +import Fl4ProofsA64.P3.Stage3PoolSysA +import Fl4ProofsA64.P3.Stage3PoolSpecA +import Fl4ProofsA64.P3.Stage3PoolIpcA +import Fl4ProofsA64.P3.Stage3PoolCoreA +import Fl4ProofsA64.P3.Stage3PoolShapeA +import Fl4ProofsA64.P3.Stage3PoolMemA +import Fl4ProofsA64.P3.Stage3PoolJ7A +import Fl4ProofsA64.P3.Stage3PoolSysEndA +import Fl4ProofsA64.P3.Stage3PoolRecA +import Fl4ProofsA64.P3.Stage3PoolTopA +import Fl4ProofsA64.P3.Stage3ArmPoolA +import Fl4ProofsA64.P3.Stage3PoolEndA +import Fl4ProofsA64.P3.Stage3PoolFinA +import Fl4ProofsA64.P3.Stage3PoolJ5A +import Fl4ProofsA64.P3.Stage3T3PoolA diff --git a/proofs/Fl4ProofsA64/P1/BootW1Items.lean b/proofs/Fl4ProofsA64/P1/BootW1Items.lean index 7d20cb5bf..1901a5c58 100644 --- a/proofs/Fl4ProofsA64/P1/BootW1Items.lean +++ b/proofs/Fl4ProofsA64/P1/BootW1Items.lean @@ -296,11 +296,17 @@ section caps variable (P : BootLay1 kb ib nc) include P +/-- **The exact objects of the `w1` frames** (boot: every frame is exactly its heap object). -/ +theorem w1_frameObj {y : U64} (hy : y ∈ OS1) {ptr : U64} {size : capability.FrameSize} {rights : U64} {x1 x2 : Bool} {x3 x4 : U64} + (hc : capA bst S1 y = .Frame ptr size rights false x1 x2 x3 x4) {bits : U64} (hb : size.bits = ok bits) : + H1 ptr = some (.other bits.val) := by + obtain ⟨rfl, hF⟩ := (w1_rootCap P hy).fr _ _ _ _ _ _ _ _ hc + rw [small_bits hb]; exact frPg_obj hF + /-- **`FrameOK` at `w1`.** -/ theorem w1_frameOK : FrameOK bst H1 OS1 S1 := by intro y hy ptr size rights x1 x2 x3 x4 hc bits hb - obtain ⟨rfl, hF⟩ := (w1_rootCap P hy).fr _ _ _ _ _ _ _ _ hc - rw [small_bits hb]; exact frPg_obj hF + exact FrAt.ofObj (w1_frameObj P hy hc hb) /-- **`UserOffFr` at `w1`**: the frame words are off the RAM untyped. -/ theorem w1_userOffFr : UserOffFr bst OS1 S1 := by diff --git a/proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean b/proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean index 4654523ad..e3b4f7a0d 100644 --- a/proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean @@ -102,7 +102,7 @@ theorem RunBuf.frUb {Ub' : Set U64} {s : S} {y : U64} (hH : HeapOK H) (hF : Fram subst hdev have hcap0 : capA st s (sbWordA y) = .Frame ptr size rights false x1 x2 x3 x4 := okinj ((capA_eq s _).symm.trans hcap) - have hp : H ptr = some (.other bits.val) := hF _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits + have hp : FrAt H ptr bits := hF _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits intro i hi obtain ⟨hal, hin⟩ := frame_off_words hH hp hbits hsz h63 hlt hge hi exact ⟨hU i hi, hf _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits _ hal hin.1 hin.2⟩ diff --git a/proofs/Fl4ProofsA64/P1/MdbDropR.lean b/proofs/Fl4ProofsA64/P1/MdbDropR.lean index e1d4c1969..2489e9691 100644 --- a/proofs/Fl4ProofsA64/P1/MdbDropR.lean +++ b/proofs/Fl4ProofsA64/P1/MdbDropR.lean @@ -142,7 +142,7 @@ theorem SysL.dropR {s s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {x p s · rcases hO.disj y hy.1 x P.src hyx with g | g <;> omega have hf : RstF st (OffR p.val (p.val + 2 ^ sb.val) OS) x s s' := ⟨w.1, w.2.1, kc, fun y hy => ⟨lk y hy _ (Or.inl rfl), lk y hy _ (Or.inr rfl)⟩⟩ - obtain ⟨h1, h2, h3⟩ := RstF.bn hO B.sys.stz B.sys.fr B.sys.cz P.src hcx hnd hf hcx' hi hUZ + obtain ⟨h1, h2, h3⟩ := RstF.bn hO B.sys.stz B.sys.fr B.sys.cz P.src hcx hnd (R.ur.rin R.src R.cap) hf hcx' hi hUZ (not_islN_region q hnode) have hR1 : UtRV st (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) (OffR p.val (p.val + 2 ^ sb.val) OS) s' := by refine UtRV.mono (H := H) (fun y hy => ?_) fun q k hq => (Heap.drop_eq_some.1 hq).2 diff --git a/proofs/Fl4ProofsA64/P1/MdbFpuL.lean b/proofs/Fl4ProofsA64/P1/MdbFpuL.lean index a9498902e..d1e60023b 100644 --- a/proofs/Fl4ProofsA64/P1/MdbFpuL.lean +++ b/proofs/Fl4ProofsA64/P1/MdbFpuL.lean @@ -79,14 +79,13 @@ theorem frame_word (hH : HeapOK H) {ptr : U64} {z : Nat} (hp : H ptr = some (.ot /-- **The 65 words from `ptr + offset` of a frame object** (module docstring): words of `Ω \ Sg` inside `[ptr, ptr + 2^bits)`. -/ -theorem frame_words (hH : HeapOK H) {ptr offset bits : U64} (hp : H ptr = some (.other bits.val)) +theorem frame_words (hH : HeapOK H) {ptr offset bits : U64} (hp : FrAt H ptr bits) (h12 : 12 ≤ bits.val) (ho : offset.val % 64 = 0) (hob : offset.val + 520 ≤ 2 ^ bits.val) : Aligned (wa ptr offset) ∧ (wa ptr offset).val + 8 * (65#u64 : U64).val ≤ 2 ^ 64 ∧ ∀ b, CWW (wa ptr offset) 65#u64 b → (ptr.val ≤ b.val ∧ b.val < ptr.val + 2 ^ bits.val) ∧ b ∈ H.omega ∧ b ∉ H.frame := by - have hf := hH.fits ptr _ hp - have hal := hH.align ptr _ hp - simp only [HKind.bits] at hf hal + have hf := hp.fits hH + have hal := hp.al hH have h8 : 8 ∣ 2 ^ bits.val := by have : 2 ^ bits.val = 2 ^ 3 * 2 ^ (bits.val - 3) := by rw [← Nat.pow_add]; congr 1; omega rw [this]; exact Dvd.dvd.mul_right (by norm_num) _ @@ -98,12 +97,12 @@ theorem frame_words (hH : HeapOK H) {ptr offset bits : U64} (hp : H ptr = some ( rw [h65] at hk rw [hfv] at e have hin : ptr.val ≤ b.val ∧ b.val < ptr.val + 2 ^ bits.val := by omega - exact ⟨hin, frame_word hH hp (by unfold Aligned; omega) hin⟩ + exact ⟨hin, hp.word hH (by unfold Aligned; omega) hin⟩ /-- (A64-S1A gen 29) **The 128 words at a checked offset of a frame object** (the common part of MdbRunQ's `runBuf_of`, MdbVcStQ's `frU_of` and MdbDelVsZ's `RunBuf.frUb`): each aligned and inside the object. -/ theorem frame_off_words (hH : HeapOK H) {ptr bits sz off : U64} {size : capability.FrameSize} - (hp : H ptr = some (.other bits.val)) (hbits : capability.FrameSize.bits size = ok bits) + (hp : FrAt H ptr bits) (hbits : capability.FrameSize.bits size = ok bits) (hsz : (1#u64 <<< (bits &&& 63#u64) : Result U64) = ok sz) (h63 : (off &&& 63#u64) = 0#u64) (hlt : off.val < sz.val) (hge : 1024 ≤ sz.val - off.val) {i : U64} (hi : i.val < 128) : @@ -122,8 +121,7 @@ theorem frame_off_words (hH : HeapOK H) {ptr bits sz off : U64} {size : capabili simpa using e rw [hszv] at hlt hge obtain ⟨hal, -, -⟩ := frame_words hH hp hb64.2 ho (by omega) - have hf := hH.fits ptr _ hp - simp only [HKind.bits] at hf + have hf := hp.fits hH have hpo : (wa ptr off).val = ptr.val + off.val := by simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega have hv : (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val = ptr.val + off.val + 8 * i.val := by @@ -289,7 +287,7 @@ theorem tcb.fpu_transfer.readLK (hA : P0.ArchTotal ar) {s s1 : S} {a1 : A} {t le have hcap0 : capA st s x = .Frame ptr sz r false m ep asid va := by rw [← k1.capA hxO]; exact hcp have h12 : 12 ≤ bits.val := by cases sz <;> simp only [capability.FrameSize.bits] at hb <;> rw [← okinj hb] <;> simp - have hH : H ptr = some (.other bits.val) := B.sys.fr x hxO ptr sz r m ep asid va hcap0 bits hb + have hH : FrAt H ptr bits := B.sys.fr x hxO ptr sz r m ep asid va hcap0 bits hb have hFo := (B.fo x hxO ptr sz r m ep asid va hcap0 bits hb).1 obtain ⟨hfa, hff, hW⟩ := frame_words P.heap hH h12 ho hob -- the restart @@ -322,7 +320,7 @@ theorem tcb.fpu_transfer.readLK (hA : P0.ArchTotal ar) {s s1 : S} {a1 : A} {t le refine WP.spec_bind (tcb.copy_words_loop.w s2 _ _ _ 0#u64 hfa hff) fun s3 w3 => ?_ have hBo : ∀ b, CWW (wa ptr off) 65#u64 b → FrBw H OS b ∧ FrCw st OS s b := fun b hw' => by have hin := (hW b hw').1 - refine ⟨⟨(hW b hw').2, ⟨ptr, bits.val, hH, h12, hin⟩, fun y hy g => ?_⟩, + refine ⟨⟨(hW b hw').2, hH.frBw h12 hin, fun y hy g => ?_⟩, x, hxO, ptr, sz, r, m, ep, asid, va, bits, hcap0, hb, hin⟩ rcases hFo y hy with g' | g' <;> omega have X3 := SysL.cwO P2 h2.bxi run2 w3 (fun b hb => (hW b hb).2) diff --git a/proofs/Fl4ProofsA64/P1/MdbFrC.lean b/proofs/Fl4ProofsA64/P1/MdbFrC.lean index a30e5ec53..9aa124953 100644 --- a/proofs/Fl4ProofsA64/P1/MdbFrC.lean +++ b/proofs/Fl4ProofsA64/P1/MdbFrC.lean @@ -135,10 +135,35 @@ theorem frame_range {ptr r x3 x4 bits : U64} {size : capability.FrameSize} {x1 x · rw [Nat.mod_eq_of_lt hw]; omega · rw [Nat.mod_eq_sub_mod (by omega), Nat.mod_eq_of_lt (by omega)] at hr; omega +/-- **l4v `valid_untyped`** (Untyped_AI): every heap object meeting the region `[lo, hi)` lies inside it. -/ +def RegionIn (H : Heap) (lo hi : Nat) : Prop := + ∀ q k, H q = some k → MeetsR lo hi q.val (q.val + 2 ^ k.bits) → lo ≤ q.val ∧ q.val + 2 ^ k.bits ≤ hi + +/-- A frame range survives the drop of a region if every `.other` object containing it is kept. -/ +theorem FrAt.drop {H : Heap} {ptr bits : U64} {R : U64 → Prop} (h : FrAt H ptr bits) + (hD : ∀ b k, H b = some (.other k) → b.val ≤ ptr.val → ptr.val + 2 ^ bits.val ≤ b.val + 2 ^ k → ¬ R b) : + FrAt (H.drop R) ptr bits := by + obtain ⟨b, k, hb, h1, h2, h3⟩ := FrAt.def.1 h + exact FrAt.def.2 ⟨b, k, Heap.drop_eq_some.2 ⟨hD b k hb h1 h2, hb⟩, h1, h2, h3⟩ + +/-- The converse: a frame range in the dropped heap lies in a kept object, so it is off the region. -/ +theorem FrAt.undrop {H : Heap} {ptr bits : U64} {lo hi : Nat} (h : FrAt (H.drop (RegionD H lo hi)) ptr bits) : + FrAt H ptr bits ∧ ¬ MeetsR lo hi ptr.val (ptr.val + 2 ^ bits.val) := by + obtain ⟨b, k, hb, h1, h2, h3⟩ := FrAt.def.1 h + obtain ⟨hn, hb'⟩ := Heap.drop_eq_some.1 hb + refine ⟨FrAt.def.2 ⟨b, k, hb', h1, h2, h3⟩, fun hm => hn ?_⟩ + unfold RegionD + rw [hb'] + simp only [Option.elim, HKind.bits] + unfold MeetsR at hm ⊢ + omega + /-- **`FrameOK` over the dropped heap after the reset** (module docstring): the kept slots other than `u` keep their -caps, `u` holds an `Untyped`, `u` has no MDB children. -/ +caps, `u` holds an `Untyped`, `u` has no MDB children; `hRin` (l4v `valid_untyped`, `UtRV.rin`): every heap object +meeting the region lies in it, so the object containing a kept frame is kept. -/ theorem FrameOK.reset {s s' : S} (hF : FrameOK st H OS s) {par : U64 → Option U64} (hU : UtInvA st OS par s) {u p b i : U64} {d : Bool} (hu : u ∈ OS) (hcu : capA st s u = .Untyped p b i d) (hnd : ∀ y, ¬ Mdb.Desc par y u) + (hRin : RegionIn H p.val (p.val + 2 ^ b.val)) {OS' : Set U64} (hs : OS' ⊆ OS) {i' : U64} (hcu' : capA st s' u = .Untyped p b i' d) (hk : ∀ y ∈ OS', y ≠ u → capA st s' y = capA st s y) : FrameOK st (H.drop (RegionD H p.val (p.val + 2 ^ b.val))) OS' s' := by @@ -147,32 +172,39 @@ theorem FrameOK.reset {s s' : S} (hF : FrameOK st H OS s) {par : U64 → Option · rw [e, hcu'] at hc; cases hc rw [hk y hy e] at hc have hq := hF y (hs hy) ptr size rights x1 x2 x3 x4 hc bits hbits - refine Heap.drop_eq_some.2 ⟨fun hD => ?_, hq⟩ - unfold RegionD MeetsR at hD - rw [hq] at hD - simp only [Option.elim, show (HKind.other bits.val).bits = bits.val from rfl] at hD - have hp : physA (capA st s y) = true := by - have h := physA_eq (.Frame ptr size rights false x1 x2 x3 x4) - simp only [objects.cap_is_physical] at h - rw [hc]; exact (okinj h).symm - obtain ⟨rb, rt, -⟩ := ut_rangeA (capA_ut_b hcu) (by - have := hU.reg u hu (by rw [hcu]; exact physA_ut _ _ _ _); rwa [hcu] at this) - obtain ⟨fb, ft⟩ := frame_range hbits (by have := hU.reg y (hs hy) hp; rwa [hc] at this) - have hb1 : 1 ≤ 2 ^ b.val := Nat.one_le_two_pow have hf1 : 1 ≤ 2 ^ bits.val := Nat.one_le_two_pow - have hDj : ¬ DisjA (capA st s y) (capA st s u) := by unfold DisjA; rw [hcu, hc, rb, rt, fb, ft]; omega - rcases hU.drange u hu p b i d hcu y (hs hy) e hp hDj with g | g - · exact hnd y g - · have := hU.anc y u g (by rw [hcu]; rfl) - rw [hc] at this; simp [isUtA] at this + have hoff : ptr.val + 2 ^ bits.val ≤ p.val ∨ p.val + 2 ^ b.val ≤ ptr.val := by + by_contra hmeet + have hp : physA (capA st s y) = true := by + have h := physA_eq (.Frame ptr size rights false x1 x2 x3 x4) + simp only [objects.cap_is_physical] at h + rw [hc]; exact (okinj h).symm + obtain ⟨rb, rt, -⟩ := ut_rangeA (capA_ut_b hcu) (by + have := hU.reg u hu (by rw [hcu]; exact physA_ut _ _ _ _); rwa [hcu] at this) + obtain ⟨fb, ft⟩ := frame_range hbits (by have := hU.reg y (hs hy) hp; rwa [hc] at this) + have hb1 : 1 ≤ 2 ^ b.val := Nat.one_le_two_pow + have hDj : ¬ DisjA (capA st s y) (capA st s u) := by unfold DisjA; rw [hcu, hc, rb, rt, fb, ft]; omega + rcases hU.drange u hu p b i d hcu y (hs hy) e hp hDj with g | g + · exact hnd y g + · have := hU.anc y u g (by rw [hcu]; rfl) + rw [hc] at this; simp [isUtA] at this + refine FrAt.drop hq fun b0 k0 hb0 h1 h2 hD => ?_ + have hm : MeetsR p.val (p.val + 2 ^ b.val) b0.val (b0.val + 2 ^ k0) := by + unfold RegionD at hD + rw [hb0] at hD + simpa [Option.elim, HKind.bits] using hD + have hin := hRin b0 _ hb0 (by simpa [HKind.bits] using hm) + simp only [HKind.bits] at hin + omega /-- **`FrameOK` over the dropped heap and `OffR` at the reset's start** (MdbVUS's `reset_start` form). -/ theorem FrameOK.reset_start {s : S} (hS : MdbST st OS s) (hF : FrameOK st H OS s) {u p b i : U64} {d : Bool} (hu : u ∈ OS) (hcu : capA st s u = .Untyped p b i d) - (hnd : ∀ G par, TreeA st OS G par s → ∀ y, ¬ Mdb.Desc par y u) : + (hnd : ∀ G par, TreeA st OS G par s → ∀ y, ¬ Mdb.Desc par y u) + (hRin : RegionIn H p.val (p.val + 2 ^ b.val)) : FrameOK st (H.drop (RegionD H p.val (p.val + 2 ^ b.val))) (OffR p.val (p.val + 2 ^ b.val) OS) s := by obtain ⟨G, par, hM, -, -, -, -, hTr, hU⟩ := id hS - exact hF.reset hU hu hcu (hnd G par ⟨hM, hTr, hU⟩) OffR.sub hcu fun _ _ _ => rfl + exact hF.reset hU hu hcu (hnd G par ⟨hM, hTr, hU⟩) hRin OffR.sub hcu fun _ _ _ => rfl end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbGrowN.lean b/proofs/Fl4ProofsA64/P1/MdbGrowN.lean index 33e3ab355..fdbb11ae3 100644 --- a/proofs/Fl4ProofsA64/P1/MdbGrowN.lean +++ b/proofs/Fl4ProofsA64/P1/MdbGrowN.lean @@ -309,8 +309,8 @@ theorem UtEnd.freshN (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo h · rw [h4] at hc; simp [newCapA] at hc have hk := U.E.keep x hx hxs (fun j' hj' e => hwd ⟨j', hj', e⟩) rw [hk] at hc - have hq := hfr x hx ptr size rights x1 x2 x3 x4 hc bits hb - have := U.hole ptr _ hq + obtain ⟨q, z, hq, hbz, hq1, hq2⟩ := (hfr x hx ptr size rights x1 x2 x3 x4 hc bits hb).obj + have := U.hole q _ hq simp only [HKind.bits] at this rcases this with h | h <;> omega diff --git a/proofs/Fl4ProofsA64/P1/MdbInvSubA.lean b/proofs/Fl4ProofsA64/P1/MdbInvSubA.lean new file mode 100644 index 000000000..44364b6a5 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/MdbInvSubA.lean @@ -0,0 +1,299 @@ +/- +P1 (aarch64, E0.5b): **`MdbInvA` after `DeriveSubframe`'s `cdt::insert` of a 4 KiB alias of a large frame** — the A64 +twin of x86 `VsSubMdb.InsFCtx.inv`. + +The alias `c` (a frame cap inside the large frame cap's range; its slot is non-revocable: `revFA` of a frame is +`false`) is linked after the large frame's slot `src`, as `src`'s child when `src` is revocable (an original frame +cap), else as its sibling (`insParA par src dest (isPFA …)`; l4v `cap_insert` with `should_be_parent_of`). With the +chunk relation `srFA` (a non-revocable frame cap's slot is unconstrained) the chains stay chunked, given the range +hypothesis `hno` (l4v `caps_no_overlap` for the large frame: a physical cap in a chain is disjoint from it, a +non-revocable frame cap, or contains it; `FrLamA` at the `Large` frame cap). + +* **`SubInsCtxA`** / **`SubInsCtxA.inv`**: `MdbInvA` afterwards. The source's cap is kept (the alias is a new cap). + +Named premises: none. +-/ +import Fl4ProofsA64.P1.MdbSubFrA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + +namespace W7 +namespace R +namespace ST + +noncomputable section + +/-- The insertion of the alias `c` at `dest` after the large frame's slot `src` (module docstring). -/ +structure SubInsCtxA (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) + (G : List (List U64)) (par : U64 → Option U64) (s s' : S) (src dest : U64) (c : capability.Cap) : Prop where + hM : MdbLk st OS G s + hOk : Mdb.MdbOK par G + hI : MdbInvA st G par s + hsrc : src ∈ G.flatten + hdest : dest ∉ G.flatten + hnext : ∀ a, (a = dest ∨ a ∈ G.flatten) → NxA st s' a = + if a = dest then NxA st s src else if a = src then dest else NxA st s a + hcap : ∀ a, (a = dest ∨ a ∈ G.flatten) → capA st s' a = if a = dest then c else capA st s a + hrev : ∀ a, (a = dest ∨ a ∈ G.flatten) → revA st s' a = + if a = dest then revFA c (capA st s src) else revA st s a + hfb : ∀ a, (a = dest ∨ a ∈ G.flatten) → fbA st s' a = + if a = dest then revFA c (capA st s src) else fbA st s a + hsF : isFrA (capA st s src) = true + hcF : isFrA c = true + hcr : baseA c ≤ topA c + hcin : WithinA c (capA st s src) + hno : ∀ x ∈ G.flatten, physA (capA st s x) = true → DisjA (capA st s x) (capA st s src) ∨ + (isFrA (capA st s x) = true ∧ revA st s x = false) ∨ WithinA (capA st s src) (capA st s x) + +namespace SubInsCtxA +variable {OS : Set U64} {G : List (List U64)} {par : U64 → Option U64} {s s' : S} {src dest : U64} + {c : capability.Cap} (h : SubInsCtxA st OS G par s s' src dest c) +include h + +theorem dne {z : U64} (hz : z ∈ G.flatten) : z ≠ dest := fun e => h.hdest (e ▸ hz) +theorem sd : src ≠ dest := h.dne h.hsrc + +theorem cz {z : U64} (hz : z ∈ G.flatten) : capA st s' z = capA st s z := by + rw [h.hcap z (Or.inr hz), if_neg (h.dne hz)] +theorem rz {z : U64} (hz : z ∈ G.flatten) : revA st s' z = revA st s z := by + rw [h.hrev z (Or.inr hz), if_neg (h.dne hz)] +theorem fz {z : U64} (hz : z ∈ G.flatten) : fbA st s' z = fbA st s z := by + rw [h.hfb z (Or.inr hz), if_neg (h.dne hz)] +theorem nz {z : U64} (hz : z ∈ G.flatten) (hzs : z ≠ src) : NxA st s' z = NxA st s z := by + rw [h.hnext z (Or.inr hz), if_neg (h.dne hz), if_neg hzs] +theorem ns : NxA st s' src = dest := by rw [h.hnext src (Or.inr h.hsrc), if_neg h.sd, if_pos rfl] +theorem nd : NxA st s' dest = NxA st s src := by rw [h.hnext dest (Or.inl rfl), if_pos rfl] +theorem cd : capA st s' dest = c := by rw [h.hcap dest (Or.inl rfl), if_pos rfl] +theorem rfF : revFA c (capA st s src) = false := revFA_frame h.hcF _ +theorem rd : revA st s' dest = false := by rw [h.hrev dest (Or.inl rfl), if_pos rfl]; exact h.rfF +theorem fd : fbA st s' dest = false := by rw [h.hfb dest (Or.inl rfl), if_pos rfl]; exact h.rfF +theorem cs : capA st s' src = capA st s src := h.cz h.hsrc + +theorem pm {x y : U64} (hx : x ∈ G.flatten) (hy : y ∈ G.flatten) : isPMA st s' x y = isPMA st s x y := by + unfold isPMA; rw [h.rz hx, h.fz hy, h.cz hx, h.cz hy] + +theorem sm {x y : U64} (hx : x ∈ G.flatten) (hy : y ∈ G.flatten) : srMA st s' x y = srMA st s x y := by + unfold srMA; rw [h.cz hx, h.cz hy] + +theorem sf {x y : U64} (hx : x ∈ G.flatten) (hy : y ∈ G.flatten) : srFA st s' x y = srFA st s x y := by + unfold srFA; rw [h.sm hx hy, h.cz hx, h.rz hx] + +theorem pd (z : U64) : par z ≠ some dest := fun e => h.hdest (h.hOk.par_mem z dest e).2 +theorem dn : par dest = none := by + cases e : par dest with + | none => rfl + | some p => exact absurd (h.hOk.par_mem dest p e).1 h.hdest + +theorem desc (b : Bool) (y x : U64) : Mdb.Desc (insParA par src dest b) y x ↔ + Mdb.Desc par y x ∨ (y = dest ∧ ((b = true ∧ x = src) ∨ Mdb.Desc par src x)) := by + have hnp : (if b then some src else par src) ≠ some dest := by + cases b <;> simp [h.sd, h.pd src] + unfold insParA + rw [Mdb.desc_update_iff h.pd h.dn hnp, np_desc_iffA] + +theorem dest_no_desc (x : U64) : ¬ Mdb.Desc par dest x := fun e => h.hdest (desc_memA h.hOk e).1 + +theorem memI (z : U64) : z ∈ (insG src dest G).flatten ↔ z = dest ∨ z ∈ G.flatten := + mem_insG_flat h.hsrc + +theorem psd : isPMA st s' src dest = isPFA (revA st s src) (capA st s src) c (revFA c (capA st s src)) := by + unfold isPMA + rw [h.rz h.hsrc, h.cs, h.cd, h.fd, h.rfF] + +/-- An old cap's region relation to the large frame carries over to the alias. -/ +theorem sra_u {u : U64} (hu : u ∈ G.flatten) (hnf : ¬ (isFrA (capA st s u) = true ∧ revA st s u = false)) : + sraA (capA st s u) c = sraA (capA st s u) (capA st s src) := by + refine sraA_sub_eq h.hsF h.hcF ?_ h.hcr h.hcin (fun hp => ?_) + · have := h.hcin; have := h.hcr; unfold WithinA at *; omega + · rcases h.hno u hu hp with hd | hf | hw + · exact Or.inl hd + · exact absurd hf hnf + · exact Or.inr hw + +/-- An old cap that sees the large frame sees the alias. -/ +theorem sra_anc {x : U64} (h2 : sraA (capA st s x) (capA st s src) = true) : + sraA (capA st s x) c = true := by + by_cases hU : isUtA (capA st s x) = true + · obtain ⟨p, b, i, d, hx⟩ : ∃ p b i d, capA st s x = .Untyped p b i d := by + cases hc : capA st s x <;> rw [hc] at hU <;> simp [isUtA] at hU + exact ⟨_, _, _, _, rfl⟩ + rw [hx] at h2 ⊢ + rw [sraA_ut_iff] at h2 ⊢ + obtain ⟨-, hw, -⟩ := h2 + have := h.hcin; unfold WithinA at * + exact ⟨(isFrA_phys h.hcF).1, ⟨by omega, by omega⟩, h.hcr⟩ + · by_cases hF : isFrA (capA st s x) = true + · rw [sraA_frame_iff hF] at h2 ⊢ + obtain ⟨-, hw, -⟩ := h2 + have := h.hcin; unfold WithinA at * + exact ⟨h.hcF, ⟨by omega, by omega⟩, h.hcr⟩ + · rw [sraA_nonfr_frame (by simpa using hU) (by simpa using hF) h.hsF] at h2; cases h2 + +theorem notBadged_of_sra {x : U64} (h2 : sraA (capA st s x) (capA st s src) = true) : + isBadgedA (capA st s x) = false := by + by_cases hU : isUtA (capA st s x) = true + · cases hc : capA st s x <;> rw [hc] at hU <;> simp [isUtA] at hU + rfl + · by_cases hF : isFrA (capA st s x) = true + · cases hc : capA st s x <;> rw [hc] at hF <;> simp [isFrA] at hF + rfl + · rw [sraA_nonfr_frame (by simpa using hU) (by simpa using hF) h.hsF] at h2; cases h2 + +theorem isBadgedA_fr {x : capability.Cap} (hx : isFrA x = true) : isBadgedA x = false := by + cases x <;> simp [isFrA] at hx + rfl + +local notation "bI" => isPFA (revA st s src) (capA st s src) c (revFA c (capA st s src)) + +theorem orig' (z p : U64) (hz : insParA par src dest bI z = some p) : revA st s' p = true := by + unfold insParA at hz + by_cases hzd : z = dest + · subst hzd + rw [Function.update_self] at hz + cases hb : bI + · rw [hb] at hz; simp only [Bool.false_eq_true, ↓reduceIte] at hz + rw [h.rz (h.hOk.par_mem _ _ hz).2]; exact h.hI.orig _ _ hz + · rw [hb] at hz + have hp : p = src := by simpa using hz.symm + rw [hp, h.rz h.hsrc] + simp only [isPFA, Bool.and_eq_true] at hb + exact hb.1.1 + · rw [Function.update_of_ne hzd] at hz + rw [h.rz (h.hOk.par_mem _ _ hz).2]; exact h.hI.orig _ _ hz + +theorem desc' (x y : U64) (hd : Mdb.Desc (insParA par src dest bI) y x) : isPMA st s' x y = true := by + rcases (h.desc bI y x).1 hd with hd | ⟨hy, hd⟩ + · obtain ⟨h1, h2⟩ := desc_memA h.hOk hd + rw [h.pm h2 h1]; exact h.hI.desc x y hd + · rw [hy] + rcases hd with ⟨hb, hxs⟩ | hd + · rw [hxs, h.psd]; exact hb + · have hx := (desc_memA h.hOk hd).2 + have h0 := h.hI.desc x src hd + unfold isPMA at h0 ⊢ + rw [h.rz hx, h.cz hx, h.cd, h.fd] + unfold isPFA at h0 ⊢ + simp only [Bool.and_eq_true] at h0 ⊢ + obtain ⟨⟨h1, h2⟩, h3⟩ := h0 + have hnb : isBadgedA (capA st s x) = false := h.notBadged_of_sra h2 + refine ⟨⟨h1, h.sra_anc h2⟩, ?_⟩ + rw [hnb]; simp + +theorem after' (y : U64) (hy : y ∈ (insG src dest G).flatten) (hn : NxA st s' y ≠ 0#u64) (x : U64) + (hx : x = y ∨ Mdb.Desc (insParA par src dest bI) y x) + (hnd : ¬ Mdb.Desc (insParA par src dest bI) (NxA st s' y) x) : isPMA st s' x (NxA st s' y) = false := by + rcases (h.memI y).1 hy with hyd | hy + · rw [hyd] at hn hnd hx ⊢ + rw [h.nd] at hn hnd ⊢ + have hN := h.hM.next_memA h.hsrc hn + rcases hx with hxd | hx + · subst hxd + unfold isPMA + rw [h.rd] + simp [isPFA] + · have hx' : x = src ∨ Mdb.Desc par src x := by + rcases (h.desc bI dest x).1 hx with e | ⟨-, ⟨-, e⟩ | e⟩ + · exact absurd e (h.dest_no_desc x) + · exact Or.inl e + · exact Or.inr e + have hnd' : ¬ Mdb.Desc par (NxA st s src) x := fun e => hnd ((h.desc bI _ x).2 (Or.inl e)) + have hxm : x ∈ G.flatten := by + rcases hx' with e | e + · rw [e]; exact h.hsrc + · exact (desc_memA h.hOk e).2 + rw [h.pm hxm hN] + exact h.hI.after src h.hsrc hn x hx' hnd' + · by_cases hys : y = src + · rw [hys] at hn hnd hx hy ⊢ + rw [h.ns] at hn hnd ⊢ + rcases hx with hxy | hx + · rw [hxy] at hnd ⊢ + rw [h.psd] + cases hb : bI + · rfl + · exact absurd ((h.desc bI dest src).2 (Or.inr ⟨rfl, Or.inl ⟨hb, rfl⟩⟩)) hnd + · have hx' : Mdb.Desc par src x := ((h.desc bI src x).1 hx).resolve_right (fun e => h.sd e.1) + exact absurd ((h.desc bI dest x).2 (Or.inr ⟨rfl, Or.inr hx'⟩)) hnd + · rw [h.nz hy hys] at hn hnd ⊢ + have hw := h.hM.next_memA hy hn + have hx' : x = y ∨ Mdb.Desc par y x := by + rcases hx with e | e + · exact Or.inl e + · exact Or.inr (((h.desc bI y x).1 e).resolve_right (fun e => h.dne hy e.1)) + have hnd' : ¬ Mdb.Desc par (NxA st s y) x := fun e => hnd ((h.desc bI _ x).2 (Or.inl e)) + have hxm : x ∈ G.flatten := by + rcases hx' with e | e + · rw [e]; exact hy + · exact (desc_memA h.hOk e).2 + rw [h.pm hxm hw] + exact h.hI.after y hy hn x hx' hnd' + +theorem chunk' (ch' : List U64) (hch' : ch' ∈ insG src dest G) : Mdb.ChunkL (srFA st s') ch' := by + rw [insG_eq] at hch' + obtain ⟨ch, hch, rfl⟩ := List.mem_map.1 hch' + have hchm : ∀ z, z ∈ ch → z ∈ G.flatten := fun z hz => List.mem_flatten.2 ⟨_, hch, hz⟩ + by_cases hsc : src ∈ ch + · obtain ⟨A, B, rfl⟩ := List.append_of_mem hsc + have hnd0 : (A ++ src :: B).Nodup := (List.nodup_flatten.1 h.hOk.nodup).1 _ hch + rw [Mdb.insAfter_split (Mdb.nodup_mid hnd0).1] + refine Mdb.chunkL_ins2 (h.hI.chunk _ hch) (fun u hu v hv => h.sf (hchm u hu) (hchm v hv)) + (fun u hu => ?_) (ca_trueA (fun v => by simp [srFA, h.cd, h.hcF, h.rd]) B) (srFA_of_srMA ?_) + · have hum := hchm u hu + by_cases hnf : isFrA (capA st s u) = true ∧ revA st s u = false + · simp [srFA, h.cz hum, h.rz hum, hnf.1, hnf.2] + · unfold srFA srMA; rw [h.cd, h.cz hum, h.rz hum, h.sra_u hum hnf] + · unfold srMA; rw [h.cs, h.cd]; exact (sraA_frame_iff h.hsF).2 ⟨h.hcF, h.hcin, h.hcr⟩ + · rw [Mdb.insAfter_of_not_mem hsc] + exact Mdb.chunkL_congr (h.hI.chunk _ hch) (fun u hu v hv => h.sf (hchm u hu) (hchm v hv)) + +theorem badges' (y : U64) (hy : y ∈ (insG src dest G).flatten) (hn : NxA st s' y ≠ 0#u64) + (hbg : isBadgedA (capA st s' y) = true) (hsr : srMA st s' y (NxA st s' y) = true) + (hbne : badgeA (capA st s' y) ≠ badgeA (capA st s' (NxA st s' y))) + (hb0 : badgeA (capA st s' (NxA st s' y)) ≠ 0#u64) : fbA st s' (NxA st s' y) = true := by + rcases (h.memI y).1 hy with hyd | hy + · rw [hyd, h.cd] at hbg; rw [h.isBadgedA_fr h.hcF] at hbg; cases hbg + · by_cases hys : y = src + · rw [hys, h.cs] at hbg; rw [h.isBadgedA_fr h.hsF] at hbg; cases hbg + · rw [h.nz hy hys] at hn hsr hbne hb0 ⊢ + have hw := h.hM.next_memA hy hn + rw [h.fz hw] + rw [h.cz hy, h.cz hw] at hbne + rw [h.cz hy] at hbg + rw [h.cz hw] at hb0 + exact h.hI.badges y hy hn hbg (by rw [← h.sm hy hw]; exact hsr) hbne hb0 + +theorem utrev' (x : U64) (hx : x ∈ (insG src dest G).flatten) (hu : isUtA (capA st s' x) = true) : + revA st s' x = true := by + rcases (h.memI x).1 hx with hxd | hx + · rw [hxd, h.cd, (isFrA_phys h.hcF).2] at hu; cases hu + · rw [h.rz hx]; rw [h.cz hx] at hu; exact h.hI.utrev x hx hu + +theorem self' (x : U64) (hx : x ∈ (insG src dest G).flatten) (hz : isZbA (capA st s' x) = false) : + srMA st s' x x = true := by + rcases (h.memI x).1 hx with hxd | hx + · rw [hxd]; unfold srMA; rw [h.cd] + exact (sraA_frame_iff h.hcF).2 ⟨h.hcF, ⟨le_refl _, le_refl _⟩, h.hcr⟩ + · rw [h.cz hx] at hz + rw [h.sm hx hx]; exact h.hI.self x hx hz + +/-- **`MdbInvA` after inserting the alias.** -/ +theorem inv : MdbInvA st (insG src dest G) (insParA par src dest bI) s' := + ⟨h.orig', h.desc', h.after', h.chunk', h.badges', h.utrev', h.self'⟩ + +end SubInsCtxA + + +end + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/MdbNHO.lean b/proofs/Fl4ProofsA64/P1/MdbNHO.lean index edcab1bf3..49da402dc 100644 --- a/proofs/Fl4ProofsA64/P1/MdbNHO.lean +++ b/proofs/Fl4ProofsA64/P1/MdbNHO.lean @@ -45,9 +45,127 @@ variable {OS Vc Ub : Set U64} /-! ## Live frames as heap objects -/ -/-- A frame of size `size` at `ptr` is an `.other` heap object of the frame's size. -/ +/-- **(E0.2) A frame range `[ptr, ptr + 2^bits)` lies in a heap `.other` object** `b` of size `2^k` (containment: a +subframe lies in its source frame's object), at an offset that is a multiple of its own size. `@[irreducible]`: read +only through the accessors below (`FrAt.ofObj`, `mono`, `obj`, `fits`, `al`, `lt64`, `word`, `frBw`, `disjK`, `off`, +`ne_zero`, `win`). -/ +@[irreducible] def FrAt (H : Heap) (ptr bits : U64) : Prop := + ∃ b k, H b = some (.other k) ∧ b.val ≤ ptr.val ∧ ptr.val + 2 ^ bits.val ≤ b.val + 2 ^ k ∧ + (ptr.val - b.val) % 2 ^ bits.val = 0 + +theorem FrAt.def {H : Heap} {ptr bits : U64} : FrAt H ptr bits ↔ + ∃ b k, H b = some (.other k) ∧ b.val ≤ ptr.val ∧ ptr.val + 2 ^ bits.val ≤ b.val + 2 ^ k ∧ + (ptr.val - b.val) % 2 ^ bits.val = 0 := by + unfold FrAt; exact Iff.rfl + +/-- Producer: an exact `.other` object of the frame's size at its base. -/ +theorem FrAt.ofObj {H : Heap} {ptr bits : U64} (h : H ptr = some (.other bits.val)) : FrAt H ptr bits := + FrAt.def.2 ⟨ptr, bits.val, h, le_rfl, le_rfl, by simp⟩ + +/-- The heap grows (every object kept). -/ +theorem FrAt.mono {H H' : Heap} {ptr bits : U64} (hg : ∀ q k, H q = some k → H' q = some k) (h : FrAt H ptr bits) : + FrAt H' ptr bits := by + obtain ⟨b, k, hb, h1, h2, h3⟩ := FrAt.def.1 h + exact FrAt.def.2 ⟨b, k, hg _ _ hb, h1, h2, h3⟩ + +/-- The frame range lies in an `.other` object `b` of size `2^k`. -/ +theorem FrAt.obj {H : Heap} {ptr bits : U64} (h : FrAt H ptr bits) : + ∃ b k, H b = some (.other k) ∧ bits.val ≤ k ∧ b.val ≤ ptr.val ∧ ptr.val + 2 ^ bits.val ≤ b.val + 2 ^ k := by + obtain ⟨b, k, hb, h1, h2, -⟩ := FrAt.def.1 h + refine ⟨b, k, hb, ?_, h1, h2⟩ + have h3 : 2 ^ bits.val ≤ 2 ^ k := by omega + exact (Nat.pow_le_pow_iff_right (by norm_num)).1 h3 + +theorem FrAt.fits {H : Heap} {ptr bits : U64} (hH : HeapOK H) (h : FrAt H ptr bits) : ptr.val + 2 ^ bits.val ≤ 2 ^ 64 := by + obtain ⟨b, k, hb, h1, h2, -⟩ := FrAt.def.1 h + have := hH.fits b _ hb + simp only [HKind.bits] at this + omega + +theorem FrAt.al {H : Heap} {ptr bits : U64} (hH : HeapOK H) (h : FrAt H ptr bits) : ptr.val % 2 ^ bits.val = 0 := by + obtain ⟨b, k, hb, h1, h2, ho⟩ := FrAt.def.1 h + have hbk : bits.val ≤ k := by + have h3 : 2 ^ bits.val ≤ 2 ^ k := by omega + exact (Nat.pow_le_pow_iff_right (by norm_num)).1 h3 + have hal := hH.align b _ hb + simp only [HKind.bits] at hal + have hd : 2 ^ bits.val ∣ 2 ^ k := Nat.pow_dvd_pow 2 hbk + have h5 : b.val % 2 ^ bits.val = 0 := Nat.mod_eq_zero_of_dvd (hd.trans (Nat.dvd_of_mod_eq_zero hal)) + have e : ptr.val = b.val + (ptr.val - b.val) := by omega + calc ptr.val % 2 ^ bits.val = (b.val + (ptr.val - b.val)) % 2 ^ bits.val := by rw [← e] + _ = ((b.val % 2 ^ bits.val) + ((ptr.val - b.val) % 2 ^ bits.val)) % 2 ^ bits.val := Nat.add_mod _ _ _ + _ = 0 := by rw [h5, ho]; simp + +theorem FrAt.lt64 {H : Heap} {ptr bits : U64} (hH : HeapOK H) (h : FrAt H ptr bits) : bits.val < 64 := by + obtain ⟨b, k, hb, hbk, -⟩ := h.obj + have := hH.lt64 b _ hb + simp only [HKind.bits] at this + omega + +/-- **An aligned word of the frame range is a word of `Ω \ Sg`** (`HeapOK.disj`). -/ +theorem FrAt.word {H : Heap} {ptr bits : U64} (hH : HeapOK H) (h : FrAt H ptr bits) {w : U64} (ha : Aligned w) + (hin : ptr.val ≤ w.val ∧ w.val < ptr.val + 2 ^ bits.val) : w ∈ H.omega ∧ w ∉ H.frame := by + obtain ⟨b, k, hp, h1, h2, -⟩ := FrAt.def.1 h + refine ⟨⟨ha, b, _, hp, Or.inr (Or.inr (Or.inl ⟨_, rfl⟩)), by omega, by simp only [HKind.bits]; omega⟩, ?_⟩ + rintro ⟨-, q, k', hq, hk', q1, q2⟩ + have hne : q ≠ b := by + rintro rfl + rw [hp] at hq + cases hq + rcases hk' with e' | ⟨z, e'⟩ | ⟨e', -⟩ <;> cases e' + rcases hH.disj q k' b _ hq hp hne with g | g + · omega + · have g' : b.val + 2 ^ k ≤ q.val := g + omega + +/-- The frame range as an `FrBw`-style object triple. -/ +theorem FrAt.frBw {H : Heap} {ptr bits : U64} (h : FrAt H ptr bits) (h12 : 12 ≤ bits.val) {w : U64} + (hin : ptr.val ≤ w.val ∧ w.val < ptr.val + 2 ^ bits.val) : + ∃ q z, H q = some (.other z) ∧ 12 ≤ z ∧ q.val ≤ w.val ∧ w.val < q.val + 2 ^ z := by + obtain ⟨b, k, hb, hbk, h1, h2⟩ := h.obj + exact ⟨b, k, hb, by omega, by omega, by omega⟩ + +/-- A heap object that is not an `.other` object is disjoint from the frame range. -/ +theorem FrAt.disjK {H : Heap} {ptr bits : U64} (hH : HeapOK H) (h : FrAt H ptr bits) {q : U64} {k : HKind} + (hk : H q = some k) (hn : ∀ z, k ≠ .other z) : + q.val + 2 ^ k.bits ≤ ptr.val ∨ ptr.val + 2 ^ bits.val ≤ q.val := by + obtain ⟨b, kb, hb, h1, h2, -⟩ := FrAt.def.1 h + have e : q ≠ b := by + rintro rfl + rw [hb] at hk + exact hn _ (Option.some.inj hk).symm + have g := hH.disj q k b _ hk hb e + rw [show (HKind.other kb).bits = kb from rfl] at g + omega + +/-- The frame range is off a non-`.other` heap object, as a word statement (`frameWord_offA`). -/ +theorem FrAt.off {H : Heap} {ptr bits : U64} (hH : HeapOK H) (h : FrAt H ptr bits) {q : U64} {kd : HKind} + (hq : H q = some kd) (hne : ∀ z, kd ≠ .other z) {b : U64} (h1 : ptr.val ≤ b.val) + (h2 : b.val < ptr.val + 2 ^ bits.val) : b.val < q.val ∨ q.val + 2 ^ kd.bits ≤ b.val := by + have := FrAt.disjK hH h hq hne + omega + +/-- A frame cap's base is not `0` when the heap has no object at `0`. -/ +theorem FrAt.ne_zero {H : Heap} {ptr bits : U64} (h0 : H 0#u64 = none) (h : FrAt H ptr bits) : ptr ≠ 0#u64 := by + intro e + subst e + obtain ⟨b, k, hb, h1, -, -⟩ := FrAt.def.1 h + have : b = 0#u64 := UScalar.eq_of_val_eq (by have : (0#u64 : U64).val = 0 := rfl; omega) + rw [this, h0] at hb + cases hb + +/-- A heap window `[lo, hi)` of every object holds the frame range. -/ +theorem FrAt.win {H : Heap} {ptr bits : U64} {lo hi : Nat} + (hw : ∀ p k, H p = some k → lo ≤ p.val ∧ p.val + 2 ^ k.bits ≤ hi) (h : FrAt H ptr bits) : + lo ≤ ptr.val ∧ ptr.val + 2 ^ bits.val ≤ hi := by + obtain ⟨b, k, hb, h1, h2, -⟩ := FrAt.def.1 h + have := hw b _ hb + simp only [HKind.bits] at this + omega + +/-- A frame of size `size` at `ptr` lies in a heap object (`FrAt`). -/ def FrObj (H : Heap) (ptr : U64) (size : capability.FrameSize) : Prop := - ∀ bits, size.bits = ok bits → H ptr = some (.other bits.val) + ∀ bits, size.bits = ok bits → FrAt H ptr bits /-- **Every live non-device frame cap names a heap object of its size** (module docstring). -/ def FrameOK (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS : Set U64) (s : S) : Prop := @@ -90,9 +208,9 @@ theorem LoopV.fr {H' : Heap} {s sf : S} (hF : FrameOK st H OS s) (hHH' : ∀ q k rw [hnew j hj] at hc try beta_reduce at hc obtain ⟨e, hk⟩ := newCapA_frame hn hc - rw [e]; exact hHn (newCapA_frame_dev hn hc) j hj _ (hk bits hb) + rw [e]; exact FrAt.ofObj (hHn (newCapA_frame_dev hn hc) j hj _ (hk bits hb)) · rw [hold y hy ys fun j hj e => hyd ⟨j, hj, e⟩] at hc - exact hHH' _ _ (hF y hy ptr size rights x1 x2 x3 x4 hc bits hb) + exact FrAt.mono hHH' (hF y hy ptr size rights x1 x2 x3 x4 hc bits hb) section arch variable {A : Type _} {ar : machine.Arch A} @@ -149,17 +267,7 @@ theorem UbFr.omega (hH : HeapOK H) {s : S} (hF : FrameOK st H OS s) (hU : UbFr s (hal : ∀ b ∈ Ub, Aligned b) : ∀ b ∈ Ub, b ∈ H.omega ∧ b ∉ H.frame := by intro b hb obtain ⟨y, hy, ptr, size, rights, x1, x2, x3, x4, bits, hc, hbits, h1, h2⟩ := hU b hb - have hp := hF y hy ptr size rights x1 x2 x3 x4 hc bits hbits - refine ⟨⟨hal b hb, ptr, _, hp, Or.inr (Or.inr (Or.inl ⟨_, rfl⟩)), h1, by simpa [HKind.bits] using h2⟩, ?_⟩ - rintro ⟨-, q, k, hq, hk, q1, q2⟩ - by_cases e : q = ptr - · subst e - rw [hp] at hq - obtain rfl := Option.some.inj hq - rcases hk with h | ⟨z, h⟩ | ⟨h, -⟩ <;> cases h - · have := hH.disj q k ptr _ hq hp e - rw [show (HKind.other bits.val).bits = bits.val from rfl] at this - omega + exact FrAt.word hH (hF y hy ptr size rights x1 x2 x3 x4 hc bits hbits) (hal b hb) ⟨h1, h2⟩ /-! ## `hFw` discharged, and the non-vacuity check -/ diff --git a/proofs/Fl4ProofsA64/P1/MdbPoolG.lean b/proofs/Fl4ProofsA64/P1/MdbPoolG.lean index 5724e348f..d1936ee3a 100644 --- a/proofs/Fl4ProofsA64/P1/MdbPoolG.lean +++ b/proofs/Fl4ProofsA64/P1/MdbPoolG.lean @@ -320,7 +320,7 @@ theorem SysL.growO {H1 : Heap} {OS1 : Set U64} {s : S} (hH : HeapOK H1) (hO : OS (fun e : (0#u64 : U64) = p => by rw [← e] at hp0; simp at hp0)).trans B.ly.h0, B.ly.ksw, B.ly.idleIn, B.ly.idleScIn, B.ly.idleOff, B.ly.ut0, B.ly.kslo⟩ refine ⟨⟨⟨⟨⟨B.sys.stz.1.1, B.sys.stz.1.2.1, hV, B.sys.stz.1.2.2.2.1, B.sys.stz.1.2.2.2.2⟩, B.sys.stz.2.1, - B.sys.stz.2.2⟩, fun y hy ptr size r x1 x2 x3 x4 hc bits hbt => hg _ _ (B.sys.fr y hy ptr size r x1 x2 x3 x4 hc + B.sys.stz.2.2⟩, fun y hy ptr size r x1 x2 x3 x4 hc bits hbt => FrAt.mono hg (B.sys.fr y hy ptr size r x1 x2 x3 x4 hc bits hbt), B.sys.cz, hUR⟩, hLN, hVR, hLY, fun y hy => CnOP.grow hg (B.cn y hy), fun y hy hB => B.bh y hy (by rw [eT] at hB; exact hB), B.ci, fun y hy => by rw [eS]; exact B.sc y hy, B.ct, B.fo, fun y hy hE => B.ep y hy (by rw [eT] at hE; exact hE), fun t ht => B.ipc t (by rw [eT] at ht; exact ht)⟩, diff --git a/proofs/Fl4ProofsA64/P1/MdbRegRL.lean b/proofs/Fl4ProofsA64/P1/MdbRegRL.lean index 8ff5c1a2d..8446701d5 100644 --- a/proofs/Fl4ProofsA64/P1/MdbRegRL.lean +++ b/proofs/Fl4ProofsA64/P1/MdbRegRL.lean @@ -169,7 +169,7 @@ variable {OS : Set U64} {ia ie : Nat} /-- **A buffer inside a frame object off the `OS` slots** (module docstring). -/ def BufIn (H : Heap) (OS : Set U64) (b : U64) : Prop := b.val % 1024 = 0 ∧ ∃ ptr : U64, ∃ z : Nat, H ptr = some (.other z) ∧ ptr.val ≤ b.val ∧ - b.val + 1024 ≤ ptr.val + 2 ^ z ∧ ∀ y ∈ OS, y.val + 32 ≤ ptr.val ∨ ptr.val + 2 ^ z ≤ y.val + b.val + 1024 ≤ ptr.val + 2 ^ z ∧ ∀ y ∈ OS, y.val + 32 ≤ b.val ∨ b.val + 1024 ≤ y.val /-- **The words of the caller's buffer `buf`** (none at `buf = 0`). -/ def RRBw (buf w : U64) : Prop := buf ≠ 0#u64 ∧ Aligned w ∧ buf.val ≤ w.val ∧ w.val < buf.val + 1024 @@ -227,13 +227,12 @@ theorem lookup_bufIn {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {ct : simp only [bind_ok, lift] refine WP.spec_bind (shl1_val hb64) fun size1 hs1 => ?_ refine (WP.spec_ok _).2 fun _ => ?_ - have hp : H ptr = some (.other bits.val) := B.sys.fr _ hx ptr sz r m ep asid va hcp bits hb + have hp : FrAt H ptr bits := B.sys.fr _ hx ptr sz r m ep asid va hcp bits hb have hFo := (B.fo _ hx ptr sz r m ep asid va hcp bits hb).1 have h12 : 12 ≤ bits.val := by cases sz <;> simp only [capability.FrameSize.bits] at hb <;> rw [← okinj hb] <;> simp - have hf := hH.fits ptr _ hp - have hal := hH.align ptr _ hp - simp only [HKind.bits] at hf hal + have hf := hp.fits hH + have hal := hp.al hH have hP : 2 ^ bits.val = 1024 * 2 ^ (bits.val - 10) := by rw [show (1024 : Nat) = 2 ^ 10 from rfl, ← Nat.pow_add]; congr 1; omega have hP4 : 4 ≤ 2 ^ (bits.val - 10) := by @@ -256,8 +255,12 @@ theorem lookup_bufIn {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {ct : have hv : (wa ptr o).val = ptr.val + o.val := by simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega have hQ : o.val + 1024 ≤ 1024 * Q := by omega - refine ⟨by rw [hv]; omega, ptr, bits.val, hp, by rw [hv]; omega, by rw [hv, hP]; omega, fun y hy => ?_⟩ - rw [hP]; exact hFo y hy + obtain ⟨q, z, hq, hbz, hq1, hq2⟩ := hp.obj + rw [hP] at hq2 + refine ⟨by rw [hv]; omega, q, z, hq, by rw [hv]; omega, by rw [hv]; omega, fun y hy => ?_⟩ + have := hFo y hy + rw [hv] + omega /-! ## The write phase -/ diff --git a/proofs/Fl4ProofsA64/P1/MdbRoot.lean b/proofs/Fl4ProofsA64/P1/MdbRoot.lean new file mode 100644 index 000000000..01476d497 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/MdbRoot.lean @@ -0,0 +1,219 @@ +/- +P1 (aarch64, vsinv-RO1): **`derive_cap` / `copied_cap` and the root-kind caps** — a CNode Copy / Mint's new cap `nc` +is a root-kind cap (a Stage-1 `Pml4`, a level-zero `Ept`, a `HighVSpace`) only as the source cap itself, and is never an +UNMAPPED root-kind cap (`derive_cap` refuses unmapped root caps, objects.rs:214–233; `mask_cap_rights` / +`update_cap_data` change no root-kind cap and make none). Feeds `RootClosedA.of_copy` (P3/VsUniqA). + +* `RootCapK c` / `RootCapU c`: `c` is a root-kind / an unmapped root-kind cap (of any object). +* `capability.mask_cap_rights.rt`, `objects.update_cap_data.rt`: `RootCapK m → m = c`. +* `objects.derive_cap.rt`: `(RootCapK nc → nc = c) ∧ ¬ RootCapU nc`; **`cnode.copied_cap.rt`**: the same of the new cap + against the source cap. + +No named premise; new definitions and theorems only. +-/ +import Fl4ProofsA64.P1.MdbTreeD +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + +namespace W7 +namespace R +namespace ST + +/-- A root-kind or `PageTable` cap: `Pml4`, level-zero `Ept`, `HighVSpace`, `PageTable` (both VsUniq classes at once). -/ +def RootCapK (c : capability.Cap) : Prop := + (∃ p m a, c = .Pml4 p m a) ∨ (∃ p m a v, c = .Ept p 0#u64 m a v) ∨ (∃ p m a, c = .HighVSpace p m a) ∨ + (∃ p m a v, c = .PageTable p m a v) + +/-- An unmapped root-kind cap. -/ +def RootCapU (c : capability.Cap) : Prop := + (∃ p a, c = .Pml4 p false a) ∨ (∃ p a v, c = .Ept p 0#u64 false a v) ∨ (∃ p a, c = .HighVSpace p false a) ∨ + (∃ p a v, c = .PageTable p false a v) + +set_option hygiene false in +/-- A concrete result is the argument or no root-kind cap. -/ +local macro "rtn" : tactic => `(tactic| ( + first + | exact fun _ => rfl + | exact fun h => absurd h (by rintro (⟨_, _, _, e⟩ | ⟨_, _, _, _, e⟩ | ⟨_, _, _, e⟩ | ⟨_, _, _, _, e⟩) <;> cases e))) + +/-- `mask_cap_rights` changes no root-kind cap and makes none. -/ +theorem capability.mask_cap_rights.rt (r : capability.Rights) (c : capability.Cap) : + capability.mask_cap_rights r c ⦃ m => RootCapK m → m = c ⦄ := by + cases c + case Endpoint p b sd rc g gr => + cases sd <;> cases rc <;> cases g <;> cases gr <;> + simp only [capability.mask_cap_rights, Bool.false_eq_true, ↓reduceIte, bind_ok] <;> + exact (WP.spec_ok _).2 (by rtn) + case Notification p b sd rc => + cases sd <;> cases rc <;> + simp only [capability.mask_cap_rights, Bool.false_eq_true, ↓reduceIte, bind_ok] <;> + exact (WP.spec_ok _).2 (by rtn) + case Reply p g => + cases g <;> simp only [capability.mask_cap_rights, Bool.false_eq_true, ↓reduceIte] <;> + exact (WP.spec_ok _).2 (by rtn) + case Frame p sz rt dv mp ep asd va => + simp only [capability.mask_cap_rights] + exact WP.spec_bind (P0.capability.mask_vm_rights.p0 rt r) fun _ _ => (WP.spec_ok _).2 (by rtn) + all_goals (simp only [capability.mask_cap_rights]; exact (WP.spec_ok _).2 (by rtn)) + +/-- `update_cap_data` changes no root-kind cap and makes none. -/ +theorem objects.update_cap_data.rt (pr : Bool) (data : U64) (c : capability.Cap) : + objects.update_cap_data pr data c ⦃ m => RootCapK m → m = c ⦄ := by + cases c + case Endpoint p b sd rc g gr => + simp only [objects.update_cap_data] + split + · exact (WP.spec_ok _).2 (by rtn) + · split <;> exact (WP.spec_ok _).2 (by rtn) + case Notification p b sd rc => + simp only [objects.update_cap_data] + split + · exact (WP.spec_ok _).2 (by rtn) + · split <;> exact (WP.spec_ok _).2 (by rtn) + case CNode p rd gs g => + simp only [objects.update_cap_data] + refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + split + · exact (WP.spec_ok _).2 (by rtn) + · refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + exact (WP.spec_ok _).2 (by rtn) + all_goals (simp only [objects.update_cap_data]; exact (WP.spec_ok _).2 (by rtn)) + +/-- The root-kind facts of a derived cap. -/ +def RootDerA (nc c : capability.Cap) : Prop := (RootCapK nc → nc = c) ∧ ¬ RootCapU nc + +set_option hygiene false in +local macro "rd_ok" : tactic => `(tactic| ( + refine (WP.spec_ok _).2 fun nc h => ?_ + cases h + exact ⟨by rtn, by rintro (⟨_, _, e⟩ | ⟨_, _, _, e⟩ | ⟨_, _, e⟩ | ⟨_, _, _, e⟩) <;> cases e⟩)) + +set_option maxHeartbeats 1000000 in +/-- **`derive_cap` returns a root-kind cap only as it went in, and never an unmapped one** (objects.rs:208–239). -/ +theorem objects.derive_cap.rt (s : S) (slot : U64) (c : capability.Cap) : + objects.derive_cap st s slot c ⦃ r => ∀ nc, r = .Ok nc → RootDerA nc c ⦄ := by + have hS : P0.StoreTotal st := L.total + cases c + case Untyped p b i d => + simp only [objects.derive_cap] + refine WP.spec_bind (P0.cdt.ensure_no_children.p0 st s slot hS) fun r _ => ?_ + rcases r with _ | e + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + rd_ok + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + first + | exact (WP.spec_ok _).2 fun nc h => (by cases h) + | (simp only [WP.spec_ok]; intro nc h; cases h) + case PageTable p m a v => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + rd_ok + case PageDirectory p m a v => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + rd_ok + case Pdpt p m a v => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + rd_ok + case Pml4 p m a => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + rd_ok + case Ept p l m a v => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + rd_ok + case HighVSpace p m a => + cases m + · simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 fun nc h => (by cases h) + · simp only [objects.derive_cap, ↓reduceIte] + rd_ok + all_goals (simp only [objects.derive_cap]; rd_ok) + +set_option maxHeartbeats 1000000 in +/-- **CNode Copy / Mint / Move / Mutate's new cap is a root-kind cap only as the source cap; Copy / Mint's is never an +unmapped one.** -/ +theorem cnode.copied_cap.rt (s : S) (lbl length buf src : U64) (src_cap : capability.Cap) : + cnode.copied_cap st s lbl length buf src src_cap ⦃ r => ∀ nc b, r = .Ok (nc, b) → + (RootCapK nc → nc = src_cap) ∧ (b = false → ¬ RootCapU nc) ⦄ := by + have hS : P0.StoreTotal st := L.total + have fin : ∀ (m : capability.Cap), (RootCapK m → m = src_cap) → ∀ x : core.result.Result capability.Cap error.Exc, + (∀ nc, x = .Ok nc → RootDerA nc m) → + (do + let cf ← core.result.Result.Insts.CoreOpsTry.branch x + match cf with + | core.ops.control_flow.ControlFlow.Continue val => ok (core.result.Result.Ok (val, false)) + | core.ops.control_flow.ControlFlow.Break residual => + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual + (capability.Cap × Bool) (core.convert.FromSame error.Exc) residual : + Result (core.result.Result (capability.Cap × Bool) error.Exc)) ⦃ r => + ∀ nc b, r = .Ok (nc, b) → (RootCapK nc → nc = src_cap) ∧ (b = false → ¬ RootCapU nc) ⦄ := by + intro m ht x hx + rcases x with v | e + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, WP.spec_ok] + intro nc b h; cases h + exact ⟨fun hk => ((hx v rfl).1 hk).trans (ht (by rw [← (hx v rfl).1 hk]; exact hk)), fun _ => (hx v rfl).2⟩ + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + first + | exact (WP.spec_ok _).2 fun nc b h => (by cases h) + | (simp only [WP.spec_ok]; intro nc b h; cases h) + unfold cnode.copied_cap + refine WP.spec_bind (P0.sched.cur_thread.p0 st s hS) fun ct _ => ?_ + split + · split + · simp only [error.truncated, WP.spec_ok]; intro nc b h; cases h + · refine WP.spec_bind (P0.msg.syscall_arg.p0 st s ct buf _ hS) fun i _ => ?_ + refine WP.spec_bind (P0.capability.Rights.from_word.p0 i) fun rr _ => ?_ + refine WP.spec_bind (capability.mask_cap_rights.rt rr src_cap) fun c hc => ?_ + exact WP.spec_bind (objects.derive_cap.rt s src c) fun r1 h1 => fin c hc r1 h1 + · split + · split + · simp only [error.truncated, WP.spec_ok]; intro nc b h; cases h + · refine WP.spec_bind (P0.msg.syscall_arg.p0 st s ct buf _ hS) fun i _ => ?_ + refine WP.spec_bind (P0.capability.Rights.from_word.p0 i) fun rr _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s ct buf _ hS) fun data _ => ?_ + refine WP.spec_bind (capability.mask_cap_rights.rt rr src_cap) fun c hc => ?_ + refine WP.spec_bind (objects.update_cap_data.rt false data c) fun c1 hc1 => ?_ + exact WP.spec_bind (objects.derive_cap.rt s src c1) fun r1 h1 => + fin c1 (fun hk => (hc1 hk).trans (hc (by rw [← hc1 hk]; exact hk))) r1 h1 + · split + · exact (WP.spec_ok _).2 fun nc b h => by + cases h; exact ⟨fun _ => rfl, fun e => by cases e⟩ + · split + · simp only [error.truncated, WP.spec_ok]; intro nc b h; cases h + · refine WP.spec_bind (P0.msg.syscall_arg.p0 st s ct buf _ hS) fun data _ => ?_ + exact WP.spec_bind (objects.update_cap_data.rt true data src_cap) fun c' hc' => + (WP.spec_ok _).2 fun nc b h => by + cases h; exact ⟨hc', fun e => by cases e⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/MdbRstD.lean b/proofs/Fl4ProofsA64/P1/MdbRstD.lean index 22d1863f3..004bfb61f 100644 --- a/proofs/Fl4ProofsA64/P1/MdbRstD.lean +++ b/proofs/Fl4ProofsA64/P1/MdbRstD.lean @@ -396,10 +396,6 @@ theorem untyped.retype.resetT {s : S} {a : A} {slot base nt us dest off len : U6 exact (WP.spec_ok _).2 (h2 e rfl) end arch -/-- **l4v `valid_untyped`** (Untyped_AI): every heap object meeting the region `[lo, hi)` lies inside it. -/ -def RegionIn (H : Heap) (lo hi : Nat) : Prop := - ∀ q k, H q = some k → MeetsR lo hi q.val (q.val + 2 ^ k.bits) → lo ≤ q.val ∧ q.val + 2 ^ k.bits ≤ hi - /-- **The slots off the region are placed over the dropped heap** (`RegionIn`: a word off the region lies in no dropped object). -/ theorem OSOK.dropR (hH : HeapOK H) (hO : OSOK H.tcbs H.omega Sg OS) {lo hi : Nat} (hR : RegionIn H lo hi) : diff --git a/proofs/Fl4ProofsA64/P1/MdbRstZ.lean b/proofs/Fl4ProofsA64/P1/MdbRstZ.lean index 9be5cbed0..1a2ec59db 100644 --- a/proofs/Fl4ProofsA64/P1/MdbRstZ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbRstZ.lean @@ -277,7 +277,7 @@ set_option maxHeartbeats 1000000 in /-- **The bundle over the shrunk sets at any state of the reset's frame** (module docstring). -/ theorem RstF.bn (hO : OSOK T Ω Sg OS) {s0 s : S} (hSt : StZ st H Cs OS s0) (hF : FrameOK st H OS s0) (hCZ : CoverZ st OS s0) {x p b i i' : U64} {d : Bool} (hx : x ∈ OS) (hcx : capA st s0 x = .Untyped p b i d) - (hnd : ∀ G par, TreeA st OS G par s0 → ∀ y, ¬ Mdb.Desc par y x) + (hnd : ∀ G par, TreeA st OS G par s0 → ∀ y, ¬ Mdb.Desc par y x) (hRin : RegionIn H p.val (p.val + 2 ^ b.val)) (hf : RstF st (OffR p.val (p.val + 2 ^ b.val) OS) x s0 s) (hcx' : capA st s x = .Untyped p b i' d) (hi' : i'.val ≤ 2 ^ b.val) (hUZ : UtZeroA st (OffR p.val (p.val + 2 ^ b.val) OS) s) (hNI : ∀ y ∈ OS, ¬ (y.val + 32 ≤ p.val ∨ p.val + 2 ^ b.val ≤ y.val) → ¬ IslN (L.ksb s0) y) : @@ -304,7 +304,7 @@ theorem RstF.bn (hO : OSOK T Ω Sg OS) {s0 s : S} (hSt : StZ st H Cs OS s0) (hF refine ⟨⟨⟨MdbST.of hO.offR.nz hM ⟨G, par, hT'⟩, hR'.recapU hut0 hk (fun y hy => (hl y hy).2), ValidUntypedA.reset hV OffR.sub hcx' hk, hUZ, CoverR.recapU (R := CovBy) (fun _ _ h => h.ut) hC' hut0 hk hks⟩, ((hz.sub OffR.sub).recapU hut hk), fun u hu p' b' i'' hc => ?_⟩, - hF.reset hT.ut hx hcx hnd' OffR.sub hcx' hk, + hF.reset hT.ut hx hcx hnd' hRin OffR.sub hcx' hk, CoverR.recapU (R := CovZ) (fun _ _ h => h.ut) (CoverR.sub CovZ.null hCZ OffR.sub hn) hut0 hk hks⟩ have g := RstF.region (OS := OS) OffR.sub hK hcx hcx' hk u hu p' b' i'' hc unfold RegionOffNodes LawfulStore.nodeBase at g ⊢ @@ -424,7 +424,7 @@ theorem untyped.reset_untyped.stZFC (hA : P0.ArchTotal ar) (hH : HeapOK H) {x p sb fi : U64} {dev : Bool} (hxs : CapSlotW H.tcbs H.omega H.frame x) (hRk : ResetOK st H Cs s x p sb fi dev) (hSt : StZ st H Cs OS s) (hF : FrameOK st H OS s) (hCZ : CoverZ st OS s) (hx : x ∈ OS) (hnd : ∀ G par, TreeA st OS G par s → ∀ y, ¬ Mdb.Desc par y x) - (hW : WuApart OS (L.ksb s)) (a : A) : + (hRin : RegionIn H p.val (p.val + 2 ^ sb.val)) (hW : WuApart OS (L.ksb s)) (a : A) : untyped.reset_untyped st ar s a x ⦃ r => (StZ st (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) Cs (OffR p.val (p.val + 2 ^ sb.val) OS) r.2.1 ∧ FrameOK st (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) (OffR p.val (p.val + 2 ^ sb.val) OS) r.2.1 ∧ @@ -437,7 +437,7 @@ theorem untyped.reset_untyped.stZFC (hA : P0.ArchTotal ar) (hH : HeapOK H) obtain ⟨hxO, -, -, -, hUZ0, -, -⟩ := reset_startS hSt.1 hx hcx hnd hNI have hV0 := hSt.1.2.2.1 have EX := fun (s' : S) (i' : U64) hf hc hi hz => - RstF.bn hO hSt hF hCZ hx hcx hnd (s := s') (i' := i') hf hc hi hz hNI + RstF.bn hO hSt hF hCZ hx hcx hnd hRin (s := s') (i' := i') hf hc hi hz hNI have hcn : untyped.RESET_CHUNK.val = 65536 := by simp [untyped.RESET_CHUNK] have hdv : 8 ∣ 2 ^ sb.val := by have : 2 ^ sb.val = 2 ^ 3 * 2 ^ (sb.val - 3) := by rw [← Nat.pow_add]; congr 1; omega diff --git a/proofs/Fl4ProofsA64/P1/MdbRunQ.lean b/proofs/Fl4ProofsA64/P1/MdbRunQ.lean index ce3c20b37..3ffee787c 100644 --- a/proofs/Fl4ProofsA64/P1/MdbRunQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbRunQ.lean @@ -188,7 +188,7 @@ theorem runBuf_of {s x : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL rw [capA_eq, hc] at hcap have hcap0 := okinj hcap have hH := I.del.heap - have hp : H ptr = some (.other bits.val) := B.sys.fr _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits + have hp : FrAt H ptr bits := B.sys.fr _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits have hFo := (B.fo _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits).1 have hb64 : 12 ≤ bits.val := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp @@ -196,7 +196,7 @@ theorem runBuf_of {s x : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL obtain ⟨hal', hin⟩ := frame_off_words hH hp hbits hsz h63 hlt hge hi show _ ∈ Ub ∧ FrBw H OS _ ∧ FrCw st OS s _ refine And.intro (I.fu _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits _ hal' hin.1 hin.2) - (And.intro (And.intro (frame_word hH hp hal' hin) (And.intro ⟨ptr, bits.val, hp, hb64, hin⟩ fun z hz g => ?_)) + (And.intro (And.intro (hp.word hH hal' hin) (And.intro (hp.frBw hb64 hin) fun z hz g => ?_)) ⟨_, hx, ptr, size, rights, x1, x2, x3, x4, bits, hcap0, hbits, hin⟩) rcases hFo z hz with g' | g' <;> omega diff --git a/proofs/Fl4ProofsA64/P1/MdbSubFrA.lean b/proofs/Fl4ProofsA64/P1/MdbSubFrA.lean new file mode 100644 index 000000000..807c7cd6a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/MdbSubFrA.lean @@ -0,0 +1,134 @@ +/- +P1 (aarch64, E0.5b): **`same_region_as` of frame caps** — the A64 twin of x86 `VsSubMdb`'s `srB_frame_iff` / +`srB_other_frame` — used by the MDB invariant after `DeriveSubframe`'s `cdt::insert` of a 4 KiB alias. + +* `sraA_frame_iff`: a frame cap `a` is `same_region_as` `b` iff `b` is a frame cap inside `a`'s range (non-wrapping). +* `sraA_nonfr_frame`: a cap that is neither a frame nor an untyped is not `same_region_as` a frame cap. +* `sraA_ut_iff`: an untyped cap is `same_region_as` `b` iff `b` is physical and inside its range (non-wrapping). +* `sraA_frame_nonfr`: a frame cap is not `same_region_as` a non-frame cap. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.MdbFrUt +import Fl4ProofsA64.P1.MdbInvInsA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +theorem sraA_frame_nonfr {a b : capability.Cap} (ha : isFrA a = true) (hb : isFrA b = false) : + sraA a b = false := by + have e := sraA_eq a b + cases a <;> simp [isFrA] at ha + cases b <;> simp [isFrA] at hb <;> (apply okinj; rw [← e]; simp [objects.same_region_as]) + +theorem sraA_nonfr_frame {a b : capability.Cap} (hu : isUtA a = false) (ha : isFrA a = false) + (hb : isFrA b = true) : sraA a b = false := by + have e := sraA_eq a b + cases b <;> simp [isFrA] at hb + cases a <;> simp [isFrA, isUtA] at ha hu <;> (apply okinj; rw [← e]; simp [objects.same_region_as]) + +/-- A frame cap's `same_region_as` of another frame cap, from the sizes' bits. -/ +theorem sraA_frame_frame {p1 p2 : U64} {sz1 sz2 : capability.FrameSize} {b1 b2 : U64} + (h1 : sz1.bits = ok b1) (h2 : sz2.bits = ok b2) + {r1 r2 a1 a2 v1 v2 : U64} {d1 d2 m1 m2 e1 e2 : Bool} : + sraA (.Frame p1 sz1 r1 d1 m1 e1 a1 v1) (.Frame p2 sz2 r2 d2 m2 e2 a2 v2) = + (decide (p1 ≤ p2) && (decide (wa p2 (mskA b2) ≤ wa p1 (mskA b1)) && decide (p2 ≤ wa p2 (mskA b2)))) := by + have e := sraA_eq (.Frame p1 sz1 r1 d1 m1 e1 a1 v1) (.Frame p2 sz2 r2 d2 m2 e2 a2 v2) + unfold objects.same_region_as at e + simp only [h1, h2, mskA_eq, lift, bind_ok] at e + apply okinj + rw [← e] + by_cases c1 : p1 ≤ p2 <;> by_cases c2 : wa p2 (mskA b2) ≤ wa p1 (mskA b1) <;> + by_cases c3 : p2 ≤ wa p2 (mskA b2) <;> simp [c1, c2, c3, ge_iff_le] + +theorem frameBits_exA (sz : capability.FrameSize) : ∃ bits, sz.bits = ok bits := by + cases sz <;> exact ⟨_, rfl⟩ + +theorem isFrA_ex {c : capability.Cap} (h : isFrA c = true) : + ∃ p sz r d m e a v, c = .Frame p sz r d m e a v := by + cases c <;> simp [isFrA] at h + exact ⟨_, _, _, _, _, _, _, _, rfl⟩ + +/-- **A frame cap is `same_region_as` `b` iff `b` is a (non-wrapping) frame cap inside its range.** -/ +theorem sraA_frame_iff {a b : capability.Cap} (ha : isFrA a = true) : + sraA a b = true ↔ isFrA b = true ∧ WithinA b a ∧ baseA b ≤ topA b := by + obtain ⟨p1, s1, r1, d1, m1, e1, a1, v1, rfl⟩ := isFrA_ex ha + by_cases hb : isFrA b = true + · obtain ⟨p2, s2, r2, d2, m2, e2, a2, v2, rfl⟩ := isFrA_ex hb + obtain ⟨c1, hc1⟩ := frameBits_exA s1 + obtain ⟨c2, hc2⟩ := frameBits_exA s2 + rw [sraA_frame_frame hc1 hc2] + have f1 := frA_size (ptr := p1) (rights := r1) (x3 := a1) (x4 := v1) (dv := d1) (x1 := m1) (x2 := e1) hc1 + have f2 := frA_size (ptr := p2) (rights := r2) (x3 := a2) (x4 := v2) (dv := d2) (x1 := m2) (x2 := e2) hc2 + simp only [WithinA, baseA, topA, f1.1, f2.1, f1.2.1, f2.2.1, Bool.and_eq_true, decide_eq_true_eq] + constructor + · rintro ⟨h1, h2, h3⟩; exact ⟨hb, ⟨h1, h2⟩, h3⟩ + · rintro ⟨-, ⟨h1, h2⟩, h3⟩; exact ⟨h1, h2, h3⟩ + · have hb' : isFrA b = false := by simpa using hb + rw [sraA_frame_nonfr (a := .Frame p1 s1 r1 d1 m1 e1 a1 v1) rfl hb'] + simp [hb] + +/-- **An untyped cap is `same_region_as` `b` iff `b` is physical and a (non-wrapping) range inside its own.** -/ +theorem sraA_ut_iff (p b i : U64) (d : Bool) (c : capability.Cap) : + sraA (.Untyped p b i d) c = true ↔ physA c = true ∧ WithinA c (.Untyped p b i d) ∧ baseA c ≤ topA c := by + rw [sraA_ut] + simp only [WithinA, baseA, topA, ptrA_ut, sizeA_ut, Bool.and_eq_true, decide_eq_true_eq] + constructor + · rintro ⟨h0, h1, h2, h3⟩; exact ⟨h0, ⟨h1, h2⟩, h3⟩ + · rintro ⟨h0, ⟨h1, h2⟩, h3⟩; exact ⟨h0, h1, h2, h3⟩ + +/-- **A cap that is neither a frame nor an untyped sees no frame cap** (re-statement for the case split). -/ +theorem sraA_kind {u b : capability.Cap} (hb : isFrA b = true) : + isUtA u = false → isFrA u = false → sraA u b = false := fun hu hf => sraA_nonfr_frame hu hf hb + +/-- **A cap `u` seeing the alias `c` sees the large frame `src`, and conversely, when `u` is disjoint from or +contains `src`** (x86 `InsFCtx.k2`'s core). -/ +theorem sraA_sub_eq {u src c : capability.Cap} (hsF : isFrA src = true) (hcF : isFrA c = true) + (hsr : baseA src ≤ topA src) (hcr : baseA c ≤ topA c) (hcin : WithinA c src) + (hno : physA u = true → DisjA u src ∨ WithinA src u) : sraA u c = sraA u src := by + by_cases hU : isUtA u = true + · obtain ⟨p, b, i, d, rfl⟩ : ∃ p b i d, u = .Untyped p b i d := by + cases u <;> simp [isUtA] at hU + exact ⟨_, _, _, _, rfl⟩ + apply Bool.eq_iff_iff.2 + rw [sraA_ut_iff, sraA_ut_iff] + have hphc := (isFrA_phys hcF).1 + have hphs := (isFrA_phys hsF).1 + rcases hno (physA_ut _ _ _ _) with hd | hw + · unfold DisjA at hd; unfold WithinA at hcin + constructor + · rintro ⟨-, ⟨h1, h2⟩, h3⟩; omega + · rintro ⟨-, ⟨h1, h2⟩, h3⟩; omega + · unfold WithinA at hw hcin + exact ⟨fun _ => ⟨hphs, hw, hsr⟩, fun _ => ⟨hphc, ⟨by omega, by omega⟩, hcr⟩⟩ + · have hU' : isUtA u = false := by simpa using hU + by_cases hF : isFrA u = true + · apply Bool.eq_iff_iff.2 + rw [sraA_frame_iff hF, sraA_frame_iff hF] + rcases hno (isFrA_phys hF).1 with hd | hw + · unfold DisjA at hd; unfold WithinA at hcin + constructor + · rintro ⟨-, ⟨h1, h2⟩, h3⟩; omega + · rintro ⟨-, ⟨h1, h2⟩, h3⟩; omega + · unfold WithinA at hw hcin + exact ⟨fun _ => ⟨hsF, hw, hsr⟩, fun _ => ⟨hcF, ⟨by omega, by omega⟩, hcr⟩⟩ + · have hF' : isFrA u = false := by simpa using hF + rw [sraA_nonfr_frame hU' hF' hcF, sraA_nonfr_frame hU' hF' hsF] + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/MdbUtR.lean b/proofs/Fl4ProofsA64/P1/MdbUtR.lean index 288156f0e..d90b5b368 100644 --- a/proofs/Fl4ProofsA64/P1/MdbUtR.lean +++ b/proofs/Fl4ProofsA64/P1/MdbUtR.lean @@ -407,7 +407,7 @@ theorem untyped.retype.stZFCRUGB (hA : P0.ArchTotal ar) {s0 s2 : S} {extra : Aen have hdn0 := UtArgs.hdn R.ty R.ext hU apply untyped.retype.resetT refine WP.spec_mono (WP.spec_and (untyped.reset_untyped.stZFC hA hH hO hb2 R.slotw hRk2 hSt2 hF2 hCZ2 hsrc hnd2 - hW2 a) (WP.spec_and (untyped.reset_untyped.wr hA hb2 R.slotw hRk2 a) + (R.ur.rin R.src R.cap) hW2 a) (WP.spec_and (untyped.reset_untyped.wr hA hb2 R.slotw hRk2 a) (resetP1Step_holds (st := st) hA H Cs Ac s2 a slot p sb fi false hb2 hRk2.1 R.slotw hpal hfit P2 hnode2 hsz))) ?_ rintro ⟨r, s1, a1⟩ ⟨⟨⟨hS1, hF1, hC1⟩, i, hci, hi0⟩, hw1, H2, Ac2, hbR, hsh, -, -⟩ dsimp only at hS1 hF1 hC1 hci hw1 hbR ⊢ diff --git a/proofs/Fl4ProofsA64/P1/MdbVcStQ.lean b/proofs/Fl4ProofsA64/P1/MdbVcStQ.lean index e4385e5b4..9eee81c50 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVcStQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVcStQ.lean @@ -86,14 +86,14 @@ theorem frU_of {s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL st H (h63 : (off &&& 63#u64) = 0#u64) (hlt : off.val < sz.val) (hge : 1024 ≤ sz.val - off.val) : FrU {b | FrBw H OS b ∧ FrCw st OS s b} (wa ptr off) := by have hH := I.del.heap - have hp : H ptr = some (.other bits.val) := B.sys.fr _ hx ptr size rights x1 x2 x3 x4 hcap bits hbits + have hp : FrAt H ptr bits := B.sys.fr _ hx ptr size rights x1 x2 x3 x4 hcap bits hbits have hFo := (B.fo _ hx ptr size rights x1 x2 x3 x4 hcap bits hbits).1 have hb64 : 12 ≤ bits.val := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp intro i hi obtain ⟨hal', hin⟩ := frame_off_words hH hp hbits hsz h63 hlt hge hi show FrBw H OS _ ∧ FrCw st OS s _ - refine And.intro (And.intro (frame_word hH hp hal' hin) (And.intro ⟨ptr, bits.val, hp, hb64, hin⟩ fun z hz g => ?_)) + refine And.intro (And.intro (hp.word hH hal' hin) (And.intro (hp.frBw hb64 hin) fun z hz g => ?_)) ⟨x, hx, ptr, size, rights, x1, x2, x3, x4, bits, hcap, hbits, hin⟩ rcases hFo z hz with g' | g' <;> omega diff --git a/proofs/Fl4ProofsA64/P1/MdbVsGaQ.lean b/proofs/Fl4ProofsA64/P1/MdbVsGaQ.lean index f22e8b5f4..7fc389d46 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVsGaQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVsGaQ.lean @@ -9,18 +9,9 @@ P1 (aarch64, gen 157): **Page GetAddress to `ArmQIAt ∧ TabKeepOrZero`** (Archi from the decode's state (MdbVcRdL's `vcpu.reply1.dfK`), closed by MdbVcArmQ's `ArmQIAt.ofDFBv`. * Top **`syscall.decode_invocation.getAddr_armQIAt`** (a `Frame` cap at `ARMPageGetAddress`: `decode_frame`'s label chain, the restart, `layout::paddr`, the reply). -* **Finding (DeriveSubframe, ruling item 2 expected 0 new premises):** `derive_subframe` (vspace.rs:1012–1041, 1071–1087) - inserts non-device `Frame (ptr + offset + (i << 12)) Small …` caps under a non-device `Large` RAM frame cap `Frame ptr - Large …` that stays in the invoked slot. MdbNHO's `FrameOK` (in `SysL.sys.fr`) asks every non-device frame cap of - `OS` to name a heap object **of its own size at its base** (`FrObj H ptr size`), so with `offset = 0` the source and - the first subframe ask `H ptr = other 21` and `H ptr = other 12` at once. **`FrameOK.sub_false`**, - **`SysL.sub_false`**, **`ArmQIAt.sub_false`**, **`ArmQI.sub_false`** mechanise this: no heap `H'` and slot set - containing both slots satisfies `SysL`, so `ArmQIAt` (and `ArmQI`) is false after a successful DeriveSubframe at - offset 0 into a CNode slot of `OS`. Not added to `DecArmQH`. -* (gen 158, Architect 14:29Z, ruling item 2, option (b)) **DeriveSubframe (an FL4 extension) is excluded from - `DecArmQH` / `armQHAt`**: the exact-size `FrObj` of `FrameOK` cannot hold for a subframe beside its source (the four - lemmas below). The follow-up — generalising `FrObj` to containment inside an `.other b` heap object at a - size-aligned offset — is scheduled after the VSpace closure; it is not started. +* **DeriveSubframe finding (history):** with the exact-size `FrObj`, a subframe cap beside its source made `ArmQIAt` false + (four `sub_false` lemmas, removed in Stage 5 E0.1: they were unused). `FrameOK` now reads a frame range through the + `FrAt` accessors, so E0.2 can swap in containment in an `.other b` object and DeriveSubframe joins `DecArmQH`. (A64-S1A gen 40, Architect ruling for gen 40, R3) `restart_reply_armQ` and `getAddr_armQIAt` also post `ArmVsK` (last conjunct; MdbVcArmQ's `ofDFBv`). @@ -148,50 +139,6 @@ theorem syscall.decode_invocation.getAddr_armQIAt {s : S} WP.spec_mono (syscall.decode_invocation.getAddr_armSAt I D P B Y hks a hl len blk call don fp' buf) fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ -/-! ## DeriveSubframe: the finding -/ - -/-- **`FrameOK` holds no non-device `Large` frame cap beside a non-device `Small` one at the same base** -(module docstring). DeriveSubframe (FL4 extension) is excluded from `DecArmQH` / `armQHAt` because the exact-size `FrObj` cannot hold for -subframes (gen 158, ruling item 2 (b)); the follow-up (`FrObj` as containment in an `.other b` object) is scheduled -after the VSpace closure. -/ -theorem FrameOK.sub_false {OS' : Set U64} {H' : Heap} {s : S} (h : FrameOK st H' OS' s) {y1 y2 p r1 r2 x1 x2 : U64} - {m1 e1 m2 e2 : Bool} {v1 v2 : U64} (hy1 : y1 ∈ OS') (hy2 : y2 ∈ OS') - (c1 : capA st s y1 = .Frame p .Large r1 false m1 e1 x1 v1) - (c2 : capA st s y2 = .Frame p .Small r2 false m2 e2 x2 v2) : False := by - have k1 := h y1 hy1 _ _ _ _ _ _ _ c1 21#u64 (by simp [capability.FrameSize.bits]) - have k2 := h y2 hy2 _ _ _ _ _ _ _ c2 12#u64 (by simp [capability.FrameSize.bits]) - rw [k1] at k2 - simp at k2 - -/-- `SysL` at any heap and slot set excludes the pair (`SysL.sys.fr`). DeriveSubframe (FL4 extension) is excluded from `DecArmQH` / `armQHAt` because the exact-size `FrObj` cannot hold for -subframes (gen 158, ruling item 2 (b)); the follow-up (`FrObj` as containment in an `.other b` object) is scheduled -after the VSpace closure. -/ -theorem SysL.sub_false {OS' : Set U64} {H' : Heap} {s : S} (B : SysL st H' Cs OS' ia ie s) - {y1 y2 p r1 r2 x1 x2 : U64} {m1 e1 m2 e2 : Bool} {v1 v2 : U64} (hy1 : y1 ∈ OS') (hy2 : y2 ∈ OS') - (c1 : capA st s y1 = .Frame p .Large r1 false m1 e1 x1 v1) - (c2 : capA st s y2 = .Frame p .Small r2 false m2 e2 x2 v2) : False := - B.sys.fr.sub_false hy1 hy2 c1 c2 - -/-- **`ArmQIAt` is false at a state holding the pair in two `OS` slots** (module docstring). DeriveSubframe (FL4 extension) is excluded from `DecArmQH` / `armQHAt` because the exact-size `FrObj` cannot hold for -subframes (gen 158, ruling item 2 (b)); the follow-up (`FrObj` as containment in an `.other b` object) is scheduled -after the VSpace closure. -/ -theorem ArmQIAt.sub_false {s0 s : S} (h : ArmQIAt st H Cs OS Vc ia ie s0 s) - {y1 y2 p r1 r2 x1 x2 : U64} {m1 e1 m2 e2 : Bool} {v1 v2 : U64} (hy1 : y1 ∈ OS) (hy2 : y2 ∈ OS) - (c1 : capA st s y1 = .Frame p .Large r1 false m1 e1 x1 v1) - (c2 : capA st s y2 = .Frame p .Small r2 false m2 e2 x2 v2) : False := - h.1.sub_false hy1 hy2 c1 c2 - -/-- **`ArmQI` is false at a state holding the pair in two slots of its end slot set** (`∀ H' OS'`). DeriveSubframe (FL4 extension) is excluded from `DecArmQH` / `armQHAt` because the exact-size `FrObj` cannot hold for -subframes (gen 158, ruling item 2 (b)); the follow-up (`FrObj` as containment in an `.other b` object) is scheduled -after the VSpace closure. -/ -theorem ArmQI.sub_false {s0 s : S} - {y1 y2 p r1 r2 x1 x2 : U64} {m1 e1 m2 e2 : Bool} {v1 v2 : U64} - (c1 : capA st s y1 = .Frame p .Large r1 false m1 e1 x1 v1) - (c2 : capA st s y2 = .Frame p .Small r2 false m2 e2 x2 v2) : - ¬ ∃ (H' : Heap) (OS' : Set U64), y1 ∈ OS' ∧ y2 ∈ OS' ∧ ArmQIEnd st H Cs OS Vc ia ie s0 H' OS' s := by - rintro ⟨H', OS', hy1, hy2, h⟩ - exact h.1.sub_false hy1 hy2 c1 c2 - end ST end R end W7 diff --git a/proofs/Fl4ProofsA64/P1/MdbVsMapB.lean b/proofs/Fl4ProofsA64/P1/MdbVsMapB.lean index da0db1945..843af2c8d 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVsMapB.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVsMapB.lean @@ -196,11 +196,10 @@ theorem frame_al4k {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {x : U6 {sz : capability.FrameSize} {m e : Bool} (hc : capA st s x = .Frame p sz r false m e a v) : p.val % 4096 = 0 := by obtain ⟨bits, hb⟩ : ∃ bits : U64, sz.bits = ok bits := by cases sz <;> exact ⟨_, rfl⟩ - have hp : H p = some (.other bits.val) := B.sys.fr _ hx p sz r m e a v hc bits hb + have hp : FrAt H p bits := B.sys.fr _ hx p sz r m e a v hc bits hb have h12 : 12 ≤ bits.val := by cases sz <;> simp only [capability.FrameSize.bits] at hb <;> rw [← okinj hb] <;> simp - have hal := hH.align p _ hp - simp only [HKind.bits] at hal + have hal := hp.al hH have hP : 2 ^ bits.val = 4096 * 2 ^ (bits.val - 12) := by rw [show (4096 : Nat) = 2 ^ 12 from rfl, ← Nat.pow_add]; congr 1; omega rw [hP] at hal diff --git a/proofs/Fl4ProofsA64/P1/MdbXferQ.lean b/proofs/Fl4ProofsA64/P1/MdbXferQ.lean index 42775ea3f..19b0bb9aa 100644 --- a/proofs/Fl4ProofsA64/P1/MdbXferQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbXferQ.lean @@ -190,13 +190,12 @@ theorem lookup_bufKC {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {ct : simp only [bind_ok, lift] refine WP.spec_bind (shl1_val hb64) fun size1 hs1 => ?_ refine (WP.spec_ok _).2 fun _ => ?_ - have hp : H ptr = some (.other bits.val) := B.sys.fr _ hx ptr sz r m ep asid va hcp bits hb + have hp : FrAt H ptr bits := B.sys.fr _ hx ptr sz r m ep asid va hcp bits hb have hFo := (B.fo _ hx ptr sz r m ep asid va hcp bits hb).1 have h12 : 12 ≤ bits.val := by cases sz <;> simp only [capability.FrameSize.bits] at hb <;> rw [← okinj hb] <;> simp - have hf := hH.fits ptr _ hp - have hal := hH.align ptr _ hp - simp only [HKind.bits] at hf hal + have hf := hp.fits hH + have hal := hp.al hH have hP : 2 ^ bits.val = 1024 * 2 ^ (bits.val - 10) := by rw [show (1024 : Nat) = 2 ^ 10 from rfl, ← Nat.pow_add]; congr 1; omega have hP4 : 4 ≤ 2 ^ (bits.val - 10) := by @@ -219,11 +218,15 @@ theorem lookup_bufKC {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {ct : have hv : (wa ptr o).val = ptr.val + o.val := by simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega have hQ : o.val + 1024 ≤ 1024 * Q := by omega - refine ⟨⟨by rw [hv]; omega, ptr, bits.val, hp, by rw [hv]; omega, by rw [hv, hP]; omega, fun y hy => ?_⟩, - ⟨ptr, bits.val, hp, h12, by rw [hv]; omega, by rw [hv, hP]; omega⟩, + obtain ⟨q, z, hq, hbz, hq1, hq2⟩ := hp.obj + rw [hP] at hq2 + refine ⟨⟨by rw [hv]; omega, q, z, hq, by rw [hv]; omega, by rw [hv]; omega, fun y hy => ?_⟩, + ⟨q, z, hq, by omega, by rw [hv]; omega, by rw [hv]; omega⟩, fun v g1 g2 => ⟨sbA ct, hx, ptr, sz, r, m, ep, asid, va, bits, hcp, hb, by rw [hv] at g1; omega, by rw [hv] at g2; rw [hP]; omega⟩⟩ - rw [hP]; exact hFo y hy + have := hFo y hy + rw [hv] + omega /-- **`lookup_ipc_buffer` of a thread on `SysL`: `0` or a `BufIn ∧ BufK` buffer** (MdbRegRL's `lookup_bufIn` text, the frame object's size kept; A64-S1A gen 30: `lookup_bufKC`'s projection). -/ diff --git a/proofs/Fl4ProofsA64/P1/S1aBootU.lean b/proofs/Fl4ProofsA64/P1/S1aBootU.lean index e21a5d0c3..fd64971b3 100644 --- a/proofs/Fl4ProofsA64/P1/S1aBootU.lean +++ b/proofs/Fl4ProofsA64/P1/S1aBootU.lean @@ -55,6 +55,24 @@ theorem HeapOK.off12 (hH : HeapOK H) {p q : U64} {k : HKind} (hp : H p = some (. have g := hH.disj q k p _ hq hp hne rwa [show (HKind.other 12).bits = 12 from rfl, show (2 : Nat) ^ 12 = 4096 by norm_num] at g +/-- A frame range (`12 ≤ bits`) is disjoint from a distinct 4 KiB `.other` object `p`. -/ +theorem FrAt.off12 {ptr bits p : U64} (hH : HeapOK H) (h : FrAt H ptr bits) (h12 : 12 ≤ bits.val) + (hp : H p = some (.other 12)) (e : ptr ≠ p) : ptr.val + 2 ^ bits.val ≤ p.val ∨ p.val + 4096 ≤ ptr.val := by + obtain ⟨b, k, hb, -, h1, h2⟩ := h.obj + by_cases hbp : b = p + · subst hbp + rw [hb] at hp + have hk : k = 12 := HKind.other.inj (Option.some.inj hp) + subst hk + have h3 : 2 ^ 12 ≤ 2 ^ bits.val := Nat.pow_le_pow_right (by norm_num) h12 + have h4 : ptr.val ≠ b.val := fun h => e (UScalar.eq_of_val_eq h) + norm_num at h3 h2 + omega + · have g := HeapOK.off12 hH hp hb hbp + simp only [HKind.bits] at g + norm_num at g + omega + /-- An aligned word of an `other` object is an `Ω` word and not an `Sg` word. -/ theorem HeapOK.otherW (hH : HeapOK H) {p b : U64} {z : Nat} (hp : H p = some (.other z)) (hal : Aligned b) (h1 : p.val ≤ b.val) (h2 : b.val < p.val + 2 ^ z) : b ∈ H.omega ∧ b ∉ H.frame := by @@ -79,7 +97,8 @@ theorem UbFr.inOther (hF : FrameOK st H OS s) (hU : UbFr st OS Ub s) : ∀ b ∈ Ub, ∃ q z, H q = some (.other z) ∧ q.val ≤ b.val ∧ b.val < q.val + 2 ^ z := by intro b hb obtain ⟨y, hy, ptr, size, rights, x1, x2, x3, x4, bits, hc, hbits, h1, h2⟩ := hU b hb - exact ⟨ptr, bits.val, hF y hy ptr size rights x1 x2 x3 x4 hc bits hbits, h1, h2⟩ + obtain ⟨q, z, hq, hbz, hq1, hq2⟩ := (hF y hy ptr size rights x1 x2 x3 x4 hc bits hbits).obj + exact ⟨q, z, hq, by omega, by omega⟩ /-- **`Ub` is off a 4 KiB `other` object no frame cap names** (a pool or a page table). -/ theorem UbFr.offObj (hH : HeapOK H) (hF : FrameOK st H OS s) (hU : UbFr st OS Ub s) {p : U64} @@ -90,8 +109,9 @@ theorem UbFr.offObj (hH : HeapOK H) (hF : FrameOK st H OS s) (hU : UbFr st OS Ub obtain ⟨y, hy, ptr, size, rights, x1, x2, x3, x4, bits, hc, hbits, h1, h2⟩ := hU b hb have hq := hF y hy ptr size rights x1 x2 x3 x4 hc bits hbits have e : ptr ≠ p := by rintro rfl; exact hne y hy size rights x1 x2 x3 x4 hc - have g := HeapOK.off12 hH hp hq e - rw [show (HKind.other bits.val).bits = bits.val from rfl] at g + have h12 : 12 ≤ bits.val := by + cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp + have g := hq.off12 hH h12 hp e rcases g with g | g <;> omega /-- **Boot (`Ub`): `NtOffU`**, derived: a frame is an `other` object, disjoint from every notification. -/ diff --git a/proofs/Fl4ProofsA64/P1/S1aBootV.lean b/proofs/Fl4ProofsA64/P1/S1aBootV.lean index 3693a0306..7f32ddd69 100644 --- a/proofs/Fl4ProofsA64/P1/S1aBootV.lean +++ b/proofs/Fl4ProofsA64/P1/S1aBootV.lean @@ -51,16 +51,10 @@ theorem UbFr.usrW (hH : HeapOK H) (hF : FrameOK st H OS s) (hU : UbFr st OS Ub s ∀ b ∈ Ub, UsrW st H.tcbs Cs H H.frame H.scs H.scBits s b := by intro b hb obtain ⟨y, hy, ptr, size, rights, x1, x2, x3, x4, bits, hc, hbits, h1, h2⟩ := hU b hb - have hq : H ptr = some (.other bits.val) := hF y hy ptr size rights x1 x2 x3 x4 hc bits hbits + have hq : FrAt H ptr bits := hF y hy ptr size rights x1 x2 x3 x4 hc bits hbits have hrk := (hfo y hy ptr size rights x1 x2 x3 x4 hc bits hbits).2 have off : ∀ q k, H q = some k → (∀ z, k ≠ .other z) → - q.val + 2 ^ k.bits ≤ ptr.val ∨ ptr.val + 2 ^ bits.val ≤ q.val := fun q k hk hn => by - have e : q ≠ ptr := by - rintro rfl - rw [hq] at hk - exact hn _ (Option.some.inj hk).symm - have g := hH.disj q k ptr _ hk hq e - rwa [show (HKind.other bits.val).bits = bits.val from rfl] at g + q.val + 2 ^ k.bits ≤ ptr.val ∨ ptr.val + 2 ^ bits.val ≤ q.val := fun q k hk hn => hq.disjK hH hk hn have hb8 : b.val % 8 = 0 := hal b hb refine ⟨⟨hal b hb, fun t ht => ?_, fun c hc => ?_⟩, fun e he => ?_, (UbFr.omega hH hF hU hal b hb).2, fun o ho _ => ?_, fun c hc => ?_⟩ diff --git a/proofs/Fl4ProofsA64/P1/S1aCFinish.lean b/proofs/Fl4ProofsA64/P1/S1aCFinish.lean index d41d51cd2..841099128 100644 --- a/proofs/Fl4ProofsA64/P1/S1aCFinish.lean +++ b/proofs/Fl4ProofsA64/P1/S1aCFinish.lean @@ -232,7 +232,7 @@ theorem runBuf_of' {Ub : Set U64} {s x : S} (hH : HeapOK H) (fu : FrUb st Ub OS subst hdev rw [capA_eq, hc] at hcap have hcap0 := okinj hcap - have hp : H ptr = some (.other bits.val) := B.sys.fr _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits + have hp : FrAt H ptr bits := B.sys.fr _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits have hFo := (B.fo _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits).1 have hb64 : 12 ≤ bits.val := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp @@ -240,7 +240,7 @@ theorem runBuf_of' {Ub : Set U64} {s x : S} (hH : HeapOK H) (fu : FrUb st Ub OS obtain ⟨hal', hin⟩ := frame_off_words hH hp hbits hsz h63 hlt hge hi show _ ∈ Ub ∧ FrBw H OS _ ∧ FrCw st OS s _ refine And.intro (fu _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits _ hal' hin.1 hin.2) - (And.intro (And.intro (frame_word hH hp hal' hin) (And.intro ⟨ptr, bits.val, hp, hb64, hin⟩ fun z hz g => ?_)) + (And.intro (And.intro (hp.word hH hal' hin) (And.intro (hp.frBw hb64 hin) fun z hz g => ?_)) ⟨_, hx, ptr, size, rights, x1, x2, x3, x4, bits, hcap0, hbits, hin⟩) rcases hFo z hz with g' | g' <;> omega diff --git a/proofs/Fl4ProofsA64/P1/S1aKTab.lean b/proofs/Fl4ProofsA64/P1/S1aKTab.lean index 033236185..131f3ea8b 100644 --- a/proofs/Fl4ProofsA64/P1/S1aKTab.lean +++ b/proofs/Fl4ProofsA64/P1/S1aKTab.lean @@ -236,7 +236,7 @@ theorem SysL.addKt {ia ie : Nat} (X : KtOut st H Cs OS Vc Ub Kt s) (B : SysL st have h0 : KtH H Kt 0#u64 = H 0#u64 := Heap.add_of_not (H := H) (N := (· ∈ Kt)) (kd := .other 12) (q := 0#u64) fun h => X.nz _ h rfl exact ⟨⟨⟨⟨B.sys.stz.1.1, B.sys.stz.1.2.1, hV, B.sys.stz.1.2.2.2.1, B.sys.stz.1.2.2.2.2⟩, B.sys.stz.2.1, - B.sys.stz.2.2⟩, fun y hy ptr size r x1 x2 x3 x4 hc bits hbt => hg _ _ (B.sys.fr y hy ptr size r x1 x2 x3 x4 hc + B.sys.stz.2.2⟩, fun y hy ptr size r x1 x2 x3 x4 hc bits hbt => FrAt.mono hg (B.sys.fr y hy ptr size r x1 x2 x3 x4 hc bits hbt), B.sys.cz, hUR⟩, hLN, hVR, ⟨h0.trans B.ly.h0, B.ly.ksw, B.ly.idleIn, B.ly.idleScIn, B.ly.idleOff, B.ly.ut0, B.ly.kslo⟩, fun y hy => CnOP.grow hg (B.cn y hy), fun y hy hB => B.bh y hy (by rw [eT] at hB; exact hB), B.ci, diff --git a/proofs/Fl4ProofsA64/P1/S1aKtPoolArms.lean b/proofs/Fl4ProofsA64/P1/S1aKtPoolArms.lean index ce697d940..e75dd23d9 100644 --- a/proofs/Fl4ProofsA64/P1/S1aKtPoolArms.lean +++ b/proofs/Fl4ProofsA64/P1/S1aKtPoolArms.lean @@ -57,7 +57,7 @@ theorem syscall.decode_invocation.makePool_kt (q = s) ∨ ∃ (p sb : U64), S1aHiKeep st OS (OffR p.val (p.val + 2 ^ sb.val) OS) Kt s q ⦄ := by refine WP.spec_mono (syscall.decode_invocation.makePoolEndR2 D P B Y vr covered hks h sep a label len blk call don fp buf) ?_ - rintro ⟨_, q, _⟩ (⟨same, _⟩ | ⟨x, v, p, sb, fi, i, base, Pt', Pp', Tb', Te', hx, source, size, childless, post, + rintro ⟨_, q, _⟩ (⟨same, _⟩ | ⟨x, v, p, sb, fi, i, base, Pp', Tb', Te', hx, source, size, childless, post, others, _⟩) · exact Or.inl same refine Or.inr ⟨p, sb, EdgeKeepOn.ofKept fun b hb e => ?_, fun y hy R m a c => ?_⟩ diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AddPool.lean b/proofs/Fl4ProofsA64/P1/S1aR2AddPool.lean index 575fbcbcc..ffb666cbc 100644 --- a/proofs/Fl4ProofsA64/P1/S1aR2AddPool.lean +++ b/proofs/Fl4ProofsA64/P1/S1aR2AddPool.lean @@ -385,11 +385,11 @@ theorem S1aR2.addPool {x v p sb fi base i : U64} (h : S1aR2 st H O Pt Pp Tb Hr T have live := keepCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e) refine ⟨y, hy, sz, rights, device, address, size, live, ref, ?_⟩ cases device - · have placed := frames y hy _ sz rights _ _ _ _ live _ size + · obtain ⟨pq, pz, pH, -, p1, p2⟩ := (frames y hy _ sz rights _ _ _ _ live _ size).obj have exponent : (⟨BitVec.ofNat 64 sh⟩ : U64).val = sh := by rcases before.geometry.1 with e | e | e | e <;> rw [e] <;> rfl - rw [exponent] at placed - exact Or.inr ⟨_, _, placed, le_rfl, le_rfl⟩ + rw [exponent] at p2 + exact Or.inr ⟨pq, pz, pH, p1, p2⟩ · exact Or.inl rfl have typedHeap : TeH (PoolH H p sb.val) Te Re bits n := fun t member => ⟨E.grow (h.core.heap t member).1, (h.core.heap t member).2⟩ diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameBacking.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameBacking.lean index 6d00a333c..adce6dd90 100644 --- a/proofs/Fl4ProofsA64/P1/S1aR2FrameBacking.lean +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameBacking.lean @@ -71,7 +71,8 @@ theorem S1aFrameMap.backing {f : vspace.FrameCap} (effect : S1aFrameMap st OS Pt cases isDevice : f.is_device · have object := ram slot member f.ptr f.size f.rights f.mapped f.is_ept f.asid f.vaddr (by simpa only [isDevice] using old) shift size - exact Or.inr ⟨f.ptr, shift.val, object, le_rfl, le_rfl⟩ + obtain ⟨pq, pz, pH, -, p1, p2⟩ := object.obj + exact Or.inr ⟨pq, pz, pH, p1, p2⟩ · exact Or.inl rfl · have keep := write.memory _ (Or.inl (h.pathWord prior bound al)) selectedWord rw [keep] at valid ⊢ diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MakePool.lean b/proofs/Fl4ProofsA64/P1/S1aR2MakePool.lean index a0bdb671f..0fd738bbb 100644 --- a/proofs/Fl4ProofsA64/P1/S1aR2MakePool.lean +++ b/proofs/Fl4ProofsA64/P1/S1aR2MakePool.lean @@ -30,7 +30,7 @@ theorem syscall.decode_invocation.makePoolEndR2 {U Ac Vc Ub : Set U64} (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot .AsidControl blk call don fp buf extra ⦃ _ q _ => (q = s ∧ S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q ∧ S1aKtUt st OS Kt q) ∨ - ∃ (x v p sb fi i base : U64) (Pt' Pp' Tb' Te' : Set U64), x ∈ OS ∧ capA st s x = .Untyped p sb fi false ∧ + ∃ (x v p sb fi i base : U64) (Pp' Tb' Te' : Set U64), x ∈ OS ∧ capA st s x = .Untyped p sb fi false ∧ sb = fl4_abi.consts.bits.ASID_POOL ∧ cdt.ensure_no_children st s x = ok (core.result.Result.Ok ()) ∧ PoolPost st H OS s q x v p sb i base ∧ (∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → @@ -38,7 +38,7 @@ theorem syscall.decode_invocation.makePoolEndR2 {U Ac Vc Ub : Set U64} ArmQIEnd st H Cs OS Vc ia ie s (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val) (OffR p.val (p.val + 2 ^ sb.val) OS) q ∧ S1aR2 st (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val) (OffR p.val (p.val + 2 ^ sb.val) OS) - Pt' Pp' Tb' (HvRt st (OffR p.val (p.val + 2 ^ sb.val) OS) q) Te' Kt Lv Re bits n q ∧ + (insert p (s1aKeptPt (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) Pt)) Pp' Tb' (HvRt st (OffR p.val (p.val + 2 ^ sb.val) OS) q) Te' Kt Lv Re bits n q ∧ S1aKtUt st (OffR p.val (p.val + 2 ^ sb.val) OS) Kt q ⦄ := by refine WP.spec_mono (syscall.decode_invocation.makePoolLIEAtX D P B Y vr covered a label len blk call don fp buf) ?_ rintro ⟨_, q, _⟩ (⟨same, _⟩ | ⟨x, hx, _, p, sb, fi, source, size, childless, v, i, base, small, low, free, post, @@ -91,9 +91,9 @@ theorem syscall.decode_invocation.makePoolEndR2 {U Ac Vc Ub : Set U64} (OffR p.val (p.val + 2 ^ sb.val) OS) Kt s := ⟨P.heap, fun t k obj => (drop obj).2, fun _ member => member.1, nonnull, survive⟩ have frames : FrameOK st (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) (OffR p.val (p.val + 2 ^ sb.val) OS) s := - FrameOK.reset_start B.sys.stz.1.1 B.sys.fr hx source fun G par tree => + FrameOK.reset_start B.sys.stz.1.1 B.sys.fr hx source (fun G par tree => tree.noDescN hx source (cdt.ensure_no_children.out P.os source - (B.sys.stz.1.2.1 x hx (by rw [source]; rfl)) childless) + (B.sys.stz.1.2.1 x hx (by rw [source]; rfl)) childless)) region obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS have shrunk := h.restrict restriction kinds frames have after : SysL st (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val) Cs @@ -150,7 +150,7 @@ theorem syscall.decode_invocation.makePoolEndR2 {U Ac Vc Ub : Set U64} by_cases first : y = x · exact Or.inr (first.symm ▸ ⟨_, _, _, _, sourceAfter⟩) · exact Or.inl (kept y hy first second) - refine Or.inr ⟨x, v, p, sb, fi, i, base, _, _, _, _, hx, source, size, childless, post, others, E, final, ?_⟩ + refine Or.inr ⟨x, v, p, sb, fi, i, base, _, _, _, hx, source, size, childless, post, others, E, final, ?_⟩ intro t member u hu p' b' i' d' cap by_cases first : u = x · rw [first, sourceAfter] at cap @@ -180,7 +180,7 @@ theorem syscall.decode_invocation.makePoolExactR2 {U Ac Vc Ub : Set U64} S1aR2 st H' OS' Pt' Pp' Tb' (HvRt st OS' q) Te' Kt Lv Re bits n q ∧ S1aKtUt st OS' Kt q ⦄ := by refine WP.spec_mono (syscall.decode_invocation.makePoolEndR2 D P B Y vr covered hks h sep a label len blk call don fp buf) ?_ - rintro ⟨_, q, _⟩ (same | ⟨_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, E, final, kt⟩) + rintro ⟨_, q, _⟩ (same | ⟨_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, E, final, kt⟩) · exact Or.inl same · exact Or.inr ⟨_, _, _, _, _, _, E, final, kt⟩ diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapWalk.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapWalk.lean index 12ded03b9..421b7ebe8 100644 --- a/proofs/Fl4ProofsA64/P1/S1aR2MapWalk.lean +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapWalk.lean @@ -98,7 +98,7 @@ theorem s1aFrameAligned (heap : HeapOK H) (ram : FrameOK st H OS s) (device : De (hx : x ∈ OS) (cap : capA st s x = .Frame p sz rights dev mapped ept asid va) (size : sz.bits = ok bits) : p.val % 2 ^ bits.val = 0 := by cases dev - · exact heap.align p (.other bits.val) (ram x hx p sz rights mapped ept asid va cap bits size) + · exact (ram x hx p sz rights mapped ept asid va cap bits size).al heap · exact device x hx p sz rights mapped ept asid va cap bits size end frame diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Restrict.lean b/proofs/Fl4ProofsA64/P1/S1aR2Restrict.lean index 94174f3c8..863c02986 100644 --- a/proofs/Fl4ProofsA64/P1/S1aR2Restrict.lean +++ b/proofs/Fl4ProofsA64/P1/S1aR2Restrict.lean @@ -234,11 +234,11 @@ theorem S1aR2.restrict (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) have live := E.keep hx cap (fun e => by cases e) refine ⟨x, live, sz, rights, device, address, size, cap, ref, ?_⟩ cases device - · have placed := frames x live _ sz rights _ _ _ _ cap _ size + · obtain ⟨pq, pz, pH, -, p1, p2⟩ := (frames x live _ sz rights _ _ _ _ cap _ size).obj have exponent : (⟨BitVec.ofNat 64 sh⟩ : U64).val = sh := by rcases path.geometry.1 with e | e | e | e <;> rw [e] <;> rfl - rw [exponent] at placed - exact Or.inr ⟨_, _, placed, le_rfl, le_rfl⟩ + rw [exponent] at p2 + exact Or.inr ⟨pq, pz, pH, p1, p2⟩ · exact Or.inl rfl have typedHeap : TeH H' {t | t ∈ Te ∧ H' t = some (.other (bits t))} Re bits n := fun t member => ⟨member.2, (h.core.heap t member.1).2⟩ diff --git a/proofs/Fl4ProofsA64/P1/S1aR2RetypePost.lean b/proofs/Fl4ProofsA64/P1/S1aR2RetypePost.lean index fbf26c43e..a28d6f81d 100644 --- a/proofs/Fl4ProofsA64/P1/S1aR2RetypePost.lean +++ b/proofs/Fl4ProofsA64/P1/S1aR2RetypePost.lean @@ -644,11 +644,11 @@ theorem r2 (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt s obtain ⟨member, same⟩ := keepCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) refine ⟨x, member, sz, rights, device, address, size, same, ref, ?_⟩ cases device - · have placed := frames x member _ sz rights _ _ _ _ same _ size + · obtain ⟨pq, pz, pH, -, p1, p2⟩ := (frames x member _ sz rights _ _ _ _ same _ size).obj have exponent : (⟨BitVec.ofNat 64 sh⟩ : U64).val = sh := by rcases before.geometry.1 with e | e | e | e <;> rw [e] <;> rfl - rw [exponent] at placed - exact Or.inr ⟨_, _, placed, le_rfl, le_rfl⟩ + rw [exponent] at p2 + exact Or.inr ⟨pq, pz, pH, p1, p2⟩ · exact Or.inl rfl have highLink : ∀ R ∈ HvRt st (s1aRtSlots OS1 dev nt us aligned win) q, wa (L.mem q (wa R 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE = wa R 4096#u64 := by diff --git a/proofs/Fl4ProofsA64/P1/S1aStepR2.lean b/proofs/Fl4ProofsA64/P1/S1aStepR2.lean index d8cb3ae48..07ba31641 100644 --- a/proofs/Fl4ProofsA64/P1/S1aStepR2.lean +++ b/proofs/Fl4ProofsA64/P1/S1aStepR2.lean @@ -275,7 +275,7 @@ theorem syscall.decode_invocation.s1aStepR2 (hA : P0.ArchTotal ar) (hM : MaxSpi · refine WP.spec_mono (syscall.decode_invocation.makePoolEndR2 D P B Y I.del.vr hSC hks R sep a hl len blk call don fp buf) fun r d => ?_ obtain ⟨_, s', _⟩ := r - rcases d with ⟨rfl, R', sep'⟩ | ⟨x, v, p, sb, fi, i, base, Pt', Pp', Tb', Te', hx, source, size, childless, post, + rcases d with ⟨rfl, R', sep'⟩ | ⟨x, v, p, sb, fi, i, base, Pp', Tb', Te', hx, source, size, childless, post, others, E, R', sep'⟩ · exact S1aStepR2.ofR2 B Y (Set.Subset.refl _) I.vcc C Kc Df sep' R' · have column := S1aArmCol.poolEnd P B I.del.vr C Kc hal hx source size childless post E diff --git a/proofs/Fl4ProofsA64/P1/S1aStepR2A.lean b/proofs/Fl4ProofsA64/P1/S1aStepR2A.lean index 2536631d7..84c12dac5 100644 --- a/proofs/Fl4ProofsA64/P1/S1aStepR2A.lean +++ b/proofs/Fl4ProofsA64/P1/S1aStepR2A.lean @@ -348,7 +348,7 @@ theorem syscall.decode_invocation.s1aStepR2A (hA : P0.ArchTotal ar) (hM : MaxSpi · refine WP.spec_mono (syscall.decode_invocation.makePoolEndR2 D P B Y I.del.vr hSC hks R sep a hl len blk call don fp buf) fun r d => ?_ obtain ⟨_, s', _⟩ := r - rcases d with ⟨rfl, R', sep'⟩ | ⟨x, v, p, sb, fi, i, base, Pt', Pp', Tb', Te', hx, source, size, childless, post, + rcases d with ⟨rfl, R', sep'⟩ | ⟨x, v, p, sb, fi, i, base, Pp', Tb', Te', hx, source, size, childless, post, others, E, R', sep'⟩ · exact S1aStepR2.ofR2 B Y (Set.Subset.refl _) I.vcc C Kc Df sep' R' · have column := S1aArmCol.poolEnd P B I.del.vr C Kc hal hx source size childless post E diff --git a/proofs/Fl4ProofsA64/P1/S1aStepR2K.lean b/proofs/Fl4ProofsA64/P1/S1aStepR2K.lean index c130fc3cf..784a27ac2 100644 --- a/proofs/Fl4ProofsA64/P1/S1aStepR2K.lean +++ b/proofs/Fl4ProofsA64/P1/S1aStepR2K.lean @@ -252,7 +252,7 @@ theorem syscall.decode_invocation.s1aStepR2K (hA : P0.ArchTotal ar) (hM : MaxSpi · refine WP.spec_mono (syscall.decode_invocation.makePoolEndR2 D P B Y I.del.vr hSC hks R sep a hl len blk call don fp buf) fun r d => ?_ obtain ⟨_, s', _⟩ := r - rcases d with ⟨rfl, R', sep'⟩ | ⟨x, v, p, sb, fi, i, base, Pt', Pp', Tb', Te', hx, source, size, childless, post, + rcases d with ⟨rfl, R', sep'⟩ | ⟨x, v, p, sb, fi, i, base, Pp', Tb', Te', hx, source, size, childless, post, others, E, R', sep'⟩ · exact S1aStepR2K.ofR2 B Y (Set.Subset.refl _) I.vcc C Kc Df sep' R' KC · have column := S1aArmCol.poolEnd P B I.del.vr C Kc hal hx source size childless post E diff --git a/proofs/Fl4ProofsA64/P1/S1aSubArm.lean b/proofs/Fl4ProofsA64/P1/S1aSubArm.lean new file mode 100644 index 000000000..e5f34beb6 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aSubArm.lean @@ -0,0 +1,194 @@ +/- +P1 (aarch64, E0.4): **Page DeriveSubframe to `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ SubSlots`** (Stage 5 E0.4). + +`vspace.derive_subframe`'s walk (argument checks, `subframe_dest`, `ensure_empty_run`, the caller's restart, then +`insert_subframes`) over the decode's state: every error leaf is `ArmQIAt.ofPR` at the unchanged state; the success +path is MdbIrqCQ's restart step followed by S1aSubLoop's `insert_subframes.subS`, whose hypotheses come from the +argument checks (S1aSubGeo) and the destination run (S1aSubDest, S1aSubRun). + +* **`vspace.derive_subframe.armSAt`**, top **`syscall.decode_invocation.deriveSub_armSAt`** (a `Frame` cap at + `ARMPageDeriveSubframe`: `decode_frame`'s label chain). + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aSubGeo +import Fl4ProofsA64.P1.S1aSubRun +import Fl4ProofsA64.P1.MdbVsGaQ +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} +variable {Cs : Set U64} {Ac U : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} +variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-! ## Small value lemmas -/ + +theorem shl21_val : (1#u64 <<< 21#i32 : Result U64) ⦃ z => z.val = 2097152 ⦄ := by + rw [CapRt.shl_eq 1#u64 21#i32 (by decide) (by decide), WP.spec_ok] + rfl + +theorem shr12_val {x : U64} : (x >>> 12#i32 : Result U64) ⦃ z => z.val = x.val / 4096 ⦄ := by + rw [CapRt.shr_eq x 12#i32 (by decide) (by decide), WP.spec_ok] + show (x.bv >>> (12#i32 : I32).toNat).toNat = x.val / 4096 + rw [BitVec.toNat_ushiftRight] + have e : (12#i32 : I32).toNat = 12 := by decide + rw [e, Nat.shiftRight_eq_div_pow] + rfl + +theorem and4095_val {x : U64} : (x &&& 4095#u64).val = x.val % 4096 := by + rw [UScalar.val_and, show (4095#u64).val = 2 ^ 12 - 1 from rfl, Nat.and_two_pow_sub_one_eq_mod] + +theorem large_ram_frame_some {c : capability.Cap} {ptr rights : U64} + (h : vspace.large_ram_frame c = ok (some (ptr, rights))) : + ∃ m e a v, c = .Frame ptr .Large rights false m e a v := by + cases c <;> simp [vspace.large_ram_frame] at h + rename_i p sz r d m e a v + cases sz <;> cases d <;> simp at h + obtain ⟨rfl, rfl⟩ := h + exact ⟨m, e, a, v, rfl⟩ + +theorem large_ram_frame_tot (c : capability.Cap) : ∃ o, vspace.large_ram_frame c = ok o := by + cases c with + | Frame p sz r d m e a v => cases sz <;> cases d <;> exact ⟨_, rfl⟩ + | _ => exact ⟨_, rfl⟩ + +/-- A frame cap read from a slot has a canonical pointer (every decoded cap is `EncWf`). -/ +theorem capA_frame_canon {s : S} {x p r a v : U64} {sz : capability.FrameSize} {d m e : Bool} + (h : capA st s x = .Frame p sz r d m e a v) : CapRt.Canonical p := by + have w := CapRt.decodeF_encWf (L.mem s x).bv (L.mem s (wa x 8#u64)).bv + have e' : CapRt.decodeF (L.mem s x).bv (L.mem s (wa x 8#u64)).bv = .Frame p sz r d m e a v := h + rw [e'] at w + cases e <;> exact w.1 + +theorem vspace.is_cache_label.derive : + vspace.is_cache_label fl4_abi.label.ARMPageDeriveSubframe = ok false := by + unfold vspace.is_cache_label + simp [fl4_abi.label.ARMPageDeriveSubframe, fl4_abi.label.ARMPageClean_Data, fl4_abi.label.ARMPageInvalidate_Data, + fl4_abi.label.ARMPageCleanInvalidate_Data, fl4_abi.label.ARMPageUnify_Instruction] + +/-! ## The arm -/ + +set_option hygiene false in +/-- An error leaf with the state unchanged. -/ +local macro "errS" : tactic => `(tactic| ( + obtain ⟨q, t⟩ := ArmQIAt.ofPR (Vc := Vc) ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) + first + | exact (WP.spec_ok _).2 ⟨q, t, ArmVsK.refl s, SubSlots.refl s⟩ + | (simp only [core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, + core.convert.FromSame.from, core.result.Result.Insts.CoreOpsTry.branch, bind_ok, bind_tc_ok, + error.illegal, error.truncated, error.range, error.invalid_cap, error.invalid_arg, vspace.failed_lookup] + exact (WP.spec_ok _).2 ⟨q, t, ArmVsK.refl s, SubSlots.refl s⟩))) + +set_option maxHeartbeats 8000000 in +/-- **`derive_subframe` to `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ SubSlots`** (module docstring). -/ +theorem vspace.derive_subframe.armSAt {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (len buf : U64) : + vspace.derive_subframe st s len slot cap buf extra ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2 ∧ TabKeepOrZero st s r.2 ∧ ArmVsK st H OS Vc s r.2 ∧ + SubSlots st OS s r.2 ⦄ := by + have hS : P0.StoreTotal st := L.total + have hc0 : capA st s slot = cap := by + rw [capA_eq] at hcap + exact okinj hcap + unfold vspace.derive_subframe + step with sched.cur_thread.spec as ⟨ct, ect⟩ + have e : ct = L.curW s := ect + subst e + refine WP.spec_bind (vspace.extra.memA extra 0#usize) fun o ho => ?_ + rcases o with _ | x + · errS + try dsimp only + have hx : x ∈ OS := P.ext x (ho x rfl).1 (ho x rfl).2 + refine spec_ite (fun _ => ?_) (fun _ => by errS) + obtain ⟨o1, ho1⟩ := large_ram_frame_tot cap + rw [ho1, bind_ok] + rcases o1 with _ | ⟨ptr, rights⟩ + · errS + try dsimp only + obtain ⟨fm, fe, fa, fv, hcapF⟩ := large_ram_frame_some ho1 + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun ni _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun nd _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun no _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun off _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun cnt _ => ?_ + refine WP.spec_bind shl21_val fun i hi => ?_ + refine spec_ite (fun _ => by errS) (fun hoff => ?_) + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by errS) (fun hlo => ?_) + have hoff' : off.val < 2097152 := by scalar_tac + have hlo' : off.val % 4096 = 0 := by + have h0 : off.val &&& 4095 = 0 := by simpa using hlo + have h1 : off.val &&& (2 ^ 12 - 1) = off.val % 2 ^ 12 := Nat.and_two_pow_sub_one_eq_mod _ _ + norm_num at h1 + rw [h1] at h0 + exact h0 + step as ⟨i2, hi2⟩ + refine WP.spec_bind shr12_val fun mx hmx => ?_ + refine spec_ite (fun _ => by errS) (fun hc1 => ?_) + refine spec_ite (fun _ => by errS) (fun hc2 => ?_) + have hcnt1 : 1 ≤ cnt.val := by scalar_tac + have hcnt2 : cnt.val ≤ mx.val := by scalar_tac + have hcnt3 : cnt.val * 4096 + off.val ≤ 2097152 := by + have : mx.val = (i.val - off.val) / 4096 := by rw [hmx, hi2] + rw [hi] at this + omega + refine WP.spec_bind (vspace.subframe_dest.window P.heap B P.ty hx) fun r hr => ?_ + rcases r with dst | e + swap + · errS + obtain ⟨hcv, hinj⟩ := hr dst rfl + simp only [irq_branch_ok, bind_ok] + refine WP.spec_bind (vspace.ensure_empty_run.spec s dst no cnt) fun r1 hr1 => ?_ + rcases r1 with _ | e + swap + · errS + have hnull := hr1 rfl + simp only [irq_branch_ok, bind_ok] + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun mask _ => ?_ + refine WP.spec_bind (P0.capability.Rights.from_word.p0 _) fun r2 _ => ?_ + refine WP.spec_bind (capability.mask_vm_rights.lt4 rights r2) fun vm hvm => ?_ + refine WP.spec_bind (sched.set_thread_state.restartQ I D P B Y) fun s1 ⟨R1, Q1, k1, K1⟩ => ?_ + try simp only [lift, bind_ok] + obtain ⟨Ac1, hb1⟩ := R1.jv.1.parts + have I0 : SubInv st H Cs OS Vc ia ie s s1 s1 := + { sys := R1.sys, sym := R1.sym, blk := ⟨Ac1, hb1.blk⟩, vc := R1.vc, pool := Q1, + z0 := ⟨K1.toZ, fun _ hf => FrUb.keepO hf k1⟩, kl := ⟨ArmVsK.refl s1, FrC.refl' s1⟩, + slots := SubSlots.refl s1 } + have hFr := (B.sys.fr slot P.src) ptr .Large rights fm fe fa fv (by rw [hc0, hcapF]) + have hF : FrAt H ptr 21#u64 := hFr 21#u64 rfl + have hpal : ptr.val % 2097152 = 0 := hF.al P.heap + have hfit : ptr.val + 2097152 ≤ 18446744073709551616 := hF.fits P.heap + have hcanP : CapRt.Canonical ptr := capA_frame_canon (by rw [hc0, hcapF]) + have hsc : capA st s1 slot = .Frame ptr .Large rights false fm fe fa fv := by + rw [k1.capA P.src, hc0, hcapF] + have SS1 : SubSlots st OS s s1 := fun z hz => Or.inl (k1.capA hz) + refine WP.spec_bind (vspace.insert_subframes.subS P.heap P.os P.win I.del.vr R1.jv.ksb I0 P.src hsc + (fun j hj => ⟨(hcv j hj).1, (hcv j hj).2.keepSub SS1⟩) + (fun j hj => by rw [k1.capA (hcv j hj).1]; exact hnull j hj) hinj (by omega) hfit (by omega) + (fun i z hi hz => subGeo_ptr hfit hlo' hcnt3 hi hz) (fun i z hi hz => subGeo_canon hcanP hpal hfit hcnt3 hi hz)) + fun s2 h2 => ?_ + obtain ⟨hI2, -⟩ := h2 + obtain ⟨q, t⟩ := ArmQIAt.ofPR ⟨hI2.sys, hI2.sym⟩ hI2.blk (fun _ => hI2.vc) hI2.pool hI2.z0.1.toVs + exact (WP.spec_ok _).2 ⟨q, t, ArmVsK.trans K1 k1 hI2.kl.1, SubSlots.trans SS1 hI2.slots⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aSubDest.lean b/proofs/Fl4ProofsA64/P1/S1aSubDest.lean new file mode 100644 index 000000000..8fb7141c7 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aSubDest.lean @@ -0,0 +1,123 @@ +/- +P1 (aarch64, E0.4): **`vspace.subframe_dest`'s `Ok dest`** (the destination of `DeriveSubframe`'s `count` caps). + +As for `untyped.retype_dest` (MdbCovU's `.cnode`): on `Ok dest`, `dest` is the pointer of a CNode cap held by an `OS` +slot whose node holds the window `[node_offset, node_offset + count)`. Hence every slot `dest + 32·(node_offset + j)`, +`j < count`, is an `OS` slot of a held CNode cap (`SlotCov`). + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aSubIns +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {T : Set U64} {Ω : Set U64} {Sg : Set U64} +variable {H : Heap} {Rp Nt : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +variable {OS : Set U64} + +theorem vcnode_of_some {c : capability.Cap} {d r : U64} (h : vspace.cnode_of c = ok (some (d, r))) : + ∃ g b, c = .CNode d r g b := by + cases c <;> simp [vspace.cnode_of] at h + obtain ⟨rfl, rfl⟩ := h + exact ⟨_, _, rfl⟩ + +theorem vcnode_of_tot (c : capability.Cap) : ∃ o, vspace.cnode_of c = ok o := by + cases c <;> exact ⟨_, rfl⟩ + +set_option hygiene false in +/-- `subframe_dest`'s common tail from the node cap `c` read from the `OS` slot `y` (`hc : capA st s y = c`). -/ +local macro "sdtail" : tactic => `(tactic| ( + obtain ⟨o, ho⟩ := vcnode_of_tot c + rw [ho, bind_ok] + rcases o with _ | ⟨dest, radix⟩ + · simp only [vspace.failed_lookup, bind_ok, WP.spec_ok]; try (intro d h; cases h) + obtain ⟨g, b, rfl⟩ := vcnode_of_some ho + have hr64 : radix.val < 64 := + (RootOK.of_slot (c := .CNode dest radix g b) hT hy (by rw [capA_eq, hc])).2 dest radix g b rfl + have h63 : 2 ^ radix.val ≤ 2 ^ 63 := Nat.pow_le_pow_right (by norm_num) (by omega) + try dsimp only + try simp only [lift, bind_ok] + refine WP.spec_bind (shl1_val hr64) fun ns hns => ?_ + have hns1 : 1 ≤ ns.val := by rw [hns]; exact Nat.one_le_two_pow + have hs1 : (core.num.U64.wrapping_sub ns 1#u64).val = ns.val - 1 := by + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits]; omega + try simp only [lift, bind_ok] + split + · simp only [error.range, lift, bind_ok, WP.spec_ok]; try (intro d h; cases h) + rename_i h1 + try simp only [lift, bind_ok] + split + · simp only [error.range, lift, bind_ok, WP.spec_ok]; try (intro d h; cases h) + rename_i h4 + simp only [WP.spec_ok] + intro d hdd + cases hdd + have h1' : no.val ≤ ns.val - 1 := by + have := h1; simp only [gt_iff_lt, not_lt] at this + have : no.val ≤ (core.num.U64.wrapping_sub ns 1#u64).val := this + omega + have hoff : (core.num.U64.wrapping_sub ns no).val = ns.val - no.val := by + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits]; omega + have h4' : cnt.val ≤ ns.val - no.val := by + have := h4; simp only [gt_iff_lt, not_lt] at this + have : cnt.val ≤ (core.num.U64.wrapping_sub ns no).val := this + omega + exact ⟨_, hy, radix, g, b, hc, by omega⟩)) + +set_option maxHeartbeats 2000000 in +/-- **`subframe_dest`'s `Ok dest`: a held CNode cap of `dest` whose node holds the window** (module docstring). -/ +theorem vspace.subframe_dest.cnode {s : S} (hT : SlotTy st T Ω Sg H Rp Nt OS s) {x ni nd no cnt : U64} + (hx : x ∈ OS) : + vspace.subframe_dest st s x ni nd no cnt ⦃ r => ∀ d, r = .Ok d → + ∃ y ∈ OS, ∃ rd g b, capA st s y = .CNode d rd g b ∧ no.val + cnt.val ≤ 2 ^ rd.val ⦄ := by + unfold vspace.subframe_dest + rw [capA_eq, bind_ok] + split + · refine WP.spec_bind (lookup_tgt_in hT (capA st s x) (RootOK.of_slot hT hx (capA_eq s x)) ni nd) + fun r hr => ?_ + rcases r with v | e + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + rw [capA_eq, bind_ok] + have hy : v ∈ OS := hr v rfl + generalize hc : capA st s v = c + sdtail + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + first + | exact (WP.spec_ok _).2 fun nc h => (by cases h) + | (simp only [WP.spec_ok]; intro nc h; cases h) + · have hy : x ∈ OS := hx + generalize hc : capA st s x = c + sdtail + +/-- **Every slot of `subframe_dest`'s window is an `OS` slot of a held CNode cap** (`SlotCov`). -/ +theorem vspace.subframe_dest.slots {s : S} (hT : SlotTy st T Ω Sg H Rp Nt OS s) {no cnt dest : U64} + (hex : ∃ y ∈ OS, ∃ rd g b, capA st s y = .CNode dest rd g b ∧ no.val + cnt.val ≤ 2 ^ rd.val) : + ∀ j : U64, j.val < cnt.val → slotIdx dest (wa no j) ∈ OS ∧ SlotCov st OS s (slotIdx dest (wa no j)) := by + obtain ⟨y, hy, rd, g, b, hc, hle⟩ := hex + intro j hj + have hR := RootOK.of_slot hT hy (by rw [capA_eq, hc]) + have hr : rd.val < 64 := hR.2 dest rd g b rfl + have h63 : 2 ^ rd.val ≤ 2 ^ 63 := Nat.pow_le_pow_right (by norm_num) (by omega) + have hi : (wa no j).val < 2 ^ (rd.val % 64) := by + rw [wa_val, Nat.mod_eq_of_lt (show no.val + j.val < 2 ^ 64 by omega), Nat.mod_eq_of_lt hr]; omega + exact ⟨hR.1.1 dest rd g b rfl _ hi, ⟨y, hy, dest, rd, g, b, hc, _, hi, rfl⟩⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aSubFin.lean b/proofs/Fl4ProofsA64/P1/S1aSubFin.lean new file mode 100644 index 000000000..b3071c373 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aSubFin.lean @@ -0,0 +1,77 @@ +/- +P1 (aarch64, E0.5d): **the entry facts after `DeriveSubframe`, once** — what `decodeFinA` reads from `s1aStepEntAll` / +`s1aStepFix` / `fixHeap` / `poolNamedFix` for the heap-keeping arms, for the new arm. + +* **`S1aStepFix.ofSub`**: `S1aStepFix.ofKeep` with `SubSlots` for `OSKeep` (as `S1aStepR2K.ofSub`). +* **`syscall.decode_invocation.subFin`**: `deriveSub_armSAt`, then `S1aStepR2K`, `S1aStepEnt`, `S1aStepFix` and + `PoolNamed` at the post state. + +Named premises: none new. +-/ +import Fl4ProofsA64.P1.S1aSubTop +import Fl4ProofsA64.P1.S1aStepFix +import Fl4ProofsA64.P1.S1aStepPool +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} +variable {Cs Ac U : Set U64} + +namespace W7 +namespace R +namespace ST + +variable {OS Vc Ub Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} +variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- **`S1aStepFix.ofKeep` with `SubSlots` for `OSKeep`** (module docstring). -/ +theorem S1aStepFix.ofSub {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 ∧ SubSlots st OS s q) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (fu : FrUb st Ub OS s) + (vcc : VcCap st Vc OS s) (C : S1aArmCol st H Cs OS Vc Ub s) + (Df : DevFrAl st OS s) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (KC : S1aHiK st OS Kt KLv s) : + S1aStepFix st H Cs OS Vc Ub Pt Kt KLv ia ie n q := by + obtain ⟨arm, tab, mem, slots⟩ := d + have vs : VsKeep st (L.ksb s) Pt s q := mem.2 Ub Pt vr fu + have R' : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := + R.ofImage mem.1 vs (.ofSame R.capRefs.refs fun y hy => (slots y hy).elim Or.inl fun ⟨e0, p, r, e1⟩ => + Or.inr ⟨by rw [e0]; intro h; exact h, by rw [e1]; intro h; cases h⟩) + 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.subSlots slots) R'.ex col + +/-- **The entry facts after the `DeriveSubframe` decode** (module docstring). -/ +theorem syscall.decode_invocation.subFin {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (a : A) {lbl : U64} (hc : DecArmS1aSub cap lbl) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) + (hPN : PoolNamed st OS s) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie n s' ∧ S1aStepEnt st H Cs OS U ia ie s' ∧ + S1aStepFix st H Cs OS Vc Ub Pt Kt KLv ia ie n s' ∧ PoolNamed st OS s' ∧ L.ksb s' = L.ksb s ⦄ := by + obtain ⟨fp0, fsz, fr, fd, fm, fe, fa, fv, rfl, rfl⟩ := hc + refine WP.spec_mono (syscall.decode_invocation.deriveSub_armSAt I D P B Y hcap a len blk call don fp buf) + fun r d => ?_ + obtain ⟨_, s', _⟩ := r + have k := S1aStepR2K.ofSub d I.del.vr I.fu I.vcc C Kc Df R sep KC + obtain ⟨Ac', bk⟩ := d.1.2.2.1 + exact ⟨k, ⟨d.1.1, I.del.heap, ⟨Ac', BlkOK.bxi bk⟩, I.del.os, D.user.ksb d.2.1.1, k.vsTy, d.1.1.ly.ksw⟩, + S1aStepFix.ofSub d I.del.vr I.fu I.vcc C Df R sep KC, d.1.2.2.2.2.2.1 hPN, d.2.1.1⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aSubGeo.lean b/proofs/Fl4ProofsA64/P1/S1aSubGeo.lean new file mode 100644 index 000000000..6ab3b9e69 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aSubGeo.lean @@ -0,0 +1,82 @@ +/- +P1 (aarch64, E0.4): **the arithmetic of `DeriveSubframe`'s window** (`vspace.derive_subframe`): the `i`-th subframe is at +`p + offset + i·4096` inside the 2 MiB frame `[p, p + 2^21)`, canonical when `p` is. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aSubLoop +import Fl4ProofsA64.P1.MdbUtW +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +theorem wa_val_lt' {x y : U64} (h : x.val + y.val < 2 ^ 64) : (wa x y).val = x.val + y.val := by + rw [wa_val] + exact Nat.mod_eq_of_lt h + +/-- The window arithmetic over plain numbers (`M` stands for `2^64`, so that `omega` never sees it). -/ +theorem geo_nat (P off z i cnt M : Nat) (hfit : P + 2097152 ≤ M) (hoff4 : off % 4096 = 0) + (hc : cnt * 4096 + off ≤ 2097152) (hi : i < cnt) (hz : z = i * 4096) : + P + off < M ∧ P + off + z < M ∧ (off / 4096 + i) * 4096 + 4096 ≤ 2097152 ∧ + P + off + z = P + (off / 4096 + i) * 4096 ∧ P + off + z + 4096 ≤ P + 2097152 := by + omega + +theorem geo_lt (P off z i cnt M : Nat) (hfit : P + 2097152 ≤ M) (hc : cnt * 4096 + off ≤ 2097152) (hi : i < cnt) + (hz : z = i * 4096) : P + off < M ∧ P + off + z < M := by + omega + +theorem canon_nat (P off z i cnt M T : Nat) (hal : P % 2097152 = 0) (hT : T % 2097152 = 0) + (hc : cnt * 4096 + off ≤ 2097152) (hi : i < cnt) (hz : z = i * 4096) : + (P < T → P + off + z < T) ∧ (M - T ≤ P → M - T ≤ P + off + z) := by + omega + +/-- The `i`-th subframe's pointer is the frame's plus `k·4096`, the subframe inside the frame. -/ +theorem subGeo_ptr {p off z : U64} {i cnt : Nat} (hfit : p.val + 2 ^ 21 ≤ 2 ^ 64) + (hoff4 : off.val % 4096 = 0) (hc : cnt * 4096 + off.val ≤ 2 ^ 21) (hi : i < cnt) (hz : z.val = i * 4096) : + ∃ k, (wa (wa p off) z).val = p.val + k * 4096 ∧ k * 4096 + 4096 ≤ 2 ^ 21 := by + have e21 : (2 : Nat) ^ 21 = 2097152 := by norm_num + rw [e21] at hfit hc ⊢ + obtain ⟨b1, b2, b3, b4, -⟩ := geo_nat p.val off.val z.val i cnt (2 ^ 64) hfit hoff4 hc hi hz + refine ⟨off.val / 4096 + i, ?_, b3⟩ + have hv1 : (wa p off).val = p.val + off.val := wa_val_lt' b1 + have hv2 : (wa (wa p off) z).val = (wa p off).val + z.val := wa_val_lt' (by rw [hv1]; exact b2) + rw [hv2, hv1] + exact b4 + +/-- The `i`-th subframe's pointer is canonical when the frame's is (the frame is 2 MiB-aligned and fits). -/ +theorem subGeo_canon {p off z : U64} {i cnt : Nat} (hcan : CapRt.Canonical p) (hal : p.val % 2 ^ 21 = 0) + (hfit : p.val + 2 ^ 21 ≤ 2 ^ 64) (hc : cnt * 4096 + off.val ≤ 2 ^ 21) (hi : i < cnt) + (hz : z.val = i * 4096) : CapRt.Canonical (wa (wa p off) z) := by + have e21 : (2 : Nat) ^ 21 = 2097152 := by norm_num + rw [e21] at hfit hc hal + have hT : (2 : Nat) ^ 47 % 2097152 = 0 := by norm_num + obtain ⟨b1, b2⟩ := geo_lt p.val off.val z.val i cnt (2 ^ 64) hfit hc hi hz + obtain ⟨c1, c2⟩ := canon_nat p.val off.val z.val i cnt (2 ^ 64) (2 ^ 47) hal hT hc hi hz + have hv1 : (wa p off).val = p.val + off.val := wa_val_lt' b1 + have hv2 : (wa (wa p off) z).val = (wa p off).val + z.val := wa_val_lt' (by rw [hv1]; exact b2) + have hv : (wa (wa p off) z).val = p.val + off.val + z.val := by rw [hv2, hv1] + apply canon_of_lt + rcases canon_lt hcan with h | h + · left + rw [hv] + exact c1 h + · right + rw [hv] + exact c2 h + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aSubIns.lean b/proofs/Fl4ProofsA64/P1/S1aSubIns.lean new file mode 100644 index 000000000..1d527a4d1 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aSubIns.lean @@ -0,0 +1,258 @@ +/- +P1 (aarch64, E0.4): **the insertion of one subframe cap** (`vspace.insert_subframes` inserts +`Frame p' Small r' false false false 0 0` as the child of the `Large` frame cap `Frame p sz r false m e a v`, +`p' = p + k·4096`, `k·4096 + 4096 ≤ 2^bits(sz)`). + +`cdt.insert_with_cap.sysLVB` is out (its `InsC` carries `FE` and `UA`, which a subframe does not satisfy: same base and +size). As for the `IrqHandler` insertion (MdbIrqC's `sysLI`) the MDB steps that do not read them are applied one by one; +the tree steps are S1aSubTree's `treeSub` / `trSub` (`SubA`), and the `CapInv` fields that name a frame cap (`FrP`, +`FrOffP`) are carried over from the source by their `sub` lemmas. + +* **`FrAt.sub`**: a 4 KiB-aligned subrange of a frame's range is a `Small` frame at the same object. +* **`IsSubFr nc sc`**, **`FrP.sub`**, **`FrOffP.sub`**, **`FrUbP.sub`**, **`CapSrc.sub`**, **`IsSubFr.subA`**. +* **`cdt.insert_with_cap.sysLS`**: the insertion keeps `SysL ∧ SymL`. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aSubTree +import Fl4ProofsA64.P1.MdbIrqC +import Fl4ProofsA64.P1.MdbHiVsArm +import Fl4ProofsA64.P1.MdbFrUt +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} +variable {Cs : Set U64} {Ac U : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} + +/-! ## Subframes of a frame object -/ + +/-- **A 4 KiB-aligned subrange of a frame's range is a `Small` frame in the same object.** -/ +theorem FrAt.sub {H : Heap} {p bits p' bits' : U64} {k : Nat} (h : FrAt H p bits) (hp' : p'.val = p.val + k * 4096) + (hk : k * 4096 + 4096 ≤ 2 ^ bits.val) (hb' : bits'.val = 12) : FrAt H p' bits' := by + obtain ⟨b, kk, hb, h1, h2, h3⟩ := FrAt.def.1 h + have e12 : 2 ^ bits'.val = 4096 := by rw [hb']; norm_num + have hb12 : 12 ≤ bits.val := by + by_contra hlt + have hle : 2 ^ bits.val ≤ 2 ^ 11 := Nat.pow_le_pow_right (by norm_num) (by omega) + norm_num at hle + omega + have hd : 4096 ∣ 2 ^ bits.val := by + have := Nat.pow_dvd_pow 2 hb12 + norm_num at this + exact this + have h4 : (p.val - b.val) % 4096 = 0 := Nat.mod_eq_zero_of_dvd (hd.trans (Nat.dvd_of_mod_eq_zero h3)) + refine FrAt.def.2 ⟨b, kk, hb, by omega, by omega, ?_⟩ + rw [e12] + omega + +/-- **The cap `nc` is a subframe cap of the `Large` non-device frame cap `sc`.** -/ +def IsSubFr (nc sc : capability.Cap) : Prop := + ∃ p p' sz r r' m e a v k, sc = .Frame p sz r false m e a v ∧ + nc = .Frame p' .Small r' false false false 0#u64 0#u64 ∧ p'.val = p.val + k * 4096 ∧ + ∀ bits, capability.FrameSize.bits sz = ok bits → k * 4096 + 4096 ≤ 2 ^ bits.val + +theorem smallBits {bits : U64} (h : capability.FrameSize.bits .Small = ok bits) : bits.val = 12 := by + have e : capability.FrameSize.bits .Small = ok 12#u64 := rfl + rw [e] at h + have h' := okinj h + rw [← h'] + rfl + +theorem frameBits_ex (sz : capability.FrameSize) : ∃ bits, capability.FrameSize.bits sz = ok bits := by + cases sz <;> exact ⟨_, rfl⟩ + +theorem FrP.sub {H : Heap} {nc sc : capability.Cap} (hs : IsSubFr nc sc) (h : FrP H sc) : FrP H nc := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc, hnc, hp, hk⟩ := hs + intro ptr size rights x1 x2 x3 x4 hc + rw [hnc] at hc + injection hc with h1 h2 h3 h4 h5 h6 h7 h8 + subst h1 h2 + intro bits hb + obtain ⟨bits0, hb0⟩ := frameBits_ex sz + have hF := h p sz r m e a v hsc bits0 hb0 + exact FrAt.sub hF hp (hk bits0 hb0) (smallBits hb) + +theorem FrOffP.sub {Cs OS : Set U64} {kb : U64} {nc sc : capability.Cap} (hs : IsSubFr nc sc) + (h : FrOffP Cs OS kb sc) : FrOffP Cs OS kb nc := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc, hnc, hp, hk⟩ := hs + intro ptr size rights x1 x2 x3 x4 hc bits hb + rw [hnc] at hc + injection hc with h1 h2 h3 h4 h5 h6 h7 h8 + subst h1 h2 + obtain ⟨bits0, hb0⟩ := frameBits_ex sz + have hF := h p sz r m e a v hsc bits0 hb0 + have e12 : 2 ^ bits.val = 4096 := by rw [smallBits hb]; norm_num + have hk0 := hk bits0 hb0 + refine ⟨fun y hy => ?_, RegOffK.sub hF.2 (by omega) (by omega)⟩ + have := hF.1 y hy + omega + +theorem FrUbP.sub {Ub : Set U64} {nc sc : capability.Cap} (hs : IsSubFr nc sc) (h : FrUbP Ub sc) : FrUbP Ub nc := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc, hnc, hp, hk⟩ := hs + intro ptr size rights x1 x2 x3 x4 hc bits hb b hal h1 h2 + rw [hnc] at hc + injection hc with h1' h2' h3 h4 h5 h6 h7 h8 + subst h1' h2' + obtain ⟨bits0, hb0⟩ := frameBits_ex sz + have e12 : 2 ^ bits.val = 4096 := by rw [smallBits hb]; norm_num + have hk0 := hk bits0 hb0 + exact h p sz r m e a v hsc bits0 hb0 b hal (by omega) (by omega) + +theorem CapSrc.sub {OS : Set U64} {s0 : S} {nc sc : capability.Cap} (hs : IsSubFr nc sc) (h : CapSrc st OS s0 sc) : + CapSrc st OS s0 nc := by + intro Q hQ hI + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc, hnc, hp, hk⟩ := hs + have h0 := h Q hQ hI + rw [hsc] at h0 + rw [hnc] + exact hQ.sub (r' := r') k h0 hp hk + +theorem IsSubFr.noAp {nc sc : capability.Cap} (hs : IsSubFr nc sc) : NoAp nc := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc, hnc, hp, hk⟩ := hs + intro q b h + rw [hnc] at h + cases h + +theorem IsSubFr.ne_null {nc sc : capability.Cap} (hs : IsSubFr nc sc) : nc ≠ .Null := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc, hnc, hp, hk⟩ := hs + rw [hnc] + intro h + cases h + +theorem IsSubFr.sc_ne_null {nc sc : capability.Cap} (hs : IsSubFr nc sc) : sc ≠ .Null := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc, hnc, hp, hk⟩ := hs + rw [hsc] + intro h + cases h + +theorem RngKeyA.frame_not (p : U64) (sz : capability.FrameSize) (r : U64) (d m e : Bool) (a v : U64) : + ¬ RngKeyA (.Frame p sz r d m e a v) := fun h => by + have := h.2.2 + simp [isFrA] at this + +/-- **A subframe cap is a `SubA` of its source frame cap** (`hreg`: the subframe's range does not wrap, `hwin`: it +lies in the source's). -/ +theorem IsSubFr.subA {nc sc : capability.Cap} (hs : IsSubFr nc sc) + (hreg : baseA nc ≤ topA nc) (hwin : WithinA nc sc) : SubA nc sc := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc, hnc, hp, hk⟩ := hs + obtain ⟨bits0, hb0⟩ := frameBits_ex sz + have f1 := frA_size (ptr := p) (rights := r) (x3 := a) (x4 := v) (dv := false) (x1 := m) (x2 := e) (size := sz) hb0 + have f2 := frA_size (ptr := p') (rights := r') (x3 := 0#u64) (x4 := 0#u64) (dv := false) (x1 := false) + (x2 := false) (size := .Small) (bits := 12#u64) rfl + subst hsc hnc + exact ⟨f2.2.2.2.2, f1.2.2.2.2, f2.2.2.2.1, f1.2.2.2.1, hwin, hreg⟩ + +theorem IsSubFr.alike {nc sc : capability.Cap} (hs : IsSubFr nc sc) : AlikeA nc sc := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc, hnc, hp, hk⟩ := hs + rw [hsc, hnc] + exact ⟨⟨fun h => absurd h (RngKeyA.frame_not _ _ _ _ _ _ _ _), + fun h => absurd h (RngKeyA.frame_not _ _ _ _ _ _ _ _)⟩, fun h => absurd h (RngKeyA.frame_not _ _ _ _ _ _ _ _)⟩ + +/-! ## `insert_with_cap` of a subframe cap keeps `SysL ∧ SymL` -/ + +set_option maxHeartbeats 4000000 in +/-- **`insert_with_cap` of a subframe cap from its `Large` frame cap's slot keeps `SysL ∧ SymL`** (module docstring). -/ +theorem cdt.insert_with_cap.sysLS (hH : HeapOK H) (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) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) {x y : U64} {nc sc : capability.Cap} + (hs : IsSubFr nc sc) (hw : CapRt.EncWf nc) (hS : SubA nc sc) (hx : x ∈ OS) (hy : y ∈ OS) + (hyc : obj.sext48 y = ok y) (hsc : capA st s x = sc) (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) : + cdt.insert_with_cap st s nc sc x y ⦃ s' => + SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ⦄ := by + obtain ⟨Q, Rq, q⟩ := hb.1 + have hm := B.sys.stz.1.1 + have hSm : MdbS st OS s := hm.mdbS + have hxy : x ≠ y := fun e => by rw [e, hy0] at hsc; exact hs.sc_ne_null hsc.symm + have hsc0 : sc ≠ .Null := hs.sc_ne_null + have hnc : nc ≠ .Null := hs.ne_null + have hal : AlikeA nc sc := hs.alike + have hnk : ¬ RngKeyA nc := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc', hnc', hp, hk⟩ := hs + rw [hnc']; exact RngKeyA.frame_not _ _ _ _ _ _ _ _ + have hnz : NZA nc := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc', hnc', hp, hk⟩ := hs + rw [hnc']; exact fun _ _ _ h => by cases h + have hnu : ∀ p b i e, nc ≠ .Untyped p b i e := by + obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc', hnc', hp, hk⟩ := hs + rw [hnc']; exact fun _ _ _ _ h => by cases h + obtain ⟨-, nn⟩ := hSm.lnk hO hx + have hS' := hSm + obtain ⟨G, hM, hRO, hK, hN, hC⟩ := hS' + have hsm : x ∈ G.flatten := (hM.members x).2 ⟨hx, by rw [hsc]; exact hsc0⟩ + obtain ⟨G', par, hT⟩ := hm.tu + obtain ⟨⟨-, hR, hV, hZ, hCA⟩, hz, hks⟩ := B.sys.stz + obtain ⟨z0, hz0, hcz⟩ := hcd + refine WP.spec_mono (WP.spec_and (WP.spec_and (WP.spec_and + (cdt.insert_with_cap.mdbO hO hM hRO hK hN hC hsm hy hy0 hyc hsc hw hnc hal) + (cdt.insert_with_cap.trSub hO hT hR hx (by rw [hsc]; exact hsc0) hy hy0 hyc hsc hw hnc hS)) + (WP.spec_and (cdt.insert_with_cap.ubF hO hSm hx hy hxy hyc hsc hsc0 hw (UB.of_not (fun p b i => hnu p b i false)) + (fun p b i e h => by have := hS.cnu; rw [h] at this; simp [isUtA] at this)) + (WP.spec_and (cdt.insert_with_cap.cov hO hCA hSm hx hy hxy hyc hsc hsc0 hw hy0 fun _ => ⟨z0, hz0, hcz.1⟩) + (cdt.insert_with_cap.covR (R := CovZ) CovZ.null (fun _ _ h => h.ut) hO B.sys.cz hSm hx hy hxy hyc hsc hsc0 + hw hy0 fun _ _ => ⟨z0, hz0, hcz⟩)))) + (spec_andA (cdt.insert_with_cap.lrF hO (LR.self s) hx hy hxy hyc hsc hsc0 hw nn) + (cdt.insert_with_cap.srcU hO hx hy hxy hsc hw nn))) ?_ + rintro s' ⟨⟨⟨m1, t2⟩, ⟨hW, u⟩, c4, cz⟩, ⟨w, -, ed, -, -, ek, -⟩, hU⟩ + have hxk : capA st s' x = capA st s x := by + rcases hU.1 with e | ⟨p, b, j, e0, j1, es, -, -⟩ + · rw [e, hsc] + · have h := hS.cnu + rw [es] at h + simp [isUtA] at h + have hk : ∀ z ∈ OS, z ≠ y → capA st s' z = capA st s z := fun z hz e => by + by_cases a : z = x + · rw [a]; exact hxk + · exact ek z hz a e + have g : LiveAg st H Cs s s' := LiveAg.ofCwN hb.blk w fun _ _ hb' => Or.inl hb' + obtain ⟨y', vr', ly'⟩ := SVL.cw hb.blk ⟨Y, B.vr, B.ly⟩ w (fun _ _ hb' => Or.inl hb') u + have nk : NamesKept st OS s s' := NamesKept.of_alike fun z hz hkz => by + have hzy : z ≠ y := fun e => by rw [e, hy0] at hkz; exact RngKeyA.not_null hkz + exact ⟨z, hz, by rw [hk z hz hzy]; exact AlikeA.refl _⟩ + have bi : BufInv st H OS s' := (BufInv.of B.cn B.bh).map fun z hz => by + by_cases e : z = y + · subst e + refine Or.inr (Or.inr ⟨hyB, fun _ _ _ _ h => ?_, fun _ _ _ h => ?_⟩) <;> (rw [ed] at h; obtain ⟨p, p', sz, r, r', m, e', a, v, k, hsc', hnc', hp, hk'⟩ := hs; rw [hnc'] at h; cases h) + · exact Or.inr (Or.inl (hk z hz e)) + have ksk : L.ksb s' = L.ksb s := hW.1 + have ep' : EptSlot st H OS s' := B.ep.map fun z hz => by + by_cases e : z = y + · subst e; exact Or.inr (Or.inr hyE) + · exact Or.inr (Or.inl (hk z hz e)) + have hFr : FrP H nc := FrP.sub hs (by rw [← hsc]; exact B.sys.fr x hx) + have hFo : FrOffP Cs OS (L.ksb s) nc := FrOffP.sub hs (by rw [← hsc]; exact B.fo x hx) + refine ⟨⟨⟨⟨⟨MdbST.of hO.nz ⟨_, m1⟩ t2.1, t2.2, (vzW hH ⟨hV, hZ⟩ hW u).1, (vzW hH ⟨hV, hZ⟩ hW u).2, c4⟩, + hz.insNK hnk hnz ed hk, hks.of_ub ksk u⟩, + CapInv.ins (P := FrP H) B.sys.fr hFr ed hk, cz, + CapInv.ins (P := UtCP H) B.sys.ur (fun p b i d h => absurd h (hnu p b i d)) ed hk⟩, + B.ln.ag g nk, vr', ly', bi.cn, bi.bh, + (CapInv.ins B.ci ⟨(fun h => by obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc', hnc', hp, hk'⟩ := hs; rw [hnc'] at h; cases h), + (fun _ h => by obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc', hnc', hp, hk'⟩ := hs; rw [hnc'] at h; cases h), + (fun _ _ _ h => by obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc', hnc', hp, hk'⟩ := hs; rw [hnc'] at h; cases h)⟩ ed hk).idleMv g.idle + (g.idleSc q.idleT), + CapInv.ins B.sc (fun _ _ h => by obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc', hnc', hp, hk'⟩ := hs; rw [hnc'] at h; cases h) ed hk, + CtOff.ks ksk (CapInv.ins B.ct (CtOffP.of_not + (fun _ _ _ _ h => by obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc', hnc', hp, hk'⟩ := hs; rw [hnc'] at h; cases h) + (fun _ _ _ h => by obtain ⟨p, p', sz, r, r', m, e, a, v, k, hsc', hnc', hp, hk'⟩ := hs; rw [hnc'] at h; cases h)) ed hk), + FrOff.ks ksk (CapInv.ins B.fo hFo ed hk), + ep', + B.ipc.keep (IbK.of_w q.tcbs w fun y hy => ib_not_cw q hy)⟩, y'⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aSubLoop.lean b/proofs/Fl4ProofsA64/P1/S1aSubLoop.lean new file mode 100644 index 000000000..b1d706041 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aSubLoop.lean @@ -0,0 +1,284 @@ +/- +P1 (aarch64, E0.4): **`vspace.insert_subframes` to the `ArmQIAt` facts** (the n-fold insertion of `Small` frame caps under +the invoked `Large` frame slot, one per destination slot of a held CNode's window). + +* **`SubInv`**: the facts kept by one insertion (`SysL ∧ SymL`, `BlkOK`, `VcCap`, `PoolR`, the deletion family's + `ArmVsZ ∧ FrC` from the invocation start, and `ArmVsK ∧ FrC` from the loop's start) and **`SubSlots`**: every `OS` + slot keeps its capability, except an empty one that receives a `Small` frame cap. +* **`cdt.insert.subStep`**: one `cdt.insert` of a subframe cap (S1aSubIns's `sysLS`; MdbHiVsArm's `lrF` / `poolR` / + `armVsZ` / `armVsK`, as the `IrqHandler` insertion's `invoke_irq_control.armS`). +* **`vspace.insert_subframes.subS`**: the loop; each slot of the window is an empty `OS` slot of a held CNode, the + window's slots are distinct, and the cap written at iteration `i` is a subframe of the source (`hgeo`). + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aSubDest +import Fl4ProofsA64.P1.MdbIrqCQ +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} +variable {Cs : Set U64} {Ac U : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} + +/-! ## Slot facts -/ + +variable (st) in +/-- **The slot fact of a subframe insertion**: every `OS` slot keeps its capability, except an empty one that +receives a `Small` frame cap. -/ +def SubSlots (OS : Set U64) (s r : S) : Prop := + ∀ z ∈ OS, capA st r z = capA st s z ∨ + (capA st s z = .Null ∧ ∃ p r', capA st r z = .Frame p .Small r' false false false 0#u64 0#u64) + +theorem SubSlots.refl (s : S) : SubSlots st OS s s := fun _ _ => Or.inl rfl + +theorem SubSlots.trans {s q r : S} (h1 : SubSlots st OS s q) (h2 : SubSlots st OS q r) : SubSlots st OS s r := + fun z hz => by + rcases h2 z hz with e | ⟨e0, p, r', e1⟩ + · rw [e]; exact h1 z hz + · rcases h1 z hz with e' | ⟨e0', -⟩ + · exact Or.inr ⟨e'.symm.trans e0, p, r', e1⟩ + · exact Or.inr ⟨e0', p, r', e1⟩ + +/-- A slot of a held CNode cap stays a slot of it: its covering cap is not `Null`, so it is kept. -/ +theorem SlotCov.keepSub {s r : S} {y : U64} (h : SlotCov st OS s y) (k : SubSlots st OS s r) : SlotCov st OS r y := by + obtain ⟨z, hz, p, r', g, b, hc, i, hi, e⟩ := h + refine ⟨z, hz, p, r', g, b, ?_, i, hi, e⟩ + rcases k z hz with e' | ⟨e0, -⟩ + · rw [e']; exact hc + · rw [e0] at hc; cases hc + +theorem FrC.trans' {s1 s2 s3 : S} (h1 : FrC st OS s1 s2) (h2 : FrC st OS s2 s3) : FrC st OS s1 s3 := + fun Ub hf => h2 Ub (h1 Ub hf) + +theorem FrC.refl' (s : S) : FrC st OS s s := fun _ hf => hf + +/-- **Two keeping steps, the first one keeping the frame-cap closure `FrC`** (`ArmVsK.trans` with `FrC` for `OSKeep`). -/ +theorem ArmVsK.transF {s1 s2 s3 : S} (h1 : ArmVsK st H OS Vc s1 s2) (F : FrC st OS s1 s2) + (h2 : ArmVsK st H OS Vc s2 s3) : ArmVsK st H OS Vc s1 s3 := by + refine ⟨h2.1.trans h1.1, fun Ub Pt hvr hf => ?_⟩ + have hvr2 : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s2) Pt := by rw [h1.1]; exact hvr + have k2 := h2.2 Ub Pt hvr2 (F Ub hf) + rw [h1.1] at k2 + exact (h1.2 Ub Pt hvr hf).trans k2 + +/-- A CNode cap held by an `OS` slot has a radix below 64 (its heap object's size bits are). -/ +theorem cnR64 (hH : HeapOK H) {s : S} (B : SysL st H Cs OS ia ie s) {z p r g b : U64} (hz : z ∈ OS) + (h : capA st s z = .CNode p r g b) : r.val < 64 := by + have hcn : CnOP H (.CNode p r g b) := by rw [← h]; exact B.cn z hz + have hp := hcn.1 p r g b rfl + have hl := hH.lt64 p _ hp + simp only [HKind.bits] at hl + omega + +/-! ## One insertion -/ + +variable (st H Cs OS Vc ia ie) in +/-- **The facts kept by the insertions** (module docstring). `s0`: the invocation's start, `sL`: the loop's start. -/ +structure SubInv (s0 sL a : S) : Prop where + sys : SysL st H Cs OS ia ie a + sym : SymL st H Cs a + blk : ∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' a + vc : VcCap st Vc OS a + pool : PoolR st OS s0 a + z0 : ArmVsZ st H OS Vc s0 a ∧ FrC st OS s0 a + kl : ArmVsK st H OS Vc sL a ∧ FrC st OS sL a + slots : SubSlots st OS sL a + +set_option maxHeartbeats 4000000 in +/-- **One `cdt.insert` of a subframe cap under the invoked frame slot keeps `SubInv`** (module docstring). -/ +theorem cdt.insert.subStep (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hW : WinOK H.tcbs H.omega) + {Ω' Sg' Scs' Vc' Ub' Pt' : Set U64} {Z' : U64 → Nat} {s0 sL a : S} + (hvr : VrOK Ω' Sg' Scs' Z' OS Vc' Ub' (L.ksb s0) Pt') (hk0 : L.ksb sL = L.ksb s0) + (I : SubInv st H Cs OS Vc ia ie s0 sL a) {x y : U64} {nc sc : capability.Cap} (hs : IsSubFr nc sc) + (hw : CapRt.EncWf nc) (hS : SubA nc sc) (hx : x ∈ OS) (hy : y ∈ OS) (hsc : capA st a x = sc) + (hy0 : capA st a y = .Null) (hcv : SlotCov st OS a y) : + cdt.insert st a nc x y ⦃ a' => SubInv st H Cs OS Vc ia ie s0 sL a' ∧ capA st a' x = sc ∧ capA st a' y = nc ∧ + ∀ z ∈ OS, z ≠ y → capA st a' z = capA st a z ⦄ := by + unfold cdt.insert + rw [capA_eq, bind_ok, hsc] + obtain ⟨Ac', hbk⟩ := I.blk + obtain ⟨z, hz, p0, r0, g0, b0, hcz0, hcv'⟩ := SlotCov.covC hO I.sys.sys.stz.1.1.reg + (fun z hz p r g b h => cnR64 hH I.sys hz h) hy hcv + have hcz : CovZ (capA st a z) y := by rw [hcz0]; exact CovZ.cnode hcv' + have hxy : x ≠ y := fun e => by rw [e, hy0] at hsc; exact hs.sc_ne_null hsc.symm + have hm : MdbS st OS a := I.sys.sys.stz.1.1.mdbS + have hk1 : L.ksb a = L.ksb s0 := I.kl.1.1.trans hk0 + have hyc : obj.sext48 y = ok y := OSOK.canon hO hW hy + obtain ⟨-, hyE, hyB⟩ := SlotCov.offs hH I.sys hcv + have hsc0 : sc ≠ .Null := hs.sc_ne_null + have hSA : CapSrc st OS s0 nc := CapSrc.sub hs (by rw [← hsc]; exact (I.pool.1 x hx).2) + have hnoap : NoAp nc := hs.noAp + have hnoap' : NoAp sc := by + obtain ⟨p, p', sz, r, r', m, e, a', v, k, hsc', hnc', hp, hk⟩ := hs + rw [hsc'] + intro q b h + cases h + have hfr : ∀ Ub', FrUbP Ub' sc → FrUbP Ub' nc := fun Ub' h => FrUbP.sub hs h + refine WP.spec_mono (WP.spec_and (WP.spec_and (WP.spec_and (WP.spec_and (WP.spec_and + (cdt.insert_with_cap.sysLS hH hO hbk.bxi I.sys I.sym hs hw hS hx hy hyc hsc hy0 hyB hyE ⟨z, hz, hcz⟩) + (cdt.insert_with_cap.lrF hO (LR.self a) hx hy hxy hyc hsc hsc0 hw (hm.lnk hO hx).2)) + (cdt.insert_with_cap.poolR hO hvr hk1 hm hx hy hxy hyc hsc hsc0 hw hnoap' hnoap hSA hy0 I.pool)) + (cdt.insert_with_cap.armVsZ hO hm hx hy hxy hyc hsc hsc0 hw hfr I.z0)) + (cdt.insert_with_cap.armVsK (H := H) (Vc := Vc) hO hm hx hy hxy hyc hsc hsc0 hw)) + (cdt.insert_with_cap.srcF hO hx hy hxy hsc hw (hm.lnk hO hx).2)) ?_ + rintro a' ⟨⟨⟨⟨⟨hS2, w2, -, ed, -, -, ek, -⟩, q2⟩, z2⟩, K2⟩, full⟩ + have hxk : capA st a' x = sc := by + rcases full with e | ⟨p, b, i, d, i1, es, -⟩ + · exact e + · have h := hS.cnu + rw [es] at h + simp [isUtA] at h + have hk : ∀ z ∈ OS, z ≠ y → capA st a' z = capA st a z := fun z hz e => by + by_cases e' : z = x + · rw [e', hxk, hsc] + · exact ek z hz e' e + have FC : FrC st OS a a' := fun Ub' hf => by + refine CapInv.ins (P := FrUbP Ub') hf ?_ ed hk + exact FrUbP.sub hs (by rw [← hsc]; exact hf x hx) + obtain ⟨p', r', hnc'⟩ : ∃ p' r', nc = .Frame p' .Small r' false false false 0#u64 0#u64 := by + obtain ⟨p, p', sz, r, r', m, e, a'', v, k, hsc', hnc', hp, hk'⟩ := hs + exact ⟨p', r', hnc'⟩ + have V' : VcCap st Vc OS a' := fun z hz => by + by_cases e1 : z = y + · rw [e1, ed, hnc']; exact fun _ h => by cases h + · rw [hk z hz e1]; exact I.vc z hz + have SS : SubSlots st OS a a' := fun z hz => by + by_cases e1 : z = y + · rw [e1]; exact Or.inr ⟨hy0, p', r', by rw [ed, hnc']⟩ + · exact Or.inl (hk z hz e1) + have KL : ArmVsK st H OS Vc sL a' ∧ FrC st OS sL a' := + ⟨ArmVsK.transF I.kl.1 I.kl.2 K2, FrC.trans' I.kl.2 FC⟩ + exact ⟨⟨hS2.1, hS2.2, ⟨_, (W7.blk_of_capw hbk w2 fun _ h => h).1⟩, V', q2, z2, KL, + SubSlots.trans I.slots SS⟩, hxk, ed, hk⟩ + +/-! ## The loop -/ + +theorem shl12_val {i : U64} (h : i.val < 2 ^ 52) : (i <<< 12#i32 : Result U64) ⦃ z => z.val = i.val * 4096 ⦄ := by + rw [CapRt.shl_eq i 12#i32 (by decide) (by decide), WP.spec_ok] + show (i.bv <<< (12#i32 : I32).toNat).toNat = i.val * 4096 + rw [BitVec.toNat_shiftLeft] + have e : (12#i32 : I32).toNat = 12 := by decide + rw [e, Nat.shiftLeft_eq] + have h2 : i.val * 2 ^ 12 < 2 ^ 64 := by + have : i.val * 2 ^ 12 < 2 ^ 52 * 2 ^ 12 := Nat.mul_lt_mul_of_pos_right h (by norm_num) + simpa using this + have hv : i.bv.toNat = i.val := rfl + rw [hv, Nat.mod_eq_of_lt h2] + norm_num + +theorem largeBits {bits : U64} (h : capability.FrameSize.bits .Large = ok bits) : bits.val = 21 := by + have e : capability.FrameSize.bits .Large = ok 21#u64 := rfl + rw [e] at h + have h' := okinj h + rw [← h'] + rfl + +/-- **A `Small` frame inside a `Large` frame: a `SubA`** (`p' = p + k·4096`, the `Large` frame `[p, p + 2^21)`). -/ +theorem subA_large {p p' r r' a v : U64} {m e : Bool} {k : Nat} (hp' : p'.val = p.val + k * 4096) + (hk : k * 4096 + 4096 ≤ 2 ^ 21) (hfit : p.val + 2 ^ 21 ≤ 2 ^ 64) : + SubA (.Frame p' .Small r' false false false 0#u64 0#u64) (.Frame p .Large r false m e a v) := by + have f1 := frA_size (ptr := p) (rights := r) (x3 := a) (x4 := v) (dv := false) (x1 := m) (x2 := e) + (size := .Large) (bits := 21#u64) rfl + have f2 := frA_size (ptr := p') (rights := r') (x3 := 0#u64) (x4 := 0#u64) (dv := false) (x1 := false) + (x2 := false) (size := .Small) (bits := 12#u64) rfl + have e12 : (12#u64 : U64).val = 12 := rfl + have e21 : (21#u64 : U64).val = 21 := rfl + have b1 : baseA (.Frame p' .Small r' false false false 0#u64 0#u64) = p'.val := by + unfold baseA; rw [f2.1] + have b2 : baseA (.Frame p .Large r false m e a v) = p.val := by + unfold baseA; rw [f1.1] + have t1 : topA (.Frame p' .Small r' false false false 0#u64 0#u64) = p'.val + 4095 := by + unfold topA + rw [f2.1, f2.2.1, wa_val, mskA_val (by rw [e12]; norm_num), e12] + have h1 : (2 : Nat) ^ 12 - 1 = 4095 := by norm_num + rw [h1] + exact Nat.mod_eq_of_lt (by omega) + have t2 : topA (.Frame p .Large r false m e a v) = p.val + (2 ^ 21 - 1) := by + unfold topA + rw [f1.1, f1.2.1, wa_val, mskA_val (by rw [e21]; norm_num), e21] + exact Nat.mod_eq_of_lt (by omega) + refine ⟨f2.2.2.2.2, f1.2.2.2.2, f2.2.2.2.1, f1.2.2.2.1, ?_, ?_⟩ + · refine ⟨?_, ?_⟩ + · rw [b1, b2]; omega + · rw [t1, t2]; omega + · rw [b1, t1]; omega + +set_option maxHeartbeats 4000000 in +/-- **`vspace.insert_subframes` keeps `SubInv`** (module docstring). -/ +theorem vspace.insert_subframes.subS (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) + (hW : WinOK H.tcbs H.omega) {Ω' Sg' Scs' Vc' Ub' Pt' : Set U64} {Z' : U64 → Nat} {s0 sL : S} + (hvr : VrOK Ω' Sg' Scs' Z' OS Vc' Ub' (L.ksb s0) Pt') (hk0 : L.ksb sL = L.ksb s0) + (I : SubInv st H Cs OS Vc ia ie s0 sL sL) {src dest first base count vm p r a v : U64} {m e : Bool} + (hx : src ∈ OS) (hsc : capA st sL src = .Frame p .Large r false m e a v) + (hcv : ∀ j : U64, j.val < count.val → slotIdx dest (wa first j) ∈ OS ∧ SlotCov st OS sL (slotIdx dest (wa first j))) + (hnull : ∀ j : U64, j.val < count.val → capA st sL (slotIdx dest (wa first j)) = .Null) + (hinj : ∀ j l : U64, j.val < count.val → l.val < count.val → + slotIdx dest (wa first j) = slotIdx dest (wa first l) → j = l) + (hcnt : count.val ≤ 512) (hfit : p.val + 2 ^ 21 ≤ 2 ^ 64) (hvm : vm.val < 4) + (hgeo : ∀ i z : U64, i.val < count.val → z.val = i.val * 4096 → + ∃ k, (wa base z).val = p.val + k * 4096 ∧ k * 4096 + 4096 ≤ 2 ^ 21) + (hcan : ∀ i z : U64, i.val < count.val → z.val = i.val * 4096 → CapRt.Canonical (wa base z)) : + vspace.insert_subframes st sL (src) dest first base count vm ⦃ s' => + SubInv st H Cs OS Vc ia ie s0 sL s' ∧ capA st s' src = .Frame p .Large r false m e a v ⦄ := by + unfold vspace.insert_subframes vspace.insert_subframes_loop + apply loop.spec_decr_nat (measure := fun y : S × U64 => count.val - y.2.val) + (inv := fun y => SubInv st H Cs OS Vc ia ie s0 sL y.1 ∧ capA st y.1 src = .Frame p .Large r false m e a v ∧ + y.2.val ≤ count.val ∧ ∀ j : U64, y.2.val ≤ j.val → j.val < count.val → + capA st y.1 (slotIdx dest (wa first j)) = .Null) + · rintro ⟨s3, i3⟩ ⟨h3, hx3, hi3, hn3⟩ + simp only at h3 hx3 hi3 hn3 + dsimp only + unfold vspace.insert_subframes_loop.body + split + · rename_i hlt + have hlt' : i3.val < count.val := by simpa using hlt + refine WP.spec_bind (shl12_val (by omega)) fun i1 hi1 => ?_ + try simp only [lift, bind_ok] + have hidx : obj.Slot.index dest (wa first i3) = ok (slotIdx dest (wa first i3)) := by + unfold obj.Slot.index + simp only [lift, bind_ok, cte_size] + rfl + rw [hidx, bind_ok] + obtain ⟨hy, hcov⟩ := hcv i3 hlt' + have hcov3 : SlotCov st OS s3 (slotIdx dest (wa first i3)) := hcov.keepSub h3.slots + obtain ⟨k, hk1, hk2⟩ := hgeo i3 i1 hlt' hi1 + have hs : IsSubFr (.Frame (wa base i1) .Small vm false false false 0#u64 0#u64) + (.Frame p .Large r false m e a v) := + ⟨p, wa base i1, .Large, r, vm, m, e, a, v, k, rfl, rfl, hk1, fun bits hb => by rw [largeBits hb]; exact hk2⟩ + have hw : CapRt.EncWf (.Frame (wa base i1) .Small vm false false false 0#u64 0#u64) := by + simp only [CapRt.EncWf] + exact ⟨hcan i3 i1 hlt' hi1, hvm, by decide, Or.inl fun j hj _ => by simp⟩ + have hSub := subA_large (r' := vm) (r := r) (a := a) (v := v) (m := m) (e := e) hk1 hk2 hfit + refine WP.spec_bind (cdt.insert.subStep hH hO hW hvr hk0 h3 hs hw hSub hx hy hx3 (hn3 i3 le_rfl hlt') + hcov3) fun s4 h4 => ?_ + obtain ⟨hI4, hx4, hed, hk4⟩ := h4 + step as ⟨i4, hi4⟩ + refine ⟨hI4, hx4, by omega, ?_, by omega⟩ + intro j hj1 hj2 + have hne : slotIdx dest (wa first j) ≠ slotIdx dest (wa first i3) := fun e' => + absurd (hinj j i3 hj2 hlt' e') (fun e'' => by rw [e''] at hj1; omega) + rw [hk4 _ (hcv j hj2).1 hne] + exact hn3 j (by omega) hj2 + · rename_i hge + have hge' : count.val ≤ i3.val := by simpa using hge + exact (WP.spec_ok _).2 ⟨h3, hx3⟩ + · exact ⟨I, hsc, by simp, fun j _ hj => hnull j hj⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aSubRun.lean b/proofs/Fl4ProofsA64/P1/S1aSubRun.lean new file mode 100644 index 000000000..7aa95ace9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aSubRun.lean @@ -0,0 +1,136 @@ +/- +P1 (aarch64, E0.4): **the destination run of `DeriveSubframe`**: `vspace.ensure_empty_run` answering `Ok` empties the +window's slots, and the window's slots are pairwise distinct (the run lies inside one CNode object, which fits). + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aSubDest +import Fl4ProofsA64.P1.MdbIrqC +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} +variable {Cs : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +variable {OS : Set U64} {ia ie : Nat} + +theorem obj.Slot.index_eq (dest i : U64) : obj.Slot.index dest i = ok (slotIdx dest i) := by + unfold obj.Slot.index + simp only [lift, bind_ok, cte_size] + rfl + +/-- A slot index's value (no wrap). -/ +theorem slotIdx_valS {t i : U64} (h : t.val + 32 * i.val + 32 ≤ 2 ^ 64) : + (slotIdx t i).val = t.val + 32 * i.val := by + unfold slotIdx + simp [core.num.U64.wrapping_add_val_eq, core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits] + rw [Nat.mod_eq_of_lt (by omega)] + omega + +/-- The loop of `ensure_empty_run` from `i`, with every slot below `i` null so far. -/ +theorem vspace.ensure_empty_run_loop.null (s : S) (dest first count : U64) (i : U64) (hi : i.val ≤ count.val) + (hprev : ∀ j : U64, j.val < i.val → capA st s (slotIdx dest (wa first j)) = .Null) : + vspace.ensure_empty_run_loop st s dest first count i ⦃ r => r = .Ok () → + ∀ j : U64, j.val < count.val → capA st s (slotIdx dest (wa first j)) = .Null ⦄ := by + unfold vspace.ensure_empty_run_loop + apply loop.spec_decr_nat (measure := fun x : U64 => count.val - x.val) + (inv := fun x : U64 => x.val ≤ count.val ∧ + ∀ j : U64, j.val < x.val → capA st s (slotIdx dest (wa first j)) = .Null) + · rintro i1 ⟨w1, w2⟩ + unfold vspace.ensure_empty_run_loop.body + by_cases hlt : i1 < count + · rw [if_pos hlt] + have hlt' : i1.val < count.val := hlt + simp only [lift, bind_ok] + rw [obj.Slot.index_eq, bind_ok] + refine WP.spec_bind (cdt.ensure_empty_slot.nullS s _) fun r hr => ?_ + cases r with + | Ok u => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + step as ⟨i2, hi2⟩ + have hi2' : i2.val = i1.val + 1 := by scalar_tac + have hn := hr rfl + try rw [WP.spec_ok] + refine ⟨by omega, fun j hj => ?_, by omega⟩ + by_cases hk : j.val < i1.val + · exact w2 j hk + · have : j = i1 := UScalar.eq_of_val_eq (by omega) + rw [this]; exact hn + | Err e => + 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] + intro e'; cases e' + · rw [if_neg hlt, WP.spec_ok] + intro _ j hj + exact w2 j (by have : ¬ i1.val < count.val := hlt; omega) + · exact ⟨hi, hprev⟩ + +/-- **`ensure_empty_run` answering `Ok` empties its window.** -/ +theorem vspace.ensure_empty_run.null {s : S} {dest first count : U64} + (h : vspace.ensure_empty_run st s dest first count = ok (.Ok ())) : + ∀ j : U64, j.val < count.val → capA st s (slotIdx dest (wa first j)) = .Null := by + have h1 := vspace.ensure_empty_run_loop.null (st := st) s dest first count 0#u64 (by simp) + (fun j hj => absurd hj (by simp)) + unfold vspace.ensure_empty_run at h + rw [h, WP.spec_ok] at h1 + exact h1 rfl + +/-- **The window's slots are pairwise distinct** (the CNode object fits in the address space). -/ +theorem vspace.subframe_dest.inj (hH : HeapOK H) {s : S} + (B : SysL st H Cs OS ia ie s) {no cnt dest : U64} + (hex : ∃ y ∈ OS, ∃ rd g b, capA st s y = .CNode dest rd g b ∧ no.val + cnt.val ≤ 2 ^ rd.val) : + ∀ j l : U64, j.val < cnt.val → l.val < cnt.val → + slotIdx dest (wa no j) = slotIdx dest (wa no l) → j = l := by + obtain ⟨y, hy, rd, g, b, hc, hle⟩ := hex + have hcn : CnOP H (.CNode dest rd g b) := by rw [← hc]; exact B.cn y hy + have hp := hcn.1 dest rd g b rfl + have hf := hH.fits dest _ hp + have hl := hH.lt64 dest _ hp + simp only [HKind.bits] at hf hl + have hK : 2 ^ (rd.val + 5) = 2 ^ rd.val * 32 := by rw [pow_add]; norm_num + have hr : rd.val < 64 := by omega + have v : ∀ i : U64, i.val < cnt.val → (slotIdx dest (wa no i)).val = dest.val + 32 * (no.val + i.val) := by + intro i hi + have h63 : 2 ^ rd.val ≤ 2 ^ 63 := Nat.pow_le_pow_right (by norm_num) (by omega) + have hw : (wa no i).val = no.val + i.val := by + rw [wa_val]; exact Nat.mod_eq_of_lt (by omega) + have := slotIdx_valS (t := dest) (i := wa no i) (by rw [hw]; omega) + rw [this, hw] + intro j l hj hl' he + have e := congrArg UScalar.val he + rw [v j hj, v l hl'] at e + exact UScalar.eq_of_val_eq (by omega) + +/-- `ensure_empty_run`, as a spec. -/ +theorem vspace.ensure_empty_run.spec (s : S) (dest first count : U64) : + vspace.ensure_empty_run st s dest first count ⦃ r => r = .Ok () → + ∀ j : U64, j.val < count.val → capA st s (slotIdx dest (wa first j)) = .Null ⦄ := by + unfold vspace.ensure_empty_run + exact vspace.ensure_empty_run_loop.null s dest first count 0#u64 (by simp) (fun j hj => absurd hj (by simp)) + +/-- **`subframe_dest`'s `Ok dest`: its window's slots are `OS` slots of a held CNode, pairwise distinct.** -/ +theorem vspace.subframe_dest.window {T Ω Sg Rp Nt : Set U64} (hH : HeapOK H) {s : S} + (B : SysL st H Cs OS ia ie s) (hT : SlotTy st T Ω Sg H Rp Nt OS s) {x ni nd no cnt : U64} (hx : x ∈ OS) : + vspace.subframe_dest st s x ni nd no cnt ⦃ r => ∀ d, r = .Ok d → + (∀ j : U64, j.val < cnt.val → slotIdx d (wa no j) ∈ OS ∧ SlotCov st OS s (slotIdx d (wa no j))) ∧ + (∀ j l : U64, j.val < cnt.val → l.val < cnt.val → slotIdx d (wa no j) = slotIdx d (wa no l) → j = l) ⦄ := + WP.spec_mono (vspace.subframe_dest.cnode (ni := ni) (nd := nd) (no := no) (cnt := cnt) hT hx) + fun _ h d hd => ⟨vspace.subframe_dest.slots hT (h d hd), vspace.subframe_dest.inj hH B (h d hd)⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aSubTop.lean b/proofs/Fl4ProofsA64/P1/S1aSubTop.lean new file mode 100644 index 000000000..9fed1181d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aSubTop.lean @@ -0,0 +1,131 @@ +/- +P1 (aarch64, E0.4): **a `Frame` cap at `ARMPageDeriveSubframe`: the decode's label chain, then `derive_subframe`** +(`syscall.decode_invocation` → `vspace.decode` → `vspace.decode_frame`), and the S1a step over it. + +* **`syscall.decode_invocation.deriveSub_armSAt`**: `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ SubSlots`. +* **`S1aKtUt.subSlots`**, **`S1aStepR2K.ofSub`** (`S1aStepR2K.ofKeep'` with `SubSlots` for `OSKeep`: the new caps are + unmapped `Small` frame caps, which R2 does not read and the untyped / KT separation does not constrain). +* **`DecArmS1aSub`** and **`syscall.decode_invocation.s1aStepR2Sub`**: the S1a step for the new arm, a sibling of + `s1aStepR2All` (whose `DecArmS1aAll` is unchanged). + +Named premises: none new. +-/ +import Fl4ProofsA64.P1.S1aSubArm +import Fl4ProofsA64.P1.S1aCAll +import Fl4ProofsA64.P1.S1aKtUtArms +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} +variable {Cs Ac U : Set U64} + +namespace W7 +namespace R +namespace ST + +variable {OS Vc Ub Pt Pp Tb Hr Te Kt Uq : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} +variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-! ## The decode's label chain -/ + +/-- **A `Frame` cap at `ARMPageDeriveSubframe` to `ArmQIAt ∧ TabKeepOrZero ∧ ArmVsK ∧ SubSlots`** (module docstring). -/ +theorem syscall.decode_invocation.deriveSub_armSAt {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {fp : U64} {fsz : capability.FrameSize} {fr : U64} + {fd fm fe : Bool} {fa fv : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame fp fsz fr fd fm fe fa fv) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok (.Frame fp fsz fr fd fm fe fa fv)) (a : A) + (len : U64) (blk call don fp' : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageDeriveSubframe len slot + (.Frame fp fsz fr fd fm fe fa fv) blk call don fp' buf extra ⦃ r s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ + SubSlots st OS s s' ⦄ := by + have h1 : fl4_abi.label.ARMPageDeriveSubframe ≠ fl4_abi.label.ARMPageMap := lbl_ne_of_val (by + simp [fl4_abi.label.ARMPageDeriveSubframe, fl4_abi.label.ARMPageMap]) + have h2 : fl4_abi.label.ARMPageDeriveSubframe ≠ fl4_abi.label.ARMPageUnmap := lbl_ne_of_val (by + simp [fl4_abi.label.ARMPageDeriveSubframe, fl4_abi.label.ARMPageUnmap]) + have h3 : fl4_abi.label.ARMPageDeriveSubframe ≠ fl4_abi.label.ARMPageGetAddress := lbl_ne_of_val (by + simp [fl4_abi.label.ARMPageDeriveSubframe, fl4_abi.label.ARMPageGetAddress]) + have h4 : fl4_abi.label.ARMPageDeriveSubframe ≠ fl4_abi.label.ARMPageTestAndClearAccessed := lbl_ne_of_val (by + simp [fl4_abi.label.ARMPageDeriveSubframe, fl4_abi.label.ARMPageTestAndClearAccessed]) + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + unfold vspace.decode + step with sched.cur_thread.spec as ⟨ct', _⟩ + try dsimp only + unfold vspace.decode_frame + simp only [vspace.as_frame, bind_ok] + step with sched.cur_thread.spec as ⟨ct'', ect⟩ + have e : ct'' = L.curW s := ect + subst e + refine spec_ite (fun hc => absurd hc h1) (fun _ => ?_) + refine spec_ite (fun hc => absurd hc h2) (fun _ => ?_) + rw [vspace.is_cache_label.derive, bind_ok] + refine spec_ite (fun hc => absurd hc Bool.false_ne_true) (fun _ => ?_) + refine spec_ite (fun hc => absurd hc h3) (fun _ => ?_) + refine spec_ite (fun hc => absurd hc h4) (fun _ => ?_) + refine spec_ite (fun _ => ?_) (fun hc => absurd trivial hc) + refine WP.spec_bind (vspace.derive_subframe.armSAt I D P B Y hcap len buf) fun r hr => ?_ + obtain ⟨r1, s1⟩ := r + first + | exact (WP.spec_ok _).2 hr + | (simp only [WP.uncurry'_pair]; exact (WP.spec_ok _).2 hr) + +/-! ## The S1a step -/ + +theorem S1aKtUt.subSlots {s q : S} (h : S1aKtUt st OS Kt s) (sl : SubSlots st OS s q) : S1aKtUt st OS Kt q := + h.slots fun y hy => (sl y hy).imp id fun ⟨_, p, r, e⟩ p' b j d cap => by rw [e] at cap; cases cap + +/-- **`S1aStepR2K.ofKeep'` with `SubSlots` for `OSKeep`** (module docstring). -/ +theorem S1aStepR2K.ofSub {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 ∧ SubSlots st OS s q) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Uq (L.ksb s) Pt) (fu : FrUb st Uq OS s) + (vcc : VcCap st Vc OS s) (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) + (Df : DevFrAl st OS s) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (KC : S1aHiK st OS Kt KLv s) : + S1aStepR2K st Cs Ub Kt KLv ia ie n q := by + obtain ⟨arm, tab, mem, slots⟩ := d + have vs : VsKeep st (L.ksb s) Pt s q := mem.2 Uq Pt vr fu + have R' : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := + R.ofImage mem.1 vs (.ofSame R.capRefs.refs fun y hy => (slots y hy).elim Or.inl fun ⟨e0, p, r, e1⟩ => + Or.inr ⟨by rw [e0]; intro h; exact h, by rw [e1]; intro h; cases h⟩) + obtain ⟨Ub', hsub, hC, hK⟩ := (S1aColU.of arm.1 (S1aArmCol.ofTZ tab C)) + have col : S1aHiK st OS Kt KLv q := KC.keep ⟨EdgeKeepOn.ofVsKeep R vs, arm.hiRoots R.highHeaders⟩ + exact ⟨H, OS, Vc, Ub', Pt, ⟨arm.1, arm.2.1, hsub, arm.2.2.2.1 vcc, hC, hK, arm.ptCap R.pageTables, + arm.hvPt R.hvPt, R.footprint, arm.devFr Df, R'.highHeaders, arm.eptPlaced R.eptRoots, + arm.ptCap R.pageObjects, arm.hvObjects R.highObjects⟩, sep.subSlots slots, R'.ex, col⟩ + +/-- **The invocation `DeriveSubframe` on a `Frame` cap** (the arm beside `DecArmS1aAll`). -/ +def DecArmS1aSub (cap : capability.Cap) (lbl : U64) : Prop := + ∃ fp fsz fr fd fm fe fa fv, cap = .Frame fp fsz fr fd fm fe fa fv ∧ lbl = fl4_abi.label.ARMPageDeriveSubframe + +/-- **The S1a step over `DeriveSubframe`** (module docstring): `s1aStepR2K`'s hypotheses, its post. -/ +theorem syscall.decode_invocation.s1aStepR2Sub {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (Df : DevFrAl st OS s) + (a : A) {lbl : U64} (hc : DecArmS1aSub cap lbl) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) (KC : S1aHiK st OS Kt KLv s) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie n s' ⦄ := by + obtain ⟨fp0, fsz, fr, fd, fm, fe, fa, fv, rfl, rfl⟩ := hc + refine WP.spec_mono (syscall.decode_invocation.deriveSub_armSAt I D P B Y hcap a len blk call don fp buf) + fun r d => ?_ + obtain ⟨_, s', _⟩ := r + exact S1aStepR2K.ofSub d I.del.vr I.fu I.vcc C Kc Df R sep KC + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aSubTree.lean b/proofs/Fl4ProofsA64/P1/S1aSubTree.lean new file mode 100644 index 000000000..a13b20dfb --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aSubTree.lean @@ -0,0 +1,224 @@ +/- +P1 (aarch64, E0.4): **the derivation tree along a subframe insertion** (`vspace.derive_subframe`'s +`insert_subframes` inserts a 4 KiB `Small` frame cap as the child of a `Large` frame cap's slot). + +`cdt.insert_with_cap.tree` / `.tr` take `UA nc sc` (same base and size), which a subframe does not satisfy. The +untyped invariant `UtInvA` only constrains untyped caps and their relation to physical caps, so a non-untyped +physical child whose range lies inside its non-untyped parent's range keeps every field: + +* **`SubA d c`**: `d`, `c` non-untyped physical, `d`'s range within `c`'s, `d`'s range non-wrapping. +* **`UtInvA.insSub`**: the insertion of `dest` after `src` as its child, `src` kept, `dest` a `SubA` of it. +* **`cdt.insert_with_cap.treeSub`** / **`.trSub`**: `tree` / `tr` with `SubA nc sc` in place of `UA nc sc` and + without the (vacuous, `sc` is no untyped cap) `hut`. + +Named premises: none. +-/ +import Fl4ProofsA64.P1.MdbTreeC +import Fl4ProofsA64.P1.MdbInvInsA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +section +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {T : Set U64} {Ω : Set U64} {Sg : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +variable {OS : Set U64} {G : List (List U64)} {par : U64 → Option U64} + +/-- **A non-untyped physical cap inside another's range** (module docstring). -/ +structure SubA (d c : capability.Cap) : Prop where + dnu : isUtA d = false + cnu : isUtA c = false + dph : physA d = true + cph : physA c = true + win : WithinA d c + reg : baseA d ≤ topA d + +set_option maxHeartbeats 2000000 in +/-- **Insertion of `dest` after `src` as its child (`bp`) or its sibling, a `SubA` of the unchanged `src`** (module +docstring): `dest` gets the parent `if bp then some src else par src`. -/ +theorem UtInvA.insSubGen {s s' : S} (hU : UtInvA st OS par s) (hP : ParIn OS par) {src dest : U64} + (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) + (hdp : ∀ z, par z ≠ some dest) (hdn : par dest = none) + (hk : ∀ y ∈ OS, y ≠ dest → capA st s' y = capA st s y) + (hS : SubA (capA st s' dest) (capA st s src)) (bp : Bool) : + UtInvA st OS (Function.update par dest (if bp then some src else par src)) s' := by + have hnp : (if bp then some src else par src) ≠ some dest := by cases bp <;> simp [hsd, hdp src] + have hD : ∀ y x, Mdb.Desc (Function.update par dest (if bp then some src else par src)) y x ↔ + Mdb.Desc par y x ∨ (y = dest ∧ ((bp = true ∧ x = src) ∨ Mdb.Desc par src x)) := by + intro y x + rw [Mdb.desc_update_iff hdp hdn hnp, np_desc_iffA] + have ndD : ∀ x, ¬ Mdb.Desc par dest x := fun x => Mdb.not_desc_of_none hdn + have nDd : ∀ y, ¬ Mdb.Desc par y dest := fun y => Mdb.not_desc_of_no_child hdp + have up : ∀ {a z}, Mdb.Desc par a z → Mdb.Desc (Function.update par dest (if bp then some src else par src)) a z := + fun e => (hD _ _).2 (Or.inl e) + have dn : ∀ {z}, ((bp = true ∧ z = src) ∨ Mdb.Desc par src z) → + Mdb.Desc (Function.update par dest (if bp then some src else par src)) dest z := + fun e => (hD _ _).2 (Or.inr ⟨rfl, e⟩) + obtain ⟨w1, w2⟩ := hS.win + have notUt : ∀ {x p b i : U64} {e : Bool}, capA st s' x = .Untyped p b i e → x ≠ dest := + fun {x p b i e} hc ex => by + have h := hS.dnu + rw [← ex, hc] at h + simp [isUtA] at h + have srcNe : ∀ {x : U64} {p b i : U64} {e : Bool}, capA st s x = .Untyped p b i e → src ≠ x := fun {x p b i e} hc ex => by + have h := hS.cnu + rw [ex, hc] at h + simp [isUtA] at h + refine ⟨fun x hx hp => ?_, fun x hx p b i d hc y hy => ?_, fun x hx p b i d hc y hy hp => ?_, + fun x hx y hy hxy p b i i' d d' hcx hcy => ?_, fun x hx p b i d hc => ?_, + fun x hx p b i d hc y hy hyx hp hd => ?_, fun x y hd hu => ?_⟩ + -- reg + · by_cases e : x = dest + · rw [e]; exact hS.reg + · rw [hk x hx e] at hp ⊢; exact hU.reg x hx hp + -- inc + · have hxd : x ≠ dest := notUt hc + rw [hk x hx hxd] at hc + rcases (hD y x).1 hy with h0 | ⟨hyd, ⟨-, hxs⟩ | h0⟩ + · have hyd : y ≠ dest := fun e => ndD x (by rw [← e]; exact h0) + obtain ⟨hyO, -⟩ := desc_in hP h0 + obtain ⟨g1, g2, g3⟩ := hU.inc x hx p b i d hc y h0 + rw [hk y hyO hyd]; exact ⟨g1, g2, g3⟩ + · exact absurd hxs.symm (srcNe hc) + · obtain ⟨g1, g2, g3⟩ := hU.inc x hx p b i d hc src h0 + rw [hyd] + exact ⟨hS.dph, by omega, by omega⟩ + -- noov + · have hxd : x ≠ dest := notUt hc + rw [hk x hx hxd] at hc ⊢ + by_cases hyd : y = dest + · rw [hyd] + left + rcases hU.noov x hx p b i d hc src hsrc hS.cph with g | ⟨g1, -⟩ + · unfold DisjRA at g ⊢ + omega + · rw [hS.cnu] at g1; simp at g1 + · rw [hk y hy hyd] at hp ⊢ + exact hU.noov x hx p b i d hc y hy hp + -- excl + · have hxd : x ≠ dest := notUt hcx + have hyd : y ≠ dest := notUt hcy + rw [hk x hx hxd] at hcx; rw [hk y hy hyd] at hcy + exact hU.excl x hx y hy hxy p b i i' d d' hcx hcy + -- fib + · have hxd : x ≠ dest := notUt hc + rw [hk x hx hxd] at hc + exact hU.fib x hx p b i d hc + -- drange + · have hxd : x ≠ dest := notUt hc + rw [hk x hx hxd] at hc hd + by_cases hyD : y = dest + · rw [hyD] at hd hp ⊢ + have hd0 : ¬ DisjA (capA st s src) (capA st s x) := by + intro hdisj + apply hd + unfold DisjA at hdisj ⊢ + omega + rcases hU.drange x hx p b i d hc src hsrc (srcNe hc) hS.cph hd0 with g | g + · exact Or.inl (dn (Or.inr g)) + · have h := hU.anc src x g (by rw [hc]; rfl) + rw [hS.cnu] at h; simp at h + · rw [hk y hy hyD] at hp hd + rcases hU.drange x hx p b i d hc y hy hyx hp hd with g | g + · exact Or.inl (up g) + · exact Or.inr (up g) + -- anc + · rcases (hD y x).1 hd with h0 | ⟨hyd, -⟩ + · have hyd : y ≠ dest := fun e => ndD x (by rw [← e]; exact h0) + have hxd : x ≠ dest := fun e => nDd y (by rw [← e]; exact h0) + obtain ⟨hyO, hxO⟩ := desc_in hP h0 + rw [hk y hyO hyd] at hu; rw [hk x hxO hxd]; exact hU.anc x y h0 hu + · rw [hyd, hS.dnu] at hu; simp at hu + +/-- **Insertion of `dest` after `src` as its child, a `SubA` of the unchanged `src`** (`insSubGen` at `bp = true`). -/ +theorem UtInvA.insSub {s s' : S} (hU : UtInvA st OS par s) (hP : ParIn OS par) {src dest : U64} + (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) + (hdp : ∀ z, par z ≠ some dest) (hdn : par dest = none) + (hk : ∀ y ∈ OS, y ≠ dest → capA st s' y = capA st s y) + (hS : SubA (capA st s' dest) (capA st s src)) : + UtInvA st OS (Function.update par dest (some src)) s' := by + simpa using hU.insSubGen hP hsrc hd hsd hdp hdn hk hS true + +set_option maxHeartbeats 2000000 in +/-- **`insert_with_cap` of a subframe as `src`'s child keeps the tree** (module docstring). -/ +theorem cdt.insert_with_cap.treeSub (hO : OSOK T Ω Sg OS) {s : S} (hT : TreeA st OS G par s) {src dest : U64} + {nc sc : capability.Cap} (hsrc : src ∈ G.flatten) (hd : dest ∈ OS) (hd0 : capA st s dest = .Null) + (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hw : CapRt.EncWf nc) (hnc : nc ≠ .Null) + (hA : SubA nc sc) : + cdt.insert_with_cap st s nc sc src dest ⦃ s' => TreeA st OS (insG src dest G) + (Function.update par dest (some src)) s' ⦄ := by + have hM := hT.lk + have h0 : ∀ y ∈ OS, y ≠ 0#u64 := hO.nz + have inOS : ∀ y ∈ G.flatten, y ∈ OS := fun y hy => ((hM.members y).1 hy).1 + have F := hM.lkF h0 + have os := inOS src hsrc + have hs0 : capA st s src ≠ .Null := ((hM.members src).1 hsrc).2 + have hsc0 : sc ≠ .Null := by rw [← hsc]; exact hs0 + have dG : dest ∉ G.flatten := fun hm => ((hM.members dest).1 hm).2 hd0 + have hsd : src ≠ dest := fun e => dG (e ▸ hsrc) + have hNm : NxA st s src ≠ 0#u64 → NxA st s src ∈ G.flatten := F.nxm _ hsrc + have hNd : NxA st s src ≠ dest := fun e => by + have h1 : NxA st s src ≠ 0#u64 := fun e0 => h0 dest hd (e ▸ e0) + exact dG (e ▸ hNm h1) + refine WP.spec_mono (WP.spec_and (cdt.insert_with_cap.lr hO (LR.self s) os hd hsd hdc hsc hsc0 hw + (fun h => inOS _ (hNm h))) (cdt.insert_with_cap.srcU hO os hd hsd hsc hw (fun h => inOS _ (hNm h)))) ?_ + rintro s' ⟨⟨hL, ed, -, ns, ek, -⟩, hsu⟩ + have hk : ∀ y ∈ OS, y ≠ src → y ≠ dest → capA st s' y = capA st s y := ek + have hxk : capA st s' src = capA st s src := by + rcases hsu.1 with e | ⟨p, b, j, e0, j1, es, -, -⟩ + · rw [e, hsc] + · have h := hA.cnu + rw [es] at h + simp [isUtA] at h + have hk' : ∀ y ∈ OS, y ≠ dest → capA st s' y = capA st s y := fun y hy hyd => by + by_cases e : y = src + · rw [e]; exact hxk + · exact hk y hy e hyd + have hLk : MdbLk st OS (insG src dest G) s' := by + refine hM.ins h0 hsrc hd hd0 (by rw [ed]; exact hnc) (fun y hy hyd => ?_) ?_ ?_ ?_ (fun hN => ?_) + (fun y hy h1 h2 => ?_) (fun y hy h1 h2 => ?_) + · by_cases e : y = src + · rw [e] + exact ⟨fun h => absurd h ns, fun h => absurd h hs0⟩ + · rw [hk y hy e hyd] + · rw [(hL src os).2]; simp + · rw [(hL dest hd).1]; simp [hNd.symm] + · rw [(hL dest hd).2]; simp [hsd.symm] + · rw [(hL _ (inOS _ (hNm hN))).1]; simp [hN] + · rw [(hL y hy).2]; simp [h1, h2] + · rw [(hL y hy).1]; simp [h1, h2] + refine ⟨hLk, by rw [insG_eq]; exact hT.tree.insert hsrc dG (Or.inl rfl), ?_⟩ + refine hT.ut.insSub hT.parIn os hd hsd (fun z e => dG (hT.tree.par_mem z dest e).2) ?_ hk' ?_ + · cases e : par dest with + | none => rfl + | some q => exact absurd (hT.tree.par_mem dest q e).1 dG + · rw [ed, hsc]; exact hA + +/-- **`insert_with_cap` of a subframe keeps `TR`** (`treeSub` + `utRev`). -/ +theorem cdt.insert_with_cap.trSub (hO : OSOK T Ω Sg OS) {G : List (List U64)} {par : U64 → Option U64} {s : S} + (hT : TreeA st OS G par s) (hR : UtRev st OS s) {src dest : U64} {nc sc : capability.Cap} + (hsrc : src ∈ OS) (hs0 : capA st s src ≠ .Null) (hd : dest ∈ OS) (hd0 : capA st s dest = .Null) + (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hw : CapRt.EncWf nc) (hnc : nc ≠ .Null) + (hA : SubA nc sc) : + cdt.insert_with_cap st s nc sc src dest ⦃ s' => TR st OS s' ⦄ := by + have hsG : src ∈ G.flatten := (hT.lk.members src).2 ⟨hsrc, hs0⟩ + have F := hT.lk.lkF hO.nz + have hsd : src ≠ dest := fun e => hs0 (by rw [e]; exact hd0) + exact WP.spec_mono (WP.spec_and (cdt.insert_with_cap.treeSub hO hT hsG hd hd0 hdc hsc hw hnc hA) + (cdt.insert_with_cap.utRev hO hR hsrc hd hsd hdc hsc (by rw [← hsc]; exact hs0) hw + (fun h => ((hT.lk.members _).1 (F.nxm _ hsG h)).1))) fun _ ⟨h1, h2⟩ => ⟨⟨_, _, h1⟩, h2⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aVsUnmB.lean b/proofs/Fl4ProofsA64/P1/S1aVsUnmB.lean index 3cd519874..aa24bfaf2 100644 --- a/proofs/Fl4ProofsA64/P1/S1aVsUnmB.lean +++ b/proofs/Fl4ProofsA64/P1/S1aVsUnmB.lean @@ -859,7 +859,7 @@ private theorem w1_pathBacking (n : U64) (Re bits : U64 → Nat) : rw [if_neg (by decide), wv (by omega : 4194304 + j * 4096 < 2 ^ 64)] rfl refine ⟨x, hx, .Small, 3#u64, false, _, rfl, cap, addr, Or.inr ⟨_, 12, ?_, le_rfl, le_rfl⟩⟩ - have old := w1_frameOK P x hx _ .Small _ true false _ _ cap 12#u64 (by rfl) + have old := w1_frameObj P hx cap (bits := 12#u64) (by rfl) exact (Heap.add_of_not (N := (· ∈ ({bwv KTb} : Set U64))) (kd := .other 12) (fun h => off (Set.mem_singleton_iff.1 h))).trans old @@ -1025,8 +1025,7 @@ private theorem w1_pathBackingPlain (n : U64) (Re bits : U64 → Nat) : rw [if_neg (by decide), wv (by omega : 4194304 + j * 4096 < 2 ^ 64)] rfl refine ⟨x, hx, .Small, 3#u64, false, _, rfl, cap, addr, Or.inr ⟨_, 12, ?_, le_rfl, le_rfl⟩⟩ - have old := w1_frameOK P x hx _ .Small _ true false _ _ cap 12#u64 (by rfl) - exact old + exact w1_frameObj P hx cap (bits := 12#u64) (by rfl) set_option maxRecDepth 20000 in set_option maxHeartbeats 4000000 in diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2EntryA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2EntryA.lean index dea8c12d5..7461664b0 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2EntryA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2EntryA.lean @@ -22,7 +22,7 @@ noncomputable section open Fl4ProofsA64.P3.Wit2 (WA AR1) -variable {c0 r now mt sl : U64} {uw : U64 → U64} +variable {c0 : WitMsg} {r now mt sl : U64} {uw : U64 → U64} local notation "S2" => witSc c0 r now mt sl uw local notation "RT" => (bwv RTb) @@ -68,14 +68,14 @@ 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 {c0 mt sl : U64} {uw : U64 → U64} : +theorem wit_rawNext {c0 : WitMsg} {mt sl : U64} {uw : U64 → U64} : Sched.rawNextA (witSAc c0 wNow mt sl uw).machineState = wTick := rfl -theorem wit_counterStep {c0 mt sl : U64} {uw : U64 → U64} : Sched.CounterStepA (witSAc c0 wNow mt sl uw) := by +theorem wit_counterStep {c0 : WitMsg} {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) {c0 mt sl : U64} {uw : U64 → U64} : +theorem wit_hNow (O : Wit2.OpaqueWA) {c0 : WitMsg} {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 @@ -89,7 +89,7 @@ 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) {c0 mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) +theorem wit_hsuf (O : Wit2.OpaqueWA) {c0 : WitMsg} {mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) {σ1 : Fl4SpecA64.State Unit} (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 @@ -113,7 +113,7 @@ theorem wit_hsuf (O : Wit2.OpaqueWA) {c0 mt sl : U64} {uw : U64 → U64} (hsl : /-! ## The VSpace words are not the preemption point's -/ -theorem wit_hvp {c0 r now mt sl : U64} {uw : U64 → U64} : +theorem wit_hvp {c0 : WitMsg} {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 (witSc c0 r now mt sl uw) b := by @@ -164,7 +164,7 @@ theorem wit_hvp {c0 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) {c0 r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) +theorem wit_budget_id (O : Wit2.OpaqueWA) {c0 : WitMsg} {r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (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) ∧ diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2TierA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2TierA.lean index d34eefcfd..29f14f46b 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2TierA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2TierA.lean @@ -105,7 +105,7 @@ theorem wit_pollAgree (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMa /-! ## The fault handler of the root thread is `Null` -/ -theorem wit_faultCap {c0 r now mt sl : U64} {uw : U64 → U64} : +theorem wit_faultCap {c0 : WitMsg} {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 @@ -130,13 +130,13 @@ theorem wit_faultCap {c0 r now mt sl : U64} {uw : U64 → U64} : /-! ## The entry record and the charge -/ /-- The record at the entry of the witness. -/ -abbrev WitJ (Z : XSetsA) (c0 r now mt sl : U64) (uw : U64 → U64) (s : BS) (a : WA) (σ : Fl4SpecA64.State Unit) : Prop := +abbrev WitJ (Z : XSetsA) (c0 : WitMsg) (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) {c0 r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) +theorem wit_entryIn (O : OpaqueWA) {c0 : WitMsg} {r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) (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 @@ -157,7 +157,7 @@ theorem wit_entryIn (O : OpaqueWA) {c0 r mt sl : U64} {uw : U64 → U64} (hsl : 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 {c0 mt sl : U64} {uw : U64 → U64} : +theorem wit_pc {c0 : WitMsg} {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)) := @@ -182,7 +182,7 @@ theorem wit_pc {c0 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) {c0 r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (a : WA) : +theorem wit_hCharge (O : OpaqueWA) {c0 : WitMsg} {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 @@ -206,7 +206,7 @@ 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} {c0 r mt sl : U64} {uw : U64 → U64} {ab : WA} {τ : Fl4SpecA64.State Unit} +theorem wit_faultHandler_null {Z : XSetsA} {c0 : WitMsg} {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 @@ -232,7 +232,7 @@ theorem wit_faultHandler_null {Z : XSetsA} {c0 r mt sl : U64} {uw : U64 → U64} 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 } 2#u64 r wNow mt sl uw (witS r wNow mt sl uw) ab τ) : + (Jr : WitJ { witZA with Q := Q, R := Rl } WitMsg.copy 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 @@ -284,14 +284,10 @@ theorem wit_scope (O : OpaqueWA) (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA6 /-- **`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 {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) : +theorem wit_kRunsG {c0 : WitMsg} {r mt sl : U64} {uw : U64 → U64} (number : I64) (rep : Bool) + (call : Fl4SpecA64.Syscall) + (rng : ¬ number < fl4_abi.syscall.SYSCALL_MIN ∧ ¬ number > fl4_abi.syscall.SYSCALL_MAX) : 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 (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) = @@ -315,6 +311,16 @@ theorem wit_kRuns {c0 r mt sl : U64} {uw : U64 → U64} (number : I64) (rep : Bo · rw [flags_ok, hf] · first | simp | (apply UScalar.eq_of_val_eq; simp) +theorem wit_kRuns {c0 : WitMsg} {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 (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) + exact wit_kRunsG number rep call rng + /-- The witness's `r` exists: FL4's pointer of the spec's global page-table pointer. -/ theorem wit_r_ex : ∃ r : U64, specPtr r = Fl4SpecA64.armGlobalPtPtr := ⟨fl4Ptr Fl4SpecA64.armGlobalPtPtr, by diff --git a/proofs/Fl4ProofsA64/P3/A64Wit2bBodyA.lean b/proofs/Fl4ProofsA64/P3/A64Wit2bBodyA.lean index bc7eb924a..641e6c1cd 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit2bBodyA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit2bBodyA.lean @@ -169,10 +169,10 @@ local instance witPlainB : PlainStore bst := ⟨fun _ => rfl⟩ local notation "SL2" => (bwv (RRb + 64)) 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 +/-- No thread of `witSAc c0` runs a guest: its TCBs are the running root and the idle ones. -/ +theorem wit_noVmC {c0 : WitMsg} {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 2#u64))) p = some (.tcb x) at hp + 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 @@ -182,10 +182,13 @@ theorem wit_noVm {now mt sl : U64} {uw : U64 → U64} : NoVmA (witSA now mt sl u unfold w1KA bootKA at hp split_ifs at hp <;> cases hp <;> cases v +/-- No thread of the Send witness's spec state runs a guest. -/ +theorem wit_noVm {now mt sl : U64} {uw : U64 → U64} : NoVmA (witSA now mt sl uw) := wit_noVmC + 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 2#u64 r wNow mt sl uw (witS r wNow mt sl uw) ab τ) + {τ : Fl4SpecA64.State Unit} (Jr : WitJ Z WitMsg.copy 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 @@ -196,7 +199,7 @@ theorem wit_invoke_okVm {Z : XSetsA} {r mt sl : U64} {uw : U64 → U64} (U : Wit rw [curW2] have e : layout.reg.CAP = 0#u64 := by simp [layout.reg.CAP, layout.reg.X0] rw [e, wit_regWord 0#u64 (by simp)] - simp [witRtW] + simp [witRtW, WitMsg.copy] rw [cp] at hy have einfo : msg.msg_info bst (witS r wNow mt sl uw) (bL.curW (witS r wNow mt sl uw)) = ok { label := 24#u64, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := 5#u64 } := by diff --git a/proofs/Fl4ProofsA64/P3/A64Wit3RunA.lean b/proofs/Fl4ProofsA64/P3/A64Wit3RunA.lean index ed03b5799..bb4d11831 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit3RunA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit3RunA.lean @@ -50,7 +50,7 @@ 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)) := +theorem witTs_tcb : (witTs mt sl uw).kheap (witTs mt sl uw).curThread = some (.tcb (witTcbA WitMsg.copy)) := Function.update_self _ _ _ /-- **A state that agrees with the time-stamp state on the heap, the current thread and SC, and has consumed `0`** @@ -68,7 +68,7 @@ theorem WitLike.sc (h : WitLike mt sl uw σ) : 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 + σ.kheap (witTs mt sl uw).curThread = some (.tcb (witTcbA WitMsg.copy)) := by rw [h.1]; exact witTs_tcb /-- **The head refill is sufficient** (the spec's `getScRefillSufficient`). -/ diff --git a/proofs/Fl4ProofsA64/P3/A64Wit3TopA.lean b/proofs/Fl4ProofsA64/P3/A64Wit3TopA.lean index 39cf7f2fe..c59e7df20 100644 --- a/proofs/Fl4ProofsA64/P3/A64Wit3TopA.lean +++ b/proofs/Fl4ProofsA64/P3/A64Wit3TopA.lean @@ -30,7 +30,7 @@ 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)) := + have hk : (witSA wNow mt sl uw).kheap (witSA wNow mt sl uw).curThread = some (.tcb (witTcbA WitMsg.copy)) := Function.update_self _ _ _ rw [hk] at hx obtain rfl := KernelObject.tcb.inj (Option.some.inj hx) diff --git a/proofs/Fl4ProofsA64/P3/A64WitCopyA.lean b/proofs/Fl4ProofsA64/P3/A64WitCopyA.lean index 353e5ee3a..37fd9df20 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitCopyA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitCopyA.lean @@ -13,7 +13,7 @@ current (root) thread's `Send` on CPtr `2` (its CSpace's root CNode cap) is a `C Hypotheses: the two IPC-buffer words (`WitUw`). No premise. New module; no existing statement changed. -/ -import Fl4ProofsA64.P3.A64WitSyscA +import Fl4ProofsA64.P3.A64WitReadA import Fl4ProofsA64.P0.Auto import Fl4ProofsA64.P1.LocalVcpuKeep import Fl4ProofsA64.P1.VcpuHooks @@ -39,13 +39,6 @@ theorem witUw_ex : ∃ uw, WitUw uw := ⟨fun b => if b.val = IPb + 976 then 2#u64 else 15#u64, ⟨fun _ h => if_pos h, fun _ h => if_neg (by omega)⟩⟩ -/-- The concrete store is total (A64 P0's `StoreTotal`). -/ -theorem bstTotal : Fl4ProofsA64.P0.StoreTotal bst := - ⟨fun _ => (WP.spec_ok _).2 trivial, fun _ _ => (WP.spec_ok _).2 trivial, fun _ _ => (WP.spec_ok _).2 trivial, - fun _ _ _ => (WP.spec_ok _).2 trivial, fun _ _ _ => (WP.spec_ok _).2 trivial, - fun _ _ _ => (WP.spec_ok _).2 trivial, fun _ => (WP.spec_ok _).2 trivial, fun _ => (WP.spec_ok _).2 trivial, - fun _ _ _ => (WP.spec_ok _).2 trivial⟩ - variable {r now mt sl : U64} {uw : U64 → U64} local notation "S1" => w1S KB IB 1 r now mt sl uw @@ -55,75 +48,11 @@ 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 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) - rw [vRT] at h - show (Endp.regA RT i).val = _ - omega - exact congrArg ok (wit_rtWords _ _ (by omega) (by omega) (by rw [v, vRT])) - -theorem ipb_word {k : Nat} (hk : k < 512) {b : U64} (hb : b.val = IPb + 8 * k) : bL.mem S2 b = uw b := by - have e : bL.mem S2 b = bL.mem S1 b := ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) - rw [e] - change w1M KB IB 1 r now mt sl uw b = _ - rw [w1M_root lay1 (o := 401408 + 8 * k) (by omega) (by omega)] - unfold rootW - rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos (by omega)] - -theorem bufGet {k : U64} (hk : k.val < 512) {b : U64} (hb : b.val = IPb + 8 * k.val) : - msg.buf_get bst S2 (bwv IPb) k = ok (uw b) := by - rw [buf_get_eqA] - have e : bufWA (bwv IPb) k = b := by - apply UScalar.eq_of_val_eq - unfold bufWA - have e8 : (8#u64 : U64).val = 8 := rfl - rw [wa_valm, core.num.U64.wrapping_mul_val_eq, vIP, hb, e8] - have : UScalar.size UScalarTy.U64 = 2 ^ 64 := by simp [U64.size_def, U64.numBits] - rw [this, Nat.mod_eq_of_lt (by omega), Nat.mod_eq_of_lt (by omega)] - omega - rw [e, ipb_word hk hb] - -/-- A root CNode slot is not changed. -/ -theorem capS2_rs {x : U64} {i : Nat} (hi : i < 8192) (hx : x.val = RRb + 32 * i) : capA bst S2 x = capOf 1 i := by - rw [← cap_root (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) lay1 hi hx] - have h8 : (wa x 8#u64).val = RRb + 32 * i + 8 := by - rw [wa_valm, hx]; simp; omega - have e1 : bL.mem S2 x = bL.mem S1 x := ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) - have e2 : bL.mem S2 (wa x 8#u64) = bL.mem S1 (wa x 8#u64) := ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) - unfold capA - rw [e1, e2] - -/-- A root TCB slot is not changed. -/ -theorem capS2_ts {i : U64} (hi : i.val < 7) : capA bst S2 (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 S2 (slotIdx RT i) = bL.mem S1 (slotIdx RT i) := - ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) - have e2 : bL.mem S2 (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_ok (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 prefix lookups -/ - /-- **`msg_info`**: label `CNodeCopy`, one extra cap, length 5. -/ 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 2#u64 (256 + 8 * (1#u64 : U64).val) = 98437#u64 := by simp [witRtW] + have v : witRtW WitMsg.copy (256 + 8 * (1#u64 : U64).val) = 98437#u64 := by simp [witRtW, WitMsg.copy] 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 @@ -141,180 +70,12 @@ theorem wit_msgInfo : msg.msg_info bst S2 RT = simp only [bind_ok, m1, m2, m3] rw [if_neg le] -theorem wit_ipcBuffer : msg.lookup_ipc_buffer bst S2 false RT = ok (bwv IPb) := by - have ipo : layout.tcb.IPC_BUFFER = ok 3512#u64 := by - unfold layout.tcb.IPC_BUFFER layout.tcb.F; rfl - have w : obj.Tcb.ipc_buffer bst RT S2 = ok (bwv 4198400) := by - unfold obj.Tcb.ipc_buffer - rw [ipo] - simp only [bind_ok, lift] - have v : (wa RT 3512#u64).val = RTb + 3512 := by - rw [fldV rtMem1 (by simp), vRT]; simp - refine congrArg ok ?_ - exact (wit_rtWords _ 3512 (by omega) (by omega) (by rw [v, vRT])).trans (by simp [witRtW, rtW]) - have sb : layout.tcb.SLOT_BUFFER = 2#u64 := by simp [layout.tcb.SLOT_BUFFER] - have c : capA bst S2 (slotIdx RT 2#u64) = .Frame (bwv IPb) .Small 3#u64 false false false 0#u64 (bwv 0) := by - rw [capS2_ts (by simp), cap_rt lay1 (by simp)] - simp - unfold msg.lookup_ipc_buffer - rw [w, bind_ok, sb, tcbSlot_ok 2#u64 (by simp), bind_ok, capA_eq, c, bind_ok] - have rw3 : (3#u64 : U64) = capability.VM_READ_WRITE := by simp [capability.VM_READ_WRITE] - simp only [Bool.false_eq_true, if_false, rw3, if_true] - have fb : capability.FrameSize.bits .Small = ok 12#u64 := by rfl - have s1 : (12#u64 : U64) &&& 63#u64 = 12#u64 := by rfl - have s2 : (1#u64 : U64) <<< (12#u64 : U64) = ok 4096#u64 := by rfl - have s3 : core.num.U64.wrapping_sub 4096#u64 1#u64 = 4095#u64 := by rfl - have s4 : (bwv 4198400) &&& 4095#u64 = 0#u64 := by rfl - have s5 : wa (bwv IPb) 0#u64 = bwv IPb := by - apply UScalar.eq_of_val_eq - rw [wa_valm, vIP]; simp - rw [fb, bind_ok] - simp only [lift, bind_ok, s1] - rw [s2, bind_ok] - simp only [bind_ok, s3, s4, s5] - -/-- **The CSpace walk of the root CNode**: one level, 13 bits behind a 51-bit zero guard. -/ -theorem wit_resolve {cptr : U64} (hc : cptr.val < 8192) {slot : U64} (hs : slot.val = RRb + 32 * cptr.val) : - cspace.resolve_address_bits bst S2 RC cptr 64#u64 = ok (.Ok { slot := slot, bits_left := 0#u64 }) := by - have body : cspace.resolve_address_bits_loop.body bst S2 cptr RC 64#u64 65#u64 = - ok (ControlFlow.done (.Ok { slot := slot, bits_left := 0#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 : cptr >>> (13#u64 : U64) = ok 0#u64 := by - obtain ⟨z, hz, hv⟩ := spec_ex_fd (U64.ShiftRight_spec cptr 13#u64 (by simp)) - rw [hz] - refine congrArg ok (UScalar.eq_of_val_eq ?_) - rw [hv.1] - simp [Nat.shiftRight_eq_div_pow] - omega - 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 : (0#u64 : U64) &&& 2251799813685247#u64 = 0#u64 := by rfl - have s64 : (64#u64 : U64) - 64#u64 = ok 0#u64 := by rfl - have z63 : (0#u64 : U64) &&& 63#u64 = 0#u64 := by rfl - have c0 : cptr >>> (0#u64 : U64) = ok cptr := by - obtain ⟨z, hz, hv⟩ := spec_ex_fd (U64.ShiftRight_spec cptr 0#u64 (by simp)) - rw [hz] - refine congrArg ok (UScalar.eq_of_val_eq ?_) - rw [hv.1] - simp - have m13 : cspace.mask 13#u64 = ok 8191#u64 := by - have a : (13#u64 : U64) &&& 63#u64 = 13#u64 := by rfl - have b : (1#u64 : U64) <<< (13#u64 : U64) = ok 8192#u64 := by rfl - unfold cspace.mask - rw [if_neg (by scalar_tac)] - simp only [lift, bind_ok, a] - rw [b, bind_ok] - rfl - have off : cptr &&& 8191#u64 = cptr := by - apply UScalar.eq_of_val_eq - rw [UScalar.val_and] - have : (8191#u64 : U64).val = 2 ^ 13 - 1 := rfl - rw [this, Nat.and_two_pow_sub_one_eq_mod] - omega - have idx : obj.Slot.index (bwv RRb) cptr = ok slot := by - unfold obj.Slot.index - simp only [lift, bind_ok] - refine congrArg ok (UScalar.eq_of_val_eq ?_) - have z : layout.cte.SIZE.val = 32 := by simp [layout.cte.SIZE] - have : UScalar.size UScalarTy.U64 = 2 ^ 64 := by simp [U64.size_def, U64.numBits] - rw [wa_valm, core.num.U64.wrapping_mul_val_eq, vRR, z, this, hs, Nat.mod_eq_of_lt (by omega), - Nat.mod_eq_of_lt (by omega)] - omega - unfold cspace.resolve_address_bits_loop.body - simp only [lift, bind_ok, l, f, sh, c13, m51, g, s64, z63, c0, m13, off, idx] - simp - unfold cspace.resolve_address_bits - rw [rabLoop_unfold, body, bind_ok] - -theorem wit_lookupSlot {cptr : U64} (hc : cptr.val < 8192) {slot : U64} (hs : slot.val = RRb + 32 * cptr.val) : - cspace.lookup_slot bst S2 RT cptr = ok (.Ok { slot := slot, bits_left := 0#u64 }) := by - have ct : layout.tcb.SLOT_CTABLE = 0#u64 := by simp [layout.tcb.SLOT_CTABLE] - have c : capA bst S2 (slotIdx RT 0#u64) = RC := by - rw [capS2_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_ok 0#u64 (by simp), bind_ok, capA_eq, c, bind_ok, w] - exact wit_resolve hc hs - -theorem wit_cnodeOp (src : Bool) {cptr : U64} (hc : cptr.val < 8192) {slot : U64} (hs : slot.val = RRb + 32 * cptr.val) : - cspace.lookup_slot_for_cnode_op bst S2 src RC cptr 64#u64 = ok (.Ok slot) := by - have w : cspace.WORD_BITS = 64#u64 := by simp [cspace.WORD_BITS] - unfold cspace.lookup_slot_for_cnode_op - simp only [bind_ok, if_true, w] - rw [if_neg (by simp), if_neg (by simp), wit_resolve hc hs, bind_ok] - simp - /-- Root CNode slot 2. -/ local notation "SL2" => (bwv (RRb + 64)) -theorem sl2v : (SL2).val = RRb + 32 * 2 := bwv_val (by omega) - -theorem sl2_cap : capA bst S2 SL2 = RC := by - rw [capS2_rs (i := 2) (by omega) sl2v] - unfold capOf - rw [slotC_lo (by omega)] - rfl - -/-- The extra caps: the source root, root CNode slot 2. -/ -def witExtra : Aeneas.Std.Array obj.Slot 3#usize := Array.make 3#usize [bwv (RRb + 64), 0#u64, 0#u64] - theorem wit_extraCaps (U : WitUw uw) : ipc.lookup_extra_caps bst S2 RT (bwv IPb) - { label := 24#u64, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := 5#u64 } = ok (.Ok witExtra) := by - have ne : (bwv IPb) ≠ 0#u64 := fun e => by - have := congrArg UScalar.val e - rw [vIP] at this - simp at this - have bc : msg.BUF_CAPS = ok 122#u64 := by - have a : (1#u64 : U64) + 120#u64 = ok 121#u64 := by rfl - have b : (121#u64 : U64) + 1#u64 = ok 122#u64 := by rfl - have m : msg.MSG_MAX_LENGTH = 120#u64 := by simp [msg.MSG_MAX_LENGTH] - unfold msg.BUF_CAPS msg.BUF_USER_DATA - rw [m, a, bind_ok, b] - have g : msg.buf_get bst S2 (bwv IPb) 122#u64 = ok 2#u64 := by - have v : (bwv (IPb + 976)).val = IPb + 976 := bwv_val (by omega) - rw [bufGet (k := 122#u64) (b := bwv (IPb + 976)) (by simp) (by rw [v]; simp), U.cap0 _ v] - have l := wit_lookupSlot (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (cptr := 2#u64) (by simp) - (slot := SL2) (by rw [sl2v]; simp) - have b0 : ipc.lookup_extra_caps_loop.body bst S2 RT (bwv IPb) 1#u64 ipc.NO_EXTRA_CAPS 0#u64 = - ok (ControlFlow.cont (witExtra, 1#u64)) := by - unfold ipc.lookup_extra_caps_loop.body - rw [if_pos (by simp), if_pos (by simp), bc, bind_ok] - simp only [lift, bind_ok] - have u : ipc.NO_EXTRA_CAPS.update (UScalar.cast .Usize 0#u64) SL2 = ok witExtra := by - have c : UScalar.cast .Usize 0#u64 = 0#usize := by - apply UScalar.eq_of_val_eq; simp - rw [c] - obtain ⟨z, hz, hv⟩ := spec_ex_fd (Aeneas.Std.Array.update_spec ipc.NO_EXTRA_CAPS 0#usize SL2 (by simp)) - rw [hz, hv] - refine congrArg ok ?_ - first - | (apply Subtype.eq; rfl) - | (unfold ipc.NO_EXTRA_CAPS witExtra Aeneas.Std.Array.make Aeneas.Std.Array.set; rfl) - | (simp [ipc.NO_EXTRA_CAPS, witExtra, Aeneas.Std.Array.make, Aeneas.Std.Array.set]; done) - have q : (0#u64 : U64) + 1#u64 = ok 1#u64 := by rfl - rw [show core.num.U64.wrapping_add 122#u64 0#u64 = 122#u64 from rfl, g, bind_ok, l, bind_ok] - simp only [] - rw [u, bind_ok, q, bind_ok] - have b1 : ipc.lookup_extra_caps_loop.body bst S2 RT (bwv IPb) 1#u64 witExtra 1#u64 = - ok (ControlFlow.done (.Ok witExtra)) := by - unfold ipc.lookup_extra_caps_loop.body - rw [if_neg (by simp)] - unfold ipc.lookup_extra_caps - rw [if_neg ne] - unfold ipc.lookup_extra_caps_loop - rw [loop.eq_def] - simp only [b0, bind_ok] - rw [loop.eq_def] - simp only [b1, bind_ok] + { label := 24#u64, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := 5#u64 } = ok (.Ok witExtra) := + wit_extraCapsG U.cap0 /-! ## The decode -/ @@ -328,10 +89,10 @@ theorem wit_hSel : ∀ (info : msginfo.MessageInfo) (buf : U64) (r1 : cspace.Res rw [wit_msgInfo] at h1 have cp : bL.mem S2 (regWA RT layout.reg.CAP) = 2#u64 := by have e : layout.reg.CAP = 0#u64 := by simp [layout.reg.CAP, layout.reg.X0] - have h := regW2 (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) 0#u64 (by simp) + have h := regW2 (c0 := WitMsg.copy) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) 0#u64 (by simp) rw [tcb_reg_eqA] at h rw [e] - exact (ok_inj_ff h).trans (by simp [witRtW]) + exact (ok_inj_ff h).trans (by simp [witRtW, WitMsg.copy]) rw [cp, wit_lookupSlot (cptr := 2#u64) (by simp) (slot := SL2) (by rw [sl2v]; simp)] at h3 have e1 := ok_inj_ff h1 have e3 := ok_inj_ff h3 @@ -345,22 +106,22 @@ 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 2#u64 (256 + 8 * k.val)) := fun i k hi e hk => by + msg.syscall_arg bst S2 RT (bwv IPb) i = ok (witRtW WitMsg.copy (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] have a0 : msg.syscall_arg bst S2 RT (bwv IPb) 0#u64 = ok 1000#u64 := by rw [arg 0#u64 2#u64 (by simp) (by simp [msg.msg_register, layout.reg.X2]) (by simp)] - simp [witRtW] + simp [witRtW, WitMsg.copy] have a1 : msg.syscall_arg bst S2 RT (bwv IPb) 1#u64 = ok 64#u64 := by rw [arg 1#u64 3#u64 (by simp) (by simp [msg.msg_register, layout.reg.X3]) (by simp)] - simp [witRtW] + simp [witRtW, WitMsg.copy] have a2 : msg.syscall_arg bst S2 RT (bwv IPb) 2#u64 = ok 2#u64 := by rw [arg 2#u64 4#u64 (by simp) (by simp [msg.msg_register, layout.reg.X4]) (by simp)] - simp [witRtW] + simp [witRtW, WitMsg.copy] have a3 : msg.syscall_arg bst S2 RT (bwv IPb) 3#u64 = ok 64#u64 := by rw [arg 3#u64 5#u64 (by simp) (by simp [msg.msg_register, layout.reg.X5]) (by simp)] - simp [witRtW] + simp [witRtW, WitMsg.copy] -- the destination: slot 1000 of the invoked CNode, empty have d : (bwv (RRb + 32000)).val = RRb + 32 * 1000 := bwv_val (by omega) have dcap : capA bst S2 (bwv (RRb + 32000)) = .Null := by diff --git a/proofs/Fl4ProofsA64/P3/A64WitJA.lean b/proofs/Fl4ProofsA64/P3/A64WitJA.lean index 2243b66cf..cec182146 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitJA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitJA.lean @@ -26,17 +26,17 @@ 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 (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 +def witRegs (c0 : WitMsg) : Fl4SpecA64.Register → Fl4SpecA64.Word + | .x0 => c0.x0.bv | .x1 => c0.x1.bv | .x2 => c0.x2.bv | .x3 => c0.x3.bv | .x4 => c0.x4.bv | .x5 => c0.x5.bv | .x6 => c0.x6.bv | .faultIP => 4194300 | r => rootRegsA r -def witTcbA (c0 : U64) : Fl4SpecA64.Tcb := +def witTcbA (c0 : WitMsg) : Fl4SpecA64.Tcb := { rootTcbA with tcbArch := { rootTcbA.tcbArch with tcbContext := { rootTcbA.tcbArch.tcbContext with userRegs := witRegs c0 } } } /-- **The spec state of the witness** (module docstring). -/ -def witSAc (c0 : U64) (now mt sl : U64) (uw : U64 → U64) : Fl4SpecA64.State Unit := +def witSAc (c0 : WitMsg) (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 c0))) curThread := specPtr (bwv RTb) @@ -44,7 +44,7 @@ def witSAc (c0 : U64) (now mt sl : U64) (uw : U64 → U64) : Fl4SpecA64.State Un 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 +abbrev witSA (now mt sl : U64) (uw : U64 → U64) : Fl4SpecA64.State Unit := witSAc WitMsg.copy now mt sl uw /-- **The ghosts of the witness**: `w1`'s with core 0's current thread and SC. -/ def witZA : XSetsA := @@ -52,7 +52,7 @@ def witZA : XSetsA := 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 {c0 : U64} {r now mt sl : U64} {uw : U64 → U64} +variable {c0 : WitMsg} {r now mt sl : U64} {uw : U64 → U64} local notation "S1" => w1S KB IB 1 r now mt sl uw local notation "S2" => witSc c0 r now mt sl uw diff --git a/proofs/Fl4ProofsA64/P3/A64WitMsgA.lean b/proofs/Fl4ProofsA64/P3/A64WitMsgA.lean new file mode 100644 index 000000000..c4cef59b0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitMsgA.lean @@ -0,0 +1,30 @@ +/- +P3 (aarch64, A64-P5 line wit, S1a): **the witness's message registers, as one parameter.** + +The root TCB's registers `x0`–`x6` at the witness state were written three times (`witM` on the store words, `witRegs` on the +spec registers, `witRtW` on the `TcbWordsA` view), with `x0` / `x6` the only parameters. `WitMsg` holds the seven registers; +the three views read its fields, so a witness with another invocation (`WitMsg.retype`, `P3/A64WitUtMsgA`) is one more value. +`FAULT_IP` (word 528) stays `NEXT_IP - 4` in every witness. + +* `WitMsg.copy`: the CNode Copy message of the Send witness (`x0 = 2`, the root CNode cap; `x6 = 0`). +* `WitMsg.fail`: the receive / combined witnesses' message: the CAP and REPLY cptrs `8192` fail to look up. + +No premise. New module; no existing statement changed. +-/ +import Fl4ProofsA64.P3.A64WitW1A +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Wit + +/-- **The message registers of the root thread at a witness**: `x0` (CAP), `x1` (message info), `x2`–`x5` (MR0–MR3), `x6` +(REPLY). -/ +structure WitMsg where + (x0 x1 x2 x3 x4 x5 x6 : U64) + +/-- The CNode Copy message (the Send witness). -/ +abbrev WitMsg.copy : WitMsg := ⟨2#u64, 98437#u64, 1000#u64, 64#u64, 2#u64, 64#u64, 0#u64⟩ + +/-- The failing-cptr message (the receive and combined witnesses). -/ +abbrev WitMsg.fail : WitMsg := ⟨8192#u64, 98437#u64, 1000#u64, 64#u64, 2#u64, 64#u64, 8192#u64⟩ + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitRcA.lean b/proofs/Fl4ProofsA64/P3/A64WitRcA.lean index 27bdc72b9..f6a786dd4 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitRcA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitRcA.lean @@ -32,9 +32,9 @@ 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 +abbrev cFail : WitMsg := WitMsg.fail -variable {r now mt sl : U64} {uw : U64 → U64} {c0 : U64} +variable {r now mt sl : U64} {uw : U64 → U64} {c0 : WitMsg} local notation "wa" => core.num.U64.wrapping_add local notation "S3" => witSc c0 r now mt sl uw @@ -42,26 +42,6 @@ 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 = @@ -92,11 +72,11 @@ theorem wit_lookupSlot_fail : 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)] + rw [capS2_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] + rw [ct, tcbSlot_ok 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.** -/ @@ -107,7 +87,7 @@ theorem wit_lookupCap_fail (h0 : c0 = cFail) : 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] + simp [witRtW, h0, WitMsg.fail] rw [cp, curW2] unfold cspace.lookup_cap rw [wit_lookupSlot_fail] @@ -117,7 +97,7 @@ theorem wit_lookupCap_fail (h0 : c0 = cFail) : /-! ## 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 := +abbrev RcJ (Z : XSetsA) (c0 : WitMsg) (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)`. -/ @@ -213,19 +193,6 @@ theorem JSyscallA.recvCapFault_vmA (hPl : ArchPlat ar) 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} @@ -289,30 +256,7 @@ theorem wit_kRunsR {r mt sl : U64} {uw : U64 → U64} (number : I64) (rep : Bool 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) + exact wit_kRunsG number rep call rng end diff --git a/proofs/Fl4ProofsA64/P3/A64WitRcCombA.lean b/proofs/Fl4ProofsA64/P3/A64WitRcCombA.lean index 2518a35e8..cfca27251 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitRcCombA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitRcCombA.lean @@ -30,11 +30,11 @@ 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 + bL.mem (witSc cFail r now mt sl uw) (regWA (bL.curW (witSc cFail r now mt sl uw)) layout.reg.REPLY) = 8192#u64 := 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] + simp [witRtW, cFail, WitMsg.fail] /-- **The REPLY cptr fails to look up.** -/ theorem wit_replyLookup_fail {r now mt sl : U64} {uw : U64 → U64} : @@ -206,30 +206,7 @@ theorem wit_kRunsC {r mt sl : U64} {uw : U64 → U64} (number : I64) (rep : Bool 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 + exact wit_kRunsG number rep call rng end diff --git a/proofs/Fl4ProofsA64/P3/A64WitReadA.lean b/proofs/Fl4ProofsA64/P3/A64WitReadA.lean new file mode 100644 index 000000000..442985d61 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitReadA.lean @@ -0,0 +1,269 @@ +/- +P3 (aarch64, A64-P5 line wit, S1b): **the witness's generic reads**: what any root-task message at `witSc c0` reads. + +Split out of `P3/A64WitCopyA` (which keeps the CNode Copy message's own lookups). At `witSc c0 r now mt sl uw` for every +message `c0 : WitMsg` and IPC buffer `uw`: + +* `bstTotal`, `regW2` (the register words of the message), `ipb_word` / `bufGet` (IPC buffer words), `capS2_rs` (root CNode slots + are unchanged); +* `wit_ipcBuffer` (the root thread's IPC buffer), `wit_resolve` / `wit_lookupSlot` / `wit_cnodeOp` (the CSpace walk of a cptr + below `8192` in the root CNode), `sl2_cap` (root CNode slot 2 is the root CNode cap). + +No premise. New module; every statement is that of `P3/A64WitCopyA` generalised from `witS` to `witSc c0`. +-/ +import Fl4ProofsA64.P3.A64WitSyscA +import Fl4ProofsA64.P0.Auto +import Fl4ProofsA64.P1.LocalVcpuKeep +import Fl4ProofsA64.P1.VcpuHooks +import Fl4ProofsA64.P2.GuardBase +import Fl4ProofsA64.P1.FastFault +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 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- The concrete store is total (A64 P0's `StoreTotal`). -/ +theorem bstTotal : Fl4ProofsA64.P0.StoreTotal bst := + ⟨fun _ => (WP.spec_ok _).2 trivial, fun _ _ => (WP.spec_ok _).2 trivial, fun _ _ => (WP.spec_ok _).2 trivial, + fun _ _ _ => (WP.spec_ok _).2 trivial, fun _ _ _ => (WP.spec_ok _).2 trivial, + fun _ _ _ => (WP.spec_ok _).2 trivial, fun _ => (WP.spec_ok _).2 trivial, fun _ => (WP.spec_ok _).2 trivial, + fun _ _ _ => (WP.spec_ok _).2 trivial⟩ + +variable {c0 : WitMsg} {r now mt sl : U64} {uw : U64 → U64} + +local notation "S1" => w1S KB IB 1 r now mt sl uw +local notation "S2" => witSc c0 r now mt sl uw +local notation "RT" => (bwv RTb) +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 c0 (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) + rw [vRT] at h + show (Endp.regA RT i).val = _ + omega + exact congrArg ok (wit_rtWords _ _ (by omega) (by omega) (by rw [v, vRT])) + +theorem ipb_word {k : Nat} (hk : k < 512) {b : U64} (hb : b.val = IPb + 8 * k) : bL.mem S2 b = uw b := by + have e : bL.mem S2 b = bL.mem S1 b := ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) + rw [e] + change w1M KB IB 1 r now mt sl uw b = _ + rw [w1M_root lay1 (o := 401408 + 8 * k) (by omega) (by omega)] + unfold rootW + rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega), if_pos (by omega)] + +theorem bufGet {k : U64} (hk : k.val < 512) {b : U64} (hb : b.val = IPb + 8 * k.val) : + msg.buf_get bst S2 (bwv IPb) k = ok (uw b) := by + rw [buf_get_eqA] + have e : bufWA (bwv IPb) k = b := by + apply UScalar.eq_of_val_eq + unfold bufWA + have e8 : (8#u64 : U64).val = 8 := rfl + rw [wa_valm, core.num.U64.wrapping_mul_val_eq, vIP, hb, e8] + have : UScalar.size UScalarTy.U64 = 2 ^ 64 := by simp [U64.size_def, U64.numBits] + rw [this, Nat.mod_eq_of_lt (by omega), Nat.mod_eq_of_lt (by omega)] + omega + rw [e, ipb_word hk hb] + +/-- A root CNode slot is not changed. -/ +theorem capS2_rs {x : U64} {i : Nat} (hi : i < 8192) (hx : x.val = RRb + 32 * i) : capA bst S2 x = capOf 1 i := by + rw [← cap_root (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) lay1 hi hx] + have h8 : (wa x 8#u64).val = RRb + 32 * i + 8 := by + rw [wa_valm, hx]; simp; omega + have e1 : bL.mem S2 x = bL.mem S1 x := ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) + have e2 : bL.mem S2 (wa x 8#u64) = bL.mem S1 (wa x 8#u64) := ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) + unfold capA + rw [e1, e2] + +/-! ## The prefix lookups -/ + +theorem wit_ipcBuffer : msg.lookup_ipc_buffer bst S2 false RT = ok (bwv IPb) := by + have ipo : layout.tcb.IPC_BUFFER = ok 3512#u64 := by + unfold layout.tcb.IPC_BUFFER layout.tcb.F; rfl + have w : obj.Tcb.ipc_buffer bst RT S2 = ok (bwv 4198400) := by + unfold obj.Tcb.ipc_buffer + rw [ipo] + simp only [bind_ok, lift] + have v : (wa RT 3512#u64).val = RTb + 3512 := by + rw [fldV rtMem1 (by simp), vRT]; simp + refine congrArg ok ?_ + exact (wit_rtWords _ 3512 (by omega) (by omega) (by rw [v, vRT])).trans (by simp [witRtW, rtW]) + have sb : layout.tcb.SLOT_BUFFER = 2#u64 := by simp [layout.tcb.SLOT_BUFFER] + have c : capA bst S2 (slotIdx RT 2#u64) = .Frame (bwv IPb) .Small 3#u64 false false false 0#u64 (bwv 0) := by + rw [capS2_ts (by simp), cap_rt lay1 (by simp)] + simp + unfold msg.lookup_ipc_buffer + rw [w, bind_ok, sb, tcbSlot_ok 2#u64 (by simp), bind_ok, capA_eq, c, bind_ok] + have rw3 : (3#u64 : U64) = capability.VM_READ_WRITE := by simp [capability.VM_READ_WRITE] + simp only [Bool.false_eq_true, if_false, rw3, if_true] + have fb : capability.FrameSize.bits .Small = ok 12#u64 := by rfl + have s1 : (12#u64 : U64) &&& 63#u64 = 12#u64 := by rfl + have s2 : (1#u64 : U64) <<< (12#u64 : U64) = ok 4096#u64 := by rfl + have s3 : core.num.U64.wrapping_sub 4096#u64 1#u64 = 4095#u64 := by rfl + have s4 : (bwv 4198400) &&& 4095#u64 = 0#u64 := by rfl + have s5 : wa (bwv IPb) 0#u64 = bwv IPb := by + apply UScalar.eq_of_val_eq + rw [wa_valm, vIP]; simp + rw [fb, bind_ok] + simp only [lift, bind_ok, s1] + rw [s2, bind_ok] + simp only [bind_ok, s3, s4, s5] + +/-- **The CSpace walk of the root CNode**: one level, 13 bits behind a 51-bit zero guard. -/ +theorem wit_resolve {cptr : U64} (hc : cptr.val < 8192) {slot : U64} (hs : slot.val = RRb + 32 * cptr.val) : + cspace.resolve_address_bits bst S2 RC cptr 64#u64 = ok (.Ok { slot := slot, bits_left := 0#u64 }) := by + have body : cspace.resolve_address_bits_loop.body bst S2 cptr RC 64#u64 65#u64 = + ok (ControlFlow.done (.Ok { slot := slot, bits_left := 0#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 : cptr >>> (13#u64 : U64) = ok 0#u64 := by + obtain ⟨z, hz, hv⟩ := spec_ex_fd (U64.ShiftRight_spec cptr 13#u64 (by simp)) + rw [hz] + refine congrArg ok (UScalar.eq_of_val_eq ?_) + rw [hv.1] + simp [Nat.shiftRight_eq_div_pow] + omega + 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 : (0#u64 : U64) &&& 2251799813685247#u64 = 0#u64 := by rfl + have s64 : (64#u64 : U64) - 64#u64 = ok 0#u64 := by rfl + have z63 : (0#u64 : U64) &&& 63#u64 = 0#u64 := by rfl + have c0 : cptr >>> (0#u64 : U64) = ok cptr := by + obtain ⟨z, hz, hv⟩ := spec_ex_fd (U64.ShiftRight_spec cptr 0#u64 (by simp)) + rw [hz] + refine congrArg ok (UScalar.eq_of_val_eq ?_) + rw [hv.1] + simp + have m13 : cspace.mask 13#u64 = ok 8191#u64 := by + have a : (13#u64 : U64) &&& 63#u64 = 13#u64 := by rfl + have b : (1#u64 : U64) <<< (13#u64 : U64) = ok 8192#u64 := by rfl + unfold cspace.mask + rw [if_neg (by scalar_tac)] + simp only [lift, bind_ok, a] + rw [b, bind_ok] + rfl + have off : cptr &&& 8191#u64 = cptr := by + apply UScalar.eq_of_val_eq + rw [UScalar.val_and] + have : (8191#u64 : U64).val = 2 ^ 13 - 1 := rfl + rw [this, Nat.and_two_pow_sub_one_eq_mod] + omega + have idx : obj.Slot.index (bwv RRb) cptr = ok slot := by + unfold obj.Slot.index + simp only [lift, bind_ok] + refine congrArg ok (UScalar.eq_of_val_eq ?_) + have z : layout.cte.SIZE.val = 32 := by simp [layout.cte.SIZE] + have : UScalar.size UScalarTy.U64 = 2 ^ 64 := by simp [U64.size_def, U64.numBits] + rw [wa_valm, core.num.U64.wrapping_mul_val_eq, vRR, z, this, hs, Nat.mod_eq_of_lt (by omega), + Nat.mod_eq_of_lt (by omega)] + omega + unfold cspace.resolve_address_bits_loop.body + simp only [lift, bind_ok, l, f, sh, c13, m51, g, s64, z63, c0, m13, off, idx] + simp + unfold cspace.resolve_address_bits + rw [rabLoop_unfold, body, bind_ok] + +theorem wit_lookupSlot {cptr : U64} (hc : cptr.val < 8192) {slot : U64} (hs : slot.val = RRb + 32 * cptr.val) : + cspace.lookup_slot bst S2 RT cptr = ok (.Ok { slot := slot, bits_left := 0#u64 }) := by + have ct : layout.tcb.SLOT_CTABLE = 0#u64 := by simp [layout.tcb.SLOT_CTABLE] + have c : capA bst S2 (slotIdx RT 0#u64) = RC := by + rw [capS2_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_ok 0#u64 (by simp), bind_ok, capA_eq, c, bind_ok, w] + exact wit_resolve hc hs + +theorem wit_cnodeOp (src : Bool) {cptr : U64} (hc : cptr.val < 8192) {slot : U64} (hs : slot.val = RRb + 32 * cptr.val) : + cspace.lookup_slot_for_cnode_op bst S2 src RC cptr 64#u64 = ok (.Ok slot) := by + have w : cspace.WORD_BITS = 64#u64 := by simp [cspace.WORD_BITS] + unfold cspace.lookup_slot_for_cnode_op + simp only [bind_ok, if_true, w] + rw [if_neg (by simp), if_neg (by simp), wit_resolve hc hs, bind_ok] + simp + +/-- Root CNode slot 2. -/ +local notation "SL2" => (bwv (RRb + 64)) + +theorem sl2v : (SL2).val = RRb + 32 * 2 := bwv_val (by omega) + +theorem sl2_cap : capA bst S2 SL2 = RC := by + rw [capS2_rs (i := 2) (by omega) sl2v] + unfold capOf + rw [slotC_lo (by omega)] + rfl + + +/-- The extra caps: the source root, root CNode slot 2. -/ +def witExtra : Aeneas.Std.Array obj.Slot 3#usize := Array.make 3#usize [bwv (RRb + 64), 0#u64, 0#u64] + +theorem wit_extraCapsG {lbl len : U64} (hcap : ∀ b : U64, b.val = IPb + 976 → uw b = 2#u64) : + ipc.lookup_extra_caps bst S2 RT (bwv IPb) + { label := lbl, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := len } = ok (.Ok witExtra) := by + have ne : (bwv IPb) ≠ 0#u64 := fun e => by + have := congrArg UScalar.val e + rw [vIP] at this + simp at this + have bc : msg.BUF_CAPS = ok 122#u64 := by + have a : (1#u64 : U64) + 120#u64 = ok 121#u64 := by rfl + have b : (121#u64 : U64) + 1#u64 = ok 122#u64 := by rfl + have m : msg.MSG_MAX_LENGTH = 120#u64 := by simp [msg.MSG_MAX_LENGTH] + unfold msg.BUF_CAPS msg.BUF_USER_DATA + rw [m, a, bind_ok, b] + have g : msg.buf_get bst S2 (bwv IPb) 122#u64 = ok 2#u64 := by + have v : (bwv (IPb + 976)).val = IPb + 976 := bwv_val (by omega) + rw [bufGet (k := 122#u64) (b := bwv (IPb + 976)) (by simp) (by rw [v]; simp), hcap _ v] + have l := wit_lookupSlot (c0 := c0) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (cptr := 2#u64) (by simp) + (slot := SL2) (by rw [sl2v]; simp) + have b0 : ipc.lookup_extra_caps_loop.body bst S2 RT (bwv IPb) 1#u64 ipc.NO_EXTRA_CAPS 0#u64 = + ok (ControlFlow.cont (witExtra, 1#u64)) := by + unfold ipc.lookup_extra_caps_loop.body + rw [if_pos (by simp), if_pos (by simp), bc, bind_ok] + simp only [lift, bind_ok] + have u : ipc.NO_EXTRA_CAPS.update (UScalar.cast .Usize 0#u64) SL2 = ok witExtra := by + have c : UScalar.cast .Usize 0#u64 = 0#usize := by + apply UScalar.eq_of_val_eq; simp + rw [c] + obtain ⟨z, hz, hv⟩ := spec_ex_fd (Aeneas.Std.Array.update_spec ipc.NO_EXTRA_CAPS 0#usize SL2 (by simp)) + rw [hz, hv] + refine congrArg ok ?_ + first + | (apply Subtype.eq; rfl) + | (unfold ipc.NO_EXTRA_CAPS witExtra Aeneas.Std.Array.make Aeneas.Std.Array.set; rfl) + | (simp [ipc.NO_EXTRA_CAPS, witExtra, Aeneas.Std.Array.make, Aeneas.Std.Array.set]; done) + have q : (0#u64 : U64) + 1#u64 = ok 1#u64 := by rfl + rw [show core.num.U64.wrapping_add 122#u64 0#u64 = 122#u64 from rfl, g, bind_ok, l, bind_ok] + simp only [] + rw [u, bind_ok, q, bind_ok] + have b1 : ipc.lookup_extra_caps_loop.body bst S2 RT (bwv IPb) 1#u64 witExtra 1#u64 = + ok (ControlFlow.done (.Ok witExtra)) := by + unfold ipc.lookup_extra_caps_loop.body + rw [if_neg (by simp)] + unfold ipc.lookup_extra_caps + rw [if_neg ne] + unfold ipc.lookup_extra_caps_loop + rw [loop.eq_def] + simp only [b0, bind_ok] + rw [loop.eq_def] + simp only [b1, bind_ok] + + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitRecA.lean b/proofs/Fl4ProofsA64/P3/A64WitRecA.lean index 327beef4d..19cebdc16 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitRecA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitRecA.lean @@ -20,7 +20,7 @@ noncomputable section local notation "wa" => core.num.U64.wrapping_add -variable {cw r now mt sl : U64} {uw : U64 → U64} +variable {cw : WitMsg} {r now mt sl : U64} {uw : U64 → U64} local notation "S1" => w1S KB IB 1 r now mt sl uw local notation "S2" => witSc cw r now mt sl uw diff --git a/proofs/Fl4ProofsA64/P3/A64WitStA.lean b/proofs/Fl4ProofsA64/P3/A64WitStA.lean index 8b0d48ac9..813a43a84 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitStA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitStA.lean @@ -12,7 +12,7 @@ The state is built directly, not as the output of a run of `schedule` (no kernel No premise. New module; no existing statement changed. -/ -import Fl4ProofsA64.P3.A64WitW1A +import Fl4ProofsA64.P3.A64WitMsgA import Fl4ProofsA64.P3.Stage3SyscallA import Fl4ProofsA64.P3.Stage3IpcGlueA open Aeneas Aeneas.Std Result @@ -26,42 +26,38 @@ 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 (c0 : U64) (mem : U64 → U64) (b : U64) : U64 := +def witM (c0 : WitMsg) (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 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 + 256 then c0.x0 + else if b.val = RTb + 264 then c0.x1 + else if b.val = RTb + 272 then c0.x2 + else if b.val = RTb + 280 then c0.x3 + else if b.val = RTb + 288 then c0.x4 + else if b.val = RTb + 296 then c0.x5 + else if b.val = RTb + 304 then c0.x6 else if b.val = RTb + 528 then 4194300#u64 else mem b /-- **The witness state.** -/ -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⟩ +def witSc (c0 : WitMsg) (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 +abbrev witS (r now mt sl : U64) (uw : U64 → U64) : BS := witSc WitMsg.copy 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 {c0 : U64} {mem : U64 → U64} {b : U64} (h : ¬ WitW b) : witM c0 mem b = mem b := by +theorem witM_keep {c0 : WitMsg} {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)] -variable {c0 r now mt sl : U64} {uw : U64 → U64} +variable {c0 : WitMsg} {r now mt sl : U64} {uw : U64 → U64} local notation "S1" => w1S KB IB 1 r now mt sl uw local notation "S2" => witSc c0 r now mt sl uw @@ -219,6 +215,28 @@ theorem rt_stA1 : bL.mem S1 (stA (bwv RTb)) = 1#u64 := by theorem rt_affA1 : bL.mem S1 (affA (bwv RTb)) = 0#u64 := (rt_word (o := 3520#u64) (k := 3520) (by simp) (by omega)).trans (by simp [rtW]) +/-! ## Root TCB slots (shared by every witness's reads) -/ + +/-- A root TCB slot is not changed by the witness's nine words. -/ +theorem capS2_ts {i : U64} (hi : i.val < 7) : capA bst S2 (slotIdx (bwv RTb) i) = capA bst S1 (slotIdx (bwv RTb) i) := by + have v : (slotIdx (bwv RTb) i).val = RTb + 32 * i.val := by + have e : slotIdx (bwv RTb) i = ts i := rfl + rw [e, ts_val (by omega)] + omega + have h8 : (wa (slotIdx (bwv RTb) i) 8#u64).val = RTb + 32 * i.val + 8 := by + rw [wa_valm, v]; simp; omega + have e1 : bL.mem S2 (slotIdx (bwv RTb) i) = bL.mem S1 (slotIdx (bwv RTb) i) := + ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) + have e2 : bL.mem S2 (wa (slotIdx (bwv RTb) i) 8#u64) = bL.mem S1 (wa (slotIdx (bwv RTb) i) 8#u64) := + ks_keep (Or.inr (Or.inl ⟨by omega, by omega⟩)) + unfold capA + rw [e1, e2] + +theorem tcbSlot_ok (i : U64) (hi : i.val < 7) : obj.Tcb.slot (bwv RTb) i = ok (slotIdx (bwv RTb) 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] + end end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitSubA.lean b/proofs/Fl4ProofsA64/P3/A64WitSubA.lean new file mode 100644 index 000000000..4afced199 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitSubA.lean @@ -0,0 +1,324 @@ +/- +P3 (aarch64, E0.5 step E): **non-vacuity witness of `ARMPageDeriveSubframe`, part 1** — the decode site at `w1vR` +(`P3/A64WitVsPremA`): the `Large` frame cap of new slot 4 (`newC 4`, 2 MiB at `FRn`) in root CNode slot `57 + nc`, the extra +cap the root CNode cap (root slot 2), `node_depth = 0`, `first = 60 + nc` (empty slots), `offset = 0`, `count = 2`, +mask `3`, six message words (`X2..X4` registers, the root IPC buffer words 5 and 6 of `uw`). + +* `wit_sub_empty`, `wit_sub_x0`, `wit_sub_win`: the cap readings (window slots `Null`, the root CNode cap in slot 2); +* `wit_sub_args`: message words 3 (`X5 = 0`), 4 (`count`), 5 (`mask`); `wit_sub_dest`: `subframe_dest` answers `Ok root`; + `ee_run_ok` (general): `ensure_empty_run` answers `Ok` on a `Null` window; +* `wit_sub_dec`: `vspace::derive_subframe` runs through its whole decode (ex0, `len >= 6`, `large_ram_frame`, offset/count + checks, `subframe_dest`, `ensure_empty_run`, mask, Restart) and reaches `insert_subframes` on the Restart state; +* `wit_sub_ins`: the pure inputs of `JStage3A.subframesA` (`hAs`, `hth`, `hr`, `hfpC`, `hfpAl`, `hvm`, `hoff`, `hfc`, `hoff4`, + `hsrc`, `hall`, `hdo`). Not done here: `SubInv` (needs `SysL`/`SymL`/`BlkOK` at `w1vS`, not proved there) and the arm-level + witness (waits for step D). + +No named premise beyond `w1vR`'s layout (`BootLayA`, `BootKsA`, `BootLay1`). New module. +-/ +import Fl4ProofsA64.P3.A64WitVsArmsA +import Fl4ProofsA64.P3.Stage3ArmSubframeA +import Fl4ProofsA64.P3.W1UserBytesA +import Fl4ProofsA64.P1.S1aSubRun +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 + +noncomputable section +open Classical + +local notation "wa" => core.num.U64.wrapping_add + +/-- The window's first slot, `60 + nc`, as a word. -/ +def firstS (nc : Nat) : U64 := ⟨BitVec.ofNat 64 (60 + nc)⟩ + +theorem firstS_val (h : nc ≤ 128) : (firstS nc).val = 60 + nc := by + show (BitVec.ofNat 64 (60 + nc)).toNat = _ + rw [BitVec.toNat_ofNat]; exact Nat.mod_eq_of_lt (by omega) + +section sub +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} +local notation "SR" => w1vR kb ib nc r now mt sl uw 0#u64 0#u64 (firstS nc) + +/-- Root CNode slot `j ≥ 58 + nc` is `Null`. -/ +theorem wit_sub_empty (P : BootLay1 kb ib nc) {j : Nat} (h1 : 58 + nc ≤ j) (h2 : j < 8192) : + capA bst SR (rsV j) = .Null := by + have h128 := P.w0.nc128 + rw [capR_keep P (rsV_os h2)] + rcases capV_split P (rsV_os h2) with e | ⟨k, hk, hx, -, -⟩ + · rw [e, cap_root P h2 (by rw [rsV_val h2])] + unfold capOf + rw [slotC_hi (by omega), tailC_big (by omega)] + · rw [rsV_val h2] at hx; omega + +/-- The extra cap, root slot 2, is the root CNode cap. -/ +theorem wit_sub_x0 (P : BootLay1 kb ib nc) : + capA bst SR (rsV 2) = .CNode (bwv RRb) 13#u64 51#u64 0#u64 := by + have h128 := P.w0.nc128 + rw [capR_keep P (rsV_os (by omega))] + rcases capV_split P (rsV_os (j := 2) (by omega)) with e | ⟨k, hk, hx, -, -⟩ + · rw [e, cap_root P (i := 2) (by omega) (by rw [rsV_val (by omega)])] + unfold capOf + rw [slotC_lo (by omega)] + rfl + · rw [rsV_val (by omega)] at hx; omega + +/-- The root IPC buffer's words are `uw` at the witness. -/ +theorem wit_sub_ipb (P : BootLay1 kb ib nc) {k : U64} (hk : k.val < 128) : + bL.mem SR (bufW (bwv IPb) k) = uw (bufW (bwv IPb) k) := by + have hkb := P.kbR + have h128 := P.w0.nc128 + have hv := bufW_ipb hk + rw [memR_keep (by omega) (by omega), memV_keep (by omega) (by omega) (by omega) (by omega)] + exact w1M_ipbA P hk + +/-- Message words 3, 4, 5: `offset = 0` (register `X5`), `count` and `mask` (IPC buffer words 5 and 6). -/ +theorem wit_sub_args (P : BootLay1 kb ib nc) : + msg.syscall_arg bst SR (bwv RTn) (bwv IPb) 3#u64 = ok 0#u64 ∧ + msg.syscall_arg bst SR (bwv RTn) (bwv IPb) 4#u64 = ok (uw (bufW (bwv IPb) 5#u64)) ∧ + msg.syscall_arg bst SR (bwv RTn) (bwv IPb) 5#u64 = ok (uw (bufW (bwv IPb) 6#u64)) := by + have n : msg.N_MSG_REGISTERS = 4#u64 := by simp [msg.N_MSG_REGISTERS] + have hne : (bwv IPb : U64) ≠ 0#u64 := fun e => by + have := congrArg UScalar.val e; rw [vIP] at this; simp at this + refine ⟨?_, ?_, ?_⟩ + · have hkb := P.kbR + have h128 := P.w0.nc128 + unfold msg.syscall_arg + rw [n, if_pos (by decide), show msg.msg_register 3#u64 = ok layout.reg.X5 by + simp [msg.msg_register], bind_ok, tcb_reg_eqA] + refine congrArg ok ?_ + have hx5 : (layout.reg.X5 : U64).val = 5 := by simp [layout.reg.X5] + have a := regAv (k := layout.reg.X5) (by omega) + rw [hx5] at a + rw [memR_keep (by omega) (by omega), + memV_keep (by omega) (by omega) (by omega) (by omega)] + have x : (regWA (bwv RTn) layout.reg.X5).val = RTb + 296 := by + omega + exact (w1M_rt P (by omega) x).trans (by simp [rtW]) + · unfold msg.syscall_arg + rw [n, if_neg (by decide), if_pos (by simpa using hne)] + simp only [lift, bind_ok] + rw [buf_get_eqA] + refine congrArg ok ?_ + have e : core.num.U64.wrapping_add 4#u64 1#u64 = 5#u64 := by rfl + rw [e] + exact wit_sub_ipb P (k := 5#u64) (by simp) + · unfold msg.syscall_arg + rw [n, if_neg (by decide), if_pos (by simpa using hne)] + simp only [lift, bind_ok] + rw [buf_get_eqA] + refine congrArg ok ?_ + have e : core.num.U64.wrapping_add 5#u64 1#u64 = 6#u64 := by rfl + rw [e] + exact wit_sub_ipb P (k := 6#u64) (by simp) + +end sub + +/-- `ensure_empty_slot` on a `Null` slot answers `Ok`. -/ +theorem ee_slot_ok {s : BS} {y : U64} (h : capA bst s y = .Null) : + cdt.ensure_empty_slot bst s y = ok (.Ok ()) := by + unfold cdt.ensure_empty_slot + rw [capA_eq, bind_ok, h, is_null_t, bind_ok] + simp + +/-- **`ensure_empty_run` answers `Ok` on a window of `Null` slots** (the converse of `ensure_empty_run.null`). -/ +theorem ee_run_ok {s : BS} {dest first count : U64} + (hall : ∀ j : U64, j.val < count.val → capA bst s (slotIdx dest (wa first j)) = .Null) : + ∃ r, vspace.ensure_empty_run bst s dest first count = ok r ∧ r = .Ok () := by + have : vspace.ensure_empty_run bst s dest first count ⦃ r => r = .Ok () ⦄ := by + unfold vspace.ensure_empty_run vspace.ensure_empty_run_loop + apply loop.spec_decr_nat (measure := fun x : U64 => count.val - x.val) + (inv := fun x : U64 => x.val ≤ count.val) + · intro i1 w1 + unfold vspace.ensure_empty_run_loop.body + by_cases hlt : i1 < count + · rw [if_pos hlt] + have hlt' : i1.val < count.val := hlt + simp only [lift, bind_ok] + rw [Fl4ProofsA64.P1.W7.R.ST.obj.Slot.index_eq, bind_ok, ee_slot_ok (hall i1 hlt')] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + step as ⟨i2, hi2⟩ + have hi2' : i2.val = i1.val + 1 := by scalar_tac + try rw [WP.spec_ok] + exact ⟨by omega, by omega⟩ + · rw [if_neg hlt, WP.spec_ok] + · exact Nat.zero_le _ + exact spec_existsU this + +section dec +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} +local notation "SR" => w1vR kb ib nc r now mt sl uw 0#u64 0#u64 (firstS nc) + +/-- The extra-cap array of an arm: `vspace::extra` reads slot `j`. -/ +theorem wit_extra {j : Nat} (hj : j < 8192) : + vspace.extra (extraV (rsV j)) 0#usize = ok (some (rsV j)) := by + have ne : rsV j ≠ 0#u64 := fun e => by + have := congrArg UScalar.val e; rw [rsV_val hj] at this; simp at this + have ix : Aeneas.Std.Array.index_usize (extraV (rsV j)) 0#usize = ok (rsV j) := by + rfl + unfold vspace.extra + rw [if_neg (by decide), ix, bind_ok] + simp [obj.Slot.is_null, ne] + +/-- `subframe_dest` at depth `0` on the root CNode cap (slot 2): the root CNode, window `[60 + nc, 62 + nc)`. -/ +theorem wit_sub_dest (P : BootLay1 kb ib nc) : + vspace.subframe_dest bst SR (rsV 2) 0#u64 0#u64 (firstS nc) 2#u64 = ok (.Ok (bwv RRb)) := by + have h128 := P.w0.nc128 + have hf := firstS_val h128 + unfold vspace.subframe_dest + rw [capA_eq, bind_ok, wit_sub_x0 P, if_neg (by simp)] + unfold vspace.cnode_of + dsimp only + have e0 : (13#u64 &&& 63#u64 : U64) = 13#u64 := by rfl + have e1 : (1#u64 <<< 13#u64 : Result U64) = ok 8192#u64 := by rfl + have w1 : core.num.U64.wrapping_sub 8192#u64 1#u64 = 8191#u64 := by rfl + have c1 : ¬ (firstS nc > 8191#u64) := by + intro h; simp only [gt_iff_lt, UScalar.lt_equiv] at h; simp at h; omega + have c2 : ¬ ((2#u64 : U64) > core.num.U64.wrapping_sub 8192#u64 (firstS nc)) := by + intro h; simp only [gt_iff_lt, UScalar.lt_equiv, core.num.U64.wrapping_sub_val_eq] at h + simp [U64.size, U64.numBits, hf] at h; omega + simp only [bind_ok, lift] + show (do let node_size ← (1#u64 <<< (13#u64 &&& 63#u64) : Result U64) + if firstS nc > core.num.U64.wrapping_sub node_size 1#u64 then + error.range U64 0#u64 (core.num.U64.wrapping_sub node_size 1#u64) + else if 2#u64 > core.num.U64.wrapping_sub node_size (firstS nc) then + error.range U64 1#u64 (core.num.U64.wrapping_sub node_size (firstS nc)) + else ok (core.result.Result.Ok (bwv RRb))) = _ + simp only [e0, e1] + show Std.bind (ok 8192#u64) _ = _ + simp only [bind_ok, w1, if_neg c1, if_neg c2] + +/-- The window's slots are `Null`. -/ +theorem wit_sub_win (P : BootLay1 kb ib nc) {j : U64} (hj : j.val < 2) : + capA bst SR (slotIdx (bwv RRb) (wa (firstS nc) j)) = .Null := by + have h128 := P.w0.nc128 + have hf := firstS_val h128 + have hw : (wa (firstS nc) j).val = 60 + nc + j.val := by + rw [wa_val]; rw [hf]; exact Nat.mod_eq_of_lt (by omega) + have vR : (bwv RRb : U64).val = RRb := bwv_val (by norm_num) + have e : slotIdx (bwv RRb) (wa (firstS nc) j) = rsV (60 + nc + j.val) := by + apply UScalar.eq_of_val_eq + rw [slotIdx_valS (by rw [hw, vR]; omega), hw, vR, rsV_val (by omega)] + rw [e]; exact wit_sub_empty P (by omega) (by omega) + +/-- **`vspace::derive_subframe` runs through its decode at the witness**: ends at `insert_subframes` on the Restart state. -/ +theorem wit_sub_dec (P : BootLay1 kb ib nc) (h5 : uw (bufW (bwv IPb) 5#u64) = 2#u64) + (h6 : uw (bufW (bwv IPb) 6#u64) = 3#u64) : + ∃ s1, sched.set_thread_state bst SR (bwv RTn) sched.TS_RESTART = ok s1 ∧ + vspace.derive_subframe bst SR 6#u64 (rsV (57 + nc)) (newC 4) (bwv IPb) (extraV (rsV 2)) = + (do let s2 ← vspace.insert_subframes bst s1 (rsV (57 + nc)) (bwv RRb) (firstS nc) + (wa (bwv FRn) 0#u64) 2#u64 3#u64 + ok (.Ok (), s2)) := by + have h128 := P.w0.nc128 + obtain ⟨s1, hs1⟩ := sts_ok SR (bwv RTn) sched.TS_RESTART + refine ⟨s1, hs1, ?_⟩ + obtain ⟨a0, a1, a2⟩ : msg.syscall_arg bst SR (bwv RTn) (bwv IPb) 0#u64 = ok 0#u64 ∧ + msg.syscall_arg bst SR (bwv RTn) (bwv IPb) 1#u64 = ok 0#u64 ∧ + msg.syscall_arg bst SR (bwv RTn) (bwv IPb) 2#u64 = ok (firstS nc) := argsR P (bwv IPb) + obtain ⟨a3, a4, a5⟩ := wit_sub_args (uw := uw) (r := r) (now := now) (mt := mt) (sl := sl) P + rw [h5] at a4; rw [h6] at a5 + have lrf : vspace.large_ram_frame (newC 4) = ok (some (bwv FRn, 3#u64)) := by + simp [newC, vspace.large_ram_frame] + unfold vspace.derive_subframe + rw [curThreadR P, bind_ok, wit_extra (j := 2) (by omega), bind_ok] + dsimp only + rw [if_pos (by decide), lrf, bind_ok] + dsimp only + simp only [a0, a1, a2, a3, a4, a5, bind_ok] + have sh21 : (1#u64 <<< 21#i32 : Result U64) = ok 2097152#u64 := by rfl + have sub0 : (2097152#u64 - 0#u64 : Result U64) = ok 2097152#u64 := by rfl + have sh12 : (2097152#u64 >>> 12#i32 : Result U64) = ok 512#u64 := by rfl + simp only [sh21, sub0, sh12, bind_ok, lift] + have c0 : ¬ ((0#u64 : U64) ≥ 2097152#u64) := by + intro h; simp only [ge_iff_le, UScalar.le_equiv] at h; simp at h + have c1 : (0#u64 &&& 4095#u64 != 0#u64) = false := by rfl + have c2 : ¬ ((2#u64 : U64) < 1#u64) := by + intro h; simp only [UScalar.lt_equiv] at h; simp at h + have c3 : ¬ ((2#u64 : U64) > 512#u64) := by + intro h; simp only [gt_iff_lt, UScalar.lt_equiv] at h; simp at h + simp only [if_neg c0, c1, Bool.false_eq_true, ↓reduceIte, if_neg c2, if_neg c3, bind_ok, wit_sub_dest P] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + obtain ⟨r1, hr1, rfl⟩ := ee_run_ok (s := SR) (dest := bwv RRb) (first := firstS nc) (count := 2#u64) + (fun j hj => wit_sub_win P (by simpa using hj)) + rw [hr1] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + obtain ⟨rr, hrr, hvm⟩ : ∃ rr, capability.Rights.from_word 3#u64 = ok rr ∧ + capability.mask_vm_rights 3#u64 rr = ok 3#u64 := by + refine ⟨⟨true, true, false, false⟩, ?_, ?_⟩ + · unfold capability.Rights.from_word + simp only [lift, bind_ok] + rfl + simp [capability.mask_vm_rights, capability.VM_READ_ONLY, capability.VM_READ_WRITE] + simp only [hrr, hs1, bind_ok] + show (do let vm ← capability.mask_vm_rights 3#u64 rr + let s2 ← vspace.insert_subframes bst s1 (rsV (57 + nc)) (bwv RRb) (firstS nc) + (wa (bwv FRn) 0#u64) 2#u64 vm + ok (core.result.Result.Ok (), s2)) = _ + rw [hvm] + show Std.bind (ok 3#u64) _ = _ + rw [bind_ok] + rfl + +end dec + +theorem frn_canon : CapRt.Canonical (bwv FRn) := by + right + intro j hj h + have hv : (bwv FRn : U64).bv.toNat = FRn := vFR + rw [BitVec.getElem_eq_testBit_toNat, hv] + interval_cases j <;> decide + +section ins +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} +variable (hL : BootLayA ib nc) (hK : BootKsA kb ib nc) (P : BootLay1 kb ib nc) +include hL hK P +local notation "SR" => w1vR kb ib nc r now mt sl uw 0#u64 0#u64 (firstS nc) + +/-- **The pure inputs of `JStage3A.subframesA` at the witness**: the source slot `57 + nc` (the `Large` frame cap on `FRn`), the +destination root CNode (radix 13) with the window `[60 + nc, 62 + nc)` empty, `offset = 0`, `count = 2`, `vm = 3`. -/ +theorem wit_sub_ins : + AbsSlotA (w1vThA kb ib nc) (w1RrSlotA (57 + nc)) ∧ + w1vThA kb ib nc (bwv RRb) = some (.cnode 13) ∧ (1 ≤ 13 ∧ 13 ≤ 58) ∧ + CapRt.Canonical (bwv FRn) ∧ (bwv FRn).val % 2 ^ 21 = 0 ∧ + (1 ≤ (3#u64 : U64).val ∧ (3#u64 : U64).val ≤ 3) ∧ + (0#u64 : U64).val + (2#u64 : U64).val * 4096 ≤ 2 ^ 21 ∧ + (60 + nc) + (2#u64 : U64).val ≤ 2 ^ 13 ∧ (0#u64 : U64).val % 4096 = 0 ∧ + capAtA (bL.mem SR) (cslotAddrA (w1RrSlotA (57 + nc))) = + .Frame (bwv FRn) .Large 3#u64 false false false 0#u64 0#u64 ∧ + (∀ j < (2#u64 : U64).val, capAtA (bL.mem SR) (cslotAddrA + (specPtr (bwv RRb), Fl4SpecA64.natToCref 13 (60 + nc + j))) = .Null) ∧ + ¬ IrqNodeA (bL.ksb SR) (bwv RRb) := by + have h128 := P.w0.nc128 + have hkb := P.kbR + have vF : (bwv FRn : U64).val = FRn := vFR + refine ⟨(cteV hL hK P (j := 57 + nc) (by omega)).1, w1vTh_old hL hK P w1ThA_rr, by omega, ?_, ?_, + by simp, by simp, by simp; omega, by simp, ?_, ?_, ?_⟩ + · exact Or.inr (by decide) + · rw [vF]; norm_num + · rw [(cteV hL hK P (j := 57 + nc) (by omega)).2.1] + rw [show 57 + nc = 53 + nc + 4 by omega] + have h4 := capR_new (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (v0 := 0#u64) (v1 := 0#u64) + (v2 := firstS nc) P (k := 4) (by omega) + rw [show newC 4 = .Frame (bwv FRn) .Large 3#u64 false false false 0#u64 0#u64 by simp [newC]] at h4 + exact h4 + · intro j hj + have hj : j < 2 := by simpa using hj + have e : (specPtr (bwv RRb), Fl4SpecA64.natToCref 13 (60 + nc + j)) = w1RrSlotA (60 + nc + j) := by + unfold w1RrSlotA + rw [natToCref_eqA _ _ (by norm_num), Nat.mod_eq_of_lt (by omega)] + rw [e, cslotAddr_rrA hL hK P (by omega)] + exact wit_sub_empty P (by omega) (by omega) + · rintro ⟨i, hi, e⟩ + have vR : (bwv RRb : U64).val = RRb := bwv_val (by norm_num) + have k : bL.ksb SR = kb := rfl + rw [k] at e + have h := congrArg UScalar.val e + rw [irqSlot_val (by omega) hi, vR] at h + omega + +end ins + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitSyscA.lean b/proofs/Fl4ProofsA64/P3/A64WitSyscA.lean index b42c00a78..979eecc94 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitSyscA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitSyscA.lean @@ -22,7 +22,7 @@ noncomputable section local notation "wa" => core.num.U64.wrapping_add -variable {c0 r now mt sl : U64} {uw : U64 → U64} +variable {c0 : WitMsg} {r now mt sl : U64} {uw : U64 → U64} local notation "S1" => w1S KB IB 1 r now mt sl uw local notation "S2" => witSc c0 r now mt sl uw @@ -36,9 +36,9 @@ local notation "OS1" => w1OS KB IB 1 /-! ## The thread relations -/ /-- The root TCB's words at the witness. -/ -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 +def witRtW (c0 : WitMsg) (o : Nat) : U64 := + if o = 256 then c0.x0 else if o = 264 then c0.x1 else if o = 272 then c0.x2 else + if o = 280 then c0.x3 else if o = 288 then c0.x4 else if o = 296 then c0.x5 else if o = 304 then c0.x6 else if o = 528 then 4194300#u64 else rtW IB o theorem wit_rtWords : TcbWordsA (bL.mem S2) (bwv RTb) (witRtW c0) := by intro x o ho _ hx diff --git a/proofs/Fl4ProofsA64/P3/A64WitTopA.lean b/proofs/Fl4ProofsA64/P3/A64WitTopA.lean index 6099a2fc4..59acdc4a6 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitTopA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitTopA.lean @@ -43,10 +43,10 @@ theorem wit_frameMasks : A64FrameMasks bst S2 := rfl theorem wit_capWord : bL.mem S2 (regWA RT layout.reg.CAP) = 2#u64 := by have e : layout.reg.CAP = 0#u64 := by simp [layout.reg.CAP, layout.reg.X0] - have h := regW2 (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) 0#u64 (by simp) + have h := regW2 (c0 := WitMsg.copy) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) 0#u64 (by simp) rw [tcb_reg_eqA] at h rw [e] - exact (ok_inj_ff h).trans (by simp [witRtW]) + exact (ok_inj_ff h).trans (by simp [witRtW, WitMsg.copy]) theorem wit_slot2 : cspace.lookup_slot bst S2 RT 2#u64 = ok (.Ok { slot := SL2, bits_left := 0#u64 }) := wit_lookupSlot (cptr := 2#u64) (by simp) (slot := SL2) (by rw [bwv_val (by omega)]; simp) diff --git a/proofs/Fl4ProofsA64/P3/A64WitUtA.lean b/proofs/Fl4ProofsA64/P3/A64WitUtA.lean index 308544306..b4e60902e 100644 --- a/proofs/Fl4ProofsA64/P3/A64WitUtA.lean +++ b/proofs/Fl4ProofsA64/P3/A64WitUtA.lean @@ -13,6 +13,10 @@ state-level fields of the arm are satisfiable: 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`). +`wit_utChunk_prems` does the same for the chunk-loop arms' platform premises. Not instantiated for them: a used untyped +(`fi ≠ 0`), the reset run (`hres`), `DelPlatA`, the entry clock and the post-reset barriers (`hPost`, a statement about +the opaque barrier operations): the run witness is the witness line's backlog. + Named premises: `OpaqueWA` [P]. New module. -/ import Fl4ProofsA64.P3.A64Wit2TierA @@ -30,7 +34,7 @@ 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) + rw [capS2_rs (c0 := WitMsg.copy) (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 @@ -53,6 +57,20 @@ theorem wit_ut_prems (O : OpaqueWA) (a : WA) : obtain ⟨-, -, rfl, -⟩ := capability.Cap.Untyped.inj h exact Or.inr rfl +/-- **Platform and state premises of the chunk-loop arms** (`UtPreScopeA.retypeRstPre`, `UtScopeA.retypeRstBig`) at the +witness world: one core, the chunk size, the entry `CounterStepA`, and the untyped of slot `53` is at least a chunk. -/ +theorem wit_utChunk_prems (O : OpaqueWA) {c0 : WitMsg} {mt sl : U64} {uw : U64 → U64} : + Fl4SpecA64.fl4A64Platform.numNodes ≤ Fl4SpecA64.fl4A64Platform.numNodes ∧ + (∀ c ∈ witZA.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) ∧ Fl4SpecA64.resetChunkBits = 16 ∧ + Sched.CounterStepA (witSAc c0 wNow mt sl uw) ∧ + (∀ {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 → 16 ≤ sb.val) := by + refine ⟨le_refl _, wit_hCs O, O.chunk, wit_counterStep, ?_⟩ + intro r now mt sl uw p sb fi h + rw [wit_ut_cap] at h + obtain ⟨-, rfl, -, -⟩ := capability.Cap.Untyped.inj h + decide + end end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitUtMsgA.lean b/proofs/Fl4ProofsA64/P3/A64WitUtMsgA.lean new file mode 100644 index 000000000..1f4470697 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitUtMsgA.lean @@ -0,0 +1,127 @@ +/- +P3 (aarch64, A64-P5 line wit, S2a): **the UntypedRetype message at the witness, and FL4's prefix lookups of it.** + +The root thread invokes its RAM Untyped (root CNode slot `53`, `Untyped UTb 20 0 false`) with `UntypedRetype`: an Endpoint +(`new_type = 2`, `size_bits = 0`), the destination being the root CNode itself (`node_depth = 0`, so the extra cap's own +CNode), `node_offset = 1000` (an empty slot), `node_window = 1`. + +* `WitMsg.retype`: `x0 = 53` (the CAP cptr), `x1 = 4230` (label `1` = `UntypedRetype`, no unwrapped caps, one extra cap, + length 6), `x2`-`x5` = `MR0`-`MR3` = `2, 0, 0, 0` (type, size, node index, node depth). +* `UtUw`: the IPC-buffer words: word 122 (the extra cap's cptr) is `2` (root CNode slot 2, the root CNode cap), word 5 + (`MR4`, the node offset) is `1000`, word 6 (`MR5`, the node window) is `1`. +* `wit_msgInfoU`, `wit_extraCapsU`, `wit_slotU`, `wit_capU`: `msg_info`, `lookup_extra_caps` and the CSpace walk of cptr `53`. +* `wit_prefixU`: any successful prefix lookups are these. + +Named premise: the three IPC-buffer words (`UtUw`). New module. +-/ +import Fl4ProofsA64.P3.A64WitReadA +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 + +noncomputable section + +/-- **The Retype message of the Untyped witness** (module docstring). -/ +abbrev WitMsg.retype : WitMsg := ⟨53#u64, 4230#u64, 2#u64, 0#u64, 0#u64, 0#u64, 0#u64⟩ + +/-- The Untyped witness's store. -/ +abbrev witSu (r now mt sl : U64) (uw : U64 → U64) : BS := witSc WitMsg.retype r now mt sl uw + +/-- The Untyped witness's spec state. -/ +abbrev witSAu (now mt sl : U64) (uw : U64 → U64) : Fl4SpecA64.State Unit := witSAc WitMsg.retype now mt sl uw + +/-- The three IPC-buffer words of the Retype message. -/ +structure UtUw (uw : U64 → U64) : Prop where + cap0 : ∀ b : U64, b.val = IPb + 976 → uw b = 2#u64 + off : ∀ b : U64, b.val = IPb + 40 → uw b = 1000#u64 + win : ∀ b : U64, b.val = IPb + 48 → uw b = 1#u64 + +/-- Such user words exist. -/ +theorem utUw_ex : ∃ uw, UtUw uw := + ⟨fun b => if b.val = IPb + 976 then 2#u64 else if b.val = IPb + 40 then 1000#u64 else 1#u64, + ⟨fun _ h => if_pos h, fun _ h => by rw [if_neg (by omega), if_pos h], + fun _ h => by rw [if_neg (by omega), if_neg (by omega)]⟩⟩ + +variable {r now mt sl : U64} {uw : U64 → U64} + +local notation "SU" => witSu r now mt sl uw +local notation "RT" => (bwv RTb) +local notation "SLU" => (bwv (RRb + 32 * 53)) + +/-- **`msg_info`**: label `UntypedRetype`, one extra cap, length 6. -/ +theorem wit_msgInfoU : msg.msg_info bst SU RT = + ok { label := 1#u64, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := 6#u64 } := by + have e : layout.reg.MSG_INFO = 1#u64 := by simp [layout.reg.MSG_INFO, layout.reg.X1] + have v : witRtW WitMsg.retype (256 + 8 * (1#u64 : U64).val) = 4230#u64 := by simp [witRtW, WitMsg.retype] + have s12 : (4230#u64 : U64) >>> 12#i32 = ok 1#u64 := by rfl + have s9 : (4230#u64 : U64) >>> 9#i32 = ok 8#u64 := by rfl + have s7 : (4230#u64 : U64) >>> 7#i32 = ok 33#u64 := by rfl + have m1 : (8#u64 : U64) &&& 7#u64 = 0#u64 := by rfl + have m2 : (33#u64 : U64) &&& 3#u64 = 1#u64 := by rfl + have m3 : (4230#u64 : U64) &&& 127#u64 = 6#u64 := by rfl + have le : ¬ (6#u64 : U64) > fl4_abi.consts.MSG_MAX_LENGTH := by + simp [fl4_abi.consts.MSG_MAX_LENGTH] + unfold msg.msg_info + rw [e, regW2 (c0 := WitMsg.retype) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) 1#u64 (by simp), + bind_ok, v] + unfold msginfo.MessageInfo.from_word_clamped msginfo.MessageInfo.from_word + rw [s12, bind_ok, s9, bind_ok] + simp only [lift, bind_ok] + rw [s7, bind_ok] + simp only [bind_ok, m1, m2, m3] + rw [if_neg le] + +/-- The extra cap: root CNode slot 2. -/ +theorem wit_extraCapsU (U : UtUw uw) : ipc.lookup_extra_caps bst SU RT (bwv IPb) + { label := 1#u64, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := 6#u64 } = ok (.Ok witExtra) := + wit_extraCapsG (c0 := WitMsg.retype) U.cap0 + +/-- **The CSpace walk of cptr `53`** is root CNode slot 53. -/ +theorem wit_slotU : cspace.lookup_slot bst SU RT 53#u64 = ok (.Ok { slot := SLU, bits_left := 0#u64 }) := + wit_lookupSlot (c0 := WitMsg.retype) (cptr := 53#u64) (by simp) (slot := SLU) + (by rw [bwv_val (by omega)]; simp) + +/-- **The invoked cap**: the RAM Untyped, free index `0`. -/ +theorem wit_capU : capA bst SU SLU = .Untyped (bwv UTb) 20#u64 0#u64 false := by + rw [capS2_rs (c0 := WitMsg.retype) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (i := 53) (by norm_num) + (by rw [bwv_val (by omega)])] + rfl + +theorem wit_capWordU : bL.mem SU (regWA RT layout.reg.CAP) = 53#u64 := by + have e : layout.reg.CAP = 0#u64 := by simp [layout.reg.CAP, layout.reg.X0] + have h := regW2 (c0 := WitMsg.retype) (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) 0#u64 (by simp) + rw [tcb_reg_eqA] at h + rw [e] + exact (ok_inj_ff h).trans (by simp [witRtW, WitMsg.retype]) + +/-- The message info the Untyped witness reads. -/ +def witInfoU : msginfo.MessageInfo := + { label := 1#u64, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := 6#u64 } + +/-- The run's prefix, from any successful lookups: they are the Untyped witness's. -/ +theorem wit_prefixU (U : UtUw uw) {info : msginfo.MessageInfo} {buf : U64} {r1 : cspace.Resolved} + {e : Aeneas.Std.Array obj.Slot 3#usize} + (h1 : msg.msg_info bst SU (bL.curW SU) = ok info) + (h2 : msg.lookup_ipc_buffer bst SU false (bL.curW SU) = ok buf) + (h3 : cspace.lookup_slot bst SU (bL.curW SU) (bL.mem SU (regWA (bL.curW SU) layout.reg.CAP)) = ok (.Ok r1)) + (h4 : ipc.lookup_extra_caps bst SU (bL.curW SU) buf info = ok (.Ok e)) : + info = witInfoU ∧ buf = bwv IPb ∧ r1 = { slot := SLU, bits_left := 0#u64 } ∧ e = witExtra := by + rw [curW2] at h1 h2 h3 h4 + rw [wit_msgInfoU] at h1 + rw [wit_ipcBuffer (c0 := WitMsg.retype)] at h2 + rw [wit_capWordU, wit_slotU] at h3 + have e1 := ok_inj_ff h1 + have e2 := ok_inj_ff h2 + have e3 := ok_inj_ff h3 + injection e3 with e3 + subst e1 e2 + rw [wit_extraCapsU U] at h4 + have e4 := ok_inj_ff h4 + injection e4 with e4 + exact ⟨rfl, rfl, e3.symm, e4.symm⟩ + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitUtScopeA.lean b/proofs/Fl4ProofsA64/P3/A64WitUtScopeA.lean new file mode 100644 index 000000000..9d2773f3e --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitUtScopeA.lean @@ -0,0 +1,325 @@ +/- +P3 (aarch64, A64-P5 line wit, S2b): **the spec side of the Untyped Retype arm at the witness: `UtScopeA.retypeRst`.** + +At the Retype message of `P3/A64WitUtMsgA` (an Endpoint into the root CNode, slot `1000`, from the RAM Untyped of slot `53`, +free index `0`, no CDT child): + +* `OpaqueUtWA` [W]: the two facts about `opaque` constants the arm asks beyond `OpaqueWA`: `fl4A64Virt = false` (the model + arch has no virtualization: `hvirt`) and `retypeFanOutLimit = 256` (`hfan`); +* `wit_tauU`: the budget prefix leaves the spec's `cdt` and heap as the witness state's; +* `wit_decS`: `fl4DecodeUntypedInvocationVirt` of the message succeeds with one outcome, the state unchanged (`hdecS`); +* `wit_excapsU`, `wit_argsUeq`: the extra caps and the message arguments the front end reads are the witness's; +* `wit_utScopeU`: `UtScopeA.retypeRst` at the invocation site `SiteA`: every premise from the record, the facts above + and the model arch ([P] `hVP`, `hKt` / `hK0` of `w1Ar`, `hIpa`, `hchunk`, `numNodes = 1`). + +Named premises: [P] `OpaqueWA` (as the other witnesses), [W] `OpaqueUtWA`. New module. +-/ +import Fl4ProofsA64.P3.A64WitUtMsgA +import Fl4ProofsA64.P3.A64WitUtA +import Fl4ProofsA64.P3.A64Wit2TierA +import Fl4ProofsA64.P3.CnodeDelZombieA +import Fl4ProofsA64.P3.CnodeDelDefA +import Fl4ProofsA64.P3.UtSpecA +import Fl4ProofsA64.P3.UtDecodeA +import Fl4ProofsA64.P3.A64Wit3ClockA +import Fl4ProofsA64.P3.Stage3SiteA +import Fl4ProofsA64.P3.Stage3DispUtA +import Fl4ProofsA64.P3.Stage3PinCnA +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 time-stamp state's `cdt` and heap are the witness's. -/ +theorem wit_tauU (O : OpaqueWA) {c0 : WitMsg} {mt sl : U64} {uw : U64 → U64} + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) {τPC τ : State Unit} + (pc : fl4SyscallFaultIP (Z := Unit) (witSAc c0 wNow mt sl uw).curThread (witSAc c0 wNow mt sl uw) = + ({((), τPC)}, False)) + (b : fl4BudgetOk (Z := Unit) τPC = ({(true, τ)}, False)) : + τ.cdt = (witSAc c0 wNow mt sl uw).cdt ∧ τ.kheap = (witSAc c0 wNow mt sl uw).kheap := by + have hτ : τPC = witSAc c0 wNow mt sl uw := + (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (pc.symm.trans wit_pc)))).2 + subst hτ + obtain ⟨σ1, e, hc, hk, hct⟩ : ∃ σ1 : State Unit, fl4UpdateTimestamp (Z := Unit) (witSAc c0 wNow mt sl uw) = + ({((), σ1)}, False) ∧ σ1.cdt = (witSAc c0 wNow mt sl uw).cdt ∧ σ1.kheap = (witSAc c0 wNow mt sl uw).kheap ∧ + σ1.curThread = (witSAc c0 wNow mt sl uw).curThread := ⟨_, Sched.fl4UpdateTimestamp_eqA _, rfl, rfl, rfl⟩ + have hs := wit_hsuf O hsl e + have hcb : fl4CheckBudget (Z := Unit) σ1 = ({(true, σ1)}, False) := by + unfold fl4CheckBudget + rw [nd_gets_bindSc, nd_gets_bindSc, nd_bind_oneSc hs, if_pos rfl, nd_gets_bindSc] + simp only [Fl4SpecA64.isCurDomainExpired, O.nd] + rfl + have htcb : σ1.kheap σ1.curThread = some (.tcb (witTcbA c0)) := by + rw [hk, hct]; exact Function.update_self _ _ _ + unfold fl4BudgetOk at b + rw [nd_bind_oneSc e] at b + unfold fl4CheckBudgetRestart at b + rw [nd_bind_oneSc hcb, nd_gets_bindSc, nd_bind_oneSc (getThreadState_eq htcb)] at b + have b' : ((NonDet.when (¬(true = true) ∧ runnable (witTcbA c0).tcbState = true) + (setThreadState σ1.curThread ThreadState.restart) >>= fun _ => pure true) σ1) = ({(true, τ)}, False) := b + rw [NonDet.when, if_neg (fun h => h.1 rfl)] at b' + have b'' : (({(true, σ1)}, False) : Set (Bool × State Unit) × Prop) = ({(true, τ)}, False) := by + rw [← b'] + change _ = ((pure () : NonDet (State Unit) Unit) >>= fun _ => pure true) σ1 + rw [nd_pure_bindSc]; rfl + have hτ1 : σ1 = τ := (Prod.mk.inj (Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst b''))).2 + subst hτ1 + exact ⟨hc, hk⟩ + + +/-- Witness-world [W] facts about `opaque` constants of the Untyped Retype arm. -/ +structure OpaqueUtWA : Prop where + virt : Fl4SpecA64.fl4A64Virt = false + fan : Fl4SpecA64.retypeFanOutLimit = 256#64 + +/-- The Retype message's arguments, as the spec reads them. -/ +abbrev witArgsU : List Data := [2, 0, 0, 0, 1000, 1] + +theorem witArgsU_eq : witArgsU = [2#u64, 0#u64, 0#u64, 0#u64, 1000#u64, 1#u64].map UScalar.bv := rfl + +macro "wW" : tactic => `(tactic| rw [run_bind_okA (run_whenE_falseA ?_ _ _)]) +macro "wU" : tactic => `(tactic| rw [run_bind_okA (run_unlessE_trueA ?_ _ _)]) + +/-- `get_cap` of an empty root-CNode slot. -/ +theorem getCap_rootNullU {τ : State Unit} (hk : τ.kheap (specPtr (bwv RRb)) = some (.cnode 13 (rootCsA 1))) + {idx : List Bool} (hc : rootCsA 1 idx = some .nullCap) : + getCap (Z := Unit) (specPtr (bwv RRb), idx) τ = ({(.nullCap, τ)}, False) := by + unfold getCap + show (getObject _ >>= _) τ = _ + rw [nd_bind_singleA (getObject_oneA hk)] + dsimp only + have h2 : (NonDet.assert (wellFormedCnodeN 13 (rootCsA 1)) : NonDet (State Unit) Unit) τ = ({((), τ)}, False) := by + simp [NonDet.assert, rootCsA_wf] + simp only [nd_bind_singleA h2, nd_pure_bindA] + exact assertOpt_oneA hc τ + +theorem rootCs_null1000 : rootCsA 1 (natToCref 13 1000) = some .nullCap := by + unfold rootCsA + rw [if_pos (natToCref_length_utA 13 1000 (by norm_num)), natToCref_utA 13 1000 (by norm_num), blvA_bitsOfA] + have : BootWit.capOf 1 (1000 % 2 ^ 64 % 2 ^ 13) = .Null := by + show BootWit.capOf 1 1000 = .Null + unfold BootWit.capOf + rw [slotC_hi (by omega), tailC_big (by omega)] + rw [this]; rfl + + +theorem wit_decS (OU : OpaqueUtWA) {τ : State Unit} {slbl : Data} + (hlbl : genInvocationType slbl = .untypedRetype) + (hk : τ.kheap (specPtr (bwv RRb)) = some (.cnode 13 (rootCsA 1))) + (hcdt : τ.cdt = w1CdtA) {cap rc : Cap} (hcap : cap = .untypedCap false (specPtr (bwv UTb)) 20 0) + (hrc : rc = .cnodeCap (specPtr (bwv RRb)) 13 (bitsOfA 0 51)) : + ∃ inv, (fl4DecodeUntypedInvocationVirt (Z := Unit) slbl witArgsU + (w1RrSlotA 53) cap [rc]).run τ = ({(.ok inv, τ)}, False) ∧ + inv = .retype (w1RrSlotA 53) true (specPtr (bwv UTb)) (specPtr (bwv UTb)) .endpointObject 0 + [(specPtr (bwv RRb), natToCref 13 1000)] false := by + classical + subst hcap hrc + rw [fl4DecodeUntypedInvocationVirt_other (by + simp [fl4UntypedVirtRefused, Fl4SpecA64.the, dataToNat, unat])] + unfold fl4DecodeUntypedInvocation decodeUntypedInvocationWith + refine ⟨?w, ?_, ?e⟩ + rotate_left + simp only [NonDetE.returnOk, ndE_pure_bindA] + wU + wW + wW + have hT : (fl4DataToObjType (Z := Unit) (the witArgsU[0]?)).run τ = ({(.ok .endpointObject, τ)}, False) := by + rw [fl4DataToObjType_runA] + simp [witArgsU, Fl4SpecA64.the, objTypeOfA] + rw [run_bind_okA hT] + wU + wW + wW + wW + rw [ite_eq_left (show dataToNat (the witArgsU[3]?) = 0 by simp [witArgsU, Fl4SpecA64.the, dataToNat, unat])] + simp only [ndE_pure_bindA] + rw [ite_eq_left (show isCnodeCap (the [Cap.cnodeCap (specPtr (bwv RRb)) 13 (bitsOfA 0 51)][0]?) = true by + simp [isCnodeCap, Fl4SpecA64.the])] + wW + wW + wW + have hME : ∀ slots : List CslotPtr, (∀ sl ∈ slots, getCap (Z := Unit) sl τ = ({(.nullCap, τ)}, False)) → + (NonDetE.mapMEx (ensureEmpty (Z := Unit)) slots).run τ = ({(.ok (), τ)}, False) := fun slots h => by + rw [mapMEx_ensureEmpty_runA τ (fun _ => .nullCap) slots h] + simp + rw [run_bind_okA (hME _ ?_)] + have hnc : decide (¬ ∃ x, τ.cdt x = some (w1RrSlotA 53)) = true := + decide_eq_true (by rw [hcdt]; exact wit_ut_nochild) + have hcr := run_liftEA (ε := SyscallError) (constOnFailure_runA τ (w1RrSlotA 53)) + rw [hnc] at hcr + erw [run_bind_okA hcr] + simp only [ndE_pure_bindA, if_true] + wW + wW + rfl + all_goals first + | exact hlbl + | (congr 1 <;> first | rfl | decide +kernel) + | (simp [witArgsU, Fl4SpecA64.the, dataToNat, unat, isFrameType, objSize, fl4ObjBitsApi, bitsOf, natToCref, wordBits, untypedMaxBits, objBitsApi, endpointBits]; done) + | (simp [witArgsU, Fl4SpecA64.the, dataToNat, unat, OU.fan]; done) + | (intro sl hsl + simp [witArgsU, Fl4SpecA64.the, dataToNat, unat, objRefOf, bitsOf] at hsl + subst hsl + exact getCap_rootNullU hk rootCs_null1000) + + +variable {r now mt sl : U64} {uw : U64 → U64} +local notation "SU" => witSu r wNow mt sl uw + +theorem exAt_witExtra0 : exAtA witExtra 0 = bwv (RRb + 64) := by simp [exAtA, witExtra, Aeneas.Std.Array.make] +theorem exAt_witExtra1 : exAtA witExtra 1 = 0#u64 := by simp [exAtA, witExtra, Aeneas.Std.Array.make] +theorem exAt_witExtra2 : exAtA witExtra 2 = 0#u64 := by simp [exAtA, witExtra, Aeneas.Std.Array.make] + +/-- The extra caps: exactly the root CNode cap of slot 2. -/ +theorem wit_excapsU {th : TypedHeapA} {kb : U64} (hP : PlaceA th kb) + {excaps : List (Fl4SpecA64.Cap × CslotPtr)} + (hx : ExtraOKA th (bL.mem SU) witExtra excaps) : + ∃ y, excaps = [y] ∧ cslotAddrA y.2 = bwv (RRb + 64) ∧ y.1 = absCapA (.CNode (bwv RRb) 13#u64 51#u64 0#u64) := by + obtain ⟨-, H⟩ := ExtraOKA.xc hP hx + rw [exAt_witExtra0, exAt_witExtra1, exAt_witExtra2] at H + have ne : bwv (RRb + 64) ≠ 0#u64 := by + intro h + have := congrArg UScalar.val h + rw [bwv_val (by omega)] at this + simp at this + obtain ⟨h0a, h0b⟩ := H 0 (bwv (RRb + 64)) rfl + obtain ⟨h1a, -⟩ := H 1 0#u64 rfl + have l1 : excaps.length ≤ 1 := h1a.1 rfl + have l0 : ¬ excaps.length ≤ 0 := fun h => ne (h0a.2 h) + rcases excaps with _ | ⟨y, _ | ⟨y', t⟩⟩ + · exact absurd (le_refl _) l0 + · obtain ⟨hx0, hcap, -⟩ := h0b y rfl + refine ⟨y, rfl, hx0.symm, ?_⟩ + rw [capAtA_eq (st := bst), sl2_cap (c0 := WitMsg.retype)] at hcap + exact (show absCapA (.CNode (bwv RRb) 13#u64 51#u64 0#u64) = y.1 from hcap).symm + · simp at l1 + +theorem wit_msgLenU : msgLenA witInfoU (bwv IPb) = 6#u64 := by + have n : msg.N_MSG_REGISTERS = 4#u64 := by simp [msg.N_MSG_REGISTERS] + have ne : (bwv IPb) ≠ 0#u64 := fun e => by + have := congrArg UScalar.val e + rw [vIP] at this + simp at this + unfold msgLenA witInfoU + rw [n, if_pos (by scalar_tac), if_neg ne] + +theorem wit_argsUeq (U : UtUw uw) {argsU : List U64} + (hlen : (msgLenA witInfoU (bwv IPb)).val = argsU.length) + (hargs : ∀ (i : U64) x, argsU[i.val]? = some x → msg.syscall_arg bst SU (bL.curW SU) (bwv IPb) i = ok x) : + argsU = [2#u64, 0#u64, 0#u64, 0#u64, 1000#u64, 1#u64] := by + rw [wit_msgLenU] at hlen + have hc : bL.curW SU = bwv RTb := curW2 + rw [hc] at hargs + have arg : ∀ (i k : U64), i.val < 4 → msg.msg_register i = ok k → k.val < 6 → + msg.syscall_arg bst SU (bwv RTb) (bwv IPb) i = ok (witRtW WitMsg.retype (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 (c0 := WitMsg.retype) k hk] + have buf : ∀ (i : U64) (k : U64) (hk : k.val < 512), i.val = 4 ∨ i.val = 5 → + msg.syscall_arg bst SU (bwv RTb) (bwv IPb) i = ok (uw (bwv (IPb + 8 * k.val))) → True := fun _ _ _ _ _ => trivial + have a0 : msg.syscall_arg bst SU (bwv RTb) (bwv IPb) 0#u64 = ok 2#u64 := by + rw [arg 0#u64 2#u64 (by simp) (by simp [msg.msg_register, layout.reg.X2]) (by simp)] + simp [witRtW, WitMsg.retype] + have a1 : msg.syscall_arg bst SU (bwv RTb) (bwv IPb) 1#u64 = ok 0#u64 := by + rw [arg 1#u64 3#u64 (by simp) (by simp [msg.msg_register, layout.reg.X3]) (by simp)] + simp [witRtW, WitMsg.retype] + have a2 : msg.syscall_arg bst SU (bwv RTb) (bwv IPb) 2#u64 = ok 0#u64 := by + rw [arg 2#u64 4#u64 (by simp) (by simp [msg.msg_register, layout.reg.X4]) (by simp)] + simp [witRtW, WitMsg.retype] + have a3 : msg.syscall_arg bst SU (bwv RTb) (bwv IPb) 3#u64 = ok 0#u64 := by + rw [arg 3#u64 5#u64 (by simp) (by simp [msg.msg_register, layout.reg.X5]) (by simp)] + simp [witRtW, WitMsg.retype] + have ne : (bwv IPb) ≠ 0#u64 := fun e => by + have := congrArg UScalar.val e + rw [vIP] at this + simp at this + have n : msg.N_MSG_REGISTERS = 4#u64 := by simp [msg.N_MSG_REGISTERS] + have a4 : msg.syscall_arg bst SU (bwv RTb) (bwv IPb) 4#u64 = ok 1000#u64 := by + have v : (bwv (IPb + 40)).val = IPb + 40 := bwv_val (by omega) + unfold msg.syscall_arg + rw [n, if_neg (by scalar_tac), if_pos (by simpa using ne)] + simp only [lift, bind_ok] + rw [show core.num.U64.wrapping_add 4#u64 1#u64 = 5#u64 from rfl, + bufGet (c0 := WitMsg.retype) (k := 5#u64) (b := bwv (IPb + 40)) (by simp) (by rw [v]; simp), U.off _ v] + have a5 : msg.syscall_arg bst SU (bwv RTb) (bwv IPb) 5#u64 = ok 1#u64 := by + have v : (bwv (IPb + 48)).val = IPb + 48 := bwv_val (by omega) + unfold msg.syscall_arg + rw [n, if_neg (by scalar_tac), if_pos (by simpa using ne)] + simp only [lift, bind_ok] + rw [show core.num.U64.wrapping_add 5#u64 1#u64 = 6#u64 from rfl, + bufGet (c0 := WitMsg.retype) (k := 6#u64) (b := bwv (IPb + 48)) (by simp) (by rw [v]; simp), U.win _ v] + rcases argsU with _ | ⟨x0, _ | ⟨x1, _ | ⟨x2, _ | ⟨x3, _ | ⟨x4, _ | ⟨x5, _ | ⟨x6, t⟩⟩⟩⟩⟩⟩⟩ <;> simp at hlen + have e0 := ok_inj_ff ((hargs 0#u64 x0 rfl).symm.trans a0) + have e1 := ok_inj_ff ((hargs 1#u64 x1 rfl).symm.trans a1) + have e2 := ok_inj_ff ((hargs 2#u64 x2 rfl).symm.trans a2) + have e3 := ok_inj_ff ((hargs 3#u64 x3 rfl).symm.trans a3) + have e4 := ok_inj_ff ((hargs 4#u64 x4 rfl).symm.trans a4) + have e5 := ok_inj_ff ((hargs 5#u64 x5 rfl).symm.trans a5) + rw [e0, e1, e2, e3, e4, e5] + +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA WClock ar1_total ar1_plat) in +theorem wit_utScopeU (O : OpaqueWA) (OU : OpaqueUtWA) (U : UtUw uw) {Z : XSetsA} {τ : State Unit} + (hZ : Z.th = w1ThA KB IB 1) (hZc : Z.Cs = witZA.Cs) (hcdt : τ.cdt = w1CdtA) (hkh : τ.kheap = (witSAu wNow mt sl uw).kheap) + {info : msginfo.MessageInfo} {buf : U64} {r1 : cspace.Resolved} {e : Aeneas.Std.Array obj.Slot 3#usize} + {mi : MessageInfo} {sl' : CslotPtr} {c : Cap} {excaps : List (Cap × CslotPtr)} {buffer : Option ObjRef} + {argsU : List U64} + (h1 : msg.msg_info bst SU (bL.curW SU) = ok info) (h2 : msg.lookup_ipc_buffer bst SU false (bL.curW SU) = ok buf) + (h3 : cspace.lookup_slot bst SU (bL.curW SU) (bL.mem SU (regWA (bL.curW SU) layout.reg.CAP)) = ok (.Ok r1)) + (h4 : ipc.lookup_extra_caps bst SU (bL.curW SU) buf info = ok (.Ok e)) + (S : SiteA bst Z (w1OS KB IB 1) SU τ info buf r1.slot e mi sl' c excaps buffer argsU) + (a : WA) (calling blocking donate : Bool) : + ∃ Out, UtScopeA bst (fun _ _ => True) Fl4SpecA64.fl4A64Platform.numNodes Z (w1OS KB IB 1) AR1 SU a τ + info.label (msgLenA info buf) r1.slot blocking calling donate false buf e Out := by + obtain ⟨rfl, rfl, rfl, rfl⟩ := wit_prefixU U h1 h2 h3 h4 + have hP := S.place + have hsl' : sl' = w1RrSlotA 53 := + (cslotAddrA_inj hP (by rw [hZ]; exact w1RrSlotA_abs 53) S.F.pin.habs + ((cslotAddr_rrA layA layK lay1 (j := 53) (by norm_num)).trans S.F.pin.hslot)).symm + subst hsl' + have hargs := wit_argsUeq U S.F.len S.F.args + have hc : c = .untypedCap false (specPtr (bwv UTb)) 20 0 := by + have h := S.F.cap.2 + rw [wit_capU] at h + exact h.symm + obtain ⟨y, hy, hya, hy1⟩ := wit_excapsU hP S.F.extra + subst hargs hy hc + have hrr : specPtr (bwv RRb) ≠ specPtr (bwv RTb) := fun h => by + have := congrArg UScalar.val (specPtr_inj h) + rw [vRR, vRT] at this + revert this + norm_num + have hk' : τ.kheap (specPtr (bwv RRb)) = some (.cnode 13 (rootCsA 1)) := by + rw [hkh] + exact (Function.update_of_ne hrr _ _).trans w1KA_rr + have hlbl : genInvocationType (specLabelWord (fl4LabelOf mi.miLabel)) = .untypedRetype ↔ + witInfoU.label = fl4_abi.label.UntypedRetype := by + rw [S.F.lab]; exact ut_labelA _ + have hlbl' := hlbl.2 (by simp [witInfoU, fl4_abi.label.UntypedRetype]) + obtain ⟨inv, hd, -⟩ := wit_decS OU hlbl' hk' hcdt (cap := .untypedCap false (specPtr (bwv UTb)) 20 0) rfl + (rc := y.1) hy1 + exact ⟨_, UtScopeA.retypeRst (blk := blocking) (call := calling) (don := donate) (hslot := S.hOS) (hcov := S.cov) (hext := S.hext) (hslc := wit_capU) + (sl := w1RrSlotA 53) (hsl := S.F.pin.hslot) (hsrc := S.F.cnode) (vi := 0#u64) (hvi := rfl) + (hvirt := ⟨fun _ => OU.virt, fun _ => rfl⟩) (hfan := OU.fan) (slbl := specLabelWord (fl4LabelOf mi.miLabel)) + (hlbl := hlbl) (hlen := S.F.len) (hargs := S.F.args) (hex := S.F.extra) + (hnochild := by rw [hcdt]; exact wit_ut_nochild) (inv := inv) (hdecS := hd) + (hVP := fun a1 => ⟨(Fl4ProofsA64.P3.Wit3.ar1_vcpuPlat O).midr a1, (Fl4ProofsA64.P3.Wit3.ar1_vcpuPlat O).vtr a1, + (Fl4ProofsA64.P3.Wit3.ar1_vcpuPlat O).gic a1⟩) + (k := fun i => if i = 256#u64 then bwv KTe else 0#u64) + (hKt := fun a1 i _ => by + show (if (0#u64 : U64) = 0#u64 ∧ i = 256#u64 then ok (bwv KTe) else ok 0#u64) = + ok (if i = 256#u64 then bwv KTe else 0#u64) + by_cases h : i = 256#u64 <;> simp [h]) + (hK0 := fun i hi => by + have : i ≠ 256#u64 := by rintro rfl; simp at hi + simp [this]) (hnN := le_refl _) (h1 := O.nodes) + (hCs := fun c hc => wit_hCs O c (hZc ▸ hc)) (hS := Or.inr rfl) (hIpa := (⟨40#u64, rfl, by rw [O.ipaBits]; rfl⟩ : S2IpaE AR1 a)) (hchunk := O.chunk) + (hPost := fun h => absurd rfl h) + (hpin := DecPinA.of_frontA S.F.pin (fun cptr => run_liftME_okA hd))⟩ + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitUtTopA.lean b/proofs/Fl4ProofsA64/P3/A64WitUtTopA.lean new file mode 100644 index 000000000..f07631d01 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitUtTopA.lean @@ -0,0 +1,562 @@ +/- +P3 (aarch64, A64-P3 non-vacuity witness 2, Tier B): **`kernelEntrySend_recGA` at the Untyped Retype witness.** + +The Send witness world with `WitMsg.retype` as the message (`A64WitUtMsgA`): `UntypedRetype` of the RAM Untyped in slot 53 +into one Endpoint in the root CNode, `fi = 0` (so `UtScopeA.retypeRst`). + +* `wit_invoke_okVmU`, `wit_bodyNoVmU`, `wit2b_hNatU`: the entry body never leaves a thread running a VM (`hNat`, from `NoVmA`); +* `wit_JU`, `wit_decodeOkU`, `wit_notPreemptedU`, `wit_noDecodeErrU`: the decode returns `Ok` (from the arm `A64WitUtScopeA` and + `UtScopeA.soundOk`), so no `Err` arm is reachable; +* `wit_scopeU`: `SendScopeA` at the witness (`hArm` is `UtScopeA.retypeRst`); +* `wit_top_ut`: an inhabitant of `SendEntryHyps` and the theorem's conclusion there; `wit_ut_nonvacuous`: every witness-side + parameter is existential. + +Named premises: [P] `OpaqueWA` and the IRQ-oracle fact `hI` (as `wit_send_nonvacuous`), [W] `OpaqueUtWA`. New module. +-/ +import Fl4ProofsA64.P3.A64WitUtScopeA +import Fl4ProofsA64.P3.UtRtFrontA +import Fl4ProofsA64.P3.UtApSpecObjA +import Fl4ProofsA64.P3.A64Wit2bBodyA +import Fl4ProofsA64.P3.A64Wit2TierA +import Fl4ProofsA64.P3.A64Wit2TopA +import Fl4ProofsA64.P3.A64WitTopA +import Fl4ProofsA64.P3.Stage3WrapA +import Fl4ProofsA64.P3.ReplyRunExA +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 + +/-- `get_cap` of a root-CNode slot with a known cap. -/ +theorem getCap_rootU {τ : State Unit} (hk : τ.kheap (specPtr (bwv RRb)) = some (.cnode 13 (rootCsA 1))) + {idx : List Bool} {c : Cap} (hc : rootCsA 1 idx = some c) : + getCap (Z := Unit) (specPtr (bwv RRb), idx) τ = ({(c, τ)}, False) := by + unfold getCap + show (getObject _ >>= _) τ = _ + rw [nd_bind_singleA (getObject_oneA hk)] + dsimp only + have h2 : (NonDet.assert (wellFormedCnodeN 13 (rootCsA 1)) : NonDet (State Unit) Unit) τ = ({((), τ)}, False) := by + simp [NonDet.assert, rootCsA_wf] + simp only [nd_bind_singleA h2, nd_pure_bindA] + exact assertOpt_oneA hc τ + +theorem rootCs_53 : rootCsA 1 (bitsOfA 53 13) = some (.untypedCap false (specPtr (bwv UTb)) 20 0) := by + unfold rootCsA + rw [if_pos (by simp [length_bitsOfA]), blvA_bitsOfA] + rfl + +/-- The reset of the witness's untyped (free index `0`) is the identity. -/ +theorem reset_noopU {τ : State Unit} (hk : τ.kheap (specPtr (bwv RRb)) = some (.cnode 13 (rootCsA 1))) + {y : Except Unit Unit × State Unit} + (hy : y ∈ ((resetUntypedCap (Z := Unit) (w1RrSlotA 53)).run τ).1) : y = (.ok (), τ) := by + have hg : getCap (Z := Unit) (w1RrSlotA 53) τ = ({(.untypedCap false (specPtr (bwv UTb)) 20 0, τ)}, False) := + getCap_rootU hk rootCs_53 + unfold resetUntypedCap at hy + rw [run_bind_okA (run_liftEA hg)] at hy + simp only [NonDetE.returnOk, ndE_pure_bindA] at hy + rw [if_pos (by simp [freeIndexOf])] at hy + exact Set.mem_singleton_iff.1 hy + +/-- The A64 invocation of a non-VCPU retype has the outcomes of `fl4InvokeUntyped`. -/ +theorem invA64_memU {srcSlot : CslotPtr} {reset : Bool} {base rb : Word} {t : ApiObjectType} {sz : Nat} + {slots : List CslotPtr} {dev : Bool} (ht : t ≠ .archObject .vcpuObj) {σ : State Unit} + {y : Except Unit Unit × State Unit} + (h : y ∈ ((fl4InvokeUntypedA64 (Z := Unit) (.retype srcSlot reset base rb t sz slots dev)).run σ).1) : + y ∈ ((fl4InvokeUntyped (Z := Unit) (.retype srcSlot reset base rb t sz slots dev)).run σ).1 := by + unfold fl4InvokeUntypedA64 at h + rw [ExceptT.run_bind] at h + obtain ⟨⟨e, σx⟩, hx, hy⟩ := mem_bindA.1 h + cases e with + | error u => rw [(mem_pureA hy)]; exact hx + | ok u => + have hyA : y ∈ ((NonDetE.liftE (ε := Unit) (NonDet.when (t = .archObject .vcpuObj) (NonDet.mapMx + (fun v => do let vcpu ← getVcpu v; setVcpu v (fl4VcpuInit vcpu)) + (fl4RetypeAddrs fl4ObjBitsApi rb slots.length sz t)))).run σx).1 := hy + rw [liftE_runD] at hyA + obtain ⟨⟨a, σz⟩, hz, hyB⟩ := mem_bindA.1 hyA + rw [NonDet.when, if_neg ht] at hz + have e1 := (Prod.mk.inj (mem_pureA hz)).2 + have e2 := mem_pureA hyB + have e3 : y = (.ok (), σx) := by rw [e2, e1] + cases u + rw [e3] + exact hx + +theorem addrs_UT : fl4RetypeAddrs fl4ObjBitsApi (specPtr (bwv UTb)) 1 0 .endpointObject = [specPtr (bwv UTb)] := by + simp [fl4RetypeAddrs, ptrAdd] + +/-- **Every outcome of the witness's Retype succeeds and creates no `runningVM` thread.** -/ +theorem invokeUt_all {σ : State Unit} + (hS : σ.kheap (specPtr (bwv RRb)) = some (.cnode 13 (rootCsA 1))) + (hfree : σ.kheap (specPtr (bwv UTb)) = none) + (hne : specPtr (bwv RRb) ≠ specPtr (bwv UTb)) + {y : Except Unit Unit × State Unit} + (h : y ∈ ((fl4InvokeUntypedA64 (Z := Unit) (.retype (w1RrSlotA 53) true (specPtr (bwv UTb)) + (specPtr (bwv UTb)) .endpointObject 0 [(specPtr (bwv RRb), natToCref 13 1000)] false)).run σ).1) : + y.1 = .ok () ∧ VmKA σ y.2 := by + have h1 := invA64_memU (by decide) h + rw [utInvoke_eqA] at h1 + rw [ExceptT.run_bind] at h1 + obtain ⟨⟨e, σr⟩, hr, h2⟩ := mem_bindA.1 h1 + have hr' : (e, σr) ∈ ((resetUntypedCap (Z := Unit) (w1RrSlotA 53)).run σ).1 := by + simpa [NonDetE.whenE] using hr + obtain ⟨he, hσ⟩ := Prod.mk.inj (reset_noopU hS hr') + subst he + subst hσ + have h2' : y ∈ ((NonDetE.liftE (ε := Unit) (utRtBodyA (w1RrSlotA 53) (specPtr (bwv UTb)) + (specPtr (bwv UTb)) .endpointObject 0 [(specPtr (bwv RRb), natToCref 13 1000)] false)).run σr).1 := h2 + rw [liftE_runD] at h2' + obtain ⟨⟨a, σz⟩, hz, hyB⟩ := mem_bindA.1 h2' + have e2 := mem_pureA hyB + subst e2 + cases a + refine ⟨rfl, ?_⟩ + have N := utRtBody_newObjA hz hS (capS := .untypedCap false (specPtr (bwv UTb)) 20 0) + (by simpa [w1RrSlotA] using rootCs_53) + (by rw [List.length_singleton, addrs_UT]; simpa [w1RrSlotA] using hne) + (fun d hd => by + simp at hd + subst hd + exact ⟨⟨13, rootCsA 1, hS⟩, by simp [List.length_singleton, addrs_UT]; exact hne⟩) + (fun q hq _ => by + rw [List.length_singleton, addrs_UT] at hq + simp at hq + subst hq + exact hfree) + intro p y hy v + rcases N.back p (.tcb y) hy (fun _ _ e => by cases e) with g | ⟨-, g⟩ + · exact ⟨y, g, v⟩ + · cases g + +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA WClock ar1_total ar1_plat) in +set_option maxHeartbeats 4000000 in +/-- **Every outcome of the witness's Retype invocation succeeds and creates no `runningVM` thread.** -/ +theorem wit_invoke_okVmU {r mt sl : U64} {uw : U64 → U64} (O : OpaqueWA) (OU : OpaqueUtWA) (U : UtUw uw) + {Z : XSetsA} {ab : WA} {τ : Fl4SpecA64.State Unit} + (hZ : Z.th = w1ThA KB IB 1) (hcdt : τ.cdt = w1CdtA) (hkh : τ.kheap = (witSAu wNow mt sl uw).kheap) + (Jr : WitJ Z WitMsg.retype r wNow mt sl uw (witSu r wNow mt sl uw) ab τ) + (rep calling blocking donate : Bool) {x : Tcb} + (hk : τ.kheap (specPtr (bL.curW (witSu r wNow mt sl uw))) = some (.tcb x)) : + ∀ y, y ∈ ((fl4HandleInvocationR (Z := Unit) rep calling blocking donate false + (toBl (bL.mem (witSu r wNow mt sl uw) (regWA (bL.curW (witSu r wNow mt sl uw)) layout.reg.CAP)).bv)).run τ).1 → + y.1 = .ok () ∧ VmKA τ y.2 := by + intro y hy + have cp : bL.mem (witSu r wNow mt sl uw) (regWA (bL.curW (witSu r wNow mt sl uw)) layout.reg.CAP) = 53#u64 := by + rw [curW2]; exact wit_capWordU + have einfo : msg.msg_info bst (witSu r wNow mt sl uw) (bL.curW (witSu r wNow mt sl uw)) = + ok { label := 1#u64, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := 6#u64 } := by + rw [curW2]; exact wit_msgInfoU + have ebuf : msg.lookup_ipc_buffer bst (witSu r wNow mt sl uw) false (bL.curW (witSu r wNow mt sl uw)) = + ok (bwv IPb) := by rw [curW2]; exact wit_ipcBuffer (c0 := WitMsg.retype) + have elr : cspace.lookup_slot bst (witSu r wNow mt sl uw) (bL.curW (witSu r wNow mt sl uw)) 53#u64 = + ok (.Ok { slot := bwv (RRb + 32 * 53), bits_left := 0#u64 }) := by + rw [curW2]; exact wit_slotU + have eex : ipc.lookup_extra_caps bst (witSu r wNow mt sl uw) (bL.curW (witSu r wNow mt sl uw)) (bwv IPb) + { label := 1#u64, caps_unwrapped := 0#u64, extra_caps := 1#u64, length := 6#u64 } = ok (.Ok witExtra) := by + rw [curW2]; exact wit_extraCapsU U + obtain ⟨mi, sl', c, excaps, buffer, argsU, Q⟩ := Jr.siteA einfo ebuf elr eex + have F := Q.F + have ct : τ.curThread = specPtr (bL.curW (witSu r wNow mt sl uw)) := Jr.j.1.sch.curThread + have hP := Q.place + have hsl' : sl' = w1RrSlotA 53 := + (cslotAddrA_inj hP (by rw [hZ]; exact w1RrSlotA_abs 53) F.pin.habs + ((cslotAddr_rrA layA layK lay1 (j := 53) (by norm_num)).trans F.pin.hslot)).symm + subst hsl' + have hargs := wit_argsUeq U F.len F.args + have hc : c = .untypedCap false (specPtr (bwv UTb)) 20 0 := by + have h := F.cap.2 + rw [wit_capU] at h + exact h.symm + obtain ⟨y0, hy0, hya, hy1⟩ := wit_excapsU hP F.extra + subst hargs hy0 hc + have hrr : specPtr (bwv RRb) ≠ specPtr (bwv RTb) := fun h => by + have := congrArg UScalar.val (specPtr_inj h) + rw [vRR, vRT] at this + revert this + norm_num + have hk' : τ.kheap (specPtr (bwv RRb)) = some (.cnode 13 (rootCsA 1)) := by + rw [hkh] + exact (Function.update_of_ne hrr _ _).trans w1KA_rr + have hlbl : genInvocationType (specLabelWord (fl4LabelOf mi.miLabel)) = .untypedRetype ↔ + witInfoU.label = fl4_abi.label.UntypedRetype := by + rw [F.lab]; exact ut_labelA _ + have hlbl' := hlbl.2 (by simp [witInfoU, fl4_abi.label.UntypedRetype]) + obtain ⟨inv, hd, hinv⟩ := wit_decS OU hlbl' hk' hcdt (cap := .untypedCap false (specPtr (bwv UTb)) 20 0) rfl + (rc := y0.1) hy1 + -- the spec's front lookups and decode, one outcome each + have htZ : bL.curW (witSu r wNow mt sl uw) ∈ Z.T := Jr.sr.curT + have hth : Z.th (bL.curW (witSu r wNow mt sl uw)) = some .tcb := (Jr.j.1.thT _).2 htZ + obtain ⟨lr, elr', se, hse, hrel⟩ := spec_existsA + (lookup_slot_refinesA Z.th (witSu r wNow mt sl uw) τ Jr.j.1.st Jr.j.1.cv _ hth 53#u64) + obtain rfl := ok_inj_ff (elr'.symm.trans elr) + cases se with + | error _ => exact hrel.1.elim + | ok v => + obtain ⟨sl2, rest⟩ := v + obtain ⟨⟨hsl, -⟩, q, hq1, hq, -⟩ := hrel + have esl : sl2 = w1RrSlotA 53 := cslotAddrA_inj Q.place ⟨q, hq1, Or.inl hq⟩ F.pin.habs (hsl.symm.trans F.pin.hslot) + subst esl + have lcs := lcs_okA (ofBl (toBl (53#u64 : U64).bv)) hse F.pin.hcap + have front : (frontSpecA τ.curThread (toBl (53#u64 : U64).bv) mi).run τ = + ({(.ok (w1RrSlotA 53, .untypedCap false (specPtr (bwv UTb)) 20 0, [y0], buffer), τ)}, False) := by + rw [ct] + have eb := F.pin.hbuf + have ex := F.pin.hex + rw [ct] at eb ex + unfold frontSpecA + rw [run_bind_okA lcs] + dsimp only + rw [run_bind_okA (run_liftEA eb), run_bind_okA ex] + rfl + have dec : (decSpecA calling τ.curThread (toBl (53#u64 : U64).bv) mi + (w1RrSlotA 53, .untypedCap false (specPtr (bwv UTb)) 20 0, [y0], buffer)).run τ = + ({(.ok (.invokeUntyped inv), τ)}, False) := by + unfold decSpecA + dsimp only + rw [run_bind_okA (run_liftEA F.pin.hargs)] + exact run_liftME_okA hd + have gc : (NonDet.gets fun s : Fl4SpecA64.State Unit => s.curThread) τ = ({(τ.curThread, τ)}, False) := rfl + rw [cp] at hy + rw [fl4HandleInvocationR_piecesA, run_bind_okA (run_liftEA gc)] at hy + unfold withoutPreemption at hy + rw [run_bind_okA (run_liftEA F.pin.hmi), syscall_okA front dec] at hy + have hk0 : τ.kheap τ.curThread = some (.tcb x) := by rw [ct]; exact hk + unfold finSpecA withoutPreemption at hy + rw [run_lift_bindA (setThreadState_stsActExA hk0 .restart)] at hy + have hmem : ((), stsActA (updKSc τ τ.curThread (.tcb { x with tcbState := .restart })) τ.curThread) ∈ + (setThreadState (Z := Unit) τ.curThread .restart τ).1 := by + rw [setThreadState_stsActExA hk0 .restart]; exact Set.mem_singleton _ + have kσ1 := (VPresInst.pres (m := setThreadState (Z := Unit) τ.curThread .restart)) τ _ hmem + have khs : ∀ q, q ≠ τ.curThread → + (stsActA (updKSc τ τ.curThread (.tcb { x with tcbState := .restart })) τ.curThread).kheap q = τ.kheap q := by + intro q hq + have e1 : ∀ σ' : State Unit, (stsActA σ' τ.curThread).kheap = σ'.kheap := fun σ' => by + unfold stsActA; split <;> rfl + rw [e1] + unfold updKSc + exact Function.update_of_ne hq _ _ + have hct : τ.curThread = specPtr (bwv RTb) := by rw [ct]; rw [curW2] + have hrr' : specPtr (bwv RRb) ≠ τ.curThread := by rw [hct]; exact hrr + have hut' : specPtr (bwv UTb) ≠ τ.curThread := fun h => by + rw [hct] at h + have := congrArg UScalar.val (specPtr_inj h) + rw [bwv_val (n := UTb) (by norm_num), vRT] at this + revert this + norm_num + have hfree0 : τ.kheap (specPtr (bwv UTb)) = none := + Jr.toJStage3A.specFree.heap (bwv UTb) ⟨_, Q.hOS, bwv UTb, 20#u64, 0#u64, false, wit_capU, trivial, + by simp, by simp⟩ + have hS1 := (khs _ hrr').trans hk' + have hfree1 := (khs _ hut').trans hfree0 + have hne : specPtr (bwv RRb) ≠ specPtr (bwv UTb) := fun h => by + have := congrArg UScalar.val (specPtr_inj h) + rw [vRR, bwv_val (n := UTb) (by norm_num)] at this + revert this + norm_num + subst hinv + rw [ExceptT.run_bind] at hy + obtain ⟨⟨e1, σ2⟩, h1, hy2⟩ := mem_bindA.1 hy + have h1' : (e1, σ2) ∈ (ExceptT.run (fl4InvokeUntypedA64 (Z := Unit) (.retype (w1RrSlotA 53) true + (specPtr (bwv UTb)) (specPtr (bwv UTb)) .endpointObject 0 [(specPtr (bwv RRb), natToCref 13 1000)] false) >>= + fun _ => NonDetE.returnOk ([] : List Data)) _).1 := h1 + rw [ExceptT.run_bind] at h1' + obtain ⟨⟨e0, σ3⟩, h0, h1b⟩ := mem_bindA.1 h1' + obtain ⟨he0, k3⟩ := invokeUt_all hS1 hfree1 hne h0 + have he0' : e0 = .ok () := he0 + subst he0' + have e12 := mem_pureA h1b + obtain ⟨he1, hσ2⟩ := Prod.mk.inj e12 + subst he1 hσ2 + have hy3 : y ∈ ((NonDetE.liftE (ε := Unit) (epiSpecA calling τ.curThread [])).run σ2).1 := hy2 + obtain ⟨⟨a, e, -⟩, k4⟩ := (OkVmA.lift (ε := Unit) (VPresInst.pres (m := epiSpecA calling τ.curThread []))) σ2 y hy3 + cases a + exact ⟨e, PreO.trans kσ1 (PreO.trans k3 k4)⟩ + +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA WClock ar1_total ar1_plat) in +set_option maxHeartbeats 4000000 in +/-- **No thread runs a guest after any outcome of the witness's `Send` / `NBSend` / `Call`.** -/ +theorem wit_bodyNoVmU (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (OU : OpaqueUtWA) (U : UtUw uw) + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) + (ha : WClock a (witSAu wNow mt sl uw).machineState) (number : I64) (rep : Bool) (call : Syscall) + (hc : call = .sysSend ∨ call = .sysNBSend ∨ call = .sysCall) {τf : Fl4SpecA64.State Unit} + (h : ((), τf) ∈ (kOpA (.syscall number rep call) (witSAu wNow mt sl uw)).1) : NoVmA τf := by + -- the post-budget record + have I := wit_entryIn O (c0 := WitMsg.retype) (r := r) (mt := mt) (uw := uw) hsl hr a ha + obtain ⟨a1, hb, -⟩ := wit_budget_id O (c0 := WitMsg.retype) 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 = witSu 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) (witSAu wNow mt sl uw) = ({(true, τ)}, False) := by + rw [hb1] at e1; exact e1 + -- the spec prefix + have hcdt : τ.cdt = w1CdtA := (wit_tauU O hsl wit_pc e1').1 + have hkh : τ.kheap = (witSAu wNow mt sl uw).kheap := (wit_tauU O hsl wit_pc e1').2 + have nvτ : NoVmA τ := wit_noVmC.of_vm (budgetOk_vm (by rw [e1']; exact Set.mem_singleton _)) + have htZ : bL.curW (witSu r wNow mt sl uw) ∈ witZA.T := Jr.sr.curT + obtain ⟨x, hk, -⟩ := Jr.ep.tcb _ htZ + have ct : τ.curThread = specPtr (bL.curW (witSu r wNow mt sl uw)) := Jr.j.1.sch.curThread + have reg : x.tcbArch.tcbContext.userRegs cap_register = + (bL.mem (witSu r wNow mt sl uw) (regWA (bL.curW (witSu r wNow mt sl uw)) layout.reg.CAP)).bv := by + have e : Endp.regA (bL.curW (witSu r wNow mt sl uw)) (regIdxA cap_register) = + regWA (bL.curW (witSu r wNow mt sl uw)) layout.reg.CAP := by + unfold Endp.regA regWA + rw [UScalar.eq_of_val_eq (show (regIdxA cap_register).val = layout.reg.CAP.val by + simp [cap_register, capRegister, regIdxA, layout.reg.CAP, layout.reg.X0])] + rw [← e] + exact ((Jr.ep.at_tcb htZ hk).regs cap_register).symm + have capRead : getCapReg (Z := Unit) cap_register τ = ({(toBl + (bL.mem (witSu r wNow mt sl uw) (regWA (bL.curW (witSu r wNow mt sl uw)) layout.reg.CAP)).bv, τ)}, False) := by + unfold getCapReg NonDet.liftM + rw [nd_gets_bindSc, ct, nd_bind_singleA' (asUser_getRegister_eqA hk _), reg] + rfl + have inv : ∀ calling blocking donate y, + y ∈ ((NonDetE.liftE (getCapReg (Z := Unit) cap_register) >>= fun cptr => + fl4HandleInvocationR (Z := Unit) rep calling blocking donate false cptr).run τ).1 → + y.1 = .ok () ∧ VmKA τ y.2 := fun calling blocking donate y hy => by + rw [run_bind_okA (run_liftEA capRead)] at hy + exact wit_invoke_okVmU O OU U rfl hcdt hkh Jr rep calling blocking donate hk y hy + have body : ∀ y, y ∈ ((fl4HandleEvent (Z := Unit) rep (.syscallEvent call)).run (witSAu 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 <;> simp only [fl4HandleSyscallWith] at hy <;> exact inv _ _ _ y hy + unfold kOpA at h + dsimp only at h + rw [nd_gets_bindSc, nd_bind_oneSc wit_pc] 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 + +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA WClock ar1_total ar1_plat) in +/-- **`hNat` of `kernelEntry_recGA` / `kernelEntrySend_recGA` at the witness** (module docstring). -/ +theorem wit2b_hNatU (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (OU : OpaqueUtWA) (U : UtUw uw) + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) + (ha : WClock a (witSAu wNow mt sl uw).machineState) (number : I64) (rep : Bool) (call : Syscall) + (hc : call = .sysSend ∨ call = .sysNBSend ∨ call = .sysCall) {view : Fl4SpecA64.State Unit → Fl4TimerView} : + ∀ s' a' τ, kBodyA bst AR1 (witSu r wNow mt sl uw) a (.syscall number rep call) = ok (s', a') → + ((), τ) ∈ (kOpA (.syscall number rep call) (witSAu wNow mt sl uw)).1 → + A64RelS3 bst (fun _ _ => True) AR1 Wit2.ar1_plat.ipa Fl4SpecA64.fl4A64Platform.numNodes witZA.Cs s' a' τ + (w1MA IB 1) → ∀ τ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 := + hNat_of_noVmA fun _ _ _ _ op _ => wit_bodyNoVmU O OU U hsl hr a ha number rep call hc op + + +section +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA WClock ar1_total ar1_plat) + +theorem wit_frameMasksU {r now mt sl : U64} {uw : U64 → U64} : A64FrameMasks bst (witSu r now mt sl uw) := rfl + +/-- The record at the Untyped witness's entry state (any arch state). -/ +theorem wit_JU (O : OpaqueWA) {r mt sl : U64} {uw : U64 → U64} (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) + (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) : + WitJ witZA WitMsg.retype r wNow mt sl uw (witSu r wNow mt sl uw) a (witSAu wNow mt sl uw) := by + rw [WitJ, 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 + +/-- **The Untyped Retype decode returns `Ok`** at the witness (from the arm, at the entry record). -/ +theorem wit_decodeOkU (O : OpaqueWA) (OU : OpaqueUtWA) {r mt sl : U64} {uw : U64 → U64} (U : UtUw uw) + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) + (blk call don : Bool) : + ∃ s' a', syscall.decode_invocation bst AR1 (witSu r wNow mt sl uw) a 1#u64 6#u64 (bwv (RRb + 32 * 53)) + (.Untyped (bwv UTb) 20#u64 0#u64 false) blk call don false (bwv IPb) witExtra = ok (.Ok (), s', a') := by + have J0 := wit_JU (mt := mt) (uw := uw) O hsl hr a + have einfo : msg.msg_info bst (witSu r wNow mt sl uw) (bL.curW (witSu r wNow mt sl uw)) = ok witInfoU := by + rw [curW2]; exact wit_msgInfoU + have ebuf : msg.lookup_ipc_buffer bst (witSu r wNow mt sl uw) false (bL.curW (witSu r wNow mt sl uw)) = + ok (bwv IPb) := by rw [curW2]; exact wit_ipcBuffer (c0 := WitMsg.retype) + have elr : cspace.lookup_slot bst (witSu r wNow mt sl uw) (bL.curW (witSu r wNow mt sl uw)) + (bL.mem (witSu r wNow mt sl uw) (regWA (bL.curW (witSu r wNow mt sl uw)) layout.reg.CAP)) = + ok (.Ok { slot := bwv (RRb + 32 * 53), bits_left := 0#u64 }) := by + rw [curW2, wit_capWordU]; exact wit_slotU + have eex : ipc.lookup_extra_caps bst (witSu r wNow mt sl uw) (bL.curW (witSu r wNow mt sl uw)) (bwv IPb) + witInfoU = ok (.Ok witExtra) := by + rw [curW2]; exact wit_extraCapsU U + obtain ⟨mi, sl', c, excaps, buffer, argsU, Q⟩ := J0.siteA einfo ebuf elr eex + obtain ⟨Out, S⟩ := wit_utScopeU (Z := witZA) O OU U rfl rfl rfl rfl einfo ebuf elr eex Q a blk call don + obtain ⟨s', a', σ', hdec, -⟩ := UtScopeA.soundOk Wit2.ar1_total Wit2.ar1_plat J0 wit_frameMasksU S + refine ⟨s', a', ?_⟩ + have hl : msgLenA witInfoU (bwv IPb) = 6#u64 := wit_msgLenU + rw [hl, wit_capU] at hdec + exact hdec + +theorem wit_notPreemptedU (O : OpaqueWA) (OU : OpaqueUtWA) {r mt sl : U64} {uw : U64 → U64} (U : UtUw uw) + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) + {a : WA} {call blk don : Bool} {x : error.Exc} {s' : BS} {a' : WA} + (h : syscall.handle_invocation bst AR1 (witSu r wNow mt sl uw) a call blk don false + (bL.mem (witSu r wNow mt sl uw) (regWA (bL.curW (witSu r wNow mt sl uw)) layout.reg.CAP)) = + ok (.Err x, s', a')) : False := by + obtain ⟨s3, a3, d⟩ := wit_decodeOkU O OU U hsl hr a blk call don + have ct : sched.cur_thread bst (witSu r wNow mt sl uw) = ok (bwv RTb) := by rw [cur_thread_ok, curW2] + have n : msg.N_MSG_REGISTERS = 4#u64 := by simp [msg.N_MSG_REGISTERS] + have ne : (bwv IPb) ≠ 0#u64 := fun e => by + have := congrArg UScalar.val e + rw [vIP] at this + simp at this + have c : obj.Slot.cap bst (bwv (RRb + 32 * 53)) (witSu r wNow mt sl uw) = ok (.Untyped (bwv UTb) 20#u64 0#u64 false) := by + rw [capA_eq, wit_capU] + rw [curW2, wit_capWordU] at h + unfold syscall.handle_invocation at h + rw [ct, bind_ok, wit_msgInfoU, bind_ok, wit_slotU, bind_ok] at h + try simp only at h + rw [c, bind_ok, wit_ipcBuffer (c0 := WitMsg.retype), bind_ok, wit_extraCapsU U, bind_ok] at h + try simp only at h + rw [n, if_pos (by scalar_tac), if_neg ne, bind_ok, d, bind_ok] at h + try simp only at h + obtain ⟨i, -, h⟩ := bind_eq_ok h + split at h + · obtain ⟨s2, -, h⟩ := bind_eq_ok h + obtain ⟨s4, -, h⟩ := bind_eq_ok h + have := ok_inj_ff h + cases this + · have := ok_inj_ff h + cases this + + +theorem wit_noDecodeErrU (O : OpaqueWA) (OU : OpaqueUtWA) {r mt sl : U64} {uw : U64 → U64} (U : UtUw uw) + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) + {blk call don : Bool} {info : msginfo.MessageInfo} {buf : U64} {r1 : cspace.Resolved} + {e : Aeneas.Std.Array obj.Slot 3#usize} {x : error.Exc} {s' : BS} {a' : WA} + (h1 : msg.msg_info bst (witSu r wNow mt sl uw) (bL.curW (witSu r wNow mt sl uw)) = ok info) + (h2 : msg.lookup_ipc_buffer bst (witSu r wNow mt sl uw) false (bL.curW (witSu r wNow mt sl uw)) = ok buf) + (h3 : cspace.lookup_slot bst (witSu r wNow mt sl uw) (bL.curW (witSu r wNow mt sl uw)) + (bL.mem (witSu r wNow mt sl uw) (regWA (bL.curW (witSu r wNow mt sl uw)) layout.reg.CAP)) = ok (.Ok r1)) + (h4 : ipc.lookup_extra_caps bst (witSu r wNow mt sl uw) (bL.curW (witSu r wNow mt sl uw)) buf info = ok (.Ok e)) + (h : syscall.decode_invocation bst AR1 (witSu r wNow mt sl uw) a info.label (msgLenA info buf) r1.slot + (capA bst (witSu r wNow mt sl uw) r1.slot) blk call don false buf e = ok (.Err x, s', a')) : False := by + obtain ⟨rfl, rfl, rfl, rfl⟩ := wit_prefixU U h1 h2 h3 h4 + obtain ⟨s3, a3, d⟩ := wit_decodeOkU O OU U hsl hr a blk call don + rw [wit_msgLenU, wit_capU] at h + have := ok_inj_ff (d.symm.trans h) + cases this + +set_option maxHeartbeats 4000000 in +/-- **`SendScopeA` at the Untyped witness.** -/ +theorem wit_scopeU (O : OpaqueWA) (OU : OpaqueUtWA) (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) + {r mt sl : U64} {uw : U64 → U64} (U : UtUw uw) (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) + (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (rep : Bool) + (call : Fl4SpecA64.Syscall) {Q : U64 → U64 → List U64} {Rl : U64 → List U64} {ab : WA} + {τ : Fl4SpecA64.State Unit} + (hτc : τ.cdt = w1CdtA) (hτk : τ.kheap = (witSAu wNow mt sl uw).kheap) + (Jr : WitJ { witZA with Q := Q, R := Rl } WitMsg.retype r wNow mt sl uw (witSu 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 + (witSu r wNow mt sl uw) ab τ (w1MA IB 1) WClock Wit2.ar1_plat rep (Fl4SpecA64.maybeHandleInterrupt true) call := by + refine { hFault := ?_, hArm := ?_, hErr := ?_, HEnv := ?_ } + · intro calling blocking donate _ _ f f' _ + obtain ⟨σ2, s2, hm, hf, B, Q2, R2, J2⟩ := Jr.faultNullA Wit2.ar1_total Wit2.ar1_plat (wit_hCs O) O.nodes f f' + wit_faultCap (wit_faultHandler_null Jr) + rw [hf] + exact (WP.spec_ok _).2 ⟨σ2, hm, A64RelS3.ofJ J2 B.1⟩ + · intro calling blocking donate _ info buf r1 e mi sl' c excaps buffer argsU einfo ebuf elr eex Q' r0 s0 a0 _ _ + obtain ⟨Out, S⟩ := wit_utScopeU (Z := { witZA with Q := Q, R := Rl }) O OU U rfl rfl hτc hτk einfo ebuf elr eex Q' ab + calling blocking donate + exact DispScopeA.of4 ⟨Out, Or.inr (Or.inr (Or.inl (Or.inl S)))⟩ + · intro calling blocking donate _ info buf r1 e x s' a' h1 h2 h3 h4 hdec _ + exact (wit_noDecodeErrU O OU U hsl hr _ h1 h2 h3 h4 hdec).elim + · refine + { 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_notPreemptedU O OU U hsl hr hh).elim + 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 + exact absurd (congrArg Prod.fst (ok_inj_ff ht)).symm hne + +set_option maxHeartbeats 4000000 in +/-- **`kernelEntrySend_recGA` at the Untyped witness**: the premises and the conclusion at one state. -/ +theorem wit_top_ut (O : OpaqueWA) (OU : OpaqueUtWA) (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) + {r mt sl : U64} {uw : U64 → U64} (U : UtUw uw) + (hsl : Fl4SpecA64.MIN_BUDGET ≤ sl.bv) (hr : specPtr r = Fl4SpecA64.armGlobalPtPtr) (a : WA) + (ha : WClock a (witSAu wNow mt sl uw).machineState) (number : I64) (rep : Bool) (call : Fl4SpecA64.Syscall) + (hnum : number = syscallNumberA call) (hc : call = .sysSend ∨ call = .sysNBSend ∨ call = .sysCall) : + ∃ Hy : SendEntryHyps 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) WClock + (witSu r wNow mt sl uw) a (witSAu wNow mt sl uw) Wit2.witTm + (gapViewA bst AR1 (kBodyA bst AR1 (witSu r wNow mt sl uw) a (.syscall number rep call))) number rep call, + kCodeA bst AR1 (witSu r wNow mt sl uw) a (.syscall number rep call) ⦃ out => + StepPostA (KExitA bst AR1 (fun _ _ => True) Wit2.ar1_plat.ipa (w1MA IB 1)) + (kOpA (.syscall number rep call) >>= fun _ => fl4Finish kLimitA + (gapViewA bst AR1 (kBodyA bst AR1 (witSu r wNow mt sl uw) a (.syscall number rep call)))) + (witSAu wNow mt sl uw) out ⦄ := by + let Hy : SendEntryHyps 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) WClock + (witSu r wNow mt sl uw) a (witSAu wNow mt sl uw) Wit2.witTm + (gapViewA bst AR1 (kBodyA bst AR1 (witSu r wNow mt sl uw) a (.syscall number rep call))) number rep call := + { plain := ⟨fun _ => rfl⟩ + hA := Wit2.ar1_total + hM := Wit2.ar1_spi + hPl := Wit2.ar1_plat + hIP := ⟨fun _ => (WP.spec_ok _).2 rfl⟩ + 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_kRuns 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 pc eb b Jr _ => by + obtain ⟨a1, hb, -⟩ := wit_budget_id O hsl hr a ha + rw [wit_faultIP_id, hb] at eb + have e := ok_inj_ff eb + have hsb : sb = witSu r wNow mt sl uw := (congrArg (fun p => p.2.1) e).symm + subst hsb + have hτ := wit_tauU O hsl pc b + exact wit_scopeU O OU hI U hsl hr rep call hτ.1 hτ.2 Jr + hGap := Wit2.wit2b_hGapA O Wit2.witArchSwOf (wit_hCs O) _ a _ (.syscall number rep call) + hNat := wit2b_hNatU O OU U hsl hr a ha number rep call hc } + exact ⟨Hy, Hy.concl⟩ + +/-- **Non-vacuity of `kernelEntrySend_recGA` on an Untyped Retype**: with `OpaqueWA` and `OpaqueUtWA` the only hypotheses, +every witness-side parameter is existential and instantiated by a concrete value (the entry's message is `UntypedRetype` +of an Endpoint into the root CNode). -/ +theorem wit_ut_nonvacuous (O : OpaqueWA) (OU : OpaqueUtWA) + (hI : ∀ n, Fl4SpecA64.irqOracle n = Fl4SpecA64.irqVGICMaintenance) : + ∃ (r mt sl : U64) (uw : U64 → U64) (a : WA) (number : I64) (rep : Bool) (call : Syscall), + Nonempty (SendEntryHyps 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) + WClock (witSu r wNow mt sl uw) a (witSAu wNow mt sl uw) Wit2.witTm + (gapViewA bst AR1 (kBodyA bst AR1 (witSu r wNow mt sl uw) a (.syscall number rep call))) + number rep call) := by + obtain ⟨r, hr⟩ := wit_r_ex + obtain ⟨uw, U⟩ := utUw_ex + obtain ⟨Hy, -⟩ := wit_top_ut O OU hI (r := r) (mt := 0#u64) (sl := ⟨Fl4SpecA64.MIN_BUDGET⟩) (uw := uw) U + (BitVec.le_refl _) hr (witA0 (witSAu 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⟩⟩ + +end + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitVsArchA.lean b/proofs/Fl4ProofsA64/P3/A64WitVsArchA.lean new file mode 100644 index 000000000..4c0e0034a --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitVsArchA.lean @@ -0,0 +1,30 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line witvs, spike S3.0): **the model arch serves the VS arms unchanged.** + +The arms `frameMapS2`, `ptMapHi`, `ptMapS2`, `ptUnmapT2` ask the arch for `ArchKeepsA` and `S2IpaE`; both hold at +the witness world's `AR1` (`P3/A64Wit2ArchA`) with the trivial arch relation. None of the four arms mentions +`fl4A64Virt` or `Arch::virtualization` (only `untyped::decode` and the Retype arms do), so a VS top needs neither +value of `fl4A64Virt`: no `OpaqueVsWA` and no second arch, and no clash with witSu's `OpaqueUtWA` +(`fl4A64Virt = false`). A clash would arise only if the VS objects were *created* by Retype (types 12 / 13 need +`fl4A64Virt = true`); `w1v` builds them in the initial state. + +Named premises: `OpaqueWA` [P] (`ipaBits`). New module; no existing statement changed. +-/ +import Fl4ProofsA64.P3.A64Wit2ArchA +import Fl4ProofsA64.P3.VsMapJA +import Fl4ProofsA64.P3.ExtVsTopA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3.Wit +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P3 +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA) + +theorem wit_archKeeps : ArchKeepsA AR1 (fun (_ : WA) (_ : HwRootA) => True) := + ⟨fun _ _ _ _ _ => (WP.spec_ok _).2 trivial, fun _ _ _ _ => (WP.spec_ok _).2 trivial, + fun _ _ _ _ _ _ _ _ _ => (WP.spec_ok _).2 trivial, fun _ _ _ _ _ => (WP.spec_ok _).2 trivial, + fun _ _ _ _ => (WP.spec_ok _).2 trivial, fun _ _ _ _ => (WP.spec_ok _).2 trivial, + fun _ _ _ _ => (WP.spec_ok _).2 trivial, fun _ => rfl⟩ + +theorem wit_s2Ipa (O : OpaqueWA) (a : WA) : S2IpaE AR1 a := ⟨40#u64, rfl, by rw [O.ipaBits]; rfl⟩ + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitVsArmsA.lean b/proofs/Fl4ProofsA64/P3/A64WitVsArmsA.lean new file mode 100644 index 000000000..721484fd3 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitVsArmsA.lean @@ -0,0 +1,289 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line witvs): **the four VS arms' premises, jointly, per arm** (`VsScopeA.ptMapHi`, +`ptMapS2`, `frameMapS2`, `ptUnmapT2`), at the state `w1vR` (`P3/A64WitVsPremA`) and the model arch `AR1`: +**`wit_ptMapHi_prems`**, **`wit_ptMapS2_prems`**, **`wit_frameMapS2_prems`**, **`wit_ptUnmapT2_prems`**. The arch +premises `ArchKeepsA` / `S2IpaE` are `wit_archKeeps` / `wit_s2Ipa` (`P3/A64WitVsArchA`). + +This is a **premise-level** witness. **Not shown:** +* **the whole record (`JStage3A` / `JSyscallA`) is not proved satisfiable with non-empty Stage-2 roots, high + windows or Stage-2 tables**; +* hence the record-dependent premises: `TabOffA` / `ExtTabOffA` (`hTO`, `hEO`), `DecPre` (`d`), `DecPinA` + (`hpin`) and the success of the spec decode; +* `ptUnmapT2`'s [J] premise `hUniq`. + +Hypotheses: `BootLayA`, `BootKsA`, `BootLay1` (inhabited by `layA`, `layK`, `lay1`); [P] `OpaqueWA` (`ipaBits`). +New module; no existing statement changed. +-/ +import Fl4ProofsA64.P3.A64WitVsPremA +import Fl4ProofsA64.P3.A64WitVsExtA +import Fl4ProofsA64.P3.A64WitVsArchA +import Fl4ProofsA64.P3.Stage3ArmPtMapS2A +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 +open Fl4ProofsA64.P3.Wit2 (WA AR1 OpaqueWA) + +noncomputable section +open Classical + +section arms +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} +variable (hL : BootLayA ib nc) (hK : BootKsA kb ib nc) (P : BootLay1 kb ib nc) +include hL hK P + +local notation "SR" v0 "," v1 "," v2 => w1vR kb ib nc r now mt sl uw v0 v1 v2 + +/-- The invoked slot as the spec names it: a slot of the root CNode. -/ +theorem cteV {j : Nat} (hj : j < 8192) : + AbsSlotA (w1vThA kb ib nc) (w1RrSlotA j) ∧ cslotAddrA (w1RrSlotA j) = rsV j ∧ + ∃ pc, (w1RrSlotA j).1 = specPtr pc ∧ w1vThA kb ib nc pc = some (.cnode (w1RrSlotA j).2.length) := by + have h : w1vThA kb ib nc (bwv RRn) = some (.cnode (w1RrSlotA j).2.length) := by + rw [show (w1RrSlotA j).2.length = 13 from length_bitsOfA j 13] + exact w1vTh_old hL hK P w1ThA_rr + exact ⟨⟨bwv RRn, rfl, Or.inl h⟩, cslotAddr_rrA hL hK P hj, bwv RRn, rfl, h⟩ + +/-- The extra slot `x0` of an arm: `vspace::extra` reads it. -/ +theorem extraR (s : BS) {j : Nat} (hj : j < 8192) : + vspace.extra (extraV (rsV j)) 0#usize = ok (some (rsV j)) := by + have ne : rsV j ≠ 0#u64 := fun e => by + have := congrArg UScalar.val e; rw [rsV_val hj] at this; simp at this + have ix : Aeneas.Std.Array.index_usize (extraV (rsV j)) 0#usize = ok (rsV j) := by + rfl + unfold vspace.extra + rw [if_neg (by decide), ix, bind_ok] + simp [obj.Slot.is_null, ne] + +/-- A `w1` page-table cap names one of `w1`'s three tables, so never the new Stage-2 table. -/ +theorem capOf_ne_t2 (i : Nat) (mp : Bool) (a v : U64) : capOf nc i ≠ .PageTable (bwv T2n) mp a v := by + have no : ∀ t : Nat, t = L1b ∨ t = L2b ∨ t = L3b → bwv t ≠ bwv T2n := fun t ht e => by + have := congrArg UScalar.val e + rw [vT2, bwv_val (by rcases ht with rfl | rfl | rfl <;> norm_num)] at this + omega + intro h + unfold capOf at h + by_cases h1 : i < 16 + · rw [slotC_lo h1] at h + interval_cases i <;> cases h + by_cases h2 : i < 16 + nc + · rw [slotC_sch (by omega) h2] at h + cases h + rw [slotC_hi (by omega)] at h + generalize i - (16 + nc) = k at h + by_cases h3 : k < 37 + · interval_cases k + all_goals first + | exact no L1b (Or.inl rfl) (capability.Cap.PageTable.inj h).1 + | exact no L2b (Or.inr (Or.inl rfl)) (capability.Cap.PageTable.inj h).1 + | exact no L3b (Or.inr (Or.inr rfl)) (capability.Cap.PageTable.inj h).1 + | cases h + · rw [tailC_big (by omega)] at h + cases h + +/-- **`hno`**: no other slot of `OS` holds a cap to the mapped Stage-2 table. -/ +theorem hnoR (v0 v1 v2 : U64) : ∀ y ∈ w1OS kb ib nc, y ≠ rsV (53 + nc + 2) → ∀ (mp : Bool) (a0 v0' : U64), + capA bst (SR v0, v1, v2) y ≠ .PageTable (bwv T2n) mp a0 v0' := by + intro y hy hne mp a0 v0' h + have h128 := P.w0.nc128 + rw [capR_keep P hy] at h + rcases capV_split (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P hy with e | ⟨k, hk, hx, e, -⟩ + · rw [e] at h + rcases w1OS_val P hy with ⟨t, c, i, hT, hc, et, hi, ex, -⟩ | ⟨i, hi, ex, -⟩ | ⟨i, hi, ex⟩ | ⟨j, hj, ex, -⟩ + · have : y ∈ bootOS kb ib nc := Or.inl ⟨t, hT, i, hi, ex⟩ + rw [cap_idle P this] at h + cases h + · rw [ex, cap_rt P hi] at h + split_ifs at h <;> cases h + · rw [cap_root P hi ex] at h + exact capOf_ne_t2 hL hK P i mp a0 v0' h + · have : y ∈ bootOS kb ib nc := Or.inr ⟨j, hj, ex⟩ + rw [cap_idle P this] at h + cases h + · rw [e] at h + have k2 : k ≠ 2 := fun k2 => hne (UScalar.eq_of_val_eq (by rw [rsV_val (by omega), hx, k2]; omega)) + interval_cases k + · cases h + · cases h + · exact k2 rfl + · have := (capability.Cap.PageTable.inj h).1 + have := congrArg UScalar.val this + rw [vUP, vT2] at this + omega + · cases h + +omit hL hK in +theorem upNotS2 : (bwv UPn) ∉ S2PgE w1vX w1vT2 ∧ (bwv UPn) ∉ w1vY := by + have no : ∀ t : U64, t.val ≠ UPn → bwv UPn ≠ t := fun t h e => h (by rw [← e, vUP]) + refine ⟨?_, fun h => no _ (by rw [vHW]; omega) h⟩ + rintro (h | ⟨q, hq, h | h⟩) + · exact no _ (by rw [vT2]; omega) h + · obtain rfl : q = bwv S2n := hq + exact no _ (by rw [vS2]; omega) h + · obtain rfl : q = bwv S2n := hq + exact no _ (by rw [waWin_valA (by rw [vS2]; norm_num), vS2]; omega) h + +/-- **`ptMapHi`**: its state premises and FL4's run, jointly. -/ +theorem wit_ptMapHi_prems (v1 v2 : U64) : + let s := (SR 18446743936270598144#u64, v1, v2) + let slot := rsV (53 + nc + 3) + let x0 := rsV (53 + nc + 1) + bL.mem s (stA (bL.curW s)) ≠ sched.TS_RUNNING_VM ∧ + (AbsSlotA (w1vThA kb ib nc) (w1RrSlotA (53 + nc + 3)) ∧ cslotAddrA (w1RrSlotA (53 + nc + 3)) = slot) ∧ + capAtA (bL.mem s) slot = .PageTable (bwv UPn) false 0#u64 0#u64 ∧ + UnmPtA w1Tb w1vY (w1OS kb ib nc) (w1H kb ib nc).tcbs (bL.mem s) (w1vSA kb ib nc now mt sl) (bwv UPn) ∧ + (bwv UPn) ∉ S2PgE w1vX w1vT2 ∧ (bwv UPn) ∉ w1vY ∧ + vspace.extra (extraV x0) 0#usize = ok (some x0) ∧ + capA bst s x0 = .HighVSpace (bwv HWn) true 3#u64 ∧ + msg.syscall_arg bst s (bL.curW s) 0#u64 0#u64 = ok 18446743936270598144#u64 ∧ + (slot ∈ w1OS kb ib nc ∧ SlotCov bst (w1OS kb ib nc) s slot ∧ x0 ∈ w1OS kb ib nc ∧ + SlotCov bst (w1OS kb ib nc) s x0) ∧ + ∃ s3, vspace.map_high_page_table bst s slot (bwv UPn) (.HighVSpace (bwv HWn) true 3#u64) + 18446743936270598144#u64 = ok (core.result.Result.Ok (), s3) := by + intro s slot x0 + have h128 := P.w0.nc128 + have c := cteV hL hK P (j := 53 + nc + 3) (by omega) + refine ⟨hnvmR P, ⟨c.1, c.2.1⟩, capR_new P (k := 3) (by omega), unmPtR P, (upNotS2 P).1, (upNotS2 P).2, + extraR hL hK P s (by omega), capR_new P (k := 1) (by omega), ?_, + ⟨rsV_os (by omega), slotCovR P (by omega), rsV_os (by omega), slotCovR P (by omega)⟩, ptMapHiR P⟩ + rw [curR P] + exact (argsR P 0#u64).1 + +/-- **`ptMapS2`**: its state premises, the root lookup and FL4's run, jointly. -/ +theorem wit_ptMapS2_prems (O : OpaqueWA) (a : WA) (v1 v2 : U64) : + let s := (SR 1073741824#u64, v1, v2) + let slot := rsV (53 + nc + 3) + let x0 := rsV (53 + nc + 0) + bL.mem s (stA (bL.curW s)) ≠ sched.TS_RUNNING_VM ∧ + S2IpaE AR1 a ∧ Fl4SpecA64.s2IpaLimit.toNat < 2 ^ 47 ∧ + (AbsSlotA (w1vThA kb ib nc) (w1RrSlotA (53 + nc + 3)) ∧ cslotAddrA (w1RrSlotA (53 + nc + 3)) = slot) ∧ + capAtA (bL.mem s) slot = .PageTable (bwv UPn) false 0#u64 0#u64 ∧ + UnmPtA w1Tb w1vY (w1OS kb ib nc) (w1H kb ib nc).tcbs (bL.mem s) (w1vSA kb ib nc now mt sl) (bwv UPn) ∧ + (bwv UPn) ∉ S2PgE w1vX w1vT2 ∧ (bwv UPn) ∉ w1vY ∧ + vspace.extra (extraV x0) 0#usize = ok (some x0) ∧ + capA bst s x0 = .Ept (bwv S2n) 0#u64 true 2#u64 0#u64 ∧ + ept.root bst s (.Ept (bwv S2n) 0#u64 true 2#u64 0#u64) 1#u64 = ok (core.result.Result.Ok (bwv S2n, 2#u64)) ∧ + msg.syscall_arg bst s (bL.curW s) 0#u64 0#u64 = ok 1073741824#u64 ∧ + (slot ∈ w1OS kb ib nc ∧ SlotCov bst (w1OS kb ib nc) s slot ∧ x0 ∈ w1OS kb ib nc ∧ + SlotCov bst (w1OS kb ib nc) s x0) ∧ + ∃ s3 a3, ept.map_table bst AR1 s a (bwv S2n) 2#u64 1073741824#u64 (bwv UPn) slot = + ok (core.result.Result.Ok (), s3, a3) := by + intro s slot x0 + have h128 := P.w0.nc128 + have c := cteV hL hK P (j := 53 + nc + 3) (by omega) + have lim : Fl4SpecA64.s2IpaLimit.toNat < 2 ^ 47 := by + unfold Fl4SpecA64.s2IpaLimit + rw [O.ipaBits] + decide + refine ⟨hnvmR P, wit_s2Ipa O a, lim, ⟨c.1, c.2.1⟩, capR_new P (k := 3) (by omega), unmPtR P, (upNotS2 P).1, + (upNotS2 P).2, extraR hL hK P s (by omega), capR_new P (k := 0) (by omega), eptRootR P, ?_, + ⟨rsV_os (by omega), slotCovR P (by omega), rsV_os (by omega), slotCovR P (by omega)⟩, + ptMapS2R P AR1 a Fl4ProofsA64.P3.Wit2.ar1_total rfl⟩ + rw [curR P] + exact (argsR P 0#u64).1 + +/-- **`frameMapS2`**: its state and message premises, the root lookup and FL4's run, jointly. -/ +theorem wit_frameMapS2_prems (O : OpaqueWA) (a : WA) (attr : U64) : + let s := (SR 2097152#u64, 3#u64, attr) + let slot := rsV (53 + nc + 4) + let x0 := rsV (53 + nc + 0) + bL.mem s (stA (bL.curW s)) ≠ sched.TS_RUNNING_VM ∧ + S2IpaE AR1 a ∧ + (AbsSlotA (w1vThA kb ib nc) (w1RrSlotA (53 + nc + 4)) ∧ cslotAddrA (w1RrSlotA (53 + nc + 4)) = slot ∧ + ∃ pc, (w1RrSlotA (53 + nc + 4)).1 = specPtr pc ∧ + w1vThA kb ib nc pc = some (.cnode (w1RrSlotA (53 + nc + 4)).2.length)) ∧ + capAtA (bL.mem s) slot = .Frame (bwv FRn) .Large 3#u64 false false false 0#u64 0#u64 ∧ + FrPlA .Large (bwv FRn) false 0#u64 ∧ + vspace.extra (extraV x0) 0#usize = ok (some x0) ∧ + capA bst s x0 = .Ept (bwv S2n) 0#u64 true 2#u64 0#u64 ∧ + ept.root bst s (.Ept (bwv S2n) 0#u64 true 2#u64 0#u64) 1#u64 = ok (core.result.Result.Ok (bwv S2n, 2#u64)) ∧ + (msg.syscall_arg bst s (bL.curW s) 0#u64 0#u64 = ok 2097152#u64 ∧ + msg.syscall_arg bst s (bL.curW s) 0#u64 1#u64 = ok 3#u64 ∧ + msg.syscall_arg bst s (bL.curW s) 0#u64 2#u64 = ok attr) ∧ + (∃ rr, capability.Rights.from_word 3#u64 = ok rr ∧ capability.mask_vm_rights 3#u64 rr = ok 3#u64) ∧ + (3#u64 : U64) = capability.VM_READ_WRITE ∧ + vmRightsOfA 3#u64 = Fl4SpecA64.maskVmRights (vmRightsOfA 3#u64) (Fl4SpecA64.dataToRights (3#u64 : U64).bv) ∧ + (slot ∈ w1OS kb ib nc ∧ SlotCov bst (w1OS kb ib nc) s slot ∧ x0 ∈ w1OS kb ib nc ∧ + SlotCov bst (w1OS kb ib nc) s x0) ∧ + ∃ s3 a3, ept.map_frame bst AR1 s a (bwv S2n) 2#u64 2097152#u64 3#u64 attr (bwv FRn) .Large 3#u64 false 0#u64 + 0#u64 slot = ok (core.result.Result.Ok (), s3, a3) := by + intro s slot x0 + have h128 := P.w0.nc128 + have c := cteV hL hK P (j := 53 + nc + 4) (by omega) + have fp : FrPlA .Large (bwv FRn) false 0#u64 := by + have e : (core.num.U64.wrapping_sub (bwv FRn) layout.PPTR_BASE).val = FRn - 18446603336221196288 := by + have b : (layout.PPTR_BASE : U64) = 18446603336221196288#u64 := by simp [layout.PPTR_BASE] + rw [b]; rfl + refine ⟨?_, by rw [e]; norm_num, by simp⟩ + rw [e, show (psA .Large).val = 21 from rfl] + norm_num + have mask : ∃ rr, capability.Rights.from_word 3#u64 = ok rr ∧ capability.mask_vm_rights 3#u64 rr = ok 3#u64 := by + refine ⟨⟨true, true, false, false⟩, ?_, ?_⟩ + · unfold capability.Rights.from_word + simp only [lift, bind_ok] + rfl + simp [capability.mask_vm_rights, capability.VM_READ_ONLY, capability.VM_READ_WRITE] + have spec : vmRightsOfA 3#u64 = + Fl4SpecA64.maskVmRights (vmRightsOfA 3#u64) (Fl4SpecA64.dataToRights (3#u64 : U64).bv) := by + have rw3 : vmRightsOfA 3#u64 = Fl4SpecA64.vmReadWrite := by + unfold vmRightsOfA; rw [if_pos (by simp)] + rw [rw3] + unfold Fl4SpecA64.maskVmRights Fl4SpecA64.validateVmRights + have hr : Fl4SpecA64.Rights.allowRead ∈ Fl4SpecA64.vmReadWrite ∩ Fl4SpecA64.dataToRights (3#u64 : U64).bv := + ⟨by simp [Fl4SpecA64.vmReadWrite], show _ = true by decide⟩ + have hw : Fl4SpecA64.Rights.allowWrite ∈ Fl4SpecA64.vmReadWrite ∩ Fl4SpecA64.dataToRights (3#u64 : U64).bv := + ⟨by simp [Fl4SpecA64.vmReadWrite], show _ = true by decide⟩ + rw [if_pos hr, if_pos hw] + have args := argsR (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (v0 := 2097152#u64) (v1 := 3#u64) + (v2 := attr) P 0#u64 + refine ⟨hnvmR P, wit_s2Ipa O a, c, capR_new P (k := 4) (by omega), fp, extraR hL hK P s (by omega), + capR_new P (k := 0) (by omega), eptRootR P, ?_, mask, by simp [capability.VM_READ_WRITE], spec, + ⟨rsV_os (by omega), slotCovR P (by omega), rsV_os (by omega), slotCovR P (by omega)⟩, + frameMapS2R P AR1 a Fl4ProofsA64.P3.Wit2.ar1_total rfl attr⟩ + rw [curR P] + exact args + +/-- **`ptUnmapT2`**: its state premises, the finality run, the spec root kind and `hno`, jointly (`hUniq` [J] is not +shown). -/ +theorem wit_ptUnmapT2_prems (O : OpaqueWA) (a : WA) (v0 v1 v2 : U64) : + let s := (SR v0, v1, v2) + let slot := rsV (53 + nc + 2) + bL.mem s (stA (bL.curW s)) ≠ sched.TS_RUNNING_VM ∧ + S2IpaE AR1 a ∧ + (AbsSlotA (w1vThA kb ib nc) (w1RrSlotA (53 + nc + 2)) ∧ cslotAddrA (w1RrSlotA (53 + nc + 2)) = slot) ∧ + (bwv T2n) ∈ w1vT2 ∧ + capA bst s slot = .PageTable (bwv T2n) true 2#u64 0#u64 ∧ + cdt.is_final_capability bst s slot = ok true ∧ + (Fl4SpecA64.asidRootKind (w1vSA kb ib nc now mt sl) (BitVec.ofNat 16 (2#u64 : U64).val) = + some Fl4SpecA64.ExtRootKind.stage2 ∧ Fl4SpecA64.ExtRootKind.stage2 ≠ .stage1) ∧ + (∀ y ∈ w1OS kb ib nc, y ≠ slot → ∀ (mp : Bool) (a0 v0' : U64), capA bst s y ≠ .PageTable (bwv T2n) mp a0 v0') ∧ + (slot ∈ w1OS kb ib nc ∧ SlotCov bst (w1OS kb ib nc) s slot) := by + intro s slot + have h128 := P.w0.nc128 + have c := cteV hL hK P (j := 53 + nc + 2) (by omega) + have kind : Fl4SpecA64.asidRootKind (w1vSA kb ib nc now mt sl) (BitVec.ofNat 16 (2#u64 : U64).val) = + some Fl4SpecA64.ExtRootKind.stage2 := by + have two : BitVec.ofNat 16 (2#u64 : U64).val = (2 : BitVec 16) := rfl + have pool : w1vPoolA (Fl4SpecA64.asidLowBitsOf 2) = some (.asidPoolVSpace (specPtr (bwv S2n))) := by + unfold w1vPoolA; rw [if_pos (by decide)] + have tab : (w1vSA kb ib nc now mt sl).archState.armAsidTable (Fl4SpecA64.asidHighBitsOf 2) = + some (specPtr (bwv PLb)) := by + show w1AsidA (Fl4SpecA64.asidHighBitsOf 2) = _ + unfold w1AsidA; rw [if_pos (by decide)] + have v : Fl4SpecA64.vspaceForAsid 2 (w1vSA kb ib nc now mt sl) = some (specPtr (bwv S2n)) := by + rw [vspaceForAsid_posA (by decide), specVsA_eqA tab w1vK_pl, pool] + rfl + have k : (w1vSA kb ib nc now mt sl).kheap (specPtr (bwv S2n)) = + some (.archObj (.ext (.stage2Root w1vEsA))) := w1vK_s2 + rw [two] + unfold Fl4SpecA64.asidRootKind + rw [v] + unfold Option.map Fl4SpecA64.rootKindAt Fl4SpecA64.extObjAt + simp only [k] + exact ⟨hnvmR P, wit_s2Ipa O a, ⟨c.1, c.2.1⟩, rfl, capR_new P (k := 2) (by omega), finalT2R P v0, + ⟨kind, fun e => by cases e⟩, hnoR hL hK P v0 v1 v2, rsV_os (by omega), slotCovR P (by omega)⟩ + +end arms + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitVsExtA.lean b/proofs/Fl4ProofsA64/P3/A64WitVsExtA.lean new file mode 100644 index 000000000..ae487141e --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitVsExtA.lean @@ -0,0 +1,212 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line witvs, step 3 part 1): **the extension records, `cv` and `pml` at `w1vS`**. + +The typed heap `w1vThA` (`w1ThA` and the new `Large` frame), the relation sets `w1vZA` (`w1ZA` with `X`, `Y`, `T2`, +`Sh2` non-empty), and at the state `w1vS` (`P3/A64WitVsStA`): + +* **`w1v_extA`**: `VcpuCoreA`, `Stage2CoreA`, `HighVSpaceCoreA` (the last two with an object and a cap each); +* **`w1v_cvA`** (`JAtZA.cv`) and **`w1v_pmlA`** (`JAtZA.pml`). + +The VCPU record's per-thread words are taken from `w1` (a TCB word is no new slot, pool word or new-block word). + +Hypotheses: `BootLayA`, `BootKsA`, `BootLay1` (as `w1`'s). New module; no existing statement changed. +-/ +import Fl4ProofsA64.P3.A64WitVsStA +import Fl4ProofsA64.P3.JEntW1A +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 Classical + +local notation "wa" => core.num.U64.wrapping_add + +/-- **The typed heap at `w1v`**: `w1`'s and the `Large` frame. -/ +def w1vThA (kb ib : U64) (nc : Nat) : TypedHeapA := fun p => + if p = bwv FRn then some (.other (2 ^ 21)) else w1ThA kb ib nc p + +/-- **The relation sets at `w1v`**: `w1`'s with the typed heap, the Stage-2 root, the window and the table. -/ +def w1vZA (kb ib : U64) (nc : Nat) : XSetsA := + { w1ZA kb ib nc with th := w1vThA kb ib nc, X := w1vX, Y := w1vY, T2 := w1vT2, Sh2 := w1vSh2 } + +section ext +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} +variable (hL : BootLayA ib nc) (hK : BootKsA kb ib nc) (P : BootLay1 kb ib nc) +include hL hK P + +local notation "S1" => w1S kb ib nc r now mt sl uw +local notation "SV" => w1vS kb ib nc r now mt sl uw +local notation "σV" => w1vSA kb ib nc now mt sl + +theorem w1Th_fr : w1ThA kb ib nc (bwv FRn) = none := by + cases h : w1ThA kb ib nc (bwv FRn) with + | none => rfl + | some k => + exfalso + rcases w1ThA_cases h with ⟨e, -⟩ | ⟨e, -⟩ | ⟨e, -⟩ | hb + · have := congrArg UScalar.val e; rw [vFR, vRR] at this; omega + · have := congrArg UScalar.val e; rw [vFR, vRT] at this; omega + · rw [vFR] at e; unfold FrPg at e; omega + · have hkb := P.kbR + have hib := P.ibR + rcases bootTh_loc hL hK hb with ⟨c, hc, -, hv, -, -⟩ | ⟨-, i, hi, hv, -, -⟩ <;> rw [vFR] at hv <;> omega + +theorem w1vTh_old {p : U64} {k : ObjKindA} (h : w1ThA kb ib nc p = some k) : w1vThA kb ib nc p = some k := by + unfold w1vThA + rw [if_neg (fun e => by rw [e, w1Th_fr hL hK P] at h; cases h), h] + +/-- A slot of `w1vThA` is a slot of `w1`'s typed heap (the new object holds none). -/ +theorem w1v_isSlot {y : U64} (hy : IsSlotA (w1vThA kb ib nc) y) : y ∈ w1OS kb ib nc := by + have back : ∀ p k, w1vThA kb ib nc p = some k → (∀ z, k ≠ .other z) → w1ThA kb ib nc p = some k := by + intro p k h hk + unfold w1vThA at h + split_ifs at h + · cases h; exact absurd rfl (hk _) + · exact h + rw [← w1OS_eqA hL hK P] + obtain ⟨p, ⟨n, hn, h⟩ | ⟨ht, h⟩⟩ := hy + · exact ⟨p, Or.inl ⟨n, back p _ hn (fun _ e => by cases e), h⟩⟩ + · exact ⟨p, Or.inr ⟨back p _ ht (fun _ e => by cases e), h⟩⟩ + +theorem w1v_capCases {y : U64} (hy : IsSlotA (w1vThA kb ib nc) y) : + (y ∈ w1OS kb ib nc ∧ capA bst SV y = capA bst S1 y) ∨ ∃ k, k < 5 ∧ capA bst SV y = newC k := by + have h := w1v_isSlot hL hK P hy + rcases capV_split (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P h with e | ⟨k, hk, -, e, -⟩ + · exact Or.inl ⟨h, e⟩ + · exact Or.inr ⟨k, hk, e⟩ + +/-- **`JAtZA.cv` at `w1v`.** -/ +theorem w1v_cvA : ∀ y, IsSlotA (w1vThA kb ib nc) y → CapValidA (w1vThA kb ib nc) (capAtA (bL.mem SV) y) := by + intro y hy + show CapValidA _ (capA bst SV y) + rcases w1v_capCases (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) hL hK P hy with ⟨h, e⟩ | ⟨k, hk, e⟩ + · rw [e] + have c := w1_cvA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) hL hK P y + (by rw [← w1OS_eqA hL hK P] at h; exact h) + change CapValidA (w1ThA kb ib nc) (capA bst S1 y) at c + revert c + cases capA bst S1 y <;> intro c <;> try exact c + · exact ⟨w1vTh_old hL hK P c.1, c.2⟩ + · exact w1vTh_old hL hK P c + · rw [e] + interval_cases k + all_goals first | exact trivial | exact fun h => absurd h (by decide) + +/-- **`JAtZA.pml` at `w1v`.** -/ +theorem w1v_pmlA (y : U64) (hy : IsSlotA (w1vThA kb ib nc) y) (p : U64) (mp : Bool) (asid : U64) + (hc : capAtA (bL.mem SV) y = .Pml4 p mp asid) : p ∈ w1Tb ∧ w1Lv p = 0 := by + change capA bst SV y = .Pml4 p mp asid at hc + rcases w1v_capCases (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) hL hK P hy with ⟨h, e⟩ | ⟨k, hk, e⟩ + · rw [e] at hc + exact w1_pmlA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) hL hK P y + (by rw [← w1OS_eqA hL hK P] at h; exact h) p mp asid hc + · rw [e] at hc + interval_cases k <;> cases hc + +/-- A heap object of `w1v` is a new object, the new pool, or `w1`'s. -/ +theorem w1vK_cases {p : Fl4SpecA64.ObjRef} {ko : Fl4SpecA64.KernelObject} + (h : w1vKA kb ib nc now mt sl p = some ko) : + (p = specPtr (bwv S2n) ∧ ko = .archObj (.ext (.stage2Root w1vEsA))) ∨ + (p = specPtr (bwv HWn) ∧ ko = .archObj (.ext (.highVSpace fun _ => .invalidPTE))) ∨ + ko = .archObj (.pageTable w1vPtA) ∨ ko = .archObj (.asidPool w1vPoolA) ∨ w1KA kb ib nc now mt sl p = some ko := by + have hnm : ∀ n, n < 2 ^ 64 → (fl4Ptr p).val = n → p = specPtr (bwv n) := fun n hn e => by + rw [← specPtr_fl4Ptr p] + exact congrArg specPtr (UScalar.eq_of_val_eq (by rw [bwv_val hn]; exact e)) + unfold w1vKA at h + split_ifs at h with h1 h2 h3 h4 h5 + · exact Or.inl ⟨hnm _ (by norm_num) h1, (Option.some.inj h).symm⟩ + · exact Or.inr (Or.inl ⟨hnm _ (by norm_num) h2, (Option.some.inj h).symm⟩) + · exact Or.inr (Or.inr (Or.inl (Option.some.inj h).symm)) + · exact Or.inr (Or.inr (Or.inl (Option.some.inj h).symm)) + · exact Or.inr (Or.inr (Or.inr (Or.inl (Option.some.inj h).symm))) + · exact Or.inr (Or.inr (Or.inr (Or.inr h))) + +/-- A `w1` heap object away from the five new names is `w1v`'s. -/ +theorem w1vK_old {q : U64} (h : q.val < S2n) (hp : q.val ≠ PLn) : + w1vKA kb ib nc now mt sl (specPtr q) = w1KA kb ib nc now mt sl (specPtr q) := by + unfold w1vKA + rw [fl4Ptr_specPtr, if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg hp] + +/-- **The extension records at `w1v`.** -/ +theorem w1v_extA : + VcpuCoreA (L := bL) (w1vZA kb ib nc) SV σV ∧ Stage2CoreA (L := bL) (w1vZA kb ib nc) SV σV ∧ + HighVSpaceCoreA (L := bL) (w1vZA kb ib nc) SV σV := by + obtain ⟨V1, S1', H1'⟩ := w1_extA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) hL hK P + refine ⟨⟨fun _ h => absurd h (Set.notMem_empty _), fun p x h => ?_, fun t ht => ?_, fun y hy p e => ?_⟩, + ⟨fun q hq => ?_, fun p es h => ?_, fun y hy p l mp asid va e => ?_⟩, + ⟨fun q hq => ?_, fun p l1 h => ?_, fun y hy p mp asid e => ?_⟩⟩ + · change w1vKA kb ib nc now mt sl p = _ at h + rcases w1vK_cases hL hK P h with ⟨-, c⟩ | ⟨-, c⟩ | c | c | c + · cases c + · cases c + · cases c + · cases c + · exact V1.back p x c + · -- the TCB records and words are `w1`'s + have htT : t ∈ (w1H kb ib nc).tcbs := ht + obtain ⟨x, hx, h1, h2⟩ := V1.tcb t ht + have hkb := P.kbR + have hib := P.ibR + have loc : (t.val + 4096 ≤ RRn) ∨ t.val = 18446604435733233664 := by + rcases w1T P htT with h | h + · obtain ⟨c, hc, e⟩ := bootT_of hL h + have := idleTA_val hL hc + rw [e]; omega + · exact Or.inr (by rw [h, vRT]) + have kw : ∀ o : U64, 224 ≤ o.val → o.val < 4096 → bL.mem SV (wa t o) = bL.mem S1 (wa t o) := by + intro o h1' h2' + have v : (wa t o).val = t.val + o.val := wadd_val (by omega) + have h128 := P.w0.nc128 + exact memV_keep (by omega) (by omega) (by omega) (by omega) + have hnm : w1vKA kb ib nc now mt sl (specPtr t) = w1KA kb ib nc now mt sl (specPtr t) := + w1vK_old hL hK P (by omega) (by omega) + refine ⟨x, hnm.trans hx, ?_, ?_⟩ + · rw [kw 3664#u64 (by decide) (by decide)]; exact h1 + · rw [show runVcpuA t = wa t 3672#u64 from rfl, kw 3672#u64 (by decide) (by decide)] + exact h2 + · change capA bst SV y = _ at e + rcases w1v_capCases (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) hL hK P hy with ⟨h, c⟩ | ⟨k, hk, c⟩ + · exact V1.cap y (by rw [← w1OS_eqA hL hK P] at h; exact h) p (c.symm.trans e) + · rw [c] at e; interval_cases k <;> cases e + · obtain rfl : q = bwv S2n := hq + exact ⟨_, w1vK_s2⟩ + · change w1vKA kb ib nc now mt sl p = _ at h + rcases w1vK_cases hL hK P h with ⟨e, -⟩ | ⟨-, c⟩ | c | c | c + · exact ⟨bwv S2n, rfl, e.symm⟩ + · cases c + · cases c + · cases c + · obtain ⟨_, hr, -⟩ := S1'.back p es c + exact absurd hr (Set.notMem_empty _) + · change capA bst SV y = _ at e + rcases w1v_capCases (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) hL hK P hy with ⟨h, c⟩ | ⟨k, hk, c⟩ + · exact absurd (c.symm.trans e) ((w1_noExtA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P h).1 + p l mp asid va) + · rw [c] at e + interval_cases k <;> cases e + rfl + · obtain rfl : q = bwv HWn := hq + exact ⟨_, w1vK_hw⟩ + · change w1vKA kb ib nc now mt sl p = _ at h + rcases w1vK_cases hL hK P h with ⟨-, c⟩ | ⟨e, -⟩ | c | c | c + · cases c + · exact ⟨bwv HWn, rfl, e.symm⟩ + · cases c + · cases c + · obtain ⟨_, hr, -⟩ := H1'.back p l1 c + exact absurd hr (Set.notMem_empty _) + · change capA bst SV y = _ at e + rcases w1v_capCases (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) hL hK P hy with ⟨h, c⟩ | ⟨k, hk, c⟩ + · exact absurd (c.symm.trans e) ((w1_noExtA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P h).2 + p mp asid) + · rw [c] at e + interval_cases k <;> cases e + rfl + +end ext + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitVsLayA.lean b/proofs/Fl4ProofsA64/P3/A64WitVsLayA.lean new file mode 100644 index 000000000..20817cc2f --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitVsLayA.lean @@ -0,0 +1,433 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line witvs, spike S3.0): **`w1v`, the VS-world layout** over A64-Boot's `w1`. + +`w1` has no Stage-2 or high-window object, which the arms `frameMapS2`, `ptMapHi`, `ptMapS2`, `ptUnmapT2` need. +`w1v` adds, in a fresh block `NB = PPTR_BASE + 2^43` (inside the kernel window, above `w1`'s root-server block, +untyped and image): + +* a Stage-2 root (8 KiB, 1024 entries) at `NB`, whose entry 0 is a table descriptor naming +* a Stage-2 table (4 KiB, shift 21, all invalid) at `NB + 0x4000`; +* a high window (8 KiB) at `NB + 0x2000`: its level-0 page with entry 511 naming its level-1 page `NB + 0x3000` + (all invalid); +* an unmapped page table (4 KiB, all invalid, in no ghost set) at `NB + 0x5000`, for the two table maps; +* the root ASID pool's entries 2 (the Stage-2 root, tag 1) and 3 (the window, tag 2); +* the two cap words of four new caps (`Ept`, `HighVSpace`, the mapped and the unmapped `PageTable`), as decodes. + +Proved here: **`VsRelA` and `ExtVsRelA` at `w1v`** with `X = {S2}`, `Y = {HW}`, `T2 = {T2}`, the root and the window +active and the Stage-2 table reachable (so the relations' reachability-guarded clauses are not vacuous). + +Not here (step 3): the cap words in root CNode slots, heap / typed heap / CDT, and the whole record +(`JStage3A`) at `w1v`. Hypotheses: `BootLay1`, and for `ExtVsRelA` the platform's Stage-2 IPA width 40 ([P] +`OpaqueWA.ipaBits`: `s2Geom` is read from the opaque platform). New module; no existing statement changed. +-/ +import Fl4ProofsA64.P3.JBootW1SA +import Fl4ProofsA64.P3.ExtVsDefA +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 Classical + +local notation "wa" => core.num.U64.wrapping_add + +/-! ## Addresses -/ + +/-- The new block `NB = PPTR_BASE + 2^43`: the Stage-2 root. -/ +scoped notation "S2n" => (18446612132314218496 : Nat) +/-- The high window (its level-0 page). -/ +scoped notation "HWn" => (18446612132314226688 : Nat) +/-- The window's level-1 page, `HW + 4096`. -/ +scoped notation "H1n" => (18446612132314230784 : Nat) +/-- The Stage-2 table below the root. -/ +scoped notation "T2n" => (18446612132314234880 : Nat) +/-- The unmapped page table. -/ +scoped notation "UPn" => (18446612132314238976 : Nat) +/-- The end of the new block. -/ +scoped notation "NEn" => (18446612132314243072 : Nat) +scoped notation "PPn" => (18446603336221196288 : Nat) +scoped notation "VSn" => (18446604435733217280 : Nat) +scoped notation "PLn" => (18446604435733221376 : Nat) + +theorem vS2 : (bwv S2n).val = S2n := bwv_val (by norm_num) +theorem vHW : (bwv HWn).val = HWn := bwv_val (by norm_num) +theorem vT2 : (bwv T2n).val = T2n := bwv_val (by norm_num) +theorem vUP : (bwv UPn).val = UPn := bwv_val (by norm_num) +theorem vH1 : (bwv H1n).val = H1n := bwv_val (by norm_num) + +theorem waHW : wa (bwv HWn) 4096#u64 = bwv H1n := by + apply UScalar.eq_of_val_eq + rw [waWin_valA (by rw [vHW]; norm_num), vHW, vH1] + +/-! ## The memory -/ + +/-- **`w1v`'s memory** over a base memory (module docstring). -/ +def w1vM (mem : U64 → U64) (b : U64) : U64 := + if b.val = PLn + 16 then bwv (S2n + 1) + else if b.val = PLn + 24 then bwv (HWn + 2) + else if S2n ≤ b.val ∧ b.val < NEn then + (if b.val = S2n then bwv (tabE T2n) else if b.val = HWn + 4088 then bwv (tabE H1n) else 0#u64) + else mem b + +theorem w1vM_keep {mem : U64 → U64} {b : U64} (h1 : b.val ≠ PLn + 16) (h2 : b.val ≠ PLn + 24) + (h3 : b.val < S2n ∨ NEn ≤ b.val) : w1vM mem b = mem b := by + unfold w1vM + rw [if_neg h1, if_neg h2, if_neg (by omega)] + +/-- A word of the new block other than the two descriptors is zero. -/ +theorem w1vM_zero {mem : U64 → U64} {b : U64} (h1 : S2n ≤ b.val) (h2 : b.val < NEn) (h3 : b.val ≠ S2n) + (h4 : b.val ≠ HWn + 4088) : w1vM mem b = 0#u64 := by + unfold w1vM + rw [if_neg (by omega), if_neg (by omega), if_pos ⟨h1, h2⟩, if_neg h3, if_neg h4] + +theorem w1vM_s2e {mem : U64 → U64} {b : U64} (h : b.val = S2n) : w1vM mem b = bwv (tabE T2n) := by + unfold w1vM + rw [if_neg (by omega), if_neg (by omega), if_pos (by omega), if_pos h] + +theorem w1vM_wl {mem : U64 → U64} {b : U64} (h : b.val = HWn + 4088) : w1vM mem b = bwv (tabE H1n) := by + unfold w1vM + rw [if_neg (by omega), if_neg (by omega), if_pos (by omega), if_neg (by omega), if_pos h] + +/-! ## The two table descriptors -/ + +/-- `tabE t` for a table of the new block is a table descriptor naming `t` (`tabE_okA`'s facts). -/ +structure TabDescA (t : Nat) : Prop where + b0 : dBitA (bwv (tabE t)) 0 = true + b1 : dBitA (bwv (tabE t)) 1 = true + lt : (dAddrA (bwv (tabE t))).val < 2 ^ 44 + tab : dTabA (bwv (tabE t)) = bwv t + and3 : (bwv (tabE t) &&& 3#u64) = 3#u64 + +theorem tabDesc_of {t : Nat} (ht : t = T2n ∨ t = H1n) : TabDescA t := by + have hb : tabE t < 2 ^ 64 := by unfold tabE; rcases ht with rfl | rfl <;> norm_num + have ha : (dAddrA (bwv (tabE t))).val = t - PPn := by rcases ht with rfl | rfl <;> rfl + refine ⟨?_, ?_, by rw [ha]; rcases ht with rfl | rfl <;> norm_num, ?_, by rcases ht with rfl | rfl <;> rfl⟩ + · rw [dBitA_bwv hb]; unfold tabE; rcases ht with rfl | rfl <;> decide + · rw [dBitA_bwv hb]; unfold tabE; rcases ht with rfl | rfl <;> decide + · apply UScalar.eq_of_val_eq + unfold dTabA + have e : (18446603336221196288#u64 : U64).val = PPn := rfl + rw [wa_valP, ha, e, bwv_val (by rcases ht with rfl | rfl <;> norm_num)] + rcases ht with rfl | rfl <;> norm_num + +/-! ## The new cap words -/ + +/-- `2^59` (a cap's tag unit), `2^48`. -/ +scoped notation "TGn" => (576460752303423488 : Nat) +scoped notation "P48n" => (281474976710656 : Nat) + +/-- The Stage-2 root cap: mapped at ASID 2. -/ +theorem dec_ept : CapRt.decodeF (BitVec.ofNat 64 (23 * TGn + P48n + S2n % P48n)) (BitVec.ofNat 64 (2 * P48n)) = + .Ept (bwv S2n) 0#u64 true 2#u64 0#u64 := rfl + +/-- The high-window cap: mapped at ASID 3. -/ +theorem dec_hw : CapRt.decodeF (BitVec.ofNat 64 (25 * TGn + P48n + HWn % P48n)) (BitVec.ofNat 64 3) = + .HighVSpace (bwv HWn) true 3#u64 := rfl + +/-- The mapped Stage-2 table cap (`ptUnmapT2`): ASID 2, address 0. -/ +theorem dec_t2 : CapRt.decodeF (BitVec.ofNat 64 (14 * TGn + P48n + T2n % P48n)) (BitVec.ofNat 64 (2 * P48n)) = + .PageTable (bwv T2n) true 2#u64 0#u64 := rfl + +/-- The unmapped page-table cap (`ptMapHi`, `ptMapS2`). -/ +theorem dec_up : CapRt.decodeF (BitVec.ofNat 64 (14 * TGn + UPn % P48n)) (BitVec.ofNat 64 0) = + .PageTable (bwv UPn) false 0#u64 0#u64 := rfl + +/-! ## The spec objects -/ + +/-- The Stage-2 root's entries: entry 0 names the table. -/ +def w1vEsA : Fin 1024 → Fl4SpecA64.PTE := fun i => + if i.val = 0 then .pageTablePTE (ppnA (bwv (tabE T2n))) else .invalidPTE + +/-- An all-invalid normal page table. -/ +def w1vPtA : Fl4SpecA64.PT := .normalPT fun _ => .invalidPTE + +/-- The root ASID pool with the two new entries. -/ +def w1vPoolA : Fl4SpecA64.AsidPool := fun lo => + if lo = 2 then some (.asidPoolVSpace (specPtr (bwv S2n))) + else if lo = 3 then some (.asidPoolVSpace (specPtr (bwv HWn))) + else w1PoolA lo + +/-- **`w1v`'s heap**: `w1`'s with the new objects and the new pool. -/ +def w1vKA (kb ib : U64) (nc : Nat) (now mt sl : U64) : Fl4SpecA64.KHeap := fun p => + if (fl4Ptr p).val = S2n then some (.archObj (.ext (.stage2Root w1vEsA))) + else if (fl4Ptr p).val = HWn then some (.archObj (.ext (.highVSpace fun _ => .invalidPTE))) + else if (fl4Ptr p).val = T2n then some (.archObj (.pageTable w1vPtA)) + else if (fl4Ptr p).val = UPn then some (.archObj (.pageTable w1vPtA)) + else if (fl4Ptr p).val = PLn then some (.archObj (.asidPool w1vPoolA)) + else w1KA kb ib nc now mt sl p + +/-- **`w1v`'s abstract state** (heap only; the CSpace / CDT part is step 3's). -/ +def w1vSA (kb ib : U64) (nc : Nat) (now mt sl : U64) : Fl4SpecA64.State Unit := + { w1SA kb ib nc now mt sl with kheap := w1vKA kb ib nc now mt sl } + +def w1vX : Set U64 := {bwv S2n} +def w1vY : Set U64 := {bwv HWn} +def w1vT2 : Set U64 := {bwv T2n} +def w1vSh2 : U64 → Nat := fun _ => 21 + +section heap +variable {kb ib now mt sl : U64} {nc : Nat} + +theorem w1vK_s2 : w1vKA kb ib nc now mt sl (specPtr (bwv S2n)) = some (.archObj (.ext (.stage2Root w1vEsA))) := by + unfold w1vKA; rw [fl4Ptr_specPtr, vS2, if_pos rfl] + +theorem w1vK_hw : w1vKA kb ib nc now mt sl (specPtr (bwv HWn)) = + some (.archObj (.ext (.highVSpace fun _ => .invalidPTE))) := by + unfold w1vKA; rw [fl4Ptr_specPtr, vHW, if_neg (by norm_num), if_pos rfl] + +theorem w1vK_t2 : w1vKA kb ib nc now mt sl (specPtr (bwv T2n)) = some (.archObj (.pageTable w1vPtA)) := by + unfold w1vKA; rw [fl4Ptr_specPtr, vT2, if_neg (by norm_num), if_neg (by norm_num), if_pos rfl] + +theorem w1vK_up : w1vKA kb ib nc now mt sl (specPtr (bwv UPn)) = some (.archObj (.pageTable w1vPtA)) := by + unfold w1vKA; rw [fl4Ptr_specPtr, vUP, if_neg (by norm_num), if_neg (by norm_num), if_neg (by norm_num), if_pos rfl] + +theorem w1vK_pl : w1vKA kb ib nc now mt sl (specPtr (bwv PLb)) = some (.archObj (.asidPool w1vPoolA)) := by + unfold w1vKA + rw [fl4Ptr_specPtr, vPL, if_neg (by norm_num), if_neg (by norm_num), if_neg (by norm_num), if_neg (by norm_num), + if_pos rfl] + +theorem w1vK_tb {p : U64} (hp : p ∈ w1Tb) : + w1vKA kb ib nc now mt sl (specPtr p) = some (.archObj (.pageTable (ptOfA p))) := by + have h := w1Tb_val hp + unfold w1vKA + rw [fl4Ptr_specPtr, if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] + exact w1KA_pt hp + +end heap + +/-! ## The relations -/ + +section rel +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} + +local notation "M1" => w1M kb ib nc r now mt sl uw +local notation "MV" => w1vM (w1M kb ib nc r now mt sl uw) +local notation "SV" => w1vSA kb ib nc now mt sl + +theorem w1v_asidW (P : BootLay1 kb ib nc) {hi : U64} (hh : hi.val < 128) : + MV (atAF kb hi) = if hi.val = 0 then bwv PLb else 0#u64 := by + have hk := P.w0.kbw + have hR := P.kbR + have hv := atAF_valA (kb := kb) hk hh + rw [w1vM_keep (by omega) (by omega) (Or.inl (by omega))] + exact w1_asidW P hh + +/-- The pool's words: entries 2 and 3 are new, the others `w1`'s. -/ +theorem w1v_poolW (P : BootLay1 kb ib nc) {lo : U64} (hl : lo.val < 512) : + MV (peAF (bwv PLb) lo) = if lo.val = 2 then bwv (S2n + 1) else if lo.val = 3 then bwv (HWn + 2) + else if lo.val = 1 then bwv VSb else 0#u64 := by + have hv := peAF_valA (p := bwv PLb) (by rw [vPL]; norm_num) hl + rw [vPL] at hv + by_cases h2 : lo.val = 2 + · rw [if_pos h2]; unfold w1vM; rw [if_pos (by omega)] + by_cases h3 : lo.val = 3 + · rw [if_neg h2, if_pos h3]; unfold w1vM; rw [if_neg (by omega), if_pos (by omega)] + rw [if_neg h2, if_neg h3, w1vM_keep (by omega) (by omega) (Or.inl (by omega))] + exact w1_poolW P hl + +theorem w1v_tbW (P : BootLay1 kb ib nc) {p : U64} (hp : p ∈ w1Tb) {i : U64} (hi : i.val < 512) : + MV (peAF p i) = ptWA p.val (8 * i.val) := by + have hb := w1Tb_val hp + have hv := peAF_valA (p := p) (by omega) hi + rw [w1vM_keep (by omega) (by omega) (Or.inl (by omega))] + exact w1_ptMem P hp hi + +theorem untag_s2 : untagA (bwv (S2n + 1)) = bwv S2n := by unfold untagA; rfl +theorem untag_hw : untagA (bwv (HWn + 2)) = bwv HWn := by unfold untagA; rfl +theorem tag_s2 : tagA (bwv (S2n + 1)) = 1 := by unfold tagA; rw [bwv_val (by norm_num)] +theorem tag_hw : tagA (bwv (HWn + 2)) = 2 := by unfold tagA; rw [bwv_val (by norm_num)] + +theorem ofNat9_eqk {lo : U64} (hl : lo.val < 512) (k : Nat) (hk : k < 512) : + BitVec.ofNat 9 lo.val = BitVec.ofNat 9 k ↔ lo.val = k := by + constructor + · intro e + have h := congrArg BitVec.toNat e + rwa [BitVec.toNat_ofNat, BitVec.toNat_ofNat, Nat.mod_eq_of_lt (by omega), Nat.mod_eq_of_lt (by omega)] at h + · intro h; rw [h] + +theorem w1v_peAF_s2 {i : U64} (hi : i.val < 512) : (peAF (bwv S2n) i).val = S2n + 8 * i.val := by + rw [peAF_valA (by rw [vS2]; norm_num) hi, vS2] + +/-- The window's level-1 page and the Stage-2 table are all zero. -/ +theorem w1v_zeroPg {mem : U64 → U64} {t : Nat} (ht : t = H1n ∨ t = T2n ∨ t = UPn) {i : U64} (hi : i.val < 512) : + w1vM mem (peAF (bwv t) i) = 0#u64 := by + have hv : (peAF (bwv t) i).val = t + 8 * i.val := by + have e : (bwv t).val = t := bwv_val (by rcases ht with rfl | rfl | rfl <;> norm_num) + rw [peAF_valA (by rw [e]; rcases ht with rfl | rfl | rfl <;> norm_num) hi, e] + exact w1vM_zero (by omega) (by omega) (by omega) (by omega) + +/-- **`VsRelA` at `w1v`**, with the high window in `Y` and the Stage-2 root in `X`. -/ +theorem w1v_vsRelA (P : BootLay1 kb ib nc) : + VsRelA w1Pp w1Tb w1Lv w1vX w1vY MV kb SV := by + have R := w1_vsRelA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P + have eM : ∀ hi : U64, hi.val < 128 → MV (atAF kb hi) = M1 (atAF kb hi) := fun hi hh => by + rw [w1v_asidW P hh, w1_asidW P hh] + have pl : ∀ p ∈ w1Pp, p = bwv PLb := fun p hp => UScalar.eq_of_val_eq (by rw [vPL]; exact hp) + refine ⟨fun hi hh => ?_, fun hi hh h => ?_, fun p hp => ?_, fun p hp _ lo hl => ?_, fun _ => ?_, + fun p hp => ?_, fun y hy => ?_, R.lv, R.al, R.pal, fun y hy => ?_, fun y hy => ?_⟩ + · rw [eM hi hh]; exact R.table hi hh + · rw [eM hi hh] at h ⊢; exact R.tmem hi hh h + · obtain rfl := pl p hp + refine ⟨w1vPoolA, w1vK_pl, fun _ lo hl => ?_⟩ + rw [w1v_poolW P hl] + unfold w1vPoolA + have n2 : BitVec.ofNat 9 lo.val = 2 ↔ lo.val = 2 := ofNat9_eqk hl 2 (by omega) + have n3 : BitVec.ofNat 9 lo.val = 3 ↔ lo.val = 3 := ofNat9_eqk hl 3 (by omega) + by_cases h2 : lo.val = 2 + · rw [if_pos (n2.2 h2), if_pos h2] + unfold poolEntA + rw [if_neg (fun e => by have := congrArg UScalar.val e; rw [bwv_val (by norm_num)] at this; simp at this), + untag_s2] + by_cases h3 : lo.val = 3 + · rw [if_neg (_root_.mt n2.1 h2), if_pos (n3.2 h3), if_neg h2, if_pos h3] + unfold poolEntA + rw [if_neg (fun e => by have := congrArg UScalar.val e; rw [bwv_val (by norm_num)] at this; simp at this), + untag_hw] + rw [if_neg (_root_.mt n2.1 h2), if_neg (_root_.mt n3.1 h3), if_neg h2, if_neg h3] + unfold w1PoolA + by_cases h : lo.val = 1 + · rw [if_pos ((ofNat9_eq1 hl).2 h), if_pos h] + unfold poolEntA; rw [if_neg (fun e => by have := congrArg UScalar.val e; rw [vVS] at this; simp at this)] + rfl + · rw [if_neg (fun e => h ((ofNat9_eq1 hl).1 e)), if_neg h, poolEntA_zero] + · obtain rfl := pl p hp + rw [w1v_poolW P hl] + by_cases h2 : lo.val = 2 + · rw [if_pos h2] + exact Or.inr (Or.inr (Or.inl ⟨tag_s2, by rw [untag_s2]; exact rfl⟩)) + by_cases h3 : lo.val = 3 + · rw [if_neg h2, if_pos h3] + exact Or.inr (Or.inr (Or.inr ⟨tag_hw, by rw [untag_hw]; exact rfl⟩)) + rw [if_neg h2, if_neg h3] + by_cases h : lo.val = 1 + · rw [if_pos h] + have u : untagA (bwv VSb) = bwv VSb := by unfold untagA; rfl + refine Or.inr (Or.inl ⟨by simp [tagA, vVS], ?_, ?_⟩) <;> rw [u] + · exact Or.inl vVS + · exact lv_vs + · rw [if_neg h]; exact Or.inl rfl + · rw [w1v_asidW P (hi := 0#u64) (by decide), if_pos (show (0#u64 : U64).val = 0 from rfl), + w1v_poolW P (lo := 0#u64) (by decide), if_neg (show ¬ (0#u64 : U64).val = 2 by decide), + if_neg (show ¬ (0#u64 : U64).val = 3 by decide), if_neg (show ¬ (0#u64 : U64).val = 1 by decide)] + · refine ⟨ptOfA p, w1vK_tb hp, ptOfA_type hp, fun _ i hi => ?_⟩ + rw [w1v_tbW P hp hi, ptOfA_apply p hi] + exact pteOfA_rel (ptWA_ok hp _) + · obtain rfl : y = bwv HWn := hy + refine ⟨_, w1vK_hw, fun _ i hi => ?_⟩ + show dBitA (MV (peAF (wa (bwv HWn) 4096#u64) i)) 0 = false + rw [waHW, w1v_zeroPg (Or.inl rfl) hi] + exact dBitA_zero 0 + · obtain rfl : y = bwv HWn := hy + rw [vHW]; norm_num + · obtain rfl : y = bwv HWn := hy + rw [waHW] + intro h + have := w1Tb_val h + rw [vH1] at this + omega + +/-! ## Reachability: the guarded clauses are not vacuous -/ + +/-- The Stage-2 root is installed at ASID 2. -/ +theorem w1v_activeS2 : ActiveS2RootA w1Pp w1vX SV (bwv S2n) := by + refine ⟨rfl, 2, bwv PLb, w1vPoolA, by decide, vPL, ?_, w1vK_pl, ?_⟩ + · show w1AsidA (Fl4SpecA64.asidHighBitsOf 2) = _ + unfold w1AsidA; rw [if_pos (by decide)] + · show w1vPoolA (Fl4SpecA64.asidLowBitsOf 2) = _ + unfold w1vPoolA; rw [if_pos (by decide)] + +/-- The window is installed at ASID 3. -/ +theorem w1v_activeHigh (P : BootLay1 kb ib nc) : ActiveHighRootA MV kb w1Pp (bwv HWn) := by + refine ⟨3#u64, bwv (HWn + 2), ⟨0#u64, 3#u64, by decide, by decide, by decide, bwv PLb, vPL, + fun e => by have := congrArg UScalar.val e; rw [vPL] at this; simp at this, ?_, ?_, ?_⟩, tag_hw, untag_hw⟩ + · rw [w1v_asidW P (by decide), if_pos (show (0#u64 : U64).val = 0 from rfl)] + · rw [w1v_poolW P (by decide), if_neg (show ¬ (3#u64 : U64).val = 2 by decide), + if_pos (show (3#u64 : U64).val = 3 from rfl)] + · exact fun e => by have := congrArg UScalar.val e; rw [bwv_val (by norm_num)] at this; simp at this + +/-- The Stage-2 table is reachable from the active root through its entry 0. -/ +theorem w1v_reachT2 : S2ReachA w1Pp w1vX w1vT2 w1vSh2 MV SV (bwv T2n) := by + have e : MV (peAF (bwv S2n) 0#u64) = bwv (tabE T2n) := + w1vM_s2e (by rw [w1v_peAF_s2 (by decide)]; rfl) + have d := tabDesc_of (t := T2n) (Or.inl rfl) + have h := S2ReachA.stepRoot (T2 := w1vT2) (Sh2 := w1vSh2) (mem := MV) (i := 0#u64) + (w1v_activeS2 (kb := kb) (ib := ib) (now := now) (mt := mt) (sl := sl) (nc := nc)) + (Nat.zero_le _ |>.trans_lt (Nat.succ_pos _)) (by rw [e]; exact d.and3) (by rw [e, d.tab]; exact rfl) + rwa [e, d.tab] at h + +/-- **`ExtVsRelA` at `w1v`** for one Stage-2 root, one table below it and one high window. -/ +theorem w1v_extVsRelA (hI : Fl4SpecA64.fl4A64Platform.s2IpaBits = 40) : + ExtVsRelA w1Pp w1Tb w1vX w1vY w1vT2 w1vSh2 MV SV := by + have g : Fl4SpecA64.s2Geom.topShift = 30 := by unfold Fl4SpecA64.s2Geom; rw [hI]; rfl + have hs2 : ∀ r ∈ w1vX, r = bwv S2n := fun r h => h + have hhw : ∀ y ∈ w1vY, y = bwv HWn := fun y h => h + have ht2 : ∀ t ∈ w1vT2, t = bwv T2n := fun t h => h + have wlw : MV (peAF (bwv HWn) 511#u64) = bwv (tabE H1n) := by + refine w1vM_wl ?_ + rw [peAF_valA (by rw [vHW]; norm_num) (by decide), vHW]; rfl + have d1 := tabDesc_of (t := H1n) (Or.inr rfl) + have notVs : ∀ q : U64, S2n ≤ q.val → q.val ≠ H1n → q ∉ VsPtA w1Pp w1Tb w1vY := by + rintro q h1 h2 (h | h | ⟨y, hy, rfl⟩) + · have : q.val = PLb := h; omega + · have := w1Tb_val h; omega + · obtain rfl := hhw y hy; rw [waHW, vH1] at h2; exact h2 rfl + have pg : ∀ q ∈ S2PgE w1vX w1vT2, q.val = S2n ∨ q.val = S2n + 4096 ∨ q.val = T2n := by + rintro q (h | ⟨r, hr, h | h⟩) + · obtain rfl := ht2 q h; exact Or.inr (Or.inr vT2) + · obtain rfl := hs2 r hr; rw [h]; exact Or.inl vS2 + · obtain rfl := hs2 r hr + rw [h, waWin_valA (by rw [vS2]; norm_num), vS2]; exact Or.inr (Or.inl rfl) + refine ⟨fun r hr => ?_, fun t ht => ?_, fun t _ => by unfold w1vSh2; omega, fun y hy => ?_, fun y hy i hi => ?_, + fun r hr => ?_, fun t ht => ?_, fun q hq => ?_, fun t ht r hr => ?_, fun y hy => ?_, fun y hy => ?_⟩ + · obtain rfl := hs2 r hr + refine ⟨w1vEsA, w1vK_s2, fun _ i hi _ => ?_⟩ + unfold w1vEsA + by_cases h0 : i.val = 0 + · rw [if_pos h0] + have e : MV (peAF (bwv S2n) i) = bwv (tabE T2n) := + w1vM_s2e (by rw [w1v_peAF_s2 (by omega), h0]) + have d := tabDesc_of (t := T2n) (Or.inl rfl) + rw [e, g] + exact ⟨⟨by decide, d.b0, d.b1, d.lt, rfl, by rw [d.tab]; exact ⟨rfl, rfl⟩⟩, trivial⟩ + · rw [if_neg h0] + have e : MV (peAF (bwv S2n) i) = 0#u64 := by + have hv : (peAF (bwv S2n) i).val = S2n + 8 * i.val := by + rw [peAF_val1kE (by rw [vS2]; norm_num) hi, vS2] + exact w1vM_zero (by omega) (by omega) (by omega) (by omega) + rw [e]; exact ⟨descRelE_zero _ _, trivial⟩ + · obtain rfl := ht2 t ht + refine ⟨w1vPtA, w1vK_t2, rfl, fun _ i hi => ?_⟩ + rw [w1v_zeroPg (Or.inr (Or.inl rfl)) hi] + exact ⟨descRelE_zero _ _, trivial⟩ + · obtain rfl := hhw y hy + rw [wlw, waHW]; exact ⟨d1.b0, d1.b1, d1.tab⟩ + · obtain rfl := hhw y hy + have hv : (peAF (bwv HWn) i).val = HWn + 8 * i.val := by + rw [peAF_valA (by rw [vHW]; norm_num) (by omega), vHW] + exact w1vM_zero (by omega) (by omega) (by omega) (by omega) + · obtain rfl := hs2 r hr; rw [vS2]; norm_num + · obtain rfl := ht2 t ht; rw [vT2]; norm_num + · have h := pg q hq + refine ⟨notVs q (by omega) (by omega), fun hy => ?_⟩ + obtain rfl := hhw q hy + rw [vHW] at h; omega + · obtain rfl := ht2 t ht + obtain rfl := hs2 r hr + refine ⟨fun e => ?_, fun e => ?_⟩ + · have := congrArg UScalar.val e; rw [vT2, vS2] at this; omega + · have := congrArg UScalar.val e + rw [vT2, waWin_valA (by rw [vS2]; norm_num), vS2] at this; omega + · obtain rfl := hhw y hy + exact notVs _ (by rw [vHW]; omega) (by rw [vHW]; omega) + · obtain rfl := hhw y hy + rw [waHW] + intro h + have : (bwv H1n).val = PLb := h + rw [vH1] at this; omega + +end rel + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitVsPremA.lean b/proofs/Fl4ProofsA64/P3/A64WitVsPremA.lean new file mode 100644 index 000000000..cf51dbf34 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitVsPremA.lean @@ -0,0 +1,692 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line witvs): **the premise-level witness of the VS arms** `ptMapHi`, `ptMapS2`, +`frameMapS2`, `ptUnmapT2` (`VsScopeA`, `P3/Stage3DispVsA`), as `P3/A64WitUtA` is for the Untyped reset arm. + +The state `w1vR … v0 v1 v2` is `w1vS` (`P3/A64WitVsStA`) with core 0's current thread the root TCB and the first +three message registers `v0`, `v1`, `v2`. Per arm, jointly satisfiable at it: the invoked cap, the extra root cap, +the root lookup (`ept.root`), the unmapped-table / frame facts, the message words and **FL4's kernel run** (the map +returns `Ok`); for `ptUnmapT2` the finality run, the spec root kind and the absence of another cap on the table. +The VSpace relations hold at the same state (`w1vR_vsRels`). + +**Not shown** (state exactly what is open): +* **the whole record (`JStage3A` / `JSyscallA`) is not proved satisfiable with non-empty Stage-2 roots, high + windows or Stage-2 tables** (backlog: the full VS-world witness, measured projection ≈ 6,600 lines, range + 4,900–8,300); +* hence the record-dependent premises of the arms: `hTO` / `hEO` (`TabOffA`, `ExtTabOffA`), `DecPre` (`d`), + `hcov` / `hSC` beyond the invoked slot's `SlotCov`, `hpin` (`DecPinA`) and the spec decode's success; +* `ptUnmapT2`'s [J] premise `hUniq` (a fact about the unmap run). + +Hypotheses: `BootLay1`; [P] `s2IpaBits = 40` where the Stage-2 geometry is read; `P0.ArchTotal` and +`s2_ipa_bits = ok 40` of the arch (both hold at the model arch `AR1`). New module; no existing statement changed. +-/ +import Fl4ProofsA64.P3.A64WitVsStA +import Fl4ProofsA64.P3.VsMapPageA +import Fl4ProofsA64.P3.VsUnmapA +import Fl4ProofsA64.P3.VsMapA +import Fl4ProofsA64.P3.CapRelA +import Fl4ProofsA64.P3.FrontEndExtraA +import Fl4ProofsA64.P3.JEntW1A +import Fl4ProofsA64.P1.VcpuHooks +import Fl4ProofsA64.P1.VmRootRd +import Fl4ProofsA64.P0.Auto +import Fl4ProofsA64.P1.QueueUtRetype +import Fl4ProofsA64.P1.QueueSlotTy +import Fl4ProofsA64.P3.ExtVsWalkA +import Fl4ProofsA64.P3.VsWalkA +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 Classical + +local notation "wa" => core.num.U64.wrapping_add + +/-- `NB`'s root TCB address and `NODE 0`'s `CUR_THREAD` offset. -/ +scoped notation "RTn" => (18446604435733233664 : Nat) + +/-! ## The state with a message -/ + +/-- The current thread and the three message registers over a memory. -/ +def msgM (kb : Nat) (v0 v1 v2 : U64) (mem : U64 → U64) (b : U64) : U64 := + if b.val = kb + 223488 then bwv RTn else if b.val = RTn + 272 then v0 else + if b.val = RTn + 280 then v1 else if b.val = RTn + 288 then v2 else mem b + +/-- **The witness state of the arms.** -/ +def w1vR (kb ib : U64) (nc : Nat) (r now mt sl : U64) (uw : U64 → U64) (v0 v1 v2 : U64) : BS := + ⟨msgM kb.val v0 v1 v2 (w1vFM nc (w1M kb ib nc r now mt sl uw)), kb, 0#u64⟩ + +/-- The extra-cap array with one cap. -/ +def extraV (x0 : U64) : Aeneas.Std.Array obj.Slot 3#usize := Aeneas.Std.Array.make 3#usize [x0, 0#u64, 0#u64] + +/-- Root CNode slot `j`'s address. -/ +abbrev rsV (j : Nat) : U64 := bwv (RRn + 32 * j) + +theorem rsV_val {j : Nat} (h : j < 8192) : (rsV j).val = RRn + 32 * j := bwv_val (by omega) + +section st +variable {kb ib r now mt sl v0 v1 v2 : U64} {nc : Nat} {uw : U64 → U64} + +local notation "S1" => w1S kb ib nc r now mt sl uw +local notation "SV" => w1vS kb ib nc r now mt sl uw +local notation "SR" => w1vR kb ib nc r now mt sl uw v0 v1 v2 + +/-- A word other than the current thread and the three registers is `w1vS`'s. -/ +theorem memR_keep {b : U64} (h0 : b.val ≠ kb.val + 223488) (h1 : b.val < RTn + 272 ∨ RTn + 296 ≤ b.val) : + bL.mem SR b = bL.mem SV b := by + show msgM kb.val v0 v1 v2 _ b = _ + unfold msgM + rw [if_neg h0, if_neg (by omega), if_neg (by omega), if_neg (by omega)] + rfl + +theorem curR (P : BootLay1 kb ib nc) : bL.curW SR = bwv RTn := by + have h128 := P.w0.nc128 + have hnc := P.w0.nc0 + have e : bL.nodeAt SR 0#u64 layout.node.CUR_THREAD = bL.nodeAt (bootS kb ib nc r now mt) 0#u64 + layout.node.CUR_THREAD := nodeAt_of_ksb (by rfl) _ _ + have v : (bL.nodeAt SR 0#u64 layout.node.CUR_THREAD).val = kb.val + 223488 := by + rw [e, nodeAt_bv (r := r) (now := now) (mt := mt) P.w0 (by simp) (by simp [layout.node.CUR_THREAD])] + simp [layout.node.CUR_THREAD] + change msgM kb.val v0 v1 v2 _ (bL.nodeAt SR 0#u64 layout.node.CUR_THREAD) = _ + unfold msgM + rw [if_pos v] + +theorem curThreadR (P : BootLay1 kb ib nc) : sched.cur_thread bst SR = ok (bwv RTn) := by + rw [cur_thread_ok, curR P] + +/-- The kernel block lies below the root-server block and off the root TCB. -/ +theorem kb_lo (P : BootLay1 kb ib nc) : kb.val + 788736 ≤ RRn := P.kbR + +/-- A slot of `w1OS` keeps its cap from `w1vS`. -/ +theorem capR_keep (P : BootLay1 kb ib nc) {x : U64} (hx : x ∈ w1OS kb ib nc) : capA bst SR x = capA bst SV x := by + have hkb := P.kbR + have e8 : (8#u64 : U64).val = 8 := by simp + have loc : (x.val + 32 ≤ kb.val + 223488 ∨ kb.val + 223496 ≤ x.val) ∧ + (x.val + 32 ≤ RTn + 272 ∨ RTn + 296 ≤ x.val) ∧ x.val + 32 ≤ 2 ^ 64 := by + have hib := P.ibR + have ha := P.w0.apart + rcases w1OS_val P hx with ⟨t, c, i, -, hc, et, hi, -, ex⟩ | ⟨i, hi, -, ex⟩ | ⟨i, hi, ex⟩ | ⟨j, hj, -, ex⟩ + · exact ⟨by omega, Or.inl (by omega), by omega⟩ + · exact ⟨Or.inr (by omega), Or.inl (by omega), by omega⟩ + · exact ⟨Or.inr (by omega), by omega, by omega⟩ + · exact ⟨Or.inl (by omega), Or.inl (by omega), by omega⟩ + have h8 : (wa x 8#u64).val = x.val + 8 := by rw [wadd_val (by rw [e8]; omega), e8] + rw [capA_w, capA_w] + show CapRt.decodeF (bL.mem SR x).bv (bL.mem SR (wa x 8#u64)).bv = + CapRt.decodeF (bL.mem SV x).bv (bL.mem SV (wa x 8#u64)).bv + rw [memR_keep (b := x) (by omega) (by omega), memR_keep (b := wa x 8#u64) (by omega) (by omega)] + +theorem rsV_os {j : Nat} (h : j < 8192) : rsV j ∈ w1OS kb ib nc := Or.inr ⟨j, h, rsV_val h⟩ + +/-- **New slot `k`'s cap at the witness state.** -/ +theorem capR_new (P : BootLay1 kb ib nc) {k : Nat} (hk : k < 5) : capA bst SR (rsV (53 + nc + k)) = newC k := by + have h128 := P.w0.nc128 + rw [capR_keep P (rsV_os (by omega))] + exact capV_new h128 hk (by rw [rsV_val (by omega)]; omega) + +/-- The root CNode cap covers every root slot. -/ +theorem slotCovR (P : BootLay1 kb ib nc) {j : Nat} (h : j < 8192) : SlotCov bst (w1OS kb ib nc) SR (rsV j) := by + have hz : slotIdx (bwv RTn) 0#u64 ∈ w1OS kb ib nc := Or.inl (Or.inr ⟨0#u64, by simp, rfl⟩) + have zv : (slotIdx (bwv RTn) 0#u64).val = RTn := by rw [slotRT (i := 0#u64) (by simp)]; simp + refine ⟨_, hz, bwv RRn, 13#u64, 51#u64, 0#u64, ?_, bwv j, ?_, ?_⟩ + · have h128 := P.w0.nc128 + rw [capR_keep P hz, capV_keep (Or.inr (by omega)) (Or.inr (by omega)) (Or.inl (by omega)) (by omega), + cap_rt P (i := 0#u64) (by simp)] + rfl + · rw [bwv_val (by omega)]; simp; omega + · apply UScalar.eq_of_val_eq + have a : (bwv j).val = j := bwv_val (by omega) + have b : (bwv RRn).val = RRn := bwv_val (by norm_num) + rw [slotIdx_valG (by rw [a, b]; omega), a, b, rsV_val h] + +/-! ## The message registers -/ + +theorem regR (i k : U64) (hk : k.val = 2 ∨ k.val = 3 ∨ k.val = 4) (v : U64) (e : msg.msg_register i = ok k) + (hi : i < 4#u64) (P : BootLay1 kb ib nc) (buf : U64) + (hv : msgM kb.val v0 v1 v2 (w1vFM nc (w1M kb ib nc r now mt sl uw)) (regWA (bwv RTn) k) = v) : + msg.syscall_arg bst SR (bwv RTn) buf i = ok v := by + have n : msg.N_MSG_REGISTERS = 4#u64 := by simp [msg.N_MSG_REGISTERS] + unfold msg.syscall_arg + rw [n, if_pos hi, e, bind_ok, tcb_reg_eqA] + exact congrArg ok hv + +theorem regAv {k : U64} (hk : k.val < 6) : (regWA (bwv RTn) k).val = RTn + 256 + 8 * k.val := by + have a : (bwv RTn).val = RTn := bwv_val (by norm_num) + unfold regWA + have h1 : (wa (bwv RTn) layout.tcb.REGS).val = RTn + 256 := by + have e : (layout.tcb.REGS : U64).val = 256 := by simp [layout.tcb.REGS] + rw [wadd_val (by omega), a, e] + have h2 : (core.num.U64.wrapping_mul k 8#u64).val = 8 * k.val := by + simp [core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits] + omega + rw [wadd_val (by omega), h1, h2] + +/-- **The three message words.** -/ +theorem argsR (P : BootLay1 kb ib nc) (buf : U64) : + msg.syscall_arg bst SR (bwv RTn) buf 0#u64 = ok v0 ∧ + msg.syscall_arg bst SR (bwv RTn) buf 1#u64 = ok v1 ∧ + msg.syscall_arg bst SR (bwv RTn) buf 2#u64 = ok v2 := by + have hkb := P.kbR + have go : ∀ (i k : U64), (k.val = 2 ∨ k.val = 3 ∨ k.val = 4) → msg.msg_register i = ok k → i < 4#u64 → + msg.syscall_arg bst SR (bwv RTn) buf i = + ok (if k.val = 2 then v0 else if k.val = 3 then v1 else v2) := by + intro i k hk e hi + refine regR i k hk _ e hi P buf ?_ + have a := regAv (k := k) (by omega) + unfold msgM + rw [if_neg (by omega)] + rcases hk with h | h | h + · rw [if_pos (by omega), if_pos h] + · rw [if_neg (by omega), if_pos (by omega), if_neg (by omega), if_pos h] + · rw [if_neg (by omega), if_neg (by omega), if_pos (by omega), if_neg (by omega), if_neg (by omega)] + refine ⟨?_, ?_, ?_⟩ + · have := go 0#u64 2#u64 (by simp) (by simp [msg.msg_register, layout.reg.X2]) (by decide) + simpa using this + · have := go 1#u64 3#u64 (by simp) (by simp [msg.msg_register, layout.reg.X3]) (by decide) + simpa using this + · have := go 2#u64 4#u64 (by simp) (by simp [msg.msg_register, layout.reg.X4]) (by decide) + simpa using this + +/-- The current thread is not running a VCPU (`hnvm`). -/ +theorem hnvmR (P : BootLay1 kb ib nc) : bL.mem SR (stA (bL.curW SR)) ≠ sched.TS_RUNNING_VM := by + have hkb := P.kbR + have h128 := P.w0.nc128 + rw [curR P] + have a : (bwv RTn).val = RTn := bwv_val (by norm_num) + have v : (stA (bwv RTn)).val = RTn + 3328 := by + rw [stA_eq] + have e : (3328#u64 : U64).val = 3328 := by simp + rw [wadd_val (by omega), a, e] + rw [memR_keep (by omega) (by omega), memV_keep (by omega) (by omega) (by omega) (by omega)] + have w : bL.mem S1 (stA (bwv RTn)) = 1#u64 := by + rw [stA_eq] + have x : (wa (bwv RTn) 3328#u64).val = RTn + 3328 := by rw [← stA_eq]; exact v + exact (w1M_rt P (by omega) x).trans (by simp [rtW]) + rw [w] + intro h + have := congrArg UScalar.val h + simp [sched.TS_RUNNING_VM] at this + +/-! ## The VSpace words -/ + +/-- A word of the new block or the pool is `w1vM`'s. -/ +theorem memR_vs (P : BootLay1 kb ib nc) {b : U64} (h : RRn + 397312 ≤ b.val) (h' : b.val < RTn ∨ S2n ≤ b.val) : + bL.mem SR b = w1vM (w1M kb ib nc r now mt sl uw) b := by + have hkb := P.kbR + have h128 := P.w0.nc128 + rw [memR_keep (by omega) (by omega)] + exact w1vFM_out (Or.inr (by omega)) + +theorem asidR (P : BootLay1 kb ib nc) : bL.mem SR (atAF kb 0#u64) = bwv PLb := by + have hkb := P.kbR + have h128 := P.w0.nc128 + have v : (atAF kb 0#u64).val = kb.val + 772352 := by + rw [atAF_valA P.w0.kbw (by simp)]; simp + rw [memR_keep (by omega) (by omega)] + show w1vFM nc _ _ = _ + rw [w1vFM_out (Or.inl (by omega)), w1v_asidW P (by simp)] + simp + +/-- **`find_asid_raw`** at ASID 2 (the Stage-2 root) and 3 (the window). -/ +theorem findRawR (P : BootLay1 kb ib nc) {asid : U64} (h : asid = 2#u64 ∨ asid = 3#u64) : + vspace.find_asid_raw bst SR asid = + ok (.Ok (if asid = 2#u64 then bwv (S2n + 1) else bwv (HWn + 2))) := by + have hlo : asid.val < 512 := by rcases h with rfl | rfl <;> simp + have b16 : asid >>> vspace.ASID_BITS = ok 0#u64 := by + rcases h with rfl | rfl <;> simp [vspace.ASID_BITS] <;> rfl + have b9 : asid >>> vspace.ASID_LOW_BITS = ok 0#u64 := by + rcases h with rfl | rfl <;> simp [vspace.ASID_LOW_BITS] <;> rfl + have m : (asid &&& 511#u64) = asid := by rcases h with rfl | rfl <;> rfl + have t : vspace.asid_table bst SR 0#u64 = ok (bwv PLb) := by + rw [asid_table_eq, show (0#u64 &&& 127#u64) = 0#u64 from rfl] + exact congrArg ok (asidR P) + have pv : (bwv PLb).val = PLn := vPL + have pa : wa (bwv PLb) (core.num.U64.wrapping_mul asid 8#u64) = peAF (bwv PLb) asid := rfl + have pe : (peAF (bwv PLb) asid).val = PLn + 8 * asid.val := by + rw [peAF_valA (by rw [pv]; norm_num) hlo, pv] + have word : bL.mem SR (peAF (bwv PLb) asid) = if asid = 2#u64 then bwv (S2n + 1) else bwv (HWn + 2) := by + rw [memR_vs P (by omega) (Or.inl (by omega)), w1v_poolW P hlo] + rcases h with rfl | rfl <;> simp + have pne : bwv PLb ≠ 0#u64 := fun e => by have := congrArg UScalar.val e; rw [pv] at this; simp at this + have wne : (if asid = 2#u64 then bwv (S2n + 1) else bwv (HWn + 2)) ≠ 0#u64 := by + intro e + have := congrArg UScalar.val e + split_ifs at this <;> rw [bwv_val (by norm_num)] at this <;> simp at this + unfold vspace.find_asid_raw + rw [b16, bind_ok, if_neg (by simp), b9, bind_ok, t, bind_ok, if_neg pne] + simp only [lift, bind_ok, m, pa, LawfulStore.read_eq, word] + rw [if_neg wne] + +/-- **`hrt`**: the Stage-2 root cap resolves. -/ +theorem eptRootR (P : BootLay1 kb ib nc) : + ept.root bst SR (.Ept (bwv S2n) 0#u64 true 2#u64 0#u64) 1#u64 = + ok (core.result.Result.Ok (bwv S2n, 2#u64)) := by + have f := findRawR (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (v0 := v0) (v1 := v1) (v2 := v2) P + (asid := 2#u64) (Or.inl rfl) + rw [if_pos rfl] at f + have tag : (bwv (S2n + 1) &&& vspace.ROOT_TAG) = vspace.ROOT_S2 := by + simp only [vspace.ROOT_TAG, vspace.ROOT_S2]; rfl + have un : (bwv (S2n + 1) &&& ~~~ vspace.ROOT_TAG) = bwv S2n := by simp only [vspace.ROOT_TAG]; rfl + have fd : ept.find bst SR 2#u64 = ok (.Ok (bwv S2n)) := by + unfold ept.find + rw [f, bind_ok] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, lift, tag, bne_self_eq_false, + Bool.false_eq_true, ↓reduceIte, un] + unfold ept.root + simp [fd, core.result.Result.map_err, core.result.Result.Insts.CoreOpsTry.branch] + rfl + +/-- The window cap resolves (`map_high_page_table`'s `check_high_vspace`). -/ +theorem checkHighR (P : BootLay1 kb ib nc) : + vspace.check_high_vspace bst SR (.HighVSpace (bwv HWn) true 3#u64) 1#u64 = + ok (core.result.Result.Ok (bwv HWn, 3#u64)) := by + have f := findRawR (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) (v0 := v0) (v1 := v1) (v2 := v2) P + (asid := 3#u64) (Or.inr rfl) + rw [if_neg (by decide)] at f + have tag : (bwv (HWn + 2) &&& vspace.ROOT_TAG) = vspace.ROOT_HIGH := by + simp only [vspace.ROOT_TAG, vspace.ROOT_HIGH]; rfl + have un : (bwv (HWn + 2) &&& ~~~ vspace.ROOT_TAG) = bwv HWn := by simp only [vspace.ROOT_TAG]; rfl + have fd : vspace.find_high_asid bst SR 3#u64 = ok (.Ok (bwv HWn)) := by + unfold vspace.find_high_asid + rw [f, bind_ok] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, lift, tag, bne_self_eq_false, + Bool.false_eq_true, ↓reduceIte, un] + unfold vspace.check_high_vspace + simp [fd] + +/-- **The VSpace relations at the witness state.** -/ +theorem w1vR_vsRels (P : BootLay1 kb ib nc) (hI : Fl4SpecA64.fl4A64Platform.s2IpaBits = 40) : + VsRelA w1Pp w1Tb w1Lv w1vX w1vY (bL.mem SR) kb (w1vSA kb ib nc now mt sl) ∧ + ExtVsRelA w1Pp w1Tb w1vX w1vY w1vT2 w1vSh2 (bL.mem SR) (w1vSA kb ib nc now mt sl) := by + have hkb := P.kbR + have h128 := P.w0.nc128 + have hk := P.w0.kbw + refine ⟨(w1v_vsRelA_st (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P).of_mem fun b hb => ?_, + (w1v_extVsRelA_st (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P hI).of_mem fun b hb => ?_⟩ + · cases hb with + | asid hi hh => + have v := atAF_valA (kb := kb) hk hh + exact memR_keep (by omega) (by omega) + | pool p lo hp hl => + have e : p.val = PLn := hp + have v : (peAF p lo).val = p.val + 8 * lo.val := peAF_valA (by omega) hl + exact memR_keep (by omega) (by omega) + | pt p i hp hi => + have e := w1Tb_val hp + have v : (peAF p i).val = p.val + 8 * i.val := peAF_valA (by omega) hi + exact memR_keep (by omega) (by omega) + | high y i hy hi => + obtain rfl : y = bwv HWn := hy + have v : (peAF (wa (bwv HWn) 4096#u64) i).val = H1n + 8 * i.val := by + rw [waHW, peAF_valA (by rw [vH1]; norm_num) hi, vH1] + exact memR_keep (by omega) (by omega) + · have far : S2n ≤ b.val → bL.mem SR b = bL.mem SV b := fun h => memR_keep (by omega) (by omega) + refine far ?_ + cases hb with + | s2lo r i hr hi => + obtain rfl : r = bwv S2n := hr + rw [peAF_valA (by rw [vS2]; norm_num) hi, vS2]; omega + | s2hi r i hr hi => + obtain rfl : r = bwv S2n := hr + have e : (wa (bwv S2n) 4096#u64).val = S2n + 4096 := by rw [waWin_valA (by rw [vS2]; norm_num), vS2] + rw [peAF_valA (by omega) hi, e]; omega + | s2pt t i ht hi => + obtain rfl : t = bwv T2n := ht + rw [peAF_valA (by rw [vT2]; norm_num) hi, vT2]; omega + | wl0 y hy => + obtain rfl : y = bwv HWn := hy + rw [peAF_valA (by rw [vHW]; norm_num) (by decide), vHW]; omega + | wlo y i hy hi => + obtain rfl : y = bwv HWn := hy + rw [peAF_valA (by rw [vHW]; norm_num) (by omega), vHW]; omega + +/-- A word of the new block other than the two descriptors is zero. -/ +theorem zeroR (P : BootLay1 kb ib nc) {b : U64} {n : Nat} (hb : b.val = n) (h1 : S2n ≤ n) (h2 : n < NEn) + (h3 : n ≠ S2n) (h4 : n ≠ HWn + 4088) : bL.mem SR b = 0#u64 := by + rw [memR_vs P (by omega) (Or.inr (by omega))] + exact w1vM_zero (by omega) (by omega) (by omega) (by omega) + +/-! ## The unmapped table -/ + +/-- **`UnmPtA`** for the unmapped page table (`ptMapHi`, `ptMapS2`). -/ +theorem unmPtR (P : BootLay1 kb ib nc) : + UnmPtA w1Tb w1vY (w1OS kb ib nc) (w1H kb ib nc).tcbs (bL.mem SR) (w1vSA kb ib nc now mt sl) (bwv UPn) := by + have hkb := P.kbR + have hib := P.ibR + have pv : ∀ i : U64, i.val < 512 → (peAF (bwv UPn) i).val = UPn + 8 * i.val := fun i hi => by + rw [peAF_valA (by rw [vUP]; norm_num) hi, vUP] + refine ⟨fun h => ?_, by rw [vUP]; norm_num, fun y hy e => ?_, ?_, fun i hi => ?_, fun i hi ⟨y, hy, h1, h2⟩ => ?_, + fun i hi t ht => ?_, ⟨w1vPtA, w1vK_up, rfl, fun _ _ => rfl⟩⟩ + · have := w1Tb_val h; rw [vUP] at this; omega + · obtain rfl : y = bwv HWn := hy + rw [waHW] at e + have := congrArg UScalar.val e + rw [vH1, vUP] at this; omega + · have e : (core.num.U64.wrapping_sub (bwv UPn) layout.PPTR_BASE).val = UPn - 18446603336221196288 := by + have b : (layout.PPTR_BASE : U64) = 18446603336221196288#u64 := by simp [layout.PPTR_BASE] + rw [b]; rfl + rw [e]; norm_num + · rw [zeroR P (pv i hi) (by omega) (by omega) (by omega) (by omega)] + exact dBitA_zero 0 + · have a := pv i hi + have : y.val + 32 ≤ RRn + 262144 ∨ y.val + 32 ≤ RTn + 224 := by + rcases w1OS_val P hy with ⟨t, c, k, -, hc, et, hk, -, ex⟩ | ⟨k, hk, -, ex⟩ | ⟨k, hk, ex⟩ | ⟨j, hj, -, ex⟩ + · exact Or.inl (by omega) + · exact Or.inr (by omega) + · exact Or.inl (by omega) + · exact Or.inl (by omega) + omega + · refine Or.inr ?_ + rw [pv i hi] + have : t.val + 4096 ≤ RTn + 4096 := by + rcases w1H_tcbs P ht with ⟨c, hc, e⟩ | e + · omega + · omega + omega + +/-! ## The runs -/ + +theorem sts_ok (s : BS) (t : U64) (v : U64) : ∃ s', sched.set_thread_state bst s t v = ok s' := by + obtain ⟨s', h, -⟩ := spec_exists_u (Fl4ProofsA64.P0.sched.set_thread_state.p0 bst s t v LawfulStore.total) + exact ⟨s', h⟩ + +theorem setcap_ok (x : U64) (s : BS) (c : capability.Cap) : ∃ s', obj.Slot.set_cap bst x s c = ok s' := by + obtain ⟨s', h, -⟩ := spec_exists_u (Fl4ProofsA64.P0.obj.Slot.set_cap.p0 bst x s c LawfulStore.total) + exact ⟨s', h⟩ + +end st + +/-! ## The walks -/ + +theorem is_table_zero {sh : U64} (h : 12 < sh.val) : vspace.is_table 0#u64 sh = ok false := by + unfold vspace.is_table + rw [if_pos (show sh > vspace.PAGE_BITS by simp [vspace.PAGE_BITS]; scalar_tac), + eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, eq_of_spec_fd P0.Consts.vspace.D_TABLE_OR_PAGE.spec] + simp only [lift, bind_ok] + rfl + +theorem is_table_desc {e sh : U64} (h : 12 < sh.val) (he : (e &&& 3#u64) = 3#u64) : + vspace.is_table e sh = ok true := by + unfold vspace.is_table + rw [if_pos (show sh > vspace.PAGE_BITS by simp [vspace.PAGE_BITS]; scalar_tac), + eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, eq_of_spec_fd P0.Consts.vspace.D_TABLE_OR_PAGE.spec] + simp only [lift, bind_ok] + rw [show (1#u64 ||| 2#u64) = 3#u64 from rfl, he] + rfl + +theorem loop_done {s : BS} {v sh sl lv : U64} {x : U64 × U64} + (h : vspace.lookup_pt_slot_loop.body bst s v sh sl lv = ok (.done x)) : + vspace.lookup_pt_slot_loop bst s v sh sl lv = ok x := by + unfold vspace.lookup_pt_slot_loop + rw [loop] + dsimp only + rw [h, bind_ok] + +theorem loop_cont {s : BS} {v sh sl lv a b c : U64} + (h : vspace.lookup_pt_slot_loop.body bst s v sh sl lv = ok (.cont (a, b, c))) : + vspace.lookup_pt_slot_loop bst s v sh sl lv = vspace.lookup_pt_slot_loop bst s v a b c := by + unfold vspace.lookup_pt_slot_loop + conv_lhs => + rw [loop] + dsimp only + rw [h, bind_ok] + +/-- A walk step at a zero word ends the walk. -/ +theorem body_zero {s : BS} {v sh sl lv : U64} (h12 : 12 < sh.val) (hlv : lv > 0#u64) (hm : bL.mem s sl = 0#u64) : + vspace.lookup_pt_slot_loop.body bst s v sh sl lv = ok (.done (sh, sl)) := by + unfold vspace.lookup_pt_slot_loop.body + rw [if_pos hlv] + simp only [bL.read_eq, bind_ok, hm, is_table_zero h12, Bool.false_eq_true, ↓reduceIte] + +/-- A walk step through a table descriptor of the new block. -/ +theorem body_tab {s : BS} {v sh sl lv lv1 sh1 : U64} {t : Nat} (ht : t = T2n ∨ t = H1n) (h12 : 12 < sh.val) + (hlv : lv > 0#u64) (hm : bL.mem s sl = bwv (tabE t)) (hl : lv - 1#u64 = ok lv1) + (hs : core.num.U64.wrapping_sub sh 9#u64 = sh1) (hs1 : sh1.val < 64) : + vspace.lookup_pt_slot_loop.body bst s v sh sl lv = ok (.cont (sh1, peAF (bwv t) (idxA v sh1), lv1)) := by + have d := tabDesc_of ht + have tof : vspace.table_of (bwv (tabE t)) = ok (bwv t) := by + unfold vspace.table_of layout.pptr + simp only [lift, bind_ok] + have e : core.num.U64.wrapping_add (bwv (tabE t) &&& vspace.ADDR_MASK) layout.PPTR_BASE = + dTabA (bwv (tabE t)) := by + have b : (layout.PPTR_BASE : U64) = 18446603336221196288#u64 := by simp [layout.PPTR_BASE] + unfold dTabA dAddrA vspace.ADDR_MASK + rw [b] + rw [e, d.tab] + unfold vspace.lookup_pt_slot_loop.body + rw [if_pos hlv] + simp only [bL.read_eq, bind_ok, hm, is_table_desc h12 d.and3, ↓reduceIte, hl, lift, hs, tof, + entry_addr_eqA _ _ _ hs1] + +section runs +variable {kb ib r now mt sl v1 v2 : U64} {nc : Nat} {uw : U64 → U64} + +/-- The high-window address of `ptMapHi`'s message. -/ +scoped notation "VAhi" => (18446743936270598144#u64 : U64) +/-- `ptMapS2`'s guest-physical address `2^30`, `frameMapS2`'s `2^21`. -/ +scoped notation "IPApt" => (1073741824#u64 : U64) +scoped notation "IPAfr" => (2097152#u64 : U64) + +local notation "SR" v0 => w1vR kb ib nc r now mt sl uw v0 v1 v2 + +theorem lookupHi (P : BootLay1 kb ib nc) : + vspace.lookup_pt_slot bst (SR VAhi) (bwv HWn) VAhi = + ok { slot := peAF (bwv H1n) (idxA VAhi 30#u64), shift := 30#u64 } := by + have i39 : idxA VAhi 39#u64 = 511#u64 := by + apply UScalar.eq_of_val_eq; rw [idxA_val]; rfl + have i30 : (idxA VAhi 30#u64).val = 384 := by rw [idxA_val]; rfl + have top : vspace.TOP_LEVEL_SHIFT = 39#u64 := by simp [vspace.TOP_LEVEL_SHIFT] + have w0 : bL.mem (SR VAhi) (peAF (bwv HWn) 511#u64) = bwv (tabE H1n) := by + have v : (peAF (bwv HWn) 511#u64).val = HWn + 4088 := by + rw [peAF_valA (by rw [vHW]; norm_num) (by decide), vHW]; rfl + rw [memR_vs P (by omega) (Or.inr (by omega))] + exact w1vM_wl v + have w1 : bL.mem (SR VAhi) (peAF (bwv H1n) (idxA VAhi 30#u64)) = 0#u64 := by + have v : (peAF (bwv H1n) (idxA VAhi 30#u64)).val = H1n + 3072 := by + rw [peAF_valA (by rw [vH1]; norm_num) (by omega), vH1, i30] + exact zeroR P v (by omega) (by omega) (by omega) (by omega) + unfold vspace.lookup_pt_slot + rw [top, entry_addr_eqA _ _ _ (by simp), bind_ok, i39, + loop_cont (body_tab (t := H1n) (lv1 := 2#u64) (sh1 := 30#u64) (Or.inr rfl) (by simp) (by decide) w0 + (by rfl) (by rfl) (by simp)), + loop_done (body_zero (by simp) (by decide) w1), bind_ok] + rfl + +/-- `map_high_page_table` returns `Ok` when the window resolves, the address is in range, the walk stops at a free +level-1 slot (every argument abstract, so no literal is elaborated in the unfolded goal). -/ +theorem map_high_ok {s : BS} {slot ptr root asid va ct sl : U64} {vcap : capability.Cap} + (hct : sched.cur_thread bst s = ok ct) + (hchk : vspace.check_high_vspace bst s vcap 1#u64 = ok (core.result.Result.Ok (root, asid))) + (hlo : ¬ va < fl4_abi.consts.HIGH_VSPACE_BASE) (hhi : ¬ va ≥ fl4_abi.consts.HIGH_VSPACE_TOP) + (hlu : vspace.lookup_pt_slot bst s root va = ok { slot := sl, shift := 30#u64 }) + (hw : bL.mem s sl = 0#u64) : + ∃ s3, vspace.map_high_page_table bst s slot ptr vcap va = ok (core.result.Result.Ok (), s3) := by + have hS := LawfulStore.total (st := bst) + have dv : vspace.D_VALID = ok 1#u64 := eq_of_spec_fd P0.Consts.vspace.D_VALID.spec + have ne1 : ¬ (30#u64 : U64) = vspace.PAGE_BITS := by simp [vspace.PAGE_BITS] + have ne2 : ¬ (30#u64 : U64) = vspace.TOP_LEVEL_SHIFT := by simp [vspace.TOP_LEVEL_SHIFT] + have z : (0#u64 &&& 1#u64) = 0#u64 := rfl + suffices h : vspace.map_high_page_table bst s slot ptr vcap va ⦃ x => x.1 = core.result.Result.Ok () ⦄ by + obtain ⟨⟨a, s3⟩, e, ha⟩ := spec_exists_u h + exact ⟨s3, by rw [e]; simp only at ha; rw [ha]⟩ + unfold vspace.map_high_page_table + rw [hct, bind_ok, hchk, bind_ok] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + -- the pair `let` stays in the term: split the range checks, then bind the walk through it + split + · rename_i h; first | exact absurd h hlo | exact absurd h hhi + refine WP.spec_bind (spec_of_eq_fd hlu) ?_ + rintro lu rfl + simp only [] + rw [if_neg ne1, if_neg ne2, bL.read_eq, bind_ok, hw, dv, bind_ok] + simp only [lift, bind_ok, z] + rw [if_neg (by simp)] + step* + +/-- **`ptMapHi`'s run**: FL4 maps the unmapped table into the high window. -/ +theorem ptMapHiR (P : BootLay1 kb ib nc) : + ∃ s3, vspace.map_high_page_table bst (SR VAhi) (rsV (53 + nc + 3)) (bwv UPn) + (.HighVSpace (bwv HWn) true 3#u64) VAhi = ok (core.result.Result.Ok (), s3) := by + have base : fl4_abi.consts.HIGH_VSPACE_BASE = VAhi := by simp [fl4_abi.consts.HIGH_VSPACE_BASE] + have topv : fl4_abi.consts.HIGH_VSPACE_TOP = 18446744056529682432#u64 := by + simp [fl4_abi.consts.HIGH_VSPACE_TOP] + have w1 : bL.mem (SR VAhi) (peAF (bwv H1n) (idxA VAhi 30#u64)) = 0#u64 := by + have i30 : (idxA VAhi 30#u64).val = 384 := by rw [idxA_val]; rfl + have v : (peAF (bwv H1n) (idxA VAhi 30#u64)).val = H1n + 3072 := by + rw [peAF_valA (by rw [vH1]; norm_num) (by omega), vH1, i30] + exact zeroR P v (by omega) (by omega) (by omega) (by omega) + exact map_high_ok (curThreadR P) (checkHighR P) (by rw [base]; exact lt_irrefl _) + (by rw [topv]; scalar_tac) (lookupHi P) w1 + +theorem eptGeom40 : ept.geom 40#u64 = + ok { ipa_bits := 40#u64, top_shift := 30#u64, top_mask := 1023#u64, levels := 3#u64 } := by + unfold ept.geom + rw [if_pos (by decide)] + +/-- The Stage-2 root's slot for `ipa`. -/ +theorem eptTop (ipa i : U64) (h : (idxME ipa 30#u64 10) = i) : + ept.entry_addr (bwv S2n) ipa 30#u64 1023#u64 = ok (peAF (bwv S2n) i) := by + rw [ept_entry_addrE (k := 10) _ _ _ _ (by simp) (by simp), h] + +theorem lookupS2pt (P : BootLay1 kb ib nc) : + ept.lookup_slot bst (SR IPApt) (bwv S2n) IPApt 40#u64 = + ok { slot := peAF (bwv S2n) 1#u64, shift := 30#u64 } := by + have i1 : idxME IPApt 30#u64 10 = 1#u64 := by apply UScalar.eq_of_val_eq; rfl + have w : bL.mem (SR IPApt) (peAF (bwv S2n) 1#u64) = 0#u64 := by + have v : (peAF (bwv S2n) 1#u64).val = S2n + 8 := by + rw [peAF_valA (by rw [vS2]; norm_num) (by decide), vS2]; rfl + exact zeroR P v (by omega) (by omega) (by omega) (by omega) + unfold ept.lookup_slot + rw [eptGeom40, bind_ok] + simp only [] + rw [eptTop _ _ i1, bind_ok] + simp only [lift, bind_ok] + rw [ept_lookup_loopE, show core.num.U64.wrapping_sub 3#u64 1#u64 = 2#u64 from rfl, + loop_done (body_zero (by simp) (by decide) w), bind_ok] + rfl + +theorem lookupS2fr (P : BootLay1 kb ib nc) : + ept.lookup_slot bst (SR IPAfr) (bwv S2n) IPAfr 40#u64 = + ok { slot := peAF (bwv T2n) (idxA IPAfr 21#u64), shift := 21#u64 } := by + have i0 : idxME IPAfr 30#u64 10 = 0#u64 := by apply UScalar.eq_of_val_eq; rfl + have i21 : (idxA IPAfr 21#u64).val = 1 := by rw [idxA_val]; rfl + have w0 : bL.mem (SR IPAfr) (peAF (bwv S2n) 0#u64) = bwv (tabE T2n) := by + have v : (peAF (bwv S2n) 0#u64).val = S2n := by + rw [peAF_valA (by rw [vS2]; norm_num) (by decide), vS2]; rfl + rw [memR_vs P (by omega) (Or.inr (by omega))] + exact w1vM_s2e v + have w1 : bL.mem (SR IPAfr) (peAF (bwv T2n) (idxA IPAfr 21#u64)) = 0#u64 := by + have v : (peAF (bwv T2n) (idxA IPAfr 21#u64)).val = T2n + 8 := by + rw [peAF_valA (by rw [vT2]; norm_num) (by omega), vT2, i21] + exact zeroR P v (by omega) (by omega) (by omega) (by omega) + unfold ept.lookup_slot + rw [eptGeom40, bind_ok] + simp only [] + rw [eptTop _ _ i0, bind_ok] + simp only [lift, bind_ok] + rw [ept_lookup_loopE, show core.num.U64.wrapping_sub 3#u64 1#u64 = 2#u64 from rfl, + loop_cont (body_tab (t := T2n) (lv1 := 1#u64) (sh1 := 21#u64) (Or.inl rfl) (by simp) (by decide) w0 + (by rfl) (by rfl) (by simp)), + loop_done (body_zero (by simp) (by decide) w1), bind_ok] + rfl + +set_option backward.isDefEq.respectTransparency false in +theorem ipaLimit40 : ept.ipa_limit 40#u64 = ok 1099511627775#u64 := by + unfold ept.ipa_limit + have s40 : (1#u64 <<< 40#u64 : Result U64) = ok 1099511627776#u64 := rfl + rw [eptGeom40, bind_ok] + show (1#u64 <<< 40#u64 >>= fun i => ok (core.num.U64.wrapping_sub i 1#u64)) = _ + rw [s40] + refine (bind_tc_ok _ _).trans ?_ + rfl + +/-- **`ptMapS2`'s run.** -/ +theorem ptMapS2R (P : BootLay1 kb ib nc) {A : Type} (ar : machine.Arch A) (a : A) (hA : P0.ArchTotal ar) + (hI : ar.s2_ipa_bits a = ok 40#u64) : + ∃ s3 a3, ept.map_table bst ar (SR IPApt) a (bwv S2n) 2#u64 IPApt (bwv UPn) (rsV (53 + nc + 3)) = + ok (core.result.Result.Ok (), s3, a3) := by + have hS := LawfulStore.total (st := bst) + have dv : ept.D_VALID = ok 1#u64 := eq_of_spec_fd P0.Consts.ept.D_VALID.spec + have ne1 : ¬ (30#u64 : U64) = ept.PAGE_BITS := by simp [ept.PAGE_BITS] + have w : bL.mem (SR IPApt) (peAF (bwv S2n) 1#u64) = 0#u64 := by + have v : (peAF (bwv S2n) 1#u64).val = S2n + 8 := by + rw [peAF_valA (by rw [vS2]; norm_num) (by decide), vS2]; rfl + exact zeroR P v (by omega) (by omega) (by omega) (by omega) + have z : (0#u64 &&& 1#u64) = 0#u64 := rfl + suffices h : ept.map_table bst ar (SR IPApt) a (bwv S2n) 2#u64 IPApt (bwv UPn) (rsV (53 + nc + 3)) + ⦃ x => x.1 = core.result.Result.Ok () ⦄ by + obtain ⟨⟨c, s3, a3⟩, e, hc⟩ := spec_exists_u h + exact ⟨s3, a3, by rw [e]; simp only at hc; rw [hc]⟩ + unfold ept.map_table + rw [hI, bind_ok, ipaLimit40, bind_ok, if_neg (by scalar_tac), lookupS2pt P, bind_ok] + simp only [] + rw [if_neg ne1, bL.read_eq, bind_ok, w, dv, bind_ok] + simp only [lift, bind_ok, z] + rw [if_neg (by simp)] + step* + +/-- **`frameMapS2`'s run**: the `Large` frame maps at the shift-21 table. -/ +theorem frameMapS2R (P : BootLay1 kb ib nc) {A : Type} (ar : machine.Arch A) (a : A) (hA : P0.ArchTotal ar) + (hI : ar.s2_ipa_bits a = ok 40#u64) (attr : U64) : + ∃ s3 a3, ept.map_frame bst ar (SR IPAfr) a (bwv S2n) 2#u64 IPAfr 3#u64 attr (bwv FRn) .Large 3#u64 false 0#u64 + 0#u64 (rsV (53 + nc + 4)) = ok (core.result.Result.Ok (), s3, a3) := by + have hS := LawfulStore.total (st := bst) + suffices h : ept.map_frame bst ar (SR IPAfr) a (bwv S2n) 2#u64 IPAfr 3#u64 attr (bwv FRn) .Large 3#u64 false 0#u64 + 0#u64 (rsV (53 + nc + 4)) ⦃ x => x.1 = core.result.Result.Ok () ⦄ by + obtain ⟨⟨c, s3, a3⟩, e, hc⟩ := spec_exists_u h + exact ⟨s3, a3, by rw [e]; simp only at hc; rw [hc]⟩ + unfold ept.map_frame + have sh : capability.FrameSize.bits .Large = ok 21#u64 := rfl + have pw : (1#u64 <<< (21#u64 &&& 63#u64) : Result U64) = ok 2097152#u64 := by rfl + rw [sh, bind_ok, hI, bind_ok] + simp only [lift, bind_ok] + rw [pw, bind_ok] + rw [if_neg (show ¬ (IPAfr &&& core.num.U64.wrapping_sub 2097152#u64 1#u64) != 0#u64 by decide), + if_neg (show ¬ (0#u64 : U64) != 0#u64 by decide), bind_ok, ipaLimit40, bind_ok, + if_neg (show ¬ core.num.U64.wrapping_add IPAfr (core.num.U64.wrapping_sub 2097152#u64 1#u64) > + 1099511627775#u64 by decide), + if_neg (show ¬ core.num.U64.wrapping_add IPAfr (core.num.U64.wrapping_sub 2097152#u64 1#u64) < + IPAfr by decide), lookupS2fr P, bind_ok] + simp only [] + rw [if_neg (show ¬ (21#u64 : U64) != 21#u64 by decide)] + step* + +/-- **`ptUnmapT2`'s finality run** (`hf`): the table cap has no CDT neighbour. -/ +theorem finalT2R (P : BootLay1 kb ib nc) (v0 : U64) : + cdt.is_final_capability bst (SR v0) (rsV (53 + nc + 2)) = ok true := by + have hkb := P.kbR + have h128 := P.w0.nc128 + have xv : (rsV (53 + nc + 2)).val = newLo nc + 64 := by rw [rsV_val (by omega)]; omega + have word : ∀ o : U64, o.val < 32 → bL.mem (SR v0) (wa (rsV (53 + nc + 2)) o) = newSlotW (64 + o.val) := by + intro o ho + have v : (wa (rsV (53 + nc + 2)) o).val = newLo nc + (32 * 2 + o.val) := by + rw [wadd_val (by omega)]; omega + rw [memR_keep (by omega) (by omega), memV_new (k := 2) (by omega) ho v] + have prev : obj.Slot.prev bst (rsV (53 + nc + 2)) (SR v0) = ok 0#u64 := by + rw [slot_prev_eq, word 16#u64 (by simp)]; rfl + have next : obj.Slot.next bst (rsV (53 + nc + 2)) (SR v0) = ok 0#u64 := by + have nw : obj.Slot.next_word bst (rsV (53 + nc + 2)) (SR v0) = ok (bwv (3 * P48n)) := by + unfold obj.Slot.next_word + have e : (layout.cte.NEXT : U64) = 24#u64 := by simp [layout.cte.NEXT] + simp only [lift, bind_ok, e, bL.read_eq] + rw [word 24#u64 (by simp)]; rfl + unfold obj.Slot.next + rw [nw, bind_ok] + have m : (obj.MDB_PTR_MASK : U64) = 281474976710655#u64 := by simp [obj.MDB_PTR_MASK] + unfold obj.sext48 + simp only [lift, bind_ok, m] + rw [show (bwv (3 * P48n) &&& 281474976710655#u64) = 0#u64 from rfl, + show (0#u64 &&& 140737488355328#u64) = 0#u64 from rfl, if_neg (by decide)] + simp only [bind_ok] + unfold cdt.is_final_capability + rw [capA_eq (st := bst), bind_ok] + unfold cdt.is_final_capability_with_cap + rw [prev, bind_ok] + simp only [obj.Slot.is_null, decide_true, bind_ok, ↓reduceIte, Bool.false_eq_true, next] + +end runs + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/A64WitVsStA.lean b/proofs/Fl4ProofsA64/P3/A64WitVsStA.lean new file mode 100644 index 000000000..66442ae44 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/A64WitVsStA.lean @@ -0,0 +1,205 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line witvs, step 3 part 1): **the state `w1vS`** — `w1v`'s memory (`P3/A64WitVsLayA`) +with five new caps in the first free root CNode slots `53 + nc … 57 + nc`: + +* `0` the Stage-2 root cap (`Ept`, ASID 2), `1` the high-window cap (ASID 3), `2` the mapped Stage-2 table cap, + `3` the unmapped page-table cap, `4` an unmapped `Large` frame cap on a 2 MiB block at `NB + 2^21` (for + `frameMapS2`: `ept.map_frame` needs the walk to stop at the frame's own shift, here 21). + +Each new slot is written as `write_slot` leaves one (`PREV = 0`, `NEXT = REVOCABLE | FIRST_BADGED`). + +Proved: the cap readings of every slot of `w1OS` (**`capV_split`**: a slot holds its `w1` cap, or it is a new slot, +`Null` at `w1`), and `VsRelA` / `ExtVsRelA` at `w1vS`. + +Hypotheses: `BootLay1`; `ExtVsRelA` also [P] `s2IpaBits = 40`. New module; no existing statement changed. +-/ +import Fl4ProofsA64.P3.A64WitVsLayA +import Fl4ProofsA64.P1.BootMdb1 +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 Classical + +local notation "wa" => core.num.U64.wrapping_add + +scoped notation "RRn" => (18446604435732824064 : Nat) +/-- The `Large` frame, `NB + 2^21`. -/ +scoped notation "FRn" => (18446612132316315648 : Nat) + +theorem vFR : (bwv FRn).val = FRn := bwv_val (by norm_num) + +/-! ## The five new caps -/ + +/-- New cap `k`. -/ +def newC (k : Nat) : capability.Cap := + if k = 0 then .Ept (bwv S2n) 0#u64 true 2#u64 0#u64 else + if k = 1 then .HighVSpace (bwv HWn) true 3#u64 else + if k = 2 then .PageTable (bwv T2n) true 2#u64 0#u64 else + if k = 3 then .PageTable (bwv UPn) false 0#u64 0#u64 else + .Frame (bwv FRn) .Large 3#u64 false false false 0#u64 0#u64 + +/-- Its first cap word. -/ +def newW0 (k : Nat) : Nat := + if k = 0 then 23 * TGn + P48n + S2n % P48n else if k = 1 then 25 * TGn + P48n + HWn % P48n else + if k = 2 then 14 * TGn + P48n + T2n % P48n else if k = 3 then 14 * TGn + UPn % P48n else + 13 * TGn + P48n + 3 * 1125899906842624 + FRn % P48n + +/-- Its second cap word. -/ +def newW1 (k : Nat) : Nat := if k = 0 then 2 * P48n else if k = 1 then 3 else if k = 2 then 2 * P48n else 0 + +theorem new_dec {k : Nat} (hk : k < 5) : + CapRt.decodeF (BitVec.ofNat 64 (newW0 k)) (BitVec.ofNat 64 (newW1 k)) = newC k := by + interval_cases k <;> rfl + +theorem new_nonnull {k : Nat} : newC k ≠ .Null := by + unfold newC; split_ifs <;> exact fun e => by cases e + +/-! ## The memory and the state -/ + +/-- Word `d` of the five new slots. -/ +def newSlotW (d : Nat) : U64 := + if d % 32 = 0 then bwv (newW0 (d / 32)) else if d % 32 = 8 then bwv (newW1 (d / 32)) else + if d % 32 = 24 then bwv (3 * P48n) else 0#u64 + +/-- The first byte of new slot `0`. -/ +scoped notation:max "newLo " nc:max => (18446604435732824064 + 32 * (53 + nc) : Nat) + +/-- **`w1vS`'s memory**: the new slots over `w1vM`. -/ +def w1vFM (nc : Nat) (mem : U64 → U64) (b : U64) : U64 := + if newLo nc ≤ b.val ∧ b.val < newLo nc + 160 then newSlotW (b.val - newLo nc) else w1vM mem b + +theorem w1vFM_out {nc : Nat} {mem : U64 → U64} {b : U64} (h : b.val < newLo nc ∨ newLo nc + 160 ≤ b.val) : + w1vFM nc mem b = w1vM mem b := by + unfold w1vFM; rw [if_neg (by omega)] + +/-- **The witness state of the VS world.** -/ +def w1vS (kb ib : U64) (nc : Nat) (r now mt sl : U64) (uw : U64 → U64) : BS := + ⟨w1vFM nc (w1M kb ib nc r now mt sl uw), kb, 0#u64⟩ + +section st +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} + +local notation "S1" => w1S kb ib nc r now mt sl uw +local notation "SV" => w1vS kb ib nc r now mt sl uw + +/-- A word outside the new slots, the two pool words and the new block is `w1`'s. -/ +theorem memV_keep {b : U64} (h0 : b.val < newLo nc ∨ newLo nc + 160 ≤ b.val) (h1 : b.val ≠ PLn + 16) + (h2 : b.val ≠ PLn + 24) (h3 : b.val < S2n ∨ NEn ≤ b.val) : bL.mem SV b = bL.mem S1 b := by + show w1vFM nc _ b = _ + rw [w1vFM_out h0, w1vM_keep h1 h2 h3] + rfl + +/-- The word at offset `o` of new slot `k`. -/ +theorem memV_new {b : U64} {k o : Nat} (hk : k < 5) (ho : o < 32) (hb : b.val = newLo nc + (32 * k + o)) : + bL.mem SV b = newSlotW (32 * k + o) := by + show w1vFM nc _ b = _ + unfold w1vFM + rw [if_pos (by omega), show b.val - newLo nc = 32 * k + o by omega] + +/-- **A new slot's cap.** -/ +theorem capV_new (h128 : nc ≤ 128) {x : U64} {k : Nat} (hk : k < 5) (hx : x.val = newLo nc + 32 * k) : + capA bst SV x = newC k := by + rw [capA_w] + have e8 : (8#u64 : U64).val = 8 := by simp + have h8 : (wa x 8#u64).val = newLo nc + (32 * k + 8) := by + rw [wadd_val (by rw [e8]; omega), e8]; omega + show CapRt.decodeF (bL.mem SV x).bv (bL.mem SV (wa x 8#u64)).bv = _ + rw [memV_new (k := k) (o := 0) hk (by omega) (by omega), memV_new (k := k) (o := 8) hk (by omega) h8] + have w0 : newSlotW (32 * k + 0) = bwv (newW0 k) := by + unfold newSlotW; rw [if_pos (by omega), show (32 * k + 0) / 32 = k by omega] + have w1 : newSlotW (32 * k + 8) = bwv (newW1 k) := by + unfold newSlotW; rw [if_neg (by omega), if_pos (by omega), show (32 * k + 8) / 32 = k by omega] + rw [w0, w1] + exact new_dec hk + +/-- A 32-byte slot outside the new slots, the pool words and the new block reads its `w1` cap. -/ +theorem capV_keep {x : U64} (h0 : x.val + 32 ≤ newLo nc ∨ newLo nc + 160 ≤ x.val) + (h1 : x.val + 32 ≤ PLn + 16 ∨ PLn + 32 ≤ x.val) (h3 : x.val + 32 ≤ S2n ∨ NEn ≤ x.val) + (hw : x.val + 32 ≤ 2 ^ 64) : capA bst SV x = capA bst S1 x := by + have e8 : (8#u64 : U64).val = 8 := by simp + have h8 : (wa x 8#u64).val = x.val + 8 := by rw [wadd_val (by rw [e8]; omega), e8] + rw [capA_w, capA_w] + show CapRt.decodeF (bL.mem SV x).bv (bL.mem SV (wa x 8#u64)).bv = + CapRt.decodeF (bL.mem S1 x).bv (bL.mem S1 (wa x 8#u64)).bv + rw [memV_keep (b := x) (by omega) (by omega) (by omega) (by omega), + memV_keep (b := wa x 8#u64) (by omega) (by omega) (by omega) (by omega)] + +/-- Where the slots of `w1OS` lie: below the root-server block, in the root TCB, or in the root CNode. -/ +theorem osV_loc (P : BootLay1 kb ib nc) {x : U64} (hx : x ∈ w1OS kb ib nc) : + x.val + 32 ≤ RRn ∨ (18446604435733233664 ≤ x.val ∧ x.val + 32 ≤ 18446604435733233664 + 224) ∨ + ∃ i, i < 8192 ∧ x.val = RRn + 32 * i := by + have hib := P.ibR + have hkb := P.kbR + rcases w1OS_val P hx with ⟨t, c, i, -, hc, et, hi, -, ex⟩ | ⟨i, hi, -, ex⟩ | h | ⟨j, hj, -, ex⟩ + · exact Or.inl (by omega) + · exact Or.inr (Or.inl ⟨by omega, by omega⟩) + · exact Or.inr (Or.inr h) + · exact Or.inl (by omega) + +/-- **Every slot of `w1OS` keeps its `w1` cap, or is a new slot, `Null` at `w1`.** -/ +theorem capV_split (P : BootLay1 kb ib nc) {x : U64} (hx : x ∈ w1OS kb ib nc) : + capA bst SV x = capA bst S1 x ∨ + ∃ k, k < 5 ∧ x.val = newLo nc + 32 * k ∧ capA bst SV x = newC k ∧ capA bst S1 x = .Null := by + have h128 : nc ≤ 128 := P.w0.nc128 + rcases osV_loc P hx with h | ⟨h1, h2⟩ | ⟨i, hi, e⟩ + · exact Or.inl (capV_keep (Or.inl (by omega)) (Or.inl (by omega)) (Or.inl (by omega)) (by omega)) + · exact Or.inl (capV_keep (Or.inr (by omega)) (Or.inr (by omega)) (Or.inl (by omega)) (by omega)) + by_cases hn : 53 + nc ≤ i ∧ i < 58 + nc + · refine Or.inr ⟨i - (53 + nc), by omega, by omega, capV_new h128 (by omega) (by omega), ?_⟩ + rw [cap_root P hi e] + unfold capOf + rw [slotC_hi (by omega), tailC_big (by omega)] + · exact Or.inl (capV_keep (by omega) (Or.inl (by omega)) (Or.inl (by omega)) (by omega)) + +/-! ## The VSpace relations at `w1vS` -/ + +theorem w1v_vsRelA_st (P : BootLay1 kb ib nc) : + VsRelA w1Pp w1Tb w1Lv w1vX w1vY (bL.mem SV) kb (w1vSA kb ib nc now mt sl) := by + refine (w1v_vsRelA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P).of_mem fun b hb => ?_ + have h128 : nc ≤ 128 := P.w0.nc128 + have hk := P.w0.kbw + have hR := P.kbR + refine w1vFM_out ?_ + cases hb with + | asid hi hh => rw [atAF_valA hk hh]; omega + | pool p lo hp hl => + have e : p.val = PLn := hp + rw [peAF_valA (by omega) hl, e]; omega + | pt p i hp hi => + have e := w1Tb_val hp + rw [peAF_valA (by omega) hi]; omega + | high y i hy hi => + obtain rfl : y = bwv HWn := hy + rw [waHW, peAF_valA (by rw [vH1]; norm_num) hi, vH1]; omega + +theorem w1v_extVsRelA_st (P : BootLay1 kb ib nc) (hI : Fl4SpecA64.fl4A64Platform.s2IpaBits = 40) : + ExtVsRelA w1Pp w1Tb w1vX w1vY w1vT2 w1vSh2 (bL.mem SV) (w1vSA kb ib nc now mt sl) := by + refine (w1v_extVsRelA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) hI).of_mem fun b hb => ?_ + have h128 : nc ≤ 128 := P.w0.nc128 + refine w1vFM_out (Or.inr ?_) + cases hb with + | s2lo r i hr hi => + obtain rfl : r = bwv S2n := hr + rw [peAF_valA (by rw [vS2]; norm_num) hi, vS2]; omega + | s2hi r i hr hi => + obtain rfl : r = bwv S2n := hr + have e : (wa (bwv S2n) 4096#u64).val = S2n + 4096 := by rw [waWin_valA (by rw [vS2]; norm_num), vS2] + rw [peAF_valA (by omega) hi, e]; omega + | s2pt t i ht hi => + obtain rfl : t = bwv T2n := ht + rw [peAF_valA (by rw [vT2]; norm_num) hi, vT2]; omega + | wl0 y hy => + obtain rfl : y = bwv HWn := hy + rw [peAF_valA (by rw [vHW]; norm_num) (by decide), vHW]; omega + | wlo y i hy hi => + obtain rfl : y = bwv HWn := hy + rw [peAF_valA (by rw [vHW]; norm_num) (by omega), vHW]; omega + +end st + +end + +end Fl4ProofsA64.P3.Wit diff --git a/proofs/Fl4ProofsA64/P3/ArchTopA.lean b/proofs/Fl4ProofsA64/P3/ArchTopA.lean index 5d7afcfeb..04bd3cd22 100644 --- a/proofs/Fl4ProofsA64/P3/ArchTopA.lean +++ b/proofs/Fl4ProofsA64/P3/ArchTopA.lean @@ -93,6 +93,13 @@ theorem ArchDecTopPostA.of_archTopA {AR : A → HwRootA → Prop} {Z : XSetsA} { end post +theorem ArchDecTopPostA.errOnly {S A : Type} {st : machine.Store S} [L : LawfulStore st] {AR : A → HwRootA → Prop} + {Z : XSetsA} {OS : Set U64} {m : Fl4SpecA64.McState} {block call cd : Bool} {σ : Fl4SpecA64.State Unit} + {D : Set (Except Fl4SpecA64.SyscallError Fl4SpecA64.Fl4Invocation × Fl4SpecA64.State Unit) × Prop} + {s : S} {a : A} : ∀ {res}, ArchDecTopPostA (L := L) AR Z OS m block call cd σ D s a res → VsErrPostA σ D s a res + | (.Err _, _, _), h => h + | (.Ok (), _, _), _ => trivial + /-! ## Unified VSpace / ASID / Frame top (`decInv_arch_jA`) -/ section arch_top @@ -101,9 +108,17 @@ variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : {ia ie : Nat} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} /-- **Unified AArch64 VSpace / ASID / Frame top at `syscall.decode_invocation` against -`Fl4SpecA64.fl4DecodeInvocation`**: covers all 7 VSpace / ASID / Frame cap kinds (`Pml4`, +`Fl4SpecA64.fl4DecodeInvocation`, error outcome only** (`VsErrPostA`; its callers are the two `DecErr` records, and +the Stage-2 table unmap's success is the dedicated arm `ptUnmapT2A`): covers all 7 VSpace / ASID / Frame cap kinds (`Pml4`, `PageTable`, `Frame`, `AsidPool`, `AsidControl`, `Ept`, `HighVSpace`) across all labels (42–45, 47–59, and illegal labels). `Cap::Vcpu` is excluded (`IsArchVsCapA`). -/ +theorem ArchTopErrA.liftVs {S A : Type} {st : machine.Store S} [L : LawfulStore st] + {σ : Fl4SpecA64.State Unit} {d : Fl4SpecA64.SEMonad Unit Fl4SpecA64.Fl4ArchInvocation} {s : S} {a : A} : + ∀ {res}, ArchTopErrA σ (d.run σ) s a res → + VsErrPostA σ ((Fl4Spec.NonDetE.liftME Fl4SpecA64.Fl4Invocation.invokeArchObject d).run σ) s a res + | (.Err _, _, _), ⟨hs, ha, e', hD, hEr⟩ => ⟨hs, ha, e', run_liftME_errA hD, hEr⟩ + | (.Ok (), _, _), _ => trivial + theorem decInv_arch_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) @@ -135,17 +150,15 @@ theorem decInv_arch_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) lbl = fl4_abi.label.ARMPageMap → FrPlA sz fp mp asid) (hFrSub : ∀ fp sz rt dev mp e asid va, cap = .Frame fp sz rt dev mp e asid va → lbl = fl4_abi.label.ARMPageDeriveSubframe → sz = .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) + fp.val % 2 ^ 21 = 0 ∧ CapRt.Canonical fp) (hAsidAssign : ∀ p base, 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) : + UnmRootAssignA k (L.mem s) σ root) + (hno : FinPtNoOtherA st Z OS s) : syscall.decode_invocation st ar s a lbl length (cslotAddrA cte) cap block call cd fpb buf ex - ⦃ res => ArchDecTopPostA (L := L) AR Z OS m block call cd σ + ⦃ res => VsErrPostA σ ((Fl4SpecA64.fl4DecodeInvocation (Z := Unit) call firstPhase lbl.bv (args.map UScalar.bv) xSlot cte (absCapA cap) exs bufOpt).run σ) s a res ⦄ := by cases cap with @@ -153,30 +166,32 @@ theorem decInv_arch_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) exact WP.spec_mono (decInv_vspace_jA K E RS hTr cte hab ptr asid mp hcap lbl length buf block call cd fpb call ex args hlen hargs xSlot exs) - fun _ h => ArchDecTopPostA.of_archTopA (ArchTopPostA.of_vsTopA h) + fun _ h => ArchDecTopPostA.errOnly (block := block) (call := call) (cd := cd) + (ArchDecTopPostA.of_archTopA (ArchTopPostA.of_vsTopA (calling := call) h)) | PageTable ptr mp asid va => exact WP.spec_mono (decInv_pt_all_jA K E RS hTO hEO hK hT hIpa hPC hFI hTr hnul cte hab hos ptr asid va mp hcap lbl length buf block call cd fpb call ex args hlen hargs (exAtA ex 0) (exAtA_idx0 ex) - xSlot exs (hex.rel1 E.j.1.place) (hPtMap ptr mp asid va rfl)) - fun _ h => ArchDecTopPostA.of_archTopA (ArchTopPostA.of_vsTopA h) + xSlot exs (hex.rel1 E.j.1.place) (hPtMap ptr mp asid va rfl) hno) + fun _ h => VsErrPostA.liftME h | Frame fp sz rt dev mp e asid va => exact WP.spec_mono (decInv_frame_all_jA K E RS hvcR hTO hEO hK hT hIpa hTr hnul hcO cte hab hos fp rt asid va sz dev mp e hcap lbl length buf block call cd fpb ex args hlen hargs (exAtA ex 0) (exAtA_idx0 ex) xSlot exs (hex.rel1 E.j.1.place) (hFrMap fp sz rt dev mp e asid va rfl) (hFrSub fp sz rt dev mp e asid va rfl)) - fun _ h => ArchDecTopPostA.of_archTopA h + fun _ h => ArchTopErrA.liftVs (st := st) (s := s) (a := a) h | AsidPool p base => exact WP.spec_mono (decInv_asidPool_jA ar E RS hTr hnul cte hab hcap lbl length buf block call cd fpb call ex args xSlot exs hex (hAsidAssign p base rfl)) - fun _ h => ArchDecTopPostA.of_archTopA (ArchTopPostA.of_vsTopA h) + fun _ h => ArchDecTopPostA.errOnly (block := block) (call := call) (cd := cd) + (ArchDecTopPostA.of_archTopA (ArchTopPostA.of_vsTopA (calling := call) h)) | AsidControl => exact WP.spec_mono (decInv_asidControl_all_jA ar E RS hT hYAs hTr hnul hcO hD lbl length buf cte block call cd fpb call ex args xSlot exs hlen hargs hex) - fun _ h => ArchDecTopPostA.of_archTopA h + fun _ h => ArchDecTopPostA.errOnly (block := block) (call := call) (cd := cd) (ArchDecTopPostA.of_archTopA h) | Ept ptr lvl mp asid va => obtain ⟨_, _, hwf, _⟩ := StateRelA.getAbsA E.j.1.st hab change CapWfA (capAtA (L.mem s) (cslotAddrA cte)) at hwf @@ -184,13 +199,15 @@ theorem decInv_arch_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) have hl0 : lvl = 0#u64 := UScalar.eq_of_val_eq hwf.1 subst hl0 exact WP.spec_mono - (decInv_s2Vspace_jA K E RS hTr hIpa cte hab ptr asid va mp hcap lbl length buf block call cd + (decInv_s2Vspace_jA (σ := σ) K E RS hTr hIpa cte hab ptr asid va mp hcap lbl length buf block call cd fpb call ex args hlen hargs xSlot exs) - fun _ h => ArchDecTopPostA.of_archTopA (ArchTopPostA.of_vsTopA h) + fun _ h => ArchDecTopPostA.errOnly (block := block) (call := call) (cd := cd) + (ArchDecTopPostA.of_archTopA (ArchTopPostA.of_vsTopA (calling := call) h)) | HighVSpace ptr mp asid => exact WP.spec_mono - (decInv_highVspace_jA ar cte ptr asid mp lbl length buf block call cd fpb call ex args xSlot exs) - fun _ h => ArchDecTopPostA.of_archTopA (ArchTopPostA.of_vsTopA h) + (decInv_highVspace_jA (AR := AR) (Z := Z) (OS := OS) (m := m) (σ := σ) ar cte ptr asid mp lbl length buf block call cd fpb call ex args xSlot exs) + fun _ h => ArchDecTopPostA.errOnly (block := block) (call := call) (cd := cd) + (ArchDecTopPostA.of_archTopA (ArchTopPostA.of_vsTopA (calling := call) h)) | _ => cases harch end arch_top diff --git a/proofs/Fl4ProofsA64/P3/AsidCtrlTopA.lean b/proofs/Fl4ProofsA64/P3/AsidCtrlTopA.lean index 26282eea3..43e548b6a 100644 --- a/proofs/Fl4ProofsA64/P3/AsidCtrlTopA.lean +++ b/proofs/Fl4ProofsA64/P3/AsidCtrlTopA.lean @@ -22,9 +22,13 @@ Named premise (Architect 21:51Z D1, statement change): `hD` **[J] `DeadDrop4KA`* producer the Untyped line's `UtDropA`), replacing `ObjNamedA.disjoint_of_childless`. -/ import Fl4ProofsA64.P3.VsMakePoolA +import Fl4ProofsA64.P3.VsUniqGrowA import Fl4ProofsA64.P3.FrReplyA import Fl4ProofsA64.P3.NoChildA import Fl4ProofsA64.P3.EmptyA +import Fl4ProofsA64.P3.CnodeDelStepA +import Fl4ProofsA64.P3.EpBufA +import Fl4ProofsA64.P3.Stage3PoolJ5A open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -181,24 +185,142 @@ private theorem selectExt_bind_okA {α : Type} (a : State DetExt → AsidHighInd rintro ⟨r, s1⟩ ⟨x, hx, heq⟩ cases heq; exact hfail x hx +private theorem spNoOv_fitA {p : U64} {n : Nat} (hn : n < 64) (h : SpNoOvA p n) : (specPtr p).toNat + 2 ^ n ≤ 2 ^ 64 := by + unfold SpNoOvA at h + have hk : 2 ^ n < 2 ^ 64 := Nat.pow_lt_pow_right (by decide) hn + have h1 : (1 : Nat) ≤ 2 ^ n := Nat.one_le_two_pow + have e1 : ((1 : BitVec 64) <<< n).toNat = 2 ^ n := by + rw [BitVec.toNat_shiftLeft, show (1 : BitVec 64).toNat = 1 from rfl, Nat.shiftLeft_eq, Nat.one_mul, + Nat.mod_eq_of_lt hk] + have ha := (specPtr p).isLt + generalize (1 : BitVec 64) <<< n = y at h e1 + by_contra hc + have e2 : (specPtr p + y).toNat = (specPtr p).toNat + 2 ^ n - 2 ^ 64 := by + rw [BitVec.toNat_add, e1, Nat.mod_eq_sub_mod (by omega), Nat.mod_eq_of_lt (by omega)] + have e3 : (specPtr p + y - 1).toNat = (specPtr p + y).toNat - 1 := + BitVec.toNat_sub_of_le (by + rw [BitVec.le_def, e2] + show 1 ≤ (specPtr p).toNat + 2 ^ n - 2 ^ 64 + omega) + rw [BitVec.le_def, e3, e2] at h + omega + +private theorem foldl_upd_zeroA (L : List Int) (f : Int → Word8) (hf : ∀ i, f i = 0) (m : Word → Word8) (p a : Word) : + (L.foldl (fun m i => Function.update m (p + BitVec.ofInt 64 i) (f i)) m) a = m a ∨ + ((L.foldl (fun m i => Function.update m (p + BitVec.ofInt 64 i) (f i)) m) a = 0 ∧ + ∃ i ∈ L, a = p + BitVec.ofInt 64 i) := by + induction L generalizing m with + | nil => exact Or.inl rfl + | cons i L ih => + simp only [List.foldl_cons] + rcases ih (Function.update m (p + BitVec.ofInt 64 i) (f i)) with h | ⟨h, j, hj, e⟩ + · by_cases ha : a = p + BitVec.ofInt 64 i + · right + refine ⟨?_, i, List.mem_cons_self .., ha⟩ + rw [h, ha, Function.update_self, hf] + · left + rw [h, Function.update_of_ne ha] + · exact Or.inr ⟨h, j, List.mem_cons_of_mem _ hj, e⟩ + +/-- `storeWord p 0` zeroes the eight bytes at `p` and keeps the others. -/ +private theorem storeMem_zero_umA (um : Word → Word8) (p a : Word) : + Fl4ProofsA64.P3.Endp.storeMem um p 0 a = um a ∨ + (Fl4ProofsA64.P3.Endp.storeMem um p 0 a = 0 ∧ ∃ y : Word, y.toNat < 8 ∧ a = p + y) := by + have hf : ∀ i : Int, ((wordRsplit (0 : Word) : List Word8)).getD (7 - i.toNat) 0 = 0 := by + intro i + rw [Fl4ProofsA64.P3.Endp.wordRsplit_eq] + generalize 7 - i.toNat = k + rcases k with _ | _ | _ | _ | _ | _ | _ | _ | k <;> simp + unfold Fl4ProofsA64.P3.Endp.storeMem + rcases foldl_upd_zeroA (intUpto 0 7) + (fun i => ((wordRsplit (0 : Word) : List Word8)).getD (7 - i.toNat) 0) hf um p a with h | ⟨h, i, hi, e⟩ + · exact Or.inl h + · right + refine ⟨h, BitVec.ofInt 64 i, ?_, e⟩ + rw [Fl4ProofsA64.P3.Endp.intUpto_07] at hi + simp only [List.mem_cons, List.not_mem_nil, or_false] at hi + rcases hi with rfl | rfl | rfl | rfl | rfl | rfl | rfl | rfl <;> decide + private theorem mapMx_storeWord_exA (xs : List Word) (hal : ∀ p ∈ xs, p &&& mask 3 = 0) (ms : MachineState) : - ∃ ms', ((), ms') ∈ (NonDet.mapMx (fun p => storeWord p 0) xs ms).1 := by + ∃ ms', ((), ms') ∈ (NonDet.mapMx (fun p => storeWord p 0) xs ms).1 ∧ + ∀ a, ms'.underlyingMemory a = ms.underlyingMemory a ∨ + (ms'.underlyingMemory a = 0 ∧ ∃ p ∈ xs, ∃ y : Word, y.toNat < 8 ∧ a = p + y) := by induction xs generalizing ms with - | nil => exact ⟨ms, Set.mem_singleton _⟩ + | nil => exact ⟨ms, Set.mem_singleton _, fun a => Or.inl rfl⟩ | cons p ps ih => unfold NonDet.mapMx have hp : p &&& mask 3 = 0 := hal p (List.mem_cons_self ..) - have hsw : ∃ ms1, ((), ms1) ∈ (storeWord p 0 ms).1 := by - unfold storeWord NonDet.assert NonDet.modify - simp [hp, NonDet.bind, NonDet.pure, pure] - exact ⟨_, ⟨((), ms), Set.mem_singleton _, Set.mem_singleton _⟩⟩ - obtain ⟨ms1, hms1⟩ := hsw - obtain ⟨ms2, hms2⟩ := ih (fun q hq => hal q (List.mem_cons_of_mem p hq)) ms1 - exact ⟨ms2, ⟨((), ms1), hms1, hms2⟩⟩ + have hp' : p.toNat % 8 = 0 := by + have h := congrArg BitVec.toNat hp + rw [BitVec.toNat_and, show (mask 3 : BitVec 64).toNat = 7 from rfl, + show (7 : Nat) = 2 ^ 3 - 1 from rfl, Nat.and_two_pow_sub_one_eq_mod] at h + exact h + have hms1 : ((), { ms with underlyingMemory := Fl4ProofsA64.P3.Endp.storeMem ms.underlyingMemory p 0 }) ∈ + (storeWord p 0 ms).1 := by + rw [Fl4ProofsA64.P3.Endp.storeWord_eq ms p 0 hp'] + exact Set.mem_singleton _ + obtain ⟨ms2, hms2, hum⟩ := ih (fun q hq => hal q (List.mem_cons_of_mem p hq)) + { ms with underlyingMemory := Fl4ProofsA64.P3.Endp.storeMem ms.underlyingMemory p 0 } + refine ⟨ms2, ⟨((), _), hms1, hms2⟩, fun a => ?_⟩ + rcases hum a with h | ⟨h, q, hq, y, hy, e⟩ + · rcases storeMem_zero_umA ms.underlyingMemory p a with h1 | ⟨h1, y, hy, e⟩ + · exact Or.inl (h.trans h1) + · exact Or.inr ⟨h.trans h1, p, List.mem_cons_self .., y, hy, e⟩ + · exact Or.inr ⟨h, q, List.mem_cons_of_mem _ hq, y, hy, e⟩ -private theorem deleteObjects_exA (ptr : Word) (bits : Nat) (hal : ptr.toNat % 8 = 0) (σ : State Unit) : +private theorem uptoEnumRangeA (ptr : Word) (bits : Nat) (hfit : ptr.toNat + 2 ^ bits ≤ 2 ^ 64) (hb64 : bits < 64) + (h8 : 2 ^ bits % 8 = 0) {p : Word} + (hp : p ∈ uptoEnumStep ptr (ptr + BitVec.ofNat 64 wordSize) (ptr + 2 ^ bits - 1)) {y : Word} (hy : y.toNat < 8) : + ptr ≤ p + y ∧ p + y ≤ ptr + 2 ^ bits - 1 := by + unfold uptoEnumStep at hp + split_ifs at hp with hlt + · cases hp + · rw [List.mem_map] at hp + obtain ⟨x, hx, rfl⟩ := hp + have hws : BitVec.ofNat 64 wordSize = 8#64 := by decide + have hsub : ptr + 8#64 - ptr = 8#64 := by bv_omega + have hN : ptr + 2 ^ bits - 1 - ptr = 2 ^ bits - 1 := by bv_omega + rw [hws, hsub, hN] at hx + rw [hws, hsub] + unfold uptoEnum at hx + rw [List.mem_map] at hx + obtain ⟨k, hk, rfl⟩ := hx + rw [List.mem_range'_1] at hk + have hP : (2 ^ bits : BitVec 64).toNat = 2 ^ bits := by + rw [BitVec.toNat_pow, show (2 : BitVec 64).toNat = 2 from rfl, + Nat.mod_eq_of_lt (Nat.pow_lt_pow_right (by omega) hb64)] + have h1 : 1 ≤ 2 ^ bits := Nat.one_le_two_pow + have hP1 : (2 ^ bits - 1 : BitVec 64).toNat = 2 ^ bits - 1 := by + rw [BitVec.toNat_sub_of_le (by rw [BitVec.le_def, hP]; exact h1), hP]; rfl + have hD : ((2 ^ bits - 1 : BitVec 64) / 8#64).toNat = (2 ^ bits - 1) / 8 := by + rw [BitVec.toNat_udiv, hP1]; rfl + rw [hD] at hk + have hpl := ptr.isLt + have hyl := y.isLt + have hk' : k ≤ (2 ^ bits - 1) / 8 := by + have : (0#64 : BitVec 64).toNat = 0 := rfl + omega + have hkl : k < 2 ^ 64 := by omega + have e1 : (BitVec.ofNat 64 k * 8#64).toNat = 8 * k := by + rw [BitVec.toNat_mul, BitVec.toNat_ofNat, Nat.mod_eq_of_lt hkl, show (8#64).toNat = 8 from rfl] + rw [Nat.mod_eq_of_lt (by omega)]; omega + have e2 : (ptr + BitVec.ofNat 64 k * 8#64).toNat = ptr.toNat + 8 * k := by + rw [BitVec.toNat_add, e1, Nat.mod_eq_of_lt (by omega)] + have e3 : (ptr + BitVec.ofNat 64 k * 8#64 + y).toNat = ptr.toNat + 8 * k + y.toNat := by + rw [BitVec.toNat_add, e2, Nat.mod_eq_of_lt (by omega)] + have e4 : (ptr + 2 ^ bits - 1).toNat = ptr.toNat + 2 ^ bits - 1 := by + have e : ptr + 2 ^ bits - 1 = ptr + (2 ^ bits - 1) := by bv_omega + rw [e, BitVec.toNat_add, hP1, Nat.mod_eq_of_lt (by omega)] + omega + rw [BitVec.le_def, BitVec.le_def, e3, e4] + omega + +private theorem deleteObjects_exA (ptr : Word) (bits : Nat) (hal : ptr.toNat % 8 = 0) + (hfit : ptr.toNat + 2 ^ bits ≤ 2 ^ 64) (hb64 : bits < 64) (h8 : 2 ^ bits % 8 = 0) (σ : State Unit) : ∃ ms', ((), detype {x | ptr ≤ x ∧ x ≤ ptr + 2 ^ bits - 1} { σ with machineState := ms' }) ∈ - (deleteObjects (Z := Unit) ptr bits σ).1 := by + (deleteObjects (Z := Unit) ptr bits σ).1 ∧ + ∀ a, ms'.underlyingMemory a = σ.machineState.underlyingMemory a ∨ + (ms'.underlyingMemory a = 0 ∧ ptr ≤ a ∧ a ≤ ptr + 2 ^ bits - 1) := by have hall : ∀ p ∈ uptoEnumStep ptr (ptr + BitVec.ofNat 64 wordSize) (ptr + 2 ^ bits - 1), p &&& mask 3 = 0 := by intro p hp unfold uptoEnumStep at hp @@ -216,13 +338,18 @@ private theorem deleteObjects_exA (ptr : Word) (bits : Nat) (hal : ptr.toNat % 8 BitVec.toNat_add, BitVec.toNat_mul, show (8#64 : BitVec 64).toNat = 8 from rfl, show (0 : BitVec 64).toNat = 0 from rfl] omega - obtain ⟨ms', hms'⟩ := mapMx_storeWord_exA _ hall σ.machineState - refine ⟨ms', ?_⟩ - unfold deleteObjects doMachineOp freeMemory - refine ⟨((), { σ with machineState := ms' }), ?_, Set.mem_singleton _⟩ - refine ⟨(σ.machineState, σ), Set.mem_singleton _, ?_⟩ - refine ⟨(((), ms'), σ), ⟨hms', rfl⟩, ?_⟩ - exact ⟨((), { σ with machineState := ms' }), Set.mem_singleton _, Set.mem_singleton _⟩ + obtain ⟨ms', hms', hum⟩ := mapMx_storeWord_exA _ hall σ.machineState + refine ⟨ms', ?_, fun a => ?_⟩ + · unfold deleteObjects doMachineOp freeMemory + refine ⟨((), { σ with machineState := ms' }), ?_, Set.mem_singleton _⟩ + refine ⟨(σ.machineState, σ), Set.mem_singleton _, ?_⟩ + refine ⟨(((), ms'), σ), ⟨hms', rfl⟩, ?_⟩ + exact ⟨((), { σ with machineState := ms' }), Set.mem_singleton _, Set.mem_singleton _⟩ + · rcases hum a with h | ⟨h, q, hq, y, hy, e⟩ + · exact Or.inl h + · obtain ⟨r1, r2⟩ := uptoEnumRangeA ptr bits hfit hb64 h8 hq hy + subst e + exact Or.inr ⟨h, r1, r2⟩ private theorem retypeRegion_asidPool_memA (ptr : ObjRef) (σ : State Unit) : ([ptr], { σ with kheap := Function.update σ.kheap ptr (some (.archObj (.asidPool fun _ => none))) }) ∈ @@ -530,6 +657,38 @@ end frame_disj /-! ## `MakePool` perform tail (`s1 → s2 → s3 → s4 → s5`) on `JAtZAX`, `TreeA`, `CarryA` -/ +open Fl4SpecA64 in +/-- (vsx-D) `StateRelA.setAbsA` with the object's shape at a CNode slot: the holder is the old CNode with the one entry +updated. -/ +theorem StateRelA.setAbsShapeA {th : TypedHeapA} {kb : U64} {mem mem' : U64 → U64} {σ : State Unit} + (hR : StateRelA th mem σ) (hP : PlaceA th kb) {sl : CslotPtr} (hs : AbsSlotA th sl) {a : Fl4SpecA64.Cap} + (hca : CapRelA (capAtA mem' (cslotAddrA sl)) a) + (hcap : ∀ y, IsSlotA th y → y ≠ cslotAddrA sl → capAtA mem' y = capAtA mem y) : + ∃ o, ((), setObjA σ sl.1 o) ∈ (Fl4SpecA64.setCap (Z := Unit) a sl σ).1 ∧ StateRelA th mem' (setObjA σ sl.1 o) ∧ + SpecSlotA σ (setObjA σ sl.1 o) ∧ + ∀ r cs, σ.kheap sl.1 = some (.cnode r cs) → o = .cnode r (Function.update cs sl.2 (some a)) := by + obtain ⟨o, idx⟩ := sl + obtain ⟨p, e1, hc | ⟨ht, i, hi, e2⟩⟩ := hs + · simp only at e1 hc; subst e1 + obtain ⟨cs, hk, hwf, -⟩ := hR.cnode p _ hc + refine ⟨.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 (SpecGlobA.ofKey rfl), ?_⟩ + intro r cs' hk' + simp only at hk' + rw [hk] at hk' + obtain ⟨rfl, rfl⟩ : idx.length = r ∧ cs = cs' := by + injection Option.some.inj hk' with h1 h2 + exact ⟨h1, h2⟩ + rfl + · simp only at e1 e2; subst e1 e2 + obtain ⟨x, hk, -⟩ := hR.tcb p ht + refine ⟨.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, ?_⟩ + intro r cs' hk' + simp only at hk' + rw [hk] at hk' + cases hk' + section perform 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} @@ -987,7 +1146,54 @@ private theorem finMA_insAsidPoolA {mem1 mem2 : U64 → U64} {G : List (List U64 rw [hkeep y hy0] at ho exact hF.zfin x hx0 y hy0 hne hzx ho -set_option maxHeartbeats 2000000 in +/-- (vsx-D) The spec heap after `deleteObjects (specPtr frame) pageBits` with machine state `ms'`. -/ +def poolDelA (σ1 : Fl4SpecA64.State Unit) (ms' : Fl4SpecA64.MachineState) (frame : U64) : Fl4SpecA64.State Unit := + Fl4SpecA64.detype {q | specPtr frame ≤ q ∧ q ≤ specPtr frame + 2 ^ Fl4SpecA64.pageBits - 1} + { σ1 with machineState := ms' } + +/-- (vsx-D) `retypeRegion` of the empty ASID pool at `specPtr frame`. -/ +def poolRetA (σ3 : Fl4SpecA64.State Unit) (frame : U64) : Fl4SpecA64.State Unit := + { σ3 with kheap := Function.update σ3.kheap (specPtr frame) (some (.archObj (.asidPool fun _ => none))) } + +/-- (vsx-D) The ASID-table update of the perform's last step. -/ +def poolTabA (σ5 : Fl4SpecA64.State Unit) (i frame : U64) : Fl4SpecA64.State Unit := + { σ5 with archState := { σ5.archState with + armAsidTable := Function.update σ5.archState.armAsidTable (BitVec.ofNat 7 i.val) (some (specPtr frame)) } } + +variable (st) in +/-- **(vsx-D) What `makePool_perform_jA` also exposes**: the FL4 memory footprint of the five steps, the slot caps, +the table and pool words, and the spec outcome as three explicit updates of `σ1` with slot-only steps between them. +This is what the `JStage3A` lift (`P3/Stage3PoolA*`) needs besides `JAtZAX`. -/ +structure MakePoolExpoA (H : Heap) (OS : Set U64) (s s5 : S) (σ1 σ' : Fl4SpecA64.State Unit) + (parent dest : Fl4SpecA64.CslotPtr) (frame i base : U64) : Prop where + w : WritesIn st s s5 (fun b => W7.CapW H.tcbs {b | InOS OS b} ∅ b ∨ + (frame.val ≤ b.val ∧ b.val < frame.val + 4096) ∨ b = stA (L.curW s) ∨ b = atAF (L.ksb s) i) + /-- the same footprint from the state after the caller's restart write (no `stA curW` disjunct). -/ + w1 : WritesIn st (L.wr s (stA (L.curW s)) sched.TS_RESTART) s5 (fun b => W7.CapW H.tcbs {b | InOS OS b} ∅ b ∨ + (frame.val ≤ b.val ∧ b.val < frame.val + 4096) ∨ b = atAF (L.ksb s) i) + capP : capA st s5 (cslotAddrA parent) = .Untyped frame 12#u64 4096#u64 false + capD : capA st s5 (cslotAddrA dest) = .AsidPool frame base + capK : ∀ y ∈ OS, y ≠ cslotAddrA parent → y ≠ cslotAddrA dest → capA st s5 y = capA st s y + /-- (E0.5c) the revocable bits of the non-empty slots other than the destination are kept. -/ + revK : ∀ y ∈ OS, y ≠ cslotAddrA dest → capA st s y ≠ .Null → Fl4ProofsA64.P1.W7.R.ST.revA st s5 y = Fl4ProofsA64.P1.W7.R.ST.revA st s y + tab : L.mem s5 (atAF (L.ksb s) i) = frame + pool : ∀ lo : U64, lo.val < 512 → L.mem s5 (peAF frame lo) = 0#u64 + spec : ∃ (ms' : Fl4SpecA64.MachineState) (ko3 : Fl4SpecA64.KernelObject) (σ5 : Fl4SpecA64.State Unit), + (∀ a, ms'.underlyingMemory a = σ1.machineState.underlyingMemory a ∨ + (ms'.underlyingMemory a = 0 ∧ specPtr frame ≤ a ∧ a ≤ specPtr frame + 2 ^ Fl4SpecA64.pageBits - 1)) ∧ + SpecSlotA (poolDelA σ1 ms' frame) (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) ∧ + SpecSlotA (poolRetA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) frame) σ5 ∧ + WfKeepA (poolDelA σ1 ms' frame) (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) ∧ + WfKeepA (poolRetA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) frame) σ5 ∧ + (∀ r cs, (poolDelA σ1 ms' frame).kheap parent.1 = some (.cnode r cs) → + ko3 = .cnode r (Function.update cs parent.2 (some (absCapA (.Untyped frame 12#u64 4096#u64 false))))) ∧ + (∃ (ko5 : Fl4SpecA64.KernelObject) (b v : Bool), + σ5 = insFinA (setObjA (poolRetA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) frame) dest.1 ko5) parent dest b v ∧ + ∀ r cs, (poolRetA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) frame).kheap dest.1 = some (.cnode r cs) → + ko5 = .cnode r (Function.update cs dest.2 (some (absCapA (.AsidPool frame base))))) ∧ + σ' = poolTabA σ5 i frame + +set_option maxHeartbeats 8000000 in /-- The 5-step `MakePool` perform tail refines `setThreadState .restart` + `performAsidControlInvocation (.makePool (specPtr frame) dest parent (asidOfA base))`, preserving `JAtZAX` at `Z' = { Z with Pp := insert frame Z.Pp, G := G' }`, `TreeA` on `OS`, and `CarryA`. -/ @@ -1017,10 +1223,14 @@ theorem makePool_perform_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s (.spec (.invokeASIDControl (.makePool (specPtr frame) dest parent (asidOfA base))))).run σ1).1 ∧ ∃ Z' : XSetsA, res = (.Ok (), res.2.1, a) ∧ - Z'.Pp = insert frame Z.Pp ∧ + Z' = { Z with Pp := insert frame Z.Pp, G := Z'.G } ∧ JAtZAX (L := L) AR Z' res.2.1 a σ' m ∧ TreeA st OS Z'.G.chains Z'.G.par res.2.1 ∧ - (CarryA Z (L.mem s) σ → CarryA Z' (L.mem res.2.1) σ') ⦄ := by + (CarryA Z (L.mem s) σ → CarryA Z' (L.mem res.2.1) σ') ∧ + MakePoolExpoA st H OS s res.2.1 σ1 σ' parent dest frame i base ∧ + ((MdbInvA st Z.G.chains Z.G.par s ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Z.G.chains s ∧ HandlersActiveA st Z.G.chains s) → + (MdbInvA st Z'.G.chains Z'.G.par res.2.1 ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Z'.G.chains res.2.1 ∧ + HandlersActiveA st Z'.G.chains res.2.1)) ⦄ := by have hO := E.sys.ent.os have hRev := E.sys.sysl.sys.stz.1.2.1 have hpS := hAp.isSlot E.j.1.place @@ -1075,7 +1285,12 @@ theorem makePool_perform_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s have hspAl8 : (specPtr frame).toNat % 8 = 0 := by have := specPtr_mod frame (n := 3) (by omega) simpa [show 2 ^ 3 = 8 by decide, show frame.val % 8 = 0 by omega] using this - obtain ⟨ms', hdel⟩ := deleteObjects_exA (specPtr frame) Fl4SpecA64.pageBits hspAl8 σ1 + have hfitSp : (specPtr frame).toNat + 2 ^ 12 ≤ 2 ^ 64 := by + obtain ⟨_, _, hwf0, _⟩ := StateRelA.getAbsA E.j.1.st hAp + change CapWfA (capA st s (cslotAddrA parent)) at hwf0 + rw [hcp] at hwf0 + exact spNoOv_fitA (by omega) hwf0 + obtain ⟨ms', hdel, hdelUm⟩ := deleteObjects_exA (specPtr frame) Fl4SpecA64.pageBits hspAl8 hfitSp (by decide) (by decide) σ1 set Dset : Set Fl4SpecA64.ObjRef := {q | specPtr frame ≤ q ∧ q ≤ specPtr frame + 2 ^ Fl4SpecA64.pageBits - 1} set σ2 : Fl4SpecA64.State Unit := Fl4SpecA64.detype Dset { σ1 with machineState := ms' } have hdet_inv : ∀ q ko, σ2.kheap q = some ko → σ1.kheap q = some ko := fun q ko h => by @@ -1130,7 +1345,7 @@ theorem makePool_perform_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s rw [hcp1] at h; exact h.symm have hmax_eq : Fl4SpecA64.maxFreeIndexUpdate ap = absCapA (.Untyped frame 12#u64 4096#u64 false) := by rw [hap_eq]; rfl - obtain ⟨ko3, hset3, hR3, hSS3⟩ := StateRelA.setAbsA (mem' := L.mem s2) hR_detype (hks1 ▸ E1.j.1.place) hAp + obtain ⟨ko3, hset3, hR3, hSS3, hSh3⟩ := StateRelA.setAbsShapeA (mem' := L.mem s2) hR_detype (hks1 ▸ E1.j.1.place) hAp (a := Fl4SpecA64.maxFreeIndexUpdate ap) (by show CapRelA (capA st s2 _) _ @@ -1367,10 +1582,14 @@ theorem makePool_perform_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s TreeA st OS (insG (cslotAddrA parent) (cslotAddrA dest) Z.G.chains) (insGA Z.G (cslotAddrA parent) (cslotAddrA dest) (insBA σ4 parent (absCapA (.AsidPool frame base)) (absCapA (capA st s3 (cslotAddrA parent))))).par s4 ∧ - SpecSlotA σ4 σ5) ∧ + SpecSlotA σ4 σ5 ∧ WfKeepA σ4 σ5 ∧ + ∃ (ko5 : Fl4SpecA64.KernelObject) (b v : Bool), σ5 = insFinA (setObjA σ4 dest.1 ko5) parent dest b v ∧ + ∀ r cs, σ4.kheap dest.1 = some (.cnode r cs) → + ko5 = .cnode r (Function.update cs dest.2 (some (absCapA (.AsidPool frame base))))) ∧ WritesIn st s3 s4 (W7.CapW H.tcbs {b | InOS OS_is b} ∅) ∧ (∀ y ∈ OS, y ≠ cslotAddrA dest → capA st s4 y = capA st s3 y) ∧ - capA st s4 (cslotAddrA dest) = .AsidPool frame base ⦄ := by + capA st s4 (cslotAddrA dest) = .AsidPool frame base ∧ + (∀ y ∈ OS, y ≠ cslotAddrA dest → Fl4ProofsA64.P1.W7.R.ST.revA st s4 y = Fl4ProofsA64.P1.W7.R.ST.revA st s3 y) ⦄ := by unfold cdt.insert; rw [capA_eq, bind_ok] have F3 := hTr3.lk.lkF hO.nz have inOS3 : ∀ y ∈ Z.G.chains.flatten, y ∈ OS := fun y hy => ((hTr3.lk.members y).1 hy).1 @@ -1440,7 +1659,7 @@ theorem makePool_perform_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s unfold Fl4SpecA64.setUntypedCapAsFull rw [if_neg (fun h => hnotFull ((utCondA_iff _ _).1 h))] exact Set.mem_singleton _ - obtain ⟨ko5, hset5, hR5, hSS5⟩ := StateRelA.setAbsA (mem' := L.mem s4) hR4 hP3 hAd + obtain ⟨ko5, hset5, hR5, hSS5, hSh5⟩ := StateRelA.setAbsShapeA (mem' := L.mem s4) hR4 hP3 hAd (a := absCapA (.AsidPool frame base)) (by show CapRelA (capA st s4 _) _; rw [ed]; exact ⟨hbaseWf, CapEqA.of_abs rfl⟩) (fun y hy hne => hkeep4 y (RS.sub y hy) hne) @@ -1464,9 +1683,40 @@ theorem makePool_perform_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s · rw [if_pos e, e, ← hv]; exact revA_of_val hdb · rw [if_neg e] exact revA_of_keep (hb _ (RS.sub _ (hsl.isSlot hP3)) (fun h => e (cslotAddrA_inj hP3 hsl hAd h))) - exact ⟨⟨_, hmem5, hR5.of_kheap rfl, hC5, hT4, hSS5.trans (SpecSlotA.insFin _ _ _ _ _)⟩, - h1.1, hkeep4, ed⟩ - refine WP.spec_bind hInsAll fun s4 ⟨⟨σ5, hins5, hR5, hC5, hT5, hSS5⟩, hw4, hkeep4, hsd4⟩ => ?_ + exact ⟨⟨_, hmem5, hR5.of_kheap rfl, hC5, hT4, hSS5.trans (SpecSlotA.insFin _ _ _ _ _), + (setCap_wfA _ _ _ _ hset5).trans (WfKeepA.of_kheap rfl), ko5, _, _, rfl, hSh5⟩, + h1.1, hkeep4, ed, fun y hy hne => by + have hbk := hb y hy hne + unfold Fl4ProofsA64.P1.W7.R.ST.revA + exact congrArg (fun w => w != 0#u64) hbk⟩ + -- J5 (group J5): the chain facts at `s3`, across the insert + have hrev0 : Fl4ProofsA64.P1.W7.R.ST.revA st s (cslotAddrA parent) = true := + revA_of_revocableA (hRev _ hpO (by rw [hcp]; rfl)) + have hmemSl : ∀ y ∈ Z.G.chains.flatten, IsSlotA Z.th y := fun y hy => by + by_contra hn + exact ((hTr.lk.members y).1 hy).2 (hnul y ((hTr.lk.members y).1 hy).1 hn) + have h24_3 : ∀ y, IsSlotA Z.th y → L.mem s3 (wa y 24#u64) = L.mem s (wa y 24#u64) := fun y hy => + (hzr_slot y hy 24#u64 (by decide) (by decide)).trans + (((set_cap_links hO hpO y (RS.sub y hy)).2).trans (hOS1 y (RS.sub y hy)).2.2.2) + have hcapS3 : ∀ y ∈ Z.G.chains.flatten, y ≠ cslotAddrA parent → capA st s3 y = capA st s y := fun y hy hne => by + have hyO := ((hTr.lk.members y).1 hy).1 + rw [hcap3_all y hyO, hko2 y hyO hne, hOS1.capA hyO] + have hJ3 : (MdbInvA st Z.G.chains Z.G.par s ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Z.G.chains s ∧ HandlersActiveA st Z.G.chains s) → + MdbInvA st Z.G.chains Z.G.par s3 ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Z.G.chains s3 := fun hJ => + poolJ5_keepA hTr.lk hTr.tree hJ.1 hJ.2.1 (src := cslotAddrA parent) (p := frame) (sb := 12#u64) (i := fi) + (i' := 4096#u64) (d := false) (d' := false) hcapS3 hcp hcp3 (fun y hy => h24_3 y (hmemSl y hy)) + have hrev3 : Fl4ProofsA64.P1.W7.R.ST.revA st s3 (cslotAddrA parent) = true := by + rw [revA_congr (h24_3 _ hpS)]; exact hrev0 + have hInsJ5 : (MdbInvA st Z.G.chains Z.G.par s ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Z.G.chains s ∧ HandlersActiveA st Z.G.chains s) → + cdt.insert st s3 (.AsidPool frame base) (cslotAddrA parent) (cslotAddrA dest) ⦃ s4 => + MdbInvA st (insG (cslotAddrA parent) (cslotAddrA dest) Z.G.chains) + (insParA Z.G.par (cslotAddrA parent) (cslotAddrA dest) true) s4 ∧ + Fl4ProofsA64.P1.W7.R.ST.IrqRunA st (insG (cslotAddrA parent) (cslotAddrA dest) Z.G.chains) s4 ⦄ := fun hJ => by + obtain ⟨hI3, hR3⟩ := hJ3 hJ + unfold cdt.insert; rw [capA_eq, bind_ok] + exact WP.spec_mono (poolJ5_insA hO hTr3 hI3 hR3 hpO hdO hcp3 hcd3 (hcO _ hdO) hwAp hrev3 hnd1) fun _ h => ⟨h.1, h.2.1⟩ + refine WP.spec_bind (spec_and_impA hInsAll hInsJ5) + fun s4 ⟨⟨⟨σ5, hins5, hR5, hC5, hT5, hSS5, hWf5, hShape5⟩, hw4, hkeep4, hsd4, hrv4⟩, hJ4imp⟩ => ?_ -- Step 5: `vspace.set_asid_table s4 i frame` have hks4 : L.ksb s4 = L.ksb s := hw4.1.trans hks3 have hcpu4 : L.cpu s4 = L.cpu s := hw4.2.1.trans hcpu3 @@ -2200,11 +2450,106 @@ theorem makePool_perform_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s have hfv := congrArg UScalar.val hEq rcases hdisj y 8192 (Or.inr (Or.inl ⟨rfl, Or.inr hy⟩)) with h | h <;> omega · exact hExt1.ypp y hy hp0 + -- `VsUniqA` across installing the empty pool `frame` (`VsUniqA.of_poolGrow`) + have hnone : σ1.archState.armAsidTable hiBv = none := by + have h := E.j.1.vs.table i hi + rw [hfree] at h + exact h.trans (by unfold optPtrA; simp) + have hz1 : L.mem s1 (atAF (L.ksb s1) i) = 0#u64 := by + by_contra hne + have h := E1.j.1.vs.table i hi + rw [hnone] at h + unfold optPtrA at h; rw [if_neg hne] at h; cases h + have hkhEqP : ∀ p ∈ Z.Pp, σ6.kheap (specPtr p) = σ1.kheap (specPtr p) := fun p hp0 => by + obtain ⟨f1, hf1, -⟩ := E1.j.1.vs.pool p hp0 + have hneP : specPtr p ≠ specPtr frame := hkh4_ne p 4096 (by omega) (Or.inl ⟨rfl, Or.inl hp0⟩) + exact hkh6_nonSlot (specPtr p) + (not_mem_detype_of_disjA (by omega) hfrAl hfrFit (hdisj p 4096 (Or.inl ⟨rfl, Or.inl hp0⟩))) + hneP (fun _ _ h => by rw [hf1] at h; cases h) (fun _ h => by rw [hf1] at h; cases h) + have hneHiG : ∀ asid : Fl4SpecA64.Asid, σ1.archState.armAsidTable (Fl4SpecA64.asidHighBitsOf asid) ≠ none → + Fl4SpecA64.asidHighBitsOf asid ≠ hiBv := fun asid h he => h (by rw [he]; exact hnone) + have hS2gen : ∀ (asid : Fl4SpecA64.Asid) (p : U64) (f : Fl4SpecA64.AsidPool), p ∈ insert frame Z.Pp → + σ6.archState.armAsidTable (Fl4SpecA64.asidHighBitsOf asid) = some (specPtr p) → + σ6.kheap (specPtr p) = some (.archObj (.asidPool f)) → + (∃ r', f (Fl4SpecA64.asidLowBitsOf asid) = some (.asidPoolVSpace r')) → + p ∈ Z.Pp ∧ σ1.archState.armAsidTable (Fl4SpecA64.asidHighBitsOf asid) = some (specPtr p) ∧ + σ1.kheap (specPtr p) = some (.archObj (.asidPool f)) := by + intro asid p f hp htab hkh6 hex + rcases Set.mem_insert_iff.1 hp with rfl | hp0 + · obtain ⟨f0, hkhF, -⟩ := hVs6.pool p (Set.mem_insert p Z.Pp) + have h54 : σ5.kheap (specPtr p) = σ4.kheap (specPtr p) := by + rcases hSS5.kh (specPtr p) with h | ⟨_, _, _, h1, _⟩ | ⟨_, _, h1, _, _⟩ + · exact h + · simp [σ4] at h1 + · simp [σ4] at h1 + have hkhF' : σ6.kheap (specPtr p) = some (.archObj (.asidPool (fun _ => none))) := by + simpa [σ6, σ4] using h54 + rw [hkhF'] at hkh6 + cases hkh6 + obtain ⟨r', hf⟩ := hex + simp at hf + · obtain ⟨f1, hf1, -⟩ := E1.j.1.vs.pool p hp0 + have hneP : specPtr p ≠ specPtr frame := hkh4_ne p 4096 (by omega) (Or.inl ⟨rfl, Or.inl hp0⟩) + rw [hkhEqP p hp0] at hkh6 + have hneHi : Fl4SpecA64.asidHighBitsOf asid ≠ hiBv := by + intro he + simp only [σ6, he, Function.update_self] at htab + exact hneP (Option.some.inj htab).symm + simp only [σ6, Function.update_of_ne hneHi, hGlob5.asid] at htab + exact ⟨hp0, htab, hkh6⟩ + have hVsu6 : VsUniqA Z.th (insert frame Z.Pp) Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s5) (L.ksb s5) σ6 := by + rw [hks51] + refine E1.j.1.vsu.of_poolGrow E1.j.1.ext.xal ?_ ?_ ?_ ?_ ?_ ?_ ?_ ?_ + · intro b hb + rcases hb with ⟨r, k, hr, hk⟩ | ⟨r, k, hr, hk⟩ | ⟨t, k, ht, hk⟩ | ⟨y, hy⟩ | ⟨y, k, hy, hk⟩ + · exact hfn_s5 _ (.ext _ (.s2lo r k hr hk)) + (fun e => hT r k hk (Or.inl (Or.inr ⟨r, hr, Or.inl rfl⟩)) (e ▸ hAsI)) + · exact hfn_s5 _ (.ext _ (.s2hi r k hr hk)) + (fun e => hT (wa r 4096#u64) k hk (Or.inl (Or.inr ⟨r, hr, Or.inr rfl⟩)) (e ▸ hAsI)) + · exact hfn_s5 _ (.ext _ (.s2pt t k ht hk)) + (fun e => hT t k hk (Or.inl (Or.inl ht)) (e ▸ hAsI)) + · exact hfn_s5 _ (.ext _ (.wl0 y hy)) + (fun e => hYAs y hy 511#u64 (by decide) (e ▸ hAsI)) + · exact hfn_s5 _ (.ext _ (.wlo y k hy hk)) + (fun e => hYAs y hy k (by omega) (e ▸ hAsI)) + · intro t k htab hk + rcases htab with ht | ⟨y, hy, rfl⟩ + · exact hfn_s5 _ (.vs _ (.pt t k ht hk)) (fun e => E.vsLeafA.2.1 t ht k hk (e ▸ hAsI)) + · exact hfn_s5 _ (.vs _ (.high y k hy hk)) + (fun e => hT (wa y 4096#u64) k hk (Or.inr (Or.inr (Or.inr ⟨y, hy, rfl⟩))) (e ▸ hAsI)) + · intro a raw h + rw [← hks51] at h + exact hActR51 a raw h + · rintro a raw ⟨hi', lo, hhi', hlo, ha', pool, hp, hpne, htab, hw, hrne⟩ + have he : hi' ≠ i := fun e => by subst e; exact hpne (htab.symm.trans hz1) + refine ⟨hi', lo, hhi', hlo, ha', pool, Set.mem_insert_of_mem _ hp, hpne, ?_, ?_, hrne⟩ + · rw [hks1, hfn_s5 _ (by rw [← hks1]; exact .vs _ (.asid hi' hhi')) (hAtNeAt hi' hhi' he), ← hks1] + exact htab + · rw [hfn_s5 _ (.vs _ (.pool pool lo hp hlo)) (fun e => E.vsLeafA.2.2 pool hp lo hlo (e ▸ hAsI))] + exact hw + · rintro r ⟨hr, asid, p, f, ha0, hp, htab, hkh6, hf⟩ + obtain ⟨hp0, ht1, hk1⟩ := hS2gen asid p f hp htab hkh6 ⟨_, hf⟩ + exact ⟨hr, asid, p, f, ha0, hp0, ht1, hk1, hf⟩ + · rintro a r ⟨hr, p, f, ha0, hp, htab, hkh6, hf⟩ + obtain ⟨hp0, ht1, hk1⟩ := hS2gen _ p f hp htab hkh6 ⟨_, hf⟩ + exact ⟨hr, p, f, ha0, hp0, ht1, hk1, hf⟩ + · rintro a r ⟨hr, p, f, ha0, hp, htab, hkh6, hf⟩ + have hne : Fl4SpecA64.asidHighBitsOf (BitVec.ofNat 16 a.val) ≠ hiBv := + hneHiG _ (by rw [htab]; exact fun h => by cases h) + refine ⟨hr, p, f, ha0, Set.mem_insert_of_mem _ hp, ?_, ?_, hf⟩ + · simp only [σ6, Function.update_of_ne hne, hGlob5.asid]; exact htab + · rw [hkhEqP p hp]; exact hkh6 + · exact PtClosedA.of_cap fun y hy => by + rcases hcap5_cases y hy with h | h | h + · exact Or.inl h + · exact Or.inr (by rw [h]; exact ⟨(fun _ _ _ _ e => by cases e), NoRootKindA.untyped _ _ _ _⟩) + · exact Or.inr (by rw [h]; exact ⟨(fun _ _ _ _ e => by cases e), + NoRootKindA.of_ne (fun _ _ _ e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ _ e => by cases e)⟩) -- Cap-based fields (`cv`, `pml`, `VcpuCoreA.cap`, `Stage2CoreA.cap`, `HighVSpaceCoreA.cap`) have hJAt6 : JAtZA (L := L) AR Z' s5 a σ6 m := by refine ⟨⟨hSt6, hCdt6, hSch6, E1.j.1.ar, hks51.symm ▸ E1.j.1.place, hIrq6, hRest6⟩, E1.j.1.thT, E1.j.1.csN, ?_, ?_, ?_, ?_, hks51.symm ▸ E1.j.1.ksFit, E1.j.1.scOffD, - ?_, ?_, hVs6, hExt6⟩ + ?_, ?_, hVs6, hExt6, hVsu6⟩ · intro c hc; rw [hnode51 c hc _ (Or.inr (Or.inl rfl))]; exact E1.j.1.idleT c hc · intro c hc; rw [hnode51 c hc _ (Or.inr (Or.inr (Or.inr rfl)))]; exact E1.j.1.idleC c hc · intro c hc; rw [hnode51 c hc _ (Or.inl rfl)]; exact E1.j.1.curT c hc @@ -2482,7 +2827,82 @@ theorem makePool_perform_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s rw [hcap5m y hy] at ho exact hfm4.zfin x hx y hy hne hzx ho⟩ exact ⟨hC.2.kt.of_typesA hty.1 hty.2, hfm5⟩ - exact (WP.spec_ok _).2 ⟨σ1, hset, σ6, [], hperf, Z', rfl, rfl, hJ6, hTr5, hCarry⟩ + have hExpo : MakePoolExpoA st H OS s s5 σ1 σ6 parent dest frame i base := by + have sA : Aligned (stA (L.curW s)) := by + rw [stA_eq]; exact field_aligned (E.sq.tcbs _ E.sq.curT) (by simp) (by simp) + have hW1 : WritesIn st s1 s5 (fun b => W7.CapW H.tcbs {b | InOS OS b} ∅ b ∨ + (frame.val ≤ b.val ∧ b.val < frame.val + 4096) ∨ b = atAF (L.ksb s) i) := by + refine ⟨hks5.trans hks1.symm, hcpu5.trans hcpu1.symm, fun b hb hn => ?_⟩ + have hnC : ¬ W7.CapW H.tcbs {b | InOS OS b} ∅ b := fun h => hn (Or.inl h) + have hnF : ¬ (frame.val ≤ b.val ∧ b.val < frame.val + 4096) := fun h => hn (Or.inr (Or.inl h)) + have hnA : b ≠ atAF (L.ksb s) i := fun h => hn (Or.inr (Or.inr h)) + have hnotCapIs : ¬ W7.CapW H.tcbs {b | InOS OS_is b} ∅ b := fun hc => + hnC (hc.imp id fun ⟨⟨y, hy, h1, h2⟩, h3⟩ => ⟨⟨y, hy.1, h1, h2⟩, h3⟩) + have h54 : L.mem s5 b = L.mem s4 b := L.mem_wr_ne hAtAl hb (fun e => hnA (UScalar.eq_of_val_eq e).symm) + have h43 : L.mem s4 b = L.mem s3 b := hw4.2.2 b hb hnotCapIs + have h32 : L.mem s3 b = L.mem s2 b := hzr_off b hb hnF + have h21 : L.mem s2 b = L.mem s1 b := by + have ha0 := hO.al0 hpO + have ha8 := hO.al hpO (k := 8#u64) (by simp) (by simp) + have hne0 : (cslotAddrA parent).val ≠ b.val := fun e => + hnC (Or.inr ⟨by rw [← UScalar.eq_of_val_eq e]; exact ⟨_, hpO, by omega, by omega⟩, by simp⟩) + have hne8 : (wa (cslotAddrA parent) 8#u64).val ≠ b.val := fun e => + hnC (Or.inr ⟨by rw [← UScalar.eq_of_val_eq e]; refine ⟨_, hpO, ?_, ?_⟩ <;> rw [wa_valP, show (8#u64 : U64).val = 8 from rfl] <;> have := hO.fit _ hpO <;> omega, by simp⟩) + rw [L.mem_wr_ne ha8 hb hne8, L.mem_wr_ne ha0 hb hne0] + rw [h54, h43, h32, h21] + refine ⟨⟨hks5, hcpu5, fun b hb hn => ?_⟩, hW1, ?_, ?_, ?_, ?_, hAtWr, hpool5, ?_⟩ + · exact (hW1.2.2 b hb (fun h => hn (h.elim Or.inl fun h => Or.inr (h.elim Or.inl fun h => Or.inr (Or.inr h))))).trans + (L.mem_wr_ne sA hb (fun e => hn (Or.inr (Or.inr (Or.inl (UScalar.eq_of_val_eq e).symm))))) + · rw [hcap5_eq _ hpO, hkeep4 _ hpO (fun e => hne_pd e.symm), hcp3] + · rw [hcap5_eq _ hdO, hsd4] + · intro y hy hyp hyd + rw [hcap5_eq y hy, hkeep4 y hy hyd, hcap3_all y hy, hko2 y hy hyp, hOS1.capA hy] + · intro y hy hyd hnn + have hyG : y ∈ Z.G.chains.flatten := (hTr.lk.members y).2 ⟨hy, hnn⟩ + have ha24 := hO.al hy (k := 24#u64) (by simp) (by simp) + have e54 : L.mem s5 (wa y 24#u64) = L.mem s4 (wa y 24#u64) := + L.mem_wr_ne hAtAl ha24 (hAtOffOS y hy 24#u64 (by decide)) + rw [revA_congr e54, hrv4 y hy hyd, revA_congr (h24_3 y (hmemSl y hyG))] + · exact ⟨ms', ko3, σ5, hdelUm, hSS3, hSS5, setCap_wfA _ _ _ _ hset3, hWf5, (fun r cs hk => by rw [hSh3 r cs hk, hmax_eq]), hShape5, rfl⟩ + -- J5 at `s5` + have hirq5 : ∀ j : U64, j.val < 5376 → L.mem s5 (irqStAddrA (L.ksb s) j) = L.mem s (irqStAddrA (L.ksb s) j) := by + intro j hj + have eI : irqStAddrA (L.ksb s) j = irqWordA (L.ksb s) j := rfl + rw [eI] + have hfn : FootNA (L := L) Z s1 (irqWordA (L.ksb s) j) := by rw [← hks1]; exact .irq j hj + have hne : irqWordA (L.ksb s) j ≠ atAF (L.ksb s) i := fun e => by + have h := congrArg UScalar.val e + rw [irqWordA_val hksFit hj, atAF_valA hksFit hi] at h; omega + rw [hfn_s5 _ hfn hne] + have O := E.stOffA RS.vc + have hsA : Aligned (stA (L.curW s)) := by + rw [stA_eq]; exact field_aligned (E.sq.tcbs _ E.sq.curT) (by simp) (by simp) + have hal : Aligned (irqWordA (L.ksb s) j) := + FootNA.aligned E.j.1 (bxi_nodes E.sys.ent.bxi) E.scAl E.ap.vcAl _ (.irq j hj) + exact L.mem_wr_ne hsA hal (fun e => + O.om _ (Or.inr (Or.inr (Or.inl ⟨j, hj, rfl⟩))) (UScalar.eq_of_val_eq e).symm) + have hG'par : G'.par = insParA Z.G.par (cslotAddrA parent) (cslotAddrA dest) true := by + simp only [G', insGA, insParA, hInsB] + have hJ5imp : (MdbInvA st Z.G.chains Z.G.par s ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Z.G.chains s ∧ HandlersActiveA st Z.G.chains s) → + (MdbInvA st G'.chains G'.par s5 ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st G'.chains s5 ∧ HandlersActiveA st G'.chains s5) := by + intro hJ + obtain ⟨hI4, hR4⟩ := hJ4imp hJ + have hI4' : MdbInvA st G'.chains G'.par s4 := by rw [hG'par]; exact hI4 + obtain ⟨hI5, hR5'⟩ := poolJ5_keepEqA hT5.lk hT5.tree hI4' hR4 + (fun y hy => hcap5_eq y ((hT5.lk.members y).1 hy).1) + (fun y hy => by + have hyO := ((hT5.lk.members y).1 hy).1 + have ha24 := hO.al hyO (k := 24#u64) (by simp) (by simp) + exact L.mem_wr_ne hAtAl ha24 (hAtOffOS y hyO 24#u64 (by decide))) + refine ⟨hI5, hR5', poolJ5_handlersA (frame := frame) (base := base) hJ.2.2 hpG3 (fun y hy j h => ?_) ?_ hks5 hirq5⟩ + · have hyO := ((hTr.lk.members y).1 hy).1 + have hyd : y ≠ cslotAddrA dest := fun e => hdG3 (e ▸ hy) + rw [hcap5_eq y hyO, hkeep4 y hyO hyd] at h + by_cases e : y = cslotAddrA parent + · rw [e, hcp3] at h; cases h + · rw [hcapS3 y hy e] at h; exact h + · exact (hcap5_eq _ hdO).trans hsd4 + exact (WP.spec_ok _).2 ⟨σ1, hset, σ6, [], hperf, Z', rfl, rfl, hJ6, hTr5, hCarry, hExpo, hJ5imp⟩ end perform @@ -2761,7 +3181,7 @@ theorem decInv_asidControl_all_jA (ar : machine.Arch A) simp only [lift, bind_ok, eq_of_spec_fd hsh12] have hperf := makePool_perform_jA E RS hT hYAs hTr hnul hcO hAp hAd hcu' hncOk hdn hiLt (hiZ hiLt) hbaseVal (hD _ ptr fi hcu' hncOk) - refine WP.spec_mono hperf fun res ⟨σ1, hset, σ', rv, hp, Z', hresEq, _, hJ', hT', hC'⟩ => ?_ + refine WP.spec_mono hperf fun res ⟨σ1, hset, σ', rv, hp, Z', hresEq, _, hJ', hT', hC', _⟩ => ?_ rcases res with ⟨r, s', a'⟩ rcases hresEq with ⟨rfl, rfl, rfl⟩ have ⟨_, _, hbaseSpec⟩ := asid_high_low_of_shl9A hiLt hbaseVal diff --git a/proofs/Fl4ProofsA64/P3/CapInsSpecQA.lean b/proofs/Fl4ProofsA64/P3/CapInsSpecQA.lean new file mode 100644 index 000000000..c4203c20e --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/CapInsSpecQA.lean @@ -0,0 +1,158 @@ +/- +P3 (AArch64, E0.5c): **the spec side of one `cap_insert`**, as the facts `JStage3A.of_capDerivA` asks of the spec +step, stated once (the CNode Copy arm proves them inline; the n-fold `DeriveSubframe` loop needs them per step). + +* `capInsert_specQA`: for a `cap_insert a ss sd` at a spec state whose slot `ss` holds `asc` and whose `sd` is a + slot of a live object: the well-formed-CNode keep (`WfKeepA`), the machine state, the CDT / original-flag + provenance (`hcdt` / `horig` shapes of `of_capDerivA`), the original bit is set only at `sd`, and every cap after + is a cap before, the new cap at `sd`, or `maxFreeIndexUpdate asc` at `ss`. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3CnInsA +import Fl4ProofsA64.P3.Stage3ArmCnMoveA +import Fl4ProofsA64.P3.IpcXferLoopA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Endp Fl4SpecA64 Classical + +noncomputable section + +/-- **The spec side of one `cap_insert`** (module docstring). -/ +theorem capInsert_specQA {σ σ2 : Fl4SpecA64.State Unit} {a asc : Fl4SpecA64.Cap} {ss sd : Fl4SpecA64.CslotPtr} + (hgs : (getCap (Z := Unit) ss σ).1 = {(asc, σ)}) (hgd : ∀ x ∈ (getCap (Z := Unit) sd σ).1, x.2 = σ) + (hm : ((), σ2) ∈ (Fl4SpecA64.capInsert (Z := Unit) a ss sd σ).1) (HS : SpecSlotA σ σ2) + (hks : σ.kheap ss.1 ≠ none) (hkd : σ.kheap sd.1 ≠ none) : + WfKeepA σ σ2 ∧ σ2.machineState = σ.machineState ∧ + (∀ x y, σ2.cdt x = some y → ∀ sl, sl = x ∨ sl = y → + σ.kheap sl.1 ≠ none ∨ ∃ x0 y0, σ.cdt x0 = some y0 ∧ (sl = x0 ∨ sl = y0)) ∧ + (∀ p, σ2.isOriginalCap p = true → σ.kheap p.1 ≠ none ∨ σ.isOriginalCap p = true) ∧ + (∀ p, σ2.isOriginalCap p = true → σ.isOriginalCap p = true ∨ p = sd) ∧ + (∀ sl c, specCapAtA σ2 sl = some c → + specCapAtA σ sl = some c ∨ (sl = sd ∧ c = a) ∨ (sl = ss ∧ c = maxFreeIndexUpdate asc)) := by + obtain ⟨σa, σb, v, h1, h2, ecdt, eorig, ekh⟩ := capInsert_outA hgs hgd hm + obtain ⟨c2, o2, -⟩ := setCap_keepsA h2 + have A1 : σa.cdt = σ.cdt ∧ σa.isOriginalCap = σ.isOriginalCap ∧ WfKeepA σ σa ∧ + ∀ p o', σa.kheap p = some o' → ∃ o, σ.kheap p = some o ∧ + (∀ b c, Fl4SpecA64.capOf o' b = some c → ((p, b) = ss ∧ c = maxFreeIndexUpdate asc) ∨ + Fl4SpecA64.capOf o b = some c) ∧ + ∀ n, (∃ cs, o' = .cnode n cs ∧ wellFormedCnodeN n cs) ↔ (∃ cs, o = .cnode n cs ∧ wellFormedCnodeN n cs) := by + rcases h1 with rfl | h1 + · exact ⟨rfl, rfl, WfKeepA.of_kheap rfl, fun p o h => ⟨o, h, fun _ _ h => Or.inr h, fun _ => Iff.rfl⟩⟩ + · obtain ⟨c1, o1, -⟩ := setCap_keepsA h1 + exact ⟨c1, o1, setCap_wfA _ _ _ _ h1, setCap_objsA h1⟩ + have W : WfKeepA σ σ2 := (A1.2.2.1.trans (setCap_wfA _ _ _ _ h2)).trans (WfKeepA.of_kheap ekh) + have ec : σ2.cdt = Function.update σ.cdt sd (if v then some ss else σ.cdt ss) := by + rw [ecdt, c2, A1.1] + have eo : σ2.isOriginalCap = Function.update σ.isOriginalCap sd + (decide (Fl4SpecA64.isCapRevocable a asc)) := by + rw [eorig, o2, A1.2.1] + have kk : ∀ r : Fl4SpecA64.CslotPtr, (r = ss ∨ r = sd) → σ.kheap r.1 ≠ none := by + intro r hr + rcases hr with e | e <;> rw [e] + · exact hks + · exact hkd + refine ⟨W, capInsert_msA _ _ _ _ _ hm, ?_, ?_, ?_, ?_⟩ + · intro p q h sl hsl + rw [ec] at h + by_cases ep : p = sd + · rw [ep, Function.update_self] at h + rcases hsl with e | e + · exact Or.inl (kk _ (Or.inr (e.trans ep))) + · split at h + · cases h; exact Or.inl (kk _ (Or.inl e)) + · exact Or.inr ⟨ss, q, h, Or.inr e⟩ + · rw [Function.update_of_ne ep] at h + exact Or.inr ⟨p, q, h, hsl⟩ + · intro p h + by_cases ep : p = sd + · exact Or.inl (kk _ (Or.inr ep)) + · rw [eo, Function.update_of_ne ep] at h; exact Or.inr h + · intro p h + by_cases ep : p = sd + · exact Or.inr ep + · rw [eo, Function.update_of_ne ep] at h; exact Or.inl h + · refine specCapAtA_orA (Q := fun sl c => (sl = sd ∧ c = a) ∨ (sl = ss ∧ c = maxFreeIndexUpdate asc)) HS + (fun p o h => ?_) + rw [ekh] at h + obtain ⟨ob, kb, cb, wb⟩ := setCap_objsA h2 p o h + obtain ⟨oa, ka, ca, wa'⟩ := A1.2.2.2 p ob kb + refine ⟨oa, ka, fun b c hb => ?_, fun n => (wb n).trans (wa' n)⟩ + rcases cb b c hb with h | h + · exact Or.inl (Or.inl h) + · rcases ca b c h with h | h + · exact Or.inl (Or.inr h) + · exact Or.inr h + +/-- A spec step's objects are the same set: a slot's object stays, only CNode / TCB contents change. -/ +theorem SpecSlotA.kheap_ne {σ σ' : Fl4SpecA64.State Unit} (h : SpecSlotA σ σ') {p : Fl4SpecA64.ObjRef} + (hp : σ'.kheap p ≠ none) : σ.kheap p ≠ none := by + rcases h.kh p with e | ⟨r, cs, cs', e, e'⟩ | ⟨x, x', e, e', -⟩ + · rw [← e]; exact hp + · rw [e]; simp + · rw [e]; simp + +/-- **The spec side of a run of `cap_insert`s into the slots `Dm` of caps satisfying `Pc`** (module docstring of +`FrSubframeJ5A`): transitive, so a `mapMx` of insertions composes it. -/ +structure SubQA (Dm : Fl4SpecA64.CslotPtr → Prop) (Pc : Fl4SpecA64.Cap → Prop) + (σ σ' : Fl4SpecA64.State Unit) : Prop where + hs : SpecSlotA σ σ' + wf : WfKeepA σ σ' + ms : σ'.machineState = σ.machineState + cdt : ∀ x y, σ'.cdt x = some y → ∀ sl, sl = x ∨ sl = y → + σ.kheap sl.1 ≠ none ∨ ∃ x0 y0, σ.cdt x0 = some y0 ∧ (sl = x0 ∨ sl = y0) + orig : ∀ p, σ'.isOriginalCap p = true → σ.kheap p.1 ≠ none ∨ σ.isOriginalCap p = true + origD : ∀ p, σ'.isOriginalCap p = true → σ.isOriginalCap p = true ∨ Dm p + cap : ∀ sl c, specCapAtA σ' sl = some c → specCapAtA σ sl = some c ∨ (Dm sl ∧ Pc c) + +theorem SubQA.refl {Dm Pc} (σ : Fl4SpecA64.State Unit) : SubQA Dm Pc σ σ := + ⟨SpecSlotA.refl σ, WfKeepA.refl σ, rfl, fun x y h sl hsl => Or.inr ⟨x, y, h, hsl⟩, + fun p h => Or.inr h, fun p h => Or.inl h, fun sl c h => Or.inl h⟩ + +theorem SubQA.trans {Dm Pc} {σ1 σ2 σ3 : Fl4SpecA64.State Unit} (h1 : SubQA Dm Pc σ1 σ2) + (h2 : SubQA Dm Pc σ2 σ3) : SubQA Dm Pc σ1 σ3 where + hs := h1.hs.trans h2.hs + wf := h1.wf.trans h2.wf + ms := h2.ms.trans h1.ms + cdt x y h sl hsl := by + rcases h2.cdt x y h sl hsl with k | ⟨x0, y0, e, hs0⟩ + · exact Or.inl (h1.hs.kheap_ne k) + · exact h1.cdt x0 y0 e sl hs0 + orig p h := by + rcases h2.orig p h with k | o + · exact Or.inl (h1.hs.kheap_ne k) + · exact h1.orig p o + origD p h := by + rcases h2.origD p h with o | d + · rcases h1.origD p o with o | d + · exact Or.inl o + · exact Or.inr d + · exact Or.inr d + cap sl c h := by + rcases h2.cap sl c h with e | d + · exact h1.cap sl c e + · exact Or.inr d + +/-- **One `cap_insert` of a cap `a` satisfying `Pc` into a slot of `Dm` is a `SubQA` step**, the source cap +`maxFreeIndexUpdate`-fixed (a frame) and read back at `ss`. -/ +theorem SubQA.ofInsert {Dm Pc} {σ σ2 : Fl4SpecA64.State Unit} {a asc : Fl4SpecA64.Cap} + {ss sd : Fl4SpecA64.CslotPtr} + (hgs : (getCap (Z := Unit) ss σ).1 = {(asc, σ)}) (hgd : ∀ x ∈ (getCap (Z := Unit) sd σ).1, x.2 = σ) + (hm : ((), σ2) ∈ (Fl4SpecA64.capInsert (Z := Unit) a ss sd σ).1) (HS : SpecSlotA σ σ2) + (hks : σ.kheap ss.1 ≠ none) (hkd : σ.kheap sd.1 ≠ none) + (hmf : maxFreeIndexUpdate asc = asc) (hsa : specCapAtA σ ss = some asc) + (hD : Dm sd) (hP : Pc a) : SubQA Dm Pc σ σ2 := by + obtain ⟨W, ms, hc, ho, hod, hcap⟩ := capInsert_specQA hgs hgd hm HS hks hkd + refine ⟨HS, W, ms, hc, ho, fun p h => by + rcases hod p h with e | e + · exact Or.inl e + · rw [e]; exact Or.inr hD, fun sl c h => ?_⟩ + rcases hcap sl c h with e | ⟨e1, e2⟩ | ⟨e1, e2⟩ + · exact Or.inl e + · exact Or.inr ⟨e1 ▸ hD, e2 ▸ hP⟩ + · rw [hmf] at e2; rw [e1, e2]; exact Or.inl hsa + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/CnodeCopyA.lean b/proofs/Fl4ProofsA64/P3/CnodeCopyA.lean index fa847f078..0ffebaa29 100644 --- a/proofs/Fl4ProofsA64/P3/CnodeCopyA.lean +++ b/proofs/Fl4ProofsA64/P3/CnodeCopyA.lean @@ -60,6 +60,43 @@ theorem u64_eq_iffA (x y : U64) : x = y ↔ x.val = y.val := ⟨congrArg _, USca @[simp] theorem lblA_mutate : fl4_abi.label.CNodeMutate.val = 27 := by simp [fl4_abi.label.CNodeMutate] @[simp] theorem lblA_rotate : fl4_abi.label.CNodeRotate.val = 28 := by simp [fl4_abi.label.CNodeRotate] +/-- **Copy / Mint's new cap is a root-kind cap only as the source, and never an unmapped one** (`copied_cap.rt`). -/ +theorem cnode.copied_cap.rootDerivA3 {S : Type} {st : machine.Store S} [LawfulStore st] {s : S} + {lbl len buf src : U64} {c nc : capability.Cap} + (h : cnode.copied_cap st s lbl len buf src c = ok (.Ok (nc, false))) : RootDerivA nc c := by + have w := cnode.copied_cap.rt (st := st) s lbl len buf src c + rw [h, WP.spec_ok] at w + have w := w nc false rfl + exact RootDerivA.of_p1 ⟨w.1, w.2 rfl⟩ + +/-- `update_cap_data` changes no table-kind cap and makes none (both classes). -/ +theorem objects.update_cap_data.kindEqA3 {pr : Bool} {data : U64} {c nc : capability.Cap} + (h : objects.update_cap_data pr data c = ok nc) : KindEqA nc c := + ⟨fun r hk => by + have w := objects.update_cap_data.rt pr data c + rw [h, WP.spec_ok] at w + exact w hk.to_p1, fun r hk => by + have w := objects.update_cap_data.rt pr data c + rw [h, WP.spec_ok] at w + exact w hk.to_p1⟩ + +/-- `update_cap_data` changes no root-kind cap and makes none. -/ +theorem objects.update_cap_data.rootMvA3 {pr : Bool} {data : U64} {c nc : capability.Cap} + (h : objects.update_cap_data pr data c = ok nc) : RootMvA nc c := + RootMvA.of_kindEq (objects.update_cap_data.kindEqA3 h) + +/-- **Move / Mutate's new cap is a root-kind cap only as the source** (`copied_cap.rt`). -/ +theorem cnode.copied_cap.rootMvA3 {S : Type} {st : machine.Store S} [LawfulStore st] {s : S} + {lbl len buf src : U64} {c nc : capability.Cap} {b : Bool} + (h : cnode.copied_cap st s lbl len buf src c = ok (.Ok (nc, b))) : RootMvA nc c := + RootMvA.of_kindEq ⟨fun r hk => by + have w := cnode.copied_cap.rt (st := st) s lbl len buf src c + rw [h, WP.spec_ok] at w + exact (w nc b rfl).1 hk.to_p1, fun r hk => by + have w := cnode.copied_cap.rt (st := st) s lbl len buf src c + rw [h, WP.spec_ok] at w + exact (w nc b rfl).1 hk.to_p1⟩ + /-! ## The caps a copy makes, spec side -/ /-- **What `cap_insert_dA` asks of a copied cap, on the spec caps** (module docstring): the source `a0` is no zombie, @@ -761,7 +798,8 @@ theorem decode_copy_relA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a exact (hok.2.2 e (specPtr p) b.val i.val (by rw [hcu]; rfl)).2 ((E.j.1.cdt.hasChildA hP hAs).2 (has_child_desc.2 ⟨y, hy⟩))) hsh2 (by rw [hsc2]; intro p t n e; exact hok.1 (specPtr p) (zombieBitsA t) n.val (by rw [e]; rfl)) - (by rw [hsc2]; exact hok.2.1) hdo (fun h => hcv' Z.th (by rw [← hsc2]; exact h))) + (by rw [hsc2]; exact hok.2.1) hdo (fun h => hcv' Z.th (by rw [← hsc2]; exact h)) + (by rw [hsc2]; exact cnode.copied_cap.rootDerivA3 hr2)) rw [hs3]; simp only [bind_ok] rw [WP.spec_ok] refine ⟨.insertCall anc sl dsl, ?_, _, hset, σ', _, liftE_memA hm, hJ, hT', @@ -773,7 +811,8 @@ theorem decode_copy_relA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a (NodeOffA.of_ctOff (E2.sys.sysl.ct _ (hsub _ hsS))).of_shapeA hsh2 obtain ⟨s3, hs3, σ', hm, hJ, hT'⟩ := spec_existsA (cap_move_jA E2 hT2 hsub hnul2 hAs hAd hsn2 hdn2 hcan ⟨hw', hanc⟩ he' hnn hal ((E2.j.capObj hsS).of_shapeA hsh2 - fun h => hcv' Z.th (by rw [← hsc2]; exact h))) + fun h => hcv' Z.th (by rw [← hsc2]; exact h)) (PtSrcA.of_shape hsS hsh2) + (by rw [hsc2]; exact cnode.copied_cap.rootMvA3 hr2)) rw [hs3]; simp only [bind_ok] rw [WP.spec_ok] have hokAnc : CapOkA σ.interruptIrqNode dsl anc := by diff --git a/proofs/Fl4ProofsA64/P3/CnodeDecDelA.lean b/proofs/Fl4ProofsA64/P3/CnodeDecDelA.lean index 59aaef583..f3a2b6fb6 100644 --- a/proofs/Fl4ProofsA64/P3/CnodeDecDelA.lean +++ b/proofs/Fl4ProofsA64/P3/CnodeDecDelA.lean @@ -84,11 +84,18 @@ theorem DelSiteA.restartA (h : DelSiteA st th OS s σ G.chains) (hT : TreeA st O (hsub : ∀ y, IsSlotA th y → y ∈ OS) (hOK : OSKeep st OS s s1) (hcov : FinCovA th σ1) : DelSiteA st th OS s1 σ1 G.chains := by refine ⟨hcov, ?_, ?_, ?_⟩ - · refine FrBaseApartA.of h.fr (fun y hy hf => ⟨y, hy, ?_, ?_⟩) (fun z hz hk => ⟨z, hz, ?_, ?_⟩) + · refine FrBaseApartA.of h.fr (fun y hy hf => ⟨y, hy, ?_, ?_, ?_⟩) (fun z hz hk => ⟨z, hz, ?_, ?_⟩) ?_ · rwa [hOK.capA hy] at hf · rw [hOK.capA hy] + · rw [hOK.capA hy] · rwa [hOK.capA hz] at hk · rw [hOK.capA hz] + · have rv : ∀ z ∈ OS, Fl4ProofsA64.P1.W7.R.ST.revA st s1 z = Fl4ProofsA64.P1.W7.R.ST.revA st s z := fun z hz => by + unfold Fl4ProofsA64.P1.W7.R.ST.revA; rw [(hOK z hz).2.2.2] + exact h.fr.2.2.tr (fun y hy p rt mp e asid va hcy => ⟨y, hy, p, rt, mp, e, asid, va, + by rw [← hOK.capA hy]; exact hcy, by rw [hOK.capA hy], by rw [hOK.capA hy]⟩) + (fun z hz pz => ⟨z, hz, by rw [← hOK.capA hz]; exact pz, by rw [hOK.capA hz], by rw [hOK.capA hz], + fun f r => ⟨by rw [hOK.capA hz]; exact f, by rw [rv z hz]; exact r⟩⟩) · exact h.irq.keepIrq fun y hy i => by rw [hOK.capA ((hT.lk.members y).1 hy).1] · intro y hy p zt n hc rw [hOK.capA (hsub y hy)] at hc diff --git a/proofs/Fl4ProofsA64/P3/CnodeDelFootA.lean b/proofs/Fl4ProofsA64/P3/CnodeDelFootA.lean index 83e96630c..fc205795d 100644 --- a/proofs/Fl4ProofsA64/P3/CnodeDelFootA.lean +++ b/proofs/Fl4ProofsA64/P3/CnodeDelFootA.lean @@ -71,10 +71,11 @@ theorem DelFootA.slotWrites {A : Type} {AR : A → HwRootA → Prop} {a : A} {Z {s0 s s' : S} (F : DelFootA st Z T Ω Sg OS s0) (hk : SameCoreA st s0 s) {G G' : MdbGhostA} {σ σ' : State Unit} {m : McState} (J : JAtZAX (L := L) AR { Z with G := G } s a σ m) (hw : WritesIn st s s' (W7.CapW T {b | InOS OS b} ∅)) (HS : SpecSlotA σ σ') (hst : StateRelA Z.th (L.mem s') σ') - (hcdt : CdtRelA st Z.th s' σ' G') (hcap : ∀ y, IsSlotA Z.th y → CapObjOkA Z (capAtA (L.mem s') y)) : + (hcdt : CdtRelA st Z.th s' σ' G') (hcap : ∀ y, IsSlotA Z.th y → CapObjOkA Z (capAtA (L.mem s') y)) + (hpt : PtClosedA Z.th Z.S1 Z.T2 (L.mem s) (L.mem s')) : JAtZAX (L := L) AR { Z with G := G' } s' a σ' m := by have h := J.of_slotWrites hw (fun b hb hf => F.off b (footNA_coreA hk hf) hb) - (fun b hf => F.al b (footNA_coreA hk hf)) G' HS hst hcdt hcap + (fun b hf => F.al b (footNA_coreA hk hf)) G' HS hst hcdt hcap hpt exact h end diff --git a/proofs/Fl4ProofsA64/P3/CnodeDelStepA.lean b/proofs/Fl4ProofsA64/P3/CnodeDelStepA.lean index cf5a2071a..4f3f9e778 100644 --- a/proofs/Fl4ProofsA64/P3/CnodeDelStepA.lean +++ b/proofs/Fl4ProofsA64/P3/CnodeDelStepA.lean @@ -107,14 +107,23 @@ variable {OS : Set U64} {s s' : S} state (somewhere in `OS`), at the same base. -/ theorem FrBaseApartA.of (h : FrBaseApartA st OS s) (hf : ∀ y ∈ OS, isFrA (capA st s' y) = true → - ∃ y' ∈ OS, isFrA (capA st s y') = true ∧ ptrA (capA st s y') = ptrA (capA st s' y)) + ∃ y' ∈ OS, isFrA (capA st s y') = true ∧ ptrA (capA st s y') = ptrA (capA st s' y) ∧ + sizeA (capA st s y') = sizeA (capA st s' y)) (hk : ∀ z ∈ OS, RngKeyA (capA st s' z) → - ∃ z' ∈ OS, RngKeyA (capA st s z') ∧ ptrA (capA st s z') = ptrA (capA st s' z)) : + ∃ z' ∈ OS, RngKeyA (capA st s z') ∧ ptrA (capA st s z') = ptrA (capA st s' z)) + (hl : FrLamA st OS s') : FrBaseApartA st OS s' := by - intro y hy z hz fy kz e - obtain ⟨y', hy', fy', ey⟩ := hf y hy fy - obtain ⟨z', hz', kz', ez⟩ := hk z hz kz - exact h y' hy' z' hz' fy' kz' (by rw [ez, ey, e]) + refine ⟨fun y hy z hz fy kz e => ?_, fun y hy z hz fy kz => ?_, hl⟩ + · obtain ⟨y', hy', fy', ey, -⟩ := hf y hy fy + obtain ⟨z', hz', kz', ez⟩ := hk z hz kz + exact h.1 y' hy' z' hz' fy' kz' (by rw [ez, ey, e]) + · obtain ⟨y', hy', fy', ey, sy⟩ := hf y hy fy + obtain ⟨z', hz', kz', ez⟩ := hk z hz kz + have by' : baseA (capA st s y') = baseA (capA st s' y) := by unfold baseA; rw [ey] + have bz : baseA (capA st s z') = baseA (capA st s' z) := by unfold baseA; rw [ez] + have ty : topA (capA st s y') = topA (capA st s' y) := by unfold topA; rw [ey, sy] + rw [← by', ← bz, ← ty] + exact h.2.1 y' hy' z' hz' fy' kz' /-- [J] `IrqRunA` along the renaming of two slots. -/ theorem IrqRunA.ren {G : List (List U64)} (h : IrqRunA st G s) {x1 x2 : U64} @@ -193,13 +202,41 @@ theorem DelInvA.of (D : DStateA st th OS s σ G) obtain ⟨y', hy', h'⟩ := hc y hy p zt n h exact D.zw y' (D.isSlot_of hy' (by rw [h']; exact fun e => by cases e)) p zt n h' +/-- **`FrLamA` after two caps changed places** (their revocable bits with them). -/ +theorem FrLamA.swapped (h : FrLamA st OS s) {x1 x2 : U64} (hx1 : x1 ∈ OS) (hx2 : x2 ∈ OS) + (hc : ∀ y ∈ OS, capA st s' y = capA st s (swp x1 x2 y)) + (hr : ∀ z ∈ OS, physA (capA st s' z) = true → Fl4ProofsA64.P1.W7.R.ST.revA st s' z = Fl4ProofsA64.P1.W7.R.ST.revA st s (swp x1 x2 z)) : + FrLamA st OS s' := + h.tr (fun y hy p rt mp e asid va hcy => ⟨swp x1 x2 y, swp_os hx1 hx2 hy, p, rt, mp, e, asid, va, + by rw [← hc y hy]; exact hcy, by rw [hc y hy], by rw [hc y hy]⟩) + (fun z hz pz => by + have ez := hc z hz + rw [ez] at pz + exact ⟨swp x1 x2 z, swp_os hx1 hx2 hz, pz, by rw [ez], by rw [ez], + fun f r => ⟨by rw [ez]; exact f, by rw [hr z hz (by rw [ez]; exact pz)]; exact r⟩⟩) + +/-- **`FrLamA` after one slot was emptied.** -/ +theorem FrLamA.removed (h : FrLamA st OS s) {x : U64} (hx0 : capA st s' x = .Null) + (hk : ∀ y ∈ OS, y ≠ x → capA st s' y = capA st s y) + (hr : ∀ z ∈ OS, physA (capA st s' z) = true → Fl4ProofsA64.P1.W7.R.ST.revA st s' z = Fl4ProofsA64.P1.W7.R.ST.revA st s z) : FrLamA st OS s' := by + have back : ∀ y ∈ OS, capA st s' y ≠ .Null → capA st s y = capA st s' y := fun y hy hn => + (hk y hy (fun e => hn (e ▸ hx0))).symm + exact h.tr (fun y hy p rt mp e asid va hcy => by + have n0 : capA st s' y ≠ .Null := fun e0 => by rw [hcy] at e0; cases e0 + exact ⟨y, hy, p, rt, mp, e, asid, va, by rw [back y hy n0]; exact hcy, by rw [back y hy n0], by rw [back y hy n0]⟩) + (fun z hz pz => by + have n0 : capA st s' z ≠ .Null := fun e0 => by rw [e0, physA_null] at pz; cases pz + exact ⟨z, hz, by rw [back z hz n0]; exact pz, by rw [back z hz n0], by rw [back z hz n0], + fun f r => ⟨by rw [← back z hz n0]; exact f, by rw [hr z hz pz]; exact r⟩⟩) + /-- **`DStateA` after two caps changed places** (the ghost renamed by the transposition). -/ theorem DStateA.swapped (D : DStateA st th OS s σ G) {x1 x2 : U64} (hx1 : x1 ∈ OS) (hx2 : x2 ∈ OS) (hs1 : IsSlotA th x1) (hs2 : IsSlotA th x2) (hrel : StateRelA th (L.mem s') σ') (hplace : PlaceA th (L.ksb s')) (hcdt : CdtRelA st th s' σ' (swGA G x1 x2)) (htree : TreeA st OS (swGA G x1 x2).chains (swGA G x1 x2).par s') (hcov : FinCovA th σ') (hzf : ZombiesFinal st OS s') (hnl : NullLk st OS s') - (hc : ∀ y ∈ OS, capA st s' y = capA st s (swp x1 x2 y)) : DStateA st th OS s' σ' (swGA G x1 x2) := by + (hc : ∀ y ∈ OS, capA st s' y = capA st s (swp x1 x2 y)) (hmw : SwapMdbA st G.chains x1 x2 s s') : + DStateA st th OS s' σ' (swGA G x1 x2) := by have hc' : ∀ y ∈ OS, capA st s' (swp x1 x2 y) = capA st s y := fun y hy => by rw [hc _ (swp_os hx1 hx2 hy), swp_swp] have inOS : ∀ y ∈ G.chains.flatten, y ∈ OS := fun y hy => ((D.lk.members y).1 hy).1 @@ -213,9 +250,14 @@ theorem DStateA.swapped (D : DStateA st th OS s σ G) {x1 x2 : U64} (hx1 : x1 unfold swp rw [if_neg (fun e => hn (by rw [e]; exact hs1)), if_neg (fun e => hn (by rw [e]; exact hs2))] rw [hc y hy, e]; exact D.nul y hy hn - · refine D.fr.of (fun y hy f => ?_) (fun z hz k => ?_) - · rw [hc y hy] at f ⊢; exact ⟨_, swp_os hx1 hx2 hy, f, rfl⟩ + · refine D.fr.of (fun y hy f => ?_) (fun z hz k => ?_) (D.fr.2.2.swapped hx1 hx2 hc (fun z hz pz => ?_)) + · rw [hc y hy] at f ⊢; exact ⟨_, swp_os hx1 hx2 hy, f, rfl, rfl⟩ · rw [hc z hz] at k ⊢; exact ⟨_, swp_os hx1 hx2 hz, k, rfl⟩ + · have n0 : capA st s (swp x1 x2 z) ≠ .Null := fun e0 => by rw [hc z hz, e0, physA_null] at pz; cases pz + have hzG : swp x1 x2 z ∈ G.chains.flatten := (D.lk.members _).2 ⟨swp_os hx1 hx2 hz, n0⟩ + have := (hmw _ hzG).2.1 + have e : ∀ a, Equiv.swap x1 x2 a = swp x1 x2 a := fun a => by rw [Equiv.swap_apply_def]; rfl + rwa [e, swp_swp] at this · refine DelInvA.of D (fun y hy p zt n h => ?_) have hyO := D.sub y hy rw [hc y hyO] at h @@ -226,8 +268,8 @@ theorem DStateA.removed (D : DStateA st th OS s σ G) {x : U64} (hx : x ∈ OS) (hrel : StateRelA th (L.mem s') σ') (hplace : PlaceA th (L.ksb s')) (hcdt : CdtRelA st th s' σ' (remGA G x)) (htree : TreeA st OS (remGA G x).chains (remGA G x).par s') (hcov : FinCovA th σ') (hrng : RngOneA64 st (remGA G x).chains s') (hkind : KindA st OS s') - (hnl : NullLk st OS s') (hx0 : capA st s' x = .Null) (hk : ∀ y ∈ OS, y ≠ x → capA st s' y = capA st s y) : - DStateA st th OS s' σ' (remGA G x) := by + (hnl : NullLk st OS s') (hx0 : capA st s' x = .Null) (hk : ∀ y ∈ OS, y ≠ x → capA st s' y = capA st s y) + (hmw : EmpMdbA st G.chains x s s') : DStateA st th OS s' σ' (remGA G x) := by have kn : ∀ y ∈ OS, capA st s' y = capA st s y ∨ capA st s' y = .Null := fun y hy => by by_cases e : y = x · exact Or.inr (e ▸ hx0) @@ -249,11 +291,14 @@ theorem DStateA.removed (D : DStateA st th OS s σ G) {x : U64} (hx : x ∈ OS) · rcases kn y hy with e | e · rw [e]; exact D.nul y hy hn · exact e - · refine D.fr.of (fun y hy f => ?_) (fun z hz k => ?_) + · refine D.fr.of (fun y hy f => ?_) (fun z hz k => ?_) (D.fr.2.2.removed hx0 hk (fun z hz pz => ?_)) · have n0 : capA st s' y ≠ .Null := fun e => by rw [e] at f; exact Bool.false_ne_true f - exact ⟨y, hy, by rw [back y hy n0]; exact f, by rw [back y hy n0]⟩ + exact ⟨y, hy, by rw [back y hy n0]; exact f, by rw [back y hy n0], by rw [back y hy n0]⟩ · have n0 : capA st s' z ≠ .Null := fun e => RngKeyA.not_null (e ▸ k) exact ⟨z, hz, by rw [back z hz n0]; exact k, by rw [back z hz n0]⟩ + · have n0 : capA st s' z ≠ .Null := fun e0 => by rw [e0, physA_null] at pz; cases pz + have hzx : z ≠ x := fun e0 => n0 (e0 ▸ hx0) + exact hmw.rev z ((D.lk.members z).2 ⟨hz, by rw [back z hz n0]; exact n0⟩) hzx · refine DelInvA.of D (fun y hy p zt n h => ?_) have hyO := D.sub y hy have n0 : capA st s' y ≠ .Null := fun e => by rw [e] at h; cases h @@ -299,7 +344,7 @@ theorem empty_slot_sA {ar : machine.Arch A} (hO : OSOK T Ω Sg OS) (D : DStateA have W : WfKeepA σ σ' := emptySlot_wfA xs .nullCap σ _ hm have hP : PlaceA th (L.ksb q.1) := by rw [hw.1]; exact D.place exact ⟨har, hw, hx0, hcr, σ', hm, hSS, - D.removed hxO hst hP hcdt hT (D.cov.step H W) hRO hK hnl hx0 hcr, hmw⟩ + D.removed hxO hst hP hcdt hT (D.cov.step H W) hRO hK hnl hx0 hcr hmw, hmw⟩ /-- **`cdt::cap_swap_for_delete` of two non-null slots keeps the deletion's states.** -/ theorem cap_swap_for_delete_sA (hO : OSOK T Ω Sg OS) (D : DStateA st th OS s σ G) @@ -363,7 +408,7 @@ theorem cap_swap_for_delete_sA (hO : OSOK T Ω Sg OS) (D : DStateA st th OS s σ have H : SchedFrA σ σ' := capSwapForDelete_ndr sa sb σ _ hm have W : WfKeepA σ σ' := capSwapForDelete_wfA sa sb σ _ hm have hP' : PlaceA th (L.ksb s') := by rw [hw.1]; exact D.place - exact ⟨hw, hc, σ', hm, hSS, D.swapped hx1 hx2 hS1 hS2 hst hP' hcdt hT (D.cov.step H W) hzf hnl hc, hmw⟩ + exact ⟨hw, hc, σ', hm, hSS, D.swapped hx1 hx2 hS1 hS2 hst hP' hcdt hT (D.cov.step H W) hzf hnl hc hmw, hmw⟩ end diff --git a/proofs/Fl4ProofsA64/P3/CnodeDelSwapA.lean b/proofs/Fl4ProofsA64/P3/CnodeDelSwapA.lean index ea7c9822a..ffd176b80 100644 --- a/proofs/Fl4ProofsA64/P3/CnodeDelSwapA.lean +++ b/proofs/Fl4ProofsA64/P3/CnodeDelSwapA.lean @@ -181,7 +181,7 @@ theorem cap_swap_for_delete_hsA (hO : OSOK T Ω Sg OS) (D : DStateA st th OS s have H : SchedFrA σ σ' := capSwapForDelete_ndr sa sb σ _ hm have W : WfKeepA σ σ' := capSwapForDelete_wfA sa sb σ _ hm have hP' : PlaceA th (L.ksb s') := by rw [hw.1]; exact D.place - exact ⟨hw, hc, σ', hm, hSS, D.swapped hx1 hx2 hS1 hS2 hst hP' hcdt hT (D.cov.step H W) hzf hnl hc, hmw⟩ + exact ⟨hw, hc, σ', hm, hSS, D.swapped hx1 hx2 hS1 hS2 hst hP' hcdt hT (D.cov.step H W) hzf hnl hc hmw, hmw⟩ end diff --git a/proofs/Fl4ProofsA64/P3/CnodeDelWA.lean b/proofs/Fl4ProofsA64/P3/CnodeDelWA.lean index 28000dd2f..08a1dda98 100644 --- a/proofs/Fl4ProofsA64/P3/CnodeDelWA.lean +++ b/proofs/Fl4ProofsA64/P3/CnodeDelWA.lean @@ -38,7 +38,7 @@ theorem swapHyp_jA (F : DelFootA st Z T Ω Sg OS s0) {X : DelWA S A} (hX : SwapH have hzok := D.zw _ hxs p zt n hz have h := hzok.absSlot.isSlot D.place rwa [hzok.addr] at h - refine ⟨hk.writes hw, ⟨m, F.slotWrites hk J hw hSS D'.rel D'.cdt fun y hy => ?_⟩, + refine ⟨hk.writes hw, ⟨m, F.slotWrites hk J hw hSS D'.rel D'.cdt (fun y hy => ?_) ?_⟩, hX s s' a σ σ' G sl p zt n hx h1 D D' hw hSS hm hA hz hne hcap hM⟩ show CapObjOkA Z (capA st s' y) rw [hcap y (D.sub y hy)] @@ -46,25 +46,44 @@ theorem swapHyp_jA (F : DelFootA st Z T Ω Sg OS s0) {X : DelWA S A} (hX : SwapH · exact J.capObj hps · exact J.capObj hxs · exact J.capObj hy + · have tc : TabClosedA Z.th (L.mem s) (L.mem s') := TabClosedA.of_exch hxs hps + (by rw [capAtA_eq, capAtA_eq, hcap _ (D.sub _ hxs), if_pos rfl]) + (by rw [capAtA_eq, capAtA_eq, hcap _ (D.sub _ hps), if_neg hne, if_pos rfl]) + (by intro y hy h1 h2 + rw [capAtA_eq, capAtA_eq, hcap _ (D.sub _ hy), if_neg h1, if_neg h2]) + refine ⟨fun y hy ptr asid va mp h => ?_, tc.root, tc.pts.toE⟩ + rw [capAtA_eq, hcap y (D.sub y hy)] at h + split_ifs at h + · exact Or.inl ⟨_, hps, by rw [capAtA_eq]; exact h⟩ + · exact Or.inl ⟨_, hxs, by rw [capAtA_eq]; exact h⟩ + · exact Or.inl ⟨y, hy, by rw [capAtA_eq]; exact h⟩ theorem emptyHyp_jA (F : DelFootA st Z T Ω Sg OS s0) {X Xx : DelWA S A} {Rd : S → A → Fl4SpecA64.State Unit → MdbGhostA → U64 → Prop} (hX : EmptyHypA st T Z.th OS X Xx Rd) : EmptyHypA st T Z.th OS (DelJWA (st := st) AR Z s0 X) (DelJWA (st := st) AR Z s0 Xx) Rd := by intro s s' a σ σ' G sl hW hRd D D' hw hSS hm hA hn h0 hcap hM obtain ⟨hk, ⟨m, J⟩, hx⟩ := hW - refine ⟨hk.writes hw, ⟨m, F.slotWrites hk J hw hSS D'.rel D'.cdt fun y hy => ?_⟩, + refine ⟨hk.writes hw, ⟨m, F.slotWrites hk J hw hSS D'.rel D'.cdt (fun y hy => ?_) ?_⟩, hX s s' a σ σ' G sl hx hRd D D' hw hSS hm hA hn h0 hcap hM⟩ show CapObjOkA Z (capA st s' y) by_cases e : y = cslotAddrA sl · rw [e, h0]; exact CapObjOkA.null Z · rw [hcap y (D.sub y hy) e]; exact J.capObj hy + · refine PtClosedA.of_cap fun y hy => ?_ + by_cases e : y = cslotAddrA sl + · right + rw [capAtA_eq, e, h0] + exact NoVsCapA.null + · left + rw [capAtA_eq, capAtA_eq] + exact hcap y (D.sub y hy) e theorem zombieHyp_jA (F : DelFootA st Z T Ω Sg OS s0) {X : DelWA S A} {Rz : S → A → Fl4SpecA64.State Unit → MdbGhostA → U64 → Prop} (hX : ZombieHypA st T Z.th OS X Rz) : ZombieHypA st T Z.th OS (DelJWA (st := st) AR Z s0 X) Rz := by intro s s' a σ σ' G sl p zt n hW hRz hz hnz D D' hw hSS hset hA hn hc hcap hM obtain ⟨hk, ⟨m, J⟩, hx⟩ := hW - refine ⟨hk.writes hw, ⟨m, F.slotWrites hk J hw hSS D'.rel D'.cdt fun y hy => ?_⟩, + refine ⟨hk.writes hw, ⟨m, F.slotWrites hk J hw hSS D'.rel D'.cdt (fun y hy => ?_) ?_⟩, hX s s' a σ σ' G sl p zt n hx hRz hz hnz D D' hw hSS hset hA hn hc hcap hM⟩ show CapObjOkA Z (capA st s' y) by_cases e : y = cslotAddrA sl @@ -72,6 +91,14 @@ theorem zombieHyp_jA (F : DelFootA st Z T Ω Sg OS s0) {X : DelWA S A} exact ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), trivial⟩ · rw [hcap y (D.sub y hy) e]; exact J.capObj hy + · refine PtClosedA.of_cap fun y hy => ?_ + by_cases e : y = cslotAddrA sl + · right + rw [capAtA_eq, e, hc] + exact NoVsCapA.zombie _ _ _ + · left + rw [capAtA_eq, capAtA_eq] + exact hcap y (D.sub y hy) e /-- **`DelHypsA` at the relation**: the hooks at `DelJWA`, and the extra invariant `X` kept by the loop's own slot steps. -/ diff --git a/proofs/Fl4ProofsA64/P3/CnodeDelZombieA.lean b/proofs/Fl4ProofsA64/P3/CnodeDelZombieA.lean index f52e956c2..cb37e417a 100644 --- a/proofs/Fl4ProofsA64/P3/CnodeDelZombieA.lean +++ b/proofs/Fl4ProofsA64/P3/CnodeDelZombieA.lean @@ -210,13 +210,26 @@ theorem set_zombie_sA (hO : OSOK T Ω Sg OS) (D : DStateA st th OS s σ G) by_cases e : y = x · rw [e, cx]; trivial · rw [co y hy e]; exact D.cv y hy } - · refine D.fr.of (fun y hy f => ?_) (fun y hy k => ?_) + · have hr : ∀ z ∈ OS, Fl4ProofsA64.P1.W7.R.ST.revA st s' z = Fl4ProofsA64.P1.W7.R.ST.revA st s z := fun z hz => by + unfold Fl4ProofsA64.P1.W7.R.ST.revA; rw [(hl z hz).2] + have fz : isFrA (capA st s x) = false := by have := hk0.2.2; simpa using this + refine D.fr.of (fun y hy f => ?_) (fun y hy k => ?_) (D.fr.2.2.tr (fun y hy p rt mp e asid va hcy => ?_) + (fun z hz pz => ?_)) · by_cases e : y = x · rw [e, cx] at f; cases f - · rw [co y hy e] at f ⊢; exact ⟨y, hy, f, rfl⟩ + · rw [co y hy e] at f ⊢; exact ⟨y, hy, f, rfl, rfl⟩ · by_cases e : y = x · rw [e, cx, ptrA_zombie]; exact ⟨x, hxO, hk0, hp0⟩ · rw [co y hy e] at k ⊢; exact ⟨y, hy, k, rfl⟩ + · have ne : y ≠ x := fun h => by rw [h, cx] at hcy; cases hcy + exact ⟨y, hy, p, rt, mp, e, asid, va, by rw [← co y hy ne]; exact hcy, by rw [co y hy ne], by rw [co y hy ne]⟩ + · by_cases e : z = x + · refine ⟨x, hxO, hk0.1, ?_, ?_, fun f _ => ?_⟩ + · rw [e, cx]; exact hua.base + · rw [e, cx]; exact hua.top + · rw [fz] at f; cases f + · exact ⟨z, hz, by rw [← co z hz e]; exact pz, by rw [co z hz e], by rw [co z hz e], + fun f r => ⟨by rw [co z hz e]; exact f, by rw [hr z hz]; exact r⟩⟩ · refine D.irq.keepIrq fun y hy i => ?_ by_cases e : y = x · rw [e, cx] diff --git a/proofs/Fl4ProofsA64/P3/CnodeFinalA.lean b/proofs/Fl4ProofsA64/P3/CnodeFinalA.lean index 176d4431f..8e9b08016 100644 --- a/proofs/Fl4ProofsA64/P3/CnodeFinalA.lean +++ b/proofs/Fl4ProofsA64/P3/CnodeFinalA.lean @@ -25,6 +25,7 @@ Named premises (Architect ruling of 2026-12-02 18:58Z): word, those of the entry line's `SlotHeapCovA th σ` (`P3/SlotCoverageA`, absent on this branch). -/ import Fl4ProofsA64.P3.EpBufA +import Fl4ProofsA64.P1.MdbFrUt import Fl4ProofsA64.P3.FinDefsA import Fl4ProofsA64.P3.LookupA import Fl4ProofsA64.P3.EmptyA @@ -237,10 +238,67 @@ theorem so_irqA (i : U64) : objects.same_object_as (.IrqHandler i) (.IrqHandler section variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +/-- (E0.5) The address range of a frame cap that fits: `[q, q + 2^bits)`. -/ +theorem frame_rangeA {q r a v bits : U64} {sz : capability.FrameSize} {d m e : Bool} + (hb : capability.FrameSize.bits sz = ok bits) (hfit : q.val + 2 ^ bits.val ≤ 2 ^ 64) : + baseA (.Frame q sz r d m e a v) = q.val ∧ topA (.Frame q sz r d m e a v) = q.val + (2 ^ bits.val - 1) := by + have f := frA_size (ptr := q) (rights := r) (x3 := a) (x4 := v) (dv := d) (x1 := m) (x2 := e) (size := sz) hb + have h1 : 1 ≤ 2 ^ bits.val := Nat.one_le_two_pow + refine ⟨by unfold baseA; rw [f.1], ?_⟩ + unfold topA + rw [f.1, f.2.1, wa_val, mskA_val f.2.2.1] + exact Nat.mod_eq_of_lt (by omega) + /-- **[J]** (module docstring) No `OS` frame cap shares its base with a range key cap of an `OS` slot. -/ -def FrBaseApartA (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s : S) : Prop := +def FrBaseOnlyA (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s : S) : Prop := ∀ y ∈ OS, ∀ z ∈ OS, isFrA (capA st s y) = true → RngKeyA (capA st s z) → ptrA (capA st s z) ≠ ptrA (capA st s y) +/-- **[J]** (E0.5) No range key cap's base lies strictly inside an `OS` frame cap's range (so a 4 KiB subframe of a +larger frame never shares its base with a range key cap). -/ +def FrIntApartA (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s : S) : Prop := + ∀ y ∈ OS, ∀ z ∈ OS, isFrA (capA st s y) = true → RngKeyA (capA st s z) → + ¬ (baseA (capA st s y) < baseA (capA st s z) ∧ baseA (capA st s z) ≤ topA (capA st s y)) + +/-- **[J]** (E0.5b; x86 `LargeFrOK` / `NoOverlap.hno`, l4v `caps_no_overlap` for a large frame) Every physical cap of an +`OS` slot is disjoint from a large RAM frame cap of an `OS` slot, or is a non-revocable frame cap, or contains it. -/ +def FrLamA (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s : S) : Prop := + ∀ y ∈ OS, ∀ (p rt : U64) (mp e : Bool) (asid va : U64), + capA st s y = .Frame p .Large rt false mp e asid va → ∀ z ∈ OS, physA (capA st s z) = true → + DisjA (capA st s z) (capA st s y) ∨ (isFrA (capA st s z) = true ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s z = false) ∨ + WithinA (capA st s y) (capA st s z) + +/-- **Where the revocable bit of a frame slot comes from** (E0.5b): a frame cap of the new state is non-revocable, or a +frame cap of the same range with the same bit sat in some slot of the old state. -/ +def RevFromA (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s s' : S) : Prop := + ∀ u ∈ OS, isFrA (capA st s' u) = true → Fl4ProofsA64.P1.W7.R.ST.revA st s' u = false ∨ + ∃ v ∈ OS, isFrA (capA st s v) = true ∧ baseA (capA st s v) = baseA (capA st s' u) ∧ + topA (capA st s v) = topA (capA st s' u) ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s v = Fl4ProofsA64.P1.W7.R.ST.revA st s' u + +/-- **`FrLamA` along a step whose slots' caps are the old slots' (same range), non-revocable frames staying so.** -/ +theorem FrLamA.tr {s s' : S} {OS : Set U64} (h : FrLamA st OS s) + (hyF : ∀ y ∈ OS, ∀ (p rt : U64) (mp e : Bool) (asid va : U64), + capA st s' y = .Frame p .Large rt false mp e asid va → + ∃ y0 ∈ OS, ∃ (p0 rt0 : U64) (mp0 e0 : Bool) (asid0 va0 : U64), + capA st s y0 = .Frame p0 .Large rt0 false mp0 e0 asid0 va0 ∧ + baseA (capA st s' y) = baseA (capA st s y0) ∧ topA (capA st s' y) = topA (capA st s y0)) + (hzF : ∀ z ∈ OS, physA (capA st s' z) = true → + ∃ z0 ∈ OS, physA (capA st s z0) = true ∧ baseA (capA st s' z) = baseA (capA st s z0) ∧ + topA (capA st s' z) = topA (capA st s z0) ∧ + (isFrA (capA st s z0) = true → Fl4ProofsA64.P1.W7.R.ST.revA st s z0 = false → isFrA (capA st s' z) = true ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s' z = false)) : + FrLamA st OS s' := by + intro y hy p rt mp e asid va hc z hz' pz + obtain ⟨y0, hy0, p0, rt0, mp0, e0, a0, v0, hc0, b1, t1⟩ := hyF y hy p rt mp e asid va hc + obtain ⟨z0, hz0, pz0, b2, t2, fr⟩ := hzF z hz' pz + rcases h y0 hy0 p0 rt0 mp0 e0 a0 v0 hc0 z0 hz0 pz0 with d | ⟨f, r⟩ | w + · left; unfold DisjA at d ⊢; rw [b1, b2, t1, t2]; exact d + · right; left; exact fr f r + · right; right; unfold WithinA at w ⊢; rw [b1, b2, t1, t2]; exact w + +/-- **[J]** (module docstring; E0.5: strengthened to the containment form) No `OS` frame cap shares its base with, or +contains the base of, a range key cap of an `OS` slot. -/ +def FrBaseApartA (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s : S) : Prop := + FrBaseOnlyA st OS s ∧ FrIntApartA st OS s ∧ FrLamA st OS s + /-- **[J]** (module docstring) The handler caps of one IRQ lie in one MDB chain, contiguously. -/ structure IrqRunA (st : machine.Store S) [L : LawfulStore st] (G : List (List U64)) (s : S) : Prop where one : ∀ y ∈ G.flatten, ∀ y' ∈ G.flatten, ∀ i, capA st s y = .IrqHandler i → capA st s y' = .IrqHandler i → @@ -509,7 +567,7 @@ theorem finalHypA (th : TypedHeapA) : FinalHypA st th := by rcases h with h | h · exact ⟨h, e⟩ · exact absurd (hc.symm ▸ e.symm : ptrA (capA st s (cslotAddrA sl)) = ptrA (capA st s y)) - (F.fr y hy _ hx h (hc.symm ▸ hk)) + (F.fr.1 y hy _ hx h (hc.symm ▸ hk)) by_cases hz : IsZombieA c · obtain ⟨p, t, n, rfl⟩ := hz have alone : ∀ w ∈ OS, w ≠ cslotAddrA sl → ¬ Q (capA st s w) := fun w hw hne h => diff --git a/proofs/Fl4ProofsA64/P3/CnodeRotA.lean b/proofs/Fl4ProofsA64/P3/CnodeRotA.lean index 6c78396bd..943fdc361 100644 --- a/proofs/Fl4ProofsA64/P3/CnodeRotA.lean +++ b/proofs/Fl4ProofsA64/P3/CnodeRotA.lean @@ -61,7 +61,9 @@ theorem cap_move2_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (hcp : CapRelA np ap) (hwp : CapRt.EncWf np) (hnp : np ≠ .Null) (halp : UA np (capA st s (cslotAddrA sp))) (hop : CapObjOkA Z np) (hcs : CapRelA ns an) (hws : CapRt.EncWf ns) (hns : ns ≠ .Null) (hals : UA ns (capA st s (cslotAddrA ss))) - (hos : CapObjOkA Z ns) : + (hos : CapObjOkA Z ns) (hpp : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) np) (hps : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) ns) + (hrp : KindEqA np (capAtA (L.mem s) (cslotAddrA sp))) + (hrs : KindEqA ns (capAtA (L.mem s) (cslotAddrA ss))) : cdt.move_cap st s np (cslotAddrA sp) (cslotAddrA sd) ⦃ s1 => cdt.move_cap st s1 ns (cslotAddrA ss) (cslotAddrA sp) ⦃ s2 => ∃ σ1 σ2, ((), σ1) ∈ (Fl4SpecA64.capMove (Z := Unit) ap sp sd σ).1 ∧ @@ -87,7 +89,7 @@ theorem cap_move2_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (fun h => inOS _ (F.pvm _ hpG h)) (fun h => inOS _ (F.nxm _ hpG h)))) (cdt.move_cap.lr hO (LR.self s) (hsub _ hpS) (hsub _ hdS) hpd hdc hwp (fun h => inOS _ (F.pvm _ hpG h)) (fun h => inOS _ (F.nxm _ hpG h)))) ?_ - rintro s1 ⟨⟨⟨σ1, hm1, hst1, hcdt1, hT1, hSS1, hcs1⟩, hw1⟩, -, -, es1, ek1⟩ + rintro s1 ⟨⟨⟨σ1, hm1, hst1, hcdt1, hT1, hSS1, hcs1⟩, hw1⟩, -, ed1, es1, ek1⟩ -- between the moves: the source cap and every null non-relation slot kept have hsc1 : capA st s1 (cslotAddrA ss) = capA st s (cslotAddrA ss) := ek1 _ (hsub _ hsS) hsp hsd have hsn1 : capAtA (L.mem s1) (cslotAddrA ss) ≠ .Null := by rw [capAtA_eq, hsc1]; exact hsn @@ -98,12 +100,38 @@ theorem cap_move2_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} have F1 := hT1.lk.lkF hO.nz have inOS1 : ∀ y ∈ (mvGA Z.G (cslotAddrA sp) (cslotAddrA sd)).chains.flatten, y ∈ OS := fun y hy => ((hT1.lk.members y).1 hy).1 - refine WP.spec_mono (WP.spec_and (cap_move_refinesA s1 σ1 _ hst1 hcdt1 hP hO hT1 hsub hnul1 hAs hAp hsn1 es1 hpc + refine WP.spec_mono (WP.spec_and (WP.spec_and (cap_move_refinesA s1 σ1 _ hst1 hcdt1 hP hO hT1 hsub hnul1 hAs hAp hsn1 es1 hpc hcs hws hns (by rw [hsc1]; exact hals)) (moveCap_osA hO (hsub _ hsS) (hsub _ hpS) + (fun h => inOS1 _ (F1.pvm _ hsG1 h)) (fun h => inOS1 _ (F1.nxm _ hsG1 h)))) + (cdt.move_cap.lr hO (LR.self s1) (hsub _ hsS) (hsub _ hpS) hsp hpc hws (fun h => inOS1 _ (F1.pvm _ hsG1 h)) (fun h => inOS1 _ (F1.nxm _ hsG1 h)))) ?_ - rintro s2 ⟨⟨σ2, hm2, hst2, hcdt2, hT2, hSS2, hcs2⟩, hw2⟩ + rintro s2 ⟨⟨⟨σ2, hm2, hst2, hcdt2, hT2, hSS2, hcs2⟩, hw2⟩, -, ed2, es2, ek2⟩ + -- the root-kind caps: the rotation `sd ← sp ← ss ← Null` of the slots + have hroot : TabClosedA Z.th (L.mem s) (L.mem s2) := by + have cd : capAtA (L.mem s2) (cslotAddrA sd) = np := by + rw [capAtA_eq, ek2 _ (hsub _ hdS) hsd.symm hpd.symm, ed1] + have cp : capAtA (L.mem s2) (cslotAddrA sp) = ns := by rw [capAtA_eq, ed2] + have cs : capAtA (L.mem s2) (cslotAddrA ss) = .Null := by rw [capAtA_eq, es2] + have co : ∀ y, IsSlotA Z.th y → y ≠ cslotAddrA sd → y ≠ cslotAddrA sp → y ≠ cslotAddrA ss → + capAtA (L.mem s2) y = capAtA (L.mem s) y := fun y hy h1 h2 h3 => by + rw [capAtA_eq, capAtA_eq, ek2 _ (hsub _ hy) h3 h2, ek1 _ (hsub _ hy) h2 h1] + exact TabClosedA.of_rot hdS hpS hsS hpd.symm hsd.symm hsp.symm cd cp cs co hrp hrs refine ⟨σ1, σ2, hm1, hm2, E.j.of_slotWrites (hw1.trans1 hw2) (fun b hb' hb => footN_offA E b hb hb') hal _ - (hSS1.trans hSS2) hst2 hcdt2 (fun y hy => ?_), hT2, fun o1 o2 n hI => ?_⟩ + (hSS1.trans hSS2) hst2 hcdt2 (fun y hy => ?_) ⟨fun y hy ptr asid va mp h => ?_, hroot.root, hroot.pts.toE⟩, hT2, fun o1 o2 n hI => ?_⟩ + swap + · rcases hcs2 y hy with e | e | e + · rw [e] at h; cases h + · rcases hcs1 y hy with e' | e' | e' + · rw [e, e'] at h; cases h + · exact Or.inl ⟨y, hy, by rw [← e']; rw [e] at h; exact h⟩ + · rw [e, e'] at h + rcases hpp ptr asid va mp h with ⟨y0, hy0, hc⟩ | hu + · exact Or.inl ⟨y0, hy0, hc.trans h⟩ + · exact Or.inr hu + · rw [e] at h + rcases hps ptr asid va mp h with ⟨y0, hy0, hc⟩ | hu + · exact Or.inl ⟨y0, hy0, hc.trans h⟩ + · exact Or.inr hu · rcases hcs2 y hy with e | e | e <;> rw [e] · exact CapObjOkA.null Z · rcases hcs1 y hy with e' | e' | e' <;> rw [e'] @@ -454,6 +482,36 @@ private theorem capOk_of_capEqA {nd : Fl4SpecA64.Irq → Fl4SpecA64.ObjRef} {sl have hi := hok.1 irq hirq hsl; simp [IrqCapA, absCapA] at hi | _ => rw [← h]; exact hok +/-- **A root-kind result of `update_cap_data` is the source cap itself** (the rootOnce `copied_cap` fact for Rotate's swap). -/ +theorem objects.update_cap_data.rootA (pr : Bool) (data : U64) (c : capability.Cap) : + objects.update_cap_data pr data c ⦃ m => ∀ r, RootKindA r m → m = c ⦄ := by + have nr : ∀ {r : U64} {x : capability.Cap}, (∀ r', ¬ RootKindA r' x) → RootKindA r x → False := + fun h hk => h _ hk + cases c + case Endpoint p b sd rc g gr => + simp only [objects.update_cap_data] + split + · exact (WP.spec_ok _).2 fun r hk => by rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h + · split <;> exact (WP.spec_ok _).2 fun r hk => by + rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h + case Notification p b sd rc => + simp only [objects.update_cap_data] + split + · exact (WP.spec_ok _).2 fun r hk => by rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h + · split <;> exact (WP.spec_ok _).2 fun r hk => by + rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h + case CNode p rd gs g => + simp only [objects.update_cap_data] + refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + split + · exact (WP.spec_ok _).2 fun r hk => by rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h + · refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + refine WP.spec_bind (Pₘ := fun _ => True) (by first | p0_auto | p0_split) fun _ _ => ?_ + exact (WP.spec_ok _).2 fun r hk => by rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h + all_goals (simp only [objects.update_cap_data]; exact (WP.spec_ok _).2 fun _ _ => rfl) + /-- An untyped cap is kept by `update_cap_data true` (Rotate's and Mutate's preserving update). -/ theorem update_utA {c c' : capability.Cap} {w : Fl4SpecA64.Data} (hu : isUtA c = true) (h : absCapA c' = Fl4SpecA64.updateCapData true w (absCapA c)) : absCapA c' = absCapA c := by @@ -546,6 +604,8 @@ theorem decode_rotate_relA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a update_relA true a5 (capA st s (cslotAddrA sl)) hsca.1 (CapRt.decodeF_encWf _ _) obtain ⟨np, hnp, hnpw, hnpa, hnpe, hnpv, -, hnpsh⟩ := update_relA true a2 (capA st s (cslotAddrA pl)) hpca.1 (CapRt.decodeF_encWf _ _) + have hrks : KindEqA ns (capA st s (cslotAddrA sl)) := objects.update_cap_data.kindEqA3 hns + have hrkp : KindEqA np (capA st s (cslotAddrA pl)) := objects.update_cap_data.kindEqA3 hnp set nsA := Fl4SpecA64.updateCapData true a5.bv srcA set npA := Fl4SpecA64.updateCapData true a2.bv pivA have hnsEq : CapEqA ns nsA := capEqA_update hsrcEq hnsa @@ -627,7 +687,8 @@ theorem decode_rotate_relA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a simp only [show decide (cslotAddrA sl = cslotAddrA dsl) = true from decide_eq_true e3, ↓reduceIte] obtain ⟨s3, hs3, σ', hm, hJ, hT', hI⟩ := spec_existsA (cap_swap_jA E2 hT2 hsub hnul2 hAs hAp (fun h => hne1 h.symm) hsn2 hpn2 (hcan _ hsO) (hcan _ hpO) ⟨hnsw, hnsEq⟩ ⟨hnpw, hnpEq⟩ hnse hnpe hnsn hnpn - hals halp hos hop) + hals halp hos hop (PtSrcA.of_shape hsS hshs) (PtSrcA.of_shape hpS hshp) + (by rw [capAtA_eq, hsc2]; exact hrks) (by rw [capAtA_eq, hpc2]; exact hrkp)) rw [hs3]; simp only [bind_ok] rw [WP.spec_ok] refine ⟨.rotateCall nsA npA sl pl dsl, hinv, _, hset, σ', _, ?_, hJ, hT', @@ -644,7 +705,8 @@ theorem decode_rotate_relA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a rw [capAtA_eq, hOK.capA hdO]; exact hdd e3' have hsp : cslotAddrA sl ≠ cslotAddrA pl := fun h => hne1 (cslotAddrA_inj hP hAp hAs h.symm) obtain ⟨s4, hs4, L3⟩ := spec_existsA (cap_move2_jA E2 hT2 hsub hnul2 hAs hAp hAd hsp hsn2 hpn2 hdn2 - (hcan _ hpO) (hcan _ hdO) ⟨hnpw, hnpEq⟩ hnpe hnpn halp hop ⟨hnsw, hnsEq⟩ hnse hnsn hals hos) + (hcan _ hpO) (hcan _ hdO) ⟨hnpw, hnpEq⟩ hnpe hnpn halp hop ⟨hnsw, hnsEq⟩ hnse hnsn hals hos (PtSrcA.of_shape hpS hshp) (PtSrcA.of_shape hsS hshs) + (by rw [capAtA_eq, hpc2]; exact hrkp) (by rw [capAtA_eq, hsc2]; exact hrks)) obtain ⟨s5, hs5, σ1', σ', hm1, hm2, hJ, hT', hI⟩ := spec_existsA L3 rw [hs4]; simp only [bind_ok] rw [hs5]; simp only [bind_ok] diff --git a/proofs/Fl4ProofsA64/P3/DelAsidA.lean b/proofs/Fl4ProofsA64/P3/DelAsidA.lean index 420a97625..142b37c93 100644 --- a/proofs/Fl4ProofsA64/P3/DelAsidA.lean +++ b/proofs/Fl4ProofsA64/P3/DelAsidA.lean @@ -13,6 +13,7 @@ Hypotheses: `hsplit` (the entry naming the root's object is the root's own tagge (the current thread is a TCB). [P] `ArchKeepsA`, `DelArchA`, `P0.ArchTotal`. New module. -/ import Fl4ProofsA64.P3.VsAssignA +import Fl4ProofsA64.P3.VsUniqClearA import Fl4ProofsA64.P3.DelAsidSpecA import Fl4ProofsA64.P3.DelRecA @@ -171,7 +172,8 @@ theorem pool_write_jointA (E : JEntTA st AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) (hunmS2 : tagA word = 1 → ((∀ j : U64, j.val < 1024 → dBitA (L.mem s2 (peAF (untagA word) j)) 0 = false) ∧ ∀ es, σ2.kheap (specPtr (untagA word)) = some (.archObj (.ext (.stage2Root es))) → - ∀ j : Fin 1024, es j = .invalidPTE)) : + ∀ j : Fin 1024, es j = .invalidPTE)) + (hw0 : word = 0#u64) : let σ3 := poolSetA σ2 p (Function.update f (BitVec.ofNat 9 i.val) (poolEntA word)) let s3 := L.wr s2 (peAF p i) word JAtZAX (L := L) AR Z s3 a σ3 m ∧ OSKeep st OS s2 s3 ∧ TyKeepA σ2 σ3 := by @@ -209,11 +211,18 @@ theorem pool_write_jointA (E : JEntTA st AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) fun e => hn' (Option.some.inj (hq.symm.trans (e ▸ hk))) 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 + have hVU := VsUniqA.of_clearPool (mem' := L.mem (L.wr s2 (peAF p i) word)) + (σ' := poolSetA σ2 p (Function.update f (BitVec.ofNat 9 i.val) (poolEntA word))) + J.1.vsu J.1.vs J.1.ext hp hi hk (J.1.vs.pool_offA J.1.ext.ypp hp hi hn) + (fun b hb hne => hmem b (hall b (.nslot b (.vs b hb))) hne) + (fun b hb => hmem b (hall b (.nslot b (.ext b hb))) (hExt b hb)) + ((L.mem_wr_same w.al).trans hw0) (by subst hw0; simp [poolSetA, setObjA, poolEntA]) + (fun q hq => poolSetA_get hq) rfl (fun y hy => Hm.cap (Or.inl hy)) refine ⟨J.of_sameVsA (σ' := poolSetA σ2 p (Function.update f (BitVec.ofNat 9 i.val) (poolEntA word))) (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, + (fun _ h1 h2 => ⟨h1, h2⟩) (by rw [L.ksb_wr]; exact hVR) hER (by rw [L.ksb_wr]; exact hVU), osKeep_tabWriteA E.ent.os (fun ⟨y, hy, ho⟩ => w.os y hy ho) hmem, TyKeepA.upd hk (fun _ _ e => by cases e) (fun _ e => by cases e)⟩ · obtain ⟨cs, he, _, _⟩ := J.1.st.cnode q r hq @@ -376,7 +385,7 @@ theorem delete_asid_jA {ar : machine.Arch A} (hA : P0.ArchTotal ar) (K : ArchKee exact hr0 (hw.symm.trans h) have J := pool_write_jointA E hsub (s2 := s) (σ2 := σ) E.j rfl rfl (p := pool) (i := asid &&& 511#u64) (word := 0#u64) hP hlo hW hk (Or.inl rfl) hzero - ⟨fun _ h => (h rfl).elim, fun h => by simp [tagA] at h⟩ (fun h => by simp [tagA] at h) + ⟨fun _ h => (h rfl).elim, fun h => by simp [tagA] at h⟩ (fun h => by simp [tagA] at h) rfl dsimp only at J obtain ⟨J, -, -⟩ := J rw [poolEntA_zero, ← hbits] at J diff --git a/proofs/Fl4ProofsA64/P3/DelAsidPoolA.lean b/proofs/Fl4ProofsA64/P3/DelAsidPoolA.lean index 9df4788d1..82fdd253f 100644 --- a/proofs/Fl4ProofsA64/P3/DelAsidPoolA.lean +++ b/proofs/Fl4ProofsA64/P3/DelAsidPoolA.lean @@ -415,7 +415,18 @@ theorem JAtZAX.of_tabClearA (E : JEntTA st AR Z H OS U Ac Pp Tb Lv ia ie s a σ rw [hcap y (Or.inl hy)] at e exact J0.pml y hy q mp asid e vs := hVs - ext := hExt } + ext := hExt + vsu := by + rw [hks] + exact VsUniqA.of_clearTab (mem' := L.mem s') (σ' := dropPoolA σ (BitVec.ofNat 7 i.val)) J0.vsu J0.vs J0.ext hi + hksFit (fun b hb hne => hfr b (.nslot b (.vs b hb)) hne) hAt0 (fun q j hj hq => A.pg q j hj (Or.inr hq)) + (fun b hb => hfn b (.ext b hb) (A.extW b hb)) + (fun k q h => by + simp only [dropPoolA] at h + by_cases e : k = BitVec.ofNat 7 i.val + · rw [e, Function.update_self] at h; cases h + · rwa [Function.update_of_ne e] at h) + (fun q => rfl) (fun y hy => hcap y (Or.inl hy)) } refine ⟨J', ⟨fun v hv' => ?_, fun q x e => V.back q x e, fun t ht => ?_, fun y hy q e => V.cap y hy q (by rw [← hcap y (Or.inl hy)]; exact e)⟩, ⟨fun r hr => X0.obj r hr, fun q es e => X0.back q es e, diff --git a/proofs/Fl4ProofsA64/P3/DelBufKeepA.lean b/proofs/Fl4ProofsA64/P3/DelBufKeepA.lean index a9a7590be..179550bc2 100644 --- a/proofs/Fl4ProofsA64/P3/DelBufKeepA.lean +++ b/proofs/Fl4ProofsA64/P3/DelBufKeepA.lean @@ -218,7 +218,8 @@ theorem lookup_frameA {t w : U64} {rcv : Bool} (hl : msg.lookup_ipc_buffer st s /-- **The tracked buffers still pinned after a step that keeps or nulls each buffer slot still cover the IPC buffers**: a surviving thread's buffer is pinned by its own slot, whose frame is the heap object of the old pin. -/ theorem BufCover.pinA {Bf : Set (U64 × Fl4SpecA64.Word)} (hH : HeapOK H) (hF : FrameOK st H OS s) - (C : BufCover st T Bf r σ') (hO : ∀ t ∈ T, sbWordA t ∈ OS) + (C : BufCover st T Bf r σ') + (hO : ∀ t ∈ T, sbWordA t ∈ OS) (k : ∀ t ∈ T, capA st r (sbWordA t) = capA st s (sbWordA t) ∨ capA st r (sbWordA t) = .Null) (pin : ∀ bp ∈ Bf, BufPinA st T OS s bp.1) : BufCover st T {bp | bp ∈ Bf ∧ BufPinA st T OS r bp.1} r σ' := by @@ -231,31 +232,29 @@ theorem BufCover.pinA {Bf : Set (U64 × Fl4SpecA64.Word)} (hH : HeapOK H) (hF : · exact e.symm.trans hc · rw [e] at hc; cases hc obtain ⟨bits, hbits⟩ : ∃ bits, size.bits = ok bits := by cases size <;> exact ⟨_, rfl⟩ - have hp : H ptr = some (.other bits.val) := hF _ (hO t ht) ptr size rights x1 x2 x3 x4 hcs bits hbits - have fit : ptr.val + 2 ^ bits.val ≤ 2 ^ 64 := by - have := hH.fits ptr _ hp; simpa only [HKind.bits] using this + have hpF : FrAt H ptr bits := hF _ (hO t ht) ptr size rights x1 x2 x3 x4 hcs bits hbits + have fit : ptr.val + 2 ^ bits.val ≤ 2 ^ 64 := hpF.fits hH obtain ⟨w1, w2⟩ := hin bits hbits fit - obtain ⟨t', -, hO', ptr', size', rights', y1, y2, y3, y4, bits', hc', hbits', hw'⟩ := pin _ hm - have hp' : H ptr' = some (.other bits'.val) := hF _ hO' ptr' size' rights' y1 y2 y3 y4 hc' bits' hbits' - have e0 : bufW w 0#u64 = w := by - apply UScalar.eq_of_val_eq + obtain ⟨hw1024, t', -, hO', ptr', size', rights', y1, y2, y3, y4, bits', hc', hbits', hw'⟩ := pin _ hm + have h10 : 10 ≤ bits.val := by + cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← ok_inj_ff hbits] <;> simp + have hpal : ptr.val % 2 ^ bits.val = 0 := hpF.al hH + have hdvd : 1024 ∣ 2 ^ bits.val := by + rw [show (1024 : Nat) = 2 ^ 10 by norm_num] + exact Nat.pow_dvd_pow 2 h10 + have hP : 2 ^ bits.val % 1024 = 0 := Nat.mod_eq_zero_of_dvd hdvd + have hpal' : ptr.val % 1024 = 0 := by + rw [← Nat.mod_mod_of_dvd ptr.val hdvd, hpal] + have hw1024' : w.val % 1024 = 0 := hw1024 + have w2' : w.val + 1024 ≤ ptr.val + 2 ^ bits.val := by omega + refine ⟨hw1024', t, ht, hO t ht, ptr, size, rights, x1, x2, x3, x4, bits, hc, hbits, fun j hj => ?_⟩ + obtain ⟨hal_j, -, -⟩ := hw' j hj + have hv : (bufW w j).val = w.val + 8 * j.val := by unfold bufW - simp [core.num.U64.wrapping_add_val_eq, core.num.U64.wrapping_mul_val_eq] - obtain ⟨-, v1, v2⟩ := hw' 0#u64 (by simp) - rw [e0] at v1 v2 - have ep : ptr = ptr' := by - by_contra ne - have := hH.disj ptr _ ptr' _ hp hp' ne - simp only [HKind.bits] at this - omega - subst ep - have eb : bits.val = bits'.val := by - rw [hp] at hp' - injection hp' with h - injection h - refine ⟨t, ht, hO t ht, ptr, size, rights, x1, x2, x3, x4, bits, hc, hbits, fun j hj => ?_⟩ - rw [eb] - exact hw' j hj + have hj8 : (core.num.U64.wrapping_mul j 8#u64).val = j.val * 8 := by + simp [core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits]; omega + rw [wa_valP, hj8, Nat.mod_eq_of_lt (by omega)]; omega + exact ⟨hal_j, (by show ptr.val ≤ (bufW w j).val; omega), (by show (bufW w j).val < ptr.val + 2 ^ bits.val; omega)⟩ end diff --git a/proofs/Fl4ProofsA64/P3/DelIrqFrA.lean b/proofs/Fl4ProofsA64/P3/DelIrqFrA.lean index 9d055d7bd..90ffc38d3 100644 --- a/proofs/Fl4ProofsA64/P3/DelIrqFrA.lean +++ b/proofs/Fl4ProofsA64/P3/DelIrqFrA.lean @@ -331,7 +331,15 @@ theorem JAtZAX.of_schedI {AR : A → HwRootA → Prop} {Z : XSetsA} {s s' : S} { rcases hq with hq | hq | hq · obtain ⟨f, hk, -⟩ := J.vs.pool q hq; rw [hk] at h; cases h; rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e · obtain ⟨es, hk, -⟩ := J.ext.s2root q hq; rw [hk] at h; cases h; rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e - · obtain ⟨pt, hk, -⟩ := J.ext.s2pt q hq; rw [hk] at h; cases h; rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e } + · obtain ⟨pt, hk, -⟩ := J.ext.s2pt q hq; rw [hk] at h; cases h; rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e + vsu := J.vsuOf H.ksb (fun b hb => by + rcases hb with hb | hb + · exact H.ext b hb + · exact H.vs b hb) + ⟨HS.asid, fun p hp => HS.other (fun x h => J.vs.not_tcb (Or.inl ⟨p, hp, rfl⟩) h) (fun o ho h => by + obtain ⟨f, hk, -⟩ := J.vs.pool p hp; rw [hk] at h; cases h + rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e)⟩ + (PtClosedA.of_cap fun y hy => Or.inl (hcap y (Or.inl hy))) } have hsl : ∀ y, IsSlotA Z.th y → capAtA (L.mem s') y = capAtA (L.mem s) y := fun y hy => hcap y (Or.inl hy) refine ⟨J', ?_, ?_, ?_⟩ · refine ⟨fun v hv => ?_, fun p x e => V.back p x (HS.back e (fun _ h => by cases h) (fun h => by rcases h with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e)), diff --git a/proofs/Fl4ProofsA64/P3/DelIrqWrA.lean b/proofs/Fl4ProofsA64/P3/DelIrqWrA.lean index fa4edbef7..b02e469db 100644 --- a/proofs/Fl4ProofsA64/P3/DelIrqWrA.lean +++ b/proofs/Fl4ProofsA64/P3/DelIrqWrA.lean @@ -428,7 +428,7 @@ theorem JStage3TA.of_irqWr {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} rw [HS.orig] exact J.nullOrig sl (by rw [← SpecSchedIA.specCapAt HS sl]; exact h) thPos := fun p z h => J.thPos p z h - frBase := J.frBase.keepA capE + frBase := J.frBase.keepOS osk devFr := J.devFr.keepA capE fun p dev pg h => HS.keep h (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e) finCov := J.finCov.keepA diff --git a/proofs/Fl4ProofsA64/P3/DelNtfnRecA.lean b/proofs/Fl4ProofsA64/P3/DelNtfnRecA.lean index 8c6cbab06..d438c4f7c 100644 --- a/proofs/Fl4ProofsA64/P3/DelNtfnRecA.lean +++ b/proofs/Fl4ProofsA64/P3/DelNtfnRecA.lean @@ -66,8 +66,7 @@ theorem DStateA.keepOSA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {O (D.tree.keepO k) D.sub (fun y hy hn => (caps y hy).trans (D.nul y hy hn)) ?_ refine { cov := J.finCov - fr := D.fr.of (fun y hy f => ⟨y, hy, by rw [← caps y hy]; exact f, by rw [caps y hy]⟩) - (fun y hy f => ⟨y, hy, by rw [← caps y hy]; exact f, by rw [caps y hy]⟩) + fr := D.fr.keepOS k irq := IrqRunA.ofP1 J.j5.1.2.1 zw := DelInvA.of D (fun y hy p zt n h => ?_) } have hyO := D.sub y hy diff --git a/proofs/Fl4ProofsA64/P3/DelPoolKeepA.lean b/proofs/Fl4ProofsA64/P3/DelPoolKeepA.lean index 5d81f5c37..86ce8b6a1 100644 --- a/proofs/Fl4ProofsA64/P3/DelPoolKeepA.lean +++ b/proofs/Fl4ProofsA64/P3/DelPoolKeepA.lean @@ -235,9 +235,7 @@ theorem delVs_zeroKeepHwA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} have site : DelSiteA st Z.th OS (L.wr s (peAF p i) 0#u64) σ' Z.G.chains := { cov := ⟨fun q r cs hk hw => D.cov.cnode q r cs (HS.back hk (fun _ e => by cases e)) hw, fun q x hk => D.cov.tcb q x (HS.back hk (fun _ e => by cases e))⟩ - fr := fun y hy z hz h1 h2 => by - rw [capE y hy] at h1; rw [capE z hz] at h2; rw [capE y hy, capE z hz] - exact D.fr y hy z hz h1 h2 + fr := D.fr.keepOS osk irq := Fl4ProofsA64.P3.IrqRunA.keepIrq D.irq fun y hy _ => by rw [capE y ((D.lk.members y).1 hy).1] zw := fun y hy q zt k hc => by rw [capE y (D.sub y hy)] at hc diff --git a/proofs/Fl4ProofsA64/P3/DelPpA.lean b/proofs/Fl4ProofsA64/P3/DelPpA.lean index 00854a23a..5531c6854 100644 --- a/proofs/Fl4ProofsA64/P3/DelPpA.lean +++ b/proofs/Fl4ProofsA64/P3/DelPpA.lean @@ -75,9 +75,7 @@ theorem DelXA.stepPpA {s s' : S} {a' : A} {σ σ' : State Unit} {G : MdbGhostA} have hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s' y = .Null := fun y hy hn => (capE y hy).trans (D.nul y hy hn) have site : DelSiteA st Z.th OS s' σ' G.chains := { cov := J'.finCov - fr := fun y hy z hz h1 h2 => by - rw [capE y hy] at h1; rw [capE z hz] at h2; rw [capE y hy, capE z hz] - exact D.fr y hy z hz h1 h2 + fr := D.fr.keepOS osk irq := Fl4ProofsA64.P3.IrqRunA.keepIrq D.irq fun y hy _ => by rw [capE y ((D.lk.members y).1 hy).1] zw := fun y hy q zt k hc => by rw [capE y (D.sub y hy)] at hc diff --git a/proofs/Fl4ProofsA64/P3/DelRec6A.lean b/proofs/Fl4ProofsA64/P3/DelRec6A.lean index 769aac681..5eb2712de 100644 --- a/proofs/Fl4ProofsA64/P3/DelRec6A.lean +++ b/proofs/Fl4ProofsA64/P3/DelRec6A.lean @@ -51,7 +51,7 @@ structure Std6GA (Ag : Set U64) (Z : XSetsA) (H : Heap) (OS : Set U64) (Bf : Set runBack : ∀ t ∈ Z.T, L.mem s (runVcpuA t) ≠ 0#u64 → L.mem s (wa (L.mem s (runVcpuA t)) 24#u64) = t vcSnap : VcpuStateSnapA Z.V (L.mem s) σ vcOS : ∀ b, VcW Z.V b → ¬ InOS OS b - userFr : UserFrSpecA st OS s σ + userFr : UserFrSpecA st H OS s σ frTh : FrThA st Z.th OS s bfSpec : ∀ bp ∈ Bf, bp.2 = specPtr bp.1 vcSym1 : VcSym1A st Z.T s @@ -105,9 +105,10 @@ theorem JStage3TA.frwA {R7 : Set U64 → JSlotA S} ((L.ksb s).val + 223488 ≤ b.val ∨ b.val < (L.ksb s).val) := by obtain ⟨u, hu, ptr, size, rights, x1, x2, x3, x4, bits, hc, hbits, h1, h2⟩ := lv obtain ⟨-, -, -, -, -, ⟨-, frOK⟩, -⟩ := J.j7 - have hH : H ptr = some (.other bits.val) := frOK u hu ptr size rights x1 x2 x3 x4 hc bits hbits + have hH : FrAt H ptr bits := frOK u hu ptr size rights x1 x2 x3 x4 hc bits hbits obtain ⟨hos, -, hreg⟩ := fo u hu ptr size rights x1 x2 x3 x4 hc bits hbits - refine ⟨ptr, bits.val, hH, ⟨h1, by simpa [HKind.bits] using h2⟩, ?_, ?_⟩ + obtain ⟨q, z, hq, hbz, hq1, hq2⟩ := hH.obj + refine ⟨q, z, hq, ⟨by omega, by simp only [HKind.bits]; omega⟩, ?_, ?_⟩ · rintro ⟨y, hy, y1, y2⟩ rcases hos y hy with e | e <;> omega · rcases hreg with e | e <;> omega @@ -228,7 +229,7 @@ theorem Std6GA.keepA (h : Std6GA st Ag Z H OS Bf s σ) (R : VcRunA st Z.T Z.V s) runBack := runBack_keepA R.run hr h24 h.runBack vcSnap := h.vcSnap.keepA hv hk vcOS := h.vcOS - userFr := UserFrSpecA.keepA capE dp h.userFr + userFr := UserFrSpecA.keepA capE (fun _ _ e => e) dp h.userFr frTh := h.frTh.keepA capE fun _ _ e => e bfSpec := h.bfSpec vcSym1 := h.vcSym1.keepA R ht h0 @@ -278,7 +279,8 @@ theorem Std6GA.stepA (h : Std6GA st Ag Z H OS Bf s σ) (R : VcRunA st Z.T Z.V s) rcases caps y hy with c | ⟨_, _, _, c⟩ | ⟨z, hz, c⟩ · rw [c] at e; cases e · rw [c] at e; cases e - · exact dp _ _ _ (h.userFr z hz p size rights mapped ept asid va (c.symm.trans e)) + · obtain ⟨b, pg, hb, hk, h1, h2⟩ := h.userFr z hz p size rights mapped ept asid va (c.symm.trans e) + exact ⟨b, pg, hb, dp _ _ _ hk, h1, h2⟩ frTh := fun y hy p size rights x1 x2 x3 x4 bits e hb => by rcases caps y hy with c | ⟨_, _, _, c⟩ | ⟨z, hz, c⟩ · rw [c] at e; cases e diff --git a/proofs/Fl4ProofsA64/P3/DelStepAsmA.lean b/proofs/Fl4ProofsA64/P3/DelStepAsmA.lean index be7766a7f..ade98018d 100644 --- a/proofs/Fl4ProofsA64/P3/DelStepAsmA.lean +++ b/proofs/Fl4ProofsA64/P3/DelStepAsmA.lean @@ -135,8 +135,24 @@ theorem swapHyp_delPA {Φ : Set (U64 × Fl4SpecA64.Word) → S → State Unit have hpa : cslotAddrA (homeSlA p zt) = p := hzok.addr have hp : p ∈ OS := by rw [← hpa]; exact D.mem_slot hAp have kb : L.ksb s = L.ksb s0 := hcore.1 + have hpS : IsSlotA Z.th p := by have := hAp.isSlot D.place; rwa [hpa] at this have jx : JAtZAX (L := L) AR { Z with G := swGA G p (cslotAddrA sl), Q := Q, R := R, hw := hw } s' a σ' m := by - refine (delFoot_loopA F G Q R hw).slotWrites hcore J.j w HS D'.rel D'.cdt fun y hy => ?_ + refine (delFoot_loopA F G Q R hw).slotWrites hcore J.j w HS D'.rel D'.cdt (fun y hy => ?_) + ⟨(fun y hy ptr asid va mp h => by + change capA st s' y = _ at h + rw [hcap y (D.sub y hy)] at h + split_ifs at h + · exact Or.inl ⟨p, by rw [← hpa]; exact hAp.isSlot D.place, h⟩ + · exact Or.inl ⟨_, hA.isSlot D.place, h⟩ + · exact Or.inl ⟨y, hy, h⟩), + (TabClosedA.of_exch (a := cslotAddrA sl) (b := p) (hA.isSlot D.place) hpS + (by rw [capAtA_eq, capAtA_eq, hcap _ (D.sub _ (hA.isSlot D.place)), if_pos rfl]) + (by rw [capAtA_eq, capAtA_eq, hcap _ (D.sub _ hpS), if_neg hne, if_pos rfl]) + (fun y hy h1 h2 => by rw [capAtA_eq, capAtA_eq, hcap _ (D.sub _ hy), if_neg h1, if_neg h2])).root, + (TabClosedA.of_exch (a := cslotAddrA sl) (b := p) (hA.isSlot D.place) hpS + (by rw [capAtA_eq, capAtA_eq, hcap _ (D.sub _ (hA.isSlot D.place)), if_pos rfl]) + (by rw [capAtA_eq, capAtA_eq, hcap _ (D.sub _ hpS), if_neg hne, if_pos rfl]) + (fun y hy h1 h2 => by rw [capAtA_eq, capAtA_eq, hcap _ (D.sub _ hy), if_neg h1, if_neg h2])).pts.toE⟩ show CapObjOkA _ (capA st s' y) rw [hcap y (D.sub y hy)] split_ifs @@ -302,7 +318,15 @@ theorem zombieHyp_delPA {Φ : Set (U64 × Fl4SpecA64.Word) → S → State Unit have hxs := hA.isSlot D.place have kb : L.ksb s = L.ksb s0 := hcore.1 have jx : JAtZAX (L := L) AR { Z with G := G, Q := Q, R := R, hw := hw } s' a σ' m := by - refine (delFoot_loopA F G Q R hw).slotWrites hcore J.j w HS D'.rel D'.cdt fun y hy => ?_ + refine (delFoot_loopA F G Q R hw).slotWrites hcore J.j w HS D'.rel D'.cdt (fun y hy => ?_) + (PtClosedA.of_cap fun y hy => by + by_cases e : y = cslotAddrA sl + · refine Or.inr ?_ + rw [e] + change NoVsCapA (capA st s' (cslotAddrA sl)) + rw [hc] + first | exact NoVsCapA.null | exact NoVsCapA.zombie _ _ _ + · exact Or.inl (hcap y (D.sub y hy) e)) show CapObjOkA _ (capA st s' y) by_cases e : y = cslotAddrA sl · rw [e, hc] @@ -534,7 +558,7 @@ theorem other_of_nonfinalA {th : TypedHeapA} {G : List (List U64)} {s : S} {σ : rcases h with h | h · exact ⟨h, e⟩ · exact absurd (hc.symm ▸ e.symm : ptrA (capA st s (cslotAddrA sl)) = ptrA (capA st s y)) - (F.fr y hy _ hx h (hc.symm ▸ hk)) + (F.fr.1 y hy _ hx h (hc.symm ▸ hk)) rw [habs] at hn simp only [not_forall, not_not] at hn obtain ⟨w, hw, ne, kw, pw⟩ := hn @@ -685,7 +709,15 @@ theorem emptyHyp_delPA {Rv : S → A → State Unit → MdbGhostA → U64 → Pr have hx : cslotAddrA sl ∈ OS := D.mem_slot hA have kb : L.ksb s = L.ksb s0 := hcore.1 have jx : JAtZAX (L := L) AR { Z with G := remGA G (cslotAddrA sl), Q := Q, R := R, hw := hw } s' a σ' m := by - refine (delFoot_loopA F G Q R hw).slotWrites hcore J.j w HS D'.rel D'.cdt fun y hy => ?_ + refine (delFoot_loopA F G Q R hw).slotWrites hcore J.j w HS D'.rel D'.cdt (fun y hy => ?_) + (PtClosedA.of_cap fun y hy => by + by_cases e : y = cslotAddrA sl + · refine Or.inr ?_ + rw [e] + change NoVsCapA (capA st s' (cslotAddrA sl)) + rw [h0] + first | exact NoVsCapA.null | exact NoVsCapA.zombie _ _ _ + · exact Or.inl (hcap y (D.sub y hy) e)) show CapObjOkA _ (capA st s' y) by_cases e : y = cslotAddrA sl · rw [e, h0]; exact CapObjOkA.null _ diff --git a/proofs/Fl4ProofsA64/P3/DelSuspendLiveA.lean b/proofs/Fl4ProofsA64/P3/DelSuspendLiveA.lean index 0e740e234..6c8af18bc 100644 --- a/proofs/Fl4ProofsA64/P3/DelSuspendLiveA.lean +++ b/proofs/Fl4ProofsA64/P3/DelSuspendLiveA.lean @@ -119,7 +119,7 @@ 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] (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z OS Bf s σ) + (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z H OS Bf 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) diff --git a/proofs/Fl4ProofsA64/P3/DelTabKeepA.lean b/proofs/Fl4ProofsA64/P3/DelTabKeepA.lean index cd431d82b..df5be3608 100644 --- a/proofs/Fl4ProofsA64/P3/DelTabKeepA.lean +++ b/proofs/Fl4ProofsA64/P3/DelTabKeepA.lean @@ -236,9 +236,7 @@ theorem delTab_zeroKeepHwA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} have site : DelSiteA st Z.th OS (L.wr s (atAF (L.ksb s) i) 0#u64) σ' Z.G.chains := { cov := ⟨fun q r cs hk hw => D.cov.cnode q r cs (HS.back hk (fun _ e => by cases e)) hw, fun q x hk => D.cov.tcb q x (HS.back hk (fun _ e => by cases e))⟩ - fr := fun y hy z hz h1 h2 => by - rw [capE y hy] at h1; rw [capE z hz] at h2; rw [capE y hy, capE z hz] - exact D.fr y hy z hz h1 h2 + fr := D.fr.keepOS osk irq := Fl4ProofsA64.P3.IrqRunA.keepIrq D.irq fun y hy _ => by rw [capE y ((D.lk.members y).1 hy).1] zw := fun y hy q zt k hc => by rw [capE y (D.sub y hy)] at hc diff --git a/proofs/Fl4ProofsA64/P3/DelThrHookA.lean b/proofs/Fl4ProofsA64/P3/DelThrHookA.lean index 7db046e41..ae9152b39 100644 --- a/proofs/Fl4ProofsA64/P3/DelThrHookA.lean +++ b/proofs/Fl4ProofsA64/P3/DelThrHookA.lean @@ -240,7 +240,7 @@ theorem finHookThreadA {ipa : U64} (s0 : S) (_ : SchedValidA σ) (_ : VcpuStateSnapA Z'.V (L.mem s) σ) (_ : VcSym1A st Z'.T s) (_ : VcSym2A st Z'.V s) (_ : ∀ v ∈ Z'.V, L.mem s v ≠ 0#u64 → L.mem s (wa (L.mem s v) 3664#u64) = v) (_ : ∀ u ∈ Z'.T, L.mem s (runVcpuA u) ≠ 0#u64 → L.mem s (wa (L.mem s (runVcpuA u)) 24#u64) = u) - (_ : ∀ b, VcW Z'.V b → ¬ InOS OS b) (_ : FrOff st Z'.Cs OS (L.ksb s) s) (_ : UserFrSpecA st OS s σ) (_ : FrThA st Z'.th OS s) (_ : ∀ bp ∈ Bf, bp.2 = specPtr bp.1) + (_ : ∀ b, VcW Z'.V b → ¬ InOS OS b) (_ : FrOff st Z'.Cs OS (L.ksb s) s) (_ : UserFrSpecA st H OS s σ) (_ : FrThA st Z'.th OS s) (_ : ∀ bp ∈ Bf, bp.2 = specPtr bp.1) (_ : Clock a σ.machineState) (_ : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) (_ : ∀ a' ms (vc : U64), Clock a' ms → ar.vcpu_flush a' vc ⦃ a'' => Clock a'' ms ⦄) @@ -261,7 +261,7 @@ theorem finHookThreadA {ipa : U64} (s0 : S) (∀ v ∈ Z'.V, L.mem res.1 v ≠ 0#u64 → L.mem res.1 (wa (L.mem res.1 v) 3664#u64) = v) ∧ (∀ u ∈ Z'.T, L.mem res.1 (runVcpuA u) ≠ 0#u64 → L.mem res.1 (wa (L.mem res.1 (runVcpuA u)) 24#u64) = u) ∧ - UserFrSpecA st OS res.1 σ' ∧ + UserFrSpecA st H OS res.1 σ' ∧ Clock res.2 σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ diff --git a/proofs/Fl4ProofsA64/P3/DelZeroKeepA.lean b/proofs/Fl4ProofsA64/P3/DelZeroKeepA.lean index 4b552f330..7ea1a2616 100644 --- a/proofs/Fl4ProofsA64/P3/DelZeroKeepA.lean +++ b/proofs/Fl4ProofsA64/P3/DelZeroKeepA.lean @@ -313,9 +313,7 @@ theorem delVs_zeroKeepA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {O have site : DelSiteA st Z.th OS (L.wr s (peAF p i) 0#u64) σ' Z.G.chains := { cov := ⟨fun q r cs hk hw => D.cov.cnode q r cs (HS.back hk (fun _ e => by cases e)) hw, fun q x hk => D.cov.tcb q x (HS.back hk (fun _ e => by cases e))⟩ - fr := fun y hy z hz h1 h2 => by - rw [capE y hy] at h1; rw [capE z hz] at h2; rw [capE y hy, capE z hz] - exact D.fr y hy z hz h1 h2 + fr := D.fr.keepOS osk irq := Fl4ProofsA64.P3.IrqRunA.keepIrq D.irq fun y hy _ => by rw [capE y ((D.lk.members y).1 hy).1] zw := fun y hy q zt k hc => by rw [capE y (D.sub y hy)] at hc diff --git a/proofs/Fl4ProofsA64/P3/ExtMapFrA.lean b/proofs/Fl4ProofsA64/P3/ExtMapFrA.lean index 6c1a5ff42..752a0cdc3 100644 --- a/proofs/Fl4ProofsA64/P3/ExtMapFrA.lean +++ b/proofs/Fl4ProofsA64/P3/ExtMapFrA.lean @@ -19,6 +19,7 @@ followed by `set_thread_state Restart` and `performExtVSpace (.map …)`, with ` Named premises: `ArchKeepsA` [P], `S2IpaE` [P] (standing). No new named premise. -/ +import Fl4ProofsA64.P3.VsLeafShrA import Fl4ProofsA64.P3.VsFlushA open Aeneas Aeneas.Std Result @@ -1233,11 +1234,13 @@ theorem s2_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) have finish (ew : U64) (newC : capability.Cap) (newSC : ArchCap) (pte : PTE) (hEnc : CapRt.EncWf newC) (hca : CapRelA newC (.archObjectCap newSC)) (hnn : newC ≠ .Null) (hUA : UA newC (.Frame fp sz rt dev mp e asid va)) + (hnpt : ∀ x a' v' m', newC ≠ .PageTable x m' a' v') (hObj : CapObjOkA Z newC) (hpt : ∀ p a v, newC ≠ .PageTable p true a v) (hfe : CapFinEqA newC (.Frame fp sz rt dev mp e asid va)) (hpte : DescRelE (G2E Z.T2 Z.Sh2) pos.shift ew pte ∧ S2AttrE pos.shift ew pte) (hnotPt : ∀ ppn, pte ≠ .pageTablePTE ppn) - (hInv : D = ({(.ok (.extVSpace (.map newSC cte pte pos.slot)), σ)}, False)) : + (hInv : D = ({(.ok (.extVSpace (.map newSC cte pte pos.slot)), σ)}, False)) + (hnrt : NoRootKindA newC) : (do let ct ← sched.cur_thread st s let s1 ← sched.set_thread_state st s ct sched.TS_RESTART @@ -1246,11 +1249,13 @@ theorem s2_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) ok (core.result.Result.Ok (), s3, a1)) ⦃ res => VsTopPostA (L := L) AR Z OS m σ D s a res ⦄ := by rw [cur_thread_ok, bind_ok] obtain ⟨x, s2, σ2, _, hst, hset, hsc, hσ2, HS, hksb2, R2, hcpu2, hwi2, hJ2, hFr2⟩ := - restart_setcapJA E RS cte hab hos hEnc hca + restart_setcapJA E RS cte hab hos hEnc hca (hrt := RootSetA.of_noRoot hnrt) + (hpt := Or.inl (PtSetA.of_noPt (NoPtKindA.of_ne fun r mp a v => hnpt r a v mp))) rw [hst, bind_ok, hsc, bind_ok] have hcap0 : capA st s (cslotAddrA cte) = .Frame fp sz rt dev mp e asid va := by rw [← capAtA_eq]; exact hcap obtain ⟨J2, T2⟩ := hJ2 hTr hnul hnn (by rw [hcap0]; intro h; cases h) (by rw [hcap0]; exact hUA) hObj + (PtSrcA.nopt hnpt) have hSlotAl : Aligned lu.slot := by rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨r, j, hr, hj, hluEq, -, -⟩ · rw [hluEq]; exact peAF_alignedA (Nat.mod_eq_zero_of_dvd (E.j.1.ext.tal t ht)) hi @@ -1280,6 +1285,15 @@ theorem s2_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (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 (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) hi]; exact hp)) + (hshr_oneA (q := t) (i := i) (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) (fun w hw hne => by rw [hW.2.2 w hw, if_neg (Ne.symm hne)]) + (fun h => by + obtain ⟨pt0, hk0, -, -⟩ := J2.1.ext.s2pt t ht + refine h.notTab_of_rel hE3 rfl ht hi (pt := Fl4SpecA64.ptUpd pt0 i.bv pte) ?_ (fun ppn e => hnotPt ppn ?_) + · rw [extPtSetE hk0 (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) hi]; simp [ptSetA, setObjA] + · rw [ptApply_updA pt0 hi hi, if_pos rfl] at e; exact e) + (fun h => (s1Entry_offA J2.1.vs (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) hi + (fun m => (J2.1.ext.pgd t (Or.inl ht)).1 (Or.inr (Or.inl m))) + (fun y hy e => (J2.1.ext.pgd t (Or.inl ht)).1 (Or.inr (Or.inr ⟨y, hy, e⟩))) h).elim)) (by rw [hW.1]; exact hV3) hE3 exact hJ'.of_arA hAR' · rw [hluEq] at hW @@ -1299,6 +1313,20 @@ theorem s2_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) 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 [hW.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) + (hshr_oneA (q := q) (i := j') (by + rcases hq with h | h <;> rw [h] + exacts [Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) (J2.1.ext.xal r0 hr0)), + waWin_modA (J2.1.ext.xal r0 hr0)] : q.val % 4096 = 0) (fun w hw hne => by rw [hW.2.2 w hw, if_neg (by rw [hpeq]; exact Ne.symm hne)]) + (fun h => by + obtain ⟨es0, hk0, -⟩ := J2.1.ext.s2root r0 hr0 + refine h.notTab_of_relRoot hE3 hpeq.symm hr0 hj1k hj0 (extRootSetE hk0 j0.val pte) (fun ppn e => hnotPt ppn ?_) + simpa using e) + (fun h => (s1Entry_offA J2.1.vs (by + rcases hq with h | h <;> rw [h] + exacts [Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) (J2.1.ext.xal r0 hr0)), + waWin_modA (J2.1.ext.xal r0 hr0)] : q.val % 4096 = 0) hj' + (fun m => (J2.1.ext.pgd q (Or.inr ⟨r0, hr0, hq⟩)).1 (Or.inr (Or.inl m))) + (fun y hy e => (J2.1.ext.pgd q (Or.inr ⟨r0, hr0, hq⟩)).1 (Or.inr (Or.inr ⟨y, hy, e⟩))) h).elim)) (by rw [hW.1]; exact hV3) hE3 exact hJ'.of_arA hAR' have hoffOS : ¬ InOS OS lu.slot := by @@ -1338,11 +1366,12 @@ theorem s2_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (.frameCap (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev none) .invalidPTE (by simp only [CapRt.EncWf]; exact ⟨hcanP, by omega, by decide, Or.inl (fun _ _ _ => by simp)⟩) ⟨⟨hr1, hr3, ⟨by decide, fun _ => rfl, by simp, by simp⟩, hov⟩, rfl⟩ - (by intro h; cases h) (UA.of_shapeA rfl (by simp [isUtA])) + (by intro h; cases h) (UA.of_shapeA rfl (by simp [isUtA])) (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), fun h _ => (by cases h)⟩ (fun _ _ _ h => by cases h) (⟨by cases e <;> rfl, rfl, rfl, rfl⟩) ⟨descRelE_zero _ _, trivial⟩ (fun _ h => by cases h) hInv + (by intro r hk; rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h) · refine WP.spec_bind (make_s2_leaf_valA _ _ _ _ _ hvm23.symm) fun ew hew => ?_ obtain ⟨hne0, hDesc, hAttr⟩ := s2_leaf_relA (G := G2E Z.T2 Z.Sh2) (R := vmRightsOfA rt) rfl hvm23.symm hew FP.al FP.pa @@ -1372,12 +1401,13 @@ theorem s2_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (vmRightsOfA rt) (frameSizeOfA sz)) (by simp only [CapRt.EncWf]; exact ⟨hcanP, by omega, by omega, hipa48⟩) ⟨⟨hr1, hr3, ⟨ha16, by simp, fun _ => ha1, fun _ => rfl⟩, hov⟩, rfl⟩ - (by intro h; cases h) (UA.of_shapeA rfl (by simp [isUtA])) + (by intro h; cases h) (UA.of_shapeA rfl (by simp [isUtA])) (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), fun _ h => (by cases h)⟩ (fun _ _ _ h => by cases h) (⟨by cases e <;> rfl, rfl, rfl, rfl⟩) ⟨hDesc, hAttr⟩ (fun _ h => by unfold makeUserPte at h; cases h) hInv + (by intro r hk; rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h) -- Split on mapped_asid != 0 (which is mp = true by CapWfA) cases mp · have hz : asid = 0#u64 := UScalar.eq_of_val_eq (hmz0 rfl) @@ -1671,7 +1701,7 @@ theorem hi_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) unfold fl4_abi.consts.HIGH_VSPACE_TOP; decide have h2' : last.val < fl4_abi.consts.HIGH_VSPACE_TOP.val := Nat.lt_of_not_ge h2 have h3' : vaddr.val ≤ last.val := Nat.not_lt.mp h3 - omega⟩⟩ + omega⟩⟩ (PtSrcA.nopt fun _ _ _ _ h => by cases h) have hSlotAl : Aligned lu.slot := by rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨y, j, hy, hj, hluEq, -, -⟩ · rw [hluEq]; exact peAF_alignedA (E.j.1.vs.al_mod ht) hi @@ -1681,6 +1711,7 @@ theorem hi_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (vmRightsOfA vm) (vmRightsOfA rt) (frameSizeOfA sz) have hExtOk : ExtSlotOkX σ2 pos.slot := extSlotOk_of_hiSlotA J2.1.vs hsl have hPerf := performExtMap_memA (pte := pte) hσ2 hExtOk + have hnotPt : ∀ ppn, pte ≠ .pageTablePTE ppn := fun _ h => by unfold pte makeUserPte at h; cases h have hInv : D = ({(.ok (.extVSpace (.map (.frameCap (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev (some (asidOfA asid1, vaddr.bv))) cte pte pos.slot)), σ)}, False) := by rw [hD3] @@ -1726,6 +1757,13 @@ theorem hi_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (fun w hw hne => by rw [hW.2.2 w hw, if_neg (Ne.symm (hne i hi))]) (Or.inr (Or.inr (Or.inr ht))) (fun p hp => kheap_writeX (by rw [slotObjPtE (J2.1.vs.al_mod ht) hi]; exact hp)) + (hshr_oneA (q := t) (i := i) (J2.1.vs.al_mod ht) (fun w hw hne => by rw [hW.2.2 w hw, if_neg (Ne.symm hne)]) + (fun h => (s2Entry_offA J2.1.ext (J2.1.vs.al_mod ht) hi (Or.inr (Or.inl ht)) h).elim) + (fun h => by + obtain ⟨pt0, hk0, -, -⟩ := J2.1.vs.pt t ht + refine h.notTab_of_rel hV3 rfl ht hi (pt := Fl4SpecA64.ptUpd pt0 i.bv pte) ?_ (fun ppn e => hnotPt ppn ?_) + · rw [extPtSetE hk0 (J2.1.vs.al_mod ht) hi]; simp [ptSetA, setObjA] + · rw [ptApply_updA pt0 hi hi, if_pos rfl] at e; exact e)) (by rw [hW.1]; exact hV3) hE3 exact hJ'.of_arA hAR' · rw [hluEq] at hW @@ -1743,6 +1781,12 @@ theorem hi_map_frame_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) have hJ' := J2.of_extPageA hfa2 hTO2 hEO2 (Or.inr (Or.inl ⟨y, hy, rfl⟩)) hW.1 hW.2.1 (fun w hw hne => by rw [hW.2.2 w hw, if_neg (Ne.symm (hne j hj))]) (Or.inr (Or.inl hy)) (fun p hp => kheap_writeX (sl := .root (specPtr y) j.val) (pte := pte) hp) + (hshr_oneA (q := core.num.U64.wrapping_add y 4096#u64) (i := j) (waWin_modA (J2.1.vs.yal y hy)) (fun w hw hne => by rw [hW.2.2 w hw, if_neg (Ne.symm hne)]) + (fun h => (s2Entry_offA J2.1.ext (waWin_modA (J2.1.vs.yal y hy)) hj (Or.inr (Or.inr ⟨y, hy, rfl⟩)) h).elim) + (fun h => by + obtain ⟨l1, hk0, -⟩ := J2.1.vs.high y hy + refine h.notTab_of_relHi hV3 rfl hy hj (extRootSetE hk0 j.val pte) (fun ppn e => hnotPt ppn ?_) + simpa using e)) (by rw [hW.1]; exact hV3) hE3 exact hJ'.of_arA hAR' have hoffOS : ¬ InOS OS lu.slot := by diff --git a/proofs/Fl4ProofsA64/P3/ExtMapPtA.lean b/proofs/Fl4ProofsA64/P3/ExtMapPtA.lean index 9b0222912..8113394c3 100644 --- a/proofs/Fl4ProofsA64/P3/ExtMapPtA.lean +++ b/proofs/Fl4ProofsA64/P3/ExtMapPtA.lean @@ -17,6 +17,9 @@ against `fl4ArchDecodeInvocation` at label 47 (`ARMPageTableMap`), `decodeS2Page Named premises: `ArchKeepsA` [P], `S2IpaE` [P] (standing). No new named premise. -/ import Fl4ProofsA64.P3.ExtMapFrA +import Fl4ProofsA64.P3.VsHiMapVsuA +import Fl4ProofsA64.P3.VsWalkHiA +import Fl4ProofsA64.P3.VsS2ArmVsuA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -529,6 +532,30 @@ theorem unm_mem_keep_pt {S : Type} {st : machine.Store S} [L : LawfulStore st] rcases hT _ hcurT with h | h <;> omega rw [hw2.2.2 _ ha hnc, mem_wr_ne' sA ha hns] +/-- **Off the OS pages and the TCBs, the restart + cap write keeps memory** (the `hfr` of `Stage3PtMapShapeA`). -/ +theorem restart_memkeepA {S : Type} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS : Set U64} {s s2 : S} + (hcurT : L.curW s ∈ H.tcbs) (hfitT : ∀ t ∈ H.tcbs, t.val + 4096 ≤ 2 ^ 64) + (sA : Aligned (stA (L.curW s))) + (hw2 : WritesIn st (L.wr s (stA (L.curW s)) sched.TS_RESTART) s2 (W7.CapW H.tcbs {b | InOS OS b} ∅)) : + ∀ b, Aligned b → ¬ InOS OS b → (∀ t ∈ H.tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) → + L.mem s2 b = L.mem s b := by + intro b ha hnos hT + have hnc : ¬ W7.CapW H.tcbs {b | InOS OS b} ∅ b := by + rintro (⟨t, ht, K, hK, he⟩ | ⟨hin, -⟩) + · have hfit := hfitT t ht + have := congrArg UScalar.val he + rw [wa_valm] at this + rcases hT t ht with h | h <;> omega + · exact hnos hin + have hns : stA (L.curW s) ≠ b := fun e => by + have := congrArg UScalar.val e + have e3 : (3328#u64 : U64).val = 3328 := rfl + have hfit := hfitT _ hcurT + rw [stA_eq, wa_valm, e3] at this + rcases hT _ hcurT with h | h <;> omega + rw [hw2.2.2 _ ha hnc, mem_wr_ne' sA ha hns] + end helpers /-! ## Stage-2 `ARMPageTableMap` (`ept.map_table` vs `decodeS2PageTableMap`) -/ @@ -547,8 +574,9 @@ theorem s2_map_pt_jA {ar : machine.Arch A} (hTr : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) (cte : CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) (ptr asid0 va0 : U64) (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr false asid0 va0) + (hPC : PtCapInA Z (L.mem s)) (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (hS2 : ptr ∉ S2PgE Z.X Z.T2) (hY : ptr ∉ Z.Y) - (root asid1 ipa : U64) (hrX : root ∈ Z.X) (hactR : ActiveS2RootA Z.Pp Z.X σ root) + (root asid1 ipa : U64) (hrX : root ∈ Z.X) (hrootA : S2RootOfAsidA Z.Pp Z.X σ asid1 root) (ha1 : asid1 ≠ 0#u64) (ha16 : asid1.val < 2 ^ 16) {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} (hD : D = (NonDetE.liftME Fl4ArchInvocation.extVSpace (do @@ -561,6 +589,7 @@ theorem s2_map_pt_jA {ar : machine.Arch A} ept.map_table st ar s a root asid1 ipa ptr (cslotAddrA cte) ⦃ res => VsTopPostA (L := L) AR Z OS m σ D s a res ⦄ := by obtain ⟨nIpa, hnIpa, hnvIpa⟩ := hIpa + have hactR : ActiveS2RootA Z.Pp Z.X σ root := hrootA.active unfold ept.map_table rw [hnIpa, bind_ok, s2LimitEq_pt hnvIpa, bind_ok] -- Range check: ipa > s2IpaLimit @@ -581,6 +610,8 @@ theorem s2_map_pt_jA {ar : machine.Arch A} -- Lookup slot let pos := extLookupSlot σ s2Geom (specPtr root) ipa.bv obtain ⟨lu, hlu, hlsh, hslR⟩ := spec_ex_fd (ept_lookup_slot_mapA E.j.1.ext hrX hactR hnvIpa ipa) + have hwk := lookup_walk_s2A E.j.1.ext hrX hactR hnvIpa ipa + rw [hlu, WP.spec_ok] at hwk 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] @@ -651,7 +682,7 @@ theorem s2_map_pt_jA {ar : machine.Arch A} (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA asid1, base.bv)))) := ⟨ha16, rfl, rfl, Or.inr ⟨rfl, hbase48⟩⟩ obtain ⟨x, s2, σ2, hkx, hst, hset, hsc, hσ2, HS, hksb2, R2, hcpu2, hw2, hJ2, hFr2⟩ := - restart_setcapJA E RS cte hab hos hEnc hca + restart_setcapJA E RS cte hab hos hEnc hca (hpt := Or.inl (PtSetA.map hcap)) rw [cur_thread_ok, bind_ok, hst, bind_ok, set_cap_pt_unpack48A _ _ _ _ _ _ hbase48, hsc, bind_ok] -- make_s2_table and write rw [show layout.paddr ptr = ok (core.num.U64.wrapping_sub ptr layout.PPTR_BASE) from rfl, bind_ok] @@ -668,9 +699,10 @@ theorem s2_map_pt_jA {ar : machine.Arch A} let pte : PTE := .pageTablePTE (ppnFromPptr (specPtr ptr)) have hco : capA st s (cslotAddrA cte) = .PageTable ptr false asid0 va0 := by rw [← capAtA_eq, hcap] obtain ⟨J2, hT2⟩ := hJ2 hTr hnul (by simp) (by rw [hco]; simp) - (UA.of_shapeA (by rw [hco]; rfl) fun h => by rw [hco] at h; simp [isUtA] at h) + (by rw [hco]; exact ⟨rfl, rfl, rfl, rfl, 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), trivial⟩ + (fun _ _ _ _ e => by cases e; exact Or.inr (Or.inl ⟨UP.nt, fun h => hS2 (Or.inl h)⟩)) have hmem2 := unm_mem_keep_pt E.sq.curT (fun t ht => by have := (E.sq.tcbs t ht).fits; simp only [Nat.reducePow] at this; exact this) (by rw [stA_eq]; exact field_aligned (E.sq.tcbs _ E.sq.curT) (by simp) (by simp)) UP hw2 obtain ⟨tp, hkp, htp, hep⟩ := UP.spec @@ -803,6 +835,16 @@ theorem s2_map_pt_jA {ar : machine.Arch A} · 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 + have hVU := by + have hsubOS : ∀ y, IsSlotA Z.th y → y ∈ OS := by + obtain ⟨⟨Rp, Nt, extra', sp, P⟩, Y', hrun, hcur, hvs, hvc, hsub⟩ := RS; exact hsub + have hfr := restart_memkeepA (OS := OS) E.sq.curT + (fun t ht => by have := (E.sq.tcbs t ht).fits; simp only [Nat.reducePow] at this; exact this) + (by rw [stA_eq]; exact field_aligned (E.sq.tcbs _ E.sq.curT) (by simp) (by simp)) hw2 + have hP02 := poolKeepA_stUpd (s := s) hkx HS E.j.1.vs + exact s2MapVsuA (tcbs := H.tcbs) J2 hksb2 hfa2 hsubOS E.sys.ent.os hFr2 hPC (hab.isSlot E.j.1.place) hS2 hY + UP.nt (Nat.mod_eq_zero_of_dvd UP.al) UP.inv (fun i hi => hmem2 i hi) E.ap.vs E.ap.ext hfr hT hsl hvf hW hdTab + (hrootA.of_spec hP02.1 hP02.2) (hwk _ (agreeWA_baseU ipa base hbase)) obtain ⟨J, V, X0, Y0⟩ := J2 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) := @@ -842,7 +884,8 @@ theorem s2_map_pt_jA {ar : machine.Arch A} 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 }, ?_, ?_, ?_⟩ + ext := hER3 + vsu := hVU }, ?_, ?_, ?_⟩ · 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'' @@ -901,6 +944,7 @@ theorem hi_map_pt_jA (hTr : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) (cte : CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) (ptr asid0 va0 : U64) (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr false asid0 va0) + (hPC : PtCapInA Z (L.mem s)) (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} @@ -982,7 +1026,10 @@ theorem hi_map_pt_jA rw [← ht]; exact h -- Lookup slot let pos := extLookupSlot σ highGeom (specPtr vp) vaddr.bv - refine WP.spec_bind (lookup_pt_slot_hiA E.j.1.vs E.j.1.ext hrootY hactY (hi_idx39_eq_pt vaddr hlo)) fun lu ⟨hlsh, hslR⟩ => ?_ + obtain ⟨hwb0, hwb1, hwtab⟩ := E.j.1.ext.wl0 vp hrootY + refine WP.spec_bind (spec_andA (lookup_pt_slot_hiA E.j.1.vs E.j.1.ext hrootY hactY (hi_idx39_eq_pt vaddr hlo)) + (lookup_walk_hiA E.j.1.vs hrootY hactY ((and3_bitsA _).2 ⟨hwb0, hwb1⟩) hwtab vaddr + (hi_idx39_eq_pt vaddr hlo))) fun lu ⟨⟨hlsh, hslR⟩, hwalkF⟩ => ?_ 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 @@ -1053,7 +1100,7 @@ theorem hi_map_pt_jA (.archObjectCap (.pageTableCap (specPtr ptr) .normalPtT (some (asidOfA vasid, base.bv)))) := ⟨ha16, rfl, rfl, Or.inl rfl⟩ obtain ⟨x, s2, σ2, hkx, hst, hset, hsc, hσ2, HS, hksb2, R2, hcpu2, hw2, hJ2, hFr2⟩ := - restart_setcapJA E RS cte hab hos hEnc hca + restart_setcapJA E RS cte hab hos hEnc hca (hpt := Or.inl (PtSetA.map hcap)) rw [hst, bind_ok, hsc, bind_ok] -- make_user_table and write rw [show layout.paddr ptr = ok (core.num.U64.wrapping_sub ptr layout.PPTR_BASE) from rfl, bind_ok] @@ -1073,9 +1120,10 @@ theorem hi_map_pt_jA let pte : PTE := .pageTablePTE (ppnFromPptr (specPtr ptr)) have hco : capA st s (cslotAddrA cte) = .PageTable ptr false asid0 va0 := by rw [← capAtA_eq, hcap] obtain ⟨J2, hT2⟩ := hJ2 hTr hnul (by simp) (by rw [hco]; simp) - (UA.of_shapeA (by rw [hco]; rfl) fun h => by rw [hco] at h; simp [isUtA] at h) + (by rw [hco]; exact ⟨rfl, rfl, rfl, rfl, 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), trivial⟩ + (fun _ _ _ _ e => by cases e; exact Or.inr (Or.inl ⟨UP.nt, fun h => hS2 (Or.inl h)⟩)) have hmem2 := unm_mem_keep_pt E.sq.curT (fun t ht => by have := (E.sq.tcbs t ht).fits; simp only [Nat.reducePow] at this; exact this) (by rw [stA_eq]; exact field_aligned (E.sq.tcbs _ E.sq.curT) (by simp) (by simp)) UP hw2 obtain ⟨tp, hkp, htp, hep⟩ := UP.spec @@ -1215,6 +1263,69 @@ theorem hi_map_pt_jA have hne : q ≠ ptr := fun e => UP.nt (e ▸ hq) show Function.update Z.Lv ptr n q = 0 rw [Function.update_of_ne hne]; exact hl⟩) hV3 hE3 + (by + have hsubOS : ∀ y, IsSlotA Z.th y → y ∈ OS := by + obtain ⟨⟨Rp, Nt, extra', sp, P⟩, Y', hrun, hcur, hvs, hvc, hsub⟩ := RS; exact hsub + have hfr := restart_memkeepA (OS := OS) E.sq.curT + (fun t ht => by have := (E.sq.tcbs t ht).fits; simp only [Nat.reducePow] at this; exact this) + (by rw [stA_eq]; exact field_aligned (E.sq.tcbs _ E.sq.curT) (by simp) (by simp)) hw2 + obtain ⟨raw, hactA, htag2, hun⟩ := activeHiAsidRootA E.j.1.vs hX hrootY + (vspaceForAsid_of_checkExtRootA (by decide) hchkOk) (by have := ha16; omega) + have hbase' : ∀ k, lu.shift.val ≤ k → walkIdx base k 512 = walkIdx vaddr k 512 := fun k hk => by + rw [← hbase]; exact walkIdx_baseA vaddr lu.shift.val k hk + have hwk := hwalkF base hbase' + have hpal : ptr.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd UP.al + have hW' := hW + rcases hsl with ⟨t, i, ⟨ht, h1t, hst⟩, hi, hluEq, hslEq⟩ | ⟨y, j, hy, hj, hluEq, hslEq, hshEq⟩ + · rw [hluEq] at hW' hwk hvf ⊢ + have hbal : Aligned (peAF t i) := peAF_alignedA (E.j.1.vs.al_mod ht) hi + refine linkVsuA (p := t) (i := i) (v := ew) E.j.1.vs E.ap.vs hfr J2 hksb2 hfa2 hsubOS E.sys.ent.os + hFr2 hPC UP.nt (fun h => hS2 (Or.inl h)) hpal UP.ytb UP.inv (fun i hi => hmem2 i hi) (Or.inl ht) hi + ((E.ap.vs _ (.pt t i ht hi)).1) ?_ hvf + ⟨raw, hactA, Or.inr ⟨htag2, hun ▸ hrootY, by rw [hun]; exact hwk⟩⟩ hW'.1 ?_ ?_ hdTab ?_ + · intro b hb heq + rcases hb with hb | hb + · exact extFoot_ne_vsA J2.1.ext J2.1.vs.yal (Or.inr (Or.inl ht)) (J2.1.vs.al t ht) hi hb heq + · exact (hTO2 t ht).mem i hi (heq ▸ AsidWordsA.foot (L := L) (Z := Z) (s := s2) + (by rw [hksb2]; exact hb)) + · intro w hw hne; rw [hW'.2.2 w hw, if_neg (Ne.symm hne)] + · rw [hW'.2.2 _ hbal, if_pos rfl] + · refine ⟨rfl, fun q hq => ?_⟩ + rw [hslEq] + refine kheap_writeX ?_ + rw [slotObjPtE (J2.1.vs.al_mod ht) hi] + intro e + have := specPtr_inj e + subst this + obtain ⟨_, h1, -⟩ := J2.1.vs.pool q hq + obtain ⟨_, h2, -⟩ := J2.1.vs.pt q ht + rw [h1] at h2; cases h2 + · rw [hluEq] at hW' hwk hvf ⊢ + have hbal : Aligned (peAF (wa y 4096#u64) j) := peAF_alignedA (waWin_modA (J2.1.vs.yal y hy)) hj + refine linkVsuA (p := wa y 4096#u64) (i := j) (v := ew) E.j.1.vs E.ap.vs hfr J2 hksb2 hfa2 hsubOS + E.sys.ent.os hFr2 hPC UP.nt (fun h => hS2 (Or.inl h)) hpal UP.ytb UP.inv (fun i hi => hmem2 i hi) + (Or.inr ⟨y, hy, rfl⟩) hj ((E.ap.vs _ (.high y j hy hj)).1) ?_ hvf + ⟨raw, hactA, Or.inr ⟨htag2, hun ▸ hrootY, by rw [hun]; exact hwk⟩⟩ hW'.1 ?_ ?_ hdTab ?_ + · intro b hb heq + rcases hb with hb | hb + · exact extFoot_ne_vsA J2.1.ext 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 hb heq + · have F : FootA (L := L) (extZA Z) s2 b := AsidWordsA.foot (L := L) + (Z := extZA Z) (s := s2) (by rw [hksb2]; exact hb) + rw [heq] at F + exact hEO2.mem (wa y 4096#u64) (Or.inr ⟨y, hy, rfl⟩) j hj F + · intro w hw hne; rw [hW'.2.2 w hw, if_neg (Ne.symm hne)] + · rw [hW'.2.2 _ hbal, if_pos rfl] + · refine ⟨rfl, fun q hq => ?_⟩ + rw [hslEq] + refine kheap_writeX ?_ + intro e + have e' : specPtr q = specPtr y := e + have := specPtr_inj e' + subst this + obtain ⟨_, h1, -⟩ := J2.1.vs.pool q hq + obtain ⟨_, h2, -⟩ := J2.1.vs.high q hy + rw [h1] at h2; cases h2) have hoffOS : ¬ InOS OS lu.slot := by have hft : VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) lu.slot := by rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨y, j, hy, hj, hluEq, -, -⟩ @@ -1397,6 +1508,7 @@ theorem pt_map_all_jA {ar : machine.Arch A} (hTr : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) (cte : CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) (ptr asid va : U64) (mp : Bool) (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr mp asid va) + (hPC : PtCapInA Z (L.mem s)) (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) (calling : Bool) (ex : Aeneas.Std.Array obj.Slot 3#usize) (args : List U64) (hlen : length.val = args.length) @@ -1434,7 +1546,7 @@ theorem pt_map_all_jA {ar : machine.Arch A} constructor <;> intro q a h <;> cases h | _ => constructor <;> intro q a h <;> simp [CapEqA, absCapA] at habs <;> rw [← habs] at h <;> cases h rw [dec_ptMap_noExtRootA calling _ xSlot cte exs _ _ hno] - exact WP.spec_mono (pt_map_jA ar E RS cte hab hos hcap UP _ invType_ptMapA length buf args hlen hargs + exact WP.spec_mono (pt_map_jA ar E RS cte hab hos hcap hPC UP _ invType_ptMapA length buf args hlen hargs x0 hx0 exs hex hneEpt hneHi hTr hnul hTO hS2 hY) fun _ h => vsTop_ofPtMapA h -- Otherwise x0 holds Ept or HighVSpace; unfold decode_page_table have hct : sched.cur_thread st s = ok (L.curW s) := cur_thread_ok s @@ -1548,9 +1660,9 @@ theorem pt_map_all_jA {ar : machine.Arch A} have h1 : root = vp := congrArg Prod.fst hpair have h2 : asid1 = vasid := congrArg Prod.snd hpair subst root; subst asid1 - exact s2_map_pt_jA E RS hTO hEO hK hT hIpa hTr hnul cte hab hos ptr asid va hcap UP hS2 hY + exact s2_map_pt_jA E RS hTO hEO hK hT hIpa hTr hnul cte hab hos ptr asid va hcap hPC UP hS2 hY vp vasid a0 hrootX - (activeS2RootA_of_vspaceForAsid E.j.1.vs hrootX (vspaceForAsid_of_checkExtRootA (by decide) hchkOk)) + (s2RootOfAsidA_of_vspaceForAsid E.j.1.vs hrootX (vspaceForAsid_of_checkExtRootA (by decide) hchkOk)) ha1ne hvwf.2 (D := (NonDetE.liftME Fl4ArchInvocation.extVSpace (decodeS2PageTableMap (Z := Unit) cte (.pageTableCap (specPtr ptr) .normalPtT none) @@ -1574,13 +1686,15 @@ theorem pt_map_all_jA {ar : machine.Arch A} and_self, ↓reduceIte, List.getElem?_cons_zero, Fl4SpecA64.the, NonDetE.whenE, ne_self_iff_false, ndE_pure_bindA, extRootCapA] rfl - exact WP.spec_bind (hi_map_pt_jA E RS hTO hEO hK hT hTr hnul cte hab hos ptr asid va hcap UP hS2 hY + exact WP.spec_bind (hi_map_pt_jA E RS hTO hEO hK hT hTr hnul cte hab hos ptr asid va hcap hPC UP hS2 hY vp vasid a0 vmp hvwf hD) fun ⟨r, s1⟩ h => (WP.spec_ok _).2 h set_option maxHeartbeats 4000000 in /-- **Full `Cap::PageTable` top (every label, retiring `NoExtXA`)**: `decode_invocation` on a `Cap::PageTable` at `ARMPageTableMap` (Stage-1, Stage-2, `ArmHighVSpace`), `ARMPageTableUnmap`, -and illegal labels, against `fl4ArchDecodeInvocation`, with `VsTopPostA`. -/ +and illegal labels, against `fl4ArchDecodeInvocation`, **error outcome only** (`VsErrPostA`): the unmap of a +Stage-2 table (`ptr ∈ Z.T2`) is the dedicated arm `ptUnmapT2A`, so there is no uniform success post here; the success +arms are the per-arm tops (`pt_unmap_decJA` for `ptr ∉ Z.T2`, `pt_map_all_jA`). -/ theorem decInv_pt_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) @@ -1596,9 +1710,10 @@ theorem decInv_pt_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (xSlot : CapRef) (exs : List (Cap × CslotPtr)) (hex : ExtraRelA Z.th (L.mem s) x0 (exs.map Prod.fst)) (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) : + UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr ∧ ptr ∉ S2PgE Z.X Z.T2 ∧ ptr ∉ Z.Y) + (hno : FinPtNoOtherA st Z OS s) : 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 + ex ⦃ res => VsErrPostA σ ((fl4ArchDecodeInvocation (Z := Unit) calling (fl4LabelOf lbl.bv) (args.map UScalar.bv) xSlot cte (.pageTableCap (specPtr ptr) .normalPtT (mapDataA mp asid va)) exs).run σ) s a res ⦄ := by rw [decInv_ptA] @@ -1617,31 +1732,31 @@ theorem decInv_pt_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) · rw [show mapDataA false asid va = none from rfl] obtain ⟨hD, x, -, hset, hrest⟩ := pt_unmapU_decJA (ar := ar) E RS length buf calling ex (args.map UScalar.bv) xSlot exs cte hab ptr asid va hcap hFI hf - obtain ⟨s3, σ3, hdec, hp, J3, T3, C3⟩ := hrest hTr hnul + obtain ⟨s3, σ3, hdec, -⟩ := hrest hTr hnul rw [hdec] - exact (WP.spec_ok _).2 ⟨_, okD_memA hD, _, hset, σ3, [], mem_archNRA hp, Z, rfl, rfl, J3, T3, C3⟩ + exact (WP.spec_ok _).2 trivial rw [show mapDataA true asid va = some (BitVec.ofNat 16 asid.val, va.bv) from rfl] have hS1 : ∀ k, asidRootKind σ (BitVec.ofNat 16 asid.val) = k → (k = none ∨ k = some .stage1) → vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap length (cslotAddrA cte) - (.PageTable ptr true asid va) buf ex ⦃ res => VsTopPostA (L := L) AR Z OS m σ + (.PageTable ptr true asid va) buf ex ⦃ res => VsErrPostA σ ((fl4ArchDecodeInvocation (Z := Unit) calling (archL .armPageTableUnmap) (args.map UScalar.bv) xSlot cte (.pageTableCap (specPtr ptr) .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) exs).run σ) s a res ⦄ := by rintro k hk hk' obtain ⟨hD, x, -, hset, hrest⟩ := pt_unmapS1_decJA K E RS hTO hEO hK hT length buf calling ex - (args.map UScalar.bv) xSlot exs cte hab ptr asid va hPC hcap hFI hf (by subst hk; exact hk') - obtain ⟨s3, σ3, fa, hdec, hp, hJ, T3, C3⟩ := hrest hTr hnul + (args.map UScalar.bv) xSlot exs cte hab ptr asid va hPC hcap hFI hf hno (by subst hk; exact hk') + obtain ⟨s3, σ3, fa, hdec, -, hJ, -⟩ := hrest hTr hnul rw [hdec] - exact vsTop_ofFaA hD hset (mem_archNRA hp) hJ T3 C3 + exact WP.spec_bind hJ fun _ _ => (WP.spec_ok _).2 trivial rcases hk : asidRootKind σ (BitVec.ofNat 16 asid.val) with _ | k · exact hS1 _ hk (Or.inl rfl) by_cases hk1 : k = .stage1 · subst hk1; exact hS1 _ hk (Or.inr rfl) obtain ⟨hD, x, -, hset, hrest⟩ := pt_unmap_decJA K E RS hTO hEO hK hT hIpa length buf calling ex - (args.map UScalar.bv) xSlot exs cte hab ptr asid va hPC hcap hFI hf k hk hk1 - obtain ⟨s3, σ3, fa, hdec, hp, hJ, T3, C3⟩ := hrest hTr hnul + (args.map UScalar.bv) xSlot exs cte hab ptr asid va hPC hcap hFI hf hno k hk hk1 + obtain ⟨s3, σ3, fa, hdec, -, hJ, -⟩ := hrest hTr hnul rw [hdec] - exact vsTop_ofFaA hD hset (mem_archExtA hp) hJ T3 C3 + exact WP.spec_bind hJ fun _ _ => (WP.spec_ok _).2 trivial by_cases h47 : lbl = fl4_abi.label.ARMPageTableMap · subst h47 have hlab : fl4LabelOf fl4_abi.label.ARMPageTableMap.bv = archL .armPageTableMap := by @@ -1649,10 +1764,11 @@ theorem decInv_pt_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) 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 + exact WP.spec_mono (pt_map_mappedA (AR := AR) (Z := Z) (OS := OS) (m := m) (σ := σ) cte ptr asid va length buf calling ex args hlen x0 hx0 xSlot exs hex) + fun _ h => VsTopPostA.errOnly h 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 + exact WP.spec_mono (pt_map_all_jA E RS hTO hEO hK hT hIpa hTr hnul cte hab hos ptr asid va mp hcap hPC UP hS2 hY + length buf calling ex args hlen hargs x0 hx0 xSlot exs hex) fun _ h => VsTopPostA.errOnly h rw [decode_pt_otherA lbl length _ buf ex ptr asid va mp h48 h47] have hv48 : lbl.val ≠ 48 := fun e => h48 (UScalar.eq_of_val_eq (by rw [e]; simp [fl4_abi.label.ARMPageTableUnmap])) have hv47 : lbl.val ≠ 47 := fun e => h47 (UScalar.eq_of_val_eq (by rw [e]; simp [fl4_abi.label.ARMPageTableMap])) diff --git a/proofs/Fl4ProofsA64/P3/FinVsJA.lean b/proofs/Fl4ProofsA64/P3/FinVsJA.lean index 238926c04..51022e676 100644 --- a/proofs/Fl4ProofsA64/P3/FinVsJA.lean +++ b/proofs/Fl4ProofsA64/P3/FinVsJA.lean @@ -275,6 +275,7 @@ theorem JAtZAX.of_s1ClearA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, Foo cdt := hcdt orig := horig } exact J.of_sameS1A H HS (fun _ hq hl => ⟨hq, hl⟩) VR ER + (J.vsuShrinkS1A H HS fun q hq j hj => wrZero_shrinkA hal (peAF_alignedA (J.1.vs.al_mod hq) hj)) /-- **The finaliser leaves' post with `JAtZAX`** (module docstring). -/ def FinJA (AR : A → HwRootA → Prop) (Z : XSetsA) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) (s : S) diff --git a/proofs/Fl4ProofsA64/P3/FinVsXA.lean b/proofs/Fl4ProofsA64/P3/FinVsXA.lean index 9ad07f0ae..1453993e3 100644 --- a/proofs/Fl4ProofsA64/P3/FinVsXA.lean +++ b/proofs/Fl4ProofsA64/P3/FinVsXA.lean @@ -44,11 +44,8 @@ structure ExtTabOffA (Z : XSetsA) (m : Fl4SpecA64.McState) (s : S) : Prop where ¬ FootA (L := L) (extZA Z) s (peAF q i) obj : ∀ p, (p ∈ Z.X ∨ p ∈ Z.Y ∨ p ∈ Z.T2) → ¬ RelPA (extZA Z) m (specPtr p) -/-- **`JAtZAX` across a change of one VSpace page's words and one VSpace object** (module docstring): FL4's state -changes only words of the page-aligned page `q` (a Stage-2 page, a window's level-1 page or a Stage-1 table), the -spec's only the heap at the object `specPtr p0` (a Stage-2 root, a window, a Stage-2 or a Stage-1 table), with both -VSpace relations after. The core of `JAtZAX.of_extClearA` (one zero write) and of `P3/TabZeroA`'s table zeroing. -/ -theorem JAtZAX.of_extPageA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, FootA (L := L) Z s w → Aligned w) +/-- `JAtZAX.of_extPageA` with the VSpace contract record supplied by the caller. -/ +theorem JAtZAX.of_extPageVUA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, FootA (L := L) Z s w → Aligned w) (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) {q : U64} (hq : q ∈ S2PgE Z.X Z.T2 ∨ (∃ y ∈ Z.Y, q = wa y 4096#u64) ∨ q ∈ Z.S1) {s' : S} (hks : L.ksb s' = L.ksb s) (hcpu : L.cpu s' = L.cpu s) @@ -56,7 +53,9 @@ theorem JAtZAX.of_extPageA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, Foo (hp0 : p0 ∈ Z.X ∨ p0 ∈ Z.Y ∨ p0 ∈ Z.T2 ∨ p0 ∈ Z.S1) {kh : Fl4SpecA64.KHeap} (hkh : ∀ p, p ≠ specPtr p0 → kh p = σ.kheap p) (VR : VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s') (L.ksb s') { σ with kheap := kh }) - (ER : ExtVsRelA Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') { σ with kheap := kh }) : + (ER : ExtVsRelA Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') { σ with kheap := kh }) + (VU : (∀ b, AsidWordsA Z.Pp (L.ksb s) b → L.mem s' b = L.mem s b) → PoolKeepA Z.Pp σ { σ with kheap := kh } → + VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') { σ with kheap := kh }) : JAtZAX (L := L) AR Z s' a { σ with kheap := kh } m := by have hoff : ∀ j : U64, j.val < 512 → ¬ FootA (L := L) (extZA Z) s (peAF q j) := fun j hj => by rcases hq with h | h | h @@ -109,8 +108,61 @@ 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) + have hkeepW : ∀ b, AsidWordsA Z.Pp (L.ksb s) b → L.mem s' b = L.mem s b := fun b hb => H.mem b (by + rcases hb with ⟨hi, hh, rfl⟩ | ⟨p, lo, hp, hl, rfl⟩ + · exact .nslot _ (.vs _ (.asid hi hh)) + · exact .nslot _ (.vs _ (.pool p lo hp hl))) + have hpool : PoolKeepA Z.Pp σ { σ with kheap := kh } := + ⟨rfl, fun p hp => hkh _ (hne _ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨p, hp, 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 + hv hx hy (fun _ hq hl => ⟨hq, hl⟩) VR ER (VU hkeepW hpool) + +/-- **`JAtZAX` across a change of one VSpace page's words and one VSpace object** (module docstring): FL4's state +changes only words of the page-aligned page `q` (a Stage-2 page, a window's level-1 page or a Stage-1 table), the +spec's only the heap at the object `specPtr p0` (a Stage-2 root, a window, a Stage-2 or a Stage-1 table), with both +VSpace relations after. The core of `JAtZAX.of_extClearA` (one zero write) and of `P3/TabZeroA`'s table zeroing. -/ +theorem JAtZAX.of_extPageA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, FootA (L := L) Z s w → Aligned w) + (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) {q : U64} + (hq : q ∈ S2PgE Z.X Z.T2 ∨ (∃ y ∈ Z.Y, q = wa y 4096#u64) ∨ q ∈ Z.S1) {s' : S} + (hks : L.ksb s' = L.ksb s) (hcpu : L.cpu s' = L.cpu s) + (hm : ∀ w, Aligned w → (∀ j : U64, j.val < 512 → w ≠ peAF q j) → L.mem s' w = L.mem s w) {p0 : U64} + (hp0 : p0 ∈ Z.X ∨ p0 ∈ Z.Y ∨ p0 ∈ Z.T2 ∨ p0 ∈ Z.S1) {kh : Fl4SpecA64.KHeap} + (hkh : ∀ p, p ≠ specPtr p0 → kh p = σ.kheap p) + (hshr : ∀ j : U64, j.val < 512 → + (S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem s') { σ with kheap := kh } (peAF q j) ∨ + S1EntryA Z.Pp Z.S1 Z.Y (L.mem s') (L.ksb s) (peAF q j)) → + L.mem s' (peAF q j) = L.mem s (peAF q j) ∨ NotTabA (L.mem s' (peAF q j))) + (VR : VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s') (L.ksb s') { σ with kheap := kh }) + (ER : ExtVsRelA Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') { σ with kheap := kh }) : + JAtZAX (L := L) AR Z s' a { σ with kheap := kh } m := by + refine J.of_extPageVUA hfa hTO hEO hq hks hcpu hm hp0 hkh VR ER fun hA hP => ?_ + have hcase : ∀ b, Aligned b → + (S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem s') { σ with kheap := kh } b ∨ + S1EntryA Z.Pp Z.S1 Z.Y (L.mem s') (L.ksb s) b) → + L.mem s' b = L.mem s b ∨ NotTabA (L.mem s' b) := fun b hb he => by + by_cases hj : ∃ j : U64, j.val < 512 ∧ b = peAF q j + · obtain ⟨j, hj, rfl⟩ := hj; exact hshr j hj he + · exact Or.inl (hm b hb (fun j hj' e => hj ⟨j, hj', e⟩)) + exact J.vsuShrinkA (σ' := { σ with kheap := kh }) hks + (fun b hb => hcase b (hfa b (.nslot b (.ext b (hb.word.foot J.1.ext.xal)))) (Or.inl hb)) + (fun b hbE => by + refine hcase b ?_ (Or.inr hbE) + obtain ⟨tag, sh, t, i, -, ht, -, hi, hb⟩ := hbE + subst hb + apply hfa + rcases ht with ht | ⟨y, hy, rfl⟩ + · exact .nslot _ (.vs _ (.pt t i ht hi)) + · exact .nslot _ (.vs _ (.high y i hy hi))) + hA hP (PtClosedA.of_cap fun y hy => Or.inl (by + refine (?_ : capAtA (L.mem s') y = capAtA (L.mem s) y) + have hoff : ∀ j : U64, j.val < 512 → ¬ FootA (L := L) (extZA Z) s (peAF q j) := fun j hj => by + rcases hq with h | h | h + · exact hEO.mem q (Or.inl h) j hj + · exact hEO.mem q (Or.inr h) j hj + · exact fun hf => (hTO q h).mem j hj hf.extMonoA + have H : SameA (L := L) (extZA Z) s s' := + ⟨hks, hcpu, fun w hw => hm w (hfa w (FootA.s1_monoA hw.extMonoA)) fun j hj e => hoff j hj (e ▸ hw)⟩ + exact H.cap (Or.inl hy))) /-- **`JAtZAX` across an Ext unmap's zero write and its spec outcome** (module docstring). -/ theorem JAtZAX.of_extClearA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, FootA (L := L) Z s w → Aligned w) @@ -122,7 +174,8 @@ theorem JAtZAX.of_extClearA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, Fo obtain ⟨⟨q, j, hj, rfl, hq4, hq⟩, p0, hp0, kh, rfl, hkh⟩ := hw have hal : Aligned (peAF q j) := peAF_alignedA (Nat.mod_eq_zero_of_dvd hq4) hj exact J.of_extPageA hfa hTO hEO hq (L.ksb_wr _ _ _) (L.cpu_wr _ _ _) (fun w hw hn => by - rw [L.mem_wr _ _ _ _ hal hw, if_neg fun e => hn j hj e.symm]) hp0 hkh VR ER + rw [L.mem_wr _ _ _ _ hal hw, if_neg fun e => hn j hj e.symm]) hp0 hkh + (fun j' hj' _ => wrZero_shrinkA hal (peAF_alignedA (Nat.mod_eq_zero_of_dvd hq4) hj')) VR ER /-- **The Stage-2 / high branch with `JAtZAX`** (module docstring). -/ theorem ExtUnmapRelE.finJA {fk : S → Result (S × A)} (hk : ArchContE fk) {u : Result (S × A)} diff --git a/proofs/Fl4ProofsA64/P3/FrReplyA.lean b/proofs/Fl4ProofsA64/P3/FrReplyA.lean index 24b0bce1e..039ac7b04 100644 --- a/proofs/Fl4ProofsA64/P3/FrReplyA.lean +++ b/proofs/Fl4ProofsA64/P3/FrReplyA.lean @@ -21,6 +21,7 @@ invocations** — `ARMPageGetAddress` (label 57) and `ARMPageTestAndClearAccesse Named premises: `ArchKeepsA` [P]. Decode-site hypotheses: `RsSiteA`, `TabOffA`, `ExtTabOffA`, `hvcR` (VCPUs disjoint from the current thread's register words, vacuous at `w0`/`w1`). No new named premise. No existing statement changed. -/ +import Fl4ProofsA64.P3.VsLeafShrA import Fl4ProofsA64.P3.FrFlushA open Aeneas Aeneas.Std Result @@ -390,7 +391,11 @@ theorem JAtZAX.of_tcbCtxA (J : JAtZAX (L := L) AR Z s a σ m) {t : U64} {x : Fl4 · rcases hq with hqP | hqXT · exact absurd (ep ▸ hk) (J.vs.not_tcb (Or.inl ⟨q, hqP, rfl⟩)) · exact absurd (ep ▸ hk) (J.ext.not_tcb hqXT x) - · exact hkn _ ep } + · exact hkn _ ep, + vsu := J.vsu.of_frame J.ext.xal (fun _ _ => rfl) ⟨rfl, fun p hp => by + by_cases ep : specPtr p = specPtr t + · exact absurd (ep ▸ hk) (J.vs.not_tcb (Or.inl ⟨p, hp, rfl⟩)) + · exact hkn _ ep⟩ (PtClosedA.refl _ _ _ _) } refine ⟨J', ⟨fun w hw => ?_, fun p y e => V.back p y (hback _ _ e (fun _ h => by cases h)), fun y hy => ?_, V.cap⟩, ⟨fun r hr => ?_, fun p es e => X.back p es (hback _ _ e (fun _ h => by cases h)), X.cap⟩, ⟨fun r hr => ?_, fun p l1 e => Y.back p l1 (hback _ _ e (fun _ h => by cases h)), Y.cap⟩⟩ @@ -1152,8 +1157,24 @@ theorem jat_clearAF (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) · exact ⟨y, Or.inr (Or.inl hy)⟩ obtain ⟨p0, hp0⟩ := hp0 have J1 : JAtZAX (L := L) AR Z s1 a σ m := - E.j.of_extPageA hal hTO hEO hq hks1 hcpu1 (fun w hw hne => hm w hw (hne j hj)) - hp0 (kh := σ.kheap) (fun _ _ => rfl) (by rw [hks1]; exact R1) E1 + E.j.of_extPageVUA hal hTO hEO hq hks1 hcpu1 (fun w hw hne => hm w hw (hne j hj)) + hp0 (kh := σ.kheap) (fun _ _ => rfl) (by rw [hks1]; exact R1) E1 (fun hA hP => by + have hD : ∀ w, Aligned w → DescEqA (L.mem s1 w) (L.mem s w) := fun w hw => by + by_cases e : w = sl + · rw [e, L.mem_wr_same hslAl] + refine ⟨?_, by unfold dTabA; rw [clearAF_dAddrA]⟩ + apply UScalar.eq_of_val_eq + rw [and3_valA, and3_valA, ← Nat.mod_mod_of_dvd (L.mem s sl &&& ~~~1024#u64).val (by decide : 4 ∣ 1024), + clearAF_mod1024, Nat.mod_mod_of_dvd (L.mem s sl).val (by decide : 4 ∣ 1024)] + · rw [hm w hw e]; exact ⟨rfl, rfl⟩ + rw [hks1] + refine E.j.1.vsu.of_descEqA R (σ' := σ) (by exact R1) ?_ hA hP (PtClosedA.of_cap fun y hy => Or.inl ?_) + · exact + { s2r := fun r hr i hi => hD _ (E.j.1.ext.foot_alignedE R.yal _ (rootFootE hr (E.j.1.ext.xal r hr) hi)) + s2t := fun t ht i hi => hD _ (peAF_alignedA (Nat.mod_eq_zero_of_dvd (E.j.1.ext.tal t ht)) hi) + s1 := fun t ht i hi => hD _ (peAF_alignedA (S1TabA.mod4k R ht) hi) } + · rw [capAtA_eq (st := st), capAtA_eq (st := st)] + exact (osKeep_of_wr_notInOS E.sys.ent.os hslAl (E.ap.vs sl hslFoot).1).capA (RS.sub y hy)) -- `OSKeep` (since `sl` is in `VsFootA`, which is off `OS` by `E.ap.vs`) have hOS : OSKeep st OS s s1 := osKeep_of_wr_notInOS E.sys.ent.os hslAl (E.ap.vs sl hslFoot).1 have hTr1 : TreeA st OS Z.G.chains Z.G.par s1 := treeA_of_mem hTr hOS diff --git a/proofs/Fl4ProofsA64/P3/FrSubframeA.lean b/proofs/Fl4ProofsA64/P3/FrSubframeA.lean index 050cc2644..b468ecac1 100644 --- a/proofs/Fl4ProofsA64/P3/FrSubframeA.lean +++ b/proofs/Fl4ProofsA64/P3/FrSubframeA.lean @@ -786,6 +786,38 @@ private theorem cap_insert_subframe_refinesA {T Ω Sg OS : Set U64} {th : TypedH · exact Or.inl (by rw [f1]; exact hnf hnc_fc) · exact Or.inl (ek y (hsub y hy) f1 f2) +/-- **The footprint of `Z with G := G1` at `s1` is off the cap-write set and aligned** (`cap_insert_frame_stepA`'s +two facts, standalone for the `JStage3A`-level loop's `hst`). -/ +theorem subframe_foot_offA + (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) + {s1 : S} {σ1 : Fl4SpecA64.State Unit} {G1 : MdbGhostA} + (hJ1 : JAtZAX (L := L) AR { Z with G := G1 } s1 a σ1 m) + (hks1 : L.ksb s1 = L.ksb s) (hcpu1 : L.cpu s1 = L.cpu s) : + (∀ b, FootNA (L := L) { Z with G := G1 } s1 b → ¬ W7.CapW H.tcbs {b | InOS OS b} ∅ b) ∧ + (∀ b, FootNA (L := L) { Z with G := G1 } s1 b → Aligned b) := by + have hfnOff : ∀ b, FootNA (L := L) { Z with G := G1 } s1 b → ¬ W7.CapW H.tcbs {b | InOS OS b} ∅ b := by + intro b hb + have hb0 : FootNA (L := L) Z s b := by + have hna := nodeAt_ksb hks1 + cases hb with + | node c _ hc ho => simp only [hna] at ho; exact .node c _ hc ho + | cur _ ho => simp only [hcpu1, hna] at ho; exact .cur _ ho + | cur2 _ ho => simp only [hcpu1, hna] at ho; exact .cur2 _ ho + | tcb y _ hy ho => exact .tcb y _ hy ho + | tcb2 y _ hy ho => exact .tcb2 y _ hy ho + | sc c hc => exact .sc c hc + | sc2 c hc => exact .sc2 c hc + | irq i hi => rw [hks1] at *; exact .irq i hi + | glob _ ho => rw [hks1] at ho; exact .glob _ ho + | vcpu v _ hv hw => exact .vcpu v _ hv hw + | vs _ h => rw [hks1] at h; exact .vs _ h + | ext _ h => exact .ext _ h + exact footN_offA E b hb0 + have hal1 : ∀ b, FootNA (L := L) { Z with G := G1 } s1 b → Aligned b := + FootNA.aligned hJ1.1 (fun c hc o ho => by rw [nodeAt_ksb hks1]; exact bxi_nodes E.sys.ent.bxi c hc o ho) + E.scAl E.ap.vcAl + exact ⟨hfnOff, hal1⟩ + /-- Single `cdt.insert` step for a 4 KiB subframe cap: preserves `JAtZAX`, `TreeA`, `CarryA`, `ksb`, `cpu`, `hnul`, and every slot cap off `cslotAddrA sd` (without rebuilding `JEntA`). -/ theorem cap_insert_frame_stepA @@ -802,14 +834,13 @@ theorem cap_insert_frame_stepA (hdn : capAtA (L.mem s1) (cslotAddrA sd) = .Null) (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) (hfpC : CapRt.Canonical fp) (hfpAl : fp.val % 2 ^ 21 = 0) - (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) (hk : k.val + 4096 ≤ 2 ^ 21) - (hfr : ∀ w ∈ G1.chains.flatten, OvlA (absCapA (.Frame (wa fp k) .Small vm false false false 0#u64 0#u64)) - (absCapA (capAtA (L.mem s1) w)) → - isFrameA (capAtA (L.mem s1) w) = true ∧ ∃ ch ∈ G1.chains, cslotAddrA ss ∈ ch ∧ w ∈ ch) : + (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) (hk : k.val + 4096 ≤ 2 ^ 21) : let nc := capability.Cap.Frame (wa fp k) .Small vm false false false 0#u64 0#u64 let anc := absCapA nc cdt.insert st s1 nc (cslotAddrA ss) (cslotAddrA sd) ⦃ s2 => ∃ σ2 G2, + G2 = insGA G1 (cslotAddrA ss) (cslotAddrA sd) + (insBA σ1 ss (absCapA nc) (absCapA (capA st s1 (cslotAddrA ss)))) ∧ G2.chains = insG (cslotAddrA ss) (cslotAddrA sd) G1.chains ∧ ((), σ2) ∈ (Fl4SpecA64.capInsert (Z := Unit) anc ss sd σ1).1 ∧ JAtZAX (L := L) AR { Z with G := G2 } s2 a σ2 m ∧ @@ -818,7 +849,7 @@ theorem cap_insert_frame_stepA (∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s2 y = .Null) ∧ (∀ y ∈ OS, y ≠ cslotAddrA sd → capAtA (L.mem s2) y = capAtA (L.mem s1) y) ∧ capAtA (L.mem s2) (cslotAddrA sd) = nc ∧ - (CarryA { Z with G := G1 } (L.mem s1) σ1 → CarryA { Z with G := G2 } (L.mem s2) σ2) ⦄ := by + WritesIn st s1 s2 (W7.CapW H.tcbs {b | InOS OS b} ∅) ∧ SpecSlotA σ1 σ2 ⦄ := by intro nc anc have hO := E.sys.ent.os have hP := hJ1.1.place @@ -861,31 +892,15 @@ theorem cap_insert_frame_stepA refine WP.spec_mono (WP.spec_and href hwr) fun s2 ⟨⟨σ2, hm, hst2, hcdt2, hT2, hSS2, hcs2⟩, hw2, hkeep, hsd2⟩ => ?_ have hks2 : L.ksb s2 = L.ksb s := hw2.1.trans hks1 have hcpu2 : L.cpu s2 = L.cpu s := hw2.2.1.trans hcpu1 - have hfnOff : ∀ b, FootNA (L := L) { Z with G := G1 } s1 b → ¬ W7.CapW H.tcbs {b | InOS OS b} ∅ b := by - intro b hb - have hb0 : FootNA (L := L) Z s b := by - have hna := nodeAt_ksb hks1 - cases hb with - | node c _ hc ho => simp only [hna] at ho; exact .node c _ hc ho - | cur _ ho => simp only [hcpu1, hna] at ho; exact .cur _ ho - | cur2 _ ho => simp only [hcpu1, hna] at ho; exact .cur2 _ ho - | tcb y _ hy ho => exact .tcb y _ hy ho - | tcb2 y _ hy ho => exact .tcb2 y _ hy ho - | sc c hc => exact .sc c hc - | sc2 c hc => exact .sc2 c hc - | irq i hi => rw [hks1] at *; exact .irq i hi - | glob _ ho => rw [hks1] at ho; exact .glob _ ho - | vcpu v _ hv hw => exact .vcpu v _ hv hw - | vs _ h => rw [hks1] at h; exact .vs _ h - | ext _ h => exact .ext _ h - exact footN_offA E b hb0 - have hal1 : ∀ b, FootNA (L := L) { Z with G := G1 } s1 b → Aligned b := - FootNA.aligned hJ1.1 (fun c hc o ho => by rw [nodeAt_ksb hks1]; exact bxi_nodes E.sys.ent.bxi c hc o ho) - E.scAl E.ap.vcAl + obtain ⟨hfnOff, hal1⟩ := subframe_foot_offA E hJ1 hks1 hcpu1 set G2 := insGA G1 (cslotAddrA ss) (cslotAddrA sd) (insBA σ1 ss (absCapA nc) (absCapA (capA st s1 (cslotAddrA ss)))) have hJ2 : JAtZAX (L := L) AR { Z with G := G2 } s2 a σ2 m := by - refine hJ1.of_slotWrites hw2 (fun b hw' hb => hfnOff b hb hw') hal1 G2 hSS2 hst2 hcdt2 fun y hy => ?_ + refine hJ1.of_slotWrites hw2 (fun b hw' hb => hfnOff b hb hw') hal1 G2 hSS2 hst2 hcdt2 (fun y hy => ?_) + (PtClosedA.ofTab (PtCapClosedA.of_ins (PtSrcA.nopt fun _ _ _ _ h => by simp [nc] at h) hcs2) + (TabClosedA.of_copy hcs2 (RootCopyA.of_no (th := Z.th) (mem := L.mem s1) + (fun r h => by rcases h with ⟨_, _, e⟩ | ⟨_, _, _, e⟩ | ⟨_, _, e⟩ <;> simp [nc] at e) + (fun r h => by rcases h with ⟨_, _, _, e⟩; simp [nc] at e)))) rcases hcs2 y hy with e | e | ⟨p, b, i, d, e⟩ <;> rw [e] · exact hJ1.capObj hy · exact ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), @@ -893,27 +908,9 @@ theorem cap_insert_frame_stepA fun h => (by cases h)⟩ · exact ⟨fun _ h => (by cases h), fun _ _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), fun _ _ _ h => (by cases h), trivial⟩ - refine ⟨σ2, G2, rfl, hm, hJ2, hT2, hks2, hcpu2, fun y hy hni => ?_, hkeep, hsd2, fun hC => ?_⟩ - · have hne : y ≠ cslotAddrA sd := fun e => hni (e ▸ hdS) - rw [hkeep y hy hne]; exact hnul y hy hni - · refine ⟨hC.1.of_capsA rfl (fun _ h => h) (fun _ h => h) (fun y hy => ?_), ?_⟩ - · by_cases hne : y = cslotAddrA sd - · exact Or.inr (fun _ _ _ h => by rw [hne] at h; change capA st s2 (cslotAddrA sd) = _ at h; rw [hsd2] at h; dsimp only [nc] at h; cases h) - · exact Or.inl (hkeep y (hsub y hy) hne) - · refine ⟨hC.2.kt.of_typesA (fun o r cs ho => ?_) (fun o t ho => ?_), ?_⟩ - · rcases hSS2.kh o with h | ⟨r', cs0, cs', h1, h2⟩ | ⟨x0, x', h1, h2, -⟩ - · exact ⟨cs, h ▸ ho⟩ - · rw [ho] at h2; cases h2; exact ⟨cs0, h1⟩ - · rw [ho] at h2; cases h2 - · rcases hSS2.kh o with h | ⟨r', cs0, cs', h1, h2⟩ | ⟨x0, x', h1, h2, -⟩ - · exact ⟨t, h ▸ ho⟩ - · rw [ho] at h2; cases h2 - · rw [ho] at h2; cases h2; exact ⟨x0, h1⟩ - · exact finMA_insFrameA hC.2.fm hT1.lk.nodup hdG - (fun y hy => hkeep y ((hT1.lk.members y).1 hy).1 (fun e => hdG (e ▸ hy))) - (by rw [hsrc]; intro h; exact h fp .Large false rfl) hsd2 (fun w hw ho => by - change OvlA (absCapA (capA st s2 (cslotAddrA sd))) _ at ho - rw [hsd2] at ho; exact hfr w hw ho) + refine ⟨σ2, G2, rfl, rfl, hm, hJ2, hT2, hks2, hcpu2, fun y hy hni => ?_, hkeep, hsd2, hw2, hSS2⟩ + have hne : y ≠ cslotAddrA sd := fun e => hni (e ▸ hdS) + rw [hkeep y hy hne]; exact hnul y hy hni end frame_ins @@ -1292,7 +1289,7 @@ private theorem mapMEx_ensureEmpty_appendA {σ : Fl4SpecA64.State Unit} rw [run_bind_okD (hx a (List.mem_cons_self ..))] exact ih fun x h => hx x (List.mem_cons_of_mem _ h) -private theorem mapMx_appendA {α : Type} (f : α → Fl4SpecA64.SMonad Unit Unit) +theorem mapMx_appendA {α : Type} (f : α → Fl4SpecA64.SMonad Unit Unit) {σ0 σ1 σ2 : Fl4SpecA64.State Unit} (xs ys : List α) (h1 : ((), σ1) ∈ (Fl4Spec.NonDet.mapMx f xs σ0).1) (h2 : ((), σ2) ∈ (Fl4Spec.NonDet.mapMx f ys σ1).1) : @@ -1415,10 +1412,7 @@ theorem insert_subframes_refinesA (hks0 : L.ksb s0 = L.ksb s) (hcpu0 : L.cpu s0 = L.cpu s) (hnul0 : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s0 y = .Null) (hsrc0 : capAtA (L.mem s0) (cslotAddrA ss) = .Frame fp .Large rt false mp e asid va) - (hall0 : ∀ j < count.val, capAtA (L.mem s0) (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null) - (hfr0 : ∀ 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 s0) w)) → - isFrameA (capAtA (L.mem s0) w) = true ∧ ∃ ch ∈ Z.G.chains, cslotAddrA ss ∈ ch ∧ w ∈ ch) : + (hall0 : ∀ j < count.val, capAtA (L.mem s0) (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null) : vspace.insert_subframes st s0 (cslotAddrA ss) dest first (wa fp offset) count vm ⦃ s2 => let ds := (List.range' first.val count.val).map fun j => (specPtr dest, Fl4SpecA64.natToCref r j) let ps := (List.range' 0 count.val).zip ds @@ -1428,8 +1422,7 @@ theorem insert_subframes_refinesA (specPtr fp + offset.bv + BitVec.ofNat 64 (d.1 * 4096)) (vmRightsOfA vm) .armSmallPage false none)) ss d.2) ps σ0).1 ∧ JAtZAX (L := L) AR { Z with G := G2 } s2 a σ2 m ∧ - TreeA st OS G2.chains G2.par s2 ∧ - (CarryA Z (L.mem s0) σ0 → CarryA { Z with G := G2 } (L.mem s2) σ2) ⦄ := by + TreeA st OS G2.chains G2.par s2 ⦄ := by unfold vspace.insert_subframes vspace.insert_subframes_loop have h2r58 : 2 ^ r ≤ 2 ^ 58 := Nat.pow_le_pow_right (by omega) hr.2 apply loop.spec_decr_nat (measure := fun p : S × U64 => count.val - p.2.val) @@ -1448,12 +1441,8 @@ theorem insert_subframes_refinesA (∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s1 y = .Null) ∧ capAtA (L.mem s1) (cslotAddrA ss) = .Frame fp .Large rt false mp e asid va ∧ (∀ j, i.val ≤ j → j < count.val → - capAtA (L.mem s1) (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null) ∧ - (∀ w ∈ G1.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 s1) w)) → - isFrameA (capAtA (L.mem s1) w) = true ∧ ∃ ch ∈ G1.chains, cslotAddrA ss ∈ ch ∧ w ∈ ch) ∧ - (CarryA Z (L.mem s0) σ0 → CarryA { Z with G := G1 } (L.mem s1) σ1)) - · rintro ⟨s1, i⟩ ⟨hi, σ1, G1, hm1, hJ1, hT1, hks1, hcpu1, hnul1, hsrc1, hall1, hfr1, hC1⟩ + capAtA (L.mem s1) (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null)) + · rintro ⟨s1, i⟩ ⟨hi, σ1, G1, hm1, hJ1, hT1, hks1, hcpu1, hnul1, hsrc1, hall1⟩ dsimp only unfold vspace.insert_subframes_loop.body by_cases hlt : i < count @@ -1490,8 +1479,8 @@ theorem insert_subframes_refinesA have : fp.val < 2 ^ 64 := fp.hBounds; omega exact Nat.mod_eq_of_lt (by omega) have hstep := cap_insert_frame_stepA E hJ1 hT1 hks1 hcpu1 hsub hnul1 hAs hAd hsrc1 hdn hdc hfpC hfpAl hvm - (by omega) (fun w hw ho => hfr1 w hw (wa fp (wa offset i1)) vm (by omega) (by omega) ho) - refine WP.spec_bind hstep fun s2 ⟨σ2, G2, hG2, hm2, hJ2, hT2, hks2, hcpu2, hnul2, hkeep2, hsd2, hC2⟩ => ?_ + (k := wa offset i1) (by omega) + refine WP.spec_bind hstep fun s2 ⟨σ2, G2, hGeq, hG2, hm2, hJ2, hT2, hks2, hcpu2, hnul2, hkeep2, hsd2, _, _⟩ => ?_ have hinc : (i + 1#u64) ⦃ i4 => i4.val = i.val + 1 ⦄ := by step as ⟨i4, hi4⟩; omega obtain ⟨i4, hi4Ok, hi4Val⟩ := spec_ex_fd hinc rw [hi4Ok, bind_ok, WP.spec_ok] @@ -1516,35 +1505,6 @@ theorem insert_subframes_refinesA omega rw [hkeep2 _ (hsub _ (hAd'.isSlot hJ1.1.place)) hne] exact hall1 j (by omega) hj2 - have hfr2 : ∀ w ∈ G2.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 s2) w)) → - isFrameA (capAtA (L.mem s2) w) = true ∧ ∃ ch ∈ G2.chains, cslotAddrA ss ∈ ch ∧ w ∈ ch := by - intro w hw q vm' hq1 hq2 ho - rw [hG2] at hw ⊢ - have hsG : cslotAddrA ss ∈ G1.chains.flatten := - (hT1.lk.members _).2 ⟨hsub _ (hAs.isSlot hJ1.1.place), by - show capAtA (L.mem s1) (cslotAddrA ss) ≠ .Null; rw [hsrc1]; intro h; cases h⟩ - have hsd_mem : w = cslotAddrA sd ∨ w ∈ G1.chains.flatten := by - obtain ⟨ch', hch', hw'⟩ := List.mem_flatten.1 hw - rw [insG, List.mem_map] at hch' - obtain ⟨ch, hch, rfl⟩ := hch' - by_cases hss : cslotAddrA ss ∈ ch - · rcases List.mem_cons.1 ((insA_perm (dest := cslotAddrA sd) hss).mem_iff.1 hw') with rfl | h - · exact Or.inl rfl - · exact Or.inr (List.mem_flatten.2 ⟨ch, hch, h⟩) - · rw [insA_of_not_mem hss] at hw' - exact Or.inr (List.mem_flatten.2 ⟨ch, hch, hw'⟩) - rcases hsd_mem with rfl | hw1 - · obtain ⟨ch, hch, hsc⟩ := List.mem_flatten.1 hsG - refine ⟨by rw [hsd2]; rfl, insA (cslotAddrA ss) (cslotAddrA sd) ch, List.mem_map.2 ⟨ch, hch, rfl⟩, - (insA_perm (dest := cslotAddrA sd) hsc).mem_iff.2 (List.mem_cons_of_mem _ hsc), - (insA_perm (dest := cslotAddrA sd) hsc).mem_iff.2 (List.mem_cons_self ..)⟩ - · have hwne : w ≠ cslotAddrA sd := fun e => ((hT1.lk.members _).1 (e ▸ hw1)).2 hdn - rw [hkeep2 w ((hT1.lk.members w).1 hw1).1 hwne] at ho ⊢ - obtain ⟨hf, ch, hch, hsc, hwc⟩ := hfr1 w hw1 q vm' hq1 hq2 ho - exact ⟨hf, insA (cslotAddrA ss) (cslotAddrA sd) ch, List.mem_map.2 ⟨ch, hch, rfl⟩, - (insA_perm (dest := cslotAddrA sd) hsc).mem_iff.2 (List.mem_cons_of_mem _ hsc), - (insA_perm (dest := cslotAddrA sd) hsc).mem_iff.2 (List.mem_cons_of_mem _ hwc)⟩ have hanc : absCapA (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) = .archObjectCap (.frameCap (specPtr fp + offset.bv + BitVec.ofNat 64 (i.val * 4096)) (vmRightsOfA vm) .armSmallPage false none) := by @@ -1569,7 +1529,7 @@ theorem insert_subframes_refinesA rw [hi4Val, List.range'_concat]; simp rw [hr1, hr2, List.map_append, List.map_singleton, List.zip_append (by simp)] rfl - refine ⟨⟨by dsimp only; omega, σ2, G2, ?_, hJ2, hT2, hks2, hcpu2, hnul2, hsrc2, hall2, hfr2, fun hC => hC2 (hC1 hC)⟩, by dsimp only; omega⟩ + refine ⟨⟨by dsimp only; omega, σ2, G2, ?_, hJ2, hT2, hks2, hcpu2, hnul2, hsrc2, hall2⟩, by dsimp only; omega⟩ rw [hzip] exact mapMx_appendA _ _ _ hm1 (by unfold Fl4Spec.NonDet.mapMx Fl4Spec.NonDet.bind @@ -1577,11 +1537,11 @@ theorem insert_subframes_refinesA · rw [if_neg hlt, WP.spec_ok] have hieq : i.val = count.val := by have : ¬ (i.val < count.val) := hlt; omega rw [hieq] at hm1 - exact ⟨σ1, G1, hm1, hJ1, hT1, hC1⟩ + exact ⟨σ1, G1, hm1, hJ1, hT1⟩ · exact ⟨by change 0 ≤ count.val; omega, σ0, Z.G, Set.mem_singleton _, hJ0, hT0, hks0, hcpu0, hnul0, hsrc0, - fun j _ hj => hall0 j hj, hfr0, id⟩ + fun j _ hj => hall0 j hj⟩ -private theorem dec_deriveSubA (calling : Bool) (args : List Fl4SpecA64.Data) (xSlot : Fl4SpecA64.CapRef) +theorem dec_deriveSubA (calling : Bool) (args : List Fl4SpecA64.Data) (xSlot : Fl4SpecA64.CapRef) (cte : Fl4SpecA64.CslotPtr) (e : Bool) (p : Fl4SpecA64.ObjRef) (r : Fl4SpecA64.CapRights) (sz : Fl4SpecA64.VMPageSize) (dev : Bool) (md : Option (Fl4SpecA64.Asid × Fl4SpecA64.VSpaceRef)) (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) : @@ -1591,8 +1551,57 @@ private theorem dec_deriveSubA (calling : Bool) (args : List Fl4SpecA64.Data) (x (Fl4SpecA64.decodeDeriveSubframe (Z := Unit) args cte (.frameCap p r sz dev md) exs)).run σ := by cases e <;> simp [absFrameE, Fl4SpecA64.fl4ArchDecodeInvocation] -/-- **Label 55 (`ARMPageDeriveSubframe`) on `ArchTopPostA`** (module docstring): both plain and Stage-2 frames, -covering all error paths and the CDT-extending `insert_subframes` success loop. -/ +/-- **The error half of `ArchTopPostA`** (E0.5b): `Err` is the spec's error with the state kept, `Ok` asks nothing. The +error path of the lifted top needs no more (`ArchDecTopPostA.errOnly` drops `Ok`); the success path is the `JStage3A` +arm's (`JStage3A.deriveSubframeA`), so the old success half's `FinInvA`-carry (`CarryA`) and its range premise `hfr` are +gone: they were read only by `finMA_insFrameA`. -/ +def ArchTopErrA (σ : Fl4SpecA64.State Unit) + (D : Set (Except Fl4SpecA64.SyscallError Fl4SpecA64.Fl4ArchInvocation × Fl4SpecA64.State Unit) × Prop) + (s : S) (a : A) : core.result.Result Unit error.Exc × S × A → Prop + | (.Err e, s', a') => s' = s ∧ a' = a ∧ ∃ e', D = ({(.error e', σ)}, False) ∧ VsErrRelA e e' + | (.Ok (), _, _) => True + +theorem ArchTopPostA.toErrA {AR : A → HwRootA → Prop} {Z : XSetsA} {OS : Set U64} {m : Fl4SpecA64.McState} + {calling : Bool} {σ : Fl4SpecA64.State Unit} + {D : Set (Except Fl4SpecA64.SyscallError Fl4SpecA64.Fl4ArchInvocation × Fl4SpecA64.State Unit) × Prop} + {s : S} {a : A} : ∀ {res}, ArchTopPostA (L := L) AR Z OS m calling σ D s a res → ArchTopErrA σ D s a res + | (.Err _, _, _), h => h + | (.Ok (), _, _), _ => trivial + +variable (st) in +/-- **`ArchTopErrA`'s `Err` half, and the success view of `ARMPageDeriveSubframe`** (E0.5c): the `Ok` half names the +arguments and the run: the caller's restart, the CNode `dest` (radix, window, ranges), the masked VM rights, the empty +destination slots, `insert_subframes` at the restarted state, and the spec decode's `deriveSubframe` invocation +(`performDeriveSubframe` is `cap_insert` of the `i`-th 4 KiB frame cap into the `i`-th destination). -/ +def ArchTopSubA (th : TypedHeapA) (s : S) (σ : Fl4SpecA64.State Unit) (cte : Fl4SpecA64.CslotPtr) (fp rt : U64) + (D : Set (Except Fl4SpecA64.SyscallError Fl4SpecA64.Fl4ArchInvocation × Fl4SpecA64.State Unit) × Prop) (a : A) : + core.result.Result Unit error.Exc × S × A → Prop + | (.Err e, s', a') => s' = s ∧ a' = a ∧ ∃ e', D = ({(.error e', σ)}, False) ∧ VsErrRelA e e' + | (.Ok (), s3, a3) => a3 = a ∧ + ∃ (x : Fl4SpecA64.Tcb) (dest radix first offset count a5 vm : U64), + σ.kheap σ.curThread = some (.tcb x) ∧ + sched.set_thread_state st s (L.curW s) sched.TS_RESTART = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) ∧ + th dest = some (.cnode radix.val) ∧ 1 ≤ radix.val ∧ radix.val ≤ 58 ∧ + offset.val + count.val * 4096 ≤ 2 ^ 21 ∧ first.val + count.val ≤ 2 ^ radix.val ∧ + offset.val % 4096 = 0 ∧ (1 ≤ vm.val ∧ vm.val ≤ 3) ∧ + vmRightsOfA vm = Fl4SpecA64.maskVmRights (vmRightsOfA rt) (Fl4SpecA64.dataToRights a5.bv) ∧ + (∀ j < count.val, capAtA (L.mem s) + (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref radix.val (first.val + j))) = .Null) ∧ + vspace.insert_subframes st (L.wr s (stA (L.curW s)) sched.TS_RESTART) (cslotAddrA cte) dest first + (core.num.U64.wrapping_add fp offset) count vm = ok s3 ∧ + D = ({(.ok (.deriveSubframe (Fl4SpecA64.Fl4SubframeInvocation.mk cte (specPtr fp + offset.bv) + (vmRightsOfA vm) ((List.range' first.val count.val).map fun i => + (specPtr dest, Fl4SpecA64.natToCref radix.val i)))), σ)}, False) + +theorem ArchTopSubA.toErrA {th : TypedHeapA} {s : S} {σ : Fl4SpecA64.State Unit} {cte : Fl4SpecA64.CslotPtr} + {fp rt : U64} + {D : Set (Except Fl4SpecA64.SyscallError Fl4SpecA64.Fl4ArchInvocation × Fl4SpecA64.State Unit) × Prop} {a : A} : + ∀ {res}, ArchTopSubA st th s σ cte fp rt D a res → ArchTopErrA σ D s a res + | (.Err _, _, _), h => h + | (.Ok (), _, _), _ => trivial + +/-- **Label 55 (`ARMPageDeriveSubframe`) on `ArchTopErrA`** (module docstring): both plain and Stage-2 frames, +covering all error paths (the success loop is run for its no-panic spec only). -/ theorem derive_subframe_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) @@ -1603,10 +1612,6 @@ theorem derive_subframe_jA (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) (hfp : sz = .Large → dev = false → fp.val % 2 ^ 21 = 0 ∧ CapRt.Canonical fp) - (hfr : sz = .Large → dev = false → - ∀ 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) (length buf : U64) (call : Bool) (ex : Aeneas.Std.Array obj.Slot 3#usize) (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) @@ -1616,16 +1621,16 @@ theorem derive_subframe_jA (do let (r, s1) ← vspace.derive_subframe st s length (cslotAddrA cte) (.Frame fp sz rt dev mp e asid va) buf ex ok (r, s1, a)) ⦃ res => - ArchTopPostA (L := L) AR Z OS m call σ ((Fl4SpecA64.fl4ArchDecodeInvocation (Z := Unit) call + ArchTopSubA st Z.th s σ cte fp rt ((Fl4SpecA64.fl4ArchDecodeInvocation (Z := Unit) call (.ext .armPageDeriveSubframe) (args.map UScalar.bv) xSlot cte - (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev (mapDataA mp asid va)) exs).run σ) s a res ⦄ := by + (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev (mapDataA mp asid va)) exs).run σ) a res ⦄ := by rw [dec_deriveSubA] refine WP.spec_bind - (Pₘ := fun p => ArchTopPostA (L := L) AR Z OS m call σ + (Pₘ := fun p => ArchTopSubA st Z.th s σ cte fp rt ((Fl4Spec.NonDetE.liftME Fl4SpecA64.Fl4ArchInvocation.deriveSubframe (Fl4SpecA64.decodeDeriveSubframe (Z := Unit) (args.map UScalar.bv) cte (.frameCap (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev (mapDataA mp asid va)) exs)).run σ) - s a (p.1, p.2, a)) ?_ fun ⟨r, s1⟩ hp => (WP.spec_ok _).2 hp + a (p.1, p.2, a)) ?_ fun ⟨r, s1⟩ hp => (WP.spec_ok _).2 hp unfold vspace.derive_subframe rw [cur_thread_ok, bind_ok] -- 1. Extra cap 0 @@ -1845,46 +1850,23 @@ theorem derive_subframe_jA have h' := hOS1 _ (RS.sub _ (hAd.isSlot E.j.1.place)) unfold capAtA; rw [h'.1, h'.2.1] exact hall0 j hj - have hfr1 : ∀ 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 s1) w)) → - isFrameA (capAtA (L.mem s1) w) = true ∧ ∃ ch ∈ Z.G.chains, cslotAddrA cte ∈ ch ∧ w ∈ ch := by - intro w hw q vm' hq1 hq2 ho - have h' := hOS1 w ((hTr.lk.members w).1 hw).1 - have hcw : capAtA (L.mem s1) w = capAtA (L.mem s) w := by unfold capAtA; rw [h'.1, h'.2.1] - rw [hcw] at ho ⊢ - exact hfr rfl rfl w hw q vm' hq1 hq2 ho -- 9. `insert_subframes` have hins := insert_subframes_refinesA E RS.sub hab hth ⟨hr1, hr58⟩ hfpC hfpAl ⟨hvm1, hvm3⟩ - hcntBound (by omega) hcO E1.j hTr1 hks1 hcpu1 hnul1 hsrc1 hall1 hfr1 - refine WP.spec_bind hins fun s2 ⟨σ2, G2, hm2, hJ2, hT2, hC2⟩ => ?_ - refine (WP.spec_ok _).2 ?_ - set dests := (List.range' a2.val a4.val).map fun j => (specPtr dest, Fl4SpecA64.natToCref radix.val j) - set iv : Fl4SpecA64.Fl4SubframeInvocation := ⟨cte, specPtr fp + a3.bv, vmRightsOfA vm, dests⟩ - have hD : (Fl4Spec.NonDetE.liftME Fl4SpecA64.Fl4ArchInvocation.deriveSubframe - (Fl4SpecA64.decodeDeriveSubframe (Z := Unit) - (List.map UScalar.bv (a0 :: a1 :: a2 :: a3 :: a4 :: a5 :: rest)) cte - (.frameCap (specPtr fp) (vmRightsOfA rt) (frameSizeOfA .Large) false (mapDataA mp asid va)) exs)).run σ = - ({(.ok (.deriveSubframe iv), σ)}, False) := by - refine run_liftME_okA ?_ - rw [decodeDeriveSubframe_stepA hnotTrunc hnotOff hnotCnt hex0_eq, - run_bind_okD hsdOk, run_bind_okD herOk, ← hvmSpec] - rfl - have hperf : (.ok ([] : List Fl4SpecA64.Data), σ2) ∈ - ((Fl4SpecA64.fl4ArchPerformInvocation (Z := Unit) (.deriveSubframe iv)).run σ1).1 := by - unfold Fl4SpecA64.fl4ArchPerformInvocation Fl4SpecA64.performDeriveSubframe + hcntBound (by omega) hcO E1.j hTr1 hks1 hcpu1 hnul1 hsrc1 hall1 + obtain ⟨s2, hs2e, -⟩ := spec_existsA hins + have hdec : (Fl4SpecA64.decodeDeriveSubframe (Z := Unit) + (List.map UScalar.bv (a0 :: a1 :: a2 :: a3 :: a4 :: a5 :: rest)) cte + (.frameCap (specPtr fp) (vmRightsOfA rt) (frameSizeOfA .Large) false (mapDataA mp asid va)) exs).run σ = + ({(.ok (Fl4SpecA64.Fl4SubframeInvocation.mk cte (specPtr fp + a3.bv) (vmRightsOfA vm) + ((List.range' a2.val a4.val).map fun i => (specPtr dest, Fl4SpecA64.natToCref radix.val i))), σ)}, + False) := by + rw [decodeDeriveSubframe_stepA hnotTrunc hnotOff hnotCnt hex0_eq, run_bind_okD hsdOk] dsimp only - have hlenD : dests.length = a4.val := by simp [dests] - have hrg : List.range dests.length = List.range' 0 a4.val := by - rw [hlenD, List.range_eq_range'] - rw [hrg] - exact mem_liftED ⟨((), σ2), by simpa [dests, iv] using hm2, Set.mem_singleton _⟩ - refine ⟨.deriveSubframe iv, okD_memA hD, σ1, hset, σ2, [], hperf, Or.inl ⟨{ Z with G := G2 }, hJ2, hT2, ?_⟩⟩ - intro hC - have hty := TyKeepA.stUpdA hk .restart - exact hC2 ⟨hC.1.of_capsA rfl (fun _ h => h) (fun _ h => h) (fun y hy => Or.inl (by - have h' := hOS1 y (RS.sub y hy); unfold capAtA; rw [h'.1, h'.2.1])), - hC.2.of_keepA hty.1 hty.2 (fun y hy => by - have h' := hOS1 y ((hTr.lk.members y).1 hy).1; unfold capAtA; rw [h'.1, h'.2.1]; exact CapFinEqA.refl _)⟩ + rw [run_bind_okD herOk, hvmSpec] + rfl + rw [hs2e, bind_ok] + exact (WP.spec_ok _).2 ⟨rfl, x, dest, radix, a2, a3, a4, a5, vm, hk, hst, hth, hr1, hr58, hcntBound, + by omega, hoffMod, ⟨hvm1, hvm3⟩, hvmSpec, hall0, hs2e, run_liftME_okA hdec⟩ end subframe_top @@ -1895,7 +1877,7 @@ 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} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} -private theorem decode_frame_subframeA (ar : machine.Arch A) (length : U64) (slot : obj.Slot) +theorem decode_frame_subframeA (ar : machine.Arch A) (length : U64) (slot : obj.Slot) (fp rt asid va : U64) (sz : capability.FrameSize) (dev mp e call : Bool) (buf : U64) (ex : Aeneas.Std.Array obj.Slot 3#usize) : vspace.decode_frame st ar s a fl4_abi.label.ARMPageDeriveSubframe length slot @@ -1941,12 +1923,9 @@ theorem decInv_frame_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (hex : ExtraRelA Z.th (L.mem s) x0 (exs.map Prod.fst)) (hMap : lbl = fl4_abi.label.ARMPageMap → FrPlA sz fp mp asid) (hSub : lbl = fl4_abi.label.ARMPageDeriveSubframe → sz = .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) : + fp.val % 2 ^ 21 = 0 ∧ CapRt.Canonical fp) : syscall.decode_invocation st ar s a lbl length (cslotAddrA cte) (.Frame fp sz rt dev mp e asid va) block call cd - fpb buf ex ⦃ res => ArchTopPostA (L := L) AR Z OS m call σ ((Fl4SpecA64.fl4ArchDecodeInvocation (Z := Unit) call + fpb buf ex ⦃ res => ArchTopErrA σ ((Fl4SpecA64.fl4ArchDecodeInvocation (Z := Unit) call (Fl4SpecA64.fl4LabelOf lbl.bv) (args.map UScalar.bv) xSlot cte (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA sz) dev (mapDataA mp asid va)) exs).run σ) s a res ⦄ := by by_cases h57 : lbl = fl4_abi.label.ARMPageGetAddress @@ -1955,7 +1934,8 @@ theorem decInv_frame_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) have hlab : Fl4SpecA64.fl4LabelOf fl4_abi.label.ARMPageGetAddress.bv = Fl4SpecA64.archL .armPageGetAddress := by rw [fl4LabelOf_bvA, show fl4_abi.label.ARMPageGetAddress.val = 57 by simp [fl4_abi.label.ARMPageGetAddress]]; rfl rw [hlab] - exact page_get_addr_jA E RS hvcR hTr cte fp rt asid va sz dev mp e length buf call ex args xSlot exs + exact WP.spec_mono (page_get_addr_jA E RS hvcR hTr cte fp rt asid va sz dev mp e length buf call ex args xSlot exs) + fun _ h => ArchTopPostA.toErrA (calling := call) h by_cases h56 : lbl = fl4_abi.label.ARMPageTestAndClearAccessed · subst h56 rw [decInv_frameA, decode_frame_testClearA] @@ -1964,7 +1944,8 @@ theorem decInv_frame_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) rw [fl4LabelOf_bvA, show fl4_abi.label.ARMPageTestAndClearAccessed.val = 56 by simp [fl4_abi.label.ARMPageTestAndClearAccessed]]; rfl rw [hlab] - exact test_clear_accessed_jA K E RS hvcR hTO hEO hTr cte hab fp rt asid va sz dev mp e hcap call args xSlot exs + exact WP.spec_mono (test_clear_accessed_jA K E RS hvcR hTO hEO hTr cte hab fp rt asid va sz dev mp e hcap call args xSlot exs) + fun _ h => ArchTopPostA.toErrA (calling := call) h by_cases h55 : lbl = fl4_abi.label.ARMPageDeriveSubframe · subst h55 rw [decInv_frameA, decode_frame_subframeA] @@ -1973,9 +1954,9 @@ theorem decInv_frame_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) rw [fl4LabelOf_bvA, show fl4_abi.label.ARMPageDeriveSubframe.val = 55 by simp [fl4_abi.label.ARMPageDeriveSubframe]]; rfl rw [hlab] - exact derive_subframe_jA E RS hTr hnul hcO cte hab fp rt asid va sz dev mp e hcap - (fun h1 h2 => (hSub rfl h1 h2).1) (fun h1 h2 => (hSub rfl h1 h2).2) - length buf call ex args hlen hargs x0 hx0 xSlot exs hex + exact WP.spec_mono (derive_subframe_jA E RS hTr hnul hcO cte hab fp rt asid va sz dev mp e hcap + (fun h1 h2 => hSub rfl h1 h2) + length buf call ex args hlen hargs x0 hx0 xSlot exs hex) fun _ h => ArchTopSubA.toErrA h have hLbl : lbl.val ≤ 54 ∨ 57 < lbl.val := by have h55' : lbl.val ≠ 55 := fun h => h55 (UScalar.eq_of_val_eq (by rw [h]; simp [fl4_abi.label.ARMPageDeriveSubframe])) have h56' : lbl.val ≠ 56 := fun h => h56 (UScalar.eq_of_val_eq (by rw [h]; simp [fl4_abi.label.ARMPageTestAndClearAccessed])) @@ -1983,7 +1964,7 @@ theorem decInv_frame_all_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) omega exact WP.spec_mono (decInv_frame_jA K E RS hTO hEO hK hT hIpa hTr hnul cte hab hos fp rt asid va sz dev mp e hcap lbl length buf block call cd fpb call ex args hlen hargs x0 hx0 xSlot exs hex hLbl hMap) - fun _ hr => ArchTopPostA.of_vsTopA hr + fun _ hr => ArchTopPostA.toErrA (calling := call) (ArchTopPostA.of_vsTopA (calling := call) hr) end frame_all diff --git a/proofs/Fl4ProofsA64/P3/FrSubframeJ5A.lean b/proofs/Fl4ProofsA64/P3/FrSubframeJ5A.lean new file mode 100644 index 000000000..1e11a27fd --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/FrSubframeJ5A.lean @@ -0,0 +1,383 @@ +/- +P3 (AArch64, E0.5b): **the `n`-fold subframe insertion with the J5 slot** — `insert_subframes_refinesA` (FrSubframeA) with +the carried J5 slot (`J5A.insSubA` per step), `FrLamA` (kept by each insertion: `FrLamA.derivA` over `CapsFromA.of_insA`) +and the slot facts the `JStage3A` arm reads: every slot off the window keeps its cap and revocable bit, each window slot +holds its subframe cap, non-revocable. + +Named premises: none. New module. +-/ +import Fl4ProofsA64.P3.FrSubframeA +import Fl4ProofsA64.P3.Stage3CnInsSubA +import Fl4ProofsA64.P3.Stage3CapDerivA +import Fl4ProofsA64.P3.CapInsSpecQA +import Fl4ProofsA64.P3.DelStepSpecA +import Fl4ProofsA64.P1.S1aSubLoop +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- The spec slots `insert_subframes` writes: the `count` slots from `first` of the CNode `dest` (E0.5c). -/ +def SubDmA (dest : U64) (r first count : Nat) : Fl4SpecA64.CslotPtr → Prop := + fun sl => ∃ j < count, sl = (specPtr dest, Fl4SpecA64.natToCref r (first + j)) + +/-- The caps it writes: unmapped, non-device 4 KiB frame caps. -/ +def SubPcA : Fl4SpecA64.Cap → Prop := + fun c => ∃ p rr, c = .archObjectCap (.frameCap p rr .armSmallPage false none) + +section subframe_j5 +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} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} {n : Nat} + +set_option maxHeartbeats 8000000 in +/-- **`vspace.insert_subframes` with the J5 slot and `FrLamA`** (module docstring). -/ +theorem insert_subframes_j5A + (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) + (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) + {ss : Fl4SpecA64.CslotPtr} (hAs : AbsSlotA Z.th ss) + {dest : U64} {r : Nat} (hth : Z.th dest = some (.cnode r)) (hr : 1 ≤ r ∧ r ≤ 58) + {fp rt asid va offset first count vm : U64} {mp e : Bool} + (hfpC : CapRt.Canonical fp) (hfpAl : fp.val % 2 ^ 21 = 0) + (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) + (hoff : offset.val + count.val * 4096 ≤ 2 ^ 21) + (hfc : first.val + count.val ≤ 2 ^ r) + (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) + {s0 : S} {σ0 : Fl4SpecA64.State Unit} + (hJ0 : JAtZAX (L := L) AR Z s0 a σ0 m) + (hT0 : TreeA st OS Z.G.chains Z.G.par s0) + (hks0 : L.ksb s0 = L.ksb s) (hcpu0 : L.cpu s0 = L.cpu s) + (hnul0 : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s0 y = .Null) + (hsrc0 : capAtA (L.mem s0) (cslotAddrA ss) = .Frame fp .Large rt false mp e asid va) + (hall0 : ∀ j < count.val, capAtA (L.mem s0) (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null) + (J50 : J5A st Z H OS s0 σ0 m) (hLam0 : FrLamA st OS s0) (hoff4 : offset.val % 4096 = 0) + (hS0 : SInvXA σ0 m n) (hdo : ¬ IrqNodeA (L.ksb s) dest) : + vspace.insert_subframes st s0 (cslotAddrA ss) dest first (wa fp offset) count vm ⦃ s2 => + let ds := (List.range' first.val count.val).map fun j => (specPtr dest, Fl4SpecA64.natToCref r j) + let ps := (List.range' 0 count.val).zip ds + ∃ σ2 G2, + ((), σ2) ∈ (Fl4Spec.NonDet.mapMx (fun d : Nat × Fl4SpecA64.CslotPtr => + Fl4SpecA64.capInsert (Z := Unit) (.archObjectCap (.frameCap + (specPtr fp + offset.bv + BitVec.ofNat 64 (d.1 * 4096)) (vmRightsOfA vm) .armSmallPage false none)) + ss d.2) ps σ0).1 ∧ + JAtZAX (L := L) AR { Z with G := G2 } s2 a σ2 m ∧ + TreeA st OS G2.chains G2.par s2 ∧ + J5A st { Z with G := G2 } H OS s2 σ2 m ∧ FrLamA st OS s2 ∧ + (∀ y ∈ OS, (∀ j < count.val, y ≠ cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) → + capA st s2 y = capA st s0 y ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s2 y = Fl4ProofsA64.P1.W7.R.ST.revA st s0 y) ∧ + (∀ j < count.val, ∀ z : U64, z.val = j * 4096 → + capA st s2 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = + .Frame (wa fp (wa offset z)) .Small vm false false false 0#u64 0#u64 ∧ + Fl4ProofsA64.P1.W7.R.ST.revA st s2 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = false) ∧ + WritesIn st s0 s2 (W7.CapW H.tcbs {b | InOS OS b} ∅) ∧ + SubQA (SubDmA dest r first.val count.val) SubPcA σ0 σ2 ∧ SInvXA σ2 m n ∧ + (∀ j < count.val, DerivA (capA st s2 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)))) (.Frame fp .Large rt false mp e asid va)) ⦄ := by + unfold vspace.insert_subframes vspace.insert_subframes_loop + have h2r58 : 2 ^ r ≤ 2 ^ 58 := Nat.pow_le_pow_right (by omega) hr.2 + apply loop.spec_decr_nat (measure := fun p : S × U64 => count.val - p.2.val) + (inv := fun p : S × U64 => + let (s1, i) := p + i.val ≤ count.val ∧ + ∃ σ1 G1, + ((), σ1) ∈ (Fl4Spec.NonDet.mapMx (fun d : Nat × Fl4SpecA64.CslotPtr => + Fl4SpecA64.capInsert (Z := Unit) (.archObjectCap (.frameCap + (specPtr fp + offset.bv + BitVec.ofNat 64 (d.1 * 4096)) (vmRightsOfA vm) .armSmallPage false none)) + ss d.2) ((List.range' 0 i.val).zip ((List.range' first.val i.val).map fun j => + (specPtr dest, Fl4SpecA64.natToCref r j))) σ0).1 ∧ + JAtZAX (L := L) AR { Z with G := G1 } s1 a σ1 m ∧ + TreeA st OS G1.chains G1.par s1 ∧ + L.ksb s1 = L.ksb s ∧ L.cpu s1 = L.cpu s ∧ + (∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s1 y = .Null) ∧ + capAtA (L.mem s1) (cslotAddrA ss) = .Frame fp .Large rt false mp e asid va ∧ + (∀ j, i.val ≤ j → j < count.val → + capAtA (L.mem s1) (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null) ∧ + J5A st { Z with G := G1 } H OS s1 σ1 m ∧ FrLamA st OS s1 ∧ + (∀ y ∈ OS, (∀ j < i.val, y ≠ cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) → + capA st s1 y = capA st s0 y ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s1 y = Fl4ProofsA64.P1.W7.R.ST.revA st s0 y) ∧ + (∀ j < i.val, ∀ z : U64, z.val = j * 4096 → + capA st s1 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = + .Frame (wa fp (wa offset z)) .Small vm false false false 0#u64 0#u64 ∧ + Fl4ProofsA64.P1.W7.R.ST.revA st s1 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = false) ∧ + WritesIn st s0 s1 (W7.CapW H.tcbs {b | InOS OS b} ∅) ∧ + SubQA (SubDmA dest r first.val count.val) SubPcA σ0 σ1 ∧ SInvXA σ1 m n ∧ + (∀ j < i.val, DerivA (capA st s1 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)))) (.Frame fp .Large rt false mp e asid va))) + · rintro ⟨s1, i⟩ ⟨hi, σ1, G1, hm1, hJ1, hT1, hks1, hcpu1, hnul1, hsrc1, hall1, hJ51, hLam1, hKeep1, hWin1, hWr1, hQ1, hSI1, hDer1⟩ + dsimp only + unfold vspace.insert_subframes_loop.body + by_cases hlt : i < count + · rw [if_pos hlt] + have hiLt : i.val < count.val := hlt + have hshl : (i <<< 12#i32) ⦃ i1 => i1.val = i.val * 4096 ⦄ := by + step as ⟨i1, hi1⟩ + have hlt64 : i.val * 4096 < 2 ^ 64 := by omega + simp only [U64.size, U64.numBits, UScalarTy.U64_numBits_eq, Nat.shiftLeft_eq] at hi1 + rw [Nat.mod_eq_of_lt hlt64] at hi1 + exact hi1 + obtain ⟨i1, hi1Ok, hi1Val⟩ := spec_ex_fd hshl + have hsum : (wa first i).val = first.val + i.val := by + rw [wa_valP]; exact Nat.mod_eq_of_lt (by omega) + have hki : (wa offset i1).val = offset.val + i.val * 4096 := by + rw [wa_valP, hi1Val]; exact Nat.mod_eq_of_lt (by omega) + have hwa_assoc : wa (wa fp offset) i1 = wa fp (wa offset i1) := by + apply UScalar.eq_of_val_eq + simp only [wa_valP, hi1Val] + have : offset.val + i.val * 4096 < 2 ^ 64 := by omega + rw [Nat.mod_eq_of_lt this]; omega + have hsl : obj.Slot.index dest (wa first i) = + ok (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + i.val))) := by + rw [slotIndex_eqA dest (wa first i) (by omega), hsum, cslotAddr_natToCrefA dest r hr _ (by omega)] + rw [hi1Ok, bind_ok] + simp only [lift, bind_ok, hsl, hwa_assoc] + set sd : Fl4SpecA64.CslotPtr := (specPtr dest, Fl4SpecA64.natToCref r (first.val + i.val)) + have hAd : AbsSlotA Z.th sd := ⟨dest, rfl, Or.inl (by rw [natToCref_lengthA r _ (by omega)]; exact hth)⟩ + have hdn : capAtA (L.mem s1) (cslotAddrA sd) = .Null := hall1 i.val le_rfl hiLt + have hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd) := hcO _ (hsub _ (hAd.isSlot hJ1.1.place)) + have hqval : (wa fp (wa offset i1)).val = fp.val + (wa offset i1).val := by + rw [wa_valP] + have : fp.val + 2 ^ 21 ≤ 2 ^ 64 := by + have : fp.val < 2 ^ 64 := fp.hBounds; omega + exact Nat.mod_eq_of_lt (by omega) + have hstep := cap_insert_frame_stepA E hJ1 hT1 hks1 hcpu1 hsub hnul1 hAs hAd hsrc1 hdn hdc hfpC hfpAl hvm + (k := wa offset i1) (by omega) + try dsimp only at hstep + have hO := E.sys.ent.os + have hsOS : cslotAddrA ss ∈ OS := hsub _ (hAs.isSlot hJ1.1.place) + have hdOS : cslotAddrA sd ∈ OS := hsub _ (hAd.isSlot hJ1.1.place) + have hcs1 : capA st s1 (cslotAddrA ss) = .Frame fp .Large rt false mp e asid va := hsrc1 + have hss_ne_sd : cslotAddrA ss ≠ cslotAddrA sd := fun e => by rw [e, hdn] at hsrc1; cases hsrc1 + have hk4 : (wa offset i1).val + 4096 ≤ 2 ^ 21 := by omega + have hfit : fp.val + 2 ^ 21 ≤ 2 ^ 64 := by have : fp.val < 2 ^ 64 := fp.hBounds; omega + have hki' : (wa offset i1).val = offset.val + i.val * 4096 := hki + have hkk : (offset.val / 4096 + i.val) * 4096 = (wa offset i1).val := by omega + have hpk : (wa fp (wa offset i1)).val = fp.val + (offset.val / 4096 + i.val) * 4096 := by rw [hqval, hkk] + have hkb : (offset.val / 4096 + i.val) * 4096 + 4096 ≤ 2 ^ 21 := by omega + have hS : Fl4ProofsA64.P1.W7.R.ST.SubA + (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) (capA st s1 (cslotAddrA ss)) := by + rw [hcs1]; exact Fl4ProofsA64.P1.W7.R.ST.subA_large hpk hkb hfit + have hsF : isFrA (capA st s1 (cslotAddrA ss)) = true := by rw [hcs1]; rfl + have hcF : isFrA (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) = true := rfl + have hsn1 : capA st s1 (cslotAddrA ss) ≠ .Null := by rw [hcs1]; intro h; cases h + have hsG : cslotAddrA ss ∈ G1.chains.flatten := (hT1.lk.members _).2 ⟨hsOS, hsn1⟩ + have hnN : NxA st s1 (cslotAddrA ss) ≠ 0#u64 → NxA st s1 (cslotAddrA ss) ∈ OS := + fun h => ((hT1.lk.members _).1 ((hT1.lk.lkF hO.nz).nxm _ hsG h)).1 + have hno : ∀ x ∈ G1.chains.flatten, physA (capA st s1 x) = true → + DisjA (capA st s1 x) (capA st s1 (cslotAddrA ss)) ∨ + (isFrA (capA st s1 x) = true ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s1 x = false) ∨ + WithinA (capA st s1 (cslotAddrA ss)) (capA st s1 x) := + fun x hx hp => hLam1 (cslotAddrA ss) hsOS fp rt mp e asid va hcs1 x ((hT1.lk.members x).1 hx).1 hp + obtain ⟨hfnOff, hal1⟩ := subframe_foot_offA E hJ1 hks1 hcpu1 + have hst : ∀ s', WritesIn st s1 s' (W7.CapW H.tcbs {b | InOS OS b} ∅) → + ∀ ii : U64, ii.val < 5376 → L.mem s' (irqStAddrA (L.ksb s1) ii) = L.mem s1 (irqStAddrA (L.ksb s1) ii) := + fun s' w ii hi => w.mem_eq (hal1 _ (.irq ii hi)) (hfnOff _ (.irq ii hi)) + have hIns : cdt.insert st s1 (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) + (cslotAddrA ss) (cslotAddrA sd) = cdt.insert_with_cap st s1 + (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) (capA st s1 (cslotAddrA ss)) + (cslotAddrA ss) (cslotAddrA sd) := by + unfold cdt.insert; rw [capA_eq, bind_ok] + have hw : CapRt.EncWf (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) := + subframe_encWfA hfpC hfpAl hvm (by omega) + obtain ⟨s2, hs2, σ2, G2, hGeq, hG2, hm2, hJ2, hT2, hks2, hcpu2, hnul2, hkeep2, hsd2, hwS2, hSS2⟩ := spec_existsA hstep + have mJ := J5A.insSubA (σ' := σ2) (m := m) (m' := m) hO hJ51 hT1 hsOS hdOS (hAs.isSlot hJ1.1.place) + (hAd.isSlot hJ1.1.place) hsn1 hdn hdc hw hS hsF hcF hno hst + rw [← hIns] at mJ + obtain ⟨s2', hs2', wJ, edJ, hfullJ, ekJ, J52⟩ := spec_existsA mJ + rw [hs2] at hs2' + have e1 : s2' = s2 := (okinj hs2').symm + subst s2' + have mB := insWC_bitsA hO hsOS hdOS hss_ne_sd rfl hw hnN + rw [← hIns] at mB + obtain ⟨s2'', hs2'', hbk, hrd, hfd⟩ := spec_existsA mB + rw [hs2] at hs2'' + have e2 : s2'' = s2 := (okinj hs2'').symm + subst s2'' + rw [hs2, bind_ok] + have hinc : (i + 1#u64) ⦃ i4 => i4.val = i.val + 1 ⦄ := by step as ⟨i4, hi4⟩; omega + obtain ⟨i4, hi4Ok, hi4Val⟩ := spec_ex_fd hinc + rw [hi4Ok, bind_ok, WP.spec_ok] + have hsrc2 : capAtA (L.mem s2) (cslotAddrA ss) = .Frame fp .Large rt false mp e asid va := by + rw [hkeep2 _ (hsub _ (hAs.isSlot hJ1.1.place)) hss_ne_sd, hsrc1] + have hall2 : ∀ j, i4.val ≤ j → j < count.val → + capAtA (L.mem s2) (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null := by + intro j hj1 hj2 + set sd' : Fl4SpecA64.CslotPtr := (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) + have hAd' : AbsSlotA Z.th sd' := ⟨dest, rfl, Or.inl (by rw [natToCref_lengthA r _ (by omega)]; exact hth)⟩ + have hne : cslotAddrA sd' ≠ cslotAddrA sd := fun e => by + have h3 := cslotAddr_natToCrefA dest r hr (first.val + j) (by omega) + have h4 := cslotAddr_natToCrefA dest r hr (first.val + i.val) (by omega) + rw [h3, h4] at e + have hbv : dest.bv + BitVec.ofNat 64 ((first.val + j) * 32) = + dest.bv + BitVec.ofNat 64 ((first.val + i.val) * 32) := congrArg UScalar.bv e + have h5 := congrArg BitVec.toNat (add_left_cancel hbv) + rw [BitVec.toNat_ofNat, BitVec.toNat_ofNat, + Nat.mod_eq_of_lt (by omega : (first.val + j) * 32 < 2 ^ 64), + Nat.mod_eq_of_lt (by omega : (first.val + i.val) * 32 < 2 ^ 64)] at h5 + omega + rw [hkeep2 _ (hsub _ (hAd'.isSlot hJ1.1.place)) hne] + exact hall1 j (by omega) hj2 + have hanc : absCapA (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) = + .archObjectCap (.frameCap (specPtr fp + offset.bv + BitVec.ofNat 64 (i.val * 4096)) + (vmRightsOfA vm) .armSmallPage false none) := by + simp only [absCapA, absFrameE, Bool.false_eq_true, ↓reduceIte, frameSizeOfA, mapDataA, specPtr_wa] + have hptr : specPtr fp + (wa offset i1).bv = specPtr fp + offset.bv + BitVec.ofNat 64 (i.val * 4096) := by + rw [add_assoc]; congr 1 + apply BitVec.eq_of_toNat_eq + rw [BitVec.toNat_add, BitVec.toNat_ofNat] + have h1 : (wa offset i1).bv.toNat = offset.val + i.val * 4096 := hki + have h2 : offset.bv.toNat = offset.val := rfl + rw [h1, h2, Nat.mod_eq_of_lt (by omega : i.val * 4096 < 2 ^ 64), + Nat.mod_eq_of_lt (by omega : offset.val + i.val * 4096 < 2 ^ 64)] + rw [hptr] + rw [hanc] at hm2 + have hzip : ((List.range' 0 i4.val).zip ((List.range' first.val i4.val).map fun j => + (specPtr dest, Fl4SpecA64.natToCref r j))) = + ((List.range' 0 i.val).zip ((List.range' first.val i.val).map fun j => + (specPtr dest, Fl4SpecA64.natToCref r j))) ++ [(i.val, sd)] := by + have hr1 : List.range' 0 i4.val = List.range' 0 i.val ++ [i.val] := by + rw [hi4Val, List.range'_concat]; simp + have hr2 : List.range' first.val i4.val = List.range' first.val i.val ++ [first.val + i.val] := by + rw [hi4Val, List.range'_concat]; simp + rw [hr1, hr2, List.map_append, List.map_singleton, List.zip_append (by simp)] + rfl + have hslne : ∀ j, j < count.val → j ≠ i.val → + cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) ≠ cslotAddrA sd := fun j hj hji e => by + have h3 := cslotAddr_natToCrefA dest r hr (first.val + j) (by omega) + have h4 := cslotAddr_natToCrefA dest r hr (first.val + i.val) (by omega) + rw [h3, h4] at e + have hbv : dest.bv + BitVec.ofNat 64 ((first.val + j) * 32) = + dest.bv + BitVec.ofNat 64 ((first.val + i.val) * 32) := congrArg UScalar.bv e + have h5 := congrArg BitVec.toNat (add_left_cancel hbv) + rw [BitVec.toNat_ofNat, BitVec.toNat_ofNat, + Nat.mod_eq_of_lt (by omega : (first.val + j) * 32 < 2 ^ 64), + Nat.mod_eq_of_lt (by omega : (first.val + i.val) * 32 < 2 ^ 64)] at h5 + omega + have hGJ : G2 = ⟨insG (cslotAddrA ss) (cslotAddrA sd) G1.chains, insParA G1.par (cslotAddrA ss) (cslotAddrA sd) + (isPFA (Fl4ProofsA64.P1.W7.R.ST.revA st s1 (cslotAddrA ss)) (capA st s1 (cslotAddrA ss)) + (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) + (revFA (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) + (capA st s1 (cslotAddrA ss))))⟩ := by + rw [hGeq] + unfold insGA + have hbeq : insBA σ1 ss (absCapA (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64)) + (absCapA (capA st s1 (cslotAddrA ss))) = + isPFA (Fl4ProofsA64.P1.W7.R.ST.revA st s1 (cslotAddrA ss)) (capA st s1 (cslotAddrA ss)) + (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) + (revFA (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) + (capA st s1 (cslotAddrA ss))) := by + unfold insBA + rw [hJ1.1.cdt.orig ss hAs] + obtain ⟨_, -, hcr⟩ := hJ1.1.st.getAbsA hAs + rw [hsrc1] at hcr + have hwfN := subframe_wfA (vm := vm) hcr.1 hvm hk4 + have hsr := subframe_srA (vm := vm) hcr.1 hk4 + have hS' := hS + rw [hcs1] at hS' + rw [hcs1] + exact sbp_eqFrA _ _ _ rfl hcF hsr ((Fl4ProofsA64.P1.W7.R.ST.sraA_frame_iff rfl).2 ⟨hcF, hS'.win, hS'.reg⟩) + trivial hwfN + rw [hbeq] + rfl + have hxk : capA st s2 (cslotAddrA ss) = capA st s1 (cslotAddrA ss) := by + rcases hfullJ with e | ⟨p, b, ii, d, i1', h1, h2, -⟩ + · first | exact e | exact e.symm + · rw [h1] at hsF; simp [isFrA] at hsF + have hek : ∀ y ∈ OS, y ≠ cslotAddrA sd → capA st s2 y = capA st s1 y := fun y hy hyd => by + by_cases hys : y = cslotAddrA ss + · rw [hys]; exact hxk + · exact ekJ y hy hys hyd + have hrv : ∀ y ∈ OS, y ≠ cslotAddrA sd → + Fl4ProofsA64.P1.W7.R.ST.revA st s2 y = Fl4ProofsA64.P1.W7.R.ST.revA st s1 y := fun y hy hyd => (hbk y hy hyd).1 + have hrdf : Fl4ProofsA64.P1.W7.R.ST.revA st s2 (cslotAddrA sd) = false := by rw [hrd]; exact revFA_frame hcF (capA st s1 (cslotAddrA ss)) + have hDsubF : DerivA (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) + (.Frame fp .Large rt false mp e asid va) := by + refine DerivA.sub fp (wa fp (wa offset i1)) .Large rt vm mp e asid va false false 0#u64 0#u64 + (offset.val / 4096 + i.val) hpk ?_ + intro bits hb + have hb21 : capability.FrameSize.bits .Large = ok 21#u64 := rfl + rw [hb21] at hb + have := okinj hb + subst this + exact ⟨by simpa using hkb, by simpa using hfit⟩ + have hDsub : DerivA (.Frame (wa fp (wa offset i1)) .Small vm false false false 0#u64 0#u64) + (capA st s1 (cslotAddrA ss)) := by rw [hcs1]; exact hDsubF + have FC : CapsFromA st OS s1 s2 := + CapsFromA.of_insA hsOS hdOS hDsub hdn edJ hfullJ (fun p b ii d h => by rw [hcs1] at h; cases h) ekJ + (fun y hy hyd => (hbk y hy hyd).1) (fun _ => hrdf) + have hLam2 : FrLamA st OS s2 := FrLamA.derivA FC hLam1 + have hKeep2 : ∀ y ∈ OS, (∀ j < i4.val, y ≠ cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) → + capA st s2 y = capA st s0 y ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s2 y = Fl4ProofsA64.P1.W7.R.ST.revA st s0 y := by + intro y hy hyj + have hyd : y ≠ cslotAddrA sd := hyj i.val (by omega) + rw [hek y hy hyd, hrv y hy hyd] + exact hKeep1 y hy (fun j hj => hyj j (by omega)) + have hWin2 : ∀ j < i4.val, ∀ z : U64, z.val = j * 4096 → + capA st s2 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = + .Frame (wa fp (wa offset z)) .Small vm false false false 0#u64 0#u64 ∧ + Fl4ProofsA64.P1.W7.R.ST.revA st s2 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = false := by + intro j hj z hz + by_cases hji : j = i.val + · subst hji + have hz1 : z = i1 := UScalar.eq_of_val_eq (by omega) + subst hz1 + exact ⟨edJ, hrdf⟩ + · have hne := hslne j (by omega) hji + have hj' : j < i.val := by omega + obtain ⟨c1, c2⟩ := hWin1 j hj' z hz + have hAdj : AbsSlotA Z.th (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) := + ⟨dest, rfl, Or.inl (by rw [natToCref_lengthA r _ (by omega)]; exact hth)⟩ + have hOSj := hsub _ (hAdj.isSlot hJ1.1.place) + exact ⟨by rw [hek _ hOSj hne]; exact c1, by rw [hrv _ hOSj hne]; exact c2⟩ + have hWr2 : WritesIn st s0 s2 (W7.CapW H.tcbs {b | InOS OS b} ∅) := hWr1.trans1 hwS2 + have hQ2 : SubQA (SubDmA dest r first.val count.val) SubPcA σ0 σ2 := by + obtain ⟨asc, hgs, hceq⟩ := getCap_eqA hJ1.1.st hAs + obtain ⟨dc, hgd0, -⟩ := getCap_eqA hJ1.1.st hAd + have hgd : ∀ y ∈ (getCap (Z := Unit) sd σ1).1, y.2 = σ1 := fun y hy => by + rw [hgd0] at hy; obtain rfl : y = (dc, σ1) := hy; rfl + have hceq' : absCapA (.Frame fp .Large rt false mp e asid va) = asc := by + have h := hceq; rw [hsrc1] at h; exact h + have hmf : maxFreeIndexUpdate asc = asc := by + rw [← hceq']; first | rfl | simp [absCapA, absFrameE, maxFreeIndexUpdate] + have hsa : specCapAtA σ1 ss = some asc := getCap_specAtA (by rw [hgs]; exact Set.mem_singleton _) + exact hQ1.trans (SubQA.ofInsert hgs hgd hm2 hSS2 (absSlot_kheapA hJ1.1.st hAs) + (absSlot_kheapA hJ1.1.st hAd) hmf hsa ⟨i.val, hiLt, rfl⟩ + ⟨_, _, by first | rfl | simp [absCapA, absFrameE]⟩) + have hSI2 : SInvXA σ2 m n := by + have hnode : ¬ IrqNodeA (L.ksb s1) (fl4Ptr sd.1) := by + show ¬ IrqNodeA (L.ksb s1) (fl4Ptr (specPtr dest)) + rw [hks1, fl4Ptr_specPtr]; exact hdo + refine SInvXA.capInsert hSI1 (r := ((), σ2)) ?_ hm2 + refine ⟨fun irq hirq e => ?_, fun ⟨irq, hirq, n, g, e⟩ => by cases e⟩ + exact absurd ((specPtr_fl4Ptr _).trans e) (offNode_ofA hJ1.1.irq hnode irq hirq) + have hDer2 : ∀ j < i4.val, DerivA (capA st s2 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)))) + (.Frame fp .Large rt false mp e asid va) := by + intro j hj + by_cases hji : j = i.val + · subst hji; rw [edJ]; exact hDsubF + · have hne := hslne j (by omega) hji + have hj' : j < i.val := by omega + have hAdj : AbsSlotA Z.th (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) := + ⟨dest, rfl, Or.inl (by rw [natToCref_lengthA r _ (by omega)]; exact hth)⟩ + rw [hek _ (hsub _ (hAdj.isSlot hJ1.1.place)) hne] + exact hDer1 j hj' + have J5new : J5A st { Z with G := G2 } H OS s2 σ2 m := by rw [hGJ]; exact J52 + refine ⟨⟨by dsimp only; omega, σ2, G2, ?_, hJ2, hT2, hks2, hcpu2, hnul2, hsrc2, hall2, J5new, hLam2, hKeep2, hWin2, hWr2, hQ2, hSI2, hDer2⟩, by dsimp only; omega⟩ + rw [hzip] + exact mapMx_appendA _ _ _ hm1 (by + unfold Fl4Spec.NonDet.mapMx Fl4Spec.NonDet.bind + exact ⟨((), σ2), hm2, Set.mem_singleton _⟩) + · rw [if_neg hlt, WP.spec_ok] + have hieq : i.val = count.val := by have : ¬ (i.val < count.val) := hlt; omega + rw [hieq] at hm1 + refine ⟨σ1, G1, hm1, hJ1, hT1, hJ51, hLam1, fun y hy hyj => hKeep1 y hy (fun j hj => hyj j (by omega)), fun j hj z hz => hWin1 j (by omega) z hz, hWr1, hQ1, hSI1, fun j hj => hDer1 j (by omega)⟩ + · exact ⟨by change 0 ≤ count.val; omega, σ0, Z.G, Set.mem_singleton _, hJ0, hT0, hks0, hcpu0, hnul0, hsrc0, + fun j _ hj => hall0 j hj, J50, hLam0, fun y hy _ => ⟨rfl, rfl⟩, fun j hj => absurd hj (by simp), WritesIn.refl s0 _, SubQA.refl σ0, hS0, fun j hj => absurd hj (by simp)⟩ + + +end subframe_j5 + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/FrameA.lean b/proofs/Fl4ProofsA64/P3/FrameA.lean index 459131f52..56093b98c 100644 --- a/proofs/Fl4ProofsA64/P3/FrameA.lean +++ b/proofs/Fl4ProofsA64/P3/FrameA.lean @@ -234,6 +234,15 @@ theorem SameNA.ext {σ : Fl4SpecA64.State Unit} (h : ExtVsRelA Z.Pp Z.S1 Z.X Z.Y ExtVsRelA Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') σ := h.of_mem fun b hb => H.mem b (.ext b hb) +/-- (Stage 5) `VsUniqA` carried by a state agreeing on the footprint outside the slots, when the page-table caps are +closed (`PtClosedA`). -/ +theorem SameNA.vsu {σ σ' : Fl4SpecA64.State Unit} + (h : VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s) (L.ksb s) σ) (hxal : ∀ r ∈ Z.X, 8192 ∣ r.val) + (hP : PoolKeepA Z.Pp σ σ') (hpt : PtClosedA Z.th Z.S1 Z.T2 (L.mem s) (L.mem s')) : + VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ' := by + rw [H.ksb] + exact h.of_frame hxal (fun b hb => H.mem b (hb.elim (.ext b) (.vs b))) hP hpt + theorem SameNA.tcb2W {t : U64} (ht : t ∈ Z.T) : L.mem s' (prioA t) = L.mem s (prioA t) ∧ L.mem s' (domA t) = L.mem s (domA t) := ⟨H.mem _ (.tcb2 _ _ ht (Or.inl rfl)), H.mem _ (.tcb2 _ _ ht (Or.inr rfl))⟩ @@ -619,6 +628,10 @@ def TcbKeepA (T : Set U64) (σ σ' : Fl4SpecA64.State Unit) : Prop := theorem TcbKeepA.of_eq {T : Set U64} (hT : ∀ t ∈ T, σ'.kheap (specPtr t) = σ.kheap (specPtr t)) : TcbKeepA T σ σ' := fun t ht x e => ⟨x, by rw [hT t ht]; exact e, rfl⟩ +/-- The pools and the ASID table kept (`VsUniqA`). -/ +theorem SpecSameA.pool (H : SpecSameA Z m σ σ') : PoolKeepA Z.Pp σ σ' := + ⟨H.asid, fun p hp => H.kh _ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨p, hp, rfl⟩)))))))⟩ + theorem SpecSameA.th (H : SpecSameA Z m σ σ') {q : U64} {k : ObjKindA} (h : Z.th q = some k) : σ'.kheap (specPtr q) = σ.kheap (specPtr q) := H.kh _ (Or.inl ⟨q, by rw [h]; exact Option.some_ne_none _, rfl⟩) @@ -712,6 +725,7 @@ theorem JAtZAX.of_spec {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨q, hq, rfl⟩)))))) · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨q, hq, rfl⟩))))))) · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨q, hq, rfl⟩)))))) + vsu := J.vsu.of_frame J.ext.xal (fun _ _ => rfl) H.pool (PtClosedA.refl _ _ _ _) ext := J.ext.of_spec H.asid fun q hq => H.kh _ (by rcases hq with hq | hq | hq · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨q, hq, rfl⟩)))))) @@ -760,9 +774,10 @@ theorem JAtZAX.capObj {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L) /-- **`JAtZAX` across a slot-only step** (gen 5, ruling 11:09Z item 3): the words outside the slots are kept (`SameNA`), the spec changes only CNode contents, the CDT and the original-cap map (`SpecSlotA`), the CSpace and CDT relations hold afterwards at the new ghost `G'`, and every slot's cap names counted objects. -/ -theorem JAtZAX.of_slot {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L) AR Z s a σ m) (G' : MdbGhostA) +theorem JAtZAX.of_slotV {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L) AR Z s a σ m) (G' : MdbGhostA) (H : SameNA (L := L) Z s s') (HS : SpecSlotA σ σ') (hst : StateRelA Z.th (L.mem s') σ') - (hcdt : CdtRelA st Z.th s' σ' G') (hcap : ∀ y, IsSlotA Z.th y → CapObjOkA Z (capAtA (L.mem s') y)) : + (hcdt : CdtRelA st Z.th s' σ' G') (hcap : ∀ y, IsSlotA Z.th y → CapObjOkA Z (capAtA (L.mem s') y)) + (hv : VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ') : JAtZAX (L := L) AR { Z with G := G' } s' a σ' m := by obtain ⟨J, V, X, Y⟩ := J have hT : TcbKeepA Z.T σ σ' := fun t _ x e => HS.tcb e @@ -790,6 +805,7 @@ theorem JAtZAX.of_slot {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L cv := fun y hy => (hcap y hy).2.2.2.2 pml := fun y hy => (hcap y hy).2.2.2.1 vs := (H.vs J.vs).of_specSlot HS HS.asid + vsu := hv ext := (H.ext J.ext).of_specSlot J.vs HS } refine ⟨J', ?_, ?_, ?_⟩ · refine ⟨fun v hv => ?_, fun p x e => V.back p x (HS.back e (fun _ _ h => by cases h) (fun _ h => by cases h)), @@ -811,12 +827,38 @@ theorem JAtZAX.of_slot {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L obtain ⟨l1, e⟩ := Y.obj r hr exact ⟨l1, HS.keep e (fun _ _ h => by cases h) (fun _ h => by cases h)⟩ +/-- (Stage 5) **`VsUniqA` across a step that keeps `ksb`** (the producers of `JAtZA` that rebuild the VSpace records): +words kept on the two footprints, the pools and ASID table kept, every slot's cap kept or no page-table cap. -/ +theorem JAtZA.vsuOf {AR : A → HwRootA → Prop} {a : A} (J : JAtZA (L := L) AR Z s a σ m) {s' : S} + {σ' : Fl4SpecA64.State Unit} (hks : L.ksb s' = L.ksb s) + (hmem : ∀ b, ExtFootE Z.X Z.Y Z.T2 b ∨ VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b → L.mem s' b = L.mem s b) + (hP : PoolKeepA Z.Pp σ σ') (hpt : PtClosedA Z.th Z.S1 Z.T2 (L.mem s) (L.mem s')) : + VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ' := by + rw [hks]; exact J.vsu.of_frame J.ext.xal hmem hP hpt + +/-- The pools and the ASID table kept by a slot-only spec step. -/ +theorem JAtZA.poolSlot {AR : A → HwRootA → Prop} {a : A} (J : JAtZA (L := L) AR Z s a σ m) + (HS : SpecSlotA σ σ') : PoolKeepA Z.Pp σ σ' := + ⟨HS.asid, fun p hp => by + rcases HS.kh (specPtr p) with e | ⟨r, cs, cs', h1, -⟩ | ⟨x, x', h1, -⟩ + · exact e + · exact absurd h1 (J.vs.not_cnode (Or.inl ⟨p, hp, rfl⟩)) + · exact absurd h1 (J.vs.not_tcb (Or.inl ⟨p, hp, rfl⟩))⟩ + +/-- **`JAtZAX.of_slotV` with the page-table caps closed** (`PtClosedA`): the VSpace contract record is carried. -/ +theorem JAtZAX.of_slot {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L) AR Z s a σ m) (G' : MdbGhostA) + (H : SameNA (L := L) Z s s') (HS : SpecSlotA σ σ') (hst : StateRelA Z.th (L.mem s') σ') + (hcdt : CdtRelA st Z.th s' σ' G') (hcap : ∀ y, IsSlotA Z.th y → CapObjOkA Z (capAtA (L.mem s') y)) + (hpt : PtClosedA Z.th Z.S1 Z.T2 (L.mem s) (L.mem s')) : + JAtZAX (L := L) AR { Z with G := G' } s' a σ' m := + J.of_slotV G' H HS hst hcdt hcap (H.vsu J.1.vsu J.1.ext.xal (J.1.poolSlot HS) hpt) + /-- **`JAtZAX` kept by a state that agrees on the footprint** (module docstring; gen 5: `JAtZAX.of_slot` with the spec and the ghost kept). -/ theorem JAtZAX.of_mem {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L) AR Z s a σ m) (H : SameA (L := L) Z s s') : JAtZAX (L := L) AR Z s' a σ m := - J.of_slot Z.G H.toN (SpecSlotA.refl σ) (J.1.st.of_mem H) (J.1.cdt.of_mem H) fun y hy => by - rw [H.cap (Or.inl hy)]; exact J.capObj hy + J.of_slot Z.G H.toN (SpecSlotA.refl σ) (J.1.st.of_mem H) (J.1.cdt.of_mem H) (fun y hy => by + rw [H.cap (Or.inl hy)]; exact J.capObj hy) (PtClosedA.of_cap fun y hy => Or.inl (H.cap (Or.inl hy))) /-- **`JAtZAX` across a step writing only words off the footprint** (module docstring; A64 P1's `WritesIn`). -/ theorem JAtZAX.of_writesIn {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L) AR Z s a σ m) {W : U64 → Prop} @@ -832,9 +874,21 @@ theorem JAtZAX.of_slotWrites {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX ( {W : U64 → Prop} (hw : WritesIn st s s' W) (hW : ∀ b, W b → ¬ FootNA (L := L) Z s b) (hal : ∀ b, FootNA (L := L) Z s b → Aligned b) (G' : MdbGhostA) (HS : SpecSlotA σ σ') (hst : StateRelA Z.th (L.mem s') σ') (hcdt : CdtRelA st Z.th s' σ' G') - (hcap : ∀ y, IsSlotA Z.th y → CapObjOkA Z (capAtA (L.mem s') y)) : + (hcap : ∀ y, IsSlotA Z.th y → CapObjOkA Z (capAtA (L.mem s') y)) + (hpt : PtClosedA Z.th Z.S1 Z.T2 (L.mem s) (L.mem s')) : + JAtZAX (L := L) AR { Z with G := G' } s' a σ' m := + J.of_slot G' ⟨hw.1, hw.2.1, fun b hb => hw.2.2 b (hal b hb) fun e => hW b e hb⟩ HS hst hcdt hcap hpt + +/-- **`JAtZAX.of_slotWrites` with the VSpace contract record given** (the page-table map's cap write, which is not +`PtClosedA`). -/ +theorem JAtZAX.of_slotWritesV {AR : A → HwRootA → Prop} {a : A} (J : JAtZAX (L := L) AR Z s a σ m) + {W : U64 → Prop} (hw : WritesIn st s s' W) (hW : ∀ b, W b → ¬ FootNA (L := L) Z s b) + (hal : ∀ b, FootNA (L := L) Z s b → Aligned b) (G' : MdbGhostA) (HS : SpecSlotA σ σ') + (hst : StateRelA Z.th (L.mem s') σ') (hcdt : CdtRelA st Z.th s' σ' G') + (hcap : ∀ y, IsSlotA Z.th y → CapObjOkA Z (capAtA (L.mem s') y)) + (hv : VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ') : JAtZAX (L := L) AR { Z with G := G' } s' a σ' m := - J.of_slot G' ⟨hw.1, hw.2.1, fun b hb => hw.2.2 b (hal b hb) fun e => hW b e hb⟩ HS hst hcdt hcap + J.of_slotV G' ⟨hw.1, hw.2.1, fun b hb => hw.2.2 b (hal b hb) fun e => hW b e hb⟩ HS hst hcdt hcap hv end slotw diff --git a/proofs/Fl4ProofsA64/P3/InsBaseA.lean b/proofs/Fl4ProofsA64/P3/InsBaseA.lean index 7a06608ef..d61677f8f 100644 --- a/proofs/Fl4ProofsA64/P3/InsBaseA.lean +++ b/proofs/Fl4ProofsA64/P3/InsBaseA.lean @@ -105,7 +105,8 @@ theorem cap_insert_jBA (B : InsBaseA (L := L) AR Z H OS s a σ m) insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))) = true) (hsib : insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))) = false → ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc Z.G.par y (cslotAddrA ss)) - (hno : CapObjOkA Z nc) : + (hno : CapObjOkA Z nc) (hptn : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) nc) + (hrc : RootCopyA Z.th (L.mem s) nc) : cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) ⦃ s' => ∃ σ', ((), σ') ∈ (Fl4SpecA64.capInsert (Z := Unit) anc ss sd σ).1 ∧ JAtZAX (L := L) AR { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA sd) @@ -134,10 +135,11 @@ theorem cap_insert_jBA (B : InsBaseA (L := L) AR Z H OS s a σ m) (cdt.insert_with_cap.srcF hO (hsub _ hsS) (hsub _ hdS) hsd rfl hw (fun h => inOS _ (F.nxm _ hsG h)))) fun _ ⟨⟨h1, _, h3, _, _, h6, _⟩, h7⟩ => ⟨h1, h1.1, h1.2.1, h3, h7, h6⟩ refine WP.spec_mono (WP.spec_and (cap_insert_refinesA s σ Z.G B.j.1.st B.j.1.cdt hP hO hT hsub hnul - hAs hAd hsn hdn hdc hwf hanc hw hn hal hk hut hub hsib) hwr) ?_ + hAs hAd hsn hdn hdc hwf hanc hw hn (Or.inl hal) hk hut hub hsib) hwr) ?_ rintro s' ⟨⟨σ', hm, hst, hcdt, hT', hSS, hcs⟩, hw', hIS⟩ refine ⟨σ', hm, B.j.of_slotWrites hw' (fun b hb' hb => B.footN b hb hb') - (FootNA.aligned B.j.1 B.nodes B.scAl B.vcAl) _ hSS hst hcdt fun y hy => ?_, hT', + (FootNA.aligned B.j.1 B.nodes B.scAl B.vcAl) _ hSS hst hcdt (fun y hy => ?_) + (PtClosedA.ofTab (PtCapClosedA.of_ins hptn hcs) (TabClosedA.of_copy hcs hrc)), hT', fun hc n hI => SInvXA.capInsert hI hc hm, hSS, hIS, hw'⟩ rcases hcs y hy with e | e | ⟨p, b, i, d, e⟩ <;> rw [e] · exact B.j.capObj hy @@ -165,7 +167,8 @@ theorem cap_insert_dBA (B : InsBaseA (L := L) AR Z H OS s a σ m) absCapA (capA st s (cslotAddrA ss)) = .notificationCap r b rs) → b ≠ 0 → Fl4SpecA64.capEpBadge (absCapA nc) = b) (hdo : ¬ IrqNodeA (L.ksb s) (fl4Ptr sd.1) ∨ IrqCapA (absCapA nc)) - (hcv : CapValidA Z.th (capA st s (cslotAddrA ss)) → CapValidA Z.th nc) : + (hcv : CapValidA Z.th (capA st s (cslotAddrA ss)) → CapValidA Z.th nc) + (hrd : RootDerivA nc (capA st s (cslotAddrA ss))) : cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) ⦃ s' => ∃ σ', ((), σ') ∈ (Fl4SpecA64.capInsert (Z := Unit) anc ss sd σ).1 ∧ JAtZAX (L := L) AR { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA sd) @@ -181,6 +184,7 @@ theorem cap_insert_dBA (B : InsBaseA (L := L) AR Z H OS s a σ m) have hov : NoOvA (capA st s (cslotAddrA ss)) := noOvA_of_wf hcr.1 have hd := derivA_of _ _ (srA_shape hsh hov hcr.1 hsn hz) hbd have hno : CapObjOkA Z nc := (B.j.capObj hsS).of_shapeA hsh hcv + have hptn : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) nc := PtSrcA.of_shape hsS hsh have hoff : NodeOffA (L.ksb s) nc := (NodeOffA.of_ctOff (B.ct _ (hsub _ hsS))).of_shapeA hsh have hokAnc : CapOkA σ.interruptIrqNode sd anc := by @@ -198,7 +202,8 @@ theorem cap_insert_dBA (B : InsBaseA (L := L) AR Z H OS s a σ m) insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))) = true := fun hu => insBA_of_orig (by rw [B.j.1.cdt.orig ss hAs]; exact revA_of_revocableA (B.utRev _ (hsub _ hsS) hu)) hd refine WP.spec_mono (cap_insert_jBA B hT hsub hnul hAs hAd hsn hdn hdc hwf hanc hw hn hal hk hut - hub (hsib_ofA B.j.1.cdt hAs hd) hno) ?_ + hub (hsib_ofA B.j.1.cdt hAs hd) hno hptn + (RootCopyA.of_der hsS (by rw [capAtA_eq (st := st)]; exact hrd))) ?_ rintro s' ⟨σ', hm, hJ, hT', hI, hSS, hIS, hw'⟩ exact ⟨σ', hm, hJ, hT', hI hokAnc, hSS, hIS, hw'⟩ diff --git a/proofs/Fl4ProofsA64/P3/InsDisA.lean b/proofs/Fl4ProofsA64/P3/InsDisA.lean index fb7d37d8f..a054316a8 100644 --- a/proofs/Fl4ProofsA64/P3/InsDisA.lean +++ b/proofs/Fl4ProofsA64/P3/InsDisA.lean @@ -133,7 +133,6 @@ def shapeA : capability.Cap → capability.Cap | .CNode p r _ _ => .CNode p r 0#u64 0#u64 | .SchedControl _ => .SchedControl 0#u64 | .Frame p sz _ _ _ _ _ _ => .Frame p sz 0#u64 false false false 0#u64 0#u64 - | .PageTable p _ _ _ => .PageTable p false 0#u64 0#u64 | .Pml4 p _ _ => .Pml4 p false 0#u64 | .Ept p level _ _ _ => .Ept p level false 0#u64 0#u64 | .HighVSpace p _ _ => .HighVSpace p false 0#u64 @@ -294,6 +293,16 @@ theorem capOk_insA {mem : U64 → U64} {ksb : U64} {σ : State Unit} (hI : IrqRe exact offNode_ofA hI (hno p r gs g' rfl) irq hirq e.1 | _ => simp [absCapA] at e +/-- A cap of the source's shape is a page-table cap only if it is the source (`shapeA` keeps a page-table cap whole). -/ +theorem PtSrcA.of_shape {th : TypedHeapA} {S1 T2 : Set U64} {s : S} {src : U64} {nc : capability.Cap} + (hsS : IsSlotA th src) (hsh : shapeA nc = shapeA (capA st s src)) : PtSrcA th S1 T2 (L.mem s) nc := by + intro ptr asid va mp h + refine Or.inl ⟨src, hsS, ?_⟩ + subst h + rw [capAtA_eq] + generalize capA st s src = c at hsh ⊢ + cases c <;> simp [shapeA] at hsh <;> simp_all + open Classical in /-- **`cap_insert_jA` with its call-site debts discharged** (module docstring; ruling 12:26Z item 2). -/ theorem cap_insert_dA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} @@ -317,7 +326,8 @@ theorem cap_insert_dA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} absCapA (capA st s (cslotAddrA ss)) = .notificationCap r b rs) → b ≠ 0 → Fl4SpecA64.capEpBadge (absCapA nc) = b) (hdo : ¬ IrqNodeA (L.ksb s) (fl4Ptr sd.1) ∨ IrqCapA (absCapA nc)) - (hcv : CapValidA Z.th (capA st s (cslotAddrA ss)) → CapValidA Z.th nc) : + (hcv : CapValidA Z.th (capA st s (cslotAddrA ss)) → CapValidA Z.th nc) + (hrd : RootDerivA nc (capA st s (cslotAddrA ss))) : cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) ⦃ s' => ∃ σ', ((), σ') ∈ (Fl4SpecA64.capInsert (Z := Unit) anc ss sd σ).1 ∧ JAtZAX (L := L) AR { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA sd) @@ -345,7 +355,8 @@ theorem cap_insert_dA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} simp [IrqCapA, absCapA] at hi | _ => rw [← hanc]; exact h0 refine WP.spec_mono (cap_insert_jA E hT hsub hnul hAs hAd hsn hdn hdc hwf hanc hw hn hal hk hut - (hub_ofA E hAs (hsub _ hsS) hd) (hsib_ofA E.j.1.cdt hAs hd) hno) ?_ + (hub_ofA E hAs (hsub _ hsS) hd) (hsib_ofA E.j.1.cdt hAs hd) hno (PtSrcA.of_shape hsS hsh) + (RootCopyA.of_der hsS (by rw [capAtA_eq (st := st)]; exact hrd))) ?_ rintro s' ⟨σ', hm, hJ, hT', hI⟩ exact ⟨σ', hm, hJ, hT', hI hokAnc⟩ diff --git a/proofs/Fl4ProofsA64/P3/InsertA.lean b/proofs/Fl4ProofsA64/P3/InsertA.lean index 2f93c4cd9..a4bcf5442 100644 --- a/proofs/Fl4ProofsA64/P3/InsertA.lean +++ b/proofs/Fl4ProofsA64/P3/InsertA.lean @@ -25,6 +25,7 @@ child and the sibling case** (ruling q3, as x86 `InsertRefine`): the ghost paren Gen 8: CNode or TCB slots (`AbsSlotA`, `StateRelA.setAbsA` / `getAbsA`). Named premise: none (gen 7: `SlotApA` is `JEntA.ap`, no longer a premise; `CdtRelA.prev` kept, gen 7). -/ import Fl4ProofsA64.P3.SwapA +import Fl4ProofsA64.P1.S1aSubTree open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -380,7 +381,7 @@ set_option maxHeartbeats 2000000 in theorem insWC_treeGA (hO : OSOK T Ω Sg OS) {s : S} (hT : TreeA st OS G par s) {src dest : U64} {nc sc : capability.Cap} (hsrc : src ∈ G.flatten) (hd : dest ∈ OS) (hd0 : capA st s dest = .Null) (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hw : CapRt.EncWf nc) (hnc : nc ≠ .Null) - (hA : UA nc sc) (hut : isUtA sc = true → ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc par y src) (bp : Bool) + (hA : UA nc sc ∨ Fl4ProofsA64.P1.W7.R.ST.SubA nc sc) (hut : isUtA sc = true → ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc par y src) (bp : Bool) (hb : isUtA sc = true → bp = true) (hsib : bp = false → ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc par y src) : cdt.insert_with_cap st s nc sc src dest ⦃ s' => TreeA st OS (insG src dest G) (Function.update par dest (if bp then some src else par src)) s' ⦄ := by @@ -414,21 +415,34 @@ theorem insWC_treeGA (hO : OSOK T Ω Sg OS) {s : S} (hT : TreeA st OS G par s) { · rw [(hL _ (inOS _ (hNm hN))).1]; simp [hN] · rw [(hL y hy).2]; simp [h1, h2] · rw [(hL y hy).1]; simp [h1, h2] - have hfib : ∀ p b i e, capA st s src = .Untyped p b i e → i.val ≤ 2 ^ b.val := - fun p b i e h => hT.ut.fib src os p b i e h - have hs : UA (capA st s' src) (capA st s src) := by - rw [hsc]; exact hsu.1.ua fun p b i e h => hfib p b i e (hsc.trans h) - have hdA : UA (capA st s' dest) (capA st s src) := by rw [ed, hsc]; exact hA - refine ⟨hLk, by rw [insG_eq]; exact hT.tree.insert hsrc dG (by cases bp; exacts [Or.inr ⟨rfl, hsib rfl⟩, Or.inl rfl]), ?_⟩ - refine UtInvA.insGenA hT.ut hT.parIn os hd hsd (fun z e => dG (hT.tree.par_mem z dest e).2) ?_ hk hs hdA - (fun p b i e h => ?_) (fun hu => hut (by rw [← hsc]; exact hu)) bp (fun hu => hb (by rw [← hsc]; exact hu)) - · cases e : par dest with + have hdp : ∀ z, par z ≠ some dest := fun z e => dG (hT.tree.par_mem z dest e).2 + have hdn' : par dest = none := by + cases e : par dest with | none => rfl | some q => exact absurd (hT.tree.par_mem dest q e).1 dG - · rw [ed] at h + refine ⟨hLk, by rw [insG_eq]; exact hT.tree.insert hsrc dG (by cases bp; exacts [Or.inr ⟨rfl, hsib rfl⟩, Or.inl rfl]), ?_⟩ + rcases hA with hA | hA + · have hfib : ∀ p b i e, capA st s src = .Untyped p b i e → i.val ≤ 2 ^ b.val := + fun p b i e h => hT.ut.fib src os p b i e h + have hs : UA (capA st s' src) (capA st s src) := by + rw [hsc]; exact hsu.1.ua fun p b i e h => hfib p b i e (hsc.trans h) + have hdA : UA (capA st s' dest) (capA st s src) := by rw [ed, hsc]; exact hA + refine UtInvA.insGenA hT.ut hT.parIn os hd hsd hdp hdn' hk hs hdA + (fun p b i e h => ?_) (fun hu => hut (by rw [← hsc]; exact hu)) bp (fun hu => hb (by rw [← hsc]; exact hu)) + rw [ed] at h obtain ⟨i0, e0, hsc0', -, -⟩ := hA.ut p b i e h obtain ⟨i1, h1, h2⟩ := hsu.2 p b i0 e0 i e hsc0' h exact ⟨i1, e0, h1, h2⟩ + · have hxk : capA st s' src = capA st s src := by + rcases hsu.1 with e | ⟨p, b, j, e0, j1, es, -, -⟩ + · rw [e, hsc] + · have h := hA.cnu + rw [es] at h + simp [isUtA] at h + refine hT.ut.insSubGen hT.parIn os hd hsd hdp hdn' (fun y hy hyd => ?_) (by rw [ed, hsc]; exact hA) bp + by_cases e : y = src + · rw [e]; exact hxk + · exact hk y hy e hyd end gen @@ -698,7 +712,7 @@ theorem cap_insert_refinesA {T Ω Sg OS : Set U64} {th : TypedHeapA} {kb : U64} (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) {nc : capability.Cap} {anc : Fl4SpecA64.Cap} (hwf : CapWfA nc) (hanc : CapEqA nc anc) (hw : CapRt.EncWf nc) (hn : nc ≠ .Null) - (hal : UA nc (capA st s (cslotAddrA ss))) + (hal : UA nc (capA st s (cslotAddrA ss)) ∨ Fl4ProofsA64.P1.W7.R.ST.SubA nc (capA st s (cslotAddrA ss))) (hk : SameBadgeKindA nc (capA st s (cslotAddrA ss))) (hut : isUtA (capA st s (cslotAddrA ss)) = true → ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc G.par y (cslotAddrA ss)) @@ -849,7 +863,8 @@ theorem cap_insert_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))) = true) (hsib : insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))) = false → ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc Z.G.par y (cslotAddrA ss)) - (hno : CapObjOkA Z nc) : + (hno : CapObjOkA Z nc) (hptn : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) nc) + (hrc : RootCopyA Z.th (L.mem s) nc) : cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) ⦃ s' => ∃ σ', ((), σ') ∈ (Fl4SpecA64.capInsert (Z := Unit) anc ss sd σ).1 ∧ JAtZAX (L := L) AR { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA sd) @@ -874,10 +889,11 @@ theorem cap_insert_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} exact WP.spec_mono (cdt.insert_with_cap.lrF (osokA hO) (LR.self s) (hsub _ hsS) (hsub _ hdS) hsd hdc rfl hsn hw (fun h => inOS _ (F.nxm _ hsG h))) fun _ h => h.1 refine WP.spec_mono (WP.spec_and (cap_insert_refinesA s σ Z.G E.j.1.st E.j.1.cdt hP hO hT hsub hnul - hAs hAd hsn hdn hdc hwf hanc hw hn hal hk hut hub hsib) hwr) ?_ + hAs hAd hsn hdn hdc hwf hanc hw hn (Or.inl hal) hk hut hub hsib) hwr) ?_ rintro s' ⟨⟨σ', hm, hst, hcdt, hT', hSS, hcs⟩, hw'⟩ refine ⟨σ', hm, E.j.of_slotWrites hw' (fun b hb' hb => footN_offA E b hb hb') - (FootNA.aligned E.j.1 (bxi_nodes E.sys.ent.bxi) E.scAl E.ap.vcAl) _ hSS hst hcdt fun y hy => ?_, hT', + (FootNA.aligned E.j.1 (bxi_nodes E.sys.ent.bxi) E.scAl E.ap.vcAl) _ hSS hst hcdt (fun y hy => ?_) + (PtClosedA.ofTab (PtCapClosedA.of_ins hptn hcs) (TabClosedA.of_copy hcs hrc)), hT', fun hc n hI => SInvXA.capInsert hI hc hm⟩ rcases hcs y hy with e | e | ⟨p, b, i, d, e⟩ <;> rw [e] · exact E.j.capObj hy diff --git a/proofs/Fl4ProofsA64/P3/IpcExtraCapInsertDischA.lean b/proofs/Fl4ProofsA64/P3/IpcExtraCapInsertDischA.lean index 0e14a7607..d74572e10 100644 --- a/proofs/Fl4ProofsA64/P3/IpcExtraCapInsertDischA.lean +++ b/proofs/Fl4ProofsA64/P3/IpcExtraCapInsertDischA.lean @@ -36,12 +36,13 @@ theorem ipcExtraCapInsertA_of_jEntA {AR : A → HwRootA → Prop} {Z : XSetsA} { insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))) = true) (hsib : insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))) = false → ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc Z.G.par y (cslotAddrA ss)) - (hno : CapObjOkA Z nc) : + (hno : CapObjOkA Z nc) (hptn : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) nc) + (hrc : RootCopyA Z.th (L.mem s) nc) : IpcExtraCapInsertA st AR Z m a s σ ss sd nc (fun G' s' σ' => TreeA st OS G'.chains G'.par s' ∧ (CapOkA σ.interruptIrqNode sd (absCapA nc) → ∀ n, SInvXA σ m n → SInvXA σ' m n)) := by refine WP.spec_mono (cap_insert_jA E hT hsub hnul hAs hAd hsn hdn hdc hwf (CapEqA.of_abs rfl) hw hn hal hk - hut hub hsib hno) ?_ + hut hub hsib hno hptn hrc) ?_ rintro s' ⟨σ', hmem, hJ, hT', hS⟩ exact ⟨σ', _, hmem, hJ, hT', hS⟩ diff --git a/proofs/Fl4ProofsA64/P3/IpcXferLoopA.lean b/proofs/Fl4ProofsA64/P3/IpcXferLoopA.lean index ced67a572..47f549f51 100644 --- a/proofs/Fl4ProofsA64/P3/IpcXferLoopA.lean +++ b/proofs/Fl4ProofsA64/P3/IpcXferLoopA.lean @@ -354,6 +354,10 @@ theorem transfer_caps_loop_relA {s0 : S} {a : A} {σ0 : State Unit} {m : McState | error _ => exact hrel.elim | ok an => obtain ⟨hwf, hanc, hw, hcv, hkd, hsh⟩ := hrel + have hrd : RootDerivA nc c := by + have w := objects.derive_cap.rt (st := st) s1 (cslotAddrA (caps[j.val]).2) c + rw [hr, WP.spec_ok] at w + exact RootDerivA.of_p1 (w nc rfl) try dsimp only by_cases hn : nc = .Null · subst hn @@ -409,7 +413,7 @@ theorem transfer_caps_loop_relA {s0 : S} {a : A} {σ0 : State Unit} {m : McState rw [hOK.capA hy]; exact hnul y hy hn' obtain ⟨s2, hs2, σ2, hm, J2, T2, SI2, HS2, ⟨hk2, hc2, hnew, hfull, hoth⟩, hWi⟩ := spec_existsA (cap_insert_dBA B1 T1 hsub hnul1 hAs hAd hsn1 hdn1 (B0.can _ hdO) hwf - hanc hw hn hal hkd hut hsh' hz hbd hdo (hcv Z.th)) + hanc hw hn hal hkd hut hsh' hz hbd hdo (hcv Z.th) hrd) rw [hs2, bind_ok, hj', bind_ok, WP.spec_ok] refine ⟨⟨by first | omega | (dsimp only; omega) | (simp only []; omega), σ2, _, mi1, [], hQ.insert _ _ _ _ hq hWi HS2 (capInsert_msA _ _ _ _ _ hm), hu8, hlb, fun r hr => R r ?_, hl, hla, hcu, J2, T2, diff --git a/proofs/Fl4ProofsA64/P3/IrqDeleteEntryFrameA.lean b/proofs/Fl4ProofsA64/P3/IrqDeleteEntryFrameA.lean index bbed88f1e..3e24e698a 100644 --- a/proofs/Fl4ProofsA64/P3/IrqDeleteEntryFrameA.lean +++ b/proofs/Fl4ProofsA64/P3/IrqDeleteEntryFrameA.lean @@ -97,7 +97,7 @@ theorem irqDeleteNotification_entryA {AR : A → HwRootA → Prop} {Z : XSetsA} (∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s1 y = .Null) ∧ capAtA (L.mem s1) (cslotAddrA sl) ≠ .Null have hfin := ntfnFinality_of_slotHeapA cov E.j.1.st E.j.1.place tree.lk ranges kind E.sys.ent.os.nz - slots nullOutside E.sys.sysl.sys.fr ht ntfn cap deviceFrames + slots nullOutside E.sys.sysl.sys.fr E.sys.ent.heap ht ntfn cap deviceFrames have hf : objects.finalise_cap_object st ar s a c fin ⦃ r => ∃ σ1, ((), σ1) ∈ (fastFinalise (Z := Unit) (absCapA c) fin σ).1 ∧ Mid r.2.1 r.2.2 σ1 ⦄ := by by_cases h : isFinalCap' (absCapA c) σ diff --git a/proofs/Fl4ProofsA64/P3/IrqFinalCoverageA.lean b/proofs/Fl4ProofsA64/P3/IrqFinalCoverageA.lean index 1cf85d895..eb0895d8f 100644 --- a/proofs/Fl4ProofsA64/P3/IrqFinalCoverageA.lean +++ b/proofs/Fl4ProofsA64/P3/IrqFinalCoverageA.lean @@ -88,7 +88,7 @@ theorem ntfnFinality_of_slotHeapA {s : S} {σ : State Unit} {th : TypedHeapA} {H (links : MdbLk st OS chains s) (ranges : RngOneA64 st chains s) (kind : KindA st OS s) (nonzero : ∀ y ∈ OS, y ≠ 0#u64) (slots : ∀ y, IsSlotA th y → y ∈ OS) (nullOutside : ∀ y ∈ OS, ¬ IsSlotA th y → capA st s y = .Null) - (frames : FrameOK st H OS s) {sl : CslotPtr} (hsl : AbsSlotA th sl) + (frames : FrameOK st H OS s) (hH : HeapOK H) {sl : CslotPtr} (hsl : AbsSlotA th sl) {p b : U64} {send recv : Bool} (ntfn : H p = some .ntfn) (cap : capAtA (L.mem s) (cslotAddrA sl) = .Notification p b send recv) (deviceFrames : DevFrDisjA st H OS s σ) : @@ -108,9 +108,12 @@ theorem ntfnFinality_of_slotHeapA {s : S} {σ : State Unit} {th : TypedHeapA} {H cases dev · obtain ⟨bits, hbits⟩ : ∃ bits, size.bits = ok bits := by cases size <;> exact ⟨_, rfl⟩ - have hFrameType := frames y hy p size rights mapped ept asid va hcap bits hbits - rw [ntfn] at hFrameType - cases hFrameType + have hq := frames y hy p size rights mapped ept asid va hcap bits hbits + have hd := hq.disjK hH ntfn (fun z => by simp) + have h1 : 1 ≤ 2 ^ bits.val := Nat.one_le_two_pow + have h2 : 1 ≤ 2 ^ HKind.ntfn.bits := Nat.one_le_two_pow + exfalso + omega · obtain ⟨⟨bits, htype⟩, _⟩ := deviceFrames y hy p size rights mapped ept asid va hcap .ntfn ntfn cases htype diff --git a/proofs/Fl4ProofsA64/P3/IrqInvokeGhostA.lean b/proofs/Fl4ProofsA64/P3/IrqInvokeGhostA.lean index a22b3d5b9..d9edb76ce 100644 --- a/proofs/Fl4ProofsA64/P3/IrqInvokeGhostA.lean +++ b/proofs/Fl4ProofsA64/P3/IrqInvokeGhostA.lean @@ -58,6 +58,9 @@ theorem irqInsertNotification_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : (by rw [hc]; exact UA.refl c) (by rw [hc]; trivial) (by rw [hc]; simp [isUtA]) (by rw [hc]) (by rw [hc]; simp) hbadge (Or.inr hnode) (by rw [hc]; exact id) + (RootDerivA.of_no (fun r h => by + rcases h with ⟨_, _, e⟩ | ⟨_, _, _, e⟩ | ⟨_, _, e⟩ <;> simp [c] at e) + (fun r h => by rcases h with ⟨_, _, _, e⟩; simp [c] at e)) rw [hc] at hcall exact hcall diff --git a/proofs/Fl4ProofsA64/P3/IrqInvokeSlotsA.lean b/proofs/Fl4ProofsA64/P3/IrqInvokeSlotsA.lean index 93f5859b4..20a8232b0 100644 --- a/proofs/Fl4ProofsA64/P3/IrqInvokeSlotsA.lean +++ b/proofs/Fl4ProofsA64/P3/IrqInvokeSlotsA.lean @@ -96,6 +96,10 @@ theorem irqInsertHandler_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap (show UA (.IrqHandler irq) (capA st s (cslotAddrA src)) by rw [hc]; exact handlerFromControlA irq) (by rw [hc]; trivial) (by rw [hc]; simp [isUtA]) (by rw [hc]; simp [isUtA]) (by rw [hc]; exact hsib_ofA E.j.1.cdt hs hpar) hn + (PtSrcA.nopt fun _ _ _ _ h => by cases h) + (RootCopyA.of_no (fun r h => by + rcases h with ⟨_, _, e⟩ | ⟨_, _, _, e⟩ | ⟨_, _, e⟩ <;> cases e) + (fun r h => by rcases h with ⟨_, _, _, e⟩; cases e)) refine WP.spec_mono hcall ?_ rintro s' ⟨σ', hm, HJ, HT, HI⟩ rw [hc] at HJ HT diff --git a/proofs/Fl4ProofsA64/P3/JBootA.lean b/proofs/Fl4ProofsA64/P3/JBootA.lean index 2ba54df94..93d74e696 100644 --- a/proofs/Fl4ProofsA64/P3/JBootA.lean +++ b/proofs/Fl4ProofsA64/P3/JBootA.lean @@ -762,6 +762,8 @@ theorem boot_jAtZA (AR : A → HwRootA → Prop) {a : A} (hL : BootLayA ib nc) pml y hy _ _ _ e := by rw [boot_null hL hW hy] at e; cases e vs := by rw [hW.ksb]; exact boot_vsRelA_of (fun hi hh => hW.asid hi hh) _ ext := ExtVsRelA.empty _ _ _ _ _ + vsu := VsUniqA.ofNoPt (fun y hy ptr asid va mp e => by rw [boot_null hL hW hy] at e; cases e) + (fun y hy r h => by rw [boot_null hL hW hy] at h; exact NoRootKindA.null r h.kind) VsForestA.empty /-- **The extension records at boot** (no VCPU, Stage-2 root or high window; every slot null). -/ theorem boot_ext (hL : BootLayA ib nc) (hW : BootWordsA st s kb ib now nc) : diff --git a/proofs/Fl4ProofsA64/P3/JEntW1A.lean b/proofs/Fl4ProofsA64/P3/JEntW1A.lean index 335edfa85..513e7a19b 100644 --- a/proofs/Fl4ProofsA64/P3/JEntW1A.lean +++ b/proofs/Fl4ProofsA64/P3/JEntW1A.lean @@ -26,6 +26,7 @@ import Fl4ProofsA64.P3.JBootW1SA import Fl4ProofsA64.P3.BootAddrA import Fl4ProofsA64.P3.JEntW0A import Fl4ProofsA64.P2.BootSysA +import Fl4ProofsA64.P3.VsW1A open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -297,6 +298,13 @@ theorem w1_pmlA (y : U64) (hy : IsSlotA (w1ThA kb ib nc) y) (p : U64) (mp : Bool rw [vVS] decide +include hL hK P in +include hL hK P in +/-- **`VsUniqA` at `w1`** (`P3/VsW1A`). -/ +theorem w1_vsuA : VsUniqA (w1ZA kb ib nc).th (w1ZA kb ib nc).Pp (w1ZA kb ib nc).S1 (w1ZA kb ib nc).X + (w1ZA kb ib nc).Y (w1ZA kb ib nc).T2 (w1ZA kb ib nc).Sh2 (bL.mem S1) (bL.ksb S1) (w1SA kb ib nc now mt sl) := + w1_vsuA_of hL hK P _ _ + include hL hK P hW in /-- **`JAtZA` at `w1`** (module docstring). -/ theorem w1_jAtZA {A : Type} (AR : A → HwRootA → Prop) {a : A} (hAR : AR a bootHwA) : @@ -359,6 +367,7 @@ theorem w1_jAtZA {A : Type} (AR : A → HwRootA → Prop) {a : A} (hAR : AR a bo pml := w1_pmlA hL hK P vs := w1_vsRelA P ext := ExtVsRelA.empty _ _ _ _ _ + vsu := w1_vsuA hL hK P /-! ## The extension records at `w1` -/ diff --git a/proofs/Fl4ProofsA64/P3/JointA.lean b/proofs/Fl4ProofsA64/P3/JointA.lean index 215e1ff3d..66566f9c8 100644 --- a/proofs/Fl4ProofsA64/P3/JointA.lean +++ b/proofs/Fl4ProofsA64/P3/JointA.lean @@ -86,6 +86,7 @@ changed. import Fl4ProofsA64.P3.StateRelA import Fl4ProofsA64.P3.VsRelA import Fl4ProofsA64.P3.ExtVsDefA +import Fl4ProofsA64.P3.VsUniqA import Fl4ProofsA64.P1.QueueSchedStep import Fl4ProofsA64.P1.QueueSchedInv import Fl4ProofsA64.P1.QueueCancel @@ -376,6 +377,9 @@ structure JAtZA (AR : A → HwRootA → Prop) (Z : XSetsA) (s : S) (a : A) spec's `stage2Root` objects and normal `PageTable`s. The address half of the integration (`VaOkE` for every mapped plain frame cap) is `cv` (`CapValidA`'s frame arm). -/ ext : ExtVsRelA Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s) σ + /-- (Stage 5, `vsinv`) **The VSpace contract record** (`P3/VsUniqA`): a mapped page-table cap's reachable table + references are on its walk (Stage-2 and Stage-1 / window tables), an unmapped one names an untracked table. -/ + vsu : VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s) (L.ksb s) σ /-! ## The extension records -/ diff --git a/proofs/Fl4ProofsA64/P3/MachKeepA.lean b/proofs/Fl4ProofsA64/P3/MachKeepA.lean index 9ae25063b..b7aabd74d 100644 --- a/proofs/Fl4ProofsA64/P3/MachKeepA.lean +++ b/proofs/Fl4ProofsA64/P3/MachKeepA.lean @@ -99,7 +99,7 @@ theorem JStage3A.arSwapA have x : JAtZA (L := L) AR' Z s a σ m := { st := j.st, cdt := j.cdt, sch := j.sch, ar := h, place := j.place, irq := j.irq, rest := j.rest thT := j.thT, csN := j.csN, idleT := j.idleT, idleC := j.idleC, curT := j.curT, cscC := j.cscC - ksFit := j.ksFit, scOffD := j.scOffD, cv := j.cv, pml := j.pml, vs := j.vs, ext := j.ext } + ksFit := j.ksFit, scOffD := j.scOffD, cv := j.cv, pml := j.pml, vs := j.vs, ext := j.ext, vsu := j.vsu } exact { J with j := ⟨x, J.j.2⟩ } /-- **The record at another arch state** that the arch relation holds of. -/ @@ -111,7 +111,7 @@ theorem JStage3A.arStateA {a' : A} have x : JAtZA (L := L) AR Z s a' σ m := { st := j.st, cdt := j.cdt, sch := j.sch, ar := h, place := j.place, irq := j.irq, rest := j.rest thT := j.thT, csN := j.csN, idleT := j.idleT, idleC := j.idleC, curT := j.curT, cscC := j.cscC - ksFit := j.ksFit, scOffD := j.scOffD, cv := j.cv, pml := j.pml, vs := j.vs, ext := j.ext } + ksFit := j.ksFit, scOffD := j.scOffD, cv := j.cv, pml := j.pml, vs := j.vs, ext := j.ext, vsu := j.vsu } exact { J with j := ⟨x, J.j.2⟩ } end diff --git a/proofs/Fl4ProofsA64/P3/MoveA.lean b/proofs/Fl4ProofsA64/P3/MoveA.lean index 4375c7a97..7ee91db9f 100644 --- a/proofs/Fl4ProofsA64/P3/MoveA.lean +++ b/proofs/Fl4ProofsA64/P3/MoveA.lean @@ -513,7 +513,8 @@ theorem cap_move_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (hdn : capAtA (L.mem s) (cslotAddrA sd) = .Null) (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) {nc : capability.Cap} {ac : Cap} (hca : CapRelA nc ac) (hw : CapRt.EncWf nc) (hn : nc ≠ .Null) - (hal : UA nc (capA st s (cslotAddrA ss))) (hno : CapObjOkA Z nc) : + (hal : UA nc (capA st s (cslotAddrA ss))) (hno : CapObjOkA Z nc) + (hptn : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) nc) (hrn : RootMvA nc (capA st s (cslotAddrA ss))) : cdt.move_cap st s nc (cslotAddrA ss) (cslotAddrA sd) ⦃ s' => ∃ σ', ((), σ') ∈ (capMove (Z := Unit) ac ss sd σ).1 ∧ JAtZAX (L := L) AR { Z with G := mvGA Z.G (cslotAddrA ss) (cslotAddrA sd) } s' a σ' m ∧ @@ -525,12 +526,23 @@ theorem cap_move_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} have F := hT.lk.lkF hO.nz have inOS : ∀ y ∈ Z.G.chains.flatten, y ∈ OS := fun y hy => ((hT.lk.members y).1 hy).1 have hdS : IsSlotA Z.th (cslotAddrA sd) := AbsSlotA.isSlot E.j.1.place hAd - refine WP.spec_mono (WP.spec_and (cap_move_refinesA s σ Z.G E.j.1.st E.j.1.cdt E.j.1.place hO hT hsub hnul + have hsd : cslotAddrA ss ≠ cslotAddrA sd := fun e => hsn (e ▸ hdn) + have hpP : L.mem s (wa (cslotAddrA ss) 16#u64) ≠ 0#u64 → L.mem s (wa (cslotAddrA ss) 16#u64) ∈ OS := + fun h => inOS _ (F.pvm _ hsG h) + have hnN : NxA st s (cslotAddrA ss) ≠ 0#u64 → NxA st s (cslotAddrA ss) ∈ OS := fun h => inOS _ (F.nxm _ hsG h) + refine WP.spec_mono (WP.spec_and (WP.spec_and (cap_move_refinesA s σ Z.G E.j.1.st E.j.1.cdt E.j.1.place hO hT hsub hnul hAs hAd hsn hdn hdc hca hw hn hal) (moveCap_osA hO (hsub _ hsS) (hsub _ hdS) - (fun h => inOS _ (F.pvm _ hsG h)) (fun h => inOS _ (F.nxm _ hsG h)))) ?_ - rintro s' ⟨⟨σ', hm, hst, hcdt, hT', hSS, hcs⟩, hw'⟩ + (fun h => inOS _ (F.pvm _ hsG h)) (fun h => inOS _ (F.nxm _ hsG h)))) + (cdt.move_cap.lrF (⟨fun _ hx => osw hO hx, hO.fit, hO.disj, hO.nz⟩ : OSOK _ {b | InOS OS b} ∅ OS) (LR.self s) (hsub _ hsS) (hsub _ hdS) hsd hdc hw hpP hnN)) ?_ + rintro s' ⟨⟨⟨σ', hm, hst, hcdt, hT', hSS, hcs⟩, hw'⟩, -, -, ed, es, ek⟩ refine ⟨σ', hm, E.j.of_slotWrites hw' (fun b hb' hb => footN_offA E b hb hb') - (FootNA.aligned E.j.1 (bxi_nodes E.sys.ent.bxi) E.scAl E.ap.vcAl) _ hSS hst hcdt fun y hy => ?_, hT'⟩ + (FootNA.aligned E.j.1 (bxi_nodes E.sys.ent.bxi) E.scAl E.ap.vcAl) _ hSS hst hcdt (fun y hy => ?_) + (PtClosedA.ofTab (PtCapClosedA.of_three hptn hcs) + (TabClosedA.of_mv (ss := cslotAddrA ss) (sd := cslotAddrA sd) (nc := nc) (by rw [capAtA_eq (st := st)]; exact es) + (by rw [capAtA_eq (st := st)]; exact ed) hsS + (fun y hy e1 e2 => by + rw [capAtA_eq (st := st), capAtA_eq (st := st)]; exact ek y (hsub y hy) e1 e2) + (by rw [capAtA_eq (st := st)]; exact hrn))), hT'⟩ rcases hcs y hy with e | e | e <;> rw [e] · exact CapObjOkA.null Z · exact E.j.capObj hy diff --git a/proofs/Fl4ProofsA64/P3/RestartA.lean b/proofs/Fl4ProofsA64/P3/RestartA.lean index 7edd35c9f..02ba9850d 100644 --- a/proofs/Fl4ProofsA64/P3/RestartA.lean +++ b/proofs/Fl4ProofsA64/P3/RestartA.lean @@ -432,7 +432,16 @@ theorem JAtZAX.of_stA {t : U64} (J : JAtZAX (L := L) AR Z s a σ m) (O : StOffA · rcases hq with hq | hq · exact absurd (by rw [ep]; exact hk) (J.vs.not_tcb (Or.inl ⟨q, hq, rfl⟩)) · exact absurd (by rw [ep]; exact hk) (J.ext.not_tcb hq x) - · simp [σ1, setObjA, Function.update_of_ne ep] } + · simp [σ1, setObjA, Function.update_of_ne ep] + vsu := J.vsuOf kb (fun b hb => by + rcases hb with hb | hb + · exact hm b (.nslot _ (.ext b hb)) (O.ext b hb) + · exact hm b (.nslot _ (.vs b hb)) (O.vs b hb)) + ⟨rfl, fun p hp => by + by_cases ep : specPtr p = specPtr t + · exact absurd (by rw [ep]; exact hk) (J.vs.not_tcb (Or.inl ⟨p, hp, rfl⟩)) + · simp [σ1, setObjA, Function.update_of_ne ep]⟩ + (PtClosedA.of_cap fun y hy => Or.inl (hcap y (Or.inl hy))) } have hVw : ∀ w ∈ Z.V, L.mem s2 w = L.mem s w ∧ L.mem s2 (wa w 24#u64) = L.mem s (wa w 24#u64) := fun w hw => ⟨hm _ (.nslot _ (.vcpu _ _ hw (Or.inl rfl))) (O.vc w hw).1, hm _ (.nslot _ (.vcpu _ _ hw (Or.inr rfl))) (O.vc w hw).2⟩ diff --git a/proofs/Fl4ProofsA64/P3/SetCapJA.lean b/proofs/Fl4ProofsA64/P3/SetCapJA.lean index f91df605d..1f605d556 100644 --- a/proofs/Fl4ProofsA64/P3/SetCapJA.lean +++ b/proofs/Fl4ProofsA64/P3/SetCapJA.lean @@ -32,8 +32,8 @@ variable {AR : A → HwRootA → Prop} {Z : XSetsA} {s : S} {a : A} {σ : Fl4Spe {m : Fl4SpecA64.McState} set_option maxHeartbeats 2000000 in -/-- **`JAtZAX` across an in-place cap write** (module docstring). -/ -theorem JAtZAX.of_setcapA (J : JAtZAX (L := L) AR Z s a σ m) {T Ω Sg OS : Set U64} (hO : OSOK T Ω Sg OS) +/-- **`JAtZAX` across an in-place cap write**, the relation under `P` (the cap source may need `P`) (module docstring). -/ +theorem JAtZAX.of_setcapCondA (J : JAtZAX (L := L) AR Z s a σ m) {T Ω Sg OS : Set U64} (hO : OSOK T Ω Sg OS) (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) (hoff : ∀ b, FootNA (L := L) Z s b → ¬ W7.CapW T {b | InOS OS b} ∅ b) (hal : ∀ b, FootNA (L := L) Z s b → Aligned b) @@ -41,11 +41,13 @@ theorem JAtZAX.of_setcapA (J : JAtZAX (L := L) AR Z s a σ m) {T Ω Sg OS : Set (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) (hT : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) (hcn : c ≠ .Null) (hc0 : capA st s (cslotAddrA cte) ≠ .Null) (hua : UA c (capA st s (cslotAddrA cte))) - (hok : CapObjOkA Z c) : + (hok : CapObjOkA Z c) {P : Prop} (hptc : P → PtSrcA Z.th Z.S1 Z.T2 (L.mem s) c) + (hrt : RootSetA (capAtA (L.mem s) (cslotAddrA cte)) c := by root_nr) + (hpt : PtSetE Z.th (L.mem s) (cslotAddrA cte) c := by pt_nr) : ∃ s2 σ2, obj.Slot.set_cap st (cslotAddrA cte) s c = ok s2 ∧ ((), σ2) ∈ (Fl4SpecA64.setCap (Z := Unit) sc cte σ).1 ∧ SpecSlotA σ σ2 ∧ WritesIn st s s2 (W7.CapW T {b | InOS OS b} ∅) ∧ - JAtZAX (L := L) AR Z s2 a σ2 m ∧ TreeA st OS Z.G.chains Z.G.par s2 := by + (P → JAtZAX (L := L) AR Z s2 a σ2 m) ∧ TreeA st OS Z.G.chains Z.G.par s2 ∧ StateRelA Z.th (L.mem s2) σ2 := by have hP1 := J.1.place have hcs : IsSlotA Z.th (cslotAddrA cte) := hab.isSlot hP1 have hos := hsub _ hcs @@ -80,11 +82,33 @@ theorem JAtZAX.of_setcapA (J : JAtZAX (L := L) AR Z s a σ m) {T Ω Sg OS : Set (fun sl hsl => by rw [← hs2, revA_wr2A hO hos (hsub _ (hsl.isSlot hP1))]; exact C1.orig sl hsl) C1.par_slot C1.po refine ⟨s2, _, by rw [← hs2]; exact set_cap_eq hen, hσ2, HS, hw2, - J.of_slotWrites hw2 (fun b hb hf => hoff b hf hb) hal Z.G HS hSR hC fun y hy => ?_, hT2⟩ + fun hP => J.of_slotWrites hw2 (fun b hb hf => hoff b hf hb) hal Z.G HS hSR hC (fun y hy => ?_) + (PtClosedA.of_set (hptc hP) hcx hcapo hrt hpt), hT2, hSR⟩ by_cases hne : y = cslotAddrA cte · subst hne; rw [hcx]; exact hok · rw [hcapo y hy hne]; exact J.capObj hy +set_option maxHeartbeats 2000000 in +/-- **`JAtZAX` across an in-place cap write** (module docstring). -/ +theorem JAtZAX.of_setcapA (J : JAtZAX (L := L) AR Z s a σ m) {T Ω Sg OS : Set U64} (hO : OSOK T Ω Sg OS) + (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) + (hoff : ∀ b, FootNA (L := L) Z s b → ¬ W7.CapW T {b | InOS OS b} ∅ b) + (hal : ∀ b, FootNA (L := L) Z s b → Aligned b) + (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) {c : capability.Cap} {sc : Fl4SpecA64.Cap} + (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) + (hT : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) + (hcn : c ≠ .Null) (hc0 : capA st s (cslotAddrA cte) ≠ .Null) (hua : UA c (capA st s (cslotAddrA cte))) + (hok : CapObjOkA Z c) (hptc : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) c) + (hrt : RootSetA (capAtA (L.mem s) (cslotAddrA cte)) c := by root_nr) + (hpt : PtSetE Z.th (L.mem s) (cslotAddrA cte) c := by pt_nr) : + ∃ s2 σ2, obj.Slot.set_cap st (cslotAddrA cte) s c = ok s2 ∧ + ((), σ2) ∈ (Fl4SpecA64.setCap (Z := Unit) sc cte σ).1 ∧ SpecSlotA σ σ2 ∧ + WritesIn st s s2 (W7.CapW T {b | InOS OS b} ∅) ∧ + JAtZAX (L := L) AR Z s2 a σ2 m ∧ TreeA st OS Z.G.chains Z.G.par s2 := by + obtain ⟨s2, σ2, h1, h2, h3, h4, h5, h6, -⟩ := + J.of_setcapCondA hO hsub hoff hal cte hab hEnc hca hT hnul hcn hc0 hua hok (P := True) (fun _ => hptc) hrt hpt + exact ⟨s2, σ2, h1, h2, h3, h4, h5 trivial, h6⟩ + /-- The slot facts carried to a state with the same `ksb` / `cpu`. -/ theorem footNOff_ksA {T OS : Set U64} {s' : S} (hks : L.ksb s' = L.ksb s) (hcpu : L.cpu s' = L.cpu s) (h : ∀ b, FootNA (L := L) Z s b → ¬ W7.CapW T {b | InOS OS b} ∅ b) : diff --git a/proofs/Fl4ProofsA64/P3/SlotJA.lean b/proofs/Fl4ProofsA64/P3/SlotJA.lean index 4ffb6672e..93d922736 100644 --- a/proofs/Fl4ProofsA64/P3/SlotJA.lean +++ b/proofs/Fl4ProofsA64/P3/SlotJA.lean @@ -224,10 +224,14 @@ theorem empty_slot_jA {AR : A → HwRootA → Prop} {ar : machine.Arch A} {Z : X (fun h => inOS _ (F.nxm _ hxG h)))) ?_ rintro q ⟨⟨har, σ', hm, hst, hcdt, hT', hRO', hK', hSS, hcs⟩, hw⟩ refine ⟨har, σ', hm, E.j.of_slotWrites hw (fun b hw hb => footN_offA E b hb hw) - (FootNA.aligned E.j.1 (bxi_nodes E.sys.ent.bxi) E.scAl E.ap.vcAl) _ hSS hst hcdt fun y hy => ?_, hT', hRO', hK'⟩ - rcases hcs y hy with e | e <;> rw [e] - · exact CapObjOkA.null Z - · exact E.j.capObj hy + (FootNA.aligned E.j.1 (bxi_nodes E.sys.ent.bxi) E.scAl E.ap.vcAl) _ hSS hst hcdt (fun y hy => ?_) + (PtClosedA.of_cap fun y hy => ?_), hT', hRO', hK'⟩ + · rcases hcs y hy with e | e <;> rw [e] + · exact CapObjOkA.null Z + · exact E.j.capObj hy + · rcases hcs y hy with e | e + · exact Or.inr (by rw [e]; exact NoVsCapA.null) + · exact Or.inl e end diff --git a/proofs/Fl4ProofsA64/P3/Stage3A.lean b/proofs/Fl4ProofsA64/P3/Stage3A.lean index ee9c2ef7d..8221186f4 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3A.lean @@ -485,7 +485,7 @@ structure JStage3A (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U A /-- [J] (record edit #6, G3) No `OS` slot covers a VCPU word (A64 P1's `VcOK.os`). -/ vcOS : ∀ b, VcW Z.V b → ¬ InOS OS b /-- [J] (record edit #6, item 12) Non-device frame caps name spec data pages (`UserFrSpecA`). -/ - userFr : UserFrSpecA st OS s σ + userFr : UserFrSpecA st H OS s σ /-- [J] (record edit #6, item 13) A tracked buffer's spec name is its FL4 address's. -/ bfSpec : ∀ bp ∈ Bf, bp.2 = specPtr bp.1 /-- [J] (record edit #7) No VCPU is loaded in the spec's `arm_current_vcpu` (FL4 switches VCPU registers lazily). -/ diff --git a/proofs/Fl4ProofsA64/P3/Stage3AfterPreemptA.lean b/proofs/Fl4ProofsA64/P3/Stage3AfterPreemptA.lean index 9a4f4a73f..ba7243acb 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3AfterPreemptA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3AfterPreemptA.lean @@ -1,7 +1,7 @@ /- P3 (aarch64, A64-P3 Stage-3 integration, G3): **`after_invocation` of a preempted invocation** (`afterPreemptA`): the body of the callers' plug-in `hPre` (`sendBodyScopeA`, `cnodeCopyBodyA`, `VsBodyA`, `sendBodyErrA`), from -`A64RelPS3` and `PreExitA`: `check_budget` for a schedulable current thread, else `charge_budget … false` for an active +`A64RelPS3fx` (the record at a fixed view; `P3/Stage3HPreA` opens `A64RelPS3`) and `PreExitA`: `check_budget` for a schedulable current thread, else `charge_budget … false` for an active current SC, else the clear of the consumed time, then the pending interrupt. * `SendPA`: the timeout-fault plug-in without a waiting receiver, free of the scheduler action. @@ -123,7 +123,7 @@ theorem afterPreemptA {Cs : Set U64} {Clock : A → MachineState → Prop} {poll (hSend : ∀ (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), Z.Cs = Cs → SendPA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s a σ) - (hRel : A64RelPS3 st AR ar nA n Cs s a σ m) (hPre : PreExitA σ) + (hRel : A64RelPS3fx st AR ar nA n Cs s a σ m) (hPre : PreExitA σ) (line : ∀ (r : S × A) (τ : State Unit) (irq : U64) (a' : A) (τ' : State Unit), syscall.mcs_preemption_point st ar s a = ok r → A64RelS3 st AR ar nA n Cs r.1 r.2 τ m → ar.take_pending_irq r.2 = ok (irq, a') → irq ≠ syscall.NO_IRQ → (some irq.bv, τ') ∈ (poll τ).1 → diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmAssignA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmAssignA.lean index c582ee093..382e66b01 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmAssignA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmAssignA.lean @@ -272,7 +272,7 @@ theorem JStage3A.asidAssignA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea have hn0 : assignUnmappedA k root oldAsid oldVa ≠ .Null := by cases k <;> intro h <;> cases h -- restart and the cap write obtain ⟨x, s2, σ2, hkx, hrestart, hrestartS, hs, hsS, Hs, hks, R, hcpu2, hw2, -, -⟩ := - restart_setcapJA E0 RS dst hd hx hEnc hrel + restart_setcapJA E0 RS dst hd hx hEnc hrel (by rw [show capAtA (L.mem s) (cslotAddrA dst) = assignUnmappedA k root oldAsid oldVa from hcap]; exact RootSetA.assign k root oldAsid oldVa _) (by cases k <;> pt_nr) obtain ⟨x', hkx', 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 exx : x' = x := by rw [hkx] at hkx'; cases hkx'; rfl @@ -412,14 +412,17 @@ 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) + (hrt := by rw [show capAtA (L.mem s1) (cslotAddrA dst) = assignUnmappedA k root oldAsid oldVa from c1]; exact RootSetA.assign k root oldAsid oldVa _) + (hptw := by cases k <;> pt_nr) (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) (assignInvA k (specPtr p) dst (asidOfA (wa base i)))).run (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)) - dst hd hEnc hrel hTr hnul hn1 (by rw [c1]; exact hn0) hM hObj hirq hsci - (fun s2' σ2' hs2 hσ2 HSs wc jx hcx => by + dst hd hEnc hrel hTr hnul hn1 (by rw [c1]; exact hn0) hM hObj hirq hsci (Pj := True) (fun _ => PtSrcA.nopt fun _ _ _ _ h => by cases k <;> cases h) + (fun s2' σ2' hs2 hσ2 HSs wc jxP hst2 hcx => by + have jx := jxP trivial have es : s2' = s2 := okinj (hs2.symm.trans hs) subst es have hk2' := HSs.keep hk1 (fun _ _ e => by cases e) (fun _ e => by cases e) @@ -503,7 +506,57 @@ theorem JStage3A.asidAssignA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) (E0.j.1.vs.yal root hrootY)) obtain ⟨ht', -⟩ := assignTagA (tag := assignTagWordA .high) hr (by decide) exact fun ht1 => by rw [ht'] at ht1; cases ht1 + -- (A′) the root of the new pool entry: its unmapped cap at dst is the only root-kind cap of `root`, `root` is installed nowhere + have hasidE : σ2'.archState.armAsidTable = σ.archState.armAsidTable := HSs.asid + have hroot4k : root.val % 4096 = 0 := by + cases k with + | stage1 => exact E0.j.1.vs.al_mod (hOldObj.2.2.2.1 root false oldAsid rfl).1 + | stage2 => + exact Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) + (E0.j.1.ext.xal root (hOldObj.2.1 root 0#u64 false oldAsid oldVa rfl))) + | high => + exact Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) + (E0.j.1.vs.yal root (hOldObj.2.2.1 root false oldAsid rfl))) + have hurt : untagA (root ||| assignTagWordA k) = root := + (assignTagA (tag := assignTagWordA k) hroot4k (by cases k <;> decide)).2 + obtain ⟨hcxA, hcoA⟩ := capA_setCapA hO hx hEnc hs2 + have hunmOld : RootUnmA root (capAtA (L.mem s) (cslotAddrA dst)) := by + have e : capAtA (L.mem s) (cslotAddrA dst) = assignUnmappedA k root oldAsid oldVa := hcap + rw [e] + cases k + · exact Or.inl ⟨_, rfl⟩ + · exact Or.inr (Or.inl ⟨_, _, rfl⟩) + · exact Or.inr (Or.inr ⟨_, rfl⟩) + obtain ⟨hnI0, hK0⟩ := E0.j.1.vsu.rootOnce _ hA root hunmOld + have hnoU : ∀ y, IsSlotA Z.th y → + ¬ RootUnmA (untagA (root ||| assignTagWordA k)) (capAtA (L.mem s2') y) := by + intro y hy hRU + rw [hurt] at hRU + by_cases e : y = cslotAddrA dst + · subst e + have e2 : capAtA (L.mem s2') (cslotAddrA dst) = assignMappedA k root (wa base i) := hcxA + rw [e2] at hRU + cases k <;> simp [RootUnmA, assignMappedA] at hRU + · have hyO : y ∈ OS := RS.sub _ hy + have e2 : capAtA (L.mem s2') y = capA st s y := (hcoA y hyO e).trans (hOS1.capA hyO) + rw [e2] at hRU + exact e (hK0 y hy hRU.kind) + have hinst : ¬ RootInstA Z.Pp Z.X (L.mem s2') (L.ksb s2') σ2' (untagA (root ||| assignTagWordA k)) := by + rw [hurt] + rintro (⟨a, raw, hact, e⟩ | ⟨a, hS⟩) + · rw [hjks] at hact + exact hnI0 (Or.inl ⟨a, raw, ActiveAsidRootA.of_mem (fun b hb => hVsMem b hb) hact, e⟩) + · refine hnI0 (Or.inr ⟨a, S2RootOfAsidA.of_spec (σ := σ2') (σ' := σ) hasidE.symm (fun q hq => ?_) hS⟩) + obtain ⟨g, hkg, -⟩ := E0.j.1.vs.pool q hq + have hn : specPtr q ≠ σ.curThread := fun e => by rw [e, hkx] at hkg; cases hkg + have hk1 : (stUpdA σ σ.curThread x' .restart).kheap (specPtr q) = some (.archObj (.asidPool g)) := by + simp [stUpdA, setObjA, Function.update_of_ne hn, hkg] + rw [hkg, HSs.keep hk1 (fun _ _ e => by cases e) (fun _ e => by cases e)] obtain ⟨J3, -, -⟩ := assign_write_jointA E0 RS jx hjks hcpu2 hpP hi512 w hk2' hkind hzero hunmVs2 hunmS2' + ⟨hp0, hi, hhi, by rw [hjks, hVsMem _ (.asid hi hhi)]; exact hq⟩ + (by rw [hVsMem _ (.pool p i hpP hi512)]; exact hentry) + (fun a b q h1 h2 => E0.tabInj a b q (by rw [← hasidE]; exact h1) (by rw [← hasidE]; exact h2)) + hnoU hinst -- the writes have wP : WritesIn st s2' (L.wr s2' (peAF p i) (root ||| assignTagWordA k)) (fun b => b = peAF p i) := (writesIn_wr w.al).mono fun b hb => hb diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmCnCopyA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmCnCopyA.lean index af0caeff0..0ae1fcda3 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmCnCopyA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmCnCopyA.lean @@ -12,6 +12,7 @@ keeps `JStage3A`. No named premise. New module. -/ +import Fl4ProofsA64.P3.Stage3ArmCnMoveA import Fl4ProofsA64.P3.Stage3BodyKeepA import Fl4ProofsA64.P3.Stage3CnInsA import Fl4ProofsA64.P3.IpcXferLoopA @@ -139,7 +140,8 @@ theorem JStage3A.capInsertGenA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : H (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) {nc : capability.Cap} {anc : Fl4SpecA64.Cap} (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))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA nc (capA st s (cslotAddrA ss))) + (hal : UA nc (capA st s (cslotAddrA ss)) ∨ Fl4ProofsA64.P1.W7.R.ST.SubA nc (capA st s (cslotAddrA ss))) (hk : SameBadgeKindA nc (capA st s (cslotAddrA ss))) (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)) @@ -208,9 +210,18 @@ theorem JStage3A.capInsertGenA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : H fun s' w i hi => w.mem_eq (hfal _ (.irq i hi)) (hoff _ (.irq i hi)) have mJ := hJ5 hst0 σ rw [← hIns] at mJ - have mv := WP.spec_and (cap_insert_refinesA s σ Z.G J1.j.1.st J1.j.1.cdt hP hO hTr J1.j5.2.1 hnul hAs hAd - hsn cd0 hdc hwf hanc hw hn hal hk hut hub hsib) mJ - obtain ⟨s2, hs2, ⟨σ2, hm, hst2, hcdt2, -, HS, hcs2⟩, w, ed, hfull, ek, -⟩ := spec_existsA mv + have hsd0 : cslotAddrA ss ≠ cslotAddrA sd := fun e => hsn (by rw [e]; exact hdn) + have hsG0 : cslotAddrA ss ∈ Z.G.chains.flatten := (hTr.lk.members _).2 ⟨xs, hsn⟩ + have mB : cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) ⦃ s' => + (∀ y ∈ OS, y ≠ cslotAddrA sd → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y ∧ + fbA st s' y = fbA st s y) ∧ + Fl4ProofsA64.P1.W7.R.ST.revA st s' (cslotAddrA sd) = revFA nc (capA st s (cslotAddrA ss)) ∧ + fbA st s' (cslotAddrA sd) = revFA nc (capA st s (cslotAddrA ss)) ⦄ := by + rw [hIns] + exact insWC_bitsA hO xs xd hsd0 rfl hw (fun h => ((hTr.lk.members _).1 ((hTr.lk.lkF hO.nz).nxm _ hsG0 h)).1) + have mv := WP.spec_and (WP.spec_and (cap_insert_refinesA s σ Z.G J1.j.1.st J1.j.1.cdt hP hO hTr J1.j5.2.1 hnul hAs hAd + hsn cd0 hdc hwf hanc hw hn hal hk hut hub hsib) mJ) mB + obtain ⟨s2, hs2, ⟨⟨σ2, hm, hst2, hcdt2, -, HS, hcs2⟩, w, ed, hfull, ek, -⟩, hbk, hrb, -⟩ := spec_existsA mv have j5' : J5A st { 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 := by have mJ2 := hJ5 hst0 σ2 @@ -221,6 +232,9 @@ theorem JStage3A.capInsertGenA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : H have jx : JAtZAX (L := L) AR { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA sd) (insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))))) } s2 a σ2 m := by refine J1.j.of_slotWrites w (fun b hb' hb => hoff b hb hb') hfal _ HS hst2 hcdt2 (fun y hy => ?_) + (PtClosedA.ofTab (PtCapClosedA.of_ins (PtSrcA.of_deriv hsS hD) hcs2) + (TabClosedA.of_copy hcs2 + (RootCopyA.of_der (mem := L.mem s) hsS (by rw [capAtA_eq (st := st)]; exact hrd)))) rcases hcs2 y hy with e | e | ⟨p, b, i, d, e⟩ <;> rw [e] · exact J1.j.capObj hy · exact hno @@ -228,6 +242,8 @@ theorem JStage3A.capInsertGenA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : H fun _ _ _ h => (by cases h), trivial⟩ have F : CapsFromA st OS s s2 := CapsFromA.of_insA xs xd hD cd0 ed hfull (fun p b i d h => hTr.ut.fib _ xs p b i d h) ek + (fun y hy hyd => (hbk y hy hyd).1) + (fun fr => by rw [hrb]; exact revFA_frame (by rw [ed] at fr; exact fr) _) -- the spec side obtain ⟨asc, hgs, -⟩ := getCap_eqA J1.j.1.st hAs obtain ⟨dc, hgd0, -⟩ := getCap_eqA J1.j.1.st hAd @@ -400,7 +416,7 @@ theorem JStage3A.capInsertA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) {nc : capability.Cap} {anc : Fl4SpecA64.Cap} (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))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA 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))) @@ -463,7 +479,7 @@ theorem JStage3A.capInsertA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap unfold insBA rw [J1.j.1.cdt.orig ss hAs] exact sbp_eqA _ _ _ hsh hsr hss hk hwf - exact JStage3A.capInsertGenA (J := J) ss sd hCs hCd hsn hdn hdc hwf hanc hw hn hD hal hk hut hdo hsci hno hoffN + exact JStage3A.capInsertGenA (J := J) ss sd hCs hCd hsn hdn hdc hwf hanc hw hn hD hrd (Or.inl hal) hk hut hdo hsci hno hoffN (hub_ofA E1 hAs xs hd) (hsib_ofA J1.j.1.cdt hAs hd) hbeq (fun hst σ' => J5A.insGenA (σ' := σ') (m := m) (m' := m) hO J1.j5 hTr xs xd hsS hdS hsn cd0 hdc hw hsh1 hbd1 hirqB hirqN hirqA hut hzb hst) symL sysl j7 @@ -483,7 +499,7 @@ theorem JStage3A.cnodeCopyA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) {nc : capability.Cap} {anc : Fl4SpecA64.Cap} (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))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA 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))) @@ -527,12 +543,12 @@ theorem JStage3A.cnodeCopyA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap have cs0 : capA st (L.wr s (stA (L.curW s)) sched.TS_RESTART) (cslotAddrA ss) = capA st s (cslotAddrA ss) := hOS1.capA xs have cd0 : capA st (L.wr s (stA (L.curW s)) sched.TS_RESTART) (cslotAddrA sd) = .Null := (hOS1.capA xd).trans hdn - rw [← cs0] at hsn hD hal hk hsh hsh1 hbd1 hbd hirq hz hut hcv j7 ⊢ - generalize hs0 : L.wr s (stA (L.curW s)) sched.TS_RESTART = s0 at heq J1 hOS1 sysl symL j7 cs0 cd0 hsn hD hal hk hsh hsh1 hbd1 hbd hirq hz hut hcv ⊢ + rw [← cs0] at hsn hD hrd hal hk hsh hsh1 hbd1 hbd hirq hz hut hcv j7 ⊢ + generalize hs0 : L.wr s (stA (L.curW s)) sched.TS_RESTART = s0 at heq J1 hOS1 sysl symL j7 cs0 cd0 hsn hD hrd hal hk hsh hsh1 hbd1 hbd hirq hz hut hcv ⊢ generalize hσ0 : stUpdA σ σ.curThread x .restart = σ0 at J1 j7 ⊢ have hdo0 : ¬ IrqNodeA (L.ksb s0) (fl4Ptr sd.1) ∨ IrqCapA (absCapA nc) := by rw [← hs0, L.ksb_wr]; exact hdo - obtain ⟨s2, σ2, hs2, hm, hbk, -, J3⟩ := JStage3A.capInsertA (J := J1) ss sd hCs hCd hsn cd0 hdc hwf hanc hw hn hD hal hk hsh + obtain ⟨s2, σ2, hs2, hm, hbk, -, J3⟩ := JStage3A.capInsertA (J := J1) ss sd hCs hCd hsn cd0 hdc hwf hanc hw hn hD hrd hal hk hsh hsh1 hbd1 hbd (fun i h => (hirq i).2 h) (fun i h => Or.inl ((hirq i).1 h)) (fun i h => Or.inl ((hirq i).1 h)) hz hut hdo0 hcv hsci symL sysl (fun s2 σ2 h1 h2 => by have h3 := j7 x s2 σ2 hk0 h1 (by rw [hσ0]; exact h2) diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmCnMoveA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmCnMoveA.lean index 761e59adb..8deb802a6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmCnMoveA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmCnMoveA.lean @@ -257,6 +257,27 @@ theorem updCapData_true_okA {d : U64} {c nc : capability.Cap} (h : objects.updat · exact absurd e' hn exact ⟨a, u, b, c', e⟩ +/-- A derived cap is a page-table cap only if it is the source. -/ +theorem PtSrcA.of_deriv {th : TypedHeapA} {S1 T2 : Set U64} {s : S} {src : U64} {nc : capability.Cap} + (hsS : IsSlotA th src) (hD : Fl4ProofsA64.P3.DerivA nc (capA st s src)) : PtSrcA th S1 T2 (L.mem s) nc := by + intro ptr asid va mp h + refine Or.inl ⟨src, hsS, ?_⟩ + subst h + rw [capAtA_eq (st := st)] + generalize capA st s src = c at hD ⊢ + cases hD + rfl + +/-- A derived cap is a root-kind cap only if it is the source. -/ +theorem DerivA.root_of {nc c : capability.Cap} (h : Fl4ProofsA64.P3.DerivA nc c) {r : U64} (hk : RootKindA r nc) : + nc = c := by + cases h <;> first | rfl | (exfalso; rcases hk with ⟨_, _, e⟩ | ⟨_, _, _, e⟩ | ⟨_, _, e⟩ <;> cases e) + +/-- A derived cap is a `PageTable` cap only if it is the source. -/ +theorem DerivA.pt_of {nc c : capability.Cap} (h : Fl4ProofsA64.P3.DerivA nc c) {r : U64} (hk : PtKindA r nc) : + nc = c := by + cases h <;> first | rfl | (exfalso; obtain ⟨_, _, _, e⟩ := hk; cases e) + set_option maxHeartbeats 4000000 in /-- **`JStage3A` across the CNode Move / Mutate arm** (module docstring). -/ theorem JStage3A.cnodeMoveA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} @@ -316,14 +337,22 @@ theorem JStage3A.cnodeMoveA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap have F0 := hTr.lk.lkF hO.nz have inOS : ∀ y ∈ Z.G.chains.flatten, y ∈ OS := fun y hy => ((hTr.lk.members y).1 hy).1 have hsG : cslotAddrA ss ∈ Z.G.chains.flatten := (hTr.lk.members _).2 ⟨xs, hsn⟩ - have mv := WP.spec_and (WP.spec_and + have mv := WP.spec_and (WP.spec_and (WP.spec_and (cap_move_refinesA s1 σ1 Z.G J1.j.1.st J1.j.1.cdt hP hO hTr J1.j5.2.1 hnul hAs hAd hsn cd1 hdc hca hw hn hal) (moveCap_osA hO xs xd (fun h => inOS _ (F0.pvm _ hsG h)) (fun h => inOS _ (F0.nxm _ hsG h)))) + (moveCap_revT hO hTr xs xd hsd hsn hw)) (J5A.moveA (σ' := σ1) (m := m) (m' := m) hO J1.j5 hTr xs xd hsd hsS hdS hsn cd1 hdc hw hn hal hsh hbd hirq (fun s' w i hi => w.mem_eq (hfal _ (.irq i hi)) (hoff _ (.irq i hi)))) - obtain ⟨s2, hs2, ⟨⟨σ2, hm, hst, hcdt, -, HS, hcs⟩, -⟩, w, ed, es, ek, -⟩ := spec_existsA mv + obtain ⟨s2, hs2, ⟨⟨⟨σ2, hm, hst, hcdt, -, HS, hcs⟩, -⟩, hrk, hrd⟩, w, ed, es, ek, -⟩ := spec_existsA mv have jx : JAtZAX (L := L) AR { Z with G := mvGA Z.G (cslotAddrA ss) (cslotAddrA sd) } s2 a σ2 m := by refine J1.j.of_slotWrites w (fun b hb' hb => hoff b hb hb') hfal _ HS hst hcdt (fun y hy => ?_) + (PtClosedA.ofTab (PtCapClosedA.of_three (PtSrcA.of_deriv hsS hD) hcs) + (TabClosedA.of_mv (ss := cslotAddrA ss) (sd := cslotAddrA sd) (nc := nc) + (by rw [capAtA_eq (st := st)]; exact es) + (by rw [capAtA_eq (st := st)]; exact ed) hsS + (fun y hy e1 e2 => by rw [capAtA_eq (st := st), capAtA_eq (st := st)]; exact ek y (J1.j5.2.1 y hy) e1 e2) + (by rw [capAtA_eq (st := st)] + exact RootMvA.of_der (fun r hk => hD.root_of hk) (fun r hk => hD.pt_of hk)))) rcases hcs y hy with e | e | e <;> rw [e] · exact CapObjOkA.null Z · exact J1.j.capObj hy @@ -333,7 +362,7 @@ theorem JStage3A.cnodeMoveA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap (J5A.moveA (σ' := σ2) (m := m) (m' := m) hO J1.j5 hTr xs xd hsd hsS hdS hsn cd1 hdc hw hn hal hsh hbd hirq (fun s' w i hi => w.mem_eq (hfal _ (.irq i hi)) (hoff _ (.irq i hi)))) rw [hs2] at hs2'; have e := okinj hs2'; subst e; exact J5' - have F : CapsFromA st OS s1 s2 := CapsFromA.of_moveA xs xd hsd hD cd1 ed es ek + have F : CapsFromA st OS s1 s2 := CapsFromA.of_moveA xs xd hsd hD cd1 ed es ek hal hrk hrd -- the spec side obtain ⟨σa, σb, h1, h2, ecdt, eorig, ekh, ems⟩ := capMove_outA hm obtain ⟨c1, o1, m1⟩ := setCap_keepsA h1 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmCnRotA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmCnRotA.lean index a7d534280..19777e77f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmCnRotA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmCnRotA.lean @@ -157,8 +157,12 @@ theorem CapsFromA.of_rotA {OS : Set U64} {s s' : S} {src piv dest : U64} (hs : s (hd : dest ∈ OS) {np ns : capability.Cap} (hDp : Fl4ProofsA64.P3.DerivA np (capA st s piv)) (hDs : Fl4ProofsA64.P3.DerivA ns (capA st s src)) (hdn : capA st s dest = .Null) (ed : capA st s' dest = np) (ep : capA st s' piv = ns) (es : capA st s' src = .Null) - (ek : ∀ y ∈ OS, y ≠ src → y ≠ piv → y ≠ dest → capA st s' y = capA st s y) : CapsFromA st OS s s' := by - refine ⟨fun u hu => ?_, fun v hv => ?_⟩ + (ek : ∀ y ∈ OS, y ≠ src → y ≠ piv → y ≠ dest → capA st s' y = capA st s y) + (halp : UA np (capA st s piv)) (hals : UA ns (capA st s src)) + (hr : ∀ y ∈ OS, y ≠ src → y ≠ piv → y ≠ dest → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) + (hrd : Fl4ProofsA64.P1.W7.R.ST.revA st s' dest = Fl4ProofsA64.P1.W7.R.ST.revA st s piv) (hrp : Fl4ProofsA64.P1.W7.R.ST.revA st s' piv = Fl4ProofsA64.P1.W7.R.ST.revA st s src) : + CapsFromA st OS s s' := by + refine ⟨fun u hu => ?_, fun v hv => ?_, fun u hu fu => ?_⟩ · by_cases e1 : u = src · exact Or.inl (e1 ▸ es) by_cases e2 : u = piv @@ -173,6 +177,19 @@ theorem CapsFromA.of_rotA {OS : Set U64} {s s' : S} {src piv dest : U64} (hs : s by_cases e3 : v = dest · exact Or.inl (e3 ▸ hdn) exact Or.inr ⟨v, hv, by rw [ek v hv e1 e2 e3]; exact .refl _⟩ + · by_cases e1 : u = src + · rw [e1, es] at fu; simp [isFrA] at fu + by_cases e2 : u = piv + · right + rw [e2, ep] at fu + exact ⟨src, hs, by rw [← hDs.isFr]; exact fu, by rw [e2, ep, hals.base], by rw [e2, ep, hals.top], by rw [e2, hrp]⟩ + by_cases e3 : u = dest + · right + rw [e3, ed] at fu + exact ⟨piv, hp, by rw [← hDp.isFr]; exact fu, by rw [e3, ed, halp.base], by rw [e3, ed, halp.top], by rw [e3, hrd]⟩ + · right + exact ⟨u, hu, by rw [← ek u hu e1 e2 e3]; exact fu, by rw [ek u hu e1 e2 e3], by rw [ek u hu e1 e2 e3], + (hr u hu e1 e2 e3).symm⟩ set_option maxHeartbeats 4000000 in /-- **`JStage3A` across the CNode Rotate arm, source ≠ destination** (module docstring). -/ @@ -256,12 +273,13 @@ theorem JStage3A.cnodeRotateA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He have inOS : ∀ y ∈ Z.G.chains.flatten, y ∈ OS := fun y hy => ((hTr.lk.members y).1 hy).1 have hpG : cslotAddrA sp ∈ Z.G.chains.flatten := (hTr.lk.members _).2 ⟨xp, hpn⟩ -- the first move: the pivot's new cap to the destination - have mv1 := WP.spec_and (WP.spec_and + have mv1 := WP.spec_and (WP.spec_and (WP.spec_and (cap_move_refinesA s0 σ0 Z.G J1.j.1.st J1.j.1.cdt hP hO hTr J1.j5.2.1 hnul hAp hAd hpn cd0 hdc hcp hwp hnp halp) (moveCap_osA hO xp xd (fun h => inOS _ (F0.pvm _ hpG h)) (fun h => inOS _ (F0.nxm _ hpG h)))) + (moveCap_revT hO hTr xp xd hpd hpn hwp)) (J5A.moveA (σ' := σ0) (m := m) (m' := m) hO J1.j5 hTr xp xd hpd hpS hdS hpn cd0 hdc hwp hnp halp hshp hbdp hirqp (fun s' w i hi => w.mem_eq (hfal _ (.irq i hi)) (hoff _ (.irq i hi)))) - obtain ⟨s1, hs1, ⟨⟨σ1, hm1, hst1, hcdt1, hT1, HS1, hcs1⟩, -⟩, w1, ed1, es1, ek1, J51⟩ := spec_existsA mv1 + obtain ⟨s1, hs1, ⟨⟨⟨σ1, hm1, hst1, hcdt1, hT1, HS1, hcs1⟩, -⟩, hrk1, hrd1⟩, w1, ed1, es1, ek1, J51⟩ := spec_existsA mv1 -- between the moves: no `SysL` / J7, only the relation, the tree and the MDB slot have ks1 : L.ksb s1 = L.ksb s0 := w1.1 have cs1 : capA st s1 (cslotAddrA ss) = capA st s0 (cslotAddrA ss) := ek1 _ xs hsp hsd @@ -272,12 +290,13 @@ theorem JStage3A.cnodeRotateA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He ∀ i : U64, i.val < 5376 → L.mem s' (irqStAddrA (L.ksb s1) i) = L.mem s1 (irqStAddrA (L.ksb s1) i) := fun s' w i hi => by rw [ks1]; exact w.mem_eq (hfal _ (.irq i hi)) (hoff _ (.irq i hi)) -- the second move: the source's new cap to the pivot - have mv2 := WP.spec_and + have mv2 := WP.spec_and (WP.spec_and (cap_move_refinesA s1 σ1 _ hst1 hcdt1 hP hO hT1 J1.j5.2.1 hnul1 hAs hAp hsn1 es1 hpc hcs hws hns (by rw [cs1]; exact hals)) + (moveCap_revT hO hT1 xs xp hsp hsn1 hws)) (J5A.moveA (σ' := σ1) (m := m) (m' := m) hO J51 hT1 xs xp hsp hsS hpS hsn1 es1 hpc hws hns (by rw [cs1]; exact hals) (by rw [cs1]; exact hshs) (by rw [cs1]; exact hbds) (by rw [cs1]; exact hirqs) hst1') - obtain ⟨s3, hs3, ⟨σ3, hm2, hst3, hcdt3, -, HS2, hcs2⟩, w2, ed2, es2, ek2, -⟩ := spec_existsA mv2 + obtain ⟨s3, hs3, ⟨⟨σ3, hm2, hst3, hcdt3, -, HS2, hcs2⟩, hrk2, hrd2⟩, w2, ed2, es2, ek2, -⟩ := spec_existsA mv2 have j5' : J5A st { Z with G := rotGA Z.G (cslotAddrA ss) (cslotAddrA sp) (cslotAddrA sd) } H OS s3 σ3 m := by obtain ⟨s3', hs3', -, -, -, -, J5'⟩ := spec_existsA (J5A.moveA (σ' := σ3) (m := m) (m' := m) hO J51 hT1 xs xp hsp hsS hpS hsn1 es1 hpc hws hns @@ -286,8 +305,31 @@ theorem JStage3A.cnodeRotateA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He rw [hs3] at hs3'; have e := okinj hs3'; subst e; exact J5' have w : WritesIn st s0 s3 (W7.CapW H.tcbs {b | InOS OS b} ∅) := w1.trans1 w2 have HS : SpecSlotA σ0 σ3 := HS1.trans HS2 + have tcRot : TabClosedA Z.th (L.mem s0) (L.mem s3) := + TabClosedA.trans + (TabClosedA.of_mv (ss := cslotAddrA sp) (sd := cslotAddrA sd) (nc := np) + (by rw [capAtA_eq (st := st)]; exact es1) (by rw [capAtA_eq (st := st)]; exact ed1) hpS + (fun y hy e1 e2 => by + rw [capAtA_eq (st := st), capAtA_eq (st := st)]; exact ek1 y (J1.j5.2.1 y hy) e1 e2) + (by rw [capAtA_eq (st := st)] + exact RootMvA.of_der (fun r hk => hDp.root_of hk) (fun r hk => hDp.pt_of hk))) + (TabClosedA.of_mv (ss := cslotAddrA ss) (sd := cslotAddrA sp) (nc := ns) + (by rw [capAtA_eq (st := st)]; exact es2) (by rw [capAtA_eq (st := st)]; exact ed2) hsS + (fun y hy e1 e2 => by + rw [capAtA_eq (st := st), capAtA_eq (st := st)]; exact ek2 y (J1.j5.2.1 y hy) e1 e2) + (by rw [capAtA_eq (st := st), cs1] + exact RootMvA.of_der (fun r hk => hDs.root_of hk) (fun r hk => hDs.pt_of hk))) have jx : JAtZAX (L := L) AR { Z with G := rotGA Z.G (cslotAddrA ss) (cslotAddrA sp) (cslotAddrA sd) } s3 a σ3 m := by refine J1.j.of_slotWrites w (fun b hb' hb => hoff b hb hb') hfal _ HS hst3 hcdt3 (fun y hy => ?_) + ⟨fun y hy ptr asid va mp h => by + rcases hcs2 y hy with e | e | e <;> rw [e] at h + · cases h + · rcases hcs1 y hy with e' | e' | e' <;> rw [e'] at h + · cases h + · exact Or.inl ⟨y, hy, h⟩ + · exact (PtSrcA.of_deriv hpS hDp ptr asid va mp h).imp (fun ⟨y0, a0, b0⟩ => ⟨y0, a0, b0.trans h⟩) id + · exact (PtSrcA.of_deriv hsS hDs ptr asid va mp h).imp (fun ⟨y0, a0, b0⟩ => ⟨y0, a0, b0.trans h⟩) id, + tcRot.root, tcRot.pts.toE⟩ rcases hcs2 y hy with e | e | e <;> rw [e] · exact CapObjOkA.null Z · rcases hcs1 y hy with e' | e' | e' <;> rw [e'] @@ -299,7 +341,10 @@ theorem JStage3A.cnodeRotateA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He have cd3 : capA st s3 (cslotAddrA sd) = np := by rw [ek2 _ xd (Ne.symm hsd) (Ne.symm hpd)]; exact ed1 have ek : ∀ y ∈ OS, y ≠ cslotAddrA ss → y ≠ cslotAddrA sp → y ≠ cslotAddrA sd → capA st s3 y = capA st s0 y := fun y hy e1 e2 e3 => by rw [ek2 y hy e1 e2, ek1 y hy e2 e3] - have F : CapsFromA st OS s0 s3 := CapsFromA.of_rotA xs xp xd hDp hDs cd0 cd3 ed2 es2 ek + have F : CapsFromA st OS s0 s3 := CapsFromA.of_rotA xs xp xd hDp hDs cd0 cd3 ed2 es2 ek halp hals + (fun y hy e1 e2 e3 => by rw [hrk2 y hy e1 e2, hrk1 y hy e2 e3]) + (by rw [hrk2 _ xd (Ne.symm hsd) (Ne.symm hpd)]; exact hrd1) + (by rw [hrd2, hrk1 _ xs hsp hsd]) -- the spec side, per step have hne1 : sp ≠ sd := fun e => hpd (by rw [e]) have hne2 : ss ≠ sp := fun e => hsp (by rw [e]) diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmCnSwapA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmCnSwapA.lean index a7d8962ae..ade7f4ddb 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmCnSwapA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmCnSwapA.lean @@ -14,6 +14,7 @@ l4v `cap_swap`, keeps `JStage3A`. No named premise. New module. -/ +import Fl4ProofsA64.P3.Stage3ArmCnMoveA import Fl4ProofsA64.P3.Stage3BodyKeepA import Fl4ProofsA64.P3.Stage3ArmCnRotA import Fl4ProofsA64.P3.SwapA @@ -277,12 +278,34 @@ theorem J5A.swapA {Z : XSetsA} {H : Heap} {s : S} {σ σ' : Fl4SpecA64.State Uni have f2 : y ≠ x2 := fun e => hns (e ▸ hS2) rw [ek y hy f1 f2]; exact J.2.2 y hy hns +/-- **`swap` and the revocable bit** (module docstring), over the tree: the two slots exchange their bits, every other +`OS` slot keeps its own. -/ +theorem swap_revT {G : List (List U64)} {par : U64 → Option U64} (hO : OSOK T Ω Sg OS) {s : S} + (hT : TreeA st OS G par s) {x1 x2 : U64} + {c1 c2 : capability.Cap} (hx1 : x1 ∈ OS) (hx2 : x2 ∈ OS) (hne : x1 ≠ x2) (hn1 : capA st s x1 ≠ .Null) + (hn2 : capA st s x2 ≠ .Null) (hs1 : obj.sext48 x1 = ok x1) + (hs2 : obj.sext48 x2 = ok x2) (hw1 : CapRt.EncWf c1) (hw2 : CapRt.EncWf c2) : + cdt.swap st s c1 x1 c2 x2 ⦃ s' => + (∀ y ∈ OS, y ≠ x1 → y ≠ x2 → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s' x1 = Fl4ProofsA64.P1.W7.R.ST.revA st s x2 ∧ + Fl4ProofsA64.P1.W7.R.ST.revA st s' x2 = Fl4ProofsA64.P1.W7.R.ST.revA st s x1 ⦄ := by + have F := hT.lk.lkF hO.nz + have inOS : ∀ y ∈ G.flatten, y ∈ OS := fun y hy => ((hT.lk.members y).1 hy).1 + have hG1 : x1 ∈ G.flatten := (hT.lk.members _).2 ⟨hx1, hn1⟩ + have hG2 : x2 ∈ G.flatten := (hT.lk.members _).2 ⟨hx2, hn2⟩ + exact WP.spec_mono (swap_bitA hO (LR.self s) hx1 hx2 hne hs1 hs2 hw1 hw2 + (fun h => inOS _ (F.pvm _ hG1 h)) (fun h => inOS _ (F.nxm _ hG1 h)) + (fun h => inOS _ (F.pvm _ hG2 h)) (fun h => inOS _ (F.nxm _ hG2 h))) + fun _ ⟨hbk, hb1, hb2⟩ => ⟨fun y hy e1 e2 => revA_of_rvb_eqA (hbk y hy e1 e2), revA_of_rvbA hb1, revA_of_rvbA hb2⟩ + /-- **The slot caps after a swap**: each slot holds a cap derived from the other's. -/ theorem CapsFromA.of_swapA {s s' : S} {x1 x2 : U64} (h1 : x1 ∈ OS) (h2 : x2 ∈ OS) {c1 c2 : capability.Cap} (hD1 : Fl4ProofsA64.P3.DerivA c1 (capA st s x1)) (hD2 : Fl4ProofsA64.P3.DerivA c2 (capA st s x2)) (e1 : capA st s' x1 = c2) (e2 : capA st s' x2 = c1) - (ek : ∀ y ∈ OS, y ≠ x1 → y ≠ x2 → capA st s' y = capA st s y) : CapsFromA st OS s s' := by - refine ⟨fun u hu => ?_, fun v hv => ?_⟩ + (ek : ∀ y ∈ OS, y ≠ x1 → y ≠ x2 → capA st s' y = capA st s y) + (hal1 : UA c1 (capA st s x1)) (hal2 : UA c2 (capA st s x2)) + (hr : ∀ y ∈ OS, y ≠ x1 → y ≠ x2 → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) + (hr1 : Fl4ProofsA64.P1.W7.R.ST.revA st s' x1 = Fl4ProofsA64.P1.W7.R.ST.revA st s x2) (hr2 : Fl4ProofsA64.P1.W7.R.ST.revA st s' x2 = Fl4ProofsA64.P1.W7.R.ST.revA st s x1) : CapsFromA st OS s s' := by + refine ⟨fun u hu => ?_, fun v hv => ?_, fun u hu fu => ?_⟩ · by_cases f1 : u = x1 · exact Or.inr ⟨x2, h2, by rw [f1, e1]; exact hD2⟩ by_cases f2 : u = x2 @@ -293,6 +316,15 @@ theorem CapsFromA.of_swapA {s s' : S} {x1 x2 : U64} (h1 : x1 ∈ OS) (h2 : x2 by_cases f2 : v = x2 · exact Or.inr ⟨x1, h1, by rw [e1, f2]; exact hD2⟩ exact Or.inr ⟨v, hv, by rw [ek v hv f1 f2]; exact .refl _⟩ + · right + by_cases f1 : u = x1 + · rw [f1, e1] at fu + exact ⟨x2, h2, by rw [← hD2.isFr]; exact fu, by rw [f1, e1, hal2.base], by rw [f1, e1, hal2.top], by rw [f1, hr1]⟩ + by_cases f2 : u = x2 + · rw [f2, e2] at fu + exact ⟨x1, h1, by rw [← hD1.isFr]; exact fu, by rw [f2, e2, hal1.base], by rw [f2, e2, hal1.top], by rw [f2, hr2]⟩ + · exact ⟨u, hu, by rw [← ek u hu f1 f2]; exact fu, by rw [ek u hu f1 f2], by rw [ek u hu f1 f2], + (hr u hu f1 f2).symm⟩ end @@ -365,12 +397,13 @@ theorem JStage3A.cnodeRotateSwA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : have hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s0 y = .Null := J1.j5.2.2 have hoff := footN_offA E1 have hfal := FootNA.aligned J1.j.1 (bxi_nodes E1.sys.ent.bxi) E1.scAl E1.ap.vcAl - have mv := WP.spec_and + have mv := WP.spec_and (WP.spec_and (cap_swap_refinesA s0 σ0 Z.G J1.j.1.st J1.j.1.cdt hP hO hTr J1.j5.2.1 hnul hAs hAp hne hsn hpn hsx hpx hcs hcp hws hwp hns hnp hals halp) + (swap_revT hO hTr xs xp hsp hsn hpn hsx hpx hws hwp)) (J5A.swapA (σ' := σ0) (m := m) (m' := m) hO J1.j5 hTr xs xp hsp hsS hpS hsn hpn hsx hpx hws hwp hshs hbds hirqs hshp hbdp hirqp (fun s' w i hi => w.mem_eq (hfal _ (.irq i hi)) (hoff _ (.irq i hi)))) - obtain ⟨s2, hs2, ⟨σ2, hm, hst2, hcdt2, -, HS, hcs2⟩, w, e1, e2, ek, -⟩ := spec_existsA mv + obtain ⟨s2, hs2, ⟨⟨σ2, hm, hst2, hcdt2, -, HS, hcs2, hp1, hp2, hpo⟩, hrk, hr1, hr2⟩, w, e1, e2, ek, -⟩ := spec_existsA mv have j5' : J5A st { Z with G := swGA Z.G (cslotAddrA ss) (cslotAddrA sp) } H OS s2 σ2 m := by obtain ⟨s2', hs2', -, -, -, -, J5'⟩ := spec_existsA (J5A.swapA (σ' := σ2) (m := m) (m' := m) hO J1.j5 hTr xs xp hsp hsS hpS hsn hpn hsx hpx hws hwp hshs hbds @@ -378,11 +411,17 @@ theorem JStage3A.cnodeRotateSwA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : rw [hs2] at hs2'; have e := okinj hs2'; subst e; exact J5' have jx : JAtZAX (L := L) AR { Z with G := swGA Z.G (cslotAddrA ss) (cslotAddrA sp) } s2 a σ2 m := by refine J1.j.of_slotWrites w (fun b hb' hb => hoff b hb hb') hfal _ HS hst2 hcdt2 (fun y hy => ?_) + (PtClosedA.ofTab (PtCapClosedA.of_swap (PtSrcA.of_deriv hsS hDs) (PtSrcA.of_deriv hpS hDp) hcs2) + (TabClosedA.of_swapC hsS hpS hp1 hp2 hpo + (fun r hk => by rw [capAtA_eq]; first | exact DerivA.root_of hDs hk | (rw [← cs0]; exact DerivA.root_of hDs hk)) + (fun r hk => by rw [capAtA_eq]; first | exact DerivA.root_of hDp hk | (rw [← cp0]; exact DerivA.root_of hDp hk)) + (fun r hk => by rw [capAtA_eq]; first | exact DerivA.pt_of hDs hk | (rw [← cs0]; exact DerivA.pt_of hDs hk)) + (fun r hk => by rw [capAtA_eq]; first | exact DerivA.pt_of hDp hk | (rw [← cp0]; exact DerivA.pt_of hDp hk)))) rcases hcs2 y hy with e | e | e <;> rw [e] · exact J1.j.capObj hy · exact hos · exact hop - have F : CapsFromA st OS s0 s2 := CapsFromA.of_swapA xs xp hDs hDp e1 e2 ek + have F : CapsFromA st OS s0 s2 := CapsFromA.of_swapA xs xp hDs hDp e1 e2 ek hals halp hrk hr1 hr2 -- the spec side obtain ⟨σa, σb, h1, h2, ecdt, eorig, ekh, ems⟩ := capSwap_outA hm obtain ⟨c1, o1, m1⟩ := setCap_keepsA h1 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapA.lean index 5f454b218..dc8db8e9e 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapA.lean @@ -87,7 +87,7 @@ theorem JStage3A.frameMapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea have hSh := page_map_shapeA (L := L) (extra := extra) ar E0 RS cte hab hos hcap FP slbl hl length buf args hlen hargs call x0 hx0 exs hex hS1 hHi s3 a3 hdec obtain ⟨hfl, ivp, hD, x', s2, σ2, asid1, va, p, i, e, pte, σp, σ', hk', -, hsc, hσ2, HSs, hEnc, hca, hks2, hcpu2, - R2, hJ2, hFr2, hva, hp, hreach, hi, hk1, hk3', hwr, ⟨pa, sm, att, rg, hpte⟩, hA, hks3, hcpu3, hm3, ⟨t', hσp⟩, hms, + R2, hJ2, hFr2, hva, hp, hreach, hi, hk1, hk3', hwr, ⟨pa, sm, att, rg, hpte⟩, hA, hks3, hcpu3, hm3, ⟨t', hσp, happ⟩, hms, hperf, VR, HS2⟩ := hSh 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 @@ -220,7 +220,7 @@ theorem JStage3A.frameMapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea (Q := fun s' a' σ'' hw => s' = s3 ∧ a' = a3 ∧ σ'' = σ' ∧ 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 := .Frame fp sz rt dev true false asid1 va) (by rw [c1]; exact hM) hok hirq hsci + (c := .Frame fp sz rt dev true false asid1 va) (by rw [c1]; exact hM) hok hirq hsci (PtSrcA.nopt fun _ _ _ _ h => by cases h) (fun s2' σ2' hs2 hσ2' HS' w jx hcx => by obtain rfl : s2' = s2 := okinj (hs2.symm.trans hsc) obtain rfl : σ2' = σ2 := setCap_detA hσ2' hσ2 @@ -231,8 +231,9 @@ theorem JStage3A.frameMapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea simp only [Prod.mk.injEq, true_and] at e' rw [e']; exact h have J3 : JAtZAX (L := L) AR Z s3 a3 σ' m := by - have := map_finJA (S1' := Z.S1) (Lv' := Z.Lv) E0 J2 hT2 hks2 hcpu2 hp (J.tabS1 p hp) hi hks3 hcpu3 - (fun b hb hne => wP.mem_eq hb hne) (hσp ▸ hms) (fun q hq => Or.inl hq) (fun _ hq hl => ⟨hq, hl⟩) VR hFr2 hos + have := map_finJA_leaf E0 J2 hT2 hks2 hcpu2 hp (J.tabS1 p hp) hi hks3 hcpu3 + (fun b hb hne => wP.mem_eq hb hne) (hσp ▸ hms) VR + (fun ppn h => by rw [happ, hpte] at h; cases h) hFr2 hos exact this.1.of_arA hAR have eσ : σ'.kheap = σp.kheap := by obtain ⟨ms, h⟩ := hms diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapHiA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapHiA.lean index 5709eb085..9a00bc2f8 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapHiA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapHiA.lean @@ -5,6 +5,7 @@ P3 (AArch64, merge line, D8 step 5 (ii), the map arms): **`JStage3A` across a su hypotheses: the mapped `ArmHighVSpace` extra cap in an `OS` slot, `DecPre` (T3 adapter), [P] `P0.ArchTotal`. The final-state facts owed at T3 are `fin`. No named [J]. New module. -/ +import Fl4ProofsA64.P3.VsLeafShrA import Fl4ProofsA64.P3.Stage3BodyKeepA import Fl4ProofsA64.P3.Stage3MapExtCoreA open Aeneas Aeneas.Std Result @@ -244,7 +245,7 @@ theorem JStage3A.frameMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea have es2 := ok_inj_ff (hsc.symm.trans hsc1) subst es2 obtain ⟨J2, -⟩ := hJ2 hTr hnul (by intro h; cases h) (by rw [hcap0]; intro h; cases h) - (by rw [hcap0]; exact UA.of_shapeA rfl (by simp [isUtA])) hok + (by rw [hcap0]; exact UA.of_shapeA rfl (by simp [isUtA])) hok (PtSrcA.nopt fun _ _ _ _ h => by cases h) have hSlotAl : Aligned lu.slot := by rcases hslR with ⟨t, i, ⟨⟨ht, -⟩, -⟩, hi, hluEq, -⟩ | ⟨y, j, hy, -, hj, hluEq, -, -⟩ · rw [hluEq]; exact peAF_alignedA (E0.j.1.vs.al_mod ht) hi @@ -387,6 +388,13 @@ theorem JStage3A.frameMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea (fun w hw hne => by rw [hW'.2.2 w hw, if_neg (Ne.symm (hne i hi))]) (Or.inr (Or.inr (Or.inr ht))) (fun p hp => kheap_writeX (by rw [slotObjPtE (J2.1.vs.al_mod ht) hi]; exact hp)) + (hshr_oneA (q := t) (i := i) (J2.1.vs.al_mod ht) (fun w hw hne => by rw [hW'.2.2 w hw, if_neg (Ne.symm hne)]) + (fun h => (s2Entry_offA J2.1.ext (J2.1.vs.al_mod ht) hi (Or.inr (Or.inl ht)) h).elim) + (fun h => by + obtain ⟨pt0, hk0, -, -⟩ := J2.1.vs.pt t ht + refine h.notTab_of_rel hV3 rfl ht hi (pt := Fl4SpecA64.ptUpd pt0 i.bv pte) ?_ (fun ppn e => hnotPt ppn ?_) + · rw [extPtSetE hk0 (J2.1.vs.al_mod ht) hi]; simp [ptSetA, setObjA] + · rw [ptApply_updA pt0 hi hi, if_pos rfl] at e; exact e)) (by rw [hW'.1]; exact hV3) hE3 exact hJ'.of_arA hAR' have R1 := E0.j.1.vs @@ -442,6 +450,12 @@ theorem JStage3A.frameMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea have hJ' := J2.of_extPageA hfa2 hTO2 hEO2 (Or.inr (Or.inl ⟨y, hy, rfl⟩)) hW'.1 hW'.2.1 (fun w hw hne => by rw [hW'.2.2 w hw, if_neg (Ne.symm (hne j hj))]) (Or.inr (Or.inl hy)) (fun p hp => kheap_writeX (sl := .root (specPtr y) j.val) (pte := pte) hp) + (hshr_oneA (q := wa y 4096#u64) (i := j) (waWin_modA (J2.1.vs.yal y hy)) (fun w hw hne => by rw [hW'.2.2 w hw, if_neg (Ne.symm hne)]) + (fun h => (s2Entry_offA J2.1.ext (waWin_modA (J2.1.vs.yal y hy)) hj (Or.inr (Or.inr ⟨y, hy, rfl⟩)) h).elim) + (fun h => by + obtain ⟨l1, hk0, -⟩ := J2.1.vs.high y hy + refine h.notTab_of_relHi hV3 rfl hy hj (extRootSetE hk0 j.val pte) (fun ppn e => hnotPt ppn ?_) + simpa using e)) (by rw [hW'.1]; exact hV3) hE3 exact hJ'.of_arA hAR' have R1 := E0.j.1.vs diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapS2A.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapS2A.lean index dbc3e0148..a2fb00ae6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapS2A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmFrMapS2A.lean @@ -11,6 +11,7 @@ Named premises: the arm's decode-site facts (`hrt`, `hres`, `hCn`); [P] `P0.Arch `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.VsLeafShrA import Fl4ProofsA64.P3.Stage3BodyKeepA import Fl4ProofsA64.P3.Stage3MapExtCoreA import Fl4ProofsA64.P3.Stage3MapS2UnmA @@ -258,11 +259,20 @@ theorem JStage3A.frameMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea -- 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 + (hrt := RootSetA.of_noRoot (fun r hk => by + obtain ⟨_, _, _, _, hc, -⟩ := hbn; rw [hc] at hk + rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h)) + (hpt := Or.inl (PtSetA.of_noPt (fun r hk => by + obtain ⟨_, _, _, _, hc, -⟩ := hbn; rw [hc] at hk + obtain ⟨_, _, _, h⟩ := hk; cases h))) 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 + (PtSrcA.nopt fun _ _ _ _ h => by + obtain ⟨_, _, _, _, e, -⟩ := hbn + rw [e] at h; cases h) 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 @@ -377,6 +387,15 @@ theorem JStage3A.frameMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea (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)) + (hshr_oneA (q := t) (i := i) (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) (fun w hw hne => by rw [hW'.2.2 w hw, if_neg (Ne.symm hne)]) + (fun h => by + obtain ⟨pt0, hk0, -, -⟩ := J2.1.ext.s2pt t ht + refine h.notTab_of_rel hE3 rfl ht hi (pt := Fl4SpecA64.ptUpd pt0 i.bv pte) ?_ (fun ppn e => hnotPt ppn ?_) + · rw [extPtSetE hk0 (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) hi]; simp [ptSetA, setObjA] + · rw [ptApply_updA pt0 hi hi, if_pos rfl] at e; exact e) + (fun h => (s1Entry_offA J2.1.vs (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) hi + (fun m => (J2.1.ext.pgd t (Or.inl ht)).1 (Or.inr (Or.inl m))) + (fun y hy e => (J2.1.ext.pgd t (Or.inl ht)).1 (Or.inr (Or.inr ⟨y, hy, e⟩))) h).elim)) (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 @@ -419,6 +438,20 @@ theorem JStage3A.frameMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea 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) + (hshr_oneA (q := q) (i := j') (by + rcases hq with h | h <;> rw [h] + exacts [Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) (J2.1.ext.xal r0 hr0)), + waWin_modA (J2.1.ext.xal r0 hr0)] : q.val % 4096 = 0) (fun w hw hne => by rw [hW0.2.2 w hw, if_neg (by rw [hpeq]; exact Ne.symm hne)]) + (fun h => by + obtain ⟨es0, hk0, -⟩ := J2.1.ext.s2root r0 hr0 + refine h.notTab_of_relRoot hE3 hpeq.symm hr0 hj1k hj0 (extRootSetE hk0 j0.val pte) (fun ppn e => hnotPt ppn ?_) + simpa using e) + (fun h => (s1Entry_offA J2.1.vs (by + rcases hq with h | h <;> rw [h] + exacts [Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) (J2.1.ext.xal r0 hr0)), + waWin_modA (J2.1.ext.xal r0 hr0)] : q.val % 4096 = 0) hj' + (fun m => (J2.1.ext.pgd q (Or.inr ⟨r0, hr0, hq⟩)).1 (Or.inr (Or.inl m))) + (fun y hy e => (J2.1.ext.pgd q (Or.inr ⟨r0, hr0, hq⟩)).1 (Or.inr (Or.inr ⟨y, hy, e⟩))) h).elim)) (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 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmA.lean index d42b60fed..9b6b15ff6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmA.lean @@ -330,7 +330,7 @@ theorem JStage3A.frameUnmapUA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He obtain ⟨s2, σ2, hs2, hσ2, HSsk, -, J2⟩ := J1.of_capFrame (hpt := fun _ _ _ h => by cases h) 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 := .Frame fp sz rt dev false false 0#u64 0#u64) (by rw [c1]; exact .frame ..) hok hirq hsci + (c := .Frame fp sz rt dev false false 0#u64 0#u64) (by rw [c1]; exact .frame ..) hok hirq hsci (PtSrcA.nopt fun _ _ _ _ h => by cases h) (fun s2 σ2 hs2 hσ2 HS w jx hc2 => by obtain ⟨hcx, hco⟩ := capA_setCapA hO hx hEnc hs2 obtain ⟨w0, w1, hen, -⟩ := CapRt.decode_encode _ hEnc diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmMA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmMA.lean index 33457af22..79400ba05 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmMA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmMA.lean @@ -101,7 +101,10 @@ theorem setcap_core2A (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m (hcpu : L.cpu s2 = L.cpu s) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) {c0 c : capability.Cap} {sc : Fl4SpecA64.Cap} (hcap : capA st s (cslotAddrA cte) = c0) (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) (hua : UA c c0) (hok : CapObjOkA Z c) (hcn : c ≠ .Null) (hc0 : c0 ≠ .Null) - (hT : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) : + (hT : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) + (hptc : PtSrcA Z.th Z.S1 Z.T2 (L.mem s2) c) + (hrt : RootSetA (capAtA (L.mem s2) (cslotAddrA cte)) c := by root_nr) + (hptw : PtSetE Z.th (L.mem s2) (cslotAddrA cte) c := by pt_nr) : ∃ s3 σ3, obj.Slot.set_cap st (cslotAddrA cte) s2 c = ok s3 ∧ (∃ c', CapEqA c0 c' ∧ (c', σ2) ∈ (Fl4SpecA64.getCap (Z := Unit) cte σ2).1) ∧ ((), σ3) ∈ (Fl4SpecA64.setCap (Z := Unit) sc cte σ2).1 ∧ SpecSlotA σ2 σ3 ∧ @@ -115,7 +118,7 @@ theorem setcap_core2A (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m obtain ⟨s3, σ3, hsc, hσ3, HS, -, J3, T3⟩ := J2.of_setcapA E.sys.ent.os RS.sub (footNOff_ksA hks hcpu (footN_offA E)) (footNAl_ksA hks hcpu (FootNA.aligned E.j.1 hN E.scAl E.ap.vcAl)) cte hab hEnc hca (hT.keepO hk) (fun y hy hn => by rw [hk.capA hy]; exact hnul y hy hn) hcn - (by rw [e0]; exact hc0) (by rw [e0]; exact hua) hok + (by rw [e0]; exact hc0) (by rw [e0]; exact hua) hok hptc hrt hptw exact ⟨s3, σ3, hsc, ⟨c', hc', hg⟩, hσ3, HS, J3, T3⟩ @@ -349,7 +352,7 @@ theorem JStage3A.frameUnmapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : H (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 := .Frame fp sz rt dev false false 0#u64 0#u64) (by rw [c1]; exact .frame ..) hok hirq hsci + (c := .Frame fp sz rt dev false false 0#u64 0#u64) (by rw [c1]; exact .frame ..) hok hirq hsci (PtSrcA.nopt fun _ _ _ _ h => by cases h) (fun s2 σ2 hs2 hσ2 HSs w jx hcx => by have hS1' : Fl4SpecA64.asidRootKind (stUpdA σ σ.curThread x .restart) (BitVec.ofNat 16 asid.val) = none ∨ Fl4SpecA64.asidRootKind (stUpdA σ σ.curThread x .restart) (BitVec.ofNat 16 asid.val) = some .stage1 := by @@ -362,7 +365,7 @@ theorem JStage3A.frameUnmapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : H (fun q hq => (hTO q hq).of_ksA hks hcpu) E1.sys.ent.os hpOS hU obtain ⟨s3, σ3, hsc, ⟨_, heq', hg⟩, hσ3, HSu, J3, T3⟩ := setcap_core2A E0 RS J2 (hOS1.trans' hk2) (hks2.trans hks) (hcpu2.trans hcpu) 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 + (fun h => by cases h) (fun h => by cases h) hTr0 hnul0 (PtSrcA.nopt fun _ _ _ _ h => by cases h) rw [← heq'] at hg obtain ⟨a', hfa', hAR⟩ : ∃ a', fa = ok a' ∧ AR a' Z.hw := by rcases hfa with rfl | rfl diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmXA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmXA.lean index 64509cd87..b903ea716 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmXA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmXA.lean @@ -264,7 +264,7 @@ theorem JStage3A.frameUnmapXA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He (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 := .Frame fp sz rt dev false false 0#u64 0#u64) (by rw [c1]; exact .frame ..) hok hirq hsci + (c := .Frame fp sz rt dev false false 0#u64 0#u64) (by rw [c1]; exact .frame ..) hok hirq hsci (PtSrcA.nopt fun _ _ _ _ h => by cases h) (fun s2 σ2 hs2 hσ2 HSs w jx hcx => by have hk' : isEpt = false → Fl4SpecA64.asidRootKind (stUpdA σ σ.curThread x .restart) (BitVec.ofNat 16 asid.val) = some k ∧ k ≠ .stage1 := fun he' => by @@ -277,7 +277,7 @@ theorem JStage3A.frameUnmapXA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He (hEO.of_ksA hks hcpu) E1.sys.ent.os hpOS hU obtain ⟨s3, σ3, hsc, -, hσ3, HSu, J3, T3⟩ := setcap_core2A E0 RS J2 (hOS1.trans' hk2) (hks2.trans hks) (hcpu2.trans hcpu) 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 + (fun h => by cases h) (fun h => by cases h) hTr0 hnul0 (PtSrcA.nopt fun _ _ _ _ h => by cases h) obtain ⟨a', hfa', hAR⟩ := spec_ex_fd (hfl.arA K J3.1.ar) have J3' := J3.of_arA hAR have hdec' : vspace.decode_frame st ar s a fl4_abi.label.ARMPageUnmap length (cslotAddrA cte) diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmZA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmZA.lean index 8c1dbe05f..7a23aaf1b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmZA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmFrUnmZA.lean @@ -117,7 +117,7 @@ theorem JStage3A.frameClearZA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He obtain ⟨s2, σ2, hs2, hσ2, HSsk, -, J2⟩ := J1.of_capFrame (hpt := fun _ _ _ h => by cases h) 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 := .Frame fp sz rt dev false false 0#u64 0#u64) (by rw [c1]; exact .frame ..) hok hirq hsci + (c := .Frame fp sz rt dev false false 0#u64 0#u64) (by rw [c1]; exact .frame ..) hok hirq hsci (PtSrcA.nopt fun _ _ _ _ h => by cases h) (fun s2 σ2 hs2 hσ2 HS w jx hc2 => by obtain ⟨hsl, hsy, hj7⟩ := fin x s2 σ2 hk hs2 hσ2 obtain ⟨hcx, hco⟩ := capA_setCapA hO hx hEnc hs2 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPoolA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPoolA.lean new file mode 100644 index 000000000..d80ff584b --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPoolA.lean @@ -0,0 +1,226 @@ +/- +P3 (aarch64, Stage 5, line pool, D2): **the `ARMASIDControlMakePool` arm** at `syscall.decode_invocation`. + +* `poolPerform_lmA`: every outcome of the spec's MakePool perform keeps `lastMachineTime` (the one `BodyKeepA` field the + exposed footprint does not carry): `freeMemory` is a run of `storeWord`s, the rest are slot/CDT/heap writes. +* `decodePoolRunA`: FL4's label-58 decode, on the success path (both extra caps, two message words, the untyped, a free + table index, no CDT children, an empty destination), is exactly `makePool_perform_dropA`'s five-step block. +* **`JStage3A.asidMakePoolA`**: the decode, then `makePool_recordA`: the whole record at the grown sets `Zn`, the dropped + view `dropMA D m`, `BodyKeepA` of the spec step. + +Named premises: those of `makePool_recordA` (`hnvm`, `hCp hCd` [W], `hdr` [W], `Fin` [P] = A64 P1's end state until the +pool-End line lands) and the decode-site facts below ([W]). New module. +-/ +import Fl4ProofsA64.P3.Stage3PoolTopA +import Fl4ProofsA64.P3.Stage3PoolFinA +import Fl4ProofsA64.P3.UtRtLastA +import Fl4ProofsA64.P3.Stage3SendBudgetA +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 + +theorem ut_freeMemory_lmA (ptr : Word) (bits : Nat) : UtMopLA (freeMemory ptr bits) := by + unfold freeMemory + generalize uptoEnumStep ptr (ptr + BitVec.ofNat 64 wordSize) (ptr + 2 ^ bits - 1) = xs + induction xs with + | nil => intro ms r hr; obtain rfl : r = ((), ms) := hr; rfl + | cons p xs ih => + intro ms r hr + unfold NonDet.mapMx at hr + obtain ⟨x, hx, hr⟩ := hr + exact (ih _ r hr).trans (storeWord_lmtA p 0 ms x hx) + +theorem ut_deleteObjects_lmA (ptr : Word) (bits : Nat) : UtLA (deleteObjects (Z := Unit) ptr bits) := by + unfold deleteObjects + exact UtLA.bind (ut_doMachineOp_lmA (ut_freeMemory_lmA ptr bits)) fun _ => ut_modify_lmA fun _ => rfl + +theorem ut_retypeRegion_lmA (ptr : ObjRef) (n bits : Nat) (t : ApiObjectType) (dev : Bool) : + UtLA (retypeRegion (Z := Unit) ptr n bits t dev) := by + unfold retypeRegion + refine UtLA.bind (UtLA.pure _) fun _ => UtLA.bind (UtLA.pure _) fun _ => UtLA.bind ?_ fun _ => UtLA.pure _ + unfold NonDet.when + split_ifs + · exact UtLA.bind (UtLA.gets _) fun _ => UtLA.bind (UtLA.gets _) fun _ => UtLA.bind (UtLA.pure _) fun _ => + ut_modify_lmA fun _ => rfl + · exact UtLA.pure _ + +theorem ut_capInsert_lmA (newCap : Cap) (src dst : CslotPtr) : UtLA (capInsert (Z := Unit) newCap src dst) := by + unfold capInsert + refine UtLA.bind (ut_getCap_lmA _) fun _ => UtLA.bind (UtLA.pure _) fun _ => UtLA.bind (ut_getCap_lmA _) fun _ => + UtLA.bind (UtLA.assert _) fun _ => UtLA.bind ?_ fun _ => UtLA.bind (ut_setCap_lmA _ _) fun _ => + UtLA.bind (UtLA.gets _) fun _ => UtLA.bind (UtLA.pure _) fun _ => UtLA.bind (UtLA.gets _) fun _ => + UtLA.bind (UtLA.gets _) fun _ => UtLA.bind ?_ fun _ => UtLA.bind (ut_doExtendedOp_lmA _) fun _ => + ut_setOriginal_lmA _ _ + · unfold setUntypedCapAsFull + split_ifs + · exact ut_setCap_lmA _ _ + · exact UtLA.pure _ + · unfold updateCdt + exact UtLA.bind (UtLA.gets _) fun _ => ut_setCdt_lmA _ + +/-- **MakePool's perform keeps the last machine time.** -/ +theorem poolPerform_lmA {σ1 σ' : State Unit} {rv : List Data} {frame : U64} {dest parent : CslotPtr} {base : Asid} + (h : (.ok rv, σ') ∈ ((fl4ArchPerformInvocation (Z := Unit) + (.spec (.invokeASIDControl (.makePool (specPtr frame) dest parent base)))).run σ1).1) : + σ'.machineState.lastMachineTime = σ1.machineState.lastMachineTime := by + unfold fl4ArchPerformInvocation archPerformInvocation archNoReturn at h + obtain ⟨x, hx, hr⟩ := mem_bindA.1 (mem_liftE_invA h) + have key : UtLA (performAsidControlInvocation (Z := Unit) (.makePool (specPtr frame) dest parent base)) := by + unfold performAsidControlInvocation + refine UtLA.bind (ut_deleteObjects_lmA _ _) fun _ => UtLA.bind (ut_getCap_lmA _) fun _ => + UtLA.bind (ut_setCap_lmA _ _) fun _ => UtLA.bind (ut_retypeRegion_lmA _ _ _ _ _) fun _ => + UtLA.bind (ut_capInsert_lmA _ _ _) fun _ => UtLA.bind (UtLA.assert _) fun _ => UtLA.bind (UtLA.gets _) fun _ => + UtLA.bind (UtLA.pure _) fun _ => ut_modify_lmA fun _ => rfl + have e : σ' = x.2 := congrArg Prod.snd hr + rw [e] + exact key σ1 x hx + + +/-- MakePool's perform returns no data (`archNoReturn`). -/ +theorem poolPerform_rvA {σ1 σ' : State Unit} {rv : List Data} {frame : U64} {dest parent : CslotPtr} {base : Asid} + (h : (.ok rv, σ') ∈ ((fl4ArchPerformInvocation (Z := Unit) + (.spec (.invokeASIDControl (.makePool (specPtr frame) dest parent base)))).run σ1).1) : rv = [] := by + unfold fl4ArchPerformInvocation archPerformInvocation archNoReturn at h + obtain ⟨x, hx, hr⟩ := mem_bindA.1 (mem_liftE_invA h) + exact congrArg Prod.fst hr + +section dec +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +theorem poolExtra01A {ex : Aeneas.Std.Array obj.Slot 3#usize} : + vspace.extra ex 0#usize = ok (if exAtA ex 0 = 0#u64 then none else some (exAtA ex 0)) ∧ + vspace.extra ex 1#usize = ok (if exAtA ex 1 = 0#u64 then none else some (exAtA ex 1)) := by + constructor + · exact extra0_eqA (exAtA_idx0 ex) + · unfold vspace.extra obj.Slot.is_null + have hidx : ex.index_usize 1#usize = ok (exAtA ex 1) := exAtA_idx1 ex + simp only [show ¬(1#usize ≥ 3#usize) by decide, ↓reduceIte, hidx, bind_ok] + by_cases h : exAtA ex 1 = 0#u64 <;> simp [h] + +set_option maxHeartbeats 4000000 in +/-- **FL4's label-58 decode on its success path is MakePool's five-step block** (module docstring). -/ +theorem decodePoolRunA {ar : machine.Arch A} (s : S) (a : A) (length buf : U64) (cte : CslotPtr) + (block call cd fp : Bool) (ex : Aeneas.Std.Array obj.Slot 3#usize) + (hx0 : exAtA ex 0 ≠ 0#u64) (hx1 : exAtA ex 1 ≠ 0#u64) (hlen2 : length ≥ 2#u64) {a0 a1 : U64} + (ha0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok a0) (ha1 : msg.syscall_arg st s (L.curW s) buf 1#u64 = ok a1) + {frame fi : U64} (hcu : capA st s (exAtA ex 0) = .Untyped frame 12#u64 fi false) + {i base : U64} (hiOk : vspace.decode_loop0 st s 0#u64 = ok i) (hiLt : i.val < 128) + (hbaseOk : (i <<< vspace.ASID_LOW_BITS : Result U64) = ok base) + (hnc : cdt.ensure_no_children st s (exAtA ex 0) = ok (core.result.Result.Ok ())) + {dst : U64} (hlt : cspace.lookup_slot_for_cnode_op st s false (capA st s (exAtA ex 1)) a0 a1 = + ok (core.result.Result.Ok dst)) + (hcd : capA st s dst = .Null) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMASIDControlMakePool length (cslotAddrA cte) .AsidControl + block call cd fp buf ex = + (do + let s1 ← sched.set_thread_state st s (L.curW s) sched.TS_RESTART + let s2 ← obj.Slot.set_cap st (exAtA ex 0) s1 (.Untyped frame 12#u64 4096#u64 false) + let s3 ← st.clear_free s2 frame 4096#u64 + let s4 ← cdt.insert st s3 (.AsidPool frame base) (exAtA ex 0) dst + let s5 ← vspace.set_asid_table st s4 i frame + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s5, a)) := by + have hfull : i ≠ 128#u64 := fun e => by have := congrArg UScalar.val e; simp at this; omega + have hsz : (12#u64 : U64) = fl4_abi.consts.bits.ASID_POOL := + UScalar.eq_of_val_eq (by simp [fl4_abi.consts.bits.ASID_POOL]) + unfold syscall.decode_invocation vspace.decode + rw [cur_thread_ok, bind_ok] + simp only [bne_self_eq_false, Bool.false_eq_true, ↓reduceIte, poolExtra01A.1, poolExtra01A.2, bind_ok] + rw [if_neg hx0]; dsimp only + rw [if_neg hx1]; dsimp only + rw [if_pos hlen2, ha0, bind_ok, ha1, bind_ok, capA_eq, bind_ok, capA_eq, bind_ok, hiOk, bind_ok] + unfold vspace.N_ASID_POOLS + have h128 : (1#u64 <<< fl4_abi.consts.bits.NUM_ASID_POOLS : Result U64) = ok 128#u64 := by + apply eq_of_spec_fd; unfold fl4_abi.consts.bits.NUM_ASID_POOLS; step* + rw [h128, bind_ok, if_neg hfull, hbaseOk, bind_ok, hcu] + simp only [Bool.false_eq_true, ↓reduceIte] + rw [if_pos hsz] + rw [hnc, bind_ok] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + rw [show cspace.lookup_target_slot st s (capA st s (exAtA ex 1)) a0 a1 = + cspace.lookup_slot_for_cnode_op st s false (capA st s (exAtA ex 1)) a0 a1 from rfl, hlt, bind_ok] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + unfold cdt.ensure_empty_slot + rw [capA_eq, bind_ok, hcd, cap_is_null_nullA] + simp only [bind_ok, ↓reduceIte, core.result.Result.Insts.CoreOpsTry.branch] + have hsh12 : (1#u64 <<< (12#u64 &&& 63#u64)) ⦃ w => w = 4096#u64 ⦄ := by + step as ⟨w, hw⟩; apply UScalar.eq_of_val_eq; simpa [U64.size, U64.numBits] using hw + simp only [lift, bind_ok, eq_of_spec_fd hsh12] + + +end dec + +section arm +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +set_option maxHeartbeats 4000000 in +/-- **The MakePool arm at `syscall.decode_invocation`** (module docstring): the success-path decode facts, then +`makePool_recordA`. `hpa`/`hda` identify the spec slots with the decoded addresses. -/ +theorem JStage3A.asidMakePoolA {ar : machine.Arch A} {nA : 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 × Word)} + {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {s : S} {a : A} {σ : State Unit} {m : McState} + [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] + (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) + (hT : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s)) + (hYAs : ∀ y ∈ Z.Y, ∀ j : U64, j.val < 512 → ¬ AsW (L.ksb s) (peAF y j)) + (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) + {parent dest : CslotPtr} {frame fi i base : U64} + (hAp : AbsSlotA Z.th parent) (hAd : AbsSlotA Z.th dest) + (hdc : ∃ y ∈ OS, ∃ q r gs g : U64, capA st s y = .CNode q r gs g ∧ dest.1 = specPtr q) + {Ud Acd Rq Nt : Set U64} {ex : Aeneas.Std.Array obj.Slot 3#usize} + (Dp : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ud Acd s + (.Untyped frame 12#u64 fi false) ex) + (P : SysPlace st H Z.Cs H.frame Rq Nt OS s ex (cslotAddrA parent)) + (othT : ∀ c ∈ Z.Cs, c ≠ L.cpu s → + specPtr (L.mem s (L.nodeAt s c layout.node.CUR_THREAD)) ∉ utDA frame 12) + (othC : ∀ c ∈ Z.Cs, c ≠ L.cpu s → specPtr (L.mem s (L.nodeAt s c layout.node.CUR_SC)) ∉ utDA frame 12) + (hn : nA.val = fl4A64Platform.s2IpaBits) (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hCp : ∃ pp, parent.1 = specPtr pp ∧ Z.th pp = some (.cnode parent.2.length)) + (hCd : ∃ pd, dest.1 = specPtr pd ∧ Z.th pd = some (.cnode dest.2.length)) (hdr : dest.2.length ≠ 0) + -- the decode site + (length buf : U64) (cte : CslotPtr) (block call cd fp : Bool) + {Ud0 Acd0 : Set U64} (D0 : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ud0 Acd0 s .AsidControl ex) + (P0 : SysPlace st H Z.Cs H.frame H.replies H.ntfns OS s ex (cslotAddrA cte)) + (hSC : ∀ x ∈ ex.val, x ≠ 0#u64 → SlotCov st OS s x) + (hx0 : exAtA ex 0 ≠ 0#u64) (hx1 : exAtA ex 1 ≠ 0#u64) (hlen2 : length ≥ 2#u64) {a0 a1 : U64} + (ha0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok a0) (ha1 : msg.syscall_arg st s (L.curW s) buf 1#u64 = ok a1) + (hpa : cslotAddrA parent = exAtA ex 0) (hcp : capA st s (cslotAddrA parent) = .Untyped frame 12#u64 fi false) + (hnc : cdt.ensure_no_children st s (cslotAddrA parent) = ok (core.result.Result.Ok ())) + (hiOk : vspace.decode_loop0 st s 0#u64 = ok i) (hi : i.val < 128) (hfree : L.mem s (atAF (L.ksb s) i) = 0#u64) + (hbaseOk : (i <<< vspace.ASID_LOW_BITS : Result U64) = ok base) (hbase : base.val = i.val * 512) + (hlt : cspace.lookup_slot_for_cnode_op st s false (capA st s (exAtA ex 1)) a0 a1 = + ok (core.result.Result.Ok (cslotAddrA dest))) + (hcd : capA st s (cslotAddrA dest) = .Null) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMASIDControlMakePool length (cslotAddrA cte) .AsidControl + block call cd fp buf ex ⦃ res => PoolRecPostA st ar nA AR Z H OS U Pp Tb Lv ia ie N E Rp Bf stack κ n a σ m + parent dest frame base res ⦄ := by + have hdec : syscall.decode_invocation st ar s a fl4_abi.label.ARMASIDControlMakePool length (cslotAddrA cte) + .AsidControl block call cd fp buf ex = (do + let s1 ← sched.set_thread_state st s (L.curW s) sched.TS_RESTART + let s2 ← obj.Slot.set_cap st (cslotAddrA parent) s1 (.Untyped frame 12#u64 4096#u64 false) + let s3 ← st.clear_free s2 frame 4096#u64 + let s4 ← cdt.insert st s3 (.AsidPool frame base) (cslotAddrA parent) (cslotAddrA dest) + let s5 ← vspace.set_asid_table st s4 i frame + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s5, a)) := by + have hcu : capA st s (exAtA ex 0) = .Untyped frame 12#u64 fi false := by rw [← hpa]; exact hcp + have hnc' : cdt.ensure_no_children st s (exAtA ex 0) = ok (core.result.Result.Ok ()) := by rw [← hpa]; exact hnc + have e := decodePoolRunA (ar := ar) s a length buf cte block call cd fp ex hx0 hx1 hlen2 ha0 ha1 hcu hiOk hi hbaseOk + hnc' hlt hcd + rw [← hpa] at e + exact e + rw [hdec] + exact makePool_recordA J RS hT hYAs hcO hAp hAd hcp hnc hcd hi hfree hbase hdc Dp P othT othC hn hnvm hCp hCd hdr + (fun _ _ _ h => poolPerform_lmA h) + (fun s5 σ1 σ' Zn Jd C hr5 => poolFinA (block := block) (call := call) (cd := cd) (fp := fp) J Jd C RS D0 P0 hSC (hdec.trans hr5) rfl) + +end arm + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapA.lean index 23dd5557f..f84852abb 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapA.lean @@ -17,6 +17,7 @@ covered here. No named premise. New module. -/ +import Fl4ProofsA64.P3.VsUniqAssignA import Fl4ProofsA64.P3.Stage3BodyKeepA import Fl4ProofsA64.P3.Stage3PtMapShapeA import Fl4ProofsA64.P3.Stage3ArmAssignA @@ -241,7 +242,7 @@ theorem JStage3A.ptMapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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 hSh := pt_map_shapeA (L := L) (extra := extra) ar E0 RS cte hab hx hcap UP slbl hl length buf args hlen hargs + have hSh := pt_map_shapeA (L := L) (extra := extra) ar E0 RS cte hab hx hcap J.ptCapIn UP slbl hl length buf args hlen hargs x0 hx0 exs hex hS1 hHi rw [hdec, WP.spec_ok] at hSh obtain ⟨ha, iv, hD, x', s2, σ2, asid1, va, p, i, v, nL, σp, σ', wv, hk', hset', hsc, hσ2, HSs, hEnc, hca, hks2, hcpu2, @@ -358,7 +359,7 @@ theorem JStage3A.ptMapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (some (asidOfA asid1, wv)))) := ⟨fun _ _ e => (by cases e), fun _ e => (by cases e), fun _ _ _ e => by cases e; exact fun h => absurd hwlt (not_lt.2 h.1)⟩ - have main := JStage3A.of_capVsFrameGA (J := J1) + have main := JStage3A.of_capVsFrameGA (J := J1) (hptw := Or.inl (PtSetA.map (show capAtA (L.mem s1) (cslotAddrA cte) = .PageTable ptr false asid0 va0 from c1))) (hS := fun q0 hq => by refine ⟨Set.mem_insert_of_mem _ hq.1, ?_⟩ by_cases e : q0 = ptr @@ -372,8 +373,8 @@ theorem JStage3A.ptMapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (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 p i) v ∧ a' = a3 ∧ σ'' = σ' ∧ 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) hM hok hirq hsci - (fun s2' σ2' hs2 hσ2' HSs' wc jx hcx => by + cte hab hEnc hca hTr hnul (fun h => by cases h) (by rw [c1]; exact fun h => by cases h) hM hok hirq hsci (Pj := True) (fun _ _ _ _ _ e => by cases e; exact Or.inr (Or.inl ⟨UP.nt, fun h => hS2 (Or.inl h)⟩)) + (fun s2' σ2' hs2 hσ2' HSs' wc jxP hst2 hcx => by have es : s2' = s2 := okinj (hs2.symm.trans hsc) subst es have eσ : σ2' = σ2 := setCap_detA hσ2' hσ2 @@ -556,7 +557,7 @@ theorem JStage3A.ptMapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} show (ptSetA σ2' (specPtr p) t').kheap q0 = _ rw [ptSetA_kheap, if_neg hne] exact h - · exact BufCover.vsA (BufCover.mapA J1.bufCover J1.bufNative J1.j.1.st jx.1.st + · exact BufCover.vsA (BufCover.mapA J1.bufCover J1.bufNative J1.j.1.st hst2 (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 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapHiA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapHiA.lean index d1bcdc0dd..c95c0893b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapHiA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapHiA.lean @@ -202,7 +202,10 @@ theorem JStage3A.ptMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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⟩ => ?_ + obtain ⟨hwb0, hwb1, hwtab⟩ := E0.j.1.ext.wl0 vp hrootY + refine WP.spec_bind (spec_andA (lookup_pt_slot_hiA E0.j.1.vs E0.j.1.ext hrootY hactY (hi_idx39_eq_pt vaddr hlo)) + (lookup_walk_hiA E0.j.1.vs hrootY hactY ((and3_bitsA _).2 ⟨hwb0, hwb1⟩) hwtab vaddr + (hi_idx39_eq_pt vaddr hlo))) fun lu ⟨⟨hlsh, hslR⟩, hwalkF⟩ => ?_ 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 @@ -270,7 +273,7 @@ theorem JStage3A.ptMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (.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 + restart_setcapJA E0 RS cte hab hx hEnc hca (hpt := Or.inl (PtSetA.map hcap)) 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 @@ -291,9 +294,10 @@ theorem JStage3A.ptMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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) + (by rw [hco]; exact ⟨rfl, rfl, rfl, rfl, 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), trivial⟩ + (fun _ _ _ _ e => by cases e; exact Or.inr (Or.inl ⟨UP.nt, fun h => hS2 (Or.inl h)⟩)) 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 @@ -444,6 +448,69 @@ theorem JStage3A.ptMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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 + (by + have hsubOS : ∀ y, IsSlotA Z.th y → y ∈ OS := by + obtain ⟨⟨Rp, Nt, extra', sp, P⟩, Y', hrun, hcur, hvs, hvc, hsub⟩ := RS; exact hsub + have hfr := restart_memkeepA (OS := OS) 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)) hw2 + obtain ⟨raw, hactA, htag2, hun⟩ := activeHiAsidRootA E0.j.1.vs hX hrootY + (vspaceForAsid_of_checkExtRootA (by decide) hchkOk) (by have := ha16; omega) + have hbase' : ∀ k, lu.shift.val ≤ k → walkIdx base k 512 = walkIdx vaddr k 512 := fun k hk => by + rw [← hbase]; exact walkIdx_baseA vaddr lu.shift.val k hk + have hwk := hwalkF base hbase' + have hpal : ptr.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd UP.al + have hW' := hW + rcases hsl with ⟨t, i, ⟨ht, h1t, hst⟩, hi, hluEq, hslEq⟩ | ⟨y, j, hy, hj, hluEq, hslEq, hshEq⟩ + · rw [hluEq] at hW' hwk hvf ⊢ + have hbal : Aligned (peAF t i) := peAF_alignedA (E0.j.1.vs.al_mod ht) hi + refine linkVsuA (p := t) (i := i) (v := ew) E0.j.1.vs E0.ap.vs hfr J2 hksb2 hfa2 hsubOS E0.sys.ent.os + hFr2 J.ptCapIn UP.nt (fun h => hS2 (Or.inl h)) hpal UP.ytb UP.inv (fun i hi => hmem2 i hi) (Or.inl ht) hi + ((E0.ap.vs _ (.pt t i ht hi)).1) ?_ hvf + ⟨raw, hactA, Or.inr ⟨htag2, hun ▸ hrootY, by rw [hun]; exact hwk⟩⟩ hW'.1 ?_ ?_ hdTab ?_ + · intro b hb heq + rcases hb with hb | hb + · exact extFoot_ne_vsA J2.1.ext J2.1.vs.yal (Or.inr (Or.inl ht)) (J2.1.vs.al t ht) hi hb heq + · exact (hTO2 t ht).mem i hi (heq ▸ AsidWordsA.foot (L := L) (Z := Z) (s := s2) + (by rw [hksb2]; exact hb)) + · intro w hw hne; rw [hW'.2.2 w hw, if_neg (Ne.symm hne)] + · rw [hW'.2.2 _ hbal, if_pos rfl] + · refine ⟨rfl, fun q hq => ?_⟩ + rw [hslEq] + refine kheap_writeX ?_ + rw [slotObjPtE (J2.1.vs.al_mod ht) hi] + intro e + have := specPtr_inj e + subst this + obtain ⟨_, h1, -⟩ := J2.1.vs.pool q hq + obtain ⟨_, h2, -⟩ := J2.1.vs.pt q ht + rw [h1] at h2; cases h2 + · rw [hluEq] at hW' hwk hvf ⊢ + have hbal : Aligned (peAF (wa y 4096#u64) j) := peAF_alignedA (waWin_modA (J2.1.vs.yal y hy)) hj + refine linkVsuA (p := wa y 4096#u64) (i := j) (v := ew) E0.j.1.vs E0.ap.vs hfr J2 hksb2 hfa2 hsubOS + E0.sys.ent.os hFr2 J.ptCapIn UP.nt (fun h => hS2 (Or.inl h)) hpal UP.ytb UP.inv (fun i hi => hmem2 i hi) + (Or.inr ⟨y, hy, rfl⟩) hj ((E0.ap.vs _ (.high y j hy hj)).1) ?_ hvf + ⟨raw, hactA, Or.inr ⟨htag2, hun ▸ hrootY, by rw [hun]; exact hwk⟩⟩ hW'.1 ?_ ?_ hdTab ?_ + · intro b hb heq + rcases hb with hb | hb + · exact extFoot_ne_vsA J2.1.ext 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 hb heq + · have F : FootA (L := L) (extZA Z) s2 b := AsidWordsA.foot (L := L) + (Z := extZA Z) (s := s2) (by rw [hksb2]; exact hb) + rw [heq] at F + exact hEO2.mem (wa y 4096#u64) (Or.inr ⟨y, hy, rfl⟩) j hj F + · intro w hw hne; rw [hW'.2.2 w hw, if_neg (Ne.symm hne)] + · rw [hW'.2.2 _ hbal, if_pos rfl] + · refine ⟨rfl, fun q hq => ?_⟩ + rw [hslEq] + refine kheap_writeX ?_ + intro e + have e' : specPtr q = specPtr y := e + have := specPtr_inj e' + subst this + obtain ⟨_, h1, -⟩ := J2.1.vs.pool q hq + obtain ⟨_, h2, -⟩ := J2.1.vs.high q hy + rw [h1] at h2; cases h2) 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 @@ -583,7 +650,7 @@ theorem JStage3A.ptMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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) + have main := JStage3A.of_capVsFrameGA (J := J1) (hptw := Or.inl (PtSetA.map (show capAtA (L.mem s1) (cslotAddrA cte) = .PageTable ptr false asid0 va0 from c1))) (hS := fun q0 hq0 => by refine ⟨Set.mem_insert_of_mem _ hq0.1, ?_⟩ by_cases e : q0 = ptr @@ -597,8 +664,8 @@ theorem JStage3A.ptMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (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 + cte hab hEnc hca hTr1 hnul1 (fun h => by cases h) (by rw [c1]; exact fun h => by cases h) hM hok hirq hsci (Pj := True) (fun _ _ _ _ _ e => by cases e; exact Or.inr (Or.inl ⟨UP.nt, fun h => hS2 (Or.inl h)⟩)) + (fun s2' σ2' hs2 hσ2' HSs' wc jxP hst2 hcx => by have es : s2' = s2 := okinj (hs2.symm.trans hsc) subst es have eσ : σ2' = σ2 := setCap_detA hσ2' hσ2 @@ -710,7 +777,7 @@ theorem JStage3A.ptMapHiA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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 + · exact BufCover.vsA (BufCover.mapA J1.bufCover J1.bufNative J1.j.1.st hst2 (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 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapS2A.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapS2A.lean index 3f401e033..b6464093a 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapS2A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtMapS2A.lean @@ -278,7 +278,8 @@ theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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 + have hrootA : S2RootOfAsidA Z.Pp Z.X σ vasid vp := s2RootOfAsidA_of_vspaceForAsid E0.j.1.vs hrootX hvs + have hactR : ActiveS2RootA Z.Pp Z.X σ vp := hrootA.active 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) @@ -320,6 +321,8 @@ theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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 hwk := lookup_walk_s2A E0.j.1.ext hrootX hactR hnvIpa vaddr + rw [hlu, WP.spec_ok] at hwk 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] @@ -381,7 +384,7 @@ theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (.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 + restart_setcapJA E0 RS cte hab hx hEnc hca (hpt := Or.inl (PtSetA.map hcap)) 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 @@ -402,9 +405,10 @@ theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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) + (by rw [hco]; exact ⟨rfl, rfl, rfl, rfl, 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), trivial⟩ + (fun _ _ _ _ e => by cases e; exact Or.inr (Or.inl ⟨UP.nt, fun h => hS2 (Or.inl h)⟩)) 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 @@ -547,6 +551,14 @@ theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} · 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 + have hVU := by + have hfr := restart_memkeepA (OS := OS) 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)) hw2 + have hP02 := poolKeepA_stUpd (s := s) hkx HS E0.j.1.vs + exact s2MapVsuA (tcbs := H.tcbs) J2 hksb2 hfa2 RS.sub E0.sys.ent.os hFr2 J.ptCapIn (hab.isSlot E0.j.1.place) + hS2 hY UP.nt (Nat.mod_eq_zero_of_dvd UP.al) UP.inv (fun i hi => hmem2 i hi) E0.ap.vs E0.ap.ext hfr hT hsl hvf hW + hdTab (hrootA.of_spec hP02.1 hP02.2) (hwk _ (agreeWA_baseU vaddr base hbase)) 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) := @@ -586,7 +598,8 @@ theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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 }, ?_, ?_, ?_⟩ + ext := hER3 + vsu := hVU }, ?_, ?_, ?_⟩ · 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'' @@ -746,7 +759,7 @@ theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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) + have main := JStage3A.of_capVsFrameGA (J := J1) (hptw := Or.inl (PtSetA.map (show capAtA (L.mem s1) (cslotAddrA cte) = .PageTable ptr false asid0 va0 from c1))) (hS := fun _ h => h) (hT2 := fun _ _ _ _ _ _ _ h => Set.mem_insert_of_mem _ h) (hpt := fun q0 _ _ h => by @@ -756,8 +769,8 @@ theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (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 + cte hab hEnc hca hTr1 hnul1 (fun h => by cases h) (by rw [c1]; exact fun h => by cases h) hM hok hirq hsci (Pj := True) (fun _ _ _ _ _ e => by cases e; exact Or.inr (Or.inl ⟨UP.nt, fun h => hS2 (Or.inl h)⟩)) + (fun s2' σ2' hs2 hσ2' HSs' wc jxP hst2 hcx => by have es : s2' = s2 := okinj (hs2.symm.trans hsc) subst es have eσ : σ2' = σ2 := setCap_detA hσ2' hσ2 @@ -855,7 +868,7 @@ theorem JStage3A.ptMapS2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (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 + · exact BufCover.vsA (BufCover.mapA J1.bufCover J1.bufNative J1.j.1.st hst2 (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 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmMA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmMA.lean index bffc91eb8..ff9a2bde4 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmMA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmMA.lean @@ -286,6 +286,7 @@ theorem JStage3A.ptUnmapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap (hpS : ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr) (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) (fin : ∀ (x : Fl4SpecA64.Tcb) (s3 : S) (σ3 : Fl4SpecA64.State Unit) (a' : A), @@ -374,7 +375,10 @@ theorem JStage3A.ptUnmapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap .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 + (c := .PageTable ptr false 0#u64 0#u64) + (hptw := PtSetE.unmapHolder (by rw [capAtA_eq]; exact c1) (fun y hy hne mp a v => by + rw [capAtA_eq, hOS1.capA (RS.sub y hy)]; exact hno y (RS.sub y hy) hne mp a v)) + (by rw [c1]; exact .pt ..) hok hirq hsci (PtSrcA.unmPtA (fun h => (J.j.1.ext.pgd ptr (Or.inl h)).1 (Or.inr (Or.inl hpS.1)))) (fun s2 σ2 hs2 hσ2 HSs w jx hcx => by have hS1' : Fl4SpecA64.asidRootKind (stUpdA σ σ.curThread x .restart) (BitVec.ofNat 16 asid.val) = none ∨ Fl4SpecA64.asidRootKind (stUpdA σ σ.curThread x .restart) (BitVec.ofNat 16 asid.val) = some .stage1 := by @@ -411,7 +415,9 @@ theorem JStage3A.ptUnmapS1A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap rw [e'] obtain ⟨s5, σ6, hsc, ⟨c', heq', hg⟩, 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 + (hptw := PtSetE.unmapHolder (by rw [capAtA_eq, ((hOS1.trans' hk2).trans' hk3).capA hx, hcap]) (fun y hy hne mp a v => by + rw [capAtA_eq, ((hOS1.trans' hk2).trans' hk3).capA (RS.sub y hy)]; exact hno y (RS.sub y hy) hne mp a v)) + ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by cases h⟩ hok (fun h => by cases h) (fun h => by cases h) hTr0 hnul0 (PtSrcA.unmPtA (fun h => (E0.j.1.ext.pgd ptr (Or.inl h)).1 (Or.inr (Or.inl hpS.1)))) obtain ⟨asid', va', rfl, _, _⟩ := CapEqA.pt_mapped_iff.mp heq' have hperf := perfPtUnmapN_memA (p := specPtr ptr) (asid := BitVec.ofNat 16 asid.val) (v := va.bv) (cte := cte) (σz := ptSetA σu (specPtr ptr) t') diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmStaleA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmStaleA.lean new file mode 100644 index 000000000..e8b34fecf --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmStaleA.lean @@ -0,0 +1,452 @@ +/- +P3 (AArch64, vsinv RO3): **the stale Stage-2 table unmap shrink** — `JStage3A.ptUnmapT2StaleA`, the `ARMPageTableUnmap` arm +of a final mapped page-table cap of a Stage-2 table `ptr ∈ Z.T2` whose ASID names no Stage-2 root (kind none after +`delete_asid`, or Stage-1). It is `ptUnmapS1A`'s run and spec (the Stage-1 / stale unmap, the cache clean) with +`ptUnmapT2A`'s tail: `T2` shrinks to `T2 \ {ptr}` after the zero and before the cap write (`setcap_core2TA`). +The `hUniq` premise of `ptUnmapT2A` is replaced by `VsUniqA.no_reach_stale` (`P3/VsUniqStaleA`). No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3ArmPtUnmT2A +import Fl4ProofsA64.P3.VsUniqStaleA +import Fl4ProofsA64.P3.Stage3ArmPtUnmMA +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 arm +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +set_option maxHeartbeats 8000000 in +/-- **`JStage3A` across the `ARMPageTableUnmap` arm of a final mapped page-table cap of a Stage-2 table whose ASID names no +Stage-2 root** (`ptr ∈ Z.T2`, kind none after `delete_asid`, or Stage-1): the run is the Stage-1 / stale unmap (a no-op on +the tracked descriptors), the spec performs `pageTableUnmap` (512 invalid `storePte`s, the cache clean, the cap write), +and the record holds at the final state with the ghost `T2` shrunk to `Z.T2 \ {ptr}`. **No named premise**: that no +reachable valid descriptor names `ptr` comes from `VsUniqA.t2` (`VsUniqA.no_reach_stale`). -/ +theorem JStage3A.ptUnmapT2StaleA {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)) + (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) + (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ + Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) + (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') → + ((), σ3) ∈ (Fl4SpecA64.performPageTableInvocation (Z := Unit) (.pageTableUnmap (.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') ∧ + ((), σ3) ∈ (Fl4SpecA64.performPageTableInvocation (Z := Unit) (.pageTableUnmap (.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 + 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) + (hptw := PtSetE.unmapHolder (by rw [capAtA_eq]; exact c1) (fun y hy hne mp a v => hno1 y (RS.sub y hy) hne mp a v)) + (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') ∧ + ((), σ') ∈ (Fl4SpecA64.performPageTableInvocation (Z := Unit) (.pageTableUnmap (.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 (Pj := False) (fun h => h.elim) + (fun s2 σ2 hs2 hσ2 HSs w jxP hst2 hcx => by + have hS1' : Fl4SpecA64.asidRootKind (stUpdA σ σ.curThread x .restart) (BitVec.ofNat 16 asid.val) = none ∨ + Fl4SpecA64.asidRootKind (stUpdA σ σ.curThread x .restart) (BitVec.ofNat 16 asid.val) = some .stage1 := by + rw [asidRootKind_stUpdA hk]; exact hS1 + have hU := unmap_page_tableA (ar := ar) (a := a) E1.j.1.vs (by rw [hks]; exact hK) + (fun p hp i hi => by rw [hks]; exact hT p i hi (Or.inr (Or.inr (Or.inl hp)))) E1.j.2.2.1.obj h16 + (hs1_ofE hS1') va ptr + obtain ⟨s2u, fa, σu, hfa, hu, hσu, J2, hk2, hks2, hcpu2, UQ, hcase⟩ := unmap_post2A + (unmapPageTable_kmA _ _ _) (unmapPageTable_unQ _ _ _) E1.j (FootA.aligned E1.j.1 hN E1.scAl E1.ap.vcAl) + (fun q hq => (hTO q hq).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 UQzz : UnQ (stUpdA σ σ.curThread x .restart) (ptSetA σu (specPtr ptr) t') := UQ.trans UQz + have Q5 : QvA (stUpdA σ σ.curThread x .restart) (ptSetA σu (specPtr ptr) t') := UQzz.1 + have I5 : InvXA (stUpdA σ σ.curThread x .restart) (ptSetA σu (specPtr ptr) t') := UQzz.2.toX + obtain ⟨a', hfa', hAR⟩ : ∃ a', fa = ok a' ∧ AR a' Z.hw := by + rcases hfa with rfl | rfl + · exact ⟨a, rfl, J5.1.ar⟩ + · exact spec_ex_fd (K.invAsid a Z.hw asid J5.1.ar) + obtain ⟨Pt, Ub, vr, -, -, -, -, -, -, link, -, -⟩ := J1.j7 + 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 hzGz : ∀ Pt' : Set U64, (∀ b, VsR (L.ksb s1) Pt' b → Aligned b) → + VsZ st (L.ksb s1) Pt' s1 (L.zr s2u ptr 4096#u64) := fun Pt' hal b hb => by + have hb1 := hal b hb + rcases zr_caseA (st := st) (s := s2u) hp4 hb1 with e | e + · exact Or.inr e + · rw [e] + rcases hcase with rfl | ⟨q, hqS, j, 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 hrelZ : ∀ q, XqA Z q → ∀ j : U64, j.val < 512 → + L.mem (L.zr s2u ptr 4096#u64) (peAF q j) = L.mem s1 (peAF q j) ∨ L.mem (L.zr s2u ptr 4096#u64) (peAF q j) = 0#u64 := fun q hq j hj => + hzGz Pt vr.al _ (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 hs5Z : ∀ q, XqA Z q → ∀ j : U64, j.val < 512 → + L.mem (L.zr s2u ptr 4096#u64) (peAF q j) = 0#u64 ∨ L.mem (L.zr s2u ptr 4096#u64) (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 + exact zr_caseA (st := st) (s := s2u) hp4 hb1 + have hATz : (ptSetA σu (specPtr ptr) t').archState.armAsidTable = σ.archState.armAsidTable := by + exact Q5.asidTable + have hpoolZ : ∀ (p : U64) f, (ptSetA σu (specPtr ptr) t').kheap (specPtr p) = some (.archObj (.asidPool f)) → + σ.kheap (specPtr p) = some (.archObj (.asidPool f)) := fun p f hk6 => by + have h1 := hk6 + 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 hActZ : ∀ r, ActiveS2RootA Z.Pp Z.X (ptSetA σu (specPtr ptr) t') 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 [← hATz]; exact ht, hpoolZ p f hk6, hf'⟩ + have hMqZ : ∀ q ∈ S2PgE Z.X Z.T2, ∀ j : U64, j.val < 512 → L.mem (L.zr s2u ptr 4096#u64) (peAF q j) ≠ 0#u64 → + L.mem s1 (peAF q j) = L.mem (L.zr s2u ptr 4096#u64) (peAF q j) := fun q hq j hj hne => by + rcases hrelZ 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 hno5Z : ∀ w, S2EntryA Z.Pp Z.X (Z.T2 \ {ptr}) Z.Sh2 (L.mem (L.zr s2u ptr 4096#u64)) (ptSetA σu (specPtr ptr) t') w → + dBitA (L.mem (L.zr s2u ptr 4096#u64) w) 0 = true → dBitA (L.mem (L.zr s2u ptr 4096#u64) w) 1 = true → dTabA (L.mem (L.zr s2u ptr 4096#u64) w) ≠ ptr := by + intro w hw hb0 hb1' hn + have M5ne : L.mem (L.zr s2u ptr 4096#u64) 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, hActZ 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 hActZ (fun q hq j hj hne => hMqZ q hq j hj hne) hreach + obtain ⟨q, j, hXq, hj, hwq, hent⟩ := key + have M5q : L.mem (L.zr s2u ptr 4096#u64) (peAF q j) ≠ 0#u64 := by rw [← hwq]; exact M5ne + have e1 : L.mem s1 w = L.mem (L.zr s2u ptr 4096#u64) w := by rw [hwq]; exact hMqZ q hXq j hj M5q + have hentS : S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem s1) (stUpdA σ σ.curThread x .restart) w := + S2EntryA.of_frame (Y := Z.Y) (σ' := σ) (σ := stUpdA σ σ.curThread x .restart) J1.j.1.ext.xal (fun _ _ => rfl) rfl + (fun p hp => by + obtain ⟨g, hkg, -⟩ := J.j.1.vs.pool p hp + have hn' : specPtr p ≠ σ.curThread := fun e => by rw [e, hk] at hkg; cases hkg + simp [stUpdA, setObjA, Function.update_of_ne hn']) hent + have hsl : IsSlotA Z.th (cslotAddrA cte) := hab.isSlot J1.j.1.place + exact absurd (by rw [e1]; exact hn) (VsUniqA.no_reach_stale J1.j.1.vsu J1.j.1.ext hsl + (show capAtA (L.mem s1) (cslotAddrA cte) = .PageTable ptr true asid va from c1) hpT hS1' w hentS + (by rw [e1]; exact (and3_bits_sh _).2 ⟨hb0, hb1'⟩)) + have ER' := ExtVsRelA.shrinkT2E J5.1.ext hno5Z + have J4s := J5.shrinkT2A hT' ER' + obtain ⟨-, ⟨⟨⟨⟩, σ5⟩, h5⟩, h5m⟩ := doMachineOp_okA (mop := Fl4SpecA64.cleanCacheRange_PoU (specPtr ptr) + (specPtr ptr + Fl4SpecA64.mask (Fl4SpecA64.ptBits .normalPtT)) (Fl4SpecA64.addrFromPPtr (specPtr ptr))) + (machineOpLift_okA _) (ptSetA σu (specPtr ptr) t') + have hm5 := h5m _ h5 + have J5' := J4s.of_msA (σ' := σ5) hm5 + have UQc : UnQ (ptSetA σu (specPtr ptr) t') σ5 := doMachineOp_unQ _ _ ((), σ5) h5 + have UQ5 : UnQ (stUpdA σ σ.curThread x .restart) σ5 := UQ.trans (UQz.trans UQc) + have Q5m : QvA (stUpdA σ σ.curThread x .restart) σ5 := UQ5.1 + have I5m : InvXA (stUpdA σ σ.curThread x .restart) σ5 := UQ5.2.toX + have hk5 : (σ5.kheap : _) = (ptSetA σu (specPtr ptr) t').kheap := by + obtain ⟨ms, e⟩ := hm5 + have e' : σ5 = _ := e + rw [e'] + have hok' : CapObjOkA { Z with T2 := Z.T2 \ {ptr} } (.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⟩ + obtain ⟨s5, σ6, hsc, ⟨c', heq', hg⟩, hσ6, HSu, J6, T6⟩ := setcap_core2TA hT' E0 RS J5' + ((hOS1.trans' hk2).trans' hk3) (hks3.trans hks2') (hcpu3.trans hcpu2') cte hab hcap hEnc hca + ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by cases h⟩ hok' (fun h => by cases h) (fun h => by cases h) hTr0 hnul0 + (PtSrcA.unmPtA (fun h => h.2 rfl)) + (hptw := PtSetE.unmapHolder (by rw [capAtA_eq, ((hOS1.trans' hk2).trans' hk3).capA hx, hcap]) (fun y hy hne mp a v => by + rw [capAtA_eq, ((hOS1.trans' hk2).trans' hk3).capA (RS.sub y hy)]; exact hno y (RS.sub y hy) hne mp a v)) + obtain ⟨asid', va', rfl, _, _⟩ := CapEqA.pt_mapped_iff.mp heq' + have hperf : ((), σ6) ∈ (Fl4SpecA64.performPageTableInvocation (Z := Unit) (.pageTableUnmap (.pageTableCap (specPtr ptr) + .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte) (stUpdA σ σ.curThread x .restart)).1 := + perfPtUnmapN_memA (p := specPtr ptr) (asid := BitVec.ofNat 16 asid.val) (v := va.bv) (cte := cte) + (σz := ptSetA σu (specPtr ptr) t') (ac := .pageTableCap (specPtr ptr) .normalPtT (some (asid', va'))) hσu hrun0 h5 hg rfl hσ6 + 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, hqS, j, hj, hal, rfl⟩ + · exact WritesIn.refl _ _ + · exact (writesIn_wr hal).mono fun b hb => ⟨q, j, Or.inr (Or.inr hqS), 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, hqS, j, 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 Q5m I5m).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 + -- 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 : (σ5).kheap (specPtr ptr) = some (.archObj (.pageTable t')) := by + rw [hk5, 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', ⟨⟨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 Q5m.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 : (σ5).kheap p = some (.archObj (.dataPage dv pg)) := by + rcases I5m 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 hst2 (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 I5m + (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/Stage3ArmPtUnmT2A.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmT2A.lean index 293309bdc..c252508a8 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmT2A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmT2A.lean @@ -13,6 +13,7 @@ Named premise (arm): [J] `hUniq` = `PtUniqT2A`, a **candidate record invariant** exactly one reachable entry"; see `JStage3A.ptUnmapT2A`). New module. -/ import Fl4ProofsA64.P3.Stage3ArmPtUnmXA +import Fl4ProofsA64.P3.VsUniqT2ShrinkA import Fl4ProofsA64.P3.Stage3ArmPtMapA open Aeneas Aeneas.Std Result @@ -24,12 +25,6 @@ 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} @@ -102,10 +97,10 @@ 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) + {m : Fl4SpecA64.McState} {T2' : Set U64} (J : JAtZAX (L := L) AR Z s a σ m) (hT : T2' ⊆ Z.T2) (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 with ext := ER, vsu := J.1.vsu.shrinkT2 J.1.ext hT, 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⟩, @@ -160,6 +155,22 @@ theorem ExtFootE.shrinkT2A {X Y T2 T2' : Set U64} {b : U64} (hT : T2' ⊆ T2) (h | wl0 y hy => exact .wl0 y hy | wlo y i hy hi => exact .wlo y i hy hi +theorem FootNA.shrinkT2A {s : S} {w : U64} (hT : T2' ⊆ Z.T2) (h : FootNA (L := L) { Z with T2 := T2' } s w) : + FootNA (L := L) Z s w := by + cases h with + | node c w hc hw => exact .node c w hc hw + | cur w h => exact .cur w h + | tcb t w ht hw => exact .tcb t w ht hw + | sc c hc => exact .sc c hc + | vcpu v w hv hw => exact .vcpu v w hv hw + | irq i hi => exact .irq i hi + | cur2 w h => exact .cur2 w h + | glob w h => exact .glob w h + | tcb2 t w ht hw => exact .tcb2 t w ht hw + | sc2 c hc => exact .sc2 c hc + | vs w h => exact .vs w h + | ext w h => exact .ext w (ExtFootE.shrinkT2A hT h) + 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 @@ -205,6 +216,40 @@ end section arm variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +set_option maxHeartbeats 1000000 in +/-- **`setcap_core2A` at a smaller `T2`**: the entry record and the site are at `Z`, the joint relation at +`{ Z with T2 := T2' }` (`T2' ⊆ Z.T2`; the footprint facts come down by `FootNA.shrinkT2A`). -/ +theorem setcap_core2TA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS U Ac Pp Tb : Set U64} + {Lv : U64 → Nat} {ia ie : Nat} {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + {T2' : Set U64} (hT2 : T2' ⊆ Z.T2) + (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) + (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) {s2 : S} {σ2 : Fl4SpecA64.State Unit} + (J2 : JAtZAX (L := L) AR { Z with T2 := T2' } s2 a σ2 m) (hk : OSKeep st OS s s2) (hks : L.ksb s2 = L.ksb s) + (hcpu : L.cpu s2 = L.cpu s) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) {c0 c : capability.Cap} + {sc : Fl4SpecA64.Cap} (hcap : capA st s (cslotAddrA cte) = c0) (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) + (hua : UA c c0) (hok : CapObjOkA { Z with T2 := T2' } c) (hcn : c ≠ .Null) (hc0 : c0 ≠ .Null) + (hT : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) + (hptc : PtSrcA Z.th Z.S1 T2' (L.mem s2) c) + (hrt : RootSetA (capAtA (L.mem s2) (cslotAddrA cte)) c := by root_nr) + (hptw : PtSetE Z.th (L.mem s2) (cslotAddrA cte) c := by pt_nr) : + ∃ s3 σ3, obj.Slot.set_cap st (cslotAddrA cte) s2 c = ok s3 ∧ + (∃ c', CapEqA c0 c' ∧ (c', σ2) ∈ (Fl4SpecA64.getCap (Z := Unit) cte σ2).1) ∧ + ((), σ3) ∈ (Fl4SpecA64.setCap (Z := Unit) sc cte σ2).1 ∧ SpecSlotA σ2 σ3 ∧ + JAtZAX (L := L) AR { Z with T2 := T2' } s3 a σ3 m ∧ TreeA st OS Z.G.chains Z.G.par s3 := by + have hos : cslotAddrA cte ∈ OS := RS.sub _ (hab.isSlot E.j.1.place) + have hN := bxi_nodes E.sys.ent.bxi + have e0 : capA st s2 (cslotAddrA cte) = c0 := (hk.capA hos).trans hcap + obtain ⟨c', hg, -, hc'⟩ := StateRelA.getAbsA J2.1.st hab + have e1 : capAtA (L.mem s2) (cslotAddrA cte) = c0 := e0 + rw [e1] at hc' + obtain ⟨s3, σ3, hsc, hσ3, HS, -, J3, T3⟩ := J2.of_setcapA E.sys.ent.os RS.sub + (fun b hb => footNOff_ksA hks hcpu (footN_offA E) b (hb.shrinkT2A hT2)) + (fun b hb => footNAl_ksA hks hcpu (FootNA.aligned E.j.1 hN E.scAl E.ap.vcAl) b (hb.shrinkT2A hT2)) + cte hab hEnc hca (hT.keepO hk) (fun y hy hn => by rw [hk.capA hy]; exact hnul y hy hn) hcn + (by rw [e0]; exact hc0) (by rw [e0]; exact hua) hok hptc hrt hptw + exact ⟨s3, σ3, hsc, ⟨c', hc', hg⟩, hσ3, HS, J3, T3⟩ + + theorem ArchInvA.notPool {o : Fl4SpecA64.ArchKernelObj} {f : Fl4SpecA64.AsidPool} (h : ArchInvA o (.asidPool f)) : False := by cases o with @@ -430,6 +475,7 @@ theorem JStage3A.ptUnmapT2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap 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) + (hptw := PtSetE.unmapHolder (by rw [capAtA_eq]; exact c1) (fun y hy hne mp a v => hno1 y (RS.sub y hy) hne mp a v)) (hT2 := fun y hy e p0 a0' v0' hc hp0 => ⟨hp0, fun h => by have e0 := Set.mem_singleton_iff.1 h subst e0 @@ -442,8 +488,8 @@ theorem JStage3A.ptUnmapT2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap (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 + (c := .PageTable ptr false 0#u64 0#u64) (by rw [c1]; exact .pt ..) hok hirq hsci (Pj := False) (fun h => h.elim) + (fun s2 σ2 hs2 hσ2 HSs w jxP hst2 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 @@ -466,15 +512,93 @@ theorem JStage3A.ptUnmapT2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap 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 + obtain ⟨a', hfa', hAR⟩ := spec_ex_fd (hfl.arA K J5.1.ar) + obtain ⟨Pt, Ub, vr, -, -, -, -, -, -, link, -, -⟩ := J1.j7 + 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 hzGz : ∀ Pt' : Set U64, (∀ b, VsR (L.ksb s1) Pt' b → Aligned b) → + VsZ st (L.ksb s1) Pt' s1 (L.zr s2u ptr 4096#u64) := fun Pt' hal b hb => by + have hb1 := hal b hb + 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 hrelZ : ∀ q, XqA Z q → ∀ j : U64, j.val < 512 → + L.mem (L.zr s2u ptr 4096#u64) (peAF q j) = L.mem s1 (peAF q j) ∨ L.mem (L.zr s2u ptr 4096#u64) (peAF q j) = 0#u64 := fun q hq j hj => + hzGz Pt vr.al _ (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 hs5Z : ∀ q, XqA Z q → ∀ j : U64, j.val < 512 → + L.mem (L.zr s2u ptr 4096#u64) (peAF q j) = 0#u64 ∨ L.mem (L.zr s2u ptr 4096#u64) (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 + exact zr_caseA (st := st) (s := s2u) hp4 hb1 + have hATz : (ptSetA σu (specPtr ptr) t').archState.armAsidTable = σ.archState.armAsidTable := by + exact Q5.asidTable + have hpoolZ : ∀ (p : U64) f, (ptSetA σu (specPtr ptr) t').kheap (specPtr p) = some (.archObj (.asidPool f)) → + σ.kheap (specPtr p) = some (.archObj (.asidPool f)) := fun p f hk6 => by + have h1 := hk6 + 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 hActZ : ∀ r, ActiveS2RootA Z.Pp Z.X (ptSetA σu (specPtr ptr) t') 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 [← hATz]; exact ht, hpoolZ p f hk6, hf'⟩ + have hMqZ : ∀ q ∈ S2PgE Z.X Z.T2, ∀ j : U64, j.val < 512 → L.mem (L.zr s2u ptr 4096#u64) (peAF q j) ≠ 0#u64 → + L.mem s1 (peAF q j) = L.mem (L.zr s2u ptr 4096#u64) (peAF q j) := fun q hq j hj hne => by + rcases hrelZ 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 hno5Z : ∀ w, S2EntryA Z.Pp Z.X (Z.T2 \ {ptr}) Z.Sh2 (L.mem (L.zr s2u ptr 4096#u64)) (ptSetA σu (specPtr ptr) t') w → + dBitA (L.mem (L.zr s2u ptr 4096#u64) w) 0 = true → dBitA (L.mem (L.zr s2u ptr 4096#u64) w) 1 = true → dTabA (L.mem (L.zr s2u ptr 4096#u64) w) ≠ ptr := by + intro w hw hb0 hb1' hn + have M5ne : L.mem (L.zr s2u ptr 4096#u64) 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, hActZ 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 hActZ (fun q hq j hj hne => hMqZ q hq j hj hne) hreach + obtain ⟨q, j, hXq, hj, hwq, hent⟩ := key + have M5q : L.mem (L.zr s2u ptr 4096#u64) (peAF q j) ≠ 0#u64 := by rw [← hwq]; exact M5ne + have e1 : L.mem s1 w = L.mem (L.zr s2u ptr 4096#u64) w := by rw [hwq]; exact hMqZ 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 hs5Z 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 J5.1.ext hno5Z + have J5' := J5.shrinkT2A hT' ER' + have hok' : CapObjOkA { Z with T2 := Z.T2 \ {ptr} } (.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⟩ + obtain ⟨s5, σ6, hsc, -, hσ6, HSu, J6, T6⟩ := setcap_core2TA hT' 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 + ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by cases h⟩ hok' (fun h => by cases h) (fun h => by cases h) hTr0 hnul0 + (PtSrcA.unmPtA (fun h => h.2 rfl)) + (hptw := PtSetE.unmapHolder (by rw [capAtA_eq, ((hOS1.trans' hk2).trans' hk3).capA hx, hcap]) (fun y hy hne mp a v => by + rw [capAtA_eq, ((hOS1.trans' hk2).trans' hk3).capA (RS.sub y hy)]; exact hno y (RS.sub y hy) hne mp a v)) 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 @@ -574,65 +698,6 @@ theorem JStage3A.ptUnmapT2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap 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 @@ -649,7 +714,7 @@ theorem JStage3A.ptUnmapT2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap 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⟩, + HS2, ?_, ?_, J6', ⟨⟨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, @@ -677,7 +742,7 @@ theorem JStage3A.ptUnmapT2A {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap 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) + · exact BufCover.vsA (BufCover.mapA J1.bufCover J1.bufNative J1.j.1.st hst2 (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 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmUA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmUA.lean index 7cefce2a2..8d2fe5bf5 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmUA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmUA.lean @@ -211,7 +211,8 @@ theorem JStage3A.ptUnmapUA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} obtain ⟨s2, σ2, hs2, hσ2, HSsk, -, J2⟩ := J1.of_capFrame (hpt := fun _ _ _ h => by cases h) 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 + (c := .PageTable ptr false 0#u64 0#u64) (hptw := Or.inl (PtSetA.unm (by rw [capAtA_eq, c1]))) + (by rw [c1]; exact .pt ..) hok hirq hsci (PtSrcA.unmPtA (J.j.1.vsu.out _ (hab.isSlot J.j.1.place) ptr asid va ((capAtA_eq (st := st) _ _).trans hcap))) (fun s2 σ2 hs2 hσ2 HS w jx hc2 => by obtain ⟨hcx, hco⟩ := capA_setCapA hO hx hEnc hs2 have W : UnmPtWrA st OS (L.wr s (stA (L.curW s)) sched.TS_RESTART) s2 (cslotAddrA cte) ptr asid va := diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmXA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmXA.lean index 824146590..95d2b48fa 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmXA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmPtUnmXA.lean @@ -125,6 +125,7 @@ theorem JStage3A.ptUnmapXA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (hpS : ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr) (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) (k : Fl4SpecA64.ExtRootKind) (hkR : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some k) (hkR1 : k ≠ .stage1) (fin : ∀ (x : Fl4SpecA64.Tcb) (s3 : S) (σ3 : Fl4SpecA64.State Unit) (a' : A), @@ -207,13 +208,15 @@ theorem JStage3A.ptUnmapXA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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 main := J1.of_capVsFrameA (hpt := fun _ _ _ h => by cases h) + (hptw := PtSetE.unmapHolder (by rw [capAtA_eq]; exact c1) (fun y hy hne mp a v => by + rw [capAtA_eq, hOS1.capA (RS.sub y hy)]; exact hno y (RS.sub y hy) hne mp a v)) (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 + (c := .PageTable ptr false 0#u64 0#u64) (by rw [c1]; exact .pt ..) hok hirq hsci (PtSrcA.unmPtA (fun h => (J.j.1.ext.pgd ptr (Or.inl h)).1 (Or.inr (Or.inl hpS.1)))) (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 @@ -239,7 +242,9 @@ theorem JStage3A.ptUnmapXA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} 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 + (hptw := PtSetE.unmapHolder (by rw [capAtA_eq, ((hOS1.trans' hk2).trans' hk3).capA hx, hcap]) (fun y hy hne mp a v => by + rw [capAtA_eq, ((hOS1.trans' hk2).trans' hk3).capA (RS.sub y hy)]; exact hno y (RS.sub y hy) hne mp a v)) + ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by cases h⟩ hok (fun h => by cases h) (fun h => by cases h) hTr0 hnul0 (PtSrcA.unmPtA (fun h => (E0.j.1.ext.pgd ptr (Or.inl h)).1 (Or.inr (Or.inl hpS.1)))) 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 diff --git a/proofs/Fl4ProofsA64/P3/Stage3ArmSubframeA.lean b/proofs/Fl4ProofsA64/P3/Stage3ArmSubframeA.lean new file mode 100644 index 000000000..86e2f9416 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3ArmSubframeA.lean @@ -0,0 +1,239 @@ +/- +P3 (AArch64, E0.5c): **the `DeriveSubframe` insertions across `JStage3A`** — `vspace::insert_subframes` (the `count` +`cdt::insert`s of 4 KiB frame caps derived from the Large frame cap in `ss`, into the consecutive slots of a CNode), +against the spec's `mapMx` of `cap_insert`s, keeps `JStage3A`, with **one** `of_capDerivA` application at the final state +(`of_capDerivCnA`: every written slot is a CNode slot). + +* `JStage3A.subframesA`: the arm after its Restart. The pieces come from `insert_subframes_j5A` (J5 slot, `FrLamA`, the + window slots' caps and the slots kept, `WritesIn`, the transitive spec side `SubQA`, `SInvXA`, the `DerivA` of each + window cap from the source); `CapsFromA` is built directly from them. The final-state `SymL` / `SysL` / J7 are + hypotheses (as in the other arms, Option A/X). + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3CapDerivCnA +import Fl4ProofsA64.P3.FrSubframeJ5A +import Fl4ProofsA64.P3.Stage3DelInA +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} + +set_option maxHeartbeats 8000000 in +/-- **`JStage3A` across `vspace::insert_subframes`** (module docstring). -/ +theorem JStage3A.subframesA {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 : Fl4SpecA64.CslotPtr} (hAs : AbsSlotA Z.th ss) + {dest : U64} {r : Nat} (hth : Z.th dest = some (.cnode r)) (hr : 1 ≤ r ∧ r ≤ 58) + {fp rt asid va offset first count vm : U64} {mp e : Bool} + (hfpC : CapRt.Canonical fp) (hfpAl : fp.val % 2 ^ 21 = 0) (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) + (hoff : offset.val + count.val * 4096 ≤ 2 ^ 21) (hfc : first.val + count.val ≤ 2 ^ r) + (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) (hoff4 : offset.val % 4096 = 0) + (hsrc : capAtA (L.mem s) (cslotAddrA ss) = .Frame fp .Large rt false mp e asid va) + (hall : ∀ j < count.val, + capAtA (L.mem s) (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null) + (symL : ∀ s2, vspace.insert_subframes st s (cslotAddrA ss) dest first (wa fp offset) count vm = ok s2 → + SymL st H Z.Cs s2) + (sysl : ∀ s2, vspace.insert_subframes st s (cslotAddrA ss) dest first (wa fp offset) count vm = ok s2 → + SysL st H Z.Cs OS ia ie s2) + (j7 : ∀ s2 σ2 G2, vspace.insert_subframes st s (cslotAddrA ss) dest first (wa fp offset) count vm = ok s2 → + JAtZAX (L := L) AR { Z with G := G2 } s2 a σ2 m → + J7A st (J7R2A st ar nA) { Z with G := G2 } H OS s2 σ2 m) : + ∃ s2 σ2 G2, vspace.insert_subframes st s (cslotAddrA ss) dest first (wa fp offset) count vm = ok s2 ∧ + ((), σ2) ∈ (Fl4Spec.NonDet.mapMx (fun d : Nat × Fl4SpecA64.CslotPtr => + Fl4SpecA64.capInsert (Z := Unit) (.archObjectCap (.frameCap + (specPtr fp + offset.bv + BitVec.ofNat 64 (d.1 * 4096)) (vmRightsOfA vm) .armSmallPage false none)) + ss d.2) + ((List.range' 0 count.val).zip ((List.range' first.val count.val).map fun j => + (specPtr dest, Fl4SpecA64.natToCref r j))) σ).1 ∧ + Sched.BodyKeepA σ σ2 ∧ + JStage3A st AR { Z with G := G2 } 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 hsub := J.j5.2.1 + have hnul := J.j5.2.2 + have E1 := J.toJEntA + have hT0 : 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 hLam0 : FrLamA st OS s := J.frBase.2.2 + have hdo : ¬ IrqNodeA (L.ksb s) dest := fun ⟨i, hi, e⟩ => by + have h0 := J.j.1.place.irq i hi + rw [← e, hth] at h0 + cases h0 + omega + have mB := insert_subframes_j5A (s := s) (n := n) E1 hsub hAs hth hr hfpC hfpAl hvm hoff hfc hcO + (σ0 := σ) (s0 := s) J.j hT0 rfl rfl hnul0 hsrc hall J.j5 hLam0 hoff4 J.sinv hdo + obtain ⟨s2, hs2, σ2, G2, hm, hjx, hT2, j5, hLam2, hKeep, hWin, hWr, hQ, hSI, hDer⟩ := spec_existsA mB + refine ⟨s2, σ2, G2, hs2, hm, ?_, ?_⟩ + · exact Sched.BodyKeepA.ofSlot hQ.hs hQ.ms + -- the window slots + have hAdj : ∀ j < count.val, AbsSlotA Z.th (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) := + fun j hj => ⟨dest, rfl, Or.inl (by rw [natToCref_lengthA r _ (by omega)]; exact hth)⟩ + have hzex : ∀ j < count.val, ∃ z : U64, z.val = j * 4096 := fun j hj => + ⟨⟨BitVec.ofNat 64 (j * 4096)⟩, by + show (BitVec.ofNat 64 (j * 4096)).toNat = _ + rw [BitVec.toNat_ofNat]; exact Nat.mod_eq_of_lt (by omega)⟩ + have hwinN : ∀ j < count.val, capA st s2 (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) ≠ .Null := + fun j hj h => by + obtain ⟨z, hz⟩ := hzex j hj + rw [(hWin j hj z hz).1] at h; cases h + have hwinS : ∀ j < count.val, capA st s (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null := + fun j hj => hall j hj + have hnotW : ∀ y, (¬ ∃ sl : Fl4SpecA64.CslotPtr, y = cslotAddrA sl ∧ ∃ ps, sl.1 = specPtr ps ∧ + Z.th ps = some (.cnode sl.2.length)) → ∀ j < count.val, + y ≠ cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) := fun y hy j hj e => + hy ⟨_, e, dest, rfl, by rw [natToCref_lengthA r _ (by omega)]; exact hth⟩ + have hsOS : cslotAddrA ss ∈ OS := hsub _ (hAs.isSlot J.j.1.place) + have hcsS : capA st s (cslotAddrA ss) = .Frame fp .Large rt false mp e asid va := by + exact hsrc + have hkeepC : ∀ y ∈ OS, (¬ ∃ sl : Fl4SpecA64.CslotPtr, y = cslotAddrA sl ∧ ∃ ps, sl.1 = specPtr ps ∧ + Z.th ps = some (.cnode sl.2.length)) → capA st s2 y = capA st s y := fun y hy hn => + (hKeep y hy (hnotW y hn)).1 + -- caps derived both ways + have F : CapsFromA st OS s s2 := by + refine ⟨fun u hu => ?_, fun v hv => ?_, fun u hu hfr => ?_⟩ + · by_cases hw : ∃ j < count.val, u = cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) + · obtain ⟨j, hj, rfl⟩ := hw + exact Or.inr ⟨_, hsOS, by rw [hcsS]; exact hDer j hj⟩ + · have hk := (hKeep u hu (fun j hj e => hw ⟨j, hj, e⟩)).1 + exact Or.inr ⟨u, hu, by rw [hk]; exact DerivA.refl _⟩ + · by_cases hw : ∃ j < count.val, v = cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) + · obtain ⟨j, hj, rfl⟩ := hw + exact Or.inl (hwinS j hj) + · have hk := (hKeep v hv (fun j hj e => hw ⟨j, hj, e⟩)).1 + exact Or.inr ⟨v, hv, by rw [hk]; exact DerivA.refl _⟩ + · by_cases hw : ∃ j < count.val, u = cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) + · obtain ⟨j, hj, rfl⟩ := hw + obtain ⟨z, hz⟩ := hzex j hj + exact Or.inl (hWin j hj z hz).2 + · obtain ⟨hk, hkr⟩ := hKeep u hu (fun j hj e => hw ⟨j, hj, e⟩) + refine Or.inr ⟨u, hu, ?_, ?_, ?_, ?_⟩ + · rw [hk] at hfr; exact hfr + · rw [hk] + · rw [hk] + · rw [hkr] + have hcn : ∀ sl c, specCapAtA σ2 sl = some c → + specCapAtA σ sl = some c ∨ ∃ r cs, σ.kheap sl.1 = some (.cnode r cs) := fun sl c h => by + rcases hQ.cap sl c h with e | ⟨⟨j, hj, rfl⟩, -⟩ + · exact Or.inl e + · obtain ⟨cs, hk1, -⟩ := J.j.1.st.cnode dest r hth + exact Or.inr ⟨_, cs, hk1⟩ + have origLive : ∀ sl, σ2.isOriginalCap sl = true → AbsSlotA Z.th sl := fun sl h => + (hQ.origD sl h).elim (J.origLive sl) fun ⟨j, hj, e⟩ => by rw [e]; exact hAdj j hj + have nullOrig : ∀ sl, specCapAtA σ2 sl = some .nullCap → σ2.isOriginalCap sl = false := fun sl h => by + by_cases hD : SubDmA dest r first.val count.val sl + · obtain ⟨j, hj, rfl⟩ := hD + exact absurd h (specCap_nnA hjx.1.st (hAdj j hj) (fun h' => hwinN j hj h')) + · rcases hQ.cap sl _ h with h0 | ⟨hD', -⟩ + · have h1 := J.nullOrig sl h0 + cases hc : σ2.isOriginalCap sl + · rfl + · rcases hQ.origD sl hc with o | d + · rw [h1] at o; cases o + · exact absurd d hD + · exact absurd hD' hD + have hsc : ∀ sl c, specCapAtA σ2 sl = some c → (∃ sl0, specCapAtA σ sl0 = some c) ∨ NoIdleCapV m n c := + fun sl c h => (hQ.cap sl c h).elim (fun e => Or.inl ⟨sl, e⟩) fun ⟨_, p, rr, hc⟩ => + Or.inr (by + rw [hc] + exact ⟨fun _ _ h => (by cases h), fun _ h => (by cases h), fun _ _ _ h => (by cases h)⟩) + exact JStage3A.of_capDerivCnA J hWr F hQ.hs hQ.wf hQ.ms hkeepC hQ.cdt hQ.orig origLive nullOrig hsc hcn + (symL s2 hs2) (sysl s2 hs2) hjx hSI j5 (j7 s2 σ2 G2 hs2 hjx) + + +/-- **A large RAM frame cap of an `OS` slot is 2 MiB aligned and canonical** (`FrAt.al` of the `J7` frame-object +record; the cap decoder's `EncWf`). -/ +theorem JStage3A.largeFrAlCanA {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) + {y : U64} (hy : y ∈ OS) {fp rt asid va : U64} {mp e : Bool} + (hc : capAtA (L.mem s) y = .Frame fp .Large rt false mp e asid va) : + fp.val % 2 ^ 21 = 0 ∧ CapRt.Canonical fp := by + obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits7, KLv, W⟩ := J7A.unp J.j7 + have hc' : capA st s y = .Frame fp .Large rt false mp e asid va := hc + have hH : FrAt H fp 21#u64 := W.cc.fo y hy fp .Large rt mp e asid va hc' 21#u64 rfl + have hal := hH.al J.sys.ent.heap + have hw : CapRt.EncWf (capAtA (L.mem s) y) := CapRt.decodeF_encWf _ _ + rw [hc] at hw + refine ⟨by simpa using hal, ?_⟩ + cases e <;> exact hw.1 + +set_option maxHeartbeats 8000000 in +/-- **`JStage3A` across the `DeriveSubframe` arm's body**: the caller's restart, then `subframesA` at the restarted +state; the 2 MiB alignment and canonicality of the source frame are derived (`FrAt.al`, `decodeF_encWf`). -/ +theorem JStage3A.deriveSubframeA {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) + (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + {ss : Fl4SpecA64.CslotPtr} (hAs : AbsSlotA Z.th ss) + {dest : U64} {r : Nat} (hth : Z.th dest = some (.cnode r)) (hr : 1 ≤ r ∧ r ≤ 58) + {fp rt asid va offset first count vm : U64} {mp e : Bool} + (hvm : 1 ≤ vm.val ∧ vm.val ≤ 3) + (hoff : offset.val + count.val * 4096 ≤ 2 ^ 21) (hfc : first.val + count.val ≤ 2 ^ r) + (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) (hoff4 : offset.val % 4096 = 0) + (hsrc : capAtA (L.mem s) (cslotAddrA ss) = .Frame fp .Large rt false mp e asid va) + (hall : ∀ j < count.val, + capAtA (L.mem s) (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null) + (symL : ∀ s2, vspace.insert_subframes st (L.wr s (stA (L.curW s)) sched.TS_RESTART) (cslotAddrA ss) dest first + (wa fp offset) count vm = ok s2 → SymL st H Z.Cs s2) + (sysl : ∀ s2, vspace.insert_subframes st (L.wr s (stA (L.curW s)) sched.TS_RESTART) (cslotAddrA ss) dest first + (wa fp offset) count vm = ok s2 → SysL st H Z.Cs OS ia ie s2) + (j7 : ∀ s2 σ2 G2, vspace.insert_subframes st (L.wr s (stA (L.curW s)) sched.TS_RESTART) (cslotAddrA ss) dest + first (wa fp offset) count vm = ok s2 → + JAtZAX (L := L) AR { Z with G := G2 } s2 a σ2 m → + J7A st (J7R2A st ar nA) { Z with G := G2 } H OS s2 σ2 m) : + ∃ (x : Fl4SpecA64.Tcb) (s2 : S) (σ2 : Fl4SpecA64.State Unit) (G2 : MdbGhostA), σ.kheap σ.curThread = some (.tcb x) ∧ + sched.set_thread_state st s (L.curW s) sched.TS_RESTART = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + vspace.insert_subframes st (L.wr s (stA (L.curW s)) sched.TS_RESTART) (cslotAddrA ss) dest first + (wa fp offset) count vm = ok s2 ∧ + ((), σ2) ∈ (Fl4Spec.NonDet.mapMx (fun d : Nat × Fl4SpecA64.CslotPtr => + Fl4SpecA64.capInsert (Z := Unit) (.archObjectCap (.frameCap + (specPtr fp + offset.bv + BitVec.ofNat 64 (d.1 * 4096)) (vmRightsOfA vm) .armSmallPage false none)) + ss d.2) + ((List.range' 0 count.val).zip ((List.range' first.val count.val).map fun j => + (specPtr dest, Fl4SpecA64.natToCref r j))) (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with G := G2 } 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 ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ2 := by + -- the source frame's alignment and canonicality + have hsOS : cslotAddrA ss ∈ OS := RS.sub _ (hAs.isSlot J.j.1.place) + have hfp := J.largeFrAlCanA hsOS hsrc + obtain ⟨x, hk0, 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 hsrc1 : capAtA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART)) (cslotAddrA ss) = + .Frame fp .Large rt false mp e asid va := by + have h' := hOS1 _ hsOS + unfold capAtA; rw [h'.1, h'.2.1]; exact hsrc + have hall1 : ∀ j < count.val, capAtA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART)) + (cslotAddrA (specPtr dest, Fl4SpecA64.natToCref r (first.val + j))) = .Null := fun j hj => by + have hAd : AbsSlotA Z.th (specPtr dest, Fl4SpecA64.natToCref r (first.val + j)) := + ⟨dest, rfl, Or.inl (by rw [natToCref_lengthA r _ (by omega)]; exact hth)⟩ + have h' := hOS1 _ (RS.sub _ (hAd.isSlot J.j.1.place)) + unfold capAtA; rw [h'.1, h'.2.1] + exact hall j hj + obtain ⟨s2, σ2, G2, hs2, hm, hbk, J3⟩ := JStage3A.subframesA (J := J1) hAs hth hr hfp.2 hfp.1 hvm hoff hfc hcO hoff4 + hsrc1 hall1 symL sysl j7 + exact ⟨x, s2, σ2, G2, hk0, heq, hset, hs2, hm, J3, hbk⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3BootA.lean b/proofs/Fl4ProofsA64/P3/Stage3BootA.lean index 0fba06752..2eff18380 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3BootA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3BootA.lean @@ -211,18 +211,33 @@ private theorem idleAll_bootA {S : Type} {st : machine.Store S} [L : LawfulStore exact ⟨idleTA ib c, hm c, by rw [idleTA_val' hL this]; omega, by rw [idleTA_val' hL this]; omega⟩ /-- A frame cap's base at `w1`: the extra BootInfo, the IPC buffer, the BootInfo frame or the image frame. -/ -private def W1FrPtrA (v : Nat) : Prop := (EFb ≤ v ∧ v < EFb + 131072) ∨ v = IPb ∨ v = BIb ∨ v = IMb +private def W1FrPtrA (v : Nat) : Prop := (EFb ≤ v ∧ v < EFb + 131072 ∧ v % 4096 = 0) ∨ v = IPb ∨ v = BIb ∨ v = IMb + +/-- (E0.5) The addresses of the `w1` frames' 4 KiB ranges: no range key cap is based in one. -/ +private def W1FrRngA (v : Nat) : Prop := + (EFb ≤ v ∧ v < EFb + 131072) ∨ (IPb ≤ v ∧ v < IPb + 4096) ∨ (BIb ≤ v ∧ v < BIb + 4096) ∨ + (IMb ≤ v ∧ v < IMb + 4096) + +private theorem W1FrPtrA.rngIn {p v : Nat} (h : W1FrPtrA p) (h1 : p ≤ v) (h2 : v < p + 4096) : W1FrRngA v := by + unfold W1FrPtrA at h + unfold W1FrRngA + have hE : EFb % 4096 = 0 := by norm_num + rcases h with h | h | h | h + · exact Or.inl ⟨by omega, by omega⟩ + · subst h; exact Or.inr (Or.inl ⟨by omega, by omega⟩) + · subst h; exact Or.inr (Or.inr (Or.inl ⟨by omega, by omega⟩)) + · subst h; exact Or.inr (Or.inr (Or.inr ⟨by omega, by omega⟩)) /-- The shape of every `w1` cap: frames are normal frames at `W1FrPtrA`, the tables are `w1Tb`, no zombie, Stage-2 or high-window cap, and no other range-key cap is based at a frame. -/ private def W1CapA : capability.Cap → Prop - | .Frame p _ _ dev _ _ _ _ => dev = false ∧ W1FrPtrA p.val - | .Thread p => ¬ W1FrPtrA p.val - | .CNode p _ _ _ => ¬ W1FrPtrA p.val - | .AsidPool p _ => ¬ W1FrPtrA p.val - | .SchedContext p _ => ¬ W1FrPtrA p.val - | .PageTable p _ _ _ => p ∈ w1Tb ∧ ¬ W1FrPtrA p.val - | .Pml4 p _ _ => p ∈ w1Tb ∧ ¬ W1FrPtrA p.val + | .Frame p sz _ dev _ _ _ _ => dev = false ∧ W1FrPtrA p.val ∧ sz = .Small + | .Thread p => ¬ W1FrRngA p.val + | .CNode p _ _ _ => ¬ W1FrRngA p.val + | .AsidPool p _ => ¬ W1FrRngA p.val + | .SchedContext p _ => ¬ W1FrRngA p.val + | .PageTable p _ _ _ => p ∈ w1Tb ∧ ¬ W1FrRngA p.val + | .Pml4 p _ _ => p ∈ w1Tb ∧ ¬ W1FrRngA p.val | .Zombie .. => False | .Ept .. => False | .HighVSpace .. => False @@ -238,7 +253,7 @@ private theorem notRk_physA {c : capability.Cap} (h : objects.cap_is_physical c private theorem w1CapA_nullA : W1CapA .Null := notRk_physA (by simp [objects.cap_is_physical]) private theorem w1CapA_frA {p v : Nat} (h : p < 2 ^ 64) (hp : W1FrPtrA p) : W1CapA (frC p v) := - ⟨rfl, by rw [bwv_val h]; exact hp⟩ + ⟨rfl, by rw [bwv_val h]; exact hp, rfl⟩ private theorem w1CapA_capOfA (nc i : Nat) : W1CapA (capOf nc i) := by unfold capOf @@ -251,10 +266,10 @@ private theorem w1CapA_capOfA (nc i : Nat) : W1CapA (capOf nc i) := by | exact w1CapA_nullA | exact w1CapA_frA (by norm_num) (by unfold W1FrPtrA; norm_num) | exact notRk_physA (by simp [objects.cap_is_physical]) - | (show ¬ W1FrPtrA _; unfold W1FrPtrA; simp only [vRT, vRR, vPL, vSC]; norm_num) + | (show ¬ W1FrRngA _; unfold W1FrRngA; simp only [vRT, vRR, vPL, vSC]; norm_num) | (refine ⟨?_, ?_⟩ · show (bwv VSb).val = VSb ∨ _; exact Or.inl vVS - · unfold W1FrPtrA; simp only [vVS]; norm_num) + · unfold W1FrRngA; simp only [vVS]; norm_num) by_cases h2 : i < 16 + nc · rw [slotC_sch (by omega) h2] exact notRk_physA (by simp [objects.cap_is_physical]) @@ -262,9 +277,9 @@ private theorem w1CapA_capOfA (nc i : Nat) : W1CapA (capOf nc i) := by generalize i - (16 + nc) = k unfold tailC split_ifs - · exact ⟨Or.inr (Or.inl vL1), by unfold W1FrPtrA; simp only [vL1]; norm_num⟩ - · exact ⟨Or.inr (Or.inr (Or.inl vL2)), by unfold W1FrPtrA; simp only [vL2]; norm_num⟩ - · exact ⟨Or.inr (Or.inr (Or.inr vL3)), by unfold W1FrPtrA; simp only [vL3]; norm_num⟩ + · exact ⟨Or.inr (Or.inl vL1), by unfold W1FrRngA; simp only [vL1]; norm_num⟩ + · exact ⟨Or.inr (Or.inr (Or.inl vL2)), by unfold W1FrRngA; simp only [vL2]; norm_num⟩ + · exact ⟨Or.inr (Or.inr (Or.inr vL3)), by unfold W1FrRngA; simp only [vL3]; norm_num⟩ · exact w1CapA_frA (by omega) (Or.inl (by omega)) · exact w1CapA_frA (by norm_num) (by unfold W1FrPtrA; norm_num) · exact fun r => by have := r.2.1; simp [isUtA] at this @@ -312,9 +327,9 @@ private theorem w1CapA_frPtrA {c : capability.Cap} (W : W1CapA c) (f : isFrA c = cases c <;> try (simp [isFrA] at f; done) rename_i q sz r dev m ept a v rw [show ptrA (.Frame q sz r dev m ept a v) = q from ptrA_of rfl] - exact W.2 + exact W.2.1 -private theorem w1CapA_rkPtrA {c : capability.Cap} (W : W1CapA c) (k : RngKeyA c) : ¬ W1FrPtrA (ptrA c).val := by +private theorem w1CapA_rkPtrA {c : capability.Cap} (W : W1CapA c) (k : RngKeyA c) : ¬ W1FrRngA (ptrA c).val := by cases c with | Frame => exact absurd k.2.2 (by simp [isFrA]) | Thread p => rw [show ptrA (.Thread p) = p from ptrA_of rfl]; exact W @@ -328,6 +343,31 @@ private theorem w1CapA_rkPtrA {c : capability.Cap} (W : W1CapA c) (k : RngKeyA c | HighVSpace => exact W.elim | _ => exact absurd k W +/-- (E0.5) No range key cap's base lies inside a `w1` frame's range (all `w1` frames are 4 KiB). -/ +private theorem w1CapA_intA {y z : capability.Cap} (Wy : W1CapA y) (fy : isFrA y = true) (Wz : W1CapA z) + (k : RngKeyA z) : ¬ (baseA y < baseA z ∧ baseA z ≤ topA y) := by + cases y <;> try (simp [isFrA] at fy; done) + rename_i q sz r dev m ept a v + obtain ⟨-, hp, hsz⟩ := Wy + subst hsz + have f := frA_size (ptr := q) (rights := r) (x3 := a) (x4 := v) (dv := dev) (x1 := m) (x2 := ept) + (size := .Small) (bits := 12#u64) rfl + have e12 : (12#u64 : U64).val = 12 := rfl + have hq : q.val + 4096 < 2 ^ 64 := by + unfold W1FrPtrA at hp + omega + have b1 : baseA (.Frame q .Small r dev m ept a v) = q.val := by unfold baseA; rw [f.1] + have t1 : topA (.Frame q .Small r dev m ept a v) = q.val + 4095 := by + unfold topA + rw [f.1, f.2.1, wa_val, mskA_val (by rw [e12]; norm_num), e12] + have h4 : (2 : Nat) ^ 12 - 1 = 4095 := by norm_num + rw [h4] + exact Nat.mod_eq_of_lt (by omega) + rintro ⟨c1, c2⟩ + rw [b1] at c1 + rw [t1] at c2 + exact w1CapA_rkPtrA Wz k (W1FrPtrA.rngIn hp (by unfold baseA at c1; omega) (by unfold baseA at c2; omega)) + section w1caps variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} @@ -338,7 +378,7 @@ private theorem w1CapA_osA (P : BootLay1 kb ib nc) {u : U64} (hu : u ∈ w1OS kb · exact w1CapA_capOfA _ _ · exact w1CapA_capOfA _ _ · exact w1CapA_capOfA _ _ - · exact ⟨rfl, by rw [vIP]; unfold W1FrPtrA; norm_num⟩ + · exact ⟨rfl, by rw [vIP]; unfold W1FrPtrA; norm_num, rfl⟩ · exact w1CapA_nullA /-- **`w1` holds no device frame cap.** -/ @@ -424,7 +464,7 @@ private theorem w1_bufOffA (P : BootLay1 kb ib nc) : rw [← bufSlot_eqA, ← capAtA_eq (st := bst)] exact rt_capA P (by decide) have e2 : rtCapA 2 = .Frame (bwv IPb) .Small 3#u64 false false false 0#u64 (bwv 0) := by simp [rtCapA] - refine ⟨bwv RTb, w1H_rt, hsO, bwv IPb, .Small, 3#u64, false, false, 0#u64, bwv 0, 12#u64, hc.trans e2, + refine ⟨by rw [vIP], bwv RTb, w1H_rt, hsO, bwv IPb, .Small, 3#u64, false, false, 0#u64, bwv 0, 12#u64, hc.trans e2, by simp [capability.FrameSize.bits], fun k hk => ?_⟩ have v := bufW_ipb hk have e12 : (12#u64 : U64).val = 12 := rfl @@ -620,7 +660,9 @@ theorem boot_stage3_ex {A : Type} (AR : A → HwRootA → Prop) {a : A} (r now m origLive := fun _ h => Bool.noConfusion h nullOrig := fun _ _ => rfl thPos := fun p z h => thPos_bootA h - frBase := fun u hu _ _ f => by rw [nul u hu] at f; simp [isFrA] at f + frBase := ⟨fun u hu _ _ f => by rw [nul u hu] at f; simp [isFrA] at f, + fun u hu _ _ f => by rw [nul u hu] at f; simp [isFrA] at f, + fun u hu _ _ _ _ _ _ hc => by rw [nul u hu] at hc; cases hc⟩ devFr := fun u hu _ _ _ _ _ _ _ h => by rw [nul u hu] at h; cases h finCov := ⟨(boot_slotHeapCovA hL hK).cnode, (boot_slotHeapCovA hL hK).tcb⟩ idleAll := idleAll_bootA SR (fun _ => rfl) (fun _ => rfl) (fun _ h => h) hL hnn @@ -896,10 +938,18 @@ theorem w1_stage3 {kb ib : U64} {nc : Nat} (P : BootLay1 kb ib nc) (Q : BootCano exact w1ThA_rr (kb := kb) (ib := ib) (nc := nc) nullOrig := fun x h => w1_nullOrigA C x h thPos := fun p z h => thPos_w1A h - frBase := fun y hy z hz f k e => by + frBase := ⟨fun y hy z hz f k e => by have Wy := w1CapA_osA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P hy have Wz := w1CapA_osA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P hz - exact w1CapA_rkPtrA Wz k (e ▸ w1CapA_frPtrA Wy f) + exact w1CapA_rkPtrA Wz k (e ▸ W1FrPtrA.rngIn (w1CapA_frPtrA Wy f) (le_refl _) (Nat.lt_add_of_pos_right (by norm_num))), + fun y hy z hz f k => by + have Wy := w1CapA_osA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P hy + have Wz := w1CapA_osA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P hz + exact w1CapA_intA Wy f Wz k, + fun y hy p rt mp e asid va hcy => by + have Wy := w1CapA_osA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P hy + rw [hcy] at Wy + exact absurd Wy.2.2 (fun h => by cases h)⟩ devFr := fun u hu p _ _ _ _ _ _ h => by have W := w1CapA_osA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P hu rw [h] at W @@ -1004,11 +1054,11 @@ theorem w1_stage3 {kb ib : U64} {nc : Nat} (P : BootLay1 kb ib nc) (Q : BootCano vcOS := fun b ⟨v, hv, _⟩ => (e _ hv).elim userFr := fun y hy p size rights mapped ept asid va hc => by obtain ⟨rfl, hF⟩ := (w1_rootCap P hy).fr _ _ _ _ _ _ _ _ hc - exact w1KA_frA hF + exact ⟨_, .armSmallPage, frPg_obj hF, w1KA_frA hF, le_rfl, le_rfl⟩ frTh := fun y hy p size rights x1 x2 x3 x4 bits hc hb => by obtain ⟨rfl, hF⟩ := (w1_rootCap P hy).fr _ _ _ _ _ _ _ _ hc rw [show 2 ^ bits.val = 4096 by simp [small_bits hb]] - exact w1ThA_fr hF + exact ⟨_, 4096, w1ThA_fr hF, le_rfl, le_rfl⟩ bfSpec := fun bp h => by change bp ∈ ({(bwv 18446604435733225472, specPtr (bwv 18446604435733225472))} : Set (U64 × Fl4SpecA64.Word)) at h diff --git a/proofs/Fl4ProofsA64/P3/Stage3BufNewA.lean b/proofs/Fl4ProofsA64/P3/Stage3BufNewA.lean index e4e2029f9..0a1ecd45f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3BufNewA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3BufNewA.lean @@ -100,7 +100,8 @@ theorem JStage3A.bufNewPlaceA have hnew : ∀ k : U64, k.val < 128 → ∃ ptr bits, H ptr = some (.other bits) ∧ ptr.val ≤ (bufW w k).val ∧ (bufW w k).val < ptr.val + 2 ^ bits := fun k hk => by obtain ⟨u, hu, ptr, size, rights, x1, x2, x3, x4, bits, hc, hb, l1, l2⟩ := hl.2.2 k hk - exact ⟨ptr, bits.val, fo u hu ptr size rights x1 x2 x3 x4 hc bits hb, l1, l2⟩ + obtain ⟨q, z, hq, hbz, hq1, hq2⟩ := (fo u hu ptr size rights x1 x2 x3 x4 hc bits hb).obj + exact ⟨q, z, hq, by omega, by omega⟩ have P := J.iplaced have off : ∀ {q : U64} {kd : HKind}, H q = some kd → (∀ z, kd ≠ .other z) → ∀ k : U64, k.val < 128 → (bufW w k).val < q.val ∨ q.val + 2 ^ kd.bits ≤ (bufW w k).val := fun hq hne k hk => by diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapDerivA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapDerivA.lean index 443788afe..ac65f5e72 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapDerivA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapDerivA.lean @@ -12,6 +12,7 @@ and the fields that read the mapped flag or the TCB buffer slots stay arm hypoth No named premise. New module. -/ import Fl4ProofsA64.P3.Stage3CapFrameA +import Fl4ProofsA64.P1.S1aSubIns open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -22,6 +23,11 @@ noncomputable section local notation "wa" => core.num.U64.wrapping_add +theorem pageBits_frameSizeA (sz : capability.FrameSize) (bits : U64) (hb : capability.FrameSize.bits sz = ok bits) : + Fl4SpecA64.pageBitsForSize (frameSizeOfA sz) = bits.val := by + cases sz <;> simp [frameSizeOfA, Fl4SpecA64.pageBitsForSize, capability.FrameSize.bits] at hb ⊢ <;> + cases hb <;> decide + /-- **A cap derived from an old cap** (module docstring): `DerivA d c` is `d` from `c`. -/ inductive DerivA : capability.Cap → capability.Cap → Prop | refl (c : capability.Cap) : DerivA c c @@ -36,6 +42,13 @@ inductive DerivA : capability.Cap → capability.Cap → Prop | ut (p b i i' : U64) (dv : Bool) (h : i.val ≤ i'.val) : DerivA (.Untyped p b i' dv) (.Untyped p b i dv) /-- (Lift 1b) `IRQControl` issue's handler cap is derived from the control cap. -/ | irqH (i : U64) : DerivA (.IrqHandler i) .IrqControl + /-- (E0.5) A `Small` subframe cap of a non-device frame cap: `p' = p + k·4096` inside `[p, p + 2^bits)`, which does + not wrap. -/ + | sub (p p' : U64) (sz : capability.FrameSize) (r r' : U64) (m e : Bool) (a v : U64) (m' e' : Bool) (a' v' : U64) + (k : Nat) (hp : p'.val = p.val + k * 4096) + (hk : ∀ bits, capability.FrameSize.bits sz = ok bits → + k * 4096 + 4096 ≤ 2 ^ bits.val ∧ p.val + 2 ^ bits.val ≤ 2 ^ 64) : + DerivA (.Frame p' .Small r' false m' e' a' v') (.Frame p sz r false m e a v) /-- The cap kinds a derivation may change. -/ def FixedCapA : capability.Cap → Prop @@ -72,24 +85,89 @@ theorem DerivA.ut_back (h : DerivA d c) {q b fi : U64} {dv : Bool} (hd : d = .Un exact ⟨i, rfl, h⟩ | _ => cases hd +/-- A frame cap derived from `c` is `c`'s frame at the same base and size, or a subframe of it (E0.5). -/ theorem DerivA.frame_back (h : DerivA d c) {p : U64} {sz : capability.FrameSize} {r : U64} {dv m e : Bool} - {a v : U64} (hd : d = .Frame p sz r dv m e a v) : ∃ r0 m0 e0 a0 v0, c = .Frame p sz r0 dv m0 e0 a0 v0 := by + {a v : U64} (hd : d = .Frame p sz r dv m e a v) : + (∃ r0 m0 e0 a0 v0, c = .Frame p sz r0 dv m0 e0 a0 v0) ∨ + (dv = false ∧ sz = .Small ∧ ∃ p0 sz0 r0 m0 e0 a0 v0 k, c = .Frame p0 sz0 r0 false m0 e0 a0 v0 ∧ + p.val = p0.val + k * 4096 ∧ + ∀ bits, capability.FrameSize.bits sz0 = ok bits → + k * 4096 + 4096 ≤ 2 ^ bits.val ∧ p0.val + 2 ^ bits.val ≤ 2 ^ 64) := by cases h with - | refl => exact ⟨r, m, e, a, v, hd⟩ + | refl => exact Or.inl ⟨r, m, e, a, v, hd⟩ | frame p1 sz1 r1 dv1 m1 e1 a1 v1 r2 m2 e2 a2 v2 => injection hd with h1 h2 h3 h4 h5 h6 h7 h8 subst h1 h2 h4 - exact ⟨r1, m1, e1, a1, v1, rfl⟩ + exact Or.inl ⟨r1, m1, e1, a1, v1, rfl⟩ + | sub p0 p1 sz0 r0 r1 m0 e0 a0 v0 m1 e1 a1 v1 k hp hk => + injection hd with h1 h2 h3 h4 h5 h6 h7 h8 + subst h1 h2 h4 + exact Or.inr ⟨rfl, rfl, p0, sz0, r0, m0, e0, a0, v0, k, rfl, hp, hk⟩ | _ => cases hd theorem DerivA.isFr (h : DerivA d c) : isFrA d = isFrA c := by cases h <;> rfl theorem DerivA.isUt (h : DerivA d c) : isUtA d = isUtA c := by cases h <;> rfl -theorem DerivA.ptr (h : DerivA d c) : ptrA d = ptrA c := by - have e : capability.Cap.ptr d = capability.Cap.ptr c := by cases h <;> rfl - rw [ptrA_eq, ptrA_eq] at e - exact okinj e +/-- A derivation keeps the object pointer and size, or is a subframe (E0.5). -/ +theorem DerivA.same_or_sub (h : DerivA d c) : + (capability.Cap.ptr d = capability.Cap.ptr c ∧ objects.cap_size_bits d = objects.cap_size_bits c) ∨ + ∃ p p' sz r r' m e a v m' e' a' v' k, + d = .Frame p' .Small r' false m' e' a' v' ∧ c = .Frame p sz r false m e a v ∧ p'.val = p.val + k * 4096 ∧ + ∀ bits, capability.FrameSize.bits sz = ok bits → k * 4096 + 4096 ≤ 2 ^ bits.val ∧ p.val + 2 ^ bits.val ≤ 2 ^ 64 := by + cases h <;> first + | exact Or.inl ⟨rfl, rfl⟩ + | exact Or.inr ⟨_, _, _, _, _, _, _, _, _, _, _, _, _, _, rfl, rfl, ‹_›, ‹_›⟩ + +theorem DerivA.ptr (h : DerivA d c) (hnf : isFrA d = false) : ptrA d = ptrA c := by + rcases h.same_or_sub with ⟨h1, -⟩ | ⟨p, p', sz, r, r', m, e, a, v, m', e', a', v', k, hd, -⟩ + · exact okinj ((ptrA_eq d).symm.trans (h1.trans (ptrA_eq c))) + · subst hd; simp [isFrA] at hnf + +/-- A large frame cap derived from `c` has `c`'s range (a derivation to a larger size is a subframe: `Small`). -/ +theorem DerivA.large_range (h : DerivA d c) {p rt : U64} {mp e : Bool} {a v : U64} + (hd : d = .Frame p .Large rt false mp e a v) : baseA d = baseA c ∧ topA d = topA c := by + rcases h.same_or_sub with ⟨h1, h2⟩ | ⟨p0, p', sz, r, r', m, e0, a0, v0, m', e', a', v', k, hd', -⟩ + · have p1 : ptrA d = ptrA c := okinj ((ptrA_eq d).symm.trans (h1.trans (ptrA_eq c))) + have p2 : sizeA d = sizeA c := okinj ((sizeA_eq d).symm.trans (h2.trans (sizeA_eq c))) + exact ⟨by unfold baseA; rw [p1], by unfold topA; rw [p1, p2]⟩ + · rw [hd] at hd'; cases hd' + +/-- The address range of a derived cap: unchanged, or (a subframe) inside the source's and non-wrapping (E0.5). -/ +theorem DerivA.range (h : DerivA d c) : + (baseA d = baseA c ∧ topA d = topA c) ∨ + (isFrA d = true ∧ baseA c ≤ baseA d ∧ baseA d ≤ topA d ∧ topA d ≤ topA c) := by + rcases h.same_or_sub with ⟨h1, h2⟩ | ⟨p, p', sz, r, r', m, e, a, v, m', e', a', v', k, hd, hc, hp, hk⟩ + · left + have p1 : ptrA d = ptrA c := okinj ((ptrA_eq d).symm.trans (h1.trans (ptrA_eq c))) + have p2 : sizeA d = sizeA c := okinj ((sizeA_eq d).symm.trans (h2.trans (sizeA_eq c))) + exact ⟨by unfold baseA; rw [p1], by unfold topA; rw [p1, p2]⟩ + · right + subst hd hc + obtain ⟨bits0, hb0⟩ := frameBits_ex sz + obtain ⟨hk1, hk2⟩ := hk bits0 hb0 + have f1 := frA_size (ptr := p) (rights := r) (x3 := a) (x4 := v) (dv := false) (x1 := m) (x2 := e) (size := sz) hb0 + have f2 := frA_size (ptr := p') (rights := r') (x3 := a') (x4 := v') (dv := false) (x1 := m') (x2 := e') + (size := .Small) (bits := 12#u64) rfl + have e12 : (12#u64 : U64).val = 12 := rfl + have b1 : baseA (.Frame p sz r false m e a v) = p.val := by unfold baseA; rw [f1.1] + have b2 : baseA (.Frame p' .Small r' false m' e' a' v') = p'.val := by unfold baseA; rw [f2.1] + have h1 : 1 ≤ 2 ^ bits0.val := Nat.one_le_two_pow + have t1 : topA (.Frame p sz r false m e a v) = p.val + (2 ^ bits0.val - 1) := by + unfold topA + rw [f1.1, f1.2.1, wa_val, mskA_val f1.2.2.1] + exact Nat.mod_eq_of_lt (by omega) + have t2 : topA (.Frame p' .Small r' false m' e' a' v') = p'.val + 4095 := by + unfold topA + rw [f2.1, f2.2.1, wa_val, mskA_val (by rw [e12]; norm_num), e12] + have h4 : (2 : Nat) ^ 12 - 1 = 4095 := by norm_num + rw [h4] + exact Nat.mod_eq_of_lt (by omega) + have e12' : (2 : Nat) ^ 12 = 4096 := by norm_num + refine ⟨rfl, ?_, ?_, ?_⟩ + · rw [b1, b2]; omega + · rw [b2, t2]; omega + · rw [t1, t2]; omega theorem DerivA.phys (h : DerivA d c) : physA d = physA c := by have e : objects.cap_is_physical d = objects.cap_is_physical c := by cases h <;> rfl @@ -145,6 +223,8 @@ variable (st) in structure CapsFromA (OS : Set U64) (s s' : S) : Prop where back : ∀ u ∈ OS, capA st s' u = .Null ∨ ∃ v ∈ OS, DerivA (capA st s' u) (capA st s v) fwd : ∀ v ∈ OS, capA st s v = .Null ∨ ∃ u ∈ OS, DerivA (capA st s' u) (capA st s v) + /-- (E0.5b) the revocable bit of a frame slot comes from the old state or is clear -/ + rev : RevFromA st OS s s' variable (F : CapsFromA st OS s s') include F @@ -202,8 +282,9 @@ theorem DevWinCapA.derivA (o : DevWinCapA st OS s) : DevWinCapA st OS s' := fun exact (o v hv).1 q b fi0 e, fun p sz r m e a v hc bits hb => by obtain ⟨w, hw, d⟩ := F.src hu hc (by simp) - obtain ⟨r0, m0, e0, a0, v0, e1⟩ := d.frame_back rfl - exact (o w hw).2 p sz r0 m0 e0 a0 v0 e1 bits hb⟩ + rcases d.frame_back rfl with ⟨r0, m0, e0, a0, v0, e1⟩ | ⟨hdv, -⟩ + · exact (o w hw).2 p sz r0 m0 e0 a0 v0 e1 bits hb + · cases hdv⟩ theorem UtZombieA.derivA (o : UtZombieA st OS s) : UtZombieA st OS s' := fun u hu p t n hc => by obtain ⟨v, hv, e⟩ := F.fixed hu (e := .Zombie p t n) trivial (by simp) hc @@ -246,43 +327,138 @@ theorem DevUtOffA.derivA {Z Z' : XSetsA} {H : Heap} {ia ie : Nat} (hk : L.ksb s' obtain ⟨v0, hv0, fi1, e', -⟩ := F.untyped hv hc' exact h.sep u0 hu0 q b fi0 e v0 hv0 q' b' fi1 e' -theorem FrBaseApartA.derivA (h : FrBaseApartA st OS s) : FrBaseApartA st OS s' := fun y hy z hz fy kz => by - have ny : capA st s' y ≠ .Null := fun e => by rw [e] at fy; cases fy - have nz : capA st s' z ≠ .Null := fun e => by - have h0 := physA_eq capability.Cap.Null - simp only [objects.cap_is_physical] at h0 - have := kz.1 - rw [e, ← okinj h0] at this - cases this - obtain ⟨y0, hy0, dy⟩ := F.src hy rfl ny - obtain ⟨z0, hz0, dz⟩ := F.src hz rfl nz - rw [dy.isFr] at fy - rw [dz.ptr, dy.ptr] - exact h y0 hy0 z0 hz0 fy (dz.rngKey.1 kz) - -theorem UserFrSpecA.derivA {σ σ' : Fl4SpecA64.State Unit} +theorem FrLamA.derivA (h : FrLamA st OS s) : FrLamA st OS s' := by + intro y hy p rt mp e asid va hc z hz pz + obtain ⟨y0, hy0, d⟩ := F.src hy hc (by simp) + obtain ⟨bY0, tY0⟩ := d.large_range rfl + have bY : baseA (capA st s' y) = baseA (capA st s y0) := by rw [hc]; exact bY0 + have tY : topA (capA st s' y) = topA (capA st s y0) := by rw [hc]; exact tY0 + obtain ⟨r0, m0, e0, a0, v0, e1⟩ | ⟨-, hsz, -⟩ := d.frame_back rfl + swap + · cases hsz + by_cases fz : isFrA (capA st s' z) = true + · rcases F.rev z hz fz with hr | ⟨v, hv, fv, bv, tv, hrv'⟩ + · exact Or.inr (Or.inl ⟨fz, hr⟩) + · rcases h y0 hy0 p r0 m0 e0 a0 v0 e1 v hv (isFrA_phys fv).1 with dj | ⟨f, r⟩ | w + · left; unfold DisjA at dj ⊢; rw [bv, tv, ← bY, ← tY] at dj; exact dj + · exact Or.inr (Or.inl ⟨fz, by rw [← hrv']; exact r⟩) + · right; right; unfold WithinA at w ⊢; rw [bv, tv, ← bY, ← tY] at w; exact w + · have nz : capA st s' z ≠ .Null := fun e' => by + have h0 := physA_eq capability.Cap.Null + simp only [objects.cap_is_physical] at h0 + rw [e', ← okinj h0] at pz + cases pz + obtain ⟨z0, hz0, dz⟩ := F.src hz rfl nz + have fz0 : isFrA (capA st s z0) = false := by rw [← dz.isFr]; simpa using fz + have bz : baseA (capA st s' z) = baseA (capA st s z0) ∧ topA (capA st s' z) = topA (capA st s z0) := by + rcases dz.range with r | ⟨f, -⟩ + · exact r + · exact absurd f fz + rcases h y0 hy0 p r0 m0 e0 a0 v0 e1 z0 hz0 (by rw [← dz.phys]; exact pz) with dj | ⟨f, -⟩ | w + · left; unfold DisjA at dj ⊢; rw [bz.1, bz.2, bY, tY]; exact dj + · rw [fz0] at f; cases f + · right; right; unfold WithinA at w ⊢; rw [bz.1, bz.2, bY, tY]; exact w + +theorem FrBaseApartA.derivA (h : FrBaseApartA st OS s) : FrBaseApartA st OS s' := by + have key : ∀ y ∈ OS, ∀ z ∈ OS, isFrA (capA st s' y) = true → RngKeyA (capA st s' z) → + ∃ y0 ∈ OS, ∃ z0 ∈ OS, isFrA (capA st s y0) = true ∧ RngKeyA (capA st s z0) ∧ + baseA (capA st s' z) = baseA (capA st s z0) ∧ + ((baseA (capA st s' y) = baseA (capA st s y0) ∧ topA (capA st s' y) = topA (capA st s y0)) ∨ + (baseA (capA st s y0) ≤ baseA (capA st s' y) ∧ baseA (capA st s' y) ≤ topA (capA st s' y) ∧ + topA (capA st s' y) ≤ topA (capA st s y0))) := by + intro y hy z hz fy kz + have ny : capA st s' y ≠ .Null := fun e => by rw [e] at fy; cases fy + have nz : capA st s' z ≠ .Null := fun e => by + have h0 := physA_eq capability.Cap.Null + simp only [objects.cap_is_physical] at h0 + have := kz.1 + rw [e, ← okinj h0] at this + cases this + obtain ⟨y0, hy0, dy⟩ := F.src hy rfl ny + obtain ⟨z0, hz0, dz⟩ := F.src hz rfl nz + have fz : isFrA (capA st s' z) = false := by + have := kz.2.2 + simpa using this + refine ⟨y0, hy0, z0, hz0, by rw [← dy.isFr]; exact fy, dz.rngKey.1 kz, by unfold baseA; rw [dz.ptr fz], ?_⟩ + rcases dy.range with r | ⟨-, r1, r2, r3⟩ + · exact Or.inl r + · exact Or.inr ⟨r1, r2, r3⟩ + refine ⟨fun y hy z hz fy kz e => ?_, fun y hy z hz fy kz => ?_, FrLamA.derivA F h.2.2⟩ + · obtain ⟨y0, hy0, z0, hz0, fy0, kz0, bz, hr⟩ := key y hy z hz fy kz + rcases hr with ⟨hb, -⟩ | ⟨r1, r2, r3⟩ + · have : baseA (capA st s' z) = baseA (capA st s' y) := by unfold baseA; rw [e] + have e0 : ptrA (capA st s z0) = ptrA (capA st s y0) := by + have : baseA (capA st s z0) = baseA (capA st s y0) := by rw [← bz, this, hb] + unfold baseA at this; exact UScalar.eq_of_val_eq this + exact h.1 y0 hy0 z0 hz0 fy0 kz0 e0 + · have hz' : baseA (capA st s' z) = baseA (capA st s' y) := by unfold baseA; rw [e] + by_cases hb : baseA (capA st s y0) = baseA (capA st s' y) + · have e0 : ptrA (capA st s z0) = ptrA (capA st s y0) := by + have : baseA (capA st s z0) = baseA (capA st s y0) := by rw [← bz, hz', hb] + unfold baseA at this; exact UScalar.eq_of_val_eq this + exact h.1 y0 hy0 z0 hz0 fy0 kz0 e0 + · refine h.2.1 y0 hy0 z0 hz0 fy0 kz0 ⟨?_, ?_⟩ + · rw [← bz, hz']; omega + · rw [← bz, hz']; omega + · obtain ⟨y0, hy0, z0, hz0, fy0, kz0, bz, hr⟩ := key y hy z hz fy kz + intro ⟨c1, c2⟩ + rcases hr with ⟨hb, ht⟩ | ⟨r1, r2, r3⟩ + · exact h.2.1 y0 hy0 z0 hz0 fy0 kz0 ⟨by rw [← hb, ← bz]; exact c1, by rw [← ht, ← bz]; exact c2⟩ + · have hne : baseA (capA st s y0) ≤ baseA (capA st s' y) := r1 + rcases Nat.lt_or_ge (baseA (capA st s y0)) (baseA (capA st s z0)) with hl | hg + · exact h.2.1 y0 hy0 z0 hz0 fy0 kz0 ⟨hl, by rw [← bz]; omega⟩ + · -- the range key's base is the source's base: excluded by the base clause + have hz1 : baseA (capA st s z0) = baseA (capA st s y0) := by rw [← bz]; omega + have e0 : ptrA (capA st s z0) = ptrA (capA st s y0) := by + unfold baseA at hz1; exact UScalar.eq_of_val_eq hz1 + exact h.1 y0 hy0 z0 hz0 fy0 kz0 e0 + +theorem UserFrSpecA.derivA {H : Heap} {σ σ' : Fl4SpecA64.State Unit} (dp : ∀ p dev pg, σ.kheap p = some (.archObj (.dataPage dev pg)) → σ'.kheap p = some (.archObj (.dataPage dev pg))) - (h : UserFrSpecA st OS s σ) : UserFrSpecA st OS s' σ' := by + (h : UserFrSpecA st H OS s σ) : UserFrSpecA st H OS s' σ' := by intro y hy p size rights mapped ept asid va hc obtain ⟨v, hv, d⟩ := F.src hy hc (by simp) - obtain ⟨r0, m0, e0, a0, v0, e⟩ := d.frame_back rfl - exact dp _ _ _ (h v hv p size r0 m0 e0 a0 v0 e) + rcases d.frame_back rfl with ⟨r0, m0, e0, a0, v0, e⟩ | ⟨-, hsz, p0, sz0, r0, m0, e0, a0, v0, k, hc0, hp, hk⟩ + · obtain ⟨b, pg, hb, hk, h1, h2⟩ := h v hv p size r0 m0 e0 a0 v0 e + exact ⟨b, pg, hb, dp _ _ _ hk, h1, h2⟩ + · subst hsz + obtain ⟨b, pg, hb, hk', h1, h2⟩ := h v hv p0 sz0 r0 m0 e0 a0 v0 hc0 + obtain ⟨bits0, hb0⟩ := frameBits_ex sz0 + obtain ⟨hk1, -⟩ := hk bits0 hb0 + have e0' := pageBits_frameSizeA sz0 bits0 hb0 + have e1' : Fl4SpecA64.pageBitsForSize (frameSizeOfA .Small) = 12 := by + first | rfl | (simp [frameSizeOfA, Fl4SpecA64.pageBitsForSize]; rfl) | simp [frameSizeOfA, Fl4SpecA64.pageBitsForSize] + rw [e0'] at h2 + rw [e1'] + have e12 : (2 : Nat) ^ 12 = 4096 := by norm_num + rw [e12] + exact ⟨b, pg, hb, dp _ _ _ hk', by omega, by omega⟩ theorem DevFrDisjA.derivA {H : Heap} {σ σ' : Fl4SpecA64.State Unit} (dp : ∀ p dev pg, σ.kheap p = some (.archObj (.dataPage dev pg)) → σ'.kheap p = some (.archObj (.dataPage dev pg))) (h : DevFrDisjA st H OS s σ) : DevFrDisjA st H OS s' σ' := by intro y hy p size rights mapped ept asid va hc k hk obtain ⟨v, hv, d⟩ := F.src hy hc (by simp) - obtain ⟨r0, m0, e0, a0, v0, e⟩ := d.frame_back rfl - obtain ⟨h1, dev, pg, h2⟩ := h v hv p size r0 m0 e0 a0 v0 e k hk - exact ⟨h1, dev, pg, dp _ _ _ h2⟩ + rcases d.frame_back rfl with ⟨r0, m0, e0, a0, v0, e⟩ | ⟨hdv, -⟩ + · obtain ⟨h1, dev, pg, h2⟩ := h v hv p size r0 m0 e0 a0 v0 e k hk + exact ⟨h1, dev, pg, dp _ _ _ h2⟩ + · cases hdv theorem FrThA.derivA {th th' : TypedHeapA} (thE : ∀ p z, th p = some (.other z) → th' p = some (.other z)) - (h : FrThA st th OS s) : FrThA st th' OS s' := - FrThA.ofSrc (fun y hy p size rights x1 x2 x3 x4 hc => by - obtain ⟨v, hv, d⟩ := F.src hy hc (by simp) - obtain ⟨r0, m0, e0, a0, v0, e⟩ := d.frame_back rfl - exact ⟨v, hv, r0, m0, e0, a0, v0, e⟩) thE h + (h : FrThA st th OS s) : FrThA st th' OS s' := fun y hy p size rights x1 x2 x3 x4 bits hc hb => by + obtain ⟨v, hv, d⟩ := F.src hy hc (by simp) + rcases d.frame_back rfl with ⟨r0, m0, e0, a0, v0, e⟩ | ⟨-, hsz, p0, sz0, r0, m0, e0, a0, v0, k, hc0, hp, hk⟩ + · obtain ⟨b0, len, hb0, g1, g2⟩ := h v hv p size r0 m0 e0 a0 v0 bits e hb + exact ⟨b0, len, thE _ _ hb0, g1, g2⟩ + · subst hsz + obtain ⟨bits0, hb0⟩ := frameBits_ex sz0 + obtain ⟨hk1, -⟩ := hk bits0 hb0 + obtain ⟨b0, len, hb1, g1, g2⟩ := h v hv p0 sz0 r0 m0 e0 a0 v0 bits0 hc0 hb0 + have e12 := smallBits hb + have e12' : (2 : Nat) ^ 12 = 4096 := by norm_num + refine ⟨b0, len, thE _ _ hb1, by omega, ?_⟩ + rw [e12, e12'] + omega theorem SpecZeroFreeA.derivA {σ σ' : Fl4SpecA64.State Unit} (um : σ'.machineState.underlyingMemory = σ.machineState.underlyingMemory) (h : SpecZeroFreeA st OS s σ) : diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapDerivCnA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapDerivCnA.lean new file mode 100644 index 000000000..2a4677f26 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3CapDerivCnA.lean @@ -0,0 +1,102 @@ +/- +P3 (AArch64, E0.5c): **`JStage3A` across slot writes that are all CNode-slot writes** — the tail of the CNode Copy arm +(`capInsertGenA`, Stage3ArmCnCopyA) as a lemma over the *composite* of the writes, so a run of `cap_insert`s +(`DeriveSubframe`) reuses it: the buffer words / fault-handler words / tables are kept because every changed slot is a +CNode slot (`hkeepC`), and `of_capDerivA` is applied once. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3ArmCnCopyA +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} + +set_option maxHeartbeats 4000000 in +/-- **`JStage3A` across CNode-slot writes** (module docstring). -/ +theorem JStage3A.of_capDerivCnA {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 s2 : S} {a : A} + {σ σ2 : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} {G' : MdbGhostA} + (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) + (w : WritesIn st s s2 (W7.CapW H.tcbs {b | InOS OS b} ∅)) + (F : CapsFromA st OS s s2) (HS : SpecSlotA σ σ2) (W : WfKeepA σ σ2) (hms : σ2.machineState = σ.machineState) + (hkeepC : ∀ y ∈ OS, (¬ ∃ sl : Fl4SpecA64.CslotPtr, y = cslotAddrA sl ∧ ∃ ps, sl.1 = specPtr ps ∧ + Z.th ps = some (.cnode sl.2.length)) → capA st s2 y = capA st s y) + (hcdtS : ∀ x y, σ2.cdt x = some y → ∀ sl, sl = x ∨ sl = y → + σ.kheap sl.1 ≠ none ∨ ∃ x0 y0, σ.cdt x0 = some y0 ∧ (sl = x0 ∨ sl = y0)) + (horig : ∀ x, σ2.isOriginalCap x = true → σ.kheap x.1 ≠ none ∨ σ.isOriginalCap x = true) + (origLive : ∀ sl, σ2.isOriginalCap sl = true → AbsSlotA Z.th sl) + (nullOrig : ∀ sl, specCapAtA σ2 sl = some .nullCap → σ2.isOriginalCap sl = false) + (hsc : ∀ sl a, specCapAtA σ2 sl = some a → (∃ sl0, specCapAtA σ sl0 = some a) ∨ NoIdleCapV m n a) + (hcn : ∀ sl c, specCapAtA σ2 sl = some c → specCapAtA σ sl = some c ∨ ∃ r cs, σ.kheap sl.1 = some (.cnode r cs)) + (symL : SymL st H Z.Cs s2) (sysl : SysL st H Z.Cs OS ia ie s2) + (jx : JAtZAX (L := L) AR { Z with G := G' } s2 a σ2 m) (sinv : SInvXA σ2 m n) + (j5 : J5A st { Z with G := G' } H OS s2 σ2 m) + (j7 : J7A st (J7R2A st ar nA) { Z with G := G' } H OS s2 σ2 m) : + JStage3A st AR { Z with G := G' } 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 J1 := J + have hO : OSOK H.tcbs H.omega H.frame OS := J1.sys.ent.os + have hP := J1.j.1.place + have E1 := J1.toJEntA + have hoff := footN_offA E1 + have hfal := FootNA.aligned J1.j.1 (bxi_nodes E1.sys.ent.bxi) E1.scAl E1.ap.vcAl + -- the buffer slots, the tables + have wA : WritesIn st s 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 sbS : ∀ t ∈ Z.T, sbWordA t ∈ OS := fun t ht => + J1.j5.2.1 _ ⟨t, Or.inr ⟨(J1.j.1.thT t).2 ht, 2, by simp [tcbSlotsA], (bufSlot_eqA t).symm⟩⟩ + have sbK : ∀ t ∈ Z.T, capA st s2 (sbWordA t) = capA st s (sbWordA t) := fun t ht => + hkeepC _ (sbS t ht) fun ⟨sl, e, ps, e1, hc⟩ => + cnSlot_ne_sbA hP e1 hc ((J1.j.1.thT t).2 ht) e + have ib : ∀ t ∈ Z.T, L.mem s2 (ibWordA t) = L.mem s (ibWordA t) := + fun t ht => fld t (by rw [J1.tcbs]; exact ht) 3512#u64 (by simp) (by simp) (by simp) + have bufCover : BufCover st Z.T Bf s2 σ2 := BufCover.mapA J1.bufCover J1.bufNative J1.j.1.st jx.1.st + (fun t ht => (J1.j.1.thT t).2 ht) HS ib (fun t ht => by rw [sbK t ht]; exact .refl _) + have bufNative : BufNativeA Z.T (L.mem s2) := BufNativeA.mapA J1.bufNative (fun t ht q sz' rr dv m' e' a' v' h => by + rw [sbK t ht] at h + have hb := J1.bufNative t ht + rw [bufSlot_eqA, capAtA_eq (st := st), h] at hb + exact hb) + have vk : ∀ Pt Ub : Set U64, VrOK H.omega H.frame H.scs H.scBits OS Z.V Ub (L.ksb s) Pt → + VsKeep st (L.ksb s) Pt s s2 := fun Pt Ub vr => + VsKeep.of_w vr.al w (fun b hb => J1.vsr_offCapWA vr hb) + have unmPt : UnmPtSpecA st { Z with G := G' } m OS s2 σ2 := by + obtain ⟨Pt, Ub, vr, -, -, -, -, -, -, link, -, -⟩ := J1.j7 + exact UnmPtSpecA.derivA F HS w.1 w.2.1 (vk Pt Ub vr) link + (fun p h => ⟨fun i hi hf => h.mem i hi (FootA.monoA + (Z := { Z with G := G', S1 := ∅ }) 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 w.1.symm w.2.1.symm hf)), h.obj⟩) J1.unmPt + have bufOff : BufOffA st { Z with G := G' } OS s2 Bf := + ⟨J1.bufOff.os, fun b hb => by rw [w.1]; exact J1.bufOff.vs b hb, + fun b hb q hq => J1.bufOff.page b hb q (SchedPageA.derivBackA F rfl rfl rfl rfl rfl hq), J1.bufOff.vcw, + fun bp hbp => (J1.bufOff.pin bp hbp).keepC rfl rfl fun t ht _ => sbK t ht⟩ + have hfh : ∀ t ∈ Z.T, capA st s2 (slotIdx t layout.tcb.SLOT_FAULT_HANDLER) = + capA st s (slotIdx t layout.tcb.SLOT_FAULT_HANDLER) := fun t ht => + hkeepC _ (J1.j5.2.1 _ (isSlot_fhA ((J1.j.1.thT t).2 ht))) fun ⟨sl, e, ps, e1, hc⟩ => + cnSlot_ne_fhA hP e1 hc ((J1.j.1.thT t).2 ht) e + have hvt : IdleSlotNewA σ σ2 m n := IdleSlotNewA.of_cnodeA J1.sidle fun sl c h => by + rcases hcn sl c h with h | ⟨r, cs, hk⟩ + · exact Or.inl h + · exact Or.inr ⟨_, cs, hk⟩ + exact J1.of_capDerivA (hsub := J1.j5.2.1) (hnul := J1.j5.2.2) (hfh := hfh) (hvt := hvt) + (symL := symL) w F HS W hms hoff hfal hcdtS horig origLive nullOrig hsc sysl jx sinv bufCover + bufNative unmPt bufOff j5 j7 + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapFrameA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapFrameA.lean index f90607b43..bb97b353b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapFrameA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapFrameA.lean @@ -313,17 +313,20 @@ theorem JStage3A.of_capFrame {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea (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) + (hptc : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) c) (hpt : ∀ p a v, c ≠ .PageTable p true a v) (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 (W7.CapW H.tcbs {b | InOS OS b} ∅) → JAtZAX (L := L) AR Z s2 a σ2 m → capA st s2 (cslotAddrA cte) = c → - CapFrameArmA st AR Z H OS U Ac Pp Tb Lv ia ie Bf Z.T (J7A st Rj) s2 σ2 m) : + CapFrameArmA st AR Z H OS U Ac Pp Tb Lv ia ie Bf Z.T (J7A st Rj) s2 σ2 m) + (hrt : RootSetA (capAtA (L.mem s) (cslotAddrA cte)) c := by root_nr) + (hptw : PtSetE Z.th (L.mem s) (cslotAddrA cte) c := by pt_nr) : ∃ 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 (W7.CapW H.tcbs {b | InOS OS b} ∅) ∧ JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st Rj) s2 a σ2 m := by have hO : OSOK H.tcbs H.omega H.frame OS := J.sys.ent.os obtain ⟨s2, σ2, hs2, hσ2, HS, w, jx, T2⟩ := - J.j.of_setcapA hO hsub hoff hal cte hab hEnc hca hT hnul hcn hc0 hM.ua hok + J.j.of_setcapA hO hsub hoff hal cte hab hEnc hca hT hnul hcn hc0 hM.ua hok hptc hrt hptw have hx : cslotAddrA cte ∈ OS := hsub _ (hab.isSlot J.j.1.place) obtain ⟨hcx, hco⟩ := capA_setCapA hO hx hEnc hs2 have hMs : ∀ u ∈ OS, MapAlikeA (capA st s2 u) (capA st s u) := fun u hu => by @@ -390,7 +393,7 @@ theorem JStage3A.of_capFrame {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea (fun v hv => w.mem_eq (hal _ (.vcpu v _ hv (Or.inr rfl))) (hoff _ (.vcpu v _ hv (Or.inr rfl)))) J.deadExt) (SpecFreeA.mapA hMs HS hcdt horig J.specFree) (UtBlk39A.mapA hMs J.utBlk) ar.unmPt (SpecZeroFreeA.mapA hMs um J.specZero) (fun sl h => J.origLive sl (by rw [← horig]; exact h)) nul - (FrBaseApartA.mapA hMs J.frBase) + (FrBaseApartA.mapA hMs (fun u hu => revA_of_wordA (hl u hu).2) J.frBase) (DevFrDisjA.mapA hMs (fun p dev pg h => HS.keep h (fun _ _ e => by cases e) (fun _ e => by cases e)) J.devFr) (FinCovA.ofWfA J.finCov HS W) (ZombieTcbNoVcpuA.mapA hMs J.zombieTcb twH J.zombieNoVcpu) (ZombieTcbTA.mapA hMs J.zombieTcb) ar.bufOff (UtZombieA.mapA hMs J.zombieBnd) diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapInsertBufA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapInsertBufA.lean index dfb98c3b9..25b0856ca 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapInsertBufA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapInsertBufA.lean @@ -37,7 +37,8 @@ theorem JStage3A.bufThA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {O ∀ k : U64, k.val < 128 → ∃ p len, Z.th p = some (.other len) ∧ p.val ≤ (bufW w k).val ∧ (bufW w k).val < p.val + len := fun k hk => by obtain ⟨u, hu, ptr, size, rights, x1, x2, x3, x4, bits, hc, hb, h1, h2⟩ := hl.2.2 k hk - exact ⟨ptr, 2 ^ bits.val, J.frTh u hu ptr size rights x1 x2 x3 x4 bits hc hb, h1, h2⟩ + obtain ⟨b0, len, hb0, g1, g2⟩ := J.frTh u hu ptr size rights x1 x2 x3 x4 bits hc hb + exact ⟨b0, len, hb0, by omega, by omega⟩ set_option maxHeartbeats 4000000 in /-- **`JStage3A` across a `cap_insert` of a derived frame cap into slot 2 of a TCB, growing the tracked buffers** @@ -54,7 +55,7 @@ theorem JStage3A.capInsertTcbBufA {AR : A → HwRootA → Prop} {Z : XSetsA} {H (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) {nc : capability.Cap} {anc : Fl4SpecA64.Cap} (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))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA 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))) @@ -100,7 +101,7 @@ theorem JStage3A.capInsertTcbBufA {AR : A → HwRootA → Prop} {Z : XSetsA} {H have h21 : tcbCnodeIndex 2 = tcbCnodeIndex 1 := by rw [hsd] at e; exact congrArg Prod.snd e exact absurd ((tcbIdx_eq (by simp [tcbSlotsA]) (by simp [tcbSlotsA])).1 h21) (by decide) 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 + hw hn hD hrd hal hk hsh hsh1 hbd1 hbd hirqB hirqN hirqA hz hut hdo hcv hsci symL sysl j7 obtain ⟨w0, F, HS, W, hms, hcdtS, horig, origLive, nullOrig, hsc, jx, sinv, j5', hvt, ek, ed, hfull⟩ := P have hO : OSOK H.tcbs H.omega H.frame OS := J.sys.ent.os have hP := J.j.1.place @@ -207,7 +208,7 @@ theorem JStage3A.capInsertTcbBufA {AR : A → HwRootA → Prop} {Z : XSetsA} {H fun b hb q hq => J.bufOff.page b hb q (SchedPageA.derivBackA F rfl rfl rfl rfl rfl hq), J.bufOff.vcw, pinOld⟩ have bufOff := BufOffA.insertA B0 hos (fun k hk => by rw [w0.1]; exact hvs k hk) (fun k hk p hq o o1 o2 => hpg k hk p (SchedPageA.derivBackA F rfl rfl rfl rfl rfl hq) o o1 o2) hvc - ⟨t0, ht0T, sbS t0 ht0T, ptr, size, rights, x1, false, x3, x4, bits, by rw [capNew, hncE], hbits, + ⟨hl.2.1, t0, ht0T, sbS t0 ht0T, ptr, size, rights, x1, false, x3, x4, bits, by rw [capNew, hncE], hbits, fun k hk => ⟨bufW_alignedLiveA hl.2.1 hk, (hrange k hk).1, (hrange k hk).2⟩⟩ have hfh : ∀ t ∈ Z.T, NullOrEp H (capA st s2 (slotIdx t layout.tcb.SLOT_FAULT_HANDLER)) := fun t ht => by have eaF : cslotAddrA (specPtr t, tcbCnodeIndex 3) = slotIdx t layout.tcb.SLOT_FAULT_HANDLER := by diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapInsertTA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapInsertTA.lean index 853da0dc8..76f4b2ad6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapInsertTA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapInsertTA.lean @@ -17,6 +17,7 @@ and idle-slot relations differ per slot. So this module proves the common part a No named premise (those of `capInsertGenA`). New module. -/ +import Fl4ProofsA64.P3.Stage3ArmCnMoveA import Fl4ProofsA64.P3.Stage3ArmCnCopyA import Fl4ProofsA64.P3.CnSlotSbA @@ -85,7 +86,7 @@ theorem JStage3A.capInsertPartsTA {AR : A → HwRootA → Prop} {Z : XSetsA} {H (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) {nc : capability.Cap} {anc : Fl4SpecA64.Cap} (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))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA nc (capA st s (cslotAddrA ss))) (hal : UA nc (capA st s (cslotAddrA ss))) (hk : SameBadgeKindA nc (capA st s (cslotAddrA ss))) (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)) @@ -153,9 +154,18 @@ theorem JStage3A.capInsertPartsTA {AR : A → HwRootA → Prop} {Z : XSetsA} {H fun s' w i hi => w.mem_eq (hfal _ (.irq i hi)) (hoff _ (.irq i hi)) have mJ := hJ5 hst0 σ rw [← hIns] at mJ - have mv := WP.spec_and (cap_insert_refinesA s σ Z.G J1.j.1.st J1.j.1.cdt hP hO hTr J1.j5.2.1 hnul hAs hAd - hsn cd0 hdc hwf hanc hw hn hal hk hut hub hsib) mJ - obtain ⟨s2, hs2, ⟨σ2, hm, hst2, hcdt2, -, HS, hcs2⟩, w, ed, hfull, ek, -⟩ := spec_existsA mv + have hsd0 : cslotAddrA ss ≠ cslotAddrA sd := fun e => hsn (by rw [e]; exact hdn) + have hsG0 : cslotAddrA ss ∈ Z.G.chains.flatten := (hTr.lk.members _).2 ⟨xs, hsn⟩ + have mB : cdt.insert st s nc (cslotAddrA ss) (cslotAddrA sd) ⦃ s' => + (∀ y ∈ OS, y ≠ cslotAddrA sd → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y ∧ + fbA st s' y = fbA st s y) ∧ + Fl4ProofsA64.P1.W7.R.ST.revA st s' (cslotAddrA sd) = revFA nc (capA st s (cslotAddrA ss)) ∧ + fbA st s' (cslotAddrA sd) = revFA nc (capA st s (cslotAddrA ss)) ⦄ := by + rw [hIns] + exact insWC_bitsA hO xs xd hsd0 rfl hw (fun h => ((hTr.lk.members _).1 ((hTr.lk.lkF hO.nz).nxm _ hsG0 h)).1) + have mv := WP.spec_and (WP.spec_and (cap_insert_refinesA s σ Z.G J1.j.1.st J1.j.1.cdt hP hO hTr J1.j5.2.1 hnul hAs hAd + hsn cd0 hdc hwf hanc hw hn (Or.inl hal) hk hut hub hsib) mJ) mB + obtain ⟨s2, hs2, ⟨⟨σ2, hm, hst2, hcdt2, -, HS, hcs2⟩, w, ed, hfull, ek, -⟩, hbk, hrb, -⟩ := spec_existsA mv have j5' : J5A st { 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 := by have mJ2 := hJ5 hst0 σ2 @@ -166,6 +176,9 @@ theorem JStage3A.capInsertPartsTA {AR : A → HwRootA → Prop} {Z : XSetsA} {H have jx : JAtZAX (L := L) AR { Z with G := (insGA Z.G (cslotAddrA ss) (cslotAddrA sd) (insBA σ ss (absCapA nc) (absCapA (capA st s (cslotAddrA ss))))) } s2 a σ2 m := by refine J1.j.of_slotWrites w (fun b hb' hb => hoff b hb hb') hfal _ HS hst2 hcdt2 (fun y hy => ?_) + (PtClosedA.ofTab (PtCapClosedA.of_ins (PtSrcA.of_deriv hsS hD) hcs2) + (TabClosedA.of_copy hcs2 + (RootCopyA.of_der (mem := L.mem s) hsS (by rw [capAtA_eq (st := st)]; exact hrd)))) rcases hcs2 y hy with e | e | ⟨p, b, i, d, e⟩ <;> rw [e] · exact J1.j.capObj hy · exact hno @@ -173,6 +186,8 @@ theorem JStage3A.capInsertPartsTA {AR : A → HwRootA → Prop} {Z : XSetsA} {H fun _ _ _ h => (by cases h), trivial⟩ have F : CapsFromA st OS s s2 := CapsFromA.of_insA xs xd hD cd0 ed hfull (fun p b i d h => hTr.ut.fib _ xs p b i d h) ek + (fun y hy hyd => (hbk y hy hyd).1) + (fun fr => by rw [hrb]; exact revFA_frame (by rw [ed] at fr; exact fr) _) -- the spec side obtain ⟨asc, hgs, -⟩ := getCap_eqA J1.j.1.st hAs obtain ⟨dc, hgd0, -⟩ := getCap_eqA J1.j.1.st hAd @@ -304,7 +319,7 @@ theorem JStage3A.capInsertPartsA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) {nc : capability.Cap} {anc : Fl4SpecA64.Cap} (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))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA 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))) @@ -366,7 +381,7 @@ theorem JStage3A.capInsertPartsA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : unfold insBA rw [J1.j.1.cdt.orig ss hAs] exact sbp_eqA _ _ _ hsh hsr hss hk hwf - exact JStage3A.capInsertPartsTA (J := J) ss sd hCs hAd hkd hsd1 hsn hdn hdc hwf hanc hw hn hD hal hk hut hdo hsci hno hoffN + exact JStage3A.capInsertPartsTA (J := J) ss sd hCs hAd hkd hsd1 hsn hdn hdc hwf hanc hw hn hD hrd hal hk hut hdo hsci hno hoffN (hub_ofA E1 hAs xs hd) (hsib_ofA J1.j.1.cdt hAs hd) hbeq (fun hst σ' => J5A.insGenA (σ' := σ') (m := m) (m' := m) hO J1.j5 hTr xs xd hsS hdS hsn cd0 hdc hw hsh1 hbd1 hirqB hirqN hirqA hut hzb hst) symL sysl j7 @@ -389,7 +404,7 @@ theorem JStage3A.capInsertTcbSlotGA {AR : A → HwRootA → Prop} {Z : XSetsA} { (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))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA 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))) @@ -426,7 +441,7 @@ theorem JStage3A.capInsertTcbSlotGA {AR : A → HwRootA → Prop} {Z : XSetsA} { obtain ⟨x', hk', -⟩ := J.j.1.st.tcb t0 ht0 rw [hsd]; simp [hk'] 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 + hw hn hD hrd 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 have hO : OSOK H.tcbs H.omega H.frame OS := J.sys.ent.os have hP := J.j.1.place @@ -526,7 +541,7 @@ theorem JStage3A.capInsertTcbSlotA {AR : A → HwRootA → Prop} {Z : XSetsA} {H (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))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA 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))) @@ -558,7 +573,7 @@ theorem JStage3A.capInsertTcbSlotA {AR : A → HwRootA → Prop} {Z : XSetsA} {H 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 + hdc hfh3 hwf hanc hw hn hD hrd 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/Stage3CapSlotA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapSlotA.lean index 5ba429f44..a08975de5 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapSlotA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapSlotA.lean @@ -179,7 +179,7 @@ theorem JStage3A.of_slotWBfA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea (zwf : DelInvA st Z.th s') (fhOK : ∀ t ∈ Z.T, NullOrEp H (capA st s' (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) (ptCapIn : PtCapInA { Z with G := G' } (L.mem s')) - (utWin : UtWinCapA st OS s') (devWin : DevWinCapA st OS s') (userFr : UserFrSpecA st OS s' σ') (frTh : FrThA st Z.th OS s') + (utWin : UtWinCapA st OS s') (devWin : DevWinCapA st OS s') (userFr : UserFrSpecA st H OS s' σ') (frTh : FrThA st Z.th OS s') (j5 : J5 { Z with G := G' } H OS s' σ' m) (j7 : J7A st Rj { Z with G := G' } H OS s' σ' m) : JStage3A st AR { Z with G := G' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf' stack κ n J5 (J7A st Rj) s' a σ' m := by @@ -493,7 +493,7 @@ theorem JStage3A.of_slotWA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (zwf : DelInvA st Z.th s') (fhOK : ∀ t ∈ Z.T, NullOrEp H (capA st s' (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) (ptCapIn : PtCapInA { Z with G := G' } (L.mem s')) - (utWin : UtWinCapA st OS s') (devWin : DevWinCapA st OS s') (userFr : UserFrSpecA st OS s' σ') (frTh : FrThA st Z.th OS s') + (utWin : UtWinCapA st OS s') (devWin : DevWinCapA st OS s') (userFr : UserFrSpecA st H OS s' σ') (frTh : FrThA st Z.th OS s') (j5 : J5 { Z with G := G' } H OS s' σ' m) (j7 : J7A st Rj { Z with G := G' } H OS s' σ' m) : JStage3A st AR { Z with G := G' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 (J7A st Rj) s' a σ' m := diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapVsA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapVsA.lean index e6a6220a3..ffd29cddf 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapVsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapVsA.lean @@ -188,7 +188,7 @@ theorem JStage3A.of_capVsGA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap (zwf : DelInvA st Z.th s') (fhOK : ∀ t ∈ Z.T, NullOrEp H (capA st s' (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) (ptCapIn : PtCapInA { Z with hw := hw, S1 := S1', Lv := Zl', T2 := T2', Sh2 := Sh2' } (L.mem s')) - (utWin : UtWinCapA st OS s') (devWin : DevWinCapA st OS s') (userFr : UserFrSpecA st OS s' σ') (frTh : FrThA st Z.th OS s') + (utWin : UtWinCapA st OS s') (devWin : DevWinCapA st OS s') (userFr : UserFrSpecA st H OS s' σ') (frTh : FrThA st Z.th OS s') (j5 : J5 { Z with hw := hw, S1 := S1', Lv := Zl', T2 := T2', Sh2 := Sh2' } H OS s' σ' m) (j7 : J7A st Rj { Z with hw := hw, S1 := S1', Lv := Zl', T2 := T2', Sh2 := Sh2' } H OS s' σ' m) (ap' : SlotApA { Z with hw := hw, S1 := S1', Lv := Zl', T2 := T2', Sh2 := Sh2' } H OS (L.ksb s')) @@ -534,7 +534,7 @@ theorem JStage3A.of_capVsA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (zwf : DelInvA st Z.th s') (fhOK : ∀ t ∈ Z.T, NullOrEp H (capA st s' (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) (ptCapIn : PtCapInA { Z with hw := hw } (L.mem s')) - (utWin : UtWinCapA st OS s') (devWin : DevWinCapA st OS s') (userFr : UserFrSpecA st OS s' σ') (frTh : FrThA st Z.th OS s') + (utWin : UtWinCapA st OS s') (devWin : DevWinCapA st OS s') (userFr : UserFrSpecA st H OS s' σ') (frTh : FrThA st Z.th OS s') (j5 : J5 { Z with hw := hw } H OS s' σ' m) (j7 : J7A st Rj { Z with hw := hw } H OS s' σ' m) : JStage3A st AR { Z with hw := hw } H OS U Ac' Pp Tb Lv ia ie N E Rp Bf stack κ n J5 (J7A st Rj) s' a' σ' m := by diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameA.lean index 840c8b1d9..3343b5b5d 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameA.lean @@ -177,12 +177,15 @@ theorem JStage3A.of_capVsFrameA {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) + (hptc : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) c) (hpt : ∀ p0 a0' v0', c ≠ .PageTable p0 true a0' v0') (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) → JAtZAX (L := L) AR Z s2 a σ2 m → capA st s2 (cslotAddrA cte) = c → ∃ (s' : S) (a' : A) (σ' : Fl4SpecA64.State Unit) (hw : HwRootA) (P : U64 → Prop) (Ac' : Set U64), - CapVsFinA st AR Z H OS U Ac' Pp Tb Lv ia ie Bf Rj s s2 s' a' σ2 σ' m hw P ∧ Q s' a' σ' hw) : + CapVsFinA st AR Z H OS U Ac' Pp Tb Lv ia ie Bf Rj s s2 s' a' σ2 σ' m hw P ∧ Q s' a' σ' hw) + (hrt : RootSetA (capAtA (L.mem s) (cslotAddrA cte)) c := by root_nr) + (hptw : PtSetE Z.th (L.mem s) (cslotAddrA cte) c := by pt_nr) : ∃ (s2 : S) (σ2 : Fl4SpecA64.State Unit) (s' : S) (a' : A) (σ' : Fl4SpecA64.State Unit) (hw : HwRootA) (P : U64 → Prop) (Ac' : Set U64), obj.Slot.set_cap st (cslotAddrA cte) s c = ok s2 ∧ ((), σ2) ∈ (setCap (Z := Unit) sc cte σ).1 ∧ @@ -193,7 +196,7 @@ theorem JStage3A.of_capVsFrameA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : have hO : OSOK H.tcbs H.omega H.frame OS := J.sys.ent.os have hH := J.sys.ent.heap obtain ⟨s2, σ2, hs2, hσ2, HS, w, jx, -⟩ := - J.j.of_setcapA hO hsub hoff hal cte hab hEnc hca hT hnul hcn hc0 hM.ua hok + J.j.of_setcapA hO hsub hoff hal cte hab hEnc hca hT hnul hcn hc0 hM.ua hok hptc hrt hptw have hx : cslotAddrA cte ∈ OS := hsub _ (hab.isSlot J.j.1.place) obtain ⟨hcx, hco⟩ := capA_setCapA hO hx hEnc hs2 have hMs : ∀ u ∈ OS, MapAlikeA (capA st s2 u) (capA st s u) := fun u hu => by @@ -332,7 +335,7 @@ theorem JStage3A.of_capVsFrameA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : (hoff _ (.vcpu v _ hv (Or.inr rfl))) (fun hp => vr.vc _ (V _ hp) ⟨v, hv, 24#u64, by simp, by simp, rfl⟩))) J.deadExt |>.vsA F.HS) ((SpecFreeA.mapA hMs' HS hcdt horig J.specFree).vsA F.HS) (UtBlk39A.mapA hMs' J.utBlk) F.unmPt (SpecZeroFreeA.mapA hMs' um2 J.specZero) (fun sl h => J.origLive sl (by rw [← horig']; exact h)) nul - (FrBaseApartA.mapA hMs' J.frBase) (DevFrDisjA.mapA hMs' hdp' J.devFr) + (FrBaseApartA.mapA hMs' (fun u hu => revA_of_wordA (hl u hu).2) J.frBase) (DevFrDisjA.mapA hMs' hdp' J.devFr) ((FinCovA.ofWfA J.finCov HS W).vsA F.HS) (ZombieTcbNoVcpuA.mapA hMs' J.zombieTcb twH' J.zombieNoVcpu) (ZombieTcbTA.mapA hMs' J.zombieTcb) F.bufOff (UtZombieA.mapA hMs' J.zombieBnd) diff --git a/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameGA.lean b/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameGA.lean index 137d8521c..f825d0301 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameGA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CapVsFrameGA.lean @@ -77,15 +77,18 @@ 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) + {Pj : Prop} (hptc : Pj → PtSrcA Z.th Z.S1 Z.T2 (L.mem s) c) (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) → - JAtZAX (L := L) AR Z s2 a σ2 m → capA st s2 (cslotAddrA cte) = c → + (Pj → JAtZAX (L := L) AR Z s2 a σ2 m) → StateRelA Z.th (L.mem s2) σ2 → capA st s2 (cslotAddrA cte) = c → ∃ (s' : S) (a' : A) (σ' : Fl4SpecA64.State Unit) (hw : HwRootA) (P : U64 → Prop) (Ac' : Set U64), CapVsFinGA st AR Z H OS U Ac' Pp Tb' Lv' ia ie Bf Rj s s2 s' a' σ2 σ' m hw P S1' T2' Zl' Sh2' Rp stack ∧ - Q s' a' σ' hw) : + Q s' a' σ' hw) + (hrt : RootSetA (capAtA (L.mem s) (cslotAddrA cte)) c := by root_nr) + (hptw : PtSetE Z.th (L.mem s) (cslotAddrA cte) c := by pt_nr) : ∃ (s2 : S) (σ2 : Fl4SpecA64.State Unit) (s' : S) (a' : A) (σ' : Fl4SpecA64.State Unit) (hw : HwRootA) (P : U64 → Prop) (Ac' : Set U64), obj.Slot.set_cap st (cslotAddrA cte) s c = ok s2 ∧ ((), σ2) ∈ (setCap (Z := Unit) sc cte σ).1 ∧ @@ -95,8 +98,8 @@ theorem JStage3A.of_capVsFrameGA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : a' σ' m ∧ Q s' a' σ' hw := by have hO : OSOK H.tcbs H.omega H.frame OS := J.sys.ent.os have hH := J.sys.ent.heap - obtain ⟨s2, σ2, hs2, hσ2, HS, w, jx, -⟩ := - J.j.of_setcapA hO hsub hoff hal cte hab hEnc hca hT hnul hcn hc0 hM.ua hok + obtain ⟨s2, σ2, hs2, hσ2, HS, w, jx, -, hst2⟩ := + J.j.of_setcapCondA hO hsub hoff hal cte hab hEnc hca hT hnul hcn hc0 hM.ua hok hptc hrt hptw have hx : cslotAddrA cte ∈ OS := hsub _ (hab.isSlot J.j.1.place) obtain ⟨hcx, hco⟩ := capA_setCapA hO hx hEnc hs2 have hMs : ∀ u ∈ OS, MapAlikeA (capA st s2 u) (capA st s u) := fun u hu => by @@ -104,7 +107,7 @@ theorem JStage3A.of_capVsFrameGA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : · subst e; rw [hcx]; exact hM · rw [hco u hu e]; exact .refl _ obtain ⟨hcdt, horig, hms⟩ := setCap_keepsA hσ2 - obtain ⟨s', a', σ', hw, P, Ac', F, hQ⟩ := arm s2 σ2 hs2 hσ2 HS w jx hcx + obtain ⟨s', a', σ', hw, P, Ac', F, hQ⟩ := arm s2 σ2 hs2 hσ2 HS w jx hst2 hcx obtain ⟨Pt, Ub, vr, -, -, -, -, -, -, link, -, -⟩ := J.j7 obtain ⟨Qb, Rb, q⟩ := J.sys.ent.bxi.1 have V : ∀ b, P b → VsR (L.ksb s) Pt b := F.hP Pt Ub vr link @@ -236,7 +239,7 @@ theorem JStage3A.of_capVsFrameGA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : (hoff _ (.vcpu v _ hv (Or.inr rfl))) (fun hp => vr.vc _ (V _ hp) ⟨v, hv, 24#u64, by simp, by simp, rfl⟩))) J.deadExt |>.vsA F.HS)) ((SpecFreeA.mapA hMs' HS hcdt horig J.specFree).vsA F.HS) (UtBlk39A.mapA hMs' J.utBlk) F.unmPt (SpecZeroFreeA.mapA hMs' um2 J.specZero) (fun sl h => J.origLive sl (by rw [← horig']; exact h)) nul - (FrBaseApartA.mapA hMs' J.frBase) (DevFrDisjA.mapA hMs' hdp' J.devFr) + (FrBaseApartA.mapA hMs' (fun u hu => revA_of_wordA (hl u hu).2) J.frBase) (DevFrDisjA.mapA hMs' hdp' J.devFr) ((FinCovA.ofWfA J.finCov HS W).vsA F.HS) (ZombieTcbNoVcpuA.mapA hMs' J.zombieTcb twH' J.zombieNoVcpu) (ZombieTcbTA.mapA hMs' J.zombieTcb) F.bufOff (UtZombieA.mapA hMs' J.zombieBnd) diff --git a/proofs/Fl4ProofsA64/P3/Stage3CnArmFactsA.lean b/proofs/Fl4ProofsA64/P3/Stage3CnArmFactsA.lean index aba2f271e..4a848df38 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CnArmFactsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CnArmFactsA.lean @@ -28,7 +28,22 @@ theorem DerivA.trans3 {a b c : capability.Cap} (h1 : DerivA a b) (h2 : DerivA b | ntfn => cases h2 <;> exact .ntfn .. | reply => cases h2 <;> exact .reply .. | cnode => cases h2 <;> exact .cnode .. - | frame => cases h2 <;> exact .frame .. + | frame => + cases h2 with + | refl => exact .frame .. + | frame => exact .frame .. + | sub p0 p1 sz0 r0 r1 m0 e0 a0 v0 m1 e1 a1 v1 k hp hk => exact .sub _ _ _ _ _ _ _ _ _ _ _ _ _ k hp hk + | sub p p' sz r r' m e a v m' e' a' v' k hp hk => + cases h2 with + | refl => exact .sub p p' sz r r' m e a v m' e' a' v' k hp hk + | frame => exact .sub p p' sz _ r' _ _ _ _ m' e' a' v' k hp hk + | sub p0 p1 sz0 r0 r1 m0 e0 a0 v0 m1 e1 a1 v1 k2 hp2 hk2 => + have h12 := (hk 12#u64 rfl).1 + have e12 : (2 : Nat) ^ (12#u64 : U64).val = 4096 := by decide + rw [e12] at h12 + have hk0 : k = 0 := by omega + subst hk0 + exact .sub _ _ _ _ _ _ _ _ _ _ _ _ _ k2 (by omega) hk2 | irqH i => cases h2; exact .irqH i | ut p b i i' dv h => cases h2 with @@ -686,6 +701,7 @@ theorem JSyscallA.cnCopy_armA hdn := emptySlot_nullA hemp, hdc := OSOK.canon hO hwin hdO, hw := hew, hn := hn, hD := cnode.copied_cap.derivA3 hcop hn, + hrd := cnode.copied_cap.rootDerivA3 hcop, hal := UA.of_shapeA hsh (fun hu => ut_of_absA hsh hu (hut' hu hn)), hk := sbk_of_shapeA hsh, hsh := hsh, hsh1 := hsh1, hbd1 := hbd1, hbd := hok.2.1, hirq := irqH_of_shapeA hsh, diff --git a/proofs/Fl4ProofsA64/P3/Stage3CnInsA.lean b/proofs/Fl4ProofsA64/P3/Stage3CnInsA.lean index 465143ba4..92ca57d56 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CnInsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CnInsA.lean @@ -266,12 +266,14 @@ theorem CapsFromA.of_insA {s s' : S} {src dest : U64} (hs : src ∈ OS) (hd : de {nc : capability.Cap} (hD : Fl4ProofsA64.P3.DerivA nc (capA st s src)) (hdn : capA st s dest = .Null) (ed : capA st s' dest = nc) (hf : FullA (capA st s' src) (capA st s src)) (hfi : ∀ p b i d, capA st s src = .Untyped p b i d → i.val ≤ 2 ^ b.val) - (ek : ∀ y ∈ OS, y ≠ src → y ≠ dest → capA st s' y = capA st s y) : CapsFromA st OS s s' := by + (ek : ∀ y ∈ OS, y ≠ src → y ≠ dest → capA st s' y = capA st s y) + (hr : ∀ y ∈ OS, y ≠ dest → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) + (hrd : isFrA (capA st s' dest) = true → Fl4ProofsA64.P1.W7.R.ST.revA st s' dest = false) : CapsFromA st OS s s' := by have hDs : Fl4ProofsA64.P3.DerivA (capA st s' src) (capA st s src) := by rcases hf with e | ⟨p, b, i, d, i1, h1, h2, hi⟩ · rw [e]; exact .refl _ · rw [h1, h2]; exact .ut p b i i1 d (by have := hfi p b i d h1; omega) - refine ⟨fun u hu => ?_, fun v hv => ?_⟩ + refine ⟨fun u hu => ?_, fun v hv => ?_, fun u hu fu => ?_⟩ · by_cases e1 : u = src · exact Or.inr ⟨src, hs, by rw [e1]; exact hDs⟩ by_cases e2 : u = dest @@ -282,6 +284,18 @@ theorem CapsFromA.of_insA {s s' : S} {src dest : U64} (hs : src ∈ OS) (hd : de by_cases e2 : v = dest · exact Or.inl (e2 ▸ hdn) exact Or.inr ⟨v, hv, by rw [ek v hv e1 e2]; exact .refl _⟩ + · by_cases e2 : u = dest + · exact Or.inl (by rw [e2] at fu ⊢; exact hrd fu) + right + by_cases e1 : u = src + · subst e1 + rcases hf with e | ⟨p, b, i, d, i1, h1, h2, hi⟩ + · have e' : capA st s' u = capA st s u := by first | exact e | exact e.symm + rw [e'] at fu + exact ⟨u, hu, fu, by rw [e'], by rw [e'], (hr u hu e2).symm⟩ + · rw [h2] at fu; simp [isFrA] at fu + · rw [ek u hu e1 e2] at fu + exact ⟨u, hu, fu, by rw [ek u hu e1 e2], by rw [ek u hu e1 e2], (hr u hu e2).symm⟩ end diff --git a/proofs/Fl4ProofsA64/P3/Stage3CnInsSubA.lean b/proofs/Fl4ProofsA64/P3/Stage3CnInsSubA.lean new file mode 100644 index 000000000..c5aca4665 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3CnInsSubA.lean @@ -0,0 +1,119 @@ +/- +P3 (AArch64, E0.5b): **the J5 slot across `cdt::insert_with_cap` of a subframe** — `J5A.insA`'s sibling with the +`SubInsCtxA` of A64 P1's `MdbInvSubA` (the alias is a frame cap inside the large frame cap's range, the source's cap is +kept) in place of `InsCtxA`; the range hypothesis `hno` is `FrLamA` at the large frame cap. + +Named premises: none. New module. +-/ +import Fl4ProofsA64.P3.Stage3CnInsA +import Fl4ProofsA64.P1.MdbInvSubA +import Fl4ProofsA64.P1.S1aSubTree +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4SpecA64 Classical + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {T Ω Sg OS : Set U64} + +set_option maxHeartbeats 2000000 in +/-- **The concrete J5 slot across `cdt::insert_with_cap` of a subframe** (module docstring). -/ +theorem J5A.insSubA {Z : XSetsA} {H : Heap} {s : S} {σ σ' : Fl4SpecA64.State Unit} {m m' : Fl4SpecA64.McState} + (hO : OSOK H.tcbs H.omega H.frame OS) (J : J5A st Z H OS s σ m) + (hT : TreeA st OS Z.G.chains Z.G.par s) {src dest : U64} (hsrc : src ∈ OS) (hd : dest ∈ OS) + (hSs : IsSlotA Z.th src) (hSd : IsSlotA Z.th dest) + (hsn : capA st s src ≠ .Null) (hdn : capA st s dest = .Null) (hdc : obj.sext48 dest = ok dest) + {nc : capability.Cap} (hw : CapRt.EncWf nc) + (hS : SubA nc (capA st s src)) (hsF : isFrA (capA st s src) = true) (hcF : isFrA nc = true) + (hno : ∀ x ∈ Z.G.chains.flatten, physA (capA st s x) = true → + DisjA (capA st s x) (capA st s src) ∨ (isFrA (capA st s x) = true ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s x = false) ∨ + WithinA (capA st s src) (capA st s x)) + (hst : ∀ s', WritesIn st s s' (W7.CapW H.tcbs {b | InOS OS b} ∅) → + ∀ i : U64, i.val < 5376 → L.mem s' (irqStAddrA (L.ksb s) i) = L.mem s (irqStAddrA (L.ksb s) i)) : + cdt.insert_with_cap st s nc (capA st s src) src dest ⦃ s' => + WritesIn st s s' (W7.CapW H.tcbs {b | InOS OS b} ∅) ∧ capA st s' dest = nc ∧ + FullA (capA st s' src) (capA st s src) ∧ (∀ y ∈ OS, y ≠ src → y ≠ dest → capA st s' y = capA st s y) ∧ + J5A st { Z with G := ⟨insG src dest Z.G.chains, insParA Z.G.par src dest + (isPFA (Fl4ProofsA64.P1.W7.R.ST.revA st s src) (capA st s src) nc (revFA nc (capA st s src)))⟩ } H OS s' σ' m' ⦄ := by + have F := hT.lk.lkF hO.nz + have inOS : ∀ y ∈ Z.G.chains.flatten, y ∈ OS := fun y hy => ((hT.lk.members y).1 hy).1 + have hsG : src ∈ Z.G.chains.flatten := (hT.lk.members _).2 ⟨hsrc, hsn⟩ + have hdG : dest ∉ Z.G.chains.flatten := fun h => ((hT.lk.members _).1 h).2 hdn + have hsd : src ≠ dest := fun e => hdG (e ▸ hsG) + have hnN : NxA st s src ≠ 0#u64 → NxA st s src ∈ OS := fun h => inOS _ (F.nxm _ hsG h) + refine WP.spec_mono (WP.spec_and (WP.spec_and + (cdt.insert_with_cap.lrF (osokA hO) (LR.self s) hsrc hd hsd hdc rfl hsn hw hnN) + (cdt.insert_with_cap.srcF hO hsrc hd hsd rfl hw hnN)) + (insWC_bitsA hO hsrc hd hsd rfl hw hnN)) ?_ + rintro s' ⟨⟨⟨w, hL, ed, -, -, ek, -⟩, hfull⟩, hbk, hrd, hfd⟩ + have hxk : capA st s' src = capA st s src := by + rcases hfull with e | ⟨p, b, i, d, i1, h1, h2, -⟩ + · first | exact e | exact e.symm + · rw [h1] at hsF; simp [isFrA] at hsF + have hirq : ∀ i, nc = .IrqHandler i ↔ capA st s src = .IrqHandler i := fun i => + ⟨fun h => by rw [h] at hcF; simp [isFrA] at hcF, fun h => by rw [h] at hsF; simp [isFrA] at hsF⟩ + have aOS : ∀ a, (a = dest ∨ a ∈ Z.G.chains.flatten) → a ∈ OS := fun a ha => ha.elim (fun e => e ▸ hd) (inOS a) + have C : SubInsCtxA st OS Z.G.chains Z.G.par s s' src dest nc := by + refine ⟨hT.lk, hT.tree, J.1.1, hsG, hdG, fun a ha => ?_, fun a ha => ?_, fun a ha => ?_, fun a ha => ?_, + hsF, hcF, hS.reg, hS.win, hno⟩ + · have e := (hL a (aOS a ha)).2 + rw [e] + by_cases e1 : a = dest <;> by_cases e2 : a = src <;> simp [e1, e2, hsd, Ne.symm hsd] + · by_cases e1 : a = dest + · rw [if_pos e1, e1]; exact ed + · rw [if_neg e1] + by_cases e2 : a = src + · rw [e2]; exact hxk + · exact ek a (aOS a ha) e2 e1 + · by_cases e1 : a = dest + · rw [if_pos e1, e1]; exact hrd + · rw [if_neg e1]; exact (hbk a (aOS a ha) e1).1 + · by_cases e1 : a = dest + · rw [if_pos e1, e1]; exact hfd + · rw [if_neg e1]; exact (hbk a (aOS a ha) e1).2 + have hk : ∀ y ∈ Z.G.chains.flatten, ∀ i, capA st s' y = .IrqHandler i ↔ capA st s y = .IrqHandler i := + fun y hy i => by + by_cases e2 : y = src + · rw [e2, hxk] + · rw [ek y (inOS y hy) e2 (C.dne hy)] + refine ⟨w, ed, hfull, ek, ⟨C.inv, ?_, ?_⟩, J.2.1, fun y hy hns => ?_⟩ + · exact Fl4ProofsA64.P1.W7.R.ST.IrqRunA.ins J.1.2.1 hT.lk.nodup hsG hdG hk + (fun i h => Or.inl ((hirq i).1 (ed.symm.trans h))) (fun i h => ed.trans ((hirq i).2 h)) + · exact Fl4ProofsA64.P1.W7.R.ST.HandlersActiveA.ins_derived J.1.2.2 hsG (fun y hy i h => (hk y hy i).1 h) + (fun i h => (hirq i).1 (ed.symm.trans h)) w.1 (hst s' w) + · have f1 : y ≠ src := fun e => hns (e ▸ hSs) + have f2 : y ≠ dest := fun e => hns (e ▸ hSd) + rw [ek y hy f1 f2]; exact J.2.2 y hy hns + + +theorem u64_beqA' (x y : U64) : (x == y) = decide (x.bv = y.bv) := by + rw [Bool.eq_iff_iff]; simp [UScalar.eq_equiv_bv_eq] + +/-- **FL4's parent bit is l4v's `should_be_parent_of` for a frame cap inserted from a frame cap** (the alias of +`DeriveSubframe`; `sbp_eqA` needs the same shape, which an alias does not have). -/ +theorem sbp_eqFrA (sc nc : capability.Cap) (io : Bool) (hsF : isFrA sc = true) (hcF : isFrA nc = true) + (hsr : Fl4SpecA64.sameRegionAs (absCapA sc) (absCapA nc)) (hss : sraA sc nc = true) + (hk : SameBadgeKindA nc sc) (hw : CapWfA nc) : + decide (Fl4SpecA64.shouldBeParentOf (absCapA sc) io (absCapA nc) + (decide (Fl4SpecA64.isCapRevocable (absCapA nc) (absCapA sc)))) = isPFA io sc nc (revFA nc sc) := by + have hrv : decide (Fl4SpecA64.isCapRevocable (absCapA nc) (absCapA sc)) = revFA nc sc := by + have := revFA_spec nc sc hk hw + cases h : revFA nc sc <;> simp_all + rw [hrv] + unfold Fl4SpecA64.shouldBeParentOf isPFA + rw [hss] + simp only [eq_true hsr, true_and, Bool.and_true] + obtain ⟨p1, s1, r1, d1, m1, e1, a1, v1, rfl⟩ := isFrA_ex hsF + obtain ⟨p2, s2, r2, d2, m2, e2, a2, v2, rfl⟩ := isFrA_ex hcF + cases e1 <;> cases e2 <;> cases io <;> simp [absCapA, absFrameE, isBadgedA, revFA, Fl4SpecA64.shouldBeArchParentOf, + Fl4SpecA64.ArchCap.isSGISignalCap, Fl4SpecA64.ArchCap.isSMCCap, Fl4SpecA64.ArchCap.acapSmcBadge] + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3CnMoveA.lean b/proofs/Fl4ProofsA64/P3/Stage3CnMoveA.lean index 5f61a67c6..91c0d9ec0 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3CnMoveA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3CnMoveA.lean @@ -134,12 +134,56 @@ theorem moveCap_fbA (hO : OSOK T Ω Sg OS) {s : S} {src dest : U64} {nc : capabi rw [e] cases fbA st s src <;> rfl +/-! ## The revocable bit across the MDB operations (E0.5b) -/ + +theorem revA_of_rvbA {s s' : S} {y z : U64} + (h : L.mem s' (wa y 24#u64) &&& (281474976710656#u64 : U64) = (if ((L.mem s (wa z 24#u64) &&& (281474976710656#u64 : U64)) != 0#u64) then (281474976710656#u64 : U64) else 0#u64)) : + Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s z := by + unfold Fl4ProofsA64.P1.W7.R.ST.revA + have h' : L.mem s' (wa y 24#u64) &&& (281474976710656#u64 : U64) = + (if ((L.mem s (wa z 24#u64) &&& (281474976710656#u64 : U64)) != 0#u64) then 281474976710656#u64 + else 0#u64) := h + rw [h'] + cases ((L.mem s (wa z 24#u64) &&& (281474976710656#u64 : U64)) != 0#u64) <;> rfl + +theorem revA_of_rvb_eqA {s s' : S} {y : U64} + (h : L.mem s' (wa y 24#u64) &&& (281474976710656#u64 : U64) = L.mem s (wa y 24#u64) &&& (281474976710656#u64 : U64)) : + Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y := by + unfold Fl4ProofsA64.P1.W7.R.ST.revA + have h' : L.mem s' (wa y 24#u64) &&& (281474976710656#u64 : U64) = L.mem s (wa y 24#u64) &&& 281474976710656#u64 := h + rw [h'] + +/-- **`move_cap` and the revocable bit**: the others' are kept, `dest` takes `src`'s. -/ +theorem moveCap_revA (hO : OSOK T Ω Sg OS) {s : S} {src dest : U64} {nc : capability.Cap} + (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) (hw : CapRt.EncWf nc) + (hpP : L.mem s (wa src 16#u64) ≠ 0#u64 → L.mem s (wa src 16#u64) ∈ OS) + (hnN : NxA st s src ≠ 0#u64 → NxA st s src ∈ OS) : + cdt.move_cap st s nc src dest ⦃ s' => + (∀ y ∈ OS, y ≠ src → y ≠ dest → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) ∧ + Fl4ProofsA64.P1.W7.R.ST.revA st s' dest = Fl4ProofsA64.P1.W7.R.ST.revA st s src ⦄ := + WP.spec_mono (moveCap_bitA hO hsrc hd hsd hw hpP hnN) + (fun _ h => ⟨fun y hy e1 e2 => revA_of_rvb_eqA (h.1 y hy e1 e2), revA_of_rvbA h.2.1⟩) + +/-- **`move_cap` and the revocable bit**, over the tree (`moveCap_revA`). -/ +theorem moveCap_revT (hO : OSOK T Ω Sg OS) {s : S} {G : List (List U64)} {par : U64 → Option U64} + (hT : TreeA st OS G par s) {src dest : U64} {nc : capability.Cap} + (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) (hsn : capA st s src ≠ .Null) (hw : CapRt.EncWf nc) : + cdt.move_cap st s nc src dest ⦃ s' => + (∀ y ∈ OS, y ≠ src → y ≠ dest → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) ∧ + Fl4ProofsA64.P1.W7.R.ST.revA st s' dest = Fl4ProofsA64.P1.W7.R.ST.revA st s src ⦄ := by + have F := hT.lk.lkF hO.nz + have inOS : ∀ y ∈ G.flatten, y ∈ OS := fun y hy => ((hT.lk.members y).1 hy).1 + have hsG : src ∈ G.flatten := (hT.lk.members _).2 ⟨hsrc, hsn⟩ + exact moveCap_revA hO hsrc hd hsd hw (fun h => inOS _ (F.pvm _ hsG h)) (fun h => inOS _ (F.nxm _ hsG h)) + /-- The slot caps after a move: `dest` holds the new cap (derived from the source's), the source is null. -/ theorem CapsFromA.of_moveA {s s' : S} {src dest : U64} (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) {nc : capability.Cap} (hn : DerivA nc (capA st s src)) (hdn : capA st s dest = .Null) (ed : capA st s' dest = nc) (es : capA st s' src = .Null) - (ek : ∀ y ∈ OS, y ≠ src → y ≠ dest → capA st s' y = capA st s y) : CapsFromA st OS s s' := by - refine ⟨fun u hu => ?_, fun v hv => ?_⟩ + (ek : ∀ y ∈ OS, y ≠ src → y ≠ dest → capA st s' y = capA st s y) (hal : UA nc (capA st s src)) + (hr : ∀ y ∈ OS, y ≠ src → y ≠ dest → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) + (hrd : Fl4ProofsA64.P1.W7.R.ST.revA st s' dest = Fl4ProofsA64.P1.W7.R.ST.revA st s src) : CapsFromA st OS s s' := by + refine ⟨fun u hu => ?_, fun v hv => ?_, fun u hu fu => ?_⟩ · by_cases e1 : u = src · exact Or.inl (e1 ▸ es) by_cases e2 : u = dest @@ -150,6 +194,16 @@ theorem CapsFromA.of_moveA {s s' : S} {src dest : U64} (hsrc : src ∈ OS) (hd : by_cases e2 : v = dest · exact Or.inl (e2 ▸ hdn) exact Or.inr ⟨v, hv, by rw [ek v hv e1 e2]; exact .refl _⟩ + · by_cases e1 : u = src + · rw [e1, es] at fu; simp [isFrA] at fu + by_cases e2 : u = dest + · right + rw [e2, ed] at fu + exact ⟨src, hsrc, by rw [← hn.isFr]; exact fu, by rw [e2, ed]; exact hal.base.symm, + by rw [e2, ed]; exact hal.top.symm, by rw [e2]; exact hrd.symm⟩ + · right + exact ⟨u, hu, by rw [← ek u hu e1 e2]; exact fu, by rw [ek u hu e1 e2], by rw [ek u hu e1 e2], + (hr u hu e1 e2).symm⟩ /-- **The concrete J5 slot across `cdt::move_cap`** (module docstring). -/ theorem J5A.moveA {Z : XSetsA} {H : Heap} {s : S} {σ σ' : Fl4SpecA64.State Unit} {m m' : Fl4SpecA64.McState} diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrAllA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrAllA.lean index 954ef8bf8..2a8f26dd7 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrAllA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrAllA.lean @@ -5,7 +5,7 @@ P3 (aarch64, A64-P3 Stage 3 assembly): **`DecErrSpecA` for every cap**, from the Named premises: the union of the pieces', none new. [P] `ArchTotal`, `ArchPlat`, `ArchKeepsA`, `MaxSpi`, `IrqPlatA`, `ScCfgTimeAgreeA`, `VcpuPlatAgreeA`, `VcpuArchKeepsA`, `A64FrameMasks`, `hfan`, `hv`, `S2IpaE`, `numDomains = 1`; [S] `numNodes = 1`, `hCs`, `hCsN`, the VCPU `hNoS2` / `hAgreeWS` / `hAgreeRun`; [J] `hsb`, `hYAs`, `hFI`, `hcO`, `hD`, -`hPtMap`, `hFrMap`, `hFrSub`, `hAsidAssign`. Taken from the record here: `PtCapInA`, `hvcR`, the Domain piece's +`hPtMap`, `hFrMap`, `hAsidAssign`. Taken from the record here: `PtCapInA`, `hvcR`, the Domain piece's schedule facts. New module. @@ -53,7 +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 : PtMapSiteA st Z H OS σ s) (hFrMap : FrMapSiteA st OS s) (hFrSub : FrSubSiteA st Z OS s) + (hPtMap : PtMapSiteA st Z H OS σ s) (hFrMap : FrMapSiteA st 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 → @@ -86,7 +86,7 @@ theorem _root_.Fl4ProofsA64.P3.JSyscallA.decErrSpecA rwa [h0] at this refine DecErrSpecA.of_groups (DecErrSpecPA.untyped hA J hfm hfan hv) (DecErrSpecPA.cnode hA J) (DecErrSpecPA.schedCtl hA hT J hsb) - (DecErrSpecPA.archVs K J hvcR hYAs hIpa J.ptCapIn hFI hcO hD hPtMap hFrMap hFrSub hAsidAssign) + (DecErrSpecPA.archVs K J hvcR hYAs hIpa J.ptCapIn hFI hcO hD hPtMap hFrMap hAsidAssign) (DecErrSpecPA.rest_of J.j.1.place ?_) intro info buf r1 e x s' a' mi sl c excaps buffer args h1' h2 h3 h4 hd hne hR -- the open Rest caps: page tables, Domain, IRQControl, Thread, SchedContext, VCPU diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrBaseA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrBaseA.lean index 15700f808..56b6cf286 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrBaseA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrBaseA.lean @@ -39,17 +39,6 @@ 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. -/ diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrPtA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrPtA.lean index 3375c8d50..87006383e 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrPtA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrPtA.lean @@ -153,6 +153,7 @@ theorem DecErrSpecPA.pageTable (K : ArchKeepsA ar AR) (by cases hc; subst hmp; rw [← hsl]; exact hcp)) (fun _ _ _ _ _ _ _ _ h => by cases h) (fun _ _ _ _ _ _ _ _ h => by cases h) (fun _ _ h => by cases h) + (fun sl' hab' ptr' asid' va' hc hf' => J.finPtOtherA hab' hc hf') 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 rw [← hsl]; exact hd diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrVcpuA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrVcpuA.lean index 79b467bfd..e53a29762 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrVcpuA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrVcpuA.lean @@ -46,9 +46,9 @@ section variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} {s s' : S} {a a' a1 : A} {σ : State Unit} {x y : error.Exc} -/-- `smSize` at the width of `U64.bv`. -/ -abbrev smSizeU : BitVec UScalarTy.U64.numBits := smSize - +/-- `smSize` at the width of `U64.bv`. -/ +abbrev smSizeU : BitVec UScalarTy.U64.numBits := smSize + private theorem errInj0 {s1 : S} (h : (ok (core.result.Result.Err y, s1, a1) : Result (core.result.Result Unit error.Exc × S × A)) = ok (.Err x, s', a')) : x = y := by @@ -86,7 +86,7 @@ private theorem invCapA {α : Type} {d : SEMonad Unit α} (hx : x = .Sys (.Inval /-! ## `SetTCB` -/ -set_option maxHeartbeats 2000000 in +set_option maxHeartbeats 2000000 in theorem vcpuSetTcb.decErrA {vc : U64} {ex : Array obj.Slot 3#usize} {th : TypedHeapA} {kb : U64} (hPl : PlaceA th kb) {extras : List (Cap × CslotPtr)} (hEx : ExtraOKA th (L.mem s) ex extras) (h : vcpu.decode_set_tcb st ar s a vc ex = ok (.Err x, s', a')) : @@ -119,7 +119,7 @@ theorem vcpuSetTcb.decErrA {vc : U64} {ex : Array obj.Slot 3#usize} {th : TypedH rw [hc] at h; dsimp only at h exfalso repeat (first | (with_reducible exact (noOkA h).elim) | (rw [if_pos rfl] at h) | (rw [if_neg Bool.false_ne_true] at h) | (dsimp only [Bool.false_eq_true, eq_self, ↓reduceIte] at h) | (rw [eq_of_spec_fd Fl4ProofsA64.P0.Consts.layout.tcb.RUN_VCPU.spec, bind_ok] at h) | (refine (bind_eq_ok h).elim fun p hp => ?_; obtain ⟨-, h⟩ := hp; (try obtain ⟨_, _⟩ := p))) - exact noOkA h + exact noOkA h | PageTable p m asid va => rw [hc] at h habs; dsimp only at h refine ill (errInjA h) fun t e => ?_ @@ -194,7 +194,7 @@ private theorem windowErrA {off bits : U64} (hb : bits.val < 64) rw [BitVec.toNat_sub_of_le (by exact Nat.le_of_lt hlt)]; rfl have hc : fl4_abi.consts.vcpu_state_mask.SIZE.val = 1024 := by unfold fl4_abi.consts.vcpu_state_mask.SIZE; rfl - have hsm : smSize.toNat = 1024 := rfl + have hsm : smSize.toNat = 1024 := rfl have hsmU : smSizeU.toNat = 1024 := rfl by_cases hsmall : (⟨BitVec.ofNat 64 (size1.val - off.val)⟩ : U64) < fl4_abi.consts.vcpu_state_mask.SIZE · rw [if_pos hsmall] at h @@ -234,11 +234,9 @@ private theorem vgicNoneA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} specPtr (wa ptr off) = specPtr ptr + off.bv ∧ readVgicFrame (specPtr (wa ptr off)) σ = ({(none, σ)}, False) := by have J3 := J.toJStage3A obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits7, KLv, W⟩ := J7A.unp J3.j7 - have hH : H ptr = some (.other bits.val) := W.cc.fo y hy ptr sz rt mp ept asid va hc bits hbits - have hfit : ptr.val + 2 ^ bits.val ≤ 2 ^ 64 := by - have := J3.sys.ent.heap.fits ptr _ hH; simpa [HKind.bits] using this - have hal : ptr.val % 2 ^ bits.val = 0 := by - have := J3.sys.ent.heap.align ptr _ hH; simpa [HKind.bits] using this + have hH : FrAt H ptr bits := W.cc.fo y hy ptr sz rt mp ept asid va hc bits hbits + have hfit : ptr.val + 2 ^ bits.val ≤ 2 ^ 64 := hH.fits J3.sys.ent.heap + have hal : ptr.val % 2 ^ bits.val = 0 := hH.al J3.sys.ent.heap have hal8 : ptr.val % 8 = 0 := by have h8 : 8 ∣ 2 ^ bits.val := ⟨2 ^ (bits.val - 3), by rw [show (8 : Nat) = 2 ^ 3 from rfl, ← Nat.pow_add]; congr 1; omega⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3DecErrVsA.lean b/proofs/Fl4ProofsA64/P3/Stage3DecErrVsA.lean index 77ed36537..03f2a7362 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DecErrVsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DecErrVsA.lean @@ -1,11 +1,12 @@ /- P3 (aarch64, A64-P3 Lift 1b, batch a): **`DecErrSpecPA` for the VSpace / ASID / Frame caps**, from `decInv_arch_jA`. -`decInv_arch_jA`'s `Err` branch (`ArchDecTopPostA`) is the spec's error with the state kept: FL4's `Err x` is `VsErrRelA`-related +`decInv_arch_jA`'s `Err` branch (`VsErrPostA`) is the spec's error with the state kept: FL4's `Err x` is `VsErrRelA`-related to an `e'` the spec decode of the same cap and message returns. The record supplies `JEntA`, `RsSiteA`, `TreeA`, `hnul`, the slot facts and `ksbAligned`/`offAsE`/`tabS1`/`tabExt` as in `Stage3LiftFlushA`; everything the theorem asks beyond that is a premise of this one (the same names as `decInv_arch_jA`'s): [P] `K` (`ArchKeepsA`), [P] `hIpa` (`S2IpaE`), [J] `hvcR`, -`hYAs`, `hPC`, `hFI`, `hcO`, `hD` (`DeadDrop4KA`), `hPtMap`, `hFrMap`, `hFrSub`, `hAsidAssign`. +`hYAs`, `hPC`, `hFI`, `hcO`, `hD` (`DeadDrop4KA`), `hPtMap`, `hFrMap`, `hAsidAssign` (E0.5c: the subframe site's 2 MiB alignment / canonicality of a Large RAM frame +cap is derived here from `FrAt` + `HeapOK.align` and the cap decoder's `EncWf`, not a site premise). New module. -/ @@ -38,7 +39,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 : PtMapSiteA st Z H OS σ s) (hFrMap : FrMapSiteA st OS s) (hFrSub : FrSubSiteA st Z OS s) + (hPtMap : PtMapSiteA st Z H OS σ s) (hFrMap : FrMapSiteA st 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) @@ -63,9 +64,18 @@ theorem DecErrSpecPA.archVs (K : ArchKeepsA ar AR) blocking calling donate false e argsU hlen hargsU (Fl4SpecA64.toBl cptr.bv) excaps hok false buffer (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) + (fun fp sz rt dev mp e asid va hc _ hsz hdev => by + subst hsz hdev + have hc' : capA st s (cslotAddrA sl) = .Frame fp .Large rt false mp e asid va := by rw [← hsl]; exact hc + obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits7, KLv, W⟩ := J7A.unp J3.j7 + have hH : FrAt H fp 21#u64 := W.cc.fo (cslotAddrA sl) hslO fp .Large rt mp e asid va hc' 21#u64 rfl + have hal := hH.al J3.sys.ent.heap + have hw : CapRt.EncWf (capAtA (L.mem s) (cslotAddrA sl)) := CapRt.decodeF_encWf _ _ + rw [show capAtA (L.mem s) (cslotAddrA sl) = .Frame fp .Large rt false mp e asid va from hc'] at hw + refine ⟨by simpa using hal, ?_⟩ + cases e <;> exact hw.1) (hAsidAssign _ _) + (fun sl' hab' ptr' asid' va' hc hf' => J.finPtOtherA hab' hc hf') 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/Stage3DelAsmA.lean b/proofs/Fl4ProofsA64/P3/Stage3DelAsmA.lean index c3d889c72..e3842db68 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DelAsmA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DelAsmA.lean @@ -94,7 +94,7 @@ structure DelS4A (ar : machine.Arch A) (AR : A → HwRootA → Prop) (Z : XSetsA (_ : SchedValidA σ) (_ : VcpuStateSnapA Z'.V (L.mem s) σ) (_ : VcSym1A st Z'.T s) (_ : VcSym2A st Z'.V s) (_ : ∀ v ∈ Z'.V, L.mem s v ≠ 0#u64 → L.mem s (wa (L.mem s v) 3664#u64) = v) (_ : ∀ u ∈ Z'.T, L.mem s (runVcpuA u) ≠ 0#u64 → L.mem s (wa (L.mem s (runVcpuA u)) 24#u64) = u) - (_ : ∀ b, VcW Z'.V b → ¬ InOS OS b) (_ : FrOff st Z'.Cs OS (L.ksb s) s) (_ : UserFrSpecA st OS s σ) (_ : FrThA st Z'.th OS s) (_ : ∀ bp ∈ Bf, bp.2 = specPtr bp.1) + (_ : ∀ b, VcW Z'.V b → ¬ InOS OS b) (_ : FrOff st Z'.Cs OS (L.ksb s) s) (_ : UserFrSpecA st H OS s σ) (_ : FrThA st Z'.th OS s) (_ : ∀ bp ∈ Bf, bp.2 = specPtr bp.1) (_ : Clock a σ.machineState) (_ : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) (_ : ∀ a' ms (vc : U64), Clock a' ms → ar.vcpu_flush a' vc ⦃ a'' => Clock a'' ms ⦄) @@ -115,7 +115,7 @@ structure DelS4A (ar : machine.Arch A) (AR : A → HwRootA → Prop) (Z : XSetsA (∀ v ∈ Z'.V, L.mem res.1 v ≠ 0#u64 → L.mem res.1 (wa (L.mem res.1 v) 3664#u64) = v) ∧ (∀ u ∈ Z'.T, L.mem res.1 (runVcpuA u) ≠ 0#u64 → L.mem res.1 (wa (L.mem res.1 (runVcpuA u)) 24#u64) = u) ∧ - UserFrSpecA st OS res.1 σ' ∧ + UserFrSpecA st H OS res.1 σ' ∧ Clock res.2 σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ diff --git a/proofs/Fl4ProofsA64/P3/Stage3DelInA.lean b/proofs/Fl4ProofsA64/P3/Stage3DelInA.lean index b514da965..5aea1638c 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DelInA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DelInA.lean @@ -120,7 +120,7 @@ theorem runBuf_ofFrUbA {H : Heap} {OS Ub : Set U64} {s : S} {y : U64} (hH : Heap subst hdev have hcap0 : capA st s (sbWordA y) = .Frame ptr size rights false x1 x2 x3 x4 := okinj ((capA_eq s _).symm.trans hcap) - have hp : H ptr = some (.other bits.val) := hF _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits + have hp : FrAt H ptr bits := hF _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits intro i hi obtain ⟨hal, hin⟩ := frame_off_words hH hp hbits hsz h63 hlt hge hi exact hf _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits _ hal hin.1 hin.2 diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispBaseA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispBaseA.lean index df53810d2..88c564c03 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispBaseA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispBaseA.lean @@ -12,7 +12,8 @@ A group of lifted arms is an inductive scope predicate (`VsScopeA`, `CnScopeA`) `DispPostA`; the top (`Stage3DispTopA`) is their disjunction. A new group adds a module and a disjunct. * `A64RelPS3` (integration): the record at a **preempted** invocation's end, with `Sched.BodyPPA` (`BodyOKA` less - `OffOKA`, head readiness under `BodyExitA.budget`'s guard) for `BodyOKA`; `A64RelS3.toPS`. `A64RelRS3 r` / + `OffOKA`, head readiness under `BodyExitA.budget`'s guard) for `BodyOKA`, at a hidden view `m'` grown from `m` + (`A64RelPS3at`). `A64RelRS3 r` / `A64RelES3 e` pick it by FL4's result / the spec's outcome; `DispPostRA` is `DispPostA` with `A64RelRS3` (`DispPostA.toR`), what the dispatch top gives. @@ -216,8 +217,9 @@ def A64RelS3 (AR : A → HwRootA → Prop) (ar : machine.Arch A) (nA : U64) (n : (σ : 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) +/-- **The record at a preempted invocation's end, at a fixed view** (integration): `A64RelS3fx` with `BodyPPA` for +`BodyOKA`. -/ +def A64RelPS3fx (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), @@ -225,6 +227,17 @@ def A64RelPS3 (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.BodyPPA σ m +/-- **The record at a preempted invocation's end, at the view the invocation left** (as `A64RelS3at`: a preempted +Untyped reset has already dropped the dead threads' affinities). -/ +def A64RelPS3at (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' ∧ A64RelPS3fx st AR ar nA n Cs s a σ m' + +/-- **The record at a preempted invocation's end** (module docstring): `A64RelPS3 … m` hides the view `m'`. -/ +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 := + ∃ m' : Fl4SpecA64.McState, A64RelPS3at st AR ar nA n Cs s a σ m m' + /-- The record by FL4's invocation result: `A64RelPS3` after `Preempted`, `A64RelS3` otherwise. -/ def A64RelRS3 (AR : A → HwRootA → Prop) (ar : machine.Arch A) (nA : U64) (n : Nat) (Cs : Set U64) (r : core.result.Result Unit error.Exc) (s : S) (a : A) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) : @@ -323,6 +336,29 @@ theorem A64RelS3fx.ofJ {AR : A → HwRootA → Prop} {ar : machine.Arch A} {nA : (B : Sched.BodyOKA σ m) (hCs : Z.Cs = Cs := by rfl) : A64RelS3fx st AR ar nA n Cs s a σ m := ⟨_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, hCs, J, B⟩ +/-- `A64RelS3` over a grown view is `A64RelS3` at the base view. -/ +theorem A64RelS3.grow {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 : A64RelS3 st AR ar nA n Cs s a σ m') : A64RelS3 st AR ar nA n Cs s a σ m := + let ⟨m'', h, R'⟩ := R + ⟨m'', hg.trans h, R'⟩ + +theorem A64RelPS3.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.BodyPPA σ m') (hCs : Z.Cs = Cs := by rfl) : A64RelPS3 st AR ar nA n Cs s a σ m := + ⟨m', hg, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, hCs, J, B⟩ + +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 := + A64RelPS3.ofJg (McGrowA.refl m) J B hCs + /-- 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') diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispCnA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispCnA.lean index 6129756c1..bbd881964 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispCnA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispCnA.lean @@ -61,7 +61,7 @@ inductive CnScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U A (hanc : CapEqA nc anc) (hw : CapRt.EncWf nc) (hn : nc ≠ .Null) - (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA 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))) @@ -397,9 +397,10 @@ theorem CnScopeA.soundOk [PlainStore st] {AR : A → HwRootA → Prop} {Z : XSet Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ (.error (), σ'') ∈ ((Fl4SpecA64.fl4InvokeCnode (Z := Unit) inv).run σ1).1 ∧ PreExitA σ'' := by induction h with - | @cnodeCopy ps pd nc anc slot p r gs g extra lbl length buf index depth x0 si sdp root bB bC bD hnvm ss sd hCs hCd hsn hdn hdc hwf hanc hw hn hD hal hk hsh hsh1 hbd1 hbd hirq hz hut hdo hcv hsci hslot hslc hlb hl4 hl2 hi hd0 hres hx0 h0 h2 h3 hroot hemp hsrc hcop hcov hext hSC hpin => + | @cnodeCopy ps pd nc anc slot p r gs g extra lbl length buf index depth x0 si sdp root bB bC bD hnvm ss sd hCs hCd hsn hdn hdc hwf hanc hw hn hD hrd hal hk hsh hsh1 hbd1 hbd hirq hz hut hdo hcv hsci hslot hslc hlb hl4 hl2 hi hd0 hres hx0 h0 h2 h3 hroot hemp hsrc hcop hcov hext hSC hpin => left - obtain ⟨x, s2, σ2, hc0, hset, hcdt0, hc3, J3, K3⟩ := JSyscallA.cnodeCopyA (J := J) (hA := hA) (hM := hM) (hPl := hPl) (hfm := hfm) (hnvm := hnvm) (ss := ss) (sd := sd) (hCs := hCs) (hCd := hCd) (hsn := hsn) (hdn := hdn) (hdc := hdc) (hwf := hwf) (hanc := hanc) (hw := hw) (hn := hn) (hD := hD) (hal := hal) (hk := hk) (hsh := hsh) (hsh1 := hsh1) (hbd1 := hbd1) (hbd := hbd) (hirq := hirq) (hz := hz) (hut := hut) (hdo := hdo) (hcv := hcv) (hsci := hsci) (hslot := hslot) (hslc := hslc) (hlb := hlb) (hl4 := hl4) (hl2 := hl2) (hi := hi) (hd := hd0) (hres := hres) (hx0 := hx0) (h0 := h0) (h2 := h2) (h3 := h3) (hroot := hroot) (hemp := hemp) (hsrc := hsrc) (hcop := hcop) (hcov := hcov) (hext := hext) (hSC := hSC) + have Hder_ := JSyscallA.cnodeCopyA (J := J) (hA := hA) (hM := hM) (hPl := hPl) (hfm := hfm) (hnvm := hnvm) (ss := ss) (sd := sd) (hCs := hCs) (hCd := hCd) (hsn := hsn) (hdn := hdn) (hdc := hdc) (hwf := hwf) (hanc := hanc) (hw := hw) (hn := hn) (hD := hD) (hal := hal) (hk := hk) (hsh := hsh) (hsh1 := hsh1) (hbd1 := hbd1) (hbd := hbd) (hirq := hirq) (hz := hz) (hut := hut) (hdo := hdo) (hcv := hcv) (hsci := hsci) (hslot := hslot) (hslc := hslc) (hlb := hlb) (hl4 := hl4) (hl2 := hl2) (hi := hi) (hd := hd0) (hres := hres) (hx0 := hx0) (h0 := h0) (h2 := h2) (h3 := h3) (hroot := hroot) (hemp := hemp) (hsrc := hsrc) (hcop := hcop) (hcov := hcov) (hext := hext) (hSC := hSC) + obtain ⟨x, s2, σ2, hc0, hset, hcdt0, hc3, J3, K3⟩ := Hder_ hrd refine ⟨s2, a, σ2, ?_, ⟨x, hc0, hc3⟩, curW_keptA J.toJStage3A J3 K3.cur, A64RelS3.ofJ J3 (Sched.BodyOKA.ofKeep J hc0 K3)⟩ have hlbl : ¬ lbl < fl4_abi.label.CNodeRevoke ∧ ¬ lbl > fl4_abi.label.CNodeRotate ∧ lbl ≥ fl4_abi.label.CNodeCopy ∧ lbl ≤ fl4_abi.label.CNodeMutate := by @@ -490,8 +491,7 @@ theorem CnScopeA.soundOk [PlainStore st] {AR : A → HwRootA → Prop} {Z : XSet fun x hx => hps.2.1 x (by rw [← hcur]; exact hx), by rw [hcur]; exact hps.2.2.1, fun hr x hx => hps.2.2.2 hr x (by rw [← hcur]; exact hx), hown.1, hown.2⟩ refine ⟨s3, a3, σ3, ?_, ⟨σ1, hset, hperf, pre⟩, curW_keptA J.toJStage3A J3 hcur, - ⟨{ Z with G := G', Q := Q, R := R, hw := hw }, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, rfl, J3, - hpp.toPP⟩, hclk, inv', hpin, fun _ h => h⟩ + A64RelPS3.ofJ J3 hpp.toPP, hclk, inv', hpin, fun _ h => h⟩ rw [hslc, decodeCnode_programA, if_neg Bool.false_ne_true] exact hdec diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispTcbPreA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispTcbPreA.lean index 34fc78921..6a7eed2b7 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispTcbPreA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispTcbPreA.lean @@ -338,14 +338,6 @@ inductive TcbPreScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) 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)} diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispTopA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispTopA.lean index 9bd74dcec..d152a7de1 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispTopA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispTopA.lean @@ -4,13 +4,12 @@ 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`: 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 +(`UtScopeA`: Retype on a RAM Untyped; `UtPreScopeA`: its preempted reset), 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`, `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 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 +state: [S] limits, listed in DESIGN §9): Untyped Retype on a device Untyped (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 @@ -23,6 +22,7 @@ import Fl4ProofsA64.P3.Stage3DispTcbA import Fl4ProofsA64.P3.Stage3DispTcbPreA import Fl4ProofsA64.P3.Stage3DispCnA import Fl4ProofsA64.P3.Stage3DispUtA +import Fl4ProofsA64.P3.Stage3DispUtPreA import Fl4ProofsA64.P3.Stage3DispFlushA import Fl4ProofsA64.P3.Stage3DispIrqA import Fl4ProofsA64.P3.Stage3DispReplyA @@ -53,7 +53,8 @@ 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 st AR n Z OS ar s a σ 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 ∨ + UtPreScopeA st AR n Z OS ar s a σ Clock 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 ∨ @@ -84,7 +85,7 @@ 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 hA hPl J hfm h).toR) fun h => + h.elim (fun h => h.elim (fun h => (UtScopeA.sound hA hPl J hfm h).toR) (UtPreScopeA.sound hA hPl J hfm)) 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 => 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 => diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispUtA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispUtA.lean index 16c700edb..e0a15898f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispUtA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispUtA.lean @@ -7,17 +7,19 @@ Untyped cap whose slot already has a CDT child (so no reset), every object type. 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.retypeRstBig`: a reset that runs the chunk loop to completion (a used untyped of at least 64 KiB; + `JSyscallA.untypedRetypeRstBigA`). The preempted reset is `UtPreScopeA` (`P3/Stage3DispUtPreA`). * `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`): +Still outside the scope (the tops are vacuous there): 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.Stage3UtArmA +import Fl4ProofsA64.P3.Stage3UtBigArmA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -89,6 +91,42 @@ inductive UtScopeA (AR : A → HwRootA → Prop) (n : Nat) (Z : XSetsA) (OS : Se (fun σ' => ∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ (.ok (), σ') ∈ ((Fl4SpecA64.fl4InvokeUntypedA64 (Z := Unit) inv).run (stUpdA σ σ.curThread xT .restart)).1) + | retypeRstBig (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 + (hnN : n ≤ Fl4SpecA64.fl4A64Platform.numNodes) + (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) + -- [P] the preemption point's platform and entry clock, the chunk size, the post-reset barriers + (Clock : A → Fl4SpecA64.MachineState → Prop) (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCnt : Sched.CounterStepA σ) (hchunk : resetChunkBits = 16) + (hPost : ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + -- the case: a used untyped of at least a chunk, and the reset completes + (hfi : fi ≠ 0#u64) (hbig : 16 ≤ sb.val) (s3 : S) (a3 : A) + (hres : untyped.reset_untyped st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) = + ok (core.result.Result.Ok (), s3, a3)) + (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} @@ -113,6 +151,11 @@ theorem UtScopeA.soundOk (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) 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 + | retypeRstBig 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 hCs Clock P hCl hCnt hchunk hPost hfi hbig s3 a3 + hres hpin => + exact JSyscallA.untypedRetypeRstBigA 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 hCs P hCl hCnt hchunk hPost hfi hbig hres /-- **The Untyped group is sound.** -/ theorem UtScopeA.sound (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) @@ -154,6 +197,15 @@ theorem UtScopeA.invSpecA (do Fl4SpecA64.fl4InvokeUntypedA64 (Z := Unit) inv; Fl4Spec.NonDetE.returnOk ([] : List Data)) := rfl rw [e] exact perform_thenNilA hperf + | retypeRstBig 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 hCs Clock P hCl hCnt hchunk hPost hfi hbig s3 a3 + hres 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 diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispUtPreA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispUtPreA.lean new file mode 100644 index 000000000..5fac383c6 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3DispUtPreA.lean @@ -0,0 +1,129 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line prst, T3 dispatch): **the preempted Untyped reset** (`Stage3DispBaseA`), the Untyped +counterpart of `TcbPreScopeA`. + +* `UtPreScopeA.retypeRstPre`: a Retype of a RAM Untyped without a CDT child whose `reset_untyped`, from the restarted + state, returns `Preempted` (the case hypothesis `hres`). The spec outcome is a preempted `fl4InvokeUntypedA64` of the + decoded invocation, with `PreExitA`. +* `UtPreScopeA.soundPre`, `UtPreScopeA.sound`: the decode returns `Preempted`, `A64RelPS3` holds and the clock relation + holds (`DispPostRA`). +* `UtPreScopeA.invSpecA`: the spec side (`done = false`). + +Named premises: [P] `ArchTotal`, `ArchPlat`, `A64FrameMasks`, `hvi`/`hvirt`, `hfan`, `DelPlatA`, `hCl`, `resetChunkBits += 16`, the post-reset barriers; [S] one core; [J] `JSyscallA`, `CounterStepA`. New definitions and theorems only. +-/ +import Fl4ProofsA64.P3.Stage3UtPreArmA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4Spec Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} (st : machine.Store S) [L : LawfulStore st] {A : Type} + +/-- **The preempted Untyped arm in scope** (module docstring). Indexed as the other groups, with the clock relation. -/ +inductive UtPreScopeA (AR : A → HwRootA → Prop) (n : Nat) (Z : XSetsA) (OS : Set U64) (ar : machine.Arch A) (s : S) + (a : A) (σ : Fl4SpecA64.State Unit) (Clock : A → Fl4SpecA64.MachineState → Prop) : + U64 → U64 → U64 → Bool → Bool → Bool → Bool → U64 → Aeneas.Std.Array obj.Slot 3#usize → + (Fl4SpecA64.State Unit → Prop) → Prop + | retypeRstPre (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)) + -- [S] one core + (hnN : n ≤ Fl4SpecA64.fl4A64Platform.numNodes) + (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) + -- [P] the preemption point's platform and entry clock, the chunk size, the post-reset barriers + (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) (hCnt : Sched.CounterStepA σ) + (hchunk : resetChunkBits = 16) + (hPost : fi ≠ 0#u64 → ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + -- the case: the reset is preempted + (s3 : S) (a3 : A) + (hres : untyped.reset_untyped st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) = + ok (core.result.Result.Err .Preempted, s3, a3)) + (hpin : DecPinA call Z.th σ slot (.invokeUntyped inv)) : + UtPreScopeA AR n Z OS ar s a σ Clock lbl length slot blk call don false buf extra + (fun σ' => (∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + (.error (), σ') ∈ ((Fl4SpecA64.fl4InvokeUntypedA64 (Z := Unit) inv).run + (stUpdA σ σ.curThread xT .restart)).1) ∧ PreExitA σ') + +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} + {Clock : A → Fl4SpecA64.MachineState → Prop} + +/-- **The preempted arm runs and keeps the record**: its decode returns `Preempted`. -/ +theorem UtPreScopeA.soundPre (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 : UtPreScopeA st AR n Z OS ar s a σ Clock lbl len slot blk call don fp buf extra Out) : + ∃ (s' : S) (a' : A) (σ' : Fl4SpecA64.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 + | retypeRstPre 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 hnN hCs P hCl hCnt hchunk hPost s3 a3 hres hpin => + obtain ⟨s', a', σ', e, o, c, R, clk, pre⟩ := JSyscallA.untypedRetypeRstPreA (blk := blk) (call := call) (don := don) + (fp := false) 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 hnN hCs P hCl hCnt hchunk hPost hres + exact ⟨s', a', σ', e, ⟨o, pre⟩, c, R, clk⟩ + +/-- **The preempted Untyped group is sound** (the record by result). -/ +theorem UtPreScopeA.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 : UtPreScopeA st AR n 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, clk⟩ := UtPreScopeA.soundPre hA hPl J hfm h + ⟨_, s', a', σ', e, o, c, R, fun _ => clk⟩ + +/-- **The preempted group's `InvSpecA`**, from the pinned operation. -/ +theorem UtPreScopeA.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 : UtPreScopeA st AR n Z OS ar s a σ Clock 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 false mi.miLabel args cptr sl c excaps buffer σ σ' := by + cases h with + | retypeRstPre 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 hnN hCs P hCl hCnt hchunk hPost s3 a3 hres hpin => + obtain ⟨⟨xT, hk, hperf⟩, pre⟩ := hOut + refine InvSpecA.ofPinPre hP hpin F cptr (hst xT hk) ?_ pre + 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, ExceptT.run_bind] + exact mem_bindA.2 ⟨(.error (), σ'), hperf, Set.mem_singleton _⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3DispVsA.lean b/proofs/Fl4ProofsA64/P3/Stage3DispVsA.lean index d4cc6cad0..4e45c5193 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3DispVsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3DispVsA.lean @@ -16,6 +16,10 @@ import Fl4ProofsA64.P3.Stage3DispBaseA import Fl4ProofsA64.P3.VsArmA import Fl4ProofsA64.P3.Stage3T3DecEqA import Fl4ProofsA64.P3.Stage3T3ArmT2A +import Fl4ProofsA64.P3.Stage3T3PoolA +import Fl4ProofsA64.P3.Stage3UtArmA +import Fl4ProofsA64.P3.Stage3T3ArmStaleA +import Fl4ProofsA64.P3.Stage3T3ArmSubA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -274,6 +278,7 @@ inductive VsScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U A (hpS : ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr) (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) (hcov : SlotCov st OS s (cslotAddrA cte)) @@ -302,6 +307,7 @@ inductive VsScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U A (hpS : ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr) (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) (k : Fl4SpecA64.ExtRootKind) (hkR : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some k) (hkR1 : k ≠ .stage1) @@ -373,6 +379,46 @@ inductive VsScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U A ((.archObjectCap (assignRootCapA k (specPtr root) none), dst) :: rest)).run σ).1) ∧ (.ok ([] : List Fl4SpecA64.Data), σ') ∈ ((fl4ArchPerformInvocation (Z := Unit) (assignInvA k (specPtr p) dst (asidOfA (wa base i)))).run (stUpdA σ σ.curThread x .restart)).1) + | asidMakePool + (hnN : n ≤ Fl4SpecA64.fl4A64Platform.numNodes) + (h1 : Fl4SpecA64.fl4A64Platform.numNodes = 1) (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) + (hn : nA.val = fl4A64Platform.s2IpaBits) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (cte : Fl4SpecA64.CslotPtr) + (hab : AbsSlotA Z.th cte) + (hcteC : capA st s (cslotAddrA cte) = .AsidControl) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (ex : Aeneas.Std.Array obj.Slot 3#usize) + (hext : ∀ x ∈ ex.val, x ≠ 0#u64 → x ∈ OS) + (hSC : ∀ x ∈ ex.val, x ≠ 0#u64 → SlotCov st OS s x) + (parent dest : Fl4SpecA64.CslotPtr) (frame fi i base : U64) + (hAp : AbsSlotA Z.th parent) (hAd : AbsSlotA Z.th dest) + (hdc : ∃ y ∈ OS, ∃ q r gs g : U64, capA st s y = .CNode q r gs g ∧ dest.1 = specPtr q) + (hCp : ∃ pp, parent.1 = specPtr pp ∧ Z.th pp = some (.cnode parent.2.length)) + (hCd : ∃ pd, dest.1 = specPtr pd ∧ Z.th pd = some (.cnode dest.2.length)) (hdr : dest.2.length ≠ 0) + (length buf : U64) (block call cd fp : Bool) + (hx0 : exAtA ex 0 ≠ 0#u64) (hx1 : exAtA ex 1 ≠ 0#u64) (hlen2 : length ≥ 2#u64) (a0 a1 : U64) + (ha0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok a0) + (ha1 : msg.syscall_arg st s (L.curW s) buf 1#u64 = ok a1) + (hpa : cslotAddrA parent = exAtA ex 0) (hcp : capA st s (cslotAddrA parent) = .Untyped frame 12#u64 fi false) + (hnc : cdt.ensure_no_children st s (cslotAddrA parent) = ok (core.result.Result.Ok ())) + (hiOk : vspace.decode_loop0 st s 0#u64 = ok i) (hi : i.val < 128) + (hfree : L.mem s (atAF (L.ksb s) i) = 0#u64) + (hbaseOk : (i <<< vspace.ASID_LOW_BITS : Result U64) = ok base) (hbase : base.val = i.val * 512) + (hlt : cspace.lookup_slot_for_cnode_op st s false (capA st s (exAtA ex 1)) a0 a1 = + ok (core.result.Result.Ok (cslotAddrA dest))) + (hcd : capA st s (cslotAddrA dest) = .Null) + (hpin : DecPinA call Z.th σ (cslotAddrA cte) (.invokeArchObject (.spec (.invokeASIDControl + (.makePool (specPtr frame) dest parent (asidOfA base)))))) : + 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.ARMASIDControlMakePool length + (cslotAddrA cte) block call cd fp buf ex + (fun σ' => ∃ (x : Fl4SpecA64.Tcb), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok ([] : List Fl4SpecA64.Data), σ') ∈ ((fl4ArchPerformInvocation (Z := Unit) + (.spec (.invokeASIDControl (.makePool (specPtr frame) dest parent (asidOfA base))))).run + (stUpdA σ σ.curThread x .restart)).1) | frameMapHi {x0 : U64} {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} @@ -489,6 +535,43 @@ inductive VsScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U A (([] : List Fl4SpecA64.Data), σ') ∈ (Fl4SpecA64.performExtVSpace (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1) + | frameDeriveSub + {s3 : S} + {a3 : A} + {fp rt asid va : U64} + {mp e : Bool} + {bB bD bF : Bool} + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (cte : Fl4SpecA64.CslotPtr) + (hab : AbsSlotA Z.th cte) + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .Frame fp .Large rt false mp e asid va) + (length buf : U64) + (call : Bool) + (ex : Aeneas.Std.Array obj.Slot 3#usize) + (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) + (x0 : U64) + (hx0 : Aeneas.Std.Array.index_usize ex 0#usize = ok x0) + (xSlot : Fl4SpecA64.CapRef) + (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) + (hex : ExtraRelA Z.th (L.mem s) x0 (exs.map Prod.fst)) + (hD : D = (fl4ArchDecodeInvocation (Z := Unit) call (.ext .armPageDeriveSubframe) (args.map UScalar.bv) xSlot cte + (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA .Large) false (mapDataA mp asid va)) exs).run σ) + (hdec : vspace.decode_frame st ar s a fl4_abi.label.ARMPageDeriveSubframe length (cslotAddrA cte) + (.Frame fp .Large rt false mp e asid va) call buf ex = ok (core.result.Result.Ok (), s3, a3)) + (hcov : SlotCov st OS s (cslotAddrA cte)) + (hext : ∀ x ∈ ex.val, x ≠ 0#u64 → x ∈ OS) + (hpin : ∀ iv, (.ok (.deriveSubframe iv), σ) ∈ D.1 → + DecPinA call Z.th σ (cslotAddrA cte) (.invokeArchObject (.deriveSubframe 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.ARMPageDeriveSubframe length (cslotAddrA cte) bB call bD bF buf ex + (fun σ' => ∃ (x : Fl4SpecA64.Tcb) (iv : Fl4SubframeInvocation), + σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (.ok (.deriveSubframe iv), σ) ∈ D.1 ∧ + ((), σ') ∈ (Fl4SpecA64.performDeriveSubframe (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1) | ptMapHi {x0 : U64} {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} @@ -617,6 +700,34 @@ inductive VsScopeA (AR : A → HwRootA → Prop) (Z : XSetsA) (H : Heap) (OS U 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) + + | ptUnmapT2Stale + {bB bC bD bF : Bool} + (K : ArchKeepsA ar AR) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (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) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) + (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ + Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) + (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 (.spec (.invokePageTable (.pageTableUnmap (.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) ∧ + ((), σ') ∈ (Fl4SpecA64.performPageTableInvocation (Z := Unit) (.pageTableUnmap (.pageTableCap (specPtr ptr) + .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte) (stUpdA σ σ.curThread x .restart)).1) + variable {st} set_option maxHeartbeats 8000000 in @@ -668,13 +779,13 @@ theorem VsScopeA.soundOk {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} { refine ⟨s3, a3, σ3, ?_, ⟨x, ivp, 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] exact (decInv_ptA ar s a _ length _ ptr false asid0 va0 bB bC bD bF buf extra).trans hdec - | @ptUnmapS1 bB bC bD bF K hnvm hTO hEO length buf ex cte hab ptr asid va hpS hcap hf hS1 hcov hext hSC hpin => - obtain ⟨x, s3, a', σ3, Ac', hc0, hc1, hdec1, hc3, J3, K3⟩ := JSyscallA.ptUnmapS1A (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) (length := length) (buf := buf) (ex := ex) (cte := cte) (hab := hab) (ptr := ptr) (asid := asid) (va := va) (hpS := hpS) (hcap := hcap) (hf := hf) (hS1 := hS1) (hcov := hcov) (hext := hext) (hSC := hSC) + | @ptUnmapS1 bB bC bD bF K hnvm hTO hEO length buf ex cte hab ptr asid va hpS hcap hf hno hS1 hcov hext hSC hpin => + obtain ⟨x, s3, a', σ3, Ac', hc0, hc1, hdec1, hc3, J3, K3⟩ := JSyscallA.ptUnmapS1A (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) (length := length) (buf := buf) (ex := ex) (cte := cte) (hab := hab) (ptr := ptr) (asid := asid) (va := va) (hpS := hpS) (hcap := hcap) (hf := hf) (hno := hno) (hS1 := hS1) (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 - | @ptUnmapX bB bC bD bF K hnvm hTO hEO hIpa length buf ex cte hab ptr asid va hpS hcap hf k hkR hkR1 hcov hext hSC hpin => - obtain ⟨x, s3, a', σ3, Ac', hc0, hc1, hdec1, hc3, J3, K3⟩ := JSyscallA.ptUnmapXA (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) (hpS := hpS) (hcap := hcap) (hf := hf) (k := k) (hkR := hkR) (hkR1 := hkR1) (hcov := hcov) (hext := hext) (hSC := hSC) + | @ptUnmapX bB bC bD bF K hnvm hTO hEO hIpa length buf ex cte hab ptr asid va hpS hcap hf hno k hkR hkR1 hcov hext hSC hpin => + obtain ⟨x, s3, a', σ3, Ac', hc0, hc1, hdec1, hc3, J3, K3⟩ := JSyscallA.ptUnmapXA (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) (hpS := hpS) (hcap := hcap) (hf := hf) (hno := hno) (k := k) (hkR := hkR) (hkR1 := hkR1) (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 @@ -688,6 +799,16 @@ theorem VsScopeA.soundOk {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} { refine ⟨s3, a, σ3, ?_, ⟨x, hc0, hc1, hc3, hc4⟩, curW_keptA J.toJStage3A J3 K3.cur, A64RelS3.ofJ J3 (Sched.BodyOKA.ofKeep J hc0 K3)⟩ rw [show capA st s (cslotAddrA cte) = .AsidPool p base from hpool] exact hdec1 + | @asidMakePool hnN h1 hCs hn hnvm cte hab hcteC hcov ex hext hSC parent dest frame fi i base hAp hAd hdc hCp hCd hdr length buf block call cd fp hx0 hx1 hlen2 a0 a1 ha0 ha1 hpa hcp hnc hiOk hi hfree hbaseOk hbase hlt hcd hpin => + haveI : Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes) := ⟨hnN⟩ + obtain ⟨x, s3, σ3, Zn, Ac', hc0, hc1, hdec1, hc3, hBK, hZn, J3⟩ := JSyscallA.asidMakePoolA hPl J h1 hCs hn + hnvm cte hab hcteC hcov hext hSC hAp hAd hdc hCp hCd hdr length buf block call cd fp hx0 hx1 hlen2 ha0 ha1 hpa hcp hnc + hiOk hi hfree hbaseOk hbase hlt hcd + refine ⟨s3, a, σ3, ?_, ⟨x, hc0, hc1, hc3⟩, curW_keptA J.toJStage3A J3 hBK.cur, + A64RelS3.ofJg (dropMA_growA _ m) J3 (BodyOKA.ofGrow (dropMA_growA _ m) (Sched.BodyOKA.ofKeep J hc0 hBK)) + (by rw [hZn]; rfl)⟩ + rw [hcteC] + exact hdec1 | @frameMapHi x0 D dc ex s3 a3 callD lenD bufD rr bB bD bF K hnvm hTO hEO cte hab fp rt asid va sz dev mp hcap FP p1 asid1 mp1 h16 hx0 hx0c vaddr rightsMask vm attr 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.frameMapHiA (J := J) (hA := hA) (hM := hM) (hPl := hPl) (hfm := hfm) (callD := callD) (hK := J.toJStage3A.ksbAligned) (hT := J.toJStage3A.offAsE) (K := K) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (cte := cte) (hab := hab) (fp := fp) (rt := rt) (asid := asid) (va := va) (sz := sz) (dev := dev) (mp := mp) (hcap := hcap) (FP := FP) (p1 := p1) (asid1 := asid1) (mp1 := mp1) (h16 := h16) (hx0 := hx0) (hx0c := hx0c) (vaddr := vaddr) (rightsMask := rightsMask) (vm := vm) (attr := attr) (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)⟩ @@ -695,6 +816,13 @@ 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 + | @frameDeriveSub s3 a3 fp rt asid va mp e bB bD bF D hnvm cte hab hcap length buf call ex args hlen hargs x0 hx0 xSlot exs hex hD hdec hcov hext hpin => + obtain ⟨x, iv, σ3, G2, ha3, hc0, hc1, hc2, hc3, J3, K3⟩ := JSyscallA.frameDeriveSubA (J := J) hA hPl hnvm cte hab fp rt asid va mp e hcap hcov (fun y hy => OSOK.canon J.sys.ent.os J.toJStage3A.winOK hy) length buf call ex hext args hlen hargs x0 hx0 xSlot exs hex hdec + subst ha3 + refine ⟨s3, _, σ3, ?_, ⟨x, iv, hc0, hc1, by rw [hD, hc2]; exact Set.mem_singleton _, 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 .Large rt false mp e asid va) from (capAtA_eq (st := st) _ _).symm.trans hcap, + decInv_frameA ar s _ _ length _ fp .Large rt false mp e asid va bB call bD bF buf ex] + exact hdec | @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)⟩ @@ -723,6 +851,11 @@ theorem VsScopeA.soundOk {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} { 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 + | @ptUnmapT2Stale bB bC bD bF K hnvm length buf ex cte hab ptr asid va hpT hcap hf hno hS1 hcov hext hSC hpin => + obtain ⟨x, s3, a', σ3, Ac', hc0, hc1, hdec1, hc3, J3, K3⟩ := JSyscallA.ptUnmapT2StaleA (J := J) (hA := hA) (hM := hM) (hPl := hPl) (hfm := hfm) (hK := J.toJStage3A.ksbAligned) (hT := J.toJStage3A.offAsE) (K := K) (hnvm := hnvm) (hTO := J.toJStage3A.tabS1) (hEO := J.toJStage3A.tabExt) (length := length) (buf := buf) (ex := ex) (cte := cte) (hab := hab) (ptr := ptr) (asid := asid) (va := va) (hpT := hpT) (hcap := hcap) (hf := hf) (hno := hno) (hS1 := hS1) (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/Stage3FieldsA.lean b/proofs/Fl4ProofsA64/P3/Stage3FieldsA.lean index 79bb59e37..b5b1964f6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3FieldsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3FieldsA.lean @@ -50,7 +50,7 @@ variable (st) in /-- **The pin of a tracked buffer** (12′): the 128 words of the 1 KiB buffer at `b` are aligned words of the non-device Frame cap in the `SLOT_BUFFER` slot of a TCB of `T`. -/ def BufPinA (T OS : Set U64) (s : S) (b : U64) : Prop := - ∃ t ∈ T, sbWordA t ∈ OS ∧ ∃ ptr size rights x1 x2 x3 x4 bits, + b.val % 1024 = 0 ∧ ∃ t ∈ T, sbWordA t ∈ OS ∧ ∃ ptr size rights x1 x2 x3 x4 bits, capA st s (sbWordA t) = .Frame ptr size rights false x1 x2 x3 x4 ∧ size.bits = ok bits ∧ ∀ k : U64, k.val < 128 → Aligned (bufW b k) ∧ ptr.val ≤ (bufW b k).val ∧ (bufW b k).val < ptr.val + 2 ^ bits.val @@ -61,9 +61,9 @@ theorem BufPinA.keepF {T T' OS OS' : Set U64} {s s' : S} {b : U64} (h : BufPinA t ∈ T' ∧ sbWordA t ∈ OS' ∧ ∃ r y1 y2 y3 y4, capA st s' (sbWordA t) = .Frame ptr size r false y1 y2 y3 y4) : BufPinA st T' OS' s' b := by - obtain ⟨t, ht, hO, ptr, size, rights, x1, x2, x3, x4, bits, hc, hs, hw⟩ := h + obtain ⟨hb1024, t, ht, hO, ptr, size, rights, x1, x2, x3, x4, bits, hc, hs, hw⟩ := h obtain ⟨ht', hO', r, y1, y2, y3, y4, hc'⟩ := hk t ht hO ptr size rights x1 x2 x3 x4 hc - exact ⟨t, ht', hO', ptr, size, r, y1, y2, y3, y4, bits, hc', hs, hw⟩ + exact ⟨hb1024, t, ht', hO', ptr, size, r, y1, y2, y3, y4, bits, hc', hs, hw⟩ /-- `BufPinA` along a step keeping every pinning slot's cap. -/ theorem BufPinA.keepC {T T' OS OS' : Set U64} {s s' : S} {b : U64} (h : BufPinA st T OS s b) @@ -74,7 +74,7 @@ theorem BufPinA.keepC {T T' OS OS' : Set U64} {s s' : S} {b : U64} (h : BufPinA /-- The 128 words of a pinned buffer lie in every `Ub` bounding the live frames. -/ theorem BufPinA.ubA {T OS Ub : Set U64} {s : S} {b : U64} (h : BufPinA st T OS s b) (hF : Fl4ProofsA64.P1.W7.R.ST.FrUb st Ub OS s) {k : U64} (hk : k.val < 128) : bufW b k ∈ Ub := by - obtain ⟨t, -, hO, ptr, size, rights, x1, x2, x3, x4, bits, hc, hs, hw⟩ := h + obtain ⟨-, t, -, hO, ptr, size, rights, x1, x2, x3, x4, bits, hc, hs, hw⟩ := h obtain ⟨al, h1, h2⟩ := hw k hk exact hF _ hO ptr size rights x1 x2 x3 x4 hc bits hs _ al h1 h2 @@ -93,7 +93,7 @@ theorem BufOffA.frameWordsA {Z : XSetsA} {OS : Set U64} {s : S} {Bf : Set (U64 (B : BufOffA st Z OS s Bf) {b : U64} (hb : BufW Bf b) : b ∈ Fl4ProofsA64.P1.W7.R.ST.FrameWords st OS s := by obtain ⟨bp, hbp, k, hk, rfl⟩ := hb - obtain ⟨t, -, hO, ptr, size, rights, x1, x2, x3, x4, bits, hc, hs, hw⟩ := B.pin bp hbp + obtain ⟨-, t, -, hO, ptr, size, rights, x1, x2, x3, x4, bits, hc, hs, hw⟩ := B.pin bp hbp obtain ⟨al, h1, h2⟩ := hw k hk exact ⟨al, _, hO, ptr, size, rights, x1, x2, x3, x4, bits, hc, hs, h1, h2⟩ @@ -174,34 +174,150 @@ structure DevUtOffA (Z : XSetsA) (H : Heap) (OS : Set U64) (ia ie : Nat) (s : S) variable {s s' : S} {OS : Set U64} -theorem FrBaseApartA.keepA (capE : ∀ u ∈ OS, capA st s' u = capA st s u) (h : FrBaseApartA st OS s) : - FrBaseApartA st OS s' := fun y hy z hz fy kz => by - rw [capE y hy] at fy - rw [capE z hz] at kz - rw [capE y hy, capE z hz] - exact h y hy z hz fy kz +theorem _root_.Fl4ProofsA64.P1.W7.R.ST.OSKeep.revA {s s' : S} (k : OSKeep st OS s s') {y : U64} (hy : y ∈ OS) : + Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y := by + unfold Fl4ProofsA64.P1.W7.R.ST.revA; rw [(k y hy).2.2.2] + +theorem FrLamA.keepA (capE : ∀ u ∈ OS, capA st s' u = capA st s u) (revE : ∀ u ∈ OS, Fl4ProofsA64.P1.W7.R.ST.revA st s' u = Fl4ProofsA64.P1.W7.R.ST.revA st s u) + (h : FrLamA st OS s) : FrLamA st OS s' := + h.tr (fun y hy p rt mp e asid va hc => ⟨y, hy, p, rt, mp, e, asid, va, by rw [← capE y hy]; exact hc, by rw [capE y hy], + by rw [capE y hy]⟩) + (fun z hz pz => ⟨z, hz, by rw [← capE z hz]; exact pz, by rw [capE z hz], by rw [capE z hz], + fun f r => ⟨by rw [capE z hz]; exact f, by rw [revE z hz]; exact r⟩⟩) + +theorem FrBaseApartA.keepA (capE : ∀ u ∈ OS, capA st s' u = capA st s u) (revE : ∀ u ∈ OS, Fl4ProofsA64.P1.W7.R.ST.revA st s' u = Fl4ProofsA64.P1.W7.R.ST.revA st s u) + (h : FrBaseApartA st OS s) : FrBaseApartA st OS s' := + ⟨fun y hy z hz fy kz => by + rw [capE y hy] at fy + rw [capE z hz] at kz + rw [capE y hy, capE z hz] + exact h.1 y hy z hz fy kz, + fun y hy z hz fy kz => by + rw [capE y hy] at fy + rw [capE z hz] at kz + rw [capE y hy, capE z hz] + exact h.2.1 y hy z hz fy kz, FrLamA.keepA capE revE h.2.2⟩ + +theorem FrBaseApartA.keepOS (osk : OSKeep st OS s s') (h : FrBaseApartA st OS s) : FrBaseApartA st OS s' := + h.keepA (fun u hu => osk.capA hu) (fun u hu => osk.revA hu) + +theorem mask_page_eqA (q ptr : U64) (k : Nat) (hk : k ≤ 39) + (hal : ptr.val % 2 ^ k = 0) (hle : ptr.val ≤ q.val) (hlt : q.val < ptr.val + 2 ^ k) : + (specPtr q &&& ~~~(@Fl4SpecA64.mask 64 k)) = specPtr ptr := by + have hk64 : k < 64 := by omega + have hpos : 0 < 2 ^ k := Nat.pow_pos (by decide) + have hlt64 : 2 ^ k < 2 ^ 64 := Nat.pow_lt_pow_right (by decide) hk64 + have e : ~~~(@Fl4SpecA64.mask 64 k) = BitVec.allOnes 64 <<< k := by + apply BitVec.eq_of_toNat_eq + unfold Fl4SpecA64.mask + rw [BitVec.toNat_not, BitVec.toNat_sub, BitVec.toNat_shiftLeft, BitVec.toNat_allOnes] + have h1 : (1 : BitVec 64).toNat = 1 := rfl + have hcast : ((1 <<< k : Nat) : BitVec 64).toNat = 2 ^ k := by + change (BitVec.ofNat 64 (1 <<< k)).toNat = 2 ^ k + rw [BitVec.toNat_ofNat, Nat.shiftLeft_eq, Nat.one_mul, Nat.mod_eq_of_lt hlt64] + rw [h1, hcast] + simp only [Nat.shiftLeft_eq] + have hge1 : 1 ≤ 2 ^ 64 := Nat.lt_trans hpos hlt64 + have hsub : (2 ^ 64 - 1 + 2 ^ k) % 2 ^ 64 = 2 ^ k - 1 := by + have hsum : 2 ^ 64 - 1 + 2 ^ k = 2 ^ 64 + (2 ^ k - 1) := by omega + rw [hsum, Nat.add_mod_left, Nat.mod_eq_of_lt (Nat.lt_of_le_of_lt (Nat.sub_le _ _) hlt64)] + have hmul : (2 ^ 64 - 1) * 2 ^ k = 2 ^ 64 * (2 ^ k - 1) + (2 ^ 64 - 2 ^ k) := by + rw [Nat.mul_sub_right_distrib, Nat.one_mul, Nat.mul_sub_left_distrib, Nat.mul_one] + have hle' : 2 ^ 64 ≤ 2 ^ 64 * 2 ^ k := Nat.le_mul_of_pos_right _ hpos + have hle2 : 2 ^ k ≤ 2 ^ 64 := Nat.le_of_lt hlt64 + omega + have hlt_rem : 2 ^ 64 - 2 ^ k < 2 ^ 64 := Nat.sub_lt (Nat.lt_trans hpos hlt64) hpos + rw [hsub, hmul, Nat.mul_add_mod, Nat.mod_eq_of_lt hlt_rem] + exact Nat.sub_sub_sub_cancel_right hpos + rw [e, ← BitVec.shiftLeft_ushiftRight] + apply BitVec.eq_of_toNat_eq + rw [BitVec.toNat_shiftLeft, BitVec.toNat_ushiftRight] + simp only [Nat.shiftLeft_eq, Nat.shiftRight_eq_div_pow] + have hqlt : (specPtr q).toNat / 2 ^ k * 2 ^ k < 2 ^ 64 := + Nat.lt_of_le_of_lt (Nat.div_mul_le_self _ _) (specPtr q).isLt + rw [Nat.mod_eq_of_lt hqlt] + have hsp_al : (specPtr ptr).toNat % 2 ^ k = 0 := (specPtr_mod ptr hk).trans hal + have hsp_ptr : (specPtr ptr).toNat = (specPtr ptr).toNat / 2 ^ k * 2 ^ k := by + have := Nat.div_add_mod (specPtr ptr).toNat (2 ^ k) + rw [Nat.mul_comm, hsp_al, Nat.add_zero] at this + exact this.symm + have hsp_lt : (specPtr ptr).toNat + 2 ^ k ≤ 2 ^ 64 := by + have h64 : 2 ^ 64 = (2 ^ 64 / 2 ^ k) * 2 ^ k := by + have hdiv := Nat.div_mul_cancel (Nat.pow_dvd_pow 2 (Nat.le_of_lt hk64)) + exact hdiv.symm + have hq_lt : (specPtr ptr).toNat / 2 ^ k < 2 ^ 64 / 2 ^ k := by + by_contra hge + have h1 : 2 ^ 64 / 2 ^ k ≤ (specPtr ptr).toNat / 2 ^ k := Nat.le_of_not_lt hge + have h2 := Nat.mul_le_mul_right (2 ^ k) h1 + rw [← h64, ← hsp_ptr] at h2 + exact Nat.not_le_of_lt (specPtr ptr).isLt h2 + have h3 := Nat.mul_le_mul_right (2 ^ k) (Nat.succ_le_of_lt hq_lt) + rw [Nat.succ_mul, ← hsp_ptr, ← h64] at h3 + exact h3 + set off : U64 := ⟨BitVec.ofNat 64 (q.val - ptr.val)⟩ + have hoff_val : off.val = q.val - ptr.val := by + change (BitVec.ofNat 64 (q.val - ptr.val)).toNat = q.val - ptr.val + rw [BitVec.toNat_ofNat, Nat.mod_eq_of_lt (by omega)] + have hq_eq : q = wa ptr off := by + apply UScalar.eq_of_val_eq + rw [wa_valP, hoff_val, Nat.add_sub_of_le hle] + exact (Nat.mod_eq_of_lt (show q.val < 2 ^ 64 from q.bv.isLt)).symm + have hsp_q : (specPtr q).toNat = (specPtr ptr).toNat + off.val := by + rw [hq_eq, specPtr_wa, BitVec.toNat_add] + change ((specPtr ptr).toNat + off.val) % 2 ^ 64 = _ + rw [Nat.mod_eq_of_lt (by omega)] + have hdiv : (specPtr q).toNat / 2 ^ k = (specPtr ptr).toNat / 2 ^ k := by + apply Nat.div_eq_of_lt_le + · rw [← hsp_ptr, hsp_q]; exact Nat.le_add_right _ _ + · rw [Nat.succ_mul, ← hsp_ptr, hsp_q]; omega + rw [hdiv, ← hsp_ptr] + variable (st) in -/-- **[J] (record edit #6, item 12) `UserFrSpecA`**, the non-device twin of `DevFrDisjA`: every `OS` non-device frame -cap's page is a spec non-device data page of the cap's size. -/ -def UserFrSpecA (OS : Set U64) (s : S) (σ : Fl4SpecA64.State Unit) : Prop := +/-- **[J] (record edit #6, item 12; E0.3 containment) `UserFrSpecA`**, the non-device twin of `DevFrDisjA`: every `OS` +non-device frame cap's range lies in a spec non-device data page, which is the heap's `.other` object `b` of the page's +size (a subframe lies in its source's page; `HeapOK.disj` makes `b` the object `FrameOK` names). -/ +def UserFrSpecA (H : Heap) (OS : Set U64) (s : S) (σ : Fl4SpecA64.State Unit) : Prop := ∀ y ∈ OS, ∀ p size rights mapped ept asid va, capA st s y = .Frame p size rights false mapped ept asid va → - σ.kheap (specPtr p) = some (.archObj (.dataPage false (frameSizeOfA size))) + ∃ b pg, H b = some (.other (Fl4SpecA64.pageBitsForSize pg)) ∧ + σ.kheap (specPtr b) = some (.archObj (.dataPage false pg)) ∧ b.val ≤ p.val ∧ + p.val + 2 ^ Fl4SpecA64.pageBitsForSize (frameSizeOfA size) ≤ b.val + 2 ^ Fl4SpecA64.pageBitsForSize pg -theorem UserFrSpecA.keepA {σ σ' : Fl4SpecA64.State Unit} (capE : ∀ u ∈ OS, capA st s' u = capA st s u) +theorem UserFrSpecA.keepA {H H' : Heap} {σ σ' : Fl4SpecA64.State Unit} + (capE : ∀ u ∈ OS, capA st s' u = capA st s u) + (hg : ∀ q k, H q = some k → H' q = some k) (dp : ∀ p dev pg, σ.kheap p = some (.archObj (.dataPage dev pg)) → σ'.kheap p = some (.archObj (.dataPage dev pg))) - (h : UserFrSpecA st OS s σ) : UserFrSpecA st OS s' σ' := fun y hy p size rights mapped ept asid va hc => - dp _ _ _ (h y hy p size rights mapped ept asid va ((capE y hy).symm.trans hc)) + (h : UserFrSpecA st H OS s σ) : UserFrSpecA st H' OS s' σ' := fun y hy p size rights mapped ept asid va hc => by + obtain ⟨b, pg, hb, hk, h1, h2⟩ := h y hy p size rights mapped ept asid va ((capE y hy).symm.trans hc) + exact ⟨b, pg, hg _ _ hb, dp _ _ _ hk, h1, h2⟩ + +/-- **A word of a live non-device frame's range is in a spec user frame** (the page containing the frame). -/ +theorem UserFrSpecA.inUser {H : Heap} {σ : Fl4SpecA64.State Unit} (hH : HeapOK H) (h : UserFrSpecA st H OS s σ) + {y p : U64} {size : capability.FrameSize} {rights asid va bits w : U64} {mapped ept : Bool} (hy : y ∈ OS) + (hc : capA st s y = .Frame p size rights false mapped ept asid va) (hb : size.bits = ok bits) + (h1 : p.val ≤ w.val) (h2 : w.val < p.val + 2 ^ bits.val) : Fl4SpecA64.inUserFrame (specPtr w) σ := by + obtain ⟨b, pg, hHb, hk, c1, c2⟩ := h y hy p size rights mapped ept asid va hc + have hal : b.val % 2 ^ Fl4SpecA64.pageBitsForSize pg = 0 := by + have := hH.align b _ hHb; simpa [HKind.bits] using this + have hpb : Fl4SpecA64.pageBitsForSize (frameSizeOfA size) = bits.val := by + cases size <;> simp [frameSizeOfA, Fl4SpecA64.pageBitsForSize, capability.FrameSize.bits] at hb ⊢ <;> + cases hb <;> decide + have hle39 : Fl4SpecA64.pageBitsForSize pg ≤ 39 := by + cases pg <;> simp [Fl4SpecA64.pageBitsForSize, Fl4SpecA64.pageBits, Fl4SpecA64.ptTranslationBits] + rw [hpb] at c2 + refine ⟨pg, ?_⟩ + rw [mask_page_eqA w b (Fl4SpecA64.pageBitsForSize pg) hle39 hal (by omega) (by omega)] + exact hk variable (st) in -/-- **[J] (frth, Architect 21:53Z) `FrThA`**: every live non-device Frame cap of `OS` names an `other` object of the -typed heap `th` of its full size `2 ^ bits` (`size.bits = ok bits`; A64 frame types 7 / 9 / 10). -/ +/-- **[J] (frth, Architect 21:53Z) `FrThA`**: every live non-device Frame cap of `OS` lies in an `other` object of the +typed heap `th` (E0.3 containment; bytes `len`) (`size.bits = ok bits`; A64 frame types 7 / 9 / 10). -/ def FrThA (th : TypedHeapA) (OS : Set U64) (s : S) : Prop := ∀ y ∈ OS, ∀ p size rights x1 x2 x3 x4 bits, capA st s y = .Frame p size rights false x1 x2 x3 x4 → size.bits = ok bits → - th p = some (.other (2 ^ bits.val)) + ∃ b len, th b = some (.other len) ∧ b.val ≤ p.val ∧ p.val + 2 ^ bits.val ≤ b.val + len /-- A frame cap after was a frame cap of the same page and size before (any other fields): `FrThA` is kept when the typed heap keeps the `other` objects. -/ @@ -211,7 +327,8 @@ theorem FrThA.ofSrc {th th' : TypedHeapA} {s' : S} (thE : ∀ p z, th p = some (.other z) → th' p = some (.other z)) (h : FrThA st th OS s) : FrThA st th' OS s' := fun y hy p size rights x1 x2 x3 x4 bits hc hb => by obtain ⟨z, hz, r0, a, b, c, d, e⟩ := src y hy p size rights x1 x2 x3 x4 hc - exact thE _ _ (h z hz p size r0 a b c d bits e hb) + obtain ⟨b0, len, hb0, h1, h2⟩ := h z hz p size r0 a b c d bits e hb + exact ⟨b0, len, thE _ _ hb0, h1, h2⟩ theorem FrThA.keepA {th th' : TypedHeapA} (capE : ∀ u ∈ OS, capA st s' u = capA st s u) (thE : ∀ p z, th p = some (.other z) → th' p = some (.other z)) diff --git a/proofs/Fl4ProofsA64/P3/Stage3FinA.lean b/proofs/Fl4ProofsA64/P3/Stage3FinA.lean index 426e8a937..7cc3502fd 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3FinA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3FinA.lean @@ -23,6 +23,7 @@ import Fl4ProofsA64.P3.Stage3DelInA import Fl4ProofsA64.P3.Stage3SysPlaceA import Fl4ProofsA64.P3.Stage3OffAsEA import Fl4ProofsA64.P1.S1aStepPool +import Fl4ProofsA64.P1.S1aSubFin open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -72,6 +73,32 @@ theorem JSyscallA.decPreA DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (capA st s x) extra := J.toJStage3EntryA.decPreA J.actW J.running J.curSc J.cur hx hext +/-- **The `fin` bundle from the entry facts at the post state** (the tail of `decodeFinA`, shared with the +`DeriveSubframe` arm's `decodeFinSubA`). -/ +theorem JSyscallA.finTailA {ar : machine.Arch A} (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) + {Pt Ub Pp7 Tb7 Hr Te Kt : Set U64} {Lv7 Re bits KLv : U64 → Nat} + (W : J7UnpA st ar hPl.ipa Z H OS s Pt Ub Pp7 Tb7 Hr Te Kt Lv7 Re bits KLv) {s3 : S} + (hk : L.ksb s3 = L.ksb s) + (e1 : S1aStepEnt st H Z.Cs OS U ia ie s3) + (Fx : S1aStepFix st H Z.Cs OS Z.V Ub Pt Kt KLv ia ie hPl.ipa s3) (e4' : PoolNamed st OS s3) + (σ3 : Fl4SpecA64.State Unit) (m3 : Fl4SpecA64.McState) : + L.ksb s3 = L.ksb s ∧ ∃ 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 m3 := by + obtain ⟨S1, -, ⟨Ac', bx⟩, -, us, -, -⟩ := e1 + have hsp : ∀ p, SchedPageA st Z OS s3 p → p ∈ Pt := by + obtain ⟨_, -, -, -, ⟨_, _, _, _, _, _, _, R'⟩, -⟩ := Fx + exact schedPage_ptA R' W.sp + have sym : SymL st H Z.Cs s3 := by + obtain ⟨_, i, _⟩ := Fx + exact i.2.1 + exact ⟨hk, Ac', S1, sym, bx, us, + J7A.of_stepFixedA Fx W.vr hk W.al W.vu e4' hsp + (fun b hb o ho => by rw [hk]; exact W.ks b hb o ho) (J7R2K.of_stepFixedA (σ' := σ3) (m := m3) Fx W.ktK)⟩ + /-- **The `fin` bundle of the heap-keeping decode arms** (module docstring). -/ theorem JSyscallA.decodeFinA {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)) @@ -113,18 +140,32 @@ theorem JSyscallA.decodeFinA {ar : machine.Arch A} (hA : P0.ArchTotal ar) (hM : have e4 := post_of_okA (syscall.decode_invocation.poolNamedFix hA hM hPl I hPI D P B Y hrd J.ko W.col a hc hIq hSC mcp J.cur.2 fh hScC W.r2 W.df W.hiK W.pn len blk call don fp buf) hd have hk : L.ksb s3 = L.ksb s := e3.2.2 - obtain ⟨-, S1, -, ⟨Ac', bx⟩, -, us, -, -⟩ := e1 - have Fx : S1aStepFix st H Z.Cs OS Z.V Ub Pt Kt KLv ia ie hPl.ipa s3 := e2 - have hsp : ∀ p, SchedPageA st Z OS s3 p → p ∈ Pt := by - obtain ⟨_, -, -, -, ⟨_, _, _, _, _, _, _, R'⟩, -⟩ := Fx - exact schedPage_ptA R' W.sp - have e4' : PoolNamed st OS s3 := e4 - have sym : SymL st H Z.Cs s3 := by - obtain ⟨_, i, _⟩ := Fx - exact i.2.1 - exact ⟨hk, Ac', S1, sym, bx, us, - J7A.of_stepFixedA Fx W.vr hk W.al W.vu e4' hsp - (fun b hb o ho => by rw [hk]; exact W.ks b hb o ho) (J7R2K.of_stepFixedA (σ' := σ3) (m := m3) Fx W.ktK)⟩ + exact JSyscallA.finTailA hPl J W hk e1.2 e2 e4 σ3 m3 + +/-- **The `fin` bundle after `DeriveSubframe`** (E0.5d): `decodeFinA` for the new arm, from `subFin`. -/ +theorem JSyscallA.decodeFinSubA {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) + {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (hsl : slot ∈ OS) (hcap : capA st s slot = cap) + (hext : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hcov : SlotCov st OS s slot) + {lbl : U64} (hc : DecArmS1aSub cap lbl) + {len : U64} {blk call don fp : Bool} {buf : U64} {r : core.result.Result Unit error.Exc} {s3 : S} {a3 : A} + (hd : syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra = ok (r, s3, a3)) + (σ3 : Fl4SpecA64.State Unit) (m3 : Fl4SpecA64.McState) : + L.ksb s3 = L.ksb s ∧ ∃ 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 m3 := by + subst hcap + 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 := J.decPreA hsl hext + have P := J.toJStage3A.sysPlace hext hsl hcov + have hrd : obj.Slot.cap st slot s = ok (capA st s slot) := capA_eq s slot + obtain ⟨-, e1, e2, e4, hk⟩ := post_of_okA (syscall.decode_invocation.subFin I D P J.sys.sysl J.symL hrd W.col W.cc + W.df a hc W.r2 W.sep W.hiK W.pn len blk call don fp buf) hd + exact JSyscallA.finTailA hPl J W hk e1 e2 e4 σ3 m3 end diff --git a/proofs/Fl4ProofsA64/P3/Stage3HPreA.lean b/proofs/Fl4ProofsA64/P3/Stage3HPreA.lean index dcf522b0e..3415a6511 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3HPreA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3HPreA.lean @@ -43,11 +43,11 @@ theorem hPre_ofA {Clock : A → MachineState → Prop} {poll : SMonad Unit (Opti (hLimit : ∀ a', sporadic.max_release_time ar a' ⦃ v => v.bv = fl4MaxReleaseTime ⦄) (hmax : maxTicksToUs = core.num.U64.MAX.bv) (htu : ∀ a v, ar.ticks_to_us a v ⦃ r => r.bv = ticksToUs v.bv ⦄) (hconv : Fl4TicksToUsLegacyAgree) - (hSend : ∀ (s' : S) (a' : A) (τ : State Unit), Rch s' a' → A64RelPS3 st AR ar nA n Cs s' a' τ m → PreExitA τ → - Clock a' τ.machineState → + (hSend : ∀ (s' : S) (a' : A) (τ : State Unit), Rch s' a' → + ∀ m', A64RelPS3at st AR ar nA n Cs s' a' τ m m' → PreExitA τ → Clock a' τ.machineState → ∀ (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), Z.Cs = Cs → - SendPA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m Clock s' a' τ) + SendPA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ nA m' Clock s' a' τ) (line : ∀ (s' : S) (a' : A) (r : S × A) (τ : State Unit) (irq : U64) (a'' : A) (τ' : State Unit), syscall.mcs_preemption_point st ar s' a' = ok r → A64RelS3 st AR ar nA n Cs r.1 r.2 τ m → ar.take_pending_irq r.2 = ok (irq, a'') → irq ≠ syscall.NO_IRQ → (some irq.bv, τ') ∈ (poll τ).1 → @@ -57,10 +57,14 @@ theorem hPre_ofA {Clock : A → MachineState → Prop} {poll : SMonad Unit (Opti syscall.after_invocation st ar s' a' (.Err .Preempted) ⦃ r => r.1 = false ∧ StepPostA (fun s'' a'' υ => A64RelS3 st AR ar nA n Cs s'' a'' υ m) (fl4PreemptionPath (pendingIrqA poll preemptServiceA)) τ r.2 ⦄ := by - intro s' a' τ hr hRel hPre clk + intro s' a' τ hr ⟨m', hg, hRel⟩ hPre clk subst hn - exact afterPreemptA hA hPl hnA K hMax hpoll hCs one hnd rfl hag hmb hLimit hmax htu hconv clk - (fun _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ J => BufOffXA.ofBufOff st J.bufOff) (hSend s' a' τ hr hRel hPre clk) hRel hPre (line s' a') + refine WP.spec_mono (afterPreemptA (m := m') hA hPl hnA K hMax hpoll hCs one hnd rfl hag hmb hLimit hmax htu hconv clk + (fun _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ J => BufOffXA.ofBufOff st J.bufOff) + (hSend s' a' τ hr m' ⟨hg, hRel⟩ hPre clk) hRel hPre + (fun r τ2 irq a2 τ3 h1 h2 => line s' a' r τ2 irq a2 τ3 h1 (A64RelS3.grow hg h2))) ?_ + rintro r ⟨e, τ4, mem, R⟩ + exact ⟨e, τ4, mem, A64RelS3.grow hg R⟩ variable (st) in /-- **The callers' plug-in `hPre`** (the statement of `sendBodyScopeA`'s / `cnodeCopyBodyA`'s / … premise). -/ @@ -100,10 +104,10 @@ structure HPreEnvA (AR : A → HwRootA → Prop) (ar : machine.Arch A) (hPl : Ar (L.mem s (regWA (L.curW s) layout.reg.CAP)) → 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, s', a') → - A64RelPS3 st AR ar hPl.ipa n Cs s' a' τ m → PreExitA τ → Clock a' τ.machineState → + ∀ m', A64RelPS3at st AR ar hPl.ipa n Cs s' a' τ m m' → PreExitA τ → Clock a' τ.machineState → ∀ (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), Z.Cs = Cs → - SendPA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m Clock s' a' τ + SendPA st ar AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ hPl.ipa m' Clock s' a' τ /-- [P] the poll, its pending interrupt, and [J] the accepted line. -/ poll : ∃ poll : SMonad Unit (Option Word), PollAgreeA ar AR poll ∧ pendingIrqA poll preemptServiceA = pending ∧ ∀ (s' : S) (a' : A) (r : S × A) (τ : State Unit) (irq : U64) (a'' : A) (τ' : State Unit), @@ -122,7 +126,7 @@ theorem HPreA.ofEnv {Z : XSetsA} {Clock : A → MachineState → Prop} {pending 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.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 + (fun s2 a2 τ2 hr2 m' hR hP clk => E.hSend calling blocking donate s2 a2 τ2 hd hr2 m' hR hP clk) line s' a' τ hh h.1 h.2.1 h.2.2 end diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecCnA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecCnA.lean index 521b4ec17..b29206ba6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InvSpecCnA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecCnA.lean @@ -44,7 +44,7 @@ theorem CnScopeA.invSpecA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (do fl4InvokeCnode i; Fl4Spec.NonDetE.returnOk []) := fun _ => by cases blk <;> cases call <;> cases don <;> rfl induction h with - | @cnodeCopy ps pd nc anc slot p r gs g extra lbl length buf index depth x0 si sdp root bB bC bD hnvm ss sd hCs hCd hsn hdn hdc hwf hanc hw hn hD hal hk hsh hsh1 hbd1 hbd hirq hz hut hdo hcv hsci hslot hslc hlb hl4 hl2 hi hd0 hres hx0 h0 h2 h3 hroot hemp hsrc hcop hcov hext hSC hpin => + | @cnodeCopy ps pd nc anc slot p r gs g extra lbl length buf index depth x0 si sdp root bB bC bD hnvm ss sd hCs hCd hsn hdn hdc hwf hanc hw hn hD hrd hal hk hsh hsh1 hbd1 hbd hirq hz hut hdo hcv hsci hslot hslc hlb hl4 hl2 hi hd0 hres hx0 h0 h2 h3 hroot hemp hsrc hcop hcov hext hSC hpin => obtain ⟨x, hx, hperf⟩ := hOut obtain ⟨σ1, hset⟩ : ∃ σ1, σ1 = stUpdA σ σ.curThread x .restart := ⟨_, rfl⟩ refine InvSpecA.ofPin hP hpin F cptr (σ1 := σ1) (by rw [hset]; exact hst x hx) ?_ diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTopA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTopA.lean index 985ba154f..9c6cd4269 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InvSpecTopA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecTopA.lean @@ -103,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 | h + rcases h with h | 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 @@ -129,6 +129,14 @@ theorem DispScope4A.invSpecA [PlainStore st] {ar : machine.Arch A} (hA : P0.Arch · 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 + · obtain ⟨s0, a0, σ0, e0, -⟩ := UtPreScopeA.soundPre (m := m) hA hPl J hfm h + have er := (Prod.mk.inj (okinj (hd.symm.trans e0))).1 + have hdf : done = false := by + rcases hdone with ⟨-, h⟩ | ⟨h, -⟩ + · rw [er] at h; cases h + · exact h + subst hdf + exact UtPreScopeA.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 diff --git a/proofs/Fl4ProofsA64/P3/Stage3InvSpecVsA.lean b/proofs/Fl4ProofsA64/P3/Stage3InvSpecVsA.lean index 8b1727866..ae17333b9 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3InvSpecVsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3InvSpecVsA.lean @@ -93,13 +93,13 @@ theorem VsScopeA.invSpecA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} rw [flags] refine liftE_memA ?_ exact mem_bindA.2 ⟨_, hperf, Set.mem_singleton _⟩ - | @ptUnmapS1 bB bC bD bF K hnvm hTO hEO length buf ex cte hab ptr asid va hpS hcap hf hS1 hcov hext hSC hpin => + | @ptUnmapS1 bB bC bD bF K hnvm hTO hEO length buf ex cte hab ptr asid va hpS hcap hf hno hS1 hcov hext hSC hpin => obtain ⟨x, -, hset, hperf⟩ := hOut refine InvSpecA.ofPin hP hpin F cptr hset ?_ rw [flags] refine liftE_memA ?_ exact mem_bindA.2 ⟨_, hperf, Set.mem_singleton _⟩ - | @ptUnmapX bB bC bD bF K hnvm hTO hEO hIpa length buf ex cte hab ptr asid va hpS hcap hf k hkR hkR1 hcov hext hSC hpin => + | @ptUnmapX bB bC bD bF K hnvm hTO hEO hIpa length buf ex cte hab ptr asid va hpS hcap hf hno k hkR hkR1 hcov hext hSC hpin => obtain ⟨x, -, hset, hperf⟩ := hOut refine InvSpecA.ofPin hP hpin F cptr hset ?_ rw [flags] @@ -109,6 +109,12 @@ 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 + | @ptUnmapT2Stale bB bC bD bF K hnvm length buf ex cte hab ptr asid va hpT hcap hf hno hS1 hcov hext hSC hpin => + obtain ⟨x, -, hset, hperf⟩ := hOut + refine InvSpecA.ofPin hP hpin F cptr hset ?_ + rw [flags] + refine liftE_memA ?_ + exact mem_bindA.2 ⟨_, hperf, Set.mem_singleton _⟩ | @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,11 +126,21 @@ theorem VsScopeA.invSpecA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} refine InvSpecA.ofPin hP hpin F cptr hset ?_ rw [flags] exact hperf + | @asidMakePool hnN h1 hCs hn hnvm cte hab hcteC hcov ex hext hSC parent dest frame fi i base hAp hAd hdc hCp hCd hdr length buf block call cd fp hx0 hx1 hlen2 a0 a1 ha0 ha1 hpa hcp hnc hiOk hi hfree hbaseOk hbase hlt hcd hpin => + obtain ⟨x, -, hset, hperf⟩ := hOut + refine InvSpecA.ofPin hP hpin F cptr hset ?_ + rw [flags] + exact hperf | @frameMapHi x0 D dc ex s3 a3 callD lenD bufD rr bB bD bF K hnvm hTO hEO cte hab fp rt asid va sz dev mp hcap FP p1 asid1 mp1 h16 hx0 hx0c vaddr rightsMask vm attr 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 + | @frameDeriveSub s3 a3 fp rt asid va mp e bB bD bF D hnvm cte hab hcap length buf call ex args hlen hargs x0 hx0 xSlot exs hex hD hdec hcov hext hpin => + obtain ⟨x, iv, -, hset, hD', hperf⟩ := hOut + refine InvSpecA.ofPin hP (hpin iv hD') F cptr hset ?_ + rw [flags] + exact liftE_memA (mem_bindA.2 ⟨((), σ'), hperf, Set.mem_singleton _⟩) | @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 ?_ diff --git a/proofs/Fl4ProofsA64/P3/Stage3J7A.lean b/proofs/Fl4ProofsA64/P3/Stage3J7A.lean index 8efe01f78..7acd779c7 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3J7A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3J7A.lean @@ -171,7 +171,7 @@ theorem w1_J7A (P : BootLay1 kb ib nc) (R : Set U64 → JSlotA BS) (σ : Fl4Spec exact ⟨h1, q, k, hg _ _ hq, h2⟩ refine ⟨w1Pt ∪ {bwv KTb}, w1Ub, B.2.2.2.2.1, hpn, arm, ⟨w1_ubFr P, huo, fun y hy ptr size rights x1 x2 x3 x4 hc bits hb => - hg _ _ (w1_frameOK (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P y hy ptr size rights x1 x2 x3 x4 hc + FrAt.mono hg (w1_frameOK (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P y hy ptr size rights x1 x2 x3 x4 hc bits hb)⟩, hvc, w1_devFrAl P, (w1_s1aPtCol P).hi, ?_, fun b hb => ?_, w1_frUb P, fun _ hb => hb.1, fun _ h => absurd h.choose_spec.1 (Set.notMem_empty _), hR⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3KtA.lean b/proofs/Fl4ProofsA64/P3/Stage3KtA.lean index 34461b20c..ce125f8c4 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3KtA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3KtA.lean @@ -125,6 +125,7 @@ theorem JStage3EntryA.addKt {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap vs := by rw [eT]; exact J.ap.vs ext := by rw [eT]; exact J.ap.ext } ko := X.ksOff J.ko + userFr := J.userFr.keepA (fun _ _ => rfl) hg (fun _ _ _ g => g) ptH := J.ptH.monoH hg poolOff := PoolOff.addKt X J.poolOff objAlloc := fun p bytes hp u hu q b i d hc => by diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftIrqIssueA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftIrqIssueA.lean index 81488ff9f..2d5657d26 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftIrqIssueA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftIrqIssueA.lean @@ -232,11 +232,11 @@ theorem JSyscallA.irqIssueStepA [PlainStore st] (hA : P0.ArchTotal ar) (hPl : Ar have hfr1 : ∀ y ∈ Z.G.chains.flatten, capA st s1 y ≠ .IrqHandler irq := fun y hy hc => by have hyO := ((hTr2.lk.members y).1 hy).1 exact hno1 y hyO ((osk1.capA hyO).symm.trans hc) - obtain ⟨s3, σ3, hs3, hm3, hbk3, -, J3⟩ := JStage3A.capInsertGenA (J := J2) (nc := .IrqHandler irq) + have Hder_ := JStage3A.capInsertGenA (J := J2) (nc := .IrqHandler irq) (anc := absCapA (.IrqHandler irq)) ss sd (hCs := hCs) (hCd := hCd) (hsn := by rw [hcs1]; simp) (hdn := hdn1) (hdc := OSOK.canon J2.sys.ent.os J2.winOK (hsd ▸ hdO)) (hwf := hi) (hanc := CapEqA.of_abs rfl) (hw := trivial) (hn := by simp) (hD := by rw [hcs1]; exact DerivA.irqH irq) - (hal := by rw [hcs1]; exact handlerFromControlIA irq) (hk := by rw [hcs1]; trivial) + (hal := Or.inl (by rw [hcs1]; exact handlerFromControlIA irq)) (hk := by rw [hcs1]; trivial) (hut := fun h => by rw [hcs1] at h; simp [isUtA] at h) (hdo := Or.inl (by rw [hCd.1, fl4Ptr_specPtr, hksb]; exact hpdn)) (hsci := ⟨fun c _ => by simp [absCapA], fun b => by simp [absCapA], fun _ _ _ h => by simp [absCapA] at h⟩) @@ -260,6 +260,7 @@ theorem JSyscallA.irqIssueStepA [PlainStore st] (hA : P0.ArchTotal ar) (hPl : Ar (symL := fun s3 hs3 => (F s3 a1' (hinv s3 hs3) σ m).choose_spec.2.1) (sysl := fun s3 hs3 => (F s3 a1' (hinv s3 hs3) σ m).choose_spec.1) (j7 := fun s3 σ3 hs3 _ => (F s3 a1' (hinv s3 hs3) σ3 m).choose_spec.2.2.2.2) + obtain ⟨s3, σ3, hs3, hm3, hbk3, -, J3⟩ := Hder_ (RootDerivA.of_no (NoRootKindA.of_ne (fun _ _ _ h => by cases h) (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h)) (NoPtKindA.of_ne (fun _ _ _ _ h => by cases h))) obtain ⟨x, hx, -, hset', -⟩ := J.restartMachA hsl hcov hext have e1 : stUpdA σ σ.curThread xt .restart = stUpdA σ σ.curThread x .restart := by have := Set.singleton_eq_singleton_iff.1 (congrArg Prod.fst (hset.symm.trans hset')) diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftIrqSetA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftIrqSetA.lean index 7dc3626fb..cb95accbf 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftIrqSetA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftIrqSetA.lean @@ -146,7 +146,7 @@ theorem JSyscallA.irqSetA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSpi ar rcases hb with hb | hb · cases hb · exact (Cap.notificationCap.inj hb).2.1 - obtain ⟨s3, σ3, hs3, hm3, hbk3, scF3, J3⟩ := JStage3A.capInsertA (J := J2) (nc := .Notification pn bg true recv) + have Hder_ := JStage3A.capInsertA (J := J2) (nc := .Notification pn bg true recv) (anc := absCapA (.Notification pn bg true recv)) ss sd (hCs := hCsS) (hCd := ⟨J1.j.1.irq.node irq hi, place1.irq irq hi⟩) (hsn := by rw [hcs2]; simp) (hdn := by rw [hesl, ← hy]; exact hnull) @@ -161,6 +161,7 @@ theorem JSyscallA.irqSetA [PlainStore st] (hA : P0.ArchTotal ar) (hM : MaxSpi ar (symL := fun s3 hs3 => (F s3 hs3 σ2 m).choose_spec.2.1) (sysl := fun s3 hs3 => (F s3 hs3 σ2 m).choose_spec.1) (j7 := fun s3 σ3 hs3 _ => (F s3 hs3 σ3 m).choose_spec.2.2.2.2) + obtain ⟨s3, σ3, hs3, hm3, hbk3, scF3, J3⟩ := Hder_ (RootDerivA.of_no (NoRootKindA.of_ne (fun _ _ _ h => by cases h) (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h)) (NoPtKindA.of_ne (fun _ _ _ _ h => by cases h))) have hdec3 := hdecS s3 hs3 obtain ⟨ac0, hg, hac⟩ := irqSlot_ntfnOrNullA J1 D1 hi have hbody := deletingIrqHandler_bodyA hg hac (irqSlot_qneA J1 D1 hi hg) hstep diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgFrontA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgFrontA.lean index cd6d08724..dd3967ee5 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgFrontA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbCfgFrontA.lean @@ -188,7 +188,7 @@ theorem JSyscallA.configFrontA [PlainStore st] (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 h => by rw [h]; rfl) (fun _ => tcbInsKA_selfA hvk (rootDerivA_of_derive (hvdr s)) (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))) diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbHighA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbHighA.lean index 233ecbc80..abb76c6dc 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbHighA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbHighA.lean @@ -185,7 +185,9 @@ theorem JSyscallA.setHighVSpaceA [PlainStore st] 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) + exact tcbInsKA_selfA (Or.inr (Or.inr (Or.inr (Or.inr ⟨_, _, _, rfl⟩)))) + (RootDerivA.of_p1 ⟨fun _ => rfl, by rintro (⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ | ⟨_, _, _, h⟩) <;> cases h⟩) + (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 diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSpaceA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSpaceA.lean index 9523929d6..902468bf1 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSpaceA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSpaceA.lean @@ -176,7 +176,10 @@ theorem JSyscallA.setSpaceA [PlainStore st] 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) + exact tcbInsKA_selfA hk (by + rcases hfhK with h | ⟨ep, b0, b1, b2, b3, b4, h, -⟩ + · exact absurd h hn + · rw [h]; exact RootDerivA.of_no (NoRootKindA.of_ne (fun _ _ _ h => by cases h) (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h)) (NoPtKindA.of_ne (fun _ _ _ _ h => by cases h))) (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 @@ -216,7 +219,7 @@ theorem JSyscallA.setSpaceA [PlainStore st] (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 h => by rw [h]; rfl) (fun _ => tcbInsKA_selfA hvk (rootDerivA_of_derive (hvdr s)) (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))) diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspEpA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspEpA.lean index d840a6f2c..6b0cecfcf 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspEpA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbSspEpA.lean @@ -491,7 +491,7 @@ theorem JSyscallA.setSchedParamsEpA [PlainStore st] (absCapA (capA st sd (cslotAddrA κsrc)))))) have hFs : ∀ s2, cdt.insert st sd (.Endpoint p b sn rv g gr) (cslotAddrA κsrc) (cslotAddrA sl) = ok s2 → s2 = s2a := fun s2 h2 => okinj (h2.symm.trans hs2a) - obtain ⟨s2, σ2, hs2, hm, hbk, -, J2⟩ := JStage3A.capInsertTcbSlotA (J := Jd) κsrc sl (ps := ps) ⟨hss1, hss2⟩ + obtain ⟨s2, σ2, hs2, hm, hbk, -, J2⟩ := JStage3A.capInsertTcbSlotA (hrd := RootDerivA.of_no (NoRootKindA.of_ne (fun _ _ _ h => by cases h) (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h)) (NoPtKindA.of_ne (fun _ _ _ _ h => by cases h))) (J := Jd) κsrc sl (ps := ps) ⟨hss1, hss2⟩ (t0 := t) hthT (i := 3) (by decide) (by decide) (by decide) hsl (by rw [hS']; simp) hdn (J.delCanA _ hdOS) (nc := .Endpoint p b sn rv g gr) (anc := absCapA (.Endpoint p b sn rv g gr)) (fun _ => hN) hwf diff --git a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutNnA.lean b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutNnA.lean index e100a7310..9e0812cfc 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutNnA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3LiftTcbTimeoutNnA.lean @@ -349,7 +349,7 @@ theorem JSyscallA.setTimeoutNonNullA [PlainStore st] 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 - obtain ⟨s2, σ2, hs2, hm, hbk, -, J2⟩ := JStage3A.capInsertTcbSlotA (J := Jd) κsrc sl (ps := ps) ⟨hss1, hss2⟩ + obtain ⟨s2, σ2, hs2, hm, hbk, -, J2⟩ := JStage3A.capInsertTcbSlotA (hrd := RootDerivA.of_no (NoRootKindA.of_ne (fun _ _ _ h => by cases h) (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h)) (NoPtKindA.of_ne (fun _ _ _ _ h => by cases h))) (J := Jd) κsrc sl (ps := ps) ⟨hss1, hss2⟩ (t0 := t) hthT (i := 4) (by decide) (by decide) (by decide) hsl (by rw [hS']; simp) (by exact hnull) (J.delCanA _ hdOS) (nc := .Endpoint p b sn rv g gr) (anc := absCapA (.Endpoint p b sn rv g gr)) (fun h => by cases h) hwf (CapEqA.of_abs rfl) hw' (by simp) diff --git a/proofs/Fl4ProofsA64/P3/Stage3MapAlikeA.lean b/proofs/Fl4ProofsA64/P3/Stage3MapAlikeA.lean index ca5dec2c4..4830b3414 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3MapAlikeA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3MapAlikeA.lean @@ -68,12 +68,12 @@ variable {d c : capability.Cap} theorem MapAlikeA.shape (h : MapAlikeA d c) : shpA d = shpA c := by cases h <;> rfl -theorem MapAlikeA.shape3 (h : MapAlikeA d c) : Fl4ProofsA64.P3.shapeA d = Fl4ProofsA64.P3.shapeA c := by cases h <;> rfl - theorem MapAlikeA.isFr (h : MapAlikeA d c) : isFrA d = isFrA c := isFrA_of_shape h.shape -theorem MapAlikeA.ua (h : MapAlikeA d c) : UA d c := - UA.of_shapeA h.shape3 fun hu => by cases h <;> simp_all [isUtA] +theorem MapAlikeA.ua (h : MapAlikeA d c) : UA d c := by + cases h with + | refl => exact UA.of_shapeA rfl fun _ => rfl + | _ => exact ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by cases h⟩ theorem MapAlikeA.back_eq (h : MapAlikeA d c) {e : capability.Cap} (he : StableCapA e) (hd : d = e) : c = e := by cases h with @@ -194,13 +194,33 @@ theorem DevUtOffA.mapA {Z Z' : XSetsA} {H : Heap} {ia ie : Nat} (hM : ∀ u ∈ rw [eC, hk] exact ⟨fun c hcs => by rw [hnb c]; exact r.1 c hcs, r.2⟩ -theorem FrBaseApartA.mapA (hM : ∀ u ∈ OS, MapAlikeA (capA st s' u) (capA st s u)) (h : FrBaseApartA st OS s) : - FrBaseApartA st OS s' := fun y hy z hz fy kz => by - have my := hM y hy - have mz := hM z hz - rw [my.isFr] at fy - rw [mz.ua.ptr, my.ua.ptr] - exact h y hy z hz fy (mz.rngKey.1 kz) +theorem revA_of_wordA {s s' : S} {u : U64} + (h : L.mem s' (core.num.U64.wrapping_add u 24#u64) = L.mem s (core.num.U64.wrapping_add u 24#u64)) : + Fl4ProofsA64.P1.W7.R.ST.revA st s' u = Fl4ProofsA64.P1.W7.R.ST.revA st s u := by + unfold Fl4ProofsA64.P1.W7.R.ST.revA; rw [h] + +theorem FrLamA.mapA (hM : ∀ u ∈ OS, MapAlikeA (capA st s' u) (capA st s u)) (revE : ∀ u ∈ OS, Fl4ProofsA64.P1.W7.R.ST.revA st s' u = Fl4ProofsA64.P1.W7.R.ST.revA st s u) + (h : FrLamA st OS s) : FrLamA st OS s' := + h.tr (fun y hy p rt mp e asid va hc => by + obtain ⟨m0, e0, a0, v0, hc0⟩ := (hM y hy).frame_back hc + exact ⟨y, hy, p, rt, m0, e0, a0, v0, hc0, by rw [(hM y hy).ua.base], by rw [(hM y hy).ua.top]⟩) + (fun z hz pz => ⟨z, hz, by rw [← (hM z hz).ua.phys]; exact pz, (hM z hz).ua.base, (hM z hz).ua.top, + fun f r => ⟨by rw [(hM z hz).isFr]; exact f, by rw [revE z hz]; exact r⟩⟩) + +theorem FrBaseApartA.mapA (hM : ∀ u ∈ OS, MapAlikeA (capA st s' u) (capA st s u)) (revE : ∀ u ∈ OS, Fl4ProofsA64.P1.W7.R.ST.revA st s' u = Fl4ProofsA64.P1.W7.R.ST.revA st s u) + (h : FrBaseApartA st OS s) : FrBaseApartA st OS s' := + ⟨fun y hy z hz fy kz => by + have my := hM y hy + have mz := hM z hz + rw [my.isFr] at fy + rw [mz.ua.ptr, my.ua.ptr] + exact h.1 y hy z hz fy (mz.rngKey.1 kz), + fun y hy z hz fy kz => by + have my := hM y hy + have mz := hM z hz + rw [my.isFr] at fy + rw [mz.ua.base, my.ua.base, my.ua.top] + exact h.2.1 y hy z hz fy (mz.rngKey.1 kz), FrLamA.mapA hM revE h.2.2⟩ theorem DevWinCapA.mapA (hM : ∀ u ∈ OS, MapAlikeA (capA st s' u) (capA st s u)) (o : DevWinCapA st OS s) : DevWinCapA st OS s' := fun u hu => @@ -217,12 +237,13 @@ theorem DevFrDisjA.mapA {H : Heap} {σ σ' : Fl4SpecA64.State Unit} (hM : ∀ u obtain ⟨h1, dev, pg, h2⟩ := h y hy p size rights m0 e0 a0 v0 hc0 k hk exact ⟨h1, dev, pg, dp _ _ _ h2⟩ -theorem UserFrSpecA.mapA {σ σ' : Fl4SpecA64.State Unit} (hM : ∀ u ∈ OS, MapAlikeA (capA st s' u) (capA st s u)) +theorem UserFrSpecA.mapA {H : Heap} {σ σ' : Fl4SpecA64.State Unit} (hM : ∀ u ∈ OS, MapAlikeA (capA st s' u) (capA st s u)) (dp : ∀ p dev pg, σ.kheap p = some (.archObj (.dataPage dev pg)) → σ'.kheap p = some (.archObj (.dataPage dev pg))) - (h : UserFrSpecA st OS s σ) : UserFrSpecA st OS s' σ' := by + (h : UserFrSpecA st H OS s σ) : UserFrSpecA st H OS s' σ' := by intro y hy p size rights mapped ept asid va hc obtain ⟨m0, e0, a0, v0, hc0⟩ := (hM y hy).frame_back hc - exact dp _ _ _ (h y hy p size rights m0 e0 a0 v0 hc0) + obtain ⟨b, pg, hb, hk, h1, h2⟩ := h y hy p size rights m0 e0 a0 v0 hc0 + exact ⟨b, pg, hb, dp _ _ _ hk, h1, h2⟩ theorem FrThA.mapA {th th' : TypedHeapA} (hM : ∀ u ∈ OS, MapAlikeA (capA st s' u) (capA st s u)) (thE : ∀ p z, th p = some (.other z) → th' p = some (.other z)) (h : FrThA st th OS s) : FrThA st th' OS s' := diff --git a/proofs/Fl4ProofsA64/P3/Stage3MapExtCoreA.lean b/proofs/Fl4ProofsA64/P3/Stage3MapExtCoreA.lean index 1b8acff1b..7eb91311a 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3MapExtCoreA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3MapExtCoreA.lean @@ -164,10 +164,13 @@ theorem JStage3A.frameMapExtCoreA {AR : A → HwRootA → Prop} {Z : XSetsA} {H rw [J.pp] at a1 a2 exact ⟨a1, a2⟩ have main := J1.of_capVsFrameA (hpt := fun _ _ _ h => by rw [ec] at h; cases h) + (hrt := RootSetA.of_noRoot (fun r hk => by + rw [ec] at hk; rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h)) + (hptw := Or.inl (PtSetA.of_noPt (fun r hk => by rw [ec] at hk; obtain ⟨_, _, _, h⟩ := hk; cases h))) (Q := fun s' a' σ'' hw => s' = s3 ∧ a' = a3 ∧ σ'' = extSlotWriteX σ2 sl 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 hTr hnul hcn (by rw [c1]; exact fun h => by cases h) - (c := c) (by rw [c1]; exact hM) hok hirq hsci + (c := c) (by rw [c1]; exact hM) hok hirq hsci (PtSrcA.nopt fun _ _ _ _ h => by rw [ec] at h; cases h) (fun s2' σ2' hs2 hσ2' HSs w' jx hcx => by obtain rfl : s2' = s2 := okinj (hs2.symm.trans hsc) obtain rfl : σ2' = σ2 := setCap_detA hσ2' hσ2 diff --git a/proofs/Fl4ProofsA64/P3/Stage3MapShapeA.lean b/proofs/Fl4ProofsA64/P3/Stage3MapShapeA.lean index 1394b32c0..c6beacbd9 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3MapShapeA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3MapShapeA.lean @@ -69,7 +69,7 @@ def MapShapeA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (sl fp r ¬ AsW (L.ksb s2) (peAF p i) ∧ L.ksb s' = L.ksb s2 ∧ L.cpu s' = L.cpu s2 ∧ (∀ w, Aligned w → L.mem s' w = L.mem (L.wr s2 (peAF p i) e) w) ∧ - (∃ t', σ3 = ptSetA σ2 (specPtr p) t') ∧ MsA σ3 σ' ∧ + (∃ t', σ3 = ptSetA σ2 (specPtr p) t' ∧ Fl4SpecA64.ptApply t' i.bv = pte) ∧ MsA σ3 σ' ∧ (([] : List Fl4SpecA64.Data), σ') ∈ (Fl4SpecA64.performPageInvocation (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s') (L.ksb s') σ' ∧ VsSpecA σ2 σ' @@ -362,7 +362,7 @@ theorem page_map_shapeA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac have hK2 : Aligned (L.ksb s2) := by rw [hksb2]; exact hKal obtain ⟨-, σ3, hstore, R4, -⟩ := write_storePteA R2 hp hidx hwr hA hK2 (fun _ h => by unfold Fl4SpecA64.makeUserPte at h; cases h) - obtain ⟨t', hσ3⟩ := storePte_eqA R2 hp hidx hstore + obtain ⟨t', hσ3, happ⟩ := storePte_eq2A R2 hp hidx hstore -- `install_page` have hsla : Aligned lu.slot := by rw [hsl]; exact peAF_alignedA (R.al_mod hp) hidx obtain ⟨s', hks', hcpu', hm', hfl⟩ := install_pageA (L := L) ar s2 a lu e r0 asid1 a0 a2 hsla @@ -385,9 +385,10 @@ theorem page_map_shapeA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac rw [hks', ← L.ksb_wr s2 lu.slot e] exact R5.of_msA hms refine PgShapeA.okA ((hfl _).bind (fun _ => rfl)) ⟨_, rfl, x, s2, σ2, asid1, a0, p, idxA a0 lu.shift, e, _, σ3, σ', - hkx, hset, hsc, hσ2, HS, hEnc, hca, hksb2, hcpu2, R2, hJ2, hFr2, hva, hp, hreach, hidx, hk1, by omega, hwr, + hkx, hset, hsc, hσ2, HS, hEnc, hca, hksb2, hcpu2, R2, + (fun h1 h2 h3 h4 h5 h6 => hJ2 h1 h2 h3 h4 h5 h6 (PtSrcA.nopt fun _ _ _ _ h => by cases h)), hFr2, hva, hp, hreach, hidx, hk1, by omega, hwr, ⟨_, _, _, _, by unfold Fl4SpecA64.makeUserPte; rfl⟩, hA, hks', hcpu', - (fun w hw => by rw [hm' w hw, hsl]), ⟨_, hσ3⟩, hms, hσ', VR, by + (fun w hw => by rw [hm' w hw, hsl]), ⟨_, hσ3, happ⟩, hms, hσ', VR, by obtain ⟨tw, hkw, -, -⟩ := R2.pt p hp exact VsSpecA.of_ptStoreA hkw (hσ3 ▸ hun)⟩ | _ => diff --git a/proofs/Fl4ProofsA64/P3/Stage3OffAsEA.lean b/proofs/Fl4ProofsA64/P3/Stage3OffAsEA.lean index 181006330..5f892112d 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3OffAsEA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3OffAsEA.lean @@ -94,6 +94,16 @@ theorem JStage3A.offAsE (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s) := fun _ _ hj hq => ptHA_not_asW J.sys.ent.heap J.ko J.sys.ent.ksw J.ptHAll hq hj +/-- **`hYAs`**: no word of a high-window root's first page is an ASID-table word (`ptHAll` covers the second pages of the +windows' roots; the first page sits in the same `other` heap object, `root_pageA`). -/ +theorem JStage3A.yNotAsW (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) : + ∀ y ∈ Z.Y, ∀ j : U64, j.val < 512 → ¬ AsW (L.ksb s) (peAF y j) := by + intro y hy j hj + 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 ptHA_not_asW J.sys.ent.heap J.ko J.sys.ent.ksw (P := {y}) + (fun p hp => by rw [Set.mem_singleton_iff] at hp; subst hp; exact ⟨q', z, hq', g1, g2⟩) (Set.mem_singleton y) hj + /-- `hK`: the state block is word aligned. -/ theorem JStage3A.ksbAligned (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) : Aligned (L.ksb s) := diff --git a/proofs/Fl4ProofsA64/P3/Stage3PinVsA.lean b/proofs/Fl4ProofsA64/P3/Stage3PinVsA.lean index 456eee3c6..a9773623b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3PinVsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3PinVsA.lean @@ -483,6 +483,22 @@ theorem frameMapHi_pinA (hlab : info.label = fl4_abi.label.ARMPageMap) {fp rt as rw [e, ← hD] exact hiv +/-- `VsScopeA.frameDeriveSub`'s pin. -/ +theorem frameDeriveSub_pinA (hlab : info.label = fl4_abi.label.ARMPageDeriveSubframe) {fp rt asid va : U64} + {mp e call : Bool} (hcap : capA st s slot = .Frame fp .Large rt false mp e asid va) (xSlot : CapRef) + {D : Set (Except SyscallError Fl4ArchInvocation × State Unit) × Prop} + (hD : D = (fl4ArchDecodeInvocation (Z := Unit) call (.ext .armPageDeriveSubframe) (argsU.map UScalar.bv) xSlot sl + (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA .Large) false (mapDataA mp asid va)) excaps).run σ) : + ∀ iv, (.ok (.deriveSubframe iv), σ) ∈ D.1 → DecPinA call Z.th σ slot (.invokeArchObject (.deriveSubframe iv)) := by + intro iv hiv + have hc : c = .archObjectCap (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA .Large) false + (mapDataA mp asid va)) := F.absA hcap (fun _ _ _ e => by cases e) + refine DecPinA.of_archA F.pin hc (F.labelA hlab (v := 55) (l := .ext .armPageDeriveSubframe) + (by simp [fl4_abi.label.ARMPageDeriveSubframe]) (by decide)) fun cptr => ?_ + rw [dec_deriveSubA call _ cptr sl e _ _ _ _ _ excaps] + rw [hD, dec_deriveSubA call _ xSlot sl e _ _ _ _ _ excaps] at hiv + 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) diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolCapsA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolCapsA.lean new file mode 100644 index 000000000..23602c274 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolCapsA.lean @@ -0,0 +1,190 @@ +/- +P3 (aarch64, Stage 4, line vsx-D, CP D1): **the cap-split fields of the record after `ARMASIDControlMakePool`**, the +pool twin of `P3/UtAsmCapsA` (`UtSlotsA` and the `utRt_*A` field lemmas, which are specific to a retype window). + +MakePool changes exactly two cap slots of the (dropped) slot set: the childless parent untyped `x` (its free index +becomes `4096`, the whole block) and the null destination `v`, which receives `AsidPool frame base`. The new pool +page is a ghost-heap `other 12` object at `frame` (A64 P1's `PoolH`) and a member of the pools `Pp`. + +* `PoolSlotsA`: where a cap of the slot set after MakePool comes from. +* `poolRt_zombieBndA`, `poolRt_zombieTcbA`, `poolRt_zombieNoVcpuA`, `poolRt_utBlkA`, `poolRt_capTyA`, + `poolRt_idleAnchorA`, `poolRt_objAllocA`: the fields `zombieBnd`, `zombieTcb`, `zombieNoVcpu`, `utBlk`, `capTy`, + `idleAnchor`, `objAlloc`. + +No named premise: hypotheses only. New module. +-/ +import Fl4ProofsA64.P3.UtAsmCapsA +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 + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] + +/-- **Where a cap of the slot set after MakePool comes from**: an old slot kept, the parent untyped `x` (now full), +or the destination `v` (now the pool cap). -/ +def PoolSlotsA (st : machine.Store S) [LawfulStore st] (OS OS' : Set U64) (s s' : S) (x v frame base : U64) : + Prop := + ∀ u ∈ OS', (u ∈ OS ∧ u ≠ x ∧ u ≠ v ∧ capA st s' u = capA st s u) ∨ (u = x ∧ capA st s' u = .Untyped frame 12#u64 4096#u64 false) ∨ + (u = v ∧ capA st s' u = .AsidPool frame base) + +variable {OS OS' : Set U64} {s s' : S} {x v frame base : U64} + +/-- A zombie of the slot set after MakePool is an old one. -/ +theorem poolRt_oldZombieA (F : PoolSlotsA st OS OS' s s' x v frame base) {u q t k : U64} (hu : u ∈ OS') + (h : capA st s' u = .Zombie q t k) : u ∈ OS ∧ capA st s u = .Zombie q t k := by + rcases F u hu with ⟨a, -, -, e⟩ | ⟨-, e⟩ | ⟨-, e⟩ + · exact ⟨a, e.symm.trans h⟩ + · rw [e] at h; cases h + · rw [e] at h; cases h + +theorem poolRt_zombieBndA (h : UtZombieA st OS s) (F : PoolSlotsA st OS OS' s s' x v frame base) : + UtZombieA st OS' s' := by + intro y hy q t k e + obtain ⟨a, b⟩ := poolRt_oldZombieA F hy e + exact h y a q t k b + +theorem poolRt_zombieTcbA {H H' : Heap} (h : ZombieTcbTA st H OS s) (F : PoolSlotsA st OS OS' s s' x v frame base) + (hH : ∀ t ∈ H.tcbs, t ∈ H'.tcbs) : ZombieTcbTA st H' OS' s' := by + intro u hu q k e + obtain ⟨a, b⟩ := poolRt_oldZombieA F hu e + exact hH q (h u a q k b) + +theorem poolRt_zombieNoVcpuA {H : Heap} (h : ZombieTcbNoVcpuA st OS s) (hz : ZombieTcbTA st H OS s) + (F : PoolSlotsA st OS OS' s s' x v frame base) + (hm : ∀ t ∈ H.tcbs, L.mem s' (wa t 3664#u64) = L.mem s (wa t 3664#u64)) : ZombieTcbNoVcpuA st OS' s' := by + intro u hu q k e + obtain ⟨a, b⟩ := poolRt_oldZombieA F hu e + rw [hm q (hz u a q k b)] + exact h u a q k b + +/-- The new untyped keeps its size bound: `12 ≤ 39`. -/ +theorem poolRt_utBlkA (h : UtBlk39A st OS s) (F : PoolSlotsA st OS OS' s s' x v frame base) : + UtBlk39A st OS' s' := by + intro u hu q b f d e + rcases F u hu with ⟨a, -, -, k⟩ | ⟨-, k⟩ | ⟨-, k⟩ + · exact h u a q b f d (k.symm.trans e) + · rw [k] at e + simp only [capability.Cap.Untyped.injEq] at e + obtain ⟨-, rfl, -⟩ := e + decide + · rw [k] at e; cases e + +/-- The two new caps carry no heap-kind obligation (`Untyped`, `AsidPool`). -/ +theorem poolRt_capTyA {H H' : Heap} (h : CapTyA st H OS s) (F : PoolSlotsA st OS OS' s s' x v frame base) + (hH : ∀ q k, H q = some k → H' q = some k) : CapTyA st H' OS' s' := by + intro u hu + rcases F u hu with ⟨uo, -, -, k⟩ | ⟨-, k⟩ | ⟨-, k⟩ + · rw [k] + obtain ⟨a, b, c, d, f⟩ := h u uo + exact ⟨fun q b' x' y z w e => hH _ _ (a q b' x' y z w e), fun q b' x' y e => hH _ _ (b q b' x' y e), + fun q g e => hH _ _ (c q g e), fun q sz e => hH _ _ (d q sz e), f⟩ + · rw [k] + exact ⟨(fun _ _ _ _ _ _ e => by cases e), (fun _ _ _ _ e => by cases e), (fun _ _ e => by cases e), + (fun _ _ e => by cases e), (fun _ e => by cases e)⟩ + · rw [k] + exact ⟨(fun _ _ _ _ _ _ e => by cases e), (fun _ _ _ _ e => by cases e), (fun _ _ e => by cases e), + (fun _ _ e => by cases e), (fun _ e => by cases e)⟩ + +/-- The idle-SC anchor is off the parent's block, so off the new full untyped (same block). -/ +theorem poolRt_idleAnchorA (h : IdleAnchorOffA (st := st) OS s) (F : PoolSlotsA st OS OS' s s' x v frame base) + {fi : U64} (hx : x ∈ OS) (hc : capA st s x = .Untyped frame 12#u64 fi false) : + IdleAnchorOffA (st := st) OS' s' := by + intro u hu q b f d e + rcases F u hu with ⟨uo, -, -, k⟩ | ⟨-, k⟩ | ⟨-, k⟩ + · exact h u uo q b f d (k.symm.trans e) + · have g := k.symm.trans e + simp only [capability.Cap.Untyped.injEq] at g + obtain ⟨g1, g2, -, -⟩ := g + rw [← g1, ← g2] + exact h x hx frame 12#u64 fi false hc + · rw [k] at e; cases e + +/-- **No joint object meets an untyped's free part after MakePool.** The old joint objects are off the pool block +(`hold`, `hobj`: the dead drop of the childless parent); the new joint objects are the pool page itself. +`hoth`: another untyped is off the block or holds it below its watermark (A64 P1's `pool_utOther`). -/ +theorem poolRt_objAllocA {Z Z' : XSetsA} {H H' : Heap} (h : ObjAllocA (st := st) Z H OS s) + (F : PoolSlotsA st OS OS' s s' x v frame base) {fi : U64} (hx : x ∈ OS) + (hc : capA st s x = .Untyped frame 12#u64 fi false) + (hobj : ∀ q bytes, JointObjectA Z' H' q bytes → (JointObjectA Z H q bytes ∧ + (q.val + bytes ≤ frame.val ∨ frame.val + 4096 ≤ q.val)) ∨ (q = frame ∧ bytes = 4096)) + (hoth : ∀ u ∈ OS, u ≠ x → ∀ q b f d, capA st s u = .Untyped q b f d → + (frame.val + 4096 ≤ q.val ∨ q.val + 2 ^ b.val ≤ frame.val) ∨ + (q.val ≤ frame.val ∧ frame.val + 4096 ≤ q.val + f.val)) : + ObjAllocA (st := st) Z' H' OS' s' := by + intro o bytes ho u hu q b f d e + rcases F u hu with ⟨uo, uxe, -, k⟩ | ⟨ux, k⟩ | ⟨-, k⟩ + · have e0 := k.symm.trans e + rcases hobj o bytes ho with ⟨old, off⟩ | ⟨rfl, rfl⟩ + · exact h o bytes old u uo q b f d e0 + · rcases hoth u uo uxe q b f d e0 with (g | g) | g + · left; omega + · right; left; omega + · right; right; omega + · subst ux + have g := k.symm.trans e + simp only [capability.Cap.Untyped.injEq] at g + obtain ⟨g1, g2, g3, -⟩ := g + rw [← g1, ← g2, ← g3] + have h12 : (12#u64 : U64).val = 12 := rfl + have h4096 : (4096#u64 : U64).val = 4096 := rfl + rcases hobj o bytes ho with ⟨old, off⟩ | ⟨rfl, rfl⟩ + · rw [h12] + rcases off with g | g + · left; omega + · right; left; omega + · rw [h12, h4096] + right; right + omega + · rw [k] at e; cases e + +/-- **`DevUtOffA` after MakePool**: the device untypeds are the old ones; the pool page is off them because the +source untyped is a RAM one (`sep`). -/ +theorem poolRt_devUtOffA {Z Z' : XSetsA} {H H' : Heap} {ia ie : Nat} (h : DevUtOffA st Z H OS ia ie s) + (F : PoolSlotsA st OS OS' s s' x v frame base) {fi : U64} (hx : x ∈ OS) + (hc : capA st s x = .Untyped frame 12#u64 fi false) + (hobj : ∀ q bytes, JointObjectA Z' H' q bytes → JointObjectA Z H q bytes ∨ (q = frame ∧ bytes = 4096)) + (hks : ∀ lo hi, RegionOffNodes st Z.Cs s lo hi → RegionOffNodes st Z'.Cs s' lo hi) : + DevUtOffA st Z' H' OS' ia ie s' := by + have dv : ∀ u ∈ OS', ∀ q b f, capA st s' u = .Untyped q b f true → u ∈ OS ∧ capA st s u = .Untyped q b f true := by + intro u hu q b f e + rcases F u hu with ⟨uo, -, -, k⟩ | ⟨-, k⟩ | ⟨-, k⟩ + · exact ⟨uo, k.symm.trans e⟩ + · rw [k] at e + simp only [capability.Cap.Untyped.injEq] at e + exact absurd e.2.2.2 (by simp) + · rw [k] at e; cases e + refine ⟨fun u hu q b f e o bytes ho => ?_, fun u hu q b f e => ?_, fun u hu q b f e => ?_, + fun u hu q b f e w hw q' b' f' e' => ?_⟩ + · obtain ⟨uo, k⟩ := dv u hu q b f e + rcases hobj o bytes ho with g | ⟨e1, e2⟩ + · exact h.obj u uo q b f k o bytes g + · subst e2 + have e3 := congrArg UScalar.val e1 + have h12 : (12#u64 : U64).val = 12 := rfl + rcases h.sep u uo q b f k x hx frame 12#u64 fi hc with d | d + · left; rw [h12] at d; omega + · right; omega + · obtain ⟨uo, k⟩ := dv u hu q b f e + exact hks _ _ (h.ks u uo q b f k) + · obtain ⟨uo, k⟩ := dv u hu q b f e + exact h.idle u uo q b f k + · obtain ⟨uo, k⟩ := dv u hu q b f e + rcases F w hw with ⟨wo, -, -, kw⟩ | ⟨-, kw⟩ | ⟨-, kw⟩ + · exact h.sep u uo q b f k w wo q' b' f' (kw.symm.trans e') + · have g := kw.symm.trans e' + simp only [capability.Cap.Untyped.injEq] at g + rw [← g.1, ← g.2.1] + exact h.sep u uo q b f k x hx frame 12#u64 fi hc + · rw [kw] at e'; cases e' + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolCoreA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolCoreA.lean new file mode 100644 index 000000000..3beb73ce5 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolCoreA.lean @@ -0,0 +1,103 @@ +/- +P3 (aarch64, Stage 5, line pool, Step 1): **the shared context of the MakePool record lift**, `PoolCtxA`. + +The five bundles `Stage3Pool{Caps,Heap,Spec,Ipc,Sys}A` all run on the *dropped* record `Zd = dropZA D Z` (`D = utDA frame 12`), +the footprint `Expo.w1` from the post-restart state, and the grown record `Zn = { Zd with Pp := insert frame Zd.Pp, G := G' }` +at the grown view `m' = dropMA D m` (`McGrowA m m'`, `dropMA_growA`: no `dropMA D m = m` premise). `PoolCtxA` bundles +the facts every field-group module (`Stage3Pool{Shape,Mem,SysEnd,Rec}A`) reads from `makePool_perform_dropA`'s post, so a +group takes ONE context parameter (AGENTS.md "Proof records" rules 3 and 5; a new fact is a new field). + +* `PoolCtxA`: the context (all fields are facts of `makePool_perform_dropA`'s post or its decode-site hypotheses). +* `PoolCtxA.ofDrop`: builds it from that post's conjuncts (the assembly calls it inside `WP.spec_mono`). +* `PoolCtxA.grow`: `McGrowA m m'`. + +Named premises: the decode-site [W] holders `holdP`/`holdD` (the parent and destination slots are slots of a spec CNode, as +`Stage3ArmCnCopyA`). No other premise. New definitions only. +-/ +import Fl4ProofsA64.P3.UtMakePoolA +import Fl4ProofsA64.P3.McGrowUtA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4SpecA64 Classical + +noncomputable section + +section +variable {S : Type} (st : machine.Store S) [L : LawfulStore st] {A : Type} + +/-- **The MakePool lift's shared context** (module docstring). `Zd`/`Hd`/`OSd` are the dropped record's sets, `s`/`s5` +the states before the restart write and after the table write, `σ1` the spec state after the restart (dropped), `σ'` the spec +outcome, `Zn`/`m'` the grown record's sets and view, `m` the view before the drop. -/ +structure PoolCtxA (AR : A → HwRootA → Prop) (Zd : XSetsA) (Hd : Heap) (OSd : Set U64) (s s5 : S) (a : A) + (σ1 σ' : State Unit) (Zn : XSetsA) (m m' : McState) (parent dest : CslotPtr) (frame fi i base : U64) : Prop where + /-- the grown record is the dropped one with the pool added and the ghost chains replaced. -/ + zn : Zn = { Zd with Pp := insert frame Zd.Pp, G := Zn.G } + hm : m' = dropMA (utDA frame 12) m + /-- the FL4 footprint, slot caps and spec outcome shape. -/ + expo : MakePoolExpoA st Hd OSd s s5 σ1 σ' parent dest frame i base + /-- the core post at the grown record. -/ + jat : JAtZAX (L := L) AR Zn s5 a σ' m' + tree : TreeA st OSd Zn.G.chains Zn.G.par s5 + /-- (group J5, `Stage3PoolJ5A`) J5's MDB facts at the grown ghost. -/ + j5c : MdbInvA st Zn.G.chains Zn.G.par s5 ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Zn.G.chains s5 ∧ HandlersActiveA st Zn.G.chains s5 + /-- no dead joint object in the parent's used prefix (of the dropped record). -/ + dd : DeadDrop4KA Zd Hd frame fi + hcp : capA st s (cslotAddrA parent) = .Untyped frame 12#u64 fi false + hnc : cdt.ensure_no_children st s (cslotAddrA parent) = ok (core.result.Result.Ok ()) + hcd : capA st s (cslotAddrA dest) = .Null + hi : i.val < 128 + hfree : L.mem s (atAF (L.ksb s) i) = 0#u64 + hbase : base.val = i.val * 512 + absP : AbsSlotA Zd.th parent + absD : AbsSlotA Zd.th dest + /-- [W] the parent slot is a slot of a spec CNode (so `PoolStepA.kh` excludes TCB changes). -/ + holdP : ∃ pp, parent.1 = specPtr pp ∧ Zd.th pp = some (.cnode parent.2.length) + /-- [W] likewise the destination slot. -/ + holdD : ∃ pp, dest.1 = specPtr pp ∧ Zd.th pp = some (.cnode dest.2.length) + +variable {st} {AR : A → HwRootA → Prop} {Zd Zn : XSetsA} {Hd : Heap} {OSd : Set U64} {s s5 : S} {a : A} + {σ1 σ' : State Unit} {m m' : McState} {parent dest : CslotPtr} {frame fi i base : U64} + +/-- The grown view contains the old one (`McGrowA`, R1): replaces the old premise `dropMA D m = m`. -/ +theorem PoolCtxA.grow (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base) : + McGrowA m m' := C.hm ▸ dropMA_growA _ m + +/-- A CNode holder of an undropped slot is one of the dropped record, given the slot is abstract there. -/ +theorem poolHold_dropA {D : Set ObjRef} {th : TypedHeapA} {sl : CslotPtr} {pp : U64} (hsl : sl.1 = specPtr pp) + (hc : th pp = some (.cnode sl.2.length)) (hA : AbsSlotA (dropThA D th) sl) : + ∃ pp, sl.1 = specPtr pp ∧ dropThA D th pp = some (.cnode sl.2.length) := by + obtain ⟨q, e, h⟩ := hA + have eq : q = pp := specPtr_inj (e.symm.trans hsl) + subst eq + rcases h with h | ⟨h, -⟩ + · exact ⟨q, hsl, h⟩ + · have := (dropThA_someA.1 h).2 + rw [hc] at this + cases this + +/-- **The context from `makePool_perform_dropA`'s post** (its conjuncts, in order, with the decode-site holders on the +undropped typed heap `th`). -/ +theorem PoolCtxA.ofDrop {Z : XSetsA} (hZ : Zd = dropZA (utDA frame 12) Z) + (hn : Zn = { Zd with Pp := insert frame Zd.Pp, G := Zn.G }) (hm : m' = dropMA (utDA frame 12) m) + (expo : MakePoolExpoA st Hd OSd s s5 σ1 σ' parent dest frame i base) + (jat : JAtZAX (L := L) AR Zn s5 a σ' m') (tree : TreeA st OSd Zn.G.chains Zn.G.par s5) + (j5c : MdbInvA st Zn.G.chains Zn.G.par s5 ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Zn.G.chains s5 ∧ HandlersActiveA st Zn.G.chains s5) + (dd : DeadDrop4KA Zd Hd frame fi) + (hcp : capA st s (cslotAddrA parent) = .Untyped frame 12#u64 fi false) + (hnc : cdt.ensure_no_children st s (cslotAddrA parent) = ok (core.result.Result.Ok ())) + (hcd : capA st s (cslotAddrA dest) = .Null) (hi : i.val < 128) (hfree : L.mem s (atAF (L.ksb s) i) = 0#u64) + (hbase : base.val = i.val * 512) (absP : AbsSlotA Zd.th parent) (absD : AbsSlotA Zd.th dest) + {pp pd : U64} (hP : parent.1 = specPtr pp ∧ Z.th pp = some (.cnode parent.2.length)) + (hD : dest.1 = specPtr pd ∧ Z.th pd = some (.cnode dest.2.length)) : + PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base := by + subst hZ + exact { zn := hn, hm := hm, expo := expo, jat := jat, tree := tree, j5c := j5c, dd := dd, hcp := hcp, hnc := hnc, hcd := hcd, + hi := hi, hfree := hfree, hbase := hbase, absP := absP, absD := absD, + holdP := poolHold_dropA hP.1 hP.2 absP, holdD := poolHold_dropA hD.1 hD.2 absD } + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolEndA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolEndA.lean new file mode 100644 index 000000000..c9bc16d95 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolEndA.lean @@ -0,0 +1,201 @@ +/- +P3 (aarch64, Stage 5, line pool, item 6): **the P1 → `PoolJ7EndA` transformer** of the MakePool record lift. + +`poolJ7A` (`P3/Stage3PoolJ7A`) takes `Ee : ∀ Pt Ub, J7BodyA … Z0 H0 OS0 s0 σ0 m0 Pt Ub → PoolJ7EndA … Pt Ub`. This module +proves, for ONE pair of witnesses `Pt Ub`, the body `PoolJ7EndA … Pt Ub` from A64 P1's MakePool end facts at the undropped +decode state `s0` / heap `H0` (the success branch of `syscall.decode_invocation.makePoolEndR2` and `makePoolLIEAtX`): +the assembler builds `Ee := fun Pt Ub hb => poolEndA hb …`. + +* `PoolP1EndA`: that success branch's decode-level facts (`PoolPost`, the slot clause, `ArmQIEnd`) in P1's own form. +* `poolEndA`: the transformer. `col` := `S1aArmCol.poolEnd`, `pools` := `ArmQIEnd`, `dev` := `DevFrAl.poolEnd`, + `frub` := `CapInv.poolEnd` at `FrUbP` (trivial on `AsidPool`/`Untyped`), `asw` := `AsW.poolH`, `hi` := the new R2's + `highHeaders` (so `PoolPost.hiCap511` is not needed), `r2` := `makePoolEndR2`'s R2 / `S1aKtUt` with `S1aHiK` through + `S1aHiKeep.ofPool`. `vcc` is a hypothesis (`poolVcCapA` derives it from the dropped record). +* `poolP1FactsA`: the P1-side hypotheses of `poolSysEndA` (`hsys hsym hblk hpo hHE`, the table-word facts). + +P1 side change: `makePoolEndR2` now names the page-table witness of its new R2 (`insert p (s1aKeptPt …)`). +Named premises: none. +-/ +import Fl4ProofsA64.P3.Stage3PoolSysEndA +import Fl4ProofsA64.P1.S1aStepR2K + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4SpecA64 Classical + +local notation "wa" => core.num.U64.wrapping_add + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **MakePool's decode-level end facts** (`makePoolEndR2`'s success branch, P1's form; `p` is the pool page). -/ +structure PoolP1EndA (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs OS Vq : Set U64) (ia ie : Nat) + (s0 s5 : S) (x v p sb fi i base : U64) : Prop where + hx : x ∈ OS + src : capA st s0 x = .Untyped p sb fi false + size : sb = fl4_abi.consts.bits.ASID_POOL + nochild : cdt.ensure_no_children st s0 x = ok (core.result.Result.Ok ()) + post : PoolPost st H OS s0 s5 x v p sb i base + others : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st s5 y = capA st s0 y ∨ ∃ p' b' i' d', capA st s5 y = .Untyped p' b' i' d' + E : ArmQIEnd st H Cs OS Vq ia ie s0 (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val) + (OffR p.val (p.val + 2 ^ sb.val) OS) s5 + +theorem PoolP1EndA.h12 {H : Heap} {Cs OS Vq : Set U64} {ia ie : Nat} {s0 s5 : S} {x v p sb fi i base : U64} + (E : PoolP1EndA st H Cs OS Vq ia ie s0 s5 x v p sb fi i base) : sb.val = 12 := by + have := E.size + rw [this] + first | rfl | decide | simp [fl4_abi.consts.bits.ASID_POOL] + +/-- **The transformer** (module docstring): `PoolJ7EndA` at the witnesses `Pt Ub` of the old `J7A` body `hb`. +`hR2` is `makePoolEndR2`'s R2 / separation clause, for every R2 witness of `hb` (P1's form, over `2 ^ sb.val`). -/ +theorem poolEndA {Z0 Zn : XSetsA} {H0 Hd : Heap} {OS0 OS' Pt Ub : Set U64} {ia ie : Nat} {nA : U64} {s0 s5 : S} + {σ0 σ' : Fl4SpecA64.State Unit} {m0 m' : Fl4SpecA64.McState} {frame x v sb fi i base slot : U64} + {Rp Nt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hb : J7BodyA st (J7R2A st ar nA) Z0 H0 OS0 s0 σ0 m0 Pt Ub) + (P : SysPlace st H0 Z0.Cs H0.frame Rp Nt OS0 s0 extra slot) (B : SysL st H0 Z0.Cs OS0 ia ie s0) + (hks : HeapKsOff H0 (L.ksb s0)) + (E1 : PoolP1EndA st H0 Z0.Cs OS0 Z0.V ia ie s0 s5 x v frame sb fi i base) + (hHd : Hd = H0.drop (RegionD H0 frame.val (frame.val + 4096))) + (hOS' : OS' = OffR frame.val (frame.val + 4096) OS0) + (hvc : VcCap st Zn.V OS' s5) + (hR2 : ∀ Pp Tb Hr Te Kt Lv Re bits, S1aR2 st H0 OS0 Pt Pp Tb Hr Te Kt Lv Re bits nA s0 → + S1aKtUt st OS0 Kt s0 → ∃ Pp' Tb' Te' : Set U64, + S1aR2 st (PoolH (H0.drop (RegionD H0 frame.val (frame.val + 2 ^ sb.val))) frame sb.val) + (OffR frame.val (frame.val + 2 ^ sb.val) OS0) + (insert frame (s1aKeptPt (H0.drop (RegionD H0 frame.val (frame.val + 2 ^ sb.val))) Pt)) Pp' Tb' + (HvRt st (OffR frame.val (frame.val + 2 ^ sb.val) OS0) s5) Te' Kt Lv Re bits nA s5 ∧ + S1aKtUt st (OffR frame.val (frame.val + 2 ^ sb.val) OS0) Kt s5) : + PoolJ7EndA st ar nA Z0 Zn Hd frame OS' s5 σ' m' Pt Ub := by + have h12 := E1.h12 + have e4 : (2 : Nat) ^ sb.val = 4096 := by rw [h12]; norm_num + subst hHd hOS' + obtain ⟨vr, pools, C, Kc, -, Df, -, -, -, frub, hal, -, R⟩ := hb + obtain ⟨Pp, Tb, Hr, Te, Kt, Lv, Re, bits, R0, sep, KLv, ktab, hik⟩ := R + have col := S1aArmCol.poolEnd P B vr C Kc hal E1.hx E1.src E1.size E1.nochild E1.post E1.E + have hRin := B.sys.ur.rin E1.hx E1.src + have hks' := (B.sys.stz.2.2 x E1.hx frame sb fi E1.src).2 + have hfr : (H0.drop (RegionD H0 frame.val (frame.val + 2 ^ sb.val))) frame = none := by + cases e : (H0.drop (RegionD H0 frame.val (frame.val + 2 ^ sb.val))) frame with + | none => rfl + | some k => + obtain ⟨hD, hHp⟩ := Heap.drop_eq_some.1 e + exfalso + apply hD + have := @Nat.one_le_two_pow k.bits + have := @Nat.one_le_two_pow sb.val + simp only [RegionD, hHp, Option.elim, MeetsR] + omega + have hAs := AsW.poolH hRin hks' B.ly.ksw hfr (fun b hb => + ⟨vr.om b (Or.inr hb), vr.sg b (Or.inr hb), vr.os b (Or.inr hb)⟩) + have frub' := CapInv.poolEnd E1.post E1.others (Q := FrUbP Ub) + (fun _ _ _ _ _ _ _ _ h => by cases h) (fun _ _ _ _ _ _ _ _ _ _ _ h => by cases h) frub + have dev := DevFrAl.poolEnd E1.post E1.others Df + have ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b := hks.ptAsWG R0.footprint B.ly.ksw (R0.footprint.fit P.heap) + have keep := S1aHiKeep.ofPool (Kt := Kt) R0 vr ptKs E1.post E1.others + obtain ⟨Pp', Tb', Te', R', sep'⟩ := hR2 Pp Tb Hr Te Kt Lv Re bits R0 sep + have pn := E1.E.2.2.2.2.2.1 pools + rw [e4] at R' sep' col hAs frub' dev keep pn + rw [h12] at R' col hAs + refine + { col := col + pools := pn + vcc := hvc + asw := fun b hb => ?_ + dev := dev + hi := R'.highHeaders + frub := frub' + r2 := ⟨Pp', Tb', HvRt st _ s5, Te', Kt, Lv, Re, bits, R', sep', KLv, ktab, ?_⟩ } + · rw [E1.post.ksb] at hb + have := hAs b hb + exact ⟨this.1, this.2.1⟩ + · exact S1aHiK.keep hik keep + +/-- **The P1-side hypotheses of `poolSysEndA`** (module docstring), over the pool heap `PoolH Hd frame 12` and the slots +`OS'`; the ASID-table entry is `AtOff i`. -/ +structure PoolEndFactsA (st : machine.Store S) [L : LawfulStore st] (Cs OS' : Set U64) (Hd : Heap) (frame : U64) + (ia ie : Nat) (s0 s5 : S) (i : U64) : Prop where + hsys : SysL st (PoolH Hd frame 12) Cs OS' ia ie s5 + hsym : SymL st (PoolH Hd frame 12) Cs s5 + hblk : ∃ Ac', BlkOK st (PoolH Hd frame 12).tcbs Cs (PoolH Hd frame 12).omega (PoolH Hd frame 12) + (PoolH Hd frame 12).frame (PoolH Hd frame 12).replies (PoolH Hd frame 12).scs (PoolH Hd frame 12).ntfns + (PoolH Hd frame 12).scBits Ac' s5 + hpo : PoolOff st (PoolH Hd frame 12) Cs OS' s5 + hHE : HeapOK (PoolH Hd frame 12) + hoi : 772352 ≤ (AtOff i).val ∧ (AtOff i).val < 773376 ∧ (AtOff i).val % 8 = 0 + htab : L.mem s5 (wa (L.ksb s5) (AtOff i)) = frame + hfz : frame ≠ 0#u64 + hother : ∀ o : U64, 772352 ≤ o.val → o.val < 773376 → o.val % 8 = 0 → o ≠ AtOff i → + L.mem s5 (wa (L.ksb s0) o) = L.mem s0 (wa (L.ksb s0) o) + hz : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s5 (wa frame o) = 0#u64 + +/-- **MakePool's end facts for `poolSysEndA`** from P1's decode facts `E1` and the old column's `PoolOff` +(`po`: `S1aArmCol.case.po`). -/ +theorem poolEndFactsA {Cs OS0 OS' : Set U64} {H0 Hd : Heap} {ia ie : Nat} {s0 s5 : S} {frame x v sb fi i base : U64} + {Vq : Set U64} (B : SysL st H0 Cs OS0 ia ie s0) (po : PoolOff st H0 Cs OS0 s0) + (E1 : PoolP1EndA st H0 Cs OS0 Vq ia ie s0 s5 x v frame sb fi i base) + (hHd : Hd = H0.drop (RegionD H0 frame.val (frame.val + 4096))) + (hOS' : OS' = OffR frame.val (frame.val + 4096) OS0) : + PoolEndFactsA st Cs OS' Hd frame ia ie s0 s5 i := by + have h12 := E1.h12 + have e4 : (2 : Nat) ^ sb.val = 4096 := by rw [h12]; norm_num + have post := E1.post + have hE := E1.E + have hpool : PoolOff st (PoolH (H0.drop (RegionD H0 frame.val (frame.val + 2 ^ sb.val))) frame sb.val) + Cs (OffR frame.val (frame.val + 2 ^ sb.val) OS0) s5 := hE.2.2.2.2.1 po + have hheap := post.heap + have hs : SysL st (PoolH (H0.drop (RegionD H0 frame.val (frame.val + 2 ^ sb.val))) frame sb.val) Cs + (OffR frame.val (frame.val + 2 ^ sb.val) OS0) ia ie s5 := hE.1 + have hy := hE.2.1 + have hk := hE.2.2.1 + rw [e4, h12] at hpool hheap hs hy hk + subst hHd hOS' + have hpos : 0 < frame.val := B.ly.ut0 x E1.hx frame sb fi E1.src + refine ⟨hs, hy, hk, hpool, hheap, AtOff.v i, ?_, fun h => by rw [h] at hpos; exact absurd hpos (by decide), ?_, ?_⟩ + · rw [post.ksb]; exact post.tabI + · intro o h1 h2 h8 hne + obtain ⟨j, rfl⟩ := atOff_of_off h1 h2 h8 + exact post.tab j hne + · intro o ho h8 + have align := post.heap.align frame (.other sb.val) (Heap.add_eq_some.2 (Or.inl ⟨rfl, rfl⟩)) + have fit := post.heap.fits frame (.other sb.val) (Heap.add_eq_some.2 (Or.inl ⟨rfl, rfl⟩)) + change frame.val % 2 ^ sb.val = 0 at align + change frame.val + 2 ^ sb.val ≤ 2 ^ 64 at fit + rw [e4] at align fit + have value : (wa frame o).val = frame.val + o.val := wadd_val (by omega) + exact post.zr _ (by unfold Aligned; rw [value]; omega) (by rw [value]; omega) (by rw [value, e4]; omega) + +/-- **`PtZ` for the pool's footprint**: every placed page-table word of the reachable VSpace pages is kept or zeroed +(`PoolPost.vs`; `ptKs`: none of them is an ASID-table word, `HeapKsOff.ptAsWG`). -/ +theorem poolPtZA {H0 : Heap} {Cs OS0 Vc Ub Pt : Set U64} {ia ie : Nat} {s0 s5 : S} {frame x v sb fi i base : U64} + {Vq : Set U64} (vr : VrOK H0.omega H0.frame H0.scs H0.scBits OS0 Vc Ub (L.ksb s0) Pt) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) + (E1 : PoolP1EndA st H0 Cs OS0 Vq ia ie s0 s5 x v frame sb fi i base) : PtZ st Pt s0 s5 := by + intro b hb + rcases E1.post.vs Vc Ub Pt vr b (Or.inl hb) with kept | ⟨lo, hi⟩ | table + · exact Or.inl kept + · exact Or.inr (E1.post.zr b (vr.al b (Or.inl hb)) lo hi) + · exact (ptKs b hb (by rw [table]; exact asW_at (L.ksb s0) i)).elim + +/-- **`VcCap` after the perform tail** at any vcpu set the dropped record satisfies: the parent slot becomes `Untyped`, +the destination `AsidPool`, every other slot of `OSd` keeps its cap (`MakePoolExpoA.capP/capD/capK`). -/ +theorem poolVcCapA {V OSd OS' : Set U64} {s s5 : S} {pA dA frame fi base : U64} (h0 : VcCap st V OSd s) + (hsub : OS' ⊆ OSd) (capP : capA st s5 pA = .Untyped frame 12#u64 fi false) + (capD : capA st s5 dA = .AsidPool frame base) + (capK : ∀ y ∈ OSd, y ≠ pA → y ≠ dA → capA st s5 y = capA st s y) : VcCap st V OS' s5 := by + intro y hy + by_cases a : y = pA + · rw [a, capP]; exact VcCapP.ut _ _ _ _ _ + by_cases b : y = dA + · rw [b, capD]; exact fun v h => by cases h + rw [capK y (hsub hy) a b] + exact h0 y (hsub hy) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolFinA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolFinA.lean new file mode 100644 index 000000000..18629e233 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolFinA.lean @@ -0,0 +1,199 @@ +/- +P3 (aarch64, Stage 5, line pool): **the `PoolEndA` hypothesis discharged** from A64 P1's `makePoolEndR2` and the pool-End +line (`Stage3PoolEndA`). + +* `poolHgrowA`: the reachable VSpace set after MakePool is the old one plus the pool page (`bufVs`'s input). +* **`poolFinA`**: `PoolEndA` (but `j5`) from the entry record `J`, the dropped record `Jd`, the perform's context `C`, the + label-58 decode run `hrun = ok (Ok, s5, a)` and its entry facts (`D0`, `P0`, `hSC`): `makePoolEndR2` is applied per R2 + witness of the old `J7A`, its success branch is identified with the run's pool (`p = frame`, the table entry) and fed to + `poolEndA`, `poolEndFactsA`, `poolPtZA`, `poolVcCapA`. + +Named premises: `j5` (`Stage3PoolJ5A`, not landed). New module. +-/ +import Fl4ProofsA64.P3.Stage3PoolTopA +import Fl4ProofsA64.P3.Stage3PoolEndA +import Fl4ProofsA64.P3.UtVsOkJA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4SpecA64 Classical + +local notation "wa" => core.num.U64.wrapping_add + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} {nA : U64} +variable {AR : A → HwRootA → Prop} + +/-- **The reachable VSpace words grow by the pool page only** (`poolVsTyR`'s reachability, as a set). -/ +theorem poolHgrowA {Pp Tb : Set U64} {Lv : U64 → Nat} {s s5 : S} {frame oi : U64} + (h : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ Tb Lv s) (ksb : L.ksb s5 = L.ksb s) + (vsz : PtZ st (utVsPtA st Pp Tb Lv s) s s5) + (htab : L.mem s5 (wa (L.ksb s) oi) = frame) + (hother : ∀ o : U64, 772352 ≤ o.val → o.val < 773376 → o.val % 8 = 0 → o ≠ oi → + L.mem s5 (wa (L.ksb s) o) = L.mem s (wa (L.ksb s) o)) + (hz : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s5 (wa frame o) = 0#u64) : + utVsPtA st (insert frame Pp) Tb Lv s5 ⊆ utVsPtA st Pp Tb Lv s ∪ {frame} := by + have toOld : ∀ p, p ∈ PoolSet st (insert frame Pp) s5 → p ≠ frame → p ∈ PoolSet st Pp s := by + intro p hp hne + obtain ⟨a, o, b, c, d, e, f⟩ := hp + rw [ksb] at e + have hoo : o ≠ oi := fun eq => by + rw [eq, htab] at e + exact hne e.symm + exact ⟨a.resolve_left hne, o, b, c, d, by rw [← hother o b c d hoo]; exact e, f⟩ + have h' : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ (VsRt st (PoolSet st Pp s) ∅ Tb Lv s) Lv s := + h.sub.toRsub (Set.Subset.refl _) (Set.empty_subset _) + have reach : ∀ t, VsReach st (PoolSet st (insert frame Pp) s5) ∅ Lv s5 t → + VsReach st (PoolSet st Pp s) ∅ Lv s t := by + intro t hr + have sub : PoolSet st (insert frame Pp) s5 ⊆ insert frame (PoolSet st Pp s) := fun p hp => by + by_cases e : p = frame + · exact Or.inl e + · exact Or.inr (toOld p hp e) + have r2 : VsReach st (PoolSet st Pp s) ∅ Lv s5 t := (VsReach.zeroPool hz).1 (hr.poolMono sub) + exact VsReach.ptz (Pt := utVsPtA st Pp Tb Lv s) (fun p hp => Or.inl hp) (fun p hp => Or.inr hp) + (Set.empty_subset _) h' vsz r2 + rintro q (hq | ⟨hqT, hr⟩) + · by_cases e : q = frame + · exact Or.inr e + · exact Or.inl (Or.inl (toOld q hq e)) + · exact Or.inl (Or.inr ⟨hqT, reach q hr⟩) + +set_option maxHeartbeats 8000000 in +/-- **`PoolEndA` from A64 P1** (module docstring). -/ +theorem poolFinA {Z Zn : XSetsA} {H0 : Heap} {OS0 U Ac Pp0 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 s5 : S} {a : A} {σ σ1 σ' : State Unit} {m m' : McState} {parent dest : CslotPtr} {frame fi i base : U64} + (J : JStage3A st AR Z H0 OS0 U Ac Pp0 Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (Jd : JStage3A st AR (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H0) (dropSetA (utDA frame 12) OS0) U Ac + (dropSetA (utDA frame 12) Pp0) Tb Lv ia ie (dropSetA (utDA frame 12) N) (dropSetA (utDA frame 12) E) + (dropSetA (utDA frame 12) Rp) (dropBfA (utDA frame 12) Bf) stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a + (detype (utDA frame 12) σ) m') + (C : PoolCtxA st AR (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H0) (dropSetA (utDA frame 12) OS0) s s5 a σ1 + σ' Zn m m' parent dest frame fi i base) + (RS : RsSiteA (L := L) Z H0 OS0 Ac Pp0 Tb Lv s) + {Ud Acd : Set U64} {ex : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (D0 : DecPre st H0.tcbs Z.Cs H0.omega H0 H0.frame H0.replies H0.scs H0.ntfns H0.scBits Ud Acd s .AsidControl ex) + (P0 : SysPlace st H0 Z.Cs H0.frame H0.replies H0.ntfns OS0 s ex slot) + (hSC : ∀ x ∈ ex.val, x ≠ 0#u64 → SlotCov st OS0 s x) + {length buf : U64} {block call cd fp : Bool} + (hrun : syscall.decode_invocation st ar s a fl4_abi.label.ARMASIDControlMakePool length slot .AsidControl + block call cd fp buf ex = ok (core.result.Result.Ok (), s5, a)) + (hs1 : m' = dropMA (utDA frame 12) m) : + PoolEndA st ar nA Z (dropZA (utDA frame 12) Z) Zn H0 (dropHA (utDA frame 12) H0) OS0 + (dropSetA (utDA frame 12) OS0) (dropSetA (utDA frame 12) Pp0) Tb Lv ia ie s + (L.wr s (stA (L.curW s)) sched.TS_RESTART) s5 σ σ' m m' frame i := by + have e12 : (12#u64 : U64).val = 12 := rfl + have hxO : cslotAddrA parent ∈ dropSetA (utDA frame 12) OS0 := Jd.j5.2.1 _ (C.absP.isSlot Jd.j.1.place) + have off := poolHeap_offA Jd.objAlloc C hxO + have hwin := Jd.utWin (cslotAddrA parent) hxO frame 12#u64 fi C.hcp + have hbase : layout.PPTR_BASE.val = 18446603336221196288 := by unfold layout.PPTR_BASE; rfl + rw [hbase, e12] at hwin + have hp : frame.val + 2 ^ 12 ≤ 2 ^ 64 := by omega + have hsp : (specPtr frame).toNat + 2 ^ 12 ≤ 2 ^ 64 := by rw [specPtr_toNat]; omega + have hfz : frame ≠ 0#u64 := fun e => by + have h0 : frame.val = 0 := by rw [e]; rfl + omega + obtain ⟨hpal, -, -⟩ := Jd.sys.sysl.sys.ur.utv Jd.sys.sysl.sys.stz.1.1 hxO C.hcp + rw [e12] at hpal + have hf8 : frame.val % 8 = 0 := by omega + have hHd := poolDrop_regionA hp hsp off + have hOS := (poolOS_eqA hp hsp hf8 Jd.sys.ent.heap Jd.sys.ent.os off).symm + have ksb5 : L.ksb s5 = L.ksb s := C.expo.w.1 + have htab : L.mem s5 (wa (L.ksb s) (AtOff i)) = frame := by rw [poolAtOffA C.hi]; exact C.expo.tab + have hfree' : L.mem s (wa (L.ksb s) (AtOff i)) = 0#u64 := by rw [poolAtOffA C.hi]; exact C.hfree + have hks1 : L.ksb (L.wr s (stA (L.curW s)) sched.TS_RESTART) = L.ksb s := L.ksb_wr _ _ _ + have B := J.sys.sysl + -- A64 P1's success branch of the run, for one R2 witness, identified with the run's pool + have post : ∀ (Pt Ub : Set U64) (hb : J7BodyA st (J7R2A st ar nA) Z H0 OS0 s σ m Pt Ub), + ∀ (Pp Tb' Hr Te Kt : Set U64) (Lv' Re bits : U64 → Nat), S1aR2 st H0 OS0 Pt Pp Tb' Hr Te Kt Lv' Re bits nA s → + S1aKtUt st OS0 Kt s → ∃ (x v fi1 i1 base1 : U64) (Pp' Tb'' Te' : Set U64), + PoolP1EndA st H0 Z.Cs OS0 Z.V ia ie s s5 x v frame fl4_abi.consts.bits.ASID_POOL fi1 i1 base1 ∧ + AtOff i1 = AtOff i ∧ + S1aR2 st (PoolH (H0.drop (RegionD H0 frame.val (frame.val + 2 ^ fl4_abi.consts.bits.ASID_POOL.val))) + frame fl4_abi.consts.bits.ASID_POOL.val) + (OffR frame.val (frame.val + 2 ^ fl4_abi.consts.bits.ASID_POOL.val) OS0) + (insert frame (s1aKeptPt (H0.drop (RegionD H0 frame.val (frame.val + 2 ^ fl4_abi.consts.bits.ASID_POOL.val))) Pt)) + Pp' Tb'' (HvRt st (OffR frame.val (frame.val + 2 ^ fl4_abi.consts.bits.ASID_POOL.val) OS0) s5) Te' Kt Lv' Re + bits nA s5 ∧ + S1aKtUt st (OffR frame.val (frame.val + 2 ^ fl4_abi.consts.bits.ASID_POOL.val) OS0) Kt s5 := by + intro Pt Ub hb Pp Tb' Hr Te Kt Lv' Re bits R sep + have P1 := syscall.decode_invocation.makePoolEndR2 (ar := ar) D0 P0 B J.symL hb.1 hSC J.ko R sep a rfl length + block call cd fp buf + rw [hrun] at P1 + have P1' := (WP.spec_ok _).1 P1 + rcases P1' with ⟨hq, -⟩ | ⟨x, v, p, sb, fi1, i1, base1, Pp', Tb'', Te', hx, src, size, nochild, pp, others, E, R2', sep'⟩ + · exfalso + rw [hq] at htab + rw [htab] at hfree' + exact hfz hfree' + · have hAt : AtOff i1 = AtOff i := by + by_contra hne + have := pp.tab i (Ne.symm hne) + rw [htab, hfree'] at this + exact hfz this + have hp1 : p = frame := by + have := pp.tabI + rw [hAt, htab] at this + exact this.symm + subst hp1 + subst size + exact ⟨x, v, fi1, i1, base1, Pp', Tb'', Te', + { hx := hx, src := src, size := rfl, nochild := nochild, post := pp, others := others, E := E }, hAt, R2', sep'⟩ + have wit : ∀ (Pt Ub : Set U64) (hb : J7BodyA st (J7R2A st ar nA) Z H0 OS0 s σ m Pt Ub), + ∃ (Pp Tb' Hr Te Kt : Set U64) (Lv' Re bits : U64 → Nat), S1aR2 st H0 OS0 Pt Pp Tb' Hr Te Kt Lv' Re bits nA s ∧ + S1aKtUt st OS0 Kt s := fun Pt Ub hb => by + obtain ⟨Pp, Tb', Hr, Te, Kt, Lv', Re, bits, R, sep, -⟩ := hb.2.2.2.2.2.2.2.2.2.2.2.2 + exact ⟨Pp, Tb', Hr, Te, Kt, Lv', Re, bits, R, sep⟩ + obtain ⟨Pt0, Ub0, hb0⟩ := J.j7 + obtain ⟨Pp1, Tb1, Hr1, Te1, Kt1, Lv1, Re1, bits1, R0, sep0⟩ := wit Pt0 Ub0 hb0 + obtain ⟨x0, v0, fi0, i0, base0, -, -, -, E1, hAt, R2z, sz⟩ := post Pt0 Ub0 hb0 Pp1 Tb1 Hr1 Te1 Kt1 Lv1 Re1 bits1 R0 sep0 + have facts := poolEndFactsA (OS' := dropSetA (utDA frame 12) OS0) B J.poolOff E1 hHd hOS + have hvc : VcCap st Zn.V (dropSetA (utDA frame 12) OS0) s5 := by + obtain ⟨-, -, -, -, -, -, vcd, -⟩ := Jd.j7 + rw [C.eV] + exact poolVcCapA vcd Set.Subset.rfl C.expo.capP C.expo.capD C.expo.capK + have hother : ∀ o : U64, 772352 ≤ o.val → o.val < 773376 → o.val % 8 = 0 → o ≠ AtOff i → + L.mem s5 (wa (L.ksb s) o) = L.mem s (wa (L.ksb s) o) := fun o h1 h2 h8 hne => + facts.hother o h1 h2 h8 (fun e => hne (e.trans hAt)) + have vsz : PtZ st (utVsPtA st (dropSetA (utDA frame 12) Pp0) Tb Lv s) s s5 := by + have ptKs : ∀ b, PtW Pt0 b → ¬ AsW (L.ksb s) b := J.ko.ptAsWG R0.footprint B.ly.ksw (R0.footprint.fit J.sys.ent.heap) + have z := poolPtZA hb0.1 ptKs E1 + exact fun b hb => z b (ptw_mono (utVsPt_subR2A R0 Jd.sys.ent.vs) hb) + have hz := poolZeroWordsA C.expo.pool + have hgrow : utVsPtA st (insert frame (dropSetA (utDA frame 12) Pp0)) Tb Lv s5 ⊆ + utVsPtA st (dropSetA (utDA frame 12) Pp0) Tb Lv (L.wr s (stA (L.curW s)) sched.TS_RESTART) ∪ {frame} := by + have g := poolHgrowA Jd.sys.ent.vs ksb5 vsz htab hother hz + have sA : Aligned (stA (L.curW s)) := by + rw [stA_eq]; exact field_aligned (J.toJEntA.sq.tcbs _ J.toJEntA.sq.curT) (by simp) (by simp) + have k : ∀ b, VsR (L.ksb s) (utVsPtA st (dropSetA (utDA frame 12) Pp0) Tb Lv s) b → + L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART) b = L.mem s b := fun b hb => by + obtain ⟨al, ne⟩ := RS.vs b (hb.imp (ptw_mono (utVsPtA_monoA (st := st) (Tb := Tb) (Lv := Lv) (s := s) + (show dropSetA (utDA frame 12) Pp0 ⊆ Pp0 from fun _ h => h.1))) id) + exact L.mem_wr_ne sA al (fun e => ne (UScalar.eq_of_val_eq e).symm) + rw [(utVsPt_keepA Jd.sys.ent.vs hks1 k).2] + exact g + exact + { Ee := fun Pt Ub hb => by + obtain ⟨Pp2, Tb2, Hr2, Te2, Kt2, Lv2, Re2, bits2, R2, sep2⟩ := wit Pt Ub hb + obtain ⟨x, v, fi, i2, base, -, -, -, E2, -, -, -⟩ := post Pt Ub hb Pp2 Tb2 Hr2 Te2 Kt2 Lv2 Re2 bits2 R2 sep2 + exact poolEndA hb P0 B J.ko E2 hHd hOS hvc fun Pp Tb' Hr Te Kt Lv' Re bits R sep => by + obtain ⟨x', v', fi', i', base', Pp', Tb'', Te', -, -, R2', sep'⟩ := post Pt Ub hb Pp Tb' Hr Te Kt Lv' Re bits R sep + exact ⟨Pp', Tb'', Te', R2', sep'⟩ + hHE := facts.hHE + hsys := facts.hsys + hsym := facts.hsym + hblk := facts.hblk + hpo := facts.hpo + hother := hother + vsz := vsz + hgrow := hgrow } + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolHeapA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolHeapA.lean new file mode 100644 index 000000000..91434c43b --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolHeapA.lean @@ -0,0 +1,630 @@ +/- +P3 (aarch64, Stage 4, line vsx-D, CP D1): **the table and heap fields of the record after the pool is made**, the +pool twin of `P3/UtAsmHeapA` (`unmPt`, `tabS1`, `tabExt`, `vsVc`, `ptH`, `setsInH`, `bufOff`, `deadExt`, `utIpc`, +`scSize`, `frBase`, `devFr`, `thPos`). + +The step is the pool's materialisation: the parent untyped is rewritten and the block `[frame, frame + 4096)` is +cleared; the typed heap gains the `other 12` object at `frame` and the relation's pools gain `frame`. The record before +it is the one after the childless parent's block was dropped (nothing of `H` or the spec heap is in the block). + +* `poolHeapA_*`: the cap/heap/footprint facts. +* `PoolAsmHeapInA`: what the step supplies. +* **`poolRt_asmHeapA`**: the fields. +* `poolFrOffA`: the frame-cap premise `frOff` from `ensure_no_children` on the parent. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.UtAsmHeapA +import Fl4ProofsA64.P3.Stage3PoolCapsA +import Fl4ProofsA64.P3.UtApHeap2A +import Fl4ProofsA64.P3.Stage3PoolJ5A + +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 + +local notation "wa" => core.num.U64.wrapping_add + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] + +/-- **`frOff` from the childless parent**: no frame cap of `OS` meets the block of an untyped without children +(the frame-cap twin of `keyDisjoint_of_childlessA`). -/ +theorem poolFrOffA {T Ω Sg OS : Set U64} {G : MdbGhostA} {s : S} + (hO : OSOK T Ω Sg OS) (hTr : TreeA st OS G.chains G.par s) (hRev : UtRev st OS s) + {u q b i : U64} {d : Bool} (hu : u ∈ OS) (hc : capA st s u = .Untyped q b i d) + (he : cdt.ensure_no_children st s u = ok (core.result.Result.Ok ())) : + ∀ y ∈ OS, ∀ p sz r dv a1 a2 a3 a4 bits, capA st s y = .Frame p sz r dv a1 a2 a3 a4 → sz.bits = ok bits → + p.val + 2 ^ bits.val ≤ q.val ∨ q.val + 2 ^ b.val ≤ p.val := by + intro y hy p sz r dv a1 a2 a3 a4 bits hcy hbits + have huy : y ≠ u := fun e => by + rw [e, hc] at hcy + cases hcy + have hphys : physA (capA st s y) = true := by rw [hcy]; exact physA_of rfl + have hut : isUtA (capA st s u) = true := by rw [hc]; rfl + have hnd := cdt.ensure_no_children.noDesc hO hTr hu hc (hRev u hu hut) he + have hdisj : DisjA (capA st s y) (capA st s u) := by + by_contra hn + rcases hTr.ut.drange u hu q b i d hc y hy huy hphys hn with hd | hd + · exact hnd y hd + · have bad := hTr.ut.anc y u hd hut + rw [hcy] at bad + cases bad + have hreg := hTr.ut.reg u hu (by rw [hc]; exact physA_ut _ _ _ _) + rw [hc] at hreg + obtain ⟨hbase, htop, hfit⟩ := ut_rangeA (capA_ut_b hc) hreg + have hregy := hTr.ut.reg y hy hphys + have eb : baseA (capA st s y) = p.val := by + unfold baseA + rw [hcy, ptrA_of (c := .Frame p sz r dv a1 a2 a3 a4) (v := p) rfl] + have es : sizeA (capA st s y) = bits := by + rw [hcy] + exact sizeA_of (by simpa [objects.cap_size_bits] using hbits) + have b64 : bits.val < 64 := by + rw [frameBitsE] at hbits + obtain rfl := okinj hbits + cases sz <;> decide + have et : topA (capA st s y) = (p.val + (2 ^ bits.val - 1)) % 2 ^ 64 := by + unfold topA + rw [es, hcy, ptrA_of (c := .Frame p sz r dv a1 a2 a3 a4) (v := p) rfl, wa_val, mskA_val b64] + have h1 : 1 ≤ 2 ^ bits.val := Nat.one_le_two_pow + have hp : 2 ^ bits.val < 2 ^ 64 := Nat.pow_lt_pow_right (by decide) b64 + have fit : p.val + 2 ^ bits.val ≤ 2 ^ 64 := by + rw [eb, et] at hregy + have := p.hBounds + by_contra hn + rw [Nat.mod_eq_sub_mod (by omega), Nat.mod_eq_of_lt (by simp at *; omega)] at hregy + omega + have etop : topA (capA st s y) = p.val + 2 ^ bits.val - 1 := by + rw [et, Nat.mod_eq_of_lt (by omega)] + omega + have h2 : 1 ≤ 2 ^ b.val := Nat.one_le_two_pow + unfold DisjA at hdisj + rw [eb, etop, hc, hbase, htop] at hdisj + omega + +end + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {OS 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 : JSlotA S} {ar : machine.Arch A} {nA : U64} {s s' : S} {a : A} {σ σ' : State Unit} + {m : McState} {G' : MdbGhostA} {x v frame base fi i : U64} + +/-- A word of the pool's new table words lies in the block. -/ +theorem poolHeapA_peIn {frame lo : U64} (fit : frame.val + 4096 ≤ 2 ^ 64) (h : lo.val < 512) : + frame.val ≤ (peAF frame lo).val ∧ (peAF frame lo).val < frame.val + 4096 := by + rw [peAF_valA fit h]; omega + +/-- A word of an `omega` heap object is no TCB's low word. -/ +theorem poolHeapA_tlow {H : Heap} (hH : HeapOK H) {b : U64} (h : b ∈ H.omega) {t k : U64} (ht : t ∈ H.tcbs) + (hk : k.val < 4096) (e : b = wa t k) : False := by + obtain ⟨-, q, kd, hq, kind, g1, g2⟩ := h + have f := hH.fits t _ ht + simp only [HKind.bits] at f + have ev : b.val = t.val + k.val := by + rw [e, wa_valP] + exact Nat.mod_eq_of_lt (by omega) + have ne : q ≠ t := fun e' => by + rw [e', show H t = some .tcb from ht] at hq + have ek := (Option.some.inj hq).symm + rw [ek] at kind + rcases kind with g | ⟨_, g⟩ | ⟨_, g⟩ | ⟨g, -⟩ <;> cases g + have d := hH.disj q kd t .tcb hq ht ne + rw [show HKind.tcb.bits = 12 from rfl] at d + omega + +/-- The footprint after the step: the old one and the pool's words. -/ +theorem poolRt_footSplitA {S : Type} {st : machine.Store S} [L : LawfulStore st] {Z : XSetsA} {G' : MdbGhostA} {s s' : S} {frame w : U64} + (hks : L.ksb s' = L.ksb s) (hcpu : L.cpu s' = L.cpu s) + (h : FootA (L := L) { Z with Pp := insert frame Z.Pp, G := G' } s' w) : + FootA (L := L) Z s w ∨ ∃ lo : U64, lo.val < 512 ∧ w = peAF frame lo := by + have na : ∀ c o, L.nodeAt s' c o = L.nodeAt s c o := fun c o => nodeAt_ksb hks c o + cases h with + | slot y w hy hw => exact Or.inl (.slot y w hy hw) + | nslot w h => + have O : FootNA (L := L) Z s w → + FootA (L := L) Z s w ∨ ∃ lo : U64, lo.val < 512 ∧ w = peAF frame lo := + fun k => Or.inl (.nslot w k) + cases h with + | node c w hc hw => + simp only [na] at hw + exact O (.node c w hc hw) + | cur w hw => + simp only [na, hcpu] at hw + exact O (.cur w hw) + | tcb t w ht hw => exact O (.tcb t w ht hw) + | sc c hc => exact O (.sc c hc) + | vcpu y w hy hw => exact O (.vcpu y w hy hw) + | irq i hi => + rw [hks] + exact Or.inl (.nslot _ (.irq i hi)) + | cur2 w hw => + simp only [na, hcpu] at hw + exact O (.cur2 w hw) + | glob w hw => + rw [hks] at hw + exact O (.glob w hw) + | tcb2 t w ht hw => exact O (.tcb2 t w ht hw) + | sc2 c hc => exact O (.sc2 c hc) + | vs w hw => + rw [hks] at hw + cases hw with + | asid hi h => exact O (.vs _ (.asid hi h)) + | pool p lo hp h => + rcases hp with rfl | hp + · exact Or.inr ⟨lo, h, rfl⟩ + · exact O (.vs _ (.pool p lo hp h)) + | pt p i hp h => exact O (.vs _ (.pt p i hp h)) + | high y i hy h => exact O (.vs _ (.high y i hy h)) + | ext w hw => exact O (.ext w hw) + +/-- A related spec object after the step: an old one, or the pool's. -/ +theorem poolRt_relSplitA {Z : XSetsA} {G' : MdbGhostA} {m : McState} {frame : U64} {r : ObjRef} + (h : RelPA { Z with Pp := insert frame Z.Pp, G := G' } m r) : + RelPA Z m r ∨ r = specPtr frame := by + unfold RelPA at h ⊢ + rcases h with h | h | h | h | h | h | ⟨q, (rfl | hq), e⟩ | h | h + · 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.inr e.symm + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨q, hq, e⟩))))))) + · exact Or.inl (Or.inr (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.inr h)))))))) + +/-- **What MakePool's perform supplies** to the table and heap fields (one step from the dropped record to the post +state: the footprint is `MakePoolExpoA.w`). -/ +structure PoolAsmHeapInA (st : machine.Store S) [L : LawfulStore st] (Z : XSetsA) (H : Heap) (OS OS' : Set U64) + (Bf : Set (U64 × Fl4SpecA64.Word)) (s s' : S) (σ σ' : State Unit) (x v frame base fi i : U64) : Prop where + /-- the dropped record: no heap object meets the pool block. -/ + off : ∀ q k, H q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val + /-- the footprint: slot words, TCB low words, the cleared block, the caller's state and the table word. -/ + w : WritesIn st s s' (fun b => W7.CapW H.tcbs {b | InOS OS b} ∅ b ∨ + (frame.val ≤ b.val ∧ b.val < frame.val + 4096) ∨ b = stA (L.curW s) ∨ b = atAF (L.ksb s) i) + curT : L.curW s ∈ H.tcbs + hi : i.val < 128 + vIn : v ∈ OS' + capV : capA st s' v = .AsidPool frame base + vcpuW : ∀ t ∈ Z.T, L.mem s' (wa t 3664#u64) = L.mem s (wa t 3664#u64) + vcw : ∀ y ∈ Z.V, L.mem s' (wa y 24#u64) = L.mem s (wa y 24#u64) + /- the cap split -/ + src : x ∈ OS + cap : capA st s x = .Untyped frame 12#u64 fi false + cap' : capA st s' x = .Untyped frame 12#u64 4096#u64 false + dst : capA st s v = .Null + src' : x ∈ OS' + slots : PoolSlotsA st OS OS' s s' x v frame base + sub : OS' ⊆ OS + kept : ∀ u ∈ OS, u ≠ x → capA st s u ≠ .Null → u ∈ OS' ∧ capA st s' u = capA st s u + /-- (E0.5c) the revocable bits of the non-empty slots other than the destination are kept. -/ + revK : ∀ y ∈ OS, y ≠ v → capA st s y ≠ .Null → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y + /-- the childless parent: no frame cap meets its block (`poolFrOffA`). -/ + frOff : ∀ y ∈ OS, ∀ q sz r d a1 a2 a3 a4 bits, capA st s y = .Frame q sz r d a1 a2 a3 a4 → sz.bits = ok bits → + q.val + 2 ^ bits.val ≤ frame.val ∨ frame.val + 4096 ≤ q.val + /- the spec side: only slot holders and the pool object change -/ + free : σ.kheap (specPtr frame) = none + kh : ∀ p, p ≠ specPtr frame → σ'.kheap p = σ.kheap p ∨ + (∃ r cs cs', σ.kheap p = some (.cnode r cs) ∧ σ'.kheap p = some (.cnode r cs')) ∨ + ∃ y y', σ.kheap p = some (.tcb y) ∧ σ'.kheap p = some (.tcb y') + /-- the only new ASID-table entry names the pool. -/ + asid : ∀ j q, σ'.archState.armAsidTable j = some (specPtr q) → + q = frame ∨ σ.archState.armAsidTable j = some (specPtr q) + +variable (K : PoolAsmHeapInA st Z H OS OS' Bf s s' σ σ' x v frame base fi i) +include K + +/-- A word of a heap object is off the pool block. -/ +theorem poolHeapA_omega {b : U64} (h : b ∈ H.omega) : ¬ (frame.val ≤ b.val ∧ b.val < frame.val + 4096) := by + obtain ⟨-, q, k, hq, -, g1, g2⟩ := h + rcases K.off q k hq with g | g <;> omega + +/-- A range inside an `other` object is off the pool block. -/ +theorem poolHeapA_page {r : U64} {len : Nat} (h : ∃ q z, H q = some (.other z) ∧ q.val ≤ r.val ∧ + r.val + len ≤ q.val + 2 ^ z) : r.val + len ≤ frame.val ∨ frame.val + 4096 ≤ r.val := by + obtain ⟨q, z, hq, g1, g2⟩ := h + rcases K.off q _ hq with g | g + · simp only [HKind.bits] at g + left; omega + · right; omega + +/-- A heap object is not at the pool page. -/ +theorem poolHeapA_ne {q : U64} {k : HKind} (h : H q = some k) : q ≠ frame := by + intro e + have := Nat.two_pow_pos k.bits + rcases K.off q k h with g | g <;> rw [e] at g <;> omega + +theorem poolHeapA_mono : ∀ q k, H q = some k → (PoolH H frame 12) q = some k := fun q _ h => + (Heap.add_of_not (N := (· = frame)) (poolHeapA_ne K h)).trans h + +theorem poolHeapA_new : (PoolH H frame 12) frame = some (.other 12) := Heap.add_of_mem rfl + +/-- A member of a set of heap pages is not the pool page. -/ +theorem poolHeapA_ptNe {P : Set U64} (h : PtHA H P) {r : U64} (hr : r ∈ P) : r ≠ frame := by + intro e + rcases poolHeapA_page K (len := 4096) (h r hr) with g | g <;> rw [e] at g <;> omega + +/-- A spec object that exists, is not a slot holder, and is not at the pool page, is kept. -/ +theorem poolHeapA_specKeep {p : ObjRef} {ko : KernelObject} (h : σ.kheap p = some ko) + (hc : ∀ r cs, ko ≠ .cnode r cs) (ht : ∀ y, ko ≠ .tcb y) : σ'.kheap p = some ko := by + have ne : p ≠ specPtr frame := fun e => by + rw [e, K.free] at h + cases h + rcases K.kh p ne with g | ⟨r, cs, cs', g, -⟩ | ⟨y, y', g, -⟩ + · exact g.trans h + · rw [h] at g + exact absurd (Option.some.inj g) (hc _ _) + · rw [h] at g + exact absurd (Option.some.inj g) (ht _) + +/-- The words of a tracked page are kept and off the block. -/ +theorem poolHeapA_pg + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 (J7A st (J7R2A st ar nA)) s a σ m) + {q : U64} (hq : SchedPageA st Z OS s q) (lo : U64) (hl : lo.val < 512) : + L.mem s' (peAF q lo) = L.mem s (peAF q lo) ∧ + ¬ (frame.val ≤ (peAF q lo).val ∧ (peAF q lo).val < frame.val + 4096) := by + obtain ⟨Pt, Ub, vr, -, -, -, -, -, -, link, -, -, -, -, hR⟩ := J.j7 + obtain ⟨_, _, _, _, _, _, _, _, R2, -⟩ := hR + have hw : PtW Pt (peAF q lo) := by + refine ⟨q, link q hq, core.num.U64.wrapping_mul lo 8#u64, ?_, ?_, rfl⟩ + · rw [wm8_valA hl]; omega + · rw [wm8_valA hl]; omega + have hv : VsR (L.ksb s) Pt (peAF q lo) := Or.inl hw + have off := poolHeapA_omega K (vr.om _ hv) + refine ⟨K.w.2.2 _ (vr.al _ hv) fun h => ?_, off⟩ + rcases h with (h | h) | h | h | h + · obtain ⟨t, ht, k, hk, e⟩ := h + exact poolHeapA_tlow J.sys.ent.heap (vr.om _ hv) ht (by omega) e + · exact vr.os _ hv h.1 + · exact off h + · exact poolHeapA_tlow J.sys.ent.heap (vr.om _ hv) K.curT (k := layout.tcb.STATE) (by simp) h + · refine HeapKsOff.ptAsWG J.ko R2.footprint J.sys.ent.ksw (R2.footprint.fit J.sys.ent.heap) _ hw (h ▸ ?_) + refine ⟨core.num.U64.wrapping_add 772352#u64 (core.num.U64.wrapping_mul i 8#u64), ?_, ?_, ?_, rfl⟩ <;> + · have := K.hi + have e : (core.num.U64.wrapping_add 772352#u64 (core.num.U64.wrapping_mul i 8#u64)).val = 772352 + 8 * i.val := by + rw [wa_valP, wm8_valA (by omega)] + simp + omega + omega + +/-- The parent's block fits the address space (`UtInvA.reg`). -/ +theorem poolHeapA_fit + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 (J7A st (J7R2A st ar nA)) s a σ m) : + frame.val + 4096 ≤ 2 ^ 64 := by + obtain ⟨G, par, hT⟩ := J.sys.sysl.sys.stz.1.1.tu + have hr := hT.ut.reg x K.src (by rw [K.cap]; exact physA_ut _ _ _ _) + rw [K.cap] at hr + obtain ⟨-, -, h⟩ := ut_rangeA (capA_ut_b K.cap) hr + exact h + +/-- A cap of the new set that is neither the untyped nor the pool cap is an old one. -/ +theorem poolHeapA_oldCap {u : U64} (hu : u ∈ OS') (h1 : ∀ q b f d, capA st s' u ≠ .Untyped q b f d) + (h2 : ∀ q b, capA st s' u ≠ .AsidPool q b) : u ∈ OS ∧ capA st s u = capA st s' u := by + rcases K.slots u hu with ⟨a, -, -, e⟩ | ⟨-, e⟩ | ⟨-, e⟩ + · exact ⟨a, e.symm⟩ + · exact absurd e (h1 _ _ _ _) + · exact absurd e (h2 _ _) + +/-- The tracked buffer words are off the block (their pinning frame is off it). -/ +theorem poolHeapA_bufPg + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 (J7A st (J7R2A st ar nA)) s a σ m) + {b : U64} (hb : BufW Bf b) : ¬ (frame.val ≤ b.val ∧ b.val < frame.val + 4096) := by + obtain ⟨bp, hbp, k, hk, rfl⟩ := hb + obtain ⟨-, t, -, hO, ptr, size, rights, x1, x2, x3, x4, bits, hc, hs, hw⟩ := J.bufOff.pin bp hbp + obtain ⟨-, g1, g2⟩ := hw k hk + rcases K.frOff _ hO _ _ _ _ _ _ _ _ _ hc hs with g | g <;> omega + +/-- A table page off the block stays off the grown footprint. -/ +theorem poolHeapA_tabOff + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 (J7A st (J7R2A st ar nA)) s a σ m) + {q : U64} (hq : SchedPageA st Z OS s q) (O : TabOffA (L := L) Z m s q) : + TabOffA (L := L) { Z with Pp := insert frame Z.Pp, G := G' } m s' q := by + have fit := poolHeapA_fit K J + refine ⟨fun i hi k => ?_, fun r hr e => ?_⟩ + · rcases poolRt_footSplitA (Z := { Z with S1 := ∅ }) (G' := G') K.w.1 K.w.2.1 k with g | ⟨lo, hlo, g⟩ + · exact O.mem i hi g + · exact (poolHeapA_pg K J hq i hi).2 (g ▸ poolHeapA_peIn fit hlo) + · rcases poolRt_relSplitA (Z := { Z with S1 := ∅ }) (G' := G') hr with g | g + · exact O.obj r g e + · have eq : q = frame := specPtr_inj (e.symm.trans g) + have h0 : (0#u64 : U64).val < 512 := by decide + exact (poolHeapA_pg K J hq 0#u64 h0).2 (by rw [eq]; exact poolHeapA_peIn fit h0) + +/-- **The table and heap fields of the record after the pool is made.** -/ +theorem poolRt_asmHeapA + (J : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 (J7A st (J7R2A st ar nA)) s a σ m) : + UtAsmHeapOutA st { Z with Pp := insert frame Z.Pp, G := G' } (PoolH H frame 12) OS' N E Rp Bf stack s' σ' m := by + have fit := poolHeapA_fit K J + have mono := poolHeapA_mono K + have hks := K.w.1 + -- the pool word is in the block + have keepT : ∀ (ty : PtType) (q : U64), SchedPageA st Z OS s q → UnmTabA st Z m s σ ty q → + UnmTabA st { Z with Pp := insert frame Z.Pp, G := G' } m s' σ' ty q := by + intro ty q pg O + obtain ⟨tb, hk, hty, he⟩ := O.spec + refine ⟨fun i hi => ?_, ⟨tb, poolHeapA_specKeep K hk (fun _ _ e => by cases e) (fun _ e => by cases e), hty, he⟩, + poolHeapA_tabOff K J pg O.off⟩ + rw [(poolHeapA_pg K J pg i hi).1] + exact O.inv i hi + have capPage : ∀ u ∈ OS, ∀ q : U64, ((∃ m a v, capA st s u = .PageTable q m a v) ∨ (∃ m a, capA st s u = .Pml4 q m a) ∨ + (∃ a v, capA st s u = .Ept q 0#u64 false a v) ∨ (∃ p a v, capA st s u = .Ept p 0#u64 false a v ∧ q = wa p 4096#u64) ∨ + ∃ y a, capA st s u = .HighVSpace y false a ∧ q = wa y 4096#u64) → SchedPageA st Z OS s q := + fun u hu q h => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨u, hu, h⟩)))))) + have hdead : ∀ k q, DeadA st OS' k s' q → DeadA st OS k s q := fun _ _ h => + utRt_deadMonoA K.cap K.cap' K.src' K.kept h + have tabPg : ∀ q, (q ∈ S2PgE Z.X Z.T2 ∨ ∃ y ∈ Z.Y, q = wa y 4096#u64) → SchedPageA st Z OS s q := by + rintro q ((h | ⟨r, hr, rfl | rfl⟩) | ⟨y, hy, rfl⟩) + · exact Or.inr (Or.inr (Or.inl h)) + · exact Or.inr (Or.inr (Or.inr (Or.inl hr))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨r, hr, rfl⟩)))) + · exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨y, hy, rfl⟩)))))) + have vNe : ∀ y ∈ Z.V, specPtr y ≠ specPtr frame := fun y hy e => + poolHeapA_ptNe K J.setsInH.pages (Or.inr hy) (specPtr_inj e) + refine + { unmPt := ?_ + tabS1 := fun q hq => poolHeapA_tabOff K J (Or.inr (Or.inl hq)) (J.tabS1 q hq) + tabExt := ?_ + vsVc := utRt_vsVcA J.vsVc hks fun b hb hv => ?_ + ptH := utRt_ptHA J.ptH mono fun r hr => ?_ + setsInH := utRt_setsInHA J.setsInH mono (fun r hr => ?_) (fun r hr => Or.inl hr) + bufOff := utRt_bufOffA J.bufOff (fun _ _ ⟨y, hy, h⟩ => ⟨y, K.sub hy, h⟩) (fun b hb h => ?_) + (fun b hb p hp o ho _ e => ?_) (fun _ _ y hy _ _ _ _ => hy) fun bp hbp => + (J.bufOff.pin bp hbp).keepF fun t ht hO _ _ r x1 x2 x3 x4 e => by + obtain ⟨h1, h2⟩ := K.kept _ hO (fun e' => by + rw [e', K.cap] at e + cases e) (by rw [e]; exact fun h => by cases h) + exact ⟨ht, h1, r, x1, x2, x3, x4, h2.trans e⟩ + deadExt := ?_ + utIpc := utRt_ipcHeapA J.utIpc mono (fun _ h => Or.inl h) (fun _ h => Or.inl h) (fun _ h => Or.inl h) + scSize := utRt_scSizeA (C := Z.C) (m := m) (σ := σ) (H := H) J.scSize (fun c hc => J.toJEntA.scs.symm ▸ hc) mono + (fun c hc => Or.inl ⟨hc, by + obtain ⟨y, k, hk, -⟩ := J.j.1.sch.sc c hc + exact (poolHeapA_specKeep K hk (fun _ _ e => by cases e) (fun _ e => by cases e)).trans hk.symm⟩) + frBase := ?_ + devFr := ?_ + thPos := J.thPos } + · -- unmPt + have old : ∀ u ∈ OS', ∀ c, capA st s' u = c → (∀ q b f d, c ≠ .Untyped q b f d) → (∀ q b, c ≠ .AsidPool q b) → + u ∈ OS ∧ capA st s u = c := fun u hu c e h1 h2 => by + obtain ⟨a, b⟩ := poolHeapA_oldCap K hu (fun q b f d => e ▸ h1 q b f d) (fun q b => e ▸ h2 q b) + exact ⟨a, b.trans e⟩ + refine { pt := fun u hu p asid va e => ?_, vs := fun u hu p asid e => ?_, + s2 := fun u hu p asid va e => ?_, hv := fun u hu p asid e => ?_ } + · obtain ⟨a, c⟩ := old u hu _ e (fun _ _ _ _ h => by cases h) (fun _ _ h => by cases h) + exact keepT _ p (capPage u a p (Or.inl ⟨_, _, _, c⟩)) (J.unmPt.pt u a p asid va c) + · obtain ⟨a, c⟩ := old u hu _ e (fun _ _ _ _ h => by cases h) (fun _ _ h => by cases h) + exact keepT _ p (capPage u a p (Or.inr (Or.inl ⟨_, _, c⟩))) (J.unmPt.vs u a p asid c) + · obtain ⟨a, c⟩ := old u hu _ e (fun _ _ _ _ h => by cases h) (fun _ _ h => by cases h) + have O := J.unmPt.s2 u a p asid va c + obtain ⟨es, hk, he⟩ := O.spec + refine ⟨fun i hi => ?_, es, poolHeapA_specKeep K hk (fun _ _ e => by cases e) (fun _ e => by cases e), he⟩ + by_cases lo : i.val < 512 + · rw [(poolHeapA_pg K J (capPage u a p (Or.inr (Or.inr (Or.inl ⟨_, _, c⟩)))) i lo).1] + exact O.inv i hi + · obtain ⟨j, hj, ej⟩ := peAF_hiA p i (by omega) hi + rw [ej, (poolHeapA_pg K J (capPage u a _ (Or.inr (Or.inr (Or.inr (Or.inl ⟨p, _, _, c, rfl⟩))))) j hj).1, ← ej] + exact O.inv i hi + · obtain ⟨a, c⟩ := old u hu _ e (fun _ _ _ _ h => by cases h) (fun _ _ h => by cases h) + have O := J.unmPt.hv u a p asid c + obtain ⟨l1, hk, he⟩ := O.spec + refine ⟨fun i hi => ?_, l1, poolHeapA_specKeep K hk (fun _ _ e => by cases e) (fun _ e => by cases e), he⟩ + rw [(poolHeapA_pg K J (capPage u a _ (Or.inr (Or.inr (Or.inr (Or.inr ⟨p, _, c, rfl⟩))))) i hi).1] + exact O.inv i hi + · -- tabExt + refine ⟨fun q hq i hi k => ?_, fun p hp r => ?_⟩ + · rcases poolRt_footSplitA (Z := extZA Z) (G' := G') hks K.w.2.1 k with g | ⟨lo, hlo, g⟩ + · exact J.tabExt.mem q hq i hi g + · exact (poolHeapA_pg K J (tabPg q hq) i hi).2 (g ▸ poolHeapA_peIn fit hlo) + · rcases poolRt_relSplitA (Z := extZA Z) (G' := G') r with g | g + · exact J.tabExt.obj p hp g + · have eq : p = frame := specPtr_inj g + have pg : SchedPageA st Z OS s p := by + rcases hp with h | h | h + · exact 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.inl h)) + have h0 : (0#u64 : U64).val < 512 := by decide + exact (poolHeapA_pg K J pg 0#u64 h0).2 (by rw [eq]; exact poolHeapA_peIn fit h0) + · -- vsVc + cases hb with + | asid hi h => exact ⟨.asid hi h, hv⟩ + | pool p lo hp h => + rcases hp with rfl | hp + · obtain ⟨y, hy, o, ho, -, e⟩ := hv + have g := poolHeapA_page K (len := 4096) (J.setsInH.pages y (Or.inr hy)) + have b0 := poolHeapA_peIn fit h + obtain ⟨q, z, hq, g1, g2⟩ := J.setsInH.pages y (Or.inr hy) + have fq := J.sys.ent.heap.fits q _ hq + simp only [HKind.bits] at fq + have ev : (wa y o).val = y.val + o.val := by + rw [wa_valP]; exact Nat.mod_eq_of_lt (by omega) + rw [e, ev] at b0 + omega + · exact ⟨.pool p lo hp h, hv⟩ + | pt p i hp h => exact ⟨.pt p i hp h, hv⟩ + | high y i hy h => exact ⟨.high y i hy h, hv⟩ + · -- ptH + have new : ∃ q z, (PoolH H frame 12) q = some (.other z) ∧ q.val ≤ frame.val ∧ frame.val + 4096 ≤ q.val + 2 ^ z := + ⟨frame, 12, poolHeapA_new K, le_refl _, le_refl _⟩ + rcases hr with (rfl | hr) | hr + · exact Or.inr new + · exact Or.inl (Or.inl hr) + · exact Or.inl (Or.inr hr) + · -- setsInH + have new : ∃ q z, (PoolH H frame 12) q = some (.other z) ∧ q.val ≤ frame.val ∧ frame.val + 4096 ≤ q.val + 2 ^ z := + ⟨frame, 12, poolHeapA_new K, le_refl _, le_refl _⟩ + rcases hr with (((rfl | hr) | hr) | hr) | hr + · exact Or.inr new + · exact Or.inl (Or.inl (Or.inl (Or.inl hr))) + · exact Or.inl (Or.inl (Or.inl (Or.inr hr))) + · exact Or.inl (Or.inl (Or.inr hr)) + · exact Or.inl (Or.inr hr) + · -- bufOff: VSpace words + rw [hks] at h + cases h with + | asid hi h => exact .asid hi h + | pool p lo hp h => + rcases hp with rfl | hp + · exact absurd (poolHeapA_peIn fit h) (poolHeapA_bufPg K J hb) + · exact .pool p lo hp h + | pt p i hp h => exact .pt p i hp h + | high y i hy h => exact .high y i hy h + · -- bufOff: pages + rcases hp with (rfl | h) | h | h | h | h | h | h | ⟨u, hu, h⟩ + · have ev : (wa p o).val = p.val + o.val := by + rw [wa_valP]; exact Nat.mod_eq_of_lt (by omega) + exact absurd (poolHeapA_bufPg K J hb) (not_not.2 (by rw [e, ev]; omega)) + · 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)))))) + · have o : u ∈ OS ∧ capA st s u = capA st s' u := by + refine poolHeapA_oldCap K hu (fun q b f d e' => ?_) (fun q b e' => ?_) <;> + rcases h with ⟨_, _, _, k⟩ | ⟨_, _, k⟩ | ⟨_, _, k⟩ | ⟨_, _, _, k, -⟩ | ⟨_, _, k, -⟩ <;> + rw [k] at e' <;> cases e' + exact capPage u o.1 p (by rw [o.2]; exact h) + · -- deadExt + have hV : ∀ y ∈ Z.V, (y ∈ Z.V ∧ σ'.kheap (specPtr y) = σ.kheap (specPtr y)) ∨ + ∀ w, σ'.kheap (specPtr y) = some (.archObj (.vcpu w)) → w.vcpuTcb = none := fun y hy => by + rcases K.kh _ (vNe y hy) with g | ⟨_, _, _, -, g⟩ | ⟨_, _, -, g⟩ + · exact Or.inl ⟨hy, g⟩ + · exact Or.inr fun _ e => by rw [g] at e; cases e + · exact Or.inr fun _ e => by rw [g] at e; cases e + have hY : ∀ r ∈ Rp, ∀ y, σ'.kheap (specPtr r) = some (.reply y) → + (r ∈ Rp ∧ σ.kheap (specPtr r) = some (.reply y)) ∨ y.replyTcb = none := fun r hr y e => by + have ne : specPtr r ≠ specPtr frame := fun h => poolHeapA_ne K (J.utIpc.reply r hr) (specPtr_inj h) + rcases K.kh _ ne with g | ⟨_, _, _, -, g⟩ | ⟨_, _, -, g⟩ + · exact Or.inl ⟨hr, g.symm.trans e⟩ + · rw [g] at e; cases e + · rw [g] at e; cases e + have D := utRt_deadExtA (Z' := { Z with Pp := insert frame Z.Pp, G := G' }) (σ' := { σ' with archState := σ.archState }) + (Rp' := Rp) (stack' := stack) (OS' := OS') (s' := s') J.deadExt hdead hV (fun r hr c hc h => ⟨hr, hc, h⟩) rfl + (fun t ht => Or.inl ⟨ht, K.vcpuW t ht⟩) (fun y hy => Or.inl ⟨hy, K.vcw y hy⟩) hY + refine { vcpu := D.vcpu, reply := D.reply, asid := fun j p h => ?_, tvcpu := D.tvcpu, vcDeadRun := D.vcDeadRun, + replyTcb := D.replyTcb } + rcases K.asid j p h with rfl | old + · exact fun dead => dead v K.vIn ⟨base, K.capV⟩ + · exact fun dead => J.deadExt.asid j p old (hdead _ _ dead) + · -- frBase + have lam : FrLamA st OS' s' := by + intro y hy p rt mp e asid va hc z hz pz + have oy : y ∈ OS ∧ capA st s y = capA st s' y := + poolHeapA_oldCap K hy (fun q b f d h => by rw [hc] at h; cases h) (fun q b h => by rw [hc] at h; cases h) + have e12 : (12#u64 : U64).val = 12 := rfl + have blk : ∀ c : capability.Cap, baseA c = frame.val → topA c = frame.val + 4095 → + DisjA c (capA st s' y) := by + intro c bc tc + obtain ⟨bits, hb⟩ : ∃ bits, capability.FrameSize.bits .Large = ok bits := ⟨_, rfl⟩ + unfold DisjA + rcases K.frOff y oy.1 _ _ _ _ _ _ _ _ _ (oy.2.trans hc) hb with g | g + · have hq : p.val + 2 ^ bits.val ≤ 2 ^ 64 := by have := frame.hBounds; simp [U64.size] at this; omega + obtain ⟨b1, t1⟩ := frame_rangeA (r := rt) (a := asid) (v := va) (d := false) (m := mp) (e := e) hb hq + right + rw [hc, t1, bc] + have := Nat.two_pow_pos bits.val + omega + · have f := frA_size (ptr := p) (rights := rt) (x3 := asid) (x4 := va) (dv := false) (x1 := mp) (x2 := e) + (size := .Large) hb + left + rw [hc, tc] + unfold baseA + rw [f.1] + omega + have U1b : baseA (.Untyped frame 12#u64 4096#u64 false) = frame.val := by unfold baseA; rw [ptrA_ut] + have U1t : topA (.Untyped frame 12#u64 4096#u64 false) = frame.val + 4095 := by + obtain ⟨G0, par0, hT0⟩ := J.sys.sysl.sys.stz.1.1.tu + have hr := hT0.ut.reg _ K.src (by rw [K.cap]; exact physA_ut _ _ _ _) + rw [K.cap] at hr + obtain ⟨-, r2, -⟩ := ut_rangeA (capA_ut_b K.cap) hr + have eq : topA (.Untyped frame 12#u64 4096#u64 false) = topA (.Untyped frame 12#u64 fi false) := by + unfold topA; rw [ptrA_ut, sizeA_ut, ptrA_ut, sizeA_ut] + rw [eq, r2, e12] + norm_num + rcases K.slots z hz with ⟨zo, -, hzv, kz'⟩ | ⟨-, kz'⟩ | ⟨-, kz'⟩ + · have pz0 : physA (capA st s z) = true := by rw [← kz']; exact pz + have hnn : capA st s z ≠ .Null := fun h => by rw [h, physA_null] at pz0; cases pz0 + rcases J.frBase.2.2 y oy.1 p rt mp e asid va (by rw [oy.2]; exact hc) z zo pz0 with d | ⟨f, r⟩ | w + · left; rwa [oy.2, ← kz'] at d + · right; left + exact ⟨by rw [kz']; exact f, by rw [K.revK z zo hzv hnn]; exact r⟩ + · right; right; rwa [oy.2, ← kz'] at w + · left; exact blk _ (by rw [kz']; exact U1b) (by rw [kz']; exact U1t) + · left + obtain ⟨rb, rt'⟩ := poolRegA frame base + exact blk _ (by rw [kz', rb]; exact U1b) (by rw [kz', rt']; exact U1t) + refine ⟨fun y hy z hz fy kz => ?_, fun y hy z hz fy kz => ?_, lam⟩ + swap + · have oy : y ∈ OS ∧ capA st s y = capA st s' y := by + refine poolHeapA_oldCap K hy (fun q b f d e => ?_) (fun q b e => ?_) <;> rw [e] at fy <;> cases fy + rcases K.slots z hz with ⟨zo, -, -, kz'⟩ | ⟨-, kz'⟩ | ⟨-, kz'⟩ + · rw [← oy.2, kz'] + exact J.frBase.2.1 y oy.1 z zo (by rw [oy.2]; exact fy) (by rw [← kz']; exact kz) + · rw [kz'] at kz + have := kz.2.1 + cases this + · rw [kz'] + rintro ⟨c1, c2⟩ + have hbz : baseA (.AsidPool frame base) = frame.val := by unfold baseA; rw [ptrA_of (c := .AsidPool frame base) (v := frame) rfl] + rw [hbz] at c1 c2 + cases hc : capA st s' y <;> rw [hc] at fy <;> try (cases fy; done) + rename_i q sz r d a1 a2 a3 a4 + obtain ⟨bits, hb⟩ : ∃ bits, capability.FrameSize.bits sz = ok bits := by cases sz <;> exact ⟨_, rfl⟩ + rcases K.frOff y oy.1 _ _ _ _ _ _ _ _ _ (oy.2.trans hc) hb with g | g + · have hq : q.val + 2 ^ bits.val ≤ 2 ^ 64 := by have := frame.hBounds; simp [U64.size] at this; omega + obtain ⟨b1, t1⟩ := frame_rangeA (r := r) (a := a3) (v := a4) (d := d) (m := a1) (e := a2) hb hq + rw [hc, t1] at c2 + have := Nat.two_pow_pos bits.val + omega + · have f := frA_size (ptr := q) (rights := r) (x3 := a3) (x4 := a4) (dv := d) (x1 := a1) (x2 := a2) + (size := sz) hb + rw [hc] at c1 + unfold baseA at c1 + rw [f.1] at c1 + omega + have oy : y ∈ OS ∧ capA st s y = capA st s' y := by + refine poolHeapA_oldCap K hy (fun q b f d e => ?_) (fun q b e => ?_) <;> rw [e] at fy <;> cases fy + rcases K.slots z hz with ⟨zo, -, -, kz'⟩ | ⟨-, kz'⟩ | ⟨-, kz'⟩ + · rw [← oy.2, kz'] + exact J.frBase.1 y oy.1 z zo (by rw [oy.2]; exact fy) (by rw [← kz']; exact kz) + · rw [kz'] at kz + have := kz.2.1 + cases this + · rw [kz', ptrA_of (c := .AsidPool frame base) (v := frame) rfl] + intro e + cases hc : capA st s' y <;> rw [hc] at fy <;> try (cases fy; done) + rename_i q sz r d a1 a2 a3 a4 + rw [hc, ptrA_of (c := .Frame q sz r d a1 a2 a3 a4) (v := q) rfl] at e + rcases K.frOff y oy.1 _ _ _ _ _ _ _ _ _ (oy.2.trans hc) (frameBitsE sz) with g | g + all_goals + have := Nat.two_pow_pos (psA sz).val + rw [← e] at g + omega + · -- devFr + intro y hy p size rights mapped ept asid va hc k hk + have oy : y ∈ OS ∧ capA st s y = capA st s' y := by + refine poolHeapA_oldCap K hy (fun q b f d e => ?_) (fun q b e => ?_) <;> rw [e] at hc <;> cases hc + have c0 := oy.2.trans hc + have ne : p ≠ frame := fun e => by + rcases K.frOff y oy.1 _ _ _ _ _ _ _ _ _ c0 (frameBitsE size) with g | g + all_goals + have := Nat.two_pow_pos (psA size).val + rw [e] at g + omega + replace hk : H p = some k := by + rcases Heap.add_eq_some.1 hk with ⟨g, -⟩ | ⟨-, g⟩ + · exact absurd g ne + · exact g + obtain ⟨hb, dev, pg, h⟩ := J.devFr y oy.1 p size rights mapped ept asid va c0 k hk + exact ⟨hb, dev, pg, poolHeapA_specKeep K h (fun _ _ e => by cases e) (fun _ e => by cases e)⟩ + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolIpcA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolIpcA.lean new file mode 100644 index 000000000..8baa17a59 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolIpcA.lean @@ -0,0 +1,526 @@ +/- +P3 (aarch64, Stage 4, line vsx-D): **the spec, IPC and scheduler fields of the record after +`ARMASIDControlMakePool`**, the pool twins of `P3/UtAsmIpcA` and `P3/UtAsmSchedA` (the spec side is +`Stage3PoolSpecA`). One transfer from the dropped record (after the caller's restart, so the caller's state word is +not written) to the post state. + +`PoolStepA` states the step on the record before it (the dropped record: no joint object meets the pool page). The +FL4 footprint is the cap words, the pool page and the ASID-table word `i`; no CDT, ASID or user-memory word of the +spec is read by these fields. From it: + +* `poolRt_clrA`, `poolRt_atOffA`, `poolRt_keepA`: no relation word is written. +* `poolRt_asmIpcSchedA`: `UtAsmSpecOutA`, `UtAsmIpcOutA`, `UtAsmSchedOutA` and `BlkQueuedA` after the step. The + Retype IPC bundle and `utRt_sidleA` are applied with no new thread, SC or IPC object, at the spec state with the + old machine and arch state; the fields that depend on the spec state's identity are then restated at the real state. + +No named premise: hypotheses only. New module. +-/ +import Fl4ProofsA64.P3.Stage3PoolSpecA +import Fl4ProofsA64.P3.UtAsmIpcA +import Fl4ProofsA64.P3.UtAsmSchedA +import Fl4ProofsA64.P3.SlotJA +import Fl4ProofsA64.P3.UtClrA +import Fl4ProofsA64.P3.UtApIpcA +import Fl4ProofsA64.P3.UtZeroSpecA +import Fl4ProofsA64.P3.Stage3CapSlotA + +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 + +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 H' : Heap} {OS 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' : S} {a : A} {σ σ' : State Unit} {m : McState} {x v frame base fi i : U64} + +/-- **The step, on the record before it**: `x` is the parent untyped's slot, `v` the destination slot, `frame` the +parent's 4 KiB block, `i` the ASID-table index. -/ +structure PoolStepA (st : machine.Store S) [L : LawfulStore st] (Z : XSetsA) (H : Heap) (OS : Set U64) (s s' : S) + (σ σ' : State Unit) (m : McState) (n : Nat) (x v frame fi i : U64) : Prop where + mem : x ∈ OS + cap : capA st s x = .Untyped frame 12#u64 fi false + slot : IsSlotA Z.th x + /-- every slot of the typed heap is a slot of the store. -/ + sub : ∀ y, IsSlotA Z.th y → y ∈ OS + /-- the destination is not a TCB's buffer slot. -/ + vsb : ∀ t ∈ Z.T, v ≠ sbWordA t + hi : i.val < 128 + /-- no joint object meets the pool page (the dead-object drop). -/ + disj : ∀ q bytes, JointObjectA Z H q bytes → q.val + bytes ≤ frame.val ∨ frame.val + 4096 ≤ q.val + w : WritesIn st s s' (fun b => W7.CapW H.tcbs {b | InOS OS b} ∅ b ∨ + (frame.val ≤ b.val ∧ b.val < frame.val + 4096) ∨ b = atAF (L.ksb s) i) + capK : ∀ y ∈ OS, y ≠ x → y ≠ v → capA st s' y = capA st s y + fresh : σ.kheap (specPtr frame) = none + pool : σ'.kheap (specPtr frame) = some (.archObj (.asidPool fun _ => none)) + /-- only CNodes change besides the pool. -/ + kh : ∀ p, p ≠ specPtr frame → σ'.kheap p = σ.kheap p ∨ + ∃ r cs cs', σ.kheap p = some (.cnode r cs) ∧ σ'.kheap p = some (.cnode r cs') ∧ + (wellFormedCnodeN r cs' → wellFormedCnodeN r cs) + glob : SpecGlobA σ { σ' with machineState := σ.machineState, archState := σ.archState } + /-- the spec's memory changes only by zeroing bytes of the page. -/ + um : ∀ w, σ'.machineState.underlyingMemory w = σ.machineState.underlyingMemory w ∨ + (σ'.machineState.underlyingMemory w = 0 ∧ ∃ q : U64, w = specPtr q ∧ frame.val ≤ q.val ∧ q.val < frame.val + 4096) + cdt : ∀ c d, σ'.cdt c = some d → σ.cdt c = some d ∨ + ∀ q : U64, UtFreeA st OS s (fun _ => True) q.val → c.1 ≠ specPtr q ∧ d.1 ≠ specPtr q + tabInj : ∀ i j r, σ'.archState.armAsidTable i = some r → σ'.archState.armAsidTable j = some r → i = j + irq : SpecIrqA σ' + newCap : ∀ sl, (∃ sl0, specCapAtA σ' sl = specCapAtA σ sl0) ∨ ∀ c, specCapAtA σ' sl = some c → NoIdleCapV m n c + +/-- The pool page holds no object, node or kernel-state word. -/ +theorem poolRt_clrA + (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) + (P : PoolStepA st Z H OS s s' σ σ' m n x v frame fi i) : + UtClrA st Z H s frame.val (frame.val + 4096) := by + obtain ⟨hnodes, hks⟩ := J.sys.sysl.sys.stz.2.2 x P.mem frame 12#u64 fi P.cap + have h12 : (12#u64 : U64).val = 12 := rfl + rw [h12] at hnodes hks + refine ⟨P.disj, fun c hc => ?_, ?_⟩ + · rcases hnodes c hc with g | g <;> omega + · rcases hks with g | g <;> omega + +/-- **No relation word is an ASID-table word.** -/ +theorem poolRt_atOffA + (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) + {i b : U64} (hi : i.val < 128) (h : UtWhereA st Z H m s σ b) : b ≠ atAF (L.ksb s) i := by + intro eb + have hk : (L.ksb s).val + 788736 ≤ 2 ^ 64 := J.sys.ent.ksw + have v := atAF_valA hk hi + rw [← eb] at v + have P := J.j.1.place + -- a word of a non-CNode object, or of a block of 4096 bytes or more, is off the table + have obj : ∀ q k, Z.th q = some k → (∀ r, k ≠ .cnode r) → q.val ≤ b.val → b.val < q.val + k.size → False := by + intro q k hq nc h1 h2 + have ni : ¬ IrqNodeA (L.ksb s) q := by + rintro ⟨j, hj, e⟩ + have := P.irq j hj + rw [← e, hq] at this + exact nc 0 (Option.some.inj this) + have := P.ks q k hq ni + unfold ksSizeA at this + omega + cases h with + | tcb t ht h1 h2 => + exact obj t _ (ut_tcbThA J ht).1 (fun _ e => by cases e) (by omega) (by simp only [ObjKindA.size]; omega) + | ibuf t ht e => + have w := ut_sbValA J ht + refine obj t _ (ut_tcbThA J ht).1 (fun _ e => by cases e) ?_ ?_ + · rcases e with e | e <;> rw [e] <;> omega + · simp only [ObjKindA.size]; rcases e with e | e <;> rw [e] <;> omega + | other q len hq h1 h2 => exact obj q _ hq (fun _ e => by cases e) h1 h2 + | sc c y k hc hk' ha => + have := (J.sr.scp.out c hc y k hk' b ha).2 + unfold ksSizeA at this + omega + | node c o hc ho e => + have w : b.val = L.nodeBase s c + o.val := by rw [e]; exact nodeAt_val (J.sq.nodes c hc) ho + obtain ⟨cn, _, hcn, hcs⟩ := J.j.1.csN + have : c.val < 128 := by have := (hcs c).1 hc; omega + unfold LawfulStore.nodeBase at w + omega + | glob o ho e => + have w : b.val = (L.ksb s).val + o.val := by rw [e, wa_valP]; exact Nat.mod_eq_of_lt (by omega) + omega + +/-- A word that no slot of the store holds is not written, if off the page and the table word. -/ +theorem poolRt_memA + (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) + (P : PoolStepA st Z H OS s s' σ σ' m n x v frame fi i) {b : U64} (al : Aligned b) (ns : ¬ InOS OS b) + (pg : ¬ (frame.val ≤ b.val ∧ b.val < frame.val + 4096)) (at' : b ≠ atAF (L.ksb s) i) : + L.mem s' b = L.mem s b := by + refine P.w.mem_eq al fun h => ?_ + rcases h with (⟨t, ht, K, hK, e⟩ | ⟨h, -⟩) | h | h + · have ht' : t ∈ Z.T := by rw [← J.tcbs]; exact ht + have f := (ut_tcbThA J ht').2 + have bv : b.val = t.val + K.val := by rw [e, wa_valP]; exact Nat.mod_eq_of_lt (by omega) + have jlt : K.val / 32 < 7 := by omega + have sl : IsSlotA Z.th (slotAddrA (specPtr t) (BitVec.ofNat 64 (K.val / 32))) := + ⟨_, Or.inr ⟨(ut_tcbThA J ht').1, K.val / 32, by simp [tcbSlotsA]; omega, rfl⟩⟩ + have sv : (slotAddrA (specPtr t) (BitVec.ofNat 64 (K.val / 32))).val = t.val + 32 * (K.val / 32) := + slotAddrA_valN (by omega) + exact ns ⟨_, P.sub _ sl, by omega, by omega⟩ + · exact ns h + · exact pg h + · exact at' h + +/-- **No word the relations read, outside a TCB's buffer slot, is written.** -/ +theorem poolRt_keepA + (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) + (P : PoolStepA st Z H OS s s' σ σ' m n x v frame fi i) {b : U64} (al : Aligned b) + (h : UtRdA st Z N E Rp Bf m s σ b) + (sb : (∀ t ∈ Z.T, b ≠ sbWordA t ∧ b ≠ wa (sbWordA t) 8#u64) ∨ SReadA st Z m s σ b) : + L.mem s' b = L.mem s b := by + have wh := ut_rd_whereA J h + have node : ∀ c ∈ Z.Cs, ∀ o : U64, o.val < 4288 → b = L.nodeAt s c o → ¬ InOS OS b := by + intro c hc o ho e g + obtain ⟨⟨Q, R, q⟩, -⟩ := J.sys.ent.bxi + exact capw_ne_node q (inOS_capw J.sys.ent.os al g) hc ho e + have ns : ¬ InOS OS b := by + by_cases hs : SReadA st Z m s σ b + · by_cases hn : b = nwA st s + · have h0 : (0#u64 : U64) ∈ Z.Cs := by + obtain ⟨k, hk, -, h⟩ := J.j.1.csN + exact (h 0#u64).2 (by simpa using hk) + exact node 0#u64 h0 layout.node.DEBUG_TCBS (by rw [debug_val]; omega) hn + · exact (utRt_rdOffA J al (Or.inr ⟨hs, hn⟩)).1 + · have hb : UtRdBA st Z N E Rp Bf b := h.resolve_left hs + exact (utRt_rdOffA J al (Or.inl ⟨hb, sb.resolve_right hs⟩)).1 + exact poolRt_memA J P al ns (ut_rd_regionA J (poolRt_clrA J P) h) (poolRt_atOffA J P.hi wh) + +/-- **The spec, IPC and scheduler fields after MakePool.** `th'` / `H'` are the grown typed heap and heap (the pool is +a ghost `other` object on the page); `OS'` the slot set with its cap split `F` and `hoth` as in `Stage3PoolCapsA`. -/ +theorem poolRt_asmIpcSchedA + (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) + (P : PoolStepA st Z H OS s s' σ σ' m n x v frame fi i) + {base : U64} (F : PoolSlotsA st OS OS' s s' x v frame base) + (hoth : ∀ u ∈ OS, u ≠ x → ∀ q b f d, capA st s u = .Untyped q b f d → + (frame.val + 4096 ≤ q.val ∨ q.val + 2 ^ b.val ≤ frame.val) ∨ + (q.val ≤ frame.val ∧ frame.val + 4096 ≤ q.val + f.val)) + {th' : TypedHeapA} {Pp' : Set U64} {G' : MdbGhostA} (hth : ∀ q k, Z.th q = some k → th' q = some k) + (hthN : ∀ q k, th' q = some k → Z.th q = some k ∨ (frame.val ≤ q.val ∧ q.val + k.size ≤ frame.val + 4096)) + (hthT : ∀ t, th' t = some .tcb ↔ t ∈ Z.T) (hpl : PlaceA th' (L.ksb s')) + (horig : ∀ sl, σ'.isOriginalCap sl = true → + (σ.isOriginalCap sl = true ∧ specCapAtA σ' sl = specCapAtA σ sl) ∨ + ((∀ q : U64, UtFreeA st OS s (fun _ => True) q.val → sl.1 ≠ specPtr q) ∧ AbsSlotA th' sl ∧ + specCapAtA σ' sl ≠ some .nullCap)) + (hN : ∀ q, H' q = some .ntfn → H q = some .ntfn) (hE : ∀ q, H' q = some .ep → H q = some .ep) + (hR : ∀ q, H' q = some .reply → H q = some .reply) : + UtAsmSpecOutA st { Z with th := th', Pp := Pp', G := G' } OS' ia ie s' σ' m ∧ + UtAsmIpcOutA st Z.T Z.C th' H' N E Rp Bf stack n s' σ' m ∧ + UtAsmSchedOutA st { Z with th := th', Pp := Pp', G := G' } κ s' σ' m n ∧ + BlkQueuedA Z.T E N (L.mem s') σ' := by + have hks : L.ksb s' = L.ksb s := P.w.1 + have hcpu : L.cpu s' = L.cpu s := P.w.2.1 + have clr := poolRt_clrA J P + have keepR : ∀ b, Aligned b → UtRdA st Z N E Rp Bf m s σ b → + (∀ t ∈ Z.T, b ≠ sbWordA t ∧ b ≠ wa (sbWordA t) 8#u64) → L.mem s' b = L.mem s b := + fun _ al h g => poolRt_keepA J P al h (Or.inl g) + have keepS : ∀ b, Aligned b → SReadA st Z m s σ b → L.mem s' b = L.mem s b := + fun _ al h => poolRt_keepA J P al (Or.inl h) (Or.inr h) + have footN : Notif.FootEq N Z.T (L.mem s) (L.mem s') := fun b al h => + keepR b al (Or.inr (Or.inr (Or.inl h))) (utRt_sbOffA J (Or.inr h)) + have footE : Endp.FootEq Z.T E Rp Bf (L.mem s) (L.mem s') := fun b al h => + keepR b al (Or.inr (Or.inl h)) (utRt_sbOffA J (Or.inl h)) + have tf : ∀ u ∈ Z.T, u.val + 4096 ≤ 2 ^ 64 := fun u hu => (ut_tcbThA J hu).2 + have sbv : ∀ u ∈ Z.T, (sbWordA u).val = u.val + 64 := fun u hu => (ut_sbValA J hu).1 + have ta : ∀ u ∈ Z.T, u.val % 4096 = 0 := fun u hu => by + have := J.j.1.place.align u _ (ut_tcbThA J hu).1 + simpa only [ObjKindA.size] using this + -- a TCB word above the slots is no buffer-slot word + have tcbW : ∀ u ∈ Z.T, ∀ K : U64, 224 ≤ K.val → K.val < 4096 → K.val % 8 = 0 → + UtRdA st Z N E Rp Bf m s σ (wa u K) → L.mem s' (wa u K) = L.mem s (wa u K) := by + intro u hu K k0 k1 k8 g + have fu := tf u hu + have au := ta u hu + have e : (wa u K).val = u.val + K.val := by rw [wa_valP]; exact Nat.mod_eq_of_lt (by omega) + refine keepR _ (by show _ % 8 = 0; omega) g fun t ht => ?_ + have v0 := sbv t ht + have ft := tf t ht + have at8 := ta t ht + have v8 : (wa (sbWordA t) 8#u64).val = t.val + 72 := by + rw [wa_valP, show (8#u64 : U64).val = 8 from rfl, v0]; exact Nat.mod_eq_of_lt (by omega) + constructor <;> intro h <;> have := congrArg UScalar.val h <;> omega + have tW : ∀ u ∈ Z.T, ∀ b, (b = mcpA u ∨ b = yieldA u ∨ b = sbWordA u ∨ b = wa (sbWordA u) 8#u64 ∨ + b = wa u 3512#u64 ∨ b = wa u 3664#u64 ∨ b = flagsA u) → UtRdA st Z N E Rp Bf m s σ b := + fun u hu b h => Or.inr (Or.inr (Or.inr (Or.inr ⟨u, hu, h⟩))) + have linkW : ∀ rp ∈ Rp, ∀ K : U64, K = 8#u64 ∨ K = 16#u64 → (wa rp K = rNextA rp ∨ wa rp K = rPrevA rp) → + L.mem s' (wa rp K) = L.mem s (wa rp K) := by + intro rp hrp K hK hw + have R := J.iplaced.e.rep rp hrp + have K8 : K.val = 8 ∨ K.val = 16 := by rcases hK with rfl | rfl <;> simp + have e : (wa rp K).val = rp.val + K.val := by rw [wa_valP]; exact Nat.mod_eq_of_lt (by omega) + have al : Aligned (wa rp K) := by show _ % 8 = 0; omega + refine keepR _ al (Or.inr (Or.inr (Or.inr (Or.inl ⟨rp, hrp, hw⟩)))) fun t ht => ?_ + have v0 := sbv t ht + have ft := tf t ht + have v8 : (wa (sbWordA t) 8#u64).val = t.val + 72 := by + rw [wa_valP, show (8#u64 : U64).val = 8 from rfl, v0]; exact Nat.mod_eq_of_lt (by omega) + have d := J.iplaced.e.rt rp hrp t ht + constructor <;> intro h <;> have := congrArg UScalar.val h <;> omega + have sbCap : ∀ u ∈ Z.T, capA st s' (sbWordA u) = capA st s (sbWordA u) := by + intro u hu + have sl : IsSlotA Z.th (sbWordA u) := + ⟨u, Or.inr ⟨(ut_tcbThA J hu).1, 2, by simp [tcbSlotsA], (bufSlot_eqA u).symm⟩⟩ + refine P.capK _ (P.sub _ sl) (fun e => ?_) (fun e => P.vsb u hu e.symm) + exact ut_rd_slotA J P.mem P.cap P.slot (Or.inl e) (tW u hu _ (Or.inr (Or.inr (Or.inl rfl)))) + -- the creation, at the old machine and arch state + let σo : State Unit := { σ' with machineState := σ.machineState, archState := σ.archState } + have O : UtNewObjA σ σo (fun q => q = specPtr frame) (.archObj (.asidPool fun _ => none)) := + poolRt_specObjA P.fresh P.pool P.kh P.glob + have kt : ∀ p y, σ.kheap p = some (.tcb y) → σ'.kheap p = some (.tcb y) := fun p y h => + O.keep p _ h (fun _ _ e => by cases e) + have ks : ∀ p y k, σ.kheap p = some (.schedContext y k) → σ'.kheap p = some (.schedContext y k) := fun p y k h => + O.keep p _ h (fun _ _ e => by cases e) + have bt : ∀ p y, σ'.kheap p = some (.tcb y) → σ.kheap p = some (.tcb y) := fun p y h => by + rcases O.back p _ h (fun _ _ e => by cases e) with g | ⟨-, e⟩ + · exact g + · cases e + have bs : ∀ p y k, σ'.kheap p = some (.schedContext y k) → σ.kheap p = some (.schedContext y k) := fun p y k h => by + rcases O.back p _ h (fun _ _ e => by cases e) with g | ⟨-, e⟩ + · exact g + · cases e + have irqo : SpecIrqA σo := ⟨P.irq.node, P.irq.slot, P.irq.ref⟩ + -- the spec side + have spec : UtAsmSpecOutA st { Z with th := th', Pp := Pp', G := G' } OS' ia ie s' σ' m := by + refine poolRt_asmSpecA J F hoth + { th := hth, cs := rfl, idleW := fun c hc o ho => ?_, kheapNone := fun q hq off => ?_, um := fun w e => ?_, + cdt := P.cdt, orig := horig, cnode := fun q r cs e w => ?_, tcb := fun q y e => ⟨y, bt q y e⟩, + tabInj := P.tabInj } + · have nc := J.sq.nodes c hc + have o4 : o.val < 4288 ∧ o.val % 8 = 0 := by + rcases ho with rfl | rfl <;> simp [layout.node.IDLE_THREAD, layout.node.IDLE_SC] + have al : Aligned (L.nodeAt s c o) := by + show _ % 8 = 0 + rw [nodeAt_val nc o4.1] + have := nc.align + omega + rw [nodeAt_ksb hks] + exact keepS _ al (Or.inl ⟨c, hc, o, o4.1, rfl⟩) + · have h1 : specPtr q ≠ specPtr frame := fun g => by + have := specPtr_inj g + rw [this] at off + omega + rcases P.kh _ h1 with g | ⟨r, cs, cs', g, -⟩ + · rw [g]; exact hq + · rw [hq] at g; cases g + · rcases P.um w with g | ⟨g, -⟩ + · rw [g]; exact e + · exact g + · have h1 : q ≠ specPtr frame := fun g => by rw [g, P.pool] at e; cases e + rcases P.kh q h1 with g | ⟨r0, cs0, cs1, g0, g1, wf⟩ + · exact ⟨cs, g ▸ e, w⟩ + · have h := Option.some.inj (g1.symm.trans e) + simp only [KernelObject.cnode.injEq] at h + obtain ⟨rfl, rfl⟩ := h + exact ⟨cs0, g0, wf w⟩ + have Ki : UtAsmIpcInA st Z th' H H' N E Rp Bf ∅ ∅ ∅ ∅ ∅ (fun _ => False) s s' σ σo m m + (fun q => q = specPtr frame) (.archObj (.asidPool fun _ => none)) := + { spec := O + grow := ⟨hth, fun _ h => h.elim, fun _ h => h.elim, fun _ h => h.elim, fun _ h => h.elim, + fun _ h => h.elim, fun t ht => (J.sr.thT t).2 ht⟩ + place := hks ▸ hpl + footE := footE + footN := footN + newN := fun _ h => h.elim + newE := fun _ h => h.elim + newR := fun _ h => h.elim + newT := fun _ h => h.elim + newTslot := fun _ h => h.elim + newC := fun _ h => h.elim + newRfresh := fun _ h => h.elim + newCfresh := fun _ h => h.elim + oldReply := fun rr h => by + obtain ⟨y, e, -⟩ := J.ep.reply rr h + exact ⟨y, e⟩ + link := fun rr h => by + have e16 : rNextA rr = wa rr 16#u64 := by unfold rNextA layout.reply.NEXT; rfl + have e8 : rPrevA rr = wa rr 8#u64 := by unfold rPrevA layout.reply.PREV; rfl + rw [e16, e8] + exact ⟨linkW rr h _ (Or.inr rfl) (Or.inl e16.symm), linkW rr h _ (Or.inl rfl) (Or.inr e8.symm)⟩ + mcpW := fun u h => ⟨tcbW u h 3440#u64 (by simp) (by simp) (by simp) (tW u h _ (Or.inl rfl)), + tcbW u h 3456#u64 (by simp) (by simp) (by simp) + (tW u h _ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr rfl)))))))⟩ + yieldW := fun u h => tcbW u h 3472#u64 (by simp) (by simp) (by simp) (tW u h _ (Or.inr (Or.inl rfl))) + bufW := fun u h => ⟨tcbW u h 3512#u64 (by simp) (by simp) (by simp) + (tW u h _ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))), sbCap u h⟩ + bufSlot := fun u h => by + rw [bufSlot_eqA, capAtA_eq, capAtA_eq] + exact sbCap u h + scOld := fun c h => by + obtain ⟨y, k, e, -⟩ := J.j.1.sch.sc c h + exact ⟨y, k, e⟩ + optSc := fun _ => rfl + scName := fun _ => rfl + curCore := rfl + idleThreadOf := rfl + idleScOf := rfl + affinity := fun _ _ h => Or.inl h + newTcbState := fun _ e => by cases e + newTcbFault := fun _ e => by cases e + newScInactive := fun _ _ e => by cases e + newScNoRep := fun _ _ e => by cases e + newScName := fun _ _ _ _ e => by cases e + irq := irqo + heapN := fun q h => Or.inl (hN q h) + heapE := fun q h => Or.inl (hE q h) + heapR := fun q h => Or.inl (hR q h) } + have ipc := utRt_asmIpcA J Ki + simp only [Set.union_empty, Set.mem_empty_iff_false, if_false] at ipc + -- the buffers' bytes are off the page + have epo : EpStateRel Z.T E Rp Bf (L.mem s') σ' := by + refine ⟨ipc.ep.ep, ipc.ep.reply, ipc.ep.tcb, fun bp hbp k hk => ?_⟩ + obtain ⟨h1, h2⟩ := ipc.ep.buf bp hbp k hk + refine ⟨h1.trans ?_, h2⟩ + show loadWordAt σ.machineState.underlyingMemory _ = loadWordAt σ'.machineState.underlyingMemory _ + symm + refine ut_loadWordAt_congrA fun j hj => ?_ + rcases P.um (bufAddr bp.2 k.val + BitVec.ofNat 64 j) with g | ⟨-, q, e, q1, q2⟩ + · exact g + exfalso + have hbw : BufW Bf (bufW bp.1 k) := ⟨bp, hbp, k, hk, rfl⟩ + have ba : (bufW bp.1 k).val % 8 = 0 := J.iplaced.e.balign _ hbw + have off : ¬ (frame.val ≤ (bufW bp.1 k).val ∧ (bufW bp.1 k).val < frame.val + 4096) := + ut_rd_regionA J clr (Or.inr (Or.inl (Or.inr (Or.inr (Or.inr hbw)))) : + UtRdA st Z N E Rp Bf m s σ (bufW bp.1 k)) + have eb : bufAddr bp.2 k.val = specPtr (bufW bp.1 k) := by + rw [J.bfSpec bp hbp]; exact bufAddr_specPtrWrapA _ _ hk + have fa := (J.sys.sysl.sys.ur x P.mem frame 12#u64 fi false P.cap).1.1 + rw [show (12#u64 : U64).val = 12 from rfl] at fa + rw [eb, specPtr_def, specPtr_def] at e + have e' : (bufW bp.1 k).bv + BitVec.ofNat 64 j = q.bv := by + have : (bufW bp.1 k).bv + BitVec.ofNat 64 j + pptrShiftA = q.bv + pptrShiftA := by + rw [← e]; ac_rfl + exact (BitVec.add_left_inj _).1 this + have en := congrArg BitVec.toNat e' + rw [BitVec.toNat_add, BitVec.toNat_ofNat] at en + change ((bufW bp.1 k).val + j % 2 ^ 64) % 2 ^ 64 = q.val at en + have hub : (bufW bp.1 k).val < 2 ^ 64 := by simpa using (bufW bp.1 k).hBounds + omega + -- the scheduler side + have scK : ∀ c ∈ Z.C, ∀ y k, σ'.kheap (scNameA m c) = some (.schedContext y k) → + σ.kheap (scNameA m c) = some (.schedContext y k) := fun _ _ y k h => bs _ y k h + have step : SStepA σ σ' := + ⟨⟨P.glob.cur, P.glob.csc, P.glob.idle, P.glob.time, P.glob.cons, P.glob.repr, P.glob.dom, P.glob.domT⟩, P.glob.act, P.glob.rq, P.glob.rls, + fun p y k h => (ks p y k h).trans h.symm, fun p y h => ⟨y, kt p y h, rfl, rfl, rfl⟩, + fun p y k h => (bs p y k h).trans h.symm, fun p y h => ⟨y, bt p y h⟩, + fun p y h => by + rcases O.back p _ h (fun _ _ e => by cases e) with g | ⟨-, e⟩ + · exact ⟨y, g, rfl⟩ + · cases e⟩ + have nb : NoBlockESc σ σ' := fun p y z h1 h2 => by + have e := (kt p y h1).symm.trans h2 + cases e + exact Or.inl ⟨rfl, id⟩ + have off : ∀ b, W7.CapW H.tcbs {b | InOS OS b} ∅ b ∨ (frame.val ≤ b.val ∧ b.val < frame.val + 4096) ∨ + b = atAF (L.ksb s) i → Aligned b → SReadA st Z m s σ b → False := by + intro b hw al hs + have wh := ut_rd_whereA J (Or.inl hs : UtRdA st Z N E Rp Bf m s σ b) + have ns : ¬ InOS OS b := by + by_cases hn : b = nwA st s + · have h0 : (0#u64 : U64) ∈ Z.Cs := by + obtain ⟨k, hk, -, h⟩ := J.j.1.csN + exact (h 0#u64).2 (by simpa using hk) + intro g + obtain ⟨⟨Q, R, q⟩, -⟩ := J.sys.ent.bxi + exact capw_ne_node q (inOS_capw J.sys.ent.os al g) h0 (show layout.node.DEBUG_TCBS.val < 4288 by + rw [debug_val]; omega) hn + · exact (utRt_rdOffA J al (Or.inr ⟨hs, hn⟩)).1 + rcases hw with (⟨t, ht, K, hK, e⟩ | ⟨h, -⟩) | h | h + · have ht' : t ∈ Z.T := by rw [← J.tcbs]; exact ht + have f := tf t ht' + have bv : b.val = t.val + K.val := by rw [e, wa_valP]; exact Nat.mod_eq_of_lt (by omega) + have sl : IsSlotA Z.th (slotAddrA (specPtr t) (BitVec.ofNat 64 (K.val / 32))) := + ⟨_, Or.inr ⟨(ut_tcbThA J ht').1, K.val / 32, by simp [tcbSlotsA]; omega, rfl⟩⟩ + have sv : (slotAddrA (specPtr t) (BitVec.ofNat 64 (K.val / 32))).val = t.val + 32 * (K.val / 32) := + slotAddrA_valN (by omega) + exact ns ⟨_, P.sub _ sl, by omega, by omega⟩ + · exact ns h + · exact ut_rd_regionA J clr (Or.inl hs : UtRdA st Z N E Rp Bf m s σ b) h + · exact poolRt_atOffA J P.hi wh h + have srZ := J.sr.stable (s' := s') (σ' := σ') (WritesIn.mono' (B := fun b => (W7.CapW H.tcbs {b | InOS OS b} ∅ b ∨ + (frame.val ≤ b.val ∧ b.val < frame.val + 4096) ∨ b = atAF (L.ksb s) i) ∧ Aligned b) P.w fun _ al h => ⟨h, al⟩) + (fun b h hs => off b h.1 h.2 hs) step nb + have sr : SchedSRA st { Z with th := th', Pp := Pp', G := G' } m κ s' σ' := + ⟨{ srZ.toSchedSRN with + rest := { srZ.rest with } + thT := hthT + place := hpl + scp := ⟨srZ.scp.inj, srZ.scp.disj, fun c hc y k e b hb => by + refine ⟨fun q kd hq => ?_, hks ▸ (J.sr.scp.out c hc y k (scK c hc y k e) b hb).2⟩ + rcases hthN q kd hq with old | ⟨b1, b2⟩ + · exact (J.sr.scp.out c hc y k (scK c hc y k e) b hb).1 q kd old + · have := ut_rd_regionA J clr (Or.inl (Or.inr (Or.inr (Or.inr (Or.inr + ⟨c, hc, y, k, scK c hc y k e, hb⟩)))) : UtRdA st Z N E Rp Bf m s σ b) + omega⟩ }, srZ.rd⟩ + -- VCPU words: off the slots (footprint), the page and the table + have vcK : ∀ y ∈ Z.V, ∀ o : U64, o = 0#u64 ∨ o = 24#u64 → L.mem s' (wa y o) = L.mem s (wa y o) := by + intro y hy o ho + have hf : FootNA (L := L) Z s (wa y o) := by + refine .vcpu y _ hy ?_ + rcases ho with rfl | rfl + · exact Or.inl (wa_zeroVcA y) + · exact Or.inr rfl + have al := FootNA.aligned J.j.1 (bxi_nodes J.sys.ent.bxi) J.toJEntA.scAl J.ap.vcAl _ hf + refine poolRt_memA J P al (fun g => footN_offA J.toJEntA _ hf (Or.inr ⟨g, fun h => h.elim⟩)) + (ut_foot_regionA J clr (.nslot _ hf)) (fun e => ?_) + refine J.toJEntA.vsVc _ (.asid i P.hi) ⟨y, hy, o, ?_, ?_, e.symm⟩ <;> rcases ho with rfl | rfl <;> simp + have vk : ∀ y ∈ Z.V, L.mem s' y = L.mem s y := fun y hy => by + have := vcK y hy 0#u64 (Or.inl rfl) + rwa [wa_zeroVcA] at this + have tvk : ∀ t ∈ Z.T, L.mem s' (wa t 3664#u64) = L.mem s (wa t 3664#u64) := fun t ht => + tcbW t ht 3664#u64 (by simp) (by simp) (by simp) + (tW t ht _ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))) + have runk : ∀ t ∈ Z.T, L.mem s' (runVcpuA t) = L.mem s (runVcpuA t) := fun t ht => by + have hf : FootNA (L := L) Z s (runVcpuA t) := .tcb t _ ht (Or.inr (Or.inr (Or.inr (Or.inr rfl)))) + have al := FootNA.aligned J.j.1 (bxi_nodes J.sys.ent.bxi) J.toJEntA.scAl J.ap.vcAl _ hf + refine poolRt_memA J P al (fun g => footN_offA J.toJEntA _ hf (Or.inr ⟨g, fun h => h.elim⟩)) + (ut_foot_regionA J clr (.nslot _ hf)) (poolRt_atOffA J P.hi ?_) + rw [show runVcpuA t = wa t 3672#u64 from rfl] + exact ut_tcbFieldA J ht (by simp) (by simp) + have stk : ∀ t ∈ Z.T, L.mem s' (stA t) = L.mem s (stA t) := fun t ht => by + have f := foot_st J.iplaced.n ht + exact footN _ f.1 f.2 + have tbk : ∀ t ∈ Z.T, L.mem s' (Notif.tBlockA t) = L.mem s (Notif.tBlockA t) := fun t ht => by + have f := foot_blk J.iplaced.n ht + exact footN _ f.1 f.2 + have vcRun : VcRunA st Z.T Z.V s' := by + constructor + · intro t ht + rw [tvk t ht]; exact J.vcRun.tcb t ht + · intro y hy + rw [vcK y hy 24#u64 (Or.inr rfl)]; exact J.vcRun.vcpu y hy + · intro y hy + rw [vk y hy]; exact J.vcRun.vtcb y hy + · intro t ht + rw [runk t ht]; exact J.vcRun.run t ht + · intro t ht h0 + rw [tvk t ht] at h0 + rw [runk t ht]; exact J.vcRun.disj t ht h0 + have sidleo := utRt_sidleA J.sidle O rfl P.glob.idle + (fun e => by + have g : fl4Ptr Fl4SpecA64.idleScPtr = frame := by rw [e, fl4Ptr_specPtr] + have := P.disj (fl4Ptr Fl4SpecA64.idleScPtr) 4096 (Or.inl ⟨rfl, Or.inr (Or.inr (Or.inr (Or.inr rfl)))⟩) + rw [g] at this + omega) + (fun _ _ e => by cases e) P.newCap + have sched : UtAsmSchedOutA st { Z with th := th', Pp := Pp', G := G' } κ s' σ' m n := + { sr := sr + scCpu := J.scCpu + scNZ := J.scNZ + vcRun := vcRun + sidle := ⟨sidleo.f3, sidleo.f4, sidleo.f5, sidleo.f6, sidleo.f7, sidleo.idleSlot, sidleo.idleBound⟩ + vcSym1 := fun t ht h0 => by + rw [tvk t ht] at h0 ⊢ + rcases J.vcRun.tcb t ht with e | mem + · exact absurd e h0 + · rw [vk _ mem]; exact J.vcSym1 t ht h0 + vcSym2 := fun y hy h0 => by + have e := vcK y hy 24#u64 (Or.inr rfl) + rw [e] at h0 ⊢ + rcases J.vcRun.vcpu y hy with z | mem + · exact absurd z h0 + · rw [runk _ mem]; exact J.vcSym2 y hy h0 + runVcpu := fun t ht h => by + rw [runk t ht] at h + rw [stk t ht] + exact J.runVcpu t ht h } + have blk : BlkQueuedA Z.T E N (L.mem s') σ' := + J.blkQ.keepA tbk (fun t _ y h => Or.inr ⟨y, bt _ _ h, rfl⟩) + (fun p y h => O.keep p _ h (fun _ _ e => by cases e)) (fun p y h => O.keep p _ h (fun _ _ e => by cases e)) + exact ⟨spec, + { ipc with + ep := epo + ntfn := by cases ipc.ntfn; constructor <;> assumption + reply := by cases ipc.reply; constructor <;> assumption + yieldRel := by cases ipc.yieldRel; constructor <;> assumption + sinv := by + cases ipc.sinv + constructor <;> first | exact P.irq | assumption }, + sched, blk⟩ + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolJ5A.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolJ5A.lean new file mode 100644 index 000000000..dfe3fd881 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolJ5A.lean @@ -0,0 +1,274 @@ +/- +P3 (aarch64, Stage 5, line pool, group J5): **J5's MDB facts across `ARMASIDControlMakePool`** (`Stage3J5A`'s `J5A` at the +grown ghost `insG parent dest G` / `insParA par parent dest true`). + +A64 P1 has no `MdbInvA` after MakePool (`J5A.insGenA` needs `Fl4ProofsA64.P1.W7.R.ST.shapeA nc = Fl4ProofsA64.P1.W7.R.ST.shapeA src`, false for Untyped→AsidPool). The perform +tail is a single-object Retype of the whole 4 KiB untyped: the parent `Untyped frame 12 4096` is full and childless and the new +`AsidPool frame base` names its region exactly, so the Retype window facts (`UtJ5LoopA`) are replaced by two region lemmas. + +* **`poolOvA`**: against the pool cap `c` (same region as the source `u`) an old cap reads as against `u` (`hsr_left`), and `c` + is in no region of an old cap that is no ancestor of `u` (`hdest_after`, `hdest_ca`); from `UtInvA.drange/inc/anc/reg` + and `u` childless. +* **`poolJ5_insA`**: `cdt.insert_with_cap (AsidPool ..)` builds P1's `FreshChildCtxA` (`rv = fb = false`) and gives `MdbInvA` and + `IrqRunA` at the grown ghost. +* **`poolJ5_keepA` / `poolJ5_keepEqA`**: `MdbInvA ∧ IrqRunA` across a step that keeps the chain words (the first lets the source + untyped's free index change: `set_cap parent` + `clear_free`). +* **`poolJ5_handlersA`**: `HandlersActiveA` at the grown ghost from the old one, the caps and the IRQ state words. +* **`poolJ5_outA`**: `J5A` of the grown record from the three chain facts and the old `J5A`. + +Named premises: none. New module; no existing statement changed. +-/ +import Fl4ProofsA64.P3.UtJ5LoopA +import Fl4ProofsA64.P3.Stage3CnInsA +import Fl4ProofsA64.P3.Stage3J5A +import Fl4ProofsA64.P1.MdbPoolI +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4ProofsA64.P1 Fl4Proofs.P3 Fl4ProofsA64.P1.W7.R.ST + +local notation "wa" => core.num.U64.wrapping_add + +noncomputable section + +/-- A triple and a conditional triple of one program give the first with the conditional postcondition. -/ +theorem spec_and_impA {α : Type _} {x : Result α} {A B : α → Prop} {P : Prop} (h : x ⦃ r => A r ⦄) + (h2 : P → x ⦃ r => B r ⦄) : x ⦃ r => A r ∧ (P → B r) ⦄ := by + by_cases hp : P + · exact WP.spec_mono (WP.spec_and h (h2 hp)) fun r ⟨a, b⟩ => ⟨a, fun _ => b⟩ + · exact WP.spec_mono h fun r a => ⟨a, fun hp' => absurd hp' hp⟩ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {T Ω Sg OS : Set U64} + +/-- **The pool cap's region is its source untyped's.** -/ +theorem poolRegA (frame base : U64) : + baseA (.AsidPool frame base) = baseA (.Untyped frame 12#u64 4096#u64 false) ∧ + topA (.AsidPool frame base) = topA (.Untyped frame 12#u64 4096#u64 false) := + ⟨by unfold baseA; rw [ptrA_ap, ptrA_ut], + by unfold topA; rw [ptrA_ap, ptrA_ut, sizeA_ap, sizeA_ut]; simp [fl4_abi.consts.bits.ASID_POOL]⟩ + +/-- **An old cap against a cap `c` of the childless source `src`'s region** (module docstring). -/ +theorem poolOvA {par : U64 → Option U64} {s : S} (hU : UtInvA st OS par s) {src a : U64} (hsrc : src ∈ OS) (ha : a ∈ OS) + {p sb fi : U64} {dv : Bool} (hcs : capA st s src = .Untyped p sb fi dv) (hut : ∀ y, ¬ Mdb.Desc par y src) + (hne : a ≠ src) {c : capability.Cap} (hcp : physA c = true) (hb : baseA c = baseA (capA st s src)) + (ht : topA c = topA (capA st s src)) : + sraA (capA st s a) c = sraA (capA st s a) (capA st s src) ∧ + (¬ Mdb.Desc par src a → sraA c (capA st s a) = false) := by + have hps : physA (capA st s src) = true := by rw [hcs]; exact physA_ut _ _ _ _ + have rs := hU.reg src hsrc hps + refine ⟨?_, fun hnd => ?_⟩ + · by_cases hp : physA (capA st s a) = true + swap + · have f : ∀ b, physA b = true → sraA (capA st s a) b = false := fun b hb => by + cases e : sraA (capA st s a) b + · rfl + · exact absurd ((utJ5_sraPhysA e).trans hb) hp + rw [f c hcp, f _ hps] + have ra := hU.reg a ha hp + by_cases dj : DisjA (capA st s a) (capA st s src) + · have f : ∀ b, physA b = true → baseA b = baseA (capA st s src) → topA b = topA (capA st s src) → + sraA (capA st s a) b = false := fun b hb hbb htb => by + cases e : sraA (capA st s a) b + · rfl + · exfalso + have m := utJ5_sraMeetA e hb + unfold DisjA at dj + rcases m with m | m <;> omega + rw [f c hcp hb ht, f _ hps rfl rfl] + · rcases hU.drange src hsrc p sb fi dv hcs a ha hne hp dj with d | d + · exact absurd d (hut a) + · have ut : isUtA (capA st s a) = true := hU.anc a src d (by rw [hcs]; rfl) + obtain ⟨q, qb, qi, qd, e⟩ : ∃ q qb qi qd, capA st s a = .Untyped q qb qi qd := by + revert ut; cases capA st s a <;> simp [isUtA] + obtain ⟨-, i1, i2⟩ := hU.inc a ha q qb qi qd e src d + have fib := hU.fib a ha q qb qi qd e + have ra' := ra; rw [e] at ra' + obtain ⟨r1, r2, -⟩ := ut_rangeA (capA_ut_b e) ra' + have f1 : sraA (.Untyped q qb qi qd) c = true := utJ5_sraUtOfA hcp (by omega) (by omega) (by omega) + have f2 : sraA (.Untyped q qb qi qd) (capA st s src) = true := + utJ5_sraUtOfA hps (by omega) (by omega) (by omega) + rw [e, f1, f2] + · cases e : sraA c (capA st s a) + · rfl + · exfalso + have hpa : physA (capA st s a) = true := (utJ5_sraPhysA e).symm.trans hcp + have ra := hU.reg a ha hpa + have m := utJ5_sraMeetA e hpa + have dj : ¬ DisjA (capA st s a) (capA st s src) := by unfold DisjA; rcases m with m | m <;> omega + rcases hU.drange src hsrc p sb fi dv hcs a ha hne hpa dj with d | d + · exact hut a d + · exact hnd d + +set_option maxHeartbeats 4000000 in +/-- **`insert_with_cap` of the pool cap under the full childless source keeps `MdbInvA` and `IrqRunA`** (module docstring). -/ +theorem poolJ5_insA (hO : OSOK T Ω Sg OS) {G : List (List U64)} {par : U64 → Option U64} {s : S} + (hT : TreeA st OS G par s) (hI : MdbInvA st G par s) (hR : Fl4ProofsA64.P1.W7.R.ST.IrqRunA st G s) {src dest frame base : U64} + (hsrc : src ∈ OS) (hd : dest ∈ OS) (hcs : capA st s src = .Untyped frame 12#u64 4096#u64 false) + (hcd : capA st s dest = .Null) (hdc : obj.sext48 dest = ok dest) (hw : CapRt.EncWf (.AsidPool frame base)) + (hrev : Fl4ProofsA64.P1.W7.R.ST.revA st s src = true) (hut : ∀ y, ¬ Mdb.Desc par y src) : + cdt.insert_with_cap st s (.AsidPool frame base) (capA st s src) src dest ⦃ s' => + MdbInvA st (insG src dest G) (insParA par src dest true) s' ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st (insG src dest G) s' ∧ + (∀ y ∈ OS, y ≠ dest → capA st s' y = capA st s y) ∧ capA st s' dest = .AsidPool frame base ⦄ := by + have F := hT.lk.lkF hO.nz + have inOS : ∀ y ∈ G.flatten, y ∈ OS := fun y hy => ((hT.lk.members y).1 hy).1 + have hs0 : capA st s src ≠ .Null := by rw [hcs]; intro h; cases h + have hsG : src ∈ G.flatten := (hT.lk.members _).2 ⟨hsrc, hs0⟩ + have dG : dest ∉ G.flatten := fun hm => ((hT.lk.members _).1 hm).2 hcd + have hsd : src ≠ dest := fun e => dG (e ▸ hsG) + have hN : NxA st s src ≠ 0#u64 → NxA st s src ∈ OS := fun h => inOS _ (F.nxm _ hsG h) + have hnf0 : ¬ FullCondA (capA st s src) (.AsidPool frame base) := by + rw [hcs]; unfold FullCondA; simp + have hps : physA (capA st s src) = true := by rw [hcs]; exact physA_ut _ _ _ _ + have rs := hT.ut.reg src hsrc hps + obtain ⟨rb, rt⟩ := poolRegA frame base + have rb' : baseA (.AsidPool frame base) = baseA (capA st s src) := by rw [hcs]; exact rb + have rt' : topA (.AsidPool frame base) = topA (capA st s src) := by rw [hcs]; exact rt + have rsU : baseA (.Untyped frame 12#u64 4096#u64 false) ≤ topA (.Untyped frame 12#u64 4096#u64 false) := by + have := rs; rwa [hcs] at this + have h1 : sraA (.Untyped frame 12#u64 4096#u64 false) (.AsidPool frame base) = true := + utJ5_sraUtOfA (physA_ap frame base) (by rw [rb]; unfold baseA; rw [ptrA_ut]) rt.le (by rw [rb, rt]; exact rsU) + refine WP.spec_mono (WP.spec_and (WP.spec_and + (cdt.insert_with_cap.lr hO (LR.self s) hsrc hd hsd hdc rfl hs0 hw hN) + (insWC_walkA hO hsrc hd hsd rfl hw hN)) (insWC_bitsA hO hsrc hd hsd rfl hw hN)) ?_ + rintro s' ⟨⟨⟨hL, ed, -, -, ek, -⟩, -, -, -, hnf⟩, hbk, hrd, hfd⟩ + have hkAll : ∀ y ∈ OS, y ≠ dest → capA st s' y = capA st s y := fun y hy hyd => by + by_cases hys : y = src + · subst hys; exact hnf hnf0 + · exact ek y hy hys hyd + have capK : ∀ a ∈ G.flatten, capA st s' a = capA st s a := fun a ha => hkAll a (inOS a ha) (fun e => dG (e ▸ ha)) + have nm : ∀ ch ∈ G, ∀ A B : List U64, ch = A ++ src :: B → ∀ v ∈ B, srMA st s' dest v = false := by + intro ch hch A B e v hv + obtain ⟨vs, va⟩ := utJ5_afterNotAncA hT.tree hch e hv + have vm : v ∈ G.flatten := List.mem_flatten.2 ⟨ch, hch, by rw [e]; exact List.mem_append_right _ (List.mem_cons_of_mem _ hv)⟩ + unfold srMA + rw [ed, capK v vm] + exact (poolOvA hT.ut hsrc (inOS v vm) hcs hut vs (physA_ap frame base) rb' rt').2 va + have C : FreshChildCtxA st OS G par s s' src dest (.AsidPool frame base) (capA st s src) false false := + { hM := hT.lk, hOk := hT.tree, hI := hI, hsrc := hsG, hdest := dG, hsrc_rev := hrev + hsrc_nb := by rw [hcs]; rfl, hsh1 := rfl, hbd1 := rfl, hc_nb := rfl + hc_ut := fun h => by simp [isUtA] at h + hc_self := fun _ => by apply sraA_of_eq; simp [objects.same_region_as] + hc_in_src := by rw [hcs]; exact h1 + hsr_left := fun a ha => by + unfold srMA + by_cases e : a = src + · subst e + rw [hcs, h1] + exact (sraA_self h1 4096#u64 false).symm + · exact (poolOvA hT.ut hsrc (inOS a ha) hcs hut e (physA_ap frame base) rb' rt').1 + hanc_nb := fun a ha d => by + have ut : isUtA (capA st s a) = true := hT.ut.anc a src d (by rw [hcs]; rfl) + revert ut; cases capA st s a <;> simp [isUtA, isBadgedA] + hdest_after := fun _ => by simp [isPFA] + hdest_ca := fun ch hch A B e => by + have ca : ∀ l : List U64, (∀ v ∈ l, v ∈ B) → Mdb.CA (srFA st s') dest l := by + intro l + induction l with + | nil => intro _; trivial + | cons v l ih => + intro sub + refine ⟨fun h0 x hx => ?_, ih fun y hy => sub y (List.mem_cons_of_mem _ hy)⟩ + have n1 := nm ch hch A B e v (sub v List.mem_cons_self) + have n2 := nm ch hch A B e x (sub x (List.mem_cons_of_mem _ hx)) + unfold srFA at h0 ⊢ + rw [n1] at h0 + rw [n2] + exact h0 + exact ca B fun _ h => h + hnext := fun a ha => by + have aOS : a ∈ OS := ha.elim (fun e => e ▸ hd) (inOS a) + rw [show NxA st s' a = _ from (hL a aOS).2] + by_cases ad : a = dest + · subst ad; simp [hsd.symm] + · simp [ad] + hcap := fun a ha => by + by_cases ad : a = dest + · subst ad; simp [ed] + · have am := ha.resolve_left ad + rw [ite_eq_right ad, capK a am] + by_cases asr : a = src + · rw [ite_eq_left asr, asr] + · rw [ite_eq_right asr] + hrev := fun a ha => by + by_cases ad : a = dest + · subst ad; rw [ite_eq_left rfl, hrd]; rfl + · rw [ite_eq_right ad, (hbk a (ha.elim (fun e => absurd e ad) (inOS a)) ad).1] + hfb := fun a ha => by + by_cases ad : a = dest + · subst ad; rw [ite_eq_left rfl, hfd]; rfl + · rw [ite_eq_right ad, (hbk a (ha.elim (fun e => absurd e ad) (inOS a)) ad).2] } + refine ⟨C.inv, ?_, hkAll, ed⟩ + exact Fl4ProofsA64.P1.W7.R.ST.IrqRunA.ins hR hT.lk.nodup hsG dG (fun y hy i => by rw [capK y hy]) + (fun i h => by rw [ed] at h; cases h) (fun i h => by rw [hcs] at h; cases h) + +/-- **`MdbInvA ∧ IrqRunA` across a step that keeps the chain words** (the cap shapes and badges, the `+24` words (next, flags) +and the IRQ handler caps of every member). -/ +theorem poolJ5_keepCoreA {G : List (List U64)} {par : U64 → Option U64} {s s' : S} (hM : MdbLk st OS G s) + (hOk : Mdb.MdbOK par G) (hI : MdbInvA st G par s) (hR : Fl4ProofsA64.P1.W7.R.ST.IrqRunA st G s) + (hsh : ∀ x ∈ G.flatten, Fl4ProofsA64.P1.W7.R.ST.shapeA (capA st s' x) = Fl4ProofsA64.P1.W7.R.ST.shapeA (capA st s x)) + (hbd : ∀ x ∈ G.flatten, badgeA (capA st s' x) = badgeA (capA st s x)) + (hirq : ∀ y ∈ G.flatten, ∀ i, capA st s' y = .IrqHandler i ↔ capA st s y = .IrqHandler i) + (h24 : ∀ y ∈ G.flatten, L.mem s' (wa y 24#u64) = L.mem s (wa y 24#u64)) : + MdbInvA st G par s' ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st G s' := + ⟨MdbInvA.recap_alike hM hOk hI hsh hbd (fun y hy => by unfold NxA; rw [h24 y hy]) + (fun y hy => revA_congr (h24 y hy)) (fun y hy => fbA_congr (h24 y hy)), hR.keepIrq hirq⟩ + +/-- **`MdbInvA ∧ IrqRunA` from `s` to `s3`** (`set_cap parent` + `clear_free`: every member but the source keeps its cap, the +source stays an `Untyped` with a new free index). -/ +theorem poolJ5_keepA {G : List (List U64)} {par : U64 → Option U64} {s s' : S} (hM : MdbLk st OS G s) + (hOk : Mdb.MdbOK par G) (hI : MdbInvA st G par s) (hR : Fl4ProofsA64.P1.W7.R.ST.IrqRunA st G s) {src p sb i i' : U64} {d d' : Bool} + (hcap : ∀ y ∈ G.flatten, y ≠ src → capA st s' y = capA st s y) + (hs : capA st s src = .Untyped p sb i d) (hs' : capA st s' src = .Untyped p sb i' d') + (h24 : ∀ y ∈ G.flatten, L.mem s' (wa y 24#u64) = L.mem s (wa y 24#u64)) : + MdbInvA st G par s' ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st G s' := by + refine poolJ5_keepCoreA hM hOk hI hR (fun x hx => ?_) (fun x hx => ?_) (fun y hy k => ?_) h24 + · by_cases e : x = src + · subst e; rw [hs, hs']; rfl + · rw [hcap x hx e] + · by_cases e : x = src + · subst e; rw [hs, hs']; rfl + · rw [hcap x hx e] + · by_cases e : y = src + · subst e; rw [hs, hs']; exact ⟨(fun h => by cases h), (fun h => by cases h)⟩ + · rw [hcap y hy e] + +/-- **`MdbInvA ∧ IrqRunA` across a step that keeps every member's cap** (`set_asid_table`). -/ +theorem poolJ5_keepEqA {G : List (List U64)} {par : U64 → Option U64} {s s' : S} (hM : MdbLk st OS G s) + (hOk : Mdb.MdbOK par G) (hI : MdbInvA st G par s) (hR : Fl4ProofsA64.P1.W7.R.ST.IrqRunA st G s) + (hcap : ∀ y ∈ G.flatten, capA st s' y = capA st s y) + (h24 : ∀ y ∈ G.flatten, L.mem s' (wa y 24#u64) = L.mem s (wa y 24#u64)) : + MdbInvA st G par s' ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st G s' := + poolJ5_keepCoreA hM hOk hI hR (fun x hx => by rw [hcap x hx]) (fun x hx => by rw [hcap x hx]) + (fun y hy i => by rw [hcap y hy]) h24 + +/-- **`HandlersActiveA` at the grown chains**: the pool cap is no handler, the old members keep their handler caps and the IRQ +state words of the old state. -/ +theorem poolJ5_handlersA {G : List (List U64)} {s s' : S} (h : HandlersActiveA st G s) {src dest frame base : U64} + (hsrc : src ∈ G.flatten) (hk : ∀ y ∈ G.flatten, ∀ i, capA st s' y = .IrqHandler i → capA st s y = .IrqHandler i) + (hd : capA st s' dest = .AsidPool frame base) (hks : L.ksb s' = L.ksb s) + (hst : ∀ i : U64, i.val < 5376 → L.mem s' (irqStAddrA (L.ksb s) i) = L.mem s (irqStAddrA (L.ksb s) i)) : + HandlersActiveA st (insG src dest G) s' := + h.ins_derived hsrc hk (fun i e => by rw [hd] at e; cases e) hks hst + +end + +section out +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] + +/-- **`J5A` of the grown record**: the three chain facts at the grown ghost, and the old `J5A`'s slot clauses (the slots of the +spec heap are `OS'` slots, the non-slots of `OS'` hold null caps: the old ones, the parent and destination being slots). -/ +theorem poolJ5_outA {Z Zn : XSetsA} {H Hn : Heap} {OS OS' : Set U64} {s s5 : S} {σ σ' : Fl4SpecA64.State Unit} + {m m' : Fl4SpecA64.McState} (J : J5A st Z H OS s σ m) (hth : Zn.th = Z.th) + (hc : MdbInvA st Zn.G.chains Zn.G.par s5 ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Zn.G.chains s5 ∧ HandlersActiveA st Zn.G.chains s5) + (hsub : OS' ⊆ OS) (hsl : ∀ y, IsSlotA Z.th y → y ∈ OS') + (hcap : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s5 y = capA st s y) : + J5A st Zn Hn OS' s5 σ' m' := + ⟨hc, fun y hy => by rw [hth] at hy; exact hsl y hy, + fun y hy hn => by rw [hth] at hn; rw [hcap y (hsub hy) hn]; exact J.2.2 y (hsub hy) hn⟩ + +end out + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolJ7A.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolJ7A.lean new file mode 100644 index 000000000..0f03594de --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolJ7A.lean @@ -0,0 +1,342 @@ +/- +P3 (aarch64, Stage 5, line pool, group C): **`J7A` over the pool heap**, the P3-only part of the MakePool record lift. + +A64 P1's MakePool end facts (`S1aArmCol.poolEnd`, `DevFrAl.poolEnd`, `PoolPost.hiCap511`, `S1aR2.addPool`, `CapInv.poolEnd`) +are functions of the old `J7A` witnesses `Pt`, `Ub` (they live at the undropped heap `H0` and decode state `s0`); they are +bundled in `PoolJ7EndA Pt Ub`. The assembler builds them from the old record: + + `E : ∀ Pt Ub, J7BodyA … Z0 H0 OS0 s0 σ0 m0 Pt Ub → PoolJ7EndA … Pt Ub` + +(`col` := `S1aArmCol.poolEnd` at the old `S1aArmCol`, `pools` := `ArmQIEnd.2.2.2.2.2.1`, `vcc` := `ArmQIEnd.2.2.2.1`, +`dev` := `DevFrAl.poolEnd`, `hi` := `PoolPost.hiCap511`, `frub` := `CapInv.poolEnd` at `FrUbP` (trivial on `AsidPool` and +`Untyped`), `r2` := `S1aR2.addPool` / `makePoolEndR2`'s `S1aR2` and `S1aKtUt` with `S1aHiK` from `S1aHiK.keep`). + +Proved here: `J7A` at the grown record `Zn`, pool heap `PoolH Hd frame 12`, slots `OS'`, end state `s5`, for the witnesses +`Pt' = insert frame (s1aKeptPt Hd Pt)`, `Ub' = Ub ∩ FrameWords st OS' s5`. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3PoolCoreA +import Fl4ProofsA64.P3.Stage3PoolSysA +import Fl4ProofsA64.P1.S1aDevFr +import Fl4ProofsA64.P1.S1aR2Restrict +import Fl4ProofsA64.P1.MdbPoolT +import Fl4ProofsA64.P1.S1aKeep +import Fl4ProofsA64.P1.MdbFrUb +import Fl4ProofsA64.P1.S1aStepFix + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4SpecA64 Classical + +local notation "wa" => core.num.U64.wrapping_add + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +/-- **The body of `J7A`** at witnesses `Pt`, `Ub` (`J7A` is `∃ Pt Ub, J7BodyA …`). -/ +def J7BodyA (st : machine.Store S) [L : LawfulStore st] (R : Set U64 → JSlotA S) (Z : XSetsA) (H : Heap) + (OS : Set U64) (s : S) (σ : Fl4SpecA64.State Unit) (m : Fl4SpecA64.McState) (Pt Ub : Set U64) : Prop := + VrOK H.omega H.frame H.scs H.scBits OS Z.V Ub (L.ksb s) Pt ∧ PoolNamed st OS s ∧ + S1aArmCol st H Z.Cs OS Z.V Ub s ∧ S1aCapCol st H OS Ub s ∧ VcCap st Z.V OS s ∧ DevFrAl st OS s ∧ + HiCap511 st OS s ∧ (∀ p, SchedPageA st Z OS s p → p ∈ Pt) ∧ + (∀ b, VcW Z.V b → ∀ o : U64, o.val < 223488 → wa (L.ksb s) o ≠ b) ∧ + FrUb st Ub OS s ∧ (∀ b ∈ Ub, Aligned b) ∧ (∀ b, VcW Z.V b → b ∉ Ub) ∧ R Pt Z H OS s σ m + +theorem J7A.iff_body {R : Set U64 → JSlotA S} {Z : XSetsA} {H : Heap} {OS : Set U64} {s : S} + {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} : + J7A st R Z H OS s σ m ↔ ∃ Pt Ub, J7BodyA st R Z H OS s σ m Pt Ub := Iff.rfl + +/-- **A64 P1's MakePool end facts** at the old witnesses `Pt`, `Ub` (module docstring). `Z0` is the undropped record +(its `Cs`, `V`), `Hd` the dropped heap, `OS'` the grown slots, `s5` the end state. -/ +structure PoolJ7EndA (st : machine.Store S) [L : LawfulStore st] {A : Type} (ar : machine.Arch A) (nA : U64) + (Z0 Zn : XSetsA) (Hd : Heap) (frame : U64) (OS' : Set U64) (s5 : S) (σ' : Fl4SpecA64.State Unit) + (m' : Fl4SpecA64.McState) (Pt Ub : Set U64) : Prop where + col : S1aArmCol st (PoolH Hd frame 12) Z0.Cs OS' Z0.V Ub s5 + pools : PoolNamed st OS' s5 + vcc : VcCap st Zn.V OS' s5 + asw : ∀ b, AsW (L.ksb s5) b → b ∈ (PoolH Hd frame 12).omega ∧ b ∉ (PoolH Hd frame 12).frame + dev : DevFrAl st OS' s5 + hi : HiCap511 st OS' s5 + frub : FrUb st Ub OS' s5 + r2 : J7R2A st ar nA (insert frame (s1aKeptPt Hd Pt)) Zn (PoolH Hd frame 12) OS' s5 σ' m' + +end + +section heap +variable {Hd : Heap} {frame : U64} + +theorem poolHE_inv {q : U64} {k : HKind} (h : PoolH Hd frame 12 q = some k) : + (q = frame ∧ k = .other 12) ∨ Hd q = some k := by + rcases Heap.add_eq_some.1 h with ⟨e, e2⟩ | ⟨-, e⟩ + · exact Or.inl ⟨e, e2⟩ + · exact Or.inr e + +theorem poolHE_old (off : ∀ q k, Hd q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) + {q : U64} {k : HKind} (h : Hd q = some k) : PoolH Hd frame 12 q = some k := by + have nf : q ≠ frame := fun e => by + have := Nat.two_pow_pos k.bits + rcases off q k h with g | g <;> rw [e] at g <;> omega + exact (Heap.add_of_not (N := (· = frame)) nf).trans h + +theorem poolHE_pool : PoolH Hd frame 12 frame = some (.other 12) := Heap.add_of_mem rfl + +/-- The pool heap's reply / SC / notification objects are the dropped heap's. -/ +theorem poolHE_frame {b : U64} (h : b ∈ (PoolH Hd frame 12).frame) : b ∈ Hd.frame := by + obtain ⟨al, p, k, hp, hk, hin⟩ := h + refine ⟨al, p, k, ?_, hk, hin⟩ + rcases poolHE_inv hp with ⟨-, rfl⟩ | e + · rcases hk with h | ⟨z, h⟩ | ⟨h, -⟩ <;> cases h + · exact e + +theorem poolHE_scs {c : U64} (h : c ∈ (PoolH Hd frame 12).scs) : c ∈ Hd.scs ∧ + (PoolH Hd frame 12).scBits c = Hd.scBits c := by + obtain ⟨z, hz⟩ := h + rcases poolHE_inv hz with ⟨-, h⟩ | e + · cases h + · refine ⟨⟨z, e⟩, ?_⟩ + unfold Heap.scBits + rw [hz, e] + +theorem poolHE_omega {b : U64} (h : b ∈ Hd.omega) + (off : ∀ q k, Hd q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) : + b ∈ (PoolH Hd frame 12).omega := by + obtain ⟨al, p, k, hp, hk, hin⟩ := h + exact ⟨al, p, k, poolHE_old off hp, hk, hin⟩ + +end heap + +section vr +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {H0 Hd : Heap} {OS0 OS' Vc Vc0 Ub Pt : Set U64} {frame kb : U64} + +/-- **`VrOK` over the pool heap** at the new footprint `insert frame (s1aKeptPt Hd Pt)` (module docstring). -/ +theorem poolVrOK {s5 : S} (hH : HeapOK Hd) (hHE : HeapOK (PoolH Hd frame 12)) + (hdr : ∀ q k, Hd q = some k → H0 q = some k) + (off : ∀ q k, Hd q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) + (osOff : ∀ y ∈ OS', y.val + 32 ≤ frame.val ∨ frame.val + 4096 ≤ y.val) + (hOS : OS' ⊆ OS0) (hV : Vc ⊆ Vc0) + (hks : kb.val + 788736 ≤ frame.val ∨ frame.val + 4096 ≤ kb.val) (hkw : kb.val + 788736 ≤ 2 ^ 64) + (vr : VrOK H0.omega H0.frame H0.scs H0.scBits OS0 Vc0 Ub kb Pt) + (hVp : ∀ v ∈ Vc, ∃ q z, Hd q = some (.other z) ∧ q.val ≤ v.val ∧ v.val + 4096 ≤ q.val + 2 ^ z) + (hUbP : ∀ b ∈ Ub, ¬ (frame.val ≤ b.val ∧ b.val < frame.val + 4096)) + (hAs : ∀ b, AsW kb b → b ∈ (PoolH Hd frame 12).omega ∧ b ∉ (PoolH Hd frame 12).frame) : + VrOK (PoolH Hd frame 12).omega (PoolH Hd frame 12).frame (PoolH Hd frame 12).scs (PoolH Hd frame 12).scBits OS' Vc + (Ub ∩ FrameWords st OS' s5) kb (insert frame (s1aKeptPt Hd Pt)) := by + have fits := hHE.fits frame (.other 12) poolHE_pool + have al12 := hHE.align frame (.other 12) poolHE_pool + simp only [HKind.bits] at fits al12 + -- classification of a footprint word + have cls : ∀ b, VsR kb (insert frame (s1aKeptPt Hd Pt)) b → + (frame.val ≤ b.val ∧ b.val < frame.val + 4096 ∧ Aligned b) ∨ (VsR kb Pt b ∧ + (AsW kb b ∨ ∃ q z, Hd q = some (.other z) ∧ q.val ≤ b.val ∧ b.val < q.val + 2 ^ z)) := by + intro b hb + rcases hb with ⟨p, hp, o, ho, ho8, rfl⟩ | hb + · rcases hp with rfl | ⟨hpt, hg⟩ + · have v : (wa p o).val = p.val + o.val := wadd_val (by omega) + refine Or.inl ⟨by omega, by omega, ?_⟩ + unfold Aligned + rw [v] + omega + · obtain ⟨-, q, z, hq, h1, h2⟩ := hg p rfl + have hf := hH.fits q _ hq + try simp only [HKind.bits] at hf + have v : (wa p o).val = p.val + o.val := wadd_val (by omega) + exact Or.inr ⟨Or.inl ⟨p, hpt, o, ho, ho8, rfl⟩, Or.inr ⟨q, z, hq, by omega, by omega⟩⟩ + · exact Or.inr ⟨Or.inr hb, Or.inl hb⟩ + have old : ∀ b, VsR kb (insert frame (s1aKeptPt Hd Pt)) b → ¬ (frame.val ≤ b.val ∧ b.val < frame.val + 4096) → + VsR kb Pt b := by + intro b hb nb + rcases cls b hb with ⟨h1, h2, -⟩ | ⟨h, -⟩ + · exact absurd ⟨h1, h2⟩ nb + · exact h + refine ⟨fun b hb => ?_, fun b hb => ?_, fun b hb => ?_, fun b hb => ?_, fun b hb => ?_, fun b hb => ?_, + fun b hb => ?_, fun b hb => ?_⟩ + · rcases cls b hb with ⟨-, -, a⟩ | ⟨h, -⟩ + · exact a + · exact vr.al b h + · rcases cls b hb with ⟨h1, h2, a⟩ | ⟨h, hh⟩ + · exact ⟨a, frame, .other 12, poolHE_pool, Or.inr (Or.inr (Or.inl ⟨12, rfl⟩)), + ⟨h1, by simp only [HKind.bits]; omega⟩⟩ + · rcases hh with ha | ⟨q, z, hq, h1, h2⟩ + · exact (hAs b ha).1 + · exact ⟨vr.al b h, q, .other z, poolHE_old off hq, Or.inr (Or.inr (Or.inl ⟨z, rfl⟩)), ⟨h1, h2⟩⟩ + · rcases cls b hb with ⟨h1, h2, a⟩ | ⟨h, hh⟩ + · rintro ⟨-, p, k, hp, hk, hin⟩ + rcases poolHE_inv hp with ⟨-, rfl⟩ | e + · rcases hk with h | ⟨z, h⟩ | ⟨h, -⟩ <;> cases h + · rcases off p k e with g | g <;> simp only [InObj] at hin <;> omega + · intro hf + rcases hh with ha | _ + · exact (hAs b ha).2 hf + · exact vr.sg b h (by + obtain ⟨-, p, k, hp, hk, hin⟩ := poolHE_frame hf + exact ⟨vr.al b h, p, k, hdr p k hp, hk, hin⟩) + · intro c hc hin + obtain ⟨hc0, hbits⟩ := poolHE_scs hc + rcases cls b hb with ⟨h1, h2, a⟩ | ⟨h, hh⟩ + · obtain ⟨z, hz⟩ := hc + rcases poolHE_inv hz with ⟨-, e⟩ | e + · cases e + · rcases off c _ e with g | g <;> (try simp only [HKind.bits] at g) <;> + simp only [InSC, Heap.scBits, hz] at hin <;> omega + · obtain ⟨z, hz⟩ := hc0 + have e0 : H0.scBits c = z := by + unfold Heap.scBits + rw [hdr c _ hz] + have eE : (PoolH Hd frame 12).scBits c = z := by + unfold Heap.scBits + rw [poolHE_old off hz] + refine vr.sc b h c ⟨z, hdr c _ hz⟩ ?_ + rw [e0] + rw [eE] at hin + exact hin + · rintro ⟨y, hy, h1, h2⟩ + rcases cls b hb with ⟨g1, g2, a⟩ | ⟨h, hh⟩ + · rcases osOff y hy with g | g <;> omega + · exact vr.os b h ⟨y, hOS hy, h1, h2⟩ + · intro hv + rcases cls b hb with ⟨g1, g2, a⟩ | ⟨h, hh⟩ + · obtain ⟨v, hvV, o, ho, ho8, e⟩ := hv + obtain ⟨q, z, hq, h1, h2⟩ := hVp v hvV + have hf := hH.fits q _ hq + try simp only [HKind.bits] at hf + have hv' : b.val = v.val + o.val := by rw [e]; exact wadd_val (by omega) + rcases off q _ hq with g | g <;> (try simp only [HKind.bits] at g) <;> omega + · exact vr.vc b h (by obtain ⟨v, hvV, o, ho, ho8, e⟩ := hv; exact ⟨v, hV hvV, o, ho, ho8, e⟩) + · intro hu + rcases cls b hb with ⟨g1, g2, a⟩ | ⟨h, hh⟩ + · exact hUbP b hu.1 ⟨g1, g2⟩ + · exact vr.ub b h hu.1 + · intro o ho e + rcases cls b hb with ⟨g1, g2, a⟩ | ⟨h, hh⟩ + · have v : (wa kb o).val = kb.val + o.val := wadd_val (by omega) + rw [e] at v + rcases hks with g | g <;> omega + · exact vr.ks b h o ho e + +end vr + + +section sched +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {Z0 Zd Zn : XSetsA} {Hd H1 : Heap} {OS0 OS' Pt Pp1 Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {frame : U64} {s0 s5 : S} {n : U64} + +/-- **`SchedPageA ⊆ Pt'` over the grown record** (module docstring): the dropped record's pages by the old +`SchedPageA ⊆ Pt` and `SetsInHA`, the cap-named pages by the end `S1aR2`. -/ +theorem poolSched (hHd : HeapOK Hd) (SI : SetsInHA Zd Hd) (hZn : Zn.Pp = insert frame Zd.Pp ∧ Zn.S1 = Zd.S1 ∧ + Zn.T2 = Zd.T2 ∧ Zn.X = Zd.X ∧ Zn.Y = Zd.Y) + (hPp : Zd.Pp ⊆ Z0.Pp) (hS1 : Zd.S1 ⊆ Z0.S1) (hT2 : Zd.T2 ⊆ Z0.T2) (hX : Zd.X ⊆ Z0.X) (hY : Zd.Y ⊆ Z0.Y) + (sched0 : ∀ p, SchedPageA st Z0 OS0 s0 p → p ∈ Pt) (hal0 : ∀ p ∈ Pt, p.val % 4096 = 0) + (R : S1aR2 st (PoolH Hd frame 12) OS' (insert frame (s1aKeptPt Hd Pt)) Pp1 Tb Hr Te Kt Lv Re bits n s5) : + ∀ p, SchedPageA st Zn OS' s5 p → p ∈ insert frame (s1aKeptPt Hd Pt) := by + obtain ⟨ePp, eS1, eT2, eX, eY⟩ := hZn + have kept : ∀ p, SchedPageA st Z0 OS0 s0 p → + (∃ q z, Hd q = some (.other z) ∧ q.val ≤ p.val ∧ p.val + 4096 ≤ q.val + 2 ^ z) → + p ∈ insert frame (s1aKeptPt Hd Pt) := fun p hp ⟨q, z, hq, h1, h2⟩ => + Or.inr ⟨sched0 p hp, fun t ht => by + have e : t = p := ht + rw [e] + exact ⟨hal0 _ (sched0 p hp), q, z, hq, h1, h2⟩⟩ + have root : ∀ r ∈ Zd.X ∪ Zd.Y, ∃ q z, Hd q = some (.other z) ∧ q.val ≤ r.val ∧ r.val + 8192 ≤ q.val + 2 ^ z := + SI.roots + intro p hp + rcases hp with h | h | h | h | ⟨r, hr, rfl⟩ | h | ⟨y, hy, rfl⟩ | ⟨u, hu, hc⟩ + · rw [ePp] at h + rcases h with rfl | h + · exact Or.inl rfl + · exact kept p (Or.inl (hPp h)) (SI.pages p (Or.inl (Or.inl (Or.inl h)))) + · rw [eS1] at h + exact kept p (Or.inr (Or.inl (hS1 h))) (SI.pages p (Or.inl (Or.inl (Or.inr h)))) + · rw [eT2] at h + exact kept p (Or.inr (Or.inr (Or.inl (hT2 h)))) (SI.pages p (Or.inl (Or.inr h))) + · rw [eX] at h + obtain ⟨q, z, hq, h1, h2⟩ := root p (Or.inl h) + exact kept p (Or.inr (Or.inr (Or.inr (Or.inl (hX h))))) ⟨q, z, hq, h1, by omega⟩ + · rw [eX] at hr + obtain ⟨q, z, hq, h1, h2⟩ := root r (Or.inl hr) + have hf := hHd.fits q _ hq + try simp only [HKind.bits] at hf + have v : (wa r 4096#u64).val = r.val + 4096 := wadd_val (by show r.val + 4096 < 2 ^ 64; omega) + exact kept _ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨r, hX hr, rfl⟩))))) ⟨q, z, hq, by omega, by omega⟩ + · rw [eY] at h + obtain ⟨q, z, hq, h1, h2⟩ := root p (Or.inr h) + exact kept p (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl (hY h))))))) ⟨q, z, hq, h1, by omega⟩ + · rw [eY] at hy + obtain ⟨q, z, hq, h1, h2⟩ := root y (Or.inr hy) + have hf := hHd.fits q _ hq + try simp only [HKind.bits] at hf + have v : (wa y 4096#u64).val = y.val + 4096 := wadd_val (by show y.val + 4096 < 2 ^ 64; omega) + exact kept _ (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨y, hY hy, rfl⟩))))))) ⟨q, z, hq, by omega, by omega⟩ + · rcases hc with ⟨m, a, v, hc⟩ | ⟨m, a, hc⟩ | ⟨a, v, hc⟩ | ⟨q, a, v, hc, rfl⟩ | ⟨y, a, hc, rfl⟩ + · exact R.pageTables u hu p m a v hc + · exact (R.nativeRoots u hu p m a hc).2 + · exact (R.eptRoots u hu p _ _ a v hc).2 ⟨p, rfl, Or.inl rfl⟩ + · exact (R.eptRoots u hu q _ _ a v hc).2 ⟨q, rfl, Or.inr ⟨rfl, rfl⟩⟩ + · have yh : y ∈ Hr := by + rw [R.highRoots] + exact ⟨u, hu, _, a, hc⟩ + exact R.highFootprint ⟨y, yh, Or.inr ⟨rfl, rfl⟩⟩ + +end sched + + +section top +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +theorem VcW.monoA {V V' : Set U64} (h : V ⊆ V') {b : U64} (hb : VcW V b) : VcW V' b := + let ⟨v, hv, o, ho, ho8, e⟩ := hb + ⟨v, h hv, o, ho, ho8, e⟩ + +/-- **`J7A` over the pool heap** (module docstring). `E` is the transformer from the old witnesses to A64 P1's end +facts (`PoolJ7EndA`), built by the assembler from the undropped record. -/ +theorem poolJ7A {nA : U64} {Z0 Zd Zn : XSetsA} {H0 Hd : Heap} {OS0 OS' : Set U64} {s0 s5 : S} + {σ0 σ' : Fl4SpecA64.State Unit} {m0 m' : Fl4SpecA64.McState} {frame : U64} {ia ie : Nat} + (J0 : J7A st (J7R2A st ar nA) Z0 H0 OS0 s0 σ0 m0) + (E : ∀ Pt Ub, J7BodyA st (J7R2A st ar nA) Z0 H0 OS0 s0 σ0 m0 Pt Ub → + PoolJ7EndA st ar nA Z0 Zn Hd frame OS' s5 σ' m' Pt Ub) + (hHd : HeapOK Hd) (hHE : HeapOK (PoolH Hd frame 12)) (SI : SetsInHA Zd Hd) + (hdr : ∀ q k, Hd q = some k → H0 q = some k) + (off : ∀ q k, Hd q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) + (osOff : ∀ y ∈ OS', y.val + 32 ≤ frame.val ∨ frame.val + 4096 ≤ y.val) (hOS : OS' ⊆ OS0) + (hCs : Zn.Cs = Z0.Cs) (hV : Zn.V ⊆ Z0.V) (hVd : Zn.V = Zd.V) + (hZn : Zn.Pp = insert frame Zd.Pp ∧ Zn.S1 = Zd.S1 ∧ Zn.T2 = Zd.T2 ∧ Zn.X = Zd.X ∧ Zn.Y = Zd.Y) + (hPp : Zd.Pp ⊆ Z0.Pp) (hS1 : Zd.S1 ⊆ Z0.S1) (hT2 : Zd.T2 ⊆ Z0.T2) (hX : Zd.X ⊆ Z0.X) (hY : Zd.Y ⊆ Z0.Y) + (hks : (L.ksb s0).val + 788736 ≤ frame.val ∨ frame.val + 4096 ≤ (L.ksb s0).val) + (hkw : (L.ksb s0).val + 788736 ≤ 2 ^ 64) (ksb : L.ksb s5 = L.ksb s0) + (hsys : SysL st (PoolH Hd frame 12) Z0.Cs OS' ia ie s5) + (htab : ∃ i, L.mem s5 (wa (L.ksb s5) (AtOff i)) = frame) (hfz : frame ≠ 0#u64) : + J7A st (J7R2A st ar nA) Zn (PoolH Hd frame 12) OS' s5 σ' m' := by + obtain ⟨Pt, Ub, vr, pools, C, K, vcc, dev, hi, sched0, apart, frub, alub, vcub, R0⟩ := J0 + have End := E Pt Ub ⟨vr, pools, C, K, vcc, dev, hi, sched0, apart, frub, alub, vcub, R0⟩ + obtain ⟨Pp0, Tb0, Hr0, Te0, Kt0, Lv0, Re0, bits0, R20, -⟩ := R0 + obtain ⟨Pp1, Tb1, Hr1, Te1, Kt1, Lv1, Re1, bits1, R2e, -⟩ := End.r2 + obtain ⟨i, hi'⟩ := htab + have hUbP : ∀ b ∈ Ub, ¬ (frame.val ≤ b.val ∧ b.val < frame.val + 4096) := fun b hb => by + have := End.col.pool i (by rw [hi']; exact hfz) b hb + rw [hi'] at this + exact this + have C' := End.col.sub (Set.inter_subset_left : Ub ∩ FrameWords st OS' s5 ⊆ Ub) + refine ⟨insert frame (s1aKeptPt Hd Pt), Ub ∩ FrameWords st OS' s5, ?_, End.pools, ?_, ?_, End.vcc, End.dev, + End.hi, ?_, ?_, ?_, fun b hb => alub b hb.1, fun b hb hbU => vcub b (VcW.monoA hV hb) hbU.1, End.r2⟩ + · rw [ksb] + exact poolVrOK hHd hHE hdr off osOff hOS hV hks hkw vr + (fun v hv => by rw [hVd] at hv; exact SI.pages v (Or.inr hv)) hUbP (fun b hb => End.asw b (by rw [ksb]; exact hb)) + · rw [hCs] + exact { C' with vh := fun v hv => End.col.vh v (hV hv) } + · exact ⟨fun b hb => FrameWords.ubFr s5 b hb.2, hsys.userOffFr, hsys.sys.fr⟩ + · exact poolSched hHd SI hZn hPp hS1 hT2 hX hY sched0 (fun p hp => (R20.footprint p hp).1) R2e + · intro b hb o ho + rw [ksb] + exact apart b (VcW.monoA hV hb) o ho + · exact FrUb.inter_fw End.frub + +end top + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolMemA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolMemA.lean new file mode 100644 index 000000000..b53e9ebf9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolMemA.lean @@ -0,0 +1,286 @@ +/- +P3 (aarch64, Stage 5, line pool, group B): **the memory side of the MakePool record** (caps + heap fields). + +Takes `PoolCtxA` and the dropped record before (`Jd`, at `s`) and after (`J`, at `s1 = L.wr s (stA curW) TS_RESTART`) the +caller's restart write; `PoolMemOutA = UtAsmCapsOutA ∧ UtAsmHeapOutA` at the grown record `Zn`, heap `PoolH Hd frame 12`. + +* `poolHeap_offA`, **`poolHeap_dropA`**: no heap object of the dropped record meets the pool block, so + `Hd.drop (RegionD Hd frame.val (frame.val + 4096)) = Hd` (the export Group C takes as a hypothesis). + +No named premise beyond `PoolCtxA`'s. New module. +-/ +import Fl4ProofsA64.P3.Stage3PoolCoreA +import Fl4ProofsA64.P3.Stage3PoolHeapA +import Fl4ProofsA64.P3.Stage3PoolCapsA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST 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} +variable {AR : A → HwRootA → Prop} {Zd Zn : XSetsA} {Hd : Heap} {OSd 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 s5 : S} {a : A} {σ σ1 σ' : State Unit} + {m m' : McState} {parent dest : CslotPtr} {frame fi i base : U64} + +/-- **The dropped heap is off the pool block** (`ObjAllocA` at the parent's slot + the dead drop). -/ +theorem poolHeap_offA (hA : ObjAllocA (st := st) Zd Hd OSd s) (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base) + (hx : cslotAddrA parent ∈ OSd) : + ∀ q k, Hd q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val := fun q k hq => + ObjAllocA.disjoint_of_drop hA hx C.hcp C.dd (Or.inr (Or.inr (Or.inr ⟨k, hq, rfl⟩))) + +/-- **`H.drop (RegionD Hd lo hi) = Hd`** for the pool block `[frame, frame + 4096)` (Group C's hypothesis). -/ +theorem poolHeap_dropA {H : Heap} {frame : U64} + (off : ∀ q k, H q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) : + H.drop (RegionD H frame.val (frame.val + 4096)) = H := by + funext q + by_cases hR : RegionD H frame.val (frame.val + 4096) q + · cases hq : H q with + | none => simp [Heap.drop, hR, hq] + | some k => + exfalso + unfold RegionD MeetsR at hR + rw [hq] at hR + simp only [Option.elim] at hR + rcases off q k hq with h | h <;> omega + · rw [Heap.drop_of_not hR] + + +/-- The ASID-table word's value. -/ +theorem poolAtAF_valA {kb hi : U64} (hkw : kb.val + 788736 ≤ 2 ^ 64) (h : hi.val < 128) : + (atAF kb hi).val = kb.val + 772352 + 8 * hi.val := by + unfold atAF + have e7 : (772352#u64 : U64).val = 772352 := rfl + have em : (wa 772352#u64 (core.num.U64.wrapping_mul hi 8#u64)).val = 772352 + 8 * hi.val := by + rw [wa_valP, e7, wm8_valA (by omega)] + exact Nat.mod_eq_of_lt (by omega) + rw [wa_valP, em] + have := Nat.mod_eq_of_lt (a := kb.val + (772352 + 8 * hi.val)) (b := 2 ^ 64) (by omega) + omega + +/-- A word of an object `[q, q + 2^z)` of the dropped heap is off the pool block and the ASID table, given the +object is off the block (`off`) and placed by `HeapKsOff`. -/ +theorem poolWord_offA {Hd : Heap} {frame kb i q w : U64} {k : HKind} + (off : ∀ q k, Hd q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) + (hq : Hd q = some k) (hkb : (∀ z, k ≠ .other z) ∨ ∃ z, k = .other z) (hK : HeapKsOff Hd kb) + (hz : ∀ z, k = .other z → 4096 ≤ 2 ^ z) + (hkw : kb.val + 788736 ≤ 2 ^ 64) (hi : i.val < 128) (h1 : q.val ≤ w.val) (h2 : w.val < q.val + 2 ^ k.bits) : + ¬ (frame.val ≤ w.val ∧ w.val < frame.val + 4096) ∧ w ≠ atAF kb i := by + have o := off q k hq + refine ⟨fun h => by omega, fun e => ?_⟩ + have ev := poolAtAF_valA hkw hi + rw [← e] at ev + rcases hkb with hn | ⟨z, rfl⟩ + · have := hK.1 q k hq hn + omega + · have := hK.2 q z hq + have := hz z rfl + simp only [HKind.bits] at h2 + omega + +/-- **The grown joint objects**: an old one, or the pool page. -/ +theorem poolJoint_splitA {Z : XSetsA} {G' : MdbGhostA} {H : Heap} {frame q : U64} {bytes : Nat} + (h : JointObjectA { Z with Pp := insert frame Z.Pp, G := G' } (PoolH H frame 12) q bytes) : + JointObjectA Z H q bytes ∨ (q = frame ∧ bytes = 4096) := by + rcases h with ⟨hb, hq⟩ | h | ⟨k, hk, hb⟩ | ⟨k, hk, hb⟩ + · rcases hq with hq | hq | hq | hq | hq + · rcases hq with rfl | hq + · exact Or.inr ⟨rfl, hb⟩ + · exact Or.inl (Or.inl ⟨hb, Or.inl hq⟩) + · exact Or.inl (Or.inl ⟨hb, Or.inr (Or.inl hq)⟩) + · exact Or.inl (Or.inl ⟨hb, Or.inr (Or.inr (Or.inl hq))⟩) + · exact Or.inl (Or.inl ⟨hb, Or.inr (Or.inr (Or.inr (Or.inl hq)))⟩) + · exact Or.inl (Or.inl ⟨hb, Or.inr (Or.inr (Or.inr (Or.inr hq)))⟩) + · exact Or.inl (Or.inr (Or.inl h)) + · exact Or.inl (Or.inr (Or.inr (Or.inl ⟨k, hk, hb⟩))) + · rcases Heap.add_eq_some.1 hk with ⟨hq, rfl⟩ | ⟨-, hk⟩ + · exact Or.inr ⟨hq, by rw [hb]; rfl⟩ + · exact Or.inl (Or.inr (Or.inr (Or.inr ⟨k, hk, hb⟩))) + + +/-- **What MakePool's perform and the record supply** to the heap bundle (`PoolAsmHeapInA`): the group B content. +`Jd` is the dropped record at `s` (before the restart write), `J` at `s1 = L.wr s (stA curW) TS_RESTART`. +`free`, `kh`, `asid` are Group A's three spec facts (plain hypotheses). -/ +theorem poolHeapInA {s1 : S} {σ0 : State Unit} + (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base) + (Jd : JStage3A st AR Zd Hd OSd U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s a σ0 m') + (J : JStage3A st AR Zd Hd OSd U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s1 a σ1 m') + (hs1 : s1 = L.wr s (stA (L.curW s)) sched.TS_RESTART) (hk : OSKeep st OSd s s1) + (free : σ1.kheap (specPtr frame) = none) + (kh : ∀ p, p ≠ specPtr frame → σ'.kheap p = σ1.kheap p ∨ + (∃ r cs cs', σ1.kheap p = some (.cnode r cs) ∧ σ'.kheap p = some (.cnode r cs')) ∨ + ∃ y y', σ1.kheap p = some (.tcb y) ∧ σ'.kheap p = some (.tcb y')) + (asid : ∀ j q, σ'.archState.armAsidTable j = some (specPtr q) → + q = frame ∨ σ1.archState.armAsidTable j = some (specPtr q)) : + PoolAsmHeapInA st Zd Hd OSd OSd Bf s1 s5 σ1 σ' (cslotAddrA parent) (cslotAddrA dest) frame base fi i := by + have hks1 : L.ksb s1 = L.ksb s := by rw [hs1]; exact L.ksb_wr _ _ _ + have hxO : cslotAddrA parent ∈ OSd := Jd.j5.2.1 _ (C.absP.isSlot Jd.j.1.place) + have hvO : cslotAddrA dest ∈ OSd := Jd.j5.2.1 _ (C.absD.isSlot Jd.j.1.place) + have hcp1 : capA st s1 (cslotAddrA parent) = .Untyped frame 12#u64 fi false := by rw [hk.capA hxO]; exact C.hcp + have hcd1 : capA st s1 (cslotAddrA dest) = .Null := by rw [hk.capA hvO]; exact C.hcd + have off := poolHeap_offA Jd.objAlloc C hxO + have hH := J.sys.ent.heap + have hkw : (L.ksb s).val + 788736 ≤ 2 ^ 64 := by rw [← hks1]; exact J.sys.ent.ksw + have ko : HeapKsOff Hd (L.ksb s) := by rw [← hks1]; exact J.ko + have hw1 : WritesIn st s1 s5 (fun b => W7.CapW Hd.tcbs {b | InOS OSd b} ∅ b ∨ + (frame.val ≤ b.val ∧ b.val < frame.val + 4096) ∨ b = atAF (L.ksb s) i) := by rw [hs1]; exact C.expo.w1 + -- a word of a footprint object that is kept by the step + have kept : ∀ w, FootNA (L := L) Zd s1 w → ∀ q k, Hd q = some k → + ((∀ z, k ≠ .other z) ∨ ∃ z, k = .other z) → (∀ z, k = .other z → 4096 ≤ 2 ^ z) → q.val ≤ w.val → w.val < q.val + 2 ^ k.bits → + L.mem s5 w = L.mem s1 w := by + intro w hb q k hq hkb hz h1 h2 + have al := FootNA.aligned J.j.1 (bxi_nodes J.sys.ent.bxi) J.toJEntA.scAl J.ap.vcAl w hb + refine hw1.mem_eq al ?_ + rintro (hc | blk | e) + · exact footN_offA J.toJEntA w hb hc + · exact (poolWord_offA off hq hkb ko hz hkw C.hi h1 h2).1 blk + · exact (poolWord_offA off hq hkb ko hz hkw C.hi h1 h2).2 e + have frOff0 := poolFrOffA (G := Zd.G) Jd.sys.ent.os + (Jd.j.1.cdt.tree.grow Jd.j5.2.1 (fun x hx hn => Jd.j5.2.2 x hx hn)) Jd.sys.sysl.sys.stz.1.2.1 hxO C.hcp C.hnc + have e12 : (12#u64 : U64).val = 12 := rfl + refine + { off := off + w := hw1.mono (fun b h => by + rw [hks1] + rcases h with h | h | h + · exact Or.inl h + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr (Or.inr h))) + curT := by rw [J.tcbs]; exact J.sr.curT + hi := C.hi + vIn := hvO + capV := C.expo.capD + vcpuW := fun t ht => by + have htH : Hd t = some .tcb := by + have : t ∈ Hd.tcbs := by rw [J.tcbs]; exact ht + exact this + have f := hH.fits t _ htH + simp only [HKind.bits] at f + refine (kept _ (.tcb t _ ht (Or.inr (Or.inr (Or.inr (Or.inl rfl))))) t .tcb htH (Or.inl fun z h => by cases h) (fun z h => by cases h) + ?_ ?_) + · rw [wa_valP]; simp only [show (3664#u64 : U64).val = 3664 from rfl] + rw [Nat.mod_eq_of_lt (by omega)]; omega + · rw [wa_valP]; simp only [show (3664#u64 : U64).val = 3664 from rfl, HKind.bits] + rw [Nat.mod_eq_of_lt (by omega)]; omega + vcw := fun y hy => by + obtain ⟨q, z, hq, g1, g2⟩ := J.setsInH.pages y (Or.inr hy) + have f := hH.fits q _ hq + simp only [HKind.bits] at f + have ev : (wa y 24#u64).val = y.val + 24 := by + rw [wa_valP, show (24#u64 : U64).val = 24 from rfl] + exact Nat.mod_eq_of_lt (by omega) + exact kept _ (.vcpu y _ hy (Or.inr rfl)) q _ hq (Or.inr ⟨z, rfl⟩) (fun z' h => by cases h; omega) (by omega) (by simp only [HKind.bits]; omega) + src := hxO + cap := hcp1 + cap' := C.expo.capP + dst := hcd1 + src' := hxO + slots := fun u hu => by + by_cases ux : u = cslotAddrA parent + · subst ux; exact Or.inr (Or.inl ⟨rfl, C.expo.capP⟩) + · by_cases uv : u = cslotAddrA dest + · subst uv; exact Or.inr (Or.inr ⟨rfl, C.expo.capD⟩) + · exact Or.inl ⟨hu, ux, uv, by rw [C.expo.capK u hu ux uv, hk.capA hu]⟩ + sub := fun _ h => h + revK := fun y hy hyd hnn => by + have hn0 : capA st s (y) ≠ .Null := by rw [← hk.capA hy]; exact hnn + rw [C.expo.revK y hy hyd hn0] + exact (revA_congr (hk y hy).2.2.2).symm + kept := fun u hu ux hn => by + by_cases uv : u = cslotAddrA dest + · subst uv; exact absurd hcd1 hn + · exact ⟨hu, by rw [C.expo.capK u hu ux uv, hk.capA hu]⟩ + frOff := fun y hy q sz r d a1 a2 a3 a4 bits hc hb => by + rcases frOff0 y hy q sz r d a1 a2 a3 a4 bits (by rw [← hk.capA hy]; exact hc) hb with g | g + · exact Or.inl g + · exact Or.inr (by rw [e12] at g; norm_num at g; omega) + free := free + kh := kh + asid := asid } + + +/-- **The cap-split fields** of the record after MakePool (`PoolSlotsA` + the eight `poolRt_*A` lemmas). -/ +theorem poolRt_asmCapsA {s1 : S} {σ0 : State Unit} {G' : MdbGhostA} + (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' { Zd with Pp := insert frame Zd.Pp, G := G' } m m' parent dest frame fi i base) + (Jd : JStage3A st AR Zd Hd OSd U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s a σ0 m') + (J : JStage3A st AR Zd Hd OSd U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s1 a σ1 m') + (K : PoolAsmHeapInA st Zd Hd OSd OSd Bf s1 s5 σ1 σ' (cslotAddrA parent) (cslotAddrA dest) frame base fi i) + (hk : OSKeep st OSd s s1) : + UtAsmCapsOutA st { Zd with Pp := insert frame Zd.Pp, G := G' } (PoolH Hd frame 12) OSd ia ie s5 := by + have mono := poolHeapA_mono K + have hxO := K.src + have hdis : ∀ p bytes, JointObjectA Zd Hd p bytes → p.val + bytes ≤ frame.val ∨ frame.val + 4096 ≤ p.val := + fun p bytes hp => ObjAllocA.disjoint_of_drop Jd.objAlloc hxO C.hcp C.dd hp + have nb : ∀ c, L.nodeBase s5 c = L.nodeBase s1 c := fun c => by unfold LawfulStore.nodeBase; rw [K.w.1] + have e12 : (12#u64 : U64).val = 12 := rfl + exact + { utBlk := poolRt_utBlkA J.utBlk K.slots + zombieBnd := poolRt_zombieBndA J.zombieBnd K.slots + zombieTcb := poolRt_zombieTcbA J.zombieTcb K.slots (fun t ht => mono t .tcb ht) + zombieNoVcpu := poolRt_zombieNoVcpuA J.zombieNoVcpu J.zombieTcb K.slots + (fun t ht => K.vcpuW t (by rw [← J.tcbs]; exact ht)) + capTy := poolRt_capTyA J.capTy K.slots mono + devUtOff := poolRt_devUtOffA J.devUtOff K.slots K.src K.cap + (fun q bytes h => poolJoint_splitA h) + (fun lo hi h => by + unfold RegionOffNodes at h ⊢ + simp only [nb, K.w.1] + exact h) + idleAnchor := poolRt_idleAnchorA J.idleAnchor K.slots K.src K.cap + objAlloc := poolRt_objAllocA J.objAlloc K.slots K.src K.cap + (fun q bytes h => by + rcases poolJoint_splitA h with old | e + · exact Or.inl ⟨old, hdis q bytes old⟩ + · exact Or.inr e) + (fun u hu hux q b f d e => by + have e' : capA st s u = .Untyped q b f d := (hk.capA hu).symm.trans e + have nd : ∀ G par, TreeA st OSd G par s → ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc par y (cslotAddrA parent) := + fun G par h => cdt.ensure_no_children.noDesc Jd.sys.ent.os h hxO C.hcp + (Jd.sys.sysl.sys.stz.1.2.1 _ hxO (by rw [C.hcp]; rfl)) C.hnc + rcases pool_utOther Jd.sys.sysl.sys hxO C.hcp nd hu hux e' with g | g + · exact Or.inl (by rw [e12] at g; norm_num at g; omega) + · exact Or.inr (by rw [e12] at g; norm_num at g; omega)) } + + +/-- **Group B's output**: the caps fields and the table/heap fields at the grown record. -/ +def PoolMemOutA (st : machine.Store S) [L : LawfulStore st] (Zn : XSetsA) (H' : Heap) (OS : Set U64) (ia ie : Nat) + (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) (s' : S) (σ' : State Unit) + (m' : McState) : Prop := + UtAsmCapsOutA st Zn H' OS ia ie s' ∧ UtAsmHeapOutA st Zn H' OS N E Rp Bf stack s' σ' m' + +/-- **Group B's theorem** (statement in `WS/handoff/a64p5-pool-b-notes.md`). -/ +theorem poolMemA {s1 : S} {σ0 : State Unit} + (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base) + (Jd : JStage3A st AR Zd Hd OSd U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s a σ0 m') + (J : JStage3A st AR Zd Hd OSd U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s1 a σ1 m') + (hs1 : s1 = L.wr s (stA (L.curW s)) sched.TS_RESTART) (hk : OSKeep st OSd s s1) + (free : σ1.kheap (specPtr frame) = none) + (kh : ∀ p, p ≠ specPtr frame → σ'.kheap p = σ1.kheap p ∨ + (∃ r cs cs', σ1.kheap p = some (.cnode r cs) ∧ σ'.kheap p = some (.cnode r cs')) ∨ + ∃ y y', σ1.kheap p = some (.tcb y) ∧ σ'.kheap p = some (.tcb y')) + (asid : ∀ j q, σ'.archState.armAsidTable j = some (specPtr q) → + q = frame ∨ σ1.archState.armAsidTable j = some (specPtr q)) : + PoolMemOutA st Zn (PoolH Hd frame 12) OSd ia ie N E Rp Bf stack s5 σ' m' := by + obtain ⟨G', hG⟩ : ∃ G', G' = Zn.G := ⟨_, rfl⟩ + have e : Zn = { Zd with Pp := insert frame Zd.Pp, G := G' } := by rw [hG]; exact C.zn + clear hG + subst e + have K := poolHeapInA C Jd J hs1 hk free kh asid + exact ⟨poolRt_asmCapsA C Jd J K hk, poolRt_asmHeapA K J⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolRecA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolRecA.lean new file mode 100644 index 000000000..9ab1eabdf --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolRecA.lean @@ -0,0 +1,370 @@ +/- +P3 (aarch64, Stage 5, line pool, Group D): **the record-edit-#5/#6 fields and the small tail of the record after +`ARMASIDControlMakePool`**, the pool twins of `utRt_rec5A` / `utRt_rec6A` (`P3/UtApRec5A`, `P3/UtApRec6A`) without the +creation window: MakePool creates no VCPU, TCB or SC, only the `other 12` pool object at `frame`. + +The step is read from the record after the caller's restart write and the parent's block drop (`J`, state `sr`), the +step data `PoolStepA` (footprint = cap words, pool page, ASID-table word `i`; spec change = CNodes and the new pool) +and the shared context `PoolCtxA` (`capP`/`capD` and the spec shape). The grown record is `Zn` at the grown typed heap +`PoolH Hd frame 12`, the same slot set `OSd`, state `s5`, spec outcome `σ'`. + +* `PoolRecOutA`: R5 `heapWin coresAll ptCapIn symL fhOK zwf schedValid`, R6 `utWin devWin vcBack runBack vcOS userFr + frTh`, and the tail `vcSnap domOK ipiZero` (`bufVs`: `poolRt_bufVsA`). +* **`poolRt_recA`**: the fields. `symL` is Group C's output, taken as a hypothesis. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.Stage3PoolCoreA +import Fl4ProofsA64.P3.Stage3PoolIpcA +import Fl4ProofsA64.P3.UtApRec6A + +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 + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} {Zd Zn : XSetsA} {Hd : Heap} {OSd U Ac Pp Tb N E Rp : Set U64} {Lv : U64 → Nat} + {ia ie : Nat} {Bf : Set (U64 × Fl4SpecA64.Word)} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {nA : U64} + {s sr s5 : S} {a : A} {σ1 σ' : State Unit} {m m' : McState} {parent dest : CslotPtr} {frame fi i base : U64} + +/-- **The record-edit-#5/#6 fields and the tail but `bufVs`** (module docstring). -/ +structure PoolRecOutA (st : machine.Store S) [L : LawfulStore st] (Z' : XSetsA) (H' : Heap) (OS' : Set U64) (s' : S) + (σ' : State Unit) : Prop extends UtRec5OutA st Z' H' s' σ', UtRec6OutA st Z' H' OS' s' σ' where + vcSnap : VcpuStateSnapA Z'.V (L.mem s') σ' + domOK : Sched.NdOKA (st := st) s' σ' + ipiZero : Sched.SilentScheduleIpiA (st := st) s' + +section ctx +variable (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base) +include C + +theorem PoolCtxA.eCs : Zn.Cs = Zd.Cs := by + have h := congrArg (fun z : XSetsA => z.Cs) C.zn + exact h +theorem PoolCtxA.eT : Zn.T = Zd.T := by + have h := congrArg (fun z : XSetsA => z.T) C.zn + exact h +theorem PoolCtxA.eV : Zn.V = Zd.V := by + have h := congrArg (fun z : XSetsA => z.V) C.zn + exact h +theorem PoolCtxA.eth : Zn.th = Zd.th := by + have h := congrArg (fun z : XSetsA => z.th) C.zn + exact h +theorem PoolCtxA.eS1 : Zn.S1 = Zd.S1 := by + have h := congrArg (fun z : XSetsA => z.S1) C.zn + exact h +theorem PoolCtxA.eT2 : Zn.T2 = Zd.T2 := by + have h := congrArg (fun z : XSetsA => z.T2) C.zn + exact h +theorem PoolCtxA.eLv : Zn.Lv = Zd.Lv := by + have h := congrArg (fun z : XSetsA => z.Lv) C.zn + exact h + +end ctx + +variable (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base) + (J : JStage3A st AR Zd Hd OSd U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) sr a σ1 m') + (P : PoolStepA st Zd Hd OSd sr s5 σ1 σ' m' n (cslotAddrA parent) (cslotAddrA dest) frame fi i) +include C J P + +/-- A slot's cap after: the parent's untyped, the destination's pool, or kept. -/ +theorem poolRec_capA {y : U64} (hy : y ∈ OSd) : + capA st s5 y = .Untyped frame 12#u64 4096#u64 false ∨ capA st s5 y = .AsidPool frame base ∨ + capA st s5 y = capA st sr y := by + by_cases e1 : y = cslotAddrA parent + · exact Or.inl (by rw [e1]; exact C.expo.capP) + by_cases e2 : y = cslotAddrA dest + · exact Or.inr (Or.inl (by rw [e2]; exact C.expo.capD)) + exact Or.inr (Or.inr (P.capK y hy e1 e2)) + +/-- The dropped heap keeps clear of the pool block. -/ +theorem poolRec_grow : ∀ q k, Hd q = some k → PoolH Hd frame 12 q = some k := fun q k h => by + have nf : ¬ q = frame := fun e => by + have := Nat.two_pow_pos k.bits + rcases P.disj q _ (Or.inr (Or.inr (Or.inr ⟨k, h, rfl⟩))) with g | g <;> rw [e] at g <;> omega + exact (Heap.add_of_not (N := (· = frame)) nf).trans h + +theorem poolRec_heapWin : ∀ p k, PoolH Hd frame 12 p = some k → + layout.PPTR_BASE.val ≤ p.val ∧ p.val + 2 ^ k.bits ≤ layout.PPTR_BASE.val + 2 ^ 44 := by + intro p k h + rcases Heap.add_eq_some.1 h with ⟨e, rfl⟩ | ⟨-, e⟩ + · have e' : p = frame := e + rw [e'] + have w := J.utWin _ P.mem _ _ _ P.cap + simpa only [show (12#u64 : U64).val = 12 from rfl, show (HKind.other 12).bits = 12 from rfl] using w + · exact J.heapWin p k e + +theorem poolRec_coresAll : ∀ k < Fl4SpecA64.fl4A64Platform.numNodes, ∃ c ∈ Zn.Cs, c.val = k := fun k hk => by + obtain ⟨c, hc, e⟩ := J.coresAll k hk + exact ⟨c, by rw [C.eCs]; exact hc, e⟩ + +theorem poolRec_ptCapIn : PtCapInA Zn (L.mem s5) := by + intro y hy ptr asid va h + rw [C.eth] at hy + change capA st s5 y = _ at h + rcases poolRec_capA C J P (P.sub y hy) with g | g | g + · rw [g] at h; cases h + · rw [g] at h; cases h + · rw [g] at h + rw [C.eS1, C.eLv, C.eT2] + exact J.ptCapIn y hy ptr asid va h + +/-- The parent and destination slots are no TCB's fault-handler slot. -/ +theorem poolRec_fhNe {t : U64} (tth : Zd.th t = some .tcb) {d : CslotPtr} + (hd : ∃ q, d.1 = specPtr q ∧ Zd.th q = some (.cnode d.2.length)) (ad : AbsSlotA Zd.th d) : + slotIdx t layout.tcb.SLOT_FAULT_HANDLER ≠ cslotAddrA d := by + obtain ⟨q, eq, hq⟩ := hd + intro e + have a1 : AbsSlotA Zd.th (specPtr t, Fl4SpecA64.tcbCnodeIndex 3) := + ⟨t, rfl, Or.inr ⟨tth, 3, by unfold tcbSlotsA; omega, rfl⟩⟩ + have ea : cslotAddrA (specPtr t, Fl4SpecA64.tcbCnodeIndex 3) = cslotAddrA d := by + rw [← e, slotIdx_fhA] + unfold cslotAddrA + rw [ofBl_tcbIdx 3 (by omega)] + have := cslotAddrA_inj J.j.1.place a1 ad ea + rw [← this] at eq + have e2 := specPtr_inj eq + rw [← e2, tth] at hq + cases hq + +theorem poolRec_fhOK : ∀ t ∈ Zn.T, NullOrEp (PoolH Hd frame 12) (capA st s5 (slotIdx t layout.tcb.SLOT_FAULT_HANDLER)) := by + intro t ht + rw [C.eT] at ht + have tth : Zd.th t = some .tcb := (J.sr.thT t).2 ht + have yO := P.sub _ (isSlot_fhA tth) + have was := J.fhOK t ht + rw [P.capK _ yO (poolRec_fhNe C J P tth C.holdP C.absP) (poolRec_fhNe C J P tth C.holdD C.absD)] + exact was.imp id fun ⟨ep, b0, b1, b2, b3, b4, e, he⟩ => ⟨ep, b0, b1, b2, b3, b4, e, poolRec_grow C J P _ _ he⟩ + +theorem poolRec_zwf : DelInvA st Zn.th s5 := by + intro y hy p zt k h + rw [C.eth] at hy ⊢ + rcases poolRec_capA C J P (P.sub y hy) with g | g | g + · rw [g] at h; cases h + · rw [g] at h; cases h + · rw [g] at h + exact J.zwf y hy p zt k h + +theorem poolRec_schedValid : SchedValidA σ' := by + have O := poolRt_specObjA P.fresh P.pool P.kh P.glob + have keep : ∀ q ko, σ1.kheap q = some ko → (∀ r cs, ko ≠ .cnode r cs) → + σ'.kheap q = some ko := O.keep + have act : ∀ q, ScActiveAtA σ1 q → ScActiveAtA σ' q := fun q ⟨y, k, e, g⟩ => + ⟨y, k, keep q _ e (fun _ _ h => by cases h), g⟩ + refine ⟨fun dm pr t hm => ?_, fun e1 e2 => ?_, fun t x sc e1 e2 e3 => ?_, fun t hm => ?_⟩ + · rw [O.glob.rq] at hm + obtain ⟨⟨x, sc, e, es, g⟩, nr⟩ := J.schedValid.rq dm pr t hm + exact ⟨⟨x, sc, keep t _ e (fun _ _ h => by cases h), es, act _ g⟩, by rw [O.glob.rls]; exact nr⟩ + · rw [O.glob.act] at e1 + rw [O.glob.cur, O.glob.idle] at e2 + obtain ⟨⟨x, sc, e, es, g⟩, nr⟩ := J.schedValid.act e1 e2 + rw [O.glob.cur, O.glob.rls] + exact ⟨⟨x, sc, keep _ _ e (fun _ _ h => by cases h), es, act _ g⟩, nr⟩ + · rcases O.back t _ e1 (fun _ _ h => by cases h) with old | ⟨-, e⟩ + · exact act _ (J.schedValid.blk t x sc old e2 e3) + · cases e + · rw [O.glob.rls] at hm + obtain ⟨x, sc, e, es, g⟩ := J.schedValid.rls t hm + exact ⟨x, sc, keep t _ e (fun _ _ h => by cases h), es, act _ g⟩ + +theorem poolRec_utWin : UtWinCapA st OSd s5 := by + intro u hu p sb f h + rcases poolRec_capA C J P hu with g | g | g + · rw [g] at h + cases h + exact J.utWin _ P.mem _ _ _ P.cap + · rw [g] at h; cases h + · rw [g] at h + exact J.utWin u hu p sb f h + +theorem poolRec_devWin : DevWinCapA st OSd s5 := by + intro u hu + rcases poolRec_capA C J P hu with g | g | g + · exact ⟨fun p sb f h => (by rw [g] at h; cases h), fun p sz r mp e a v h => (by rw [g] at h; cases h)⟩ + · exact ⟨fun p sb f h => (by rw [g] at h; cases h), fun p sz r mp e a v h => (by rw [g] at h; cases h)⟩ + · rw [g] + exact J.devWin u hu + +theorem poolRec_frTh : FrThA st Zn.th OSd s5 := by + intro y hy p size rights x1 x2 x3 x4 bits h hb + rw [C.eth] + rcases poolRec_capA C J P hy with g | g | g + · rw [g] at h; cases h + · rw [g] at h; cases h + · rw [g] at h + exact J.frTh y hy p size rights x1 x2 x3 x4 bits h hb + +theorem poolRec_userFr : UserFrSpecA st (PoolH Hd frame 12) OSd s5 σ' := by + intro y hy p size rights mp ept asid va h + rcases poolRec_capA C J P hy with g | g | g + · rw [g] at h; cases h + · rw [g] at h; cases h + · rw [g] at h + obtain ⟨b, pg, hHb, hk, hb1, hb2⟩ := J.userFr y hy p size rights mp ept asid va h + have ne : specPtr b ≠ specPtr frame := fun e => by rw [e, P.fresh] at hk; cases hk + rcases P.kh _ ne with k | ⟨r, cs, cs', h1, -⟩ + · exact ⟨b, pg, poolRec_grow C J P _ _ hHb, by rw [k]; exact hk, hb1, hb2⟩ + · rw [h1] at hk; cases hk + +/-! ### Words kept by the pool's footprint -/ + +/-- A word of a VCPU of the record is kept. -/ +theorem poolRec_vcWord {v o : U64} (hv : v ∈ Zd.V) (ho : o.val < 4096) (h8 : o.val % 8 = 0) : + L.mem s5 (wa v o) = L.mem sr (wa v o) := by + obtain ⟨hv12, ev, al, -, -⟩ := utVc_wordA J hv ho h8 + refine poolRt_memA J P al (J.vcOS _ ⟨v, hv, o, ho, h8, rfl⟩) (fun ⟨g1, g2⟩ => ?_) + (fun e => J.vsVc _ (.asid i P.hi) ⟨v, hv, o, ho, h8, e.symm⟩) + exact (poolRt_clrA J P).inObj (Or.inr (Or.inr (Or.inr ⟨_, hv12, rfl⟩))) (a := wa v o) (by omega) + (by simp only [show (HKind.other 12).bits = 12 from rfl, Nat.reducePow]; omega) ⟨g1, g2⟩ + +/-- A TCB word above the slots is kept. -/ +theorem poolRec_tcbWord {t K : U64} (ht : t ∈ Zd.T) (h1 : 224 ≤ K.val) (h2 : K.val < 4096) (h8 : K.val % 8 = 0) + (h3 : K.val ≠ 3584) : L.mem s5 (wa t K) = L.mem sr (wa t K) := by + obtain ⟨al, -⟩ := utT_wordA J ht h2 h8 + have W := ut_tcbFieldA J ht h1 h2 + have f := (ut_tcbThA J ht).2 + have ev : (wa t K).val = t.val + K.val := by rw [wa_valP]; exact Nat.mod_eq_of_lt (by omega) + exact poolRt_memA J P al (utRt_tcbOffA J ht al (by omega) (by omega) (by omega)).1 + (ut_where_regionA J (poolRt_clrA J P) W) (poolRt_atOffA J P.hi W) + +theorem poolRec_vcBack : ∀ v ∈ Zn.V, L.mem s5 v ≠ 0#u64 → + L.mem s5 (wa (L.mem s5 v) 3664#u64) = v := by + intro v hv h0 + rw [C.eV] at hv + have e0 : L.mem s5 v = L.mem sr v := by + have := poolRec_vcWord C J P (o := 0#u64) hv (by decide) (by decide) + rwa [wa_zeroVcA] at this + rw [e0] at h0 ⊢ + have tT : L.mem sr v ∈ Zd.T := (J.vcRun.vtcb v hv).resolve_left h0 + rw [poolRec_tcbWord C J P tT (K := 3664#u64) (by decide) (by decide) (by decide) (by decide)] + exact J.vcBack v hv h0 + +theorem poolRec_runBack : ∀ t ∈ Zn.T, L.mem s5 (runVcpuA t) ≠ 0#u64 → + L.mem s5 (wa (L.mem s5 (runVcpuA t)) 24#u64) = t := by + intro t ht h0 + rw [C.eT] at ht + have e0 : L.mem s5 (runVcpuA t) = L.mem sr (runVcpuA t) := + poolRec_tcbWord C J P ht (K := 3672#u64) (by decide) (by decide) (by decide) (by decide) + rw [e0] at h0 ⊢ + have vV : L.mem sr (runVcpuA t) ∈ Zd.V := (J.vcRun.run t ht).resolve_left h0 + rw [poolRec_vcWord C J P vV (o := 24#u64) (by decide) (by decide)] + exact J.runBack t ht h0 + +/-- The spec's domain schedule is kept. -/ +theorem poolRec_domKeep : DomKeepA σ1 σ' := by + obtain ⟨ms', ko3, σ5, -, -, -, -, -, -, ⟨ko5, b, v, h5, -⟩, h'⟩ := C.expo.spec + subst h' h5 + exact DomKeepA.ofKey rfl + +theorem poolRec_domOK : Sched.NdOKA (st := st) s5 σ' := by + have hks : (L.ksb sr).val + 788736 ≤ 2 ^ 64 := J.sys.ent.ksw + have Cl := poolRt_clrA J P + refine J.domOK.keepS J.sr.toSchedSRN (poolRec_domKeep C J P) P.w.1 P.w.2.1 fun b hb hd => P.w.mem_eq hb (fun h => ?_) + rcases h with h | ⟨g1, g2⟩ | e + · exact J.capw_domA h hd + · unfold DomW at hd + rcases Cl.ks with g | g <;> omega + · rw [e, DomW] at hd + rw [atAF_valA hks P.hi] at hd + omega + +theorem poolRec_ipi : Sched.SilentScheduleIpiA (st := st) s5 := by + have hks : (L.ksb sr).val + 788736 ≤ 2 ^ 64 := J.sys.ent.ksw + have Cl := poolRt_clrA J P + refine J.ipiKeepOf P.w fun o ho h => ?_ + obtain ⟨hv, hcl⟩ := J.sr.toSchedSRN.ipi_val ho + rcases h with h | ⟨g1, g2⟩ | e + · exact J.ipi_capwA ho h + · rcases Cl.ks with g | g <;> omega + · have := congrArg UScalar.val e + rw [atAF_valA hks P.hi] at this + omega + +theorem poolRec_vcSnap : VcpuStateSnapA Zn.V (L.mem s5) σ' := by + have conv : ∀ v ∈ Zn.V, ∀ x, σ'.kheap (specPtr v) = some (.archObj (.vcpu x)) → + σ1.kheap (specPtr v) = some (.archObj (.vcpu x)) := fun v _ x hk => by + have ne : specPtr v ≠ specPtr frame := fun e => by rw [e, P.pool] at hk; cases hk + rcases P.kh _ ne with k | ⟨r, cs, cs', h1, h2, -⟩ + · rw [← k]; exact hk + · rw [h2] at hk; cases hk + refine ⟨fun v hv x hk => ?_, fun v hv x hk => ?_⟩ + · have exy := conv v hv x hk + rw [C.eV] at hv + obtain ⟨g1, g2, g3, g4, g5⟩ := J.vcSnap.snap v hv x exy + have words : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s5 (wa v o) = L.mem sr (wa v o) := fun o o1 o8 => + poolRec_vcWord C J P hv o1 o8 + refine ⟨fun i hi => ?_, ?_, ?_, ?_, ?_⟩ + · obtain ⟨o1, o2⟩ := snapOffA i hi + rw [words _ o1 o2]; exact g1 i hi + · rw [words 16#u64 (by simp) (by simp)]; exact g2 + · rw [words 32#u64 (by simp) (by simp)]; exact g3 + · rw [words 40#u64 (by simp) (by simp)]; exact g4 + · rw [words 8#u64 (by simp) (by simp)]; exact g5 + · rw [C.eV] at hv + exact J.vcSnap.mask v hv x (conv v (by rw [C.eV]; exact hv) x hk) + +/-- **The record-edit-#5/#6 fields and the tail but `bufVs` after MakePool** (module docstring). `symL` is Group C's +`SymL` over the grown heap. -/ +theorem poolRt_recA (symL : SymL st (PoolH Hd frame 12) Zn.Cs s5) : + PoolRecOutA st Zn (PoolH Hd frame 12) OSd s5 σ' := + { heapWin := poolRec_heapWin C J P + coresAll := poolRec_coresAll C J P + ptCapIn := poolRec_ptCapIn C J P + symL := symL + fhOK := poolRec_fhOK C J P + zwf := poolRec_zwf C J P + schedValid := poolRec_schedValid C J P + utWin := poolRec_utWin C J P + devWin := poolRec_devWin C J P + vcBack := poolRec_vcBack C J P + runBack := poolRec_runBack C J P + vcOS := fun b hb => J.vcOS b (by rwa [C.eV] at hb) + userFr := poolRec_userFr C J P + frTh := poolRec_frTh C J P + vcSnap := poolRec_vcSnap C J P + domOK := poolRec_domOK C J P + ipiZero := poolRec_ipi C J P } + +theorem poolRec_fit : frame.val + 4096 ≤ 2 ^ 64 := by + have h1 := (J.sys.sysl.sys.ur _ P.mem frame 12#u64 fi false P.cap).1.1 + have h12 : (12#u64 : U64).val = 12 := rfl + rw [h12] at h1 + have hfl : frame.val < 2 ^ 64 := by simpa using frame.hBounds + simp only [Nat.reducePow] at h1 ⊢ + omega + +/-- **`bufVs` after MakePool**: the reachable VSpace set grows by the pool page only (`hgrow`, from A64 P1's end +state), and no tracked buffer word lies in the pool page (buffer words are frame words of `OS` caps; their typed +objects are off the block). -/ +theorem poolRt_bufVsA {Tb' : Set U64} {Lv' : U64 → Nat} + (hgrow : utVsPtA st (insert frame Pp) Tb' Lv' s5 ⊆ utVsPtA st Pp Tb Lv sr ∪ {frame}) : + ∀ b, Endp.BufW Bf b → ¬ VsR (L.ksb s5) (utVsPtA st (insert frame Pp) Tb' Lv' s5) b := by + intro b hb hv + rw [P.w.1] at hv + rcases hv with ⟨p, hp, o, h1, h2, e⟩ | hv + · rcases hgrow hp with g | g + · exact J.bufVs b hb (Or.inl ⟨p, g, o, h1, h2, e⟩) + · have pe : p = frame := g + subst pe + obtain ⟨al, y, hO, ptr, size, rights, x1, x2, x3, x4, bits, hc, hs, g1, g2⟩ := J.bufOff.frameWordsA hb + obtain ⟨b0, len, th, tb1, tb2⟩ := J.frTh y hO ptr size rights x1 x2 x3 x4 bits hc hs + have jo : JointObjectA Zd Hd b0 len := Or.inr (Or.inr (Or.inl ⟨_, th, rfl⟩)) + have fit := poolRec_fit C J P + have ev : (wa p o).val = p.val + o.val := by rw [wa_valP]; exact Nat.mod_eq_of_lt (by omega) + rw [e] at g1 g2 + have g1' := le_trans (show b0.val ≤ ptr.val by omega) g1 + have g2' := lt_of_lt_of_le g2 (show ptr.val + 2 ^ bits.val ≤ b0.val + len by omega) + exact (poolRt_clrA J P).inObj jo g1' g2' ⟨by omega, by omega⟩ + · exact J.bufVs b hb (Or.inr hv) + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolShapeA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolShapeA.lean new file mode 100644 index 000000000..27bf6f5ea --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolShapeA.lean @@ -0,0 +1,614 @@ +/- +P3 (aarch64, Stage 5, line pool, group A): **the spec, IPC and scheduler fields of the record after +`ARMASIDControlMakePool`**, from the shared context `PoolCtxA`. + +Group A of the four field-group modules: 36 `JStage3A` fields (spec group, IPC group, scheduler group, `blkQ`, `bfSpec`, +`curVcpuNone`), as `PoolShapeOutA`. It reads only the spec side and the cap split, from `PoolCtxA` and the post-restart +dropped record `J` (all the field-group modules run on `J1 = of_restartCurA` of the dropped record). + +Named inputs (all derived by the assembly, none new): `hK` (`OSKeep` across the restart write), `hR` (the dropped spec +heap is empty on the pool page: `σ1 = stUpdA (detype D σ0) …`) and `hdr` [W] (the destination CNode's radix is not `0`, so it +is no IRQ node: from the decode site's CNode cap and `CapValidA`). +-/ +import Fl4ProofsA64.P3.Stage3PoolCoreA +import Fl4ProofsA64.P3.Stage3PoolIpcA +import Fl4ProofsA64.P3.Stage3PoolCapsA +import Fl4ProofsA64.P3.Stage3PoolSpecA +import Fl4ProofsA64.P3.CnSlotSbA + +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 + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} {nA : U64} +variable {AR : A → HwRootA → Prop} {Zd Zn : XSetsA} {Hd : Heap} {OSd 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 s5 : S} {a : A} {σ1 σ' : State Unit} {m m' : McState} {parent dest : CslotPtr} + {frame fi i base : U64} + +/-- **The group's output**: the spec, IPC and scheduler fields of the grown record `Zn`. -/ +structure PoolShapeOutA (st : machine.Store S) [L : LawfulStore st] (Zd Zn : XSetsA) (Hd : Heap) (OSd : Set U64) + (ia ie : Nat) (N E Rp : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (stack : U64 → List U64) + (κ : U64 → U64) (n : Nat) (s5 : S) (σ' : State Unit) (m' : McState) : Prop where + spec : UtAsmSpecOutA st Zn OSd ia ie s5 σ' m' + ipc : UtAsmIpcOutA st Zd.T Zd.C Zd.th Hd N E Rp Bf stack n s5 σ' m' + sched : UtAsmSchedOutA st Zn κ s5 σ' m' n + blkQ : BlkQueuedA Zd.T E N (L.mem s5) σ' + bfSpec : ∀ bp ∈ Bf, bp.2 = specPtr bp.1 + curVcpuNone : σ'.archState.armCurrentVcpu = none + +/-- The cap split of the slot set after MakePool. -/ +theorem poolShape_slotsA + (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base) + {s1 : S} (hK : OSKeep st OSd s s1) : + PoolSlotsA st OSd OSd s1 s5 (cslotAddrA parent) (cslotAddrA dest) frame base := by + intro u hu + by_cases hx : u = cslotAddrA parent + · exact Or.inr (Or.inl ⟨hx, hx ▸ C.expo.capP⟩) + by_cases hv : u = cslotAddrA dest + · exact Or.inr (Or.inr ⟨hv, hv ▸ C.expo.capD⟩) + exact Or.inl ⟨hu, hx, hv, (C.expo.capK u hu hx hv).trans (hK.capA hu).symm⟩ + + +/-- **The spec outcome of MakePool, explicitly** (module docstring): the five spec steps as updates of `σ1`. The pool +page is empty before and holds the new ASID pool after; the CNodes change in the parent's and destination's slots only; +the CDT, the original-cap map and the ASID table change at the destination and the new table index only. -/ +structure PoolSpecShapeA (σ1 σ' : State Unit) (parent dest : CslotPtr) (frame i base : U64) : Prop where + fresh : σ1.kheap (specPtr frame) = none + pool : σ'.kheap (specPtr frame) = some (.archObj (.asidPool fun _ => none)) + cn : ∀ q r cs, σ1.kheap q = some (.cnode r cs) → ∃ cs', σ'.kheap q = some (.cnode r cs') ∧ ∀ idx, + cs' idx = if q = dest.1 ∧ idx = dest.2 then some (absCapA (.AsidPool frame base)) else + if q = parent.1 ∧ idx = parent.2 then some (absCapA (.Untyped frame 12#u64 4096#u64 false)) else cs idx + nc : ∀ q, q ≠ specPtr frame → (∀ r cs, σ1.kheap q ≠ some (.cnode r cs)) → σ'.kheap q = σ1.kheap q + wf : ∀ q n, (∃ cs, σ'.kheap q = some (.cnode n cs) ∧ wellFormedCnodeN n cs) ↔ + (∃ cs, σ1.kheap q = some (.cnode n cs) ∧ wellFormedCnodeN n cs) + um : ∀ w, σ'.machineState.underlyingMemory w = σ1.machineState.underlyingMemory w ∨ + (σ'.machineState.underlyingMemory w = 0 ∧ specPtr frame ≤ w ∧ w ≤ specPtr frame + 2 ^ pageBits - 1) + glob : SpecGlobA σ1 { σ' with machineState := σ1.machineState, archState := σ1.archState } + cdt : ∃ b : Bool, σ'.cdt = Function.update σ1.cdt dest (if b then some parent else σ1.cdt parent) + orig : ∃ v : Bool, σ'.isOriginalCap = Function.update σ1.isOriginalCap dest v + tab : σ'.archState = { σ1.archState with + armAsidTable := Function.update σ1.archState.armAsidTable (BitVec.ofNat 7 i.val) (some (specPtr frame)) } + +theorem poolSpecShapeA + (E : MakePoolExpoA st Hd OSd s s5 σ1 σ' parent dest frame i base) + (hR : ∀ p ∈ utDA frame 12, σ1.kheap p = none) (hfr : specPtr frame ∈ utDA frame 12) + (hP : ∃ r cs, σ1.kheap parent.1 = some (.cnode r cs)) (hD : ∃ r cs, σ1.kheap dest.1 = some (.cnode r cs)) : + PoolSpecShapeA σ1 σ' parent dest frame i base := by + obtain ⟨ms', ko3, σ5, hms, S1, S2, W1, W2, hk3, ⟨ko5, b, v, h5, hk5⟩, h'⟩ := E.spec + obtain ⟨rP, csP, hkP⟩ := hP + obtain ⟨rD, csD, hkD⟩ := hD + have fresh : σ1.kheap (specPtr frame) = none := hR _ hfr + have h2 : ∀ q, (poolDelA σ1 ms' frame).kheap q = σ1.kheap q := fun q => by + unfold poolDelA Fl4SpecA64.detype + dsimp only + split_ifs with h + · exact (hR q h).symm + · rfl + have hdf : dest.1 ≠ specPtr frame := fun e => by rw [e, fresh] at hkD; cases hkD + have hpf : parent.1 ≠ specPtr frame := fun e => by rw [e, fresh] at hkP; cases hkP + have e3 : ko3 = .cnode rP (Function.update csP parent.2 (some (absCapA (.Untyped frame 12#u64 4096#u64 false)))) := + hk3 rP csP ((h2 _).trans hkP) + have K : ∀ q, σ'.kheap q = if q = dest.1 then some ko5 else + if q = specPtr frame then some (.archObj (.asidPool fun _ => none)) else + if q = parent.1 then some ko3 else σ1.kheap q := by + intro q + have : σ'.kheap q = Function.update (Function.update (Function.update (poolDelA σ1 ms' frame).kheap parent.1 + (some ko3)) (specPtr frame) (some (.archObj (.asidPool fun _ => none)))) dest.1 (some ko5) q := by + rw [h', h5]; rfl + rw [this] + simp only [Function.update_apply, h2] + have k4 : (poolRetA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) frame).kheap dest.1 = + if dest.1 = parent.1 then some ko3 else σ1.kheap dest.1 := by + simp only [poolRetA, setObjA, Function.update_apply, hdf, h2, if_false] + have kD : ∃ cs5, ko5 = .cnode rD cs5 ∧ ∀ idx, cs5 idx = + if idx = dest.2 then some (absCapA (.AsidPool frame base)) else + if dest.1 = parent.1 ∧ idx = parent.2 then some (absCapA (.Untyped frame 12#u64 4096#u64 false)) else csD idx := by + by_cases hdp : dest.1 = parent.1 + · have hr : rD = rP ∧ csD = csP := by + rw [hdp, hkP] at hkD + injection hkD with h1 + injection h1 with h2 h3 + exact ⟨h2.symm, h3.symm⟩ + obtain ⟨h1, h2'⟩ := hr + subst h1 h2' + have := hk5 rD _ (show (poolRetA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) frame).kheap dest.1 = + some (.cnode rD (Function.update csD parent.2 (some (absCapA (.Untyped frame 12#u64 4096#u64 false))))) by + rw [k4, if_pos hdp, e3]) + exact ⟨_, this, fun idx => by simp [Function.update_apply, hdp]⟩ + · have := hk5 rD csD (by rw [k4, if_neg hdp]; exact hkD) + exact ⟨_, this, fun idx => by simp [Function.update_apply, hdp]⟩ + have cn : ∀ q r cs, σ1.kheap q = some (.cnode r cs) → ∃ cs', σ'.kheap q = some (.cnode r cs') ∧ ∀ idx, + cs' idx = if q = dest.1 ∧ idx = dest.2 then some (absCapA (.AsidPool frame base)) else + if q = parent.1 ∧ idx = parent.2 then some (absCapA (.Untyped frame 12#u64 4096#u64 false)) else cs idx := by + intro q r cs hq + have hqf : q ≠ specPtr frame := fun e => by rw [e, fresh] at hq; cases hq + by_cases hqd : q = dest.1 + · subst hqd + rw [hkD] at hq + injection hq with h1 + injection h1 with h2 h3 + subst h2 h3 + obtain ⟨cs5, he, hf⟩ := kD + refine ⟨cs5, ?_, fun idx => ?_⟩ + · rw [K, if_pos rfl, he] + · rw [hf idx] + by_cases hi : idx = dest.2 <;> simp [hi] + · by_cases hqp : q = parent.1 + · subst hqp + rw [hkP] at hq + injection hq with h1 + injection h1 with h2 h3 + subst h2 h3 + refine ⟨Function.update csP parent.2 (some (absCapA (.Untyped frame 12#u64 4096#u64 false))), ?_, fun idx => ?_⟩ + · rw [K, if_neg hqd, if_neg hqf, if_pos rfl, e3] + · simp [Function.update_apply, hqd] + · exact ⟨cs, by rw [K, if_neg hqd, if_neg hqf, if_neg hqp]; exact hq, fun idx => by simp [hqd, hqp]⟩ + have nc : ∀ q, q ≠ specPtr frame → (∀ r cs, σ1.kheap q ≠ some (.cnode r cs)) → σ'.kheap q = σ1.kheap q := by + intro q hqf hn + have hqd : q ≠ dest.1 := fun e => hn _ _ (e ▸ hkD) + have hqp : q ≠ parent.1 := fun e => hn _ _ (e ▸ hkP) + rw [K, if_neg hqd, if_neg hqf, if_neg hqp] + have w1 : ∀ q n, (∃ cs, (setObjA (poolDelA σ1 ms' frame) parent.1 ko3).kheap q = some (.cnode n cs) ∧ + wellFormedCnodeN n cs) ↔ (∃ cs, σ1.kheap q = some (.cnode n cs) ∧ wellFormedCnodeN n cs) := fun q n => by + have := W1 q n + simp only [h2] at this + exact this + have w2 : ∀ q n, (∃ cs, (poolRetA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) frame).kheap q = + some (.cnode n cs) ∧ wellFormedCnodeN n cs) ↔ (∃ cs, (setObjA (poolDelA σ1 ms' frame) parent.1 ko3).kheap q = + some (.cnode n cs) ∧ wellFormedCnodeN n cs) := by + intro q n + by_cases hq : q = specPtr frame + · subst hq + constructor + · rintro ⟨cs, h, -⟩ + simp [poolRetA] at h + · rintro ⟨cs, h, -⟩ + simp [setObjA, Function.update_apply, h2, fresh, hpf.symm] at h + · have : (poolRetA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) frame).kheap q = + (setObjA (poolDelA σ1 ms' frame) parent.1 ko3).kheap q := by + simp only [poolRetA, Function.update_apply, if_neg hq] + rw [this] + have hker : ∀ q, σ'.kheap q = σ5.kheap q := fun q => by rw [h']; rfl + have k1 : SpecGlobKeyA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) = SpecGlobKeyA (poolDelA σ1 ms' frame) := + S1.toSpecGlobA.key + have k2 : SpecGlobKeyA σ5 = SpecGlobKeyA (poolRetA (setObjA (poolDelA σ1 ms' frame) parent.1 ko3) frame) := + S2.toSpecGlobA.key + have k0 : SpecGlobKeyA (poolDelA σ1 ms' frame) = SpecGlobKeyA σ1 := rfl + have kk : SpecGlobKeyA σ5 = SpecGlobKeyA σ1 := k2.trans (k1.trans k0) + refine + { fresh := fresh + pool := by rw [K, if_neg hdf.symm, if_pos rfl] + cn := cn + nc := nc + wf := fun q n => by + simp only [hker] + exact (W2 q n).trans ((w2 q n).trans (w1 q n)) + um := fun w => by + have e : σ'.machineState = ms' := by rw [h', h5]; rfl + rw [e]; exact hms w + glob := SpecGlobA.ofKey ((show SpecGlobKeyA { σ' with machineState := σ1.machineState, archState := σ1.archState } + = SpecGlobKeyA σ5 by rw [h', h5]; rfl).trans kk) + cdt := ⟨b, by rw [h', h5]; rfl⟩ + orig := ⟨v, by rw [h', h5]; rfl⟩ + tab := by rw [h', h5]; rfl } + + +/-- A CNode of the old heap is unique: two contents at one address and radix are equal. -/ +theorem poolShape_cnUniq {σ : State Unit} {q : ObjRef} {r : Nat} {cs cs0 : CnodeContents} + (h : σ.kheap q = some (.cnode r cs)) (h0 : σ.kheap q = some (.cnode r cs0)) : cs = cs0 := by + rw [h] at h0 + have := Option.some.inj h0 + injection this + +theorem specCapAtA_cnodeA {σ : State Unit} {sl : CslotPtr} {r : Nat} {cs : CnodeContents} + (h : σ.kheap sl.1 = some (.cnode r cs)) : + specCapAtA σ sl = if wellFormedCnodeN r cs then cs sl.2 else none := by + unfold specCapAtA + rw [h] + +/-- A cap of the grown spec outside the parent and destination slots is the old one. -/ +theorem poolShape_capKeepA (Sh : PoolSpecShapeA σ1 σ' parent dest frame i base) {sl : CslotPtr} + (hp : sl ≠ parent) (hd : sl ≠ dest) : specCapAtA σ' sl = specCapAtA σ1 sl := by + have hd' : ¬ (sl.1 = dest.1 ∧ sl.2 = dest.2) := fun ⟨a, b⟩ => hd (Prod.ext a b) + have hp' : ¬ (sl.1 = parent.1 ∧ sl.2 = parent.2) := fun ⟨a, b⟩ => hp (Prod.ext a b) + by_cases hc : ∃ r cs, σ1.kheap sl.1 = some (.cnode r cs) + · obtain ⟨r, cs, hq⟩ := hc + obtain ⟨cs', h1, hf⟩ := Sh.cn sl.1 r cs hq + have e : cs' sl.2 = cs sl.2 := by rw [hf sl.2, if_neg hd', if_neg hp'] + have hw : wellFormedCnodeN r cs' ↔ wellFormedCnodeN r cs := by + constructor + · intro hw + obtain ⟨cs0, h0, hw0⟩ := (Sh.wf sl.1 r).1 ⟨cs', h1, hw⟩ + rw [poolShape_cnUniq hq h0]; exact hw0 + · intro hw + obtain ⟨cs0, h0, hw0⟩ := (Sh.wf sl.1 r).2 ⟨cs, hq, hw⟩ + rw [poolShape_cnUniq h1 h0]; exact hw0 + rw [specCapAtA_cnodeA h1, specCapAtA_cnodeA hq] + simp only [hw, e] + · by_cases hf : sl.1 = specPtr frame + · unfold specCapAtA + rw [hf, Sh.pool, Sh.fresh] + · unfold specCapAtA + rw [Sh.nc sl.1 hf (fun r cs e => hc ⟨r, cs, e⟩)] + +/-- The new caps: the destination holds the pool cap, the parent the full untyped cap. -/ +theorem poolShape_capNewA (Sh : PoolSpecShapeA σ1 σ' parent dest frame i base) (hne : parent ≠ dest) + {rD rP : Nat} {csD csP : CnodeContents} (hkD : σ1.kheap dest.1 = some (.cnode rD csD)) + (hkP : σ1.kheap parent.1 = some (.cnode rP csP)) : + (∀ c, specCapAtA σ' dest = some c → c = absCapA (.AsidPool frame base)) ∧ + (∀ c, specCapAtA σ' parent = some c → c = absCapA (.Untyped frame 12#u64 4096#u64 false)) := by + constructor + · intro c h + obtain ⟨cs', h1, hf⟩ := Sh.cn dest.1 rD csD hkD + rw [specCapAtA_cnodeA h1] at h + by_cases w : wellFormedCnodeN rD cs' + · rw [if_pos w, hf dest.2, if_pos ⟨rfl, rfl⟩] at h + exact (Option.some.inj h).symm + · rw [if_neg w] at h; cases h + · intro c h + obtain ⟨cs', h1, hf⟩ := Sh.cn parent.1 rP csP hkP + have hpd : ¬ (parent.1 = dest.1 ∧ parent.2 = dest.2) := fun ⟨a, b⟩ => hne (Prod.ext a b) + rw [specCapAtA_cnodeA h1] at h + by_cases w : wellFormedCnodeN rP cs' + · rw [if_pos w, hf parent.2, if_neg hpd, if_pos ⟨rfl, rfl⟩] at h + exact (Option.some.inj h).symm + · rw [if_neg w] at h; cases h + +theorem noIdle_asidPoolA (m : McState) (n : Nat) (frame base : U64) : + NoIdleCapV m n (absCapA (.AsidPool frame base)) := + ⟨fun c _ e => by simp [absCapA] at e, fun b e => by simp [absCapA] at e, + fun p asid va e => by simp [absCapA] at e⟩ + +theorem noIdle_untypedA (m : McState) (n : Nat) (frame : U64) (fi : U64) : + NoIdleCapV m n (absCapA (.Untyped frame 12#u64 fi false)) := + ⟨fun c _ e => by simp [absCapA] at e, fun b e => by simp [absCapA] at e, + fun p asid va e => by simp [absCapA] at e⟩ + +theorem poolShape_newCapA (Sh : PoolSpecShapeA σ1 σ' parent dest frame i base) (hne : parent ≠ dest) + {rD rP : Nat} {csD csP : CnodeContents} (hkD : σ1.kheap dest.1 = some (.cnode rD csD)) + (hkP : σ1.kheap parent.1 = some (.cnode rP csP)) (m : McState) (n : Nat) : + ∀ sl, (∃ sl0, specCapAtA σ' sl = specCapAtA σ1 sl0) ∨ ∀ c, specCapAtA σ' sl = some c → NoIdleCapV m n c := by + intro sl + obtain ⟨hA, hU⟩ := poolShape_capNewA Sh hne hkD hkP + by_cases hd : sl = dest + · right + intro c h + rw [hd] at h + rw [hA c h]; exact noIdle_asidPoolA m n frame base + by_cases hp : sl = parent + · right + intro c h + rw [hp] at h + rw [hU c h]; exact noIdle_untypedA m n frame 4096#u64 + · left + exact ⟨sl, poolShape_capKeepA Sh hp hd⟩ + +/-- The original-cap clause. -/ +theorem poolShape_origA (Sh : PoolSpecShapeA σ1 σ' parent dest frame i base) (hne : parent ≠ dest) {s1 : S} + {rD rP : Nat} {csD csP : CnodeContents} (hkD : σ1.kheap dest.1 = some (.cnode rD csD)) + (hkP : σ1.kheap parent.1 = some (.cnode rP csP)) {th : TypedHeapA} + (hS : SpecFreeA st OSd s1 σ1) (hAP : AbsSlotA th parent) (hAD : AbsSlotA th dest) : + ∀ sl, σ'.isOriginalCap sl = true → + (σ1.isOriginalCap sl = true ∧ specCapAtA σ' sl = specCapAtA σ1 sl) ∨ + ((∀ q : U64, UtFreeA st OSd s1 (fun _ => True) q.val → sl.1 ≠ specPtr q) ∧ AbsSlotA th sl ∧ + specCapAtA σ' sl ≠ some .nullCap) := by + intro sl h + obtain ⟨v, hv⟩ := Sh.orig + obtain ⟨hA, hU⟩ := poolShape_capNewA Sh hne hkD hkP + rw [hv, Function.update_apply] at h + have free : ∀ (c : CslotPtr), σ1.kheap c.1 ≠ none → ∀ q : U64, UtFreeA st OSd s1 (fun _ => True) q.val → + c.1 ≠ specPtr q := fun c hc q hq e => hc (by rw [e]; exact hS.heap q hq) + by_cases hd : sl = dest + · right + refine ⟨free sl (by rw [hd, hkD]; simp), hd ▸ hAD, fun hh => ?_⟩ + rw [hd] at hh + have := hA _ hh + simp [absCapA] at this + · rw [if_neg hd] at h + by_cases hp : sl = parent + · right + refine ⟨free sl (by rw [hp, hkP]; simp), hp ▸ hAP, fun hh => ?_⟩ + rw [hp] at hh + have := hU _ hh + simp [absCapA] at this + · left + exact ⟨h, poolShape_capKeepA Sh hp hd⟩ + +/-- The heap clause of `PoolStepA`: the changed objects are CNodes. -/ +theorem poolShape_khA (Sh : PoolSpecShapeA σ1 σ' parent dest frame i base) : + ∀ p, p ≠ specPtr frame → σ'.kheap p = σ1.kheap p ∨ + ∃ r cs cs', σ1.kheap p = some (.cnode r cs) ∧ σ'.kheap p = some (.cnode r cs') ∧ + (wellFormedCnodeN r cs' → wellFormedCnodeN r cs) := by + intro p hp + by_cases h : ∃ r cs, σ1.kheap p = some (.cnode r cs) + · obtain ⟨r, cs, hq⟩ := h + obtain ⟨cs', h1, -⟩ := Sh.cn p r cs hq + refine Or.inr ⟨r, cs, cs', hq, h1, fun hw => ?_⟩ + obtain ⟨cs0, h0, hw0⟩ := (Sh.wf p r).1 ⟨cs', h1, hw⟩ + rw [poolShape_cnUniq hq h0]; exact hw0 + · exact Or.inl (Sh.nc p hp (fun r cs e => h ⟨r, cs, e⟩)) + +/-- The memory clause of `PoolStepA`: only page bytes are zeroed. -/ +theorem poolShape_umA (Sh : PoolSpecShapeA σ1 σ' parent dest frame i base) (hp : frame.val + 2 ^ 12 ≤ 2 ^ 64) + (hsp : (specPtr frame).toNat + 2 ^ 12 ≤ 2 ^ 64) : + ∀ w, σ'.machineState.underlyingMemory w = σ1.machineState.underlyingMemory w ∨ + (σ'.machineState.underlyingMemory w = 0 ∧ ∃ q : U64, w = specPtr q ∧ frame.val ≤ q.val ∧ + q.val < frame.val + 4096) := by + intro w + rcases Sh.um w with h | ⟨h0, h1, h2⟩ + · exact Or.inl h + · right + refine ⟨h0, fl4Ptr w, (specPtr_fl4Ptr w).symm, ?_⟩ + have hm : specPtr (fl4Ptr w) ∈ utDA frame 12 := by + rw [specPtr_fl4Ptr] + exact ⟨h1, h2⟩ + have := (utD_memA (by norm_num) hp hsp (fl4Ptr w)).1 hm + omega + +/-- The CDT clause of `PoolStepA`. -/ +theorem poolShape_cdtA (Sh : PoolSpecShapeA σ1 σ' parent dest frame i base) {OS : Set U64} {s1 : S} + (hS : SpecFreeA st OS s1 σ1) {rD rP : Nat} {csD csP : CnodeContents} + (hkD : σ1.kheap dest.1 = some (.cnode rD csD)) (hkP : σ1.kheap parent.1 = some (.cnode rP csP)) : + ∀ c d, σ'.cdt c = some d → σ1.cdt c = some d ∨ + ∀ q : U64, UtFreeA st OS s1 (fun _ => True) q.val → c.1 ≠ specPtr q ∧ d.1 ≠ specPtr q := by + intro c d h + obtain ⟨b, hb⟩ := Sh.cdt + rw [hb, Function.update_apply] at h + by_cases hc : c = dest + · right + intro q hq + have hdn : c.1 ≠ specPtr q := fun e => by + have := hS.heap q hq + rw [← e, hc, hkD] at this + cases this + rw [if_pos hc] at h + by_cases hb' : b + · rw [if_pos hb'] at h + have hd := Option.some.inj h + subst hd + exact ⟨hdn, fun e => by + have := hS.heap q hq + rw [← e, hkP] at this + cases this⟩ + · rw [if_neg hb'] at h + exact ⟨hdn, (hS.cdt parent d h q hq).2⟩ + · left + rw [if_neg hc] at h + exact h + +/-- The ASID table stays injective. -/ +theorem poolShape_tabInjA (Sh : PoolSpecShapeA σ1 σ' parent dest frame i base) + (hI : ∀ i j r, σ1.archState.armAsidTable i = some r → σ1.archState.armAsidTable j = some r → i = j) + (hnot : ∀ k : BitVec 7, σ1.archState.armAsidTable k ≠ some (specPtr frame)) : + ∀ i' j r, σ'.archState.armAsidTable i' = some r → σ'.archState.armAsidTable j = some r → i' = j := by + intro i' j r h1 h2 + rw [Sh.tab] at h1 h2 + simp only [Function.update_apply] at h1 h2 + by_cases a1 : i' = BitVec.ofNat 7 i.val <;> by_cases a2 : j = BitVec.ofNat 7 i.val + · exact a1.trans a2.symm + · rw [if_pos a1] at h1 + rw [if_neg a2] at h2 + rw [← Option.some.inj h1] at h2 + exact absurd h2 (hnot j) + · rw [if_neg a1] at h1 + rw [if_pos a2] at h2 + rw [← Option.some.inj h2] at h1 + exact absurd h1 (hnot i') + · rw [if_neg a1] at h1 + rw [if_neg a2] at h2 + exact hI i' j r h1 h2 + +/-- The IRQ node clause of `PoolStepA`. -/ +theorem poolShape_irqA (Sh : PoolSpecShapeA σ1 σ' parent dest frame i base) (hI : SpecIrqA σ1) + {rD rP : Nat} {csD csP : CnodeContents} (hkD : σ1.kheap dest.1 = some (.cnode rD csD)) + (hwD : wellFormedCnodeN rD csD) (hrD : rD ≠ 0) (hkP : σ1.kheap parent.1 = some (.cnode rP csP)) + (hwP : wellFormedCnodeN rP csP) {fi : U64} + (hcP : csP parent.2 = some (absCapA (.Untyped frame 12#u64 fi false))) : SpecIrqA σ' := by + have hn : σ'.interruptIrqNode = σ1.interruptIrqNode := Sh.glob.irqN + have hnp : ∀ irq : Irq, σ1.interruptIrqNode irq ≠ parent.1 := by + intro irq e + by_cases hlt : irq.toNat < fl4IrqCount + · have := hI.slot irq hlt _ parent.2 _ (by rw [e]; exact hkP) (show capOf (.cnode rP csP) parent.2 = _ from hcP) + rcases this with g | ⟨_, _, _, g⟩ <;> simp [absCapA] at g + · exact hI.node.2 irq (by omega) rP ⟨csP, by rw [e]; exact hkP, hwP⟩ + have hnd : ∀ irq : Irq, σ1.interruptIrqNode irq ≠ dest.1 := by + intro irq e + by_cases hlt : irq.toNat < fl4IrqCount + · obtain ⟨cs0, h0, -⟩ := hI.node.1.2 irq hlt + rw [e, hkD] at h0 + have := Option.some.inj h0 + injection this with h1 + exact hrD h1 + · exact hI.node.2 irq (by omega) rD ⟨csD, by rw [e]; exact hkD, hwD⟩ + refine ⟨⟨⟨?_, fun irq hlt => ?_⟩, fun irq hge k => ?_⟩, fun irq hlt o b a ho hcap => ?_, + fun q o b a ho hcap => ?_⟩ + · intro i' j hi hj e + rw [hn] at e + exact hI.node.1.1 i' j hi hj e + · rw [hn] + obtain ⟨cs0, h0, hw0⟩ := hI.node.1.2 irq hlt + exact (Sh.wf _ 0).2 ⟨cs0, h0, hw0⟩ + · rw [hn] + intro hh + exact hI.node.2 irq hge k ((Sh.wf _ k).1 hh) + · rw [hn] at ho + obtain ⟨cs0, h0, hw0⟩ := hI.node.1.2 irq hlt + obtain ⟨cs', h1, hf⟩ := Sh.cn _ 0 cs0 h0 + rw [h1] at ho + have eo := (Option.some.inj ho).symm + subst eo + have e1 : ¬ (σ1.interruptIrqNode irq = dest.1 ∧ b = dest.2) := fun ⟨h, _⟩ => hnd irq h + have e2 : ¬ (σ1.interruptIrqNode irq = parent.1 ∧ b = parent.2) := fun ⟨h, _⟩ => hnp irq h + change cs' b = some a at hcap + rw [hf b, if_neg e1, if_neg e2] at hcap + exact hI.slot irq hlt _ b a h0 (show capOf (.cnode 0 cs0) b = _ from hcap) + · rw [hn] + by_cases hqf : q = specPtr frame + · rw [hqf, Sh.pool] at ho + have eo := (Option.some.inj ho).symm + subst eo + simp [capOf] at hcap + · by_cases hc : ∃ r cs, σ1.kheap q = some (.cnode r cs) + · obtain ⟨r, cs, hq⟩ := hc + obtain ⟨cs', h1, hf⟩ := Sh.cn q r cs hq + rw [h1] at ho + have eo := (Option.some.inj ho).symm + subst eo + change cs' b = some a at hcap + rw [hf b] at hcap + by_cases e1 : q = dest.1 ∧ b = dest.2 + · rw [if_pos e1] at hcap + have := Option.some.inj hcap + subst this + rintro ⟨irq, -, n', g, hg⟩ + simp [absCapA] at hg + · rw [if_neg e1] at hcap + by_cases e2 : q = parent.1 ∧ b = parent.2 + · rw [if_pos e2] at hcap + have := Option.some.inj hcap + subst this + rintro ⟨irq, -, n', g, hg⟩ + simp [absCapA] at hg + · rw [if_neg e2] at hcap + exact hI.ref q (.cnode r cs) b a hq (show capOf (.cnode r cs) b = _ from hcap) + · rw [Sh.nc q hqf (fun r cs e => hc ⟨r, cs, e⟩)] at ho + exact hI.ref q o b a ho hcap + + +variable {J7 : JSlotA S} + +/-- **Group A: the spec, IPC and scheduler fields of the record after MakePool** (module docstring). `J` is the dropped +record after the caller's restart write (`s1`, `JStage3A.of_restartCurA`), `hK` the `OSKeep` of that write, `hR` the +dropped spec heap's emptiness on the pool page, `hdr` [W] the destination CNode's radix. -/ +theorem poolShapeFullA + (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base) + {s1 : S} (hs1 : s1 = L.wr s (stA (L.curW s)) sched.TS_RESTART) + (J : JStage3A st AR Zd Hd OSd U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s1 a σ1 m') + (hK : OSKeep st OSd s s1) (hR : ∀ p ∈ utDA frame 12, σ1.kheap p = none) (hdr : dest.2.length ≠ 0) : + PoolShapeOutA st Zd Zn Hd OSd ia ie N E Rp Bf stack κ n s5 σ' m' ∧ + PoolSpecShapeA σ1 σ' parent dest frame i base ∧ + PoolStepA st Zd Hd OSd s1 s5 σ1 σ' m' n (cslotAddrA parent) (cslotAddrA dest) frame fi i := by + have e12 : (12#u64 : U64).val = 12 := rfl + have hK' : OSKeep st OSd s1 s := fun y hy => + ⟨(hK y hy).1.symm, (hK y hy).2.1.symm, (hK y hy).2.2.1.symm, (hK y hy).2.2.2.symm⟩ + have hks1 : L.ksb s1 = L.ksb s := by rw [hs1]; exact L.ksb_wr _ _ _ + have hxO : cslotAddrA parent ∈ OSd := J.j5.2.1 _ (C.absP.isSlot J.j.1.place) + have hcp1 : capA st s1 (cslotAddrA parent) = .Untyped frame 12#u64 fi false := by + rw [hK.capA hxO]; exact C.hcp + obtain ⟨pp, hpe, hpt⟩ := C.holdP + obtain ⟨pd, hde, hdt⟩ := C.holdD + obtain ⟨csP, hkP0, hwP, -⟩ := J.j.1.st.cnode pp _ hpt + obtain ⟨csD, hkD0, hwD, -⟩ := J.j.1.st.cnode pd _ hdt + have hkP : σ1.kheap parent.1 = some (.cnode parent.2.length csP) := by rw [hpe]; exact hkP0 + have hkD : σ1.kheap dest.1 = some (.cnode dest.2.length csD) := by rw [hde]; exact hkD0 + have hne : parent ≠ dest := by + intro e + have h := C.hcd + rw [← e, C.hcp] at h + cases h + -- the pool page lies in the kernel window + have hwin := J.utWin (cslotAddrA parent) hxO frame 12#u64 fi hcp1 + have hbase : layout.PPTR_BASE.val = 18446603336221196288 := by unfold layout.PPTR_BASE; rfl + rw [hbase, e12] at hwin + have hp : frame.val + 2 ^ 12 ≤ 2 ^ 64 := by omega + have hsp : (specPtr frame).toNat + 2 ^ 12 ≤ 2 ^ 64 := by rw [specPtr_toNat]; omega + have hfr : specPtr frame ∈ utDA frame 12 := (utD_memA (by norm_num) hp hsp frame).2 ⟨le_refl _, by omega⟩ + have Sh := poolSpecShapeA C.expo hR hfr ⟨_, csP, hkP⟩ ⟨_, csD, hkD⟩ + -- the parent's cap in the spec + have hcapP : csP parent.2 = some (absCapA (.Untyped frame 12#u64 fi false)) := by + obtain ⟨a0, ha0, hr⟩ := ut_absRelA J.j.1.st C.absP + have h2 := hr.2 + change CapEqA (capA st s1 (cslotAddrA parent)) a0 at h2 + rw [hcp1] at h2 + rw [specCapAtA_cnodeA hkP, if_pos hwP] at ha0 + have h3 : absCapA (.Untyped frame 12#u64 fi false) = a0 := h2 + rw [ha0, h3] + have hZn : ({ Zd with th := Zd.th, Pp := Zn.Pp, G := Zn.G } : XSetsA) = Zn := by rw [C.zn] + -- the step + have hnot : ∀ k : BitVec 7, σ1.archState.armAsidTable k ≠ some (specPtr frame) := by + intro k hk + have hkv : k.toNat < 128 := k.isLt + let hi : U64 := ⟨BitVec.ofNat 64 k.toNat⟩ + have hhi : hi.val = k.toNat := by + show (BitVec.ofNat 64 k.toNat).toNat = _ + rw [BitVec.toNat_ofNat]; omega + have t := J.j.1.vs.table hi (by omega) + have kk : BitVec.ofNat 7 hi.val = k := by + apply BitVec.eq_of_toNat_eq + rw [hhi, BitVec.toNat_ofNat]; omega + rw [kk, hk] at t + by_cases h0 : L.mem s1 (atAF (L.ksb s1) hi) = 0#u64 + · rw [optPtrA, if_pos h0] at t; cases t + · rw [optPtrA, if_neg h0] at t + have e := specPtr_inj (Option.some.inj t) + have hmem := J.j.1.vs.tmem hi (by omega) h0 + obtain ⟨f, hf, -⟩ := J.j.1.vs.pool _ hmem + rw [← e, Sh.fresh] at hf + cases hf + have P : PoolStepA st Zd Hd OSd s1 s5 σ1 σ' m' n (cslotAddrA parent) (cslotAddrA dest) frame fi i := + { mem := hxO + cap := hcp1 + slot := C.absP.isSlot J.j.1.place + sub := J.j5.2.1 + vsb := fun t ht e => cnSlot_ne_sbA J.j.1.place hde hdt (ut_tcbThA J ht).1 e.symm + hi := C.hi + disj := fun q bytes h => ObjAllocA.disjoint_of_drop J.toJEntA.objAlloc hxO hcp1 C.dd h + w := by rw [hks1, hs1]; exact C.expo.w1 + capK := fun y hy hx hv => (C.expo.capK y hy hx hv).trans (hK.capA hy).symm + fresh := Sh.fresh + pool := Sh.pool + kh := poolShape_khA Sh + glob := Sh.glob + um := poolShape_umA Sh hp hsp + cdt := poolShape_cdtA Sh J.specFree hkD hkP + tabInj := poolShape_tabInjA Sh J.toJEntA.tabInj hnot + irq := poolShape_irqA Sh J.sinv.irqN hkD hwD hdr hkP hwP hcapP + newCap := poolShape_newCapA Sh hne hkD hkP m' n } + have F := poolShape_slotsA C hK + have hrev0 : obj.Slot.revocable st (cslotAddrA parent) s = ok true := + (UtRev.keep J.sys.sysl.sys.stz.1.2.1 hK') _ hxO (by rw [C.hcp]; rfl) + have hoth : ∀ u ∈ OSd, u ≠ cslotAddrA parent → ∀ q b f d, capA st s1 u = .Untyped q b f d → + (frame.val + 4096 ≤ q.val ∨ q.val + 2 ^ b.val ≤ frame.val) ∨ + (q.val ≤ frame.val ∧ frame.val + 4096 ≤ q.val + f.val) := by + intro u hu hux q b f d hc + have hcc := pool_utOther (x := cslotAddrA parent) J.sys.sysl.sys hxO hcp1 + (fun G par hT y => cdt.ensure_no_children.noDesc J.sys.ent.os (hT.keepO hK') hxO C.hcp hrev0 C.hnc y) + hu hux hc + rw [e12] at hcc + rcases hcc with (g | g) | g + · exact Or.inl (Or.inl (by omega)) + · exact Or.inl (Or.inr g) + · exact Or.inr ⟨g.1, by omega⟩ + have hpl : PlaceA Zd.th (L.ksb s5) := by rw [P.w.1]; exact J.j.1.place + have horig := poolShape_origA Sh hne hkD hkP (th := Zd.th) J.specFree C.absP C.absD + obtain ⟨hsp', hipc, hsch, hblk⟩ := poolRt_asmIpcSchedA (th' := Zd.th) (Pp' := Zn.Pp) (G' := Zn.G) (H' := Hd) + J P F hoth (fun _ _ h => h) (fun _ _ h => Or.inl h) J.j.1.thT hpl horig (fun _ h => h) (fun _ h => h) + (fun _ h => h) + rw [hZn] at hsp' hsch + exact + ⟨{ spec := hsp' + ipc := hipc + sched := hsch + blkQ := hblk + bfSpec := J.bfSpec + curVcpuNone := by rw [Sh.tab]; exact J.curVcpuNone }, Sh, P⟩ + +/-- **Group A** (statement unchanged): the shape output of `poolShapeFullA`. -/ +theorem poolShapeA + (C : PoolCtxA st AR Zd Hd OSd s s5 a σ1 σ' Zn m m' parent dest frame fi i base) + {s1 : S} (hs1 : s1 = L.wr s (stA (L.curW s)) sched.TS_RESTART) + (J : JStage3A st AR Zd Hd OSd U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s1 a σ1 m') + (hK : OSKeep st OSd s s1) (hR : ∀ p ∈ utDA frame 12, σ1.kheap p = none) (hdr : dest.2.length ≠ 0) : + PoolShapeOutA st Zd Zn Hd OSd ia ie N E Rp Bf stack κ n s5 σ' m' := + (poolShapeFullA C hs1 J hK hR hdr).1 + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolSpecA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolSpecA.lean new file mode 100644 index 000000000..2f8d78ac9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolSpecA.lean @@ -0,0 +1,135 @@ +/- +P3 (aarch64, Stage 4, line vsx-D): **the spec-side fields of the record after `ARMASIDControlMakePool`**, the pool +twin of `P3/UtAsmSpecA`. One transfer from the dropped record (after the caller's restart) to the post state: the +spec zeroes the pool page, updates CNodes (the parent's and the destination's caps), creates the empty ASID pool at +`specPtr frame` and enters it in the ASID table. + +* `poolRt_freeShrinkA`: a free address after the step was free before and is off the pool page (the parent is now + full). `hoth` is the same hypothesis as in `poolRt_objAllocA`. +* `PoolAsmSpecInA`: the step's side of these fields; `poolRt_asmSpecA` gives `UtAsmSpecOutA`. +* `poolRt_specObjA`: the heap change as a one-object creation (`UtNewObjA`), at the spec state with the old machine and + arch state (`UtNewObjA` needs both unchanged). + +No named premise: hypotheses only. New module. +-/ +import Fl4ProofsA64.P3.Stage3PoolCapsA +import Fl4ProofsA64.P3.UtAsmSpecA +import Fl4ProofsA64.P3.UtFullIpcA +import Fl4ProofsA64.P3.FrameA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4SpecA64 Classical + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} +variable {AR : A → HwRootA → Prop} {Z Z' : XSetsA} {H : Heap} {OS 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' : S} {a : A} {σ σ' : State Unit} {m : McState} {x v frame base : U64} + +/-- **A free address after MakePool's step was free before and is off the pool page.** -/ +theorem poolRt_freeShrinkA (F : PoolSlotsA st OS OS' s s' x v frame base) + (hoth : ∀ u ∈ OS, u ≠ x → ∀ q b f d, capA st s u = .Untyped q b f d → + (frame.val + 4096 ≤ q.val ∨ q.val + 2 ^ b.val ≤ frame.val) ∨ + (q.val ≤ frame.val ∧ frame.val + 4096 ≤ q.val + f.val)) + {dev : Bool → Prop} {w : Nat} (h : UtFreeA st OS' s' dev w) : + UtFreeA st OS s dev w ∧ ¬ (frame.val ≤ w ∧ w < frame.val + 4096) := by + obtain ⟨u, hu, q, b, f, d, e, hd, a1, a2⟩ := h + rcases F u hu with ⟨uo, uxe, -, k⟩ | ⟨-, k⟩ | ⟨-, k⟩ + · have e0 := k.symm.trans e + refine ⟨⟨u, uo, q, b, f, d, e0, hd, a1, a2⟩, fun ⟨c1, c2⟩ => ?_⟩ + rcases hoth u uo uxe q b f d e0 with (g | g) | g <;> omega + · have g := k.symm.trans e + simp only [capability.Cap.Untyped.injEq] at g + obtain ⟨g1, g2, g3, -⟩ := g + rw [← g1, ← g3] at a1 + rw [← g1, ← g2] at a2 + have h12 : (12#u64 : U64).val = 12 := rfl + have h4096 : (4096#u64 : U64).val = 4096 := rfl + rw [h4096] at a1 + rw [h12] at a2 + omega + · rw [k] at e; cases e + +/-- The step's side of the spec-side fields, beyond the cap split (`PoolSlotsA`). -/ +structure PoolAsmSpecInA (st : machine.Store S) [L : LawfulStore st] (Z Z' : XSetsA) (OS : Set U64) (frame : U64) + (s s' : S) (σ σ' : State Unit) (m : McState) : Prop where + th : ∀ q k, Z.th q = some k → Z'.th q = some k + cs : Z'.Cs = Z.Cs + idleW : ∀ c ∈ Z.Cs, ∀ o : U64, (o = layout.node.IDLE_THREAD ∨ o = layout.node.IDLE_SC) → + L.mem s' (L.nodeAt s' c o) = L.mem s (L.nodeAt s c o) + /-- the spec creates no object off the pool page. -/ + kheapNone : ∀ q : U64, σ.kheap (specPtr q) = none → ¬ (frame.val ≤ q.val ∧ q.val < frame.val + 4096) → + σ'.kheap (specPtr q) = none + um : ∀ w, σ.machineState.underlyingMemory w = 0 → σ'.machineState.underlyingMemory w = 0 + /-- a new CDT link names no free address. -/ + cdt : ∀ c d, σ'.cdt c = some d → σ.cdt c = some d ∨ + ∀ q : U64, UtFreeA st OS s (fun _ => True) q.val → c.1 ≠ specPtr q ∧ d.1 ≠ specPtr q + /-- a new original cap names no free address, is a slot of the grown heap and is not null. -/ + orig : ∀ sl, σ'.isOriginalCap sl = true → + (σ.isOriginalCap sl = true ∧ specCapAtA σ' sl = specCapAtA σ sl) ∨ + ((∀ q : U64, UtFreeA st OS s (fun _ => True) q.val → sl.1 ≠ specPtr q) ∧ AbsSlotA Z'.th sl ∧ + specCapAtA σ' sl ≠ some .nullCap) + cnode : ∀ q r cs, σ'.kheap q = some (.cnode r cs) → wellFormedCnodeN r cs → + ∃ cs0, σ.kheap q = some (.cnode r cs0) ∧ wellFormedCnodeN r cs0 + tcb : ∀ q y, σ'.kheap q = some (.tcb y) → ∃ y0, σ.kheap q = some (.tcb y0) + /-- the ASID table stays injective (the new entry names the fresh pool). -/ + tabInj : ∀ i j r, σ'.archState.armAsidTable i = some r → σ'.archState.armAsidTable j = some r → i = j + +/-- **The spec-side fields after MakePool**: the pool twin of `utRt_asmSpecA`. -/ +theorem poolRt_asmSpecA + (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) + (F : PoolSlotsA st OS OS' s s' x v frame base) + (hoth : ∀ u ∈ OS, u ≠ x → ∀ q b f d, capA st s u = .Untyped q b f d → + (frame.val + 4096 ≤ q.val ∨ q.val + 2 ^ b.val ≤ frame.val) ∨ + (q.val ≤ frame.val ∧ frame.val + 4096 ≤ q.val + f.val)) + (K : PoolAsmSpecInA st Z Z' OS frame s s' σ σ' m) : + UtAsmSpecOutA st Z' OS' ia ie s' σ' m := by + have shrink : ∀ (dev : Bool → Prop) (w : Nat), UtFreeA st OS' s' dev w → + UtFreeA st OS s dev w ∧ ¬ (frame.val ≤ w ∧ w < frame.val + 4096) := + fun _ _ h => poolRt_freeShrinkA F hoth h + have orig' : ∀ sl, σ'.isOriginalCap sl = true → σ.isOriginalCap sl = true ∨ AbsSlotA Z'.th sl := + fun sl h => (K.orig sl h).imp And.left fun g => g.2.1 + exact + { specFree := ⟨fun q hq => K.kheapNone q (J.specFree.heap q (shrink _ _ hq).1) (shrink _ _ hq).2, + fun c d e q hq => (K.cdt c d e).elim (fun g => J.specFree.cdt c d g q (shrink _ _ hq).1) + (fun g => g q (shrink _ _ hq).1), + fun c e q hq => (K.orig c e).elim (fun g => J.specFree.orig c g.1 q (shrink _ _ hq).1) + (fun g => g.1 q (shrink _ _ hq).1)⟩ + specZero := fun w hw => K.um w (J.specZero w (shrink _ _ hw).1) + origLive := utRt_origLiveA J.origLive K.th orig' + nullOrig := utRt_nullOrigA J.nullOrig fun sl h => (K.orig sl h).imp id fun g => g.2.2 + finCov := utRt_finCovA J.finCov K.th (fun q r cs e w => Or.inl (K.cnode q r cs e w)) + (fun q y e => Or.inl (K.tcb q y e)) + tabInj := K.tabInj + idleAll := utRt_idleAllA J.idleAll K.cs rfl K.idleW } + +/-- **The heap change is a one-object creation**: only CNodes change besides the new empty ASID pool. -/ +theorem poolRt_specObjA (fresh : σ.kheap (specPtr frame) = none) + (pool : σ'.kheap (specPtr frame) = some (.archObj (.asidPool fun _ => none))) + (kh : ∀ p, p ≠ specPtr frame → σ'.kheap p = σ.kheap p ∨ + ∃ r cs cs', σ.kheap p = some (.cnode r cs) ∧ σ'.kheap p = some (.cnode r cs') ∧ + (wellFormedCnodeN r cs' → wellFormedCnodeN r cs)) + (glob : SpecGlobA σ { σ' with machineState := σ.machineState, archState := σ.archState }) : + UtNewObjA σ { σ' with machineState := σ.machineState, archState := σ.archState } + (fun q => q = specPtr frame) (.archObj (.asidPool fun _ => none)) := by + refine ⟨fun p e => ?_, fun p e => ?_, fun p ko e nc => ?_, fun p ko e nc => ?_, glob, rfl⟩ + · subst e; exact fresh + · subst e; exact pool + · show σ'.kheap p = some ko + have h1 : p ≠ specPtr frame := fun g => by rw [g, fresh] at e; cases e + rcases kh p h1 with g | ⟨r, cs, cs', g, -⟩ + · rw [g]; exact e + · rw [g] at e; exact absurd (Option.some.inj e).symm (nc _ _) + · change σ'.kheap p = some ko at e + by_cases h1 : p = specPtr frame + · rw [h1, pool] at e + exact Or.inr ⟨h1, (Option.some.inj e).symm⟩ + · rcases kh p h1 with g | ⟨r, cs, cs', -, g, -⟩ + · exact Or.inl (g ▸ e) + · rw [g] at e; exact absurd (Option.some.inj e).symm (nc _ _) + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolSysA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolSysA.lean new file mode 100644 index 000000000..634145112 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolSysA.lean @@ -0,0 +1,142 @@ +/- +P3 (aarch64, Stage 4, line vsx-D, CP D1): **the entry-invariant side of the record after the pool is made**, the pool +twin of `P3/UtAsmSysA` (`sys.ent`, `sys.sysl`, `SymL`, `poolOff`, `sq`, `tcbs`, `scs`, `ap`, `pp`, `s1`, `ko`, `j7`, +`vsOk`), over the grown typed heap `PoolH H frame 12` and the relation's pools with `frame`. + +The invariants at the post state are A64 P1's (`syscall.decode_invocation.makePoolLIEAtX` / `makePoolEndR2`: +`ArmQIEnd`, `S1aR2`), inputs of `PoolAsmSysInA`; the slot and footprint apartness (`SlotApA`) over the grown heap is +proved here. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.UtAsmSysA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4SpecA64 Classical + +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 OS' U U0 Ac Pp Tb Tb' : Set U64} + {Lv 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} {J5 : JSlotA S} {s s' : S} {a : A} + {σ σ' : State Unit} {m : McState} {G' : MdbGhostA} {frame : U64} + +/-- **What the pool's making supplies** to the entry-invariant side. -/ +structure PoolAsmSysInA (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) (nA : U64) (Z : XSetsA) + (H : Heap) (OS OS' U Pp Tb Tb' : Set U64) (Lv' : U64 → Nat) (ia ie : Nat) (s s' : S) (σ' : State Unit) + (m : McState) (G' : MdbGhostA) (frame : U64) : Prop where + /-- the dropped record: no heap object meets the pool block. -/ + off : ∀ q k, H q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val + /-- nor does a slot of the new slot set (A64 P1's `OffR`). -/ + osOff : ∀ y ∈ OS', y.val + 32 ≤ frame.val ∨ frame.val + 4096 ≤ y.val + sub : OS' ⊆ OS + ksb : L.ksb s' = L.ksb s + /- A64 P1's end state (`ArmQIEnd`) -/ + sysl : SysL st (PoolH H frame 12) Z.Cs OS' ia ie s' + symL : SymL st (PoolH H frame 12) Z.Cs s' + blk : ∃ Ac', BlkOK st (PoolH H frame 12).tcbs Z.Cs (PoolH H frame 12).omega (PoolH H frame 12) + (PoolH H frame 12).frame (PoolH H frame 12).replies (PoolH H frame 12).scs (PoolH H frame 12).ntfns + (PoolH H frame 12).scBits Ac' s' + poolOff : PoolOff st (PoolH H frame 12) Z.Cs OS' s' + heapOK : HeapOK (PoolH H frame 12) + os : OSOK (PoolH H frame 12).tcbs (PoolH H frame 12).omega (PoolH H frame 12).frame OS' + user : Fl4ProofsA64.P1.UserOK st (PoolH H frame 12).tcbs Z.Cs (PoolH H frame 12).omega (PoolH H frame 12) U s' + ko : HeapKsOff (PoolH H frame 12) (L.ksb s') + /- the VSpace typing and J7 at the end state -/ + vs : VsTyR st (L.ksb s') (PoolSet st (insert frame Pp) s') ∅ Tb' Lv' s' + tb : Tb ⊆ Tb' + j7 : J7A st (J7R2A st ar nA) { Z with Pp := insert frame Z.Pp, G := G' } (PoolH H frame 12) OS' s' σ' m + /-- the old queue lists over the grown TCBs (the sched bundle). -/ + core : SchedCoreA st (PoolH H frame 12).tcbs Z.Cs s' Z.Q Z.R + +/-- **The entry-invariant side of the record after the pool is made**, at the new block set `Ac'`. -/ +theorem poolRt_asmSysA + (J : JStage3A st AR Z H OS U0 Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 (J7A st (J7R2A st ar nA)) s a σ m) + (K : PoolAsmSysInA st ar nA Z H OS OS' U Pp Tb Tb' Lv' ia ie s s' σ' m G' frame) : + ∃ Ac', UtAsmSysOutA st ar nA { Z with Pp := insert frame Z.Pp, G := G' } (PoolH H frame 12) OS' U Ac' + (insert frame Pp) Tb' Lv' ia ie s' σ' m := by + have nf : ∀ q k, H q = some k → q ≠ frame := fun q k h e => by + have := Nat.two_pow_pos k.bits + rcases K.off q k h with g | g <;> rw [e] at g <;> omega + have old : ∀ q k, (∀ z, k ≠ .other z) → (PoolH H frame 12) q = some k → H q = some k := fun q k hk h => by + rcases Heap.add_eq_some.1 h with ⟨-, e⟩ | ⟨-, e⟩ + · exact absurd e (hk _) + · exact e + have new : ∀ q k, H q = some k → (PoolH H frame 12) q = some k := fun q k h => + (Heap.add_of_not (N := (· = frame)) (nf q k h)).trans h + have eT : (PoolH H frame 12).tcbs = H.tcbs := + Set.ext fun q => ⟨fun h => old q _ (fun _ e => by cases e) h, fun h => new q _ h⟩ + have eS : (PoolH H frame 12).scs = H.scs := + Set.ext fun q => ⟨fun ⟨z, h⟩ => ⟨z, old q _ (fun _ e => by cases e) h⟩, fun ⟨z, h⟩ => ⟨z, new q _ h⟩⟩ + have eZ : ∀ c ∈ H.scs, (PoolH H frame 12).scBits c = H.scBits c := fun c ⟨z, h⟩ => by + unfold Heap.scBits + rw [new c _ h, h] + have mono : ∀ b, InOS OS' b → InOS OS b := fun _ ⟨y, hy, h⟩ => ⟨y, K.sub hy, h⟩ + have fit : ∀ b : U64, frame.val + 4096 ≤ 2 ^ 64 → ∀ lo : U64, lo.val < 512 → b = peAF frame lo → + frame.val ≤ b.val ∧ b.val < frame.val + 4096 := fun b f lo h e => by + rw [e, peAF_valA f h]; omega + have fr : frame.val + 4096 ≤ 2 ^ 64 := by + have := K.heapOK.fits frame (.other 12) (Heap.add_of_mem rfl) + simp only [HKind.bits] at this + omega + obtain ⟨Ac', blk⟩ := K.blk + obtain ⟨⟨Q0, R0, h0⟩, bound, xinv, scsok, sg⟩ := blk + have sq : SchedQueuesInv st (PoolH H frame 12).tcbs Z.Cs (PoolH H frame 12).omega (PoolH H frame 12) s' Z.Q Z.R := + utRt_sqA K.core h0 + have vsOk := utVsOk_of_J7A K.j7 K.vs + refine ⟨Ac', ?_⟩ + exact + { sys := + { ent := ⟨K.heapOK, ⟨⟨_, _, sq⟩, bound, xinv, sg, scsok⟩, K.os, K.user, K.vs, K.ksb.symm ▸ J.sys.ent.ksw⟩ + sysl := K.sysl } + symL := K.symL + poolOff := K.poolOff + sq := sq + tcbs := eT.trans J.tcbs + scs := eS.trans J.scs + ap := + { sca := fun x hx c hc => by + rw [eS] at hc + rw [eZ c hc] + exact J.ap.sca x (K.sub hx) c hc + irqSt := fun o h1 h2 y hy => K.ksb.symm ▸ J.ap.irqSt o h1 h2 y (K.sub hy) + vcAl := J.ap.vcAl + vc := fun v hv b hb => by + obtain ⟨g1, g2⟩ := J.ap.vc v hv b hb + exact ⟨fun h => g1 (mono b h), eT.symm ▸ g2⟩ + vs := fun b hb => by + rw [K.ksb] at hb + have oldB : VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b → + ¬ InOS OS' b ∧ ∀ t ∈ (PoolH H frame 12).tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val := fun h => by + obtain ⟨g1, g2⟩ := J.ap.vs b h + exact ⟨fun k => g1 (mono b k), eT.symm ▸ g2⟩ + cases hb with + | asid hi h => exact oldB (.asid hi h) + | pool p lo hp h => + rcases hp with rfl | hp + · have g := fit _ fr lo h rfl + refine ⟨fun ⟨y, hy, k1, k2⟩ => ?_, fun t ht => ?_⟩ + · rcases K.osOff y hy with o | o <;> omega + · rw [eT] at ht + have o := K.off t _ ht + rw [show HKind.tcb.bits = 12 from rfl] at o + omega + · exact oldB (.pool p lo hp h) + | pt p i hp h => exact oldB (.pt p i hp h) + | high y i hy h => exact oldB (.high y i hy h) + ext := fun b hb => by + obtain ⟨g1, g2⟩ := J.ap.ext b hb + exact ⟨fun h => g1 (mono b h), eT.symm ▸ g2⟩ } + pp := by rw [← J.pp] + s1 := fun x hx => K.tb (J.s1 hx) + ko := K.ko + j7 := K.j7 + vsOk := vsOk } + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolSysEndA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolSysEndA.lean new file mode 100644 index 000000000..3dea82a6e --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolSysEndA.lean @@ -0,0 +1,270 @@ +/- +P3 (aarch64, Stage 5, line pool, group C): **the sys fields of the MakePool record** — the P1 end state, `J7A` over the +pool heap (`P3/Stage3PoolJ7A`) and `J5A`, assembled into `PoolAsmSysInA` and `poolRt_asmSysA`. + +* `poolVsTyR`: the narrowed Stage-1 typing after the pool is made (`Tb' = Tb`, `Lv' = Lv`): the new pool is all-zero, so + it adds no walk (`VsReach.zeroPool`); every old reachable word is kept or zeroed (`VsZ`), the table entry `oi` goes + `0 → frame`, the others are kept. +* `poolOsok`: `OSOK` over the pool heap and the smaller slot set. +* **`poolSysEndA`**: the group theorem (`PoolSysOutA`). + +Named premises: none. Hypotheses are facts the other groups / the assembler produce (`PoolJ7EndA`'s transformer `E`, +`vsz`, `core`, `j5`; `Stage3PoolJ5A` is another executor's). +-/ +import Fl4ProofsA64.P3.Stage3PoolJ7A +import Fl4ProofsA64.P3.Stage3D1bA +import Fl4ProofsA64.P1.QueueUnmR +import Fl4ProofsA64.P1.S1aR2AddPool +import Fl4ProofsA64.P1.S1aR2Shrink +import Fl4ProofsA64.P3.UtApA + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P3.Sched Fl4SpecA64 Classical + +local notation "wa" => core.num.U64.wrapping_add + +noncomputable section + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +theorem poolHE_tcbs {Hd : Heap} {frame : U64} + (off : ∀ q k, Hd q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) : + (PoolH Hd frame 12).tcbs = Hd.tcbs := by + ext q + constructor + · intro h + rcases poolHE_inv h with ⟨-, e⟩ | e + · cases e + · exact e + · exact fun h => poolHE_old off h + +theorem poolHE_ksOff {Hd : Heap} {kb frame : U64} (h : HeapKsOff Hd kb) + (hks : kb.val + 788736 ≤ frame.val ∨ frame.val + 2 ^ 12 ≤ kb.val) : HeapKsOff (PoolH Hd frame 12) kb := by + refine ⟨fun q k hq hk => ?_, fun q z hq => ?_⟩ + · rcases Heap.add_eq_some.1 hq with ⟨-, rfl⟩ | ⟨-, hq'⟩ + · exact absurd rfl (hk 12) + · exact h.1 q k hq' hk + · rcases Heap.add_eq_some.1 hq with ⟨e, he⟩ | ⟨-, hq'⟩ + · have e' : q = frame := e + cases he + rw [e'] + rcases hks with g | g <;> omega + · exact h.2 q z hq' + +/-- `OSOK` over the pool heap and a smaller slot set. -/ +theorem poolOsok {Hd : Heap} {frame : U64} {OS OS' : Set U64} + (off : ∀ q k, Hd q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) + (h : OSOK Hd.tcbs Hd.omega Hd.frame OS) (hs : OS' ⊆ OS) : + OSOK (PoolH Hd frame 12).tcbs (PoolH Hd frame 12).omega (PoolH Hd frame 12).frame OS' := by + have h' := h.mono (T' := (PoolH Hd frame 12).tcbs) (Ω' := (PoolH Hd frame 12).omega) + (Sg' := (PoolH Hd frame 12).frame) (fun b hb => by + rcases hb with hT | ⟨ho, hf⟩ + · left + rw [poolHE_tcbs off] + exact hT + · exact Or.inr ⟨poolHE_omega ho off, fun hh => hf (poolHE_frame hh)⟩) + exact ⟨fun x hx => h'.slot x (hs hx), fun x hx => h'.fit x (hs hx), fun x hx y hy => h'.disj x (hs hx) y (hs hy), + fun x hx => h'.nz x (hs hx)⟩ + +/-- **Every placed page-table word kept or made `0`** (`VsZ` without the ASID-table words, which MakePool writes). -/ +def PtZ (st : machine.Store S) [L : LawfulStore st] (Pt : Set U64) (s s' : S) : Prop := + ∀ b, PtW Pt b → L.mem s' b = L.mem s b ∨ L.mem s' b = 0#u64 + +/-- **Stage-1 reachability only shrinks along a `PtZ` step** (`VsReach.vsz` with the table words left out). -/ +theorem VsReach.ptz {kb : U64} {Pp Tb Hr Pt : Set U64} {Lv : U64 → Nat} {s s' : S} (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) + (hH : Hr ⊆ Tb) (h : VsTyR st kb Pp Hr Tb Lv s) (z : PtZ st Pt s s') {p : U64} + (hr : VsReach st Pp Hr Lv s' p) : VsReach st Pp Hr Lv s p := by + induction hr with + | hr hR => exact VsReach.hr hR + | @root0 q o hq ho h8 hne h0 => + rcases z _ (ptw_mono hPp ⟨q, hq, o, ho, h8, rfl⟩) with e | e + · rw [e] at hne h0 ⊢; exact VsReach.root0 hq ho h8 hne h0 + · exact absurd e hne + | @root2 q o hq ho h8 h2 => + rcases z _ (ptw_mono hPp ⟨q, hq, o, ho, h8, rfl⟩) with e | e + · rw [e] at h2 ⊢; exact VsReach.root2 hq ho h8 h2 + · rw [e] at h2; exact absurd h2 (by decide) + | @step q o _ hl ho h8 h3 ih => + have hq : q ∈ Tb := (h.sub.reach (hr_rt hH) ih).1 + rcases z _ (ptw_mono hTb ⟨q, hq, o, ho, h8, rfl⟩) with e | e + · rw [e] at h3 ⊢; exact VsReach.step ih hl ho h8 h3 + · rw [e] at h3; exact absurd h3 (by decide) + +/-- **The narrowed Stage-1 typing after the pool is made** (module docstring). -/ +theorem poolVsTyR {Pp Tb : Set U64} {Lv : U64 → Nat} {s s5 : S} {frame oi : U64} + (h : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ Tb Lv s) (ksb : L.ksb s5 = L.ksb s) + (vsz : PtZ st (utVsPtA st Pp Tb Lv s) s s5) + (hoi : 772352 ≤ oi.val ∧ oi.val < 773376 ∧ oi.val % 8 = 0) + (hfree : L.mem s (wa (L.ksb s) oi) = 0#u64) (htab : L.mem s5 (wa (L.ksb s) oi) = frame) (hfz : frame ≠ 0#u64) + (hother : ∀ o : U64, 772352 ≤ o.val → o.val < 773376 → o.val % 8 = 0 → o ≠ oi → + L.mem s5 (wa (L.ksb s) o) = L.mem s (wa (L.ksb s) o)) + (hz : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s5 (wa frame o) = 0#u64) + (hfrPp : frame ∉ Pp) : + VsTyR st (L.ksb s5) (PoolSet st (insert frame Pp) s5) ∅ Tb Lv s5 := by + have pset5 : ∀ p, p ∈ PoolSet st (insert frame Pp) s5 → p ∈ insert frame Pp ∧ ∃ o : U64, 772352 ≤ o.val ∧ + o.val < 773376 ∧ o.val % 8 = 0 ∧ L.mem s5 (wa (L.ksb s) o) = p ∧ p ≠ 0#u64 := by + intro p hp + obtain ⟨a, o, b, c, d, e, f⟩ := hp + rw [ksb] at e + exact ⟨a, o, b, c, d, e, f⟩ + have toOld : ∀ p, p ∈ PoolSet st (insert frame Pp) s5 → p ≠ frame → p ∈ PoolSet st Pp s := by + intro p hp hne + obtain ⟨a, o, b, c, d, e, f⟩ := pset5 p hp + have hoo : o ≠ oi := fun eq => by + rw [eq, htab] at e + exact hne e.symm + exact ⟨a.resolve_left hne, o, b, c, d, by rw [← hother o b c d hoo]; exact e, f⟩ + -- the typing over the reachable tables + have h' : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ (VsRt st (PoolSet st Pp s) ∅ Tb Lv s) Lv s := + h.sub.toRsub (Set.Subset.refl _) (Set.empty_subset _) + have reach : ∀ t, VsReach st (PoolSet st (insert frame Pp) s5) ∅ Lv s5 t → + VsReach st (PoolSet st Pp s) ∅ Lv s t := by + intro t hr + have sub : PoolSet st (insert frame Pp) s5 ⊆ insert frame (PoolSet st Pp s) := fun p hp => by + by_cases e : p = frame + · exact Or.inl e + · exact Or.inr (toOld p hp e) + have r2 : VsReach st (PoolSet st Pp s) ∅ Lv s5 t := (VsReach.zeroPool hz).1 (hr.poolMono sub) + exact VsReach.ptz (Pt := utVsPtA st Pp Tb Lv s) (fun p hp => Or.inl hp) (fun p hp => Or.inr hp) + (Set.empty_subset _) h' vsz r2 + rw [ksb] + refine ⟨fun o h1 h2 h8 hne => ?_, fun p hp o ho h8 hne => ?_, fun p hp hr hl o ho h8 h3 => ?_⟩ + · -- the ASID table + by_cases e : o = oi + · subst e + rw [htab] at hne ⊢ + exact ⟨Or.inl rfl, o, h1, h2, h8, by rw [ksb, htab], hne⟩ + · rw [hother o h1 h2 h8 e] at hne ⊢ + have hp := h.tbl o h1 h2 h8 hne + obtain ⟨hpP, o', b1, b2, b3, e', hn0⟩ := hp + have hoo : o' ≠ oi := fun eq => by + rw [eq, hfree] at e' + exact hn0 e'.symm + exact ⟨Or.inr hpP, o', b1, b2, b3, by rw [ksb, hother o' b1 b2 b3 hoo]; exact e', hn0⟩ + · -- the pools + by_cases e : p = frame + · subst e + exact absurd (hz o ho h8) hne + · have hpo := toOld p hp e + rcases vsz _ ⟨p, Or.inl hpo, o, ho, h8, rfl⟩ with e1 | e1 + · rw [e1] at hne ⊢ + exact h.pool p hpo o ho h8 hne + · exact absurd e1 hne + · -- the descriptors + have r := reach p hr + have hmem : p ∈ utVsPtA st Pp Tb Lv s := Or.inr ⟨hp, r⟩ + rcases vsz _ ⟨p, hmem, o, ho, h8, rfl⟩ with e1 | e1 + · rw [e1] at h3 ⊢ + exact h.desc p hp r hl o ho h8 h3 + · rw [e1] at h3 + exact absurd h3 (by decide) + +end + +section top +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} +variable {AR : A → HwRootA → Prop} + +/-- **The sys fields of the MakePool record** (module docstring): `PoolAsmSysInA` assembled from A64 P1's end state +(`hsys hsym hblk hpo hHE`, `E`), the dropped record `J` (post-restart) and the undropped `J7A` `J0`, then +`poolRt_asmSysA`; `j5` (`Stage3PoolJ5A`) rides along. The user words are `utUserA HE U0`. -/ +theorem poolSysEndA {Z Z0 : XSetsA} {Hd H0 : Heap} {OSd OS0 OS' U0 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 s0 s5 : S} {a : A} {σ σ0 σ' : Fl4SpecA64.State Unit} {m m0 : Fl4SpecA64.McState} + {G' : MdbGhostA} {frame : U64} {i : U64} {D : Set Fl4SpecA64.ObjRef} + (J : JStage3A st AR Z Hd OSd U0 Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σ m) + (J0 : J7A st (J7R2A st ar nA) Z0 H0 OS0 s0 σ0 m0) (hZ : Z = dropZA D Z0) + (Ee : ∀ Pt Ub, J7BodyA st (J7R2A st ar nA) Z0 H0 OS0 s0 σ0 m0 Pt Ub → + PoolJ7EndA st ar nA Z0 { Z with Pp := insert frame Z.Pp, G := G' } Hd frame OS' s5 σ' m Pt Ub) + (hdrop : Hd = H0.drop (RegionD H0 frame.val (frame.val + 4096))) + (hOS' : OS' = OffR frame.val (frame.val + 4096) OS0) (hsub : OS' ⊆ OSd) + (hHE : HeapOK (PoolH Hd frame 12)) + (hks0 : L.ksb s = L.ksb s0) (ksb5 : L.ksb s5 = L.ksb s) + (hks : (L.ksb s).val + 788736 ≤ frame.val ∨ frame.val + 4096 ≤ (L.ksb s).val) + (hkw : (L.ksb s).val + 788736 ≤ 2 ^ 64) + (hsys : SysL st (PoolH Hd frame 12) Z.Cs OS' ia ie s5) (hsym : SymL st (PoolH Hd frame 12) Z.Cs s5) + (hblk : ∃ Ac', BlkOK st (PoolH Hd frame 12).tcbs Z.Cs (PoolH Hd frame 12).omega (PoolH Hd frame 12) + (PoolH Hd frame 12).frame (PoolH Hd frame 12).replies (PoolH Hd frame 12).scs (PoolH Hd frame 12).ntfns + (PoolH Hd frame 12).scBits Ac' s5) + (hpo : PoolOff st (PoolH Hd frame 12) Z.Cs OS' s5) + -- the ASID-table entry `i` and the pool page + (hoi : 772352 ≤ (AtOff i).val ∧ (AtOff i).val < 773376 ∧ (AtOff i).val % 8 = 0) + (hfree : L.mem s (wa (L.ksb s) (AtOff i)) = 0#u64) (htab : L.mem s5 (wa (L.ksb s5) (AtOff i)) = frame) + (hfz : frame ≠ 0#u64) + (hother : ∀ o : U64, 772352 ≤ o.val → o.val < 773376 → o.val % 8 = 0 → o ≠ AtOff i → + L.mem s5 (wa (L.ksb s) o) = L.mem s (wa (L.ksb s) o)) + (hz : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s5 (wa frame o) = 0#u64) + (vsz : PtZ st (utVsPtA st Pp Tb Lv s) s s5) + (core : SchedCoreA st (PoolH Hd frame 12).tcbs Z.Cs s5 Z.Q Z.R) + (j5 : J5A st { Z with Pp := insert frame Z.Pp, G := G' } (PoolH Hd frame 12) OS' s5 σ' m) : + (∃ Ac', UtAsmSysOutA st ar nA { Z with Pp := insert frame Z.Pp, G := G' } (PoolH Hd frame 12) OS' + (utUserA (PoolH Hd frame 12) U0) Ac' (insert frame Pp) Tb Lv ia ie s5 σ' m) ∧ + J5A st { Z with Pp := insert frame Z.Pp, G := G' } (PoolH Hd frame 12) OS' s5 σ' m := by + subst hdrop + subst hOS' + have off : ∀ q k, (H0.drop (RegionD H0 frame.val (frame.val + 4096))) q = some k → + q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val := fun q k h => by + obtain ⟨away, found⟩ := Heap.drop_eq_some.1 h + by_contra overlap + apply away + unfold RegionD MeetsR + rw [found] + exact overlap + have hdr : ∀ q k, (H0.drop (RegionD H0 frame.val (frame.val + 4096))) q = some k → H0 q = some k := + fun q k h => (Heap.drop_eq_some.1 h).2 + have hHd := J.sys.ent.heap + have hfrPp : frame ∉ Pp := fun hf => by + rw [← J.pp] at hf + obtain ⟨q, z, hq, h1, h2⟩ := J.ptH frame (Or.inl hf) + rcases off q _ hq with g | g <;> (try simp only [HKind.bits] at g) <;> omega + have hCs : Z.Cs = Z0.Cs := by rw [hZ]; rfl + have hsub0 : OffR frame.val (frame.val + 4096) OS0 ⊆ OS0 := fun y hy => hy.1 + have j7 : J7A st (J7R2A st ar nA) { Z with Pp := insert frame Z.Pp, G := G' } + (PoolH (H0.drop (RegionD H0 frame.val (frame.val + 4096))) frame 12) (OffR frame.val (frame.val + 4096) OS0) + s5 σ' m := + poolJ7A (Zd := Z) J0 Ee hHd hHE J.setsInH hdr off (fun y hy => hy.2) hsub0 hCs + (fun v hv => by + have hv' : v ∈ Z.V := hv + rw [hZ] at hv' + exact hv'.1) rfl ⟨rfl, rfl, rfl, rfl, rfl⟩ + (fun p hp => by rw [hZ] at hp; exact hp.1) (fun p hp => by rw [hZ] at hp; exact hp.1) + (fun p hp => by rw [hZ] at hp; exact hp.1) (fun p hp => by rw [hZ] at hp; exact hp.1) + (fun p hp => by rw [hZ] at hp; exact hp.1) + (by rw [hks0] at hks; exact hks) (by rw [hks0] at hkw; exact hkw) (by rw [ksb5, hks0]) + (hCs ▸ hsys) ⟨i, htab⟩ hfz + have vs := poolVsTyR J.sys.ent.vs ksb5 vsz hoi hfree (by rw [ksb5] at htab; exact htab) hfz + (fun o h1 h2 h8 hne => hother o h1 h2 h8 hne) hz hfrPp + have K : PoolAsmSysInA st ar nA Z (H0.drop (RegionD H0 frame.val (frame.val + 4096))) OSd + (OffR frame.val (frame.val + 4096) OS0) (utUserA (PoolH (H0.drop (RegionD H0 frame.val (frame.val + 4096))) frame 12) U0) + Pp Tb Tb Lv ia ie s s5 σ' m G' frame := + { off := off + osOff := fun y hy => hy.2 + sub := hsub + ksb := ksb5 + sysl := hsys + symL := hsym + blk := hblk + poolOff := hpo + heapOK := hHE + os := poolOsok off J.sys.ent.os hsub + user := by + have := utRt_userA (H' := PoolH (H0.drop (RegionD H0 frame.val (frame.val + 4096))) frame 12) (Cs := Z.Cs) + J.sys.ent.user ksb5 + exact this + ko := by + rw [ksb5] + exact poolHE_ksOff J.ko (by omega) + vs := vs + tb := Set.Subset.rfl + j7 := j7 + core := core } + exact ⟨poolRt_asmSysA J K, j5⟩ + +end top + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PoolTopA.lean b/proofs/Fl4ProofsA64/P3/Stage3PoolTopA.lean new file mode 100644 index 000000000..c5dbc1d2f --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3PoolTopA.lean @@ -0,0 +1,499 @@ +/- +P3 (aarch64, Stage 5, line pool, assembly): **the whole record `JStage3A` after `ARMASIDControlMakePool`**, from the four +field-group modules (`Stage3Pool{Shape,Mem,SysEnd,Rec}A`), the shared context `PoolCtxA` and A64 P1's end facts. + +* `poolDrop_regionA`, `poolSlotOffA`, `poolOS_eqA`: the dead-object drop `dropHA D` / `dropSetA D` of the 4 KiB block equals + P1's `H.drop (RegionD ..)` / `OffR ..` (the dropped heap is off the block, the slot words are heap words). +* `PoolEndA`: **A64 P1's end facts at the final state** (the pool-End executor's output) and `Stage3PoolJ5A`'s `j5`, as + hypotheses of the assembly: the `J7A` transformer `Ee`, `SysL/SymL/BlkOK/PoolOff/HeapOK` over the pool heap, the other table + words, the VSpace words kept or zeroed (`vsz`), `SchedCoreA`, and the reachable-VSpace growth `hgrow`. +* **`poolRecordA`**: the record at the grown sets (`Zn`, `PoolH Hd frame 12`, `insert frame Pp`, `U' = utUserA ..`). + +Named premises: `hdr` [W] (the destination CNode radix is not `0`, decode site) and `PoolEndA` (P1's end state; [P]). +-/ +import Fl4ProofsA64.P3.Stage3PoolShapeA +import Fl4ProofsA64.P3.Stage3PoolMemA +import Fl4ProofsA64.P3.Stage3PoolRecA +import Fl4ProofsA64.P3.Stage3PoolSysEndA +import Fl4ProofsA64.P3.UtAsmAllA +import Fl4ProofsA64.P3.Stage3RestartA +import Fl4ProofsA64.P3.Stage3BodyKeepA + +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 helpers + +/-- The dead-object drop of the pool block is P1's region drop, once the dropped heap is off the block. -/ +theorem poolDrop_regionA {H0 : Heap} {frame : U64} (hp : frame.val + 2 ^ 12 ≤ 2 ^ 64) + (hsp : (specPtr frame).toNat + 2 ^ 12 ≤ 2 ^ 64) + (off : ∀ q k, dropHA (utDA frame 12) H0 q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) : + dropHA (utDA frame 12) H0 = H0.drop (RegionD H0 frame.val (frame.val + 4096)) := by + funext q + refine Option.ext fun k => ?_ + rw [Heap.drop_eq_some] + have hm := utD_memA (p := frame) (sb := 12) (by norm_num) hp hsp q + unfold dropHA + by_cases hD : specPtr q ∈ utDA frame 12 + · simp only [if_pos hD] + constructor + · intro h; cases h + · rintro ⟨hR, h0⟩ + exfalso + apply hR + have hq' := hm.1 hD + unfold RegionD MeetsR + rw [h0] + simp only [Option.elim] + have := Nat.two_pow_pos k.bits + omega + · simp only [if_neg hD] + constructor + · intro h0 + refine ⟨fun hR => ?_, h0⟩ + have o := off q k (by unfold dropHA; rw [if_neg hD]; exact h0) + unfold RegionD MeetsR at hR + rw [h0] at hR + simp only [Option.elim] at hR + omega + · exact fun h => h.2 + +/-- A cap word of the dropped heap lies in a heap object. -/ +theorem poolCapW_objA {Hd : Heap} (hH : HeapOK Hd) {b : U64} (h : W7.CapW Hd.tcbs Hd.omega Hd.frame b) : + ∃ p k, Hd p = some k ∧ p.val ≤ b.val ∧ b.val < p.val + 2 ^ k.bits := by + rcases h with ⟨t, ht, K, hK, rfl⟩ | ⟨⟨-, p, k, hp, -, hI⟩, -⟩ + · have htH : Hd t = some .tcb := ht + have f := hH.fits t _ htH + simp only [HKind.bits] at f + have ev : (wa t K).val = t.val + K.val := by rw [wa_valP]; exact Nat.mod_eq_of_lt (by omega) + exact ⟨t, .tcb, htH, by omega, by simp only [HKind.bits]; omega⟩ + · exact ⟨p, k, hp, hI⟩ + +/-- **A slot of the dropped slot set is off the pool block** (its words are heap words, the heap is off the block). -/ +theorem poolSlotOffA {Hd : Heap} {frame : U64} {OS : Set U64} (hH : HeapOK Hd) (hO : OSOK Hd.tcbs Hd.omega Hd.frame OS) + (off : ∀ q k, Hd q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) + (hf8 : frame.val % 8 = 0) {y : U64} (hy : y ∈ OS) : y.val + 32 ≤ frame.val ∨ frame.val + 4096 ≤ y.val := by + obtain ⟨al, hw⟩ := hO.slot y hy + have fit := hO.fit y hy + have w0 := poolCapW_objA hH (hw 0#u64 (by decide) (by decide)) + have w3 := poolCapW_objA hH (hw 24#u64 (by decide) (by decide)) + have e0 : (wa y 0#u64).val = y.val := by + rw [wa_valP, show (0#u64 : U64).val = 0 from rfl]; exact Nat.mod_eq_of_lt (by omega) + have e3 : (wa y 24#u64).val = y.val + 24 := by + rw [wa_valP, show (24#u64 : U64).val = 24 from rfl]; exact Nat.mod_eq_of_lt (by omega) + obtain ⟨p0, k0, h0, a0, b0⟩ := w0 + obtain ⟨p3, k3, h3, a3, b3⟩ := w3 + have o0 := off p0 k0 h0 + have o3 := off p3 k3 h3 + have al' : y.val % 8 = 0 := al + rw [e0] at a0 b0 + rw [e3] at a3 b3 + omega + +/-- The slot set of the dropped record is P1's `OffR` of the undropped one. -/ +theorem poolOS_eqA {H0 : Heap} {OS0 : Set U64} {frame : U64} (hp : frame.val + 2 ^ 12 ≤ 2 ^ 64) + (hsp : (specPtr frame).toNat + 2 ^ 12 ≤ 2 ^ 64) (hf8 : frame.val % 8 = 0) + (hH : HeapOK (dropHA (utDA frame 12) H0)) + (hO : OSOK (dropHA (utDA frame 12) H0).tcbs (dropHA (utDA frame 12) H0).omega (dropHA (utDA frame 12) H0).frame + (dropSetA (utDA frame 12) OS0)) + (off : ∀ q k, dropHA (utDA frame 12) H0 q = some k → q.val + 2 ^ k.bits ≤ frame.val ∨ frame.val + 4096 ≤ q.val) : + OffR frame.val (frame.val + 4096) OS0 = dropSetA (utDA frame 12) OS0 := by + ext y + have hm := utD_memA (p := frame) (sb := 12) (by norm_num) hp hsp y + constructor + · rintro ⟨hy, h⟩ + refine ⟨hy, fun hD => ?_⟩ + have := hm.1 hD + omega + · intro hy + exact ⟨hy.1, poolSlotOffA hH hO off hf8 hy⟩ + +/-- `wa kb (AtOff i)` is the table word `atAF kb i`. -/ +theorem poolAtOffA {kb i : U64} (hi : i.val < 128) : wa kb (AtOff i) = atAF kb i := by + unfold AtOff atAF + have hm : i &&& 127#u64 = i := + UScalar.eq_of_val_eq (by rw [and_maskA _ 7 _ rfl]; exact Nat.mod_eq_of_lt hi) + rw [hm] + +/-- The pool page's words are zero (`peAF`, as bytes). -/ +theorem poolZeroWordsA {S : Type} {st : machine.Store S} [L : LawfulStore st] {s5 : S} {frame : U64} + (h : ∀ lo : U64, lo.val < 512 → L.mem s5 (peAF frame lo) = 0#u64) : + ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s5 (wa frame o) = 0#u64 := by + intro o ho h8 + let lo : U64 := ⟨BitVec.ofNat 64 (o.val / 8)⟩ + have hlo : lo.val = o.val / 8 := by + show (BitVec.ofNat 64 (o.val / 8)).toNat = _ + rw [BitVec.toNat_ofNat]; omega + have := h lo (by omega) + have e : core.num.U64.wrapping_mul lo 8#u64 = o := + UScalar.eq_of_val_eq (by rw [wm8_valA (by omega)]; omega) + unfold peAF at this + rw [e] at this + exact this + +/-- The IPC heap coverage over the pool heap (the new object is `.other`). -/ +theorem poolIpcHeapCovA {Hd : Heap} {frame : U64} {N E Rp : Set U64} (h : IpcHeapCovA Hd N E Rp) : + IpcHeapCovA (PoolH Hd frame 12) N E Rp := by + refine ⟨fun p hp => h.ntfn p ?_, fun p hp => h.ep p ?_, fun p hp => h.reply p ?_⟩ <;> + rcases Heap.add_eq_some.1 ‹_› with ⟨-, e⟩ | ⟨-, e⟩ <;> first | exact e | cases e + +/-- **The spec step keeps the scheduler globals** (`BodyKeepA`), from the step's facts and the last machine time. -/ +theorem poolBodyKeepA {S : Type} {st : machine.Store S} [L : LawfulStore st] {Z : XSetsA} {H : Heap} + {OS : Set U64} {s s' : S} {m : McState} {n : Nat} {x v frame fi i : U64} {D : Set ObjRef} + {σu σ' : State Unit} + (P : PoolStepA st Z H OS s s' (detype D σu) σ' m n x v frame fi i) + (hl : σ'.machineState.lastMachineTime = σu.machineState.lastMachineTime) : BodyKeepA σu σ' := by + have g := P.glob + have det : ∀ p w, (detype D σu).kheap p = some w → σu.kheap p = some w := fun p w h => by + by_cases hp : p ∈ D + · change (if p ∈ D then none else σu.kheap p) = some w at h + rw [if_pos hp] at h; cases h + · change (if p ∈ D then none else σu.kheap p) = some w at h + rw [if_neg hp] at h; exact h + refine ⟨g.act, g.time, hl, g.cur, g.csc, g.cons, g.rls, fun p y k h => ?_, fun p x' h => ?_⟩ + · have ne : p ≠ specPtr frame := fun e => by rw [e, P.pool] at h; cases h + rcases P.kh p ne with e | ⟨r, cs, cs', h1, h2, -⟩ + · exact det p _ (e.symm.trans h) + · rw [h2] at h; cases h + · have ne : p ≠ specPtr frame := fun e => by rw [e, P.pool] at h; cases h + rcases P.kh p ne with e | ⟨r, cs, cs', h1, h2, -⟩ + · exact ⟨x', det p _ (e.symm.trans h), rfl⟩ + · rw [h2] at h; cases h + +end helpers + +section end_facts +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +/-- **A64 P1's end facts for MakePool** at the final state `s5`, (`Stage3PoolJ5A`'s `j5` is built from the perform's J5 facts): the hypotheses of the +assembly [P]. `s σ0 m0` is the undropped record's state (the decode state), `s1` the state after the restart write. -/ +structure PoolEndA (st : machine.Store S) [L : LawfulStore st] {A : Type} (ar : machine.Arch A) (nA : U64) + (Z0 Zd Zn : XSetsA) (H0 Hd : Heap) (OS0 OSd Pp Tb : Set U64) (Lv : U64 → Nat) (ia ie : Nat) (s s1 s5 : S) + (σ0 σ' : Fl4SpecA64.State Unit) (m0 m' : Fl4SpecA64.McState) (frame i : U64) : Prop where + /-- the `J7A` transformer, from the old witnesses to P1's end facts. -/ + Ee : ∀ Pt Ub, J7BodyA st (J7R2A st ar nA) Z0 H0 OS0 s σ0 m0 Pt Ub → + PoolJ7EndA st ar nA Z0 Zn Hd frame OSd s5 σ' m' Pt Ub + hHE : HeapOK (PoolH Hd frame 12) + hsys : SysL st (PoolH Hd frame 12) Zd.Cs OSd ia ie s5 + hsym : SymL st (PoolH Hd frame 12) Zd.Cs s5 + hblk : ∃ Ac', BlkOK st (PoolH Hd frame 12).tcbs Zd.Cs (PoolH Hd frame 12).omega (PoolH Hd frame 12) + (PoolH Hd frame 12).frame (PoolH Hd frame 12).replies (PoolH Hd frame 12).scs (PoolH Hd frame 12).ntfns + (PoolH Hd frame 12).scBits Ac' s5 + hpo : PoolOff st (PoolH Hd frame 12) Zd.Cs OSd s5 + /-- the other ASID-table words are kept (`PoolPost.tabI`). -/ + hother : ∀ o : U64, 772352 ≤ o.val → o.val < 773376 → o.val % 8 = 0 → o ≠ AtOff i → + L.mem s5 (wa (L.ksb s) o) = L.mem s (wa (L.ksb s) o) + vsz : PtZ st (utVsPtA st Pp Tb Lv s) s s5 + hgrow : utVsPtA st (insert frame Pp) Tb Lv s5 ⊆ utVsPtA st Pp Tb Lv s1 ∪ {frame} + +end end_facts + +section top +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} {nA : U64} +variable {AR : A → HwRootA → Prop} + +set_option maxHeartbeats 4000000 in +/-- **The record after MakePool** (module docstring). `Jd` is the dropped record at the decode state, `J` the dropped +record after the caller's restart write (`of_restartCurA`), `J0` the undropped `J7A`. -/ +theorem poolRecordA {Z Zn : XSetsA} {H0 : Heap} {OS0 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 s1 s5 : S} {a : A} {σ0 σ1 σd σ' : State Unit} {m m' : McState} {parent dest : CslotPtr} + {frame fi i base : U64} + (C : PoolCtxA st AR (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H0) (dropSetA (utDA frame 12) OS0) s s5 a σ1 σ' + Zn m m' parent dest frame fi i base) + (Jd : JStage3A st AR (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H0) (dropSetA (utDA frame 12) OS0) U Ac Pp Tb + Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a σd m') + (J : JStage3A st AR (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H0) (dropSetA (utDA frame 12) OS0) U Ac Pp Tb + Lv ia ie N E Rp Bf stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s1 a σ1 m') + (J0 : J7A st (J7R2A st ar nA) Z H0 OS0 s σ0 m) + (hs1 : s1 = L.wr s (stA (L.curW s)) sched.TS_RESTART) (hK : OSKeep st (dropSetA (utDA frame 12) OS0) s s1) + (hR : ∀ p ∈ utDA frame 12, σ1.kheap p = none) (hdr : dest.2.length ≠ 0) + (End : PoolEndA st ar nA Z (dropZA (utDA frame 12) Z) Zn H0 (dropHA (utDA frame 12) H0) OS0 + (dropSetA (utDA frame 12) OS0) Pp Tb Lv ia ie s s1 s5 σ0 σ' m m' frame i) : + (∃ Ac', JStage3A st AR Zn (PoolH (dropHA (utDA frame 12) H0) frame 12) (dropSetA (utDA frame 12) OS0) + (utUserA (PoolH (dropHA (utDA frame 12) H0) frame 12) U) Ac' (insert frame Pp) Tb Lv ia ie N E Rp Bf stack κ n + (J5A st) (J7A st (J7R2A st ar nA)) s5 a σ' m') ∧ + PoolStepA st (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H0) (dropSetA (utDA frame 12) OS0) s1 s5 σ1 σ' m' n + (cslotAddrA parent) (cslotAddrA dest) frame fi i := by + obtain ⟨G', hG⟩ : ∃ G', G' = Zn.G := ⟨_, rfl⟩ + have eZn : Zn = { dropZA (utDA frame 12) Z with Pp := insert frame (dropZA (utDA frame 12) Z).Pp, G := G' } := by + rw [hG]; exact C.zn + clear hG + subst eZn + have e12 : (12#u64 : U64).val = 12 := rfl + have hks1 : L.ksb s1 = L.ksb s := by rw [hs1]; exact L.ksb_wr _ _ _ + obtain ⟨Sh0, Sh, P⟩ := poolShapeFullA C hs1 J hK hR hdr + have hxO : cslotAddrA parent ∈ dropSetA (utDA frame 12) OS0 := Jd.j5.2.1 _ (C.absP.isSlot Jd.j.1.place) + have off := poolHeap_offA Jd.objAlloc C hxO + -- the pool block's bounds + have hwin := Jd.utWin (cslotAddrA parent) hxO frame 12#u64 fi C.hcp + have hbase : layout.PPTR_BASE.val = 18446603336221196288 := by unfold layout.PPTR_BASE; rfl + rw [hbase, e12] at hwin + have hp : frame.val + 2 ^ 12 ≤ 2 ^ 64 := by omega + have hsp : (specPtr frame).toNat + 2 ^ 12 ≤ 2 ^ 64 := by rw [specPtr_toNat]; omega + have hfz : frame ≠ 0#u64 := fun e => by + have h0 : frame.val = 0 := by rw [e]; rfl + omega + obtain ⟨hpal, -, -⟩ := Jd.sys.sysl.sys.ur.utv Jd.sys.sysl.sys.stz.1.1 hxO C.hcp + rw [e12] at hpal + have hf8 : frame.val % 8 = 0 := by omega + obtain ⟨-, hks⟩ := Jd.sys.sysl.sys.stz.2.2 _ hxO frame 12#u64 fi C.hcp + rw [e12] at hks + have ksb5 : L.ksb s5 = L.ksb s := P.w.1.trans hks1 + -- the other groups + have asid : ∀ j q, σ'.archState.armAsidTable j = some (specPtr q) → + q = frame ∨ σ1.archState.armAsidTable j = some (specPtr q) := by + intro j q h + rw [Sh.tab] at h + change Function.update σ1.archState.armAsidTable (BitVec.ofNat 7 i.val) (some (specPtr frame)) j = + some (specPtr q) at h + by_cases hj : j = BitVec.ofNat 7 i.val + · subst hj + simp only [Function.update_self] at h + exact Or.inl (specPtr_inj (Option.some.inj h)).symm + · right + rw [Function.update_of_ne hj] at h + exact h + obtain ⟨CO, HO⟩ := poolMemA C Jd J hs1 hK P.fresh + (fun p hp => by + rcases P.kh p hp with h | ⟨r, cs, cs', h1, h2, -⟩ + · exact Or.inl h + · exact Or.inr (Or.inl ⟨r, cs, cs', h1, h2⟩)) asid + have RO := poolRt_recA C J P End.hsym + have hbv := poolRt_bufVsA (Tb' := Tb) (Lv' := Lv) C J P End.hgrow + have hcore : SchedCoreA st (PoolH (dropHA (utDA frame 12) H0) frame 12).tcbs (dropZA (utDA frame 12) Z).Cs s5 + (dropZA (utDA frame 12) Z).Q (dropZA (utDA frame 12) Z).R := by + rw [poolHE_tcbs off, Jd.tcbs]; exact Sh0.sched.sr.core + -- the sys group + have hj5 : J5A st { dropZA (utDA frame 12) Z with Pp := insert frame (dropZA (utDA frame 12) Z).Pp, G := G' } + (PoolH (dropHA (utDA frame 12) H0) frame 12) (dropSetA (utDA frame 12) OS0) s5 σ' m' := + poolJ5_outA Jd.j5 rfl C.j5c Set.Subset.rfl + (fun y hy => Jd.j5.2.1 y hy) (fun y hy hn => C.expo.capK y hy (fun e => hn (e ▸ C.absP.isSlot Jd.j.1.place)) + (fun e => hn (e ▸ C.absD.isSlot Jd.j.1.place))) + obtain ⟨⟨Ac', SO⟩, j5⟩ := poolSysEndA Jd J0 rfl End.Ee + (poolDrop_regionA hp hsp off) (poolOS_eqA hp hsp hf8 Jd.sys.ent.heap Jd.sys.ent.os off).symm Set.Subset.rfl + End.hHE rfl ksb5 (by rcases hks with g | g <;> omega) Jd.sys.ent.ksw End.hsys End.hsym End.hblk End.hpo + (AtOff.v i) (by rw [poolAtOffA C.hi]; exact C.hfree) (by rw [ksb5, poolAtOffA C.hi]; exact C.expo.tab) hfz + End.hother (poolZeroWordsA C.expo.pool) End.vsz hcore hj5 + refine ⟨⟨Ac', ?_⟩, P⟩ + exact + { sys := SO.sys + j := C.jat + tcbs := SO.tcbs + scs := SO.scs + sq := SO.sq + ap := SO.ap + pp := SO.pp + s1 := SO.s1 + ko := SO.ko + ptH := HO.ptH + tabInj := Sh0.spec.tabInj + poolOff := SO.poolOff + objAlloc := CO.objAlloc + idleAnchor := CO.idleAnchor + vsVc := HO.vsVc + sr := Sh0.sched.sr + scCov := Sh0.ipc.scCov + scSize := HO.scSize + ep := Sh0.ipc.ep + ntfn := Sh0.ipc.ntfn + reply := Sh0.ipc.reply + bufCover := Sh0.ipc.bufCover + bufNative := Sh0.ipc.bufNative + iplaced := Sh0.ipc.iplaced + ipcPlace := Sh0.ipc.ipcPlace + idleNoFault := Sh0.ipc.idleNoFault + mcp := Sh0.ipc.mcp + yieldRel := Sh0.ipc.yieldRel + sinv := Sh0.ipc.sinv + setsInH := HO.setsInH + utIpc := HO.utIpc + ipcTh := Sh0.ipc.ipcTh + deadExt := HO.deadExt + specFree := Sh0.spec.specFree + utBlk := CO.utBlk + unmPt := HO.unmPt + tabS1 := HO.tabS1 + tabExt := HO.tabExt + specZero := Sh0.spec.specZero + origLive := Sh0.spec.origLive + nullOrig := Sh0.spec.nullOrig + thPos := HO.thPos + frBase := HO.frBase + devFr := HO.devFr + finCov := Sh0.spec.finCov + idleAll := Sh0.spec.idleAll + ipcHeapCov := poolIpcHeapCovA Sh0.ipc.ipcHeapCov + zombieNoVcpu := CO.zombieNoVcpu + zombieTcb := CO.zombieTcb + bufOff := HO.bufOff + vsOk := SO.vsOk + bufAl := Sh0.ipc.bufAl + zombieBnd := CO.zombieBnd + devUtOff := CO.devUtOff + sidle := Sh0.sched.sidle + capTy := CO.capTy + scCpu := Sh0.sched.scCpu + scNZ := Sh0.sched.scNZ + vcRun := Sh0.sched.vcRun + vcSym1 := Sh0.sched.vcSym1 + runVcpu := Sh0.sched.runVcpu + vcSym2 := Sh0.sched.vcSym2 + blkQ := Sh0.blkQ + heapWin := RO.heapWin + coresAll := RO.coresAll + ptCapIn := RO.ptCapIn + symL := RO.symL + fhOK := RO.fhOK + zwf := RO.zwf + schedValid := RO.schedValid + utWin := RO.utWin + devWin := RO.devWin + vcBack := RO.vcBack + runBack := RO.runBack + vcSnap := RO.vcSnap + vcOS := RO.vcOS + userFr := RO.userFr + frTh := RO.frTh + bfSpec := Sh0.bfSpec + curVcpuNone := Sh0.curVcpuNone + ipcSorted := Sh0.ipc.ipcSorted + activeReplyScs := Sh0.ipc.activeReplyScs + domOK := RO.domOK + ipiZero := RO.ipiZero + bufVs := hbv + j5 := j5 + j7 := SO.j7 } + + +variable (st ar nA AR) in +/-- **The post of the MakePool run with its record** (module docstring): the spec restart and perform, `BodyKeepA`, and the +whole record at the grown sets. -/ +def PoolRecPostA (Z : XSetsA) (H : Heap) (OS U 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) (a : A) + (σ : State Unit) (m : McState) (parent dest : CslotPtr) (frame base : U64) + (res : core.result.Result Unit error.Exc × S × A) : Prop := + ∃ σ1, setThreadState (Z := Unit) σ.curThread .restart σ = ({((), σ1)}, False) ∧ + (∃ x, σ.kheap σ.curThread = some (.tcb x) ∧ σ1 = stUpdA σ σ.curThread x .restart) ∧ + ∃ σ' rv, (.ok rv, σ') ∈ ((fl4ArchPerformInvocation (Z := Unit) + (.spec (.invokeASIDControl (.makePool (specPtr frame) dest parent (asidOfA base))))).run σ1).1 ∧ + BodyKeepA σ1 σ' ∧ + ∃ (Zn : XSetsA) (Ac' : Set U64), res = (.Ok (), res.2.1, a) ∧ + Zn = { dropZA (utDA frame 12) Z with Pp := insert frame (dropZA (utDA frame 12) Z).Pp, G := Zn.G } ∧ + TreeA st (dropSetA (utDA frame 12) OS) Zn.G.chains Zn.G.par res.2.1 ∧ + JStage3A st AR Zn (PoolH (dropHA (utDA frame 12) H) frame 12) (dropSetA (utDA frame 12) OS) + (utUserA (PoolH (dropHA (utDA frame 12) H) frame 12) U) Ac' (insert frame (dropSetA (utDA frame 12) Pp)) + Tb Lv ia ie (dropSetA (utDA frame 12) N) (dropSetA (utDA frame 12) E) (dropSetA (utDA frame 12) Rp) + (dropBfA (utDA frame 12) Bf) stack κ n (J5A st) (J7A st (J7R2A st ar nA)) res.2.1 a σ' + (dropMA (utDA frame 12) m) + +set_option maxHeartbeats 4000000 in +/-- **MakePool's perform with the whole record** (module docstring): `makePool_perform_dropA`'s run, then the record at +the grown sets. `Fin` is the P1 end state (`PoolEndA`) at the run's final state: guarded by the run equation and the +perform's post (`PoolCtxA`), so it is not an all-states premise. `hnvm` is `of_restartCurA`'s, `hCp hCd` and `hdr` [W]. -/ +theorem makePool_recordA {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} + [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] + (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) + (hT : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s)) + (hYAs : ∀ y ∈ Z.Y, ∀ j : U64, j.val < 512 → ¬ AsW (L.ksb s) (peAF y j)) + (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) + {parent dest : CslotPtr} {frame fi i base : U64} + (hAp : AbsSlotA Z.th parent) (hAd : AbsSlotA Z.th dest) + (hcp : capA st s (cslotAddrA parent) = .Untyped frame 12#u64 fi false) + (hnc : cdt.ensure_no_children st s (cslotAddrA parent) = ok (core.result.Result.Ok ())) + (hcd : capA st s (cslotAddrA dest) = .Null) + (hi : i.val < 128) (hfree : L.mem s (atAF (L.ksb s) i) = 0#u64) (hbase : base.val = i.val * 512) + (hdc : ∃ y ∈ OS, ∃ q r gs g : U64, capA st s y = .CNode q r gs g ∧ dest.1 = specPtr q) + {Ud Acd Rq Nt : Set U64} {ex : Aeneas.Std.Array obj.Slot 3#usize} + (Dp : DecPre st H.tcbs Z.Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ud Acd s + (.Untyped frame 12#u64 fi false) ex) + (P : SysPlace st H Z.Cs H.frame Rq Nt OS s ex (cslotAddrA parent)) + (othT : ∀ c ∈ Z.Cs, c ≠ L.cpu s → + specPtr (L.mem s (L.nodeAt s c layout.node.CUR_THREAD)) ∉ utDA frame 12) + (othC : ∀ c ∈ Z.Cs, c ≠ L.cpu s → specPtr (L.mem s (L.nodeAt s c layout.node.CUR_SC)) ∉ utDA frame 12) + (hn : nA.val = fl4A64Platform.s2IpaBits) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (hCp : ∃ pp, parent.1 = specPtr pp ∧ Z.th pp = some (.cnode parent.2.length)) + (hCd : ∃ pd, dest.1 = specPtr pd ∧ Z.th pd = some (.cnode dest.2.length)) + (hdr : dest.2.length ≠ 0) + (hlast : ∀ (σ1 σ' : State Unit) (rv : List Data), + (.ok rv, σ') ∈ ((fl4ArchPerformInvocation (Z := Unit) + (.spec (.invokeASIDControl (.makePool (specPtr frame) dest parent (asidOfA base))))).run σ1).1 → + σ'.machineState.lastMachineTime = σ1.machineState.lastMachineTime) + (Fin : ∀ (s5 : S) (σ1 σ' : State Unit) (Zn : XSetsA), + (Jd : JStage3A st AR (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H) (dropSetA (utDA frame 12) OS) U Ac + (dropSetA (utDA frame 12) Pp) Tb Lv ia ie (dropSetA (utDA frame 12) N) (dropSetA (utDA frame 12) E) + (dropSetA (utDA frame 12) Rp) (dropBfA (utDA frame 12) Bf) stack κ n (J5A st) (J7A st (J7R2A st ar nA)) s a + (detype (utDA frame 12) σ) (dropMA (utDA frame 12) m)) → + PoolCtxA st AR (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H) (dropSetA (utDA frame 12) OS) s s5 a σ1 σ' Zn m + (dropMA (utDA frame 12) m) parent dest frame fi i base → + (do + let s1 ← sched.set_thread_state st s (L.curW s) sched.TS_RESTART + let s2 ← obj.Slot.set_cap st (cslotAddrA parent) s1 (.Untyped frame 12#u64 4096#u64 false) + let s3 ← st.clear_free s2 frame 4096#u64 + let s4 ← cdt.insert st s3 (.AsidPool frame base) (cslotAddrA parent) (cslotAddrA dest) + let s5 ← vspace.set_asid_table st s4 i frame + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s5, a)) = ok (.Ok (), s5, a) → + PoolEndA st ar nA Z (dropZA (utDA frame 12) Z) Zn H (dropHA (utDA frame 12) H) OS (dropSetA (utDA frame 12) OS) + (dropSetA (utDA frame 12) Pp) Tb Lv ia ie s (L.wr s (stA (L.curW s)) sched.TS_RESTART) s5 σ σ' m + (dropMA (utDA frame 12) m) frame i) : + (do + let s1 ← sched.set_thread_state st s (L.curW s) sched.TS_RESTART + let s2 ← obj.Slot.set_cap st (cslotAddrA parent) s1 (.Untyped frame 12#u64 4096#u64 false) + let s3 ← st.clear_free s2 frame 4096#u64 + let s4 ← cdt.insert st s3 (.AsidPool frame base) (cslotAddrA parent) (cslotAddrA dest) + let s5 ← vspace.set_asid_table st s4 i frame + ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s5, a)) ⦃ res => PoolRecPostA st ar nA AR Z H OS U Pp Tb Lv ia ie N E Rp Bf stack κ n a σ m parent dest frame base res ⦄ := by + have main := makePool_perform_dropA J RS hT hYAs hcO hAp hAd hcp hnc hcd hi hfree hbase hdc Dp P othT othC hn + obtain ⟨res, hres, h⟩ := spec_existsA main + rw [hres, WP.spec_ok] + unfold PoolRecPostA + obtain ⟨σ1, hst, σ', rv, hrun, Zn, hr, hZn, hJ, hTree, hCar, Jd, RS', hD, hAp', hAd', hX, hj5c⟩ := h + obtain ⟨pp, hpp1, hpp2⟩ := hCp + obtain ⟨pd, hpd1, hpd2⟩ := hCd + have C := PoolCtxA.ofDrop (Z := Z) rfl hZn rfl hX hJ hTree hj5c hD hcp hnc hcd hi hfree hbase hAp' hAd' + ⟨hpp1, hpp2⟩ ⟨hpd1, hpd2⟩ + -- the restart on both records + obtain ⟨x, hkx, -, hset0, -⟩ := J.of_restartCurA RS.pl.choose_spec.choose_spec.choose_spec.choose_spec RS.sym RS.run hnvm + RS.cur RS.vs RS.vc + obtain ⟨x', hkx', -, -, J1, -, hOS1, -⟩ := Jd.of_restartCurA RS'.pl.choose_spec.choose_spec.choose_spec.choose_spec + RS'.sym RS'.run hnvm RS'.cur RS'.vs RS'.vc + have curK : σ.curThread ∉ utDA frame 12 := fun hc => by + change (if σ.curThread ∈ utDA frame 12 then none else σ.kheap σ.curThread) = some (.tcb x') at hkx' + rw [if_pos hc] at hkx' + cases hkx' + have exx : x' = x := by + change (if σ.curThread ∈ utDA frame 12 then none else σ.kheap σ.curThread) = some (.tcb x') at hkx' + rw [if_neg curK, hkx] at hkx' + injection hkx' with h1 + injection h1 with h2 + exact h2.symm + have eσ : σ1 = stUpdA σ σ.curThread x .restart := by + have h := hst.symm.trans hset0 + have h1 := (Prod.mk.inj h).1 + exact (congrArg Prod.snd (Set.singleton_eq_singleton_iff.1 h1)) + have eσ1 : detype (utDA frame 12) σ1 = stUpdA (detype (utDA frame 12) σ) (detype (utDA frame 12) σ).curThread x' .restart := by + rw [eσ, exx] + exact (ut_detype_updA curK _).symm + have hR : ∀ p ∈ utDA frame 12, (detype (utDA frame 12) σ1).kheap p = none := fun p hp => by + change (if p ∈ utDA frame 12 then none else σ1.kheap p) = none + rw [if_pos hp] + rw [← eσ1] at J1 + obtain ⟨⟨Ac', hrec⟩, hP⟩ := poolRecordA C Jd J1 J.j7 rfl hOS1 hR hdr (Fin _ _ _ _ Jd C (hres.trans (congrArg ok hr))) + refine ⟨σ1, hst, ⟨x, hkx, eσ⟩, σ', rv, hrun, ?_, Zn, Ac', hr, hZn, hTree, hrec⟩ + exact poolBodyKeepA hP (hlast σ1 σ' rv hrun) +end top + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3PtMapShapeA.lean b/proofs/Fl4ProofsA64/P3/Stage3PtMapShapeA.lean index 39758bae6..bcd317b8e 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3PtMapShapeA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3PtMapShapeA.lean @@ -58,6 +58,7 @@ theorem pt_map_shapeA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac P (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) {ptr asid0 va0 : U64} {mp : Bool} (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr mp asid0 va0) + (hPC : PtCapInA Z (L.mem s)) (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (slbl : Fl4SpecA64.Data) (hl : Fl4SpecA64.invocationType slbl = .archInvocationLabel .armPageTableMap) (length buf : U64) (args : List U64) (hlen : length.val = args.length) @@ -165,8 +166,14 @@ theorem pt_map_shapeA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac P rw [hrun'] have R := E.j.1.vs obtain ⟨hKal, hS1A, -⟩ := E.vsLeafA - refine WP.spec_bind (lookup_pt_slotA R hrT hrL (vsReachA_of_vspaceForAsid R E.j.2.2.1.obj hrT hvRoot) a0) - fun lu ⟨p, hp, l, hl3, hsh, hlv, hsl, _, hLs, hreachP⟩ => ?_ + have hreachR := vsReachA_of_vspaceForAsid R E.j.2.2.1.obj hrT hvRoot + obtain ⟨lu, hlu, p, hp, l, hl3, hsh, hlv, hsl, -, hLs, hreachP⟩ := + spec_ex_fd (lookup_pt_slotA R hrT hrL hreachR a0) + have hwk := lookup_walkA R hrT hrL hreachR a0 + rw [hlu, WP.spec_ok] at hwk + obtain ⟨htagR, hactR⟩ := activeS1RootA R E.j.2.2.1.obj h16 hrT hvRoot + refine WP.spec_bind (show vspace.lookup_pt_slot st s r0 a0 ⦃ x => x = lu ⦄ by rw [hlu, WP.spec_ok]) fun x hx => ?_ + subst x obtain ⟨tq, hkq, htq, hrq⟩ := R.pt p hp have hidx := idxA_lt a0 lu.shift have hpte := ptesOf_atA hkq (ptT := Fl4SpecA64.levelType (lvA l)) @@ -222,7 +229,7 @@ theorem pt_map_shapeA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac P .normalPtT (some (asidOfA asid1, a0.bv &&& ~~~(Fl4SpecA64.mask (Fl4SpecA64.ptBitsLeft (lvA l))))))) := by exact ⟨hwf, rfl, rfl, Or.inl hbv⟩ obtain ⟨xc, s2, σ2, hkx, hst, hset, hsc, hσ2, HS, hksb, R2, hcpu2, hw2, hJ2, hFr2⟩ := - restart_setcapJA E RS cte hab hos hEnc hca + restart_setcapJA E RS cte hab hos hEnc hca (hpt := Or.inl (PtSetA.map hcap)) rw [hst, bind_ok, hsc, bind_ok] -- the new table at the written states have hpal : ptr.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd UP.al @@ -290,16 +297,63 @@ theorem pt_map_shapeA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac P intro hT hnul hTO hc have hco : capA st s (cslotAddrA cte) = .PageTable ptr false asid0 va0 := by rw [← capAtA_eq, hcap] obtain ⟨J2, hT2⟩ := hJ2 hT hnul (by simp) (by rw [hco]; simp) - (UA.of_shapeA (by rw [hco]; rfl) fun h => by rw [hco] at h; simp [isUtA] at h) + (by rw [hco]; exact ⟨rfl, rfl, rfl, rfl, 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), trivial⟩ + (fun p' a' v' mp e => by cases e; exact Or.inr (Or.inl ⟨UP.nt, fun h => hc.1 (Or.inl h)⟩)) obtain ⟨t', rfl⟩ := storePte_eqA R3 (Set.mem_insert_of_mem _ hp) hidx hstore + have hsub : ∀ y, IsSlotA Z.th y → y ∈ OS := by + obtain ⟨⟨Rp, Nt, extra', sp, P⟩, Y, hrun, hcur, hvs, hvc, hsub⟩ := RS; exact hsub + have hfr : ∀ b, Aligned b → ¬ InOS OS b → (∀ t ∈ H.tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) → + L.mem s2 b = L.mem s b := by + intro b ha hnos htc + have hnc : ¬ W7.CapW H.tcbs {b | InOS OS b} ∅ b := by + rintro (⟨t, ht, K, hK, he⟩ | ⟨hin, -⟩) + · have hfit := (E.sq.tcbs t ht).fits + simp only [Nat.reducePow] at hfit + have := congrArg UScalar.val he + rw [wa_valm] at this + rcases htc t ht with h | h <;> omega + · exact hnos hin + have hns : stA (L.curW s) ≠ b := fun e => by + have := congrArg UScalar.val e + have e3 : (3328#u64 : U64).val = 3328 := rfl + have hfit := hta.fits + simp only [Nat.reducePow] at hfit + rw [stA_eq, wa_valm, e3] at this + rcases htc _ hcurT with h | h <;> omega + rw [hw2.2.2 _ ha hnc, mem_wr_ne' sA ha hns] + have hN : ∀ c ∈ Z.Cs, ∀ o : U64, o.val < 4288 → o.val % 8 = 0 → Aligned (L.nodeAt s2 c o) := + fun c hc o h1 h2 => by rw [nodeAt_ksb hksb]; exact bxi_nodes E.sys.ent.bxi c hc o h1 h2 + have hbase' : ∀ k, lu.shift.val ≤ k → walkIdx base k 512 = walkIdx a0 k 512 := fun k hk => by + rw [← hbase]; exact walkIdx_baseA a0 lu.shift.val k hk + have hwalk := hwk base hbase' + rw [hsl] at hwalk hv' + have hP : PoolKeepA Z.Pp σ2 σ4 := by + obtain ⟨ms, hh⟩ := hms + rw [hh] + refine ⟨rfl, fun q hq => ?_⟩ + show (ptSetA σ2 (specPtr p) t').kheap (specPtr q) = _ + rw [ptSetA_kheap, if_neg] + intro e + have := specPtr_inj e + subst this + obtain ⟨_, h1, -⟩ := J2.1.vs.pool q hq + obtain ⟨_, h2, -⟩ := J2.1.vs.pt q hp + rw [h1] at h2; cases h2 + have hbal := peAF_alignedA (R.al_mod hp) hidx + have hv3m : L.mem (L.wr s2 (peAF p (idxA a0 lu.shift)) v) (peAF p (idxA a0 lu.shift)) = v := + L.mem_wr_same hbal + have VU := ptMap_vsuA (s3 := L.wr s2 (peAF p (idxA a0 lu.shift)) v) (σ3 := σ4) R E.ap.vs hfr J2 hksb + (FootA.aligned J2.1 hN E.scAl E.ap.vcAl) hsub E.sys.ent.os hFr2 hPC UP.nt (fun h => hc.1 (Or.inl h)) hpal + UP.ytb UP.inv hmem2 hp hidx ((hTO p hp).of_ksA hksb hcpu2) hv' hrT htagR hactR hwalk (L.ksb_wr _ _ _) + (fun w hw hne => mem_wr_ne' hbal hw (Ne.symm hne)) hv3m hdTab hP exact map_finJA E J2 hT2 hksb hcpu2 hp (hTO p hp) hidx (L.ksb_wr _ _ _) (L.cpu_wr _ _ _) (fun w hw hne => mem_wr_ne' (peAF_alignedA (R.al_mod hp) hidx) hw (Ne.symm hne)) hms (fun q hq => (Set.mem_insert_iff.1 hq).elim (fun e => by subst e; exact Or.inr hc) Or.inl) (fun q hq hl => by have hne : q ≠ ptr := fun e => UP.nt (e ▸ hq) exact ⟨Set.mem_insert_of_mem _ hq, by rw [Function.update_of_ne hne]; exact hl⟩) - (R4.of_msA hms) hFr2 hos + (R4.of_msA hms) VU hFr2 hos refine (WP.spec_ok _).2 fun s' a' e => ?_ simp only [Prod.mk.injEq, true_and] at e obtain ⟨rfl, rfl⟩ := e diff --git a/proofs/Fl4ProofsA64/P3/Stage3RecvBufA.lean b/proofs/Fl4ProofsA64/P3/Stage3RecvBufA.lean index 99f16c972..a739e4de5 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3RecvBufA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3RecvBufA.lean @@ -40,6 +40,18 @@ theorem maskAndA_toNat (x : BitVec 64) {k : Nat} (hk : k ∈ [12, 21, 30]) : theorem pageBitsA_mem (vms : VMPageSize) : pageBitsForSize vms ∈ [12, 21, 30] := by cases vms <;> simp [pageBitsForSize, pageBits, ptTranslationBits] +/-- Masking down to a smaller page then to a larger one is masking down to the larger one. -/ +theorem andNotMask_chainA (X : BitVec 64) {n pg : Nat} (hn : n ∈ [12, 21, 30]) (hpg : pg ∈ [12, 21, 30]) + (hle : n ≤ pg) : X &&& ~~~(Fl4SpecA64.mask pg : BitVec 64) = + (X &&& ~~~(Fl4SpecA64.mask n : BitVec 64)) &&& ~~~(Fl4SpecA64.mask pg : BitVec 64) := by + apply BitVec.eq_of_toNat_eq + rw [andNotMaskA_toNat _ hpg, andNotMaskA_toNat _ hpg, andNotMaskA_toNat _ hn] + obtain ⟨t, ht⟩ : ∃ t, 2 ^ pg = 2 ^ n * t := ⟨2 ^ (pg - n), by rw [← Nat.pow_add]; congr 1; omega⟩ + have hm : 0 < 2 ^ n := Nat.pow_pos (by norm_num) + have key : X.toNat / 2 ^ n * 2 ^ n / 2 ^ pg = X.toNat / 2 ^ pg := by + rw [ht, ← Nat.div_div_eq_div_mul, ← Nat.div_div_eq_div_mul, Nat.mul_div_cancel _ hm] + rw [key] + /-- **The page of a buffer word** (module docstring). -/ theorem bufAddr_pageA {q : U64} {n : Nat} (hn : n ∈ [12, 21, 30]) (hq : q.val % 2 ^ n = 0) (w : BitVec 64) (hw : w.toNat % 1024 = 0) {k : Nat} (hk : k < 128) : @@ -88,9 +100,10 @@ theorem JStage3A.bufFrameObjA {R7 : Set U64 → JSlotA 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 R7) s a σ m) {d : U64} (hd : d ∈ Z.T) {xd : Tcb} (hkd : σ.kheap (specPtr d) = some (.tcb xd)) (b : Bool) {rp : ObjRef} (hrp : ipcBufOfA b xd = some rp) : - ∃ q vms, H q = some (.other (pageBitsForSize vms)) ∧ q.val % 2 ^ pageBitsForSize vms = 0 ∧ + ∃ q vms b' pg, H b' = some (.other (pageBitsForSize pg)) ∧ b'.val ≤ q.val ∧ + q.val + 2 ^ pageBitsForSize vms ≤ b'.val + 2 ^ pageBitsForSize pg ∧ q.val % 2 ^ pageBitsForSize vms = 0 ∧ rp = specPtr q + (xd.tcbIpcBuffer &&& Fl4SpecA64.mask (pageBitsForSize vms)) ∧ - σ.kheap (specPtr q) = some (.archObj (.dataPage false vms)) := by + σ.kheap (specPtr b') = some (.archObj (.dataPage false pg)) := by have hth : Z.th d = some .tcb := (J.sr.thT d).2 hd obtain ⟨x', hk', hs⟩ := J.j.1.st.tcb d hth rw [hkd] at hk' @@ -114,15 +127,15 @@ theorem JStage3A.bufFrameObjA {R7 : Set U64 → JSlotA S} simp only [absCapA, absFrameE, Bool.false_eq_true, ↓reduceIte] at hrp split_ifs at hrp exact (Option.some.inj hrp).symm - have hpg := J.userFr _ hyOS q sz r mp false asid va hc + obtain ⟨b', pg, hHb, hk, g1, g2⟩ := J.userFr _ hyOS q sz r mp false asid va hc obtain ⟨Pt, Ub, -, -, -, cc, -⟩ := J.j7 have hfo := cc.fo _ hyOS q sz r mp false asid va hc - have hH : H q = some (.other (pageBitsForSize (frameSizeOfA sz))) := by + have hal : q.val % 2 ^ pageBitsForSize (frameSizeOfA sz) = 0 := by cases sz - · exact hfo 12#u64 rfl - · exact hfo 21#u64 rfl - · exact hfo 30#u64 rfl - exact ⟨q, frameSizeOfA sz, hH, J.sys.ent.heap.align q _ hH, erp, hpg⟩ + · exact (hfo 12#u64 rfl).al J.sys.ent.heap + · exact (hfo 21#u64 rfl).al J.sys.ent.heap + · exact (hfo 30#u64 rfl).al J.sys.ent.heap + exact ⟨q, frameSizeOfA sz, b', pg, hHb, g1, g2, hal, erp, hk⟩ · unfold ipcBufOfA at hrp; rw [← hab] at hrp; simp [absCapA, absFrameE] at hrp · unfold ipcBufOfA at hrp; rw [← hab] at hrp; cases ept <;> simp [absCapA, absFrameE] at hrp | _ => @@ -135,9 +148,19 @@ theorem JStage3A.bufFrameA {R7 : Set U64 → JSlotA S} {d : U64} (hd : d ∈ Z.T) {xd : Tcb} (hkd : σ.kheap (specPtr d) = some (.tcb xd)) (b : Bool) : ∀ rp, ipcBufOfA b xd = some rp → ∀ k, k < 128 → inUserFrame (bufAddr rp k) σ := by intro rp hrp k hk - obtain ⟨q, vms, -, hal, erp, hpg⟩ := J.bufFrameObjA hd hkd b hrp - refine ⟨vms, ?_⟩ - rw [erp, bufAddr_pageA (pageBitsA_mem _) hal _ (J.bufAl d hd xd hkd) hk] + obtain ⟨q, vms, b', pg, hHb, g1, g2, hal, erp, hpg⟩ := J.bufFrameObjA hd hkd b hrp + refine ⟨pg, ?_⟩ + have hn := pageBitsA_mem vms + have hpgm := pageBitsA_mem pg + have h1p : 1 ≤ 2 ^ pageBitsForSize vms := Nat.one_le_two_pow + have hle : pageBitsForSize vms ≤ pageBitsForSize pg := by + have h3 : 2 ^ pageBitsForSize vms ≤ 2 ^ pageBitsForSize pg := by omega + exact (Nat.pow_le_pow_iff_right (by norm_num)).1 h3 + have hbal : b'.val % 2 ^ pageBitsForSize pg = 0 := by + have := J.sys.ent.heap.align b' _ hHb; simpa [HKind.bits] using this + have hpg39 : pageBitsForSize pg ≤ 39 := by simp at hpgm; omega + have e1 := bufAddr_pageA hn hal xd.tcbIpcBuffer (J.bufAl d hd xd hkd) hk + rw [erp, andNotMask_chainA _ hn hpgm hle, e1, mask_page_eqA q b' _ hpg39 hbal g1 (by omega)] exact hpg /-- The buffer's word 0 is aligned. -/ @@ -146,7 +169,7 @@ theorem JStage3A.bufAlign0A {R7 : Set U64 → JSlotA S} {d : U64} (hd : d ∈ Z.T) {xd : Tcb} (hkd : σ.kheap (specPtr d) = some (.tcb xd)) (b : Bool) : ∀ rp, ipcBufOfA b xd = some rp → (bufAddr rp 0).toNat % 8 = 0 := by intro rp hrp - obtain ⟨q, vms, -, hal, erp, -⟩ := J.bufFrameObjA hd hkd b hrp + obtain ⟨q, vms, -, -, -, -, -, hal, erp, -⟩ := J.bufFrameObjA hd hkd b hrp have hn := pageBitsA_mem vms have hn39 : pageBitsForSize vms ≤ 39 := by simp at hn; omega have hn10 : 10 ≤ pageBitsForSize vms := by simp at hn; omega @@ -199,10 +222,13 @@ theorem JStage3A.specZero_of_recvBufA {R7 : Set U64 → JSlotA S} by_contra hne have hB : Sched.BufBytesA (ipcBufOfA true xd) x := Classical.byContradiction fun h => hne (hum x h) obtain ⟨rp, hrp, k, hk, y, hy, rfl⟩ := hB - obtain ⟨q, vms, hH, -, erp, -⟩ := J.bufFrameObjA hd hkd true hrp + obtain ⟨q, vms, b', pg, hH, g1, g2, -, erp, -⟩ := J.bufFrameObjA hd hkd true hrp obtain ⟨u, hu, qu, b, fi, dd, hc, -, f1, f2⟩ := hfree - have hO := J.objAlloc q (2 ^ pageBitsForSize vms) (Or.inr (Or.inr (Or.inr ⟨_, hH, rfl⟩))) u hu qu b fi dd hc - have hfit : q.val + 2 ^ pageBitsForSize vms ≤ 2 ^ 64 := J.sys.ent.heap.fits q _ hH + have hO := J.objAlloc b' (2 ^ pageBitsForSize pg) (Or.inr (Or.inr (Or.inr ⟨_, hH, rfl⟩))) u hu qu b fi dd hc + have hfit0 : b'.val + 2 ^ pageBitsForSize pg ≤ 2 ^ 64 := by + have := J.sys.ent.heap.fits b' _ hH; simpa [HKind.bits] using this + have h1p : 1 ≤ 2 ^ pageBitsForSize vms := Nat.one_le_two_pow + have hfit : q.val + 2 ^ pageBitsForSize vms ≤ 2 ^ 64 := by omega rw [erp] at f1 f2 have hb := fl4Ptr_bufA (pageBitsA_mem vms) hfit xd.tcbIpcBuffer (J.bufAl d hd xd hkd) hk hy omega diff --git a/proofs/Fl4ProofsA64/P3/Stage3ReplyErrBufA.lean b/proofs/Fl4ProofsA64/P3/Stage3ReplyErrBufA.lean index d61c105f4..88726c4b6 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ReplyErrBufA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ReplyErrBufA.lean @@ -35,6 +35,18 @@ theorem maskAndA_toNat (x : BitVec 64) {k : Nat} (hk : k ∈ [12, 21, 30]) : theorem pageBitsA_mem (vms : VMPageSize) : pageBitsForSize vms ∈ [12, 21, 30] := by cases vms <;> simp [pageBitsForSize, pageBits, ptTranslationBits] +/-- Masking down to a smaller page then to a larger one is masking down to the larger one. -/ +theorem andNotMask_chainA (X : BitVec 64) {n pg : Nat} (hn : n ∈ [12, 21, 30]) (hpg : pg ∈ [12, 21, 30]) + (hle : n ≤ pg) : X &&& ~~~(Fl4SpecA64.mask pg : BitVec 64) = + (X &&& ~~~(Fl4SpecA64.mask n : BitVec 64)) &&& ~~~(Fl4SpecA64.mask pg : BitVec 64) := by + apply BitVec.eq_of_toNat_eq + rw [andNotMaskA_toNat _ hpg, andNotMaskA_toNat _ hpg, andNotMaskA_toNat _ hn] + obtain ⟨t, ht⟩ : ∃ t, 2 ^ pg = 2 ^ n * t := ⟨2 ^ (pg - n), by rw [← Nat.pow_add]; congr 1; omega⟩ + have hm : 0 < 2 ^ n := Nat.pow_pos (by norm_num) + have key : X.toNat / 2 ^ n * 2 ^ n / 2 ^ pg = X.toNat / 2 ^ pg := by + rw [ht, ← Nat.div_div_eq_div_mul, ← Nat.div_div_eq_div_mul, Nat.mul_div_cancel _ hm] + rw [key] + /-- **The page of a buffer word** (module docstring). -/ theorem bufAddr_pageA {q : U64} {n : Nat} (hn : n ∈ [12, 21, 30]) (hq : q.val % 2 ^ n = 0) (w : BitVec 64) (hw : w.toNat % 1024 = 0) {k : Nat} (hk : k < 128) : @@ -83,9 +95,10 @@ theorem _root_.Fl4ProofsA64.P3.JStage3A.replyBufObjA {R7 : Set U64 → JSlotA 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 R7) s a σ m) {d : U64} (hd : d ∈ Z.T) {xd : Tcb} (hkd : σ.kheap (specPtr d) = some (.tcb xd)) (b : Bool) {rp : ObjRef} (hrp : ipcBufOfA b xd = some rp) : - ∃ q vms, H q = some (.other (pageBitsForSize vms)) ∧ q.val % 2 ^ pageBitsForSize vms = 0 ∧ + ∃ q vms b' pg, H b' = some (.other (pageBitsForSize pg)) ∧ b'.val ≤ q.val ∧ + q.val + 2 ^ pageBitsForSize vms ≤ b'.val + 2 ^ pageBitsForSize pg ∧ q.val % 2 ^ pageBitsForSize vms = 0 ∧ rp = specPtr q + (xd.tcbIpcBuffer &&& Fl4SpecA64.mask (pageBitsForSize vms)) ∧ - σ.kheap (specPtr q) = some (.archObj (.dataPage false vms)) := by + σ.kheap (specPtr b') = some (.archObj (.dataPage false pg)) := by have hth : Z.th d = some .tcb := (J.sr.thT d).2 hd obtain ⟨x', hk', hs⟩ := J.j.1.st.tcb d hth rw [hkd] at hk' @@ -109,15 +122,15 @@ theorem _root_.Fl4ProofsA64.P3.JStage3A.replyBufObjA {R7 : Set U64 → JSlotA S} simp only [absCapA, absFrameE, Bool.false_eq_true, ↓reduceIte] at hrp split_ifs at hrp exact (Option.some.inj hrp).symm - have hpg := J.userFr _ hyOS q sz r mp false asid va hc + obtain ⟨b', pg, hHb, hk, g1, g2⟩ := J.userFr _ hyOS q sz r mp false asid va hc obtain ⟨Pt, Ub, -, -, -, cc, -⟩ := J.j7 have hfo := cc.fo _ hyOS q sz r mp false asid va hc - have hH : H q = some (.other (pageBitsForSize (frameSizeOfA sz))) := by + have hal : q.val % 2 ^ pageBitsForSize (frameSizeOfA sz) = 0 := by cases sz - · exact hfo 12#u64 rfl - · exact hfo 21#u64 rfl - · exact hfo 30#u64 rfl - exact ⟨q, frameSizeOfA sz, hH, J.sys.ent.heap.align q _ hH, erp, hpg⟩ + · exact (hfo 12#u64 rfl).al J.sys.ent.heap + · exact (hfo 21#u64 rfl).al J.sys.ent.heap + · exact (hfo 30#u64 rfl).al J.sys.ent.heap + exact ⟨q, frameSizeOfA sz, b', pg, hHb, g1, g2, hal, erp, hk⟩ · unfold ipcBufOfA at hrp; rw [← hab] at hrp; simp [absCapA, absFrameE] at hrp · unfold ipcBufOfA at hrp; rw [← hab] at hrp; cases ept <;> simp [absCapA, absFrameE] at hrp | _ => @@ -130,9 +143,19 @@ theorem _root_.Fl4ProofsA64.P3.JStage3A.replyBufFrameA {R7 : Set U64 → JSlotA {d : U64} (hd : d ∈ Z.T) {xd : Tcb} (hkd : σ.kheap (specPtr d) = some (.tcb xd)) (b : Bool) : ∀ rp, ipcBufOfA b xd = some rp → ∀ k, k < 128 → inUserFrame (bufAddr rp k) σ := by intro rp hrp k hk - obtain ⟨q, vms, -, hal, erp, hpg⟩ := J.replyBufObjA hd hkd b hrp - refine ⟨vms, ?_⟩ - rw [erp, bufAddr_pageA (pageBitsA_mem _) hal _ (J.bufAl d hd xd hkd) hk] + obtain ⟨q, vms, b', pg, hHb, g1, g2, hal, erp, hpg⟩ := J.replyBufObjA hd hkd b hrp + refine ⟨pg, ?_⟩ + have hn := pageBitsA_mem vms + have hpgm := pageBitsA_mem pg + have h1p : 1 ≤ 2 ^ pageBitsForSize vms := Nat.one_le_two_pow + have hle : pageBitsForSize vms ≤ pageBitsForSize pg := by + have h3 : 2 ^ pageBitsForSize vms ≤ 2 ^ pageBitsForSize pg := by omega + exact (Nat.pow_le_pow_iff_right (by norm_num)).1 h3 + have hbal : b'.val % 2 ^ pageBitsForSize pg = 0 := by + have := J.sys.ent.heap.align b' _ hHb; simpa [HKind.bits] using this + have hpg39 : pageBitsForSize pg ≤ 39 := by simp at hpgm; omega + have e1 := bufAddr_pageA hn hal xd.tcbIpcBuffer (J.bufAl d hd xd hkd) hk + rw [erp, andNotMask_chainA _ hn hpgm hle, e1, mask_page_eqA q b' _ hpg39 hbal g1 (by omega)] exact hpg /-- The buffer's word 0 is aligned. -/ @@ -141,7 +164,7 @@ theorem _root_.Fl4ProofsA64.P3.JStage3A.replyBufAlign0A {R7 : Set U64 → JSlotA {d : U64} (hd : d ∈ Z.T) {xd : Tcb} (hkd : σ.kheap (specPtr d) = some (.tcb xd)) (b : Bool) : ∀ rp, ipcBufOfA b xd = some rp → (bufAddr rp 0).toNat % 8 = 0 := by intro rp hrp - obtain ⟨q, vms, -, hal, erp, -⟩ := J.replyBufObjA hd hkd b hrp + obtain ⟨q, vms, -, -, -, -, -, hal, erp, -⟩ := J.replyBufObjA hd hkd b hrp have hn := pageBitsA_mem vms have hn39 : pageBitsForSize vms ≤ 39 := by simp at hn; omega have hn10 : 10 ≤ pageBitsForSize vms := by simp at hn; omega @@ -194,10 +217,13 @@ theorem _root_.Fl4ProofsA64.P3.JStage3A.replyBufZeroA {R7 : Set U64 → JSlotA S by_contra hne have hB : BufBytesA (ipcBufOfA true xd) x := Classical.byContradiction fun h => hne (hum x h) obtain ⟨rp, hrp, k, hk, y, hy, rfl⟩ := hB - obtain ⟨q, vms, hH, -, erp, -⟩ := J.replyBufObjA hd hkd true hrp + obtain ⟨q, vms, b', pg, hH, g1, g2, -, erp, -⟩ := J.replyBufObjA hd hkd true hrp obtain ⟨u, hu, qu, b, fi, dd, hc, -, f1, f2⟩ := hfree - have hO := J.objAlloc q (2 ^ pageBitsForSize vms) (Or.inr (Or.inr (Or.inr ⟨_, hH, rfl⟩))) u hu qu b fi dd hc - have hfit : q.val + 2 ^ pageBitsForSize vms ≤ 2 ^ 64 := J.sys.ent.heap.fits q _ hH + have hO := J.objAlloc b' (2 ^ pageBitsForSize pg) (Or.inr (Or.inr (Or.inr ⟨_, hH, rfl⟩))) u hu qu b fi dd hc + have hfit0 : b'.val + 2 ^ pageBitsForSize pg ≤ 2 ^ 64 := by + have := J.sys.ent.heap.fits b' _ hH; simpa [HKind.bits] using this + have h1p : 1 ≤ 2 ^ pageBitsForSize vms := Nat.one_le_two_pow + have hfit : q.val + 2 ^ pageBitsForSize vms ≤ 2 ^ 64 := by omega rw [erp] at f1 f2 have hb := fl4Ptr_bufA (pageBitsA_mem vms) hfit xd.tcbIpcBuffer (J.bufAl d hd xd hkd) hk hy omega diff --git a/proofs/Fl4ProofsA64/P3/Stage3SchedPresA.lean b/proofs/Fl4ProofsA64/P3/Stage3SchedPresA.lean index c903ef375..f870bbfbe 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SchedPresA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SchedPresA.lean @@ -239,7 +239,15 @@ theorem JAtZAX.of_sched {AR : A → HwRootA → Prop} {Z : XSetsA} {s s' : S} {a rcases hq with hq | hq | hq · obtain ⟨f, hk, -⟩ := J.vs.pool q hq; rw [hk] at h; cases h; rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e · obtain ⟨es, hk, -⟩ := J.ext.s2root q hq; rw [hk] at h; cases h; rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e - · obtain ⟨pt, hk, -⟩ := J.ext.s2pt q hq; rw [hk] at h; cases h; rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e } + · obtain ⟨pt, hk, -⟩ := J.ext.s2pt q hq; rw [hk] at h; cases h; rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e + vsu := J.vsuOf H.ksb (fun b hb => by + rcases hb with hb | hb + · exact H.ext b hb + · exact H.vs b hb) + ⟨HS.asid, fun p hp => HS.other (fun x h => J.vs.not_tcb (Or.inl ⟨p, hp, rfl⟩) h) (fun o ho h => by + obtain ⟨f, hk, -⟩ := J.vs.pool p hp; rw [hk] at h; cases h + rcases ho with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e)⟩ + (PtClosedA.of_cap fun y hy => Or.inl (hcap y (Or.inl hy))) } have hsl : ∀ y, IsSlotA Z.th y → capAtA (L.mem s') y = capAtA (L.mem s) y := fun y hy => hcap y (Or.inl hy) refine ⟨J', ?_, ?_, ?_⟩ · refine ⟨fun v hv => ?_, fun p x e => V.back p x (HS.back e (fun _ h => by cases h) (fun h => by rcases h with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e)), diff --git a/proofs/Fl4ProofsA64/P3/Stage3SchedWrA.lean b/proofs/Fl4ProofsA64/P3/Stage3SchedWrA.lean index a6646d107..c6a780f4f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SchedWrA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SchedWrA.lean @@ -776,7 +776,7 @@ theorem JStage3A.of_schedWrD {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea rw [HS.orig] exact J.nullOrig sl (by rw [← SpecSchedA.specCapAt HS sl]; exact h) thPos := fun p z h => J.thPos p z h - frBase := J.frBase.keepA capE + frBase := J.frBase.keepOS osk devFr := J.devFr.keepA capE fun p dev pg h => HS.keep h (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e) finCov := J.finCov.keepA @@ -867,7 +867,7 @@ theorem JStage3A.of_schedWrD {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea (fun v _ x hx => HS.back hx (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e)) vcOS := J.vcOS - userFr := J.userFr.keepA capE fun p dev pg h => HS.keep h (fun _ e => by cases e) + userFr := J.userFr.keepA capE (fun _ _ e => e) fun p dev pg h => HS.keep h (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e) frTh := J.frTh.keepA capE fun _ _ e => e bfSpec := J.bfSpec diff --git a/proofs/Fl4ProofsA64/P3/Stage3SchedWrNA.lean b/proofs/Fl4ProofsA64/P3/Stage3SchedWrNA.lean index 953a01837..3e25e7b83 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SchedWrNA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SchedWrNA.lean @@ -584,7 +584,7 @@ theorem JStage3A.of_schedWrXSS {Ac' : Set U64} {AR : A → HwRootA → Prop} {Z rw [HS.orig] exact J.nullOrig sl (by rw [← SpecSchedA.specCapAt HS sl]; exact h) thPos := fun p z h => J.thPos p z h - frBase := J.frBase.keepA capE + frBase := J.frBase.keepOS osk devFr := J.devFr.keepA capE fun p dev pg h => HS.keep h (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e) finCov := J.finCov.keepA @@ -672,7 +672,7 @@ theorem JStage3A.of_schedWrXSS {Ac' : Set U64} {AR : A → HwRootA → Prop} {Z (fun v _ x hx => HS.back hx (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e)) vcOS := J.vcOS - userFr := J.userFr.keepA capE fun p dev pg h => HS.keep h (fun _ e => by cases e) + userFr := J.userFr.keepA capE (fun _ _ e => e) fun p dev pg h => HS.keep h (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e) frTh := J.frTh.keepA capE fun _ _ e => e bfSpec := J.bfSpec diff --git a/proofs/Fl4ProofsA64/P3/Stage3SchedWrNTA.lean b/proofs/Fl4ProofsA64/P3/Stage3SchedWrNTA.lean index 3c038835d..03d366fc4 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SchedWrNTA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SchedWrNTA.lean @@ -610,7 +610,7 @@ theorem JStage3BA.of_schedWrX {AR : A → HwRootA → Prop} {Z : XSetsA} {H : He rw [HS.orig] exact J.nullOrig sl (by rw [← SpecSchedA.specCapAt HS sl]; exact h) thPos := fun p z h => J.thPos p z h - frBase := J.frBase.keepA capE + frBase := J.frBase.keepOS osk devFr := J.devFr.keepA capE fun p dev pg h => HS.keep h (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e) finCov := J.finCov.keepA diff --git a/proofs/Fl4ProofsA64/P3/Stage3SchedWrSTA.lean b/proofs/Fl4ProofsA64/P3/Stage3SchedWrSTA.lean index 11c357bd1..03b6592ee 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SchedWrSTA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SchedWrSTA.lean @@ -333,7 +333,7 @@ theorem JStage3TA.of_schedWrSX {AR : A → HwRootA → Prop} {Z : XSetsA} {H : H rw [HS.orig] exact J.nullOrig sl (by rw [← SpecSchedA.specCapAt HS sl]; exact h) thPos := fun p z h => J.thPos p z h - frBase := J.frBase.keepA capE + frBase := J.frBase.keepOS osk devFr := J.devFr.keepA capE fun p dev pg h => HS.keep h (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e) finCov := J.finCov.keepA diff --git a/proofs/Fl4ProofsA64/P3/Stage3SchedWrTA.lean b/proofs/Fl4ProofsA64/P3/Stage3SchedWrTA.lean index 67fd7fc59..09bf76c8d 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SchedWrTA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SchedWrTA.lean @@ -748,7 +748,7 @@ theorem JStage3TA.of_schedWr {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea rw [HS.orig] exact J.nullOrig sl (by rw [← SpecSchedA.specCapAt HS sl]; exact h) thPos := fun p z h => J.thPos p z h - frBase := J.frBase.keepA capE + frBase := J.frBase.keepOS osk devFr := J.devFr.keepA capE fun p dev pg h => HS.keep h (fun _ e => by cases e) (fun e => by rcases e with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ <;> cases e) finCov := J.finCov.keepA diff --git a/proofs/Fl4ProofsA64/P3/Stage3ScopeArmsA.lean b/proofs/Fl4ProofsA64/P3/Stage3ScopeArmsA.lean index 1b6984f13..6487d5564 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3ScopeArmsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3ScopeArmsA.lean @@ -189,30 +189,6 @@ theorem JSyscallA.ptMapS1_scopeA subst hsl exact ⟨_, Or.inl (VsScopeA.ptMapS1 (s3 := s3) (a3 := a3) (ptr := ptr) (asid0 := asid0) (va0 := va0) (bB := bB) (bC := bC) (bD := bD) (bF := bF) (hnvm := Q.nvm) (cte := sl) (hab := Q.F.pin.habs) (hcap := hcap) (UP := UP) (hS2 := hS2) (hY := hY) (slbl := (specLabelWord (archL .armPageTableMap))) (hl := (by rw [invType_specA]; rfl)) (length := (msgLenA info buf)) (buf := buf) (args := argsU) (hlen := Q.F.len) (hargs := Q.F.args) (extra := extra) (x0 := x0) (hx0 := hx0) (exs := excaps) (hex := (by rw [show x0 = exAtA extra 0 from okinj (hx0.symm.trans (exAtA_idx0 extra))]; exact Q.F.extra.rel1 Q.place)) (hS1 := hS1) (hHi := hHi) (hdec := hdec) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hpin := (ptMapS1_pinA Q.F hlab ((capAtA_eq _ _).symm.trans hcap) hx0 hS1 hHi)))⟩ -/-- `VsScopeA.ptUnmapS1` at the invocation site. -/ -theorem JSyscallA.ptUnmapS1_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) - (ptr asid va : U64) - (hpS : ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr) - (hcap : capA st s slot = .PageTable ptr true asid va) - (hf : cdt.is_final_capability st s slot = ok true) - (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ - Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) - -- [J] the spec's mapped page-table cap at the slot is the canonical one (record edit #8b part C) - (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.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). -/ @@ -236,10 +212,34 @@ theorem JSyscallA.finPtOtherA {R : Set U64 → JSlotA S} 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)) + (F.fr.1 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.ptUnmapS1` at the invocation site. -/ +theorem JSyscallA.ptUnmapS1_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) + (ptr asid va : U64) + (hpS : ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr) + (hcap : capA st s slot = .PageTable ptr true asid va) + (hf : cdt.is_final_capability st s slot = ok true) + (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ + Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) + -- [J] the spec's mapped page-table cap at the slot is the canonical one (record edit #8b part C) + (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.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) (hno := J.finPtOtherA Q.F.pin.habs hcap hf) (hS1 := hS1) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hpin := (ptUnmapS1_pinA Q.F J hlab hcap hcan hf hS1)))⟩ + /-- `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) @@ -264,7 +264,29 @@ theorem JSyscallA.ptUnmapX_scopeA rw [hlab] have hsl := Q.F.pin.hslot 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)))⟩ + 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) (hno := J.finPtOtherA Q.F.pin.habs hcap 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.ptUnmapT2Stale` at the invocation site. -/ +theorem JSyscallA.ptUnmapT2Stale_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) + (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) + (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ + Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) + -- [J] the spec's mapped page-table cap at the slot is the canonical one (record edit #8b part C) + (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.ptUnmapT2Stale (bB := bB) (bC := bC) (bD := bD) (bF := bF) (K := K) (hnvm := Q.nvm) (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) (hno := J.finPtOtherA Q.F.pin.habs hcap hf) (hS1 := hS1) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hpin := (ptUnmapS1_pinA Q.F J hlab hcap hcan hf hS1)))⟩ /-- `VsScopeA.ptUnmapT2` at the invocation site: `hno` is the finality test read on the slots. [J] `hUniq`. -/ theorem JSyscallA.ptUnmapT2_scopeA @@ -340,6 +362,41 @@ theorem JSyscallA.asidAssign_scopeA subst hsl exact ⟨_, Or.inl (VsScopeA.asidAssign (hnvm := Q.nvm) (cte := sl) (hab := Q.F.pin.habs) (p := p) (base := base) (hpool := hpool) (length := (msgLenA info buf)) (buf := buf) (block := block) (call := call) (cd := cd) (fp := fp) (ex := extra) (dst := dst) (hd0 := hd0) (hex := hex) (k := k) (root := root) (oldAsid := oldAsid) (oldVa := oldVa) (hcap := hcap) (htab := htab) (hp0 := hp0) (i := i) (hsearch := hsearch) (hfull := hfull) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hpin := (asidAssign_pinA (block := block) (cd := cd) (fp := fp) hA hM hPl J hfm Q.F hlab Q.nvm hpool hd0 hex hcap htab hp0 hsearch hfull Q.cov Q.hext Q.hSC)))⟩ +/-- `VsScopeA.asidMakePool` at the invocation site (`hpin`: the spec's decode of label 58 has the MakePool outcome). -/ +theorem JSyscallA.asidMakePool_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.ARMASIDControlMakePool) + (hnN : n ≤ Fl4SpecA64.fl4A64Platform.numNodes) + (h1 : Fl4SpecA64.fl4A64Platform.numNodes = 1) (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) + (hn : hPl.ipa.val = fl4A64Platform.s2IpaBits) + (hcteC : capA st s slot = .AsidControl) + (parent dest : Fl4SpecA64.CslotPtr) (frame fi i base : U64) + (hAp : AbsSlotA Z.th parent) (hAd : AbsSlotA Z.th dest) + (hdc : ∃ y ∈ OS, ∃ q r gs g : U64, capA st s y = .CNode q r gs g ∧ dest.1 = specPtr q) + (hCp : ∃ pp, parent.1 = specPtr pp ∧ Z.th pp = some (.cnode parent.2.length)) + (hCd : ∃ pd, dest.1 = specPtr pd ∧ Z.th pd = some (.cnode dest.2.length)) (hdr : dest.2.length ≠ 0) + (block call cd fp : Bool) + (hx0 : exAtA extra 0 ≠ 0#u64) (hx1 : exAtA extra 1 ≠ 0#u64) (hlen2 : msgLenA info buf ≥ 2#u64) (a0 a1 : U64) + (ha0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok a0) (ha1 : msg.syscall_arg st s (L.curW s) buf 1#u64 = ok a1) + (hpa : cslotAddrA parent = exAtA extra 0) (hcp : capA st s (cslotAddrA parent) = .Untyped frame 12#u64 fi false) + (hnc : cdt.ensure_no_children st s (cslotAddrA parent) = ok (core.result.Result.Ok ())) + (hiOk : vspace.decode_loop0 st s 0#u64 = ok i) (hi : i.val < 128) (hfree : L.mem s (atAF (L.ksb s) i) = 0#u64) + (hbaseOk : (i <<< vspace.ASID_LOW_BITS : Result U64) = ok base) (hbase : base.val = i.val * 512) + (hlt : cspace.lookup_slot_for_cnode_op st s false (capA st s (exAtA extra 1)) a0 a1 = + ok (core.result.Result.Ok (cslotAddrA dest))) + (hcd : capA st s (cslotAddrA dest) = .Null) + (hpin : DecPinA call Z.th σ slot (.invokeArchObject (.spec (.invokeASIDControl + (.makePool (specPtr frame) dest parent (asidOfA base)))))) : + ∃ 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 block call cd fp buf extra Out := by + rw [hlab] + have hsl := Q.F.pin.hslot + subst hsl + exact ⟨_, Or.inl (VsScopeA.asidMakePool hnN h1 hCs hn Q.nvm sl Q.F.pin.habs hcteC Q.cov extra Q.hext Q.hSC + parent dest frame fi i base hAp hAd hdc hCp hCd hdr (msgLenA info buf) buf block call cd fp hx0 hx1 hlen2 a0 a1 ha0 ha1 + hpa hcp hnc hiOk hi hfree hbaseOk hbase hlt hcd hpin)⟩ + /-- `VsScopeA.frameMapHi` at the invocation site. -/ theorem JSyscallA.frameMapHi_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) @@ -390,6 +447,42 @@ theorem JSyscallA.frameMapHi_scopeA subst hsl exact ⟨_, Or.inl (VsScopeA.frameMapHi (x0 := x0) (D := D) (dc := dc) (ex := extra) (s3 := s3) (a3 := a3) (callD := callD) (lenD := (msgLenA info buf)) (bufD := buf) (rr := rr) (bB := bB) (bD := bD) (bF := bF) (K := K) (hnvm := Q.nvm) (hTO := hTO) (hEO := hEO) (cte := sl) (hab := Q.F.pin.habs) (fp := fp) (rt := rt) (asid := asid) (va := va) (sz := sz) (dev := dev) (mp := mp) (hcap := hcap) (FP := FP) (p1 := p1) (asid1 := asid1) (mp1 := mp1) (h16 := h16) (hx0 := hx0) (hx0c := hx0c) (vaddr := vaddr) (rightsMask := rightsMask) (vm := vm) (attr := attr) (hvmEq := hvmEq) (hD := hD) (d := d) (hres := hres) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hx := hx) (hlen := hlen) (h0 := h0) (h1 := h1) (h2 := h2) (hr := hr) (hvm := hvm) (hpin := (frameMapHi_pinA Q.F hlab ((capAtA_eq _ _).symm.trans hcap) hx hx0c hlen h0 h1 h2 hD)))⟩ +set_option maxHeartbeats 8000000 in +/-- `VsScopeA.frameDeriveSub` at the invocation site. -/ +theorem JSyscallA.frameDeriveSub_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.ARMPageDeriveSubframe) + {s3 : S} + {a3 : A} + {fp rt asid va : U64} + {mp e : Bool} + {bB bD bF : Bool} + (call : Bool) + (hcap : capAtA (L.mem s) slot = .Frame fp .Large rt false mp e asid va) + (x0 : U64) + (hx0 : Aeneas.Std.Array.index_usize extra 0#usize = ok x0) + (xSlot : CapRef) + (hdec : vspace.decode_frame st ar s a fl4_abi.label.ARMPageDeriveSubframe (msgLenA info buf) slot + (.Frame fp .Large rt false mp e asid va) call buf extra = ok (core.result.Result.Ok (), s3, a3)) : + ∃ 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 call bD bF buf extra Out := by + rw [hlab] + have hsl := Q.F.pin.hslot + subst hsl + have hD : (fl4ArchDecodeInvocation (Z := Unit) call (.ext .armPageDeriveSubframe) (argsU.map UScalar.bv) xSlot sl + (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA .Large) false (mapDataA mp asid va)) excaps).run σ = + (fl4ArchDecodeInvocation (Z := Unit) call (.ext .armPageDeriveSubframe) (argsU.map UScalar.bv) xSlot sl + (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA .Large) false (mapDataA mp asid va)) excaps).run σ := rfl + have hpin := frameDeriveSub_pinA Q.F hlab ((capAtA_eq _ _).symm.trans hcap) xSlot hD + have hex : ExtraRelA Z.th (L.mem s) x0 (excaps.map Prod.fst) := by + rw [show x0 = exAtA extra 0 from okinj (hx0.symm.trans (exAtA_idx0 extra))]; exact Q.F.extra.rel1 Q.place + exact ⟨_, Or.inl (VsScopeA.frameDeriveSub (s3 := s3) (a3 := a3) (fp := fp) (rt := rt) (asid := asid) (va := va) + (mp := mp) (e := e) (bB := bB) (bD := bD) (bF := bF) (hnvm := Q.nvm) (cte := sl) (hab := Q.F.pin.habs) + (hcap := hcap) (length := (msgLenA info buf)) (buf := buf) (call := call) (ex := extra) + (args := argsU) (hlen := Q.F.len) (hargs := Q.F.args) (x0 := x0) (hx0 := hx0) (xSlot := xSlot) (exs := excaps) + (hex := hex) (hD := rfl) (hdec := hdec) (hcov := Q.cov) (hext := Q.hext) (hpin := hpin))⟩ + /-- `CnScopeA.cnodeCopy` at the invocation site. -/ theorem JSyscallA.cnodeCopy_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) @@ -409,7 +502,7 @@ theorem JSyscallA.cnodeCopy_scopeA (hdc : obj.sext48 (cslotAddrA sd) = ok (cslotAddrA sd)) (hw : CapRt.EncWf nc) (hn : nc ≠ .Null) - (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA 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))) @@ -447,7 +540,7 @@ theorem JSyscallA.cnodeCopy_scopeA (by have := lblA_copy; have := lblA_mint; have := lblA_move; have := lblA_mutate; rcases hlb with h | h <;> subst h <;> refine ⟨?_, ?_⟩ <;> scalar_tac) ⟨_, hCs.1, Or.inl hCs.2⟩ ⟨_, hCd.1, Or.inl hCd.2⟩ hsn hdn hn hslc hl4 hi hd0 hres hx0 h0 h2 h3 hroot hsrc hcop rw [hlab] - exact ⟨_, Or.inr (Or.inl (CnScopeA.cnodeCopy (ps := ps) (pd := pd) (nc := nc) (anc := anc) (slot := slot) (p := p) (r := r) (gs := gs) (g := g) (extra := extra) (length := (msgLenA info buf)) (buf := buf) (lbl := lbl) (index := index) (depth := depth) (x0 := x0) (si := si) (sdp := sdp) (root := root) (bB := bB) (bC := bC) (bD := bD) (hnvm := Q.nvm) (ss := ss) (sd := sd) (hCs := hCs) (hCd := hCd) (hsn := hsn) (hdn := hdn) (hdc := hdc) (hwf := hrel.1) (hanc := hrel.2) (hw := hw) (hn := hn) (hD := hD) (hal := hal) (hk := hk) (hsh := hsh) (hsh1 := hsh1) (hbd1 := hbd1) (hbd := hbd) (hirq := hirq) (hz := hz) (hut := hut) (hdo := hdo) (hcv := hcv) (hsci := (hsci anc hrel hnh)) (hslot := Q.hOS) (hslc := hslc) (hlb := hlb) (hl4 := hl4) (hl2 := hl2) (hi := hi) (hd0 := hd0) (hres := hres) (hx0 := hx0) (h0 := h0) (h2 := h2) (h3 := h3) (hroot := hroot) (hemp := hemp) (hsrc := hsrc) (hcop := hcop) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hpin := hpin)))⟩ + exact ⟨_, Or.inr (Or.inl (CnScopeA.cnodeCopy (ps := ps) (pd := pd) (nc := nc) (anc := anc) (slot := slot) (p := p) (r := r) (gs := gs) (g := g) (extra := extra) (length := (msgLenA info buf)) (buf := buf) (lbl := lbl) (index := index) (depth := depth) (x0 := x0) (si := si) (sdp := sdp) (root := root) (bB := bB) (bC := bC) (bD := bD) (hnvm := Q.nvm) (ss := ss) (sd := sd) (hCs := hCs) (hCd := hCd) (hsn := hsn) (hdn := hdn) (hdc := hdc) (hwf := hrel.1) (hanc := hrel.2) (hw := hw) (hn := hn) (hD := hD) (hrd := hrd) (hal := hal) (hk := hk) (hsh := hsh) (hsh1 := hsh1) (hbd1 := hbd1) (hbd := hbd) (hirq := hirq) (hz := hz) (hut := hut) (hdo := hdo) (hcv := hcv) (hsci := (hsci anc hrel hnh)) (hslot := Q.hOS) (hslc := hslc) (hlb := hlb) (hl4 := hl4) (hl2 := hl2) (hi := hi) (hd0 := hd0) (hres := hres) (hx0 := hx0) (h0 := h0) (h2 := h2) (h3 := h3) (hroot := hroot) (hemp := hemp) (hsrc := hsrc) (hcop := hcop) (hcov := Q.cov) (hext := Q.hext) (hSC := Q.hSC) (hpin := hpin)))⟩ /-- `CnScopeA.cnodeMove` at the invocation site. -/ theorem JSyscallA.cnodeMove_scopeA @@ -998,6 +1091,7 @@ structure CnCopyArmA (st : machine.Store S) [L : LawfulStore st] (Z : XSetsA) (O hw : CapRt.EncWf nc hn : nc ≠ .Null hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss)) + hrd : RootDerivA 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)) @@ -1036,7 +1130,7 @@ theorem JSyscallA.cnodeCopyArm_scopeA ∃ 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 false buf extra Out := J.cnodeCopy_scopeA hA hM hPl hfm Q (lbl := info.label) (bB := bB) (bC := bC) (bD := bD) - X.ss X.sd X.hCs X.hCd X.hsn X.hdn X.hdc X.hw X.hn X.hD X.hal X.hk X.hsh X.hsh1 X.hbd1 X.hbd X.hirq X.hz X.hut X.hdo X.hcv X.hslc X.hlb X.hl4 X.hl2 X.hi X.hd0 X.hres X.hx0 X.h0 X.h2 X.h3 X.hroot X.hemp X.hsrc X.hcop X.hsci rfl + X.ss X.sd X.hCs X.hCd X.hsn X.hdn X.hdc X.hw X.hn X.hD X.hrd X.hal X.hk X.hsh X.hsh1 X.hbd1 X.hbd X.hirq X.hz X.hut X.hdo X.hcv X.hslc X.hlb X.hl4 X.hl2 X.hi X.hd0 X.hres X.hx0 X.h0 X.h2 X.h3 X.hroot X.hemp X.hsrc X.hcop X.hsci rfl end diff --git a/proofs/Fl4ProofsA64/P3/Stage3SendErrAllA.lean b/proofs/Fl4ProofsA64/P3/Stage3SendErrAllA.lean index 08eb47baa..4edd5cf32 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3SendErrAllA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3SendErrAllA.lean @@ -67,7 +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 : PtMapSiteA st Z H OS σ s) (hFrMap : FrMapSiteA st OS s) (hFrSub : FrSubSiteA st Z OS s) + (hPtMap : PtMapSiteA st Z H OS σ s) (hFrMap : FrMapSiteA st 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 → @@ -94,7 +94,7 @@ theorem _root_.Fl4ProofsA64.P3.JSyscallA.sendBodyErrAllA [PlainStore st] (hA : P (fl4SettleDispatch pending (fl4DispatchSyscall (fl4HandleInvocationR (Z := Unit) true) call)) σ r ⦄ := J.sendBodyErrA (hCnt := hCnt) hA hM hPl hfm hIP call hc hFault hArm (fun _ _ _ => J.decErrSpecA hA hM hPl K hIP hT hP hAK hfm hfan hv hIpa hnum hCs hCsN h1 hsb hYAs hFI hcO hD hPtMap hFrMap - hFrSub hAsidAssign hNoS2 hAgreeWS hAgreeRun) hKeep XP HEnv + hAsidAssign hNoS2 hAgreeWS hAgreeRun) hKeep XP HEnv end diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmStaleA.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmStaleA.lean new file mode 100644 index 000000000..509bf3f78 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmStaleA.lean @@ -0,0 +1,94 @@ +/- +P3 (AArch64, vsinv RO3): **the stale Stage-2 table unmap at a syscall entry** — `JSyscallA.ptUnmapT2StaleA`, the T3 wrapper of +`JStage3A.ptUnmapT2StaleA` (`P3/Stage3ArmPtUnmStaleA`); the ghost `T2` loses `ptr` (`J7A.shrinkT2A`). No named premise +besides `hno` (derived at the site from the finality test). New module. +-/ +import Fl4ProofsA64.P3.Stage3T3ArmT2A +import Fl4ProofsA64.P3.Stage3ArmPtUnmStaleA +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 + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} + +set_option maxHeartbeats 4000000 in +/-- **Page-table unmap of a Stage-2 table (`ptr ∈ Z.T2`) whose ASID names no Stage-2 root**, at a syscall entry; the ghost +`T2` loses `ptr`. -/ +theorem JSyscallA.ptUnmapT2StaleA + {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)) + (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) + (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ + Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) + (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') ∧ + ((), σ3) ∈ (Fl4SpecA64.performPageTableInvocation (Z := Unit) (.pageTableUnmap (.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.ptUnmapT2StaleA (ar := ar) (nA := hPl.ipa) (J := J.toJStage3A) (RS := RS) (K := K) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (hK := hK) (hT := hT) (length := length) (buf := buf) (ex := ex) (cte := cte) (hab := hab) (ptr := ptr) (asid := asid) (va := va) (hpT := hpT) (hcap := hcap) (hf := hf) (hno := hno) (hS1 := hS1) + (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/Stage3T3ArmSubA.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmSubA.lean new file mode 100644 index 000000000..88b26fa98 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmSubA.lean @@ -0,0 +1,100 @@ +/- +P3 (AArch64, E0.5d): **`ARMPageDeriveSubframe` at a syscall entry** (`JSyscallA.frameDeriveSubA`): from the decode's +success (`vspace.decode_frame … = ok (Ok (), s3, a3)`), the Ok view of `derive_subframe_jA` (`ArchTopSubA`) gives the +arguments and the run, `decodeFinSubA` the final-state `SymL` / `SysL` / J7, and `JStage3A.deriveSubframeA` the +`JStage3A` at `s3`; the spec side is the decode's `deriveSubframe` invocation and `performDeriveSubframe`. + +Named premises: none new (`hcO` is derived from the record, `OSOK.canon`, at the scope arm). +-/ +import Fl4ProofsA64.P3.Stage3ArmSubframeA +import Fl4ProofsA64.P3.Stage3T3ArmsA +import Fl4ProofsA64.P3.Stage3FinA +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} + +set_option maxHeartbeats 8000000 in +/-- **`ARMPageDeriveSubframe` at a syscall entry** (module docstring). -/ +theorem JSyscallA.frameDeriveSubA {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) (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) + (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (fp rt asid va : U64) (mp e : Bool) + (hcap : capAtA (L.mem s) (cslotAddrA cte) = .Frame fp .Large rt false mp e asid va) + (hcov : SlotCov st OS s (cslotAddrA cte)) (hcO : ∀ y ∈ OS, obj.sext48 y = ok y) + (length buf : U64) (call : Bool) (ex : Aeneas.Std.Array obj.Slot 3#usize) + (hext : ∀ x ∈ ex.val, x ≠ 0#u64 → x ∈ OS) + (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) + (x0 : U64) (hx0 : Aeneas.Std.Array.index_usize ex 0#usize = ok x0) + (xSlot : Fl4SpecA64.CapRef) (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) + (hex : ExtraRelA Z.th (L.mem s) x0 (exs.map Prod.fst)) + {s3 : S} {a3 : A} + (hdec : vspace.decode_frame st ar s a fl4_abi.label.ARMPageDeriveSubframe length (cslotAddrA cte) + (.Frame fp .Large rt false mp e asid va) call buf ex = ok (core.result.Result.Ok (), s3, a3)) : + ∃ (x : Fl4SpecA64.Tcb) (iv : Fl4SpecA64.Fl4SubframeInvocation) (σ3 : Fl4SpecA64.State Unit) (G2 : MdbGhostA), + a3 = a ∧ σ.kheap σ.curThread = some (.tcb x) ∧ + Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = + ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + (Fl4SpecA64.fl4ArchDecodeInvocation (Z := Unit) call (.ext .armPageDeriveSubframe) (args.map UScalar.bv) xSlot + cte (absFrameE e (specPtr fp) (vmRightsOfA rt) (frameSizeOfA .Large) false (mapDataA mp asid va)) exs).run σ = + ({(.ok (.deriveSubframe iv), σ)}, False) ∧ + ((), σ3) ∈ (Fl4SpecA64.performDeriveSubframe (Z := Unit) iv (stUpdA σ σ.curThread x .restart)).1 ∧ + JStage3A st AR { Z with G := G2 } 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 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 hfp := J.toJStage3A.largeFrAlCanA hslot hcap + have hj := derive_subframe_jA J.toJStage3A.toJEntA RS hTr J.j5.2.2 hcO cte hab fp rt asid va .Large false mp e hcap + (fun _ _ => hfp) length buf call ex args hlen hargs x0 hx0 xSlot exs hex + rw [decode_frame_subframeA ar length (cslotAddrA cte) fp rt asid va .Large false mp e call buf ex] at hdec + obtain ⟨ha3, -, dest, radix, first, offset, count, a5, vm, hk, hst, hth, hr1, hr58, hcnt, hfc, hoff4, hvm13, hvmSp, + hall, hins, hD⟩ := post_of_okA hj hdec + have hd : syscall.decode_invocation st ar s a fl4_abi.label.ARMPageDeriveSubframe length (cslotAddrA cte) + (.Frame fp .Large rt false mp e asid va) false call false false buf ex = ok (core.result.Result.Ok (), s3, a3) := + (decInv_frameA ar s a _ length _ fp .Large rt false mp e asid va false call false false buf ex).trans + (by rw [decode_frame_subframeA ar length (cslotAddrA cte) fp rt asid va .Large false mp e call buf ex]; exact hdec) + have hF : ∀ (σ' : Fl4SpecA64.State Unit), L.ksb s3 = L.ksb s ∧ ∃ 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 σ' m := + fun σ' => J.decodeFinSubA hA hPl hslot hcap hext hcov + ⟨fp, .Large, rt, false, mp, e, asid, va, rfl, rfl⟩ hd σ' m + have hFin : ∀ s2, vspace.insert_subframes st (L.wr s (stA (L.curW s)) sched.TS_RESTART) (cslotAddrA cte) dest first + (wa fp offset) count vm = ok s2 → s2 = s3 := fun s2 h => okinj (h.symm.trans hins) + obtain ⟨x, s2, σ2, G2, hk', heq, hset, hs2, hm, J3, hbk⟩ := JStage3A.deriveSubframeA (J := J.toJStage3A) RS hnvm + (ss := cte) hab (dest := dest) (r := radix.val) hth ⟨hr1, hr58⟩ (fp := fp) (rt := rt) (asid := asid) (va := va) + (offset := offset) (first := first) (count := count) (vm := vm) (mp := mp) (e := e) hvm13 hcnt hfc hcO hoff4 hcap hall + (fun s2 hs2 => by rw [hFin s2 hs2]; exact (hF σ).2.choose_spec.2.1) + (fun s2 hs2 => by rw [hFin s2 hs2]; exact (hF σ).2.choose_spec.1) + (fun s2 σ2 G2 hs2 _ => by rw [hFin s2 hs2]; exact (hF σ2).2.choose_spec.2.2.2.2) + have hs23 : s2 = s3 := hFin s2 hs2 + subst hs23 + have hl : (((List.range' first.val count.val).map fun i => + ((specPtr dest : Fl4SpecA64.ObjRef), Fl4SpecA64.natToCref radix.val i)).length) = count.val := by simp + refine ⟨x, ⟨cte, specPtr fp + offset.bv, vmRightsOfA vm, (List.range' first.val count.val).map fun i => + (specPtr dest, Fl4SpecA64.natToCref radix.val i)⟩, σ2, G2, ha3, hk', hset, hD, ?_, J3, hbk⟩ + unfold Fl4SpecA64.performDeriveSubframe + dsimp only + rw [hl, List.range_eq_range'] + exact hm + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsA.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsA.lean index 73fda6d7b..718f5c844 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsA.lean @@ -600,6 +600,7 @@ theorem JSyscallA.ptUnmapS1A (hpS : ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr) (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) (hcov : SlotCov st OS s (cslotAddrA cte)) @@ -624,7 +625,7 @@ theorem JSyscallA.ptUnmapS1A 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.ptUnmapS1A (ar := ar) (nA := hPl.ipa) (J := J.toJStage3A) (RS := RS) (K := K) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (hK := hK) (hT := hT) (length := length) (buf := buf) (ex := ex) (cte := cte) (hab := hab) (ptr := ptr) (asid := asid) (va := va) (hpS := hpS) (hcap := hcap) (hf := hf) (hS1 := hS1) + refine JStage3A.ptUnmapS1A (ar := ar) (nA := hPl.ipa) (J := J.toJStage3A) (RS := RS) (K := K) (hnvm := hnvm) (hTO := hTO) (hEO := hEO) (hK := hK) (hT := hT) (length := length) (buf := buf) (ex := ex) (cte := cte) (hab := hab) (ptr := ptr) (asid := asid) (va := va) (hpS := hpS) (hcap := hcap) (hf := hf) (hno := hno) (hS1 := hS1) (fin := fun _ _ σ3 _ _ hd _ => 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) @@ -672,6 +673,7 @@ theorem JSyscallA.ptUnmapXA (hpS : ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr) (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (hno : ∀ y ∈ OS, y ≠ cslotAddrA cte → ∀ (mp : Bool) (a0 v0 : U64), capA st s y ≠ .PageTable ptr mp a0 v0) (k : Fl4SpecA64.ExtRootKind) (hkR : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some k) (hkR1 : k ≠ .stage1) @@ -697,7 +699,7 @@ theorem JSyscallA.ptUnmapXA 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.ptUnmapXA (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) (hpS := hpS) (hcap := hcap) (hf := hf) (k := k) (hkR := hkR) (hkR1 := hkR1) + refine JStage3A.ptUnmapXA (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) (hpS := hpS) (hcap := hcap) (hf := hf) (hno := hno) (k := k) (hkR := hkR) (hkR1 := hkR1) (fin := fun _ _ σ3 _ _ hd _ => 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) diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsCnA.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsCnA.lean index 60fd47732..4e97842a9 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsCnA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsCnA.lean @@ -65,7 +65,7 @@ theorem JSyscallA.cnodeCopyA (hanc : CapEqA nc anc) (hw : CapRt.EncWf nc) (hn : nc ≠ .Null) - (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) + (hD : Fl4ProofsA64.P3.DerivA nc (capA st s (cslotAddrA ss))) (hrd : RootDerivA 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))) @@ -128,7 +128,7 @@ theorem JSyscallA.cnodeCopyA ok (core.result.Result.Ok (), s2, a) := fun s2 hs2 => by rw [(decCnode_copyA (ar := ar) (a := a) (block := false) (call := false) (donate := false) hlbl.1 hlbl.2.1 hlbl.2.2.1 hlbl.2.2.2 hl2 hl4 hi hd hres hx0 h0 h2 h3 hroot hemp hsrc (capA_eq _ _) hsn hcop hn), heq, bind_ok, if_neg Bool.false_ne_true, ← e, hs2, bind_ok] - refine JStage3A.cnodeCopyA (ar := ar) (nA := hPl.ipa) (J := J.toJStage3A) (RS := RS) (hnvm := hnvm) (ss := ss) (sd := sd) (hCs := hCs) (hCd := hCd) (hsn := hsn) (hdn := hdn) (hdc := hdc) (hwf := hwf) (hanc := hanc) (hw := hw) (hn := hn) (hD := hD) (hal := hal) (hk := hk) (hsh := hsh) (hsh1 := hsh1) (hbd1 := hbd1) (hbd := hbd) (hirq := hirq) (hz := hz) (hut := hut) (hdo := hdo) (hcv := hcv) (hsci := hsci) + refine JStage3A.cnodeCopyA (ar := ar) (nA := hPl.ipa) (J := J.toJStage3A) (RS := RS) (hnvm := hnvm) (ss := ss) (sd := sd) (hCs := hCs) (hCd := hCd) (hsn := hsn) (hdn := hdn) (hdc := hdc) (hwf := hwf) (hanc := hanc) (hw := hw) (hn := hn) (hD := hD) (hrd := hrd) (hal := hal) (hk := hk) (hsh := hsh) (hsh1 := hsh1) (hbd1 := hbd1) (hbd := hbd) (hirq := hirq) (hz := hz) (hut := hut) (hdo := hdo) (hcv := hcv) (hsci := hsci) (symL := fun s2 hs2 => (D (hdec s2 hs2) σ).choose_spec.2.1) (sysl := fun s2 hs2 => (D (hdec s2 hs2) σ).choose_spec.1) (j7 := fun _ s2 σ2 _ hs2 _ => (D (hdec s2 hs2) σ2).choose_spec.2.2.2.2) diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpu2A.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpu2A.lean index 7e71b6c62..165a14536 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpu2A.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpu2A.lean @@ -326,7 +326,7 @@ theorem JSyscallA.vcpuReadStateA {ar : machine.Arch A} private theorem vcpu_unbind_ext_stage3TA {J7 : JSlotA S} [J7PpA st J7] [J7PpKA st J7] [J7FrA st J7] (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z OS Bf s σ) + (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z H OS Bf s σ) (hP : VcpuPlatAgreeA ar) (hAK : VcpuArchKeepsA ar AR) (hVR : VcpuVmRootA st ar AR) (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) (h1 : Fl4SpecA64.fl4A64Platform.numNodes = 1) @@ -336,7 +336,7 @@ private theorem vcpu_unbind_ext_stage3TA fl4VcpuUnbindExt (specPtr vc) σ = ({((), σ')}, False) ∧ JStage3TA st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 res.1 res.2 σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st { Z with hw := hw' } OS Bf res.1 σ' ∧ + VcpuRec6A st { Z with hw := hw' } H OS Bf res.1 σ' ∧ L.mem res.1 vc = 0#u64 ∧ L.mem res.1 (wa vc 24#u64) = 0#u64 ∧ (L.mem s vc ≠ 0#u64 → L.mem res.1 (wa (L.mem s vc) 3664#u64) = 0#u64) ∧ @@ -486,9 +486,9 @@ private theorem vcpu_unbind_ext_stage3TA obtain ⟨x, hkx, -⟩ := J'.j.2.1.obj v hv exact (R6'.snap.snap v hv x hkx).2.2.2.2 have hFrTh'' : FrThA st Z.th OS s' := R6'.frTh.keepA (fun _ _ => rfl) fun _ _ e => e - have hUserFr'' : UserFrSpecA st OS s' σ'' := - R6'.userFr.keepA (fun _ _ => rfl) fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) - have hR6'' : VcpuRec6A st { Z with hw := hw' } OS Bf s' σ'' := + have hUserFr'' : UserFrSpecA st H OS s' σ'' := + R6'.userFr.keepA (fun _ _ => rfl) (fun _ _ e => e) fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) + have hR6'' : VcpuRec6A st { Z with hw := hw' } H OS Bf s' σ'' := ⟨hSnap'', R6'.vcSym1, R6'.vcSym2, R6'.vcBack, R6'.runBack, R6'.vcOS, R6'.frOff, hUserFr'', hFrTh'', R6'.bfSpec⟩ exact ⟨hw', σ'', hsp_ext, J'', hSV'', hR6'', hvc0, hrc0', hclr, hkeep0, hksb, hcpu, osk⟩ @@ -497,7 +497,7 @@ via `JStage3TA.of_vcpuStepA`. -/ private theorem vcpu_assoc_stage3TA {J7 : JSlotA S} [J7PpA st J7] [J7PpKA st J7] [J7FrA st J7] (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z OS Bf s σ) + (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z H OS Bf s σ) {vc ptr : U64} (hvc : vc ∈ Z.V) (hptr : ptr ∈ Z.T) (hvc_nz_all : ∀ v ∈ Z.V, v ≠ 0#u64) (ht_nz_all : ∀ t ∈ Z.T, t ≠ 0#u64) (hvc_live : ¬ DeadA st OS .vcpu s vc) (hptr_live : ¬ DeadA st OS .tcb s ptr) @@ -513,7 +513,7 @@ private theorem vcpu_assoc_stage3TA let s' := L.wr (L.wr s vc ptr) (wa ptr 3664#u64) vc JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf s' σ' ∧ + VcpuRec6A st Z H OS Bf s' σ' ∧ OSKeep st OS s s' := by have hvc_nz : vc ≠ 0#u64 := hvc_nz_all vc hvc have hptr_nz : ptr ≠ 0#u64 := ht_nz_all ptr hptr @@ -778,9 +778,9 @@ private theorem vcpu_assoc_stage3TA intro u hu p0 sz0 r0 mp0 ept0 a0 va0 hc0 b0 hb0 exact R6.frOff u hu p0 sz0 r0 mp0 ept0 a0 va0 ((capE u hu).symm.trans hc0) b0 hb0 have hFrTh' : FrThA st Z.th OS s' := R6.frTh.keepA capE fun _ _ e => e - have hUserFr' : UserFrSpecA st OS s' σ' := - R6.userFr.keepA capE fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) - have hR6' : VcpuRec6A st Z OS Bf s' σ' := by + have hUserFr' : UserFrSpecA st H OS s' σ' := + R6.userFr.keepA capE (fun _ _ e => e) fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) + have hR6' : VcpuRec6A st Z H OS Bf s' σ' := by refine ⟨hSnap', fun u hu hne => ?_, fun v hv hne => ?_, fun v hv hne => ?_, fun u hu hne => ?_, R6.vcOS, hFrOff', hUserFr', hFrTh', R6.bfSpec⟩ · by_cases huu : u = ptr @@ -992,7 +992,7 @@ theorem JSyscallA.vcpuSetTcbA {ar : machine.Arch A} JStage3TA st AR { Z with hw := hw_u2 } 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_u2 a_u2 σ_u2 m ∧ SchedValidA σ_u2 ∧ - VcpuRec6A st { Z with hw := hw_u2 } OS Bf s_u2 σ_u2 ∧ + VcpuRec6A st { Z with hw := hw_u2 } H OS Bf s_u2 σ_u2 ∧ L.mem s_u2 vc = 0#u64 ∧ L.mem s_u2 (wa ptr 3664#u64) = 0#u64 ∧ OSKeep st OS s_u1 s_u2 := by @@ -1079,7 +1079,7 @@ theorem JSyscallA.vcpuSetTcbA {ar : machine.Arch A} JStage3TA st AR { Z with hw := hw_r } 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_r a_r σ_r m ∧ SchedValidA σ_r ∧ - VcpuRec6A st { Z with hw := hw_r } OS Bf s_r σ_r ∧ + VcpuRec6A st { Z with hw := hw_r } H OS Bf s_r σ_r ∧ L.mem s_r vc = 0#u64 ∧ L.mem s_r (wa ptr 3664#u64) = 0#u64 ∧ L.mem s_r (runVcpuA ptr) = 0#u64 ∧ @@ -1193,7 +1193,7 @@ theorem JSyscallA.vcpuSetTcbA {ar : machine.Arch A} have hstep7 : ∃ hw_fin, JStage3TA st AR { Z with hw := hw_fin } 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 ∧ - VcpuRec6A st { Z with hw := hw_fin } OS Bf s3 σ3 ∧ + VcpuRec6A st { Z with hw := hw_fin } H OS Bf s3 σ3 ∧ OSKeep st OS s2 s3 := by have osk_2a : OSKeep st OS s2 s_a := fun u hu => ⟨by rw [(osk_a u hu).1, (osk_r u hu).1, (osk_u2 u hu).1, (osk_u1 u hu).1], @@ -2055,7 +2055,7 @@ set_option maxHeartbeats 800000 in theorem vcpu_write_state_from_frame_stage3TA {ar : machine.Arch A} {Ub : Set U64} [J7PpA st J7] [J7FrA st J7] (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z OS Bf s σ) + (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z H OS Bf s σ) (hP : VcpuPlatAgreeA ar) (hVcP : VcPlacedA Z OS Ub (L.ksb s)) (hU : UbFootDisjAtA Z OS Ub (L.ksb s)) (hCs128 : ∀ c ∈ Z.Cs, c.val < 128) (hCsN : ∀ c ∈ Z.Cs, c.val < n) @@ -2072,7 +2072,7 @@ theorem vcpu_write_state_from_frame_stage3TA {ar : machine.Arch A} {Ub : Set U64 ∃ σ', fl4WriteStateFromFrame (specPtr vc) (specPtr frame) mask.bv vgicSpec σ = ({((), σ')}, False) ∧ JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf s' σ' ∧ + VcpuRec6A st Z H OS Bf s' σ' ∧ WritesIn st s s' (WfSet vc (L.mem s vc)) ⦄ := by unfold vcpu.write_state_from_frame by_cases hm0 : mask = 0#u64 @@ -2112,7 +2112,7 @@ theorem vcpu_write_state_from_frame_stage3TA {ar : machine.Arch A} {Ub : Set U64 -- Helper: finish `WfInv` → `JStage3TA + SchedValidA + VcpuRec6A + WritesIn` have hFin : ∀ (sf : S) (σf : Fl4SpecA64.State Unit), WfInv st Z H s σ vc v_tcb sf σf → JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 sf a σf m ∧ - SchedValidA σf ∧ VcpuRec6A st Z OS Bf sf σf ∧ WritesIn st s sf (WfSet vc v_tcb) := by + SchedValidA σf ∧ VcpuRec6A st Z H OS Bf sf σf ∧ WritesIn st s sf (WfSet vc v_tcb) := by intro sf σf invf have hwf_sub : WritesIn st s sf (WfSet vc v_tcb) := invf.hw have hw_no : WritesIn st s sf (VcpuWrFootA st true Z OS s) := @@ -2274,7 +2274,7 @@ theorem vcpu_write_state_from_frame_stage3TA {ar : machine.Arch A} {Ub : Set U64 R6.vcOS, fun y hy p sz r mp ept asid va hc b hb => by rw [invf.hw.1]; exact R6.frOff y hy p sz r mp ept asid va (by rwa [← hcapE y hy]) b hb, - R6.userFr.keepA hcapE (fun _ _ _ h => invf.hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e)), + R6.userFr.keepA hcapE (fun _ _ e => e) (fun _ _ _ h => invf.hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e)), R6.frTh.keepA hcapE (fun _ _ e => e), R6.bfSpec⟩, hwf_sub⟩ @@ -3147,12 +3147,10 @@ theorem JSyscallA.vcpuWriteStateA {ar : machine.Arch A} rw [sm_vgic_ok, bind_ok, sm_vgic_lr_ok, bind_ok, lift_ok2, bind_ok, lift_ok2, bind_ok] at hdec -- Frame window properties from `J7A` (`W.cc`) set frame := wa ptr offset - have hptrH : H ptr = some (.other bits.val) := + have hptrH : FrAt H ptr bits := W.cc.fo s1 hs1_OS ptr sz rights mp ept asid va hc_s1 bits hbits - have hptrFit : ptr.val + 2 ^ bits.val ≤ 2 ^ 64 := by - have := J3.sys.ent.heap.fits ptr _ hptrH; simpa [HKind.bits] using this - have hptrAl : ptr.val % 2 ^ bits.val = 0 := by - have := J3.sys.ent.heap.align ptr _ hptrH; simpa [HKind.bits] using this + have hptrFit : ptr.val + 2 ^ bits.val ≤ 2 ^ 64 := hptrH.fits J3.sys.ent.heap + have hptrAl : ptr.val % 2 ^ bits.val = 0 := hptrH.al J3.sys.ent.heap have hbits12 : 12 ≤ bits.val := by cases sz <;> simp [capability.FrameSize.bits] at hbits <;> subst hbits <;> decide have hptr_al8 : ptr.val % 8 = 0 := by have h8 : 8 ∣ 2 ^ bits.val := ⟨2 ^ (bits.val - 3), by rw [show (8 : Nat) = 2 ^ 3 from rfl, ← Nat.pow_add]; congr 1; omega⟩ @@ -3180,8 +3178,8 @@ theorem JSyscallA.vcpuWriteStateA {ar : machine.Arch A} have hfr_disj_tcb : ∀ t ∈ Z.T, ∀ k < 128, ∀ K : U64, 256 ≤ K.val → K.val < 3328 → wa frame ⟨BitVec.ofNat 64 (8 * k)⟩ ≠ wa t K := fun t ht k hk K _ hK2 e => by have htH : H t = some .tcb := show t ∈ H.tcbs by rw [J3.tcbs]; exact ht - have hne : ptr ≠ t := fun h => by rw [h, htH] at hptrH; cases hptrH - have hd := J3.sys.ent.heap.disj ptr (.other bits.val) t .tcb hptrH htH hne + have hd : ptr.val + 2 ^ (HKind.other bits.val).bits ≤ t.val ∨ t.val + 2 ^ HKind.tcb.bits ≤ ptr.val := + (hptrH.disjK J3.sys.ent.heap htH (fun z => by simp)).symm have hft := (hU.tcb_al t ht).fits have hw1 : (wa frame ⟨BitVec.ofNat 64 (8 * k)⟩).val = frame.val + 8 * k := by rw [wa_valP] @@ -3291,8 +3289,9 @@ theorem JSyscallA.vcpuWriteStateA {ar : machine.Arch A} have hne : stA (L.curW s) ≠ wa frame ⟨BitVec.ofNat 64 (8 * k)⟩ := fun e => by rw [stA_eq_wa] at e have htH : H (L.curW s) = some .tcb := show L.curW s ∈ H.tcbs by rw [J3.tcbs]; exact J3.sr.curT - have hne_pt : ptr ≠ L.curW s := fun h => by rw [h, htH] at hptrH; cases hptrH - have hd := J3.sys.ent.heap.disj ptr (.other bits.val) (L.curW s) .tcb hptrH htH hne_pt + have hd : ptr.val + 2 ^ (HKind.other bits.val).bits ≤ (L.curW s).val ∨ + (L.curW s).val + 2 ^ HKind.tcb.bits ≤ ptr.val := + (hptrH.disjK J3.sys.ent.heap htH (fun z => by simp)).symm have hft := (hU.tcb_al _ J3.sr.curT).fits have hw1 : (wa frame ⟨BitVec.ofNat 64 (8 * k)⟩).val = frame.val + 8 * k := by rw [wa_valP] diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuRunA.lean b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuRunA.lean index 517a8a71f..3dc711d8b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuRunA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3T3ArmsVcpuRunA.lean @@ -122,13 +122,13 @@ private theorem badgeRegA_eq_256 (u : U64) : badgeRegA u = wa u 256#u64 := by /-- Step 1 of `decode_run`: write `vc + 8 := cpu + 1` (`OWNER_CPU`) on `JStage3TA` (spec unchanged). -/ theorem vcpu_set_owner_stage3TA {Ub : Set U64} [J7PpA st J7] [J7FrA st J7] (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hVcP : VcPlacedA Z OS Ub (L.ksb s)) (hcpu128 : (L.cpu s).val < 128) {vc : U64} (hvc : vc ∈ Z.V) : let s1 := L.wr s (wa vc 8#u64) (wa (L.cpu s) 1#u64) JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s1 a σ m ∧ - VcpuRec6A st Z OS Bf s1 σ ∧ + VcpuRec6A st Z H OS Bf s1 σ ∧ OSKeep st OS s s1 ∧ WritesIn st s s1 (fun b => b = wa vc 8#u64) := by intro s1 @@ -211,7 +211,7 @@ theorem vcpu_set_owner_stage3TA {Ub : Set U64} [J7PpA st J7] [J7FrA st J7] exact J.zombieNoVcpu z hz u num hc0) have hZ : ({ Z with hw := Z.hw } : XSetsA) = Z := by cases Z; rfl rwa [hZ] at h - have R6_1 : VcpuRec6A st Z OS Bf s1 σ := + have R6_1 : VcpuRec6A st Z H OS Bf s1 σ := ⟨hSnap, fun t ht hnz => by rw [ht_eq t ht 3664#u64 (by decide) (by decide)] at hnz ⊢ @@ -229,7 +229,7 @@ theorem vcpu_set_owner_stage3TA {Ub : Set U64} [J7PpA st J7] [J7FrA st J7] R6.vcOS, fun y hy p sz r mp ept asid va hc b hb => by rw [hw1.1]; exact R6.frOff y hy p sz r mp ept asid va (by rwa [← hcapE y hy]) b hb, - R6.userFr.keepA hcapE (fun _ _ _ h => h), R6.frTh.keepA hcapE (fun _ _ e => e), R6.bfSpec⟩ + R6.userFr.keepA hcapE (fun _ _ e => e) (fun _ _ _ h => h), R6.frTh.keepA hcapE (fun _ _ e => e), R6.bfSpec⟩ exact ⟨J1, R6_1, osk, hw1⟩ private theorem set_thread_state_running_vm_ipcA {ar : machine.Arch A} {nA : U64} @@ -636,7 +636,7 @@ theorem set_thread_state_running_vm_stage3A {ar : machine.Arch A} {nA : 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) (hNoSw : ∀ u, σ.schedulerAction ≠ .switchThread u) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) {ct : U64} (hct : ct ∈ Z.T) {x : Fl4SpecA64.Tcb} (hk : σ.kheap (specPtr ct) = some (.tcb x)) (hrun : runnable x.tcbState = true) @@ -649,7 +649,7 @@ theorem set_thread_state_running_vm_stage3A {ar : machine.Arch A} {nA : 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 nA)) s_vm a σ_vm m ∧ (∀ u, σ_vm.schedulerAction ≠ .switchThread u) ∧ - VcpuRec6A st Z OS Bf s_vm σ_vm ∧ + VcpuRec6A st Z H OS Bf s_vm σ_vm ∧ OSKeep st OS s s_vm := by intro s_vm σ_vm obtain ⟨Pt, Ub, Pp7, Tb7, Hr, Te, Kt, Lv7, Re, bits7, KLv, W⟩ := J7A.unp J.j7 @@ -871,7 +871,7 @@ using write commutation (`set_thread_state_running_vm_stage3A` + `JStage3A.of_vc theorem vcpu_enter_run_vm_stage3A {ar : machine.Arch A} {nA : U64} {Ub : 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) - (hNoSw : ∀ u, σ.schedulerAction ≠ .switchThread u) (R6 : VcpuRec6A st Z OS Bf s σ) + (hNoSw : ∀ u, σ.schedulerAction ≠ .switchThread u) (R6 : VcpuRec6A st Z H OS Bf s σ) (hS2R : VcpuStage2RootA st ar AR) (hVcP : VcPlacedA Z OS Ub (L.ksb s)) {vc ct v_tcb a0 a2 : U64} (hvc : vc ∈ Z.V) (hct : ct ∈ Z.T) (hvt : v_tcb ∈ Z.T) @@ -912,7 +912,7 @@ theorem vcpu_enter_run_vm_stage3A {ar : machine.Arch A} {nA : U64} {Ub : 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 nA)) res.1 res.2 σ' m ∧ (∀ u, σ'.schedulerAction ≠ .switchThread u) ∧ - VcpuRec6A st Z OS Bf res.1 σ' ∧ + VcpuRec6A st Z H OS Bf res.1 σ' ∧ OSKeep st OS s res.1 ∧ L.ksb res.1 = L.ksb s ∧ L.mem res.1 (stA ct) = sched.TS_RUNNING_VM ∧ @@ -1298,12 +1298,12 @@ theorem vcpu_enter_run_vm_stage3A {ar : machine.Arch A} {nA : U64} {Ub : Set U64 by_cases hvv : v = vc · subst hvv; rw [updKSc_same] at hkv; cases hkv; exact hout_ok · rw [updKSc_other _ (fun e => hvv (specPtr_inj e))] at hkv; exact R6_vm.snap.mask v hv xv hkv - have R6_10 : VcpuRec6A st Z OS Bf s10 σ10 := by + have R6_10 : VcpuRec6A st Z H OS Bf s10 σ10 := by refine ⟨hSnap10, fun t ht hnz => ?_, fun v hv hnz => ?_, fun v hv hnz => ?_, fun t ht hnz => ?_, R6_vm.vcOS, fun y hy p sz r mp ept asid va hc b hb => by rw [hw_vm_10.1]; exact R6_vm.frOff y hy p sz r mp ept asid va (by rwa [← hcapE_10 y hy]) b hb, - R6_vm.userFr.keepA hcapE_10 (fun _ _ _ h => hHS_vm_10.keepObj h (fun _ e => by cases e) (fun _ e => by cases e)), + R6_vm.userFr.keepA hcapE_10 (fun _ _ e => e) (fun _ _ _ h => hHS_vm_10.keepObj h (fun _ e => by cases e) (fun _ e => by cases e)), R6_vm.frTh.keepA hcapE_10 (fun _ _ e => e), R6_vm.bfSpec⟩ · have ht3664 : L.mem s10 (wa t 3664#u64) = L.mem s_vm (wa t 3664#u64) := @@ -1937,7 +1937,7 @@ theorem ntfn_set_idle_stage3A {ar : machine.Arch A} {nA : U64} {Ub : 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) (hNoSw : ∀ u, σ.schedulerAction ≠ .switchThread u) - (_R6 : VcpuRec6A st Z OS Bf s σ) + (_R6 : VcpuRec6A st Z H OS Bf s σ) (_hVcP : VcPlacedA Z OS Ub (L.ksb s)) {nf : U64} (hnf : nf ∈ N) {ntfn : Notification} (hkn : σ.kheap (specPtr nf) = some (.notification ntfn)) @@ -1947,7 +1947,7 @@ theorem ntfn_set_idle_stage3A {ar : machine.Arch A} {nA : U64} {Ub : 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 nA)) s1 a σ1 m ∧ (∀ u, σ1.schedulerAction ≠ .switchThread u) ∧ - VcpuRec6A st Z OS Bf s1 σ1 ∧ + VcpuRec6A st Z H OS Bf s1 σ1 ∧ OSKeep st OS s s1 := by intro s1 σ1 have hnfH : H nf = some .ntfn := J.utIpc.ntfn nf hnf @@ -2102,7 +2102,7 @@ theorem vcpu_check_running_vm_stage3A {ar : machine.Arch A} {nA : U64} {Ub : Set (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) (hNoSw : ∀ u, σ.schedulerAction ≠ .switchThread u) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hVcP : VcPlacedA Z OS Ub (L.ksb s)) (hP : VcpuPlatAgreeA ar) (hAK : VcpuArchKeepsA ar AR) (hVR : VcpuVmRootA st ar AR) {ct : U64} (hct : ct ∈ Z.T) @@ -2416,11 +2416,12 @@ theorem JSyscallA.vcpuRunA {ar : machine.Arch A} -- Frame window properties from `W.fu` + `J3.sys.ent.heap` have hvtT : v_tcb ∈ Z.T := (J3.vcRun.vtcb vc hvc).resolve_left hvt0 set frame := wa ptr offset - have hptrH : H ptr = some (.other (frameBitsA sz)) := by - rw [← hbits_val] - exact W.cc.fo (sbWordA ct) hsb_os ptr sz rights mapped ept asid va (by rwa [hdev] at hcap_buf) bits hbits_ok - have hptrAl : ptr.val % 2 ^ frameBitsA sz = 0 := J3.sys.ent.heap.align ptr _ hptrH - have hptrFit : ptr.val + 2 ^ frameBitsA sz ≤ 2 ^ 64 := J3.sys.ent.heap.fits ptr _ hptrH + have hptrF : FrAt H ptr bits := + W.cc.fo (sbWordA ct) hsb_os ptr sz rights mapped ept asid va (by rwa [hdev] at hcap_buf) bits hbits_ok + have hptrAl : ptr.val % 2 ^ frameBitsA sz = 0 := by + rw [← hbits_val]; exact hptrF.al J3.sys.ent.heap + have hptrFit : ptr.val + 2 ^ frameBitsA sz ≤ 2 ^ 64 := by + rw [← hbits_val]; exact hptrF.fits J3.sys.ent.heap have hfr_val : frame.val = ptr.val + offset.val := by rw [wa_valP, Nat.mod_eq_of_lt (by omega)] have hfr_fit : frame.val + 1024 ≤ 2 ^ 64 := by omega @@ -2445,15 +2446,16 @@ theorem JSyscallA.vcpuRunA {ar : machine.Arch A} have hfr_dt : ∀ t ∈ Z.T, ∀ k < 128, ∀ K : U64, K.val < 4096 → wa frame ⟨BitVec.ofNat 64 (8 * k)⟩ ≠ wa t K := fun t ht k hk K hK e => by have htH : t ∈ H.tcbs := J3.tcbs ▸ ht change H t = some .tcb at htH - have hne_pt : ptr ≠ t := fun h => by rw [h, htH] at hptrH; cases hptrH - have hd := J3.sys.ent.heap.disj ptr _ t .tcb hptrH htH hne_pt + have hd0 := hptrF.disjK J3.sys.ent.heap htH (fun z => by simp) have hft := (hU.tcb_al t ht).fits have hv1 : (wa frame ⟨BitVec.ofNat 64 (8 * k)⟩).val = frame.val + 8 * k := by rw [wa_valP]; change (frame.val + (BitVec.ofNat 64 (8 * k)).toNat) % 2 ^ 64 = _ rw [BitVec.toNat_ofNat, Nat.mod_eq_of_lt (by omega), Nat.mod_eq_of_lt (by omega)] have hv2 : (wa t K).val = t.val + K.val := by rw [wa_valP, Nat.mod_eq_of_lt (by omega)] have hv := congrArg UScalar.val e; rw [hv1, hv2] at hv - change ptr.val + 2 ^ frameBitsA sz ≤ t.val ∨ t.val + 4096 ≤ ptr.val at hd; omega + rw [hbits_val] at hd0 + have hd : ptr.val + 2 ^ frameBitsA sz ≤ t.val ∨ t.val + 4096 ≤ ptr.val := hd0.symm + omega -- Bind `num_lrs`, `vcpu_gic_version`, VGIC masks rw [lift_okR, bind_ok, vcpu_num_lrs_eqA hP a, bind_ok] at hdec obtain ⟨g, hg_eq, hgv⟩ := hP.gic a @@ -2818,7 +2820,7 @@ theorem JSyscallA.vcpuRunA {ar : machine.Arch A} have hJ3_a3 : JStage3TA 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 a3' σ m := { J3.toTA J.sact J.noSwitch with j := ⟨{ J3.j.1 with ar := hAR3' }, J3.j.2⟩ } - have R6_0 : VcpuRec6A st Z OS Bf s σ := J3.vcpuRec6A + have R6_0 : VcpuRec6A st Z H OS Bf s σ := J3.vcpuRec6A obtain ⟨J_ow, R6_ow, osk_ow, hw_ow⟩ := vcpu_set_owner_stage3TA hJ3_a3 R6_0 hpl hcpu128 hvc set s_ow := L.wr s (wa vc 8#u64) (wa (L.cpu s) 1#u64) have hksb_ow : L.ksb s_ow = L.ksb s := hw_ow.1 diff --git a/proofs/Fl4ProofsA64/P3/Stage3T3PoolA.lean b/proofs/Fl4ProofsA64/P3/Stage3T3PoolA.lean new file mode 100644 index 000000000..335705d01 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3T3PoolA.lean @@ -0,0 +1,103 @@ +/- +P3 (aarch64, Stage 5, line pool, D2): **the T3 wrapper of `ARMASIDControlMakePool`** at a syscall entry +(`Stage3ArmPoolA`'s `JStage3A.asidMakePoolA` on a `JSyscallA`). The entry's `RS`, `DecPre`, `SysPlace` come from the record +as in `untypedRetypeRstA` (the parent untyped is the first extra cap, the invoked slot holds the ASID control cap); +`othT`/`othC` are [S] one core. Output: the restart and perform of the spec, the decode run, `BodyKeepA`, and the whole record +at the grown sets over the dropped view `dropMA D m`. + +Named premises: those of `asidMakePoolA` ([W] decode-site facts), [S] one core (`h1`, `hnN`) and [P] `hCs`. `hT` (`JStage3A.offAsE`), `hYAs` (`JStage3A.yNotAsW`) and `hcO` (`OSOK.canon`) are derived from the record, not premises. New module. +-/ +import Fl4ProofsA64.P3.Stage3ArmPoolA +import Fl4ProofsA64.P3.Stage3T3ArmsA +import Fl4ProofsA64.P3.Stage3OffAsEA +import Fl4ProofsA64.P3.Stage3DelInA + +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} + +theorem exAtA0_memA (ex : Aeneas.Std.Array obj.Slot 3#usize) : exAtA ex 0 ∈ ex.val := by + unfold exAtA + have h : 0 < ex.val.length := by rw [ex.property]; decide + rw [List.getD_eq_getElem _ _ h] + exact List.getElem_mem h + +set_option maxHeartbeats 8000000 in +/-- **MakePool at a syscall entry** (module docstring). -/ +theorem JSyscallA.asidMakePoolA {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} {ar : machine.Arch A} + (hPl : ArchPlat ar) [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] + (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) + -- [S] one core (`h1`); [P] `hCs` + (h1 : Fl4SpecA64.fl4A64Platform.numNodes = 1) (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) + (hn : hPl.ipa.val = fl4A64Platform.s2IpaBits) (hnvm : L.mem s (stA (L.curW s)) ≠ sched.TS_RUNNING_VM) + (cte : CslotPtr) (hab : AbsSlotA Z.th cte) (hcteC : capA st s (cslotAddrA cte) = .AsidControl) + (hcov : SlotCov st OS s (cslotAddrA cte)) {ex : Aeneas.Std.Array obj.Slot 3#usize} + (hext : ∀ x ∈ ex.val, x ≠ 0#u64 → x ∈ OS) (hSC : ∀ x ∈ ex.val, x ≠ 0#u64 → SlotCov st OS s x) + {parent dest : CslotPtr} {frame fi i base : U64} (hAp : AbsSlotA Z.th parent) (hAd : AbsSlotA Z.th dest) + (hdc : ∃ y ∈ OS, ∃ q r gs g : U64, capA st s y = .CNode q r gs g ∧ dest.1 = specPtr q) + (hCp : ∃ pp, parent.1 = specPtr pp ∧ Z.th pp = some (.cnode parent.2.length)) + (hCd : ∃ pd, dest.1 = specPtr pd ∧ Z.th pd = some (.cnode dest.2.length)) (hdr : dest.2.length ≠ 0) + (length buf : U64) (block call cd fp : Bool) + (hx0 : exAtA ex 0 ≠ 0#u64) (hx1 : exAtA ex 1 ≠ 0#u64) (hlen2 : length ≥ 2#u64) {a0 a1 : U64} + (ha0 : msg.syscall_arg st s (L.curW s) buf 0#u64 = ok a0) (ha1 : msg.syscall_arg st s (L.curW s) buf 1#u64 = ok a1) + (hpa : cslotAddrA parent = exAtA ex 0) (hcp : capA st s (cslotAddrA parent) = .Untyped frame 12#u64 fi false) + (hnc : cdt.ensure_no_children st s (cslotAddrA parent) = ok (core.result.Result.Ok ())) + (hiOk : vspace.decode_loop0 st s 0#u64 = ok i) (hi : i.val < 128) (hfree : L.mem s (atAF (L.ksb s) i) = 0#u64) + (hbaseOk : (i <<< vspace.ASID_LOW_BITS : Result U64) = ok base) (hbase : base.val = i.val * 512) + (hlt : cspace.lookup_slot_for_cnode_op st s false (capA st s (exAtA ex 1)) a0 a1 = + ok (core.result.Result.Ok (cslotAddrA dest))) + (hcd : capA st s (cslotAddrA dest) = .Null) : + ∃ (x : Tcb) (s3 : S) (σ3 : State Unit) (Zn : XSetsA) (Ac' : Set U64), + σ.kheap σ.curThread = some (.tcb x) ∧ + setThreadState (Z := Unit) σ.curThread .restart σ = ({((), stUpdA σ σ.curThread x .restart)}, False) ∧ + syscall.decode_invocation st ar s a fl4_abi.label.ARMASIDControlMakePool length (cslotAddrA cte) .AsidControl + block call cd fp buf ex = ok (core.result.Result.Ok (), s3, a) ∧ + (.ok ([] : List Data), σ3) ∈ ((fl4ArchPerformInvocation (Z := Unit) + (.spec (.invokeASIDControl (.makePool (specPtr frame) dest parent (asidOfA base))))).run + (stUpdA σ σ.curThread x .restart)).1 ∧ + Sched.BodyKeepA (stUpdA σ σ.curThread x .restart) σ3 ∧ + Zn = { dropZA (utDA frame 12) Z with Pp := insert frame (dropZA (utDA frame 12) Z).Pp, G := Zn.G } ∧ + JStage3A st AR Zn (PoolH (dropHA (utDA frame 12) H) frame 12) (dropSetA (utDA frame 12) OS) + (utUserA (PoolH (dropHA (utDA frame 12) H) frame 12) U) Ac' (insert frame (dropSetA (utDA frame 12) Pp)) + Tb Lv ia ie (dropSetA (utDA frame 12) N) (dropSetA (utDA frame 12) E) (dropSetA (utDA frame 12) Rp) + (dropBfA (utDA frame 12) Bf) stack κ n (J5A st) (J7A st (J7R2A st ar hPl.ipa)) s3 a σ3 + (dropMA (utDA frame 12) m) := by + have hslot : cslotAddrA cte ∈ OS := J.j5.2.1 _ (hab.isSlot J.j.1.place) + have hpar : cslotAddrA parent ∈ OS := J.j5.2.1 _ (hAp.isSlot J.j.1.place) + have RS := J.toJStage3A.rsSiteA hext hslot hcov J.actW J.running J.cur + have D0 := J.decPreA hslot hext + rw [hcteC] at D0 + have P0 := J.toJStage3A.sysPlace hext hslot hcov + have Dp := J.decPreA hpar hext + rw [hcp] at Dp + have hmem : cslotAddrA parent ∈ ex.val := hpa ▸ exAtA0_memA ex + have Pp' := J.toJStage3A.sysPlace hext hpar (hSC _ hmem (hpa ▸ hx0)) + 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 := JStage3A.asidMakePoolA J.toJStage3A RS J.toJStage3A.offAsE J.toJStage3A.yNotAsW + (fun y hy => OSOK.canon J.sys.ent.os J.toJStage3A.winOK hy) hAp hAd hdc Dp Pp' + (fun c hc hne => absurd (hone c hc) hne) (fun c hc hne => absurd (hone c hc) hne) hn hnvm hCp hCd hdr + length buf cte block call cd fp D0 P0 hSC hx0 hx1 hlen2 ha0 ha1 hpa hcp hnc hiOk hi hfree hbaseOk hbase hlt hcd + obtain ⟨res, hdec, post⟩ := spec_existsA K + obtain ⟨σ1, hst, ⟨x, hkx, eσ⟩, σ', rv, hrun, hBK, Zn, Ac', hres, hZn, -, hrec⟩ := post + have hrv := poolPerform_rvA hrun + subst hrv + rw [hres] at hdec + subst eσ + exact ⟨x, res.2.1, σ', Zn, Ac', hkx, hst, hdec, hrun, hBK, hZn, hrec⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3TA.lean b/proofs/Fl4ProofsA64/P3/Stage3TA.lean index 0f4655379..97c099a2e 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TA.lean @@ -367,7 +367,7 @@ theorem JStage3TA.toJA (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf (runBack : ∀ t ∈ Z.T, L.mem s (runVcpuA t) ≠ 0#u64 → L.mem s (core.num.U64.wrapping_add (L.mem s (runVcpuA t)) 24#u64) = t) (vcSnap : VcpuStateSnapA Z.V (L.mem s) σ) (vcOS : ∀ b, VcW Z.V b → ¬ InOS OS b) - (userFr : UserFrSpecA st OS s σ) (frTh : FrThA st Z.th OS s) (bfSpec : ∀ bp ∈ Bf, bp.2 = specPtr bp.1) : + (userFr : UserFrSpecA st H OS s σ) (frTh : FrThA st Z.th OS s) (bfSpec : ∀ bp ∈ Bf, bp.2 = specPtr bp.1) : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m where sys := ⟨J.ent, sysl⟩ j := J.j diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbBufMidA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbBufMidA.lean index ea5d7ee35..97e0c123f 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbBufMidA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbBufMidA.lean @@ -36,15 +36,11 @@ theorem bufLiveOfFrameA {H : Heap} {OS : Set U64} {s : S} (hH : HeapOK H) (h0 : (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 + have hfp : FrAt H ptr bits := hfo src hsrc ptr size rights mp ep asid va hc bits hbits + have hal : ptr.val % 2 ^ bits.val = 0 := hfp.al hH 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 + exact hfp.ne_zero h0 (UScalar.eq_of_val_eq e) 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 @@ -56,8 +52,8 @@ theorem bufLiveOfFrameA {H : Heap} {OS : Set U64} {s : S} (hH : HeapOK H) (h0 : 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 hfp : FrAt H ptr bits := hfo u hu ptr size rights x1 x2 x3 x4 hc bits hb + have := hfp.off hH 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 @@ -459,7 +455,7 @@ theorem TcbMidA.bufStepA [PlainStore st] {ct : ObjRef} {s : S} {a : A} {σ : Sta rw [e] at hx cases hx rfl - obtain ⟨s2, σ2, hs2, hm, hbk, -, J2⟩ := JStage3A.capInsertTcbBufA (J := JB) κsrc sl (ps := ps) ⟨hss1, hss2⟩ + obtain ⟨s2, σ2, hs2, hm, hbk, -, J2⟩ := JStage3A.capInsertTcbBufA (hrd := by rw [hfr]; exact RootDerivA.of_no (NoRootKindA.of_ne (fun _ _ _ h => by cases h) (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h)) (NoPtKindA.of_ne (fun _ _ _ _ h => by cases h))) (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) diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbFpuA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbFpuA.lean index 3bab6d2e9..46623b619 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbFpuA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbFpuA.lean @@ -298,7 +298,7 @@ theorem JSyscallA.writeFpuA obtain ⟨Pt, Ub, -, -, -, cc, -⟩ := J.toJStage3A.j7 have hfo := cc.fo fs hfs ptr size rights mapped stage2 asid va hfcap have key : ∀ b : U64, size.bits = ok b → 3 ≤ b.val → ptr.val % 8 = 0 := fun b hb h3 => by - have h : ptr.val % 2 ^ b.val = 0 := J.sys.ent.heap.align ptr _ (hfo b hb) + have h : ptr.val % 2 ^ b.val = 0 := (hfo b hb).al J.sys.ent.heap exact Nat.mod_eq_zero_of_dvd ((Nat.pow_dvd_pow 2 h3 : 2 ^ 3 ∣ 2 ^ b.val).trans (Nat.dvd_of_mod_eq_zero h)) cases size · exact key 12#u64 rfl (by decide) diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbFpuRdA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbFpuRdA.lean index cc5e67e10..ae610f519 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbFpuRdA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbFpuRdA.lean @@ -189,7 +189,7 @@ theorem JStage3A.fpuRead_stepA have hta : TcbAddr t := J.sr.core.tcbs t ht have h12 : 12 ≤ bits.val := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp - have hH : H ptr = some (.other bits.val) := + have hH : FrAt H ptr bits := J.sys.sysl.sys.fr fs hfs ptr size rights mapped stage2 asid va hfc bits hbits obtain ⟨hfa, -, hW⟩ := frame_words J.sys.ent.heap hH h12 hoff hroom have hsrcfit : (wa t layout.tcb.FPU).val + 520 ≤ 2 ^ 64 ∧ Aligned (wa t layout.tcb.FPU) := by @@ -197,8 +197,7 @@ theorem JStage3A.fpuRead_stepA refine ⟨?_, field_aligned hta (by simp) (by simp)⟩ rw [vF]; have := hta.fits; omega have hdfit : dst.val + fl4FpuStateSize ≤ 2 ^ 64 := by - have h1 := J.sys.ent.heap.fits ptr _ hH - simp only [HKind.bits] at h1 + have h1 := hH.fits J.sys.ent.heap have : dst.val = ptr.val + offset.val := by show (wa ptr offset).val = _ rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) @@ -221,12 +220,7 @@ theorem JStage3A.fpuRead_stepA have hobj : ∀ q k, H q = some k → (∀ z, k ≠ .other z) → ∀ c : U64, q.val ≤ c.val → c.val < q.val + 2 ^ k.bits → ¬ X c := by intro q k hq hk c c1 c2 hc - have hne : q ≠ ptr := by - rintro rfl - rw [hH] at hq - cases hq - exact hk _ rfl - have := J.sys.ent.heap.disj q k ptr _ hq hH hne + have := hH.disjK J.sys.ent.heap hq hk have := inF c hc simp only [HKind.bits] at * omega @@ -381,8 +375,7 @@ theorem JStage3A.fpuRead_stepA -- the written bytes are bytes of copied words have h8 : (65#u64 : U64).val = 65 := by simp have hd : dst.val = ptr.val + offset.val := by - have h1 := J.sys.ent.heap.fits ptr _ hH - simp only [HKind.bits] at h1 + have h1 := hH.fits J.sys.ent.heap show (wa ptr offset).val = _ rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) have e' : (bufW bp.1 k).bv + BitVec.ofNat 64 j = dst.bv + BitVec.ofNat 64 i := by @@ -396,8 +389,7 @@ theorem JStage3A.fpuRead_stepA rw [BitVec.toNat_add, BitVec.toNat_add, BitVec.toNat_ofNat, BitVec.toNat_ofNat] at en change ((bufW bp.1 k).val + j % 2 ^ 64) % 2 ^ 64 = (dst.val + i % 2 ^ 64) % 2 ^ 64 at en have hub : (bufW bp.1 k).val < 2 ^ 64 := (bufW bp.1 k).hBounds - have hfit := J.sys.ent.heap.fits ptr _ hH - simp only [HKind.bits] at hfit + have hfit := hH.fits J.sys.ent.heap rw [Nat.mod_eq_of_lt (show j < 2 ^ 64 by omega), Nat.mod_eq_of_lt (show i < 2 ^ 64 by omega), Nat.mod_eq_of_lt (show (bufW bp.1 k).val + j < 2 ^ 64 by omega), Nat.mod_eq_of_lt (show dst.val + i < 2 ^ 64 by omega)] at en @@ -542,8 +534,7 @@ theorem JStage3A.fpuRead_stepA by_contra h exact hne (hum x h) obtain ⟨k, hk, e⟩ := hb - have hfit := J.sys.ent.heap.fits ptr _ hH - simp only [HKind.bits] at hfit + have hfit := hH.fits J.sys.ent.heap have hd : dst.val = ptr.val + offset.val := by show (wa ptr offset).val = _ rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) @@ -558,7 +549,8 @@ theorem JStage3A.fpuRead_stepA change (dst.val + k % 2 ^ 64) % 2 ^ 64 = _ rw [Nat.mod_eq_of_lt (show k < 2 ^ 64 by omega), Nat.mod_eq_of_lt (by omega)] obtain ⟨u, hu, q, b, fi, d, hc, -, f1, f2⟩ := hf - have hO := J.objAlloc ptr (2 ^ bits.val) (Or.inr (Or.inr (Or.inr ⟨_, hH, by simp [HKind.bits]⟩))) u hu q b fi d hc + obtain ⟨b0, k0, hb0, hbk0, g1, g2⟩ := hH.obj + have hO := J.objAlloc b0 (2 ^ k0) (Or.inr (Or.inr (Or.inr ⟨_, hb0, by simp [HKind.bits]⟩))) u hu q b fi d hc 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⟩ @@ -612,14 +604,13 @@ theorem JSyscallA.readFpuA have hbytes : fpuFrameBytesPubA size = 2 ^ bits.val := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> rfl have hroom' : offset.val + 520 ≤ 2 ^ bits.val := hbytes ▸ hroom - have hH : H ptr = some (.other bits.val) := + have hH : FrAt H ptr bits := J.sys.sysl.sys.fr fs hfs ptr size rights mapped stage2 asid va hfcap bits hbits have hfc1 : capA st s1 fs = .Frame ptr size rights false mapped stage2 asid va := by rw [osk1.capA hfs]; exact hfcap obtain ⟨hfa, -, -⟩ := frame_words J.sys.ent.heap hH h12 halign hroom' have hpa : ptr.val % 8 = 0 := by - have h := J.sys.ent.heap.align ptr _ hH - simp only [HKind.bits] at h + have h := hH.al J.sys.ent.heap exact Nat.mod_eq_zero_of_dvd ((Nat.pow_dvd_pow 2 (by omega : 3 ≤ bits.val) : 2 ^ 3 ∣ 2 ^ bits.val).trans (Nat.dvd_of_mod_eq_zero h)) have hfr : (specPtr (wa ptr offset)).toNat % 8 = 0 := by @@ -643,8 +634,7 @@ theorem JSyscallA.readFpuA (by simp only [↓reduceIte] exact ⟨hfa, by - have h1' := J.sys.ent.heap.fits ptr _ hH - simp only [HKind.bits] at h1' + have h1' := hH.fits J.sys.ent.heap have : (wa ptr offset).val = ptr.val + offset.val := by rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) have e : fl4FpuStateSize = 520 := by decide omega⟩) diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbInstallA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbInstallA.lean index 3f5118e61..0467e58b0 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbInstallA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbInstallA.lean @@ -32,6 +32,7 @@ structure TcbInsKA (H : Heap) (th : TypedHeapA) (m : McState) (n i : Nat) (nc c0 kind : TcbK nc same : objects.same_object_as nc c0 = ok true hD : Fl4ProofsA64.P3.DerivA nc c0 + hrd : RootDerivA nc c0 hal : UA nc c0 hk : SameBadgeKindA nc c0 hsh : Fl4ProofsA64.P3.shapeA nc = Fl4ProofsA64.P3.shapeA c0 @@ -85,15 +86,23 @@ theorem tcbNoIdle_absA {c : capability.Cap} (hk : TcbK c) (m : McState) (n : Nat 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] +/-- A successful `derive_cap` result is root-derived (P1 `objects.derive_cap.rt`). -/ +theorem rootDerivA_of_derive {S : Type} {st : machine.Store S} [L : LawfulStore st] {s : S} {slot : U64} + {c nc : capability.Cap} (h : objects.derive_cap st s slot c = ok (.Ok nc)) : RootDerivA nc c := by + have := objects.derive_cap.rt (st := st) s slot c + rw [h, WP.spec_ok] at this + exact RootDerivA.of_p1 (this nc rfl) + /-- **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 + (hrd : RootDerivA c 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 _ + hrd := hrd hal := UA.refl _ hk := by cases c <;> trivial hsh := rfl @@ -120,7 +129,7 @@ theorem tcbInsKA_cnodeA {H : Heap} {th : TypedHeapA} {m : McState} {n i : Nat} { 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 := ?_, + { kind := hk, same := by simp [objects.same_object_as, objects.same_region_as], hD := .cnode .., hrd := RootDerivA.of_no (NoRootKindA.of_ne (fun _ _ _ h => by cases h) (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h)) (NoPtKindA.of_ne (fun _ _ _ _ h => by cases h)), 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) @@ -357,7 +366,7 @@ theorem JStage3A.installTcbCapA {s sd : S} {a ad : A} {σ σd : State Unit} 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) + obtain ⟨s2, σ2, hs2, hm, hbk, -, J2, HS, w, ek0, ed, hfull⟩ := JStage3A.capInsertTcbSlotGA (hrd := by rw [hS']; exact k.hrd) (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) diff --git a/proofs/Fl4ProofsA64/P3/Stage3TcbSuspendArmA.lean b/proofs/Fl4ProofsA64/P3/Stage3TcbSuspendArmA.lean index 2ba737fd1..43a44a779 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3TcbSuspendArmA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3TcbSuspendArmA.lean @@ -102,7 +102,7 @@ theorem JSyscallA.suspendMidA have JT := J1.toTA sact noSw 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)) s1 a σ1 m := { JT with j7 := J7A.toLA JT.j7 } - have R6 : VcpuRec6A st Z OS Bf s1 σ1 := + have R6 : VcpuRec6A st Z H OS Bf s1 σ1 := ⟨J1.vcSnap, J1.vcSym1, J1.vcSym2, J1.vcBack, J1.runBack, J1.vcOS, J1.sys.sysl.fo, J1.userFr, J1.frTh, J1.bfSpec⟩ -- the target is no core's idle thread have hcap1 : capA st s1 slot = .Thread t := (osk0.capA hslot).trans hcap diff --git a/proofs/Fl4ProofsA64/P3/Stage3UtBigArmA.lean b/proofs/Fl4ProofsA64/P3/Stage3UtBigArmA.lean new file mode 100644 index 000000000..56399f4ff --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3UtBigArmA.lean @@ -0,0 +1,134 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line prst, Part B): **the Retype arm whose reset runs the chunk loop to completion**, at +the syscall-entry record. + +* **`JSyscallA.untypedRetypeRstBigA`**: the untyped has no CDT child, is used and at least 64 KiB, and `reset_untyped` + from the restarted state returns `Ok` (case hypotheses). Then the decode returns `Ok`, the spec's + `fl4InvokeUntypedA64` of the decoded invocation has the outcome `σ'`, the current thread word is kept and `A64RelS3` + holds at the grown view. The body facts survive the clock ticks: `DelBudA` through each passed preemption point. + +Named premises: [P] `ArchTotal`, `ArchPlat`, `A64FrameMasks`, `hvi`/`hvirt`, `hfan`, `hVP`, `hKt`/`hK0`, +`resetChunkBits = 16`, the post-reset barriers, `DelPlatA`, `Clock` and `CounterStepA` at entry; [S] one core; +[J] `JSyscallA`. New theorems only. +-/ +import Fl4ProofsA64.P3.UtBigDecA +import Fl4ProofsA64.P3.UtPreExitA +import Fl4ProofsA64.P3.Stage3UtArmA +import Fl4ProofsA64.P3.Stage3DelAsmA + +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 + +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 4000000 in +/-- **The Retype arm with a completed chunk loop** (module docstring). -/ +theorem JSyscallA.untypedRetypeRstBigA {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 + (hnN : n ≤ Fl4SpecA64.fl4A64Platform.numNodes) + (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) + -- [P] the preemption point's platform and entry clock, the chunk size, the post-reset barriers + {Clock : A → MachineState → Prop} (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCnt : CounterStepA σ) (hchunk : resetChunkBits = 16) + (hPost : ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + -- the case: a used untyped of at least a chunk, and the reset completes + (hfi : fi ≠ 0#u64) (hbig : 16 ≤ sb.val) {s3 : S} {a3 : A} + (hres : untyped.reset_untyped st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) = + ok (core.result.Result.Ok (), s3, a3)) : + ∃ (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 Pl := 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⟩ := P.s2Ipa a + 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 h1 := P.numNodes1 + 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_recResetBigA hA J sl hsrc D Pl 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 + P.numDomains1 P.now P.counter P.rawNow (fun s a h => P.arStamp s a _ h) + (fun a σ h hc => P.irqPending a σ _ h hc) P.minBudget P.minAgree P.del.clockFr hCl hCnt hfi hbig hres 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, hok, σ3, hm, ⟨a4, T, Kp, Bud⟩, σ', 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 _ _) + obtain ⟨PP, -⟩ := utPre_exitA J hkT Kp T (McGrowA.refl m) + have B3 : Sched.BodyOKA σ3 m := + { validTime := T.valid, budget := fun y n hk hg' _ => Bud y n hk hg', ctAct := PP.ctAct, sw := PP.sw, + scNotIdle := PP.scNotIdle, owner := PP.owner } + have hns : ∀ u, σ3.schedulerAction ≠ .switchThread u := fun u h => by + rw [Kp.act] at h + exact J.noSwitch u h + have B := Sched.BodyOKA.ofGrow hg (Sched.BodyOKA.utKeepCur B3 kp.cur hns T.cur.sc + (let ⟨t, ht, _⟩ := T.cur.tcb; ⟨t, ht⟩)) + have hcur : σ'.curThread = σ.curThread := kp.cur.glob.cur.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/Stage3UtPreArmA.lean b/proofs/Fl4ProofsA64/P3/Stage3UtPreArmA.lean new file mode 100644 index 000000000..f05fbbcee --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/Stage3UtPreArmA.lean @@ -0,0 +1,119 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line prst): **the Retype arm whose reset is preempted**, at the syscall-entry record. + +* **`JSyscallA.untypedRetypeRstPreA`**: the untyped has no CDT child and `reset_untyped`, from the restarted state, + returns `Preempted` (a case hypothesis on the run). Then `syscall.decode_invocation` returns `Preempted`, the spec's + `fl4InvokeUntypedA64` of the decoded invocation has a preempted outcome `σ'`, the current thread word is kept, + `A64RelPS3` holds (at the view with the dead threads dropped, `dropMA`), the clock relation holds and `PreExitA σ'`. + +Named premises: [P] `ArchTotal`, `ArchPlat`, `A64FrameMasks`, the virtualization word (`hvi`/`hvirt`), +`retypeFanOutLimit = 256` (`hfan`), `resetChunkBits = 16` (`hchunk`), the post-reset barriers (`hPost`), the platform +facts of the preemption point (`DelPlatA`), `Clock` and `CounterStepA` at entry; [S] one core (`hnN`, `hCs`); +[J] `JSyscallA`. New theorems only. +-/ +import Fl4ProofsA64.P3.UtPreDecA +import Fl4ProofsA64.P3.UtPreExitA +import Fl4ProofsA64.P3.Stage3UtArmA +import Fl4ProofsA64.P3.Stage3DelAsmA + +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 + +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 4000000 in +/-- **The Retype arm whose reset is preempted** (module docstring). -/ +theorem JSyscallA.untypedRetypeRstPreA {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)) + -- [S] one core + (hnN : n ≤ Fl4SpecA64.fl4A64Platform.numNodes) + (hCs : ∀ c ∈ Z.Cs, c.val < Fl4SpecA64.fl4A64Platform.numNodes) + -- [P] the preemption point's platform, the chunk size, the post-reset barriers + {Clock : A → MachineState → Prop} (P : DelPlatA st ar AR Clock) (hCl : Clock a σ.machineState) + (hCnt : CounterStepA σ) (hchunk : resetChunkBits = 16) + (hPost : fi ≠ 0#u64 → ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + -- the case: the reset is preempted + {s3 : S} {a3 : A} + (hres : untyped.reset_untyped st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) = + ok (core.result.Result.Err .Preempted, s3, a3)) : + ∃ (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.Err .Preempted, s', a') ∧ + (∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + (.error (), σ') ∈ ((fl4InvokeUntypedA64 (Z := Unit) inv).run (stUpdA σ σ.curThread xT .restart)).1) ∧ + L.curW s' = L.curW s ∧ A64RelPS3 st AR ar hPl.ipa n Z.Cs s' a' σ' m ∧ Clock a' σ'.machineState ∧ + PreExitA σ' := 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 Pl := 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⟩ := P.s2Ipa a + 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 h1 := P.numNodes1 + 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_recResetPreA hA J sl hsrc D Pl 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) hn hPost + hchunk P.numDomains1 P.now P.counter P.rawNow (fun s a h => P.arStamp s a _ h) + (fun a σ h hc => P.irqPending a σ _ h hc) P.minBudget P.del.clockFr hCl hCnt hres + 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 ⟨hok, base, retypeBase, t, us, slots, rfl, xT, hkT, σ3, hm, J3, T, Kp⟩ := hq + simp only at hok J3 T + subst hok + have hg : McGrowA m (dropMA (utDA p sb.val) m) := dropMA_growA _ m + obtain ⟨B, PE⟩ := utPre_exitA J hkT Kp T hg + have hcur : σ3.curThread = σ.curThread := Kp.cur + refine ⟨s1, a1, σ3, ?_, ⟨xT, hkT, utInvokeA64_preempted_memA hm⟩, curW_keptA J.toJStage3A J3 hcur, + A64RelPS3.ofJg hg J3 B (by rfl), T.clk, PE⟩ + rw [hdc, hdec] + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/Stage3VcpuBridgeA.lean b/proofs/Fl4ProofsA64/P3/Stage3VcpuBridgeA.lean index ec1abd8aa..6dc07a9a5 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VcpuBridgeA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VcpuBridgeA.lean @@ -122,97 +122,14 @@ theorem JStage3A.tcbRegsRelA rw [hx0] at hkx; cases hkx exact hrel.regs r -private theorem mask_page_eqA (q ptr : U64) (k : Nat) (hk : k ≤ 39) - (hal : ptr.val % 2 ^ k = 0) (hle : ptr.val ≤ q.val) (hlt : q.val < ptr.val + 2 ^ k) : - (specPtr q &&& ~~~(@Fl4SpecA64.mask 64 k)) = specPtr ptr := by - have hk64 : k < 64 := by omega - have hpos : 0 < 2 ^ k := Nat.pow_pos (by decide) - have hlt64 : 2 ^ k < 2 ^ 64 := Nat.pow_lt_pow_right (by decide) hk64 - have e : ~~~(@Fl4SpecA64.mask 64 k) = BitVec.allOnes 64 <<< k := by - apply BitVec.eq_of_toNat_eq - unfold Fl4SpecA64.mask - rw [BitVec.toNat_not, BitVec.toNat_sub, BitVec.toNat_shiftLeft, BitVec.toNat_allOnes] - have h1 : (1 : BitVec 64).toNat = 1 := rfl - have hcast : ((1 <<< k : Nat) : BitVec 64).toNat = 2 ^ k := by - change (BitVec.ofNat 64 (1 <<< k)).toNat = 2 ^ k - rw [BitVec.toNat_ofNat, Nat.shiftLeft_eq, Nat.one_mul, Nat.mod_eq_of_lt hlt64] - rw [h1, hcast] - simp only [Nat.shiftLeft_eq] - have hge1 : 1 ≤ 2 ^ 64 := Nat.lt_trans hpos hlt64 - have hsub : (2 ^ 64 - 1 + 2 ^ k) % 2 ^ 64 = 2 ^ k - 1 := by - have hsum : 2 ^ 64 - 1 + 2 ^ k = 2 ^ 64 + (2 ^ k - 1) := by omega - rw [hsum, Nat.add_mod_left, Nat.mod_eq_of_lt (Nat.lt_of_le_of_lt (Nat.sub_le _ _) hlt64)] - have hmul : (2 ^ 64 - 1) * 2 ^ k = 2 ^ 64 * (2 ^ k - 1) + (2 ^ 64 - 2 ^ k) := by - rw [Nat.mul_sub_right_distrib, Nat.one_mul, Nat.mul_sub_left_distrib, Nat.mul_one] - have hle' : 2 ^ 64 ≤ 2 ^ 64 * 2 ^ k := Nat.le_mul_of_pos_right _ hpos - have hle2 : 2 ^ k ≤ 2 ^ 64 := Nat.le_of_lt hlt64 - omega - have hlt_rem : 2 ^ 64 - 2 ^ k < 2 ^ 64 := Nat.sub_lt (Nat.lt_trans hpos hlt64) hpos - rw [hsub, hmul, Nat.mul_add_mod, Nat.mod_eq_of_lt hlt_rem] - exact Nat.sub_sub_sub_cancel_right hpos - rw [e, ← BitVec.shiftLeft_ushiftRight] - apply BitVec.eq_of_toNat_eq - rw [BitVec.toNat_shiftLeft, BitVec.toNat_ushiftRight] - simp only [Nat.shiftLeft_eq, Nat.shiftRight_eq_div_pow] - have hqlt : (specPtr q).toNat / 2 ^ k * 2 ^ k < 2 ^ 64 := - Nat.lt_of_le_of_lt (Nat.div_mul_le_self _ _) (specPtr q).isLt - rw [Nat.mod_eq_of_lt hqlt] - have hsp_al : (specPtr ptr).toNat % 2 ^ k = 0 := (specPtr_mod ptr hk).trans hal - have hsp_ptr : (specPtr ptr).toNat = (specPtr ptr).toNat / 2 ^ k * 2 ^ k := by - have := Nat.div_add_mod (specPtr ptr).toNat (2 ^ k) - rw [Nat.mul_comm, hsp_al, Nat.add_zero] at this - exact this.symm - have hsp_lt : (specPtr ptr).toNat + 2 ^ k ≤ 2 ^ 64 := by - have h64 : 2 ^ 64 = (2 ^ 64 / 2 ^ k) * 2 ^ k := by - have hdiv := Nat.div_mul_cancel (Nat.pow_dvd_pow 2 (Nat.le_of_lt hk64)) - exact hdiv.symm - have hq_lt : (specPtr ptr).toNat / 2 ^ k < 2 ^ 64 / 2 ^ k := by - by_contra hge - have h1 : 2 ^ 64 / 2 ^ k ≤ (specPtr ptr).toNat / 2 ^ k := Nat.le_of_not_lt hge - have h2 := Nat.mul_le_mul_right (2 ^ k) h1 - rw [← h64, ← hsp_ptr] at h2 - exact Nat.not_le_of_lt (specPtr ptr).isLt h2 - have h3 := Nat.mul_le_mul_right (2 ^ k) (Nat.succ_le_of_lt hq_lt) - rw [Nat.succ_mul, ← hsp_ptr, ← h64] at h3 - exact h3 - set off : U64 := ⟨BitVec.ofNat 64 (q.val - ptr.val)⟩ - have hoff_val : off.val = q.val - ptr.val := by - change (BitVec.ofNat 64 (q.val - ptr.val)).toNat = q.val - ptr.val - rw [BitVec.toNat_ofNat, Nat.mod_eq_of_lt (by omega)] - have hq_eq : q = wa ptr off := by - apply UScalar.eq_of_val_eq - rw [wa_valP, hoff_val, Nat.add_sub_of_le hle] - exact (Nat.mod_eq_of_lt (show q.val < 2 ^ 64 from q.bv.isLt)).symm - have hsp_q : (specPtr q).toNat = (specPtr ptr).toNat + off.val := by - rw [hq_eq, specPtr_wa, BitVec.toNat_add] - change ((specPtr ptr).toNat + off.val) % 2 ^ 64 = _ - rw [Nat.mod_eq_of_lt (by omega)] - have hdiv : (specPtr q).toNat / 2 ^ k = (specPtr ptr).toNat / 2 ^ k := by - apply Nat.div_eq_of_lt_le - · rw [← hsp_ptr, hsp_q]; exact Nat.le_add_right _ _ - · rw [Nat.succ_mul, ← hsp_ptr, hsp_q]; omega - rw [hdiv, ← hsp_ptr] - /-- **`hUbUser`**: every word in `Ub` lies in a spec user data page, from `UbFr` + `UserFrSpecA`. -/ theorem JStage3A.ubUserA (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) - {Ub : Set U64} (huf : UbFr st OS Ub s) (hfo : FrameOK st H OS s) : + {Ub : Set U64} (huf : UbFr st OS Ub s) (_hfo : FrameOK st H OS s) : ∀ q ∈ Ub, inUserFrame (specPtr q) σ := by intro q hq obtain ⟨y, hy, ptr, size, rights, x1, x2, x3, x4, bits, hcap, hbits, hle, hlt⟩ := huf q hq - have hdp := J.userFr y hy ptr size rights x1 x2 x3 x4 hcap - have hfp := hfo y hy ptr size rights x1 x2 x3 x4 hcap bits hbits - have hal : ptr.val % 2 ^ bits.val = 0 := by - have h := J.sys.ent.heap.align ptr _ hfp - simpa [HKind.bits] using h - have hpb : pageBitsForSize (frameSizeOfA size) = bits.val := by - cases size <;> simp [frameSizeOfA, pageBitsForSize, capability.FrameSize.bits] at hbits ⊢ <;> - cases hbits <;> decide - have hle39 : bits.val ≤ 39 := by - cases size <;> simp [capability.FrameSize.bits] at hbits <;> cases hbits <;> decide - refine ⟨frameSizeOfA size, ?_⟩ - rw [hpb, mask_page_eqA q ptr bits.val hle39 hal hle hlt] - exact hdp + exact UserFrSpecA.inUser J.sys.ent.heap J.userFr hy hcap hbits hle hlt /-- **`VcPlacedA`** derived from `J7UnpA` + `JStage3A.vcOS` + `HeapOK` + `J5A`. -/ theorem JStage3A.vcPlacedA {ar : machine.Arch A} {nA : U64} @@ -1223,7 +1140,7 @@ theorem JStage3A.of_vcpuNonLinkWrA {ar : machine.Arch A} {nA : U64} origLive := J.origLive nullOrig := fun sl h => J.nullOrig sl (by rwa [Eq.specCap] at h) thPos := J.thPos - frBase := J.frBase.keepA Eq.capE + frBase := J.frBase.keepOS Eq.os devFr := J.devFr.keepA Eq.capE (fun p dev pg h => Eq.khNe _ _ h (fun _ e => by cases e)) finCov := J.finCov.keepA (fun q r cs h => Eq.khBack _ _ h (fun _ e => by cases e)) @@ -1282,7 +1199,7 @@ theorem JStage3A.of_vcpuNonLinkWrA {ar : machine.Arch A} {nA : U64} have hvV := (J.vcRun.run t ht).resolve_left hne; unfold runVcpuA at hvV rw [(Eq.vcLink _ hvV).2]; exact J.runBack t ht hne vcSnap := hsnap, vcOS := J.vcOS - userFr := J.userFr.keepA Eq.capE (fun p dev pg h => Eq.khNe _ _ h (fun _ e => by cases e)) + userFr := J.userFr.keepA Eq.capE (fun _ _ e => e) (fun p dev pg h => Eq.khNe _ _ h (fun _ e => by cases e)) frTh := J.frTh.keepA Eq.capE fun _ _ e => e bfSpec := J.bfSpec, curVcpuNone := J.curVcpuNone ipcSorted := IpcSortedA.of_sub J.ipcSorted @@ -1306,7 +1223,7 @@ theorem JStage3A.of_vcpuNonLinkWrA {ar : machine.Arch A} {nA : U64} /-- Project `VcpuRec6A` directly from `JStage3A`. -/ theorem JStage3A.vcpuRec6A (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) : - VcpuRec6A st Z OS Bf s σ := + VcpuRec6A st Z H OS Bf s σ := ⟨J.vcSnap, J.vcSym1, J.vcSym2, J.vcBack, J.runBack, J.vcOS, J.sys.sysl.fo, J.userFr, J.frTh, J.bfSpec⟩ /-- Generic lift from `JStage3TA` + `SchedValidA` + `VcpuRec6A` back to `JStage3A` across any VCPU @@ -1317,7 +1234,7 @@ theorem JStage3TA.toJA_vcpuA (J0 : 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) (J' : JStage3TA st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a' σ' m) (hSV' : SchedValidA σ') - (R6' : VcpuRec6A st { Z with hw := hw' } OS Bf s' σ') + (R6' : VcpuRec6A st { Z with hw := hw' } H OS Bf s' σ') (osk : OSKeep st OS s s') (sysl : SysL st H Z.Cs OS ia ie s') (symL : SymL st H Z.Cs s') : JStage3A st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a' σ' m := diff --git a/proofs/Fl4ProofsA64/P3/Stage3VcpuExitA.lean b/proofs/Fl4ProofsA64/P3/Stage3VcpuExitA.lean index b6c3f9c1b..a2ce68d04 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VcpuExitA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VcpuExitA.lean @@ -493,7 +493,7 @@ private theorem vcpu_mask_vppi_stage3A {ar : machine.Arch A} {nA : U64} · by_cases hvv : v = vc · subst hvv; rw [updKSc_same] at hkx; cases hkx; exact R6.snap.mask v hv v0 hkv0 · rw [updKSc_other _ (fun e => hvv (specPtr_inj e))] at hkx; exact R6.snap.mask v hv x hkx - have R6_1 : VcpuRec6A st Z OS Bf s1 σ1 := + have R6_1 : VcpuRec6A st Z H OS Bf s1 σ1 := { snap := hSnap vcSym1 := fun t ht hnz => by rw [ht_eq t ht 3664#u64 (by decide) (by decide)] at hnz ⊢ @@ -516,7 +516,7 @@ private theorem vcpu_mask_vppi_stage3A {ar : machine.Arch A} {nA : U64} frOff := fun y hy p sz r mp ept asid va hcap => by rw [L.ksb_wr]; exact R6.frOff y hy p sz r mp ept asid va (by rwa [osk.capA hy] at hcap) frTh := R6.frTh.keepA (fun y hy => osk.capA hy) fun _ _ e => e - userFr := R6.userFr.keepA (fun y hy => osk.capA hy) + userFr := R6.userFr.keepA (fun y hy => osk.capA hy) (fun _ _ e => e) (fun p sz _ h => by rw [updKSc_other _ (fun e => by rw [e, hkv0] at h; cases h)]; exact h) bfSpec := R6.bfSpec } have wv : WritesIn st s s1 (VW st H.tcbs Z.Cs Z.V {b | b ∈ Ub ∧ FrBw H OS b ∧ FrCw st OS s b} (L.ksb s) (fun _ => False)) := diff --git a/proofs/Fl4ProofsA64/P3/Stage3VsArmFactsA.lean b/proofs/Fl4ProofsA64/P3/Stage3VsArmFactsA.lean index 2c8e75671..2fd82490c 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VsArmFactsA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VsArmFactsA.lean @@ -140,9 +140,9 @@ theorem JSyscallA.frPlA {u fp rt asid va : U64} {sz : capability.FrameSize} {dev have hv := psA_valA sz cases dev with | false => - have hf : H fp = some (.other b.val) := W.cc.fo u hu fp sz rt mp ept asid va hcap b hb - have hal : fp.val % 2 ^ b.val = 0 := J.sys.ent.heap.align fp _ hf - obtain ⟨w1, w2⟩ := J.heapWin fp _ hf + have hf : FrAt H fp b := W.cc.fo u hu fp sz rt mp ept asid va hcap b hb + have hal : fp.val % 2 ^ b.val = 0 := hf.al J.sys.ent.heap + obtain ⟨w1, w2⟩ := hf.win J.heapWin have w2' : fp.val + 2 ^ b.val ≤ layout.PPTR_BASE.val + 2 ^ 44 := w2 have e := Fl4ProofsA64.P0.Consts.layout.PPTR_BASE.val_eq refine ⟨?_, ?_, hmz⟩ diff --git a/proofs/Fl4ProofsA64/P3/Stage3VsBodyA.lean b/proofs/Fl4ProofsA64/P3/Stage3VsBodyA.lean index d04706f7b..1a43ce62c 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VsBodyA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VsBodyA.lean @@ -140,7 +140,7 @@ theorem JSyscallA.ptUnmapBodyA [PlainStore st] (K : ArchKeepsA ar AR) (hIpa : 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 → - (∃ k, asidRootKind σ (BitVec.ofNat 16 asid.val) = some k ∧ k ≠ .stage1) ∧ + ∀ 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 => diff --git a/proofs/Fl4ProofsA64/P3/Stage3VsRunA.lean b/proofs/Fl4ProofsA64/P3/Stage3VsRunA.lean index 39b2674f8..2a34db60b 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VsRunA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VsRunA.lean @@ -96,8 +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`) - -- 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) ∧ + -- a Stage-2 table (`ptr ∈ Z.T2`) mapped on a Stage-2 / high root satisfies [J] `PtUniqT2A`; on a stale / Stage-1 + -- ASID it is the arm `ptUnmapT2Stale` (no premise: `VsUniqA.no_reach_stale`) + (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)) @@ -124,15 +125,25 @@ theorem JSyscallA.ptUnmap_runA (hlab : info.label = fl4_abi.label.ARMPageTableUn (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 + · 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) + have Stl : (asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ + asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) → + ∃ 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 false buf extra Out := fun hS1 => + J.ptUnmapT2Stale_scopeA hA hM hPl hfm Q hlab (bB := bB) (bC := bC) (bD := bD) (bF := false) (K := K) + (ptr := ptr) (asid := asid) (va := va) (hpT := hmem) + (hcap := hcap) (hf := hf) (hS1 := hS1) (hcan := hc) + rcases hk : asidRootKind σ (BitVec.ofNat 16 asid.val) with _ | k + · exact Stl (Or.inl hk) + by_cases hk1 : k = .stage1 + · exact Stl (Or.inr (by rw [hk, hk1])) 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) + (hcap := hcap) (hf := hf) (k := k) (hkR := hk) (hkR1 := hk1) (hUniq := hT2 rfl hmem k hk hk1) (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) hmem have hc : c = absCapA (capA st s slot) := by diff --git a/proofs/Fl4ProofsA64/P3/Stage3VsWriteA.lean b/proofs/Fl4ProofsA64/P3/Stage3VsWriteA.lean index 1ff54593b..839ef33c1 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VsWriteA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VsWriteA.lean @@ -507,7 +507,7 @@ theorem JStage3A.of_vsWrite {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap rw [horig] exact J.nullOrig sl (by rw [← sca sl]; exact h) thPos := fun p z h => J.thPos p z h - frBase := J.frBase.keepA capE + frBase := J.frBase.keepOS osk devFr := J.devFr.keepA capE hdp vsOk := vsOk' bufAl := fun t ht y h => J.bufAl t ht y (HS.back h (fun _ e => by cases e)) @@ -569,7 +569,7 @@ theorem JStage3A.of_vsWrite {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap · rw [← e]; exact hx · rw [hx] at e2; cases e2; exact absurd rfl (nv x)) vcOS := J.vcOS - userFr := J.userFr.keepA capE hdp + userFr := J.userFr.keepA capE (fun _ _ e => e) hdp frTh := J.frTh.keepA capE fun _ _ e => e bfSpec := J.bfSpec curVcpuNone := HS.vcur.trans J.curVcpuNone diff --git a/proofs/Fl4ProofsA64/P3/Stage3VsWriteTA.lean b/proofs/Fl4ProofsA64/P3/Stage3VsWriteTA.lean index 52fceb37b..50ddd47e4 100644 --- a/proofs/Fl4ProofsA64/P3/Stage3VsWriteTA.lean +++ b/proofs/Fl4ProofsA64/P3/Stage3VsWriteTA.lean @@ -441,7 +441,7 @@ theorem JStage3TA.of_vsWrite {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Hea rw [horig] exact J.nullOrig sl (by rw [← sca sl]; exact h) thPos := fun p z h => J.thPos p z h - frBase := J.frBase.keepA capE + frBase := J.frBase.keepOS osk devFr := J.devFr.keepA capE hdp vsOk := vsOk' bufAl := fun t ht y h => J.bufAl t ht y (HS.back h (fun _ e => by cases e)) diff --git a/proofs/Fl4ProofsA64/P3/SwapA.lean b/proofs/Fl4ProofsA64/P3/SwapA.lean index a1ca19288..6869f87b7 100644 --- a/proofs/Fl4ProofsA64/P3/SwapA.lean +++ b/proofs/Fl4ProofsA64/P3/SwapA.lean @@ -324,8 +324,10 @@ theorem cap_swap_refinesA {T Ω Sg OS : Set U64} {th : TypedHeapA} {kb : U64} (s CdtRelA st th s' σ' (swGA G (cslotAddrA sa) (cslotAddrA sb)) ∧ TreeA st OS (swGA G (cslotAddrA sa) (cslotAddrA sb)).chains (swGA G (cslotAddrA sa) (cslotAddrA sb)).par s' ∧ SpecSlotA σ σ' ∧ - ∀ y, IsSlotA th y → capAtA (L.mem s') y = capAtA (L.mem s) y ∨ capAtA (L.mem s') y = c1 ∨ - capAtA (L.mem s') y = c2 ⦄ := by + (∀ y, IsSlotA th y → capAtA (L.mem s') y = capAtA (L.mem s) y ∨ capAtA (L.mem s') y = c1 ∨ + capAtA (L.mem s') y = c2) ∧ + (capAtA (L.mem s') (cslotAddrA sa) = c2 ∧ capAtA (L.mem s') (cslotAddrA sb) = c1 ∧ + ∀ y, IsSlotA th y → y ≠ cslotAddrA sa → y ≠ cslotAddrA sb → capAtA (L.mem s') y = capAtA (L.mem s) y) ⦄ := by have hS1 := hA1.isSlot hP have hS2 := hA2.isSlot hP have hAne : cslotAddrA sa ≠ cslotAddrA sb := fun h => hne (cslotAddrA_inj hP hA1 hA2 h) @@ -359,7 +361,7 @@ theorem cap_swap_refinesA {T Ω Sg OS : Set U64} {th : TypedHeapA} {kb : U64} (s refine ⟨_, capSwap_memA h1 h2, hR2.of_kheap rfl, CdtRelA.swapA hP hC hA1 hA2 ?_ (swap_cdt_eqA _ _ _ hne) (swap_io_eqA _ _ _ hne) ?_, hT', (hQ1.trans hQ2).trans (SpecSlotA.swFin _ _ _), - fun y hy => ?_⟩ + ⟨fun y hy => ?_, e1, e2, hk'⟩⟩ · refine hT'.sub (fun y hy => hsub y hy) fun y hy hn' => ?_ have f1 : y ≠ cslotAddrA sa := fun e => hn' (e ▸ hS1) have f2 : y ≠ cslotAddrA sb := fun e => hn' (e ▸ hS2) @@ -396,7 +398,10 @@ theorem cap_swap_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} {c1 c2 : capability.Cap} {a1 a2 : Cap} (hca1 : CapRelA c1 a1) (hca2 : CapRelA c2 a2) (hw1 : CapRt.EncWf c1) (hw2 : CapRt.EncWf c2) (hc1 : c1 ≠ .Null) (hc2 : c2 ≠ .Null) (ha1 : UA c1 (capA st s (cslotAddrA sa))) (ha2 : UA c2 (capA st s (cslotAddrA sb))) - (hno1 : CapObjOkA Z c1) (hno2 : CapObjOkA Z c2) : + (hno1 : CapObjOkA Z c1) (hno2 : CapObjOkA Z c2) (hpt1 : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) c1) + (hpt2 : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) c2) + (hrk1 : KindEqA c1 (capAtA (L.mem s) (cslotAddrA sa))) + (hrk2 : KindEqA c2 (capAtA (L.mem s) (cslotAddrA sb))) : cdt.swap st s c1 (cslotAddrA sa) c2 (cslotAddrA sb) ⦃ s' => ∃ σ', ((), σ') ∈ (Fl4SpecA64.capSwap (Z := Unit) a1 sa a2 sb σ).1 ∧ JAtZAX (L := L) AR { Z with G := swGA Z.G (cslotAddrA sa) (cslotAddrA sb) } s' a σ' m ∧ @@ -418,9 +423,11 @@ theorem cap_swap_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : Heap} (cdt.swap.lrWF (osokA hO) (LR.self s) (inOS _ hG1) (inOS _ hG2) hAne hs1 hs2 hw1 hw2 (fun h => inOS _ (F.pvm _ hG1 h)) (fun h => inOS _ (F.nxm _ hG1 h)) (fun h => inOS _ (F.pvm _ hG2 h)) (fun h => inOS _ (F.nxm _ hG2 h)))) ?_ - rintro s' ⟨⟨σ', hm, hst, hcdt, hT', hSS, hcs⟩, hw', -⟩ + rintro s' ⟨⟨σ', hm, hst, hcdt, hT', hSS, hcs, hp1, hp2, hpo⟩, hw', -⟩ refine ⟨σ', hm, E.j.of_slotWrites hw' (fun b hb' hb => footN_offA E b hb hb') - (FootNA.aligned E.j.1 (bxi_nodes E.sys.ent.bxi) E.scAl E.ap.vcAl) _ hSS hst hcdt fun y hy => ?_, hT', + (FootNA.aligned E.j.1 (bxi_nodes E.sys.ent.bxi) E.scAl E.ap.vcAl) _ hSS hst hcdt (fun y hy => ?_) + (PtClosedA.ofTab (PtCapClosedA.of_swap hpt1 hpt2 hcs) + (TabClosedA.of_swapC hS1 hS2 hp1 hp2 hpo hrk1.1 hrk2.1 hrk1.2 hrk2.2)), hT', fun o1 o2 n hI => SInvXA.capSwap hI o1 o2 hm⟩ rcases hcs y hy with e | e | e <;> rw [e] · exact E.j.capObj hy @@ -468,7 +475,10 @@ theorem cap_swap_for_delete_jA {AR : A → HwRootA → Prop} {Z : XSetsA} {H : H obtain ⟨b2, hg2, hcb2⟩ := E.j.1.st.getAbsA hA2 refine WP.spec_mono (cap_swap_jA E hT hsub hnul hA1 hA2 hne hn1 hn2 hs1 hs2 hcb1 hcb2 (CapRt.decodeF_encWf _ _) (CapRt.decodeF_encWf _ _) hn1 hn2 (UA.refl _) (UA.refl _) - (E.j.capObj (AbsSlotA.isSlot hP hA1)) (E.j.capObj (AbsSlotA.isSlot hP hA2))) ?_ + (E.j.capObj (AbsSlotA.isSlot hP hA1)) (E.j.capObj (AbsSlotA.isSlot hP hA2)) + (fun _ _ _ _ _ => Or.inl ⟨cslotAddrA sa, AbsSlotA.isSlot hP hA1, rfl⟩) + (fun _ _ _ _ _ => Or.inl ⟨cslotAddrA sb, AbsSlotA.isSlot hP hA2, rfl⟩) + ⟨fun _ _ => rfl, fun _ _ => rfl⟩ ⟨fun _ _ => rfl, fun _ _ => rfl⟩) ?_ rintro s' ⟨σ', hm, hJ, hT', -⟩ have hmem : ((), σ') ∈ (Fl4SpecA64.capSwapForDelete (Z := Unit) sa sb σ).1 := by unfold Fl4SpecA64.capSwapForDelete NonDet.when diff --git a/proofs/Fl4ProofsA64/P3/TabNewA.lean b/proofs/Fl4ProofsA64/P3/TabNewA.lean index 959a351b4..467e05770 100644 --- a/proofs/Fl4ProofsA64/P3/TabNewA.lean +++ b/proofs/Fl4ProofsA64/P3/TabNewA.lean @@ -197,6 +197,7 @@ theorem pt_map_jTA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac Pp T (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) {ptr asid0 va0 : U64} {mp : Bool} (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr mp asid0 va0) + (hPC : PtCapInA Z (L.mem s)) (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (slbl : Fl4SpecA64.Data) (hl : Fl4SpecA64.invocationType slbl = .archInvocationLabel .armPageTableMap) (length buf : U64) (args : List U64) (hlen : length.val = args.length) @@ -211,7 +212,7 @@ theorem pt_map_jTA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac Pp T (.PageTable ptr mp asid0 va0) buf extra ⦃ res => PtMapJTPostA (L := L) AR Z OS m ptr σ ((Fl4SpecA64.decodePageTableInvocation (Z := Unit) slbl (args.map UScalar.bv) cte (.pageTableCap (specPtr ptr) .normalPtT (mapDataA mp asid0 va0)) exs).run σ) s a res ⦄ := - WP.spec_mono (pt_map_refinesGA ar E RS cte hab hos hcap UP slbl hl length buf args hlen + WP.spec_mono (pt_map_refinesGA ar E RS cte hab hos hcap hPC UP slbl hl length buf args hlen hargs x0 hx0 exs hex hS1 hHi) fun _ h => PtMapPostGA.liftTA hT hnul hTO ⟨hS2, hY⟩ RS.sub hcap h /-- **`hTO` of `pt_map_jTA` from `pt_map_jA`'s and the new table's facts** (`tabOff_newA`). -/ diff --git a/proofs/Fl4ProofsA64/P3/TabZeroA.lean b/proofs/Fl4ProofsA64/P3/TabZeroA.lean index acaefdd68..b1bf25130 100644 --- a/proofs/Fl4ProofsA64/P3/TabZeroA.lean +++ b/proofs/Fl4ProofsA64/P3/TabZeroA.lean @@ -284,7 +284,7 @@ theorem JAtZAX.of_zeroA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, FootA JAtZAX (L := L) AR Z (L.zr s p 4096#u64) a (ptSetA σ (specPtr p) t') m := by refine J.of_extPageA (q := p) (p0 := p) (kh := Function.update σ.kheap (specPtr p) (some (.archObj (.pageTable t')))) hfa hTO hEO ?_ (L.ksb_zr _ _ _) (L.cpu_zr _ _ _) (fun w hw hn => ?_) ?_ - (fun q hq => Function.update_of_ne hq _ _) VR ER + (fun q hq => Function.update_of_ne hq _ _) (fun j hj _ => Or.inr ?_) VR ER · rcases hp with h | h · exact Or.inr (Or.inr h) · exact Or.inl (Or.inl h) @@ -294,6 +294,10 @@ theorem JAtZAX.of_zeroA (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, FootA · rcases hp with h | h · exact Or.inr (Or.inr (Or.inr h)) · exact Or.inr (Or.inr (Or.inl h)) + · have e : L.mem (L.zr s p 4096#u64) (peAF p j) = 0#u64 := by + rw [zr_wrsA hp4 s (peAF_alignedA hp4 hj), mem_wrsA hp4 (peAF_alignedA hp4 hj) _ (fun j h => List.mem_range.1 h), + if_pos ⟨j.val, List.mem_range.2 hj, by rw [ujA_eq hj]⟩] + rw [e]; decide end diff --git a/proofs/Fl4ProofsA64/P3/TcbInvokeSlotPostA.lean b/proofs/Fl4ProofsA64/P3/TcbInvokeSlotPostA.lean index 62889a7ef..35152f58e 100644 --- a/proofs/Fl4ProofsA64/P3/TcbInvokeSlotPostA.lean +++ b/proofs/Fl4ProofsA64/P3/TcbInvokeSlotPostA.lean @@ -81,7 +81,8 @@ theorem tcbSlotInsert_afterDeleteA {AR : A → HwRootA → Prop} {Z : XSetsA} {H absCapA (capA st sDeleted (cslotAddrA src)) = .notificationCap r b rs) → b ≠ 0 → capEpBadge (absCapA nc) = b) (hdo : ¬ IrqNodeA (L.ksb sDeleted) (fl4Ptr (specPtr t)) ∨ IrqCapA (absCapA nc)) - (hcv : CapValidA Z.th (capA st sDeleted (cslotAddrA src)) → CapValidA Z.th nc) : + (hcv : CapValidA Z.th (capA st sDeleted (cslotAddrA src)) → CapValidA Z.th nc) + (hrd : RootDerivA nc (capA st sDeleted (cslotAddrA src))) : tcb.install_tcb_cap st ar s0 a0 t (cslotAddrA invoked) indexWord nc (cslotAddrA src) ⦃ r => r.1 = .Ok () ∧ r.2.2 = aDeleted ∧ ∃ σFinal, (.ok (), σFinal) ∈ ((fl4InstallTcbCap (Z := Unit) (specPtr t) invoked index @@ -95,7 +96,7 @@ theorem tcbSlotInsert_afterDeleteA {AR : A → HwRootA → Prop} {Z : XSetsA} {H (cslotAddrA (specPtr t, tcbCnodeIndex index)) nc hroot hdel] simp only [hnull, bind_ok, Bool.false_eq_true, ite_false, hcheck, ite_true] refine WP.spec_bind (cap_insert_dA E hT hsub hnul hAs hAd hsn hdn hdc hwf (CapEqA.of_abs rfl) hw hn hal hk hut - hsh hz hbd hdo hcv) ?_ + hsh hz hbd hdo hcv hrd) ?_ rintro sFinal ⟨σFinal, hinsert, hJ, htree, hinv⟩ exact (WP.spec_ok _).2 ⟨rfl, rfl, σFinal, tcbSlotInsert_specA hdelSpec hnSpec hsource hmatch hinvoked htarget hinsert, hJ, htree, hinv⟩ diff --git a/proofs/Fl4ProofsA64/P3/UnmapDecJA.lean b/proofs/Fl4ProofsA64/P3/UnmapDecJA.lean index bef698365..14a57819a 100644 --- a/proofs/Fl4ProofsA64/P3/UnmapDecJA.lean +++ b/proofs/Fl4ProofsA64/P3/UnmapDecJA.lean @@ -455,6 +455,7 @@ theorem pt_unmap_decJA {ar : machine.Arch A} (K : ArchKeepsA ar AR) {H : Heap} { (ptr asid va : U64) (hPC : PtCapInA Z (L.mem s)) (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) (hFI : FinInvA Z.th (L.mem s) σ Z.G) (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (hno : FinPtNoOtherA st Z OS s) (k : Fl4SpecA64.ExtRootKind) (hk : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some k) (hk1 : k ≠ .stage1) : (Fl4SpecA64.fl4ArchDecodeInvocation (Z := Unit) calling (Fl4SpecA64.archL .armPageTableUnmap) args xSlot cte @@ -472,7 +473,7 @@ theorem pt_unmap_decJA {ar : machine.Arch A} (K : ArchKeepsA ar AR) {H : Heap} { (([] : 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 ∧ - fa ⦃ a' => JAtZAX (L := L) AR Z s3 a' σ3 m ⦄ ∧ TreeA st OS Z.G.chains Z.G.par s3 ∧ + fa ⦃ a' => ptr ∉ Z.T2 → JAtZAX (L := L) AR Z s3 a' σ3 m ⦄ ∧ TreeA st OS Z.G.chains Z.G.par s3 ∧ (CarryA Z (L.mem s) σ → CarryA Z (L.mem s3) σ3)) := by have hcap' : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr true asid va := hcap have hp := hPC.hpA E.j.1.place hab hcap' @@ -495,7 +496,7 @@ theorem pt_unmap_decJA {ar : machine.Arch A} (K : ArchKeepsA ar AR) {H : Heap} { 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⟩ obtain ⟨x, hkx, hset, hrest⟩ := pt_unmap_jA K E RS hTO hEO (VsPgOffOSA.of_apA E.ap) hK hT hIpa length buf ex cte - hab ptr asid va (lt_of_lt_of_eq h16a (by norm_num)) hp hf hcap hEnc hca (UA.of_shapeA rfl fun h => by cases h) hok + hab ptr asid va (lt_of_lt_of_eq h16a (by norm_num)) hp hf hno hcap hEnc hca ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by cases h⟩ hok exact ⟨dec_ptUnmapA calling args xSlot cte exs _ _ _ hk hk1 hfS, x, hkx, hset, fun hTr hnul => hrest k (by rw [asidRootKind_stUpdA hkx]; exact hk) hk1 hTr hnul⟩ diff --git a/proofs/Fl4ProofsA64/P3/UnmapL4vJA.lean b/proofs/Fl4ProofsA64/P3/UnmapL4vJA.lean index ea9203f1a..94f0f76f9 100644 --- a/proofs/Fl4ProofsA64/P3/UnmapL4vJA.lean +++ b/proofs/Fl4ProofsA64/P3/UnmapL4vJA.lean @@ -85,7 +85,7 @@ theorem page_unmapU_jA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ obtain ⟨x, hkx, hst, hset, E1, -, hOK, -, -⟩ := E.restartA P RS.sym RS.run RS.cur RS.vs RS.vc refine ⟨x, hkx, hset, fun hTr hnul => ?_⟩ obtain ⟨s3, σ3, hsc, ⟨c', heq, hgc⟩, hσ3, J3, T3⟩ := setcap_coreA E RS E1.j hOK (L.ksb_wr _ _ _) (L.cpu_wr _ _ _) 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) hTr hnul + hcap hEnc hca (UA.of_shapeA rfl fun h => by cases h) hok (fun h => by cases h) (fun h => by cases h) hTr hnul (PtSrcA.nopt fun _ _ _ _ h => by cases h) obtain ⟨cCur, hcCur, hcur1, hcur2⟩ := StateRelA.curA E1.j.1.st hab have e0 : capAtA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART)) (cslotAddrA cte) = .Frame fp sz rt dev false isEpt asid va := (hOK.capA (RS.sub _ (hab.isSlot E.j.1.place))).trans hcap @@ -214,7 +214,9 @@ theorem pt_unmapU_decJA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ obtain ⟨x, hkx, hst, hset, E1, -, hOK, -, -⟩ := E.restartA P RS.sym RS.run RS.cur RS.vs RS.vc refine ⟨dec_ptUnmap_specA calling args xSlot cte exs _ none trivial hfS, x, hkx, hset, fun hTr hnul => ?_⟩ obtain ⟨s3, σ3, hsc, ⟨c', heq, hgc⟩, hσ3, J3, T3⟩ := setcap_coreA E RS E1.j hOK (L.ksb_wr _ _ _) (L.cpu_wr _ _ _) 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) hTr hnul + hcap hEnc hca ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by cases h⟩ hok (fun h => by cases h) (fun h => by cases h) hTr hnul + (PtSrcA.unmPtA (E.j.1.vsu.out _ (hab.isSlot E.j.1.place) ptr asid va hcap')) + (hpt := Or.inl (PtSetA.unm (by rw [capAtA_eq, hOK.capA (RS.sub _ (hab.isSlot E.j.1.place))]; exact hcap))) obtain ⟨cCur, hcCur, hcur1, hcur2⟩ := StateRelA.curA E1.j.1.st hab have e0 : capAtA (L.mem (L.wr s (stA (L.curW s)) sched.TS_RESTART)) (cslotAddrA cte) = .PageTable ptr false asid va := (hOK.capA (RS.sub _ (hab.isSlot E.j.1.place))).trans hcap @@ -300,7 +302,7 @@ theorem page_unmapS1_decJA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (FootA.aligned E1.j.1 hN E1.scAl E1.ap.vcAl) (fun q hq => (hTO q hq).of_ksA hks hcpu) E1.sys.ent.os hpOS hU obtain ⟨s3, σ3, hsc, ⟨_, heq, hg⟩, hσ3, J3, T3⟩ := setcap_coreA E RS J2 (hOK.trans' hk2) (hks2.trans hks) (hcpu2.trans hcpu) 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) hTr hnul + (fun h => by cases h) hTr hnul (PtSrcA.nopt fun _ _ _ _ h => by cases h) rw [← heq] at hg have hP := perfPgUnmapM_memA (R := vmRightsOfA rt) (dev := dev) hσu hg hσ3 refine ⟨s3, σ3, fa, ?_, hP, ?_, T3, fun C => C.of_setcapA E1.sys.ent.os RS.sub hTr (hOK.trans' hk2) diff --git a/proofs/Fl4ProofsA64/P3/UnmapPtS1JA.lean b/proofs/Fl4ProofsA64/P3/UnmapPtS1JA.lean index 88324a425..77a0be454 100644 --- a/proofs/Fl4ProofsA64/P3/UnmapPtS1JA.lean +++ b/proofs/Fl4ProofsA64/P3/UnmapPtS1JA.lean @@ -84,7 +84,8 @@ set_option maxHeartbeats 4000000 in `unmap_postS1JA`), `zero` (`zero_relA`, `JAtZAX.of_zeroA`) and the cap write against l4v's `perform_pt_inv_unmap` (`unmap_page_table`, the 512 `store_pte`s, the cache clean, `JAtZAX.of_msA`, the cap read, the write); `JAtZAX` at FL4's returned arch state (`ArchKeepsA.invAsid`) and the tree; the table's membership from `PtCapInA` (as -`pt_unmap_decJA`); `CarryA` kept. -/ +`pt_unmap_decJA`); `CarryA` kept. `JAtZAX` only for `ptr ∉ Z.T2` (a Stage-2 table whose ASID has no root or a +Stage-1 root would stay in `T2` behind an unmapped cap, against `VsUniqA.out`). -/ theorem pt_unmapS1_decJA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (hTO : ∀ q ∈ Z.S1, TabOffA (L := L) Z m s q) (hEO : ExtTabOffA (L := L) Z m s) @@ -95,6 +96,7 @@ theorem pt_unmapS1_decJA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (ptr asid va : U64) (hPC : PtCapInA Z (L.mem s)) (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) (hFI : FinInvA Z.th (L.mem s) σ Z.G) (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (hno : FinPtNoOtherA st Z OS s) (hS1 : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) : (Fl4SpecA64.fl4ArchDecodeInvocation (Z := Unit) calling (Fl4SpecA64.archL .armPageTableUnmap) args xSlot cte @@ -111,7 +113,7 @@ theorem pt_unmapS1_decJA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (do let a1 ← fa; ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), s3, a1)) ∧ ((), σ3) ∈ (Fl4SpecA64.performPageTableInvocation (Z := Unit) (.pageTableUnmap (.pageTableCap (specPtr ptr) .normalPtT (some (BitVec.ofNat 16 asid.val, va.bv))) cte) (stUpdA σ σ.curThread x .restart)).1 ∧ - fa ⦃ a' => JAtZAX (L := L) AR Z s3 a' σ3 m ⦄ ∧ TreeA st OS Z.G.chains Z.G.par s3 ∧ + fa ⦃ a' => ptr ∉ Z.T2 → JAtZAX (L := L) AR Z s3 a' σ3 m ⦄ ∧ TreeA st OS Z.G.chains Z.G.par s3 ∧ (CarryA Z (L.mem s) σ → CarryA Z (L.mem s3) σ3)) := by have hcap' : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr true asid va := hcap have hp := hPC.hpA E.j.1.place hab hcap' @@ -162,9 +164,16 @@ theorem pt_unmapS1_decJA {ar : machine.Arch A} (K : ArchKeepsA ar AR) (specPtr ptr + Fl4SpecA64.mask (Fl4SpecA64.ptBits .normalPtT)) (Fl4SpecA64.addrFromPPtr (specPtr ptr))) (machineOpLift_okA _) (ptSetA σu (specPtr ptr) t') have J5 := J4.of_msA (σ' := σ5) (h5m _ h5) - obtain ⟨s5, σ6, hsc, ⟨c', hc', hg⟩, hσ6, J6, T6⟩ := setcap_coreA E RS J5 ((hOK.trans' hk2).trans' hk3) (hks3.trans hks2') + obtain ⟨s5, σ6, hsc, ⟨c', hc', hg⟩, hσ6, J6, T6⟩ := setcap_coreCondA E RS J5 ((hOK.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) hTr hnul + hcap hEnc hca ⟨rfl, rfl, rfl, rfl, fun _ _ _ _ h => by cases h⟩ hok (fun h => by cases h) (fun h => by cases h) hTr hnul + (P := ptr ∉ Z.T2) (fun h => PtSrcA.unmPtA h) + (hpt := Or.inr ⟨fun r ⟨mp, a0, v0, e⟩ => by + cases e; rw [capAtA_eq, ((hOK.trans' hk2).trans' hk3).capA (RS.sub _ (hab.isSlot E.j.1.place)), hcap] + exact ⟨true, asid, va, rfl⟩, + fun r ⟨a0, v0, e⟩ y hy hne ⟨mp, a1, v1, e'⟩ => by + cases e; rw [capAtA_eq, ((hOK.trans' hk2).trans' hk3).capA (RS.sub y hy)] at e' + exact hno cte hab ptr asid va hcap hf y (RS.sub y hy) hne mp a1 v1 e'⟩) obtain ⟨asid', va', rfl, _, _⟩ := CapEqA.pt_mapped_iff.mp hc' have hP := perfPtUnmapN_memA (p := specPtr ptr) (asid := BitVec.ofNat 16 asid.val) (v := va.bv) (cte := cte) (σz := ptSetA σu (specPtr ptr) t') @@ -177,7 +186,7 @@ theorem pt_unmapS1_decJA {ar : machine.Arch A} (K : ArchKeepsA ar AR) exact then_setcapA (then_zeroA hu ptr) hsc · rcases hfa with rfl | rfl · exact (WP.spec_ok _).2 J6 - · exact WP.spec_mono (K.invAsid a _ asid J6.1.ar) fun _ h => J6.of_arA h + · exact WP.spec_mono (K.invAsid a _ asid J4.1.ar) fun _ h hn => (J6 hn).of_arA h /-- **FL4's `ARMPageUnmap` of a plain frame mapped with ASID 0**: the restart and the cap write (the unmap is @@ -254,7 +263,7 @@ theorem page_unmapZ_decJA {ar : machine.Arch A} 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 hst E1 hOK hks hcpu obtain ⟨s3, σ3, hsc, ⟨_, heq, hg⟩, hσ3, J3, T3⟩ := setcap_coreA E RS E1.j hOK hks hcpu 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) hTr hnul + (UA.of_shapeA rfl fun h => by cases h) hok (fun h => by cases h) (fun h => by cases h) hTr hnul (PtSrcA.nopt fun _ _ _ _ h => by cases h) rw [← heq] at hg have hu0 : ((), stUpdA σ σ.curThread x .restart) ∈ (Fl4SpecA64.unmapPage (Z := Unit) (frameSizeOfA sz) (BitVec.ofNat 16 (0#u64 : U64).val) va.bv (specPtr fp) (stUpdA σ σ.curThread x .restart)).1 := by diff --git a/proofs/Fl4ProofsA64/P3/UnmapS1JA.lean b/proofs/Fl4ProofsA64/P3/UnmapS1JA.lean index 100284d5d..205e24464 100644 --- a/proofs/Fl4ProofsA64/P3/UnmapS1JA.lean +++ b/proofs/Fl4ProofsA64/P3/UnmapS1JA.lean @@ -208,32 +208,60 @@ theorem JAtZAX.of_msA (J : JAtZAX (L := L) AR Z s a σ m) {σ' : Fl4SpecA64.Stat variable {H : Heap} {OS U Ac Pp Tb : Set U64} {Lv : U64 → Nat} {ia ie : Nat} +/-- An unmapped page-table cap of a table outside `T2` is a cap source. -/ +theorem PtSrcA.unmPtA {th : TypedHeapA} {S1 T2 : Set U64} {mem : U64 → U64} {p x y : U64} (h : p ∉ T2) : + PtSrcA th S1 T2 mem (.PageTable p false x y) := + fun _ _ _ _ e => by cases e; exact Or.inr (Or.inr ⟨rfl, h⟩) + set_option maxHeartbeats 1000000 in /-- **The cap write after a step that keeps the slots** (module docstring): the invoked slot's abstract cap is `getCap`'s value, and the in-place write keeps `JAtZAX` and the tree. -/ -theorem setcap_coreA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) +theorem setcap_coreCondA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) {s2 : S} {σ2 : Fl4SpecA64.State Unit} (J2 : JAtZAX (L := L) AR Z s2 a σ2 m) (hk : OSKeep st OS s s2) (hks : L.ksb s2 = L.ksb s) (hcpu : L.cpu s2 = L.cpu s) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) {c0 c : capability.Cap} {sc : Fl4SpecA64.Cap} (hcap : capA st s (cslotAddrA cte) = c0) (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) (hua : UA c c0) (hok : CapObjOkA Z c) (hcn : c ≠ .Null) (hc0 : c0 ≠ .Null) - (hT : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) : + (hT : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) + {P : Prop} (hptc : P → PtSrcA Z.th Z.S1 Z.T2 (L.mem s2) c) + (hrt : RootSetA (capAtA (L.mem s2) (cslotAddrA cte)) c := by root_nr) + (hpt : PtSetE Z.th (L.mem s2) (cslotAddrA cte) c := by pt_nr) : ∃ s3 σ3, obj.Slot.set_cap st (cslotAddrA cte) s2 c = ok s3 ∧ (∃ c', CapEqA c0 c' ∧ (c', σ2) ∈ (Fl4SpecA64.getCap (Z := Unit) cte σ2).1) ∧ ((), σ3) ∈ (Fl4SpecA64.setCap (Z := Unit) sc cte σ2).1 ∧ - JAtZAX (L := L) AR Z s3 a σ3 m ∧ TreeA st OS Z.G.chains Z.G.par s3 := by + (P → JAtZAX (L := L) AR Z s3 a σ3 m) ∧ TreeA st OS Z.G.chains Z.G.par s3 := by have hos : cslotAddrA cte ∈ OS := RS.sub _ (hab.isSlot E.j.1.place) have hN := bxi_nodes E.sys.ent.bxi have e0 : capA st s2 (cslotAddrA cte) = c0 := (hk.capA hos).trans hcap obtain ⟨c', hg, -, hc'⟩ := StateRelA.getAbsA J2.1.st hab have e1 : capAtA (L.mem s2) (cslotAddrA cte) = c0 := e0 rw [e1] at hc' - obtain ⟨s3, σ3, hsc, hσ3, -, -, J3, T3⟩ := J2.of_setcapA E.sys.ent.os RS.sub + obtain ⟨s3, σ3, hsc, hσ3, -, -, J3, T3, -⟩ := J2.of_setcapCondA E.sys.ent.os RS.sub (footNOff_ksA hks hcpu (footN_offA E)) (footNAl_ksA hks hcpu (FootNA.aligned E.j.1 hN E.scAl E.ap.vcAl)) cte hab hEnc hca (hT.keepO hk) (fun y hy hn => by rw [hk.capA hy]; exact hnul y hy hn) hcn - (by rw [e0]; exact hc0) (by rw [e0]; exact hua) hok + (by rw [e0]; exact hc0) (by rw [e0]; exact hua) hok hptc hrt hpt exact ⟨s3, σ3, hsc, ⟨c', hc', hg⟩, hσ3, J3, T3⟩ +/-- **The cap write after a step that keeps the slots** (module docstring): the invoked slot's abstract cap is +`getCap`'s value, and the in-place write keeps `JAtZAX` and the tree. -/ +theorem setcap_coreA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) + (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) {s2 : S} {σ2 : Fl4SpecA64.State Unit} + (J2 : JAtZAX (L := L) AR Z s2 a σ2 m) (hk : OSKeep st OS s s2) (hks : L.ksb s2 = L.ksb s) + (hcpu : L.cpu s2 = L.cpu s) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) {c0 c : capability.Cap} + {sc : Fl4SpecA64.Cap} (hcap : capA st s (cslotAddrA cte) = c0) (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) + (hua : UA c c0) (hok : CapObjOkA Z c) (hcn : c ≠ .Null) (hc0 : c0 ≠ .Null) + (hT : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) + (hptc : PtSrcA Z.th Z.S1 Z.T2 (L.mem s2) c) + (hrt : RootSetA (capAtA (L.mem s2) (cslotAddrA cte)) c := by root_nr) + (hpt : PtSetE Z.th (L.mem s2) (cslotAddrA cte) c := by pt_nr) : + ∃ s3 σ3, obj.Slot.set_cap st (cslotAddrA cte) s2 c = ok s3 ∧ + (∃ c', CapEqA c0 c' ∧ (c', σ2) ∈ (Fl4SpecA64.getCap (Z := Unit) cte σ2).1) ∧ + ((), σ3) ∈ (Fl4SpecA64.setCap (Z := Unit) sc cte σ2).1 ∧ + JAtZAX (L := L) AR Z s3 a σ3 m ∧ TreeA st OS Z.G.chains Z.G.par s3 := by + obtain ⟨s3, σ3, hsc, hg, hσ3, J3, T3⟩ := setcap_coreCondA E RS J2 hk hks hcpu cte hab hcap hEnc hca hua hok hcn hc0 + hT hnul (P := True) (fun _ => hptc) hrt hpt + exact ⟨s3, σ3, hsc, hg, hσ3, J3 trivial, T3⟩ + /-- **After a Stage-1 unmap** (module docstring; the Stage-1 twin of `unmap_postJA`). -/ theorem unmap_postS1JA {fl : Result A} {u : Result (S × A)} {mm : Fl4SpecA64.SMonad Unit Unit} (hmm : OutKmA mm) (J : JAtZAX (L := L) AR Z s a σ m) (hfa : ∀ w, FootA (L := L) Z s w → Aligned w) diff --git a/proofs/Fl4ProofsA64/P3/UnmapTopJA.lean b/proofs/Fl4ProofsA64/P3/UnmapTopJA.lean index 25d120b40..de1c7a373 100644 --- a/proofs/Fl4ProofsA64/P3/UnmapTopJA.lean +++ b/proofs/Fl4ProofsA64/P3/UnmapTopJA.lean @@ -155,7 +155,7 @@ theorem page_unmap_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) {H : Heap} {O (footNOff_ksA hks2 hcpu2 (footN_offA E1)) (footNAl_ksA hks2 hcpu2 (FootNA.aligned E1.j.1 hN E1.scAl E1.ap.vcAl)) cte hab hEnc hca (hTr.keepO hk12) (fun y hy hn => by rw [hk12.capA hy]; exact hnul y hy hn) (fun h => by cases h) (by rw [hk12.capA hos, hcap]; exact fun h => by cases h) (by rw [hk12.capA hos, hcap]; exact hua) - hok + hok (PtSrcA.nopt fun _ _ _ _ h => by cases h) refine (fun hP => ⟨s3, σ3, fa, ?_, hP, WP.spec_mono (hfl.arA K J3.1.ar) fun _ h => J3.of_arA h, T3, fun C => C.of_setcapA E1.sys.ent.os hsub hTr hk12 hos hEnc hsc (fun _ _ _ h => by cases h) (by show CapFinEqA _ (capA st s _); rw [hcap]; exact CapFinEqA.frameA _ _ _ _ _ _ _ _) @@ -202,6 +202,14 @@ theorem zero_postA {s2 : S} {σu : Fl4SpecA64.State Unit} (J2 : JAtZAX (L := L) exact hpOS ptr (ujA j) (by rw [ujA_val hj']; exact hj') (by rcases hp with ⟨h, -⟩ | h; exact Or.inr (Or.inr h); exact Or.inl (Or.inl h)) (e ▸ hin) +/-- **A final page-table cap has no other `PageTable` cap of its table** (`cdt::is_final_capability`, from the +finality records at the syscall site, `JSyscallA.finPtOtherA`): the premise of the unmap's unique-holder escape. -/ +def FinPtNoOtherA {S : Type} (st : machine.Store S) [LawfulStore st] (Z : XSetsA) (OS : Set U64) (s : S) : Prop := + ∀ sl : Fl4SpecA64.CslotPtr, AbsSlotA Z.th sl → ∀ ptr asid va : U64, + capA st s (cslotAddrA sl) = .PageTable ptr true asid va → + 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 + set_option maxHeartbeats 4000000 in /-- **The `ARMPageTableUnmap` top on an FL4 root** (module docstring; x86 `P3/EptTableUnmapDec`): the restart, the Ext unmap (`P3/ExtVsPerfA`'s `perform_tabUnmapXA`), the zeroing of the table (`zero_relA`, `JAtZAX.of_zeroA`) and the @@ -212,7 +220,7 @@ theorem pt_unmap_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) {H : Heap} {OS (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) (h16 : asid.val < 65536) (hp : (ptr ∈ Z.S1 ∧ 1 ≤ Z.Lv ptr) ∨ ptr ∈ Z.T2) - (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) + (hf : cdt.is_final_capability st s (cslotAddrA cte) = ok true) (hno : FinPtNoOtherA st Z OS s) (hcap : capA st s (cslotAddrA cte) = .PageTable ptr true asid va) (hEnc : CapRt.EncWf (.PageTable ptr false 0#u64 0#u64)) (hca : CapRelA (.PageTable ptr false 0#u64 0#u64) (.archObjectCap (Fl4SpecA64.updateMapData @@ -232,7 +240,7 @@ theorem pt_unmap_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) {H : Heap} {OS (([] : 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 ∧ - fa ⦃ a' => JAtZAX (L := L) AR Z s3 a' σ3 m ⦄ ∧ TreeA st OS Z.G.chains Z.G.par s3 ∧ + fa ⦃ a' => ptr ∉ Z.T2 → JAtZAX (L := L) AR Z s3 a' σ3 m ⦄ ∧ TreeA st OS Z.G.chains Z.G.par s3 ∧ (CarryA Z (L.mem s) σ → CarryA Z (L.mem s3) σ3) := by have hos : cslotAddrA cte ∈ OS := RS.sub _ (hab.isSlot E.j.1.place) obtain ⟨⟨Rp, Nt, extra, sp, P⟩, Y, hrun, hcur, hvs, hvc, hsub⟩ := RS @@ -257,12 +265,18 @@ theorem pt_unmap_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) {H : Heap} {OS have hks4 : L.ksb (L.zr s2 ptr 4096#u64) = L.ksb s1 := (L.ksb_zr _ _ _).trans hks2 have hcpu4 : L.cpu (L.zr s2 ptr 4096#u64) = L.cpu s1 := (L.cpu_zr _ _ _).trans hcpu2 have hk14 := (hOK.trans' hk2).trans' hk3 - obtain ⟨s5, σ5, hsc, hσ5, -, -, J5, T5⟩ := J4.of_setcapA hO hsub + obtain ⟨s5, σ5, hsc, hσ5, -, -, J5, T5, -⟩ := J4.of_setcapCondA (P := ptr ∉ Z.T2) hO hsub (footNOff_ksA hks4 hcpu4 (footN_offA E1)) (footNAl_ksA hks4 hcpu4 (FootNA.aligned E1.j.1 hN E1.scAl E1.ap.vcAl)) cte hab hEnc hca (hTr.keepO hk14) (fun y hy hn => by rw [hk14.capA hy]; exact hnul y hy hn) (fun h => by cases h) (by rw [hk14.capA hos, hcap]; exact fun h => by cases h) (by rw [hk14.capA hos, hcap]; exact hua) hok - refine (fun hP => ⟨s5, σ5, fa, ?_, hP, WP.spec_mono (hfl.arA K J5.1.ar) fun _ h => J5.of_arA h, T5, + (fun hn p' a' v' mp e => by cases e; exact Or.inr (Or.inr ⟨rfl, hn⟩)) + (hpt := Or.inr ⟨fun r ⟨mp, a0, v0, e⟩ => by + cases e; rw [capAtA_eq, hk14.capA hos, hcap]; exact ⟨true, asid, va, rfl⟩, + fun r ⟨a0, v0, e⟩ y hy hne ⟨mp, a1, v1, e'⟩ => by + cases e; rw [capAtA_eq, hk14.capA (hsub y hy)] at e' + exact hno cte hab ptr asid va hcap hf y (hsub y hy) hne mp a1 v1 e'⟩) + refine (fun hP => ⟨s5, σ5, fa, ?_, hP, WP.spec_mono (hfl.arA K J4.1.ar) fun _ h hn => (J5 hn).of_arA h, T5, fun C => C.of_setcapA hO hsub hTr hk14 hos hEnc hsc (fun _ _ _ h => by cases h) (by show CapFinEqA _ (capA st s _); rw [hcap]; exact CapFinEqA.ptA _ _ _ _) ((TyKeepA.stUpdA hkx _).trans (perfExtPtUnmap_tyA _ _ _ _ _ hP))⟩) ?_ diff --git a/proofs/Fl4ProofsA64/P3/UtApHeap2A.lean b/proofs/Fl4ProofsA64/P3/UtApHeap2A.lean index d9014cf02..6f5ba79b7 100644 --- a/proofs/Fl4ProofsA64/P3/UtApHeap2A.lean +++ b/proofs/Fl4ProofsA64/P3/UtApHeap2A.lean @@ -234,6 +234,8 @@ theorem utRt_heapAllA {Rj : Set U64 → JSlotA S} (w : WritesIn st s s' (UtCrtWA st H OS s nt aligned (zA nt.val us) win.val)) -- the destination slots were empty (dstNull : ∀ j < win.val, capA st s (djA dest off j) = .Null) + -- the revocable bits of the kept slots (J5 context, supplied by the assembly) + (hrevK : ∀ y ∈ OS, capA st s y = capA st s' y → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) -- the grown heap (hgrow : ∀ q k, H q = some k → H' q = some k) (hex : ∀ q k, H' q = some k → H q = some k ∨ @@ -805,6 +807,7 @@ theorem utRt_heapAllA {Rj : Set U64 → JSlotA S} asid := utRtBody_asidA hr deadT := fun u hu => ?_ deadW := Sch.vcw + revK := hrevK frSplit := ⟨fun y => ∃ j < win.val, capA st s' y = newCapA nt.val (bjA aligned (zA nt.val us) j) us false, fun y hy hk => ?_, fun y z ⟨j, _, ey⟩ ⟨l, _, ez⟩ fy kz => ?_⟩ devSplit := fun y hy q size rights mapped ept asid va h => ?_ @@ -1133,7 +1136,7 @@ theorem utRt_heapAllA {Rj : Set U64 → JSlotA S} rw [k, newCapA_ptr] have gj := bj j hj have := Nat.two_pow_pos (zA nt.val us).val - exact ⟨by omega, by omega⟩ + exact ⟨by omega, by omega, fun _ => utRt_newTopA hn hj (capA_ut_b hc) (by omega) h2 fit false⟩ · rw [k] at hk rcases hk with hk | hk · cases hk diff --git a/proofs/Fl4ProofsA64/P3/UtApHeapA.lean b/proofs/Fl4ProofsA64/P3/UtApHeapA.lean index c142893f7..6f1de3ca3 100644 --- a/proofs/Fl4ProofsA64/P3/UtApHeapA.lean +++ b/proofs/Fl4ProofsA64/P3/UtApHeapA.lean @@ -57,7 +57,8 @@ structure UtApHeapOutA (st : machine.Store S) [L : LawfulStore st] (Z Z' : XSets frSplit : ∃ New : U64 → Prop, (∀ y ∈ OS', isFrA (capA st s' y) = true ∨ RngKeyA (capA st s' y) → (∃ y0 ∈ OS, capA st s y0 = capA st s' y) ∨ - (New y ∧ p.val + fi.val ≤ (ptrA (capA st s' y)).val ∧ (ptrA (capA st s' y)).val < p.val + 2 ^ sb.val)) ∧ + (New y ∧ p.val + fi.val ≤ (ptrA (capA st s' y)).val ∧ (ptrA (capA st s' y)).val < p.val + 2 ^ sb.val ∧ + (isFrA (capA st s' y) = true → topA (capA st s' y) < p.val + 2 ^ sb.val))) ∧ ∀ y z, New y → New z → isFrA (capA st s' y) = true → ¬ RngKeyA (capA st s' z) devSplit : ∀ y ∈ OS', ∀ o size rights mapped ept asid va, capA st s' y = .Frame o size rights true mapped ept asid va → @@ -183,7 +184,8 @@ theorem utRt_heapInA · have := hk.2.1; simp [isUtA] at this · refine Or.inr ⟨⟨j, hj, k⟩, ?_⟩ rw [k, newCapA_ptr] - exact inWin j hj + obtain ⟨nfi0, hq0⟩ := cap' + exact ⟨(inWin j hj).1, (inWin j hj).2, fun _ => utRt_newTopA U.A.hn hj (capA_ut_b hq0) U.A.pa U.A.aw hfit false⟩ · rw [k] at hk rcases hk with hk | hk · cases hk diff --git a/proofs/Fl4ProofsA64/P3/UtApRec6A.lean b/proofs/Fl4ProofsA64/P3/UtApRec6A.lean index 94f6fb59b..74f3dacfc 100644 --- a/proofs/Fl4ProofsA64/P3/UtApRec6A.lean +++ b/proofs/Fl4ProofsA64/P3/UtApRec6A.lean @@ -52,14 +52,14 @@ theorem utKind_frameA {nt us b p rights x3 x4 bits : U64} {size : capability.Fra simp only [capability.FrameSize.bits] at hb <;> rw [← okinj hb] <;> simp [zA] /-- The record-edit-#6 fields of the grown record, but the VCPU snapshot. -/ -structure UtRec6OutA {S : Type} (st : machine.Store S) [L : LawfulStore st] (Z' : XSetsA) (OS' : Set U64) (s' : S) +structure UtRec6OutA {S : Type} (st : machine.Store S) [L : LawfulStore st] (Z' : XSetsA) (H' : Heap) (OS' : Set U64) (s' : S) (σ' : State Unit) : Prop where utWin : UtWinCapA st OS' s' devWin : DevWinCapA st OS' s' vcBack : ∀ v ∈ Z'.V, L.mem s' v ≠ 0#u64 → L.mem s' (wa (L.mem s' v) 3664#u64) = v runBack : ∀ t ∈ Z'.T, L.mem s' (runVcpuA t) ≠ 0#u64 → L.mem s' (wa (L.mem s' (runVcpuA t)) 24#u64) = t vcOS : ∀ b, VcW Z'.V b → ¬ InOS OS' b - userFr : UserFrSpecA st OS' s' σ' + userFr : UserFrSpecA st H' OS' s' σ' frTh : FrThA st Z'.th OS' s' section @@ -116,9 +116,11 @@ theorem utRt_rec6A (VW : nt.val = 12 → UtVcpuZW st aligned (zA nt.val us) win.val s') {t : ApiObjectType} (htt : objTypeOfA nt.val = some t) (O : UtNewObjA σ σ' (fun q => t ≠ .untyped ∧ UtNewSpA aligned (zA nt.val us) win.val q) - (utNewDA t us.val σ.curDomain)) : + (utNewDA t us.val σ.curDomain)) + {H' : Heap} (hHH' : ∀ q k, H q = some k → H' q = some k) + (hHn : ∀ j, j < win.val → ∀ k, newKind nt.val us.val = some k → H' (bjA aligned (zA nt.val us) j) = some k) : UtRec6OutA st (utRtZA Z G' nt us aligned win.val (UtOfTyA 1 nt us aligned win.val) Cn - (UtOfTyA 12 nt us aligned win.val)) (OS ∪ NewSl false nt us aligned win) s' σ' := by + (UtOfTyA 12 nt us aligned win.val)) H' (OS ∪ NewSl false nt us aligned win) s' σ' := by have Cl : UtClrA st Z H s aligned.val (aligned.val + win.val * 2 ^ (zA nt.val us).val) := utRt_winClrA J hx hc h1 h2 have footK : ∀ b : U64, FootNA (L := L) Z s b → L.mem s' b = L.mem s b := fun b h => @@ -265,14 +267,20 @@ theorem utRt_rec6A rcases caps y hy with g | ⟨j, hj, g⟩ | ⟨-, i, g⟩ | ⟨yO, g⟩ · rw [g] at hcy; cases hcy · rw [g] at hcy - obtain ⟨eq, -⟩ := newCapA_frame hn hcy + obtain ⟨eq, nk⟩ := newCapA_frame hn hcy obtain ⟨tn, d⟩ := utNewFrame_objA hn hcy htt σ.curDomain have o := O.new (specPtr q) ⟨tn, j, hj, by rw [eq]⟩ rw [utNewDA_ne tn, d] at o - exact o + obtain ⟨bits, hbits⟩ : ∃ bits, size.bits = ok bits := by cases size <;> exact ⟨_, rfl⟩ + have hpb : Fl4SpecA64.pageBitsForSize (frameSizeOfA size) = bits.val := by + cases size <;> simp [frameSizeOfA, Fl4SpecA64.pageBitsForSize, capability.FrameSize.bits] at hbits ⊢ <;> + cases hbits <;> decide + have hH : H' q = some (.other bits.val) := by rw [eq]; exact hHn j hj _ (nk bits hbits) + exact ⟨q, frameSizeOfA size, by rw [hpb]; exact hH, o, le_rfl, le_rfl⟩ · rw [g] at hcy; cases hcy · rw [g] at hcy - exact O.keep _ _ (J.userFr y yO q size rights mapped ept asid va hcy) (fun _ _ e => by cases e) + obtain ⟨b, pg, hHb, hk, h1, h2⟩ := J.userFr y yO q size rights mapped ept asid va hcy + exact ⟨b, pg, hHH' _ _ hHb, O.keep _ _ hk (fun _ _ e => by cases e), h1, h2⟩ case th => intro y hy q size rights x1 x2 x3 x4 bits hcy hb rcases caps y hy with g | ⟨j, hj, g⟩ | ⟨-, i, g⟩ | ⟨yO, g⟩ @@ -281,11 +289,13 @@ theorem utRt_rec6A obtain ⟨eq, -⟩ := newCapA_frame hn hcy obtain ⟨n0, n5, uk⟩ := utKind_frameA hn hcy hb have nw : UtNewA false nt us aligned win.val q := ⟨rfl, n0, n5, j, hj, eq⟩ + refine ⟨q, 2 ^ bits.val, ?_, le_rfl, le_rfl⟩ show utRtThA Z.th false nt us aligned win.val q = _ rw [utRtTh_newA nw, uk] · rw [g] at hcy; cases hcy · rw [g] at hcy - exact utRtTh_growA thFree (J.frTh y yO q size rights x1 x2 x3 x4 bits hcy hb) + obtain ⟨b0, len, hb0, g1, g2⟩ := J.frTh y yO q size rights x1 x2 x3 x4 bits hcy hb + exact ⟨b0, len, utRtTh_growA thFree hb0, g1, g2⟩ set_option maxHeartbeats 1000000 in /-- **`vcSnap` after the spec's `vcpu::init` step** (module docstring). -/ diff --git a/proofs/Fl4ProofsA64/P3/UtAsmAll0A.lean b/proofs/Fl4ProofsA64/P3/UtAsmAll0A.lean index 506932b7d..6d0ea5d7d 100644 --- a/proofs/Fl4ProofsA64/P3/UtAsmAll0A.lean +++ b/proofs/Fl4ProofsA64/P3/UtAsmAll0A.lean @@ -148,7 +148,7 @@ theorem utRt_asmAll0A (j5 : J5A st Z' H' OS' s' σ' m') (R5 : UtRec5OutA st Z' H' s' σ') -- the spec's `vcpu::init` step and the record-edit-#6 fields - {τ : State Unit} (Hτ : UtVcStepA σ' τ) (R6 : UtRec6OutA st Z' OS' s' σ') + {τ : State Unit} (Hτ : UtVcStepA σ' τ) (R6 : UtRec6OutA st Z' H' OS' s' σ') (vcS : VcpuStateSnapA Z'.V (L.mem s') τ) (hdom : Sched.NdOKA (st := st) s' τ) (hipi : Sched.SilentScheduleIpiA (st := st) s') (hbv : ∀ b, Endp.BufW Bf b → ¬ VsR (L.ksb s') (utVsPtA st Pp' Tb' Lv' s') b) : diff --git a/proofs/Fl4ProofsA64/P3/UtAsmAllA.lean b/proofs/Fl4ProofsA64/P3/UtAsmAllA.lean index daf1a52f6..85e9eef6e 100644 --- a/proofs/Fl4ProofsA64/P3/UtAsmAllA.lean +++ b/proofs/Fl4ProofsA64/P3/UtAsmAllA.lean @@ -53,7 +53,7 @@ theorem utRt_asmAllA (j5 : J5A st Z' H' OS' s' σ' m') (R5 : UtRec5OutA st Z' H' s' σ') -- the spec's `vcpu::init` step and the record-edit-#6 fields - {τ : State Unit} (Hτ : UtVcStepA σ' τ) (R6 : UtRec6OutA st Z' OS' s' σ') + {τ : State Unit} (Hτ : UtVcStepA σ' τ) (R6 : UtRec6OutA st Z' H' OS' s' σ') (vcS : VcpuStateSnapA Z'.V (L.mem s') τ) (hdom : Sched.NdOKA (st := st) s' τ) (hipi : Sched.SilentScheduleIpiA (st := st) s') (hbv : ∀ b, Endp.BufW Bf b → ¬ VsR (L.ksb s') (utVsPtA st Pp Tb' Lv' s') b) : diff --git a/proofs/Fl4ProofsA64/P3/UtAsmHeapA.lean b/proofs/Fl4ProofsA64/P3/UtAsmHeapA.lean index 83e59070c..087286cff 100644 --- a/proofs/Fl4ProofsA64/P3/UtAsmHeapA.lean +++ b/proofs/Fl4ProofsA64/P3/UtAsmHeapA.lean @@ -35,6 +35,8 @@ structure UtAsmHeapInA (st : machine.Store S) [L : LawfulStore st] (Z Z' : XSets /-- the source stays, and every other non-null slot keeps its cap. -/ src' : x ∈ OS' kept : ∀ u ∈ OS, u ≠ x → capA st s u ≠ .Null → u ∈ OS' ∧ capA st s' u = capA st s u + /-- (E0.5c) an old slot whose cap is unchanged keeps its revocable bit (J5 context's `hrev`). -/ + revK : ∀ y ∈ OS, capA st s y = capA st s' y → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y /-- (12′) the old TCBs stay. -/ tcbSub : ∀ t ∈ Z.T, t ∈ Z'.T /- new IPC objects and SCs in the grown heap -/ @@ -102,7 +104,8 @@ structure UtAsmHeapInA (st : machine.Store S) [L : LawfulStore st] (Z Z' : XSets frSplit : ∃ New : U64 → Prop, (∀ y ∈ OS', isFrA (capA st s' y) = true ∨ RngKeyA (capA st s' y) → (∃ y0 ∈ OS, capA st s y0 = capA st s' y) ∨ - (New y ∧ p.val + fi.val ≤ (ptrA (capA st s' y)).val ∧ (ptrA (capA st s' y)).val < p.val + 2 ^ sb.val)) ∧ + (New y ∧ p.val + fi.val ≤ (ptrA (capA st s' y)).val ∧ (ptrA (capA st s' y)).val < p.val + 2 ^ sb.val ∧ + (isFrA (capA st s' y) = true → topA (capA st s' y) < p.val + 2 ^ sb.val))) ∧ ∀ y z, New y → New z → isFrA (capA st s' y) = true → ¬ RngKeyA (capA st s' z) devSplit : ∀ y ∈ OS', ∀ q size rights mapped ept asid va, capA st s' y = .Frame q size rights true mapped ept asid va → @@ -132,6 +135,113 @@ structure UtAsmHeapOutA (st : machine.Store S) [L : LawfulStore st] (Z' : XSetsA devFr : DevFrDisjA st H' OS' s' σ' thPos : ∀ q z, Z'.th q = some (.other z) → 0 < z +/-- **A new cap's range** (E0.5c): `[bj, bj + 2^z)`, inside the untyped's free part (from the cap bundle). -/ +theorem utRt_newRngCapA (I : UtAsmCapsInA st Z Z' H H' OS OS' s s' x p sb fi nfi nt us aligned win) + (hn : nt.val < 15) {j : Nat} (hj : j < win) : + baseA (newCapA nt.val (bjA aligned (zA nt.val us) j) us false) = aligned.val + j * 2 ^ (zA nt.val us).val ∧ + topA (newCapA nt.val (bjA aligned (zA nt.val us) j) us false) = + aligned.val + j * 2 ^ (zA nt.val us).val + 2 ^ (zA nt.val us).val - 1 ∧ + p.val + fi.val ≤ baseA (newCapA nt.val (bjA aligned (zA nt.val us) j) us false) ∧ + topA (newCapA nt.val (bjA aligned (zA nt.val us) j) us false) < p.val + 2 ^ sb.val := by + have hpos := Nat.two_pow_pos (zA nt.val us).val + have hs1 : j * 2 ^ (zA nt.val us).val + 2 ^ (zA nt.val us).val ≤ win * 2 ^ (zA nt.val us).val := by + have := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt hj) + rwa [Nat.succ_mul] at this + have hfit := I.W.fit + have hbv : (bjA aligned (zA nt.val us) j).val = aligned.val + j * 2 ^ (zA nt.val us).val := bjA_val (by omega) + obtain ⟨b1, t1⟩ := newCapA_range hn (bjA aligned (zA nt.val us) j) us false I.W.z64 (by omega) + have lo := I.lo + have top := I.top + exact ⟨by rw [b1, hbv], by rw [t1, hbv], by rw [b1, hbv]; omega, by rw [t1, hbv]; omega⟩ + +/-- **`FrLamA` after Retype**, from the cap split (E0.5c). `New` = a fresh slot (not the source, not kept) holding a new +object's cap; two of those either are disjoint or hold the same range. -/ +theorem utRt_lamHeapA + (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) + (I : UtAsmCapsInA st Z Z' H H' OS OS' s s' x p sb fi nfi nt us aligned win) + (hn : nt.val < 15) + (revK : ∀ y ∈ OS, capA st s y = capA st s' y → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) : + FrLamA st OS' s' := by + obtain ⟨G, par, hT⟩ := J.sys.sysl.sys.stz.1.1.tu + have hU := hT.ut + refine utRt_lamA J.frBase.2.2 hU I.src I.cap + (fun y => y ∈ OS' ∧ y ≠ x ∧ ¬ (y ∈ OS ∧ capA st s' y = capA st s y) ∧ + ∃ j < win, capA st s' y = newCapA nt.val (bjA aligned (zA nt.val us) j) us false) ?_ ?_ ?_ ?_ + · intro y hy ny p0 rt mp e asid va hc + have old : y ∈ OS ∧ capA st s' y = capA st s y → ∃ y0 ∈ OS, ∃ (q0 rt0 : U64) (mp0 e0 : Bool) (a0 v0 : U64), + capA st s y0 = .Frame q0 .Large rt0 false mp0 e0 a0 v0 ∧ + baseA (capA st s' y) = baseA (capA st s y0) ∧ topA (capA st s' y) = topA (capA st s y0) := + fun ⟨hyo, k⟩ => ⟨y, hyo, p0, rt, mp, e, asid, va, by rw [← k]; exact hc, by rw [k], by rw [k]⟩ + rcases I.slots y hy with o | ⟨-, fi', k⟩ | ⟨j, hj, k⟩ | k + · exact old o + · rw [k] at hc; cases hc + · by_cases ko : y ∈ OS ∧ capA st s' y = capA st s y + · exact old ko + · exact (ny ⟨hy, (fun hyx => by rw [hyx, I.cap'] at hc; cases hc), ko, j, hj, k⟩).elim + · rw [k] at hc; cases hc + · intro z hz nz pz + have old : z ∈ OS ∧ capA st s' z = capA st s z → ∃ z0 ∈ OS, physA (capA st s z0) = true ∧ + baseA (capA st s' z) = baseA (capA st s z0) ∧ topA (capA st s' z) = topA (capA st s z0) ∧ + (isFrA (capA st s z0) = true → Fl4ProofsA64.P1.W7.R.ST.revA st s z0 = false → isFrA (capA st s' z) = true ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s' z = false) := + fun ⟨hzo, k⟩ => ⟨z, hzo, by rw [← k]; exact pz, by rw [k], by rw [k], + fun f r => ⟨by rw [k]; exact f, by rw [revK z hzo k.symm]; exact r⟩⟩ + have src : ∀ fi', capA st s' z = .Untyped p sb fi' false → ∃ z0 ∈ OS, physA (capA st s z0) = true ∧ + baseA (capA st s' z) = baseA (capA st s z0) ∧ topA (capA st s' z) = topA (capA st s z0) ∧ + (isFrA (capA st s z0) = true → Fl4ProofsA64.P1.W7.R.ST.revA st s z0 = false → isFrA (capA st s' z) = true ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s' z = false) := + fun fi' k => ⟨x, I.src, by rw [I.cap]; exact physA_ut _ _ _ _, + by rw [k, I.cap]; unfold baseA; rw [ptrA_ut, ptrA_ut], + by rw [k, I.cap]; unfold topA; rw [ptrA_ut, sizeA_ut, ptrA_ut, sizeA_ut], + fun f _ => by rw [I.cap] at f; simp [isFrA] at f⟩ + rcases I.slots z hz with o | ⟨-, fi', k⟩ | ⟨j, hj, k⟩ | k + · exact old o + · exact src fi' k + · by_cases hzx : z = x + · exact src nfi (by rw [hzx]; exact I.cap') + · by_cases ko : z ∈ OS ∧ capA st s' z = capA st s z + · exact old ko + · exact (nz ⟨hz, hzx, ko, j, hj, k⟩).elim + · rw [k, physA_null] at pz; cases pz + · rintro y hy ⟨-, -, -, j, hj, k⟩ _ + obtain ⟨-, -, b, t⟩ := utRt_newRngCapA I hn hj + rw [k] + exact ⟨b, t⟩ + · rintro y hy z hz ⟨-, -, -, j, hj, ky⟩ ⟨-, -, -, l, hl, kz⟩ _ _ _ + by_cases hjl : j = l + · subst hjl + rw [ky, kz] + exact Or.inr ⟨le_refl _, le_refl _⟩ + · obtain ⟨b1, t1, -, -⟩ := utRt_newRngCapA I hn hj + obtain ⟨b2, t2, -, -⟩ := utRt_newRngCapA I hn hl + rw [ky, kz] + refine Or.inl ?_ + have hpos := Nat.two_pow_pos (zA nt.val us).val + unfold DisjA + rw [b1, t1, b2, t2] + rcases Nat.lt_or_gt_of_ne hjl with hlt | hgt + · have := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt hlt) + rw [Nat.succ_mul] at this + left; omega + · have := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt hgt) + rw [Nat.succ_mul] at this + right; omega + +/-- **The kept slots' revocable bits** (E0.5c): from the loop's `hrevL` (every slot off the destination slots), the +destination slots being empty before and holding a physical new cap after. -/ +theorem utRt_revKA {OS : Set U64} {s s' : S} {dest off win : U64} {nt us aligned : U64} + (hrevL : ∀ y ∈ OS, (∀ j, j < win.val → y ≠ djA dest off j) → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) + (dstNull : ∀ j < win.val, capA st s (djA dest off j) = .Null) + (hnew : ∀ j < win.val, capA st s' (djA dest off j) = newCapA nt.val (bjA aligned (zA nt.val us) j) us false) : + ∀ y ∈ OS, capA st s y = capA st s' y → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s y := by + intro y hy e + refine hrevL y hy fun j hj ey => ?_ + have h1 := dstNull j hj + have h2 := hnew j hj + rw [← ey] at h1 h2 + rw [h1, h2] at e + have := newCapA_phys nt.val (bjA aligned (zA nt.val us) j) us false + rw [← e, physA_null] at this + cases this + theorem utRt_asmHeapA (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) (I : UtAsmCapsInA st Z Z' H H' OS OS' s s' x p sb fi nfi nt us aligned win) @@ -167,7 +277,7 @@ theorem utRt_asmHeapA exact ⟨h1, fun hn => h2 ⟨hn.1, fun i hi => by rw [← K.idleSc i]; exact hn.2 i hi⟩⟩) (fun c hc => J.toJEntA.scs.symm ▸ hc) I.heap (fun c hc => (K.scSplit c hc).imp (fun g => ⟨g.1, by rw [g.2, K.scName c]⟩) id) - frBase := utRt_frBaseA J.frBase hU I.src I.cap New hsplit huni + frBase := utRt_frBaseA J.frBase hU I.src I.cap New hsplit huni (utRt_lamHeapA J I K.nt15 K.revK) devFr := utRt_devFrDisjA J.devFr hU I.src I.cap K.devSplit K.devKeep thPos := fun q z h => (K.thSplit q z h).elim (J.thPos q z) id } diff --git a/proofs/Fl4ProofsA64/P3/UtBigCarryA.lean b/proofs/Fl4ProofsA64/P3/UtBigCarryA.lean new file mode 100644 index 000000000..3c3e189fe --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtBigCarryA.lean @@ -0,0 +1,157 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line prst, Part B): **what a completed chunk loop carries**. + +* `DelBudA` (the current SC's head ready and, with consumed time, still sufficient) is kept by a CNode write + (`delBud_cnStepA`) and by an `Ok` preemption point (`delBud_ppA`: no clock tick, or a tick whose sufficiency check + passed). +* `utBig_ppA`: the preemption point's loop hook with the timing facts, the frame (`UtPreKeepA`) and `DelBudA` carried + on the `Ok` exit. +* `utBig_budA`: `DelBudA` after `delete_objects`, from the syscall-entry record. +* `BodyOKA.utKeepCur`: `BodyOKA` across the creation (`UtKeepCurA`). + +Named premises: [P] `hnd`, `hNow`, `hag` (FL4's minimum budget is the spec's). New theorems only. +-/ +import Fl4ProofsA64.P3.UtPreCarryA + +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 + +theorem delBud_cnStepA {σ σ' : State Unit} (B : DelBudA σ) (H : UtCnStepA σ σ') : DelBudA σ' := by + intro y n hk hg + have hk0 : σ.kheap σ.curSc = some (.schedContext y n) := by + rw [← H.csc]; exact H.back hk (fun _ _ e => by cases e) + rw [H.csc] at hg + obtain ⟨r, o⟩ := B y n hk0 hg + refine ⟨fun z j hz => ?_, fun hpos z j hz ha => ?_⟩ + · rw [hk] at hz + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + rw [H.cons, H.time] + exact r y n hk0 + · rw [hk] at hz + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + rw [H.cons] at hpos ⊢ + rw [H.time] + exact o hpos y n hk0 (fun h => ha (by rw [H.csc]; exact h)) + +/-- **An `Ok` preemption point keeps `DelBudA`** (module docstring). -/ +theorem delBud_ppA {σ σ' : State Unit} (B : DelBudA σ) (hnd : numDomains = 1) + (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) + (hmono : σ.curTime ≤ rawNextA σ.machineState) (hag : fl4MinBudget = MIN_BUDGET) + (h : (Except.ok (), σ') ∈ ((preemptionPoint (Z := Unit)).run σ).1) : DelBudA σ' := by + rcases preemptionPoint_casesA hnd hNow h with ⟨-, e⟩ | ⟨t, F⟩ + · rw [e]; exact B + obtain ⟨w, i, hw, ha, hsuf⟩ := (F rfl).sc + have hw0 : σ.kheap σ.curSc = some (.schedContext w i) := by rw [← t.kheap, ← t.csc]; exact hw + have ready : OffReadyA σ' := fun z j hz => by + rw [t.kheap, t.csc] at hz + exact t.offReady hmono (fun v k hv => (B w i hw0 (Or.inr ha)).1 v k hv) hz + intro y n hk _ + refine ⟨ready, fun _ z j hz _ => ?_⟩ + rw [hw] at hz + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + have hr := ready w i hw + have hlt := σ'.curTime.isLt + have e : ((refillHd w).rTime + σ'.consumedTime).toNat = (refillHd w).rTime.toNat + σ'.consumedTime.toNat := by + rw [BitVec.toNat_add]; exact Nat.mod_eq_of_lt (by omega) + refine ⟨by rw [hag]; exact hsuf, ?_, ?_⟩ + · unfold refillReady' + rw [decide_eq_true_eq, BitVec.le_def, e]; exact hr + · unfold refillReady refillReady' + have e0 : ((refillHd w).rTime + 0).toNat = (refillHd w).rTime.toNat := by simp + rw [decide_eq_true_eq, BitVec.le_def, e0]; omega + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **The preemption point's hook for a chunk loop that completes** (module docstring). -/ +theorem utBig_ppA {OS : Set U64} {R Rp : S → A → State Unit → Prop} {Clock : A → MachineState → Prop} + {σ0 : State Unit} (hnd : numDomains = 1) + (hNow : ∀ σ : State Unit, fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) + (hag : fl4MinBudget = MIN_BUDGET) + (h : PPHypUtA st ar OS (fun s a σ => R s a σ ∧ UtPpTimeA Clock a σ) (fun s a σ => R s a σ ∧ UtPpTimeA Clock a σ)) + (hRp : ∀ s a σ, R s a σ → Rp s a σ) : + PPHypUtA st ar OS (fun s a σ => R s a σ ∧ (UtPpTimeA Clock a σ ∧ UtPreKeepA σ0 σ ∧ DelBudA σ)) Rp := by + rintro s a σ ⟨hR, hT, hK, hB⟩ + refine WP.spec_mono (h s a σ ⟨hR, hT⟩) ?_ + rintro r ⟨hc, σ', g⟩ + refine ⟨hc, σ', ?_⟩ + rcases g with ⟨e, mem, hR', hT'⟩ | ⟨e, mem, hR', -⟩ + · exact Or.inl ⟨e, mem, hR', hT', hK.ppStep hnd (hNow σ) mem, + delBud_ppA hB hnd (hNow σ) (BitVec.le_trans hT.valid hT.cs) hag mem⟩ + · exact Or.inr ⟨e, mem, hRp _ _ _ hR'⟩ + +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} {σ σd : State Unit} {m : McState} + +/-- **`DelBudA` at a state that keeps the frame and the time of the restarted entry state.** -/ +theorem utBig_budA (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)) + (K : UtPreKeepA (stUpdA σ σ.curThread x .restart) σd) (htime : σd.curTime = σ.curTime) + (hcons : σd.consumedTime = σ.consumedTime) : DelBudA σd := by + obtain ⟨y0, k0, hy0⟩ := J.curInv.sc + have ne : σ.curSc ≠ σ.curThread := fun e => by rw [e, hk] at hy0; cases hy0 + have ecsc : σd.curSc = σ.curSc := K.csc + have hd : σd.kheap σ.curSc = some (.schedContext y0 k0) := + K.sc y0 k0 (show (stUpdA σ σ.curThread x .restart).kheap σ.curSc = _ by + simp only [stUpdA, setObjA, Function.update_of_ne ne]; exact hy0) + intro y n hy _ + rw [ecsc, hd] at hy + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hy) + refine ⟨fun z j hz => ?_, fun hpos z j hz ha => ?_⟩ + · rw [ecsc, hd] at hz + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + rw [hcons, htime] + exact J.offReady y0 k0 hy0 + · rw [ecsc, hd] at hz + obtain ⟨rfl, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + rw [hcons] at hpos ⊢ + rw [htime] + exact J.offOK hpos y0 k0 hy0 (fun h => ha (by rw [ecsc]; exact h)) + +end + +/-- **`BodyOKA` across the creation** after a reset (module docstring). -/ +theorem Sched.BodyOKA.utKeepCur {σ σ' : State Unit} {m : McState} (B : Sched.BodyOKA σ m) (K : UtKeepCurA σ σ') + (hns : ∀ u, σ.schedulerAction ≠ .switchThread u) + (hsc : ∃ y k, σ.kheap σ.curSc = some (.schedContext y k)) (ht : ∃ x, σ.kheap σ.curThread = some (.tcb x)) : + Sched.BodyOKA σ' m := by + obtain ⟨y0, k0, hy0⟩ := hsc + obtain ⟨x0, hx0⟩ := ht + have hsc' : σ'.kheap σ.curSc = some (.schedContext y0 k0) := K.sc y0 k0 hy0 + have ht' : σ'.kheap σ.curThread = some (.tcb x0) := K.tcb x0 hx0 + have hy : ∀ y k, σ'.kheap σ'.curSc = some (.schedContext y k) → σ.kheap σ.curSc = some (.schedContext y k) := + fun y k h => by + rw [K.glob.csc, hsc'] at h + rw [hy0]; exact h + have hg : ∀ y : SchedContext, (σ'.curSc = idleScPtr ∨ scActive y = true) → (σ.curSc = idleScPtr ∨ scActive y = true) := + fun y h => by rwa [K.glob.csc] at h + refine { validTime := ?_, budget := fun y k hk g c => ?_, ctAct := fun h x hx => ?_, sw := fun u e => ?_, + scNotIdle := fun h => ?_, owner := fun y k hk a ne c o ho => ?_ } + · have := B.validTime + unfold ValidMachineTimeA at this ⊢ + rw [K.glob.time, K.last]; exact this + · rw [K.glob.cons, K.glob.act] at c + obtain ⟨r, o⟩ := B.budget y k (hy y k hk) (hg y g) c + refine ⟨fun z j hz => ?_, fun hpos z j hz ha => ?_⟩ + · rw [K.glob.cons, K.glob.time]; exact r z j (hy z j hz) + · rw [K.glob.cons] at hpos ⊢ + rw [K.glob.time] + exact o hpos z j (hy z j hz) (fun h => ha (by rw [K.glob.csc]; exact h)) + · rw [K.glob.cur, ht'] at hx + obtain rfl := KernelObject.tcb.inj (Option.some.inj hx) + exact B.ctAct (by rw [← K.glob.act]; exact h) x0 hx0 + · rw [K.glob.act] at e; exact absurd e (hns u) + · rw [K.glob.csc] at h ⊢; exact B.scNotIdle h + · rw [K.glob.rls] + rw [K.glob.csc] at ne + rw [K.glob.cons] at c + exact B.owner y k (hy y k hk) a ne c o ho + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtBigDecA.lean b/proofs/Fl4ProofsA64/P3/UtBigDecA.lean new file mode 100644 index 000000000..6d6cc11b9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtBigDecA.lean @@ -0,0 +1,181 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line prst, Part B): **`untyped::decode` for a Retype whose reset runs the chunk loop to +completion** (a RAM untyped of at least 64 KiB, used, and `reset_untyped` returns `Ok`: case hypotheses). + +* `utRetype_resetBigRunA`: at the reset's exit, a spec reset matches, `JStage3A` holds over the dropped sets, with the + timing facts, the frame (`UtPreKeepA`) and `DelBudA`. +* `utDecode_recResetBigA`: the decode-level top (`utDecode_recResetGenA`), with a spec outcome of the invocation and the + record after the creation. + +Named premises: those of `utDecode_recResetGenA`, [P] `hPost`, `hchunk`, `hnd`, the clock and interrupt facts, `hag`; +[J] `JSyscallA`. New theorems only. +-/ +import Fl4ProofsA64.P3.UtBigCarryA +import Fl4ProofsA64.P3.UtPreDecA +import Fl4ProofsA64.P3.UtDecExA + +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 + +set_option maxRecDepth 100000 + +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} +variable {Ud Acd Rq Nt : Set U64} {ex : Aeneas.Std.Array obj.Slot 3#usize} {p sb fi : U64} + +set_option maxHeartbeats 1000000 in +/-- **The exit of a completed chunk loop** (module docstring). -/ +theorem utRetype_resetBigRunA [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 : ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + (hchunk : resetChunkBits = 16) + (hnd : numDomains = 1) {Clock : A → MachineState → Prop} (Pc : NowAgreeA ar Clock) + (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 ⦄) + (hag : fl4MinBudget = MIN_BUDGET) + (hT0 : UtPpTimeA Clock a (utDelStA (specPtr p) sb.val σ)) + (hK0 : UtPreKeepA σ (utDelStA (specPtr p) sb.val σ)) + (hB0 : DelBudA (utDelStA (specPtr p) sb.val σ)) + (hfi : fi ≠ 0#u64) (hbig : 16 ≤ sb.val) + {s3 : S} {a3 : A} + (hres : untyped.reset_untyped st ar s a (cslotAddrA cte) = ok (core.result.Result.Ok (), s3, a3)) : + ∃ σ3, (.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 a3 σ3 (dropMA (utDA p sb.val) m) ∧ + UtPpTimeA Clock a3 σ3 ∧ UtPreKeepA σ σ3 ∧ DelBudA σ3 := by + have R := utReset_bigA ar Y.sact Y.rec_ Y.dec Y.place Y.cap Y.noch Y.symL Y.othT Y.othC hn cte hq hth rfl hPost + (fun _ _ _ _ => True) (fun a σ' => UtPpTimeA Clock a σ' ∧ UtPreKeepA σ σ' ∧ DelBudA σ') + (fun _ _ _ h H hm => ⟨h.1.cnStep H hm, h.2.1.cnStep H, delBud_cnStepA h.2.2 H⟩) ⟨hT0, hK0, hB0⟩ + (fun Rq' Nt' o _ => utBig_ppA (σ0 := σ) (Clock := Clock) + (R := 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) + (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n nA (dropMA (utDA p sb.val) m) p sb + (cslotAddrA cte) Rq' Nt' (Array.repeat 3#usize 0#u64) s a σ' o) + hnd hNow hag (utPp_hookA (AR := AR) (Z := dropZA (utDA p sb.val) Z) ar hnd Pc + (fun _ _ _ J sact nsw => utRst_hvpA J sact nsw) hC hNow hAr hirq hmb) (fun _ _ _ _ => trivial)) + hfi hbig hchunk + rw [hres, WP.spec_ok] at R + rcases R with ⟨-, σ3, _, _, hm, I, T, K, B⟩ | ⟨h, -⟩ + · exact ⟨σ3, hm, I.rec_, T, K, B⟩ + · cases h + +variable {J7 : JSlotA S} + +set_option maxHeartbeats 4000000 in +/-- **The decode-level top of a completed chunk loop** (module docstring). -/ +theorem utDecode_recResetBigA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA : P0.ArchTotal 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 nA)) s a σ m) + (sl : CslotPtr) (hsrc : ∃ q, sl.1 = specPtr q ∧ Z.th q = some (.cnode sl.2.length)) + (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) + (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) + (hn : nA.val = fl4A64Platform.s2IpaBits) + (hPost : ∀ σ' : State Unit, ((), σ') ∈ (archPostResetUntyped (Z := Unit) false sb.val σ').1) + (hchunk : resetChunkBits = 16) + (hnd : numDomains = 1) {Clock : A → MachineState → Prop} (Pc : NowAgreeA ar Clock) + (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 ⦄) + (hag : fl4MinBudget = MIN_BUDGET) + (hFr : ∀ a ms ms', Clock a ms → ms'.timeState = ms.timeState → ms'.lastMachineTime = ms.lastMachineTime → + Clock a ms') + (hCl : Clock a σ.machineState) (hCnt : CounterStepA σ) + -- the case: a used untyped of at least a chunk, and the reset completes + (hfi : fi ≠ 0#u64) (hbig : 16 ≤ sb.val) {s3 : S} {a3 : A} + (hres : untyped.reset_untyped st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) = + ok (core.result.Result.Ok (), s3, a3)) + -- 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), + res.1 = .Ok () ∧ ∃ σ3, (.ok (), σ3) ∈ ((resetUntypedCap (Z := Unit) sl).run + (stUpdA σ σ.curThread xT .restart)).1 ∧ + (∃ a4 : A, UtPpTimeA Clock a4 σ3 ∧ UtPreKeepA (stUpdA σ σ.curThread xT .restart) σ3 ∧ DelBudA σ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_recResetGenA hA J.sact J.toJStage3A 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 + (fun xT a4 σ3 => UtPpTimeA Clock a4 σ3 ∧ UtPreKeepA (stUpdA σ σ.curThread xT .restart) σ3 ∧ DelBudA σ3) ?_ hVP + hKt hK0) fun res h => h.monoQ fun inv g => ?_ + · intro xT hkT Y base nt us dest off win K _ hdrop + have J2 := (utReset_startA Y.rec_ Y.dec Y.place Y.cap Y.noch Y.symL Y.othT Y.othC hn sl hsrc.choose_spec.1 + hsrc.choose_spec.2 rfl).1 + obtain ⟨T0, Kp0⟩ := utPre_startA J hkT J2 hCl hCnt hFr + have B0 := utBig_budA J hkT Kp0 rfl rfl + obtain ⟨σ3, hm, J3, T, Kp, B⟩ := utRetype_resetBigRunA ar sl hsrc.choose_spec.1 hsrc.choose_spec.2 Y hn hPost hchunk + hnd Pc hC hNow hAr hirq hmb hag T0 Kp0 B0 hfi hbig hres + have e := utRetype_splitA (st := st) ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) base nt us + dest off win false + rw [e, hres, bind_ok] + simp only [Aeneas.Std.uncurry_apply_pair, core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + exact hdrop hfi s3 a3 σ3 hres hm J3 ⟨T, Kp, B⟩ + · obtain ⟨base, retypeBase, t, us, slots, rfl, xT, hkT, aligned, nt, usF, dest, off, win, rd, hU, rfl, rfl, rfl, + rfl, hok, σ3, hm, hW, Z0, m0, hZ, ⟨r, hr⟩, Kr⟩ := g + obtain ⟨vm, kp, H'', OS'', U'', Ac', Pp'', Tb'', N'', E'', Rp'', Bf'', stack'', κ'', J'⟩ := Kr r hr + obtain ⟨⟨⟩, σ1⟩ := r + exact ⟨xT, hkT, aligned, nt, usF, dest, off, win, hok, σ3, hm, hW, _, 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/UtChunkA.lean b/proofs/Fl4ProofsA64/P3/UtChunkA.lean index 90e37cafe..ecd7117a8 100644 --- a/proofs/Fl4ProofsA64/P3/UtChunkA.lean +++ b/proofs/Fl4ProofsA64/P3/UtChunkA.lean @@ -44,7 +44,9 @@ theorem JAtZAX.of_lowerA {AR : A → HwRootA → Prop} {Z : XSetsA} {s : S} {a : (hal : ∀ b, FootNA (L := L) Z s b → Aligned b) (cte : CslotPtr) {q : U64} (hq : cte.1 = specPtr q) (hth : Z.th q = some (.cnode cte.2.length)) {c : capability.Cap} {sc : Cap} (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) - (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) (hok : CapObjOkA Z c) {s2 : S} + (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) (hok : CapObjOkA Z c) + (hptc : PtSrcA Z.th Z.S1 Z.T2 (L.mem s) c) (hrt : RootSetA (capAtA (L.mem s) (cslotAddrA cte)) c) + (hpt : PtSetE Z.th (L.mem s) (cslotAddrA cte) c := by pt_nr) {s2 : S} (hset : obj.Slot.set_cap st (cslotAddrA cte) s c = ok s2) (hT2 : TreeA st OS Z.G.chains Z.G.par s2) : ∃ cs, σ.kheap cte.1 = some (.cnode cte.2.length cs) ∧ wellFormedCnodeN cte.2.length cs ∧ @@ -101,7 +103,8 @@ theorem JAtZAX.of_lowerA {AR : A → HwRootA → Prop} {Z : XSetsA} {s : S} {a : (fun sl hsl => by rw [revA_wr2A hO hos (hsub _ (hsl.isSlot hP1))]; exact C1.orig sl hsl) C1.par_slot C1.po refine ⟨cs, hk', hwf, hmem, hw2, - J.of_slotWrites hw2 (fun b hb hf => hoff b hf hb) hal Z.G HS hSR hC fun y hy => ?_⟩ + J.of_slotWrites hw2 (fun b hb hf => hoff b hf hb) hal Z.G HS hSR hC (fun y hy => ?_) + (PtClosedA.of_set hptc hcx hcapo hrt hpt)⟩ by_cases hne : y = cslotAddrA (specPtr q, idx) · subst hne; rw [hcx]; exact hok · rw [hcapo y hy hne]; exact J.capObj hy @@ -283,7 +286,9 @@ theorem utChunk_coreA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] {dev : B (footNAl_ksA hks1 hcpu1 hfal) cte hq hth hEnc hca (fun y hy hn => (osk1.capA hy).trans (hnul y hy hn)) ⟨(fun _ h => by cases h), (fun _ _ _ _ _ h => by cases h), (fun _ _ _ h => by cases h), (fun _ _ _ h => by cases h), - trivial⟩ (s2 := s2) (by rw [hxc]; exact hset) hT2 + trivial⟩ (PtSrcA.nopt fun _ _ _ _ h => by cases h) + (RootSetA.of_noRoot (NoRootKindA.untyped _ _ _ _)) + (Or.inl (PtSetA.of_noPt (NoPtKindA.of_ne fun _ _ _ _ h => by cases h))) (s2 := s2) (by rw [hxc]; exact hset) hT2 have hcsidx : cs cte.2 = some (.untypedCap dev (specPtr p) sb.val i.val) := by unfold specCapAtA at hacx rw [hk] at hacx @@ -786,13 +791,35 @@ theorem utChunk_coreA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] {dev : B exact hw.mem_eq (nodeAt_aligned (J.sq.nodes c hc) ho h8) fun h => hW _ h (Or.inl (Or.inl ⟨c, hc, o, ho, rfl⟩)) have frBase2 : FrBaseApartA st OS s2 := by - intro y hy z hz fy kz - have ny : y ≠ x := fun e => by rw [e, hcx'] at fy; simp [isFrA] at fy - have nz : z ≠ x := fun e => by rw [e, hcx'] at kz; exact absurd kz.2.1 (by simp [isUtA]) - rw [capK y hy ny] at fy - rw [capK z hz nz] at kz - rw [capK y hy ny, capK z hz nz] - exact J.frBase y hy z hz fy kz + have ny : ∀ y, y ∈ OS → isFrA (capA st s2 y) = true → y ≠ x := fun y hy fy e => by + rw [e, hcx'] at fy; simp [isFrA] at fy + have nz : ∀ z, z ∈ OS → RngKeyA (capA st s2 z) → z ≠ x := fun z hz kz e => by + rw [e, hcx'] at kz; exact absurd kz.2.1 (by simp [isUtA]) + refine ⟨fun y hy z hz fy kz => ?_, fun y hy z hz fy kz => ?_, ?_⟩ + · have ny' := ny y hy fy + have nz' := nz z hz kz + rw [capK y hy ny'] at fy + rw [capK z hz nz'] at kz + rw [capK y hy ny', capK z hz nz'] + exact J.frBase.1 y hy z hz fy kz + · have ny' := ny y hy fy + have nz' := nz z hz kz + rw [capK y hy ny'] at fy + rw [capK z hz nz'] at kz + rw [capK y hy ny', capK z hz nz'] + exact J.frBase.2.1 y hy z hz fy kz + · exact J.frBase.2.2.tr (fun y hy p0 rt mp e asid va hcy => by + have ny' : y ≠ x := fun h => by rw [h, hcx'] at hcy; cases hcy + exact ⟨y, hy, p0, rt, mp, e, asid, va, by rw [← capK y hy ny']; exact hcy, by rw [capK y hy ny'], + by rw [capK y hy ny']⟩) + (fun z hz pz => by + by_cases ez : z = x + · refine ⟨x, hx, (by rw [hcx]; exact physA_ut _ _ _ _), ?_, ?_, fun f _ => ?_⟩ + · rw [ez, hcx', hcx]; unfold baseA; rw [ptrA_ut, ptrA_ut] + · rw [ez, hcx', hcx]; unfold topA; rw [ptrA_ut, sizeA_ut, ptrA_ut, sizeA_ut] + · rw [hcx] at f; simp [isFrA] at f + · exact ⟨z, hz, by rw [← capK z hz ez]; exact pz, by rw [capK z hz ez], by rw [capK z hz ez], + fun f r => ⟨by rw [capK z hz ez]; exact f, by rw [hrv z hz]; exact r⟩⟩) have devFr2 : DevFrDisjA st H OS s2 σ2 := by intro y hy q size rights mapped ept asid va hc k hk obtain ⟨-, hc0⟩ := capNU y hy _ (by simp [isUtA]) hc @@ -978,8 +1005,9 @@ theorem utChunk_coreA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] {dev : B · exact J.vcOS _ ⟨v, hv, o, ho, h8, rfl⟩ (inOSx _ h)) (fun v _ y hy => H2.back hy (fun _ _ e => by cases e)) vcOS := J.vcOS - userFr := fun y hy q size rights mapped ept asid va hc => - H2.keep (J.userFr y hy q size rights mapped ept asid va ((same y hy _ rfl).1 hc)) (fun _ _ e => by cases e) + userFr := fun y hy q size rights mapped ept asid va hc => by + obtain ⟨b, pg, hHb, hk, g1, g2⟩ := J.userFr y hy q size rights mapped ept asid va ((same y hy _ rfl).1 hc) + exact ⟨b, pg, hHb, H2.keep hk (fun _ _ e => by cases e), g1, g2⟩ frTh := fun y hy q size rights x1 x2 x3 x4 bits hc hb => J.frTh y hy q size rights x1 x2 x3 x4 bits ((same y hy _ rfl).1 hc) hb bfSpec := J.bfSpec diff --git a/proofs/Fl4ProofsA64/P3/UtClosA.lean b/proofs/Fl4ProofsA64/P3/UtClosA.lean index d1314236c..569367907 100644 --- a/proofs/Fl4ProofsA64/P3/UtClosA.lean +++ b/proofs/Fl4ProofsA64/P3/UtClosA.lean @@ -454,7 +454,8 @@ theorem utClos_linksCdtA {th : TypedHeapA} {σ : Fl4SpecA64.State Unit} {G : Mdb or `Null` (`BufHold`), and the frame's heap object is kept by A64 P1's `FrameOK` over the dropped heap. -/ theorem utClos_bufA {H : Heap} {OS : Set U64} {par : U64 → Option U64} (hH : HeapOK H) (hF : FrameOK st H OS s) (hU : UtInvA st OS par s) {u p b i : U64} {d : Bool} (hu : u ∈ OS) (hcu : capA st s u = .Untyped p b i d) - (hnd : ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc par y u) (hsb : b.val < 64) (hp : p.val + 2 ^ b.val ≤ 2 ^ 64) + (hnd : ∀ y, ¬ Fl4Proofs.P3.Mdb.Desc par y u) (hRin : RegionIn H p.val (p.val + 2 ^ b.val)) (hsb : b.val < 64) + (hp : p.val + 2 ^ b.val ≤ 2 ^ 64) (hsp : (specPtr p).toNat + 2 ^ b.val ≤ 2 ^ 64) {t w : U64} {rcv : Bool} (hx : sbWordA t ∈ OffR p.val (p.val + 2 ^ b.val) OS) (hbc : BufCap (capA st s (sbWordA t))) (hl : msg.lookup_ipc_buffer st s rcv t = ok w) (hw : w ≠ 0#u64) : specPtr w ∉ utDA p b.val := by @@ -464,16 +465,15 @@ theorem utClos_bufA {H : Heap} {OS : Set U64} {par : U64 → Option U64} (hH : H rcases hbc with hn | ⟨ptr, size, rights, x1, x2, x3, x4, hc⟩ · rw [hn] at hl exact absurd (okinj hl).symm hw - have hF' := FrameOK.reset hF hU hu hcu hnd (OS' := OffR p.val (p.val + 2 ^ b.val) OS) (fun y hy => hy.1) + have hF' := FrameOK.reset hF hU hu hcu hnd hRin (OS' := OffR p.val (p.val + 2 ^ b.val) OS) (fun y hy => hy.1) (s' := s) (i' := i) hcu (fun _ _ _ => rfl) rw [hc] at hl simp only [Bool.false_eq_true, ↓reduceIte] at hl obtain ⟨bits, hbits⟩ : ∃ bits, size.bits = ok bits := by cases size <;> exact ⟨_, rfl⟩ have hobj := hF' _ hx ptr size rights x1 x2 x3 x4 hc bits hbits - obtain ⟨hnR, hqH⟩ := Heap.drop_eq_some.1 hobj - have hfit := hH.fits ptr _ hqH - simp only [HKind.bits] at hfit + obtain ⟨hqH0, hnR⟩ := FrAt.undrop hobj + have hfit := hqH0.fits hH have h30 : bits.val < 31 := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp -- the buffer address lies in the frame @@ -523,9 +523,7 @@ theorem utClos_bufA {H : Heap} {OS : Set U64} {par : U64 → Option U64} (hH : H intro hd have hr := (utD_memA hsb hp hsp w).1 hd apply hnR - unfold RegionD MeetsR - rw [hqH] - simp only [Option.elim, HKind.bits] + unfold MeetsR omega end diff --git a/proofs/Fl4ProofsA64/P3/UtCrtResetA.lean b/proofs/Fl4ProofsA64/P3/UtCrtResetA.lean index 8db4b9e18..54e5e37d8 100644 --- a/proofs/Fl4ProofsA64/P3/UtCrtResetA.lean +++ b/proofs/Fl4ProofsA64/P3/UtCrtResetA.lean @@ -65,7 +65,7 @@ theorem utCrtP_resetA (hA : P0.ArchTotal ar) {s0 s2 s3 : S} {extra : Aeneas.Std. have hdc' := untyped.retype_dest.covC hO R.ty hS0 (R.ext x hxm hx0) erd have hdn0 := UtArgs.hdn R.ty R.ext hU have hrun := WP.spec_and (untyped.reset_untyped.stZFC hA hH hO hb2 R.slotw hRk2 hSt2 hF2 hCZ2 hsrc hnd2 - hW2 a) (WP.spec_and (untyped.reset_untyped.wr hA hb2 R.slotw hRk2 a) + hRin hW2 a) (WP.spec_and (untyped.reset_untyped.wr hA hb2 R.slotw hRk2 a) (resetP1Step_holds (st := st) hA H Cs Ac s2 a slot p sb fi false hb2 hRk2.1 R.slotw hpal hfit P2 hnode2 hsz)) rw [eres, WP.spec_ok] at hrun obtain ⟨⟨⟨hS1, hF1, hC1⟩, i, hci, hi0⟩, hw1, H2, Ac2, hbR, hsh, -, -⟩ := hrun diff --git a/proofs/Fl4ProofsA64/P3/UtDecRecRstA.lean b/proofs/Fl4ProofsA64/P3/UtDecRecRstA.lean index ec1a0e129..d84fb60a6 100644 --- a/proofs/Fl4ProofsA64/P3/UtDecRecRstA.lean +++ b/proofs/Fl4ProofsA64/P3/UtDecRecRstA.lean @@ -125,8 +125,10 @@ def UtRstRecA (AR : A → HwRootA → Prop) (Z0 : XSetsA) (m0 : McState) (sl : C (utRtMA m0 (UtOfTyA 1 nt us aligned win.val)) set_option maxHeartbeats 4000000 in -/-- **The decode-level top, with a reset** (module docstring). -/ -theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA : P0.ArchTotal ar) +/-- **The decode-level top, with a reset, over how the reset returns**: `hrst` splits `retype` with `reset` into the +creation after an unused untyped's no-op and the creation over the dropped sets, and says what `W` holds of the reset's +exit. (`utDecode_recResetA`: no chunk loop; `utDecode_recResetBigA`: a completed chunk loop.) -/ +theorem utDecode_recResetGenA [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) @@ -154,10 +156,33 @@ 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 : 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) + (W : Tcb → A → State Unit → Prop) + (hrst : ∀ (xT : Tcb), σ.kheap σ.curThread = some (.tcb xT) → + UtRstReadyA (ar := ar) st AR Z H OS U Ac Pp Tb Lv ia ie N E Rq Bf stack κ n nA m U Ac H.replies H.ntfns + (Array.repeat 3#usize 0#u64) (cslotAddrA sl) p sb fi (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (stUpdA σ σ.curThread xT .restart) → + ∀ (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 + (fi = 0#u64 → + untyped.reset_untyped st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) = + ok (core.result.Result.Ok (), L.wr s (stA (L.curW s)) sched.TS_RESTART, a) → + (.ok (), stUpdA σ σ.curThread xT .restart) ∈ + ((resetUntypedCap (Z := Unit) sl).run (stUpdA σ σ.curThread xT .restart)).1 → + W xT a (stUpdA σ σ.curThread xT .restart) → + untyped.retype st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) false base nt us dest off + win false ⦃ r => K r ⦄) → + -- a used one: over the dropped sets + (fi ≠ 0#u64 → ∀ (s3 : S) (a3 : A) (σ3 : State Unit), + untyped.reset_untyped st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) = + ok (core.result.Result.Ok (), s3, a3) → + (.ok (), σ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)) s3 a3 σ3 (dropMA (utDA p sb.val) m) → + W xT a3 σ3 → + untyped.retype st ar s3 a3 (cslotAddrA sl) false base nt us dest off win false ⦃ r => K r ⦄) → + untyped.retype st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) true base nt us dest off win + false ⦃ r => K r ⦄) -- 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)) @@ -174,7 +199,7 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA slots = windowSlotsA dest rd off.val win.val ∧ (res.1 = .Ok () ∧ ∃ σ3, (.ok (), σ3) ∈ ((resetUntypedCap (Z := Unit) sl).run (stUpdA σ σ.curThread xT .restart)).1 ∧ - UtKeepCurA (stUpdA σ σ.curThread xT .restart) σ3 ∧ + (∃ a3, W xT a3 σ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 ⦄ := by @@ -302,14 +327,14 @@ theorem utDecode_recResetA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA 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 _ _ kp - refine WP.spec_mono (drop s3 a σ3 eres J3) fun res h => ?_ + refine hrst y hkT Y aligned nt us dest off win _ ?hnoop ?hdrop + case hdrop => + intro _ s3 a3 σ3 eres hm J3 hW + refine WP.spec_mono (drop s3 a3 σ3 eres J3) fun res h => ?_ exact ⟨_, _, _, _, _, rfl, y, hkT, aligned, nt, us, dest, off, win, rd, hU, rfl, rfl, rfl, rfl, - h.1, σ3, hm, kp, _, _, Or.inr ⟨rfl, rfl⟩, h.2⟩ + h.1, σ3, hm, ⟨a3, hW⟩, _, _, Or.inr ⟨rfl, rfl⟩, h.2⟩ case hnoop => - intro h0 eres hm + intro h0 eres hm hW obtain ⟨C1, -, -⟩ := utCrtP_resetA hA R e a a hU eres have hc2 : capA st s2 (cslotAddrA sl) = .Untyped p sb 0#u64 false := by rw [← h0]; exact okinj ((capA_eq s2 _).symm.trans Y.cap) @@ -352,13 +377,79 @@ 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, - ⟨hok, σ2, hm, UtKeepCurA.refl σ2, Z, m, Or.inl ⟨rfl, rfl⟩, + ⟨hok, σ2, hm, ⟨a, hW⟩, 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⟩ +set_option maxHeartbeats 4000000 in +/-- **The decode-level top, with a reset** (module docstring). -/ +theorem utDecode_recResetA [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 => ∃ (base retypeBase : Word) (t : ApiObjectType) (us : Nat) (slots : List CslotPtr), + inv = .retype sl true base retypeBase t us slots false ∧ + ∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + ∃ (aligned nt usF dest off win : U64) (rd : Nat), + 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, + (.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 ⦄ := by + refine WP.spec_mono (utDecode_recResetGenA 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 + (fun xT _ σ3 => UtKeepCurA (stUpdA σ σ.curThread xT .restart) σ3) ?_ hVP hKt hK0) fun res h => h.imp id fun ⟨inv, r, g⟩ => ⟨inv, r, ?_⟩ + · intro xT _ Y base nt us dest off win K hnoop hdrop + refine utRetype_resetNpA ar sl hsrc.choose_spec.1 hsrc.choose_spec.2 Y hn hPost hchunk hS base nt us dest off win K + (fun h0 e hm => hnoop h0 e hm (UtKeepCurA.refl _)) + (fun h0 _ s3 σ3 e hm J3 _ _ kp => hdrop h0 s3 a σ3 e hm J3 kp) + · obtain ⟨b1, b2, t, us, slots, e1, xT, hkT, aligned, nt, usF, dest, off, win, rd, hU, e2, e3, e4, e5, hok, σ3, hm, + ⟨_, kp⟩, rest⟩ := g + exact ⟨b1, b2, t, us, slots, e1, xT, hkT, aligned, nt, usF, dest, off, win, rd, hU, e2, e3, e4, e5, hok, σ3, hm, kp, + rest⟩ + end diff --git a/proofs/Fl4ProofsA64/P3/UtDropCA.lean b/proofs/Fl4ProofsA64/P3/UtDropCA.lean index 9c8d6b5df..835516292 100644 --- a/proofs/Fl4ProofsA64/P3/UtDropCA.lean +++ b/proofs/Fl4ProofsA64/P3/UtDropCA.lean @@ -143,8 +143,7 @@ theorem utBuf_addrA {H : Heap} {s : S} (hH : HeapOK H) {t w : U64} {rcv : Bool} obtain ⟨bits, hbits⟩ : ∃ bits, size.bits = ok bits := by cases size <;> exact ⟨_, rfl⟩ have hqH := hobj bits hbits - have hfit := hH.fits ptr _ hqH - simp only [HKind.bits] at hfit + have hfit := hqH.fits hH have h30 : bits.val < 31 ∧ 10 ≤ bits.val := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp have addr : ∀ r : Result U64, (do @@ -202,7 +201,10 @@ theorem utBuf_addrA {H : Heap} {s : S} (hH : HeapOK H) {t w : U64} {rcv : Bool} · split at hl · exact addr _ rfl hl · exact absurd (okinj hl).symm hw - exact ⟨ptr, bits.val, hqH, hin.1, hin.2, hfit⟩ + obtain ⟨q, z, hq, hbz, hq1, hq2⟩ := hqH.obj + have hfq := hH.fits q _ hq + simp only [HKind.bits] at hfq + exact ⟨q, z, hq, by omega, by omega, hfq⟩ /-! ## The derivation -/ @@ -377,6 +379,8 @@ theorem utDropG_of {dev : Bool} refine { dropOK := DK regionIn := hRin + hD := hD + src := ⟨x, R.src, _, hcx⟩ heapB := ?heapB slotsB := ?slotsB vsClos := hVs @@ -578,7 +582,7 @@ theorem utDropG_of {dev : Bool} have main : ∀ rcv, msg.lookup_ipc_buffer st s rcv t = ok w → specPtr (bufW w k) ∉ utDA p sb.val := by intro rcv hl' have kw : specPtr w ∉ utDA p sb.val := - utClos_bufA hH R.fr htr.ut R.src hcx hnd hsb hpfit hsp hsbK hbc hl' hw + utClos_bufA hH R.fr htr.ut R.src hcx hnd hRin hsb hpfit hsp hsbK hbc hl' hw obtain ⟨ptr, b, hq, h1, h2, h3⟩ := utBuf_addrA hH (fun ptr size rights x1 x2 x3 x4 hc => R.fr _ hsbO ptr size rights x1 x2 x3 x4 hc) hbc hl' hw (J.sys.sysl.ipc t ht) have hv : (bufW w k).val = w.val + 8 * k.val := by @@ -706,7 +710,7 @@ theorem utDropG_of {dev : Bool} obtain ⟨_, _, -, -, k, -⟩ := R.stz.1.1 exact k case frames => - have h := FrameOK.reset R.fr htr.ut R.src hcx hnd (OS' := OffR p.val (p.val + 2 ^ sb.val) OS) + have h := FrameOK.reset R.fr htr.ut R.src hcx hnd hRin (OS' := OffR p.val (p.val + 2 ^ sb.val) OS) (fun y hy => hy.1) (s' := s) (i' := fi) hcx (fun _ _ _ => rfl) have eH : H.drop (RegionD H p.val (p.val + 2 ^ sb.val)) = dropHA (utDA p sb.val) H := by funext q diff --git a/proofs/Fl4ProofsA64/P3/UtDropTopA.lean b/proofs/Fl4ProofsA64/P3/UtDropTopA.lean index c97f508fd..951c3b3d5 100644 --- a/proofs/Fl4ProofsA64/P3/UtDropTopA.lean +++ b/proofs/Fl4ProofsA64/P3/UtDropTopA.lean @@ -12,6 +12,7 @@ retained object refers into `D`". None of `UtDropC` is derived in this module. ` import Fl4ProofsA64.P3.Stage3Rec5A import Fl4ProofsA64.P3.UtDropJ57A import Fl4ProofsA64.P3.UtDropVs2A +import Fl4ProofsA64.P3.UtDropVsUniqA import Fl4ProofsA64.P3.UtClosA import Fl4ProofsA64.P1.QueueHeapDrop import Fl4ProofsA64.P3.UtVsOkJA @@ -36,6 +37,8 @@ structure UtDropG (st : machine.Store S) [L : LawfulStore st] (D : Set ObjRef) ( -- A64 P1's drop of the region dropOK : DropOK st H (RegionD H p.val (p.val + 2 ^ sb.val)) Z.Cs s regionIn : RegionIn H p.val (p.val + 2 ^ sb.val) + hD : ∀ z : U64, specPtr z ∈ D ↔ p.val ≤ z.val ∧ z.val < p.val + 2 ^ sb.val + src : ∃ x ∈ OS, ∃ d, capA st s x = .Untyped p sb fi d -- the bridges heapB : H.drop (RegionD H p.val (p.val + 2 ^ sb.val)) = dropHA D H slotsB : OffR p.val (p.val + 2 ^ sb.val) OS = dropSetA D OS @@ -333,6 +336,16 @@ theorem utDrop_blkQA rw [← ee, detype_keptA σ kb] exact hy +/-- **A joint object that holds a word off the removed region is kept** (E0.3: the objects containing a kept frame +range; `ObjAllocA` makes every joint object off the region or inside its used prefix). -/ +theorem utDrop_objKeptA {Z : XSetsA} {H : Heap} {OS : Set U64} {s : S} {D : Set ObjRef} {p sb fi : U64} + (hA : ObjAllocA (st := st) Z H OS s) (hD : ∀ z : U64, specPtr z ∈ D ↔ p.val ≤ z.val ∧ z.val < p.val + 2 ^ sb.val) + {x : U64} (hx : x ∈ OS) {d : Bool} (hc : capA st s x = .Untyped p sb fi d) (hfi : fi.val ≤ 2 ^ sb.val) + {q : U64} {bytes : Nat} (hj : JointObjectA Z H q bytes) {a : U64} (h1 : q.val ≤ a.val) + (h2 : a.val < q.val + bytes) (hoff : a.val < p.val ∨ p.val + 2 ^ sb.val ≤ a.val) : specPtr q ∉ D := fun hin => by + have hq := (hD q).1 hin + rcases hA q bytes hj x hx p sb fi d hc with o | o | o <;> omega + /-- **The top drop at any removed region** (module docstring): `UtDropG` and A64 P1's `SysL ∧ SymL` over the dropped heap and slot set. -/ theorem utDrop_genA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] @@ -347,6 +360,7 @@ theorem utDrop_genA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] SymL st (dropHA D H) Z.Cs s := by have hent := utDrop_entA J.sys.ent C.dropOK C.regionIn have hsq := SchedQueuesInv.drop C.dropOK J.sq + have hfr0 := hsys.1.sys.fr rw [C.heapB, C.slotsB] at hent hsys rw [C.heapB] at hsq obtain ⟨eh, ebxi, eos, euser, eksw⟩ := hent @@ -355,6 +369,18 @@ theorem utDrop_genA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] have hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null := J.j5.2.2 have htr : TreeA st OS Z.G.chains Z.G.par s := J.j.1.cdt.tree.grow hsub fun y hy hn => hnul y hy hn have htree := utDrop_treeA (D := D) htr hsub hnul C.gone + obtain ⟨xs, hxs, ds, hcs⟩ := C.src + have hfis : fi.val ≤ 2 ^ sb.val := htr.ut.fib xs hxs p sb fi ds hcs + -- the frame range of a kept frame cap lies in objects (heap, typed heap, spec page) kept by the drop + have frKept : ∀ y ∈ dropSetA D OS, ∀ fp size rights x1 x2 x3 x4 bits, + capA st s y = .Frame fp size rights false x1 x2 x3 x4 → size.bits = ok bits → + fp.val < p.val ∨ p.val + 2 ^ sb.val ≤ fp.val := by + intro y hy fp size rights x1 x2 x3 x4 bits hc hb + have hy' : y ∈ OffR p.val (p.val + 2 ^ sb.val) OS := by rw [C.slotsB]; exact hy + obtain ⟨-, hoff⟩ := FrAt.undrop (hfr0 y hy' fp size rights x1 x2 x3 x4 hc bits hb) + have h1 : 1 ≤ 2 ^ bits.val := Nat.one_le_two_pow + unfold MeetsR at hoff + omega have hps : PoolSet st (dropSetA D Pp) s = PoolSet st Pp s := by ext p constructor @@ -391,7 +417,8 @@ theorem utDrop_genA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] cv := utDrop_capValidA J.j.1.cv C.noCap pml := utDrop_pmlA J.j.1.pml C.pmlN vs := utDrop_vsRelA J.j.1.vs C.vsClos - ext := utDrop_extVsRelA J.j.1.ext C.vsClos } + ext := utDrop_extVsRelA J.j.1.ext C.vsClos + vsu := utDrop_vsUniqA J.j.1.vs J.j.1.ext C.vsClos J.j.1.vsu } have j7' : J7A st (J7R2A st ar nA) (dropZA D Z) (dropHA D H) (dropSetA D OS) s (detype D σ) (dropMA D m) := utDrop_J7A J.j7 rfl C.restr C.kinds C.frames C.arm C.omega C.vcpuN C.pages refine ⟨?_, ssym⟩ @@ -433,7 +460,8 @@ theorem utDrop_genA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] sinv := utDrop_sinvA J.sinv C.spec C.anchor C.curThread C.curSc C.idleThread C.irqNode setsInH := utDrop_setsInHA J.setsInH C.whole utIpc := utDrop_utIpcA J.utIpc - frBase := fun y hy z hz => J.frBase y hy.1 z hz.1 + frBase := ⟨fun y hy z hz => J.frBase.1 y hy.1 z hz.1, fun y hy z hz => J.frBase.2.1 y hy.1 z hz.1, + fun y hy p rt mp e asid va hc z hz pz => J.frBase.2.2 y hy.1 p rt mp e asid va hc z hz.1 pz⟩ devFr := fun y hy q size rights mapped ept asid va hc k hk => by obtain ⟨kq, hq⟩ := dropHA_someA.1 hk obtain ⟨h1, dev, pg, h2⟩ := J.devFr y hy.1 q size rights mapped ept asid va hc k hq @@ -512,13 +540,25 @@ theorem utDrop_genA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] vcSnap := ⟨fun v hv x hx => J.vcSnap.snap v hv.1 x (detype_someA.1 hx).2, fun v hv x hx => J.vcSnap.mask v hv.1 x (detype_someA.1 hx).2⟩ vcOS := fun b ⟨v, hv, r⟩ ⟨y, hy, g⟩ => J.vcOS b ⟨v, hv.1, r⟩ ⟨y, hy.1, g⟩ - userFr := fun y hy p size rights mapped ept asid va hc => by + userFr := fun y hy fp size rights mapped ept asid va hc => by obtain ⟨bits, hbits⟩ : ∃ bits, size.bits = ok bits := by cases size <;> exact ⟨_, rfl⟩ - have kp := (dropHA_someA.1 (ssys.sys.fr y hy p size rights mapped ept asid va hc bits hbits)).1 - exact (detype_keptA σ kp).trans (J.userFr y hy.1 p size rights mapped ept asid va hc) - frTh := fun y hy p size rights x1 x2 x3 x4 bits hc hb => by - have kp := (dropHA_someA.1 (ssys.sys.fr y hy p size rights x1 x2 x3 x4 hc bits hb)).1 - exact dropThA_someA.2 ⟨kp, J.frTh y hy.1 p size rights x1 x2 x3 x4 bits hc hb⟩ + have hfp := frKept y hy fp size rights mapped ept asid va bits hc hbits + obtain ⟨b, pg, hHb, hk, g1, g2⟩ := J.userFr y hy.1 fp size rights mapped ept asid va hc + have hpb : Fl4SpecA64.pageBitsForSize (frameSizeOfA size) = bits.val := by + cases size <;> simp [frameSizeOfA, Fl4SpecA64.pageBitsForSize, capability.FrameSize.bits] at hbits ⊢ <;> + cases hbits <;> decide + have h1 : 1 ≤ 2 ^ bits.val := Nat.one_le_two_pow + rw [hpb] at g2 + have kb := utDrop_objKeptA J.objAlloc C.hD hxs hcs hfis (Or.inr (Or.inr (Or.inr ⟨_, hHb, rfl⟩))) g1 + (by simp only [HKind.bits]; omega) hfp + exact ⟨b, pg, dropHA_someA.2 ⟨kb, hHb⟩, (detype_keptA σ kb).trans hk, g1, by rw [hpb]; exact g2⟩ + frTh := fun y hy fp size rights x1 x2 x3 x4 bits hc hb => by + have hfp := frKept y hy fp size rights x1 x2 x3 x4 bits hc hb + obtain ⟨b, len, hb0, g1, g2⟩ := J.frTh y hy.1 fp size rights x1 x2 x3 x4 bits hc hb + have h1 : 1 ≤ 2 ^ bits.val := Nat.one_le_two_pow + have kb := utDrop_objKeptA J.objAlloc C.hD hxs hcs hfis (Or.inr (Or.inr (Or.inl ⟨_, hb0, rfl⟩))) g1 + (by show _ < _ + (ObjKindA.other len).size; simp [ObjKindA.size]; omega) hfp + exact ⟨b, len, dropThA_someA.2 ⟨kb, hb0⟩, g1, g2⟩ bfSpec := fun bp h => J.bfSpec bp h.1 vcSym1 := fun t ht h => J.vcSym1 t ht.1 h runVcpu := fun t ht h => J.runVcpu t ht.1 h diff --git a/proofs/Fl4ProofsA64/P3/UtDropVsUniqA.lean b/proofs/Fl4ProofsA64/P3/UtDropVsUniqA.lean new file mode 100644 index 000000000..e0c3530dc --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtDropVsUniqA.lean @@ -0,0 +1,159 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`): **`VsUniqA` across the retype's drop** (`utDrop_vsUniqA`): the sets filtered +by `D`, the spec state `detype D σ`, FL4's memory unchanged. From **`UtVsClosA`** (nothing reachable from the ASID table +refers into `D`): roots and walks survive; every other field is monotone. No named premise. New module. +-/ +import Fl4ProofsA64.P3.UtDropVsA +import Fl4ProofsA64.P3.UtDropJ57A +import Fl4ProofsA64.P3.VsUniqShrinkA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Classical + +local notation "wa" => core.num.U64.wrapping_add + +variable {D : Set Fl4SpecA64.ObjRef} {th : TypedHeapA} {Pp Tb Y X T2 : Set U64} {Sh2 Lv : U64 → Nat} + {mem : U64 → U64} {ksb : U64} {σ : Fl4SpecA64.State Unit} + +/-- An entry installed in the spec's ASID table at a tracked pool survives the drop, with its root. -/ +theorem utAsidEnt_upA (R : VsRelA Pp Tb Lv X Y mem ksb σ) (C : UtVsClosA D Pp Tb Y X T2 Sh2 mem ksb σ) + {asid : Fl4SpecA64.Asid} {p r : U64} {f : Fl4SpecA64.AsidPool} (hp : p ∈ Pp) + (htab : σ.archState.armAsidTable (Fl4SpecA64.asidHighBitsOf asid) = some (specPtr p)) + (hk : σ.kheap (specPtr p) = some (.archObj (.asidPool f))) + (hf : f (Fl4SpecA64.asidLowBitsOf asid) = some (.asidPoolVSpace (specPtr r))) : + specPtr p ∉ D ∧ specPtr r ∉ D := by + obtain ⟨hi, hiv⟩ : ∃ hi : U64, hi.val = (Fl4SpecA64.asidHighBitsOf asid).toNat := + ⟨⟨BitVec.ofNat 64 (Fl4SpecA64.asidHighBitsOf asid).toNat⟩, by + show (BitVec.ofNat 64 _).toNat = _ + rw [BitVec.toNat_ofNat] + exact Nat.mod_eq_of_lt (lt_trans (Fl4SpecA64.asidHighBitsOf asid).isLt (by norm_num))⟩ + have hi128 : hi.val < 128 := by rw [hiv]; exact (Fl4SpecA64.asidHighBitsOf asid).isLt + have ht := R.table hi hi128 + rw [hiv, BitVec.ofNat_toNat, BitVec.setWidth_eq, htab] at ht + unfold optPtrA at ht + split_ifs at ht with h0 + have hw : mem (atAF ksb hi) = p := (specPtr_inj (Option.some.inj ht)).symm + have hpD : specPtr p ∉ D := by rw [← hw]; exact C.tpool hi hi128 h0 + refine ⟨hpD, ?_⟩ + have hact : ActivePoolA mem ksb p := ⟨hw ▸ h0, hi, hi128, hw⟩ + obtain ⟨lo, lov⟩ : ∃ lo : U64, lo.val = (Fl4SpecA64.asidLowBitsOf asid).toNat := + ⟨⟨BitVec.ofNat 64 (Fl4SpecA64.asidLowBitsOf asid).toNat⟩, by + show (BitVec.ofNat 64 _).toNat = _ + rw [BitVec.toNat_ofNat] + exact Nat.mod_eq_of_lt (lt_trans (Fl4SpecA64.asidLowBitsOf asid).isLt (by norm_num))⟩ + have lo512 : lo.val < 512 := by rw [lov]; exact (Fl4SpecA64.asidLowBitsOf asid).isLt + obtain ⟨f', hk', hf'⟩ := R.pool p hp + rw [hk] at hk' + cases hk' + have e := hf' hact lo lo512 + rw [lov, BitVec.ofNat_toNat, BitVec.setWidth_eq, hf] at e + unfold poolEntA at e + split_ifs at e with h1 + have hr : r = untagA (mem (peAF p lo)) := specPtr_inj (by injection (Option.some.inj e)) + rw [hr] + exact C.ent p hp hpD hact lo lo512 h1 + +theorem utS2RootOfAsid_upA (R : VsRelA Pp Tb Lv X Y mem ksb σ) (C : UtVsClosA D Pp Tb Y X T2 Sh2 mem ksb σ) + {asid r : U64} (h : S2RootOfAsidA Pp X σ asid r) : + S2RootOfAsidA (dropSetA D Pp) (dropSetA D X) (Fl4SpecA64.detype D σ) asid r ∧ specPtr r ∉ D := by + obtain ⟨hr, p, f, h0, hp, htab, hk, hf⟩ := h + obtain ⟨hpD, hrD⟩ := utAsidEnt_upA R C hp htab hk hf + exact ⟨⟨⟨hr, hrD⟩, p, f, h0, ⟨hp, hpD⟩, htab, (detype_keptA σ hpD).trans hk, hf⟩, hrD⟩ + +theorem utS2RootOfAsid_dropA {asid r : U64} + (h : S2RootOfAsidA (dropSetA D Pp) (dropSetA D X) (Fl4SpecA64.detype D σ) asid r) : + S2RootOfAsidA Pp X σ asid r := by + obtain ⟨hr, p, f, h0, hp, htab, hk, hf⟩ := h + exact ⟨hr.1, p, f, h0, hp.1, htab, (detype_someA.1 hk).2, hf⟩ + +theorem utS2Entry_dropA {w : U64} + (h : S2EntryA (dropSetA D Pp) (dropSetA D X) (dropSetA D T2) Sh2 mem (Fl4SpecA64.detype D σ) w) : + S2EntryA Pp X T2 Sh2 mem σ w := by + rcases h with ⟨r, i, hr, hi, e⟩ | ⟨t, i, hr, ht, h12, hi, e⟩ + · exact Or.inl ⟨r, i, utActiveS2_dropA hr, hi, e⟩ + · exact Or.inr ⟨t, i, utS2Reach_dropA hr, ht.1, h12, hi, e⟩ + +/-- A Stage-2 walk from a retained table stays in retained tables. -/ +theorem utWalk2_upA (E : ExtVsRelA Pp Tb X Y T2 Sh2 mem σ) (C : UtVsClosA D Pp Tb Y X T2 Sh2 mem ksb σ) + {va t w : U64} {sh n : Nat} (W : WalkSlotA (· ∈ T2) mem va t sh n w) + (ht : S2WalkTabA Pp X T2 Sh2 mem σ t sh n) (htD : specPtr t ∉ D) : + WalkSlotA (· ∈ dropSetA D T2) mem va t sh n w := by + revert ht htD + induction W with + | here t sh n => intro _ _; exact .here t sh n + | @down t sh n w h3 h12 hc W' ih => + intro ht htD + have hn := ht.n_pos + have hi := walkIdx_lt va sh n hn.1 hn.2 + obtain ⟨ht', -⟩ := S2WalkTabA.step E ht hi h3 h12 hc + obtain ⟨b0, b1⟩ := (and3_bits_sh _).1 h3 + have hcD : specPtr (dTabA (mem (peAF t (walkIdx va sh n)))) ∉ D := by + rcases ht with ⟨ha, rfl, rfl⟩ | ⟨htT, hr, rfl, rfl⟩ + · have := s2Top1k + exact C.s2root t ha htD _ (by omega) hi b0 b1 hc + · exact C.s2pt t hr htT h12 _ hi b0 b1 hc + exact .down t sh n w h3 h12 ⟨hc, hcD⟩ (ih ht' hcD) + +/-- A Stage-1 / window walk from a reached table stays in retained tables. -/ +theorem utWalk1_upA (R : VsRelA Pp Tb Lv X Y mem ksb σ) (C : UtVsClosA D Pp Tb Y X T2 Sh2 mem ksb σ) + {va t w : U64} {sh n : Nat} (W : WalkSlotA (S1TabA Tb Y) mem va t sh n w) (hn : n = 512) + (ht : ∃ tag, (tag = 0#u64 ∨ tag = 2#u64) ∧ VsPathA Pp Tb Y mem ksb tag sh t) (htb : S1TabA Tb Y t) : + WalkSlotA (S1TabA (dropSetA D Tb) (dropSetA D Y)) mem va t sh n w := by + revert hn ht htb + induction W with + | here t sh n => intro _ _ _; exact .here t sh n + | @down t sh n w h3 h12 hc W' ih => + intro hn ht htb + subst hn + have hi := walkIdx_lt va sh 512 (by norm_num) (by norm_num) + obtain ⟨tag, htag, hp⟩ := ht + have hcTb := R.child_tb hp htb h12 hi h3 + obtain ⟨b0, b1⟩ := (and3_bits_sh _).1 h3 + have hcD := C.tab tag sh t htag hp h12 htb _ hi b0 b1 hcTb + exact .down t sh 512 w h3 h12 (Or.inl ⟨hcTb, hcD⟩) (ih rfl ⟨tag, htag, .child hp htb h12 hi h3⟩ hc) + +/-- An installed Stage-1 / window root word survives the drop; its root is retained. -/ +theorem utActiveAsid_upA (C : UtVsClosA D Pp Tb Y X T2 Sh2 mem ksb σ) {asid raw : U64} + (h : ActiveAsidRootA mem ksb Pp asid raw) : + ActiveAsidRootA mem ksb (dropSetA D Pp) asid raw ∧ specPtr (untagA raw) ∉ D := by + obtain ⟨hi, lo, h1, h2, h3, pool, hp, h0, hm, hr, hr0⟩ := h + have hpD : specPtr pool ∉ D := by rw [← hm]; exact C.tpool hi h1 (hm ▸ h0) + refine ⟨⟨hi, lo, h1, h2, h3, pool, ⟨hp, hpD⟩, h0, hm, hr, hr0⟩, ?_⟩ + rw [← hr] + exact C.ent pool hp hpD ⟨h0, hi, h1, hm⟩ lo h2 (hr ▸ hr0) + +theorem utDrop_vsUniqA (R : VsRelA Pp Tb Lv X Y mem ksb σ) (E : ExtVsRelA Pp Tb X Y T2 Sh2 mem σ) + (C : UtVsClosA D Pp Tb Y X T2 Sh2 mem ksb σ) (U : VsUniqA th Pp Tb X Y T2 Sh2 mem ksb σ) : + VsUniqA (dropThA D th) (dropSetA D Pp) (dropSetA D Tb) (dropSetA D X) (dropSetA D Y) (dropSetA D T2) Sh2 mem + ksb (Fl4SpecA64.detype D σ) where + t2 y hy ptr asid va hcap hT w hw h3 hd := by + obtain ⟨r, hr, hws⟩ := U.t2 y (utIsSlot_dropA hy) ptr asid va hcap hT.1 w (utS2Entry_dropA hw) h3 hd + obtain ⟨hr', hrD⟩ := utS2RootOfAsid_upA R C hr + exact ⟨r, hr', utWalk2_upA E C hws (Or.inl ⟨hr.active, rfl, rfl⟩) hrD⟩ + s1 y hy ptr asid va hcap hS tag sh t i hpath htab h12 hi h3 hd := by + have htab' : S1TabA Tb Y t := htab.imp And.left fun ⟨y, hy, e⟩ => ⟨y, hy.1, e⟩ + obtain ⟨raw, hact, hw⟩ := U.s1 y (utIsSlot_dropA hy) ptr asid va hcap hS.1 tag sh t i (utVsPath_dropA hpath) htab' + h12 hi h3 hd + obtain ⟨hact', hrD⟩ := utActiveAsid_upA C hact + refine ⟨raw, hact', ?_⟩ + rcases hw with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · rw [untagA_of h0] at hrD + exact Or.inl ⟨h0, ⟨hr, hrD⟩, utWalk1_upA R C hws rfl ⟨0#u64, Or.inl rfl, .native hact h0 hr⟩ (Or.inl hr)⟩ + · exact Or.inr ⟨h2, ⟨hy2, hrD⟩, utWalk1_upA R C hws rfl ⟨2#u64, Or.inr rfl, .high hact h2 hy2⟩ + (Or.inr ⟨untagA raw, hy2, rfl⟩)⟩ + out y hy ptr asid va hcap h := U.out y (utIsSlot_dropA hy) ptr asid va hcap h.1 + inj2 w1 w2 h1 h2 v1 v2 e hT := + U.inj2 w1 w2 (utS2Entry_dropA h1) (utS2Entry_dropA h2) v1 v2 e hT.1 + rootInj2 a1 a2 r h1 h2 := U.rootInj2 a1 a2 r (utS2RootOfAsid_dropA h1) (utS2RootOfAsid_dropA h2) + inj1 tag tag' sh sh' t t' i i' p1 b1 s1 i1 v1 p2 b2 s2 i2 v2 e hT := + U.inj1 tag tag' sh sh' t t' i i' (utVsPath_dropA p1) (b1.imp And.left fun ⟨y, hy, e⟩ => ⟨y, hy.1, e⟩) s1 i1 v1 + (utVsPath_dropA p2) (b2.imp And.left fun ⟨y, hy, e⟩ => ⟨y, hy.1, e⟩) s2 i2 v2 e hT.1 + rootInj1 a1 a2 raw h1 h2 := U.rootInj1 a1 a2 raw (utActiveAsid_dropA h1) (utActiveAsid_dropA h2) + rootOnce y hy r h := + let ⟨hn, hu⟩ := U.rootOnce y (utIsSlot_dropA hy) r h + ⟨fun hi => hn (hi.imp (fun ⟨a, raw, h, e⟩ => ⟨a, raw, utActiveAsid_dropA h, e⟩) + (fun ⟨a, h⟩ => ⟨a, utS2RootOfAsid_dropA h⟩)), fun z hz hk => hu z (utIsSlot_dropA hz) hk⟩ + ptOnce y hy r h z hz hk := U.ptOnce y (utIsSlot_dropA hy) r h z (utIsSlot_dropA hz) hk + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtFullJ5A.lean b/proofs/Fl4ProofsA64/P3/UtFullJ5A.lean index c8b5e9520..361a39009 100644 --- a/proofs/Fl4ProofsA64/P3/UtFullJ5A.lean +++ b/proofs/Fl4ProofsA64/P3/UtFullJ5A.lean @@ -35,10 +35,12 @@ theorem utRt_j5LoopA (hA : P0.ArchTotal ar) {H1 : Heap} {Cs Sg OS1 : Set U64} {s {par : U64 → Option U64} (hT : TreeA st OS1 G par s1) (hI : MdbInvA st G par s1) (hR : Fl4ProofsA64.P1.W7.R.ST.IrqRunA st G s1) (hrev : Fl4ProofsA64.P1.W7.R.ST.revA st s1 slot = true) (a1 : A) : untyped.retype st ar s1 a1 slot false aligned nt us dest off win dev ⦃ r => - MdbInvA st (utGA slot (djA dest off) G win.val) (utPA slot (djA dest off) par win.val) r.2.1 ∧ + (MdbInvA st (utGA slot (djA dest off) G win.val) (utPA slot (djA dest off) par win.val) r.2.1 ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st (utGA slot (djA dest off) G win.val) r.2.1 ∧ (∀ y ∈ (utGA slot (djA dest off) G win.val).flatten, ∀ k, capA st r.2.1 y = .IrqHandler k → - y ∈ G.flatten ∧ capA st s1 y = .IrqHandler k) ⦄ := by + y ∈ G.flatten ∧ capA st s1 y = .IrqHandler k)) ∧ + (∀ y ∈ OS1, (∀ j, j < win.val → y ≠ djA dest off j) → + Fl4ProofsA64.P1.W7.R.ST.revA st r.2.1 y = Fl4ProofsA64.P1.W7.R.ST.revA st s1 y) ⦄ := by obtain ⟨hdev, hal, hfi, hA0, hAw, hinj, hcan, -⟩ := C.ar obtain ⟨hSA, -, hK1⟩ := C.stz obtain ⟨-, -, hV1, hUZ1, -⟩ := hSA diff --git a/proofs/Fl4ProofsA64/P3/UtJ5LoopA.lean b/proofs/Fl4ProofsA64/P3/UtJ5LoopA.lean index 51b0ead25..cd19992ca 100644 --- a/proofs/Fl4ProofsA64/P3/UtJ5LoopA.lean +++ b/proofs/Fl4ProofsA64/P3/UtJ5LoopA.lean @@ -484,10 +484,12 @@ theorem utRetype_j5A (hO : OSOK T Ω Sg OS) {G : List (List U64)} {par : U64 → (hinj : ∀ j l, j < len.val → l < len.val → djA dcn off j = djA dcn off l → j = l) (hcan : ∀ j, j < len.val → CapRt.Canonical (bjA base (zA nt.val us) j)) (hus : us.val < 64) : untyped.retype st ar s a src false base nt us dcn off len device ⦃ r => - MdbInvA st (utGA src (djA dcn off) G len.val) (utPA src (djA dcn off) par len.val) r.2.1 ∧ + (MdbInvA st (utGA src (djA dcn off) G len.val) (utPA src (djA dcn off) par len.val) r.2.1 ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st (utGA src (djA dcn off) G len.val) r.2.1 ∧ (∀ y ∈ (utGA src (djA dcn off) G len.val).flatten, ∀ k, capA st r.2.1 y = .IrqHandler k → - y ∈ G.flatten ∧ capA st s y = .IrqHandler k) ⦄ := by + y ∈ G.flatten ∧ capA st s y = .IrqHandler k)) ∧ + (∀ y ∈ OS, (∀ j, j < len.val → y ≠ djA dcn off j) → + Fl4ProofsA64.P1.W7.R.ST.revA st r.2.1 y = Fl4ProofsA64.P1.W7.R.ST.revA st s y) ⦄ := by have hU := hT.ut have hM := hT.lk set z := zA nt.val us with hzdef @@ -595,8 +597,13 @@ theorem utRetype_j5A (hO : OSOK T Ω Sg OS) {G : List (List U64)} {par : U64 → hZ0 s1 (by obtain ⟨-, -, -, -, -, hW⟩ := h1.facts hO hsrc; exact hW)⟩ rw [utPA_zero] exact ⟨Or.inl, fun h => h.elim id fun ⟨j, hj, _⟩ => absurd hj (Nat.not_lt_zero j)⟩ - rintro r ⟨-, s1, h1, ⟨hM', -, -, k1, k2, -⟩, hI', hR', -⟩ - refine ⟨hI', hR', fun y hy k e => ?_⟩ + rintro r ⟨-, s1, h1, ⟨hM', -, -, k1, k2, -, h4, -⟩, hI', hR', -⟩ + obtain ⟨nfi, -, h1c, h1k, h1l, -⟩ := h1.facts hO hsrc + have rv : ∀ y ∈ OS, (∀ j, j < len.val → y ≠ djA dcn off j) → + Fl4ProofsA64.P1.W7.R.ST.revA st r.2.1 y = Fl4ProofsA64.P1.W7.R.ST.revA st s y := fun y hy nd => by + unfold Fl4ProofsA64.P1.W7.R.ST.revA + rw [show (281474976710656#u64 : U64) = RVB from rfl, h4 y hy nd, (h1l y hy).2] + refine ⟨⟨hI', hR', fun y hy k e => ?_⟩, rv⟩ obtain ⟨nfi, -, h1c, h1k, -, -⟩ := h1.facts hO hsrc obtain ⟨yOS, -⟩ := (hM'.members y).1 hy by_cases ex : ∃ j, j < len.val ∧ y = djA dcn off j diff --git a/proofs/Fl4ProofsA64/P3/UtMakePoolA.lean b/proofs/Fl4ProofsA64/P3/UtMakePoolA.lean index 033573490..3b5f68581 100644 --- a/proofs/Fl4ProofsA64/P3/UtMakePoolA.lean +++ b/proofs/Fl4ProofsA64/P3/UtMakePoolA.lean @@ -167,11 +167,26 @@ theorem makePool_perform_dropA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (.spec (.invokeASIDControl (.makePool (specPtr frame) dest parent (asidOfA base))))).run σ1).1 ∧ ∃ Z' : XSetsA, res = (.Ok (), res.2.1, a) ∧ - Z'.Pp = insert frame (dropSetA (utDA frame 12) Z.Pp) ∧ + Z' = { dropZA (utDA frame 12) Z with Pp := insert frame (dropZA (utDA frame 12) Z).Pp, G := Z'.G } ∧ JAtZAX (L := L) AR Z' res.2.1 a σ' (dropMA (utDA frame 12) m) ∧ TreeA st (dropSetA (utDA frame 12) OS) Z'.G.chains Z'.G.par res.2.1 ∧ (CarryA (dropZA (utDA frame 12) Z) (L.mem s) (detype (utDA frame 12) σ) → - CarryA Z' (L.mem res.2.1) σ') ⦄ := by + CarryA Z' (L.mem res.2.1) σ') ∧ + -- (vsx-D D1) what the full-record lift needs: the dropped record, its decode site, the dead-drop + -- fact, the slots, and MakePool's exposed footprint/spec shape from the dropped restart state + JStage3A st AR (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H) (dropSetA (utDA frame 12) OS) U Ac + (dropSetA (utDA frame 12) Pp) Tb Lv ia ie (dropSetA (utDA frame 12) N) (dropSetA (utDA frame 12) E) + (dropSetA (utDA frame 12) Rp) (dropBfA (utDA frame 12) Bf) stack κ n (J5A st) + (J7A st (J7R2A st ar nA)) s a (detype (utDA frame 12) σ) (dropMA (utDA frame 12) m) ∧ + RsSiteA (L := L) (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H) (dropSetA (utDA frame 12) OS) Ac + (dropSetA (utDA frame 12) Pp) Tb Lv s ∧ + DeadDrop4KA (dropZA (utDA frame 12) Z) (dropHA (utDA frame 12) H) frame fi ∧ + AbsSlotA (dropThA (utDA frame 12) Z.th) parent ∧ AbsSlotA (dropThA (utDA frame 12) Z.th) dest ∧ + MakePoolExpoA st (dropHA (utDA frame 12) H) (dropSetA (utDA frame 12) OS) s res.2.1 + (detype (utDA frame 12) σ1) σ' parent dest frame i base ∧ + -- (group J5) J5's MDB facts at the grown ghost + (MdbInvA st Z'.G.chains Z'.G.par res.2.1 ∧ Fl4ProofsA64.P1.W7.R.ST.IrqRunA st Z'.G.chains res.2.1 ∧ + HandlersActiveA st Z'.G.chains res.2.1) ⦄ := by have e12 : (12#u64 : U64).val = 12 := rfl have hcap : obj.Slot.cap st (cslotAddrA parent) s = ok (.Untyped frame 12#u64 fi false) := by rw [capA_eq, hcp] have C := utDropC_of J Dp P hcap hnc RS.sym (by rw [e12]; exact othT) (by rw [e12]; exact othC) hn @@ -281,7 +296,7 @@ theorem makePool_perform_dropA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (fun y hy => hcO y hy.1) (parent := parent) (dest := dest) (frame := frame) (fi := fi) (i := i) (base := base) hAp' hAd' hcp hnc hcd hi hfree hbase hD refine WP.spec_mono main fun res h => ?_ - obtain ⟨σ1d, hst, σ', rv, hrun, Z', hres, hPp, hJ, hTree, hC⟩ := h + obtain ⟨σ1d, hst, σ', rv, hrun, Z', hres, hPp, hJ, hTree, hC, hX⟩ := h -- the spec's restart on both records have curK : σ.curThread ∉ utDA frame 12 := C.curThread obtain ⟨Rp0, Nt0, extra0, sp0, hP0⟩ := RS.pl @@ -302,9 +317,11 @@ theorem makePool_perform_dropA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] rw [h3, exT] exact ut_detype_updA curK _ have eD : utDA frame 12 = {x | specPtr frame ≤ x ∧ x ≤ specPtr frame + 2 ^ pageBits - 1} := rfl - refine ⟨_, hst0, σ', rv, ?_, Z', hres, hPp, hJ, hTree, hC⟩ - rw [eσ, eD, ut_makePool_dropA] at hrun - exact hrun + refine ⟨_, hst0, σ', rv, ?_, Z', hres, hPp, hJ, hTree, hC, J', RS', hD, hAp', hAd', ?_⟩ + · rw [eσ, eD, ut_makePool_dropA] at hrun + exact hrun + · rw [eσ] at hX + exact ⟨hX.1, hX.2 J'.j5.1⟩ end diff --git a/proofs/Fl4ProofsA64/P3/UtPpHookA.lean b/proofs/Fl4ProofsA64/P3/UtPpHookA.lean index 7b3a156de..44c2ab80f 100644 --- a/proofs/Fl4ProofsA64/P3/UtPpHookA.lean +++ b/proofs/Fl4ProofsA64/P3/UtPpHookA.lean @@ -8,7 +8,7 @@ P3 (aarch64, A64-P3 Untyped, J8): **the preemption point's loop hook for the res * **`utPp_hookA`**: `PPHypUtA` for `R := UtRstInvA ∧ UtPpTimeA`. Named premises (each over every state of `R`): -* [J] `hvp`: no VSpace word of `Pp ∪ Tb`, and no ASID-table word, is a preemption-point word. +* [J] `hvp`: no VSpace word of `utVsPtA` (Pp, Tb), and no ASID-table word, is a preemption-point word. * [P] `hC` (executor 49, ruling 13:24Z: the raw counter oracle is monotone; `CounterStepA` itself is carried in `UtPpTimeA.cs`, it was an over-quantified `∀ σ, ValidMachineTimeA σ → CounterStepA σ`), `hNow` (the raw counter read is `getCurrentTime`), `hAr` (the arch relation after the timestamp), `hirq` (`irq_pending` is an outcome of `getActiveIRQ true`; it keeps the spec memory, the last machine @@ -110,7 +110,8 @@ theorem utPp_hookA (ar : machine.Arch A) (hnd : numDomains = 1) {Clock : A → M (P : NowAgreeA ar Clock) (hvp : ∀ (s : S) (a : A) (σ : State Unit), 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, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ ¬ PPW st s b) + SActA σ → (∀ u, σ.schedulerAction ≠ .switchThread u) → + ∀ b, VsR (L.ksb s) (utVsPtA st Pp Tb Lv s) 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 ⦄) @@ -128,13 +129,13 @@ theorem utPp_hookA (ar : machine.Arch A) (hnd : numDomains = 1) {Clock : A → M UtPpTimeA Clock a σ) := by refine preemption_point_refinesA OS _ hnd ?_ ?_ ?_ ?_ ?_ · rintro s a σ v s1 ⟨I, T⟩ h - have hv : ∀ b, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ b ≠ wa (L.ksb s) layout.ks.WORK_UNITS := fun b hb => - ⟨(hvp s a σ I.rec_ b hb).1, fun e => (hvp s a σ I.rec_ b hb).2 (Or.inl e)⟩ + have hv : ∀ b, VsR (L.ksb s) (utVsPtA st Pp Tb Lv s) b → Aligned b ∧ b ≠ wa (L.ksb s) layout.ks.WORK_UNITS := fun b hb => + ⟨(hvp s a σ I.rec_ I.sact I.noSwitch b hb).1, fun e => (hvp s a σ I.rec_ I.sact I.noSwitch b hb).2 (Or.inl e)⟩ obtain ⟨I1, k⟩ := I.workUnitsA hv h exact ⟨⟨I1, T⟩, k⟩ · rintro s a σ ⟨I, T⟩ have har : AR a Z.hw := I.rec_.j.1.ar - refine WP.spec_mono (I.timestampA (hvp s a σ I.rec_) P T.clk hnd T.valid T.cs T.cur T.off T.act (hNow σ) + refine WP.spec_mono (I.timestampA (hvp s a σ I.rec_ I.sact I.noSwitch) P T.clk hnd T.valid T.cs T.cur T.off T.act (hNow σ) (hAr s a har)) ?_ rintro r ⟨σ1, h1, I1, k, v, c, o, ac, cl⟩ obtain ⟨now, -, e⟩ : ∃ now : Ticks, True ∧ diff --git a/proofs/Fl4ProofsA64/P3/UtPpTsA.lean b/proofs/Fl4ProofsA64/P3/UtPpTsA.lean index db19ee5d3..3cb635d80 100644 --- a/proofs/Fl4ProofsA64/P3/UtPpTsA.lean +++ b/proofs/Fl4ProofsA64/P3/UtPpTsA.lean @@ -11,7 +11,7 @@ Named premises: returned again after the step. * [P] `P`, `hClock` (the clock relation), `C` (`CounterStepA`), `hNow` (the raw counter read is the spec's `getCurrentTime`), `hAr` (the arch relation after the timestamp), `hnd` (one domain). -* [J] `hvp`: no VSpace word of `Pp ∪ Tb`, and no ASID-table word, is a preemption-point word. +* [J] `hvp`: no VSpace word of `utVsPtA` (Pp, Tb), and no ASID-table word, is a preemption-point word. New theorems only. -/ @@ -48,7 +48,7 @@ set_option maxHeartbeats 2000000 in /-- **`preemption_point_refinesA`'s `hTs`** (module docstring). -/ theorem UtRstInvA.timestampA {ar : machine.Arch A} {p sb x i : U64} (I : UtRstInvA (ar := ar) st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n nA m p sb x Rq Nt ex s a σ i) - (hvp : ∀ b, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ ¬ PPW st s b) + (hvp : ∀ b, VsR (L.ksb s) (utVsPtA st Pp Tb Lv s) 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) @@ -61,7 +61,7 @@ theorem UtRstInvA.timestampA {ar : machine.Arch A} {p sb x i : U64} have E0 := J.yieldQueueA refine WP.spec_mono (WP.spec_and (WP.spec_and (WP.spec_and (update_timestamp_refinesA E0 a P hClock hnd V C CI R Act) (update_timestamp_wordsA E0.sched.toSchedSRN a P hClock)) hAr) - ((J.toTA I.sact I.noSwitch).timestampA (fun b hb => hvp b (hb.imp (ptw_mono utVsPtA_sub) id)) P hClock hnd V C hNow + ((J.toTA I.sact I.noSwitch).timestampA hvp P hClock hnd V C hNow (CurEntryGA.of_cur CI R J.sr.inv) hAr)) ?_ rintro ⟨s', a'⟩ ⟨⟨⟨⟨τ, hτ, E1, hCl, V1, CI1, R1, Act1, -, -, F⟩, now, -, -, es⟩, har⟩, σT, memT, JT, -, -, -⟩ dsimp only at hτ E1 hCl F es har memT JT ⊢ diff --git a/proofs/Fl4ProofsA64/P3/UtPpWuA.lean b/proofs/Fl4ProofsA64/P3/UtPpWuA.lean index 7e3375fdf..b5856e462 100644 --- a/proofs/Fl4ProofsA64/P3/UtPpWuA.lean +++ b/proofs/Fl4ProofsA64/P3/UtPpWuA.lean @@ -45,7 +45,7 @@ theorem JStage3A.of_workUnitsA (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) (P : SysPlace st H Z.Cs H.frame Rq Nt OS s ex x) (Y : SymL st H Z.Cs s) (hrun : Runnable (L.mem s (stA (L.curW s)))) - (hvw : ∀ b, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ b ≠ wa (L.ksb s) layout.ks.WORK_UNITS) (v : U64) : + (hvw : ∀ b, VsR (L.ksb s) (utVsPtA st Pp Tb Lv s) b → Aligned b ∧ b ≠ wa (L.ksb s) layout.ks.WORK_UNITS) (v : 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 nA)) (L.wr s (wa (L.ksb s) layout.ks.WORK_UNITS) v) a σ m ∧ SymL st H Z.Cs (L.wr s (wa (L.ksb s) layout.ks.WORK_UNITS) v) ∧ @@ -77,7 +77,7 @@ theorem JStage3A.of_workUnitsA exact ⟨h1, h2⟩ obtain ⟨sysl2, Y2⟩ := SysL.dfB P J.sys.ent.bxi hrun hKo (fun b e => by rw [e]; exact ⟨hΩ, hnS⟩) hBo J.sys.sysl Y d -- the record without `SysL` across the write is the shared module's - have T := (J.toTA sact noSwitch).workUnitsA (fun b hb => hvw b (hb.imp (ptw_mono utVsPtA_sub) id)) v + have T := (J.toTA sact noSwitch).workUnitsA hvw v rw [← ewu] at T have X := utTA_extraA J T.1 rfl have K6 := utRec6_keepA J (s' := L.wr s wu v) (σ' := σ) (fun u hu => T.2.capA hu) rfl @@ -105,7 +105,7 @@ theorem JStage3A.of_workUnitsA /-- **The reset loop's invariant across the `WORK_UNITS` write** (`preemption_point_refinesA`'s `hW`). -/ theorem UtRstInvA.workUnitsA {p sb x : U64} {i : U64} {s s1 : S} {a : A} {σ : State Unit} (I : UtRstInvA (ar := ar) st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n nA m p sb x Rq Nt ex s a σ i) - (hvw : ∀ b, VsR (L.ksb s) (Pp ∪ Tb) b → Aligned b ∧ b ≠ wa (L.ksb s) layout.ks.WORK_UNITS) {v : U64} + (hvw : ∀ b, VsR (L.ksb s) (utVsPtA st Pp Tb Lv s) b → Aligned b ∧ b ≠ wa (L.ksb s) layout.ks.WORK_UNITS) {v : U64} (h : obj.ks_set st s layout.ks.WORK_UNITS v = ok s1) : UtRstInvA (ar := ar) st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n nA m p sb x Rq Nt ex s1 a σ i ∧ ∀ y ∈ OS, capA st s1 y = capA st s y := by diff --git a/proofs/Fl4ProofsA64/P3/UtPreCarryA.lean b/proofs/Fl4ProofsA64/P3/UtPreCarryA.lean new file mode 100644 index 000000000..067e9b52a --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtPreCarryA.lean @@ -0,0 +1,148 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line prst): **what the preempted Untyped reset carries through the chunk loop**. + +* `UtPreKeepA σ0 σ`: the spec frame without the time fields: current thread, current SC, scheduler action, ready and + release queues, the current thread's TCB and the current SC. Kept by a CNode write (`UtCnStepA`), by the preemption + point (`preemptionPoint_casesA`) and obtained from `delete_objects` (`UtKeepCurA`). +* `utPre_ppA`: the preemption point's loop hook with `UtPreKeepA` added to the carried predicate. +* `utPre_startA`: at the state after `delete_objects`, from the syscall-entry record: `UtPreKeepA` and the preemption + point's timing facts (`UtPpTimeA`). + +Named premises: [P] `hnd` (one domain), `hNow` (the raw counter read is `getCurrentTime`); [P] `hFr` (the clock +relation reads the time state and the last machine time only). New definitions and theorems only. +-/ +import Fl4ProofsA64.P3.UtPpHookA +import Fl4ProofsA64.P3.UtKeepCurA +import Fl4ProofsA64.P3.Stage3DelBodyLoopA +import Fl4ProofsA64.P3.Stage3SyscallA + +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 + +/-- **The spec frame of a preempted reset** (module docstring). -/ +structure UtPreKeepA (σ0 σ : State Unit) : Prop where + cur : σ.curThread = σ0.curThread + csc : σ.curSc = σ0.curSc + act : σ.schedulerAction = σ0.schedulerAction + rq : σ.readyQueues = σ0.readyQueues + rls : σ.releaseQueue = σ0.releaseQueue + tcb : ∀ x, σ0.kheap σ0.curThread = some (.tcb x) → σ.kheap σ0.curThread = some (.tcb x) + sc : ∀ y k, σ0.kheap σ0.curSc = some (.schedContext y k) → σ.kheap σ0.curSc = some (.schedContext y k) + +theorem UtPreKeepA.ofKeepCur {σ0 σ : State Unit} (K : UtKeepCurA σ0 σ) : UtPreKeepA σ0 σ := + ⟨K.glob.cur, K.glob.csc, K.glob.act, K.glob.rq, K.glob.rls, K.tcb, K.sc⟩ + +theorem UtPreKeepA.cnStep {σ0 σ σ' : State Unit} (K : UtPreKeepA σ0 σ) (H : UtCnStepA σ σ') : UtPreKeepA σ0 σ' := + ⟨H.cur.trans K.cur, H.csc.trans K.csc, H.act.trans K.act, H.rq.trans K.rq, H.rls.trans K.rls, + fun x h => H.keep (K.tcb x h) (fun _ _ e => by cases e), + fun y k h => H.keep (K.sc y k h) (fun _ _ e => by cases e)⟩ + +/-- The preemption point keeps the frame, whatever its outcome. -/ +theorem UtPreKeepA.ppStep {σ0 σ σ' : State Unit} {e : Except Unit Unit} (K : UtPreKeepA σ0 σ) (hnd : numDomains = 1) + (hNow : fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) + (h : (e, σ') ∈ ((preemptionPoint (Z := Unit)).run σ).1) : UtPreKeepA σ0 σ' := by + rcases preemptionPoint_casesA hnd hNow h with ⟨-, e'⟩ | ⟨T, -⟩ + · rw [e']; exact K + · exact ⟨T.cur.trans K.cur, T.csc.trans K.csc, T.act.trans K.act, T.rq.trans K.rq, T.rel.trans K.rls, + fun x hx => by rw [T.kheap]; exact K.tcb x hx, fun y k hy => by rw [T.kheap]; exact K.sc y k hy⟩ + +section +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} {ar : machine.Arch A} + +/-- **The preemption point's hook with the frame carried** (module docstring). -/ +theorem utPre_ppA {OS : Set U64} {R : S → A → State Unit → Prop} {Clock : A → MachineState → Prop} + {σ0 : State Unit} (hnd : numDomains = 1) + (hNow : ∀ σ : State Unit, fl4ReadRawCounter σ.machineState = getCurrentTime σ.machineState) + (h : PPHypUtA st ar OS (fun s a σ => R s a σ ∧ UtPpTimeA Clock a σ) (fun s a σ => R s a σ ∧ UtPpTimeA Clock a σ)) : + PPHypUtA st ar OS (fun s a σ => R s a σ ∧ (UtPpTimeA Clock a σ ∧ UtPreKeepA σ0 σ)) + (fun s a σ => R s a σ ∧ (UtPpTimeA Clock a σ ∧ UtPreKeepA σ0 σ)) := by + rintro s a σ ⟨hR, hT, hK⟩ + refine WP.spec_mono (h s a σ ⟨hR, hT⟩) ?_ + rintro r ⟨hc, σ', g⟩ + refine ⟨hc, σ', ?_⟩ + rcases g with ⟨e, mem, hR', hT'⟩ | ⟨e, mem, hR', hT'⟩ + · exact Or.inl ⟨e, mem, hR', hT', hK.ppStep hnd (hNow σ) mem⟩ + · exact Or.inr ⟨e, mem, hR', hT', hK.ppStep hnd (hNow σ) mem⟩ + +variable {AR : A → HwRootA → Prop} {Z Z' : XSetsA} {H H' : Heap} {OS OS' U U' Ac Ac' Pp Pp' Tb Tb' : Set U64} + {Lv Lv' : U64 → Nat} {ia ie ia' ie' : Nat} {N N' E E' Rp Rp' : Set U64} {Bf Bf' : Set (U64 × Fl4SpecA64.Word)} + {stack stack' : U64 → List U64} {κ κ' : U64 → U64} {n n' : Nat} {J5 J7 J5' J7' : JSlotA S} {s s' : S} {a a' : A} + {σ : State Unit} {m m' : McState} + +/-- **The frame and the timing facts after `delete_objects`**, from the entry record `J` and the record `J2` over the +dropped sets. -/ +theorem utPre_startA (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)) {pu : Fl4SpecA64.Word} {sz : Nat} + (J2 : JStage3A st AR Z' H' OS' U' Ac' Pp' Tb' Lv' ia' ie' N' E' Rp' Bf' stack' κ' n' J5' J7' s' a' + (utDelStA pu sz (stUpdA σ σ.curThread x .restart)) m') + {Clock : A → MachineState → Prop} (hCl : Clock a σ.machineState) (hCnt : CounterStepA σ) + (hFr : ∀ a ms ms', Clock a ms → ms'.timeState = ms.timeState → ms'.lastMachineTime = ms.lastMachineTime → + Clock a ms') : + UtPpTimeA Clock a (utDelStA pu sz (stUpdA σ σ.curThread x .restart)) ∧ + UtPreKeepA (stUpdA σ σ.curThread x .restart) (utDelStA pu sz (stUpdA σ σ.curThread x .restart)) := by + set σ2 := stUpdA σ σ.curThread x .restart with hσ2 + set σd := utDelStA pu sz σ2 with hσd + have K : UtKeepCurA σ2 σd := + UtKeepCurA.ofDelStep (UtCnStepA.refl _) rfl J2.sinv.curTcb J2.sinv.curSc + refine ⟨?_, UtPreKeepA.ofKeepCur K⟩ + obtain ⟨t, hkt, htsc, -⟩ := J.curInv.tcb + obtain rfl : t = x := KernelObject.tcb.inj (Option.some.inj (hkt.symm.trans hk)) + obtain ⟨y0, k0, hy0⟩ := J.curInv.sc + have ne : σ.curSc ≠ σ.curThread := fun e => by rw [e, hk] at hy0; cases hy0 + have h2sc : σ2.kheap σ.curSc = some (.schedContext y0 k0) := by + simp only [hσ2, stUpdA, setObjA, Function.update_of_ne ne]; exact hy0 + have h2t : σ2.kheap σ.curThread = some (.tcb { t with tcbState := .restart }) := by + simp [hσ2, stUpdA, setObjA] + have hdsc : σd.kheap σ.curSc = some (.schedContext y0 k0) := K.sc y0 k0 h2sc + have hdt : σd.kheap σ.curThread = some (.tcb { t with tcbState := .restart }) := K.tcb _ h2t + have ecur : σd.curThread = σ.curThread := K.glob.cur + have ecsc : σd.curSc = σ.curSc := K.glob.csc + have eact : σd.schedulerAction = σ.schedulerAction := K.glob.act + have erls : σd.releaseQueue = σ.releaseQueue := K.glob.rls + have eidle : σd.idleThread = σ.idleThread := K.glob.idle + have hsc : ∀ y k, σd.kheap σd.curSc = some (.schedContext y k) → y = y0 ∧ k = k0 := fun y k h => by + rw [ecsc, hdsc] at h + obtain ⟨h1, h2⟩ := KernelObject.schedContext.inj (Option.some.inj h) + exact ⟨h1.symm, h2.symm⟩ + -- the current thread is not the idle thread, so the current SC is not the idle SC + have hit : σ.curThread ≠ σ.idleThread := fun e => by + obtain ⟨xi, hxi, hsi⟩ := J2.sinv.idleTcb + rw [eidle, ← e, hdt] at hxi + obtain rfl := KernelObject.tcb.inj (Option.some.inj hxi) + cases hsi + have hci : σ.curSc ≠ idleScPtr := fun e => by + obtain ⟨z, j, hz, hzo⟩ := J.sr.inv.back _ _ _ hk htsc + obtain ⟨xi, yi, ki, -, -, hyi, hti⟩ := J.sinv.idleSc + rw [← e, hz] at hyi + obtain ⟨h1, -⟩ := KernelObject.schedContext.inj (Option.some.inj hyi) + subst h1 + exact hit (Option.some.inj (hzo.symm.trans hti)) + have ha : scActive y0 = true := J.curInv.active hci _ _ hy0 + refine + { valid := J.validTime + cur := ⟨⟨_, by rw [ecur]; exact hdt, by rw [ecsc]; exact htsc, rfl⟩, ⟨y0, k0, by rw [ecsc]; exact hdsc⟩, + fun _ y k h => by rw [(hsc y k h).1]; exact ha, by rw [ecur, erls]; exact J.curInv.notRel⟩ + off := fun y k h => by + rw [(hsc y k h).1, K.glob.cons, K.glob.time] + exact J.offReady y0 k0 hy0 + act := ?_ + clk := hFr a σ.machineState _ hCl rfl rfl + scAct := fun y k h => by rw [(hsc y k h).1]; exact ha + cs := hCnt } + refine ⟨fun u h => ?_, ?_⟩ + · rw [eact, J.act] at h; cases h + · obtain ⟨xi, yi, ki, hxi, hxs, -, -⟩ := J2.sinv.idleSc + obtain ⟨xi', hxi', hsi⟩ := J2.sinv.idleTcb + obtain rfl := KernelObject.tcb.inj (Option.some.inj (hxi.symm.trans hxi')) + obtain ⟨-, -, -, -, hr⟩ := J.actIdle.2 + exact ⟨_, hxi, hxs, hsi, by rw [eidle, erls]; exact hr⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtPreDecA.lean b/proofs/Fl4ProofsA64/P3/UtPreDecA.lean new file mode 100644 index 000000000..0e0803b5b --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtPreDecA.lean @@ -0,0 +1,193 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line prst): **`untyped::decode` for a Retype whose reset is preempted**. + +* `utRst_hvpA`: the preemption point's VSpace-word premise at a record (`vsOk` and `JStage3TA.vsr_offPPWA`). +* `utRetype_resetPreA`: a retype with `reset` whose `reset_untyped` returns `Preempted` (a case hypothesis): the result + is `Preempted`, a preempted spec reset matches, and `JStage3A` holds over the dropped sets, with the timing facts and + the frame (`UtPreKeepA`) at the exit. +* `utDecode_recResetPreA`: the same through `untyped::decode`, from the syscall-entry record. + +None of the creation's premises is used: the retype stops inside the reset. + +Named premises: [P] `ArchTotal`, `A64FrameMasks`, `hvi`/`hvirt`, `hfan`, `hn`, `hPost`, `hchunk`, `hnd`, the clock and +interrupt facts (`Pc`, `hC`, `hNow`, `hAr`, `hirq`, `hmb`, `hFr`, `hCl`, `hCnt`); [S] `othT`, `othC` (one core); +[J] `JSyscallA`. New theorems only. +-/ +import Fl4ProofsA64.P3.UtPreCarryA +import Fl4ProofsA64.P3.UtRtResetPpA +import Fl4ProofsA64.P3.UtRstReadyA +import Fl4ProofsA64.P3.DelPpA +import Fl4ProofsA64.P3.Stage3PreemptTA + +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 + +set_option maxRecDepth 100000 + +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} + +/-- **The preemption point's VSpace-word premise at a record** (module docstring). -/ +theorem utRst_hvpA + (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 σ) (noSwitch : ∀ u, σ.schedulerAction ≠ .switchThread u) : + ∀ b, VsR (L.ksb s) (utVsPtA st Pp Tb Lv s) b → Aligned b ∧ ¬ PPW st s b := fun b hb => + ⟨VrOK.al J.vsOk b hb, (J.toTA sact noSwitch).vsr_offPPWA J.vsOk hb⟩ + +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 whose reset is preempted** (module docstring). -/ +theorem utRetype_resetPreA [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) + (hnd : numDomains = 1) {Clock : A → MachineState → Prop} (Pc : NowAgreeA ar Clock) + (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 : UtPpTimeA Clock a (utDelStA (specPtr p) sb.val σ)) + (hK0 : UtPreKeepA σ (utDelStA (specPtr p) sb.val σ)) + {s3 : S} {a3 : A} + (hres : untyped.reset_untyped st ar s a (cslotAddrA cte) = ok (core.result.Result.Err .Preempted, s3, a3)) + (base nt us dest off win : U64) : + untyped.retype st ar s a (cslotAddrA cte) true base nt us dest off win false ⦃ r => + r.1 = .Err .Preempted ∧ ∃ σ3, (.error (), σ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)) r.2.1 r.2.2 σ3 (dropMA (utDA p sb.val) m) ∧ + UtPpTimeA Clock r.2.2 σ3 ∧ UtPreKeepA σ σ3 ⦄ := by + have no : ∀ (s4 : S) (a4 : A), + untyped.reset_untyped st ar s a (cslotAddrA cte) = ok (core.result.Result.Ok (), s4, a4) → False := by + intro s4 a4 h + rw [hres] at h + cases (Prod.mk.inj (okinj h)).1 + refine utRetype_resetA ar cte hq hth Y hn hPost hchunk + (fun o s a σ' => ∃ Rq' Nt' : Set U64, 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) + (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n nA (dropMA (utDA p sb.val) m) p sb + (cslotAddrA cte) Rq' Nt' (Array.repeat 3#usize 0#u64) s a σ' o ∧ (UtPpTimeA Clock a σ' ∧ UtPreKeepA σ σ')) + (fun a σ' => UtPpTimeA Clock a σ' ∧ UtPreKeepA σ σ') + (fun _ _ _ h H hm => ⟨h.1.cnStep H hm, h.2.cnStep H⟩) ⟨hT0, hK0⟩ ?hpp base nt us dest off win _ + (fun _ h _ => (no _ _ h).elim) (fun _ _ _ _ h _ _ _ _ _ => (no _ _ h).elim) + (fun _ _ _ _ _ _ _ h _ _ _ => (no _ _ h).elim) ?hpre + case hpp => + intro _ Rq' Nt' o _ s1 a1 σ1 h + have hook := utPre_ppA (st := st) (ar := ar) (OS := dropSetA (utDA p sb.val) OS) (σ0 := σ) (Clock := Clock) + (R := 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) + (utBfOffA (utDA p sb.val) (dropBfA (utDA p sb.val) Bf)) stack κ n nA (dropMA (utDA p sb.val) m) p sb + (cslotAddrA cte) Rq' Nt' (Array.repeat 3#usize 0#u64) s a σ' o) + hnd hNow (utPp_hookA (AR := AR) (Z := dropZA (utDA p sb.val) Z) ar hnd Pc + (fun _ _ _ J sact nsw => utRst_hvpA J sact nsw) hC hNow hAr hirq hmb) + refine WP.spec_mono (hook s1 a1 σ1 h) ?_ + rintro r ⟨hc, σ', g⟩ + exact ⟨hc, σ', g.imp id fun ⟨e, mem, hR⟩ => ⟨e, mem, Rq', Nt', hR⟩⟩ + case hpre => + intro s4 a4 σ4 o hm ⟨_, _, I, T, K⟩ + exact ⟨rfl, σ4, hm, I.rec_, T, K⟩ + +variable {J5 J7 : JSlotA S} + +set_option maxHeartbeats 1000000 in +/-- **The decode-level top of a preempted reset** (module docstring). -/ +theorem utDecode_recResetPreA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (hA : P0.ArchTotal 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 nA)) s a σ m) + (sl : CslotPtr) (hsrc : ∃ q, sl.1 = specPtr q ∧ Z.th q = some (.cnode sl.2.length)) + (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) + (hn : nA.val = fl4A64Platform.s2IpaBits) + (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) + (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 ⦄) + (hFr : ∀ a ms ms', Clock a ms → ms'.timeState = ms.timeState → ms'.lastMachineTime = ms.lastMachineTime → + Clock a ms') + (hCl : Clock a σ.machineState) (hCnt : CounterStepA σ) + {s3 : S} {a3 : A} + (hres : untyped.reset_untyped st ar (L.wr s (stA (L.curW s)) sched.TS_RESTART) a (cslotAddrA sl) = + ok (core.result.Result.Err .Preempted, s3, a3)) : + 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 = .Err .Preempted ∧ + ∃ (base retypeBase : Word) (t : ApiObjectType) (us : Nat) (slots : List CslotPtr), + inv = .retype sl true base retypeBase t us slots false ∧ + ∃ xT, σ.kheap σ.curThread = some (.tcb xT) ∧ + ∃ σ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) Rp) + (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) ∧ + UtPpTimeA Clock res.2.2 σ3 ∧ UtPreKeepA (stUpdA σ σ.curThread xT .restart) σ3) res ⦄ := by + obtain ⟨qc, hq, hth⟩ := hsrc + refine utDecode_resetA J.toJStage3A ex sl ⟨qc, hq, hth⟩ D P hcapF RS hfm vi hvi hvirt hfan lbl slbl hlbl length buf + args hlen hargs exs hex hnochild _ ?_ + intro aligned nt us dest off win t rd xT fiv X hU hkT _ _ _ + obtain ⟨-, -, -, -, -, -, -, -, -, -, hrs, -⟩ := id hU + have he := hrs.1 rfl + obtain ⟨⟨⟩, he⟩ := he + obtain ⟨y, hk, -, -, Y⟩ := utRstReady_restartA J.sact J.toJStage3A D P hcapF he RS.sym RS.run RS.cur RS.vs RS.vc + othT othC + obtain rfl : y = xT := by + have h := hk.symm.trans hkT + injection h with h + injection h + have J2 := (utReset_startA Y.rec_ Y.dec Y.place Y.cap Y.noch Y.symL Y.othT Y.othC hn sl hq hth rfl).1 + obtain ⟨T0, K0⟩ := utPre_startA J hkT J2 hCl hCnt hFr + refine WP.spec_mono (utRetype_resetPreA ar sl hq hth Y hn hPost hchunk hnd Pc hC hNow hAr hirq hmb T0 K0 hres + aligned nt us dest off win) ?_ + rintro res ⟨hr, σ3, hm, J3, T, K⟩ + exact ⟨hr, _, _, _, _, _, rfl, y, hkT, σ3, hm, J3, T, K⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtPreExitA.lean b/proofs/Fl4ProofsA64/P3/UtPreExitA.lean new file mode 100644 index 000000000..2bd26a3a4 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtPreExitA.lean @@ -0,0 +1,84 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line prst): **the body facts at a preempted reset's exit**: `Sched.BodyPPA` at the grown +view and `PreExitA`, from the syscall-entry record, the spec frame (`UtPreKeepA`) from the restarted state, and the +preemption point's timing facts (`UtPpTimeA`). + +No named premise besides [J] `JSyscallA`. New theorems only. +-/ +import Fl4ProofsA64.P3.UtPreCarryA +import Fl4ProofsA64.P3.Stage3DispBaseA + +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 + +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} {σ σ3 : State Unit} {m m' : McState} + +/-- **`BodyPPA` and `PreExitA` at a preempted reset's exit** (module docstring). -/ +theorem utPre_exitA (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)) + (K : UtPreKeepA (stUpdA σ σ.curThread x .restart) σ3) + {Clock : A → MachineState → Prop} {a3 : A} (T : UtPpTimeA Clock a3 σ3) (hg : McGrowA m m') : + Sched.BodyPPA σ3 m' ∧ PreExitA σ3 := by + set σ2 := stUpdA σ σ.curThread x .restart with hσ2 + obtain ⟨t, hkt, htsc, -⟩ := J.curInv.tcb + obtain rfl : t = x := KernelObject.tcb.inj (Option.some.inj (hkt.symm.trans hk)) + obtain ⟨y0, k0, hy0⟩ := J.curInv.sc + have ne : σ.curSc ≠ σ.curThread := fun e => by rw [e, hk] at hy0; cases hy0 + have ecur : σ3.curThread = σ.curThread := K.cur + have ecsc : σ3.curSc = σ.curSc := K.csc + have eact : σ3.schedulerAction = .resumeCurThread := K.act.trans J.act + have erq : σ3.readyQueues = σ.readyQueues := K.rq + have erls : σ3.releaseQueue = σ.releaseQueue := K.rls + have h3t : σ3.kheap σ.curThread = some (.tcb { t with tcbState := .restart }) := + K.tcb _ (show σ2.kheap σ.curThread = _ by simp [hσ2, stUpdA, setObjA]) + have h3sc : σ3.kheap σ.curSc = some (.schedContext y0 k0) := + K.sc y0 k0 (show σ2.kheap σ.curSc = _ by simp only [hσ2, stUpdA, setObjA, Function.update_of_ne ne]; exact hy0) + have htcb : ∀ x', σ3.kheap σ3.curThread = some (.tcb x') → x' = { t with tcbState := .restart } := fun x' h => by + rw [ecur, h3t] at h + exact (KernelObject.tcb.inj (Option.some.inj h)).symm + -- the thread bound to the current SC is the current thread + obtain ⟨z, j, hz, hzt⟩ := J.sr.inv.back _ _ _ hk htsc + have hy0t : y0.scTcb = some σ.curThread := by + rw [hy0] at hz + obtain ⟨h1, -⟩ := KernelObject.schedContext.inj (Option.some.inj hz) + rw [h1]; exact hzt + have hbound : ∀ y k o, σ3.kheap σ3.curSc = some (.schedContext y k) → y.scTcb = some o → o = σ.curThread := + fun y k o h ho => by + rw [ecsc, h3sc] at h + obtain ⟨h1, -⟩ := KernelObject.schedContext.inj (Option.some.inj h) + rw [← h1, hy0t] at ho + exact (Option.some.inj ho).symm + have howner : ∀ y k, σ3.kheap σ3.curSc = some (.schedContext y k) → ∀ o, y.scTcb = some o → + o ∉ σ3.releaseQueue := fun y k h o ho => by + rw [hbound y k o h ho, erls]; exact J.curInv.notRel + have noSw : ∀ u, σ3.schedulerAction ≠ .switchThread u := fun u h => by rw [eact] at h; cases h + constructor + · refine { validTime := T.valid, ready := fun _ _ _ _ _ => T.off, ctAct := fun _ x' h => ?_, + sw := fun u h => absurd h (noSw u), scNotIdle := fun h => ?_, + owner := fun y k h _ _ _ o ho => howner y k h o ho } + · rw [htcb x' h]; exact Or.inr (Or.inl rfl) + · rw [ecsc] at h ⊢ + obtain ⟨h1, h2⟩ := J.curScNotIdle h + exact ⟨h1, fun c hc => by rw [hg.idleSc]; exact h2 c hc⟩ + · refine ⟨noSw, fun d p => by rw [ecur, erq]; exact J.sinv.ctQ J.act d p, fun x' h => ?_, + by rw [ecur, erls]; exact J.curInv.notRel, fun _ x' h => by rw [htcb x' h]; rfl, + fun y k h _ _ o ho => howner y k h o ho, fun y k o x' h ho hx => ?_⟩ + · rw [htcb x' h, ecsc]; exact Or.inr htsc + · have eo := hbound y k o h ho + rw [eo, ← ecur] at hx + refine Or.inl ⟨eo.trans ecur.symm, ?_⟩ + rw [htcb x' hx]; rfl + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtRec6KeepA.lean b/proofs/Fl4ProofsA64/P3/UtRec6KeepA.lean index 80ef706cd..21737bc28 100644 --- a/proofs/Fl4ProofsA64/P3/UtRec6KeepA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRec6KeepA.lean @@ -69,7 +69,7 @@ theorem utRec6_keepA UtWinCapA st OS s' ∧ (∀ v ∈ Z.V, L.mem s' v ≠ 0#u64 → L.mem s' (wa (L.mem s' v) 3664#u64) = v) ∧ (∀ t ∈ Z.T, L.mem s' (runVcpuA t) ≠ 0#u64 → L.mem s' (wa (L.mem s' (runVcpuA t)) 24#u64) = t) ∧ - VcpuStateSnapA Z.V (L.mem s') σ' ∧ UserFrSpecA st OS s' σ' := by + VcpuStateSnapA Z.V (L.mem s') σ' ∧ UserFrSpecA st H OS s' σ' := by have v0 : ∀ v ∈ Z.V, L.mem s' v = L.mem s v := fun v hv => by have := vm v hv 0#u64 (by simp) (by simp) rwa [wa_zeroVcA] at this @@ -79,7 +79,7 @@ theorem utRec6_keepA vcBack_keepA J.vcRun.vtcb v0 tw J.vcBack, runBack_keepA J.vcRun.run tr (fun v hv => vm v hv _ (by simp) (by simp)) J.runBack, J.vcSnap.keepA vm (fun v _ x h => by rw [← kh]; exact h), - J.userFr.keepA capE (fun p dev pg h => by rw [kh]; exact h)⟩ + J.userFr.keepA capE (fun _ _ e => e) (fun p dev pg h => by rw [kh]; exact h)⟩ end diff --git a/proofs/Fl4ProofsA64/P3/UtRtEndA.lean b/proofs/Fl4ProofsA64/P3/UtRtEndA.lean index 13d840aab..4f10d41b3 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtEndA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtEndA.lean @@ -124,12 +124,78 @@ theorem utEnd_scSizeA {m : Fl4SpecA64.McState} {σ σ' : Fl4SpecA64.State Unit} refine Or.inr ⟨us.val, hz, ?_, e ▸ hnew hd h5 j hj⟩ exact U.A.sc h5 -/-- **`FrBaseApartA` at the creation's end.** -/ +/-- **A new cap's range** (E0.5b): `[bj, bj + 2^z)`, inside the untyped's free part. -/ +theorem utEnd_newRngA {fi1 : U64} (hcx1 : capA st s1 slot = .Untyped p sb fi1 dev) + (hfa : p.val + fi1.val ≤ aligned.val) {j : Nat} (hj : j < win.val) : + baseA (newCapA nt.val (bjA aligned (zA nt.val us) j) us dev) = aligned.val + j * 2 ^ (zA nt.val us).val ∧ + topA (newCapA nt.val (bjA aligned (zA nt.val us) j) us dev) = + aligned.val + j * 2 ^ (zA nt.val us).val + 2 ^ (zA nt.val us).val - 1 ∧ + p.val + fi1.val ≤ baseA (newCapA nt.val (bjA aligned (zA nt.val us) j) us dev) ∧ + topA (newCapA nt.val (bjA aligned (zA nt.val us) j) us dev) < p.val + 2 ^ sb.val := by + obtain ⟨hv, hlt⟩ := utEnd_bjA U hj + have hpos := Nat.two_pow_pos (zA nt.val us).val + have hs1 : j * 2 ^ (zA nt.val us).val + 2 ^ (zA nt.val us).val ≤ win.val * 2 ^ (zA nt.val us).val := by + have := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt hj) + rwa [Nat.succ_mul] at this + have hsb := capA_ut_b hcx1 + have hz : (zA nt.val us).val < 64 := by + by_contra hz + push_neg at hz + have e1 : 2 ^ 64 ≤ 2 ^ (zA nt.val us).val := Nat.pow_le_pow_right (by norm_num) hz + have e2 : 2 ^ sb.val < 2 ^ 64 := Nat.pow_lt_pow_right (by norm_num) hsb + have := U.A.aw + omega + have hfit : (bjA aligned (zA nt.val us) j).val + 2 ^ (zA nt.val us).val ≤ 2 ^ 64 := by + have := U.A.aw + have := U.A.pf + omega + obtain ⟨b1, t1⟩ := newCapA_range U.A.hn (bjA aligned (zA nt.val us) j) us dev hz hfit + have := U.A.aw + refine ⟨by rw [b1, hv], by rw [t1, hv], by rw [b1, hv]; omega, by rw [t1, hv]; omega⟩ + +/-- **`FrBaseApartA` at the creation's end.** `hrev`: the revocable bits of the kept slots. -/ theorem utEnd_frBaseA {par : U64 → Option U64} (h : FrBaseApartA st OS1 s1) (I : UtInvA st OS1 par s1) {fi1 : U64} - (hcx1 : capA st s1 slot = .Untyped p sb fi1 dev) (hfa : p.val + fi1.val ≤ aligned.val) : + (hcx1 : capA st s1 slot = .Untyped p sb fi1 dev) (hfa : p.val + fi1.val ≤ aligned.val) + (hrev : ∀ y ∈ OS1, (∀ j, j < win.val → y ≠ djA dest off j) → Fl4ProofsA64.P1.W7.R.ST.revA st s' y = Fl4ProofsA64.P1.W7.R.ST.revA st s1 y) : FrBaseApartA st OS1 s' := by + have hl : FrLamA st OS1 s' := by + refine utRt_lamA h.2.2 I U.src hcx1 (fun y => ∃ j, j < win.val ∧ y = djA dest off j) ?_ ?_ ?_ ?_ + · intro y hy ny p0 rt mp e asid va hc + rcases utEnd_capsA U (y := y) with ⟨-, nfi, e'⟩ | ⟨j, hj, ey, -⟩ | ⟨-, -, k⟩ + · rw [e'] at hc; cases hc + · exact (ny ⟨j, hj, ey⟩).elim + · exact ⟨y, hy, p0, rt, mp, e, asid, va, by rw [← k hy]; exact hc, by rw [k hy], by rw [k hy]⟩ + · intro z hz nz pz + rcases utEnd_capsA U (y := z) with ⟨ez, nfi, e'⟩ | ⟨j, hj, ey, -⟩ | ⟨-, hn, k⟩ + · refine ⟨slot, U.src, by rw [hcx1]; exact physA_ut _ _ _ _, ?_, ?_, fun f _ => ?_⟩ + · rw [e', hcx1]; unfold baseA; rw [ptrA_ut, ptrA_ut] + · rw [e', hcx1]; unfold topA; rw [ptrA_ut, sizeA_ut, ptrA_ut, sizeA_ut] + · rw [hcx1] at f; simp [isFrA] at f + · exact (nz ⟨j, hj, ey⟩).elim + · exact ⟨z, hz, by rw [← k hz]; exact pz, by rw [k hz], by rw [k hz], + fun f r => ⟨by rw [k hz]; exact f, by rw [hrev z hz hn]; exact r⟩⟩ + · rintro y hy ⟨j, hj, ey⟩ _ + obtain ⟨b1, t1, b2, t2⟩ := utEnd_newRngA U hcx1 hfa hj + rw [ey, U.E.new j hj] + exact ⟨b2, t2⟩ + · rintro y hy z hz ⟨j, hj, ey⟩ ⟨l, hl, ez⟩ hne _ _ + have hjl : j ≠ l := fun e' => hne (by rw [ey, ez, e']) + obtain ⟨b1, t1, -, -⟩ := utEnd_newRngA U hcx1 hfa hj + obtain ⟨b2, t2, -, -⟩ := utEnd_newRngA U hcx1 hfa hl + rw [ey, ez, U.E.new j hj, U.E.new l hl] + have hpos := Nat.two_pow_pos (zA nt.val us).val + refine Or.inl ?_ + unfold DisjA + rw [b1, t1, b2, t2] + rcases Nat.lt_or_gt_of_ne hjl with hlt | hgt + · have := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt hlt) + rw [Nat.succ_mul] at this + left; omega + · have := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt hgt) + rw [Nat.succ_mul] at this + right; omega refine utRt_frBaseA h I U.src hcx1 (fun y => ∃ j, j < win.val ∧ y = djA dest off j) (fun y hy hk => ?_) - (fun y z hy hz fy kz => ?_) + (fun y z hy hz fy kz => ?_) hl · rcases utEnd_capsA U (y := y) with ⟨-, nfi, e⟩ | ⟨j, hj, ey, e⟩ | ⟨-, -, k⟩ · rw [e] at hk rcases hk with hk | hk @@ -138,7 +204,8 @@ theorem utEnd_frBaseA {par : U64 → Option U64} (h : FrBaseApartA st OS1 s1) (I · refine Or.inr ⟨⟨j, hj, ey⟩, ?_⟩ obtain ⟨hv, hlt⟩ := utEnd_bjA U hj rw [e, newCapA_ptr, hv] - exact ⟨by omega, hlt⟩ + exact ⟨by omega, hlt, fun _ => utRt_newTopA U.A.hn hj (capA_ut_b hcx1) U.A.pa U.A.aw + (le_trans U.A.aw U.A.pf) dev⟩ · exact Or.inl ⟨y, hy, (k hy).symm⟩ · obtain ⟨j, hj, rfl⟩ := hy obtain ⟨l, hl, rfl⟩ := hz diff --git a/proofs/Fl4ProofsA64/P3/UtRtFrA.lean b/proofs/Fl4ProofsA64/P3/UtRtFrA.lean index 5bb2f7bf7..32ea6b24a 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtFrA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtFrA.lean @@ -111,28 +111,145 @@ theorem utRt_baseOffA {OS : Set U64} {par : U64 → Option U64} {s : S} (U : UtI · unfold baseA at h; omega · rw [hu] at h; cases h -/-- **`FrBaseApartA` after Retype.** -/ +/-- **An old non-untyped physical cap is disjoint from an untyped's free part** (`UtInvA.noov`). -/ +theorem utRt_disjA {OS : Set U64} {par : U64 → Option U64} {s : S} (U : UtInvA st OS par s) {x p b i : U64} + {d : Bool} (hx : x ∈ OS) (hcx : capA st s x = .Untyped p b i d) {y : U64} (hy : y ∈ OS) + (hp : physA (capA st s y) = true) (hu : isUtA (capA st s y) = false) : + DisjRA (capA st s y) (p.val + i.val) (p.val + 2 ^ b.val) := by + rcases U.noov x hx p b i d hcx y hy hp with h | ⟨h, -⟩ + · exact h + · rw [hu] at h; cases h + +/-- **The top of a new cap lies below the untyped's end** (the window `[aligned, aligned + win·2^z)` is inside it). -/ +theorem utRt_newTopA {n : Nat} (hn : n < 15) {aligned us p sb : U64} {win j : Nat} (hj : j < win) + (hsb : sb.val < 64) (h1 : p.val ≤ aligned.val) + (h2 : aligned.val + win * 2 ^ (zA n us).val ≤ p.val + 2 ^ sb.val) + (hfit : aligned.val + win * 2 ^ (zA n us).val ≤ 2 ^ 64) (d : Bool) : + topA (newCapA n (bjA aligned (zA n us) j) us d) < p.val + 2 ^ sb.val := by + have hpos := Nat.two_pow_pos (zA n us).val + have hs1 : j * 2 ^ (zA n us).val + 2 ^ (zA n us).val ≤ win * 2 ^ (zA n us).val := by + have := Nat.mul_le_mul_right (2 ^ (zA n us).val) (Nat.succ_le_of_lt hj) + rwa [Nat.succ_mul] at this + have hz : (zA n us).val < 64 := by + by_contra hz + push_neg at hz + have e1 : 2 ^ 64 ≤ 2 ^ (zA n us).val := Nat.pow_le_pow_right (by norm_num) hz + have e2 : 2 ^ sb.val < 2 ^ 64 := Nat.pow_lt_pow_right (by norm_num) hsb + omega + have hbj : (bjA aligned (zA n us) j).val = aligned.val + j * 2 ^ (zA n us).val := bjA_val (by omega) + obtain ⟨-, ht⟩ := newCapA_range hn (bjA aligned (zA n us) j) us d hz (by omega) + rw [ht] + omega + +/-- **`FrLamA` after Retype** (E0.5b): an old physical cap is disjoint from an untyped's free part or an untyped +containing it (`UtInvA.noov`), the new caps lie in the free part and are pairwise disjoint or the same slot. -/ +theorem utRt_lamA {OS OS' : Set U64} {s s' : S} (h : FrLamA st OS s) {par : U64 → Option U64} + (U : UtInvA st OS par s) {x p b i : U64} {d : Bool} (hx : x ∈ OS) (hcx : capA st s x = .Untyped p b i d) + (New : U64 → Prop) + (hOldY : ∀ y ∈ OS', ¬ New y → ∀ (p0 rt : U64) (mp e : Bool) (asid va : U64), + capA st s' y = .Frame p0 .Large rt false mp e asid va → + ∃ y0 ∈ OS, ∃ (q0 rt0 : U64) (mp0 e0 : Bool) (a0 v0 : U64), + capA st s y0 = .Frame q0 .Large rt0 false mp0 e0 a0 v0 ∧ + baseA (capA st s' y) = baseA (capA st s y0) ∧ topA (capA st s' y) = topA (capA st s y0)) + (hOldZ : ∀ z ∈ OS', ¬ New z → physA (capA st s' z) = true → + ∃ z0 ∈ OS, physA (capA st s z0) = true ∧ baseA (capA st s' z) = baseA (capA st s z0) ∧ + topA (capA st s' z) = topA (capA st s z0) ∧ + (isFrA (capA st s z0) = true → Fl4ProofsA64.P1.W7.R.ST.revA st s z0 = false → + isFrA (capA st s' z) = true ∧ Fl4ProofsA64.P1.W7.R.ST.revA st s' z = false)) + (hNewR : ∀ y ∈ OS', New y → physA (capA st s' y) = true → + p.val + i.val ≤ baseA (capA st s' y) ∧ topA (capA st s' y) < p.val + 2 ^ b.val) + (hNewS : ∀ y ∈ OS', ∀ z ∈ OS', New y → New z → y ≠ z → physA (capA st s' y) = true → + physA (capA st s' z) = true → DisjA (capA st s' y) (capA st s' z) ∨ WithinA (capA st s' y) (capA st s' z)) : + FrLamA st OS' s' := by + have hr := U.reg x hx (by rw [hcx]; exact physA_ut _ _ _ _) + rw [hcx] at hr + obtain ⟨r1, r2, -⟩ := ut_rangeA (capA_ut_b hcx) hr + have bx : baseA (capA st s x) = p.val := by rw [hcx]; exact r1 + have tx : topA (capA st s x) = p.val + 2 ^ b.val - 1 := by rw [hcx]; exact r2 + have h2 : 1 ≤ 2 ^ b.val := Nat.one_le_two_pow + intro y hy p0 rt mp e asid va hc z hz pz + have fy : isFrA (capA st s' y) = true := by rw [hc]; rfl + have py : physA (capA st s' y) = true := (utFr_physA fy).1 + by_cases ny : New y + · obtain ⟨ylo, yhi⟩ := hNewR y hy ny py + by_cases nz : New z + · by_cases yz : y = z + · subst yz; exact Or.inr (Or.inr ⟨le_refl _, le_refl _⟩) + · exact (hNewS y hy z hz ny nz yz py pz).elim (fun d => Or.inl (Or.symm d)) fun w => Or.inr (Or.inr w) + · obtain ⟨z0, hz0, pz0, bz, tz, -⟩ := hOldZ z hz nz pz + rcases U.noov x hx p b i d hcx z0 hz0 pz0 with dj | ⟨-, wi⟩ + · left + unfold DisjRA at dj + unfold DisjA + rw [bz, tz] + omega + · right; right + unfold WithinA at wi ⊢ + rw [bx, tx] at wi + rw [bz, tz] + omega + · obtain ⟨y0, hy0, q0, rt0, mp0, e0, a0, v0, hc0, b1, t1⟩ := hOldY y hy ny p0 rt mp e asid va hc + have f0 : isFrA (capA st s y0) = true := by rw [hc0]; rfl + have p0' : physA (capA st s y0) = true := (utFr_physA f0).1 + by_cases nz : New z + · obtain ⟨zlo, zhi⟩ := hNewR z hz nz pz + rcases U.noov x hx p b i d hcx y0 hy0 p0' with dj | ⟨hu, -⟩ + · left + unfold DisjRA at dj + unfold DisjA + rw [b1, t1] + omega + · rw [(utFr_physA f0).2] at hu; cases hu + · obtain ⟨z0, hz0, pz0, bz, tz, fr⟩ := hOldZ z hz nz pz + rcases h y0 hy0 q0 rt0 mp0 e0 a0 v0 hc0 z0 hz0 pz0 with dj | ⟨f, r⟩ | w + · left; unfold DisjA at dj ⊢; rw [b1, t1, bz, tz]; exact dj + · right; left; exact fr f r + · right; right; unfold WithinA at w ⊢; rw [b1, t1, bz, tz]; exact w + +/-- **`FrBaseApartA` after Retype** (the base clause and the containment clause). -/ theorem utRt_frBaseA {OS OS' : Set U64} {s s' : S} (h : FrBaseApartA st OS s) {par : U64 → Option U64} (U : UtInvA st OS par s) {x p b i : U64} {d : Bool} (hx : x ∈ OS) (hcx : capA st s x = .Untyped p b i d) (New : U64 → Prop) (hsplit : ∀ y ∈ OS', isFrA (capA st s' y) = true ∨ RngKeyA (capA st s' y) → (∃ y0 ∈ OS, capA st s y0 = capA st s' y) ∨ - (New y ∧ p.val + i.val ≤ (ptrA (capA st s' y)).val ∧ (ptrA (capA st s' y)).val < p.val + 2 ^ b.val)) - (huni : ∀ y z, New y → New z → isFrA (capA st s' y) = true → ¬ RngKeyA (capA st s' z)) : + (New y ∧ p.val + i.val ≤ (ptrA (capA st s' y)).val ∧ (ptrA (capA st s' y)).val < p.val + 2 ^ b.val ∧ + (isFrA (capA st s' y) = true → topA (capA st s' y) < p.val + 2 ^ b.val))) + (huni : ∀ y z, New y → New z → isFrA (capA st s' y) = true → ¬ RngKeyA (capA st s' z)) + (hl : FrLamA st OS' s') : FrBaseApartA st OS' s' := by - intro y hy z hz fy kz e - rcases hsplit y hy (Or.inl fy) with ⟨y0, hy0, ey⟩ | ⟨ny, y1, y2⟩ <;> - rcases hsplit z hz (Or.inr kz) with ⟨z0, hz0, ez⟩ | ⟨nz, z1, z2⟩ - · exact h y0 hy0 z0 hz0 (ey ▸ fy) (ez ▸ kz) (by rw [ey, ez]; exact e) - · have f0 : isFrA (capA st s y0) = true := ey ▸ fy - have := utRt_baseOffA U hx hcx hy0 (utFr_physA f0).1 (utFr_physA f0).2 - rw [ey, ← e] at this - exact this ⟨z1, z2⟩ - · have k0 : RngKeyA (capA st s z0) := ez ▸ kz - have := utRt_baseOffA U hx hcx hz0 k0.1 k0.2.1 - rw [ez, e] at this - exact this ⟨y1, y2⟩ - · exact huni y z ny nz fy kz + refine ⟨fun y hy z hz fy kz e => ?_, fun y hy z hz fy kz => ?_, hl⟩ + · rcases hsplit y hy (Or.inl fy) with ⟨y0, hy0, ey⟩ | ⟨ny, y1, y2, -⟩ <;> + rcases hsplit z hz (Or.inr kz) with ⟨z0, hz0, ez⟩ | ⟨nz, z1, z2, -⟩ + · exact h.1 y0 hy0 z0 hz0 (ey ▸ fy) (ez ▸ kz) (by rw [ey, ez]; exact e) + · have f0 : isFrA (capA st s y0) = true := ey ▸ fy + have := utRt_baseOffA U hx hcx hy0 (utFr_physA f0).1 (utFr_physA f0).2 + rw [ey, ← e] at this + exact this ⟨z1, z2⟩ + · have k0 : RngKeyA (capA st s z0) := ez ▸ kz + have := utRt_baseOffA U hx hcx hz0 k0.1 k0.2.1 + rw [ez, e] at this + exact this ⟨y1, y2⟩ + · exact huni y z ny nz fy kz + · rintro ⟨c1, c2⟩ + rcases hsplit y hy (Or.inl fy) with ⟨y0, hy0, ey⟩ | ⟨ny, y1, y2, yt⟩ <;> + rcases hsplit z hz (Or.inr kz) with ⟨z0, hz0, ez⟩ | ⟨nz, z1, z2, -⟩ + · refine h.2.1 y0 hy0 z0 hz0 (ey ▸ fy) (ez ▸ kz) ⟨?_, ?_⟩ + · rw [ey, ez]; exact c1 + · rw [ey, ez]; exact c2 + · have f0 : isFrA (capA st s y0) = true := ey ▸ fy + have hd := utRt_disjA U hx hcx hy0 (utFr_physA f0).1 (utFr_physA f0).2 + rw [ey] at hd + unfold DisjRA at hd + have hb : baseA (capA st s' z) = (ptrA (capA st s' z)).val := rfl + omega + · have k0 : RngKeyA (capA st s z0) := ez ▸ kz + have := utRt_baseOffA U hx hcx hz0 k0.1 k0.2.1 + rw [ez] at this + have hy1 : baseA (capA st s' y) = (ptrA (capA st s' y)).val := rfl + have hz1 : baseA (capA st s' z) = (ptrA (capA st s' z)).val := rfl + have ht := yt fy + exact this ⟨by omega, by omega⟩ + · exact huni y z ny nz fy kz /-- **`DevFrDisjA` after Retype.** -/ theorem utRt_devFrDisjA {H H' : Heap} {OS OS' : Set U64} {s s' : S} {σ σ' : Fl4SpecA64.State Unit} diff --git a/proofs/Fl4ProofsA64/P3/UtRtHighPostA.lean b/proofs/Fl4ProofsA64/P3/UtRtHighPostA.lean index ca29f81e7..172c429f3 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtHighPostA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtHighPostA.lean @@ -135,7 +135,7 @@ theorem utRt_highPostA rw [hNew gt q ((memA q).2 gq)] at h exact (Option.some.inj h).symm have hcap : ∀ y, IsSlotA (utRtThA Z.th false nt us aligned win.val) y → - UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win.val y := by + UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win.val (djA dest off) y := by intro y hy by_cases old : IsSlotA Z.th y · by_cases ex : y = x @@ -143,7 +143,7 @@ theorem utRt_highPostA exact Or.inr (Or.inr (Or.inl ⟨p, sb, nfi, false, by rw [ex]; exact e⟩)) · by_cases ed : ∃ j < win.val, y = djA dest off j · obtain ⟨j, hj, e⟩ := ed - exact Or.inr (Or.inl ⟨j, hj, by rw [e]; exact Ec.new j hj⟩) + exact Or.inr (Or.inl ⟨j, hj, e, by rw [e]; exact Ec.new j hj⟩) · exact Or.inl ⟨old, Ec.keep y (hsub y old) ex (fun j hj e => ed ⟨j, hj, e⟩)⟩ · refine Or.inr (Or.inr (Or.inr ?_)) obtain ⟨q, h⟩ := hy @@ -170,7 +170,7 @@ theorem utRt_highPostA rw [n14] at htt simpa [objTypeOfA, eq_comm] using htt rw [← utRtMA_empty m] - refine utRt_postA (Tn := ∅) (Cn := ∅) (Vn := ∅) J hx hc W h1 h2 hn + refine utRt_postA (hsub := hsub) (Tn := ∅) (Cn := ∅) (Vn := ∅) J hx hc W h1 h2 hn (fun h => by omega) w hS hC P' har (utRtBody_globA hr) hkeep (fun q => ⟨fun h => h.elim, fun h => absurd h.2 z1⟩) (fun c h => h.elim) (fun v h => h.elim) (fun h => absurd h z12) hcap (fun q h => h.elim) (fun c h => h.elim) (fun v h => h.elim) (fun q h => ?_) (fun q h => ?_) (fun y h => ?_) (fun q y h => ?_) diff --git a/proofs/Fl4ProofsA64/P3/UtRtPostA.lean b/proofs/Fl4ProofsA64/P3/UtRtPostA.lean index f6984e70c..9a019d5aa 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtPostA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtPostA.lean @@ -15,6 +15,7 @@ facts. No named premise. New definitions and theorems only. -/ import Fl4ProofsA64.P3.UtRtKeptA import Fl4ProofsA64.P3.UtRtVsA +import Fl4ProofsA64.P3.UtRtVsUniqA import Fl4ProofsA64.P3.UtRtSchedA import Fl4ProofsA64.P3.UtRtThA import Fl4ProofsA64.P3.UtRtWitA @@ -48,9 +49,9 @@ def utRtZA (Z : XSetsA) (G' : MdbGhostA) (nt us aligned : U64) (win : Nat) (Tn C Lv := utLvNewA Z.Lv nt aligned (zA nt.val us) win } /-- What a slot of the new typed heap holds. -/ -def UtCapAfterA (th : TypedHeapA) (mem mem' : U64 → U64) (nt us aligned : U64) (win : Nat) (y : U64) : Prop := +def UtCapAfterA (th : TypedHeapA) (mem mem' : U64 → U64) (nt us aligned : U64) (win : Nat) (dd : Nat → U64) (y : U64) : Prop := (IsSlotA th y ∧ capAtA mem' y = capAtA mem y) ∨ - (∃ j < win, capAtA mem' y = newCapA nt.val (bjA aligned (zA nt.val us) j) us false) ∨ + (∃ j < win, y = dd j ∧ capAtA mem' y = newCapA nt.val (bjA aligned (zA nt.val us) j) us false) ∨ (∃ a b c d, capAtA mem' y = .Untyped a b c d) ∨ capAtA mem' y = .Null private theorem ut_ite_eqA {α : Type} {c : Prop} [Decidable c] {x y z : α} (h : (if c then x else y) = z) : @@ -79,6 +80,16 @@ theorem utNewCap_vcpuA {n : Nat} {b u p} {d : Bool} | cases h cases h +theorem utNewCap_ptA {n : Nat} {b u p asid va : U64} {mp d : Bool} + (h : newCapA n b u d = .PageTable p mp asid va) : mp = false ∧ p = b := by + unfold newCapA at h + repeat + rcases ut_ite_eqA h with ⟨-, h⟩ | ⟨-, h⟩ + · first + | (cases h; exact ⟨rfl, rfl⟩) + | cases h + cases h + theorem utNewCap_eptA {n : Nat} {b u p l mp asid va} {d : Bool} (h : newCapA n b u d = .Ept p l mp asid va) : n = 13 ∧ p = b := by unfold newCapA at h @@ -99,6 +110,16 @@ theorem utNewCap_highA {n : Nat} {b u p mp asid} {d : Bool} | cases h cases h +theorem utNewCap_rootA {n : Nat} {b u r : U64} {d : Bool} (h : RootKindA r (newCapA n b u d)) : r = b := by + rcases h with ⟨_, _, e⟩ | ⟨_, _, _, e⟩ | ⟨_, _, e⟩ + · exact (utNewCap_pmlA e).2 + · exact (utNewCap_eptA e).2 + · exact (utNewCap_highA e).2 + +theorem utNewCap_ptKindA {n : Nat} {b u r : U64} {d : Bool} (h : PtKindA r (newCapA n b u d)) : r = b := by + obtain ⟨_, _, _, e⟩ := h + exact (utNewCap_ptA e).2 + /-- A new base lies in the window. -/ theorem utRt_newValA {nt aligned z : U64} {win : Nat} (W : UtWinZA nt aligned z win) {j : Nat} (hj : j < win) : aligned.val ≤ (bjA aligned z j).val ∧ (bjA aligned z j).val < aligned.val + win * 2 ^ z.val := by @@ -163,6 +184,7 @@ theorem utRt_relOffA /-- **`JAtZAX` after a RAM creation** (module docstring). -/ theorem utRt_postA (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) + (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) (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) (hr4 : nt.val = 4 → us.val ≠ 0) @@ -177,8 +199,9 @@ theorem utRt_postA (hCn : ∀ c ∈ Cn, c ∈ utBasesA aligned (zA nt.val us) win) (hVn : ∀ v ∈ Vn, v ∈ utBasesA aligned (zA nt.val us) win) (hVn12 : nt.val = 12 → ∀ v ∈ utBasesA aligned (zA nt.val us) win, v ∈ Vn) + {dd : Nat → U64} (hcap : ∀ y, IsSlotA (utRtThA Z.th false nt us aligned win) y → - UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win y) + UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win dd y) -- the new threads (hnt : ∀ t ∈ Tn, (L.mem s' (affA t)).val = 0 ∧ L.mem s' (stA t) = 0#u64 ∧ L.mem s' (scA t) = 0#u64 ∧ L.mem s' (domA t) = 0#u64 ∧ (L.mem s' (prioA t)).val = 0 ∧ L.mem s' (wa t 3664#u64) = 0#u64 ∧ @@ -318,7 +341,7 @@ theorem utRt_postA (∃ y0, IsSlotA Z.th y0 ∧ capAtA (L.mem s) y0 = c) ∨ ∃ j < win, newCapA nt.val (bjA aligned (zA nt.val us) j) us false = c := by intro y hy c e nu nn - rcases hcap y hy with ⟨h, k⟩ | ⟨j, hj, k⟩ | ⟨a, b, d, f, k⟩ | k + rcases hcap y hy with ⟨h, k⟩ | ⟨j, hj, -, k⟩ | ⟨a, b, d, f, k⟩ | k · exact Or.inl ⟨y, h, k.symm.trans e⟩ · exact Or.inr ⟨j, hj, k.symm.trans e⟩ · exact absurd (e.symm.trans k) (nu _ _ _ _) @@ -344,7 +367,8 @@ theorem utRt_postA cv := ?_ pml := ?_ vs := ?_ - ext := ?_ } + ext := ?_ + vsu := ?_ } · refine utRt_schedRelA (Tn := Tn) (Cn := Cn) J.j.1.sch H'.cpu (fun c hc' o ho => ?_) ?_ H'.act H'.time (fun t ht => ⟨(H'.tcbW ht).2.2.1, (H'.tcbW ht).1, (H'.tcbW ht).2.1⟩) (fun c hc' => H'.scW hc') kth kch ⟨hglob.cur, hglob.csc, hglob.idle, hglob.act, hglob.time⟩ (fun t ht => ?_) (fun c hcm => ?_) @@ -423,7 +447,7 @@ theorem utRt_postA · intro y hy change IsSlotA (utRtThA Z.th false nt us aligned win) y at hy show CapValidA (utRtThA Z.th false nt us aligned win) (capAtA (L.mem s') y) - rcases hcap y hy with ⟨h, k⟩ | ⟨j, hj, k⟩ | ⟨a, b, d, f, k⟩ | k + rcases hcap y hy with ⟨h, k⟩ | ⟨j, hj, -, k⟩ | ⟨a, b, d, f, k⟩ | k · rw [k] exact utRt_capValid_growA thFree (J.j.1.cv y h) · rw [k] @@ -445,6 +469,120 @@ theorem utRt_postA rw [H'.ksb] exact utVsRel_growA V0 G · exact utExtVs_growA V0 E0 G + · show VsUniqA (utRtThA Z.th false nt us aligned win) Z.Pp _ _ _ Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ' + rw [H'.ksb] + refine utGrow_vsUniqA V0 E0 G J.j.1.vsu (fun y hy ptr asid va mp h => ?_) (fun y hy r hU => ?_) + (fun y hy r hU => ?_) + · rcases capOld y hy _ h (fun _ _ _ _ e => by cases e) (fun e => by cases e) with hh | ⟨j, hj, k⟩ + · exact Or.inl hh + · obtain ⟨rfl, rfl⟩ := utNewCap_ptA k + refine Or.inr ⟨rfl, fun hT => ?_⟩ + have v := newV _ ⟨j, hj, rfl⟩ + rcases hoff _ (Or.inr (Or.inr (Or.inl hT))) with g | g <;> omega + · have oldRoot : ∀ y, IsSlotA Z.th y → ∀ r, RootKindA r (capAtA (L.mem s) y) → + ∀ j < win, r ≠ bjA aligned (zA nt.val us) j := by + intro y hy' r hk j hj e + have v := newV _ ⟨j, hj, rfl⟩ + rw [← e] at v + obtain ⟨c1, c2, c3, c4, -⟩ := J.j.capObj hy' + rcases hk with ⟨mp, asid, hk⟩ | ⟨mp, asid, va, hk⟩ | ⟨mp, asid, hk⟩ + · rcases hoff r (Or.inr (Or.inl (c4 _ _ _ hk).1)) with g | g <;> omega + · rcases hoff r (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl (c2 _ _ _ _ _ hk))))))) with g | g <;> omega + · rcases hoff r (Or.inr (Or.inr (Or.inr (Or.inl (c3 _ _ _ hk))))) with g | g <;> omega + have rkU : ∀ a b d e, ¬ RootKindA r (.Untyped a b d e) := fun a b d e h => by + rcases h with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h + have rkN : ¬ RootKindA r (.Null : capability.Cap) := fun h => by + rcases h with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h + rcases hcap y hy with ⟨h, k⟩ | ⟨j, hj, hyd, k⟩ | ⟨a, b, d, f, k⟩ | k + · refine Or.inl ⟨y, h, k ▸ hU, fun z hz hk => ?_⟩ + by_cases ez : z = y + · exact Or.inl ez + rcases hcap z hz with ⟨h2, k2⟩ | ⟨j, hj, hzd, k2⟩ | ⟨a, b, d, f, k2⟩ | k2 + · exact Or.inr ⟨z, h2, k2 ▸ hk, ez⟩ + · exact absurd (utNewCap_rootA (k2 ▸ hk)) (oldRoot y h r (k ▸ hU.kind) j hj) + · exact absurd (k2 ▸ hk) (rkU a b d f) + · exact absurd (k2 ▸ hk) rkN + · have hrb : r = bjA aligned (zA nt.val us) j := utNewCap_rootA (k ▸ hU.kind) + have v := newV _ ⟨j, hj, rfl⟩ + rw [← hrb] at v + have bjinj : ∀ j' , j' < win → bjA aligned (zA nt.val us) j = bjA aligned (zA nt.val us) j' → j = j' := by + intro j' hj' e + have hz : 0 < 2 ^ (zA nt.val us).val := Nat.two_pow_pos _ + have fit := W.fit + have h1 : (j + 1) * 2 ^ (zA nt.val us).val ≤ win * 2 ^ (zA nt.val us).val := Nat.mul_le_mul_right _ hj + have h2 : (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 h2 + have e1 : (bjA aligned (zA nt.val us) j).val = aligned.val + j * 2 ^ (zA nt.val us).val := bjA_val (by omega) + have e2 : (bjA aligned (zA nt.val us) j').val = aligned.val + j' * 2 ^ (zA nt.val us).val := bjA_val (by omega) + have := congrArg UScalar.val e + rw [e1, e2] at this + exact Nat.eq_of_mul_eq_mul_right hz (by omega) + refine Or.inr ⟨fun hT => ?_, fun hT => ?_, fun hT => ?_, fun z hz hk => ?_⟩ + rotate_left 3 + rcases hcap z hz with ⟨h2, k2⟩ | ⟨j', hj', hzd, k2⟩ | ⟨a, b, d, f, k2⟩ | k2 + · exact absurd hrb (oldRoot z h2 r (k2 ▸ hk) j hj) + · have := bjinj j' hj' (hrb.symm.trans (utNewCap_rootA (k2 ▸ hk))) + subst this; rw [hzd, hyd] + · exact absurd (k2 ▸ hk) (rkU a b d f) + · exact absurd (k2 ▸ hk) rkN + · rcases hoff r (Or.inr (Or.inl hT)) with g | g <;> omega + · rcases hoff r (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl hT)))))) with g | g <;> omega + · rcases hoff r (Or.inr (Or.inr (Or.inr (Or.inl hT)))) with g | g <;> omega + · exact absurd (k ▸ hU.kind) (rkU a b d f) + · exact absurd (k ▸ hU.kind) rkN + · have oldPt : ∀ y, IsSlotA Z.th y → ∀ r, PtKindA r (capAtA (L.mem s) y) → + ∀ j < win, r ≠ bjA aligned (zA nt.val us) j := by + intro y hy' r hk j hj e + have v := newV _ ⟨j, hj, rfl⟩ + subst e + obtain ⟨mp, a, vv, hkc⟩ := hk + cases mp + · -- an unmapped table: its spec object exists (J9), the window is spec-free (J3) + have hsp := (J.unmPt.pt y (hsub y hy') _ a vv (by rw [← capAtA_eq]; exact hkc)).spec + obtain ⟨t, ht, -⟩ := hsp + have hfree : UtFreeA st OS s (fun _ => True) (bjA aligned (zA nt.val us) j).val := + ⟨x, hx, p, sb, fi, false, hc, trivial, by omega, by omega⟩ + rw [J.specFree.heap _ hfree] at ht + cases ht + · rcases J.ptCapIn y hy' _ a vv hkc with ⟨hS, -⟩ | hT + · rcases hoff _ (Or.inr (Or.inl hS)) with g | g <;> omega + · rcases hoff _ (Or.inr (Or.inr (Or.inl hT))) with g | g <;> omega + have rkP : ∀ a b d e, ¬ PtKindA r (.Untyped a b d e) := fun a b d e h => by + obtain ⟨_, _, _, h⟩ := h; cases h + have rkPN : ¬ PtKindA r (.Null : capability.Cap) := fun h => by + obtain ⟨_, _, _, h⟩ := h; cases h + have bjinj : ∀ j j' : Nat, j < win → j' < win → + bjA aligned (zA nt.val us) j = bjA aligned (zA nt.val us) j' → j = j' := by + intro j j' hj hj' e + have hz : 0 < 2 ^ (zA nt.val us).val := Nat.two_pow_pos _ + have fit := W.fit + have h1 : (j + 1) * 2 ^ (zA nt.val us).val ≤ win * 2 ^ (zA nt.val us).val := Nat.mul_le_mul_right _ hj + have h2 : (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 h2 + have e1 : (bjA aligned (zA nt.val us) j).val = aligned.val + j * 2 ^ (zA nt.val us).val := bjA_val (by omega) + have e2 : (bjA aligned (zA nt.val us) j').val = aligned.val + j' * 2 ^ (zA nt.val us).val := bjA_val (by omega) + have := congrArg UScalar.val e + rw [e1, e2] at this + exact Nat.eq_of_mul_eq_mul_right hz (by omega) + rcases hcap y hy with ⟨h, k⟩ | ⟨j, hj, hyd, k⟩ | ⟨a, b, d, f, k⟩ | k + · refine Or.inl ⟨y, h, k ▸ hU, fun z hz hk => ?_⟩ + by_cases ez : z = y + · exact Or.inl ez + rcases hcap z hz with ⟨h2, k2⟩ | ⟨j, hj, hzd, k2⟩ | ⟨a, b, d, f, k2⟩ | k2 + · exact Or.inr ⟨z, h2, k2 ▸ hk, ez⟩ + · exact absurd (utNewCap_ptKindA (k2 ▸ hk)) (oldPt y h r (k ▸ hU.kind) j hj) + · exact absurd (k2 ▸ hk) (rkP a b d f) + · exact absurd (k2 ▸ hk) rkPN + · have hrb : r = bjA aligned (zA nt.val us) j := utNewCap_ptKindA (k ▸ hU.kind) + refine Or.inr fun z hz hk => ?_ + rcases hcap z hz with ⟨h2, k2⟩ | ⟨j', hj', hzd, k2⟩ | ⟨a, b, d, f, k2⟩ | k2 + · exact absurd hrb (oldPt z h2 r (k2 ▸ hk) j hj) + · have := bjinj j j' hj hj' (hrb.symm.trans (utNewCap_ptKindA (k2 ▸ hk))) + subst this; rw [hzd, hyd] + · exact absurd (k2 ▸ hk) (rkP a b d f) + · exact absurd (k2 ▸ hk) rkPN + · exact absurd (k ▸ hU.kind) (rkP a b d f) + · exact absurd (k ▸ hU.kind) rkPN · refine utRt_vcpuCoreA (Z := Z) (Z' := utRtZA Z G' nt us aligned win Tn Cn Vn) (Tn := Tn) (Vn := Vn) J.j.2.1 rfl rfl (fun v hv => H'.vcW hv) (fun t ht => ⟨(H'.tcbW ht).2.2.2.1, (H'.tcbW ht).2.2.2.2⟩) kvh kth bvc hnv (fun t ht => ?_) (fun y hy q e => ?_) diff --git a/proofs/Fl4ProofsA64/P3/UtRtRecA.lean b/proofs/Fl4ProofsA64/P3/UtRtRecA.lean index b5752834b..d28f99300 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtRecA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtRecA.lean @@ -90,6 +90,7 @@ theorem utRt_recNoResetA Fl4ProofsA64.P1.W7.R.ST.IrqRunA st (utGA slot (djA dest off) Z.G.chains win.val) q ∧ (∀ y ∈ (utGA slot (djA dest off) Z.G.chains win.val).flatten, ∀ k, capA st q y = .IrqHandler k → y ∈ Z.G.chains.flatten ∧ capA st s2 y = .IrqHandler k)) + (hrevL : ∀ y ∈ OS, (∀ j, j < win.val → y ≠ djA dest off j) → Fl4ProofsA64.P1.W7.R.ST.revA st q y = Fl4ProofsA64.P1.W7.R.ST.revA st s2 y) -- the spec body {t : ApiObjectType} (htt : objTypeOfA nt.val = some t) (hus : us.val < 64) (hsc : nt.val = 5 → 7 ≤ us.val) {srcSlot : CslotPtr} (hxc : cslotAddrA srcSlot = slot) @@ -153,7 +154,7 @@ theorem utRt_recNoResetA utPA slot (djA dest off) Z.G.par win.val⟩) (Tn := UtOfTyA 1 nt us aligned win.val) (Cn := UtOfTyA 5 nt us aligned win.val) (Vn := UtOfTyA 12 nt us aligned win.val) (s' := q) J2 hx hc W h1 h2 w htt hus hxc hsrcS hlen hdst0 hr' - have KH := utRt_heapAllA J2 hx hc W h1 h2 Ec w dstNull hgrow hex hnew HW htt hus hsc hr' IC KSc + have KH := utRt_heapAllA J2 hx hc W h1 h2 Ec w dstNull (utRt_revKA hrevL dstNull Ec.new) hgrow hex hnew HW htt hus hsc hr' IC KSc obtain ⟨KS, hVs⟩ := utRt_sysAllA J ER noch hb0 arm ko j7at hvs hr J2 hx hc h1 h2 w hgrow hex hnew KSc -- `J5A` have hfree : ∀ q, UtNewA false nt us aligned win.val q → Z.th q = none := utRt_ipcFreeA J2 hx hc W h1 h2 @@ -170,7 +171,7 @@ theorem utRt_recNoResetA exact ⟨d, ⟨q, e1, hq⟩, e⟩) hfree newNull hgrow hex arm.2.1 KI.spec (fun x e => (KSc.hdt x e).2.1) have R6 := utRt_rec6A (G' := ⟨utGA slot (djA dest off) Z.G.chains win.val, utPA slot (djA dest off) Z.G.par win.val⟩) (Cn := UtOfTyA 5 nt us aligned win.val) - J2 hx hc W h1 h2 hn hus Ec w newNull TW VW htt KI.spec + J2 hx hc W h1 h2 hn hus Ec w newNull TW VW htt KI.spec ER.creation.grow (fun j hj => ER.creation.hn rfl j hj) 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 diff --git a/proofs/Fl4ProofsA64/P3/UtRtRecRstA.lean b/proofs/Fl4ProofsA64/P3/UtRtRecRstA.lean index c34c6c2fe..e69c8180b 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtRecRstA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtRecRstA.lean @@ -109,6 +109,7 @@ theorem utRt_recRstA Fl4ProofsA64.P1.W7.R.ST.IrqRunA st (utGA slot (djA dest off) Z0.G.chains win.val) q ∧ (∀ y ∈ (utGA slot (djA dest off) Z0.G.chains win.val).flatten, ∀ k, capA st q y = .IrqHandler k → y ∈ Z0.G.chains.flatten ∧ capA st s3 y = .IrqHandler k)) + (hrevL : ∀ y ∈ OS1, (∀ j, j < win.val → y ≠ djA dest off j) → Fl4ProofsA64.P1.W7.R.ST.revA st q y = Fl4ProofsA64.P1.W7.R.ST.revA st s3 y) -- the spec body {t : ApiObjectType} (htt : objTypeOfA nt.val = some t) (hus : us.val < 64) (hsc : nt.val = 5 → 7 ≤ us.val) {srcSlot : CslotPtr} (hxc : cslotAddrA srcSlot = slot) @@ -171,7 +172,7 @@ theorem utRt_recRstA utPA slot (djA dest off) Z0.G.par win.val⟩) (Tn := UtOfTyA 1 nt us aligned win.val) (Cn := UtOfTyA 5 nt us aligned win.val) (Vn := UtOfTyA 12 nt us aligned win.val) (s' := q) J2 hx hc W h1' h2 w htt hus hxc hsrcS hlen hdst0 hr' - have KH := utRt_heapAllA J2 hx hc W h1' h2 Ec w dstNull hgrow hex hnew HW htt hus hsc hr' IC KSc + have KH := utRt_heapAllA J2 hx hc W h1' h2 Ec w dstNull (utRt_revKA hrevL dstNull Ec.new) hgrow hex hnew HW htt hus hsc hr' IC KSc obtain ⟨KS, hVs⟩ := utRt_sysRstA J ER hb0 arm ko j7at cs pp s1' t2 x y v offr offr2 vc0 J2 hx hc h1 h2 w hgrow hex hnew KSc -- `J5A` @@ -189,7 +190,7 @@ theorem utRt_recRstA exact ⟨d, ⟨q, e1, hq⟩, e⟩) hfree newNull hgrow hex (cs.symm ▸ arm.2.1) KI.spec (fun x e => (KSc.hdt x e).2.1) have R6 := utRt_rec6A (G' := ⟨utGA slot (djA dest off) Z0.G.chains win.val, utPA slot (djA dest off) Z0.G.par win.val⟩) (Cn := UtOfTyA 5 nt us aligned win.val) - J2 hx hc W h1' h2 hn hus Ec w newNull TW VW htt KI.spec + J2 hx hc W h1' h2 hn hus Ec w newNull TW VW htt KI.spec ER.creation.grow (fun j hj => ER.creation.hn rfl j hj) 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 @@ -339,10 +340,10 @@ theorem utCreate_recRstA (hA : P0.ArchTotal ar) (WP.spec_and (untyped.retype.liveRWH (ar := ar) hA C hb0 a3) (WP.spec_and tcbW (WP.spec_and vcW (WP.spec_and hiW (WP.spec_and (utRetype_nfiA (ar := ar) hA C a3) (utRt_j5LoopA hA C hTr2 J2.j5.1.1 J2.j5.1.2.1 hrev a3)))))))) ?_ - rintro res ⟨⟨hok, Kall⟩, w, ⟨Ec, Xd, WT, -⟩, TR, VW, HW, ⟨nfi, hnv, cap'⟩, L5⟩ + rintro res ⟨⟨hok, Kall⟩, w, ⟨Ec, Xd, WT, -⟩, TR, VW, HW, ⟨nfi, hnv, cap'⟩, ⟨L5, hrevL⟩⟩ refine ⟨hok, fun r hr H'' Vn U0 Ac0 lo hi extra ER arm ko j7at => ?_⟩ exact utRt_recRstA J ER arm ko j7at cs pp s1' t2 x y v offr offr2 vc0 J2 hc2 W (by simpa using h1) h2 pos us39 hb0 - hc47 C.dn Ec Xd 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 + hc47 C.dn Ec Xd w WT (fun h => (TR h).1) (fun h => (TR h).2) VW HW hnv cap' L5 hrevL X.ty hus hsc rfl hsrc hlen hdst hdstA hr (Kall r hr) J2.utWin J2.j.1.irq.nodeHi J2.coresAll end diff --git a/proofs/Fl4ProofsA64/P3/UtRtRecTopA.lean b/proofs/Fl4ProofsA64/P3/UtRtRecTopA.lean index c921b0dde..b6a93c6b0 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtRecTopA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtRecTopA.lean @@ -197,12 +197,12 @@ theorem utCreate_recA (hA : P0.ArchTotal ar) (WP.spec_and (untyped.retype.liveRWH (ar := ar) hA C hb0 a) (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⟩ + rintro res ⟨⟨hok, Kall⟩, w, ⟨-, -, WT, -⟩, TR, VW, HW, ⟨nfi, hnv, cap'⟩, ⟨L5, hrevL⟩⟩ 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 + (fun h => (TR h).1) (fun h => (TR h).2) VW HW hnv cap' L5 hrevL X.ty hus hsc rfl hsrc hlen hdst hdstA hr (Kall r hr) J2.utWin J2.j.1.irq.nodeHi J2.coresAll end diff --git a/proofs/Fl4ProofsA64/P3/UtRtResetCrtA.lean b/proofs/Fl4ProofsA64/P3/UtRtResetCrtA.lean index df7e1e267..287012337 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtResetCrtA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtResetCrtA.lean @@ -100,7 +100,8 @@ theorem utDecode_resetPostA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (h (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) + SActA σ → (∀ u, σ.schedulerAction ≠ .switchThread u) → + ∀ b, VsR (L.ksb s) (utVsPtA st (dropSetA (utDA p sb.val) Pp) Tb Lv s) 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 ⦄) diff --git a/proofs/Fl4ProofsA64/P3/UtRtResetPpA.lean b/proofs/Fl4ProofsA64/P3/UtRtResetPpA.lean index ef299d1cc..0bb823101 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtResetPpA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtResetPpA.lean @@ -46,7 +46,8 @@ theorem utRetype_resetPpA [Fact (n ≤ Fl4SpecA64.fl4A64Platform.numNodes)] (ar (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) → - ∀ b, VsR (L.ksb s) (dropSetA (utDA p sb.val) Pp ∪ Tb) b → Aligned b ∧ ¬ PPW st s b) + SActA σ → (∀ u, σ.schedulerAction ≠ .switchThread u) → + ∀ b, VsR (L.ksb s) (utVsPtA st (dropSetA (utDA p sb.val) Pp) Tb Lv s) 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 ⦄) diff --git a/proofs/Fl4ProofsA64/P3/UtRtTcbPostA.lean b/proofs/Fl4ProofsA64/P3/UtRtTcbPostA.lean index bb788ee6c..6b5a576a5 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtTcbPostA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtTcbPostA.lean @@ -171,7 +171,7 @@ theorem utRt_tcbPostA have : K = k := by omega exact absurd (this ▸ hK) ni have hcap : ∀ y, IsSlotA (utRtThA Z.th false nt us aligned win.val) y → - UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win.val y := by + UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win.val (djA dest off) y := by intro y hy by_cases old : IsSlotA Z.th y · by_cases ex : y = x @@ -179,7 +179,7 @@ theorem utRt_tcbPostA exact Or.inr (Or.inr (Or.inl ⟨p, sb, nfi, false, by rw [ex]; exact e⟩)) · by_cases ed : ∃ j < win.val, y = djA dest off j · obtain ⟨j, hj, e⟩ := ed - exact Or.inr (Or.inl ⟨j, hj, by rw [e]; exact Ec.new j hj⟩) + exact Or.inr (Or.inl ⟨j, hj, e, by rw [e]; exact Ec.new j hj⟩) · exact Or.inl ⟨old, Ec.keep y (hsub y old) ex (fun j hj e => ed ⟨j, hj, e⟩)⟩ · refine Or.inr (Or.inr (Or.inr ?_)) obtain ⟨q, h⟩ := hy @@ -230,7 +230,7 @@ theorem utRt_tcbPostA have et : t = .tcbObject := by rw [n1] at htt simpa [objTypeOfA, eq_comm] using htt - refine utRt_postA (Tn := utBasesA aligned (zA nt.val us) win.val) (Cn := ∅) (Vn := ∅) J hx hc W h1 h2 hn + refine utRt_postA (hsub := hsub) (Tn := utBasesA aligned (zA nt.val us) win.val) (Cn := ∅) (Vn := ∅) J hx hc W h1 h2 hn (fun h => by omega) w hS hC P' har (utRtBody_globA hr) hkeep (fun q => ?_) (fun c h => h.elim) (fun v h => h.elim) (fun h => absurd h z12) hcap (fun q h => ?_) (fun c h => h.elim) (fun v h => h.elim) (fun q h => ?_) (fun q h => ?_) (fun y h => absurd h.1 z14) (fun q y h => ?_) (fun q es h => ?_) diff --git a/proofs/Fl4ProofsA64/P3/UtRtVcpuPostA.lean b/proofs/Fl4ProofsA64/P3/UtRtVcpuPostA.lean index d951b0c0e..4dcddfd0e 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtVcpuPostA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtVcpuPostA.lean @@ -135,7 +135,7 @@ theorem utRt_vcpuPostA rw [hNew gt q ((memA q).2 gq)] at h exact (Option.some.inj h).symm have hcap : ∀ y, IsSlotA (utRtThA Z.th false nt us aligned win.val) y → - UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win.val y := by + UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win.val (djA dest off) y := by intro y hy by_cases old : IsSlotA Z.th y · by_cases ex : y = x @@ -143,7 +143,7 @@ theorem utRt_vcpuPostA exact Or.inr (Or.inr (Or.inl ⟨p, sb, nfi, false, by rw [ex]; exact e⟩)) · by_cases ed : ∃ j < win.val, y = djA dest off j · obtain ⟨j, hj, e⟩ := ed - exact Or.inr (Or.inl ⟨j, hj, by rw [e]; exact Ec.new j hj⟩) + exact Or.inr (Or.inl ⟨j, hj, e, by rw [e]; exact Ec.new j hj⟩) · exact Or.inl ⟨old, Ec.keep y (hsub y old) ex (fun j hj e => ed ⟨j, hj, e⟩)⟩ · refine Or.inr (Or.inr (Or.inr ?_)) obtain ⟨q, h⟩ := hy @@ -170,7 +170,7 @@ theorem utRt_vcpuPostA rw [n12] at htt simpa [objTypeOfA, archDataToObjType, eq_comm] using htt rw [← utRtMA_empty m] - refine utRt_postA (Tn := ∅) (Cn := ∅) (Vn := utBasesA aligned (zA nt.val us) win.val) J hx hc W h1 h2 hn + refine utRt_postA (hsub := hsub) (Tn := ∅) (Cn := ∅) (Vn := utBasesA aligned (zA nt.val us) win.val) J hx hc W h1 h2 hn (fun h => by omega) w hS hC P' har (utRtBody_globA hr) hkeep (fun q => ⟨fun h => h.elim, fun h => absurd h.2 z1⟩) (fun c h => h.elim) (fun v h => h) (fun _ v h => h) hcap (fun q h => h.elim) (fun c h => h.elim) (fun v h => ?_) (fun q h => ?_) (fun q h => ?_) (fun y h => absurd h.1 z14) (fun q y h => ?_) diff --git a/proofs/Fl4ProofsA64/P3/UtRtVsUniqA.lean b/proofs/Fl4ProofsA64/P3/UtRtVsUniqA.lean new file mode 100644 index 000000000..95170f89e --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/UtRtVsUniqA.lean @@ -0,0 +1,151 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`): **`VsUniqA` across a creation's growth of the VSpace sets** +(`utGrow_vsUniqA`): from `UtVsGrowA` (only unreferenced objects join `Tb`, `X`, `Y`) and the new caps being old +page-table caps or unmapped ones naming no Stage-2 table. Every walk of the grown sets is an old one. No named premise. +New module. +-/ +import Fl4ProofsA64.P3.UtVsGrowA +import Fl4ProofsA64.P3.VsUniqShrinkA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Classical + +local notation "wa" => core.num.U64.wrapping_add + +variable {th th' : TypedHeapA} {Pp Tb Tb' X X' Y Y' T2 : Set U64} {Lv Lv' Sh2 : U64 → Nat} {mem mem' : U64 → U64} + {ksb : U64} {σ σ' : Fl4SpecA64.State Unit} + +theorem utGrow_vsUniqA (V : VsRelA Pp Tb Lv X Y mem ksb σ) (E : ExtVsRelA Pp Tb X Y T2 Sh2 mem σ) + (G : UtVsGrowA Pp Tb Tb' X X' Y Y' T2 Lv Lv' mem mem' ksb σ σ') + (U : VsUniqA th Pp Tb X Y T2 Sh2 mem ksb σ) + (hc : ∀ y, IsSlotA th' y → ∀ ptr asid va : U64, ∀ mp : Bool, capAtA mem' y = .PageTable ptr mp asid va → + (∃ y0, IsSlotA th y0 ∧ capAtA mem y0 = .PageTable ptr mp asid va) ∨ (mp = false ∧ ptr ∉ T2)) + (hr : ∀ y, IsSlotA th' y → ∀ r, RootUnmA r (capAtA mem' y) → + (∃ y0, IsSlotA th y0 ∧ RootUnmA r (capAtA mem y0) ∧ ∀ z, IsSlotA th' z → RootKindA r (capAtA mem' z) → + z = y ∨ ∃ s, IsSlotA th s ∧ RootKindA r (capAtA mem s) ∧ s ≠ y0) ∨ + -- a root the creation just made: in no set, the only root-kind cap of its object + (r ∉ Tb ∧ r ∉ X ∧ r ∉ Y ∧ ∀ z, IsSlotA th' z → RootKindA r (capAtA mem' z) → z = y)) + (hpr : ∀ y, IsSlotA th' y → ∀ r, PtUnmA r (capAtA mem' y) → + (∃ y0, IsSlotA th y0 ∧ PtUnmA r (capAtA mem y0) ∧ ∀ z, IsSlotA th' z → PtKindA r (capAtA mem' z) → + z = y ∨ ∃ s, IsSlotA th s ∧ PtKindA r (capAtA mem s) ∧ s ≠ y0) ∨ + -- a table the creation just made: the only `PageTable` cap of its object + ∀ z, IsSlotA th' z → PtKindA r (capAtA mem' z) → z = y) : + VsUniqA th' Pp Tb' X' Y' T2 Sh2 mem' ksb σ' := by + -- Stage 2: entries and roots of the grown sets are old ones, with their words + have e2 : ∀ w, S2EntryA Pp X' T2 Sh2 mem' σ' w → S2EntryA Pp X T2 Sh2 mem σ w ∧ mem' w = mem w := by + intro w hw + have hold : S2EntryA Pp X T2 Sh2 mem σ w := by + rcases hw with ⟨r, i, hr, hi, e⟩ | ⟨t, i, hr, ht, h12, hi, e⟩ + · exact Or.inl ⟨r, i, utS2Root_oldA V G hr, hi, e⟩ + · exact Or.inr ⟨t, i, utS2Reach_oldA V E G hr, ht, h12, hi, e⟩ + exact ⟨hold, G.kext _ (hold.foot E.xal)⟩ + have root2 : ∀ asid r, S2RootOfAsidA Pp X' σ' asid r → S2RootOfAsidA Pp X σ asid r := by + intro asid r h + have ha := utS2Root_oldA V G h.active + obtain ⟨-, p, f, h0, hp, ht, hk, hf⟩ := h + rw [G.ktab] at ht + rw [G.kheap p (Or.inl hp)] at hk + exact ⟨ha.1, p, f, h0, hp, ht, hk, hf⟩ + have root2up : ∀ asid r, S2RootOfAsidA Pp X σ asid r → S2RootOfAsidA Pp X' σ' asid r := by + rintro asid r ⟨hr, p, f, h0, hp, ht, hk, hf⟩ + exact ⟨G.xs hr, p, f, h0, hp, by rw [G.ktab]; exact ht, by rw [G.kheap p (Or.inl hp)]; exact hk, hf⟩ + -- Stage 1: walks of the grown sets are old ones, in old tables, with their words + have e1 : ∀ tag sh t (i : U64), VsPathA Pp Tb' Y' mem' ksb tag sh t → i.val < 512 → + VsPathA Pp Tb Y mem ksb tag sh t ∧ S1TabA Tb Y t ∧ mem' (peAF t i) = mem (peAF t i) := by + intro tag sh t i hp hi + have hold := utVsPath_oldA V G hp + rcases (V.path_props hold).2 with ⟨ht, -, -⟩ | ⟨-, -, y, hy, -, rfl⟩ + · exact ⟨hold, Or.inl ht, G.kmem _ (.pt t i ht hi)⟩ + · exact ⟨hold, Or.inr ⟨y, hy, rfl⟩, G.kmem _ (.high y i hy hi)⟩ + have act1 : ∀ asid raw, ActiveAsidRootA mem ksb Pp asid raw → ActiveAsidRootA mem' ksb Pp asid raw := by + rintro asid raw ⟨hi, lo, h1, h2, h3, pool, hp, h0, h4, h5, h6⟩ + exact ⟨hi, lo, h1, h2, h3, pool, hp, h0, (G.asid h1).trans h4, (G.kmem _ (.pool pool lo hp h2)).trans h5, h6⟩ + -- a Stage-2 walk reads old words only + have w2 : ∀ va t sh n w, WalkSlotA (· ∈ T2) mem va t sh n w → S2WalkTabA Pp X T2 Sh2 mem σ t sh n → + WalkSlotA (· ∈ T2) mem' va t sh n w := by + intro va t sh n w W + induction W with + | here t sh n => intro _; exact .here t sh n + | @down t sh n w h3 h12 hP W' ih => + intro ht + have hn := ht.n_pos + have hi := walkIdx_lt va sh n hn.1 hn.2 + obtain ⟨ht', hent⟩ := S2WalkTabA.step E ht hi h3 h12 hP + have em : mem' (peAF t (walkIdx va sh n)) = mem (peAF t (walkIdx va sh n)) := G.kext _ (hent.foot E.xal) + exact .down t sh n w (by rw [em]; exact h3) h12 (by rw [em]; exact hP) (by rw [em]; exact ih ht') + have w1 : ∀ va t sh n w, WalkSlotA (S1TabA Tb Y) mem va t sh n w → n = 512 → + (∃ tag, VsPathA Pp Tb Y mem ksb tag sh t) → S1TabA Tb Y t → WalkSlotA (S1TabA Tb' Y') mem' va t sh n w := by + intro va t sh n w W + induction W with + | here t sh n => intro _ _ _; exact .here t sh n + | @down t sh n w h3 h12 hP W' ih => + intro hn ht htb + subst hn + have hi := walkIdx_lt va sh 512 (by norm_num) (by norm_num) + obtain ⟨tag, hp⟩ := ht + have em : mem' (peAF t (walkIdx va sh 512)) = mem (peAF t (walkIdx va sh 512)) := by + rcases htb with h | ⟨y, hy, rfl⟩ + · exact G.kmem _ (.pt t _ h hi) + · exact G.kmem _ (.high y _ hy hi) + have hP' : S1TabA Tb' Y' (dTabA (mem (peAF t (walkIdx va sh 512)))) := + hP.imp (fun h => G.tb h) fun ⟨y, hy, e⟩ => ⟨y, G.ys hy, e⟩ + exact .down t sh 512 w (by rw [em]; exact h3) h12 (by rw [em]; exact hP') + (by rw [em]; exact ih rfl ⟨tag, .child hp htb h12 hi h3⟩ hP) + exact + { t2 := fun y hy ptr asid va hcap hT w hw h3 hd => by + obtain ⟨y0, hy0, hc0⟩ := (hc y hy ptr asid va true hcap).resolve_right (fun h => by cases h.1) + obtain ⟨hw0, em⟩ := e2 w hw + rw [em] at h3 hd + obtain ⟨r, hr, hws⟩ := U.t2 y0 hy0 ptr asid va hc0 hT w hw0 h3 hd + exact ⟨r, root2up _ _ hr, w2 _ _ _ _ _ hws (Or.inl ⟨hr.active, rfl, rfl⟩)⟩ + s1 := fun y hy ptr asid va hcap _ tag sh t i hpath _ h12 hi h3 hd => by + obtain ⟨y0, hy0, hc0⟩ := (hc y hy ptr asid va true hcap).resolve_right (fun h => by cases h.1) + obtain ⟨hp0, htb0, em⟩ := e1 tag sh t i hpath hi + rw [em] at h3 hd + have hS : ptr ∈ Tb := hd ▸ V.child_tb hp0 htb0 h12 hi h3 + obtain ⟨raw, hact, hw⟩ := U.s1 y0 hy0 ptr asid va hc0 hS tag sh t i hp0 htb0 h12 hi h3 hd + refine ⟨raw, act1 _ _ hact, ?_⟩ + rcases hw with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · exact Or.inl ⟨h0, G.tb hr, w1 _ _ _ _ _ hws rfl ⟨0#u64, .native hact h0 hr⟩ (Or.inl hr)⟩ + · exact Or.inr ⟨h2, G.ys hy2, w1 _ _ _ _ _ hws rfl ⟨2#u64, .high hact h2 hy2⟩ + (Or.inr ⟨untagA raw, hy2, rfl⟩)⟩ + out := fun y hy ptr asid va hcap => by + rcases hc y hy ptr asid va false hcap with ⟨y0, hy0, hc0⟩ | h + · exact U.out y0 hy0 ptr asid va hc0 + · exact h.2 + inj2 := fun a b ha hb va vb e hT => by + obtain ⟨ha0, ea⟩ := e2 a ha + obtain ⟨hb0, eb⟩ := e2 b hb + rw [ea] at va e hT + rw [eb] at vb e + exact U.inj2 a b ha0 hb0 va vb e hT + rootInj2 := fun a1 a2 r h1 h2 => U.rootInj2 a1 a2 r (root2 _ _ h1) (root2 _ _ h2) + inj1 := fun tag tag' sh sh' t t' i i' p1 _ s1 i1 v1 p2 _ s2 i2 v2 e _ => by + obtain ⟨q1, b1, m1⟩ := e1 tag sh t i p1 i1 + obtain ⟨q2, b2, m2⟩ := e1 tag' sh' t' i' p2 i2 + rw [m1] at v1 e + rw [m2] at v2 e + exact U.inj1 tag tag' sh sh' t t' i i' q1 b1 s1 i1 v1 q2 b2 s2 i2 v2 e (V.child_tb q1 b1 s1 i1 v1) + rootInj1 := fun a1 a2 raw h1 h2 => U.rootInj1 a1 a2 raw (G.root h1) (G.root h2) + rootOnce := fun y hy r h => by + have hI : RootInstA Pp X' mem' ksb σ' r → RootInstA Pp X mem ksb σ r := fun hi => + hi.imp (fun ⟨a, raw, h, e⟩ => ⟨a, raw, G.root h, e⟩) (fun ⟨a, h⟩ => ⟨a, root2 _ _ h⟩) + rcases hr y hy r h with ⟨y0, hy0, h0, hz⟩ | ⟨h1, h2, h3, hz⟩ + · obtain ⟨hn, hu⟩ := U.rootOnce y0 hy0 r h0 + refine ⟨fun hi => hn (hI hi), fun z hz' hk => ?_⟩ + rcases hz z hz' hk with e | ⟨s, hs, hks, hne⟩ + · exact e + · exact absurd (hu s hs hks) hne + · refine ⟨fun hi => ?_, hz⟩ + rcases (hI hi |>.mem V) with h | h | h + exacts [h1 h, h2 h, h3 h] + ptOnce := fun y hy r h => by + rcases hpr y hy r h with ⟨y0, hy0, h0, hz⟩ | hz + · refine fun z hz' hk => ?_ + rcases hz z hz' hk with e | ⟨s, hs, hks, hne⟩ + · exact e + · exact absurd (U.ptOnce y0 hy0 r h0 s hs hks) hne + · exact hz } + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/UtRtZeroPostA.lean b/proofs/Fl4ProofsA64/P3/UtRtZeroPostA.lean index fb7020412..a17d3712d 100644 --- a/proofs/Fl4ProofsA64/P3/UtRtZeroPostA.lean +++ b/proofs/Fl4ProofsA64/P3/UtRtZeroPostA.lean @@ -177,7 +177,7 @@ theorem utRt_zeroPostA unfold Aligned omega have hcap : ∀ y, IsSlotA (utRtThA Z.th false nt us aligned win.val) y → - UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win.val y := by + UtCapAfterA Z.th (L.mem s) (L.mem s') nt us aligned win.val (djA dest off) y := by intro y hy by_cases old : IsSlotA Z.th y · by_cases ex : y = x @@ -185,7 +185,7 @@ theorem utRt_zeroPostA exact Or.inr (Or.inr (Or.inl ⟨p, sb, nfi, false, by rw [ex]; exact e⟩)) · by_cases ed : ∃ j < win.val, y = djA dest off j · obtain ⟨j, hj, e⟩ := ed - exact Or.inr (Or.inl ⟨j, hj, by rw [e]; exact Ec.new j hj⟩) + exact Or.inr (Or.inl ⟨j, hj, e, by rw [e]; exact Ec.new j hj⟩) · exact Or.inl ⟨old, Ec.keep y (hsub y old) ex (fun j hj e => ed ⟨j, hj, e⟩)⟩ · refine Or.inr (Or.inr (Or.inr ?_)) obtain ⟨q, h⟩ := hy @@ -238,7 +238,7 @@ theorem utRt_zeroPostA have hCnb : ∀ c ∈ utCNewA nt aligned (zA nt.val us) win.val, c ∈ utBasesA aligned (zA nt.val us) win.val := fun c h => h.2 rw [← utRtMA_empty m] - refine utRt_postA (Tn := ∅) (Cn := utCNewA nt aligned (zA nt.val us) win.val) (Vn := ∅) J hx hc W h1 h2 hn hr4 w + refine utRt_postA (hsub := hsub) (Tn := ∅) (Cn := utCNewA nt aligned (zA nt.val us) win.val) (Vn := ∅) J hx hc W h1 h2 hn hr4 w hS hC P' har (utRtBody_globA hr) hkeep (fun q => ⟨fun h => h.elim, fun h => absurd h.2 z1⟩) hCnb (fun v h => h.elim) (fun h => absurd h z12) hcap (fun q h => h.elim) (fun c h => ?_) (fun v h => h.elim) (fun q h => ?_) (fun q h => ?_) (fun y h => absurd h.1 z14) (fun q y h => ?_) (fun q es h => ?_) diff --git a/proofs/Fl4ProofsA64/P3/UtSbufA.lean b/proofs/Fl4ProofsA64/P3/UtSbufA.lean index e75ea92fd..ba408e4d4 100644 --- a/proofs/Fl4ProofsA64/P3/UtSbufA.lean +++ b/proofs/Fl4ProofsA64/P3/UtSbufA.lean @@ -148,7 +148,7 @@ theorem utSbufG_keptA {dev : Bool} unfold ipcBufOfA at hb rw [← hab] at hb cases hb - have hF' := FrameOK.reset R.fr htr.ut R.src hcx hnd (OS' := OffR p.val (p.val + 2 ^ sb.val) OS) (fun y hy => hy.1) + have hF' := FrameOK.reset R.fr htr.ut R.src hcx hnd hRin (OS' := OffR p.val (p.val + 2 ^ sb.val) OS) (fun y hy => hy.1) (s' := s) (i' := fi) hcx (fun _ _ _ => rfl) rw [hc] at hab hNative have hept : x2 = false := hNative @@ -156,10 +156,13 @@ theorem utSbufG_keptA {dev : Bool} obtain ⟨bits', hbits⟩ : ∃ bits', size.bits = ok bits' := by cases size <;> exact ⟨_, rfl⟩ have hobj := hF' _ hsbK ptr size rights x1 false x3 x4 hc bits' hbits - obtain ⟨hnR, hqH⟩ := Heap.drop_eq_some.1 hobj - have kp : specPtr ptr ∉ utDA p sb.val := fun h => hnR ((hbr ptr _ hqH).1 h) - have hfit := hH.fits ptr _ hqH - simp only [HKind.bits] at hfit + obtain ⟨hqH0, hnR⟩ := FrAt.undrop hobj + have hf1 : 1 ≤ 2 ^ bits'.val := Nat.one_le_two_pow + have kp : specPtr ptr ∉ utDA p sb.val := fun h => hnR (by + have := (utD_memA hsb hpfit hsp ptr).1 h + unfold MeetsR; omega) + have hfit := hqH0.fits hH + obtain ⟨b0, k0, hb0, hbk0, hb01, hb02⟩ := hqH0.obj have hpg : pageBitsForSize (frameSizeOfA size) = bits'.val ∧ 10 ≤ bits'.val ∧ bits'.val < 64 := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> exact ⟨by decide, by decide, by decide⟩ @@ -194,8 +197,8 @@ theorem utSbufG_keptA {dev : Bool} rw [wa_valP] exact Nat.mod_eq_of_lt (by omega) have hpos : 0 < 2 ^ bits'.val := Nat.two_pow_pos _ - exact ut_jointA J.objAlloc R.src hcx hfi hD (Or.inr (Or.inr (Or.inr ⟨_, hqH, rfl⟩))) (a := ptr) (b := wa ptr o) - (le_refl _) (by simp only [HKind.bits]; omega) (by omega) (by simp only [HKind.bits]; omega) kp + exact ut_jointA J.objAlloc R.src hcx hfi hD (Or.inr (Or.inr (Or.inr ⟨_, hb0, rfl⟩))) (a := ptr) (b := wa ptr o) + hb01 (by simp only [HKind.bits]; omega) (by omega) (by simp only [HKind.bits]; omega) kp /-- **A retained thread's spec IPC buffer misses a childless RAM untyped** (module docstring). -/ theorem utSbuf_keptA diff --git a/proofs/Fl4ProofsA64/P3/UtVcTrA.lean b/proofs/Fl4ProofsA64/P3/UtVcTrA.lean index b54eb0a3a..5b233ec57 100644 --- a/proofs/Fl4ProofsA64/P3/UtVcTrA.lean +++ b/proofs/Fl4ProofsA64/P3/UtVcTrA.lean @@ -158,7 +158,10 @@ theorem utVc_jatA (J : JAtZAX (L := L) AR Z s a σ m) : JAtZAX (L := L) AR Z s a rcases hq with hq | hq | hq · have g := J.vs.pool q hq; rw [e] at g; simp at g · have g := J.ext.s2root q hq; rw [e] at g; simp at g - · have g := J.ext.s2pt q hq; rw [e] at g; simp at g } + · have g := J.ext.s2pt q hq; rw [e] at g; simp at g + vsu := J.vsu.of_frame J.ext.xal (fun _ _ => rfl) ⟨by rw [H.arch], fun p hp => H.same fun x e => by + obtain ⟨_, k, -⟩ := J.vs.pool p hp + rw [e] at k; cases k⟩ (PtClosedA.refl _ _ _ _) } refine ⟨J', ?_, ?_, ?_⟩ · refine ⟨fun v hv => ?_, fun p y e => ?_, fun t ht => ?_, V.cap⟩ · obtain ⟨x, h, h1, h2⟩ := V.obj v hv @@ -281,8 +284,8 @@ theorem utVc_nullOrigA (h : ∀ sl, specCapAtA σ sl = some .nullCap → σ.isOr theorem utVc_devFrA {Hp : Heap} {OS : Set U64} (h : DevFrDisjA st Hp OS s σ) : DevFrDisjA st Hp OS s τ := DevFrDisjA.keepA (fun _ _ => rfl) (fun _ _ _ g => H.keep g (fun _ e => by cases e)) h -theorem utVc_userFrA {OS : Set U64} (h : UserFrSpecA st OS s σ) : UserFrSpecA st OS s τ := - h.keepA (fun _ _ => rfl) (fun _ _ _ g => H.keep g (fun _ e => by cases e)) +theorem utVc_userFrA {Hp : Heap} {OS : Set U64} (h : UserFrSpecA st Hp OS s σ) : UserFrSpecA st Hp OS s τ := + h.keepA (fun _ _ => rfl) (fun _ _ e => e) (fun _ _ _ g => H.keep g (fun _ e => by cases e)) theorem utVc_finCovA {th : TypedHeapA} (h : FinCovA th σ) : FinCovA th τ := ⟨fun q r cs g w => h.cnode q r cs (H.back g (fun _ e => by cases e)) w, diff --git a/proofs/Fl4ProofsA64/P3/VcpuCheckJA.lean b/proofs/Fl4ProofsA64/P3/VcpuCheckJA.lean index 090770faa..5af372969 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuCheckJA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuCheckJA.lean @@ -253,7 +253,14 @@ theorem VcpuXferStateA.ntfn_set_idle {AR : A → HwRootA → Prop} {Z : XSetsA} scOffD := X.j.1.scOffD, cv := fun y hy => by rw [hcap_sl y (Or.inl hy)]; exact X.j.1.cv y hy, pml := fun y hy p mp asid hc => by rw [hcap_sl y (Or.inl hy)] at hc; exact X.j.1.pml y hy p mp asid hc, - vs := hVs, ext := hExt } + vs := hVs, ext := hExt, + vsu := by + rw [hksb1] + exact X.j.1.vsu.of_frame X.j.1.ext.xal (fun b hb => hb.elim + (fun hb => hwr_ne (hND.ext_al b hb) (fun e => hND.ne_ext (e ▸ hb))) + (fun hb => hwr_ne (hND.vs_al b hb) (fun e => hND.ne_vs (e ▸ hb)))) + ⟨rfl, fun p hp => hVs_kh _ (Or.inl ⟨p, hp, rfl⟩)⟩ + (PtClosedA.of_cap fun y hy => Or.inl (hcap_sl y (Or.inl hy))) } have hS2 : Stage2CoreA (L := L) Z s1 σ1 := ⟨fun r hr => by rw [hExt_kh r (Or.inr (Or.inl hr))]; exact X.j.2.2.1.obj r hr, fun p es h => by diff --git a/proofs/Fl4ProofsA64/P3/VcpuDelFinHookA.lean b/proofs/Fl4ProofsA64/P3/VcpuDelFinHookA.lean index 643cfd636..40265ab25 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuDelFinHookA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuDelFinHookA.lean @@ -214,7 +214,7 @@ theorem vcpuHookA {ipa : U64} (s0 : S) have hpv : layout.PPTR_BASE.val = 18446603336221196288 := by unfold layout.PPTR_BASE; rfl rw [h0v, hpv] at hwin omega - have R6 : VcpuRec6A st { Z with G := G, Q := Q, R := R, hw := hw } OS Bf s σ := + have R6 : VcpuRec6A st { Z with G := G, Q := Q, R := R, hw := hw } H OS Bf s σ := { snap := X.vcSnap, vcSym1 := X.vcSym1, vcSym2 := X.vcSym2, vcBack := X.vcBack, runBack := X.runBack, vcOS := X.vcOS, frOff := X.frOff, userFr := X.userFr, frTh := X.frTh, bfSpec := X.bfSpec } diff --git a/proofs/Fl4ProofsA64/P3/VcpuDelFrameA.lean b/proofs/Fl4ProofsA64/P3/VcpuDelFrameA.lean index bf033ada5..eba7a292d 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuDelFrameA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuDelFrameA.lean @@ -113,7 +113,7 @@ instance j7FrA_j7LA {S : Type} {st : machine.Store S} [L : LawfulStore st] /-- Record-edit #6 per-step facts carried alongside `JStage3TA` (projected directly from `JStage3A` and `DelRecA`). -/ structure VcpuRec6A {S : Type} (st : machine.Store S) [L : LawfulStore st] - (Z : XSetsA) (OS : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) + (Z : XSetsA) (H : Heap) (OS : Set U64) (Bf : Set (U64 × Fl4SpecA64.Word)) (s : S) (σ : Fl4SpecA64.State Unit) : Prop where snap : VcpuStateSnapA Z.V (L.mem s) σ vcSym1 : VcSym1A st Z.T s @@ -122,7 +122,7 @@ structure VcpuRec6A {S : Type} (st : machine.Store S) [L : LawfulStore st] runBack : ∀ t ∈ Z.T, L.mem s (runVcpuA t) ≠ 0#u64 → L.mem s (wa (L.mem s (runVcpuA t)) 24#u64) = t vcOS : ∀ b, VcW Z.V b → ¬ InOS OS b frOff : FrOff st Z.Cs OS (L.ksb s) s - userFr : UserFrSpecA st OS s σ + userFr : UserFrSpecA st H OS s σ frTh : FrThA st Z.th OS s bfSpec : ∀ bp ∈ Bf, bp.2 = specPtr bp.1 @@ -549,7 +549,7 @@ theorem JStage3VcpuCoreA.toJA (vcBack : ∀ v ∈ Z.V, L.mem s v ≠ 0#u64 → L.mem s (wa (L.mem s v) 3664#u64) = v) (runBack : ∀ t ∈ Z.T, L.mem s (runVcpuA t) ≠ 0#u64 → L.mem s (wa (L.mem s (runVcpuA t)) 24#u64) = t) (vcSnap : VcpuStateSnapA Z.V (L.mem s) σ) (vcOS : ∀ b, VcW Z.V b → ¬ InOS OS b) - (userFr : UserFrSpecA st OS s σ) (frTh : FrThA st Z.th OS s) (bfSpec : ∀ bp ∈ Bf, bp.2 = specPtr bp.1) : + (userFr : UserFrSpecA st H OS s σ) (frTh : FrThA st Z.th OS s) (bfSpec : ∀ bp ∈ Bf, bp.2 = specPtr bp.1) : JStage3A st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n J5 J7 s a σ m := { toJEntA := ⟨⟨J.ent, sysl⟩, J.j, J.tcbs, J.scs, J.sq, J.ap, J.pp, J.s1, J.ko, J.ptH, J.tabInj, J.poolOff, J.objAlloc, J.idleAnchor, J.vsVc⟩ @@ -575,7 +575,7 @@ omit [J7PpA st J7] [J7FrA st J7] in theorem JStage3VcpuCoreA.toJA_vcpuA {hw' : HwRootA} {a' : A} {σ' : Fl4SpecA64.State Unit} (J0 : 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) (J' : JStage3VcpuCoreA st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a' σ' m) - (hSV' : SchedValidA σ') (R6' : VcpuRec6A st { Z with hw := hw' } OS Bf s' σ') + (hSV' : SchedValidA σ') (R6' : VcpuRec6A st { Z with hw := hw' } H OS Bf s' σ') (osk : OSKeep st OS s s') (sysl : SysL st H Z.Cs OS ia ie s') (symL : SymL st H Z.Cs s') : JStage3A st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a' σ' m := have capE : ∀ y ∈ OS, capA st s' y = capA st s y := fun y hy => osk.capA hy @@ -640,7 +640,8 @@ private theorem vcpuWr_inHeapA · exact Or.inr (Or.inr rfl) have ev : (wa t K).val = t.val + K.val := by rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) exact Or.inr (Or.inl ⟨t, ht, htH, K, hKv, ev⟩) - · exact Or.inr (Or.inr ⟨ptr, bits.val, fo y hy ptr sz r mp ept asid va hc bits hbits, h1, h2⟩) + · obtain ⟨q, z, hq, hbz, hq1, hq2⟩ := (fo y hy ptr sz r mp ept asid va hc bits hbits).obj + exact Or.inr (Or.inr ⟨q, z, hq, by omega, by omega⟩) omit [J7PpA st J7] in /-- No `OS` slot word lies in `VcpuWrNoStA` (core). -/ @@ -939,16 +940,28 @@ theorem vcpuSnap_off_vcpuWrCoreA have hne : v ≠ t := fun h => by rw [h, htH] at hH; cases hH have hd := J.ent.heap.disj v (.other 12) t .tcb hH htH hne change v.val + 4096 ≤ t.val ∨ t.val + 4096 ≤ v.val at hd; have := congrArg UScalar.val e; omega - · have hptrH := fo u hu ptr sz r mp ept asid va hc bits hbits + · have hFr := fo u hu ptr sz r mp ept asid va hc bits hbits + have h12 : 12 ≤ bits.val := by + cases sz <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp by_cases he : v = ptr · subst he - have hbits12 : bits.val = 12 := HKind.other.inj (Option.some.inj (hH.symm.trans hptrH)).symm - have hv_al : Aligned v := by - have := J.ent.heap.align v _ hH; change v.val % 4096 = 0 at this; show v.val % 8 = 0; omega - have hv_ub : v ∈ Ub := frub u hu v sz r mp ept asid va hc bits hbits v hv_al (le_refl _) (by rw [hbits12]; omega) - exact vcub.1 v ⟨v, hv, 0#u64, by simp, by simp, (wa_zeroVcA v).symm⟩ hv_ub - · have hd := J.ent.heap.disj v (.other 12) ptr (.other bits.val) hH hptrH he - change v.val + 4096 ≤ ptr.val ∨ ptr.val + 2 ^ bits.val ≤ v.val at hd; omega + obtain ⟨b0, k0, hb0, hbk, g1, g2⟩ := hFr.obj + have h1 : 1 ≤ 2 ^ bits.val := Nat.one_le_two_pow + have b0v : b0 = v := by + by_contra hne + have := J.ent.heap.disj b0 _ v _ hb0 hH hne + simp only [HKind.bits] at this + omega + subst b0v + rw [hH] at hb0 + have hk0 : k0 = 12 := HKind.other.inj (Option.some.inj hb0).symm + have hbits12 : bits.val = 12 := by omega + have hv_al : Aligned b0 := by + have := J.ent.heap.align b0 _ hH; change b0.val % 4096 = 0 at this; show b0.val % 8 = 0; omega + have hv_ub : b0 ∈ Ub := frub u hu b0 sz r mp ept asid va hc bits hbits b0 hv_al (le_refl _) (by rw [hbits12]; omega) + exact vcub.1 b0 ⟨b0, hv, 0#u64, by simp, by simp, (wa_zeroVcA b0).symm⟩ hv_ub + · have hd := hFr.off12 J.ent.heap h12 hH (Ne.symm he) + omega omit [J7PpA st J7] in /-- Every `VcpuStateSnapA` word (`v + 16`, `v + 32`, `v + 40`, `v + 64 + 8*i` for `i < 64`) @@ -1202,7 +1215,7 @@ set_option maxHeartbeats 1600000 in (serves both `JStage3TA.of_vcpuStepA` and `JStage3A.of_vcpuStepA` without requiring `SActA σ`). -/ theorem JStage3VcpuCoreA.of_vcpuStepA (J : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) {hw' : HwRootA} {regWr : Bool} (w : WritesIn st s s' (VcpuWrFootA st regWr Z OS s)) (HS : VcpuSpecStepA H σ σ' regWr) @@ -1543,7 +1556,15 @@ theorem JStage3VcpuCoreA.of_vcpuStepA pml := fun y hy p mp asid h => by have hyOS : y ∈ OS := J.j5.2.1 y hy unfold capAtA at h; rw [(osk y hyOS).1, (osk y hyOS).2.1] at h; exact J.j.1.pml y hy p mp asid h, - vs := vsRel', ext := extRel' } + vs := vsRel', ext := extRel' + vsu := by + rw [hk] + exact J.j.1.vsu.of_frame J.j.1.ext.xal (fun b hb => hb.elim (extfoot b) (vsfoot b)) + ⟨HS.asid, fun p hp => by + obtain ⟨f, hf, -⟩ := J.j.1.vs.pool p hp + rw [HS.keepObj hf (fun _ e => by cases e) (fun _ e => by cases e), hf]⟩ + (PtClosedA.of_cap fun y hy => Or.inl (by + unfold capAtA; rw [(osk y (J.j5.2.1 y hy)).1, (osk y (J.j5.2.1 y hy)).2.1])) } have s2Core' : Stage2CoreA (L := L) { Z with hw := hw' } s' σ' := ⟨fun r hr => let ⟨es, hes⟩ := J.j.2.2.1.obj r hr; ⟨es, HS.keepObj hes (fun _ e => by cases e) (fun _ e => by cases e)⟩, fun p es hp => J.j.2.2.1.back p es (HS.backObj hp (fun _ e => by cases e) (fun _ e => by cases e)), @@ -1954,7 +1975,7 @@ theorem JStage3VcpuCoreA.of_vcpuStepA origLive := fun x h => J.origLive x (by rw [HS.orig] at h; exact h) nullOrig := fun sl h => by rw [HS.orig]; exact J.nullOrig sl (by rw [← HS.specCapAt sl]; exact h) thPos := J.thPos - frBase := J.frBase.keepA capE + frBase := J.frBase.keepOS osk devFr := J.devFr.keepA capE fun p dev pg h => HS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) finCov := J.finCov.keepA (fun q r cs h => HS.backObj h (fun _ e => by cases e) (fun _ e => by cases e)) @@ -2036,7 +2057,7 @@ theorem _root_.Fl4ProofsA64.P3.SActA.of_vcpuStepA {H : Heap} {σ σ' : Fl4SpecA6 (wrapper over `JStage3VcpuCoreA.of_vcpuStepA`). -/ theorem JStage3TA.of_vcpuStepA (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) {hw' : HwRootA} {regWr : Bool} (w : WritesIn st s s' (VcpuWrFootA st regWr Z OS s)) (HS : VcpuSpecStepA H σ σ' regWr) @@ -2063,7 +2084,7 @@ theorem JStage3TA.of_vcpuStepA theorem _root_.Fl4ProofsA64.P3.JStage3A.of_vcpuStepA (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) (hNoSw : ∀ u, σ.schedulerAction ≠ .switchThread u) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) {hw' : HwRootA} {regWr : Bool} (w : WritesIn st s s' (VcpuWrFootA st regWr Z OS s)) (HS : VcpuSpecStepA H σ σ' regWr) @@ -2081,7 +2102,7 @@ theorem _root_.Fl4ProofsA64.P3.JStage3A.of_vcpuStepA (hDeadTvcpu : ∀ t ∈ Z.T, DeadA st OS .tcb s' t → L.mem s' (wa t 3664#u64) = 0#u64) (hDeadVcRun : ∀ v ∈ Z.V, DeadA st OS .vcpu s' v → L.mem s' (wa v 24#u64) = 0#u64) (hZombNoVc : ZombieTcbNoVcpuA st OS s') - (hSV' : SchedValidA σ') (R6' : VcpuRec6A st { Z with hw := hw' } OS Bf s' σ') + (hSV' : SchedValidA σ') (R6' : VcpuRec6A st { Z with hw := hw' } H OS Bf s' σ') (sysl : SysL st H Z.Cs OS ia ie s') (symL : SymL st H Z.Cs s') : JStage3A st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a' σ' m := (JStage3VcpuCoreA.of_vcpuStepA (J.toVcpuCoreA hNoSw) R6 w HS har hUtVs hVcCore hVcRun hRunVcpu @@ -2107,13 +2128,13 @@ theorem _root_.Fl4ProofsA64.P3.JStage3TA.liveOffKerA (J : JStage3TA st AR Z H OS ∃ p k, H p = some k ∧ p.val ≤ b.val ∧ b.val < p.val + 2 ^ k.bits := by obtain ⟨u, hu, ptr, size, rights, x1, x2, x3, x4, bits, hc, hb, lo, hi⟩ := lv obtain ⟨_, Ub, -, -, -, fo, -, frub, -, vcub, -⟩ := J7FrA.fr (st := st) _ _ _ _ _ _ J.j7 - have hpH : H ptr = some (.other bits.val) := fo u hu ptr size rights x1 x2 x3 x4 hc bits hb + have hpH : FrAt H ptr bits := fo u hu ptr size rights x1 x2 x3 x4 hc bits hb + obtain ⟨q, k, hq, hbk, hq1, hq2⟩ := hpH.obj refine ⟨fun h => vcub b h (frub u hu ptr size rights x1 x2 x3 x4 hc bits hb b al lo hi), - fun t ht o ho e => ?_, ptr, .other bits.val, hpH, lo, hi⟩ + fun t ht o ho e => ?_, q, .other k, hq, by omega, by show b.val < q.val + 2 ^ k; omega⟩ have htH : H t = some .tcb := show t ∈ H.tcbs by rw [J.tcbs]; exact ht have hft := J.ent.heap.fits t .tcb htH; change t.val + 4096 ≤ 2 ^ 64 at hft - have hne : t ≠ ptr := fun e => by rw [e, hpH] at htH; cases htH - have hd := J.ent.heap.disj t .tcb ptr (.other bits.val) htH hpH hne + have hd := hpH.disjK J.ent.heap htH (fun z => by simp) change t.val + 4096 ≤ ptr.val ∨ ptr.val + 2 ^ bits.val ≤ t.val at hd have ev : (core.num.U64.wrapping_add t o).val = t.val + o.val := by rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) @@ -2134,13 +2155,13 @@ theorem JStage3VcpuCoreA.liveOffKerCoreA (J : JStage3VcpuCoreA st AR Z H OS U Ac ∃ p k, H p = some k ∧ p.val ≤ b.val ∧ b.val < p.val + 2 ^ k.bits := by obtain ⟨u, hu, ptr, size, rights, x1, x2, x3, x4, bits, hc, hb, lo, hi⟩ := lv obtain ⟨_, Ub, -, -, -, fo, -, frub, -, vcub, -⟩ := J7FrA.fr (st := st) _ _ _ _ _ _ J.j7 - have hpH : H ptr = some (.other bits.val) := fo u hu ptr size rights x1 x2 x3 x4 hc bits hb + have hpH : FrAt H ptr bits := fo u hu ptr size rights x1 x2 x3 x4 hc bits hb + obtain ⟨q, k, hq, hbk, hq1, hq2⟩ := hpH.obj refine ⟨fun h => vcub b h (frub u hu ptr size rights x1 x2 x3 x4 hc bits hb b al lo hi), - fun t ht o ho e => ?_, ptr, .other bits.val, hpH, lo, hi⟩ + fun t ht o ho e => ?_, q, .other k, hq, by omega, by show b.val < q.val + 2 ^ k; omega⟩ have htH : H t = some .tcb := show t ∈ H.tcbs by rw [J.tcbs]; exact ht have hft := J.ent.heap.fits t .tcb htH; change t.val + 4096 ≤ 2 ^ 64 at hft - have hne : t ≠ ptr := fun e => by rw [e, hpH] at htH; cases htH - have hd := J.ent.heap.disj t .tcb ptr (.other bits.val) htH hpH hne + have hd := hpH.disjK J.ent.heap htH (fun z => by simp) change t.val + 4096 ≤ ptr.val ∨ ptr.val + 2 ^ bits.val ≤ t.val at hd have ev : (core.num.U64.wrapping_add t o).val = t.val + o.val := by rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) diff --git a/proofs/Fl4ProofsA64/P3/VcpuDelHookA.lean b/proofs/Fl4ProofsA64/P3/VcpuDelHookA.lean index 754c01f77..bcaf058bf 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuDelHookA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuDelHookA.lean @@ -216,9 +216,9 @@ private theorem asUser_seqH {σ σ1 σ2 : State Unit} {t : ObjRef} {x : Tcb} rw [h2']; simp [updKSc, Function.update_idem] rw [h2'']; exact asUser_eq_updH hkt hfg -private theorem VcpuRec6A.with_hw {Z : XSetsA} {OS : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} - {s : S} {σ : Fl4SpecA64.State Unit} (R6 : VcpuRec6A st Z OS Bf s σ) (hw' : HwRootA) : - VcpuRec6A st { Z with hw := hw' } OS Bf s σ := +private theorem VcpuRec6A.with_hw {Z : XSetsA} {H : Heap} {OS : Set U64} {Bf : Set (U64 × Fl4SpecA64.Word)} + {s : S} {σ : Fl4SpecA64.State Unit} (R6 : VcpuRec6A st Z H OS Bf s σ) (hw' : HwRootA) : + VcpuRec6A st { Z with hw := hw' } H OS Bf s σ := ⟨R6.snap, R6.vcSym1, R6.vcSym2, R6.vcBack, R6.runBack, R6.vcOS, R6.frOff, R6.userFr, R6.frTh, R6.bfSpec⟩ private def j3aVcpuRec6A {AR : A → HwRootA → Prop} @@ -227,7 +227,7 @@ private def j3aVcpuRec6A {AR : A → HwRootA → Prop} {stack : U64 → List U64} {κ : U64 → U64} {n : Nat} {J5 J7 : JSlotA S} {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 J5 J7 s a σ m) : - VcpuRec6A st Z OS Bf s σ := + VcpuRec6A st Z H OS Bf s σ := ⟨J.vcSnap, J.vcSym1, J.vcSym2, J.vcBack, J.runBack, J.vcOS, J.sys.sysl.fo, J.userFr, J.frTh, J.bfSpec⟩ /-! ## Section 0b: `SysL ∧ SymL` transport for VCPU / `set_thread_state` writes on `JStage3A` -/ @@ -279,12 +279,12 @@ private theorem vcpuWrNoSt_to_vwA · exact Or.inr (Or.inr (Or.inl ⟨t, htH, Or.inl ⟨K, hlo, hhi, hK, rfl⟩⟩)) · exact Or.inr (Or.inr (Or.inl ⟨t, htH, Or.inr (Or.inl rfl)⟩)) · exact Or.inr (Or.inr (Or.inl ⟨t, htH, Or.inr (Or.inr (Or.inl rfl))⟩)) - · have hp : H ptr = some (.other bits.val) := W.cc.fo y hy ptr sz r mp ept asid va hc bits hbits + · have hp : FrAt H ptr bits := W.cc.fo y hy ptr sz r mp ept asid va hc bits hbits have hFo := (J.sys.sysl.fo y hy ptr sz r mp ept asid va hc bits hbits).1 have hb12 : 12 ≤ bits.val := by cases sz <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp exact Or.inl ⟨W.fu y hy ptr sz r mp ept asid va hc bits hbits b hal h1 h2, - ⟨frame_word J.sys.ent.heap hp hal ⟨h1, h2⟩, ⟨ptr, bits.val, hp, hb12, h1, h2⟩, fun z hz g => by + ⟨hp.word J.sys.ent.heap hal ⟨h1, h2⟩, hp.frBw hb12 ⟨h1, h2⟩, fun z hz g => by rcases hFo z hz with g' | g' <;> omega⟩, ⟨y, hy, ptr, sz, r, mp, ept, asid, va, bits, hc, hbits, h1, h2⟩⟩ @@ -360,7 +360,7 @@ private structure StsRunOutA j5' : J5A st Z H OS s' σ' m j7' : J7 Z H OS s' σ' m hSV' : SchedValidA σ' - hR6' : VcpuRec6A st Z OS Bf s' σ' + hR6' : VcpuRec6A st Z H OS Bf s' σ' hCl' : Clock a σ'.machineState kb : L.ksb s' = L.ksb s hc : L.cpu s' = L.cpu s @@ -377,7 +377,7 @@ private theorem set_thread_state_running_coreA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) {t : U64} (ht : t ∈ Z.T) {x : Fl4SpecA64.Tcb} (hk : σ.kheap (specPtr t) = some (.tcb x)) @@ -1033,10 +1033,10 @@ private theorem set_thread_state_running_coreA intro u hu p0 sz0 r0 mp0 ept0 a0 va0 hc0 b0 hb0 exact R6.frOff u hu p0 sz0 r0 mp0 ept0 a0 va0 ((capE u hu).symm.trans hc0) b0 hb0 have hFrTh' : FrThA st Z.th OS s' := R6.frTh.keepA capE fun _ _ e => e - have hUserFr' : UserFrSpecA st OS s' σ' := - R6.userFr.keepA capE fun p _ _ h => by + have hUserFr' : UserFrSpecA st H OS s' σ' := + R6.userFr.keepA capE (fun _ _ e => e) fun p _ _ h => by rw [hKhOther p (fun e => by rw [e, hk] at h; cases h)]; exact h - have hR6' : VcpuRec6A st Z OS Bf s' σ' := by + have hR6' : VcpuRec6A st Z H OS Bf s' σ' := by refine ⟨hSnap', fun u hu => ?_, fun v hv => ?_, fun v hv hv0 => ?_, fun u hu hu0 => ?_, R6.vcOS, hFrOff', hUserFr', hFrTh', R6.bfSpec⟩ · rw [hTcbOff u hu 3664#u64 (by simp) (by simp) (Or.inr (by decide))] @@ -1074,7 +1074,7 @@ theorem set_thread_state_running_stage3TA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) {t : U64} (ht : t ∈ Z.T) {x : Fl4SpecA64.Tcb} (hk : σ.kheap (specPtr t) = some (.tcb x)) @@ -1086,7 +1086,7 @@ theorem set_thread_state_running_stage3TA σ'.kheap = (updKSc σ (specPtr t) (.tcb { x with tcbState := .running })).kheap ∧ JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf s' σ' ∧ + VcpuRec6A st Z H OS Bf s' σ' ∧ Clock a σ'.machineState ∧ σ'.machineState = σ.machineState ∧ L.ksb s' = L.ksb s ∧ L.cpu s' = L.cpu s ∧ @@ -1232,7 +1232,7 @@ private theorem vcpu_clear_run_pair_coreA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) {vc ct : U64} (hvc : vc ∈ Z.V) (hct : ct ∈ Z.T) (hlink : L.mem s (wa vc 24#u64) = ct) (hback : L.mem s (runVcpuA ct) = vc) @@ -1247,7 +1247,7 @@ private theorem vcpu_clear_run_pair_coreA VcpuSpecStepA H σ σ' ∧ WritesIn st s s2 (VcpuWrNoStA st Z OS s) ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf s2 σ' ∧ + VcpuRec6A st Z H OS Bf s2 σ' ∧ Clock a σ'.machineState ∧ L.mem s2 (wa vc 24#u64) = 0#u64 ∧ L.mem s2 (runVcpuA ct) = 0#u64 ∧ @@ -1523,9 +1523,9 @@ private theorem vcpu_clear_run_pair_coreA rw [hw.1]; intro u hu p0 sz0 r0 mp0 ept0 a0 va0 hc0 b0 hb0 exact R6.frOff u hu p0 sz0 r0 mp0 ept0 a0 va0 ((capE u hu).symm.trans hc0) b0 hb0 have hFrTh' : FrThA st Z.th OS s2 := R6.frTh.keepA capE fun _ _ e => e - have hUserFr' : UserFrSpecA st OS s2 σ' := - R6.userFr.keepA capE fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) - have hR6' : VcpuRec6A st Z OS Bf s2 σ' := by + have hUserFr' : UserFrSpecA st H OS s2 σ' := + R6.userFr.keepA capE (fun _ _ e => e) fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) + have hR6' : VcpuRec6A st Z H OS Bf s2 σ' := by refine ⟨hSnap', fun u hu => ?_, fun v hv => ?_, fun v hv hv0 => ?_, fun u hu hu0 => ?_, R6.vcOS, hFrOff', hUserFr', hFrTh', R6.bfSpec⟩ · rw [hmem_other _ (al_tcb u hu 3664#u64 (by decide) (by decide)) @@ -1595,7 +1595,7 @@ private theorem vcpu_tcb_reg_wr_coreA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) {ct : U64} (hct : ct ∈ Z.T) {x : Fl4SpecA64.Tcb} (hkt : σ.kheap (specPtr ct) = some (.tcb x)) @@ -1609,7 +1609,7 @@ private theorem vcpu_tcb_reg_wr_coreA VcpuSpecStepA H σ σ' ∧ WritesIn st s s' (VcpuWrNoStA st Z OS s) ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf s' σ' ∧ + VcpuRec6A st Z H OS Bf s' σ' ∧ Clock a σ'.machineState ∧ (∀ vc ∈ Z.V, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s' (wa vc o) = L.mem s (wa vc o)) ∧ (∀ u ∈ Z.T, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → @@ -1808,9 +1808,9 @@ private theorem vcpu_tcb_reg_wr_coreA rw [hw.1]; intro u hu p0 sz0 r0 mp0 ept0 a0 va0 hc0 b0 hb0 exact R6.frOff u hu p0 sz0 r0 mp0 ept0 a0 va0 ((capE u hu).symm.trans hc0) b0 hb0 have hFrTh' : FrThA st Z.th OS s' := R6.frTh.keepA capE fun _ _ e => e - have hUserFr' : UserFrSpecA st OS s' σ' := - R6.userFr.keepA capE fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) - have hR6' : VcpuRec6A st Z OS Bf s' σ' := by + have hUserFr' : UserFrSpecA st H OS s' σ' := + R6.userFr.keepA capE (fun _ _ e => e) fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) + have hR6' : VcpuRec6A st Z H OS Bf s' σ' := by refine ⟨hSnap', fun u hu => ?_, fun vc hvc => ?_, fun vc hvc hv0 => ?_, fun u hu hu0 => ?_, R6.vcOS, hFrOff', hUserFr', hFrTh', R6.bfSpec⟩ · rw [hTcbEq u hu 3664#u64 (by decide) (by decide) (Or.inr (Or.inr (by decide)))] @@ -1850,7 +1850,7 @@ private theorem vcpu_dissoc_bind_stage3TA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) {vc t : U64} (hvc : vc ∈ Z.V) (hvc_nz : vc ≠ 0#u64) (ht : t ∈ Z.T) (hlink : L.mem s vc = t) (hback : L.mem s (wa t 3664#u64) = vc) @@ -1867,7 +1867,7 @@ private theorem vcpu_dissoc_bind_stage3TA dissociateVcpuTcb (Z := Unit) (specPtr vc) (specPtr t) σ = ({((), σ')}, False) ∧ JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s4 a σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf s4 σ' ∧ + VcpuRec6A st Z H OS Bf s4 σ' ∧ Clock a σ'.machineState ∧ L.mem s4 vc = 0#u64 ∧ L.mem s4 (wa t 3664#u64) = 0#u64 ∧ @@ -2270,9 +2270,9 @@ private theorem vcpu_dissoc_bind_stage3TA rw [hw.1]; intro u hu p0 sz0 r0 mp0 ept0 a0 va0 hc0 b0 hb0 exact R6.frOff u hu p0 sz0 r0 mp0 ept0 a0 va0 ((capE u hu).symm.trans hc0) b0 hb0 have hFrTh' : FrThA st Z.th OS s4 := R6.frTh.keepA capE fun _ _ e => e - have hUserFr' : UserFrSpecA st OS s4 σ' := - R6.userFr.keepA capE fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) - have hR6' : VcpuRec6A st Z OS Bf s4 σ' := by + have hUserFr' : UserFrSpecA st H OS s4 σ' := + R6.userFr.keepA capE (fun _ _ e => e) fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) + have hR6' : VcpuRec6A st Z H OS Bf s4 σ' := by refine ⟨hSnap', fun u hu => ?_, fun v hv => ?_, fun v hv hv0 => ?_, fun u hu hu0 => ?_, R6.vcOS, hFrOff', hUserFr', hFrTh', R6.bfSpec⟩ · by_cases eu : u = t @@ -2326,7 +2326,7 @@ private theorem vcpu_set_vm_root_if_cur_coreA [J7PpA st J7] [J7PpKA st J7] [J7FrA st J7] {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) (hClVm : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) (hVR : VcpuVmRootA st ar AR) (u : U64) : @@ -2364,7 +2364,7 @@ private theorem vcpu_tcb_reg_wr_step_coreA [J7PpA st J7] [J7PpKA st J7] [J7FrA st J7] {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z OS Bf s σ) (hCl : Clock a σ.machineState) + (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) {t : U64} (ht : t ∈ Z.T) {xt : Fl4SpecA64.Tcb} (hkt : σ.kheap (specPtr t) = some (.tcb xt)) (r : Fl4SpecA64.Register) (v : U64) : ∃ (σ' : Fl4SpecA64.State Unit) (x' : Fl4SpecA64.Tcb), @@ -2379,7 +2379,7 @@ private theorem vcpu_tcb_reg_wr_step_coreA VcpuSpecStepA H σ σ' ∧ WritesIn st s (L.wr s (Endp.regA t (regIdxA r)) v) (VcpuWrNoStA st Z OS s) ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf (L.wr s (Endp.regA t (regIdxA r)) v) σ' ∧ + VcpuRec6A st Z H OS Bf (L.wr s (Endp.regA t (regIdxA r)) v) σ' ∧ Clock a σ'.machineState ∧ σ'.machineState = σ.machineState ∧ (∀ vc ∈ Z.V, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → @@ -2407,7 +2407,7 @@ private theorem vcpu_complete_run_4regs_coreA [J7PpA st J7] [J7PpKA st J7] [J7FrA st J7] {s4 : S} {a : A} {σ4 : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J4 : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s4 a σ4 m) - (hSV4 : SchedValidA σ4) (R6_4 : VcpuRec6A st Z OS Bf s4 σ4) (hCl4 : Clock a σ4.machineState) + (hSV4 : SchedValidA σ4) (R6_4 : VcpuRec6A st Z H OS Bf s4 σ4) (hCl4 : Clock a σ4.machineState) {ct : U64} (hct : ct ∈ Z.T) {x4 : Fl4SpecA64.Tcb} (hkc4 : σ4.kheap (specPtr ct) = some (.tcb x4)) {stop : U64} {stopSpec : RunStop} (hstop : stop.bv = stopSpec.word) (w1 w2 w3 : U64) : @@ -2428,7 +2428,7 @@ private theorem vcpu_complete_run_4regs_coreA JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s8 a σ8 m ∧ (SActA σ4 → SActA σ8) ∧ WritesIn st s4 s8 (VcpuWrNoStA st Z OS s4) ∧ - SchedValidA σ8 ∧ VcpuRec6A st Z OS Bf s8 σ8 ∧ Clock a σ8.machineState ∧ + SchedValidA σ8 ∧ VcpuRec6A st Z H OS Bf s8 σ8 ∧ Clock a σ8.machineState ∧ σ8.machineState = σ4.machineState ∧ (∀ v ∈ Z.V, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s8 (wa v o) = L.mem s4 (wa v o)) ∧ (∀ u ∈ Z.T, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → @@ -2487,7 +2487,7 @@ private theorem vcpu_complete_run_7regs_coreA {s3 : S} {a : A} {σ3 : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J3 : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s3 a σ3 m) (hSV3 : SchedValidA σ3) - (R6_3 : VcpuRec6A st Z OS Bf s3 σ3) + (R6_3 : VcpuRec6A st Z H OS Bf s3 σ3) (hCl3 : Clock a σ3.machineState) {ct : U64} (hct : ct ∈ Z.T) {x3 : Fl4SpecA64.Tcb} (hkc3 : σ3.kheap (specPtr ct) = some (.tcb x3)) @@ -2522,7 +2522,7 @@ private theorem vcpu_complete_run_7regs_coreA (SActA σ3 → SActA σ10) ∧ WritesIn st s3 s10 (VcpuWrNoStA st Z OS s3) ∧ SchedValidA σ10 ∧ - VcpuRec6A st Z OS Bf s10 σ10 ∧ + VcpuRec6A st Z H OS Bf s10 σ10 ∧ Clock a σ10.machineState ∧ σ10.machineState = σ3.machineState ∧ (∀ v ∈ Z.V, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s10 (wa v o) = L.mem s3 (wa v o)) ∧ @@ -2622,7 +2622,7 @@ private theorem vcpu_complete_run_pre_sts_coreA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) (hClFlushState : ∀ a' ms (vc om : U64), Clock a' ms → ar.vcpu_flush_state a' vc om ⦃ a'' => Clock a'' ms ⦄) (hClFr : ∀ a' ms ms', Clock a' ms → ms'.timeState = ms.timeState → @@ -2647,7 +2647,7 @@ private theorem vcpu_complete_run_pre_sts_coreA (SActA σ → SActA σ10) ∧ WritesIn st s s10 (VcpuWrNoStA st Z OS s) ∧ SchedValidA σ10 ∧ - VcpuRec6A st Z OS Bf s10 σ10 ∧ + VcpuRec6A st Z H OS Bf s10 σ10 ∧ Clock a1 σ10.machineState ∧ σ10.machineState.timeState = σ.machineState.timeState ∧ σ10.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -2832,7 +2832,7 @@ private theorem vcpu_complete_run_pre_sts_coreA (SActA σ → SActA σ1) ∧ WritesIn st s s1 (VcpuWrNoStA st Z OS s) ∧ SchedValidA σ1 ∧ - VcpuRec6A st Z OS Bf s1 σ1 ∧ + VcpuRec6A st Z H OS Bf s1 σ1 ∧ Clock a1 σ1.machineState ∧ σ1.machineState.timeState = σ.machineState.timeState ∧ σ1.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -2875,7 +2875,7 @@ private theorem vcpu_complete_run_pre_sts_coreA | _, _ => pure ()) σ = ({((), σ1)}, False) ∧ JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s1 a1 σ1 m ∧ (SActA σ → SActA σ1) ∧ WritesIn st s s1 (VcpuWrNoStA st Z OS s) ∧ - SchedValidA σ1 ∧ VcpuRec6A st Z OS Bf s1 σ1 ∧ Clock a1 σ1.machineState ∧ + SchedValidA σ1 ∧ VcpuRec6A st Z H OS Bf s1 σ1 ∧ Clock a1 σ1.machineState ∧ σ1.machineState.timeState = σ.machineState.timeState ∧ σ1.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ σ1.kheap = σ.kheap ∧ L.ksb s1 = L.ksb s ∧ L.cpu s1 = L.cpu s ∧ @@ -2981,7 +2981,7 @@ private theorem vcpu_complete_run_pre_sts_coreA unfold specPtr obtain ⟨_, _, -, -, -, fo, -, -, -, -, -⟩ := J7FrA.fr (st := st) _ _ _ _ _ _ J.j7 have hpH := fo _ hos_buf ptr size _ mp false asid va hcap_rw _ hbits_ok - have hpFit := J.ent.heap.fits ptr _ hpH; simp only [HKind.bits, hbits_val] at hpFit + have hpFit := hpH.fits J.ent.heap; simp only [hbits_val] at hpFit have hwa_bv : (wa ptr offset).bv = ptr.bv + offset.bv := by apply BitVec.eq_of_toNat_eq change (wa ptr offset).val = (ptr.bv + offset.bv).toNat @@ -3169,7 +3169,7 @@ theorem vcpu_complete_run_stage3TA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) (hClVm : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) (hClFlushState : ∀ a' ms (vc om : U64), Clock a' ms → ar.vcpu_flush_state a' vc om ⦃ a'' => Clock a'' ms ⦄) @@ -3183,7 +3183,7 @@ theorem vcpu_complete_run_stage3TA fl4CompleteRun (Z := Unit) (specPtr ct) stopSpec w1.bv w2.bv w3.bv σ = ({((), σ')}, False) ∧ JStage3TA st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 res.1 res.2 σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st { Z with hw := hw' } OS Bf res.1 σ' ∧ + VcpuRec6A st { Z with hw := hw' } H OS Bf res.1 σ' ∧ Clock res.2 σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -3427,7 +3427,7 @@ private theorem vcpu_unbind_phaseA_vm_stage3TA [J7PpA st J7] [J7PpKA st J7] [J7FrA st J7] {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z OS Bf s σ) (hCl : Clock a σ.machineState) + (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) (hClVm : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) (hClFlushState : ∀ a' ms (vc om : U64), Clock a' ms → ar.vcpu_flush_state a' vc om ⦃ a'' => Clock a'' ms ⦄) (hClFr : ∀ a' ms ms', Clock a' ms → ms'.timeState = ms.timeState → @@ -3444,7 +3444,7 @@ private theorem vcpu_unbind_phaseA_vm_stage3TA ∃ (hw1 : HwRootA) (σ1 : Fl4SpecA64.State Unit), fl4VcpuEndRun (Z := Unit) (specPtr vc) σ = ({((), σ1)}, False) ∧ JStage3TA st AR { Z with hw := hw1 } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 r1.1 r1.2 σ1 m ∧ - SchedValidA σ1 ∧ VcpuRec6A st { Z with hw := hw1 } OS Bf r1.1 σ1 ∧ Clock r1.2 σ1.machineState ∧ + SchedValidA σ1 ∧ VcpuRec6A st { Z with hw := hw1 } H OS Bf r1.1 σ1 ∧ Clock r1.2 σ1.machineState ∧ σ1.machineState.timeState = σ.machineState.timeState ∧ σ1.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ L.mem r1.1 (wa vc 24#u64) = 0#u64 ∧ L.mem r1.1 vc = L.mem s vc ∧ @@ -3496,7 +3496,7 @@ private theorem vcpu_unbind_phaseA_stale_stage3TA [J7PpA st J7] [J7PpKA st J7] [J7FrA st J7] {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) - (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z OS Bf s σ) (hCl : Clock a σ.machineState) + (hSV : SchedValidA σ) (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) {vc : U64} (hvc : vc ∈ Z.V) {xv : Vcpu} (hkv : σ.kheap (specPtr vc) = some (.archObj (.vcpu xv))) {xc : Tcb} (hcT : L.mem s (wa vc 24#u64) ∈ Z.T) @@ -3514,7 +3514,7 @@ private theorem vcpu_unbind_phaseA_stale_stage3TA ∃ (hw1 : HwRootA) (σ1 : Fl4SpecA64.State Unit), fl4VcpuEndRun (Z := Unit) (specPtr vc) σ = ({((), σ1)}, False) ∧ JStage3TA st AR { Z with hw := hw1 } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 r1.1 r1.2 σ1 m ∧ - SchedValidA σ1 ∧ VcpuRec6A st { Z with hw := hw1 } OS Bf r1.1 σ1 ∧ Clock r1.2 σ1.machineState ∧ + SchedValidA σ1 ∧ VcpuRec6A st { Z with hw := hw1 } H OS Bf r1.1 σ1 ∧ Clock r1.2 σ1.machineState ∧ σ1.machineState.timeState = σ.machineState.timeState ∧ σ1.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ L.mem r1.1 (wa vc 24#u64) = 0#u64 ∧ L.mem r1.1 vc = L.mem s vc ∧ @@ -3572,7 +3572,7 @@ private theorem vcpu_unbind_phaseA_stage3TA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) (hClVm : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) (hClFlushState : ∀ a' ms (vc om : U64), Clock a' ms → ar.vcpu_flush_state a' vc om ⦃ a'' => Clock a'' ms ⦄) @@ -3599,7 +3599,7 @@ private theorem vcpu_unbind_phaseA_stage3TA fl4VcpuEndRun (Z := Unit) (specPtr vc) σ = ({((), σ1)}, False) ∧ JStage3TA st AR { Z with hw := hw1 } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 r1.1 r1.2 σ1 m ∧ SchedValidA σ1 ∧ - VcpuRec6A st { Z with hw := hw1 } OS Bf r1.1 σ1 ∧ + VcpuRec6A st { Z with hw := hw1 } H OS Bf r1.1 σ1 ∧ Clock r1.2 σ1.machineState ∧ σ1.machineState.timeState = σ.machineState.timeState ∧ σ1.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -3652,7 +3652,7 @@ private theorem vcpu_unbind_phaseB_stage3TA {s1 : S} {a1 : A} {σ1 : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J1 : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s1 a1 σ1 m) (hSV1 : SchedValidA σ1) - (R6_1 : VcpuRec6A st Z OS Bf s1 σ1) + (R6_1 : VcpuRec6A st Z H OS Bf s1 σ1) (hCl1 : Clock a1 σ1.machineState) (hClVm : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) (hClFlush : ∀ a' ms (vc : U64), Clock a' ms → ar.vcpu_flush a' vc ⦃ a'' => Clock a'' ms ⦄) @@ -3686,7 +3686,7 @@ private theorem vcpu_unbind_phaseB_stage3TA | none => pure ()) σ1 = ({((), σ')}, False) ∧ JStage3TA st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 res.1 res.2 σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st { Z with hw := hw' } OS Bf res.1 σ' ∧ + VcpuRec6A st { Z with hw := hw' } H OS Bf res.1 σ' ∧ Clock res.2 σ'.machineState ∧ σ'.machineState.timeState = σ1.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ1.machineState.lastMachineTime ∧ @@ -3783,7 +3783,7 @@ theorem vcpu_unbind_stage3TA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) (hClVm : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) (hClFlush : ∀ a' ms (vc : U64), Clock a' ms → ar.vcpu_flush a' vc ⦃ a'' => Clock a'' ms ⦄) @@ -3799,7 +3799,7 @@ theorem vcpu_unbind_stage3TA fl4VcpuUnbind (specPtr vc) σ = ({((), σ')}, False) ∧ JStage3TA st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 res.1 res.2 σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st { Z with hw := hw' } OS Bf res.1 σ' ∧ + VcpuRec6A st { Z with hw := hw' } H OS Bf res.1 σ' ∧ Clock res.2 σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -3855,7 +3855,7 @@ theorem vcpu_finalise_stage3TA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) (hClVm : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) (hClFlush : ∀ a' ms (vc : U64), Clock a' ms → ar.vcpu_flush a' vc ⦃ a'' => Clock a'' ms ⦄) @@ -3871,7 +3871,7 @@ theorem vcpu_finalise_stage3TA fl4VcpuUnbind (specPtr vc) σ = ({((), σ')}, False) ∧ JStage3TA st AR { Z with hw := hw' } H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 res.1 res.2 σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st { Z with hw := hw' } OS Bf res.1 σ' ∧ + VcpuRec6A st { Z with hw := hw' } H OS Bf res.1 σ' ∧ Clock res.2 σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -3918,7 +3918,7 @@ theorem vcpu_detach_stage3GA (hRunBack : ∀ t ∈ Z.T, L.mem s (runVcpuA t) ≠ 0#u64 → L.mem s (wa (L.mem s (runVcpuA t)) 24#u64) = t) (hVcOS : ∀ b, VcW Z.V b → ¬ InOS OS b) (hFrOff : FrOff st Z.Cs OS (L.ksb s) s) - (hUserFr : UserFrSpecA st OS s σ) (hFrTh : FrThA st Z.th OS s) + (hUserFr : UserFrSpecA st H OS s σ) (hFrTh : FrThA st Z.th OS s) (hBfSpec : ∀ bp ∈ Bf, bp.2 = specPtr bp.1) (hCl : Clock a σ.machineState) (hClVm : ∀ s' a' ms (u : U64), Clock a' ms → vspace.set_vm_root st ar s' a' u ⦃ r => Clock r.2 ms ⦄) @@ -3940,7 +3940,7 @@ theorem vcpu_detach_stage3GA VcSym1A st Z.T res.1 ∧ VcSym2A st Z.V res.1 ∧ (∀ v ∈ Z.V, L.mem res.1 v ≠ 0#u64 → L.mem res.1 (wa (L.mem res.1 v) 3664#u64) = v) ∧ (∀ u ∈ Z.T, L.mem res.1 (runVcpuA u) ≠ 0#u64 → L.mem res.1 (wa (L.mem res.1 (runVcpuA u)) 24#u64) = u) ∧ - UserFrSpecA st OS res.1 σ' ∧ + UserFrSpecA st H OS res.1 σ' ∧ Clock res.2 σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -3962,7 +3962,7 @@ theorem vcpu_detach_stage3GA x'.tcbSchedContext = x.tcbSchedContext ∧ x'.tcbState = x.tcbState) ∧ FrKeepA st OS s σ res.1 σ' ⦄ := by - let R6 : VcpuRec6A st Z OS Bf s σ := + let R6 : VcpuRec6A st Z H OS Bf s σ := ⟨hSnap, hVcSym1, hVcSym2, hVcBack, hRunBack, hVcOS, hFrOff, hUserFr, hFrTh, hBfSpec⟩ unfold vcpu.detach refine WP.spec_bind (vcpu_cancel_run_stage3TA J hSV R6 hCl ht) ?_ diff --git a/proofs/Fl4ProofsA64/P3/VcpuDelReadA.lean b/proofs/Fl4ProofsA64/P3/VcpuDelReadA.lean index e7d5ef6bc..b601bb903 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuDelReadA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuDelReadA.lean @@ -696,7 +696,7 @@ theorem vcpu_read_state_to_frame_coreA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) (hClFr : ∀ a' ms ms', Clock a' ms → ms'.timeState = ms.timeState → ms'.lastMachineTime = ms.lastMachineTime → Clock a' ms') @@ -716,7 +716,7 @@ theorem vcpu_read_state_to_frame_coreA fl4ReadStateToFrame (specPtr vc) (specPtr frame) mask.bv σ = ({((), σ')}, False) ∧ JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf s' σ' ∧ + VcpuRec6A st Z H OS Bf s' σ' ∧ Clock a σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -731,10 +731,9 @@ theorem vcpu_read_state_to_frame_coreA dsimp only set frame := wa ptr offset obtain ⟨Pt, Ub, vr, arm, -, fo, -, frub, ubal, vcub, -⟩ := J7FrA.fr (st := st) _ _ _ _ _ _ J.j7 - have hpH : H ptr = some (.other bits.val) := fo y hy ptr sz capability.VM_READ_WRITE mp ept asid va hcap bits hbits - have hptrFit := J.ent.heap.fits ptr (.other bits.val) hpH - have hptrAl := J.ent.heap.align ptr (.other bits.val) hpH - simp only [HKind.bits] at hptrFit hptrAl + have hpH : FrAt H ptr bits := fo y hy ptr sz capability.VM_READ_WRITE mp ept asid va hcap bits hbits + have hptrFit := hpH.fits J.ent.heap + have hptrAl := hpH.al J.ent.heap have hbits12 : 12 ≤ bits.val := by cases sz <;> simp [capability.FrameSize.bits] at hbits <;> subst hbits <;> decide have hpow8 : 8 ∣ 2 ^ bits.val := by @@ -772,84 +771,7 @@ theorem vcpu_read_state_to_frame_coreA specPtr_wa_wordA (by omega) rw [← hsp] have hval := frame_word_valA hfit hk - have hsz_eq : pageBitsForSize (frameSizeOfA sz) = bits.val := by - cases sz <;> simp [capability.FrameSize.bits] at hbits <;> subst hbits <;> decide - have hbits_le30 : bits.val ≤ 30 := by - cases sz <;> simp [capability.FrameSize.bits] at hbits <;> subst hbits <;> decide - have hdev_k := R6.userFr y hy ptr sz capability.VM_READ_WRITE mp ept asid va hcap - refine ⟨frameSizeOfA sz, ?_⟩ - rw [hsz_eq] - have hmask_eq : specPtr (wa frame ⟨BitVec.ofNat 64 (8 * k)⟩) &&& ~~~Fl4SpecA64.mask bits.val = specPtr ptr := by - have hp_al : (specPtr ptr).toNat % 2 ^ bits.val = 0 := by - unfold specPtr - have hsh : pptrShiftA.toNat % 2 ^ bits.val = 0 := by - have hd : 2 ^ bits.val ∣ 2 ^ 30 := Nat.pow_dvd_pow 2 hbits_le30 - have hsh30 : 2 ^ 30 ∣ pptrShiftA.toNat := by decide - exact Nat.mod_eq_zero_of_dvd (Nat.dvd_trans hd hsh30) - rw [BitVec.toNat_add] - have h264 : 2 ^ bits.val ∣ 2 ^ 64 := Nat.pow_dvd_pow 2 (by omega) - rw [Nat.mod_mod_of_dvd _ h264, Nat.add_mod] - have hptr_mod : ptr.bv.toNat % 2 ^ bits.val = 0 := hptrAl - rw [hptr_mod, hsh]; simp - have hsp_add : specPtr (wa frame ⟨BitVec.ofNat 64 (8 * k)⟩) = - specPtr ptr + BitVec.ofNat 64 (offset.val + 8 * k) := by - have hwf : wa frame ⟨BitVec.ofNat 64 (8 * k)⟩ = wa ptr ⟨BitVec.ofNat 64 (offset.val + 8 * k)⟩ := by - apply UScalar.eq_of_val_eq - have hd : (⟨BitVec.ofNat 64 (offset.val + 8 * k)⟩ : U64).val = offset.val + 8 * k := by - show (BitVec.ofNat 64 _).toNat = _; rw [BitVec.toNat_ofNat]; exact Nat.mod_eq_of_lt (by omega) - rw [hval, hfrVal, wa_valm, hd, Nat.mod_eq_of_lt (by omega)]; omega - rw [hwf]; unfold specPtr - have hadd : (wa ptr ⟨BitVec.ofNat 64 (offset.val + 8 * k)⟩).bv = - ptr.bv + BitVec.ofNat 64 (offset.val + 8 * k) := by - apply BitVec.eq_of_toNat_eq - have hd : (⟨BitVec.ofNat 64 (offset.val + 8 * k)⟩ : U64).val = offset.val + 8 * k := by - show (BitVec.ofNat 64 _).toNat = _; rw [BitVec.toNat_ofNat]; exact Nat.mod_eq_of_lt (by omega) - change (wa ptr ⟨BitVec.ofNat 64 (offset.val + 8 * k)⟩).val = _ - rw [wa_valm, hd, BitVec.toNat_add, BitVec.toNat_ofNat, - Nat.mod_eq_of_lt (by omega : offset.val + 8 * k < 2 ^ 64), - Nat.mod_eq_of_lt (by change ptr.val + (offset.val + 8 * k) < 2 ^ 64; omega)] - exact (Nat.mod_eq_of_lt (by change ptr.val + (offset.val + 8 * k) < 2 ^ 64; omega)).symm - rw [hadd, BitVec.add_assoc, BitVec.add_comm (BitVec.ofNat 64 (offset.val + 8 * k)) pptrShiftA, ← BitVec.add_assoc] - rw [hsp_add] - set p := specPtr ptr - set d := offset.val + 8 * k - have hd_lt : d < 2 ^ bits.val := by omega - have hp_div : p.toNat = (p.toNat / 2 ^ bits.val) * 2 ^ bits.val := by - have hdm := Nat.div_add_mod p.toNat (2 ^ bits.val) - rw [hp_al, Nat.add_zero, Nat.mul_comm] at hdm; exact hdm.symm - have hpd_lt : p.toNat + d < 2 ^ 64 := by - have hp_lt : p.toNat < 2 ^ 64 := p.isLt - have h264 : 2 ^ bits.val ∣ 2 ^ 64 := Nat.pow_dvd_pow 2 (by omega) - have hle : p.toNat + 2 ^ bits.val ≤ 2 ^ 64 := by - obtain ⟨q, hq⟩ := h264 - have hq' : q * 2 ^ bits.val = 2 ^ 64 := by rw [Nat.mul_comm]; exact hq.symm - have hltq : p.toNat / 2 ^ bits.val < q := by - by_contra hge; push_neg at hge - have hmul : q * 2 ^ bits.val ≤ (p.toNat / 2 ^ bits.val) * 2 ^ bits.val := Nat.mul_le_mul_right _ hge - omega - have hstep : (p.toNat / 2 ^ bits.val + 1) * 2 ^ bits.val ≤ q * 2 ^ bits.val := Nat.mul_le_mul_right _ hltq - rw [Nat.add_mul, Nat.one_mul, ← hp_div, hq'] at hstep; exact hstep - omega - have hmv : (Fl4SpecA64.mask bits.val : Word).toNat = 2 ^ bits.val - 1 := by - cases sz <;> simp [capability.FrameSize.bits] at hbits <;> subst hbits <;> decide - apply BitVec.eq_of_getLsbD_eq - intro j hj64 - simp only [BitVec.getLsbD_and, BitVec.getLsbD_not, hj64, decide_true, Bool.true_and] - have hmt : (Fl4SpecA64.mask bits.val : Word).getLsbD j = decide (j < bits.val) := by - change (Fl4SpecA64.mask bits.val : Word).toNat.testBit j = _ - rw [hmv, Nat.testBit_two_pow_sub_one] - rw [hmt] - by_cases hj : j < bits.val - · simp only [hj, decide_true, Bool.not_true, Bool.and_false] - symm; change p.toNat.testBit j = false - rw [hp_div, Nat.mul_comm, Nat.testBit_two_pow_mul]; simp [hj] - · simp only [hj, decide_false, Bool.not_false, Bool.and_true] - change (p + BitVec.ofNat 64 d).toNat.testBit j = p.toNat.testBit j - rw [BitVec.toNat_add, BitVec.toNat_ofNat, - Nat.mod_eq_of_lt (by omega : d < 2 ^ 64), Nat.mod_eq_of_lt hpd_lt, - hp_div, Nat.mul_comm, Nat.testBit_two_pow_mul_add _ hd_lt, Nat.testBit_two_pow_mul] - simp [hj, show bits.val ≤ j by omega] - rw [hmask_eq]; exact hdev_k + exact UserFrSpecA.inUser J.ent.heap R6.userFr hy hcap hbits (by omega) (by omega) have hBfAl : ∀ bp ∈ Bf, ∀ j : U64, j.val < 128 → Aligned (bufW bp.1 j) := fun bp hbp j hj => J.iplaced.e.balign (bufW bp.1 j) ⟨bp, hbp, j, hj, rfl⟩ obtain ⟨xv, hkv, hvt, -⟩ := J.j.2.1.obj vc hvc @@ -882,8 +804,7 @@ theorem vcpu_read_state_to_frame_coreA have htH : H (L.mem s vc) = some .tcb := show L.mem s vc ∈ H.tcbs by rw [J.tcbs]; exact htT have htFit := J.ent.heap.fits _ .tcb htH; change (L.mem s vc).val + 4096 ≤ 2 ^ 64 at htFit have htAl := J.ent.heap.align _ .tcb htH; change (L.mem s vc).val % 4096 = 0 at htAl - have hne_tp : L.mem s vc ≠ ptr := fun e => by rw [e, hpH] at htH; cases htH - have hdisj := J.ent.heap.disj _ .tcb ptr (.other bits.val) htH hpH hne_tp + have hdisj := hpH.disjK J.ent.heap htH (fun z => by simp) change (L.mem s vc).val + 4096 ≤ ptr.val ∨ ptr.val + 2 ^ bits.val ≤ (L.mem s vc).val at hdisj refine ⟨xt, hkt, fun i hi => ?_⟩ have h256 : layout.tcb.REGS.val = 256 := by unfold layout.tcb.REGS; rfl @@ -921,7 +842,7 @@ theorem vcpu_read_state_to_frame_coreA fl4ReadStateToFrame (specPtr vc) (specPtr frame) mask.bv σ = ({((), σ')}, False) ∧ JStage3VcpuCoreA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf s' σ' ∧ + VcpuRec6A st Z H OS Bf s' σ' ∧ Clock a σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -946,7 +867,8 @@ theorem vcpu_read_state_to_frame_coreA by_cases hin : ∃ k < 128, frame.val + 8 * k ≤ (fl4Ptr p).val ∧ (fl4Ptr p).val < frame.val + 8 * k + 8 · obtain ⟨k, hk, h1, h2⟩ := hin - exact ⟨ptr, bits.val, hpH, by omega, by omega⟩ + obtain ⟨q, z, hq, hbz, hq1, hq2⟩ := hpH.obj + exact ⟨q, z, hq, by omega, by omega⟩ · exact absurd (I'.umOff p (fun k hk h => hin ⟨k, hk, h⟩)) hp have osk := osKeep_of_vcpuWrCoreA J R6.vcOS R6.frOff hw have capE : ∀ u ∈ OS, capA st s' u = capA st s u := fun u hu => by @@ -964,8 +886,7 @@ theorem vcpu_read_state_to_frame_coreA have huH : H u = some .tcb := show u ∈ H.tcbs by rw [J.tcbs]; exact hu have huf' := J.ent.heap.fits u .tcb huH; change u.val + 4096 ≤ 2 ^ 64 at huf' have hua' := J.ent.heap.align u .tcb huH; change u.val % 4096 = 0 at hua' - have hne_up : u ≠ ptr := fun e => by rw [e, hpH] at huH; cases huH - have hd := J.ent.heap.disj u .tcb ptr (.other bits.val) huH hpH hne_up + have hd := hpH.disjK J.ent.heap huH (fun z => by simp) change u.val + 4096 ≤ ptr.val ∨ ptr.val + 2 ^ bits.val ≤ u.val at hd have ev : (wa u o).val = u.val + o.val := by rw [wa_valm]; exact Nat.mod_eq_of_lt (by omega) exact I'.wr.mem_eq (by show _ % 8 = 0; rw [ev]; omega) fun ⟨k, hk, heq⟩ => by @@ -1021,8 +942,7 @@ theorem vcpu_read_state_to_frame_coreA obtain ⟨x, hku, hrel⟩ := J.ep.tcb u hu have huH : H u = some .tcb := show u ∈ H.tcbs by rw [J.tcbs]; exact hu have huf' := J.ent.heap.fits u .tcb huH; change u.val + 4096 ≤ 2 ^ 64 at huf' - have hne_up : u ≠ ptr := fun e => by rw [e, hpH] at huH; cases huH - have hd := J.ent.heap.disj u .tcb ptr (.other bits.val) huH hpH hne_up + have hd := hpH.disjK J.ent.heap huH (fun z => by simp) change u.val + 4096 ≤ ptr.val ∨ ptr.val + 2 ^ bits.val ≤ u.val at hd refine ⟨x, by rw [I'.kheap]; exact hku, hrel.frame (J.sq.tcbs u huH) fun a h8 ha => ?_⟩ have hlo := ha.1; have hhi := ha.2; unfold TOffN at hhi @@ -1055,9 +975,9 @@ theorem vcpu_read_state_to_frame_coreA intro u hu p0 sz0 r0 mp0 ept0 a0 va0 hc0 b0 hb0 exact R6.frOff u hu p0 sz0 r0 mp0 ept0 a0 va0 ((capE u hu).symm.trans hc0) b0 hb0 have hFrTh' : FrThA st Z.th OS s' := R6.frTh.keepA capE fun _ _ e => e - have hUserFr' : UserFrSpecA st OS s' σ' := - R6.userFr.keepA capE fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) - have hR6' : VcpuRec6A st Z OS Bf s' σ' := by + have hUserFr' : UserFrSpecA st H OS s' σ' := + R6.userFr.keepA capE (fun _ _ e => e) fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) + have hR6' : VcpuRec6A st Z H OS Bf s' σ' := by refine ⟨hSnap', fun u hu => ?_, fun v hv => ?_, fun v hv hv0 => ?_, fun u hu hu0 => ?_, R6.vcOS, hFrOff', hUserFr', hFrTh', R6.bfSpec⟩ · rw [hTcbEq u hu 3664#u64 (by change 3664 < 4096; omega) (by change 3664 % 8 = 0; omega)] @@ -1439,7 +1359,7 @@ theorem vcpu_read_state_to_frame_stage3TA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) (hClFr : ∀ a' ms ms', Clock a' ms → ms'.timeState = ms.timeState → ms'.lastMachineTime = ms.lastMachineTime → Clock a' ms') @@ -1459,7 +1379,7 @@ theorem vcpu_read_state_to_frame_stage3TA fl4ReadStateToFrame (specPtr vc) (specPtr frame) mask.bv σ = ({((), σ')}, False) ∧ JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s' a σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf s' σ' ∧ + VcpuRec6A st Z H OS Bf s' σ' ∧ Clock a σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ diff --git a/proofs/Fl4ProofsA64/P3/VcpuDelStepsA.lean b/proofs/Fl4ProofsA64/P3/VcpuDelStepsA.lean index 5ba6419d5..022a0590f 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuDelStepsA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuDelStepsA.lean @@ -147,7 +147,7 @@ theorem vcpu_cancel_run_stage3TA {s : S} {a : A} {σ : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} (J : JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 s a σ m) (hSV : SchedValidA σ) - (R6 : VcpuRec6A st Z OS Bf s σ) + (R6 : VcpuRec6A st Z H OS Bf s σ) (hCl : Clock a σ.machineState) {t : U64} (ht : t ∈ Z.T) : vcpu.cancel_run st ar s a t ⦃ res => @@ -156,7 +156,7 @@ theorem vcpu_cancel_run_stage3TA ((), σ') ∈ (fl4CancelRun (Z := Unit) (specPtr t) σ).1 ∧ JStage3TA st AR Z H OS U Ac Pp Tb Lv ia ie N E Rp Bf stack κ n (J5A st) J7 res.1 a σ' m ∧ SchedValidA σ' ∧ - VcpuRec6A st Z OS Bf res.1 σ' ∧ + VcpuRec6A st Z H OS Bf res.1 σ' ∧ Clock a σ'.machineState ∧ σ'.machineState.timeState = σ.machineState.timeState ∧ σ'.machineState.lastMachineTime = σ.machineState.lastMachineTime ∧ @@ -499,9 +499,9 @@ theorem vcpu_cancel_run_stage3TA intro u hu ptr sz r mp ept asid va hc bits hbits exact R6.frOff u hu ptr sz r mp ept asid va ((capE u hu).symm.trans hc) bits hbits have hFrTh' : FrThA st Z.th OS s2 := R6.frTh.keepA capE fun _ _ e => e - have hUserFr' : UserFrSpecA st OS s2 σ' := - R6.userFr.keepA capE fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) - have hR6' : VcpuRec6A st Z OS Bf s2 σ' := by + have hUserFr' : UserFrSpecA st H OS s2 σ' := + R6.userFr.keepA capE (fun _ _ e => e) fun _ _ _ h => hHS.keepObj h (fun _ e => by cases e) (fun _ e => by cases e) + have hR6' : VcpuRec6A st Z H OS Bf s2 σ' := by refine ⟨hSnap', fun u hu => ?_, fun v hv => ?_, fun v hv hv0 => ?_, fun u hu hu0 => ?_, R6.vcOS, hFrOff', hUserFr', hFrTh', R6.bfSpec⟩ · have hal3664 : Aligned (wa u 3664#u64) := al_tcb u hu 3664#u64 (by change 3664 < 4096; omega) (by change 3664 % 8 = 0; omega) diff --git a/proofs/Fl4ProofsA64/P3/VcpuRegJA.lean b/proofs/Fl4ProofsA64/P3/VcpuRegJA.lean index 1d33b8f7d..1b32062b1 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuRegJA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuRegJA.lean @@ -377,7 +377,10 @@ theorem JAtZAX.of_specVcpuNonLinkA {AR : A → HwRootA → Prop} {Z : XSetsA} {s irq := J.1.irq.of_spec hG rest := J.1.rest.of_spec hT hC hG vs := hvs' - ext := hext' } + ext := hext' + vsu := J.1.vsu.of_frame J.1.ext.xal (fun _ _ => rfl) ⟨rfl, fun p hp => hkh_other _ fun heq => by + obtain ⟨ap, hkap, -⟩ := J.1.vs.pool p hp + rw [heq, hk] at hkap; cases hkap⟩ (PtClosedA.refl _ _ _ _) } refine ⟨⟨J1', ?_, ?_, ?_⟩, ?_⟩ · refine ⟨?_, ?_, ?_, J.2.1.cap⟩ · intro w hw diff --git a/proofs/Fl4ProofsA64/P3/VcpuRunBaseA.lean b/proofs/Fl4ProofsA64/P3/VcpuRunBaseA.lean index ef291c421..771ba85a6 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuRunBaseA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuRunBaseA.lean @@ -1005,7 +1005,16 @@ theorem VcpuXferStateA.enter_run_vm {AR : A → HwRootA → Prop} {Z : XSetsA} exact mem_wr_neA hal_st (hfa b (.nslot b (.vs b hb0))) (fun e => hVs_st (e ▸ hb0))) ext := (hJ4.ext.of_spec (σ' := σ5) rfl (fun q hq => hExt_kh5 q (by rcases hq with h | h | h <;> simp [h]))).of_mem - (fun b hb => mem_wr_neA hal_st (hfa b (.nslot b (.ext b hb))) (fun e => hExt_st (e ▸ hb))) } + (fun b hb => mem_wr_neA hal_st (hfa b (.nslot b (.ext b hb))) (fun e => hExt_st (e ▸ hb))) + vsu := by + rw [L.ksb_wr] + exact hJ4.vsu.of_frame hJ4.ext.xal (fun b hb => hb.elim + (fun hb => mem_wr_neA hal_st (hfa b (.nslot b (.ext b hb))) (fun e => hExt_st (e ▸ hb))) + (fun hb => by + have hb0 : VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b := hksb4 ▸ hb + exact mem_wr_neA hal_st (hfa b (.nslot b (.vs b hb0))) (fun e => hVs_st (e ▸ hb0)))) + ⟨rfl, fun p hp => hVs_kh5 _ (Or.inl hp)⟩ + (PtClosedA.of_cap fun y hy => Or.inl (hcap_sl5 y (Or.inl hy))) } have hS2_5 : Stage2CoreA (L := L) Z s5 σ5 := ⟨fun r hr => by rw [hExt_kh5 r (Or.inr (Or.inl hr))]; exact hS2_4.obj r hr, fun p es hkp => by diff --git a/proofs/Fl4ProofsA64/P3/VcpuRunLinkJA.lean b/proofs/Fl4ProofsA64/P3/VcpuRunLinkJA.lean index 81656b266..5ef47c1ce 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuRunLinkJA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuRunLinkJA.lean @@ -89,7 +89,7 @@ theorem VcpuXferStateA.of_hw {AR : A → HwRootA → Prop} {Z : XSetsA} {OS Ub : ar := hAR', place := X.j.1.place, thT := X.j.1.thT, csN := X.j.1.csN, idleT := X.j.1.idleT, idleC := X.j.1.idleC, curT := X.j.1.curT, cscC := X.j.1.cscC, ksFit := X.j.1.ksFit, scOffD := X.j.1.scOffD, cv := X.j.1.cv, pml := X.j.1.pml, - vs := X.j.1.vs, ext := X.j.1.ext }, + vs := X.j.1.vs, ext := X.j.1.ext, vsu := X.j.1.vsu }, ⟨{ X.j.2.1 with }, { X.j.2.2.1 with }, { X.j.2.2.2 with }⟩⟩, X.tr, X.car, { X.vcpu with core := { X.vcpu.core with }, place := { X.vcpu.place with } }, { X.fmem with }, X.regs⟩ @@ -312,7 +312,12 @@ theorem jAtZA_of_vcpuLinkStepA {AR : A → HwRootA → Prop} {Z : XSetsA} cv := fun y hy => by rw [hcap_sl y (Or.inl hy)]; exact X.j.1.cv y hy, pml := fun y hy p mp asid hc => by rw [hcap_sl y (Or.inl hy)] at hc; exact X.j.1.pml y hy p mp asid hc, - vs := hVs, ext := hExt } + vs := hVs, ext := hExt, + vsu := by + rw [hksb] + exact X.j.1.vsu.of_frame X.j.1.ext.xal (fun b hb => hb.elim (hext b) (hvs b)) + ⟨hspec_asid, fun p hp => hVs_kh _ (Or.inl ⟨p, hp, rfl⟩)⟩ + (PtClosedA.of_cap fun y hy => Or.inl (hcap_sl y (Or.inl hy))) } have hS2 : Stage2CoreA (L := L) Z s' σ' := ⟨fun r hr => by rw [hExt_kh r (Or.inr (Or.inl hr))]; exact X.j.2.2.1.obj r hr, fun p es h => X.j.2.2.1.back p es (hspec_s2 p es h), @@ -1293,7 +1298,14 @@ theorem VcpuXferStateA.set_state_running_from_vm {AR : A → HwRootA → Prop} { pml := fun y hy p mp asid hc => by rw [hcap_sl y (Or.inl hy)] at hc; exact X.j.1.pml y hy p mp asid hc, vs := by rw [hksb']; exact (X.j.1.vs.of_spec (rfl : σ'.archState.armAsidTable = σ.archState.armAsidTable) hVs_kh).of_mem fun b hb => mem_wr_neA hal_st (hfa _ (.nslot _ (.vs b hb))) (fun e => hVs_st (e ▸ hb)), ext := (X.j.1.ext.of_spec (rfl : σ'.archState.armAsidTable = σ.archState.armAsidTable) fun q hq => hExt_kh q (by rcases hq with h | h | h <;> simp [h])).of_mem - fun b hb => mem_wr_neA hal_st (hfa _ (.nslot _ (.ext b hb))) (fun e => hExt_st (e ▸ hb)) } + fun b hb => mem_wr_neA hal_st (hfa _ (.nslot _ (.ext b hb))) (fun e => hExt_st (e ▸ hb)), + vsu := by + rw [hksb'] + exact X.j.1.vsu.of_frame X.j.1.ext.xal (fun b hb => hb.elim + (fun hb => mem_wr_neA hal_st (hfa _ (.nslot _ (.ext b hb))) (fun e => hExt_st (e ▸ hb))) + (fun hb => mem_wr_neA hal_st (hfa _ (.nslot _ (.vs b hb))) (fun e => hVs_st (e ▸ hb)))) + ⟨rfl, fun p hp => hVs_kh _ (Or.inl ⟨p, hp, rfl⟩)⟩ + (PtClosedA.of_cap fun y hy => Or.inl (hcap_sl y (Or.inl hy))) } have hS2 : Stage2CoreA (L := L) Z s' σ' := ⟨fun r hr => by rw [hExt_kh r (Or.inr (Or.inl hr))]; exact X.j.2.2.1.obj r hr, fun p es hp => by diff --git a/proofs/Fl4ProofsA64/P3/VcpuTimestampA.lean b/proofs/Fl4ProofsA64/P3/VcpuTimestampA.lean index 14d9d3adf..6f5c8bd4b 100644 --- a/proofs/Fl4ProofsA64/P3/VcpuTimestampA.lean +++ b/proofs/Fl4ProofsA64/P3/VcpuTimestampA.lean @@ -63,6 +63,7 @@ theorem vcpuXferStateA_of_maskInterruptA {AR : A → HwRootA → Prop} {Z : XSet exact ⟨⟨{ X'.j.1 with st := ⟨X'.j.1.st.cnode, X'.j.1.st.tcb⟩ cdt := ⟨X'.j.1.cdt.tree, X'.j.1.cdt.cdt, X'.j.1.cdt.cdt_slot, X'.j.1.cdt.orig, X'.j.1.cdt.par_slot, X'.j.1.cdt.prev⟩ + vsu := X'.j.1.vsu.of_frame X'.j.1.ext.xal (fun _ _ => rfl) ⟨rfl, fun _ _ => rfl⟩ (PtClosedA.refl _ _ _ _) sch := { core := X'.j.1.sch.core, cpuCs := X'.j.1.sch.cpuCs, curOfW := X'.j.1.sch.curOfW, curScOfW := X'.j.1.sch.curScOfW, cur := X'.j.1.sch.cur, csc := X'.j.1.sch.csc, idle := X'.j.1.sch.idle, idleOf := X'.j.1.sch.idleOf, idleScOf := X'.j.1.sch.idleScOf, @@ -320,7 +321,19 @@ theorem VcpuXferStateA.update_timestamp {AR : A → HwRootA → Prop} {Z : XSets (X.j.1.ext.of_spec (σ' := σ1) rfl (fun _ _ => rfl)).of_mem (fun b hb => hmem_other b (hfa b (.nslot b (.ext b hb))) (fun e => (hClkDisj _ (Or.inl rfl)).2.2.2.2.2.1 (e ▸ hb)) - (fun e => (hClkDisj _ (Or.inr rfl)).2.2.2.2.2.1 (e ▸ hb))) } + (fun e => (hClkDisj _ (Or.inr rfl)).2.2.2.2.2.1 (e ▸ hb))) + vsu := by + rw [hksb'] + exact X.j.1.vsu.of_frame X.j.1.ext.xal (fun b hb => hb.elim + (fun hb => hmem_other b (hfa b (.nslot b (.ext b hb))) + (fun e => (hClkDisj _ (Or.inl rfl)).2.2.2.2.2.1 (e ▸ hb)) + (fun e => (hClkDisj _ (Or.inr rfl)).2.2.2.2.2.1 (e ▸ hb))) + (fun hb => hmem_other b (hfa b (.nslot b (.vs b hb))) + (fun e => (hClkDisj _ (Or.inl rfl)).2.2.2.2.1 (e ▸ hb)) + (fun e => (hClkDisj _ (Or.inr rfl)).2.2.2.2.1 (e ▸ hb)))) + ⟨rfl, fun _ _ => rfl⟩ + (PtClosedA.of_cap fun y hy => Or.inl (by + unfold capAtA; rw [(hslot' y (Or.inl hy)).1, (hslot' y (Or.inl hy)).2.1])) } have hVcCore' : VcpuCoreA (L := L) Z s' σ1 := ⟨fun v hv => let ⟨xv, hk, h1, h2⟩ := X.vcpu.core.obj v hv; ⟨xv, hk, by rw [← wa_zeroA v, hvc_eq v hv 0#u64 (by decide) (by decide), wa_zeroA]; exact h1, by rw [hvc_eq v hv 24#u64 (by decide) (by decide)]; exact h2⟩, X.vcpu.core.back, diff --git a/proofs/Fl4ProofsA64/P3/VsAssignA.lean b/proofs/Fl4ProofsA64/P3/VsAssignA.lean index 278206178..4b2f31c4a 100644 --- a/proofs/Fl4ProofsA64/P3/VsAssignA.lean +++ b/proofs/Fl4ProofsA64/P3/VsAssignA.lean @@ -8,6 +8,7 @@ covers missing or ineligible extras and illegal labels. Modelled on x86 P3/VsAssign and P3/VsAssignRel. No new named premises. -/ import Fl4ProofsA64.P3.VsTopRootA +import Fl4ProofsA64.P3.VsUniqAssignA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -672,6 +673,7 @@ theorem JEntA.poolWord_offA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s | ext _ he => exact extFoot_emptyE he +set_option maxHeartbeats 1000000 in /-- The physical and abstract pool writes preserve the joint relation and the existing CDT. -/ theorem assign_write_jointA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) {s2 : S} {σ2 : Fl4SpecA64.State Unit} @@ -691,7 +693,11 @@ theorem assign_write_jointA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s (hunmS2 : tagA word = 1 → ((∀ j : U64, j.val < 1024 → dBitA (L.mem s2 (peAF (untagA word) j)) 0 = false) ∧ ∀ es, σ2.kheap (specPtr (untagA word)) = some (.archObj (.ext (.stage2Root es))) → - ∀ j : Fin 1024, es j = .invalidPTE)) : + ∀ j : Fin 1024, es j = .invalidPTE)) + (hact : ActivePoolA (L.mem s2) (L.ksb s2) p) (hold : L.mem s2 (peAF p i) = 0#u64) + (htabInj : ∀ a b q, σ2.archState.armAsidTable a = some q → σ2.archState.armAsidTable b = some q → a = b) + (hnoU : ∀ y, IsSlotA Z.th y → ¬ RootUnmA (untagA word) (capAtA (L.mem s2) y)) + (hinst : ¬ RootInstA Z.Pp Z.X (L.mem s2) (L.ksb s2) σ2 (untagA word)) : let σ3 := poolSetA σ2 p (Function.update f (BitVec.ofNat 9 i.val) (poolEntA word)) let s3 := L.wr s2 (peAF p i) word JAtZAX (L := L) AR Z s3 a σ3 m ∧ OSKeep st OS s2 s3 ∧ TyKeepA σ2 σ3 := by @@ -727,13 +733,21 @@ theorem assign_write_jointA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s have hnot (q : Fl4SpecA64.ObjRef) {o : Fl4SpecA64.KernelObject} (hq : σ2.kheap q = some o) (hn' : o ≠ .archObj (.asidPool f)) : q ≠ specPtr p := fun e => hn' (Option.some.inj (hq.symm.trans (e ▸ hk))) + have hVU := VsUniqA.of_assign (mem' := L.mem (L.wr s2 (peAF p i) word)) + (σ' := poolSetA σ2 p (Function.update f (BitVec.ofNat 9 i.val) (poolEntA word))) + J.1.vsu J.1.vs J.1.ext hp hi hk hact hold (J.1.vs.pool_offA J.1.ext.ypp hp hi hn) + (by simp [poolSetA, setObjA]) (fun q hq => poolSetA_get hq) rfl hkind + (fun b hb hne => hmem b (hall b (.nslot b (.vs b hb))) hne) + (fun b hb => hmem b (hall b (.nslot b (.ext b hb))) (hExt b hb)) + (L.mem_wr_same w.al) htabInj (fun h0 hw => (hunmVs.1 h0 hw).1) (fun h2 => (hunmVs.2 h2).1) + (fun h1 => (hunmS2 h1).1) (fun y hy => Hm.cap (Or.inl hy)) hnoU hinst 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 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, + (fun _ h1 h2 => ⟨h1, h2⟩) (by rw [L.ksb_wr]; exact hVR) hER (by rw [L.ksb_wr]; exact hVU), osKeep_tabWriteA E.sys.ent.os (fun ⟨y, hy, ho⟩ => w.os y hy ho) hmem, TyKeepA.upd hk (fun _ _ e => by cases e) (fun _ e => by cases e)⟩ · obtain ⟨cs, he, _, _⟩ := J.1.st.cnode q r hq @@ -916,6 +930,30 @@ def assignUnmappedA (k : ExtRootKind) (root oldAsid oldVa : U64) : capability.Ca | .stage2 => .Ept root 0#u64 false oldAsid oldVa | .high => .HighVSpace root false oldAsid +/-- **Assigning a root**: the mapped cap is a root-kind cap of `root` only (unmapped ones: none), as the unmapped cap +it replaces (`RootSetA`: the explicit proof the cap-write lemmas ask for a root-kind `c`). -/ +theorem RootSetA.assign (k : ExtRootKind) (root oldAsid oldVa asid : U64) : + RootSetA (assignUnmappedA k root oldAsid oldVa) (assignMappedA k root asid) := by + cases k + · refine ⟨fun r hk => ?_, fun r hu => ?_⟩ + · rcases hk with ⟨mp, a, h⟩ | ⟨mp, a, v, h⟩ | ⟨mp, a, h⟩ + · cases h; exact Or.inl ⟨_, _, rfl⟩ + · cases h + · cases h + · rcases hu with ⟨a, h⟩ | ⟨a, v, h⟩ | ⟨a, h⟩ <;> cases h + · refine ⟨fun r hk => ?_, fun r hu => ?_⟩ + · rcases hk with ⟨mp, a, h⟩ | ⟨mp, a, v, h⟩ | ⟨mp, a, h⟩ + · cases h + · cases h; exact Or.inr (Or.inl ⟨_, _, _, rfl⟩) + · cases h + · rcases hu with ⟨a, h⟩ | ⟨a, v, h⟩ | ⟨a, h⟩ <;> cases h + · refine ⟨fun r hk => ?_, fun r hu => ?_⟩ + · rcases hk with ⟨mp, a, h⟩ | ⟨mp, a, v, h⟩ | ⟨mp, a, h⟩ + · cases h + · cases h + · cases h; exact Or.inr (Or.inr ⟨_, _, rfl⟩) + · rcases hu with ⟨a, h⟩ | ⟨a, v, h⟩ | ⟨a, h⟩ <;> cases h + theorem decodeAssignRunA (ar : machine.Arch A) (s : S) (a : A) (k : ExtRootKind) (root p base oldAsid oldVa : U64) (cte dst : CslotPtr) (length buf : U64) (block call cd fp : Bool) (ex : Aeneas.Std.Array obj.Slot 3#usize) (hex : vspace.extra ex 0#usize = ok (some (cslotAddrA dst))) @@ -1067,7 +1105,8 @@ private theorem assignFinishA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie (hcap : capA st s (cslotAddrA dst) = assignUnmappedA k root oldAsid oldVa) (hbase : CapWfA (.AsidPool p base)) (hhi : hi.val < 128) (hv : hi.val = base.val / 512) (hp : p ≠ 0#u64) (hword : L.mem s (atAF (L.ksb s) hi) = p) - (hi512 : i.val < 512) (hfree : wa base i ≠ 0#u64) (w : PoolW st H Z.Cs OS s (peAF p i)) + (hi512 : i.val < 512) (hfree : wa base i ≠ 0#u64) (hentry : L.mem s (peAF p i) = 0#u64) + (w : PoolW st H Z.Cs OS s (peAF p i)) (hpP : p ∈ Z.Pp) {f : AsidPool} (hk : σ.kheap (specPtr p) = some (.archObj (.asidPool f))) (hunm : UnmRootAssignA k (L.mem s) σ root) : ∃ s' σ' σ1, @@ -1095,8 +1134,9 @@ private theorem assignFinishA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie have hn1 : assignMappedA k root (wa base i) ≠ .Null := by cases k <;> intro h <;> cases h have hn0 : assignUnmappedA k root oldAsid oldVa ≠ .Null := by cases k <;> intro h <;> cases h obtain ⟨x, s2, σ2, hx, hrestart, hrestartS, hs, hsS, Hs, hks, R, hcpu, hw2, hJ, Fr⟩ := - restart_setcapJA E RS dst hab hos hEnc hrel + restart_setcapJA E RS dst hab hos hEnc hrel (by rw [show capAtA (L.mem s) (cslotAddrA dst) = assignUnmappedA k root oldAsid oldVa from hcap]; exact RootSetA.assign k root oldAsid oldVa _) (by cases k <;> pt_nr) obtain ⟨J, T2⟩ := hJ T hnul hn1 (by rw [hcap]; exact hn0) (by rw [hcap]; exact hUA) hObj + (PtSrcA.nopt fun _ _ _ _ h => by cases k <;> cases h) have htyR := TyKeepA.stUpdA (ts := .restart) hx have hk1 : (stUpdA σ σ.curThread x .restart).kheap (specPtr p) = some (.archObj (.asidPool f)) := by have hn : specPtr p ≠ σ.curThread := fun e => by rw [e, hx] at hk; cases hk @@ -1176,7 +1216,56 @@ private theorem assignFinishA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie have hr : root.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) (E.j.1.vs.yal root hrootY)) obtain ⟨ht, -⟩ := assignTagA (tag := assignTagWordA .high) hr (by decide) exact fun ht1 => by rw [ht] at ht1; cases ht1 + have hasidE : σ2.archState.armAsidTable = σ.archState.armAsidTable := Hs.asid + have hroot4k : root.val % 4096 = 0 := by + cases k with + | stage1 => exact E.j.1.vs.al_mod (hOldObj.2.2.2.1 root false oldAsid rfl).1 + | stage2 => + exact Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) + (E.j.1.ext.xal root (hOldObj.2.1 root 0#u64 false oldAsid oldVa rfl))) + | high => + exact Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) + (E.j.1.vs.yal root (hOldObj.2.2.1 root false oldAsid rfl))) + have hurt : untagA (root ||| assignTagWordA k) = root := + (assignTagA (tag := assignTagWordA k) hroot4k (by cases k <;> decide)).2 + have hcxA : capAtA (L.mem s2) (cslotAddrA dst) = assignMappedA k root (wa base i) := Fr.1 + have hcoA : ∀ y ∈ OS, y ≠ cslotAddrA dst → capAtA (L.mem s2) y = capAtA (L.mem s) y := fun y hy e => ((Fr.2 y hy).1 e) + have hunmOld : RootUnmA root (capAtA (L.mem s) (cslotAddrA dst)) := by + have e : capAtA (L.mem s) (cslotAddrA dst) = assignUnmappedA k root oldAsid oldVa := hcap + rw [e] + cases k + · exact Or.inl ⟨_, rfl⟩ + · exact Or.inr (Or.inl ⟨_, _, rfl⟩) + · exact Or.inr (Or.inr ⟨_, rfl⟩) + obtain ⟨hnI0, hK0⟩ := E.j.1.vsu.rootOnce _ hA root hunmOld + have hnoU : ∀ y, IsSlotA Z.th y → + ¬ RootUnmA (untagA (root ||| assignTagWordA k)) (capAtA (L.mem s2) y) := by + intro y hy hRU + rw [hurt] at hRU + by_cases e : y = cslotAddrA dst + · subst e + rw [hcxA] at hRU + cases k <;> simp [RootUnmA, assignMappedA] at hRU + · have hyO : y ∈ OS := RS.sub _ hy + have e2 : capAtA (L.mem s2) y = capA st s y := hcoA y hyO e + rw [e2] at hRU + exact e (hK0 y hy hRU.kind) + have hinst : ¬ RootInstA Z.Pp Z.X (L.mem s2) (L.ksb s2) σ2 (untagA (root ||| assignTagWordA k)) := by + rw [hurt] + rintro (⟨a, raw, hact, e⟩ | ⟨a, hS⟩) + · rw [hks] at hact + exact hnI0 (Or.inl ⟨a, raw, ActiveAsidRootA.of_mem (fun b hb => hVsMem b hb) hact, e⟩) + · refine hnI0 (Or.inr ⟨a, S2RootOfAsidA.of_spec (σ := σ2) (σ' := σ) hasidE.symm (fun q hq => ?_) hS⟩) + obtain ⟨g, hkg, -⟩ := E.j.1.vs.pool q hq + have hn : specPtr q ≠ σ.curThread := fun e => by rw [e, hx] at hkg; cases hkg + have hk1 : (stUpdA σ σ.curThread x .restart).kheap (specPtr q) = some (.archObj (.asidPool g)) := by + simp [stUpdA, setObjA, Function.update_of_ne hn, hkg] + rw [hkg, Hs.keep hk1 (fun _ _ e => by cases e) (fun _ e => by cases e)] obtain ⟨J3, OK3, HT3⟩ := assign_write_jointA E RS J hks hcpu hpP hi512 w hk2 hkind hzero hunmVs2 hunmS2' + ⟨hp, hi, hhi, by rw [hks, hVsMem _ (.asid hi hhi)]; exact hword⟩ + (by rw [hVsMem _ (.pool p i hpP hi512)]; exact hentry) + (fun a b q h1 h2 => E.tabInj a b q (by rw [← hasidE]; exact h1) (by rw [← hasidE]; exact h2)) + hnoU hinst obtain ⟨ac, hg, heq⟩ := getCap_eqA E1.j.1.st hab change CapEqA (capA st (L.wr s (stA (L.curW s)) sched.TS_RESTART) (cslotAddrA dst)) ac at heq rw [OK1.capA hos, hcap] at heq @@ -1261,7 +1350,7 @@ private theorem assignRootRelA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie have w : PoolW st H Z.Cs OS s (peAF p i) := by simpa only [hmask, peAF] using hPoolOff hp (wa base i) obtain ⟨s', σ', σ1, hRun, hRestart, hPerf, J, T', C⟩ := - assignFinishA E RS T hnul k dst hab hcap hbase hhi hv hp hq hi512 hasid w hpP hk hunm + assignFinishA E RS T hnul k dst hab hcap hbase hhi hv hp hq hi512 hasid hentry w hpP hk hunm have hf := (assign_free_iffA hbase hi512 (hpool i hi512)).2 ⟨hasid, hentry⟩ have hDec := assignDec_memA (assignInvA k (specPtr p) dst) ht hk hf rw [assign_asidA hbase hi512] at hDec diff --git a/proofs/Fl4ProofsA64/P3/VsFlushA.lean b/proofs/Fl4ProofsA64/P3/VsFlushA.lean index 38a2c1b48..deb904a10 100644 --- a/proofs/Fl4ProofsA64/P3/VsFlushA.lean +++ b/proofs/Fl4ProofsA64/P3/VsFlushA.lean @@ -28,8 +28,7 @@ decoder `decodeFl4VsInvFlush` (`Fl4SpecA64/Ext/VSpace` item 3, dispatched by `fl Named premise: `ArchKeepsA` [P] (as the map / unmap tops). Decode-site hypotheses (standing): `RsSiteA`, the front end's argument facts (`hlen`, `hargs`). **Changed statement**: `decInv_vspace_jA` (ruling: total) drops its selector -`hLbl` and takes `K`, `E`, `RS`, `hTr`, `hab`, `hcap`, `hlen`, `hargs` (the facts its flush arm reads), as -`decInv_pt_jA`. No new named premise. +`hLbl` and takes `K`, `E`, `RS`, `hTr`, `hab`, `hcap`, `hlen`, `hargs` (the facts its flush arm reads). No new named premise. -/ import Fl4ProofsA64.P3.VsTopRootA open Aeneas Aeneas.Std Result diff --git a/proofs/Fl4ProofsA64/P3/VsHiMapVsuA.lean b/proofs/Fl4ProofsA64/P3/VsHiMapVsuA.lean new file mode 100644 index 000000000..f3ec15a94 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsHiMapVsuA.lean @@ -0,0 +1,160 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, G): **`VsUniqA` after a Stage-1 table link at any slot of the tracked +tables or of a window** (`linkVsuA`, the generalisation of `ptMap_vsuA`: the written table `p` is an `S1TabA` table and +the walk of the cap's `(asid, va)` to the written slot is an input, either from a tag-0 root or from a tag-2 window), +and the ASID-level root of a high window found by `vspace_for_asid` (`activeHiAsidRootA`). No premise. New module. +-/ +import Fl4ProofsA64.P3.VsPtMapVsuA +import Fl4ProofsA64.P3.ExtVsRelA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- A mapped high window found by `vspace_for_asid` is the tag-2 active root word of that ASID. -/ +theorem activeHiAsidRootA {Pp Tb X Y : Set U64} {Lv : U64 → Nat} {mem : U64 → U64} {ksb : U64} + {σ : Fl4SpecA64.State Unit} (R : VsRelA Pp Tb Lv X Y mem ksb σ) + (hX : ∀ r ∈ X, ∃ es, σ.kheap (specPtr r) = some (.archObj (.ext (.stage2Root es)))) + {asid1 y : U64} (hy : y ∈ Y) + (hv : Fl4SpecA64.vspaceForAsid (asidOfA asid1) σ = some (specPtr y)) (h16 : asid1.val < 65536) : + ∃ raw, ActiveAsidRootA mem ksb Pp asid1 raw ∧ tagA raw = 2 ∧ untagA raw = y := by + obtain ⟨-, raw, hact, hun⟩ := activeAsidRootA_of_vspaceForAsid (mem := mem) (ksb := ksb) R hv + have e : (⟨BitVec.ofNat 64 (asidOfA asid1).toNat⟩ : U64) = asid1 := by + apply UScalar.eq_of_val_eq + show (BitVec.ofNat 64 (BitVec.ofNat 16 asid1.val).toNat).toNat = asid1.val + rw [BitVec.toNat_ofNat, BitVec.toNat_ofNat]; omega + rw [e] at hact + obtain ⟨pool, hP, hactP, lo, hlo, hw, hrne⟩ := hact.activePool + have hk := R.kind pool hP hactP lo hlo + rw [hw] at hk + rcases hk with rfl | ⟨-, htb, -⟩ | ⟨-, hx⟩ | ⟨htag2, -⟩ + · exact absurd rfl hrne + · rw [hun] at htb + obtain ⟨t, hpt, -⟩ := R.pt y htb + obtain ⟨l1, hl1, -⟩ := R.high y hy + rw [hl1] at hpt; cases hpt + · rw [hun] at hx + obtain ⟨es, hes⟩ := hX y hx + obtain ⟨l1, hl1, -⟩ := R.high y hy + rw [hl1] at hes; cases hes + · exact ⟨raw, hact, htag2, hun⟩ + +/-- A Stage-2 / window-root footprint word is not a word of a Stage-1 table or window page. -/ +theorem extFoot_ne_vsA {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 σ) (hY : ∀ y ∈ Y, 8192 ∣ y.val) {P j b : U64} + (hP : P ∈ VsPtA Pp Tb Y) (hPa : 4096 ∣ P.val) (hj : j.val < 512) (hb : ExtFootE X Y T2 b) : + b ≠ peAF P j := by + obtain ⟨q', j', hj', rfl, hq', hc⟩ := ExtFootE.pgE E hY hb + refine pgNeE hq' hPa hj' hj fun e => ?_ + subst e + rcases hc with h | h + · exact (E.pgd _ h).1 hP + · exact E.ypg _ h hP + +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {A : Type} {AR : A → HwRootA → Prop} {Z : XSetsA} {OS : Set U64} {s s2 s3 : S} {a : A} + {σ σ2 σ3 : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + +theorem linkVsuA {tcbs : Set U64} + (R : VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s) (L.ksb s) σ) + (hap : ∀ b, VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b → ¬ InOS OS b ∧ ∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) + (hfr : ∀ b, Aligned b → ¬ InOS OS b → (∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) → L.mem s2 b = L.mem s b) + (J2 : JAtZAX (L := L) AR Z s2 a σ2 m) (hks2 : L.ksb s2 = L.ksb s) + (hfa : ∀ w, FootA (L := L) Z s2 w → Aligned w) + (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) {Ω T Sg : Set U64} (hO : OSOK T Ω Sg OS) + {sl : U64} {ptr asid1 base : U64} + (F2 : SlotFrA (L := L) OS sl (.PageTable ptr true asid1 base) s s2) + (hPC : PtCapInA Z (L.mem s)) (hnt : ptr ∉ Z.S1) (hnt2 : ptr ∉ Z.T2) (hpal : ptr.val % 4096 = 0) + (hpy : ∀ y ∈ Z.Y, wa y 4096#u64 ≠ ptr) + (hinv : ∀ i : U64, i.val < 512 → dBitA (L.mem s (peAF ptr i)) 0 = false) + (hzfr : ∀ i : U64, i.val < 512 → L.mem s2 (peAF ptr i) = L.mem s (peAF ptr i)) + {p i : U64} (hp : S1TabA Z.S1 Z.Y p) (hi : i.val < 512) + (hbOS : ¬ InOS OS (peAF p i)) + (hwne : ∀ b, (ExtFootE Z.X Z.Y Z.T2 b ∨ AsidWordsA Z.Pp (L.ksb s) b) → b ≠ peAF p i) + (hold : dBitA (L.mem s (peAF p i)) 0 = false) + (hw0 : ∃ raw, ActiveAsidRootA (L.mem s) (L.ksb s) Z.Pp asid1 raw ∧ + ((tagA raw = 0 ∧ raw ∈ Z.S1 ∧ WalkSlotA (S1TabA Z.S1 Z.Y) (L.mem s) base raw 39 512 (peAF p i)) ∨ + (tagA raw = 2 ∧ untagA raw ∈ Z.Y ∧ + WalkSlotA (S1TabA Z.S1 Z.Y) (L.mem s) base (wa (untagA raw) 4096#u64) 30 512 (peAF p i)))) + {v : U64} (hks3 : L.ksb s3 = L.ksb s2) + (hm3 : ∀ w, Aligned w → w ≠ peAF p i → L.mem s3 w = L.mem s2 w) + (hv : L.mem s3 (peAF p i) = v) (hdv : dTabA v = ptr) + (hP : PoolKeepA Z.Pp σ2 σ3) : + VsUniqA Z.th Z.Pp (insert ptr Z.S1) Z.X Z.Y Z.T2 Z.Sh2 (L.mem s3) (L.ksb s3) σ3 := by + have hbal : Aligned (peAF p i) := peAF_alignedA (S1TabA.mod4k R hp) hi + have hkeepE : ∀ b, ExtFootE Z.X Z.Y Z.T2 b → L.mem s3 b = L.mem s2 b := fun b hb => + hm3 b (hfa b (.nslot b (.ext b hb))) (hwne b (Or.inl hb)) + have hkeepA : ∀ b, AsidWordsA Z.Pp (L.ksb s2) b → L.mem s3 b = L.mem s2 b := fun b hb => by + have hb' : AsidWordsA Z.Pp (L.ksb s) b := by rw [← hks2]; exact hb + exact hm3 b (hfa b (FootA.s1_monoA (AsidWordsA.foot (L := L) hb))) (hwne b (Or.inr hb')) + have hmemT : ∀ t j : U64, S1TabA Z.S1 Z.Y t → j.val < 512 → L.mem s2 (peAF t j) = L.mem s (peAF t j) := by + intro t j ht hj + have hf : VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) (peAF t j) := by + rcases ht with h | ⟨y, hy, rfl⟩ + · exact .pt t j h hj + · exact .high y j hy hj + exact hfr _ (peAF_alignedA (S1TabA.mod4k R ht) hj) (hap _ hf).1 (hap _ hf).2 + have hasid : ∀ b, AsidWordsA Z.Pp (L.ksb s) b → L.mem s2 b = L.mem s b := by + intro b hb + have hf : VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b := by + rcases hb with ⟨hi', hh, rfl⟩ | ⟨q, lo, hq, hl, rfl⟩ + · exact .asid hi' hh + · exact .pool q lo hq hl + have hb' : AsidWordsA Z.Pp (L.ksb s2) b := by rw [hks2]; exact hb + exact hfr b (hfa b (FootA.s1_monoA (AsidWordsA.foot (L := L) hb'))) (hap _ hf).1 (hap _ hf).2 + have hold2 : (L.mem s2 (peAF p i) &&& 3#u64) ≠ 3#u64 := by + rw [hmemT p i hp hi] + intro h + have := ((and3_bits_sh _).1 h).1 + rw [hold] at this; cases this + have hw2 : ∃ raw, ActiveAsidRootA (L.mem s2) (L.ksb s2) Z.Pp asid1 raw ∧ + ((tagA raw = 0 ∧ raw ∈ Z.S1 ∧ WalkSlotA (S1TabA Z.S1 Z.Y) (L.mem s2) base raw 39 512 (peAF p i)) ∨ + (tagA raw = 2 ∧ untagA raw ∈ Z.Y ∧ + WalkSlotA (S1TabA Z.S1 Z.Y) (L.mem s2) base (wa (untagA raw) 4096#u64) 30 512 (peAF p i))) := by + obtain ⟨raw, hact, hw⟩ := hw0 + refine ⟨raw, ?_, ?_⟩ + · rw [hks2] + exact ActiveAsidRootA.shrink (mem := L.mem s2) (mem' := L.mem s) (fun b hb => (hasid b hb).symm) hact + · rcases hw with ⟨h0, hr, hwk⟩ | ⟨h2, hy2, hwk⟩ + · refine Or.inl ⟨h0, hr, hwk.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨ht', rfl⟩) + · exact hmemT _ _ (Or.inl hr) (walkIdx_lt _ _ 512 (by norm_num) (by norm_num)) + · exact hmemT _ _ ht' (walkIdx_lt _ _ 512 (by norm_num) (by norm_num)) + · refine Or.inr ⟨h2, hy2, hwk.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨ht', rfl⟩) + · exact hmemT _ _ (Or.inr ⟨_, hy2, rfl⟩) (walkIdx_lt _ _ 512 (by norm_num) (by norm_num)) + · exact hmemT _ _ ht' (walkIdx_lt _ _ 512 (by norm_num) (by norm_num)) + have hOSK : OSKeep st OS s2 s3 := osKeep_tabWriteA hO hbOS hm3 + rw [hks3] + refine J2.1.vsu.of_link J2.1.vs J2.1.ext.xal hp hi hnt hpal hpy hm3 hold2 (by rw [hv]; exact hdv) ?_ + hkeepE hkeepA hP ?_ ?_ hw2 + · intro j hj h + have hne : peAF ptr j ≠ peAF p i := fun e => by + rcases hp with hp | ⟨y, hy, rfl⟩ + · exact hnt ((peAF_injA_s hpal (R.al_mod hp) hj hi e).1 ▸ hp) + · have h1 := (peAF_injA_s hpal (waWin_modA (R.yal y hy)) hj hi e).1 + subst h1 + exact hpy y hy rfl + rw [hm3 _ (peAF_alignedA hpal hj) hne, hzfr j hj] at h + have := ((and3_bits_sh _).1 h).1 + rw [hinv j hj] at this; cases this + · intro y hy + rw [capAtA_eq, capAtA_eq] + exact hOSK.capA (hsub y hy) + · intro y hy a' v' hc + by_cases e : y = sl + · subst e + rw [F2.1] at hc + cases hc; exact ⟨rfl, rfl⟩ + · rw [(F2.2 y (hsub y hy)).1 e] at hc + rcases hPC y hy ptr a' v' hc with h | h + · exact absurd h.1 hnt + · exact absurd h hnt2 + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsLeafShrA.lean b/proofs/Fl4ProofsA64/P3/VsLeafShrA.lean new file mode 100644 index 000000000..0d629853e --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsLeafShrA.lean @@ -0,0 +1,236 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`): **`VsUniqA` obligations of the leaf writes**. + +* `hshr_oneA`, `s1Entry_offA`, `s2Entry_offA`: one written word of a page `q`; `q` outside the Stage-1 tables resp. the + Stage-2 pages. +* `S1EntryA.notTab_of_relHi`: the window version of `S1EntryA.notTab_of_rel`. +* `VsUniqA.of_descEqA`: `VsUniqA` across a step that keeps every descriptor's type bits and table address (the access + flag clear). + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.VsUniqShrinkA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Classical + +local notation "wa" => core.num.U64.wrapping_add + +theorem hshr_oneA {mem mem' : U64 → U64} {q i : U64} (hq : q.val % 4096 = 0) + (hm : ∀ w, Aligned w → w ≠ peAF q i → mem' w = mem w) + {Pp X T2 : Set U64} {Sh2 : U64 → Nat} {σ0 : Fl4SpecA64.State Unit} {S1 Y : Set U64} {kb : U64} + (h2 : S2EntryA Pp X T2 Sh2 mem' σ0 (peAF q i) → NotTabA (mem' (peAF q i))) + (h1 : S1EntryA Pp S1 Y mem' kb (peAF q i) → NotTabA (mem' (peAF q i))) : + ∀ j : U64, j.val < 512 → + (S2EntryA Pp X T2 Sh2 mem' σ0 (peAF q j) ∨ S1EntryA Pp S1 Y mem' kb (peAF q j)) → + mem' (peAF q j) = mem (peAF q j) ∨ NotTabA (mem' (peAF q j)) := by + intro j hj hP + by_cases e : peAF q j = peAF q i + · rw [e] at hP ⊢; exact Or.inr (hP.elim h2 h1) + · exact Or.inl (hm _ (peAF_alignedA hq hj) e) + +variable {Pp S1 X Y T2 : Set U64} {Sh2 Lv : U64 → Nat} {mem mem' : U64 → U64} {ksb : U64} + {σ σ' : Fl4SpecA64.State Unit} + +/-- A word of a page that is no Stage-1 table and no window table is no Stage-1 entry. -/ +theorem s1Entry_offA (R : VsRelA Pp S1 Lv X Y mem ksb σ) {q i : U64} (hq : q.val % 4096 = 0) (hi : i.val < 512) + (h1 : q ∉ S1) (h2 : ∀ y ∈ Y, q ≠ wa y 4096#u64) {m : U64 → U64} {kb : U64} + (h : S1EntryA Pp S1 Y m kb (peAF q i)) : False := by + obtain ⟨-, -, τ, i', -, hτ, -, hi', e⟩ := h + have := (peAF_injA_s (S1TabA.mod4k R hτ) hq hi' hi e.symm).1 + subst this + rcases hτ with h | ⟨y, hy, e⟩ + · exact h1 h + · exact h2 y hy e + +/-- A word of a Stage-1 table or window table is no Stage-2 entry. -/ +theorem s2Entry_offA (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {q i : U64} (hq : q.val % 4096 = 0) (hi : i.val < 512) + (hv : q ∈ VsPtA Pp S1 Y) {m : U64 → U64} {σ0 : Fl4SpecA64.State Unit} + (h : S2EntryA Pp X T2 Sh2 m σ0 (peAF q i)) : False := by + rcases h with ⟨r, j, hr, hj, e⟩ | ⟨t, j, -, ht, -, hj, e⟩ + · have hj1k : j.val < 1024 := by have := s2Top1k; omega + obtain ⟨q', j', hq', hj', hpe⟩ := rootWordE (E.xal r hr.1) hj1k + have hq4 : q'.val % 4096 = 0 := by + rcases hq' with h | h <;> rw [h] + · exact Nat.mod_eq_zero_of_dvd (dvd_trans (by decide : 4096 ∣ 8192) (E.xal r hr.1)) + · exact waWin_modA (E.xal r hr.1) + have := (peAF_injA_s hq4 hq hj' hi (hpe.symm.trans e.symm)).1 + subst this + exact (E.pgd q' (Or.inr ⟨r, hr.1, hq'⟩)).1 hv + · have := (peAF_injA_s (Nat.mod_eq_zero_of_dvd (E.tal t ht)) hq hj hi e.symm).1 + subst this + exact (E.pgd t (Or.inl ht)).1 hv + +theorem S1EntryA.notTab_of_relHi (R' : VsRelA Pp S1 Lv X Y mem' ksb σ') {b y j : U64} + (hE : S1EntryA Pp S1 Y mem' ksb b) (hb : b = peAF (wa y 4096#u64) j) (hy : y ∈ Y) (hj : j.val < 512) + {l1 : Fin 512 → Fl4SpecA64.PTE} (hk : σ'.kheap (specPtr y) = some (.archObj (.ext (.highVSpace l1)))) + (hnt : ∀ ppn, l1 ⟨j.val, hj⟩ ≠ .pageTablePTE ppn) : NotTabA (mem' b) := by + obtain ⟨tag, sh, τ, i', hpath, hτ, h12, hi', hb'⟩ := hE + have hτp := (peAF_injA_s (S1TabA.mod4k R' hτ) (waWin_modA (R'.yal y hy)) hi' hj (hb'.symm.trans hb)).1 + subst hτp + obtain ⟨-, hcase⟩ := R'.path_props hpath + rcases hcase with ⟨ht, -, -⟩ | ⟨-, -, y', hy', hact, hyc⟩ + · exact absurd ht (R'.ytb y hy) + have ey : y' = y := by + have h1 := wa4096_val (R'.yal y' hy') + have h2 := wa4096_val (R'.yal y hy) + have := congrArg UScalar.val hyc + exact UScalar.eq_of_val_eq (by omega) + rw [ey] at hact + obtain ⟨l1', hk', hrel⟩ := R'.high y hy + have e : l1' = l1 := by + have h := Option.some.inj (hk'.symm.trans hk) + injection h with h1 + injection h1 with h2 + injection h2 with h3 + subst e + have hr := hrel hact j hj + subst hb + intro h3 + obtain ⟨hb0, hb1⟩ := (and3_bits_sh _).1 h3 + rcases hpte : l1' ⟨j.val, hj⟩ with _ | ⟨a, sm, at', r⟩ | ppn + · rw [hpte] at hr + have h0 : dBitA (mem' (peAF (wa y 4096#u64) j)) 0 = false := hr + rw [hb0] at h0; cases h0 + · rw [hpte] at hr + have := hr.2.2.2.1.1 hb1 + omega + · exact hnt ppn hpte + +/-! ## Same descriptors -/ + +/-- Same type bits and table address. -/ +def DescEqA (a b : U64) : Prop := (a &&& 3#u64) = (b &&& 3#u64) ∧ dTabA a = dTabA b + +theorem DescEqA.symm {a b : U64} (h : DescEqA a b) : DescEqA b a := ⟨h.1.symm, h.2.symm⟩ + +/-- The words the walks read, at either state. -/ +structure DescKeepA (S1 X Y T2 : Set U64) (mem mem' : U64 → U64) : Prop where + s2r : ∀ r ∈ X, ∀ i : U64, i.val < 1024 → DescEqA (mem' (peAF r i)) (mem (peAF r i)) + s2t : ∀ t ∈ T2, ∀ i : U64, i.val < 512 → DescEqA (mem' (peAF t i)) (mem (peAF t i)) + s1 : ∀ t, S1TabA S1 Y t → ∀ i : U64, i.val < 512 → DescEqA (mem' (peAF t i)) (mem (peAF t i)) + +theorem DescKeepA.symm (h : DescKeepA S1 X Y T2 mem mem') : DescKeepA S1 X Y T2 mem' mem := + ⟨fun r hr i hi => (h.s2r r hr i hi).symm, fun t ht i hi => (h.s2t t ht i hi).symm, + fun t ht i hi => (h.s1 t ht i hi).symm⟩ + +theorem S2ReachA.descEq (K : DescKeepA S1 X Y T2 mem mem') (hP : PoolKeepA Pp σ σ') {q : U64} + (h : S2ReachA Pp X T2 Sh2 mem σ q) : S2ReachA Pp X T2 Sh2 mem' σ' q := by + have act : ∀ r, ActiveS2RootA Pp X σ r → ActiveS2RootA Pp X σ' r := by + rintro r ⟨hr, asid, p, f, h0, hp, ht, hk, hf⟩ + exact ⟨hr, asid, p, f, h0, hp, by rw [hP.1]; exact ht, by rw [hP.2 p hp]; exact hk, hf⟩ + induction h with + | root ha => exact .root (act _ ha) + | @stepRoot r i ha hi h3 hT => + have e := K.s2r r ha.1 i (by have := s2Top1k; omega) + rw [← e.2] + exact .stepRoot (act _ ha) hi (e.1.trans h3) (by rw [e.2]; exact hT) + | @stepPt t i _ ht h12 hi h3 hT ih => + have e := K.s2t t ht i hi + rw [← e.2] + exact .stepPt ih ht h12 hi (e.1.trans h3) (by rw [e.2]; exact hT) + +theorem S2EntryA.descEq (K : DescKeepA S1 X Y T2 mem mem') (hP : PoolKeepA Pp σ σ') {w : U64} + (h : S2EntryA Pp X T2 Sh2 mem σ w) : + S2EntryA Pp X T2 Sh2 mem' σ' w ∧ DescEqA (mem' w) (mem w) := by + rcases h with ⟨r, i, ha, hi, rfl⟩ | ⟨t, i, hr, ht, h12, hi, rfl⟩ + · refine ⟨Or.inl ⟨r, i, ?_, hi, rfl⟩, K.s2r r ha.1 i (by have := s2Top1k; omega)⟩ + obtain ⟨hr, asid, p, f, h0, hp, htb, hk, hf⟩ := ha + exact ⟨hr, asid, p, f, h0, hp, by rw [hP.1]; exact htb, by rw [hP.2 p hp]; exact hk, hf⟩ + · exact ⟨Or.inr ⟨t, i, hr.descEq K hP, ht, h12, hi, rfl⟩, K.s2t t ht i hi⟩ + +theorem VsPathA.descEq (R : VsRelA Pp S1 Lv X Y mem ksb σ) (K : DescKeepA S1 X Y T2 mem mem') + (hA : ∀ b, AsidWordsA Pp ksb b → mem' b = mem b) {tag : U64} {sh : Nat} {q : U64} + (h : VsPathA Pp S1 Y mem ksb tag sh q) : VsPathA Pp S1 Y mem' ksb tag sh q := by + have act : ∀ asid raw, ActiveAsidRootA mem ksb Pp asid raw → ActiveAsidRootA mem' ksb Pp asid raw := by + rintro asid raw ⟨hi, lo, h1, h2, h3, pool, hp, h0, h4, h5, h6⟩ + exact ⟨hi, lo, h1, h2, h3, pool, hp, h0, (hA _ (Or.inl ⟨hi, h1, rfl⟩)).trans h4, + (hA _ (Or.inr ⟨pool, lo, hp, h2, rfl⟩)).trans h5, h6⟩ + induction h with + | native ha ht hm => exact .native (act _ _ ha) ht hm + | high ha ht hm => exact .high (act _ _ ha) ht hm + | @child tag tb i sh _ htb h12 hi h3 ih => + have e := K.s1 tb htb i hi + rw [← e.2] + exact .child ih htb h12 hi (e.1.trans h3) + +theorem WalkSlotA.descEq {P : U64 → Prop} {va t w : U64} {sh n : Nat} (W : WalkSlotA P mem va t sh n w) + (K : ∀ t' sh' n', ((t' = t ∧ n' = n) ∨ (P t' ∧ n' = 512)) → + DescEqA (mem' (peAF t' (walkIdx va sh' n'))) (mem (peAF t' (walkIdx va sh' n')))) : + WalkSlotA P mem' va t sh n w := by + induction W with + | here t sh n => exact .here t sh n + | @down t sh n w h3 h12 hP W' ih => + have e := K t sh n (Or.inl ⟨rfl, rfl⟩) + have ih' := ih (fun t' sh' n' hh => by + rcases hh with ⟨rfl, rfl⟩ | hh + · exact K _ _ _ (Or.inr ⟨hP, rfl⟩) + · exact K _ _ _ (Or.inr hh)) + exact .down t sh n w (e.1.trans h3) h12 (by rw [e.2]; exact hP) (by rw [e.2]; exact ih') + +theorem VsUniqA.of_descEqA {th : TypedHeapA} (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) + (R : VsRelA Pp S1 Lv X Y mem ksb σ) (R' : VsRelA Pp S1 Lv X Y mem' ksb σ') + (K : DescKeepA S1 X Y T2 mem mem') (hA : ∀ b, AsidWordsA Pp ksb b → mem' b = mem b) + (hP : PoolKeepA Pp σ σ') (hc : PtClosedA th S1 T2 mem mem') : VsUniqA th Pp S1 X Y T2 Sh2 mem' ksb σ' := by + have hP' : PoolKeepA Pp σ' σ := ⟨hP.1.symm, fun p hp => (hP.2 p hp).symm⟩ + have hA' : ∀ b, AsidWordsA Pp ksb b → mem b = mem' b := fun b hb => (hA b hb).symm + have e2 : ∀ w, S2EntryA Pp X T2 Sh2 mem' σ' w → S2EntryA Pp X T2 Sh2 mem σ w ∧ DescEqA (mem' w) (mem w) := + fun w h => let ⟨a, b⟩ := h.descEq K.symm hP'; ⟨a, b.symm⟩ + have p1 : ∀ tag sh t, VsPathA Pp S1 Y mem' ksb tag sh t → VsPathA Pp S1 Y mem ksb tag sh t := + fun _ _ _ h => h.descEq R' K.symm hA' + have act : ∀ asid raw, ActiveAsidRootA mem' ksb Pp asid raw → ActiveAsidRootA mem ksb Pp asid raw := + fun _ _ h => ActiveAsidRootA.shrink (mem := mem) (mem' := mem') hA h + have act' : ∀ asid raw, ActiveAsidRootA mem ksb Pp asid raw → ActiveAsidRootA mem' ksb Pp asid raw := + fun _ _ h => ActiveAsidRootA.shrink (mem := mem') (mem' := mem) hA' h + have root : ∀ asid r, S2RootOfAsidA Pp X σ' asid r → S2RootOfAsidA Pp X σ asid r := + fun _ _ h => h.of_spec hP'.1 hP'.2 + have s1w : ∀ va t sh w, S1TabA S1 Y t → WalkSlotA (S1TabA S1 Y) mem va t sh 512 w → + WalkSlotA (S1TabA S1 Y) mem' va t sh 512 w := fun va t sh w ht W => + W.descEq fun t' sh' n' hh => by + rcases hh with ⟨rfl, rfl⟩ | ⟨h, rfl⟩ + · exact K.s1 _ ht _ (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + · exact K.s1 _ h _ (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + exact + { t2 := fun y hy ptr asid va hcap hT w hw h3 hd => by + obtain ⟨y0, hy0, hc0⟩ := (hc.pt y hy ptr asid va true hcap).resolve_right + (fun h => h.elim (fun h => h.2 hT) (fun h => h.2 hT)) + obtain ⟨hw0, em⟩ := e2 w hw + obtain ⟨r, hr, hws⟩ := U.t2 y0 hy0 ptr asid va hc0 hT w hw0 (em.1.symm.trans h3) (em.2.symm.trans hd) + refine ⟨r, hr.of_spec hP.1 hP.2, hws.descEq fun t' sh' n' hh => ?_⟩ + have hn := s2Top1k + rcases hh with ⟨rfl, rfl⟩ | ⟨h, rfl⟩ + · have := walkIdx_lt va sh' (Fl4SpecA64.s2Geom.topMask + 1) (by omega) (by omega) + exact K.s2r _ hr.1 _ (by omega) + · exact K.s2t _ h _ (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + s1 := fun y hy ptr asid va hcap hS tag sh t i hpath htab h12 hi h3 hd => by + obtain ⟨y0, hy0, hc0⟩ := (hc.pt y hy ptr asid va true hcap).resolve_right + (fun h => h.elim (fun h => h.1 hS) (fun h => by cases h.1)) + have em := K.s1 t htab i hi + obtain ⟨raw, hact, hw⟩ := U.s1 y0 hy0 ptr asid va hc0 hS tag sh t i (p1 _ _ _ hpath) htab h12 hi + (em.1.symm.trans h3) (em.2.symm.trans hd) + refine ⟨raw, act' _ _ hact, ?_⟩ + rcases hw with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · exact Or.inl ⟨h0, hr, s1w _ _ _ _ (Or.inl hr) hws⟩ + · exact Or.inr ⟨h2, hy2, s1w _ _ _ _ (Or.inr ⟨untagA raw, hy2, rfl⟩) hws⟩ + out := fun y hy ptr asid va hcap => by + rcases hc.pt y hy ptr asid va false hcap with ⟨y0, hy0, hc0⟩ | h + · exact U.out y0 hy0 ptr asid va hc0 + · exact h.elim (fun h => h.2) (fun h => h.2) + inj2 := fun a b ha hb va vb e hT => by + obtain ⟨ha0, ea⟩ := e2 a ha + obtain ⟨hb0, eb⟩ := e2 b hb + exact U.inj2 a b ha0 hb0 (ea.1.symm.trans va) (eb.1.symm.trans vb) (ea.2.symm.trans (e.trans eb.2)) + (ea.2 ▸ hT) + rootInj2 := fun a1 a2 r h1 h2 => U.rootInj2 a1 a2 r (root _ _ h1) (root _ _ h2) + inj1 := fun tag tag' sh sh' t t' i i' q1 b1 s1 i1 v1 q2 b2 s2 i2 v2 e hT => by + have m1 := K.s1 t b1 i i1 + have m2 := K.s1 t' b2 i' i2 + exact U.inj1 tag tag' sh sh' t t' i i' (p1 _ _ _ q1) b1 s1 i1 (m1.1.symm.trans v1) (p1 _ _ _ q2) b2 s2 i2 + (m2.1.symm.trans v2) (m1.2.symm.trans (e.trans m2.2)) (m1.2 ▸ hT) + rootInj1 := fun a1 a2 raw h1 h2 => U.rootInj1 a1 a2 raw (act _ _ h1) (act _ _ h2) + rootOnce := U.rootOnce.step hc.root (fun r hI => + hI.imp (fun ⟨a, raw, h, e⟩ => ⟨a, raw, act _ _ h, e⟩) (fun ⟨a, h⟩ => ⟨a, root _ _ h⟩)) + ptOnce := U.ptOnce.step hc.ptu } + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsMapA.lean b/proofs/Fl4ProofsA64/P3/VsMapA.lean index 363cadb63..464c8b9e1 100644 --- a/proofs/Fl4ProofsA64/P3/VsMapA.lean +++ b/proofs/Fl4ProofsA64/P3/VsMapA.lean @@ -52,6 +52,7 @@ No named premise. -/ import Fl4ProofsA64.P3.VsTabJA import Fl4ProofsA64.P3.VsUnmapA +import Fl4ProofsA64.P3.VsPtMapVsuA import Fl4ProofsA64.P1.QueueS1Map open Aeneas Aeneas.Std Result @@ -604,6 +605,7 @@ theorem pt_map_refinesGA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U A (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) {ptr asid0 va0 : U64} {mp : Bool} (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr mp asid0 va0) + (hPC : PtCapInA Z (L.mem s)) (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (slbl : Fl4SpecA64.Data) (hl : Fl4SpecA64.invocationType slbl = .archInvocationLabel .armPageTableMap) (length buf : U64) (args : List U64) (hlen : length.val = args.length) @@ -714,8 +716,14 @@ theorem pt_map_refinesGA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U A rw [hrun'] have R := E.j.1.vs obtain ⟨hKal, hS1A, -⟩ := E.vsLeafA - refine WP.spec_bind (lookup_pt_slotA R hrT hrL (vsReachA_of_vspaceForAsid R E.j.2.2.1.obj hrT hvRoot) a0) - fun lu ⟨p, hp, l, hl3, hsh, hlv, hsl, _, hLs, hreachP⟩ => ?_ + have hreachR := vsReachA_of_vspaceForAsid R E.j.2.2.1.obj hrT hvRoot + obtain ⟨lu, hlu, p, hp, l, hl3, hsh, hlv, hsl, -, hLs, hreachP⟩ := + spec_ex_fd (lookup_pt_slotA R hrT hrL hreachR a0) + have hwk := lookup_walkA R hrT hrL hreachR a0 + rw [hlu, WP.spec_ok] at hwk + obtain ⟨htagR, hactR⟩ := activeS1RootA R E.j.2.2.1.obj h16 hrT hvRoot + refine WP.spec_bind (show vspace.lookup_pt_slot st s r0 a0 ⦃ x => x = lu ⦄ by rw [hlu, WP.spec_ok]) fun x hx => ?_ + subst x obtain ⟨tq, hkq, htq, hrq⟩ := R.pt p hp have hidx := idxA_lt a0 lu.shift have hpte := ptesOf_atA hkq (ptT := Fl4SpecA64.levelType (lvA l)) @@ -771,7 +779,7 @@ theorem pt_map_refinesGA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U A .normalPtT (some (asidOfA asid1, a0.bv &&& ~~~(Fl4SpecA64.mask (Fl4SpecA64.ptBitsLeft (lvA l))))))) := by exact ⟨hwf, rfl, rfl, Or.inl hbv⟩ obtain ⟨xc, s2, σ2, hkx, hst, hset, hsc, hσ2, HS, hksb, R2, hcpu2, hw2, hJ2, hFr2⟩ := - restart_setcapJA E RS cte hab hos hEnc hca + restart_setcapJA E RS cte hab hos hEnc hca (hpt := Or.inl (PtSetA.map hcap)) rw [hst, bind_ok, hsc, bind_ok] -- the new table at the written states have hpal : ptr.val % 4096 = 0 := Nat.mod_eq_zero_of_dvd UP.al @@ -839,16 +847,63 @@ theorem pt_map_refinesGA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U A intro hT hnul hTO hc have hco : capA st s (cslotAddrA cte) = .PageTable ptr false asid0 va0 := by rw [← capAtA_eq, hcap] obtain ⟨J2, hT2⟩ := hJ2 hT hnul (by simp) (by rw [hco]; simp) - (UA.of_shapeA (by rw [hco]; rfl) fun h => by rw [hco] at h; simp [isUtA] at h) + (by rw [hco]; exact ⟨rfl, rfl, rfl, rfl, 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), trivial⟩ + (fun p' a' v' mp e => by cases e; exact Or.inr (Or.inl ⟨UP.nt, fun h => hc.1 (Or.inl h)⟩)) obtain ⟨t', rfl⟩ := storePte_eqA R3 (Set.mem_insert_of_mem _ hp) hidx hstore + have hsub : ∀ y, IsSlotA Z.th y → y ∈ OS := by + obtain ⟨⟨Rp, Nt, extra', sp, P⟩, Y, hrun, hcur, hvs, hvc, hsub⟩ := RS; exact hsub + have hfr : ∀ b, Aligned b → ¬ InOS OS b → (∀ t ∈ H.tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) → + L.mem s2 b = L.mem s b := by + intro b ha hnos htc + have hnc : ¬ W7.CapW H.tcbs {b | InOS OS b} ∅ b := by + rintro (⟨t, ht, K, hK, he⟩ | ⟨hin, -⟩) + · have hfit := (E.sq.tcbs t ht).fits + simp only [Nat.reducePow] at hfit + have := congrArg UScalar.val he + rw [wa_valm] at this + rcases htc t ht with h | h <;> omega + · exact hnos hin + have hns : stA (L.curW s) ≠ b := fun e => by + have := congrArg UScalar.val e + have e3 : (3328#u64 : U64).val = 3328 := rfl + have hfit := hta.fits + simp only [Nat.reducePow] at hfit + rw [stA_eq, wa_valm, e3] at this + rcases htc _ hcurT with h | h <;> omega + rw [hw2.2.2 _ ha hnc, mem_wr_ne' sA ha hns] + have hN : ∀ c ∈ Z.Cs, ∀ o : U64, o.val < 4288 → o.val % 8 = 0 → Aligned (L.nodeAt s2 c o) := + fun c hc o h1 h2 => by rw [nodeAt_ksb hksb]; exact bxi_nodes E.sys.ent.bxi c hc o h1 h2 + have hbase' : ∀ k, lu.shift.val ≤ k → walkIdx base k 512 = walkIdx a0 k 512 := fun k hk => by + rw [← hbase]; exact walkIdx_baseA a0 lu.shift.val k hk + have hwalk := hwk base hbase' + rw [hsl] at hwalk hv' + have hP : PoolKeepA Z.Pp σ2 σ4 := by + obtain ⟨ms, hh⟩ := hms + rw [hh] + refine ⟨rfl, fun q hq => ?_⟩ + show (ptSetA σ2 (specPtr p) t').kheap (specPtr q) = _ + rw [ptSetA_kheap, if_neg] + intro e + have := specPtr_inj e + subst this + obtain ⟨_, h1, -⟩ := J2.1.vs.pool q hq + obtain ⟨_, h2, -⟩ := J2.1.vs.pt q hp + rw [h1] at h2; cases h2 + have hbal := peAF_alignedA (R.al_mod hp) hidx + have hv3m : L.mem (L.wr s2 (peAF p (idxA a0 lu.shift)) v) (peAF p (idxA a0 lu.shift)) = v := + L.mem_wr_same hbal + have VU := ptMap_vsuA (s3 := L.wr s2 (peAF p (idxA a0 lu.shift)) v) (σ3 := σ4) R E.ap.vs hfr J2 hksb + (FootA.aligned J2.1 hN E.scAl E.ap.vcAl) hsub E.sys.ent.os hFr2 hPC UP.nt (fun h => hc.1 (Or.inl h)) hpal + UP.ytb UP.inv hmem2 hp hidx ((hTO p hp).of_ksA hksb hcpu2) hv' hrT htagR hactR hwalk (L.ksb_wr _ _ _) + (fun w hw hne => mem_wr_ne' hbal hw (Ne.symm hne)) hv3m hdTab hP exact map_finJA E J2 hT2 hksb hcpu2 hp (hTO p hp) hidx (L.ksb_wr _ _ _) (L.cpu_wr _ _ _) (fun w hw hne => mem_wr_ne' (peAF_alignedA (R.al_mod hp) hidx) hw (Ne.symm hne)) hms (fun q hq => (Set.mem_insert_iff.1 hq).elim (fun e => by subst e; exact Or.inr hc) Or.inl) (fun q hq hl => by have hne : q ≠ ptr := fun e => UP.nt (e ▸ hq) exact ⟨Set.mem_insert_of_mem _ hq, by rw [Function.update_of_ne hne]; exact hl⟩) - (R4.of_msA hms) hFr2 hos + (R4.of_msA hms) VU hFr2 hos refine (WP.spec_ok _).2 ⟨rfl, _, rfl, _, hset, σ4, Z.Lv p + 1, ?_, R4.of_msA hms, by omega, asid1, base, hMJ⟩ simp only [Fl4SpecA64.performPageTableInvocation, Fl4SpecA64.performPtInvMap, nd_bind_applyA, Set.mem_setOf_eq] @@ -876,6 +931,7 @@ theorem pt_map_refinesA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) {ptr asid0 va0 : U64} {mp : Bool} (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr mp asid0 va0) + (hPC : PtCapInA Z (L.mem s)) (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (slbl : Fl4SpecA64.Data) (hl : Fl4SpecA64.invocationType slbl = .archInvocationLabel .armPageTableMap) (length buf : U64) (args : List U64) (hlen : length.val = args.length) @@ -888,7 +944,7 @@ theorem pt_map_refinesA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac (.PageTable ptr mp asid0 va0) buf extra ⦃ res => PtMapPostA (L := L) Z ptr σ ((Fl4SpecA64.decodePageTableInvocation (Z := Unit) slbl (args.map UScalar.bv) cte (.pageTableCap (specPtr ptr) .normalPtT (mapDataA mp asid0 va0)) exs).run σ) s a res ⦄ := - WP.spec_mono (pt_map_refinesGA ar E ⟨⟨_, _, _, _, P⟩, Y, hrun, hcur, hvs, hvc, hsub⟩ cte hab hos hcap UP slbl hl + WP.spec_mono (pt_map_refinesGA ar E ⟨⟨_, _, _, _, P⟩, Y, hrun, hcur, hvs, hvc, hsub⟩ cte hab hos hcap hPC UP slbl hl length buf args hlen hargs x0 hx0 exs hex hS1 hHi) fun _ h => PtMapPostGA.weakA h end top diff --git a/proofs/Fl4ProofsA64/P3/VsMapJA.lean b/proofs/Fl4ProofsA64/P3/VsMapJA.lean index 874caeb90..63fe5c3af 100644 --- a/proofs/Fl4ProofsA64/P3/VsMapJA.lean +++ b/proofs/Fl4ProofsA64/P3/VsMapJA.lean @@ -192,6 +192,7 @@ theorem pt_map_jA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac Pp Tb (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) {ptr asid0 va0 : U64} {mp : Bool} (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr mp asid0 va0) + (hPC : PtCapInA Z (L.mem s)) (UP : UnmPtA Z.S1 Z.Y OS H.tcbs (L.mem s) σ ptr) (slbl : Fl4SpecA64.Data) (hl : Fl4SpecA64.invocationType slbl = .archInvocationLabel .armPageTableMap) (length buf : U64) (args : List U64) (hlen : length.val = args.length) @@ -206,7 +207,7 @@ theorem pt_map_jA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U Ac Pp Tb (.PageTable ptr mp asid0 va0) buf extra ⦃ res => PtMapJPostA (L := L) AR Z OS m ptr σ ((Fl4SpecA64.decodePageTableInvocation (Z := Unit) slbl (args.map UScalar.bv) cte (.pageTableCap (specPtr ptr) .normalPtT (mapDataA mp asid0 va0)) exs).run σ) s a res ⦄ := - WP.spec_mono (pt_map_refinesGA ar E RS cte hab hos hcap UP slbl hl length buf args hlen + WP.spec_mono (pt_map_refinesGA ar E RS cte hab hos hcap hPC UP slbl hl length buf args hlen hargs x0 hx0 exs hex hS1 hHi) fun _ h => PtMapPostGA.liftA hT hnul hTO ⟨hS2, hY⟩ RS.sub hcap h /-- **Stage-1 `ARMPageMap` with `JAtZAX` after it** (module docstring): `page_map_refinesGA` under `ArchKeepsA` diff --git a/proofs/Fl4ProofsA64/P3/VsMapPageA.lean b/proofs/Fl4ProofsA64/P3/VsMapPageA.lean index d6bea6a11..83430eb7b 100644 --- a/proofs/Fl4ProofsA64/P3/VsMapPageA.lean +++ b/proofs/Fl4ProofsA64/P3/VsMapPageA.lean @@ -689,7 +689,9 @@ theorem restart_setcapA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ (hvc : ∀ v ∈ Z.V, stA (L.curW s) ≠ v ∧ stA (L.curW s) ≠ wa v 24#u64) (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) - {c : capability.Cap} {sc : Fl4SpecA64.Cap} (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) : + {c : capability.Cap} {sc : Fl4SpecA64.Cap} (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) + (hrt : RootSetA (capAtA (L.mem s) (cslotAddrA cte)) c := by root_nr) + (hpt : PtSetE Z.th (L.mem s) (cslotAddrA cte) c := by pt_nr) : ∃ x s2 σ2, σ.kheap σ.curThread = some (.tcb x) ∧ sched.set_thread_state st s (L.curW s) sched.TS_RESTART = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) ∧ Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = @@ -699,7 +701,7 @@ theorem restart_setcapA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ SpecSlotA (stUpdA σ σ.curThread x .restart) σ2 ∧ L.ksb s2 = L.ksb s ∧ VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s2) (L.ksb s2) σ2 := by obtain ⟨x, s2, σ2, h1, h2, h3, h4, h5, h6, h7, h8, -⟩ := - restart_setcapJA E ⟨⟨_, _, _, _, P⟩, Y, hrun, hcur, hvs, hvc, hsub⟩ cte hab hos hEnc hca + restart_setcapJA E ⟨⟨_, _, _, _, P⟩, Y, hrun, hcur, hvs, hvc, hsub⟩ cte hab hos hEnc hca hrt hpt exact ⟨x, s2, σ2, h1, h2, h3, h4, h5, h6, h7, h8⟩ /-! ## The refinement -/ @@ -998,7 +1000,7 @@ theorem page_map_refinesGA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U have hK2 : Aligned (L.ksb s2) := by rw [hksb2]; exact hKal obtain ⟨-, σ3, hstore, R4, -⟩ := write_storePteA R2 hp hidx hwr hA hK2 (fun _ h => by unfold Fl4SpecA64.makeUserPte at h; cases h) - obtain ⟨t', hσ3⟩ := storePte_eqA R2 hp hidx hstore + obtain ⟨t', hσ3, happ⟩ := storePte_eq2A R2 hp hidx hstore -- `install_page` have hsla : Aligned lu.slot := by rw [hsl]; exact peAF_alignedA (R.al_mod hp) hidx obtain ⟨s', hks', hcpu', hm', hfl⟩ := install_pageA (L := L) ar s2 a lu e r0 asid1 a0 a2 hsla @@ -1026,10 +1028,12 @@ theorem page_map_refinesGA (ar : machine.Arch A) (E : JEntA (L := L) AR Z H OS U obtain ⟨J2, hT2⟩ := hJ2 hT hnul (by simp) (by rw [← capAtA_eq, hcap]; simp) (UA.of_shapeA (by rw [← capAtA_eq, hcap] <;> rfl) fun h => by rw [← capAtA_eq, hcap] 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), fun _ _ => hva⟩ + (PtSrcA.nopt fun _ _ _ _ h => by cases h) subst hσ3 - exact (map_finJA (S1' := Z.S1) (Lv' := Z.Lv) E J2 hT2 hksb2 hcpu2 hp (hTO p hp) hidx hks' hcpu' + exact (map_finJA_leaf E J2 hT2 hksb2 hcpu2 hp (hTO p hp) hidx hks' hcpu' (fun w hw hne => by rw [hm' w hw, hsl, mem_wr_ne' (peAF_alignedA (R.al_mod hp) hidx) hw (Ne.symm hne)]) - hms (fun q hq => Or.inl hq) (fun _ hq hl => ⟨hq, hl⟩) VR hFr2 hos).imp_left fun J => J.of_arA har + hms VR (fun ppn h => by rw [happ] at h; unfold Fl4SpecA64.makeUserPte at h; cases h) hFr2 hos).imp_left + fun J => J.of_arA har | _ => simp only [bind_ok, Bool.false_eq_true, ↓reduceIte, vspace.check_vspace, error.invalid_cap, core.result.Result.Insts.CoreOpsTry.branch, diff --git a/proofs/Fl4ProofsA64/P3/VsPtMapVsuA.lean b/proofs/Fl4ProofsA64/P3/VsPtMapVsuA.lean new file mode 100644 index 000000000..dd5fbd36a --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsPtMapVsuA.lean @@ -0,0 +1,155 @@ +/- +P3 (aarch64, Stage 5 vsinv): **`VsUniqA` after a Stage-1 `ARMPageTableMap`** (`ptMap_vsuA`): `VsUniqA.of_link` at the +descriptor write after the cap write, with the arm's facts (`lookup_walkA`, `PtCapInA` at the entry: no mapped +page-table cap names the unlinked table). No new premise. New module. +-/ +import Fl4ProofsA64.P3.VsUniqLinkA +import Fl4ProofsA64.P3.VsWalkSlotA +import Fl4ProofsA64.P3.VsTabJA +import Fl4ProofsA64.P3.FinKeepA +import Fl4ProofsA64.P3.VsFindA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- Aligning an address down below a shift keeps the walk's indices from that shift up. -/ +theorem walkIdx_baseA (a : U64) (sh k : Nat) (hsk : sh ≤ k) : + walkIdx (a &&& ~~~(⟨BitVec.ofNat 64 (2 ^ sh - 1)⟩ : U64)) k 512 = walkIdx a k 512 := by + have h : (a &&& ~~~(⟨BitVec.ofNat 64 (2 ^ sh - 1)⟩ : U64)).val / 2 ^ k = a.val / 2 ^ k := by + rw [← Nat.shiftRight_eq_div_pow, ← Nat.shiftRight_eq_div_pow] + show (a.bv &&& ~~~(BitVec.ofNat 64 (2 ^ sh - 1))).toNat >>> k = a.bv.toNat >>> k + rw [← BitVec.toNat_ushiftRight, ← BitVec.toNat_ushiftRight] + congr 1 + apply BitVec.eq_of_getLsbD_eq + intro i hi + simp only [BitVec.getLsbD_ushiftRight, BitVec.getLsbD_and, BitVec.getLsbD_not, BitVec.getLsbD_ofNat, + Nat.testBit_two_pow_sub_one] + by_cases h64 : k + i < 64 + · simp [h64, show ¬ k + i < sh by omega] + · rw [BitVec.getLsbD_of_ge a.bv (k + i) (by show 64 ≤ k + i; omega)] + simp + unfold walkIdx + rw [h] + +/-- A mapped VSpace root found by `vspace_for_asid` is the active Stage-1 root word of that ASID. -/ +theorem activeS1RootA {Pp Tb X Y : Set U64} {Lv : U64 → Nat} {mem : U64 → U64} {ksb : U64} + {σ : Fl4SpecA64.State Unit} (R : VsRelA Pp Tb Lv X Y mem ksb σ) + (hX : ∀ r ∈ X, ∃ es, σ.kheap (specPtr r) = some (.archObj (.ext (.stage2Root es)))) + {asid1 r0 : U64} (h16 : asid1.val < 65536) (hr : r0 ∈ Tb) + (hv : Fl4SpecA64.vspaceForAsid (asidOfA asid1) σ = some (specPtr r0)) : + tagA r0 = 0 ∧ ActiveAsidRootA mem ksb Pp asid1 r0 := by + obtain ⟨-, raw, hact, hun⟩ := activeAsidRootA_of_vspaceForAsid (mem := mem) (ksb := ksb) R hv + have e : (⟨BitVec.ofNat 64 (asidOfA asid1).toNat⟩ : U64) = asid1 := by + apply UScalar.eq_of_val_eq + show (BitVec.ofNat 64 (BitVec.ofNat 16 asid1.val).toNat).toNat = asid1.val + rw [BitVec.toNat_ofNat, BitVec.toNat_ofNat]; omega + rw [e] at hact + obtain ⟨pool, hP, hactP, lo, hlo, hw, hrne⟩ := hact.activePool + have hk := R.kind pool hP hactP lo hlo + rw [hw] at hk + rcases hk with rfl | ⟨htag0, -, -⟩ | ⟨-, hx⟩ | ⟨-, hy⟩ + · exact absurd rfl hrne + · have hraw : raw = r0 := by rw [← hun, untagA_of htag0] + subst hraw + exact ⟨htag0, hact⟩ + · rw [hun] at hx + obtain ⟨es, hes⟩ := hX r0 hx + obtain ⟨t, hpt, -⟩ := R.pt r0 hr + rw [hes] at hpt; cases hpt + · rw [hun] at hy + obtain ⟨l1, hl1, -⟩ := R.high r0 hy + obtain ⟨t, hpt, -⟩ := R.pt r0 hr + rw [hl1] at hpt; cases hpt + +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {A : Type} {AR : A → HwRootA → Prop} {Z : XSetsA} {OS : Set U64} {s s2 s3 : S} {a : A} + {σ σ2 σ3 : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + +theorem ptMap_vsuA {tcbs : Set U64} + (R : VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s) (L.ksb s) σ) + (hap : ∀ b, VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b → ¬ InOS OS b ∧ ∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) + (hfr : ∀ b, Aligned b → ¬ InOS OS b → (∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) → L.mem s2 b = L.mem s b) + (J2 : JAtZAX (L := L) AR Z s2 a σ2 m) (hks2 : L.ksb s2 = L.ksb s) + (hfa : ∀ w, FootA (L := L) Z s2 w → Aligned w) + (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) {Ω T Sg : Set U64} (hO : OSOK T Ω Sg OS) + {sl : U64} {ptr asid1 base : U64} + (F2 : SlotFrA (L := L) OS sl (.PageTable ptr true asid1 base) s s2) + (hPC : PtCapInA Z (L.mem s)) (hnt : ptr ∉ Z.S1) (hnt2 : ptr ∉ Z.T2) (hpal : ptr.val % 4096 = 0) + (hpy : ∀ y ∈ Z.Y, wa y 4096#u64 ≠ ptr) + (hinv : ∀ i : U64, i.val < 512 → dBitA (L.mem s (peAF ptr i)) 0 = false) + (hzfr : ∀ i : U64, i.val < 512 → L.mem s2 (peAF ptr i) = L.mem s (peAF ptr i)) + {p i : U64} (hp : p ∈ Z.S1) (hi : i.val < 512) (T0 : TabOffA (L := L) Z m s2 p) + (hold : dBitA (L.mem s (peAF p i)) 0 = false) + {r0 : U64} (hr0 : r0 ∈ Z.S1) (htag : tagA r0 = 0) + (hact : ActiveAsidRootA (L.mem s) (L.ksb s) Z.Pp asid1 r0) + (hwalk : WalkSlotA (S1TabA Z.S1 Z.Y) (L.mem s) base r0 39 512 (peAF p i)) + {v : U64} (hks3 : L.ksb s3 = L.ksb s2) + (hm3 : ∀ w, Aligned w → w ≠ peAF p i → L.mem s3 w = L.mem s2 w) + (hv : L.mem s3 (peAF p i) = v) (hdv : dTabA v = ptr) + (hP : PoolKeepA Z.Pp σ2 σ3) : + VsUniqA Z.th Z.Pp (insert ptr Z.S1) Z.X Z.Y Z.T2 Z.Sh2 (L.mem s3) (L.ksb s3) σ3 := by + have hbnot : ∀ w, FootA (L := L) { Z with S1 := ∅ } s2 w → w ≠ peAF p i := fun w hw e => T0.mem i hi (e ▸ hw) + have hkeep : ∀ w, FootA (L := L) { Z with S1 := ∅ } s2 w → L.mem s3 w = L.mem s2 w := fun w hw => + hm3 w (hfa w (FootA.s1_monoA hw)) (hbnot w hw) + have hbOS : ¬ InOS OS (peAF p i) := (hap _ (.pt p i hp hi)).1 + have hOSK : OSKeep st OS s2 s3 := osKeep_tabWriteA hO hbOS hm3 + have hmemT : ∀ t j : U64, S1TabA Z.S1 Z.Y t → j.val < 512 → L.mem s2 (peAF t j) = L.mem s (peAF t j) := by + intro t j ht hj + have hf : VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) (peAF t j) := by + rcases ht with h | ⟨y, hy, rfl⟩ + · exact .pt t j h hj + · exact .high y j hy hj + exact hfr _ (peAF_alignedA (S1TabA.mod4k R ht) hj) (hap _ hf).1 (hap _ hf).2 + have hasid : ∀ b, AsidWordsA Z.Pp (L.ksb s) b → L.mem s2 b = L.mem s b := by + intro b hb + have hf : VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b := by + rcases hb with ⟨hi', hh, rfl⟩ | ⟨q, lo, hq, hl, rfl⟩ + · exact .asid hi' hh + · exact .pool q lo hq hl + have hb' : AsidWordsA Z.Pp (L.ksb s2) b := by rw [hks2]; exact hb + exact hfr b (hfa b (FootA.s1_monoA (AsidWordsA.foot (L := L) hb'))) (hap _ hf).1 (hap _ hf).2 + have hbal : Aligned (peAF p i) := peAF_alignedA (R.al_mod hp) hi + have hold2 : (L.mem s2 (peAF p i) &&& 3#u64) ≠ 3#u64 := by + rw [hmemT p i (Or.inl hp) hi] + intro h + have := ((and3_bits_sh _).1 h).1 + rw [hold] at this; cases this + have hact2 : ActiveAsidRootA (L.mem s2) (L.ksb s2) Z.Pp asid1 r0 := by + rw [hks2] + exact ActiveAsidRootA.shrink (mem := L.mem s2) (mem' := L.mem s) (fun b hb => (hasid b hb).symm) hact + have hwalk2 : WalkSlotA (S1TabA Z.S1 Z.Y) (L.mem s2) base r0 39 512 (peAF p i) := by + refine hwalk.of_mem' ?_ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨ht', rfl⟩) + · exact hmemT _ _ (Or.inl hr0) (walkIdx_lt _ _ 512 (by norm_num) (by norm_num)) + · exact hmemT _ _ ht' (walkIdx_lt _ _ 512 (by norm_num) (by norm_num)) + rw [hks3] + refine J2.1.vsu.of_link J2.1.vs J2.1.ext.xal (Or.inl hp) hi hnt hpal hpy hm3 hold2 (by rw [hv]; exact hdv) ?_ + (fun b hb => hkeep b (.nslot b (.ext b hb))) (fun b hb => hkeep b (AsidWordsA.foot (L := L) hb)) hP ?_ ?_ + ⟨r0, hact2, Or.inl ⟨htag, hr0, hwalk2⟩⟩ + · intro j hj h + have hne : peAF ptr j ≠ peAF p i := fun e => + hnt ((peAF_injA_s hpal (R.al_mod hp) hj hi e).1 ▸ hp) + rw [hm3 _ (peAF_alignedA hpal hj) hne, hzfr j hj] at h + have := ((and3_bits_sh _).1 h).1 + rw [hinv j hj] at this; cases this + · intro y hy + rw [capAtA_eq, capAtA_eq] + exact hOSK.capA (hsub y hy) + · intro y hy a' v' hc + by_cases e : y = sl + · subst e + rw [F2.1] at hc + cases hc; exact ⟨rfl, rfl⟩ + · rw [(F2.2 y (hsub y hy)).1 e] at hc + rcases hPC y hy ptr a' v' hc with h | h + · exact absurd h.1 hnt + · exact absurd h hnt2 + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsS2ArmVsuA.lean b/proofs/Fl4ProofsA64/P3/VsS2ArmVsuA.lean new file mode 100644 index 000000000..518b8d750 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsS2ArmVsuA.lean @@ -0,0 +1,174 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, G): **the Stage-2 `ARMPageTableMap` VU, once for both arms** (`s2MapVsuA`): +`linkVsuS2A` fed from the arm's descriptor-slot case analysis (`SlotRelE`), plus the walk-index agreement of the +looked-up address, its aligned base and the cap's `unpack48A` base (`agreeWA_baseU`), and the pool-keep of the +restart + cap write (`poolKeepA_stUpd`). No premise. New module. +-/ +import Fl4ProofsA64.P3.VsS2MapVsuA +import Fl4ProofsA64.P3.ExtMapFrA +import Fl4ProofsA64.P3.VsHiMapVsuA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4Spec Fl4SpecA64 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- Aligning down keeps the walk's indices (any entry count) from that shift up. -/ +theorem walkIdx_baseG (a : U64) (sh k n : Nat) (hsk : sh ≤ k) : + walkIdx (a &&& ~~~(⟨BitVec.ofNat 64 (2 ^ sh - 1)⟩ : U64)) k n = walkIdx a k n := by + have h : (a &&& ~~~(⟨BitVec.ofNat 64 (2 ^ sh - 1)⟩ : U64)).val / 2 ^ k = a.val / 2 ^ k := by + rw [← Nat.shiftRight_eq_div_pow, ← Nat.shiftRight_eq_div_pow] + show (a.bv &&& ~~~(BitVec.ofNat 64 (2 ^ sh - 1))).toNat >>> k = a.bv.toNat >>> k + rw [← BitVec.toNat_ushiftRight, ← BitVec.toNat_ushiftRight] + congr 1 + apply BitVec.eq_of_getLsbD_eq + intro i hi + simp only [BitVec.getLsbD_ushiftRight, BitVec.getLsbD_and, BitVec.getLsbD_not, BitVec.getLsbD_ofNat, + Nat.testBit_two_pow_sub_one] + by_cases h64 : k + i < 64 + · simp [h64, show ¬ k + i < sh by omega] + · rw [BitVec.getLsbD_of_ge a.bv (k + i) (by show 64 ≤ k + i; omega)] + simp + unfold walkIdx + rw [h] + + +/-- The `unpack48A` of an address agrees with it on the index bits below bit 48. -/ +theorem walkIdx_unpack48G (b : U64) (k e : Nat) (hke : k + e ≤ 48) : + walkIdx (⟨unpack48A b.bv⟩ : U64) k (2 ^ e) = walkIdx b k (2 ^ e) := by + unfold walkIdx + congr 2 + show (unpack48A b.bv).toNat / 2 ^ k % 2 ^ e = b.val / 2 ^ k % 2 ^ e + unfold unpack48A + split + · rfl + · apply Nat.eq_of_testBit_eq + intro i + rw [Nat.testBit_mod_two_pow, Nat.testBit_mod_two_pow, Nat.testBit_div_two_pow, Nat.testBit_div_two_pow] + by_cases hi : i < e + · have hlt : i + k < 48 := by omega + simp only [hi, decide_true, Bool.true_and] + rw [BitVec.toNat_or, Nat.testBit_or] + have hM : (0xffff000000000000#64 : BitVec 64).toNat = 18446462598732840960 := by rfl + have h0 : (18446462598732840960 % 2 ^ 48) = 0 := by norm_num + have h := Nat.testBit_mod_two_pow 18446462598732840960 48 (i + k) + rw [h0, Nat.zero_testBit, decide_eq_true hlt, Bool.true_and] at h + rw [hM, ← h, Bool.or_false] + rfl + · simp [hi] + +theorem agreeWA_baseU (ipa base : U64) {sh : Nat} + (hbase : ipa &&& ~~~(⟨BitVec.ofNat 64 (2 ^ sh - 1)⟩ : U64) = base) : + AgreeWA (⟨unpack48A base.bv⟩ : U64) ipa sh := fun k e hk hke => by + rw [walkIdx_unpack48G base k e hke, ← hbase, walkIdx_baseG ipa sh k _ hk] + +section arm +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {A : Type} {AR : A → HwRootA → Prop} {Z : XSetsA} {OS : Set U64} {s s2 : S} {a : A} + {σ σ2 : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + +/-- The restart and the in-place cap write keep the pools and the ASID table. -/ +theorem poolKeepA_stUpd {x : Fl4SpecA64.Tcb} (hkx : σ.kheap σ.curThread = some (.tcb x)) + (HS : SpecSlotA (stUpdA σ σ.curThread x .restart) σ2) + (V : VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s) (L.ksb s) σ) : PoolKeepA Z.Pp σ σ2 := by + refine ⟨HS.asid, fun q hq => ?_⟩ + obtain ⟨f, hf, -⟩ := V.pool q hq + have h1 := stUpd_keep (ts := .restart) hkx hf (fun _ h => by cases h) + rw [HS.keep h1 (fun _ _ h => by cases h) (fun _ h => by cases h), hf] + + +/-- **`VsUniqA` after the Stage-2 `ARMPageTableMap`'s descriptor write** (module docstring). -/ +theorem s2MapVsuA {tcbs : Set U64} {T Ω Sg : Set U64} {sl ptr asid1 baseU root ew lslot : U64} + {pos : Fl4SpecA64.ExtPos} {s3 : S} + (J2 : JAtZAX (L := L) AR Z s2 a σ2 m) (hks2 : L.ksb s2 = L.ksb s) + (hfa : ∀ w, FootA (L := L) Z s2 w → Aligned w) (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) (hO : OSOK T Ω Sg OS) + (F2 : SlotFrA (L := L) OS sl (.PageTable ptr true asid1 baseU) s s2) (hPC : PtCapInA Z (L.mem s)) + (hab : IsSlotA Z.th sl) (hS2 : ptr ∉ S2PgE Z.X Z.T2) (hY : ptr ∉ Z.Y) (hnt : ptr ∉ Z.S1) + (hpal : ptr.val % 4096 = 0) + (hinv : ∀ i : U64, i.val < 512 → dBitA (L.mem s (peAF ptr i)) 0 = false) + (hzfr : ∀ i : U64, i.val < 512 → L.mem s2 (peAF ptr i) = L.mem s (peAF ptr i)) + (hapV : ∀ b, VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b → ¬ InOS OS b ∧ ∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) + (hapE : ∀ b, ExtFootE Z.X Z.Y Z.T2 b → ¬ InOS OS b ∧ ∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) + (hfr : ∀ b, Aligned b → ¬ InOS OS b → (∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) → L.mem s2 b = L.mem s b) + (hT : OffAsE Z.Pp Z.S1 Z.X Z.Y Z.T2 (L.ksb s)) + (hsl : SlotRelE (G2E Z.T2 Z.Sh2) (TopS2E Z.X) lslot pos.slot pos.shift) + (hvf : dBitA (L.mem s lslot) 0 = false) + (hW : ExtWordWriteA (st := st) s2 s3 lslot ew) (hdTab : dTabA ew = ptr) + (hroot : S2RootOfAsidA Z.Pp Z.X σ2 asid1 root) + (hwalk : WalkSlotA (· ∈ Z.T2) (L.mem s) baseU root Fl4SpecA64.s2Geom.topShift + (Fl4SpecA64.s2Geom.topMask + 1) lslot) : + VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y (insert ptr Z.T2) (Function.update Z.Sh2 ptr (pos.shift - 9)) (L.mem s3) + (L.ksb s3) (extSlotWriteX σ2 pos.slot (.pageTablePTE (ppnFromPptr (specPtr ptr)))) := by + -- the written word is a word of an S2 page + have hq : ∃ q j : U64, j.val < 512 ∧ lslot = peAF q j ∧ q.val % 4096 = 0 ∧ q ∈ S2PgE Z.X Z.T2 := by + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨r0, j0, hr0, hj0, hluEq, -, -⟩ + · exact ⟨t, i, hi, hluEq, J2.1.ext.tal t ht |> Nat.mod_eq_zero_of_dvd, Or.inl ht⟩ + · 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 + refine ⟨q, j, hj, hluEq.trans hpe, ?_, Or.inr ⟨r0, hr0, hq⟩⟩ + exact Nat.mod_eq_zero_of_dvd (hq.elim (fun e => e ▸ al4kE (J2.1.ext.xal r0 hr0)) + (fun e => e ▸ al4kHiE (J2.1.ext.xal r0 hr0))) + obtain ⟨q, j, hj, hqe, hq4, hqS⟩ := hq + have hwF : ExtFootE Z.X Z.Y Z.T2 lslot := by + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, -⟩ | ⟨r0, j0, hr0, hj0, hluEq, -, -⟩ + · rw [hluEq]; exact .s2pt t i ht hi + · rw [hluEq]; exact rootFootE hr0 (J2.1.ext.xal r0 hr0) (by have := s2GeomNumE.2.2.1; omega) + have hbal : Aligned lslot := hfa lslot (.nslot _ (.ext _ hwF)) + refine linkVsuS2A (n := pos.shift - 9) (w0 := lslot) (v := ew) hapV hapE hfr J2 hks2 hfa hsub hO F2 hPC hnt + (fun h => hS2 (Or.inl h)) hpal hinv hzfr hwF ((hapE _ hwF).1) ?_ ?_ hvf hroot hwalk ?_ hW.1 ?_ ?_ hdTab ?_ + · -- no Stage-1 footprint word is the written word + intro b hb heq + subst heq + cases hb with + | asid hi' hh => + exact hT q j hj (Or.inl hqS) (hqe ▸ atAF_asWA hh) + | pool q' lo hq' hl => + exact extFoot_ne_vsA J2.1.ext J2.1.vs.yal (Or.inl hq') (J2.1.vs.pal q' hq') + hl hwF rfl + | pt t' j' ht' hj' => + exact extFoot_ne_vsA J2.1.ext J2.1.vs.yal (Or.inr (Or.inl ht')) (J2.1.vs.al t' ht') hj' hwF rfl + | high y' j' hy' hj' => + exact extFoot_ne_vsA J2.1.ext 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' hwF rfl + · intro j' hj' heq + have := (peAF_injA_s hpal hq4 hj' hj (heq.trans hqe)).1 + exact hS2 (this ▸ hqS) + · -- no unmapped page-table cap names `ptr` after the cap write (`ptOnce`) + intro y hy a' v' hc + have hsl' : IsSlotA Z.th sl := hab + have := J2.1.vsu.ptOnce y hy ptr ⟨a', v', hc⟩ sl hsl' ⟨true, asid1, baseU, F2.1⟩ + subst this + rw [F2.1] at hc + cases hc + · intro w hw hne + rw [hW.2.2 w hw, if_neg (Ne.symm hne)] + · rw [hW.2.2 _ hbal, if_pos rfl] + · refine ⟨rfl, fun q' hq' => ?_⟩ + rcases hsl with ⟨t, i, ⟨ht, -⟩, hi, hluEq, hslEq⟩ | ⟨r0, j0, hr0, hj0, hluEq, hslEq, -⟩ + · rw [hslEq] + refine kheap_writeX ?_ + rw [slotObjPtE (Nat.mod_eq_zero_of_dvd (J2.1.ext.tal t ht)) hi] + intro e + have := specPtr_inj e + subst this + obtain ⟨_, h1, -⟩ := J2.1.vs.pool q' hq' + obtain ⟨_, h2, -⟩ := J2.1.ext.s2pt q' ht + rw [h1] at h2; cases h2 + · rw [hslEq] + refine kheap_writeX ?_ + intro e + have e' : specPtr q' = specPtr r0 := e + have := specPtr_inj e' + subst this + obtain ⟨_, h1, -⟩ := J2.1.vs.pool q' hq' + obtain ⟨_, h2, -⟩ := J2.1.ext.s2root q' hr0 + rw [h1] at h2; cases h2 + +end arm + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsS2MapVsuA.lean b/proofs/Fl4ProofsA64/P3/VsS2MapVsuA.lean new file mode 100644 index 000000000..9faf7bfb8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsS2MapVsuA.lean @@ -0,0 +1,146 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, G): **`VsUniqA` after a Stage-2 `ARMPageTableMap`** (`linkVsuS2A`): +`VsUniqA.of_linkS2` at the descriptor write after the cap write, with the arm's facts, plus the ASID-specific root fact of +`vspace_for_asid` (`s2RootOfAsidA_of_vspaceForAsid`). The uniqueness of the unmapped cap (`hOutU`) is an input. No +premise. New module. +-/ +import Fl4ProofsA64.P3.VsUniqLinkS2A +import Fl4ProofsA64.P3.VsFindA +import Fl4ProofsA64.P3.VsPtMapVsuA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section s2root +variable {Pp Tb : Set U64} {Lv : U64 → Nat} {X Y : Set U64} {σ : Fl4SpecA64.State Unit} + +theorem s2RootOfAsidA_of_vspaceForAsid {mem : U64 → U64} {ksb : U64} + (hR : VsRelA Pp Tb Lv X Y mem ksb σ) {asid : U64} {r : U64} (hr : r ∈ X) + (hv : Fl4SpecA64.vspaceForAsid (asidOfA asid) σ = some (specPtr r)) : + S2RootOfAsidA Pp X σ asid r := by + generalize ha : asidOfA asid = a at hv + have haEq0 : a = BitVec.ofNat 16 asid.val := ha.symm + have ha0 : 0 < a := by + by_contra hle + unfold Fl4SpecA64.vspaceForAsid Fl4Spec.Lookup.oassert at hv + rw [ite_eq_right_iff.mpr (fun h => absurd h hle)] at hv; cases hv + rw [vspaceForAsid_posA ha0] at hv + unfold specVsA at hv + cases htab : σ.archState.armAsidTable (Fl4SpecA64.asidHighBitsOf a) with + | none => simp [htab] at hv + | some pref => + cases hpo : Fl4SpecA64.asidPoolsOf σ pref with + | none => simp [htab, hpo] at hv + | some f => + cases hfe : f (Fl4SpecA64.asidLowBitsOf a) with + | none => simp [htab, hpo, hfe] at hv + | some ent => + simp only [htab, hpo, hfe, Option.bind, Option.some.injEq] at hv + have ha16 : a.toNat < 65536 := by + have := a.isLt; simpa [Fl4SpecA64.asidRepLen, Fl4SpecA64.asidLen] using this + have haEq : BitVec.ofNat 16 a.toNat = a := by + apply BitVec.eq_of_toNat_eq + rw [BitVec.toNat_ofNat, Nat.mod_eq_of_lt ha16] + let hi : U64 := ⟨BitVec.ofNat 64 (a.toNat / 512)⟩ + have hiv : hi.val = a.toNat / 512 := by + show (BitVec.ofNat 64 (a.toNat / 512)).toNat = _; rw [BitVec.toNat_ofNat] + exact Nat.mod_eq_of_lt (by simp only [Nat.reducePow]; omega) + have hhi : hi.val < 128 := by omega + have htabR := hR.table hi hhi + rw [hiv, ← asidHi_eqA ha16, haEq, htab] at htabR + have hpne : mem (atAF ksb hi) ≠ 0#u64 := by + intro hz; rw [hz, optPtrA_zero] at htabR; cases htabR + rw [optPtrA_ne hpne] at htabR + have hpref : pref = specPtr (mem (atAF ksb hi)) := Option.some.inj htabR + subst hpref + have hP : mem (atAF ksb hi) ∈ Pp := hR.tmem hi hhi hpne + obtain ⟨f0, hkh0, -⟩ := hR.pool _ hP + rw [asidPoolsOf_eqA hkh0] at hpo + obtain rfl := Option.some.inj hpo + cases ent with + | asidPoolVSpace v => + change v = specPtr r at hv + subst hv + subst haEq0 + exact ⟨hr, _, f0, ha0, hP, htab, hkh0, hfe⟩ + + +end s2root + +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {A : Type} {AR : A → HwRootA → Prop} {Z : XSetsA} {OS : Set U64} {s s2 s3 : S} {a : A} + {σ σ2 σ3 : Fl4SpecA64.State Unit} {m : Fl4SpecA64.McState} + +theorem linkVsuS2A {tcbs : Set U64} {n : Nat} + (hapV : ∀ b, VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b → ¬ InOS OS b ∧ ∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) + (hapE : ∀ b, ExtFootE Z.X Z.Y Z.T2 b → ¬ InOS OS b ∧ ∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) + (hfr : ∀ b, Aligned b → ¬ InOS OS b → (∀ t ∈ tcbs, b.val < t.val ∨ t.val + 4096 ≤ b.val) → L.mem s2 b = L.mem s b) + (J2 : JAtZAX (L := L) AR Z s2 a σ2 m) (hks2 : L.ksb s2 = L.ksb s) + (hfa : ∀ w, FootA (L := L) Z s2 w → Aligned w) + (hsub : ∀ y, IsSlotA Z.th y → y ∈ OS) {Ω T Sg : Set U64} (hO : OSOK T Ω Sg OS) + {sl : U64} {ptr asid1 base : U64} + (F2 : SlotFrA (L := L) OS sl (.PageTable ptr true asid1 base) s s2) + (hPC : PtCapInA Z (L.mem s)) (hnt : ptr ∉ Z.S1) (hnt2 : ptr ∉ Z.T2) (hpal : ptr.val % 4096 = 0) + (hinv : ∀ i : U64, i.val < 512 → dBitA (L.mem s (peAF ptr i)) 0 = false) + (hzfr : ∀ i : U64, i.val < 512 → L.mem s2 (peAF ptr i) = L.mem s (peAF ptr i)) + {w0 : U64} (hw0F : ExtFootE Z.X Z.Y Z.T2 w0) (hbOS : ¬ InOS OS w0) + (hwV : ∀ b, VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b → b ≠ w0) + (hwptr : ∀ j : U64, j.val < 512 → peAF ptr j ≠ w0) + (hold : dBitA (L.mem s w0) 0 = false) + {r : U64} (hroot : S2RootOfAsidA Z.Pp Z.X σ2 asid1 r) + (hwalk : WalkSlotA (· ∈ Z.T2) (L.mem s) base r Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) w0) + (hOutU : ∀ y, IsSlotA Z.th y → ∀ a' v' : U64, capAtA (L.mem s2) y = .PageTable ptr false a' v' → False) + {v : U64} (hks3 : L.ksb s3 = L.ksb s2) + (hm3 : ∀ w, Aligned w → w ≠ w0 → L.mem s3 w = L.mem s2 w) + (hv : L.mem s3 w0 = v) (hdv : dTabA v = ptr) + (hP : PoolKeepA Z.Pp σ2 σ3) : + VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y (insert ptr Z.T2) (Function.update Z.Sh2 ptr n) (L.mem s3) (L.ksb s3) σ3 := by + have hmemE : ∀ b, ExtFootE Z.X Z.Y Z.T2 b → L.mem s2 b = L.mem s b := fun b hb => + hfr b (hfa b (.nslot b (.ext b hb))) (hapE b hb).1 (hapE b hb).2 + have hOSK : OSKeep st OS s2 s3 := osKeep_tabWriteA hO hbOS hm3 + have hbal : Aligned w0 := hfa w0 (.nslot w0 (.ext w0 hw0F)) + have hold2 : (L.mem s2 w0 &&& 3#u64) ≠ 3#u64 := by + rw [hmemE w0 hw0F] + intro h + have := ((and3_bits_sh _).1 h).1 + rw [hold] at this; cases this + rw [hks3] + refine J2.1.vsu.of_linkS2 J2.1.ext (asid := asid1) (va := base) (n := n) ?_ hnt + (fun b hb hne => hm3 b (hfa b (.nslot b (.ext b hb))) hne) ?_ hP hold2 (by rw [hv]; exact hdv) ?_ ?_ ?_ ?_ ?_ + · exact hnt2 + · intro b hb + have hb' : VsFootA Z.Pp Z.S1 Z.Y (L.ksb s) b := by rw [← hks2]; exact hb + exact hm3 b (hfa b (.nslot b (.vs b hb))) (hwV b hb') + · intro j hj h + rw [hm3 _ (peAF_alignedA hpal hj) (hwptr j hj), hzfr j hj] at h + have := ((and3_bits_sh _).1 h).1 + rw [hinv j hj] at this; cases this + · obtain ⟨hr, p, f, ha0, hp, htab, hkh, hf⟩ := hroot + refine ⟨r, ⟨hr, p, f, ha0, hp, htab, hkh, hf⟩, ?_⟩ + refine hwalk.of_mem' ?_ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨ht', rfl⟩) + · exact hmemE _ (rootFootE hr (J2.1.ext.xal _ hr) + (Nat.lt_of_lt_of_le (walkIdx_lt base sh' _ (Nat.succ_pos _) (Nat.le_trans s2Top1k (by norm_num))) s2Top1k)) + · exact hmemE _ (.s2pt t' _ ht' (walkIdx_lt base sh' 512 (by norm_num) (by norm_num))) + · intro y hy + rw [capAtA_eq, capAtA_eq] + exact hOSK.capA (hsub y hy) + · intro y hy a' v' hc + by_cases e : y = sl + · subst e + rw [F2.1] at hc + cases hc; exact ⟨rfl, rfl⟩ + · rw [(F2.2 y (hsub y hy)).1 e] at hc + rcases hPC y hy ptr a' v' hc with h | h + · exact absurd h.1 hnt + · exact absurd h hnt2 + · exact hOutU + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsTabJA.lean b/proofs/Fl4ProofsA64/P3/VsTabJA.lean index 688e3a5ec..0f24daa8c 100644 --- a/proofs/Fl4ProofsA64/P3/VsTabJA.lean +++ b/proofs/Fl4ProofsA64/P3/VsTabJA.lean @@ -56,6 +56,7 @@ Decode-site hypothesis: `TabOffA` (gen 21). No named premise. -/ import Fl4ProofsA64.P3.FrontEndExtraA import Fl4ProofsA64.P3.VsUnmapA +import Fl4ProofsA64.P3.VsUniqShrinkA open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P3 @@ -184,7 +185,8 @@ theorem JAtZAX.of_sameVsA (J : JAtZAX (L := L) AR Z s a σ m) {P0 : Set U64} (hy : ∀ p l1, σ'.kheap p = some (.archObj (.ext (.highVSpace l1))) → ∃ r ∈ Z.Y, specPtr r = p) {S1' : Set U64} {Lv' : U64 → Nat} (hroot : ∀ q ∈ Z.S1, Z.Lv q = 0 → q ∈ S1' ∧ Lv' q = 0) (VR : VsRelA Z.Pp S1' Lv' Z.X Z.Y (L.mem s') (L.ksb s') σ') - (ER : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') σ') : + (ER : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') σ') + (VU : VsUniqA Z.th Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ') : JAtZAX (L := L) AR { Z with S1 := S1', Lv := Lv' } s' a σ' m := by obtain ⟨J, V, X0, Y0⟩ := J have hT : TcbKeepA Z.T σ σ' := TcbKeepA.of_eq ht @@ -218,7 +220,8 @@ theorem JAtZAX.of_sameVsA (J : JAtZAX (L := L) AR Z s a σ m) {P0 : Set U64} obtain ⟨hq, hl⟩ := J.pml y hy q mp asid e exact hroot q hq hl vs := VR - ext := ER } + ext := ER + vsu := VU } refine ⟨J', ?_, ?_, ?_⟩ · 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 [← H.cap (Or.inl hy)]; exact e)⟩ @@ -250,7 +253,8 @@ theorem JAtZAX.of_sameXA (J : JAtZAX (L := L) AR Z s a σ m) (H : SameA (L := L) (hy : ∀ p l1, σ'.kheap p = some (.archObj (.ext (.highVSpace l1))) → ∃ r ∈ Z.Y, specPtr r = p) {S1' : Set U64} {Lv' : U64 → Nat} (hroot : ∀ q ∈ Z.S1, Z.Lv q = 0 → q ∈ S1' ∧ Lv' q = 0) (VR : VsRelA Z.Pp S1' Lv' Z.X Z.Y (L.mem s') (L.ksb s') σ') - (ER : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') σ') : + (ER : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') σ') + (VU : VsUniqA Z.th Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ') : JAtZAX (L := L) AR { Z with S1 := S1', Lv := Lv' } s' a σ' m := J.of_sameVsA (P0 := Z.Pp) H HG (fun p _ h => hkh _ (Or.inl ⟨p, by rw [h]; exact Option.some_ne_none _, rfl⟩)) @@ -258,7 +262,7 @@ theorem JAtZAX.of_sameXA (J : JAtZAX (L := L) AR Z s a σ m) (H : SameA (L := L) (fun t h => hkh _ (Or.inr (Or.inl ⟨t, h, rfl⟩))) (fun c h => hkh _ (Or.inr (Or.inr (Or.inl ⟨c, h, rfl⟩)))) (fun v h => hkh _ (Or.inr (Or.inr (Or.inr (Or.inl ⟨v, h, rfl⟩))))) - hcdt horig hv hx hy hroot VR ER + hcdt horig hv hx hy hroot VR ER VU /-- (gen 24) **`JAtZAX` across a change that keeps the non-Stage-1 footprint and related objects** (`SameA` / `SpecSameA` at `{Z with S1 := ∅}`), at new Stage-1 ghosts given `VsRelA` and `ExtVsRelA` there: the core of @@ -268,12 +272,61 @@ theorem JAtZAX.of_sameS1A (J : JAtZAX (L := L) AR Z s a σ m) (H : SameA (L := L (HS : SpecSameA { Z with S1 := ∅ } m σ σ') {S1' : Set U64} {Lv' : U64 → Nat} (hroot : ∀ q ∈ Z.S1, Z.Lv q = 0 → q ∈ S1' ∧ Lv' q = 0) (VR : VsRelA Z.Pp S1' Lv' Z.X Z.Y (L.mem s') (L.ksb s') σ') - (ER : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') σ') : + (ER : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') σ') + (VU : VsUniqA Z.th Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ') : JAtZAX (L := L) AR { Z with S1 := S1', Lv := Lv' } s' a σ' m := J.of_sameXA ⟨H.ksb, H.cpu, fun w hw => H.mem w hw.extMonoA⟩ HS.toSpecGlobA (fun p hp => HS.kh p hp.extMonoA) HS.cdt HS.orig (fun p x e => HS.ext p _ e (Or.inl ⟨x, rfl⟩)) (fun p es e => J.2.2.1.back p es (HS.ext p _ e (Or.inr (Or.inl ⟨es, rfl⟩)))) - (fun p l1 e => J.2.2.2.back p l1 (HS.ext p _ e (Or.inr (Or.inr ⟨l1, rfl⟩)))) hroot VR ER + (fun p l1 e => J.2.2.2.back p l1 (HS.ext p _ e (Or.inr (Or.inr ⟨l1, rfl⟩)))) hroot VR ER VU + +/-! ## `VsUniqA` across the removal of table descriptors -/ + +theorem S2WordA.foot {X Y T2 : Set U64} {Sh2 : U64 → Nat} {b : U64} (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (h : S2WordA X T2 Sh2 b) : ExtFootE X Y T2 b := by + rcases h with ⟨r, i, hr, hi, rfl⟩ | ⟨t, i, ht, -, hi, rfl⟩ + · exact rootFootE hr (hxal r hr) (by have := s2Top1k; omega) + · exact .s2pt t i ht hi + +/-- A write of zero to an aligned address leaves every aligned word equal or not a table descriptor. -/ +theorem wrZero_shrinkA {s : S} {a b : U64} (ha : Aligned a) (hb : Aligned b) : + L.mem (L.wr s a 0#u64) b = L.mem s b ∨ NotTabA (L.mem (L.wr s a 0#u64) b) := by + rw [L.mem_wr _ _ _ _ ha hb] + by_cases e : a = b + · rw [if_pos e]; right; decide + · rw [if_neg e]; left; rfl + +/-- (Stage 5) **`VsUniqA` across a step that only removes table descriptors** (`VsUniqA.of_shrink`), in `JAtZAX` terms. -/ +theorem JAtZAX.vsuShrinkA (J : JAtZAX (L := L) AR Z s a σ m) {s' : S} {σ' : Fl4SpecA64.State Unit} + (hks : L.ksb s' = L.ksb s) + (hmE : ∀ b, S2EntryA Z.Pp Z.X Z.T2 Z.Sh2 (L.mem s') σ' b → L.mem s' b = L.mem s b ∨ NotTabA (L.mem s' b)) + (hmV : ∀ b, S1EntryA Z.Pp Z.S1 Z.Y (L.mem s') (L.ksb s) b → L.mem s' b = L.mem s b ∨ NotTabA (L.mem s' b)) + (hA : ∀ b, AsidWordsA Z.Pp (L.ksb s) b → L.mem s' b = L.mem s b) (hP : PoolKeepA Z.Pp σ σ') + (hc : PtClosedA Z.th Z.S1 Z.T2 (L.mem s) (L.mem s')) : + VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ' := by + rw [hks]; exact J.1.vsu.of_shrink J.1.ext J.1.vs hmE hmV hA hP hc + +/-- The ASID-table and pool words are in the footprint off the Stage-1 tables. -/ +theorem AsidWordsA.foot {Z : XSetsA} {s : S} {b : U64} (h : AsidWordsA Z.Pp (L.ksb s) b) : + FootA (L := L) { Z with S1 := ∅ } s b := by + rcases h with ⟨hi, hh, rfl⟩ | ⟨p, lo, hp, hl, rfl⟩ + · exact .nslot _ (.vs _ (.asid hi hh)) + · exact .nslot _ (.vs _ (.pool p lo hp hl)) + +/-- **`VsUniqA` across a change of Stage-1 table words (the footprint off them kept) that removes descriptors.** -/ +theorem JAtZAX.vsuShrinkS1A (J : JAtZAX (L := L) AR Z s a σ m) {s' : S} {σ' : Fl4SpecA64.State Unit} + (H : SameA (L := L) { Z with S1 := ∅ } s s') (HS : SpecSameA { Z with S1 := ∅ } m σ σ') + (hS1 : ∀ q ∈ Z.S1, ∀ i : U64, i.val < 512 → + L.mem s' (peAF q i) = L.mem s (peAF q i) ∨ NotTabA (L.mem s' (peAF q i))) : + VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ' := + J.vsuShrinkA H.ksb (fun b hb => Or.inl (H.mem b (.nslot b (.ext b (hb.word.foot J.1.ext.xal))))) + (fun b hbE => by + obtain ⟨tag, sh, t, i, -, ht, -, hi, hb⟩ := hbE + subst hb + rcases ht with ht | ⟨y, hy, rfl⟩ + · exact hS1 t ht i hi + · exact Or.inl (H.mem _ (.nslot _ (.vs _ (.high y i hy hi))))) + (fun b hb => H.mem b hb.foot) HS.pool (PtClosedA.of_cap fun y hy => Or.inl (H.cap (Or.inl hy))) /-- **`JAtZAX` across a write of one word of a table off the non-Stage-1 footprint** (module docstring). -/ theorem JAtZAX.of_tabWriteA (J : JAtZAX (L := L) AR Z s a σ m) {p i : U64} (T : TabOffA (L := L) Z m s p) @@ -285,7 +338,8 @@ theorem JAtZAX.of_tabWriteA (J : JAtZAX (L := L) AR Z s a σ m) {p i : U64} (T : (hpx : ∀ ko, σ'.kheap (specPtr p) = some ko → ¬ ExtObjA ko) {S1' : Set U64} {Lv' : U64 → Nat} (hroot : ∀ q ∈ Z.S1, Z.Lv q = 0 → q ∈ S1' ∧ Lv' q = 0) (VR : VsRelA Z.Pp S1' Lv' Z.X Z.Y (L.mem s') (L.ksb s') σ') - (ER : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') σ') : + (ER : ExtVsRelA Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') σ') + (VU : VsUniqA Z.th Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ') : JAtZAX (L := L) AR { Z with S1 := S1', Lv := Lv' } s' a σ' m := by have H : SameA (L := L) { Z with S1 := ∅ } s s' := ⟨hks, hcpu, fun w hw => hm w (hfa w hw) fun e => T.mem i hi (e ▸ hw)⟩ @@ -298,7 +352,7 @@ theorem JAtZAX.of_tabWriteA (J : JAtZAX (L := L) AR Z s a σ m) {p i : U64} (T : · rwa [hk q hq] at e cdt := hcdt orig := horig } - exact J.of_sameS1A H HS hroot VR ER + exact J.of_sameS1A H HS hroot VR ER VU /-! ## Small frames (gen 22) -/ @@ -393,6 +447,18 @@ theorem storePte_eqA {Pp Tb : Set U64} {Lv : U64 → Nat} {X Y : Set U64} {mem : simp only [Set.singleton_eq_singleton_iff, Prod.mk.injEq, true_and] at e exact ⟨_, e.symm⟩ +/-- `store_pte`'s outcome at a related table is `ptSetA`, with the new entry. -/ +theorem storePte_eq2A {Pp Tb : Set U64} {Lv : U64 → Nat} {X Y : Set U64} {mem : U64 → U64} {ksb : U64} + {σ σ' : Fl4SpecA64.State Unit} (R : VsRelA Pp Tb Lv X Y mem ksb σ) {p i : U64} (hp : p ∈ Tb) (hi : i.val < 512) + {pte : Fl4SpecA64.PTE} + (h : Fl4SpecA64.storePte (Z := Unit) (ptTyA (Lv p)) (specPtr (peAF p i)) pte σ = ({((), σ')}, False)) : + ∃ t', σ' = ptSetA σ (specPtr p) t' ∧ Fl4SpecA64.ptApply t' i.bv = pte := by + obtain ⟨t, hk, ht, -⟩ := R.pt p hp + rw [storePte_runA hk ht (R.al_mod hp) hi pte] at h + have e := congrArg Prod.fst h + simp only [Set.singleton_eq_singleton_iff, Prod.mk.injEq, true_and] at e + exact ⟨_, e.symm, by rw [ptApply_updA t hi hi, if_pos rfl]⟩ + /-! ## The slot frame of a map (gen 30) -/ /-- (gen 30, ruling 01:13Z item 1) **The slot frame of a map**: the invoked slot `sl` holds `c`, and every `OS` slot @@ -464,7 +530,9 @@ set_option maxHeartbeats 2000000 in theorem restart_setcapJA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) - {c : capability.Cap} {sc : Fl4SpecA64.Cap} (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) : + {c : capability.Cap} {sc : Fl4SpecA64.Cap} (hEnc : CapRt.EncWf c) (hca : CapRelA c sc) + (hrt : RootSetA (capAtA (L.mem s) (cslotAddrA cte)) c := by root_nr) + (hpt : PtSetE Z.th (L.mem s) (cslotAddrA cte) c := by pt_nr) : ∃ x s2 σ2, σ.kheap σ.curThread = some (.tcb x) ∧ sched.set_thread_state st s (L.curW s) sched.TS_RESTART = ok (L.wr s (stA (L.curW s)) sched.TS_RESTART) ∧ Fl4SpecA64.setThreadState (Z := Unit) σ.curThread .restart σ = @@ -476,6 +544,7 @@ theorem restart_setcapJA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a WritesIn st (L.wr s (stA (L.curW s)) sched.TS_RESTART) s2 (W7.CapW H.tcbs {b | InOS OS b} ∅) ∧ (TreeA st OS Z.G.chains Z.G.par s → (∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) → c ≠ .Null → capA st s (cslotAddrA cte) ≠ .Null → UA c (capA st s (cslotAddrA cte)) → CapObjOkA Z c → + PtSrcA Z.th Z.S1 Z.T2 (L.mem s) c → JAtZAX (L := L) AR Z s2 a σ2 m ∧ TreeA st OS Z.G.chains Z.G.par s2) ∧ SlotFrA (L := L) OS (cslotAddrA cte) c s s2 := by obtain ⟨⟨Rp, Nt, extra, sp, P⟩, Y, hrun, hcur, hvs, hvc, hsub⟩ := RS @@ -520,7 +589,7 @@ theorem restart_setcapJA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a refine ⟨x, s2, _, hkx, hst, hset, by rw [← hs2]; exact set_cap_eq hen, hσ2, HS, hksb, ((E1.j.1.vs).of_writesIn hw2 hW2 ((E1.j.1.vs).foot_alignedA E1.vsLeafA.1)).of_specSlot HS HS.asid, hw2.2.1.trans hcpu1, hw2, ?_, hFr⟩ - intro hT hnul hcn hc0 hua hok + intro hT hnul hcn hc0 hua hok hptc have hP1 := E1.j.1.place have hcs : IsSlotA Z.th (cslotAddrA cte) := hab.isSlot hP1 have hc1 : capA st s1 (cslotAddrA cte) = capA st s (cslotAddrA cte) := hOK.capA hos @@ -534,7 +603,11 @@ theorem restart_setcapJA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a (fun sl hsl => by rw [← hs2, revA_wr2A hO hos (hsub _ (hsl.isSlot hP1))]; exact C1.orig sl hsl) C1.par_slot C1.po refine ⟨E1.j.of_slotWrites hw2 (fun b hb hf => footN_offA E1 b hf hb) - (FootNA.aligned E1.j.1 (bxi_nodes E1.sys.ent.bxi) E1.scAl E1.ap.vcAl) Z.G HS hSR hC fun y hy => ?_, hT2⟩ + (FootNA.aligned E1.j.1 (bxi_nodes E1.sys.ent.bxi) E1.scAl E1.ap.vcAl) Z.G HS hSR hC (fun y hy => ?_) + (PtClosedA.of_set (x := cslotAddrA cte) + (hptc.congr fun y hy => by rw [capAtA_eq, capAtA_eq, hOK.capA (hsub y hy)]) hcx hcapo + (by have h0 := hrt; rw [capAtA_eq] at h0 ⊢; rwa [hOK.capA hos]) + (PtSetE.congr (fun y hy => by rw [capAtA_eq, capAtA_eq, hOK.capA (hsub y hy)]) (AbsSlotA.isSlot E1.j.1.place hab) hpt)), hT2⟩ by_cases hne : y = cslotAddrA cte · subst hne; rw [hcx]; exact hok · rw [hcapo y hy hne]; exact E1.j.capObj hy @@ -549,7 +622,8 @@ theorem JAtZAX.of_pteWriteA (J : JAtZAX (L := L) AR Z s a σ m) {p i : U64} (hp {t' : Fl4SpecA64.PT} (hms : MsA (ptSetA σ (specPtr p) t') σ') {S1' : Set U64} {Lv' : U64 → Nat} (hT : ∀ q ∈ S1', q ∈ Z.S1 ∨ (q ∉ S2PgE Z.X Z.T2 ∧ q ∉ Z.Y)) (hroot : ∀ q ∈ Z.S1, Z.Lv q = 0 → q ∈ S1' ∧ Lv' q = 0) - (VR : VsRelA Z.Pp S1' Lv' Z.X Z.Y (L.mem s') (L.ksb s') σ') : + (VR : VsRelA Z.Pp S1' Lv' Z.X Z.Y (L.mem s') (L.ksb s') σ') + (VU : VsUniqA Z.th Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') σ') : JAtZAX (L := L) AR { Z with S1 := S1', Lv := Lv' } s' a σ' m := by obtain ⟨ms, rfl⟩ := hms have hk : ∀ q, q ≠ specPtr p → @@ -563,13 +637,56 @@ theorem JAtZAX.of_pteWriteA (J : JAtZAX (L := L) AR Z s a σ m) {p i : U64} (hp 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 (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) + fun e => T.mem i hi (e ▸ .nslot b (.ext b hb))) hpS hpP rfl hk hT) VU intro ko e hx have e' : (ptSetA σ (specPtr p) t').kheap (specPtr p) = some ko := e rw [ptSetA_kheap, if_pos rfl] at e' cases e' rcases hx with ⟨_, h⟩ | ⟨_, h⟩ | ⟨_, h⟩ <;> cases h +/-- (Stage 5) **A non-table descriptor written into a Stage-1 table** (a frame map): the ghosts are kept and +`VsUniqA` follows from `VsUniqA.of_shrink` (the new entry is not a table descriptor by the new relation). -/ +theorem JAtZAX.of_pteWriteLeafA (J : JAtZAX (L := L) AR Z s a σ m) {p i : U64} (hp : p ∈ Z.S1) + (T : TabOffA (L := L) Z m s p) (hi : i.val < 512) (hfa : ∀ w, FootA (L := L) Z s w → Aligned w) + (hks : L.ksb s' = L.ksb s) (hcpu : L.cpu s' = L.cpu s) + (hm : ∀ w, Aligned w → w ≠ peAF p i → L.mem s' w = L.mem s w) + {t' : Fl4SpecA64.PT} (hms : MsA (ptSetA σ (specPtr p) t') σ') + (VR : VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s') (L.ksb s') σ') + (hnt : ∀ ppn, Fl4SpecA64.ptApply t' i.bv ≠ .pageTablePTE ppn) : + JAtZAX (L := L) AR Z s' a σ' m := by + obtain ⟨ms, hσ'⟩ := hms + subst hσ' + have hpP : p ∉ Z.Pp := fun h => by + obtain ⟨_, h1, -⟩ := J.1.vs.pool p h + obtain ⟨_, h2, -⟩ := J.1.vs.pt p hp + rw [h1] at h2; cases h2 + have hk : ∀ q, q ≠ specPtr p → + ({ ptSetA σ (specPtr p) t' with machineState := ms } : Fl4SpecA64.State Unit).kheap q = σ.kheap q := + fun q hq => by show (ptSetA σ (specPtr p) t').kheap q = _; rw [ptSetA_kheap, if_neg hq] + have hkp : ({ ptSetA σ (specPtr p) t' with machineState := ms } : Fl4SpecA64.State Unit).kheap (specPtr p) = + some (.archObj (.pageTable t')) := by + show (ptSetA σ (specPtr p) t').kheap (specPtr p) = _; rw [ptSetA_kheap, if_pos rfl] + have H : SameA (L := L) { Z with S1 := ∅ } s s' := + ⟨hks, hcpu, fun w hw => hm w (hfa w (FootA.s1_monoA hw)) fun e => T.mem i hi (e ▸ hw)⟩ + have VR2 : VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s') (L.ksb s) { ptSetA σ (specPtr p) t' with machineState := ms } := by + rw [← hks]; exact VR + have VU : VsUniqA Z.th Z.Pp Z.S1 Z.X Z.Y Z.T2 Z.Sh2 (L.mem s') (L.ksb s') + { ptSetA σ (specPtr p) t' with machineState := ms } := by + rw [hks] + refine J.1.vsu.of_shrink J.1.ext J.1.vs ?_ ?_ (fun b hb => H.mem b hb.foot) + ⟨rfl, fun q hq => hk _ (fun e => hpP (specPtr_inj e ▸ hq))⟩ + (PtClosedA.of_cap fun y hy => Or.inl (H.cap (Or.inl hy))) + · intro b hb + exact Or.inl (H.mem b (.nslot b (.ext b (hb.word.foot J.1.ext.xal)))) + · intro b hb + by_cases hbe : b = peAF p i + · exact Or.inr (hb.notTab_of_rel VR2 hbe hp hi hkp hnt) + · obtain ⟨tag, sh, t, j, -, ht, -, hj, hbt⟩ := hb + subst hbt + exact Or.inl (hm _ (peAF_alignedA (S1TabA.mod4k J.1.vs ht) hj) hbe) + exact (J.of_pteWriteA hp T hi hfa hks hcpu hm ⟨ms, rfl⟩ (S1' := Z.S1) (Lv' := Z.Lv) (fun q hq => Or.inl hq) + (fun q hq hl => ⟨hq, hl⟩) VR VU) + /-- **The lift's obligation** (module docstring): under the call-site MDB tree at `OS`, the null non-relation slots, every Stage-1 table off the non-Stage-1 footprint and the extra condition `hc`, `JAtZAX` at the ghosts `Z'` and the tree hold at the outcome (gen 23: and its `ksb` / `cpu` are the entry's, so `TabOffA` carries over, `TabOffA.liftA`; @@ -592,13 +709,35 @@ theorem map_finJA (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) {s {S1' : Set U64} {Lv' : U64 → Nat} (hT : ∀ q ∈ S1', q ∈ Z.S1 ∨ (q ∉ S2PgE Z.X Z.T2 ∧ q ∉ Z.Y)) (hroot : ∀ q ∈ Z.S1, Z.Lv q = 0 → q ∈ S1' ∧ Lv' q = 0) (VR : VsRelA Z.Pp S1' Lv' Z.X Z.Y (L.mem s3) (L.ksb s3) σ3) + (VU : VsUniqA Z.th Z.Pp S1' Z.X Z.Y Z.T2 Z.Sh2 (L.mem s3) (L.ksb s3) σ3) {sl : U64} {c : capability.Cap} (F2 : SlotFrA (L := L) OS sl c s s2) (hsl : sl ∈ OS) : JAtZAX (L := L) AR { Z with S1 := S1', Lv := Lv' } s3 a σ3 m ∧ TreeA st OS Z.G.chains Z.G.par s3 ∧ L.ksb s3 = L.ksb s ∧ L.cpu s3 = L.cpu s ∧ SlotFrA (L := L) OS sl c s s3 := by have hN : ∀ c ∈ Z.Cs, ∀ o : U64, o.val < 4288 → o.val % 8 = 0 → Aligned (L.nodeAt s2 c o) := fun c hc o h1 h2 => by rw [nodeAt_ksb hks2]; exact bxi_nodes E.sys.ent.bxi c hc o h1 h2 have hK := osKeep_tabWriteA E.sys.ent.os (E.ap.vs _ (.pt p i hp hi)).1 hm - exact ⟨J2.of_pteWriteA hp (T.of_ksA hks2 hcpu2) hi (FootA.aligned J2.1 hN E.scAl E.ap.vcAl) hks hcpu hm hms hT hroot VR, + exact ⟨J2.of_pteWriteA hp (T.of_ksA hks2 hcpu2) hi (FootA.aligned J2.1 hN E.scAl E.ap.vcAl) hks hcpu hm hms hT hroot VR VU, + hT2.keepO hK, hks.trans hks2, hcpu.trans hcpu2, F2.keepR hsl hK⟩ + +/-- (Stage 5) **`map_finJA` for a non-table descriptor** (a frame map): the ghosts are kept, `VsUniqA` follows from the +new relation (`JAtZAX.of_pteWriteLeafA`). -/ +theorem map_finJA_leaf (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) {s2 s3 : S} + {σ2 σ3 : Fl4SpecA64.State Unit} + (J2 : JAtZAX (L := L) AR Z s2 a σ2 m) (hT2 : TreeA st OS Z.G.chains Z.G.par s2) + (hks2 : L.ksb s2 = L.ksb s) (hcpu2 : L.cpu s2 = L.cpu s) + {p i : U64} (hp : p ∈ Z.S1) (T : TabOffA (L := L) Z m s p) (hi : i.val < 512) + (hks : L.ksb s3 = L.ksb s2) (hcpu : L.cpu s3 = L.cpu s2) + (hm : ∀ w, Aligned w → w ≠ peAF p i → L.mem s3 w = L.mem s2 w) + {t' : Fl4SpecA64.PT} (hms : MsA (ptSetA σ2 (specPtr p) t') σ3) + (VR : VsRelA Z.Pp Z.S1 Z.Lv Z.X Z.Y (L.mem s3) (L.ksb s3) σ3) + (hnt : ∀ ppn, Fl4SpecA64.ptApply t' i.bv ≠ .pageTablePTE ppn) + {sl : U64} {c : capability.Cap} (F2 : SlotFrA (L := L) OS sl c s s2) (hsl : sl ∈ OS) : + JAtZAX (L := L) AR Z s3 a σ3 m ∧ TreeA st OS Z.G.chains Z.G.par s3 ∧ + L.ksb s3 = L.ksb s ∧ L.cpu s3 = L.cpu s ∧ SlotFrA (L := L) OS sl c s s3 := by + have hN : ∀ c ∈ Z.Cs, ∀ o : U64, o.val < 4288 → o.val % 8 = 0 → Aligned (L.nodeAt s2 c o) := + fun c hc o h1 h2 => by rw [nodeAt_ksb hks2]; exact bxi_nodes E.sys.ent.bxi c hc o h1 h2 + have hK := osKeep_tabWriteA E.sys.ent.os (E.ap.vs _ (.pt p i hp hi)).1 hm + exact ⟨J2.of_pteWriteLeafA hp (T.of_ksA hks2 hcpu2) hi (FootA.aligned J2.1 hN E.scAl E.ap.vcAl) hks hcpu hm hms VR hnt, hT2.keepO hK, hks.trans hks2, hcpu.trans hcpu2, F2.keepR hsl hK⟩ end diff --git a/proofs/Fl4ProofsA64/P3/VsTopFrA.lean b/proofs/Fl4ProofsA64/P3/VsTopFrA.lean index e51486a93..4474e6664 100644 --- a/proofs/Fl4ProofsA64/P3/VsTopFrA.lean +++ b/proofs/Fl4ProofsA64/P3/VsTopFrA.lean @@ -294,7 +294,7 @@ theorem page_unmapS2Z_decJA {ar : machine.Arch A} 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 hst E1 hOK hks hcpu obtain ⟨s3, σ3, hsc, -, hσ3, J3, T3⟩ := setcap_coreA E RS E1.j hOK hks hcpu 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) hTr hnul + (UA.of_shapeA rfl fun h => by cases h) hok (fun h => by cases h) (fun h => by cases h) hTr hnul (PtSrcA.nopt fun _ _ _ _ h => by cases h) have hu0 : ((), stUpdA σ σ.curThread x .restart) ∈ (Fl4SpecA64.extUnmapPage (Z := Unit) .stage2 (frameSizeOfA sz) (BitVec.ofNat 16 (0#u64 : U64).val) va.bv (specPtr fp) (stUpdA σ σ.curThread x .restart)).1 := by rw [e0]; exact extUnmapPage_zeroA _ _ _ _ diff --git a/proofs/Fl4ProofsA64/P3/VsTopPtA.lean b/proofs/Fl4ProofsA64/P3/VsTopPtA.lean index 506eb00ee..a4e3d1d67 100644 --- a/proofs/Fl4ProofsA64/P3/VsTopPtA.lean +++ b/proofs/Fl4ProofsA64/P3/VsTopPtA.lean @@ -23,16 +23,9 @@ cap kind, every label, `TopPost`). **`NoExtXA`** — FL4's first extra cap is no `Ept`, no `HighVSpace` and no Stage-2 (`is_ept`) frame cap; **`NoExtXA.s1`** / **`.hi`** (the map tops' `hS1` / `hHi`), **`NoExtXA.spec`** (through `ExtraRelA`, the spec's first extra cap is no `.archObjectCap (.ext _)`). -* **`decInv_pt_jA`**: the top. `ARMPageTableUnmap` by FL4's `is_final_capability` (total, `P0`), the mapping and the - ASID's root kind: non-final `pt_unmap_nfJA`, unmapped `pt_unmapU_decJA`, on no root / a Stage-1 root - `pt_unmapS1_decJA`, on an FL4 root `pt_unmap_decJA`; `ARMPageTableMap` `pt_map_jA` (`dec_ptMap_specA`); any other - label FL4's `IllegalOperation` against `dec_ptOtherA`. - -Named premises: `ArchKeepsA` [P] and `S2IpaE` [P] (as the unmap tops). Decode-site hypotheses (standing): `TabOffA`, -`ExtTabOffA`, `RsSiteA`; at `ARMPageTableMap` only (`hMap`), `UnmPtA` and ruling (c)'s `ptr ∉ S2PgE ∧ ptr ∉ Y`. -Lemma hypotheses: `PtCapInA`, `FinInvA` (as the unmap tops), the front end's argument / extra-cap facts (`hlen`, -`hargs`, `hx0`, `hex`, as `pt_map_jA`), the selector `NoExtXA`. No new named premise; new module, no existing statement -changed. +* The page-table cap-kind top over all labels is `ExtMapPtA.decInv_pt_all_jA` (error outcome only, `VsErrPostA`). + +This module holds the shared outcome definitions and front-end lemmas; no named premise. -/ import Fl4ProofsA64.P3.VsArmA import Fl4ProofsA64.P3.UnmapPtS1JA @@ -61,6 +54,13 @@ def VsTopPostA (AR : A → HwRootA → Prop) (Z : XSetsA) (OS : Set U64) (m : Fl ∃ Z' : XSetsA, Z'.th = Z.th ∧ Z'.G = Z.G ∧ JAtZAX (L := L) AR Z' s' a' σ' m ∧ TreeA st OS Z.G.chains Z.G.par s' ∧ (CarryA Z (L.mem s) σ → CarryA Z' (L.mem s') σ') +/-- **The error-only outcome**: an error as in `VsTopPostA`; nothing is said of success. -/ +def VsErrPostA {α : Type} (σ : Fl4SpecA64.State Unit) + (D : Set (Except Fl4SpecA64.SyscallError α × Fl4SpecA64.State Unit) × Prop) + (s : S) (a : A) : core.result.Result Unit error.Exc × S × A → Prop + | (.Err e, s', a') => s' = s ∧ a' = a ∧ ∃ e', D = ({(.error e', σ)}, False) ∧ VsErrRelA e e' + | (.Ok (), _, _) => True + /-- (S3 gen 33, ruling 02:15Z F2) A single decode outcome is one of the decode's outcomes. -/ theorem okD_memA {α : Type} {D : Set (Except Fl4SpecA64.SyscallError α × Fl4SpecA64.State Unit) × Prop} {σ : Fl4SpecA64.State Unit} {x : α} (h : D = ({(.ok x, σ)}, False)) : (.ok x, σ) ∈ D.1 ∧ ¬ D.2 := by @@ -100,6 +100,18 @@ theorem mem_archExtA {iv : Fl4SpecA64.ExtVSpaceInvocation} {σ1 σ' : Fl4SpecA64 variable {AR : A → HwRootA → Prop} {Z : XSetsA} {OS : Set U64} {m : Fl4SpecA64.McState} {σ : Fl4SpecA64.State Unit} {s : S} {a : A} +theorem VsErrPostA.liftME {α β : Type} {f : α → β} + {d : Fl4Spec.NonDetE (Fl4SpecA64.State Unit) Fl4SpecA64.SyscallError α} : + ∀ {res}, VsErrPostA σ (d.run σ) s a res → VsErrPostA σ ((Fl4Spec.NonDetE.liftME f d).run σ) s a res + | (.Err _, _, _), ⟨hs, ha, e', hD, he⟩ => ⟨hs, ha, e', run_liftME_errA hD, he⟩ + | (.Ok (), _, _), _ => trivial + +theorem VsTopPostA.errOnly + {D : Set (Except Fl4SpecA64.SyscallError Fl4SpecA64.Fl4ArchInvocation × Fl4SpecA64.State Unit) × Prop} : + ∀ {res}, VsTopPostA (L := L) AR Z OS m σ D s a res → VsErrPostA σ D s a res + | (.Err _, _, _), h => h + | (.Ok (), _, _), _ => trivial + /-- **`PtMapJPostA` through `liftME .spec`** (module docstring). -/ theorem vsTop_ofPtMapA {ptr : U64} {m0 : Fl4SpecA64.SEMonad Unit Fl4SpecA64.ArchInvocation} : ∀ {res}, PtMapJPostA (L := L) AR Z OS m ptr σ (m0.run σ) s a res → @@ -263,7 +275,7 @@ theorem NoExtXA.spec {th : TypedHeapA} {mem : U64 → U64} {x0 : U64} end sel -/-! ## The top -/ +/-! ## FL4's front end on other labels -/ section variable {S : Type} {st : machine.Store S} [L : LawfulStore st] {A : Type} @@ -282,86 +294,6 @@ theorem decode_pt_otherA {ar : machine.Arch A} (lbl length slot buf : U64) (ex : unfold vspace.decode_page_table simp only [hct, bind_ok, h48, h47', ↓reduceIte, error.illegal] -set_option maxHeartbeats 4000000 in -/-- **The page-table cap-kind top** (module docstring; ruling 01:37Z item 1): `decode_invocation` on a `Cap::PageTable`, -every label, against `fl4ArchDecodeInvocation` at FL4's label, with `VsTopPostA`. -/ -theorem decInv_pt_jA {ar : machine.Arch A} (K : ArchKeepsA ar AR) - (E : JEntA (L := L) AR Z H OS U Ac Pp Tb Lv ia ie s a σ m) (RS : RsSiteA (L := L) Z H OS Ac Pp Tb Lv s) - (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) - (hPC : PtCapInA Z (L.mem s)) (hFI : FinInvA Z.th (L.mem s) σ Z.G) - (hTr : TreeA st OS Z.G.chains Z.G.par s) (hnul : ∀ y ∈ OS, ¬ IsSlotA Z.th y → capA st s y = .Null) - (cte : Fl4SpecA64.CslotPtr) (hab : AbsSlotA Z.th cte) (hos : cslotAddrA cte ∈ OS) - (ptr asid va : U64) (mp : Bool) (hcap : capAtA (L.mem s) (cslotAddrA cte) = .PageTable ptr mp asid va) - (lbl length buf : U64) (block call cd fp calling : Bool) (ex : Aeneas.Std.Array obj.Slot 3#usize) - (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) - (x0 : U64) (hx0 : Aeneas.Std.Array.index_usize ex 0#usize = ok x0) - (xSlot : Fl4SpecA64.CapRef) (exs : List (Fl4SpecA64.Cap × Fl4SpecA64.CslotPtr)) - (hex : ExtraRelA Z.th (L.mem s) x0 (exs.map Prod.fst)) (hNX : NoExtXA (capAtA (L.mem s) x0)) - (hMap : 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) : - 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 σ ((Fl4SpecA64.fl4ArchDecodeInvocation (Z := Unit) calling - (Fl4SpecA64.fl4LabelOf lbl.bv) (args.map UScalar.bv) xSlot cte - (.pageTableCap (specPtr ptr) .normalPtT (mapDataA mp asid va)) exs).run σ) s a res ⦄ := by - rw [decInv_ptA] - by_cases h48 : lbl = fl4_abi.label.ARMPageTableUnmap - · subst h48 - have hlab : Fl4SpecA64.fl4LabelOf fl4_abi.label.ARMPageTableUnmap.bv = Fl4SpecA64.archL .armPageTableUnmap := by - rw [fl4LabelOf_bvA, show fl4_abi.label.ARMPageTableUnmap.val = 48 by simp [fl4_abi.label.ARMPageTableUnmap]]; rfl - rw [hlab] - obtain ⟨b, hf, -⟩ := spec_existsA (Fl4ProofsA64.P0.cdt.is_final_capability.p0 st s (cslotAddrA cte) L.total) - cases b - · obtain ⟨hD, hdec, hrel, -⟩ := pt_unmap_nfJA (ar := ar) E hFI length buf calling ex (args.map UScalar.bv) xSlot - exs cte hab ptr asid va mp hcap hf - rw [hdec] - exact (WP.spec_ok _).2 ⟨rfl, rfl, .revokeFirst, hD, Or.inl hrel⟩ - cases mp - · rw [show mapDataA false asid va = none from rfl] - obtain ⟨hD, x, -, hset, hrest⟩ := pt_unmapU_decJA (ar := ar) E RS length buf calling ex (args.map UScalar.bv) - xSlot exs cte hab ptr asid va hcap hFI hf - obtain ⟨s3, σ3, hdec, hp, J3, T3, C3⟩ := hrest hTr hnul - rw [hdec] - exact (WP.spec_ok _).2 ⟨_, okD_memA hD, _, hset, σ3, [], mem_archNRA hp, Z, rfl, rfl, J3, T3, C3⟩ - rw [show mapDataA true asid va = some (BitVec.ofNat 16 asid.val, va.bv) from rfl] - have hS1 : ∀ k, Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = k → (k = none ∨ k = some .stage1) → - vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap length (cslotAddrA cte) - (.PageTable ptr true asid va) buf ex ⦃ res => VsTopPostA (L := L) AR Z OS m σ - ((Fl4SpecA64.fl4ArchDecodeInvocation (Z := Unit) calling (Fl4SpecA64.archL .armPageTableUnmap) - (args.map UScalar.bv) xSlot cte (.pageTableCap (specPtr ptr) .normalPtT - (some (BitVec.ofNat 16 asid.val, va.bv))) exs).run σ) s a res ⦄ := by - rintro k hk hk' - obtain ⟨hD, x, -, hset, hrest⟩ := pt_unmapS1_decJA K E RS hTO hEO hK hT length buf calling ex - (args.map UScalar.bv) xSlot exs cte hab ptr asid va hPC hcap hFI hf (by subst hk; exact hk') - obtain ⟨s3, σ3, fa, hdec, hp, hJ, T3, C3⟩ := hrest hTr hnul - rw [hdec] - exact vsTop_ofFaA hD hset (mem_archNRA hp) hJ T3 C3 - rcases hk : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) with _ | k - · exact hS1 _ hk (Or.inl rfl) - by_cases hk1 : k = .stage1 - · subst hk1; exact hS1 _ hk (Or.inr rfl) - obtain ⟨hD, x, -, hset, hrest⟩ := pt_unmap_decJA K E RS hTO hEO hK hT hIpa length buf calling ex - (args.map UScalar.bv) xSlot exs cte hab ptr asid va hPC hcap hFI hf k hk hk1 - obtain ⟨s3, σ3, fa, hdec, hp, hJ, T3, C3⟩ := hrest hTr hnul - rw [hdec] - 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 : Fl4SpecA64.fl4LabelOf fl4_abi.label.ARMPageTableMap.bv = Fl4SpecA64.archL .armPageTableMap := by - rw [fl4LabelOf_bvA, show fl4_abi.label.ARMPageTableMap.val = 47 by simp [fl4_abi.label.ARMPageTableMap]]; rfl - rw [hlab, dec_ptMap_specA calling _ xSlot cte exs _ _ (hNX.spec hex)] - exact WP.spec_mono (pt_map_jA ar E RS cte hab hos hcap UP _ invType_ptMapA length buf args hlen hargs x0 hx0 exs - hex hNX.s1 hNX.hi hTr hnul hTO hS2 hY) fun _ h => vsTop_ofPtMapA h - rw [decode_pt_otherA lbl length _ buf ex ptr asid va mp h48 h47] - have hv48 : lbl.val ≠ 48 := fun e => h48 (UScalar.eq_of_val_eq (by rw [e]; simp [fl4_abi.label.ARMPageTableUnmap])) - have hv47 : lbl.val ≠ 47 := fun e => h47 (UScalar.eq_of_val_eq (by rw [e]; simp [fl4_abi.label.ARMPageTableMap])) - rw [dec_ptOtherA calling _ xSlot cte exs _ - (by rw [fl4LabelOf_bvA]; exact labNA_neA (fun n hn => (labNA_tabA n hn).1) (by decide) hv47) - (by rw [fl4LabelOf_bvA]; exact labNA_neA (fun n hn => (labNA_tabA n hn).2.1) (by decide) hv48)] - exact (WP.spec_ok _).2 ⟨rfl, rfl, .illegalOperation, rfl, Or.inl trivial⟩ - end end diff --git a/proofs/Fl4ProofsA64/P3/VsUClosedA.lean b/proofs/Fl4ProofsA64/P3/VsUClosedA.lean new file mode 100644 index 000000000..64815e55d --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUClosedA.lean @@ -0,0 +1,237 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, RO1): **the class-generic "unmapped table cap is unique" step obligation** +(`rootOnce`, A′, and its page-table twin). A *class* is a pair `K U` of predicates `r → cap → Prop` (`K r c`: `c` is a +cap of the class naming `r`; `U r c`: an unmapped one), with `U ⊆ K`, no `Null` and no `Untyped` cap in `K`. +* `UClosed K U th mem mem'`: an unmapped `K`-cap of `r` after the step was one before (at `y0`), and every other `K`-cap + of `r` after is `y` or has a `K`-source other than `y0` before (impossible by the uniqueness at `y0`). +* `UClosedE`: the same with the escape "`y` is the only holder of `r` after" (the unmap of the unique mapped holder). +* Lemmas written once: `refl`, `of_cap`, `pos`, `of_set`, `of_perm`, `of_exch`, `of_swapC`, `of_mv`, `of_copy`, `trans`, + `UClosed.toE`, `UClosedE.of_set_esc`. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.StateRelA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 + +noncomputable section + +/-- A class of table caps (module docstring). -/ +structure UCls (K U : U64 → capability.Cap → Prop) : Prop where + uk : ∀ r c, U r c → K r c + kn : ∀ r, ¬ K r .Null + ku : ∀ r p b i e, ¬ K r (.Untyped p b i e) + +section +variable {K U : U64 → capability.Cap → Prop} {th : TypedHeapA} {mem mem' : U64 → U64} + +def UClosed (K U : U64 → capability.Cap → Prop) (th : TypedHeapA) (mem mem' : U64 → U64) : Prop := + ∀ y, IsSlotA th y → ∀ r, U r (capAtA mem' y) → + ∃ y0, IsSlotA th y0 ∧ U r (capAtA mem y0) ∧ + ∀ z, IsSlotA th z → K r (capAtA mem' z) → + z = y ∨ ∃ s, IsSlotA th s ∧ K r (capAtA mem s) ∧ s ≠ y0 + +/-- `UClosed` with the escape "`y` is the only `K`-holder of `r` after". -/ +def UClosedE (K U : U64 → capability.Cap → Prop) (th : TypedHeapA) (mem mem' : U64 → U64) : Prop := + ∀ y, IsSlotA th y → ∀ r, U r (capAtA mem' y) → + (∃ y0, IsSlotA th y0 ∧ U r (capAtA mem y0) ∧ + ∀ z, IsSlotA th z → K r (capAtA mem' z) → + z = y ∨ ∃ s, IsSlotA th s ∧ K r (capAtA mem s) ∧ s ≠ y0) ∨ + ∀ z, IsSlotA th z → K r (capAtA mem' z) → z = y + +theorem UClosed.toE (h : UClosed K U th mem mem') : UClosedE K U th mem mem' := + fun y hy r hu => Or.inl (h y hy r hu) + +theorem UClosed.refl (th : TypedHeapA) (mem : U64 → U64) : UClosed K U th mem mem := + fun y hy r h => ⟨y, hy, h, fun z hz hk => by + by_cases e : z = y + · exact Or.inl e + · exact Or.inr ⟨z, hz, hk, e⟩⟩ + +theorem UClosed.of_cap (C : UCls K U) + (hc : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y ∨ ∀ r, ¬ K r (capAtA mem' y)) : UClosed K U th mem mem' := + fun y hy r h => by + rcases hc y hy with e | e + · refine ⟨y, hy, e ▸ h, fun z hz hk => ?_⟩ + by_cases ez : z = y + · exact Or.inl ez + · rcases hc z hz with e' | e' + · exact Or.inr ⟨z, hz, e' ▸ hk, ez⟩ + · exact (e' r hk).elim + · exact (e r (C.uk _ _ h)).elim + +theorem UClosed.trans {m0 m1 m2 : U64 → U64} (h1 : UClosed K U th m0 m1) (h2 : UClosed K U th m1 m2) : + UClosed K U th m0 m2 := by + intro y hy r h + obtain ⟨y1, hy1, hu1, k1⟩ := h2 y hy r h + obtain ⟨y0, hy0, hu0, k0⟩ := h1 y1 hy1 r hu1 + refine ⟨y0, hy0, hu0, fun z hz hk => ?_⟩ + rcases k1 z hz hk with e | ⟨s1, hs1, hk1, hne⟩ + · exact Or.inl e + · rcases k0 s1 hs1 hk1 with e | ⟨s, hs, hks, hne0⟩ + · exact absurd e hne + · exact Or.inr ⟨s, hs, hks, hne0⟩ + +theorem UClosed.pos + (hU : ∀ y, IsSlotA th y → ∀ r, U r (capAtA mem' y) → U r (capAtA mem y)) + (hK : ∀ y, IsSlotA th y → ∀ r, K r (capAtA mem' y) → K r (capAtA mem y)) : UClosed K U th mem mem' := + fun y hy r h => ⟨y, hy, hU y hy r h, fun z hz hk => by + by_cases e : z = y + · exact Or.inl e + · exact Or.inr ⟨z, hz, hK z hz r hk, e⟩⟩ + +theorem UClosed.of_set {x : U64} {c : capability.Cap} + (hcx : capAtA mem' x = c) (hco : ∀ y, IsSlotA th y → y ≠ x → capAtA mem' y = capAtA mem y) + (hk : ∀ r, K r c → K r (capAtA mem x)) (hu : ∀ r, U r c → U r (capAtA mem x)) : UClosed K U th mem mem' := + UClosed.pos + (fun y hy r h => by + by_cases e : y = x + · subst e; rw [hcx] at h; exact hu r h + · rwa [hco y hy e] at h) + (fun y hy r h => by + by_cases e : y = x + · subst e; rw [hcx] at h; exact hk r h + · rwa [hco y hy e] at h) + +theorem UClosed.of_perm (C : UCls K U) {π : U64 → U64} + (hπ : ∀ y, IsSlotA th y → IsSlotA th (π y) ∧ ∀ r, K r (capAtA mem' y) → capAtA mem' y = capAtA mem (π y)) + (hinj : ∀ y z, IsSlotA th y → IsSlotA th z → π y = π z → y = z) : UClosed K U th mem mem' := by + intro y hy r h + obtain ⟨hs, he⟩ := hπ y hy + have hy' := he r (C.uk _ _ h) + refine ⟨π y, hs, hy' ▸ h, fun z hz hk => ?_⟩ + obtain ⟨hs', he'⟩ := hπ z hz + by_cases e : z = y + · exact Or.inl e + · exact Or.inr ⟨π z, hs', (he' r hk) ▸ hk, fun h' => e (hinj z y hz hy h')⟩ + +theorem UClosed.of_swapC (C : UCls K U) {a b : U64} {c1 c2 : capability.Cap} + (ha : IsSlotA th a) (hb : IsSlotA th b) + (h1 : capAtA mem' a = c2) (h2 : capAtA mem' b = c1) + (ho : ∀ y, IsSlotA th y → y ≠ a → y ≠ b → capAtA mem' y = capAtA mem y) + (hk1 : ∀ r, K r c1 → c1 = capAtA mem a) (hk2 : ∀ r, K r c2 → c2 = capAtA mem b) : + UClosed K U th mem mem' := by + refine UClosed.of_perm C (π := Equiv.swap a b) (fun y hy => ?_) + (fun y z _ _ h => (Equiv.swap a b).injective h) + by_cases ya : y = a + · subst ya; rw [Equiv.swap_apply_left]; exact ⟨hb, fun r h => by rw [h1] at h ⊢; exact hk2 r h⟩ + · by_cases yb : y = b + · subst yb; rw [Equiv.swap_apply_right]; exact ⟨ha, fun r h => by rw [h2] at h ⊢; exact hk1 r h⟩ + · rw [Equiv.swap_apply_of_ne_of_ne ya yb]; exact ⟨hy, fun _ _ => ho y hy ya yb⟩ + +theorem UClosed.of_exch (C : UCls K U) {a b : U64} (ha : IsSlotA th a) (hb : IsSlotA th b) + (h1 : capAtA mem' a = capAtA mem b) (h2 : capAtA mem' b = capAtA mem a) + (ho : ∀ y, IsSlotA th y → y ≠ a → y ≠ b → capAtA mem' y = capAtA mem y) : UClosed K U th mem mem' := by + refine UClosed.of_perm C (π := Equiv.swap a b) (fun y hy => ?_) (fun y z _ _ h => (Equiv.swap a b).injective h) + by_cases ya : y = a + · subst ya; rw [Equiv.swap_apply_left]; exact ⟨hb, fun _ _ => h1⟩ + · by_cases yb : y = b + · subst yb; rw [Equiv.swap_apply_right]; exact ⟨ha, fun _ _ => h2⟩ + · rw [Equiv.swap_apply_of_ne_of_ne ya yb]; exact ⟨hy, fun _ _ => ho y hy ya yb⟩ + +theorem UClosed.of_mv (C : UCls K U) {ss sd : U64} {nc : capability.Cap} + (h1 : capAtA mem' ss = .Null) (h2 : capAtA mem' sd = nc) (hss : IsSlotA th ss) + (ho : ∀ y, IsSlotA th y → y ≠ ss → y ≠ sd → capAtA mem' y = capAtA mem y) + (hk : ∀ r, K r nc → K r (capAtA mem ss)) + (hu : ∀ r, U r nc → U r (capAtA mem ss)) : UClosed K U th mem mem' := by + intro y hy r h + by_cases eys : y = ss + · subst eys; rw [h1] at h; exact (C.kn r (C.uk _ _ h)).elim + by_cases eyd : y = sd + · subst eyd + rw [h2] at h + refine ⟨ss, hss, hu r h, fun z hz hz' => ?_⟩ + by_cases ezs : z = ss + · subst ezs; rw [h1] at hz'; exact (C.kn r hz').elim + by_cases ezd : z = y + · exact Or.inl ezd + · exact Or.inr ⟨z, hz, (ho z hz ezs ezd ▸ hz'), ezs⟩ + · have hy0 : capAtA mem' y = capAtA mem y := ho y hy eys eyd + refine ⟨y, hy, hy0 ▸ h, fun z hz hz' => ?_⟩ + by_cases ezy : z = y + · exact Or.inl ezy + by_cases ezs : z = ss + · subst ezs; rw [h1] at hz'; exact (C.kn r hz').elim + by_cases ezd : z = sd + · subst ezd; rw [h2] at hz' + exact Or.inr ⟨ss, hss, hk r hz', fun e => eys e.symm⟩ + · exact Or.inr ⟨z, hz, (ho z hz ezs ezd ▸ hz'), ezy⟩ + +theorem UClosed.of_copy (C : UCls K U) {nc : capability.Cap} + (hcs : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y ∨ capAtA mem' y = nc ∨ + ∃ p b i e, capAtA mem' y = .Untyped p b i e) + (hn : ∀ r, ¬ U r nc) + (hs : ∀ r, K r nc → ∃ s0, IsSlotA th s0 ∧ K r (capAtA mem s0) ∧ ¬ U r (capAtA mem s0)) : + UClosed K U th mem mem' := by + intro y hy r h + have hy0 : capAtA mem' y = capAtA mem y := by + rcases hcs y hy with e | e | ⟨p, b, i, e', e⟩ + · exact e + · exact absurd (e ▸ h) (hn r) + · exact absurd (e ▸ C.uk _ _ h) (C.ku r p b i e') + refine ⟨y, hy, hy0 ▸ h, fun z hz hk => ?_⟩ + by_cases ez : z = y + · exact Or.inl ez + · rcases hcs z hz with e | e | ⟨p, b, i, e', e⟩ + · exact Or.inr ⟨z, hz, e ▸ hk, ez⟩ + · obtain ⟨s0, hs0, hk0, hnu⟩ := hs r (e ▸ hk) + refine Or.inr ⟨s0, hs0, hk0, fun e0 => hnu ?_⟩ + rw [e0, ← hy0]; exact h + · exact absurd (e ▸ hk) (C.ku r p b i e') + +/-- **A rotation** `sd ← sp ← ss ← Null` (three distinct slots), the others kept; a `K`-cap of the new `np` / `ns` is +the cap it came from. -/ +theorem UClosed.of_rot (C : UCls K U) {sd sp ss : U64} {np ns : capability.Cap} + (hdS : IsSlotA th sd) (hpS : IsSlotA th sp) (hsS : IsSlotA th ss) + (hdp : sd ≠ sp) (hds : sd ≠ ss) (hps : sp ≠ ss) + (cd : capAtA mem' sd = np) (cp : capAtA mem' sp = ns) (cs : capAtA mem' ss = .Null) + (co : ∀ y, IsSlotA th y → y ≠ sd → y ≠ sp → y ≠ ss → capAtA mem' y = capAtA mem y) + (hrp : ∀ r, K r np → np = capAtA mem sp) (hrs : ∀ r, K r ns → ns = capAtA mem ss) : + UClosed K U th mem mem' := by + refine UClosed.of_perm C (π := fun y => Equiv.swap sd sp (Equiv.swap sp ss y)) + (fun y hy => ?_) (fun y z _ _ e => (Equiv.swap _ _).injective ((Equiv.swap _ _).injective e)) + beta_reduce + by_cases eyd : y = sd + · subst y + rw [Equiv.swap_apply_of_ne_of_ne hdp hds, Equiv.swap_apply_left] + exact ⟨hpS, fun r hk => by rw [cd] at hk ⊢; exact hrp r hk⟩ + by_cases eyp : y = sp + · subst y + rw [Equiv.swap_apply_left, Equiv.swap_apply_of_ne_of_ne hds.symm hps.symm] + exact ⟨hsS, fun r hk => by rw [cp] at hk ⊢; exact hrs r hk⟩ + by_cases eys : y = ss + · subst y + rw [Equiv.swap_apply_right, Equiv.swap_apply_right] + exact ⟨hdS, fun r hk => by rw [cs] at hk; exact (C.kn r hk).elim⟩ + · rw [Equiv.swap_apply_of_ne_of_ne eyp eys, Equiv.swap_apply_of_ne_of_ne eyd eyp] + exact ⟨hy, fun r hk => co y hy eyd eyp eys⟩ + +/-- **The unmap of the unique holder**: slot `x` is rewritten to `c`, the others kept; a `K`-cap of `c` was one at `x` +(`hk`), and when `c` is unmapped no other slot holds a `K`-cap of its `r` (`hesc`, from finality). -/ +theorem UClosedE.of_set_esc {x : U64} {c : capability.Cap} + (hcx : capAtA mem' x = c) (hco : ∀ y, IsSlotA th y → y ≠ x → capAtA mem' y = capAtA mem y) + (hk : ∀ r, K r c → K r (capAtA mem x)) (hu : ∀ r, U r c → ∀ y, IsSlotA th y → y ≠ x → ¬ K r (capAtA mem y)) : + UClosedE K U th mem mem' := by + intro y hy r h + by_cases e : y = x + · subst e + rw [hcx] at h + refine Or.inr fun z hz hk' => ?_ + by_cases ez : z = y + · exact ez + · exfalso; rw [hco z hz ez] at hk'; exact hu r h z hz ez hk' + · refine Or.inl ⟨y, hy, by rw [← hco y hy e]; exact h, fun z hz hk' => ?_⟩ + by_cases ez : z = y + · exact Or.inl ez + · by_cases ezx : z = x + · subst ezx; rw [hcx] at hk' + exact Or.inr ⟨z, hz, hk r hk', ez⟩ + · rw [hco z hz ezx] at hk'; exact Or.inr ⟨z, hz, hk', ez⟩ + +end + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsUniqA.lean b/proofs/Fl4ProofsA64/P3/VsUniqA.lean new file mode 100644 index 000000000..d7499104b --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUniqA.lean @@ -0,0 +1,816 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, S0a): **the VSpace contract-tightening record `VsUniqA`** (a field of +`JAtZA`, next to `pml`; handoff `a64p5-vsinv-step0.md`). + +* `WalkSlotA`: the slots on the walk of an address `va` from a root table, through valid table descriptors of the + tracked tables (`P`). +* `S2EntryA` (moved here from `Stage3ArmPtUnmT2A`): the entry words of the reachable Stage-2 tables. +* `VsUniqA` (cap-universal, conditional on a *reachable* reference): + `t2` — a mapped page-table cap `(ptr, asid, va)` of a Stage-2 table: every reachable valid table descriptor naming + `ptr` lies on the walk of `va` from the Stage-2 root installed at `asid` (so the unmap of the cap clears it; replaces + the former case premises `PtUniqT2A` and "root kind ≠ stage1"); + `s1` — the same for a Stage-1 / high-window table (S1 shrink); + `out` — an unmapped page-table cap names an untracked table (`ptr ∉ S1 ∪ T2`). +* Generic frames `VsUniqA.ofNoPt`, `of_frame` (same ghosts; words kept on the footprint, ASID table and pools kept, caps + unchanged or no page-table cap). + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.StateRelA +import Fl4ProofsA64.P3.VsRelA +import Fl4ProofsA64.P3.ExtVsDefA +import Fl4ProofsA64.P3.VsUClosedA +import Fl4ProofsA64.P1.MdbRoot +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- The index of `va` at shift `sh` in a table of `n` entries. -/ +def walkIdx (va : U64) (sh n : Nat) : U64 := ⟨BitVec.ofNat 64 (va.val / 2 ^ sh % n)⟩ + +/-- **The slots on the walk of `va`** from the table `t` (shift `sh`, `n` entries): the slot of `va` in `t`, and the +walk's slots in the child tables reached through valid table descriptors of the tracked tables `P`. -/ +inductive WalkSlotA (P : U64 → Prop) (mem : U64 → U64) (va : U64) : U64 → Nat → Nat → U64 → Prop + | here (t : U64) (sh n : Nat) : WalkSlotA P mem va t sh n (peAF t (walkIdx va sh n)) + | down (t : U64) (sh n : Nat) (w : U64) : + (mem (peAF t (walkIdx va sh n)) &&& 3#u64) = 3#u64 → 12 < sh → + P (dTabA (mem (peAF t (walkIdx va sh n)))) → + WalkSlotA P mem va (dTabA (mem (peAF t (walkIdx va sh n)))) (sh - 9) 512 w → + WalkSlotA P mem va t sh n w + +/-- A walk reads only the words `hq` keeps (the start table at its size, the tracked tables at 512 entries). -/ +theorem WalkSlotA.of_mem {P : U64 → Prop} {mem mem' : U64 → U64} {va t w : U64} {sh n : Nat} + (h : WalkSlotA P mem' va t sh n w) + (hq : ∀ t' sh' n', ((t' = t ∧ n' = n) ∨ (P t' ∧ n' = 512)) → + mem' (peAF t' (walkIdx va sh' n')) = mem (peAF t' (walkIdx va sh' n'))) : + WalkSlotA P mem va t sh n w := by + induction h with + | here t sh n => exact .here t sh n + | @down t sh n w h3 h12 hP hw ih => + have e := hq t sh n (Or.inl ⟨rfl, rfl⟩) + have ih' := ih (fun t' sh' n' hh => by + rcases hh with ⟨rfl, rfl⟩ | hh + · exact hq _ _ _ (Or.inr ⟨hP, rfl⟩) + · exact hq _ _ _ (Or.inr hh)) + refine .down t sh n w ?_ h12 ?_ ?_ + · rw [← e]; exact h3 + · rw [← e]; exact hP + · rw [← e]; exact ih' + +/-- The reverse direction (`mem'` and `mem` swapped). -/ +theorem WalkSlotA.of_mem' {P : U64 → Prop} {mem mem' : U64 → U64} {va t w : U64} {sh n : Nat} + (h : WalkSlotA P mem va t sh n w) + (hq : ∀ t' sh' n', ((t' = t ∧ n' = n) ∨ (P t' ∧ n' = 512)) → + mem' (peAF t' (walkIdx va sh' n')) = mem (peAF t' (walkIdx va sh' n'))) : + WalkSlotA P mem' va t sh n w := + WalkSlotA.of_mem (mem := mem') (mem' := mem) h fun t' sh' n' hh => (hq t' sh' n' hh).symm + +/-- **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) + +/-- The Stage-2 root installed at `asid` (`ActiveS2RootA` at a given ASID). -/ +def S2RootOfAsidA (Pp X : Set U64) (σ : Fl4SpecA64.State Unit) (asid : U64) (r : U64) : Prop := + r ∈ X ∧ ∃ (p : U64) (f : Fl4SpecA64.AsidPool), + 0 < BitVec.ofNat 16 asid.val ∧ p ∈ Pp ∧ + σ.archState.armAsidTable (Fl4SpecA64.asidHighBitsOf (BitVec.ofNat 16 asid.val)) = some (specPtr p) ∧ + σ.kheap (specPtr p) = some (.archObj (.asidPool f)) ∧ + f (Fl4SpecA64.asidLowBitsOf (BitVec.ofNat 16 asid.val)) = some (.asidPoolVSpace (specPtr r)) + +/-- **A root-kind cap of `r`** (A′, `rootOnce`): a Stage-1 `Pml4`, a level-zero `Ept` or a `HighVSpace` cap. -/ +def RootKindA (r : U64) (c : capability.Cap) : Prop := + (∃ mp asid, c = .Pml4 r mp asid) ∨ (∃ mp asid va, c = .Ept r 0#u64 mp asid va) ∨ + (∃ mp asid, c = .HighVSpace r mp asid) + +/-- An UNMAPPED root-kind cap of `r` (not yet assigned to an ASID). -/ +def RootUnmA (r : U64) (c : capability.Cap) : Prop := + (∃ asid, c = .Pml4 r false asid) ∨ (∃ asid va, c = .Ept r 0#u64 false asid va) ∨ + (∃ asid, c = .HighVSpace r false asid) + +theorem RootUnmA.kind {r : U64} {c : capability.Cap} (h : RootUnmA r c) : RootKindA r c := by + rcases h with ⟨a, rfl⟩ | ⟨a, v, rfl⟩ | ⟨a, rfl⟩ + · exact Or.inl ⟨_, _, rfl⟩ + · exact Or.inr (Or.inl ⟨_, _, _, rfl⟩) + · exact Or.inr (Or.inr ⟨_, _, rfl⟩) + +/-- A cap that is no root-kind cap. -/ +def NoRootKindA (c : capability.Cap) : Prop := ∀ r, ¬ RootKindA r c + +/-- A cap that is neither a page-table cap nor a root-kind cap. -/ +def NoVsCapA (c : capability.Cap) : Prop := + (∀ ptr asid va : U64, ∀ mp : Bool, c ≠ .PageTable ptr mp asid va) ∧ NoRootKindA c + +theorem NoRootKindA.null : NoRootKindA .Null := by + intro r h + rcases h with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h + +theorem NoRootKindA.of_ne {c : capability.Cap} (h : ∀ r mp asid, c ≠ .Pml4 r mp asid) + (h2 : ∀ r mp asid va, c ≠ .Ept r 0#u64 mp asid va) (h3 : ∀ r mp asid, c ≠ .HighVSpace r mp asid) : NoRootKindA c := by + intro r hk + rcases hk with ⟨_, _, e⟩ | ⟨_, _, _, e⟩ | ⟨_, _, e⟩ + exacts [h _ _ _ e, h2 _ _ _ _ e, h3 _ _ _ e] + +theorem NoRootKindA.untyped (p b i e) : NoRootKindA (.Untyped p b i e) := + NoRootKindA.of_ne (fun _ _ _ => by intro h; cases h) (fun _ _ _ _ => by intro h; cases h) + (fun _ _ _ => by intro h; cases h) + +theorem rootUCls : UCls RootKindA RootUnmA := + ⟨fun _ _ h => h.kind, fun r h => NoRootKindA.null r h, fun r p b i e h => NoRootKindA.untyped p b i e r h⟩ + +/-- **A `PageTable` cap of `r`** (the page-table twin of `RootKindA`, ruling 20:28Z). -/ +def PtKindA (r : U64) (c : capability.Cap) : Prop := ∃ mp asid va, c = .PageTable r mp asid va + +/-- An UNMAPPED `PageTable` cap of `r`. -/ +def PtUnmA (r : U64) (c : capability.Cap) : Prop := ∃ asid va, c = .PageTable r false asid va + +theorem PtUnmA.kind {r : U64} {c : capability.Cap} (h : PtUnmA r c) : PtKindA r c := by + obtain ⟨a, v, e⟩ := h; exact ⟨false, a, v, e⟩ + +theorem ptUCls : UCls PtKindA PtUnmA := + ⟨fun _ _ h => h.kind, fun r h => (by obtain ⟨_, _, _, e⟩ := h; cases e), + fun r p b i e h => (by obtain ⟨_, _, _, e⟩ := h; cases e)⟩ + +/-- A cap that is no `PageTable` cap. -/ +def NoPtKindA (c : capability.Cap) : Prop := ∀ r, ¬ PtKindA r c + +theorem NoVsCapA.pt {c : capability.Cap} (h : NoVsCapA c) : NoPtKindA c := by + intro r hk; obtain ⟨mp, a, v, e⟩ := hk; exact h.1 r a v mp e + +theorem NoPtKindA.of_ne {c : capability.Cap} (h : ∀ r mp asid va, c ≠ .PageTable r mp asid va) : NoPtKindA c := by + intro r hk; obtain ⟨mp, a, v, e⟩ := hk; exact h r mp a v e + +theorem NoVsCapA.zombie (p zt n : U64) : NoVsCapA (.Zombie p zt n) := + And.intro (fun _ _ _ _ h => by cases h) (NoRootKindA.of_ne (fun _ _ _ h => by cases h) + (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h)) + +theorem NoVsCapA.null : NoVsCapA .Null := + And.intro (fun _ _ _ _ h => by cases h) NoRootKindA.null + +/-- **`r` is installed at an ASID** (a pool entry naming it, or a spec pool entry naming it). -/ +def RootInstA (Pp X : Set U64) (mem : U64 → U64) (ksb : U64) (σ : Fl4SpecA64.State Unit) (r : U64) : Prop := + (∃ asid raw, ActiveAsidRootA mem ksb Pp asid raw ∧ untagA raw = r) ∨ ∃ asid, S2RootOfAsidA Pp X σ asid r + +theorem RootInstA.mem {Pp Tb X Y : Set U64} {Lv : U64 → Nat} {mem : U64 → U64} {ksb : U64} {σ : Fl4SpecA64.State Unit} + {r : U64} (V : VsRelA Pp Tb Lv X Y mem ksb σ) (h : RootInstA Pp X mem ksb σ r) : r ∈ Tb ∨ r ∈ X ∨ r ∈ Y := by + rcases h with ⟨a, raw, ha, e⟩ | ⟨a, h⟩ + · obtain ⟨pool, hp, hpl, lo, hlo, hw, hne⟩ := ha.activePool + have hk := V.kind pool hp hpl lo hlo + rw [hw] at hk + subst e + rcases hk with h0 | ⟨-, h, -⟩ | ⟨-, h⟩ | ⟨-, h⟩ + · exact absurd h0 hne + · exact Or.inl h + · exact Or.inr (Or.inl h) + · exact Or.inr (Or.inr h) + · exact Or.inr (Or.inl h.1) + +/-- **`rootOnce`** (A′): an UNMAPPED root-kind cap of `r` is the only root-kind cap of `r`, and `r` is installed at no +ASID (so ASIDPoolAssign keeps `rootInj1/2`). -/ +def RootOnceA (th : TypedHeapA) (Pp X : Set U64) (mem : U64 → U64) (ksb : U64) (σ : Fl4SpecA64.State Unit) : Prop := + ∀ y, IsSlotA th y → ∀ r, RootUnmA r (capAtA mem y) → + ¬ RootInstA Pp X mem ksb σ r ∧ ∀ z, IsSlotA th z → RootKindA r (capAtA mem z) → z = y + +/-- **The root-kind step obligation**: an unmapped root-kind cap after the step was one before (at `y0`), and every +other root-kind cap of `r` after is `y` or has a root-kind source other than `y0` before (impossible by `rootOnce`). -/ +def RootClosedA (th : TypedHeapA) (mem mem' : U64 → U64) : Prop := UClosed RootKindA RootUnmA th mem mem' + +/-- **`ptOnce`** (ruling 20:06Z): an UNMAPPED `PageTable` cap of `r` is the only `PageTable` cap of `r`. -/ +def PtOnceA (th : TypedHeapA) (mem : U64 → U64) : Prop := + ∀ y, IsSlotA th y → ∀ r, PtUnmA r (capAtA mem y) → ∀ z, IsSlotA th z → PtKindA r (capAtA mem z) → z = y + +/-- The page-table step obligation (`UClosedE`: the unmap of the unique holder escapes). -/ +def PtUClosedA (th : TypedHeapA) (mem mem' : U64 → U64) : Prop := UClosedE PtKindA PtUnmA th mem mem' + +theorem PtOnceA.step {th : TypedHeapA} {mem mem' : U64 → U64} (U : PtOnceA th mem) (hc : PtUClosedA th mem mem') : + PtOnceA th mem' := by + intro y hy r h z hz hk + rcases hc y hy r h with ⟨y0, hy0, h0, hzs⟩ | hz' + · rcases hzs z hz hk with e | ⟨s, hs, hks, hne⟩ + · exact e + · exact absurd (U y0 hy0 r h0 s hs hks) hne + · exact hz' z hz hk + +theorem RootOnceA.step {th : TypedHeapA} {Pp Pp' X X' : Set U64} {mem mem' : U64 → U64} {ksb ksb' : U64} + {σ σ' : Fl4SpecA64.State Unit} (U : RootOnceA th Pp X mem ksb σ) (hc : RootClosedA th mem mem') + (hI : ∀ r, RootInstA Pp' X' mem' ksb' σ' r → RootInstA Pp X mem ksb σ r) : RootOnceA th Pp' X' mem' ksb' σ' := by + intro y hy r h + obtain ⟨y0, hy0, h0, hz⟩ := hc y hy r h + obtain ⟨hn, hu⟩ := U y0 hy0 r h0 + refine ⟨fun hi => hn (hI r hi), fun z hz' hk => ?_⟩ + rcases hz z hz' hk with e | ⟨s, hs, hks, hne⟩ + · exact e + · exact absurd (hu s hs hks) hne + +section rel +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {ksb : U64} + {σ : Fl4SpecA64.State Unit} + +/-- **The tracked Stage-1 / high-window tables** (a walk's tables). -/ +abbrev S1TabA (S1 Y : Set U64) (t : U64) : Prop := t ∈ S1 ∨ ∃ y ∈ Y, t = wa y 4096#u64 + +/-- **The VSpace contract record** (module docstring). -/ +structure VsUniqA (th : TypedHeapA) (Pp S1 X Y T2 : Set U64) (Sh2 : U64 → Nat) (mem : U64 → U64) (ksb : U64) + (σ : Fl4SpecA64.State Unit) : Prop where + /-- A mapped page-table cap of a Stage-2 table: every reachable valid table descriptor naming it is on the walk of + its address from the Stage-2 root installed at its ASID. -/ + t2 : ∀ y, IsSlotA th y → ∀ ptr asid va : U64, capAtA mem y = .PageTable ptr true asid va → ptr ∈ T2 → + ∀ w, S2EntryA Pp X T2 Sh2 mem σ w → (mem w &&& 3#u64) = 3#u64 → dTabA (mem w) = ptr → + ∃ r, S2RootOfAsidA Pp X σ asid r ∧ + WalkSlotA (· ∈ T2) mem va r Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) w + /-- The same for a Stage-1 / high-window table. -/ + s1 : ∀ y, IsSlotA th y → ∀ ptr asid va : U64, capAtA mem y = .PageTable ptr true asid va → ptr ∈ S1 → + ∀ (tag : U64) (sh : Nat) (t i : U64), VsPathA Pp S1 Y mem ksb tag sh t → S1TabA S1 Y t → 12 < sh → + i.val < 512 → (mem (peAF t i) &&& 3#u64) = 3#u64 → dTabA (mem (peAF t i)) = ptr → + ∃ raw, ActiveAsidRootA mem ksb Pp asid raw ∧ + ((tagA raw = 0 ∧ raw ∈ S1 ∧ WalkSlotA (S1TabA S1 Y) mem va raw 39 512 (peAF t i)) ∨ + (tagA raw = 2 ∧ untagA raw ∈ Y ∧ WalkSlotA (S1TabA S1 Y) mem va (wa (untagA raw) 4096#u64) 30 512 (peAF t i))) + /-- An unmapped page-table cap names an untracked Stage-2 table (the Stage-1 half, `ptr ∉ S1`, waits for the S1 + shrink of the Stage-1 unmap arms, which keep the table in `S1`). -/ + out : ∀ y, IsSlotA th y → ∀ ptr asid va : U64, capAtA mem y = .PageTable ptr false asid va → ptr ∉ T2 + /-- **Stage-2 reach is a forest**: two reachable valid descriptors naming one tracked table are one slot (the + walk of a cap survives the removal of a descriptor off it). -/ + inj2 : ∀ w1 w2, S2EntryA Pp X T2 Sh2 mem σ w1 → S2EntryA Pp X T2 Sh2 mem σ w2 → + (mem w1 &&& 3#u64) = 3#u64 → (mem w2 &&& 3#u64) = 3#u64 → dTabA (mem w1) = dTabA (mem w2) → + dTabA (mem w1) ∈ T2 → w1 = w2 + /-- A Stage-2 root is installed at one ASID (modulo the 16 bits the spec reads). -/ + rootInj2 : ∀ a1 a2 r : U64, S2RootOfAsidA Pp X σ a1 r → S2RootOfAsidA Pp X σ a2 r → + BitVec.ofNat 16 a1.val = BitVec.ofNat 16 a2.val + /-- The Stage-1 forest property. -/ + inj1 : ∀ (tag tag' : U64) (sh sh' : Nat) (t t' i i' : U64), + VsPathA Pp S1 Y mem ksb tag sh t → S1TabA S1 Y t → 12 < sh → i.val < 512 → (mem (peAF t i) &&& 3#u64) = 3#u64 → + VsPathA Pp S1 Y mem ksb tag' sh' t' → S1TabA S1 Y t' → 12 < sh' → i'.val < 512 → + (mem (peAF t' i') &&& 3#u64) = 3#u64 → dTabA (mem (peAF t i)) = dTabA (mem (peAF t' i')) → + dTabA (mem (peAF t i)) ∈ S1 → peAF t i = peAF t' i' + /-- A Stage-1 / window root word is installed at one ASID. -/ + rootInj1 : ∀ a1 a2 raw : U64, ActiveAsidRootA mem ksb Pp a1 raw → ActiveAsidRootA mem ksb Pp a2 raw → a1 = a2 + /-- **A root cap is installed once** (A′): an unmapped root cap is the only root-kind cap of its root, which is + installed at no ASID (so `ARMASIDPoolAssign` keeps `rootInj1/2`). -/ + rootOnce : RootOnceA th Pp X mem ksb σ + /-- An unmapped `PageTable` cap is the only `PageTable` cap of its table. -/ + ptOnce : PtOnceA th mem + +/-- The forest fields of `VsUniqA` (the cap-free part). -/ +structure VsForestA (Pp S1 X Y T2 : Set U64) (Sh2 : U64 → Nat) (mem : U64 → U64) (ksb : U64) + (σ : Fl4SpecA64.State Unit) : Prop where + inj2 : ∀ w1 w2, S2EntryA Pp X T2 Sh2 mem σ w1 → S2EntryA Pp X T2 Sh2 mem σ w2 → + (mem w1 &&& 3#u64) = 3#u64 → (mem w2 &&& 3#u64) = 3#u64 → dTabA (mem w1) = dTabA (mem w2) → + dTabA (mem w1) ∈ T2 → w1 = w2 + rootInj2 : ∀ a1 a2 r : U64, S2RootOfAsidA Pp X σ a1 r → S2RootOfAsidA Pp X σ a2 r → + BitVec.ofNat 16 a1.val = BitVec.ofNat 16 a2.val + inj1 : ∀ (tag tag' : U64) (sh sh' : Nat) (t t' i i' : U64), + VsPathA Pp S1 Y mem ksb tag sh t → S1TabA S1 Y t → 12 < sh → i.val < 512 → (mem (peAF t i) &&& 3#u64) = 3#u64 → + VsPathA Pp S1 Y mem ksb tag' sh' t' → S1TabA S1 Y t' → 12 < sh' → i'.val < 512 → + (mem (peAF t' i') &&& 3#u64) = 3#u64 → dTabA (mem (peAF t i)) = dTabA (mem (peAF t' i')) → + dTabA (mem (peAF t i)) ∈ S1 → peAF t i = peAF t' i' + rootInj1 : ∀ a1 a2 raw : U64, ActiveAsidRootA mem ksb Pp a1 raw → ActiveAsidRootA mem ksb Pp a2 raw → a1 = a2 + +theorem S2ReachA.empty_false {T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {σ : Fl4SpecA64.State Unit} {q : U64} + (h : S2ReachA (∅ : Set U64) ∅ T2 Sh2 mem σ q) : False := by + induction h with + | root ha => exact Set.notMem_empty _ ha.1 + | stepRoot ha => exact Set.notMem_empty _ ha.1 + | stepPt _ _ _ _ _ _ ih => exact ih + +theorem VsPathA.empty_false {Tb Y : Set U64} {mem : U64 → U64} {ksb tag : U64} {sh : Nat} {q : U64} + (h : VsPathA (∅ : Set U64) Tb Y mem ksb tag sh q) : False := by + induction h with + | native hact => obtain ⟨-, -, -, -, -, pool, hp, -⟩ := hact; exact Set.notMem_empty _ hp + | high hact => obtain ⟨-, -, -, -, -, pool, hp, -⟩ := hact; exact Set.notMem_empty _ hp + | child _ _ _ _ _ ih => exact ih + +/-- **No active pools or Stage-2 roots** (the boot worlds): every forest field is vacuous. -/ +theorem VsForestA.empty {S1 Y T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {ksb : U64} + {σ : Fl4SpecA64.State Unit} : VsForestA (∅ : Set U64) S1 ∅ Y T2 Sh2 mem ksb σ where + inj2 w1 w2 h1 := by + rcases h1 with ⟨r, i, ha, -⟩ | ⟨t, i, hr, -⟩ + · exact absurd ha.1 (Set.notMem_empty _) + · exact hr.empty_false.elim + rootInj2 a1 a2 r h1 := absurd h1.1 (Set.notMem_empty _) + inj1 tag tag' sh sh' t t' i i' p1 := p1.empty_false.elim + rootInj1 a1 a2 raw h1 := by + obtain ⟨-, -, -, -, -, pool, hp, -⟩ := h1 + exact absurd hp (Set.notMem_empty _) + +/-- No slot holds a page-table cap (the boot witnesses), given the forest part. -/ +theorem VsUniqA.ofNoPt (h : ∀ y, IsSlotA th y → ∀ ptr asid va : U64, ∀ mp : Bool, + capAtA mem y ≠ .PageTable ptr mp asid va) + (hr : ∀ y, IsSlotA th y → ∀ r, ¬ RootUnmA r (capAtA mem y)) (F : VsForestA Pp S1 X Y T2 Sh2 mem ksb σ) : + VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ where + t2 y hy ptr asid va hc := (h y hy ptr asid va true hc).elim + s1 y hy ptr asid va hc := (h y hy ptr asid va true hc).elim + out y hy ptr asid va hc := (h y hy ptr asid va false hc).elim + inj2 := F.inj2 + rootInj2 := F.rootInj2 + inj1 := F.inj1 + rootInj1 := F.rootInj1 + rootOnce y hy r h := (hr y hy r h).elim + ptOnce y hy r := fun ⟨a, v, e⟩ => (h y hy r a v false e).elim + +theorem VsUniqA.forest (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) : VsForestA Pp S1 X Y T2 Sh2 mem ksb σ := + ⟨U.inj2, U.rootInj2, U.inj1, U.rootInj1⟩ + +theorem S2EntryA.foot {w : U64} (hxal : ∀ r ∈ X, 8192 ∣ r.val) (h : S2EntryA Pp X T2 Sh2 mem σ w) : + ExtFootE X Y T2 w := by + rcases h with ⟨r, i, hr, hi, rfl⟩ | ⟨t, i, -, ht, -, hi, rfl⟩ + · have hi1k : i.val < 1024 := by + unfold Fl4SpecA64.s2Geom Fl4SpecA64.s2GeomOf at hi + split_ifs at hi <;> dsimp only at hi <;> omega + exact rootFootE hr.1 (hxal r hr.1) hi1k + · exact .s2pt t i ht hi + +theorem S2EntryA.of_frame {mem' : U64 → U64} {σ' : Fl4SpecA64.State Unit} {w : U64} + (hxal : ∀ r ∈ X, 8192 ∣ r.val) (h : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) + (ht : σ'.archState.armAsidTable = σ.archState.armAsidTable) + (hkP : ∀ p ∈ Pp, σ'.kheap (specPtr p) = σ.kheap (specPtr p)) + (hw : S2EntryA Pp X T2 Sh2 mem' σ' w) : S2EntryA Pp X T2 Sh2 mem σ w := by + rcases hw with ⟨r, i, hr, hi, e⟩ | ⟨t, i, hr, ht2, h12, hi, e⟩ + · exact Or.inl ⟨r, i, hr.of_spec ht hkP, hi, e⟩ + · exact Or.inr ⟨t, i, (hr.of_mem hxal h).of_spec ht hkP, ht2, h12, hi, e⟩ + +end rel + +theorem walkIdx_val (va : U64) (sh n : Nat) (hn : 0 < n) (hn2 : n ≤ 2 ^ 64) : + (walkIdx va sh n).val = va.val / 2 ^ sh % n := by + show (BitVec.ofNat 64 _).toNat = _ + rw [BitVec.toNat_ofNat] + exact Nat.mod_eq_of_lt (Nat.lt_of_lt_of_le (Nat.mod_lt _ hn) hn2) + +theorem walkIdx_lt (va : U64) (sh n : Nat) (hn : 0 < n) (hn2 : n ≤ 2 ^ 64) : (walkIdx va sh n).val < n := by + rw [walkIdx_val va sh n hn hn2]; exact Nat.mod_lt _ hn + +theorem s2Top1k : Fl4SpecA64.s2Geom.topMask + 1 ≤ 1024 := by + unfold Fl4SpecA64.s2Geom Fl4SpecA64.s2GeomOf + split_ifs <;> dsimp only <;> omega + +/-- A page-table cap that need not come from a slot: it names an untracked table, or it is unmapped and names no +Stage-2 table. -/ +def PtFreshA (S1 T2 : Set U64) (mp : Bool) (ptr : U64) : Prop := + (ptr ∉ S1 ∧ ptr ∉ T2) ∨ + -- TIGHTEN after S1 shrink: remove this disjunct (an unmap arm still keeps its Stage-1 table in `S1`). + (mp = false ∧ ptr ∉ T2) + +/-- **The page-table caps after a slot step were page-table caps before, or name untracked tables** (same content at +some slot, or `ptr ∉ S1 ∪ T2`: a freshly mapped table, an unmapped cap): every step that only copies, moves or deletes +caps satisfies it; so does a page-table map's cap write before the ghosts grow. -/ +def PtCapClosedA (th : TypedHeapA) (S1 T2 : Set U64) (mem mem' : U64 → U64) : Prop := + ∀ y, IsSlotA th y → ∀ ptr asid va : U64, ∀ mp : Bool, capAtA mem' y = .PageTable ptr mp asid va → + (∃ y0, IsSlotA th y0 ∧ capAtA mem y0 = .PageTable ptr mp asid va) ∨ PtFreshA S1 T2 mp ptr + +/-- **The VSpace caps after a step**: page-table caps closed (`PtCapClosedA`) and root-kind caps closed +(`RootClosedA`, A′). -/ +structure PtClosedA (th : TypedHeapA) (S1 T2 : Set U64) (mem mem' : U64 → U64) : Prop where + pt : PtCapClosedA th S1 T2 mem mem' + root : RootClosedA th mem mem' + ptu : PtUClosedA th mem mem' + +theorem RootClosedA.refl (th : TypedHeapA) (mem : U64 → U64) : RootClosedA th mem mem := UClosed.refl th mem + +/-- Every slot's cap unchanged, or no root-kind cap. -/ +theorem RootClosedA.of_cap {th : TypedHeapA} {mem mem' : U64 → U64} + (hc : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y ∨ NoRootKindA (capAtA mem' y)) : RootClosedA th mem mem' := UClosed.of_cap rootUCls hc + +theorem PtClosedA.refl (th : TypedHeapA) (S1 T2 : Set U64) (mem : U64 → U64) : PtClosedA th S1 T2 mem mem := + ⟨fun y hy _ _ _ _ h => Or.inl ⟨y, hy, h⟩, RootClosedA.refl th mem, (UClosed.refl th mem).toE⟩ + +/-- Caps unchanged or no page-table cap and no root-kind cap. -/ +theorem PtClosedA.of_cap {th : TypedHeapA} {S1 T2 : Set U64} {mem mem' : U64 → U64} + (hc : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y ∨ NoVsCapA (capAtA mem' y)) : + PtClosedA th S1 T2 mem mem' where + pt y hy ptr asid va mp h := by + rcases hc y hy with e | e + · exact Or.inl ⟨y, hy, e ▸ h⟩ + · exact (e.1 ptr asid va mp h).elim + root := RootClosedA.of_cap fun y hy => (hc y hy).imp id (fun e => e.2) + ptu := (UClosed.of_cap ptUCls fun y hy => (hc y hy).imp id (fun e => e.pt)).toE + +/-- **A cap about to be written is a page-table cap only if it already sits in a slot, or names an untracked table** +(a copy / move of a cap of the record; a derived cap of a kind derivation does not change; a table about to be +mapped). -/ +def PtSrcA (th : TypedHeapA) (S1 T2 : Set U64) (mem : U64 → U64) (c : capability.Cap) : Prop := + ∀ ptr asid va : U64, ∀ mp : Bool, c = .PageTable ptr mp asid va → + (∃ y0, IsSlotA th y0 ∧ capAtA mem y0 = c) ∨ PtFreshA S1 T2 mp ptr + +/-- A source at another memory whose slot caps agree. -/ +theorem PtSrcA.congr {th : TypedHeapA} {S1 T2 : Set U64} {mem mem' : U64 → U64} {c : capability.Cap} + (h : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y) (hp : PtSrcA th S1 T2 mem c) : + PtSrcA th S1 T2 mem' c := fun ptr asid va mp e => + (hp ptr asid va mp e).imp (fun ⟨y0, hy0, hc⟩ => ⟨y0, hy0, (h y0 hy0).trans hc⟩) id + +/-- A cap that is no page-table cap is a source. -/ +theorem PtSrcA.nopt {th : TypedHeapA} {S1 T2 : Set U64} {mem : U64 → U64} {c : capability.Cap} + (h : ∀ ptr asid va : U64, ∀ mp : Bool, c ≠ .PageTable ptr mp asid va) : PtSrcA th S1 T2 mem c := + fun ptr asid va mp e => (h ptr asid va mp e).elim + +/-- **A cap `c` written over `old` is root-kind (unmapped) only if `old` was** (a write that creates no root cap; the +Assign cap write has `old` unmapped, `c` mapped). -/ +def RootSetA (old c : capability.Cap) : Prop := + (∀ r, RootKindA r c → RootKindA r old) ∧ (∀ r, RootUnmA r c → RootUnmA r old) + +theorem RootSetA.of_noRoot {old c : capability.Cap} (h : NoRootKindA c) : RootSetA old c := + ⟨fun r hk => (h r hk).elim, fun r hu => (h r hu.kind).elim⟩ + +theorem RootSetA.refl (c : capability.Cap) : RootSetA c c := ⟨fun _ h => h, fun _ h => h⟩ + +/-- Discharges `RootSetA old c` for a `c` with a concrete non-root constructor (the `autoParam` of the cap-write +lemmas; a root-kind `c` (Assign, a copied root cap) passes the proof explicitly). -/ +macro "root_nr" : tactic => `(tactic| exact RootSetA.of_noRoot (fun r hk => by + rcases hk with ⟨_, _, h⟩ | ⟨_, _, _, h⟩ | ⟨_, _, h⟩ <;> cases h)) + +/-- The cap at a slot rewritten to `c`, the others kept. -/ +theorem PtCapClosedA.of_set {th : TypedHeapA} {S1 T2 : Set U64} {mem mem' : U64 → U64} {x : U64} {c : capability.Cap} + (hc : PtSrcA th S1 T2 mem c) (hcx : capAtA mem' x = c) + (hco : ∀ y, IsSlotA th y → y ≠ x → capAtA mem' y = capAtA mem y) : PtCapClosedA th S1 T2 mem mem' := + fun y hy ptr asid va mp h => by + by_cases hne : y = x + · subst hne + rw [hcx] at h + rcases hc ptr asid va mp h with ⟨y0, hy0, e⟩ | hu + · exact Or.inl ⟨y0, hy0, e.trans h⟩ + · exact Or.inr hu + · exact Or.inl ⟨y, hy, by rw [← hco y hy hne]; exact h⟩ + +/-- A slot after the step holds `Null`, its old cap, or `nc` (move, insert, swap): closed when `nc` is a source. -/ +theorem PtCapClosedA.of_three {th : TypedHeapA} {S1 T2 : Set U64} {mem mem' : U64 → U64} {nc : capability.Cap} + (hn : PtSrcA th S1 T2 mem nc) + (hcs : ∀ y, IsSlotA th y → capAtA mem' y = .Null ∨ capAtA mem' y = capAtA mem y ∨ capAtA mem' y = nc) : + PtCapClosedA th S1 T2 mem mem' := fun y hy ptr asid va mp h => by + rcases hcs y hy with e | e | e + · rw [e] at h; cases h + · exact Or.inl ⟨y, hy, by rw [← e]; exact h⟩ + · rw [e] at h + rcases hn ptr asid va mp h with ⟨y0, hy0, hc⟩ | hu + · exact Or.inl ⟨y0, hy0, hc.trans h⟩ + · exact Or.inr hu + +/-- Insert: a slot after the step holds its old cap, `nc`, or an Untyped cap. -/ +theorem PtCapClosedA.of_ins {th : TypedHeapA} {S1 T2 : Set U64} {mem mem' : U64 → U64} {nc : capability.Cap} + (hn : PtSrcA th S1 T2 mem nc) + (hcs : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y ∨ capAtA mem' y = nc ∨ + ∃ p b i e, capAtA mem' y = .Untyped p b i e) : + PtCapClosedA th S1 T2 mem mem' := fun y hy ptr asid va mp h => by + rcases hcs y hy with e | e | ⟨p, b, i, e', e⟩ + · exact Or.inl ⟨y, hy, by rw [← e]; exact h⟩ + · rw [e] at h + rcases hn ptr asid va mp h with ⟨y0, hy0, hc⟩ | hu + · exact Or.inl ⟨y0, hy0, hc.trans h⟩ + · exact Or.inr hu + · rw [e] at h; cases h + +/-- Swap: a slot after the step holds its old cap, `c1` or `c2`. -/ +theorem PtCapClosedA.of_swap {th : TypedHeapA} {S1 T2 : Set U64} {mem mem' : U64 → U64} {c1 c2 : capability.Cap} + (h1 : PtSrcA th S1 T2 mem c1) (h2 : PtSrcA th S1 T2 mem c2) + (hcs : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y ∨ capAtA mem' y = c1 ∨ capAtA mem' y = c2) : + PtCapClosedA th S1 T2 mem mem' := fun y hy ptr asid va mp h => by + rcases hcs y hy with e | e | e + · exact Or.inl ⟨y, hy, by rw [← e]; exact h⟩ + · rw [e] at h + rcases h1 ptr asid va mp h with ⟨y0, hy0, hc⟩ | hu + · exact Or.inl ⟨y0, hy0, hc.trans h⟩ + · exact Or.inr hu + · rw [e] at h + rcases h2 ptr asid va mp h with ⟨y0, hy0, hc⟩ | hu + · exact Or.inl ⟨y0, hy0, hc.trans h⟩ + · exact Or.inr hu + +/-- Two root-closed steps compose. -/ +theorem RootClosedA.trans {th : TypedHeapA} {m0 m1 m2 : U64 → U64} (h1 : RootClosedA th m0 m1) + (h2 : RootClosedA th m1 m2) : RootClosedA th m0 m2 := UClosed.trans h1 h2 + +/-- **Root-kind caps only where they were** (a step that rewrites no root-kind cap into existence). -/ +theorem RootClosedA.pos {th : TypedHeapA} {mem mem' : U64 → U64} + (hU : ∀ y, IsSlotA th y → ∀ r, RootUnmA r (capAtA mem' y) → RootUnmA r (capAtA mem y)) + (hK : ∀ y, IsSlotA th y → ∀ r, RootKindA r (capAtA mem' y) → RootKindA r (capAtA mem y)) : + RootClosedA th mem mem' := UClosed.pos hU hK + +/-- A cap written at `x` (the others kept) is root-kind of `r` only when the cap it replaces is, and unmapped only +when that is. -/ +theorem RootClosedA.of_set {th : TypedHeapA} {mem mem' : U64 → U64} {x : U64} {c : capability.Cap} + (hcx : capAtA mem' x = c) (hco : ∀ y, IsSlotA th y → y ≠ x → capAtA mem' y = capAtA mem y) + (hk : ∀ r, RootKindA r c → RootKindA r (capAtA mem x)) + (hu : ∀ r, RootUnmA r c → RootUnmA r (capAtA mem x)) : RootClosedA th mem mem' := UClosed.of_set hcx hco hk hu + +/-- A step that permutes the slots (`π` a bijection of slots): every root-kind cap after is the cap of its `π`-image +before (the other caps are arbitrary but not root-kind). -/ +theorem RootClosedA.of_perm {th : TypedHeapA} {mem mem' : U64 → U64} {π : U64 → U64} + (hπ : ∀ y, IsSlotA th y → IsSlotA th (π y) ∧ ∀ r, RootKindA r (capAtA mem' y) → capAtA mem' y = capAtA mem (π y)) + (hinj : ∀ y z, IsSlotA th y → IsSlotA th z → π y = π z → y = z) : RootClosedA th mem mem' := UClosed.of_perm rootUCls hπ hinj + +/-- A swap of the slots `a ≠ b` writing `c2` at `a` and `c1` at `b` (root-kind `c1`, `c2` are the caps they came from). -/ +theorem RootClosedA.of_swapC {th : TypedHeapA} {mem mem' : U64 → U64} {a b : U64} {c1 c2 : capability.Cap} + (ha : IsSlotA th a) (hb : IsSlotA th b) + (h1 : capAtA mem' a = c2) (h2 : capAtA mem' b = c1) + (ho : ∀ y, IsSlotA th y → y ≠ a → y ≠ b → capAtA mem' y = capAtA mem y) + (hk1 : ∀ r, RootKindA r c1 → c1 = capAtA mem a) (hk2 : ∀ r, RootKindA r c2 → c2 = capAtA mem b) : + RootClosedA th mem mem' := UClosed.of_swapC rootUCls ha hb h1 h2 ho hk1 hk2 + +/-- Two slots exchange their caps (a move onto a `Null` slot, a swap), the others kept. -/ +theorem RootClosedA.of_exch {th : TypedHeapA} {mem mem' : U64 → U64} {a b : U64} (ha : IsSlotA th a) (hb : IsSlotA th b) + (h1 : capAtA mem' a = capAtA mem b) (h2 : capAtA mem' b = capAtA mem a) + (ho : ∀ y, IsSlotA th y → y ≠ a → y ≠ b → capAtA mem' y = capAtA mem y) : RootClosedA th mem mem' := UClosed.of_exch rootUCls ha hb h1 h2 ho + +/-- A move: `ss` becomes `Null`, `sd` holds `nc`, the others kept; a root-kind `nc` has a root-kind source at `ss` +of the same unmappedness. -/ +theorem RootClosedA.of_mv {th : TypedHeapA} {mem mem' : U64 → U64} {ss sd : U64} {nc : capability.Cap} + (h1 : capAtA mem' ss = .Null) (h2 : capAtA mem' sd = nc) (hss : IsSlotA th ss) + (ho : ∀ y, IsSlotA th y → y ≠ ss → y ≠ sd → capAtA mem' y = capAtA mem y) + (hk : ∀ r, RootKindA r nc → RootKindA r (capAtA mem ss)) + (hu : ∀ r, RootUnmA r nc → RootUnmA r (capAtA mem ss)) : RootClosedA th mem mem' := UClosed.of_mv rootUCls h1 h2 hss ho hk hu + +/-- A cap `nc` is inserted (copy / mint): the others are kept (or become Untyped). `nc` is never unmapped, and a +root-kind `nc` has a mapped root-kind source (`derive_cap` refuses unmapped root caps). -/ +theorem RootClosedA.of_copy {th : TypedHeapA} {mem mem' : U64 → U64} {nc : capability.Cap} + (hcs : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y ∨ capAtA mem' y = nc ∨ + ∃ p b i e, capAtA mem' y = .Untyped p b i e) + (hn : ∀ r, ¬ RootUnmA r nc) + (hs : ∀ r, RootKindA r nc → ∃ s0, IsSlotA th s0 ∧ RootKindA r (capAtA mem s0) ∧ ¬ RootUnmA r (capAtA mem s0)) : + RootClosedA th mem mem' := UClosed.of_copy rootUCls hcs hn hs + +/-- **`derive_cap`'s facts of a derived cap** (`derive_cap` refuses unmapped root caps and unmapped page-table caps; a +root-kind or page-table cap comes out only as it went in): `nc` is a table-kind cap only as the source `c`, and is no +unmapped one. -/ +structure RootDerivA (nc c : capability.Cap) : Prop where + rk : ∀ r, RootKindA r nc → nc = c + ru : ∀ r, ¬ RootUnmA r nc + pk : ∀ r, PtKindA r nc → nc = c + pu : ∀ r, ¬ PtUnmA r nc + +/-- The P1 view (`RootCapK` / `RootCapU` cover both classes). -/ +theorem RootKindA.to_p1 {r : U64} {c : capability.Cap} (h : RootKindA r c) : W7.R.ST.RootCapK c := by + rcases h with ⟨m, a, e⟩ | ⟨m, a, v, e⟩ | ⟨m, a, e⟩ + · exact Or.inl ⟨_, m, a, e⟩ + · exact Or.inr (Or.inl ⟨_, m, a, v, e⟩) + · exact Or.inr (Or.inr (Or.inl ⟨_, m, a, e⟩)) + +theorem RootUnmA.to_p1 {r : U64} {c : capability.Cap} (h : RootUnmA r c) : W7.R.ST.RootCapU c := by + rcases h with ⟨a, e⟩ | ⟨a, v, e⟩ | ⟨a, e⟩ + · exact Or.inl ⟨_, a, e⟩ + · exact Or.inr (Or.inl ⟨_, a, v, e⟩) + · exact Or.inr (Or.inr (Or.inl ⟨_, a, e⟩)) + +theorem PtKindA.to_p1 {r : U64} {c : capability.Cap} (h : PtKindA r c) : W7.R.ST.RootCapK c := by + obtain ⟨m, a, v, e⟩ := h; exact Or.inr (Or.inr (Or.inr ⟨_, m, a, v, e⟩)) + +theorem PtUnmA.to_p1 {r : U64} {c : capability.Cap} (h : PtUnmA r c) : W7.R.ST.RootCapU c := by + obtain ⟨a, v, e⟩ := h; exact Or.inr (Or.inr (Or.inr ⟨_, a, v, e⟩)) + +theorem RootDerivA.of_p1 {nc c : capability.Cap} (h : W7.R.ST.RootDerA nc c) : RootDerivA nc c := + ⟨fun _ hk => h.1 hk.to_p1, fun _ hu => h.2 hu.to_p1, fun _ hk => h.1 hk.to_p1, fun _ hu => h.2 hu.to_p1⟩ + +theorem RootDerivA.of_no {nc c : capability.Cap} (h : NoRootKindA nc) (hp : NoPtKindA nc) : RootDerivA nc c := + ⟨fun r hk => absurd hk (h r), fun r hu => h r hu.kind, fun r hk => absurd hk (hp r), fun r hu => hp r hu.kind⟩ + +/-- A copy / mint's new cap `nc` against the slot caps `mem` (the premise of `RootClosedA.of_copy`): no unmapped +table-kind cap, and each table-kind cap of `nc` already sits mapped in a slot. -/ +structure RootCopyA (th : TypedHeapA) (mem : U64 → U64) (nc : capability.Cap) : Prop where + ru : ∀ r, ¬ RootUnmA r nc + rk : ∀ r, RootKindA r nc → ∃ s0, IsSlotA th s0 ∧ RootKindA r (capAtA mem s0) ∧ ¬ RootUnmA r (capAtA mem s0) + pu : ∀ r, ¬ PtUnmA r nc + pk : ∀ r, PtKindA r nc → ∃ s0, IsSlotA th s0 ∧ PtKindA r (capAtA mem s0) ∧ ¬ PtUnmA r (capAtA mem s0) + +/-- The derive facts at the source slot give `RootCopyA`. -/ +theorem RootCopyA.of_der {th : TypedHeapA} {mem : U64 → U64} {src : U64} {nc : capability.Cap} + (hsS : IsSlotA th src) (h : RootDerivA nc (capAtA mem src)) : RootCopyA th mem nc := + ⟨h.ru, fun r hk => ⟨src, hsS, (h.rk r hk) ▸ hk, (h.rk r hk) ▸ h.ru r⟩, h.pu, + fun r hk => ⟨src, hsS, (h.pk r hk) ▸ hk, (h.pk r hk) ▸ h.pu r⟩⟩ + +/-- A new cap that is no table-kind cap. -/ +theorem RootCopyA.of_no {th : TypedHeapA} {mem : U64 → U64} {nc : capability.Cap} (h : NoRootKindA nc) + (hp : NoPtKindA nc) : RootCopyA th mem nc := + ⟨fun r hu => h r hu.kind, fun r hk => absurd hk (h r), fun r hu => hp r hu.kind, fun r hk => absurd hk (hp r)⟩ + +/-- A move's new cap `nc` against the source cap `c`: a table-kind (unmapped) cap of `nc` is one of `c`. -/ +structure RootMvA (nc c : capability.Cap) : Prop where + rk : ∀ r, RootKindA r nc → RootKindA r c + ru : ∀ r, RootUnmA r nc → RootUnmA r c + pk : ∀ r, PtKindA r nc → PtKindA r c + pu : ∀ r, PtUnmA r nc → PtUnmA r c + +theorem RootMvA.of_der {nc c : capability.Cap} (h : ∀ r, RootKindA r nc → nc = c) + (hp : ∀ r, PtKindA r nc → nc = c) : RootMvA nc c := + ⟨fun r hk => h r hk ▸ hk, fun r hu => h r hu.kind ▸ hu, fun r hk => hp r hk ▸ hk, fun r hu => hp r hu.kind ▸ hu⟩ + +/-- **A cap `c` written over `old` is a `PageTable` cap (unmapped) only if `old` was** (the page-table twin of +`RootSetA`; the page-table map has `old` unmapped, `c` mapped). -/ +def PtSetA (old c : capability.Cap) : Prop := + (∀ r, PtKindA r c → PtKindA r old) ∧ (∀ r, PtUnmA r c → PtUnmA r old) + +theorem PtSetA.of_noPt {old c : capability.Cap} (h : NoPtKindA c) : PtSetA old c := + ⟨fun r hk => (h r hk).elim, fun r hu => (h r hu.kind).elim⟩ + +theorem PtSetA.refl (c : capability.Cap) : PtSetA c c := ⟨fun _ h => h, fun _ h => h⟩ + +/-- **A write of an unmapped page-table cap over an unmapped one of the same table.** -/ +theorem PtSetA.unm {old : capability.Cap} {ptr asid0 va0 asid1 va1 : U64} + (h : old = .PageTable ptr false asid0 va0) : PtSetA old (.PageTable ptr false asid1 va1) := + ⟨fun r hk => by obtain ⟨_, _, _, e⟩ := hk; cases e; exact ⟨_, _, _, h⟩, + fun r hu => by obtain ⟨_, _, e⟩ := hu; cases e; exact ⟨_, _, h⟩⟩ + +/-- **A page-table map**: the old cap is a `PageTable ptr` cap, the new cap the mapped `PageTable ptr` cap. -/ +theorem PtSetA.map {old : capability.Cap} {ptr asid0 va0 asid1 va1 : U64} {mp : Bool} + (h : old = .PageTable ptr mp asid0 va0) : PtSetA old (.PageTable ptr true asid1 va1) := + ⟨fun r hk => by obtain ⟨_, _, _, e⟩ := hk; cases e; exact ⟨_, _, _, h⟩, + fun r hu => by obtain ⟨_, _, e⟩ := hu; cases e⟩ + +/-- **The page-table cap write at `x`**: `PtSetA` (a write that creates no unmapped page-table cap), or **the unmap of the +unique holder**: a `PageTable` cap of `c` was one at `x`, and when `c` is unmapped no other slot holds a `PageTable` cap +of its table (`cdt::is_final_capability`, so the new unmapped cap is the only one). -/ +def PtSetE (th : TypedHeapA) (mem : U64 → U64) (x : U64) (c : capability.Cap) : Prop := + PtSetA (capAtA mem x) c ∨ ((∀ r, PtKindA r c → PtKindA r (capAtA mem x)) ∧ + ∀ r, PtUnmA r c → ∀ y, IsSlotA th y → y ≠ x → ¬ PtKindA r (capAtA mem y)) + +/-- **The unmap of the unique holder** of a mapped `PageTable ptr` cap at `x`, to the unmapped `PageTable ptr` cap. -/ +theorem PtSetE.unmapHolder {th : TypedHeapA} {mem : U64 → U64} {x : U64} {ptr asid va : U64} + (hcapx : capAtA mem x = .PageTable ptr true asid va) + (hno : ∀ y, IsSlotA th y → y ≠ x → ∀ (mp : Bool) (a v : U64), capAtA mem y ≠ .PageTable ptr mp a v) : + PtSetE th mem x (.PageTable ptr false 0#u64 0#u64) := + Or.inr ⟨fun r hk => by obtain ⟨_, _, _, e⟩ := hk; cases e; rw [hcapx]; exact ⟨true, asid, va, rfl⟩, + fun r hu y hy hne hk => by + obtain ⟨_, _, e⟩ := hu; cases e + obtain ⟨mp, a, v, e'⟩ := hk; exact hno y hy hne mp a v e'⟩ + +/-- The same at a memory whose slot caps agree. -/ +theorem PtSetE.congr {th : TypedHeapA} {mem mem' : U64 → U64} {x : U64} {c : capability.Cap} + (h : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y) (hx : IsSlotA th x) (hp : PtSetE th mem x c) : + PtSetE th mem' x c := by + rcases hp with hp | ⟨hk, hu⟩ + · exact Or.inl (by rw [h x hx]; exact hp) + · exact Or.inr ⟨fun r h' => by rw [h x hx]; exact hk r h', + fun r h' y hy hne => by rw [h y hy]; exact hu r h' y hy hne⟩ + +/-- Discharges `PtSetA old c` for a `c` with a concrete non-`PageTable` constructor (the `autoParam` of the cap-write +lemmas; a `PageTable` cap `c` passes the proof explicitly). -/ +macro "pt_nr" : tactic => `(tactic| exact Or.inl (PtSetA.of_noPt (fun r hk => by obtain ⟨_, _, _, h⟩ := hk; cases h))) + +/-- The `PtClosedA` of a single slot write `c` at `x` (the others kept). -/ +theorem PtClosedA.of_set {th : TypedHeapA} {S1 T2 : Set U64} {mem mem' : U64 → U64} {x : U64} {c : capability.Cap} + (hc : PtSrcA th S1 T2 mem c) (hcx : capAtA mem' x = c) + (hco : ∀ y, IsSlotA th y → y ≠ x → capAtA mem' y = capAtA mem y) (hr : RootSetA (capAtA mem x) c := by root_nr) + (hp : PtSetE th mem x c := by pt_nr) : + PtClosedA th S1 T2 mem mem' := + ⟨PtCapClosedA.of_set hc hcx hco, RootClosedA.of_set hcx hco hr.1 hr.2, + hp.elim (fun hp => (UClosed.of_set hcx hco hp.1 hp.2).toE) + (fun ⟨hk, hu⟩ => UClosedE.of_set_esc hcx hco hk hu)⟩ + +/-- **Both table classes' step obligations** (root kinds and page tables): the sites' one-call constructors. -/ +structure TabClosedA (th : TypedHeapA) (mem mem' : U64 → U64) : Prop where + root : RootClosedA th mem mem' + pts : UClosed PtKindA PtUnmA th mem mem' + +theorem TabClosedA.trans {th : TypedHeapA} {m0 m1 m2 : U64 → U64} (h1 : TabClosedA th m0 m1) (h2 : TabClosedA th m1 m2) : + TabClosedA th m0 m2 := ⟨UClosed.trans h1.root h2.root, UClosed.trans h1.pts h2.pts⟩ + +theorem PtClosedA.ofTab {th : TypedHeapA} {S1 T2 : Set U64} {mem mem' : U64 → U64} (hpt : PtCapClosedA th S1 T2 mem mem') + (tc : TabClosedA th mem mem') : PtClosedA th S1 T2 mem mem' := ⟨hpt, tc.root, tc.pts.toE⟩ + +theorem TabClosedA.of_mv {th : TypedHeapA} {mem mem' : U64 → U64} {ss sd : U64} {nc : capability.Cap} + (h1 : capAtA mem' ss = .Null) (h2 : capAtA mem' sd = nc) (hss : IsSlotA th ss) + (ho : ∀ y, IsSlotA th y → y ≠ ss → y ≠ sd → capAtA mem' y = capAtA mem y) + (hr : RootMvA nc (capAtA mem ss)) : TabClosedA th mem mem' := + ⟨UClosed.of_mv rootUCls h1 h2 hss ho hr.rk hr.ru, UClosed.of_mv ptUCls h1 h2 hss ho hr.pk hr.pu⟩ + +theorem TabClosedA.of_copy {th : TypedHeapA} {mem mem' : U64 → U64} {nc : capability.Cap} + (hcs : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y ∨ capAtA mem' y = nc ∨ + ∃ p b i e, capAtA mem' y = .Untyped p b i e) + (hr : RootCopyA th mem nc) : TabClosedA th mem mem' := + ⟨UClosed.of_copy rootUCls hcs hr.ru hr.rk, UClosed.of_copy ptUCls hcs hr.pu hr.pk⟩ + +theorem TabClosedA.of_exch {th : TypedHeapA} {mem mem' : U64 → U64} {a b : U64} (ha : IsSlotA th a) (hb : IsSlotA th b) + (h1 : capAtA mem' a = capAtA mem b) (h2 : capAtA mem' b = capAtA mem a) + (ho : ∀ y, IsSlotA th y → y ≠ a → y ≠ b → capAtA mem' y = capAtA mem y) : TabClosedA th mem mem' := + ⟨UClosed.of_exch rootUCls ha hb h1 h2 ho, UClosed.of_exch ptUCls ha hb h1 h2 ho⟩ + +/-- The table-kind caps of `nc` are `c` itself (both classes). -/ +def KindEqA (nc c : capability.Cap) : Prop := (∀ r, RootKindA r nc → nc = c) ∧ ∀ r, PtKindA r nc → nc = c + +theorem RootMvA.of_kindEq {nc c : capability.Cap} (h : KindEqA nc c) : RootMvA nc c := RootMvA.of_der h.1 h.2 + +/-- A rotation `sd ← sp ← ss ← Null` (module `CnodeRotA`). -/ +theorem TabClosedA.of_rot {th : TypedHeapA} {mem mem' : U64 → U64} {sd sp ss : U64} {np ns : capability.Cap} + (hdS : IsSlotA th sd) (hpS : IsSlotA th sp) (hsS : IsSlotA th ss) + (hdp : sd ≠ sp) (hds : sd ≠ ss) (hps : sp ≠ ss) + (cd : capAtA mem' sd = np) (cp : capAtA mem' sp = ns) (cs : capAtA mem' ss = .Null) + (co : ∀ y, IsSlotA th y → y ≠ sd → y ≠ sp → y ≠ ss → capAtA mem' y = capAtA mem y) + (hrp : KindEqA np (capAtA mem sp)) (hrs : KindEqA ns (capAtA mem ss)) : TabClosedA th mem mem' := + ⟨UClosed.of_rot rootUCls hdS hpS hsS hdp hds hps cd cp cs co hrp.1 hrs.1, + UClosed.of_rot ptUCls hdS hpS hsS hdp hds hps cd cp cs co hrp.2 hrs.2⟩ + +/-- A swap of the slots `a ≠ b` writing `c2` at `a` and `c1` at `b`; table-kind `c1`, `c2` are the caps they came from. -/ +theorem TabClosedA.of_swapC {th : TypedHeapA} {mem mem' : U64 → U64} {a b : U64} {c1 c2 : capability.Cap} + (ha : IsSlotA th a) (hb : IsSlotA th b) + (h1 : capAtA mem' a = c2) (h2 : capAtA mem' b = c1) + (ho : ∀ y, IsSlotA th y → y ≠ a → y ≠ b → capAtA mem' y = capAtA mem y) + (hk1 : ∀ r, RootKindA r c1 → c1 = capAtA mem a) (hk2 : ∀ r, RootKindA r c2 → c2 = capAtA mem b) + (hp1 : ∀ r, PtKindA r c1 → c1 = capAtA mem a) (hp2 : ∀ r, PtKindA r c2 → c2 = capAtA mem b) : + TabClosedA th mem mem' := + ⟨UClosed.of_swapC rootUCls ha hb h1 h2 ho hk1 hk2, UClosed.of_swapC ptUCls ha hb h1 h2 ho hp1 hp2⟩ + +/-- The pools and the ASID table kept. -/ +def PoolKeepA (Pp : Set U64) (σ σ' : Fl4SpecA64.State Unit) : Prop := + σ'.archState.armAsidTable = σ.archState.armAsidTable ∧ ∀ p ∈ Pp, σ'.kheap (specPtr p) = σ.kheap (specPtr p) + +section frame +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem mem' : U64 → U64} {ksb : U64} + {σ σ' : Fl4SpecA64.State Unit} + +theorem S2RootOfAsidA.of_spec {asid r : U64} + (ht : σ'.archState.armAsidTable = σ.archState.armAsidTable) + (hkP : ∀ p ∈ Pp, σ'.kheap (specPtr p) = σ.kheap (specPtr p)) (h : S2RootOfAsidA Pp X σ asid r) : + S2RootOfAsidA Pp X σ' asid r := by + obtain ⟨hr, p, f, h0, hp, htab, hk, hf⟩ := h + exact ⟨hr, p, f, h0, hp, by rw [ht]; exact htab, by rw [hkP p hp]; exact hk, hf⟩ + +/-- **`VsUniqA` across a step that keeps the ghosts**: words kept on the footprints, the ASID table and the pools kept, +every slot's cap unchanged or no page-table cap. -/ +theorem VsUniqA.of_frame (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (hm : ∀ b, ExtFootE X Y T2 b ∨ VsFootA Pp S1 Y ksb b → mem' b = mem b) + (hP : PoolKeepA Pp σ σ') (hc : PtClosedA th S1 T2 mem mem') : + VsUniqA th Pp S1 X Y T2 Sh2 mem' ksb σ' where + t2 y hy ptr asid va hcap hT w hw h3 hd := by + obtain ⟨yc, hyc, hcap0⟩ := (hc.pt y hy ptr asid va true hcap).resolve_right (fun h => h.elim (fun h => h.2 hT) (fun h => h.2 hT)) + have hw0 := S2EntryA.of_frame hxal (fun b hb => hm b (Or.inl hb)) hP.1 hP.2 hw + have hf : mem' w = mem w := hm w (Or.inl (hw0.foot hxal)) + rw [hf] at h3 hd + obtain ⟨r, hr, hws⟩ := U.t2 yc hyc ptr asid va hcap0 hT w hw0 h3 hd + refine ⟨r, hr.of_spec hP.1 hP.2, hws.of_mem' ?_⟩ + intro t' sh' n' hh + apply hm _ (Or.inl _) + rcases hh with ⟨rfl, rfl⟩ | ⟨ht', rfl⟩ + · exact rootFootE hr.1 (hxal _ hr.1) + (Nat.lt_of_lt_of_le (walkIdx_lt va sh' _ (Nat.succ_pos _) (Nat.le_trans s2Top1k (by norm_num))) s2Top1k) + · exact .s2pt t' _ ht' (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + s1 y hy ptr asid va hcap hS tag sh t i hpath htab h12 hi h3 hd := by + obtain ⟨yc, hyc, hcap0⟩ := (hc.pt y hy ptr asid va true hcap).resolve_right (fun h => h.elim (fun h => h.1 hS) (fun h => by cases h.1)) + have hv : ∀ b, VsFootA Pp S1 Y ksb b → mem' b = mem b := fun b hb => hm b (Or.inr hb) + have path0 := hpath.of_mem hv + have hf : mem' (peAF t i) = mem (peAF t i) := by + rcases htab with ht | ⟨y0, hy0, rfl⟩ + · exact hv _ (.pt t i ht hi) + · exact hv _ (.high y0 i hy0 hi) + rw [hf] at h3 hd + obtain ⟨raw, hact, hw⟩ := U.s1 yc hyc ptr asid va hcap0 hS tag sh t i path0 htab h12 hi h3 hd + have hact' : ActiveAsidRootA mem' ksb Pp asid raw := + ActiveAsidRootA.of_mem (mem := mem') (mem' := mem) (Tb := S1) (Y := Y) + (fun b hb => (hv b hb).symm) hact + have hS1f : ∀ t' sh', S1TabA S1 Y t' → + mem' (peAF t' (walkIdx va sh' 512)) = mem (peAF t' (walkIdx va sh' 512)) := by + intro t' sh' h + have hl := walkIdx_lt va sh' 512 (by norm_num) (by norm_num) + rcases h with ht | ⟨y0, hy0, rfl⟩ + · exact hv _ (.pt t' _ ht hl) + · exact hv _ (.high y0 _ hy0 hl) + refine ⟨raw, hact', ?_⟩ + rcases hw with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · refine Or.inl ⟨h0, hr, hws.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inl hr) + · exact hS1f _ _ h + · refine Or.inr ⟨h2, hy2, hws.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inr ⟨untagA raw, hy2, rfl⟩) + · exact hS1f _ _ h + out y hy ptr asid va hcap := by + rcases hc.pt y hy ptr asid va false hcap with ⟨yc, hyc, hcap0⟩ | hu + · exact U.out yc hyc ptr asid va hcap0 + · exact hu.elim (fun h => h.2) (fun h => h.2) + inj2 w1 w2 h1 h2 v1 v2 hd hT := by + have h1' := S2EntryA.of_frame hxal (fun b hb => hm b (Or.inl hb)) hP.1 hP.2 h1 + have h2' := S2EntryA.of_frame hxal (fun b hb => hm b (Or.inl hb)) hP.1 hP.2 h2 + have f1 : mem' w1 = mem w1 := hm w1 (Or.inl (h1'.foot hxal)) + have f2 : mem' w2 = mem w2 := hm w2 (Or.inl (h2'.foot hxal)) + rw [f1] at v1 hd hT + rw [f2] at v2 hd + exact U.inj2 w1 w2 h1' h2' v1 v2 hd hT + rootInj2 a1 a2 r h1 h2 := + U.rootInj2 a1 a2 r (S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h1) + (S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h2) + inj1 tag tag' sh sh' t t' i i' p1 tb1 h12 hi v1 p2 tb2 h12' hi' v2 hd hS := by + have hv : ∀ b, VsFootA Pp S1 Y ksb b → mem' b = mem b := fun b hb => hm b (Or.inr hb) + have hf : ∀ t i, S1TabA S1 Y t → i.val < 512 → mem' (peAF t i) = mem (peAF t i) := by + intro t i htb hi + rcases htb with ht | ⟨y0, hy0, rfl⟩ + · exact hv _ (.pt t i ht hi) + · exact hv _ (.high y0 i hy0 hi) + rw [hf t i tb1 hi] at v1 hd hS + rw [hf t' i' tb2 hi'] at v2 hd + exact U.inj1 tag tag' sh sh' t t' i i' (p1.of_mem hv) tb1 h12 hi v1 (p2.of_mem hv) tb2 h12' hi' v2 hd hS + rootInj1 a1 a2 raw h1 h2 := + U.rootInj1 a1 a2 raw (ActiveAsidRootA.of_mem (Tb := S1) (Y := Y) (fun b hb => hm b (Or.inr hb)) h1) + (ActiveAsidRootA.of_mem (Tb := S1) (Y := Y) (fun b hb => hm b (Or.inr hb)) h2) + rootOnce := U.rootOnce.step hc.root (fun r hI => by + rcases hI with ⟨a, raw, h1, e⟩ | ⟨a, h1⟩ + · exact Or.inl ⟨a, raw, ActiveAsidRootA.of_mem (Tb := S1) (Y := Y) (fun b hb => hm b (Or.inr hb)) h1, e⟩ + · exact Or.inr ⟨a, S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h1⟩) + ptOnce := U.ptOnce.step hc.ptu + +end frame + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsUniqAssignA.lean b/proofs/Fl4ProofsA64/P3/VsUniqAssignA.lean new file mode 100644 index 000000000..c026145c4 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUniqAssignA.lean @@ -0,0 +1,386 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, RO3): **`VsUniqA` across an ASIDPoolAssign pool write** (`rootOnce`, A′). + +The new pool entry names a root that is installed nowhere (`hinst`) and is the root of no unmapped root cap +(`hnoU`: the cap is now mapped); every descriptor of the new root is invalid (`hn1`/`hnH`/`hn2`), so it adds no +reachable table. The write is abstract (`σ'`: the pool object updated, the other pools and the ASID table kept); the +footprint off-facts (`hoff`, `VsRelA.pool_offA`) are premises of the caller. No named premise. New module. +-/ +import Fl4ProofsA64.P3.VsUniqA +import Fl4ProofsA64.P3.VsFindA +import Fl4ProofsA64.P3.VsLeafA +import Fl4ProofsA64.P3.VsWalkA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- **Mapping an unmapped page-table cap in place** (`ARMPageTableMap`): the mapped cap is a `PageTable` cap of its own +table only, as the unmapped one it replaces, and is no unmapped one (`PtSetE`: the explicit proof the cap-write lemmas +ask for a `PageTable` `c`). -/ +theorem PtSetE.map {th : TypedHeapA} {mem : U64 → U64} {x ptr a0 v0 asid va : U64} + (hold : capAtA mem x = .PageTable ptr false a0 v0) : PtSetE th mem x (.PageTable ptr true asid va) := + Or.inr ⟨fun r ⟨mp, a, v, h⟩ => by cases h; rw [hold]; exact ⟨false, a0, v0, rfl⟩, + fun r ⟨a, v, h⟩ => by cases h⟩ + +section UniqAssign +open Fl4Spec Fl4SpecA64 +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {Lv : U64 → Nat} + {mem mem' : U64 → U64} {ksb p i word : U64} {σ σ' : State Unit} {f : AsidPool} + +/-- A 16-bit ASID is its high 7 and low 9 bits. -/ +theorem asid16_ext {x y : Asid} (h1 : asidHighBitsOf x = asidHighBitsOf y) (h2 : asidLowBitsOf x = asidLowBitsOf y) : + x = y := by + apply BitVec.eq_of_toNat_eq + have e1 := congrArg BitVec.toNat h1 + have e2 := congrArg BitVec.toNat h2 + simp [asidHighBitsOf, asidLowBits, asidLowLen, asidHighLen, asidRepLen, asidLen, ucast, BitVec.toNat_ushiftRight, + Nat.shiftRight_eq_div_pow, asidLowBitsOf] at e1 e2 + have hx := x.isLt + have hy := y.isLt + omega + +/-- **`VsUniqA` across an ASIDPoolAssign pool write** (`rootOnce`, A′): the new pool entry names a root that is +installed nowhere (`hinst`) and is the root of no unmapped root cap (`hnoU`: the cap is now mapped); every descriptor of +the new root is invalid (`hn1`/`hnH`/`hn2`), so it adds no reachable table. No named premise. -/ +theorem VsUniqA.of_assign (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (R : VsRelA Pp S1 Lv X Y mem ksb σ) + (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) + (hp : p ∈ Pp) (hi : i.val < 512) (hk : σ.kheap (specPtr p) = some (.archObj (.asidPool f))) + (hact : ActivePoolA mem ksb p) (hold : mem (peAF p i) = 0#u64) + (hoff : ∀ b, VsFootA ∅ S1 Y ksb b → b ≠ peAF p i) + (hσk : σ'.kheap (specPtr p) = some (.archObj (.asidPool (Function.update f (BitVec.ofNat 9 i.val) (poolEntA word))))) + (hσo : ∀ q, q ≠ p → σ'.kheap (specPtr q) = σ.kheap (specPtr q)) + (hσt : σ'.archState.armAsidTable = σ.archState.armAsidTable) + (hKind : EntKindA S1 Lv X Y word) + (hm : ∀ b, VsFootA Pp S1 Y ksb b → b ≠ peAF p i → mem' b = mem b) + (hmE : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) + (hwrite : mem' (peAF p i) = word) + (htabInj : ∀ a b q, σ.archState.armAsidTable a = some q → σ.archState.armAsidTable b = some q → a = b) + (hn1 : tagA word = 0 → word ≠ 0#u64 → ∀ j : U64, j.val < 512 → dBitA (mem (peAF (untagA word) j)) 0 = false) + (hnH : tagA word = 2 → ∀ j : U64, j.val < 512 → dBitA (mem (peAF (wa (untagA word) 4096#u64) j)) 0 = false) + (hn2 : tagA word = 1 → ∀ j : U64, j.val < 1024 → dBitA (mem (peAF (untagA word) j)) 0 = false) + (hcap : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y) + (hnoU : ∀ y, IsSlotA th y → ¬ RootUnmA (untagA word) (capAtA mem y)) + (hinst : ¬ RootInstA Pp X mem ksb σ (untagA word)) : + VsUniqA th Pp S1 X Y T2 Sh2 mem' ksb σ' := by + have hal := Nat.mod_eq_zero_of_dvd (R.pal p hp) + have hword : ∀ q ∈ Pp, ∀ j : U64, j.val < 512 → peAF q j = peAF p i → q = p ∧ j = i := + fun q hq j hj => peAF_injA (Nat.mod_eq_zero_of_dvd (R.pal q hq)) hal hj hi + have hmV : ∀ b, VsFootA ∅ S1 Y ksb b → mem' b = mem b := fun b hb => + hm b (by + cases hb with + | asid j hj => exact .asid j hj + | pool q j hq hj => exact absurd hq (Set.notMem_empty q) + | pt q j hq hj => exact .pt q j hq hj + | high y j hy hj => exact .high y j hy hj) (hoff b hb) + have htab : ∀ j : U64, j.val < 128 → mem' (atAF ksb j) = mem (atAF ksb j) := + fun j hj => hm _ (.asid j hj) (hoff _ (.asid j hj)) + have hT1 : ∀ t j : U64, S1TabA S1 Y t → j.val < 512 → mem' (peAF t j) = mem (peAF t j) := by + intro t j htb hj + rcases htb with ht | ⟨y0, hy0, rfl⟩ + · exact hmV _ (.pt t j ht hj) + · exact hmV _ (.high y0 j hy0 hj) + have hfold : f (BitVec.ofNat 9 i.val) = none := by + obtain ⟨g, hkg, hg⟩ := R.pool p hp + rw [hk] at hkg + cases hkg + rw [hg hact i hi, hold] + unfold poolEntA + rw [if_pos rfl] + -- spec heaps + have hHeap : ∀ p' g, σ'.kheap (specPtr p') = + some (.archObj (.asidPool g)) → + (p' ≠ p ∧ σ.kheap (specPtr p') = some (.archObj (.asidPool g))) ∨ + (p' = p ∧ g = Function.update f (BitVec.ofNat 9 i.val) (poolEntA word)) := by + intro p' g h + by_cases e : p' = p + · right + subst e + rw [hσk] at h + cases h + exact ⟨rfl, rfl⟩ + · left + rw [hσo p' e] at h + exact ⟨e, h⟩ + have hHeap' : ∀ p' g, σ.kheap (specPtr p') = some (.archObj (.asidPool g)) → + (p' ≠ p ∧ σ'.kheap (specPtr p') = + some (.archObj (.asidPool g))) ∨ (p' = p ∧ g = f) := by + intro p' g h + by_cases e : p' = p + · right + subst e + rw [hk] at h + cases h + exact ⟨rfl, rfl⟩ + · left + rw [← hσo p' e] at h + exact ⟨e, h⟩ + have hX1 : ∀ {r : U64}, r ∈ X → r = untagA word → word ≠ 0#u64 → tagA word = 1 := by + intro r hr e hw + have hg : r ∈ S2PgE X T2 := Or.inr ⟨r, hr, Or.inl rfl⟩ + rcases hKind with h0 | ⟨ht0, hS, -⟩ | ⟨ht1, -⟩ | ⟨ht2, hy⟩ + · exact absurd h0 hw + · exact absurd (show r ∈ VsPtA Pp S1 Y from Or.inr (Or.inl (by rw [e]; exact hS))) (E.pgd r hg).1 + · exact ht1 + · exact absurd (by rw [e]; exact hy) (E.pgd r hg).2 + -- the active ASID entries + have hActR : ∀ {asid raw : U64}, ActiveAsidRootA mem' ksb Pp asid raw → ActiveAsidRootA mem ksb Pp asid raw ∨ + (raw = word ∧ word ≠ 0#u64 ∧ ∃ h : U64, h.val < 128 ∧ asid.val = h.val * 512 + i.val ∧ mem (atAF ksb h) = p ∧ + p ≠ 0#u64) := by + rintro asid raw ⟨hj, lo, hhj, hlo, ha', pool, hpool, hpne, htab', hpe, hrne⟩ + rw [htab hj hhj] at htab' + by_cases he : peAF pool lo = peAF p i + · obtain ⟨h1, h2⟩ := hword pool hpool lo hlo he + rw [he, hwrite] at hpe + rw [h1] at htab' hpne + rw [h2] at ha' + exact Or.inr ⟨hpe.symm, hpe ▸ hrne, hj, hhj, ha', htab', hpne⟩ + · rw [hm _ (.pool pool lo hpool hlo) he] at hpe + exact Or.inl ⟨hj, lo, hhj, hlo, ha', pool, hpool, hpne, htab', hpe, hrne⟩ + have hActO : ∀ {asid raw : U64}, ActiveAsidRootA mem ksb Pp asid raw → ActiveAsidRootA mem' ksb Pp asid raw := by + rintro asid raw ⟨hj, lo, hhj, hlo, ha', pool, hpool, hpne, htab', hpe, hrne⟩ + refine ⟨hj, lo, hhj, hlo, ha', pool, hpool, hpne, by rw [htab hj hhj]; exact htab', ?_, hrne⟩ + by_cases he : peAF pool lo = peAF p i + · rw [he, hold] at hpe + exact absurd hpe.symm hrne + · rw [hm _ (.pool pool lo hpool hlo) he] + exact hpe + have hPath : ∀ {tag sh q}, VsPathA Pp S1 Y mem' ksb tag sh q → + VsPathA Pp S1 Y mem ksb tag sh q ∨ (tagA word = 0 ∧ word ≠ 0#u64 ∧ q = word) ∨ + (tagA word = 2 ∧ q = wa (untagA word) 4096#u64) := by + intro tag sh q hpth + induction hpth with + | native ha' htag htb => + rcases hActR ha' with ha0 | ⟨rfl, hwne, -⟩ + · exact Or.inl (.native ha0 htag htb) + · exact Or.inr (Or.inl ⟨htag, hwne, rfl⟩) + | high ha' htag hy' => + rcases hActR ha' with ha0 | ⟨rfl, -⟩ + · exact Or.inl (.high ha0 htag hy') + · exact Or.inr (Or.inr ⟨htag, rfl⟩) + | @child tag tb j sh _ htY h12 hj h3 ih => + rw [hT1 tb j htY hj] at h3 ⊢ + rcases ih with hpar | ⟨ht0, hwne, rfl⟩ | ⟨ht2, rfl⟩ + · exact Or.inl (.child hpar htY h12 hj h3) + · have hb0 := ((and3_bitsA _).1 h3).1 + have hz := hn1 ht0 hwne j hj + rw [untagA_of ht0] at hz + rw [hz] at hb0 + exact absurd hb0 (by simp) + · have hb0 := ((and3_bitsA _).1 h3).1 + rw [hnH ht2 j hj] at hb0 + exact absurd hb0 (by simp) + have hPold : ∀ {tag t j : U64} {n : Nat}, VsPathA Pp S1 Y mem' ksb tag n t → j.val < 512 → + (mem' (peAF t j) &&& 3#u64) = 3#u64 → S1TabA S1 Y t → VsPathA Pp S1 Y mem ksb tag n t := by + intro tag t j n hp0 hj h3 htb + rcases hPath hp0 with h0 | ⟨ht0, hwne, rfl⟩ | ⟨ht2, rfl⟩ + · exact h0 + · exfalso + rw [hT1 _ j htb hj] at h3 + have hb0 := ((and3_bitsA _).1 h3).1 + have hz := hn1 ht0 hwne j hj + rw [untagA_of ht0] at hz + rw [hz] at hb0 + exact absurd hb0 (by simp) + · exfalso + rw [hT1 _ j htb hj] at h3 + have hb0 := ((and3_bitsA _).1 h3).1 + rw [hnH ht2 j hj] at hb0 + exact absurd hb0 (by simp) + -- the Stage-2 side + have hAct2 : ∀ {r : U64}, ActiveS2RootA Pp X σ' r → + ActiveS2RootA Pp X σ r ∨ (tagA word = 1 ∧ r = untagA word) := by + rintro r ⟨hr, asid, p', f', h0, hp', htab', hkh', hf'⟩ + rw [hσt] at htab' + rcases hHeap p' f' hkh' with ⟨-, hk0⟩ | ⟨hpp, hg⟩ + · exact Or.inl ⟨hr, asid, p', f', h0, hp', htab', hk0, hf'⟩ + · rw [hg] at hf' + by_cases hlo : asidLowBitsOf asid = BitVec.ofNat 9 i.val + · right + rw [hlo, Function.update_self] at hf' + have hw0 : word ≠ 0#u64 := by + intro h + rw [h] at hf' + unfold poolEntA at hf' + simp at hf' + unfold poolEntA at hf' + rw [if_neg hw0] at hf' + have h2 := specPtr_inj (by injection hf' with h1; injection h1) + exact ⟨hX1 hr h2.symm hw0, h2.symm⟩ + · left + rw [Function.update_of_ne hlo] at hf' + exact ⟨hr, asid, p', f, h0, hp', htab', by rw [hpp]; exact hk, hf'⟩ + have hS2R : ∀ {a r : U64}, S2RootOfAsidA Pp X σ' a r → + S2RootOfAsidA Pp X σ a r ∨ (r = untagA word ∧ + σ.archState.armAsidTable (asidHighBitsOf (BitVec.ofNat 16 a.val)) = some (specPtr p) ∧ + asidLowBitsOf (BitVec.ofNat 16 a.val) = BitVec.ofNat 9 i.val) := by + rintro a r ⟨hr, p', f', h0, hp', htab', hkh', hf'⟩ + rw [hσt] at htab' + rcases hHeap p' f' hkh' with ⟨-, hk0⟩ | ⟨hpp, hg⟩ + · exact Or.inl ⟨hr, p', f', h0, hp', htab', hk0, hf'⟩ + · rw [hg] at hf' + by_cases hlo : asidLowBitsOf (BitVec.ofNat 16 a.val) = BitVec.ofNat 9 i.val + · right + rw [hlo, Function.update_self] at hf' + have hw0 : word ≠ 0#u64 := by + intro h + rw [h] at hf' + unfold poolEntA at hf' + simp at hf' + unfold poolEntA at hf' + rw [if_neg hw0] at hf' + have h2 := specPtr_inj (by injection hf' with h1; injection h1) + refine ⟨h2.symm, ?_, hlo⟩ + rw [htab', hpp] + · left + rw [Function.update_of_ne hlo] at hf' + exact ⟨hr, p', f, h0, hp', htab', by rw [hpp]; exact hk, hf'⟩ + have hS2R' : ∀ {a r : U64}, S2RootOfAsidA Pp X σ a r → + S2RootOfAsidA Pp X σ' a r := by + rintro a r ⟨hr, p', f', h0, hp', htab', hkh', hf'⟩ + rcases hHeap' p' f' hkh' with ⟨-, hk1⟩ | ⟨hpp, hg⟩ + · exact ⟨hr, p', f', h0, hp', by rw [hσt]; exact htab', hk1, hf'⟩ + · rw [hg] at hf' + have hlo : asidLowBitsOf (BitVec.ofNat 16 a.val) ≠ BitVec.ofNat 9 i.val := fun h => by + rw [h, hfold] at hf' + cases hf' + refine ⟨hr, p', Function.update f (BitVec.ofNat 9 i.val) (poolEntA word), h0, hp', by rw [hσt]; exact htab', + by rw [hpp]; exact hσk, ?_⟩ + rw [Function.update_of_ne hlo] + exact hf' + have hS2Reach : ∀ {q : U64}, S2ReachA Pp X T2 Sh2 mem' σ' q → + S2ReachA Pp X T2 Sh2 mem σ q ∨ (tagA word = 1 ∧ q = untagA word) := by + intro q h + induction h with + | root ha => + rcases hAct2 ha with h0 | ⟨ht, rfl⟩ + · exact Or.inl (.root h0) + · exact Or.inr ⟨ht, rfl⟩ + | @stepRoot r j ha hj h3 ht2 => + have h1k : j.val < 1024 := by have := s2Top1k; omega + rw [hmE _ (rootFootE ha.1 (E.xal r ha.1) h1k)] at h3 ht2 ⊢ + rcases hAct2 ha with h0 | ⟨ht, rfl⟩ + · exact Or.inl (.stepRoot h0 hj h3 ht2) + · have hb0 := ((and3_bitsA _).1 h3).1 + rw [hn2 ht j h1k] at hb0 + exact absurd hb0 (by simp) + | @stepPt t j _ ht h12 hj h3 ht2 ih => + rw [hmE _ (.s2pt t j ht hj)] at h3 ht2 ⊢ + rcases ih with h0 | ⟨ht1, rfl⟩ + · exact Or.inl (.stepPt h0 ht h12 hj h3 ht2) + · have hb0 := ((and3_bitsA _).1 h3).1 + rw [hn2 ht1 j (by omega)] at hb0 + exact absurd hb0 (by simp) + have hS2E : ∀ {w : U64}, S2EntryA Pp X T2 Sh2 mem' + σ' w → + (mem' w &&& 3#u64) = 3#u64 → S2EntryA Pp X T2 Sh2 mem σ w := by + rintro w (⟨r, j, ha, hj, rfl⟩ | ⟨t, j, hr, ht, h12, hj, rfl⟩) h3 + · have h1k : j.val < 1024 := by have := s2Top1k; omega + rw [hmE _ (rootFootE ha.1 (E.xal r ha.1) h1k)] at h3 + rcases hAct2 ha with h0 | ⟨ht1, rfl⟩ + · exact Or.inl ⟨r, j, h0, hj, rfl⟩ + · have hb0 := ((and3_bitsA _).1 h3).1 + rw [hn2 ht1 j h1k] at hb0 + exact absurd hb0 (by simp) + · rw [hmE _ (.s2pt t j ht hj)] at h3 + rcases hS2Reach hr with h0 | ⟨ht1, rfl⟩ + · exact Or.inr ⟨t, j, h0, ht, h12, hj, rfl⟩ + · have hb0 := ((and3_bitsA _).1 h3).1 + rw [hn2 ht1 j (by omega)] at hb0 + exact absurd hb0 (by simp) + refine { t2 := ?_, s1 := ?_, out := ?_, inj2 := ?_, rootInj2 := ?_, inj1 := ?_, rootInj1 := ?_, rootOnce := ?_, ptOnce := ?_ } + · intro y hy ptr asid va hcp hT w hw h3 hd + rw [hcap y hy] at hcp + have hw0 := hS2E hw h3 + have hf : mem' w = mem w := hmE w (hw0.foot E.xal) + rw [hf] at h3 hd + obtain ⟨r, hr, hws⟩ := U.t2 y hy ptr asid va hcp hT w hw0 h3 hd + refine ⟨r, hS2R' hr, hws.of_mem' ?_⟩ + intro t' sh' n' hh + apply hmE _ + rcases hh with ⟨rfl, rfl⟩ | ⟨ht', rfl⟩ + · exact rootFootE hr.1 (E.xal _ hr.1) + (Nat.lt_of_lt_of_le (walkIdx_lt va sh' _ (Nat.succ_pos _) (Nat.le_trans s2Top1k (by norm_num))) s2Top1k) + · exact .s2pt t' _ ht' (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + · intro y hy ptr asid va hcp hS tag sh t j hpath htab' h12 hj h3 hd + rw [hcap y hy] at hcp + have p0 := hPold hpath hj h3 htab' + have hf : mem' (peAF t j) = mem (peAF t j) := hT1 t j htab' hj + rw [hf] at h3 hd + obtain ⟨raw, hact', hw⟩ := U.s1 y hy ptr asid va hcp hS tag sh t j p0 htab' h12 hj h3 hd + have hS1f : ∀ t' sh', S1TabA S1 Y t' → + mem' (peAF t' (walkIdx va sh' 512)) = mem (peAF t' (walkIdx va sh' 512)) := fun t' sh' h => + hT1 t' _ h (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + refine ⟨raw, hActO hact', ?_⟩ + rcases hw with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · refine Or.inl ⟨h0, hr, hws.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inl hr) + · exact hS1f _ _ h + · refine Or.inr ⟨h2, hy2, hws.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inr ⟨untagA raw, hy2, rfl⟩) + · exact hS1f _ _ h + · intro y hy ptr asid va hcp + rw [hcap y hy] at hcp + exact U.out y hy ptr asid va hcp + · intro w1 w2 h1 h2 v1 v2 hd hT + have h1' := hS2E h1 v1 + have h2' := hS2E h2 v2 + have f1 : mem' w1 = mem w1 := hmE w1 (h1'.foot E.xal) + have f2 : mem' w2 = mem w2 := hmE w2 (h2'.foot E.xal) + rw [f1] at v1 hd hT + rw [f2] at v2 hd + exact U.inj2 w1 w2 h1' h2' v1 v2 hd hT + · intro a1 a2 r h1 h2 + rcases hS2R h1 with o1 | ⟨e1, t1, l1⟩ <;> rcases hS2R h2 with o2 | ⟨e2, t2, l2⟩ + · exact U.rootInj2 a1 a2 r o1 o2 + · exact absurd (Or.inr ⟨a1, by rw [← e2]; exact o1⟩) hinst + · exact absurd (Or.inr ⟨a2, by rw [← e1]; exact o2⟩) hinst + · exact asid16_ext (htabInj _ _ _ t1 t2) (l1.trans l2.symm) + · intro tag tag' sh sh' t t' j j' p1 tb1 h12 hj v1 p2 tb2 h12' hj' v2 hd hS + have p1' := hPold p1 hj v1 tb1 + have p2' := hPold p2 hj' v2 tb2 + rw [hT1 t j tb1 hj] at v1 hd hS + rw [hT1 t' j' tb2 hj'] at v2 hd + exact U.inj1 tag tag' sh sh' t t' j j' p1' tb1 h12 hj v1 p2' tb2 h12' hj' v2 hd hS + · intro a1 a2 raw h1 h2 + rcases hActR h1 with o1 | ⟨e1, -, hh1, hlt1, ha1, ht1, hp1⟩ <;> + rcases hActR h2 with o2 | ⟨e2, -, hh2, hlt2, ha2, ht2, hp2⟩ + · exact U.rootInj1 a1 a2 raw o1 o2 + · exact absurd (Or.inl ⟨a1, raw, o1, by rw [e2]⟩) hinst + · exact absurd (Or.inl ⟨a2, raw, o2, by rw [e1]⟩) hinst + · have s1 := R.table hh1 hlt1 + have s2 := R.table hh2 hlt2 + rw [ht1, optPtrA_ne hp1] at s1 + rw [ht2, optPtrA_ne hp2] at s2 + have hv := congrArg BitVec.toNat (htabInj _ _ _ s1 s2) + rw [BitVec.toNat_ofNat, BitVec.toNat_ofNat, Nat.mod_eq_of_lt (show hh1.val < 2 ^ 7 by omega), + Nat.mod_eq_of_lt (show hh2.val < 2 ^ 7 by omega)] at hv + exact UScalar.eq_of_val_eq (by omega) + · intro y hy r hr + rw [hcap y hy] at hr + obtain ⟨hn, hu⟩ := U.rootOnce y hy r hr + have hrne : r ≠ untagA word := fun e => hnoU y hy (e ▸ hr) + refine ⟨fun hI => hn ?_, fun z hz hk' => ?_⟩ + · rcases hI with ⟨a, raw, h1, e⟩ | ⟨a, h1⟩ + · rcases hActR h1 with h0 | ⟨rfl, -⟩ + · exact Or.inl ⟨a, raw, h0, e⟩ + · exact absurd e.symm hrne + · rcases hS2R h1 with h0 | ⟨e', -⟩ + · exact Or.inr ⟨a, h0⟩ + · exact absurd e' hrne + · rw [hcap z hz] at hk' + exact hu z hz hk' + · exact U.ptOnce.step (UClosed.pos (fun y hy r h => by rw [hcap y hy] at h; exact h) + (fun y hy r h => by rw [hcap y hy] at h; exact h)).toE + +end UniqAssign + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsUniqClearA.lean b/proofs/Fl4ProofsA64/P3/VsUniqClearA.lean new file mode 100644 index 000000000..15c30409b --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUniqClearA.lean @@ -0,0 +1,570 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, RO3): **`VsUniqA` across the removal of an ASID entry** (DelAsid's pool-entry +clear, DelAsidPool's table-word clear): the active ASID roots and the Stage-2 roots only shrink, no table descriptor changes. + +* `RPathA`: a Stage-1 / window path with its root named (`VsPathA` forgets it); `RPathA.rpath_unique`: **two paths to + one table start at one root** (the forest property `inj1` at every step, the root level by the shape facts); +* `walk_rpath`: the walk of an address from a root is a rooted path to the table of each of its slots. + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.VsUniqShrinkA +import Fl4ProofsA64.P3.VsFindA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section s1 +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {Lv : U64 → Nat} {mem mem' : U64 → U64} + {ksb : U64} {σ : Fl4SpecA64.State Unit} + +/-- A path from the named root `raw` (a pool word of tag 0 / 2). -/ +inductive RPathA (S1 Y : Set U64) (mem : U64 → U64) (raw : U64) : U64 → Nat → U64 → Prop + | native : tagA raw = 0 → raw ∈ S1 → RPathA S1 Y mem raw 0#u64 39 raw + | high : tagA raw = 2 → untagA raw ∈ Y → RPathA S1 Y mem raw 2#u64 30 (wa (untagA raw) 4096#u64) + | child {tag : U64} {sh : Nat} {t i : U64} : RPathA S1 Y mem raw tag sh t → S1TabA S1 Y t → 12 < sh → + i.val < 512 → (mem (peAF t i) &&& 3#u64) = 3#u64 → + RPathA S1 Y mem raw tag (sh - 9) (dTabA (mem (peAF t i))) + +theorem RPathA.toPath {raw tag : U64} {sh : Nat} {t asid : U64} (h : RPathA S1 Y mem raw tag sh t) + (ha : ActiveAsidRootA mem ksb Pp asid raw) : VsPathA Pp S1 Y mem ksb tag sh t := by + induction h with + | native ht hS => exact .native ha ht hS + | high ht hy => exact .high ha ht hy + | child _ htb h12 hi h3 ih => exact .child ih htb h12 hi h3 + +theorem RPathA.ofPath {tag : U64} {sh : Nat} {t : U64} (h : VsPathA Pp S1 Y mem ksb tag sh t) : + ∃ asid raw, ActiveAsidRootA mem ksb Pp asid raw ∧ RPathA S1 Y mem raw tag sh t := by + induction h with + | @native asid raw ha ht hS => exact ⟨asid, raw, ha, .native ht hS⟩ + | @high asid raw ha ht hy => exact ⟨asid, raw, ha, .high ht hy⟩ + | child _ htb h12 hi h3 ih => + obtain ⟨a, r, ha, hr⟩ := ih + exact ⟨a, r, ha, .child hr htb h12 hi h3⟩ + +theorem RPathA.of_mem {raw tag : U64} {sh : Nat} {t : U64} + (hT : ∀ t j : U64, S1TabA S1 Y t → j.val < 512 → mem' (peAF t j) = mem (peAF t j)) + (h : RPathA S1 Y mem' raw tag sh t) : RPathA S1 Y mem raw tag sh t := by + induction h with + | native ht hS => exact .native ht hS + | high ht hy => exact .high ht hy + | @child tag sh t i _ htb h12 hi h3 ih => + rw [hT t i htb hi] at h3 ⊢ + exact .child ih htb h12 hi h3 + +/-- **The walk of an address from a rooted table is a rooted path to the table of each of its slots.** -/ +theorem walk_rpath {raw tag : U64} {va t0 w : U64} {sh0 : Nat} + {n : Nat} (W : WalkSlotA (S1TabA S1 Y) mem va t0 sh0 n w) (hn : n = 512) + (hr : RPathA S1 Y mem raw tag sh0 t0) (hb : S1TabA S1 Y t0) : + ∃ (t' : U64) (sh' : Nat) (j : U64), RPathA S1 Y mem raw tag sh' t' ∧ S1TabA S1 Y t' ∧ j.val < 512 ∧ + w = peAF t' j := by + revert hr hb hn + induction W with + | here t sh n => + intro hn hr hb + subst hn + exact ⟨t, sh, _, hr, hb, walkIdx_lt va sh 512 (by norm_num) (by norm_num), rfl⟩ + | @down t sh n w h3 h12 hc W' ih => + intro hn hr hb + subst hn + exact ih rfl (.child hr hb h12 (walkIdx_lt va sh 512 (by norm_num) (by norm_num)) h3) hc + +theorem raw_ext {a b : U64} (h1 : untagA a = untagA b) (h2 : tagA a = tagA b) : a = b := by + apply UScalar.eq_of_val_eq + have e : ∀ w : U64, (untagA w).val = 4 * (w.val / 4) := fun w => by + unfold untagA + rw [UScalar.val_and, show (18446744073709551612#u64 : U64).val = 2 ^ 64 - 1 - (2 ^ 2 - 1) from rfl, + nat_and_hiA w.val 2 w.bv.isLt (by decide)] + omega + have a1 := e a + have b1 := e b + rw [h1] at a1 + unfold tagA at h2 + omega + +theorem VsRelA.sh_of (R : VsRelA Pp S1 Lv X Y mem ksb σ) {tag : U64} {sh : Nat} {t : U64} + (p : VsPathA Pp S1 Y mem ksb tag sh t) : sh ≤ 39 ∧ (t ∈ S1 → sh = 39 - 9 * Lv t) := by + rcases (R.path_props p).2 with ⟨hS, -, h⟩ | ⟨-, h30, y, hy, -, hq⟩ + · exact ⟨by omega, fun _ => h⟩ + · exact ⟨by omega, fun hS => absurd (hq ▸ hS) (R.ytb y hy)⟩ + +/-- A native root path and a child path cannot end at one table. -/ +theorem VsRelA.no_native_child (R : VsRelA Pp S1 Lv X Y mem ksb σ) {tag tag' tag'' : U64} {sh0 : Nat} {t t0 : U64} + (p1 : VsPathA Pp S1 Y mem ksb tag 39 t) (pc : VsPathA Pp S1 Y mem ksb tag' (sh0 - 9) t) + (pp : VsPathA Pp S1 Y mem ksb tag'' sh0 t0) (hS : t ∈ S1) : False := by + have a := R.sh_of p1 + have c := R.sh_of pc + have b := R.sh_of pp + have := a.2 hS + have := c.2 hS + omega + +theorem RPathA.inv {raw tag : U64} {sh : Nat} {t : U64} (h : RPathA S1 Y mem raw tag sh t) : + (tagA raw = 0 ∧ raw ∈ S1 ∧ t = raw) ∨ (tagA raw = 2 ∧ untagA raw ∈ Y ∧ t = wa (untagA raw) 4096#u64) ∨ + ∃ (tag0 : U64) (sh0 : Nat) (t0 i : U64), RPathA S1 Y mem raw tag0 sh0 t0 ∧ S1TabA S1 Y t0 ∧ 12 < sh0 ∧ + i.val < 512 ∧ (mem (peAF t0 i) &&& 3#u64) = 3#u64 ∧ sh = sh0 - 9 ∧ t = dTabA (mem (peAF t0 i)) := by + cases h with + | native ht hS => exact Or.inl ⟨ht, hS, rfl⟩ + | high ht hy => exact Or.inr (Or.inl ⟨ht, hy, rfl⟩) + | child hp htb h12 hi h3 => exact Or.inr (Or.inr ⟨_, _, _, _, hp, htb, h12, hi, h3, rfl, rfl⟩) + +/-- **Two rooted paths to one table start at one root.** -/ +theorem rpath_unique (R : VsRelA Pp S1 Lv X Y mem ksb σ) (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) + {raw1 tag1 : U64} {sh1 : Nat} {t : U64} (h1 : RPathA S1 Y mem raw1 tag1 sh1 t) : + ∀ {a1 : U64}, ActiveAsidRootA mem ksb Pp a1 raw1 → + ∀ {raw2 tag2 : U64} {sh2 : Nat}, RPathA S1 Y mem raw2 tag2 sh2 t → ∀ {a2 : U64}, + ActiveAsidRootA mem ksb Pp a2 raw2 → raw1 = raw2 := by + induction h1 with + | @native ht hS => + intro a1 ha1 raw2 tag2 sh2 h2 a2 ha2 + rcases h2.inv with ⟨-, -, e⟩ | ⟨-, hy', e⟩ | ⟨tg, s0, t0, i, hp, htb, h12, hi, h3, rfl, e⟩ + · exact e + · rw [e] at hS + exact absurd hS (R.ytb _ hy') + · have p1 : VsPathA Pp S1 Y mem ksb 0#u64 39 raw1 := (RPathA.native ht hS).toPath ha1 + have pc : VsPathA Pp S1 Y mem ksb tg (s0 - 9) (dTabA (mem (peAF t0 i))) := + (RPathA.child hp htb h12 hi h3).toPath ha2 + rw [← e] at pc + exact (R.no_native_child p1 pc (hp.toPath ha2) hS).elim + | high ht hy => + intro a1 ha1 raw2 tag2 sh2 h2 a2 ha2 + rcases h2.inv with ⟨-, hS', e⟩ | ⟨ht2, hy', e⟩ | ⟨tg, s0, t0, i, hp, htb, h12, hi, h3, rfl, e⟩ + · rw [← e] at hS' + exact absurd hS' (R.ytb _ hy) + · have e1 := wa4096_val (R.yal _ hy) + have e2 := wa4096_val (R.yal _ hy') + have ev := congrArg UScalar.val e + have hu : untagA raw1 = untagA raw2 := UScalar.eq_of_val_eq (by omega) + exact raw_ext hu (by rw [ht, ht2]) + · have hc := R.child_tb (hp.toPath ha2) htb h12 hi h3 + rw [← e] at hc + exact absurd hc (R.ytb _ hy) + | @child tag sh t0 i hp htb h12 hi h3 ih => + intro a1 ha1 raw2 tag2 sh2 h2 a2 ha2 + rcases h2.inv with ⟨ht', hS', e⟩ | ⟨ht', hy', e⟩ | ⟨tg, s0, t1, i', hp', htb', h12', hi', h3', rfl, e⟩ + · have p1 : VsPathA Pp S1 Y mem ksb 0#u64 39 raw2 := (RPathA.native ht' hS').toPath ha2 + have pc : VsPathA Pp S1 Y mem ksb tag (sh - 9) (dTabA (mem (peAF t0 i))) := + (RPathA.child hp htb h12 hi h3).toPath ha1 + rw [e] at pc + exact (R.no_native_child p1 pc (hp.toPath ha1) hS').elim + · have hc := R.child_tb (hp.toPath ha1) htb h12 hi h3 + rw [e] at hc + exact absurd hc (R.ytb _ hy') + · have hdt : dTabA (mem (peAF t0 i)) = dTabA (mem (peAF t1 i')) := e + have hS : dTabA (mem (peAF t0 i)) ∈ S1 := R.child_tb (hp.toPath ha1) htb h12 hi h3 + have hi1 := U.inj1 _ _ _ _ t0 t1 i i' (hp.toPath ha1) htb h12 hi h3 (hp'.toPath ha2) htb' h12' hi' h3' hdt hS + have et := (peAF_injA_s (S1TabA.mod4k R htb) (S1TabA.mod4k R htb') hi hi' hi1).1 + subst et + exact ih ha1 hp' ha2 + +end s1 + +section s2 +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem mem' : U64 → U64} {ksb : U64} + {σ : Fl4SpecA64.State Unit} + +/-- A Stage-2 table reached from the named root `r`. -/ +inductive RS2A (X T2 : Set U64) (Sh2 : U64 → Nat) (mem : U64 → U64) (r : U64) : U64 → Prop + | root : r ∈ X → RS2A X T2 Sh2 mem r r + | stepRoot {i : U64} : r ∈ X → i.val < Fl4SpecA64.s2Geom.topMask + 1 → (mem (peAF r i) &&& 3#u64) = 3#u64 → + dTabA (mem (peAF r i)) ∈ T2 → RS2A X T2 Sh2 mem r (dTabA (mem (peAF r i))) + | stepPt {t i : U64} : RS2A X T2 Sh2 mem r t → t ∈ T2 → 12 < Sh2 t → i.val < 512 → + (mem (peAF t i) &&& 3#u64) = 3#u64 → dTabA (mem (peAF t i)) ∈ T2 → + RS2A X T2 Sh2 mem r (dTabA (mem (peAF t i))) + +theorem RS2A.toReach {r t : U64} (h : RS2A X T2 Sh2 mem r t) (ha : ActiveS2RootA Pp X σ r) : + S2ReachA Pp X T2 Sh2 mem σ t := by + induction h with + | root _ => exact .root ha + | stepRoot _ hi h3 hc => exact .stepRoot ha hi h3 hc + | stepPt _ ht h12 hi h3 hc ih => exact .stepPt ih ht h12 hi h3 hc + +theorem RS2A.ofReach {t : U64} (h : S2ReachA Pp X T2 Sh2 mem σ t) : + ∃ r, ActiveS2RootA Pp X σ r ∧ RS2A X T2 Sh2 mem r t := by + induction h with + | @root r ha => exact ⟨r, ha, .root ha.1⟩ + | @stepRoot r i ha hi h3 hc => exact ⟨r, ha, .stepRoot ha.1 hi h3 hc⟩ + | @stepPt t i _ ht h12 hi h3 hc ih => + obtain ⟨r, ha, hr⟩ := ih + exact ⟨r, ha, .stepPt hr ht h12 hi h3 hc⟩ + +theorem RS2A.of_mem {r t : U64} (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (hE : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) (h : RS2A X T2 Sh2 mem' r t) : RS2A X T2 Sh2 mem r t := by + induction h with + | root hX => exact .root hX + | @stepRoot i hX hi h3 hc => + have h1k : i.val < 1024 := by have := s2Top1k; omega + rw [hE _ (rootFootE hX (hxal _ hX) h1k)] at h3 hc ⊢ + exact .stepRoot hX hi h3 hc + | @stepPt t i _ ht h12 hi h3 hc ih => + rw [hE _ (.s2pt t i ht hi)] at h3 hc ⊢ + exact .stepPt ih ht h12 hi h3 hc + +theorem RS2A.inv {r t : U64} (h : RS2A X T2 Sh2 mem r t) : + (t = r ∧ r ∈ X) ∨ + (∃ i : U64, r ∈ X ∧ i.val < Fl4SpecA64.s2Geom.topMask + 1 ∧ (mem (peAF r i) &&& 3#u64) = 3#u64 ∧ + dTabA (mem (peAF r i)) ∈ T2 ∧ t = dTabA (mem (peAF r i))) ∨ + (∃ t0 i : U64, RS2A X T2 Sh2 mem r t0 ∧ t0 ∈ T2 ∧ 12 < Sh2 t0 ∧ i.val < 512 ∧ + (mem (peAF t0 i) &&& 3#u64) = 3#u64 ∧ dTabA (mem (peAF t0 i)) ∈ T2 ∧ t = dTabA (mem (peAF t0 i))) := by + cases h with + | root hX => exact Or.inl ⟨rfl, hX⟩ + | stepRoot hX hi h3 hc => exact Or.inr (Or.inl ⟨_, hX, hi, h3, hc, rfl⟩) + | stepPt hp ht h12 hi h3 hc => exact Or.inr (Or.inr ⟨_, _, hp, ht, h12, hi, h3, hc, rfl⟩) + +/-- **Two rooted Stage-2 paths to one table start at one root.** -/ +theorem rs2_unique (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) + {r1 t : U64} (h1 : RS2A X T2 Sh2 mem r1 t) (ha1 : ActiveS2RootA Pp X σ r1) : + ∀ {r2 : U64}, RS2A X T2 Sh2 mem r2 t → ActiveS2RootA Pp X σ r2 → r1 = r2 := by + induction h1 with + | root hX => + intro r2 h2 ha2 + rcases h2.inv with ⟨e, -⟩ | ⟨i, hX2, hi, h3, hc, e⟩ | ⟨t0, i, hp, ht, h12, hi, h3, hc, e⟩ + · exact e + · exact absurd e.symm (E.t2x _ hc _ hX).1 + · exact absurd e.symm (E.t2x _ hc _ hX).1 + | @stepRoot i hX hi h3 hc => + intro r2 h2 ha2 + have hi1k : i.val < 1024 := by have := s2Top1k; omega + have w1 : S2EntryA Pp X T2 Sh2 mem σ (peAF r1 i) := Or.inl ⟨r1, i, ha1, hi, rfl⟩ + rcases h2.inv with ⟨e, hX2⟩ | ⟨i2, hX2, hi2, h32, hc2, e⟩ | ⟨t0, i2, hp, ht, h12, hi2, h32, hc2, e⟩ + · exact absurd e (E.t2x _ hc _ hX2).1 + · have w2 : S2EntryA Pp X T2 Sh2 mem σ (peAF r2 i2) := Or.inl ⟨r2, i2, ha2, hi2, rfl⟩ + have := U.inj2 _ _ w1 w2 h3 h32 e hc + have hi2k : i2.val < 1024 := by have := s2Top1k; omega + exact root_root_eq E hX hX2 hi1k hi2k this + · have w2 : S2EntryA Pp X T2 Sh2 mem σ (peAF t0 i2) := Or.inr ⟨t0, i2, hp.toReach ha2, ht, h12, hi2, rfl⟩ + have := U.inj2 _ _ w1 w2 h3 h32 e hc + exact absurd this (root_tab_ne E hX ht hi1k hi2) + | @stepPt t0 i hp ht h12 hi h3 hc ih => + intro r2 h2 ha2 + have w1 : S2EntryA Pp X T2 Sh2 mem σ (peAF t0 i) := Or.inr ⟨t0, i, hp.toReach ha1, ht, h12, hi, rfl⟩ + rcases h2.inv with ⟨e, hX2⟩ | ⟨i2, hX2, hi2, h32, hc2, e⟩ | ⟨t1, i2, hp2, ht2, h122, hi2, h32, hc2, e⟩ + · exact absurd e (E.t2x _ hc _ hX2).1 + · have hi2k : i2.val < 1024 := by have := s2Top1k; omega + have w2 : S2EntryA Pp X T2 Sh2 mem σ (peAF r2 i2) := Or.inl ⟨r2, i2, ha2, hi2, rfl⟩ + have := U.inj2 _ _ w1 w2 h3 h32 e hc + exact absurd this.symm (root_tab_ne E hX2 ht hi2k hi) + · have w2 : S2EntryA Pp X T2 Sh2 mem σ (peAF t1 i2) := Or.inr ⟨t1, i2, hp2.toReach ha2, ht2, h122, hi2, rfl⟩ + have := U.inj2 _ _ w1 w2 h3 h32 e hc + have et := (peAF_injA_s (Nat.mod_eq_zero_of_dvd (E.tal t0 ht)) (Nat.mod_eq_zero_of_dvd (E.tal t1 ht2)) hi hi2 this).1 + subst et + exact ih hp2 ha2 + +end s2 + +section clear +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {Lv : U64 → Nat} {mem mem' : U64 → U64} + {ksb : U64} {σ σ' : Fl4SpecA64.State Unit} + +/-- A root of `X` reached from `r` is `r` (a Stage-2 table is no root). -/ +theorem RS2A.eq_of_mem (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {r t : U64} (h : RS2A X T2 Sh2 mem r t) + (ht : t ∈ X) : t = r := by + rcases h.inv with ⟨e, -⟩ | ⟨i, -, -, -, hc, e⟩ | ⟨t0, i, -, -, -, -, -, hc, e⟩ + · exact e + · rw [e] at ht; exact absurd rfl (E.t2x _ hc _ ht).1 + · rw [e] at ht; exact absurd rfl (E.t2x _ hc _ ht).1 + +/-- **The walk of an address from a Stage-2 root is a rooted path to the table of each of its slots.** -/ +theorem walk_rs2 (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {r0 va t w : U64} {sh n : Nat} + (W : WalkSlotA (· ∈ T2) mem va t sh n w) (hT : S2WalkTabA Pp X T2 Sh2 mem σ t sh n) + (hR : RS2A X T2 Sh2 mem r0 t) : + ∃ t' j : U64, RS2A X T2 Sh2 mem r0 t' ∧ + ((t' ∈ X ∧ j.val < Fl4SpecA64.s2Geom.topMask + 1) ∨ (t' ∈ T2 ∧ j.val < 512)) ∧ w = peAF t' j := by + revert hR + induction W with + | here t sh n => + intro hR + have hn := hT.n_pos + refine ⟨t, _, hR, ?_, rfl⟩ + rcases hT with ⟨ha, rfl, rfl⟩ | ⟨htT, hr, rfl, rfl⟩ + · exact Or.inl ⟨ha.1, walkIdx_lt va _ _ hn.1 hn.2⟩ + · exact Or.inr ⟨htT, walkIdx_lt va _ _ hn.1 hn.2⟩ + | @down t sh n w h3 h12 hc W' ih => + intro hR + have hn := hT.n_pos + have hi := walkIdx_lt va sh n hn.1 hn.2 + obtain ⟨hT', -⟩ := S2WalkTabA.step E hT hi h3 h12 hc + refine ih hT' ?_ + rcases hT with ⟨ha, rfl, rfl⟩ | ⟨htT, hr, rfl, rfl⟩ + · have := RS2A.eq_of_mem E hR ha.1 + subst this + exact .stepRoot ha.1 hi h3 hc + · exact .stepPt hR htT h12 hi h3 hc + +theorem S2RootOfAsidA.ofActive {r : U64} (h : ActiveS2RootA Pp X σ r) : ∃ a : U64, S2RootOfAsidA Pp X σ a r := by + obtain ⟨hr, asid, p, f, h0, hp, htab, hk, hf⟩ := h + have hv : (⟨BitVec.ofNat 64 asid.toNat⟩ : U64).val = asid.toNat := by + show (BitVec.ofNat 64 asid.toNat).toNat = _ + rw [BitVec.toNat_ofNat] + exact Nat.mod_eq_of_lt (Nat.lt_of_lt_of_le asid.isLt (Nat.pow_le_pow_right (by norm_num) (by decide))) + have he : BitVec.ofNat 16 (⟨BitVec.ofNat 64 asid.toNat⟩ : U64).val = asid := by + rw [hv] + apply BitVec.eq_of_toNat_eq + rw [BitVec.toNat_ofNat] + exact Nat.mod_eq_of_lt asid.isLt + exact ⟨⟨BitVec.ofNat 64 asid.toNat⟩, hr, p, f, by rw [he]; exact h0, hp, by rw [he]; exact htab, hk, + by rw [he]; exact hf⟩ + +theorem S2RootOfAsidA.congr {a b r : U64} (h : BitVec.ofNat 16 a.val = BitVec.ofNat 16 b.val) + (hr : S2RootOfAsidA Pp X σ a r) : S2RootOfAsidA Pp X σ b r := by + obtain ⟨hX, p, f, h0, hp, htab, hk, hf⟩ := hr + exact ⟨hX, p, f, by rw [← h]; exact h0, hp, by rw [← h]; exact htab, hk, by rw [← h]; exact hf⟩ + +/-- **`VsUniqA` across the removal of an ASID entry** (module docstring): the active ASID roots and the Stage-2 roots +only shrink, no table descriptor changes, the caps are kept. A mapped page-table cap whose ASID was removed is left +with no reachable descriptor (the forest identifies the root of any surviving path with the old one). -/ +theorem VsUniqA.of_clear (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (R : VsRelA Pp S1 Lv X Y mem ksb σ) + (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) + (hmE : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) + (hT1 : ∀ t j : U64, S1TabA S1 Y t → j.val < 512 → mem' (peAF t j) = mem (peAF t j)) + (hAS : ∀ a r, ActiveAsidRootA mem' ksb Pp a r → ActiveAsidRootA mem ksb Pp a r) + (hS2 : ∀ r, ActiveS2RootA Pp X σ' r → ActiveS2RootA Pp X σ r) + (hSR : ∀ a r, S2RootOfAsidA Pp X σ' a r → S2RootOfAsidA Pp X σ a r) + (hcap : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y) : + VsUniqA th Pp S1 X Y T2 Sh2 mem' ksb σ' := by + have hPold : ∀ {tag sh t}, VsPathA Pp S1 Y mem' ksb tag sh t → VsPathA Pp S1 Y mem ksb tag sh t := by + intro tag sh t h + induction h with + | native ha ht hS => exact .native (hAS _ _ ha) ht hS + | high ha ht hy => exact .high (hAS _ _ ha) ht hy + | @child tag t i sh _ htb h12 hi h3 ih => + rw [hT1 t i htb hi] at h3 ⊢ + exact .child ih htb h12 hi h3 + have hReach : ∀ {q}, S2ReachA Pp X T2 Sh2 mem' σ' q → S2ReachA Pp X T2 Sh2 mem σ q := by + intro q h + induction h with + | root ha => exact .root (hS2 _ ha) + | @stepRoot r j ha hj h3 ht2 => + have h1k : j.val < 1024 := by have := s2Top1k; omega + rw [hmE _ (rootFootE ha.1 (E.xal r ha.1) h1k)] at h3 ht2 ⊢ + exact .stepRoot (hS2 _ ha) hj h3 ht2 + | @stepPt t j _ ht h12 hj h3 ht2 ih => + rw [hmE _ (.s2pt t j ht hj)] at h3 ht2 ⊢ + exact .stepPt ih ht h12 hj h3 ht2 + have hS2E : ∀ {w}, S2EntryA Pp X T2 Sh2 mem' σ' w → S2EntryA Pp X T2 Sh2 mem σ w := by + rintro w (⟨r, j, ha, hj, rfl⟩ | ⟨t, j, hr, ht, h12, hj, rfl⟩) + · exact Or.inl ⟨r, j, hS2 _ ha, hj, rfl⟩ + · exact Or.inr ⟨t, j, hReach hr, ht, h12, hj, rfl⟩ + have hActive : ∀ {w r0 : U64} {va : U64}, ActiveS2RootA Pp X σ r0 → S2EntryA Pp X T2 Sh2 mem' σ' w → + WalkSlotA (· ∈ T2) mem va r0 Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) w → + ActiveS2RootA Pp X σ' r0 := by + intro w r0 va ha0 hw W + obtain ⟨t', j', hR', hc', hwe⟩ := walk_rs2 E W (Or.inl ⟨ha0, rfl, rfl⟩) (.root ha0.1) + rcases hw with ⟨r', j, ha', hj, hwe'⟩ | ⟨t, j, hrch, ht, h12, hj, hwe'⟩ + · have hj1k : j.val < 1024 := by have := s2Top1k; omega + rcases hc' with ⟨hX', hj'⟩ | ⟨ht', hj'⟩ + · have hj'1k : j'.val < 1024 := by have := s2Top1k; omega + have e := root_root_eq E ha'.1 hX' hj1k hj'1k (hwe'.symm.trans hwe) + have e2 := RS2A.eq_of_mem E hR' hX' + rw [← e2, ← e] + exact ha' + · exact absurd (hwe'.symm.trans hwe) (root_tab_ne E ha'.1 ht' hj1k hj') + · obtain ⟨r', ha', hr'⟩ := RS2A.ofReach hrch + have hr0 : RS2A X T2 Sh2 mem r' t := RS2A.of_mem E.xal hmE hr' + rcases hc' with ⟨hX', hj'⟩ | ⟨ht', hj'⟩ + · have hj'1k : j'.val < 1024 := by have := s2Top1k; omega + exact absurd (hwe'.symm.trans hwe) (fun h => root_tab_ne E hX' ht hj'1k hj h.symm) + · have et := (peAF_injA_s (Nat.mod_eq_zero_of_dvd (E.tal t ht)) (Nat.mod_eq_zero_of_dvd (E.tal t' ht')) hj hj' + (hwe'.symm.trans hwe)).1 + subst et + have := rs2_unique E U hr0 (hS2 _ ha') hR' ha0 + rw [← this] + exact ha' + refine { t2 := ?_, s1 := ?_, out := ?_, inj2 := ?_, rootInj2 := ?_, inj1 := ?_, rootInj1 := ?_, rootOnce := ?_, ptOnce := ?_ } + · intro y hy ptr asid va hcp hT w hw h3 hd + rw [hcap y hy] at hcp + have hw0 := hS2E hw + have hf : mem' w = mem w := hmE w (hw0.foot E.xal) + rw [hf] at h3 hd + obtain ⟨r0, hr0, hws⟩ := U.t2 y hy ptr asid va hcp hT w hw0 h3 hd + have hA' := hActive hr0.active hw hws + obtain ⟨a2, ha2⟩ := S2RootOfAsidA.ofActive hA' + have h2 := hSR _ _ ha2 + have hrr := U.rootInj2 _ _ _ h2 hr0 + refine ⟨r0, (S2RootOfAsidA.congr hrr ha2), hws.of_mem' ?_⟩ + intro t' sh' n' hh + apply hmE _ + rcases hh with ⟨rfl, rfl⟩ | ⟨ht', rfl⟩ + · exact rootFootE hr0.1 (E.xal _ hr0.1) + (Nat.lt_of_lt_of_le (walkIdx_lt va sh' _ (Nat.succ_pos _) (Nat.le_trans s2Top1k (by norm_num))) s2Top1k) + · exact .s2pt t' _ ht' (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + · intro y hy ptr asid va hcp hS tag sh t j hpath htab' h12 hj h3 hd + rw [hcap y hy] at hcp + have p0 := hPold hpath + have hf := hT1 t j htab' hj + rw [hf] at h3 hd + obtain ⟨raw, hact, hw⟩ := U.s1 y hy ptr asid va hcp hS tag sh t j p0 htab' h12 hj h3 hd + obtain ⟨a'', raw'', ha'', hrp''⟩ := RPathA.ofPath hpath + have hrp0 := hrp''.of_mem hT1 + have hS1f : ∀ t' sh', S1TabA S1 Y t' → + mem' (peAF t' (walkIdx va sh' 512)) = mem (peAF t' (walkIdx va sh' 512)) := fun t' sh' h => + hT1 t' _ h (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + have fin : ∀ {tg : U64} {sh0 : Nat} {t0 : U64}, + WalkSlotA (S1TabA S1 Y) mem va t0 sh0 512 (peAF t j) → RPathA S1 Y mem raw tg sh0 t0 → S1TabA S1 Y t0 → + ActiveAsidRootA mem' ksb Pp asid raw := by + intro tg sh0 t0 W hr hb + obtain ⟨t', sh', j', hrp, htb2, hj', hwe⟩ := walk_rpath W rfl hr hb + have et := (peAF_injA_s (S1TabA.mod4k R htab') (S1TabA.mod4k R htb2) hj hj' hwe).1 + subst et + have hq : raw'' = raw := rpath_unique R U hrp0 (hAS _ _ ha'') hrp hact + subst hq + have := U.rootInj1 _ _ _ (hAS _ _ ha'') hact + subst this + exact ha'' + rcases hw with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · refine ⟨raw, fin hws (.native h0 hr) (Or.inl hr), Or.inl ⟨h0, hr, hws.of_mem' ?_⟩⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inl hr) + · exact hS1f _ _ h + · refine ⟨raw, fin hws (.high h2 hy2) (Or.inr ⟨untagA raw, hy2, rfl⟩), Or.inr ⟨h2, hy2, hws.of_mem' ?_⟩⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inr ⟨untagA raw, hy2, rfl⟩) + · exact hS1f _ _ h + · intro y hy ptr asid va hcp + rw [hcap y hy] at hcp + exact U.out y hy ptr asid va hcp + · intro w1 w2 h1 h2 v1 v2 hd hT + have h1' := hS2E h1 + have h2' := hS2E h2 + have f1 : mem' w1 = mem w1 := hmE w1 (h1'.foot E.xal) + have f2 : mem' w2 = mem w2 := hmE w2 (h2'.foot E.xal) + rw [f1] at v1 hd hT + rw [f2] at v2 hd + exact U.inj2 w1 w2 h1' h2' v1 v2 hd hT + · intro a1 a2 r h1 h2 + exact U.rootInj2 a1 a2 r (hSR _ _ h1) (hSR _ _ h2) + · intro tag tag' sh sh' t t' j j' p1 tb1 h12 hj v1 p2 tb2 h12' hj' v2 hd hS + have p1' := hPold p1 + have p2' := hPold p2 + rw [hT1 t j tb1 hj] at v1 hd hS + rw [hT1 t' j' tb2 hj'] at v2 hd + exact U.inj1 tag tag' sh sh' t t' j j' p1' tb1 h12 hj v1 p2' tb2 h12' hj' v2 hd hS + · intro a1 a2 raw h1 h2 + exact U.rootInj1 a1 a2 raw (hAS _ _ h1) (hAS _ _ h2) + · refine U.rootOnce.step (RootClosedA.pos (fun y hy r h => ?_) (fun y hy r h => ?_)) (fun r hI => ?_) + · rw [hcap y hy] at h; exact h + · rw [hcap y hy] at h; exact h + · exact hI.imp (fun ⟨a, raw, h, e⟩ => ⟨a, raw, hAS _ _ h, e⟩) (fun ⟨a, h⟩ => ⟨a, hSR _ _ h⟩) + · exact U.ptOnce.step (UClosed.pos (fun y hy r h => by rw [hcap y hy] at h; exact h) + (fun y hy r h => by rw [hcap y hy] at h; exact h)).toE + +/-- **`VsUniqA` across DelAsid's pool-entry clear** (`mem'` is `mem` with the word of pool `p` at `i` zeroed, the +spec pool's entry removed). -/ +theorem VsUniqA.of_clearPool {p i : U64} {f : Fl4SpecA64.AsidPool} + (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (R : VsRelA Pp S1 Lv X Y mem ksb σ) + (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) + (hp : p ∈ Pp) (hi : i.val < 512) (hk : σ.kheap (specPtr p) = some (.archObj (.asidPool f))) + (hoff : ∀ b, VsFootA ∅ S1 Y ksb b → b ≠ peAF p i) + (hm : ∀ b, VsFootA Pp S1 Y ksb b → b ≠ peAF p i → mem' b = mem b) + (hmE : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) (hwrite : mem' (peAF p i) = 0#u64) + (hσk : σ'.kheap (specPtr p) = + some (.archObj (.asidPool (Function.update f (BitVec.ofNat 9 i.val) none)))) + (hσo : ∀ q, q ≠ p → σ'.kheap (specPtr q) = σ.kheap (specPtr q)) + (hσt : σ'.archState.armAsidTable = σ.archState.armAsidTable) + (hcap : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y) : + VsUniqA th Pp S1 X Y T2 Sh2 mem' ksb σ' := by + have hal := Nat.mod_eq_zero_of_dvd (R.pal p hp) + have hword : ∀ q ∈ Pp, ∀ j : U64, j.val < 512 → peAF q j = peAF p i → q = p ∧ j = i := + fun q hq j hj => peAF_injA_s (Nat.mod_eq_zero_of_dvd (R.pal q hq)) hal hj hi + have hmV : ∀ b, VsFootA ∅ S1 Y ksb b → mem' b = mem b := fun b hb => + hm b (by + cases hb with + | asid j hj => exact .asid j hj + | pool q j hq hj => exact absurd hq (Set.notMem_empty q) + | pt q j hq hj => exact .pt q j hq hj + | high y j hy hj => exact .high y j hy hj) (hoff b hb) + have hT1 : ∀ t j : U64, S1TabA S1 Y t → j.val < 512 → mem' (peAF t j) = mem (peAF t j) := by + intro t j htb hj + rcases htb with ht | ⟨y0, hy0, rfl⟩ + · exact hmV _ (.pt t j ht hj) + · exact hmV _ (.high y0 j hy0 hj) + have hHeap : ∀ p' g, σ'.kheap (specPtr p') = some (.archObj (.asidPool g)) → + (σ.kheap (specPtr p') = some (.archObj (.asidPool g))) ∨ + (p' = p ∧ g = Function.update f (BitVec.ofNat 9 i.val) none) := by + intro p' g h + by_cases e : p' = p + · right + subst e + rw [hσk] at h + cases h + exact ⟨rfl, rfl⟩ + · left + rw [hσo p' e] at h + exact h + refine VsUniqA.of_clear U R E hmE hT1 ?_ ?_ ?_ hcap + · rintro a r ⟨hj, lo, hhj, hlo, ha', pool, hpool, hpne, htab', hpe, hrne⟩ + have htab : mem' (atAF ksb hj) = mem (atAF ksb hj) := + hm _ (.asid hj hhj) (hoff _ (.asid hj hhj)) + rw [htab] at htab' + by_cases he : peAF pool lo = peAF p i + · rw [he, hwrite] at hpe + exact absurd hpe.symm hrne + · rw [hm _ (.pool pool lo hpool hlo) he] at hpe + exact ⟨hj, lo, hhj, hlo, ha', pool, hpool, hpne, htab', hpe, hrne⟩ + · rintro r ⟨hr, asid, p', f', h0, hp', htab', hkh', hf'⟩ + rw [hσt] at htab' + rcases hHeap p' f' hkh' with hk0 | ⟨hpp, hg⟩ + · exact ⟨hr, asid, p', f', h0, hp', htab', hk0, hf'⟩ + · rw [hg] at hf' + by_cases hlo : Fl4SpecA64.asidLowBitsOf asid = BitVec.ofNat 9 i.val + · rw [hlo, Function.update_self] at hf' + cases hf' + · rw [Function.update_of_ne hlo] at hf' + exact ⟨hr, asid, p', f, h0, hp', htab', by rw [hpp]; exact hk, hf'⟩ + · rintro a r ⟨hr, p', f', h0, hp', htab', hkh', hf'⟩ + rw [hσt] at htab' + rcases hHeap p' f' hkh' with hk0 | ⟨hpp, hg⟩ + · exact ⟨hr, p', f', h0, hp', htab', hk0, hf'⟩ + · rw [hg] at hf' + by_cases hlo : Fl4SpecA64.asidLowBitsOf (BitVec.ofNat 16 a.val) = BitVec.ofNat 9 i.val + · rw [hlo, Function.update_self] at hf' + cases hf' + · rw [Function.update_of_ne hlo] at hf' + exact ⟨hr, p', f, h0, hp', htab', by rw [hpp]; exact hk, hf'⟩ + +/-- **`VsUniqA` across DelAsidPool's ASID-table word clear** (`mem'` is `mem` with the word `i` zeroed, the spec's table +entry removed, the pools kept). -/ +theorem VsUniqA.of_clearTab {i : U64} (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) + (R : VsRelA Pp S1 Lv X Y mem ksb σ) (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) (hi : i.val < 128) + (hk : ksb.val + 788736 ≤ 2 ^ 64) + (hm : ∀ b, VsFootA Pp S1 Y ksb b → b ≠ atAF ksb i → mem' b = mem b) + (h0 : mem' (atAF ksb i) = 0#u64) + (hpg : ∀ q j : U64, j.val < 512 → (q ∈ Pp ∨ q ∈ S1 ∨ ∃ y ∈ Y, q = wa y 4096#u64) → peAF q j ≠ atAF ksb i) + (hmE : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) + (hσt : ∀ k q, σ'.archState.armAsidTable k = some q → σ.archState.armAsidTable k = some q) + (hσk : ∀ q, σ'.kheap q = σ.kheap q) + (hcap : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y) : + VsUniqA th Pp S1 X Y T2 Sh2 mem' ksb σ' := by + have hneAt : ∀ j : U64, j.val < 128 → j ≠ i → atAF ksb j ≠ atAF ksb i := by + intro j hj hne e + have hv := congrArg UScalar.val e + rw [atAF_valA hk hj, atAF_valA hk hi] at hv + exact hne (UScalar.eq_of_val_eq (by omega)) + have hT1 : ∀ t j : U64, S1TabA S1 Y t → j.val < 512 → mem' (peAF t j) = mem (peAF t j) := by + intro t j htb hj + rcases htb with ht | ⟨y0, hy0, rfl⟩ + · exact hm _ (.pt t j ht hj) (hpg t j hj (Or.inr (Or.inl ht))) + · exact hm _ (.high y0 j hy0 hj) (hpg _ j hj (Or.inr (Or.inr ⟨y0, hy0, rfl⟩))) + refine VsUniqA.of_clear U R E hmE hT1 ?_ ?_ ?_ hcap + · rintro a r ⟨hj, lo, hhj, hlo, ha', pool, hpool, hpne, htab', hpe, hrne⟩ + by_cases he : hj = i + · rw [he, h0] at htab' + exact absurd htab'.symm hpne + · rw [hm _ (.asid hj hhj) (hneAt hj hhj he)] at htab' + rw [hm _ (.pool pool lo hpool hlo) (hpg pool lo hlo (Or.inl hpool))] at hpe + exact ⟨hj, lo, hhj, hlo, ha', pool, hpool, hpne, htab', hpe, hrne⟩ + · rintro r ⟨hr, asid, p', f', h0', hp', htab', hkh', hf'⟩ + exact ⟨hr, asid, p', f', h0', hp', hσt _ _ htab', by rw [← hσk]; exact hkh', hf'⟩ + · rintro a r ⟨hr, p', f', h0', hp', htab', hkh', hf'⟩ + exact ⟨hr, p', f', h0', hp', hσt _ _ htab', by rw [← hσk]; exact hkh', hf'⟩ + +end clear + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsUniqGrowA.lean b/proofs/Fl4ProofsA64/P3/VsUniqGrowA.lean new file mode 100644 index 000000000..39d935dde --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUniqGrowA.lean @@ -0,0 +1,128 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, G): **`VsUniqA` across growing the pool set** (`VsUniqA.of_poolGrow`): the +pool set changes from `Pp` to `Pp'` (a new, empty pool is installed in `armAsidTable`) while the Stage-1/Stage-2 +tables keep their words. The transfer is phrased by the ASID-root activity of both states (`hA1`/`hA2` for Stage-1 +roots, `hR1`..`hR3` for Stage-2 roots), so no pool-specific fact is needed here. No premise. New module. +-/ +import Fl4ProofsA64.P3.VsUniqA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section grow +variable {th : TypedHeapA} {Pp Pp' S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem mem' : U64 → U64} {ksb : U64} + {σ σ' : Fl4SpecA64.State Unit} + +theorem S2ReachA.of_grow (hxal : ∀ r ∈ X, 8192 ∣ r.val) (hmE : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) + (hR1 : ∀ r, ActiveS2RootA Pp' X σ' r → ActiveS2RootA Pp X σ r) {q : U64} + (h : S2ReachA Pp' X T2 Sh2 mem' σ' q) : S2ReachA Pp X T2 Sh2 mem σ q := by + induction h with + | root ha => exact .root (hR1 _ ha) + | @stepRoot r i ha hi h3 hT => + have e : mem' (peAF r i) = mem (peAF r i) := + hmE _ (rootFootE ha.1 (hxal r ha.1) (Nat.lt_of_lt_of_le hi s2Top1k)) + rw [e] at h3 hT ⊢ + exact .stepRoot (hR1 _ ha) hi h3 hT + | @stepPt t i hr ht h12 hi h3 hT ih => + have e : mem' (peAF t i) = mem (peAF t i) := hmE _ (.s2pt t i ht hi) + rw [e] at h3 hT ⊢ + exact .stepPt ih ht h12 hi h3 hT + +theorem S2EntryA.of_grow (hxal : ∀ r ∈ X, 8192 ∣ r.val) (hmE : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) + (hR1 : ∀ r, ActiveS2RootA Pp' X σ' r → ActiveS2RootA Pp X σ r) {w : U64} + (h : S2EntryA Pp' X T2 Sh2 mem' σ' w) : S2EntryA Pp X T2 Sh2 mem σ w := by + rcases h with ⟨r, i, hr, hi, e⟩ | ⟨t, i, hr, ht2, h12, hi, e⟩ + · exact Or.inl ⟨r, i, hR1 _ hr, hi, e⟩ + · exact Or.inr ⟨t, i, S2ReachA.of_grow hxal hmE hR1 hr, ht2, h12, hi, e⟩ + +theorem VsPathA.of_grow (hmT : ∀ t i : U64, S1TabA S1 Y t → i.val < 512 → mem' (peAF t i) = mem (peAF t i)) + (hA1 : ∀ a raw, ActiveAsidRootA mem' ksb Pp' a raw → ActiveAsidRootA mem ksb Pp a raw) + {tag : U64} {sh : Nat} {p : U64} (h : VsPathA Pp' S1 Y mem' ksb tag sh p) : + VsPathA Pp S1 Y mem ksb tag sh p := by + induction h with + | native hact htag htb => exact .native (hA1 _ _ hact) htag htb + | high hact htag hy => exact .high (hA1 _ _ hact) htag hy + | @child tag t i sh _ htY h12 hi h3 ih => + have hpe : mem' (peAF t i) = mem (peAF t i) := hmT t i htY hi + rw [hpe] at h3 ⊢ + exact .child ih htY h12 hi h3 + +theorem VsUniqA.of_poolGrow (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (hmE : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) + (hmT : ∀ t i : U64, S1TabA S1 Y t → i.val < 512 → mem' (peAF t i) = mem (peAF t i)) + (hA1 : ∀ a raw, ActiveAsidRootA mem' ksb Pp' a raw → ActiveAsidRootA mem ksb Pp a raw) + (hA2 : ∀ a raw, ActiveAsidRootA mem ksb Pp a raw → ActiveAsidRootA mem' ksb Pp' a raw) + (hR1 : ∀ r, ActiveS2RootA Pp' X σ' r → ActiveS2RootA Pp X σ r) + (hR2 : ∀ a r, S2RootOfAsidA Pp' X σ' a r → S2RootOfAsidA Pp X σ a r) + (hR3 : ∀ a r, S2RootOfAsidA Pp X σ a r → S2RootOfAsidA Pp' X σ' a r) + (hc : PtClosedA th S1 T2 mem mem') : + VsUniqA th Pp' S1 X Y T2 Sh2 mem' ksb σ' where + t2 y hy ptr asid va hcap hT w hw' h3 hd := by + obtain ⟨yc, hyc, hcap0⟩ := (hc.pt y hy ptr asid va true hcap).resolve_right + (fun h => h.elim (fun h => h.2 hT) (fun h => h.2 hT)) + have hw0 := S2EntryA.of_grow hxal hmE hR1 hw' + have hf : mem' w = mem w := hmE w (hw0.foot hxal) + rw [hf] at h3 hd + obtain ⟨r, hr, hws⟩ := U.t2 yc hyc ptr asid va hcap0 hT w hw0 h3 hd + refine ⟨r, hR3 _ _ hr, hws.of_mem' ?_⟩ + intro t' sh' n' hh + apply hmE + rcases hh with ⟨rfl, rfl⟩ | ⟨ht', rfl⟩ + · exact rootFootE hr.1 (hxal _ hr.1) + (Nat.lt_of_lt_of_le (walkIdx_lt va sh' _ (Nat.succ_pos _) (Nat.le_trans s2Top1k (by norm_num))) s2Top1k) + · exact .s2pt t' _ ht' (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + s1 y hy ptr asid va hcap hS tag sh t i hpath htab h12 hi h3 hd := by + obtain ⟨yc, hyc, hcap0⟩ := (hc.pt y hy ptr asid va true hcap).resolve_right + (fun h => h.elim (fun h => h.1 hS) (fun h => by cases h.1)) + have path0 := VsPathA.of_grow hmT hA1 hpath + have hf : mem' (peAF t i) = mem (peAF t i) := hmT t i htab hi + rw [hf] at h3 hd + obtain ⟨raw, hact, hw⟩ := U.s1 yc hyc ptr asid va hcap0 hS tag sh t i path0 htab h12 hi h3 hd + have hS1f : ∀ t' sh', S1TabA S1 Y t' → + mem' (peAF t' (walkIdx va sh' 512)) = mem (peAF t' (walkIdx va sh' 512)) := fun t' sh' h => + hmT t' _ h (walkIdx_lt va sh' 512 (by norm_num) (by norm_num)) + refine ⟨raw, hA2 _ _ hact, ?_⟩ + rcases hw with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · refine Or.inl ⟨h0, hr, hws.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inl hr) + · exact hS1f _ _ h + · refine Or.inr ⟨h2, hy2, hws.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inr ⟨untagA raw, hy2, rfl⟩) + · exact hS1f _ _ h + out y hy ptr asid va hcap := by + rcases hc.pt y hy ptr asid va false hcap with ⟨yc, hyc, hcap0⟩ | hu + · exact U.out yc hyc ptr asid va hcap0 + · exact hu.elim (fun h => h.2) (fun h => h.2) + inj2 w1 w2 h1 h2 v1 v2 hd hT := by + have h1' := S2EntryA.of_grow hxal hmE hR1 h1 + have h2' := S2EntryA.of_grow hxal hmE hR1 h2 + have f1 : mem' w1 = mem w1 := hmE w1 (h1'.foot hxal) + have f2 : mem' w2 = mem w2 := hmE w2 (h2'.foot hxal) + rw [f1] at v1 hd hT + rw [f2] at v2 hd + exact U.inj2 w1 w2 h1' h2' v1 v2 hd hT + rootInj2 a1 a2 r h1 h2 := U.rootInj2 a1 a2 r (hR2 _ _ h1) (hR2 _ _ h2) + inj1 tag tag' sh sh' t t' i i' p1 tb1 h12 hi v1 p2 tb2 h12' hi' v2 hd hS := by + rw [hmT t i tb1 hi] at v1 hd hS + rw [hmT t' i' tb2 hi'] at v2 hd + exact U.inj1 tag tag' sh sh' t t' i i' (VsPathA.of_grow hmT hA1 p1) tb1 h12 hi v1 + (VsPathA.of_grow hmT hA1 p2) tb2 h12' hi' v2 hd hS + rootInj1 a1 a2 raw h1 h2 := U.rootInj1 a1 a2 raw (hA1 _ _ h1) (hA1 _ _ h2) + rootOnce := U.rootOnce.step hc.root (fun r hI => by + rcases hI with ⟨a, raw, h1, e⟩ | ⟨a, h1⟩ + · exact Or.inl ⟨a, raw, hA1 _ _ h1, e⟩ + · exact Or.inr ⟨a, hR2 _ _ h1⟩) + ptOnce := U.ptOnce.step hc.ptu + +end grow + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsUniqLinkA.lean b/proofs/Fl4ProofsA64/P3/VsUniqLinkA.lean new file mode 100644 index 000000000..782644672 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUniqLinkA.lean @@ -0,0 +1,203 @@ +/- +P3 (aarch64, Stage 5 vsinv): **`VsUniqA` across linking a fresh Stage-1 table** (`VsUniqA.of_link`): one invalid +descriptor of a related table `p` is replaced by a table descriptor naming a zero table `ptr ∉ S1`, and `ptr` joins +`S1`. No page-table cap other than ones mapped at `(asid, va)` names `ptr`, and the written slot is on the walk of +`(asid, va)`. No premise. New module. +-/ +import Fl4ProofsA64.P3.VsUniqShrinkA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 Lv : U64 → Nat} {mem mem' : U64 → U64} {ksb : U64} + {σ σ' : Fl4SpecA64.State Unit} + +/-- A walk of the old tables survives writing an invalid slot (and growing the tracked set). -/ +theorem WalkSlotA.of_linkA {ptr b va w : U64} {sh n : Nat} {t : U64} + (hword : ∀ t i : U64, S1TabA S1 Y t → i.val < 512 → peAF t i ≠ b → mem' (peAF t i) = mem (peAF t i)) + (hold : (mem b &&& 3#u64) ≠ 3#u64) (hn : n = 512) (ht : S1TabA S1 Y t) + (h : WalkSlotA (S1TabA S1 Y) mem va t sh n w) : + WalkSlotA (S1TabA (insert ptr S1) Y) mem' va t sh n w := by + induction h with + | here t sh n => exact .here t sh n + | @down t sh n w h3 h12 hP hw ih => + subst hn + have hi := walkIdx_lt va sh 512 (by norm_num) (by norm_num) + have e : mem' (peAF t (walkIdx va sh 512)) = mem (peAF t (walkIdx va sh 512)) := + hword _ _ ht hi (fun c => hold (c ▸ h3)) + refine .down t sh 512 w ?_ h12 ?_ ?_ + · rw [e]; exact h3 + · rw [e]; exact hP.imp (Set.mem_insert_of_mem _) id + · rw [e]; exact ih rfl hP + +theorem VsUniqA.of_link (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (R : VsRelA Pp S1 Lv X Y mem ksb σ) + (hxal : ∀ r ∈ X, 8192 ∣ r.val) + {p i0 ptr asid va : U64} (hp : S1TabA S1 Y p) (hi0 : i0.val < 512) + (hptr : ptr ∉ S1) (hpal : ptr.val % 4096 = 0) (hpy : ∀ y ∈ Y, wa y 4096#u64 ≠ ptr) + (hm : ∀ w, Aligned w → w ≠ peAF p i0 → mem' w = mem w) + (hold : (mem (peAF p i0) &&& 3#u64) ≠ 3#u64) + (hdn : dTabA (mem' (peAF p i0)) = ptr) + (hz : ∀ j : U64, j.val < 512 → (mem' (peAF ptr j) &&& 3#u64) ≠ 3#u64) + (hE : ∀ b, ExtFootE X Y T2 b → mem' b = mem b) + (hA : ∀ b, AsidWordsA Pp ksb b → mem' b = mem b) + (hP : PoolKeepA Pp σ σ') + (hcap : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y) + (hnm : ∀ y, IsSlotA th y → ∀ a v : U64, capAtA mem y = .PageTable ptr true a v → a = asid ∧ v = va) + (hw : ∃ raw, ActiveAsidRootA mem ksb Pp asid raw ∧ + ((tagA raw = 0 ∧ raw ∈ S1 ∧ WalkSlotA (S1TabA S1 Y) mem va raw 39 512 (peAF p i0)) ∨ + (tagA raw = 2 ∧ untagA raw ∈ Y ∧ + WalkSlotA (S1TabA S1 Y) mem va (wa (untagA raw) 4096#u64) 30 512 (peAF p i0)))) : + VsUniqA th Pp (insert ptr S1) X Y T2 Sh2 mem' ksb σ' := by + have hmod : ∀ t, S1TabA S1 Y t → t.val % 4096 = 0 := fun t h => S1TabA.mod4k R h + have hword : ∀ t i : U64, S1TabA S1 Y t → i.val < 512 → peAF t i ≠ peAF p i0 → mem' (peAF t i) = mem (peAF t i) := + fun t i ht hi hne => hm _ (peAF_alignedA (hmod t ht) hi) hne + have htabO : ∀ t, S1TabA (insert ptr S1) Y t → t ≠ ptr → S1TabA S1 Y t := fun t h hne => + h.imp (fun h' => (Set.mem_insert_iff.1 h').resolve_left hne) id + have hA' : ∀ b, AsidWordsA Pp ksb b → mem b = mem' b := fun b hb => (hA b hb).symm + have hact0 : ∀ a raw, ActiveAsidRootA mem' ksb Pp a raw → ActiveAsidRootA mem ksb Pp a raw := + fun a raw h => h.shrink hA + have hact1 : ∀ a raw, ActiveAsidRootA mem ksb Pp a raw → ActiveAsidRootA mem' ksb Pp a raw := + fun a raw h => ActiveAsidRootA.shrink (mem := mem') (mem' := mem) hA' h + have path : ∀ {tag : U64} {sh : Nat} {t : U64}, VsPathA Pp (insert ptr S1) Y mem' ksb tag sh t → + t = ptr ∨ VsPathA Pp S1 Y mem ksb tag sh t := by + intro tag sh t h + induction h with + | @native a raw hact htag htb => + have h0 := hact0 _ _ hact + obtain ⟨pool, hpool, hactP, lo, hlo, hwd, hrne⟩ := h0.activePool + have hk := R.kind pool hpool hactP lo hlo + rw [hwd] at hk + rcases hk with rfl | ⟨-, hu, -⟩ | ⟨h1, -⟩ | ⟨h2, -⟩ + · exact absurd rfl hrne + · have hr : untagA raw = raw := by + apply UScalar.eq_of_val_eq + have h4 : raw.val % 4 = 0 := htag + unfold untagA + rw [UScalar.val_and] + have e : (18446744073709551612#u64 : U64).val = (2 ^ 62 - 1) * 2 ^ 2 := by rfl + rw [e] + have hlt : raw.val < 2 ^ 64 := raw.bv.isLt + apply Nat.eq_of_testBit_eq + intro i + rw [Nat.testBit_and, Nat.testBit_mul_two_pow, Nat.testBit_two_pow_sub_one] + by_cases h2 : 2 ≤ i + · by_cases h64 : i < 64 + · simp [h2, show i - 2 < 62 by omega] + · rw [Nat.testBit_lt_two_pow (Nat.lt_of_lt_of_le hlt (Nat.pow_le_pow_right (by omega) (by omega)))] + simp + · have : raw.val.testBit i = false := by + have hm : raw.val = 4 * (raw.val / 4) := by omega + rw [hm, show (4 : Nat) = 2 ^ 2 by rfl, Nat.testBit_two_pow_mul] + simp [h2] + simp [this] + rw [hr] at hu + exact Or.inr (.native h0 htag hu) + · omega + · omega + | @high a raw hact htag hy => exact Or.inr (.high (hact0 _ _ hact) htag hy) + | @child tag t i sh hpar htY h12 hi h3 ih => + have htne : t ≠ ptr := fun e => hz i hi (e ▸ h3) + have hpar0 := ih.resolve_left htne + have htb := htabO t htY htne + by_cases hb : peAF t i = peAF p i0 + · rw [hb, hdn]; exact Or.inl rfl + · rw [hword t i htb hi hb] at h3 ⊢ + exact Or.inr (.child hpar0 htb h12 hi h3) + have hwalk : ∀ (t va : U64) (sh : Nat) (w : U64), S1TabA S1 Y t → WalkSlotA (S1TabA S1 Y) mem va t sh 512 w → + WalkSlotA (S1TabA (insert ptr S1) Y) mem' va t sh 512 w := fun t va sh w ht h => + h.of_linkA hword hold rfl ht + have hraw : ∀ (a v w : U64), (∃ raw, ActiveAsidRootA mem ksb Pp a raw ∧ + ((tagA raw = 0 ∧ raw ∈ S1 ∧ WalkSlotA (S1TabA S1 Y) mem v raw 39 512 w) ∨ + (tagA raw = 2 ∧ untagA raw ∈ Y ∧ WalkSlotA (S1TabA S1 Y) mem v (wa (untagA raw) 4096#u64) 30 512 w))) → + ∃ raw, ActiveAsidRootA mem' ksb Pp a raw ∧ + ((tagA raw = 0 ∧ raw ∈ insert ptr S1 ∧ WalkSlotA (S1TabA (insert ptr S1) Y) mem' v raw 39 512 w) ∨ + (tagA raw = 2 ∧ untagA raw ∈ Y ∧ + WalkSlotA (S1TabA (insert ptr S1) Y) mem' v (wa (untagA raw) 4096#u64) 30 512 w)) := by + rintro a v w ⟨raw, hact, h⟩ + refine ⟨raw, hact1 _ _ hact, ?_⟩ + rcases h with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · exact Or.inl ⟨h0, Set.mem_insert_of_mem _ hr, hwalk _ _ _ _ (Or.inl hr) hws⟩ + · exact Or.inr ⟨h2, hy2, hwalk _ _ _ _ (Or.inr ⟨_, hy2, rfl⟩) hws⟩ + have s2f : ∀ w, S2EntryA Pp X T2 Sh2 mem' σ' w → S2EntryA Pp X T2 Sh2 mem σ w ∧ mem' w = mem w := by + intro w h + have h' := S2EntryA.of_frame hxal hE hP.1 hP.2 h + exact ⟨h', hE w (h'.foot hxal)⟩ + constructor + · intro y hy ptr' a v hc hT w hw' h3 hd + rw [hcap y hy] at hc + obtain ⟨hw0, hf⟩ := s2f w hw' + rw [hf] at h3 hd + obtain ⟨r, hr, hws⟩ := U.t2 y hy ptr' a v hc hT w hw0 h3 hd + refine ⟨r, hr.of_spec hP.1 hP.2, hws.of_mem' ?_⟩ + intro t' sh' n' hh + apply hE + rcases hh with ⟨rfl, rfl⟩ | ⟨ht', rfl⟩ + · exact rootFootE hr.1 (hxal _ hr.1) + (Nat.lt_of_lt_of_le (walkIdx_lt v sh' _ (Nat.succ_pos _) (Nat.le_trans s2Top1k (by norm_num))) s2Top1k) + · exact .s2pt t' _ ht' (walkIdx_lt v sh' 512 (by norm_num) (by norm_num)) + · intro y hy ptr' a v hc _ tag sh t i hpath htab h12 hi h3 hd + rw [hcap y hy] at hc + have htne : t ≠ ptr := fun e => hz i hi (e ▸ h3) + have path0 := (path hpath).resolve_left htne + have htab0 := htabO t htab htne + by_cases hb : peAF t i = peAF p i0 + · rw [hb, hdn] at hd + subst hd + obtain ⟨rfl, rfl⟩ := hnm y hy a v hc + rw [hb]; exact hraw _ _ _ hw + · rw [hword t i htab0 hi hb] at h3 hd + have hS : ptr' ∈ S1 := hd ▸ R.child_tb path0 htab0 h12 hi h3 + exact hraw _ _ _ (U.s1 y hy ptr' a v hc hS tag sh t i path0 htab0 h12 hi h3 hd) + · intro y hy ptr' a v hc + rw [hcap y hy] at hc + exact U.out y hy ptr' a v hc + · intro w1 w2 h1 h2 v1 v2 hd hT + obtain ⟨h1', f1⟩ := s2f w1 h1 + obtain ⟨h2', f2⟩ := s2f w2 h2 + rw [f1] at v1 hd hT + rw [f2] at v2 hd + exact U.inj2 w1 w2 h1' h2' v1 v2 hd hT + · intro a1 a2 r h1 h2 + exact U.rootInj2 a1 a2 r (S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h1) + (S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h2) + · intro tag tag' sh sh' t t' i i' p1 tb1 h12 hi v1 p2 tb2 h12' hi' v2 hd _ + have hne1 : t ≠ ptr := fun e => hz i hi (e ▸ v1) + have hne2 : t' ≠ ptr := fun e => hz i' hi' (e ▸ v2) + have q1 := (path p1).resolve_left hne1 + have q2 := (path p2).resolve_left hne2 + have b1 := htabO t tb1 hne1 + have b2 := htabO t' tb2 hne2 + by_cases c1 : peAF t i = peAF p i0 + · by_cases c2 : peAF t' i' = peAF p i0 + · rw [c1, c2] + · rw [c1, hdn, hword t' i' b2 hi' c2] at hd + rw [hword t' i' b2 hi' c2] at v2 + exact absurd (hd ▸ R.child_tb q2 b2 h12' hi' v2) hptr + · rw [hword t i b1 hi c1] at v1 hd + by_cases c2 : peAF t' i' = peAF p i0 + · rw [c2, hdn] at hd + exact absurd (hd ▸ R.child_tb q1 b1 h12 hi v1) hptr + · rw [hword t' i' b2 hi' c2] at v2 hd + exact U.inj1 tag tag' sh sh' t t' i i' q1 b1 h12 hi v1 q2 b2 h12' hi' v2 hd (R.child_tb q1 b1 h12 hi v1) + · intro a1 a2 raw h1 h2 + exact U.rootInj1 a1 a2 raw (hact0 _ _ h1) (hact0 _ _ h2) + · intro y hy r h + rw [hcap y hy] at h + obtain ⟨hn, hu⟩ := U.rootOnce y hy r h + refine ⟨fun hi => hn (hi.imp (fun ⟨a, raw, h, e⟩ => ⟨a, raw, hact0 _ _ h, e⟩) + (fun ⟨a, h⟩ => ⟨a, S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h⟩)), fun z hz hk => ?_⟩ + rw [hcap z hz] at hk + exact hu z hz hk + · intro y hy r h z hz hk + rw [hcap y hy] at h + rw [hcap z hz] at hk + exact U.ptOnce y hy r h z hz hk + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsUniqLinkS2A.lean b/proofs/Fl4ProofsA64/P3/VsUniqLinkS2A.lean new file mode 100644 index 000000000..0e40d806c --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUniqLinkS2A.lean @@ -0,0 +1,244 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, G): **`VsUniqA` across linking a fresh Stage-2 table** (`VsUniqA.of_linkS2`): +one invalid descriptor `w0` of a reachable Stage-2 table or root is replaced by a table descriptor naming a zero table +`ptr ∉ T2`, and `ptr` joins `T2` (its shift `n` recorded in `Sh2`). The cap of `ptr` that was unmapped is now mapped at +`(asid, va)`, and `w0` is on the walk of `va` from the root installed at `asid`. The facts about caps are inputs: +the new cap is the only mapped cap naming `ptr` (`hcap`, `hmapped`) and no unmapped cap names it afterwards (`hOutU`, +from the unmapped-table-cap uniqueness conjunct). No premise. New module. +-/ +import Fl4ProofsA64.P3.VsWalkS2A +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section link2 +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem mem' : U64 → U64} {ksb : U64} + {σ σ' : Fl4SpecA64.State Unit} + +/-- A walk whose read words are kept or the one overwritten (which was not a valid descriptor) survives. -/ +theorem WalkSlotA.of_link2 {P Q : U64 → Prop} (hPQ : ∀ x, P x → Q x) {w0 va t0 : U64} {n0 : Nat} + (hword : ∀ t' sh' n', ((t' = t0 ∧ n' = n0) ∨ (P t' ∧ n' = 512)) → + peAF t' (walkIdx va sh' n') ≠ w0 → mem' (peAF t' (walkIdx va sh' n')) = mem (peAF t' (walkIdx va sh' n'))) + (hold : (mem w0 &&& 3#u64) ≠ 3#u64) {t w : U64} {sh n : Nat} + (hc : (t = t0 ∧ n = n0) ∨ (P t ∧ n = 512)) + (h : WalkSlotA P mem va t sh n w) : WalkSlotA Q mem' va t sh n w := by + induction h with + | here t sh n => exact .here t sh n + | @down t sh n w h3 h12 hP hw ih => + have hne : peAF t (walkIdx va sh n) ≠ w0 := fun e => hold (e ▸ h3) + have e : mem' (peAF t (walkIdx va sh n)) = mem (peAF t (walkIdx va sh n)) := hword t sh n hc hne + refine .down t sh n w ?_ h12 ?_ ?_ + · rw [e]; exact h3 + · rw [e]; exact hPQ _ hP + · rw [e]; exact ih (Or.inr ⟨hP, rfl⟩) + +variable {ptr w0 : U64} {n : Nat} + +/-- Stage-2 reach after the link was reach before, or the new table. -/ +theorem S2ReachA.of_link2 (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (hptr : ptr ∉ T2) (hm : ∀ b, ExtFootE X Y T2 b → b ≠ w0 → mem' b = mem b) + (hP : PoolKeepA Pp σ σ') (hdn : dTabA (mem' w0) = ptr) + (hz : ∀ j : U64, j.val < 512 → (mem' (peAF ptr j) &&& 3#u64) ≠ 3#u64) {q : U64} + (h : S2ReachA Pp X (insert ptr T2) (Function.update Sh2 ptr n) mem' σ' q) : + q = ptr ∨ S2ReachA Pp X T2 Sh2 mem σ q := by + induction h with + | root ha => exact Or.inr (.root (ha.of_spec hP.1 hP.2)) + | @stepRoot r i ha hi h3 hT => + have hf : ExtFootE X Y T2 (peAF r i) := rootFootE ha.1 (hxal r ha.1) (Nat.lt_of_lt_of_le hi s2Top1k) + by_cases e : peAF r i = w0 + · left; rw [e, hdn] + · right + have ha0 := ha.of_spec hP.1 hP.2 + have e2 := hm _ hf e + rw [e2] at h3 hT ⊢ + have hch := (s2_root_childA E ha0.1 ha0 hi h3).1 + exact .stepRoot ha0 hi h3 hch + | @stepPt t i hr ht h12 hi h3 hT ih => + by_cases etp : t = ptr + · subst etp; exact absurd h3 (hz i hi) + · have ht0 : t ∈ T2 := (Set.mem_insert_iff.1 ht).resolve_left etp + have ih0 : S2ReachA Pp X T2 Sh2 mem σ t := ih.resolve_left etp + have h12' : 12 < Sh2 t := by simpa [Function.update_of_ne etp] using h12 + have hf : ExtFootE X Y T2 (peAF t i) := .s2pt t i ht0 hi + by_cases e : peAF t i = w0 + · left; rw [e, hdn] + · right + have e2 := hm _ hf e + rw [e2] at h3 hT ⊢ + have hch := (s2_child_validA E ih0 ht0 h12' hi h3).1 + exact .stepPt ih0 ht0 h12' hi h3 hch + +/-- A valid word of a reachable Stage-2 entry names a tracked table. -/ +theorem s2Entry_childA (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {w : U64} + (h : S2EntryA Pp X T2 Sh2 mem σ w) (h3 : (mem w &&& 3#u64) = 3#u64) : dTabA (mem w) ∈ T2 := by + rcases h with ⟨r, i, ha, hi, e⟩ | ⟨t, i, hr, ht, h12, hi, e⟩ + · subst e; exact (s2_root_childA E ha.1 ha hi h3).1 + · subst e; exact (s2_child_validA E hr ht h12 hi h3).1 + +theorem S2EntryA.of_link2 (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (hptr : ptr ∉ T2) (hm : ∀ b, ExtFootE X Y T2 b → b ≠ w0 → mem' b = mem b) + (hP : PoolKeepA Pp σ σ') (hdn : dTabA (mem' w0) = ptr) + (hz : ∀ j : U64, j.val < 512 → (mem' (peAF ptr j) &&& 3#u64) ≠ 3#u64) {w : U64} + (h : S2EntryA Pp X (insert ptr T2) (Function.update Sh2 ptr n) mem' σ' w) : + S2EntryA Pp X T2 Sh2 mem σ w ∨ ∃ j : U64, j.val < 512 ∧ w = peAF ptr j := by + rcases h with ⟨r, i, ha, hi, e⟩ | ⟨t, i, hr, ht, h12, hi, e⟩ + · exact Or.inl (Or.inl ⟨r, i, ha.of_spec hP.1 hP.2, hi, e⟩) + · by_cases etp : t = ptr + · subst etp; exact Or.inr ⟨i, hi, e⟩ + · have ht0 : t ∈ T2 := (Set.mem_insert_iff.1 ht).resolve_left etp + have h12' : 12 < Sh2 t := by simpa [Function.update_of_ne etp] using h12 + have hr0 := (S2ReachA.of_link2 E hxal hptr hm hP hdn hz hr).resolve_left etp + exact Or.inl (Or.inr ⟨t, i, hr0, ht0, h12', hi, e⟩) + +theorem VsUniqA.of_linkS2 (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) + {asid va : U64} (hptr : ptr ∉ T2) (hnt : ptr ∉ S1) + (hmE : ∀ b, ExtFootE X Y T2 b → b ≠ w0 → mem' b = mem b) + (hV : ∀ b, VsFootA Pp S1 Y ksb b → mem' b = mem b) + (hP : PoolKeepA Pp σ σ') + (hold : (mem w0 &&& 3#u64) ≠ 3#u64) (hdn : dTabA (mem' w0) = ptr) + (hz : ∀ j : U64, j.val < 512 → (mem' (peAF ptr j) &&& 3#u64) ≠ 3#u64) + (hw : ∃ r, S2RootOfAsidA Pp X σ asid r ∧ + WalkSlotA (· ∈ T2) mem va r Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) w0) + (hcap : ∀ y, IsSlotA th y → capAtA mem' y = capAtA mem y) + (hnm : ∀ y, IsSlotA th y → ∀ a v : U64, capAtA mem y = .PageTable ptr true a v → a = asid ∧ v = va) + (hOutU : ∀ y, IsSlotA th y → ∀ a v : U64, capAtA mem y = .PageTable ptr false a v → False) : + VsUniqA th Pp S1 X Y (insert ptr T2) (Function.update Sh2 ptr n) mem' ksb σ' where + t2 y hy ptr' asid' va' hc hT' w hw' h3 hd := by + have hxal := E.xal + have hwe := S2EntryA.of_link2 (n := n) E hxal hptr hmE hP hdn hz hw' + have hfoot : ∀ va0 r' : U64, r' ∈ X → ∀ sh' : Nat, + ExtFootE X Y T2 (peAF r' (walkIdx va0 sh' (Fl4SpecA64.s2Geom.topMask + 1))) := + fun va0 r' hr' sh' => rootFootE hr' (hxal r' hr') + (Nat.lt_of_lt_of_le (walkIdx_lt va0 sh' _ (Nat.succ_pos _) (Nat.le_trans s2Top1k (by norm_num))) s2Top1k) + have hwalk : ∀ va0 r : U64, r ∈ X → ∀ {w1 : U64}, WalkSlotA (· ∈ T2) mem va0 r Fl4SpecA64.s2Geom.topShift + (Fl4SpecA64.s2Geom.topMask + 1) w1 → + WalkSlotA (· ∈ insert ptr T2) mem' va0 r Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) w1 := + fun va0 r hr w1 hw1 => WalkSlotA.of_link2 (P := (· ∈ T2)) (Q := (· ∈ insert ptr T2)) + (fun x hx => Set.mem_insert_of_mem _ hx) (t0 := r) (n0 := Fl4SpecA64.s2Geom.topMask + 1) + (fun t' sh' n' hc' hne => by + rcases hc' with ⟨e1, rfl⟩ | ⟨ht', rfl⟩ + · rw [e1]; exact hmE _ (hfoot va0 r hr sh') (e1 ▸ hne) + · exact hmE _ (.s2pt t' _ ht' (walkIdx_lt va0 sh' 512 (by norm_num) (by norm_num))) hne) + hold (Or.inl ⟨rfl, rfl⟩) hw1 + rcases hwe with hwo | ⟨j, hj, hwj⟩ + · have hf : ExtFootE X Y T2 w := hwo.foot hxal + by_cases ew : w = w0 + · subst ew + have hpp : ptr' = ptr := by rw [← hd, hdn] + subst hpp + have hc0 : capAtA mem y = .PageTable ptr' true asid' va' := by rw [← hcap y hy]; exact hc + obtain ⟨h1, h2⟩ := hnm y hy asid' va' hc0 + subst h1; subst h2 + obtain ⟨r, hr, hws⟩ := hw + exact ⟨r, hr.of_spec hP.1 hP.2, hwalk _ r hr.1 hws⟩ + · have f2 : mem' w = mem w := hmE w hf ew + rw [f2] at h3 hd + have hch := s2Entry_childA E hwo h3 + have hT0 : ptr' ∈ T2 := by + rcases Set.mem_insert_iff.1 hT' with e | e + · exact absurd (e ▸ hd ▸ hch) hptr + · exact e + have hne : ptr' ≠ ptr := fun e => hptr (e ▸ hT0) + have hc0 : capAtA mem y = .PageTable ptr' true asid' va' := by rw [← hcap y hy]; exact hc + obtain ⟨r, hr, hws⟩ := U.t2 y hy ptr' asid' va' hc0 hT0 w hwo h3 hd + exact ⟨r, hr.of_spec hP.1 hP.2, hwalk _ r hr.1 hws⟩ + · rw [hwj] at h3; exact absurd h3 (hz j hj) + s1 y hy ptr' asid' va' hc hS tag sh t i hpath htab h12 hi h3 hd := by + have hc0 : capAtA mem y = .PageTable ptr' true asid' va' := by rw [← hcap y hy]; exact hc + have path0 := hpath.of_mem hV + have hf : mem' (peAF t i) = mem (peAF t i) := by + rcases htab with ht | ⟨y0, hy0, rfl⟩ + · exact hV _ (.pt t i ht hi) + · exact hV _ (.high y0 i hy0 hi) + rw [hf] at h3 hd + obtain ⟨raw, hact, hw1⟩ := U.s1 y hy ptr' asid' va' hc0 hS tag sh t i path0 htab h12 hi h3 hd + have hact' : ActiveAsidRootA mem' ksb Pp asid' raw := + ActiveAsidRootA.of_mem (mem := mem') (mem' := mem) (Tb := S1) (Y := Y) (fun b hb => (hV b hb).symm) hact + have hS1f : ∀ t' sh', S1TabA S1 Y t' → + mem' (peAF t' (walkIdx va' sh' 512)) = mem (peAF t' (walkIdx va' sh' 512)) := by + intro t' sh' h + have hl := walkIdx_lt va' sh' 512 (by norm_num) (by norm_num) + rcases h with ht | ⟨y0, hy0, rfl⟩ + · exact hV _ (.pt t' _ ht hl) + · exact hV _ (.high y0 _ hy0 hl) + refine ⟨raw, hact', ?_⟩ + rcases hw1 with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · refine Or.inl ⟨h0, hr, hws.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inl hr) + · exact hS1f _ _ h + · refine Or.inr ⟨h2, hy2, hws.of_mem' ?_⟩ + rintro t' sh' n' (⟨rfl, rfl⟩ | ⟨h, rfl⟩) + · exact hS1f _ _ (Or.inr ⟨untagA raw, hy2, rfl⟩) + · exact hS1f _ _ h + out y hy ptr' asid' va' hc := by + have hc0 : capAtA mem y = .PageTable ptr' false asid' va' := by rw [← hcap y hy]; exact hc + intro h + rcases Set.mem_insert_iff.1 h with e | e + · exact hOutU y hy asid' va' (e ▸ hc0) + · exact U.out y hy ptr' asid' va' hc0 e + inj2 w1 w2 h1 h2 v1 v2 hd hT := by + have hxal := E.xal + have e1 := S2EntryA.of_link2 (n := n) E hxal hptr hmE hP hdn hz h1 + have e2 := S2EntryA.of_link2 (n := n) E hxal hptr hmE hP hdn hz h2 + rcases e1 with h1' | ⟨j, hj, hwj⟩ + swap + · rw [hwj] at v1; exact absurd v1 (hz j hj) + rcases e2 with h2' | ⟨j, hj, hwj⟩ + swap + · rw [hwj] at v2; exact absurd v2 (hz j hj) + by_cases b1 : w1 = w0 <;> by_cases b2 : w2 = w0 + · rw [b1, b2] + · exfalso + have f2 := hmE w2 (h2'.foot hxal) b2 + rw [f2] at hd v2 + subst b1 + exact hptr (by have := s2Entry_childA E h2' v2; rwa [← hd, hdn] at this) + · exfalso + have f1 := hmE w1 (h1'.foot hxal) b1 + rw [f1] at hd v1 + subst b2 + exact hptr (by have := s2Entry_childA E h1' v1; rwa [hd, hdn] at this) + · have f1 := hmE w1 (h1'.foot hxal) b1 + have f2 := hmE w2 (h2'.foot hxal) b2 + rw [f1] at v1 hd hT + rw [f2] at v2 hd + have hch := s2Entry_childA E h1' v1 + exact U.inj2 w1 w2 h1' h2' v1 v2 hd hch + rootInj2 a1 a2 r h1 h2 := + U.rootInj2 a1 a2 r (S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h1) + (S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h2) + inj1 tag tag' sh sh' t t' i i' p1 tb1 h12 hi v1 p2 tb2 h12' hi' v2 hd hS := by + have hf : ∀ t i, S1TabA S1 Y t → i.val < 512 → mem' (peAF t i) = mem (peAF t i) := by + intro t i htb hi + rcases htb with ht | ⟨y0, hy0, rfl⟩ + · exact hV _ (.pt t i ht hi) + · exact hV _ (.high y0 i hy0 hi) + rw [hf t i tb1 hi] at v1 hd hS + rw [hf t' i' tb2 hi'] at v2 hd + exact U.inj1 tag tag' sh sh' t t' i i' (p1.of_mem hV) tb1 h12 hi v1 (p2.of_mem hV) tb2 h12' hi' v2 hd hS + rootInj1 a1 a2 raw h1 h2 := + U.rootInj1 a1 a2 raw (ActiveAsidRootA.of_mem (Tb := S1) (Y := Y) hV h1) + (ActiveAsidRootA.of_mem (Tb := S1) (Y := Y) hV h2) + rootOnce y hy r h := by + rw [hcap y hy] at h + obtain ⟨hn, hu⟩ := U.rootOnce y hy r h + refine ⟨fun hi => hn (hi.imp (fun ⟨a, raw, h1, e⟩ => ⟨a, raw, ActiveAsidRootA.of_mem (Tb := S1) (Y := Y) hV h1, e⟩) + (fun ⟨a, h1⟩ => ⟨a, S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h1⟩)), fun z hz hk => ?_⟩ + rw [hcap z hz] at hk + exact hu z hz hk + ptOnce y hy r h z hz hk := by + rw [hcap y hy] at h + rw [hcap z hz] at hk + exact U.ptOnce y hy r h z hz hk + +end link2 + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsUniqShrinkA.lean b/proofs/Fl4ProofsA64/P3/VsUniqShrinkA.lean new file mode 100644 index 000000000..21b4ffe86 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUniqShrinkA.lean @@ -0,0 +1,561 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`): **`VsUniqA` across a step that only removes table descriptors** (a zero write, +a zeroed page, an unmap's clear), Stage-2 half. + +* `S2EntryA.root_of` / `.tab_of`: the container of a reachable entry word is the root / table the word is addressed + from (pages are disjoint: `ExtVsRelA.t2x`). +* `S2ReachA.shrink`, `S2EntryA.shrink`: reachability at a state whose changed footprint words are non-table + descriptors is reachability before. +* `walk_shrink2`: **a walk that reaches a still-reachable entry survives** (the forest property `VsUniqA.inj2` + identifies the path that is still reachable with the walk). + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.VsUniqA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- A word that is not a valid table descriptor. -/ +abbrev NotTabA (w : U64) : Prop := (w &&& 3#u64) ≠ 3#u64 + +theorem eqOfValidA {a b : U64} (h : a = b ∨ NotTabA a) (hv : (a &&& 3#u64) = 3#u64) : a = b := + h.resolve_right (not_not.2 hv) + +theorem s2Top_gt : 12 < Fl4SpecA64.s2Geom.topShift := by + unfold Fl4SpecA64.s2Geom Fl4SpecA64.s2GeomOf + split_ifs <;> dsimp only <;> omega + +theorem s2Top_le : Fl4SpecA64.s2Geom.topShift ≤ 39 := by + unfold Fl4SpecA64.s2Geom Fl4SpecA64.s2GeomOf + split_ifs <;> dsimp only <;> omega + +/-- The words of the Stage-2 entries a walk follows (root words, words of tables above the leaf level). -/ +def S2WordA (X T2 : Set U64) (Sh2 : U64 → Nat) (b : U64) : Prop := + (∃ r i : U64, r ∈ X ∧ i.val < Fl4SpecA64.s2Geom.topMask + 1 ∧ b = peAF r i) ∨ + (∃ t i : U64, t ∈ T2 ∧ 12 < Sh2 t ∧ i.val < 512 ∧ b = peAF t i) + +theorem S2EntryA.word {Pp X T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {σ : Fl4SpecA64.State Unit} {w : U64} + (h : S2EntryA Pp X T2 Sh2 mem σ w) : S2WordA X T2 Sh2 w := by + rcases h with ⟨r, i, ha, hi, e⟩ | ⟨t, i, -, ht, h12, hi, e⟩ + · exact Or.inl ⟨r, i, ha.1, hi, e⟩ + · exact Or.inr ⟨t, i, ht, h12, hi, e⟩ + +theorem peAF_injA_s {p q i j : U64} (hp : p.val % 4096 = 0) (hq : q.val % 4096 = 0) (hi : i.val < 512) + (hj : j.val < 512) (h : peAF p i = peAF q j) : p = q ∧ i = j := by + have bp : p.val < 2 ^ 64 := p.bv.isLt + have bq : q.val < 2 ^ 64 := q.bv.isLt + have e := congrArg UScalar.val h + rw [peAF_valA (by omega) hi, peAF_valA (by omega) hj] at e + exact ⟨UScalar.eq_of_val_eq (by omega), UScalar.eq_of_val_eq (by omega)⟩ + +section s2 +variable {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem mem' : U64 → U64} {σ σ' : Fl4SpecA64.State Unit} + +theorem wa4096_val {r : U64} (hr : 8192 ∣ r.val) : (wa r 4096#u64).val = r.val + 4096 := by + have br : r.val < 2 ^ 64 := r.bv.isLt + rw [wa_valP] + have h4 : (4096#u64 : U64).val = 4096 := rfl + rw [h4] + omega + +/-- A root and a Stage-2 table do not share a slot. -/ +theorem root_tab_ne (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {r c i j : U64} (hr : r ∈ X) (hc : c ∈ T2) + (hi : i.val < 1024) (hj : j.val < 512) : peAF r i ≠ peAF c j := by + intro h + have e := congrArg UScalar.val h + have h8 := E.xal r hr + have h4 := E.tal c hc + have br : r.val < 2 ^ 64 := r.bv.isLt + have bc : c.val < 2 ^ 64 := c.bv.isLt + rw [peAF_val1kE (by omega) hi, peAF_valA (by omega) hj] at e + obtain ⟨h1, h2⟩ := E.t2x c hc r hr + have hc' : c.val = r.val ∨ c.val = r.val + 4096 := by omega + rcases hc' with h' | h' + · exact h1 (UScalar.eq_of_val_eq h') + · exact h2 (UScalar.eq_of_val_eq (by rw [wa4096_val h8]; exact h')) + +/-- Two root words are one word only at one root and index. -/ +theorem root_root_eq (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {r r' i i' : U64} (hr : r ∈ X) (hr' : r' ∈ X) + (hi : i.val < 1024) (hi' : i'.val < 1024) (h : peAF r i = peAF r' i') : r = r' := by + have e := congrArg UScalar.val h + have h8 := E.xal r hr + have h8' := E.xal r' hr' + have br : r.val < 2 ^ 64 := r.bv.isLt + have br' : r'.val < 2 ^ 64 := r'.bv.isLt + rw [peAF_val1kE (by omega) hi, peAF_val1kE (by omega) hi'] at e + exact UScalar.eq_of_val_eq (by omega) + +/-- **The container of a reachable root word is that (active) root.** -/ +theorem S2EntryA.root_of (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {w r idx : U64} + (h : S2EntryA Pp X T2 Sh2 mem' σ' w) (hr : r ∈ X) (hidx : idx.val < 1024) (hw : w = peAF r idx) : + ActiveS2RootA Pp X σ' r := by + rcases h with ⟨r', i, ha, hi, e⟩ | ⟨t, i, -, ht, -, hi, e⟩ + · have hi1k : i.val < 1024 := by + have := s2Top1k; omega + have := root_root_eq E ha.1 hr hi1k hidx (e.symm.trans hw) + subst this; exact ha + · exact absurd (e.symm.trans hw) (fun h => root_tab_ne E hr ht hidx hi h.symm) + +/-- **The container of a reachable table word is that table, which is reachable.** -/ +theorem S2EntryA.tab_of (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {w c idx : U64} + (h : S2EntryA Pp X T2 Sh2 mem' σ' w) (hc : c ∈ T2) (hidx : idx.val < 512) (hw : w = peAF c idx) : + S2ReachA Pp X T2 Sh2 mem' σ' c ∧ 12 < Sh2 c := by + rcases h with ⟨r', i, ha, hi, e⟩ | ⟨t, i, hr, ht, h12, hi, e⟩ + · have hi1k : i.val < 1024 := by + have := s2Top1k; omega + exact absurd (e.symm.trans hw) (fun h => root_tab_ne E ha.1 hc hi1k hidx h) + · have := (peAF_injA_s (Nat.mod_eq_zero_of_dvd (E.tal t ht)) (Nat.mod_eq_zero_of_dvd (E.tal c hc)) hi hidx + (e.symm.trans hw)).1 + subst this + exact ⟨hr, h12⟩ + + +theorem and3_bits_sh (e : U64) : (e &&& 3#u64) = 3#u64 ↔ dBitA e 0 = true ∧ dBitA e 1 = true := by + have d0 : dBitA e 0 = decide (e.val % 2 = 1) := by + unfold dBitA; rw [BitVec.getLsbD, Nat.testBit_zero]; rfl + have d1 : dBitA e 1 = decide (e.val / 2 % 2 = 1) := by + unfold dBitA; rw [BitVec.getLsbD, ← Nat.zero_add 1, ← Nat.testBit_div_two_pow, Nat.testBit_zero]; rfl + rw [d0, d1] + simp only [decide_eq_true_eq] + have h3v : (e &&& 3#u64).val = e.val % 4 := by + rw [UScalar.val_and, show (3#u64 : U64).val = 2 ^ 2 - 1 from rfl, Nat.and_two_pow_sub_one_eq_mod] + have c3 : (3#u64 : U64).val = 3 := rfl + constructor + · intro h; have := congrArg UScalar.val h; rw [h3v, c3] at this; omega + · rintro ⟨h0, h1⟩; apply UScalar.eq_of_val_eq; rw [h3v, c3]; omega + +/-- A valid table descriptor above the leaf level names a table at the next shift. -/ +theorem descRelE_tab {sh : Nat} {w : U64} {pte : Fl4SpecA64.PTE} (hrel : DescRelE (G2E T2 Sh2) sh w pte) + (h3 : (w &&& 3#u64) = 3#u64) (h12 : 12 < sh) : dTabA w ∈ T2 ∧ Sh2 (dTabA w) = sh - 9 := by + obtain ⟨hb0, hb1⟩ := (and3_bits_sh w).1 h3 + cases pte with + | invalidPTE => + have h0 : dBitA w 0 = false := hrel + rw [hb0] at h0; cases h0 + | pageTablePTE ppn => exact hrel.2.2.2.2.2 + | pagePTE a sm at' r => exact absurd (hrel.2.1.1 hb1) (by omega) + +/-- **A reachable Stage-2 table word whose spec entry is not a table descriptor is not a table descriptor.** -/ +theorem S2EntryA.notTab_of_rel (E' : ExtVsRelA Pp S1 X Y T2 Sh2 mem' σ') {b t i : U64} + (hE : S2EntryA Pp X T2 Sh2 mem' σ' b) (hb : b = peAF t i) (ht : t ∈ T2) (hi : i.val < 512) + {pt : Fl4SpecA64.PT} (hk : σ'.kheap (specPtr t) = some (.archObj (.pageTable pt))) + (hnt : ∀ ppn, Fl4SpecA64.ptApply pt i.bv ≠ .pageTablePTE ppn) : NotTabA (mem' b) := by + obtain ⟨hreach, h12⟩ := hE.tab_of E' ht hi hb + obtain ⟨pt', hk', -, hrel⟩ := E'.s2pt t ht + have e : pt' = pt := by + have h := Option.some.inj (hk'.symm.trans hk) + injection h with h1 + injection h1 with h2 + subst e + have hd := (hrel hreach i hi).1 + subst hb + intro h3 + obtain ⟨hb0, hb1⟩ := (and3_bits_sh _).1 h3 + rcases hpte : Fl4SpecA64.ptApply pt' i.bv with _ | ⟨a, sm, at', r⟩ | ppn + · rw [hpte] at hd + have h0 : dBitA (mem' (peAF t i)) 0 = false := hd + rw [hb0] at h0; cases h0 + · rw [hpte] at hd + have := hd.2.1.1 hb1 + omega + · exact hnt ppn hpte + +/-- The root version of `notTab_of_rel`. -/ +theorem S2EntryA.notTab_of_relRoot (E' : ExtVsRelA Pp S1 X Y T2 Sh2 mem' σ') {b r j : U64} + (hE : S2EntryA Pp X T2 Sh2 mem' σ' b) (hb : b = peAF r j) (hr : r ∈ X) (hj : j.val < 1024) + (hjm : j.val < Fl4SpecA64.s2Geom.topMask + 1) {es : Fin 1024 → Fl4SpecA64.PTE} + (hk : σ'.kheap (specPtr r) = some (.archObj (.ext (.stage2Root es)))) + (hnt : ∀ ppn, es ⟨j.val, hj⟩ ≠ .pageTablePTE ppn) : NotTabA (mem' b) := by + have ha := hE.root_of E' hr hj hb + obtain ⟨es', hk', hrel⟩ := E'.s2root r hr + have e : es' = es := by + have h := Option.some.inj (hk'.symm.trans hk) + injection h with h1 + injection h1 with h2 + injection h2 with h3 + subst e + have hd := (hrel ha j hj hjm).1 + subst hb + intro h3 + obtain ⟨hb0, hb1⟩ := (and3_bits_sh _).1 h3 + rcases hpte : es' ⟨j.val, hj⟩ with _ | ⟨a, sm, at', r'⟩ | ppn + · rw [hpte] at hd + have h0 : dBitA (mem' (peAF r j)) 0 = false := hd + rw [hb0] at h0; cases h0 + · rw [hpte] at hd + have := hd.2.1.1 hb1 + have := s2Top_gt + omega + · exact hnt ppn hpte + +theorem S2ReachA.shrink {q : U64} (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (hm : ∀ b, S2EntryA Pp X T2 Sh2 mem' σ' b → mem' b = mem b ∨ NotTabA (mem' b)) (hP : PoolKeepA Pp σ σ') + (hr : S2ReachA Pp X T2 Sh2 mem' σ' q) : S2ReachA Pp X T2 Sh2 mem σ q := by + induction hr with + | root ha => exact .root (ha.of_spec hP.1 hP.2) + | @stepRoot r i ha hi h3 ht2 => + have e := eqOfValidA (hm _ (Or.inl ⟨r, i, ha, hi, rfl⟩)) h3 + rw [e] at h3 ht2 ⊢ + exact .stepRoot (ha.of_spec hP.1 hP.2) hi h3 ht2 + | @stepPt t i hr ht h12 hi h3 ht2 ih => + have e := eqOfValidA (hm _ (Or.inr ⟨t, i, hr, ht, h12, hi, rfl⟩)) h3 + rw [e] at h3 ht2 ⊢ + exact .stepPt ih ht h12 hi h3 ht2 + +theorem S2EntryA.shrink {w : U64} (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (hm : ∀ b, S2EntryA Pp X T2 Sh2 mem' σ' b → mem' b = mem b ∨ NotTabA (mem' b)) (hP : PoolKeepA Pp σ σ') + (h : S2EntryA Pp X T2 Sh2 mem' σ' w) : S2EntryA Pp X T2 Sh2 mem σ w := by + rcases h with ⟨r, i, ha, hi, e⟩ | ⟨t, i, hr, ht, h12, hi, e⟩ + · exact Or.inl ⟨r, i, ha.of_spec hP.1 hP.2, hi, e⟩ + · exact Or.inr ⟨t, i, hr.shrink hxal hm hP, ht, h12, hi, e⟩ + +/-- Inversion of Stage-2 reachability. -/ +theorem S2ReachA.inv {q : U64} (h : S2ReachA Pp X T2 Sh2 mem σ q) : + (ActiveS2RootA Pp X σ q) ∨ + (∃ r i, ActiveS2RootA Pp X σ r ∧ i.val < Fl4SpecA64.s2Geom.topMask + 1 ∧ (mem (peAF r i) &&& 3#u64) = 3#u64 ∧ + dTabA (mem (peAF r i)) ∈ T2 ∧ q = dTabA (mem (peAF r i))) ∨ + (∃ t i, S2ReachA Pp X T2 Sh2 mem σ t ∧ t ∈ T2 ∧ 12 < Sh2 t ∧ i.val < 512 ∧ (mem (peAF t i) &&& 3#u64) = 3#u64 ∧ + dTabA (mem (peAF t i)) ∈ T2 ∧ q = dTabA (mem (peAF t i))) := by + cases h with + | root ha => exact Or.inl ha + | stepRoot ha hi h3 ht2 => exact Or.inr (Or.inl ⟨_, _, ha, hi, h3, ht2, rfl⟩) + | stepPt hr ht h12 hi h3 ht2 => exact Or.inr (Or.inr ⟨_, _, hr, ht, h12, hi, h3, ht2, rfl⟩) + +/-- The walk's current table in the old state: an active root at the top, or a reachable table at its shift. -/ +def S2WalkTabA (Pp X T2 : Set U64) (Sh2 : U64 → Nat) (mem : U64 → U64) (σ : Fl4SpecA64.State Unit) + (t : U64) (sh n : Nat) : Prop := + (ActiveS2RootA Pp X σ t ∧ sh = Fl4SpecA64.s2Geom.topShift ∧ n = Fl4SpecA64.s2Geom.topMask + 1) ∨ + (t ∈ T2 ∧ S2ReachA Pp X T2 Sh2 mem σ t ∧ Sh2 t = sh ∧ n = 512) + +theorem S2WalkTabA.step (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {t : U64} {sh n : Nat} {i : U64} + (ht : S2WalkTabA Pp X T2 Sh2 mem σ t sh n) (hi : i.val < n) (h3 : (mem (peAF t i) &&& 3#u64) = 3#u64) + (h12 : 12 < sh) (hc : dTabA (mem (peAF t i)) ∈ T2) : + S2WalkTabA Pp X T2 Sh2 mem σ (dTabA (mem (peAF t i))) (sh - 9) 512 ∧ + S2EntryA Pp X T2 Sh2 mem σ (peAF t i) := by + rcases ht with ⟨ha, rfl, rfl⟩ | ⟨htT, hr, rfl, rfl⟩ + · have hi1k : i.val < 1024 := by have := s2Top1k; omega + obtain ⟨es, -, hrel⟩ := E.s2root t ha.1 + have hd := (hrel ha i hi1k hi).1 + have := descRelE_tab hd h3 h12 + exact ⟨Or.inr ⟨hc, .stepRoot ha hi h3 hc, this.2, rfl⟩, Or.inl ⟨t, i, ha, hi, rfl⟩⟩ + · obtain ⟨pt, -, -, hrel⟩ := E.s2pt t htT + have hd := (hrel hr i hi).1 + have := descRelE_tab hd h3 h12 + exact ⟨Or.inr ⟨hc, .stepPt hr htT h12 hi h3 hc, this.2, rfl⟩, Or.inr ⟨t, i, hr, htT, h12, hi, rfl⟩⟩ + +/-- A reachable slot of the walk's table makes that table reachable at the new state. -/ +theorem S2WalkTabA.reach' (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {t : U64} {sh n : Nat} {i : U64} + (ht : S2WalkTabA Pp X T2 Sh2 mem σ t sh n) (hi : i.val < n) + (hw : S2EntryA Pp X T2 Sh2 mem' σ' (peAF t i)) : S2ReachA Pp X T2 Sh2 mem' σ' t := by + rcases ht with ⟨ha, rfl, rfl⟩ | ⟨htT, hr, rfl, rfl⟩ + · have hi1k : i.val < 1024 := by have := s2Top1k; omega + exact .root (hw.root_of E ha.1 hi1k rfl) + · exact (hw.tab_of E htT hi rfl).1 + +theorem S2WalkTabA.n_pos {t : U64} {sh n : Nat} (ht : S2WalkTabA Pp X T2 Sh2 mem σ t sh n) : + 0 < n ∧ n ≤ 2 ^ 64 := by + rcases ht with ⟨-, -, rfl⟩ | ⟨-, -, -, rfl⟩ + · have := s2Top1k; omega + · omega + +/-- **A Stage-2 walk survives the removal of descriptors that are off the path of a still-reachable entry.** -/ +theorem walk_shrink2 (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) (F : VsForestA Pp S1 X Y T2 Sh2 mem ksb σ) + (hxal : ∀ r ∈ X, 8192 ∣ r.val) + (hm : ∀ b, S2EntryA Pp X T2 Sh2 mem' σ' b → mem' b = mem b ∨ NotTabA (mem' b)) (hP : PoolKeepA Pp σ σ') + {va t w : U64} {sh n : Nat} (W : WalkSlotA (· ∈ T2) mem va t sh n w) + (ht : S2WalkTabA Pp X T2 Sh2 mem σ t sh n) (hw : S2EntryA Pp X T2 Sh2 mem' σ' w) : + S2ReachA Pp X T2 Sh2 mem' σ' t ∧ WalkSlotA (· ∈ T2) mem' va t sh n w := by + revert ht hw + induction W with + | here t sh n => + intro ht hw + have hn := ht.n_pos + exact ⟨ht.reach' E (walkIdx_lt va sh n hn.1 hn.2) hw, .here t sh n⟩ + | @down t sh n w h3 h12 hc W' ih => + intro ht hw + have hn := ht.n_pos + have hi := walkIdx_lt va sh n hn.1 hn.2 + obtain ⟨ht', hent⟩ := S2WalkTabA.step E ht hi h3 h12 hc + obtain ⟨hR', hW'⟩ := ih ht' hw + -- the descriptor of the walk at this level is still valid: it is the only one naming the child + have hs : mem' (peAF t (walkIdx va sh n)) = mem (peAF t (walkIdx va sh n)) ∧ + S2EntryA Pp X T2 Sh2 mem' σ' (peAF t (walkIdx va sh n)) := by + have key : ∀ q, S2EntryA Pp X T2 Sh2 mem' σ' q → (mem' q &&& 3#u64) = 3#u64 → + dTabA (mem' q) = dTabA (mem (peAF t (walkIdx va sh n))) → + mem' (peAF t (walkIdx va sh n)) = mem (peAF t (walkIdx va sh n)) ∧ + S2EntryA Pp X T2 Sh2 mem' σ' (peAF t (walkIdx va sh n)) := by + intro q hq hqv hdq + have eq : mem' q = mem q := eqOfValidA (hm q hq) hqv + have hqE : S2EntryA Pp X T2 Sh2 mem σ q := hq.shrink hxal hm hP + rw [eq] at hqv hdq + have := F.inj2 q _ hqE hent hqv h3 hdq (by rw [hdq]; exact hc) + subst this + exact ⟨eq, hq⟩ + rcases hR'.inv with hr | ⟨r, i, ha, hi', h3', hc', hq⟩ | ⟨t1, i, hr1, ht1, h121, hi1, h3', hc', hq⟩ + · exact absurd rfl (E.t2x _ hc _ hr.1).1 + · exact key (peAF r i) (Or.inl ⟨r, i, ha, hi', rfl⟩) h3' hq.symm + · exact key (peAF t1 i) (Or.inr ⟨t1, i, hr1, ht1, h121, hi1, rfl⟩) h3' hq.symm + refine ⟨ht.reach' E hi hs.2, ?_⟩ + have h3' : (mem' (peAF t (walkIdx va sh n)) &&& 3#u64) = 3#u64 := by rw [hs.1]; exact h3 + refine .down t sh n w h3' h12 (by rw [hs.1]; exact hc) ?_ + rw [hs.1]; exact hW' + +end s2 + +/-! ## Stage 1 -/ + +section s1 +variable {Pp S1 X Y : Set U64} {Lv : U64 → Nat} {mem mem' : U64 → U64} {ksb : U64} {σ : Fl4SpecA64.State Unit} + +/-- The words of the ASID table and of the pools are kept. -/ +abbrev AsidWordsA (Pp : Set U64) (ksb : U64) (b : U64) : Prop := + (∃ hi : U64, hi.val < 128 ∧ b = atAF ksb hi) ∨ (∃ p lo : U64, p ∈ Pp ∧ lo.val < 512 ∧ b = peAF p lo) + +theorem ActiveAsidRootA.shrink {asid raw : U64} (hA : ∀ b, AsidWordsA Pp ksb b → mem' b = mem b) + (h : ActiveAsidRootA mem' ksb Pp asid raw) : ActiveAsidRootA mem ksb Pp asid raw := by + obtain ⟨hi, lo, hhi, hlo, ha', pool, hp, hpne, htab, hw, hrne⟩ := h + refine ⟨hi, lo, hhi, hlo, ha', pool, hp, hpne, ?_, ?_, hrne⟩ + · rw [← hA _ (Or.inl ⟨hi, hhi, rfl⟩)]; exact htab + · rw [← hA _ (Or.inr ⟨pool, lo, hp, hlo, rfl⟩)]; exact hw + +/-- A Stage-1 entry word reachable at a state. -/ +def S1EntryA (Pp S1 Y : Set U64) (mem : U64 → U64) (ksb : U64) (w : U64) : Prop := + ∃ (tag : U64) (sh : Nat) (t i : U64), VsPathA Pp S1 Y mem ksb tag sh t ∧ S1TabA S1 Y t ∧ 12 < sh ∧ + i.val < 512 ∧ w = peAF t i + +theorem VsPathA.shrink {tag : U64} {sh : Nat} {q : U64} + (hA : ∀ b, AsidWordsA Pp ksb b → mem' b = mem b) + (hm : ∀ b, S1EntryA Pp S1 Y mem' ksb b → mem' b = mem b ∨ NotTabA (mem' b)) + (h : VsPathA Pp S1 Y mem' ksb tag sh q) : VsPathA Pp S1 Y mem ksb tag sh q := by + induction h with + | native hact htag htb => exact .native (hact.shrink hA) htag htb + | high hact htag hy => exact .high (hact.shrink hA) htag hy + | @child tag t i sh hpar htY h12 hi h3 ih => + have hpe : mem' (peAF t i) = mem (peAF t i) := eqOfValidA (hm _ ⟨tag, sh, t, i, hpar, htY, h12, hi, rfl⟩) h3 + rw [hpe] at h3 ⊢ + exact .child ih htY h12 hi h3 + +/-- Inversion of a Stage-1 path. -/ +theorem VsPathA.inv {tag : U64} {sh : Nat} {q : U64} (h : VsPathA Pp S1 Y mem ksb tag sh q) : + (∃ asid, tag = 0#u64 ∧ sh = 39 ∧ ActiveAsidRootA mem ksb Pp asid q ∧ tagA q = 0 ∧ q ∈ S1) ∨ + (∃ asid raw, tag = 2#u64 ∧ sh = 30 ∧ ActiveAsidRootA mem ksb Pp asid raw ∧ tagA raw = 2 ∧ untagA raw ∈ Y ∧ + q = wa (untagA raw) 4096#u64) ∨ + (∃ (tag0 : U64) (sh0 : Nat) (t i : U64), tag = tag0 ∧ VsPathA Pp S1 Y mem ksb tag0 sh0 t ∧ S1TabA S1 Y t ∧ + 12 < sh0 ∧ i.val < 512 ∧ (mem (peAF t i) &&& 3#u64) = 3#u64 ∧ sh = sh0 - 9 ∧ + q = dTabA (mem (peAF t i))) := by + cases h with + | native hact htag htb => exact Or.inl ⟨_, rfl, rfl, hact, htag, htb⟩ + | high hact htag hy => exact Or.inr (Or.inl ⟨_, _, rfl, rfl, hact, htag, hy, rfl⟩) + | child hp htY h12 hi h3 => exact Or.inr (Or.inr ⟨_, _, _, _, rfl, hp, htY, h12, hi, h3, rfl, rfl⟩) + +theorem VsRelA.child_tb (R : VsRelA Pp S1 Lv X Y mem ksb σ) {tag : U64} {sh : Nat} {t i : U64} + (hp : VsPathA Pp S1 Y mem ksb tag sh t) (htb : S1TabA S1 Y t) (h12 : 12 < sh) (hi : i.val < 512) + (h3 : (mem (peAF t i) &&& 3#u64) = 3#u64) : dTabA (mem (peAF t i)) ∈ S1 := by + obtain ⟨htag, hcase⟩ := R.path_props hp + obtain ⟨hb0, hb1⟩ := (and3_bits_sh _).1 h3 + rcases hcase with ⟨ht, hlv, hsh⟩ | ⟨rfl, rfl, y, hy, hactY, rfl⟩ + · obtain ⟨pt, -, -, hpt⟩ := R.pt t ht + have hrel := hpt ⟨tag, sh, htag, hp⟩ i hi + generalize Fl4SpecA64.ptApply pt i.bv = pte at hrel + cases pte with + | invalidPTE => rw [hrel] at hb0; cases hb0 + | pageTablePTE _ => + obtain ⟨-, -, -, -, -, hdTb, hdLv⟩ := hrel + exact hdTb + | pagePTE _ _ _ _ => + obtain ⟨-, -, -, hiff, -⟩ := hrel + have := hiff.1 hb1; omega + · obtain ⟨l1, -, hl1⟩ := R.high y hy + have hrel := hl1 hactY i hi + generalize l1 ⟨i.val, hi⟩ = pte at hrel + cases pte with + | invalidPTE => rw [hrel] at hb0; cases hb0 + | pageTablePTE _ => + obtain ⟨-, -, -, -, -, hdTb, hdLv⟩ := hrel + exact hdTb + | pagePTE _ _ _ _ => + obtain ⟨-, -, -, hiff, -⟩ := hrel + have := hiff.1 hb1; omega + +theorem S1TabA.mod4k (R : VsRelA Pp S1 Lv X Y mem ksb σ) {t : U64} (h : S1TabA S1 Y t) : t.val % 4096 = 0 := by + rcases h with ht | ⟨y, hy, rfl⟩ + · exact R.al_mod ht + · have h8 := R.yal y hy + have by' : y.val < 2 ^ 64 := y.bv.isLt + rw [wa_valP] + have h4 : (4096#u64 : U64).val = 4096 := rfl + rw [h4] + omega + +/-- **A reachable Stage-1 table word whose spec entry is not a table descriptor is not a table descriptor.** -/ +theorem S1EntryA.notTab_of_rel (R' : VsRelA Pp S1 Lv X Y mem' ksb σ') {b p i : U64} + (hE : S1EntryA Pp S1 Y mem' ksb b) (hb : b = peAF p i) (hp : p ∈ S1) (hi : i.val < 512) + {pt : Fl4SpecA64.PT} (hk : σ'.kheap (specPtr p) = some (.archObj (.pageTable pt))) + (hnt : ∀ ppn, Fl4SpecA64.ptApply pt i.bv ≠ .pageTablePTE ppn) : NotTabA (mem' b) := by + obtain ⟨tag, sh, τ, i', hpath, hτ, h12, hi', hb'⟩ := hE + have hτp := (peAF_injA_s (S1TabA.mod4k R' hτ) (R'.al_mod hp) hi' hi (hb'.symm.trans hb)).1 + subst hτp + obtain ⟨htag, hcase⟩ := R'.path_props hpath + obtain ⟨t, hk', -, hpt⟩ := R'.pt τ hp + have e : t = pt := by + have h := Option.some.inj (hk'.symm.trans hk) + injection h with h1 + injection h1 with h2 + subst e + have hlv : Lv τ < 3 := by + rcases hcase with ⟨-, -, hsh⟩ | ⟨-, -, y, hy, -, hyc⟩ + · omega + · exact absurd hp (by rw [hyc]; exact R'.ytb y hy) + have hrel := hpt ⟨tag, sh, htag, hpath⟩ i hi + subst hb + intro h3 + obtain ⟨hb0, hb1⟩ := (and3_bits_sh _).1 h3 + rcases hpte : Fl4SpecA64.ptApply t i.bv with _ | ⟨a, sm, at', r⟩ | ppn + · rw [hpte] at hrel + have h0 : dBitA (mem' (peAF τ i)) 0 = false := hrel + rw [hb0] at h0; cases h0 + · rw [hpte] at hrel + have := hrel.2.2.2.1.1 hb1 + omega + · exact hnt ppn hpte + +/-- **A Stage-1 walk survives the removal of descriptors off the path of a still-reachable entry.** -/ +theorem walk_shrink1 (R : VsRelA Pp S1 Lv X Y mem ksb σ) (F : VsForestA Pp S1 X Y T2 Sh2 mem ksb σ) + (hA : ∀ b, AsidWordsA Pp ksb b → mem' b = mem b) + (hm : ∀ b, S1EntryA Pp S1 Y mem' ksb b → mem' b = mem b ∨ NotTabA (mem' b)) + {va t w : U64} {sh n : Nat} (W : WalkSlotA (S1TabA S1 Y) mem va t sh n w) (hn : n = 512) + (ht : ∃ tag, VsPathA Pp S1 Y mem ksb tag sh t) (htb : S1TabA S1 Y t) + (hw : S1EntryA Pp S1 Y mem' ksb w) : + (∃ tag sh', VsPathA Pp S1 Y mem' ksb tag sh' t) ∧ WalkSlotA (S1TabA S1 Y) mem' va t sh n w := by + revert ht htb hw hn + induction W with + | here t sh n => + intro hn ht htb hw + refine ⟨?_, .here t sh n⟩ + obtain ⟨tag', sh', τ, i', hp', hτ, h12', hi', hwe⟩ := hw + subst hn + have := (peAF_injA_s (S1TabA.mod4k R hτ) (S1TabA.mod4k R htb) hi' (walkIdx_lt va sh 512 (by norm_num) (by norm_num)) hwe.symm).1 + subst this + exact ⟨tag', sh', hp'⟩ + | @down t sh n w h3 h12 hc W' ih => + intro hn ht htb hw + subst hn + have hi := walkIdx_lt va sh 512 (by norm_num) (by norm_num) + obtain ⟨tag, hpt⟩ := ht + have hcTb := R.child_tb hpt htb h12 hi h3 + obtain ⟨⟨tag1, sh1, hp1⟩, hW'⟩ := ih rfl ⟨tag, .child hpt htb h12 hi h3⟩ hc hw + -- the old and the new path to the child + have hold := R.path_props (.child hpt htb h12 hi h3) + have hsh := (R.path_props hpt).2 + have key : ∀ q t1 i1 : U64, ∀ (tag0 : U64) (sh0 : Nat), VsPathA Pp S1 Y mem' ksb tag0 sh0 t1 → S1TabA S1 Y t1 → + 12 < sh0 → i1.val < 512 → (mem' (peAF t1 i1) &&& 3#u64) = 3#u64 → q = peAF t1 i1 → + dTabA (mem' q) = dTabA (mem (peAF t (walkIdx va sh 512))) → + mem' (peAF t (walkIdx va sh 512)) = mem (peAF t (walkIdx va sh 512)) ∧ + (∃ tag' sh', VsPathA Pp S1 Y mem' ksb tag' sh' t) := by + intro q t1 i1 tag0 sh0 hp0 htb1 h121 hi1 hv1 hq hdq + subst hq + have hp0' := hp0.shrink hA hm + have eq : mem' (peAF t1 i1) = mem (peAF t1 i1) := eqOfValidA (hm _ ⟨tag0, sh0, t1, i1, hp0, htb1, h121, hi1, rfl⟩) hv1 + rw [eq] at hv1 hdq + have := F.inj1 tag0 tag sh0 sh t1 t i1 (walkIdx va sh 512) hp0' htb1 h121 hi1 hv1 hpt htb h12 hi h3 + hdq (by rw [hdq]; exact hcTb) + have e1 := (peAF_injA_s (S1TabA.mod4k R htb1) (S1TabA.mod4k R htb) hi1 hi this).1 + subst e1 + refine ⟨by rw [← this]; exact eq, tag0, sh0, hp0⟩ + rcases hp1.inv with ⟨asid, h0, h39, hact, htg, hc1⟩ | ⟨asid, raw, h0, h30, hact, htg, hy, hq⟩ | + ⟨tag0, sh0, t1, i1, h0, hp0, htb1, h121, hi1, hv1, hsh1, hq⟩ + · -- a native root cannot be the child of the walk + have hnew := R.path_props (hp1.shrink hA hm) + rcases hold with ⟨-, ⟨-, -, hs'⟩ | ⟨-, hs30', y, hy, -, hyc⟩⟩ + · rcases hnew with ⟨-, ⟨-, -, hs⟩ | ⟨-, hs30, -⟩⟩ <;> rcases hsh with ⟨-, -, hs''⟩ | ⟨-, hs30'', -⟩ <;> omega + · exact absurd hcTb (by rw [hyc]; exact R.ytb y hy) + · -- a window's level-1 table is not in `S1` + obtain ⟨y, hy, hyc⟩ : ∃ y ∈ Y, dTabA (mem (peAF t (walkIdx va sh 512))) = wa y 4096#u64 := + ⟨untagA raw, hy, hq⟩ + exact absurd hcTb (by rw [hyc]; exact R.ytb y hy) + · obtain ⟨e, hr⟩ := key _ t1 i1 tag0 sh0 hp0 htb1 h121 hi1 hv1 rfl hq.symm + refine ⟨hr, ?_⟩ + have h3' : (mem' (peAF t (walkIdx va sh 512)) &&& 3#u64) = 3#u64 := by rw [e]; exact h3 + refine .down t sh 512 w h3' h12 (by rw [e]; exact hc) ?_ + rw [e]; exact hW' + + +end s1 + +section shrink +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {Lv : U64 → Nat} {mem mem' : U64 → U64} + {ksb : U64} {σ σ' : Fl4SpecA64.State Unit} + +theorem S2RootOfAsidA.active {asid r : U64} (h : S2RootOfAsidA Pp X σ asid r) : ActiveS2RootA Pp X σ r := by + obtain ⟨hr, p, f, h0, hp, htab, hk, hf⟩ := h + exact ⟨hr, _, p, f, h0, hp, htab, hk, hf⟩ + +/-- **`VsUniqA` across a step that only removes table descriptors** (module docstring): the changed words of the +Stage-2 and Stage-1 footprints are non-table descriptors afterwards, the ASID words and the pools are kept, the +caps are closed (`PtClosedA`). -/ +theorem VsUniqA.of_shrink (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) + (R : VsRelA Pp S1 Lv X Y mem ksb σ) + (hmE : ∀ b, S2EntryA Pp X T2 Sh2 mem' σ' b → mem' b = mem b ∨ NotTabA (mem' b)) + (hmV : ∀ b, S1EntryA Pp S1 Y mem' ksb b → mem' b = mem b ∨ NotTabA (mem' b)) + (hA : ∀ b, AsidWordsA Pp ksb b → mem' b = mem b) (hP : PoolKeepA Pp σ σ') + (hc : PtClosedA th S1 T2 mem mem') : VsUniqA th Pp S1 X Y T2 Sh2 mem' ksb σ' where + t2 y hy ptr asid va hcap hT w hw h3 hd := by + obtain ⟨yc, hyc, hcap0⟩ := (hc.pt y hy ptr asid va true hcap).resolve_right (fun h => h.elim (fun h => h.2 hT) (fun h => h.2 hT)) + have hw0 := hw.shrink E.xal hmE hP + have hf : mem' w = mem w := eqOfValidA (hmE w hw) h3 + rw [hf] at h3 hd + obtain ⟨r, hr, hws⟩ := U.t2 yc hyc ptr asid va hcap0 hT w hw0 h3 hd + refine ⟨r, hr.of_spec hP.1 hP.2, ?_⟩ + exact (walk_shrink2 E U.forest E.xal hmE hP hws (Or.inl ⟨hr.active, rfl, rfl⟩) hw).2 + s1 y hy ptr asid va hcap hS tag sh t i hpath htab h12 hi h3 hd := by + obtain ⟨yc, hyc, hcap0⟩ := (hc.pt y hy ptr asid va true hcap).resolve_right (fun h => h.elim (fun h => h.1 hS) (fun h => by cases h.1)) + have hf : mem' (peAF t i) = mem (peAF t i) := eqOfValidA (hmV _ ⟨tag, sh, t, i, hpath, htab, h12, hi, rfl⟩) h3 + rw [hf] at h3 hd + obtain ⟨raw, hact, hw⟩ := U.s1 yc hyc ptr asid va hcap0 hS tag sh t i (hpath.shrink hA hmV) htab h12 hi h3 hd + have hact' : ActiveAsidRootA mem' ksb Pp asid raw := + ActiveAsidRootA.shrink (mem := mem') (mem' := mem) (fun b hb => (hA b hb).symm) hact + have hent : S1EntryA Pp S1 Y mem' ksb (peAF t i) := ⟨tag, sh, t, i, hpath, htab, h12, hi, rfl⟩ + refine ⟨raw, hact', ?_⟩ + rcases hw with ⟨h0, hr, hws⟩ | ⟨h2, hy2, hws⟩ + · exact Or.inl ⟨h0, hr, (walk_shrink1 R U.forest hA hmV hws rfl ⟨0#u64, .native hact h0 hr⟩ (Or.inl hr) hent).2⟩ + · exact Or.inr ⟨h2, hy2, (walk_shrink1 R U.forest hA hmV hws rfl ⟨2#u64, .high hact h2 hy2⟩ + (Or.inr ⟨untagA raw, hy2, rfl⟩) hent).2⟩ + out y hy ptr asid va hcap := by + rcases hc.pt y hy ptr asid va false hcap with ⟨yc, hyc, hcap0⟩ | hu + · exact U.out yc hyc ptr asid va hcap0 + · exact hu.elim (fun h => h.2) (fun h => h.2) + inj2 w1 w2 h1 h2 v1 v2 hd hT := by + have h1' := h1.shrink E.xal hmE hP + have h2' := h2.shrink E.xal hmE hP + have f1 : mem' w1 = mem w1 := eqOfValidA (hmE w1 h1) v1 + have f2 : mem' w2 = mem w2 := eqOfValidA (hmE w2 h2) v2 + rw [f1] at v1 hd hT + rw [f2] at v2 hd + exact U.inj2 w1 w2 h1' h2' v1 v2 hd hT + rootInj2 a1 a2 r h1 h2 := + U.rootInj2 a1 a2 r (S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h1) + (S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h2) + inj1 tag tag' sh sh' t t' i i' p1 tb1 h12 hi v1 p2 tb2 h12' hi' v2 hd hS := by + have e1 : mem' (peAF t i) = mem (peAF t i) := eqOfValidA (hmV _ ⟨tag, sh, t, i, p1, tb1, h12, hi, rfl⟩) v1 + have e2 : mem' (peAF t' i') = mem (peAF t' i') := eqOfValidA (hmV _ ⟨tag', sh', t', i', p2, tb2, h12', hi', rfl⟩) v2 + rw [e1] at v1 hd hS + rw [e2] at v2 hd + exact U.inj1 tag tag' sh sh' t t' i i' (p1.shrink hA hmV) tb1 h12 hi v1 (p2.shrink hA hmV) tb2 h12' hi' v2 hd hS + rootInj1 a1 a2 raw h1 h2 := + U.rootInj1 a1 a2 raw (h1.shrink hA) (h2.shrink hA) + rootOnce := U.rootOnce.step hc.root (fun r hI => + hI.imp (fun ⟨a, raw, h, e⟩ => ⟨a, raw, h.shrink hA, e⟩) + (fun ⟨a, h⟩ => ⟨a, S2RootOfAsidA.of_spec hP.1.symm (fun p hp => (hP.2 p hp).symm) h⟩)) + ptOnce := U.ptOnce.step hc.ptu + +end shrink + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsUniqStaleA.lean b/proofs/Fl4ProofsA64/P3/VsUniqStaleA.lean new file mode 100644 index 000000000..df81e8a61 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUniqStaleA.lean @@ -0,0 +1,62 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, RO3): **the core of `ptUnmapT2Stale`** — the unmap of a mapped Stage-2 table +`ptr ∈ Z.T2` whose ASID names no Stage-2 root (kind `none`, a deleted ASID, or `stage1`). + +* `S2RootOfAsidA.kind`: a Stage-2 root installed at `asid` makes `asidRootKind σ asid = some .stage2`; +* `VsUniqA.no_reach_stale`: **no reachable valid table descriptor names `ptr`**, from `VsUniqA.t2` (every such + descriptor would be on the walk of a Stage-2 root installed at the cap's ASID) and the ASID's kind; +* `VsUniqA.hno_stale`: the same in the dirty-bit form of `JStage3A.ptUnmapT2A`'s `hno5` (entries at `T2 \ {ptr}`). + +This replaces the arm premise `hUniq` (`PtUniqT2A`) for the stale case. No named premise. New module. +-/ +import Fl4ProofsA64.P3.ExtVsTopA +import Fl4ProofsA64.P3.VsUniqT2ShrinkA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +section stale +variable {th : TypedHeapA} {Pp S1 X Y T2 : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {ksb : U64} + {σ : Fl4SpecA64.State Unit} + +theorem S2RootOfAsidA.kind (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) {asid r : U64} + (h : S2RootOfAsidA Pp X σ asid r) : + Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage2 := by + obtain ⟨hr, p, f, h0, hp, htab, hk, hf⟩ := h + have hv : Fl4SpecA64.vspaceForAsid (BitVec.ofNat 16 asid.val) σ = some (specPtr r) := by + rw [vspaceForAsid_posA h0, specVsA_eqA htab hk, hf] + rfl + rw [asidRootKind_ofE hv] + obtain ⟨es, hes, -⟩ := E.s2root r hr + have : Fl4SpecA64.rootKindAt σ (specPtr r) = .stage2 := by + simp [Fl4SpecA64.rootKindAt, Fl4SpecA64.extObjAt, hes] + rw [this] + +/-- **No reachable valid table descriptor names the table of a stale mapped cap.** -/ +theorem VsUniqA.no_reach_stale (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) + {y ptr asid va : U64} (hy : IsSlotA th y) (hcap : capAtA mem y = .PageTable ptr true asid va) (hT : ptr ∈ T2) + (hk : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ + Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) : + ∀ w, S2EntryA Pp X T2 Sh2 mem σ w → (mem w &&& 3#u64) = 3#u64 → dTabA (mem w) ≠ ptr := by + intro w hw h3 hd + obtain ⟨r, hr, -⟩ := U.t2 y hy ptr asid va hcap hT w hw h3 hd + have := hr.kind E + rcases hk with h | h <;> rw [this] at h <;> cases h + +/-- The same in the form of `JStage3A.ptUnmapT2A`'s `hno5` (entries of the shrunk table set, dirty bits). -/ +theorem VsUniqA.hno_stale (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) + {y ptr asid va : U64} (hy : IsSlotA th y) (hcap : capAtA mem y = .PageTable ptr true asid va) (hT : ptr ∈ T2) + (hk : Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = none ∨ + Fl4SpecA64.asidRootKind σ (BitVec.ofNat 16 asid.val) = some .stage1) : + ∀ w, S2EntryA Pp X (T2 \ {ptr}) Sh2 mem σ w → dBitA (mem w) 0 = true → dBitA (mem w) 1 = true → + dTabA (mem w) ≠ ptr := fun w hw hb0 hb1 => + U.no_reach_stale E hy hcap hT hk w (hw.mono (T2 := T2) (fun _ (h : _ ∈ T2 \ {ptr}) => h.1)) ((and3_bits_sh _).2 ⟨hb0, hb1⟩) + +end stale + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsUniqT2ShrinkA.lean b/proofs/Fl4ProofsA64/P3/VsUniqT2ShrinkA.lean new file mode 100644 index 000000000..6514b428d --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsUniqT2ShrinkA.lean @@ -0,0 +1,112 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, RO3): **`VsUniqA` at a smaller Stage-2 table set** (`PtUnmT2A`'s +shrink-before-cap-write: `JAtZAX.shrinkT2A`). + +* `S2ReachA.mono` / `S2EntryA.mono`: reachability at `T2' ⊆ T2` is reachability at `T2`; +* `S2WalkTabA.reachT2`: a `T2'`-entry in a slot of the walk's table makes that table `T2'`-reachable; +* `walk_shrinkT2`: **the walk of an address to a `T2'`-reachable entry stays inside `T2'`** (the forest property + `inj2` identifies the `T2'`-path with the walk, as `walk_shrink2`); +* `VsUniqA.shrinkT2`: the record at `T2'` (`Stage-1` half and the caps unchanged). + +No named premise. New module. +-/ +import Fl4ProofsA64.P3.VsUniqShrinkA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +section t2 +variable {th : TypedHeapA} {Pp S1 X Y T2 T2' : Set U64} {Sh2 : U64 → Nat} {mem : U64 → U64} {ksb : U64} + {σ : Fl4SpecA64.State Unit} + +theorem S2ReachA.mono (hT : T2' ⊆ T2) {q : U64} (h : S2ReachA Pp X T2' Sh2 mem σ q) : + S2ReachA Pp X T2 Sh2 mem σ q := by + induction h with + | root ha => exact .root ha + | stepRoot ha hi h3 hc => exact .stepRoot ha hi h3 (hT hc) + | stepPt _ ht h12 hi h3 hc ih => exact .stepPt ih (hT ht) h12 hi h3 (hT hc) + +theorem S2EntryA.mono (hT : T2' ⊆ T2) {w : U64} (h : S2EntryA Pp X T2' Sh2 mem σ w) : + S2EntryA Pp X T2 Sh2 mem σ w := by + rcases h with ⟨r, i, ha, hi, e⟩ | ⟨t, i, hr, ht, h12, hi, e⟩ + · exact Or.inl ⟨r, i, ha, hi, e⟩ + · exact Or.inr ⟨t, i, hr.mono hT, hT ht, h12, hi, e⟩ + +/-- **A `T2'`-entry in a slot of the walk's table makes that table `T2'`-reachable.** -/ +theorem S2WalkTabA.reachT2 (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) (hT : T2' ⊆ T2) {t : U64} {sh n : Nat} + {i : U64} (ht : S2WalkTabA Pp X T2 Sh2 mem σ t sh n) (hi : i.val < n) + (hw : S2EntryA Pp X T2' Sh2 mem σ (peAF t i)) : S2ReachA Pp X T2' Sh2 mem σ t := by + rcases ht with ⟨ha, rfl, rfl⟩ | ⟨htT, hr, rfl, rfl⟩ + · have hi1k : i.val < 1024 := by have := s2Top1k; omega + rcases hw with ⟨r', i', ha', hi', e⟩ | ⟨t1, i1, hr1, ht1, h121, hi1', e⟩ + · have hi'1k : i'.val < 1024 := by have := s2Top1k; omega + have := root_root_eq E ha'.1 ha.1 hi'1k hi1k e.symm + subst this + exact .root ha' + · exact absurd e (root_tab_ne E ha.1 (hT ht1) hi1k hi1') + · rcases hw with ⟨r', i', ha', hi', e⟩ | ⟨t1, i1, hr1, ht1, h121, hi1', e⟩ + · have hi'1k : i'.val < 1024 := by have := s2Top1k; omega + exact absurd e.symm (root_tab_ne E ha'.1 htT hi'1k hi) + · have := (peAF_injA_s (Nat.mod_eq_zero_of_dvd (E.tal t1 (hT ht1))) (Nat.mod_eq_zero_of_dvd (E.tal t htT)) + hi1' hi e.symm).1 + subst this + exact hr1 + +/-- **The walk of an address to a `T2'`-reachable entry stays inside `T2'`.** -/ +theorem walk_shrinkT2 (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) + (hT : T2' ⊆ T2) {va t w : U64} {sh n : Nat} (W : WalkSlotA (· ∈ T2) mem va t sh n w) + (ht : S2WalkTabA Pp X T2 Sh2 mem σ t sh n) (hw : S2EntryA Pp X T2' Sh2 mem σ w) : + S2ReachA Pp X T2' Sh2 mem σ t ∧ WalkSlotA (· ∈ T2') mem va t sh n w := by + revert ht hw + induction W with + | here t sh n => + intro ht hw + have hn := ht.n_pos + exact ⟨ht.reachT2 E hT (walkIdx_lt va sh n hn.1 hn.2) hw, .here t sh n⟩ + | @down t sh n w h3 h12 hc W' ih => + intro ht hw + have hn := ht.n_pos + have hi := walkIdx_lt va sh n hn.1 hn.2 + obtain ⟨ht', hent⟩ := S2WalkTabA.step E ht hi h3 h12 hc + obtain ⟨hR', hW'⟩ := ih ht' hw + have key : ∀ q, S2EntryA Pp X T2' Sh2 mem σ q → (mem q &&& 3#u64) = 3#u64 → + dTabA (mem q) = dTabA (mem (peAF t (walkIdx va sh n))) → dTabA (mem q) ∈ T2' → + S2ReachA Pp X T2' Sh2 mem σ t ∧ dTabA (mem (peAF t (walkIdx va sh n))) ∈ T2' := by + intro q hq hqv hdq hq2 + have := U.inj2 q _ (hq.mono hT) hent hqv h3 hdq (by rw [hdq]; exact hc) + subst this + exact ⟨ht.reachT2 E hT hi hq, by rw [← hdq]; exact hq2⟩ + obtain ⟨hr, hch⟩ : S2ReachA Pp X T2' Sh2 mem σ t ∧ dTabA (mem (peAF t (walkIdx va sh n))) ∈ T2' := by + rcases hR'.inv with hr | ⟨r, i, ha, hi', h3', hc', hq⟩ | ⟨t1, i, hr1, ht1, h121, hi1, h3', hc', hq⟩ + · exact absurd rfl (E.t2x _ hc _ hr.1).1 + · exact key (peAF r i) (Or.inl ⟨r, i, ha, hi', rfl⟩) h3' hq.symm hc' + · exact key (peAF t1 i) (Or.inr ⟨t1, i, hr1, ht1, h121, hi1, rfl⟩) h3' hq.symm hc' + exact ⟨hr, .down t sh n w h3 h12 hch hW'⟩ + +/-- **`VsUniqA` at a smaller Stage-2 table set.** -/ +theorem VsUniqA.shrinkT2 (U : VsUniqA th Pp S1 X Y T2 Sh2 mem ksb σ) (E : ExtVsRelA Pp S1 X Y T2 Sh2 mem σ) + (hT : T2' ⊆ T2) : VsUniqA th Pp S1 X Y T2' Sh2 mem ksb σ where + t2 y hy ptr asid va hcap hP w hw h3 hd := by + have hw0 := hw.mono hT + obtain ⟨r, hr, hws⟩ := U.t2 y hy ptr asid va hcap (hT hP) w hw0 h3 hd + refine ⟨r, hr, ?_⟩ + exact (walk_shrinkT2 E U hT hws (Or.inl ⟨hr.active, rfl, rfl⟩) hw).2 + s1 := U.s1 + out y hy ptr asid va hcap h := U.out y hy ptr asid va hcap (hT h) + inj2 w1 w2 h1 h2 v1 v2 hd hP := U.inj2 w1 w2 (h1.mono hT) (h2.mono hT) v1 v2 hd (hT hP) + rootInj2 := U.rootInj2 + inj1 := U.inj1 + rootInj1 := U.rootInj1 + rootOnce := U.rootOnce + ptOnce := U.ptOnce + +end t2 + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsW1A.lean b/proofs/Fl4ProofsA64/P3/VsW1A.lean new file mode 100644 index 000000000..39993ed47 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsW1A.lean @@ -0,0 +1,275 @@ +/- +P3 (aarch64, Stage 5 vsinv S6): **`VsUniqA` at A64-Boot's `w1`** (`w1_vsuA_of`). `w1` has no Stage-2 root, high window +or Stage-2 table (`X = Y = T2 = ∅`), so only the Stage-1 fields have content: the one active ASID is 1 (pool entry 1, +the VSpace root), the walk is root[0] → L1[0] → L2[2] → L3, and the three mapped page-table caps of +`create_it_address_space` (L1 and L2 at address 0, L3 at 0x400000, ASID 1) lie on it. No premise. New module. +-/ +import Fl4ProofsA64.P3.JBootW1SA +import Fl4ProofsA64.P3.VsUniqA +import Fl4ProofsA64.P2.BootSysA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 Fl4ProofsA64.P1.W7.R.ST Fl4ProofsA64.P1.W7.R.ST.BootWit + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +/-- A root CNode slot holding a page-table cap is one of the root task's three (L1, L2, L3). -/ +theorem capOf_ptCapA (nc i : Nat) {p : U64} {mp : Bool} {asid va : U64} + (h : capOf nc i = .PageTable p mp asid va) : + asid = 1#u64 ∧ ((p = bwv L1b ∧ va = 0#u64) ∨ (p = bwv L2b ∧ va = 0#u64) ∨ (p = bwv L3b ∧ va = bwv 4194304)) := by + unfold capOf at h + by_cases hlo : i < 16 + · rw [slotC_lo hlo] at h + interval_cases i <;> cases h + by_cases hsc : i < 16 + nc + · rw [slotC_sch (by omega) hsc] at h + cases h + rw [slotC_hi (by omega)] at h + generalize i - (16 + nc) = k at h + by_cases hlt : k < 37 + · interval_cases k <;> cases h <;> simp + · rw [tailC_big (by omega)] at h + cases h + +/-- No root CNode slot holds an UNMAPPED root cap (`rootOnce` at boot; the root task's VSpace cap is mapped). -/ +theorem capOf_noRootUnmA (nc i : Nat) {q : U64} (h : RootUnmA q (capOf nc i)) : False := by + unfold capOf at h + by_cases hlo : i < 16 + · rw [slotC_lo hlo] at h + interval_cases i <;> rcases h with ⟨a, h⟩ | ⟨a, v, h⟩ | ⟨a, h⟩ <;> cases h + by_cases hsc : i < 16 + nc + · rw [slotC_sch (by omega) hsc] at h + rcases h with ⟨a, h⟩ | ⟨a, v, h⟩ | ⟨a, h⟩ <;> cases h + rw [slotC_hi (by omega)] at h + generalize i - (16 + nc) = k at h + by_cases hlt : k < 37 + · interval_cases k <;> rcases h with ⟨a, h⟩ | ⟨a, v, h⟩ | ⟨a, h⟩ <;> cases h + · rw [tailC_big (by omega)] at h + rcases h with ⟨a, h⟩ | ⟨a, v, h⟩ | ⟨a, h⟩ <;> cases h + +/-- No root CNode slot holds an UNMAPPED page-table cap (the twin of `capOf_noRootUnmA`). -/ +theorem capOf_noPtUnmA (nc i : Nat) {q : U64} (h : PtUnmA q (capOf nc i)) : False := by + unfold capOf at h + by_cases hlo : i < 16 + · rw [slotC_lo hlo] at h + interval_cases i <;> rcases h with ⟨a, v, h⟩ <;> cases h + by_cases hsc : i < 16 + nc + · rw [slotC_sch (by omega) hsc] at h + rcases h with ⟨a, v, h⟩ <;> cases h + rw [slotC_hi (by omega)] at h + generalize i - (16 + nc) = k at h + by_cases hlt : k < 37 + · interval_cases k <;> rcases h with ⟨a, v, h⟩ <;> cases h + · rw [tailC_big (by omega)] at h + rcases h with ⟨a, v, h⟩ <;> cases h + +section vs +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} + +theorem w1_bwvNeA {a b : Nat} (ha : a < 2 ^ 64) (hb : b < 2 ^ 64) (h : a ≠ b) : bwv a ≠ bwv b := fun e => + h (by have := congrArg UScalar.val e; rwa [wv ha, wv hb] at this) + +theorem w1_tabE_and3A {t : Nat} (ht : t = L1b ∨ t = L2b ∨ t = L3b) : (bwv (tabE t) &&& 3#u64) = 3#u64 := by + rcases ht with rfl | rfl | rfl <;> rfl + +/-- The only active ASID of `w1` is 1, with the root task's VSpace root. -/ +theorem w1_activeA (P : BootLay1 kb ib nc) {asid raw : U64} + (h : ActiveAsidRootA (w1M kb ib nc r now mt sl uw) kb w1Pp asid raw) : asid = 1#u64 ∧ raw = bwv VSb := by + obtain ⟨hi, lo, hhi, hlo, he, pool, hp, hpne, htab, hw, hrne⟩ := h + rw [w1_asidW P hhi] at htab + by_cases h0 : hi.val = 0 + · rw [if_pos h0] at htab + subst htab + rw [w1_poolW P hlo] at hw + by_cases h1 : lo.val = 1 + · rw [if_pos h1] at hw + refine ⟨UScalar.eq_of_val_eq ?_, hw.symm⟩ + rw [he, h0, h1]; rfl + · rw [if_neg h1] at hw; exact absurd hw.symm hrne + · rw [if_neg h0] at htab; exact absurd htab.symm hpne + +theorem w1_activeIA (P : BootLay1 kb ib nc) : + ActiveAsidRootA (w1M kb ib nc r now mt sl uw) kb w1Pp 1#u64 (bwv VSb) := by + refine ⟨0#u64, 1#u64, by decide, by decide, by rfl, bwv PLb, vPL, bwv_PL_ne0, ?_, ?_, ?_⟩ + · rw [w1_asidW P (hi := 0#u64) (by decide), if_pos (show (0#u64 : U64).val = 0 from rfl)] + · rw [w1_poolW P (lo := 1#u64) (by decide), if_pos (show (1#u64 : U64).val = 1 from rfl)] + · exact fun e => by have := congrArg UScalar.val e; rw [vVS] at this; simp at this + +/-- The valid table descriptors of the three upper tables of `w1`: one each. -/ +theorem w1_descA (P : BootLay1 kb ib nc) {t i : U64} (ht : t = bwv VSb ∨ t = bwv L1b ∨ t = bwv L2b) + (hi : i.val < 512) (h3 : (w1M kb ib nc r now mt sl uw (peAF t i) &&& 3#u64) = 3#u64) : + (t = bwv VSb ∧ i = 0#u64 ∧ dTabA (w1M kb ib nc r now mt sl uw (peAF t i)) = bwv L1b) ∨ + (t = bwv L1b ∧ i = 0#u64 ∧ dTabA (w1M kb ib nc r now mt sl uw (peAF t i)) = bwv L2b) ∨ + (t = bwv L2b ∧ i = 2#u64 ∧ dTabA (w1M kb ib nc r now mt sl uw (peAF t i)) = bwv L3b) := by + have vL1 : (bwv L1b).val = L1b := wv (by norm_num) + have vL2 : (bwv L2b).val = L2b := wv (by norm_num) + have z : ¬ ((0#u64 : U64) &&& 3#u64) = 3#u64 := by + intro e; have := congrArg UScalar.val e; simp at this + rcases ht with rfl | rfl | rfl + · rw [w1_ptMem P (Or.inl vVS) hi, vVS, ptWA_VS] at h3 ⊢ + by_cases h : 8 * i.val = 0 + · rw [if_pos h] + exact Or.inl ⟨rfl, UScalar.eq_of_val_eq (show i.val = 0 by omega), (tabE_okA (Or.inl rfl)).2.2.2⟩ + · rw [if_neg h] at h3; exact absurd h3 z + · rw [w1_ptMem P (Or.inr (Or.inl vL1)) hi, vL1, ptWA_L1] at h3 ⊢ + by_cases h : 8 * i.val = 0 + · rw [if_pos h] + exact Or.inr (Or.inl ⟨rfl, UScalar.eq_of_val_eq (show i.val = 0 by omega), (tabE_okA (Or.inr (Or.inl rfl))).2.2.2⟩) + · rw [if_neg h] at h3; exact absurd h3 z + · rw [w1_ptMem P (Or.inr (Or.inr (Or.inl vL2))) hi, vL2, ptWA_L2] at h3 ⊢ + by_cases h : 8 * i.val = 16 + · rw [if_pos h] + exact Or.inr (Or.inr ⟨rfl, UScalar.eq_of_val_eq (show i.val = 2 by omega), (tabE_okA (Or.inr (Or.inr rfl))).2.2.2⟩) + · rw [if_neg h] at h3; exact absurd h3 z + +/-- The Stage-1 walk of `w1`: four tables. -/ +theorem w1_vsPathA (P : BootLay1 kb ib nc) {tag : U64} {sh : Nat} {t : U64} + (h : VsPathA w1Pp w1Tb ∅ (w1M kb ib nc r now mt sl uw) kb tag sh t) : + (sh = 39 ∧ t = bwv VSb) ∨ (sh = 30 ∧ t = bwv L1b) ∨ (sh = 21 ∧ t = bwv L2b) ∨ (sh = 12 ∧ t = bwv L3b) := by + induction h with + | native hact _ _ => exact Or.inl ⟨rfl, (w1_activeA P hact).2⟩ + | high _ _ hy => exact absurd hy (Set.notMem_empty _) + | child _ _ h12 hi h3 ih => + rcases ih with ⟨rfl, ht⟩ | ⟨rfl, ht⟩ | ⟨rfl, ht⟩ | ⟨rfl, ht⟩ + · rcases w1_descA P (Or.inl ht) hi h3 with ⟨-, -, e⟩ | ⟨e', -⟩ | ⟨e', -⟩ + · exact Or.inr (Or.inl ⟨rfl, e⟩) + · exact absurd (ht.symm.trans e') (w1_bwvNeA (by norm_num) (by norm_num) (by norm_num)) + · exact absurd (ht.symm.trans e') (w1_bwvNeA (by norm_num) (by norm_num) (by norm_num)) + · rcases w1_descA P (Or.inr (Or.inl ht)) hi h3 with ⟨e', -⟩ | ⟨-, -, e⟩ | ⟨e', -⟩ + · exact absurd (ht.symm.trans e') (w1_bwvNeA (by norm_num) (by norm_num) (by norm_num)) + · exact Or.inr (Or.inr (Or.inl ⟨rfl, e⟩)) + · exact absurd (ht.symm.trans e') (w1_bwvNeA (by norm_num) (by norm_num) (by norm_num)) + · rcases w1_descA P (Or.inr (Or.inr ht)) hi h3 with ⟨e', -⟩ | ⟨e', -⟩ | ⟨-, -, e⟩ + · exact absurd (ht.symm.trans e') (w1_bwvNeA (by norm_num) (by norm_num) (by norm_num)) + · exact absurd (ht.symm.trans e') (w1_bwvNeA (by norm_num) (by norm_num) (by norm_num)) + · exact Or.inr (Or.inr (Or.inr ⟨rfl, e⟩)) + · omega + +/-- A reachable valid table descriptor of `w1` above level 3 is one of three. -/ +theorem w1_pathDescA (P : BootLay1 kb ib nc) {tag : U64} {sh : Nat} {t i : U64} + (h : VsPathA w1Pp w1Tb ∅ (w1M kb ib nc r now mt sl uw) kb tag sh t) (h12 : 12 < sh) (hi : i.val < 512) + (h3 : (w1M kb ib nc r now mt sl uw (peAF t i) &&& 3#u64) = 3#u64) : + (t = bwv VSb ∧ i = 0#u64 ∧ dTabA (w1M kb ib nc r now mt sl uw (peAF t i)) = bwv L1b) ∨ + (t = bwv L1b ∧ i = 0#u64 ∧ dTabA (w1M kb ib nc r now mt sl uw (peAF t i)) = bwv L2b) ∨ + (t = bwv L2b ∧ i = 2#u64 ∧ dTabA (w1M kb ib nc r now mt sl uw (peAF t i)) = bwv L3b) := by + refine w1_descA P ?_ hi h3 + rcases w1_vsPathA P h with ⟨-, e⟩ | ⟨-, e⟩ | ⟨-, e⟩ | ⟨e, -⟩ + · exact Or.inl e + · exact Or.inr (Or.inl e) + · exact Or.inr (Or.inr e) + · omega + +/-- The three descriptors are on the walks of the three caps' addresses. -/ +theorem w1_walkA (P : BootLay1 kb ib nc) : + let M := w1M kb ib nc r now mt sl uw + WalkSlotA (S1TabA w1Tb ∅) M 0#u64 (bwv VSb) 39 512 (peAF (bwv VSb) 0#u64) ∧ + WalkSlotA (S1TabA w1Tb ∅) M 0#u64 (bwv VSb) 39 512 (peAF (bwv L1b) 0#u64) ∧ + WalkSlotA (S1TabA w1Tb ∅) M (bwv 4194304) (bwv VSb) 39 512 (peAF (bwv L2b) 2#u64) := by + intro M + have vL1 : (bwv L1b).val = L1b := wv (by norm_num) + have vL2 : (bwv L2b).val = L2b := wv (by norm_num) + have w0 : ∀ sh, walkIdx 0#u64 sh 512 = 0#u64 := fun sh => by + unfold walkIdx; apply UScalar.eq_of_val_eq; simp [UScalar.val] + have a39 : walkIdx (bwv 4194304) 39 512 = 0#u64 := by unfold walkIdx; rfl + have a30 : walkIdx (bwv 4194304) 30 512 = 0#u64 := by unfold walkIdx; rfl + have a21 : walkIdx (bwv 4194304) 21 512 = 2#u64 := by unfold walkIdx; rfl + have mVS : M (peAF (bwv VSb) 0#u64) = bwv (tabE L1b) := by + show w1M kb ib nc r now mt sl uw _ = _ + rw [w1_ptMem P (Or.inl vVS) (by decide), vVS, ptWA_VS]; rfl + have mL1 : M (peAF (bwv L1b) 0#u64) = bwv (tabE L2b) := by + show w1M kb ib nc r now mt sl uw _ = _ + rw [w1_ptMem P (Or.inr (Or.inl vL1)) (by decide), vL1, ptWA_L1]; rfl + have tL1 : S1TabA w1Tb ∅ (bwv L1b) := Or.inl (Or.inr (Or.inl vL1)) + have tL2 : S1TabA w1Tb ∅ (bwv L2b) := Or.inl (Or.inr (Or.inr (Or.inl vL2))) + have dVS : dTabA (M (peAF (bwv VSb) 0#u64)) = bwv L1b := by rw [mVS]; exact (tabE_okA (Or.inl rfl)).2.2.2 + have dL1 : dTabA (M (peAF (bwv L1b) 0#u64)) = bwv L2b := by rw [mL1]; exact (tabE_okA (Or.inr (Or.inl rfl))).2.2.2 + have vVS3 : (M (peAF (bwv VSb) 0#u64) &&& 3#u64) = 3#u64 := by rw [mVS]; exact w1_tabE_and3A (Or.inl rfl) + have vL13 : (M (peAF (bwv L1b) 0#u64) &&& 3#u64) = 3#u64 := by + rw [mL1]; exact w1_tabE_and3A (Or.inr (Or.inl rfl)) + have down : ∀ (va t c : U64) (sh : Nat) (w : U64), walkIdx va sh 512 = 0#u64 → (M (peAF t 0#u64) &&& 3#u64) = 3#u64 → + 12 < sh → dTabA (M (peAF t 0#u64)) = c → S1TabA w1Tb ∅ c → WalkSlotA (S1TabA w1Tb ∅) M va c (sh - 9) 512 w → + WalkSlotA (S1TabA w1Tb ∅) M va t sh 512 w := by + intro va t c sh w hx hv h12 hd hc hw + refine .down t sh 512 w ?_ h12 ?_ ?_ <;> rw [hx] + · exact hv + · rw [hd]; exact hc + · rw [hd]; exact hw + refine ⟨?_, ?_, ?_⟩ + · have := WalkSlotA.here (P := S1TabA w1Tb ∅) (mem := M) (va := 0#u64) (bwv VSb) 39 512 + rwa [w0] at this + · refine down _ _ _ 39 _ (w0 _) vVS3 (by omega) dVS tL1 ?_ + have := WalkSlotA.here (P := S1TabA w1Tb ∅) (mem := M) (va := 0#u64) (bwv L1b) 30 512 + rwa [w0] at this + · refine down _ _ _ 39 _ a39 vVS3 (by omega) dVS tL1 (down _ _ _ 30 _ a30 vL13 (by omega) dL1 tL2 ?_) + have := WalkSlotA.here (P := S1TabA w1Tb ∅) (mem := M) (va := bwv 4194304) (bwv L2b) 21 512 + rwa [a21] at this + +/-- **`VsUniqA` at `w1`.** -/ +theorem w1_vsuA_of (hL : BootLayA ib nc) (hK : BootKsA kb ib nc) (P : BootLay1 kb ib nc) (σ : Fl4SpecA64.State Unit) + (Sh2 : U64 → Nat) : + VsUniqA (w1ThA kb ib nc) w1Pp w1Tb ∅ ∅ ∅ Sh2 (w1M kb ib nc r now mt sl uw) kb σ where + t2 _ _ _ _ _ _ h := absurd h (Set.notMem_empty _) + s1 y hy ptr asid va hc _ tag sh t i hp _ h12 hi h3 hd := by + have hy' : y ∈ w1OS kb ib nc := + (congrArg (fun slots : Set U64 => y ∈ slots) (w1OS_eqA hL hK P)).mp hy + change capA bst (w1S kb ib nc r now mt sl uw) y = .PageTable ptr true asid va at hc + have hcap : ∃ j, capOf nc j = .PageTable ptr true asid va := by + rcases w1_capS P hy' with e | ⟨j, -, -, e⟩ | ⟨-, e⟩ | ⟨-, e⟩ | ⟨-, e⟩ | ⟨_, -, -, -, e⟩ <;> rw [e] at hc + · cases hc + · exact ⟨j, hc⟩ + · exact ⟨2, hc⟩ + · exact ⟨3, hc⟩ + · cases hc + · cases hc + obtain ⟨j, hj⟩ := hcap + obtain ⟨rfl, hv⟩ := capOf_ptCapA nc j hj + refine ⟨bwv VSb, w1_activeIA P, Or.inl ⟨by simp [tagA, vVS], Or.inl vVS, ?_⟩⟩ + obtain ⟨wA, wB, wC⟩ := w1_walkA (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P + rcases w1_pathDescA P hp h12 hi h3 with ⟨rfl, rfl, e⟩ | ⟨rfl, rfl, e⟩ | ⟨rfl, rfl, e⟩ <;> + rw [e] at hd <;> subst hd <;> rcases hv with ⟨q, rfl⟩ | ⟨q, rfl⟩ | ⟨q, rfl⟩ + all_goals first + | exact wA + | exact wB + | exact wC + | exact absurd q (w1_bwvNeA (by norm_num) (by norm_num) (by norm_num)) + out _ _ _ _ _ _ := Set.notMem_empty _ + inj2 w1 _ h1 := by + rcases h1 with ⟨_, _, ha, -⟩ | ⟨_, _, -, ht, -⟩ + · exact absurd ha.1 (Set.notMem_empty _) + · exact absurd ht (Set.notMem_empty _) + rootInj2 _ _ _ h1 := absurd h1.1 (Set.notMem_empty _) + inj1 _ _ _ _ t t' i i' p1 _ h12 hi h3 p2 _ h12' hi' h3' he _ := by + rcases w1_pathDescA P p1 h12 hi h3 with ⟨rfl, rfl, e⟩ | ⟨rfl, rfl, e⟩ | ⟨rfl, rfl, e⟩ <;> + rcases w1_pathDescA P p2 h12' hi' h3' with ⟨rfl, rfl, e'⟩ | ⟨rfl, rfl, e'⟩ | ⟨rfl, rfl, e'⟩ <;> + have he' := e.symm.trans (he.trans e') + all_goals first + | rfl + | exact absurd he' (w1_bwvNeA (by norm_num) (by norm_num) (by norm_num)) + rootInj1 _ _ _ h1 h2 := (w1_activeA P h1).1.trans (w1_activeA P h2).1.symm + rootOnce y hy rr h := by + exfalso + have hy' : y ∈ w1OS kb ib nc := + (congrArg (fun slots : Set U64 => y ∈ slots) (w1OS_eqA hL hK P)).mp hy + change RootUnmA rr (capA bst (w1S kb ib nc r now mt sl uw) y) at h + rcases w1_capS P hy' with e | ⟨j, -, -, e⟩ | ⟨-, e⟩ | ⟨-, e⟩ | ⟨-, e⟩ | ⟨_, -, -, -, e⟩ <;> rw [e] at h + all_goals first + | exact capOf_noRootUnmA _ _ h + | (rcases h with ⟨a, h⟩ | ⟨a, v, h⟩ | ⟨a, h⟩ <;> cases h) + ptOnce y hy rr h := by + exfalso + have hy' : y ∈ w1OS kb ib nc := + (congrArg (fun slots : Set U64 => y ∈ slots) (w1OS_eqA hL hK P)).mp hy + change PtUnmA rr (capA bst (w1S kb ib nc r now mt sl uw) y) at h + rcases w1_capS P hy' with e | ⟨j, -, -, e⟩ | ⟨-, e⟩ | ⟨-, e⟩ | ⟨-, e⟩ | ⟨_, -, -, -, e⟩ <;> rw [e] at h + all_goals first + | exact capOf_noPtUnmA _ _ h + | (rcases h with ⟨a, v, h⟩ <;> cases h) + +end vs + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsWalkHiA.lean b/proofs/Fl4ProofsA64/P3/VsWalkHiA.lean new file mode 100644 index 000000000..b72cbab59 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsWalkHiA.lean @@ -0,0 +1,147 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, G): **the walk bridge of `lookup_pt_slot` from a high-window root** +(`lookup_walk_hiA`, the window twin of `lookup_walkA`): the returned slot is on `WalkSlotA` of every address that +shares the walk's indices with the looked-up one, from the window table `wa y 4096` at shift 30. The first step +(from the window root `y`, entry 511) is peeled by hand. No premise. New module. +-/ +import Fl4ProofsA64.P3.VsWalkSlotA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {Pp Tb : Set U64} {Lv : U64 → Nat} {X Y : Set U64} {σ : Fl4SpecA64.State Unit} + +/-- The loop invariant below the window root. -/ +def LkHiWA (Pp Tb Y : Set U64) (Lv : U64 → Nat) (mem : U64 → U64) (ksb vaddr y : U64) (x : U64 × U64 × U64) : Prop := + ∃ p, S1TabA Tb Y p ∧ VsReachA Pp Tb Y mem ksb p ∧ x.2.2.val ≤ 2 ∧ x.1.val = 12 + 9 * x.2.2.val ∧ + (p ∈ Tb → Lv p + x.2.2.val = 3) ∧ (p ∉ Tb → x.2.2.val = 2) ∧ x.2.1 = peAF p (idxA vaddr x.1) ∧ + ∀ va : U64, (∀ k, x.1.val ≤ k → walkIdx va k 512 = walkIdx vaddr k 512) → + ∀ w, WalkSlotA (S1TabA Tb Y) mem va p x.1.val 512 w → WalkSlotA (S1TabA Tb Y) mem va (wa y 4096#u64) 30 512 w + +set_option maxHeartbeats 4000000 in +theorem lookup_walk_hiA {s : S} (hR : VsRelA Pp Tb Lv X Y (L.mem s) (L.ksb s) σ) {y : U64} (hy : y ∈ Y) + (hact : ActiveHighRootA (L.mem s) (L.ksb s) Pp y) + (hb : (L.mem s (peAF y 511#u64) &&& 3#u64) = 3#u64) + (hd : dTabA (L.mem s (peAF y 511#u64)) = wa y 4096#u64) + (vaddr : U64) (hhi : idxA vaddr 39#u64 = 511#u64) : + vspace.lookup_pt_slot st s y vaddr ⦃ lu => ∀ va : U64, + (∀ k, lu.shift.val ≤ k → walkIdx va k 512 = walkIdx vaddr k 512) → + WalkSlotA (S1TabA Tb Y) (L.mem s) va (wa y 4096#u64) 30 512 lu.slot ⦄ := by + have hreach0 : VsReachA Pp Tb Y (L.mem s) (L.ksb s) (wa y 4096#u64) := by + obtain ⟨asid, raw, ha, htag, hyr⟩ := hact + refine ⟨2#u64, 30, Or.inr rfl, ?_⟩ + have := VsPathA.high (Pp := Pp) (Tb := Tb) (Y := Y) (mem := L.mem s) (ksb := L.ksb s) ha htag (hyr ▸ hy) + rw [hyr] at this; exact this + have hnb : wa y 4096#u64 ∉ Tb := hR.ytb y hy + unfold vspace.lookup_pt_slot + rw [entry_addr_eqA _ _ _ (by simp)] + simp only [bind_ok] + have e39 : vspace.TOP_LEVEL_SHIFT.val = 39 := by simp + have loop : vspace.lookup_pt_slot_loop st s vaddr vspace.TOP_LEVEL_SHIFT + (peAF y (idxA vaddr vspace.TOP_LEVEL_SHIFT)) 3#u64 ⦃ r => ∀ va : U64, + (∀ k, r.1.val ≤ k → walkIdx va k 512 = walkIdx vaddr k 512) → + WalkSlotA (S1TabA Tb Y) (L.mem s) va (wa y 4096#u64) 30 512 r.2 ⦄ := by + unfold vspace.lookup_pt_slot_loop + apply loop.spec_decr_nat (measure := fun x => x.2.2.val) + (inv := fun x => LkHiWA Pp Tb Y Lv (L.mem s) (L.ksb s) vaddr y x ∨ + x = (vspace.TOP_LEVEL_SHIFT, peAF y (idxA vaddr vspace.TOP_LEVEL_SHIFT), 3#u64)) + · rintro ⟨sh, sl, lv⟩ hx + rcases hx with ⟨p, hp, hre, hl3, hsh, hlvn, hlvn2, e, K⟩ | hx + · simp only at hl3 hsh hlvn hlvn2 e K + subst e + have hfin : ∀ va : U64, (∀ k, sh.val ≤ k → walkIdx va k 512 = walkIdx vaddr k 512) → + WalkSlotA (S1TabA Tb Y) (L.mem s) va (wa y 4096#u64) 30 512 (peAF p (idxA vaddr sh)) := by + intro va hv + refine K va hv _ ?_ + have := WalkSlotA.here (P := S1TabA Tb Y) (mem := L.mem s) (va := va) p sh.val 512 + rwa [hv _ le_rfl, ← idxA_walkIdxA] at this + dsimp only + unfold vspace.lookup_pt_slot_loop.body + split + · rename_i hpos + have hpos' : 0 < lv.val := by simpa using hpos + rw [L.read_eq, bind_ok, is_table_eqA _ _ (by omega), bind_ok] + have hidx := idxA_lt vaddr sh + by_cases ht3 : (L.mem s (peAF p (idxA vaddr sh)) &&& 3#u64) = 3#u64 + · rw [if_pos (by simp [ht3])] + obtain ⟨tag, sh0, htag, hpath⟩ := hre + have hsh0 : sh0 = sh.val := by + rcases (hR.path_props hpath).2 with ⟨hpt, -, e⟩ | ⟨-, e, y', hy', -, hq⟩ + · have := hlvn hpt; omega + · have hpn : p ∉ Tb := hq ▸ hR.ytb y' hy' + have := hlvn2 hpn; omega + subst hsh0 + have hch := hR.child_tb hpath hp (by omega) hidx ht3 + have hpath' : VsPathA Pp Tb Y (L.mem s) (L.ksb s) tag (sh.val - 9) + (dTabA (L.mem s (peAF p (idxA vaddr sh)))) := .child hpath hp (by omega) hidx ht3 + have hlv' : Lv (dTabA (L.mem s (peAF p (idxA vaddr sh)))) + (lv.val - 1) = 3 := by + rcases (hR.path_props hpath').2 with ⟨-, h3', e⟩ | ⟨-, -, y', hy', -, hq⟩ + · omega + · exact absurd (hq ▸ hch) (hR.ytb y' hy') + step as ⟨lv1, hlv1⟩ + have h9 : (core.num.U64.wrapping_sub sh 9#u64).val = sh.val - 9 := by + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits]; omega + simp only [lift, bind_ok, table_of_eqA] + rw [entry_addr_eqA _ _ _ (by rw [h9]; omega)] + simp only [bind_ok] + refine (WP.spec_ok _).2 ⟨Or.inl ⟨_, Or.inl hch, ⟨tag, _, htag, hpath'⟩, ?_, ?_, ?_, ?_, rfl, ?_⟩, ?_⟩ + · simp only; omega + · simp only; rw [h9]; omega + · simp only; intro _; omega + · simp only; intro h; exact absurd hch h + · intro va hv w hw + simp only [h9] at hv hw + have hk : walkIdx va sh.val 512 = idxA vaddr sh := by + rw [hv _ (by omega), idxA_walkIdxA] + refine K va (fun k hk' => hv k (by omega)) w (.down p sh.val 512 w ?_ (by omega) ?_ ?_) <;> rw [hk] + · exact ht3 + · exact Or.inl hch + · exact hw + · show lv1.val < lv.val + omega + · rw [if_neg (by simp [ht3])] + exact (WP.spec_ok _).2 hfin + · exact (WP.spec_ok _).2 hfin + · simp only [Prod.mk.injEq] at hx + obtain ⟨rfl, rfl, rfl⟩ := hx + have h511 : idxA vaddr vspace.TOP_LEVEL_SHIFT = 511#u64 := by + have : vspace.TOP_LEVEL_SHIFT = 39#u64 := by unfold vspace.TOP_LEVEL_SHIFT; rfl + rw [this]; exact hhi + dsimp only + unfold vspace.lookup_pt_slot_loop.body + rw [h511] + split + · rw [L.read_eq, bind_ok, is_table_eqA _ _ (by rw [e39]; omega), bind_ok, if_pos (by simp [hb])] + step as ⟨lv1, hlv1⟩ + have h9 : (core.num.U64.wrapping_sub vspace.TOP_LEVEL_SHIFT 9#u64).val = 30 := by + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits, vspace.TOP_LEVEL_SHIFT] + simp only [lift, bind_ok, table_of_eqA] + rw [entry_addr_eqA _ _ _ (by rw [h9]; omega)] + simp only [bind_ok] + have hl2 : lv1.val = 2 := by scalar_tac + rw [hd] + refine (WP.spec_ok _).2 ⟨Or.inl ⟨wa y 4096#u64, Or.inr ⟨y, hy, rfl⟩, hreach0, ?_, ?_, ?_, ?_, ?_, ?_⟩, ?_⟩ + · simp only; omega + · simp only; rw [h9, hl2] + · intro h; exact absurd h hnb + · intro _; simp only; omega + · simp only + · intro va hv w hw; simp only [h9] at hw; exact hw + · show lv1.val < (3#u64 : U64).val + rw [hl2]; decide + · rename_i hz + exact absurd hz (by scalar_tac) + · exact Or.inr rfl + refine WP.spec_bind loop ?_ + rintro ⟨sh, sl⟩ h + exact (WP.spec_ok _).2 h + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsWalkS2A.lean b/proofs/Fl4ProofsA64/P3/VsWalkS2A.lean new file mode 100644 index 000000000..c1d1d730f --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsWalkS2A.lean @@ -0,0 +1,234 @@ +/- +P3 (aarch64, A64-P3 Stage 5, line `vsinv`, G): **the walk bridge of `ept::lookup_slot`** (`lookup_walk_s2A`, the Stage-2 +twin of `lookup_walkA`): the returned slot is on `WalkSlotA` of every address that shares the walk's indices with the +looked-up one (shifts at or above the returned one), from the active Stage-2 root. The loop is +`vspace::lookup_pt_slot_loop` (`ept_lookup_loopE`); the root level has `topMask + 1` entries. No premise. New module. +-/ +import Fl4ProofsA64.P3.VsWalkSlotA +import Fl4ProofsA64.P3.ExtVsTopA +import Fl4ProofsA64.P3.VsUniqShrinkA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {Pp Tb : Set U64} {Lv : U64 → Nat} {X Y T2 : Set U64} {Sh2 : U64 → Nat} {σ : Fl4SpecA64.State Unit} + +/-- A valid table descriptor of a reachable Stage-2 table names a tracked table one level down. -/ +theorem s2_child_validA {mem : U64 → U64} (E : ExtVsRelA Pp Tb X Y T2 Sh2 mem σ) {t i : U64} + (hr : S2ReachA Pp X T2 Sh2 mem σ t) (ht : t ∈ T2) (h12 : 12 < Sh2 t) (hi : i.val < 512) + (h3 : (mem (peAF t i) &&& 3#u64) = 3#u64) : + dTabA (mem (peAF t i)) ∈ T2 ∧ Sh2 (dTabA (mem (peAF t i))) = Sh2 t - 9 := by + obtain ⟨pt, hk, -, hrel⟩ := E.s2pt t ht + have hd := (hrel hr i hi).1 + obtain ⟨hb0, hb1⟩ := (and3_bits_sh _).1 h3 + rcases hpte : Fl4SpecA64.ptApply pt i.bv with _ | ⟨a, sm, at', r⟩ | ppn + · rw [hpte] at hd + have h0 : dBitA (mem (peAF t i)) 0 = false := hd + rw [hb0] at h0; cases h0 + · rw [hpte] at hd + have := hd.2.1.1 hb1 + omega + · rw [hpte] at hd + exact hd.2.2.2.2.2 + +/-- A valid root entry of an active Stage-2 root names a tracked table one level down. -/ +theorem s2_root_childA {mem : U64 → U64} (E : ExtVsRelA Pp Tb X Y T2 Sh2 mem σ) {r i : U64} + (hr : r ∈ X) (ha : ActiveS2RootA Pp X σ r) (hi : i.val < Fl4SpecA64.s2Geom.topMask + 1) + (h3 : (mem (peAF r i) &&& 3#u64) = 3#u64) : + dTabA (mem (peAF r i)) ∈ T2 ∧ Sh2 (dTabA (mem (peAF r i))) = Fl4SpecA64.s2Geom.topShift - 9 := by + obtain ⟨es, hk, hrel⟩ := E.s2root r hr + have hi1k : i.val < 1024 := by have := s2Top1k; omega + have hd := (hrel ha i hi1k hi).1 + obtain ⟨hb0, hb1⟩ := (and3_bits_sh _).1 h3 + have htop : 12 < Fl4SpecA64.s2Geom.topShift := by rcases s2GeomNumE.1 with h | h <;> omega + rcases hpte : es ⟨i.val, hi1k⟩ with _ | ⟨a, sm, at', r'⟩ | ppn + · rw [hpte] at hd + have h0 : dBitA (mem (peAF r i)) 0 = false := hd + rw [hb0] at h0; cases h0 + · rw [hpte] at hd + have := hd.2.1.1 hb1 + omega + · rw [hpte] at hd + exact hd.2.2.2.2.2 + +/-- `s2StartE` with the root level's entry count. -/ +theorem s2StartE' {n : U64} (hnv : n.val = Fl4SpecA64.fl4A64Platform.s2IpaBits) : + ∃ g kk, ept.geom n = ok g ∧ kk ≤ 10 ∧ g.top_mask.val = 2 ^ kk - 1 ∧ g.top_shift.val < 64 ∧ + g.top_shift.val = Fl4SpecA64.s2Geom.topShift ∧ + (core.num.U64.wrapping_sub g.levels 1#u64).val = Fl4SpecA64.s2Geom.levels - 1 ∧ + Fl4SpecA64.s2Geom.topMask + 1 = 2 ^ kk := by + obtain ⟨g, kk, hg, hkk, hmk, h64, hts, hrem, -⟩ := s2StartE hnv + obtain ⟨g', hg', -, htm, -⟩ := ept_geomE n + rw [hg] at hg' + have hgg : g' = g := (ok_inj_ff hg').symm + subst hgg + have hg2 : Fl4SpecA64.s2GeomOf n.val = Fl4SpecA64.s2Geom := by rw [hnv]; rfl + rw [hg2] at htm + refine ⟨g', kk, hg, hkk, hmk, h64, hts, hrem, ?_⟩ + rw [← htm, hmk] + exact Nat.sub_add_cancel Nat.one_le_two_pow + +/-- Two addresses agree on the walk indices from shift `sh` up, for every entry count `2 ^ e` the walk can use +(the bits stay below bit 48: the Stage-2 IPA space). -/ +def AgreeWA (va' va : U64) (sh : Nat) : Prop := + ∀ k e : Nat, sh ≤ k → k + e ≤ 48 → walkIdx va' k (2 ^ e) = walkIdx va k (2 ^ e) + +theorem s2Geom_fit48 : ∃ e, Fl4SpecA64.s2Geom.topMask + 1 = 2 ^ e ∧ Fl4SpecA64.s2Geom.topShift + e ≤ 48 := by + rcases s2Geom_casesX with h | h | h <;> rw [h] <;> + first | exact ⟨10, by decide, by decide⟩ | exact ⟨5, by decide, by decide⟩ | exact ⟨9, by decide, by decide⟩ + +/-- The loop invariant below the root. -/ +def LkS2WA (Pp X T2 : Set U64) (Sh2 : U64 → Nat) (mem : U64 → U64) (σ : Fl4SpecA64.State Unit) (va p : U64) + (x : U64 × U64 × U64) : Prop := + ∃ t, t ∈ T2 ∧ S2ReachA Pp X T2 Sh2 mem σ t ∧ Sh2 t = x.1.val ∧ x.2.2.val ≤ 2 ∧ x.1.val = 12 + 9 * x.2.2.val ∧ + x.2.1 = peAF t (idxA va x.1) ∧ + ∀ va' : U64, AgreeWA va' va x.1.val → + ∀ w, WalkSlotA (· ∈ T2) mem va' t x.1.val 512 w → + WalkSlotA (· ∈ T2) mem va' p Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) w + +set_option maxHeartbeats 4000000 in +theorem lookup_walk_s2A {s : S} (E : ExtVsRelA Pp Tb X Y T2 Sh2 (L.mem s) σ) {p n : U64} (hp : p ∈ X) + (hact : ActiveS2RootA Pp X σ p) (hn : n.val = Fl4SpecA64.fl4A64Platform.s2IpaBits) (va : U64) : + ept.lookup_slot st s p va n ⦃ lu => ∀ va' : U64, AgreeWA va' va lu.shift.val → + WalkSlotA (· ∈ T2) (L.mem s) va' p Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) lu.slot ⦄ := by + obtain ⟨g, kk, hg, hkk, hmk, h64, hts, hrem, hmk1⟩ := s2StartE' hn + obtain ⟨-, -, -, -, htop⟩ := s2StartE hn + have hxal : 8192 ∣ p.val := E.xal p hp + unfold ept.lookup_slot + rw [hg, bind_ok, ept_entry_addrE _ _ _ _ h64 hmk, bind_ok] + simp only [lift, bind_ok] + rw [ept_lookup_loopE] + have hidx0 : (idxME va g.top_shift kk).val = va.val / 2 ^ Fl4SpecA64.s2Geom.topShift % (Fl4SpecA64.s2Geom.topMask + 1) := by + rw [idxME_val va _ hkk, hts, hmk1] + have hwi : walkIdx va Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) = idxME va g.top_shift kk := by + apply UScalar.eq_of_val_eq + rw [walkIdx_val _ _ _ (by omega) (by have := s2GeomNumE.2.2.1; omega), hidx0] + have hlvl := s2GeomNumE + have loop : vspace.lookup_pt_slot_loop st s va g.top_shift (peAF p (idxME va g.top_shift kk)) + (core.num.U64.wrapping_sub g.levels 1#u64) ⦃ r => ∀ va' : U64, + AgreeWA va' va r.1.val → + WalkSlotA (· ∈ T2) (L.mem s) va' p Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) r.2 ⦄ := by + unfold vspace.lookup_pt_slot_loop + apply loop.spec_decr_nat (measure := fun x => x.2.2.val) + (inv := fun x => LkS2WA Pp X T2 Sh2 (L.mem s) σ va p x ∨ + x = (g.top_shift, peAF p (idxME va g.top_shift kk), core.num.U64.wrapping_sub g.levels 1#u64)) + · rintro ⟨sh, sl, lv⟩ hx + rcases hx with ⟨t, ht, hre, hS, hl3, hsh, e, K⟩ | hx + · simp only at hS hl3 hsh e K + subst e + have hfin : ∀ va' : U64, AgreeWA va' va sh.val → + WalkSlotA (· ∈ T2) (L.mem s) va' p Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) + (peAF t (idxA va sh)) := by + intro va' hv + refine K va' hv _ ?_ + have := WalkSlotA.here (P := (· ∈ T2)) (mem := L.mem s) (va := va') t sh.val 512 + have e : walkIdx va' sh.val 512 = walkIdx va sh.val 512 := by + simpa using hv sh.val 9 le_rfl (by omega) + rwa [e, ← idxA_walkIdxA] at this + dsimp only + unfold vspace.lookup_pt_slot_loop.body + split + · rename_i hpos + have hpos' : 0 < lv.val := by simpa using hpos + rw [L.read_eq, bind_ok, is_table_eqA _ _ (by omega), bind_ok] + have hidx := idxA_lt va sh + by_cases ht3 : (L.mem s (peAF t (idxA va sh)) &&& 3#u64) = 3#u64 + · rw [if_pos (by simp [ht3])] + have h12 : 12 < Sh2 t := by omega + obtain ⟨hch, hchS⟩ := s2_child_validA E hre ht h12 hidx ht3 + step as ⟨lv1, hlv1⟩ + have h9 : (core.num.U64.wrapping_sub sh 9#u64).val = sh.val - 9 := by + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits]; omega + simp only [lift, bind_ok, table_of_eqA] + rw [entry_addr_eqA _ _ _ (by rw [h9]; omega)] + simp only [bind_ok] + refine (WP.spec_ok _).2 ⟨Or.inl ⟨_, hch, S2ReachA.stepPt hre ht h12 hidx ht3 hch, ?_, ?_, ?_, rfl, ?_⟩, ?_⟩ + · simp only; rw [h9]; omega + · simp only; omega + · simp only; rw [h9]; omega + · intro va' hv w hw + rw [h9] at hv + simp only [h9] at hw + have hk : walkIdx va' sh.val 512 = idxA va sh := by + have e : walkIdx va' sh.val 512 = walkIdx va sh.val 512 := by + simpa using hv sh.val 9 (by omega) (by omega) + rw [e, idxA_walkIdxA] + refine K va' (fun k e hk' he => hv k e (by omega) he) w (.down t sh.val 512 w ?_ (by omega) ?_ ?_) <;> rw [hk] + · exact ht3 + · exact hch + · exact hw + · show lv1.val < lv.val + omega + · rw [if_neg (by simp [ht3])] + exact (WP.spec_ok _).2 hfin + · exact (WP.spec_ok _).2 hfin + · simp only [Prod.mk.injEq] at hx + obtain ⟨rfl, rfl, rfl⟩ := hx + have hlv0 : (core.num.U64.wrapping_sub g.levels 1#u64).val = Fl4SpecA64.s2Geom.levels - 1 := hrem + have hi0 : (idxME va g.top_shift kk).val < Fl4SpecA64.s2Geom.topMask + 1 := by + rw [hidx0]; exact Nat.mod_lt _ (by omega) + have hfin0 : ∀ va' : U64, AgreeWA va' va g.top_shift.val → + WalkSlotA (· ∈ T2) (L.mem s) va' p Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) + (peAF p (idxME va g.top_shift kk)) := by + intro va' hv + have := WalkSlotA.here (P := (· ∈ T2)) (mem := L.mem s) (va := va') p + Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) + obtain ⟨e0, he0, hfit⟩ := s2Geom_fit48 + have e1 : walkIdx va' Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) = + walkIdx va Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) := by + rw [he0]; exact hv Fl4SpecA64.s2Geom.topShift e0 (by omega) (by omega) + rw [e1, hwi] at this + exact this + dsimp only + unfold vspace.lookup_pt_slot_loop.body + split + · rename_i hpos + have hpos' : 0 < (core.num.U64.wrapping_sub g.levels 1#u64).val := by simpa using hpos + rw [L.read_eq, bind_ok, is_table_eqA _ _ (by omega), bind_ok] + by_cases ht3 : (L.mem s (peAF p (idxME va g.top_shift kk)) &&& 3#u64) = 3#u64 + · rw [if_pos (by simp [ht3])] + obtain ⟨hch, hchS⟩ := s2_root_childA E hp hact hi0 ht3 + step as ⟨lv1, hlv1⟩ + have h9 : (core.num.U64.wrapping_sub g.top_shift 9#u64).val = g.top_shift.val - 9 := by + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits]; omega + simp only [lift, bind_ok, table_of_eqA] + rw [entry_addr_eqA _ _ _ (by rw [h9]; omega)] + simp only [bind_ok] + refine (WP.spec_ok _).2 ⟨Or.inl ⟨_, hch, S2ReachA.stepRoot hact hi0 ht3 hch, ?_, ?_, ?_, rfl, ?_⟩, ?_⟩ + · simp only; rw [h9]; omega + · simp only; rcases hlvl.1 with h | h <;> rcases hlvl.2.2.2.1 with h' | h' <;> omega + · simp only; rw [h9]; rcases hlvl.1 with h | h <;> rcases hlvl.2.2.2.1 with h' | h' <;> omega + · intro va' hv w hw + rw [h9] at hv + simp only [h9] at hw + have hk : walkIdx va' g.top_shift.val (Fl4SpecA64.s2Geom.topMask + 1) = idxME va g.top_shift kk := by + obtain ⟨e0, he0, hfit⟩ := s2Geom_fit48 + have e1 : walkIdx va' Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) = + walkIdx va Fl4SpecA64.s2Geom.topShift (Fl4SpecA64.s2Geom.topMask + 1) := by + rw [he0]; exact hv Fl4SpecA64.s2Geom.topShift e0 (by omega) (by omega) + rw [hts, e1]; exact hwi + rw [← hts] + refine .down p g.top_shift.val (Fl4SpecA64.s2Geom.topMask + 1) w ?_ (by omega) ?_ ?_ <;> rw [hk] + · exact ht3 + · exact hch + · exact hw + · show lv1.val < _ + omega + · rw [if_neg (by simp [ht3])] + exact (WP.spec_ok _).2 hfin0 + · rename_i hz + have hlv2 : 2 ≤ (core.num.U64.wrapping_sub g.levels 1#u64).val := by + rw [hlv0]; rcases hlvl.2.2.2.1 with h | h <;> omega + exact absurd hz (by scalar_tac) + · exact Or.inr rfl + refine WP.spec_bind loop ?_ + rintro ⟨sh, sl⟩ h + exact (WP.spec_ok _).2 h + +end + +end Fl4ProofsA64.P3 diff --git a/proofs/Fl4ProofsA64/P3/VsWalkSlotA.lean b/proofs/Fl4ProofsA64/P3/VsWalkSlotA.lean new file mode 100644 index 000000000..dc5b1f408 --- /dev/null +++ b/proofs/Fl4ProofsA64/P3/VsWalkSlotA.lean @@ -0,0 +1,109 @@ +/- +P3 (aarch64, Stage 5 vsinv): **the walk bridge of `lookup_pt_slot`** (`lookup_walkA`): the returned slot is on +`WalkSlotA` of every address that shares the walk's indices with the looked-up one (shifts at or above the returned +one), from the root table. No premise. New module. +-/ +import Fl4ProofsA64.P3.VsWalkA +import Fl4ProofsA64.P3.VsUniqShrinkA +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P3 +open fl4_core_a64 Fl4ProofsA64.P1 + +noncomputable section + +variable {S : Type} {st : machine.Store S} [L : LawfulStore st] +variable {Pp Tb : Set U64} {Lv : U64 → Nat} {X Y : Set U64} {σ : Fl4SpecA64.State Unit} + +theorem idxA_walkIdxA (v sh : U64) : idxA v sh = walkIdx v sh.val 512 := by + apply UScalar.eq_of_val_eq + rw [idxA_val, walkIdx_val _ _ _ (by norm_num) (by norm_num)] + +/-- The loop invariant: a table `p` of the walk with the continuation from the root. -/ +def LkSlotWA (Pp Tb Y : Set U64) (Lv : U64 → Nat) (mem : U64 → U64) (ksb vaddr root : U64) (x : U64 × U64 × U64) : Prop := + ∃ p ∈ Tb, VsReachA Pp Tb Y mem ksb p ∧ x.2.2.val ≤ 3 ∧ x.1.val = 12 + 9 * x.2.2.val ∧ Lv p + x.2.2.val = 3 ∧ + x.2.1 = peAF p (idxA vaddr x.1) ∧ + ∀ va : U64, (∀ k, x.1.val ≤ k → walkIdx va k 512 = walkIdx vaddr k 512) → + ∀ w, WalkSlotA (S1TabA Tb Y) mem va p x.1.val 512 w → WalkSlotA (S1TabA Tb Y) mem va root 39 512 w + +set_option maxHeartbeats 4000000 in +theorem lookup_walkA {s : S} (hR : VsRelA Pp Tb Lv X Y (L.mem s) (L.ksb s) σ) + {root : U64} (hr : root ∈ Tb) (h0 : Lv root = 0) + (hreach : VsReachA Pp Tb Y (L.mem s) (L.ksb s) root) (vaddr : U64) : + vspace.lookup_pt_slot st s root vaddr ⦃ lu => ∀ va : U64, + (∀ k, lu.shift.val ≤ k → walkIdx va k 512 = walkIdx vaddr k 512) → + WalkSlotA (S1TabA Tb Y) (L.mem s) va root 39 512 lu.slot ⦄ := by + unfold vspace.lookup_pt_slot + rw [entry_addr_eqA _ _ _ (by simp)] + simp only [bind_ok] + have e39 : vspace.TOP_LEVEL_SHIFT.val = 39 := by simp + have loop : vspace.lookup_pt_slot_loop st s vaddr vspace.TOP_LEVEL_SHIFT + (peAF root (idxA vaddr vspace.TOP_LEVEL_SHIFT)) 3#u64 ⦃ r => ∀ va : U64, + (∀ k, r.1.val ≤ k → walkIdx va k 512 = walkIdx vaddr k 512) → + WalkSlotA (S1TabA Tb Y) (L.mem s) va root 39 512 r.2 ⦄ := by + unfold vspace.lookup_pt_slot_loop + apply loop.spec_decr_nat (measure := fun x => x.2.2.val) + (inv := LkSlotWA Pp Tb Y Lv (L.mem s) (L.ksb s) vaddr root) + · rintro ⟨sh, sl, lv⟩ ⟨p, hp, hre, hl3, hsh, hlv, e, K⟩ + simp only at hl3 hsh hlv e K + subst e + have hfin : ∀ va : U64, (∀ k, sh.val ≤ k → walkIdx va k 512 = walkIdx vaddr k 512) → + WalkSlotA (S1TabA Tb Y) (L.mem s) va root 39 512 (peAF p (idxA vaddr sh)) := by + intro va hv + refine K va hv _ ?_ + have := WalkSlotA.here (P := S1TabA Tb Y) (mem := L.mem s) (va := va) p sh.val 512 + rwa [hv _ le_rfl, ← idxA_walkIdxA] at this + dsimp only + unfold vspace.lookup_pt_slot_loop.body + split + · rename_i hpos + have hpos' : 0 < lv.val := by simpa using hpos + rw [L.read_eq, bind_ok, is_table_eqA _ _ (by omega), bind_ok] + have hidx := idxA_lt vaddr sh + by_cases ht3 : (L.mem s (peAF p (idxA vaddr sh)) &&& 3#u64) = 3#u64 + · rw [if_pos (by simp [ht3])] + obtain ⟨tag, sh0, htag, hpath⟩ := hre + have hsh0 : sh0 = sh.val := by + rcases (hR.path_props hpath).2 with ⟨-, -, e⟩ | ⟨-, -, y, hy, -, hq⟩ + · omega + · exact absurd (hq ▸ hp) (hR.ytb y hy) + subst hsh0 + have hch := hR.child_tb hpath (Or.inl hp) (by omega) hidx ht3 + have hpath' : VsPathA Pp Tb Y (L.mem s) (L.ksb s) tag (sh.val - 9) + (dTabA (L.mem s (peAF p (idxA vaddr sh)))) := .child hpath (Or.inl hp) (by omega) hidx ht3 + have hlv' : Lv (dTabA (L.mem s (peAF p (idxA vaddr sh)))) = Lv p + 1 := by + rcases (hR.path_props hpath').2 with ⟨-, h3', e⟩ | ⟨-, -, y, hy, -, hq⟩ + · omega + · exact absurd (hq ▸ hch) (hR.ytb y hy) + step as ⟨lv1, hlv1⟩ + have h9 : (core.num.U64.wrapping_sub sh 9#u64).val = sh.val - 9 := by + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits]; omega + simp only [lift, bind_ok, table_of_eqA] + rw [entry_addr_eqA _ _ _ (by rw [h9]; omega)] + simp only [bind_ok] + refine (WP.spec_ok _).2 ⟨⟨_, hch, ⟨tag, _, htag, hpath'⟩, ?_, ?_, ?_, rfl, ?_⟩, ?_⟩ + · simp only; omega + · simp only; rw [h9]; omega + · simp only; rw [hlv']; omega + · intro va hv w hw + simp only [h9] at hv hw + have hk : walkIdx va sh.val 512 = idxA vaddr sh := by + rw [hv _ (by omega), idxA_walkIdxA] + refine K va (fun k hk' => hv k (by omega)) w (.down p sh.val 512 w ?_ (by omega) ?_ ?_) <;> rw [hk] + · exact ht3 + · exact Or.inl hch + · exact hw + · show lv1.val < lv.val + omega + · rw [if_neg (by simp [ht3])] + exact (WP.spec_ok _).2 hfin + · exact (WP.spec_ok _).2 hfin + · refine ⟨root, hr, hreach, by simp, by simp [e39], by simp [h0], rfl, fun va _ w hw => ?_⟩ + simpa [e39] using hw + refine WP.spec_bind loop ?_ + rintro ⟨sh, sl⟩ h + exact (WP.spec_ok _).2 h + +end + +end Fl4ProofsA64.P3