From 967b763bf013a46f4fabf9c1c7bcfe2ce341fc90 Mon Sep 17 00:00:00 2001 From: CommaBot Date: Thu, 3 Dec 2026 11:15:34 +0900 Subject: [PATCH] P1 (aarch64): close the S1A invariant (R2/R3/B2): the decode step chains from boot with the kernel-table column The AArch64 P1 S1A line: the R2 reachable-VSpace invariant, the R3 ASID/pool columns and the B2 decode step, completed after the #146 snapshot. - syscall.decode_invocation.s1aStepR2K: one decode_invocation step on every DecArmS1aH arm re-establishes S1aR2, S1aKtUt and the kernel-table level column S1aHiK. No per-step typing input remains: the former HiDelTy witness (full typing of every HighVSpace root) is false on reachable states after delete_asid_pool / unmap / retype, and is replaced by the reachability- guarded HiDelTyR, a projection of R2. - BootWit.w0_s1aStepEntryK / w1K_s1aStepEntryK: the step's entry facts at boot. - README and DESIGN section 9 list the covered and uncovered AArch64 arms and the step's outer entry inputs. Statements merged in #146 changed with the line's later generations (FinKZ widened over Pt, decode-state parameter sd / FrCw write sets, FE over any device bit, PoolPost/AsgPost fields); cdt.delete.armQIAt moved to MdbDelVsZ with the FrC / ArmVsZ premises, DecArmKK3 moved unchanged to S1aHiK. Co-Authored-By: Claude Opus 5.5 --- DESIGN.md | 4 +- README.md | 28 +- proofs/Fl4ProofsA64.lean | 124 ++ proofs/Fl4ProofsA64/P1/MdbAllArmQ.lean | 6 +- proofs/Fl4ProofsA64/P1/MdbArmDf.lean | 55 +- proofs/Fl4ProofsA64/P1/MdbArmDfB.lean | 36 +- proofs/Fl4ProofsA64/P1/MdbArmDm.lean | 41 +- proofs/Fl4ProofsA64/P1/MdbArmQH.lean | 13 +- proofs/Fl4ProofsA64/P1/MdbArmQHD.lean | 49 +- proofs/Fl4ProofsA64/P1/MdbArmQR.lean | 2 +- proofs/Fl4ProofsA64/P1/MdbArmQZ2.lean | 4 +- proofs/Fl4ProofsA64/P1/MdbArmTab.lean | 18 +- proofs/Fl4ProofsA64/P1/MdbArmVs.lean | 187 +++ proofs/Fl4ProofsA64/P1/MdbArmVsF.lean | 123 ++ proofs/Fl4ProofsA64/P1/MdbArmVsG.lean | 190 +++ proofs/Fl4ProofsA64/P1/MdbArmVsV.lean | 258 ++++ proofs/Fl4ProofsA64/P1/MdbAsidA.lean | 17 +- proofs/Fl4ProofsA64/P1/MdbCapI.lean | 2 +- proofs/Fl4ProofsA64/P1/MdbCnArmQ.lean | 32 +- proofs/Fl4ProofsA64/P1/MdbCnDelArm.lean | 44 +- proofs/Fl4ProofsA64/P1/MdbDelArmQ.lean | 4 +- proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean | 405 ++++++ proofs/Fl4ProofsA64/P1/MdbEptMapQ.lean | 86 +- proofs/Fl4ProofsA64/P1/MdbEptQ.lean | 11 +- proofs/Fl4ProofsA64/P1/MdbEptUnmQ.lean | 4 +- proofs/Fl4ProofsA64/P1/MdbFpuL.lean | 71 +- proofs/Fl4ProofsA64/P1/MdbFrE.lean | 26 +- proofs/Fl4ProofsA64/P1/MdbFrOff.lean | 2 +- proofs/Fl4ProofsA64/P1/MdbFrUb.lean | 2 +- proofs/Fl4ProofsA64/P1/MdbGrowN.lean | 29 +- proofs/Fl4ProofsA64/P1/MdbHiVsArm.lean | 157 +- proofs/Fl4ProofsA64/P1/MdbInsL.lean | 4 +- proofs/Fl4ProofsA64/P1/MdbIrqCQ.lean | 186 ++- proofs/Fl4ProofsA64/P1/MdbLiveU.lean | 145 +- proofs/Fl4ProofsA64/P1/MdbLiveY.lean | 85 +- proofs/Fl4ProofsA64/P1/MdbMcpArm.lean | 11 +- proofs/Fl4ProofsA64/P1/MdbPoolA.lean | 304 +++- proofs/Fl4ProofsA64/P1/MdbPoolDelR.lean | 82 +- proofs/Fl4ProofsA64/P1/MdbPoolN.lean | 8 + proofs/Fl4ProofsA64/P1/MdbPrioArm.lean | 11 +- proofs/Fl4ProofsA64/P1/MdbPtCapA.lean | 94 ++ proofs/Fl4ProofsA64/P1/MdbRegRQ.lean | 177 ++- proofs/Fl4ProofsA64/P1/MdbRtBlk.lean | 31 +- proofs/Fl4ProofsA64/P1/MdbRunF.lean | 114 +- proofs/Fl4ProofsA64/P1/MdbRunQ.lean | 118 +- proofs/Fl4ProofsA64/P1/MdbRvPool.lean | 4 +- proofs/Fl4ProofsA64/P1/MdbSendQ.lean | 197 ++- proofs/Fl4ProofsA64/P1/MdbSetTcbQ.lean | 82 +- proofs/Fl4ProofsA64/P1/MdbSigQ.lean | 36 +- proofs/Fl4ProofsA64/P1/MdbSspArm.lean | 133 +- proofs/Fl4ProofsA64/P1/MdbSspIns.lean | 37 +- proofs/Fl4ProofsA64/P1/MdbSspTail.lean | 87 +- proofs/Fl4ProofsA64/P1/MdbSusQ.lean | 56 +- proofs/Fl4ProofsA64/P1/MdbTcbArmQ.lean | 307 ++-- proofs/Fl4ProofsA64/P1/MdbTmoArmQ.lean | 31 +- proofs/Fl4ProofsA64/P1/MdbVcArmQ.lean | 59 +- proofs/Fl4ProofsA64/P1/MdbVcStQ.lean | 105 +- proofs/Fl4ProofsA64/P1/MdbVsFlQ.lean | 31 +- proofs/Fl4ProofsA64/P1/MdbVsGaQ.lean | 50 +- proofs/Fl4ProofsA64/P1/MdbVsMapA.lean | 87 +- proofs/Fl4ProofsA64/P1/MdbVsMapB.lean | 189 ++- proofs/Fl4ProofsA64/P1/MdbVsMapC.lean | 2 +- proofs/Fl4ProofsA64/P1/MdbVsUnmQ.lean | 56 +- proofs/Fl4ProofsA64/P1/MdbXferQ.lean | 465 ++++-- proofs/Fl4ProofsA64/P1/QueueUnmD.lean | 32 +- proofs/Fl4ProofsA64/P1/QueueZombieQ.lean | 253 +++- proofs/Fl4ProofsA64/P1/S1aArmCol.lean | 2 +- proofs/Fl4ProofsA64/P1/S1aArmDel.lean | 4 +- proofs/Fl4ProofsA64/P1/S1aArmDelU.lean | 22 +- proofs/Fl4ProofsA64/P1/S1aArmZ2.lean | 12 +- proofs/Fl4ProofsA64/P1/S1aBootK.lean | 246 ++++ proofs/Fl4ProofsA64/P1/S1aBootW1.lean | 29 +- proofs/Fl4ProofsA64/P1/S1aDevFr.lean | 220 +++ proofs/Fl4ProofsA64/P1/S1aHiAsg.lean | 186 +++ proofs/Fl4ProofsA64/P1/S1aHiCap.lean | 138 ++ proofs/Fl4ProofsA64/P1/S1aHiDel.lean | 151 ++ proofs/Fl4ProofsA64/P1/S1aHiDelDec.lean | 185 +++ proofs/Fl4ProofsA64/P1/S1aHiDelIrq.lean | 127 ++ proofs/Fl4ProofsA64/P1/S1aHiDelR.lean | 213 +++ proofs/Fl4ProofsA64/P1/S1aHiDelTcb.lean | 619 ++++++++ proofs/Fl4ProofsA64/P1/S1aHiDispatch.lean | 120 ++ proofs/Fl4ProofsA64/P1/S1aHiInit.lean | 95 ++ proofs/Fl4ProofsA64/P1/S1aHiK.lean | 153 ++ proofs/Fl4ProofsA64/P1/S1aHiMap.lean | 314 ++++ proofs/Fl4ProofsA64/P1/S1aHiRetype.lean | 251 ++++ proofs/Fl4ProofsA64/P1/S1aHiTca.lean | 109 ++ proofs/Fl4ProofsA64/P1/S1aHiUnm.lean | 125 ++ proofs/Fl4ProofsA64/P1/S1aHiVs.lean | 91 ++ proofs/Fl4ProofsA64/P1/S1aHiVsW.lean | 72 + proofs/Fl4ProofsA64/P1/S1aHvPt.lean | 192 +++ proofs/Fl4ProofsA64/P1/S1aKTab.lean | 451 ++++++ proofs/Fl4ProofsA64/P1/S1aKtArms.lean | 150 ++ proofs/Fl4ProofsA64/P1/S1aKtDelArms.lean | 237 +++ proofs/Fl4ProofsA64/P1/S1aKtLvCol.lean | 110 ++ proofs/Fl4ProofsA64/P1/S1aKtPoolArms.lean | 80 + proofs/Fl4ProofsA64/P1/S1aKtRetype.lean | 164 +++ proofs/Fl4ProofsA64/P1/S1aKtUt.lean | 164 +++ proofs/Fl4ProofsA64/P1/S1aKtUtArms.lean | 284 ++++ proofs/Fl4ProofsA64/P1/S1aKtUtDel.lean | 116 ++ proofs/Fl4ProofsA64/P1/S1aKtVsArms.lean | 261 ++++ proofs/Fl4ProofsA64/P1/S1aPtCap.lean | 40 +- proofs/Fl4ProofsA64/P1/S1aPtCol.lean | 51 +- proofs/Fl4ProofsA64/P1/S1aPtStep.lean | 210 ++- proofs/Fl4ProofsA64/P1/S1aR2AccessBits.lean | 107 ++ proofs/Fl4ProofsA64/P1/S1aR2AccessPaths.lean | 145 ++ proofs/Fl4ProofsA64/P1/S1aR2AccessPost.lean | 166 +++ proofs/Fl4ProofsA64/P1/S1aR2AccessWrite.lean | 128 ++ proofs/Fl4ProofsA64/P1/S1aR2AddPool.lean | 577 ++++++++ proofs/Fl4ProofsA64/P1/S1aR2Assign.lean | 237 +++ proofs/Fl4ProofsA64/P1/S1aR2AssignCaps.lean | 156 ++ proofs/Fl4ProofsA64/P1/S1aR2AssignD.lean | 255 ++++ proofs/Fl4ProofsA64/P1/S1aR2AssignLive.lean | 181 +++ proofs/Fl4ProofsA64/P1/S1aR2AssignLookup.lean | 173 +++ proofs/Fl4ProofsA64/P1/S1aR2AssignPaths.lean | 181 +++ proofs/Fl4ProofsA64/P1/S1aR2AssignPlace.lean | 162 +++ proofs/Fl4ProofsA64/P1/S1aR2AssignPost.lean | 135 ++ proofs/Fl4ProofsA64/P1/S1aR2AssignRoot.lean | 133 ++ proofs/Fl4ProofsA64/P1/S1aR2AssignStage1.lean | 259 ++++ proofs/Fl4ProofsA64/P1/S1aR2AssignStage2.lean | 166 +++ proofs/Fl4ProofsA64/P1/S1aR2AssignWrite.lean | 192 +++ proofs/Fl4ProofsA64/P1/S1aR2Caps.lean | 93 ++ proofs/Fl4ProofsA64/P1/S1aR2CnodeImage.lean | 364 +++++ proofs/Fl4ProofsA64/P1/S1aR2Contract.lean | 172 +++ proofs/Fl4ProofsA64/P1/S1aR2Del.lean | 139 ++ proofs/Fl4ProofsA64/P1/S1aR2DelArm.lean | 500 +++++++ proofs/Fl4ProofsA64/P1/S1aR2Delete.lean | 116 ++ proofs/Fl4ProofsA64/P1/S1aR2Domains.lean | 497 +++++++ proofs/Fl4ProofsA64/P1/S1aR2Ept.lean | 546 +++++++ proofs/Fl4ProofsA64/P1/S1aR2Field.lean | 170 +++ proofs/Fl4ProofsA64/P1/S1aR2FinAlias.lean | 149 ++ proofs/Fl4ProofsA64/P1/S1aR2FinFrame.lean | 74 + proofs/Fl4ProofsA64/P1/S1aR2FinPool.lean | 235 +++ proofs/Fl4ProofsA64/P1/S1aR2FinPt.lean | 266 ++++ proofs/Fl4ProofsA64/P1/S1aR2FinRoot.lean | 652 +++++++++ proofs/Fl4ProofsA64/P1/S1aR2Frame.lean | 264 ++++ proofs/Fl4ProofsA64/P1/S1aR2FrameBacking.lean | 112 ++ proofs/Fl4ProofsA64/P1/S1aR2FrameClear.lean | 146 ++ .../Fl4ProofsA64/P1/S1aR2FrameMapDecode.lean | 193 +++ proofs/Fl4ProofsA64/P1/S1aR2FrameMapPost.lean | 167 +++ .../Fl4ProofsA64/P1/S1aR2FrameMapStage1.lean | 164 +++ .../Fl4ProofsA64/P1/S1aR2FrameMapStage2.lean | 134 ++ .../Fl4ProofsA64/P1/S1aR2FrameMapWrite.lean | 149 ++ proofs/Fl4ProofsA64/P1/S1aR2FramePaths.lean | 86 ++ proofs/Fl4ProofsA64/P1/S1aR2FrameRaw.lean | 119 ++ proofs/Fl4ProofsA64/P1/S1aR2FrameRemove.lean | 228 +++ .../Fl4ProofsA64/P1/S1aR2FrameUnmapPost.lean | 238 +++ .../Fl4ProofsA64/P1/S1aR2FrameUnmapWalk.lean | 93 ++ .../Fl4ProofsA64/P1/S1aR2FrameUnmapWord.lean | 92 ++ proofs/Fl4ProofsA64/P1/S1aR2FrameWord.lean | 133 ++ proofs/Fl4ProofsA64/P1/S1aR2Image.lean | 388 +++++ proofs/Fl4ProofsA64/P1/S1aR2Install.lean | 386 +++++ proofs/Fl4ProofsA64/P1/S1aR2Keep.lean | 86 ++ proofs/Fl4ProofsA64/P1/S1aR2KeepArms.lean | 116 ++ proofs/Fl4ProofsA64/P1/S1aR2KtDel.lean | 271 ++++ proofs/Fl4ProofsA64/P1/S1aR2KtLevel.lean | 197 +++ proofs/Fl4ProofsA64/P1/S1aR2Loop.lean | 99 ++ proofs/Fl4ProofsA64/P1/S1aR2MakePool.lean | 187 +++ proofs/Fl4ProofsA64/P1/S1aR2MapBacking.lean | 118 ++ proofs/Fl4ProofsA64/P1/S1aR2MapCaps.lean | 100 ++ proofs/Fl4ProofsA64/P1/S1aR2MapDispatch.lean | 76 + proofs/Fl4ProofsA64/P1/S1aR2MapGrow.lean | 122 ++ proofs/Fl4ProofsA64/P1/S1aR2MapHigh.lean | 87 ++ proofs/Fl4ProofsA64/P1/S1aR2MapHighEntry.lean | 60 + proofs/Fl4ProofsA64/P1/S1aR2MapNative.lean | 83 ++ proofs/Fl4ProofsA64/P1/S1aR2MapPaths.lean | 143 ++ proofs/Fl4ProofsA64/P1/S1aR2MapPlacement.lean | 218 +++ proofs/Fl4ProofsA64/P1/S1aR2MapPost.lean | 200 +++ proofs/Fl4ProofsA64/P1/S1aR2MapReach.lean | 151 ++ proofs/Fl4ProofsA64/P1/S1aR2MapReference.lean | 127 ++ proofs/Fl4ProofsA64/P1/S1aR2MapRootSlots.lean | 236 +++ proofs/Fl4ProofsA64/P1/S1aR2MapRoots.lean | 156 ++ .../Fl4ProofsA64/P1/S1aR2MapStage1Post.lean | 227 +++ proofs/Fl4ProofsA64/P1/S1aR2MapStage2.lean | 120 ++ .../Fl4ProofsA64/P1/S1aR2MapStage2Post.lean | 79 + proofs/Fl4ProofsA64/P1/S1aR2MapTypes.lean | 154 ++ proofs/Fl4ProofsA64/P1/S1aR2MapWalk.lean | 368 +++++ proofs/Fl4ProofsA64/P1/S1aR2MapWrite.lean | 124 ++ proofs/Fl4ProofsA64/P1/S1aR2OfImage.lean | 107 ++ .../Fl4ProofsA64/P1/S1aR2PathReference.lean | 70 + proofs/Fl4ProofsA64/P1/S1aR2PtUnmap.lean | 424 ++++++ proofs/Fl4ProofsA64/P1/S1aR2Relabel.lean | 218 +++ proofs/Fl4ProofsA64/P1/S1aR2Restrict.lean | 319 ++++ proofs/Fl4ProofsA64/P1/S1aR2RetypeEnd.lean | 221 +++ proofs/Fl4ProofsA64/P1/S1aR2RetypeFrame.lean | 346 +++++ proofs/Fl4ProofsA64/P1/S1aR2RetypeHigh.lean | 131 ++ proofs/Fl4ProofsA64/P1/S1aR2RetypeNew.lean | 152 ++ proofs/Fl4ProofsA64/P1/S1aR2RetypePost.lean | 899 ++++++++++++ proofs/Fl4ProofsA64/P1/S1aR2RetypeTop.lean | 87 ++ proofs/Fl4ProofsA64/P1/S1aR2RootInit.lean | 381 +++++ proofs/Fl4ProofsA64/P1/S1aR2Shrink.lean | 421 ++++++ proofs/Fl4ProofsA64/P1/S1aR2SlotUnique.lean | 120 ++ proofs/Fl4ProofsA64/P1/S1aR2Slots.lean | 32 + proofs/Fl4ProofsA64/P1/S1aR2TcbArm.lean | 281 ++++ proofs/Fl4ProofsA64/P1/S1aR2Transfer.lean | 165 +++ proofs/Fl4ProofsA64/P1/S1aR2Transport.lean | 309 ++++ proofs/Fl4ProofsA64/P1/S1aR2UnmapAddress.lean | 96 ++ proofs/Fl4ProofsA64/P1/S1aR2UnmapPost.lean | 311 ++++ proofs/Fl4ProofsA64/P1/S1aR2UnmapRoute.lean | 80 + proofs/Fl4ProofsA64/P1/S1aR2UnmapS1.lean | 163 +++ proofs/Fl4ProofsA64/P1/S1aR2UnmapS2.lean | 227 +++ proofs/Fl4ProofsA64/P1/S1aR2UnmapWalk.lean | 85 ++ proofs/Fl4ProofsA64/P1/S1aR2Zeroed.lean | 110 ++ proofs/Fl4ProofsA64/P1/S1aRtV.lean | 33 +- proofs/Fl4ProofsA64/P1/S1aStep.lean | 65 +- proofs/Fl4ProofsA64/P1/S1aStepH.lean | 42 +- proofs/Fl4ProofsA64/P1/S1aStepR2.lean | 285 ++++ proofs/Fl4ProofsA64/P1/S1aStepR2A.lean | 358 +++++ proofs/Fl4ProofsA64/P1/S1aStepR2Boot.lean | 121 ++ proofs/Fl4ProofsA64/P1/S1aStepR2K.lean | 263 ++++ proofs/Fl4ProofsA64/P1/S1aStepR2KBoot.lean | 62 + proofs/Fl4ProofsA64/P1/S1aVsUnm.lean | 533 +++++++ proofs/Fl4ProofsA64/P1/S1aVsUnmB.lean | 962 ++++++++++++ proofs/scratch/a64/a64_ax2.lean | 1287 +++++++++++++++++ 213 files changed, 34435 insertions(+), 1347 deletions(-) create mode 100644 proofs/Fl4ProofsA64/P1/MdbArmVs.lean create mode 100644 proofs/Fl4ProofsA64/P1/MdbArmVsF.lean create mode 100644 proofs/Fl4ProofsA64/P1/MdbArmVsG.lean create mode 100644 proofs/Fl4ProofsA64/P1/MdbArmVsV.lean create mode 100644 proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aBootK.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aDevFr.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiAsg.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiCap.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiDel.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiDelDec.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiDelIrq.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiDelR.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiDelTcb.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiDispatch.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiInit.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiK.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiMap.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiRetype.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiTca.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiUnm.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiVs.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHiVsW.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aHvPt.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKTab.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKtArms.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKtDelArms.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKtLvCol.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKtPoolArms.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKtRetype.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKtUt.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKtUtArms.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKtUtDel.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aKtVsArms.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AccessBits.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AccessPaths.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AccessPost.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AccessWrite.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AddPool.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Assign.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignCaps.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignD.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignLive.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignLookup.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignPaths.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignPlace.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignPost.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignRoot.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignStage1.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignStage2.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2AssignWrite.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Caps.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2CnodeImage.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Contract.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Del.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2DelArm.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Delete.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Domains.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Ept.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Field.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FinAlias.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FinFrame.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FinPool.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FinPt.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FinRoot.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Frame.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameBacking.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameClear.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameMapDecode.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameMapPost.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameMapStage1.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameMapStage2.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameMapWrite.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FramePaths.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameRaw.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameRemove.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapPost.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapWalk.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapWord.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2FrameWord.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Image.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Install.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Keep.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2KeepArms.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2KtDel.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2KtLevel.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Loop.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MakePool.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapBacking.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapCaps.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapDispatch.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapGrow.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapHigh.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapHighEntry.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapNative.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapPaths.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapPlacement.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapPost.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapReach.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapReference.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapRootSlots.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapRoots.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapStage1Post.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapStage2.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapStage2Post.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapTypes.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapWalk.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2MapWrite.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2OfImage.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2PathReference.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2PtUnmap.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Relabel.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Restrict.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2RetypeEnd.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2RetypeFrame.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2RetypeHigh.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2RetypeNew.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2RetypePost.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2RetypeTop.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2RootInit.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Shrink.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2SlotUnique.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Slots.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2TcbArm.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Transfer.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Transport.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2UnmapAddress.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2UnmapPost.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2UnmapRoute.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2UnmapS1.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2UnmapS2.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2UnmapWalk.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aR2Zeroed.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aStepR2.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aStepR2A.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aStepR2Boot.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aStepR2K.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aStepR2KBoot.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aVsUnm.lean create mode 100644 proofs/Fl4ProofsA64/P1/S1aVsUnmB.lean diff --git a/DESIGN.md b/DESIGN.md index 9b8c292fa..466f388f2 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). `syscall.decode_invocation.s1aStepH` / `s1aStepPt` (`S1aStepH`, `S1aPtCol`) add Untyped Retype, ASIDPool Assign and ASIDControl MakePool, and carry the untyped and page-table columns (`S1aStep`: per-step `PtCap` and `PtHG`, page tables inside heap objects) across every arm. Their named premises: [P] `ArchTotal`, `MaxSpi`, `ArchPlat` (the IPA width), the thread facts `mcp`, `cs`, `fh`; per-step inputs not yet discharged from an invariant: the VSpace typing witness `hvs` (Stage-1 `VsTy` with `NoTag3` / `HighRoot511`, Stage-2 `S2DecTy`) and `HiCap511`. On real hardware `hvs` cannot hold after an ASIDPool Assign of a `HighVSpace` root whose copied kernel TTBR1 entries are non-zero (the kernel's tables are not heap objects), so the theorems say nothing at such states until a platform contract for those tables is added. At the boot witness `w1` (in the kernel window), the page-table column holds (`w1_s1aPtCol`). + - AArch64 (`proofs/Fl4ProofsA64/P1`, in progress): one capability invocation at a time, from P1's syscall-level bundle `SysL` (with `SymL`, the deletion input `DelIn` and the decode's placement facts). `syscall.decode_invocation.armQHAt` (`MdbArmQHD`) proves that every arm of `DecArmQH` ends in `ArmQIAt` (`SysL`, `SymL` and `BlkOK` at the result, plus the cap-only carries, including the page-table cap placement `PtCap`) and keeps the ASID table or zeroes an entry: CNode and deletion arms, TCB SetSchedParams / Suspend / ReadRegisters, IRQ control, Notification and Endpoint send, every VCPU invocation, and the VSpace arms (Stage-1 and `HighVSpace` Page / PageTable Map and Unmap, TestAndClearAccessed, the flushes, GetAddress, and every Stage-2 (EPT) operation). The step theorem is `syscall.decode_invocation.s1aStepR2K` (`S1aStepR2K`): on every arm of `DecArmS1aH` (`DecArmQH` plus Untyped Retype, ASIDPool Assign and ASIDControl MakePool) it takes, at entry, `S1aR2` (the VSpace record over the tables reachable from the ASID table: lookup, walks, root agreement, the Stage-1 and Stage-2 typings narrowed to reachable tables, exact path backing, footprint and placement), `S1aKtUt` (the kernel TTBR1 tables outside every Untyped) and `S1aHiK` (the levels of the kernel tables `Kt` and of the `HighVSpace` headers' copied descriptors, at the levels `KLv` of the platform contract `KTab`), and returns all three at the end, with `S1aStep`'s columns (`SysL`, `SymL`, the arm and cap columns, `PtCap`, `PtHG`, `HiCap511`, …; `S1aStepR2K.toR2` is `s1aStepR2`'s post). The boot witnesses give the entry (`w0_s1aStepEntryK`, `w1K_s1aStepEntryK`). Full typing of every live table is false on reachable states: `delete_asid_pool` leaves a mapped `HighVSpace` root whose private table still names a page table that can then be deleted and its memory retyped. So the deletion typing is the reachable one (`HiDelTyR`, a projection of `S1aR2`), and the tables an ASIDPool Assign makes reachable are typed by relabelling `S1aR2`'s levels on unreachable tables (`S1aR2.relabel`). Named premises: [P] `P0.ArchTotal`, `MaxSpi`, `ArchPlat` (the IPA width), `KTab`, `A64FrameMasks`. Covered arms: Null and Zombie caps, Endpoint and Notification sends, Domain, Untyped, IrqControl, IRQ handler Ack / Clear / Set, CNode Copy / Mint / Move / Mutate / Rotate / Revoke / Delete, the TCB labels SetSpace, SetHighVSpace, SetIPCBuffer, Configure, SetEPTRoot, SetTimeoutEndpoint, SetSchedParams, SetPriority, SetMCPriority, Suspend, ReadRegisters, SetTLSBase, SetPACKeys, SetFlags, ReadFPU and UnbindNotification, SchedContext Unbind / UnbindObject / Consumed, every VCPU label, every Stage-2 (`Ept`) invocation, Frame Map / Unmap / GetAddress / TestAndClearAccessed and the four cache operations, PageTable Map / Unmap, the `Pml4`, `PageDirectory` and `Pdpt` invocations, ASIDPool Assign and ASIDControl MakePool. Not covered on AArch64: Reply and SchedControl caps, direct `HighVSpace` invocations, CNode CancelBadgedSends, the TCB labels WriteRegisters, CopyRegisters, Resume, BindNotification, ConfigureSingleStepping, Set / Get / UnsetBreakpoint, SetTimer and WriteFPU, SchedContext Bind and YieldTo, Frame DeriveSubframe, and the unknown-label error branches. `IoPortControl`, `IoPort` and `TdxControl` are x86_64 only and do not apply on AArch64. Boundary: the theorem is about one `decode_invocation` of a `DecArmS1aH` arm, not `kernel_entry`, and it still takes entry-layer inputs its post does not return (`DelIn`, `DecPre`, `SysPlace`, the IRQ and slot-coverage facts `hIq` / `hSC`, and the thread facts `mcp`, `cs`, `fh`). The earlier tops `s1aStepH` / `s1aStepPt` / `s1aStepR2` remain, with their per-step inputs. - **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`). @@ -465,7 +465,7 @@ The argument ### Trusted base -The proof assumes: Rust, LLVM and the linker, and the kernels' linker scripts; Charon, Aeneas and the Lean kernel; the abstract spec; entry assembly and boot code; `fl4-store` and `fl4-sync`, and the Lean transcription of their protocol core (`proofs/Fl4P2Base/GateImpl.lean`); hardware backends; the totality of `Store` and `Arch` (for each extraction); and the processor's memory model. fl4-core's AArch64 slice has P0 only. Everything trusted is listed in one file in the repo, with its size tracked in CI. +The proof assumes: Rust, LLVM and the linker, and the kernels' linker scripts; Charon, Aeneas and the Lean kernel; the abstract spec; entry assembly and boot code; `fl4-store` and `fl4-sync`, and the Lean transcription of their protocol core (`proofs/Fl4P2Base/GateImpl.lean`); hardware backends; the totality of `Store` and `Arch` (for each extraction); and the processor's memory model. For fl4-core's AArch64 build, P0 is complete and P1 and P2 cover the parts listed above; P3 is about the x86_64 build only. Everything trusted is listed in one file in the repo, with its size tracked in CI. ## 10. Deterministic simulation diff --git a/README.md b/README.md index d2c24ed56..4b3d2f364 100644 --- a/README.md +++ b/README.md @@ -190,10 +190,30 @@ items to the same public modules, preserving the paths used by the backends and by the proof extractions (`proofs/Fl4Core` for x86_64, `proofs/Fl4CoreA64` for AArch64). P0 (no failure) covers both builds; P3 is about the x86_64 build, one serial kernel entry at a time; P1 covers -the x86_64 entries and, on AArch64, each capability invocation's decode step -(`armQHAt`, `s1aStepH`: every CNode, TCB, VCPU, Stage-1, `HighVSpace` and -Stage-2 arm plus Untyped Retype, ASID Assign and MakePool) from named -premises and two per-step inputs (DESIGN.md §9). +the x86_64 entries and, on AArch64, the decode step of the capability +invocations in `DecArmS1aH` (`syscall.decode_invocation.s1aStepR2K`; DESIGN.md +§9): from the reachable VSpace record `S1aR2`, the kernel-table / Untyped +separation and the kernel-table level column `S1aHiK` it returns all three +with the syscall-level bundle, and the boot witnesses give them at entry. The +arms covered are Null and Zombie caps, Endpoint and Notification sends, Domain, +Untyped, IrqControl, IRQ handler Ack / Clear / Set, CNode Copy / Mint / Move / +Mutate / Rotate / Revoke / Delete, the TCB labels SetSpace, SetHighVSpace, +SetIPCBuffer, Configure, SetEPTRoot, SetTimeoutEndpoint, SetSchedParams, +SetPriority, SetMCPriority, Suspend, ReadRegisters, SetTLSBase, SetPACKeys, +SetFlags, ReadFPU and UnbindNotification, SchedContext Unbind / +UnbindObject / Consumed, every VCPU label, every Stage-2 (`Ept`) invocation, +Frame Map / Unmap / GetAddress / TestAndClearAccessed and the four cache +operations, PageTable Map / Unmap, the `Pml4`, `PageDirectory` and `Pdpt` +invocations, ASIDPool Assign and ASIDControl MakePool. Not covered on AArch64: +Reply and SchedControl caps, direct `HighVSpace` invocations, CNode +CancelBadgedSends, the TCB labels WriteRegisters, CopyRegisters, Resume, +BindNotification, ConfigureSingleStepping, Set / Get / UnsetBreakpoint, +SetTimer and WriteFPU, SchedContext Bind and YieldTo, Frame DeriveSubframe, +and the unknown-label error branches. `IoPortControl`, `IoPort` and +`TdxControl` are x86_64 only (not applicable on AArch64). The step still +takes entry-layer inputs its post does not return (`DelIn`, `DecPre`, +`SysPlace`, `hIq`, `hSC`, `mcp`, `cs`, `fh`), so it is not yet an induction +over `kernel_entry`. The existing x86_64 P2 theorem is about the transactional runtime that was removed (DESIGN.md §9). On AArch64, P2 proves serializability for the serial gate and the local paths that run SMP today diff --git a/proofs/Fl4ProofsA64.lean b/proofs/Fl4ProofsA64.lean index e76240d57..ec18e929a 100644 --- a/proofs/Fl4ProofsA64.lean +++ b/proofs/Fl4ProofsA64.lean @@ -926,10 +926,109 @@ import Fl4ProofsA64.P1.MdbArmQHD import Fl4ProofsA64.P1.S1aStepH import Fl4ProofsA64.P1.S1aPtCap import Fl4ProofsA64.P1.S1aPtStep +import Fl4ProofsA64.P1.S1aDevFr +import Fl4ProofsA64.P1.S1aHiCap +import Fl4ProofsA64.P1.S1aHvPt +import Fl4ProofsA64.P1.S1aHiK +import Fl4ProofsA64.P1.S1aHiDelDec +import Fl4ProofsA64.P1.S1aHiVs +import Fl4ProofsA64.P1.S1aHiAsg +import Fl4ProofsA64.P1.S1aHiRetype +import Fl4ProofsA64.P1.S1aHiDispatch import Fl4ProofsA64.P1.S1aVsDec import Fl4ProofsA64.P1.S1aPtCol import Fl4ProofsA64.P1.S1aBootW1 import Fl4ProofsA64.P1.S1aS2Dec +import Fl4ProofsA64.P1.S1aKTab +import Fl4ProofsA64.P1.S1aKtUt +import Fl4ProofsA64.P1.S1aBootK +import Fl4ProofsA64.P1.S1aVsUnm +import Fl4ProofsA64.P1.S1aVsUnmB +import Fl4ProofsA64.P1.S1aR2Frame +import Fl4ProofsA64.P1.S1aR2Caps +import Fl4ProofsA64.P1.S1aR2Image +import Fl4ProofsA64.P1.S1aR2Shrink +import Fl4ProofsA64.P1.S1aR2Keep +import Fl4ProofsA64.P1.S1aR2Ept +import Fl4ProofsA64.P1.S1aR2Contract +import Fl4ProofsA64.P1.S1aR2Domains +import Fl4ProofsA64.P1.S1aR2RootInit +import Fl4ProofsA64.P1.S1aR2RetypeHigh +import Fl4ProofsA64.P1.S1aR2RetypeEnd +import Fl4ProofsA64.P1.S1aR2RetypeNew +import Fl4ProofsA64.P1.S1aR2RetypePost +import Fl4ProofsA64.P1.S1aR2RetypeTop +import Fl4ProofsA64.P1.S1aR2Restrict +import Fl4ProofsA64.P1.S1aR2AddPool +import Fl4ProofsA64.P1.S1aR2MakePool +import Fl4ProofsA64.P1.S1aR2Del +import Fl4ProofsA64.P1.S1aR2Slots +import Fl4ProofsA64.P1.S1aR2Loop +import Fl4ProofsA64.P1.S1aR2Field +import Fl4ProofsA64.P1.S1aR2Zeroed +import Fl4ProofsA64.P1.S1aR2FinPool +import Fl4ProofsA64.P1.S1aR2FinFrame +import Fl4ProofsA64.P1.S1aR2FinPt +import Fl4ProofsA64.P1.S1aR2FinRoot +import Fl4ProofsA64.P1.S1aR2FinAlias +import Fl4ProofsA64.P1.S1aR2Delete +import Fl4ProofsA64.P1.S1aR2Transport +import Fl4ProofsA64.P1.S1aR2MapRoots +import Fl4ProofsA64.P1.S1aR2MapWalk +import Fl4ProofsA64.P1.S1aR2MapNative +import Fl4ProofsA64.P1.S1aR2MapHighEntry +import Fl4ProofsA64.P1.S1aR2MapHigh +import Fl4ProofsA64.P1.S1aR2MapStage2 +import Fl4ProofsA64.P1.S1aR2MapWrite +import Fl4ProofsA64.P1.S1aR2MapStage2Post +import Fl4ProofsA64.P1.S1aR2MapReference +import Fl4ProofsA64.P1.S1aR2MapStage1Post +import Fl4ProofsA64.P1.S1aR2MapPlacement +import Fl4ProofsA64.P1.S1aR2MapPaths +import Fl4ProofsA64.P1.S1aR2MapBacking +import Fl4ProofsA64.P1.S1aR2MapReach +import Fl4ProofsA64.P1.S1aR2MapTypes +import Fl4ProofsA64.P1.S1aR2MapRootSlots +import Fl4ProofsA64.P1.S1aR2MapCaps +import Fl4ProofsA64.P1.S1aR2MapGrow +import Fl4ProofsA64.P1.S1aR2MapPost +import Fl4ProofsA64.P1.S1aR2MapDispatch +import Fl4ProofsA64.P1.S1aR2FrameWord +import Fl4ProofsA64.P1.S1aR2FramePaths +import Fl4ProofsA64.P1.S1aR2FrameMapWrite +import Fl4ProofsA64.P1.S1aR2FrameMapStage1 +import Fl4ProofsA64.P1.S1aR2FrameMapStage2 +import Fl4ProofsA64.P1.S1aR2FrameMapDecode +import Fl4ProofsA64.P1.S1aR2FrameRaw +import Fl4ProofsA64.P1.S1aR2SlotUnique +import Fl4ProofsA64.P1.S1aR2FrameBacking +import Fl4ProofsA64.P1.S1aR2FrameMapPost +import Fl4ProofsA64.P1.S1aR2FrameUnmapPost +import Fl4ProofsA64.P1.S1aR2AccessPost +import Fl4ProofsA64.P1.S1aR2AssignRoot +import Fl4ProofsA64.P1.S1aR2AssignPaths +import Fl4ProofsA64.P1.S1aR2AssignCaps +import Fl4ProofsA64.P1.S1aR2AssignStage2 +import Fl4ProofsA64.P1.S1aR2AssignStage1 +import Fl4ProofsA64.P1.S1aR2AssignPlace +import Fl4ProofsA64.P1.S1aR2AssignLive +import Fl4ProofsA64.P1.S1aR2AssignLookup +import Fl4ProofsA64.P1.S1aR2AssignPost +import Fl4ProofsA64.P1.S1aR2RetypeFrame +import Fl4ProofsA64.P1.S1aR2PathReference +import Fl4ProofsA64.P1.S1aR2UnmapAddress +import Fl4ProofsA64.P1.S1aR2UnmapWalk +import Fl4ProofsA64.P1.S1aR2UnmapS1 +import Fl4ProofsA64.P1.S1aR2UnmapS2 +import Fl4ProofsA64.P1.S1aR2UnmapRoute +import Fl4ProofsA64.P1.S1aR2Assign +import Fl4ProofsA64.P1.S1aR2PtUnmap +import Fl4ProofsA64.P1.S1aR2UnmapPost +import Fl4ProofsA64.P1.MdbArmVs +import Fl4ProofsA64.P1.MdbArmVsF +import Fl4ProofsA64.P1.MdbArmVsG +import Fl4ProofsA64.P1.MdbDelVsZ +import Fl4ProofsA64.P1.MdbArmVsV import Fl4ProofsA64.P1.MdbRunF import Fl4ProofsA64.P1.MdbRunW import Fl4ProofsA64.P1.MdbRunQ @@ -977,6 +1076,31 @@ import Fl4ProofsA64.P1.BootSysL1 import Fl4ProofsA64.P1.BootScAp import Fl4ProofsA64.P2.BootSysA import Fl4ProofsA64.P1.BootW1Win +import Fl4ProofsA64.P1.S1aR2DelArm +import Fl4ProofsA64.P1.S1aR2OfImage +import Fl4ProofsA64.P1.S1aR2Transfer +import Fl4ProofsA64.P1.S1aR2CnodeImage +import Fl4ProofsA64.P1.S1aR2Install +import Fl4ProofsA64.P1.S1aR2TcbArm +import Fl4ProofsA64.P1.S1aR2KeepArms +import Fl4ProofsA64.P1.S1aKtUtArms +import Fl4ProofsA64.P1.S1aKtUtDel +import Fl4ProofsA64.P1.S1aR2KtDel +import Fl4ProofsA64.P1.S1aStepR2 +import Fl4ProofsA64.P1.S1aStepR2Boot +import Fl4ProofsA64.P1.S1aHiDelR +import Fl4ProofsA64.P1.S1aR2AssignD +import Fl4ProofsA64.P1.S1aStepR2A +import Fl4ProofsA64.P1.S1aKtLvCol +import Fl4ProofsA64.P1.S1aR2KtLevel +import Fl4ProofsA64.P1.S1aR2Relabel +import Fl4ProofsA64.P1.S1aKtArms +import Fl4ProofsA64.P1.S1aKtDelArms +import Fl4ProofsA64.P1.S1aKtVsArms +import Fl4ProofsA64.P1.S1aKtPoolArms +import Fl4ProofsA64.P1.S1aKtRetype +import Fl4ProofsA64.P1.S1aStepR2K +import Fl4ProofsA64.P1.S1aStepR2KBoot import Fl4ProofsA64.P2.GlueAdeqA import Fl4ProofsA64.P2.GlueRepA import Fl4ProofsA64.P2.MdbEditA diff --git a/proofs/Fl4ProofsA64/P1/MdbAllArmQ.lean b/proofs/Fl4ProofsA64/P1/MdbAllArmQ.lean index 7c65d6dfa..6d51f58d3 100644 --- a/proofs/Fl4ProofsA64/P1/MdbAllArmQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbAllArmQ.lean @@ -105,7 +105,7 @@ theorem syscall.decode_invocation.armKQAt (hA : P0.ArchTotal ar) {s : S} {cap : (syscall.decode_invocation.scConsumed_armQIKAt hA D P B Y hvr hks hSA hcap a hl len blk call don fp buf) fun _ h => ⟨h.1, h.2.1.toDel⟩ · exact WP.spec_mono (syscall.decode_invocation.cnode_armQIKAt D P B Y hvr a len blk call don fp buf hl hf hcap) - fun _ h => ⟨h.1, h.2.toDel⟩ + fun _ h => ⟨h.1, h.2.1.toDel⟩ · exact WP.spec_mono (syscall.decode_invocation.rej_eq hr a lbl len blk call don fp buf) fun ⟨_, s', _⟩ e => by subst e @@ -131,7 +131,7 @@ theorem syscall.decode_invocation.armKQ (hA : P0.ArchTotal ar) {s : S} {cap : ca moved here, `syscall.decode_invocation.armQZ` its projection). -/ theorem syscall.decode_invocation.armQZAt (hA : P0.ArchTotal ar) {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) @@ -150,7 +150,7 @@ theorem syscall.decode_invocation.armQZAt (hA : P0.ArchTotal ar) {s : S} {cap : `del_armQI` on the deletion-family arms, `armKQ` on the others. -/ theorem syscall.decode_invocation.armQZ (hA : P0.ArchTotal ar) {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) diff --git a/proofs/Fl4ProofsA64/P1/MdbArmDf.lean b/proofs/Fl4ProofsA64/P1/MdbArmDf.lean index 5c3c5f03b..a9c93e2fc 100644 --- a/proofs/Fl4ProofsA64/P1/MdbArmDf.lean +++ b/proofs/Fl4ProofsA64/P1/MdbArmDf.lean @@ -26,6 +26,9 @@ shared wrapper, each arm a short instance). `ArmQIAt` (the same facts at the decode's own `(H, OS)`); each is the body of the name without `At`, moved, and that name is now its `ArmQIAt.toQI` projection (statement unchanged). +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ArmQIAt.ofDFK` and the six `…_armQIKAt` tops also post the `ArmVsK` +they build (last conjunct; `ArmVsK.refl` on the unchanged exits); the `…_armQIK` projections take `h.2.1, h.2.2.1`. + Named premises: none. Case facts: none new. `hvr` is the entry record's `DelIn.del.vr`. -/ import Fl4ProofsA64.P1.MdbArmTab @@ -54,7 +57,7 @@ theorem ArmQIAt.ofDFK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (d : DF st H Cs (L.curW s) Ko s s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' := by obtain ⟨Q, Rq, q⟩ := D.bxi.1 have hSg := D.bxi.blk.2.2.2.2 have F : TabF st H Cs OS s := TabF.of hvr q B.ly.ksw P.core0 @@ -64,9 +67,11 @@ theorem ArmQIAt.ofDFK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra (fun _ _ c hc => absurd hc (Set.notMem_empty c)) (fun e he => absurd he (Set.notMem_empty e)) hx hb h1 h2 (K8.KW.to7 hk) · exact B.ly.kslo o hl x hx (by rw [← e]; exact ⟨h1, h2⟩) - exact (fun h => ⟨h.1, h.2, k⟩) (ArmQIAt.ofWK hvr d.w - (fun b hd => DfW.notAsW P.heap F hvr (fun c hc => q.nodes c hc) hd) k - (SysL.df P D.bxi D.run (fun o _ hl y hy => B.ly.kslo o hl y hy) B Y d) hb) + have hA : ∀ b, DfW st H.tcbs Cs H.frame H.scBits Ko s b → ¬ AsW (L.ksb s) b := + fun b hd => DfW.notAsW P.heap F hvr (fun c hc => q.nodes c hc) hd + have vk : ArmVsK st H OS Vc s s' := ArmVsK.ofDF q d hA + exact (fun h => ⟨h.1, h.2, k, vk⟩) (ArmQIAt.ofWK hvr d.w hA k + (SysL.df P D.bxi D.run (fun o _ hl y hy => B.ly.kslo o hl y hy) B Y d) hb vk.toVs) /-- (gen 143) **`ofDF` with `TabKeep ∧ OSKeep` exported** (the body of `ofDF`, moved). -/ theorem ArmQI.ofDFK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -77,7 +82,7 @@ theorem ArmQI.ofDFK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : (d : DF st H Cs (L.curW s) Ko s s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' := - (fun h => ⟨h.1.toQI, h.2⟩) (ArmQIAt.ofDFK D P B Y hvr d hb) + (fun h => ⟨h.1.toQI, h.2.1, h.2.2.1⟩) (ArmQIAt.ofDFK D P B Y hvr d hb) /-- **The DF-family wrapper** (module docstring). -/ theorem ArmQI.ofDF {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -101,13 +106,13 @@ theorem syscall.decode_invocation.domain_armQIKAt (hA : P0.ArchTotal ar) {s : S} (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot .Domain blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (domain.decode.dfK hA s a lbl len buf extra D) fun r d => by obtain ⟨r, s', a'⟩ := r exact ArmQIAt.ofDFK D P B Y hvr d.1 d.2 @@ -123,6 +128,8 @@ theorem syscall.decode_invocation.domain_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.domain_armQIKAt hA D P B Y hvr a lbl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI @@ -163,7 +170,7 @@ theorem syscall.decode_invocation.irqAck_armQIKAt (hA : P0.ArchTotal ar) {s : S} (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.IRQAckIRQ) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.IrqHandler irq) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ exact WP.spec_mono (interrupt.decode_irq_handler.ackDFK hA D a irq hl) fun r d => by @@ -181,6 +188,8 @@ theorem syscall.decode_invocation.irqAck_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.irqAck_armQIKAt hA D P B Y hvr a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI @@ -207,13 +216,13 @@ theorem syscall.decode_invocation.tls_armQIKAt (hA : P0.ArchTotal ar) {s : S} (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetTLSBase) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (tcb.decode.tlsDFK hA D hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact ArmQIAt.ofDFK D P B Y hvr d.1 d.2 @@ -229,6 +238,8 @@ theorem syscall.decode_invocation.tls_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.tls_armQIKAt hA D P B Y hvr a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI @@ -255,13 +266,13 @@ theorem syscall.decode_invocation.pac_armQIKAt (hA : P0.ArchTotal ar) {s : S} (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetPACKeys) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (tcb.decode.pacDFK hA D hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact ArmQIAt.ofDFK D P B Y hvr d.1 d.2 @@ -277,6 +288,8 @@ theorem syscall.decode_invocation.pac_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.pac_armQIKAt hA D P B Y hvr a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI @@ -303,13 +316,13 @@ theorem syscall.decode_invocation.flags_armQIKAt (hA : P0.ArchTotal ar) {s : S} (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetFlags) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (tcb.decode.flagsDFK hA D hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact ArmQIAt.ofDFK D P B Y hvr d.1 d.2 @@ -325,6 +338,8 @@ theorem syscall.decode_invocation.flags_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.flags_armQIKAt hA D P B Y hvr a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI @@ -351,7 +366,7 @@ theorem syscall.decode_invocation.vcRead_armQIKAt (hA : P0.ArchTotal ar) {s : S} (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPUReadReg) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ unfold vcpu.decode @@ -374,6 +389,8 @@ theorem syscall.decode_invocation.vcRead_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.vcRead_armQIKAt hA D P B Y hvr a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI diff --git a/proofs/Fl4ProofsA64/P1/MdbArmDfB.lean b/proofs/Fl4ProofsA64/P1/MdbArmDfB.lean index 80da6e151..426e0c076 100644 --- a/proofs/Fl4ProofsA64/P1/MdbArmDfB.lean +++ b/proofs/Fl4ProofsA64/P1/MdbArmDfB.lean @@ -21,6 +21,9 @@ P1 (aarch64, gen 141): **the DFB-family wrapper and TCB ReadFPU to `ArmQI`** (ge OS)`); each is the body of the name without `At`, moved, and that name is now its `ArmQIAt.toQI` projection (statement unchanged). +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ArmQIAt.ofDFBK` and `readFpu_armQIKAt` also post the `ArmVsK` they +build (last conjunct). + Named premises: none. Case facts: none new; `hks : HeapKsOff H (L.ksb s)` (S1aPlace, ruled gen 136) is read, as by the CNode arms. `hvr` is the entry record's `DelIn.del.vr`. -/ @@ -58,10 +61,10 @@ theorem ArmQIAt.ofDFBK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra (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 Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (hks : HeapKsOff H (L.ksb s)) - (d : DFB st H Cs (L.curW s) Ko Bw s s') (hBw : ∀ b, Bw b → FrBw H OS b) + (d : DFB st H Cs (L.curW s) Ko Bw s s') (hBw : ∀ b, Bw b → FrBw H OS b ∧ FrCw st OS s b) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' := by obtain ⟨Q, Rq, q⟩ := D.bxi.1 have hSg := D.bxi.blk.2.2.2.2 have F : TabF st H Cs OS s := TabF.of hvr q B.ly.ksw P.core0 @@ -71,12 +74,15 @@ theorem ArmQIAt.ofDFBK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra (fun _ _ c hc => absurd hc (Set.notMem_empty c)) (fun e he => absurd he (Set.notMem_empty e)) hx hb h1 h2 (K8.KW.to7 hk) · exact B.ly.kslo o hl x hx (by rw [← e]; exact ⟨h1, h2⟩) - · exact (hBw b hw).2.2 x hx ⟨h1, h2⟩ - refine (fun h => ⟨h.1, h.2, k⟩) (ArmQIAt.ofWK hvr d.w (fun b hd => ?_) k hS hb) - rcases hd with hd | hw - · exact DfW.notAsW P.heap F hvr (fun c hc => q.nodes c hc) hd - · obtain ⟨ptr, z, hp, hz, h1, h2⟩ := (hBw b hw).2.1 - exact fun ha => frObj_notAsW hks F.ksw hp hz h1 h2 ha + · exact (hBw b hw).1.2.2 x hx ⟨h1, h2⟩ + have hA : ∀ b, (DfW st H.tcbs Cs H.frame H.scBits Ko s b ∨ Bw b) → ¬ AsW (L.ksb s) b := fun b hd => by + rcases hd with hd | hw + · exact DfW.notAsW P.heap F hvr (fun c hc => q.nodes c hc) hd + · obtain ⟨ptr, z, hp, hz, h1, h2⟩ := (hBw b hw).1.2.1 + exact fun ha => frObj_notAsW hks F.ksw hp hz h1 h2 ha + have vk : ArmVsK st H OS Vc s s' := + ArmVsK.ofFoot P.heap q d.w (fun b hb => hb.imp_right fun hw => Or.inr (hBw b hw).2) hA + exact (fun h => ⟨h.1, h.2, k, vk⟩) (ArmQIAt.ofWK hvr d.w hA k hS hb vk.toVs) /-- (gen 143) **`ofDFB` with `TabKeep ∧ OSKeep` exported** (the body of `ofDFB`, moved). -/ theorem ArmQI.ofDFBK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -84,11 +90,11 @@ theorem ArmQI.ofDFBK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : (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 Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (hks : HeapKsOff H (L.ksb s)) - (d : DFB st H Cs (L.curW s) Ko Bw s s') (hBw : ∀ b, Bw b → FrBw H OS b) + (d : DFB st H Cs (L.curW s) Ko Bw s s') (hBw : ∀ b, Bw b → FrBw H OS b ∧ FrCw st OS s b) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' := - (fun h => ⟨h.1.toQI, h.2⟩) (ArmQIAt.ofDFBK D P B hvr hks d hBw hS hb) + (fun h => ⟨h.1.toQI, h.2.1, h.2.2.1⟩) (ArmQIAt.ofDFBK D P B hvr hks d hBw hS hb) /-- **The DFB-family wrapper** (module docstring). -/ theorem ArmQI.ofDFB {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -96,7 +102,7 @@ theorem ArmQI.ofDFB {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : (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 Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (hks : HeapKsOff H (L.ksb s)) - (d : DFB st H Cs (L.curW s) Ko Bw s s') (hBw : ∀ b, Bw b → FrBw H OS b) + (d : DFB st H Cs (L.curW s) Ko Bw s s') (hBw : ∀ b, Bw b → FrBw H OS b ∧ FrCw st OS s b) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : ArmQI st H Cs OS Vc ia ie s s' := @@ -113,13 +119,13 @@ theorem syscall.decode_invocation.readFpu_armQIKAt (hA : P0.ArchTotal ar) {s : S (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (hks : HeapKsOff H (L.ksb s)) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBReadFPU) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (tcb.decode.readFpuLK hA D P B Y hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact ArmQIAt.ofDFBK D P B hvr hks d.2.2 (fun _ h => h) d.1 d.2.1 @@ -135,6 +141,8 @@ theorem syscall.decode_invocation.readFpu_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.readFpu_armQIKAt hA D P B Y hvr hks a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI diff --git a/proofs/Fl4ProofsA64/P1/MdbArmDm.lean b/proofs/Fl4ProofsA64/P1/MdbArmDm.lean index 6bfd289e8..f7e4ef076 100644 --- a/proofs/Fl4ProofsA64/P1/MdbArmDm.lean +++ b/proofs/Fl4ProofsA64/P1/MdbArmDm.lean @@ -23,6 +23,9 @@ TCB UnbindNotification, SchedContext UnbindObject / Unbind, SchedContext Consume OS)`); each is the body of the name without `At`, moved, and that name is now its `ArmQIAt.toQI` projection (statement unchanged). +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ArmQIAt.ofDMK` and the three `…_armQIKAt` tops also post the +`ArmVsK` they build (last conjunct). + Named premises: none. Case facts: none new; `hks : HeapKsOff H (L.ksb s)` (S1aPlace, ruled gen 136) and the state-free `ScApart H.scs H.scBits OS` (as MdbDfM's tops) are read. `hvr` is the entry record's `DelIn.del.vr`. -/ @@ -83,7 +86,7 @@ theorem ArmQIAt.ofDMK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra (hSA : ScApart H.scs H.scBits OS) (w : WritesIn st s s' (DmW st H Cs s)) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' := by obtain ⟨Q, Rq, q⟩ := D.bxi.1 have hSg := D.bxi.blk.2.2.2.2 have F : TabF st H Cs OS s := TabF.of hvr q B.ly.ksw P.core0 @@ -94,10 +97,12 @@ theorem ArmQIAt.ofDMK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra (K8.KW.to7 hk) · exact B.ly.kslo o hl x hx (by rw [← e]; exact ⟨h1, h2⟩) · exact kw7_not_os (Es := EH H) q hSg.sub hSA (fun _ he => he) hx hb h1 h2 (K8.KW.to7 hk) - refine (fun h => ⟨h.1, h.2, k⟩) (ArmQIAt.ofWK hvr w (fun b hd => ?_) k hS hb) - rcases hd with hd | hd - · exact DfW.notAsW P.heap F hvr (fun c hc => q.nodes c hc) hd - · exact fun ha => K8.KW.notAsWE P.heap F hvr hks (fun _ he => he) (fun c hc => q.nodes c hc) hd ha + have hA : ∀ b, DmW st H Cs s b → ¬ AsW (L.ksb s) b := fun b hd => by + rcases hd with hd | hd + · exact DfW.notAsW P.heap F hvr (fun c hc => q.nodes c hc) hd + · exact fun ha => K8.KW.notAsWE P.heap F hvr hks (fun _ he => he) (fun c hc => q.nodes c hc) hd ha + have vk : ArmVsK st H OS Vc s s' := ArmVsK.ofDM P.heap q w hA + exact (fun h => ⟨h.1, h.2, k, vk⟩) (ArmQIAt.ofWK hvr w hA k hS hb vk.toVs) /-- (gen 143) **`ofDM` with `TabKeep ∧ OSKeep` exported** (the body of `ofDM`, moved). -/ theorem ArmQI.ofDMK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -109,7 +114,7 @@ theorem ArmQI.ofDMK {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' := - (fun h => ⟨h.1.toQI, h.2⟩) (ArmQIAt.ofDMK D P B hvr hks hSA w hS hb) + (fun h => ⟨h.1.toQI, h.2.1, h.2.2.1⟩) (ArmQIAt.ofDMK D P B hvr hks hSA w hS hb) /-- **The DM-family wrapper** (module docstring). -/ theorem ArmQI.ofDM {Rp Nt Vc' Ub Pt : Set U64} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -136,13 +141,13 @@ theorem syscall.decode_invocation.unbindN_armQIKAt (hA : P0.ArchTotal ar) {s : S (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBUnbindNotification) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (tcb.decode.unbindNLK hA D P B Y hSA hcap hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact ArmQIAt.ofDMK D P B hvr hks hSA d.w d.sys d.blk @@ -160,6 +165,8 @@ theorem syscall.decode_invocation.unbindN_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.unbindN_armQIKAt hA D P B Y hvr hks hSA hcap a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI @@ -190,13 +197,13 @@ theorem syscall.decode_invocation.scUnbind_armQIKAt (hA : P0.ArchTotal ar) {s : (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.SchedContextUnbindObject ∨ lbl = fl4_abi.label.SchedContextUnbind) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.SchedContext p b) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (schedcontext.decode.unbindLK hA D P B Y hSA hcap hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact ArmQIAt.ofDMK D P B hvr hks hSA d.w d.sys d.blk @@ -214,6 +221,8 @@ theorem syscall.decode_invocation.scUnbind_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.scUnbind_armQIKAt hA D P B Y hvr hks hSA hcap a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI @@ -244,13 +253,13 @@ theorem syscall.decode_invocation.scConsumed_armQIKAt (hA : P0.ArchTotal ar) {s (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.SchedContextConsumed) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.SchedContext p b) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (schedcontext.decode.consumedLK hA D P B Y hSA hcap hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact ArmQIAt.ofDMK D P B hvr hks hSA d.w d.sys d.blk @@ -268,6 +277,8 @@ theorem syscall.decode_invocation.scConsumed_armQIK (hA : P0.ArchTotal ar) {s : ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.scConsumed_armQIKAt hA D P B Y hvr hks hSA hcap a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI diff --git a/proofs/Fl4ProofsA64/P1/MdbArmQH.lean b/proofs/Fl4ProofsA64/P1/MdbArmQH.lean index 4a5cb4e56..5af506d8c 100644 --- a/proofs/Fl4ProofsA64/P1/MdbArmQH.lean +++ b/proofs/Fl4ProofsA64/P1/MdbArmQH.lean @@ -13,7 +13,9 @@ is local). - (gen 158, Architect 14:29Z, option (A): one more binder `Pt`, the `Pt` of `DelIn`) `vs`: QueueVsTy's `VsTy` at the decode state over ghost pools `Pp ⊆ Pt` and tables `Tb ⊆ Pt` (S1a's `EntryInvA.vs`); - (gen 158) `ptCap`: an invoked `PageTable p …` cap has `p ∈ Pt` (S1a: from an `OS`-wide `PtCap` invariant); - (gen 160, F3) and `p.val + 4096 ≤ 2 ^ 64`. + (gen 160, F3) and `p.val + 4096 ≤ 2 ^ 64`; (A64-S1A gen 33, G2) and `p.val % 4096 = 0`. + - (A64-S1A gen 33, Architect 00:25Z, G1) `frAl`: an invoked device `Frame` cap is 4 KiB aligned (Page Map's + `VsWr.leaf` needs `DescTo`). - (gen 159, Architect 15:01Z, F2) `vs` bundles QueueVsTy's `VsTy` with `noTag3` (no ASID-pool entry has tag 3) and `high511` (a tag-2 / `HighVSpace` root's entry 511 is the table descriptor `init_high_vspace` writes) as the local record **`VsDecTy`** (QueuePtTy's `PtTy.high` and the tag-3 half of `PtTy.tag`; the Stage-2 tag 1 stays allowed); @@ -95,11 +97,16 @@ structure ArmDecHyps (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Pt vs : VsDecS2 st Pt n s /-- (gen 158, Architect 14:29Z) An invoked `PageTable` cap names a table of `Pt` (S1a discharges it from an `OS`-wide `PtCap` invariant at its entry layer); (gen 160, Architect 15:34Z, F3) and the table does not wrap - (`zero(ptr, 4096)`; S1a: from `PtH` and `HeapOK.fits`). -/ - ptCap : ∀ p m a v, cap = .PageTable p m a v → p ∈ Pt ∧ p.val + 4096 ≤ 2 ^ 64 + (`zero(ptr, 4096)`; S1a: from `PtH` and `HeapOK.fits`); (A64-S1A gen 33, Architect 00:25Z, G2) and the table is + 4 KiB aligned (`make_user_table` / `make_s2_table (paddr ptr)` keep `ptr & ADDR_MASK`). -/ + ptCap : ∀ p m a v, cap = .PageTable p m a v → p ∈ Pt ∧ p.val + 4096 ≤ 2 ^ 64 ∧ p.val % 4096 = 0 /-- (gen 159, Architect 15:01Z, F1a) No `PtW Pt` word is an ASID-table word of the decode's state block (S1A: from `PtH : ∀ p ∈ Pt, H p = some (.other 12)` and `HeapKsOff`, as `HeapKsOff.vcAsW`). -/ ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b + /-- (A64-S1A gen 33, Architect 00:25Z, G1) An invoked device `Frame` cap is 4 KiB aligned (`make_user_page` / + `make_s2_leaf` keep `paddr(fp) & ADDR_MASK`; non-device frames are aligned by the heap, MdbVsMapB's `frame_al4k`; + S1A: from its carried `DevFrAl`, Retype aligning device frames as `untyped.rs` `align_up`). -/ + frAl : ∀ p sz r m e a v, cap = .Frame p sz r true m e a v → p.val % 4096 = 0 /-- **The Stage-1 half of `ArmDecHyps.vs`** (gen 162; the form the Stage-1 arms read). -/ theorem ArmDecHyps.vs1 {n : U64} {s : S} {cap : capability.Cap} (Hy : ArmDecHyps st H Pt n s cap) : diff --git a/proofs/Fl4ProofsA64/P1/MdbArmQHD.lean b/proofs/Fl4ProofsA64/P1/MdbArmQHD.lean index d97b838f5..69f0db7d0 100644 --- a/proofs/Fl4ProofsA64/P1/MdbArmQHD.lean +++ b/proofs/Fl4ProofsA64/P1/MdbArmQHD.lean @@ -96,7 +96,7 @@ def DecArmQH (cap : capability.Cap) (lbl : U64) : Prop := /-- **`decode_invocation` to `ArmQIAt ∧ TabKeepOrZero` on every `DecArmQH` arm** (module docstring). -/ theorem syscall.decode_invocation.armQHAt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) @@ -117,20 +117,34 @@ theorem syscall.decode_invocation.armQHAt (hA : P0.ArchTotal ar) (hM : MaxSpi ar fp buf · exact syscall.decode_invocation.armKQ3At hA I D P B Y hcap hks Hy.mcp Hy.cs a hc len blk call don fp buf · exact syscall.decode_invocation.ssp_armQIAt hA I hKZ hPI D P B Y hks hcap Hy a hl len blk call don fp buf - · exact syscall.decode_invocation.irqCtl_armQIAt hA hM I D P B Y hcap a lbl len blk call don fp buf - · exact syscall.decode_invocation.ntfn_armQIAt hA I D P B Y hks hcap a lbl len blk call don fp buf - · exact syscall.decode_invocation.ep_armQIAt hA I D P B Y hks hcap a lbl len blk call don fp buf - · exact syscall.decode_invocation.suspend_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf - · exact syscall.decode_invocation.readRegs_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf - · exact syscall.decode_invocation.run_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf - · exact syscall.decode_invocation.ackVppi_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf - · exact syscall.decode_invocation.vcWr_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf - · exact syscall.decode_invocation.vcSt_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf - · exact syscall.decode_invocation.setTcb_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf - · exact syscall.decode_invocation.vsFl_armQIAt hA I D P B Y hks a lbl len blk call don fp buf - · exact syscall.decode_invocation.pgFl_armQIAt hA I D P B Y hks a hl len blk call don fp buf - · exact syscall.decode_invocation.pdInv_armQIAt D B Y a hc lbl len blk call don fp buf - · exact syscall.decode_invocation.getAddr_armQIAt I D P B Y hks a hl len blk call don fp buf + · exact WP.spec_mono (syscall.decode_invocation.irqCtl_armQIAt hA hM I D P B Y hcap a lbl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.ntfn_armQIAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.ep_armQIAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.suspend_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.readRegs_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.run_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.ackVppi_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.vcWr_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.vcSt_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.setTcb_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.vsFl_armQIAt hA I D P B Y hks a lbl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.pgFl_armQIAt hA I D P B Y hks a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.pdInv_armQIAt D B Y a hc lbl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ + · exact WP.spec_mono (syscall.decode_invocation.getAddr_armQIAt I D P B Y hks a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ · cases fe · exact syscall.decode_invocation.pgUnmap_armQIAt hA I D P B Y Hy hcap a hl len blk call don fp buf · exact syscall.decode_invocation.pgUnmapE_armQIAt hA hPl I D P B Y Hy.vs hcap a hl len blk call don fp buf @@ -138,12 +152,13 @@ theorem syscall.decode_invocation.armQHAt (hA : P0.ArchTotal ar) (hM : MaxSpi ar · exact syscall.decode_invocation.pgMapS_armQIAt hA hPl I D P B Y Hy hcap a hl len blk call don fp buf · exact syscall.decode_invocation.ptMapS_armQIAt hA hPl I D P B Y Hy hcap a hl len blk call don fp buf · exact syscall.decode_invocation.ptUnmapS_armQIAt hA hPl I D P B Y Hy Hy.vs hcap a hl len blk call don fp buf - · exact syscall.decode_invocation.ept_armQIAt hA I D P B Y hks a lbl len blk call don fp buf + · exact WP.spec_mono (syscall.decode_invocation.ept_armQIAt hA I D P B Y hks a lbl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1⟩ /-- **`armQHAt` in `ArmQI` form** (`ArmQIAt.toQI`). -/ theorem syscall.decode_invocation.armQH (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) diff --git a/proofs/Fl4ProofsA64/P1/MdbArmQR.lean b/proofs/Fl4ProofsA64/P1/MdbArmQR.lean index 0e1e200f5..60ce8e0ca 100644 --- a/proofs/Fl4ProofsA64/P1/MdbArmQR.lean +++ b/proofs/Fl4ProofsA64/P1/MdbArmQR.lean @@ -34,7 +34,7 @@ its projection). -/ theorem ArmQIAt.refl {s : S} (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) : ArmQIAt st H Cs OS Vc ia ie s s := - ⟨B, Y, ⟨Ac, hb⟩, id, id, id, fun _ h => h, fun _ h => h⟩ + ⟨B, Y, ⟨Ac, hb⟩, id, id, id, fun _ h => h, fun _ _ h => h, ArmVs.refl s⟩ /-- **`ArmQI` at the decode's own state** (module docstring). -/ theorem ArmQI.refl {s : S} (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) diff --git a/proofs/Fl4ProofsA64/P1/MdbArmQZ2.lean b/proofs/Fl4ProofsA64/P1/MdbArmQZ2.lean index 351f26dd8..3e59b28db 100644 --- a/proofs/Fl4ProofsA64/P1/MdbArmQZ2.lean +++ b/proofs/Fl4ProofsA64/P1/MdbArmQZ2.lean @@ -54,7 +54,7 @@ theorem syscall.decode_invocation.armKQ2At (hA : P0.ArchTotal ar) {s : S} {cap : /-- **`decode_invocation` to `ArmQIAt ∧ TabKeepOrZero` on every `DecArmQZ2` arm** (module docstring). -/ theorem syscall.decode_invocation.armQZ2At (hA : P0.ArchTotal ar) {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) @@ -72,7 +72,7 @@ theorem syscall.decode_invocation.armQZ2At (hA : P0.ArchTotal ar) {s : S} {cap : /-- **`armQZ2At` in `ArmQI` form** (`ArmQIAt.toQI`). -/ theorem syscall.decode_invocation.armQZ2 (hA : P0.ArchTotal ar) {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) diff --git a/proofs/Fl4ProofsA64/P1/MdbArmTab.lean b/proofs/Fl4ProofsA64/P1/MdbArmTab.lean index c4621a01c..f262ce9cd 100644 --- a/proofs/Fl4ProofsA64/P1/MdbArmTab.lean +++ b/proofs/Fl4ProofsA64/P1/MdbArmTab.lean @@ -97,11 +97,11 @@ theorem ArmQIAt.ofW {Ω Sg Scs Vc' Ub Pt : Set U64} {Z : U64 → Nat} {W : U64 (hvr : VrOK Ω Sg Scs Z OS Vc' Ub (L.ksb s) Pt) (w : WritesIn st s s' W) (hW : ∀ b, W b → ¬ AsW (L.ksb s) b) (k : OSKeep st OS s s') (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') - (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' := + (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') + (hV : ArmVs st H OS Vc s s') : ArmQIAt st H Cs OS Vc ia ie s s' := have ht := tab_of_w hvr w hW ⟨hS.1, hS.2, ⟨Ac', hb⟩, fun h => CapInv.keepO h k, PoolOff.ofTab w.1 ht, PoolNamed.ofTab w.1 ht k, - fun _ => PoolIdx.ofTab w.1 ht k, fun _ h => PtCap.ofOSK k h⟩ + fun _ => PoolIdx.ofTab w.1 ht k, fun _ _ h => CapInv.keepO h k, hV⟩ /-- **The generic wrapper's core** (module docstring): `ArmQI` at the decode's own heap and slots from the arm's `SysL ∧ SymL`, its end `BlkOK`, and a footprint with no table word that keeps every `OS` word. -/ @@ -111,7 +111,9 @@ theorem ArmQI.ofW {Ω Sg Scs Vc' Ub Pt : Set U64} {Z : U64 → Nat} {W : U64 → (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : ArmQI st H Cs OS Vc ia ie s s' := - (ArmQIAt.ofW hvr w hW k hS hb).toQI + have ht := tab_of_w hvr w hW + ⟨H, OS, hS.1, hS.2, ⟨Ac', hb⟩, fun h => CapInv.keepO h k, PoolOff.ofTab w.1 ht, PoolNamed.ofTab w.1 ht k, + fun _ => PoolIdx.ofTab w.1 ht k⟩ /-- **`TabKeep` from a footprint with no table word** (MdbArmTab's `tab_of_w`). -/ theorem TabKeep.ofW {Ω Sg Scs Vc' Ub' Pt' : Set U64} {Z : U64 → Nat} {W : U64 → Prop} {s s' : S} @@ -125,9 +127,9 @@ theorem ArmQIAt.ofWK {Ω Sg Scs Vc' Ub Pt : Set U64} {Z : U64 → Nat} {W : U64 (hvr : VrOK Ω Sg Scs Z OS Vc' Ub (L.ksb s) Pt) (w : WritesIn st s s' W) (hW : ∀ b, W b → ¬ AsW (L.ksb s) b) (k : OSKeep st OS s s') (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') - (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' := - ⟨ArmQIAt.ofW hvr w hW k hS hb, TabKeep.ofW hvr w hW⟩ + (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') + (hV : ArmVs st H OS Vc s s') : ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' := + ⟨ArmQIAt.ofW hvr w hW k hS hb hV, TabKeep.ofW hvr w hW⟩ /-- (gen 143) **`ArmQI.ofW` with the table frame exported**: the same hypotheses give `ArmQI ∧ TabKeep`. -/ theorem ArmQI.ofWK {Ω Sg Scs Vc' Ub Pt : Set U64} {Z : U64 → Nat} {W : U64 → Prop} {Ac' : Set U64} {s s' : S} @@ -136,7 +138,7 @@ theorem ArmQI.ofWK {Ω Sg Scs Vc' Ub Pt : Set U64} {Z : U64 → Nat} {W : U64 (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' := - (fun h => ⟨h.1.toQI, h.2⟩) (ArmQIAt.ofWK hvr w hW k hS hb) + ⟨ArmQI.ofW hvr w hW k hS hb, TabKeep.ofW hvr w hW⟩ end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbArmVs.lean b/proofs/Fl4ProofsA64/P1/MdbArmVs.lean new file mode 100644 index 000000000..fac3472c9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/MdbArmVs.lean @@ -0,0 +1,187 @@ +/- +P1 (aarch64, A64-S1A gen 27, Architect 20:56Z ruling item S1A-b (i)): **the memory-frame clause for `ArmQIAt`** +(designed once, for R2's `VsLk` and R3's `HiCap511` / `hvs` / `TeH` / `KtOut`; the field itself is added to MdbPoolA's +`ArmQIAt` in gen 28, once every producer proves it — adding it now would leave the unconverted producers red). + +`ArmQIAt` has no ghost VSpace set, so the clause quantifies over every `(Ub, Pt)` that the decode's state places +(`VrOK` at the decode's state block base, with `FrUb`: every non-device frame of an `OS` cap has its words in +`Ub`). S1A instantiates it at its own `DelIn` `(Ub, Pt)` (`DelIn.del.vr`, `DelIn.fu`). The words it speaks of are +`VsR kb Pt`: every page-table / root / pool word of `Pt` (the reachable tables, every `HighVSpace` root's +`R + 4088` word and the ASID pools are `Pt` objects) and the ASID-table words `AsW`. + +* **`VsWr st OS kb s0 s b`** (the exact VSpace edit records; all of them read the arm's end `s`, the cap sources + read the decode's state `s0`): + * `zero` — the word is `0` at `s` (Page / PageTable Unmap's clear, PageTable Unmap's `zero(ptr, 4096)`, the + deletion family's finalisers); + * `af` — the word differs from `s0` at most in the access flag `D_AF = 1 <<< 10` (TestAndClearAccessed's + `fetch_and(pte, !D_AF)`, vspace.rs:970); + * `leaf` — the word's output address (`vspace.ADDR_MASK` or `ept.ADDR_MASK`, from `PPTR_BASE`, **`DescTo`**) is + the object of a `Frame` cap of `OS` at `s0` (Page Map, Stage 1, high and Stage 2); + * `tab` — the word's output address is an object `q` that an `OS` slot held as an unmapped `PageTable` / `Ept` + cap at `s0` and holds as the mapped cap at `s` (PageTable Map, Stage 1, high and Stage 2); + * `pool` — an ASID-table word `AsW kb b` naming the object of an `AsidPool` cap of `OS` at `s`, whose 4 KiB are + zero at `s` (ASIDControl MakePool: `clear_free`, then `set_asid_table`). +* **`ArmVs st H OS Vc s0 s`** (the clause): the block base kept, and for every placed `(Ub, Pt)` every `VsR` word + kept or a `VsWr` word. Non-VSpace arms prove the first disjunct throughout (**`ArmVsK`**, `ArmVsK.toVs`); the + consumer reads it by **`ArmVs.get`** / **`ArmVsK.vsKeep`** (instantiated `VsKeep`). +* Algebra for the producers: **`ArmVs.refl`**, **`ArmVsK.refl`**, **`ArmVsK.trans`**, **`ArmVsK.ofW`** (a footprint + missing every placed `VsR` word, the shape of every non-VSpace arm), **`ArmVsK.ofWA`** (its `¬ AsW` / `¬ PtW` + halves apart), **`ArmVs.keepL`** (a keeping step with + `OSKeep` before a VSpace step: the restart), **`ArmVs.keepR`** (one after it: the reply). + +Named premises: none. Case facts: none (definitions and their algebra). +-/ +import Fl4ProofsA64.P1.MdbPtCapA +import Fl4ProofsA64.P1.MdbFrUb +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 + +variable {H : Heap} {OS Vc : Set U64} + +/-! ## The clause -/ + +/-- **A descriptor's output address is `q`** (Stage-1 or Stage-2 address mask, from `PPTR_BASE`). -/ +def DescTo (v q : U64) : Prop := + wa (v &&& vspace.ADDR_MASK) layout.PPTR_BASE = q ∨ wa (v &&& ept.ADDR_MASK) layout.PPTR_BASE = q + +variable (st) in +/-- **The exact VSpace edit records** of a `VsR` word `b` from `s0` to `s` (module docstring). -/ +def VsWr (OS : Set U64) (kb : U64) (s0 s : S) (b : U64) : Prop := + L.mem s b = 0#u64 ∨ + (L.mem s b ||| 1024#u64) = (L.mem s0 b ||| 1024#u64) ∨ + (∃ y ∈ OS, ∃ p sz r d m e a v, capA st s0 y = .Frame p sz r d m e a v ∧ DescTo (L.mem s b) p) ∨ + (∃ y ∈ OS, ∃ q, ((∃ a v, capA st s0 y = .PageTable q false a v) ∧ (∃ a v, capA st s y = .PageTable q true a v) ∨ + ∃ l, (∃ a v, capA st s0 y = .Ept q l false a v) ∧ (∃ a v, capA st s y = .Ept q l true a v)) ∧ + DescTo (L.mem s b) q) ∨ + (AsW kb b ∧ ∃ y ∈ OS, ∃ base, capA st s y = .AsidPool (L.mem s b) base ∧ + ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s (wa (L.mem s b) o) = 0#u64) + +variable (st) in +/-- **The memory-frame clause** (module docstring): every placed `VsR` word kept or a `VsWr` word. -/ +def ArmVs (H : Heap) (OS Vc : Set U64) (s0 s : S) : Prop := + L.ksb s = L.ksb s0 ∧ ∀ Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → FrUb st Ub OS s0 → + ∀ b, VsR (L.ksb s0) Pt b → L.mem s b = L.mem s0 b ∨ VsWr st OS (L.ksb s0) s0 s b + +variable (st) in +/-- **The keeping form** (the non-VSpace arms): every placed `VsR` word kept. -/ +def ArmVsK (H : Heap) (OS Vc : Set U64) (s0 s : S) : Prop := + L.ksb s = L.ksb s0 ∧ ∀ Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → FrUb st Ub OS s0 → + VsKeep st (L.ksb s0) Pt s0 s + +/-! ## Consumers -/ + +/-- **The clause at a placed `(Ub, Pt)`.** -/ +theorem ArmVs.get {s0 s : S} (h : ArmVs st H OS Vc s0 s) {Ub Pt : Set U64} + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt) (hf : FrUb st Ub OS s0) {b : U64} + (hb : VsR (L.ksb s0) Pt b) : L.mem s b = L.mem s0 b ∨ VsWr st OS (L.ksb s0) s0 s b := + h.2 Ub Pt hvr hf b hb + +/-- **The keeping form at a placed `(Ub, Pt)`**: a `VsKeep` step. -/ +theorem ArmVsK.vsKeep {s0 s : S} (h : ArmVsK st H OS Vc s0 s) {Ub Pt : Set U64} + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt) (hf : FrUb st Ub OS s0) : + VsKeep st (L.ksb s0) Pt s0 s := + h.2 Ub Pt hvr hf + +/-! ## Producers -/ + +theorem ArmVsK.toVs {s0 s : S} (h : ArmVsK st H OS Vc s0 s) : ArmVs st H OS Vc s0 s := + ⟨h.1, fun Ub Pt hvr hf b hb => Or.inl (h.2 Ub Pt hvr hf b hb)⟩ + +theorem ArmVsK.refl (s : S) : ArmVsK st H OS Vc s s := ⟨rfl, fun _ _ _ _ => VsKeep.refl s⟩ + +theorem ArmVs.refl (s : S) : ArmVs st H OS Vc s s := (ArmVsK.refl s).toVs + +/-- Two keeping steps, the second with the caps of `OS` (so the placement carries). -/ +theorem ArmVsK.trans {s1 s2 s3 : S} (h1 : ArmVsK st H OS Vc s1 s2) (k : OSKeep 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 (CapInv.keepO hf k) + rw [h1.1] at k2 + exact (h1.2 Ub Pt hvr hf).trans k2 + +/-- **A footprint missing every placed `VsR` word** is a keeping step (`VsKeep.of_w`, `VrOK.al`). -/ +theorem ArmVsK.ofW {s0 s : S} {W : U64 → Prop} (w : WritesIn st s0 s W) + (hW : ∀ Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → FrUb st Ub OS s0 → + ∀ b, W b → ¬ VsR (L.ksb s0) Pt b) : ArmVsK st H OS Vc s0 s := + ⟨w.1, fun Ub Pt hvr hf => VsKeep.of_w hvr.al w fun b hb hw => hW Ub Pt hvr hf b hw hb⟩ + +/-- **`ofW` with the two halves of `VsR` apart**: the footprint's `¬ AsW` (state-independent of the placement) and +its `¬ PtW` at every placement. -/ +theorem ArmVsK.ofWA {s0 s : S} {W : U64 → Prop} (w : WritesIn st s0 s W) + (hA : ∀ b, W b → ¬ AsW (L.ksb s0) b) + (hP : ∀ Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → FrUb st Ub OS s0 → + ∀ b, W b → ¬ PtW Pt b) : ArmVsK st H OS Vc s0 s := + ArmVsK.ofW w fun Ub Pt hvr hf b hw hv => hv.elim (hP Ub Pt hvr hf b hw) (hA b hw) + +/-- `VsWr` read back through a step keeping the caps of `OS` before it and the `VsR` word itself. -/ +theorem VsWr.keepL {kb b : U64} {s0 s1 s : S} (k : OSKeep st OS s0 s1) (hb : L.mem s1 b = L.mem s0 b) + (h : VsWr st OS kb s1 s b) : VsWr st OS kb s0 s b := by + rcases h with h | h | ⟨y, hy, p, sz, r, d, m, e, a, v, hc, ht⟩ | ⟨y, hy, q, hq, ht⟩ | h + · exact Or.inl h + · exact Or.inr (Or.inl (by rw [h, hb])) + · exact Or.inr (Or.inr (Or.inl ⟨y, hy, p, sz, r, d, m, e, a, v, by rw [← k.capA hy]; exact hc, ht⟩)) + · refine Or.inr (Or.inr (Or.inr (Or.inl ⟨y, hy, q, ?_, ht⟩))) + rw [← k.capA hy]; exact hq + · exact Or.inr (Or.inr (Or.inr (Or.inr h))) + +/-- **A keeping step with the caps of `OS`, then a VSpace step** (the caller's restart, then the arm's write). -/ +theorem ArmVs.keepL {s0 s1 s : S} (h1 : ArmVsK st H OS Vc s0 s1) (k : OSKeep st OS s0 s1) + (h2 : ArmVs st H OS Vc s1 s) : ArmVs st H OS Vc s0 s := by + refine ⟨h2.1.trans h1.1, fun Ub Pt hvr hf b hb => ?_⟩ + have hvr1 : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s1) Pt := by rw [h1.1]; exact hvr + have e1 := h1.2 Ub Pt hvr hf b hb + rw [← h1.1] at hb + rcases h2.2 Ub Pt hvr1 (CapInv.keepO hf k) b hb with e | w + · exact Or.inl (e.trans e1) + · rw [h1.1] at w + exact Or.inr (w.keepL k e1) + +/-- `VsWr` carried through a later step keeping the caps of `OS`, the `VsR` word and the words of every pool +named by an `AsidPool` cap of `OS`. -/ +theorem VsWr.keepR {kb b : U64} {s0 s s' : S} (k : OSKeep st OS s s') (hb : L.mem s' b = L.mem s b) + (hP : ∀ y ∈ OS, ∀ p base, capA st s y = .AsidPool p base → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + (h : VsWr st OS kb s0 s b) : VsWr st OS kb s0 s' b := by + rcases h with h | h | ⟨y, hy, p, sz, r, d, m, e, a, v, hc, ht⟩ | ⟨y, hy, q, hq, ht⟩ | ⟨ha, y, hy, base, hc, hz⟩ + · exact Or.inl (by rw [hb, h]) + · exact Or.inr (Or.inl (by rw [hb, h])) + · exact Or.inr (Or.inr (Or.inl ⟨y, hy, p, sz, r, d, m, e, a, v, hc, by rw [hb]; exact ht⟩)) + · refine Or.inr (Or.inr (Or.inr (Or.inl ⟨y, hy, q, ?_, by rw [hb]; exact ht⟩))) + rw [k.capA hy]; exact hq + · refine Or.inr (Or.inr (Or.inr (Or.inr ⟨ha, y, hy, base, by rw [k.capA hy, hb]; exact hc, fun o ho h8 => ?_⟩))) + rw [hb, hP y hy _ base hc o ho h8] + exact hz o ho h8 + +/-- **A VSpace step, then a keeping step with the caps of `OS` and the named pools' words** (the reply). The keeping +step is stated at the decode's placement (`hk`), as every footprint argument is. -/ +theorem ArmVs.keepR {s0 s s' : S} (h1 : ArmVs st H OS Vc s0 s) (k : OSKeep st OS s s') + (hk : L.ksb s' = L.ksb s) + (h2 : ∀ Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → FrUb st Ub OS s0 → + VsKeep st (L.ksb s0) Pt s s') + (hP : ∀ y ∈ OS, ∀ p base, capA st s y = .AsidPool p base → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) : ArmVs st H OS Vc s0 s' := by + refine ⟨hk.trans h1.1, fun Ub Pt hvr hf b hb => ?_⟩ + have e2 := h2 Ub Pt hvr hf b hb + rcases h1.2 Ub Pt hvr hf b hb with e | w + · exact Or.inl (e2.trans e) + · exact Or.inr (w.keepR k e2 hP) + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/MdbArmVsF.lean b/proofs/Fl4ProofsA64/P1/MdbArmVsF.lean new file mode 100644 index 000000000..ec44dc43a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/MdbArmVsF.lean @@ -0,0 +1,123 @@ +/- +P1 (aarch64, A64-S1A gen 27, Architect 20:56Z ruling item S1A-b (i)): **MdbArmVs's clause for the first producer +batch — the cap-free decode frame `DF`** (MdbLiveX), shared by the six DF arms of `ArmQIAt.ofDFK` (MdbArmDf: Domain, +IRQ Ack, SetTLSBase, SetPACKeys, SetFlags, VCPU ReadReg). + +* **`DfW.notPtW`**: no `DfW` word is a `Pt` word of any `VrOK` placement of the decode's state: a `Pt` word lies in + `Ω` (`VrOK.om`), hence outside every TCB and node (`SchedQueuesInvX.omega`, QueueCallers' `out_ne_field` / + `out_ne_node`), outside `Sg` (`VrOK.sg`) and off the low state-block words (`VrOK.ks`). +* (`DM`, the three DM arms of `ArmQIAt.ofDMK`: UnbindNotification, SC Unbind / UnbindObject, SC Consumed) + **`omega_obj_frame`** (an `Ω` word inside a TCB / endpoint / notification object is a notification frame word), + **`DmW.notPtW`** (also SC words by `VrOK.sc`, endpoint / notification head and tail words by `omega_obj_frame`). +* **`ArmVsK.ofDF`**, **`ArmVsK.ofDM`** (by MdbArmVs's `ArmVsK.ofWA`): the ASID-table half is the footprint's + existing `¬ AsW` proof (`DfW.notAsW`, `K8.KW.notAsWE`), passed in, so this module sits upstream of MdbArmDf / + MdbArmDm and gen 28 adds `(ArmVsK.ofDF … (fun b hd => DfW.notAsW …)).toVs` to `ArmQIAt.ofDFK` / `ofDMK` with the + field (no producer statement or proof touched: the nine tops go through those two). + +Named premises: none. Case facts: none (the hypotheses are `ofDFK` / `ofDMK`'s own: `DecPre`'s queues, `HeapOK`). +-/ +import Fl4ProofsA64.P1.MdbArmVs +import Fl4ProofsA64.P1.MdbDfM +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} {Cs : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +variable {OS Vc : Set U64} + +/-- **No `DfW` word is a placed `Pt` word** (module docstring). -/ +theorem DfW.notPtW {Ko : Set Nat} {Vc' Ub Pt X : Set U64} {Q : U64 → U64 → List U64} {Rq : U64 → List U64} + {s0 : S} (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s0 Q Rq) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s0) Pt) {b : U64} + (h : DfW st H.tcbs Cs H.frame H.scBits Ko s0 b) : ¬ PtW Pt b := fun hp => by + have hO := q.omega b (hvr.om b (Or.inl hp)) + rcases h with (⟨y, hy, K, -, hK, -, -, e⟩ | ⟨c, hc, o, ho, -, e⟩ | h | ⟨c, hc, -⟩ | ⟨e0, he, -⟩) | + ⟨o, -, hl, -, e⟩ + · exact out_ne_field hO hy (q.tcbs y hy) hK (by rw [e]) + · exact out_ne_node hO hc (q.nodes c hc) ho (by rw [e]) + · exact hvr.sg b (Or.inl hp) h + · exact absurd hc (Set.notMem_empty c) + · exact absurd he (Set.notMem_empty e0) + · exact hvr.ks b (Or.inl hp) o (by omega) e.symm + +/-- **A `DF` step keeps every placed `VsR` word**, given its footprint's `¬ AsW` (module docstring). -/ +theorem ArmVsK.ofDF {Ko : Set Nat} {X : Set U64} {Q : U64 → U64 → List U64} {Rq : U64 → List U64} {c : U64} + {s0 s : S} (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s0 Q Rq) (d : DF st H Cs c Ko s0 s) + (hA : ∀ b, DfW st H.tcbs Cs H.frame H.scBits Ko s0 b → ¬ AsW (L.ksb s0) b) : ArmVsK st H OS Vc s0 s := + ArmVsK.ofWA d.w hA fun _ _ hvr _ _ hd => DfW.notPtW q hvr hd + +/-! ## The `DM` footprint -/ + +/-- **An `Ω` word inside a TCB, endpoint or notification object is a frame word** (a notification's frame words; +`HeapOK.disj` for every other object). -/ +theorem omega_obj_frame (hH : HeapOK H) {e b : U64} {k : HKind} (he : H e = some k) + (hk : k = .tcb ∨ k = .ep ∨ k = .ntfn) (h1 : e.val ≤ b.val) (h2 : b.val < e.val + 2 ^ k.bits) + (hb : b ∈ H.omega) : b ∈ H.frame := by + obtain ⟨ha, p, k', hp, hk', hin⟩ := hb + by_cases hpe : p = e + · rw [hpe] at hp hin hk' + rw [he] at hp + obtain rfl := Option.some.inj hp + rcases hk' with rfl | ⟨z, rfl⟩ | ⟨z, rfl⟩ | ⟨rfl, hw⟩ + · rcases hk with h | h | h <;> cases h + · rcases hk with h | h | h <;> cases h + · rcases hk with h | h | h <;> cases h + · exact ⟨ha, e, .ntfn, he, Or.inr (Or.inr ⟨rfl, hw⟩), hin⟩ + · exfalso + have d := hH.disj p k' e k hp he hpe + simp only [InObj] at hin + omega + +/-- (gen 28) **No `K8.KW` word with endpoints and notifications is a placed `Pt` word** (TCB / node words by +`out_ne_field` / `out_ne_node`, `Sg` and SC words by `VrOK.sg` / `.sc`, endpoint / notification head and tail words +by `omega_obj_frame`). -/ +theorem K8.KW.notPtWE {Vc' Ub Pt X : Set U64} {Q : U64 → U64 → List U64} {Rq : U64 → List U64} + {s0 : S} (hH : HeapOK H) (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s0 Q Rq) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s0) Pt) {b : U64} + (h : K8.KW st H.tcbs Cs H.frame H.scs H.scBits (EH H) s0 b) : ¬ PtW Pt b := by + intro hp + have hO := q.omega b (hvr.om b (Or.inl hp)) + rcases h with ⟨y, hy, K, -, hK, -, -, e⟩ | ⟨c, hc, o, ho, -, e⟩ | h | ⟨c, hc, h⟩ | ⟨e0, he, e⟩ + · exact out_ne_field hO hy (q.tcbs y hy) hK (by rw [e]) + · exact out_ne_node hO hc (q.nodes c hc) ho (by rw [e]) + · exact hvr.sg b (Or.inl hp) h + · exact hvr.sc b (Or.inl hp) c hc h + · obtain ⟨k, hk, hkk, h16⟩ : ∃ k, H e0 = some k ∧ (k = .tcb ∨ k = .ep ∨ k = .ntfn) ∧ 16 ≤ 2 ^ k.bits := by + rcases he with g | g + · exact ⟨_, g, Or.inr (Or.inl rfl), by simp [HKind.bits]⟩ + · exact ⟨_, g, Or.inr (Or.inr rfl), by simp [HKind.bits]⟩ + have hf := hH.fits e0 _ hk + have hv : b.val = e0.val ∨ b.val = e0.val + 8 := by + rcases e with e | e <;> rw [e] <;> simp only [epHeadA, epTSA, layout.ep.HEAD, layout.ep.TAIL_STATE] <;> + rw [wadd_val (by simp; omega)] <;> simp + exact hvr.sg b (Or.inl hp) (omega_obj_frame hH hk hkk (by omega) (by omega) (hvr.om b (Or.inl hp))) + +/-- **No `DmW` word is a placed `Pt` word** (module docstring). -/ +theorem DmW.notPtW {Vc' Ub Pt X : Set U64} {Q : U64 → U64 → List U64} {Rq : U64 → List U64} + {s0 : S} (hH : HeapOK H) (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s0 Q Rq) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s0) Pt) {b : U64} + (h : DmW st H Cs s0 b) : ¬ PtW Pt b := + Or.elim h (DfW.notPtW q hvr) (K8.KW.notPtWE hH q hvr) + +/-- **A `DmW` step keeps every placed `VsR` word**, given its footprint's `¬ AsW` (module docstring). -/ +theorem ArmVsK.ofDM {X : Set U64} {Q : U64 → U64 → List U64} {Rq : U64 → List U64} {s0 s : S} (hH : HeapOK H) + (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s0 Q Rq) (w : WritesIn st s0 s (DmW st H Cs s0)) + (hA : ∀ b, DmW st H Cs s0 b → ¬ AsW (L.ksb s0) b) : ArmVsK st H OS Vc s0 s := + ArmVsK.ofWA w hA fun _ _ hvr _ _ hd => DmW.notPtW hH q hvr hd + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/MdbArmVsG.lean b/proofs/Fl4ProofsA64/P1/MdbArmVsG.lean new file mode 100644 index 000000000..73090ea6c --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/MdbArmVsG.lean @@ -0,0 +1,190 @@ +/- +P1 (aarch64, A64-S1A gen 28, Architect 21:25Z ruling item 1): **MdbArmVs's clause for the remaining non-VSpace +footprints** — the TCB-side words of the Run / VCPU family, Suspend / SetSchedParams, IRQ control and the IPC +senders, and (FrBw finding, approved) the buffer words as the object of a non-device `Frame` cap of an `OS` slot. + +* **`TkW st H Cs Vc s0`** (the union the non-VSpace footprints sit in, beside MdbLiveX's `DfW`): a `K8.KW` word with + endpoints and notifications (`EH H`), a QueueIpc `DbgW` word, a VCPU word `VcW Vc`, or any TCB field word + `wa y K` (`K < 4096`: the `RUN_VCPU` word 3672 of `SusW`, the bound-VCPU word 3664 of `RunB`, …). + **`TkW.notPtW`**: none is a placed `Pt` word (MdbArmVsF's `K8.KW.notPtWE`, `out_ne_field` / `out_ne_node` + through `VrOK.om`, `VrOK.vc`). +* **`FrCw st OS s0 b`** (A64-S1A gen 30: the def and `FrCw.keepO` moved to MdbFpuL, beside `FrBw`, for the + producers' export): `b` lies in the object of a non-device `Frame` cap held by an `OS` slot at `s0` (the IPC + buffer / ReadFPU / VCPU-state frame; FL4's `lookup_ipc_buffer` returns `0` for a device frame, msg.rs:28–34). + **`FrCw.notVsR`**: such a word is no placed `VsR` word (`FrUb` puts its aligned words in `Ub`, `VrOK.ub`; an + unaligned word is no `VsR` word, `VrOK.al`). +* **`ArmVsK.ofFoot`**: a step whose footprint sits in `DfW ∨ TkW ∨ FrCw` (at its start) keeps every placed `VsR` + word, given the footprint's `¬ AsW` (passed in, as `ArmVsK.ofDF`). + +Named premises: none. Case facts: none (the hypotheses are the producers' own: `DecPre` / `BlkOK` queues, +`HeapOK`). +-/ +import Fl4ProofsA64.P1.MdbArmVsF +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} {Cs : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +variable {OS Vc : Set U64} + +variable (st) in +/-- **The TCB-side words of the non-VSpace footprints** (module docstring). -/ +def TkW (H : Heap) (Cs Vc : Set U64) (s0 : S) (b : U64) : Prop := + K8.KW st H.tcbs Cs H.frame H.scs H.scBits (EH H) s0 b ∨ DbgW st H.tcbs Cs s0 b ∨ VcW Vc b ∨ + ∃ y ∈ H.tcbs, ∃ K : U64, K.val < 4096 ∧ b = wa y K + +/-- **No `TkW` word is a placed `Pt` word** (module docstring). -/ +theorem TkW.notPtW {Ub Pt X : Set U64} {Q : U64 → U64 → List U64} {Rq : U64 → List U64} {s0 : S} + (hH : HeapOK H) (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s0 Q Rq) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt) {b : U64} + (h : TkW st H Cs Vc s0 b) : ¬ PtW Pt b := by + rcases h with h | h | h | ⟨y, hy, K, hK, e⟩ + · exact K8.KW.notPtWE hH q hvr h + · intro hp + have hO := q.omega b (hvr.om b (Or.inl hp)) + rcases h with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ + · exact out_ne_field hO hy (q.tcbs y hy) (K := 3576#u64) (by simp) (by rw [e]; rfl) + · exact out_ne_field hO hy (q.tcbs y hy) (K := 3584#u64) (by simp) (by rw [e]; rfl) + · exact out_ne_node hO hc (q.nodes c hc) (by rw [debug_val]; omega) (by rw [e]) + · exact fun hp => hvr.vc b (Or.inl hp) h + · intro hp + exact out_ne_field (q.omega b (hvr.om b (Or.inl hp))) hy (q.tcbs y hy) hK (by rw [e]) + +/-- **No `FrCw` word is a placed `VsR` word** (module docstring). -/ +theorem FrCw.notVsR {Ub Pt : Set U64} {kb : U64} {s0 : S} + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub kb Pt) (hf : FrUb st Ub OS s0) {b : U64} + (h : FrCw st OS s0 b) : ¬ VsR kb Pt b := fun hv => by + obtain ⟨y, hy, ptr, size, rights, x1, x2, x3, x4, bits, hc, hb, h1, h2⟩ := h + exact hvr.ub b hv (hf y hy ptr size rights x1 x2 x3 x4 hc bits hb b (hvr.al b hv) h1 h2) + +/-- **A footprint inside `DfW ∨ TkW ∨ FrCw` keeps every placed `VsR` word**, given its `¬ AsW` (module docstring). -/ +theorem ArmVsK.ofFoot {Ko : Set Nat} {X : Set U64} {Q : U64 → U64 → List U64} {Rq : U64 → List U64} + {W : U64 → Prop} {s0 s : S} (hH : HeapOK H) (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s0 Q Rq) + (w : WritesIn st s0 s W) + (hW : ∀ b, W b → DfW st H.tcbs Cs H.frame H.scBits Ko s0 b ∨ TkW st H Cs Vc s0 b ∨ FrCw st OS s0 b) + (hA : ∀ b, W b → ¬ AsW (L.ksb s0) b) : ArmVsK st H OS Vc s0 s := + ArmVsK.ofW w fun _ _ hvr hf b hb hv => by + rcases hW b hb with h | h | h + · exact Or.elim hv (DfW.notPtW q hvr h) (hA b hb) + · exact Or.elim hv (TkW.notPtW hH q hvr h) (hA b hb) + · exact FrCw.notVsR hvr hf h hv + +/-! ## The zero records (`VsWr.zero`): Page / PageTable Unmap -/ + +variable (st) in +/-- **The zero form of the clause**: every placed `VsR` word kept or `0` (the unmapping arms; `ArmVsZ.toVs`). -/ +def ArmVsZ (H : Heap) (OS Vc : Set U64) (s0 s : S) : Prop := + L.ksb s = L.ksb s0 ∧ ∀ Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → FrUb st Ub OS s0 → + ∀ b, VsR (L.ksb s0) Pt b → L.mem s b = L.mem s0 b ∨ L.mem s b = 0#u64 + +theorem ArmVsZ.toVs {s0 s : S} (h : ArmVsZ st H OS Vc s0 s) : ArmVs st H OS Vc s0 s := + ⟨h.1, fun Ub Pt hvr hf b hb => (h.2 Ub Pt hvr hf b hb).imp id fun e => Or.inl e⟩ + +theorem ArmVsK.toZ {s0 s : S} (h : ArmVsK st H OS Vc s0 s) : ArmVsZ st H OS Vc s0 s := + ⟨h.1, fun Ub Pt hvr hf b hb => Or.inl (h.2 Ub Pt hvr hf b hb)⟩ + +/-- Two zero steps, the second with every placement's `FrUb` carried (e.g. `OSKeep`, `CapInv.keepO`). -/ +theorem ArmVsZ.trans {s1 s2 s3 : S} (h1 : ArmVsZ st H OS Vc s1 s2) + (hF : ∀ Ub, FrUb st Ub OS s1 → FrUb st Ub OS s2) (h2 : ArmVsZ st H OS Vc s2 s3) : + ArmVsZ st H OS Vc s1 s3 := by + refine ⟨h2.1.trans h1.1, fun Ub Pt hvr hf b hb => ?_⟩ + 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 hb2 : VsR (L.ksb s2) Pt b := by rw [h1.1]; exact hb + rcases h2.2 Ub Pt hvr2 (hF Ub hf) b hb2 with e | e + · rw [e]; exact h1.2 Ub Pt hvr hf b hb + · exact Or.inr e + +/-- **A zero stretch, then a step writing only `OS` slot words** (the in-place cap write closing an unmapping). -/ +theorem ArmVsZ.thenOS {s0 s1 s2 : S} {W : U64 → Prop} (h : ArmVsZ st H OS Vc s0 s1) (w : WritesIn st s1 s2 W) + (hW : ∀ b, W b → InOS OS b) : ArmVsZ st H OS Vc s0 s2 := by + refine ⟨w.1.trans h.1, fun Ub Pt hvr hf b hb => ?_⟩ + have e : L.mem s2 b = L.mem s1 b := + w.2.2 b (hvr.al b hb) fun hw => hvr.os b hb (hW b hw) + rw [e]; exact h.2 Ub Pt hvr hf b hb + +variable (st) in +/-- **Every `PtW Pt0` word kept or `0`** (the carry of the unmapping walks over the decode's own table set). -/ +def PtZ (Pt0 : Set U64) (s0 s : S) : Prop := + ∀ b, PtW Pt0 b → L.mem s b = L.mem s0 b ∨ L.mem s b = 0#u64 + +theorem PtZ.refl {Pt0 : Set U64} (s : S) : PtZ st Pt0 s s := fun _ _ => Or.inl rfl + +theorem PtZ.trans {Pt0 : Set U64} {s1 s2 s3 : S} (h1 : PtZ st Pt0 s1 s2) (h2 : PtZ st Pt0 s2 s3) : + PtZ st Pt0 s1 s3 := fun b hb => by + rcases h2 b hb with e | e + · rw [e]; exact h1 b hb + · exact Or.inr e + +/-- A step keeping the `VsR` words is a `PtZ` step (the caller's restart, `vsk_sts`). -/ +theorem PtZ.ofKeep {Pt0 : Set U64} {kb : U64} {s s' : S} (h : VsKeep st kb Pt0 s s') : PtZ st Pt0 s s' := + fun b hb => Or.inl (h b (Or.inl hb)) + +/-- A QueueVsTy `Wr0` step (one zero write into a `PtW Pt0` word) is a `PtZ` step. -/ +theorem PtZ.wr0 {Pt0 : Set U64} {s s' : S} (hal : ∀ b, PtW Pt0 b → Aligned b) (h : Wr0 st Pt0 s s') : + PtZ st Pt0 s s' := by + rcases h with rfl | ⟨b0, hb0, rfl⟩ + · exact PtZ.refl _ + · intro b hb + by_cases e : b = b0 + · subst e; exact Or.inr (L.mem_wr_same (hal b hb)) + · exact Or.inl (L.mem_wr_ne (hal b0 hb0) (hal b hb) fun hv => e (UScalar.eq_of_val_eq hv).symm) + +/-- `zero(p, 4096)` (not wrapping) is a `PtZ` step. -/ +theorem PtZ.zr {Pt0 : Set U64} {s : S} {p : U64} (hal : ∀ b, PtW Pt0 b → Aligned b) (ha : Aligned p) + (hw : p.val + 4096 ≤ 2 ^ 64) : PtZ st Pt0 s (L.zr s p 4096#u64) := fun b hb => by + have h4096 : (4096#u64).val % 8 = 0 := by simp + have hw' : p.val + (4096#u64).val ≤ 2 ^ 64 := by simpa using hw + rw [L.mem_zr _ _ _ _ ha h4096 hw' (hal b hb)] + split + · exact Or.inr rfl + · exact Or.inl rfl + +/-- **A DFB step over `PtW Pt0` whose `PtW Pt0` words are kept or zeroed is a zero step at every placement** +(`DfW.notPtW`, its `¬ AsW` passed in). -/ +theorem ArmVsZ.ofDZ {Ko : Set Nat} {X Pt0 : Set U64} {Q : U64 → U64 → List U64} {Rq : U64 → List U64} + {s0 s : S} (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s0 Q Rq) + (w : WritesIn st s0 s (fun b => DfW st H.tcbs Cs H.frame H.scBits Ko s0 b ∨ PtW Pt0 b)) + (hA : ∀ b, DfW st H.tcbs Cs H.frame H.scBits Ko s0 b → ¬ AsW (L.ksb s0) b) + (Z : PtZ st Pt0 s0 s) : ArmVsZ st H OS Vc s0 s := by + refine ⟨w.1, fun Ub Pt hvr _ b hb => ?_⟩ + by_cases hw : DfW st H.tcbs Cs H.frame H.scBits Ko s0 b ∨ PtW Pt0 b + · rcases hw with hd | hp + · exact absurd hb fun hv => Or.elim hv (DfW.notPtW q hvr hd) (hA b hd) + · exact Z b hp + · exact Or.inl (w.2.2 b (hvr.al b hb) hw) + +/-! ## The access-flag record (`VsWr.af`): TestAndClearAccessed -/ + +/-- Clearing then setting a mask's bits is setting them. -/ +theorem andn_or_self (v m : U64) : ((v &&& ~~~ m) ||| m) = (v ||| m) := by + rw [UScalar.eq_equiv_bv_eq] + apply BitVec.eq_of_getLsbD_eq; intro i + simp only [UScalar.bv_and, UScalar.bv_or, UScalar.bv_not, BitVec.getLsbD_and, BitVec.getLsbD_or, + BitVec.getLsbD_not] + cases v.bv.getLsbD i <;> cases m.bv.getLsbD i <;> simp + +/-- **TestAndClearAccessed's `fetch_and(pte, !D_AF)`** (vspace.rs:970) is an `af` step at every placement. -/ +theorem ArmVs.ofAf {s : S} {x : U64} (hal : Aligned x) : + ArmVs st H OS Vc s (L.wr s x (L.mem s x &&& ~~~1024#u64)) := by + refine ⟨L.ksb_wr _ _ _, fun Ub Pt hvr _ b hb => ?_⟩ + by_cases e : b = x + · subst e + exact Or.inr (Or.inr (Or.inl (by rw [L.mem_wr_same hal, andn_or_self]))) + · exact Or.inl (L.mem_wr_ne hal (hvr.al b hb) fun hv => e (UScalar.eq_of_val_eq hv).symm) + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/MdbArmVsV.lean b/proofs/Fl4ProofsA64/P1/MdbArmVsV.lean new file mode 100644 index 000000000..364ab17d8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/MdbArmVsV.lean @@ -0,0 +1,258 @@ +/- +P1 (aarch64, A64-S1A gen 30, Architect 22:19Z ruling item 2): **the written values of the VSpace map records** +(MdbArmVs's `leaf` / `tab`: `DescTo v p`, the descriptor's output address is the mapped object). + +* **`nat_or_offM`**, **`nat_small_offM`**: an `|||` with a word that has no bit in `[12, 48)` (`ADDR_MASK`) keeps + the address bits (QueueS2Map's `tb_M`). +* **`paddr_ok`**: the physical address `p - PPTR_BASE` (wrapping) of a canonical 4 KiB-aligned pointer is 4 KiB-aligned + below `2 ^ 48` — both halves: `p ≥ PPTR_BASE` gives `p - PPTR_BASE < 2 ^ 47`, `p < 2 ^ 47` gives `p + 2 ^ 47`. + **`descTo_of`**: a descriptor whose address bits are `p - PPTR_BASE` is `DescTo v p` (the Stage-1 mask; wrapping + `(p - B) + B = p`). +* **`s1page_v`**: `make_user_page x …` (vspace.rs `make_user_page`: `(x & ADDR_MASK) | VALID [| PAGE] | attr idx << 2 + | AP << 6 | SH | AF | nG | PXN [| UXN]`) has the address bits of `x`; **`s1page_desc`** (Page Map's leaf: + `DescTo e p` for `x = paddr p`), **`s1tab_desc`** (PageTable Map's table descriptor, from QueueS1Map's `s1tab_v`). +* MdbVsMapB's **`vspace.install_page.slotE`** (the body of `install_page.ptw`, moved) gives the slot's final value `e`. + +(A64-S1A gen 32, F3) Imports MdbArmVsG (MdbArmVsW dissolved). **`paddr_spec`**, **`paddr_andE`**, **`descTo_ofE`** +(`DescTo`'s `ept.ADDR_MASK` side), **`s2leaf_v`** / **`s2leaf_desc`** (`make_s2_leaf`: `0` or the frame's address +bits), **`s2tab_desc`**; **`ArmVs.ofOne`** (one `VsWr` word, the rest of the footprint off every placed `VsR` word: +TestAndClearAccessed), **`ArmVsZ.thenOne`** (a zero stretch, then one write of a word kept or ending as a `VsWr` +record: the map arms). + +Named premises: none. Case facts: none (the pointer's `Canonical` is the cap's `EncWf`, its alignment the heap's). +-/ +import Fl4ProofsA64.P1.MdbArmVsG +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts + +section + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +namespace W7 +namespace R +namespace ST + +/-! ## Address bits -/ + +/-- **An `|||` with a word off `ADDR_MASK` keeps the address bits** (module docstring). -/ +theorem nat_or_offM (y c : Nat) (hc : c &&& 281474976706560 = 0) : + (y ||| c) &&& 281474976706560 = y &&& 281474976706560 := by + apply Nat.eq_of_testBit_eq + intro i + have h := congrArg (fun n => n.testBit i) hc + simp only [Nat.testBit_and, Nat.zero_testBit] at h + rw [Nat.testBit_and, Nat.testBit_and, Nat.testBit_or] + cases h1 : y.testBit i <;> cases h2 : c.testBit i <;> cases h3 : (281474976706560 : Nat).testBit i <;> + simp_all + +/-- A word below `2 ^ 12` is off `ADDR_MASK`. -/ +theorem nat_small_offM {c : Nat} (h : c < 4096) : c &&& 281474976706560 = 0 := by + apply Nat.eq_of_testBit_eq + intro i + rw [Nat.testBit_and, tb_M i, Nat.zero_testBit] + by_cases hi : 12 ≤ i + · have h' : c < 2 ^ i := lt_of_lt_of_le h (le_trans (by norm_num) (Nat.pow_le_pow_right (by norm_num) hi)) + rw [Nat.testBit_eq_false_of_lt h'] + rfl + · simp [hi] + +/-- **The physical address of a canonical 4 KiB-aligned pointer** (module docstring). -/ +theorem paddr_ok {p : U64} (hp : CapRt.Canonical p) (ha : p.val % 4096 = 0) : + (ws p layout.PPTR_BASE).val % 4096 = 0 ∧ (ws p layout.PPTR_BASE).val < 2 ^ 48 := by + have hc := canon_lt hp + have e : p.bv.toNat = p.val := rfl + have hl := p.bv.isLt + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits] + omega + +/-- The address bits of `p - PPTR_BASE` are itself. -/ +theorem paddr_andM {p : U64} (hp : CapRt.Canonical p) (ha : p.val % 4096 = 0) : + (ws p layout.PPTR_BASE &&& vspace.ADDR_MASK) = ws p layout.PPTR_BASE := by + obtain ⟨h1, h2⟩ := paddr_ok hp ha + exact UScalar.eq_of_val_eq (by rw [UScalar.val_and, vspace.ADDR_MASK.val_eq]; exact nat_and_M h1 h2) + +/-- **A descriptor with the address bits of `p - PPTR_BASE` names `p`** (module docstring). -/ +theorem descTo_of {v p : U64} (hv : (v &&& vspace.ADDR_MASK) = ws p layout.PPTR_BASE) : DescTo v p := by + left + rw [hv] + apply UScalar.eq_of_val_eq + have e : p.bv.toNat = p.val := rfl + have hl := p.bv.isLt + simp [core.num.U64.wrapping_add_val_eq, core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits] + omega + +/-! ## The descriptors -/ + +set_option maxHeartbeats 1000000 in +/-- **`make_user_page x …` keeps the address bits of `x`** (module docstring). -/ +theorem s1page_v (x rights : U64) (cr : Bool) (attr shift : U64) : + vspace.make_user_page x rights cr attr shift ⦃ v => (v &&& vspace.ADDR_MASK) = (x &&& vspace.ADDR_MASK) ⦄ := by + unfold vspace.make_user_page + rw [eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, eq_of_spec_fd P0.Consts.vspace.D_TABLE_OR_PAGE.spec, + eq_of_spec_fd P0.Consts.vspace.D_SH_INNER.spec, eq_of_spec_fd P0.Consts.vspace.D_AF.spec, + eq_of_spec_fd P0.Consts.vspace.D_NG.spec, eq_of_spec_fd P0.Consts.vspace.D_PXN.spec, + eq_of_spec_fd P0.Consts.vspace.D_UXN.spec] + simp only [lift, bind_ok] + refine WP.spec_bind (P0.vspace.exec_never.p0 _ _) fun xn _ => ?_ + refine WP.spec_bind (Pₘ := fun p : U64 × U64 => p.1.val ≤ 1 ∧ p.2.val < 4096) ?_ ?_ + · split <;> exact (WP.spec_ok _).2 ⟨by simp, by decide⟩ + rintro ⟨idx, sh⟩ ⟨hidx, hsh⟩ + change idx.val ≤ 1 at hidx + change sh.val < 4096 at hsh + try dsimp only + refine WP.spec_bind (Pₘ := fun v : U64 => v.val < 4096) ?_ fun i2 hi2 => ?_ + · split <;> exact (WP.spec_ok _).2 (by decide) + have e64 : (2 : Nat) ^ UScalarTy.U64.numBits = 2 ^ 64 := rfl + refine WP.spec_bind (U64.ShiftLeft_spec idx vspace.D_ATTR_SHIFT (by simp)) fun i4 hi4 => ?_ + have h4 : i4.val < 4096 := by + rw [hi4.1] + simp only [vspace.D_ATTR_SHIFT.val_eq, Nat.shiftLeft_eq, U64.size, U64.numBits] + rw [e64] + exact lt_of_le_of_lt (Nat.mod_le _ _) (by have : (2 : Nat) ^ 2 = 4 := rfl; rw [this]; omega) + refine WP.spec_bind (Pₘ := fun v : U64 => v.val < 4) ?_ fun i6 hi6 => ?_ + · unfold vspace.ap_bits + split + · exact (WP.spec_ok _).2 (by decide) + · split <;> exact (WP.spec_ok _).2 (by decide) + refine WP.spec_bind (U64.ShiftLeft_spec i6 vspace.D_AP_SHIFT (by simp)) fun i7 hi7 => ?_ + have h7 : i7.val < 4096 := by + rw [hi7.1] + simp only [vspace.D_AP_SHIFT.val_eq, Nat.shiftLeft_eq, U64.size, U64.numBits] + rw [e64] + exact lt_of_le_of_lt (Nat.mod_le _ _) (by have : (2 : Nat) ^ 6 = 64 := rfl; rw [this]; omega) + refine WP.spec_bind (Pₘ := fun v : U64 => v.val &&& 281474976706560 = 0) ?_ fun i16 hi16 => ?_ + · split <;> exact (WP.spec_ok _).2 (by decide) + refine (WP.spec_ok _).2 (UScalar.eq_of_val_eq ?_) + have c1 : ((1024#u64 : U64).val) = 1024 := rfl + have c2 : ((2048#u64 : U64).val) = 2048 := rfl + have c3 : ((9007199254740992#u64 : U64).val) = 9007199254740992 := rfl + simp only [UScalar.val_and, UScalar.val_or, vspace.ADDR_MASK.val_eq, c1, c2, c3] + rw [nat_or_offM _ _ hi16, nat_or_offM _ _ (by decide), nat_or_offM _ _ (by decide), + nat_or_offM _ _ (by decide), nat_or_offM _ _ (nat_small_offM hsh), nat_or_offM _ _ (nat_small_offM h7), + nat_or_offM _ _ (nat_small_offM h4), nat_or_offM _ _ (nat_small_offM hi2), Nat.and_assoc, Nat.and_self] + +/-- **Page Map's leaf descriptor names the frame** (module docstring). -/ +theorem s1page_desc {p : U64} (hp : CapRt.Canonical p) (ha : p.val % 4096 = 0) (rights : U64) (cr : Bool) + (attr shift : U64) : + vspace.make_user_page (ws p layout.PPTR_BASE) rights cr attr shift ⦃ v => DescTo v p ⦄ := + WP.spec_mono (s1page_v _ rights cr attr shift) fun _ h => descTo_of (h.trans (paddr_andM hp ha)) + +/-- **PageTable Map's table descriptor names the table** (module docstring). -/ +theorem s1tab_desc {q : U64} (hp : CapRt.Canonical q) (ha : q.val % 4096 = 0) : + vspace.make_user_table (ws q layout.PPTR_BASE) ⦃ v => DescTo v q ⦄ := + WP.spec_mono (s1tab_v _ (paddr_ok hp ha).1 (paddr_ok hp ha).2) fun _ h => descTo_of h.2 + +/-! ## (A64-S1A gen 32, F3) The physical address and the Stage-2 descriptors -/ + +/-- `layout.paddr p` is `p - PPTR_BASE` (wrapping). -/ +theorem paddr_spec (p : U64) : layout.paddr p ⦃ v => v = ws p layout.PPTR_BASE ⦄ := by + unfold layout.paddr; exact (WP.spec_ok _).2 rfl + +/-- The Stage-2 address bits of `p - PPTR_BASE` are itself. -/ +theorem paddr_andE {p : U64} (hp : CapRt.Canonical p) (ha : p.val % 4096 = 0) : + (ws p layout.PPTR_BASE &&& ept.ADDR_MASK) = ws p layout.PPTR_BASE := by + obtain ⟨h1, h2⟩ := paddr_ok hp ha + exact UScalar.eq_of_val_eq (by rw [UScalar.val_and, ept.ADDR_MASK.val_eq]; exact nat_and_M h1 h2) + +/-- **A descriptor with the Stage-2 address bits of `p - PPTR_BASE` names `p`** (`DescTo`'s `ept.ADDR_MASK` side). -/ +theorem descTo_ofE {v p : U64} (hv : (v &&& ept.ADDR_MASK) = ws p layout.PPTR_BASE) : DescTo v p := by + right + rw [hv] + apply UScalar.eq_of_val_eq + have e : p.bv.toNat = p.val := rfl + have hl := p.bv.isLt + simp [core.num.U64.wrapping_add_val_eq, core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits] + omega + +set_option maxHeartbeats 1000000 in +/-- **`make_s2_leaf x …`** (ept.rs:99–121) is `0` (rights neither RW nor RO) or keeps the address bits of `x`. -/ +theorem s2leaf_v (x vm : U64) (cr : Bool) (attr sh : U64) : + ept.make_s2_leaf x vm cr attr sh ⦃ v => v = 0#u64 ∨ (v &&& ept.ADDR_MASK) = (x &&& ept.ADDR_MASK) ⦄ := by + unfold ept.make_s2_leaf + rw [eq_of_spec_fd P0.Consts.ept.S2_AP_RW.spec, eq_of_spec_fd P0.Consts.ept.S2_AP_RO.spec, + eq_of_spec_fd P0.Consts.ept.S2_MEMATTR_NORMAL_WB.spec, eq_of_spec_fd P0.Consts.ept.S2_MEMATTR_DEVICE.spec, + eq_of_spec_fd P0.Consts.ept.S2_SH_INNER.spec, eq_of_spec_fd P0.Consts.ept.S2_AF.spec, + eq_of_spec_fd P0.Consts.ept.S2_XN.spec, eq_of_spec_fd P0.Consts.ept.D_VALID.spec, + eq_of_spec_fd P0.Consts.ept.D_TABLE_OR_PAGE.spec] + simp only [lift, bind_ok] + refine spec_ite (fun _ => ?_) (fun _ => spec_ite (fun _ => ?_) (fun _ => (WP.spec_ok _).2 (Or.inl rfl))) + all_goals + refine WP.spec_bind (P0.vspace.exec_never.p0 attr cr) fun xn _ => ?_ + refine WP.spec_bind (Pₘ := fun p : U64 × U64 => p.1.val < 4096 ∧ p.2.val < 4096) + (by split <;> exact (WP.spec_ok _).2 ⟨by decide, by decide⟩) ?_ + rintro ⟨m, sh'⟩ ⟨hm, hs⟩ + try dsimp only + try simp only [lift, bind_ok] + refine WP.spec_bind (Pₘ := fun v : U64 => v.val < 4096) + (by split <;> exact (WP.spec_ok _).2 (by decide)) fun i2 h2 => ?_ + try simp only [lift, bind_ok] + refine WP.spec_bind (Pₘ := fun v : U64 => v.val &&& 281474976706560 = 0) + (by split <;> exact (WP.spec_ok _).2 (by decide)) fun i9 h9 => ?_ + refine (WP.spec_ok _).2 (Or.inr (UScalar.eq_of_val_eq ?_)) + simp only [UScalar.val_and, UScalar.val_or, ept.ADDR_MASK.val_eq] + rw [nat_or_offM _ _ h9, nat_or_offM _ _ (by decide), nat_or_offM _ _ (nat_small_offM hs), + nat_or_offM _ _ (by decide), nat_or_offM _ _ (nat_small_offM hm), nat_or_offM _ _ (nat_small_offM h2), + Nat.and_assoc, Nat.and_self] + +/-- **Stage-2 Page Map's leaf descriptor is `0` or names the frame**. -/ +theorem s2leaf_desc {p : U64} (hp : CapRt.Canonical p) (ha : p.val % 4096 = 0) (vm : U64) (cr : Bool) + (attr sh : U64) : + ept.make_s2_leaf (ws p layout.PPTR_BASE) vm cr attr sh ⦃ v => v = 0#u64 ∨ DescTo v p ⦄ := + WP.spec_mono (s2leaf_v _ vm cr attr sh) fun _ h => h.imp id fun h => descTo_ofE (h.trans (paddr_andE hp ha)) + +/-- **Stage-2 PageTable Map's table descriptor names the table** (QueueS2Map's `s2tab_v`). -/ +theorem s2tab_desc {q : U64} (hp : CapRt.Canonical q) (ha : q.val % 4096 = 0) : + ept.make_s2_table (ws q layout.PPTR_BASE) ⦃ v => DescTo v q ⦄ := + WP.spec_mono (s2tab_v _ (paddr_ok hp ha).1 (paddr_ok hp ha).2) fun _ h => descTo_ofE h.2 + +end ST +end R +end W7 + +end + +section vs +open Fl4Proofs.P3 +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {OS Vc : Set U64} + +namespace W7 +namespace R +namespace ST + +/-- (A64-S1A gen 32, F3) **A step whose footprint misses every placed `VsR` word but one word `x`, which ends as a +`VsWr` record** (TestAndClearAccessed: the access-flag write, then the reply's `DfW` words). -/ +theorem ArmVs.ofOne {s0 s : S} {W : U64 → Prop} {x : U64} (w : WritesIn st s0 s (fun b => W b ∨ b = x)) + (hW : ∀ Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → FrUb st Ub OS s0 → + ∀ b, W b → ¬ VsR (L.ksb s0) Pt b) + (hx : VsWr st OS (L.ksb s0) s0 s x) : ArmVs st H OS Vc s0 s := + ⟨w.1, fun Ub Pt hvr hf b hb => by + by_cases e : b = x + · subst e; exact Or.inr hx + · exact Or.inl (w.2.2 b (hvr.al b hb) fun h => h.elim (fun hw => hW Ub Pt hvr hf b hw hb) e)⟩ + +/-- (A64-S1A gen 32, F3) **A zero stretch, then one write of a word `x` ending as a `VsWr` record** (the map arms: +the restart and the in-place cap write, then the descriptor). -/ +theorem ArmVsZ.thenOne {s0 s1 s : S} {x : U64} (Z : ArmVsZ st H OS Vc s0 s1) (w : WritesIn st s1 s (· = x)) + (hx : L.mem s x = L.mem s1 x ∨ VsWr st OS (L.ksb s0) s0 s x) : ArmVs st H OS Vc s0 s := + ⟨w.1.trans Z.1, fun Ub Pt hvr hf b hb => by + have k : L.mem s b = L.mem s1 b ∨ VsWr st OS (L.ksb s0) s0 s b := by + by_cases e : b = x + · subst e; exact hx + · exact Or.inl (w.2.2 b (hvr.al b hb) e) + rcases k with e2 | v + · rcases Z.2 Ub Pt hvr hf b hb with h | h + · exact Or.inl (e2.trans h) + · exact Or.inr (Or.inl (e2.trans h)) + · exact Or.inr v⟩ + +end ST +end R +end W7 + +end vs + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/MdbAsidA.lean b/proofs/Fl4ProofsA64/P1/MdbAsidA.lean index ec6f0f48f..4d1128079 100644 --- a/proofs/Fl4ProofsA64/P1/MdbAsidA.lean +++ b/proofs/Fl4ProofsA64/P1/MdbAsidA.lean @@ -33,6 +33,8 @@ P1 (aarch64, gen 118): **ASIDPool Assign on `SysL ∧ SymL`** (Architect ruling `capA_wr_offA`, `OSOK.inOS`, `asW_at`, `pool_write.asg`, **`obj.Slot.set_cap.assignKW`**, and the widened arm **`vspace.decode.assignLW`** / **`syscall.decode_invocation.assignLW`** (post `(SysL ∧ SymL) ∧ BlkOK ∧ AsgPost`); `assignL` / `assign_sysL` are now their projections (statements byte-identical). MdbArmQ reads `AsgPost`. +* (gen 39, A64-S1A, threading Architect ruling L1's `HvPt`) `AsgPost` gains the field **`al`** (every `OS` cap kept + or `AlikeA` its old cap; `set_cap.assignKW` by `InsC.al`); no statement changed. Named premises: none new (QueueDecIrq's [P] `MaxSpi`, QueueSignal's [J] `RunVcpuInv` as in `armLD7`). Case facts: **`PoolOff`** (ruled; at `assignL` / `armLD8`, for the Assign arm only). @@ -198,15 +200,20 @@ structure AsgPost (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS : S tab : ∀ {Vc Ub Pt : Set U64}, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt → ∀ j, L.mem s' (wa (L.ksb s) (AtOff j)) = L.mem s (wa (L.ksb s) (AtOff j)) cap : ∀ y ∈ OS, capA st s' y = capA st s y ∨ (VsRootK (capA st s y) ∧ VsRootK (capA st s' y)) + /-- (gen 39, S1A, threading Architect ruling L1's `HvPt`) Every `OS` cap kept or alike its old cap (the in-place + `set_cap`'s `InsC.al`: a rewritten root cap names the same root). -/ + al : ∀ y ∈ OS, capA st s' y = capA st s y ∨ AlikeA (capA st s' y) (capA st s y) -theorem AsgPost.refl (s : S) : AsgPost st H OS s s := ⟨rfl, fun _ _ => rfl, fun _ _ => Or.inl rfl⟩ +theorem AsgPost.refl (s : S) : AsgPost st H OS s s := + ⟨rfl, fun _ _ => rfl, fun _ _ => Or.inl rfl, fun _ _ => Or.inl rfl⟩ /-- `AsgPost` across the caller's restart (`sts_fine`'s frame: QueueVsKeep's `vsk_sts`). -/ theorem AsgPost.sts {Q : U64 → U64 → List U64} {Rq : U64 → List U64} {s s1 : S} (q : SchedQueuesInv st H.tcbs Cs H.omega H s Q Rq) {t : U64} (ht : t ∈ H.tcbs) (hw : WritesIn st s s1 (fun b => b = stA t ∨ b = L.nodeAt s (L.cpu s) layout.node.SCHED_ACTION)) (k1 : OSKeep st OS s s1) : AsgPost st H OS s s1 := - ⟨hw.1, fun hvr j => vsk_sts hvr q ht hw _ (Or.inr (asW_at _ j)), fun y hy => Or.inl (k1.capA hy)⟩ + ⟨hw.1, fun hvr j => vsk_sts hvr q ht hw _ (Or.inr (asW_at _ j)), fun y hy => Or.inl (k1.capA hy), + fun y hy => Or.inl (k1.capA hy)⟩ /-- `AsgPost` across the pool word's write (the word off the state block and the `OS` slots: `PoolW`). -/ theorem AsgPost.wr (hO : OSOK H.tcbs H.omega H.frame OS) {s s2 : S} (hkw : (L.ksb s).val + 788736 ≤ 2 ^ 64) @@ -218,6 +225,7 @@ theorem AsgPost.wr (hO : OSOK H.tcbs H.omega H.frame OS) {s s2 : S} (hkw : (L.ks rw [L.mem_wr_ne hw.al (hvr.al _ (Or.inr (asW_at _ j))) (fun e => by rcases hw.ks.2 with g | g <;> omega)] exact A.tab hvr j cap y hy := by rw [capA_wr_offA hO hy hw.al (hw.os y hy)]; exact A.cap y hy + al y hy := by rw [capA_wr_offA hO hy hw.al (hw.os y hy)]; exact A.al y hy /-- (gen 132) **The pool word's write with `BlkOK` and `AsgPost`**, flat (the decode's goal shape; `pool_write.sysL`, QueueSlots7's `blk_capw_wr`, `AsgPost.wr`). -/ @@ -249,7 +257,7 @@ theorem obj.Slot.set_cap.assignKW {Rp Nt : Set U64} {s : S} {extra : Aeneas.Std. refine WP.spec_mono (WP.spec_and (obj.Slot.set_cap.sysLA (Vc := Set.univ) P.heap P.os h1.bxi B1 Y1 (fun _ _ _ _ => Set.mem_univ _) hxO (by rw [k1.capA hxO, hc]) hdc C hK hxB hE) (obj.Slot.set_cap.capw (st := st) (s := s1) (c := nc) (hO'.slot x hxO))) fun s' ⟨h, w⟩ => - ⟨⟨h.1.1, h.1.2.1⟩, h.2.1, w.1.trans A1.ksb, fun hvr j => ?_, fun y hy => ?_⟩ + ⟨⟨h.1.1, h.1.2.1⟩, h.2.1, w.1.trans A1.ksb, fun hvr j => ?_, fun y hy => ?_, fun y hy => ?_⟩ · rw [w.2.2 _ (hvr.al _ (Or.inr (asW_at _ j))) ?_] · exact A1.tab hvr j · rintro (⟨t, ht, -⟩ | ⟨hb, -⟩) @@ -258,6 +266,9 @@ theorem obj.Slot.set_cap.assignKW {Rp Nt : Set U64} {s : S} {extra : Aeneas.Std. · by_cases e : y = x · subst e; exact Or.inr ⟨hc ▸ hKc, h.2.2.1 ▸ hK⟩ · rw [h.2.2.2 y hy e]; exact A1.cap y hy + · by_cases e : y = x + · subst e; rw [h.2.2.1, hc]; exact Or.inr C.al + · rw [h.2.2.2 y hy e]; exact A1.al y hy set_option hygiene false in /-- An error leaf at the decode's state. -/ diff --git a/proofs/Fl4ProofsA64/P1/MdbCapI.lean b/proofs/Fl4ProofsA64/P1/MdbCapI.lean index e1c550241..9403d00d2 100644 --- a/proofs/Fl4ProofsA64/P1/MdbCapI.lean +++ b/proofs/Fl4ProofsA64/P1/MdbCapI.lean @@ -313,7 +313,7 @@ theorem FrP.zombie (H : Heap) (p t n : U64) : FrP H (.Zombie p t n) := fun _ _ _ theorem FrP.fe {H : Heap} {d c : capability.Cap} (e : FE d c) (h : FrP H c) : FrP H d := by intro ptr size rights x1 x2 x3 x4 hc' - obtain ⟨r, y1, y2, y3, y4, e0⟩ := e.1 ptr size rights x1 x2 x3 x4 hc' + obtain ⟨r, y1, y2, y3, y4, e0⟩ := e.1 ptr size rights false x1 x2 x3 x4 hc' exact h ptr size r y1 y2 y3 y4 e0 end ST diff --git a/proofs/Fl4ProofsA64/P1/MdbCnArmQ.lean b/proofs/Fl4ProofsA64/P1/MdbCnArmQ.lean index 7637db33e..85b8afdbd 100644 --- a/proofs/Fl4ProofsA64/P1/MdbCnArmQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbCnArmQ.lean @@ -29,6 +29,11 @@ and that name is now its `ArmQIAt.toQI` projection (statement unchanged). (gen 160) `cnode_armQIKAt` gives `ArmQIAt`'s `PtCap` clause by MdbCapI's `cnode_ciA` at MdbPtCapA's `PtSrc s` (`PtSrc.al`), as S1A's `cnode_ptc` at `PtCapP`. +(A64-S1A gen 37) the carry is MdbPtCapA's `CapSrc s` (`CapSrc.al`), giving `ArmQIAt`'s cap-source clause by +`CapSrc.inv`. + +(A64-S1A gen 40, Architect ruling for gen 40, R3) `cnode_armQIKAt` also posts the `ArmVsK` it builds (last conjunct). + Named premises: none. Case facts: none new (`PoolOff`, `PoolNamed`, `PoolIdx` as ruled). -/ import Fl4ProofsA64.P1.S1aPoolRt @@ -391,7 +396,7 @@ theorem syscall.decode_invocation.cnode_armQIKAt {U Sg Scs Vc Ub Pt : Set U64} { lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) (hf : capFam cap = .cnode) (hcap : obj.Slot.cap st slot s = ok cap) : syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by obtain ⟨Q, Rq, q⟩ := D.bxi.1 have hc : RootOK OS cap := RootOK.of_slot P.ty P.src hcap have F : TabF st H Cs OS s := TabF.of hvr q B.ly.ksw P.core0 @@ -403,9 +408,9 @@ theorem syscall.decode_invocation.cnode_armQIKAt {U Sg Scs Vc Ub Pt : Set U64} { · exact WP.spec_mono (syscall.decode_invocation.cnode_symL D P B Y a len blk call don fp buf hl hf hcap) fun _ _ h => absurd h hV have hpt : syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => - CapInv st (PtSrc st OS s) OS s' ⦄ := - syscall.decode_invocation.cnodeG (PtSrc.refl s) a len slot cap blk call don fp buf extra hf - (cnode.decode.cnode_ciA (fun ha hf h => PtSrc.al ha hf h) P.os P.win q P.ty B.sys.stz.1.1 (PtSrc.refl s) a hl + CapInv st (CapSrc st OS s) OS s' ⦄ := + syscall.decode_invocation.cnodeG (CapSrc.refl s) a len slot cap blk call don fp buf extra hf + (cnode.decode.cnode_ciA (fun ha hf h => CapSrc.al ha hf h) P.os P.win q P.ty B.sys.stz.1.1 (CapSrc.refl s) a hl cap hc P.ext) refine WP.spec_mono (WP.spec_and (WP.spec_and (WP.spec_and (syscall.decode_invocation.cnode_symL D P B Y a len blk call don fp buf hl hf hcap) hvc) @@ -423,7 +428,22 @@ theorem syscall.decode_invocation.cnode_armQIKAt {U Sg Scs Vc Ub Pt : Set U64} { · exact F.os _ hT hb · exact F.tcb P.heap q.curT (K := layout.tcb.STATE) (by simp) hT e.symm · exact F.node rfl F.cur F.ncur (by simp) hT e.symm - refine ⟨⟨h1, h2, ⟨Ac, hBk⟩, h3, fun hPO j => ?_, fun hPN j => ?_, fun _ hPI => ?_, PtSrc.ptCap hP⟩, hW.1, htab⟩ + have hV : ArmVsK st H OS Vc s s' := ArmVsK.ofW hW fun _ _ hvr' _ b hb hv => by + rcases hv with hp | hT + · have hO := q.omega b (hvr'.om b (Or.inl hp)) + rcases hb with ((⟨t, ht, -⟩ | ⟨hb, -⟩) | e | e) + · exact absurd ht (Set.notMem_empty _) + · exact hvr'.os b (Or.inl hp) hb + · exact out_ne_field (y := L.curW s) (K := 3328#u64) hO q.curT (q.tcbs _ q.curT) (by simp) + (by rw [e, stA_eq]) + · refine out_ne_node hO F.cur F.ncur ?_ (by rw [e]); simp + · rcases hb with ((⟨t, ht, -⟩ | ⟨hb, -⟩) | e | e) + · exact absurd ht (Set.notMem_empty _) + · exact F.os _ hT hb + · exact F.tcb P.heap q.curT (K := layout.tcb.STATE) (by simp) hT e.symm + · exact F.node rfl F.cur F.ncur (by simp) hT e.symm + refine ⟨⟨h1, h2, ⟨Ac, hBk⟩, h3, fun hPO j => ?_, fun hPN j => ?_, fun _ hPI => ?_, CapSrc.inv hP, hV.toVs⟩, + ⟨hW.1, htab⟩, hV⟩ · have h0 := hPO j rw [vspace.asid_table.eq] at h0 ⊢ rw [htab j] @@ -457,6 +477,8 @@ theorem syscall.decode_invocation.cnode_armQIK {U Sg Scs Vc Ub Pt : Set U64} {Z ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.cnode_armQIKAt D P B Y hvr a len blk call don fp buf hl hf hcap) fun r h => by first + | exact ⟨h.1.toQI, h.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI diff --git a/proofs/Fl4ProofsA64/P1/MdbCnDelArm.lean b/proofs/Fl4ProofsA64/P1/MdbCnDelArm.lean index cbcd88d0a..e0564464a 100644 --- a/proofs/Fl4ProofsA64/P1/MdbCnDelArm.lean +++ b/proofs/Fl4ProofsA64/P1/MdbCnDelArm.lean @@ -42,31 +42,33 @@ variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : set_option maxHeartbeats 1000000 in /-- (gen 147, ruling (a)) **`cdt.revoke.armQI` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, `cdt.revoke.armQI` its projection). -/ -theorem cdt.revoke.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Ty K) +theorem cdt.revoke.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) - (Q : PoolR st OS s0 s) (hx : x ∈ OS) : + (Q : PoolR st OS s0 s) (hx : x ∈ OS) (hF : FrC st OS s0 s) (hZ : ArmVsZ st H OS Vc s0 s) : cdt.revoke st ar s a x ⦃ r => ArmQIAt st H Cs OS Vc ia ie s0 r.2.1 ∧ TabKeepOrZero st s0 r.2.1 ⦄ := by have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 rw [R.jv.ksb] at hD have hall : ∀ y ∈ OS, ¬ IslN (L.ksb s0) y → y ∈ OSN OS (L.ksb s0) := fun y hy hI => ⟨hy, hI⟩ - refine WP.spec_mono (cdt.revoke.poolR I.del I.fin I.tyk I.kl hKZ hPI hall - ⟨R.jv, R.ty, R.sys, R.sym, hD, rfl, rfl, R.irq⟩ Q hx) fun _ h => ?_ - obtain ⟨⟨q, _⟩, p⟩ := h + refine WP.spec_mono (WP.spec_and (cdt.revoke.poolR I.del I.fin I.tyk I.kl hKZ hPI hall + ⟨R.jv, R.ty, R.sys, R.sym, hD, rfl, rfl, R.irq⟩ Q hx) (cdt.revoke.armVsZ I hKZ R hF hZ hx)) fun _ h => ?_ + obtain ⟨⟨⟨q, _⟩, p⟩, z⟩ := h obtain ⟨Ac', hb⟩ := q.jv.1.parts - exact ArmQIAt.ofPR ⟨q.sys, q.sym⟩ ⟨Ac', hb.blk⟩ (fun _ => VcCap.of_domQ q.dom I.kv q.irq hall) p + exact ArmQIAt.ofPR ⟨q.sys, q.sym⟩ ⟨Ac', hb.blk⟩ (fun _ => VcCap.of_domQ q.dom I.kv q.irq hall) p z.1.toVs set_option maxHeartbeats 1000000 in /-- **`cdt.revoke` from `DelR ∧ PoolR` to `ArmQI ∧ TabKeepOrZero`** (module docstring). -/ -theorem cdt.revoke.armQI {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Ty K) +theorem cdt.revoke.armQI {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) (hx : x ∈ OS) : cdt.revoke st ar s a x ⦃ r => ArmQI st H Cs OS Vc ia ie s0 r.2.1 ∧ TabKeepOrZero st s0 r.2.1 ⦄ := by - exact WP.spec_mono (cdt.revoke.armQIAt I hKZ hPI R Q hx) fun r h => by - first - | exact ⟨h.1.toQI, h.2⟩ - | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) - | exact h.toQI - | (obtain ⟨_, _, _⟩ := r; exact h.toQI) + have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 + rw [R.jv.ksb] at hD + have hall : ∀ y ∈ OS, ¬ IslN (L.ksb s0) y → y ∈ OSN OS (L.ksb s0) := fun y hy hI => ⟨hy, hI⟩ + refine WP.spec_mono (cdt.revoke.poolR I.del I.fin I.tyk I.kl hKZ hPI hall + ⟨R.jv, R.ty, R.sys, R.sym, hD, rfl, rfl, R.irq⟩ Q hx) fun _ h => ?_ + obtain ⟨⟨q, _⟩, p⟩ := h + obtain ⟨Ac', hb⟩ := q.jv.1.parts + exact ArmQI.ofPR ⟨q.sys, q.sym⟩ ⟨Ac', hb.blk⟩ (fun _ => VcCap.of_domQ q.dom I.kv q.irq hall) p set_option hygiene false in /-- An unchanged exit at the decode's state. -/ @@ -84,7 +86,7 @@ set_option maxHeartbeats 2000000 in /-- (gen 147, ruling (a)) **`cnode.decode.rvDelQ` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, `cnode.decode.rvDelQ` its projection). -/ theorem cnode.decode.rvDelQAt {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) (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (a : A) {lbl len buf : U64} @@ -93,7 +95,7 @@ theorem cnode.decode.rvDelQAt {s : S} {cap : capability.Cap} {extra : Aeneas.Std ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ⦄ := by have hS : P0.StoreTotal st := L.total have h0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) have hc : RootOK OS cap := RootOK.of_slot P.ty P.src hcap have hh : Held st OS s cap := ⟨slot, P.src, okinj ((capA_eq s slot).symm.trans hcap)⟩ have er : tcb.restart_caller st s = sched.set_thread_state st s (L.curW s) sched.TS_RESTART := by @@ -127,8 +129,8 @@ theorem cnode.decode.rvDelQAt {s : S} {cap : capability.Cap} {extra : Aeneas.Std clear hnc rcases hl with rfl | rfl <;> repeat (first - | exact WP.spec_bind hst fun s1 ⟨⟨_, R1⟩, Q1⟩ => cdt.revoke.armQIAt I hKZ hPI R1 Q1 hv - | exact WP.spec_bind hst fun s1 ⟨⟨_, R1⟩, Q1⟩ => cdt.delete.armQIAt I hKZ hPI R1 Q1 ⟨hv, hvI⟩ + | exact WP.spec_bind hst fun s1 ⟨⟨_, R1⟩, Q1, Z1⟩ => cdt.revoke.armQIAt I hKZ hPI R1 Q1 hv Z1.2 Z1.1 + | exact WP.spec_bind hst fun s1 ⟨⟨_, R1⟩, Q1, Z1⟩ => cdt.delete.armQIAt I hKZ hPI R1 Q1 ⟨hv, hvI⟩ Z1.2 Z1.1 | (refine spec_ite (fun hc => ?_) fun hc => ?_ <;> try (exfalso; revert hc; first | decide @@ -140,7 +142,7 @@ theorem cnode.decode.rvDelQAt {s : S} {cap : capability.Cap} {extra : Aeneas.Std set_option maxHeartbeats 2000000 in /-- **`cnode.decode` at `CNodeRevoke` / `CNodeDelete` to `ArmQI ∧ TabKeepOrZero`** (module docstring). -/ theorem cnode.decode.rvDelQ {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) (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (a : A) {lbl len buf : U64} @@ -158,7 +160,7 @@ theorem cnode.decode.rvDelQ {s : S} {cap : capability.Cap} {extra : Aeneas.Std.A the body moved here, `syscall.decode_invocation.cnodeRvDel_armQI` its projection). -/ theorem syscall.decode_invocation.cnodeRvDel_armQIAt {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hf : capFam cap = .cnode) (a : A) {lbl : U64} @@ -167,7 +169,7 @@ theorem syscall.decode_invocation.cnodeRvDel_armQIAt {s : S} {cap : capability.C syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := syscall.decode_invocation.cnodeG (P := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) a len slot cap blk call don fp buf extra hf + (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) a len slot cap blk call don fp buf extra hf (WP.spec_mono (cnode.decode.rvDelQAt I hKZ hPI D P B Y hcap a hl) fun r h => by obtain ⟨_, s', _⟩ := r exact h) @@ -175,7 +177,7 @@ theorem syscall.decode_invocation.cnodeRvDel_armQIAt {s : S} {cap : capability.C /-- **The CNode arm of `decode_invocation` at Revoke / Delete to `ArmQI ∧ TabKeepOrZero`** (MdbLook's `cnodeG`). -/ theorem syscall.decode_invocation.cnodeRvDel_armQI {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hf : capFam cap = .cnode) (a : A) {lbl : U64} diff --git a/proofs/Fl4ProofsA64/P1/MdbDelArmQ.lean b/proofs/Fl4ProofsA64/P1/MdbDelArmQ.lean index 8b703d7ae..e36db99d8 100644 --- a/proofs/Fl4ProofsA64/P1/MdbDelArmQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbDelArmQ.lean @@ -66,7 +66,7 @@ def DecArmDelQ (cap : capability.Cap) (lbl : U64) : Prop := moved here, `syscall.decode_invocation.del_armQI` its projection). -/ theorem syscall.decode_invocation.del_armQIAt (hA : P0.ArchTotal ar) {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (a : A) {lbl : U64} (hc : DecArmDelQ cap lbl) @@ -97,7 +97,7 @@ arm, each the existing per-arm top (`highVS_armQI`, `setSpace_armQI`, `setIpcBuf `cnodeRvDel_armQI`). -/ theorem syscall.decode_invocation.del_armQI (hA : P0.ArchTotal ar) {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (a : A) {lbl : U64} (hc : DecArmDelQ cap lbl) diff --git a/proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean b/proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean new file mode 100644 index 000000000..4654523ad --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/MdbDelVsZ.lean @@ -0,0 +1,405 @@ +/- +P1 (aarch64, A64-S1A gen 29, Architect 21:41Z, D1): **the `VsZ` carry through the deletion loop**, at a family of +placements, and the deletion family's zero record (MdbArmVsG's `ArmVsZ`) at every placement of MdbArmVs's clause. + +With MdbPoolDelR's widened class fact `FinKZ st ar kb Pt Ty K` (a `K` finaliser is a `VsZ kb Pt` step), every step +of the Zombie loop keeps or zeroes the `VsR` words of a placement `Pt'` for which, at the step's start, some user-frame +set `Ub''` has `VcOK`, `VrOK … Ub'' … Pt'` and the loop's `JV` at `Ub''` (**`PlW`**, the placement witness): + +* **`VsZG st G kb s0 s`**: for every placement `Pt'` of the family `G`, `VsZ kb Pt' s0 s`; **`VsZG.step`**. +* steps: a `K` finaliser (`FinKT`'s `WritesIn (VsR kb Pt)` with `FinKZ`, **`vsz_finK`**: a `Pt'` word off `VsR Pt` + is kept), a `ZS` finaliser (QueueVsKeep's `finVK` at `Ub''`), the `Zombie` writes and the swap (`OS`-slot words, + **`vsk_cw0`**), the preemption point (`sched.preemption_point.vk` at `Ub''`), `empty_slot` (`cdt.empty_slot.vk` at + `Ub''`); the per-placement posts are joined by MdbSigL's `spec_all` (**`spec_vsZG`**). +* **`LoopME.vzM`** (the field, beside MdbPoolDelR's `LoopME.poolM`). +* **The decode's own placement** (`G := (· = Pt)`, witness `Ub`): **`cdt.delete.vsZ`**, **`cdt.revoke.vsZ`** + (`VsZ (ksb s0) Pt s0` carried, D1's carry; no further hypothesis). +* **Every placement of the clause** (`G := PlG`: `VrOK` at some `Ub'`, `FrUb Ub'` at `s0`): the `ZS` finalisers' + footprint (QueueVsWs's `FW` / `VW`) holds the deletion's own `Ub` words (`vcpu.complete_run` writes the exit message + into the RUN caller's IPC buffer, `VcTy.buf` / `RunBuf`), so the witness is **`Ub ∩ Ub'`**: **`RunBuf.frUb`** (the run + frame is a non-device frame of the buffer slot, an `OS` slot: MdbNHO's `FrameOK` places it in a heap object, + MdbFpuL's `frame_off_words` makes its 128 words aligned and inside, `FrUb Ub'` puts them in `Ub'`), **`JV.inter`**, + **`VcOK.inter`**, **`VrOK.ofUb`**. `FrUb Ub'` is needed at every loop state: the loop carries + **`CapInv (FrUbA 𝒰)`** (`FrUbP Ub'` for every `Ub' ∈ 𝒰 = {Ub' | FrUb Ub' OS s0}`; MdbCapI's `LoopME.ciM`, as + MdbDelIn's `cdt.delete.frUb`), and the deletion takes it at its start as **`FrC st OS s0 s`** (`∀ Ub', FrUb Ub' OS + s0 → FrUb Ub' OS s`, the carry MdbArmVsG's `ArmVsZ.trans` reads) and gives it back. Tops: **`cdt.delete.armVsZ`**, + **`cdt.revoke.armVsZ`** (`ArmVsZ s0 ∧ FrC s0` from `DelR ∧ ArmVsZ s0 ∧ FrC s0`). **`ArmVsZ.toG`**, **`ArmVsZ.ofG`**. + +Named premises: none. Case facts: `FinKZ` (MdbPoolDelR's class fact, as `cdt.delete.poolR`). +-/ +import Fl4ProofsA64.P1.MdbRvPool +import Fl4ProofsA64.P1.MdbArmVsG +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 : Set U64} {Scs : Set U64} {Z : U64 → Nat} + +namespace W7 +namespace R +namespace ST + +variable {OS Vc Ub Pt D : Set U64} {ia ie : Nat} +variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-! ## The carry -/ + +variable (st) in +/-- **Every placement of `G` kept or zeroed from `s0`** (module docstring). -/ +def VsZG (G : Set U64 → Prop) (kb : U64) (s0 s : S) : Prop := ∀ Pt', G Pt' → VsZ st kb Pt' s0 s + +theorem VsZG.step {G : Set U64 → Prop} {kb : U64} {s0 s s' : S} (h : VsZG st G kb s0 s) + (k : ∀ Pt', G Pt' → VsZ st kb Pt' s s') : VsZG st G kb s0 s' := + fun P g => (h P g).trans (k P g) + +/-- Per-placement posts of one program, joined (MdbSigL's `spec_all`). -/ +theorem spec_vsZG {α : Type _} {m : Result α} {G : Set U64 → Prop} {kb : U64} {s : S} {f : α → S} + (h0 : m ⦃ fun _ => True ⦄) (h : ∀ Pt', G Pt' → m ⦃ fun r => VsZ st kb Pt' s (f r) ⦄) : + m ⦃ fun r => ∀ Pt', G Pt' → VsZ st kb Pt' s (f r) ⦄ := + WP.spec_mono (spec_all (ι := {P : Set U64 // G P}) (P := fun i r => VsZ st kb i.1 s (f r)) h0 + fun i => h i.1 i.2) fun _ v P g => v ⟨P, g⟩ + +/-- An `OS`-slot write set keeps every placed `VsR` word (any `VrOK`). -/ +theorem vsk_cw0 {Ω' Sg' Ub' : Set U64} {kb : U64} (hR : VrOK Ω' Sg' Scs Z OS Vc Ub' kb Pt) {s s' : S} + (w : WritesIn st s s' (W7.CapW ∅ {b | InOS OS b} ∅)) : VsKeep st kb Pt s s' := + VsKeep.of_w hR.al w fun b hb hc => by + rcases hc with ⟨t, ht, -⟩ | ⟨hin, -⟩ + · exact absurd ht (Set.notMem_empty t) + · exact hR.os b hb hin + +/-- **A `K` finaliser at any placement**: its `VsR kb Pt0` words kept or zeroed (`FinKZ`), every other word kept. -/ +theorem vsz_finK {kb : U64} {Pt0 : Set U64} {s s' : S} (hal : ∀ b, VsR kb Pt b → Aligned b) + (w : WritesIn st s s' (VsR kb Pt0)) (z : VsZ st kb Pt0 s s') : VsZ st kb Pt s s' := fun b hb => by + by_cases h0 : VsR kb Pt0 b + · exact z b h0 + · exact Or.inl (w.mem_eq (hal b hb) h0) + +/-! ## The placement witness -/ + +variable (st) in +/-- **A placement witness at `s`** (module docstring): a user-frame set with `VcOK`, `VrOK` at `Pt'` and the loop's +`JV`. -/ +def PlW (H : Heap) (Cs Ac OS Vc : Set U64) (s0 s : S) (Pt' : Set U64) : Prop := + ∃ Ub'', VcOK H.tcbs H.scs H.scBits OS Vc Ub'' ∧ VrOK H.omega H.frame H.scs H.scBits OS Vc Ub'' (L.ksb s0) Pt' ∧ + JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub'' s0 s + +/-- `VrOK` at another user-frame set off the placement. -/ +theorem VrOK.ofUb {Ω Sg Ub' : Set U64} {kb : U64} (hvr : VrOK Ω Sg Scs Z OS Vc Ub' kb Pt) + (hU : ∀ b ∈ Ub, ¬ VsR kb Pt b) : VrOK Ω Sg Scs Z OS Vc Ub kb Pt := + ⟨hvr.al, hvr.om, hvr.sg, hvr.sc, hvr.os, hvr.vc, fun b hb hu => hU b hu hb, hvr.ks⟩ + +theorem VcOK.inter {T : Set U64} {Ub' : Set U64} (hV : VcOK T Scs Z OS Vc Ub) : VcOK T Scs Z OS Vc (Ub ∩ Ub') := + ⟨hV.os, hV.sc, fun b hb => hV.ubos b hb.1, fun b hb => hV.ubv b hb.1, hV.bcov, hV.fit, hV.disj⟩ + +/-- **The run frame of a buffer slot (an `OS` slot) is in every `Ub'` with `FrUb Ub'`** (module docstring). -/ +theorem RunBuf.frUb {Ub' : Set U64} {s : S} {y : U64} (hH : HeapOK H) (hF : FrameOK st H OS s) + (hf : FrUb st Ub' OS s) (hx : sbWordA y ∈ OS) (h : RunBuf st Ub s y) : RunBuf st (Ub ∩ Ub') s y := by + intro ptr size rights dev x1 x2 x3 x4 bits sz hcap hdev hrw hbits hsz h63 hlt hge + have hU := h ptr size rights dev x1 x2 x3 x4 bits sz hcap hdev hrw hbits hsz h63 hlt hge + 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 + 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⟩ + +/-- **The loop's `JV` at `Ub ∩ Ub'`** (module docstring). -/ +theorem JV.inter {Ub' : Set U64} {s0 s : S} (hH : HeapOK H) (hV : VcOK H.tcbs H.scs H.scBits OS Vc Ub) + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) + (hF : FrameOK st H OS s) (hf : FrUb st Ub' OS s) : + JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc (Ub ∩ Ub') s0 s := + ⟨h.1, ⟨h.2.obj, h.2.bnd, h.2.run, fun b hb => h.2.usr b hb.1, + fun t ht hr => RunBuf.frUb hH hF hf (hV.bcov t ht) (h.2.buf t ht hr), h.2.ks⟩⟩ + +/-! ## The loop's steps -/ + +section steps +variable {s0 : S} {G : Set U64 → Prop} + +/-- **The `Zombie` write keeps `VsZG`.** -/ +theorem obj.Slot.set_cap.vsZG {T Ω Sg : Set U64} (hO : OSOK T Ω Sg OS) {s : S} + (hW : ∀ Pt', G Pt' → PlW st H Cs Ac OS Vc s0 s Pt') {x p t n : U64} (hx : x ∈ OS) + (hZ : VsZG st G (L.ksb s0) s0 s) : + obj.Slot.set_cap st x s (.Zombie p t n) ⦃ s' => VsZG st G (L.ksb s0) s0 s' ⦄ := by + have w := W7.obj.Slot.set_cap.capw (st := st) (s := s) (c := .Zombie p t n) (hO.inOS.slot x hx) + rw [set_cap_zombie, WP.spec_ok] at w ⊢ + exact hZ.step fun P g => (vsk_cw0 (hW P g).choose_spec.2.1 w).vsz + +/-- **The swap keeps `VsZG`.** -/ +theorem cdt.cap_swap_for_delete.vsZG {T Ω Sg : Set U64} (hO : OSOK T Ω Sg OS) {s : S} + (hW : ∀ Pt', G Pt' → PlW st H Cs Ac OS Vc s0 s Pt') (hS : MdbS st OS s) + {x1 x2 : U64} (hx1 : x1 ∈ OS) (hx2 : x2 ∈ OS) (hs1 : obj.sext48 x1 = ok x1) (hs2 : obj.sext48 x2 = ok x2) + (hZ : VsZG st G (L.ksb s0) s0 s) : + cdt.cap_swap_for_delete st s x1 x2 ⦃ s' => VsZG st G (L.ksb s0) s0 s' ⦄ := + WP.spec_mono (cdt.cap_swap_for_delete.capxW hO hS hx1 hx2 hs1 hs2) fun _ ⟨w, _⟩ => + hZ.step fun P g => (vsk_cw0 (hW P g).choose_spec.2.1 w).vsz + +/-- **The preemption point keeps `VsZG`.** -/ +theorem sched.preemption_point.vsZG (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) {s : S} {a : A} + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) + (hW : ∀ Pt', G Pt' → PlW st H Cs Ac OS Vc s0 s Pt') (hZ : VsZG st G (L.ksb s0) s0 s) : + sched.preemption_point st ar s a ⦃ r => VsZG st G (L.ksb s0) s0 r.2.1 ⦄ := + WP.spec_mono (spec_vsZG (st := st) (f := fun r => r.2.1) + (WP.spec_mono (sched.preemption_point.jv E.arch E.os E.vc h (by rw [h.ksb]; exact E.wu)) fun _ _ => trivial) + fun P g => by + obtain ⟨U2, -, hvr, h2⟩ := hW P g + exact WP.spec_mono (sched.preemption_point.vk E.arch hvr h2 h2.ksb) fun _ v => v.vsz) + fun _ v => hZ.step v + +set_option maxHeartbeats 1000000 in +/-- **`VsZG` added to a `LoopME` field giving `MdbS`** (module docstring). -/ +theorem LoopME.vzM {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} {Em : S → U64 → Prop} + (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) + (hW : ∀ s, JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s → M s → + ∀ Pt', G Pt' → PlW st H Cs Ac OS Vc s0 s Pt') + (hM : LoopME st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Em M) + (hMS : ∀ s, M s → MdbS st OS s) : + LoopME st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Em (fun s => M s ∧ VsZG st G (L.ksb s0) s0 s) where + fin s a x c f hC m hx hc hX hf := by + have h0 := WP.spec_mono (hM.fin s a x c f hC m.1 hx hc hX hf) fun _ _ => trivial + have step : objects.finalise_cap st ar s a c f false ⦃ r => + ∀ Pt', G Pt' → VsZ st (L.ksb s0) Pt' s r.2.1 ⦄ := by + rcases hX.1 with ⟨hz, -⟩ | hKc + · refine spec_vsZG (st := st) (f := fun r => r.2.1) h0 fun P g => ?_ + obtain ⟨U2, hV2, hvr, h2⟩ := hW s hC m.1 P g + exact WP.spec_mono (finVK E.arch E.os E.sca hV2 hvr h2 E.irq hX.2.2 hx hc hz a f) fun _ v => v.vsz + · exact WP.spec_mono (WP.spec_and (hK s a c f hX.2.1 hC.ksb hKc) (hKZ s a c f hX.2.1 hC.ksb hKc)) + fun _ ⟨⟨_, w, _⟩, z⟩ P g => vsz_finK (hW s hC m.1 P g).choose_spec.2.1.al w z + exact WP.spec_mono (WP.spec_and (hM.fin s a x c f hC m.1 hx hc hX hf) step) + fun _ ⟨⟨m1, z1, e1⟩, v⟩ => ⟨⟨m1, m.2.step v⟩, z1, e1⟩ + en := hM.en + setz s x p t n hC m hx hp hz := + WP.spec_and (hM.setz s x p t n hC m.1 hx hp hz) (obj.Slot.set_cap.vsZG E.os (hW s hC m.1) hx m.2) + setd s x p t n hC m hx hp hz he hn := + WP.spec_and (hM.setd s x p t n hC m.1 hx hp hz he hn) (obj.Slot.set_cap.vsZG E.os (hW s hC m.1) hx m.2) + swap s p y hC m hp hy hne hz := WP.spec_and (hM.swap s p y hC m.1 hp hy hne hz) + (cdt.cap_swap_for_delete.vsZG E.os (hW s hC m.1) (hMS s m.1) (E.dom hp) (E.dom hy) (E.dcan p hp) + (E.dcan y hy) m.2) + pre s a hC m := WP.spec_and (hM.pre s a hC m.1) (sched.preemption_point.vsZG E hC (hW s hC m.1) m.2) + emp s a x cl hC m hx hcl he := by + have h0 := WP.spec_mono (hM.emp s a x cl hC m.1 hx hcl he) fun _ _ => trivial + exact WP.spec_mono (WP.spec_and (hM.emp s a x cl hC m.1 hx hcl he) (spec_vsZG (st := st) (f := fun r => r.1) h0 + fun P g => by + obtain ⟨U2, -, hvr, h2⟩ := hW s hC m.1 P g + exact WP.spec_mono (cdt.empty_slot.vk E.arch E.os hvr h2 hx hcl h2.ksb) fun _ v => v.vsz)) + fun _ ⟨m1, v⟩ => ⟨m1, m.2.step v⟩ + +end steps + +/-! ## The decode's own placement -/ + +theorem vsZG_self {kb : U64} {s0 s : S} (h : VsZ st kb Pt s0 s) : VsZG st (· = Pt) kb s0 s := + fun _ e => e ▸ h + +set_option maxHeartbeats 1000000 in +/-- **One deletion off the IRQ node carries `VsZ` at the decode's own placement** (MdbPoolDelR's +`cdt.delete.poolG` text over `LoopME.vzM`, witness `Ub`). -/ +theorem cdt.delete.vsZG0 {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) {a : A} {x I Is : U64} + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) (hx : x ∈ OS) + (hxI : ¬ IslN (L.ksb s0) x) (hD : DomQ st K Vc D H.scs H.tcbs I Is s) (hX : XQ st K Vc D H.scs H.tcbs I Is x s) + (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hZ : VsZ st (L.ksb s0) Pt s0 s) : + cdt.delete st ar s a x true ⦃ r => VsZ st (L.ksb s0) Pt s0 r.2.1 ⦄ := + WP.spec_mono (cdt.delete.zqIGTMEQ (a := a) E.arch E.os E.sca E.vc E.dom E.dcan E.vr hK hTy E.wu E.irq + E.irqSt h hx hxI hD hX hI hIs hN hY + (LoopME.vzM (G := (· = Pt)) E hK hKZ (fun _ h1 _ _ e => e ▸ ⟨Ub, E.vc, E.vr, h1⟩) + (E.fieldI hK hTy hKL s I Is) fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + ⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨Y, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt hI hIs).idSc B.sc⟩, + CtOff.ks h.ksb.symm B.ct⟩, FrOff.ks h.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, vsZG_self hZ⟩) + fun _ h => h.2.2.1.2 Pt rfl + +set_option maxHeartbeats 1000000 in +/-- The IRQ-node form of `cdt.delete.vsZG0` on a `DelQ` state (MdbRvPool's `cdt.delete.poolI` text). -/ +theorem cdt.delete.vsZI0 {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) {a : A} {x I Is : U64} + (Qd : DelQ st H Cs OS D Vc Ub Ac K Ty ia ie I Is s0 s) (hxI : IslN (L.ksb s0) x) + (hZ : VsZ st (L.ksb s0) Pt s0 s) : + cdt.delete st ar s a x true ⦃ r => VsZ st (L.ksb s0) Pt s0 r.2.1 ⦄ := + WP.spec_mono (cdt.delete.irqME (a := a) E hK hTy Qd.jv hxI Qd.dom Qd.idle Qd.isc Qd.irq Qd.ty + (LoopME.vzM (G := (· = Pt)) E hK hKZ (fun _ h1 _ _ e => e ▸ ⟨Ub, E.vc, E.vr, h1⟩) + (E.fieldI hK hTy hKL s I Is) fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + ⟨⟨⟨⟨⟨⟨⟨⟨⟨Qd.sys.sys.start, ⟨Qd.sym, Qd.sys.vr, Qd.sys.ly⟩⟩, Qd.sys.ln⟩, BufInv.of Qd.sys.cn Qd.sys.bh⟩, + (Qd.sys.ci.idleAt Qd.idle Qd.isc).idSc Qd.sys.sc⟩, CtOff.ks Qd.jv.ksb.symm Qd.sys.ct⟩, + FrOff.ks Qd.jv.ksb.symm Qd.sys.fo⟩, Qd.sys.ep⟩, Qd.sys.ipc⟩, vsZG_self hZ⟩) + fun _ h => h.2.2.1.2 Pt rfl + +set_option maxHeartbeats 1000000 in +/-- **The exposed deletion carries `VsZ` at `DelIn`'s own placement** (D1's carry; `DelIn` / `DelR` form). -/ +theorem cdt.delete.vsZ {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) + (hZ : VsZ st (L.ksb s0) Pt s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : + cdt.delete st ar s a x true ⦃ r => VsZ st (L.ksb s0) Pt s0 r.2.1 ⦄ := by + have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 + rw [R.jv.ksb] at hD + exact cdt.delete.vsZG0 I.del I.fin I.tyk I.kl hKZ R.jv hx.1 hx.2 hD (fun c hc => hD x hx c hc) rfl rfl + R.irq R.ty R.sys R.sym hZ + +set_option maxHeartbeats 1000000 in +/-- **`cdt.revoke` carries `VsZ` at `DelIn`'s own placement** (MdbLiveY's `cdt.revoke.gen` at `Pr := VsZ`). -/ +theorem cdt.revoke.vsZ {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) + (hZ : VsZ st (L.ksb s0) Pt s0 s) (hx : x ∈ OS) : + cdt.revoke st ar s a x ⦃ r => VsZ st (L.ksb s0) Pt s0 r.2.1 ⦄ := by + have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 + rw [R.jv.ksb] at hD + have hall : ∀ y ∈ OS, ¬ IslN (L.ksb s0) y → y ∈ OSN OS (L.ksb s0) := fun y hy hI => ⟨hy, hI⟩ + have E := I.del + refine WP.spec_mono (cdt.revoke.gen (Pr := VsZ st (L.ksb s0) Pt s0) E I.fin I.tyk I.kl hall + (fun s1 a1 y Q1 p1 hy => by + by_cases hnI : IslN (L.ksb s0) y + · exact cdt.delete.vsZI0 E I.fin I.tyk I.kl hKZ Q1 hnI p1 + · exact cdt.delete.vsZG0 E I.fin I.tyk I.kl hKZ Q1.jv hy hnI Q1.dom + (fun c hc => Q1.dom y (hall _ hy hnI) c hc) Q1.idle Q1.isc Q1.irq Q1.ty Q1.sys Q1.sym p1) + (fun s1 a1 Q1 p1 => WP.spec_mono (sched.preemption_point.vsZG (G := (· = Pt)) E Q1.jv + (fun _ e => e ▸ ⟨Ub, E.vc, E.vr, Q1.jv⟩) (vsZG_self p1)) fun _ z => z Pt rfl) + ⟨R.jv, R.ty, R.sys, R.sym, hD, rfl, rfl, R.irq⟩ hZ hx) fun _ h => h.2 + +/-! ## Every placement: `ArmVsZ` -/ + +variable (st) in +/-- **The placements MdbArmVs's clause quantifies over** (`VrOK` at some `Ub'`, `FrUb Ub'` at `s0`). -/ +def PlG (H : Heap) (OS Vc : Set U64) (s0 : S) (Pt : Set U64) : Prop := + ∃ Ub', VrOK H.omega H.frame H.scs H.scBits OS Vc Ub' (L.ksb s0) Pt ∧ FrUb st Ub' OS s0 + +/-- `FrUbP` for every user-frame set of a family. -/ +def FrUbA (𝒰 : Set (Set U64)) (c : capability.Cap) : Prop := ∀ Ub' ∈ 𝒰, FrUbP Ub' c + +theorem FrUbA.null (𝒰 : Set (Set U64)) : FrUbA 𝒰 .Null := fun Ub' _ => FrUbP.null Ub' + +theorem FrUbA.zombie (𝒰 : Set (Set U64)) (p t n : U64) : FrUbA 𝒰 (.Zombie p t n) := + fun Ub' _ => FrUbP.zombie Ub' p t n + +variable (st) in +/-- **`FrUb` carried from `s0`** (the hypothesis MdbArmVsG's `ArmVsZ.trans` reads). -/ +def FrC (OS : Set U64) (s0 s : S) : Prop := ∀ Ub', FrUb st Ub' OS s0 → FrUb st Ub' OS s + +/-- (A64-S1A gen 31) **The deletion family's carry through a keeping step** (`ArmVsK` with `OSKeep`). -/ +theorem ArmVsZ.thenK {s0 s s' : S} (Z : ArmVsZ st H OS Vc s0 s ∧ FrC st OS s0 s) (h : ArmVsK st H OS Vc s s') + (k : OSKeep st OS s s') : ArmVsZ st H OS Vc s0 s' ∧ FrC st OS s0 s' := + ⟨Z.1.trans Z.2 h.toZ, fun Ub hf => FrUb.keepO (Z.2 Ub hf) k⟩ + +theorem FrC.ci {s0 s : S} (h : FrC st OS s0 s) : CapInv st (FrUbA {Ub' | FrUb st Ub' OS s0}) OS s := + fun y hy Ub' hU => h Ub' hU y hy + +theorem FrC.of_ci {s0 s : S} (h : CapInv st (FrUbA {Ub' | FrUb st Ub' OS s0}) OS s) : FrC st OS s0 s := + fun Ub' hU y hy => h y hy Ub' hU + +theorem ArmVsZ.toG {s0 s : S} (h : ArmVsZ st H OS Vc s0 s) : VsZG st (PlG st H OS Vc s0) (L.ksb s0) s0 s := + fun P ⟨Ub', hvr, hf⟩ b hb => h.2 Ub' P hvr hf b hb + +theorem ArmVsZ.ofG {s0 s : S} (hk : L.ksb s = L.ksb s0) (h : VsZG st (PlG st H OS Vc s0) (L.ksb s0) s0 s) : + ArmVsZ st H OS Vc s0 s := + ⟨hk, fun Ub' P hvr hf => h P ⟨Ub', hvr, hf⟩⟩ + +/-- **The `Ub ∩ Ub'` witness** at a loop state with `FrameOK` and the `FrUbA` carry (module docstring). -/ +theorem PlG.plW {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) + (hF : FrameOK st H OS s) (hC : CapInv st (FrUbA {Ub' | FrUb st Ub' OS s0}) OS s) : + ∀ Pt', PlG st H OS Vc s0 Pt' → PlW st H Cs Ac OS Vc s0 s Pt' := fun _ ⟨Ub', hvr, hf⟩ => + ⟨Ub ∩ Ub', VcOK.inter E.vc, VrOK.ofUb hvr fun b hb hv => hvr.ub b hv hb.2, + JV.inter E.heap E.vc h hF (FrC.of_ci hC Ub' hf)⟩ + +set_option maxHeartbeats 1000000 in +/-- **One deletion off the IRQ node is a zero step at every placement, carrying `FrUbA`** (module docstring). -/ +theorem cdt.delete.armVsZG {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) {a : A} {x I Is : U64} + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) (hx : x ∈ OS) + (hxI : ¬ IslN (L.ksb s0) x) (hD : DomQ st K Vc D H.scs H.tcbs I Is s) (hX : XQ st K Vc D H.scs H.tcbs I Is x s) + (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (hC : CapInv st (FrUbA {Ub' | FrUb st Ub' OS s0}) OS s) (hZ : VsZG st (PlG st H OS Vc s0) (L.ksb s0) s0 s) : + cdt.delete st ar s a x true ⦃ r => CapInv st (FrUbA {Ub' | FrUb st Ub' OS s0}) OS r.2.1 ∧ + VsZG st (PlG st H OS Vc s0) (L.ksb s0) s0 r.2.1 ⦄ := + WP.spec_mono (cdt.delete.zqIGTMEQ (a := a) E.arch E.os E.sca E.vc E.dom E.dcan E.vr hK hTy E.wu E.irq + E.irqSt h hx hxI hD hX hI hIs hN hY + (LoopME.vzM E hK hKZ (fun _ h1 m1 => PlG.plW E h1 m1.1.1.1.1.1.1.1.1.1.1.1.1.2 m1.2) + (LoopME.ciM (FrUbA.null _) (FrUbA.zombie _) E.arch E.os E.sca E.vc E.dom E.dcan E.vr hK hTy E.wu E.irq + E.irqSt (E.fieldI hK hTy hKL s I Is) fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨Y, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt hI hIs).idSc B.sc⟩, + CtOff.ks h.ksb.symm B.ct⟩, FrOff.ks h.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, hC⟩, hZ⟩) + fun _ h => ⟨h.2.2.1.1.2, h.2.2.1.2⟩ + +set_option maxHeartbeats 1000000 in +/-- The IRQ-node form of `cdt.delete.armVsZG` on a `DelQ` state. -/ +theorem cdt.delete.armVsZI {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) {a : A} {x I Is : U64} + (Qd : DelQ st H Cs OS D Vc Ub Ac K Ty ia ie I Is s0 s) (hxI : IslN (L.ksb s0) x) + (hC : CapInv st (FrUbA {Ub' | FrUb st Ub' OS s0}) OS s) (hZ : VsZG st (PlG st H OS Vc s0) (L.ksb s0) s0 s) : + cdt.delete st ar s a x true ⦃ r => CapInv st (FrUbA {Ub' | FrUb st Ub' OS s0}) OS r.2.1 ∧ + VsZG st (PlG st H OS Vc s0) (L.ksb s0) s0 r.2.1 ⦄ := + WP.spec_mono (cdt.delete.irqME (a := a) E hK hTy Qd.jv hxI Qd.dom Qd.idle Qd.isc Qd.irq Qd.ty + (LoopME.vzM E hK hKZ (fun _ h1 m1 => PlG.plW E h1 m1.1.1.1.1.1.1.1.1.1.1.1.1.2 m1.2) + (LoopME.ciM (FrUbA.null _) (FrUbA.zombie _) E.arch E.os E.sca E.vc E.dom E.dcan E.vr hK hTy E.wu E.irq + E.irqSt (E.fieldI hK hTy hKL s I Is) fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨Qd.sys.sys.start, ⟨Qd.sym, Qd.sys.vr, Qd.sys.ly⟩⟩, Qd.sys.ln⟩, BufInv.of Qd.sys.cn Qd.sys.bh⟩, + (Qd.sys.ci.idleAt Qd.idle Qd.isc).idSc Qd.sys.sc⟩, CtOff.ks Qd.jv.ksb.symm Qd.sys.ct⟩, + FrOff.ks Qd.jv.ksb.symm Qd.sys.fo⟩, Qd.sys.ep⟩, Qd.sys.ipc⟩, hC⟩, hZ⟩) + fun _ h => ⟨h.2.2.1.1.2, h.2.2.1.2⟩ + +set_option maxHeartbeats 1000000 in +/-- **The exposed deletion is a zero step at every placement** (`DelIn` / `DelR` form; module docstring). -/ +theorem cdt.delete.armVsZ {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) + (hF : FrC st OS s0 s) (hZ : ArmVsZ st H OS Vc s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : + cdt.delete st ar s a x true ⦃ r => ArmVsZ st H OS Vc s0 r.2.1 ∧ FrC st OS s0 r.2.1 ⦄ := by + have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 + rw [R.jv.ksb] at hD + exact WP.spec_mono (WP.spec_and (cdt.delete.delR I R hx) + (cdt.delete.armVsZG I.del I.fin I.tyk I.kl hKZ R.jv hx.1 hx.2 hD (fun c hc => hD x hx c hc) rfl rfl + R.irq R.ty R.sys R.sym hF.ci hZ.toG)) + fun _ ⟨R', c, z⟩ => ⟨ArmVsZ.ofG R'.jv.ksb z, FrC.of_ci c⟩ + +set_option maxHeartbeats 1000000 in +/-- **`cdt.revoke` is a zero step at every placement** (MdbLiveY's `cdt.revoke.gen`; module docstring). -/ +theorem cdt.revoke.armVsZ {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) + (hF : FrC st OS s0 s) (hZ : ArmVsZ st H OS Vc s0 s) (hx : x ∈ OS) : + cdt.revoke st ar s a x ⦃ r => ArmVsZ st H OS Vc s0 r.2.1 ∧ FrC st OS s0 r.2.1 ⦄ := by + have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 + rw [R.jv.ksb] at hD + have hall : ∀ y ∈ OS, ¬ IslN (L.ksb s0) y → y ∈ OSN OS (L.ksb s0) := fun y hy hI => ⟨hy, hI⟩ + have E := I.del + refine WP.spec_mono (cdt.revoke.gen (Pr := fun s1 => CapInv st (FrUbA {Ub' | FrUb st Ub' OS s0}) OS s1 ∧ + VsZG st (PlG st H OS Vc s0) (L.ksb s0) s0 s1) E I.fin I.tyk I.kl hall + (fun s1 a1 y Q1 p1 hy => by + by_cases hnI : IslN (L.ksb s0) y + · exact cdt.delete.armVsZI E I.fin I.tyk I.kl hKZ Q1 hnI p1.1 p1.2 + · exact cdt.delete.armVsZG E I.fin I.tyk I.kl hKZ Q1.jv hy hnI Q1.dom + (fun c hc => Q1.dom y (hall _ hy hnI) c hc) Q1.idle Q1.isc Q1.irq Q1.ty Q1.sys Q1.sym p1.1 p1.2) + (fun s1 a1 Q1 p1 => WP.spec_mono (WP.spec_and + (sched.preemption_point.jv E.arch E.os E.vc Q1.jv (by rw [Q1.jv.ksb]; exact E.wu)) + (sched.preemption_point.vsZG E Q1.jv (PlG.plW E Q1.jv Q1.sys.sys.fr p1.1) p1.2)) + fun _ ⟨⟨_, k, _⟩, z⟩ => ⟨p1.1.keepO k, z⟩) + ⟨R.jv, R.ty, R.sys, R.sym, hD, rfl, rfl, R.irq⟩ ⟨hF.ci, hZ.toG⟩ hx) + fun _ ⟨⟨q, _⟩, c, z⟩ => ⟨ArmVsZ.ofG q.jv.ksb z, FrC.of_ci c⟩ + +/-- (gen 147, ruling (a); A64-S1A gen 31: moved here from MdbPoolDelR, with `hF` / `hZ` for `ArmQIAt`'s `ArmVs` +clause, read off `cdt.delete.armVsZ`) **`cdt.delete.armQI` at the decode's own `(H, OS)`** (`ArmQIAt`). -/ +theorem cdt.delete.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) + (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) + (Q : PoolR st OS s0 s) (hx : x ∈ OSN OS (L.ksb s0)) (hF : FrC st OS s0 s) (hZ : ArmVsZ st H OS Vc s0 s) : + cdt.delete st ar s a x true ⦃ r => ArmQIAt st H Cs OS Vc ia ie s0 r.2.1 ∧ TabKeepOrZero st s0 r.2.1 ⦄ := + WP.spec_mono (WP.spec_and (cdt.delete.delRP I hKZ hPI R Q hx) (cdt.delete.armVsZ I hKZ R hF hZ hx)) + fun _ h => ArmQIAt.ofDelR h.1.1 h.1.2 h.2.1.toVs + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/MdbEptMapQ.lean b/proofs/Fl4ProofsA64/P1/MdbEptMapQ.lean index 5b0080c6d..3f7951568 100644 --- a/proofs/Fl4ProofsA64/P1/MdbEptMapQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbEptMapQ.lean @@ -27,6 +27,10 @@ cap write closes by MdbVsMapB's `UnmMid.set_armQ` and the descriptor writes by M by `ept.map_table.armQ`, else MdbVsMapB's `ptMap_armQIAt`). Both take `hPl : ArchPlat ar` and `ArmDecHyps st H Pt hPl.ipa s cap`; MdbArmQHD dispatches them, lifting `Ex0NoEpt` out of `DecArmQH`. +(A64-S1A gen 32, F3) **`ept.install_s2_leaf.slotE`** (the slot ends unchanged, `0` or `e`), `pgMapE_tailQ` with +`e = 0 ∨ DescTo e fp` (MdbArmVsV's `s2leaf_desc`), `map_table` with `s2tab_desc`; the tops read the +alignments from the gen-33 `ArmDecHyps` fields `frAl` / `ptCap` (Architect 00:25Z, G1 / G2). + Named premises: QueueS2Ty's [P] `ArchPlat.s2_ipa_bits_const` (existing, as `hPl`). Case facts: none new. -/ import Fl4ProofsA64.P1.MdbEptUnmQ @@ -100,7 +104,7 @@ theorem pgMapE_set {s : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.S (hcs : capA st s slot = .Frame fp fsz fr fd fm fe fa fv) {s1 : S} (M : UnmMid st H Cs OS Pt Ac s s1) (m' e' : Bool) (asid vaddr : U64) : obj.Slot.set_cap st slot s1 (.Frame fp fsz fr fd m' e' asid vaddr) ⦃ s2 => - ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2 ⦄ := by + (ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2) ∧ ArmVsZ st H OS Vc s s2 ⦄ := by have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ rw [hcs] at hw have hp : CapRt.Canonical fp := by cases fe <;> exact hw.1 @@ -109,6 +113,7 @@ theorem pgMapE_set {s : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.S have hfr0 := B.sys.fr slot P.src have hfo0 := B.fo slot P.src rw [hcs] at hfr0 hfo0 + refine WP.spec_and ?_ (obj.Slot.set_cap.armVsZ P.os P.src (UnmMid.armVsZ I D P B M M.z) _) exact UnmMid.set_armQ I D P B Y hcs M hdc (frame_insC fp fsz fr fd fm fe fa fv m' e' a' v') (fun h => by cases h) (fun _ _ _ _ _ _ _ h => by cases h; exact hfr0 _ _ _ _ _ _ _ rfl) @@ -130,6 +135,18 @@ theorem ept.install_s2_leaf.ptw (hA : P0.ArchTotal ar) {lu : ept.S2Slot} (hal : ept.install_s2_leaf.inv hA (P := fun s3 => WritesIn st s s3 (PtW Pt)) (WritesIn.refl s _) a lu e (fun s1 v _ h1 => h1.trans1 ((writesIn_wr hal).mono fun b eb => by rw [eb]; exact hx)) root asid ipa ptr dev attr +/-- (A64-S1A gen 32, F3) **`install_s2_leaf` writes only the walk's slot, which ends unchanged, `0` or `e`** +(QueueS2Frm's `install_s2_leaf.inv`). -/ +theorem ept.install_s2_leaf.slotE (hA : P0.ArchTotal ar) {lu : ept.S2Slot} (hal : Aligned lu.slot) (s : S) (a : A) + (e root asid ipa ptr : U64) (dev : Bool) (attr : U64) : + ept.install_s2_leaf st ar s a lu e root asid ipa ptr dev attr ⦃ r => WritesIn st s r.1 (· = lu.slot) ∧ + (L.mem r.1 lu.slot = L.mem s lu.slot ∨ L.mem r.1 lu.slot = 0#u64 ∨ L.mem r.1 lu.slot = e) ⦄ := + ept.install_s2_leaf.inv hA (P := fun s3 => WritesIn st s s3 (· = lu.slot) ∧ + (L.mem s3 lu.slot = L.mem s lu.slot ∨ L.mem s3 lu.slot = 0#u64 ∨ L.mem s3 lu.slot = e)) + ⟨WritesIn.refl s _, Or.inl rfl⟩ a lu e + (fun s1 v hv h1 => ⟨h1.1.trans1 (writesIn_wr hal), Or.inr (by rw [L.mem_wr_same hal]; exact hv)⟩) + root asid ipa ptr dev attr + /-- **Stage-2 Page Map's tail** (module docstring): the restart, the in-place `Frame` cap, the leaf writes. -/ theorem pgMapE_tailQ (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) @@ -140,13 +157,20 @@ theorem pgMapE_tailQ (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} {slot {lu : ept.S2Slot} (hx : PtW Pt lu.slot) (a : A) : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => ∀ (m' e' : Bool) (asid' va' : U64), obj.Slot.set_cap st slot s1 (.Frame fp fsz fr fd m' e' asid' va') ⦃ s2 => - ∀ (e root asid ipa ptr : U64) (dev : Bool) (attr : U64), + ∀ (e root asid ipa ptr : U64) (dev : Bool) (attr : U64), (e = 0#u64 ∨ DescTo e fp) → ept.install_s2_leaf st ar s2 a lu e root asid ipa ptr dev attr ⦃ r => ArmQIAt st H Cs OS Vc ia ie s r.1 ∧ TabKeepOrZero st s r.1 ⦄ ⦄ ⦄ := WP.spec_mono (sched.set_thread_state.unmMid I D) fun s1 h1 m' e' asid' va' => - WP.spec_mono (pgMapE_set I D P B Y hcs h1.1 m' e' asid' va') fun s2 h2 e root asid ipa ptr dev attr => - WP.spec_mono (ept.install_s2_leaf.ptw hA (I.del.vr.al _ (Or.inl hx)) hx s2 a e root asid ipa ptr dev attr) - fun _ w => ArmQIAt.thenPtW I P.heap P.os hpk h2 w + WP.spec_mono (pgMapE_set I D P B Y hcs h1.1 m' e' asid' va') fun s2 h2 e root asid ipa ptr dev attr he => + WP.spec_mono (ept.install_s2_leaf.slotE hA (I.del.vr.al _ (Or.inl hx)) s2 a e root asid ipa ptr dev attr) + fun _ w => ArmQIAt.thenPtW I P.heap P.os hpk h2.1 h2.2 hx w.1 (by + rcases w.2 with h | h | h + · exact Or.inl h + · exact Or.inr (Or.inl h) + · rcases he with h0 | hd + · exact Or.inr (Or.inl (h.trans h0)) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨slot, P.src, fp, fsz, fr, fd, fm, fe, fa, fv, hcs, + by rw [h]; exact hd⟩)))) /-! ## The root and the walks -/ @@ -205,11 +229,15 @@ theorem ept.map_frame.armQ (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {s : S} {c {fr : U64} {fd fm fe : Bool} {fa fv : U64} (hcs : capA st s slot = .Frame fp fsz fr fd fm fe fa fv) (hTe : Te ⊆ Pt) (h2 : S2DecTy st Pp Te Re hPl.ipa s) {root : U64} (hr : root ∈ Te) (hre : Re root + 1 = s2lv hPl.ipa) (hr2 : wa root 4096#u64 ∈ Te) - (hre2 : Re (wa root 4096#u64) + 1 = s2lv hPl.ipa) (a : A) (asid ipa vm attr masid mvaddr : U64) : + (hre2 : Re (wa root 4096#u64) + 1 = s2lv hPl.ipa) (hfa : fp.val % 4096 = 0) (a : A) + (asid ipa vm attr masid mvaddr : U64) : ept.map_frame st ar s a root asid ipa vm attr fp fsz fr fd masid mvaddr slot ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + have hfpC : CapRt.Canonical fp := by + have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ + rw [hcs] at hw; cases fe <;> exact hw.1 have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) unfold ept.map_frame refine WP.spec_bind (P0.capability.FrameSize.bits.p0 fsz) fun shift _ => ?_ rw [hPl.ipa_eq a, bind_ok] @@ -227,8 +255,9 @@ theorem ept.map_frame.armQ (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {s : S} {c refine WP.spec_bind (ept.lookup_slot.d h2 hr hre hr2 hre2 ipa) fun lu hlu => ?_ refine spec_ite (fun _ => by errQ) (fun _ => ?_) refine WP.spec_bind (P0.vspace.rights_readable.p0 _) fun cr _ => ?_ - refine WP.spec_bind (P0.layout.paddr.p0 fp) fun pa _ => ?_ - refine WP.spec_bind (P0.ept.make_s2_leaf.p0 pa vm cr attr shift) fun e _ => ?_ + refine WP.spec_bind (paddr_spec fp) fun pa hpa => ?_ + subst hpa + refine WP.spec_bind (s2leaf_desc hfpC hfa vm cr attr shift) fun e he => ?_ refine WP.spec_bind (sched.cur_thread.spec s) fun ct ect => ?_ have ec : ct = L.curW s := ect subst ec @@ -236,7 +265,7 @@ theorem ept.map_frame.armQ (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {s : S} {c repeat' (refine spec_ite (fun _ => ?_) (fun _ => ?_)) all_goals refine WP.spec_bind (h1 _ _ _ _) fun s2 h2' => ?_ - refine WP.spec_bind (h2' _ _ _ _ _ _ _) ?_ + refine WP.spec_bind (h2' _ _ _ _ _ _ _ he) ?_ rintro ⟨s3, a1⟩ h3 first | exact (WP.spec_ok _).2 h3 @@ -250,14 +279,17 @@ theorem ept.map_table.armQ (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} {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) (hpk : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) {ptr : U64} {m : Bool} {ma mv : U64} - (hcs : capA st s slot = .PageTable ptr m ma mv) + (hcs : capA st s slot = .PageTable ptr m ma mv) (hm : m = false) (hpa4 : ptr.val % 4096 = 0) (hTe : Te ⊆ Pt) (h2 : S2DecTy st Pp Te Re hPl.ipa s) {root : U64} (hr : root ∈ Te) (hre : Re root + 1 = s2lv hPl.ipa) (hr2 : wa root 4096#u64 ∈ Te) (hre2 : Re (wa root 4096#u64) + 1 = s2lv hPl.ipa) (a : A) (asid ipa : U64) : ept.map_table st ar s a root asid ipa ptr slot ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + have hptC : CapRt.Canonical ptr := by + have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ + rw [hcs] at hw; exact hw.1 have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) unfold ept.map_table rw [hPl.ipa_eq a, bind_ok] refine WP.spec_bind (P0.ept.ipa_limit.p0 _) fun _ _ => ?_ @@ -273,11 +305,12 @@ theorem ept.map_table.armQ (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} {s refine WP.spec_bind (sched.cur_thread.spec s) fun ct ect => ?_ have ec : ct = L.curW s := ect subst ec - refine WP.spec_bind (ptMap_tailQ I D P B Y hpk hcs (ptw_mono hTe hlu)) fun s1 h1 => ?_ + refine WP.spec_bind (ptMap_tailQ I D P B Y hpk hcs hm (ptw_mono hTe hlu)) fun s1 h1 => ?_ refine WP.spec_bind (h1 _ _) fun s2 h2' => ?_ - refine WP.spec_bind (P0.layout.paddr.p0 _) fun _ _ => ?_ - refine WP.spec_bind (P0.ept.make_s2_table.p0 _) fun _ _ => ?_ - refine WP.spec_bind (h2' _) fun s3 h3 => ?_ + refine WP.spec_bind (paddr_spec _) fun pa hpa => ?_ + subst hpa + refine WP.spec_bind (s2tab_desc hptC hpa4) fun tv htv => ?_ + refine WP.spec_bind (h2' _ htv) fun s3 h3 => ?_ exact (WP.spec_ok _).2 h3 end maps @@ -300,7 +333,8 @@ theorem syscall.decode_invocation.pgMapS_armQIAt (hA : P0.ArchTotal ar) (hPl : A (.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) (Hy : ArmDecHyps st H Pt hPl.ipa s (.Frame fp fsz fr fd fm fe fa fv)) - (hcap : obj.Slot.cap st slot s = ok (.Frame fp fsz fr fd fm fe fa fv)) (a : A) + (hcap : obj.Slot.cap st slot s = ok (.Frame fp fsz fr fd fm fe fa fv)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMPageMap) (len : U64) (blk call don fp' : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Frame fp fsz fr fd fm fe fa fv) blk call don fp' buf extra @@ -310,8 +344,12 @@ theorem syscall.decode_invocation.pgMapS_armQIAt (hA : P0.ArchTotal ar) (hPl : A obtain ⟨x, hx0, p0, l0, m0, as0, va0, hxc⟩ := ex0_ept hEx have hS : P0.StoreTotal st := L.total have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) have hcs : capA st s slot = .Frame fp fsz fr fd fm fe fa fv := okinj ((capA_eq s slot).symm.trans hcap) + have hfa : fp.val % 4096 = 0 := by + cases fd + · exact frame_al4k B P.heap P.src hcs + · exact Hy.frAl fp fsz fr fm fe fa fv rfl obtain ⟨Pp, Tb, Lv, Te, Re, hPp, hTb, hTe, hvs, h2⟩ := Hy.vs unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ @@ -347,8 +385,8 @@ theorem syscall.decode_invocation.pgMapS_armQIAt (hA : P0.ArchTotal ar) (hPl : A obtain ⟨hrT, hre, hrT2, hre2⟩ := hr _ rfl dsimp only at hrT hre hrT2 hre2 simp only [irq_branch_ok, bind_ok] - have mf := fun ma mv => ept.map_frame.armQ hA hPl I D P B Y Hy.ptKs hcs hTe h2 hrT hre hrT2 hre2 a asid1 vaddr vm - attr ma mv + have mf := fun ma mv => ept.map_frame.armQ hA hPl I D P B Y Hy.ptKs hcs hTe h2 hrT hre hrT2 hre2 hfa a asid1 vaddr + vm attr ma mv refine spec_ite (fun _ => ?_) (fun _ => mf _ _) refine spec_ite (fun _ => mf _ _) (fun _ => by errQ) @@ -376,8 +414,9 @@ theorem syscall.decode_invocation.ptMapS_armQIAt (hA : P0.ArchTotal ar) (hPl : A obtain ⟨x, hx0, p0, l0, m0, as0, va0, hxc⟩ := ex0_ept hEx have hS : P0.StoreTotal st := L.total have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) have hcs : capA st s slot = .PageTable ptr mp ma mv := okinj ((capA_eq s slot).symm.trans hcap) + have hpa4 : ptr.val % 4096 = 0 := (Hy.ptCap ptr mp ma mv rfl).2.2 have h1 : lbl ≠ fl4_abi.label.ARMPageTableUnmap := by lbl_neM2 obtain ⟨Pp, Tb, Lv, Te, Re, hPp, hTb, hTe, hvs, h2⟩ := Hy.vs unfold syscall.decode_invocation @@ -395,7 +434,8 @@ theorem syscall.decode_invocation.ptMapS_armQIAt (hA : P0.ArchTotal ar) (hPl : A rw [hx0, bind_ok] try dsimp only refine spec_ite (fun _ => ?_) (fun _ => by errQ) - refine spec_ite (fun _ => by errQ) (fun _ => ?_) + refine spec_ite (fun _ => by errQ) (fun hmp => ?_) + have hm : mp = false := by simpa using hmp refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun vaddr1 _ => ?_ refine WP.spec_bind (show obj.Slot.cap st x s ⦃ c => c = .Ept p0 l0 m0 as0 va0 ⦄ by rw [hxc]; exact (WP.spec_ok _).2 rfl) fun vcap hv => ?_ @@ -413,7 +453,7 @@ theorem syscall.decode_invocation.ptMapS_armQIAt (hA : P0.ArchTotal ar) (hPl : A obtain ⟨hrT, hre, hrT2, hre2⟩ := hr _ rfl dsimp only at hrT hre hrT2 hre2 simp only [irq_branch_ok, bind_ok] - exact ept.map_table.armQ hPl I D P B Y Hy.ptKs hcs hTe h2 hrT hre hrT2 hre2 a asid1 vaddr1 + exact ept.map_table.armQ hPl I D P B Y Hy.ptKs hcs hm hpa4 hTe h2 hrT hre hrT2 hre2 a asid1 vaddr1 end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbEptQ.lean b/proofs/Fl4ProofsA64/P1/MdbEptQ.lean index d778c97e7..37512c082 100644 --- a/proofs/Fl4ProofsA64/P1/MdbEptQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbEptQ.lean @@ -34,6 +34,9 @@ follows a level-3 page descriptor (`e & 3 = 3`) at shift 21 and ends in a frame, on reachable states and keeps the walk in `Pt`; the walk reads `Arch::s2_ipa_bits`, so the arm needs the platform constant ([P] `ArchPlat ar`) and the clause at that constant. +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ept.decode.armQ` and `ept_armQIAt` also post `ArmVsK` (last +conjunct; MdbVsFlQ's `restart_armQ`). + Named premises: QueueS2Ty's [P] `ArchPlat.s2_ipa_bits_const` (existing; the walks take `hPl`). Case facts: none new. -/ import Fl4ProofsA64.P1.MdbVsMapC @@ -101,10 +104,10 @@ theorem ept.decode.armQ (hA : P0.ArchTotal ar) {s : S} {cap0 : capability.Cap} { (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (a : A) (lbl len : U64) (c : capability.Cap) (sl buf : U64) : ept.decode st ar s a lbl len c sl buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by have hS : P0.StoreTotal st := L.total - have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s := + (fun h => ⟨h.1, h.2, ArmVsK.refl s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) have rst := sched.set_thread_state.restart_armQ I D P B Y hks unfold ept.decode simp only [lift, bind_ok] @@ -119,7 +122,7 @@ theorem syscall.decode_invocation.ept_armQIAt (hA : P0.ArchTotal ar) {s : S} (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Ept p l m ad v) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ try dsimp only diff --git a/proofs/Fl4ProofsA64/P1/MdbEptUnmQ.lean b/proofs/Fl4ProofsA64/P1/MdbEptUnmQ.lean index 2156b0694..81f2b8409 100644 --- a/proofs/Fl4ProofsA64/P1/MdbEptUnmQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbEptUnmQ.lean @@ -116,9 +116,9 @@ theorem syscall.decode_invocation.ptUnmapS_armQIAt (hA : P0.ArchTotal ar) (hPl : ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by have hS : P0.StoreTotal st := L.total have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) have hcs : capA st s slot = .PageTable ptr mp ma mv := okinj ((capA_eq s slot).symm.trans hcap) - obtain ⟨hpt, hpw⟩ := Hy.ptCap ptr mp ma mv rfl + obtain ⟨hpt, hpw, -⟩ := Hy.ptCap ptr mp ma mv rfl obtain ⟨Pp, Tb, Lv, Te, Re, hPp, hTb, hTe, hvs, h2⟩ := hV have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ rw [hcs] at hw diff --git a/proofs/Fl4ProofsA64/P1/MdbFpuL.lean b/proofs/Fl4ProofsA64/P1/MdbFpuL.lean index 5bf175874..a9498902e 100644 --- a/proofs/Fl4ProofsA64/P1/MdbFpuL.lean +++ b/proofs/Fl4ProofsA64/P1/MdbFpuL.lean @@ -23,6 +23,9 @@ off every other heap object (`HeapOK.disj`) and off the `OS` slots, the state bl (`DFB` with `FrBw` extra words); the old lemmas are their projections, statements unchanged (MdbArmDfB's `readFpu_armQI`). +(A64-S1A gen 29) **`frame_off_words`**: the 128 words at a checked offset of a frame object, aligned and inside it +(shared by MdbRunQ's `runBuf_of`, MdbVcStQ's `frU_of`, MdbDelVsZ's `RunBuf.frUb`; those two proof bodies now read it). + Named premises: none. No case fact. Not covered here: TCB GetBreakpoint / ReadRegisters (the IPC-buffer writes, which need the buffer word's alignment, handoff §112). -/ @@ -97,6 +100,42 @@ theorem frame_words (hH : HeapOK H) {ptr offset bits : U64} (hp : H ptr = some ( 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⟩ +/-- (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) + (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) : + Aligned (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)) ∧ + ptr.val ≤ (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val ∧ + (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val < ptr.val + 2 ^ bits.val := by + have hb64 : bits.val < 64 ∧ 12 ≤ bits.val := by + cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp + have hszv : sz.val = 2 ^ bits.val := by + have := shl1_val hb64.1 + rw [hsz, WP.spec_ok] at this + exact this + have ho : off.val % 64 = 0 := by + have e := congrArg UScalar.val h63 + rw [UScalar.val_and, show (63#u64).val = 2 ^ 6 - 1 from rfl, Nat.and_two_pow_sub_one_eq_mod] at e + 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 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 + have : (core.num.U64.wrapping_mul i 8#u64).val = i.val * 8 := by + simp [core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits]; omega + rw [core.num.U64.wrapping_add_val_eq, this, hpo] + simp [U64.size_def, U64.numBits]; omega + refine ⟨?_, ?_, ?_⟩ + · unfold Aligned at hal ⊢; rw [hv]; rw [hpo] at hal; omega + · rw [hv]; omega + · rw [hv]; omega + /-- **`fpu_transfer`'s size and offset checks with their facts** (QueueFpu's `fpu_chk`, which drops them). -/ theorem fpu_chkO {A : Type _} (s : S) (a : A) (sz : capability.FrameSize) (offset : U64) {Q : (core.result.Result Unit error.Exc) × S × A → Prop} @@ -163,6 +202,17 @@ def FrBw (H : Heap) (OS : Set U64) (b : U64) : Prop := (∃ ptr z, H ptr = some (.other z) ∧ 12 ≤ z ∧ ptr.val ≤ b.val ∧ b.val < ptr.val + 2 ^ z) ∧ ∀ y ∈ OS, ¬ (y.val ≤ b.val ∧ b.val < y.val + 32) +variable (st) in +/-- **A word of the object of a non-device `Frame` cap of an `OS` slot** (MdbArmVsG; A64-S1A gen 30: moved here, beside `FrBw`). -/ +def FrCw (OS : Set U64) (s0 : S) (b : U64) : Prop := + ∃ y ∈ OS, ∃ ptr size rights x1 x2 x3 x4 bits, capA st s0 y = .Frame ptr size rights false x1 x2 x3 x4 ∧ + capability.FrameSize.bits size = ok bits ∧ ptr.val ≤ b.val ∧ b.val < ptr.val + 2 ^ bits.val + +/-- `FrCw` read at a later state keeping the caps of `OS`. -/ +theorem FrCw.keepO {s0 s1 : S} (k : OSKeep st OS s0 s1) {b : U64} (h : FrCw st OS s0 b) : FrCw st OS s1 b := by + obtain ⟨y, hy, ptr, size, rights, x1, x2, x3, x4, bits, hc, hb, h1, h2⟩ := h + exact ⟨y, hy, ptr, size, rights, x1, x2, x3, x4, bits, by rw [k.capA hy]; exact hc, hb, h1, h2⟩ + set_option maxHeartbeats 4000000 in /-- (gen 141) **`readL` with the end's `BlkOK` and the exact frame** (the body of `readL`, moved): a `DFB` step from the decode's start whose extra words are `FrBw` words (the frame's 65 words). -/ @@ -175,7 +225,7 @@ theorem tcb.fpu_transfer.readLK (hA : P0.ArchTotal ar) {s s1 : S} {a1 : A} {t le tcb.fpu_transfer st ar s1 a1 t { length := len, buf, call, slot, extra } true ⦃ r => (SysL st H Cs OS ia ie r.2.1 ∧ SymL st H Cs r.2.1) ∧ BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac r.2.1 ∧ - DFB st H Cs (L.curW s) ∅ (FrBw H OS) s r.2.1 ⦄ := by + DFB st H Cs (L.curW s) ∅ (fun b => FrBw H OS b ∧ FrCw st OS s b) s r.2.1 ⦄ := by have hS : P0.StoreTotal st := L.total have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT have hKo : ∀ o : U64, o.val ∈ (∅ : Set Nat) → o.val < 224 → ∀ y ∈ OS, @@ -183,7 +233,7 @@ theorem tcb.fpu_transfer.readLK (hA : P0.ArchTotal ar) {s s1 : S} {a1 : A} {t le fun _ h => absurd h (Set.notMem_empty _) have E1 : (SysL st H Cs OS ia ie s1 ∧ SymL st H Cs s1) ∧ BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s1 ∧ - DFB st H Cs (L.curW s) ∅ (FrBw H OS) s s1 := + DFB st H Cs (L.curW s) ∅ (fun b => FrBw H OS b ∧ FrCw st OS s b) s s1 := ⟨SysL.df (Ko := ∅) P D.bxi D.run hKo B Y d1, h1.bxi.blk, DFB.ofDF d1⟩ have osk : ∀ {s' : S}, DF st H Cs (L.curW s) ∅ s s' → OSKeep st OS s s' := fun {s'} d => by have h := D.bxi.blk @@ -199,7 +249,7 @@ theorem tcb.fpu_transfer.readLK (hA : P0.ArchTotal ar) {s s1 : S} {a1 : A} {t le have E : ∀ (m : Result (core.result.Result Unit error.Exc)), m ⦃ _ => True ⦄ → (do let r ← m; ok (r, s1, a1)) ⦃ r => (SysL st H Cs OS ia ie r.2.1 ∧ SymL st H Cs r.2.1) ∧ BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac r.2.1 ∧ - DFB st H Cs (L.curW s) ∅ (FrBw H OS) s r.2.1 ⦄ := + DFB st H Cs (L.curW s) ∅ (fun b => FrBw H OS b ∧ FrCw st OS s b) s r.2.1 ⦄ := fun m hm => WP.spec_bind hm fun _ _ => (WP.spec_ok _).2 E1 refine WP.spec_bind (tcb.extra.mem0 _) fun o ho => ?_ rcases o with _ | x @@ -270,15 +320,16 @@ theorem tcb.fpu_transfer.readLK (hA : P0.ArchTotal ar) {s s1 : S} {a1 : A} {t le simp only [lift, bind_ok, obj.Tcb.fpu_addr, ite_true] unfold tcb.copy_words 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 := fun b hb => by - have hin := (hW b hb).1 - refine ⟨(hW b hb).2, ⟨ptr, bits.val, hH, h12, hin⟩, fun y hy g => ?_⟩ + 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 => ?_⟩, + 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) - (fun y hy b g1 g2 hb => (hBo b hb).2.2 y hy ⟨g1, g2⟩) B2 Y2 + (fun y hy b g1 g2 hb => (hBo b hb).1.2.2 y hy ⟨g1, g2⟩) B2 Y2 have K3 := (blk_of_capw h2 w3 fun b hb => Or.inr (hW b hb).2).1 - have F3 : DFB st H Cs (L.curW s) ∅ (FrBw H OS) s s3 := - (DFB.ofDF d2).trans (DFB.ofBw (LvC.of_blk h2) (w3.mono hBo) fun b hb => hb.1) + have F3 : DFB st H Cs (L.curW s) ∅ (fun b => FrBw H OS b ∧ FrCw st OS s b) s s3 := + (DFB.ofDF d2).trans (DFB.ofBw (LvC.of_blk h2) (w3.mono hBo) fun b hb => hb.1.1) refine (WP.spec_ok _).2 ?_ first | exact ⟨X3, K3, F3⟩ @@ -317,7 +368,7 @@ theorem tcb.decode.readFpuLK (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len b tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => (SysL st H Cs OS ia ie r.2.1 ∧ SymL st H Cs r.2.1) ∧ BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac r.2.1 ∧ - DFB st H Cs (L.curW s) ∅ (FrBw H OS) s r.2.1 ⦄ := by + DFB st H Cs (L.curW s) ∅ (fun b => FrBw H OS b ∧ FrCw st OS s b) s r.2.1 ⦄ := by unfold tcb.decode refine WP.spec_bind (Stalled.stallD hA (Stalled.refl0 D) (DF.refl s)) ?_ rintro ⟨s1, a1⟩ ⟨h1, d1⟩ diff --git a/proofs/Fl4ProofsA64/P1/MdbFrE.lean b/proofs/Fl4ProofsA64/P1/MdbFrE.lean index dda034a2b..02c971d22 100644 --- a/proofs/Fl4ProofsA64/P1/MdbFrE.lean +++ b/proofs/Fl4ProofsA64/P1/MdbFrE.lean @@ -37,26 +37,26 @@ namespace W7 namespace R namespace ST -/-- **A non-device frame `d` stands for a non-device frame `c` of the same base and size, and a `Zombie` `d` for the -same `Zombie`** (module docstring). -/ +/-- **A frame `d` stands for a frame `c` of the same base, size and device bit** (A64-S1A gen 36, Architect 01:07Z J1: +widened from non-device frames), **and a `Zombie` `d` for the same `Zombie`** (module docstring). -/ def FE (d c : capability.Cap) : Prop := - (∀ ptr size rights x1 x2 x3 x4, d = .Frame ptr size rights false x1 x2 x3 x4 → - ∃ r y1 y2 y3 y4, c = .Frame ptr size r false y1 y2 y3 y4) ∧ + (∀ ptr size rights dv x1 x2 x3 x4, d = .Frame ptr size rights dv x1 x2 x3 x4 → + ∃ r y1 y2 y3 y4, c = .Frame ptr size r dv y1 y2 y3 y4) ∧ (∀ p t n, d = .Zombie p t n → c = .Zombie p t n) ∧ (∀ p b i e, d = .Untyped p b i e → ∃ i0, c = .Untyped p b i0 e) ∧ (kindA d ≠ 0 → kindA d = kindA c) theorem FE.refl (c : capability.Cap) : FE c c := - ⟨fun _ _ r x1 x2 x3 x4 h => ⟨r, x1, x2, x3, x4, h⟩, fun _ _ _ h => h, fun _ _ i _ h => ⟨i, h⟩, fun _ => rfl⟩ + ⟨fun _ _ r _ x1 x2 x3 x4 h => ⟨r, x1, x2, x3, x4, h⟩, fun _ _ _ h => h, fun _ _ i _ h => ⟨i, h⟩, fun _ => rfl⟩ /-- (gen 102) **A non-null `FE` result keeps its source's kind** (the last conjunct). -/ theorem FE.kind {d c : capability.Cap} (h : FE d c) (hd : kindA d ≠ 0) : kindA d = kindA c := h.2.2.2 hd theorem FE.trans {a b c : capability.Cap} (h1 : FE a b) (h2 : FE b c) : FE a c := by - refine ⟨fun ptr size r x1 x2 x3 x4 h => ?_, fun p t n h => h2.2.1 p t n (h1.2.1 p t n h), fun p b i e h => ?_, + refine ⟨fun ptr size r dv x1 x2 x3 x4 h => ?_, fun p t n h => h2.2.1 p t n (h1.2.1 p t n h), fun p b i e h => ?_, fun hd => ?_⟩ - · obtain ⟨r', y1, y2, y3, y4, e⟩ := h1.1 ptr size r x1 x2 x3 x4 h - exact h2.1 ptr size r' y1 y2 y3 y4 e + · obtain ⟨r', y1, y2, y3, y4, e⟩ := h1.1 ptr size r dv x1 x2 x3 x4 h + exact h2.1 ptr size r' dv y1 y2 y3 y4 e · obtain ⟨i0, e0⟩ := h1.2.2.1 p b i e h exact h2.2.2.1 p b i0 e e0 · have e1 := h1.2.2.2 hd @@ -64,20 +64,20 @@ theorem FE.trans {a b c : capability.Cap} (h1 : FE a b) (h2 : FE b c) : FE a c : /-- A cap that is neither a non-device frame nor a `Zombie` nor an untyped stands for any cap of its kind (gen 102: `hk`, any cap if it is `Null`). -/ -theorem FE.nf {d : capability.Cap} (h : ∀ ptr size rights x1 x2 x3 x4, d ≠ .Frame ptr size rights false x1 x2 x3 x4) +theorem FE.nf {d : capability.Cap} (h : ∀ ptr size rights dv x1 x2 x3 x4, d ≠ .Frame ptr size rights dv x1 x2 x3 x4) (hz : ∀ p t n, d ≠ .Zombie p t n) (hu : ∀ p b i e, d ≠ .Untyped p b i e) (c : capability.Cap) (hk : kindA d ≠ 0 → kindA d = kindA c) : FE d c := - ⟨fun ptr size rights x1 x2 x3 x4 e => absurd e (h ptr size rights x1 x2 x3 x4), fun p t n e => absurd e (hz p t n), + ⟨fun ptr size rights dv x1 x2 x3 x4 e => absurd e (h ptr size rights dv x1 x2 x3 x4), fun p t n e => absurd e (hz p t n), fun p b i e he => absurd he (hu p b i e), hk⟩ theorem FE.null (c : capability.Cap) : FE .Null c := - FE.nf (fun _ _ _ _ _ _ _ e => by cases e) (fun _ _ _ e => by cases e) (fun _ _ _ _ e => by cases e) c + FE.nf (fun _ _ _ _ _ _ _ _ e => by cases e) (fun _ _ _ e => by cases e) (fun _ _ _ _ e => by cases e) c (fun h => absurd rfl h) /-- An untyped cap stands for an untyped cap of the same base, size and device bit (gen 70). -/ theorem FE.ut {d : capability.Cap} (h : isUtA d = true) {c : capability.Cap} (hu : ∀ p b i e, d = .Untyped p b i e → ∃ i0, c = .Untyped p b i0 e) : FE d c := - ⟨fun _ _ _ _ _ _ _ e => by rw [e] at h; simp [isUtA] at h, fun _ _ _ e => by rw [e] at h; simp [isUtA] at h, hu, + ⟨fun _ _ _ _ _ _ _ _ e => by rw [e] at h; simp [isUtA] at h, fun _ _ _ e => by rw [e] at h; simp [isUtA] at h, hu, fun _ => by cases d <;> simp [isUtA] at h obtain ⟨i0, e⟩ := hu _ _ _ _ rfl @@ -92,7 +92,7 @@ set_option hygiene false in local macro "fe" : tactic => `(tactic| ( first | exact FE.refl _ - | exact ⟨fun _ _ _ _ _ _ _ h => by cases h <;> exact ⟨_, _, _, _, _, rfl⟩, fun _ _ _ h => by cases h <;> rfl, + | exact ⟨fun _ _ _ _ _ _ _ _ h => by cases h <;> exact ⟨_, _, _, _, _, rfl⟩, fun _ _ _ h => by cases h <;> rfl, fun _ _ _ _ h => by cases h <;> exact ⟨_, rfl⟩, fun h => by first | rfl | exact absurd rfl h⟩)) /-- **`mask_cap_rights` keeps a frame's base, size and device bit, and makes no frame of another kind.** -/ diff --git a/proofs/Fl4ProofsA64/P1/MdbFrOff.lean b/proofs/Fl4ProofsA64/P1/MdbFrOff.lean index 2eef50301..0b7a368ab 100644 --- a/proofs/Fl4ProofsA64/P1/MdbFrOff.lean +++ b/proofs/Fl4ProofsA64/P1/MdbFrOff.lean @@ -79,7 +79,7 @@ theorem FrOffP.mono {OS' : Set U64} {kb : U64} {c : capability.Cap} (hs : ∀ x /-- **`FrOffP` along `(AlikeA ∨ Null) ∧ FE`** (`FE` keeps a non-device frame's base and size). -/ theorem FrOffP.al {kb : U64} {d c : capability.Cap} (_ : AlikeA d c ∨ d = .Null) (hf : FE d c) (h : FrOffP Cs OS kb c) : FrOffP Cs OS kb d := fun ptr size rights x1 x2 x3 x4 hd bits hb => by - obtain ⟨r, y1, y2, y3, y4, e⟩ := hf.1 ptr size rights x1 x2 x3 x4 hd + obtain ⟨r, y1, y2, y3, y4, e⟩ := hf.1 ptr size rights false x1 x2 x3 x4 hd exact h ptr size r y1 y2 y3 y4 e bits hb theorem FrOff.ks {kb kb' : U64} {s : S} (e : kb' = kb) (h : FrOff st Cs OS kb s) : FrOff st Cs OS kb' s := e ▸ h diff --git a/proofs/Fl4ProofsA64/P1/MdbFrUb.lean b/proofs/Fl4ProofsA64/P1/MdbFrUb.lean index 1623520b6..25b3b3d2b 100644 --- a/proofs/Fl4ProofsA64/P1/MdbFrUb.lean +++ b/proofs/Fl4ProofsA64/P1/MdbFrUb.lean @@ -45,7 +45,7 @@ theorem FrUbP.zombie (Ub : Set U64) (p t n : U64) : FrUbP Ub (.Zombie p t n) := /-- `FrUbP` along `FE` (the frame's pointer and size kept). -/ theorem FrUbP.fe {d c : capability.Cap} (e : FE d c) (h : FrUbP Ub c) : FrUbP Ub d := by intro ptr size rights x1 x2 x3 x4 hd - obtain ⟨r, y1, y2, y3, y4, e0⟩ := e.1 ptr size rights x1 x2 x3 x4 hd + obtain ⟨r, y1, y2, y3, y4, e0⟩ := e.1 ptr size rights false x1 x2 x3 x4 hd exact h ptr size r y1 y2 y3 y4 e0 /-- `FrUbP` along `AlikeA ∧ FE` (MdbCapI's `ciA` closure). -/ diff --git a/proofs/Fl4ProofsA64/P1/MdbGrowN.lean b/proofs/Fl4ProofsA64/P1/MdbGrowN.lean index 3d58d3f5a..33e3ab355 100644 --- a/proofs/Fl4ProofsA64/P1/MdbGrowN.lean +++ b/proofs/Fl4ProofsA64/P1/MdbGrowN.lean @@ -323,7 +323,7 @@ variable {A : Type _} {ar : machine.Arch A} /-- (gen 142) **`sysLN` with MdbLiveU's `UtEndB` at every creation end** (`sysLN`'s body, moved, over `sysLB`); `sysLN` is its projection. -/ -theorem untyped.decode.sysLNB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} +theorem untyped.decode.sysLNBH (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {ia ie : Nat} (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) @@ -334,18 +334,37 @@ theorem untyped.decode.sysLNB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} (win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) → (H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ hi = p.val + 2 ^ sb.val)) → - UtEndB st Cs H1 s1 s' dev aligned nt us win → I H' (OS1 ∪ NewSl dev nt us aligned win) s') : + UtEndB st Cs H1 s1 s' dev aligned nt us win → WinHi st s' aligned nt us win.val → I H' (OS1 ∪ NewSl dev nt us aligned win) s') : untyped.decode st ar s0 a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => ∃ (H' : Heap) (OS' : Set U64), SysL st H' Cs OS' ia ie s' ∧ I H' OS' s' ⦄ := by - refine WP.spec_mono (untyped.decode.sysLB hA D P B hcap hfm a lbl len buf + refine WP.spec_mono (untyped.decode.sysLBH hA D P B hcap hfm a lbl len buf (fun H' O s' => ∃ Nw : Set U64, ((L.ksb s').val + 788736 ≤ 2 ^ 64 → FreshN st O Nw s') ∧ I H' (O ∪ Nw) s') ⟨∅, fun _ => FreshN.empty OS s0, by rw [Set.union_empty]; exact hI0⟩ - fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp UB => - ⟨NewSl dev nt us aligned win, fun hk => E.freshN X hk, hI H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp UB⟩) + fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp UB WH => + ⟨NewSl dev nt us aligned win, fun hk => E.freshN X hk, hI H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp UB WH⟩) ?_ rintro ⟨r, s', a'⟩ ⟨H', O, B', Nw, hF, hI'⟩ exact ⟨H', O ∪ Nw, B'.growN (hF B'.ly.ksw), hI'⟩ +/-- Project the original post from the shared creation proof. -/ +theorem untyped.decode.sysLNB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {ia ie : Nat} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) (hfm : A64FrameMasks st s0) (a : A) + (lbl len buf : U64) (I : Heap → Set U64 → S → Prop) (hI0 : I H OS s0) + (hI : ∀ (H1 H' : Heap) (OS1 : Set U64) (s1 s' : S) (lo hi : Nat) (aligned nt us dest off win : U64), + UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win → UtX H H1 lo hi us → + (win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) → + (H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ + hi = p.val + 2 ^ sb.val)) → + UtEndB st Cs H1 s1 s' dev aligned nt us win → I H' (OS1 ∪ NewSl dev nt us aligned win) s') : + untyped.decode st ar s0 a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + ∃ (H' : Heap) (OS' : Set U64), SysL st H' Cs OS' ia ie s' ∧ I H' OS' s' ⦄ := + untyped.decode.sysLNBH hA D P B hcap hfm a lbl len buf I hI0 + fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp UB _ => + hI H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp UB + /-- **`sysLZ` with the slot set grown by the new TCBs' and CNodes' slots** (module docstring): `I` at `OS1 ∪ NewSl …` at every creation's end, `SysL` there by `SysL.growN` / `UtEnd.freshN`. -/ theorem untyped.decode.sysLN (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} diff --git a/proofs/Fl4ProofsA64/P1/MdbHiVsArm.lean b/proofs/Fl4ProofsA64/P1/MdbHiVsArm.lean index bfb493103..1849798b8 100644 --- a/proofs/Fl4ProofsA64/P1/MdbHiVsArm.lean +++ b/proofs/Fl4ProofsA64/P1/MdbHiVsArm.lean @@ -19,12 +19,22 @@ MdbPoolDelR's `ArmQI.ofDelR`). post MdbPoolA's `ArmQIAt` (the same facts at the decode's own `(H, OS)`); each is the body of the name without `At`, moved, and that name is now its `ArmQIAt.toQI` projection (statement unchanged). +(A64-S1A gen 37) `insert_with_cap.poolR`'s `hpc` is `CapSrc st OS s0 nc` (the source `Untyped` branch by `CapSrc.ut`); +`install_tcb_cap` passes `CapSrc.al` of the source slot's carry (`TcbK.ptSrc` no longer used); `ArmQIAt.ofPR` takes +`PoolR.capSrc`. + +(A64-S1A gen 40, Architect ruling for gen 40, R3) **`tcb.restart_caller.armVsK`**: the caller's restart after the +stall as an `ArmVsK` step with `OSKeep` (`delRP`'s keeping step before its `.toZ`). + +(A64-S1A gen 41) **`cdt.insert_with_cap.armVsK`**: the insert's `OS` footprint keeps every placed `VsR` word. + Named premises: none. Case facts: MdbDelIn's `DelIn`; MdbPoolN's ruled `PoolIdx` at the decode's state; the class fact `FinKZ` (MdbPoolDelR, discharged for `S2Q` by `finKZ_s2`). -/ import Fl4ProofsA64.P1.MdbPoolDelR import Fl4ProofsA64.P1.MdbInsJ import Fl4ProofsA64.P1.MdbTcbCapL +import Fl4ProofsA64.P1.MdbDelVsZ open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P1 @@ -47,18 +57,71 @@ variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : its projection). -/ theorem ArmQIAt.ofPR {s0 s : S} (hS : SysL st H Cs OS ia ie s ∧ SymL st H Cs s) (hb : ∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s) - (hv : VcCap st Vc OS s0 → VcCap st Vc OS s) (Q : PoolR st OS s0 s) : + (hv : VcCap st Vc OS s0 → VcCap st Vc OS s) (Q : PoolR st OS s0 s) (hV : ArmVs st H OS Vc s0 s) : ArmQIAt st H Cs OS Vc ia ie s0 s ∧ TabKeepOrZero st s0 s := have ht := Q.2.1 ⟨⟨hS.1, hS.2, hb, hv, PoolOff.ofTZ ht, Q.2.2, - fun _ hPI0 => PoolIdx.of_frame ht.1 ht.old (fun y hy p b hc => Q.ap y hy p b hc) hPI0, Q.ptCap⟩, ht⟩ + fun _ hPI0 => PoolIdx.of_frame ht.1 ht.old (fun y hy p b hc => Q.ap y hy p b hc) hPI0, Q.capSrc, hV⟩, ht⟩ /-- **The generic deletion-family wrapper** (module docstring). -/ theorem ArmQI.ofPR {s0 s : S} (hS : SysL st H Cs OS ia ie s ∧ SymL st H Cs s) (hb : ∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s) (hv : VcCap st Vc OS s0 → VcCap st Vc OS s) (Q : PoolR st OS s0 s) : ArmQI st H Cs OS Vc ia ie s0 s ∧ TabKeepOrZero st s0 s := - (fun h => ⟨h.1.toQI, h.2⟩) (ArmQIAt.ofPR hS hb hv Q) + have ht := Q.2.1 + ⟨⟨H, OS, hS.1, hS.2, hb, hv, PoolOff.ofTZ ht, Q.2.2, + fun _ hPI0 => PoolIdx.of_frame ht.1 ht.old (fun y hy p b hc => Q.ap y hy p b hc) hPI0⟩, ht⟩ + +/-- (A64-S1A gen 31) **A `DF` step from the decode's state keeps every placed `VsR` word** (MdbArmVsF's +`ArmVsK.ofDF`, its `¬ AsW` by MdbArmTab's `DfW.notAsW` at the decode's `TabF`): the stall's frame, for +`ArmQIAt.ofStall` and the restart's `ArmVsZ` carry. -/ +theorem DF.armVsK {Vc' Ub' Pt' : Set U64} {Ko : Set Nat} {c : U64} {s s' : S} (hH : HeapOK H) + (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) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt') (h0 : 0#u64 ∈ Cs) + (d : DF st H Cs c Ko s s') : ArmVsK st H OS Vc s s' := by + have q := hb.1.choose_spec.choose_spec + have F : TabF st H Cs OS s := TabF.of hvr q B.ly.ksw h0 + exact ArmVsK.ofDF q d fun b hd => DfW.notAsW hH F hvr (fun c hc => q.nodes c hc) hd + +/-- (A64-S1A gen 31) `DF.armVsK` at the decode's state (the stall). -/ +theorem ArmVsK.ofDFI {Rp Nt : Set U64} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot c : U64} {Ko : Set Nat} {s s1 : S} (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 Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (d : DF st H Cs c Ko s s1) : ArmVsK st H OS Vc s s1 := + DF.armVsK P.heap D.bxi B I.del.vr P.core0 d + +/-- (A64-S1A gen 31) **`insert_with_cap` keeps the deletion family's `ArmVsZ ∧ FrC` carry** (MdbArmVsG's +`ArmVsZ.thenOS`: `lrF`'s write set is `OS`-slot words; `FrC`: the destination holds a cap `FE`-derived from the +source's (`hfr`, e.g. `FrUbP.fe`), the source keeps its cap or becomes an `Untyped`, every other `OS` slot is kept). -/ +theorem cdt.insert_with_cap.armVsZ {T Ω Sg : Set U64} (hO : OSOK T Ω Sg OS) {s0 s : S} (hm : MdbS st OS s) + {src dest : U64} {nc sc : capability.Cap} (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) + (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hsc0 : sc ≠ .Null) (hw : CapRt.EncWf nc) + (hfr : ∀ Ub', FrUbP Ub' sc → FrUbP Ub' nc) (Z : ArmVsZ st H OS Vc s0 s ∧ FrC st OS s0 s) : + cdt.insert_with_cap st s nc sc src dest ⦃ s' => ArmVsZ st H OS Vc s0 s' ∧ FrC st OS s0 s' ⦄ := + WP.spec_mono (cdt.insert_with_cap.lrF hO.inOS (LR.self s) hsrc hd hsd hdc hsc hsc0 hw (hm.lnk hO hsrc).2) + fun s' ⟨w, _, ed, _, _, ek, es⟩ => by + refine ⟨Z.1.thenOS w ?_, fun Ub' hf y hy => ?_⟩ + · rintro b (⟨t, ht, -⟩ | ⟨hb, -⟩) + · exact absurd ht (Set.notMem_empty _) + · exact hb + · have hf' := Z.2 Ub' hf + by_cases a1 : y = dest + · rw [a1, ed]; exact hfr Ub' (by rw [← hsc]; exact hf' src hsrc) + · by_cases a2 : y = src + · subst a2 + rcases es with e | ⟨_, _, _, _, e⟩ + · rw [e]; exact hf' y hy + · rw [e]; exact fun _ _ _ _ _ _ _ h => by cases h + · rw [ek y hy a2 a1]; exact hf' y hy + +/-- **`insert_with_cap` keeps every placed `VsR` word**: its write footprint contains only `OS` slot words. -/ +theorem cdt.insert_with_cap.armVsK {T Ω Sg : Set U64} (hO : OSOK T Ω Sg OS) {s : S} (hm : MdbS st OS s) + {src dest : U64} {nc sc : capability.Cap} (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) + (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hsc0 : sc ≠ .Null) (hw : CapRt.EncWf nc) : + cdt.insert_with_cap st s nc sc src dest ⦃ s' => ArmVsK st H OS Vc s s' ⦄ := + WP.spec_mono (cdt.insert_with_cap.lrF hO.inOS (LR.self s) hsrc hd hsd hdc hsc hsc0 hw (hm.lnk hO hsrc).2) + fun _ ⟨w, _, _, _, _, _, _⟩ => ⟨w.1, fun _ _ hvr _ => vsk_cw0 hvr w⟩ theorem TcbK.noAp {c : capability.Cap} (h : TcbK c) : NoAp c := by intro p b e @@ -76,7 +139,7 @@ theorem cdt.insert_with_cap.poolR {T Ω Sg : Set U64} (hO : OSOK T Ω Sg OS) {s0 {Ω' Sg' : Set U64} (hR : VrOK Ω' Sg' Scs Z OS Vc Ub (L.ksb s0) Pt) (hk : L.ksb s = L.ksb s0) (hm : MdbS st OS s) {src dest : U64} {nc sc : capability.Cap} (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hsc0 : sc ≠ .Null) - (hw : CapRt.EncWf nc) (hnsc : NoAp sc) (hnc : NoAp nc) (hpc : PtSrc st OS s0 nc) (hd0 : capA st s dest = .Null) + (hw : CapRt.EncWf nc) (hnsc : NoAp sc) (hnc : NoAp nc) (hpc : CapSrc st OS s0 nc) (hd0 : capA st s dest = .Null) (Q : PoolR st OS s0 s) : cdt.insert_with_cap st s nc sc src dest ⦃ s' => PoolR st OS s0 s' ⦄ := WP.spec_mono (cdt.insert_with_cap.lrF hO.inOS (LR.self s) hsrc hd hsd hdc hsc hsc0 hw (hm.lnk hO hsrc).2) fun s' ⟨w, _, ed, _, _, ek, es⟩ => by @@ -97,7 +160,7 @@ theorem cdt.insert_with_cap.poolR {T Ω Sg : Set U64} (hO : OSOK T Ω Sg OS) {s0 · subst a2 rcases es with e | ⟨_, _, _, _, e⟩ · rw [e]; exact (Q.1 y hy).2 - · rw [e]; exact PtSrc.ut s0 _ _ _ _ + · rw [e]; exact CapSrc.ut s0 _ _ _ _ · rw [ek y hy a2 a1]; exact (Q.1 y hy).2 · have a1 : y ≠ dest := fun e => by rw [e, hd0] at hcy; cases hcy have a2 : y ≠ src := fun e => by rw [e, hsc] at hcy; exact hnsc p b hcy @@ -106,31 +169,34 @@ theorem cdt.insert_with_cap.poolR {T Ω Sg : Set U64} (hO : OSOK T Ω Sg OS) {s0 set_option maxHeartbeats 4000000 in /-- **`install_tcb_cap` keeps `DelR ∧ PoolR`** (MdbInsJ's `tcb.install_tcb_cap.delR` text). -/ theorem tcb.install_tcb_cap.delRP {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) - (hKZ : FinKZ st ar (L.ksb s0) Ty K) (hPI : PoolIdx st OS s0) - (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) {a : A} {target slot index src : U64} + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) + (Z : ArmVsZ st H OS Vc s0 s ∧ FrC st OS s0 s) {a : A} {target slot index src : U64} {nc : capability.Cap} (ht : target ∈ H.tcbs) (hi : index.val < 7) (hi2 : index.val ≠ 2) (hslot : slot ∈ OS) (hsrc : src ≠ 0#u64 → src ∈ OS) (hnc : nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) (hi5 : index.val ≠ 5) : tcb.install_tcb_cap st ar s a target slot index nc src ⦃ r => - DelR st H Cs OS Vc Ub Ac Ty ia ie s0 r.2.1 ∧ PoolR st OS s0 r.2.1 ⦄ := by + DelR st H Cs OS Vc Ub Ac Ty ia ie s0 r.2.1 ∧ PoolR st OS s0 r.2.1 ∧ + ArmVsZ st H OS Vc s0 r.2.1 ∧ FrC st OS s0 r.2.1 ⦄ := by have hx := R.slot I ht hi unfold tcb.install_tcb_cap rw [tcb_slot_val] simp only [bind_ok] - refine WP.spec_bind (WP.spec_and (cdt.delete.delRP I hKZ hPI R Q hx) (cdt.delete.nullR I R hx)) ?_ - rintro ⟨r, s1, a1⟩ ⟨⟨R1, Q1⟩, n1⟩ - try simp only [uncurry_apply_pair] at R1 Q1 n1 ⊢ + refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.delete.delRP I hKZ hPI R Q hx) + (cdt.delete.armVsZ I hKZ R Z.2 Z.1 hx)) (cdt.delete.nullR I R hx)) ?_ + rintro ⟨r, s1, a1⟩ ⟨⟨⟨R1, Q1⟩, Z1⟩, n1⟩ + try simp only [uncurry_apply_pair] at R1 Q1 Z1 n1 ⊢ rcases r with v | e swap · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 ⟨R1, Q1⟩ + exact (WP.spec_ok _).2 ⟨R1, Q1, Z1⟩ simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] have hy0 : capA st s1 (slotIdx target index) = .Null := okinj ((capA_eq s1 _).symm.trans (n1 v rfl)) refine WP.spec_bind (spec_eqv (P0.capability.Cap.is_null.p0 nc)) fun bn hbn => ?_ split - · exact (WP.spec_ok _).2 ⟨R1, Q1⟩ + · exact (WP.spec_ok _).2 ⟨R1, Q1, Z1⟩ rename_i hbf have hnc0 : nc ≠ .Null := by rintro rfl @@ -139,7 +205,7 @@ theorem tcb.install_tcb_cap.delRP {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K refine WP.spec_bind (tcb.still_valid.soa s1 target slot nc src) fun b hb => ?_ split swap - · exact (WP.spec_ok _).2 ⟨R1, Q1⟩ + · exact (WP.spec_ok _).2 ⟨R1, Q1, Z1⟩ rename_i hbt obtain ⟨hs0, hso, hst⟩ := hb hbt obtain ⟨hK, hw⟩ := hnc hnc0 @@ -153,13 +219,16 @@ theorem tcb.install_tcb_cap.delRP {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K exact hK.noAp _ _ e' unfold cdt.insert rw [capA_eq, bind_ok] - refine WP.spec_bind (WP.spec_and (cdt.insert_with_cap.delR I R1 hsO hx hxy (I.del.dcan _ hx) rfl hy0 + refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.insert_with_cap.delR I R1 hsO hx hxy (I.del.dcan _ hx) rfl hy0 (tcb_slot_notBufS I.del.heap ht hi hi2) ⟨slot, hslot, by rw [soa_thread hst]; exact CovZ.tcbSlot I.del.heap ht hi⟩ hw hnc0 C hty (tcb_slot_notEptS I.del.heap ht hi hi5)) (cdt.insert_with_cap.poolR I.del.os I.del.vr R1.jv.ksb R1.sys.sys.stz.1.1.mdbS hsO hx.1 hxy - (I.del.dcan _ hx) rfl C.nn hw hnsc hK.noAp hK.ptSrc hy0 Q1)) fun s2 h2 => ?_ - exact (WP.spec_ok _).2 h2 + (I.del.dcan _ hx) rfl C.nn hw hnsc hK.noAp + (CapSrc.al (Or.inl C.al) C.fe (Q1.1 src hsO).2) hy0 Q1)) + (cdt.insert_with_cap.armVsZ I.del.os R1.sys.sys.stz.1.1.mdbS hsO hx.1 hxy (I.del.dcan _ hx) rfl C.nn hw + (fun _ => FrUbP.fe C.fe) Z1)) fun s2 h2 => ?_ + exact (WP.spec_ok _).2 ⟨h2.1.1, h2.1.2, h2.2⟩ set_option maxHeartbeats 1000000 in /-- **The caller's restart after the stall keeps `PoolR`** beside MdbDelIn's `RsR ∧ DelR` (module docstring). -/ @@ -171,7 +240,7 @@ theorem tcb.restart_caller.delRP {s s1 : S} {cap : capability.Cap} {extra : Aene (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : tcb.restart_caller st s1 ⦃ s2 => (RsR st H Cs OS ia ie H.replies H.ntfns Ac extra slot s s2 ∧ DelR st H Cs OS Vc Ub Ac Ty ia ie s s2) ∧ - PoolR st OS s s2 ⦄ := by + PoolR st OS s s2 ∧ ArmVsZ st H OS Vc s s2 ∧ FrC st OS s s2 ⦄ := by have hW : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 have q1 := h1.bxi.1.choose_spec.choose_spec have hct : L.curW s1 ∈ H.tcbs := q1.curT @@ -180,17 +249,36 @@ theorem tcb.restart_caller.delRP {s s1 : S} {cap : capability.Cap} {extra : Aene rintro s2 ⟨⟨R, R2⟩, w2⟩ have ds : DS st H.tcbs OS Vc s s2 := ds1.trans (DS.sts I.del.os I.del.vc q1 hW hct w2) have vk : VsKeep st (L.ksb s) Pt s s2 := vk1.trans (vsk_sts I.del.vr q1 hct w2) - exact ⟨⟨R, R2⟩, PoolR.keep (PoolR.refl s) ds.1 R2.jv.ksb fun j => vk _ (Or.inr (asW_at _ j))⟩ + have k2 : ArmVsK st H OS Vc s1 s2 := ⟨w2.1, fun _ _ hvr _ => vsk_sts hvr q1 hct w2⟩ + have k := (ArmVsK.ofDFI I D P B d1).trans ds1.1 k2 + exact ⟨⟨R, R2⟩, PoolR.keep (PoolR.refl s) ds.1 R2.jv.ksb fun j => vk _ (Or.inr (asW_at _ j)), k.toZ, + fun _ hf => FrUb.keepO hf ds.1⟩ + +/-- (A64-S1A gen 40) **The caller's restart after the stall as a keeping step**: `delRP`'s `ArmVsK` (before its +`.toZ`) with the `OS` words kept, for the non-deleting arms' exported `ArmVsK`. -/ +theorem tcb.restart_caller.armVsK {s s1 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) : + tcb.restart_caller st s1 ⦃ s2 => ArmVsK st H OS Vc s s2 ∧ OSKeep st OS s s2 ⦄ := by + have hW : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 + have q1 := h1.bxi.1.choose_spec.choose_spec + have hct : L.curW s1 ∈ H.tcbs := q1.curT + refine WP.spec_mono (tcb.restart_caller.sts (q1.nodes _ q1.cur) (q1.tcbs _ hct)) fun s2 w2 => ?_ + have k2 : ArmVsK st H OS Vc s1 s2 := ⟨w2.1, fun _ _ hvr _ => vsk_sts hvr q1 hct w2⟩ + exact ⟨(ArmVsK.ofDFI I D P B d1).trans ds1.1 k2, (ds1.trans (DS.sts I.del.os I.del.vc q1 hW hct w2)).1⟩ /-- (gen 147, ruling (a)) **`ArmQI.ofStall` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, `ArmQI.ofStall` its projection). -/ theorem ArmQIAt.ofStall {s s1 : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) - (hS : SysL st H Cs OS ia ie s1 ∧ SymL st H Cs s1) : + (hS : SysL st H Cs OS ia ie s1 ∧ SymL st H Cs s1) (hK : ArmVsK st H OS Vc s s1) : ArmQIAt st H Cs OS Vc ia ie s s1 ∧ TabKeepOrZero st s s1 := ArmQIAt.ofPR hS ⟨Ac, h1.bxi.blk⟩ (fun h => h.keepO ds1.1) - (PoolR.keep (PoolR.refl s) ds1.1 d1.1.1 fun j => vk1 _ (Or.inr (asW_at _ j))) + (PoolR.keep (PoolR.refl s) ds1.1 d1.1.1 fun j => vk1 _ (Or.inr (asW_at _ j))) hK.toVs /-- **An error leaf at the stalled state** (`ArmQI.ofPR`; the stall keeps every `OS` word and every `VsR` word). -/ theorem ArmQI.ofStall {s s1 : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) @@ -198,26 +286,27 @@ theorem ArmQI.ofStall {s s1 : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) (hS : SysL st H Cs OS ia ie s1 ∧ SymL st H Cs s1) : ArmQI st H Cs OS Vc ia ie s s1 ∧ TabKeepOrZero st s s1 := - (fun h => ⟨h.1.toQI, h.2⟩) (ArmQIAt.ofStall I h1 d1 ds1 vk1 hS) + ArmQI.ofPR hS ⟨Ac, h1.bxi.blk⟩ (fun h => h.keepO ds1.1) + (PoolR.keep (PoolR.refl s) ds1.1 d1.1.1 fun j => vk1 _ (Or.inr (asW_at _ j))) set_option hygiene false in /-- An error leaf at the stalled state (`SysL.df`, `ArmQIAt.ofStall`). -/ local macro "qleaf" : tactic => `(tactic| first | exact (WP.spec_ok _).2 (ArmQIAt.ofStall I h1 d1 ds1 vk1 - (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1)) + (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) (ArmVsK.ofDFI I D P B d1)) | (simp only [error.invalid_cap, error.truncated, error.illegal, bind_ok, core.result.Result.Insts.CoreOpsTry.branch, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] exact (WP.spec_ok _).2 (ArmQIAt.ofStall I h1 d1 ds1 vk1 - (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1)))) + (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) (ArmVsK.ofDFI I D P B d1)))) set_option maxHeartbeats 4000000 in /-- (gen 147, ruling (a)) **`tcb.decode_set_high_vspace.armQI` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, `tcb.decode_set_high_vspace.armQI` its projection). -/ theorem tcb.decode_set_high_vspace.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -234,9 +323,9 @@ theorem tcb.decode_set_high_vspace.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} let s2 ← tcb.restart_caller st s1 tcb.install_tcb_cap st ar s2 a1 t slot layout.tcb.SLOT_HIGH_VSPACE nc x) ⦃ r => ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ⦄ := fun nc x _ hx hnc => - WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2⟩ => - WP.spec_mono (tcb.install_tcb_cap.delRP I hKZ hPI R2 Q2 ht hi hi2 P.src (fun _ => hx) hnc - (by simp [layout.tcb.SLOT_HIGH_VSPACE])) fun _ h => ArmQIAt.ofDelR h.1 h.2 + WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2, Z2⟩ => + WP.spec_mono (tcb.install_tcb_cap.delRP I hKZ hPI R2 Q2 Z2 ht hi hi2 P.src (fun _ => hx) hnc + (by simp [layout.tcb.SLOT_HIGH_VSPACE])) fun _ h => ArmQIAt.ofDelR h.1 h.2.1 h.2.2.1.toVs unfold tcb.decode_set_high_vspace refine WP.spec_bind (tcb.extra.mem0 _) ?_ rintro o ho @@ -272,7 +361,7 @@ set_option maxHeartbeats 4000000 in text). -/ theorem tcb.decode_set_high_vspace.armQI {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -294,7 +383,7 @@ set_option maxHeartbeats 2000000 in `tcb.decode.highVSQ` its projection). -/ theorem tcb.decode.highVSQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBSetHighVSpace) : @@ -315,7 +404,7 @@ set_option maxHeartbeats 2000000 in /-- **TCB SetHighVSpace to `ArmQI ∧ TabKeepOrZero`** (MdbTcbCapL's `tcb.decode.highVSL` text). -/ theorem tcb.decode.highVSQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBSetHighVSpace) : @@ -332,7 +421,7 @@ theorem tcb.decode.highVSQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf body moved here, `syscall.decode_invocation.highVS_armQI` its projection). -/ theorem syscall.decode_invocation.highVS_armQIAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetHighVSpace) (len : U64) @@ -342,7 +431,7 @@ theorem syscall.decode_invocation.highVS_armQIAt (hA : P0.ArchTotal ar) {s : S} unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split - · exact (WP.spec_ok _).mpr (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) + · exact (WP.spec_ok _).mpr (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) · exact WP.spec_mono (tcb.decode.highVSQAt hA I hKZ hPI D P B Y hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact d @@ -351,7 +440,7 @@ theorem syscall.decode_invocation.highVS_armQIAt (hA : P0.ArchTotal ar) {s : S} `highVS_sysL` text). -/ theorem syscall.decode_invocation.highVS_armQI (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetHighVSpace) (len : U64) diff --git a/proofs/Fl4ProofsA64/P1/MdbInsL.lean b/proofs/Fl4ProofsA64/P1/MdbInsL.lean index 06b14f0ae..34cb8472f 100644 --- a/proofs/Fl4ProofsA64/P1/MdbInsL.lean +++ b/proofs/Fl4ProofsA64/P1/MdbInsL.lean @@ -75,7 +75,7 @@ theorem insC_of {nc sc : capability.Cap} (hp : capability.Cap.ptr nc = capabilit have es : sizeA nc = sizeA sc := okinj ((sizeA_eq nc).symm.trans (hs.trans (sizeA_eq sc))) refine ⟨UB.of_not fun p b i e => by rw [e] at hu; simp [isUtA] at hu, ⟨⟨fun ⟨a1, _, a3⟩ => ⟨eh ▸ a1, hus, hf ▸ a3⟩, fun ⟨a1, _, a3⟩ => ⟨eh ▸ a1, hu, hf ▸ a3⟩⟩, fun _ => ⟨by unfold clsA; rw [ep, es], hk⟩⟩, hz, - ⟨fun _ _ _ _ _ _ _ e => by rw [e] at hfn; simp [isFrA] at hfn, fun p t n e => absurd e (hz p t n), + ⟨fun _ _ _ _ _ _ _ _ e => by rw [e] at hfn; simp [isFrA] at hfn, fun p t n e => absurd e (hz p t n), fun _ _ _ _ e => by rw [e] at hu; simp [isUtA] at hu, fun _ => hk⟩, ⟨eh, ep, es, hu.trans hus.symm, fun _ _ _ _ e => by rw [e] at hu; simp [isUtA] at hu⟩, hus, fun e => hk0 (by rw [e]; rfl)⟩ @@ -188,7 +188,7 @@ theorem InsC.frame {p : U64} {sz : capability.FrameSize} {r r' a a' v v' : U64} (sizeA_eq _))) refine ⟨UB.of_not (fun _ _ _ h => by cases h), ⟨⟨(fun h => by simp [RngKeyA, isFrA] at h), (fun h => by simp [RngKeyA, isFrA] at h)⟩, (fun h => by simp [RngKeyA, isFrA] at h)⟩, (fun _ _ _ h => by cases h), - ⟨(fun _ _ _ _ _ _ _ h => by cases h; exact ⟨r', m', e', a', v', rfl⟩), (fun _ _ _ h => by cases h), + ⟨(fun _ _ _ _ _ _ _ _ h => by cases h; exact ⟨r', m', e', a', v', rfl⟩), (fun _ _ _ h => by cases h), (fun _ _ _ _ h => by cases h), fun _ => rfl⟩, ⟨eh, ep, es, rfl, (fun _ _ _ _ h => by cases h)⟩, rfl, fun h => by cases h⟩ diff --git a/proofs/Fl4ProofsA64/P1/MdbIrqCQ.lean b/proofs/Fl4ProofsA64/P1/MdbIrqCQ.lean index 778b29222..0a5b83709 100644 --- a/proofs/Fl4ProofsA64/P1/MdbIrqCQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbIrqCQ.lean @@ -15,6 +15,10 @@ with the end `BlkOK`, the `VcCap` carry and MdbPoolDelR's `PoolR`, then MdbHiVsA * Arms: **`interrupt.decode_irq_control_msi.armQAt`**, **`interrupt.decode_irq_control.armQAt`** (MdbIrqC's walk, every error leaf `ArmQIAt.ofPR` at the decode's state), top **`syscall.decode_invocation.irqCtl_armQIAt`**. +(A64-S1A gen 37, K1) the new `IrqHandler` cap's carry by `CapSrc.irq`. +(A64-S1A gen 41) the IRQ-state write and CTE insert keep every placed `VsR` word. The invocation +and decode tops export their `ArmVsK` as the last conjunct. + Named premises: QueueDecIrq's [P] `MaxSpi` (the arch's `max_spi ≤ 1019`, existing; a pure arch-level platform contract, placed beside `P0.ArchTotal`). Case facts: MdbDelIn's `DelIn` (its `IrqStApart`, `VrOK`). -/ @@ -46,7 +50,7 @@ theorem interrupt.set_irq_state.tabK (hA : P0.ArchTotal ar) {Ω' Sg' Scs' Vc' Ub {s : S} (a : A) (v irq : U64) (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (hvr : VrOK Ω' Sg' Scs' Z' OS Vc' Ub' (L.ksb s) Pt') (hi : irq.val < 5376) : - interrupt.set_irq_state st ar s a v irq ⦃ r => TabKeep st s r.1 ⦄ := by + interrupt.set_irq_state st ar s a v irq ⦃ r => TabKeep st s r.1 ∧ ArmVsK st H OS Vc s r.1 ⦄ := by have q := h.1.choose_spec.choose_spec unfold interrupt.set_irq_state interrupt.state_off simp only [lift, bind_ok] @@ -61,57 +65,107 @@ theorem interrupt.set_irq_state.tabK (hA : P0.ArchTotal ar) {Ω' Sg' Scs' Vc' Ub have h8 : o.val % 8 = 0 := by omega refine WP.spec_bind (hA.mask_irq a irq _) fun a1 _ => (WP.spec_ok _).2 ?_ have w : WritesIn st s (L.wr s (wa (L.ksb s) o) v) (· = wa (L.ksb s) o) := writesIn_wr (ks_aligned q ho' h8) - exact TabKeep.ofW hvr w fun b hb hb' => hvr.ks b (Or.inr hb') o ho' hb.symm + exact ⟨TabKeep.ofW hvr w fun b hb hb' => hvr.ks b (Or.inr hb') o ho' hb.symm, + ArmVsK.ofW w fun _ _ hvr' _ b hb hv => hvr'.ks b hv o ho' hb.symm⟩ + +/-! ## The slots' capabilities -/ + +/-- (A64-S1A gen 41) The slot fact of an IrqControl invocation: every `OS` slot keeps its capability, except an empty +one that receives the handler. -/ +def IrqSlots (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s r : S) : Prop := + ∀ z ∈ OS, capA st r z = capA st s z ∨ (capA st s z = .Null ∧ ∃ i, capA st r z = .IrqHandler i) + +theorem IrqSlots.refl (s : S) : IrqSlots st OS s s := fun _ _ => Or.inl rfl + +theorem IrqSlots.after {s q r : S} (keep : OSKeep st OS s q) (h : IrqSlots st OS q r) : IrqSlots st OS s r := + fun z hz => by rw [← keep.capA hz]; exact h z hz /-! ## `invoke_irq_control` -/ set_option maxHeartbeats 4000000 in -/-- **`invoke_irq_control` to `SysL ∧ SymL`, `BlkOK`, `VcCap` and `PoolR`** (module docstring). -/ -theorem interrupt.invoke_irq_control.armQ (hA : P0.ArchTotal ar) (hH : HeapOK H) +/-- **`invoke_irq_control.armQ` exporting the slot fact** (A64-S1A gen 41). -/ +theorem interrupt.invoke_irq_control.armS (hA : P0.ArchTotal ar) (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 s : S} (a : A) {irq y x : U64} (hvr : VrOK Ω' Sg' Scs' Z' OS Vc' Ub' (L.ksb s0) Pt') (hk : L.ksb s = L.ksb s0) (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (hap : IrqStApart OS (L.ksb s)) (hi : irq.val < 5376) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) - (V : VcCap st Vc OS s) (Q : PoolR st OS s0 s) + (V : VcCap st Vc OS s) (Q : PoolR st OS s0 s) (Z : ArmVsZ st H OS Vc s0 s ∧ FrC st OS s0 s) (hx : x ∈ OS) (hsc : capA st s x = .IrqControl) (hy : y ∈ OS) (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) : interrupt.invoke_irq_control st ar s a irq y x ⦃ r => (SysL st H Cs OS ia ie r.1 ∧ SymL st H Cs r.1) ∧ (∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' r.1) ∧ - VcCap st Vc OS r.1 ∧ PoolR st OS s0 r.1 ⦄ := by + VcCap st Vc OS r.1 ∧ PoolR st OS s0 r.1 ∧ ArmVsZ st H OS Vc s0 r.1 ∧ FrC st OS s0 r.1 ∧ + ArmVsK st H OS Vc s r.1 ∧ IrqSlots st OS s r.1 ⦄ := by unfold interrupt.invoke_irq_control refine WP.spec_bind (WP.spec_and (interrupt.set_irq_state.sysL hA hH hO a _ irq h hap hi B Y) - (interrupt.set_irq_state.tabK hA a _ irq h (by rw [hk]; exact hvr) hi)) ?_ + (interrupt.set_irq_state.tabK (Vc := Vc) hA a _ irq h (by rw [hk]; exact hvr) hi)) ?_ rintro ⟨s1, a1⟩ ⟨⟨h1, k1, B1, Y1⟩, t1⟩ try simp only [uncurry_apply_pair] unfold cdt.insert rw [capA_eq, bind_ok, k1.capA hx, hsc] obtain ⟨z, hz, hcz⟩ := hcd - have Q1 : PoolR st OS s0 s1 := PoolR.keepT Q k1 t1 - have hk1 : L.ksb s1 = L.ksb s0 := t1.1.trans hk + have Q1 : PoolR st OS s0 s1 := PoolR.keepT Q k1 t1.1 + have Z1 := ArmVsZ.thenK Z t1.2 k1 + have hk1 : L.ksb s1 = L.ksb s0 := t1.1.1.trans hk have hy0' : capA st s1 y = .Null := by rw [k1.capA hy]; exact hy0 have hsc' : capA st s1 x = .IrqControl := by rw [k1.capA hx]; exact hsc have hxy : x ≠ y := fun e => by rw [e, hy0'] at hsc'; cases hsc' have hm : MdbS st OS s1 := B1.sys.stz.1.1.mdbS have V1 : VcCap st Vc OS s1 := V.keepO k1 have hyc : obj.sext48 y = ok y := OSOK.canon hO hW hy - refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLI (i := irq) hH hO h1.bxi B1 Y1 hx hy hyc + refine WP.spec_bind (WP.spec_and (WP.spec_and (WP.spec_and (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLI (i := irq) hH hO h1.bxi B1 Y1 + hx hy hyc hsc' hy0' hyB hyE ⟨z, hz, by rw [k1.capA hz]; exact hcz⟩) (cdt.insert_with_cap.lrF (nc := .IrqHandler irq) hO (LR.self s1) hx hy hxy hyc hsc' (fun h => by cases h) trivial (hm.lnk hO hx).2)) (cdt.insert_with_cap.poolR (nc := .IrqHandler irq) hO hvr hk1 hm hx hy hxy hyc hsc' (fun h => by cases h) - trivial (fun _ _ h => by cases h) (fun _ _ h => by cases h) (fun _ _ _ _ h => by cases h) hy0' Q1)) ?_ - rintro s2 ⟨⟨hS2, w2, -, ed, -, -, ek, es⟩, q2⟩ - refine (WP.spec_ok _).2 ⟨hS2, ⟨_, (W7.blk_of_capw h1 w2 fun _ h => h).1⟩, fun z hz => ?_, q2⟩ + trivial (fun _ _ h => by cases h) (fun _ _ h => by cases h) (CapSrc.irq _ irq) hy0' Q1)) + (cdt.insert_with_cap.armVsZ (nc := .IrqHandler irq) hO hm hx hy hxy hyc hsc' (fun h => by cases h) trivial + (fun _ _ _ _ _ _ _ _ _ h => by cases h) Z1)) + (cdt.insert_with_cap.armVsK (H := H) (Vc := Vc) (nc := .IrqHandler irq) hO hm hx hy hxy hyc hsc' + (fun h => by cases h) trivial)) + (cdt.insert_with_cap.srcF (nc := .IrqHandler irq) hO hx hy hxy hsc' trivial (hm.lnk hO hx).2)) ?_ + rintro s2 ⟨⟨⟨⟨⟨hS2, w2, -, ed, -, -, ek, -⟩, q2⟩, z2⟩, K2⟩, full⟩ + have slots : IrqSlots st OS s s2 := IrqSlots.after k1 fun z hz => by + by_cases e1 : z = y + · subst e1 + exact Or.inr ⟨hy0', _, ed⟩ + by_cases e2 : z = x + · subst e2 + refine Or.inl (full.elim (fun e => e.trans hsc'.symm) ?_) + rintro ⟨_, _, _, _, _, bad, -⟩ + cases bad + exact Or.inl (ek z hz e2 e1) + refine (WP.spec_ok _).2 ⟨hS2, ⟨_, (W7.blk_of_capw h1 w2 fun _ h => h).1⟩, fun z hz => ?_, q2, + z2.1, z2.2, t1.2.trans k1 K2, slots⟩ by_cases e1 : z = y · rw [e1, ed]; exact fun _ h => by cases h by_cases e2 : z = x · subst e2 - rcases es with e | ⟨p, b, j, d, e⟩ - · rw [e]; exact V1 z hz - · rw [e]; exact VcCapP.ut Vc p b j d + refine full.elim (fun e => by rw [e.trans hsc'.symm]; exact V1 z hz) ?_ + rintro ⟨_, _, _, _, _, bad, -⟩ + cases bad · rw [ek z hz e2 e1]; exact V1 z hz +set_option maxHeartbeats 4000000 in +/-- **`invoke_irq_control` to `SysL ∧ SymL`, `BlkOK`, `VcCap` and `PoolR`** (module docstring). -/ +theorem interrupt.invoke_irq_control.armQ (hA : P0.ArchTotal ar) (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 s : S} (a : A) {irq y x : U64} + (hvr : VrOK Ω' Sg' Scs' Z' OS Vc' Ub' (L.ksb s0) Pt') (hk : L.ksb s = L.ksb s0) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) + (hap : IrqStApart OS (L.ksb s)) (hi : irq.val < 5376) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (V : VcCap st Vc OS s) (Q : PoolR st OS s0 s) (Z : ArmVsZ st H OS Vc s0 s ∧ FrC st OS s0 s) + (hx : x ∈ OS) (hsc : capA st s x = .IrqControl) (hy : y ∈ OS) (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) : + interrupt.invoke_irq_control st ar s a irq y x ⦃ r => (SysL st H Cs OS ia ie r.1 ∧ SymL st H Cs r.1) ∧ + (∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' r.1) ∧ + VcCap st Vc OS r.1 ∧ PoolR st OS s0 r.1 ∧ ArmVsZ st H OS Vc s0 r.1 ∧ FrC st OS s0 r.1 ∧ + ArmVsK st H OS Vc s r.1 ⦄ := + WP.spec_mono (interrupt.invoke_irq_control.armS hA hH hO hW a hvr hk h hap hi B Y V Q Z hx hsc hy hy0 hyB hyE hcd) + fun _ h => ⟨h.1, h.2.1, h.2.2.1, h.2.2.2.1, h.2.2.2.2.1, h.2.2.2.2.2.1, h.2.2.2.2.2.2.1⟩ + /-! ## The caller's restart -/ set_option maxHeartbeats 1000000 in @@ -122,7 +176,7 @@ theorem sched.set_thread_state.restartQ {s : S} {cap : capability.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) : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => - DelR st H Cs OS Vc Ub Ac Ty ia ie s s1 ∧ PoolR st OS s s1 ∧ OSKeep st OS s s1 ⦄ := by + DelR st H Cs OS Vc Ub Ac Ty ia ie s s1 ∧ PoolR st OS s s1 ∧ OSKeep st OS s s1 ∧ ArmVsK st H OS Vc s s1 ⦄ := by have er : tcb.restart_caller st s = sched.set_thread_state st s (L.curW s) sched.TS_RESTART := by unfold tcb.restart_caller; rw [cur_thread_ok, bind_ok] rw [← er] @@ -131,20 +185,20 @@ theorem sched.set_thread_state.restartQ {s : S} {cap : capability.Cap} {extra : have hct : L.curW s ∈ H.tcbs := q1.curT exact WP.spec_mono (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 (DF.refl s) (DS.refl s) (VsKeep.refl s)) (tcb.restart_caller.sts (q1.nodes _ q1.cur) (q1.tcbs _ hct))) - fun s1 ⟨⟨⟨_, R1⟩, Q1⟩, w1⟩ => ⟨R1, Q1, stt_osk P.os q1 hct w1⟩ + fun s1 ⟨⟨⟨_, R1⟩, Q1, _⟩, w1⟩ => ⟨R1, Q1, stt_osk P.os q1 hct w1, ⟨w1.1, fun _ _ hvr _ => vsk_sts hvr q1 hct w1⟩⟩ /-! ## The IRQ control decode -/ set_option hygiene false in /-- An error leaf with the state unchanged. -/ -local macro "errQ" : tactic => `(tactic| first - | exact (WP.spec_ok _).2 (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s from - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) +local macro "errQ" : 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, IrqSlots.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] - exact (WP.spec_ok _).2 (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s from - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)))) + exact (WP.spec_ok _).2 ⟨q, t, ArmVsK.refl s, IrqSlots.refl s⟩))) set_option hygiene false in /-- The target slot's lookup from the extra cap `c` (held by a nonzero extra slot, `ho`) and its empty check. -/ @@ -169,14 +223,15 @@ local macro "tgtQ" : tactic => `(tactic| ( set_option hygiene false in /-- The restart (at the decode's state) and the invocation, after an arch step. -/ local macro "invQ" : tactic => `(tactic| ( - refine WP.spec_bind (sched.set_thread_state.restartQ I D P B Y) fun s1 ⟨R1, Q1, k1⟩ => ?_ + refine WP.spec_bind (sched.set_thread_state.restartQ I D P B Y) fun s1 ⟨R1, Q1, k1, K1⟩ => ?_ refine WP.spec_bind (Pₘ := fun _ => True) (by a64triv) fun a1 _ => ?_ obtain ⟨Ac1, hb1⟩ := R1.jv.1.parts - refine WP.spec_bind (interrupt.invoke_irq_control.armQ hA P.heap P.os P.win a1 I.del.vr R1.jv.ksb hb1.blk - (by rw [R1.jv.ksb]; exact hap) hi R1.sys R1.sym R1.vc Q1 P.src (by rw [k1.capA P.src]; exact hsc) hv + refine WP.spec_bind (interrupt.invoke_irq_control.armS hA P.heap P.os P.win a1 I.del.vr R1.jv.ksb hb1.blk + (by rw [R1.jv.ksb]; exact hap) hi R1.sys R1.sym R1.vc Q1 ⟨K1.toZ, fun _ hf => FrUb.keepO hf k1⟩ P.src (by rw [k1.capA P.src]; exact hsc) hv (by rw [k1.capA hv]; exact hv0) hvB hvE ⟨z, hz, by rw [k1.capA hz]; exact hcz⟩) ?_ - rintro ⟨s2, a2⟩ ⟨h2, b2, v2, q2⟩ - exact (WP.spec_ok _).2 (ArmQIAt.ofPR h2 b2 (fun _ => v2) q2))) + rintro ⟨s2, a2⟩ ⟨h2, b2, v2, q2, z2, _, K2, S2⟩ + obtain ⟨q, t⟩ := ArmQIAt.ofPR h2 b2 (fun _ => v2) q2 z2.toVs + exact (WP.spec_ok _).2 ⟨q, t, K1.trans k1 K2, IrqSlots.after k1 S2⟩)) /-- The decode's walk (MdbIrqC's `gicRL` with the `ArmQIAt` leaves). -/ syntax "gicRQ" : tactic @@ -204,16 +259,15 @@ macro_rules | errQ) set_option maxHeartbeats 4000000 in -/-- **`decode_irq_control_msi` to `ArmQIAt ∧ TabKeepOrZero`** (`GetMSI`; MdbIrqC's `decode_irq_control_msi.sysL` -walk). -/ -theorem interrupt.decode_irq_control_msi.armQAt (hA : P0.ArchTotal ar) {s : S} +/-- **`decode_irq_control_msi.armQAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem interrupt.decode_irq_control_msi.armSAt (hA : P0.ArchTotal ar) {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) (hsc : capA st s slot = .IrqControl) (a : A) (len buf : U64) : interrupt.decode_irq_control_msi st ar s a len slot buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ IrqSlots st OS s s' ⦄ := by have hS : P0.StoreTotal st := L.total have hap : IrqStApart OS (L.ksb s) := I.del.irqSt unfold interrupt.decode_irq_control_msi @@ -251,45 +305,87 @@ theorem interrupt.decode_irq_control_msi.armQAt (hA : P0.ArchTotal ar) {s : S} try simp only [uncurry_apply_pair] try dsimp only split - · refine WP.spec_bind (sched.set_thread_state.restartQ I D P B Y) fun s1 ⟨R1, Q1, k1⟩ => ?_ + · refine WP.spec_bind (sched.set_thread_state.restartQ I D P B Y) fun s1 ⟨R1, Q1, k1, K1⟩ => ?_ obtain ⟨Ac1, hb1⟩ := R1.jv.1.parts - refine WP.spec_bind (interrupt.invoke_irq_control.armQ hA P.heap P.os P.win a1 I.del.vr R1.jv.ksb hb1.blk - (by rw [R1.jv.ksb]; exact hap) hi R1.sys R1.sym R1.vc Q1 P.src (by rw [k1.capA P.src]; exact hsc) hv + refine WP.spec_bind (interrupt.invoke_irq_control.armS hA P.heap P.os P.win a1 I.del.vr R1.jv.ksb hb1.blk + (by rw [R1.jv.ksb]; exact hap) hi R1.sys R1.sym R1.vc Q1 ⟨K1.toZ, fun _ hf => FrUb.keepO hf k1⟩ P.src (by rw [k1.capA P.src]; exact hsc) hv (by rw [k1.capA hv]; exact hv0) hvB hvE ⟨z, hz, by rw [k1.capA hz]; exact hcz⟩) ?_ - rintro ⟨s2, a2⟩ ⟨h2, b2, v2, q2⟩ - exact (WP.spec_ok _).2 (ArmQIAt.ofPR h2 b2 (fun _ => v2) q2) + rintro ⟨s2, a2⟩ ⟨h2, b2, v2, q2, z2, _, K2, S2⟩ + obtain ⟨q, t⟩ := ArmQIAt.ofPR h2 b2 (fun _ => v2) q2 z2.toVs + exact (WP.spec_ok _).2 ⟨q, t, K1.trans k1 K2, IrqSlots.after k1 S2⟩ all_goals errQ set_option maxHeartbeats 4000000 in -/-- **`decode_irq_control` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring; [P] `MaxSpi`). -/ -theorem interrupt.decode_irq_control.armQAt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) {s : S} +/-- **`decode_irq_control_msi` to `ArmQIAt ∧ TabKeepOrZero`** (`GetMSI`; MdbIrqC's `decode_irq_control_msi.sysL` +walk). -/ +theorem interrupt.decode_irq_control_msi.armQAt (hA : P0.ArchTotal ar) {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) (hsc : capA st s slot = .IrqControl) (a : A) (len buf : U64) : + interrupt.decode_irq_control_msi st ar s a len slot 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' ⦄ := + WP.spec_mono (interrupt.decode_irq_control_msi.armSAt hA I D P B Y hsc a len buf) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨h.1, h.2.1, h.2.2.1⟩ + +set_option maxHeartbeats 4000000 in +/-- **`decode_irq_control.armQAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem interrupt.decode_irq_control.armSAt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) {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) (hsc : capA st s slot = .IrqControl) (a : A) (lbl len buf : U64) : interrupt.decode_irq_control st ar s a lbl len slot buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ IrqSlots st OS s s' ⦄ := by have hS : P0.StoreTotal st := L.total have hap : IrqStApart OS (L.ksb s) := I.del.irqSt unfold interrupt.decode_irq_control refine spec_ite (fun _ => ?_) (fun _ => ?_) - · exact interrupt.decode_irq_control_msi.armQAt hA I D P B Y hsc a len buf + · exact interrupt.decode_irq_control_msi.armSAt hA I D P B Y hsc a len buf rw [cur_thread_ok, bind_ok] gicRQ -/-- **The IrqControl arm of `decode_invocation` to `ArmQIAt ∧ TabKeepOrZero`** (every label; [P] `MaxSpi`). -/ -theorem syscall.decode_invocation.irqCtl_armQIAt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) {s : S} +set_option maxHeartbeats 4000000 in +/-- **`decode_irq_control` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring; [P] `MaxSpi`). -/ +theorem interrupt.decode_irq_control.armQAt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) {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) (hsc : capA st s slot = .IrqControl) (a : A) (lbl len buf : U64) : + interrupt.decode_irq_control st ar s a lbl len slot 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' ⦄ := + WP.spec_mono (interrupt.decode_irq_control.armSAt hA hM I D P B Y hsc a lbl len buf) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨h.1, h.2.1, h.2.2.1⟩ + +/-- **`irqCtl_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.irqCtl_armSAt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) {s : S} {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 .IrqControl 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 .IrqControl) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot .IrqControl blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ IrqSlots st OS s s' ⦄ := by unfold syscall.decode_invocation rw [cur_thread_ok, bind_ok] - exact interrupt.decode_irq_control.armQAt hA hM I D P B Y (okinj ((capA_eq s slot).symm.trans hcap)) a lbl len buf + exact interrupt.decode_irq_control.armSAt hA hM I D P B Y (okinj ((capA_eq s slot).symm.trans hcap)) a lbl len buf + +/-- **The IrqControl arm of `decode_invocation` to `ArmQIAt ∧ TabKeepOrZero`** (every label; [P] `MaxSpi`). -/ +theorem syscall.decode_invocation.irqCtl_armQIAt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) {s : S} + {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 .IrqControl 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 .IrqControl) (a : A) (lbl len : U64) + (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot .IrqControl 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' ⦄ := + WP.spec_mono (syscall.decode_invocation.irqCtl_armSAt hA hM I D P B Y hcap a lbl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbLiveU.lean b/proofs/Fl4ProofsA64/P1/MdbLiveU.lean index 49d2244a1..d1d7ad412 100644 --- a/proofs/Fl4ProofsA64/P1/MdbLiveU.lean +++ b/proofs/Fl4ProofsA64/P1/MdbLiveU.lean @@ -84,6 +84,7 @@ bodies, moved; their `hI` also receives `UtEndB`; MdbUtR's `stZFCRUGB` at the RA reset). `dbgX`, `liveR`, `live0I`, `sysLZ` are projections, statements unchanged. -/ import Fl4ProofsA64.P1.MdbLiveC +import Fl4ProofsA64.P1.S1aHiInit open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P1 @@ -836,16 +837,58 @@ theorem WinT.capw {H1 : Heap} {OS1 : Set U64} {s1 : S} {slot p sb fi1 aligned nt rw [hw.mem_eq hwa (in_free_not_capw C.heap hV1 C.src C.cap (by omega) (by omega))] exact h w hwa h1 h2 +/-- Writes to cap slots miss every newly allocated HighVSpace descriptor. -/ +theorem WinHi.capw {H1 : Heap} {OS1 : Set U64} {s1 s s' : S} {slot p sb fi base nt us dest off win : U64} + (C : CrtP st H1 Cs Sg OS1 s1 slot p sb fi false base nt us dest off win) + (hfit : p.val + 2 ^ sb.val ≤ 2 ^ 64) {j : Nat} (hj : j ≤ win.val) + (h : WinHi st s base nt us j) (w : WritesIn st s s' (W7.CapW H1.tcbs H1.omega Sg)) : + WinHi st s' base nt us j := by + intro hn i hi + obtain ⟨-, ha, -, hbase, hwin, -⟩ := C.ar + have hz : (zA nt.val us).val = 13 := by rw [hn]; exact zA_14 us + have hwfit := hwin.trans hfit + obtain ⟨-, -, -, hv, hal⟩ := WinHi.addr hn (lt_of_lt_of_le hi hj) ha hwfit + obtain ⟨⟨-, -, hV, -, -⟩, -, -⟩ := C.stz + have hoff : ¬ W7.CapW H1.tcbs H1.omega Sg (wa (bjA base (zA nt.val us) i) 4088#u64) := + in_free_not_capw C.heap hV C.src C.cap (by rw [hv]; omega) + (by rw [hv]; rw [hz] at hwin; norm_num at hwin; omega) + rw [w.mem_eq hal hoff] + exact h hn i hi + +/-- Initialization sets this object's tag and frames the earlier objects in the window. -/ +theorem create_object.winHi (hA : P0.ArchTotal ar) {H1 : Heap} {OS1 : Set U64} {s1 s : S} + {slot p sb fi base nt us dest off win : U64} + (C : CrtP st H1 Cs Sg OS1 s1 slot p sb fi false base nt us dest off win) + (hfit : p.val + 2 ^ sb.val ≤ 2 ^ 64) (a : A) {j : Nat} (hj : j < win.val) + (h : WinHi st s base nt us j) : + objects.create_object st ar s a nt (bjA base (zA nt.val us) j) us false + ⦃ r => WinHi st r.2.1 base nt us (j + 1) ⦄ := by + by_cases hn : nt.val = 14 + · obtain ⟨-, ha, -, -, hwin, -⟩ := C.ar + have hwfit := hwin.trans hfit + obtain ⟨hv, hf, h8, -, -⟩ := WinHi.addr hn hj ha hwfit + refine WP.spec_mono (WP.spec_and (create_object.highW hA s a nt _ us false hn h8 (by omega)) + (create_object.highInit hA s a nt _ us hn h8 (by omega))) ?_ + rintro r ⟨⟨-, w⟩, init⟩ _ i hi + by_cases hEq : i = j + · simpa only [hEq] using init + have hlt : i < j := by omega + obtain ⟨-, -, -, hw, hwa⟩ := WinHi.addr hn (lt_trans hlt hj) ha hwfit + rw [w.mem_eq hwa (by intro hc; have hC := hc.1; rw [hv, hw] at hC; omega)] + exact h hn i hlt + · exact WP.spec_mono (P0.objects.create_object.p0 st ar s a nt _ us false L.total hA) + fun _ _ hn' => (hn hn').elim + set_option maxHeartbeats 1000000 in /-- (gen 142) **`liveR` with the created `Tcb` window** (`WinT`, stepped by `create_object.dbgXW`; `liveR`'s body, moved); `liveR` is its projection. -/ -theorem untyped.retype.liveRW (hA : P0.ArchTotal ar) {H1 : Heap} {OS1 : Set U64} {s1 : S} +theorem untyped.retype.liveRWH (hA : P0.ArchTotal ar) {H1 : Heap} {OS1 : Set U64} {s1 : S} {slot p sb fi1 aligned nt us dest off win : U64} (C : CrtP st H1 Cs Sg OS1 s1 slot p sb fi1 false aligned nt us dest off win) (hb0 : 0 < aligned.val) (a1 : A) : untyped.retype st ar s1 a1 slot false aligned nt us dest off win false ⦃ r => CrtE st H1 Sg OS1 s1 r.2.1 slot p sb false aligned nt us dest off win ∧ DbgX st H1 s1 nt aligned (zA nt.val us) r.2.1 win.val ∧ - (nt.val = 1 → WinT st r.2.1 aligned (zA nt.val us) win.val) ⦄ := by + (nt.val = 1 → WinT st r.2.1 aligned (zA nt.val us) win.val) ∧ WinHi st r.2.1 aligned nt us win.val ⦄ := by obtain ⟨-, hal, hfi, hA0, hAw, hinj, hcan, -⟩ := C.ar obtain ⟨hSA, -, hK1⟩ := C.stz obtain ⟨hS1', -, hV1, hUZ1, -⟩ := hSA @@ -858,12 +901,15 @@ theorem untyped.retype.liveRW (hA : P0.ArchTotal ar) {H1 : Heap} {OS1 : Set U64} refine WP.spec_mono (untyped.retype.lvRG hA C.heap C.os hT hNl1 hV1 hUZ1 a1 C.src C.cap nt us dest off win aligned false rfl C.hn C.hz hal hfi hA0 hAw hnA C.nc hnF C.hd C.dO C.dn C.dc hinj hcan C.hus (Z2 := fun s j => j ≤ win.val ∧ DbgV st H1 s1 nt aligned (zA nt.val us) s j ∧ - DbgX st H1 s1 nt aligned (zA nt.val us) s j ∧ (nt.val = 1 → WinT st s aligned (zA nt.val us) j)) - (fun s' a' j hj hq _ hd => WP.spec_mono (WP.spec_and (create_object.dbgS hA C.heap hV1 C.src C.cap nt us win + DbgX st H1 s1 nt aligned (zA nt.val us) s j ∧ (nt.val = 1 → WinT st s aligned (zA nt.val us) j) ∧ WinHi st s aligned nt us j) + (fun s' a' j hj hq _ hd => WP.spec_mono (WP.spec_and (WP.spec_and (create_object.dbgS hA C.heap hV1 C.src C.cap nt us win aligned false C.hn hal hA0 hAw hpf hnA hnF C.n0 s' a' j hj hq hd.2.1) - (create_object.dbgXW hA C hb0 s' a' j hj hq hd.2.2.1)) fun _ h => ⟨by omega, h.1, h.2.1, h.2.2 hd.2.2.2⟩) + (create_object.dbgXW hA C hb0 s' a' j hj hq hd.2.2.1)) + (create_object.winHi hA C hpf a' hj hd.2.2.2.2)) fun _ h => + ⟨by omega, h.1.1, h.1.2.1, h.1.2.2 hd.2.2.2.1, h.2⟩) (fun s2 s3 j hd w => ⟨hd.1, DbgV.capw C.heap hV1 C.src C.cap hal hA0 hAw hpf hnA C.nc hd.1 hd.2.1 w, - DbgX.capw C hpf hd.1 hd.2.2.1 w, fun h1 => WinT.capw C hd.1 (hd.2.2.2 h1) w⟩) + DbgX.capw C hpf hd.1 hd.2.2.1 w, (fun h1 => WinT.capw C hd.1 (hd.2.2.2.1 h1) w), + WinHi.capw C hpf hd.1 hd.2.2.2.2 w⟩) (fun s2 w => by have w' : WritesIn st s1 s2 (W7.CapW H1.tcbs H1.omega Sg) := w.mono fun b hb => by rcases hb with e | e @@ -872,9 +918,9 @@ theorem untyped.retype.liveRW (hA : P0.ArchTotal ar) {H1 : Heap} {OS1 : Set U64} exact ⟨Nat.zero_le _, DbgV.capw C.heap hV1 C.src C.cap hal hA0 hAw hpf hnA C.nc (Nat.zero_le _) (DbgV.start H1 s1 nt aligned (zA nt.val us)) w', DbgX.capw C hpf (Nat.zero_le _) (DbgX.start H1 s1 nt aligned (zA nt.val us)) w', - fun _ => WinT.zero s2 aligned (zA nt.val us)⟩)) ?_ - rintro r ⟨-, ⟨⟨G', -, -, -, hold, -, hnew⟩, nf, -, hsr⟩, hW, -, hD, hX, hWT⟩ - refine ⟨⟨hW, hold, ⟨nf, hsr⟩, hnew, hD, fun _ hwk b hb h1 h2 => ?_⟩, hX, hWT⟩ + (fun _ => WinT.zero s2 aligned (zA nt.val us)), fun _ _ h => (Nat.not_lt_zero _ h).elim⟩)) ?_ + rintro r ⟨-, ⟨⟨G', -, -, -, hold, -, hnew⟩, nf, -, hsr⟩, hW, -, hD, hX, hWT, hHi⟩ + refine ⟨⟨hW, hold, ⟨nf, hsr⟩, hnew, hD, fun _ hwk b hb h1 h2 => ?_⟩, hX, hWT, hHi⟩ have hnf : (nwA st s1).val < p.val + fi1.val ∨ p.val + 2 ^ sb.val ≤ (nwA st s1).val := hnF slot C.src p sb fi1 C.cap have hne : ¬ RFw st H1 Sg s1 (WKA nt) aligned (zA nt.val us) win.val b := fun hr => by @@ -890,6 +936,17 @@ theorem untyped.retype.liveRW (hA : P0.ArchTotal ar) {H1 : Heap} {OS1 : Set U64} rw [hW.mem_eq hb hne] exact hUZ1 slot C.src p sb fi1 C.cap b hb (by omega) (by omega) +set_option maxHeartbeats 1000000 in +/-- The original RAM creation post is the projection of the shared HighVSpace-aware loop. -/ +theorem untyped.retype.liveRW (hA : P0.ArchTotal ar) {H1 : Heap} {OS1 : Set U64} {s1 : S} + {slot p sb fi1 aligned nt us dest off win : U64} + (C : CrtP st H1 Cs Sg OS1 s1 slot p sb fi1 false aligned nt us dest off win) (hb0 : 0 < aligned.val) (a1 : A) : + untyped.retype st ar s1 a1 slot false aligned nt us dest off win false ⦃ r => + CrtE st H1 Sg OS1 s1 r.2.1 slot p sb false aligned nt us dest off win ∧ + DbgX st H1 s1 nt aligned (zA nt.val us) r.2.1 win.val ∧ + (nt.val = 1 → WinT st r.2.1 aligned (zA nt.val us) win.val) ⦄ := + WP.spec_mono (untyped.retype.liveRWH hA C hb0 a1) fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ + set_option maxHeartbeats 1000000 in /-- **The RAM creation ends in `CrtE`** (module docstring): MdbUZR's `lvRG` with `DbgV`; (gen 77) and `DbgX` (the base nonzero: no TCB at the null address). -/ @@ -2059,7 +2116,7 @@ theorem UtDecP.blk2 {s0 s2 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slo set_option maxHeartbeats 2000000 in /-- (gen 142) **`live0I` with `UtEndB`** (`BlkOK` at the restart state, `UtDecP.blk2`; the created `Tcb` window, `liveRW`; `live0I`'s body, moved); `live0I` is its projection. -/ -theorem untyped.retype.live0IB (hA : P0.ArchTotal ar) {s0 s2 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} +theorem untyped.retype.live0IBH (hA : P0.ArchTotal ar) {s0 s2 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {ia ie : Nat} (R : UtDecP st H Cs H.frame Rp Nt OS s0 extra slot p sb fi dev) (LN : LiveNamed st H Cs OS ia ie s0) (VR : ValidReplies st H s0) (LY : A64Layout st H OS ia ie s0) (e : sched.set_thread_state st s0 (L.curW s0) sched.TS_RESTART = ok s2) (a : A) @@ -2072,7 +2129,7 @@ theorem untyped.retype.live0IB (hA : P0.ArchTotal ar) {s0 s2 : S} {extra : Aenea (I : Heap → Set U64 → S → Prop) (hI : ∀ (s1 s' : S) (lo hi : Nat), UtEnd st H Cs OS s0 slot p sb dev H H' OS s1 s' lo hi aligned nt us dest off win → - UtEndB st Cs H s1 s' dev aligned nt us win → I H' OS s') : + UtEndB st Cs H s1 s' dev aligned nt us win → WinHi st s' aligned nt us win.val → I H' OS s') : untyped.retype st ar s2 a slot false aligned nt us dest off win dev ⦃ r => (LiveNamed st H' Cs OS ia ie r.2.1 ∧ ValidReplies st H' r.2.1 ∧ A64Layout st H' OS ia ie r.2.1) ∧ I H' OS r.2.1 ⦄ := by @@ -2092,8 +2149,8 @@ theorem untyped.retype.live0IB (hA : P0.ArchTotal ar) {s0 s2 : S} {extra : Aenea · have hKs := R.stz.2.2 slot R.src p sb fi R.cap have hb0 : 0 < aligned.val := lt_of_lt_of_le (LY.ut0 slot R.src p sb fi R.cap) (CrtA.of_args R hU).pa - refine WP.spec_mono (untyped.retype.liveRW hA C hb0 a) fun r ⟨E, X, WT⟩ => ?_ - exact UtEnd.live R LN VR LY (fun U => hI _ _ (p.val + fi.val) (p.val + 2 ^ sb.val) U ⟨hb2, fun _ => WT⟩) + refine WP.spec_mono (untyped.retype.liveRWH hA C hb0 a) fun r ⟨E, X, WT, WH⟩ => ?_ + exact UtEnd.live R LN VR LY (fun U => hI _ _ (p.val + fi.val) (p.val + 2 ^ sb.val) U ⟨hb2, fun _ => WT⟩ WH) (fun _ h _ => h) ⟨CrtA.of_args R hU, fun _ _ h => h, R.stz.1.2.2.1 slot R.src p sb fi R.cap, ⟨fun c hc => (hKs.1 c hc).imp (fun g => by omega) id, hKs.2.imp (fun g => by omega) id⟩, hRT, hKT, @@ -2105,7 +2162,7 @@ theorem untyped.retype.live0IB (hA : P0.ArchTotal ar) {s0 s2 : S} {extra : Aenea fun x hx _ => hx⟩ · refine WP.spec_mono (untyped.retype.liveD C a) fun r ⟨E, X⟩ => ?_ obtain ⟨a1, a2, a3⟩ := hdev rfl - exact UtEnd.live R LN VR LY (fun U => hI _ _ 0 0 U ⟨hb2, fun h => absurd h (by simp)⟩) (fun _ h _ => h) ⟨CrtA.of_args R hU, fun _ _ h => h, + exact UtEnd.live R LN VR LY (fun U => hI _ _ 0 0 U ⟨hb2, fun h => absurd h (by simp)⟩ (fun h => (a3 h).elim)) (fun _ h _ => h) ⟨CrtA.of_args R hU, fun _ _ h => h, fun _ _ _ => Or.inr (Nat.zero_le _), ⟨fun _ _ => Or.inr (Nat.zero_le _), Or.inr (Nat.zero_le _)⟩, hRT, hKT, fun _ h => h, fun x hx _ => hx, R.src, hw1 0 0, fun y hy _ => k.capA hy, C.dO, E, X, fun h => absurd h (by unfold WKA; omega), hHH', hEx, UtArgs.dcv R.ty R.ext hU, @@ -2113,6 +2170,28 @@ theorem untyped.retype.live0IB (hA : P0.ArchTotal ar) {s0 s2 : S} {extra : Aenea fun h => absurd h (by simp), fun h => absurd h (by simp), fun _ => C.fr, C.os, C.heap, fun x hx _ => hx⟩ +set_option maxHeartbeats 2000000 in +/-- Project the original post from the shared creation proof. -/ +theorem untyped.retype.live0IB (hA : P0.ArchTotal ar) {s0 s2 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev : Bool} {ia ie : Nat} (R : UtDecP st H Cs H.frame Rp Nt OS s0 extra slot p sb fi dev) + (LN : LiveNamed st H Cs OS ia ie s0) (VR : ValidReplies st H s0) (LY : A64Layout st H OS ia ie s0) + (e : sched.set_thread_state st s0 (L.curW s0) sched.TS_RESTART = ok s2) (a : A) + {aligned nt us dest off win : U64} (hU : UtArgs st s0 extra slot p sb fi dev false aligned nt us dest off win) + {H' : Heap} (hHH' : ∀ q k, H q = some k → H' q = some k) + (hEx : ∀ q k, H' q = some k → H q = some k ∨ + (dev = false ∧ ∃ j, j < win.val ∧ q = bjA aligned (zA nt.val us) j ∧ newKind nt.val us.val = some k)) + (hHn : dev = false → + ∀ j, j < win.val → ∀ k, newKind nt.val us.val = some k → H' (bjA aligned (zA nt.val us) j) = some k) + (I : Heap → Set U64 → S → Prop) + (hI : ∀ (s1 s' : S) (lo hi : Nat), + UtEnd st H Cs OS s0 slot p sb dev H H' OS s1 s' lo hi aligned nt us dest off win → + UtEndB st Cs H s1 s' dev aligned nt us win → I H' OS s') : + untyped.retype st ar s2 a slot false aligned nt us dest off win dev ⦃ r => + (LiveNamed st H' Cs OS ia ie r.2.1 ∧ ValidReplies st H' r.2.1 ∧ A64Layout st H' OS ia ie r.2.1) ∧ + I H' OS r.2.1 ⦄ := + untyped.retype.live0IBH hA R LN VR LY e a hU hHH' hEx hHn I + fun s1 s' lo hi U B _ => hI s1 s' lo hi U B + set_option maxHeartbeats 2000000 in /-- (gen 77) **`live0` with a further invariant `I`** from the creation's end facts `UtEnd` (kept heap `H`, slots `OS`, the hole the source's free part for RAM, empty for a device). -/ @@ -2295,7 +2374,7 @@ set_option maxHeartbeats 4000000 in /-- (gen 142) **`sysLZ` with `UtEndB` at every creation end** (`BlkOK` at the creation's start and the created `Tcb` window: `live0IB`, MdbUtR's `stZFCRUGB`, a device reset's cap write by `blk_of_capw`; `sysLZ`'s body, moved); `sysLZ` is its projection. -/ -theorem untyped.decode.sysLB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} +theorem untyped.decode.sysLBH (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {ia ie : Nat} (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) @@ -2306,7 +2385,7 @@ theorem untyped.decode.sysLB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} (win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) → (H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ hi = p.val + 2 ^ sb.val)) → - UtEndB st Cs H1 s1 s' dev aligned nt us win → I H' OS1 s') : + UtEndB st Cs H1 s1 s' dev aligned nt us win → WinHi st s' aligned nt us win.val → I H' OS1 s') : untyped.decode st ar s0 a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => ∃ (H' : Heap) (OS' : Set U64), SysL st H' Cs OS' ia ie s' ∧ I H' OS' s' ⦄ := by have R := UtDecP.of_live D B.sys P hcap B.ln B.vr B.ly @@ -2325,16 +2404,16 @@ theorem untyped.decode.sysLB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} R.dbg R.run e R.core0 a R.ext R.src R.cap hU hdev hal hfi hA0 hAw hH' hHH' hHn hinj hcan) (untyped.retype.urU hA R.heap R.os R.win R.ty R.stz R.ur q R.dbg R.run e R.core0 a R.ext R.src R.cap hU hdev hal hfi hA0 hAw hH' hinj hcan)) - (untyped.retype.live0IB hA R B.ln B.vr B.ly e a hU hHH' hEx hHn + (untyped.retype.live0IBH hA R B.ln B.vr B.ly e a hU hHH' hEx hHn (fun H' OS1 s' => (BufInv st H' OS1 s' ∧ CapInv st (IdP (L.idleW s') (L.mem s' (scA (L.idleW s')))) OS1 s' ∧ (CapInv st (ScCapP H'.scs) OS1 s' ∧ CtOff st (L.ksb s') OS1 s' ∧ (FrOff st Cs OS1 (L.ksb s') s' ∧ (EptSlot st H' OS1 s' ∧ IpcAl st H' s')))) ∧ I H' OS1 s') - fun s1 s' lo hi U UB => ⟨⟨U.buf R.heap B0 R.cap, U.ci R B.ly B.ci (UtArgs.devTS hU), + fun s1 s' lo hi U UB WH => ⟨⟨U.buf R.heap B0 R.cap, U.ci R B.ly B.ci (UtArgs.devTS hU), ⟨U.sc R B.ly B.sc (UtArgs.devTS hU) (fun _ _ _ h => h) (fun j hj h5 => ⟨us.val, hHn (UtArgs.dev5 hU h5) j hj _ (by rw [h5]; simp [newKind])⟩), U.ct R B.ly B.ct (UtArgs.us64 hU), ⟨U.fo R B.fo (UtDecP.fo R hal hA0 hAw), ⟨U.ept R.heap B0 B.ep R.cap, U.ipc R.heap R.bxi.choose_spec R.core0 B.ipc⟩⟩⟩⟩, hI H H' OS s1 s' lo hi aligned nt us dest off win U (UtX.refl (UtArgs.us64 hU)) (Or.inr ⟨_, hU⟩) - (Or.inl rfl) UB⟩)) ?_ + (Or.inl rfl) UB WH⟩)) ?_ rintro ⟨r, s', a'⟩ ⟨⟨⟨-, h1, h2, h3⟩, h4⟩, ⟨h5, h6, h7⟩, h8⟩ exact ⟨H', OS, ⟨⟨h1, h2, h3, h4⟩, h5, h6, h7, h8.1.1.cn, h8.1.1.bh, h8.1.2.1, h8.1.2.2.1, h8.1.2.2.2.1, h8.1.2.2.2.2.1, h8.1.2.2.2.2.2.1, h8.1.2.2.2.2.2.2⟩, h8.2⟩ @@ -2363,8 +2442,8 @@ theorem untyped.decode.sysLB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} ⟨(UtEnd.sysL0 R B F U).1, (UtEnd.sysL0 R B F U).2, hI _ _ _ _ _ p.val (p.val + 2 ^ sb.val) p 0#u64 4#u64 0#u64 0#u64 0#u64 U (UtX.drop (R.ur.rin R.src R.cap) (by first | decide | simp)) (Or.inl rfl) (Or.inr ⟨rfl, he, rfl, rfl⟩) - ⟨hb1, fun _ h => absurd h (by simp)⟩⟩) - (fun s1 a1 hw1 keep hb1 C H' _ hHH' hHn hEx => WP.spec_mono (untyped.retype.liveRW hA C hb0 a1) fun r ⟨E, X, WT⟩ => + ⟨hb1, fun _ h => absurd h (by simp)⟩ (fun _ _ h => (Nat.not_lt_zero _ h).elim)⟩) + (fun s1 a1 hw1 keep hb1 C H' _ hHH' hHn hEx => WP.spec_mono (untyped.retype.liveRWH hA C hb0 a1) fun r ⟨E, X, WT, WH⟩ => UtEnd.live (I := fun H2 O2 s2 => (BufInv st H2 O2 s2 ∧ CapInv st (IdP (L.idleW s2) (L.mem s2 (scA (L.idleW s2)))) O2 s2 ∧ (CapInv st (ScCapP H2.scs) O2 s2 ∧ CtOff st (L.ksb s2) O2 s2 ∧ (FrOff st Cs O2 (L.ksb s2) s2 ∧ (EptSlot st H2 O2 s2 ∧ IpcAl st H2 s2)))) ∧ I H2 O2 s2) R B.ln B.vr B.ly @@ -2377,7 +2456,7 @@ theorem untyped.decode.sysLB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} rcases hx.2 with h | h <;> omega), ⟨U.ept R.heap B0 B.ep R.cap, U.ipc R.heap R.bxi.choose_spec R.core0 B.ipc⟩⟩⟩⟩, hI _ _ _ _ _ p.val (p.val + 2 ^ sb.val) aligned nt us dest off win U (UtX.drop (R.ur.rin R.src R.cap) (UtArgs.us64 hU)) (Or.inr ⟨_, hU⟩) (Or.inr ⟨rfl, he, rfl, rfl⟩) - ⟨hb1, fun _ => WT⟩⟩) hBT + ⟨hb1, fun _ => WT⟩ WH⟩) hBT ⟨CrtA.of_args R hU, hH1, hhole, R.stz.2.2 slot R.src p sb fi R.cap, hRT, hKT, fun _ h => h.1, hnn, hsrc1, rst_words w hsw hw1, keep, C.dO, E, X, fun _ => ⟨(CrtA.of_args R hU).pa, (CrtA.of_args R hU).aw⟩, hHH', hEx, UtArgs.dcv R.ty R.ext hU, @@ -2404,7 +2483,7 @@ theorem untyped.decode.sysLB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} U.ct R B.ly B.ct (UtArgs.us64 hU), ⟨U.fo R B.fo (fun h => absurd h (by simp)), ⟨U.ept R.heap B0 B.ep R.cap, U.ipc R.heap R.bxi.choose_spec R.core0 B.ipc⟩⟩⟩⟩, hI _ _ _ _ _ 0 0 aligned nt us dest off win U (UtX.refl (UtArgs.us64 hU)) (Or.inr ⟨_, hU⟩) (Or.inl rfl) ⟨let ⟨Ac2, h2⟩ := R.blk2 e; ⟨Ac2, (blk_of_capw h2 hw1 hsw).1⟩, - fun h => absurd h (by simp)⟩⟩) (fun _ h _ => h) + fun h => absurd h (by simp)⟩ (fun h => (a3 h).elim)⟩) (fun _ h _ => h) ⟨CrtA.of_args R hU, fun _ _ h => h, fun _ _ _ => Or.inr (Nat.zero_le _), ⟨fun _ _ => Or.inr (Nat.zero_le _), Or.inr (Nat.zero_le _)⟩, hRT, hKT, fun _ h => h, fun x hx _ => hx, R.src, (w.trans hw1).mono fun b hb' => by @@ -2418,6 +2497,26 @@ theorem untyped.decode.sysLB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} rintro ⟨r, s', a'⟩ ⟨H', OS', h1, h2, h3, h4, ⟨h5, h6, h7⟩, h8, h9⟩ exact ⟨H', OS', ⟨⟨h1, h2, h3, h4⟩, h5, h6, h7, h8.1.cn, h8.1.bh, h8.2.1, h8.2.2.1, h8.2.2.2.1, h8.2.2.2.2.1, h8.2.2.2.2.2.1, h8.2.2.2.2.2.2⟩, h9⟩ +set_option maxHeartbeats 4000000 in +/-- Project the original post from the shared creation proof. -/ +theorem untyped.decode.sysLB (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {ia ie : Nat} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) (hfm : A64FrameMasks st s0) (a : A) + (lbl len buf : U64) (I : Heap → Set U64 → S → Prop) (hI0 : I H OS s0) + (hI : ∀ (H1 H' : Heap) (OS1 : Set U64) (s1 s' : S) (lo hi : Nat) (aligned nt us dest off win : U64), + UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win → UtX H H1 lo hi us → + (win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) → + (H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ + hi = p.val + 2 ^ sb.val)) → + UtEndB st Cs H1 s1 s' dev aligned nt us win → I H' OS1 s') : + untyped.decode st ar s0 a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + ∃ (H' : Heap) (OS' : Set U64), SysL st H' Cs OS' ia ie s' ∧ I H' OS' s' ⦄ := + untyped.decode.sysLBH hA D P B hcap hfm a lbl len buf I hI0 + fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win U X hw hp UB _ => + hI H1 H' OS1 s1 s' lo hi aligned nt us dest off win U X hw hp UB + set_option maxHeartbeats 4000000 in /-- (gen 136) **`sysLY` with the kept heap's provenance at every end**: the decode's heap itself, or (a RAM reset) the childless source's dropped region `[p, p + 2^sb)` (`ensure_no_children` = Ok); gen 134's `sysLY` body, moved; diff --git a/proofs/Fl4ProofsA64/P1/MdbLiveY.lean b/proofs/Fl4ProofsA64/P1/MdbLiveY.lean index e498e0a2c..7d109743d 100644 --- a/proofs/Fl4ProofsA64/P1/MdbLiveY.lean +++ b/proofs/Fl4ProofsA64/P1/MdbLiveY.lean @@ -115,20 +115,18 @@ section irq variable {A : Type _} {ar : machine.Arch A} {D Pt : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} set_option maxHeartbeats 2000000 in -/-- **The immediate finalisation of an IRQ-node slot** (a notification or `Null`, `IrqN`): one round — `Null` exits at -once; a notification is finalised to `(Null, Null)` (QueueZombieV's `finL`), removable, so the loop exits with the -`Null` cleanup. Facts as QueueZombieQ's `zqGTMEQ` (finalisation by `finXQG` and the field's `fin`). -/ -theorem cdt.finalise_slot_immediate.irqME {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) +/-- (A64-S1A gen 41) **`finalise_slot_immediate.irqME` with a pending window** (`LoopMP`; the proof, moved here). -/ +theorem cdt.finalise_slot_immediate.irqMPQ {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) {a : A} {x I Is : U64} (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) (hxI : IslN (L.ksb s0) x) (hD : DomQ st K Vc D H.scs H.tcbs I Is s) (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) - {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} {Em : S → U64 → Prop} - (hM : LoopME st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) - (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Em M) (hm : M s) : + {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} {Pn : S → U64 → Prop} + (hM : LoopMP st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Pn M) (hm : M s) : cdt.finalise_slot_immediate st ar s a x ⦃ r => JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 r.2.1 ∧ Ty r.2.1 ∧ - M r.2.1 ∧ (∀ v, r.1 = .Ok v → ClOK v.cleanup ∧ Em r.2.1 x) ∧ DomQ st K Vc D H.scs H.tcbs I Is r.2.1 ∧ + ((∀ v, r.1 ≠ .Ok v) → M r.2.1) ∧ (∀ v, r.1 = .Ok v → ClOK v.cleanup ∧ Pn r.2.1 x) ∧ DomQ st K Vc D H.scs H.tcbs I Is r.2.1 ∧ L.idleW r.2.1 = I ∧ L.mem r.2.1 (scA I) = Is ∧ IrqN st (L.ksb s0) r.2.1 ∧ IrqK st (L.ksb s0) s r.2.1 ⦄ := by have hS : P0.StoreTotal st := L.total obtain ⟨i, hi, rfl⟩ := hxI @@ -142,7 +140,7 @@ theorem cdt.finalise_slot_immediate.irqME {s0 s : S} (E : DelS ar H OS D Vc Ub P unfold cdt.finalise_slot_immediate_loop.body split swap - · exact (WP.spec_ok _).2 ⟨h, hY, hm, (by intro v hv; simp_all), hD, hI, hIs, hN, IrqK.refl s⟩ + · exact (WP.spec_ok _).2 ⟨h, hY, (fun _ => hm), (by intro v hv; simp_all), hD, hI, hIs, hN, IrqK.refl s⟩ step as ⟨fuel1, hf1⟩ obtain ⟨c, hc⟩ := DPF.spec_tot (P0.obj.Slot.cap.p0 st (irqSlotA (L.ksb s0) i) s hS) rw [hc, bind_ok] @@ -151,36 +149,30 @@ theorem cdt.finalise_slot_immediate.irqME {s0 s : S} (E : DelS ar H OS D Vc Ub P · rename_i hbt have hc0 : obj.Slot.cap st (irqSlotA (L.ksb s0) i) s = ok .Null := by rw [hc]; congr 1; subst hbt; cases c <;> first | rfl | (simp [capability.Cap.is_null] at hbn) - exact (WP.spec_ok _).2 ⟨h, hY, hm, (fun v hv => by cases hv; exact ⟨Or.inl rfl, hM.en s _ hc0⟩), hD, hI, hIs, + exact (WP.spec_ok _).2 ⟨h, hY, (fun h => absurd rfl (h _)), (fun v hv => by cases hv; exact ⟨Or.inl rfl, hM.en s _ hm hc0⟩), hD, hI, hIs, hN, IrqK.refl s⟩ have hnt : IrqNt c := hN i hi c hc refine WP.spec_bind (spec_eqv (P0.cdt.is_final_capability_with_cap.p0 st s _ c hS)) fun fin hfe => ?_ refine WP.spec_bind (WP.spec_and (WP.spec_and (finXQG E.arch E.os E.sca E.vc E.vr hK hTy h E.irq hN hY h.ksb hx hc (zq_irqNt hnt) a1 fin) (hM.fin s a1 _ c fin h hm hx hc ⟨zq_irqNt hnt, hY, hN⟩ hfe.1)) (finL E.arch E.os E.sca E.vc h hx hc (zl_irqNt hnt) a1 fin)) ?_ - rintro ⟨⟨rem, cl⟩, s2, a2⟩ ⟨⟨⟨hcl, h2, k2, -, j2', sc2, y2⟩, m2, -, e2⟩, e0, -⟩ + rintro ⟨⟨rem, cl⟩, s2, a2⟩ ⟨⟨⟨hcl, h2, k2, -, j2', sc2, y2⟩, -, e2, -⟩, e0, -⟩ simp only [Prod.mk.injEq] at e0 obtain ⟨rfl, rfl⟩ := e0 - simp only at hcl h2 k2 j2' sc2 y2 m2 e2 + simp only at hcl h2 k2 j2' sc2 y2 e2 have d2 : DomQ st K Vc D H.scs H.tcbs I Is s2 := hD.oka E.irq.2 E.dom k2 have j2 : L.idleW s2 = I := j2'.trans hI have js2 : L.mem s2 (scA I) = Is := by rw [hI] at sc2; exact sc2.trans hIs have e2' := e2 rfl - first - | (simp only [cdt.cap_removable, bind_ok, ↓reduceIte] - exact (WP.spec_ok _).2 ⟨h2, y2, m2, (fun v hv => by cases hv; exact ⟨hcl, e2'⟩), d2, j2, js2, - hN.oka E.irq k2, IrqK.oka E.irq k2⟩) - | (simp only [cdt.cap_removable, bind_ok, ↓reduceIte, WP.spec_ok] - exact ⟨h2, y2, m2, (fun v hv => by cases hv; exact ⟨hcl, e2'⟩), d2, j2, js2, hN.oka E.irq k2, - IrqK.oka E.irq k2⟩) - | (simp [cdt.cap_removable, WP.spec_ok]; exact ⟨h2, y2, m2, hcl, e2', d2, j2, js2, hN.oka E.irq k2, - IrqK.oka E.irq k2⟩) + simp [cdt.cap_removable, WP.spec_ok] + exact ⟨h2, y2, hcl, e2', d2, j2, js2, hN.oka E.irq k2, IrqK.oka E.irq k2⟩ · rfl set_option maxHeartbeats 2000000 in -/-- **The exposed deletion of an IRQ-node slot** (`finalise_slot_immediate.irqME`, then `empty_slot` of the slot: -the other `OS` caps kept, the slot `Null`); facts as QueueZombieQ's `cdt.delete.zqIGTMEQ`. -/ -theorem cdt.delete.irqME {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) +/-- **The immediate finalisation of an IRQ-node slot** (a notification or `Null`, `IrqN`): one round — `Null` exits at +once; a notification is finalised to `(Null, Null)` (QueueZombieV's `finL`), removable, so the loop exits with the +`Null` cleanup. Facts as QueueZombieQ's `zqGTMEQ` (finalisation by `finXQG` and the field's `fin`). -/ +theorem cdt.finalise_slot_immediate.irqME {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) {a : A} {x I Is : U64} (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) (hxI : IslN (L.ksb s0) x) (hD : DomQ st K Vc D H.scs H.tcbs I Is s) (hI : L.idleW s = I) @@ -188,6 +180,28 @@ theorem cdt.delete.irqME {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} {Em : S → U64 → Prop} (hM : LoopME st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Em M) (hm : M s) : + cdt.finalise_slot_immediate st ar s a x ⦃ r => + JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 r.2.1 ∧ Ty r.2.1 ∧ + M r.2.1 ∧ (∀ v, r.1 = .Ok v → ClOK v.cleanup ∧ Em r.2.1 x) ∧ DomQ st K Vc D H.scs H.tcbs I Is r.2.1 ∧ + L.idleW r.2.1 = I ∧ L.mem r.2.1 (scA I) = Is ∧ IrqN st (L.ksb s0) r.2.1 ∧ IrqK st (L.ksb s0) s r.2.1 ⦄ := by + refine WP.spec_mono (cdt.finalise_slot_immediate.irqMPQ (a := a) E hK hTy h hxI hD hI hIs hN hY hM.toP hm) ?_ + rintro r ⟨h1, y1, m1, v1, d1, j1, js1, N1, q1⟩ + refine ⟨h1, y1, ?_, fun v hv => ⟨(v1 v hv).1, (v1 v hv).2.2⟩, d1, j1, js1, N1, q1⟩ + by_cases ok : ∃ v, r.1 = .Ok v + · obtain ⟨v, hv⟩ := ok + exact (v1 v hv).2.1 + · exact m1 fun v hv => ok ⟨v, hv⟩ + +set_option maxHeartbeats 2000000 in +/-- (A64-S1A gen 41) **`delete.irqME` with a pending window** (`LoopMP`; the proof, moved here). -/ +theorem cdt.delete.irqMPQ {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) {a : A} {x I Is : U64} + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) + (hxI : IslN (L.ksb s0) x) (hD : DomQ st K Vc D H.scs H.tcbs I Is s) (hI : L.idleW s = I) + (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) + {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} {Pn : S → U64 → Prop} + (hM : LoopMP st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Pn M) (hm : M s) : cdt.delete st ar s a x true ⦃ r => JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 r.2.1 ∧ Ty r.2.1 ∧ M r.2.1 ∧ DomQ st K Vc D H.scs H.tcbs I Is r.2.1 ∧ L.idleW r.2.1 = I ∧ L.mem r.2.1 (scA I) = Is ∧ @@ -196,14 +210,14 @@ theorem cdt.delete.irqME {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) have hxD : x ∉ D := fun hd => E.irq.2 x hd hxI unfold cdt.delete simp only [↓reduceIte] - refine WP.spec_bind (cdt.finalise_slot_immediate.irqME (a := a) E hK hTy h hxI hD hI hIs hN hY hM hm) ?_ + refine WP.spec_bind (cdt.finalise_slot_immediate.irqMPQ (a := a) E hK hTy h hxI hD hI hIs hN hY hM hm) ?_ rintro ⟨r, s1, a1⟩ ⟨h1, y1, m1, hv1, d1, j1, js1, N1, q1⟩ try simp only [uncurry_apply_pair] at h1 y1 m1 hv1 d1 j1 js1 N1 q1 ⊢ rcases r with v | e · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.empty_slot.zs E.arch E.os E.vc h1 hx (hv1 v rfl).1 E.irqSt) (cdt.empty_slot.vk E.arch E.os E.vr h1 hx (hv1 v rfl).1 h1.ksb)) - (hM.emp s1 a1 x _ h1 m1 hx (hv1 v rfl).1 (hv1 v rfl).2)) ?_ + (hM.emp s1 a1 x _ h1 (hv1 v rfl).2 hx (hv1 v rfl).1)) ?_ rintro ⟨s2, a2⟩ ⟨⟨h2, v2⟩, m2⟩ try simp only [uncurry_apply_pair] at h2 v2 m2 ⊢ obtain ⟨h2, k2, c2, i2, sc2⟩ := h2 @@ -215,7 +229,24 @@ theorem cdt.delete.irqME {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 ⟨h1, y1, m1, d1, j1, js1, N1, q1⟩ + exact (WP.spec_ok _).2 ⟨h1, y1, m1 (fun _ h => by cases h), d1, j1, js1, N1, q1⟩ + +set_option maxHeartbeats 2000000 in +/-- **The exposed deletion of an IRQ-node slot** (`finalise_slot_immediate.irqME`, then `empty_slot` of the slot: +the other `OS` caps kept, the slot `Null`); facts as QueueZombieQ's `cdt.delete.zqIGTMEQ`. -/ +theorem cdt.delete.irqME {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) {a : A} {x I Is : U64} + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) + (hxI : IslN (L.ksb s0) x) (hD : DomQ st K Vc D H.scs H.tcbs I Is s) (hI : L.idleW s = I) + (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) + {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} {Em : S → U64 → Prop} + (hM : LoopME st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Em M) (hm : M s) : + cdt.delete st ar s a x true ⦃ r => + JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 r.2.1 ∧ Ty r.2.1 ∧ + M r.2.1 ∧ DomQ st K Vc D H.scs H.tcbs I Is r.2.1 ∧ L.idleW r.2.1 = I ∧ L.mem r.2.1 (scA I) = Is ∧ + IrqN st (L.ksb s0) r.2.1 ∧ IrqK st (L.ksb s0) s r.2.1 ⦄ := by + exact cdt.delete.irqMPQ (a := a) E hK hTy h hxI hD hI hIs hN hY hM.toP hm set_option maxHeartbeats 1000000 in /-- **The exposed deletion of an IRQ-node slot on a `DelQ` state keeps `DelQ`** (`cdt.delete.irqME`, field diff --git a/proofs/Fl4ProofsA64/P1/MdbMcpArm.lean b/proofs/Fl4ProofsA64/P1/MdbMcpArm.lean index 1853e255a..11b14300e 100644 --- a/proofs/Fl4ProofsA64/P1/MdbMcpArm.lean +++ b/proofs/Fl4ProofsA64/P1/MdbMcpArm.lean @@ -18,6 +18,9 @@ write by MdbPacL's `tcb_wr_df`) whose end keeps `BlkOK` (QueueTcbInv's `obj.Tcb. MdbPoolA's `ArmQIAt` (the same facts at the decode's own `(H, OS)`); each is the body of the name without `At`, moved, and that name is now its `ArmQIAt.toQI` projection (statement unchanged). +(A64-S1A gen 40, Architect ruling for gen 40, R3) `mcp_armQIKAt` also posts `ArmVsK` (last conjunct, from +`ArmQIAt.ofDFK`). + Named premises: none. Case facts: none (`hvr` is the entry record's `DelIn.del.vr`, as the other `…_armQIK` tops). -/ import Fl4ProofsA64.P1.MdbArmDf @@ -142,13 +145,13 @@ theorem syscall.decode_invocation.mcp_armQIKAt (hA : P0.ArchTotal ar) {s : S} (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetMCPriority) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (tcb.decode.mcpDFK hA D hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact ArmQIAt.ofDFK D P B Y hvr d.1 d.2 @@ -166,6 +169,8 @@ theorem syscall.decode_invocation.mcp_armQIK (hA : P0.ArchTotal ar) {s : S} ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by exact WP.spec_mono (syscall.decode_invocation.mcp_armQIKAt hA D P B Y hvr a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) | exact h.toQI diff --git a/proofs/Fl4ProofsA64/P1/MdbPoolA.lean b/proofs/Fl4ProofsA64/P1/MdbPoolA.lean index 8cef4fee6..fde646e23 100644 --- a/proofs/Fl4ProofsA64/P1/MdbPoolA.lean +++ b/proofs/Fl4ProofsA64/P1/MdbPoolA.lean @@ -33,12 +33,24 @@ false)`, `s3 = clear_free s2 p 4096`, `s4 = cdt.insert (AsidPool p base) x v`, ` disjunct (`vspace.makePool.finEIP`: `finEI`'s body, moved, posting `finWI`'s `PoolPost`; `finEI` its projection, statement unchanged). +(A64-S1A gen 41) Stronger siblings for R2: **`vspace.makePool.finWIX`** / **`finEIPAtX`** / +**`vspace.decode.makePoolLIEAtX`** / **`syscall.decode_invocation.makePoolLIEAtX`** expose `i < 128`, +`base = i * 512`, that every `OffR` slot but source and target keeps its cap, and that the source holds +`Untyped p sb 4096`; the old theorems are their projections (statements byte-identical). + (gen 147, ruling (a)) **`ArmQIAt`** (`ArmQI`'s body at the decode's own `(H, OS)`) and **`ArmQIAt.toQI`**. (gen 160, Architect 15:34Z, item 1, in place) `ArmQIAt` gains the last clause `∀ Pt, PtCap st Pt OS s0 → PtCap st Pt OS s` (MdbPtCapA's `PtCap`; stated for every `Pt`, so no new binder: S1A instantiates the `Pt` it passes `DelIn`; last, so the existing projections of the other clauses are unchanged). `ArmQI` / `ArmQIEnd` are unchanged (a type-11 retype, MdbRtArm's `ArmQIV.armQI`, makes new page-table caps); hence `ArmQIAt.toQI` drops the clause and `ArmQIAt.iff_end`'s statement carries it beside `ArmQIEnd` (the one forced statement change). +(A64-S1A gen 37, Architect ruling 01:01Z item 1, final shape) that clause is replaced by the polymorphic cap-source +clause `∀ Q : capability.Cap → Prop, CapSrcClosed Q → CapInv st Q OS s0 → CapInv st Q OS s` (MdbPtCapA's +`CapSrcClosed`; `ArmVs` frozen as committed); `ArmQIAt.ptCap` (statement unchanged) is its instance at `PtCapP Pt`; +`ArmQIAt.iff_end`'s statement carries the new clause. +(A64-S1A gen 38, Architect ruling item 1) MakePool's memory footprint: `finWI` also posts MdbPoolN's new `PoolPost` +fields `zr` / `vs` (the cleared region via `clear_free_spec`, the insert's `OffR` slot words, the table word; statement +unchanged), and **`PoolPost.armVs`** reads them as an `ArmVs` step (`VsWr`'s `zero` / `pool` records). (gen 148, Architect 09:51Z) **MakePool's end exposed**: **`ArmQIEnd … s0 H' OS' s`** (`ArmQI`'s body at named end witnesses; `ArmQI.iff_end`, `ArmQIAt.iff_end`, `ArmQIEnd.toQI`); **`vspace.makePool.finEIPAt`** (`finEIP`'s body, @@ -52,6 +64,7 @@ none new (`hSC`, `DelIn` as in `armLD9`). -/ import Fl4ProofsA64.P1.MdbPoolN import Fl4ProofsA64.P1.MdbPtCapA +import Fl4ProofsA64.P1.MdbArmVsG open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P1 @@ -87,9 +100,9 @@ theorem cdt.insert.ksbP (hO : OSOK T Ω Sg OS) {s : S} (hS : MdbS st OS s) {x y exact WP.spec_mono (cdt.insert_with_cap.lrF hO (LR.self s) hx hy hxy hyc rfl hsc0 hw nn) fun _ h => h.1.1 set_option maxHeartbeats 4000000 in -/-- (gen 134) **`finWE` with the post's cap map**: every `OffR` slot but the target holds its decode-state cap or an -untyped cap (the source) — what `PoolIdx` after MakePool reads (gen 132's `finWE` body, moved). -/ -theorem vspace.makePool.finWI {s0 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} +/-- (A64-S1A gen 41) **`finWI` with the exact cap map** (its body, moved): every `OffR` slot but the source and the +target keeps its cap, and the source holds the full `Untyped` (`insert_with_cap.srcU`, `SrcU.full`). -/ +theorem vspace.makePool.finWIX {s0 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot x v p sb fi base i : U64} (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) @@ -115,8 +128,8 @@ theorem vspace.makePool.finWI {s0 : S} {cap : capability.Cap} {extra : Aeneas.St (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val).ntfns (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val).scBits Ac' s5) ∧ (VcCap st Vc OS s0 → VcCap st Vc (OffR p.val (p.val + 2 ^ sb.val) OS) s5) ∧ - (∀ 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') ⦄ ⦄ ⦄ ⦄ ⦄ := by + (∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ x → y ≠ v → capA st s5 y = capA st s0 y) ∧ + capA st s5 x = .Untyped p sb 4096#u64 false ∧ x ∈ OffR p.val (p.val + 2 ^ sb.val) OS ⦄ ⦄ ⦄ ⦄ ⦄ := by have hn : (4096#u64).val = 2 ^ sb.val := by rw [hsb]; first | rfl | decide | simp [fl4_abi.consts.bits.ASID_POOL] have hn8 : (4096#u64).val % 8 = 0 := by first | rfl | decide | simp @@ -154,8 +167,14 @@ theorem vspace.makePool.finWI {s0 : S} {cap : capability.Cap} {extra : Aeneas.St have := @Nat.one_le_two_pow sb.val omega obtain ⟨v8, -, v24⟩ := vals hO hx - refine WP.spec_mono (obj.Slot.set_cap.poolDropR Dr hn hn8) fun s2 h2 => WP.spec_mono h2 ?_ - rintro s3 ⟨Ac3, ⟨B3, Y3, hb3⟩, hc3, hxR, w3, kc3⟩ + refine WP.spec_mono (obj.Slot.set_cap.poolDropR Dr hn hn8) fun s2 h2 => + WP.spec_mono (WP.spec_and h2 (LawfulStore.clear_free_spec s2 p 4096#u64)) ?_ + rintro s3 ⟨⟨Ac3, ⟨B3, Y3, hb3⟩, hc3, hxR, w3, kc3⟩, e3⟩ + have hpa : Aligned p := F.p8 + have hpf : p.val + 2 ^ sb.val ≤ 2 ^ 64 := F.pf + have z3 : ∀ b, Aligned b → p.val ≤ b.val → b.val < p.val + 2 ^ sb.val → L.mem s3 b = 0#u64 := + fun b hb h1 h2 => by + rw [e3]; exact L.mem_zr_in hpa hn8 (by rw [hn]; exact hpf) hb ⟨h1, by rw [hn]; exact h2⟩ have hH1 : HeapOK (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) := P.heap.drop have hO1 : OSOK (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))).tcbs (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))).omega (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))).frame @@ -197,9 +216,15 @@ theorem vspace.makePool.finWI {s0 : S} {cap : capability.Cap} {extra : Aeneas.St fresh := pool_fresh OffR.sub hno hk30 hc3 zfr := pool_zfr B3.cn F.hole } have hsc0 : capA st s3 x ≠ .Null := by rw [hc3]; exact fun h => by cases h - refine WP.spec_mono (WP.spec_and (cdt.insert.sysLP hH4 hO4 hb4.bxi B4 Y4 PI) - (cdt.insert.osKU hO4 B4.sys.stz.1.1.mdbS hxR hvR (Ne.symm hvx) PI.canon hsc0 hw)) ?_ - rintro s4 ⟨⟨⟨B5, Y5⟩, hb5⟩, w4, hc4, kc4, hx4⟩ + have source : cdt.insert st s3 (.AsidPool p base) x v ⦃ s' => + SrcU (capA st s' x) (.Untyped p sb 4096#u64 false) (.AsidPool p base) ⦄ := by + unfold cdt.insert + rw [capA_eq, bind_ok, hc3] + exact cdt.insert_with_cap.srcU hO4 hxR hvR (Ne.symm hvx) hc3 hw (B4.sys.stz.1.1.mdbS.lnk hO4 hxR).2 + refine WP.spec_mono (WP.spec_and (WP.spec_and (cdt.insert.sysLP hH4 hO4 hb4.bxi B4 Y4 PI) + (cdt.insert.osKU hO4 B4.sys.stz.1.1.mdbS hxR hvR (Ne.symm hvx) PI.canon hsc0 hw)) source) ?_ + rintro s4 ⟨⟨⟨⟨B5, Y5⟩, hb5⟩, w4, hc4, kc4, hx4⟩, full⟩ + have exactSource : capA st s4 x = .Untyped p sb 4096#u64 false := SrcU.full full hn have kb4 : L.ksb s4 = L.ksb s3 := w4.1 have kb40 : L.ksb s4 = L.ksb s0 := by rw [kb4, w3.1, kb1] have vk4 : VsKeep st (L.ksb s0) Pt s3 s4 := @@ -233,8 +258,19 @@ theorem vspace.makePool.finWI {s0 : S} {cap : capability.Cap} {extra : Aeneas.St · rw [h]; exact VcCapP.ut _ _ _ _ _ · rw [hk40 y hy e2 e1]; exact V y hy.1 refine (WP.spec_ok _).2 ⟨((WP.spec_ok _).1 h5).1, ((WP.spec_ok _).1 h5).2, ?_, ⟨_, hb6⟩, hV6, ?_⟩ + have hiR : ¬ (p.val ≤ (wa (L.ksb s0) (AtOff i)).val ∧ (wa (L.ksb s0) (AtOff i)).val < p.val + 2 ^ sb.val) := + fun ⟨h1, h2⟩ => by + rw [hAv] at h1 h2 + have := (AtOff.v i).1; have := (AtOff.v i).2.1 + rcases hks with g | g <;> omega + have z4 : ∀ b, Aligned b → p.val ≤ b.val → b.val < p.val + 2 ^ sb.val → L.mem s4 b = 0#u64 := + fun b hb h1 h2 => by + rw [w4.mem_eq hb ?_] + · exact z3 b hb h1 h2 + · rintro ⟨y, hy, g1, g2⟩ + rcases hy.2 with g | g <;> omega refine ⟨hH4, by simp only [LawfulStore.ksb_wr]; exact kb40, L.mem_wr_same (hal i), fun j hj => ?_, - by rw [hcw v hv, hc4], hvR, fun y hy hyx hyv hy0 => ?_⟩ + by rw [hcw v hv, hc4], hvR, fun y hy hyx hyv hy0 => ?_, fun b hb h1 h2 => ?_, fun Vc' Ub' Pt' hvr' b hb => ?_⟩ · rw [L.mem_wr_ne (hal i) (hal j) (fun e => hj (UScalar.eq_of_val_eq (by rw [hAv, hAv] at e; omega))), vk4 _ (Or.inr (hAt j)), w3.mem_eq (hal j) ?_, vk1 _ (Or.inr (hAt j))] rintro (⟨h1, h2⟩ | e | e) @@ -245,14 +281,61 @@ theorem vspace.makePool.finWI {s0 : S} {cap : capability.Cap} {extra : Aeneas.St · exact hos j x hx ⟨by rw [e, v8]; omega, by rw [e, v8]; omega⟩ · have hyR : y ∈ OffR p.val (p.val + 2 ^ sb.val) OS := F.nn y hy (by rw [k1.capA hy]; exact hy0) exact ⟨hyR, by rw [hcw y hy, hk40 y hyR hyx hyv]⟩ - · intro y hy hyv - rw [hcw y hy.1] - by_cases e2 : y = x - · rw [e2]; right - rcases hx4 with h | ⟨a1, a2, a3, a4, h⟩ - · exact ⟨_, _, _, _, by rw [h, hc3]⟩ - · exact ⟨a1, a2, a3, a4, h⟩ - · left; exact hk40 y hy e2 hyv + · rw [L.mem_wr_ne (hal i) hb (fun e => hiR (by rw [UScalar.eq_of_val_eq e]; exact ⟨h1, h2⟩))] + exact z4 b hb h1 h2 + · have hba := hvr'.al b hb + by_cases hR : p.val ≤ b.val ∧ b.val < p.val + 2 ^ sb.val + · exact Or.inr (Or.inl hR) + by_cases hI : b = wa (L.ksb s0) (AtOff i) + · exact Or.inr (Or.inr hI) + left + have vk1' := vsk_sts hvr' q0 hct w1 + have vk4' : VsKeep st (L.ksb s0) Pt' s3 s4 := + vsk_cw q0 hvr' (w4.mono fun b hb => Or.inr ⟨let ⟨y, hy, h1, h2⟩ := hb; ⟨y, hy.1, h1, h2⟩, Set.notMem_empty _⟩) + rw [L.mem_wr_ne (hal i) hba (fun e => hI (UScalar.eq_of_val_eq e).symm), vk4' b hb, w3.mem_eq hba ?_, vk1' b hb] + rintro (hr | e | e) + · exact hR hr + · exact hvr'.os b hb ⟨x, hx, by rw [e], by rw [e]; omega⟩ + · exact hvr'.os b hb ⟨x, hx, by rw [e, v8]; omega, by rw [e, v8]; omega⟩ + · exact ⟨fun y hy hyx hyv => by rw [hcw y hy.1]; exact hk40 y hy hyx hyv, by rw [hcw x hx]; exact exactSource, hxR⟩ + +/-- (gen 134) **`finWE` with the post's cap map**: every `OffR` slot but the target holds its decode-state cap or an +untyped cap (the source) — what `PoolIdx` after MakePool reads (gen 132's `finWE` body, moved). -/ +theorem vspace.makePool.finWI {s0 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot x v p sb fi base i : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (Y : SymL st H Cs s0) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt) + (hx : x ∈ OS) (hxc : SlotCov st OS s0 x) (hcx : capA st s0 x = .Untyped p sb fi false) + (hsb : sb = fl4_abi.consts.bits.ASID_POOL) + (he : cdt.ensure_no_children st s0 x = ok (core.result.Result.Ok ())) + (hv : v ∈ OS) (hvc : SlotCov st OS s0 v) (hvB : v ∉ BufS H.tcbs) (hvE : v ∉ EptS H.tcbs) + (hv0 : capA st s0 v = .Null) : + sched.set_thread_state st s0 (L.curW s0) sched.TS_RESTART ⦃ s1 => + obj.Slot.set_cap st x s1 (.Untyped p sb 4096#u64 false) ⦃ s2 => st.clear_free s2 p 4096#u64 ⦃ s3 => + cdt.insert st s3 (.AsidPool p base) x v ⦃ s4 => vspace.set_asid_table st s4 i p ⦃ s5 => + SysL st (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val) Cs + (OffR p.val (p.val + 2 ^ sb.val) OS) ia ie s5 ∧ + SymL st (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val) Cs s5 ∧ + PoolPost st H OS s0 s5 x v p sb i base ∧ + (∃ Ac', BlkOK st (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val).tcbs Cs + (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val).omega + (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val) + (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val).frame + (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val).replies + (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val).scs + (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val).ntfns + (PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val).scBits Ac' s5) ∧ + (VcCap st Vc OS s0 → VcCap st Vc (OffR p.val (p.val + 2 ^ sb.val) OS) s5) ∧ + (∀ 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') ⦄ ⦄ ⦄ ⦄ ⦄ := + WP.spec_mono (vspace.makePool.finWIX (base := base) (i := i) D P B Y hvr hx hxc hcx hsb he hv hvc hvB hvE + hv0) fun _ h1 => WP.spec_mono h1 fun _ h2 => WP.spec_mono h2 fun _ h3 => WP.spec_mono h3 fun _ h4 => + WP.spec_mono h4 fun _ h5 => ⟨h5.1, h5.2.1, h5.2.2.1, h5.2.2.2.1, h5.2.2.2.2.1, fun y hy hyv => by + by_cases same : y = x + · subst y + exact Or.inr ⟨_, _, _, _, h5.2.2.2.2.2.2.1⟩ + · exact Or.inl (h5.2.2.2.2.2.1 y hy same hyv)⟩ /-- (gen 132) **MakePool from the caller's restart on, with its witnesses and the entry record's arm facts**: `finW`'s post (`SysL ∧ SymL ∧ PoolPost` over the pool heap and `OffR`), `BlkOK` over the pool heap (the drop's @@ -399,17 +482,28 @@ def ArmQIAt (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs OS Vc : S (VcCap st Vc OS s0 → VcCap st Vc OS s) ∧ (PoolOff st H Cs OS s0 → PoolOff st H Cs OS s) ∧ (PoolNamed st OS s0 → PoolNamed st OS s) ∧ (PoolNamed st OS s0 → PoolIdx st OS s0 → PoolIdx st OS s) ∧ - (∀ Pt, PtCap st Pt OS s0 → PtCap st Pt OS s) + (∀ Q : capability.Cap → Prop, CapSrcClosed Q → CapInv st Q OS s0 → CapInv st Q OS s) ∧ ArmVs st H OS Vc s0 s /-- (gen 147) `ArmQIAt` gives `ArmQI` (witnesses `H`, `OS`). -/ theorem ArmQIAt.toQI {H : Heap} {Cs OS Vc : Set U64} {s0 s : S} (h : ArmQIAt st H Cs OS Vc ia ie s0 s) : ArmQI st H Cs OS Vc ia ie s0 s := let ⟨h1, h2, h3, h4, h5, h6, h7, _⟩ := h; ⟨H, OS, h1, h2, h3, h4, h5, h6, h7⟩ -/-- (gen 160) **`ArmQIAt`'s `PtCap` clause** at a given `Pt` (S1A's `Pt`, the one it passes `DelIn`). -/ +/-- (gen 160) **`ArmQIAt`'s `PtCap` clause** at a given `Pt` (S1A's `Pt`, the one it passes `DelIn`); (A64-S1A gen 37) +the cap-source clause at `PtCapP Pt` (`PtCapP.closed`). -/ theorem ArmQIAt.ptCap {H : Heap} {Cs OS Vc Pt : Set U64} {s0 s : S} (h : ArmQIAt st H Cs OS Vc ia ie s0 s) (hP : PtCap st Pt OS s0) : PtCap st Pt OS s := - h.2.2.2.2.2.2.2 Pt hP + h.2.2.2.2.2.2.2.1 (PtCapP Pt) (PtCapP.closed Pt) hP + +/-- (A64-S1A gen 37) **`ArmQIAt`'s cap-source clause** at a closed class `Q`. -/ +theorem ArmQIAt.capInv {H : Heap} {Cs OS Vc : Set U64} {s0 s : S} (h : ArmQIAt st H Cs OS Vc ia ie s0 s) + {Q : capability.Cap → Prop} (hQ : CapSrcClosed Q) (h0 : CapInv st Q OS s0) : CapInv st Q OS s := + h.2.2.2.2.2.2.2.1 Q hQ h0 + +/-- (A64-S1A gen 31) **`ArmQIAt`'s memory-frame clause** (MdbArmVs's `ArmVs`; read by `ArmVs.get`). -/ +theorem ArmQIAt.vs {H : Heap} {Cs OS Vc : Set U64} {s0 s : S} (h : ArmQIAt st H Cs OS Vc ia ie s0 s) : + ArmVs st H OS Vc s0 s := + h.2.2.2.2.2.2.2.2 /-- (gen 148, Architect 09:51Z) **`ArmQI`'s body at named end witnesses `H'`, `OS'`** (MakePool's end exposed, so S1A does not restate its spine): `ArmQI` is `∃ H' OS', ArmQIEnd …` (`ArmQI.iff_end`), `ArmQIAt` is `ArmQIEnd` at @@ -430,15 +524,33 @@ theorem ArmQI.iff_end {H : Heap} {Cs OS Vc : Set U64} {s0 s : S} : /-- (gen 148) `ArmQIAt` is `ArmQIEnd` at the decode's own `(H, OS)`. -/ theorem ArmQIAt.iff_end {H : Heap} {Cs OS Vc : Set U64} {s0 s : S} : ArmQIAt st H Cs OS Vc ia ie s0 s ↔ - ArmQIEnd st H Cs OS Vc ia ie s0 H OS s ∧ ∀ Pt, PtCap st Pt OS s0 → PtCap st Pt OS s := - ⟨fun ⟨h1, h2, h3, h4, h5, h6, h7, h8⟩ => ⟨⟨h1, h2, h3, h4, h5, h6, h7⟩, h8⟩, - fun ⟨⟨h1, h2, h3, h4, h5, h6, h7⟩, h8⟩ => ⟨h1, h2, h3, h4, h5, h6, h7, h8⟩⟩ + ArmQIEnd st H Cs OS Vc ia ie s0 H OS s ∧ + (∀ Q : capability.Cap → Prop, CapSrcClosed Q → CapInv st Q OS s0 → CapInv st Q OS s) ∧ + ArmVs st H OS Vc s0 s := + ⟨fun ⟨h1, h2, h3, h4, h5, h6, h7, h8, h9⟩ => ⟨⟨h1, h2, h3, h4, h5, h6, h7⟩, h8, h9⟩, + fun ⟨⟨h1, h2, h3, h4, h5, h6, h7⟩, h8, h9⟩ => ⟨h1, h2, h3, h4, h5, h6, h7, h8, h9⟩⟩ /-- (gen 148) `ArmQIEnd` gives `ArmQI`. -/ theorem ArmQIEnd.toQI {H H' : Heap} {Cs OS OS' Vc : Set U64} {s0 s : S} (h : ArmQIEnd st H Cs OS Vc ia ie s0 H' OS' s) : ArmQI st H Cs OS Vc ia ie s0 s := ⟨H', OS', h⟩ +/-- (A64-S1A gen 38, ruling item 1) **MakePool's footprint is an `ArmVs` step** at the decode's own `(H, OS)`: the +cleared region's words are `VsWr`'s `zero`, the new table word its `pool` (the target slot's `AsidPool` cap, the +pool's 4 KiB zero), every other placed `VsR` word kept (`PoolPost.vs`). -/ +theorem PoolPost.armVs {Vc : Set U64} {s0 s : S} {x v p sb i base : U64} (Pp : PoolPost st H OS s0 s x v p sb i base) + (hsb : sb.val = 12) (hpa : Aligned p) (hpf : p.val + 4096 ≤ 2 ^ 64) : ArmVs st H OS Vc s0 s := by + refine ⟨Pp.ksb, fun Ub Pt hvr _ b hb => ?_⟩ + rcases Pp.vs Vc Ub Pt hvr b hb with h | ⟨h1, h2⟩ | rfl + · exact Or.inl h + · exact Or.inr (Or.inl (Pp.zr b (hvr.al b hb) h1 h2)) + · refine Or.inr (Or.inr (Or.inr (Or.inr (Or.inr ⟨⟨AtOff i, (AtOff.v i).1, (AtOff.v i).2.1, (AtOff.v i).2.2, rfl⟩, + v, Pp.vR.1, base, by rw [Pp.tabI]; exact Pp.capV, fun o ho h8 => ?_⟩)))) + rw [Pp.tabI] + have hv : (wa p o).val = p.val + o.val := wadd_val (by omega) + exact Pp.zr _ (by show _ % 8 = 0; rw [hv]; unfold Aligned at hpa; omega) (by rw [hv]; omega) + (by rw [hv, hsb]; omega) + /-- (gen 132) **MakePool from the caller's restart on, to `ArmQ`** (`finWE` with MdbPoolN's `PoolPost` lemmas). -/ theorem vspace.makePool.finE {s0 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot x v p sb fi base i : U64} @@ -459,10 +571,8 @@ theorem vspace.makePool.finE {s0 : S} {cap : capability.Cap} {extra : Aeneas.Std WP.spec_mono h4 fun _ h5 => ⟨_, _, h5.1, h5.2.1, h5.2.2.2.1, h5.2.2.2.2, fun hPO => h5.2.2.1.poolOff B hx hcx hsb hPO, fun hPN => h5.2.2.1.poolNamed hcx hv0 hPN⟩ -/-- (gen 148, Architect 09:51Z) **`finEIP` at the named end** (`PoolH (H.drop R) p sb`, `OffR … OS`; the body of -`finEIP`, moved, with `finWI`'s per-slot cap fact): `PoolPost`, `ArmQIEnd`, every `OffR` slot but the target holding its -decode-state cap or an `Untyped` cap. -/ -theorem vspace.makePool.finEIPAt {s0 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} +/-- (A64-S1A gen 41) **`finEIPAt` with the exact cap map** (its body, moved). -/ +theorem vspace.makePool.finEIPAtX {s0 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot x v p sb fi base i : U64} (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) @@ -478,8 +588,8 @@ theorem vspace.makePool.finEIPAt {s0 : S} {cap : capability.Cap} {extra : Aeneas PoolPost st H OS s0 s5 x v p sb i base ∧ ArmQIEnd st H Cs OS Vc 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 ∧ - (∀ 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') ⦄ ⦄ ⦄ ⦄ ⦄ := by + (∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ x → y ≠ v → capA st s5 y = capA st s0 y) ∧ + capA st s5 x = .Untyped p sb 4096#u64 false ∧ x ∈ OffR p.val (p.val + 2 ^ sb.val) OS ⦄ ⦄ ⦄ ⦄ ⦄ := by have hfr : ∀ c ∈ OS, ∀ q b, capA st s0 c = .AsidPool q b → q ≠ p := by obtain ⟨G0, par0, hT0, -, -⟩ := B.sys.stz.1.1.tree have hno := cdt.ensure_no_children.noKey P.os hT0.utRangeOrd B.sys.stz.1.2.1 hx hcx he @@ -488,11 +598,44 @@ theorem vspace.makePool.finEIPAt {s0 : S} {cap : capability.Cap} {extra : Aeneas rw [e, ptrA_ap, hq] at h have := @Nat.one_le_two_pow sb.val exact h ⟨le_refl _, by omega⟩ - exact WP.spec_mono (vspace.makePool.finWI (base := base) (i := i) D P B Y hvr hx hxc hcx hsb he hv hvc hvB hvE hv0) + exact WP.spec_mono (vspace.makePool.finWIX (base := base) (i := i) D P B Y hvr hx hxc hcx hsb he hv hvc hvB hvE hv0) fun _ h1 => WP.spec_mono h1 fun _ h2 => WP.spec_mono h2 fun _ h3 => WP.spec_mono h3 fun _ h4 => WP.spec_mono h4 fun _ h5 => ⟨h5.2.2.1, ⟨h5.1, h5.2.1, h5.2.2.2.1, h5.2.2.2.2.1, fun hPO => h5.2.2.1.poolOff B hx hcx hsb hPO, fun hPN => h5.2.2.1.poolNamed hcx hv0 hPN, - fun hPN hPI => h5.2.2.1.poolIdx h5.2.2.2.2.2 hfr hi hb hPN hPI⟩, h5.2.2.2.2.2⟩ + fun hPN hPI => h5.2.2.1.poolIdx (fun y hy hyv => by + by_cases same : y = x + · subst y + exact Or.inr ⟨_, _, _, _, h5.2.2.2.2.2.2.1⟩ + · exact Or.inl (h5.2.2.2.2.2.1 y hy same hyv)) hfr hi hb hPN hPI⟩, h5.2.2.2.2.2⟩ + +/-- (gen 148, Architect 09:51Z) **`finEIP` at the named end** (`PoolH (H.drop R) p sb`, `OffR … OS`; the body of +`finEIP`, moved, with `finWI`'s per-slot cap fact): `PoolPost`, `ArmQIEnd`, every `OffR` slot but the target holding its +decode-state cap or an `Untyped` cap. -/ +theorem vspace.makePool.finEIPAt {s0 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot x v p sb fi base i : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (Y : SymL st H Cs s0) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt) + (hx : x ∈ OS) (hxc : SlotCov st OS s0 x) (hcx : capA st s0 x = .Untyped p sb fi false) + (hsb : sb = fl4_abi.consts.bits.ASID_POOL) + (he : cdt.ensure_no_children st s0 x = ok (core.result.Result.Ok ())) + (hv : v ∈ OS) (hvc : SlotCov st OS s0 v) (hvB : v ∉ BufS H.tcbs) (hvE : v ∉ EptS H.tcbs) + (hv0 : capA st s0 v = .Null) (hi : i.val < 128) (hb : base.val = i.val * 512) : + sched.set_thread_state st s0 (L.curW s0) sched.TS_RESTART ⦃ s1 => + obj.Slot.set_cap st x s1 (.Untyped p sb 4096#u64 false) ⦃ s2 => st.clear_free s2 p 4096#u64 ⦃ s3 => + cdt.insert st s3 (.AsidPool p base) x v ⦃ s4 => vspace.set_asid_table st s4 i p ⦃ s5 => + PoolPost st H OS s0 s5 x v p sb i base ∧ + ArmQIEnd st H Cs OS Vc 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 ∧ + (∀ 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') ⦄ ⦄ ⦄ ⦄ ⦄ := + WP.spec_mono (vspace.makePool.finEIPAtX (base := base) (i := i) D P B Y hvr hx hxc hcx hsb he hv hvc hvB hvE hv0 hi + hb) fun _ h1 => WP.spec_mono h1 fun _ h2 => WP.spec_mono h2 fun _ h3 => WP.spec_mono h3 fun _ h4 => + WP.spec_mono h4 fun _ h5 => ⟨h5.1, h5.2.1, fun y hy hyv => by + by_cases same : y = x + · subst y + exact Or.inr ⟨_, _, _, _, h5.2.2.2.1⟩ + · exact Or.inl (h5.2.2.1 y hy same hyv)⟩ /-- (gen 141, Architect 06:13Z) **`finEI` with the post's `PoolPost`** (the body of `finEI`, moved). -/ theorem vspace.makePool.finEIP {s0 : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -533,6 +676,27 @@ theorem vspace.makePool.finEI {s0 : S} {cap : capability.Cap} {extra : Aeneas.St fun _ h1 => WP.spec_mono h1 fun _ h2 => WP.spec_mono h2 fun _ h3 => WP.spec_mono h3 fun _ h4 => WP.spec_mono h4 fun _ h5 => h5.1 +/-- (A64-S1A gen 41) The free-entry scan stops at a null ASID-table entry unless the table is full. -/ +theorem vspace.decode_loop0.free (s : S) : vspace.decode_loop0 st s 0#u64 ⦃ i => + i.val < 128 → L.mem s (wa (L.ksb s) (AtOff i)) = 0#u64 ⦄ := by + unfold vspace.decode_loop0 + apply loop.spec_decr_nat (measure := fun x => 128 - x.val) (inv := fun x => x.val ≤ 128) + · intro x0 h0 + unfold vspace.decode_loop0.body + rw [eq_of_spec_fd P0.Consts.vspace.N_ASID_POOLS.spec, bind_ok] + split + · rename_i hlt + have hlt' : x0.val < 128 := by scalar_tac + rw [vspace.asid_table.eq, bind_ok] + split + · step as ⟨i3, hi3⟩ + exact ⟨by omega, by omega⟩ + · rename_i full + exact (WP.spec_ok _).2 fun _ => UScalar.eq_of_val_eq (by simpa using full) + · rename_i stop + exact (WP.spec_ok _).2 fun lt => absurd (show x0 < 128#usize.val by scalar_tac) (by scalar_tac) + · simp + set_option hygiene false in /-- An error leaf at the decode's state (gen 140: with the state unchanged). -/ local macro "pleafE" : tactic => `(tactic| first @@ -545,18 +709,15 @@ local macro "pleafE" : tactic => `(tactic| first set_option hygiene false in /-- (gen 148) An error leaf at the decode's state, the state unchanged, `ArmQIAt` (`makePoolLIEAt`). -/ local macro "pleafA" : tactic => `(tactic| first - | exact (WP.spec_ok _).2 (Or.inl ⟨rfl, B, Y, ⟨Ac, D.bxi.blk⟩, id, id, id, fun _ => id, fun _ => id⟩) + | exact (WP.spec_ok _).2 (Or.inl ⟨rfl, B, Y, ⟨Ac, D.bxi.blk⟩, id, id, id, fun _ => id, fun _ _ => id, ArmVs.refl _⟩) | (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] - exact (WP.spec_ok _).2 (Or.inl ⟨rfl, B, Y, ⟨Ac, D.bxi.blk⟩, id, id, id, fun _ => id, fun _ => id⟩))) + exact (WP.spec_ok _).2 (Or.inl ⟨rfl, B, Y, ⟨Ac, D.bxi.blk⟩, id, id, id, fun _ => id, fun _ _ => id, ArmVs.refl _⟩))) set_option maxHeartbeats 4000000 in -/-- (gen 148, Architect 09:51Z) **`makePoolLIE` with MakePool's end exposed** (the body of `makePoolLIE`, moved): the -error leaves keep the state and post `ArmQIAt`; the pool's exit names the source `x`, the target `v`, the entry `i`, the -base, `PoolPost`, `ArmQIEnd` at the end heap `PoolH (H.drop R) p sb` and slots `OffR … OS`, and `finWI`'s per-slot -cap fact. -/ -theorem vspace.decode.makePoolLIEAt {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} +/-- (A64-S1A gen 41) **`makePoolLIEAt` with the entry's index, base and exact cap map** (its body, moved). -/ +theorem vspace.decode.makePoolLIEAtX {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s .AsidControl 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) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) @@ -566,11 +727,12 @@ theorem vspace.decode.makePoolLIEAt {s : S} {extra : Aeneas.Std.Array obj.Slot 3 (s' = s ∧ ArmQIAt st H Cs OS Vc ia ie s s') ∨ ∃ x ∈ OS, x ∈ extra.val ∧ ∃ p sb fi, 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 ()) ∧ - ∃ v i base, PoolPost st H OS s s' x v p sb i base ∧ + ∃ v i base, i.val < 128 ∧ base.val = i.val * 512 ∧ L.mem s (wa (L.ksb s) (AtOff i)) = 0#u64 ∧ + PoolPost st H OS s s' x v p sb i base ∧ 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) s' ∧ - (∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → - capA st s' y = capA st s y ∨ ∃ p' b' i' d', capA st s' y = .Untyped p' b' i' d') ⦄ := by + (∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ x → y ≠ v → capA st s' y = capA st s y) ∧ + capA st s' x = .Untyped p sb 4096#u64 false ∧ x ∈ OffR p.val (p.val + 2 ^ sb.val) OS ∧ capA st s v = .Null ⦄ := by have hS : P0.StoreTotal st := L.total unfold vspace.decode rw [cur_thread_ok, bind_ok] @@ -593,7 +755,7 @@ theorem vspace.decode.makePoolLIEAt {s : S} {extra : Aeneas.Std.Array obj.Slot 3 refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun idx _ => ?_ refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun dep _ => ?_ rw [capA_eq, bind_ok, capA_eq, bind_ok] - refine WP.spec_bind (vspace.decode_loop0.le s) fun i hi => ?_ + refine WP.spec_bind (WP.spec_and (vspace.decode_loop0.le s) (vspace.decode_loop0.free s)) fun i ⟨hi, free⟩ => ?_ refine WP.spec_bind P0.Consts.vspace.N_ASID_POOLS.spec fun np hnp => ?_ subst hnp refine spec_ite (fun _ => by pleafA) (fun hne => ?_) @@ -629,7 +791,7 @@ theorem vspace.decode.makePoolLIEAt {s : S} {extra : Aeneas.Std.Array obj.Slot 3 cases u1 have hv0 := hr1 rfl simp only [irq_branch_ok, bind_ok] - refine WP.spec_bind (vspace.makePool.finEIPAt (base := base) (i := i) D P B Y hvr hxO (hSC x hxm hx0) hc hsb er + refine WP.spec_bind (vspace.makePool.finEIPAtX (base := base) (i := i) D P B Y hvr hxO (hSC x hxm hx0) hc hsb er hv hvc hvB hvE hv0 hi' hb) fun s1 h1 => ?_ try simp only [lift, bind_ok] have h64 : sb.val < 64 := by rw [hsb]; first | decide | simp [fl4_abi.consts.bits.ASID_POOL] @@ -641,10 +803,39 @@ theorem vspace.decode.makePoolLIEAt {s : S} {extra : Aeneas.Std.Array obj.Slot 3 refine WP.spec_bind h2 fun s3 h3 => ?_ refine WP.spec_bind h3 fun s4 h4 => ?_ refine WP.spec_bind h4 fun s5 h5 => ?_ - exact (WP.spec_ok _).2 (Or.inr ⟨x, hxO, hxm, p, sb, fi, hc, hsb, er, v, i, base, h5.1, h5.2.1, h5.2.2⟩) + exact (WP.spec_ok _).2 (Or.inr ⟨x, hxO, hxm, p, sb, fi, hc, hsb, er, v, i, base, hi', hb, free hi', h5.1, h5.2.1, + h5.2.2.1, h5.2.2.2.1, h5.2.2.2.2, hv0⟩) · refine spec_ite (fun _ => by pleafA) (fun h => by simp at h) all_goals pleafA +/-- (gen 148, Architect 09:51Z) **`makePoolLIE` with MakePool's end exposed** (the body of `makePoolLIE`, moved): the +error leaves keep the state and post `ArmQIAt`; the pool's exit names the source `x`, the target `v`, the entry `i`, the +base, `PoolPost`, `ArmQIEnd` at the end heap `PoolH (H.drop R) p sb` and slots `OffR … OS`, and `finWI`'s per-slot +cap fact. -/ +theorem vspace.decode.makePoolLIEAt {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s .AsidControl 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) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.ARMASIDControlMakePool) (len : U64) (call : Bool) (buf : U64) : + vspace.decode st ar s a lbl len slot .AsidControl call buf extra ⦃ r s' _ => + (s' = s ∧ ArmQIAt st H Cs OS Vc ia ie s s') ∨ ∃ x ∈ OS, x ∈ extra.val ∧ ∃ p sb fi, + 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 ()) ∧ + ∃ v i base, PoolPost st H OS s s' x v p sb i base ∧ + 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) s' ∧ + (∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st s' y = capA st s y ∨ ∃ p' b' i' d', capA st s' y = .Untyped p' b' i' d') ⦄ := by + refine WP.spec_mono (vspace.decode.makePoolLIEAtX D P B Y hvr hSC a hl len call buf) ?_ + rintro ⟨_, s', _⟩ (h | ⟨x, hx, hxm, p, sb, fi, hc, hsb, he, v, i, base, _, _, _, post, E, kept, source, _, _⟩) + · exact Or.inl h + refine Or.inr ⟨x, hx, hxm, p, sb, fi, hc, hsb, he, v, i, base, post, E, fun y hy hyv => ?_⟩ + by_cases same : y = x + · subst y + exact Or.inr ⟨_, _, _, _, source⟩ + · exact Or.inl (kept y hy same hyv) + /-- (gen 140, Architect ruling of 05:38Z) **ASIDControl MakePool to `ArmQI`, with the source's childlessness**: `makePoolLI`'s body, moved; every exit other than the error leaves (the state unchanged) has passed `ensure_no_children` on the `Untyped` source `x` of the pool's size (for A64-S1A's `UbA.pool`). -/ @@ -761,6 +952,27 @@ theorem syscall.decode_invocation.makePoolLIEAt {s : S} {extra : Aeneas.Std.Arra rw [cur_thread_ok, bind_ok] exact vspace.decode.makePoolLIEAt D P B Y hvr hSC a hl len call buf +/-- (A64-S1A gen 41) The syscall level of `makePoolLIEAtX`. -/ +theorem syscall.decode_invocation.makePoolLIEAtX {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s .AsidControl 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) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.ARMASIDControlMakePool) (len : 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 ⦃ r s' _ => + (s' = s ∧ ArmQIAt st H Cs OS Vc ia ie s s') ∨ ∃ x ∈ OS, x ∈ extra.val ∧ ∃ p sb fi, + 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 ()) ∧ + ∃ v i base, i.val < 128 ∧ base.val = i.val * 512 ∧ L.mem s (wa (L.ksb s) (AtOff i)) = 0#u64 ∧ + PoolPost st H OS s s' x v p sb i base ∧ + 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) s' ∧ + (∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ x → y ≠ v → capA st s' y = capA st s y) ∧ + capA st s' x = .Untyped p sb 4096#u64 false ∧ x ∈ OffR p.val (p.val + 2 ^ sb.val) OS ∧ capA st s v = .Null ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + exact vspace.decode.makePoolLIEAtX D P B Y hvr hSC a hl len call buf + /-- (gen 140) **The `AsidControl` arm of `decode_invocation` at MakePool to `ArmQI`, with the source's childlessness** (`vspace.decode.makePoolLIE`). -/ theorem syscall.decode_invocation.makePoolLIE {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} diff --git a/proofs/Fl4ProofsA64/P1/MdbPoolDelR.lean b/proofs/Fl4ProofsA64/P1/MdbPoolDelR.lean index dec74a860..68f9b2016 100644 --- a/proofs/Fl4ProofsA64/P1/MdbPoolDelR.lean +++ b/proofs/Fl4ProofsA64/P1/MdbPoolDelR.lean @@ -47,6 +47,16 @@ through every `PoolR` step: the deletion loop (`LoopME.ciM` needs only `ApP.null (MdbRvPool), the `OSKeep` steps and the inserts (MdbHiVsArm's `insert_with_cap.poolR`, which takes the new cap's `PtSrc`). **`ApP.of_slot`**, **`PoolR.ap`** (the `AsidPool` half), **`PoolR.ptCap`** (the clause). +(A64-S1A gen 29, Architect 21:41Z, D1 — premise change) **`FinKZ` widened in place** from "every `AsW` word kept or +`0`" to **`VsZ kb Pt`** (every `VsR kb Pt` word kept or `0`: `FinK`'s `VsZ` conjunct); `FinKZ` gains the placement +`Pt` (`FinKZ st ar kb Pt Ty K`), and every statement carrying `hKZ` reads it at `DelIn`'s `Pt`. FL4's K-class +finalisers (`unmap_page`, `unmap_page_table`, `delete_asid`, `delete_asid_pool`) write only `0` into table words; +**`finKZ_s2`** discharges the widened form (each `S2Q` finaliser a `Wr0` step or `fin_pool.hr`'s `VsZ` step). The +pool carry reads the `AsW` half (`finPool`). + +(A64-S1A gen 37) `ApP`'s second conjunct is MdbPtCapA's `CapSrc` (def body); **`PoolR.capSrc`** gives `ArmQIAt`'s cap- +source clause, `PoolR.ptCap` (statement unchanged) its `PtCapP` instance. + Named premises: none. Case facts: none new (`PoolIdx` read). -/ import Fl4ProofsA64.P1.MdbDelIn @@ -113,16 +123,16 @@ theorem PoolNamed.of_map {s s' : S} (ht : TabKeepOrZero st s s') **and a `PageTable` cap naming a table some `OS` slot's `PageTable` cap named at `s0`** (MdbPtCapA's `PtSrc`, so `PoolR` carries `ArmQIAt`'s `PtCap` clause through the deletion family and `cdt.revoke`). -/ def ApP (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s0 : S) (c : capability.Cap) : Prop := - (∀ p b, c = .AsidPool p b → ∃ y0 ∈ OS, capA st s0 y0 = .AsidPool p b) ∧ PtSrc st OS s0 c + (∀ p b, c = .AsidPool p b → ∃ y0 ∈ OS, capA st s0 y0 = .AsidPool p b) ∧ CapSrc st OS s0 c -theorem ApP.null (s0 : S) : ApP st OS s0 .Null := ⟨fun _ _ h => (by cases h), PtSrc.null s0⟩ +theorem ApP.null (s0 : S) : ApP st OS s0 .Null := ⟨fun _ _ h => (by cases h), CapSrc.null s0⟩ theorem ApP.zombie (s0 : S) (p t n : U64) : ApP st OS s0 (.Zombie p t n) := - ⟨fun _ _ h => (by cases h), PtSrc.zombie s0 p t n⟩ + ⟨fun _ _ h => (by cases h), CapSrc.zombie s0 p t n⟩ /-- (gen 160) An `OS` slot's cap at `s0` satisfies `ApP s0`. -/ theorem ApP.of_slot {s0 : S} {y : U64} (hy : y ∈ OS) : ApP st OS s0 (capA st s0 y) := - ⟨fun _ _ hc => ⟨y, hy, hc⟩, PtSrc.of_slot hy rfl⟩ + ⟨fun _ _ hc => ⟨y, hy, hc⟩, CapSrc.of_slot hy rfl⟩ /-- **No `AsidPool` cap.** -/ def NoAp (c : capability.Cap) : Prop := ∀ p b, c ≠ .AsidPool p b @@ -143,9 +153,14 @@ theorem PoolR.ap {s0 s : S} (Q : PoolR st OS s0 s) : ∀ y ∈ OS, ∀ p b, capA st s y = .AsidPool p b → ∃ y0 ∈ OS, capA st s0 y0 = .AsidPool p b := fun y hy => (Q.1 y hy).1 -/-- (gen 160) **`PoolR` gives `ArmQIAt`'s `PtCap` clause** (`PtSrc.ptCap`). -/ +/-- (A64-S1A gen 37) **`PoolR` gives `ArmQIAt`'s cap-source clause** (`CapSrc.inv`). -/ +theorem PoolR.capSrc {s0 s : S} (Q : PoolR st OS s0 s) : + ∀ Q' : capability.Cap → Prop, CapSrcClosed Q' → CapInv st Q' OS s0 → CapInv st Q' OS s := + CapSrc.inv fun y hy => (Q.1 y hy).2 + +/-- (gen 160) **`PoolR` gives `ArmQIAt`'s `PtCap` clause**; (A64-S1A gen 37) `PoolR.capSrc` at `PtCapP Pt`. -/ theorem PoolR.ptCap {s0 s : S} (Q : PoolR st OS s0 s) : ∀ Pt, PtCap st Pt OS s0 → PtCap st Pt OS s := - PtSrc.ptCap fun y hy => (Q.1 y hy).2 + fun Pt => Q.capSrc (PtCapP Pt) (PtCapP.closed Pt) /-- **`PoolR` along a step keeping every `OS` word and every table word.** -/ theorem PoolR.keep {s0 s s' : S} (Q : PoolR st OS s0 s) (k : OSKeep st OS s s') (hk : L.ksb s' = L.ksb s) @@ -160,11 +175,10 @@ def PoolEm (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s : S) (x ∃ y ∈ OS, y ≠ x ∧ ∃ b', capA st s y = .AsidPool p b' /-- **The finaliser class keeps or zeroes the table words** (class fact, module docstring). -/ -def FinKZ (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) (kb : U64) (Ty : S → Prop) - (K : capability.Cap → Prop) : Prop := +def FinKZ (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) (kb : U64) (Pt : Set U64) + (Ty : S → Prop) (K : capability.Cap → Prop) : Prop := ∀ (s : S) (a : A) (c : capability.Cap) (fin : Bool), Ty s → L.ksb s = kb → K c → - objects.finalise_cap st ar s a c fin false ⦃ r => - ∀ b, AsW kb b → L.mem r.2.1 b = L.mem s b ∨ L.mem r.2.1 b = 0#u64 ⦄ + objects.finalise_cap st ar s a c fin false ⦃ r => VsZ st kb Pt s r.2.1 ⦄ /-! ## Non-finality of a pool cap -/ @@ -228,14 +242,14 @@ step). -/ theorem finKZ_s2 (hP : P0.ArchTotal ar) (hPl : ArchPlat ar) {kb : U64} (hR : VrOK Ω Sg Scs Z OS Vc Ub kb Pt) (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te bits ⊆ Pt) (hO : HrOK kb Pp Tb Lv Hr) (hS : S2OK Te bits Hr) : - FinKZ st ar kb (fun s => VsTy st kb Pp Tb Lv s ∧ S2Ty st hPl.ipa Pp Hr Te Re bits s) S2Q := by + FinKZ st ar kb Pt (fun s => VsTy st kb Pp Tb Lv s ∧ S2Ty st hPl.ipa Pp Hr Te Re bits s) S2Q := by intro s a c fin hY hk hc have hTO : TbO Tb Hr ⊆ Pt := fun _ h => hTb h.1 have hU : TbO Tb Hr ∪ Gran Te bits ⊆ Pt := fun _ h => h.elim (fun h' => hTO h') (fun h' => hTe h') have az : ∀ (X : Set U64), X ⊆ Pt → ∀ r : (capability.Cap × capability.Cap) × S × A, r.1 = (.Null, .Null) ∧ Wr0 st X s r.2.1 → - ∀ b, AsW kb b → L.mem r.2.1 b = L.mem s b ∨ L.mem r.2.1 b = 0#u64 := - fun X hX r ⟨_, z⟩ b hb => Wr0.vsz hR.al hX z b (Or.inr hb) + VsZ st kb Pt s r.2.1 := + fun X hX r ⟨_, z⟩ => Wr0.vsz hR.al hX z have hRal : ∀ R ∈ Hr, Aligned (wa R 4088#u64) := fun R hRm => hR.al _ (hr_vsr hTb hO hRm) rcases hc with ((((⟨ptr, size, rights, mapped, asid, vaddr, rfl⟩ | ⟨p, m, ad, rfl⟩ | ⟨p, m, ad, rfl⟩) | ⟨p, b, rfl⟩ | ⟨ptr, size, rights, mapped, asid, vaddr, rfl⟩) | ⟨p, m, ad, v, rfl⟩ | ⟨p, m, ad, v, rfl⟩ | @@ -247,7 +261,7 @@ theorem finKZ_s2 (hP : P0.ArchTotal ar) (hPl : ArchPlat ar) {kb : U64} · rw [fin_cap_eq_obj (by simp)] exact WP.spec_mono (fin_hvs.z hP s a p m ad fin (VsTy.ptPool (Pt := Pp) (fun _ h => h) hY.1 hk ad)) (az _ hPp) · rw [fin_cap_eq_obj (by simp)] - exact WP.spec_mono (fin_pool.hr hP hR hO hRal s a p b fin hk) fun r ⟨_, _, v, _⟩ bb hb => v bb (Or.inr hb) + exact WP.spec_mono (fin_pool.hr hP hR hO hRal s a p b fin hk) fun r ⟨_, _, v, _⟩ => v · rw [fin_cap_eq_obj (by simp)] exact WP.spec_mono (fin_dframe.hr (Hr := Hr) hP hO s a ptr size rights mapped asid vaddr fin hY.1 hk) (az _ hTO) · rw [fin_cap_eq_obj (by simp)] @@ -364,7 +378,7 @@ set_option maxHeartbeats 2000000 in /-- **The finalisation keeps `PoolCN`**, leaves a slot with a `Zombie` remainder holding no `AsidPool` cap, and gives the pool clause (module docstring). -/ theorem finPool (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) - (hTy : TyK st (L.ksb s0) Pt Ty) (hKZ : FinKZ st ar (L.ksb s0) Ty K) (hkw : (L.ksb s0).val + 788736 ≤ 2 ^ 64) + (hTy : TyK st (L.ksb s0) Pt Ty) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hkw : (L.ksb s0).val + 788736 ≤ 2 ^ 64) (hPI : PoolIdx st OS s0) {s : S} (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) (hm : MdbS st OS s) (hA : CapInv st (ApP st OS s0) OS s) (hC : PoolCN st OS s0 s) {x : U64} (hx : x ∈ OS) {c : capability.Cap} @@ -407,7 +421,7 @@ theorem finPool (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ks rcases hX.1 with ⟨hz, -⟩ | hKc · exact WP.spec_mono (finVK E.arch E.os E.sca E.vc E.vr h E.irq hX.2.2 hx hc hz a f) fun r v j => Or.inl (v _ (Or.inr (asW_at _ j))) - · exact WP.spec_mono (hKZ s a c f hX.2.1 hk hKc) fun r z j => z _ (asW_at _ j) + · exact WP.spec_mono (hKZ s a c f hX.2.1 hk hKc) fun r z j => z _ (Or.inr (asW_at _ j)) refine WP.spec_mono (WP.spec_and (finXQG E.arch E.os E.sca E.vc E.vr hK hTy h E.irq hX.2.2 hX.2.1 hk hx hc hX.1 a f) htab) ?_ rintro r ⟨⟨-, jv, k, -⟩, t⟩ @@ -431,7 +445,7 @@ set_option maxHeartbeats 1000000 in /-- **`PoolCN` added to a `LoopME` field** giving `MdbS` and `CapInv (ApP s0)` (module docstring). -/ theorem LoopME.poolM {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} {Em : S → U64 → Prop} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) - (hKZ : FinKZ st ar (L.ksb s0) Ty K) (hkw : (L.ksb s0).val + 788736 ≤ 2 ^ 64) (hPI : PoolIdx st OS s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hkw : (L.ksb s0).val + 788736 ≤ 2 ^ 64) (hPI : PoolIdx st OS s0) (hM : LoopME st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Em M) (hMS : ∀ s, M s → MdbS st OS s) (hMA : ∀ s, M s → CapInv st (ApP st OS s0) OS s) : @@ -465,7 +479,7 @@ set_option maxHeartbeats 1000000 in `cdt.delete.zqIGTsysL` (`cdt.delete.poolR`'s body, generalised to any domain `D` and idle facts `I`, `Is`, so that MdbRvPool's revoke loop uses it from a `DelQ` state). -/ theorem cdt.delete.poolG {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) - (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (hKZ : FinKZ st ar (L.ksb s0) Ty K) + (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x I Is : U64} (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) (hx : x ∈ OS) (hxI : ¬ IslN (L.ksb s0) x) (hD : DomQ st K Vc D H.scs H.tcbs I Is s) (hX : XQ st K Vc D H.scs H.tcbs I Is x s) @@ -486,7 +500,7 @@ theorem cdt.delete.poolG {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK set_option maxHeartbeats 1000000 in /-- **The exposed deletion keeps `PoolR`** (MdbDelIn's `cdt.delete.frUb` text over `LoopME.poolM` ∘ `LoopME.ciM`). -/ -theorem cdt.delete.poolR {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Ty K) +theorem cdt.delete.poolR {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : cdt.delete st ar s a x true ⦃ r => PoolR st OS s0 r.2.1 ⦄ := by @@ -496,7 +510,7 @@ theorem cdt.delete.poolR {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) ( R.ty R.sys R.sym Q /-- **The exposed deletion keeps `DelR ∧ PoolR`.** -/ -theorem cdt.delete.delRP {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Ty K) +theorem cdt.delete.delRP {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : cdt.delete st ar s a x true ⦃ r => DelR st H Cs OS Vc Ub Ac Ty ia ie s0 r.2.1 ∧ PoolR st OS s0 r.2.1 ⦄ := @@ -504,38 +518,28 @@ theorem cdt.delete.delRP {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) ( /-- (gen 147, ruling (a)) **`ArmQI.ofDelR` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, `ArmQI.ofDelR` its projection). -/ -theorem ArmQIAt.ofDelR {s0 s : S} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) : - ArmQIAt st H Cs OS Vc ia ie s0 s ∧ TabKeepOrZero st s0 s := +theorem ArmQIAt.ofDelR {s0 s : S} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) + (hV : ArmVs st H OS Vc s0 s) : ArmQIAt st H Cs OS Vc ia ie s0 s ∧ TabKeepOrZero st s0 s := have ht := Q.2.1 ⟨⟨R.sys, R.sym, by obtain ⟨Ac', hb⟩ := R.jv.1.parts; exact ⟨Ac', hb.blk⟩, fun _ => R.vc, PoolOff.ofTZ ht, Q.2.2, fun _ hPI0 => PoolIdx.of_frame ht.1 ht.old (fun y hy p b hc => Q.ap y hy p b hc) hPI0, - Q.ptCap⟩, ht⟩ + Q.capSrc, hV⟩, ht⟩ /-- **The deletion family's wrapper** (module docstring): `DelR ∧ PoolR` at `s` give `ArmQI` at the decode's own heap and slots, and the table kept or zeroed, from the decode's state `s0`. -/ theorem ArmQI.ofDelR {s0 s : S} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) : ArmQI st H Cs OS Vc ia ie s0 s ∧ TabKeepOrZero st s0 s := - (fun h => ⟨h.1.toQI, h.2⟩) (ArmQIAt.ofDelR R Q) - -/-- (gen 147, ruling (a)) **`cdt.delete.armQI` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, -`cdt.delete.armQI` its projection). -/ -theorem cdt.delete.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Ty K) - (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) - (Q : PoolR st OS s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : - cdt.delete st ar s a x true ⦃ r => ArmQIAt st H Cs OS Vc ia ie s0 r.2.1 ∧ TabKeepOrZero st s0 r.2.1 ⦄ := - WP.spec_mono (cdt.delete.delRP I hKZ hPI R Q hx) fun _ h => ArmQIAt.ofDelR h.1 h.2 + have ht := Q.2.1 + ⟨⟨H, OS, R.sys, R.sym, by obtain ⟨Ac', hb⟩ := R.jv.1.parts; exact ⟨Ac', hb.blk⟩, fun _ => R.vc, + PoolOff.ofTZ ht, Q.2.2, fun _ hPI0 => PoolIdx.of_frame ht.1 ht.old (fun y hy p b hc => Q.ap y hy p b hc) hPI0⟩, + ht⟩ /-- **The exposed deletion to `ArmQI ∧ TabKeepOrZero`** (from `DelR ∧ PoolR`; `ArmQI.ofDelR`). -/ -theorem cdt.delete.armQI {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Ty K) +theorem cdt.delete.armQI {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : cdt.delete st ar s a x true ⦃ r => ArmQI st H Cs OS Vc ia ie s0 r.2.1 ∧ TabKeepOrZero st s0 r.2.1 ⦄ := by - exact WP.spec_mono (cdt.delete.armQIAt I hKZ hPI R Q hx) fun r h => by - first - | exact ⟨h.1.toQI, h.2⟩ - | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) - | exact h.toQI - | (obtain ⟨_, _, _⟩ := r; exact h.toQI) + exact WP.spec_mono (cdt.delete.delRP I hKZ hPI R Q hx) fun _ h => ArmQI.ofDelR h.1 h.2 end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbPoolN.lean b/proofs/Fl4ProofsA64/P1/MdbPoolN.lean index 4aa86de22..fce32da04 100644 --- a/proofs/Fl4ProofsA64/P1/MdbPoolN.lean +++ b/proofs/Fl4ProofsA64/P1/MdbPoolN.lean @@ -15,6 +15,8 @@ item A, option (b); crates/fl4-core/src/arch/aarch64/vspace.rs 1194–1228). * **`PoolPost`** (record): what MdbPoolA's `vspace.makePool.finW` exposes about the post state (the pool heap's `HeapOK`, the kept state-block base, the table words, the new cap, the kept caps) and **`PoolPost.poolOff`** / **`PoolPost.poolNamed`**: `PoolOff` and `PoolNamed` at the post state over `PoolH (H.drop R) p sb` and `OffR`. + (A64-S1A gen 38, Architect ruling item 1) `PoolPost` gains MakePool's memory footprint: **`zr`** (the region is + zero) and **`vs`** (every placed `VsR` word kept, in the region, or the new table word). Finding (gen 131): `PoolOff` after MakePool does **not** need `PoolNamed`. An old entry's pool word `b` (an `Ω \ Sg` word at the decode) either lies off the region (then its object is not dropped: `RegionIn`) or inside it (then it is @@ -162,6 +164,12 @@ structure PoolPost (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS : vR : v ∈ OffR p.val (p.val + 2 ^ sb.val) OS kept : ∀ y ∈ OS, y ≠ x → y ≠ v → capA st s0 y ≠ .Null → y ∈ OffR p.val (p.val + 2 ^ sb.val) OS ∧ capA st s y = capA st s0 y + /-- (A64-S1A gen 38, ruling item 1) **The pool's region is zero** (`clear_free`; the later writes miss it). -/ + zr : ∀ b, Aligned b → p.val ≤ b.val → b.val < p.val + 2 ^ sb.val → L.mem s b = 0#u64 + /-- (A64-S1A gen 38, ruling item 1) **MakePool's memory footprint on the placed `VsR` words**: at every placement + of the decode's state, a `VsR` word is kept, lies in the cleared region (`zr`) or is the new table word (`tabI`). -/ + vs : ∀ Vc Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → ∀ b, VsR (L.ksb s0) Pt b → + L.mem s b = L.mem s0 b ∨ (p.val ≤ b.val ∧ b.val < p.val + 2 ^ sb.val) ∨ b = wa (L.ksb s0) (AtOff i) variable {ia ie : Nat} diff --git a/proofs/Fl4ProofsA64/P1/MdbPrioArm.lean b/proofs/Fl4ProofsA64/P1/MdbPrioArm.lean index 732401a3a..9eec8ccce 100644 --- a/proofs/Fl4ProofsA64/P1/MdbPrioArm.lean +++ b/proofs/Fl4ProofsA64/P1/MdbPrioArm.lean @@ -26,6 +26,9 @@ one). No deletion, no SC change. posting MdbDfM's `DmPost`; **`syscall.decode_invocation.prio_armQIKAt`** (MdbArmDm's `ArmQIAt.ofDMK`) and its `ArmQI` form **`prio_armQIK`**. +(A64-S1A gen 40, Architect ruling for gen 40, R3) `prio_armQIKAt` also posts `ArmVsK` (last conjunct, from +`ArmQIAt.ofDMK`). + Named premises: none. Hypotheses read (ruled gen 148, discharged at the entry layer from QueueDecTcb's **[P]** `TcbPlace`): **`hmcp`** (every TCB's `MCP` below 256 at the decode state, `TcbPlace.mcp`) and **`hcs`** (the current thread's `SC` word nonzero, `TcbPlace.curSc`). Also read, as MdbArmDm's tops: `hks : HeapKsOff H (L.ksb s)`, @@ -438,13 +441,13 @@ theorem syscall.decode_invocation.prio_armQIKAt (hA : P0.ArchTotal ar) {s : S} (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetPriority) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ split · refine (WP.spec_ok _).mpr ?_ - exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s from - ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s⟩) + exact (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeep st s s ∧ OSKeep st OS s s ∧ ArmVsK st H OS Vc s s from + ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl s, OSKeep.rfl' s, ArmVsK.refl s⟩) · exact WP.spec_mono (tcb.decode.prioDM hA D P B Y hSA hcap hmcp hcs hl) fun r d => by obtain ⟨_, s', a'⟩ := r exact ArmQIAt.ofDMK D P B hvr hks hSA d.w d.sys d.blk @@ -464,6 +467,8 @@ theorem syscall.decode_invocation.prio_armQIK (hA : P0.ArchTotal ar) {s : S} exact WP.spec_mono (syscall.decode_invocation.prio_armQIKAt hA D P B Y hvr hks hSA hcap hmcp hcs a hl len blk call don fp buf) fun r h => by first + | exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩ + | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2.1, h.2.2.1⟩) | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) diff --git a/proofs/Fl4ProofsA64/P1/MdbPtCapA.lean b/proofs/Fl4ProofsA64/P1/MdbPtCapA.lean index dcd389030..b35c019d1 100644 --- a/proofs/Fl4ProofsA64/P1/MdbPtCapA.lean +++ b/proofs/Fl4ProofsA64/P1/MdbPtCapA.lean @@ -11,6 +11,12 @@ and drops its copies of `PtCapP`, `PtCap`, `PtCapP.null` / `.zombie` / `.ut` / ` (**`PtSrc.al`**), and `CapInv (PtSrc s0) OS s` gives **`PtSrc.ptCap`**: `∀ Pt, PtCap Pt OS s0 → PtCap Pt OS s`, `ArmQIAt`'s clause (MdbPoolA). **`PtSrc.refl`**, **`PtSrc.trans`**, **`PtSrc.keepO`** (along `OSKeep`), **`PtSrc.setc`** (one `OS` slot written with a cap satisfying `PtSrc s0`, the others kept). +* (A64-S1A gen 37, Architect ruling 01:01Z item 1, J1 / J2 / K1) **The polymorphic cap-source carry** replacing `PtSrc` + at every `ArmQIAt` producer: **`CapMeta`** (in-place mapping-metadata update), **`CapSrcClosed Q`** (fields `null`, + `zombie`, `ut`, `irq`, `der` (`AlikeA ∨ Null` + `FE`), `sub` (4 KiB subframes), `remap`), **`CapSrc st OS s0 c`** + (`∀ Q, CapSrcClosed Q → CapInv Q OS s0 → Q c`) with `.null` / `.zombie` / `.ut` / `.irq` / `.al` / `.remap` / + `.of_slot` / `.refl` / `.trans` / `.ofOSK` / `.setc`, and **`CapSrc.inv`** (`ArmQIAt`'s clause `∀ Q, CapSrcClosed Q → + CapInv Q OS s0 → CapInv Q OS s`); **`PtCapP.closed`** (so `ArmQIAt.ptCap` is a one-line corollary). Named premises: none. Case facts: none. -/ @@ -134,6 +140,94 @@ theorem PtSrc.ptCap {s0 s : S} (h : CapInv st (PtSrc st OS s0) OS s) : obtain ⟨y0, hy0, m0, a0, v0, e0⟩ := h y hy p m a v e exact h0 y0 hy0 p m0 a0 v0 e0 +/-! ## The polymorphic cap-source carry (A64-S1A gen 37, Architect ruling 01:01Z item 1; J1 / J2 / K1) -/ + +/-- **An in-place mapping-metadata update**: `d` is `c` with only its mapping fields changed (kind, `ptr`, size and +device bit kept; a frame keeps its rights, an `Ept` cap its level). -/ +def CapMeta (d c : capability.Cap) : Prop := + (∃ p sz r dv m e a v m' e' a' v', c = .Frame p sz r dv m e a v ∧ d = .Frame p sz r dv m' e' a' v') ∨ + (∃ p m a v m' a' v', c = .PageTable p m a v ∧ d = .PageTable p m' a' v') ∨ + (∃ p m a m' a', c = .Pml4 p m a ∧ d = .Pml4 p m' a') ∨ + (∃ p m a m' a', c = .HighVSpace p m a ∧ d = .HighVSpace p m' a') ∨ + (∃ p l m a v m' a' v', c = .Ept p l m a v ∧ d = .Ept p l m' a' v') + +/-- **A cap class closed under the `ArmQIAt` producers' cap writes** (ruling 01:01Z item 1): `Null`, `Zombie`, +`Untyped` (J2: `insert_with_cap.lrF`'s source), `IrqHandler` (K1: IssueIRQHandler), derivation along `AlikeA ∨ Null` +with the widened `FE` (J1: a frame keeps base, size and device bit), 4 KiB-aligned subframe derivation, and in-place +mapping-metadata updates (`CapMeta`). -/ +structure CapSrcClosed (Q : capability.Cap → Prop) : Prop where + null : Q .Null + zombie : ∀ p t n, Q (.Zombie p t n) + ut : ∀ p b i e, Q (.Untyped p b i e) + irq : ∀ i, Q (.IrqHandler i) + der : ∀ {d c : capability.Cap}, (AlikeA d c ∨ d = .Null) → FE d c → Q c → Q d + sub : ∀ {p p' : U64} {sz : capability.FrameSize} {r r' : U64} {dv m e : Bool} {a v : U64} (k : Nat), + Q (.Frame p sz r dv m e a v) → p'.val = p.val + k * 4096 → Q (.Frame p' .Small r' dv false false 0#u64 0#u64) + remap : ∀ {d c : capability.Cap}, CapMeta d c → Q c → Q d + +/-- **A cap every closed class holding of the `OS` caps at `s0` holds of** (the carry's cap predicate). -/ +def CapSrc (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s0 : S) (c : capability.Cap) : Prop := + ∀ Q, CapSrcClosed Q → CapInv st Q OS s0 → Q c + +theorem CapSrc.null (s0 : S) : CapSrc st OS s0 .Null := fun _ hQ _ => hQ.null + +theorem CapSrc.zombie (s0 : S) (p t n : U64) : CapSrc st OS s0 (.Zombie p t n) := fun _ hQ _ => hQ.zombie p t n + +theorem CapSrc.ut (s0 : S) (p b i : U64) (e : Bool) : CapSrc st OS s0 (.Untyped p b i e) := fun _ hQ _ => + hQ.ut p b i e + +theorem CapSrc.irq (s0 : S) (i : U64) : CapSrc st OS s0 (.IrqHandler i) := fun _ hQ _ => hQ.irq i + +/-- **`CapSrc` passes along `AlikeA ∧ FE`** (`Null` included). -/ +theorem CapSrc.al {s0 : S} {d c : capability.Cap} (ha : AlikeA d c ∨ d = .Null) (hf : FE d c) + (h : CapSrc st OS s0 c) : CapSrc st OS s0 d := fun Q hQ h0 => hQ.der ha hf (h Q hQ h0) + +/-- **`CapSrc` passes along an in-place mapping-metadata update.** -/ +theorem CapSrc.remap {s0 : S} {d c : capability.Cap} (hm : CapMeta d c) (h : CapSrc st OS s0 c) : + CapSrc st OS s0 d := fun Q hQ h0 => hQ.remap hm (h Q hQ h0) + +/-- An `OS` slot's cap at `s0` satisfies `CapSrc s0`. -/ +theorem CapSrc.of_slot {s0 : S} {y : U64} (hy : y ∈ OS) {c : capability.Cap} (hc : capA st s0 y = c) : + CapSrc st OS s0 c := fun _ _ h0 => by rw [← hc]; exact h0 y hy + +theorem CapSrc.refl (s : S) : CapInv st (CapSrc st OS s) OS s := fun _ hy => CapSrc.of_slot hy rfl + +theorem CapSrc.trans {s0 s1 s2 : S} (h1 : CapInv st (CapSrc st OS s0) OS s1) + (h2 : CapInv st (CapSrc st OS s1) OS s2) : CapInv st (CapSrc st OS s0) OS s2 := fun y hy Q hQ h0 => + h2 y hy Q hQ fun y1 hy1 => h1 y1 hy1 Q hQ h0 + +/-- `CapSrc` from `s` along `OSKeep`. -/ +theorem CapSrc.ofOSK {s s' : S} (k : OSKeep st OS s s') : CapInv st (CapSrc st OS s) OS s' := + CapInv.keepO (CapSrc.refl s) k + +/-- **One `OS` slot written with a `CapSrc s0` cap, the other `OS` slots kept.** -/ +theorem CapSrc.setc {s0 s s' : S} (h : CapInv st (CapSrc st OS s0) OS s) {x : U64} {nc : capability.Cap} + (ex : capA st s' x = nc) (hn : CapSrc st OS s0 nc) (ek : ∀ y ∈ OS, y ≠ x → capA st s' y = capA st s y) : + CapInv st (CapSrc st OS s0) OS s' := fun y hy => by + by_cases e : y = x + · rw [e, ex]; exact hn + · rw [ek y hy e]; exact h y hy + +/-- **The carry gives `ArmQIAt`'s cap-source clause** (ruling 01:01Z item 1). -/ +theorem CapSrc.inv {s0 s : S} (h : CapInv st (CapSrc st OS s0) OS s) : + ∀ Q : capability.Cap → Prop, CapSrcClosed Q → CapInv st Q OS s0 → CapInv st Q OS s := fun Q hQ h0 y hy => + h y hy Q hQ h0 + +/-- **`PtCapP` is closed** (so `PtCap` is a corollary of the cap-source clause). -/ +theorem PtCapP.closed (Pt : Set U64) : CapSrcClosed (PtCapP Pt) where + null := PtCapP.null Pt + zombie := PtCapP.zombie Pt + ut := PtCapP.ut Pt + irq := fun _ _ _ _ _ h => by cases h + der := fun ha hf h => PtCapP.al ha hf h + sub := fun _ _ _ _ _ _ _ h => by cases h + remap := by + intro d c hm h p m a v e + subst e + rcases hm with ⟨_, _, _, _, _, _, _, _, _, _, _, _, -, h1⟩ | ⟨p0, m0, a0, v0, _, _, _, e0, h1⟩ | + ⟨_, _, _, _, _, -, h1⟩ | ⟨_, _, _, _, _, -, h1⟩ | ⟨_, _, _, _, _, _, _, _, -, h1⟩ <;> cases h1 + exact h _ m0 a0 v0 e0 + end ST end R end W7 diff --git a/proofs/Fl4ProofsA64/P1/MdbRegRQ.lean b/proofs/Fl4ProofsA64/P1/MdbRegRQ.lean index 810d31847..7e0a03ea1 100644 --- a/proofs/Fl4ProofsA64/P1/MdbRegRQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbRegRQ.lean @@ -17,6 +17,9 @@ P1 (aarch64, gen 152): **TCB ReadRegisters to `ArmQIAt ∧ TabKeepOrZero`, the o `restart_caller.delRP` → `ArmQIAt.ofDelR`; composed by `ArmQIAt.transZ`), **`tcb.decode.readRegsQAt`**, **`syscall.decode_invocation.readRegs_armQIAt`**. +(A64-S1A gen 40, Architect ruling for gen 40, R3) `tcb.decode_read_registers.armQAt`, `tcb.decode.readRegsQAt` and +`readRegs_armQIAt` also post `ArmVsK` (last conjunct; the restart's by MdbHiVsArm's `tcb.restart_caller.armVsK`). + Named premises: none. Case facts: none new. MdbRegRL's `IpcBufC` is not needed here: its `ts` is `DelIn.ts`, its `ia` is `SysL.ipc` (MdbIpcAl's `IpcAl`) at the decode's state; `hrv` is not needed (`suspend.dmr`). -/ @@ -62,7 +65,7 @@ theorem ArmQIAt.ofDFBs {Rp Nt Vc' Ub' Pt' : Set U64} {extra : Aeneas.Std.Array o (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac3 s) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt') (hks : HeapKsOff H (L.ksb s)) - (d : DFB st H Cs c Ko Bw s s') (hBw : ∀ b, Bw b → FrBw H OS b) + (d : DFB st H Cs c Ko Bw s s') (hBw : ∀ b, Bw b → FrBw H OS b ∧ FrCw st OS s b) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' := by @@ -75,11 +78,30 @@ theorem ArmQIAt.ofDFBs {Rp Nt Vc' Ub' Pt' : Set U64} {extra : Aeneas.Std.Array o (fun _ _ c hc => absurd hc (Set.notMem_empty c)) (fun e he => absurd he (Set.notMem_empty e)) hx hb h1 h2 (K8.KW.to7 hk) · exact B.ly.kslo o hl x hx (by rw [← e]; exact ⟨h1, h2⟩) - · exact (hBw b hw).2.2 x hx ⟨h1, h2⟩ - refine (fun h => ⟨h.1, h.2, k⟩) (ArmQIAt.ofWK hvr d.w (fun b hd => ?_) k hS hb) + · exact (hBw b hw).1.2.2 x hx ⟨h1, h2⟩ + have hA : ∀ b, (DfW st H.tcbs Cs H.frame H.scBits Ko s b ∨ Bw b) → ¬ AsW (L.ksb s) b := fun b hd => by + rcases hd with hd | hw + · exact DfW.notAsW P.heap F hvr (fun c hc => q.nodes c hc) hd + · obtain ⟨ptr, z, hp, hz, h1, h2⟩ := (hBw b hw).1.2.1 + exact fun ha => frObj_notAsW hks F.ksw hp hz h1 h2 ha + exact (fun h => ⟨h.1, h.2, k⟩) (ArmQIAt.ofWK hvr d.w hA k hS hb + (ArmVsK.ofFoot P.heap q d.w (fun b hb => hb.imp_right fun hw => Or.inr (hBw b hw).2) hA).toVs) + +/-- (A64-S1A gen 31) **A `DFB` step with `FrBw ∧ FrCw` extra words keeps every placed `VsR` word** (MdbArmVsG's +`ArmVsK.ofFoot`; `ofDFBs`'s footprint). -/ +theorem ArmVsK.ofDFBs {Rp Nt Vc' Ub' Pt' : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot c : U64} + {Ko : Set Nat} {Bw : U64 → Prop} {Ac3 : Set U64} {s s' : S} + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac3 s) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt') (hks : HeapKsOff H (L.ksb s)) + (d : DFB st H Cs c Ko Bw s s') (hBw : ∀ b, Bw b → FrBw H OS b ∧ FrCw st OS s b) : + ArmVsK st H OS Vc s s' := by + obtain ⟨Q, Rq, q⟩ := h.1 + have F : TabF st H Cs OS s := TabF.of hvr q B.ly.ksw P.core0 + refine ArmVsK.ofFoot P.heap q d.w (fun b hb => hb.imp_right fun hw => Or.inr (hBw b hw).2) fun b hd => ?_ rcases hd with hd | hw · exact DfW.notAsW P.heap F hvr (fun c hc => q.nodes c hc) hd - · obtain ⟨ptr, z, hp, hz, h1, h2⟩ := (hBw b hw).2.1 + · obtain ⟨ptr, z, hp, hz, h1, h2⟩ := (hBw b hw).1.2.1 exact fun ha => frObj_notAsW hks F.ksw hp hz h1 h2 ha /-! ## The write phase with the caller's state -/ @@ -125,18 +147,18 @@ theorem RRQ.run {Rp Nt Vc' Ub' Pt' : Set U64} {extra : Aeneas.Std.Array obj.Slot (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s3) Pt') (hks : HeapKsOff H (L.ksb s3)) (P3 : SysPlace st H Cs H.frame Rp Nt OS s3 extra slot) (h3 : BK s3) (hc3 : L.curW s3 = c) (hrun : Runnable (L.mem s3 (stA c))) (B3 : SysL st H Cs OS ia ie s3) (Y3 : SymL st H Cs s3) - (hc : c ∈ H.tcbs) (hFr : ∀ b, Bw b → FrBw H OS b) (h : RRQ st H Cs Ac c Bw s3 s5) : + (hc : c ∈ H.tcbs) (hFr : ∀ b, Bw b → FrBw H OS b ∧ FrCw st OS s3 b) (h : RRQ st H Cs Ac c Bw s3 s5) : sched.set_thread_state st s5 c sched.TS_RUNNING ⦃ s6 => - ArmQIAt st H Cs OS Vc ia ie s3 s6 ∧ TabKeep st s3 s6 ⦄ := by + (ArmQIAt st H Cs OS Vc ia ie s3 s6 ∧ TabKeep st s3 s6) ∧ ArmVsK st H OS Vc s3 s6 ∧ OSKeep st OS s3 s6 ⦄ := by refine WP.spec_mono (WP.spec_and (sched.set_thread_state.dfA s5 c _ h.1.2 hc) (sched.set_thread_state.running_bxi h.1.2.bxi hc h.2.1)) ?_ rintro s6 ⟨⟨f6, l6⟩, b6⟩ have d : DFB st H Cs c ∅ Bw s3 s6 := h.1.1.trans (DFB.ofDF (DF.ofKL f6 l6 (tc_le _ _))) subst hc3 - have hS := SysL.dfB P3 h3.bxi hrun (fun _ h => absurd h (Set.notMem_empty _)) (fun b hb => (hFr b hb).1) - (fun x hx b h1 h2 hb => (hFr b hb).2.2 x hx ⟨h1, h2⟩) B3 Y3 d + have hS := SysL.dfB P3 h3.bxi hrun (fun _ h => absurd h (Set.notMem_empty _)) (fun b hb => (hFr b hb).1.1) + (fun x hx b h1 h2 hb => (hFr b hb).1.2.2 x hx ⟨h1, h2⟩) B3 Y3 d have X := ArmQIAt.ofDFBs (Vc := Vc) P3 B3 h3 hvr hks d hFr hS b6.blk - exact ⟨X.1, X.2.1⟩ + exact ⟨⟨X.1, X.2.1⟩, ArmVsK.ofDFBs P3 B3 h3 hvr hks d hFr, X.2.2⟩ set_option maxHeartbeats 1000000 in /-- **The tail**: the message info, then the caller set running (`RRQ.run`). -/ @@ -145,13 +167,14 @@ theorem RRQ.tail {Rp Nt Vc' Ub' Pt' : Set U64} {extra : Aeneas.Std.Array obj.Slo (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s3) Pt') (hks : HeapKsOff H (L.ksb s3)) (P3 : SysPlace st H Cs H.frame Rp Nt OS s3 extra slot) (h3 : BK s3) (hc3 : L.curW s3 = c) (hrun : Runnable (L.mem s3 (stA c))) (B3 : SysL st H Cs OS ia ie s3) (Y3 : SymL st H Cs s3) - (hc : c ∈ H.tcbs) (hFr : ∀ b, Bw b → FrBw H OS b) (h : RRQ st H Cs Ac c Bw s3 s') (x y : U64) : + (hc : c ∈ H.tcbs) (hFr : ∀ b, Bw b → FrBw H OS b ∧ FrCw st OS s3 b) (h : RRQ st H Cs Ac c Bw s3 s') (x y : U64) : (do let i ← lift (wa x y) let mi ← msginfo.MessageInfo.new 0#u64 0#u64 0#u64 i let s5 ← msg.set_msg_info st s' c mi let s6 ← sched.set_thread_state st s5 c sched.TS_RUNNING - ok (s6, a1)) ⦃ r => ArmQIAt st H Cs OS Vc ia ie s3 r.1 ∧ TabKeep st s3 r.1 ⦄ := by + ok (s6, a1)) ⦃ r => (ArmQIAt st H Cs OS Vc ia ie s3 r.1 ∧ TabKeep st s3 r.1) ∧ ArmVsK st H OS Vc s3 r.1 ∧ + OSKeep st OS s3 r.1 ⦄ := by simp only [lift, bind_ok] refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun mi _ => ?_ refine WP.spec_bind (Pₘ := RRQ st H Cs Ac c Bw s3) ?_ fun s5 h5 => ?_ @@ -171,9 +194,9 @@ theorem tcb.read_registers.armQ {s0 s2 : S} {a : A} {src n : U64} {sus call : Bo (hc2 : L.curW s2 = L.curW s0) (hst : L.mem s2 (stA (L.curW s0)) = sched.TS_RESTART) (hsrc : src ∈ H.tcbs) (hne : src ≠ L.curW s0) (hnm : ∀ k, H src = some k → ∃ x ∈ OS, NamesA (capA st s2 x) src k) - (hL : msg.lookup_ipc_buffer st s2 true (L.curW s0) ⦃ b => b ≠ 0#u64 → BufIn H OS b ∧ BufK H b ⦄) : + (hL : msg.lookup_ipc_buffer st s2 true (L.curW s0) ⦃ b => b ≠ 0#u64 → BufIn H OS b ∧ BufK H b ∧ BufCw st OS s2 b ⦄) : tcb.read_registers st ar s2 a src sus n call ⦃ r => - ArmQIAt st H Cs OS Vc ia ie s2 r.1 ∧ TabKeep st s2 r.1 ⦄ := by + (ArmQIAt st H Cs OS Vc ia ie s2 r.1 ∧ TabKeep st s2 r.1) ∧ ArmVsK st H OS Vc s2 r.1 ∧ OSKeep st OS s2 r.1 ⦄ := by have hct : L.curW s0 ∈ H.tcbs := by rw [← hc2]; exact R.blk.1.choose_spec.choose_spec.curT have hT := R.blk.1.choose_spec.choose_spec.tcbs have hH := R.pl.heap @@ -188,7 +211,8 @@ theorem tcb.read_registers.armQ {s0 s2 : S} {a : A} {src n : U64} {sus call : Bo SysPlace st H Cs H.frame H.replies H.ntfns OS r.1 extra slot ∧ (BK r.1) ∧ L.curW r.1 = L.curW s0 ∧ L.mem r.1 (stA (L.curW s0)) = sched.TS_RESTART ∧ msg.lookup_ipc_buffer st r.1 true (L.curW s0) = msg.lookup_ipc_buffer st s2 true (L.curW s0) ∧ - L.ksb r.1 = L.ksb s0 ∧ (ArmQIAt st H Cs OS Vc ia ie s2 r.1 ∧ TabKeep st s2 r.1)) ?_ ?_ + L.ksb r.1 = L.ksb s0 ∧ OSKeep st OS s2 r.1 ∧ (ArmQIAt st H Cs OS Vc ia ie s2 r.1 ∧ TabKeep st s2 r.1) ∧ + ArmVsK st H OS Vc s2 r.1) ?_ ?_ · split · refine WP.spec_mono (sched.suspend.dmr a src R.blk hsrc R.sys.ly.h0 R.sys.vr R.sym (R.na src hsrc) (fun hnz => (R2.jv.2.run src hsrc).resolve_left hnz) hW hct) ?_ @@ -201,15 +225,15 @@ theorem tcb.read_registers.armQ {s0 s2 : S} {a : A} {src n : U64} {sus call : Bo have ko : ∀ K : U64, (K.val = 3328 ∨ K.val = 3512 ∨ K.val = 64 ∨ K.val = 72) → L.mem s3 (wa (L.curW s0) K) = L.mem s2 (wa (L.curW s0) K) := fun K hK => o3 _ hct hne' K (by omega) (by omega) (by omega) (by omega) (by omega) (by omega) - refine ⟨hS3.1, hS3.2, R.pl.keepO k d3.w.1, b3, c3.trans hc2, ?_, ?_, d3.w.1.trans kb2, - ArmQIAt.ofSusW I R2 hks R.pl.core0 R.blk d3.w hS3 b3⟩ + refine ⟨hS3.1, hS3.2, R.pl.keepO k d3.w.1, b3, c3.trans hc2, ?_, ?_, d3.w.1.trans kb2, k, + ArmQIAt.ofSusW I R2 hks R.pl.core0 R.blk d3.w hS3 b3, (ArmVsK.ofSusW I R2 hks R.pl.core0 R.blk d3.w).2.1⟩ · rw [stA_eq, ko 3328#u64 (by simp), ← stA_eq]; exact hst · exact lookup_buf_agree (ko 3512#u64 (by simp)) (by rw [sbA_field (hT _ hct)]; exact ko 64#u64 (by simp)) (by rw [sbA8_field (hT _ hct)]; exact ko 72#u64 (by simp)) - · exact (WP.spec_ok _).2 ⟨R.sys, R.sym, R.pl, R.blk, hc2, hst, rfl, kb2, - ArmQIAt.ofSusW I R2 hks R.pl.core0 R.blk (WritesIn.refl _ _) ⟨R.sys, R.sym⟩ R.blk⟩ - rintro ⟨s3, a1⟩ ⟨B3, Y3, P3, b3, ec3, st3, lk3, kb3, A23⟩ + · exact (WP.spec_ok _).2 ⟨R.sys, R.sym, R.pl, R.blk, hc2, hst, rfl, kb2, OSKeep.rfl' s2, + ArmQIAt.ofSusW I R2 hks R.pl.core0 R.blk (WritesIn.refl _ _) ⟨R.sys, R.sym⟩ R.blk, ArmVsK.refl s2⟩ + rintro ⟨s3, a1⟩ ⟨B3, Y3, P3, b3, ec3, st3, lk3, kb3, k23, A23, K23⟩ try simp only [uncurry_apply_pair] have hvr3 : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s3) Pt := by rw [kb3]; exact I.del.vr have hks3 : HeapKsOff H (L.ksb s3) := by rw [kb3]; exact hks @@ -219,27 +243,40 @@ theorem tcb.read_registers.armQ {s0 s2 : S} {a : A} {src n : U64} {sus call : Bo split swap · exact WP.spec_bind (RRQ.run (Bw := RRBw 0#u64) hvr3 hks3 P3 b3 ec3 hrun3 B3 Y3 hct - (fun b hb => absurd rfl hb.1) I0) fun s4 h4 => (WP.spec_ok _).2 ⟨A23.1.trans h4.1, A23.2.trans h4.2⟩ + (fun b hb => absurd rfl hb.1) I0) fun s4 h4 => (WP.spec_ok _).2 + ⟨⟨A23.1.transV h4.1.1 (K23.trans k23 h4.2.1).toVs, A23.2.trans h4.1.2⟩, K23.trans k23 h4.2.1, + OSKeep.trans' k23 h4.2.2⟩ rw [lk3] refine WP.spec_bind hL fun buf hbuf => ?_ - have hFr : ∀ b, RRBw buf b → FrBw H OS b := fun b hb => by - obtain ⟨hI, ptr, z, hp, hz, g1, g2⟩ := hbuf hb.1 + have hFr : ∀ b, RRBw buf b → FrBw H OS b ∧ FrCw st OS s3 b := fun b hb => by + obtain ⟨hI, ⟨ptr, z, hp, hz, g1, g2⟩, hC⟩ := hbuf hb.1 have hw := BufIn.word hH hI hb obtain ⟨-, -, g3, g4⟩ := hb - exact ⟨hw.1, ⟨ptr, z, hp, hz, by omega, by omega⟩, hw.2⟩ + exact ⟨⟨hw.1, ⟨ptr, z, hp, hz, by omega, by omega⟩, hw.2⟩, FrCw.keepO k23 (hC b g3 g4)⟩ have hRg : ∀ s1 r v, RRQ st H Cs Ac (L.curW s0) (RRBw buf) s3 s1 → r.val < 384 → obj.Tcb.set_reg st (L.curW s0) s1 r v ⦃ RRQ st H Cs Ac (L.curW s0) (RRBw buf) s3 ⦄ := fun _ _ _ h hr => RRQ.reg h hct hr have hBg : buf ≠ 0#u64 → ∀ s1 j v, RRQ st H Cs Ac (L.curW s0) (RRBw buf) s3 s1 → j.val < 128 → msg.buf_set st s1 buf j v ⦃ RRQ st H Cs Ac (L.curW s0) (RRBw buf) s3 ⦄ := fun h0 _ _ _ h hj => RRQ.buf hH (fun h => (hbuf h).1) h0 h hct hj + have T : ∀ {s' : S}, RRQ st H Cs Ac (L.curW s0) (RRBw buf) s3 s' → ∀ x y : U64, + (do + let i ← lift (wa x y) + let mi ← msginfo.MessageInfo.new 0#u64 0#u64 0#u64 i + let s5 ← msg.set_msg_info st s' (L.curW s0) mi + let s6 ← sched.set_thread_state st s5 (L.curW s0) sched.TS_RUNNING + ok (s6, a1)) ⦃ r => ArmQIAt st H Cs OS Vc ia ie s2 r.1 ∧ TabKeep st s2 r.1 ∧ ArmVsK st H OS Vc s2 r.1 ∧ + OSKeep st OS s2 r.1 ⦄ := fun {_} h x y => + WP.spec_mono (RRQ.tail (Vc := Vc) (a1 := a1) hvr3 hks3 P3 b3 ec3 hrun3 B3 Y3 hct hFr h x y) fun _ h => + ⟨A23.1.transV h.1.1 (K23.trans k23 h.2.1).toVs, A23.2.trans h.1.2, K23.trans k23 h.2.1, + OSKeep.trans' k23 h.2.2⟩ refine WP.spec_bind (hRg s3 _ 0#u64 I0 (by simp [layout.reg.BADGE, layout.reg.X0])) fun s4 h4 => ?_ refine WP.spec_bind (tcb.read_registers_loop0.gen h4 hRg) ?_ rintro ⟨s5, i⟩ h5 try simp only [uncurry_apply_pair] repeat' (first - | exact WP.spec_mono (RRQ.tail hvr3 hks3 P3 b3 ec3 hrun3 B3 Y3 hct hFr ‹_› _ _) - fun r h => ⟨A23.1.trans h.1, A23.2.trans h.2⟩ + | exact T ‹_› _ _ + | exact WP.spec_mono (T ‹_› _ _) fun _ h => ⟨⟨h.1, h.2.1⟩, h.2.2⟩ | (refine WP.spec_bind (tcb.read_registers_loop1.gen ‹_› (hBg (by simpa using ‹(buf != 0#u64) = true›))) ?_ rintro ⟨_, _⟩ _; try simp only [uncurry_apply_pair]) | (refine WP.spec_bind (tcb.read_registers_loop3.gen ‹_› (hBg (by simpa using ‹(buf != 0#u64) = true›))) ?_ @@ -262,8 +299,8 @@ theorem tcb.read_registers.armQ {s0 s2 : S} {a : A} {src n : U64} {sus call : Bo | (step as ⟨_, _⟩)) set_option maxHeartbeats 4000000 in -/-- **`decode_read_registers` after the stall to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem tcb.decode_read_registers.armQAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} +/-- **`decode_read_registers.armQAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem tcb.decode_read_registers.armSAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) @@ -271,13 +308,15 @@ theorem tcb.decode_read_registers.armQAt {s s1 : S} {a1 : A} {t len buf : U64} { (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : tcb.decode_read_registers st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => - ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ OSKeep st OS s r.2.1 ⦄ := by have hS : P0.StoreTotal st := L.total have ht : t ∈ H.tcbs := D.cap.2.1 t rfl have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT have hT := D.bxi.1.choose_spec.choose_spec.tcbs - have E1 : ArmQIAt st H Cs OS Vc ia ie s s1 ∧ TabKeepOrZero st s s1 := ArmQIAt.ofStall I h1 d1 ds1 vk1 - (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) + have E1 : ArmQIAt st H Cs OS Vc ia ie s s1 ∧ TabKeepOrZero st s s1 ∧ ArmVsK st H OS Vc s s1 ∧ + OSKeep st OS s s1 := + (fun h => ⟨h.1, h.2, ArmVsK.ofDFI I D P B d1, ds1.1⟩) (ArmQIAt.ofStall I h1 d1 ds1 vk1 + (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) (ArmVsK.ofDFI I D P B d1)) have est : L.mem s1 (stA (L.curW s1)) = L.mem s (stA (L.curW s)) := by rw [h1.cur, stA_eq]; exact h1.fld _ hct _ (by simp) (by simp) have hr := runnable_ok D.run @@ -299,25 +338,33 @@ theorem tcb.decode_read_registers.armQAt {s s1 : S} {a1 : A} {t len buf : U64} { rename_i hne have hne' : t ≠ L.curW s := by intro e; apply hne; rw [e, show ct = L.curW s from ect.trans h1.cur]; simp - refine WP.spec_bind (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) - (WP.spec_and (Stalled.restart D h1) + refine WP.spec_bind (WP.spec_and (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) + (tcb.restart_caller.armVsK I D P B h1 d1 ds1)) (WP.spec_and (Stalled.restart D h1) (tcb.restart_caller.blk (Es := ∅) s1 h1.bxi.blk (est ▸ hr.1) (est ▸ hr.2)))) ?_ - rintro s2 ⟨⟨⟨RS2, R2⟩, Q2⟩, ⟨-, -, ec2, -⟩, ⟨-, -, est2, k2⟩⟩ + rintro s2 ⟨⟨⟨⟨RS2, R2⟩, Q2, Z2⟩, K2⟩, ⟨-, -, ec2, -⟩, ⟨-, -, est2, -⟩⟩ rw [h1.cur] at est2 - have kb : ∀ K : U64, (K.val = 3512 ∨ K.val = 64 ∨ K.val = 72) → - L.mem s2 (wa (L.curW s) K) = L.mem s (wa (L.curW s) K) := fun K hK => - (k2.fld _ hct K (by omega) (by omega) (by omega) (by omega) (fun _ => ⟨by omega, by omega⟩)).trans - (h1.fld _ hct K (by omega) (by omega)) - have hlk : msg.lookup_ipc_buffer st s2 true (L.curW s) = msg.lookup_ipc_buffer st s true (L.curW s) := - lookup_buf_agree (kb 3512#u64 (by simp)) (by rw [sbA_field (hT _ hct)]; exact kb 64#u64 (by simp)) - (by rw [sbA8_field (hT _ hct)]; exact kb 72#u64 (by simp)) have hx : sbA (L.curW s) ∈ OS := by rw [sbA_slotIdx]; exact I.ts _ hct 2#u64 (by simp) - have hL : msg.lookup_ipc_buffer st s2 true (L.curW s) ⦃ b => b ≠ 0#u64 → BufIn H OS b ∧ BufK H b ⦄ := by - rw [hlk]; exact lookup_bufK B P.heap hx (B.ipc _ hct) + have hL : msg.lookup_ipc_buffer st s2 true (L.curW s) ⦃ b => b ≠ 0#u64 → BufIn H OS b ∧ BufK H b ∧ + BufCw st OS s2 b ⦄ := + lookup_bufKC R2.sys P.heap hx (R2.sys.ipc _ hct) simp only [lift, bind_ok] refine WP.spec_bind (tcb.read_registers.armQ (ar := ar) I R2 RS2 hks ec2 est2 ht hne' (RS2.namedT hcap ht) hL) ?_ rintro ⟨s3, a3⟩ h3 - exact (WP.spec_ok _).2 (ArmQIAt.transZ (ArmQIAt.ofDelR R2 Q2) h3) + exact (WP.spec_ok _).2 ((fun h => ⟨h.1, h.2, ArmVsK.trans K2.1 K2.2 h3.2.1, OSKeep.trans' K2.2 h3.2.2⟩) + (ArmQIAt.transZ (ArmQIAt.ofDelR R2 Q2 Z2.1.toVs) Z2 h3.1 h3.2)) + +set_option maxHeartbeats 4000000 in +/-- **`decode_read_registers` after the stall to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem tcb.decode_read_registers.armQAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + tcb.decode_read_registers st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ⦄ := + WP.spec_mono (tcb.decode_read_registers.armSAt I D P B Y hks hcap h1 d1 ds1 vk1) fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ local macro "lbl_neR" : tactic => `(tactic| exact lbl_ne_of_val (by simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, @@ -330,15 +377,15 @@ local macro "lbl_neR" : tactic => `(tactic| exact lbl_ne_of_val (by fl4_abi.label.TCBSetFlags, fl4_abi.label.TCBSetTimer, fl4_abi.label.TCBReadFPU, core.num.U64.MAX, U64.rMax])) set_option maxHeartbeats 2000000 in -/-- **TCB ReadRegisters to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem tcb.decode.readRegsQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} +/-- **`readRegsQAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem tcb.decode.readRegsSAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) (hl : lbl = fl4_abi.label.TCBReadRegisters) : tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => - ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ OSKeep st OS s r.2.1 ⦄ := by unfold tcb.decode refine WP.spec_bind (smp.remote_tcb_stall.delS hA D I a t) ?_ rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ @@ -347,7 +394,36 @@ theorem tcb.decode.readRegsQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len refine spec_ite (fun hc => absurd (hl.symm.trans hc) ?_) fun _ => ?_ · lbl_neR refine spec_ite (fun _ => ?_) fun hc => absurd hl hc - exact tcb.decode_read_registers.armQAt I D P B Y hks hcap h1 d1 ds1 vk1 + exact tcb.decode_read_registers.armSAt I D P B Y hks hcap h1 d1 ds1 vk1 + +set_option maxHeartbeats 2000000 in +/-- **TCB ReadRegisters to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem tcb.decode.readRegsQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (hl : lbl = fl4_abi.label.TCBReadRegisters) : + tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ⦄ := + WP.spec_mono (tcb.decode.readRegsSAt hA I D P B Y hks hcap hl) fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ + +/-- **`readRegs_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.readRegs_armSAt (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBReadRegisters) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := + syscall.decode_invocation.tcbG + (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x ∧ ArmVsK st H OS Vc s x ∧ + OSKeep st OS s x) + ((fun h => ⟨h.1, h.2, ArmVsK.refl s, OSKeep.rfl' s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s))) + a len blk call don fp buf + fun _ _ e => tcb.decode.readRegsSAt hA I D P B Y hks hcap (e.trans hl) /-- **The Thread arm of `decode_invocation` at ReadRegisters to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ theorem syscall.decode_invocation.readRegs_armQIAt (hA : P0.ArchTotal ar) {s : S} @@ -358,10 +434,9 @@ theorem syscall.decode_invocation.readRegs_armQIAt (hA : P0.ArchTotal ar) {s : S (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBReadRegisters) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := - syscall.decode_invocation.tcbG (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) a len blk call don fp buf - fun _ _ e => tcb.decode.readRegsQAt hA I D P B Y hks hcap (e.trans hl) + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := + WP.spec_mono (syscall.decode_invocation.readRegs_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbRtBlk.lean b/proofs/Fl4ProofsA64/P1/MdbRtBlk.lean index 109f98173..2210ce37a 100644 --- a/proofs/Fl4ProofsA64/P1/MdbRtBlk.lean +++ b/proofs/Fl4ProofsA64/P1/MdbRtBlk.lean @@ -318,7 +318,7 @@ variable {A : Type _} {ar : machine.Arch A} /-- **`untyped::decode` ends with `SysL`, `BlkOK` and any further `I`** over the grown heap and slot set (every creation end by `UtEnd.blk`, the error exits at the decode's start). -/ -theorem untyped.decode.blkI (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} +theorem untyped.decode.blkIH (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {ia ie : Nat} (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) @@ -329,20 +329,41 @@ theorem untyped.decode.blkI (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} (win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) → (H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ hi = p.val + 2 ^ sb.val)) → - I H' (OS1 ∪ NewSl dev nt us aligned win) s') : + WinHi st s' aligned nt us win.val → I H' (OS1 ∪ NewSl dev nt us aligned win) s') : untyped.decode st ar s0 a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => ∃ (H' : Heap) (OS' : Set U64), SysL st H' Cs OS' ia ie s' ∧ (∃ Ac', BlkOK st H'.tcbs Cs H'.omega H' H'.frame H'.replies H'.scs H'.ntfns H'.scBits Ac' s') ∧ I H' OS' s' ⦄ := by have R := UtDecP.of_live D B.sys P hcap B.ln B.vr B.ly - refine WP.spec_mono (untyped.decode.sysLNB hA D P B hcap hfm a lbl len buf + refine WP.spec_mono (untyped.decode.sysLNBH hA D P B hcap hfm a lbl len buf (fun H' OS' s' => (∃ Ac', BlkOK st H'.tcbs Cs H'.omega H' H'.frame H'.replies H'.scs H'.ntfns H'.scBits Ac' s') ∧ I H' OS' s') ⟨R.blk, hI0⟩ - fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp UB => - ⟨UtEnd.blk R B.ly E X hw UB, hI H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp⟩) ?_ + fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp UB WH => + ⟨UtEnd.blk R B.ly E X hw UB, hI H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp WH⟩) ?_ rintro ⟨r, s', a'⟩ ⟨H', OS', B', hb', hI'⟩ exact ⟨H', OS', B', hb', hI'⟩ +/-- Project the original post from the shared creation proof. -/ +theorem untyped.decode.blkI (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {ia ie : Nat} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) (hfm : A64FrameMasks st s0) (a : A) + (lbl len buf : U64) (I : Heap → Set U64 → S → Prop) (hI0 : I H OS s0) + (hI : ∀ (H1 H' : Heap) (OS1 : Set U64) (s1 s' : S) (lo hi : Nat) (aligned nt us dest off win : U64), + UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win → UtX H H1 lo hi us → + (win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) → + (H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ + hi = p.val + 2 ^ sb.val)) → + I H' (OS1 ∪ NewSl dev nt us aligned win) s') : + untyped.decode st ar s0 a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + ∃ (H' : Heap) (OS' : Set U64), SysL st H' Cs OS' ia ie s' ∧ + (∃ Ac', BlkOK st H'.tcbs Cs H'.omega H' H'.frame H'.replies H'.scs H'.ntfns H'.scBits Ac' s') ∧ + I H' OS' s' ⦄ := + untyped.decode.blkIH hA D P B hcap hfm a lbl len buf I hI0 + fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp _ => + hI H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp + /-- **`untyped::decode` ends with `SysL` and `BlkOK`** over the same heap and slot set (`blkI` with no further fact): the retype's and the reset's `BlkOK`. -/ theorem untyped.decode.blkN (hA : P0.ArchTotal ar) {U Ac : Set U64} {s0 : S} diff --git a/proofs/Fl4ProofsA64/P1/MdbRunF.lean b/proofs/Fl4ProofsA64/P1/MdbRunF.lean index a702d3e3a..050558910 100644 --- a/proofs/Fl4ProofsA64/P1/MdbRunF.lean +++ b/proofs/Fl4ProofsA64/P1/MdbRunF.lean @@ -22,6 +22,9 @@ P1 (aarch64, gen 153): **the VCPU Run frame on `SysL ∧ SymL`** (Architect 12:3 (the shared close from the table facts; `ofRunW` and MdbRunQ's `ofRunW0` / `ofRunB0` its projections, statements unchanged). +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ArmQIAt.ofRunBK` also posts the `ArmVsK` it builds (last conjunct); +`ofRunW` takes its first two (statement unchanged). + Named premises: none. Case facts: none new. -/ import Fl4ProofsA64.P1.MdbRegRQ @@ -40,36 +43,36 @@ namespace W7 namespace R namespace ST -variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} +variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} {sd : S} variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} /-- **The run's words** (module docstring). -/ -def RunW (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs Vc OS : Set U64) (s0 : S) (b : U64) : Prop := - SusW st H Cs Vc s0 b ∨ FrBw H OS b +def RunW (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs Vc OS : Set U64) (sd s0 : S) (b : U64) : Prop := + SusW st H Cs Vc s0 b ∨ (FrBw H OS b ∧ FrCw st OS sd b) -theorem RunW.ksb {s0 s1 : S} {b : U64} (hk : L.ksb s1 = L.ksb s0) (h : RunW st H Cs Vc OS s1 b) : - RunW st H Cs Vc OS s0 b := +theorem RunW.ksb {s0 s1 : S} {b : U64} (hk : L.ksb s1 = L.ksb s0) (h : RunW st H Cs Vc OS sd s1 b) : + RunW st H Cs Vc OS sd s0 b := h.imp (SusW.ksb hk) id -theorem RunW.trans {s1 s2 s3 : S} (w1 : WritesIn st s1 s2 (RunW st H Cs Vc OS s1)) - (w2 : WritesIn st s2 s3 (RunW st H Cs Vc OS s2)) : WritesIn st s1 s3 (RunW st H Cs Vc OS s1) := +theorem RunW.trans {s1 s2 s3 : S} (w1 : WritesIn st s1 s2 (RunW st H Cs Vc OS sd s1)) + (w2 : WritesIn st s2 s3 (RunW st H Cs Vc OS sd s2)) : WritesIn st s1 s3 (RunW st H Cs Vc OS sd s1) := (w1.trans w2).mono fun _ hb => hb.elim id (RunW.ksb w1.1) /-- **`DMR` over `RunW`** (module docstring). -/ -structure DMU (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs Vc OS : Set U64) (p q : U64) (s s' : S) : +structure DMU (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs Vc OS : Set U64) (sd : S) (p q : U64) (s s' : S) : Prop where - w : WritesIn st s s' (RunW st H Cs Vc OS s) + w : WritesIn st s s' (RunW st H Cs Vc OS sd s) lv : ∀ x, x ≠ p → x ≠ q → LiveQ st H Cs s' x → LiveQ st H Cs s x idle : L.idleW s' = L.idleW s isc : L.mem s' (scA (L.idleW s')) = L.mem s (scA (L.idleW s)) vr : ValidReplies st H s' sym : SymL st H Cs s' -theorem DMR.toU {p q : U64} {s s' : S} (d : DMR st H Cs Vc p q s s') : DMU st H Cs Vc OS p q s s' := +theorem DMR.toU {p q : U64} {s s' : S} (d : DMR st H Cs Vc p q s s') : DMU st H Cs Vc OS sd p q s s' := ⟨d.w.mono fun _ h => Or.inl h, d.lv, d.idle, d.isc, d.vr, d.sym⟩ -theorem DMU.trans {p q : U64} {s1 s2 s3 : S} (d1 : DMU st H Cs Vc OS p q s1 s2) - (d2 : DMU st H Cs Vc OS p q s2 s3) : DMU st H Cs Vc OS p q s1 s3 := +theorem DMU.trans {p q : U64} {s1 s2 s3 : S} (d1 : DMU st H Cs Vc OS sd p q s1 s2) + (d2 : DMU st H Cs Vc OS sd p q s2 s3) : DMU st H Cs Vc OS sd p q s1 s3 := ⟨RunW.trans d1.w d2.w, fun x hp hq hl => d1.lv x hp hq (d2.lv x hp hq hl), d2.idle.trans d1.idle, d2.isc.trans d1.isc, d2.vr, d2.sym⟩ @@ -77,9 +80,9 @@ theorem DMU.trans {p q : U64} {s1 s2 s3 : S} (d1 : DMU st H Cs Vc OS p q s1 s2) notification states monotone, is a `DMU c q` step (MdbSusQ's `DMR.ofNoneE` with `LvX.tc c 3328`). -/ theorem DMU.ofTc {c q : U64} {s s' : S} (h : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (h0 : H 0#u64 = none) - (Y : SymL st H Cs s) (VR : ValidReplies st H s) (f : WritesIn st s s' (RunW st H Cs Vc OS s)) + (Y : SymL st H Cs s) (VR : ValidReplies st H s) (f : WritesIn st s s' (RunW st H Cs Vc OS sd s)) (g : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.tc c 3328) s s') (M : EpM st H s s') - (hc : L.mem s (stA c) ≠ sched.TS_BLOCKED_ON_REPLY) : DMU st H Cs Vc OS c q s s' := by + (hc : L.mem s (stA c) ≠ sched.TS_BLOCKED_ON_REPLY) : DMU st H Cs Vc OS sd c q s s' := by have hX := h.2.2.1 have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT @@ -100,32 +103,32 @@ theorem DMU.ofTc {c q : U64} {s s' : S} /-! ## (gen 155) The bound-VCPU word -/ /-- **(gen 155) The run's words and the threads' bound-VCPU words** (`tl::VCPU`, offset 3664; module docstring). -/ -def RunB (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs Vc OS : Set U64) (s0 : S) (b : U64) : Prop := - RunW st H Cs Vc OS s0 b ∨ ∃ y ∈ H.tcbs, b = wa y 3664#u64 +def RunB (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs Vc OS : Set U64) (sd s0 : S) (b : U64) : Prop := + RunW st H Cs Vc OS sd s0 b ∨ ∃ y ∈ H.tcbs, b = wa y 3664#u64 -theorem RunB.ksb {s0 s1 : S} {b : U64} (hk : L.ksb s1 = L.ksb s0) (h : RunB st H Cs Vc OS s1 b) : - RunB st H Cs Vc OS s0 b := +theorem RunB.ksb {s0 s1 : S} {b : U64} (hk : L.ksb s1 = L.ksb s0) (h : RunB st H Cs Vc OS sd s1 b) : + RunB st H Cs Vc OS sd s0 b := h.imp (RunW.ksb hk) id -theorem RunB.trans {s1 s2 s3 : S} (w1 : WritesIn st s1 s2 (RunB st H Cs Vc OS s1)) - (w2 : WritesIn st s2 s3 (RunB st H Cs Vc OS s2)) : WritesIn st s1 s3 (RunB st H Cs Vc OS s1) := +theorem RunB.trans {s1 s2 s3 : S} (w1 : WritesIn st s1 s2 (RunB st H Cs Vc OS sd s1)) + (w2 : WritesIn st s2 s3 (RunB st H Cs Vc OS sd s2)) : WritesIn st s1 s3 (RunB st H Cs Vc OS sd s1) := (w1.trans w2).mono fun _ hb => hb.elim id (RunB.ksb w1.1) /-- **(gen 155) `DMU` over `RunB`** (module docstring). -/ -structure DMB (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs Vc OS : Set U64) (p q : U64) (s s' : S) : +structure DMB (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs Vc OS : Set U64) (sd : S) (p q : U64) (s s' : S) : Prop where - w : WritesIn st s s' (RunB st H Cs Vc OS s) + w : WritesIn st s s' (RunB st H Cs Vc OS sd s) lv : ∀ x, x ≠ p → x ≠ q → LiveQ st H Cs s' x → LiveQ st H Cs s x idle : L.idleW s' = L.idleW s isc : L.mem s' (scA (L.idleW s')) = L.mem s (scA (L.idleW s)) vr : ValidReplies st H s' sym : SymL st H Cs s' -theorem DMU.toB {p q : U64} {s s' : S} (d : DMU st H Cs Vc OS p q s s') : DMB st H Cs Vc OS p q s s' := +theorem DMU.toB {p q : U64} {s s' : S} (d : DMU st H Cs Vc OS sd p q s s') : DMB st H Cs Vc OS sd p q s s' := ⟨d.w.mono fun _ h => Or.inl h, d.lv, d.idle, d.isc, d.vr, d.sym⟩ -theorem DMB.trans {p q : U64} {s1 s2 s3 : S} (d1 : DMB st H Cs Vc OS p q s1 s2) - (d2 : DMB st H Cs Vc OS p q s2 s3) : DMB st H Cs Vc OS p q s1 s3 := +theorem DMB.trans {p q : U64} {s1 s2 s3 : S} (d1 : DMB st H Cs Vc OS sd p q s1 s2) + (d2 : DMB st H Cs Vc OS sd p q s2 s3) : DMB st H Cs Vc OS sd p q s1 s3 := ⟨RunB.trans d1.w d2.w, fun x hp hq hl => d1.lv x hp hq (d2.lv x hp hq hl), d2.idle.trans d1.idle, d2.isc.trans d1.isc, d2.vr, d2.sym⟩ @@ -134,7 +137,7 @@ word a `K7.KW` word as the 3672 one). -/ theorem RunB.osk {s s' : S} (hO : OSOK H.tcbs H.omega H.frame OS) (hSA : ScApart H.scs H.scBits OS) (hV : VcOK H.tcbs H.scs H.scBits OS Vc Ub) (hB : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) - (w : WritesIn st s s' (RunB st H Cs Vc OS s)) : OSKeep st OS s s' := by + (w : WritesIn st s s' (RunB st H Cs Vc OS sd s)) : OSKeep st OS s s' := by obtain ⟨Q, R, q0⟩ := hB.1 have hSg := hB.2.2.2.2 exact OSKeep.of_in hO w fun x hx b hb h1 h2 hF => by @@ -144,7 +147,7 @@ theorem RunB.osk {s s' : S} (hO : OSOK H.tcbs H.omega H.frame OS) (hSA : ScApart · exact hV.os b hv ⟨x, hx, h1, h2⟩ · exact kw7_not_os (Es := EH H) q0 hSg.sub hSA (fun _ he => he) hx hb h1 h2 (Or.inl ⟨y, hy, 3672#u64, by simp, by simp, by simp, by simp, e⟩) - · exact hf.2.2 x hx ⟨h1, h2⟩ + · exact hf.1.2.2 x hx ⟨h1, h2⟩ · exact kw7_not_os (Es := EH H) q0 hSg.sub hSA (fun _ he => he) hx hb h1 h2 (Or.inl ⟨y, hy, 3664#u64, by simp, by simp, by simp, by simp, e⟩) @@ -157,7 +160,7 @@ theorem SysL.dfMDB {p q : U64} {s s' : S} (hH : HeapOK H) (hO : OSOK H.tcbs H.om (hSA : ScApart H.scs H.scBits OS) (hp : ∀ k, H p = some k → ∃ x ∈ OS, NamesA (capA st s x) p k) (hq : ∀ k, H q = some k → ∃ x ∈ OS, NamesA (capA st s x) q k) - (B : SysL st H Cs OS ia ie s) (d : DMB st H Cs Vc OS p q s s') : + (B : SysL st H Cs OS ia ie s) (d : DMB st H Cs Vc OS sd p q s s') : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' := by have h := hB obtain ⟨Q, R, q0⟩ := h.1 @@ -172,7 +175,7 @@ theorem SysL.dfMDB {p q : U64} {s s' : S} (hH : HeapOK H) (hO : OSOK H.tcbs H.om · exact dbgw_hw hd · exact Or.inr (Or.inr (Or.inr (Or.inl (hVc _ hv)))) · exact Or.inl ⟨y, hy, 3672#u64, by simp, e⟩ - · exact Or.inr (Or.inr (Or.inr (Or.inl hf.1.1))) + · exact Or.inr (Or.inr (Or.inr (Or.inl hf.1.1.1))) · exact Or.inl ⟨y, hy, 3664#u64, by simp, e⟩) y0 hy0 p b i hc) u, CoverA.keepO hC k d.w.1⟩, ZombiesFinal.recap hz fun _ hy => Or.inl (k.capA hy), KsOffA.of_ub hK d.w.1 u⟩, FrameOK.keepO hfr k, CoverZ.keepO hcz k d.w.1, UtRV.keepO hur k⟩ @@ -183,7 +186,7 @@ theorem SysL.dfMDB {p q : U64} {s s' : S} (hH : HeapOK H) (hO : OSOK H.tcbs H.om · exact out_ne_field (K := 3512#u64) (q0.omega _ (hVc _ hv)) hy (q0.tcbs y hy) (by simp) rfl · exact field_ne (K1 := 3512#u64) (K2 := 3672#u64) (q0.tcbs y hy) (q0.tcbs y' hy') (by simp) (by simp) (fun _ => by simp) e - · exact out_ne_field (K := 3512#u64) (q0.omega _ hf.1.1) hy (q0.tcbs y hy) (by simp) rfl + · exact out_ne_field (K := 3512#u64) (q0.omega _ hf.1.1.1) hy (q0.tcbs y hy) (by simp) rfl · exact field_ne (K1 := 3512#u64) (K2 := 3664#u64) (q0.tcbs y hy) (q0.tcbs y' hy') (by simp) (by simp) (fun _ => by simp) e refine ⟨⟨sys', LiveNamed.transfer B.ln (fun x k' hx hl _ => ?_) (NamesKept.keepO k), d.vr, @@ -208,48 +211,59 @@ theorem SysL.dfMDU {p q : U64} {s s' : S} (hH : HeapOK H) (hO : OSOK H.tcbs H.om (hSA : ScApart H.scs H.scBits OS) (hp : ∀ k, H p = some k → ∃ x ∈ OS, NamesA (capA st s x) p k) (hq : ∀ k, H q = some k → ∃ x ∈ OS, NamesA (capA st s x) q k) - (B : SysL st H Cs OS ia ie s) (d : DMU st H Cs Vc OS p q s s') : + (B : SysL st H Cs OS ia ie s) (d : DMU st H Cs Vc OS sd p q s s') : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' := SysL.dfMDB hH hO hV hVc hB hSA hp hq B d.toB +/-- (A64-S1A gen 28; gen 31: moved here from MdbArmVsW) **A `RunB` word is a `TkW` word or an `FrCw` word at the +decode's state** (MdbArmVsG's `TkW`; the `FrBw` disjunct's `FrCw`). -/ +theorem RunB.tk {s0 : S} {b : U64} (h : RunB st H Cs Vc OS sd s0 b) : TkW st H Cs Vc s0 b ∨ FrCw st OS sd b := by + rcases h with (h | h) | ⟨y, hy, e⟩ + · exact Or.inl (SusW.tk h) + · exact Or.inr h.2 + · exact Or.inl (Or.inr (Or.inr (Or.inr ⟨y, hy, 3664#u64, by simp, e⟩))) + /-- **(gen 155) The shared close across a `RunB` footprint** (the body of `ofRunW`, with the 3664 case: no table word by `TabF.tcb`): `ArmQIAt ∧ TabKeep` from the table facts at `s3` and `OSKeep`. -/ theorem ArmQIAt.ofRunBK {s3 s' : S} {Ac3 Ac' : Set U64} (hH : HeapOK H) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s3) Pt) (hks3 : HeapKsOff H (L.ksb s3)) (F : TabF st H Cs OS s3) (h3 : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac3 s3) - (w : WritesIn st s3 s' (RunB st H Cs Vc OS s3)) (k : OSKeep st OS s3 s') + (w : WritesIn st s3 s' (RunB st H Cs Vc OS s3 s3)) (k : OSKeep st OS s3 s') (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s3 s' ∧ TabKeep st s3 s' := by + ArmQIAt st H Cs OS Vc ia ie s3 s' ∧ TabKeep st s3 s' ∧ ArmVsK st H OS Vc s3 s' := by obtain ⟨Q, Rq, q⟩ := h3.1 - refine ArmQIAt.ofWK hvr w (fun b hd => ?_) k hS hb - rcases hd with (((hd | hd | hv) | ⟨y, hy, e⟩) | hf) | ⟨y, hy, e⟩ - · exact fun ha => K8.KW.notAsWE hH F hvr hks3 (fun _ he => he) (fun c hc => q.nodes c hc) hd ha - · intro ha - rcases hd with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ - · exact F.tcb hH hy (K := 3576#u64) (by simp) ha e.symm - · exact F.tcb hH hy (K := 3584#u64) (by simp) ha e.symm - · exact F.node rfl hc (q.nodes c hc) (by rw [debug_val]; omega) ha e.symm - · exact fun ha => hvr.vc b (Or.inr ha) hv - · exact fun ha => F.tcb hH hy (K := 3672#u64) (by simp) ha e.symm - · obtain ⟨ptr, z, hp, hz, h1, h2⟩ := hf.2.1 - exact fun ha => frObj_notAsW hks3 F.ksw hp hz h1 h2 ha - · exact fun ha => F.tcb hH hy (K := 3664#u64) (by simp) ha e.symm + have hA : ∀ b, RunB st H Cs Vc OS s3 s3 b → ¬ AsW (L.ksb s3) b := by + intro b hd + rcases hd with (((hd | hd | hv) | ⟨y, hy, e⟩) | hf) | ⟨y, hy, e⟩ + · exact fun ha => K8.KW.notAsWE hH F hvr hks3 (fun _ he => he) (fun c hc => q.nodes c hc) hd ha + · intro ha + rcases hd with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ + · exact F.tcb hH hy (K := 3576#u64) (by simp) ha e.symm + · exact F.tcb hH hy (K := 3584#u64) (by simp) ha e.symm + · exact F.node rfl hc (q.nodes c hc) (by rw [debug_val]; omega) ha e.symm + · exact fun ha => hvr.vc b (Or.inr ha) hv + · exact fun ha => F.tcb hH hy (K := 3672#u64) (by simp) ha e.symm + · obtain ⟨ptr, z, hp, hz, h1, h2⟩ := hf.1.2.1 + exact fun ha => frObj_notAsW hks3 F.ksw hp hz h1 h2 ha + · exact fun ha => F.tcb hH hy (K := 3664#u64) (by simp) ha e.symm + have vk : ArmVsK st H OS Vc s3 s' := ArmVsK.ofFoot (Ko := ∅) hH q w (fun b hb => Or.inr (RunB.tk hb)) hA + exact (fun h => ⟨h.1, h.2, vk⟩) (ArmQIAt.ofWK hvr w hA k hS hb vk.toVs) /-- **`ArmQIAt ∧ TabKeep` from a post-install state across a `RunW` footprint** (module docstring; `ofSusW` with the `FrBw` case; gen 155: a projection of `ofRunBK`). -/ theorem ArmQIAt.ofRunW {s0 s3 s' : S} {Ac3 Ac' : Set U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (R3 : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s3) (hks : HeapKsOff H (L.ksb s0)) (hc0 : 0#u64 ∈ Cs) (h3 : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac3 s3) - (w : WritesIn st s3 s' (RunW st H Cs Vc OS s3)) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') + (w : WritesIn st s3 s' (RunW st H Cs Vc OS s3 s3)) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : ArmQIAt st H Cs OS Vc ia ie s3 s' ∧ TabKeep st s3 s' := by obtain ⟨Q, Rq, q⟩ := h3.1 have hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s3) Pt := by rw [R3.jv.ksb]; exact I.del.vr have hks3 : HeapKsOff H (L.ksb s3) := by rw [R3.jv.ksb]; exact hks - have wB : WritesIn st s3 s' (RunB st H Cs Vc OS s3) := w.mono fun _ h => Or.inl h - exact ArmQIAt.ofRunBK I.del.heap hvr hks3 (TabF.of hvr q R3.sys.ly.ksw hc0) h3 wB - (RunB.osk I.del.os I.del.sca I.del.vc h3 wB) hS hb + have wB : WritesIn st s3 s' (RunB st H Cs Vc OS s3 s3) := w.mono fun _ h => Or.inl h + exact (fun h => ⟨h.1, h.2.1⟩) (ArmQIAt.ofRunBK I.del.heap hvr hks3 (TabF.of hvr q R3.sys.ly.ksw hc0) h3 wB + (RunB.osk I.del.os I.del.sca I.del.vc h3 wB) hS hb) end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbRunQ.lean b/proofs/Fl4ProofsA64/P1/MdbRunQ.lean index bb368cfde..ce3c20b37 100644 --- a/proofs/Fl4ProofsA64/P1/MdbRunQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbRunQ.lean @@ -4,7 +4,7 @@ P1 (aarch64, gen 154): **VCPU Run (`decode_run`) to `ArmQIAt ∧ TabKeepOrZero`* [P] `VcPl` / `VcpuW` / `VcpuStA` / `VcpuObjA`; no `ArmVcHyps`, no `RunVcpuAt`). * **The carry `RQ s x`** from the decode's state `s`: only **`RnN`** words written (MdbRunW's `RnV` words with the run - frame `U0 = Ub ∩ FrBw H OS`, or a notification's state word), the liveness frame `LvX.tc ct 3328`, `EpM`. + frame `U0 = Ub ∩ FrBw H OS` (A64-S1A gen 30: `∩ FrCw st OS s`, the decode's buffer cap), or a notification's state word), the liveness frame `LvX.tc ct 3328`, `EpM`. `RQ.trans`; **`RQ.ofV`** (an `RnV` step: MdbLiveV's `LvF.ofVW`, MdbLiveT's `ep_kept`), **`RQ.ofN`** (the notification's `ACTIVE → IDLE` write: MdbSigL's `LvF.wrE`; `EpM` by its new state `IDLE`). * **`rnn_runW`**: an `RnN` word is a MdbRunF `RunW` word; **`RunW.osk`** (every `OS` word kept, MdbRunF's @@ -24,6 +24,9 @@ P1 (aarch64, gen 154): **VCPU Run (`decode_run`) to `ArmQIAt ∧ TabKeepOrZero`* when not `TS_INACTIVE` (the skip is the identity step), the flushes return the VGIC words — as #139's QueueDecVcpuRunB. +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ofRunB0`, `ofRunW0`, `vcpu.decode_run.runQ` and `run_armQIAt` also +post `ArmVsK` (last conjunct; MdbRunF's `ofRunBK`). + Named premises: none. Case facts: none new (`DelIn`, `HeapKsOff` as the other arms; `vc ∈ Vc` by `DelIn.vcc` at the invoked slot). -/ @@ -43,7 +46,7 @@ namespace W7 namespace R namespace ST -variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} +variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} {sd : S} variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s @@ -123,8 +126,8 @@ theorem RQ.ofN {x : S} (h : BK x) {n : U64} (hn : H n = some .ntfn) : rwa [epTSA_wr_ne h (Or.inr hm) hn hne] at hs /-- **An `RnN` word is a `RunW` word** (module docstring). -/ -theorem rnn_runW {s0 : S} {b : U64} (hU : ∀ b ∈ U, FrBw H OS b) (hct : ct ∈ H.tcbs) - (h : RnN st H Cs Vc U ct (L.ksb s0) b) : RunW st H Cs Vc OS s0 b := by +theorem rnn_runW {s0 : S} {b : U64} (hU : ∀ b ∈ U, FrBw H OS b ∧ FrCw st OS sd b) (hct : ct ∈ H.tcbs) + (h : RnN st H Cs Vc U ct (L.ksb s0) b) : RunW st H Cs Vc OS sd s0 b := by rcases h with (hb | hv | ⟨y, hy, ⟨K, k1, k2, -, e⟩ | e⟩ | e | ⟨c, hc, o, ho, h88, s1, e1, e⟩) | ⟨n, hn, e⟩ · exact Or.inr (hU b hb) · exact Or.inl (Or.inl (Or.inr (Or.inr hv))) @@ -142,7 +145,7 @@ end rq /-- **A `RunW` footprint from the decode's state keeps every `OS` word** (MdbRunF's `ofRunW` argument). -/ theorem RunW.osk {s s' : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (h : BK s) - (w : WritesIn st s s' (RunW st H Cs Vc OS s)) : OSKeep st OS s s' := by + (w : WritesIn st s s' (RunW st H Cs Vc OS sd s)) : OSKeep st OS s s' := by obtain ⟨Q, Rq, q⟩ := h.1 have hSg := h.2.2.2.2 exact OSKeep.of_in I.del.os w fun x hx b hb h1 h2 hF => by @@ -152,15 +155,15 @@ theorem RunW.osk {s s' : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (h : BK s) · exact I.del.vc.os b hv ⟨x, hx, h1, h2⟩ · exact kw7_not_os (Es := EH H) q hSg.sub I.del.sca (fun _ he => he) hx hb h1 h2 (Or.inl ⟨y, hy, 3672#u64, by simp, by simp, by simp, by simp, e⟩) - · exact hf.2.2 x hx ⟨h1, h2⟩ + · exact hf.1.2.2 x hx ⟨h1, h2⟩ /-- **(gen 155) `ArmQIAt ∧ TabKeep` from the decode's state across a `RunB` footprint** (MdbRunF's `ofRunBK` with the decode's `DelIn` / `SysL` facts). -/ theorem ArmQIAt.ofRunB0 {s s' : S} {Ac' : Set U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL st H Cs OS ia ie s) (hks : HeapKsOff H (L.ksb s)) (hc0 : 0#u64 ∈ Cs) (h : BK s) - (w : WritesIn st s s' (RunB st H Cs Vc OS s)) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') + (w : WritesIn st s s' (RunB st H Cs Vc OS s s)) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ ArmVsK st H OS Vc s s' := by obtain ⟨Q, Rq, q⟩ := h.1 exact ArmQIAt.ofRunBK I.del.heap I.del.vr hks (TabF.of I.del.vr q B.ly.ksw hc0) h w (RunB.osk I.del.os I.del.sca I.del.vc h w) hS hb @@ -169,9 +172,9 @@ theorem ArmQIAt.ofRunB0 {s s' : S} {Ac' : Set U64} (I : DelIn st ar H Cs OS Vc U `ofRunW` with the decode's `DelIn` / `SysL` in place of a `DelR`; gen 155: a projection of `ofRunB0`). -/ theorem ArmQIAt.ofRunW0 {s s' : S} {Ac' : Set U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL st H Cs OS ia ie s) (hks : HeapKsOff H (L.ksb s)) (hc0 : 0#u64 ∈ Cs) (h : BK s) - (w : WritesIn st s s' (RunW st H Cs Vc OS s)) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') + (w : WritesIn st s s' (RunW st H Cs Vc OS s s)) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' := + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ ArmVsK st H OS Vc s s' := ArmQIAt.ofRunB0 I B hks hc0 h (w.mono fun _ h => Or.inl h) hS hb /-! ## The run frame -/ @@ -179,7 +182,7 @@ theorem ArmQIAt.ofRunW0 {s s' : S} {Ac' : Set U64} (I : DelIn st ar H Cs OS Vc U /-- **The caller's run frame is in `Ub ∩ FrBw`** at any state keeping its buffer slot (module docstring). -/ theorem runBuf_of {s x : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL st H Cs OS ia ie s) {y : U64} (hx : sbWordA y ∈ OS) (hc : capA st x (sbWordA y) = capA st s (sbWordA y)) : - RunBuf st {b | b ∈ Ub ∧ FrBw H OS b} x y := by + RunBuf st {b | b ∈ Ub ∧ FrBw H OS b ∧ FrCw st OS s b} x y := by intro ptr size rights dev x1 x2 x3 x4 bits sz hcap hdev hrw hbits hsz h63 hlt hge subst hdev rw [capA_eq, hc] at hcap @@ -187,37 +190,14 @@ theorem runBuf_of {s x : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL 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 hFo := (B.fo _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits).1 - have hb64 : bits.val < 64 ∧ 12 ≤ bits.val := by + have hb64 : 12 ≤ bits.val := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp - have hszv : sz.val = 2 ^ bits.val := by - have := shl1_val hb64.1 - rw [hsz, WP.spec_ok] at this - exact this - generalize L.mem x (runOffA (L.mem x (runVcpuA y))) = off at h63 hlt hge ⊢ - have ho : off.val % 64 = 0 := by - have e := congrArg UScalar.val h63 - rw [UScalar.val_and, show (63#u64).val = 2 ^ 6 - 1 from rfl, Nat.and_two_pow_sub_one_eq_mod] at e - 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 hpo : (wa ptr off).val = ptr.val + off.val := by - simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega intro i hi - have hv : (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val = ptr.val + off.val + 8 * i.val := by - have : (core.num.U64.wrapping_mul i 8#u64).val = i.val * 8 := by - simp [core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits]; omega - rw [core.num.U64.wrapping_add_val_eq, this, hpo] - simp [U64.size_def, U64.numBits]; omega - have hal' : Aligned (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)) := by - unfold Aligned at hal ⊢; rw [hv]; rw [hpo] at hal; omega - have hin : ptr.val ≤ (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val ∧ - (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val < ptr.val + 2 ^ bits.val := by - rw [hv]; omega - show _ ∈ Ub ∧ FrBw H 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 (I.fu _ hx ptr size rights x1 x2 x3 x4 hcap0 bits hbits _ hal' hin.1 hin.2) - (And.intro (frame_word hH hp hal' hin) (And.intro ⟨ptr, bits.val, hp, hb64.2, hin⟩ fun z hz g => ?_)) + (And.intro (And.intro (frame_word hH hp hal' hin) (And.intro ⟨ptr, bits.val, hp, hb64, hin⟩ fun z hz g => ?_)) + ⟨_, hx, ptr, size, rights, x1, x2, x3, x4, bits, hcap0, hbits, hin⟩) rcases hFo z hz with g' | g' <;> omega /-! ## The steps -/ @@ -421,15 +401,15 @@ local macro "runQ" : tactic => `(tactic| ( exact (WP.spec_ok _).2 (fin c11 d11))) set_option maxHeartbeats 4000000 in -/-- **`ARMVCPURun` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem vcpu.decode_run.runQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U64} +/-- **`decode_run.runQ` exporting the slot fact** (A64-S1A gen 41). -/ +theorem vcpu.decode_run.runS (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Vcpu vc) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Vcpu vc)) (a : A) (len : U64) (call : Bool) (buf : U64) : vcpu.decode_run st ar s a vc len call buf ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by have hS : P0.StoreTotal st := L.total have hb0 : BK s := D.bxi.blk have hT : TcbPlaced H.tcbs := hb0.1.choose_spec.choose_spec.tcbs @@ -440,12 +420,12 @@ theorem vcpu.decode_run.runQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U have hw : VcWords H.omega H.frame vc := hW' vc hvc have hT0 := (I.vty.obj vc hvc).2.1 have hWv : ∀ b, VcW Vc b → b ∈ H.omega ∧ b ∉ H.frame := fun b hb => (I.vty.w hb).2 - have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, hb0⟩ id (PoolR.refl s) + have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ OSKeep st OS s s := + (fun h => ⟨h.1, h.2, ArmVsK.refl s, OSKeep.rfl' s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, hb0⟩ id (PoolR.refl s) (ArmVs.refl s)) -- the run frame - let U0 : Set U64 := {b | b ∈ Ub ∧ FrBw H OS b} + let U0 : Set U64 := {b | b ∈ Ub ∧ FrBw H OS b ∧ FrCw st OS s b} have hUs : ∀ b ∈ U0, UsrW st H.tcbs Cs H H.frame H.scs H.scBits s b := fun b hb => I.vty.usr b hb.1 - have hUF : ∀ b ∈ U0, FrBw H OS b := fun b hb => hb.2 + have hUF : ∀ b ∈ U0, FrBw H OS b ∧ FrCw st OS s b := fun b hb => hb.2 have stp : ∀ {x x' : S}, (C0 s x) → RQ st H Cs Vc U0 (L.curW s) s x → WritesIn st x x' (RnV st H.tcbs Cs Vc U0 (L.curW s) (L.ksb x)) → L.idleW x' = L.idleW x → RQ st H Cs Vc U0 (L.curW s) s x' := fun {x x'} c d w hi => by @@ -456,11 +436,12 @@ theorem vcpu.decode_run.runQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U ((RunW.osk I hb0 (w.mono fun b hb => rnn_runW hUF hct hb)).capA (I.del.vc.bcov _ hct)) -- the close have fin : ∀ {x : S}, (C0 s x) → RQ st H Cs Vc U0 (L.curW s) s x → - ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x := fun {x} c d => by - have f : WritesIn st s x (RunW st H Cs Vc OS s) := d.w.mono fun b hb => rnn_runW hUF hct hb - have dm : DMU st H Cs Vc OS (L.curW s) 0#u64 s x := + ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x ∧ ArmVsK st H OS Vc s x ∧ + OSKeep st OS s x := fun {x} c d => by + have f : WritesIn st s x (RunW st H Cs Vc OS s s) := d.w.mono fun b hb => rnn_runW hUF hct hb + have dm : DMU st H Cs Vc OS s (L.curW s) 0#u64 s x := DMU.ofTc hb0 B.ly.h0 Y B.vr f d.lv d.ep (runnable_ne_reply D.run) - have d0 : DMU st H Cs Vc OS 0#u64 0#u64 s x := ⟨dm.w, fun z hp _ hl => by + have d0 : DMU st H Cs Vc OS s 0#u64 0#u64 s x := ⟨dm.w, fun z hp _ hl => by by_cases hz : z = L.curW s · subst hz; exact Or.inl ⟨hct, Or.inl (runnable_ne_inactive D.run)⟩ · exact dm.lv z hz hp hl, dm.idle, dm.isc, dm.vr, dm.sym⟩ @@ -469,7 +450,7 @@ theorem vcpu.decode_run.runQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U have hS' := SysL.dfMDU I.del.heap I.del.os I.del.vc (fun b hb => (I.vty.w hb).2.1) hb0 I.del.sca hp0 hp0 B d0 obtain ⟨Ac', hb'⟩ := c.bxi have A' := ArmQIAt.ofRunW0 I B hks P.core0 hb0 f hS' hb'.blk - exact ⟨A'.1, A'.2.toDel⟩ + exact ⟨A'.1, A'.2.1.toDel, A'.2.2, RunW.osk I hb0 f⟩ unfold vcpu.decode_run rw [eq_of_spec_fd P0.Consts.layout.tcb.RUN_VCPU.spec] refine spec_ite (fun _ => ?_) (fun _ => by errQ) @@ -522,13 +503,27 @@ theorem vcpu.decode_run.runQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U try dsimp only runQ +set_option maxHeartbeats 4000000 in +/-- **`ARMVCPURun` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem vcpu.decode_run.runQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Vcpu vc) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Vcpu vc)) (a : A) + (len : U64) (call : Bool) (buf : U64) : + vcpu.decode_run st ar s a vc len call buf ⦃ r s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := + WP.spec_mono (vcpu.decode_run.runS hA I D P B Y hks hcap a len call buf) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨h.1, h.2.1, h.2.2.1⟩ + local macro "lbl_neV" : tactic => `(tactic| exact lbl_ne_of_val (by simp [fl4_abi.label.ARMVCPUSetTCB, fl4_abi.label.ARMVCPUInjectIRQ, fl4_abi.label.ARMVCPUReadReg, fl4_abi.label.ARMVCPUWriteReg, fl4_abi.label.ARMVCPUAckVPPI, fl4_abi.label.ARMVCPUReadState, fl4_abi.label.ARMVCPUWriteState, fl4_abi.label.ARMVCPURun])) -/-- **The `Vcpu` arm of `decode_invocation` at Run to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem syscall.decode_invocation.run_armQIAt (hA : P0.ArchTotal ar) {s : S} +/-- **`run_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.run_armSAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) 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) @@ -536,7 +531,7 @@ theorem syscall.decode_invocation.run_armQIAt (hA : P0.ArchTotal ar) {s : S} (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPURun) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ unfold vcpu.decode @@ -544,10 +539,23 @@ theorem syscall.decode_invocation.run_armQIAt (hA : P0.ArchTotal ar) {s : S} refine spec_ite (fun hc => absurd (hl.symm.trans hc) ?_) fun _ => ?_ · lbl_neV refine spec_ite (fun _ => ?_) fun hc => absurd hl hc - exact WP.spec_mono (vcpu.decode_run.runQ hA I D P B Y hks hcap a len call buf) fun r d => by + exact WP.spec_mono (vcpu.decode_run.runS hA I D P B Y hks hcap a len call buf) fun r d => by obtain ⟨_, s', a'⟩ := r exact d +/-- **The `Vcpu` arm of `decode_invocation` at Run to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem syscall.decode_invocation.run_armQIAt (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Vcpu vc)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPURun) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) 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' ⦄ := + WP.spec_mono (syscall.decode_invocation.run_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ + end ST end R end W7 diff --git a/proofs/Fl4ProofsA64/P1/MdbRvPool.lean b/proofs/Fl4ProofsA64/P1/MdbRvPool.lean index f5dfc2a02..5577976e5 100644 --- a/proofs/Fl4ProofsA64/P1/MdbRvPool.lean +++ b/proofs/Fl4ProofsA64/P1/MdbRvPool.lean @@ -47,7 +47,7 @@ theorem sched.preemption_point.poolR {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L. set_option maxHeartbeats 1000000 in /-- **The exposed deletion of an IRQ-node slot on a `DelQ` state keeps `PoolR`** (module docstring). -/ theorem cdt.delete.poolI {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) - (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (hKZ : FinKZ st ar (L.ksb s0) Ty K) + (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x I Is : U64} (Qd : DelQ st H Cs OS D Vc Ub Ac K Ty ia ie I Is s0 s) (hxI : IslN (L.ksb s0) x) (Q : PoolR st OS s0 s) : cdt.delete st ar s a x true ⦃ r => PoolR st OS s0 r.2.1 ⦄ := by @@ -66,7 +66,7 @@ set_option maxHeartbeats 1000000 in /-- **`cdt.revoke` of an `OS` slot from `DelQ ∧ PoolR` keeps both** (module docstring; MdbLiveY's `cdt.revoke.gen` at `Pr := PoolR st OS s0`). -/ theorem cdt.revoke.poolR {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) - (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (hKZ : FinKZ st ar (L.ksb s0) Ty K) + (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) (hDall : ∀ y ∈ OS, ¬ IslN (L.ksb s0) y → y ∈ D) {a : A} {x I Is : U64} (Qd : DelQ st H Cs OS D Vc Ub Ac K Ty ia ie I Is s0 s) (Q : PoolR st OS s0 s) (hx : x ∈ OS) : cdt.revoke st ar s a x ⦃ r => diff --git a/proofs/Fl4ProofsA64/P1/MdbSendQ.lean b/proofs/Fl4ProofsA64/P1/MdbSendQ.lean index 39b588c41..7a559c5b2 100644 --- a/proofs/Fl4ProofsA64/P1/MdbSendQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbSendQ.lean @@ -14,6 +14,9 @@ MdbXferQ's carry `XC`). `sched.set_thread_state.restartQ` (`ArmQIAt.ofDelR`), then `send_ipc` (`recvQ` / `blockQ`) closed by MdbXferQ's `ArmQIAt.ofXC`; without the send right the error leaf (`ArmQIAt.ofPR` at the decode's state). +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ep_armQIAt` also posts `ArmVsK` (last conjunct: the restart's and +the send's, `ArmVsK.trans`). + Named premises: none new (QueueSignal's [J] `RunVcpuInv`, taken as `DecPre.rv` as in `epL`). Case facts: none new — `hks : HeapKsOff H (L.ksb s)` (S1aPlace, ruled gen 136); `TcbSlotsOS` (`epL`'s `hTS`), `ScApart` and `VrOK` are `DelIn`'s (`ts`, `del.sca`, `del.vr`). @@ -41,10 +44,8 @@ local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H. local notation "BX" Xq "," s => BlkOKX st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac Xq s set_option maxHeartbeats 4000000 in -/-- **`send_ipc` on a receiving endpoint, the carry under the table hypotheses** (module docstring; the one body of -MdbSendE's `endpoint.send_ipc.recvL` and `recvQ`): the dequeue's and the tail's `DMD` footprints by `FootD.oskTab`, -the transfer by `do_ipc_transfer.xjQ` when `HeapKsOff` / `VrOK` hold, by MdbXferL's `xjX` otherwise. -/ -theorem endpoint.send_ipc.recvG (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U64} +/-- **`send_ipc` on a receiving endpoint with the carry and the slot fact** (A64-S1A gen 41). -/ +theorem endpoint.send_ipc.recvS (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) (blocking do_call : Bool) (badge : U64) (can_grant can_grant_reply can_donate : Bool) (t e : U64) (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (h : BK s) (hSA : ScApart H.scs H.scBits OS) @@ -54,7 +55,8 @@ theorem endpoint.send_ipc.recvG (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U6 (hdon : can_donate = true → L.mem s (scA t) ≠ 0#u64) (hRV : RunVcpuInv st H.tcbs s) : endpoint.send_ipc st ar s a blocking do_call badge can_grant can_grant_reply can_donate t e ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ - (HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → XC st OS Vc s s') ⦄ := by + (HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → XC st OS Vc s s' ∧ + XV st H OS Vc s s' ∧ XferSlots st OS s s') ⦄ := by obtain ⟨⟨Q, R, q⟩, hB, -, -, hSg⟩ := id h have hT := q.tcbs have ht := hc.mem @@ -76,14 +78,15 @@ theorem endpoint.send_ipc.recvG (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U6 refine WP.spec_bind (endpoint.ep_dequeue.sysL P h hSA B Y hH hst hp) ?_ rintro s1 ⟨B1, Y1, b1, P1, d1, f1, ea1, -, ei1⟩ have g1 : HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → - XC st OS Vc s s1 := fun hks hvr => by - obtain ⟨k1, t1⟩ := FootD.oskTab P.heap P.os hSA hvr hks B.ly.ksw P.core0 q hSg.sub (fun _ he => he) d1.w - exact XC.keep k1 t1 + XC st OS Vc s s1 ∧ XV st H OS Vc s s1 ∧ OSKeep st OS s s1 := fun hks hvr => by + obtain ⟨k1, t1, v1⟩ := FootD.oskTabV (Vc := Vc) P.heap P.os hSA hvr hks B.ly.ksw P.core0 q hSg.sub (fun _ he => he) + d1.w + exact ⟨XC.keep k1 t1, XV.keep v1 k1, k1⟩ have XT : ipc.do_ipc_transfer st ar s1 a t e badge can_grant hd ⦃ s2 => XJX st H Cs OS ia ie Ac {y | y ∈ (∅ : Set U64) ∨ y = hd} s1 s2 ∧ (HeapKsOff H (L.ksb s1) ∧ VrOK H.omega H.frame H.scs H.scBits OS Vc' - Ub (L.ksb s1) Pt → XC st OS Vc s1 s2) ⦄ := by + Ub (L.ksb s1) Pt → XC st OS Vc s1 s2 ∧ XV st H OS Vc s1 s2 ∧ XferSlots st OS s1 s2) ⦄ := by by_cases hkv : HeapKsOff H (L.ksb s1) ∧ VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s1) Pt - · exact WP.spec_mono (ipc.do_ipc_transfer.xjQ (Vc := Vc) hA a P1 hSA hTS hkv.1 hkv.2 B1 Y1 b1 ht hdT) + · exact WP.spec_mono (ipc.do_ipc_transfer.xjS (Vc := Vc) hA a P1 hSA hTS hkv.1 hkv.2 B1 Y1 b1 ht hdT) fun _ h => ⟨h.1, fun _ => h.2⟩ · exact WP.spec_mono (ipc.do_ipc_transfer.xjX hA a P1 hSA hTS B1 Y1 b1 ht hdT) fun _ h => ⟨h, fun h' => absurd h' hkv⟩ refine WP.spec_bind XT fun s2 ⟨J, c2⟩ => ?_ @@ -198,13 +201,14 @@ theorem endpoint.send_ipc.recvG (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U6 SndT.dmd J.blk J.sys.ly.h0 J.sym (T3.trans T7) (fun _ hq => Or.inr hq) (EpM.ofFootDX J.blk (F3.trans f7)) obtain ⟨B7, Y7⟩ := SysL.dfMDO P.heap P.os J.blk hSA (fun k hk => by rw [J.sys.ly.h0] at hk; cases hk) J.sys d refine ⟨B7, Y7, b7, fun hks hvr => ?_⟩ - have c1 := g1 hks hvr + obtain ⟨c1, x1, k1⟩ := g1 hks hvr have e1 : L.ksb s1 = L.ksb s := c1.2.2.1 - have c2' := c2 ⟨by rw [e1]; exact hks, by rw [e1]; exact hvr⟩ + obtain ⟨c2', x2, S2⟩ := c2 ⟨by rw [e1]; exact hks, by rw [e1]; exact hvr⟩ have hk2 : L.ksb s2 = L.ksb s := c2'.2.2.1.trans e1 - obtain ⟨k7, t7⟩ := FootD.oskTab P.heap P.os hSA (by rw [hk2]; exact hvr) (by rw [hk2]; exact hks) J.sys.ly.ksw - P.core0 q2 hSg2.sub (fun _ he => he) d.w - exact c1.trans (c2'.trans (XC.keep k7 t7)) + obtain ⟨k7, t7, v7⟩ := FootD.oskTabV (Vc := Vc) P.heap P.os hSA (by rw [hk2]; exact hvr) (by rw [hk2]; exact hks) + J.sys.ly.ksw P.core0 q2 hSg2.sub (fun _ he => he) d.w + exact ⟨c1.trans (c2'.trans (XC.keep k7 t7)), x1.trans (x2.trans (XV.keep v7 k7)), + XferSlots.before (fun z hz => k1.capA hz) (S2.keep fun z hz => k7.capA hz)⟩ split · repeat' split all_goals first @@ -218,6 +222,27 @@ theorem endpoint.send_ipc.recvG (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U6 | exact schedcontext.donate.rcv hA M a (by rw [sc3]; exact hdon (by assumption)) | exact rcv_ok M a +set_option maxHeartbeats 4000000 in +/-- **`send_ipc` on a receiving endpoint, the carry under the table hypotheses** (module docstring; the one body of +MdbSendE's `endpoint.send_ipc.recvL` and `recvQ`): the dequeue's and the tail's `DMD` footprints by `FootD.oskTab`, +the transfer by `do_ipc_transfer.xjQ` when `HeapKsOff` / `VrOK` hold, by MdbXferL's `xjX` otherwise. -/ +theorem endpoint.send_ipc.recvG (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) (blocking do_call : Bool) (badge : U64) + (can_grant can_grant_reply can_donate : Bool) (t e : U64) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (h : BK s) (hSA : ScApart H.scs H.scBits OS) + (hTS : TcbSlotsOS H.tcbs OS) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hH : H e = some .ep) + (hst : L.epState s e = 2#u64) (hp : ∀ k, H e = some k → ∃ x ∈ OS, NamesA (capA st s x) e k) + (hc : CanBlock st H.tcbs Ac s t) (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) + (hdon : can_donate = true → L.mem s (scA t) ≠ 0#u64) (hRV : RunVcpuInv st H.tcbs s) : + endpoint.send_ipc st ar s a blocking do_call badge can_grant can_grant_reply can_donate t e + ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ + (HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → XC st OS Vc s s' ∧ + XV st H OS Vc s s') ⦄ := + WP.spec_mono (endpoint.send_ipc.recvS (Vc := Vc) (Vc' := Vc') (Ub := Ub) (Pt := Pt) hA a blocking do_call badge + can_grant can_grant_reply can_donate t e P h hSA hTS B Y hH hst hp hc hrun hdon hRV) fun r hh => by + obtain ⟨_, _⟩ := r + exact ⟨hh.1, hh.2.1, hh.2.2.1, fun hks hvr => ⟨(hh.2.2.2 hks hvr).1, (hh.2.2.2 hks hvr).2.1⟩⟩ + /-- **`send_ipc` on a receiving endpoint with the carry** (module docstring): `recvG` at the table hypotheses. -/ theorem endpoint.send_ipc.recvQ (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) (blocking do_call : Bool) (badge : U64) @@ -229,16 +254,16 @@ theorem endpoint.send_ipc.recvQ (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U6 (hdon : can_donate = true → L.mem s (scA t) ≠ 0#u64) (hRV : RunVcpuInv st H.tcbs s) (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) : endpoint.send_ipc st ar s a blocking do_call badge can_grant can_grant_reply can_donate t e - ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ XC st OS Vc s s' ⦄ := + ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ XC st OS Vc s s' ∧ + XV st H OS Vc s s' ⦄ := WP.spec_mono (endpoint.send_ipc.recvG (Vc := Vc) (Vc' := Vc') (Ub := Ub) (Pt := Pt) hA a blocking do_call badge can_grant can_grant_reply can_donate t e P h hSA hTS B Y hH hst hp hc hrun hdon hRV) fun r hh => by obtain ⟨_, _⟩ := r exact ⟨hh.1, hh.2.1, hh.2.2.1, hh.2.2.2 hks hvr⟩ set_option maxHeartbeats 4000000 in -/-- **The blocking send, the carry under the table hypotheses** (the one body of MdbSendE's `endpoint.send_block.sysL` -and `sysQ`: its `DMD e` step's footprint by `FootD.oskTab`). -/ -theorem endpoint.send_block.sysG {A : Type _} {Rp Nt Vc' Ub Pt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} +/-- **The blocking send with the carry and the slot fact** (A64-S1A gen 41). -/ +theorem endpoint.send_block.sysS {A : Type _} {Rp Nt Vc' Ub Pt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) (t e badge : U64) (can_grant can_grant_reply do_call : Bool) (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (h : BK s) (hSA : ScApart H.scs H.scBits OS) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hH : H e = some .ep) @@ -258,7 +283,8 @@ theorem endpoint.send_block.sysG {A : Type _} {Rp Nt Vc' Ub Pt : Set U64} {extra let s5 ← sched.schedule_tcb st s4 t let s6 ← endpoint.ep_append st s5 e t obj.EP_SEND ok (s6, a)) ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ - (HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → XC st OS Vc s s') ⦄ := by + (HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → XC st OS Vc s s' ∧ + XV st H OS Vc s s' ∧ OSKeep st OS s s') ⦄ := by obtain ⟨⟨Q, R, q⟩, hB, hX, hS, hSg⟩ := id h have C := LvC.of_blk h refine WP.spec_mono (WP.spec_and (send_block.sbw (Ac := Ac) s a t e badge can_grant can_grant_reply do_call q hc hH) @@ -279,9 +305,39 @@ theorem endpoint.send_block.sysG {A : Type _} {Rp Nt Vc' Ub Pt : Set U64} {extra (fun n hn hne hs => by unfold LawfulStore.epState at hs ⊢; rwa [kE n (Or.inr hn) hne] at hs) obtain ⟨B1, Y1⟩ := SysL.dfMDX P h hSA hp B d refine ⟨B1, Y1, ⟨⟨Q, R, h1⟩, hB1, hX1, hS1, hSg1⟩, fun hks hvr => ?_⟩ - obtain ⟨k, tk⟩ := FootD.oskTab P.heap P.os hSA hvr hks B.ly.ksw P.core0 q hSg.sub (fun _ he => he) d.w - exact XC.keep k tk + obtain ⟨k, tk, v⟩ := FootD.oskTabV (Vc := Vc) P.heap P.os hSA hvr hks B.ly.ksw P.core0 q hSg.sub (fun _ he => he) + d.w + exact ⟨XC.keep k tk, XV.keep v k, k⟩ +set_option maxHeartbeats 4000000 in +/-- **The blocking send, the carry under the table hypotheses** (the one body of MdbSendE's `endpoint.send_block.sysL` +and `sysQ`: its `DMD e` step's footprint by `FootD.oskTab`). -/ +theorem endpoint.send_block.sysG {A : Type _} {Rp Nt Vc' Ub Pt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} {s : S} (a : A) (t e badge : U64) (can_grant can_grant_reply do_call : Bool) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (h : BK s) (hSA : ScApart H.scs H.scBits OS) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hH : H e = some .ep) + (hst0 : L.epState s e = 0#u64 ∨ L.epState s e = 1#u64) + (hp : ∀ k, H e = some k → ∃ x ∈ OS, NamesA (capA st s x) e k) + (hc : CanBlock st H.tcbs Ac s t) (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) : + (do + let s1 ← obj.Tcb.set_state st t s sched.TS_BLOCKED_ON_SEND + let s2 ← obj.Tcb.set_block_obj st t s1 e + let s3 ← obj.Tcb.set_block_badge st t s2 badge + let i ← if can_grant then ok endpoint.FLAG_GRANT else ok 0#u64 + let i1 ← if can_grant_reply then ok endpoint.FLAG_GRANT_REPLY else ok 0#u64 + let i2 ← lift (i ||| i1) + let i3 ← if do_call then ok endpoint.FLAG_CALL else ok 0#u64 + let f ← lift (i2 ||| i3) + let s4 ← obj.Tcb.set_block_flags st t s3 f + let s5 ← sched.schedule_tcb st s4 t + let s6 ← endpoint.ep_append st s5 e t obj.EP_SEND + ok (s6, a)) ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ + (HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → XC st OS Vc s s' ∧ + XV st H OS Vc s s') ⦄ := + WP.spec_mono (endpoint.send_block.sysS (Vc := Vc) (Vc' := Vc') (Ub := Ub) (Pt := Pt) a t e badge can_grant + can_grant_reply do_call P h hSA B Y hH hst0 hp hc hrun) fun r hh => by + obtain ⟨_, _⟩ := r + exact ⟨hh.1, hh.2.1, hh.2.2.1, fun hks hvr => ⟨(hh.2.2.2 hks hvr).1, (hh.2.2.2 hks hvr).2.1⟩⟩ /-- **The blocking send with the carry**: `send_block.sysG` at the table hypotheses. -/ theorem endpoint.send_block.sysQ {A : Type _} {Rp Nt Vc' Ub Pt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -304,16 +360,16 @@ theorem endpoint.send_block.sysQ {A : Type _} {Rp Nt Vc' Ub Pt : Set U64} {extra let s4 ← obj.Tcb.set_block_flags st t s3 f let s5 ← sched.schedule_tcb st s4 t let s6 ← endpoint.ep_append st s5 e t obj.EP_SEND - ok (s6, a)) ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ XC st OS Vc s s' ⦄ := + ok (s6, a)) ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ XC st OS Vc s s' ∧ + XV st H OS Vc s s' ⦄ := WP.spec_mono (endpoint.send_block.sysG (Vc := Vc) (Vc' := Vc') (Ub := Ub) (Pt := Pt) a t e badge can_grant can_grant_reply do_call P h hSA B Y hH hst0 hp hc hrun) fun r hh => by obtain ⟨_, _⟩ := r exact ⟨hh.1, hh.2.1, hh.2.2.1, hh.2.2.2 hks hvr⟩ -/-- **`send_ipc` on an idle or sending endpoint, the carry under the table hypotheses** (the one body of MdbSendE's -`endpoint.send_ipc.blockL` and `blockQ`). -/ -theorem endpoint.send_ipc.blockG {A : Type _} {ar : machine.Arch A} {Rp Nt Vc' Ub Pt : Set U64} +/-- **The send on an idle or sending endpoint with the carry and the slot fact** (A64-S1A gen 41). -/ +theorem endpoint.send_ipc.blockS {A : Type _} {ar : machine.Arch A} {Rp Nt Vc' Ub Pt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) (blocking do_call : Bool) (badge : U64) (can_grant can_grant_reply can_donate : Bool) (t e : U64) (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (h : BK s) (hSA : ScApart H.scs H.scBits OS) @@ -323,24 +379,43 @@ theorem endpoint.send_ipc.blockG {A : Type _} {ar : machine.Arch A} {Rp Nt Vc' U (hc : blocking = true → CanBlock st H.tcbs Ac s t) (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) : endpoint.send_ipc st ar s a blocking do_call badge can_grant can_grant_reply can_donate t e ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ - (HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → XC st OS Vc s s') ⦄ := by + (HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → XC st OS Vc s s' ∧ + XV st H OS Vc s s' ∧ OSKeep st OS s s') ⦄ := by unfold endpoint.send_ipc step with obj.Ep.state.spec as ⟨v, hv⟩ split · split - · exact endpoint.send_block.sysG a t e badge can_grant can_grant_reply do_call P h hSA B Y hH hst0 hp (hc ‹_›) + · exact endpoint.send_block.sysS a t e badge can_grant can_grant_reply do_call P h hSA B Y hH hst0 hp (hc ‹_›) hrun - · simp only [WP.spec_ok, WP.uncurry'_pair]; exact ⟨B, Y, h, fun _ _ => XC.refl s⟩ + · simp only [WP.spec_ok, WP.uncurry'_pair]; exact ⟨B, Y, h, fun _ _ => ⟨XC.refl s, XV.refl s, OSKeep.rfl' s⟩⟩ · split · split - · exact endpoint.send_block.sysG a t e badge can_grant can_grant_reply do_call P h hSA B Y hH hst0 hp + · exact endpoint.send_block.sysS a t e badge can_grant can_grant_reply do_call P h hSA B Y hH hst0 hp (hc ‹_›) hrun - · simp only [WP.spec_ok, WP.uncurry'_pair]; exact ⟨B, Y, h, fun _ _ => XC.refl s⟩ + · simp only [WP.spec_ok, WP.uncurry'_pair]; exact ⟨B, Y, h, fun _ _ => ⟨XC.refl s, XV.refl s, OSKeep.rfl' s⟩⟩ · exfalso rename_i h1 h2 rw [ep_idle_val] at h1; rw [ep_send_val'] at h2 rcases hst0 with e0 | e0 <;> rw [← hv] at e0 <;> contradiction +/-- **`send_ipc` on an idle or sending endpoint, the carry under the table hypotheses** (the one body of MdbSendE's +`endpoint.send_ipc.blockL` and `blockQ`). -/ +theorem endpoint.send_ipc.blockG {A : Type _} {ar : machine.Arch A} {Rp Nt Vc' Ub Pt : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) (blocking do_call : Bool) (badge : U64) + (can_grant can_grant_reply can_donate : Bool) (t e : U64) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (h : BK s) (hSA : ScApart H.scs H.scBits OS) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hH : H e = some .ep) + (hst0 : L.epState s e = 0#u64 ∨ L.epState s e = 1#u64) + (hp : ∀ k, H e = some k → ∃ x ∈ OS, NamesA (capA st s x) e k) + (hc : blocking = true → CanBlock st H.tcbs Ac s t) (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) : + endpoint.send_ipc st ar s a blocking do_call badge can_grant can_grant_reply can_donate t e + ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ + (HeapKsOff H (L.ksb s) → VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt → XC st OS Vc s s' ∧ + XV st H OS Vc s s') ⦄ := + WP.spec_mono (endpoint.send_ipc.blockS (ar := ar) (Vc := Vc) (Vc' := Vc') (Ub := Ub) (Pt := Pt) a blocking do_call + badge can_grant can_grant_reply can_donate t e P h hSA B Y hH hst0 hp hc hrun) fun r hh => by + obtain ⟨_, _⟩ := r + exact ⟨hh.1, hh.2.1, hh.2.2.1, fun hks hvr => ⟨(hh.2.2.2 hks hvr).1, (hh.2.2.2 hks hvr).2.1⟩⟩ /-- **`send_ipc` on an idle or sending endpoint with the carry**: `blockG` at the table hypotheses. -/ theorem endpoint.send_ipc.blockQ {A : Type _} {ar : machine.Arch A} {Rp Nt Vc' Ub Pt : Set U64} @@ -353,7 +428,8 @@ theorem endpoint.send_ipc.blockQ {A : Type _} {ar : machine.Arch A} {Rp Nt Vc' U (hc : blocking = true → CanBlock st H.tcbs Ac s t) (hrun : L.mem s (stA t) ≠ sched.TS_INACTIVE) (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) : endpoint.send_ipc st ar s a blocking do_call badge can_grant can_grant_reply can_donate t e - ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ XC st OS Vc s s' ⦄ := + ⦃ s' _ => SysL st H Cs OS ia ie s' ∧ SymL st H Cs s' ∧ (BK s') ∧ XC st OS Vc s s' ∧ + XV st H OS Vc s s' ⦄ := WP.spec_mono (endpoint.send_ipc.blockG (ar := ar) (Vc := Vc) (Vc' := Vc') (Ub := Ub) (Pt := Pt) a blocking do_call badge can_grant can_grant_reply can_donate t e P h hSA B Y hH hst0 hp hc hrun) fun r hh => by obtain ⟨_, _⟩ := r @@ -361,8 +437,8 @@ theorem endpoint.send_ipc.blockQ {A : Type _} {ar : machine.Arch A} {Rp Nt Vc' U set_option maxHeartbeats 2000000 in -/-- **The Endpoint arm of `decode_invocation` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem syscall.decode_invocation.ep_armQIAt (hA : P0.ArchTotal ar) {Ub Pt : Set U64} {K : capability.Cap → Prop} +/-- **`ep_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.ep_armSAt (hA : P0.ArchTotal ar) {Ub Pt : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {e b : U64} {sd rv g gr : Bool} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Endpoint e b sd rv g gr) @@ -372,7 +448,7 @@ theorem syscall.decode_invocation.ep_armQIAt (hA : P0.ArchTotal ar) {Ub Pt : Set (hcap : obj.Slot.cap st slot s = ok (.Endpoint e b sd rv g gr)) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Endpoint e b sd rv g gr) blk call don fp buf extra - ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ XferSlots st OS s s' ⦄ := by have hSA : ScApart H.scs H.scBits OS := I.del.sca have hTS : TcbSlotsOS H.tcbs OS := I.ts have hH : H e = some .ep := D.cap.1.1 e b sd rv g gr rfl @@ -387,7 +463,7 @@ theorem syscall.decode_invocation.ep_armQIAt (hA : P0.ArchTotal ar) {Ub Pt : Set · refine WP.spec_bind (WP.spec_and (sched.set_thread_state.restartQ I D P B Y) (sched.set_thread_state.restart_blk (Es := ∅) s _ D.bxi.blk hct (runnable_ok D.run).1 (runnable_ok D.run).2)) ?_ - rintro s1 ⟨⟨R1, Q1, k1⟩, h1, -, e1, kt1⟩ + rintro s1 ⟨⟨R1, Q1, k1, a1⟩, h1, -, e1, kt1⟩ have kb1 : L.ksb s1 = L.ksb s := R1.jv.ksb have hp : ∀ k, H e = some k → ∃ x ∈ OS, NamesA (capA st s1 x) e k := fun k hk => by rw [hH] at hk; cases hk @@ -395,36 +471,57 @@ theorem syscall.decode_invocation.ep_armQIAt (hA : P0.ArchTotal ar) {Ub Pt : Set have hc1 := D.cb.restart hT kt1 e1 have hr1 : L.mem s1 (stA (L.curW s)) ≠ sched.TS_INACTIVE := by rw [e1]; exact fun h => not_runnable_inactive (h ▸ runnable_restart) - have A1 := ArmQIAt.ofDelR R1 Q1 + have A1 := ArmQIAt.ofDelR R1 Q1 a1.toVs have hvr1 : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s1) Pt := by rw [kb1]; exact I.del.vr have hks1 : HeapKsOff H (L.ksb s1) := by rw [kb1]; exact hks have post : ∀ r : S × A, SysL st H Cs OS ia ie r.1 ∧ SymL st H Cs r.1 ∧ (BlkOK st H.tcbs Cs H.omega H H.frame - H.replies H.scs H.ntfns H.scBits Ac r.1) ∧ XC st OS Vc s1 r.1 → (ok ((core.result.Result.Ok () : + H.replies H.scs H.ntfns H.scBits Ac r.1) ∧ XC st OS Vc s1 r.1 ∧ XV st H OS Vc s1 r.1 ∧ + XferSlots st OS s1 r.1 → (ok ((core.result.Result.Ok () : core.result.Result Unit error.Exc), r.1, r.2) : Result _) ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ XferSlots st OS s s' ⦄ := fun r hh => (WP.spec_ok _).2 (by - have A2 := ArmQIAt.ofXC (ia := ia) (ie := ie) ⟨hh.1, hh.2.1⟩ ⟨Ac, hh.2.2.1⟩ hh.2.2.2 - exact ⟨A1.1.trans A2.1, A1.2.trans A2.2⟩) + have A2 := ArmQIAt.ofXC (ia := ia) (ie := ie) ⟨hh.1, hh.2.1⟩ ⟨Ac, hh.2.2.1⟩ hh.2.2.2.1 hh.2.2.2.2.1.1.toVs + have vk := ArmVsK.trans a1 k1 hh.2.2.2.2.1.1 + exact ⟨A1.1.transV A2.1 vk.toVs, A1.2.trans A2.2, vk, + XferSlots.before (fun z hz => k1.capA hz) hh.2.2.2.2.2⟩) by_cases hst1 : L.epState s1 e = 2#u64 - · refine WP.spec_bind (endpoint.send_ipc.recvQ (Vc := Vc) hA a blk call b g gr don (L.curW s) e (P.keepO k1 kb1) - h1 hSA hTS R1.sys R1.sym hH hst1 hp hc1 hr1 (fun _ => by rw [kt1.scf hct]; exact hsc) - (D.rv.restart kt1 (D.rv.zero hct D.nvm)) hks1 hvr1) fun r hh => ?_ + · refine WP.spec_bind (endpoint.send_ipc.recvS (Vc := Vc) (Vc' := Vc) (Ub := Ub) (Pt := Pt) hA a blk call b g gr + don (L.curW s) e (P.keepO k1 kb1) h1 hSA hTS R1.sys R1.sym hH hst1 hp hc1 hr1 + (fun _ => by rw [kt1.scf hct]; exact hsc) (D.rv.restart kt1 (D.rv.zero hct D.nvm))) fun r hh => ?_ obtain ⟨s2, a2⟩ := r simp only [WP.uncurry'_pair] at hh - exact post (s2, a2) hh + have carry := hh.2.2.2 hks1 hvr1 + exact post (s2, a2) ⟨hh.1, hh.2.1, hh.2.2.1, carry.1, carry.2.1, carry.2.2⟩ · obtain ⟨⟨Q2, R2, q2⟩, -⟩ := id h1 have hst0 : L.epState s1 e = 0#u64 ∨ L.epState s1 e = 1#u64 := by rcases ep_state3 q2 hH with e0 | e0 | e0 · exact Or.inl e0 · exact Or.inr e0 · exact absurd e0 hst1 - refine WP.spec_bind (endpoint.send_ipc.blockQ (Vc := Vc) a blk call b g gr don (L.curW s) e (P.keepO k1 kb1) h1 - hSA R1.sys R1.sym hH hst0 hp (fun _ => hc1) hr1 hks1 hvr1) fun r hh => ?_ + refine WP.spec_bind (endpoint.send_ipc.blockS (Vc := Vc) (Vc' := Vc) (Ub := Ub) (Pt := Pt) a blk call b g gr don + (L.curW s) e (P.keepO k1 kb1) h1 hSA R1.sys R1.sym hH hst0 hp (fun _ => hc1) hr1) fun r hh => ?_ obtain ⟨s2, a2⟩ := r simp only [WP.uncurry'_pair] at hh - exact post (s2, a2) hh - · exact (WP.spec_ok _).2 (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s from - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) + have carry := hh.2.2.2 hks1 hvr1 + exact post (s2, a2) ⟨hh.1, hh.2.1, hh.2.2.1, carry.1, carry.2.1, Or.inl fun z hz => carry.2.2.capA hz⟩ + · exact (WP.spec_ok _).2 (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ + XferSlots st OS s s from (fun h => ⟨h.1, h.2, ArmVsK.refl s, XferSlots.refl s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s))) + +set_option maxHeartbeats 2000000 in +/-- **The Endpoint arm of `decode_invocation` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem syscall.decode_invocation.ep_armQIAt (hA : P0.ArchTotal ar) {Ub Pt : Set U64} {K : capability.Cap → Prop} + {Ty : S → Prop} {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {e b : U64} + {sd rv g gr : Bool} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Endpoint e b sd rv g gr) + extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (hcap : obj.Slot.cap st slot s = ok (.Endpoint e b sd rv g gr)) (a : A) (lbl len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Endpoint e b sd rv g gr) 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' ⦄ := + WP.spec_mono (syscall.decode_invocation.ep_armSAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbSetTcbQ.lean b/proofs/Fl4ProofsA64/P1/MdbSetTcbQ.lean index 8b66aae82..e39aaf48d 100644 --- a/proofs/Fl4ProofsA64/P1/MdbSetTcbQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbSetTcbQ.lean @@ -23,6 +23,9 @@ item 1) on MdbRunF's `RunB` frame, reusing the deletion line's exact `unbind` wa `vw_wr_lnk`; the run VCPU in `Vc` by `VcTy.run`) — each a `DMB 0 0` step by `DMB.ofVW`; `VcTy … U0` is carried through the second unbind and the stall (`DS` / `keepZ`) for it. +(A64-S1A gen 40, Architect ruling for gen 40, R3) `vcpu.decode_set_tcb.armQ` and `setTcb_armQIAt` also post `ArmVsK` +(last conjunct; MdbRunQ's `ofRunB0`). + Named premises: none. Case facts: none new (`DelIn`, `HeapKsOff` as the other arms; `vc ∈ Vc` by `DelIn.vcc` at the invoked slot). QueueDecVcpuB's [P] `VcpuObjA` and QueueUnbindB's [P] `VcPl` are not read. -/ @@ -42,7 +45,7 @@ namespace W7 namespace R namespace ST -variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} +variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} {sd : S} variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} local notation "BK" s => BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s @@ -51,8 +54,8 @@ local notation "C0" s0:max s:max => Cur0 st H.tcbs Cs H.omega H H.frame H.replie /-! ## The frame -/ /-- **A `VW` word with the run frame inside `FrBw` is a `RunB` word** (module docstring). -/ -theorem vw_runB {s0 : S} {Cw : U64 → Prop} {b : U64} (hU : ∀ b ∈ U, FrBw H OS b) - (h : VW st H.tcbs Cs Vc U (L.ksb s0) Cw b) : RunB st H Cs Vc OS s0 b := by +theorem vw_runB {s0 : S} {Cw : U64 → Prop} {b : U64} (hU : ∀ b ∈ U, FrBw H OS b ∧ FrCw st OS sd b) + (h : VW st H.tcbs Cs Vc U (L.ksb s0) Cw b) : RunB st H Cs Vc OS sd s0 b := by rcases h with hb | hv | ⟨y, hy, ⟨K, k1, k2, -, e⟩ | e | e | ⟨-, e⟩⟩ | ⟨c, hc, o, ho, h88, s1, e1, e⟩ · exact Or.inl (Or.inr (hU b hb)) · exact Or.inl (Or.inl (Or.inl (Or.inr (Or.inr hv)))) @@ -67,11 +70,11 @@ theorem vw_runB {s0 : S} {Cw : U64 → Prop} {b : U64} (hU : ∀ b ∈ U, FrBw H /-- **A `RunB` step writing only `STATE` words of live-and-not-reply-blocked threads is a `DMB 0 0` step** (module docstring). -/ theorem DMB.ofCw {Cw : U64 → Prop} {s s' : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) - (VR : ValidReplies st H s) (f : WritesIn st s s' (RunB st H Cs Vc OS s)) + (VR : ValidReplies st H s) (f : WritesIn st s s' (RunB st H Cs Vc OS sd s)) (g : LvF st H.tcbs Cs H.replies H.scs H.ntfns (LvX.cw Cw) s s') (he : ∀ e, (H e = some .ep ∨ H e = some .ntfn) → L.mem s' (epTSA e) = L.mem s (epTSA e)) (hc : ∀ y, Cw y → L.mem s (stA y) ≠ sched.TS_BLOCKED_ON_REPLY ∧ L.mem s (stA y) ≠ sched.TS_INACTIVE) : - DMB st H Cs Vc OS 0#u64 0#u64 s s' := by + DMB st H Cs Vc OS sd 0#u64 0#u64 s s' := by have hX := h.2.2.1 have hz : DbgTz st H.tcbs Cs s := ⟨hX.2.2.tm.dn, hX.2.2.tm.dp, hX.2.2.tm.dh⟩ have hI : L.idleW s ∈ H.tcbs := h.1.choose_spec.choose_spec.idleT @@ -88,10 +91,10 @@ theorem DMB.ofCw {Cw : U64 → Prop} {s s' : S} (h : BK s) (h0 : H 0#u64 = none) /-- **A `VW` step with the run frame inside `FrBw`** (module docstring). -/ theorem DMB.ofVW {Cw : U64 → Prop} {s s' : S} (h : BK s) (h0 : H 0#u64 = none) (Y : SymL st H Cs s) (VR : ValidReplies st H s) (hU : ∀ b ∈ U, UsrW st H.tcbs Cs H H.frame H.scs H.scBits s b) - (hUF : ∀ b ∈ U, FrBw H OS b) (hW : ∀ b, VcW Vc b → b ∈ H.omega ∧ b ∉ H.frame) + (hUF : ∀ b ∈ U, FrBw H OS b ∧ FrCw st OS sd b) (hW : ∀ b, VcW Vc b → b ∈ H.omega ∧ b ∉ H.frame) (w : WritesIn st s s' (VW st H.tcbs Cs Vc U (L.ksb s) Cw)) (hi : L.idleW s' = L.idleW s) (hc : ∀ y, Cw y → L.mem s (stA y) ≠ sched.TS_BLOCKED_ON_REPLY ∧ L.mem s (stA y) ≠ sched.TS_INACTIVE) : - DMB st H Cs Vc OS 0#u64 0#u64 s s' := by + DMB st H Cs Vc OS sd 0#u64 0#u64 s s' := by have g := LvF.ofVW (LvC.of_blk h) (fun b hb => ⟨(hU b hb).out, (hU b hb).sg⟩) hW w hi refine DMB.ofCw h h0 Y VR (w.mono fun _ hb => vw_runB hUF hb) g (ep_kept h w fun b _ hb => ?_) hc rcases hb with hb | hb | ⟨y, hy, ⟨K, -, k2, -, rfl⟩ | rfl | rfl | ⟨-, rfl⟩⟩ | ⟨c, hc, o, ho, -, s1, e1, rfl⟩ @@ -114,14 +117,14 @@ local macro "errQ" : tactic => `(tactic| first first | exact E0 | exact (WP.spec_ok _).2 E0)) set_option maxHeartbeats 4000000 in -/-- **`ARMVCPUSetTCB` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem vcpu.decode_set_tcb.armQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U64} +/-- **`decode_set_tcb.armQ` exporting the slot fact** (A64-S1A gen 41). -/ +theorem vcpu.decode_set_tcb.armS (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Vcpu vc) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Vcpu vc)) (a : A) : vcpu.decode_set_tcb st ar s a vc extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by have hb0 : BK s := D.bxi.blk obtain ⟨Q0, R0, q0⟩ := hb0.1 have hT : TcbPlaced H.tcbs := q0.tcbs @@ -130,37 +133,38 @@ theorem vcpu.decode_set_tcb.armQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot have hvc : vc ∈ Vc := I.vcc slot P.src vc (by rw [capA_eq] at hcap; exact okinj hcap) have hW : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 have hWv : ∀ b, VcW Vc b → b ∈ H.omega ∧ b ∉ H.frame := fun b hb => (I.vty.w hb).2 - have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, hb0⟩ id (PoolR.refl s) + have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ OSKeep st OS s s := + (fun h => ⟨h.1, h.2, ArmVsK.refl s, OSKeep.rfl' s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, hb0⟩ id (PoolR.refl s) (ArmVs.refl s)) -- the run frame and the VCPU typing on it - let U0 : Set U64 := {b | b ∈ Ub ∧ FrBw H OS b} + let U0 : Set U64 := {b | b ∈ Ub ∧ FrBw H OS b ∧ FrCw st OS s b} have hUs : ∀ b ∈ U0, UsrW st H.tcbs Cs H H.frame H.scs H.scBits s b := fun b hb => I.vty.usr b hb.1 - have hUF : ∀ b ∈ U0, FrBw H OS b := fun b hb => hb.2 + have hUF : ∀ b ∈ U0, FrBw H OS b ∧ FrCw st OS s b := fun b hb => hb.2 have hV0 : VcOK H.tcbs H.scs H.scBits OS Vc U0 := ⟨I.del.vc.os, I.del.vc.sc, fun b hb => I.del.vc.ubos b hb.1, fun b hb => I.del.vc.ubv b hb.1, I.del.vc.bcov, I.del.vc.fit, I.del.vc.disj⟩ have hv0 : VcTy st H.tcbs Cs H.omega H H.frame H.scs H.scBits Vc U0 s := ⟨I.vty.obj, I.vty.bnd, I.vty.run, hUs, fun t ht _ => runBuf_of I B (I.del.vc.bcov t ht) rfl, I.vty.ks⟩ -- one `VW` step - have stp : ∀ {x x' : S} {Cw : U64 → Prop}, (C0 s x) → DMB st H Cs Vc OS 0#u64 0#u64 s x → + have stp : ∀ {x x' : S} {Cw : U64 → Prop}, (C0 s x) → DMB st H Cs Vc OS s 0#u64 0#u64 s x → WritesIn st x x' (VW st H.tcbs Cs Vc U0 (L.ksb x) Cw) → L.idleW x' = L.idleW x → (∀ y, Cw y → L.mem x (stA y) ≠ sched.TS_BLOCKED_ON_REPLY ∧ L.mem x (stA y) ≠ sched.TS_INACTIVE) → - DMB st H Cs Vc OS 0#u64 0#u64 s x' := fun {x x' Cw} c d w hi hc => by + DMB st H Cs Vc OS s 0#u64 0#u64 s x' := fun {x x' Cw} c d w hi hc => by obtain ⟨Ac', hb⟩ := c.bxi exact d.trans (DMB.ofVW hb.blk B.ly.h0 d.sym d.vr (fun b hb' => (hUs b hb').ksb d.w.1) hUF hWv w hi hc) have vm : ∀ {x : S} {y : U64}, L.mem x (stA y) = sched.TS_RUNNING_VM → L.mem x (stA y) ≠ sched.TS_BLOCKED_ON_REPLY ∧ L.mem x (stA y) ≠ sched.TS_INACTIVE := fun e => by rw [e]; exact ⟨runnable_ne_reply (Or.inr (Or.inr rfl)), runnable_ne_inactive (Or.inr (Or.inr rfl))⟩ - have d0 : DMB st H Cs Vc OS 0#u64 0#u64 s s := + have d0 : DMB st H Cs Vc OS s 0#u64 0#u64 s s := ⟨WritesIn.refl _ _, fun _ _ _ h => h, rfl, rfl, B.vr, Y⟩ -- the close - have fin : ∀ {x : S}, (C0 s x) → DMB st H Cs Vc OS 0#u64 0#u64 s x → - ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x := fun {x} c d => by + have fin : ∀ {x : S}, (C0 s x) → DMB st H Cs Vc OS s 0#u64 0#u64 s x → + ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x ∧ ArmVsK st H OS Vc s x ∧ + OSKeep st OS s x := fun {x} c d => by have hp0 : ∀ k, H 0#u64 = some k → ∃ y ∈ OS, NamesA (capA st s y) 0#u64 k := fun k hk => by rw [B.ly.h0] at hk; cases hk have hS' := SysL.dfMDB I.del.heap I.del.os I.del.vc (fun b hb => (I.vty.w hb).2.1) hb0 I.del.sca hp0 hp0 B d obtain ⟨Ac', hb'⟩ := c.bxi have A' := ArmQIAt.ofRunB0 I B hks P.core0 hb0 d.w hS' hb'.blk - exact ⟨A'.1, A'.2.toDel⟩ + exact ⟨A'.1, A'.2.1.toDel, A'.2.2, RunB.osk I.del.os I.del.sca I.del.vc hb0 d.w⟩ unfold vcpu.decode_set_tcb vcpu.set_bound rw [eq_of_spec_fd P0.Consts.layout.tcb.VCPU.spec, eq_of_spec_fd P0.Consts.layout.tcb.RUN_VCPU.spec] have hl0 : (0#usize).val < extra.val.length := by rw [extra.property]; simp @@ -196,7 +200,7 @@ theorem vcpu.decode_set_tcb.armQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot have d2 := stp c1 d1 w2 F2.idle fun y e => vm e.2 -- `unbind old_v` step with vcpu.bound.spec as ⟨ov, eov⟩ - refine WP.spec_bind (Pₘ := fun r : S × A => (C0 s r.1) ∧ DMB st H Cs Vc OS 0#u64 0#u64 s r.1 ∧ + refine WP.spec_bind (Pₘ := fun r : S × A => (C0 s r.1) ∧ DMB st H Cs Vc OS s 0#u64 0#u64 s r.1 ∧ VcTy st H.tcbs Cs H.omega H H.frame H.scs H.scBits Vc U0 r.1) ?_ ?_ · split · rename_i hov @@ -220,7 +224,7 @@ theorem vcpu.decode_set_tcb.armQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot have hv4 := hv3.keepZ D4.2 -- #134: the target's run in flight ends first (`complete_run` in `TS_RUNNING_VM`, else `cancel_run`) simp only [lift, bind_ok, L.read_eq] - refine WP.spec_bind (Pₘ := fun r : S × A => (C0 s r.1) ∧ DMB st H Cs Vc OS 0#u64 0#u64 s r.1) ?_ ?_ + refine WP.spec_bind (Pₘ := fun r : S × A => (C0 s r.1) ∧ DMB st H Cs Vc OS s 0#u64 0#u64 s r.1) ?_ ?_ · split · rename_i hne have hv : L.mem s4 (runVcpuA ptr) ≠ 0#u64 := by simpa [runVcpuA] using hne @@ -270,8 +274,21 @@ theorem vcpu.decode_set_tcb.armQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot exact (WP.spec_ok _).2 (fin F6.cur d6) · exact (WP.spec_ok _).2 (fin F6.cur d6) -/-- **The `Vcpu` arm of `decode_invocation` at SetTCB to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem syscall.decode_invocation.setTcb_armQIAt (hA : P0.ArchTotal ar) {s : S} +set_option maxHeartbeats 4000000 in +/-- **`ARMVCPUSetTCB` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem vcpu.decode_set_tcb.armQ (hA : P0.ArchTotal ar) {s : S} {vc : U64} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Vcpu vc) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Vcpu vc)) (a : A) : + vcpu.decode_set_tcb st ar s a vc extra ⦃ r s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := + WP.spec_mono (vcpu.decode_set_tcb.armS hA I D P B Y hks hcap a) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨h.1, h.2.1, h.2.2.1⟩ + +/-- **`setTcb_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.setTcb_armSAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) 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) @@ -279,15 +296,28 @@ theorem syscall.decode_invocation.setTcb_armQIAt (hA : P0.ArchTotal ar) {s : S} (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPUSetTCB) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ unfold vcpu.decode refine spec_ite (fun _ => ?_) fun hc => absurd hl hc - exact WP.spec_mono (vcpu.decode_set_tcb.armQ hA I D P B Y hks hcap a) fun r d => by + exact WP.spec_mono (vcpu.decode_set_tcb.armS hA I D P B Y hks hcap a) fun r d => by obtain ⟨_, s', a'⟩ := r exact d +/-- **The `Vcpu` arm of `decode_invocation` at SetTCB to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem syscall.decode_invocation.setTcb_armQIAt (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Vcpu vc)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPUSetTCB) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) 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' ⦄ := + WP.spec_mono (syscall.decode_invocation.setTcb_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ + end ST end R end W7 diff --git a/proofs/Fl4ProofsA64/P1/MdbSigQ.lean b/proofs/Fl4ProofsA64/P1/MdbSigQ.lean index 54d339381..fec789979 100644 --- a/proofs/Fl4ProofsA64/P1/MdbSigQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbSigQ.lean @@ -12,6 +12,9 @@ P1 (aarch64, gen 150): **Notification send to `ArmQIAt ∧ TabKeepOrZero`** (Arc from the post-restart state (MdbSspTail's `SspW.ofD`, `ArmQIAt.ofSspW`), composed by `ArmQIAt.transZ`. Without the send right the error leaf (`ArmQIAt.ofPR` at the decode's state). +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ntfn_armQIAt` also posts `ArmVsK` (last conjunct: the restart's and +the signal's, `ArmVsK.trans`). + Named premises: none new (QueueSignal's [J] `RunVcpuInv`, taken as `DecPre.rv`). Case facts: none new; `hks : HeapKsOff H (L.ksb s)` (S1aPlace, ruled gen 136), as the dispatcher's other arms. -/ @@ -36,8 +39,8 @@ variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} set_option maxHeartbeats 2000000 in -/-- **The Notification arm of `decode_invocation` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem syscall.decode_invocation.ntfn_armQIAt (hA : P0.ArchTotal ar) {s : S} +/-- **`ntfn_armQIAt` exporting the slot fact**: every `OS` word kept (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.ntfn_armSAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {n b : U64} {sd rv : Bool} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Notification n b sd rv) extra) @@ -45,7 +48,7 @@ theorem syscall.decode_invocation.ntfn_armQIAt (hA : P0.ArchTotal ar) {s : S} (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Notification n b sd rv)) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Notification n b sd rv) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by obtain ⟨hn, hH⟩ := D.cap.1.2.1 n b sd rv rfl have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT unfold syscall.decode_invocation @@ -56,23 +59,38 @@ theorem syscall.decode_invocation.ntfn_armQIAt (hA : P0.ArchTotal ar) {s : S} · refine WP.spec_bind (WP.spec_and (sched.set_thread_state.restartQ I D P B Y) (sched.set_thread_state.restart_blk (Es := ∅) s _ D.bxi.blk hct (runnable_ok D.run).1 (runnable_ok D.run).2)) ?_ - rintro s1 ⟨⟨R1, Q1, k1⟩, h1, -, -, kt1⟩ + rintro s1 ⟨⟨R1, Q1, k1, K1⟩, h1, -, -, kt1⟩ have hRV1 : RunVcpuInv st H.tcbs s1 := D.rv.restart kt1 (D.rv.zero hct D.nvm) have kb1 : L.ksb s1 = L.ksb s := R1.jv.ksb have hp : ∀ k, H n = some k → ∃ x ∈ OS, NamesA (capA st s1 x) n k := fun k hk => by rw [hH] at hk; cases hk exact ⟨slot, P.src, by rw [k1.capA P.src, okinj ((capA_eq s slot).symm.trans hcap)]; exact names_ntfn⟩ - have A1 := ArmQIAt.ofDelR R1 Q1 + have A1 := ArmQIAt.ofDelR R1 Q1 K1.toVs refine WP.spec_bind (WP.spec_and (notification.send_signal.dmd hA a n b h1 hn hH B.ly.h0 R1.sym R1.sys.vr fun y hy hb => hRV1.zero hy (blocked_ne_vm hb)) (notification.send_signal.tinv0 hA s1 a n b h1 hn hH hRV1)) ?_ rintro ⟨s2, a2⟩ ⟨d, hb2⟩ simp only [WP.uncurry'_pair] at d hb2 have hS2 := SysL.dfMD (P.keepO k1 kb1) h1.bxi I.del.sca hp R1.sys d - exact (WP.spec_ok _).2 (ArmQIAt.transZ A1 (ArmQIAt.ofSspW I R1 hks P.core0 h1 - (SspW.ofD d.w) hS2 hb2)) - · exact (WP.spec_ok _).2 (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s from - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) + have vk := ArmVsK.ofSspW I R1 hks P.core0 h1 (SspW.ofD d.w) + exact (WP.spec_ok _).2 ((fun h => ⟨h.1, h.2, ArmVsK.trans K1 k1 vk.1, OSKeep.trans' k1 vk.2⟩) (ArmQIAt.transZ A1 + ⟨K1.toZ, fun _ hf => FrUb.keepO hf k1⟩ (ArmQIAt.ofSspW I R1 hks P.core0 h1 (SspW.ofD d.w) hS2 hb2) vk)) + · exact (WP.spec_ok _).2 (show ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s ∧ + OSKeep st OS s s from (fun h => ⟨h.1, h.2, ArmVsK.refl s, OSKeep.rfl' s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s))) + +set_option maxHeartbeats 2000000 in +/-- **The Notification arm of `decode_invocation` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem syscall.decode_invocation.ntfn_armQIAt (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {n b : U64} {sd rv : Bool} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Notification n b sd rv) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Notification n b sd rv)) + (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Notification n b sd rv) 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' ⦄ := + WP.spec_mono (syscall.decode_invocation.ntfn_armSAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbSspArm.lean b/proofs/Fl4ProofsA64/P1/MdbSspArm.lean index edf76fb3d..4253e55fe 100644 --- a/proofs/Fl4ProofsA64/P1/MdbSspArm.lean +++ b/proofs/Fl4ProofsA64/P1/MdbSspArm.lean @@ -90,18 +90,6 @@ theorem not_noe_thread {t : U64} : ¬ NullOrEp H (.Thread t) := by theorem not_noe_sc {p b : U64} : ¬ NullOrEp H (.SchedContext p b) := by rintro (h | ⟨_, _, _, _, _, _, h, -⟩) <;> cases h -set_option hygiene false in -/-- An error leaf at the stalled state (MdbTmoArmQ's `qleafT`). -/ -local macro "qleafS" : tactic => `(tactic| first - | exact (WP.spec_ok _).2 (ArmQIAt.ofStall I h1 d1 ds1 vk1 - (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1)) - | (simp only [error.invalid_cap, error.truncated, error.illegal, error.range, bind_ok, - core.result.Result.Insts.CoreOpsTry.branch, - core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, - bind_tc_ok] - exact (WP.spec_ok _).2 (ArmQIAt.ofStall I h1 d1 ds1 vk1 - (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1)))) - local macro "lbl_neS" : tactic => `(tactic| exact lbl_ne_of_val (by simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, fl4_abi.label.TCBConfigure, fl4_abi.label.TCBSetPriority, fl4_abi.label.TCBSetMCPriority, @@ -112,19 +100,46 @@ local macro "lbl_neS" : tactic => `(tactic| exact lbl_ne_of_val (by fl4_abi.label.TCBUnsetBreakpoint, fl4_abi.label.TCBConfigureSingleStepping, fl4_abi.label.TCBSetEPTRoot, fl4_abi.label.TCBSetFlags, fl4_abi.label.TCBSetTimer, fl4_abi.label.TCBReadFPU, core.num.U64.MAX, U64.rMax])) +set_option hygiene false in +/-- An error leaf at the stalled state, with the predicate (MdbTmoArmQ's `qleafT`). -/ +local macro "qleafP" : tactic => `(tactic| ( + have unchanged := ArmQIAt.ofStall I h1 d1 ds1 vk1 + (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) + (ArmVsK.ofDFI I D P B d1) + have typing := I.tyk s s1 I.ty vk1 + first + | exact (WP.spec_ok _).2 ⟨unchanged.1, unchanged.2, typing, p1⟩ + | (simp only [error.invalid_cap, error.truncated, error.illegal, error.range, bind_ok, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 ⟨unchanged.1, unchanged.2, typing, p1⟩))) + set_option maxHeartbeats 4000000 in -/-- **SetSchedParams after the stall to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} +/-- The SetSchedParams walk with any state predicate `Φ` kept by the slot-and-table-keeping steps (`keep`) and by +the fault-handler install (`install`). -/ +theorem tcb.decode_set_sched_params.armQIPAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) (Hy : ArmDecHyps st H Pt n s (.Thread t)) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) - (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) + {Φ : S → Prop} (hΦ : Φ s) + (keepΦ : ∀ q r : S, Φ q → L.ksb q = L.ksb s → L.ksb r = L.ksb s → VsKeep st (L.ksb s) Pt q r → + OSKeep st OS q r → Φ r) + (install : ∀ (q : S) (a : A) (nc : capability.Cap) (src : U64), Φ q → DelR st H Cs OS Vc Ub Ac Ty ia ie s q → + PoolR st OS s q → (ArmVsZ st H OS Vc s q ∧ FrC st OS s q) → + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac q → + NullOrEp H (capA st q (slotIdx t layout.tcb.SLOT_FAULT_HANDLER)) → + (nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) → faults.valid_fault_handler nc = ok true → src ∈ OS → + capA st q src = nc → + tcb.install_tcb_cap st ar q a t slot layout.tcb.SLOT_FAULT_HANDLER nc src ⦃ r => Φ r.2.1 ⦄) : tcb.decode_set_sched_params st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => - ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ Ty r.2.1 ∧ Φ r.2.1 ⦄ := by + have p1 : Φ s1 := keepΦ s s1 hΦ rfl d1.w.1 vk1 ds1.1 have hS : P0.StoreTotal st := L.total have ht : t ∈ H.tcbs := D.cap.2.1 t rfl have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT @@ -142,21 +157,21 @@ theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64 rintro r hx rcases r with x0 | e swap - · qleafS + · qleafP simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] obtain ⟨hxm0, hx00⟩ := hx x0 rfl refine WP.spec_bind (tcb.extra_with_length.memi _ 1#usize _ (by simp)) ?_ rintro r hx rcases r with x1 | e swap - · qleafS + · qleafP simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] obtain ⟨hxm1, hx01⟩ := hx x1 rfl refine WP.spec_bind (tcb.extra_with_length.memi _ 2#usize _ (by simp)) ?_ rintro r hx rcases r with x2 | e swap - · qleafS + · qleafP simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] obtain ⟨hxm2, hx02⟩ := hx x2 rfl have hO1 : x1 ∈ OS := P.ext x1 hxm1 hx01 @@ -167,20 +182,20 @@ theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64 rintro r ⟨-, hT2⟩ rcases r with auth | e swap - · qleafS + · qleafP simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] have hauth := hT2 auth rfl refine WP.spec_bind (tcb.check_prio.le s1 mcp auth) ?_ rintro r ⟨-, -⟩ rcases r with u | e swap - · qleafS + · qleafP simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] refine WP.spec_bind (tcb.check_prio.le s1 prio auth) ?_ rintro r ⟨-, hle⟩ rcases r with u | e swap - · qleafS + · qleafP simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] have hv : prio.val < 256 := lt_of_le_of_lt (hle rfl) (by rw [h1.fld auth hauth 3440#u64 (by simp) (by simp)]; exact Hy.mcp auth hauth) @@ -189,7 +204,7 @@ theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64 rintro r ⟨hsp, hspc⟩ rcases r with v | e swap - · qleafS + · qleafP simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] have hsp := hsp v rfl have hspc := hspc v rfl @@ -205,14 +220,14 @@ theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64 (do let s2 ← tcb.restart_caller st s1 tcb.thread_control_sched st ar s2 a1 t slot (capA st s1 x2, x2) mcp prio v flags) ⦃ r => - ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ Ty r.2.1 ∧ Φ r.2.1 ⦄ := by intro flags hfl hfs hvf have hnc : capA st s1 x2 ≠ .Null → TcbK (capA st s1 x2) ∧ CapRt.EncWf (capA st s1 x2) := fun hn => ⟨vfh_tk hvf hn, CapRt.decodeF_encWf _ _⟩ refine WP.spec_bind (WP.spec_and (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) (h1.restart D)) (WP.spec_and (tcb.restart_caller.sts (q1.nodes _ q1.cur) (q1.tcbs _ hct1)) (tcb.restart_caller.blk (Es := EH H) s1 hb1 (est ▸ hr.1) (est ▸ hr.2)))) ?_ - rintro s2 ⟨⟨⟨⟨RS2, R2⟩, Q2⟩, -, hna2, ec2, k⟩, w2, -, -, est2, -⟩ + rintro s2 ⟨⟨⟨⟨RS2, R2⟩, Q2, Z2⟩, -, hna2, ec2, k⟩, w2, -, -, est2, -⟩ have k2 : OSKeep st OS s s2 := (ds1.trans (DS.sts I.del.os I.del.vc q1 hW hct1 w2)).1 have hx3 := R2.slot I ht hi have hfh2 : NullOrEp H (capA st s2 (slotIdx t layout.tcb.SLOT_FAULT_HANDLER)) := by @@ -240,20 +255,25 @@ theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64 · rwa [stA_eq, k.fld t ht _ (by simp) (by simp) (by simp) (by simp) (fun e' => absurd e' e), ← stA_eq] at hb have hunb2 : (flags &&& tcb.SCHED_UPDATE_SC) ≠ 0#u64 → v = 0#u64 → L.actionW s2 ≠ t ∧ L.idleW s2 ≠ t := fun _ _ => ⟨hna2 t ht, fun e => hti2 e.symm⟩ + have p2 : Φ s2 := keepΦ s s2 hΦ rfl R2.jv.ksb (vk1.trans (vsk_sts I.del.vr q1 hct1 w2)) k2 + have hx2 : capA st s2 x2 = capA st s1 x2 := (k2.capA hO2).trans (k1.capA hO2).symm unfold tcb.thread_control_sched simp only [lift, Aeneas.Std.bind_ok] split - · refine WP.spec_bind (tcb.install_tcb_cap.delRC I hKZ hPI R2 Q2 RS2.blk ht P.src (fun _ => hO2) hnc hfh2) ?_ - rintro ⟨r, s3, a3⟩ ⟨⟨R3, Q3⟩, h3, F3, ha3, c3⟩ - try simp only [uncurry_apply_pair] at R3 Q3 h3 F3 ha3 c3 ⊢ - have Z3 := ArmQIAt.ofDelR R3 Q3 + · refine WP.spec_bind (WP.spec_and + (tcb.install_tcb_cap.delRC I hKZ hPI R2 Q2 Z2 RS2.blk ht P.src (fun _ => hO2) hnc hfh2) + (install s2 a1 _ x2 p2 R2 Q2 Z2 RS2.blk hfh2 hnc hvf hO2 hx2)) ?_ + rintro ⟨r, s3, a3⟩ ⟨⟨⟨R3, Q3, V3⟩, h3, F3, ha3, c3⟩, p3⟩ + try simp only [uncurry_apply_pair] at p3 + try simp only [uncurry_apply_pair] at R3 Q3 V3 h3 F3 ha3 c3 ⊢ + have Z3 := ArmQIAt.ofDelR R3 Q3 V3.1.toVs cases r with | Err e => simp only [core.result.Result.Insts.CoreOpsTry.branch, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, Aeneas.Std.bind_ok] exact WP.spec_bind (Pₘ := fun _ => True) (WP.spec_bind (Pₘ := fun _ => True) ((WP.spec_ok _).2 trivial) - fun _ _ => (WP.spec_ok _).2 trivial) fun _ _ => (WP.spec_ok _).2 Z3 + fun _ _ => (WP.spec_ok _).2 trivial) fun _ _ => (WP.spec_ok _).2 ⟨Z3.1, Z3.2, R3.ty, p3⟩ | Ok u => simp only [core.result.Result.Insts.CoreOpsTry.branch, Aeneas.Std.bind_ok] have hT3 := h3.1.choose_spec.choose_spec.tcbs @@ -312,7 +332,12 @@ theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64 have TQ := tcs_tailQ (Vc := Vc) a3 t mcp prio v flags I.del.heap I.del.os I.del.sca h3 R3.sys R3.sym ht hnt3 hna3 hti3 hp3 hbnd simp only [lift, Aeneas.Std.bind_ok] at TQ - exact WP.spec_mono TQ fun r hr => ArmQIAt.transZ Z3 (ArmQIAt.ofSspW I R3 hks P.core0 h3 hr.2.2 hr.2.1 hr.1) + refine WP.spec_mono TQ fun r hr => ?_ + have keep := ArmVsK.ofSspW I R3 hks P.core0 h3 hr.2.2 + have out := ArmQIAt.transZ Z3 V3 (ArmQIAt.ofSspW I R3 hks P.core0 h3 hr.2.2 hr.2.1 hr.1) keep + have vk := keep.1.vsKeep (R3.jv.ksb.symm ▸ I.del.vr) R3.fu + exact ⟨out.1, out.2, I.tyk s3 r.2.1 R3.ty (R3.jv.ksb ▸ vk), + keepΦ s3 r.2.1 p3 R3.jv.ksb (hr.2.2.1.trans R3.jv.ksb) (R3.jv.ksb ▸ vk) keep.2⟩ · rename_i hn exfalso; simp at hn hfl; exact hfl hn split @@ -321,7 +346,7 @@ theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64 refine WP.spec_bind (spec_eqv (P0.faults.valid_fault_handler.p0 (capA st s1 x2))) fun b hb => ?_ split swap - · qleafS + · qleafP rename_i hbt exact WP.spec_mono (run _ ssp_flags.2.1 (fun _ e => by rw [ei1, e] at hne; simp at hne) (hbt ▸ hb.1)) fun r hr => by obtain ⟨r1, r2, r3⟩ := r; exact hr @@ -329,16 +354,50 @@ theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64 refine WP.spec_bind (spec_eqv (P0.faults.valid_fault_handler.p0 (capA st s1 x2))) fun b hb => ?_ split swap - · qleafS + · qleafP rename_i hbt exact WP.spec_mono (run _ ssp_flags.1 (fun hf => absurd ssp_flags.2.2.1 hf) (hbt ▸ hb.1)) fun r hr => by obtain ⟨r1, r2, r3⟩ := r; exact hr +set_option maxHeartbeats 4000000 in +/-- Shared SetSchedParams walk with its deletion typing retained for the S1A sibling post. -/ +theorem tcb.decode_set_sched_params.armQITyAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (Hy : ArmDecHyps st H Pt n s (.Thread t)) + (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + tcb.decode_set_sched_params st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ Ty r.2.1 ⦄ := + WP.spec_mono (tcb.decode_set_sched_params.armQIPAt I hKZ hPI D P B Y hks hcap Hy h1 d1 ds1 vk1 (Φ := fun _ => True) + trivial (fun _ _ _ _ _ _ _ => trivial) + (fun q a nc src _ R Q Z blk hfh hnc _ hsrc _ => WP.spec_mono + (tcb.install_tcb_cap.delRC I hKZ hPI R Q Z blk (D.cap.2.1 t rfl) P.src (fun _ => hsrc) hnc hfh) + fun _ _ => trivial)) fun _ d => ⟨d.1, d.2.1, d.2.2.1⟩ + +/-- **SetSchedParams after the stall to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem tcb.decode_set_sched_params.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (Hy : ArmDecHyps st H Pt n s (.Thread t)) + (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + tcb.decode_set_sched_params st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ⦄ := + WP.spec_mono (tcb.decode_set_sched_params.armQITyAt I hKZ hPI D P B Y hks hcap Hy h1 d1 ds1 vk1) + fun _ d => ⟨d.1, d.2.1⟩ + set_option maxHeartbeats 2000000 in /-- **TCB SetSchedParams to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ theorem tcb.decode.sspQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) @@ -358,7 +417,7 @@ theorem tcb.decode.sspQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf /-- **The Thread arm of `decode_invocation` at SetSchedParams to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ theorem syscall.decode_invocation.ssp_armQIAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) @@ -367,7 +426,7 @@ theorem syscall.decode_invocation.ssp_armQIAt (hA : P0.ArchTotal ar) {s : S} syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := syscall.decode_invocation.tcbG (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) a len blk call don fp buf + (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) a len blk call don fp buf fun _ _ e => tcb.decode.sspQAt hA I hKZ hPI D P B Y hks hcap Hy (e.trans hl) end ST diff --git a/proofs/Fl4ProofsA64/P1/MdbSspIns.lean b/proofs/Fl4ProofsA64/P1/MdbSspIns.lean index 14fe84e44..d62899f00 100644 --- a/proofs/Fl4ProofsA64/P1/MdbSspIns.lean +++ b/proofs/Fl4ProofsA64/P1/MdbSspIns.lean @@ -18,6 +18,8 @@ premise: `insert_with_cap.lrF` beside: `(DelR ∧ PoolR) ∧ BlkOK ∧ CaiFr ∧ action ∧` every `OS` cap off the slot and the source kept. +(A64-S1A gen 37) `insert_with_cap.poolR`'s `hpc` by `CapSrc.al` of the source slot's carry. + Named premises: none. Case facts: MdbDelIn's `DelIn`, `FinKZ`, `PoolIdx` (as `delRP`); the old slot-3 cap `NullOrEp` (`hfh`, ruled gen 149, `ArmDecHyps.fh`). -/ @@ -131,14 +133,16 @@ variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : set_option maxHeartbeats 4000000 in /-- **The fault-handler install with the scheduling frame** (module docstring). -/ theorem tcb.install_tcb_cap.delRC {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) - (hKZ : FinKZ st ar (L.ksb s0) Ty K) (hPI : PoolIdx st OS s0) - (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) {a : A} {target slot src : U64} + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) + (Z : ArmVsZ st H OS Vc s0 s ∧ FrC st OS s0 s) {a : A} {target slot src : U64} {nc : capability.Cap} (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) (ht : target ∈ H.tcbs) (hslot : slot ∈ OS) (hsrc : src ≠ 0#u64 → src ∈ OS) (hnc : nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) (hfh : NullOrEp H (capA st s (slotIdx target layout.tcb.SLOT_FAULT_HANDLER))) : tcb.install_tcb_cap st ar s a target slot layout.tcb.SLOT_FAULT_HANDLER nc src ⦃ r => - (DelR st H Cs OS Vc Ub Ac Ty ia ie s0 r.2.1 ∧ PoolR st OS s0 r.2.1) ∧ + (DelR st H Cs OS Vc Ub Ac Ty ia ie s0 r.2.1 ∧ PoolR st OS s0 r.2.1 ∧ ArmVsZ st H OS Vc s0 r.2.1 ∧ + FrC st OS s0 r.2.1) ∧ BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac r.2.1 ∧ CaiFr st H.tcbs H.scs 0#u64 s r.2.1 ∧ (L.actionW r.2.1 = L.actionW s ∨ L.actionW r.2.1 = 1#u64) ∧ (∀ z ∈ OS, z ≠ slotIdx target layout.tcb.SLOT_FAULT_HANDLER → z ≠ src → capA st r.2.1 z = capA st s z) ⦄ := by @@ -151,22 +155,23 @@ theorem tcb.install_tcb_cap.delRC {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K unfold tcb.install_tcb_cap rw [tcb_slot_val] simp only [bind_ok] - refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.delete.delRP I hKZ hPI R Q hx) (cdt.delete.nullR I R hx)) + refine WP.spec_bind (WP.spec_and (WP.spec_and (WP.spec_and (cdt.delete.delRP I hKZ hPI R Q hx) + (cdt.delete.armVsZ I hKZ R Z.2 Z.1 hx)) (cdt.delete.nullR I R hx)) (cdt.delete.ep8 hO I.del.sca s a hx.1 hb R.jv.1.2 R.sys.sys.stz.1.1.mdbS hfh)) ?_ - rintro ⟨r, s1, a1⟩ ⟨⟨⟨R1, Q1⟩, n1⟩, h1, F1, ha1, c1⟩ - try simp only [uncurry_apply_pair] at R1 Q1 n1 h1 F1 ha1 c1 ⊢ + rintro ⟨r, s1, a1⟩ ⟨⟨⟨⟨R1, Q1⟩, Z1⟩, n1⟩, h1, F1, ha1, c1⟩ + try simp only [uncurry_apply_pair] at R1 Q1 Z1 n1 h1 F1 ha1 c1 ⊢ rcases r with v | e swap · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 ⟨⟨R1, Q1⟩, h1, F1, ha1, fun z hz h1' _ => c1 z hz h1'⟩ + exact (WP.spec_ok _).2 ⟨⟨R1, Q1, Z1⟩, h1, F1, ha1, fun z hz h1' _ => c1 z hz h1'⟩ simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] have hy0 : capA st s1 (slotIdx target layout.tcb.SLOT_FAULT_HANDLER) = .Null := okinj ((capA_eq s1 _).symm.trans (n1 v rfl)) refine WP.spec_bind (spec_eqv (P0.capability.Cap.is_null.p0 nc)) fun bn hbn => ?_ split - · exact (WP.spec_ok _).2 ⟨⟨R1, Q1⟩, h1, F1, ha1, fun z hz h1' _ => c1 z hz h1'⟩ + · exact (WP.spec_ok _).2 ⟨⟨R1, Q1, Z1⟩, h1, F1, ha1, fun z hz h1' _ => c1 z hz h1'⟩ rename_i hbf have hnc0 : nc ≠ .Null := by rintro rfl @@ -175,7 +180,7 @@ theorem tcb.install_tcb_cap.delRC {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K refine WP.spec_bind (tcb.still_valid.soa s1 target slot nc src) fun b hb' => ?_ split swap - · exact (WP.spec_ok _).2 ⟨⟨R1, Q1⟩, h1, F1, ha1, fun z hz h1' _ => c1 z hz h1'⟩ + · exact (WP.spec_ok _).2 ⟨⟨R1, Q1, Z1⟩, h1, F1, ha1, fun z hz h1' _ => c1 z hz h1'⟩ rename_i hbt obtain ⟨hs0, hso, hst⟩ := hb' hbt obtain ⟨hK, hw⟩ := hnc hnc0 @@ -190,17 +195,21 @@ theorem tcb.install_tcb_cap.delRC {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K have hm1 : MdbS st OS s1 := R1.sys.sys.stz.1.1.mdbS unfold cdt.insert rw [capA_eq, bind_ok] - refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.insert_with_cap.delR I R1 hsO hx hxy (I.del.dcan _ hx) rfl hy0 + refine WP.spec_bind (WP.spec_and (WP.spec_and (WP.spec_and (cdt.insert_with_cap.delR I R1 hsO hx hxy + (I.del.dcan _ hx) rfl hy0 (tcb_slot_notBufS I.del.heap ht hi hi2) ⟨slot, hslot, by rw [soa_thread hst]; exact CovZ.tcbSlot I.del.heap ht hi⟩ hw hnc0 C hty (tcb_slot_notEptS I.del.heap ht hi hi5)) (cdt.insert_with_cap.poolR I.del.os I.del.vr R1.jv.ksb hm1 hsO hx.1 hxy - (I.del.dcan _ hx) rfl C.nn hw hnsc hK.noAp hK.ptSrc hy0 Q1)) + (I.del.dcan _ hx) rfl C.nn hw hnsc hK.noAp + (CapSrc.al (Or.inl C.al) C.fe (Q1.1 src hsO).2) hy0 Q1)) (cdt.insert_with_cap.lrF hO (LR.self s1) hsO hx.1 hxy (I.del.dcan _ hx) rfl C.nn hw - (hm1.lnk hO hsO).2)) fun s2 h2 => ?_ - obtain ⟨⟨R2, Q2⟩, w2, -, -, -, -, ek, -⟩ := h2 + (hm1.lnk hO hsO).2)) + (cdt.insert_with_cap.armVsZ hO hm1 hsO hx.1 hxy (I.del.dcan _ hx) rfl C.nn hw (fun _ => FrUbP.fe C.fe) Z1)) + fun s2 h2 => ?_ + obtain ⟨⟨⟨R2, Q2⟩, w2, -, -, -, -, ek, -⟩, Z2⟩ := h2 obtain ⟨-, -, -, -, ea2, -, -, -⟩ := W7.blk_of_capw h1 w2 (fun b hb => hb) - exact (WP.spec_ok _).2 ⟨⟨R2, Q2⟩, (W7.blk_of_capw h1 w2 (fun b hb => hb)).1, + exact (WP.spec_ok _).2 ⟨⟨R2, Q2, Z2⟩, (W7.blk_of_capw h1 w2 (fun b hb => hb)).1, F1.trans hTp (CaiFr.of_capw7 h1 w2 fun b hb => hb), by rw [ea2]; exact ha1, fun z hz h1' h2' => (ek z hz h2' h1').trans (c1 z hz h1')⟩ diff --git a/proofs/Fl4ProofsA64/P1/MdbSspTail.lean b/proofs/Fl4ProofsA64/P1/MdbSspTail.lean index 82c90c9bb..5e8ebb883 100644 --- a/proofs/Fl4ProofsA64/P1/MdbSspTail.lean +++ b/proofs/Fl4ProofsA64/P1/MdbSspTail.lean @@ -21,6 +21,7 @@ handoff §152: no `DelR` threading of the scheduler steps — `ArmQIAt` at the p Named premises: none. Case facts: none new. -/ import Fl4ProofsA64.P1.MdbSspIns +import Fl4ProofsA64.P1.MdbDelVsZ open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P1 @@ -39,19 +40,32 @@ 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} -/-- **`ArmQIAt` composes** (module docstring). -/ -theorem ArmQIAt.trans {s0 s1 s2 : S} (h1 : ArmQIAt st H Cs OS Vc ia ie s0 s1) - (h2 : ArmQIAt st H Cs OS Vc ia ie s1 s2) : ArmQIAt st H Cs OS Vc ia ie s0 s2 := +/-- (A64-S1A gen 31) **Every clause but `ArmVs` composes**; the composite's `ArmVs` clause is supplied. -/ +theorem ArmQIAt.transV {s0 s1 s2 : S} (h1 : ArmQIAt st H Cs OS Vc ia ie s0 s1) + (h2 : ArmQIAt st H Cs OS Vc ia ie s1 s2) (hV : ArmVs st H OS Vc s0 s2) : ArmQIAt st H Cs OS Vc ia ie s0 s2 := ⟨h2.1, h2.2.1, h2.2.2.1, fun v => h2.2.2.2.1 (h1.2.2.2.1 v), fun p => h2.2.2.2.2.1 (h1.2.2.2.2.1 p), fun n => h2.2.2.2.2.2.1 (h1.2.2.2.2.2.1 n), fun n i => h2.2.2.2.2.2.2.1 (h1.2.2.2.2.2.1 n) (h1.2.2.2.2.2.2.1 n i), - fun Pt p => h2.2.2.2.2.2.2.2 Pt (h1.2.2.2.2.2.2.2 Pt p)⟩ + fun Q hQ p => h2.2.2.2.2.2.2.2.1 Q hQ (h1.2.2.2.2.2.2.2.1 Q hQ p), hV⟩ + +/-- **`ArmQIAt` composes** (module docstring; A64-S1A gen 31, E1 ruling): the second step keeps the caps of `OS`, the +named pools' words and every `VsR` word of the first step's placements (MdbArmVs's `ArmVs.keepR` form). -/ +theorem ArmQIAt.trans {s0 s1 s2 : S} (h1 : ArmQIAt st H Cs OS Vc ia ie s0 s1) + (h2 : ArmQIAt st H Cs OS Vc ia ie s1 s2) (k : OSKeep st OS s1 s2) + (hK : ∀ Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → FrUb st Ub OS s0 → + VsKeep st (L.ksb s0) Pt s1 s2) + (hP : ∀ y ∈ OS, ∀ p base, capA st s1 y = .AsidPool p base → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s2 (wa p o) = L.mem s1 (wa p o)) : ArmQIAt st H Cs OS Vc ia ie s0 s2 := + h1.transV h2 (h1.vs.keepR k h2.vs.1 hK hP) -/-- `ArmQIAt ∧ TabKeepOrZero` then `ArmQIAt ∧ TabKeep`. -/ +/-- `ArmQIAt ∧ TabKeepOrZero` then `ArmQIAt ∧ TabKeep` (A64-S1A gen 31, E1 ruling: the first step a zero step at +every placement carrying `FrC`, the second a keeping step with `OSKeep`). -/ theorem ArmQIAt.transZ {s0 s1 s2 : S} (h1 : ArmQIAt st H Cs OS Vc ia ie s0 s1 ∧ TabKeepOrZero st s0 s1) - (h2 : ArmQIAt st H Cs OS Vc ia ie s1 s2 ∧ TabKeep st s1 s2) : + (Z : ArmVsZ st H OS Vc s0 s1 ∧ FrC st OS s0 s1) + (h2 : ArmQIAt st H Cs OS Vc ia ie s1 s2 ∧ TabKeep st s1 s2) + (hK : ArmVsK st H OS Vc s1 s2 ∧ OSKeep st OS s1 s2) : ArmQIAt st H Cs OS Vc ia ie s0 s2 ∧ TabKeepOrZero st s0 s2 := - ⟨h1.1.trans h2.1, h1.2.trans h2.2.toDel⟩ + ⟨h1.1.transV h2.1 (ArmVsZ.thenK Z hK.1 hK.2).1.toVs, h1.2.trans h2.2.toDel⟩ /-- **The tail's words** (module docstring). -/ def SspW (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs Vc : Set U64) (s0 : S) (b : U64) : Prop := @@ -82,14 +96,21 @@ theorem SusW.trans {s1 s2 s3 : S} (w1 : WritesIn st s1 s2 (SusW st H Cs Vc s1)) (w2 : WritesIn st s2 s3 (SusW st H Cs Vc s2)) : WritesIn st s1 s3 (SusW st H Cs Vc s1) := (w1.trans w2).mono fun _ hb => hb.elim id (SusW.ksb w1.1) -/-- (gen 152) **`ArmQIAt ∧ TabKeep` from a post-install state across a `SusW` footprint** (`ofSspW`'s body, the -`RUN_VCPU` words added: a TCB field from offset 224, so no `OS` word — `kw7_not_os` — and no table word — `TabF.tcb`). -/ -theorem ArmQIAt.ofSusW {s0 s3 s' : S} {Ac3 Ac' : Set U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) +/-- (A64-S1A gen 28; gen 31: moved here from MdbArmVsW) **A `SusW` word is a `TkW` word** (MdbArmVsG). -/ +theorem SusW.tk {s0 : S} {b : U64} (h : SusW st H Cs Vc s0 b) : TkW st H Cs Vc s0 b := by + rcases h with (h | h | h) | ⟨y, hy, e⟩ + · 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 ⟨y, hy, 3672#u64, by simp, e⟩)) + +/-- (A64-S1A gen 31; the footprint half of `ofSusW`, moved) **A `SusW` footprint from a post-install state**: no table +word, every placed `VsR` word kept (MdbArmVsG's `ArmVsK.ofFoot` with `SusW.tk`), every `OS` word kept. -/ +theorem ArmVsK.ofSusW {s0 s3 s' : S} {Ac3 : Set U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (R3 : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s3) (hks : HeapKsOff H (L.ksb s0)) (hc0 : 0#u64 ∈ Cs) (h3 : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac3 s3) - (w : WritesIn st s3 s' (SusW st H Cs Vc s3)) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') - (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s3 s' ∧ TabKeep st s3 s' := by + (w : WritesIn st s3 s' (SusW st H Cs Vc s3)) : + (∀ b, SusW st H Cs Vc s3 b → ¬ AsW (L.ksb s3) b) ∧ ArmVsK st H OS Vc s3 s' ∧ OSKeep st OS s3 s' := by obtain ⟨Q, Rq, q⟩ := h3.1 have hSg := h3.2.2.2.2 have hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s3) Pt := by rw [R3.jv.ksb]; exact I.del.vr @@ -102,16 +123,36 @@ theorem ArmQIAt.ofSusW {s0 s3 s' : S} {Ac3 Ac' : Set U64} (I : DelIn st ar H Cs · exact I.del.vc.os b hv ⟨x, hx, h1, h2⟩ · exact kw7_not_os (Es := EH H) q hSg.sub I.del.sca (fun _ he => he) hx hb h1 h2 (Or.inl ⟨y, hy, 3672#u64, by simp, by simp, by simp, by simp, e⟩) - refine ArmQIAt.ofWK hvr w (fun b hd => ?_) k hS hb - rcases hd with (hd | hd | hv) | ⟨y, hy, e⟩ - · exact fun ha => K8.KW.notAsWE I.del.heap F hvr hks3 (fun _ he => he) (fun c hc => q.nodes c hc) hd ha - · intro ha - rcases hd with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ - · exact F.tcb I.del.heap hy (K := 3576#u64) (by simp) ha e.symm - · exact F.tcb I.del.heap hy (K := 3584#u64) (by simp) ha e.symm - · exact F.node rfl hc (q.nodes c hc) (by rw [debug_val]; omega) ha e.symm - · exact fun ha => hvr.vc b (Or.inr ha) hv - · exact fun ha => F.tcb I.del.heap hy (K := 3672#u64) (by simp) ha e.symm + have hA : ∀ b, SusW st H Cs Vc s3 b → ¬ AsW (L.ksb s3) b := fun b hd => by + rcases hd with (hd | hd | hv) | ⟨y, hy, e⟩ + · exact fun ha => K8.KW.notAsWE I.del.heap F hvr hks3 (fun _ he => he) (fun c hc => q.nodes c hc) hd ha + · intro ha + rcases hd with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ + · exact F.tcb I.del.heap hy (K := 3576#u64) (by simp) ha e.symm + · exact F.tcb I.del.heap hy (K := 3584#u64) (by simp) ha e.symm + · exact F.node rfl hc (q.nodes c hc) (by rw [debug_val]; omega) ha e.symm + · exact fun ha => hvr.vc b (Or.inr ha) hv + · exact fun ha => F.tcb I.del.heap hy (K := 3672#u64) (by simp) ha e.symm + exact ⟨hA, ArmVsK.ofFoot (Ko := ∅) I.del.heap q w (fun b hb => Or.inr (Or.inl (SusW.tk hb))) hA, k⟩ + +/-- (A64-S1A gen 31) `ArmVsK.ofSusW` at an `SspW` footprint (the keeping second step of `ArmQIAt.transZ`). -/ +theorem ArmVsK.ofSspW {s0 s3 s' : S} {Ac3 : Set U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (R3 : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s3) (hks : HeapKsOff H (L.ksb s0)) (hc0 : 0#u64 ∈ Cs) + (h3 : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac3 s3) + (w : WritesIn st s3 s' (SspW st H Cs Vc s3)) : ArmVsK st H OS Vc s3 s' ∧ OSKeep st OS s3 s' := + (ArmVsK.ofSusW I R3 hks hc0 h3 (w.mono fun _ h => Or.inl h)).2 + +/-- (gen 152) **`ArmQIAt ∧ TabKeep` from a post-install state across a `SusW` footprint** (`ofSspW`'s body, the +`RUN_VCPU` words added: a TCB field from offset 224, so no `OS` word — `kw7_not_os` — and no table word — `TabF.tcb`). -/ +theorem ArmQIAt.ofSusW {s0 s3 s' : S} {Ac3 Ac' : Set U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (R3 : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s3) (hks : HeapKsOff H (L.ksb s0)) (hc0 : 0#u64 ∈ Cs) + (h3 : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac3 s3) + (w : WritesIn st s3 s' (SusW st H Cs Vc s3)) (hS : SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') + (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : + ArmQIAt st H Cs OS Vc ia ie s3 s' ∧ TabKeep st s3 s' := by + have hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s3) Pt := by rw [R3.jv.ksb]; exact I.del.vr + obtain ⟨hA, hK, k⟩ := ArmVsK.ofSusW I R3 hks hc0 h3 w + exact ArmQIAt.ofWK hvr w hA k hS hb hK.toVs /-- **`ArmQIAt ∧ TabKeep` from a post-install state across an `SspW` footprint** (module docstring). -/ theorem ArmQIAt.ofSspW {s0 s3 s' : S} {Ac3 Ac' : Set U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) diff --git a/proofs/Fl4ProofsA64/P1/MdbSusQ.lean b/proofs/Fl4ProofsA64/P1/MdbSusQ.lean index 2b827b6c8..c67b8cecc 100644 --- a/proofs/Fl4ProofsA64/P1/MdbSusQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbSusQ.lean @@ -16,6 +16,9 @@ ruling, item a: no `hrv` — the target may be in an `ARMVCPURun`). `suspend.dmr`, `SysL.dfMDR` with the target named by the invoked slot, MdbSspTail's `ArmQIAt.ofSusW`, `ArmQIAt.transZ`), **`syscall.decode_invocation.suspend_armQIAt`**. +(A64-S1A gen 40, Architect ruling for gen 40, R3) `tcb.decode.suspendQAt` / `suspend_armQIAt` also post `ArmVsK` (last +conjunct; the restart's by MdbHiVsArm's `tcb.restart_caller.armVsK`). + Named premises: none. Case facts: none new (`DelIn`, `HeapKsOff` as the other arms; the target's run VCPU is a `Vc` VCPU by `VcTy.run` at the post-restart `DelR` state). -/ @@ -153,15 +156,15 @@ local macro "lbl_neS" : tactic => `(tactic| exact lbl_ne_of_val (by fl4_abi.label.TCBSetFlags, fl4_abi.label.TCBSetTimer, fl4_abi.label.TCBReadFPU, core.num.U64.MAX, U64.rMax])) set_option maxHeartbeats 2000000 in -/-- **TCB Suspend to `ArmQIAt ∧ TabKeepOrZero`** (module docstring; no `hrv`). -/ -theorem tcb.decode.suspendQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} +/-- **`suspendQAt` exporting the slot fact**: every `OS` word kept (A64-S1A gen 41). -/ +theorem tcb.decode.suspendSAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) (hl : lbl = fl4_abi.label.TCBSuspend) : tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => - ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ OSKeep st OS s r.2.1 ⦄ := by have ht : t ∈ H.tcbs := D.cap.2.1 t rfl have hW : ∀ v ∈ Vc, VcWords H.omega H.frame v := fun v hv => (I.vty.obj v hv).1 unfold tcb.decode @@ -172,16 +175,48 @@ theorem tcb.decode.suspendQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len refine spec_ite (fun hc => absurd (hl.symm.trans hc) ?_) fun _ => ?_ · lbl_neS refine spec_ite (fun _ => ?_) fun hc => absurd hl hc - refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) ?_ - rintro s2 ⟨⟨RS2, R2⟩, Q2⟩ - have A2 := ArmQIAt.ofDelR R2 Q2 + refine WP.spec_bind (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) + (tcb.restart_caller.armVsK I D P B h1 d1 ds1)) ?_ + rintro s2 ⟨⟨⟨RS2, R2⟩, Q2, Z2⟩, K2⟩ + have A2 := ArmQIAt.ofDelR R2 Q2 Z2.1.toVs have hct2 : L.curW s2 ∈ H.tcbs := RS2.blk.1.choose_spec.choose_spec.curT refine WP.spec_bind (sched.suspend.dmr a1 t RS2.blk ht B.ly.h0 RS2.sys.vr RS2.sym (RS2.na t ht) (fun hnz => (R2.jv.2.run t ht).resolve_left hnz) hW hct2) ?_ rintro ⟨s3, a3⟩ ⟨b3, d3, -, -⟩ have hS3 := SysL.dfMDR I.del.heap I.del.os I.del.vc (fun b hb => (R2.jv.2.w hb).2.1) RS2.blk I.del.sca (RS2.namedT hcap ht) (RS2.namedT hcap ht) R2.sys d3 - exact (WP.spec_ok _).2 (ArmQIAt.transZ A2 (ArmQIAt.ofSusW I R2 hks P.core0 RS2.blk d3.w hS3 b3)) + have vk := (ArmVsK.ofSusW I R2 hks P.core0 RS2.blk d3.w).2 + exact (WP.spec_ok _).2 ((fun h => ⟨h.1, h.2, ArmVsK.trans K2.1 K2.2 vk.1, OSKeep.trans' K2.2 vk.2⟩) + (ArmQIAt.transZ A2 Z2 (ArmQIAt.ofSusW I R2 hks P.core0 RS2.blk d3.w hS3 b3) vk)) + +set_option maxHeartbeats 2000000 in +/-- **TCB Suspend to `ArmQIAt ∧ TabKeepOrZero`** (module docstring; no `hrv`). -/ +theorem tcb.decode.suspendQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (hl : lbl = fl4_abi.label.TCBSuspend) : + tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ⦄ := + WP.spec_mono (tcb.decode.suspendSAt hA I D P B Y hks hcap hl) fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ + +/-- **`suspend_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.suspend_armSAt (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSuspend) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := + syscall.decode_invocation.tcbG + (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x ∧ ArmVsK st H OS Vc s x ∧ + OSKeep st OS s x) + ((fun h => ⟨h.1, h.2, ArmVsK.refl s, OSKeep.rfl' s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s))) + a len blk call don fp buf + fun _ _ e => tcb.decode.suspendSAt hA I D P B Y hks hcap (e.trans hl) /-- **The Thread arm of `decode_invocation` at Suspend to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ theorem syscall.decode_invocation.suspend_armQIAt (hA : P0.ArchTotal ar) {s : S} @@ -192,10 +227,9 @@ theorem syscall.decode_invocation.suspend_armQIAt (hA : P0.ArchTotal ar) {s : S} (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSuspend) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := - syscall.decode_invocation.tcbG (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) a len blk call don fp buf - fun _ _ e => tcb.decode.suspendQAt hA I D P B Y hks hcap (e.trans hl) + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := + WP.spec_mono (syscall.decode_invocation.suspend_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbTcbArmQ.lean b/proofs/Fl4ProofsA64/P1/MdbTcbArmQ.lean index cae1b99de..44fbcc11e 100644 --- a/proofs/Fl4ProofsA64/P1/MdbTcbArmQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbTcbArmQ.lean @@ -37,6 +37,9 @@ Every post is `ArmQI st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s'` from th OS)`); each is the body of the name without `At`, moved, and that name is now its `ArmQIAt.toQI` projection (statement unchanged). +(A64-S1A gen 37) the three inserts' `hpc` (`insert_with_cap.poolR`) are the source slot's `CapSrc` carry (`CapSrc.al` +for the IPC buffer frame; the `Ept` / `Notification` caps are their sources'). + Named premises: none. Case facts: MdbDelIn's `DelIn`; MdbPoolN's ruled `PoolIdx` at the decode's state (`hPI`); the class fact `FinKZ` (`hKZ`, MdbPoolDelR, discharged for `S2Q` by `finKZ_s2`); `hXE` (SetEPTRoot) and `hSC` (SetIRQHandler) as ruled for the `SysL` tops; the handler's IRQ below 5376 (`hi`, as `irqClear_sysL` / `irqSet_sysL`). @@ -106,13 +109,13 @@ set_option hygiene false in /-- An error leaf at the stalled state (`SysL.df`, `ArmQIAt.ofStall`). -/ local macro "qleaf" : tactic => `(tactic| first | exact (WP.spec_ok _).2 (ArmQIAt.ofStall I h1 d1 ds1 vk1 - (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1)) + (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) (ArmVsK.ofDFI I D P B d1)) | (simp only [error.invalid_cap, error.truncated, error.illegal, bind_ok, core.result.Result.Insts.CoreOpsTry.branch, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] exact (WP.spec_ok _).2 (ArmQIAt.ofStall I h1 d1 ds1 vk1 - (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1)))) + (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) (ArmVsK.ofDFI I D P B d1)))) set_option hygiene false in /-- An extra-slot read with its error leaf. -/ @@ -164,7 +167,7 @@ set_option maxHeartbeats 4000000 in here, `tcb.decode_set_space.armQI` its projection). -/ theorem tcb.decode_set_space.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -202,26 +205,27 @@ theorem tcb.decode_set_space.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} {call rename_i hbt have hfh : capA st s1 x0 ≠ .Null → TcbK (capA st s1 x0) ∧ CapRt.EncWf (capA st s1 x0) := fun hn => ⟨vfh_tk (hbt ▸ hb.1) hn, CapRt.decodeF_encWf _ _⟩ - refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2⟩ => ?_ - refine WP.spec_mono (P₀ := fun r => DelR st H Cs OS Vc Ub Ac Ty ia ie s r.2.1 ∧ PoolR st OS s r.2.1) ?_ - fun r hr => ArmQIAt.ofDelR hr.1 hr.2 + refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2, Z2⟩ => ?_ + refine WP.spec_mono (P₀ := fun r => DelR st H Cs OS Vc Ub Ac Ty ia ie s r.2.1 ∧ PoolR st OS s r.2.1 ∧ + ArmVsZ st H OS Vc s r.2.1 ∧ FrC st OS s r.2.1) ?_ + fun r hr => ArmQIAt.ofDelR hr.1 hr.2.1 hr.2.2.1.toVs simp only [lift, bind_ok] unfold tcb.thread_control_caps simp only [lift, bind_ok, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_SPACE, tcb.UPDATE_IPC_BUFFER] simp - refine qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) - (Q2 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) - (tcb.install_tcb_cap.delRP I hKZ hPI R2 Q2 ht (by simp [layout.tcb.SLOT_FAULT_HANDLER]) + refine qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) + (Q2 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) + (tcb.install_tcb_cap.delRP I hKZ hPI R2 Q2 Z2 ht (by simp [layout.tcb.SLOT_FAULT_HANDLER]) (by simp [layout.tcb.SLOT_FAULT_HANDLER]) P.src (fun _ => hO0) hfh (by simp [layout.tcb.SLOT_FAULT_HANDLER])) (fun s3 a3 R3 => ?_) fun _ h => h - refine qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) - (Q2 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) - (tcb.install_tcb_cap.delRP I hKZ hPI R3.1 R3.2 ht (by simp [layout.tcb.SLOT_CTABLE]) + refine qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) + (Q2 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) + (tcb.install_tcb_cap.delRP I hKZ hPI R3.1 R3.2.1 R3.2.2 ht (by simp [layout.tcb.SLOT_CTABLE]) (by simp [layout.tcb.SLOT_CTABLE]) P.src (fun _ => hO1) (fun _ => hcc) (by simp [layout.tcb.SLOT_CTABLE])) (fun s4 a4 R4 => ?_) fun _ h => h - exact qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) - (Q2 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) - (tcb.install_tcb_cap.delRP I hKZ hPI R4.1 R4.2 ht (by simp [layout.tcb.SLOT_VTABLE]) + exact qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) + (Q2 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) + (tcb.install_tcb_cap.delRP I hKZ hPI R4.1 R4.2.1 R4.2.2 ht (by simp [layout.tcb.SLOT_VTABLE]) (by simp [layout.tcb.SLOT_VTABLE]) P.src (fun _ => hO2) (fun _ => hvc) (by simp [layout.tcb.SLOT_VTABLE])) (fun s5 a5 R5 => (WP.spec_ok _).2 R5) fun _ h => h @@ -229,7 +233,7 @@ set_option maxHeartbeats 4000000 in /-- **SetSpace after the stall to `ArmQI ∧ TabKeepOrZero`** (MdbSetSpL's `tcb.decode_set_space.sysL` text). -/ theorem tcb.decode_set_space.armQI {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -248,7 +252,7 @@ set_option maxHeartbeats 2000000 in `tcb.decode.setSpaceQ` its projection). -/ theorem tcb.decode.setSpaceQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBSetSpace) : @@ -268,7 +272,7 @@ set_option maxHeartbeats 2000000 in /-- **TCB SetSpace to `ArmQI ∧ TabKeepOrZero`** (MdbSetSpL's `tcb.decode.setSpaceL` text). -/ theorem tcb.decode.setSpaceQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBSetSpace) : @@ -285,7 +289,7 @@ theorem tcb.decode.setSpaceQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len b body moved here, `syscall.decode_invocation.setSpace_armQI` its projection). -/ theorem syscall.decode_invocation.setSpace_armQIAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetSpace) (len : U64) @@ -293,13 +297,13 @@ theorem syscall.decode_invocation.setSpace_armQIAt (hA : P0.ArchTotal ar) {s : S syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := syscall.decode_invocation.tcbG (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) a len blk call don fp buf + (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) a len blk call don fp buf fun _ _ e => tcb.decode.setSpaceQAt hA I hKZ hPI D P B Y (e.trans hl) /-- **The Thread arm of `decode_invocation` at SetSpace to `ArmQI ∧ TabKeepOrZero`.** -/ theorem syscall.decode_invocation.setSpace_armQI (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetSpace) (len : U64) @@ -317,9 +321,10 @@ theorem syscall.decode_invocation.setSpace_armQI (hA : P0.ArchTotal ar) {s : S} /-- **The `IPC_BUFFER` write keeps `PoolR`** (a TCB field: every `OS` word and every `VsR` word kept). -/ theorem obj.Tcb.set_ipc_buffer.poolR {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) - (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) {t v : U64} (ht : t ∈ H.tcbs) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) + (Z : ArmVsZ st H OS Vc s0 s ∧ FrC st OS s0 s) {t v : U64} (ht : t ∈ H.tcbs) (hv : v.val % 1024 = 0) : - obj.Tcb.set_ipc_buffer st t s v ⦃ s' => PoolR st OS s0 s' ⦄ := by + obj.Tcb.set_ipc_buffer st t s v ⦃ s' => PoolR st OS s0 s' ∧ ArmVsZ st H OS Vc s0 s' ∧ FrC st OS s0 s' ⦄ := by refine WP.spec_mono (WP.spec_and (obj.Tcb.set_ipc_buffer.delR I R ht hv) (obj.Tcb.set_ipc_buffer.wr s t v)) fun s' ⟨⟨_, k⟩, e⟩ => ?_ subst e @@ -330,14 +335,18 @@ theorem obj.Tcb.set_ipc_buffer.poolR {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub P have w : WritesIn st s (L.wr s (wa t 3512#u64) v) (· = wa t 3512#u64) := writesIn_wr ha have vk : VsKeep st (L.ksb s0) Pt s (L.wr s (wa t 3512#u64) v) := VsKeep.of_w I.del.vr.al w fun b hb e => out_ne_field (q.omega _ (I.del.vr.om b hb)) ht (hT1 t ht) (K := 3512#u64) (by simp) (by rw [e]) - exact PoolR.keep Q k (L.ksb_wr _ _ _) fun j => vk _ (Or.inr (by rw [← R.jv.ksb]; exact asW_at _ j)) + have K : ArmVsK st H OS Vc s (L.wr s (wa t 3512#u64) v) := ArmVsK.ofW w fun _ _ hvr _ b hb hv => + out_ne_field (q.omega _ (hvr.om b hv)) ht (hT1 t ht) (K := 3512#u64) (by simp) (by rw [hb]) + exact ⟨PoolR.keep Q k (L.ksb_wr _ _ _) fun j => vk _ (Or.inr (by rw [← R.jv.ksb]; exact asW_at _ j)), + ArmVsZ.thenK Z K k⟩ set_option maxHeartbeats 4000000 in /-- (gen 147, ruling (a)) **`tcb.install_buffer.armQI` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, `tcb.install_buffer.armQI` its projection). -/ theorem tcb.install_buffer.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) - (hKZ : FinKZ st ar (L.ksb s0) Ty K) (hPI : PoolIdx st OS s0) (h0 : 0#u64 ∈ Cs) - (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) {a : A} {target slot baddr : U64} + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) (h0 : 0#u64 ∈ Cs) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) + (Z : ArmVsZ st H OS Vc s0 s ∧ FrC st OS s0 s) {a : A} {target slot baddr : U64} {buffer : capability.Cap × obj.Slot} (ht : target ∈ H.tcbs) (hslot : slot ∈ OS) (hba : baddr.val % 1024 = 0) (hbuf : buffer.2 ≠ 0#u64 → buffer.2 ∈ OS ∧ (∃ ptr size rights x1 x2 x3 x4, buffer.1 = .Frame ptr size rights false x1 x2 x3 x4) ∧ CapRt.EncWf buffer.1) : @@ -348,20 +357,21 @@ theorem tcb.install_buffer.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt unfold tcb.install_buffer rw [tcb_slot_val] simp only [bind_ok] - refine WP.spec_bind (WP.spec_and (cdt.delete.delRP I hKZ hPI R Q hx) (cdt.delete.nullR I R hx)) ?_ - rintro ⟨r, s1, a1⟩ ⟨⟨R1, Q1⟩, n1⟩ - try simp only [uncurry_apply_pair] at R1 Q1 n1 ⊢ + refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.delete.delRP I hKZ hPI R Q hx) + (cdt.delete.armVsZ I hKZ R Z.2 Z.1 hx)) (cdt.delete.nullR I R hx)) ?_ + rintro ⟨r, s1, a1⟩ ⟨⟨⟨R1, Q1⟩, Z1⟩, n1⟩ + try simp only [uncurry_apply_pair] at R1 Q1 Z1 n1 ⊢ rcases r with v | e swap · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 (ArmQIAt.ofDelR R1 Q1) + exact (WP.spec_ok _).2 (ArmQIAt.ofDelR R1 Q1 Z1.1.toVs) simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] have hy0 : capA st s1 (slotIdx target layout.tcb.SLOT_BUFFER) = .Null := okinj ((capA_eq s1 _).symm.trans (n1 v rfl)) refine WP.spec_bind (WP.spec_and (obj.Tcb.set_ipc_buffer.delR I R1 ht hba) - (obj.Tcb.set_ipc_buffer.poolR I R1 Q1 ht hba)) ?_ - rintro s2 ⟨⟨R2, k2⟩, Q2⟩ + (obj.Tcb.set_ipc_buffer.poolR I R1 Q1 Z1 ht hba)) ?_ + rintro s2 ⟨⟨R2, k2⟩, Q2, Z2⟩ have hy2 : capA st s2 (slotIdx target layout.tcb.SLOT_BUFFER) = .Null := by rw [k2.capA hx.1]; exact hy0 obtain ⟨c, src⟩ := buffer simp only at hbuf @@ -369,10 +379,10 @@ theorem tcb.install_buffer.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt refine WP.spec_bind (tcb.still_valid.soa s2 target slot c src) fun b hb => ?_ refine WP.spec_bind (Pₘ := fun s3 => (SysL st H Cs OS ia ie s3 ∧ SymL st H Cs s3) ∧ (∃ Ac', BXI st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s3) ∧ VcCap st Vc OS s3 ∧ - PoolR st OS s0 s3 ∧ L.ksb s3 = L.ksb s0) ?_ fun s3 h3 => ?_ + PoolR st OS s0 s3 ∧ L.ksb s3 = L.ksb s0 ∧ ArmVsZ st H OS Vc s0 s3 ∧ FrC st OS s0 s3) ?_ fun s3 h3 => ?_ · split swap - · exact (WP.spec_ok _).2 ⟨⟨R2.sys, R2.sym⟩, R2.jv.1.parts, R2.vc, Q2, R2.jv.ksb⟩ + · exact (WP.spec_ok _).2 ⟨⟨R2.sys, R2.sym⟩, R2.jv.1.parts, R2.vc, Q2, R2.jv.ksb, Z2⟩ rename_i hbt obtain ⟨hs0, hso, hst⟩ := hb hbt obtain ⟨hsO, ⟨ptr, size, rights, x1, x2, x3, x4, rfl⟩, hw⟩ := hbuf hs0 @@ -383,7 +393,8 @@ theorem tcb.install_buffer.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt have nn := (R2.sys.sys.stz.1.1.mdbS.lnk I.del.os hsO).2 unfold cdt.insert rw [capA_eq, bind_ok] - refine WP.spec_mono (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLVB I.del.heap I.del.os hb2 R2.sys R2.sym + refine WP.spec_mono (WP.spec_and (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLVB I.del.heap I.del.os hb2 + R2.sys R2.sym R2.vc hsO hx.1 hxy (I.del.dcan _ hx) rfl hy2 (Or.inr ⟨Or.inr ⟨ptr, size, rights, x1, x2, x3, x4, rfl⟩, ⟨(fun _ _ _ _ h => by cases h), (fun _ _ _ h => by cases h)⟩⟩) @@ -392,11 +403,13 @@ theorem tcb.install_buffer.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt (cdt.insert_with_cap.lrF I.del.os (LR.self s2) hsO hx.1 hxy (I.del.dcan _ hx) rfl C.nn hw nn)) (cdt.insert_with_cap.poolR I.del.os I.del.vr R2.jv.ksb R2.sys.sys.stz.1.1.mdbS hsO hx.1 hxy (I.del.dcan _ hx) rfl C.nn hw (fun p b e => by rw [hsc] at e; cases e) (fun _ _ h => by cases h) - (fun _ _ _ _ h => by cases h) hy2 Q2)) + (CapSrc.al (Or.inl C.al) C.fe (Q2.1 src hsO).2) hy2 Q2)) + (cdt.insert_with_cap.armVsZ I.del.os R2.sys.sys.stz.1.1.mdbS hsO hx.1 hxy (I.del.dcan _ hx) rfl C.nn hw (fun _ => FrUbP.fe C.fe) + Z2)) ?_ - rintro s3 ⟨⟨⟨b3, y3, v3⟩, w3, -⟩, q3⟩ - exact ⟨⟨b3, y3⟩, (Cur0R.capw7 R2.jv.1.1 w3 fun _ h => h).bxi, v3, q3, w3.1.trans R2.jv.ksb⟩ - obtain ⟨⟨B3, Y3⟩, ⟨Ac3, hb3⟩, V3, Q3, kb3⟩ := h3 + rintro s3 ⟨⟨⟨⟨b3, y3, v3⟩, w3, -⟩, q3⟩, z3⟩ + exact ⟨⟨b3, y3⟩, (Cur0R.capw7 R2.jv.1.1 w3 fun _ h => h).bxi, v3, q3, w3.1.trans R2.jv.ksb, z3⟩ + obtain ⟨⟨B3, Y3⟩, ⟨Ac3, hb3⟩, V3, Q3, kb3, Z3⟩ := h3 refine WP.spec_bind (sched.cur_thread.spec s3) fun ct _ => ?_ simp only [obj.Tcb.Insts.CoreCmpPartialEqTcb.eq, bind_ok] split @@ -409,23 +422,25 @@ theorem tcb.install_buffer.armQIAt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt (DFB.ofDF (DF.ofKL f4 l4 (LvF.none_le _))) (B3.ipc.keep (IbK.of_w q4.tcbs f4 fun y hy hk => ib_not_kw8 q4 (fun c hc => absurd hc (Set.notMem_empty c)) hSg.sub (fun e he => absurd he (Set.notMem_empty e)) hy (Or.inl hk))) - obtain ⟨k4, t4⟩ := DF.osTab I.del.heap I.del.os hb3 B3 (by rw [kb3]; exact I.del.vr) h0 - (DF.ofKL (c := L.curW s3) (Ko := ∅) f4 l4 (LvF.none_le _)) + have d4 := DF.ofKL (c := L.curW s3) (Ko := ∅) f4 l4 (LvF.none_le _) + obtain ⟨k4, t4⟩ := DF.osTab I.del.heap I.del.os hb3 B3 (by rw [kb3]; exact I.del.vr) h0 d4 exact ArmQIAt.ofPR hS4 ⟨Ac3, bk4⟩ (fun _ => V3.keepO k4) (Q3.keepT k4 t4) - · exact (WP.spec_ok _).2 (ArmQIAt.ofPR ⟨B3, Y3⟩ ⟨Ac3, hb3.blk⟩ (fun _ => V3) Q3) + (ArmVsZ.thenK Z3 (DF.armVsK I.del.heap hb3 B3 (by rw [kb3]; exact I.del.vr) h0 d4) k4).1.toVs + · exact (WP.spec_ok _).2 (ArmQIAt.ofPR ⟨B3, Y3⟩ ⟨Ac3, hb3.blk⟩ (fun _ => V3) Q3 Z3.1.toVs) set_option maxHeartbeats 4000000 in /-- **`install_buffer` from `DelR ∧ PoolR` to `ArmQI ∧ TabKeepOrZero`** (MdbIpcBuf's `tcb.install_buffer.sysL` text). -/ theorem tcb.install_buffer.armQI {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) - (hKZ : FinKZ st ar (L.ksb s0) Ty K) (hPI : PoolIdx st OS s0) (h0 : 0#u64 ∈ Cs) - (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) {a : A} {target slot baddr : U64} + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) (h0 : 0#u64 ∈ Cs) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) + (Z : ArmVsZ st H OS Vc s0 s ∧ FrC st OS s0 s) {a : A} {target slot baddr : U64} {buffer : capability.Cap × obj.Slot} (ht : target ∈ H.tcbs) (hslot : slot ∈ OS) (hba : baddr.val % 1024 = 0) (hbuf : buffer.2 ≠ 0#u64 → buffer.2 ∈ OS ∧ (∃ ptr size rights x1 x2 x3 x4, buffer.1 = .Frame ptr size rights false x1 x2 x3 x4) ∧ CapRt.EncWf buffer.1) : tcb.install_buffer st ar s a target slot baddr buffer ⦃ r => ArmQI st H Cs OS Vc ia ie s0 r.2.1 ∧ TabKeepOrZero st s0 r.2.1 ⦄ := by - exact WP.spec_mono (tcb.install_buffer.armQIAt I hKZ hPI h0 R Q ht hslot hba hbuf) fun r h => by + exact WP.spec_mono (tcb.install_buffer.armQIAt I hKZ hPI h0 R Q Z ht hslot hba hbuf) fun r h => by first | exact ⟨h.1.toQI, h.2⟩ | (obtain ⟨_, _, _⟩ := r; exact ⟨h.1.toQI, h.2⟩) @@ -437,7 +452,7 @@ set_option maxHeartbeats 4000000 in moved here, `tcb.decode_set_ipc_buffer.armQI` its projection). -/ theorem tcb.decode_set_ipc_buffer.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -450,13 +465,13 @@ theorem tcb.decode_set_ipc_buffer.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} xslotOQ 0#usize as x0, hO0 refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ hS) fun baddr _ => ?_ dbufQ s1, baddr, x0 - refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2⟩ => ?_ + refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2, Z2⟩ => ?_ unfold tcb.thread_control_caps simp only [lift, bind_ok, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_SPACE, tcb.UPDATE_IPC_BUFFER] simp exact qq_bind (Q1 := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) (Q2 := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (tcb.install_buffer.armQIAt (buffer := (bc, bs)) I hKZ hPI P.core0 R2 Q2 ht P.src hba fun h => by + (tcb.install_buffer.armQIAt (buffer := (bc, bs)) I hKZ hPI P.core0 R2 Q2 Z2 ht P.src hba fun h => by obtain ⟨e, hf, hw⟩ := hbs h; exact ⟨e ▸ hO0, hf, hw⟩) (fun _ _ h => (WP.spec_ok _).2 h) fun _ h => h @@ -465,7 +480,7 @@ set_option maxHeartbeats 4000000 in text). -/ theorem tcb.decode_set_ipc_buffer.armQI {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -484,7 +499,7 @@ set_option maxHeartbeats 4000000 in here, `tcb.decode_configure.armQI` its projection). -/ theorem tcb.decode_configure.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -508,26 +523,27 @@ theorem tcb.decode_configure.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} {call simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] try simp only [uncurry_apply_pair] obtain ⟨hcc, hvc⟩ := hr cc vc rfl - refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2⟩ => ?_ + refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2, Z2⟩ => ?_ simp only [lift, bind_ok] unfold tcb.thread_control_caps simp only [lift, bind_ok, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_SPACE, tcb.UPDATE_IPC_BUFFER] simp - have sl : ∀ s', DelR st H Cs OS Vc Ub Ac Ty ia ie s s' ∧ PoolR st OS s s' → - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' := fun _ R => ArmQIAt.ofDelR R.1 R.2 - refine qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) + have sl : ∀ s', DelR st H Cs OS Vc Ub Ac Ty ia ie s s' ∧ PoolR st OS s s' ∧ ArmVsZ st H OS Vc s s' ∧ + FrC st OS s s' → ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' := + fun _ R => ArmQIAt.ofDelR R.1 R.2.1 R.2.2.1.toVs + refine qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) (Q2 := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (tcb.install_tcb_cap.delRP I hKZ hPI R2 Q2 ht (by simp [layout.tcb.SLOT_CTABLE]) + (tcb.install_tcb_cap.delRP I hKZ hPI R2 Q2 Z2 ht (by simp [layout.tcb.SLOT_CTABLE]) (by simp [layout.tcb.SLOT_CTABLE]) P.src (fun _ => hO0) (fun _ => hcc) (by simp [layout.tcb.SLOT_CTABLE])) (fun s3 a3 R3 => ?_) sl - refine qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) + refine qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) (Q2 := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (tcb.install_tcb_cap.delRP I hKZ hPI R3.1 R3.2 ht (by simp [layout.tcb.SLOT_VTABLE]) + (tcb.install_tcb_cap.delRP I hKZ hPI R3.1 R3.2.1 R3.2.2 ht (by simp [layout.tcb.SLOT_VTABLE]) (by simp [layout.tcb.SLOT_VTABLE]) P.src (fun _ => hO1) (fun _ => hvc) (by simp [layout.tcb.SLOT_VTABLE])) (fun s4 a4 R4 => ?_) sl exact qq_bind (Q1 := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) (Q2 := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (tcb.install_buffer.armQIAt (buffer := (bc, bs)) I hKZ hPI P.core0 R4.1 R4.2 ht P.src hba fun h => by + (tcb.install_buffer.armQIAt (buffer := (bc, bs)) I hKZ hPI P.core0 R4.1 R4.2.1 R4.2.2 ht P.src hba fun h => by obtain ⟨e, hf, hw⟩ := hbs h; exact ⟨e ▸ hO2, hf, hw⟩) (fun _ _ h => (WP.spec_ok _).2 h) fun _ h => h @@ -535,7 +551,7 @@ set_option maxHeartbeats 4000000 in /-- **Configure after the stall to `ArmQI ∧ TabKeepOrZero`** (MdbIpcBuf's `tcb.decode_configure.sysL` text). -/ theorem tcb.decode_configure.armQI {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -554,7 +570,7 @@ set_option maxHeartbeats 2000000 in `tcb.decode.setIpcBufQ` its projection). -/ theorem tcb.decode.setIpcBufQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBSetIPCBuffer) : @@ -574,7 +590,7 @@ set_option maxHeartbeats 2000000 in /-- **TCB SetIPCBuffer to `ArmQI ∧ TabKeepOrZero`** (MdbIpcBuf's `tcb.decode.setIpcBufL` text). -/ theorem tcb.decode.setIpcBufQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBSetIPCBuffer) : @@ -592,7 +608,7 @@ set_option maxHeartbeats 2000000 in `tcb.decode.configureQ` its projection). -/ theorem tcb.decode.configureQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBConfigure) : @@ -612,7 +628,7 @@ set_option maxHeartbeats 2000000 in /-- **TCB Configure to `ArmQI ∧ TabKeepOrZero`** (MdbIpcBuf's `tcb.decode.configureL` text). -/ theorem tcb.decode.configureQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBConfigure) : @@ -629,7 +645,7 @@ theorem tcb.decode.configureQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len the body moved here, `syscall.decode_invocation.setIpcBuf_armQI` its projection). -/ theorem syscall.decode_invocation.setIpcBuf_armQIAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetIPCBuffer) (len : U64) @@ -637,13 +653,13 @@ theorem syscall.decode_invocation.setIpcBuf_armQIAt (hA : P0.ArchTotal ar) {s : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := syscall.decode_invocation.tcbG (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) a len blk call don fp buf + (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) a len blk call don fp buf fun _ _ e => tcb.decode.setIpcBufQAt hA I hKZ hPI D P B Y (e.trans hl) /-- **The Thread arm of `decode_invocation` at SetIPCBuffer to `ArmQI ∧ TabKeepOrZero`.** -/ theorem syscall.decode_invocation.setIpcBuf_armQI (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetIPCBuffer) (len : U64) @@ -661,7 +677,7 @@ theorem syscall.decode_invocation.setIpcBuf_armQI (hA : P0.ArchTotal ar) {s : S} the body moved here, `syscall.decode_invocation.configure_armQI` its projection). -/ theorem syscall.decode_invocation.configure_armQIAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBConfigure) (len : U64) @@ -669,13 +685,13 @@ theorem syscall.decode_invocation.configure_armQIAt (hA : P0.ArchTotal ar) {s : syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := syscall.decode_invocation.tcbG (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) a len blk call don fp buf + (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) a len blk call don fp buf fun _ _ e => tcb.decode.configureQAt hA I hKZ hPI D P B Y (e.trans hl) /-- **The Thread arm of `decode_invocation` at Configure to `ArmQI ∧ TabKeepOrZero`.** -/ theorem syscall.decode_invocation.configure_armQI (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBConfigure) (len : U64) @@ -700,7 +716,7 @@ set_option maxHeartbeats 4000000 in `tcb.decode.setEptQ` its projection). -/ theorem tcb.decode.setEptQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) @@ -747,7 +763,7 @@ theorem tcb.decode.setEptQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len b have q1 := h1.bxi.1.choose_spec.choose_spec have hct : L.curW s1 ∈ H.tcbs := q1.curT refine WP.spec_bind (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) - (tcb.restart_caller.sts (q1.nodes _ q1.cur) (q1.tcbs _ hct))) fun s2 ⟨⟨⟨Rs, R2⟩, Q2⟩, w2⟩ => ?_ + (tcb.restart_caller.sts (q1.nodes _ q1.cur) (q1.tcbs _ hct))) fun s2 ⟨⟨⟨Rs, R2⟩, Q2, Z2⟩, w2⟩ => ?_ have k2 : OSKeep st OS s1 s2 := stt_osk P.os q1 hct w2 rw [tcb_slot_val, bind_ok] have hi : layout.tcb.SLOT_EPT.val < 7 := by simp [layout.tcb.SLOT_EPT] @@ -759,16 +775,16 @@ theorem tcb.decode.setEptQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len b rcases R2.sys.ep _ hy.1 hyE with h | ⟨_, _, _, _, _, h⟩ <;> (rw [← e, hsl] at h; cases h) have hyc : capA st s2 (slotIdx t layout.tcb.SLOT_EPT) = .Null ∨ K (capA st s2 (slotIdx t layout.tcb.SLOT_EPT)) := (R2.sys.ep _ hy.1 hyE).imp id fun ⟨p', l', m', a', v', e⟩ => e ▸ I.s2 _ (Or.inr (Or.inl ⟨p', l', m', a', v', rfl⟩)) - refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.delete.delRP I hKZ hPI R2 Q2 hy) (cdt.delete.nullR I R2 hy)) - (cdt.delete.capK I R2 hy.1 hyc)) ?_ - rintro ⟨r, s5, a2⟩ ⟨⟨⟨R5, Q5⟩, n5⟩, k5⟩ - try simp only [uncurry_apply_pair] at R5 Q5 n5 k5 ⊢ + refine WP.spec_bind (WP.spec_and (WP.spec_and (WP.spec_and (cdt.delete.delRP I hKZ hPI R2 Q2 hy) + (cdt.delete.armVsZ I hKZ R2 Z2.2 Z2.1 hy)) (cdt.delete.nullR I R2 hy)) (cdt.delete.capK I R2 hy.1 hyc)) ?_ + rintro ⟨r, s5, a2⟩ ⟨⟨⟨⟨R5, Q5⟩, Z5⟩, n5⟩, k5⟩ + try simp only [uncurry_apply_pair] at R5 Q5 Z5 n5 k5 ⊢ rcases r with v | e swap · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 (ArmQIAt.ofDelR R5 Q5) + exact (WP.spec_ok _).2 (ArmQIAt.ofDelR R5 Q5 Z5.1.toVs) simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] have hy0 : capA st s5 (slotIdx t layout.tcb.SLOT_EPT) = .Null := okinj ((capA_eq s5 _).symm.trans (n5 v rfl)) have hx5 : capA st s5 x = capA st s1 x := by rw [k5 x hxO hxy, k2.capA hxO] @@ -780,7 +796,8 @@ theorem tcb.decode.setEptQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len b have nn := (R5.sys.sys.stz.1.1.mdbS.lnk I.del.os hxO).2 unfold cdt.insert rw [capA_eq, bind_ok, hx5, hc] - refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLVE I.del.heap I.del.os hb5 R5.sys R5.sym + refine WP.spec_bind (WP.spec_and (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLVE I.del.heap I.del.os hb5 + R5.sys R5.sym R5.vc hxO hy.1 hxy (I.del.dcan _ hy) (hx5.trans hc) hy0 (Or.inl (tcb_slot_notBufS I.del.heap ht hi (by simp [layout.tcb.SLOT_EPT]))) ⟨slot, P.src, by rw [hsl5]; exact CovZ.tcbSlot I.del.heap ht hi⟩ hwf (fun h => by cases h) C @@ -789,17 +806,19 @@ theorem tcb.decode.setEptQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len b (fun h => by cases h) hwf nn)) (cdt.insert_with_cap.poolR I.del.os I.del.vr R5.jv.ksb R5.sys.sys.stz.1.1.mdbS hxO hy.1 hxy (I.del.dcan _ hy) (hx5.trans hc) (fun h => by cases h) hwf (fun _ _ h => by cases h) (fun _ _ h => by cases h) - (fun _ _ _ _ h => by cases h) hy0 Q5)) - fun s6 ⟨⟨h6, w6, _⟩, q6⟩ => ?_ + (by rw [← hx5.trans hc]; exact (Q5.1 x hxO).2) hy0 Q5)) + (cdt.insert_with_cap.armVsZ I.del.os R5.sys.sys.stz.1.1.mdbS hxO hy.1 hxy (I.del.dcan _ hy) (hx5.trans hc) + (fun h => by cases h) hwf (fun _ => FrUbP.fe C.fe) Z5)) + fun s6 ⟨⟨⟨h6, w6, _⟩, q6⟩, z6⟩ => ?_ exact (WP.spec_ok _).2 (ArmQIAt.ofPR ⟨h6.1, h6.2.1⟩ ((Cur0R.capw7 R5.jv.1.1 w6 fun _ h => h).bxi.elim fun A' hb => ⟨A', hb.blk⟩) - (fun _ => h6.2.2) q6) + (fun _ => h6.2.2) q6 z6.1.toVs) set_option maxHeartbeats 4000000 in /-- **TCB SetEPTRoot to `ArmQI ∧ TabKeepOrZero`** (MdbEptRL's `tcb.decode.setEptL` text; the ruled `hXE`). -/ theorem tcb.decode.setEptQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) @@ -817,7 +836,7 @@ theorem tcb.decode.setEptQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf body moved here, `syscall.decode_invocation.setEpt_armQI` its projection). -/ theorem syscall.decode_invocation.setEpt_armQIAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) @@ -826,13 +845,13 @@ theorem syscall.decode_invocation.setEpt_armQIAt (hA : P0.ArchTotal ar) {s : S} syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := syscall.decode_invocation.tcbG (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) a len blk call don fp buf + (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) a len blk call don fp buf fun _ _ e => tcb.decode.setEptQAt hA I hKZ hPI D P B Y hcap hXE (e.trans hl) /-- **The Thread arm of `decode_invocation` at SetEPTRoot to `ArmQI ∧ TabKeepOrZero`** (`hXE`). -/ theorem syscall.decode_invocation.setEpt_armQI (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) @@ -850,45 +869,78 @@ theorem syscall.decode_invocation.setEpt_armQI (hA : P0.ArchTotal ar) {s : S} /-! ## The IRQ-node slot's deletion with the pool carry -/ set_option maxHeartbeats 2000000 in -/-- **`delete_one` of an IRQ-node slot keeps `PoolR`** (module docstring; MdbIrqC's `cdt.delete_one.irqLK` -traversal over the field `LoopME.poolM` ∘ `LoopME.ciM` ∘ `DelS.fieldI`). -/ -theorem cdt.delete_one.irqP {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) - (hKZ : FinKZ st ar (L.ksb s0) Ty K) (hPI : PoolIdx st OS s0) - (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) (a : A) {i : U64} (hi : i.val < 5376) : - cdt.delete_one st ar s a (irqSlotA (L.ksb s0) i) ⦃ r => PoolR st OS s0 r.1 ⦄ := by +/-- (A64-S1A gen 31) **`delete_one` of an IRQ-node slot keeps any loop field** (the body of `irqP`, moved and +generalised over the field: `finXQG` / `finL` with the field's `fin` and `emp`). -/ +theorem cdt.delete_one.irqM {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} {Em : S → U64 → Prop} + {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (a : A) + {i : U64} (hi : i.val < 5376) + (hM : LoopME st ar OS (OSN OS (L.ksb s0)) + (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + (XQF st K Vc (OSN OS (L.ksb s0)) H.scs H.tcbs Ty (L.ksb s0)) Zr Em M) (m : M s) : + cdt.delete_one st ar s a (irqSlotA (L.ksb s0) i) ⦃ r => M r.1 ⦄ := by have hS : P0.StoreTotal st := L.total have E := I.del - have B := R.sys have h := R.jv have hx := E.irq.1 i hi - have hkw : (L.ksb s0).val + 788736 ≤ 2 ^ 64 := by rw [← R.jv.ksb]; exact B.ly.ksw - have hM := LoopME.poolM E I.fin I.tyk hKZ hkw hPI - (LoopME.ciM (ApP.null s0) (ApP.zombie s0) E.arch E.os E.sca E.vc E.dom E.dcan E.vr I.fin I.tyk E.wu E.irq - E.irqSt (E.fieldI (Cs := Cs) (Ac := Ac) (ia := ia) (ie := ie) I.fin I.tyk I.kl s - (L.idleW s) (L.mem s (scA (L.idleW s)))) fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) - (fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) fun _ m => m.2 unfold cdt.delete_one obtain ⟨c, hc⟩ := DPF.spec_tot (P0.obj.Slot.cap.p0 st (irqSlotA (L.ksb s0) i) s hS) rw [hc, bind_ok] have hnt : IrqNt c := R.irq i hi c hc refine WP.spec_bind (spec_eqv (P0.capability.Cap.is_null.p0 c)) fun bn hbn => ?_ split - · exact (WP.spec_ok _).2 Q + · exact (WP.spec_ok _).2 m have hnI : ∀ j, c ≠ .IrqHandler j := by rcases hnt with ⟨n, b0, b1, b2, rfl⟩ | rfl <;> intro j e <;> cases e refine WP.spec_bind (spec_eqv (P0.cdt.is_final_capability_with_cap.p0 st s _ c hS)) fun fin hfe => ?_ rw [← fc_eq_fco ar s a fin hnI] refine WP.spec_bind (WP.spec_and (WP.spec_and (finXQG E.arch E.os E.sca E.vc E.vr I.fin I.tyk h E.irq R.irq R.ty - h.ksb hx hc (zq_irqNt hnt) a fin) (hM.fin s a _ c fin h - ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨R.sym, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt rfl rfl).idSc B.sc⟩, - CtOff.ks h.ksb.symm B.ct⟩, FrOff.ks h.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, Q.1⟩, Q.2⟩ - hx hc ⟨zq_irqNt hnt, R.ty, R.irq⟩ hfe.1)) + h.ksb hx hc (zq_irqNt hnt) a fin) (hM.fin s a _ c fin h m hx hc ⟨zq_irqNt hnt, R.ty, R.irq⟩ hfe.1)) (finL E.arch E.os E.sca E.vc h hx hc (zl_irqNt hnt) a fin)) ?_ rintro ⟨⟨rem, cl⟩, s2, a2⟩ ⟨⟨⟨-, h2, -⟩, m2, -, e2⟩, e0, -⟩ simp only [Prod.mk.injEq] at e0 obtain ⟨rfl, rfl⟩ := e0 simp only at h2 m2 e2 ⊢ - exact WP.spec_mono (hM.emp s2 a2 _ _ h2 m2 hx (Or.inl rfl) (e2 rfl)) fun _ m => ⟨m.1.2, m.2⟩ + exact hM.emp s2 a2 _ _ h2 m2 hx (Or.inl rfl) (e2 rfl) + +set_option maxHeartbeats 2000000 in +/-- **`delete_one` of an IRQ-node slot keeps `PoolR`** (module docstring; MdbIrqC's `cdt.delete_one.irqLK` +traversal over the field `LoopME.poolM` ∘ `LoopME.ciM` ∘ `DelS.fieldI`; A64-S1A gen 31: by `irqM`). -/ +theorem cdt.delete_one.irqP {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) (a : A) {i : U64} (hi : i.val < 5376) : + cdt.delete_one st ar s a (irqSlotA (L.ksb s0) i) ⦃ r => PoolR st OS s0 r.1 ⦄ := by + have E := I.del + have B := R.sys + have h := R.jv + have hkw : (L.ksb s0).val + 788736 ≤ 2 ^ 64 := by rw [← R.jv.ksb]; exact B.ly.ksw + have hM := LoopME.poolM E I.fin I.tyk hKZ hkw hPI + (LoopME.ciM (ApP.null s0) (ApP.zombie s0) E.arch E.os E.sca E.vc E.dom E.dcan E.vr I.fin I.tyk E.wu E.irq + E.irqSt (E.fieldI (Cs := Cs) (Ac := Ac) (ia := ia) (ie := ie) I.fin I.tyk I.kl s + (L.idleW s) (L.mem s (scA (L.idleW s)))) fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + (fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) fun _ m => m.2 + exact WP.spec_mono (cdt.delete_one.irqM I R a hi hM + ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨R.sym, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt rfl rfl).idSc B.sc⟩, + CtOff.ks h.ksb.symm B.ct⟩, FrOff.ks h.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, Q.1⟩, Q.2⟩) fun _ m => ⟨m.1.2, m.2⟩ + +set_option maxHeartbeats 2000000 in +/-- (A64-S1A gen 31) **`delete_one` of an IRQ-node slot is a zero step at every placement, carrying `FrC`** +(`irqM` over MdbDelVsZ's field `LoopME.vzM` ∘ `LoopME.ciM` (`FrUbA`) ∘ `DelS.fieldI`, as `cdt.delete.armVsZG`). -/ +theorem cdt.delete_one.irqZ {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (a : A) {i : U64} + (hi : i.val < 5376) (hF : FrC st OS s0 s) (hZ : ArmVsZ st H OS Vc s0 s) : + cdt.delete_one st ar s a (irqSlotA (L.ksb s0) i) ⦃ r => ArmVsZ st H OS Vc s0 r.1 ∧ FrC st OS s0 r.1 ⦄ := by + have E := I.del + have B := R.sys + have h := R.jv + have hM := LoopME.vzM E I.fin hKZ (fun _ h1 m1 => PlG.plW E h1 m1.1.1.1.1.1.1.1.1.1.1.1.1.2 m1.2) + (LoopME.ciM (FrUbA.null _) (FrUbA.zombie _) E.arch E.os E.sca E.vc E.dom E.dcan E.vr I.fin I.tyk E.wu E.irq + E.irqSt (E.fieldI (Cs := Cs) (Ac := Ac) (ia := ia) (ie := ie) I.fin I.tyk I.kl s + (L.idleW s) (L.mem s (scA (L.idleW s)))) fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS + exact WP.spec_mono (WP.spec_and (cdt.delete_one.irqLK I R a hi) (cdt.delete_one.irqM I R a hi hM + ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨R.sym, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt rfl rfl).idSc B.sc⟩, + CtOff.ks h.ksb.symm B.ct⟩, FrOff.ks h.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, hF.ci⟩, hZ.toG⟩)) + fun _ ⟨⟨_, j, _⟩, m⟩ => ⟨ArmVsZ.ofG j.ksb m.2, FrC.of_ci m.1.2⟩ /-! ## IRQ handler ClearIRQHandler / SetIRQHandler -/ @@ -897,7 +949,7 @@ set_option maxHeartbeats 2000000 in moved here, `interrupt.decode_irq_handler.clearQ` its projection). -/ theorem interrupt.decode_irq_handler.clearQAt {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl irq : U64} (hl : lbl = fl4_abi.label.IRQClearIRQHandler) @@ -912,20 +964,21 @@ theorem interrupt.decode_irq_handler.clearQAt {s : S} {cap : capability.Cap} rw [if_neg (by simp [fl4_abi.label.IRQAckIRQ, fl4_abi.label.IRQClearIRQHandler]), if_neg (by simp [fl4_abi.label.IRQSetIRQHandler, fl4_abi.label.IRQClearIRQHandler]), if_pos rfl, ← er] refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y (Stalled.refl0 D) (DF.refl s) (DS.refl s) (VsKeep.refl s)) - fun s1 ⟨⟨_, R1⟩, Q1⟩ => ?_ + fun s1 ⟨⟨_, R1⟩, Q1, Z1⟩ => ?_ refine WP.spec_bind (interrupt.irq_slot.val s1 irq) fun isl e => ?_ rw [e, R1.jv.ksb] - refine WP.spec_bind (WP.spec_and (cdt.delete_one.irqLK I R1 a hi) (cdt.delete_one.irqP I hKZ hPI R1 Q1 a hi)) ?_ - rintro ⟨s2, a2⟩ ⟨⟨B2, j2, v2, -⟩, Q2⟩ + refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.delete_one.irqLK I R1 a hi) + (cdt.delete_one.irqP I hKZ hPI R1 Q1 a hi)) (cdt.delete_one.irqZ I hKZ R1 a hi Z1.2 Z1.1)) ?_ + rintro ⟨s2, a2⟩ ⟨⟨⟨B2, j2, v2, -⟩, Q2⟩, Z2⟩ obtain ⟨Ac2, hb2⟩ := j2.1.parts - exact (WP.spec_ok _).2 (ArmQIAt.ofPR B2 ⟨Ac2, hb2.blk⟩ (fun _ => v2) Q2) + exact (WP.spec_ok _).2 (ArmQIAt.ofPR B2 ⟨Ac2, hb2.blk⟩ (fun _ => v2) Q2 Z2.1.toVs) set_option maxHeartbeats 2000000 in /-- **IRQ handler `ClearIRQHandler` to `ArmQI ∧ TabKeepOrZero`** (MdbIrqC's `interrupt.decode_irq_handler.clearL` text: the restart, `irqLK` ∧ `irqP`). -/ theorem interrupt.decode_irq_handler.clearQ {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl irq : U64} (hl : lbl = fl4_abi.label.IRQClearIRQHandler) @@ -942,7 +995,7 @@ theorem interrupt.decode_irq_handler.clearQ {s : S} {cap : capability.Cap} /-- (gen 147, ruling (a)) **`syscall.decode_invocation.irqClear_armQI` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, `syscall.decode_invocation.irqClear_armQI` its projection). -/ theorem syscall.decode_invocation.irqClear_armQIAt {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} - {irq : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Ty K) + {irq : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.IrqHandler irq) 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) @@ -958,7 +1011,7 @@ theorem syscall.decode_invocation.irqClear_armQIAt {s : S} {extra : Aeneas.Std.A /-- **The IrqHandler arm of `decode_invocation` at ClearIRQHandler to `ArmQI ∧ TabKeepOrZero`** (`hi`). -/ theorem syscall.decode_invocation.irqClear_armQI {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} - {irq : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Ty K) + {irq : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.IrqHandler irq) 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) @@ -976,16 +1029,16 @@ theorem syscall.decode_invocation.irqClear_armQI {s : S} {extra : Aeneas.Std.Arr set_option hygiene false in /-- An error leaf at the decode's state. -/ local macro "sleafQ" : tactic => `(tactic| first - | exact (WP.spec_ok _).2 (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) + | exact (WP.spec_ok _).2 (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) | (simp only [error.invalid_cap, error.truncated, bind_ok] - exact (WP.spec_ok _).2 (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)))) + exact (WP.spec_ok _).2 (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)))) set_option maxHeartbeats 4000000 in /-- (gen 147, ruling (a)) **`interrupt.decode_irq_handler.setQ` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, `interrupt.decode_irq_handler.setQ` its projection). -/ theorem interrupt.decode_irq_handler.setQAt {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl irq : U64} (hl : lbl = fl4_abi.label.IRQSetIRQHandler) @@ -1022,12 +1075,13 @@ theorem interrupt.decode_irq_handler.setQAt {s : S} {cap : capability.Cap} have q1 := h1.bxi.1.choose_spec.choose_spec have hct : L.curW s ∈ H.tcbs := q1.curT refine WP.spec_bind (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 (DF.refl s) (DS.refl s) (VsKeep.refl s)) - (tcb.restart_caller.sts (q1.nodes _ q1.cur) (q1.tcbs _ hct))) fun s1 ⟨⟨⟨_, R1⟩, Q1⟩, w1⟩ => ?_ + (tcb.restart_caller.sts (q1.nodes _ q1.cur) (q1.tcbs _ hct))) fun s1 ⟨⟨⟨_, R1⟩, Q1, Z1⟩, w1⟩ => ?_ have k1 : OSKeep st OS s s1 := stt_osk P.os q1 hct w1 refine WP.spec_bind (interrupt.irq_slot.val s1 irq) fun isl e => ?_ rw [e, R1.jv.ksb] - refine WP.spec_bind (WP.spec_and (cdt.delete_one.irqLK I R1 a hi) (cdt.delete_one.irqP I hKZ hPI R1 Q1 a hi)) ?_ - rintro ⟨s2, a2⟩ ⟨⟨⟨B2, Y2⟩, j2, v2, n2, k2⟩, Q2⟩ + refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.delete_one.irqLK I R1 a hi) + (cdt.delete_one.irqP I hKZ hPI R1 Q1 a hi)) (cdt.delete_one.irqZ I hKZ R1 a hi Z1.2 Z1.1)) ?_ + rintro ⟨s2, a2⟩ ⟨⟨⟨⟨B2, Y2⟩, j2, v2, n2, k2⟩, Q2⟩, Z2⟩ have hx2 : capA st s2 x = .Notification n b0 b1 b2 := by rw [k2 x hxO hxI, k1.capA hxO, hc] have hy : irqSlotA (L.ksb s) irq ∈ OS := I.del.irq.1 irq hi have hxy : x ≠ irqSlotA (L.ksb s) irq := fun e' => hxI ⟨irq, hi, e'⟩ @@ -1041,7 +1095,8 @@ theorem interrupt.decode_irq_handler.setQAt {s : S} {cap : capability.Cap} try dsimp only try simp only [uncurry_apply_pair] rw [capA_eq, bind_ok, hx2] - refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLVN I.del.heap I.del.os hb2 B2 Y2 v2 hxO hy + refine WP.spec_bind (WP.spec_and (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLVN I.del.heap I.del.os hb2 B2 Y2 + v2 hxO hy hxy (P.os.canon P.win hy) hx2 n2 (Or.inl hBE.1) (fun hI => by rw [j2.ksb] at hI @@ -1049,19 +1104,21 @@ theorem interrupt.decode_irq_handler.setQAt {s : S} {cap : capability.Cap} (fun h => by cases h) C (Or.inl hBE.2)) (cdt.insert_with_cap.lrF I.del.os (LR.self s2) hxO hy hxy (P.os.canon P.win hy) hx2 (fun h => by cases h) hwf nn)) (cdt.insert_with_cap.poolR I.del.os I.del.vr j2.ksb B2.sys.stz.1.1.mdbS hxO hy hxy (P.os.canon P.win hy) hx2 - (fun h => by cases h) hwf (fun _ _ h => by cases h) (fun _ _ h => by cases h) (fun _ _ _ _ h => by cases h) - n2 Q2)) - fun s3 ⟨⟨h3, w3, _⟩, q3⟩ => ?_ + (fun h => by cases h) hwf (fun _ _ h => by cases h) (fun _ _ h => by cases h) + (by rw [← hx2]; exact (Q2.1 x hxO).2) n2 Q2)) + (cdt.insert_with_cap.armVsZ I.del.os B2.sys.stz.1.1.mdbS hxO hy hxy (P.os.canon P.win hy) hx2 + (fun h => by cases h) hwf (fun _ => FrUbP.fe C.fe) Z2)) + fun s3 ⟨⟨⟨h3, w3, _⟩, q3⟩, z3⟩ => ?_ exact (WP.spec_ok _).2 (ArmQIAt.ofPR ⟨h3.1, h3.2.1⟩ ((Cur0R.capw7 j2.1.1 w3 fun _ h => h).bxi.elim fun A' hb => ⟨A', hb.blk⟩) - (fun _ => h3.2.2) q3) + (fun _ => h3.2.2) q3 z3.1.toVs) set_option maxHeartbeats 4000000 in /-- **IRQ handler `SetIRQHandler` to `ArmQI ∧ TabKeepOrZero`** (MdbIrqH's `interrupt.decode_irq_handler.setL` text; `hi`, `hSC`). -/ theorem interrupt.decode_irq_handler.setQ {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) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl irq : U64} (hl : lbl = fl4_abi.label.IRQSetIRQHandler) @@ -1078,7 +1135,7 @@ theorem interrupt.decode_irq_handler.setQ {s : S} {cap : capability.Cap} /-- (gen 147, ruling (a)) **`syscall.decode_invocation.irqSet_armQI` at the decode's own `(H, OS)`** (`ArmQIAt`; the body moved here, `syscall.decode_invocation.irqSet_armQI` its projection). -/ theorem syscall.decode_invocation.irqSet_armQIAt {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} - {irq : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Ty K) + {irq : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.IrqHandler irq) 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) @@ -1095,7 +1152,7 @@ theorem syscall.decode_invocation.irqSet_armQIAt {s : S} {extra : Aeneas.Std.Arr /-- **The IrqHandler arm of `decode_invocation` at SetIRQHandler to `ArmQI ∧ TabKeepOrZero`** (`hi`, `hSC`). -/ theorem syscall.decode_invocation.irqSet_armQI {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} - {irq : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Ty K) + {irq : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.IrqHandler irq) 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) diff --git a/proofs/Fl4ProofsA64/P1/MdbTmoArmQ.lean b/proofs/Fl4ProofsA64/P1/MdbTmoArmQ.lean index 894e4c64b..6de9901ec 100644 --- a/proofs/Fl4ProofsA64/P1/MdbTmoArmQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbTmoArmQ.lean @@ -41,13 +41,13 @@ set_option hygiene false in /-- An error leaf at the stalled state (`SysL.df`, `ArmQIAt.ofStall`; MdbTcbArmQ's `qleaf`). -/ local macro "qleafT" : tactic => `(tactic| first | exact (WP.spec_ok _).2 (ArmQIAt.ofStall I h1 d1 ds1 vk1 - (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1)) + (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) (ArmVsK.ofDFI I D P B d1)) | (simp only [error.invalid_cap, error.truncated, error.illegal, bind_ok, core.result.Result.Insts.CoreOpsTry.branch, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] exact (WP.spec_ok _).2 (ArmQIAt.ofStall I h1 d1 ds1 vk1 - (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1)))) + (SysL.df (Ko := ∅) P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) B Y d1) (ArmVsK.ofDFI I D P B d1)))) local macro "lbl_neT" : tactic => `(tactic| exact lbl_ne_of_val (by simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, @@ -64,7 +64,7 @@ set_option maxHeartbeats 2000000 in body moved here, `tcb.decode_set_timeout_endpoint.armQI` its projection). -/ theorem tcb.decode_set_timeout_endpoint.armQIAt {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -90,15 +90,16 @@ theorem tcb.decode_set_timeout_endpoint.armQIAt {s s1 : S} {a1 : A} {t len buf : rename_i hbt have hfh : capA st s1 x0 ≠ .Null → TcbK (capA st s1 x0) ∧ CapRt.EncWf (capA st s1 x0) := fun hn => ⟨vfh_tk (hbt ▸ hb.1) hn, CapRt.decodeF_encWf _ _⟩ - refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2⟩ => ?_ - refine WP.spec_mono (P₀ := fun r => DelR st H Cs OS Vc Ub Ac Ty ia ie s r.2.1 ∧ PoolR st OS s r.2.1) ?_ - fun r hr => ArmQIAt.ofDelR hr.1 hr.2 + refine WP.spec_bind (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) fun s2 ⟨⟨_, R2⟩, Q2, Z2⟩ => ?_ + refine WP.spec_mono (P₀ := fun r => DelR st H Cs OS Vc Ub Ac Ty ia ie s r.2.1 ∧ PoolR st OS s r.2.1 ∧ + ArmVsZ st H OS Vc s r.2.1 ∧ FrC st OS s r.2.1) ?_ + fun r hr => ArmQIAt.ofDelR hr.1 hr.2.1 hr.2.2.1.toVs unfold tcb.thread_control_caps simp only [lift, bind_ok, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_SPACE, tcb.UPDATE_IPC_BUFFER] simp - exact qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) - (Q2 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x) - (tcb.install_tcb_cap.delRP I hKZ hPI R2 Q2 ht (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER]) + exact qq_bind (Q1 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) + (Q2 := fun x => DelR st H Cs OS Vc Ub Ac Ty ia ie s x ∧ PoolR st OS s x ∧ ArmVsZ st H OS Vc s x ∧ FrC st OS s x) + (tcb.install_tcb_cap.delRP I hKZ hPI R2 Q2 Z2 ht (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER]) (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER]) P.src (fun _ => hO0) hfh (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER])) (fun s3 a3 R3 => (WP.spec_ok _).2 R3) fun _ h => h @@ -107,7 +108,7 @@ set_option maxHeartbeats 2000000 in /-- **SetTimeoutEndpoint after the stall to `ArmQI ∧ TabKeepOrZero`** (module docstring). -/ theorem tcb.decode_set_timeout_endpoint.armQI {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) @@ -126,7 +127,7 @@ set_option maxHeartbeats 2000000 in `tcb.decode.setTmoQ` its projection). -/ theorem tcb.decode.setTmoQAt (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBSetTimeoutEndpoint) : @@ -146,7 +147,7 @@ set_option maxHeartbeats 2000000 in /-- **TCB SetTimeoutEndpoint to `ArmQI ∧ TabKeepOrZero`** (MdbTcbArmQ's `setSpaceQ` text, one label further). -/ theorem tcb.decode.setTmoQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hl : lbl = fl4_abi.label.TCBSetTimeoutEndpoint) : @@ -163,7 +164,7 @@ theorem tcb.decode.setTmoQ (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf body moved here, `syscall.decode_invocation.setTmo_armQI` its projection). -/ theorem syscall.decode_invocation.setTmo_armQIAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetTimeoutEndpoint) (len : U64) @@ -171,13 +172,13 @@ theorem syscall.decode_invocation.setTmo_armQIAt (hA : P0.ArchTotal ar) {s : S} syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := syscall.decode_invocation.tcbG (Φ := fun x => ArmQIAt st H Cs OS Vc ia ie s x ∧ TabKeepOrZero st s x) - (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s)) a len blk call don fp buf + (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) a len blk call don fp buf fun _ _ e => tcb.decode.setTmoQAt hA I hKZ hPI D P B Y (e.trans hl) /-- **The Thread arm of `decode_invocation` at SetTimeoutEndpoint to `ArmQI ∧ TabKeepOrZero`.** -/ theorem syscall.decode_invocation.setTmo_armQI (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetTimeoutEndpoint) (len : U64) diff --git a/proofs/Fl4ProofsA64/P1/MdbVcArmQ.lean b/proofs/Fl4ProofsA64/P1/MdbVcArmQ.lean index 189cb6683..082d8662d 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVcArmQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVcArmQ.lean @@ -12,6 +12,9 @@ invoked VCPU) closed through MdbRunF's `RunW` (`dfbv_runW`), MdbLiveX's `SysL.df * Not here: SetTCB (writes the target thread's bound-VCPU word, offset 3664, outside MdbRunF's `RunW`), ReadState / WriteState (owed, gen 155). +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ArmQIAt.ofDFBv`, `ackVppi_armQIAt` and `vcWr_armQIAt` also post +`ArmVsK` (last conjunct; MdbRunQ's `ofRunW0`). + Named premises: none. Case facts: none new (`DelIn`, `HeapKsOff`; `vc ∈ Vc` by `DelIn.vcc` at the invoked slot). -/ import Fl4ProofsA64.P1.MdbRunQ @@ -30,12 +33,12 @@ namespace W7 namespace R namespace ST -variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} +variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} {sd : S} variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} /-- **A `DFB c ∅ (VcW Vc)` word is a `RunW` word.** -/ theorem dfbv_runW {s0 : S} {b : U64} - (h : DfW st H.tcbs Cs H.frame H.scBits ∅ s0 b ∨ VcW Vc b) : RunW st H Cs Vc OS s0 b := by + (h : DfW st H.tcbs Cs H.frame H.scBits ∅ s0 b ∨ VcW Vc b) : RunW st H Cs Vc OS sd s0 b := by rcases h with ((⟨y, hy, K, h1, h2, h3, h4, e⟩ | hn | hs | ⟨c, hc, -⟩ | ⟨e, he, -⟩) | ⟨o, ho, -⟩) | hv · exact Or.inl (Or.inl (Or.inl (Or.inl ⟨y, hy, K, h1, h2, h3, h4, e⟩))) · exact Or.inl (Or.inl (Or.inl (Or.inr (Or.inl hn)))) @@ -52,11 +55,11 @@ theorem ArmQIAt.ofDFBv {s s' : S} {cap : capability.Cap} {slot : U64} {extra : A (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (d : DFB st H Cs (L.curW s) ∅ (VcW Vc) s s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' := by have hS := SysL.dfB P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) (fun b hb => (I.vty.w hb).2) (fun x hx b h1 h2 hv => I.del.vc.os b hv ⟨x, hx, h1, h2⟩) B Y d have A' := ArmQIAt.ofRunW0 I B hks P.core0 D.bxi.blk (d.w.mono fun b hb => dfbv_runW hb) hS hb - exact ⟨A'.1, A'.2.toDel⟩ + exact ⟨A'.1, A'.2.1.toDel, A'.2.2⟩ set_option maxHeartbeats 2000000 in /-- **AckVPPI is a VCPU-word `DFB` step keeping `BlkOK`** (module docstring). -/ @@ -280,8 +283,8 @@ local macro "lbl_neV" : tactic => `(tactic| exact lbl_ne_of_val (by fl4_abi.label.ARMVCPUWriteReg, fl4_abi.label.ARMVCPUAckVPPI, fl4_abi.label.ARMVCPUReadState, fl4_abi.label.ARMVCPUWriteState, fl4_abi.label.ARMVCPURun])) -/-- **The `Vcpu` arm of `decode_invocation` at AckVPPI to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem syscall.decode_invocation.ackVppi_armQIAt (hA : P0.ArchTotal ar) {s : S} +/-- **`ackVppi_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.ackVppi_armSAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) 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) @@ -289,7 +292,7 @@ theorem syscall.decode_invocation.ackVppi_armQIAt (hA : P0.ArchTotal ar) {s : S} (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPUAckVPPI) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by have hvc : vc ∈ Vc := I.vcc slot P.src vc (by rw [capA_eq] at hcap; exact okinj hcap) unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ @@ -302,10 +305,25 @@ theorem syscall.decode_invocation.ackVppi_armQIAt (hA : P0.ArchTotal ar) {s : S} fun r d => by obtain ⟨_, s', a'⟩ := r obtain ⟨Ac', hb'⟩ := d.2 - exact ArmQIAt.ofDFBv I D P B Y hks d.1 hb' + have arm := ArmQIAt.ofDFBv I D P B Y hks d.1 hb' + exact ⟨arm.1, arm.2.1, arm.2.2, DFB.osk P.os D.bxi.blk + (fun x hx b h1 h2 hv => I.del.vc.os b hv ⟨x, hx, h1, h2⟩) d.1⟩ -/-- **The `Vcpu` arm at WriteReg / InjectIRQ to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem syscall.decode_invocation.vcWr_armQIAt (hA : P0.ArchTotal ar) {s : S} +/-- **The `Vcpu` arm of `decode_invocation` at AckVPPI to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem syscall.decode_invocation.ackVppi_armQIAt (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Vcpu vc)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPUAckVPPI) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) 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' ⦄ := + WP.spec_mono (syscall.decode_invocation.ackVppi_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ + +/-- **`vcWr_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.vcWr_armSAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) 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) @@ -313,16 +331,18 @@ theorem syscall.decode_invocation.vcWr_armQIAt (hA : P0.ArchTotal ar) {s : S} (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPUWriteReg ∨ lbl = fl4_abi.label.ARMVCPUInjectIRQ) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by have hvc : vc ∈ Vc := I.vcc slot P.src vc (by rw [capA_eq] at hcap; exact okinj hcap) have hw : VcWords H.omega H.frame vc := (I.vty.obj vc hvc).1 have hWv : ∀ b, VcW Vc b → b ∈ H.omega ∧ b ∉ H.frame := fun b hb => (I.vty.w hb).2 have cl : ∀ (r : (core.result.Result Unit error.Exc) × S × A), (DFB st H Cs (L.curW s) ∅ (VcW Vc) s r.2.1 ∧ ∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' r.2.1) → - ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 := fun r d => by + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ + OSKeep st OS s r.2.1 := fun r d => by obtain ⟨Ac', hb'⟩ := d.2 - exact ArmQIAt.ofDFBv I D P B Y hks d.1 hb' + have arm := ArmQIAt.ofDFBv I D P B Y hks d.1 hb' + exact ⟨arm.1, arm.2.1, arm.2.2, DFB.osk P.os D.bxi.blk (fun x hx b h1 h2 hv => I.del.vc.os b hv ⟨x, hx, h1, h2⟩) d.1⟩ unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ unfold vcpu.decode @@ -341,6 +361,19 @@ theorem syscall.decode_invocation.vcWr_armQIAt (hA : P0.ArchTotal ar) {s : S} obtain ⟨_, s', a'⟩ := r exact cl _ d +/-- **The `Vcpu` arm at WriteReg / InjectIRQ to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem syscall.decode_invocation.vcWr_armQIAt (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Vcpu vc)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPUWriteReg ∨ lbl = fl4_abi.label.ARMVCPUInjectIRQ) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) 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' ⦄ := + WP.spec_mono (syscall.decode_invocation.vcWr_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ + end ST end R end W7 diff --git a/proofs/Fl4ProofsA64/P1/MdbVcStQ.lean b/proofs/Fl4ProofsA64/P1/MdbVcStQ.lean index 4dac028d3..e4385e5b4 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVcStQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVcStQ.lean @@ -19,6 +19,9 @@ the bound thread's registers (WriteState, `DfW` words through MdbRegL's `set_reg * (gen 164, main #139 re-extraction after #130) WriteState: `read_vgic_frame`'s `none` (error) / `some` (stall, restart, write) arms replace `validate_vgic_lrs`; `write_state_from_frame` takes the VGIC words. +(A64-S1A gen 40, Architect ruling for gen 40, R3) `ArmQIAt.ofDFBf` and `vcSt_armQIAt` also post `ArmVsK` (last +conjunct; MdbRunQ's `ofRunW0`). + Named premises: none. Case facts: none new (`DelIn`, `HeapKsOff`; `vc ∈ Vc` by `DelIn.vcc` at the invoked slot; the extra slot in `OS` by `SysPlace.ext`). -/ @@ -38,12 +41,14 @@ namespace W7 namespace R namespace ST -variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} +variable {OS Vc Ub Pt : Set U64} {ia ie : Nat} {sd : S} variable {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} -/-- **A VCPU word or a frame-object word** (module docstring). -/ -def VFW (H : Heap) (Vc OS : Set U64) (b : U64) : Prop := - VcW Vc b ∨ FrBw H OS b +variable (st) in +/-- **A VCPU word or a frame-object word** (module docstring; A64-S1A gen 30: the frame word also an `FrCw` word at +the decode's state `sd`). -/ +def VFW (H : Heap) (Vc OS : Set U64) (sd : S) (b : U64) : Prop := + VcW Vc b ∨ (FrBw H OS b ∧ FrCw st OS sd b) /-- A `DFB` step over a smaller extra-word set. -/ theorem DFB.bw {c : U64} {Ko : Set Nat} {Bw Bw' : U64 → Prop} {s s' : S} (d : DFB st H Cs c Ko Bw s s') @@ -52,7 +57,7 @@ theorem DFB.bw {c : U64} {Ko : Set Nat} {Bw Bw' : U64 → Prop} {s s' : S} (d : /-- **A `DFB c ∅ VFW` word is a `RunW` word.** -/ theorem dfbf_runW {s0 : S} {b : U64} - (h : DfW st H.tcbs Cs H.frame H.scBits ∅ s0 b ∨ VFW H Vc OS b) : RunW st H Cs Vc OS s0 b := by + (h : DfW st H.tcbs Cs H.frame H.scBits ∅ s0 b ∨ VFW st H Vc OS sd b) : RunW st H Cs Vc OS sd s0 b := by rcases h with h | hv | hf · exact dfbv_runW (Or.inl h) · exact dfbv_runW (Or.inr hv) @@ -63,15 +68,15 @@ theorem ArmQIAt.ofDFBf {s s' : S} {cap : capability.Cap} {slot : U64} {extra : A {Ac' : Set U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) - (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (d : DFB st H Cs (L.curW s) ∅ (VFW H Vc OS) s s') + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (d : DFB st H Cs (L.curW s) ∅ (VFW st H Vc OS s) s s') (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' := by have hS := SysL.dfB P D.bxi D.run (fun _ h => absurd h (Set.notMem_empty _)) - (fun b hb => hb.elim (fun hv => (I.vty.w hv).2) fun hf => hf.1) - (fun x hx b h1 h2 hb => hb.elim (fun hv => I.del.vc.os b hv ⟨x, hx, h1, h2⟩) fun hf => hf.2.2 x hx ⟨h1, h2⟩) + (fun b hb => hb.elim (fun hv => (I.vty.w hv).2) fun hf => hf.1.1) + (fun x hx b h1 h2 hb => hb.elim (fun hv => I.del.vc.os b hv ⟨x, hx, h1, h2⟩) fun hf => hf.1.2.2 x hx ⟨h1, h2⟩) B Y d have A' := ArmQIAt.ofRunW0 I B hks P.core0 D.bxi.blk (d.w.mono fun b hb => dfbf_runW hb) hS hb - exact ⟨A'.1, A'.2.toDel⟩ + exact ⟨A'.1, A'.2.1.toDel, A'.2.2⟩ /-- **The frame of an `OS` slot's non-device frame cap at a checked offset is 128 `FrBw` words** (module docstring). -/ theorem frU_of {s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL st H Cs OS ia ie s) {x : U64} @@ -79,50 +84,28 @@ theorem frU_of {s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL st H (hcap : capA st s x = .Frame ptr size rights false x1 x2 x3 x4) (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) : - FrU {b | FrBw H OS b} (wa ptr off) := by + 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 hFo := (B.fo _ hx ptr size rights x1 x2 x3 x4 hcap bits hbits).1 - have hb64 : bits.val < 64 ∧ 12 ≤ bits.val := by + have hb64 : 12 ≤ bits.val := by cases size <;> simp only [capability.FrameSize.bits] at hbits <;> rw [← okinj hbits] <;> simp - have hszv : sz.val = 2 ^ bits.val := by - have := shl1_val hb64.1 - rw [hsz, WP.spec_ok] at this - exact this - have ho : off.val % 64 = 0 := by - have e := congrArg UScalar.val h63 - rw [UScalar.val_and, show (63#u64).val = 2 ^ 6 - 1 from rfl, Nat.and_two_pow_sub_one_eq_mod] at e - 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 hpo : (wa ptr off).val = ptr.val + off.val := by - simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega intro i hi - have hv : (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val = ptr.val + off.val + 8 * i.val := by - have : (core.num.U64.wrapping_mul i 8#u64).val = i.val * 8 := by - simp [core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits]; omega - rw [core.num.U64.wrapping_add_val_eq, this, hpo] - simp [U64.size_def, U64.numBits]; omega - have hal' : Aligned (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)) := by - unfold Aligned at hal ⊢; rw [hv]; rw [hpo] at hal; omega - have hin : ptr.val ≤ (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val ∧ - (wa (wa ptr off) (core.num.U64.wrapping_mul i 8#u64)).val < ptr.val + 2 ^ bits.val := by - rw [hv]; omega - show FrBw H OS _ - refine And.intro (frame_word hH hp hal' hin) (And.intro ⟨ptr, bits.val, hp, hb64.2, hin⟩ fun z hz g => ?_) + 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 => ?_)) + ⟨x, hx, ptr, size, rights, x1, x2, x3, x4, bits, hcap, hbits, hin⟩ rcases hFo z hz with g' | g' <;> omega /-- **`read_state_to_frame` into `FrBw` words from a `VQ` state** (module docstring). -/ theorem VQ.readFr (hA : P0.ArchTotal ar) {c : U64} {s x : S} (p : VQ st H Cs Vc Ac c s x) {vc f mask : U64} - (a : A) (hfr : FrU {b | FrBw H OS b} f) : - vcpu.read_state_to_frame st ar x a vc f mask ⦃ x' => DFB st H Cs c ∅ (VFW H Vc OS) s x' ∧ + (a : A) (hfr : FrU {b | FrBw H OS b ∧ FrCw st OS s b} f) : + vcpu.read_state_to_frame st ar x a vc f mask ⦃ x' => DFB st H Cs c ∅ (VFW st H Vc OS s) s x' ∧ ∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' x' ⦄ := - WP.spec_mono (vcpu.read_state_to_frame.fw hA x a vc f mask hfr fun b hb => hb.1.1.1) fun x' w => + WP.spec_mono (vcpu.read_state_to_frame.fw hA x a vc f mask hfr fun b hb => hb.1.1.1.1) fun x' w => ⟨(DFB.bw p.2 fun _ h => Or.inl h).trans - (DFB.bw (DFB.ofBw (LvC.of_blk p.1) w fun b hb => hb.1) fun _ h => Or.inr h), - Ac, (blk_of_capw p.1 w fun b hb => Or.inr hb.1).1⟩ + (DFB.bw (DFB.ofBw (LvC.of_blk p.1) w fun b hb => hb.1.1) fun _ h => Or.inr h), + Ac, (blk_of_capw p.1 w fun b hb => Or.inr hb.1.1).1⟩ /-! ## WriteState -/ @@ -207,14 +190,14 @@ theorem vcpu.decode_state_transfer.vq (hA : P0.ArchTotal ar) {s : S} {vc slot : (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (hvc : vc ∈ Vc) (a : A) (len buf : U64) (rd : Bool) : vcpu.decode_state_transfer st ar s a vc len buf extra rd ⦃ r => - DFB st H Cs (L.curW s) ∅ (VFW H Vc OS) s r.2.1 ∧ + DFB st H Cs (L.curW s) ∅ (VFW st H Vc OS s) s r.2.1 ∧ ∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' r.2.1 ⦄ := by have hS : P0.StoreTotal st := L.total have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT have hw : VcWords H.omega H.frame vc := (I.vty.obj vc hvc).1 have hT0 := (I.vty.obj vc hvc).2.1 have hWv : ∀ b, VcW Vc b → b ∈ H.omega ∧ b ∉ H.frame := fun b hb => (I.vty.w hb).2 - have E0 : DFB st H Cs (L.curW s) ∅ (VFW H Vc OS) s s ∧ + have E0 : DFB st H Cs (L.curW s) ∅ (VFW st H Vc OS s) s s ∧ ∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s := ⟨DFB.ofDF (DF.refl _), Ac, D.bxi.blk⟩ unfold vcpu.decode_state_transfer @@ -252,7 +235,7 @@ theorem vcpu.decode_state_transfer.vq (hA : P0.ArchTotal ar) {s : S} {vc slot : refine spec_ite (fun _ => by errT) (fun hlt => ?_) step as ⟨i6, hi6⟩ refine spec_ite (fun _ => by errT) (fun hsz => ?_) - have hfr : FrU {b | FrBw H OS b} (wa ptr off) := + have hfr : FrU {b | FrBw H OS b ∧ FrCw st OS s b} (wa ptr off) := frU_of I B hsl hc.symm eb es (by apply UScalar.eq_of_val_eq; simpa using ha) (by scalar_tac) (vcpu.size_ok (by scalar_tac) hsz) refine WP.spec_bind (P0.vcpu.num_lrs.p0 ar a hA) fun lrs hl => ?_ @@ -282,9 +265,8 @@ local macro "lbl_neT" : tactic => `(tactic| exact lbl_ne_of_val (by fl4_abi.label.ARMVCPUWriteReg, fl4_abi.label.ARMVCPUAckVPPI, fl4_abi.label.ARMVCPUReadState, fl4_abi.label.ARMVCPUWriteState, fl4_abi.label.ARMVCPURun])) -/-- **The `Vcpu` arm of `decode_invocation` at ReadState / WriteState to `ArmQIAt ∧ TabKeepOrZero`** (module -docstring). -/ -theorem syscall.decode_invocation.vcSt_armQIAt (hA : P0.ArchTotal ar) {s : S} +/-- **`vcSt_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.vcSt_armSAt (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) 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) @@ -292,14 +274,17 @@ theorem syscall.decode_invocation.vcSt_armQIAt (hA : P0.ArchTotal ar) {s : S} (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPUReadState ∨ lbl = fl4_abi.label.ARMVCPUWriteState) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ OSKeep st OS s s' ⦄ := by have hvc : vc ∈ Vc := I.vcc slot P.src vc (by rw [capA_eq] at hcap; exact okinj hcap) have cl : ∀ (r : (core.result.Result Unit error.Exc) × S × A), - (DFB st H Cs (L.curW s) ∅ (VFW H Vc OS) s r.2.1 ∧ + (DFB st H Cs (L.curW s) ∅ (VFW st H Vc OS s) s r.2.1 ∧ ∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' r.2.1) → - ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 := fun r d => by + ArmQIAt st H Cs OS Vc ia ie s r.2.1 ∧ TabKeepOrZero st s r.2.1 ∧ ArmVsK st H OS Vc s r.2.1 ∧ + OSKeep st OS s r.2.1 := fun r d => by obtain ⟨Ac', hb'⟩ := d.2 - exact ArmQIAt.ofDFBf I D P B Y hks d.1 hb' + have arm := ArmQIAt.ofDFBf I D P B Y hks d.1 hb' + exact ⟨arm.1, arm.2.1, arm.2.2, DFB.osk P.os D.bxi.blk (fun x hx b h1 h2 hb => hb.elim + (fun hv => I.del.vc.os b hv ⟨x, hx, h1, h2⟩) fun hf => hf.1.2.2 x hx ⟨h1, h2⟩) d.1⟩ unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ unfold vcpu.decode @@ -319,6 +304,20 @@ theorem syscall.decode_invocation.vcSt_armQIAt (hA : P0.ArchTotal ar) {s : S} obtain ⟨_, s', a'⟩ := r exact cl _ d +/-- **The `Vcpu` arm of `decode_invocation` at ReadState / WriteState to `ArmQIAt ∧ TabKeepOrZero`** (module +docstring). -/ +theorem syscall.decode_invocation.vcSt_armQIAt (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {vc : 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 (.Vcpu vc) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Vcpu vc)) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMVCPUReadState ∨ lbl = fl4_abi.label.ARMVCPUWriteState) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Vcpu vc) 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' ⦄ := + WP.spec_mono (syscall.decode_invocation.vcSt_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ + end ST end R end W7 diff --git a/proofs/Fl4ProofsA64/P1/MdbVsFlQ.lean b/proofs/Fl4ProofsA64/P1/MdbVsFlQ.lean index c3856c33b..2b427dd30 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVsFlQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVsFlQ.lean @@ -15,6 +15,9 @@ item 2): the AArch64 MMU decode's arms whose only store write is the caller's re **`syscall.decode_invocation.pdInv_armQIAt`** (a `PageDirectory` / `Pdpt` cap: `vspace.decode` rejects it, state unchanged). +(A64-S1A gen 40, Architect ruling for gen 40, R3) `restart_armQ`, the two flush walks and `vsFl_armQIAt` / +`pgFl_armQIAt` / `pdInv_armQIAt` also post `ArmVsK` (last conjunct; MdbVcArmQ's `ofDFBv`). + Named premises: none. Case facts: none new. -/ import Fl4ProofsA64.P1.MdbVcArmQ @@ -42,7 +45,7 @@ theorem sched.set_thread_state.restart_armQ {s : S} {cap : capability.Cap} {slot (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => - ArmQIAt st H Cs OS Vc ia ie s s1 ∧ TabKeepOrZero st s s1 ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s1 ∧ TabKeepOrZero st s s1 ∧ ArmVsK st H OS Vc s s1 ⦄ := by have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT refine WP.spec_mono (sched.set_thread_state.dfR s (L.curW s) D.bxi.blk hct D.run) fun s1 h => ?_ obtain ⟨h1, fw, l⟩ := h @@ -96,10 +99,10 @@ theorem vspace.decode_vspace_flush.armQ (hA : P0.ArchTotal ar) {s : S} {cap0 : c (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (a : A) (lbl len ptr : U64) (m : Bool) (asid buf : U64) : vspace.decode_vspace_flush st ar s a lbl len (.Pml4 ptr m asid) buf ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by have hS : P0.StoreTotal st := L.total - have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s := + (fun h => ⟨h.1, h.2, ArmVsK.refl s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) have rst := sched.set_thread_state.restart_armQ I D P B Y hks unfold vspace.decode_vspace_flush try simp only [lift, bind_ok] @@ -115,10 +118,10 @@ theorem vspace.decode_page_flush.armQ (hA : P0.ArchTotal ar) {s : S} {cap0 : cap (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (a : A) (lbl len : U64) (f : vspace.FrameCap) (buf : U64) : vspace.decode_page_flush st ar s a lbl len f buf ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by have hS : P0.StoreTotal st := L.total - have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s := + (fun h => ⟨h.1, h.2, ArmVsK.refl s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) have rst := sched.set_thread_state.restart_armQ I D P B Y hks unfold vspace.decode_page_flush ept.flush_frame try simp only [lift, bind_ok] @@ -135,9 +138,9 @@ theorem syscall.decode_invocation.vsFl_armQIAt (hA : P0.ArchTotal ar) {s : S} (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.Pml4 ptr m asid) blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by - have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by + have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s := + (fun h => ⟨h.1, h.2, ArmVsK.refl s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ unfold vspace.decode @@ -177,7 +180,7 @@ theorem syscall.decode_invocation.pgFl_armQIAt (hA : P0.ArchTotal ar) {s : S} lbl = fl4_abi.label.ARMPageCleanInvalidate_Data ∨ lbl = fl4_abi.label.ARMPageUnify_Instruction) (len : U64) (blk call don fp' : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl 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' ⦄ := by + ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by have h1 : lbl ≠ fl4_abi.label.ARMPageMap := by lbl_neP have h2 : lbl ≠ fl4_abi.label.ARMPageUnmap := by lbl_neP unfold syscall.decode_invocation @@ -202,9 +205,9 @@ theorem syscall.decode_invocation.pdInv_armQIAt {s : S} {cap : capability.Cap} (hc : (∃ p m x v, cap = .PageDirectory p m x v) ∨ (∃ p m x v, cap = .Pdpt p m x v)) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by - have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by + have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s ∧ ArmVsK st H OS Vc s s := + (fun h => ⟨h.1, h.2, ArmVsK.refl s⟩) (ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s)) rcases hc with ⟨p, m, x, v, rfl⟩ | ⟨p, m, x, v, rfl⟩ <;> · unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ diff --git a/proofs/Fl4ProofsA64/P1/MdbVsGaQ.lean b/proofs/Fl4ProofsA64/P1/MdbVsGaQ.lean index 5b4885483..f22e8b5f4 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVsGaQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVsGaQ.lean @@ -22,6 +22,9 @@ P1 (aarch64, gen 157): **Page GetAddress to `ArmQIAt ∧ TabKeepOrZero`** (Archi 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. +(A64-S1A gen 40, Architect ruling for gen 40, R3) `restart_reply_armQ` and `getAddr_armQIAt` also post `ArmVsK` (last +conjunct; MdbVcArmQ's `ofDFBv`). + Named premises: none. Case facts: none new. -/ import Fl4ProofsA64.P1.MdbVsFlQ @@ -46,15 +49,16 @@ theorem vspace.reply1_eq (s : S) (t : U64) (call : Bool) (v : U64) : vspace.reply1 st s t call v = vcpu.reply1 st s t call v := by unfold vspace.reply1 vcpu.reply1; rfl -/-- **The caller's restart, then a reply, to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem sched.set_thread_state.restart_reply_armQ {s : S} {cap : capability.Cap} {slot : U64} +/-- **`restart_reply_armQ` exporting the slot fact** (A64-S1A gen 41). -/ +theorem sched.set_thread_state.restart_reply_armS {s : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (call : Bool) : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => ∀ v, vspace.reply1 st s1 (L.curW s) call v ⦃ s2 => - ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2 ⦄ ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2 ∧ ArmVsK st H OS Vc s s2 ∧ + OSKeep st OS s s2 ⦄ ⦄ := by have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT have hb := D.bxi.blk refine WP.spec_mono (WP.spec_and (sched.set_thread_state.restart_blk (Es := ∅) s (L.curW s) hb hct @@ -62,7 +66,21 @@ theorem sched.set_thread_state.restart_reply_armQ {s : S} {cap : capability.Cap} rintro s1 ⟨⟨-, -, e1, -⟩, h1, fw, l⟩ v rw [vspace.reply1_eq] refine WP.spec_mono (vcpu.reply1.dfK (Ko := ∅) h1 hct e1 call v) fun s2 h2 => ?_ - exact ArmQIAt.ofDFBv I D P B Y hks (DFB.ofDF ((DF.ofKL fw l (tc_le _ _)).trans h2.1)) h2.2 + have d := (DF.ofKL fw l (tc_le _ _)).trans h2.1 + have arm := ArmQIAt.ofDFBv I D P B Y hks (DFB.ofDF d) h2.2 + exact ⟨arm.1, arm.2.1, arm.2.2, DF.osk P D.bxi (fun _ h => absurd h (Set.notMem_empty _)) d⟩ + +/-- **The caller's restart, then a reply, to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem sched.set_thread_state.restart_reply_armQ {s : S} {cap : capability.Cap} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (call : Bool) : + sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => ∀ v, + vspace.reply1 st s1 (L.curW s) call v ⦃ s2 => + ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2 ∧ ArmVsK st H OS Vc s s2 ⦄ ⦄ := + WP.spec_mono (sched.set_thread_state.restart_reply_armS I D P B Y hks call) fun _ h v => + WP.spec_mono (h v) fun _ h => ⟨h.1, h.2.1, h.2.2.1⟩ set_option hygiene false in local macro "lbl_neG" : tactic => `(tactic| exact lbl_ne_of_val (by @@ -77,8 +95,8 @@ theorem vspace.is_cache_label.getAddr : simp [fl4_abi.label.ARMPageGetAddress, fl4_abi.label.ARMPageClean_Data, fl4_abi.label.ARMPageInvalidate_Data, fl4_abi.label.ARMPageCleanInvalidate_Data, fl4_abi.label.ARMPageUnify_Instruction] -/-- **A `Frame` cap at `ARMPageGetAddress` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ -theorem syscall.decode_invocation.getAddr_armQIAt {s : S} +/-- **`getAddr_armQIAt` exporting the slot fact** (A64-S1A gen 41). -/ +theorem syscall.decode_invocation.getAddr_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 @@ -88,10 +106,11 @@ theorem syscall.decode_invocation.getAddr_armQIAt {s : S} (hl : lbl = fl4_abi.label.ARMPageGetAddress) (len : U64) (blk call don fp' : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl 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' ⦄ := by + ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ + OSKeep st OS s s' ⦄ := by have h1 : lbl ≠ fl4_abi.label.ARMPageMap := by lbl_neG have h2 : lbl ≠ fl4_abi.label.ARMPageUnmap := by lbl_neG - have rst := sched.set_thread_state.restart_reply_armQ I D P B Y hks call + have rst := sched.set_thread_state.restart_reply_armS I D P B Y hks call unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ unfold vspace.decode @@ -114,6 +133,21 @@ theorem syscall.decode_invocation.getAddr_armQIAt {s : S} | exact (WP.spec_ok _).2 hs2 | (simp only [WP.uncurry'_pair]; exact (WP.spec_ok _).2 hs2) +/-- **A `Frame` cap at `ARMPageGetAddress` to `ArmQIAt ∧ TabKeepOrZero`** (module docstring). -/ +theorem syscall.decode_invocation.getAddr_armQIAt {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) (hks : HeapKsOff H (L.ksb s)) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.ARMPageGetAddress) + (len : U64) (blk call don fp' : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl 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' ⦄ := + 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** diff --git a/proofs/Fl4ProofsA64/P1/MdbVsMapA.lean b/proofs/Fl4ProofsA64/P1/MdbVsMapA.lean index 3c92068da..1324f6340 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVsMapA.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVsMapA.lean @@ -23,11 +23,17 @@ Source (crates/fl4-core/src/arch/aarch64/vspace.rs): `frame_root` (the ASID's po * **`vspace.decode_test_and_clear_accessed.armQ`**, top **`syscall.decode_invocation.tca_armQIAt`** (a `Frame` cap at `ARMPageTestAndClearAccessed`; an `is_ept` frame is rejected by the decode itself). +(A64-S1A gen 32, F3) **`PtW.sysK`** (`ofPtW`'s body), `ofPtW` / `ofDFBp` take the step's `ArmVs`; **`ArmQIAt.thenW`** +(a stretch, then a step with no table word keeping `OS`, the composite's `ArmVs` supplied); `thenPtW` reads the +stretch's zero record and the written word's `VsWr` record (MdbArmVsV's `ArmVsZ.thenOne`); TestAndClearAccessed's +`af` record by MdbArmVsV's `ArmVs.ofOne` (the reply's `DfW` words off every placed `VsR` word). + Named premises: none. Case facts: none new (`ArmDecHyps.vs` / `ptKs` are the ruled fields). -/ import Fl4ProofsA64.P1.MdbVsUnmQ import Fl4ProofsA64.P1.QueueS1Map import Fl4ProofsA64.P1.QueuePtTy +import Fl4ProofsA64.P1.MdbArmVsV open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P1 @@ -136,7 +142,8 @@ theorem ArmQIAt.ofDFBp {s s' : S} {cap : capability.Cap} {slot : U64} {extra : A (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) (hpk : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) (d : DFB st H Cs (L.curW s) ∅ (PtW Pt) s s') - (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : + (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') + (hV : ArmVs st H OS Vc s s') : ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' := by obtain ⟨Q, Rq, q⟩ := D.bxi.1 have hSg := D.bxi.blk.2.2.2.2 @@ -151,19 +158,18 @@ theorem ArmQIAt.ofDFBp {s s' : S} {cap : capability.Cap} {slot : U64} {extra : A (K8.KW.to7 hk) · exact B.ly.kslo o hl x hx (by rw [← e]; exact ⟨h1, h2⟩) · exact I.del.vr.os b (Or.inl hw) ⟨x, hx, h1, h2⟩ - refine (fun h => ⟨h.1, h.2, k⟩) (ArmQIAt.ofWK I.del.vr d.w (fun b hd => ?_) k hS hb) + refine (fun h => ⟨h.1, h.2, k⟩) (ArmQIAt.ofWK I.del.vr d.w (fun b hd => ?_) k hS hb hV) rcases hd with hd | hw · exact DfW.notAsW P.heap F I.del.vr (fun c hc => q.nodes c hc) hd · exact hpk b hw -/-- **A `PtW Pt` write step from a state with `SysL ∧ SymL ∧ BlkOK`** (module docstring). -/ -theorem ArmQIAt.ofPtW {Vc' Ub' : Set U64} {s s' : S} {Ac0 Ac' : Set U64} (hH : HeapOK H) +/-- (A64-S1A gen 32; `ofPtW`'s body, moved) **A `PtW Pt` write step from a state with `SysL ∧ SymL ∧ BlkOK` keeps +`SysL ∧ SymL` and every `OS` word** (`SysL.dfT`). -/ +theorem PtW.sysK {Vc' Ub' : Set U64} {s s' : S} {Ac0 : Set U64} (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt) - (hpk : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hB : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac0 s) - (w : WritesIn st s s' (PtW Pt)) - (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') : - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' := by + (w : WritesIn st s s' (PtW Pt)) : (SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') ∧ OSKeep st OS s s' := by obtain ⟨Q, Rq, q⟩ := hB.1 have hBw : ∀ b, PtW Pt b → b ∈ H.omega ∧ b ∉ H.frame := fun b hb => ⟨hvr.om b (Or.inl hb), hvr.sg b (Or.inl hb)⟩ @@ -173,20 +179,51 @@ theorem ArmQIAt.ofPtW {Vc' Ub' : Set U64} {s s' : S} {Ac0 Ac' : Set U64} (hH : H (fun _ h => absurd h (Set.notMem_empty _)) (fun b h => Or.inl (hBw b h)) (fun x hx b h1 h2 hv => hvr.os b (Or.inl hv) ⟨x, hx, h1, h2⟩) B Y d (B.ipc.keep (IbK.of_w q.tcbs w fun y hy hb => ib_out q hy (q.omega _ (hBw _ hb).1) rfl)) - have k : OSKeep st OS s s' := OSKeep.of_in hO w fun x hx b _ h1 h2 hF => - hvr.os b (Or.inl hF) ⟨x, hx, h1, h2⟩ - exact ArmQIAt.ofWK hvr w hpk k hS hb + exact ⟨hS, OSKeep.of_in hO w fun x hx b _ h1 h2 hF => hvr.os b (Or.inl hF) ⟨x, hx, h1, h2⟩⟩ -/-- **An `ArmQIAt ∧ TabKeepOrZero` stretch, then a `PtW Pt` write step** (module docstring). -/ +/-- **A `PtW Pt` write step from a state with `SysL ∧ SymL ∧ BlkOK`** (module docstring; A64-S1A gen 32: by +`PtW.sysK`, the step's `ArmVs` supplied). -/ +theorem ArmQIAt.ofPtW {Vc' Ub' : Set U64} {s s' : S} {Ac0 Ac' : Set U64} (hH : HeapOK H) + (hO : OSOK H.tcbs H.omega H.frame OS) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub' (L.ksb s) Pt) + (hpk : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (hB : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac0 s) + (w : WritesIn st s s' (PtW Pt)) + (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s') + (hV : ArmVs st H OS Vc s s') : + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' := + let X := PtW.sysK hH hO hvr B Y hB w + ArmQIAt.ofWK hvr w hpk X.2 X.1 hb hV + +/-- (A64-S1A gen 32, F3) **An `ArmQIAt ∧ TabKeepOrZero` stretch, then a step with no table word keeping every `OS` +word**, the composite's `ArmVs` supplied (MdbArmTab's `ArmQIAt.ofW` clauses composed with the first stretch's). -/ +theorem ArmQIAt.thenW {Ω Sg Scs Vc' Ub' Pt' : Set U64} {Z : U64 → Nat} {W : U64 → Prop} {Ac' : Set U64} + {s0 s1 s2 : S} (h1 : ArmQIAt st H Cs OS Vc ia ie s0 s1 ∧ TabKeepOrZero st s0 s1) + (hvr : VrOK Ω Sg Scs Z OS Vc' Ub' (L.ksb s1) Pt') (w : WritesIn st s1 s2 W) + (hW : ∀ b, W b → ¬ AsW (L.ksb s1) b) (k : OSKeep st OS s1 s2) + (hS : SysL st H Cs OS ia ie s2 ∧ SymL st H Cs s2) + (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s2) + (hV : ArmVs st H OS Vc s0 s2) : ArmQIAt st H Cs OS Vc ia ie s0 s2 ∧ TabKeepOrZero st s0 s2 := + have ht := tab_of_w hvr w hW + ⟨⟨hS.1, hS.2, ⟨Ac', hb⟩, fun v => CapInv.keepO (h1.1.2.2.2.1 v) k, + fun p => PoolOff.ofTab w.1 ht (h1.1.2.2.2.2.1 p), fun n => PoolNamed.ofTab w.1 ht k (h1.1.2.2.2.2.2.1 n), + fun n i => PoolIdx.ofTab w.1 ht k (h1.1.2.2.2.2.2.2.1 n i), + fun Q hQ p => CapInv.keepO (h1.1.2.2.2.2.2.2.2.1 Q hQ p) k, hV⟩, h1.2.trans (TabKeep.ofW hvr w hW).toDel⟩ + +/-- **An `ArmQIAt ∧ TabKeepOrZero` stretch, then a `PtW Pt` write step** (module docstring; A64-S1A gen 32, F3: the +stretch a zero step `Z` at every placement, the step one write of a word `x` ending as a `VsWr` record `hv`, by +MdbArmVsV's `ArmVsZ.thenOne`). -/ theorem ArmQIAt.thenPtW {s s2 s3 : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hpk : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) - (h2 : ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2) (w : WritesIn st s2 s3 (PtW Pt)) : + (h2 : ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2) (Z : ArmVsZ st H OS Vc s s2) {x : U64} + (hx : PtW Pt x) (w : WritesIn st s2 s3 (· = x)) (hv : L.mem s3 x = L.mem s2 x ∨ VsWr st OS (L.ksb s) s s3 x) : ArmQIAt st H Cs OS Vc ia ie s s3 ∧ TabKeepOrZero st s s3 := by obtain ⟨Ac2, hb2⟩ := h2.1.2.2.1 have hk : L.ksb s2 = L.ksb s := h2.2.1 have hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s2) Pt := by rw [hk]; exact I.del.vr - have hb3 := (blk_of_capw hb2 w fun b hb => Or.inr ⟨I.del.vr.om b (Or.inl hb), I.del.vr.sg b (Or.inl hb)⟩).1 - exact ArmQIAt.transZ h2 (ArmQIAt.ofPtW hH hO hvr (by rw [hk]; exact hpk) h2.1.1 h2.1.2.1 hb2 w hb3) + have wP : WritesIn st s2 s3 (PtW Pt) := w.mono fun b e => by rw [e]; exact hx + have hb3 := (blk_of_capw hb2 wP fun b hb => Or.inr ⟨I.del.vr.om b (Or.inl hb), I.del.vr.sg b (Or.inl hb)⟩).1 + obtain ⟨hS, k⟩ := PtW.sysK hH hO hvr h2.1.1 h2.1.2.1 hb2 wP + exact ArmQIAt.thenW h2 hvr wP (by rw [hk]; exact hpk) k hS hb3 (ArmVsZ.thenOne Z w hv) /-! ## The reply of a caller that is not blocked -/ @@ -243,7 +280,7 @@ theorem vspace.decode_test_and_clear_accessed.armQ (hA : P0.ArchTotal ar) {s : S vspace.decode_test_and_clear_accessed st ar s a ⟨fp, fsz, fr, fd, fm, fe, fa, fv⟩ call ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) obtain ⟨Pp, Tb, Lv, hPp, hTb, hvs⟩ := Hy.vs1 have hct : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT have hBw : ∀ b, PtW Pt b → b ∈ H.omega ∧ b ∉ H.frame := fun b hb => @@ -274,7 +311,7 @@ theorem vspace.decode_test_and_clear_accessed.armQ (hA : P0.ArchTotal ar) {s : S step with sched.cur_thread.spec as ⟨ct, ect⟩ have e : ct = L.curW s := ect subst e - refine WP.spec_bind P0.vspace.D_AF.p0 fun i _ => ?_ + refine WP.spec_bind P0.Consts.vspace.D_AF.spec fun i hi => ?_ try simp only [lift, bind_ok] refine WP.spec_bind (LawfulStore.fetch_and_spec s x.slot _) ?_ rintro ⟨old, s1⟩ e1 @@ -294,7 +331,21 @@ theorem vspace.decode_test_and_clear_accessed.armQ (hA : P0.ArchTotal ar) {s : S ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2 ⦄ := fun v => by rw [vspace.reply1_eq] refine WP.spec_mono (vcpu.reply1.dfKn (Ko := ∅) b1 hct hr1 call v) fun s2 h2 => ?_ - have h := ArmQIAt.ofDFBp I D P B Y Hy.ptKs (d1.trans (DFB.ofDF h2.1)) h2.2 + -- (A64-S1A gen 32, F3) the access-flag record (`VsWr.af`) of the one written `VsR` word + obtain ⟨Q1, Rq1, q1⟩ := b1.1 + have hk1 : L.ksb (L.wr s x.slot (old &&& ~~~i)) = L.ksb s := L.ksb_wr _ _ _ + have hvr1 : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb (L.wr s x.slot (old &&& ~~~i))) Pt := by + rw [hk1]; exact I.del.vr + have F1 : TabF st H Cs OS (L.wr s x.slot (old &&& ~~~i)) := TabF.of hvr1 q1 (by rw [hk1]; exact B.ly.ksw) P.core0 + have hxs : L.mem s2 x.slot = L.mem (L.wr s x.slot (old &&& ~~~i)) x.slot := + h2.1.w.mem_eq hal fun hd => DfW.notPtW q1 hvr1 hd hx + have hV : ArmVs st H OS Vc s s2 := ArmVs.ofOne (W := DfW st H.tcbs Cs H.frame H.scBits ∅ + (L.wr s x.slot (old &&& ~~~i))) (((writesIn_wr (s := s) (v := old &&& ~~~i) hal).trans h2.1.w).mono fun b hb => hb.symm) + (fun Ub' Pt' hvr' _ b hd hv => by + rw [← hk1] at hvr' hv + exact hv.elim (DfW.notPtW q1 hvr' hd) (DfW.notAsW P.heap F1 hvr1 (fun c hc => q1.nodes c hc) hd)) + (Or.inr (Or.inl (by rw [hxs, L.mem_wr_same hal, hi, andn_or_self, ← hold]))) + have h := ArmQIAt.ofDFBp I D P B Y Hy.ptKs (d1.trans (DFB.ofDF h2.1)) h2.2 hV exact ⟨h.1, h.2.1.toDel⟩ split · exact WP.spec_bind (tail 1#u64) fun s2 h2 => (WP.spec_ok _).2 h2 diff --git a/proofs/Fl4ProofsA64/P1/MdbVsMapB.lean b/proofs/Fl4ProofsA64/P1/MdbVsMapB.lean index c906aa052..da0db1945 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVsMapB.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVsMapB.lean @@ -17,12 +17,22 @@ the mapped cap, then one or two writes of the slot `lookup_pt_slot` found from a **`pt_insC`** (MdbInsL's `insC_of`). * **`UnmMid.set_armQ`** (MdbVsUnmQ's `UnmMid.frU_armQ` with MdbVsUnmQ's `set_cap.sysLG` for any new cap with the per-cap facts), **`pgMap_set`** / **`ptMap_set1`** (the restart and the in-place `Frame` / `PageTable` write). -* **`vspace.install_page.ptw`** (a `WritesIn … (PtW Pt)` step), **`pgMap_tailQ`**, **`ptMap_tailQ`** (closed by +* **`vspace.install_page.ptw`** (a `WritesIn … (PtW Pt)` step; A64-S1A gen 30: the projection of + **`vspace.install_page.slotE`**, which also exports the written value: the slot holds `e` at the end), **`pgMap_tailQ`**, **`ptMap_tailQ`** (closed by MdbVsMapA's `ArmQIAt.thenPtW`). * **`vspace.decode_high_page_map.armQ`**, **`vspace.decode_page_map.armQ`**, top **`syscall.decode_invocation.pgMap_armQIAt`**; **`vspace.map_high_page_table.armQ`**, top **`syscall.decode_invocation.ptMap_armQIAt`**. +(A64-S1A gen 32, F3) The written values: `pgMap_set` / `ptMap_set1` also post the stretch's zero record +(`UnmMid.armVsZ`, `set_cap.armVsZ`), `ptMap_set1` the mapped cap (**`obj.Slot.set_cap.capEq`**); `pgMap_tailQ` takes +the descriptor's `DescTo e fp` (MdbArmVsV's `s1page_desc` at the walks, `install_page.slotE` for the slot's value: +`VsWr.leaf`), `ptMap_tailQ` the table's `DescTo` and `m = false` (the decode's mapped check; `VsWr.tab`). The +alignment of the mapped object: **`frame_al4k`** (a non-device frame, from the heap); a device frame's +and the table's are the gen-33 `ArmDecHyps` fields `frAl` / `ptCap` (Architect 00:25Z, G1 / G2). + +(A64-S1A gen 37) the mapped cap's cap-source carry by `CapSrc.al` of the invoked slot's (`CapSrc.inv`). + Named premises: none. Case facts: none new. -/ import Fl4ProofsA64.P1.MdbVsMapA @@ -108,7 +118,7 @@ theorem frame_insC (p : U64) (sz : capability.FrameSize) (r : U64) (d m e : Bool · refine ⟨⟨fun h => ?_, fun h => ?_⟩, fun h => ?_⟩ <;> exact absurd h.2.2 (by simp [isFrA]) · intro _ _ _ h; cases h · refine ⟨?_, ?_, ?_, fun _ => rfl⟩ - · intro _ _ _ _ _ _ _ h; cases h; exact ⟨r, m, e, a, v, rfl⟩ + · intro _ _ _ _ _ _ _ _ h; cases h; exact ⟨r, m, e, a, v, rfl⟩ · intro _ _ _ h; cases h · intro _ _ _ _ h; cases h · exact ⟨eh, ep, es, rfl, fun _ _ _ _ h => by cases h⟩ @@ -157,7 +167,11 @@ theorem UnmMid.set_armQ {s s1 : S} {cap : capability.Cap} {slot : U64} {extra : have hcO : ∀ y ∈ OS, y ≠ slot → capA st s3 y = capA st s y := fun y hy e => (hk y hy e).trans (M.k.capA hy) refine ⟨⟨B3, Y3, ⟨Ac, h3⟩, fun _ => V3, PoolOff.ofTZ tz, PoolNamed.of_map tz ?_, fun _ hPI => PoolIdx.of_frame tz.1 tz.old ?_ hPI, - PtSrc.ptCap (PtSrc.setc (PtSrc.refl s) ed (PtSrc.al (Or.inl C.al) C.fe (PtSrc.of_slot P.src hcs)) hcO)⟩, tz⟩ + CapSrc.inv (CapSrc.setc (CapSrc.refl s) ed (CapSrc.al (Or.inl C.al) C.fe (CapSrc.of_slot P.src hcs)) hcO), + (ArmVsZ.thenOS (UnmMid.armVsZ I D P B M M.z) w fun b hb => by + rcases hb with ⟨t, ht, -⟩ | ⟨hb, -⟩ + · exact absurd ht (Set.notMem_empty _) + · exact hb).toVs⟩, tz⟩ · intro y hy p' b' hc _ _ by_cases e : y = slot · subst e; rw [hcs] at hc; exact absurd hc (hpo _ _) @@ -167,8 +181,35 @@ theorem UnmMid.set_armQ {s s1 : S} {cap : capability.Cap} {slot : U64} {extra : · subst e; rw [ed] at hc; exact absurd hc (hpn _ _) · exact ⟨y, hy, by rw [← hcO y hy e]; exact hc⟩ +/-- (A64-S1A gen 32) **`set_cap` writes the decoded cap into the slot** (MdbSetCapG's `sysLG` text, that part). -/ +theorem obj.Slot.set_cap.capEq (hO : OSOK H.tcbs H.omega H.frame OS) {s : S} {x : U64} (hx : x ∈ OS) + {nc dc : capability.Cap} (hdc : CapRt.decodeF (CapRt.encodeF nc).1 (CapRt.encodeF nc).2 = dc) : + obj.Slot.set_cap st x s nc ⦃ s' => capA st s' x = dc ⦄ := by + rw [set_cap_eq (CapRt.encode_eq nc), WP.spec_ok] + have hd : capability.Cap.decode ⟨(CapRt.encodeF nc).1⟩ ⟨(CapRt.encodeF nc).2⟩ = ok dc := by + rw [CapRt.decode_eq]; exact congrArg ok hdc + exact capA_wr2_self hO hx hd + +/-- (A64-S1A gen 32) **A non-device frame cap of an `OS` slot names a 4 KiB-aligned object** (`SysL`'s `fr`, the +heap's alignment, `12 ≤ bits`). -/ +theorem frame_al4k {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {x : U64} (hx : x ∈ OS) {p r a v : U64} + {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 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 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 + have := Nat.mod_mul_right_mod p.val 4096 (2 ^ (bits.val - 12)) + rw [hal] at this; omega + set_option maxHeartbeats 2000000 in -/-- **The restart, then the mapped `Frame` cap in place** (module docstring). -/ +/-- **The restart, then the mapped `Frame` cap in place** (module docstring; A64-S1A gen 32: with the zero record +of the stretch, `UnmMid.armVsZ` and `set_cap.armVsZ`). -/ theorem pgMap_set {s : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) @@ -177,7 +218,7 @@ theorem pgMap_set {s : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.St (hcs : capA st s slot = .Frame fp fsz fr fd fm fe fa fv) (asid vaddr : U64) : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => obj.Slot.set_cap st slot s1 (.Frame fp fsz fr fd true false asid vaddr) ⦃ s2 => - ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2 ⦄ ⦄ := by + (ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2) ∧ ArmVsZ st H OS Vc s s2 ⦄ ⦄ := by have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ rw [hcs] at hw have hp : CapRt.Canonical fp := by cases fe <;> exact hw.1 @@ -187,6 +228,7 @@ theorem pgMap_set {s : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.St have hfo0 := B.fo slot P.src rw [hcs] at hfr0 hfo0 refine WP.spec_mono (sched.set_thread_state.unmMid I D) fun s1 h1 => ?_ + refine WP.spec_and ?_ (obj.Slot.set_cap.armVsZ P.os P.src (UnmMid.armVsZ I D P B h1.1 h1.1.z) _) exact UnmMid.set_armQ I D P B Y hcs h1.1 hdc (frame_insC fp fsz fr fd fm fe fa fv true false a' v') (fun h => by cases h) (fun _ _ _ _ _ _ _ h => by cases h; exact hfr0 _ _ _ _ _ _ _ rfl) @@ -211,10 +253,13 @@ theorem ptMap_set1 {s : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.S (hcs : capA st s slot = .PageTable ptr m ma mv) {s1 : S} (M : UnmMid st H Cs OS Pt Ac s s1) (asid base : U64) : obj.Slot.set_cap st slot s1 (.PageTable ptr true asid base) ⦃ s2 => - ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2 ⦄ := by + (ArmQIAt st H Cs OS Vc ia ie s s2 ∧ TabKeepOrZero st s s2) ∧ ArmVsZ st H OS Vc s s2 ∧ + ∃ a' v', capA st s2 slot = .PageTable ptr true a' v' ⦄ := by have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ rw [hcs] at hw obtain ⟨a', v', hdc⟩ := CapRt.rt_PageTableA ptr true asid base hw.1 + refine WP.spec_and ?_ (WP.spec_and (obj.Slot.set_cap.armVsZ P.os P.src (UnmMid.armVsZ I D P B M M.z) _) + (WP.spec_mono (obj.Slot.set_cap.capEq P.os P.src hdc) fun _ h => ⟨a', v', h⟩)) exact UnmMid.set_armQ I D P B Y hcs M hdc (pt_insC ptr m ma mv true a' v') (fun h => by cases h) (fun _ _ _ _ _ _ _ h => by cases h) @@ -231,14 +276,16 @@ theorem ptMap_set1 {s : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.S /-! ## The descriptor writes -/ set_option maxHeartbeats 4000000 in -/-- **`install_page`** writes only the walk's slot (at most twice). -/ -theorem vspace.install_page.ptw (hA : P0.ArchTotal ar) {lu : vspace.PtSlot} (hal : Aligned lu.slot) - (hx : PtW Pt lu.slot) (s : S) (a : A) (e root asid vaddr : U64) (f : vspace.FrameCap) (attr : U64) - (high : Bool) : - vspace.install_page st ar s a lu e root asid vaddr f attr high ⦃ r => WritesIn st s r.1 (PtW Pt) ⦄ := by +/-- (A64-S1A gen 30) **`install_page` writes only the walk's slot, last with the descriptor `e`** (the body of `ptw`, +moved; `ptw` its projection, statement unchanged): Page Map's written value, for MdbArmVs's `leaf` record. -/ +theorem vspace.install_page.slotE (hA : P0.ArchTotal ar) {lu : vspace.PtSlot} (hal : Aligned lu.slot) + (s : S) (a : A) (e root asid vaddr : U64) (f : vspace.FrameCap) (attr : U64) (high : Bool) : + vspace.install_page st ar s a lu e root asid vaddr f attr high ⦃ r => + WritesIn st s r.1 (· = lu.slot) ∧ L.mem r.1 lu.slot = e ⦄ := by have hS : P0.StoreTotal st := L.total - have W : ∀ (s0 : S) (v : U64), WritesIn st s0 (L.wr s0 lu.slot v) (PtW Pt) := fun s0 v => - (writesIn_wr hal).mono fun b' e => by rw [e]; exact hx + have W : ∀ (s0 : S) (v : U64), WritesIn st s0 (L.wr s0 lu.slot v) (· = lu.slot) := + fun s0 v => writesIn_wr hal + have V : ∀ (s0 : S) (v : U64), L.mem (L.wr s0 lu.slot v) lu.slot = v := fun s0 v => L.mem_wr_same hal unfold vspace.install_page refine WP.spec_bind (LawfulStore.read_spec s lu.slot) fun old _ => ?_ refine WP.spec_bind (P0.vspace.is_page.p0 old lu.shift) fun b _ => ?_ @@ -249,17 +296,25 @@ theorem vspace.install_page.ptw (hA : P0.ArchTotal ar) {lu : vspace.PtSlot} (hal · refine WP.spec_bind (LawfulStore.write_spec s lu.slot e) fun s1 e1 => ?_ refine WP.spec_bind (P0.vspace.invalidate_mapping.p0 ar a high asid vaddr hA) fun a1 _ => ?_ subst e1 - exact (WP.spec_ok _).2 (W s e) + exact (WP.spec_ok _).2 ⟨W s e, V s e⟩ · refine WP.spec_bind (LawfulStore.write_spec s lu.slot 0#u64) fun s1 e1 => ?_ refine WP.spec_bind (P0.vspace.invalidate_mapping.p0 ar a high asid vaddr hA) fun a1 _ => ?_ refine WP.spec_bind (Pₘ := fun _ => True) (by copT) fun a2 _ => ?_ refine WP.spec_bind (LawfulStore.write_spec s1 lu.slot e) fun s2 e2 => ?_ subst e1 e2 - exact (WP.spec_ok _).2 ((W s 0#u64).trans1 (W _ e)) + exact (WP.spec_ok _).2 ⟨(W s 0#u64).trans1 (W _ e), V _ e⟩ · refine WP.spec_bind (Pₘ := fun _ => True) (by copT) fun a1 _ => ?_ refine WP.spec_bind (LawfulStore.write_spec s lu.slot e) fun s1 e1 => ?_ subst e1 - exact (WP.spec_ok _).2 (W s e) + exact (WP.spec_ok _).2 ⟨W s e, V s e⟩ + +/-- **`install_page`** writes only the walk's slot (at most twice; A64-S1A gen 30: `slotE`'s projection). -/ +theorem vspace.install_page.ptw (hA : P0.ArchTotal ar) {lu : vspace.PtSlot} (hal : Aligned lu.slot) + (hx : PtW Pt lu.slot) (s : S) (a : A) (e root asid vaddr : U64) (f : vspace.FrameCap) (attr : U64) + (high : Bool) : + vspace.install_page st ar s a lu e root asid vaddr f attr high ⦃ r => WritesIn st s r.1 (PtW Pt) ⦄ := + WP.spec_mono (vspace.install_page.slotE hA hal s a e root asid vaddr f attr high) fun _ h => + h.1.mono fun b' e => by rw [e]; exact hx /-- **Page Map's tail** (module docstring). -/ theorem pgMap_tailQ (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} {slot : U64} @@ -271,12 +326,13 @@ theorem pgMap_tailQ (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} {slot {lu : vspace.PtSlot} (hx : PtW Pt lu.slot) (a : A) (asid vaddr : U64) : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => obj.Slot.set_cap st slot s1 (.Frame fp fsz fr fd true false asid vaddr) ⦃ s2 => - ∀ (e root : U64) (f : vspace.FrameCap) (attr : U64) (high : Bool), + ∀ (e root : U64) (f : vspace.FrameCap) (attr : U64) (high : Bool), DescTo e fp → vspace.install_page st ar s2 a lu e root asid vaddr f attr high ⦃ r => ArmQIAt st H Cs OS Vc ia ie s r.1 ∧ TabKeepOrZero st s r.1 ⦄ ⦄ ⦄ := - WP.spec_mono (pgMap_set I D P B Y hcs asid vaddr) fun _ h1 => WP.spec_mono h1 fun s2 h2 e root f attr high => - WP.spec_mono (vspace.install_page.ptw hA (I.del.vr.al _ (Or.inl hx)) hx s2 a e root asid vaddr f attr high) - fun _ w => ArmQIAt.thenPtW I P.heap P.os hpk h2 w + WP.spec_mono (pgMap_set I D P B Y hcs asid vaddr) fun _ h1 => WP.spec_mono h1 fun s2 h2 e root f attr high he => + WP.spec_mono (vspace.install_page.slotE hA (I.del.vr.al _ (Or.inl hx)) s2 a e root asid vaddr f attr high) + fun _ w => ArmQIAt.thenPtW I P.heap P.os hpk h2.1 h2.2 hx w.1 + (Or.inr (Or.inr (Or.inr (Or.inl ⟨slot, P.src, fp, fsz, fr, fd, fm, fe, fa, fv, hcs, by rw [w.2]; exact he⟩)))) /-- **PageTable Map's tail** (module docstring). -/ theorem ptMap_tailQ {s : S} {cap : capability.Cap} {slot : U64} @@ -284,16 +340,22 @@ theorem ptMap_tailQ {s : S} {cap : capability.Cap} {slot : U64} (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hpk : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) {ptr : U64} {m : Bool} {ma mv : U64} - (hcs : capA st s slot = .PageTable ptr m ma mv) {b : U64} (hx : PtW Pt b) : + (hcs : capA st s slot = .PageTable ptr m ma mv) (hm : m = false) {b : U64} (hx : PtW Pt b) : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => ∀ asid base : U64, - obj.Slot.set_cap st slot s1 (.PageTable ptr true asid base) ⦃ s2 => ∀ v : U64, + obj.Slot.set_cap st slot s1 (.PageTable ptr true asid base) ⦃ s2 => ∀ v : U64, DescTo v ptr → st.write s2 b v ⦃ s3 => ArmQIAt st H Cs OS Vc ia ie s s3 ∧ TabKeepOrZero st s s3 ⦄ ⦄ ⦄ := WP.spec_mono (sched.set_thread_state.unmMid I D) fun s1 h1 asid base => - WP.spec_mono (ptMap_set1 I D P B Y hcs h1.1 asid base) fun s2 h2 v => + WP.spec_mono (ptMap_set1 I D P B Y hcs h1.1 asid base) fun s2 h2 v hv => WP.spec_mono (LawfulStore.write_spec s2 b v) fun s3 e => by - subst e - exact ArmQIAt.thenPtW I P.heap P.os hpk h2 - ((writesIn_wr (I.del.vr.al _ (Or.inl hx))).mono fun b' e => by rw [e]; exact hx) + subst e hm + have hal := I.del.vr.al _ (Or.inl hx) + obtain ⟨a', v', hc2⟩ := h2.2.2 + have k : OSKeep st OS s2 (L.wr s2 b v) := OSKeep.of_in P.os (writesIn_wr hal) fun y hy b' _ h1 h2 hF => + I.del.vr.os b' (Or.inl (hF ▸ hx)) ⟨y, hy, h1, h2⟩ + have hc3 : capA st (L.wr s2 b v) slot = .PageTable ptr true a' v' := by rw [k.capA P.src]; exact hc2 + exact ArmQIAt.thenPtW I P.heap P.os hpk h2.1 h2.2.1 hx (writesIn_wr hal) + (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl ⟨slot, P.src, ptr, Or.inl ⟨⟨ma, mv, hcs⟩, ⟨a', v', hc3⟩⟩, + by rw [L.mem_wr_same hal]; exact hv⟩))))) /-! ## Page Map -/ @@ -312,11 +374,12 @@ local macro "pmTailQ" : tactic => `(tactic| ( refine WP.spec_bind (vspace.lookup_pt_slot.ty hvs.ty hrT hr0 _) fun lu hlu => ?_ refine spec_ite (fun _ => by errQ) (fun _ => ?_) refine WP.spec_bind (P0.vspace.rights_readable.p0 _) fun _ _ => ?_ - refine WP.spec_bind (P0.layout.paddr.p0 _) fun _ _ => ?_ - refine WP.spec_bind (P0.vspace.make_user_page.p0 _ _ _ _ _) fun en _ => ?_ + refine WP.spec_bind (paddr_spec _) fun pa hpa => ?_ + subst hpa + refine WP.spec_bind (s1page_desc hfpC hfa _ _ _ _) fun en hen => ?_ refine WP.spec_bind (pgMap_tailQ hA I D P B Y Hy.ptKs hcs (ptw_mono hTb hlu) a asid vaddr) fun s1 h1 => ?_ refine WP.spec_bind h1 fun s2 h2 => ?_ - refine WP.spec_bind (h2 _ _ _ _ _) ?_ + refine WP.spec_bind (h2 _ _ _ _ _ hen) ?_ rintro ⟨s3, a1⟩ h3 first | exact (WP.spec_ok _).2 h3 @@ -329,12 +392,16 @@ theorem vspace.decode_high_page_map.armQ (hA : P0.ArchTotal ar) {s : S} {cap0 : (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap0 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) (Hy : ArmDecHyps st H Pt n s cap0) {fp : U64} {fsz : capability.FrameSize} {fr : U64} - {fd fm fe : Bool} {fa fv : U64} (hcs : capA st s slot = .Frame fp fsz fr fd fm fe fa fv) (a : A) + {fd fm fe : Bool} {fa fv : U64} (hcs : capA st s slot = .Frame fp fsz fr fd fm fe fa fv) + (hfa : fp.val % 4096 = 0) (a : A) (vcap : capability.Cap) (vaddr vm attr : U64) : vspace.decode_high_page_map st ar s a slot ⟨fp, fsz, fr, fd, fm, fe, fa, fv⟩ vcap vaddr vm attr ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + have hfpC : CapRt.Canonical fp := by + have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ + rw [hcs] at hw; cases fe <;> exact hw.1 have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) obtain ⟨Pp, Tb, Lv, hPp, hTb, hvs⟩ := Hy.vs1 unfold vspace.decode_high_page_map step with sched.cur_thread.spec as ⟨ct, ect⟩ @@ -399,12 +466,15 @@ theorem vspace.decode_page_map.armQ (hA : P0.ArchTotal ar) {s : S} {cap0 : capab (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) (Hy : ArmDecHyps st H Pt n s cap0) {fp : U64} {fsz : capability.FrameSize} {fr : U64} {fd fm fe : Bool} {fa fv : U64} (hcs : capA st s slot = .Frame fp fsz fr fd fm fe fa fv) - (hEx : Ex0NoEpt st s extra) (a : A) (len buf : U64) : + (hEx : Ex0NoEpt st s extra) (hfa : fp.val % 4096 = 0) (a : A) (len buf : U64) : vspace.decode_page_map st ar s a len slot ⟨fp, fsz, fr, fd, fm, fe, fa, fv⟩ buf extra ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + have hfpC : CapRt.Canonical fp := by + have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ + rw [hcs] at hw; cases fe <;> exact hw.1 have hS : P0.StoreTotal st := L.total have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) obtain ⟨Pp, Tb, Lv, hPp, hTb, hvs⟩ := Hy.vs1 unfold vspace.decode_page_map step with sched.cur_thread.spec as ⟨ct, ect⟩ @@ -437,11 +507,11 @@ theorem vspace.decode_page_map.armQ (hA : P0.ArchTotal ar) {s : S} {cap0 : capab · refine spec_ite (fun _ => by errQ) (fun _ => ?_) refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun b1 _ => ?_ refine spec_ite (fun _ => ?_) (fun _ => ?_) - · exact vspace.decode_high_page_map.armQ hA I D P B Y Hy hcs a vcap vaddr vm attr + · exact vspace.decode_high_page_map.armQ hA I D P B Y Hy hcs hfa a vcap vaddr vm attr s1MapQ · refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun b1 _ => ?_ refine spec_ite (fun _ => ?_) (fun _ => ?_) - · exact vspace.decode_high_page_map.armQ hA I D P B Y Hy hcs a vcap vaddr vm attr + · exact vspace.decode_high_page_map.armQ hA I D P B Y Hy hcs hfa a vcap vaddr vm attr s1MapQ /-- **A `Frame` cap at `ARMPageMap` (extra slot 0 not an `Ept` cap) to `ArmQIAt ∧ TabKeepOrZero`** (module @@ -453,12 +523,17 @@ theorem syscall.decode_invocation.pgMap_armQIAt (hA : P0.ArchTotal ar) {s : 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) (Hy : ArmDecHyps st H Pt n s (.Frame fp fsz fr fd fm fe fa fv)) - (hcap : obj.Slot.cap st slot s = ok (.Frame fp fsz fr fd fm fe fa fv)) (hEx : Ex0NoEpt st s extra) (a : A) + (hcap : obj.Slot.cap st slot s = ok (.Frame fp fsz fr fd fm fe fa fv)) (hEx : Ex0NoEpt st s extra) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMPageMap) (len : U64) (blk call don fp' : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl 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' ⦄ := by have hcs : capA st s slot = .Frame fp fsz fr fd fm fe fa fv := okinj ((capA_eq s slot).symm.trans hcap) + have hfa : fp.val % 4096 = 0 := by + cases fd + · exact frame_al4k B P.heap P.src hcs + · exact Hy.frAl fp fsz fr fm fe fa fv rfl unfold syscall.decode_invocation step with sched.cur_thread.spec as ⟨ct, _⟩ unfold vspace.decode @@ -468,7 +543,7 @@ theorem syscall.decode_invocation.pgMap_armQIAt (hA : P0.ArchTotal ar) {s : S} simp only [vspace.as_frame, bind_ok] step with sched.cur_thread.spec as ⟨ct'', _⟩ refine spec_ite (fun _ => ?_) (fun hc => absurd hl hc) - exact vspace.decode_page_map.armQ hA I D P B Y Hy hcs hEx a len buf + exact vspace.decode_page_map.armQ hA I D P B Y Hy hcs hEx hfa a len buf /-! ## PageTable Map -/ @@ -483,11 +558,12 @@ local macro "ptTailQ" : tactic => `(tactic| ( refine spec_ite (fun _ => by errQ) (fun _ => ?_) refine WP.spec_bind (shl_and63u _) fun _ _ => ?_ try simp only [lift, bind_ok] - refine WP.spec_bind (ptMap_tailQ I D P B Y Hy.ptKs hcs (ptw_mono hTb hlu)) fun s1 h1 => ?_ + refine WP.spec_bind (ptMap_tailQ I D P B Y Hy.ptKs hcs hm (ptw_mono hTb hlu)) fun s1 h1 => ?_ refine WP.spec_bind (h1 _ _) fun s2 h2 => ?_ - refine WP.spec_bind (P0.layout.paddr.p0 _) fun _ _ => ?_ - refine WP.spec_bind (P0.vspace.make_user_table.p0 _) fun _ _ => ?_ - refine WP.spec_bind (h2 _) fun s3 h3 => ?_ + refine WP.spec_bind (paddr_spec _) fun pa hpa => ?_ + subst hpa + refine WP.spec_bind (s1tab_desc hptC hpa4) fun tv htv => ?_ + refine WP.spec_bind (h2 _ htv) fun s3 h3 => ?_ first | exact (WP.spec_ok _).2 h3 | (simp only [WP.uncurry'_pair]; exact (WP.spec_ok _).2 h3))) @@ -499,11 +575,15 @@ theorem vspace.map_high_page_table.armQ {s : S} {cap0 : capability.Cap} {slot : (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap0 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) (Hy : ArmDecHyps st H Pt n s cap0) {ptr : U64} {m : Bool} {ma mv : U64} - (hcs : capA st s slot = .PageTable ptr m ma mv) (vcap : capability.Cap) (vaddr : U64) : + (hcs : capA st s slot = .PageTable ptr m ma mv) (hm : m = false) (hpa4 : ptr.val % 4096 = 0) + (vcap : capability.Cap) (vaddr : U64) : vspace.map_high_page_table st s slot ptr vcap vaddr ⦃ r => ArmQIAt st H Cs OS Vc ia ie s r.2 ∧ TabKeepOrZero st s r.2 ⦄ := by + have hptC : CapRt.Canonical ptr := by + have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ + rw [hcs] at hw; exact hw.1 have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) obtain ⟨Pp, Tb, Lv, hPp, hTb, hvs⟩ := Hy.vs1 unfold vspace.map_high_page_table step with sched.cur_thread.spec as ⟨ct, ect⟩ @@ -527,11 +607,12 @@ theorem vspace.map_high_page_table.armQ {s : S} {cap0 : capability.Cap} {slot : refine spec_ite (fun _ => by errQ) (fun _ => ?_) refine WP.spec_bind (shl_and63u _) fun _ _ => ?_ try simp only [lift, bind_ok] - refine WP.spec_bind (ptMap_tailQ I D P B Y Hy.ptKs hcs (ptw_mono hTb hlu)) fun s1 h1 => ?_ + refine WP.spec_bind (ptMap_tailQ I D P B Y Hy.ptKs hcs hm (ptw_mono hTb hlu)) fun s1 h1 => ?_ refine WP.spec_bind (h1 _ _) fun s2 h2 => ?_ - refine WP.spec_bind (P0.layout.paddr.p0 _) fun _ _ => ?_ - refine WP.spec_bind (P0.vspace.make_user_table.p0 _) fun _ _ => ?_ - refine WP.spec_bind (h2 _) fun s3 h3 => ?_ + refine WP.spec_bind (paddr_spec _) fun pa hpa => ?_ + subst hpa + refine WP.spec_bind (s1tab_desc hptC hpa4) fun tv htv => ?_ + refine WP.spec_bind (h2 _ htv) fun s3 h3 => ?_ exact (WP.spec_ok _).2 h3 set_option hygiene false in @@ -549,15 +630,20 @@ theorem syscall.decode_invocation.ptMap_armQIAt (hA : P0.ArchTotal ar) {s : S} (.PageTable ptr mp ma mv) 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) (Hy : ArmDecHyps st H Pt n s (.PageTable ptr mp ma mv)) - (hcap : obj.Slot.cap st slot s = ok (.PageTable ptr mp ma mv)) (hEx : Ex0NoEpt st s extra) (a : A) + (hcap : obj.Slot.cap st slot s = ok (.PageTable ptr mp ma mv)) (hEx : Ex0NoEpt st s extra) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMPageTableMap) (len : U64) (blk call don fp' : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot (.PageTable ptr mp ma mv) blk call don fp' buf extra ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by have hS : P0.StoreTotal st := L.total have E0 : ArmQIAt st H Cs OS Vc ia ie s s ∧ TabKeepOrZero st s s := - ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) + ArmQIAt.ofPR ⟨B, Y⟩ ⟨Ac, D.bxi.blk⟩ id (PoolR.refl s) (ArmVs.refl s) have hcs : capA st s slot = .PageTable ptr mp ma mv := okinj ((capA_eq s slot).symm.trans hcap) + have hpa4 : ptr.val % 4096 = 0 := (Hy.ptCap ptr mp ma mv rfl).2.2 + have hptC : CapRt.Canonical ptr := by + have hw : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ + rw [hcs] at hw; exact hw.1 have h1 : lbl ≠ fl4_abi.label.ARMPageTableUnmap := by lbl_neM obtain ⟨Pp, Tb, Lv, hPp, hTb, hvs⟩ := Hy.vs1 unfold syscall.decode_invocation @@ -578,13 +664,14 @@ theorem syscall.decode_invocation.ptMap_armQIAt (hA : P0.ArchTotal ar) {s : S} · errQ try dsimp only refine spec_ite (fun _ => ?_) (fun _ => by errQ) - refine spec_ite (fun _ => by errQ) (fun _ => ?_) + refine spec_ite (fun _ => by errQ) (fun hmp => ?_) + have hm : mp = false := by simpa using hmp refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ hS) fun vaddr1 _ => ?_ obtain ⟨vcap, hvc⟩ := DPF.spec_tot (P0.obj.Slot.cap.p0 st x s hS) rw [hvc, bind_ok] refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun b _ => ?_ refine spec_ite (fun _ => ?_) (fun _ => ?_) - · refine WP.spec_bind (vspace.map_high_page_table.armQ I D P B Y Hy hcs vcap vaddr1) ?_ + · refine WP.spec_bind (vspace.map_high_page_table.armQ I D P B Y Hy hcs hm hpa4 vcap vaddr1) ?_ rintro ⟨r, s1⟩ h1 exact (WP.spec_ok _).2 h1 refine WP.spec_bind (P0.vspace.is_valid_vtable_root.p0 vcap) fun b1 _ => ?_ diff --git a/proofs/Fl4ProofsA64/P1/MdbVsMapC.lean b/proofs/Fl4ProofsA64/P1/MdbVsMapC.lean index e425ca973..4f2e65d1b 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVsMapC.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVsMapC.lean @@ -66,7 +66,7 @@ theorem UnmMid.zr {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (M : Unm · exact Or.inr rfl · exact Or.inl rfl exact ⟨(blk_of_capw M.blk w fun b hb => Or.inr (hBw b hb)).1, - M.d.trans (DFB.ofBw (LvC.of_blk M.blk) w hBw), OSKeep.trans' M.k k, M.tz.trans tz⟩ + M.d.trans (DFB.ofBw (LvC.of_blk M.blk) w hBw), OSKeep.trans' M.k k, M.tz.trans tz, M.z.trans (PtZ.zr hal ha hw)⟩ end ST end R diff --git a/proofs/Fl4ProofsA64/P1/MdbVsUnmQ.lean b/proofs/Fl4ProofsA64/P1/MdbVsUnmQ.lean index dc1d897fb..d76156369 100644 --- a/proofs/Fl4ProofsA64/P1/MdbVsUnmQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbVsUnmQ.lean @@ -26,6 +26,14 @@ unmapped (`mapped = false`, `is_ept = false`, `asid = 0`, `vaddr = 0`). * Top **`syscall.decode_invocation.pgUnmap_armQIAt`** (a `Frame … false …` cap, i.e. `is_ept = false`, at `ARMPageUnmap`). A Stage-2 (`is_ept`) frame goes to `ept::unmap` and stays stop-first (ruling item 4). +(A64-S1A gen 32, F3) `UnmMid` gains the field **`z : PtZ st Pt s0 s`** (every `PtW Pt` word kept or zeroed: `unmMid` +by `PtZ.ofKeep`, `wr0` by `PtZ.wr0`, MdbVsMapC's `zr` by `PtZ.zr`); **`UnmMid.armVsZ`**, +**`sched.set_thread_state.unmMidZ`**, **`obj.Slot.set_cap.armVsZ`** moved here from MdbArmVsW (texts unchanged); +`frU_armQ` closes the `ArmVs` clause by `ArmVsZ.thenOS`. + +(A64-S1A gen 37) the unmapped frame cap's cap-source carry by `CapSrc.remap` (`CapMeta`: same base, size, rights, +device bit). + Named premises: none. Case facts: none new (`ArmDecHyps.vs` is the gen-158 ruled field). -/ import Fl4ProofsA64.P1.MdbVsGaQ @@ -71,7 +79,7 @@ theorem frame_unm_insC (p : U64) (sz : capability.FrameSize) (r : U64) (d m e : · refine ⟨⟨fun h => ?_, fun h => ?_⟩, fun h => ?_⟩ <;> exact absurd h.2.2 (by simp [isFrA]) · intro _ _ _ h; cases h · refine ⟨?_, ?_, ?_, fun _ => rfl⟩ - · intro _ _ _ _ _ _ _ h; cases h; exact ⟨r, m, e, a, v, rfl⟩ + · intro _ _ _ _ _ _ _ _ h; cases h; exact ⟨r, m, e, a, v, rfl⟩ · intro _ _ _ h; cases h · intro _ _ _ _ h; cases h · exact ⟨eh, ep, es, rfl, fun _ _ _ _ h => by cases h⟩ @@ -119,6 +127,8 @@ structure UnmMid (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs OS P d : DFB st H Cs (L.curW s0) ∅ (PtW Pt) s0 s k : OSKeep st OS s0 s tz : TabKeepOrZero st s0 s + /-- (A64-S1A gen 32, F3) every `PtW Pt` word kept or zeroed (MdbArmVsG's `PtZ`). -/ + z : PtZ st Pt s0 s /-- **The caller's restart is an `UnmMid` step keeping the `VsR` words** (module docstring). -/ theorem sched.set_thread_state.unmMid {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} @@ -132,8 +142,8 @@ theorem sched.set_thread_state.unmMid {s : S} {cap : capability.Cap} {extra : Ae (sts_fine s _ sched.TS_RESTART (q0.nodes _ q0.cur) (q0.tcbs _ hct))) fun s1 ⟨⟨h1, fw, l⟩, w1⟩ => ?_ have df : DF st H Cs (L.curW s) ∅ s s1 := DF.ofKL fw l (tc_le _ _) have vk1 := vsk_sts I.del.vr q0 hct w1 - exact ⟨⟨h1, DFB.ofDF df, RunW.osk I D.bxi.blk (df.w.mono fun b hb => dfbv_runW (Vc := Vc) (Or.inl hb)), - TabKeepOrZero.ofOld w1.1 fun j => Or.inl (vk1 _ (Or.inr (asW_at _ j)))⟩, vk1⟩ + exact ⟨⟨h1, DFB.ofDF df, RunW.osk I D.bxi.blk (df.w.mono fun b hb => dfbv_runW (Vc := Vc) (sd := s) (Or.inl hb)), + TabKeepOrZero.ofOld w1.1 fun j => Or.inl (vk1 _ (Or.inr (asW_at _ j))), PtZ.ofKeep vk1⟩, vk1⟩ /-- **A `Wr0 Pt` step keeps `UnmMid`** (module docstring). -/ theorem UnmMid.wr0 {s0 s s' : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (M : UnmMid st H Cs OS Pt Ac s0 s) @@ -158,7 +168,38 @@ theorem UnmMid.wr0 {s0 s s' : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (M : rcases h with rfl | ⟨b, hb, rfl⟩ · exact M.blk · exact blk_capw_wr M.blk (hal b hb) (Or.inr (hBw b hb)), - M.d.trans (DFB.ofBw (LvC.of_blk M.blk) w hBw), OSKeep.trans' M.k k, M.tz.trans tz⟩ + M.d.trans (DFB.ofBw (LvC.of_blk M.blk) w hBw), OSKeep.trans' M.k k, M.tz.trans tz, M.z.trans (PtZ.wr0 hal h)⟩ + +/-- (A64-S1A gen 28; gen 32: moved here from MdbArmVsW) **An `UnmMid` stretch with its `PtW Pt` words kept or zeroed +is a zero step** (MdbArmVsG's `ArmVsZ.ofDZ`; the `DfW` half's `¬ AsW` by MdbArmTab's `DfW.notAsW`). -/ +theorem UnmMid.armVsZ {s s1 : S} {cap : capability.Cap} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s 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) + (M : UnmMid st H Cs OS Pt Ac s s1) (Z : PtZ st Pt s s1) : ArmVsZ st H OS Vc s s1 := by + obtain ⟨Q, Rq, q⟩ := D.bxi.1 + have F : TabF st H Cs OS s := TabF.of I.del.vr q B.ly.ksw P.core0 + exact ArmVsZ.ofDZ q M.d.w (fun b hd => DfW.notAsW P.heap F I.del.vr (fun c hc => q.nodes c hc) hd) Z + +/-- (A64-S1A gen 28; gen 32: moved here from MdbArmVsW) **The caller's restart gives `UnmMid ∧ PtZ`** +(`PtZ.ofKeep`). -/ +theorem sched.set_thread_state.unmMidZ {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) : + sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => + UnmMid st H Cs OS Pt Ac s s1 ∧ PtZ st Pt s s1 ⦄ := + WP.spec_mono (sched.set_thread_state.unmMid I D) fun _ h => ⟨h.1, PtZ.ofKeep h.2⟩ + +/-- (A64-S1A gen 28; gen 32: moved here from MdbArmVsW) **The in-place cap write of an `OS` slot keeps a zero +stretch** (`ArmVsZ.thenOS`: `CapW` words of an `OS` slot). -/ +theorem obj.Slot.set_cap.armVsZ {s0 s : S} {slot : U64} (hO : OSOK H.tcbs H.omega H.frame OS) (hs : slot ∈ OS) + (h : ArmVsZ st H OS Vc s0 s) (nc : capability.Cap) : + obj.Slot.set_cap st slot s nc ⦃ s' => ArmVsZ st H OS Vc s0 s' ⦄ := + WP.spec_mono (obj.Slot.set_cap.capw (st := st) (s := s) (c := nc) ((OSOK.inOS hO).slot slot hs)) fun _ w => + ArmVsZ.thenOS h w (by + rintro b (⟨t, ht, -⟩ | ⟨hb, -⟩) + · exact absurd ht (Set.notMem_empty _) + · exact hb) set_option maxHeartbeats 2000000 in /-- **The in-place write closes the arm** (module docstring). -/ @@ -188,7 +229,12 @@ theorem UnmMid.frU_armQ {s s2 : S} {cap : capability.Cap} {slot : U64} {extra : have hcO : ∀ y ∈ OS, y ≠ slot → capA st s3 y = capA st s y := fun y hy e => (hk y hy e).trans (M.k.capA hy) refine ⟨⟨B3, Y3, ⟨Ac, h3⟩, fun _ => V3, PoolOff.ofTZ tz, PoolNamed.of_map tz ?_, fun _ hPI => PoolIdx.of_frame tz.1 tz.old ?_ hPI, - PtSrc.ptCap (PtSrc.setc (PtSrc.refl s) ed (fun _ _ _ _ h => by cases h) hcO)⟩, tz⟩ + CapSrc.inv (CapSrc.setc (CapSrc.refl s) ed + (CapSrc.remap (Or.inl ⟨_, _, _, _, _, _, _, _, _, _, _, _, rfl, rfl⟩) (CapSrc.of_slot P.src hcs)) hcO), + (ArmVsZ.thenOS (UnmMid.armVsZ I D P B M M.z) w fun b hb => by + rcases hb with ⟨t, ht, -⟩ | ⟨hb, -⟩ + · exact absurd ht (Set.notMem_empty _) + · exact hb).toVs⟩, tz⟩ · intro y hy p' b' hc _ _ by_cases e : y = slot · subst e; rw [hcs] at hc; cases hc diff --git a/proofs/Fl4ProofsA64/P1/MdbXferQ.lean b/proofs/Fl4ProofsA64/P1/MdbXferQ.lean index 2e30ee91b..42775ea3f 100644 --- a/proofs/Fl4ProofsA64/P1/MdbXferQ.lean +++ b/proofs/Fl4ProofsA64/P1/MdbXferQ.lean @@ -8,6 +8,8 @@ Endpoint send, part 1): `do_ipc_transfer` keeps MdbXferL's `XJX` and the carry * * **`FootD.oskTab`**: a QueueFoot8 `K8.FootD` footprint (the `DMD` steps' words: `K8.KW` words with endpoints and notifications, debug-list words) keeps every `OS` word and the table (MdbSspTail's `ofSspW` argument, from any `SchedQueuesInvX` state). +* (A64-S1A gen 30) **`BufCw`** / **`lookup_bufKC`**: the buffer's words are MdbFpuL `FrCw` words at the lookup's + state (the buffer slot's non-device frame cap); `lookup_bufK` is now its projection (statement unchanged). * **`BufK`** / **`lookup_bufK`**: MdbRegRL's `lookup_bufIn` with the buffer's frame object kept (an `other z` object, `12 ≤ z`, by the frame cap's size), so a buffer word is no table word (MdbArmDfB's `frObj_notAsW`). * Steps (each `XJX` step beside its `XC` frame): **`XJX.regQ`** (`DfW` words, MdbArmTab's `DfW.notAsW`), @@ -20,6 +22,18 @@ Endpoint send, part 1): `do_ipc_transfer` keeps MdbXferL's `XJX` and the carry * (gen 160) `XC`'s second clause is the `VcCap` implication paired with MdbPtCapA's `PtSrc` carry (`XJX.insQ`: the derived cap by `PtSrc.al`); `ArmQIAt.ofXC` gives the `PtCap` clause by `PtSrc.ptCap`. +(A64-S1A gen 32, F1, Architect 23:41Z) **`XV`**: the memory carry beside `XC` — MdbArmVs's `ArmVsK` (every placed +`VsR` word kept) and MdbDelVsZ's `FrC` (every placement's `FrUb` carried), relative to the transfer's start (the +`XJX` base); **`XV.step`** / **`XV.trans`** / **`XV.keep`**. Each step posts it: `XJX.regT` (now with `ArmVsK`, MdbArmVsG's +`ArmVsK.ofFoot` on the `DfW` words) and `regQ` / `fw1Q`, `consQ` (**`FootD.oskTabV`**: `oskTab` with `ArmVsK`, the +`K8.FootD` words `TkW` words; `oskTab` its projection), `insQ` (the `CapW` words are `OS` slot words, `FrC` by +`FrUbP.al`), `bufQ` (**`msg.buf_set.xv`**: the buffer word is a `FrCw` word of the start state by `BufCw`, so off +every placed `VsR` word, MdbArmVsG's `FrCw.notVsR`); the loop / normal / IPC transfers carry it (`do_ipc_transfer.xjQ` +reads `lookup_bufKC`). `ArmQIAt.ofXC` takes the composite's `ArmVs`. + +(A64-S1A gen 37) `XC`'s cap carry is MdbPtCapA's `CapSrc` (def body: `PtSrc` → `CapSrc`); `ArmQIAt.ofXC` gives the +cap-source clause by `CapSrc.inv`. + Named premises: none. Case facts: none new; `hks : HeapKsOff H (L.ksb s)` (S1aPlace, ruled gen 136) and `VrOK` (`DelIn.del.vr`) are read. -/ @@ -49,47 +63,85 @@ variable (st) in /-- **The `ArmQIAt` carry** (module docstring); (gen 160) with MdbPtCapA's `PtSrc` carry beside the `VcCap` implication. -/ def XC (OS Vc : Set U64) (s0 s : S) : Prop := - ApMap st OS s0 s ∧ ((VcCap st Vc OS s0 → VcCap st Vc OS s) ∧ CapInv st (PtSrc st OS s0) OS s) ∧ + ApMap st OS s0 s ∧ ((VcCap st Vc OS s0 → VcCap st Vc OS s) ∧ CapInv st (CapSrc st OS s0) OS s) ∧ TabKeepOrZero st s0 s -theorem XC.refl (s : S) : XC st OS Vc s s := ⟨ApMap.refl s, ⟨id, PtSrc.refl s⟩, TabKeepOrZero.refl s⟩ +theorem XC.refl (s : S) : XC st OS Vc s s := ⟨ApMap.refl s, ⟨id, CapSrc.refl s⟩, TabKeepOrZero.refl s⟩ theorem XC.trans {s1 s2 s3 : S} (h1 : XC st OS Vc s1 s2) (h2 : XC st OS Vc s2 s3) : XC st OS Vc s1 s3 := - ⟨h1.1.trans h2.1, ⟨fun v => h2.2.1.1 (h1.2.1.1 v), PtSrc.trans h1.2.1.2 h2.2.1.2⟩, h1.2.2.trans h2.2.2⟩ + ⟨h1.1.trans h2.1, ⟨fun v => h2.2.1.1 (h1.2.1.1 v), CapSrc.trans h1.2.1.2 h2.2.1.2⟩, h1.2.2.trans h2.2.2⟩ theorem XC.keep {s s' : S} (k : OSKeep st OS s s') (t : TabKeep st s s') : XC st OS Vc s s' := - ⟨ApMap.keep k, ⟨fun v => v.keepO k, PtSrc.ofOSK k⟩, t.toDel⟩ + ⟨ApMap.keep k, ⟨fun v => v.keepO k, CapSrc.ofOSK k⟩, t.toDel⟩ + +variable (st) in +/-- (A64-S1A gen 32, F1) **The memory carry beside `XC`** (module docstring): every placed `VsR` word kept +(MdbArmVs's `ArmVsK`) and every placement's `FrUb` carried (MdbDelVsZ's `FrC`). -/ +def XV (H : Heap) (OS Vc : Set U64) (s0 s : S) : Prop := ArmVsK st H OS Vc s0 s ∧ FrC st OS s0 s + +theorem XV.refl (s : S) : XV st H OS Vc s s := ⟨ArmVsK.refl s, fun _ h => h⟩ + +/-- A later step keeping every `VsR` word of the first state's placements. -/ +theorem XV.step {s0 s1 s2 : S} (h : XV st H OS Vc s0 s1) (hk : L.ksb s2 = L.ksb s1) + (hK : ∀ Ub Pt, VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt → FrUb st Ub OS s0 → + VsKeep st (L.ksb s0) Pt s1 s2) (hF : FrC st OS s1 s2) : XV st H OS Vc s0 s2 := + ⟨⟨hk.trans h.1.1, fun Ub Pt hvr hf => (h.1.2 Ub Pt hvr hf).trans (hK Ub Pt hvr hf)⟩, + fun Ub hf => hF Ub (h.2 Ub hf)⟩ + +theorem XV.trans {s0 s1 s2 : S} (h1 : XV st H OS Vc s0 s1) (h2 : XV st H OS Vc s1 s2) : XV st H OS Vc s0 s2 := + h1.step h2.1.1 (fun Ub Pt hvr hf => by + have k := h2.1.2 Ub Pt (by rw [h1.1.1]; exact hvr) (h1.2 Ub hf) + rwa [h1.1.1] at k) h2.2 + +theorem XV.keep {s s' : S} (a : ArmVsK st H OS Vc s s') (k : OSKeep st OS s s') : XV st H OS Vc s s' := + ⟨a, fun _ hf => FrUb.keepO hf k⟩ /-- **`ArmQIAt` from the carry** (module docstring). -/ theorem ArmQIAt.ofXC {s0 s : S} (hS : SysL st H Cs OS ia ie s ∧ SymL st H Cs s) (hb : ∃ Ac', BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s) - (c : XC st OS Vc s0 s) : ArmQIAt st H Cs OS Vc ia ie s0 s ∧ TabKeepOrZero st s0 s := + (c : XC st OS Vc s0 s) (hV : ArmVs st H OS Vc s0 s) : ArmQIAt st H Cs OS Vc ia ie s0 s ∧ TabKeepOrZero st s0 s := ⟨⟨hS.1, hS.2, hb, c.2.1.1, PoolOff.ofTZ c.2.2, PoolNamed.of_map c.2.2 fun y hy p b hcy _ _ => let ⟨z, hz, h'⟩ := c.1.2 y hy p b hcy; ⟨z, hz, b, h'⟩, fun _ hPI => PoolIdx.of_frame c.2.2.1 c.2.2.old (fun y hy p b h => c.1.1 y hy p b h) hPI, - PtSrc.ptCap c.2.1.2⟩, c.2.2⟩ + CapSrc.inv c.2.1.2, hV⟩, c.2.2⟩ -/-- **A `K8.FootD` footprint keeps every `OS` word and the table** (module docstring). -/ -theorem FootD.oskTab {X Es Vc' Ub Pt : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List U64} {s s' : S} +/-- (A64-S1A gen 32) **A `K8.FootD` footprint keeps every `OS` word, the table and every placed `VsR` word** +(`FootD.oskTab`'s body, moved; the `VsR` words by MdbArmVsG's `ArmVsK.ofFoot`, its words `TkW` words). -/ +theorem FootD.oskTabV {X Es Vc' Ub Pt : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List U64} {s s' : S} (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hSA : ScApart H.scs H.scBits OS) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (hks : HeapKsOff H (L.ksb s)) (hkw : (L.ksb s).val + 788736 ≤ 2 ^ 64) (hc0 : 0#u64 ∈ Cs) (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s Q R) (hsub : ∀ b ∈ H.frame, b ∈ H.omega) (hE : ∀ e ∈ Es, H e = some .ep ∨ H e = some .ntfn) - (w : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits Es s s') : OSKeep st OS s s' ∧ TabKeep st s s' := by + (w : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits Es s s') : + OSKeep st OS s s' ∧ TabKeep st s s' ∧ ArmVsK st H OS Vc s s' := by have F : TabF st H Cs OS s := TabF.of hvr q hkw hc0 have k : OSKeep st OS s s' := OSKeep.of_in hO w fun x hx b hb h1 h2 hF => by rcases hF with hk | hd · exact kw7_not_os q hsub hSA hE hx hb h1 h2 (K8.KW.to7 hk) · exact dbg_not_capw q hb hd - refine ⟨k, TabKeep.ofW hvr w fun b hd => ?_⟩ - rcases hd with hd | hd - · exact fun ha => K8.KW.notAsWE hH F hvr hks hE (fun c hc => q.nodes c hc) hd ha - · intro ha - rcases hd with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ - · exact F.tcb hH hy (K := 3576#u64) (by simp) ha e.symm - · exact F.tcb hH hy (K := 3584#u64) (by simp) ha e.symm - · exact F.node rfl hc (q.nodes c hc) (by rw [debug_val]; omega) ha e.symm + have hA : ∀ b, (K8.KW st H.tcbs Cs H.frame H.scs H.scBits Es s b ∨ DbgW st H.tcbs Cs s b) → + ¬ AsW (L.ksb s) b := fun b hd => by + rcases hd with hd | hd + · exact fun ha => K8.KW.notAsWE hH F hvr hks hE (fun c hc => q.nodes c hc) hd ha + · intro ha + rcases hd with ⟨y, hy, e | e⟩ | ⟨c, hc, e⟩ + · exact F.tcb hH hy (K := 3576#u64) (by simp) ha e.symm + · exact F.tcb hH hy (K := 3584#u64) (by simp) ha e.symm + · exact F.node rfl hc (q.nodes c hc) (by rw [debug_val]; omega) ha e.symm + refine ⟨k, TabKeep.ofW hvr w hA, ArmVsK.ofFoot (Ko := ∅) hH q w (fun b hb => Or.inr (Or.inl + (hb.elim (fun h => Or.inl (K8.KW.mono h fun e he => hE e he)) fun h => Or.inr (Or.inl h)))) hA⟩ + +/-- **A `K8.FootD` footprint keeps every `OS` word and the table** (module docstring; A64-S1A gen 32: `oskTabV`'s +projection). -/ +theorem FootD.oskTab {X Es Vc' Ub Pt : Set U64} {Q : U64 → U64 → List U64} {R : U64 → List U64} {s s' : S} + (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hSA : ScApart H.scs H.scBits OS) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (hks : HeapKsOff H (L.ksb s)) + (hkw : (L.ksb s).val + 788736 ≤ 2 ^ 64) (hc0 : 0#u64 ∈ Cs) + (q : SchedQueuesInvX st H.tcbs Cs H.omega H X s Q R) (hsub : ∀ b ∈ H.frame, b ∈ H.omega) + (hE : ∀ e ∈ Es, H e = some .ep ∨ H e = some .ntfn) + (w : K8.FootD st H.tcbs Cs H.frame H.scs H.scBits Es s s') : OSKeep st OS s s' ∧ TabKeep st s s' := + let h := FootD.oskTabV (Vc := ∅) hH hO hSA hvr hks hkw hc0 q hsub hE w; ⟨h.1, h.2.1⟩ /-! ## The buffer's frame object -/ @@ -97,12 +149,18 @@ theorem FootD.oskTab {X Es Vc' Ub Pt : Set U64} {Q : U64 → U64 → List U64} { def BufK (H : Heap) (b : U64) : Prop := ∃ ptr : U64, ∃ z : Nat, H ptr = some (.other z) ∧ 12 ≤ z ∧ ptr.val ≤ b.val ∧ b.val + 1024 ≤ ptr.val + 2 ^ z +variable (st) in +/-- (A64-S1A gen 30) **The buffer's 1024 bytes are words of the object of a non-device `Frame` cap of an `OS` slot at +`s`** (MdbFpuL's `FrCw`; module docstring). -/ +def BufCw (OS : Set U64) (s : S) (b : U64) : Prop := + ∀ v : U64, b.val ≤ v.val → v.val < b.val + 1024 → FrCw st OS s v + set_option maxHeartbeats 2000000 in -/-- **`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). -/ -theorem lookup_bufK {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {ct : U64} (hx : sbA ct ∈ OS) +/-- (A64-S1A gen 30) **`lookup_bufK` with the buffer slot's frame cap exported** (`BufCw`; the body of `lookup_bufK`, +moved; `lookup_bufK` its projection, statement unchanged). -/ +theorem lookup_bufKC {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {ct : U64} (hx : sbA ct ∈ OS) (hia : (L.mem s (ibA ct)).val % 1024 = 0) : - msg.lookup_ipc_buffer st s true ct ⦃ b => b ≠ 0#u64 → BufIn H OS b ∧ BufK H b ⦄ := by + msg.lookup_ipc_buffer st s true ct ⦃ b => b ≠ 0#u64 → BufIn H OS b ∧ BufK H b ∧ BufCw st OS s b ⦄ := by unfold msg.lookup_ipc_buffer have hs : obj.Tcb.slot ct layout.tcb.SLOT_BUFFER = ok (sbA ct) := by simp [obj.Tcb.slot, lift, sbA] rw [ipc_buffer_ok, hs] @@ -162,9 +220,18 @@ theorem lookup_bufK {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {ct : 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⟩ + ⟨ptr, bits.val, hp, h12, by rw [hv]; omega, by rw [hv, hP]; 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 +/-- **`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). -/ +theorem lookup_bufK {s : S} (B : SysL st H Cs OS ia ie s) (hH : HeapOK H) {ct : U64} (hx : sbA ct ∈ OS) + (hia : (L.mem s (ibA ct)).val % 1024 = 0) : + msg.lookup_ipc_buffer st s true ct ⦃ b => b ≠ 0#u64 → BufIn H OS b ∧ BufK H b ⦄ := + WP.spec_mono (lookup_bufKC B hH hx hia) fun _ h hb => ⟨(h hb).1, (h hb).2.1⟩ + /-- **A buffer word keeps the table** (module docstring). -/ theorem msg.buf_set.tabK {Ω' Sg' Scs' Vc' Ub' Pt' : Set U64} {Z' : U64 → Nat} {s : S} (hH : HeapOK H) (hks : HeapKsOff H (L.ksb s)) (hkw : (L.ksb s).val + 788736 ≤ 2 ^ 64) @@ -187,6 +254,28 @@ theorem msg.buf_set.tabK {Ω' Sg' Scs' Vc' Ub' Pt' : Set U64} {Z' : U64 → Nat} writesIn_wr (by unfold Aligned; rw [hv]; omega) exact TabKeep.ofW hvr w fun b e ha => frObj_notAsW hks hkw hp hz (by rw [e, hv]; omega) (by rw [e, hv]; omega) ha +/-- (A64-S1A gen 32, F1) **A buffer word keeps every `VsR` word of the placements of a state `s0` whose `FrCw` +words hold the buffer** (`BufCw` at `s0`, MdbArmVsG's `FrCw.notVsR`), given the step's `OSKeep`. -/ +theorem msg.buf_set.xv {Vc : Set U64} {s0 s : S} (hH : HeapOK H) {buf : U64} (hb : BufIn H OS buf) + (hK : BufK H buf) (hc : BufCw st OS s0 buf) (x : XV st H OS Vc s0 s) {j v : U64} (hj : j.val < 128) : + msg.buf_set st s buf j v ⦃ s' => OSKeep st OS s s' → XV st H OS Vc s0 s' ⦄ := by + unfold msg.buf_set + simp only [lift, bind_ok] + refine WP.spec_mono (LawfulStore.write_spec s _ v) fun s2 e => ?_ + subst e + obtain ⟨hal, -⟩ := hb + obtain ⟨ptr, z, hp, -, h1, h2⟩ := hK + have hf := hH.fits ptr _ hp + simp only [HKind.bits] at hf + have hv : (wa buf (core.num.U64.wrapping_mul j 8#u64)).val = buf.val + 8 * j.val := by + simp [core.num.U64.wrapping_add_val_eq, core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits] + omega + have w : WritesIn st s (L.wr s (wa buf (core.num.U64.wrapping_mul j 8#u64)) v) + (· = wa buf (core.num.U64.wrapping_mul j 8#u64)) := + writesIn_wr (by unfold Aligned; rw [hv]; omega) + exact fun k => x.step w.1 (fun Ub Pt hvr hf => VsKeep.of_w hvr.al w fun b hb e => FrCw.notVsR hvr hf + (hc b (by rw [e, hv]; omega) (by rw [e, hv]; omega)) hb) fun _ hf => FrUb.keepO hf k + /-! ## The steps with the carry -/ section steps @@ -197,55 +286,76 @@ include hH hO hc0 theorem XJX.regT {Vc' Ub Pt : Set U64} {s : S} (h : XJX st H Cs OS ia ie Ac Xq s0 s) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) {t r v : U64} (ht : t ∈ H.tcbs) (hr : r.val < 384) : - obj.Tcb.set_reg st t s r v ⦃ s' => XJX st H Cs OS ia ie Ac Xq s0 s' ∧ OSKeep st OS s s' ∧ TabKeep st s s' ⦄ := by + obj.Tcb.set_reg st t s r v ⦃ s' => XJX st H Cs OS ia ie Ac Xq s0 s' ∧ OSKeep st OS s s' ∧ TabKeep st s s' ∧ + ArmVsK st H OS Vc s s' ⦄ := by obtain ⟨Q, R, q⟩ := h.blk.1 have F : TabF st H Cs OS s := TabF.of hvr q h.sys.ly.ksw hc0 exact WP.spec_mono (WP.spec_and (XJX.reg hH hO h ht hr) (obj.Tcb.set_reg.dfX (c := L.curW s) (Ko := ∅) (v := v) (LvC.of_blkX h.blk) ht hr)) fun _ ⟨⟨h', k⟩, d, _⟩ => ⟨h', k, TabKeep.ofW hvr d.w fun b hd => - DfW.notAsW hH F hvr (fun c hc => q.nodes c hc) hd⟩ + DfW.notAsW hH F hvr (fun c hc => q.nodes c hc) hd, ArmVsK.ofFoot hH q d.w (fun b hd => Or.inl hd) + fun b hd => DfW.notAsW hH F hvr (fun c hc => q.nodes c hc) hd⟩ /-- A register of any thread, with the carry. -/ theorem XJX.regQ {Vc' Ub Pt : Set U64} {s : S} (h : XJX st H Cs OS ia ie Ac Xq s0 s) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) {t r v : U64} (ht : t ∈ H.tcbs) - (hr : r.val < 384) : - obj.Tcb.set_reg st t s r v ⦃ s' => XJX st H Cs OS ia ie Ac Xq s0 s' ∧ XC st OS Vc s s' ⦄ := - WP.spec_mono (XJX.regT hH hO hc0 h hvr ht hr) fun _ ⟨h', k, t⟩ => ⟨h', XC.keep k t⟩ + (hr : r.val < 384) (x : XV st H OS Vc s0 s) : + obj.Tcb.set_reg st t s r v ⦃ s' => XJX st H Cs OS ia ie Ac Xq s0 s' ∧ XC st OS Vc s s' ∧ XV st H OS Vc s0 s' ⦄ := + WP.spec_mono (XJX.regT (Vc := Vc) hH hO hc0 h hvr ht hr) fun _ ⟨h', k, t, a⟩ => ⟨h', XC.keep k t, x.trans (XV.keep a k)⟩ /-- A word of a `BufIn ∧ BufK` buffer, with the carry. -/ theorem XJX.bufQ {Vc' Ub Pt : Set U64} {s : S} (h : XJX st H Cs OS ia ie Ac Xq s0 s) (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) {buf : U64} - (hb : BufIn H OS buf) (hK : BufK H buf) (h0 : buf ≠ 0#u64) {j v : U64} (hj : j.val < 128) : - msg.buf_set st s buf j v ⦃ s' => XJX st H Cs OS ia ie Ac Xq s0 s' ∧ XC st OS Vc s s' ⦄ := - WP.spec_mono (WP.spec_and (XJX.buf hH hO h hb h0 (v := v) hj) - (msg.buf_set.tabK (v := v) hH hks h.sys.ly.ksw hvr hb hK hj)) fun _ ⟨⟨h', k⟩, t⟩ => ⟨h', XC.keep k t⟩ + (hb : BufIn H OS buf) (hK : BufK H buf) (h0 : buf ≠ 0#u64) {j v : U64} (hj : j.val < 128) + (hc : BufCw st OS s0 buf) (x : XV st H OS Vc s0 s) : + msg.buf_set st s buf j v ⦃ s' => XJX st H Cs OS ia ie Ac Xq s0 s' ∧ XC st OS Vc s s' ∧ XV st H OS Vc s0 s' ⦄ := + WP.spec_mono (WP.spec_and (WP.spec_and (XJX.buf hH hO h hb h0 (v := v) hj) + (msg.buf_set.tabK (v := v) hH hks h.sys.ly.ksw hvr hb hK hj)) (msg.buf_set.xv (v := v) hH hb hK hc x hj)) + fun _ ⟨⟨⟨h', k⟩, t⟩, x'⟩ => ⟨h', XC.keep k t, x' k⟩ /-- A TCB's `FAULT_W1` word, with the carry. -/ theorem XJX.fw1Q {Vc' Ub Pt : Set U64} {s : S} (h : XJX st H Cs OS ia ie Ac Xq s0 s) - (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) {t v : U64} (ht : t ∈ H.tcbs) : - XJX st H Cs OS ia ie Ac Xq s0 (L.wr s (wa t 3392#u64) v) ∧ XC st OS Vc s (L.wr s (wa t 3392#u64) v) := by + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) {t v : U64} (ht : t ∈ H.tcbs) + (x : XV st H OS Vc s0 s) : + XJX st H Cs OS ia ie Ac Xq s0 (L.wr s (wa t 3392#u64) v) ∧ XC st OS Vc s (L.wr s (wa t 3392#u64) v) ∧ + XV st H OS Vc s0 (L.wr s (wa t 3392#u64) v) := by obtain ⟨Q, R, q⟩ := h.blk.1 have F : TabF st H Cs OS s := TabF.of hvr q h.sys.ly.ksw hc0 have C := LvC.of_blkX h.blk have d : DF st H Cs (L.curW s) ∅ s (L.wr s (wa t 3392#u64) v) := tcb_wr_df C ht (by simp) (by simp) (by simp) (by simp) (by unfold LvO; simp) - exact ⟨XJX.fw1 hH hO h ht, XC.keep (DFB.oskX (Bw := fun _ => False) hO h.blk (fun _ _ _ _ _ h => h) (DFB.ofDF d)) - (TabKeep.ofW hvr d.w fun b hd => DfW.notAsW hH F hvr (fun c hc => q.nodes c hc) hd)⟩ + have k := DFB.oskX (Bw := fun _ => False) hO h.blk (fun _ _ _ _ _ h => h) (DFB.ofDF d) + exact ⟨XJX.fw1 hH hO h ht, XC.keep k (TabKeep.ofW hvr d.w fun b hd => DfW.notAsW hH F hvr (fun c hc => q.nodes c hc) hd), + x.trans (XV.keep (ArmVsK.ofFoot hH q d.w (fun b hd => Or.inl hd) + fun b hd => DfW.notAsW hH F hvr (fun c hc => q.nodes c hc) hd) k)⟩ -/-- `update_consumed` of a heap SC at the start state, with the carry. -/ -theorem XJX.consQ {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U64} +/-- `consQ` with every `OS` word kept (A64-S1A gen 41). -/ +theorem XJX.consS {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (hSA : ScApart H.scs H.scBits OS) (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (h : XJX st H Cs OS ia ie Ac Xq s s) {c : U64} (hc : c ∈ H.scs) : - schedcontext.update_consumed st ar s a c ⦃ r => XJX st H Cs OS ia ie Ac Xq s r.2 ∧ XC st OS Vc s r.2 ⦄ := by + schedcontext.update_consumed st ar s a c ⦃ r => XJX st H Cs OS ia ie Ac Xq s r.2 ∧ XC st OS Vc s r.2 ∧ + XV st H OS Vc s r.2 ∧ OSKeep st OS s r.2 ⦄ := by obtain ⟨Q, R, q⟩ := h.blk.1 refine WP.spec_mono (WP.spec_and (XJX.cons hA a P hSA h hc) (K8.schedcontext.update_consumed.blkX hA s a c h.blk hc)) ?_ rintro ⟨c1, s1⟩ ⟨h1, -, f1, -⟩ - obtain ⟨k, t⟩ := FootD.oskTab hH hO hSA hvr hks h.sys.ly.ksw hc0 q h.blk.2.2.2.2.sub + obtain ⟨k, t, v⟩ := FootD.oskTabV (Vc := Vc) hH hO hSA hvr hks h.sys.ly.ksw hc0 q h.blk.2.2.2.2.sub (fun e he => absurd he (Set.notMem_empty e)) (K8.Foot.d f1) - exact ⟨h1, XC.keep k t⟩ + exact ⟨h1, XC.keep k t, XV.keep v k, k⟩ + +/-- `update_consumed` of a heap SC at the start state, with the carry. -/ +theorem XJX.consQ {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {Rp Nt Vc' Ub Pt : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (hSA : ScApart H.scs H.scBits OS) + (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) + (h : XJX st H Cs OS ia ie Ac Xq s s) {c : U64} (hc : c ∈ H.scs) : + schedcontext.update_consumed st ar s a c ⦃ r => XJX st H Cs OS ia ie Ac Xq s r.2 ∧ XC st OS Vc s r.2 ∧ + XV st H OS Vc s r.2 ⦄ := + WP.spec_mono (XJX.consS hH hO hc0 hA a P hSA hks hvr h hc) fun r h => by + obtain ⟨_, _⟩ := r + exact ⟨h.1, h.2.1, h.2.2.1⟩ set_option maxHeartbeats 2000000 in /-- `cdt.insert` of `derive_cap`'s result into the loop's destination, with the carry. -/ @@ -254,8 +364,8 @@ theorem XJX.insQ (hW : WinOK H.tcbs H.omega) {Ω' Sg' Scs' Vc' Ub' Pt' : Set U64 (hx : x ∈ OS) (hD : XD st H OS s d) (hd0 : d ≠ 0#u64) {G : List (List U64)} {par : U64 → Option U64} (hT : TreeA st OS G par s) {nc : capability.Cap} (C : InsCU nc (capA st s x)) (hw : CapRt.EncWf nc) (hnc : nc ≠ .Null) (hut : isUtA (capA st s x) = true → ∀ z, ¬ Mdb.Desc par z x) - (hE : ApE nc (capA st s x)) : - cdt.insert st s nc x d ⦃ s' => XJX st H Cs OS ia ie Ac Xq s0 s' ∧ XC st OS Vc s s' ⦄ := by + (hE : ApE nc (capA st s x)) (xv : XV st H OS Vc s0 s) : + cdt.insert st s nc x d ⦃ s' => XJX st H Cs OS ia ie Ac Xq s0 s' ∧ XC st OS Vc s s' ∧ XV st H OS Vc s0 s' ⦄ := by obtain ⟨hdO, hdN, -, -, -⟩ := hD hd0 have hxd : x ≠ d := fun e => C.nn (by rw [e]; exact hdN) have nn := (h.sys.sys.stz.1.1.mdbS.lnk hO hx).2 @@ -264,16 +374,30 @@ theorem XJX.insQ (hW : WinOK H.tcbs H.omega) {Ω' Sg' Scs' Vc' Ub' Pt' : Set U64 rw [capA_eq, bind_ok] refine WP.spec_mono (cdt.insert_with_cap.lrF hO.inOS (LR.self s) hx hdO hxd (hO.canon hW hdO) rfl C.nn hw nn) ?_ rintro s' ⟨w, -, ed, -, -, ek, es⟩ - refine ⟨ApMap.ins hx hdO ed es ek (ApI.of C.fe hE) hdN, ⟨fun V z hz => ?_, fun z hz => ?_⟩, tabKZ_cw hvr rfl w⟩ + have xv' : XV st H OS Vc s s' := by + refine ⟨ArmVsK.ofW w fun _ _ hvr' _ b hw hv => ?_, fun Ub' hf z hz => ?_⟩ + · rcases hw with ⟨t, ht, -⟩ | ⟨hin, -⟩ + · exact absurd ht (Set.notMem_empty t) + · exact hvr'.os b hv hin + · by_cases e1 : z = d + · rw [e1, ed]; exact FrUbP.al (Or.inl C.al) C.fe (hf x hx) + by_cases e2 : z = x + · subst e2 + rcases es with e | ⟨_, _, _, _, e⟩ + · rw [e]; exact hf z hz + · rw [e]; exact fun _ _ _ _ _ _ _ h => by cases h + · rw [ek z hz e2 e1]; exact hf z hz + refine ⟨⟨ApMap.ins hx hdO ed es ek (ApI.of C.fe hE) hdN, ⟨fun V z hz => ?_, fun z hz => ?_⟩, tabKZ_cw hvr rfl w⟩, + xv.trans xv'⟩ rotate_left · by_cases e1 : z = d - · rw [e1, ed]; exact PtSrc.al (Or.inl C.al) C.fe (PtSrc.of_slot hx rfl) + · rw [e1, ed]; exact CapSrc.al (Or.inl C.al) C.fe (CapSrc.of_slot hx rfl) by_cases e2 : z = x · subst e2 rcases es with e | ⟨p, b, j, dd, e⟩ - · rw [e]; exact PtSrc.of_slot hz rfl - · rw [e]; exact PtSrc.ut s p b j dd - · rw [ek z hz e2 e1]; exact PtSrc.of_slot hz rfl + · rw [e]; exact CapSrc.of_slot hz rfl + · rw [e]; exact CapSrc.ut s p b j dd + · rw [ek z hz e2 e1]; exact CapSrc.of_slot hz rfl by_cases e1 : z = d · rw [e1, ed]; exact VcCapP.al (Or.inl C.al) C.fe (V x hx) by_cases e2 : z = x @@ -285,28 +409,69 @@ theorem XJX.insQ (hW : WinOK H.tcbs H.omega) {Ω' Sg' Scs' Vc' Ub' Pt' : Set U64 end steps +/-! ## The transfer's slot fact -/ + +/-- (A64-S1A gen 41) **The slot fact of a transfer**: every `OS` slot keeps its capability, or one derived copy of a +slot's capability went into an empty slot and that source's untyped index may have moved. -/ +def XferSlots (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s r : S) : Prop := + (∀ z ∈ OS, capA st r z = capA st s z) ∨ ∃ src ∈ OS, ∃ dest ∈ OS, src ≠ dest ∧ capA st s dest = .Null ∧ + (∃ q c, objects.derive_cap st q src (capA st s src) = ok (.Ok c) ∧ capA st r dest = c) ∧ + FullA (capA st r src) (capA st s src) ∧ ∀ z ∈ OS, z ≠ src → z ≠ dest → capA st r z = capA st s z + +theorem XferSlots.refl (s : S) : XferSlots st OS s s := Or.inl fun _ _ => rfl + +theorem XferSlots.keep {s q r : S} (h : XferSlots st OS s q) (k : ∀ z ∈ OS, capA st r z = capA st q z) : + XferSlots st OS s r := by + rcases h with same | ⟨src, hs, dest, hd, ne, empty, ⟨x, c, derived, new⟩, turned, others⟩ + · exact Or.inl fun z hz => (k z hz).trans (same z hz) + · exact Or.inr ⟨src, hs, dest, hd, ne, empty, ⟨x, c, derived, (k dest hd).trans new⟩, (k src hs).symm ▸ turned, + fun z hz n1 n2 => (k z hz).trans (others z hz n1 n2)⟩ + +theorem XferSlots.before {s q r : S} (k : ∀ z ∈ OS, capA st q z = capA st s z) (h : XferSlots st OS q r) : + XferSlots st OS s r := by + rcases h with same | ⟨src, hs, dest, hd, ne, empty, ⟨x, c, derived, new⟩, turned, others⟩ + · exact Or.inl fun z hz => (same z hz).trans (k z hz) + · exact Or.inr ⟨src, hs, dest, hd, ne, (k dest hd).symm.trans empty, ⟨x, c, k src hs ▸ derived, new⟩, + k src hs ▸ turned, fun z hz n1 n2 => (others z hz n1 n2).trans (k z hz)⟩ + +/-- `cdt.insert`'s slots: the new capability, the source possibly turned, every other slot kept. -/ +theorem cdt.insert.slots (hO : OSOK H.tcbs H.omega H.frame OS) {s : S} (hm : MdbS st OS s) {nc : capability.Cap} + {src dest : U64} (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) (hdc : obj.sext48 dest = ok dest) + (hsc0 : capA st s src ≠ .Null) (hw : CapRt.EncWf nc) : + cdt.insert st s nc src dest ⦃ s' => capA st s' dest = nc ∧ FullA (capA st s' src) (capA st s src) ∧ + ∀ z ∈ OS, z ≠ src → z ≠ dest → capA st s' z = capA st s z ⦄ := by + have next := (hm.lnk hO hsrc).2 + unfold cdt.insert + rw [capA_eq, bind_ok] + refine WP.spec_mono (WP.spec_and (cdt.insert_with_cap.lrF hO (LR.self s) hsrc hd hsd hdc rfl hsc0 hw next) + (cdt.insert_with_cap.srcF hO hsrc hd hsd rfl hw next)) fun s' ⟨⟨_, _, new, _, _, others, _⟩, turned⟩ => ?_ + exact ⟨new, turned, others⟩ + /-! ## `transfer_caps` and the transfer -/ set_option maxHeartbeats 4000000 in -/-- **`transfer_caps`' loop with the carry** (MdbXferL's `ipc.transfer_caps_loop.xjX` text). -/ -theorem ipc.transfer_caps_loop.xjQ {Xq Vc' Ub Pt : Set U64} {s0 s : S} (hH : HeapOK H) +/-- **`transfer_caps`' loop with the carry and the slot fact** (A64-S1A gen 41). -/ +theorem ipc.transfer_caps_loop.xjS {Xq Vc' Ub Pt : Set U64} {s0 s : S} (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hc0 : 0#u64 ∈ Cs) (hW : WinOK H.tcbs H.omega) (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) {extra : Aeneas.Std.Array obj.Slot 3#usize} {ep rb : U64} {out : msginfo.MessageInfo} {dest i : U64} (h : XJX st H Cs OS ia ie Ac Xq s0 s) (hD : XD st H OS s dest) - (hx : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hb : BufIn H OS rb) (hK : BufK H rb) (h0 : rb ≠ 0#u64) : + (hx : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hb : BufIn H OS rb) (hK : BufK H rb) (h0 : rb ≠ 0#u64) + (hcw : BufCw st OS s0 rb) (xv : XV st H OS Vc s0 s) : ipc.transfer_caps_loop st s extra ep rb out dest i ⦃ r => - XJX st H Cs OS ia ie Ac Xq s0 r.1 ∧ XC st OS Vc s r.1 ⦄ := by + XJX st H Cs OS ia ie Ac Xq s0 r.1 ∧ XC st OS Vc s r.1 ∧ XV st H OS Vc s0 r.1 ∧ XferSlots st OS s r.1 ⦄ := by have hS : P0.StoreTotal st := L.total unfold ipc.transfer_caps_loop apply loop.spec_decr_nat (measure := fun y => 3 - y.2.2.2.val) - (inv := fun y => (XJX st H Cs OS ia ie Ac Xq s0 y.1 ∧ XC st OS Vc s y.1) ∧ XD st H OS y.1 y.2.2.1) - · rintro ⟨s1, o1, d1, j⟩ ⟨⟨h1, c1⟩, hd1⟩ + (inv := fun y => (XJX st H Cs OS ia ie Ac Xq s0 y.1 ∧ XC st OS Vc s y.1 ∧ XV st H OS Vc s0 y.1) ∧ + XD st H OS y.1 y.2.2.1 ∧ (y.2.2.1 ≠ 0#u64 → ∀ z ∈ OS, capA st y.1 z = capA st s z) ∧ + XferSlots st OS s y.1) + · rintro ⟨s1, o1, d1, j⟩ ⟨⟨h1, c1, x1⟩, hd1, w1, S1⟩ have hk1 : L.ksb s1 = L.ksb s := c1.2.2.1 have hvr1 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s1) Pt := by rw [hk1]; exact hvr have hks1 : HeapKsOff H (L.ksb s1) := by rw [hk1]; exact hks unfold ipc.transfer_caps_loop.body - refine spec_ite (fun hj => ?_) fun _ => (WP.spec_ok _).2 ⟨h1, c1⟩ + refine spec_ite (fun hj => ?_) fun _ => (WP.spec_ok _).2 ⟨h1, c1, x1, S1⟩ have hj' : j.val < 3 := by simpa using hj have hl : (UScalar.cast .Usize j).val < extra.val.length := by have : 2 ^ 32 ≤ 2 ^ System.Platform.numBits := by @@ -316,44 +481,68 @@ theorem ipc.transfer_caps_loop.xjQ {Xq Vc' Ub Pt : Set U64} {s0 s : S} (hH : Hea simp only [lift, bind_ok] refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec extra _ hl) fun sl hsl => ?_ simp only [obj.Slot.is_null, bind_ok] - refine spec_ite (fun _ => (WP.spec_ok _).2 ⟨h1, c1⟩) fun hsl0 => ?_ + refine spec_ite (fun _ => (WP.spec_ok _).2 ⟨h1, c1, x1, S1⟩) fun hsl0 => ?_ refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec extra _ hl) fun x hxs => ?_ have hxO : x ∈ OS := hx x (hxs ▸ List.getElem_mem hl) (by rw [hxs, ← hsl]; simpa using hsl0) rw [capA_eq, bind_ok] refine WP.spec_bind (P0.ipc.unwrapped_badge.p0 (capA st s1 x) ep) fun o _ => ?_ rcases o with _ | badge · simp only [obj.Slot.is_null, bind_ok] - refine spec_ite (fun _ => (WP.spec_ok _).2 ⟨h1, c1⟩) fun hd0 => ?_ + refine spec_ite (fun _ => (WP.spec_ok _).2 ⟨h1, c1, x1, S1⟩) fun hd0 => ?_ have hd0' : d1 ≠ 0#u64 := by simpa using hd0 obtain ⟨G, par, hT⟩ := h1.sys.sys.stz.1.1.tu - refine WP.spec_bind (WP.spec_and (derive_insCU hO hT h1.sys.sys.stz.1.2.1 hxO) - (objects.derive_cap.apE s1 x (capA st s1 x))) fun r ⟨hr, hra⟩ => ?_ + refine WP.spec_bind (WP.spec_and (WP.spec_and (derive_insCU hO hT h1.sys.sys.stz.1.2.1 hxO) + (objects.derive_cap.apE s1 x (capA st s1 x))) + (spec_eqv (P0.objects.derive_cap.p0 st s1 x (capA st s1 x) L.total))) fun r ⟨⟨hr, hra⟩, eq, _⟩ => ?_ rcases r with c | _ · simp only by_cases hc0' : c = .Null · subst hc0' rw [is_null_t, bind_ok] simp only [↓reduceIte] - exact (WP.spec_ok _).2 ⟨h1, c1⟩ + exact (WP.spec_ok _).2 ⟨h1, c1, x1, S1⟩ rw [is_null_f hc0', bind_ok] simp only [Bool.false_eq_true, ↓reduceIte] obtain ⟨C, hw, hut⟩ := hr c rfl hc0' - refine WP.spec_bind (XJX.insQ (Vc := Vc) hH hO hc0 hW h1 hvr1 hxO hd1 hd0' hT C hw hc0' hut (hra c rfl)) - fun s2 ⟨h2, c2⟩ => ?_ + obtain ⟨hdO, hdN, -, -, -⟩ := hd1 hd0' + have hxd : x ≠ d1 := fun e => C.nn (by rw [e]; exact hdN) + refine WP.spec_bind (WP.spec_and + (XJX.insQ (Vc := Vc) hH hO hc0 hW h1 hvr1 hxO hd1 hd0' hT C hw hc0' hut (hra c rfl) x1) + (cdt.insert.slots hO h1.sys.sys.stz.1.1.mdbS hxO hdO hxd (hO.canon hW hdO) C.nn hw)) + fun s2 ⟨⟨h2, c2, x2⟩, new, turned, others⟩ => ?_ + have S2 : XferSlots st OS s s2 := XferSlots.before (w1 hd0') + (Or.inr ⟨x, hxO, d1, hdO, hxd, hdN, ⟨s1, c, eq, new⟩, turned, others⟩) step - exact ⟨h2, c1.trans c2, fun h => absurd rfl h, by omega⟩ - · exact (WP.spec_ok _).2 ⟨h1, c1⟩ + exact ⟨h2, c1.trans c2, x2, fun h => absurd rfl h, fun h => absurd rfl h, S2, by omega⟩ + · exact (WP.spec_ok _).2 ⟨h1, c1, x1, S1⟩ · simp only [msg.BUF_CAPS, msg.BUF_USER_DATA, msg.MSG_MAX_LENGTH] step step try simp only [lift, bind_ok] have hix : (core.num.U64.wrapping_add i3 j).val < 128 := by simp [core.num.U64.wrapping_add_val_eq, U64.size_def, U64.numBits]; omega - refine WP.spec_bind (WP.spec_and (XJX.bufQ (Vc := Vc) hH hO hc0 h1 hks1 hvr1 hb hK h0 (v := badge) hix) - (XJX.buf hH hO h1 hb h0 (v := badge) hix)) fun s2 ⟨⟨h2, c2⟩, _, k2⟩ => ?_ + refine WP.spec_bind (WP.spec_and (XJX.bufQ (Vc := Vc) hH hO hc0 h1 hks1 hvr1 hb hK h0 (v := badge) hix hcw x1) + (XJX.buf hH hO h1 hb h0 (v := badge) hix)) fun s2 ⟨⟨h2, c2, x2⟩, _, k2⟩ => ?_ step* - exact ⟨h2, c1.trans c2, hd1.keep k2, by omega⟩ - · exact ⟨⟨h, XC.refl s⟩, hD⟩ + exact ⟨h2, c1.trans c2, x2, hd1.keep k2, fun nz z hz => (k2.capA hz).trans (w1 nz z hz), + S1.keep fun z hz => k2.capA hz, by omega⟩ + · exact ⟨⟨h, XC.refl s, xv⟩, hD, fun _ _ _ => rfl, XferSlots.refl s⟩ + +set_option maxHeartbeats 4000000 in +/-- **`transfer_caps`' loop with the carry** (MdbXferL's `ipc.transfer_caps_loop.xjX` text). -/ +theorem ipc.transfer_caps_loop.xjQ {Xq Vc' Ub Pt : Set U64} {s0 s : S} (hH : HeapOK H) + (hO : OSOK H.tcbs H.omega H.frame OS) (hc0 : 0#u64 ∈ Cs) (hW : WinOK H.tcbs H.omega) + (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) + {extra : Aeneas.Std.Array obj.Slot 3#usize} {ep rb : U64} + {out : msginfo.MessageInfo} {dest i : U64} (h : XJX st H Cs OS ia ie Ac Xq s0 s) (hD : XD st H OS s dest) + (hx : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) (hb : BufIn H OS rb) (hK : BufK H rb) (h0 : rb ≠ 0#u64) + (hcw : BufCw st OS s0 rb) (xv : XV st H OS Vc s0 s) : + ipc.transfer_caps_loop st s extra ep rb out dest i ⦃ r => + XJX st H Cs OS ia ie Ac Xq s0 r.1 ∧ XC st OS Vc s r.1 ∧ XV st H OS Vc s0 r.1 ⦄ := + WP.spec_mono (ipc.transfer_caps_loop.xjS (Vc := Vc) (out := out) (i := i) hH hO hc0 hW hks hvr h hD hx hb hK h0 hcw + xv) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨h.1, h.2.1, h.2.2.1⟩ /-- The normal transfer's copy-phase invariant: `XJX`, every `OS` word and the table kept since `s`. -/ def XKoQ (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs OS : Set U64) (ia ie : Nat) (Ac Xq : Set U64) @@ -361,28 +550,31 @@ def XKoQ (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs OS : Set U64 (XJX st H Cs OS ia ie Ac Xq s s2 ∧ OSKeep st OS s s2) ∧ TabKeep st s s2 set_option maxHeartbeats 4000000 in -/-- **`do_normal_transfer` with the carry** (MdbXferL's `ipc.do_normal_transfer.xjX` text). -/ -theorem ipc.do_normal_transfer.xjQ {Xq Rp Nt Vc' Ub Pt : Set U64} {s : S} (hH : HeapOK H) +/-- **`do_normal_transfer` with the carry and the slot fact** (A64-S1A gen 41). -/ +theorem ipc.do_normal_transfer.xjS {Xq Rp Nt Vc' Ub Pt : Set U64} {s : S} (hH : HeapOK H) (hO : OSOK H.tcbs H.omega H.frame OS) (hc0 : 0#u64 ∈ Cs) (hW : WinOK H.tcbs H.omega) (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (hTy : SlotTy st H.tcbs H.omega H.frame H Rp Nt OS s) (hTS : TcbSlotsOS H.tcbs OS) (h : XJX st H Cs OS ia ie Ac Xq s s) {snd sb ep badge rcv rb : U64} {grant : Bool} (hs : snd ∈ H.tcbs) - (hr : rcv ∈ H.tcbs) (hb : rb ≠ 0#u64 → BufIn H OS rb ∧ BufK H rb) : + (hr : rcv ∈ H.tcbs) (hb : rb ≠ 0#u64 → BufIn H OS rb ∧ BufK H rb ∧ BufCw st OS s rb) : ipc.do_normal_transfer st s snd sb ep badge grant rcv rb ⦃ s' => - XJX st H Cs OS ia ie Ac Xq s s' ∧ XC st OS Vc s s' ⦄ := by + XJX st H Cs OS ia ie Ac Xq s s' ∧ XC st OS Vc s s' ∧ XV st H OS Vc s s' ∧ XferSlots st OS s s' ⦄ := by have hP : P0.StoreTotal st := L.total - have hR : ∀ s2 r v, XKoQ st H Cs OS ia ie Ac Xq s s2 → r.val < 384 → obj.Tcb.set_reg st rcv s2 r v ⦃ XKoQ st H Cs OS ia ie Ac Xq s ⦄ := fun s2 _ _ h2 hr' => by - have hvr2 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s2) Pt := by rw [h2.2.1]; exact hvr - exact WP.spec_mono (XJX.regT hH hO hc0 h2.1.1 hvr2 hr hr') - fun _ ⟨h3, k3, t3⟩ => ⟨⟨h3, OSKeep.trans' h2.1.2 k3⟩, h2.2.trans t3⟩ - have hB : rb ≠ 0#u64 → ∀ s2 j v, XKoQ st H Cs OS ia ie Ac Xq s s2 → j.val < 128 → - msg.buf_set st s2 rb j v ⦃ XKoQ st H Cs OS ia ie Ac Xq s ⦄ := - fun h0 s2 _ _ h2 hj => by + have hR : ∀ s2 r v, (XKoQ st H Cs OS ia ie Ac Xq s s2 ∧ XV st H OS Vc s s2) → r.val < 384 → + obj.Tcb.set_reg st rcv s2 r v ⦃ s3 => XKoQ st H Cs OS ia ie Ac Xq s s3 ∧ XV st H OS Vc s s3 ⦄ := + fun s2 _ _ ⟨h2, x2⟩ hr' => by + have hvr2 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s2) Pt := by rw [h2.2.1]; exact hvr + exact WP.spec_mono (XJX.regT (Vc := Vc) hH hO hc0 h2.1.1 hvr2 hr hr') + fun _ ⟨h3, k3, t3, a3⟩ => ⟨⟨⟨h3, OSKeep.trans' h2.1.2 k3⟩, h2.2.trans t3⟩, x2.trans (XV.keep a3 k3)⟩ + have hB : rb ≠ 0#u64 → ∀ s2 j v, (XKoQ st H Cs OS ia ie Ac Xq s s2 ∧ XV st H OS Vc s s2) → j.val < 128 → + msg.buf_set st s2 rb j v ⦃ s3 => XKoQ st H Cs OS ia ie Ac Xq s s3 ∧ XV st H OS Vc s s3 ⦄ := + fun h0 s2 _ _ ⟨h2, x2⟩ hj => by have hvr2 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s2) Pt := by rw [h2.2.1]; exact hvr have hks2 : HeapKsOff H (L.ksb s2) := by rw [h2.2.1]; exact hks - exact WP.spec_mono (WP.spec_and (XJX.buf hH hO h2.1.1 (hb h0).1 h0 hj) - (msg.buf_set.tabK hH hks2 h2.1.1.sys.ly.ksw hvr2 (hb h0).1 (hb h0).2 hj)) - fun _ ⟨⟨h3, k3⟩, t3⟩ => ⟨⟨h3, OSKeep.trans' h2.1.2 k3⟩, h2.2.trans t3⟩ + exact WP.spec_mono (WP.spec_and (WP.spec_and (XJX.buf hH hO h2.1.1 (hb h0).1 h0 hj) + (msg.buf_set.tabK hH hks2 h2.1.1.sys.ly.ksw hvr2 (hb h0).1 (hb h0).2.1 hj)) + (msg.buf_set.xv hH (hb h0).1 (hb h0).2.1 (hb h0).2.2 x2 hj)) + fun _ ⟨⟨⟨h3, k3⟩, t3⟩, x3⟩ => ⟨⟨⟨h3, OSKeep.trans' h2.1.2 k3⟩, h2.2.trans t3⟩, x3 k3⟩ have hs0 : snd ∈ OS := by have := hTS snd hs 0#u64 (by simp); rwa [slotIdx0] at this have hr0 : rcv ∈ OS := by have := hTS rcv hr 0#u64 (by simp); rwa [slotIdx0] at this unfold ipc.do_normal_transfer @@ -395,47 +587,66 @@ theorem ipc.do_normal_transfer.xjQ {Xq Rp Nt Vc' Ub Pt : Set U64} {s : S} (hH : · exact (WP.spec_ok _).2 fun x hx h0 => (hr' e rfl x hx h0).1 · exact (WP.spec_ok _).2 fun x hx h0 => absurd (by simpa [ipc.NO_EXTRA_CAPS] using hx) h0 · exact (WP.spec_ok _).2 fun x hx h0 => absurd (by simpa [ipc.NO_EXTRA_CAPS] using hx) h0 - refine WP.spec_bind (msg.copy_mrs.gx (I := XKoQ st H Cs OS ia ie Ac Xq s) (snd := snd) (sb := sb) (n := tag.length) - ⟨⟨h, OSKeep.rfl' _⟩, TabKeep.refl s⟩ hR hB) ?_ - rintro ⟨n, s1⟩ ⟨⟨h1, k1⟩, t1⟩ + refine WP.spec_bind (msg.copy_mrs.gx (I := fun s2 => XKoQ st H Cs OS ia ie Ac Xq s s2 ∧ XV st H OS Vc s s2) + (snd := snd) (sb := sb) (n := tag.length) ⟨⟨⟨h, OSKeep.rfl' _⟩, TabKeep.refl s⟩, XV.refl s⟩ hR hB) ?_ + rintro ⟨n, s1⟩ ⟨⟨⟨h1, k1⟩, t1⟩, x1⟩ try simp only [WP.uncurry'_pair] have c1 : XC st OS Vc s s1 := XC.keep k1 t1 have hvr1 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s1) Pt := by rw [t1.1]; exact hvr have hks1 : HeapKsOff H (L.ksb s1) := by rw [t1.1]; exact hks + have S1 : XferSlots st OS s s1 := Or.inl fun z hz => k1.capA hz refine WP.spec_bind (Pₘ := fun r : msginfo.MessageInfo × S => - XJX st H Cs OS ia ie Ac Xq s r.2 ∧ XC st OS Vc s r.2) ?_ ?_ + XJX st H Cs OS ia ie Ac Xq s r.2 ∧ XC st OS Vc s r.2 ∧ XV st H OS Vc s r.2 ∧ XferSlots st OS s r.2) ?_ ?_ · unfold ipc.transfer_caps refine WP.spec_bind (P0.msginfo.MessageInfo.new.p0 _ _ _ _) fun out _ => ?_ have hl0 : (0#usize).val < extra.val.length := by rw [extra.property]; simp refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec extra 0#usize hl0) fun x0 _ => ?_ simp only [obj.Slot.is_null, bind_ok] - refine spec_ite (fun _ => (WP.spec_ok _).2 ⟨h1, c1⟩) fun _ => - spec_ite (fun _ => (WP.spec_ok _).2 ⟨h1, c1⟩) fun h0 => ?_ + refine spec_ite (fun _ => (WP.spec_ok _).2 ⟨h1, c1, x1, S1⟩) fun _ => + spec_ite (fun _ => (WP.spec_ok _).2 ⟨h1, c1, x1, S1⟩) fun h0 => ?_ have hTy1 := hTy.keep k1 refine WP.spec_bind (ipc.get_receive_slot.cov hTy1 hr0 rb) fun d hd => ?_ have hD : XD st H OS s1 d := fun hd0 => by obtain ⟨hdO, hcv, hdN⟩ := hd hd0 have hof := SlotCov.offs hH h1.sys hcv exact ⟨hdO, hdN, SlotCov.covZ hO hTy1 h1.sys.sys.stz.1.1 hdO hcv, hof.2.2, hof.2.1⟩ - refine WP.spec_bind (ipc.transfer_caps_loop.xjQ (Vc := Vc) (out := out) (i := 0#u64) hH hO hc0 hW hks1 hvr1 h1 hD hx - (hb h0).1 (hb h0).2 h0) ?_ - rintro ⟨s2, o2, i⟩ ⟨h2, c2⟩ - exact (WP.spec_ok _).2 ⟨h2, c1.trans c2⟩ - rintro ⟨out, s2⟩ ⟨h2, c2⟩ + refine WP.spec_bind (ipc.transfer_caps_loop.xjS (Vc := Vc) (out := out) (i := 0#u64) hH hO hc0 hW hks1 hvr1 h1 hD hx + (hb h0).1 (hb h0).2.1 h0 (hb h0).2.2 x1) ?_ + rintro ⟨s2, o2, i⟩ ⟨h2, c2, x2, S2⟩ + exact (WP.spec_ok _).2 ⟨h2, c1.trans c2, x2, XferSlots.before (fun z hz => k1.capA hz) S2⟩ + rintro ⟨out, s2⟩ ⟨h2, c2, x2, S2⟩ try simp only [WP.uncurry'_pair] have hvr2 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s2) Pt := by rw [c2.2.2.1]; exact hvr - refine WP.spec_bind (Pₘ := fun s3 => XJX st H Cs OS ia ie Ac Xq s s3 ∧ XC st OS Vc s s3) ?_ fun s3 ⟨h3, c3⟩ => ?_ + refine WP.spec_bind (Pₘ := fun s3 => XJX st H Cs OS ia ie Ac Xq s s3 ∧ XC st OS Vc s s3 ∧ XV st H OS Vc s s3 ∧ + XferSlots st OS s s3) ?_ fun s3 ⟨h3, c3, x3, S3⟩ => ?_ · unfold msg.set_msg_info exact WP.spec_bind (P0.msginfo.MessageInfo.to_word.p0 _) fun w _ => - WP.spec_mono (XJX.regQ (Vc := Vc) hH hO hc0 h2 hvr2 hr (v := w) (by simp [layout.reg.MSG_INFO, layout.reg.X1])) - fun _ ⟨h', c'⟩ => ⟨h', c2.trans c'⟩ + WP.spec_mono (WP.spec_and + (XJX.regQ (Vc := Vc) hH hO hc0 h2 hvr2 hr (v := w) (by simp [layout.reg.MSG_INFO, layout.reg.X1]) x2) + (XJX.reg hH hO h2 hr (v := w) (by simp [layout.reg.MSG_INFO, layout.reg.X1]))) + fun _ ⟨⟨h', c', x'⟩, _, k⟩ => ⟨h', c2.trans c', x', S2.keep fun z hz => k.capA hz⟩ · have hvr3 : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s3) Pt := by rw [c3.2.2.1]; exact hvr - exact WP.spec_mono (XJX.regQ (Vc := Vc) hH hO hc0 h3 hvr3 hr (by simp [layout.reg.BADGE, layout.reg.X0])) - fun _ ⟨h', c'⟩ => ⟨h', c3.trans c'⟩ + exact WP.spec_mono (WP.spec_and + (XJX.regQ (Vc := Vc) hH hO hc0 h3 hvr3 hr (by simp [layout.reg.BADGE, layout.reg.X0]) x3) + (XJX.reg hH hO h3 hr (by simp [layout.reg.BADGE, layout.reg.X0]))) + fun _ ⟨⟨h', c', x'⟩, _, k⟩ => ⟨h', c3.trans c', x', S3.keep fun z hz => k.capA hz⟩ set_option maxHeartbeats 4000000 in -/-- **`do_ipc_transfer` with the carry** (MdbXferL's `ipc.do_ipc_transfer.xjX` text; module docstring). -/ -theorem ipc.do_ipc_transfer.xjQ {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {Xq Rp Nt Vc' Ub Pt : Set U64} +/-- **`do_normal_transfer` with the carry** (MdbXferL's `ipc.do_normal_transfer.xjX` text). -/ +theorem ipc.do_normal_transfer.xjQ {Xq Rp Nt Vc' Ub Pt : Set U64} {s : S} (hH : HeapOK H) + (hO : OSOK H.tcbs H.omega H.frame OS) (hc0 : 0#u64 ∈ Cs) (hW : WinOK H.tcbs H.omega) + (hks : HeapKsOff H (L.ksb s)) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) + (hTy : SlotTy st H.tcbs H.omega H.frame H Rp Nt OS s) (hTS : TcbSlotsOS H.tcbs OS) + (h : XJX st H Cs OS ia ie Ac Xq s s) {snd sb ep badge rcv rb : U64} {grant : Bool} (hs : snd ∈ H.tcbs) + (hr : rcv ∈ H.tcbs) (hb : rb ≠ 0#u64 → BufIn H OS rb ∧ BufK H rb ∧ BufCw st OS s rb) : + ipc.do_normal_transfer st s snd sb ep badge grant rcv rb ⦃ s' => + XJX st H Cs OS ia ie Ac Xq s s' ∧ XC st OS Vc s s' ∧ XV st H OS Vc s s' ⦄ := + WP.spec_mono (ipc.do_normal_transfer.xjS (Vc := Vc) hH hO hc0 hW hks hvr hTy hTS h hs hr hb) fun _ h => + ⟨h.1, h.2.1, h.2.2.1⟩ + +set_option maxHeartbeats 4000000 in +/-- **`do_ipc_transfer` with the carry and the slot fact** (A64-S1A gen 41). -/ +theorem ipc.do_ipc_transfer.xjS {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {Xq Rp Nt Vc' Ub Pt : Set U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (hSA : ScApart H.scs H.scBits OS) (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s)) @@ -443,7 +654,7 @@ theorem ipc.do_ipc_transfer.xjQ {A : Type _} {ar : machine.Arch A} (hA : P0.Arch (Y : SymL st H Cs s) (hbk : BlkOKX st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac Xq s) {snd ep badge rcv : U64} {grant : Bool} (hs : snd ∈ H.tcbs) (hr : rcv ∈ H.tcbs) : ipc.do_ipc_transfer st ar s a snd ep badge grant rcv ⦃ s' => - XJX st H Cs OS ia ie Ac Xq s s' ∧ XC st OS Vc s s' ⦄ := by + XJX st H Cs OS ia ie Ac Xq s s' ∧ XC st OS Vc s s' ∧ XV st H OS Vc s s' ∧ XferSlots st OS s s' ⦄ := by have hP : P0.StoreTotal st := L.total have h := XJX.start B Y hbk have hH := P.heap @@ -451,22 +662,50 @@ theorem ipc.do_ipc_transfer.xjQ {A : Type _} {ar : machine.Arch A} (hA : P0.Arch have hc0 := P.core0 unfold ipc.do_ipc_transfer have hsb : sbA rcv ∈ OS := by rw [sbA_slotIdx]; exact hTS rcv hr 2#u64 (by simp) - refine WP.spec_bind (lookup_bufK B hH hsb (B.ipc rcv hr)) fun rb hb => ?_ + refine WP.spec_bind (lookup_bufKC B hH hsb (B.ipc rcv hr)) fun rb hb => ?_ refine WP.spec_bind (P0.obj.Tcb.fault_type.p0 st snd s hP) fun ft _ => ?_ split · refine WP.spec_bind (P0.msg.lookup_ipc_buffer.p0 st s false snd hP) fun sb _ => ?_ - exact ipc.do_normal_transfer.xjQ hH hO hc0 P.win hks hvr P.ty hTS h hs hr hb - · have hk : ∀ s2, (XJX st H Cs OS ia ie Ac Xq s s2 ∧ XC st OS Vc s s2) → L.ksb s2 = L.ksb s := - fun s2 h2 => h2.2.2.2.1 - exact ipc.do_fault_transfer.gx (I := fun s2 => XJX st H Cs OS ia ie Ac Xq s s2 ∧ XC st OS Vc s s2) - ⟨h, XC.refl s⟩ - (fun s2 _ _ h2 hr' => WP.spec_mono (XJX.regQ (Vc := Vc) hH hO hc0 h2.1 - (by rw [hk s2 h2]; exact hvr) hr hr') fun _ ⟨h', c'⟩ => ⟨h', h2.2.trans c'⟩) - (fun h0 s2 _ _ h2 hj => WP.spec_mono (XJX.bufQ (Vc := Vc) hH hO hc0 h2.1 (by rw [hk s2 h2]; exact hks) - (by rw [hk s2 h2]; exact hvr) (hb h0).1 (hb h0).2 h0 hj) fun _ ⟨h', c'⟩ => ⟨h', h2.2.trans c'⟩) - (fun s2 _ h2 => let e := XJX.fw1Q (Vc := Vc) hH hO hc0 h2.1 (by rw [hk s2 h2]; exact hvr) hs - ⟨e.1, h2.2.trans e.2⟩) - (fun hc0' => XJX.consQ hH hO hc0 hA a P hSA hks hvr h ((hbk.2.2.1.2.2.bound snd hs hc0').1)) + exact ipc.do_normal_transfer.xjS hH hO hc0 P.win hks hvr P.ty hTS h hs hr hb + · have hk : ∀ s2, (XJX st H Cs OS ia ie Ac Xq s s2 ∧ XC st OS Vc s s2 ∧ XV st H OS Vc s s2 ∧ OSKeep st OS s s2) → + L.ksb s2 = L.ksb s := + fun s2 h2 => h2.2.1.2.2.1 + refine WP.spec_mono (ipc.do_fault_transfer.gx + (I := fun s2 => XJX st H Cs OS ia ie Ac Xq s s2 ∧ XC st OS Vc s s2 ∧ XV st H OS Vc s s2 ∧ OSKeep st OS s s2) + ⟨h, XC.refl s, XV.refl s, OSKeep.rfl' s⟩ + (fun s2 _ _ h2 hr' => WP.spec_mono (WP.spec_and (XJX.regQ (Vc := Vc) hH hO hc0 h2.1 + (by rw [hk s2 h2]; exact hvr) hr hr' h2.2.2.1) (XJX.reg hH hO h2.1 hr hr')) + fun _ ⟨⟨h', c', x'⟩, _, k⟩ => ⟨h', h2.2.1.trans c', x', OSKeep.trans' h2.2.2.2 k⟩) + (fun h0 s2 _ _ h2 hj => WP.spec_mono (WP.spec_and (XJX.bufQ (Vc := Vc) hH hO hc0 h2.1 + (by rw [hk s2 h2]; exact hks) (by rw [hk s2 h2]; exact hvr) (hb h0).1 (hb h0).2.1 h0 hj (hb h0).2.2 h2.2.2.1) + (XJX.buf hH hO h2.1 (hb h0).1 h0 hj)) + fun _ ⟨⟨h', c', x'⟩, _, k⟩ => ⟨h', h2.2.1.trans c', x', OSKeep.trans' h2.2.2.2 k⟩) + (fun s2 v h2 => by + have e := XJX.fw1Q (Vc := Vc) hH hO hc0 h2.1 (t := snd) (v := v) (by rw [hk s2 h2]; exact hvr) hs h2.2.2.1 + have C := LvC.of_blkX h2.1.blk + have d : DF st H Cs (L.curW s2) ∅ s2 (L.wr s2 (wa snd 3392#u64) v) := + tcb_wr_df C hs (by simp) (by simp) (by simp) (by simp) (by unfold LvO; simp) + have k := DFB.oskX (Bw := fun _ => False) hO h2.1.blk (fun _ _ _ _ _ h => h) (DFB.ofDF d) + exact ⟨e.1, h2.2.1.trans e.2.1, e.2.2, OSKeep.trans' h2.2.2.2 k⟩) + (fun hc0' => WP.spec_mono (XJX.consS hH hO hc0 hA a P hSA hks hvr h ((hbk.2.2.1.2.2.bound snd hs hc0').1)) + fun r h => by + obtain ⟨_, _⟩ := r + exact ⟨h.1, h.2.1, h.2.2.1, h.2.2.2⟩)) fun s' h => + ⟨h.1, h.2.1, h.2.2.1, Or.inl fun z hz => h.2.2.2.capA hz⟩ + +set_option maxHeartbeats 4000000 in +/-- **`do_ipc_transfer` with the carry** (MdbXferL's `ipc.do_ipc_transfer.xjX` text; module docstring). -/ +theorem ipc.do_ipc_transfer.xjQ {A : Type _} {ar : machine.Arch A} (hA : P0.ArchTotal ar) {Xq Rp Nt Vc' Ub Pt : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {s : S} (a : A) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (hSA : ScApart H.scs H.scBits OS) + (hTS : TcbSlotsOS H.tcbs OS) (hks : HeapKsOff H (L.ksb s)) + (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc' Ub (L.ksb s) Pt) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hbk : BlkOKX st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac Xq s) + {snd ep badge rcv : U64} {grant : Bool} (hs : snd ∈ H.tcbs) (hr : rcv ∈ H.tcbs) : + ipc.do_ipc_transfer st ar s a snd ep badge grant rcv ⦃ s' => + XJX st H Cs OS ia ie Ac Xq s s' ∧ XC st OS Vc s s' ∧ XV st H OS Vc s s' ⦄ := + WP.spec_mono (ipc.do_ipc_transfer.xjS (Vc := Vc) hA a P hSA hTS hks hvr B Y hbk hs hr) fun _ h => + ⟨h.1, h.2.1, h.2.2.1⟩ end ST end R diff --git a/proofs/Fl4ProofsA64/P1/QueueUnmD.lean b/proofs/Fl4ProofsA64/P1/QueueUnmD.lean index e6a233b9e..3596dddd8 100644 --- a/proofs/Fl4ProofsA64/P1/QueueUnmD.lean +++ b/proofs/Fl4ProofsA64/P1/QueueUnmD.lean @@ -261,17 +261,17 @@ theorem ept.find.congr {s s1 : S} (h : VsTyR st kb Pp Hr Tb Lv s) (hk : L.ksb s set_option maxHeartbeats 2000000 in /-- **`PtFnd` along a `VsKeep` step with the same `ks` base** (e.g. `set_thread_state`): the walks of the fact read only words of reachable tables, pool words and ASID-table words. -/ -theorem PtFnd.vk {s s1 : S} (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te bits ⊆ Pt) (hS : S2OK Te bits Hr) - (hH : HrOK kb Pp Tb Lv Hr) (h0 : VsTyR st kb Pp Hr Tb Lv s) (h2 : S2TyR st n Pp Hr Te Re bits s) +theorem PtFnd.vkSeed {s s1 : S} {Seeds : Set U64} (hSeeds : Seeds ⊆ Tb) (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te bits ⊆ Pt) (hS : S2OK Te bits Hr) + (hH : HrOK kb Pp Tb Lv Hr) (h0 : VsTyR st kb Pp Seeds Tb Lv s) (h2 : S2TyR st n Pp Hr Te Re bits s) (hk : L.ksb s = kb) (hks : L.ksb s1 = L.ksb s) (k : VsKeep st kb Pt s s1) {asid vaddr ptr : U64} - (hF : PtFnd st n Pp Hr Lv Re bits s asid vaddr ptr) : PtFnd st n Pp Hr Lv Re bits s1 asid vaddr ptr := by + (hF : PtFnd st n Pp Seeds Lv Re bits s asid vaddr ptr) : PtFnd st n Pp Seeds Lv Re bits s1 asid vaddr ptr := by have z : VsZ st kb Pt s s1 := VsKeep.vsz k have hraw := vspace.find_asid_raw.congr h0 hk hks hPp k asid have hfind := ept.find.congr h0 hk hks hPp k asid refine ⟨NoRoot.vsz hPp hF.root z, fun b hb => ?_, fun b hb => ?_⟩ · obtain ⟨r1, root, g, hr, h1, hf, hg, hl⟩ := hF.s2 b (S2Nm.vsz hPp hTe hS h2 z hb).1 refine ⟨r1, root, g, by rw [hraw]; exact hr, h1, by rw [hfind]; exact hf, hg, ?_⟩ - have hft := ept.find.tyR h0 h2 hk asid + have hft := ept.find.ty h0.sub h2.sub hk asid rw [hf, WP.spec_ok] at hft obtain ⟨hT, hre, hrb⟩ := hft root rfl have hgv := ept.geom.v n @@ -286,7 +286,7 @@ theorem PtFnd.vk {s s1 : S} (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te b rw [ept.unmap_table_loop.congr h2.sub (S2OK.sub hS S2Rt_sub) (fun b' hb' => k b' (Or.inl (ptw_mono hTe (ptwb_gran hS.sz (ptwb_mono S2Rt_sub hb'))))) _ _ _ _ _ _ hi] exact hl - · obtain ⟨r1, t, sh, lv, hr, h1, hst, hl⟩ := hF.s1 b (VsNm.vsz hPp hTb hH.sub h0 z hb).1 + · obtain ⟨r1, t, sh, lv, hr, h1, hst, hl⟩ := hF.s1 b (VsNm.vsz hPp hTb hSeeds h0 z hb).1 have hr1 := vspace.find_asid_raw.ty h0.sub hk asid rw [hr, WP.spec_ok] at hr1 obtain ⟨p, hp, o, ho, h8, er, hr0⟩ := hr1 r1 rfl @@ -298,14 +298,19 @@ theorem PtFnd.vk {s s1 : S} (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te b · rw [e0] at h2'; exact absurd h2' (by decide) · exact hR · rw [e1] at h2'; exact absurd h2' (by decide) - have hi : UpI (VsRt st Pp Hr Tb Lv s) Lv (t, sh, lv) := by + have hi : UpI (VsRt st Pp Seeds Tb Lv s) Lv (t, sh, lv) := by rcases hst with ⟨h2', rfl, rfl, rfl⟩ | ⟨hn2, rfl, rfl, rfl⟩ · have hR := hR2 h2' have hRT := hH.sub hR have hL0 := hH.lv _ hR have he := h2.hi _ hR - obtain ⟨hT1, hL1⟩ := h0.desc _ hRT (VsReach.hr hR) (by omega) 4088#u64 (by simp) (by simp) he - refine ⟨by simp, fun _ => ⟨⟨hT1, VsReach.step (VsReach.hr hR) (by omega) (by simp) (by simp) he⟩, ?_⟩⟩ + have hre : VsReach st Pp Seeds Lv s (r1 &&& ~~~3#u64) := by + have e := VsReach.root2 (st := st) (Pp := Pp) (Hr := Seeds) (Lv := Lv) (s := s) hp ho h8 + (by rw [← er]; exact h2') + rw [← er] at e + exact e + obtain ⟨hT1, hL1⟩ := h0.desc _ hRT hre (by omega) 4088#u64 (by simp) (by simp) he + refine ⟨by simp, fun _ => ⟨⟨hT1, VsReach.step hre (by omega) (by simp) (by simp) he⟩, ?_⟩⟩ simp only; rw [hL1, hL0]; simp · have h0' : (r1 &&& 3#u64) = 0#u64 := by rcases hth with ⟨e0, -⟩ | ⟨e2, -⟩ | ⟨e1, -⟩ @@ -314,8 +319,8 @@ theorem PtFnd.vk {s s1 : S} (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te b · exact absurd e1 h1 rw [and_not_of r1 3#u64 h0'] obtain ⟨hT0, hL0⟩ := hpl.1 h0' - have hre : VsReach st Pp Hr Lv s r1 := by - have := VsReach.root0 (st := st) (Pp := Pp) (Hr := Hr) (Lv := Lv) (s := s) hp ho h8 + have hre : VsReach st Pp Seeds Lv s r1 := by + have := VsReach.root0 (st := st) (Pp := Pp) (Hr := Seeds) (Lv := Lv) (s := s) hp ho h8 (by rw [← er]; exact hr0) (by rw [← er]; exact h0') rw [← er] at this; exact this refine ⟨by simp, fun _ => ⟨⟨hT0, hre⟩, ?_⟩⟩ @@ -329,6 +334,13 @@ theorem PtFnd.vk {s s1 : S} (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te b · exact Or.inl ⟨h2', by rw [ht, k _ (hr_vsr hTb hH (hR2 h2'))], hsh, hlv⟩ · exact Or.inr hst +/-- The walk is preserved when the extra Stage-1 seed is the all-live root set. -/ +theorem PtFnd.vk {s s1 : S} (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te bits ⊆ Pt) (hS : S2OK Te bits Hr) + (hH : HrOK kb Pp Tb Lv Hr) (h0 : VsTyR st kb Pp Hr Tb Lv s) (h2 : S2TyR st n Pp Hr Te Re bits s) + (hk : L.ksb s = kb) (hks : L.ksb s1 = L.ksb s) (k : VsKeep st kb Pt s s1) {asid vaddr ptr : U64} + (hF : PtFnd st n Pp Hr Lv Re bits s asid vaddr ptr) : PtFnd st n Pp Hr Lv Re bits s1 asid vaddr ptr := + PtFnd.vkSeed hH.sub hPp hTb hTe hS hH h0 h2 hk hks k hF + end walk /-! ## Store steps -/ diff --git a/proofs/Fl4ProofsA64/P1/QueueZombieQ.lean b/proofs/Fl4ProofsA64/P1/QueueZombieQ.lean index e7171f6a1..7f69f6fac 100644 --- a/proofs/Fl4ProofsA64/P1/QueueZombieQ.lean +++ b/proofs/Fl4ProofsA64/P1/QueueZombieQ.lean @@ -74,6 +74,9 @@ return the loop's `DomQ`, idle word, idle `SC` field, `IrqN` and `IrqK` from the (`ZS` cap ∧ `∀ p, ObjPtr c p → p ∉ BufS T ∧ y ∉ BufS T`) ∨ `K c` (the ruled `ZQ''`). **`finXQGB`** (`finXQG`'s proof, moved; `finXQG` its corollary) returns the remainder slot off `BufS T`; `cdt.cap_swap_for_delete.zqG` is `jvB` + `swapB_of`; the thread tops take `hpF : p ∉ BufS T`, `hxB : x ∉ BufS T`. +**A64-S1A gen 41 (pending window).** `LoopMP`: `LoopME` with the removable finalisation giving only `Pn` of the slot and +`empty_slot` turning `Pn` back into `M`. The four `LoopME` loop proofs moved to `zqGMPE` (deferred), `delete_deferred.zqGMPE`, +`zqGTMPQ` (immediate) and `zqIGTMPQ` (delete); the `LoopME` theorems are their instances at `LoopME.toP`. -/ import Fl4ProofsA64.P1.QueueZombieP import Fl4ProofsA64.P1.QueueVsPool @@ -310,6 +313,42 @@ theorem LoopMZ.toE {C M : S → Prop} {X : S → U64 → capability.Cap → Prop pre := h.pre emp s a x cl hC m hx hc _ := h.emp s a x cl hC m hx hc +/-- (A64-S1A gen 41) **A loop-invariant field with a pending window** (x86 `WJLx` / `VsPend`): `LoopME`'s +obligations, but a removable finalisation gives only `Pn` of the slot, which `empty_slot` of that slot turns back into +`M`; `M` is owed by the non-removable finalisation. For an invariant that is false between a finalisation and the +`empty_slot` that follows it. `LoopME.toP`: every `LoopME` field is one (`Pn := M ∧ Em`). -/ +structure LoopMP (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) (OS D : Set U64) + (C : S → Prop) (X : S → U64 → capability.Cap → Prop) (Zr : S → U64 → U64 → U64 → U64 → Prop) + (Pn : S → U64 → Prop) (M : S → Prop) : Prop where + fin : ∀ (s : S) (a : A) (x : U64) (c : capability.Cap) (f : Bool), C s → M s → x ∈ OS → + obj.Slot.cap st x s = ok c → X s x c → cdt.is_final_capability_with_cap st s x c = ok f → + objects.finalise_cap st ar s a c f false ⦃ r => (∀ p t n, r.1.1 = .Zombie p t n → Zr r.2.1 x p t n) ∧ + (cdt.cap_removable r.1.1 x = ok true → Pn r.2.1 x) ∧ (cdt.cap_removable r.1.1 x ≠ ok true → M r.2.1) ⦄ + en : ∀ (s : S) (x : U64), M s → obj.Slot.cap st x s = ok .Null → Pn s x + setz : ∀ (s : S) (x p t n : U64), C s → M s → x ∈ OS → Canon p → Zr s x p t n → + obj.Slot.set_cap st x s (.Zombie p t n) ⦃ s' => M s' ⦄ + setd : ∀ (s : S) (x p t n : U64), C s → M s → x ∈ OS → Canon p → obj.Slot.cap st x s = ok (.Zombie p t n) → + EndE st (slotIdx p (core.num.U64.wrapping_sub n 1#u64)) s → n ≠ 0#u64 → + obj.Slot.set_cap st x s (.Zombie p t (core.num.U64.wrapping_sub n 1#u64)) ⦃ s' => M s' ⦄ + swap : ∀ (s : S) (p y : U64), C s → M s → p ∈ D → y ∈ D → p ≠ y → + (∃ t n, obj.Slot.cap st y s = ok (.Zombie p t n) ∧ 0 < n.val) → cdt.cap_swap_for_delete st s p y ⦃ s' => M s' ⦄ + pre : ∀ (s : S) (a : A), C s → M s → sched.preemption_point st ar s a ⦃ r => M r.2.1 ⦄ + emp : ∀ (s : S) (a : A) (x : U64) (cl : capability.Cap), C s → Pn s x → x ∈ OS → ClOK cl → + cdt.empty_slot st ar s a x cl ⦃ r => M r.1 ⦄ + +/-- A `LoopME` field is a `LoopMP` field with `Pn := M ∧ Em`. -/ +theorem LoopME.toP {C M : S → Prop} {X : S → U64 → capability.Cap → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} + {Em : S → U64 → Prop} (h : LoopME st ar OS D C X Zr Em M) : + LoopMP st ar OS D C X Zr (fun s x => M s ∧ Em s x) M where + fin s a x c f hC m hx hc hX hf := + WP.spec_mono (h.fin s a x c f hC m hx hc hX hf) fun _ ⟨m', z, e⟩ => ⟨z, fun r => ⟨m', e r⟩, fun _ => m'⟩ + en s x m hc := ⟨m, h.en s x hc⟩ + setz := h.setz + setd := h.setd + swap := h.swap + pre := h.pre + emp s a x cl hC p hx hc := h.emp s a x cl hC p.1 hx hc p.2 + theorem FinK.toT {kb : U64} (hK : FinK st ar kb Pt Ty K) (hT : TyZ st kb Pt Ty) : FinKT st ar kb Pt Ty K := fun s a c fin hy hk hc => WP.spec_mono (hK s a c fin hy hk hc) fun r ⟨e, w, z⟩ => ⟨e, w, hT _ _ hy z⟩ @@ -417,9 +456,9 @@ theorem cdt.cap_swap_for_delete.zq (hO : OSOK T Ω Sg OS) (hV : VcOK T Scs Z OS ⟨a1, a2, a3, a4, a5, a6.vsz⟩ set_option maxHeartbeats 4000000 in -/-- (gen 65) **`finalise_slot_deferred.zqG` with a `LoopME` field**: gen 50's loop proof (moved here), the `Ok` post -also giving `Em` of the slot on `success` and a cyclic `Zombie` there (`CycE`) otherwise. -/ -theorem cdt.finalise_slot_deferred.zqGME (hP : P0.ArchTotal ar) +/-- (A64-S1A gen 41) **`finalise_slot_deferred.zqGME` with a pending window** (`LoopMP`; the loop proof, moved here): `Pn` of the +slot on `success`, `M` otherwise. -/ +theorem cdt.finalise_slot_deferred.zqGMPE (hP : P0.ArchTotal ar) (hO : OSOK T Ω Sg OS) (hA : ScApart Scs Z OS) (hV : VcOK T Scs Z OS Vc Ub) (hDO : D ⊆ OS) (hDC : DCan D) {s0 s : S} (hR : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s0) Pt) (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) @@ -428,13 +467,13 @@ theorem cdt.finalise_slot_deferred.zqGME (hP : P0.ArchTotal ar) (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} - {Em : S → U64 → Prop} - (hM : LoopME st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Em M) + {Pn : S → U64 → Prop} + (hM : LoopMP st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Pn M) (hm : M s) : cdt.finalise_slot_deferred st ar s a y ⦃ r => JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 r.2.1 ∧ DomQ st K Vc D Scs T I Is r.2.1 ∧ OKD st OS D (L.ksb s0) s r.2.1 ∧ L.idleW r.2.1 = I ∧ - L.mem r.2.1 (scA I) = Is ∧ Ty r.2.1 ∧ M r.2.1 ∧ ∀ v, r.1 = .Ok v → ClOK v.cleanup ∧ - (v.success = true → Em r.2.1 y) ∧ (v.success = false → CycE st y r.2.1) ⦄ := by + L.mem r.2.1 (scA I) = Is ∧ Ty r.2.1 ∧ ((∀ v, r.1 = .Ok v → v.success = false) → M r.2.1) ∧ ∀ v, r.1 = .Ok v → ClOK v.cleanup ∧ + (v.success = true → Pn r.2.1 y) ∧ (v.success = false → CycE st y r.2.1) ⦄ := by have hS : P0.StoreTotal st := L.total obtain ⟨Ac0, hb0⟩ := h.1.parts have q0 := hb0.1.choose_spec.choose_spec @@ -448,7 +487,7 @@ theorem cdt.finalise_slot_deferred.zqGME (hP : P0.ArchTotal ar) unfold cdt.finalise_slot_deferred_loop.body split swap - · exact (WP.spec_ok _).2 ⟨h1, d1, o1, i1, j1, y1, m1, by intro v hv; simp_all⟩ + · exact (WP.spec_ok _).2 ⟨h1, d1, o1, i1, j1, y1, fun _ => m1, by intro v hv; simp_all⟩ rename_i hf have hf' : 0 < fuel.val := by simpa using hf step as ⟨fuel1, hf1⟩ @@ -459,14 +498,14 @@ theorem cdt.finalise_slot_deferred.zqGME (hP : P0.ArchTotal ar) · rename_i hbt have hc0 : obj.Slot.cap st y s1 = ok .Null := by rw [hc]; congr 1; subst hbt; cases c <;> first | rfl | (simp [capability.Cap.is_null] at hbn) - exact (WP.spec_ok _).2 ⟨h1, d1, o1, i1, j1, y1, m1, fun v hv => by - cases hv; exact ⟨Or.inl rfl, fun _ => hM.en s1 y hc0, fun h => by cases h⟩⟩ + exact (WP.spec_ok _).2 ⟨h1, d1, o1, i1, j1, y1, fun h => absurd (h _ rfl) (by simp), fun v hv => by + cases hv; exact ⟨Or.inl rfl, fun _ => hM.en s1 y m1 hc0, fun h => by cases h⟩⟩ refine WP.spec_bind (spec_eqv (P0.cdt.is_final_capability_with_cap.p0 st s1 y c hS)) fun fin hfe => ?_ have hN1 : IrqN st (L.ksb s0) s1 := hN.okd hIO o1 refine WP.spec_bind (WP.spec_and (finXQGB hP hO hA hV hR hK hTy h1 hIO hN1 y1 h1.ksb (hDO hy) hc (by rw [i1, j1]; exact d1 y hy c hc) a1 fin) (hM.fin s1 a1 y c fin h1 m1 (hDO hy) hc ⟨(by rw [i1, j1]; exact d1 y hy c hc), y1, hN1⟩ hfe.1)) ?_ - rintro ⟨⟨rem, cl⟩, s2, a2⟩ ⟨⟨hcl, h2, k2, hrem, j2, sc2, v2, hxB⟩, m2, z2, e2⟩ - simp only at hcl hrem j2 sc2 v2 hxB m2 z2 e2 + rintro ⟨⟨rem, cl⟩, s2, a2⟩ ⟨⟨hcl, h2, k2, hrem, j2, sc2, v2, hxB⟩, z2, e2, n2⟩ + simp only at hcl hrem j2 sc2 v2 hxB z2 e2 n2 have d2 : DomQ st K Vc D Scs T I Is s2 := d1.oka hIO.2 hDO k2 have o2 : OKD st OS D (L.ksb s0) s s2 := o1.trans k2.okd have i2 : L.idleW s2 = I := j2.trans i1 @@ -475,21 +514,16 @@ theorem cdt.finalise_slot_deferred.zqGME (hP : P0.ArchTotal ar) rcases hrem with rfl | ⟨p, t, n, rfl, hcp, hcov, hpF⟩ · try dsimp only have e2' := e2 rfl - first - | (simp only [cdt.cap_removable, bind_ok, ↓reduceIte] - exact (WP.spec_ok _).2 ⟨h2, d2, o2, i2, js2, y2, m2, fun v hv => by - cases hv; exact ⟨hcl, fun _ => e2', fun h => by cases h⟩⟩) - | (simp only [cdt.cap_removable, bind_ok, ↓reduceIte, WP.spec_ok] - exact ⟨h2, d2, o2, i2, js2, y2, m2, fun v hv => by cases hv; exact ⟨hcl, fun _ => e2', fun h => by cases h⟩⟩) - | (simp [cdt.cap_removable, WP.spec_ok]; exact ⟨h2, d2, o2, i2, js2, y2, m2, hcl, e2'⟩) - | (simp [cdt.cap_removable, WP.spec_ok]; exact ⟨h2, d2, o2, i2, js2, y2, m2, hcl, fun _ => e2'⟩) + simp [cdt.cap_removable, WP.spec_ok] + exact ⟨h2, d2, o2, i2, js2, y2, hcl, e2'⟩ refine WP.spec_bind (spec_eqv (P0.cdt.cap_removable.p0 (.Zombie p t n) y)) fun b1 hb1 => ?_ try dsimp only split · rename_i hrm - exact (WP.spec_ok _).2 ⟨h2, d2, o2, i2, js2, y2, m2, fun v hv => by + exact (WP.spec_ok _).2 ⟨h2, d2, o2, i2, js2, y2, fun h => absurd (h _ rfl) (by simp), fun v hv => by cases hv; exact ⟨hcl, fun _ => e2 (by rw [hb1.1, hrm]), fun h => by cases h⟩⟩ rename_i hnr + have m2 := n2 (by rw [hb1.1]; simpa using hnr) have hn0 : n ≠ 0#u64 := by have hb := hb1.1 rintro rfl @@ -520,7 +554,7 @@ theorem cdt.finalise_slot_deferred.zqGME (hP : P0.ArchTotal ar) have hpy : p = y := by have hb := hb2.1; rw [hcy] at hb; simpa [cdt.cap_cyclic_zombie] using hb have hrf : cdt.cap_removable (.Zombie p t n) y = ok false := by rw [hb1.1]; simpa using hnr - exact (WP.spec_ok _).2 ⟨h3, d3, o3, i3, js3, y3, m3, fun v hv => by + exact (WP.spec_ok _).2 ⟨h3, d3, o3, i3, js3, y3, fun _ => m3, fun v hv => by cases hv; exact ⟨by first | exact Or.inl rfl | exact hcl, (fun h => by cases h), fun _ => ⟨p, _, n, c3, hpy, by first | exact hrf | simpa [cdt.cap_removable] using hrf⟩⟩⟩ rename_i hcy have hpy : p ≠ y := by @@ -558,9 +592,37 @@ theorem cdt.finalise_slot_deferred.zqGME (hP : P0.ArchTotal ar) · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 ⟨h5, d5, o5, i5, js5, y5, m5, fun v hv => by cases hv⟩ + exact (WP.spec_ok _).2 ⟨h5, d5, o5, i5, js5, y5, fun _ => m5, fun v hv => by cases hv⟩ · exact ⟨h, hD, OKD.refl s, hI, hIs, hY, hm⟩ +/-- (gen 65) **`finalise_slot_deferred.zqG` with a `LoopME` field**: gen 50's loop proof (moved here), the `Ok` post +also giving `Em` of the slot on `success` and a cyclic `Zombie` there (`CycE`) otherwise. -/ +theorem cdt.finalise_slot_deferred.zqGME (hP : P0.ArchTotal ar) + (hO : OSOK T Ω Sg OS) (hA : ScApart Scs Z OS) (hV : VcOK T Scs Z OS Vc Ub) (hDO : D ⊆ OS) (hDC : DCan D) + {s0 s : S} (hR : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s0) Pt) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) + (hW : WuApart OS (L.ksb s0)) (hIO : IrqOK OS D (L.ksb s0)) {a : A} {y I Is : U64} + (h : JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 s) (hy : y ∈ D) (hD : DomQ st K Vc D Scs T I Is s) + (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) + (hY : Ty s) + {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} + {Em : S → U64 → Prop} + (hM : LoopME st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Em M) + (hm : M s) : + cdt.finalise_slot_deferred st ar s a y ⦃ r => JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 r.2.1 ∧ + DomQ st K Vc D Scs T I Is r.2.1 ∧ OKD st OS D (L.ksb s0) s r.2.1 ∧ L.idleW r.2.1 = I ∧ + L.mem r.2.1 (scA I) = Is ∧ Ty r.2.1 ∧ M r.2.1 ∧ ∀ v, r.1 = .Ok v → ClOK v.cleanup ∧ + (v.success = true → Em r.2.1 y) ∧ (v.success = false → CycE st y r.2.1) ⦄ := by + refine WP.spec_mono (cdt.finalise_slot_deferred.zqGMPE (a := a) hP hO hA hV hDO hDC hR hK hTy hW hIO h hy hD hI hIs + hN hY hM.toP hm) ?_ + rintro r ⟨h1, d1, o1, i1, j1, y1, m1, v1⟩ + refine ⟨h1, d1, o1, i1, j1, y1, ?_, fun v hv => ⟨(v1 v hv).1, fun hs => ((v1 v hv).2.1 hs).2, (v1 v hv).2.2⟩⟩ + by_cases failed : ∀ v, r.1 = .Ok v → v.success = false + · exact m1 failed + · simp only [not_forall] at failed + obtain ⟨v, hv, hs⟩ := failed + exact ((v1 v hv).2.1 (by simpa using hs)).1 + set_option maxHeartbeats 4000000 in /-- **`finalise_slot_deferred.zqG` with a field `M` seeing the finalisation** (gen 50, `LoopMZ` at `C := JV s0`, `X := XQF`). -/ theorem cdt.finalise_slot_deferred.zqGMZ (hP : P0.ArchTotal ar) @@ -628,9 +690,8 @@ theorem cdt.finalise_slot_deferred.zqG (hP : P0.ArchTotal ar) (LoopM.triv hP) trivial) fun _ ⟨a1, a2, a3, a4, a5, a6, _, a7⟩ => ⟨a1, a2, a3, a4, a5, a6, a7⟩ set_option maxHeartbeats 4000000 in -/-- (gen 65) **`delete_deferred.zqG` with a `LoopME` field**: gen 50's proof (moved here), `emp` given `Em`, and on -`Ok` the slot ends null or holding a cyclic `Zombie` (**`EndE`**, the strengthened post). -/ -theorem cdt.delete_deferred.zqGME (hP : P0.ArchTotal ar) +/-- (A64-S1A gen 41) **`delete_deferred.zqGME` with a pending window** (`LoopMP`; the proof, moved here). -/ +theorem cdt.delete_deferred.zqGMPE (hP : P0.ArchTotal ar) (hO : OSOK T Ω Sg OS) (hA : ScApart Scs Z OS) (hV : VcOK T Scs Z OS Vc Ub) (hDO : D ⊆ OS) (hDC : DCan D) {s0 s : S} (hR : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s0) Pt) (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) @@ -640,14 +701,14 @@ theorem cdt.delete_deferred.zqGME (hP : P0.ArchTotal ar) (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} - {Em : S → U64 → Prop} - (hM : LoopME st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Em M) + {Pn : S → U64 → Prop} + (hM : LoopMP st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Pn M) (hm : M s) : cdt.delete_deferred st ar s a y ⦃ r => JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 r.2.1 ∧ DomQ st K Vc D Scs T I Is r.2.1 ∧ OKD st OS D (L.ksb s0) s r.2.1 ∧ L.idleW r.2.1 = I ∧ L.mem r.2.1 (scA I) = Is ∧ Ty r.2.1 ∧ M r.2.1 ∧ (r.1 = .Ok () → EndE st y r.2.1) ⦄ := by unfold cdt.delete_deferred - refine WP.spec_bind (cdt.finalise_slot_deferred.zqGME (a := a) hP hO hA hV hDO hDC hR hK hTy hW hIO h hy hD hI hIs + refine WP.spec_bind (cdt.finalise_slot_deferred.zqGMPE (a := a) hP hO hA hV hDO hDC hR hK hTy hW hIO h hy hD hI hIs hN hY hM hm) ?_ rintro ⟨r, s1, a1⟩ ⟨h1, d1, o1, i1, j1, y1, m1, hv1⟩ try simp only [uncurry_apply_pair] at h1 d1 o1 i1 j1 y1 m1 hv1 ⊢ @@ -657,7 +718,7 @@ theorem cdt.delete_deferred.zqGME (hP : P0.ArchTotal ar) · rename_i hsu refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.empty_slot.zs (a := a1) hP hO hV h1 (hDO hy) (hv1 v rfl).1 hap) (cdt.empty_slot.vk hP hO hR h1 (hDO hy) (hv1 v rfl).1 h1.ksb)) - (hM.emp s1 a1 y _ h1 m1 (hDO hy) (hv1 v rfl).1 ((hv1 v rfl).2.1 hsu))) ?_ + (hM.emp s1 a1 y _ h1 ((hv1 v rfl).2.1 hsu) (hDO hy) (hv1 v rfl).1)) ?_ rintro ⟨s2, a2⟩ ⟨⟨⟨h2, k2, c2, w2, K2⟩, v2⟩, m2⟩ try simp only [uncurry_apply_pair] at h2 k2 c2 w2 K2 v2 m2 ⊢ refine (WP.spec_ok _).2 ⟨h2, DomQ.upd d1 fun z hz => ?_, o1.trans (OKD.of_ck k2 hy), w2.trans i1, @@ -666,11 +727,31 @@ theorem cdt.delete_deferred.zqGME (hP : P0.ArchTotal ar) · right; subst e; intro c hc; rw [c2] at hc; rw [← okinj hc]; exact zq_null · left; exact k2.cap (hDO hz) e · rename_i hsu - exact (WP.spec_ok _).2 ⟨h1, d1, o1, i1, j1, y1, m1, fun _ => Or.inr ((hv1 v rfl).2.2 (by simpa using hsu))⟩ + exact (WP.spec_ok _).2 ⟨h1, d1, o1, i1, j1, y1, m1 (fun v' hv => by cases hv; simpa using hsu), fun _ => Or.inr ((hv1 v rfl).2.2 (by simpa using hsu))⟩ · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 ⟨h1, d1, o1, i1, j1, y1, m1, fun h => by cases h⟩ + exact (WP.spec_ok _).2 ⟨h1, d1, o1, i1, j1, y1, m1 (fun _ h => by cases h), fun h => by cases h⟩ + +/-- (gen 65) **`delete_deferred.zqG` with a `LoopME` field**: gen 50's proof (moved here), `emp` given `Em`, and on +`Ok` the slot ends null or holding a cyclic `Zombie` (**`EndE`**, the strengthened post). -/ +theorem cdt.delete_deferred.zqGME (hP : P0.ArchTotal ar) + (hO : OSOK T Ω Sg OS) (hA : ScApart Scs Z OS) (hV : VcOK T Scs Z OS Vc Ub) (hDO : D ⊆ OS) (hDC : DCan D) + {s0 s : S} (hR : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s0) Pt) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) + (hW : WuApart OS (L.ksb s0)) (hIO : IrqOK OS D (L.ksb s0)) (hap : IrqStApart OS (L.ksb s0)) + {a : A} {y I Is : U64} + (h : JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 s) (hy : y ∈ D) (hD : DomQ st K Vc D Scs T I Is s) + (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) + (hY : Ty s) + {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} + {Em : S → U64 → Prop} + (hM : LoopME st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Em M) + (hm : M s) : + cdt.delete_deferred st ar s a y ⦃ r => JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 r.2.1 ∧ + DomQ st K Vc D Scs T I Is r.2.1 ∧ OKD st OS D (L.ksb s0) s r.2.1 ∧ L.idleW r.2.1 = I ∧ + L.mem r.2.1 (scA I) = Is ∧ Ty r.2.1 ∧ M r.2.1 ∧ (r.1 = .Ok () → EndE st y r.2.1) ⦄ := by + exact cdt.delete_deferred.zqGMPE (a := a) hP hO hA hV hDO hDC hR hK hTy hW hIO hap h hy hD hI hIs hN hY hM.toP hm set_option maxHeartbeats 4000000 in /-- **`delete_deferred.zqG` with a field `M` seeing the finalisation** (gen 50, `LoopMZ` at `C := JV s0`, `X := XQF`). -/ @@ -787,16 +868,14 @@ local macro "ztailQT" : tactic => `(tactic| ( · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 ⟨h6, hTy _ _ y5 v6, m6, (fun v hv => by cases hv), DomQ.oka d5 hIO.2 hDO (OKA.of_osk k6), + exact (WP.spec_ok _).2 ⟨h6, hTy _ _ y5 v6, (fun _ => m6), (fun v hv => by cases hv), DomQ.oka d5 hIO.2 hDO (OKA.of_osk k6), i6.trans j5, (K6 I (j5 ▸ h5.idleT)).trans js5, IrqN.oka hIO N5 (OKA.of_osk k6), q5.trans (IrqK.oka hIO (OKA.of_osk k6))⟩)) set_option maxHeartbeats 4000000 in -/-- (gen 65) **`finalise_slot_immediate.zqGT` with a `LoopME` field**: gen 50's loop proof (moved here), the decrement -by `setd` with the end slot's `EndE` from `delete_deferred.zqGME`, the `Ok` post also giving `Em` of the slot; (gen 93) -the post also returns the domain class, the idle word / idle `SC` field, `IrqN` and the IRQ-node slots kept or -emptied (`IrqK`), carried by the loop. -/ -theorem cdt.finalise_slot_immediate.zqGTMEQ (hP : P0.ArchTotal ar) +/-- (A64-S1A gen 41) **`finalise_slot_immediate.zqGTMEQ` with a pending window** (`LoopMP`; the loop proof, moved here): `Pn` of the +slot on `Ok`, `M` otherwise. -/ +theorem cdt.finalise_slot_immediate.zqGTMPQ (hP : P0.ArchTotal ar) (hO : OSOK T Ω Sg OS) (hA : ScApart Scs Z OS) (hV : VcOK T Scs Z OS Vc Ub) (hDO : D ⊆ OS) (hDC : DCan D) {s0 s : S} (hR : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s0) Pt) (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) @@ -806,12 +885,12 @@ theorem cdt.finalise_slot_immediate.zqGTMEQ (hP : P0.ArchTotal ar) (hD : DomQ st K Vc D Scs T I Is s) (hX : XQ st K Vc D Scs T I Is x s) (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} - {Em : S → U64 → Prop} - (hM : LoopME st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Em M) + {Pn : S → U64 → Prop} + (hM : LoopMP st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Pn M) (hm : M s) : cdt.finalise_slot_immediate st ar s a x ⦃ r => - JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 r.2.1 ∧ Ty r.2.1 ∧ M r.2.1 ∧ - (∀ v, r.1 = .Ok v → ClOK v.cleanup ∧ Em r.2.1 x) ∧ DomQ st K Vc D Scs T I Is r.2.1 ∧ L.idleW r.2.1 = I ∧ + JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 r.2.1 ∧ Ty r.2.1 ∧ ((∀ v, r.1 ≠ .Ok v) → M r.2.1) ∧ + (∀ v, r.1 = .Ok v → ClOK v.cleanup ∧ Pn r.2.1 x) ∧ DomQ st K Vc D Scs T I Is r.2.1 ∧ L.idleW r.2.1 = I ∧ L.mem r.2.1 (scA I) = Is ∧ IrqN st (L.ksb s0) r.2.1 ∧ IrqK st (L.ksb s0) s r.2.1 ⦄ := by have hS : P0.StoreTotal st := L.total obtain ⟨Ac0, hb0⟩ := h.1.parts @@ -827,7 +906,7 @@ theorem cdt.finalise_slot_immediate.zqGTMEQ (hP : P0.ArchTotal ar) unfold cdt.finalise_slot_immediate_loop.body split swap - · exact (WP.spec_ok _).2 ⟨h1, y1, m1, (by intro v hv; simp_all), d1, j1, js1, N1, q1⟩ + · exact (WP.spec_ok _).2 ⟨h1, y1, (fun _ => m1), (by intro v hv; simp_all), d1, j1, js1, N1, q1⟩ rename_i hf have hf' : 0 < fuel.val := by simpa using hf step as ⟨fuel1, hf1⟩ @@ -838,13 +917,13 @@ theorem cdt.finalise_slot_immediate.zqGTMEQ (hP : P0.ArchTotal ar) · rename_i hbt have hc0 : obj.Slot.cap st x s1 = ok .Null := by rw [hc]; congr 1; subst hbt; cases c <;> first | rfl | (simp [capability.Cap.is_null] at hbn) - exact (WP.spec_ok _).2 ⟨h1, y1, m1, (fun v hv => by cases hv; exact ⟨Or.inl rfl, hM.en s1 x hc0⟩), d1, j1, js1, + exact (WP.spec_ok _).2 ⟨h1, y1, (fun h => absurd rfl (h _)), (fun v hv => by cases hv; exact ⟨Or.inl rfl, hM.en s1 x m1 hc0⟩), d1, j1, js1, N1, q1⟩ refine WP.spec_bind (spec_eqv (P0.cdt.is_final_capability_with_cap.p0 st s1 x c hS)) fun fin hfe => ?_ refine WP.spec_bind (WP.spec_and (finXQGB hP hO hA hV hR hK hTy h1 hIO N1 y1 h1.ksb hx hc (by rw [j1, js1]; exact x1 c hc) a1 fin) (hM.fin s1 a1 x c fin h1 m1 hx hc ⟨(by rw [j1, js1]; exact x1 c hc), y1, N1⟩ hfe.1)) ?_ - rintro ⟨⟨rem, cl⟩, s2, a2⟩ ⟨⟨hcl, h2, k2, hrem, j2', sc2, v2, hxB'⟩, m2, z2, e2⟩ - simp only at hcl hrem j2' sc2 v2 hxB' m2 z2 e2 + rintro ⟨⟨rem, cl⟩, s2, a2⟩ ⟨⟨hcl, h2, k2, hrem, j2', sc2, v2, hxB'⟩, z2, e2, n2⟩ + simp only at hcl hrem j2' sc2 v2 hxB' z2 e2 n2 have d2 : DomQ st K Vc D Scs T I Is s2 := d1.oka hIO.2 hDO k2 have j2 : L.idleW s2 = I := j2'.trans j1 have js2 : L.mem s2 (scA I) = Is := by rw [j1] at sc2; exact sc2.trans js1 @@ -854,20 +933,17 @@ theorem cdt.finalise_slot_immediate.zqGTMEQ (hP : P0.ArchTotal ar) rcases hrem with rfl | ⟨p, t, n, rfl, hcp, hcov, hpF⟩ · try dsimp only have e2' := e2 rfl - first - | (simp only [cdt.cap_removable, bind_ok, ↓reduceIte] - exact (WP.spec_ok _).2 ⟨h2, y2, m2, (fun v hv => by cases hv; exact ⟨hcl, e2'⟩), d2, j2, js2, N2, q2⟩) - | (simp only [cdt.cap_removable, bind_ok, ↓reduceIte, WP.spec_ok] - exact ⟨h2, y2, m2, (fun v hv => by cases hv; exact ⟨hcl, e2'⟩), d2, j2, js2, N2, q2⟩) - | (simp [cdt.cap_removable, WP.spec_ok]; exact ⟨h2, y2, m2, hcl, e2', d2, j2, js2, N2, q2⟩) + simp [cdt.cap_removable, WP.spec_ok] + exact ⟨h2, y2, hcl, e2', d2, j2, js2, N2, q2⟩ have hxB := hxB' p t n rfl refine WP.spec_bind (spec_eqv (P0.cdt.cap_removable.p0 (.Zombie p t n) x)) fun b1 hb1 => ?_ try dsimp only split · rename_i hrm - exact (WP.spec_ok _).2 ⟨h2, y2, m2, (fun v hv => by cases hv; exact ⟨hcl, e2 (by rw [hb1.1, hrm])⟩), d2, j2, + exact (WP.spec_ok _).2 ⟨h2, y2, (fun h => absurd rfl (h _)), (fun v hv => by cases hv; exact ⟨hcl, e2 (by rw [hb1.1, hrm])⟩), d2, j2, js2, N2, q2⟩ rename_i hnr + have m2 := n2 (by rw [hb1.1]; simpa using hnr) have hn0 : n ≠ 0#u64 := by have hb := hb1.1 rintro rfl @@ -901,7 +977,7 @@ theorem cdt.finalise_slot_immediate.zqGTMEQ (hP : P0.ArchTotal ar) refine WP.spec_bind (slot_index_in p _) fun e he => ?_ subst he have heD : slotIdx p (core.num.U64.wrapping_sub n 1#u64) ∈ D := hcov _ (by rw [wsub1 hn0]; omega) - refine WP.spec_bind (cdt.delete_deferred.zqGME (a := a2) hP hO hA hV hDO hDC hR hK hTy hW hIO hap h3 heD d3 j3 js3 + refine WP.spec_bind (cdt.delete_deferred.zqGMPE (a := a2) hP hO hA hV hDO hDC hR hK hTy hW hIO hap h3 heD d3 j3 js3 N3 y3 hM m3) ?_ rintro ⟨r4, s4, a4⟩ ⟨h4, d4, o4, j4, js4, y4, m4, en4⟩ try simp only [uncurry_apply_pair] at h4 d4 o4 j4 js4 y4 m4 en4 ⊢ @@ -957,9 +1033,39 @@ theorem cdt.finalise_slot_immediate.zqGTMEQ (hP : P0.ArchTotal ar) · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 ⟨h4, y4, m4, (fun v hv => by cases hv), d4, j4, js4, N4, q4⟩ + exact (WP.spec_ok _).2 ⟨h4, y4, (fun _ => m4), (fun v hv => by cases hv), d4, j4, js4, N4, q4⟩ · exact ⟨h, hD, hX, hI, hIs, hN, hY, hm, IrqK.refl s⟩ +/-- (gen 65) **`finalise_slot_immediate.zqGT` with a `LoopME` field**: gen 50's loop proof (moved here), the decrement +by `setd` with the end slot's `EndE` from `delete_deferred.zqGME`, the `Ok` post also giving `Em` of the slot; (gen 93) +the post also returns the domain class, the idle word / idle `SC` field, `IrqN` and the IRQ-node slots kept or +emptied (`IrqK`), carried by the loop. -/ +theorem cdt.finalise_slot_immediate.zqGTMEQ (hP : P0.ArchTotal ar) + (hO : OSOK T Ω Sg OS) (hA : ScApart Scs Z OS) (hV : VcOK T Scs Z OS Vc Ub) (hDO : D ⊆ OS) (hDC : DCan D) + {s0 s : S} (hR : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s0) Pt) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) + (hW : WuApart OS (L.ksb s0)) (hIO : IrqOK OS D (L.ksb s0)) (hap : IrqStApart OS (L.ksb s0)) + {a : A} {x I Is : U64} + (h : JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 s) (hx : x ∈ OS) (hxI : ¬ IslN (L.ksb s0) x) + (hD : DomQ st K Vc D Scs T I Is s) (hX : XQ st K Vc D Scs T I Is x s) (hI : L.idleW s = I) + (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) + {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} + {Em : S → U64 → Prop} + (hM : LoopME st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Em M) + (hm : M s) : + cdt.finalise_slot_immediate st ar s a x ⦃ r => + JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 r.2.1 ∧ Ty r.2.1 ∧ M r.2.1 ∧ + (∀ v, r.1 = .Ok v → ClOK v.cleanup ∧ Em r.2.1 x) ∧ DomQ st K Vc D Scs T I Is r.2.1 ∧ L.idleW r.2.1 = I ∧ + L.mem r.2.1 (scA I) = Is ∧ IrqN st (L.ksb s0) r.2.1 ∧ IrqK st (L.ksb s0) s r.2.1 ⦄ := by + refine WP.spec_mono (cdt.finalise_slot_immediate.zqGTMPQ (a := a) hP hO hA hV hDO hDC hR hK hTy hW hIO hap h hx hxI + hD hX hI hIs hN hY hM.toP hm) ?_ + rintro r ⟨h1, y1, m1, v1, d1, j1, js1, N1, q1⟩ + refine ⟨h1, y1, ?_, fun v hv => ⟨(v1 v hv).1, (v1 v hv).2.2⟩, d1, j1, js1, N1, q1⟩ + by_cases ok : ∃ v, r.1 = .Ok v + · obtain ⟨v, hv⟩ := ok + exact (v1 v hv).2.1 + · exact m1 fun v hv => ok ⟨v, hv⟩ + set_option maxHeartbeats 4000000 in /-- (gen 65) **`finalise_slot_immediate.zqGT` with a `LoopME` field** (gen 93: `zqGTMEQ` without the loop's facts). -/ theorem cdt.finalise_slot_immediate.zqGTME (hP : P0.ArchTotal ar) @@ -1066,10 +1172,8 @@ theorem cdt.finalise_slot_immediate.zqG (hP : P0.ArchTotal ar) /-! ## The exposed deletion -/ set_option maxHeartbeats 4000000 in -/-- (gen 65) **`cdt.delete.zqIGT` with a `LoopME` field** (gen 50's proof moved here; `emp` given `Em`); (gen 93) the -post also returns the domain class, the idle word / idle `SC` field, `IrqN` and `IrqK` for the next deletion -(`zqGTMEQ`; `empty_slot` keeps the other `OS` slots' caps, the idle word and the `SC` fields). -/ -theorem cdt.delete.zqIGTMEQ (hP : P0.ArchTotal ar) +/-- (A64-S1A gen 41) **`delete.zqIGTMEQ` with a pending window** (`LoopMP`; the proof, moved here). -/ +theorem cdt.delete.zqIGTMPQ (hP : P0.ArchTotal ar) (hO : OSOK T Ω Sg OS) (hA : ScApart Scs Z OS) (hV : VcOK T Scs Z OS Vc Ub) (hDO : D ⊆ OS) (hDC : DCan D) {s0 s : S} (hR : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s0) Pt) (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) @@ -1079,22 +1183,22 @@ theorem cdt.delete.zqIGTMEQ (hP : P0.ArchTotal ar) (hD : DomQ st K Vc D Scs T I Is s) (hX : XQ st K Vc D Scs T I Is x s) (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} - {Em : S → U64 → Prop} - (hM : LoopME st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Em M) + {Pn : S → U64 → Prop} + (hM : LoopMP st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Pn M) (hm : M s) : cdt.delete st ar s a x true ⦃ r => JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 r.2.1 ∧ Ty r.2.1 ∧ M r.2.1 ∧ DomQ st K Vc D Scs T I Is r.2.1 ∧ L.idleW r.2.1 = I ∧ L.mem r.2.1 (scA I) = Is ∧ IrqN st (L.ksb s0) r.2.1 ∧ IrqK st (L.ksb s0) s r.2.1 ⦄ := by unfold cdt.delete simp only [↓reduceIte] - refine WP.spec_bind (cdt.finalise_slot_immediate.zqGTMEQ (a := a) hP hO hA hV hDO hDC hR hK hTy hW hIO hap h hx hxI + refine WP.spec_bind (cdt.finalise_slot_immediate.zqGTMPQ (a := a) hP hO hA hV hDO hDC hR hK hTy hW hIO hap h hx hxI hD hX hI hIs hN hY hM hm) ?_ rintro ⟨r, s1, a1⟩ ⟨h1, y1, m1, hv1, d1, j1, js1, N1, q1⟩ try simp only [uncurry_apply_pair] at h1 y1 m1 hv1 d1 j1 js1 N1 q1 ⊢ rcases r with v | e · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.empty_slot.zs hP hO hV h1 hx (hv1 v rfl).1 hap) - (cdt.empty_slot.vk hP hO hR h1 hx (hv1 v rfl).1 h1.ksb)) (hM.emp s1 a1 x _ h1 m1 hx (hv1 v rfl).1 (hv1 v rfl).2)) ?_ + (cdt.empty_slot.vk hP hO hR h1 hx (hv1 v rfl).1 h1.ksb)) (hM.emp s1 a1 x _ h1 (hv1 v rfl).2 hx (hv1 v rfl).1)) ?_ rintro ⟨s2, a2⟩ ⟨⟨h2, v2⟩, m2⟩ try simp only [uncurry_apply_pair] at h2 v2 m2 ⊢ obtain ⟨h2, k2, c2, i2, sc2⟩ := h2 @@ -1108,7 +1212,28 @@ theorem cdt.delete.zqIGTMEQ (hP : P0.ArchTotal ar) · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] - exact (WP.spec_ok _).2 ⟨h1, y1, m1, d1, j1, js1, N1, q1⟩ + exact (WP.spec_ok _).2 ⟨h1, y1, m1 (fun _ h => by cases h), d1, j1, js1, N1, q1⟩ + +/-- (gen 65) **`cdt.delete.zqIGT` with a `LoopME` field** (gen 50's proof moved here; `emp` given `Em`); (gen 93) the +post also returns the domain class, the idle word / idle `SC` field, `IrqN` and `IrqK` for the next deletion +(`zqGTMEQ`; `empty_slot` keeps the other `OS` slots' caps, the idle word and the `SC` fields). -/ +theorem cdt.delete.zqIGTMEQ (hP : P0.ArchTotal ar) + (hO : OSOK T Ω Sg OS) (hA : ScApart Scs Z OS) (hV : VcOK T Scs Z OS Vc Ub) (hDO : D ⊆ OS) (hDC : DCan D) + {s0 s : S} (hR : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s0) Pt) + (hK : FinKT st ar (L.ksb s0) Pt Ty K) (hTy : TyK st (L.ksb s0) Pt Ty) + (hW : WuApart OS (L.ksb s0)) (hIO : IrqOK OS D (L.ksb s0)) (hap : IrqStApart OS (L.ksb s0)) + {a : A} {x I Is : U64} + (h : JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 s) (hx : x ∈ OS) (hxI : ¬ IslN (L.ksb s0) x) + (hD : DomQ st K Vc D Scs T I Is s) (hX : XQ st K Vc D Scs T I Is x s) (hI : L.idleW s = I) + (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) + {M : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} + {Em : S → U64 → Prop} + (hM : LoopME st ar OS D (JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0) (XQF st K Vc D Scs T Ty (L.ksb s0)) Zr Em M) + (hm : M s) : + cdt.delete st ar s a x true ⦃ r => JV st T Cs Ω H Sg Rp Scs Nt Z Ac OS Vc Ub s0 r.2.1 ∧ Ty r.2.1 ∧ M r.2.1 ∧ + DomQ st K Vc D Scs T I Is r.2.1 ∧ L.idleW r.2.1 = I ∧ L.mem r.2.1 (scA I) = Is ∧ IrqN st (L.ksb s0) r.2.1 ∧ + IrqK st (L.ksb s0) s r.2.1 ⦄ := by + exact cdt.delete.zqIGTMPQ (a := a) hP hO hA hV hDO hDC hR hK hTy hW hIO hap h hx hxI hD hX hI hIs hN hY hM.toP hm set_option maxHeartbeats 4000000 in /-- (gen 65) **`cdt.delete.zqIGT` with a `LoopME` field** (gen 93: `zqIGTMEQ` without the next deletion's facts). -/ diff --git a/proofs/Fl4ProofsA64/P1/S1aArmCol.lean b/proofs/Fl4ProofsA64/P1/S1aArmCol.lean index 11c462e7a..6a01a0a68 100644 --- a/proofs/Fl4ProofsA64/P1/S1aArmCol.lean +++ b/proofs/Fl4ProofsA64/P1/S1aArmCol.lean @@ -262,7 +262,7 @@ theorem tcb.decode.readFpu_s1aCol (hA : P0.ArchTotal ar) (hl : lbl = fl4_abi.label.TCBReadFPU) : tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => S1aArmCol st H Cs OS Vc Ub s → S1aArmCol st H Cs OS Vc Ub r.2.1 ⦄ := - S1aArmCol.liftDFB D P B hvr hks (fun _ h => h) (tcb.decode.readFpuLK hA D P B Y hl) + S1aArmCol.liftDFB D P B hvr hks (fun _ h => h.1) (tcb.decode.readFpuLK hA D P B Y hl) /-- TCB UnbindNotification (MdbDfM's `unbindNLK`, the DM wrapper). -/ theorem tcb.decode.unbindN_s1aCol (hA : P0.ArchTotal ar) diff --git a/proofs/Fl4ProofsA64/P1/S1aArmDel.lean b/proofs/Fl4ProofsA64/P1/S1aArmDel.lean index 22f255785..a4cee24c4 100644 --- a/proofs/Fl4ProofsA64/P1/S1aArmDel.lean +++ b/proofs/Fl4ProofsA64/P1/S1aArmDel.lean @@ -59,7 +59,7 @@ variable {Vq Ub' Pt : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} /-- **TCB SetHighVSpace carries the column** (a64's `highVS_armQI`). -/ theorem syscall.decode_invocation.highVS_s1aCol (hA : P0.ArchTotal ar) {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {t : U64} (I : DelIn st ar H Cs OS Vq Ub' Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetHighVSpace) (len : U64) @@ -69,7 +69,7 @@ theorem syscall.decode_invocation.highVS_s1aCol (hA : P0.ArchTotal ar) {s : S} S1aArmCol.liftTZ (syscall.decode_invocation.highVS_armQI hA I hKZ hPI D P B Y a hl len blk call don fp buf) /-- **The exposed deletion carries the column** (a64's `cdt.delete.armQI`). -/ -theorem cdt.delete.s1aCol {s0 s : S} (I : DelIn st ar H Cs OS Vq Ub' Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Ty K) +theorem cdt.delete.s1aCol {s0 s : S} (I : DelIn st ar H Cs OS Vq Ub' Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vq Ub' Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : cdt.delete st ar s a x true ⦃ r => S1aArmCol st H Cs OS Vc Ub s0 → S1aArmCol st H Cs OS Vc Ub r.2.1 ⦄ := diff --git a/proofs/Fl4ProofsA64/P1/S1aArmDelU.lean b/proofs/Fl4ProofsA64/P1/S1aArmDelU.lean index ae4d79dd7..e3c7dc982 100644 --- a/proofs/Fl4ProofsA64/P1/S1aArmDelU.lean +++ b/proofs/Fl4ProofsA64/P1/S1aArmDelU.lean @@ -96,7 +96,7 @@ variable {Vq Uq Pt : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} {s /-- **TCB SetSpace** (a64's `setSpace_armQI`). -/ theorem syscall.decode_invocation.setSpace_s1aColU (hA : P0.ArchTotal ar) {t : U64} - (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetSpace) (len : U64) @@ -107,7 +107,7 @@ theorem syscall.decode_invocation.setSpace_s1aColU (hA : P0.ArchTotal ar) {t : U /-- **TCB SetIPCBuffer** (a64's `setIpcBuf_armQI`). -/ theorem syscall.decode_invocation.setIpcBuf_s1aColU (hA : P0.ArchTotal ar) {t : U64} - (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetIPCBuffer) (len : U64) @@ -118,7 +118,7 @@ theorem syscall.decode_invocation.setIpcBuf_s1aColU (hA : P0.ArchTotal ar) {t : /-- **TCB Configure** (a64's `configure_armQI`). -/ theorem syscall.decode_invocation.configure_s1aColU (hA : P0.ArchTotal ar) {t : U64} - (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBConfigure) (len : U64) @@ -129,7 +129,7 @@ theorem syscall.decode_invocation.configure_s1aColU (hA : P0.ArchTotal ar) {t : /-- **TCB SetEPTRoot** (a64's `setEpt_armQI`, its ruled `hXE`). -/ theorem syscall.decode_invocation.setEpt_s1aColU (hA : P0.ArchTotal ar) {t : U64} - (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) @@ -142,7 +142,7 @@ theorem syscall.decode_invocation.setEpt_s1aColU (hA : P0.ArchTotal ar) {t : U64 /-- **IRQ ClearIRQHandler** (a64's `irqClear_armQI`). -/ theorem syscall.decode_invocation.irqClear_s1aColU {irq : U64} (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.IrqHandler irq) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.IRQClearIRQHandler) (hi : irq.val < 5376) @@ -153,7 +153,7 @@ theorem syscall.decode_invocation.irqClear_s1aColU {irq : U64} (I : DelIn st ar /-- **IRQ SetIRQHandler** (a64's `irqSet_armQI`, its ruled `hSC`). -/ theorem syscall.decode_invocation.irqSet_s1aColU {irq : U64} (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.IrqHandler irq) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.IRQSetIRQHandler) (hi : irq.val < 5376) @@ -165,7 +165,7 @@ theorem syscall.decode_invocation.irqSet_s1aColU {irq : U64} (I : DelIn st ar H /-- **TCB SetHighVSpace** (a64's `highVS_armQI`; the gen-9 `highVS_s1aCol` with `S1aDelU`). -/ theorem syscall.decode_invocation.highVS_s1aColU (hA : P0.ArchTotal ar) {t : U64} - (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetHighVSpace) (len : U64) @@ -176,7 +176,7 @@ theorem syscall.decode_invocation.highVS_s1aColU (hA : P0.ArchTotal ar) {t : U64 /-- **CNode Revoke / Delete at the decode** (a64's `cnodeRvDel_armQI`). -/ theorem syscall.decode_invocation.cnodeRvDel_s1aColU {cap : capability.Cap} (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hf : capFam cap = .cnode) (a : A) {lbl : U64} @@ -189,7 +189,7 @@ theorem syscall.decode_invocation.cnodeRvDel_s1aColU {cap : capability.Cap} (I : /-- **CNode Revoke / Delete, `cnode.decode` level** (a64's `cnode.decode.rvDelQ`). -/ theorem cnode.decode.rvDel_s1aColU {cap : capability.Cap} (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (a : A) {lbl len buf : U64} @@ -199,7 +199,7 @@ theorem cnode.decode.rvDel_s1aColU {cap : capability.Cap} (I : DelIn st ar H Cs WP.spec_mono (cnode.decode.rvDelQ I hKZ hPI D P B Y hcap a hl) fun _ d => S1aArmCol.ofTZU d /-- **`cdt.revoke` from `DelR ∧ PoolR`** (a64's `cdt.revoke.armQI`). -/ -theorem cdt.revoke.s1aColU {s0 : S} (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Ty K) +theorem cdt.revoke.s1aColU {s0 : S} (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vq Uq Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) (hx : x ∈ OS) : cdt.revoke st ar s a x ⦃ r => S1aArmCol st H Cs OS Vc Ub s0 → @@ -207,7 +207,7 @@ theorem cdt.revoke.s1aColU {s0 : S} (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s0) ( WP.spec_mono (cdt.revoke.armQI I hKZ hPI R Q hx) fun _ d => S1aArmCol.ofTZU d /-- **The exposed deletion at the decode's own heap and slots** (a64's `cdt.delete.delRP`: `DelR` names `H`, `OS`). -/ -theorem cdt.delete.s1aColU {s0 : S} (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Ty K) +theorem cdt.delete.s1aColU {s0 : S} (I : DelIn st ar H Cs OS Vq Uq Pt K Ty s0) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) {a : A} {x : U64} (R : DelR st H Cs OS Vq Uq Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : cdt.delete st ar s a x true ⦃ r => S1aArmCol st H Cs OS Vc Ub s0 → diff --git a/proofs/Fl4ProofsA64/P1/S1aArmZ2.lean b/proofs/Fl4ProofsA64/P1/S1aArmZ2.lean index c057aa76d..76a3dc051 100644 --- a/proofs/Fl4ProofsA64/P1/S1aArmZ2.lean +++ b/proofs/Fl4ProofsA64/P1/S1aArmZ2.lean @@ -18,6 +18,9 @@ MdbArmQZ2). * **The dispatcher-level top `syscall.decode_invocation.armQZ2_s1a`**: over a64's `armQZ2At` (its hypotheses verbatim), post `S1aZ2 … (DecArmKK cap lbl) s s'`; on `DecArmKK` arms `armKKAt` is used instead. +(A64-S1A gen 40, Architect ruling for gen 40, R3) `armKKAt` also posts the a64 tops' exported `ArmVsK` (last conjunct; +S1aHiK's `HiCap511` frame). + Named premises: none. Case facts: none new (a64's `armQZ2At` reads `DelIn`, `FinKZ`, `PoolIdx`, `hks`, `hIq`, `hSC`). -/ import Fl4ProofsA64.P1.S1aArmDelU @@ -70,7 +73,7 @@ theorem syscall.decode_invocation.armKKAt (hA : P0.ArchTotal ar) {s : S} {cap : (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) {lbl : U64} (hc : DecArmKK cap lbl) (len : U64) (blk call don fp : Bool) (buf : U64) : syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => - ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ⦄ := by + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by have hvr := I.del.vr have hSA := I.del.sca obtain ⟨hc, hn⟩ := hc @@ -90,14 +93,15 @@ theorem syscall.decode_invocation.armKKAt (hA : P0.ArchTotal ar) {s : S} {cap : · exact WP.spec_mono (syscall.decode_invocation.rej_eq hr a lbl len blk call don fp buf) fun ⟨_, s', _⟩ e => by subst e - exact ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl _, fun _ _ => ⟨rfl, rfl, rfl, rfl⟩⟩ + exact ⟨ArmQIAt.refl B Y D.bxi.blk, TabKeep.refl _, fun _ _ => ⟨rfl, rfl, rfl, rfl⟩, + ArmVsK.refl _⟩ · exact syscall.decode_invocation.mcp_armQIKAt hA D P B Y hvr a hl len blk call don fp buf /-- **The dispatcher-level S1a top over a64's `armQZ2At`** (module docstring): one `(H, OS)` across the step. -/ theorem syscall.decode_invocation.armQZ2_s1a (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {Ub' : Set U64} (I : DelIn st ar H Cs OS Vq Ub' Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) @@ -112,7 +116,7 @@ theorem syscall.decode_invocation.armQZ2_s1a (hA : P0.ArchTotal ar) {s : S} {cap · exact WP.spec_mono (syscall.decode_invocation.armKKAt hA I D P B Y hcap hks a hk len blk call don fp buf) fun r d => by obtain ⟨_, _, _⟩ := r - exact S1aZ2.ofK d + exact S1aZ2.ofK ⟨d.1, d.2.1, d.2.2.1⟩ · exact WP.spec_mono (syscall.decode_invocation.armQZ2At hA I hKZ hPI D P B Y hcap hks a hc hIq hSC len blk call don fp buf) fun r d => by diff --git a/proofs/Fl4ProofsA64/P1/S1aBootK.lean b/proofs/Fl4ProofsA64/P1/S1aBootK.lean new file mode 100644 index 000000000..49aad30d8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aBootK.lean @@ -0,0 +1,246 @@ +/- +P1 (aarch64, A64-S1A gen 25): **the kernel TTBR1 tables at the boot witnesses** (Architect ruling on K0, F1 item 2; +S1aKTab). Over A64-Boot's `w0` / `w1` definitions only (BootWit, BootW1: not edited). + +* **`Kt = ∅`** at the existing witnesses: **`w0_ktOutE`**, **`w1_ktOutE`** (`KtOut.empty`; `KtH H ∅ = H`, so the + bundle at `w1` is unchanged), **`w1_ktE`** (with `KTab.empty` for an arch without kernel table entries). +* **`Kt ≠ ∅`, non-vacuous** (`w1` extended locally): one capless 4 KiB kernel table **`kt`** at `KT = IM + 4096` (the + page after the image page, above every object, slot, untyped region and user frame of `w1`, all of whose words are + `0` in `w1`'s memory: **`w1M_kt`**), named by the table descriptor `KTe = paddr(kt) | 3` that the arch + **`w1Ar ar`** (`ar` with `kernel_ttbr1_entry a 0 256 = KTe`, every other entry `0`) returns as its TTBR1 L0[256]: + **`w1Ar_ktab`** (`KTab (w1Ar ar) {kt} (fun _ => 1)`), **`w1Ar_l0`** (the entry is a non-zero table descriptor). + * **`w1K_out`**: `KtOut` at `w1` for `{kt}` (no `w1` cap names `kt`: it lies off every object `w1`'s caps name); + * **`w1K_bundle`**: `SysL`, `HeapKsOff`, `HeapOK`, the column `S1aPtCol` at `w1Pt ∪ {kt}` (`PtCap`, `PtHG`, + `HiCap511`) and `VrOK` at `w1Pt ∪ {kt}` over `KtH (w1H …) {kt}`, with `kt` an `other 12` object; and, from + `SymL` / `DelIn` at `w1` (not built on the base witness either: entry-layer work), `KtBundle` at the extension + (**`w1K_bundleOf`**, S1aKTab's `KtBundle.addKt`); + * **`w1K_vs`**: `VsTy` at `w1` over `insert kt w1Tb ⊆ w1Pt ∪ {kt}` with `kt` at level 1 (`VsTy.addZ`) — the kernel + table is a `Tb` table inside `Pt ∪ Kt`, with `PtHG` and `VrOK` holding: B2's obstacle is gone; + * **`w1K_assign2`**: `VsTy.assign2` at that witness with `KTab (w1Ar ar)`: the tag-2 pool write of a `HighVSpace` + root whose entries are the kernel L0 copies (L0[256] → `kt`) keeps `VsTy` over `insert R (insert kt w1Tb)`. + +Named premises: none new (S1aKTab's [P] `KTab` is instantiated here, at `w1Ar ar`). Case facts: none new. +-/ +import Fl4ProofsA64.P1.S1aKTab +import Fl4ProofsA64.P1.S1aKtUt +import Fl4ProofsA64.P1.S1aBootW1 +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST +/-- Project the Untyped clause of the existing boot kernel-table placement witness. -/ +theorem KtOut.s1aKtUt {S : Type _} {st : machine.Store S} [LawfulStore st] + {H : Heap} {Cs OS Vc Ub Kt : Set U64} {s : S} (h : KtOut st H Cs OS Vc Ub Kt s) : + S1aKtUt st OS Kt s := h.ut + +namespace BootWit + +/-- The kernel table `kt = IM + 4096`. -/ +scoped notation "KTb" => (18446607734267711488 : Nat) +/-- Its TTBR1 L0 table descriptor `paddr(kt) | 3` (`paddr kt = 2^42 + 4096`). -/ +scoped notation "KTe" => (4398046515203 : Nat) + +noncomputable section + +theorem vKT : (bwv KTb).val = KTb := wv (by norm_num) + +theorem kte3 : (bwv KTe &&& 3#u64) = 3#u64 := rfl + +theorem kteT : wa (bwv KTe &&& vspace.ADDR_MASK) layout.PPTR_BASE = bwv KTb := by + unfold vspace.ADDR_MASK layout.PPTR_BASE; rfl + +/-! ## The arch with one kernel table -/ + +/-- **`ar` with one non-zero kernel TTBR1 L0 entry**: `L0[256]` the table descriptor of `kt`. -/ +def w1Ar {A : Type _} (ar : machine.Arch A) : machine.Arch A := + { ar with kernel_ttbr1_entry := fun _ l i => if l = 0#u64 ∧ i = 256#u64 then ok (bwv KTe) else ok 0#u64 } + +theorem w1Ar_l0 {A : Type _} (ar : machine.Arch A) (a : A) : + (w1Ar ar).kernel_ttbr1_entry a 0#u64 256#u64 = ok (bwv KTe) ∧ bwv KTe ≠ 0#u64 := + ⟨by + show (if (0#u64 : U64) = 0#u64 ∧ (256#u64 : U64) = 256#u64 then ok (bwv KTe) else ok 0#u64) = ok (bwv KTe) + rw [if_pos ⟨rfl, rfl⟩], + fun h => and3z (h ▸ kte3)⟩ + +/-- **`KTab` at `w1Ar ar` with the one kernel table `kt` at level 1.** -/ +theorem w1Ar_ktab {A : Type _} (ar : machine.Arch A) : KTab (w1Ar ar) {bwv KTb} (fun _ => 1) := by + refine ⟨fun a i e hi he h3 => ?_⟩ + change (if (0#u64 : U64) = 0#u64 ∧ i = 256#u64 then ok (bwv KTe) else ok 0#u64) = ok e at he + by_cases hc : (0#u64 : U64) = 0#u64 ∧ i = 256#u64 + · rw [if_pos hc] at he + rw [← okinj he, kteT] + exact ⟨rfl, rfl⟩ + · rw [if_neg hc] at he + rw [← okinj he] at h3 + exact absurd h3 and3z + +/-! ## `Kt = ∅` at the existing witnesses -/ + +section empty +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} + +theorem w0_ktOutE : KtOut bst (bootH kb ib nc) (bootCs nc) (bootOS kb ib nc) ∅ ∅ ∅ (bootS kb ib nc r now mt) := + KtOut.empty + +theorem w1_ktOutE : KtOut bst (w1H kb ib nc) (bootCs nc) (w1OS kb ib nc) ∅ w1Ub ∅ (w1S kb ib nc r now mt sl uw) := + KtOut.empty + +/-- **`w1` at `Kt = ∅`**: `KTab` (an arch without kernel table entries), the placement, and the heap unchanged. -/ +theorem w1_ktE {A : Type _} {ar : machine.Arch A} (KLv : U64 → Nat) + (h : ∀ (a : A) (i e : U64), i.val < 511 → ar.kernel_ttbr1_entry a 0#u64 i = ok e → (e &&& 3#u64) ≠ 3#u64) : + KTab ar ∅ KLv ∧ KtOut bst (w1H kb ib nc) (bootCs nc) (w1OS kb ib nc) ∅ w1Ub ∅ (w1S kb ib nc r now mt sl uw) ∧ + KtH (w1H kb ib nc) ∅ = w1H kb ib nc := + ⟨KTab.empty KLv h, KtOut.empty, KtH.empty⟩ + +end empty + +/-! ## `Kt = {kt}` at `w1` -/ + +section w1 +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} (P : BootLay1 kb ib nc) +include P + +set_option hygiene false in +local notation "S1" => w1S kb ib nc r now mt sl uw +set_option hygiene false in +local notation "H1" => w1H kb ib nc +set_option hygiene false in +local notation "OS1" => w1OS kb ib nc +set_option hygiene false in +local notation "HK" => KtH (w1H kb ib nc) {bwv KTb} + +omit P in +theorem ktv {q : U64} (hq : q ∈ ({bwv KTb} : Set U64)) : q.val = KTb := by + rw [Set.mem_singleton_iff.1 hq]; exact vKT + +omit P in +theorem p18 : (2 : Nat) ^ (HKind.other 18).bits = 262144 := by simp [HKind.bits] +omit P in +theorem pT : (2 : Nat) ^ (HKind.tcb).bits = 4096 := by simp [HKind.bits] +omit P in +theorem p7 : (2 : Nat) ^ (HKind.sc 7).bits = 128 := by simp [HKind.bits] + +/-- **`kt`'s words are `0` in `w1`'s memory.** -/ +theorem w1M_kt {o : U64} (ho : o.val < 4096) : bL.mem S1 (wa (bwv KTb) o) = 0#u64 := by + have hv : (wa (bwv KTb) o).val = KTb + o.val := by rw [wadd_val (by rw [vKT]; omega), vKT] + have := P.kbR; have := P.ibR; have := P.w0.nc0 + show w1M kb ib nc r now mt sl uw _ = 0#u64 + unfold w1M bootM + 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)] + +/-- **The kernel table's placement at `w1`** (module docstring). -/ +theorem w1K_out : KtOut bst H1 (bootCs nc) OS1 ∅ w1Ub {bwv KTb} S1 where + al q hq := by have := ktv hq; omega + fits q hq := by have := ktv hq; omega + nz q hq e := by have := ktv hq; rw [e] at this; simp at this + fresh q hq p k hp := by + have vq := ktv hq + right + rcases w1H_pos P hp with ⟨-, h⟩ | ⟨h, rfl⟩ | ⟨h, rfl⟩ | ⟨j, -, hj, -, h, rfl⟩ | ⟨h, rfl⟩ | ⟨h, rfl⟩ + · omega + · rw [p18]; omega + · rw [pT]; omega + · rw [two12]; omega + · rw [p7]; omega + · rw [two12]; omega + disj q hq q' hq' hne := absurd ((Set.mem_singleton_iff.1 hq).trans (Set.mem_singleton_iff.1 hq').symm) hne + nodes q hq c hc := by + have vq := ktv hq + have hc' : c.val < nc := hc + have := P.kbR; have := P.w0.nc128 + right + show kb.val + 223488 + c.val * 4288 + 4288 ≤ q.val + omega + ks q hq := by + have vq := ktv hq + have := P.kbR + right + show kb.val + 788736 ≤ q.val + omega + ut q hq u hu p b i d h := by + have vq := ktv hq + obtain ⟨-, rfl, rfl, -, -⟩ := w1_ut P hu h + have h20 : (20#u64 : U64).val = 20 := by simp + right + rw [vUT, h20, show (2 : Nat) ^ 20 = 1048576 by norm_num] + omega + os q hq y hy := by + have vq := ktv hq + have := P.kbR; have := P.ibR + right + rcases w1OS_val P hy with ⟨t, c, i, -, hc, et, hi, -, ex⟩ | ⟨i, hi, -, ex⟩ | ⟨i, hi, ex⟩ | ⟨j, hj, -, ex⟩ <;> + omega + vc q hq v hv := absurd hv (by simp) + ub q hq b hb := by + have vq := ktv hq + left + rcases hb.2 with ⟨-, h⟩ | ⟨-, h⟩ | ⟨-, h⟩ <;> omega + +/-- **The bundle at `w1` with the kernel table** (module docstring). -/ +theorem w1K_bundle : + SysL bst HK (bootCs nc) OS1 ib.val (ib.val + nc * 8192) S1 ∧ HeapOK HK ∧ HeapKsOff HK kb ∧ + S1aPtCol bst HK OS1 (w1Pt ∪ {bwv KTb}) S1 ∧ + VrOK (HK).omega (HK).frame (HK).scs (HK).scBits OS1 ∅ w1Ub kb (w1Pt ∪ {bwv KTb}) ∧ + HK (bwv KTb) = some (.other 12) := + have X := w1K_out (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P + ⟨SysL.addKt X (w1_sysL P), X.heapOK (w1H_ok P), X.ksOff (w1H_ksOff P), S1aPtCol.addKt X (w1_s1aPtCol P), + X.vrOK (fun _ h => absurd h (by simp)) P.w0.kbw (w1_vrOK P), + Heap.add_of_mem (H := H1) (N := (· ∈ ({bwv KTb} : Set U64))) (kd := .other 12) rfl⟩ + +/-- **The audit's bundle at the extended `w1`**, from `SymL` / `DelIn` at `w1` (module docstring). -/ +theorem w1K_bundleOf {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : BS → Prop} + (Y : SymL bst H1 (bootCs nc) S1) (I : DelIn bst ar H1 (bootCs nc) OS1 ∅ w1Ub w1Pt K Ty S1) : + KtBundle bst ar HK (bootCs nc) OS1 ∅ w1Ub (w1Pt ∪ {bwv KTb}) K Ty ib.val (ib.val + nc * 8192) S1 := + KtBundle.addKt ⟨w1_sysL P, Y, I, w1H_ksOff P, w1_s1aPtCol P⟩ (w1K_out P) + +/-- **`VsTy` at `w1` with the kernel table at level 1** (module docstring). -/ +theorem w1K_vs : + VsTy bst kb (PoolSet bst Set.univ S1) (insert (bwv KTb) w1Tb) (Function.update w1Lv (bwv KTb) 1) S1 ∧ + insert (bwv KTb) w1Tb ⊆ w1Pt ∪ {bwv KTb} := by + have hz : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → (bL.mem S1 (wa (bwv KTb) o) &&& 3#u64) ≠ 3#u64 := + fun o ho _ => by rw [w1M_kt P ho]; exact and3z + have hn : bwv KTb ∉ w1Tb := fun h => by rcases h with e | e | e | e <;> rw [vKT] at e <;> norm_num at e + refine ⟨VsTy.addZ (w1_column P Set.univ).1.2.2.2.2.1 hn 1 hz, ?_⟩ + rintro x (rfl | h) + · exact Or.inr rfl + · rcases h with e | e | e | e + · exact Or.inl (Or.inl e) + · exact Or.inl (Or.inr (Or.inr (Or.inl e))) + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inl e)))) + · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inr e)))) + +/-- **`VsTy.assign2` at the extended `w1`** (module docstring): the tag-2 pool write of a `HighVSpace` root `R` whose +entries are `w1Ar ar`'s kernel level-0 copies keeps `VsTy`, the kernel table `kt` typed at level 1. -/ +theorem w1K_assign2 {A : Type _} (ar : machine.Arch A) {R w v : U64} + (hroot : ∀ o : U64, o.val < 4088 → o.val % 8 = 0 → (bL.mem S1 (wa R o) &&& 3#u64) = 3#u64 → + ∃ (a : A) (i : U64), i.val < 511 ∧ (w1Ar ar).kernel_ttbr1_entry a 0#u64 i = ok (bL.mem S1 (wa R o))) + (h511 : (bL.mem S1 (wa R 4088#u64) &&& 3#u64) = 3#u64 → + wa (bL.mem S1 (wa R 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ insert (bwv KTb) w1Tb ∧ + Function.update w1Lv (bwv KTb) 1 (wa (bL.mem S1 (wa R 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE) = 1) + (hR : R ∈ insert (bwv KTb) w1Tb → Function.update w1Lv (bwv KTb) 1 R = 0) + (hv2 : (v &&& 3#u64) = 2#u64) (hvR : (v &&& ~~~3#u64) = R) + (hwA : ¬ AsW kb w) (hwT : ¬ PtW (insert R (insert (bwv KTb) w1Tb)) w) (hal : Aligned w) + (hall : ∀ b, VsR kb (insert R (insert (bwv KTb) w1Tb) ∪ PoolSet bst Set.univ S1) b → Aligned b) : + VsTy bst kb (PoolSet bst Set.univ S1) (insert R (insert (bwv KTb) w1Tb)) + (Function.update (Function.update w1Lv (bwv KTb) 1) R 0) (bL.wr S1 w v) := + VsTy.assign2 (w1K_vs P).1 (w1Ar_ktab ar) + (fun t ht => by obtain rfl := Set.mem_singleton_iff.1 ht; exact ⟨Set.mem_insert _ _, by simp⟩) + hroot h511 hR hv2 hvR hwA hwT hal hall + +end w1 + +end + +end BootWit +end ST +end R +end W7 + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aBootW1.lean b/proofs/Fl4ProofsA64/P1/S1aBootW1.lean index 798ac02af..0d6f11a8f 100644 --- a/proofs/Fl4ProofsA64/P1/S1aBootW1.lean +++ b/proofs/Fl4ProofsA64/P1/S1aBootW1.lean @@ -10,11 +10,14 @@ P1 (aarch64, A64-S1A gen 22): **the page-table column `S1aPtCol` at the window-r VSpace root, the pool and the three tables, is a 4 KiB `other` object of `w1H`; unchanged by the relocation). * **`w1_s1aPtCol`**: `S1aPtCol bst (w1H …) (w1OS …) w1Pt (w1S …)` (`cap` by `w1_ptCapK`, `ph` by `w1_ptHG`, `hi` by `HiCap511.ofNoHv`: `w1` has no `HighVSpace` cap). +* (gen 33) **`capOf_devFr`** / **`w1_devFrAl`**: `DevFrAl` at `w1` (every boot frame cap is non-device). +* (gen 39) **`w1_hvPt`**: S1aHvPt's `HvPt` at `w1` (no `HighVSpace` cap). Named premises: none. Case facts: none new. -/ import Fl4ProofsA64.P1.BootSysL1 import Fl4ProofsA64.P1.S1aPtStep +import Fl4ProofsA64.P1.S1aHvPt open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P1 @@ -44,6 +47,12 @@ theorem capOf_ptK (nc i : Nat) : | (cases h; exact w1Pt_l2) | (cases h; exact w1Pt_l3)) +set_option maxHeartbeats 4000000 in +/-- **No root CNode slot holds a device `Frame` cap** (gen 33; BootMdb1's `capsplit`: every boot frame is +non-device). -/ +theorem capOf_devFr (nc i : Nat) : DevFrP (capOf nc i) := by + capsplit (refine fun p sz r m e a v h => ?_; cases h) + section w1 variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} (P : BootLay1 kb ib nc) include P @@ -66,13 +75,25 @@ theorem w1_ptCapK {y : U64} (hy : y ∈ OS1) : · exact ⟨fun _ _ _ _ h => (by cases h), fun _ _ _ h => (by cases h)⟩ · exact ⟨PtCapP.null _, fun _ _ _ h => by cases h⟩ -omit P in -/-- **`PtHG` at `w1`** (module docstring). -/ -theorem w1_ptHG : PtHG H1 w1Pt := PtHG.ofVcH w1_pt +/-- **`PtHG` at `w1`** (module docstring; gen 34: the alignment by `w1H_ok`). -/ +theorem w1_ptHG : PtHG H1 w1Pt := PtHG.ofVcH (w1H_ok P) w1_pt /-- **The S1a page-table column at `w1`** (module docstring). -/ theorem w1_s1aPtCol : S1aPtCol bst H1 OS1 w1Pt S1 := - ⟨fun _ hy => (w1_ptCapK P hy).1, w1_ptHG, HiCap511.ofNoHv fun _ hy => (w1_ptCapK P hy).2⟩ + ⟨fun _ hy => (w1_ptCapK P hy).1, w1_ptHG P, HiCap511.ofNoHv fun _ hy => (w1_ptCapK P hy).2⟩ + +/-- **`DevFrAl` at `w1`** (gen 33; also at the extended `w1` of S1aBootK, same state and slots). -/ +theorem w1_devFrAl : DevFrAl bst OS1 S1 := fun y hy => by + rcases w1_capS P hy with h | ⟨i, -, -, h⟩ | ⟨-, h⟩ | ⟨-, h⟩ | ⟨-, h⟩ | ⟨-, -, -, -, h⟩ <;> rw [h] + · exact fun _ _ _ _ _ _ _ e => by cases e + · exact capOf_devFr nc i + · exact capOf_devFr nc 2 + · exact capOf_devFr nc 3 + · exact fun _ _ _ _ _ _ _ e => by cases e + · exact fun _ _ _ _ _ _ _ e => by cases e + +/-- (gen 39) **`HvPt` at `w1`** (no `HighVSpace` cap, `w1_ptCapK`). -/ +theorem w1_hvPt : HvPt bst w1Pt OS1 S1 := HvPt.ofNoHv fun _ hy => (w1_ptCapK P hy).2 end w1 diff --git a/proofs/Fl4ProofsA64/P1/S1aDevFr.lean b/proofs/Fl4ProofsA64/P1/S1aDevFr.lean new file mode 100644 index 000000000..1f0907c4d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aDevFr.lean @@ -0,0 +1,220 @@ +/- +P1 (aarch64, A64-S1A gen 34): **`DevFrAl` across the S1a step arms Retype and MakePool** (Architect ruling 00:44Z, +item 2: S1A's carried invariant behind a64's `ArmDecHyps.frAl`, G1). + +* **`newCapA_devFr`**: a retype's new device `Frame` cap is of type 7 / 9 / 10 at the creation base, with frame size in bits equal + to the object size `zA`. +* **`UtEnd.devFr`** (at a creation's end over the kept slot set `OS1`: the source slot holds an `Untyped` cap, a + destination slot a new cap at `bjA aligned z j` with `aligned % 2 ^ z = 0` by MdbUtV's `UtArgs.zalA` — + `untyped.rs` `align_up(free_ref, obj_size)` — and the batch stride is `2 ^ z`, every other slot its decode-state cap) and + **`UtEnd.devFrN`** (over the grown slot set `OS1 ∪ NewSl …`, MdbGrowN's `CapInv.growN` / `UtEnd.freshN`, as + S1aPtStep's `UtEnd.ptCapHG`). +* **`CapInv.poolEnd`** (a cap class holding of `AsidPool` and `Untyped` caps survives MakePool over `OffR`: the new + pool cap, kept caps and untyped caps, a64's `makePoolLIEAt` cap clause and MdbPoolN's `PoolPost.capV`) and + **`DevFrAl.poolEnd`** (its instance). + +(gen 37, Architect ruling 01:01Z item 1, closing I1) **`DevFrP.closed`** (a64's `CapSrcClosed DevFrP`), so +**`ArmQIAt.devFr`** (the cap-source clause at `DevFrP`) and **`AsgPost.devFr`** (ASIDPool Assign); the arm tops with +`DevFrAl` at the end: **`syscall.decode_invocation.untyped_s1aRtVDf`** (S1aPtStep's `untyped_s1aRtVPt` with +`UtEnd.devFrN` in S1aRtV's end predicate) and **`syscall.decode_invocation.makePool_s1aDf`** (`makePool_s1aPt` with +`DevFrAl.poolEnd`), used by S1aStep's post. + +`UtEnd.devFr` uses `UtEnd.bjAligned` to carry full frame-size alignment. + +Named premises: none. Case facts: none new. +-/ +import Fl4ProofsA64.P1.S1aPtStep +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} {Cs Rp Nt : Set U64} + +namespace W7 +namespace R +namespace ST + +variable {OS : Set U64} + +theorem DevFrP.null : DevFrP .Null := fun _ _ _ _ _ _ _ e => by cases e + +theorem DevFrP.ut (p b i : U64) (d : Bool) : DevFrP (.Untyped p b i d) := fun _ _ _ _ _ _ _ e => by cases e + +theorem DevFrP.pool (p b : U64) : DevFrP (.AsidPool p b) := fun _ _ _ _ _ _ _ e => by cases e + +/-- (gen 37) **`DevFrP` is closed** (a64's `CapSrcClosed`: a derived frame keeps its base and device bit (J1), a +subframe is 4 KiB above its source's base, a metadata update keeps the base). -/ +theorem DevFrP.closed : CapSrcClosed DevFrP where + null := DevFrP.null + zombie := fun _ _ _ _ _ _ _ _ _ _ e => by cases e + ut := DevFrP.ut + irq := fun _ _ _ _ _ _ _ _ e => by cases e + der := by + intro d c _ hf h p sz r m e a v hd bits hb + obtain ⟨r', y1, y2, y3, y4, hc⟩ := hf.1 p sz r true m e a v hd + exact h p sz r' y1 y2 y3 y4 hc bits hb + sub := by + intro p p' sz r r' dv m e a v k h hp q sz' r'' m' e' a' v' hq bits hb + cases hq + have al := h.aligned4K rfl + have eq : bits = 12#u64 := (okinj hb).symm + rw [eq] + change p'.val % 4096 = 0 + omega + remap := by + intro d c hm h p sz r m e a v hd bits hb + subst hd + rcases hm with ⟨_, _, _, _, m0, e0, a0, v0, _, _, _, _, hc, h1⟩ | ⟨_, _, _, _, _, _, _, -, h1⟩ | + ⟨_, _, _, _, _, -, h1⟩ | ⟨_, _, _, _, _, -, h1⟩ | ⟨_, _, _, _, _, _, _, _, -, h1⟩ <;> cases h1 + exact h _ _ _ m0 e0 a0 v0 hc bits hb + +/-- (gen 37) **`ArmQIAt` keeps `DevFrAl`** (its cap-source clause at `DevFrP`). -/ +theorem ArmQIAt.devFr {ia ie : Nat} {Vc : Set U64} {s0 s : S} (h : ArmQIAt st H Cs OS Vc ia ie s0 s) + (h0 : DevFrAl st OS s0) : DevFrAl st OS s := + h.capInv DevFrP.closed h0 + +/-- (gen 37) **ASIDPool Assign keeps `DevFrAl`** (its caps are kept or VSpace root caps; S1aPtCap's +`AsgPost.ptCap`). -/ +theorem AsgPost.devFr {s s' : S} (A : AsgPost st H OS s s') (h : DevFrAl st OS s) : DevFrAl st OS s' := by + intro y hy + rcases A.cap y hy with e | ⟨-, hk⟩ + · rw [e]; exact h y hy + · intro p sz r m e a v he + rw [he] at hk + rcases hk with ⟨_, _, _, h1⟩ | ⟨_, _, _, _, _, h1⟩ | ⟨_, _, _, h1⟩ <;> cases h1 + +/-- A new device frame cap starts at the creation base and has the size of that object. -/ +theorem newCapA_devFr {n : Nat} (hn : n < 15) {base us ptr rights x3 x4 : U64} {size : capability.FrameSize} + {dev x1 x2 : Bool} (h : newCapA n base us dev = .Frame ptr size rights true x1 x2 x3 x4) : + ptr = base ∧ size.bits = ok (zA n us) := by + interval_cases n <;> simp [newCapA] at h <;> obtain ⟨rfl, rfl, -⟩ := h <;> + exact ⟨rfl, by simp [zA, capability.FrameSize.bits]⟩ + +section rt +variable {ia ie : Nat} + +/-- **`DevFrAl` at a creation's end over the kept slots** (module docstring). -/ +theorem UtEnd.devFr {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) + (hW : win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) + (C0 : DevFrAl st OS s0) : DevFrAl st OS1 s' := by + intro x hx + by_cases hxs : x = slot + · subst hxs + obtain ⟨nfi, hc⟩ := U.E.src + rw [hc]; exact DevFrP.ut _ _ _ _ + by_cases hw : ∃ j, j < win.val ∧ x = djA dest off j + · obtain ⟨j, hj, rfl⟩ := hw + rw [U.E.new j hj] + intro q sz r m e a v hc bits hb + obtain ⟨rfl, hz⟩ := newCapA_devFr U.A.hn hc + rw [okinj (hb.symm.trans hz)] + rcases hW with h0 | ⟨_, hU⟩ + · omega + exact UtEnd.bjAligned D P B hcap U hU hj + · have hk : capA st s' x = capA st s0 x := by + rw [U.E.keep x hx hxs (fun j hj e => hw ⟨j, hj, e⟩), U.k1 x hx hxs] + rw [hk] + exact C0 x (U.os x hx) + +/-- **`DevFrAl` at a creation's end over the grown slot set** (module docstring). -/ +theorem UtEnd.devFrN {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) (X : UtX H H1 lo hi us) + (hW : win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) + (C0 : DevFrAl st OS s0) : DevFrAl st (OS1 ∪ NewSl dev nt us aligned win) s' := by + have hk : (L.ksb s').val + 788736 ≤ 2 ^ 64 := by rw [U.E.fr.1.trans U.w1.1]; exact B.ly.ksw + exact CapInv.growN (P := DevFrP) (UtEnd.devFr D P B hcap U hW C0) DevFrP.null (U.freshN X hk) + +/-- (gen 37) **The untyped arm with `DevFrAl` beside `PtCap ∧ PtHG`** at the one end `(H', OS')` (S1aPtStep's +`untyped_s1aRtVPt` with S1aRtV's end predicate widened by `UtEnd.devFrN`). -/ +theorem syscall.decode_invocation.untyped_s1aRtVDf {A : Type _} {ar : machine.Arch A} {Pt : Set U64} + (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc' Ub' Pq Vc Ub : Set U64} + {Z : U64 → Nat} {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) (Y : SymL st H Cs s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) (hfm : A64FrameMasks st s0) + (hvr : VrOK H.omega Sg Scs Z OS Vc' Ub' (L.ksb s0) Pq) (hPN : PoolNamed st OS s0) + (C : S1aArmCol st H Cs OS Vc Ub s0) (K : S1aCapCol st H OS Ub s0) (hal : ∀ b ∈ Ub, Aligned b) + (hVC : VcCap st Vc OS s0) (Cp : PtCap st Pt OS s0 ∧ PtHG H Pt) (Df : DevFrAl st OS s0) (a : A) + (lbl len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s0 a lbl len slot (.Untyped p sb fi dev) blk call don fp buf extra ⦃ r s' _ => + ∃ (H' : Heap) (OS' Vn Vc'' Pt' : Set U64), ArmQIVAt st H Cs OS ia ie s0 H' OS' Vn s' ∧ TabKeep st s0 s' ∧ + Vc'' ⊆ Vc ∪ Vn ∧ VcCap st Vc'' OS' s' ∧ S1aArmCol st H' Cs OS' Vc'' Ub s' ∧ S1aCapCol st H' OS' Ub s' ∧ + PtCap st Pt' OS' s' ∧ PtHG H' Pt' ∧ DevFrAl st OS' s' ⦄ := by + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + exact WP.spec_mono (untyped.decode.s1aRtVJ hA D P B Y hcap hfm hvr hPN C K hal hVC a lbl len buf + (fun H' O s' => ∃ Pt' : Set U64, (PtCap st Pt' O s' ∧ PtHG H' Pt') ∧ DevFrAl st O s') ⟨Pt, Cp, Df⟩ + fun _ _ _ _ _ _ _ _ _ _ _ _ _ E X hw hp => + ⟨_, UtEnd.ptCapHG D P B hcap E X hw hp Cp.1 Cp.2, UtEnd.devFrN D P B hcap E X hw Df⟩) + fun _ ⟨H', OS', Vn, Vc'', ⟨h1, h2, h3, h4, h5, h6⟩, Pt', ⟨h7, h8⟩, h9⟩ => + ⟨H', OS', Vn, Vc'', Pt', h1, h2, h3, h4, h5, h6, h7, h8, h9⟩ + +end rt + +/-! ## MakePool -/ + +/-- **A cap class holding of `AsidPool` and `Untyped` caps survives MakePool over `OffR`** (module docstring). -/ +theorem CapInv.poolEnd {Q : capability.Cap → Prop} {s s' : S} {x v p sb i base : U64} + (Pp : PoolPost st H OS s s' x v p sb i base) + (hk : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st s' y = capA st s y ∨ ∃ p' b' i' d', capA st s' y = .Untyped p' b' i' d') + (hP : ∀ b, Q (.AsidPool p b)) (hU : ∀ p' b' i' d', Q (.Untyped p' b' i' d')) + (C : CapInv st Q OS s) : CapInv st Q (OffR p.val (p.val + 2 ^ sb.val) OS) s' := by + intro y hy + by_cases hyv : y = v + · subst hyv + rw [Pp.capV] + exact hP _ + · rcases hk y hy hyv with e | ⟨p', b', i', d', e⟩ + · rw [e]; exact C y hy.1 + · rw [e]; exact hU _ _ _ _ + +/-- **MakePool keeps `DevFrAl` over `OffR`.** -/ +theorem DevFrAl.poolEnd {s s' : S} {x v p sb i base : U64} (Pp : PoolPost st H OS s s' x v p sb i base) + (hk : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st s' y = capA st s y ∨ ∃ p' b' i' d', capA st s' y = .Untyped p' b' i' d') + (C : DevFrAl st OS s) : DevFrAl st (OffR p.val (p.val + 2 ^ sb.val) OS) s' := + CapInv.poolEnd Pp hk (DevFrP.pool p) DevFrP.ut C + +/-- (gen 37) **The MakePool arm with `DevFrAl` at its end** (S1aPtStep's `makePool_s1aPt` with `DevFrAl.poolEnd`). -/ +theorem syscall.decode_invocation.makePool_s1aDf {A : Type _} {ar : machine.Arch A} {ia ie : Nat} {U Ac : Set U64} + {Pt Vc Ub Vq Uq Pq : Set U64} {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s .AsidControl 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) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vq Uq (L.ksb s) Pq) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) + (Cp : PtCap st Pt OS s ∧ PtHG H Pt) (Df : DevFrAl st OS s) (a : A) + {lbl : U64} (hl : lbl = fl4_abi.label.ARMASIDControlMakePool) (len : 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 ⦃ r s' _ => + s' = s ∨ ∃ (H' : Heap) (OS' : Set U64), ArmQIEnd st H Cs OS Vq ia ie s H' OS' s' ∧ + S1aArmCol st H' Cs OS' Vc Ub s' ∧ (PtCap st Pt OS' s' ∧ PtHG H' Pt) ∧ DevFrAl st OS' s' ⦄ := + WP.spec_mono (syscall.decode_invocation.makePoolLIEAt D P B Y hvr hSC a hl len blk call don fp buf) + fun r h => by + obtain ⟨_, s', _⟩ := r + rcases h with ⟨e, -⟩ | ⟨x, hx, -, p, sb, fi, hcx, hsb, he, v, i, base, Pp, E, hk⟩ + · exact Or.inl e + · exact Or.inr ⟨_, _, E, S1aArmCol.poolEnd P B hvr C Kc hal hx hcx hsb he Pp E, + ⟨PtCap.poolEnd Pp hk Cp.1, PtHG.poolEnd B hx hcx hsb Cp.2⟩, DevFrAl.poolEnd Pp hk Df⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aHiAsg.lean b/proofs/Fl4ProofsA64/P1/S1aHiAsg.lean new file mode 100644 index 000000000..24b55526a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiAsg.lean @@ -0,0 +1,186 @@ +/- +P1 (aarch64, A64-S1A gen 41): HighVSpace entry 511 across ASIDPool Assign and MakePool. +-/ +import Fl4ProofsA64.P1.S1aHiMap +import Fl4ProofsA64.P1.S1aHvPt +import Fl4ProofsA64.P1.S1aR2Ept + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {s s' : S} + {Cs OS Vc Ub Pt Pp Tb Hr Te Ac U : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + +theorem AsgPost.hiCap511 (P : AsgPost st H OS s s') (keep : HrW st (HvRt st OS s) s s') (Hi : HiCap511 st OS s) : + HiCap511 st OS s' := by + intro y hy p m a e + obtain ⟨m', a', hcap⟩ : ∃ m' a', capA st s y = .HighVSpace p m' a' := by + rcases P.al y hy with h | h + · exact ⟨m, a, h.symm.trans e⟩ + · rw [e] at h + exact al_hv h + rw [keep p ⟨y, hy, m', a', hcap⟩] + exact Hi y hy p m' a' hcap + +set_option hygiene false in +local macro "assignError" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 (fun _ _ => rfl) + | (simp only [error.invalid_cap, error.truncated, error.illegal, bind_ok] + exact (WP.spec_ok _).2 (fun _ _ => rfl))) + +private theorem assignOffset {asid offset : U64} + (h : offset.val = (asid &&& 511#u64).val * 8) : offset.val < 4096 ∧ offset.val % 8 = 0 := by + have hmax : (asid &&& 511#u64).val ≤ 511 := by rw [UScalar.val_and]; exact Nat.and_le_right + omega + +set_option hygiene false in +local macro "assignWords" : tactic => `(tactic| ( + refine WP.spec_bind (Pₘ := fun _ => True) (by p0_auto) fun i _ => ?_ + rw [vspace.asid_table.eq, bind_ok] + refine spec_ite (fun _ => by assignError) (fun notZero => ?_) + have p0 : L.mem s (wa (L.ksb s) (AtOff i)) ≠ 0#u64 := by simpa using notZero + have facts := AtOff.v i + have inPool := W.ty.1.tbl _ facts.1 facts.2.1 facts.2.2 p0 + refine spec_ite (fun _ => by assignError) (fun _ => ?_) + refine WP.spec_bind (Pₘ := fun _ => True) (by first + | exact P0.vspace.decode_loop1.p0 st s _ _ _ hS + | exact P0.vspace.decode_loop2.p0 st s _ _ _ hS + | exact P0.vspace.decode_loop3.p0 st s _ _ _ hS) fun idx _ => ?_ + refine spec_ite (fun _ => by assignError) (fun _ => ?_) + try simp only [lift, bind_ok] + refine WP.spec_bind (restart) fun q hq => ?_ + refine WP.spec_bind (Pₘ := HrW st Hr s) ?_ fun q' keep => ?_ + · repeat' (first | exact hq _ | split) + try simp only [lift, bind_ok] + step as ⟨offset, hOffset⟩ + try simp only [lift, bind_ok] + refine WP.spec_bind (LawfulStore.write_spec q' _ _) fun q'' e => ?_ + subst e + obtain ⟨hVal, hEight⟩ := assignOffset hOffset + have hal := I.del.vr.al _ (Or.inl (ptw_mono W.pools ⟨_, inPool, _, hVal, hEight, rfl⟩)) + refine (WP.spec_ok _).2 fun R hR => Eq.trans ?_ (keep R hR) + exact W.keepWrite I (writesIn_wr hal) (fun R hR e => W.high.pp _ inPool _ hVal hEight R hR e.symm) R hR)) + +set_option maxHeartbeats 4000000 in +theorem vspace.decode.assignHr {pptr base : U64} + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (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 (.AsidPool pptr base) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (a : A) (len buf : U64) (call : Bool) : + vspace.decode st ar s a fl4_abi.label.ARMASIDPoolAssign len slot (.AsidPool pptr base) call buf extra + ⦃ r => HrW st Hr s r.2.1 ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + try dsimp only + refine spec_ite (fun h => by simp at h) (fun _ => ?_) + refine WP.spec_bind (vspace.extra.memA extra 0#usize) fun o ho => ?_ + rcases o with _ | x + · assignError + obtain ⟨hxm, hx0⟩ := ho x rfl + have hx : x ∈ OS := P.ext x hxm hx0 + have restart := W.restartCap (slot := x) I D hx + try dsimp only + rw [capA_eq, bind_ok] + cases capA st s x <;> try assignError + case Pml4 ptr m ad => + try dsimp only + refine spec_ite (fun _ => by assignError) (fun _ => ?_) + assignWords + case HighVSpace ptr m ad => + try dsimp only + refine spec_ite (fun _ => by assignError) (fun _ => ?_) + assignWords + case Ept ptr lv m ad va => + try dsimp only + split + · try dsimp only + refine spec_ite (fun _ => by assignError) (fun _ => ?_) + assignWords + · assignError + +/-- The cap and memory posts for Assign, at the same returned state. -/ +theorem syscall.decode_invocation.assignHi {pptr base : U64} + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (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 (.AsidPool pptr base) 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) (hPO : PoolOff st H Cs OS s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.ARMASIDPoolAssign) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.AsidPool pptr base) blk call don fp buf extra ⦃ r s' _ => + (SysL st H Cs OS ia ie s' ∧ SymL st H Cs s') ∧ AsgPost st H OS s s' ∧ + (HiCap511 st OS s → HiCap511 st OS s') ⦄ := by + subst lbl + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + exact WP.spec_mono (WP.spec_and (vspace.decode.assignLW D P B Y hPO a rfl len call buf) + (vspace.decode.assignHr W I D P a len buf call)) fun _ h => + ⟨h.1.1, h.1.2.2, h.1.2.2.hiCap511 (fun R hR => h.2 R (W.roots hR))⟩ + +/-- A surviving HighVSpace cap is outside the MakePool clear and the ASID-table write. -/ +theorem PoolPost.hiCap511 {x v p sb fi i base : U64} + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (hx : x ∈ OS) (hcx : capA st s x = .Untyped p sb fi false) + (he : cdt.ensure_no_children st s x = ok (core.result.Result.Ok ())) (hG : PtHG H Pt) + (post : PoolPost st H OS s s' x v p sb i base) + (hk : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st s' y = capA st s y ∨ ∃ p' b' i' d', capA st s' y = .Untyped p' b' i' d') + (Hi : HiCap511 st OS s) : HiCap511 st (OffR p.val (p.val + 2 ^ sb.val) OS) s' := by + have caps := CapInv.poolEnd post hk + (Q := HiCap511P st (HvRt st OS s) s) + (fun _ _ _ _ e => by cases e) (fun _ _ _ _ _ _ _ e => by cases e) Hi.capP + exact HiCap511.ofRt caps fun R hR => by + have hRh := W.roots hR + have hpt := W.tables (W.high.sub hRh) + obtain ⟨y, hy, m, a, hcap⟩ := hR + have hOff := PtHG.keyOffNC P B hx hcx he hG hy (hcap ▸ RngKeyA.hv R m a) (by rw [hcap, ptrA_hv]) hpt + obtain ⟨-, q, z, hq, -, hfit⟩ := hG R hpt + have hFit := le_trans hfit (P.heap.fits q _ hq) + have h88 : (4088#u64 : U64).val = 4088 := rfl + have hval : (wa R 4088#u64).val = R.val + 4088 := by rw [wadd_val (by rw [h88]; omega), h88] + rcases post.vs Vc Ub Pt I.del.vr _ (W.word hRh) with h | h | h + · rw [h] + · exfalso + rw [hval] at h + rcases hOff with lo | hi <;> omega + · exfalso + apply W.high.asw R hRh + rw [h] + exact asW_at (L.ksb s) i + +/-- MakePool's ordinary S1A post with entry 511 carried on the same slots. -/ +theorem syscall.decode_invocation.makePool_s1aHi + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) (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 .AsidControl 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) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + {User : Set U64} (C : S1aArmCol st H Cs OS Vc User s) (Kc : S1aCapCol st H OS User s) + (hal : ∀ b ∈ User, Aligned b) (Cp : PtCap st Pt OS s ∧ PtHG H Pt) + (Df : DevFrAl st OS s) (Hv : HvPt st Pt OS s) (Hi : HiCap511 st OS s) + (Ep : EptPlaced st H OS Pt s) (objects : PtObjects st H OS s) + (highObjects : HvObjects st H OS s) (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.ARMASIDControlMakePool) (len : 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 ⦃ r s' _ => + s' = s ∨ ∃ (H' : Heap) (OS' : Set U64), ArmQIEnd st H Cs OS Vc ia ie s H' OS' s' ∧ + S1aArmCol st H' Cs OS' Vc User s' ∧ (PtCap st Pt OS' s' ∧ PtHG H' Pt) ∧ HvPt st Pt OS' s' ∧ + DevFrAl st OS' s' ∧ HiCap511 st OS' s' ∧ EptPlaced st H' OS' Pt s' ∧ PtObjects st H' OS' s' ∧ HvObjects st H' OS' s' ⦄ := + WP.spec_mono (syscall.decode_invocation.makePoolLIEAt D P B Y I.del.vr hSC a hl len blk call don fp buf) + fun _ h => by + rcases h with ⟨e, -⟩ | ⟨x, hx, -, p, sb, fi, hcx, hsb, he, v, i, base, post, E, hk⟩ + · exact Or.inl e + · exact Or.inr ⟨_, _, E, S1aArmCol.poolEnd P B I.del.vr C Kc hal hx hcx hsb he post E, + ⟨PtCap.poolEnd post hk Cp.1, PtHG.poolEnd B hx hcx hsb Cp.2⟩, HvPt.poolEnd post hk Hv, + DevFrAl.poolEnd post hk Df, post.hiCap511 W I P B hx hcx he Cp.2 hk Hi, + EptPlaced.poolEnd B hx hcx hsb post hk Ep, PtObjects.poolEnd P B hx hcx he post hk objects, + HvObjects.poolEnd B hx hcx hsb post hk highObjects⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiCap.lean b/proofs/Fl4ProofsA64/P1/S1aHiCap.lean new file mode 100644 index 000000000..78ba9193a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiCap.lean @@ -0,0 +1,138 @@ +/- +P1 (aarch64, A64-S1A gen 38, Architect ruling for gen 38 item 2): **R3's `HighVSpace` cap-source class** — `HiCap511` +through `ArmQIAt`'s cap-source clause (a64's `CapSrcClosed`, MdbPtCapA), and the frame lemmas that reduce `HiCap511` +at an arm's end to its roots' `+ 4088` words. + +* **`RngKeyA.hv`**, **`ptrA_hv`**, **`al_hv`** (a `HighVSpace` cap's `AlikeA` partner is a `HighVSpace` cap with the + same root; MdbPtCapA's `al_pt` shape). +* **`HvRt st OS s0`**: the roots of the `HighVSpace` caps of `OS` at `s0`. +* (gen 39) **`HvRootP.closed`**: any class reading only a `HighVSpace` cap's root is a `CapSrcClosed` instance. +* **`HiCap511P Rt s0 c`**: if `c` is a `HighVSpace` cap, its root lies in `Rt` and has a table descriptor at entry 511 + at `s0`. **`HiCap511P.closed`**: a `CapSrcClosed` instance with the seven existing fields (`Null`, `Zombie`, + `Untyped`, `IrqHandler` are no `HighVSpace` caps; `der` keeps the root by `al_hv`; `sub` makes a frame; `remap` + keeps the root by `CapMeta`'s `HighVSpace` case). No field added to `CapSrcClosed`, no `CapMeta` case added. +* **`HiCap511.capP`**: `HiCap511` at `s0` is `CapInv (HiCap511P (HvRt OS s0) s0)` at `s0`; **`ArmQIAt.hiCapP`**: an + `ArmQIAt` step carries it to the end (`ArmQIAt.capInv`). +* **`HiCap511.ofRt`** (the frame): the class at the end and every root of `Rt` keeping its `+ 4088` word's low two + bits give `HiCap511` at the end. +* **`HiCap511.ofArmVsK`** (the non-VSpace non-deleting arms' frame lemma): an `ArmQIAt` step whose memory is an + `ArmVsK` step keeps `HiCap511`, at any placement `(Ub, Pt')` of the decode's state whose tables contain the roots + (`HvRt OS s0 ⊆ Pt'`). + +Gen 39: Architect ruling L1's `HvPt` (S1aHvPt) gives `HvRt OS s0 ⊆ Pt` (`HvPt.rt`) at S1A's own placement. + +Not here (gen 39 plan, handoff gen 38): the root placement `VrOK … (Pt ∪ HvRt OS s0)` at S1A's state (finding L1: +S1A's `Pt` holds the page tables, `NewPt` is type 11 only, so an unassigned `HighVSpace` root's `+ 4088` word is no +placed `VsR` word and `ArmVsK` says nothing about it), the per-arm `ArmVsK` / deletion / VSpace exports, the +Retype `KTab` init, and `HiCap511` in `S1aStep`'s post. + +Named premises: none. Case facts: none new. +-/ +import Fl4ProofsA64.P1.S1aDevFr +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} {Cs : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +variable {OS : Set U64} + +theorem RngKeyA.hv (p : U64) (m : Bool) (a : U64) : RngKeyA (.HighVSpace p m a) := by + have h := physA_eq (.HighVSpace p m a) + simp only [objects.cap_is_physical] at h + exact ⟨(okinj h).symm, rfl, rfl⟩ + +theorem ptrA_hv (p : U64) (m : Bool) (a : U64) : ptrA (.HighVSpace p m a) = p := by + have h := ptrA_eq (.HighVSpace p m a) + simp only [capability.Cap.ptr] at h + exact (okinj h).symm + +/-- **A `HighVSpace` cap's `AlikeA` partner is a `HighVSpace` cap with the same root.** -/ +theorem al_hv {p : U64} {m : Bool} {a : U64} {c : capability.Cap} (ha : AlikeA (.HighVSpace p m a) c) : + ∃ m' a', c = .HighVSpace p m' a' := by + obtain ⟨hcl, hkd⟩ := ha.2 (ha.1.1 (RngKeyA.hv p m a)) + cases c + all_goals (try (exfalso; simp [kindA] at hkd; done)) + rename_i p' m' a' + have hp := ptrA_of_cls hcl + rw [ptrA_hv, ptrA_hv] at hp + exact ⟨m', a', by rw [hp]⟩ + +variable (st) in +/-- **The roots of the `HighVSpace` caps of `OS` at `s0`.** -/ +def HvRt (OS : Set U64) (s0 : S) : Set U64 := {p | ∃ y ∈ OS, ∃ m a, capA st s0 y = .HighVSpace p m a} + +variable (st) in +/-- **R3's `HighVSpace` cap class** (module docstring): a `HighVSpace` cap's root lies in `Rt` and has a table +descriptor at entry 511 at `s0`. -/ +def HiCap511P (Rt : Set U64) (s0 : S) (c : capability.Cap) : Prop := + ∀ p m a, c = .HighVSpace p m a → p ∈ Rt ∧ (L.mem s0 (wa p 4088#u64) &&& 3#u64) = 3#u64 + +/-- (gen 39) **A class reading only a `HighVSpace` cap's root is closed** (a64's `CapSrcClosed`, the seven existing +fields; `HiCap511P.closed` and S1aHvPt's `HvPt` are its instances). -/ +theorem HvRootP.closed (R : U64 → Prop) : + CapSrcClosed (fun c : capability.Cap => ∀ p m a, c = .HighVSpace p m a → R p) where + null := fun _ _ _ e => by cases e + zombie := fun _ _ _ _ _ _ e => by cases e + ut := fun _ _ _ _ _ _ _ e => by cases e + irq := fun _ _ _ _ e => by cases e + der := by + intro d c ha _ h p m a hd + subst hd + rcases ha with ha | e + · obtain ⟨m', a', hc⟩ := al_hv ha + exact h p m' a' hc + · cases e + sub := fun _ _ _ _ _ _ e => by cases e + remap := by + intro d c hm h p m a hd + subst hd + rcases hm with ⟨_, _, _, _, _, _, _, _, _, _, _, _, -, h1⟩ | ⟨_, _, _, _, _, _, _, -, h1⟩ | + ⟨_, _, _, _, _, -, h1⟩ | ⟨p0, m0, a0, _, _, hc, h1⟩ | ⟨_, _, _, _, _, _, _, _, -, h1⟩ <;> cases h1 + exact h _ m0 a0 hc + +/-- **`HiCap511P` is closed** (a64's `CapSrcClosed`, the seven existing fields). -/ +theorem HiCap511P.closed (Rt : Set U64) (s0 : S) : CapSrcClosed (HiCap511P st Rt s0) := + HvRootP.closed fun p => p ∈ Rt ∧ (L.mem s0 (wa p 4088#u64) &&& 3#u64) = 3#u64 + +/-- **`HiCap511` at `s0` is the class at the roots of `s0`.** -/ +theorem HiCap511.capP {s0 : S} (h : HiCap511 st OS s0) : CapInv st (HiCap511P st (HvRt st OS s0) s0) OS s0 := + fun y hy p m a e => ⟨⟨y, hy, m, a, e⟩, h y hy p m a e⟩ + +/-- **An `ArmQIAt` step carries the class** (its cap-source clause). -/ +theorem ArmQIAt.hiCapP {ia ie : Nat} {Vc : Set U64} {s0 s : S} (h : ArmQIAt st H Cs OS Vc ia ie s0 s) + (h0 : HiCap511 st OS s0) : CapInv st (HiCap511P st (HvRt st OS s0) s0) OS s := + h.capInv (HiCap511P.closed _ s0) h0.capP + +/-- **The frame**: the class at the end, and every root of `Rt` keeping the low two bits of its `+ 4088` word. -/ +theorem HiCap511.ofRt {Rt : Set U64} {s0 s : S} (h : CapInv st (HiCap511P st Rt s0) OS s) + (hk : ∀ p ∈ Rt, (L.mem s (wa p 4088#u64) &&& 3#u64) = (L.mem s0 (wa p 4088#u64) &&& 3#u64)) : + HiCap511 st OS s := fun y hy p m a e => by + obtain ⟨hp, h3⟩ := h y hy p m a e + rw [hk p hp]; exact h3 + +/-- **The non-VSpace non-deleting arms' frame lemma** (module docstring): an `ArmQIAt` step whose memory is an +`ArmVsK` step keeps `HiCap511`, at a placement of the decode's state whose tables contain the roots. -/ +theorem HiCap511.ofArmVsK {ia ie : Nat} {Vc Ub Pt' : Set U64} {s0 s : S} (h : ArmQIAt st H Cs OS Vc ia ie s0 s) + (hK : ArmVsK st H OS Vc s0 s) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s0) Pt') + (hf : FrUb st Ub OS s0) (hR : HvRt st OS s0 ⊆ Pt') (h0 : HiCap511 st OS s0) : HiCap511 st OS s := + HiCap511.ofRt (h.hiCapP h0) fun p hp => by + have hb : VsR (L.ksb s0) Pt' (wa p 4088#u64) := + Or.inl ⟨p, hR hp, 4088#u64, by simp, by simp, rfl⟩ + rw [hK.vsKeep hvr hf _ hb] + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aHiDel.lean b/proofs/Fl4ProofsA64/P1/S1aHiDel.lean new file mode 100644 index 000000000..45613b7e0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiDel.lean @@ -0,0 +1,151 @@ +/- +P1 (aarch64, A64-S1A gen 41): preserve the entry-511 descriptors of live HighVSpace roots through deletion. + +Case fact: `HiDelTy` ties every initial `HvRt` root, including unassigned roots, to the `Hr` of the same +`HrOK` / `S2OK` typing witness. No new named premise. The existing `finKT_s2`, `tyk_s2` and `finKZ_s2` +give the deletion class for `VsTy ∧ S2Ty`. At the end, the cap-source carry and `S2Ty.hi` give `HiCap511`. +-/ +import Fl4ProofsA64.P1.S1aHiCap +import Fl4ProofsA64.P1.MdbCnDelArm +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {Cs OS Vc Ub Pt : Set U64} + {Pp Tb Hr Te : Set U64} {Lv Re bits : U64 → Nat} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- One deletion typing witness covering every live HighVSpace root. -/ +structure HiDelTy (st : machine.Store S) [L : LawfulStore st] (Pt OS Pp Tb Hr Te : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (s : S) : Prop where + pools : Pp ⊆ Pt + tables : Tb ⊆ Pt + granules : Gran Te bits ⊆ Pt + high : HrOK (L.ksb s) Pp Tb Lv Hr + stage2 : S2OK Te bits Hr + roots : HvRt st OS s ⊆ Hr + ty : VsTy st (L.ksb s) Pp Tb Lv s ∧ S2Ty st n Pp Hr Te Re bits s + +/-- Reuse the deletion inputs at the concrete VSpace finaliser class and its typing. -/ +theorem DelIn.forHiDel {s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hPl : ArchPlat ar) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) : + DelIn st ar H Cs OS Vc Ub Pt S2Q (fun q => VsTy st (L.ksb s) Pp Tb Lv q ∧ + S2Ty st hPl.ipa Pp Hr Te Re bits q) s where + del := I.del + fin := finKT_s2 I.del.arch hPl I.del.vr W.pools W.tables W.granules W.high W.stage2 + tyk := tyk_s2 W.pools W.tables W.granules W.high W.stage2 + kl := fun c hc => I.kl c (I.s2 c hc) + kv := fun c hc => I.kv c (I.s2 c hc) + s2 := fun _ h => h + ts := I.ts + vty := I.vty + ty := W.ty + irq := I.irq + vcc := I.vcc + fu := I.fu + +/-- The zero-write portion of the same concrete finaliser instance. -/ +theorem HiDelTy.finKZ {s : S} {hPl : ArchPlat ar} + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) : + FinKZ st ar (L.ksb s) Pt (fun q => VsTy st (L.ksb s) Pp Tb Lv q ∧ + S2Ty st hPl.ipa Pp Hr Te Re bits q) S2Q := + finKZ_s2 I.del.arch hPl I.del.vr W.pools W.tables W.granules W.high W.stage2 + +/-- An end-state cap names an initial root, whose descriptor is covered by the retained typing. -/ +theorem HiCap511.ofDelTy {n : U64} {s s' : S} (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (h : ArmQIAt st H Cs OS Vc ia ie s s') (ht : S2Ty st n Pp Hr Te Re bits s') + (Hi : HiCap511 st OS s) : HiCap511 st OS s' := + fun y hy p m a e => ht.hi p (W.roots ((h.hiCapP Hi y hy p m a e).1)) + +variable {Ac : Set U64} + +/-- The existing single-delete post retains the concrete typing through its `DelR` component. -/ +theorem cdt.delete.s1aTy {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) {a : A} {x : U64} + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : + cdt.delete st ar s a x true ⦃ r => Ty r.2.1 ⦄ := + WP.spec_mono (cdt.delete.delR I R hx) fun _ d => d.ty + +/-- The existing revoke loop retains the concrete typing through its `DelQ` component. -/ +theorem cdt.revoke.s1aTy {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) + {a : A} {x : U64} (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) + (Q : PoolR st OS s0 s) (hx : x ∈ OS) : + cdt.revoke st ar s a x ⦃ r => Ty r.2.1 ⦄ := by + have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 + rw [R.jv.ksb] at hD + exact WP.spec_mono (cdt.revoke.poolR I.del I.fin I.tyk I.kl hKZ hPI + (fun y hy hib => show y ∈ OSN OS (L.ksb s0) from ⟨hy, hib⟩) + ⟨R.jv, R.ty, R.sys, R.sym, hD, rfl, rfl, R.irq⟩ Q hx) fun _ d => d.1.1.ty + +/-- An insert changes only slot words, so it preserves the deletion typing. -/ +theorem cdt.insert_with_cap.s1aTy {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hy : Ty s) (hm : MdbS st OS s) {src dest : U64} {nc sc : capability.Cap} + (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) (hdc : obj.sext48 dest = ok dest) + (hsc : capA st s src = sc) (hsc0 : sc ≠ .Null) (hw : CapRt.EncWf nc) : + cdt.insert_with_cap st s nc sc src dest ⦃ s' => Ty s' ⦄ := + WP.spec_mono (cdt.insert_with_cap.lrF I.del.os.inOS (LR.self s) hsrc hd hsd hdc hsc hsc0 hw + (hm.lnk I.del.os hsrc).2) fun s' h => I.tyk s s' hy (vsk_cw0 I.del.vr h.1) + +variable {U : Set U64} + +set_option maxHeartbeats 2000000 in +/-- CNode Delete and Revoke preserve the deletion typing, including error and preemption exits. -/ +theorem cnode.decode.rvDelTy {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) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) + (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (a : A) {lbl len buf : U64} + (hl : lbl = fl4_abi.label.CNodeRevoke ∨ lbl = fl4_abi.label.CNodeDelete) : + cnode.decode st ar s a lbl len cap buf extra ⦃ r => Ty r.2.1 ⦄ := by + have root := RootOK.of_slot P.ty P.src hcap + have held : Held st OS s cap := ⟨slot, P.src, okinj ((capA_eq s slot).symm.trans hcap)⟩ + have restart := tcb.restart_caller.delRP I D P B Y (Stalled.refl0 D) (DF.refl s) (DS.refl s) (VsKeep.refl s) + have restart_eq : tcb.restart_caller st s = sched.set_thread_state st s (L.curW s) sched.TS_RESTART := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok] + rw [restart_eq] at restart + have hnc : ¬ (lbl ≥ fl4_abi.label.CNodeCopy) := hl.elim (fun h => h ▸ lbl_rv_c) (fun h => h ▸ lbl_c1) + unfold cnode.decode + simp only [error.illegal, error.truncated, bind_ok] + iterate 3 + split + · exact (WP.spec_ok _).2 I.ty + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun idx _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun depth _ => ?_ + refine WP.spec_bind (lookup_tgt_irq P.heap P.ty B.cn cap root held idx depth) fun result found => ?_ + rcases result with v | e + swap + · 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] + exact (WP.spec_ok _).2 I.ty + obtain ⟨hv, cov, -, -⟩ := found v rfl + have off := (SlotCov.offs P.heap B cov).1 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + rcases hl with rfl | rfl <;> + repeat (first + | exact WP.spec_bind restart fun _ d => cdt.revoke.s1aTy I hKZ hPI d.1.2 d.2.1 hv + | exact WP.spec_bind restart fun _ d => cdt.delete.s1aTy I d.1.2 ⟨hv, off⟩ + | (refine spec_ite (fun hc => ?_) fun hc => ?_ <;> + try (exfalso; revert hc; decide))) + all_goals contradiction + +/-- The syscall dispatch to CNode Delete and Revoke retains the deletion typing. -/ +theorem syscall.decode_invocation.cnodeRvDel_s1aTy {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) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hf : capFam cap = .cnode) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.CNodeRevoke ∨ lbl = fl4_abi.label.CNodeDelete) (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 ⦃ r s' _ => Ty s' ⦄ := + syscall.decode_invocation.cnodeG (P := Ty) I.ty a len slot cap blk call don fp buf extra hf + (WP.spec_mono (cnode.decode.rvDelTy I hKZ hPI D P B Y hcap a hl) fun r h => by + obtain ⟨_, _, _⟩ := r + exact h) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiDelDec.lean b/proofs/Fl4ProofsA64/P1/S1aHiDelDec.lean new file mode 100644 index 000000000..afb70c38b --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiDelDec.lean @@ -0,0 +1,185 @@ +/- +P1 (aarch64, A64-S1A gen 41): the S1A sibling decode posts for deletion and SetSchedParams. +They retain the concrete deletion typing alongside the existing cap-source post, so live +HighVSpace caps are covered by the same roots at entry and exit. +Case fact: `HiDelTy`. No new named premises. +-/ +import Fl4ProofsA64.P1.S1aHiDelTcb +import Fl4ProofsA64.P1.S1aHiDelIrq +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {Cs OS Vc Ub Pt U Ac : Set U64} + {ia ie : Nat} {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +local macro "delTyLabel" : tactic => `(tactic| exact lbl_ne_of_val (by simp [ + fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, + fl4_abi.label.TCBConfigure, fl4_abi.label.TCBSetPriority, fl4_abi.label.TCBSetMCPriority, + fl4_abi.label.TCBSetSchedParams, fl4_abi.label.TCBSetTimeoutEndpoint, fl4_abi.label.TCBSetIPCBuffer, + fl4_abi.label.TCBSetSpace, fl4_abi.label.TCBSuspend, fl4_abi.label.TCBResume, fl4_abi.label.TCBBindNotification, + fl4_abi.label.TCBUnbindNotification, fl4_abi.label.TCBSetTLSBase, fl4_abi.label.TCBSetPACKeys, + fl4_abi.label.TCBSetHighVSpace, fl4_abi.label.TCBSetBreakpoint, fl4_abi.label.TCBGetBreakpoint, + fl4_abi.label.TCBUnsetBreakpoint, fl4_abi.label.TCBConfigureSingleStepping, fl4_abi.label.TCBSetEPTRoot, + fl4_abi.label.TCBSetFlags, fl4_abi.label.TCBSetTimer, fl4_abi.label.TCBReadFPU, core.num.U64.MAX, U64.rMax])) + +set_option hygiene false in +local macro "takeDelTyArm" n:num : tactic => `(tactic| ( + iterate $n:num + refine spec_ite (fun h => absurd (hl.symm.trans h) ?_) fun _ => ?_ + · delTyLabel + refine spec_ite (fun _ => ?_) fun h => absurd hl h)) + +set_option maxHeartbeats 3000000 in +private theorem tcb.decode.install_s1aTy (hA : P0.ArchTotal ar) {s : S} {a : A} {lbl t len buf : U64} + {call : Bool} {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) + (hl : lbl = fl4_abi.label.TCBSetHighVSpace ∨ lbl = fl4_abi.label.TCBSetSpace ∨ + lbl = fl4_abi.label.TCBSetIPCBuffer ∨ lbl = fl4_abi.label.TCBConfigure ∨ + lbl = fl4_abi.label.TCBSetTimeoutEndpoint) : + tcb.decode st ar s a lbl t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ⦄ := by + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.delS hA D I a t) ?_ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ + try simp only [uncurry_apply_pair] + rcases hl with hl | hl | hl | hl | hl + · takeDelTyArm 1 + unfold tcb.decode_arch + have hne : fl4_abi.label.TCBSetHighVSpace ≠ fl4_abi.label.TCBSetPACKeys := by delTyLabel + rw [if_neg (fun h => hne (hl.symm.trans h))] + exact tcb.decode_set_high_vspace.s1aTy I hKZ hPI D P B Y h1 d1 ds1 vk1 + · takeDelTyArm 13 + exact tcb.decode_set_space.s1aTy I hKZ hPI D P B Y h1 d1 ds1 vk1 + · takeDelTyArm 12 + exact tcb.decode_set_ipc_buffer.s1aTy I D P B Y h1 d1 ds1 vk1 + · takeDelTyArm 8 + exact tcb.decode_configure.s1aTy I hKZ hPI D P B Y h1 d1 ds1 vk1 + · takeDelTyArm 14 + exact tcb.decode_set_timeout_endpoint.s1aTy I hKZ hPI D P B Y h1 d1 ds1 vk1 + +set_option maxHeartbeats 2000000 in +/-- The S1A decode sibling retains the typing on all ten deletion arms. -/ +theorem syscall.decode_invocation.del_s1aTy (hA : P0.ArchTotal ar) {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) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (a : A) {lbl : U64} (hc : DecArmDelQ cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (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 ⦃ r s' _ => Ty s' ⦄ := by + have thread {t : U64} (e : cap = .Thread t) + (h : lbl = fl4_abi.label.TCBSetHighVSpace ∨ lbl = fl4_abi.label.TCBSetSpace ∨ + lbl = fl4_abi.label.TCBSetIPCBuffer ∨ lbl = fl4_abi.label.TCBConfigure ∨ + lbl = fl4_abi.label.TCBSetTimeoutEndpoint) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => Ty s' ⦄ := by + subst cap + exact syscall.decode_invocation.tcbG (Φ := Ty) I.ty a len blk call don fp buf fun _ _ e => + tcb.decode.install_s1aTy hA I hKZ hPI D P B Y (by simpa only [e] using h) + rcases hc with ⟨t, e, hl⟩ | ⟨t, e, hl⟩ | ⟨t, e, hl⟩ | ⟨t, e, hl⟩ | ⟨t, rfl, rfl⟩ | + ⟨t, e, hl⟩ | ⟨irq, rfl, hl⟩ | ⟨irq, rfl, hl⟩ | ⟨hf, hl⟩ + · exact thread e (Or.inl hl) + · exact thread e (Or.inr (Or.inl hl)) + · exact thread e (Or.inr (Or.inr (Or.inl hl))) + · exact thread e (Or.inr (Or.inr (Or.inr (Or.inl hl)))) + · exact syscall.decode_invocation.tcbG (Φ := Ty) I.ty a len blk call don fp buf fun _ _ e => by + subst e + exact tcb.decode.setEpt_s1aTy hA I D P B Y fun x hx h0 => (SlotCov.offs P.heap B (hSC x hx h0)).2.1 + · exact thread e (Or.inr (Or.inr (Or.inr (Or.inr hl)))) + · unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono (interrupt.decode_irq_handler.clear_s1aTy I D P B Y a hl (hIq irq rfl (Or.inl hl))) ?_ + rintro ⟨_, _, _⟩ h + exact h + · unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono (interrupt.decode_irq_handler.set_s1aTy I D P B Y a hl (hIq irq rfl (Or.inr hl)) hSC) ?_ + rintro ⟨_, _, _⟩ h + exact h + · exact syscall.decode_invocation.cnodeRvDel_s1aTy I hKZ hPI D P B Y hcap hf a hl len blk call don fp buf + +set_option maxHeartbeats 2000000 in +/-- SetSchedParams retains the concrete typing across deletion and its scheduler tail. -/ +theorem syscall.decode_invocation.ssp_s1aTy (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + {n : U64} (Hy : ArmDecHyps st H Pt n s (.Thread t)) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetSchedParams) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => Ty s' ⦄ := by + subst lbl + refine syscall.decode_invocation.tcbG (Φ := Ty) I.ty a len blk call don fp buf fun _ _ eq => ?_ + subst eq + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.delS hA D I a t) ?_ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ + try simp only [uncurry_apply_pair] + iterate 11 + refine spec_ite (fun hc => ?_) fun _ => ?_ + · exfalso + first | exact hc | (apply hc; contradiction) | exact absurd hc (by delTyLabel) + refine spec_ite (fun _ => ?_) (fun hc => absurd (by first | rfl | trivial) hc) + exact WP.spec_mono (tcb.decode_set_sched_params.armQITyAt I hKZ hPI D P B Y hks hcap Hy h1 d1 ds1 vk1) + fun _ d => d.2.2 + +set_option maxHeartbeats 2000000 in +/-- Typed deletion preserves every live HighVSpace descriptor. -/ +theorem syscall.decode_invocation.delOnly_hi {Pp Tb Hr Te : Set U64} {Lv Re bits : U64 → Nat} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) + (a : A) {lbl : U64} + (hd : DecArmDelQ cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (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 ⦃ r s' _ => + HiCap511 st OS s → HiCap511 st OS s' ⦄ := by + have J := I.forHiDel hPl W + have z := W.finKZ (hPl := hPl) I + refine WP.spec_mono (WP.spec_and + (syscall.decode_invocation.del_armQIAt hA J z hPI D P B Y hcap a hd hIq hSC len blk call don fp buf) + (syscall.decode_invocation.del_s1aTy hA J z hPI D P B Y hcap a hd hIq hSC len blk call don fp buf)) ?_ + rintro ⟨_, s', _⟩ ⟨arm, hty⟩ hi + exact HiCap511.ofDelTy W arm.1 hty.2 hi + +set_option maxHeartbeats 2000000 in +/-- The deletion family and SetSchedParams preserve every live HighVSpace descriptor. -/ +theorem syscall.decode_invocation.armDel_hi {Pp Tb Hr Te : Set U64} {Lv Re bits : U64 → Nat} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (Hy : ArmDecHyps st H Pt hPl.ipa s cap) (a : A) {lbl : U64} + (hc : DecArmDelQ cap lbl ∨ (∃ t, cap = .Thread t ∧ lbl = fl4_abi.label.TCBSetSchedParams)) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (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 ⦃ r s' _ => + HiCap511 st OS s → HiCap511 st OS s' ⦄ := by + have J := I.forHiDel hPl W + have z := W.finKZ (hPl := hPl) I + rcases hc with hd | ⟨t, rfl, hl⟩ + · exact syscall.decode_invocation.delOnly_hi hA hPl I W hPI D P B Y hcap a hd hIq hSC len blk call don fp buf + · refine WP.spec_mono (WP.spec_and + (syscall.decode_invocation.ssp_armQIAt hA J z hPI D P B Y hks hcap Hy a hl len blk call don fp buf) + (syscall.decode_invocation.ssp_s1aTy hA J z hPI D P B Y hks hcap Hy a hl len blk call don fp buf)) ?_ + rintro ⟨_, s', _⟩ ⟨arm, hty⟩ hi + exact HiCap511.ofDelTy W arm.1 hty.2 hi + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiDelIrq.lean b/proofs/Fl4ProofsA64/P1/S1aHiDelIrq.lean new file mode 100644 index 000000000..a929cf683 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiDelIrq.lean @@ -0,0 +1,127 @@ +/- +P1 (aarch64, A64-S1A gen 41): IRQ handler deletion preserves the typing used in `S1aHiDel`. +The IRQ node's `IrqN` cap fact drives `finXQG`; emptying and inserting frame the VSpace words. +No new named premises or case facts. +-/ +import Fl4ProofsA64.P1.S1aHiDel +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {Cs OS Vc Ub Pt U Ac : Set U64} + {ia ie : Nat} {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +set_option maxHeartbeats 2000000 in +/-- A single IRQ-node deletion keeps the typing through finalisation and the slot clear. -/ +theorem cdt.delete_one.s1aTy {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (a : A) {i : U64} (hi : i.val < 5376) : + cdt.delete_one st ar s a (irqSlotA (L.ksb s0) i) ⦃ r => Ty r.1 ⦄ := by + let x := irqSlotA (L.ksb s0) i + have hx : x ∈ OS := I.del.irq.1 i hi + unfold cdt.delete_one + rw [← show x = irqSlotA (L.ksb s0) i from rfl, capA_eq, bind_ok] + have hc := R.irq i hi (capA st s x) (capA_eq s x) + refine WP.spec_bind (P0.capability.Cap.is_null.p0 _) fun _ _ => ?_ + split + · exact (WP.spec_ok _).2 R.ty + refine WP.spec_bind (P0.cdt.is_final_capability_with_cap.p0 st s x _ L.total) fun fin _ => ?_ + have hn : ∀ j, capA st s x ≠ .IrqHandler j := by + rcases hc with ⟨n, b0, b1, b2, h⟩ | h <;> rw [h] <;> intro j e <;> cases e + rw [← fc_eq_fco ar s a fin hn] + refine WP.spec_bind (WP.spec_and + (finXQG I.del.arch I.del.os I.del.sca I.del.vc I.del.vr I.fin I.tyk R.jv I.del.irq R.irq R.ty R.jv.ksb + hx (capA_eq s x) (zq_irqNt hc) a fin) + (finL I.del.arch I.del.os I.del.sca I.del.vc R.jv hx (capA_eq s x) (zl_irqNt hc) a fin)) ?_ + rintro ⟨⟨rem, cl⟩, s2, a2⟩ ⟨⟨_, j2, _, _, _, _, ty2⟩, both, _⟩ + simp only [Prod.mk.injEq] at both + obtain ⟨rfl, rfl⟩ := both + exact WP.spec_mono (cdt.empty_slot.vk I.del.arch I.del.os I.del.vr j2 hx (Or.inl rfl) j2.ksb) + fun _ keep => I.tyk s2 _ ty2 keep + +set_option maxHeartbeats 2000000 in +/-- Clearing an IRQ handler preserves the deletion typing. -/ +theorem interrupt.decode_irq_handler.clear_s1aTy {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) (a : A) {lbl irq : U64} (hl : lbl = fl4_abi.label.IRQClearIRQHandler) + (hi : irq.val < 5376) : + interrupt.decode_irq_handler st ar s a lbl irq extra ⦃ r => Ty r.2.1 ⦄ := by + subst lbl + have restart := tcb.restart_caller.delR I D P B Y (Stalled.refl0 D) (DF.refl s) (DS.refl s) (VsKeep.refl s) + simp only [tcb.restart_caller, cur_thread_ok, bind_ok] at restart + unfold interrupt.decode_irq_handler + rw [cur_thread_ok, bind_ok, if_neg (by simp [fl4_abi.label.IRQClearIRQHandler, fl4_abi.label.IRQAckIRQ]), + if_neg (by simp [fl4_abi.label.IRQClearIRQHandler, fl4_abi.label.IRQSetIRQHandler]), if_pos rfl] + refine WP.spec_bind restart fun s1 post => ?_ + refine WP.spec_bind (interrupt.irq_slot.val s1 irq) fun _ eq => ?_ + rw [eq, post.2.jv.ksb] + refine WP.spec_bind (cdt.delete_one.s1aTy I post.2 a hi) ?_ + rintro ⟨s2, _⟩ h + exact (WP.spec_ok _).2 h + +set_option hygiene false in +/-- An IRQ decode exit that leaves the initial state intact. -/ +local macro "irqTyLeaf" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 I.ty + | (simp only [error.invalid_cap, error.truncated, error.illegal, bind_ok, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, + core.convert.FromSame.from, bind_tc_ok] + exact (WP.spec_ok _).2 I.ty)) + +set_option maxHeartbeats 3000000 in +/-- Setting an IRQ handler preserves the deletion typing through the clear and notification insert. -/ +theorem interrupt.decode_irq_handler.set_s1aTy {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) (a : A) {lbl irq : U64} (hl : lbl = fl4_abi.label.IRQSetIRQHandler) + (hi : irq.val < 5376) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) : + interrupt.decode_irq_handler st ar s a lbl irq extra ⦃ r => Ty r.2.1 ⦄ := by + subst lbl + have base := Stalled.refl0 D + have q := base.bxi.1.choose_spec.choose_spec + have restart := WP.spec_and (tcb.restart_caller.delR I D P B Y base (DF.refl s) (DS.refl s) (VsKeep.refl s)) + (tcb.restart_caller.sts (q.nodes _ q.cur) (q.tcbs _ q.curT)) + simp only [tcb.restart_caller, cur_thread_ok, bind_ok] at restart + unfold interrupt.decode_irq_handler + rw [cur_thread_ok, bind_ok, if_neg (by simp [fl4_abi.label.IRQSetIRQHandler, fl4_abi.label.IRQAckIRQ]), if_pos rfl] + have valid : (0#usize).val < extra.val.length := by simp [extra.property] + refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec extra 0#usize valid) fun x e => ?_ + have hmem : x ∈ extra.val := e ▸ List.getElem_mem valid + simp only [obj.Slot.is_null, bind_ok] + split + · irqTyLeaf + rename_i hn + have hx0 : x ≠ 0#u64 := by simpa using hn + have hx := P.ext x hmem hx0 + have off := (SlotCov.offs P.heap B (hSC x hmem hx0)).1 + rw [capA_eq, bind_ok] + have hw : CapRt.EncWf (capA st s x) := CapRt.decodeF_encWf _ _ + generalize hc : capA st s x = c at hw + cases c <;> try irqTyLeaf + rename_i n b send recv + dsimp only + split + swap + · irqTyLeaf + refine WP.spec_bind restart fun s1 ⟨post, wr⟩ => ?_ + have keep := stt_osk P.os q q.curT wr + refine WP.spec_bind (interrupt.irq_slot.val s1 irq) fun _ eq => ?_ + rw [eq, post.2.jv.ksb] + refine WP.spec_bind (WP.spec_and (cdt.delete_one.irqLK I post.2 a hi) + (cdt.delete_one.s1aTy I post.2 a hi)) ?_ + rintro ⟨s2, _⟩ ⟨⟨B2, _, _, _, kept⟩, ty2⟩ + have stays : capA st s2 x = .Notification n b send recv := (kept x hx off).trans ((keep.capA hx).trans hc) + have hd := I.del.irq.1 irq hi + have apart : x ≠ irqSlotA (L.ksb s) irq := fun he => off ⟨irq, hi, he⟩ + unfold cdt.insert + simp only [uncurry_apply_pair] + rw [capA_eq, bind_ok, stays] + refine WP.spec_bind (cdt.insert_with_cap.s1aTy I ty2 B2.1.sys.stz.1.1.mdbS hx hd apart + (P.os.canon P.win hd) stays (fun e => by cases e) hw) fun _ ty3 => ?_ + exact (WP.spec_ok _).2 ty3 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiDelR.lean b/proofs/Fl4ProofsA64/P1/S1aHiDelR.lean new file mode 100644 index 000000000..798866a76 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiDelR.lean @@ -0,0 +1,213 @@ +/- +P1 (aarch64, A64-S1A gen 41): the deletion typing guarded by reachability (Architect ruling D2, 2026-12-03). + +`HiDelTy`'s full `VsTy` asks `desc` at every table of `Tb`, the detached HighVSpace roots included; it fails on +reachable states (handoff trace: `delete_asid_pool` leaves a mapped root whose private level-1 table still names a +page table that is then deleted and retyped). `HiDelTyR` keeps `HiDelTy`'s placement and `roots` over all of `Hr` +and replaces the typing by R2's own narrowed typings (`VsTyR … ∅ …`, `S2TyR`). It is a projection of R2 +(`HiDelTyR.ofR2`, at the active pool set). + +The old finaliser lemmas are reused at the reachable sets `T = VsRt Pp ∅ Tb Lv s`, `Hr ∩ T` and `S2Rt …` +(`HiDelTyR`-free instance lemmas `HrOK.restrictT`, `S2OK.restrictT`, `S2Ty.restrictT`). A zeroed word of a +reachable table outside `Hr ∩ T` is no `R + 4088` word for any `R ∈ Hr` (`tbo_restrict`), so the typing keeps the +`hi` clause of every live root, detached ones included. + +* `finKT_s2R`, `finKZ_s2R`, `tyk_s2R`: the class facts of `S2Q` over the narrowed typing; +* `DelIn.forHiDelR`, `HiDelTyR.finKZ`: `DelIn.forHiDel` / `HiDelTy.finKZ` at `HiDelTyR`; +* `HiDelTy.toR`: the old witness gives the new one. + +Named premises: none (the [P] `ArchPlat` of the reused lemmas). No existing statement changes. +-/ +import Fl4ProofsA64.P1.S1aStepR2Boot + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {Cs OS Vc Ub Pt : Set U64} + {Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- **The deletion typing guarded by reachability**: `HiDelTy` with R2's narrowed typings. -/ +structure HiDelTyR (st : machine.Store S) [L : LawfulStore st] (Pt OS Pp Tb Hr Te : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (s : S) : Prop where + pools : Pp ⊆ Pt + tables : Tb ⊆ Pt + granules : Gran Te bits ⊆ Pt + high : HrOK (L.ksb s) Pp Tb Lv Hr + stage2 : S2OK Te bits Hr + roots : HvRt st OS s ⊆ Hr + ty : VsTyR st (L.ksb s) Pp ∅ Tb Lv s ∧ S2TyR st n Pp Hr Te Re bits s + +/-- The old witness gives the guarded one. -/ +theorem HiDelTy.toR {n : U64} {s : S} (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) : + HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits n s := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2, W.roots, W.ty.1.toR, W.ty.2.toR⟩ + +/-- **R2 gives the guarded witness at its active pool set.** -/ +theorem HiDelTyR.ofR2 {n : U64} {s : S} (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + HiDelTyR st Pt OS (PoolSet st Pp s) Tb Hr Te Lv Re bits n s := + ⟨R.place.pools, R.place.tables, R.place.granules, R.place.high, R.place.stage2, + fun _ h => R.highRoots ▸ h, R.core.stage1, R.core.stage2⟩ + +/-- The placement record of the guarded witness. -/ +theorem HiDelTyR.place {n : U64} {s : S} (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits n s) : + S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + +/-! ## The reachable instance -/ + +section inst +variable {kb n : U64} {T : Set U64} + +/-- `HrOK` at a sub-table-set, over the roots inside it. -/ +theorem _root_.Fl4ProofsA64.P1.HrOK.restrictT (hO : HrOK kb Pp Tb Lv Hr) (hT : T ⊆ Tb) : + HrOK kb Pp T Lv {R | R ∈ Hr ∧ R ∈ T} := + ⟨fun _ h => h.2, fun R h => hO.lv R h.1, fun t ht o ho h8 R hR e => hO.tb t (hT ht) o ho h8 R hR.1 e, + fun p hp o ho h8 R hR => hO.pp p hp o ho h8 R hR.1, fun R hR => hO.asw R hR.1⟩ + +/-- `S2OK` at fewer objects and fewer roots. -/ +theorem _root_.Fl4ProofsA64.P1.S2OK.restrictT {Te' Hr' : Set U64} (hS : S2OK Te bits Hr) (hT : Te' ⊆ Te) (hH : Hr' ⊆ Hr) : + S2OK Te' bits Hr' := + have h := S2OK.sub hS hT + ⟨h.sz, h.al, fun b hb R hR => h.hr b hb R (hH hR)⟩ + +/-- **`S2Ty` over the reachable roots**: a tag-2 pool entry names a reachable root. -/ +theorem S2Ty.restrictT {s : S} (h1 : VsTyR st kb Pp ∅ Tb Lv s) (h2 : S2Ty st n Pp Hr Te Re bits s) : + S2Ty st n Pp {R | R ∈ Hr ∧ R ∈ VsRt st Pp ∅ Tb Lv s} Te Re bits s := by + refine ⟨fun p hp o ho h8 hne => ?_, fun R hR => h2.hi R hR.1, h2.desc⟩ + rcases h2.tag p hp o ho h8 hne with ⟨e, hn⟩ | ⟨e, hr⟩ | c + · exact Or.inl ⟨e, fun h => hn h.1⟩ + · refine Or.inr (Or.inl ⟨e, hr, ?_, ?_⟩) + · exact ((h1.pool p hp o ho h8 hne).2 e).1 + · exact VsReach.root2 hp ho h8 e + · exact Or.inr (Or.inr c) + +/-- A word of a reachable table outside the reachable roots is no `R + 4088` word of any root. -/ +theorem tbo_restrict (hO : HrOK kb Pp Tb Lv Hr) (hT : T ⊆ Tb) {b : U64} + (hb : PtW (TbO T {R | R ∈ Hr ∧ R ∈ T}) b) : ∀ R ∈ Hr, b ≠ wa R 4088#u64 := by + obtain ⟨t, ⟨ht, htH⟩, o, ho, h8, rfl⟩ := hb + intro R hR e + have same := hO.tb t (hT ht) o ho h8 R hR e + subst same + exact htH ⟨hR, ht⟩ + +end inst + +/-! ## The class facts over the narrowed typing -/ + +section s2kR +variable {Ω Sg Scs : Set U64} {Z : U64 → Nat} {kb : U64} + +/-- **`FinKT` of `S2Q` over `VsTyR ∧ S2TyR`** (`finKT_s2`'s cases at the reachable sets). -/ +theorem finKT_s2R (hP : P0.ArchTotal ar) (hPl : ArchPlat ar) (hR : VrOK Ω Sg Scs Z OS Vc Ub kb Pt) + (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te bits ⊆ Pt) (hO : HrOK kb Pp Tb Lv Hr) (hS : S2OK Te bits Hr) : + FinKT st ar kb Pt (fun s => VsTyR st kb Pp ∅ Tb Lv s ∧ S2TyR st hPl.ipa Pp Hr Te Re bits s) S2Q := by + intro s a c fin hY hk hc + let T := VsRt st Pp ∅ Tb Lv s + let HrT : Set U64 := {R | R ∈ Hr ∧ R ∈ T} + let TeR := S2Rt st Pp Te Re bits s + have hT : T ⊆ Tb := VsRt_sub + have hTR : TeR ⊆ Te := S2Rt_sub + have hO' : HrOK kb Pp T Lv HrT := hO.restrictT hT + have hS' : S2OK TeR bits HrT := hS.restrictT hTR fun _ h => h.1 + have hY1 : VsTy st kb Pp T Lv s := hY.1.sub + have hY2 : S2Ty st hPl.ipa Pp HrT TeR Re bits s := S2Ty.restrictT hY.1 hY.2.sub + have hTO : TbO T HrT ⊆ Pt := fun _ h => hTb (hT h.1) + have hTeR : Gran TeR bits ⊆ Pt := (gran_mono hTR).trans hTe + have hU : TbO T HrT ∪ Gran TeR bits ⊆ Pt := fun _ h => h.elim (fun h' => hTO h') (fun h' => hTeR h') + have hRal : ∀ R ∈ Hr, Aligned (wa R 4088#u64) := fun R hRm => hR.al _ (hr_vsr hTb hO hRm) + have keepTy : ∀ s', VsZ st kb Pt s s' → HrW st Hr s s' → + VsTyR st kb Pp ∅ Tb Lv s' ∧ S2TyR st hPl.ipa Pp Hr Te Re bits s' := + fun _ v k => ⟨hY.1.keepZ hPp hTb (Set.empty_subset _) v, hY.2.keep hPp hTe hS v k⟩ + have tW : ∀ (X : Set U64), X ⊆ Pt → (∀ b, PtW X b → ∀ R ∈ Hr, b ≠ wa R 4088#u64) → + ∀ r : (capability.Cap × capability.Cap) × S × A, + r.1 = (.Null, .Null) ∧ Wr0 st X s r.2.1 → r.1 = (.Null, .Null) ∧ + WritesIn st s r.2.1 (VsR kb Pt) ∧ + (VsTyR st kb Pp ∅ Tb Lv r.2.1 ∧ S2TyR st hPl.ipa Pp Hr Te Re bits r.2.1) := by + intro X hX hne r ⟨e, z⟩ + obtain ⟨w, v⟩ := wr0_vs hR (Wr0.mono hX z) + exact ⟨e, w, keepTy _ v (Wr0.hrw (fun b hb => hR.al b (Or.inl (ptw_mono hX hb))) hRal hne z)⟩ + have neT : ∀ b, PtW (TbO T HrT) b → ∀ R ∈ Hr, b ≠ wa R 4088#u64 := fun _ hb => tbo_restrict hO hT hb + have neG : ∀ b, PtW (Gran TeR bits) b → ∀ R ∈ Hr, b ≠ wa R 4088#u64 := + fun b hb => hS.hr b (gran_ptwb hS.sz (ptw_mono (gran_mono hTR) hb)) + have tT := tW _ hTO neT + have tP := tW _ hPp fun b hb => hO.ppw hb + have tU := tW _ hU fun b hb => (ptw_union hb).elim (neT b) (neG b) + have tG := tW _ hTeR neG + rcases hc with ((((⟨ptr, size, rights, mapped, asid, vaddr, rfl⟩ | ⟨p, m, ad, rfl⟩ | ⟨p, m, ad, rfl⟩) | + ⟨p, b, rfl⟩ | ⟨ptr, size, rights, mapped, asid, vaddr, rfl⟩) | ⟨p, m, ad, v, rfl⟩ | ⟨p, m, ad, v, rfl⟩ | + ⟨p, m, ad, v, rfl⟩) | ⟨p, l, m, ad, v, rfl⟩ | ⟨ptr, size, rights, dev, mapped, asid, vaddr, rfl⟩) + · rw [fin_cap_eq_obj (by simp)] + exact WP.spec_mono (fin_frame.hr (Hr := HrT) hP hO' s a ptr size rights mapped asid vaddr fin hY1 hk) tT + · rw [fin_cap_eq_obj (by simp)] + exact WP.spec_mono (fin_root.z hP s a p m ad fin (VsTy.ptPool (Pt := Pp) (fun _ h => h) hY1 hk ad)) tP + · rw [fin_cap_eq_obj (by simp)] + exact WP.spec_mono (fin_hvs.z hP s a p m ad fin (VsTy.ptPool (Pt := Pp) (fun _ h => h) hY1 hk ad)) tP + · rw [fin_cap_eq_obj (by simp)] + refine WP.spec_mono (fin_pool.hr hP hR hO hRal s a p b fin hk) fun r ⟨e, w, v, k⟩ => ?_ + exact ⟨e, w, keepTy _ v k⟩ + · rw [fin_cap_eq_obj (by simp)] + exact WP.spec_mono (fin_dframe.hr (Hr := HrT) hP hO' s a ptr size rights mapped asid vaddr fin hY1 hk) tT + · rw [fin_cap_eq_obj (by simp)] + exact WP.spec_mono (fin_pt.s2 hP hPl hO' hS' s a p m ad v fin hY1 hY2 hk) tU + · rw [fin_cap_eq_obj (by simp)] + exact WP.spec_mono (fin_pd.s2 hP hPl hO' hS' s a p m ad v fin hY1 hY2 hk) tU + · rw [fin_cap_eq_obj (by simp)] + exact WP.spec_mono (fin_pdpt.s2 hP hPl hO' hS' s a p m ad v fin hY1 hY2 hk) tU + · rw [fin_cap_eq_obj (by simp)] + exact WP.spec_mono (fin_ept.s2 hP s a p l m ad v fin (VsTy.ptPool (Pt := Pp) (fun _ h => h) hY1 hk ad)) tP + · rw [fin_cap_eq_obj (by simp)] + exact WP.spec_mono (fin_eframe.s2 hP hPl hS' s a ptr size rights dev mapped asid vaddr fin hY1 hY2 hk) tG + +/-- **`TyK` of `VsTyR ∧ S2TyR`.** -/ +theorem tyk_s2R {n : U64} (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te bits ⊆ Pt) (hO : HrOK kb Pp Tb Lv Hr) + (hS : S2OK Te bits Hr) : + TyK st kb Pt (fun s => VsTyR st kb Pp ∅ Tb Lv s ∧ S2TyR st n Pp Hr Te Re bits s) := + fun _ _ h k => ⟨h.1.keepZ hPp hTb (Set.empty_subset _) k.vsz, + h.2.keep hPp hTe hS k.vsz fun R hRm => k _ (hr_vsr hTb hO hRm)⟩ + +/-- **`FinKZ` of `S2Q` over `VsTyR ∧ S2TyR`**: `finKZ_s2` at the reachable sets of the start state. -/ +theorem finKZ_s2R (hP : P0.ArchTotal ar) (hPl : ArchPlat ar) (hR : VrOK Ω Sg Scs Z OS Vc Ub kb Pt) + (hPp : Pp ⊆ Pt) (hTb : Tb ⊆ Pt) (hTe : Gran Te bits ⊆ Pt) (hO : HrOK kb Pp Tb Lv Hr) (hS : S2OK Te bits Hr) : + FinKZ st ar kb Pt (fun s => VsTyR st kb Pp ∅ Tb Lv s ∧ S2TyR st hPl.ipa Pp Hr Te Re bits s) S2Q := by + intro s a c fin hY hk hc + have hT : VsRt st Pp ∅ Tb Lv s ⊆ Tb := VsRt_sub + have hTR : S2Rt st Pp Te Re bits s ⊆ Te := S2Rt_sub + exact finKZ_s2 hP hPl hR hPp (hT.trans hTb) ((gran_mono hTR).trans hTe) (hO.restrictT hT) + (hS.restrictT hTR fun _ h => h.1) s a c fin ⟨hY.1.sub, S2Ty.restrictT hY.1 hY.2.sub⟩ hk hc + +end s2kR + +/-! ## The deletion inputs at the guarded witness -/ + +/-- `DelIn.forHiDel` at the guarded witness. -/ +theorem DelIn.forHiDelR {s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hPl : ArchPlat ar) + (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) : + DelIn st ar H Cs OS Vc Ub Pt S2Q (fun q => VsTyR st (L.ksb s) Pp ∅ Tb Lv q ∧ + S2TyR st hPl.ipa Pp Hr Te Re bits q) s where + del := I.del + fin := finKT_s2R I.del.arch hPl I.del.vr W.pools W.tables W.granules W.high W.stage2 + tyk := tyk_s2R W.pools W.tables W.granules W.high W.stage2 + kl := fun c hc => I.kl c (I.s2 c hc) + kv := fun c hc => I.kv c (I.s2 c hc) + s2 := fun _ h => h + ts := I.ts + vty := I.vty + ty := W.ty + irq := I.irq + vcc := I.vcc + fu := I.fu + +/-- `HiDelTy.finKZ` at the guarded witness. -/ +theorem HiDelTyR.finKZ {s : S} {hPl : ArchPlat ar} + (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) : + FinKZ st ar (L.ksb s) Pt (fun q => VsTyR st (L.ksb s) Pp ∅ Tb Lv q ∧ + S2TyR st hPl.ipa Pp Hr Te Re bits q) S2Q := + finKZ_s2R I.del.arch hPl I.del.vr W.pools W.tables W.granules W.high W.stage2 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiDelTcb.lean b/proofs/Fl4ProofsA64/P1/S1aHiDelTcb.lean new file mode 100644 index 000000000..251e14ede --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiDelTcb.lean @@ -0,0 +1,619 @@ +/- +P1 (aarch64, A64-S1A gen 41): the TCB deletion arms preserve the concrete deletion typing +used in `S1aHiDel`. The inputs and footprints are the existing deletion, stall, and restart +facts. No new named premises or case facts. +-/ +import Fl4ProofsA64.P1.MdbDelArmQ +import Fl4ProofsA64.P1.S1aHiDel +import Fl4ProofsA64.P1.MdbSspArm +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {Cs OS Vc Ub Pt U Ac : Set U64} + {ia ie : Nat} {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +set_option hygiene false in +/-- Preservation at a decode exit with no writes after its stall. -/ +local macro "stalledTy" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 ty1 + | (simp only [error.invalid_cap, error.truncated, error.illegal, bind_ok, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 ty1)) + +set_option maxHeartbeats 4000000 in +/-- The buffer-slot deletion changes typing through `DelR`. The later field, slot and scheduler writes preserve it. -/ +theorem tcb.install_buffer.s1aTy {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (h0 : 0#u64 ∈ Cs) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) {a : A} {t slot baddr : U64} + {buffer : capability.Cap × obj.Slot} (ht : t ∈ H.tcbs) (hslot : slot ∈ OS) (hal : baddr.val % 1024 = 0) + (hbuf : buffer.2 ≠ 0#u64 → buffer.2 ∈ OS ∧ (∃ p sz rights m e aid va, + buffer.1 = .Frame p sz rights false m e aid va) ∧ CapRt.EncWf buffer.1) : + tcb.install_buffer st ar s a t slot baddr buffer ⦃ r => Ty r.2.1 ⦄ := by + have hi : layout.tcb.SLOT_BUFFER.val < 7 := by simp [layout.tcb.SLOT_BUFFER] + have hx := R.slot I ht hi + unfold tcb.install_buffer + rw [tcb_slot_val, bind_ok] + refine WP.spec_bind (WP.spec_and (cdt.delete.delR I R hx) (cdt.delete.nullR I R hx)) ?_ + rintro ⟨r, s1, a1⟩ ⟨R1, n1⟩ + try simp only [uncurry_apply_pair] at R1 n1 ⊢ + cases r with + | Err ex => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 R1.ty + | Ok v => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + refine WP.spec_bind (obj.Tcb.set_ipc_buffer.delR I R1 ht hal) fun s2 ⟨R2, k2⟩ => ?_ + obtain ⟨c, src⟩ := buffer + try simp only [uncurry_apply_pair] + refine WP.spec_bind (tcb.still_valid.soa s2 t slot c src) fun b hb => ?_ + refine WP.spec_bind (Pₘ := fun s3 => Ty s3 ∧ L.ksb s3 = L.ksb s0 ∧ SysL st H Cs OS ia ie s3 ∧ + ∃ Ac' : Set U64, BXI st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s3) ?_ ?_ + · split + swap + · exact (WP.spec_ok _).2 ⟨R2.ty, R2.jv.ksb, R2.sys, R2.jv.1.parts⟩ + rename_i valid + obtain ⟨hnz, hsame, hthread⟩ := hb valid + obtain ⟨hs, ⟨p, sz, rights, m, e, aid, va, rfl⟩, hw⟩ := hbuf hnz + obtain ⟨_, _, _, _, _, source⟩ := soa_frame hsame + have C : InsC (.Frame p sz rights false m e aid va) (capA st s2 src) := by rw [source]; exact InsC.frame + have empty : capA st s2 (slotIdx t layout.tcb.SLOT_BUFFER) = .Null := + (k2.capA hx.1).trans (okinj ((capA_eq s1 _).symm.trans (n1 v rfl))) + have apart : src ≠ slotIdx t layout.tcb.SLOT_BUFFER := fun eq => C.nn (eq ▸ empty) + obtain ⟨_, blk2⟩ := R2.jv.1.parts + have canon := I.del.dcan _ hx + have hm := R2.sys.sys.stz.1.1.mdbS + unfold cdt.insert + rw [capA_eq, bind_ok] + refine WP.spec_mono (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLVB I.del.heap I.del.os blk2 R2.sys R2.sym + R2.vc hs hx.1 apart canon rfl empty + (Or.inr ⟨Or.inr ⟨p, sz, rights, m, e, aid, va, rfl⟩, + ⟨(fun _ _ _ _ h => by cases h), (fun _ _ _ h => by cases h)⟩⟩) + ⟨slot, hslot, by rw [soa_thread hthread]; exact CovZ.tcbSlot I.del.heap ht hi⟩ hw (fun h => by cases h) C + (tcb_slot_notEptS I.del.heap ht hi (by simp [layout.tcb.SLOT_BUFFER]))) + (cdt.insert_with_cap.lrF I.del.os (LR.self s2) hs hx.1 apart canon rfl C.nn hw (hm.lnk I.del.os hs).2)) + (cdt.insert_with_cap.s1aTy I R2.ty hm hs hx.1 apart canon rfl C.nn hw)) ?_ + rintro s3 ⟨⟨⟨B3, _, _⟩, w, _⟩, ty3⟩ + exact ⟨ty3, w.1.trans R2.jv.ksb, B3, (Cur0R.capw7 R2.jv.1.1 w fun _ h => h).bxi⟩ + · rintro s3 ⟨ty3, kb3, B3, A3, hb3⟩ + refine WP.spec_bind (sched.cur_thread.spec s3) fun _ _ => ?_ + simp only [obj.Tcb.Insts.CoreCmpPartialEqTcb.eq, bind_ok] + split + swap + · exact (WP.spec_ok _).2 ty3 + refine WP.spec_bind (sched.reschedule_required.dfK s3 hb3.blk) fun s4 ⟨_, w, lv⟩ => ?_ + have vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s3) Pt := kb3.symm ▸ I.del.vr + have q := hb3.1.choose_spec.choose_spec + have table := TabF.of vr q B3.ly.ksw h0 + have d : DF st H Cs (L.curW s3) ∅ s3 s4 := DF.ofKL w lv (LvF.none_le _) + have keep := VsKeep.of_w vr.al d.w (fun b hV hD => hV.elim (DfW.notPtW q vr hD) + (DfW.notAsW I.del.heap table vr q.nodes hD)) + exact (WP.spec_ok _).2 (I.tyk s3 s4 ty3 (kb3 ▸ keep)) + +/-- **The steps of the TCB install walks**, for any state predicate `Φ` carried through them: `G` and `B` are the +facts about the installed capability and buffer. -/ +structure S1aTcbSteps (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) (H : Heap) + (Cs OS Vc Ub Pt Ac : Set U64) (Ty : S → Prop) (ia ie : Nat) (s s1 : S) (t slot : U64) (Φ : S → Prop) + (G : capability.Cap → Prop) (B : capability.Cap × obj.Slot → Prop) : Prop where + keep : ∀ q r : S, Φ q → L.ksb q = L.ksb s → L.ksb r = L.ksb s → VsKeep st (L.ksb s) Pt q r → + OSKeep st OS q r → Φ r + install : ∀ (q : S) (a : A) (index : U64) (nc : capability.Cap) (src : U64), Φ q → + DelR st H Cs OS Vc Ub Ac Ty ia ie s q → PoolR st OS s q → (ArmVsZ st H OS Vc s q ∧ FrC st OS s q) → + index.val < 7 → index.val ≠ 2 → index.val ≠ 5 → (src ≠ 0#u64 → src ∈ OS) → + (nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) → G nc → + tcb.install_tcb_cap st ar q a t slot index nc src ⦃ r => Φ r.2.1 ⦄ + buffer : ∀ (q : S) (a : A) (baddr : U64) (buffer : capability.Cap × obj.Slot), Φ q → + DelR st H Cs OS Vc Ub Ac Ty ia ie s q → baddr.val % 1024 = 0 → + (buffer.2 ≠ 0#u64 → buffer.2 ∈ OS ∧ (∃ p sz rights m e aid va, + buffer.1 = .Frame p sz rights false m e aid va) ∧ CapRt.EncWf buffer.1) → B buffer → + tcb.install_buffer st ar q a t slot baddr buffer ⦃ r => Φ r.2.1 ⦄ + unread : ∀ nc, (nc = .Null ∨ faults.valid_fault_handler nc = ok true) → G nc + roots : ∀ cd vd cs vs : U64, cs ∈ OS → vs ∈ OS → + tcb.derive_roots st s1 t cd vd cs vs ⦃ r => ∀ cc vc, r = .Ok (cc, vc) → G cc ∧ G vc ⦄ + high : ∀ x ∈ OS, ∀ p a, capA st s1 x = .HighVSpace p true a → G (.HighVSpace p true a) + derived : ∀ baddr bslot : U64, bslot ∈ OS → + tcb.derive_for_buffer st s1 baddr bslot ⦃ r => ∀ c src, r = .Ok (c, src) → B (c, src) ⦄ + +/-- With the trivial predicate the steps are the deletion typing's. -/ +theorem S1aTcbSteps.trivial {s s1 : S} {t slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (ht : t ∈ H.tcbs) (hslot : slot ∈ OS) + (h0 : 0#u64 ∈ Cs) : + S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot (fun _ => True) (fun _ => True) (fun _ => True) where + keep _ _ _ _ _ _ _ := True.intro + install _ _ _ _ _ _ R Q Z hi hi2 hi5 hsrc hnc _ := + WP.spec_mono (tcb.install_tcb_cap.delRP I hKZ hPI R Q Z ht hi hi2 hslot hsrc hnc hi5) fun _ _ => True.intro + buffer _ _ _ _ _ R hal hbuf _ := + WP.spec_mono (tcb.install_buffer.s1aTy I h0 R ht hslot hal hbuf) fun _ _ => True.intro + unread _ _ := True.intro + roots cd vd cs vs _ _ := + WP.spec_mono (tcb.derive_roots.tk s1 t cd vd cs vs) fun _ _ _ _ _ => ⟨True.intro, True.intro⟩ + high _ _ _ _ _ := True.intro + derived baddr bslot _ := WP.spec_mono (tcb.derive_for_buffer.buf s1 baddr bslot) fun _ _ _ _ _ => True.intro + +set_option maxHeartbeats 2000000 in +/-- With a carried state predicate: an install into the high VSpace slot retains the typing through its +existing `DelR` continuation. -/ +theorem tcb.decode_set_high_vspace.s1aPhi {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) + {Φ : S → Prop} {G : capability.Cap → Prop} {Gb : capability.Cap × obj.Slot → Prop} + (W : S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot Φ G Gb) (hΦ : Φ s) : + tcb.decode_set_high_vspace st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ∧ Φ r.2.1 ⦄ := by + have ty1 : Ty s1 ∧ Φ s1 := ⟨I.tyk s s1 I.ty vk1, W.keep s s1 hΦ rfl d1.w.1 vk1 ds1.1⟩ + have restart := WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) + (tcb.restart_caller.armVsK I D P B h1 d1 ds1) + have install (nc : capability.Cap) (x : U64) (hx : x ∈ OS) (hw : nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) + (hg : G nc) : + (do + let s2 ← tcb.restart_caller st s1 + tcb.install_tcb_cap st ar s2 a1 t slot layout.tcb.SLOT_HIGH_VSPACE nc x) ⦃ r => + Ty r.2.1 ∧ Φ r.2.1 ⦄ := + WP.spec_bind restart fun s2 ⟨d, keep, os⟩ => by + have p2 := W.keep s s2 hΦ rfl d.1.2.jv.ksb (keep.2 Ub Pt I.del.vr I.fu) os + exact WP.spec_mono (WP.spec_and (tcb.install_tcb_cap.delRP I hKZ hPI d.1.2 d.2.1 d.2.2 (D.cap.2.1 t rfl) + (by simp [layout.tcb.SLOT_HIGH_VSPACE]) (by simp [layout.tcb.SLOT_HIGH_VSPACE]) P.src + (fun _ => hx) hw (by simp [layout.tcb.SLOT_HIGH_VSPACE])) + (W.install s2 a1 _ nc x p2 d.1.2 d.2.1 d.2.2 (by simp [layout.tcb.SLOT_HIGH_VSPACE]) + (by simp [layout.tcb.SLOT_HIGH_VSPACE]) (by simp [layout.tcb.SLOT_HIGH_VSPACE]) (fun _ => hx) hw hg)) + fun _ h => ⟨h.1.1.ty, h.2⟩ + unfold tcb.decode_set_high_vspace + refine WP.spec_bind (tcb.extra.mem0 _) fun o ho => ?_ + cases o with + | none => stalledTy + | some x => + have ⟨hx, hn⟩ := ho x rfl + have hxO := P.ext x hx hn + simp only + rw [capA_eq, bind_ok] + have hw : CapRt.EncWf (capA st s1 x) := CapRt.decodeF_encWf _ _ + generalize hc : capA st s1 x = c at hw + cases c <;> try stalledTy + · exact install .Null x hxO (fun h => absurd rfl h) (W.unread _ (Or.inl rfl)) + · rename_i ptr m asid + dsimp only + split + · rename_i hm + subst hm + refine WP.spec_bind (P0.vspace.find_high_asid.p0 st s1 _ L.total) fun r _ => ?_ + cases r with + | Err _ => stalledTy + | Ok _ => + simp only + split + · rw [show objects.derive_cap st s1 x (.HighVSpace ptr true asid) = + ok (.Ok (.HighVSpace ptr true asid)) by simp [objects.derive_cap]] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + exact install _ x hxO (fun _ => ⟨Or.inr (Or.inr (Or.inr (Or.inr ⟨ptr, true, asid, rfl⟩))), hw⟩) + (W.high x hxO ptr asid hc) + · stalledTy + · stalledTy + +set_option maxHeartbeats 2000000 in +/-- An install into the high VSpace slot retains the typing through its existing `DelR` continuation. -/ +theorem tcb.decode_set_high_vspace.s1aTy {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + tcb.decode_set_high_vspace st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ⦄ := + WP.spec_mono (tcb.decode_set_high_vspace.s1aPhi I hKZ hPI D P B Y h1 d1 ds1 vk1 (S1aTcbSteps.trivial I hKZ hPI (D.cap.2.1 t rfl) P.src P.core0) True.intro) fun _ h => h.1 + +set_option maxHeartbeats 2000000 in +/-- With a carried state predicate: a timeout-handler install retains the typing after its deletion and +optional reinsert. -/ +theorem tcb.decode_set_timeout_endpoint.s1aPhi {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) + {Φ : S → Prop} {G : capability.Cap → Prop} {Gb : capability.Cap × obj.Slot → Prop} + (W : S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot Φ G Gb) (hΦ : Φ s) : + tcb.decode_set_timeout_endpoint st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ∧ Φ r.2.1 ⦄ := by + have ty1 : Ty s1 ∧ Φ s1 := ⟨I.tyk s s1 I.ty vk1, W.keep s s1 hΦ rfl d1.w.1 vk1 ds1.1⟩ + unfold tcb.decode_set_timeout_endpoint + refine WP.spec_bind (tcb.extra_with_length.memi _ 0#usize _ (by simp)) fun r hr => ?_ + cases r with + | Err _ => stalledTy + | Ok x => + obtain ⟨hx, hx0⟩ := hr x rfl + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + rw [capA_eq, bind_ok] + refine WP.spec_bind (spec_eqv (P0.faults.valid_fault_handler.p0 (capA st s1 x))) fun _ h => ?_ + split + swap + · stalledTy + rename_i valid + have hw : capA st s1 x ≠ .Null → TcbK (capA st s1 x) ∧ CapRt.EncWf (capA st s1 x) := fun hn => + ⟨vfh_tk (valid ▸ h.1) hn, CapRt.decodeF_encWf _ _⟩ + refine WP.spec_bind (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) + (tcb.restart_caller.armVsK I D P B h1 d1 ds1)) fun s2 ⟨d, keep, os⟩ => ?_ + have p2 := W.keep s s2 hΦ rfl d.1.2.jv.ksb (keep.2 Ub Pt I.del.vr I.fu) os + unfold tcb.thread_control_caps + simp only [lift, bind_ok, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_SPACE, tcb.UPDATE_IPC_BUFFER] + simp + refine qq_bind (Q1 := fun q => Ty q ∧ Φ q) (Q2 := fun q => Ty q ∧ Φ q) + (WP.spec_mono (WP.spec_and (tcb.install_tcb_cap.delRP I hKZ hPI d.1.2 d.2.1 d.2.2 (D.cap.2.1 t rfl) + (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER]) (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER]) P.src + (fun _ => P.ext x hx hx0) hw (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER])) + (W.install s2 _ _ _ _ p2 d.1.2 d.2.1 d.2.2 (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER]) + (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER]) (by simp [layout.tcb.SLOT_TIMEOUT_HANDLER]) + (fun _ => P.ext x hx hx0) hw (W.unread _ (Or.inr (valid ▸ h.1))))) fun _ h => ⟨h.1.1.ty, h.2⟩) + (fun _ _ h => (WP.spec_ok _).2 h) fun _ h => h + +set_option maxHeartbeats 2000000 in +/-- A timeout-handler install retains the typing after its deletion and optional reinsert. -/ +theorem tcb.decode_set_timeout_endpoint.s1aTy {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + tcb.decode_set_timeout_endpoint st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ⦄ := + WP.spec_mono (tcb.decode_set_timeout_endpoint.s1aPhi I hKZ hPI D P B Y h1 d1 ds1 vk1 (S1aTcbSteps.trivial I hKZ hPI (D.cap.2.1 t rfl) P.src P.core0) True.intro) fun _ h => h.1 + +set_option hygiene false in +/-- Successful extra slots are in the original OS set. -/ +local macro "extraTy" i:term "as" x:ident "," hit:ident : tactic => `(tactic| ( + refine WP.spec_bind (tcb.extra_with_length.memi _ $i _ (by simp)) fun r result => ?_ + rcases r with $x:ident | _ + swap + · stalledTy + have $hit:ident : $x ∈ OS := P.ext $x (result $x rfl).1 (result $x rfl).2 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok])) + +set_option hygiene false in +/-- The checking phase of an IPC buffer argument produces an aligned address and typed source. -/ +local macro "bufferTy" addr:term "," x:term : tactic => `(tactic| ( + refine WP.spec_bind (tcb.derive_for_buffer.buf s1 $addr $x) fun r result => ?_ + rcases r with ⟨bc, bs⟩ | _ + swap + · stalledTy + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + try simp only [uncurry_apply_pair] + obtain ⟨hba, hbs⟩ := result bc bs rfl)) + +set_option maxHeartbeats 3000000 in +/-- With a carried state predicate: SetIPCBuffer preserves the deletion typing through its single install. -/ +theorem tcb.decode_set_ipc_buffer.s1aPhi {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) + {Φ : S → Prop} {Gb : capability.Cap × obj.Slot → Prop} (hΦ : Φ s) + (keepΦ : ∀ q r : S, Φ q → L.ksb q = L.ksb s → L.ksb r = L.ksb s → VsKeep st (L.ksb s) Pt q r → + OSKeep st OS q r → Φ r) + (bufferΦ : ∀ (q : S) (a : A) (baddr : U64) (buffer : capability.Cap × obj.Slot), Φ q → + DelR st H Cs OS Vc Ub Ac Ty ia ie s q → baddr.val % 1024 = 0 → + (buffer.2 ≠ 0#u64 → buffer.2 ∈ OS ∧ (∃ p sz rights m e aid va, + buffer.1 = .Frame p sz rights false m e aid va) ∧ CapRt.EncWf buffer.1) → Gb buffer → + tcb.install_buffer st ar q a t slot baddr buffer ⦃ r => Φ r.2.1 ⦄) + (derivedΦ : ∀ baddr bslot : U64, bslot ∈ OS → + tcb.derive_for_buffer st s1 baddr bslot ⦃ r => ∀ c src, r = .Ok (c, src) → Gb (c, src) ⦄) : + tcb.decode_set_ipc_buffer st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ∧ Φ r.2.1 ⦄ := by + have ty1 : Ty s1 ∧ Φ s1 := ⟨I.tyk s s1 I.ty vk1, keepΦ s s1 hΦ rfl d1.w.1 vk1 ds1.1⟩ + unfold tcb.decode_set_ipc_buffer + extraTy 0#usize as src, hsrc + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ L.total) fun addr _ => ?_ + refine WP.spec_bind (WP.spec_and (tcb.derive_for_buffer.buf s1 addr src) (derivedΦ addr src hsrc)) + fun r ⟨result, facts⟩ => ?_ + rcases r with ⟨bc, bs⟩ | _ + swap + · stalledTy + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + try simp only [uncurry_apply_pair] + obtain ⟨hba, hbs⟩ := result bc bs rfl + refine WP.spec_bind (WP.spec_and (tcb.restart_caller.delR I D P B Y h1 d1 ds1 vk1) + (tcb.restart_caller.armVsK I D P B h1 d1 ds1)) fun s2 ⟨r, keep, os⟩ => ?_ + have p2 := keepΦ s s2 hΦ rfl r.2.jv.ksb (keep.2 Ub Pt I.del.vr I.fu) os + unfold tcb.thread_control_caps + simp only [lift, bind_ok, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_SPACE, tcb.UPDATE_IPC_BUFFER] + simp + have facts' : bs ≠ 0#u64 → bs ∈ OS ∧ (∃ p sz rights m e aid va, bc = .Frame p sz rights false m e aid va) ∧ + CapRt.EncWf bc := fun h => by + obtain ⟨eq, rest⟩ := hbs h + exact ⟨eq ▸ hsrc, rest⟩ + exact qq_bind (Q1 := fun q => Ty q ∧ Φ q) (Q2 := fun q => Ty q ∧ Φ q) + (WP.spec_and (tcb.install_buffer.s1aTy (buffer := (bc, bs)) I P.core0 r.2 (D.cap.2.1 t rfl) P.src hba facts') + (bufferΦ s2 _ _ (bc, bs) p2 r.2 hba facts' (facts bc bs rfl))) + (fun _ _ h => (WP.spec_ok _).2 h) fun _ h => h + +set_option maxHeartbeats 3000000 in +/-- SetIPCBuffer preserves the deletion typing through its single install. -/ +theorem tcb.decode_set_ipc_buffer.s1aTy {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + tcb.decode_set_ipc_buffer st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ⦄ := + WP.spec_mono (tcb.decode_set_ipc_buffer.s1aPhi I D P B Y h1 d1 ds1 vk1 (Φ := fun _ => True) + (Gb := fun _ => True) True.intro (fun _ _ _ _ _ _ _ => True.intro) + (fun _ _ _ _ _ R hal hbuf _ => WP.spec_mono + (tcb.install_buffer.s1aTy I P.core0 R (D.cap.2.1 t rfl) P.src hal hbuf) fun _ _ => True.intro) + (fun baddr bslot _ => WP.spec_mono (tcb.derive_for_buffer.buf s1 baddr bslot) fun _ _ _ _ _ => True.intro)) + fun _ h => h.1 + +set_option maxHeartbeats 4000000 in +/-- With a carried state predicate: SetSpace retains the typing through the three sequential installs. -/ +theorem tcb.decode_set_space.s1aPhi {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) + {Φ : S → Prop} {G : capability.Cap → Prop} {Gb : capability.Cap × obj.Slot → Prop} + (W : S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot Φ G Gb) (hΦ : Φ s) : + tcb.decode_set_space st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ∧ Φ r.2.1 ⦄ := by + have ty1 : Ty s1 ∧ Φ s1 := ⟨I.tyk s s1 I.ty vk1, W.keep s s1 hΦ rfl d1.w.1 vk1 ds1.1⟩ + have ht := D.cap.2.1 t rfl + unfold tcb.decode_set_space + extraTy 0#usize as fault, hfault + extraTy 1#usize as cslot, hcslot + extraTy 2#usize as vslot, hvslot + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ L.total) fun cdata _ => ?_ + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ L.total) fun vdata _ => ?_ + refine WP.spec_bind (WP.spec_and (tcb.derive_roots.tk s1 t cdata vdata cslot vslot) + (W.roots cdata vdata cslot vslot hcslot hvslot)) fun r ⟨result, roots⟩ => ?_ + rcases r with ⟨cc, vc⟩ | _ + swap + · stalledTy + obtain ⟨cvalid, vvalid⟩ := result cc vc rfl + obtain ⟨gc, gv⟩ := roots cc vc rfl + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + try simp only [uncurry_apply_pair] + rw [capA_eq, bind_ok] + refine WP.spec_bind (spec_eqv (P0.faults.valid_fault_handler.p0 (capA st s1 fault))) fun _ okFault => ?_ + split + swap + · stalledTy + rename_i valid + have fvalid : capA st s1 fault ≠ .Null → TcbK (capA st s1 fault) ∧ CapRt.EncWf (capA st s1 fault) := + fun h => ⟨vfh_tk (valid ▸ okFault.1) h, CapRt.decodeF_encWf _ _⟩ + refine WP.spec_bind (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) + (tcb.restart_caller.armVsK I D P B h1 d1 ds1)) fun s2 ⟨init, keep, os⟩ => ?_ + have p2 := W.keep s s2 hΦ rfl init.1.2.jv.ksb (keep.2 Ub Pt I.del.vr I.fu) os + simp only [lift, bind_ok] + unfold tcb.thread_control_caps + simp only [lift, bind_ok, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_SPACE, tcb.UPDATE_IPC_BUFFER] + simp + let afterInstall : S → Prop := fun q => + DelR st H Cs OS Vc Ub Ac Ty ia ie s q ∧ PoolR st OS s q ∧ (ArmVsZ st H OS Vc s q ∧ FrC st OS s q) ∧ Φ q + have start : afterInstall s2 := ⟨init.1.2, init.2.1, init.2.2, p2⟩ + have gf : G (capA st s1 fault) := W.unread _ (Or.inr (valid ▸ okFault.1)) + refine qq_bind (Q1 := afterInstall) (Q2 := fun q => Ty q ∧ Φ q) (WP.spec_mono (WP.spec_and (tcb.install_tcb_cap.delRP I hKZ hPI start.1 start.2.1 start.2.2.1 ht + (by simp [layout.tcb.SLOT_FAULT_HANDLER]) (by simp [layout.tcb.SLOT_FAULT_HANDLER]) P.src (fun _ => hfault) + fvalid (by simp [layout.tcb.SLOT_FAULT_HANDLER])) + (W.install _ _ _ _ _ start.2.2.2 start.1 start.2.1 start.2.2.1 (by simp [layout.tcb.SLOT_FAULT_HANDLER]) + (by simp [layout.tcb.SLOT_FAULT_HANDLER]) (by simp [layout.tcb.SLOT_FAULT_HANDLER]) (fun _ => hfault) fvalid gf)) + fun _ h => ⟨h.1.1, h.1.2.1, h.1.2.2, h.2⟩) (fun _ _ d => ?_) fun _ h => ⟨h.1.ty, h.2.2.2⟩ + refine qq_bind (Q1 := afterInstall) (Q2 := fun q => Ty q ∧ Φ q) (WP.spec_mono (WP.spec_and (tcb.install_tcb_cap.delRP I hKZ hPI d.1 d.2.1 d.2.2.1 ht + (by simp [layout.tcb.SLOT_CTABLE]) (by simp [layout.tcb.SLOT_CTABLE]) P.src (fun _ => hcslot) + (fun _ => cvalid) (by simp [layout.tcb.SLOT_CTABLE])) + (W.install _ _ _ _ _ d.2.2.2 d.1 d.2.1 d.2.2.1 (by simp [layout.tcb.SLOT_CTABLE]) + (by simp [layout.tcb.SLOT_CTABLE]) (by simp [layout.tcb.SLOT_CTABLE]) (fun _ => hcslot) (fun _ => cvalid) gc)) + fun _ h => ⟨h.1.1, h.1.2.1, h.1.2.2, h.2⟩) (fun _ _ d => ?_) fun _ h => ⟨h.1.ty, h.2.2.2⟩ + exact qq_bind (Q1 := afterInstall) (Q2 := fun q => Ty q ∧ Φ q) (WP.spec_mono (WP.spec_and (tcb.install_tcb_cap.delRP I hKZ hPI d.1 d.2.1 d.2.2.1 ht + (by simp [layout.tcb.SLOT_VTABLE]) (by simp [layout.tcb.SLOT_VTABLE]) P.src (fun _ => hvslot) + (fun _ => vvalid) (by simp [layout.tcb.SLOT_VTABLE])) + (W.install _ _ _ _ _ d.2.2.2 d.1 d.2.1 d.2.2.1 (by simp [layout.tcb.SLOT_VTABLE]) + (by simp [layout.tcb.SLOT_VTABLE]) (by simp [layout.tcb.SLOT_VTABLE]) (fun _ => hvslot) (fun _ => vvalid) gv)) + fun _ h => ⟨h.1.1, h.1.2.1, h.1.2.2, h.2⟩) + (fun _ _ d => (WP.spec_ok _).2 ⟨d.1.ty, d.2.2.2⟩) fun _ h => ⟨h.1.ty, h.2.2.2⟩ + +set_option maxHeartbeats 4000000 in +/-- SetSpace retains the typing through the three sequential installs. -/ +theorem tcb.decode_set_space.s1aTy {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + tcb.decode_set_space st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ⦄ := + WP.spec_mono (tcb.decode_set_space.s1aPhi I hKZ hPI D P B Y h1 d1 ds1 vk1 (S1aTcbSteps.trivial I hKZ hPI (D.cap.2.1 t rfl) P.src P.core0) True.intro) fun _ h => h.1 + +set_option maxHeartbeats 4000000 in +/-- With a carried state predicate: Configure retains the typing through the two roots and the buffer install. -/ +theorem tcb.decode_configure.s1aPhi {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) + {Φ : S → Prop} {G : capability.Cap → Prop} {Gb : capability.Cap × obj.Slot → Prop} + (W : S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot Φ G Gb) (hΦ : Φ s) : + tcb.decode_configure st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ∧ Φ r.2.1 ⦄ := by + have ty1 : Ty s1 ∧ Φ s1 := ⟨I.tyk s s1 I.ty vk1, W.keep s s1 hΦ rfl d1.w.1 vk1 ds1.1⟩ + have ht := D.cap.2.1 t rfl + unfold tcb.decode_configure + extraTy 0#usize as cslot, hcslot + extraTy 1#usize as vslot, hvslot + extraTy 2#usize as bslot, hbslot + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ L.total) fun cdata _ => ?_ + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ L.total) fun vdata _ => ?_ + refine WP.spec_bind (P0.tcb.arg.p0 st s1 _ _ L.total) fun addr _ => ?_ + refine WP.spec_bind (WP.spec_and (tcb.derive_for_buffer.buf s1 addr bslot) (W.derived addr bslot hbslot)) + fun r ⟨result, facts⟩ => ?_ + rcases r with ⟨bc, bs⟩ | _ + swap + · stalledTy + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + try simp only [uncurry_apply_pair] + obtain ⟨hba, hbs⟩ := result bc bs rfl + refine WP.spec_bind (WP.spec_and (tcb.derive_roots.tk s1 t cdata vdata cslot vslot) + (W.roots cdata vdata cslot vslot hcslot hvslot)) fun r ⟨rs, roots⟩ => ?_ + rcases r with ⟨cc, vc⟩ | _ + swap + · stalledTy + obtain ⟨cvalid, vvalid⟩ := rs cc vc rfl + obtain ⟨gc, gv⟩ := roots cc vc rfl + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + try simp only [uncurry_apply_pair] + refine WP.spec_bind (WP.spec_and (tcb.restart_caller.delRP I D P B Y h1 d1 ds1 vk1) + (tcb.restart_caller.armVsK I D P B h1 d1 ds1)) fun s2 ⟨init, keep, os⟩ => ?_ + have p2 := W.keep s s2 hΦ rfl init.1.2.jv.ksb (keep.2 Ub Pt I.del.vr I.fu) os + simp only [lift, bind_ok] + unfold tcb.thread_control_caps + simp only [lift, bind_ok, tcb.UPDATE_FAULT, tcb.UPDATE_TIMEOUT, tcb.UPDATE_SPACE, tcb.UPDATE_IPC_BUFFER] + simp + let afterInstall : S → Prop := fun q => + DelR st H Cs OS Vc Ub Ac Ty ia ie s q ∧ PoolR st OS s q ∧ (ArmVsZ st H OS Vc s q ∧ FrC st OS s q) ∧ Φ q + have start : afterInstall s2 := ⟨init.1.2, init.2.1, init.2.2, p2⟩ + have facts' : bs ≠ 0#u64 → bs ∈ OS ∧ (∃ p sz rights m e aid va, bc = .Frame p sz rights false m e aid va) ∧ + CapRt.EncWf bc := fun h => by + obtain ⟨eq, rest⟩ := hbs h + exact ⟨eq ▸ hbslot, rest⟩ + refine qq_bind (Q1 := afterInstall) (Q2 := fun q => Ty q ∧ Φ q) (WP.spec_mono (WP.spec_and (tcb.install_tcb_cap.delRP I hKZ hPI start.1 start.2.1 start.2.2.1 ht + (by simp [layout.tcb.SLOT_CTABLE]) (by simp [layout.tcb.SLOT_CTABLE]) P.src (fun _ => hcslot) + (fun _ => cvalid) (by simp [layout.tcb.SLOT_CTABLE])) + (W.install _ _ _ _ _ start.2.2.2 start.1 start.2.1 start.2.2.1 (by simp [layout.tcb.SLOT_CTABLE]) + (by simp [layout.tcb.SLOT_CTABLE]) (by simp [layout.tcb.SLOT_CTABLE]) (fun _ => hcslot) (fun _ => cvalid) gc)) + fun _ h => ⟨h.1.1, h.1.2.1, h.1.2.2, h.2⟩) (fun _ _ d => ?_) fun _ h => ⟨h.1.ty, h.2.2.2⟩ + refine qq_bind (Q1 := afterInstall) (Q2 := fun q => Ty q ∧ Φ q) (WP.spec_mono (WP.spec_and (tcb.install_tcb_cap.delRP I hKZ hPI d.1 d.2.1 d.2.2.1 ht + (by simp [layout.tcb.SLOT_VTABLE]) (by simp [layout.tcb.SLOT_VTABLE]) P.src (fun _ => hvslot) + (fun _ => vvalid) (by simp [layout.tcb.SLOT_VTABLE])) + (W.install _ _ _ _ _ d.2.2.2 d.1 d.2.1 d.2.2.1 (by simp [layout.tcb.SLOT_VTABLE]) + (by simp [layout.tcb.SLOT_VTABLE]) (by simp [layout.tcb.SLOT_VTABLE]) (fun _ => hvslot) (fun _ => vvalid) gv)) + fun _ h => ⟨h.1.1, h.1.2.1, h.1.2.2, h.2⟩) (fun _ _ d => ?_) fun _ h => ⟨h.1.ty, h.2.2.2⟩ + exact qq_bind (Q1 := fun q => Ty q ∧ Φ q) (Q2 := fun q => Ty q ∧ Φ q) + (WP.spec_and (tcb.install_buffer.s1aTy (buffer := (bc, bs)) I P.core0 d.1 ht P.src hba facts') + (W.buffer _ _ _ (bc, bs) d.2.2.2 d.1 hba facts' (facts bc bs rfl))) + (fun _ _ h => (WP.spec_ok _).2 h) fun _ h => h + +set_option maxHeartbeats 4000000 in +/-- Configure retains the typing through the two roots and the buffer install. -/ +theorem tcb.decode_configure.s1aTy {s s1 : S} {a1 : A} {t len buf : U64} {call : Bool} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (h1 : Stalled st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s s1) + (d1 : DF st H Cs (L.curW s) ∅ s s1) (ds1 : DS st H.tcbs OS Vc s s1) (vk1 : VsKeep st (L.ksb s) Pt s s1) : + tcb.decode_configure st ar s1 a1 t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ⦄ := + WP.spec_mono (tcb.decode_configure.s1aPhi I hKZ hPI D P B Y h1 d1 ds1 vk1 (S1aTcbSteps.trivial I hKZ hPI (D.cap.2.1 t rfl) P.src P.core0) True.intro) fun _ h => h.1 + +set_option maxHeartbeats 3000000 in +/-- With a carried state predicate: SetEPTRoot retains the typing through its explicit deletion and CTE insertion. -/ +theorem tcb.decode.setEpt_s1aPhi (hA : P0.ArchTotal ar) {s : S} {a : A} {t len buf : U64} {call : Bool} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (hXE : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∉ EptS H.tcbs) + {Φ : S → Prop} (hΦ : Φ s) + (keepΦ : ∀ q r : S, Φ q → L.ksb q = L.ksb s → L.ksb r = L.ksb s → VsKeep st (L.ksb s) Pt q r → + OSKeep st OS q r → Φ r) + (deleteΦ : ∀ (q : S) (a : A) (x : U64), Φ q → DelR st H Cs OS Vc Ub Ac Ty ia ie s q → + x ∈ OSN OS (L.ksb s) → cdt.delete st ar q a x true ⦃ r => Φ r.2.1 ⦄) + (insertΦ : ∀ (q : S) (src dest : U64) (nc : capability.Cap), Φ q → DelR st H Cs OS Vc Ub Ac Ty ia ie s q → + src ∈ OS → dest ∈ OS → src ≠ dest → obj.sext48 dest = ok dest → capA st q src = nc → CapRt.EncWf nc → + capA st q dest = .Null → (∃ p l m v, nc = .Ept p l true m v) → + cdt.insert_with_cap st q nc nc src dest ⦃ s' => Φ s' ⦄) : + tcb.decode st ar s a fl4_abi.label.TCBSetEPTRoot t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ∧ Φ r.2.1 ⦄ := by + have ht := D.cap.2.1 t rfl + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.delS hA D I a t) ?_ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ + try simp only [uncurry_apply_pair] + have ty1 : Ty s1 ∧ Φ s1 := ⟨I.tyk s s1 I.ty vk1, keepΦ s s1 hΦ rfl d1.w.1 vk1 ds1.1⟩ + have notPac : fl4_abi.label.TCBSetEPTRoot ≠ fl4_abi.label.TCBSetPACKeys := + lbl_ne_of_val (by simp [fl4_abi.label.TCBSetEPTRoot, fl4_abi.label.TCBSetPACKeys, core.num.U64.MAX, U64.rMax]) + have notHigh : fl4_abi.label.TCBSetEPTRoot ≠ fl4_abi.label.TCBSetHighVSpace := + lbl_ne_of_val (by simp [fl4_abi.label.TCBSetEPTRoot, fl4_abi.label.TCBSetHighVSpace, core.num.U64.MAX, U64.rMax]) + refine spec_ite (fun h => absurd h notPac) fun _ => ?_ + refine spec_ite (fun h => absurd h notHigh) fun _ => ?_ + refine spec_ite (fun _ => ?_) (fun h => absurd (by first | rfl | trivial) h) + have valid : (0#usize).val < extra.val.length := by simp [extra.property] + refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec extra 0#usize valid) fun src eq => ?_ + have hs := eq ▸ List.getElem_mem valid + simp only [obj.Slot.is_null, bind_ok] + split + · stalledTy + rename_i hne + have hn : src ≠ 0#u64 := by simpa using hne + have hsrc := P.ext src hs hn + rw [capA_eq, bind_ok] + have hw : CapRt.EncWf (capA st s1 src) := CapRt.decodeF_encWf _ _ + generalize hc : capA st s1 src = c at hw + cases c <;> try stalledTy + rename_i p l m asid va + dsimp only + split + swap + · stalledTy + split + swap + · stalledTy + rename_i hm + subst hm + rw [show ∀ l', objects.derive_cap st s1 src (.Ept p l' true asid va) = + ok (.Ok (.Ept p l' true asid va)) by intro l'; simp [objects.derive_cap]] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + have q := h1.bxi.1.choose_spec.choose_spec + refine WP.spec_bind (WP.spec_and (WP.spec_and (tcb.restart_caller.delR I D P B Y h1 d1 ds1 vk1) + (tcb.restart_caller.sts (q.nodes _ q.cur) (q.tcbs _ q.curT))) (tcb.restart_caller.armVsK I D P B h1 d1 ds1)) + fun s2 ⟨⟨d, w⟩, kept, os⟩ => ?_ + have keep := stt_osk P.os q q.curT w + have p2 := keepΦ s s2 hΦ rfl d.2.jv.ksb (kept.2 Ub Pt I.del.vr I.fu) os + rw [tcb_slot_val, bind_ok] + have hi : layout.tcb.SLOT_EPT.val < 7 := by simp [layout.tcb.SLOT_EPT] + have hy := d.2.slot I ht hi + have hE : slotIdx t layout.tcb.SLOT_EPT ∈ EptS H.tcbs := ⟨t, ht, by simp [layout.tcb.SLOT_EPT]⟩ + have apart : src ≠ slotIdx t layout.tcb.SLOT_EPT := fun eq => hXE src hs hn (eq ▸ hE) + have old : capA st _ (slotIdx t layout.tcb.SLOT_EPT) = .Null ∨ K (capA st _ (slotIdx t layout.tcb.SLOT_EPT)) := + (d.2.sys.ep _ hy.1 hE).imp id fun ⟨p', l', m', a', v', e⟩ => + e ▸ I.s2 _ (Or.inr (Or.inl ⟨p', l', m', a', v', rfl⟩)) + refine WP.spec_bind (WP.spec_and (WP.spec_and (WP.spec_and (cdt.delete.delR I d.2 hy) + (cdt.delete.capK I d.2 hy.1 old)) (cdt.delete.nullR I d.2 hy)) (deleteΦ _ _ _ p2 d.2 hy)) ?_ + rintro ⟨r, s3, _⟩ ⟨⟨⟨R2, k2⟩, n2⟩, p3⟩ + try simp only [uncurry_apply_pair] at R2 k2 n2 p3 ⊢ + cases r with + | Err _ => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, bind_tc_ok] + exact (WP.spec_ok _).2 ⟨R2.ty, p3⟩ + | Ok v => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + have source := (k2 src hsrc apart).trans ((keep.capA hsrc).trans hc) + unfold cdt.insert + rw [capA_eq, bind_ok, source] + have empty : capA st s3 (slotIdx t layout.tcb.SLOT_EPT) = .Null := + okinj ((capA_eq s3 _).symm.trans (n2 v rfl)) + refine WP.spec_bind (WP.spec_and (cdt.insert_with_cap.s1aTy I R2.ty R2.sys.sys.stz.1.1.mdbS hsrc hy.1 apart + (I.del.dcan _ hy) source (fun e => by cases e) hw) + (insertΦ s3 _ _ _ p3 R2 hsrc hy.1 apart (I.del.dcan _ hy) source hw empty ⟨_, _, _, _, rfl⟩)) + fun _ h => ?_ + exact (WP.spec_ok _).2 h + +set_option maxHeartbeats 3000000 in +/-- SetEPTRoot retains the typing through its explicit deletion and CTE insertion. -/ +theorem tcb.decode.setEpt_s1aTy (hA : P0.ArchTotal ar) {s : S} {a : A} {t len buf : U64} {call : Bool} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (hXE : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∉ EptS H.tcbs) : + tcb.decode st ar s a fl4_abi.label.TCBSetEPTRoot t { length := len, buf, call, slot, extra } ⦃ r => Ty r.2.1 ⦄ := + WP.spec_mono (tcb.decode.setEpt_s1aPhi hA I D P B Y hXE (Φ := fun _ => True) True.intro + (fun _ _ _ _ _ _ _ => True.intro) + (fun q a x _ R hx => WP.spec_mono (cdt.delete.delR I R hx) fun _ _ => True.intro) + (fun q src dest nc _ R hs hd ne can eq wf _ ept => by + obtain ⟨p, l, m, v, rfl⟩ := ept + exact WP.spec_mono (cdt.insert_with_cap.s1aTy I R.ty R.sys.sys.stz.1.1.mdbS hs hd ne can eq + (fun e => by cases e) wf) fun _ _ => True.intro)) fun _ h => h.1 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiDispatch.lean b/proofs/Fl4ProofsA64/P1/S1aHiDispatch.lean new file mode 100644 index 000000000..b0517bf0b --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiDispatch.lean @@ -0,0 +1,120 @@ +/- +A64-S1A gen 41: dispatcher coverage for the reserved HighVSpace word. +The deletion and VSpace cases use the shared typing witness HiDelTy. +Named premises: none new. +-/ +import Fl4ProofsA64.P1.S1aHiK +import Fl4ProofsA64.P1.S1aHiDelDec +import Fl4ProofsA64.P1.S1aHiVs + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Pt U Ac : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {lbl : U64} + +set_option maxHeartbeats 2000000 in +/-- The keeping arms of the smaller dispatcher, including the non-deleting CNode operations. -/ +theorem syscall.decode_invocation.armKQ2_hi (hA : P0.ArchTotal ar) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (Hv : HvPt st Pt OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (a : A) (hc : DecArmKQ2 cap lbl) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => + HiCap511 st OS s → HiCap511 st OS s' ⦄ := by + by_cases h : capFam cap = .cnode ∧ (lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ + lbl = fl4_abi.label.CNodeMove ∨ lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) + · exact WP.spec_mono (syscall.decode_invocation.cnode_armQIKAt D P B Y I.del.vr a len blk call don fp buf h.2 h.1 hcap) + fun _ d => HiCap511.ofK I Hv d.1 d.2.2 + · exact WP.spec_mono (syscall.decode_invocation.armKKAt hA I D P B Y hcap hks a ⟨hc, h⟩ len blk call don fp buf) + fun _ d => HiCap511.ofK I Hv d.1 d.2.2.2 + +/-- The smaller S1A dispatcher uses the typed deletion family and the exact keeping family. -/ +theorem syscall.decode_invocation.armQZ2_hi {Pp Tb Hr Te : Set U64} {Lv Re bits : U64 → Nat} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (Hv : HvPt st Pt OS s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (a : A) (hc : DecArmQZ2 cap lbl) + (hIq : ∀ i, cap = .IrqHandler i → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → i.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (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 ⦃ r s' _ => + HiCap511 st OS s → HiCap511 st OS s' ⦄ := by + rcases hc with hd | hk + · exact syscall.decode_invocation.delOnly_hi hA hPl I W hPI D P B Y hcap a hd hIq hSC len blk call don fp buf + · exact syscall.decode_invocation.armKQ2_hi hA I Hv D P B Y hcap hks a hk len blk call don fp buf + +local macro "selectKeepingArm" n:num h:term : tactic => `(tactic| ( + unfold DecArmQHK + iterate $n:num + right + exact Or.inl $h)) + +private theorem splitHighArms (hc : DecArmQH cap lbl) : + (DecArmDelQ cap lbl ∨ (∃ t, cap = .Thread t ∧ lbl = fl4_abi.label.TCBSetSchedParams)) ∨ + DecArmKQ3 cap lbl ∨ DecArmQHK cap lbl ∨ DecArmQHV cap lbl := by + rcases hc with (hd | hk) | hs | hi | hn | he | ht | hr | hv1 | hv2 | hv3 | hv4 | hv5 | hpm | hf | hp | ha | + ⟨p, z, rg, d, m, e, asid, va, eq, hu⟩ | ⟨p, z, rg, d, m, e, asid, va, eq, htc⟩ | + ⟨p, z, rg, d, m, e, asid, va, eq, hm⟩ | ⟨p, m, asid, va, eq, hm⟩ | ⟨p, m, asid, va, eq, hu⟩ | hep + · exact Or.inl (Or.inl hd) + · exact Or.inr (Or.inl hk) + · exact Or.inl (Or.inr hs) + · exact Or.inr (Or.inr (Or.inl (Or.inl hi))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 1 hn))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 2 he))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 3 ht))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 4 hr))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 5 hv1))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 6 hv2))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 7 hv3))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 8 hv4))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 9 hv5))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 10 hpm))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 11 hf))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 12 hp))) + · exact Or.inr (Or.inr (Or.inl (by selectKeepingArm 13 ha))) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨p, z, rg, d, m, e, asid, va, eq, Or.inl hu⟩))) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨p, z, rg, d, m, e, asid, va, eq, Or.inr (Or.inl htc)⟩))) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨p, z, rg, d, m, e, asid, va, eq, Or.inr (Or.inr hm)⟩))) + · exact Or.inr (Or.inr (Or.inr (Or.inr ⟨p, m, asid, va, eq, Or.inl hm⟩))) + · exact Or.inr (Or.inr (Or.inr (Or.inr ⟨p, m, asid, va, eq, Or.inr hu⟩))) + · refine Or.inr (Or.inr (Or.inl ?_)) + unfold DecArmQHK + iterate 14 + right + exact hep + +set_option maxHeartbeats 2000000 in +/-- Every covered AArch64 decode preserves the reserved word on every returned HighVSpace cap. -/ +theorem syscall.decode_invocation.armQH_hi {Pp Tb Hr Te : Set U64} {Lv Re bits : U64 → Nat} + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (Hv : HvPt st Pt OS s) (Cp : PtHG H Pt) + (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (Hy : ArmDecHyps st H Pt hPl.ipa s cap) (a : A) (hc : DecArmQH cap lbl) + (hIq : ∀ i, cap = .IrqHandler i → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → i.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (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 ⦃ r s' _ => + HiCap511 st OS s → HiCap511 st OS s' ⦄ := by + rcases splitHighArms hc with hd | (hk | hp) | hh | hw + · exact syscall.decode_invocation.armDel_hi hA hPl I W hPI D P B Y hcap hks Hy a hd hIq hSC + len blk call don fp buf + · exact syscall.decode_invocation.armKQ2_hi hA I Hv D P B Y hcap hks a hk len blk call don fp buf + · exact syscall.decode_invocation.armKK3_hi hA I Hv D P B Y hcap hks Hy.mcp Hy.cs a (Or.inr hp) + len blk call don fp buf + · exact syscall.decode_invocation.armQHK_hi hA hM I Hv D P B Y hcap hks a hh len blk call don fp buf + · exact syscall.decode_invocation.armVs_hi hA hPl I D P B Y Hy W Cp hcap a hw len blk call don fp buf + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiInit.lean b/proofs/Fl4ProofsA64/P1/S1aHiInit.lean new file mode 100644 index 000000000..faa079a62 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiInit.lean @@ -0,0 +1,95 @@ +/- +P1 (aarch64, A64-S1A gen 41): a fresh HighVSpace root has a valid table +descriptor at entry 511. The preceding loop copies only entries below 511. +-/ +import Fl4ProofsA64.P1.MdbVUC + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + +/-- Setting the valid and table bits establishes the reserved descriptor's tag. -/ +private theorem highDescTag (v : U64) : ((v ||| 1#u64 ||| 2#u64) &&& 3#u64) = 3#u64 := by + rw [UScalar.eq_equiv_bv_eq] + simp only [UScalar.bv_and, UScalar.bv_or] + rw [BitVec.or_assoc] + change (v.bv ||| 3#64) &&& 3#64 = 3#64 + apply BitVec.eq_of_getLsbD_eq + intro i + simp [BitVec.getLsbD_and, BitVec.getLsbD_or] + exact fun _ h => Or.inr h + +set_option maxHeartbeats 2000000 in +/-- The final write of the initializer sets both descriptor tag bits in entry 511. -/ +theorem vspace.init_high_vspace.hiTag (hA : P0.ArchTotal ar) (s : S) (a : A) {b : U64} + (hal : b.val % 8 = 0) (hf : b.val + 4096 ≤ 2 ^ 64) : + vspace.init_high_vspace st ar s a b ⦃ r => L.mem r.1 (wa b 4088#u64) &&& 3#u64 = 3#u64 ⦄ := by + unfold vspace.init_high_vspace + simp only [lift, bind_ok] + refine WP.spec_bind (vspace.init_high_vspace_loop.win hA s a hal hf) fun s1 _ => ?_ + have h511 : vspace.HIGH_L0_INDEX.val = 511 := by simp [vspace.HIGH_L0_INDEX] + obtain ⟨idx, hi, hv⟩ := spec_exA (U64.mul_spec (x := vspace.HIGH_L0_INDEX) (y := 8#u64) + (by rw [h511]; scalar_tac)) + have hidx : idx = 4088#u64 := UScalar.eq_of_val_eq (by simp only [hv, h511]; decide) + rw [hi, hidx, bind_ok] + try simp only [lift, bind_ok] + refine WP.spec_bind (P0.layout.paddr.p0 _) fun addr _ => ?_ + rw [eq_of_spec_fd P0.Consts.vspace.D_PXN_TABLE.spec, bind_ok, + 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] + refine WP.spec_bind (LawfulStore.write_spec s1 _ _) fun s2 e => ?_ + subst e + have ha : Aligned (wa b 4088#u64) := by + unfold Aligned + have h88 : (4088#u64 : U64).val = 4088 := rfl + rw [wadd_val (by rw [h88]; omega), h88] + omega + exact (WP.spec_ok _).2 (by rw [L.mem_wr_same ha]; exact highDescTag _) + +set_option maxHeartbeats 2000000 in +/-- The type-14 object creation has the initialized reserved entry. -/ +theorem create_object.highInit (hA : P0.ArchTotal ar) (s : S) (a : A) (nt b us : U64) + (hn : nt.val = 14) (hal : b.val % 8 = 0) (hf : b.val + 4096 ≤ 2 ^ 64) : + objects.create_object st ar s a nt b us false ⦃ r => L.mem r.2.1 (wa b 4088#u64) &&& 3#u64 = 3#u64 ⦄ := by + obtain rfl : nt = 14#u64 := UScalar.eq_of_val_eq (by simp [hn]) + unfold objects.create_object objects.create_arch_object + simp (config := { decide := true }) only [fl4_abi.consts.object.Tcb, fl4_abi.consts.object.Endpoint, + fl4_abi.consts.object.Notification, fl4_abi.consts.object.CapTable, fl4_abi.consts.object.Untyped, + fl4_abi.consts.object.SchedContext, fl4_abi.consts.object.Reply, fl4_abi.consts.object.ArmPageTable, + fl4_abi.consts.object.ArmVSpace, fl4_abi.consts.object.ArmVcpu, fl4_abi.consts.object.ArmStage2VSpace, + fl4_abi.consts.object.ArmHighVSpace, ↓reduceIte, ite_true, ite_false] + refine WP.spec_bind (vspace.init_high_vspace.hiTag hA s a hal hf) ?_ + rintro ⟨s1, a1⟩ h + exact (WP.spec_ok _).2 h + +/-- The initialized root descriptors of the first `j` objects in a type-14 window. -/ +def WinHi (st : machine.Store S) [L : LawfulStore st] (s : S) (base nt us : U64) (j : Nat) : Prop := + nt.val = 14 → ∀ i < j, L.mem s (wa (bjA base (zA nt.val us) i) 4088#u64) &&& 3#u64 = 3#u64 + +/-- The reserved word is aligned and lies inside the corresponding 8 KiB object. -/ +theorem WinHi.addr {base nt us : U64} {j count : Nat} (hn : nt.val = 14) (hj : j < count) + (ha : base.val % 8 = 0) (hf : base.val + count * 2 ^ (zA nt.val us).val ≤ 2 ^ 64) : + (bjA base (zA nt.val us) j).val = base.val + j * 8192 ∧ + (bjA base (zA nt.val us) j).val + 8192 ≤ 2 ^ 64 ∧ + (bjA base (zA nt.val us) j).val % 8 = 0 ∧ + (wa (bjA base (zA nt.val us) j) 4088#u64).val = base.val + j * 8192 + 4088 ∧ + Aligned (wa (bjA base (zA nt.val us) j) 4088#u64) := by + have hz : (zA nt.val us).val = 13 := by rw [hn]; exact zA_14 us + obtain ⟨hv, h8, hout⟩ := bj_win (z := zA nt.val us) hj hf ha (by omega) + have pow : (2 : Nat) ^ (zA nt.val us).val = 8192 := by rw [hz]; decide + rw [pow] at hv hout hf + have h88 : (4088#u64 : U64).val = 4088 := rfl + have hfit : (bjA base (zA nt.val us) j).val + 8192 ≤ 2 ^ 64 := by rw [hv]; omega + have haddr : (wa (bjA base (zA nt.val us) j) 4088#u64).val = base.val + j * 8192 + 4088 := by + rw [wadd_val (by rw [h88]; omega), hv, h88] + refine ⟨hv, hfit, h8, haddr, ?_⟩ + unfold Aligned + rw [haddr] + omega + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiK.lean b/proofs/Fl4ProofsA64/P1/S1aHiK.lean new file mode 100644 index 000000000..2152f6a65 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiK.lean @@ -0,0 +1,153 @@ +/- +P1 (aarch64, A64-S1A gen 40, Architect ruling for gen 40 step 1): **R3's `HiCap511` across the non-VSpace +non-deleting arms that keep the `OS` words** (`DecArmKK3`: S1aArmZ2's `DecArmKK` and TCB SetPriority). + +* a64's `…_armQIKAt` tops (MdbArmDf, MdbArmDfB, MdbArmDm, MdbMcpArm, MdbPrioArm) and `cnode_armQIKAt` (MdbCnArmQ) + export the `ArmVsK` they build as their last conjunct (ruled in place, gen 40); S1aArmZ2's `armKKAt` passes it on. +* **`HiCap511.ofK`**: an `ArmQIAt` step whose memory is an `ArmVsK` step keeps `HiCap511`, at S1A's own placement + (`DelIn.del.vr`, `DelIn.fu`) with S1aHvPt's `HvPt` (`HvPt.rt`: every `HighVSpace` root in `Pt`); S1aHiCap's + `HiCap511.ofArmVsK`. +* **`syscall.decode_invocation.armKK3At`**: every `DecArmKK3` arm to `ArmQIAt ∧ TabKeep ∧ OSKeep ∧ ArmVsK` + (`armKKAt`; SetPriority by a64's `prio_armQIKAt`); **`syscall.decode_invocation.armKK3_hi`**: on the same arms, + `HiCap511` kept. +* **`DecArmQHK`**: the `DecArmQH` arms outside `DecArmKK3` that neither delete nor edit a VSpace — IRQ control (gen 41), Notification / + Endpoint send, TCB Suspend / ReadRegisters, VCPU Run / AckVPPI / WriteReg / InjectIRQ / ReadState / WriteState / + SetTCB, the cache arms (`Pml4`, page flushes, `PageDirectory` / `Pdpt`, `Ept`) and Page GetAddress; a64's tops + (`ntfn_armQIAt` … `ept_armQIAt`) now export `ArmVsK` (the TCB arms through MdbHiVsArm's new + `tcb.restart_caller.armVsK`, the VCPU arms through MdbRunF's `ofRunBK`). **`syscall.decode_invocation.armQHK_hi`**: + `HiCap511` kept on them. + +Named premises: none. Case facts: none new (`hmcp` / `hcs` are `ArmDecHyps.mcp` / `.cs`, as `armKQ3At`). +-/ +import Fl4ProofsA64.P1.S1aArmZ2 +import Fl4ProofsA64.P1.MdbArmQHD +import Fl4ProofsA64.P1.S1aHvPt +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} {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} {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} + {Ty : S → Prop} + +/-- **`DecArmKK` and TCB SetPriority** (module docstring). -/ +def DecArmKK3 (cap : capability.Cap) (lbl : U64) : Prop := + DecArmKK cap lbl ∨ ∃ t, cap = .Thread t ∧ lbl = fl4_abi.label.TCBSetPriority + +/-- **An `ArmQIAt` step with an `ArmVsK` memory keeps `HiCap511`** (module docstring). -/ +theorem HiCap511.ofK {s s' : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (Hv : HvPt st Pt OS s) + (h : ArmQIAt st H Cs OS Vc ia ie s s') (hK : ArmVsK st H OS Vc s s') (h0 : HiCap511 st OS s) : + HiCap511 st OS s' := + HiCap511.ofArmVsK h hK I.del.vr I.fu Hv.rt h0 + +/-- **Every `DecArmKK3` arm to `ArmQIAt ∧ TabKeep ∧ OSKeep ∧ ArmVsK`** (module docstring). -/ +theorem syscall.decode_invocation.armKK3At (hA : P0.ArchTotal ar) {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) (hks : HeapKsOff H (L.ksb s)) + (hmcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (hcs : L.mem s (scA (L.curW s)) ≠ 0#u64) (a : A) + {lbl : U64} (hc : DecArmKK3 cap lbl) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeep st s s' ∧ OSKeep st OS s s' ∧ ArmVsK st H OS Vc s s' ⦄ := by + rcases hc with hc | ⟨t, rfl, hl⟩ + · exact syscall.decode_invocation.armKKAt hA I D P B Y hcap hks a hc len blk call don fp buf + · exact syscall.decode_invocation.prio_armQIKAt hA D P B Y I.del.vr hks I.del.sca hcap hmcp hcs a hl len blk call + don fp buf + +/-- **`HiCap511` kept on every `DecArmKK3` arm** (module docstring). -/ +theorem syscall.decode_invocation.armKK3_hi (hA : P0.ArchTotal ar) {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) + (Hv : HvPt st Pt OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (hmcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (hcs : L.mem s (scA (L.curW s)) ≠ 0#u64) (a : A) + {lbl : U64} (hc : DecArmKK3 cap lbl) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => + HiCap511 st OS s → HiCap511 st OS s' ⦄ := + WP.spec_mono (syscall.decode_invocation.armKK3At (ia := ia) (ie := ie) hA I D P B Y hcap hks hmcp hcs a hc len blk + call don fp buf) fun _ d => HiCap511.ofK I Hv d.1 d.2.2.2 + +/-- **The `DecArmQH` arms outside `DecArmKK3` whose a64 tops export `ArmVsK`** (module docstring). -/ +def DecArmQHK (cap : capability.Cap) (lbl : U64) : Prop := + cap = .IrqControl ∨ (∃ n b sd rv, cap = .Notification n b sd rv) ∨ (∃ e b sd rv g gr, cap = .Endpoint e b sd rv g gr) ∨ + (∃ t, cap = .Thread t ∧ lbl = fl4_abi.label.TCBSuspend) ∨ + (∃ t, cap = .Thread t ∧ lbl = fl4_abi.label.TCBReadRegisters) ∨ + (∃ v, cap = .Vcpu v ∧ lbl = fl4_abi.label.ARMVCPURun) ∨ + (∃ v, cap = .Vcpu v ∧ lbl = fl4_abi.label.ARMVCPUAckVPPI) ∨ + (∃ v, cap = .Vcpu v ∧ (lbl = fl4_abi.label.ARMVCPUWriteReg ∨ lbl = fl4_abi.label.ARMVCPUInjectIRQ)) ∨ + (∃ v, cap = .Vcpu v ∧ (lbl = fl4_abi.label.ARMVCPUReadState ∨ lbl = fl4_abi.label.ARMVCPUWriteState)) ∨ + (∃ v, cap = .Vcpu v ∧ lbl = fl4_abi.label.ARMVCPUSetTCB) ∨ + (∃ p m x, cap = .Pml4 p m x) ∨ + (∃ fp fsz fr fd fm fe fa fv, cap = .Frame fp fsz fr fd fm fe fa fv ∧ + (lbl = fl4_abi.label.ARMPageClean_Data ∨ lbl = fl4_abi.label.ARMPageInvalidate_Data ∨ + lbl = fl4_abi.label.ARMPageCleanInvalidate_Data ∨ lbl = fl4_abi.label.ARMPageUnify_Instruction)) ∨ + ((∃ p m x v, cap = .PageDirectory p m x v) ∨ (∃ p m x v, cap = .Pdpt p m x v)) ∨ + (∃ fp fsz fr fd fm fe fa fv, cap = .Frame fp fsz fr fd fm fe fa fv ∧ lbl = fl4_abi.label.ARMPageGetAddress) ∨ + (∃ p l m a v, cap = .Ept p l m a v) + +/-- **`HiCap511` kept on every `DecArmQHK` arm** (module docstring; a64's per-arm tops with their exported +`ArmVsK`). -/ +theorem syscall.decode_invocation.armQHK_hi (hA : P0.ArchTotal ar) (hM : MaxSpi ar) {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) + (Hv : HvPt st Pt OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) + {lbl : U64} (hc : DecArmQHK cap lbl) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => + HiCap511 st OS s → HiCap511 st OS s' ⦄ := by + have Q : ∀ {s' : S}, ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' → + HiCap511 st OS s → HiCap511 st OS s' := fun d => HiCap511.ofK I Hv d.1 d.2.2 + rcases hc with rfl | ⟨n, b, sd, rv, rfl⟩ | ⟨e, b, sd, rv, g, gr, rfl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨v, rfl, hl⟩ | + ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨p, m, x, rfl⟩ | + ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | hc | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | + ⟨p, l, m, x, v, rfl⟩ + · exact WP.spec_mono (syscall.decode_invocation.irqCtl_armQIAt hA hM I D P B Y hcap a lbl len blk call don fp buf) + fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.ntfn_armQIAt hA I D P B Y hks hcap a lbl len blk call don fp + buf) fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.ep_armQIAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.suspend_armQIAt hA I D P B Y hks hcap a hl len blk call don fp + buf) fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.readRegs_armQIAt hA I D P B Y hks hcap a hl len blk call don fp + buf) fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.run_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.ackVppi_armQIAt hA I D P B Y hks hcap a hl len blk call don fp + buf) fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.vcWr_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.vcSt_armQIAt hA I D P B Y hks hcap a hl len blk call don fp buf) + fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.setTcb_armQIAt hA I D P B Y hks hcap a hl len blk call don fp + buf) fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.vsFl_armQIAt hA I D P B Y hks a lbl len blk call don fp buf) + fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.pgFl_armQIAt hA I D P B Y hks a hl len blk call don fp buf) + fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.pdInv_armQIAt D B Y a hc lbl len blk call don fp buf) + fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.getAddr_armQIAt I D P B Y hks a hl len blk call don fp buf) + fun _ d => Q d + · exact WP.spec_mono (syscall.decode_invocation.ept_armQIAt hA I D P B Y hks a lbl len blk call don fp buf) + fun _ d => Q d + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aHiMap.lean b/proofs/Fl4ProofsA64/P1/S1aHiMap.lean new file mode 100644 index 000000000..95c5a0414 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiMap.lean @@ -0,0 +1,314 @@ +/- +P1 (aarch64, A64-S1A gen 41): frame and table maps preserve the +HighVSpace root's reserved word. Leaf walks select a lower Stage-1 +level or a Stage-2 object. Table maps require an invalid slot. +-/ +import Fl4ProofsA64.P1.S1aHiVsW + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {s : S} + {Cs OS Vc Ub Pt Pp Tb Hr Te Ac U : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {cap : capability.Cap} {slot : U64} + +theorem HiDelTy.restartCap (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (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) + (hx : slot ∈ OS) : + sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ q => ∀ c, + obj.Slot.set_cap st slot q c ⦃ q' => HrW st Hr s q' ⦄ ⦄ := + WP.spec_mono (sched.set_thread_state.unmMid I D) fun _ h c => + WP.spec_mono (W.keepSlot I hx c) fun _ keep R hR => (keep R hR).trans (W.keepWord h.2 R hR) + +set_option hygiene false in +local macro "hiError" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 (fun _ _ => rfl) + | (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, lift, + error.illegal, error.truncated, error.range, error.invalid_cap, error.invalid_arg, vspace.failed_lookup] + first | exact (WP.spec_ok _).2 (fun _ _ => rfl) | exact fun _ _ => rfl)) + +set_option hygiene false in +local macro "restartMap" : tactic => `(tactic| ( + refine WP.spec_bind (W.restartCap I D hx) fun q hq => ?_ + refine WP.spec_bind (hq _) fun q' keep => ?_)) + +set_option hygiene false in +local macro "tableWrite" : tactic => `(tactic| ( + try simp only [lift, bind_ok] + refine WP.spec_bind (shl_and63u _) fun _ _ => ?_ + try simp only [lift, bind_ok] + restartMap + refine WP.spec_bind (P0.layout.paddr.p0 _) fun pa _ => ?_ + refine WP.spec_bind (by first | exact P0.vspace.make_user_table.p0 pa | exact P0.ept.make_s2_table.p0 pa) + fun desc _ => ?_ + refine WP.spec_bind (LawfulStore.write_spec q' lu.slot desc) fun q'' e => ?_ + subst e + have hword : Aligned lu.slot := I.del.vr.al _ (Or.inl hslot) + have keep' := W.keepWrite I (writesIn_wr (s := q') (v := desc) hword) (fun R hR e => hoff R hR e.symm) + exact (WP.spec_ok _).2 fun R hR => (keep' R hR).trans (keep R hR))) + +set_option maxHeartbeats 2000000 in +theorem ept.map_table.keepHr {hPl : ArchPlat ar} + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (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) + (hx : slot ∈ OS) {root : U64} (hroot : root ∈ Te) (hdepth : Re root + 1 = s2lv hPl.ipa) + (hspan : s2rb hPl.ipa ≤ bits root) (a : A) (asid ipa ptr : U64) : + ept.map_table st ar s a root asid ipa ptr slot ⦃ r => HrW st Hr s r.2.1 ⦄ := by + unfold ept.map_table + rw [hPl.ipa_eq a, bind_ok] + refine WP.spec_bind (P0.ept.ipa_limit.p0 _) fun limit _ => ?_ + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine WP.spec_bind (ept.lookup_slot.ty W.ty.2 W.stage2 hroot hdepth hspan ipa) fun lu hlu => ?_ + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine WP.spec_bind (LawfulStore.read_spec s lu.slot) fun e _ => ?_ + refine WP.spec_bind P0.ept.D_VALID.p0 fun valid _ => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + rw [cur_thread_ok] + have hslot := ptw_mono W.granules (ptwb_gran W.stage2.sz hlu) + have hoff := W.stage2.hr _ hlu + tableWrite + +set_option hygiene false in +local macro "s1Table" : tactic => `(tactic| ( + refine WP.spec_bind (vspace.lookup_pt_slot.ty W.ty.1 hrT hr0 _) fun lu hlu => ?_ + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + rw [L.read_eq, bind_ok, eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, bind_ok] + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by hiError) (fun invalid => ?_) + have hslot := ptw_mono W.tables hlu + have hoff := W.keepInvalid (b := lu.slot) (UScalar.eq_of_val_eq (by simpa using invalid)) + tableWrite)) + +set_option maxHeartbeats 2000000 in +theorem vspace.map_high_page_table.keepHr + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (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) + (hx : slot ∈ OS) (ptr : U64) (vcap : capability.Cap) (vaddr : U64) : + vspace.map_high_page_table st s slot ptr vcap vaddr ⦃ r => HrW st Hr s r.2 ⦄ := by + unfold vspace.map_high_page_table + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (vspace.check_high_vspace.ty W.ty.1 rfl vcap 1#u64) fun r found => ?_ + rcases r with ⟨root, asid⟩ | e + · obtain ⟨hrT, hr0⟩ := found _ rfl + simp only [irq_branch_ok, bind_ok, lift] + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine WP.spec_bind (vspace.lookup_pt_slot.ty W.ty.1 hrT hr0 _) fun lu hlu => ?_ + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + rw [L.read_eq, bind_ok, eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, bind_ok] + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by hiError) (fun invalid => ?_) + have hslot := ptw_mono W.tables hlu + have hoff := W.keepInvalid (b := lu.slot) (UScalar.eq_of_val_eq (by simpa using invalid)) + tableWrite + · hiError + +set_option maxHeartbeats 4000000 in +theorem vspace.decode_page_table.mapHr {hPl : ArchPlat ar} + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (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) + (hx : slot ∈ OS) (a : A) (len buf ptr ad va : U64) (mapped : Bool) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableMap len slot + (.PageTable ptr mapped ad va) buf extra ⦃ r => HrW st Hr s r.2.1 ⦄ := by + have hne : fl4_abi.label.ARMPageTableMap ≠ fl4_abi.label.ARMPageTableUnmap := lbl_ne_of_val + (by simp [fl4_abi.label.ARMPageTableMap, fl4_abi.label.ARMPageTableUnmap]) + unfold vspace.decode_page_table + rw [cur_thread_ok, bind_ok] + dsimp only + have hsame : (fl4_abi.label.ARMPageTableMap != fl4_abi.label.ARMPageTableMap) = false := by simp + simp only [hne, hsame, Bool.false_eq_true, ↓reduceIte] + refine WP.spec_bind (P0.vspace.extra.p0 extra 0#usize) fun x _ => ?_ + rcases x with _ | x + · hiError + try dsimp only + refine spec_ite (fun _ => ?_) (fun _ => by hiError) + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun vaddr _ => ?_ + refine WP.spec_bind (P0.obj.Slot.cap.p0 st x s L.total) fun vcap _ => ?_ + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun high _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine WP.spec_bind (vspace.map_high_page_table.keepHr W I D hx ptr vcap vaddr) ?_ + rintro ⟨r, q⟩ keep + exact (WP.spec_ok _).2 keep + refine WP.spec_bind (P0.vspace.is_valid_vtable_root.p0 vcap) fun valid _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => by hiError) + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun stage2 _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine WP.spec_bind (ept.root.ty W.ty.1 W.ty.2 rfl vcap 1#u64) fun r found => ?_ + rcases r with ⟨root, asid⟩ | e + · obtain ⟨hr, hd, hs⟩ := found _ rfl + simp only [irq_branch_ok, bind_ok] + exact ept.map_table.keepHr W I D hx hr hd hs a asid vaddr ptr + · hiError + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine WP.spec_bind (vspace.check_vspace.ty W.ty.1 rfl vcap 1#u64) fun r found => ?_ + rcases r with ⟨root, asid⟩ | e + · obtain ⟨hrT, hr0⟩ := found _ rfl + simp only [irq_branch_ok, bind_ok] + s1Table + · hiError + +set_option hygiene false in +local macro "s1Leaf" : tactic => `(tactic| ( + refine WP.spec_bind (vspace.lookup_pt_slot.lv W.ty.1 hrT hr0 _) fun lu ⟨p, hp, o, ho, h8, he, hlev⟩ => ?_ + refine spec_ite (fun _ => by hiError) (fun hshift => ?_) + have heq : lu.shift = shift := UScalar.eq_of_val_eq (by simpa using hshift) + have hlo : 0 < Lv p := by rw [heq] at hlev; omega + have hoff : ∀ R ∈ Hr, lu.slot ≠ wa R 4088#u64 := he ▸ W.keepStage1Leaf hp ho h8 hlo + have hal := I.del.vr.al _ (Or.inl (ptw_mono W.tables ⟨p, hp, o, ho, h8, he⟩)) + refine WP.spec_bind (P0.vspace.rights_readable.p0 _) fun cr _ => ?_ + refine WP.spec_bind (P0.layout.paddr.p0 _) fun pa _ => ?_ + refine WP.spec_bind (P0.vspace.make_user_page.p0 pa _ cr _ shift) fun e _ => ?_ + restartMap + refine WP.spec_bind (vspace.install_page.slotE hA hal q' a e _ _ _ _ _ _) ?_ + rintro ⟨q'', a'⟩ h + have keep' := W.keepWrite I h.1 (fun R hR e => hoff R hR e.symm) + exact (WP.spec_ok _).2 fun R hR => (keep' R hR).trans (keep R hR))) + +set_option hygiene false in +local macro "leafChecks" : tactic => `(tactic| ( + refine WP.spec_bind (vspace.page_shift.v _) fun shift hs => ?_ + refine WP.spec_bind (shl_and63u _) fun _ _ => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine spec_ite (fun _ => ?_) (fun _ => ?_))) + +set_option maxHeartbeats 3000000 in +theorem vspace.decode_high_page_map.keepHr (hA : P0.ArchTotal ar) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (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) + (hx : slot ∈ OS) (a : A) (f : vspace.FrameCap) (vcap : capability.Cap) (vaddr vm attr : U64) : + vspace.decode_high_page_map st ar s a slot f vcap vaddr vm attr ⦃ r => HrW st Hr s r.2.1 ⦄ := by + unfold vspace.decode_high_page_map + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (vspace.check_high_vspace.ty W.ty.1 rfl vcap 1#u64) fun r found => ?_ + rcases r with ⟨root, asid⟩ | e + swap + · hiError + obtain ⟨hrT, hr0⟩ := found _ rfl + simp only [irq_branch_ok, bind_ok, lift] + leafChecks + all_goals + try ( + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine spec_ite (fun _ => by hiError) (fun _ => ?_)) + refine WP.spec_bind (shl_and63u _) fun _ _ => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + s1Leaf + +set_option maxHeartbeats 4000000 in +theorem ept.map_frame.keepHr (hA : P0.ArchTotal ar) {hPl : ArchPlat ar} + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (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) + (hx : slot ∈ OS) {root : U64} (hr : root ∈ Te) (hd : Re root + 1 = s2lv hPl.ipa) + (hs : s2rb hPl.ipa ≤ bits root) (a : A) (asid ipa vm attr ptr : U64) + (size : capability.FrameSize) (rights : U64) (dev : Bool) (masid mva : U64) : + ept.map_frame st ar s a root asid ipa vm attr ptr size rights dev masid mva slot ⦃ r => HrW st Hr s r.2.1 ⦄ := by + unfold ept.map_frame + refine WP.spec_bind (P0.capability.FrameSize.bits.p0 size) fun shift _ => ?_ + rw [hPl.ipa_eq a, bind_ok] + try simp only [lift, bind_ok] + refine WP.spec_bind (shl_and63u _) fun _ _ => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine spec_ite (fun _ => ?_) (fun _ => ?_) + all_goals + repeat' (first + | (refine spec_ite (fun _ => by hiError) (fun _ => ?_)) + | (refine WP.spec_bind (shl_and63u _) fun _ _ => ?_) + | (refine WP.spec_bind (P0.ept.ipa_limit.p0 _) fun _ _ => ?_) + | (simp only [lift, bind_ok])) + refine WP.spec_bind (ept.lookup_slot.ty W.ty.2 W.stage2 hr hd hs ipa) fun lu hlu => ?_ + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine WP.spec_bind (P0.vspace.rights_readable.p0 rights) fun cr _ => ?_ + refine WP.spec_bind (P0.layout.paddr.p0 ptr) fun pa _ => ?_ + refine WP.spec_bind (P0.ept.make_s2_leaf.p0 pa vm cr attr shift) fun e _ => ?_ + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (W.restartCap I D hx) fun q hq => ?_ + repeat' (refine spec_ite (fun _ => ?_) (fun _ => ?_)) + all_goals + refine WP.spec_bind (hq _) fun q' keep => ?_ + have hal := I.del.vr.al _ (Or.inl (ptw_mono W.granules (ptwb_gran W.stage2.sz hlu))) + refine WP.spec_bind (ept.install_s2_leaf.slotE hA hal q' a e root asid ipa ptr dev attr) ?_ + rintro ⟨q'', a'⟩ h + have keep' := W.keepWrite I h.1 (fun R hR e => W.stage2.hr _ hlu R hR e.symm) + exact (WP.spec_ok _).2 fun R hR => (keep' R hR).trans (keep R hR) + +set_option hygiene false in +local macro "s1Page" : tactic => `(tactic| ( + refine WP.spec_bind (vspace.check_vspace.ty W.ty.1 rfl vcap 1#u64) fun r found => ?_ + rcases r with ⟨root, asid⟩ | e + swap + · hiError + obtain ⟨hrT, hr0⟩ := found _ rfl + simp only [irq_branch_ok, bind_ok, lift] + leafChecks + · refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + s1Leaf + · refine WP.spec_bind (shl_and63u _) fun _ _ => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine spec_ite (fun _ => by hiError) (fun _ => ?_) + s1Leaf)) + +set_option maxHeartbeats 4000000 in +theorem vspace.decode_page_map.keepHr (hA : P0.ArchTotal ar) {hPl : ArchPlat ar} + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (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) + (hx : slot ∈ OS) (a : A) (len buf : U64) (f : vspace.FrameCap) : + vspace.decode_page_map st ar s a len slot f buf extra ⦃ r => HrW st Hr s r.2.1 ⦄ := by + unfold vspace.decode_page_map + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (P0.vspace.extra.p0 extra 0#usize) fun x _ => ?_ + rcases x with _ | x + · hiError + refine spec_ite (fun _ => ?_) (fun _ => by hiError) + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun vaddr _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun mask _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun attr _ => ?_ + refine WP.spec_bind (P0.capability.Rights.from_word.p0 mask) fun rights _ => ?_ + refine WP.spec_bind (P0.capability.mask_vm_rights.p0 f.rights rights) fun vm _ => ?_ + refine WP.spec_bind (P0.obj.Slot.cap.p0 st x s L.total) fun vcap _ => ?_ + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun stage2 _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine WP.spec_bind (ept.root.ty W.ty.1 W.ty.2 rfl vcap 1#u64) fun r found => ?_ + rcases r with ⟨root, asid⟩ | e + · obtain ⟨hr, hd, hs⟩ := found _ rfl + simp only [irq_branch_ok, bind_ok] + try dsimp only + have tail := ept.map_frame.keepHr hA W I D hx hr hd hs a asid vaddr vm attr f.ptr f.size f.rights f.is_device + f.asid f.vaddr + refine spec_ite (fun _ => ?_) (fun _ => tail) + refine spec_ite (fun _ => tail) (fun _ => by hiError) + · hiError + · refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine spec_ite (fun _ => by hiError) (fun _ => ?_) + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun high _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · exact vspace.decode_high_page_map.keepHr hA W I D hx a f vcap vaddr vm attr + s1Page + · refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun high _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · exact vspace.decode_high_page_map.keepHr hA W I D hx a f vcap vaddr vm attr + s1Page + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiRetype.lean b/proofs/Fl4ProofsA64/P1/S1aHiRetype.lean new file mode 100644 index 000000000..4c6d76005 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiRetype.lean @@ -0,0 +1,251 @@ +/- +A64-S1A gen 41: Retype frames the reserved words of existing HighVSpace roots. +The placement, untyped range, and cap-tree invariants provide the exclusions. +Named premises: none new. +-/ +import Fl4ProofsA64.P1.S1aHvPt + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} +variable {OS Cs Rp Nt Pt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +set_option maxHeartbeats 4000000 in +/-- Retype frames placed VSpace words outside the allocation window and any RAM reset. -/ +theorem untyped.decode.keepVsWords (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc Ub : Set U64} {Z : U64 → Nat} + {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (cap : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (mask : A64FrameMasks st s) + (vr : VrOK H.omega Sg Scs Z OS Vc Ub (L.ksb s) Pt) {X : Set U64} + (pt : ∀ b ∈ X, VsR (L.ksb s) Pt b) + (freeOff : dev = false → ∀ b ∈ X, ¬ (p.val + fi.val ≤ b.val ∧ b.val < p.val + 2 ^ sb.val)) + (resetOff : dev = false → cdt.ensure_no_children st s slot = ok (.Ok ()) → + ∀ b ∈ X, ¬ (p.val ≤ b.val ∧ b.val < p.val + 2 ^ sb.val)) + (a : A) (lbl len buf : U64) : + untyped.decode st ar s a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + ∀ b ∈ X, L.mem s' b = L.mem s b ⦄ := by + have R := UtDecP.of_live D B.sys P cap B.ln B.vr B.ly + obtain ⟨_, hb⟩ := R.blk + obtain ⟨_, _, q⟩ := hb.1 + have osOff : ∀ x ∈ OS, ∀ o : U64, o.val < 32 → wa x o ∉ X := by + intro x hx o ho hin + have value := wv (R.os.fit x hx) ho + exact vr.os _ (pt _ hin) ⟨x, hx, by rw [value]; omega, by rw [value]; omega⟩ + have outside : ∀ b ∈ X, OutsideObjs st H.tcbs Cs s b := + fun b hb => q.omega b (vr.om b (pt b hb)) + have tcb : ∀ {t k b : U64}, H t = some .tcb → k.val < 4096 → b ∈ X → wa t k ≠ b := + fun ht hk hb eq => out_ne_field (outside _ hb) ht (q.tcbs _ ht) hk (congrArg UScalar.val eq) + have node : ∀ {s1 : S} {c o b : U64}, L.ksb s1 = L.ksb s → c ∈ Cs → o.val < 4288 → b ∈ X → + L.nodeAt s1 c o ≠ b := by + intro s1 c o b hks hc ho hb eq + rw [nodeAt_of_ksb hks] at eq + exact out_ne_node (outside b hb) hc (q.nodes c hc) ho (congrArg UScalar.val eq) + have slotOff : ∀ b ∈ X, ¬ (b = slot ∨ b = wa slot 8#u64) := by + intro b hb + rintro (e | e) + · rw [e] at hb + have hfit := R.os.fit slot R.src + have hzero : (0#u64 : U64).val = 0 := rfl + have eq : wa slot 0#u64 = slot := UScalar.eq_of_val_eq (by + rw [wadd_val (by rw [hzero]; omega), hzero, Nat.add_zero]) + exact osOff slot R.src 0#u64 (by simp) (eq.symm ▸ hb) + · exact osOff slot R.src 8#u64 (by simp) (e ▸ hb) + have decoded : untyped.decode st ar s a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r => + WritesIn st s r.2.1 (fun b => b ∉ X) ⦄ := by + refine untyped.decode.decG (P := fun _ s' => WritesIn st s s' fun b => b ∉ X) hA a lbl len slot + buf p sb fi dev (fun _ => WritesIn.refl _ _) (fun h => (mask.noShare h).elim) ?_ + intro s2 reset aligned nt us dest off win e args + have w := (restart_frame R.os q e).2 + have restart : WritesIn st s s2 (fun b => b ∉ X) := w.mono fun b h hb => by + rcases h with eq | eq + · rw [stA_eq] at eq + exact tcb q.curT (by simp) hb eq.symm + · exact node rfl q.cur (by simp) hb eq.symm + have arith := UtArgs.arithA R.ty R.ext R.cap R.utv args + have finish {s1 s' : S} {H1 : Heap} + (sub : ∀ t, H1 t = some .tcb → H t = some .tcb) + (pre : WritesIn st s s1 (fun b => b ∉ X)) + (offWindow : ∀ b ∈ X, WKA nt → ¬ (aligned.val ≤ b.val ∧ b.val < aligned.val + win.val * 2 ^ (zA nt.val us).val)) + (wr : WritesIn st s1 s' (RFw st H1 (H.frame ∪ X) s1 (WKA nt) aligned (zA nt.val us) win.val)) : + WritesIn st s s' (fun b => b ∉ X) := + (pre.trans wr).mono fun b h hb => by + rcases h with out | (⟨t, ht, k, hk, eq⟩ | ⟨_, out⟩) | ⟨wk, lo, hi⟩ | eq | ⟨t, ht, eq⟩ + · exact out hb + · exact tcb (sub t ht) (by omega) hb eq.symm + · exact out (Set.mem_union_right _ hb) + · exact offWindow b hb wk ⟨lo, hi⟩ + · exact node pre.1 R.core0 (by simp) hb eq.symm + · exact tcb (sub t ht) (by simp) hb eq.symm + have excludeDev (hd : dev = true) : ∀ b ∈ X, WKA nt → + ¬ (aligned.val ≤ b.val ∧ b.val < aligned.val + win.val * 2 ^ (zA nt.val us).val) := by + intro _ _ wk + obtain ⟨h1, h12, h14⟩ := arith.1 hd + unfold WKA at wk + omega + have excludeRam {lo : Nat} (low : lo ≤ aligned.val) + (offRange : ∀ b ∈ X, ¬ (lo ≤ b.val ∧ b.val < p.val + 2 ^ sb.val)) : + ∀ b ∈ X, WKA nt → ¬ (aligned.val ≤ b.val ∧ b.val < aligned.val + win.val * 2 ^ (zA nt.val us).val) := + fun b hb _ ⟨l, u⟩ => offRange b hb ⟨le_trans low l, lt_of_lt_of_le u arith.2.2.2.2.1⟩ + have positive (hd : dev = false) : 0 < aligned.val := + lt_of_lt_of_le (B.ly.ut0 slot R.src p sb fi (hd ▸ R.cap)) (CrtA.of_args R args).pa + cases reset + · have C := (CrtP.of0 R e args).widen (X := X) (fun x hx o ho _ => osOff x hx o ho) + cases dev + · refine WP.spec_mono (untyped.retype.liveR hA C (positive rfl) a) ?_ + rintro _ ⟨E, _⟩ + exact finish (fun _ ht => ht) restart (excludeRam (by simpa using arith.2.2.2.1) (freeOff rfl)) E.fr + · exact WP.spec_mono (untyped.retype.liveD C a) fun _ ⟨E, _⟩ => + finish (fun _ ht => ht) restart (excludeDev rfl) E.fr + cases dev + · have resetArgs := args + obtain ⟨_, _, _, _, _, _, _, _, _, _, resetEq, _⟩ := resetArgs + obtain ⟨v, nc⟩ := resetEq.1 rfl + cases v + have skipReset : ∀ b ∈ X, ¬ RstW st s2 slot p sb b := by + intro b hb + rintro (h | h | h) + · exact resetOff rfl nc b hb h + · exact slotOff b hb h + · rcases PPW.of w.1 w.2.1 h with h | h | h + · exact vr.ks b (pt b hb) _ (by simp) h.symm + · exact node rfl q.cur (by simp) hb h.symm + · exact node rfl q.cur (by simp) hb h.symm + have afterReset {s1 : S} (wr : WritesIn st s2 s1 (RstW st s2 slot p sb)) : + WritesIn st s s1 (fun b => b ∉ X) := + restart.trans (wr.mono fun b h hb => skipReset b hb h) |>.mono fun _ h => h.elim id id + refine WP.spec_mono (untyped.retype.stZFCRUG hA R e a args + (fun _ _ s' => WritesIn st s s' fun b => b ∉ X) + (fun _ _ _ wr _ => afterReset wr) ?_) ?_ + · intro s1 a1 wr _ C H' _ _ _ _ + have C' := C.widen (X := X) (fun x hx o ho _ => osOff x hx.1 o ho) + exact WP.spec_mono (untyped.retype.liveR hA C' (positive rfl) a1) fun _ ⟨E, _⟩ => + finish (fun _ ht => (Heap.drop_eq_some.1 ht).2) (afterReset wr) + (excludeRam (CrtA.of_args R args).pa (resetOff rfl nc)) E.fr + · rintro _ ⟨_, _, _, _, _, _, h⟩ + exact h + · refine WP.spec_mono (untyped.retype.stZFCRdUG hA R e a args + (fun _ _ s' => WritesIn st s s' fun b => b ∉ X) ?_) ?_ + · intro s1 a1 wr _ C H' _ _ _ _ + have beforeCreate : WritesIn st s s1 (fun b => b ∉ X) := (restart.trans (wr.mono fun b hw hb => slotOff b hb hw)).mono fun _ h => h.elim id id + have C' := C.widen (X := X) (fun x hx o ho _ => osOff x hx o ho) + exact WP.spec_mono (untyped.retype.liveD C' a1) fun _ ⟨E, _⟩ => + finish (fun _ ht => ht) beforeCreate (excludeDev rfl) E.fr + · rintro _ ⟨_, _, _, _, _, _, h⟩ + exact h + refine WP.spec_mono decoded ?_ + rintro ⟨_, s', _⟩ wr b hb + exact wr.mem_eq (vr.al b (pt b hb)) (fun h => h hb) + +set_option maxHeartbeats 4000000 in +/-- Retype preserves the reserved word of every root named before the decode. -/ +theorem untyped.decode.keepOldHi (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc Ub : Set U64} {Z : U64 → Nat} + {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (cap : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (mask : A64FrameMasks st s) + (vr : VrOK H.omega Sg Scs Z OS Vc Ub (L.ksb s) Pt) (hg : PtHG H Pt) (hv : HvPt st Pt OS s) + (a : A) (lbl len buf : U64) : + untyped.decode st ar s a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + HrW st (HvRt st OS s) s s' ⦄ := by + let X : Set U64 := {b | ∃ t ∈ HvRt st OS s, b = wa t 4088#u64} + have pt : ∀ b ∈ X, VsR (L.ksb s) Pt b := by + rintro _ ⟨t, ht, rfl⟩ + exact Or.inl ⟨t, hv.rt ht, 4088#u64, by simp, by simp, rfl⟩ + have R := UtDecP.of_live D B.sys P cap B.ln B.vr B.ly + have val : ∀ t ∈ HvRt st OS s, (wa t 4088#u64).val = t.val + 4088 := by + intro t ht + have hf := hg.fit R.heap t (hv.rt ht) + exact wadd_val (by change t.val + 4088 < 2 ^ 64; omega) + have freeOff (hd : dev = false) : ∀ b ∈ X, ¬ (p.val + fi.val ≤ b.val ∧ b.val < p.val + 2 ^ sb.val) := by + rintro b ⟨t, ht, rfl⟩ bounds + obtain ⟨_, obj, z, he, hlo, hhi⟩ := hg t (hv.rt ht) + have hc : capA st s slot = .Untyped p sb fi false := hd ▸ R.cap + obtain ⟨⟨_, _, hvalid, _, _⟩, _, _⟩ := R.stz + have hoff := hvalid slot R.src p sb fi hc obj (.other z) he + simp only [HKind.bits] at hoff + rw [val t ht] at bounds + omega + have resetOff (hd : dev = false) (he : cdt.ensure_no_children st s slot = ok (.Ok ())) : + ∀ b ∈ X, ¬ (p.val ≤ b.val ∧ b.val < p.val + 2 ^ sb.val) := by + rintro b ⟨t, ht, rfl⟩ bounds + have named := ht + obtain ⟨x, hx, m, asid, hc⟩ := named + have hoff := PtHG.keyOffNC P B R.src (hd ▸ R.cap) he hg hx + (by rw [hc]; exact RngKeyA.hv t m asid) (by rw [hc, ptrA_hv]) (hv.rt ht) + rw [val t ht] at bounds + omega + exact WP.spec_mono (untyped.decode.keepVsWords hA D P B cap mask vr pt freeOff resetOff a lbl len buf) + fun _ keep t ht => keep _ ⟨t, ht, rfl⟩ + +/-- The creation's end has either the old reserved word or the initialized word of a new root. -/ +theorem UtEnd.hiCap511 {s s1 s' : S} {slot p sb : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} + {lo hi : Nat} {base nt us dest off win : U64} + (U : UtEnd st H Cs OS s slot p sb dev H1 H' OS1 s1 s' lo hi base nt us dest off win) + (X : UtX H H1 lo hi us) (fit : (L.ksb s).val + 788736 ≤ 2 ^ 64) + (init : WinHi st s' base nt us win.val) (keep : HrW st (HvRt st OS s) s s') + (Hi : HiCap511 st OS s) : HiCap511 st (OS1 ∪ NewSl dev nt us base win) s' := by + have fit' : (L.ksb s').val + 788736 ≤ 2 ^ 64 := by + rw [U.E.fr.1.trans U.w1.1] + exact fit + have kept : CapInv st (HiCap511P st (HvRt st (OS1 ∪ NewSl dev nt us base win) s') s') OS1 s' := by + intro y hy + have liftTag : ∀ t m a, capA st s' y = .HighVSpace t m a → + (L.mem s' (wa t 4088#u64) &&& 3#u64) = 3#u64 := by + by_cases hsrc : y = slot + · subst y + obtain ⟨_, hc⟩ := U.E.src + rw [hc] + intro _ _ _ e + cases e + by_cases hdest : ∃ j, j < win.val ∧ y = djA dest off j + · obtain ⟨j, hj, rfl⟩ := hdest + rw [U.E.new j hj] + intro t m a hc + obtain ⟨hn, rfl⟩ := newCapA_hv U.A.hn hc + exact init hn j hj + · have old := (U.E.keep y hy hsrc (fun j hj e => hdest ⟨j, hj, e⟩)).trans (U.k1 y hy hsrc) + intro t m a hc + have hyOld := U.os y hy + have hOld := old.symm.trans hc + rw [keep t ⟨y, hyOld, m, a, hOld⟩] + exact Hi y hyOld t m a hOld + intro t m a hc + exact ⟨⟨y, Set.mem_union_left _ hy, m, a, hc⟩, liftTag t m a hc⟩ + have grown := CapInv.growN kept (fun _ _ _ e => by cases e) (U.freshN X fit') + exact fun y hy t m a hc => (grown y hy t m a hc).2 + +/-- Retype carries the reserved-entry invariant at the same end as the page-table and slot columns. -/ +theorem syscall.decode_invocation.untyped_s1aRtVHi {A : Type _} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc' Ub' Vc Ub : Set U64} + {Z : U64 → Nat} {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) (Y : SymL st H Cs s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) (hfm : A64FrameMasks st s0) + (hvr : VrOK H.omega Sg Scs Z OS Vc' Ub' (L.ksb s0) Pt) (hPN : PoolNamed st OS s0) + (C : S1aArmCol st H Cs OS Vc Ub s0) (K : S1aCapCol st H OS Ub s0) (hal : ∀ b ∈ Ub, Aligned b) + (hVC : VcCap st Vc OS s0) (Cp : PtCap st Pt OS s0 ∧ PtHG H Pt) (Df : DevFrAl st OS s0) + (Hv : HvPt st Pt OS s0) (Hi : HiCap511 st OS s0) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s0 a lbl len slot (.Untyped p sb fi dev) blk call don fp buf extra ⦃ r s' _ => + ∃ (H' : Heap) (OS' Vn Vc'' Pt' : Set U64), ArmQIVAt st H Cs OS ia ie s0 H' OS' Vn s' ∧ TabKeep st s0 s' ∧ + Vc'' ⊆ Vc ∪ Vn ∧ VcCap st Vc'' OS' s' ∧ S1aArmCol st H' Cs OS' Vc'' Ub s' ∧ S1aCapCol st H' OS' Ub s' ∧ + PtCap st Pt' OS' s' ∧ HvPt st Pt' OS' s' ∧ PtHG H' Pt' ∧ DevFrAl st OS' s' ∧ HiCap511 st OS' s' ⦄ := by + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + refine WP.spec_mono (WP.spec_and (untyped.decode.s1aRtVJH hA D P B Y hcap hfm hvr hPN C K hal hVC a lbl len buf + (fun H' O s' => (∃ Pt' : Set U64, (PtCap st Pt' O s' ∧ PtHG H' Pt') ∧ HvPt st Pt' O s' ∧ DevFrAl st O s') ∧ + (HrW st (HvRt st OS s0) s0 s' → HiCap511 st O s')) + ⟨⟨Pt, Cp, Hv, Df⟩, fun _ => Hi⟩ + fun _ _ _ _ _ _ _ _ _ _ _ _ _ E X hw hp init => + ⟨⟨_, UtEnd.ptCapHG D P B hcap E X hw hp Cp.1 Cp.2, UtEnd.hvPtN D P B hcap E X hp Cp.2 Hv, + UtEnd.devFrN D P B hcap E X hw Df⟩, fun keep => E.hiCap511 X B.ly.ksw init keep Hi⟩) + (untyped.decode.keepOldHi hA D P B hcap hfm hvr Cp.2 Hv a lbl len buf)) ?_ + rintro _ ⟨⟨H', OS', Vn, Vc'', ⟨h1, h2, h3, h4, h5, h6⟩, ⟨Pt', ⟨h7, h8⟩, h9, h10⟩, hh⟩, keep⟩ + exact ⟨H', OS', Vn, Vc'', Pt', h1, h2, h3, h4, h5, h6, h7, h9, h8, h10, hh keep⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiTca.lean b/proofs/Fl4ProofsA64/P1/S1aHiTca.lean new file mode 100644 index 000000000..c32c6331c --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiTca.lean @@ -0,0 +1,109 @@ +/- +P1 (aarch64, A64-S1A gen 41): TestAndClearAccessed reaches a leaf +below level zero. Neither the atomic edit nor the reply reaches entry 511. +-/ +import Fl4ProofsA64.P1.S1aHiVsW + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {s : S} + {Cs OS Vc Ub Pt Pp Tb Hr Te Ac U : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- A successful mapped-entry lookup returns a leaf word of a non-root table. -/ +theorem vspace.mapped_entry.leafSlot {kb root : U64} (ht : VsTy st kb Pp Tb Lv s) + (hroot : root ∈ Tb) (h0 : Lv root = 0) (f : vspace.FrameCap) : + vspace.mapped_entry st s f root ⦃ o => ∀ lu, o = some lu → ∃ p ∈ Tb, ∃ off : U64, + off.val < 4096 ∧ off.val % 8 = 0 ∧ lu.slot = wa p off ∧ 0 < Lv p ⦄ := by + unfold vspace.mapped_entry + refine WP.spec_bind (vspace.lookup_pt_slot.lv ht hroot h0 f.vaddr) fun lu ⟨p, hp, off, ho, h8, he, hlev⟩ => ?_ + refine WP.spec_bind (LawfulStore.read_spec s lu.slot) fun e _ => ?_ + refine WP.spec_bind (vspace.page_shift.v f.size) fun shift hs => ?_ + refine spec_ite (fun _ => (WP.spec_ok _).2 fun _ e => by cases e) (fun hshift => ?_) + have heq : lu.shift = shift := UScalar.eq_of_val_eq (by simpa using hshift) + have hlo : 0 < Lv p := by rw [heq] at hlev; omega + repeat' (first + | exact (WP.spec_ok _).2 fun x hx => by cases hx; exact ⟨p, hp, off, ho, h8, he, hlo⟩ + | exact (WP.spec_ok _).2 fun x hx => by cases hx + | (refine WP.spec_bind (P0.vspace.is_page.p0 _ _) fun _ _ => ?_) + | (refine WP.spec_bind (P0.vspace.page_base.p0 _ _) fun _ _ => ?_) + | (refine WP.spec_bind (P0.layout.paddr.p0 _) fun _ _ => ?_) + | split) + +set_option hygiene false in +local macro "hiLeaf" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 (fun _ _ => rfl) + | (simp only [bind_ok, error.illegal, error.invalid_cap] + exact (WP.spec_ok _).2 (fun _ _ => rfl))) + +set_option maxHeartbeats 3000000 in +theorem vspace.decode_test_and_clear_accessed.keepHr (hA : P0.ArchTotal ar) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (a : A) (f : vspace.FrameCap) (call : Bool) : + vspace.decode_test_and_clear_accessed st ar s a f call ⦃ r => HrW st Hr s r.2.1 ⦄ := by + unfold vspace.decode_test_and_clear_accessed + refine spec_ite (fun _ => by hiLeaf) (fun _ => ?_) + refine WP.spec_bind (Pₘ := fun _ => True) (by cases f.size <;> exact (WP.spec_ok _).2 trivial) ?_ + rintro ⟨fs, bh⟩ _ + simp only [uncurry_apply_pair] + refine spec_ite (fun _ => by hiLeaf) (fun _ => ?_) + refine spec_ite (fun _ => ?_) (fun _ => by hiLeaf) + refine spec_ite (fun _ => by hiLeaf) (fun _ => ?_) + refine WP.spec_bind (hA.hw_access_flag a) fun b1 _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => by hiLeaf) + refine WP.spec_bind (vspace.frame_root.ty W.ty.1 rfl f.asid) fun r hr => ?_ + rcases r with ⟨root, _⟩ | e + swap + · hiLeaf + obtain ⟨hrT, hr0⟩ := hr _ rfl + try dsimp only + refine WP.spec_bind (vspace.mapped_entry.leafSlot W.ty.1 hrT hr0 _) fun o ho => ?_ + rcases o with _ | x + · hiLeaf + obtain ⟨p, hp, off, ho, h8, he, hlev⟩ := ho x rfl + have hpt : PtW Pt x.slot := ptw_mono W.tables ⟨p, hp, off, ho, h8, he⟩ + have hoff : ∀ R ∈ Hr, x.slot ≠ wa R 4088#u64 := he ▸ W.keepStage1Leaf hp ho h8 hlev + have hal := I.del.vr.al _ (Or.inl hpt) + rw [cur_thread_ok] + try simp only [bind_ok] + refine WP.spec_bind P0.vspace.D_AF.p0 fun i _ => ?_ + try simp only [lift, bind_ok] + refine WP.spec_bind (LawfulStore.fetch_and_spec s x.slot _) ?_ + rintro ⟨old, q⟩ e + try simp only [uncurry_apply_pair] + obtain ⟨hold, hq⟩ := Prod.mk.inj e + rw [← hold] at hq + subst q + have hct := D.bxi.1.choose_spec.choose_spec.curT + have hmem : W7.CapW H.tcbs H.omega H.frame x.slot := + Or.inr ⟨I.del.vr.om x.slot (Or.inl hpt), I.del.vr.sg x.slot (Or.inl hpt)⟩ + have b1 := blk_capw_wr (v := old &&& ~~~i) D.bxi.blk hal hmem + have hw := writesIn_wr (st := st) (s := s) (v := old &&& ~~~i) hal + have hs : L.mem (L.wr s x.slot (old &&& ~~~i)) (stA (L.curW s)) = L.mem s (stA (L.curW s)) := + (capw_cur D.bxi.blk hw (fun _ e => e ▸ hmem) _ hct).2.2 + have runnable : ¬ BlockedR (L.mem (L.wr s x.slot (old &&& ~~~i)) (stA (L.curW s))) := by + rw [hs] + exact nbr_runnable D.run + have tail (v : U64) : vspace.reply1 st (L.wr s x.slot (old &&& ~~~i)) (L.curW s) call v + ⦃ s' => HrW st Hr s s' ⦄ := by + rw [vspace.reply1_eq] + refine WP.spec_mono (vcpu.reply1.dfKn (Ko := ∅) b1 hct runnable call v) fun q h R hR => ?_ + obtain ⟨Q, Rq, q1⟩ := b1.1 + have hvr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub + (L.ksb (L.wr s x.slot (old &&& ~~~i))) Pt := by rw [L.ksb_wr]; exact I.del.vr + have hplace : PtW Pt (wa R 4088#u64) := ⟨R, W.tables (W.high.sub hR), 4088#u64, by simp, by simp, rfl⟩ + exact (h.1.w.mem_eq (W.aligned I hR) fun hd => DfW.notPtW q1 hvr hd hplace).trans + (W.keepWrite I hw (fun R hR e => hoff R hR e.symm) R hR) + split + · exact WP.spec_bind (tail 1#u64) fun _ h => (WP.spec_ok _).2 h + · exact WP.spec_bind (tail 0#u64) fun _ h => (WP.spec_ok _).2 h + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiUnm.lean b/proofs/Fl4ProofsA64/P1/S1aHiUnm.lean new file mode 100644 index 000000000..77b00fa1e --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiUnm.lean @@ -0,0 +1,125 @@ +/- +P1 (aarch64, A64-S1A gen 41): VSpace unmap operations preserve HighVSpace entry 511. +Use the concrete Stage-1 and Stage-2 walks and the kind separation of the live MDB. +-/ +import Fl4ProofsA64.P1.S1aHiVsW + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {s : S} + {Cs OS Vc Ub Pt Pp Tb Hr Te Ac U : Set U64} {Lv Re bits : U64 → Nat} + {ia ie : Nat} {A : Type _} {ar : machine.Arch A} {hPl : ArchPlat ar} + {K : capability.Cap → Prop} {Ty : S → Prop} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {cap : capability.Cap} {slot : U64} + +/-- A live PageTable and a live HighVSpace cannot have the same base. At 4 KiB alignment +the PageTable's zero range consequently misses the HighVSpace's reserved entry. -/ +theorem HiDelTy.keepTableZero (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (B : SysL st H Cs OS ia ie s) + (hx : slot ∈ OS) {ptr a v : U64} {m : Bool} (hc : capA st s slot = .PageTable ptr m a v) + (hpt : PtHG H Pt) (hp : ptr ∈ Pt) {q : S} : + HrW st Hr s q → ∀ R ∈ HvRt st OS s, + L.mem (L.zr q ptr 4096#u64) (wa R 4088#u64) = L.mem s (wa R 4088#u64) := by + intro keep R hR + have hRH := W.roots hR + have hRR := W.tables (W.high.sub hRH) + obtain ⟨pal, p0, pz, ph, -, pfit⟩ := hpt ptr hp + obtain ⟨ral, r0, rz, rh, -, rfit⟩ := hpt R hRR + have hpfit := le_trans pfit (I.del.heap.fits p0 _ ph) + have hrfit := le_trans rfit (I.del.heap.fits r0 _ rh) + obtain ⟨y, hy, mm, aa, e⟩ := hR + obtain ⟨_, _, _, hKind, _, _⟩ := B.sys.stz.1.1.mdbS + have hne : ptr ≠ R := fun he => by + have hk := hKind.kind slot hx y hy (hc ▸ RngKeyA.pt ptr m a v) (e ▸ RngKeyA.hv R mm aa) + (by rw [hc, e, ptrA_pt, ptrA_hv, he]) + rw [hc, e] at hk + exact (by decide : (14 : Nat) ≠ 25) hk + have hnat : ptr.val ≠ R.val := fun ev => hne (UScalar.eq_of_val_eq ev) + have h88 : (4088#u64 : U64).val = 4088 := rfl + have hval : (wa R 4088#u64).val = R.val + 4088 := by rw [wadd_val (by rw [h88]; omega), h88] + have hpal : Aligned ptr := by unfold Aligned; omega + have h4 : (4096#u64 : U64).val = 4096 := rfl + have hfit : ptr.val + (4096#u64 : U64).val ≤ 2 ^ 64 := by rwa [h4] + exact ((writesIn_zrV (s := q) hpal (by decide) hfit).mem_eq (W.aligned I hRH) + (by rintro ⟨lo, hi⟩; rw [hval] at lo hi; rw [h4] at hi; omega)).trans (keep R hRH) + +set_option maxHeartbeats 2000000 in +/-- The initial restart and the final cap write keep the reserved words. The unmap walk +zeroes at most one word of a non-root Stage-1 table or a Stage-2 object. -/ +theorem vspace.decode_frame.unmapHr (hA : P0.ArchTotal ar) + (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) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (hx : slot ∈ OS) (a : A) (len buf : U64) (call : Bool) + (fp : U64) (sz : capability.FrameSize) (rights : U64) (dev mapped stage2 : Bool) (asid va : U64) : + vspace.decode_frame st ar s a fl4_abi.label.ARMPageUnmap len slot + (.Frame fp sz rights dev mapped stage2 asid va) call buf extra ⦃ r => HrW st Hr s r.2.1 ⦄ := by + unfold vspace.decode_frame + simp only [vspace.as_frame, bind_ok] + have hne : fl4_abi.label.ARMPageUnmap ≠ fl4_abi.label.ARMPageMap := lbl_ne_of_val + (by simp [fl4_abi.label.ARMPageMap, fl4_abi.label.ARMPageUnmap]) + rw [cur_thread_ok, bind_ok] + try dsimp only + rw [if_neg hne] + simp only [ite_true] + refine WP.spec_bind (sched.set_thread_state.unmMid I D) fun s1 ⟨M1, vk⟩ => ?_ + have hi1 := W.keepWord vk + refine WP.spec_bind (Pₘ := fun r : S × A => HrW st Hr s r.1) ?_ ?_ + · have h1 := W.ty.1.keepZ W.pools W.tables vk.vsz + have h2 := W.ty.2.keep W.pools W.granules W.stage2 vk.vsz hi1 + split <;> try exact (WP.spec_ok _).2 hi1 + split <;> try exact (WP.spec_ok _).2 hi1 + split + · refine WP.spec_bind (P0.capability.FrameSize.bits.p0 sz) fun i _ => ?_ + exact WP.spec_mono (ept.unmap.z hA hPl h1 h2 W.stage2 M1.tz.1 a asid va fp i false) + fun _ h R hR => (W.keepWr0 I (h.mono fun _ ht => Or.inr ht) R hR).trans (hi1 R hR) + · exact WP.spec_mono (vspace.unmap_page.hr hA W.high h1 M1.tz.1 a sz asid va fp) + fun _ h R hR => (W.keepWr0 I (h.mono fun _ ht => Or.inl ht) R hR).trans (hi1 R hR) + · rintro ⟨s2, a2⟩ hi2 + dsimp only at hi2 + simp only [uncurry_apply_pair, vspace.unmapped_frame, bind_ok] + refine WP.spec_bind (W.keepSlot I hx _) fun s3 hi3 => ?_ + exact (WP.spec_ok _).2 fun R hR => (hi3 R hR).trans (hi2 R hR) + +set_option maxHeartbeats 2000000 in +/-- The table unmap preserves the live roots' reserved entry through its walk and its +explicit four-KiB zero. -/ +theorem vspace.decode_page_table.unmapHv (hA : P0.ArchTotal ar) + (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) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (B : SysL st H Cs OS ia ie s) + (hx : slot ∈ OS) {ptr ad va : U64} {m : Bool} (hc : capA st s slot = .PageTable ptr m ad va) + (hpt : PtHG H Pt) (hp : ptr ∈ Pt) (a : A) (len buf : U64) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap len slot + (.PageTable ptr m ad va) buf extra ⦃ r => HrW st (HvRt st OS s) s r.2.1 ⦄ := by + unfold vspace.decode_page_table + rw [cur_thread_ok, bind_ok] + dsimp only + rw [if_pos rfl] + refine WP.spec_bind (P0.cdt.is_final_capability.p0 st s slot L.total) fun b _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => (WP.spec_ok _).2 fun _ _ => rfl) + refine WP.spec_bind (sched.set_thread_state.unmMid I D) fun s1 ⟨M1, vk⟩ => ?_ + have hi1 := W.keepWord vk + refine WP.spec_bind (Pₘ := fun r : S × A => HrW st (HvRt st OS s) s r.1) ?_ ?_ + · split + · have h1 := W.ty.1.keepZ W.pools W.tables vk.vsz + have h2 := W.ty.2.keep W.pools W.granules W.stage2 vk.vsz hi1 + refine WP.spec_bind (vspace.unmap_page_table.s2 hA hPl W.high W.stage2 h1 h2 M1.tz.1 a ad va ptr) ?_ + rintro ⟨s3, a3⟩ h3 + simp only [uncurry_apply_pair] + refine WP.spec_bind (LawfulStore.zero_spec s3 ptr 4096#u64) fun s4 e => ?_ + subst e + exact (WP.spec_ok _).2 (W.keepTableZero I B hx hc hpt hp + (fun R hR => (W.keepWr0 I h3 R hR).trans (hi1 R hR))) + · exact (WP.spec_ok _).2 fun R hR => hi1 R (W.roots hR) + · rintro ⟨s2, a2⟩ hi2 + simp only [uncurry_apply_pair] + refine WP.spec_bind (W.keepSlot I hx (.PageTable ptr false 0#u64 0#u64)) fun s3 hi3 => ?_ + exact (WP.spec_ok _).2 fun R hR => (hi3 R (W.roots hR)).trans (hi2 R hR) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiVs.lean b/proofs/Fl4ProofsA64/P1/S1aHiVs.lean new file mode 100644 index 000000000..918f00bf4 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiVs.lean @@ -0,0 +1,91 @@ +/- +P1 (aarch64, A64-S1A gen 41): preserve HiCap511 on the VSpace decode arms +from the concrete entry-511 memory frame and the existing cap-source post. +-/ +import Fl4ProofsA64.P1.S1aHiMap +import Fl4ProofsA64.P1.S1aHiTca +import Fl4ProofsA64.P1.S1aHiUnm + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {s : S} + {Cs OS Vc Ub Pt Pp Tb Hr Te Ac U : Set U64} {Lv Re bits : U64 → Nat} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- The DecArmQH cases that can write a VSpace descriptor. -/ +def DecArmQHV (cap : capability.Cap) (lbl : U64) : Prop := + (∃ p sz rg d m e a v, cap = .Frame p sz rg d m e a v ∧ + (lbl = fl4_abi.label.ARMPageUnmap ∨ lbl = fl4_abi.label.ARMPageTestAndClearAccessed ∨ + lbl = fl4_abi.label.ARMPageMap)) ∨ + (∃ p m a v, cap = .PageTable p m a v ∧ (lbl = fl4_abi.label.ARMPageTableMap ∨ + lbl = fl4_abi.label.ARMPageTableUnmap)) + +set_option hygiene false in +local macro "enterVs" : tactic => `(tactic| ( + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + try dsimp only)) + +set_option hygiene false in +local macro "enterFrame" : tactic => `(tactic| ( + enterVs + unfold vspace.decode_frame + simp only [vspace.as_frame, bind_ok, cur_thread_ok])) + +set_option maxHeartbeats 4000000 in +theorem syscall.decode_invocation.armVs_hi (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {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) (Hy : ArmDecHyps st H Pt hPl.ipa s cap) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (Cp : PtHG H Pt) + (hcap : obj.Slot.cap st slot s = ok cap) (a : A) {lbl : U64} (hc : DecArmQHV cap lbl) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => + HiCap511 st OS s → HiCap511 st OS s' ⦄ := by + have old : syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => + ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ⦄ := by + rcases hc with ⟨p, sz, rg, d, m, e, asid, va, rfl, hl | hl | hl⟩ | ⟨p, m, asid, va, rfl, hl | hl⟩ + · cases e + · exact syscall.decode_invocation.pgUnmap_armQIAt hA I D P B Y Hy hcap a hl len blk call don fp buf + · exact syscall.decode_invocation.pgUnmapE_armQIAt hA hPl I D P B Y Hy.vs hcap a hl len blk call don fp buf + · exact syscall.decode_invocation.tca_armQIAt hA I D P B Y Hy a hl len blk call don fp buf + · exact syscall.decode_invocation.pgMapS_armQIAt hA hPl I D P B Y Hy hcap a hl len blk call don fp buf + · exact syscall.decode_invocation.ptMapS_armQIAt hA hPl I D P B Y Hy hcap a hl len blk call don fp buf + · exact syscall.decode_invocation.ptUnmapS_armQIAt hA hPl I D P B Y Hy Hy.vs hcap a hl len blk call don fp buf + have keep : syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => + HrW st (HvRt st OS s) s s' ⦄ := by + rcases hc with ⟨p, sz, rg, d, m, e, asid, va, rfl, rfl | rfl | rfl⟩ | ⟨p, m, asid, va, rfl, rfl | rfl⟩ + · enterVs + exact WP.spec_mono (vspace.decode_frame.unmapHr hA I D W P.src a len buf call p sz rg d m e asid va) + fun _ keep R hR => keep R (W.roots hR) + · have h1 : fl4_abi.label.ARMPageTestAndClearAccessed ≠ fl4_abi.label.ARMPageMap := lbl_ne_of_val + (by simp [fl4_abi.label.ARMPageTestAndClearAccessed, fl4_abi.label.ARMPageMap]) + have h2 : fl4_abi.label.ARMPageTestAndClearAccessed ≠ fl4_abi.label.ARMPageUnmap := lbl_ne_of_val + (by simp [fl4_abi.label.ARMPageTestAndClearAccessed, fl4_abi.label.ARMPageUnmap]) + have h3 : fl4_abi.label.ARMPageTestAndClearAccessed ≠ fl4_abi.label.ARMPageGetAddress := lbl_ne_of_val + (by simp [fl4_abi.label.ARMPageTestAndClearAccessed, fl4_abi.label.ARMPageGetAddress]) + enterFrame + simp only [h1, h2, h3, vspace.is_cache_label.tca, bind_ok, Bool.false_eq_true, ↓reduceIte, ite_true] + exact WP.spec_mono (vspace.decode_test_and_clear_accessed.keepHr hA W I D a ⟨p, sz, rg, d, m, e, asid, va⟩ call) + fun _ keep R hR => keep R (W.roots hR) + · enterFrame + simp only [ite_true] + exact WP.spec_mono (vspace.decode_page_map.keepHr hA W I D P.src a len buf ⟨p, sz, rg, d, m, e, asid, va⟩) + fun _ keep R hR => keep R (W.roots hR) + · enterVs + exact WP.spec_mono (vspace.decode_page_table.mapHr W I D P.src a len buf p asid va m) + fun _ keep R hR => keep R (W.roots hR) + · enterVs + exact vspace.decode_page_table.unmapHv hA I D W B P.src (okinj ((capA_eq s slot).symm.trans hcap)) + Cp (Hy.ptCap p m asid va rfl).1 a len buf + exact WP.spec_mono (WP.spec_and old keep) fun _ d Hi => + HiCap511.ofRt (d.1.1.hiCapP Hi) fun R hR => by rw [d.2 R hR] + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHiVsW.lean b/proofs/Fl4ProofsA64/P1/S1aHiVsW.lean new file mode 100644 index 000000000..28ffc3202 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHiVsW.lean @@ -0,0 +1,72 @@ +/- +P1 (aarch64, A64-S1A gen 41): the concrete VSpace writes preserve the reserved HighVSpace root word. +The typing and placement are the same witness used by the S1A deletion arms. +-/ +import Fl4ProofsA64.P1.S1aHiDel +import Fl4ProofsA64.P1.MdbEptMapQ + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Pt Pp Tb Hr Te : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s s' : S} {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +theorem HiDelTy.word (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) {R : U64} (hR : R ∈ Hr) : + VsR (L.ksb s) Pt (wa R 4088#u64) := + hr_vsr W.tables W.high hR + +theorem HiDelTy.aligned (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) {R : U64} (hR : R ∈ Hr) : + Aligned (wa R 4088#u64) := + I.del.vr.al _ (W.word hR) + +theorem HiDelTy.keepWord (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (h : VsKeep st (L.ksb s) Pt s s') : HrW st Hr s s' := + fun _ hR => h _ (W.word hR) + +theorem HiDelTy.keepWrite (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) {q q' : S} {F : U64 → Prop} + (h : WritesIn st q q' F) (off : ∀ R ∈ Hr, ¬ F (wa R 4088#u64)) : HrW st Hr q q' := + fun R hR => h.mem_eq (W.aligned I hR) (off R hR) + +theorem HiDelTy.keepWr0 (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) {q q' : S} + (h : Wr0 st (TbO Tb Hr ∪ Gran Te bits) q q') : HrW st Hr q q' := + W.keepWrite I (h.w fun _ hb => I.del.vr.al _ (Or.inl (ptw_mono + (Set.union_subset (tbo_sub.trans W.tables) W.granules) hb))) + fun R hR hb => s2_ne W.high W.stage2 hb R hR rfl + +theorem HiDelTy.keepSlot (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) {q : S} {slot : U64} (hx : slot ∈ OS) (c : capability.Cap) : + obj.Slot.set_cap st slot q c ⦃ q' => HrW st Hr q q' ⦄ := + WP.spec_mono (obj.Slot.set_cap.capw (st := st) (s := q) (c := c) ((OSOK.inOS I.del.os).slot slot hx)) + fun _ h => W.keepWrite I h (by + rintro R hR (⟨t, ht, -⟩ | ⟨hb, -⟩) + · exact Set.notMem_empty _ ht + · exact I.del.vr.os _ (W.word hR) hb) + +theorem HiDelTy.keepStage1Leaf (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + {p o : U64} (hp : p ∈ Tb) (ho : o.val < 4096) (h8 : o.val % 8 = 0) (hl : 0 < Lv p) : + ∀ R ∈ Hr, wa p o ≠ wa R 4088#u64 := + W.high.tbo ⟨p, ⟨hp, fun hR => (Nat.ne_of_gt hl) (W.high.lv p hR)⟩, o, ho, h8, rfl⟩ + +theorem HiDelTy.keepInvalid (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + {b : U64} (h : L.mem s b &&& 1#u64 = 0#u64) : ∀ R ∈ Hr, b ≠ wa R 4088#u64 := by + intro R hR e + rw [e] at h + have hh := congrArg (fun x : U64 => x &&& 1#u64) (W.ty.2.hi R hR) + have ht : (L.mem s (wa R 4088#u64) &&& 3#u64) &&& 1#u64 = + L.mem s (wa R 4088#u64) &&& 1#u64 := by + apply UScalar.eq_of_val_eq + simp only [UScalar.val_and, Nat.and_assoc] + have eq : (3#u64 : U64).val &&& (1#u64 : U64).val = (1#u64 : U64).val := rfl + rw [eq] + rw [ht, h] at hh + exact (by decide : (0#u64 : U64) ≠ 3#u64 &&& 1#u64) hh + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aHvPt.lean b/proofs/Fl4ProofsA64/P1/S1aHvPt.lean new file mode 100644 index 000000000..26a12558a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aHvPt.lean @@ -0,0 +1,192 @@ +/- +P1 (aarch64, A64-S1A gen 39, Architect ruling L1 02:19Z): **`HvPt` — every `HighVSpace` cap's root is a placed table +of `Pt`**, the S1A clause that puts a root's level-0 page (and so its `+ 4088` word) under `ArmVsK` / `ArmVs` / +`PoolPost.vs`, carried in S1aStep's `S1aStep` post beside `PtCap`. + +* **`HvPt st Pt OS s`** := `CapInv st (fun c => ∀ p m a, c = .HighVSpace p m a → p ∈ Pt) OS s` (as ruled; a + `CapSrcClosed` instance with zero new fields: S1aHiCap's `HvRootP.closed`). **`HvPt.rt`**: `HvRt OS s ⊆ Pt` (the + `hR` of S1aHiCap's `HiCap511.ofArmVsK`); **`HvPt.mono`**, **`HvPt.ofNoHv`** (boot: no `HighVSpace` cap; `w1` by + S1aBootW1's `w1_ptCapK`). +* **The `ArmQIAt` arms**: **`ArmQIAt.hvPt`** (the cap-source clause at the class). +* **ASIDPool Assign**: **`AsgPost.hvPt`** (MdbAsidA's `AsgPost.al`, gen 39: a rewritten root cap is `AlikeA` its old + cap, so it names the same root, `al_hv`). +* **MakePool**: **`HvPt.poolEnd`** (S1aDevFr's `CapInv.poolEnd`: the new `AsidPool` cap and untyped caps are no + `HighVSpace` caps); top **`syscall.decode_invocation.makePool_s1aHv`** (S1aDevFr's `makePool_s1aDf` post with + `HvPt` at the pool end, same `Pt`). +* **Retype** (`NewPt` widened to types 11 and 14, gen 39): **`newCapA_hv`** (a retype's new `HighVSpace` cap is type + 14's at the creation base), **`UtEnd.hvPt`** (at the creation's end over `PtOffR Pt lo hi ∪ NewPt …`: a kept root is + off the region by S1aPtStep's `UtEnd.keyOff` at `RngKeyA.hv`), **`UtEnd.hvPtN`** (over the grown slot set); top + **`syscall.decode_invocation.untyped_s1aRtVHv`** (S1aDevFr's `untyped_s1aRtVDf` with `HvPt` in S1aRtV's end + predicate, at the one `Pt'` of `PtCap ∧ PtHG`). + +Named premises: none. Case facts: none new. +-/ +import Fl4ProofsA64.P1.S1aHiCap +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} {Cs Rp Nt : Set U64} + +namespace W7 +namespace R +namespace ST + +variable {OS Pt : Set U64} + +variable (st) in +/-- **Every `HighVSpace` cap of an `OS` slot names a root in `Pt`** (module docstring; Architect ruling L1). -/ +def HvPt (Pt OS : Set U64) (s : S) : Prop := + CapInv st (fun c => ∀ p m a, c = .HighVSpace p m a → p ∈ Pt) OS s + +/-- **The roots of the `HighVSpace` caps lie in `Pt`.** -/ +theorem HvPt.rt {s : S} (h : HvPt st Pt OS s) : HvRt st OS s ⊆ Pt := + fun p ⟨y, hy, m, a, e⟩ => h y hy p m a e + +theorem HvPt.mono {Pt' : Set U64} {s : S} (hs : Pt ⊆ Pt') (h : HvPt st Pt OS s) : HvPt st Pt' OS s := + fun y hy p m a e => hs (h y hy p m a e) + +/-- **No `HighVSpace` cap in `OS`** (boot). -/ +theorem HvPt.ofNoHv {s : S} (h : ∀ y ∈ OS, ∀ p m a, capA st s y ≠ .HighVSpace p m a) : HvPt st Pt OS s := + fun y hy p m a e => absurd e (h y hy p m a) + +/-- **An `ArmQIAt` step keeps `HvPt`** (its cap-source clause, `HvRootP.closed`). -/ +theorem ArmQIAt.hvPt {ia ie : Nat} {Vc : Set U64} {s0 s : S} (h : ArmQIAt st H Cs OS Vc ia ie s0 s) + (h0 : HvPt st Pt OS s0) : HvPt st Pt OS s := + h.capInv (HvRootP.closed _) h0 + +/-- **ASIDPool Assign keeps `HvPt`** (`AsgPost.al`: a rewritten root cap names the same root). -/ +theorem AsgPost.hvPt {s s' : S} (A : AsgPost st H OS s s') (h : HvPt st Pt OS s) : HvPt st Pt OS s' := by + intro y hy p m a e + rcases A.al y hy with h1 | h1 + · rw [h1] at e; exact h y hy p m a e + · rw [e] at h1 + obtain ⟨m', a', hc⟩ := al_hv h1 + exact h y hy p m' a' hc + +/-- **MakePool keeps `HvPt` over `OffR`.** -/ +theorem HvPt.poolEnd {s s' : S} {x v p sb i base : U64} (Pp : PoolPost st H OS s s' x v p sb i base) + (hk : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st s' y = capA st s y ∨ ∃ p' b' i' d', capA st s' y = .Untyped p' b' i' d') + (C : HvPt st Pt OS s) : HvPt st Pt (OffR p.val (p.val + 2 ^ sb.val) OS) s' := + CapInv.poolEnd Pp hk (fun _ _ _ _ e => by cases e) (fun _ _ _ _ _ _ _ e => by cases e) C + +/-- **A retype's new `HighVSpace` cap is type 14's**, at the creation base. -/ +theorem newCapA_hv {n : Nat} (hn : n < 15) {base us p : U64} {m : Bool} {a : U64} {dev : Bool} + (h : newCapA n base us dev = .HighVSpace p m a) : n = 14 ∧ p = base := by + interval_cases n <;> simp [newCapA] at h ⊢ + obtain ⟨h1, -⟩ := h + exact h1.symm + +section rt +variable {ia ie : Nat} + +/-- **`HvPt` at a creation's end over the kept and the new roots** (module docstring). -/ +theorem UtEnd.hvPt {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) + (hR : H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ + hi = p.val + 2 ^ sb.val)) + (hG : PtHG H Pt) (C0 : HvPt st Pt OS s0) : + HvPt st (PtOffR Pt lo hi ∪ NewPt nt aligned us win) OS1 s' := by + intro x hx + by_cases hxs : x = slot + · subst hxs + obtain ⟨nfi, hc⟩ := U.E.src + rw [hc] + intro _ _ _ e + cases e + by_cases hw : ∃ j, j < win.val ∧ x = djA dest off j + · obtain ⟨j, hj, rfl⟩ := hw + rw [U.E.new j hj] + intro q m a hc + obtain ⟨h14, rfl⟩ := newCapA_hv U.A.hn hc + exact Or.inr ⟨Or.inr h14, j, hj, rfl⟩ + · have hk : capA st s' x = capA st s0 x := by + rw [U.E.keep x hx hxs (fun j hj e => hw ⟨j, hj, e⟩), U.k1 x hx hxs] + rw [hk] + intro q m a hc + have hy := U.os x hx + exact Or.inl ⟨C0 x hy q m a hc, UtEnd.keyOff D P B hcap U hR hG hy (by rw [hc]; exact RngKeyA.hv q m a) + (by rw [hc, ptrA_hv]) (C0 x hy q m a hc)⟩ + +/-- **`HvPt` at a creation's end over the grown slot set** (module docstring). -/ +theorem UtEnd.hvPtN {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) (X : UtX H H1 lo hi us) + (hR : H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ + hi = p.val + 2 ^ sb.val)) + (hG : PtHG H Pt) (C0 : HvPt st Pt OS s0) : + HvPt st (PtOffR Pt lo hi ∪ NewPt nt aligned us win) (OS1 ∪ NewSl dev nt us aligned win) s' := by + have hk : (L.ksb s').val + 788736 ≤ 2 ^ 64 := by rw [U.E.fr.1.trans U.w1.1]; exact B.ly.ksw + exact CapInv.growN (UtEnd.hvPt D P B hcap U hR hG C0) (fun _ _ _ e => by cases e) (U.freshN X hk) + +/-- **The untyped arm with `HvPt` beside `PtCap ∧ PtHG` and `DevFrAl`** at the one end `(H', OS')`, at the one `Pt'` +(module docstring). -/ +theorem syscall.decode_invocation.untyped_s1aRtVHv {A : Type _} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc' Ub' Pq Vc Ub : Set U64} + {Z : U64 → Nat} {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) (Y : SymL st H Cs s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) (hfm : A64FrameMasks st s0) + (hvr : VrOK H.omega Sg Scs Z OS Vc' Ub' (L.ksb s0) Pq) (hPN : PoolNamed st OS s0) + (C : S1aArmCol st H Cs OS Vc Ub s0) (K : S1aCapCol st H OS Ub s0) (hal : ∀ b ∈ Ub, Aligned b) + (hVC : VcCap st Vc OS s0) (Cp : PtCap st Pt OS s0 ∧ PtHG H Pt) (Df : DevFrAl st OS s0) + (Hv : HvPt st Pt OS s0) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s0 a lbl len slot (.Untyped p sb fi dev) blk call don fp buf extra ⦃ r s' _ => + ∃ (H' : Heap) (OS' Vn Vc'' Pt' : Set U64), ArmQIVAt st H Cs OS ia ie s0 H' OS' Vn s' ∧ TabKeep st s0 s' ∧ + Vc'' ⊆ Vc ∪ Vn ∧ VcCap st Vc'' OS' s' ∧ S1aArmCol st H' Cs OS' Vc'' Ub s' ∧ S1aCapCol st H' OS' Ub s' ∧ + PtCap st Pt' OS' s' ∧ HvPt st Pt' OS' s' ∧ PtHG H' Pt' ∧ DevFrAl st OS' s' ⦄ := by + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + exact WP.spec_mono (untyped.decode.s1aRtVJ hA D P B Y hcap hfm hvr hPN C K hal hVC a lbl len buf + (fun H' O s' => ∃ Pt' : Set U64, (PtCap st Pt' O s' ∧ PtHG H' Pt') ∧ HvPt st Pt' O s' ∧ DevFrAl st O s') + ⟨Pt, Cp, Hv, Df⟩ + fun _ _ _ _ _ _ _ _ _ _ _ _ _ E X hw hp => + ⟨_, UtEnd.ptCapHG D P B hcap E X hw hp Cp.1 Cp.2, UtEnd.hvPtN D P B hcap E X hp Cp.2 Hv, + UtEnd.devFrN D P B hcap E X hw Df⟩) + fun _ ⟨H', OS', Vn, Vc'', ⟨h1, h2, h3, h4, h5, h6⟩, Pt', ⟨h7, h8⟩, h9, h10⟩ => + ⟨H', OS', Vn, Vc'', Pt', h1, h2, h3, h4, h5, h6, h7, h9, h8, h10⟩ + +end rt + +/-- **The MakePool arm with `HvPt` at its end** (S1aDevFr's `makePool_s1aDf` post with `HvPt.poolEnd`, same `Pt`). -/ +theorem syscall.decode_invocation.makePool_s1aHv {A : Type _} {ar : machine.Arch A} {ia ie : Nat} {U Ac : Set U64} + {Vc Ub Vq Uq Pq : Set U64} {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s .AsidControl 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) (hvr : VrOK H.omega H.frame H.scs H.scBits OS Vq Uq (L.ksb s) Pq) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) + (Cp : PtCap st Pt OS s ∧ PtHG H Pt) (Df : DevFrAl st OS s) (Hv : HvPt st Pt OS s) (a : A) + {lbl : U64} (hl : lbl = fl4_abi.label.ARMASIDControlMakePool) (len : 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 ⦃ r s' _ => + s' = s ∨ ∃ (H' : Heap) (OS' : Set U64), ArmQIEnd st H Cs OS Vq ia ie s H' OS' s' ∧ + S1aArmCol st H' Cs OS' Vc Ub s' ∧ (PtCap st Pt OS' s' ∧ PtHG H' Pt) ∧ HvPt st Pt OS' s' ∧ + DevFrAl st OS' s' ⦄ := + WP.spec_mono (syscall.decode_invocation.makePoolLIEAt D P B Y hvr hSC a hl len blk call don fp buf) + fun r h => by + obtain ⟨_, s', _⟩ := r + rcases h with ⟨e, -⟩ | ⟨x, hx, -, p, sb, fi, hcx, hsb, he, v, i, base, Pp, E, hk⟩ + · exact Or.inl e + · exact Or.inr ⟨_, _, E, S1aArmCol.poolEnd P B hvr C Kc hal hx hcx hsb he Pp E, + ⟨PtCap.poolEnd Pp hk Cp.1, PtHG.poolEnd B hx hcx hsb Cp.2⟩, HvPt.poolEnd Pp hk Hv, DevFrAl.poolEnd Pp hk Df⟩ + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aKTab.lean b/proofs/Fl4ProofsA64/P1/S1aKTab.lean new file mode 100644 index 000000000..033236185 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKTab.lean @@ -0,0 +1,451 @@ +/- +P1 (aarch64, A64-S1A gen 25): **the kernel TTBR1 boot tables `Kt` (B2 closed by F1), the tag-2 Assign typing +`VsTy.assign2`, and the `Te`–`H` link `TeH` giving `hR` / `hD`** (Architect ruling on K0: F1; handoff gens 24–25). + +**B2 and F1.** `init_high_vspace` copies the kernel's TTBR1 level-0 entries `0 … 510` into a new `HighVSpace` root; +after ASIDPool Assign with tag 2 the root is a `VsTy` level-0 table, so the kernel's level-1 tables (and the tables +below them) must be `Tb` tables, hence `Pt` tables. `DelIn`'s `VrOK.om` puts every `Pt` word in `H.omega`, S1A's +`PtHG` every `Pt` table inside a heap `other` object. F1 (ruled): the static kernel TTBR1 boot tables are **capless +`.other 12` objects of the ghost heap**, outside the untyped regions, the state block (hence the ASID table), the +`OS` slots, the VCPU objects and the user frames. Nothing of `PtHG`, `DelIn`, `ArmDecHyps` or any a64 statement +changes: the decode's table set is `Pt ∪ Kt` over the heap `KtH H Kt` (`H` with the kernel tables). + +* **[P] `KTab ar Kt KLv`** (the one new named premise): every kernel TTBR1 level-0 entry `i < 511` that is a table + descriptor names a table of `Kt`, at kernel level `KLv = 1` — the boot memory the kernel's TTBR1 L1..L3 tables + live in (fl4-arch-aarch64 mmu.rs:280–311, `KERNEL_L0` / `KERNEL_L1_TOP`; read by vspace.rs:283–297). + **`KTab.empty`** (an arch with no table entry, e.g. the default `Arch` stub, machine.rs:67). +* **`KtH H Kt`**: `H` with an `other 12` object at every table of `Kt`; **`KtH.empty`** (`KtH H ∅ = H`). +* **`KtOut`** (record): the placement of `Kt` the audit reads — 4 KiB aligned, no wrap, non-null, fresh against + `H`'s objects and each other, off the nodes and the whole state block, outside every untyped cap's region, off the + `OS` slots, the VCPU objects `Vc` and the user words `Ub`. **`KtOut.empty`**. +* **The audit** (every invariant of the bundle admits the kernel tables): **`KtOut.addOKP`** (QueueHeapAdd's + `AddOKP`), **`KtOut.heapOK`**, **`KtOut.osok`**, **`KtOut.ksOff`** (`HeapKsOff`), **`KtOut.ptHG`** (`PtHG` at + `Pt ∪ Kt`), **`S1aPtCol.addKt`** (`PtCap` / `PtHG` / `HiCap511`), **`SymL.addKt`**, **`SysL.addKt`** (`SysZ` with + `ValidUntypedA` / `UtRV` — the untyped disjointness — by `KtOut.ut`; `LiveNamed` because no `other` object is live, + MdbPoolG's `LiveQ.monoK`; the rest over equal sets or a growing heap, as MdbPoolG's `SysL.growO`), **`KtOut.vrOK`** + (`VrOK` at `Pt ∪ Kt`), **`DelIn.addKt`** (`DelS`, `FinKT` / `TyK` monotone in the table set, `VcTy`), assembled as + **`KtBundle.addKt`** over the record **`KtBundle`** (`SysL ∧ SymL ∧ DelIn ∧ HeapKsOff ∧ S1aPtCol`; `HeapOK` is + `DelIn.del.heap`). No invariant needs the kernel tables to be capless (no clause reads a cap naming them); capless + is a property of the witness (S1aBootK). +* **`VsTy.addZ`** (a table with no table descriptor joins `Tb` at any level) and **`VsTy.assign2`** (the tag-2 pool + write of ASIDPool Assign: the root `R` joins `Tb` at level 0; its entries `0 … 510` are kernel TTBR1 L0 copies, + typed by `KTab` and `Kt ⊆ Tb` at `KLv`, its entry 511 its own level-1 table): `VsTy` at `L.wr s w v` over + `insert R Tb`. With F1, `Tb ⊆ Pt ∪ Kt` is compatible with `PtHG` / `VrOK` (B2's counterexample is gone; the + non-vacuous instance is S1aBootK's `w1K_assign2`). +* **`TeH H Te Re bits n`** (the authorised `Te`–`H` link, one named case fact of the `hvs` witness): every Stage-2 + object of `Te` is an `other (bits p)` object of the typed heap, and a top-level one (`Re p + 1 = s2lv n`, a + Stage-2 root) has 13 bits (`STAGE2_VSPACE = 13`, fl4-abi consts.rs:98). **`TeH.hD`** (no object at a 13-bit + object's upper granule: `HeapOK.disj` / `fits`), `hR` its second half; **`S2DecTy.ofTeH`** (S1aS2Dec's + `S2DecTy.ofS2Ty` with both); **`S1aDecHyps.ofT`**: S1aPtCol's `S1aDecHyps.of` with the Stage-2 half of `hvs` in + QueueS2Ty's terms (`S2Ty` + `S2OK` + `TeH`, granules `Gran Te bits ⊆ Pt`), for S1aStepH's `s1aStepH`. + +Named premises: **[P] `KTab`** (new). Case facts: `TeH` (new, authorised); `KtOut` is the hypothesis record of the +audit lemmas (the ruled placement of the kernel tables), not a premise of any top. +-/ +import Fl4ProofsA64.P1.S1aPtCol +import Fl4ProofsA64.P1.S1aVsUnm +import Fl4ProofsA64.P1.S1aS2Dec +import Fl4ProofsA64.P1.MdbPoolG +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} {Cs : Set U64} + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST + +/-! ## The platform contract -/ + +/-- **The kernel TTBR1 boot tables** (module docstring). -/ +structure KTab {A : Type _} (ar : machine.Arch A) (Kt : Set U64) (KLv : U64 → Nat) : Prop where + /-- **[P]** A kernel TTBR1 level-0 entry `i < 511` (what `init_high_vspace` copies, vspace.rs:283–297) that is a + table descriptor names a level-1 table of `Kt`: the kernel's TTBR1 L1..L3 tables are static boot memory + (fl4-arch-aarch64 mmu.rs:280–311), outside every untyped region, the state block, the slots and the user frames. -/ + l0 : ∀ (a : A) (i e : U64), i.val < 511 → ar.kernel_ttbr1_entry a 0#u64 i = ok e → (e &&& 3#u64) = 3#u64 → + wa (e &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt ∧ KLv (wa (e &&& vspace.ADDR_MASK) layout.PPTR_BASE) = 1 + +/-- `KTab` at no kernel table, for an arch with no table descriptor among its kernel level-0 entries. -/ +theorem KTab.empty {A : Type _} {ar : machine.Arch A} (KLv : U64 → Nat) + (h : ∀ (a : A) (i e : U64), i.val < 511 → ar.kernel_ttbr1_entry a 0#u64 i = ok e → (e &&& 3#u64) ≠ 3#u64) : + KTab ar ∅ KLv := + ⟨fun a i e hi he h3 => absurd h3 (h a i e hi he)⟩ + +/-! ## The heap with the kernel tables -/ + +/-- **`H` with an `other 12` object at every kernel table** (module docstring). -/ +noncomputable abbrev KtH (H : Heap) (Kt : Set U64) : Heap := H.add (· ∈ Kt) (.other 12) + +theorem KtH.empty : KtH H ∅ = H := funext fun q => + Heap.add_of_not (H := H) (N := (· ∈ (∅ : Set U64))) (kd := .other 12) (q := q) (by simp) + +variable (st) in +/-- **The kernel tables' placement** (module docstring; the audit's hypotheses). -/ +structure KtOut (H : Heap) (Cs OS Vc Ub Kt : Set U64) (s : S) : Prop where + al : ∀ q ∈ Kt, q.val % 4096 = 0 + fits : ∀ q ∈ Kt, q.val + 4096 ≤ 2 ^ 64 + nz : ∀ q ∈ Kt, q ≠ 0#u64 + fresh : ∀ q ∈ Kt, ∀ p k, H p = some k → q.val + 4096 ≤ p.val ∨ p.val + 2 ^ k.bits ≤ q.val + disj : ∀ q ∈ Kt, ∀ q' ∈ Kt, q ≠ q' → q.val + 4096 ≤ q'.val ∨ q'.val + 4096 ≤ q.val + nodes : ∀ q ∈ Kt, ∀ c ∈ Cs, q.val + 4096 ≤ L.nodeBase s c ∨ L.nodeBase s c + 4288 ≤ q.val + ks : ∀ q ∈ Kt, q.val + 4096 ≤ (L.ksb s).val ∨ (L.ksb s).val + 788736 ≤ q.val + ut : ∀ q ∈ Kt, ∀ u ∈ OS, ∀ p b i d, capA st s u = .Untyped p b i d → q.val + 4096 ≤ p.val ∨ p.val + 2 ^ b.val ≤ q.val + os : ∀ q ∈ Kt, ∀ y ∈ OS, q.val + 4096 ≤ y.val ∨ y.val + 32 ≤ q.val + vc : ∀ q ∈ Kt, ∀ v ∈ Vc, q.val + 4096 ≤ v.val ∨ v.val + 4096 ≤ q.val + ub : ∀ q ∈ Kt, ∀ b ∈ Ub, b.val < q.val ∨ q.val + 4096 ≤ b.val + +variable {OS Vc Ub Pt Kt : Set U64} {s : S} + +theorem KtOut.empty : KtOut st H Cs OS Vc Ub ∅ s := + ⟨fun _ h => by simp at h, fun _ h => by simp at h, fun _ h => by simp at h, fun _ h => by simp at h, + fun _ h => by simp at h, fun _ h => by simp at h, fun _ h => by simp at h, fun _ h => by simp at h, + fun _ h => by simp at h, fun _ h => by simp at h, fun _ h => by simp at h⟩ + +theorem two12 : (2 : Nat) ^ (HKind.other 12).bits = 4096 := by simp [HKind.bits] + +/-- **QueueHeapAdd's `AddOKP` for the kernel tables.** -/ +theorem KtOut.addOKP (X : KtOut st H Cs OS Vc Ub Kt s) : AddOKP st H (· ∈ Kt) (.other 12) Cs s where + fresh q hq := by + cases e : H q with + | none => rfl + | some k => + have := X.fresh q hq q k e + have := @Nat.one_le_two_pow k.bits + exfalso; omega + align q hq := by rw [two12]; exact X.al q hq + fits q hq := by rw [two12]; exact X.fits q hq + nz q hq := X.nz q hq + disjH q hq p kp hp := by rw [two12]; exact X.fresh q hq p kp hp + disjN q q' hq hq' hne := by rw [two12]; exact X.disj q hq q' hq' hne + nodes q hq c hc := by rw [two12]; exact X.nodes q hq c hc + ks q hq := by + rw [two12] + rcases X.ks q hq with h | h + · exact Or.inl h + · exact Or.inr (by omega) + +theorem KtOut.hg (X : KtOut st H Cs OS Vc Ub Kt s) : ∀ q k, H q = some k → KtH H Kt q = some k := fun q k hq => + (Heap.add_of_not (H := H) (N := (· ∈ Kt)) (kd := .other 12) (q := q) + (fun hn => by rw [X.addOKP.fresh q hn] at hq; cases hq)).trans hq + +/-! ## The audit -/ + +/-- **`HeapOK` with the kernel tables.** -/ +theorem KtOut.heapOK (X : KtOut st H Cs OS Vc Ub Kt s) (hH : HeapOK H) : HeapOK (KtH H Kt) := by + have A := X.addOKP + refine ⟨fun q k hq => ?_, fun q k hq => ?_, fun q k hq => ?_, fun q z hq => ?_, fun q k r kr hq hr hne => ?_⟩ + · rcases Heap.add_eq_some.1 hq with ⟨hn, rfl⟩ | ⟨-, hq'⟩ + · exact A.align q hn + · exact hH.align q k hq' + · rcases Heap.add_eq_some.1 hq with ⟨hn, rfl⟩ | ⟨-, hq'⟩ + · exact A.fits q hn + · exact hH.fits q k hq' + · rcases Heap.add_eq_some.1 hq with ⟨-, rfl⟩ | ⟨-, hq'⟩ + · show 12 < 64; omega + · exact hH.lt64 q k hq' + · rcases Heap.add_eq_some.1 hq with ⟨-, h⟩ | ⟨-, hq'⟩ + · cases h + · exact hH.scmin q z hq' + · rcases Heap.add_eq_some.1 hq with ⟨e, rfl⟩ | ⟨-, hq'⟩ <;> + rcases Heap.add_eq_some.1 hr with ⟨e', rfl⟩ | ⟨-, hr'⟩ + · exact A.disjN q r e e' hne + · exact A.disjH q e r kr hr' + · exact (A.disjH r e' q k hq').symm + · exact hH.disj q k r kr hq' hr' hne + +/-- **`OSOK` with the kernel tables** (the `Ω` words grow, the frame words and TCBs are equal). -/ +theorem KtOut.osok (X : KtOut st H Cs OS Vc Ub Kt s) (hO : OSOK H.tcbs H.omega H.frame OS) : + OSOK (KtH H Kt).tcbs (KtH H Kt).omega (KtH H Kt).frame OS := + hO.mono fun b hb' => by + rcases hb' with h | ⟨h1, h2⟩ + · left; rw [X.addOKP.tcbs_eq (by simp)]; exact h + · right; exact ⟨X.addOKP.omega_sub h1, by rw [X.addOKP.frame_eq_other]; exact h2⟩ + +/-- **`HeapKsOff` with the kernel tables** (they lie off the whole state block). -/ +theorem KtOut.ksOff (X : KtOut st H Cs OS Vc Ub Kt s) (hK : HeapKsOff H (L.ksb s)) : + HeapKsOff (KtH H Kt) (L.ksb s) := by + refine ⟨fun p k hp hk => ?_, fun p z hp => ?_⟩ + · rcases Heap.add_eq_some.1 hp with ⟨-, rfl⟩ | ⟨-, hp'⟩ + · exact absurd rfl (hk 12) + · exact hK.1 p k hp' hk + · rcases Heap.add_eq_some.1 hp with ⟨hn, e⟩ | ⟨-, hp'⟩ + · cases e + have e12 : (2 : Nat) ^ 12 = 4096 := by norm_num + rw [e12] + rcases X.ks p hn with h | h + · exact Or.inl h + · exact Or.inr (Or.inl h) + · exact hK.2 p z hp' + +/-- **`PtHG` at `Pt ∪ Kt`**: the kernel tables are their own `other 12` objects. -/ +theorem KtOut.ptHG (X : KtOut st H Cs OS Vc Ub Kt s) (h : PtHG H Pt) : PtHG (KtH H Kt) (Pt ∪ Kt) := + PtHG.union (h.grow X.hg) fun q hq => + ⟨X.al q hq, q, 12, Heap.add_of_mem (H := H) (N := (· ∈ Kt)) (kd := .other 12) hq, le_refl _, by norm_num⟩ + +/-- **S1A's page-table column at `Pt ∪ Kt`** (`PtCap` grows with the set, `HiCap511` reads no heap). -/ +theorem S1aPtCol.addKt (X : KtOut st H Cs OS Vc Ub Kt s) (C : S1aPtCol st H OS Pt s) : + S1aPtCol st (KtH H Kt) OS (Pt ∪ Kt) s := + ⟨fun y hy p m a v hc => Or.inl (C.cap y hy p m a v hc), X.ptHG C.ph, C.hi⟩ + +/-- **`SymL` with the kernel tables** (TCBs and SCs are equal). -/ +theorem SymL.addKt (X : KtOut st H Cs OS Vc Ub Kt s) (Y : SymL st H Cs s) : SymL st (KtH H Kt) Cs s := + ⟨by rw [X.addOKP.tcbs_eq (by simp)]; exact Y.dbg, + by rw [X.addOKP.tcbs_eq (by simp), X.addOKP.scs_eq (by simp)]; exact Y.yld⟩ + +set_option maxHeartbeats 4000000 in +/-- **`SysL` with the kernel tables** (module docstring; MdbPoolG's `SysL.growO` without the untyped). -/ +theorem SysL.addKt {ia ie : Nat} (X : KtOut st H Cs OS Vc Ub Kt s) (B : SysL st H Cs OS ia ie s) : + SysL st (KtH H Kt) Cs OS ia ie s := by + have A := X.addOKP + have eT : (KtH H Kt).tcbs = H.tcbs := A.tcbs_eq (by simp) + have eS : (KtH H Kt).scs = H.scs := A.scs_eq (by simp) + have eR : (KtH H Kt).replies = H.replies := A.replies_eq (by simp) + have hg := X.hg + have hV : ValidUntypedA st (KtH H Kt) OS s := by + intro u hu p' b' i' hcu q k hq + rcases Heap.add_eq_some.1 hq with ⟨hn, rfl⟩ | ⟨-, hq'⟩ + · have := X.ut q hn u hu p' b' i' false hcu + rw [two12]; omega + · exact B.sys.stz.1.2.2.1 u hu p' b' i' hcu q k hq' + have hUR : UtRV st (KtH H Kt) OS s := by + intro u hu p' b' i' d' hcu + obtain ⟨h1, h2⟩ := B.sys.ur u hu p' b' i' d' hcu + refine ⟨h1, fun hd q k hq hm => ?_⟩ + rcases Heap.add_eq_some.1 hq with ⟨hn, rfl⟩ | ⟨-, hq'⟩ + · exfalso + have := X.ut q hn u hu p' b' i' d' hcu + unfold MeetsR at hm + rw [two12] at hm + omega + · exact h2 hd q k hq' hm + have hLN : LiveNamed st (KtH H Kt) Cs OS ia ie s := fun q k hq hl hia => by + rcases Heap.add_eq_some.1 hq with ⟨-, rfl⟩ | ⟨-, hq'⟩ + · rcases LiveQ.kind hl hq with h | h | h | h | ⟨z, h⟩ <;> cases h + · refine B.ln q k hq' (LiveQ.monoK (fun r kr hr hnk => ?_) hl) hia + rcases Heap.add_eq_some.1 hr with ⟨-, rfl⟩ | ⟨-, hr'⟩ + · exact absurd rfl (hnk 12) + · exact hr' + have hVR : ValidReplies st (KtH H Kt) s := by + obtain ⟨a1, a2, a3, a4, a5, a6, a7⟩ := B.vr + refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ <;> (try rw [eS]) <;> (try rw [eR]) <;> assumption + 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 + 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, + 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)⟩ + +/-- A word of `Pt ∪ Kt`'s tables or the ASID table: a `VsR … Pt` word or a kernel-table word (no wrap). -/ +theorem KtOut.vsr (X : KtOut st H Cs OS Vc Ub Kt s) {kb b : U64} (hb : VsR kb (Pt ∪ Kt) b) : + VsR kb Pt b ∨ ∃ q ∈ Kt, ∃ o : U64, o.val < 4096 ∧ o.val % 8 = 0 ∧ b = wa q o ∧ b.val = q.val + o.val := by + rcases hb with ⟨p, hp | hp, o, ho, h8, rfl⟩ | hb + · exact Or.inl (Or.inl ⟨p, hp, o, ho, h8, rfl⟩) + · exact Or.inr ⟨p, hp, o, ho, h8, rfl, wadd_val (by have := X.fits p hp; omega)⟩ + · exact Or.inl (Or.inr hb) + +/-- **`VrOK` at `Pt ∪ Kt` over the heap with the kernel tables** (module docstring). -/ +theorem KtOut.vrOK (X : KtOut st H Cs OS Vc Ub Kt s) (hvf : ∀ v ∈ Vc, v.val + 4096 ≤ 2 ^ 64) + (hkw : (L.ksb s).val + 788736 ≤ 2 ^ 64) (R : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) : + VrOK (KtH H Kt).omega (KtH H Kt).frame (KtH H Kt).scs (KtH H Kt).scBits OS Vc Ub (L.ksb s) (Pt ∪ Kt) := by + have A := X.addOKP + rw [A.frame_eq_other, A.scs_eq (by simp), A.scBits_eq (by simp)] + have al : ∀ q ∈ Kt, ∀ o : U64, o.val % 8 = 0 → (wa q o).val = q.val + o.val → Aligned (wa q o) := + fun q hq o h8 hv => by show (wa q o).val % 8 = 0; rw [hv]; have := X.al q hq; omega + refine ⟨fun b hb => ?_, fun b hb => ?_, fun b hb => ?_, fun b hb c hc => ?_, fun b hb => ?_, fun b hb => ?_, + fun b hb => ?_, fun b hb o ho => ?_⟩ <;> rcases X.vsr hb with hb | ⟨q, hq, o', ho', h8', rfl, hv⟩ + · exact R.al _ hb + · exact al q hq o' h8' hv + · exact A.omega_sub (R.om _ hb) + · refine ⟨al q hq o' h8' hv, q, .other 12, Heap.add_of_mem (H := H) (N := (· ∈ Kt)) (kd := .other 12) hq, + Or.inr (Or.inr (Or.inl ⟨12, rfl⟩)), ?_, ?_⟩ + · rw [hv]; omega + · rw [hv, two12]; omega + · exact R.sg _ hb + · rintro ⟨-, p, k, hp, -, i1, i2⟩ + have := X.fresh q hq p k hp + rw [hv] at i1 i2; omega + · exact R.sc _ hb c hc + · obtain ⟨z, hz⟩ := hc + rintro ⟨i1, i2⟩ + rw [Heap.scBits_eq hz] at i2 + have := X.fresh q hq c _ hz + simp only [HKind.bits] at this + rw [hv] at i1 i2; omega + · exact R.os _ hb + · rintro ⟨y, hy, i1, i2⟩ + have := X.os q hq y hy + rw [hv] at i1 i2; omega + · exact R.vc _ hb + · rintro ⟨v, hv', o2, ho2, -, e⟩ + have := X.vc q hq v hv' + have hf := hvf v hv' + have e2 := congrArg UScalar.val e + rw [hv, wadd_val (by omega)] at e2; omega + · exact R.ub _ hb + · intro hu + have := X.ub q hq _ hu + rw [hv] at this; omega + · exact R.ks _ hb o ho + · intro e + have := X.ks q hq + have e2 := congrArg UScalar.val e + rw [hv, wadd_val (by omega)] at e2; omega + +theorem vsr_unionK {kb b : U64} (hb : VsR kb Pt b) : VsR kb (Pt ∪ Kt) b := + hb.imp_left (ptw_mono Set.subset_union_left) + +/-- **`DelIn` at `Pt ∪ Kt` over the heap with the kernel tables** (module docstring). -/ +theorem DelIn.addKt {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (X : KtOut st H Cs OS Vc Ub Kt s) + (hkw : (L.ksb s).val + 788736 ≤ 2 ^ 64) : DelIn st ar (KtH H Kt) Cs OS Vc Ub (Pt ∪ Kt) K Ty s := by + have A := X.addOKP + have eT : (KtH H Kt).tcbs = H.tcbs := A.tcbs_eq (by simp) + have eS : (KtH H Kt).scs = H.scs := A.scs_eq (by simp) + have eZ : (KtH H Kt).scBits = H.scBits := A.scBits_eq (by simp) + have eF : (KtH H Kt).frame = H.frame := A.frame_eq_other + have E := I.del + refine ⟨⟨E.arch, X.heapOK E.heap, X.osok E.os, by rw [eS, eZ]; exact E.sca, by rw [eT, eS, eZ]; exact E.vc, + E.dom, E.dcan, fun b hb => A.omega_sub (E.ub b hb), X.vrOK E.vc.fit hkw E.vr, E.wu, E.irq, E.irqSt⟩, + fun s' a c fin hy hk hc => WP.spec_mono (I.fin s' a c fin hy hk hc) fun _ ⟨h1, h2, h3⟩ => + ⟨h1, h2.mono fun b hb => vsr_unionK hb, h3⟩, + fun s1 s2 hy k => I.tyk s1 s2 hy fun b hb => k b (vsr_unionK hb), I.kl, I.kv, I.s2, + by rw [eT]; exact I.ts, ?_, I.ty, I.irq, I.vcc, I.fu⟩ + rw [eT, eF, eS, eZ] + have V := I.vty + exact ⟨fun v hv => ⟨fun o h1 h2 => ⟨((V.obj v hv).1 o h1 h2).1, A.omega_sub ((V.obj v hv).1 o h1 h2).2.1, + ((V.obj v hv).1 o h1 h2).2.2⟩, (V.obj v hv).2⟩, V.bnd, V.run, + fun b hb => ⟨(V.usr b hb).out, fun e he => (V.usr b hb).eps e + (he.imp (fun h => (A.some_ne (by simp)).1 h) fun h => (A.some_ne (by simp)).1 h), (V.usr b hb).sg, + (V.usr b hb).ks, (V.usr b hb).sc⟩, V.buf, V.ks⟩ + +/-- **The bundle the kernel tables must not break** (Architect ruling on K0, item 1). -/ +structure KtBundle (st : machine.Store S) [L : LawfulStore st] {A : Type _} (ar : machine.Arch A) (H : Heap) + (Cs OS Vc Ub Pt : Set U64) (K : capability.Cap → Prop) (Ty : S → Prop) (ia ie : Nat) (s : S) : Prop where + sys : SysL st H Cs OS ia ie s + sym : SymL st H Cs s + del : DelIn st ar H Cs OS Vc Ub Pt K Ty s + hks : HeapKsOff H (L.ksb s) + col : S1aPtCol st H OS Pt s + +/-- **The audit**: the bundle holds with the kernel tables added (module docstring). -/ +theorem KtBundle.addKt {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} {ia ie : Nat} + (Bd : KtBundle st ar H Cs OS Vc Ub Pt K Ty ia ie s) (X : KtOut st H Cs OS Vc Ub Kt s) : + KtBundle st ar (KtH H Kt) Cs OS Vc Ub (Pt ∪ Kt) K Ty ia ie s := + ⟨SysL.addKt X Bd.sys, SymL.addKt X Bd.sym, DelIn.addKt Bd.del X Bd.sys.ly.ksw, X.ksOff Bd.hks, + S1aPtCol.addKt X Bd.col⟩ + +/-! ## `VsTy` with a new table, and across the tag-2 Assign -/ + +/-- **A table with no table descriptor joins `Tb`** at any level. -/ +theorem VsTy.addZ {kb t : U64} {Pp Tb : Set U64} {Lv : U64 → Nat} (h : VsTy st kb Pp Tb Lv s) (ht : t ∉ Tb) + (l : Nat) (hz : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → (L.mem s (wa t o) &&& 3#u64) ≠ 3#u64) : + VsTy st kb Pp (insert t Tb) (Function.update Lv t l) s := by + have e : ∀ q ∈ Tb, Function.update Lv t l q = Lv q := fun q hq => + Function.update_of_ne (fun h => ht (by rw [← h]; exact hq)) _ _ + refine ⟨h.tbl, fun p hp o ho h8 hne => ?_, fun p hp hl o ho h8 h3 => ?_⟩ + · obtain ⟨a1, a2⟩ := h.pool p hp o ho h8 hne + exact ⟨fun h0 => let ⟨m, lv⟩ := a1 h0; ⟨Set.mem_insert_of_mem _ m, (e _ m).trans lv⟩, + fun h2 => let ⟨m, lv⟩ := a2 h2; ⟨Set.mem_insert_of_mem _ m, (e _ m).trans lv⟩⟩ + · rcases hp with rfl | hp + · exact absurd h3 (hz o ho h8) + · rw [e p hp] at hl ⊢ + obtain ⟨m, lv⟩ := h.desc p hp hl o ho h8 h3 + exact ⟨Set.mem_insert_of_mem _ m, by rw [e _ m]; exact lv⟩ + +/-- **`VsTy` across the tag-2 pool write of ASIDPool Assign** (module docstring): the root `R` joins `Tb` at level 0; +its entries `0 … 510` are kernel TTBR1 level-0 copies (typed by `KTab` and the kernel tables in `Tb` at `KLv`), its +entry 511 names a level-1 table of `Tb`. -/ +theorem VsTy.assign2 {A : Type _} {ar : machine.Arch A} {kb R w v : U64} {Pp Tb : Set U64} {Lv KLv : U64 → Nat} + (h : VsTy st kb Pp Tb Lv s) (hK : KTab ar Kt KLv) (hKt : ∀ t ∈ Kt, t ∈ Tb ∧ Lv t = KLv t) + (hroot : ∀ o : U64, o.val < 4088 → o.val % 8 = 0 → (L.mem s (wa R o) &&& 3#u64) = 3#u64 → + ∃ (a : A) (i : U64), i.val < 511 ∧ ar.kernel_ttbr1_entry a 0#u64 i = ok (L.mem s (wa R o))) + (h511 : (L.mem s (wa R 4088#u64) &&& 3#u64) = 3#u64 → + wa (L.mem s (wa R 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Tb ∧ + Lv (wa (L.mem s (wa R 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE) = 1) + (hR : R ∈ Tb → Lv R = 0) (hv2 : (v &&& 3#u64) = 2#u64) (hvR : (v &&& ~~~3#u64) = R) + (hwA : ¬ AsW kb w) (hwT : ¬ PtW (insert R Tb) w) (hal : Aligned w) + (hall : ∀ b, VsR kb (insert R Tb ∪ Pp) b → Aligned b) : + VsTy st kb Pp (insert R Tb) (Function.update Lv R 0) (L.wr s w v) := by + have e : ∀ q ∈ Tb, Function.update Lv R 0 q = Lv q := fun q hq => by + by_cases hq' : q = R + · subst hq'; simp [hR hq] + · exact Function.update_of_ne hq' _ _ + have rd : ∀ b, VsR kb (insert R Tb ∪ Pp) b → b ≠ w → L.mem (L.wr s w v) b = L.mem s b := fun b hb hne => + L.mem_wr_ne hal (hall b hb) fun hv => hne (UScalar.eq_of_val_eq hv).symm + refine ⟨fun o h1 h2 h8 hne => ?_, fun p hp o ho h8 hne => ?_, fun p hp hl o ho h8 h3 => ?_⟩ + · have hA : AsW kb (wa kb o) := ⟨o, h1, h2, h8, rfl⟩ + have hn : wa kb o ≠ w := fun ew => hwA (ew ▸ hA) + rw [rd _ (Or.inr hA) hn] at hne ⊢ + exact h.tbl o h1 h2 h8 hne + · have hW : VsR kb (insert R Tb ∪ Pp) (wa p o) := Or.inl ⟨p, Or.inr hp, o, ho, h8, rfl⟩ + by_cases ew : wa p o = w + · rw [ew, L.mem_wr_same hal] + refine ⟨fun h0 => ?_, fun _ => ?_⟩ + · exfalso; rw [hv2] at h0; have := congrArg UScalar.val h0; simp at this + · rw [hvR]; exact ⟨Set.mem_insert _ _, by simp⟩ + · rw [rd _ hW ew] at hne ⊢ + obtain ⟨a1, a2⟩ := h.pool p hp o ho h8 hne + exact ⟨fun h0 => let ⟨m, lv⟩ := a1 h0; ⟨Set.mem_insert_of_mem _ m, (e _ m).trans lv⟩, + fun h2 => let ⟨m, lv⟩ := a2 h2; ⟨Set.mem_insert_of_mem _ m, (e _ m).trans lv⟩⟩ + · have hW : VsR kb (insert R Tb ∪ Pp) (wa p o) := Or.inl ⟨p, Or.inl hp, o, ho, h8, rfl⟩ + have hT : PtW (insert R Tb) (wa p o) := ⟨p, hp, o, ho, h8, rfl⟩ + have ew : wa p o ≠ w := fun ew => hwT (ew ▸ hT) + rw [rd _ hW ew] at h3 ⊢ + by_cases hpR : p = R + · subst hpR + have hu : Function.update Lv p 0 p = 0 := by simp + rw [hu] + by_cases h88 : o.val < 4088 + · obtain ⟨a, i, hi, he⟩ := hroot o h88 h8 h3 + obtain ⟨m, kl⟩ := hK.l0 a i _ hi he h3 + obtain ⟨m', lv⟩ := hKt _ m + exact ⟨Set.mem_insert_of_mem _ m', by rw [e _ m', lv, kl]⟩ + · have h48 : (4088#u64 : U64).val = 4088 := by simp + have eo : o = 4088#u64 := UScalar.eq_of_val_eq (by rw [h48]; omega) + subst eo + obtain ⟨m, lv⟩ := h511 h3 + exact ⟨Set.mem_insert_of_mem _ m, by rw [e _ m, lv]⟩ + · have hp' : p ∈ Tb := hp.resolve_left hpR + rw [e p hp'] at hl ⊢ + obtain ⟨m, lv⟩ := h.desc p hp' hl o ho h8 h3 + exact ⟨Set.mem_insert_of_mem _ m, by rw [e _ m]; exact lv⟩ + +/-! ## The `Te`–`H` link and `hR` / `hD` -/ + +/-- The kernel tables are `other 12` objects of `KtH H Kt`. -/ +theorem KtH.kt {Kt : Set U64} : ∀ t ∈ Kt, KtH H Kt t = some (.other 12) := fun _ ht => Heap.add_of_mem ht + +section dec +variable {Rp Nt : Set U64} {ia ie : Nat} + +/-- **`S1aDecHyps.of` with the Stage-2 half of `hvs` in QueueS2Ty's terms** (module docstring; `S2DecTy.ofTeH`). -/ +theorem S1aDecHyps.ofT {n : U64} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (cs : L.mem s (scA (L.curW s)) ≠ 0#u64) + (fh : ∀ t, cap = .Thread t → NullOrEp H (capA st s (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) + (hvs : ∃ (Pp Tb : Set U64) (Lv : U64 → Nat) (Hr Te : Set U64) (Re bits : U64 → Nat), Pp ⊆ Pt ∧ Tb ⊆ Pt ∧ + Gran Te bits ⊆ Pt ∧ VsTy st (L.ksb s) Pp Tb Lv s ∧ NoTag3 st Pp s ∧ HighRoot511 st Pp s ∧ + S2Ty st n Pp Hr Te Re bits s ∧ S2OK Te bits Hr ∧ TeH H Te Re bits n) + (C : S1aPtCol st H OS Pt s) (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok cap) (hdf : DevFrAl st OS s) : + S1aDecHyps st H Pt n s cap := + let ⟨Pp, Tb, Lv, _, Te, Re, bits, h1, h2, h3, ty, hN, hHi, h2t, hS, hT⟩ := hvs + S1aDecHyps.of mcp cs fh ⟨Pp, Tb, Lv, Gran Te bits, s2gRe Te Re, h1, h2, h3, ty, hN, hHi, + S2DecTy.ofTeH P.heap h2t hS hT⟩ C P B hks hcap hdf + +end dec + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aKtArms.lean b/proofs/Fl4ProofsA64/P1/S1aKtArms.lean new file mode 100644 index 000000000..35539728c --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKtArms.lean @@ -0,0 +1,150 @@ +/- +P1 (aarch64, A64-S1A gen 41): the kernel-table column's words through the non-deleting arms (Gate-2 table, D3 C). + +Each arm keeps every descriptor of the `Kt` and header words (`EdgeKeepOn (KtHdrW …)`) by its own memory fact: +`ArmVsK` (slot-keeping, IrqControl, Endpoint, CNode copy family, `DecArmKK3`) and the restart's `VsKeep` (cache). +`DelIn.withVsZ` adds `VsZ` from the entry to the deletion typing, for the deleting arms. + +Named premises: none. New theorems only. +-/ +import Fl4ProofsA64.P1.S1aR2Relabel + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {ia ie : Nat} {A : Type _} + {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {cap : capability.Cap} {slot : U64} + +/-- **The deletion typing with `VsZ` from the entry.** -/ +theorem DelIn.withVsZ {s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) : + DelIn st ar H Cs OS Vc Ub Pt K (fun q => Ty q ∧ VsZ st (L.ksb s) Pt s q) s where + del := I.del + fin := fun q a c fin hy hk hc => + WP.spec_mono (WP.spec_and (I.fin q a c fin hy.1 hk hc) (hKZ q a c fin hy.1 hk hc)) + fun _ ⟨⟨e, w, t⟩, z⟩ => ⟨e, w, t, hy.2.trans z⟩ + tyk := fun _ _ hy k => ⟨I.tyk _ _ hy.1 k, hy.2.trans k.vsz⟩ + kl := I.kl + kv := I.kv + s2 := I.s2 + ts := I.ts + vty := I.vty + ty := ⟨I.ty, VsZ.refl s⟩ + irq := I.irq + vcc := I.vcc + fu := I.fu + +theorem FinKZ.withVsZ {s : S} (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) : + FinKZ st ar (L.ksb s) Pt (fun q => Ty q ∧ VsZ st (L.ksb s) Pt s q) K := + fun q a c fin hy => hKZ q a c fin hy.1 + +section arms +variable {s : S} (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) +include R I + +/-- An `ArmVsK` post keeps the column's words. -/ +theorem EdgeKeepOn.ofArmVsK {s' : S} (mem : ArmVsK st H OS Vc s s') : + EdgeKeepOn st (KtHdrW st OS Kt s) s s' := + EdgeKeepOn.ofVsKeep R (mem.vsKeep I.del.vr I.fu) + +/-- **The slot-keeping invocations keep the column's words.** -/ +theorem syscall.decode_invocation.keepSlots_kt (hA : P0.ArchTotal ar) {lbl : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok cap) + (arm : DecArmR2Keep cap lbl) (a : A) (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' _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := by + have close {m : Result ((core.result.Result Unit error.Exc) × S × A)} + (top : m ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ + OSKeep st OS s s' ⦄) : + m ⦃ _ s' _ => EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := + WP.spec_mono top fun r d => by + obtain ⟨_, _, _⟩ := r + exact EdgeKeepOn.ofArmVsK R I d.2.2.1 + rcases arm with ⟨m, b, sd, rv, rfl⟩ | ⟨t, rfl, hl | hl⟩ | + ⟨v, rfl, hl | hl | hl | hl | hl | hl | hl⟩ | ⟨p, sz, r, d, m, e, asid, va, rfl, hl⟩ + · exact close (syscall.decode_invocation.ntfn_armSAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + · exact close (syscall.decode_invocation.suspend_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.readRegs_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.run_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.ackVppi_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.vcWr_armSAt hA I D P B Y hks hcap a (Or.inl hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.vcWr_armSAt hA I D P B Y hks hcap a (Or.inr hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.vcSt_armSAt hA I D P B Y hks hcap a (Or.inl hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.vcSt_armSAt hA I D P B Y hks hcap a (Or.inr hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.setTcb_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.getAddr_armSAt I D P B Y hks a hl len blk call don fp buf) + +/-- **IrqControl keeps the column's words.** -/ +theorem syscall.decode_invocation.irqCtl_kt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s .IrqControl 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 .IrqControl) (a : A) (lbl len : U64) + (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot .IrqControl blk call don fp buf extra ⦃ _ s' _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := + WP.spec_mono (syscall.decode_invocation.irqCtl_armSAt hA hM I D P B Y hcap a lbl len blk call don fp buf) + fun r d => by + obtain ⟨_, _, _⟩ := r + exact EdgeKeepOn.ofArmVsK R I d.2.2.1 + +/-- **The endpoint invocation keeps the column's words.** -/ +theorem syscall.decode_invocation.endpoint_kt (hA : P0.ArchTotal ar) {e b : U64} {sd rv g gr : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Endpoint e b sd rv g gr) + extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (hcap : obj.Slot.cap st slot s = ok (.Endpoint e b sd rv g gr)) (a : A) (lbl len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Endpoint e b sd rv g gr) blk call don fp buf extra + ⦃ _ s' _ => EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := + WP.spec_mono (syscall.decode_invocation.ep_armSAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + fun r d => by + obtain ⟨_, _, _⟩ := r + exact EdgeKeepOn.ofArmVsK R I d.2.2.1 + +/-- **The CNode copy family keeps the column's words.** -/ +theorem syscall.decode_invocation.cnodeCopy_kt {lbl : U64} {c : capability.Cap} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s c 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) (source : obj.Slot.cap st slot s = ok c) (family : capFam c = .cnode) + (labels : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot c blk call don fp buf extra ⦃ _ s' _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := + WP.spec_mono (syscall.decode_invocation.cnode_armQIKAt D P B Y I.del.vr a len blk call don fp buf labels family + source) fun _ ⟨_, _, mem⟩ => EdgeKeepOn.ofVsKeep R (mem.vsKeep I.del.vr I.fu) + +/-- **The `DecArmKK3` keeping arms keep the column's words.** -/ +theorem syscall.decode_invocation.keeping_kt (hA : P0.ArchTotal ar) {lbl : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (source : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) + (sc : L.mem s (scA (L.curW s)) ≠ 0#u64) (arm : DecArmKK3 cap lbl) + (a : A) (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' _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := + WP.spec_mono (syscall.decode_invocation.armKK3At hA I D P B Y source hks mcp sc a arm len blk call don fp buf) + fun _ ⟨_, _, _, mem⟩ => EdgeKeepOn.ofVsKeep R (mem.vsKeep I.del.vr I.fu) + +/-- **The cache-only invocations keep the column's words.** -/ +theorem syscall.decode_invocation.cache_kt (hA : P0.ArchTotal ar) {lbl : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (a : A) (arm : DecArmR2Cache cap lbl) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := + syscall.decode_invocation.cacheInvariant (EdgeKeepOn.refl _ s) + (WP.spec_mono (sched.set_thread_state.unmMid I D) fun _ h => EdgeKeepOn.ofVsKeep R h.2) hA a arm len slot + blk call don fp buf + +end arms + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aKtDelArms.lean b/proofs/Fl4ProofsA64/P1/S1aKtDelArms.lean new file mode 100644 index 000000000..076d59dee --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKtDelArms.lean @@ -0,0 +1,237 @@ +/- +P1 (aarch64, A64-S1A gen 41): R2, the separation and `VsZ` from the entry through the deleting arms (Gate-2 table, +D3 C). + +The arms run at the guarded deletion typing extended by `VsZ` (`DelIn.withVsZ`): every step's `DelR` then carries +`VsZ (ksb s) Pt s`, and the carried predicate is `S1aDelKt ∧ VsZ`. Steps: restart (`DelR`), `cdt.delete.vsZ` / +`cdt.revoke.vsZ`, `cdt.delete_one.s1aTy`, `tcb.install_tcb_cap.delRP`, `tcb.install_buffer.s1aTy`, and an insert's +slot-only writes (`vsk_cw0`). Siblings of the `*_ktR` arms with the extra conjunct. + +Named premises: none. New theorems only. +-/ +import Fl4ProofsA64.P1.S1aKtArms + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {ia ie : Nat} {A : Type _} + {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- The TCB install steps carry `VsZ` from the entry. -/ +theorem S1aTcbSteps.vsZ {s s1 : S} {t slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (ht : t ∈ H.tcbs) (hslot : slot ∈ OS) + (h0 : 0#u64 ∈ Cs) : + S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac (fun q => Ty q ∧ VsZ st (L.ksb s) Pt s q) ia ie s s1 t slot + (fun q => VsZ st (L.ksb s) Pt s q) (fun _ => True) (fun _ => True) where + keep _ _ h _ _ mem _ := h.trans mem.vsz + install _ _ _ _ _ _ R Q Z hi hi2 hi5 hsrc hnc _ := + WP.spec_mono (tcb.install_tcb_cap.delRP (I.withVsZ hKZ) hKZ.withVsZ hPI R Q Z ht hi hi2 hslot hsrc hnc hi5) + fun _ d => d.1.ty.2 + buffer _ _ _ _ _ R hal hbuf _ := + WP.spec_mono (tcb.install_buffer.s1aTy (I.withVsZ hKZ) h0 R ht hslot hal hbuf) fun _ d => d.2 + unread _ _ := True.intro + roots cd vd cs vs _ _ := + WP.spec_mono (tcb.derive_roots.tk s1 t cd vd cs vs) fun _ _ _ _ _ => ⟨True.intro, True.intro⟩ + high _ _ _ _ _ := True.intro + derived baddr bslot _ := WP.spec_mono (tcb.derive_for_buffer.buf s1 baddr bslot) fun _ _ _ _ _ => True.intro + +/-- SetHighVSpace, SetSpace, SetIPCBuffer, Configure and SetTimeoutEndpoint keep R2, the separation and `VsZ`. -/ +theorem syscall.decode_invocation.tcbInstall_ktZ (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetHighVSpace ∨ lbl = fl4_abi.label.TCBSetSpace ∨ + lbl = fl4_abi.label.TCBSetIPCBuffer ∨ lbl = fl4_abi.label.TCBConfigure ∨ + lbl = fl4_abi.label.TCBSetTimeoutEndpoint) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ∧ VsZ st (L.ksb s) Pt s s' ⦄ := by + have J0 := I.forHiDelR hPl W + have z0 := W.finKZ (hPl := hPl) I + have J := J0.withVsZ z0 + have z := z0.withVsZ + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have ht := D.cap.2.1 t rfl + exact WP.spec_mono (syscall.decode_invocation.tcbInstall_phi hA J z hPI D P B Y + (Φ := fun q => (S1aTcbKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s q ∧ S1aKtUt st OS Kt q) ∧ + VsZ st (L.ksb s) Pt s q) + ⟨⟨⟨R.toDelKeep, .refl s⟩, sep⟩, VsZ.refl s⟩ + (fun s1 ds1 => ((S1aTcbSteps.r2 (Re := Re) (Kt := Kt) (Ac := Ac) (ia := ia) (ie := ie) (s1 := s1) (t := t) + (slot := slot) J (fun _ h => h.vsCap) hPl place ptKs z hPI ht P.src P.core0 R.capRefs.refs ds1.1).and + (S1aTcbSteps.ktUt J z hPI ht P.src P.core0)).and (S1aTcbSteps.vsZ J0 z0 hPI ht P.src P.core0)) + a hl len blk call don fp buf) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨⟨h.1.1.1, h.1.2⟩, h.2⟩ + +/-- SetEPTRoot keeps R2, the separation and `VsZ`. -/ +theorem syscall.decode_invocation.setEpt_ktZ (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) (a : A) + (hXE : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∉ EptS H.tcbs) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.TCBSetEPTRoot len slot (.Thread t) blk call don fp buf extra + ⦃ r s' _ => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ∧ VsZ st (L.ksb s) Pt s s' ⦄ := by + have J0 := I.forHiDelR hPl W + have z0 := W.finKZ (hPl := hPl) I + have J := J0.withVsZ z0 + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have entry : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s ∧ VsZ st (L.ksb s) Pt s s := + ⟨⟨R.toDelKeep, sep⟩, VsZ.refl s⟩ + refine syscall.decode_invocation.tcbG + (Φ := fun q => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ∧ VsZ st (L.ksb s) Pt s q) entry + a len blk call don fp buf fun _ _ eq => ?_ + subst eq + refine WP.spec_mono (tcb.decode.setEpt_s1aPhi hA J D P B Y hXE + (Φ := fun q => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ∧ VsZ st (L.ksb s) Pt s q) entry + (fun q r h hq hr mem same => ⟨h.1.osKeep hq hr mem same, h.2.trans mem.vsz⟩) + (fun q a x h Rq hx => WP.spec_mono (WP.spec_and (WP.spec_and + (cdt.delete.r2R J (fun _ h => h.vsCap) hPl place ptKs Rq hx h.1.1) (cdt.delete.ktUtR J Rq hx h.1.2)) + (cdt.delete.vsZ J z0.withVsZ Rq h.2 hx)) fun _ ⟨a, b⟩ => ⟨a, b⟩) + (fun q src dest nc h Rq hs hd ne can source wf empty ept => by + obtain ⟨p, l, m, v, rfl⟩ := ept + have hm := Rq.sys.sys.stz.1.1.mdbS + exact WP.spec_mono (WP.spec_and (WP.spec_and + (cdt.insert_with_cap.r2C I.del.os I.del.vr Rq.jv.ksb hm hs hd ne can source + (fun e => by cases e) wf (fun _ => rfl) (fun _ _ none => by cases none) empty h.1.1) + (cdt.insert_with_cap.ktUt I.del.os hm hs hd ne can source (fun e => by cases e) wf + (fun _ _ _ _ e => by cases e) h.1.2)) + (cdt.insert_with_cap.lrF I.del.os.inOS (LR.self q) hs hd ne can source (fun e => by cases e) wf + (hm.lnk I.del.os hs).2)) fun _ ⟨a, w⟩ => ⟨a, h.2.trans (vsk_cw0 I.del.vr w.1).vsz⟩)) + fun _ h => h.2 + +/-- SetSchedParams keeps R2, the separation and `VsZ`. -/ +theorem syscall.decode_invocation.ssp_ktZ (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + {m : U64} (Hy : ArmDecHyps st H Pt m s (.Thread t)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetSchedParams) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ∧ VsZ st (L.ksb s) Pt s s' ⦄ := by + have J0 := I.forHiDelR hPl W + have z0 := W.finKZ (hPl := hPl) I + have J := J0.withVsZ z0 + have z := z0.withVsZ + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have ht := D.cap.2.1 t rfl + have hi : layout.tcb.SLOT_FAULT_HANDLER.val < 7 := by simp [layout.tcb.SLOT_FAULT_HANDLER] + have hi2 : layout.tcb.SLOT_FAULT_HANDLER.val ≠ 2 := by simp [layout.tcb.SLOT_FAULT_HANDLER] + have hi5 : layout.tcb.SLOT_FAULT_HANDLER.val ≠ 5 := by simp [layout.tcb.SLOT_FAULT_HANDLER] + exact syscall.decode_invocation.ssp_phi hA J z hPI D P B Y hks hcap Hy + (Φ := fun q => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ∧ VsZ st (L.ksb s) Pt s q) + ⟨⟨R.toDelKeep, sep⟩, VsZ.refl s⟩ + (fun q r h hq hr mem keep => ⟨h.1.osKeep hq hr mem keep, h.2.trans mem.vsz⟩) + (fun q a nc src h Rq Qq Zq blk hfh hnc valid hsrc source => WP.spec_mono (WP.spec_and (WP.spec_and + (tcb.install_tcb_cap.r2F J (fun _ h => h.vsCap) hPl place ptKs z hPI Rq Qq blk ht P.src hsrc hnc + hfh (faults.valid_fault_handler.unread valid) source h.1.1) + (tcb.install_tcb_cap.ktUt J z hPI Rq Qq ht hi (fun _ => hsrc) hnc h.1.2)) + (tcb.install_tcb_cap.delRP J z hPI Rq Qq Zq ht hi hi2 P.src (fun _ => hsrc) hnc hi5)) + fun _ ⟨a, d⟩ => ⟨a, d.1.ty.2⟩) + a hl len blk call don fp buf + +/-- CNode Delete and Revoke keep R2, the separation and `VsZ`. -/ +theorem syscall.decode_invocation.cnodeRvDel_ktZ {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) (hPl : ArchPlat ar) + (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa 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) (hf : capFam cap = .cnode) + (hks : HeapKsOff H (L.ksb s)) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (sep : S1aKtUt st OS Kt s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.CNodeRevoke ∨ lbl = fl4_abi.label.CNodeDelete) (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 ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ∧ VsZ st (L.ksb s) Pt s s' ⦄ := by + have J0 := I.forHiDelR hPl W + have z0 := W.finKZ (hPl := hPl) I + have J := J0.withVsZ z0 + have z := z0.withVsZ + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have entry : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s ∧ VsZ st (L.ksb s) Pt s s := + ⟨⟨R.toDelKeep, sep⟩, VsZ.refl s⟩ + have vsK : ∀ c, S2Q c → S1aVsCap c := fun _ h => h.vsCap + refine syscall.decode_invocation.cnodeG + (P := fun q => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ∧ VsZ st (L.ksb s) Pt s q) entry a len + slot cap blk call don fp buf extra hf + (WP.spec_mono (cnode.decode.rvDelPhi J D P B hcap + (Φ := fun q => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ∧ VsZ st (L.ksb s) Pt s q) entry + (WP.spec_mono (WP.spec_and (tcb.restart_caller.r2Keep J D P B Y entry.1.1) + (sched.set_thread_state.restartOs P D)) fun _ ⟨⟨Rq, h⟩, keep⟩ => ⟨Rq, ⟨h, sep.keep keep⟩, Rq.ty.2⟩) + (fun _ _ Rq hx h => WP.spec_mono (WP.spec_and (WP.spec_and + (cdt.delete.r2R J vsK hPl place ptKs Rq hx h.1.1) (cdt.delete.ktUtR J Rq hx h.1.2)) + (cdt.delete.vsZ J z Rq h.2 hx)) fun _ ⟨a, b⟩ => ⟨a, b⟩) + (fun _ _ Rq hx h => WP.spec_mono (WP.spec_and (WP.spec_and + (cdt.revoke.r2R J vsK hPl place ptKs Rq hx h.1.1) (cdt.revoke.ktUtR J Rq hx h.1.2)) + (cdt.revoke.vsZ J z Rq h.2 hx)) fun _ ⟨a, b⟩ => ⟨a, b⟩) + hl) fun r h => by + obtain ⟨_, _, _⟩ := r + exact h) + +/-- IRQ ClearIRQHandler and SetIRQHandler keep R2, the separation and `VsZ`. -/ +theorem syscall.decode_invocation.irqHandler_ktZ {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot irq : U64} + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.IrqHandler irq) 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) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) + (hi : irq.val < 5376) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.IrqHandler irq) blk call don fp buf extra ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ∧ VsZ st (L.ksb s) Pt s s' ⦄ := by + have J := I.withVsZ hKZ + have entry : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s ∧ VsZ st (L.ksb s) Pt s s := + ⟨⟨R.toDelKeep, sep⟩, VsZ.refl s⟩ + have restart := WP.spec_and (tcb.restart_caller.r2Keep J D P B Y entry.1.1) (sched.set_thread_state.restartOs P D) + have one (q : S) (Rq : DelR st H Cs OS Vc Ub Ac (fun q => Ty q ∧ VsZ st (L.ksb s) Pt s q) ia ie s q) + (h : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q ∧ VsZ st (L.ksb s) Pt s q) : + cdt.delete_one st ar q a (irqSlotA (L.ksb s) irq) ⦃ r => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r.1 ∧ VsZ st (L.ksb s) Pt s r.1 ⦄ := + WP.spec_mono (WP.spec_and (WP.spec_and (cdt.delete_one.r2 J Rq a hi h.1.1) (cdt.delete_one.ktUt J Rq a hi h.1.2)) + (cdt.delete_one.s1aTy J Rq a hi)) fun _ ⟨a, b⟩ => ⟨a, b.2⟩ + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + dsimp only + have done : interrupt.decode_irq_handler st ar s a lbl irq extra ⦃ r => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r.2.1 ∧ VsZ st (L.ksb s) Pt s r.2.1 ⦄ := by + rcases hl with hl | hl + · exact interrupt.decode_irq_handler.clearPhi hl + (Φ := fun q => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q ∧ VsZ st (L.ksb s) Pt s q) + (WP.spec_mono restart fun _ ⟨⟨Rq, h⟩, keep⟩ => ⟨Rq, ⟨h, sep.keep keep⟩, Rq.ty.2⟩) one + · refine interrupt.decode_irq_handler.setPhi (cap := .IrqHandler irq) J P B hl hi hSC + (Φ := fun q => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q ∧ VsZ st (L.ksb s) Pt s q) entry + (WP.spec_mono restart fun _ ⟨⟨Rq, h⟩, keep⟩ => ⟨Rq, ⟨⟨h, sep.keep keep⟩, Rq.ty.2⟩, keep⟩) one ?_ + intro q x m b send recv h base hm hx hd apart canon stays hw null + exact WP.spec_mono (WP.spec_and (WP.spec_and (cdt.insert_with_cap.r2 I.del.os I.del.vr base hm hx hd apart + canon stays (fun e => by cases e) hw (fun h => h) (fun h => h) null h.1.1) + (cdt.insert_with_cap.ktUt I.del.os hm hx hd apart canon stays (fun e => by cases e) hw + (fun _ _ _ _ e => by cases e) h.1.2)) + (cdt.insert_with_cap.lrF I.del.os.inOS (LR.self q) hx hd apart canon stays (fun e => by cases e) hw + (hm.lnk I.del.os hx).2)) fun _ ⟨a, w⟩ => ⟨a, h.2.trans (vsk_cw0 I.del.vr w.1).vsz⟩ + exact WP.spec_mono done fun r h => by + obtain ⟨_, _, _⟩ := r + exact h + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aKtLvCol.lean b/proofs/Fl4ProofsA64/P1/S1aKtLvCol.lean new file mode 100644 index 000000000..917f0fe44 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKtLvCol.lean @@ -0,0 +1,110 @@ +/- +P1 (aarch64, A64-S1A gen 41): the kernel-table levels column `S1aHiK` (module `S1aKtLvCol`; not the gen-40 module `S1aHiK`) (Architect ruling D3, form C, 2026-12-03). + +A tag-2 ASIDPool Assign makes the kernel TTBR1 tables `Kt` and the new root's header reachable; R2 types only reachable +tables, so the levels of those tables are carried here, witness-free, at the platform levels `KLv` of `[P] KTab`: + +* `S1aHiK st OS Kt KLv s`: (kt) a table descriptor in a `Kt` table above level 3 names a `Kt` table one level down; + (hdr) a table descriptor in a header word `R + o` (`o < 4088`) of a live HighVSpace cap names a `Kt` table at level 1. +* `S1aHiKeep st OS OS' Kt s s'`: every descriptor of a `Kt` or old-header word at `s'` is that word at `s`, and every + HighVSpace cap of `OS'` at `s'` is one of `OS` at `s` with the same root. `S1aHiK.keep`. +* `EdgeKeepOn`: the word half, from a `VsZ` step (`EdgeKeepOn.ofVsZ`) over R2's footprint. + +Named premises: none. New definitions and theorems only. +-/ +import Fl4ProofsA64.P1.S1aStepR2A + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS OS' Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} + +/-- The table descriptor target of a word. -/ +def kChild (v : U64) : U64 := wa (v &&& vspace.ADDR_MASK) layout.PPTR_BASE + +variable (st) in +/-- **The kernel-table levels column** (module docstring). -/ +structure S1aHiK (OS Kt : Set U64) (KLv : U64 → Nat) (s : S) : Prop where + kt : ∀ t ∈ Kt, KLv t < 3 → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → (L.mem s (wa t o) &&& 3#u64) = 3#u64 → + kChild (L.mem s (wa t o)) ∈ Kt ∧ KLv (kChild (L.mem s (wa t o))) = KLv t + 1 + hdr : ∀ y ∈ OS, ∀ R m a, capA st s y = .HighVSpace R m a → ∀ o : U64, o.val < 4088 → o.val % 8 = 0 → + (L.mem s (wa R o) &&& 3#u64) = 3#u64 → kChild (L.mem s (wa R o)) ∈ Kt ∧ KLv (kChild (L.mem s (wa R o))) = 1 + +variable (st) in +/-- The `Kt` words and the header words of the live HighVSpace roots of `OS` at `s`. -/ +def KtHdrW (OS Kt : Set U64) (s : S) (b : U64) : Prop := + (∃ t ∈ Kt, ∃ o : U64, o.val < 4096 ∧ o.val % 8 = 0 ∧ b = wa t o) ∨ + (∃ R ∈ HvRt st OS s, ∃ o : U64, o.val < 4088 ∧ o.val % 8 = 0 ∧ b = wa R o) + +variable (st) in +/-- Every word of `F` holding a table descriptor at `s'` held one at `s`, to the same table. -/ +def EdgeKeepOn (F : U64 → Prop) (s s' : S) : Prop := + ∀ b, F b → (L.mem s' b &&& 3#u64) = 3#u64 → + (L.mem s b &&& 3#u64) = 3#u64 ∧ kChild (L.mem s' b) = kChild (L.mem s b) + +variable (st) in +/-- **The step relation keeping `S1aHiK`** (module docstring). -/ +def S1aHiKeep (OS OS' Kt : Set U64) (s s' : S) : Prop := + EdgeKeepOn st (KtHdrW st OS Kt s) s s' ∧ + ∀ y ∈ OS', ∀ R m a, capA st s' y = .HighVSpace R m a → R ∈ HvRt st OS s + +/-- **`S1aHiK` along a keeping step.** -/ +theorem S1aHiK.keep {s s' : S} (h : S1aHiK st OS Kt KLv s) (k : S1aHiKeep st OS OS' Kt s s') : + S1aHiK st OS' Kt KLv s' := by + refine ⟨fun t ht hl o ho h8 e => ?_, fun y hy R m a c o ho h8 e => ?_⟩ + · obtain ⟨e0, w⟩ := k.1 _ (Or.inl ⟨t, ht, o, ho, h8, rfl⟩) e + rw [w] + exact h.kt t ht hl o ho h8 e0 + · obtain ⟨y0, hy0, m0, a0, c0⟩ := k.2 y hy R m a c + obtain ⟨e0, w⟩ := k.1 _ (Or.inr ⟨R, ⟨y0, hy0, m0, a0, c0⟩, o, ho, h8, rfl⟩) e + rw [w] + exact h.hdr y0 hy0 R m0 a0 c0 o ho h8 e0 + +theorem EdgeKeepOn.mono {F G : U64 → Prop} {s s' : S} (h : EdgeKeepOn st G s s') (sub : ∀ b, F b → G b) : + EdgeKeepOn st F s s' := fun b hb e => h b (sub b hb) e + +theorem EdgeKeepOn.refl (F : U64 → Prop) (s : S) : EdgeKeepOn st F s s := fun _ _ e => ⟨e, rfl⟩ + +theorem EdgeKeepOn.trans {F : U64 → Prop} {s1 s2 s3 : S} (h1 : EdgeKeepOn st F s1 s2) (h2 : EdgeKeepOn st F s2 s3) : + EdgeKeepOn st F s1 s3 := fun b hb e => by + obtain ⟨e2, c2⟩ := h2 b hb e + obtain ⟨e1, c1⟩ := h1 b hb e2 + exact ⟨e1, c2.trans c1⟩ + +/-- A word kept whenever it holds a descriptor keeps the descriptor. -/ +theorem EdgeKeepOn.ofKept {F : U64 → Prop} {s s' : S} + (h : ∀ b, F b → (L.mem s' b &&& 3#u64) = 3#u64 → L.mem s' b = L.mem s b) : EdgeKeepOn st F s s' := + fun b hb e => by have w := h b hb e; rw [w] at e ⊢; exact ⟨e, rfl⟩ + +/-- **The column's words are R2 footprint words.** -/ +theorem S1aR2.ktHdrW {s : S} (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) {b : U64} + (hb : KtHdrW st OS Kt s b) : PtW Pt b := by + rcases hb with ⟨t, ht, o, ho, h8, rfl⟩ | ⟨r, hr, o, ho, h8, rfl⟩ + · exact ⟨t, R.place.tables (R.kernelTables.1 ht), o, ho, h8, rfl⟩ + · have hr' : r ∈ Hr := R.highRoots ▸ hr + exact ⟨r, R.place.tables (R.place.high.sub hr'), o, by omega, h8, rfl⟩ + +/-- **A `VsZ` step over R2's footprint keeps every descriptor of the column's words.** -/ +theorem EdgeKeepOn.ofVsZ {s s' : S} (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (z : VsZ st (L.ksb s) Pt s s') : EdgeKeepOn st (KtHdrW st OS Kt s) s s' := by + refine EdgeKeepOn.ofKept fun b hb e => ?_ + rcases z b (Or.inl (R.ktHdrW hb)) with k | k + · exact k + · rw [k] at e; exact absurd e (by decide) + +/-- **A `VsKeep` step keeps them.** -/ +theorem EdgeKeepOn.ofVsKeep {s s' : S} (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (k : VsKeep st (L.ksb s) Pt s s') : EdgeKeepOn st (KtHdrW st OS Kt s) s s' := + EdgeKeepOn.ofVsZ R k.vsz + +/-- **The root half from `ArmQIAt` and `HiCap511`.** -/ +theorem ArmQIAt.hiRoots {Cs Vc : Set U64} {ia ie : Nat} {s s' : S} (h : ArmQIAt st H Cs OS Vc ia ie s s') + (h0 : HiCap511 st OS s) : ∀ y ∈ OS, ∀ R m a, capA st s' y = .HighVSpace R m a → R ∈ HvRt st OS s := + fun y hy R m a c => (h.hiCapP h0 y hy R m a c).1 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aKtPoolArms.lean b/proofs/Fl4ProofsA64/P1/S1aKtPoolArms.lean new file mode 100644 index 000000000..ce697d940 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKtPoolArms.lean @@ -0,0 +1,80 @@ +/- +P1 (aarch64, A64-S1A gen 41): the kernel-table column through ASIDPool Assign and MakePool (Gate-2 table, D3 C). + +* Assign: the one table write is a pool entry (`tag < 3`, never a descriptor), so every descriptor of a footprint word + is kept (`S1aAssignWrite.edgeKept`); the HighVSpace roots are unchanged (`S1aAssignWrite.highSet`). +* MakePool: every footprint word is kept, in the zeroed pool or the new ASID-table word (`PoolPost.vs`, `zr`); the + surviving capabilities are old or Untyped (`makePoolEndR2`'s slot clause). + +Named premises: none. New theorems only. +-/ +import Fl4ProofsA64.P1.S1aKtVsArms + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} + {A : Type _} {ar : machine.Arch A} {Cs Vc Ub U Ac Rp Nt : Set U64} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot pool base : U64} + +/-- **ASIDPool Assign keeps the column.** -/ +theorem syscall.decode_invocation.assign_kt + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.AsidPool pool base) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (src : obj.Slot.cap st slot s = ok (.AsidPool pool base)) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMASIDPoolAssign len slot + (.AsidPool pool base) blk call don fp buf extra ⦃ _ q _ => S1aHiKeep st OS OS Kt s q ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono (vspace.decode.assignExactWrite h vr D P src a len buf call) ?_ + rintro ⟨_, q, _⟩ (reject | ⟨x, root, tag, asid, index, off, ev⟩) + · change q = s at reject + subst q + exact ⟨EdgeKeepOn.refl _ _, fun y hy R m a c => ⟨y, hy, m, a, c⟩⟩ + · refine ⟨EdgeKeepOn.ofKept fun b hb e => ev.edgeKept h P.heap (h.ktHdrW hb) e, fun y hy R m a c => ?_⟩ + rw [ev.highSet] + exact ⟨y, hy, m, a, c⟩ + +/-- **MakePool keeps the column.** -/ +theorem syscall.decode_invocation.makePool_kt + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s .AsidControl 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) (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (covered : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) (hks : HeapKsOff H (L.ksb s)) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) {lbl : U64} (label : lbl = fl4_abi.label.ARMASIDControlMakePool) (len : 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) ∨ ∃ (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, + others, _⟩) + · exact Or.inl same + refine Or.inr ⟨p, sb, EdgeKeepOn.ofKept fun b hb e => ?_, fun y hy R m a c => ?_⟩ + · have loc := h.ktHdrW hb + rcases post.vs Vc Ub Pt vr b (Or.inl loc) with kept | ⟨lo, hi⟩ | table + · exact kept + · rw [post.zr b (vr.al b (Or.inl loc)) lo hi] at e + exact absurd e (by decide) + · exact (ptKs b loc (by rw [table]; exact asW_at (L.ksb s) i)).elim + · have ne : y ≠ v := by + rintro rfl + rw [post.capV] at c + cases c + rcases others y hy ne with old | ⟨_, _, _, _, ut⟩ + · rw [old] at c + exact ⟨y, hy.1, m, a, c⟩ + · rw [ut] at c + cases c + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aKtRetype.lean b/proofs/Fl4ProofsA64/P1/S1aKtRetype.lean new file mode 100644 index 000000000..da03bc5ce --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKtRetype.lean @@ -0,0 +1,164 @@ +/- +P1 (aarch64, A64-S1A gen 41): the kernel-table column through Untyped Retype (Gate-2 table, D3 C). + +* `Kt1 ar`: the targets of the kernel's level-0 table descriptors. `KTab ar (Kt1 ar) KLv` holds (`Kt1.ktab`), and + `Kt1 ar ⊆ Kt` at level 1 (`Kt1.sub`), both by `KTab.l0`. The existing `newHighInit` at `Kt1` therefore gives the + new roots' header descriptors at level 1, with no new initialisation lemma. +* `S1aRtIn.hiK`: the column at the creation end. Kernel-table and old header words are owned and kept + (`keepOwnedVsWords`); a new HighVSpace cap is fresh (`S1aRtIn.capAt`, `newCapA_hv`) and initialised at `Kt1`. +* `syscall.decode_invocation.untypedExactR2K`: `untypedExactR2` with the column (same proof, one more conjunct). + +Named premises: [P] `KTab` (existing). New definitions and theorems only. +-/ +import Fl4ProofsA64.P1.S1aKtPoolArms + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +section kt1 +variable {A : Type _} + +/-- The tables the kernel's level-0 descriptors name. -/ +def Kt1 (ar : machine.Arch A) : Set U64 := + {t | ∃ (a : A) (i e : U64), i.val < 511 ∧ ar.kernel_ttbr1_entry a 0#u64 i = ok e ∧ (e &&& 3#u64) = 3#u64 ∧ + wa (e &&& vspace.ADDR_MASK) layout.PPTR_BASE = t} + +theorem Kt1.ktab {ar : machine.Arch A} {Kt : Set U64} {KLv : U64 → Nat} (K : KTab ar Kt KLv) : + KTab ar (Kt1 ar) KLv := + ⟨fun a i e hi he h3 => ⟨⟨a, i, e, hi, he, h3, rfl⟩, (K.l0 a i e hi he h3).2⟩⟩ + +theorem Kt1.sub {ar : machine.Arch A} {Kt : Set U64} {KLv : U64 → Nat} (K : KTab ar Kt KLv) : + ∀ t ∈ Kt1 ar, t ∈ Kt ∧ KLv t = 1 := by + rintro _ ⟨a, i, e, hi, he, h3, rfl⟩ + exact K.l0 a i e hi he h3 + +end kt1 + +section rt +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H H1 H' : Heap} {Cs OS OS1 Pt Pp Tb Hr Te Kt Kt' U0 Ac : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} + {s s1 q : S} {ia ie lo hi : Nat} + {slot p sb fi aligned nt us dest off win : U64} {dev : Bool} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +/-- **The column at a Retype creation end.** -/ +theorem S1aRtIn.hiK + (E : S1aRtIn st H Cs OS U0 Ac s ia ie slot p sb fi dev extra H1 H' OS1 s1 q lo hi aligned nt us dest off win) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (K : S1aHiK st OS Kt KLv s) + (words : ∀ b, VsR (L.ksb s) Pt b → S1aRetypeWordOwner st H OS Kt s b → L.mem q b = L.mem s b) + (init : ∀ x ∈ OS, capA st s x = .Null → + (cdt.ensure_no_children st s slot = ok (.Ok ()) → x.val + 32 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ x.val) → + ∀ t m asid, capA st q x = .HighVSpace t m asid → S1aHighInit st Kt' q t) + (sub : ∀ t ∈ Kt', t ∈ Kt ∧ KLv t = 1) : + S1aHiK st (s1aRtSlots OS1 dev nt us aligned win) Kt KLv q := by + refine ⟨fun t ht hl o ho al e => ?_, fun y hy R m a c o ho al e => ?_⟩ + · have found := h.kernelTables.2 t ht + have w := words _ (Or.inl ⟨t, h.place.tables (h.kernelTables.1 ht), o, ho, al, rfl⟩) + ⟨t, .other 12, found, inObjWord E.place.heap found ho, Or.inl ⟨ht, rfl⟩⟩ + rw [w] at e ⊢ + exact K.kt t ht hl o ho al e + · rcases E.capAt hy c (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨yo, _, old⟩ | ⟨j, hj, _, new⟩ + · have found := h.highObjects y yo R m a old + have held : R ∈ Hr := by rw [h.highRoots]; exact ⟨y, yo, m, a, old⟩ + have w := words _ (Or.inl ⟨R, h.place.tables (h.place.high.sub held), o, by omega, al, rfl⟩) + ⟨R, .other 13, found, inObjWord E.place.heap found (by simp only [HKind.bits]; omega), + Or.inr ⟨y, yo, by rw [old]; exact RngKeyA.hv R m a, by rw [old]; exact ptrA_hv R m a⟩⟩ + rw [w] at e ⊢ + exact K.hdr y yo R m a old o ho al e + · obtain ⟨type, base⟩ := newCapA_hv E.creation.A.hn new.symm + have hinit := E.highInit init hj type + rw [← base] at hinit + exact sub _ (hinit.1 o ho al e) + +end rt + +section top +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {Cs : Set U64} + {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {s : S} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} + +set_option maxHeartbeats 4000000 in +/-- `untypedExactR2` with the kernel-table column. -/ +theorem syscall.decode_invocation.untypedExactR2K (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) + {U Ac Sg Scs Vq Uq Vc Ub : Set U64} {Z : U64 → Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Untyped p sb fi dev) 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) + (source : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (masks : A64FrameMasks st s) + (vr : VrOK H.omega Sg Scs Z OS Vq Uq (L.ksb s) Pt) (pools : PoolNamed st OS s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) + (vc : VcCap st Vc OS s) (frame : DevFrAl st OS s) (hi : HiCap511 st OS s) (hks : HeapKsOff H (L.ksb s)) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (KC : S1aHiK st OS Kt KLv s) + (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Untyped p sb fi dev) blk call don fp buf extra ⦃ _ q _ => + ∃ (H' : Heap) (OS' Vn Vc' Pt' Tb' Te' : Set U64) (Lv' : U64 → Nat), + ArmQIVAt st H Cs OS ia ie s H' OS' Vn q ∧ TabKeep st s q ∧ Vc' ⊆ Vc ∪ Vn ∧ VcCap st Vc' OS' q ∧ + S1aArmCol st H' Cs OS' Vc' Ub q ∧ S1aCapCol st H' OS' Ub q ∧ DevFrAl st OS' q ∧ HiCap511 st OS' q ∧ + S1aR2 st H' OS' Pt' Pp Tb' (HvRt st OS' q) Te' Kt Lv' Re bits n q ∧ S1aKtUt st OS' Kt q ∧ + S1aHiK st OS' Kt KLv q ⦄ := by + have R := UtDecP.of_live D B.sys P source B.ln B.vr B.ly + have capSource : capA st s slot = .Untyped p sb fi dev := okinj ((capA_eq s slot).symm.trans source) + have offState : dev = false → + (L.ksb s).val + 788736 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ (L.ksb s).val := fun ram => by + subst ram + exact (R.stz.2.2 slot R.src p sb fi R.cap).2 + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + refine WP.spec_mono (WP.spec_and + (untyped.decode.s1aRtVJH hA D P B Y source masks vr pools C Kc hal vc a lbl len buf + (fun H' O q => + (KindA st O q → FrameOK st H' O q → + (∀ b, VsR (L.ksb s) Pt b → S1aRetypeWordOwner st H OS Kt s b → L.mem q b = L.mem s b) → + TabKeep st s q → + (∀ asid raw, ActiveAsidRoot st Pp q asid raw ↔ ActiveAsidRoot st Pp s asid raw) → + (∀ tag asid sh base t, S1aPath st Pp n q tag asid sh base t ↔ S1aPath st Pp n s tag asid sh base t) → + (∀ x ∈ OS, capA st s x = .Null → + (cdt.ensure_no_children st s slot = ok (.Ok ()) → x.val + 32 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ x.val) → + ∀ t m asid, capA st q x = .HighVSpace t m asid → S1aHighInit st Kt q t) → + HiCap511 st O q → + ∃ (Pt' Tb' Te' : Set U64) (Lv' : U64 → Nat), + S1aR2 st H' O Pt' Pp Tb' (HvRt st O q) Te' Kt Lv' Re bits n q ∧ S1aKtUt st O Kt q) ∧ + (HrW st (HvRt st OS s) s q → HiCap511 st O q) ∧ DevFrAl st O q ∧ + ((∀ x ∈ OS, capA st s x = .Null → + (cdt.ensure_no_children st s slot = ok (.Ok ()) → x.val + 32 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ x.val) → + ∀ t m asid, capA st q x = .HighVSpace t m asid → S1aHighInit st (Kt1 ar) q t) → + (∀ b, VsR (L.ksb s) Pt b → S1aRetypeWordOwner st H OS Kt s b → L.mem q b = L.mem s b) → + S1aHiK st O Kt KLv q)) + ⟨fun _ _ _ _ _ _ _ _ => ⟨Pt, Tb, Te, Lv, h.highRoots ▸ h, sep⟩, fun _ => hi, frame, fun _ _ => KC⟩ ?_) + (WP.spec_and (untyped.decode.keepOwnedVsWords hA D P B source masks vr sep a lbl len buf) + (WP.spec_and (untyped.decode.tabK hA D P B source masks vr a lbl len buf) + (WP.spec_and (untyped.decode.keepActivePaths hA D P B source masks vr h sep a lbl len buf) + (WP.spec_and (untyped.decode.newHighInit hA K D P B source masks a lbl len buf) + (WP.spec_and (untyped.decode.keepOldHi hA D P B source masks vr h.footprint + (show HvPt st Pt OS s from fun y hy t m asid cap => + h.highFootprint ⟨t, h.highRoots ▸ ⟨y, hy, m, asid, cap⟩, Or.inl rfl⟩) + a lbl len buf) (untyped.decode.newHighInit hA (Kt1.ktab K) D P B source masks a lbl len buf))))))) ?_ + · intro H1 H' OS1 s1 q lo hi' aligned nt us dest off win E X window reset init + have rt : S1aRtIn st H Cs OS U Ac s ia ie slot p sb fi dev extra H1 H' OS1 s1 q lo hi' aligned nt us dest off win := + ⟨D, P, B, source, E, X, window, reset⟩ + have ksOff : HeapKsOff H' (L.ksb s) := E.heapKsOff X offState hks + have tables := UtEnd.ptCapHG D P B source E X window reset h.pageTables h.footprint + refine ⟨fun kinds frames words tab roots paths fresh headers => ?_, + fun keep => E.hiCap511 X B.ly.ksw init keep hi, UtEnd.devFrN D P B source E X window frame, + fun init1 words => rt.hiK h KC words init1 (Kt1.sub K)⟩ + exact ⟨_, _, _, _, rt.r2 h sep words tab roots paths fresh kinds frames headers ksOff tables, + E.s1aKtUt X B.ly.ksw capSource sep⟩ + · rintro ⟨_, q, _⟩ ⟨⟨H', OS', Vn, Vc', ⟨h1, h2, h3, h4, h5, h6⟩, record, finish, devices, column⟩, + words, writes, ⟨roots, paths⟩, fresh, keep, fresh1⟩ + have tab : TabKeep st s q := TabKeep.ofW vr writes fun _ h => h + have after : SysL st H' Cs OS' ia ie q := h1.1 + obtain ⟨_, _, _, kinds, _, _⟩ := after.sys.stz.1.1.mdbS + have headers := finish keep + obtain ⟨Pt', Tb', Te', Lv', r2, separate⟩ := + record kinds after.sys.fr words tab roots paths fresh headers + exact ⟨H', OS', Vn, Vc', Pt', Tb', Te', Lv', h1, h2, h3, h4, h5, h6, devices, headers, r2, separate, + column fresh1 words⟩ + +end top + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aKtUt.lean b/proofs/Fl4ProofsA64/P1/S1aKtUt.lean new file mode 100644 index 000000000..4d574b897 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKtUt.lean @@ -0,0 +1,164 @@ +/- +P1 (aarch64): the Untyped separation clause of KtOut and its transport through Retype and CNode moves. +Named premises: none. +-/ +import Fl4ProofsA64.P1.MdbCapI +import Fl4ProofsA64.P1.MdbLook +import Fl4ProofsA64.P1.MdbRtArm + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {OS O Kt : Set U64} {s q : S} + +/-- Every kernel table lies outside every live Untyped extent, including device Untyped. -/ +def S1aKtUt (st : machine.Store S) [LawfulStore st] (OS Kt : Set U64) (s : S) : Prop := + ∀ k ∈ Kt, ∀ x ∈ OS, ∀ p b i d, capA st s x = .Untyped p b i d → + k.val + 4096 ≤ p.val ∨ p.val + 2 ^ b.val ≤ k.val + +/-- Separation persists when every post-state Untyped extent lies inside a prior Untyped extent. -/ +theorem S1aKtUt.ofRanges (h : S1aKtUt st OS Kt s) + (back : ∀ x ∈ O, ∀ p b i d, capA st q x = .Untyped p b i d → + ∃ y ∈ OS, ∃ p₀ b₀ i₀ d₀, capA st s y = .Untyped p₀ b₀ i₀ d₀ ∧ + p₀.val ≤ p.val ∧ p.val + 2 ^ b.val ≤ p₀.val + 2 ^ b₀.val) : + S1aKtUt st O Kt q := by + intro k hk x hx p b i d cap + obtain ⟨y, hy, p₀, b₀, i₀, d₀, old, lo, hi⟩ := back x hx p b i d cap + exact (h k hk y hy p₀ b₀ i₀ d₀ old).imp (·.trans lo) (hi.trans ·) + +theorem S1aKtUt.keep (h : S1aKtUt st OS Kt s) (frame : OSKeep st OS s q) : + S1aKtUt st OS Kt q := + fun k hk x hx p b i d cap => h k hk x hx p b i d ((frame.capA hx).symm.trans cap) + +/-- The cap-local form used by the existing CNode and deletion hooks. -/ +def S1aKtUtCap (Kt : Set U64) (c : capability.Cap) : Prop := + ∀ p b i d, c = .Untyped p b i d → + ∀ k ∈ Kt, k.val + 4096 ≤ p.val ∨ p.val + 2 ^ b.val ≤ k.val + +theorem S1aKtUt.iff_capInv : + S1aKtUt st OS Kt s ↔ CapInv st (S1aKtUtCap Kt) OS s := + ⟨fun h x hx p b i d eq k hk => h k hk x hx p b i d eq, + fun h k hk x hx p b i d eq => h x hx p b i d eq k hk⟩ + +theorem S1aKtUtCap.fe {c d : capability.Cap} (rel : FE d c) (h : S1aKtUtCap Kt c) : + S1aKtUtCap Kt d := by + intro p b i dev cap + obtain ⟨i₀, old⟩ := rel.2.2.1 p b i dev cap + exact h p b i₀ dev old + +section cnode + +variable {H : Heap} {Cs Rp Nt : Set U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} + +/-- Copy, Mint, Move, Mutate and Rotate preserve the extents of all Untyped caps. -/ +theorem syscall.decode_invocation.cnode_s1aKtUt {U Ac : Set U64} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : obj.Slot} + (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 Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (h : S1aKtUt st OS Kt s) (a : A) {lbl : U64} (len : U64) (blk call don fp : Bool) (buf : U64) + (hl : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) + (hf : capFam cap = .cnode) (hcap : obj.Slot.cap st slot s = ok cap) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => + S1aKtUt st OS Kt s' ⦄ := by + obtain ⟨Q, Rq, q⟩ := D.bxi.1 + have root : RootOK OS cap := RootOK.of_slot P.ty P.src hcap + have keep := cnode.decode.cnode_ci (ar := ar) (len := len) (buf := buf) S1aKtUtCap.fe P.os P.win q P.ty B.sys.stz.1.1 + (S1aKtUt.iff_capInv.mp h) a hl cap root P.ext + exact syscall.decode_invocation.cnodeG h a len slot cap blk call don fp buf extra hf + (WP.spec_mono keep fun _ hc => S1aKtUt.iff_capInv.mpr hc) + +end cnode + +variable {H H₁ H' : Heap} {Cs O₁ : Set U64} {s₁ : S} + {slot p sb fi aligned nt us dest off win : U64} {dev : Bool} {lo hi : Nat} + +/-- A new Untyped child uses a complete, non-wrapping piece of the source extent. -/ +private theorem CrtA.untypedChildRange (h : CrtA st s p sb aligned nt us dest off win) + {j : Nat} (hj : j < win.val) (typ : nt.val = 0) : + let child := bjA aligned (zA nt.val us) j + p.val ≤ child.val ∧ child.val + 2 ^ us.val ≤ p.val + 2 ^ sb.val := by + obtain ⟨base, endLe⟩ := + bj_facts (aligned := aligned) (z := zA nt.val us) hj (h.aw.trans h.pf) + have sizeEq : zA nt.val us = us := by simp [zA, typ] + have last := endLe.trans h.aw + refine ⟨?_, ?_⟩ + · rw [base] + exact h.pa.trans (Nat.le_add_right _ _) + · simpa only [sizeEq] using last + +/-- Retype preserves the same kernel-table set over the exact grown slot witness. +The reset can change the source cursor and add null slots. Any new Untyped cap +describes a child range of the original source. -/ +theorem UtEnd.s1aKtUt + (U : UtEnd st H Cs OS s slot p sb dev H₁ H' O₁ s₁ q lo hi aligned nt us dest off win) + (X : UtX H H₁ lo hi us) (hksw : (L.ksb s).val + 788736 ≤ 2 ^ 64) + (capSrc : capA st s slot = .Untyped p sb fi dev) (h : S1aKtUt st OS Kt s) : + S1aKtUt st (O₁ ∪ NewSl dev nt us aligned win) Kt q := by + have hk : (L.ksb q).val + 788736 ≤ 2 ^ 64 := by rw [U.E.fr.1.trans U.w1.1]; exact hksw + apply h.ofRanges + rintro y (hy | hy) p' b' i' d' cap + · by_cases ys : y = slot + · subst y + obtain ⟨_, hw⟩ := U.E.src + rw [hw] at cap + cases cap + exact ⟨slot, U.os slot U.src, p, sb, fi, dev, capSrc, le_rfl, le_rfl⟩ + · by_cases yd : ∃ j, j < win.val ∧ y = djA dest off j + · obtain ⟨j, hj, rfl⟩ := yd + rw [U.E.new j hj] at cap + obtain ⟨typ, rfl, rfl, _⟩ := newCapA_utE cap + exact ⟨slot, U.os slot U.src, p, sb, fi, dev, capSrc, U.A.untypedChildRange hj typ⟩ + · rw [U.E.keep y hy ys (fun j hj he => yd ⟨j, hj, he⟩), U.k1 y hy ys] at cap + exact ⟨y, U.os y hy, p', b', i', d', cap, le_rfl, le_rfl⟩ + · rw [(U.freshN X hk).null y hy] at cap + cases cap + +/-- The reset and creation preserve every kernel page and keep it outside the hole. -/ +theorem UtEnd.kernelTables + (U : UtEnd st H Cs OS s slot p sb dev H₁ H' O₁ s₁ q lo hi aligned nt us dest off win) + (X : UtX H H₁ lo hi us) + (reset : H₁ = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s slot = ok (.Ok v)) ∧ + lo = p.val ∧ hi = p.val + 2 ^ sb.val)) + (capSrc : capA st s slot = .Untyped p sb fi dev) (h : S1aKtUt st OS Kt s) + {k : U64} (hk : k ∈ Kt) (obj : H k = some (.other 12)) : + H' k = some (.other 12) ∧ (k.val + 4096 ≤ lo ∨ hi ≤ k.val) := by + have keep : H₁ k = some (.other 12) := by + rcases reset with same | ⟨_, _, start, finish⟩ + · exact same.symm ▸ obj + · rcases X.kept k (.other 12) obj with present | inside + · exact present + · have sep := h k hk slot (U.os slot U.src) p sb fi dev capSrc + change lo ≤ k.val ∧ k.val + 4096 ≤ hi at inside + rcases sep with left | right <;> omega + exact ⟨U.grow k (.other 12) keep, U.hole k (.other 12) keep⟩ + +section retype + +variable {Rp Nt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + +/-- At Retype dispatch, the separation and the post heap and slots use the same closure witness. -/ +theorem syscall.decode_invocation.untyped_s1aKtUt (total : P0.ArchTotal ar) {U Ac : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (cap : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (masks : A64FrameMasks st s) + (h : S1aKtUt st OS Kt s) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Untyped p sb fi dev) blk call don fp buf extra ⦃ r s' _ => + ∃ H' O, SysL st H' Cs O ia ie s' ∧ S1aKtUt st O Kt s' ⦄ := by + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + have capSrc := okinj ((capA_eq s slot).symm.trans cap) + exact WP.spec_mono (untyped.decode.blkI total D P B cap masks a lbl len buf + (fun _ O s' => S1aKtUt st O Kt s') h + (fun _ _ _ _ _ _ _ _ _ _ _ _ _ E X _ _ => E.s1aKtUt X B.ly.ksw capSrc h)) + fun _ ⟨H', O, sys, _, sep⟩ => ⟨H', O, sys, sep⟩ + +end retype + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aKtUtArms.lean b/proofs/Fl4ProofsA64/P1/S1aKtUtArms.lean new file mode 100644 index 000000000..54dd6a8cc --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKtUtArms.lean @@ -0,0 +1,284 @@ +/- +P1 (aarch64): the kernel-table / Untyped separation (`S1aKtUt`) across the arms that delete nothing: the +slot-keeping invocations, IrqControl, the endpoint send, cache maintenance, the page-table and frame invocations +and ASIDPool Assign (A64-S1A gen 41). + +None of them writes a new Untyped extent: each slot keeps its capability, takes a derived copy of one, or takes a +capability that is not Untyped. Named premises: [P] `MaxSpi` (IrqControl, as in its top). +-/ +import Fl4ProofsA64.P1.S1aKtUt +import Fl4ProofsA64.P1.S1aR2KeepArms +import Fl4ProofsA64.P1.S1aR2Frame +import Fl4ProofsA64.P1.S1aR2MapDispatch +import Fl4ProofsA64.P1.S1aR2FrameMapPost +import Fl4ProofsA64.P1.S1aR2FrameUnmapPost +import Fl4ProofsA64.P1.S1aR2UnmapPost +import Fl4ProofsA64.P1.S1aR2AccessPost +import Fl4ProofsA64.P1.S1aHiAsg + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Rp Nt Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {ia ie : Nat} {A : Type _} + {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- Each slot keeps its capability or takes one that is not Untyped. -/ +theorem S1aKtUt.slots {s q : S} (h : S1aKtUt st OS Kt s) + (caps : ∀ y ∈ OS, capA st q y = capA st s y ∨ ∀ p b i d, capA st q y ≠ .Untyped p b i d) : + S1aKtUt st OS Kt q := by + intro k hk x hx p b i d cap + rcases caps x hx with same | other + · exact h k hk x hx p b i d (same.symm.trans cap) + · exact absurd cap (other p b i d) + +/-- One slot takes a capability that is not Untyped. -/ +theorem S1aKtUt.at {s q : S} {slot : U64} {c : capability.Cap} (h : S1aKtUt st OS Kt s) + (new : capA st q slot = c) (plain : ∀ p b i d, c ≠ .Untyped p b i d) + (others : ∀ y ∈ OS, y ≠ slot → capA st q y = capA st s y) : S1aKtUt st OS Kt q := + h.slots fun y hy => by + by_cases same : y = slot + · exact Or.inr (by rw [same, new]; exact plain) + · exact Or.inl (others y hy same) + +theorem XferSlots.ktUt {s r : S} (h : XferSlots st OS s r) (sep : S1aKtUt st OS Kt s) : S1aKtUt st OS Kt r := by + rcases h with same | ⟨src, hs, dest, hd, ne, -, ⟨q, c, derived, new⟩, turned, others⟩ + · exact sep.slots fun y hy => Or.inl (same y hy) + have old := S1aKtUt.iff_capInv.mp sep + have rel := objects.derive_cap.fe (st := st) q src (capA st s src) + rw [derived, WP.spec_ok] at rel + refine S1aKtUt.iff_capInv.mpr fun y hy => ?_ + by_cases at_dest : y = dest + · rw [at_dest, new] + exact S1aKtUtCap.fe (rel c rfl) (old src hs) + by_cases at_src : y = src + · rw [at_src] + rcases turned with same | ⟨p, b, i, d, i', before, after, -⟩ + · rw [same] + exact old src hs + · intro p' b' j d' cap + rw [after] at cap + cases cap + exact old src hs p b i d before + rw [others y hy at_src at_dest] + exact old y hy + +theorem IrqSlots.ktUt {s r : S} (h : IrqSlots st OS s r) (sep : S1aKtUt st OS Kt s) : S1aKtUt st OS Kt r := + sep.slots fun y hy => (h y hy).imp id fun ⟨_, i, new⟩ p b j d cap => by rw [new] at cap; cases cap + +/-- The slot-keeping invocations keep the separation. -/ +theorem syscall.decode_invocation.keepSlots_ktUt (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot lbl : U64} (sep : S1aKtUt st OS Kt s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok cap) + (arm : DecArmR2Keep cap lbl) (a : A) (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' _ => + S1aKtUt st OS Kt s' ⦄ := by + have close {m : Result ((core.result.Result Unit error.Exc) × S × A)} + (top : m ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ + OSKeep st OS s s' ⦄) : + m ⦃ _ s' _ => S1aKtUt st OS Kt s' ⦄ := + WP.spec_mono top fun r d => by + obtain ⟨_, _, _⟩ := r + exact sep.keep d.2.2.2 + rcases arm with ⟨m, b, sd, rv, rfl⟩ | ⟨t, rfl, hl | hl⟩ | + ⟨v, rfl, hl | hl | hl | hl | hl | hl | hl⟩ | ⟨p, sz, r, d, m, e, asid, va, rfl, hl⟩ + · exact close (syscall.decode_invocation.ntfn_armSAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + · exact close (syscall.decode_invocation.suspend_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.readRegs_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.run_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.ackVppi_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.vcWr_armSAt hA I D P B Y hks hcap a (Or.inl hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.vcWr_armSAt hA I D P B Y hks hcap a (Or.inr hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.vcSt_armSAt hA I D P B Y hks hcap a (Or.inl hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.vcSt_armSAt hA I D P B Y hks hcap a (Or.inr hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.setTcb_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.getAddr_armSAt I D P B Y hks a hl len blk call don fp buf) + +/-- IrqControl keeps the separation. -/ +theorem syscall.decode_invocation.irqCtl_ktUt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (sep : S1aKtUt st OS Kt s) + (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 .IrqControl 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 .IrqControl) (a : A) (lbl len : U64) + (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot .IrqControl blk call don fp buf extra ⦃ _ s' _ => + S1aKtUt st OS Kt s' ⦄ := + WP.spec_mono (syscall.decode_invocation.irqCtl_armSAt hA hM I D P B Y hcap a lbl len blk call don fp buf) + fun r d => by + obtain ⟨_, _, _⟩ := r + exact d.2.2.2.ktUt sep + +/-- The endpoint send keeps the separation. -/ +theorem syscall.decode_invocation.endpoint_ktUt (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot e b : U64} {sd rv g gr : Bool} (sep : S1aKtUt st OS Kt s) + (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 (.Endpoint e b sd rv g gr) + extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (hcap : obj.Slot.cap st slot s = ok (.Endpoint e b sd rv g gr)) (a : A) (lbl len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Endpoint e b sd rv g gr) blk call don fp buf extra + ⦃ _ s' _ => S1aKtUt st OS Kt s' ⦄ := + WP.spec_mono (syscall.decode_invocation.ep_armSAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + fun r d => by + obtain ⟨_, _, _⟩ := r + exact d.2.2.2.ktUt sep + +/-- Cache maintenance keeps the separation. -/ +theorem syscall.decode_invocation.cache_ktUt {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} (sep : S1aKtUt st OS Kt s) + (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) + (hA : P0.ArchTotal ar) (a : A) {lbl : U64} (arm : DecArmR2Cache cap lbl) + (len slot : 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' _ => + S1aKtUt st OS Kt s' ⦄ := + syscall.decode_invocation.cacheInvariant sep + (WP.spec_mono (sched.set_thread_state.unmMid I D) fun _ mid => sep.keep mid.1.k) + hA a arm len slot blk call don fp buf + +/-- PageTable Map keeps the separation. -/ +theorem syscall.decode_invocation.pageTableMap_ktUt (hPl : ArchPlat ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot ptr oldAsid oldVa : U64} {mapped : Bool} + (sep : S1aKtUt st OS Kt s) (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.PageTable ptr mapped oldAsid oldVa) extra) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr mapped oldAsid oldVa)) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableMap len slot + (.PageTable ptr mapped oldAsid oldVa) blk call don fp buf extra ⦃ _ q _ => S1aKtUt st OS Kt q ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + cases mapped + · have old := okinj ((capA_eq s slot).symm.trans cap) + have al := (h.footprint ptr (h.pageTables slot P.src ptr false oldAsid oldVa old)).1 + refine WP.spec_mono (vspace.decode_page_table.mapExactEffect hPl h vr P D (canon_pt cap) al a len buf) ?_ + rintro ⟨_, q, _⟩ (eq | ⟨tag, event⟩) + · change q = s at eq + subst q + exact sep + · obtain ⟨_, _, _, _, _, _, _, _, _, _, _, _, write⟩ := event.edit + exact sep.at write.cap (fun _ _ _ _ bad => by cases bad) write.other + · refine WP.spec_mono (vspace.decode_page_table.mapMappedKeeps (st := st) (ar := ar) + (s := s) (slot := slot) (ptr := ptr) (oldAsid := oldAsid) (oldVa := oldVa) (extra := extra) a len buf) ?_ + rintro ⟨_, q, _⟩ eq + change q = s at eq + subst q + exact sep + +/-- PageTable Unmap keeps the separation. -/ +theorem syscall.decode_invocation.pageTableUnmap_ktUt (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot ptr asid va : U64} {mapped : Bool} + (sep : S1aKtUt st OS Kt s) (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) (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 + (.PageTable ptr mapped asid va) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr mapped asid va)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableUnmap len slot (.PageTable ptr mapped asid va) + blk call don fp buf extra ⦃ _ q _ => S1aKtUt st OS Kt q ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + cases mapped + · refine vspace.decode_page_table.unmapUnmappedInvariant I D P cap sep ?_ a len buf + intro q _ _ written others + exact sep.at written (fun _ _ _ _ bad => by cases bad) others + · have hiObj r (hr : r ∈ Hr) : H r = some (.other 13) := by + rw [h.highRoots] at hr + obtain ⟨x, hx, m, q, hc⟩ := hr + exact h.highObjects x hx r m q hc + refine WP.spec_mono (vspace.decode_page_table.unmapMappedEffect hA hPl h.core place I D P B cap h.pageTables + h.eptRoots h.pageObjects h.highObjects hiObj ptKs a len buf) ?_ + rintro ⟨_, q, _⟩ (eq | cleared) + · subst q + exact sep + · exact sep.at cleared.cap (fun _ _ _ _ bad => by cases bad) cleared.other + +/-- Page Map keeps the separation. -/ +theorem syscall.decode_invocation.frameMap_ktUt (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (sep : S1aKtUt st OS Kt s) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (B : SysL st H Cs OS ia ie s) (dev : DevFrAl st OS s) + {ptr rights oldAsid oldVa : U64} {sz : capability.FrameSize} {device mapped oldStage : Bool} + (cap : obj.Slot.cap st slot s = ok (.Frame ptr sz rights device mapped oldStage oldAsid oldVa)) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame ptr sz rights device mapped oldStage oldAsid oldVa) extra) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageMap len slot + (.Frame ptr sz rights device mapped oldStage oldAsid oldVa) blk call don fp buf extra ⦃ _ q _ => + S1aKtUt st OS Kt q ⦄ := by + refine WP.spec_mono (syscall.decode_invocation.frameMapExactEffect hA hPl h vr P B.sys.fr dev cap d + a len blk call don fp buf) ?_ + rintro ⟨_, q, _⟩ (eq | ⟨tag, edit⟩) + · change q = s at eq + subst q + exact sep + · obtain ⟨_, _, _, _, _, _, _, _, _, _, _, write⟩ := edit.edit + refine sep.at write.cap (fun _ _ _ _ bad => ?_) write.other + split at bad <;> cases bad + +/-- Page Unmap keeps the separation. -/ +theorem syscall.decode_invocation.frameUnmap_ktUt (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (sep : S1aKtUt st OS Kt s) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + {ptr rights asid va : U64} {sz : capability.FrameSize} {device mapped stage : Bool} + (cap : obj.Slot.cap st slot s = ok (.Frame ptr sz rights device mapped stage asid va)) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame ptr sz rights device mapped stage asid va) extra) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageUnmap len slot + (.Frame ptr sz rights device mapped stage asid va) blk call don fp buf extra ⦃ _ q _ => + S1aKtUt st OS Kt q ⦄ := by + have old := okinj ((capA_eq s slot).symm.trans cap) + let frame : vspace.FrameCap := ⟨ptr, sz, rights, device, mapped, stage, asid, va⟩ + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono (vspace.decode_frame.unmapExactEffect hA hPl frame h place I d P.src old ptKs a len buf call) ?_ + rintro ⟨_, q, _⟩ ⟨start, -, effect, -, caps, -⟩ + have before : S1aKtUt st OS Kt start := sep.slots fun y hy => Or.inl (caps y hy) + exact before.at effect.cap (fun _ _ _ _ bad => by cases bad) effect.other + +/-- Page TestAndClearAccessed keeps the separation. -/ +theorem syscall.decode_invocation.access_ktUt (hA : P0.ArchTotal ar) (f : vspace.FrameCap) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (sep : S1aKtUt st OS Kt s) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) extra) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTestAndClearAccessed len slot + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) blk call don fp buf extra ⦃ _ q _ => + S1aKtUt st OS Kt q ⦄ := by + refine syscall.decode_invocation.accessRoute (Q := S1aKtUt st OS Kt) f ?_ + exact WP.spec_mono (vspace.decode_test_and_clear_accessed.exactWrite hA h I d P B Y ptKs a f call) + fun _ effect => sep.slots fun y hy => Or.inl (effect.caps y hy) + +/-- ASIDPool Assign keeps the separation: it rewrites a VSpace root cap. -/ +theorem AsgPost.ktUt {s s' : S} (post : AsgPost st H OS s s') (sep : S1aKtUt st OS Kt s) : S1aKtUt st OS Kt s' := + sep.slots fun y hy => (post.cap y hy).imp id fun ⟨_, root⟩ p b i d cap => by + rcases root with ⟨_, _, _, e⟩ | ⟨_, _, _, _, _, e⟩ | ⟨_, _, _, e⟩ <;> rw [cap] at e <;> cases e + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aKtUtDel.lean b/proofs/Fl4ProofsA64/P1/S1aKtUtDel.lean new file mode 100644 index 000000000..6bacff50d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKtUtDel.lean @@ -0,0 +1,116 @@ +/- +P1 (aarch64): the kernel-table / Untyped separation (`S1aKtUt`) through the deletion primitives: delete, revoke, +the IRQ node's `delete_one`, and an insert of a capability that is not Untyped (A64-S1A gen 41). + +The separation is a capability invariant holding of `Null` and the zombies, so the deletion loops keep it. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aKtUt +import Fl4ProofsA64.P1.S1aR2Install + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS D Vc Ub Pt Ac Kt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {K : capability.Cap → Prop} {Ty : S → Prop} {I Is : U64} + +theorem S1aKtUtCap.null (Kt : Set U64) : S1aKtUtCap Kt .Null := fun _ _ _ _ cap => by cases cap + +theorem S1aKtUtCap.zombie (Kt : Set U64) (p t n : U64) : S1aKtUtCap Kt (.Zombie p t n) := + fun _ _ _ _ cap => by cases cap + +/-- One deletion off the IRQ node, at the arm's `DelR`. -/ +theorem cdt.delete.ktUtR {s0 s : S} (In : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) {a : A} {x : U64} + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (hx : x ∈ OSN OS (L.ksb s0)) (sep : S1aKtUt st OS Kt s) : + cdt.delete st ar s a x true ⦃ r => S1aKtUt st OS Kt r.2.1 ⦄ := + WP.spec_mono (cdt.delete.capInvR In R hx (S1aKtUtCap.null Kt) (S1aKtUtCap.zombie Kt) + (S1aKtUt.iff_capInv.mp sep)) fun _ h => S1aKtUt.iff_capInv.mpr h + +/-- One deletion from a revoke state, on or off the IRQ node. -/ +theorem cdt.delete.ktUtQ {s0 s : S} (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) + (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (hDall : ∀ y ∈ OS, ¬ IslN (L.ksb s0) y → y ∈ D) + {a : A} {y : U64} (Q : DelQ st H Cs OS D Vc Ub Ac K Ty ia ie I Is s0 s) (hy : y ∈ OS) + (sep : S1aKtUt st OS Kt s) : + cdt.delete st ar s a y true ⦃ r => S1aKtUt st OS Kt r.2.1 ⦄ := by + have field := LoopME.ciM (P := S1aKtUtCap Kt) (S1aKtUtCap.null Kt) (S1aKtUtCap.zombie Kt) E.arch E.os E.sca + E.vc E.dom E.dcan E.vr hK hTy E.wu E.irq E.irqSt + (E.fieldI (Cs := Cs) (Ac := Ac) (ia := ia) (ie := ie) hK hTy hKL s I Is) + (fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + have B := Q.sys + by_cases node : IslN (L.ksb s0) y + · exact WP.spec_mono (cdt.delete.irqMPQ (a := a) E hK hTy Q.jv node Q.dom Q.idle Q.isc Q.irq Q.ty field.toP + ⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨Q.sym, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt Q.idle Q.isc).idSc B.sc⟩, + CtOff.ks Q.jv.ksb.symm B.ct⟩, FrOff.ks Q.jv.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, S1aKtUt.iff_capInv.mp sep⟩) + fun _ post => S1aKtUt.iff_capInv.mpr post.2.2.1.2 + · exact WP.spec_mono (cdt.delete.zqIGTMPQ (a := a) E.arch E.os E.sca E.vc E.dom E.dcan E.vr hK hTy E.wu E.irq + E.irqSt Q.jv hy node Q.dom (fun c hc => Q.dom y (hDall _ hy node) c hc) Q.idle Q.isc Q.irq Q.ty field.toP + ⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨Q.sym, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt Q.idle Q.isc).idSc B.sc⟩, + CtOff.ks Q.jv.ksb.symm B.ct⟩, FrOff.ks Q.jv.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, S1aKtUt.iff_capInv.mp sep⟩) + fun _ post => S1aKtUt.iff_capInv.mpr post.2.2.1.2 + +/-- Revoke at the arm's `DelR`. -/ +theorem cdt.revoke.ktUtR {s0 s : S} (In : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) {a : A} {x : U64} + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (hx : x ∈ OS) (sep : S1aKtUt st OS Kt s) : + cdt.revoke st ar s a x ⦃ r => S1aKtUt st OS Kt r.2.1 ⦄ := by + have hD := DomQ.of_sysL (K := K) In.del.heap R.jv R.sys R.vc In.ts In.s2 + rw [R.jv.ksb] at hD + have E := In.del + refine WP.spec_mono (cdt.revoke.gen (Pr := S1aKtUt st OS Kt) E In.fin In.tyk In.kl (fun y hy hib => ⟨hy, hib⟩) + (fun s1 a1 y Q1 p1 hy => cdt.delete.ktUtQ E In.fin In.tyk In.kl (fun y hy hib => ⟨hy, hib⟩) Q1 hy p1) + (fun s1 a1 Q1 p1 => ?_) ⟨R.jv, R.ty, R.sys, R.sym, hD, rfl, rfl, R.irq⟩ sep hx) fun _ done => done.2 + refine WP.spec_mono (sched.preemption_point.jv E.arch E.os E.vc Q1.jv (by rw [Q1.jv.ksb]; exact E.wu)) + fun r ⟨_, kept, _⟩ k hk y hy p b i d cap => + p1 k hk y hy p b i d (Eq.trans (Eq.symm ?_) cap) + have same := kept y hy + have words : obj.Slot.cap st y r.2.1 = obj.Slot.cap st y s1 := by + rw [DPF.slot_cap_dec, DPF.slot_cap_dec, same.1, same.2.1] + exact okinj ((capA_eq _ _).symm.trans (words.trans (capA_eq _ _))) + +/-- The deletion of an IRQ-node slot. -/ +theorem cdt.delete_one.ktUt {s0 s : S} (In : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (a : A) {i : U64} (hi : i.val < 5376) (sep : S1aKtUt st OS Kt s) : + cdt.delete_one st ar s a (irqSlotA (L.ksb s0) i) ⦃ r => S1aKtUt st OS Kt r.1 ⦄ := by + have E := In.del + have B := R.sys + have h := R.jv + have field := LoopME.ciM (P := S1aKtUtCap Kt) (S1aKtUtCap.null Kt) (S1aKtUtCap.zombie Kt) E.arch E.os E.sca + E.vc E.dom E.dcan E.vr In.fin In.tyk E.wu E.irq E.irqSt + (E.fieldI (Cs := Cs) (Ac := Ac) (ia := ia) (ie := ie) In.fin In.tyk In.kl s (L.idleW s) (L.mem s (scA (L.idleW s)))) + fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS + exact WP.spec_mono (cdt.delete_one.irqM In R a hi field + ⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨R.sym, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt rfl rfl).idSc B.sc⟩, + CtOff.ks h.ksb.symm B.ct⟩, FrOff.ks h.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, S1aKtUt.iff_capInv.mp sep⟩) + fun _ m => S1aKtUt.iff_capInv.mpr m.2 + +/-- An insert of a capability that is not Untyped. -/ +theorem cdt.insert_with_cap.ktUt {s : S} (hO : OSOK H.tcbs H.omega H.frame OS) (hm : MdbS st OS s) + {src dest : U64} {nc sc : capability.Cap} (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) + (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hsc0 : sc ≠ .Null) (hw : CapRt.EncWf nc) + (plain : ∀ p b i d, nc ≠ .Untyped p b i d) (sep : S1aKtUt st OS Kt s) : + cdt.insert_with_cap st s nc sc src dest ⦃ s' => S1aKtUt st OS Kt s' ⦄ := by + have next := (hm.lnk hO hsrc).2 + refine WP.spec_mono (WP.spec_and (cdt.insert_with_cap.lrF hO.inOS (LR.self s) hsrc hd hsd hdc hsc hsc0 hw next) + (cdt.insert_with_cap.srcF hO hsrc hd hsd hsc hw next)) fun s' ⟨⟨_, _, new, _, _, other, _⟩, turned⟩ => ?_ + have old := S1aKtUt.iff_capInv.mp sep + refine S1aKtUt.iff_capInv.mpr fun y hy => ?_ + by_cases at_dest : y = dest + · rw [at_dest, new] + intro p b i dev cap + exact absurd cap (plain p b i dev) + by_cases at_src : y = src + · rw [at_src] + have before : S1aKtUtCap Kt sc := hsc ▸ old src hsrc + rcases turned with same | ⟨p, b, i, d, i', was, now, -⟩ + · rw [same] + exact before + · intro p' b' j d' cap + rw [now] at cap + cases cap + exact before p b i d was + rw [other y hy at_src at_dest] + exact old y hy + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aKtVsArms.lean b/proofs/Fl4ProofsA64/P1/S1aKtVsArms.lean new file mode 100644 index 000000000..a7cf908da --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aKtVsArms.lean @@ -0,0 +1,261 @@ +/- +P1 (aarch64, A64-S1A gen 41): the kernel-table column's words through the VSpace arms (Gate-2 table, D3 C). + +Each arm keeps every descriptor of the `Kt` and header words by its write record: a map's one descriptor write is +off every kernel-table word (`S1aR2.pathOffKernel`) and every header word (`S1aMapWrite.highHeader`); FrameUnmap, +PageTableUnmap and the unmapped PageTable reset are `VsZ` / `VsKeep` steps; TestAndClearAccessed changes only the +access flag (`S1aAccessWrite.mask`). `vspace.decode_frame.unmapExactEffectK` is `unmapExactEffect` with the +restart's `VsKeep` exported (same proof). + +Named premises: none. New theorems only. +-/ +import Fl4ProofsA64.P1.S1aKtDelArms + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {s q : S} {n : U64} + {A : Type _} {ar : machine.Arch A} + +/-- **A map's descriptor write keeps the column's words.** -/ +theorem EdgeKeepOn.ofMapWrite (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (kinds : KindA st OS s) {tag asid : U64} {va level : Nat} {addr slot word : U64} {c : capability.Cap} + (path : S1aSlotAt st Pp n s tag asid va level addr) (write : S1aMapWrite st OS Pt s q slot addr word c) : + EdgeKeepOn st (KtHdrW st OS Kt s) s q := by + refine EdgeKeepOn.ofKept fun b hb _ => ?_ + rcases hb with ⟨t, ht, o, ho, al, rfl⟩ | ⟨r, hr, o, ho, al, rfl⟩ + · exact write.memory _ (Or.inl ⟨t, h.place.tables (h.kernelTables.1 ht), o, ho, al, rfl⟩) + (h.pathOffKernel heap path ht o ho) + · have live : r ∈ Hr := by rw [h.highRoots]; exact hr + exact write.highHeader h heap kinds path live o (by omega) al + +/-- Same capabilities give the same column words. -/ +theorem KtHdrW.ofCaps {s' : S} (caps : ∀ x ∈ OS, capA st s' x = capA st s x) {b : U64} + (hb : KtHdrW st OS Kt s b) : KtHdrW st OS Kt s' b := by + rcases hb with k | ⟨r, ⟨y, hy, m, a, c⟩, rest⟩ + · exact Or.inl k + · exact Or.inr ⟨r, ⟨y, hy, m, a, (caps y hy).trans c⟩, rest⟩ + +set_option maxHeartbeats 3400000 in +/-- `unmapExactEffect` with the restart's `VsKeep` (same proof). -/ +theorem vspace.decode_frame.unmapExactEffectK + {Cs Vc Ub U Ac : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (f : vspace.FrameCap) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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 f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) extra) + (member : slot ∈ OS) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) (a : A) (len buf : U64) (call : Bool) : + vspace.decode_frame st ar s a fl4_abi.label.ARMPageUnmap len slot + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) call buf extra ⦃ r => + ∃ start, S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa start ∧ + S1aFrameUnmap st OS Pt Pp Hr hPl.ipa start r.2.1 slot f ∧ + capA st start slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr ∧ + (∀ x ∈ OS, capA st start x = capA st s x) ∧ L.ksb start = L.ksb s ∧ + VsKeep st (L.ksb s) Pt s start ⦄ := by + unfold vspace.decode_frame + simp only [vspace.as_frame, bind_ok, cur_thread_ok] + have ne : fl4_abi.label.ARMPageUnmap ≠ fl4_abi.label.ARMPageMap := + lbl_ne_of_val (by simp [fl4_abi.label.ARMPageMap, fl4_abi.label.ARMPageUnmap]) + try dsimp only + rw [if_neg ne] + simp only [ite_true] + have restart := WP.spec_and (sched.set_thread_state.restartR2 h.core place I D) + (sched.set_thread_state.unmMid I D) + refine WP.spec_bind restart fun start ⟨core, mid, keep⟩ => ?_ + have caps : ∀ x ∈ OS, capA st start x = capA st s x := fun _ hx => mid.k.capA hx + have before := h.keep core mid.tz.1 keep caps + have vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb start) Pt := by + rw [mid.tz.1]; exact I.del.vr + have old' := (caps slot member).trans old + have unchanged b (hb : PtW Pt b) : ¬ AsW (L.ksb start) b := by rw [mid.tz.1]; exact ptKs b hb + refine WP.spec_bind (s1aFrameRemove (f := f) hA hPl a before (fun b hb => vr.al b (Or.inl hb))) ?_ + rintro ⟨out, arch⟩ ⟨zero, clear⟩ + simp only [uncurry_apply_pair, vspace.unmapped_frame, bind_ok] + refine WP.spec_bind (obj.Slot.set_cap.frameUnmapTail before vr I.del.os member old' unchanged zero clear) + fun q effect => ?_ + exact (WP.spec_ok _).2 ⟨start, before, effect, old', caps, mid.tz.1, keep⟩ + +/-- **FrameUnmap keeps the column's words.** -/ +theorem syscall.decode_invocation.frameUnmap_kt + {Cs Vc Ub U Ac Rp Nt : Set U64} + {K : capability.Cap → Prop} {Ty : S → Prop} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + {ptr rights asid va : U64} {sz : capability.FrameSize} {device mapped stage : Bool} + (cap : obj.Slot.cap st slot s = ok (.Frame ptr sz rights device mapped stage asid va)) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame ptr sz rights device mapped stage asid va) extra) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageUnmap len slot + (.Frame ptr sz rights device mapped stage asid va) blk call don fp buf extra ⦃ _ q _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s q ⦄ := by + have old := okinj ((capA_eq s slot).symm.trans cap) + let frame : vspace.FrameCap := ⟨ptr, sz, rights, device, mapped, stage, asid, va⟩ + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono (vspace.decode_frame.unmapExactEffectK hA hPl frame h place I d P.src old ptKs a len buf call) ?_ + rintro ⟨_, q, _⟩ ⟨start, before, effect, _, caps, _, keep⟩ + exact (EdgeKeepOn.ofVsKeep h keep).trans + ((EdgeKeepOn.ofVsZ before effect.memory).mono fun _ hb => KtHdrW.ofCaps caps hb) + +/-- **TestAndClearAccessed keeps the column's words.** -/ +theorem syscall.decode_invocation.access_kt + {Cs Vc Ub U Ac Rp Nt : Set U64} {slot : U64} + {K : capability.Cap → Prop} {Ty : S → Prop} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hA : P0.ArchTotal ar) (f : vspace.FrameCap) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) extra) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTestAndClearAccessed len slot + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) blk call don fp buf extra ⦃ _ q _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s q ⦄ := by + refine syscall.decode_invocation.accessRoute (Q := EdgeKeepOn st (KtHdrW st OS Kt s) s) f ?_ + refine WP.spec_mono (vspace.decode_test_and_clear_accessed.exactWrite hA h I d P B Y ptKs a f call) + fun _ effect b hb e => ?_ + have loc := h.ktHdrW hb + have m3 := effect.mask loc 3#u64 (by decide) + have ma := effect.mask loc vspace.ADDR_MASK s1aAccessMaskStage1 + refine ⟨by rw [← m3]; exact e, ?_⟩ + unfold kChild + rw [ma] + +/-- **FrameMap keeps the column's words.** -/ +theorem syscall.decode_invocation.frameMap_kt {Cs Vc Ub U Ac Rp Nt : Set U64} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (B : SysL st H Cs OS ia ie s) (dev : DevFrAl st OS s) + {ptr rights oldAsid oldVa : U64} {sz : capability.FrameSize} {device mapped oldStage : Bool} + (cap : obj.Slot.cap st slot s = ok (.Frame ptr sz rights device mapped oldStage oldAsid oldVa)) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame ptr sz rights device mapped oldStage oldAsid oldVa) extra) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageMap len slot + (.Frame ptr sz rights device mapped oldStage oldAsid oldVa) blk call don fp buf extra ⦃ _ q _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s q ⦄ := by + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + refine WP.spec_mono (syscall.decode_invocation.frameMapExactEffect hA hPl h vr P B.sys.fr dev cap d + a len blk call don fp buf) ?_ + rintro ⟨_, q, _⟩ (eq | ⟨tag, edit⟩) + · change q = s at eq + subst q + exact EdgeKeepOn.refl _ _ + · obtain ⟨_, _, _, _, _, _, path, _, _, _, _, write⟩ := edit.edit + exact EdgeKeepOn.ofMapWrite h P.heap kinds path write + +/-- **PageTableMap keeps the column's words.** -/ +theorem syscall.decode_invocation.pageTableMap_kt {Cs Vc Ub U Ac Rp Nt : Set U64} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot ptr oldAsid oldVa : U64} (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + {mapped : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.PageTable ptr mapped oldAsid oldVa) extra) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr mapped oldAsid oldVa)) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableMap len slot + (.PageTable ptr mapped oldAsid oldVa) blk call don fp buf extra ⦃ _ q _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s q ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + cases mapped + · have old := okinj ((capA_eq s slot).symm.trans cap) + have al := (h.footprint ptr (h.pageTables slot P.src ptr false oldAsid oldVa old)).1 + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + refine WP.spec_mono (vspace.decode_page_table.mapExactEffect hPl h vr P D (canon_pt cap) al a len buf) ?_ + rintro ⟨_, q, _⟩ (eq | ⟨tag, event⟩) + · change q = s at eq + subst q + exact EdgeKeepOn.refl _ _ + · obtain ⟨_, _, _, _, _, _, path, _, _, _, _, _, write⟩ := event.edit + exact EdgeKeepOn.ofMapWrite h P.heap kinds path write + · refine WP.spec_mono (vspace.decode_page_table.mapMappedKeeps (st := st) (ar := ar) + (s := s) (slot := slot) (ptr := ptr) (oldAsid := oldAsid) (oldVa := oldVa) (extra := extra) a len buf) ?_ + rintro ⟨_, q, _⟩ eq + change q = s at eq + subst q + exact EdgeKeepOn.refl _ _ + +/-- **PageTableUnmap of a mapped table keeps the column's words.** -/ +theorem syscall.decode_invocation.unmapMapped_kt + {Cs Vc Ub U Ac Rp Nt : Set U64} + {K : capability.Cap → Prop} {Ty : S → Prop} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot ptr a va : U64} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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 + (.PageTable ptr true a va) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr true a va)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (arch : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s arch fl4_abi.label.ARMPageTableUnmap len slot (.PageTable ptr true a va) + blk call don fp buf extra ⦃ _ q _ => EdgeKeepOn st (KtHdrW st OS Kt s) s q ⦄ := by + have hiObj r (hr : r ∈ Hr) : H r = some (.other 13) := by + rw [h.highRoots] at hr + obtain ⟨x, hx, m, q, hc⟩ := hr + exact h.highObjects x hx r m q hc + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono + (vspace.decode_page_table.unmapMappedEffect hA hPl h.core place I D P B cap h.pageTables h.eptRoots + h.pageObjects h.highObjects hiObj ptKs arch len buf) ?_ + rintro ⟨_, q, _⟩ (eq | cleared) + · subst q; exact EdgeKeepOn.refl _ _ + · exact EdgeKeepOn.ofVsZ h cleared.memory + +/-- **PageTableUnmap of an unmapped table keeps the column's words.** -/ +theorem syscall.decode_invocation.unmapUnmapped_kt + {Cs Vc Ub U Ac Rp Nt : Set U64} + {K : capability.Cap → Prop} {Ty : S → Prop} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot ptr a va : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (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 + (.PageTable ptr false a va) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr false a va)) + (arch : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s arch fl4_abi.label.ARMPageTableUnmap len slot (.PageTable ptr false a va) + blk call don fp buf extra ⦃ _ q _ => EdgeKeepOn st (KtHdrW st OS Kt s) s q ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + exact vspace.decode_page_table.unmapUnmappedInvariant I D P cap (EdgeKeepOn.refl _ s) + (fun _ _ mem _ _ => EdgeKeepOn.ofVsKeep h mem) arch len buf + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aPtCap.lean b/proofs/Fl4ProofsA64/P1/S1aPtCap.lean index af74b53fd..986bfcc1f 100644 --- a/proofs/Fl4ProofsA64/P1/S1aPtCap.lean +++ b/proofs/Fl4ProofsA64/P1/S1aPtCap.lean @@ -33,6 +33,11 @@ Gen 20 (a64 gen-160 merge): the definitions `PtCapP`, `PtCap` and the lemmas `Pt verbatim); they are imported from there and dropped here. `PtCap` across the `ArmQIAt` arms of `armQHAt` and `cdt.revoke` is a64's `ArmQIAt` clause (`ArmQIAt.ptCap`; S1aPtCol's `S1aZ2.ptCap`). +Gen 39 (Architect ruling L1): **`NewPt`**'s body widened to types 11 and 14 (`HighVSpace` roots, S1aHvPt's `HvPt`); +**`NewPt11`** (the type-11 bases, `NewPt`'s gen-19 body) now names the heap side of **`UtEnd.ptHA`** / **`UtEnd.ptCapH`** +(statements changed: a type-14 root is an `other 13` object, not a `VcH` page); **`UtEnd.ptN`** (`PtCap` over any +`Pt ∪ N` holding the type-11 bases; `UtEnd.pt` is its instance). + Named premises: none. Case facts: none new (the deletion reads MdbDelIn's `DelIn` / `DelR`, retype MdbVcCap's hypotheses). -/ @@ -100,8 +105,12 @@ end cn /-! ## Retype / reset -/ -/-- The creation bases of a type-11 (`PageTable`) retype. -/ +/-- The creation bases of a type-11 (`PageTable`) or (gen 39, Architect ruling L1) type-14 (`HighVSpace`) retype. -/ def NewPt (nt aligned us win : U64) : Set U64 := + {v | (nt.val = 11 ∨ nt.val = 14) ∧ ∃ j, j < win.val ∧ v = bjA aligned (zA nt.val us) j} + +/-- (gen 39) The creation bases of a type-11 (`PageTable`) retype only (`NewPt`'s gen-19 body: the 4 KiB tables). -/ +def NewPt11 (nt aligned us win : U64) : Set U64 := {v | nt.val = 11 ∧ ∃ j, j < win.val ∧ v = bjA aligned (zA nt.val us) j} /-- **A retype's new page-table cap is type 11's**, at the creation base. -/ @@ -119,11 +128,12 @@ theorem UtArgs.dev11 {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot · exfalso rcases UtArgs.devK hU with h | h | h | h <;> omega -/-- **`PtCap` at the creation's end over `Pt ∪ NewPt`** (MdbVcCap's `UtEnd.vc` at `PtCapP`). -/ -theorem UtEnd.pt {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} {s0 s1 s' : S} {slot p sb : U64} {dev : Bool} +/-- (gen 39) **`PtCap` at the creation's end over `Pt ∪ N`**, `N` holding the type-11 creation bases. -/ +theorem UtEnd.ptN {H1 H' : Heap} {OS1 N : Set U64} {lo hi : Nat} {s0 s1 s' : S} {slot p sb : U64} {dev : Bool} {aligned nt us dest off win : U64} (C0 : PtCap st Pt OS s0) - (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) : - PtCap st (Pt ∪ NewPt nt aligned us win) OS1 s' := by + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) + (hN : nt.val = 11 → ∀ j, j < win.val → bjA aligned (zA nt.val us) j ∈ N) : + PtCap st (Pt ∪ N) OS1 s' := by intro x hx by_cases hxs : x = slot · subst hxs @@ -134,12 +144,19 @@ theorem UtEnd.pt {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} {s0 s1 s' : S} {sl rw [U.E.new j hj] intro q m a v hc obtain ⟨h11, rfl⟩ := newCapA_pt U.A.hn hc - exact Or.inr ⟨h11, j, hj, rfl⟩ + exact Or.inr (hN h11 j hj) · have hk : capA st s' x = capA st s0 x := by rw [U.E.keep x hx hxs (fun j hj e => hw ⟨j, hj, e⟩), U.k1 x hx hxs] rw [hk] exact PtCapP.mono Set.subset_union_left (C0 x (U.os x hx)) +/-- **`PtCap` at the creation's end over `Pt ∪ NewPt`** (MdbVcCap's `UtEnd.vc` at `PtCapP`). -/ +theorem UtEnd.pt {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} {s0 s1 s' : S} {slot p sb : U64} {dev : Bool} + {aligned nt us dest off win : U64} (C0 : PtCap st Pt OS s0) + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) : + PtCap st (Pt ∪ NewPt nt aligned us win) OS1 s' := + UtEnd.ptN C0 U fun h11 j hj => ⟨Or.inl h11, j, hj, rfl⟩ + /-- **`PtCap` at the reset form** `VcKeptR H Pt` when no page-table cap names a table meeting the region. -/ theorem PtCap.keptR {lo hi : Nat} {s : S} (C : PtCap st Pt OS s) (hf : ∀ y ∈ OS, ∀ p m a v, capA st s y = .PageTable p m a v → ¬ RegionD H lo hi p) : @@ -151,7 +168,7 @@ theorem UtEnd.ptHA {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {aligned nt us dest off win : U64} (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) (X : UtX H H1 lo hi us) (hW : win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) - (h : VcH H Pt) : VcH H' (VcKeptR H Pt lo hi ∪ NewPt nt aligned us win) := by + (h : VcH H Pt) : VcH H' (VcKeptR H Pt lo hi ∪ NewPt11 nt aligned us win) := by rintro v (hk | ⟨h11, j, hj, rfl⟩) · exact UtEnd.vcKept U X h v hk · rcases hW with h0 | ⟨_, hU⟩ @@ -173,10 +190,11 @@ theorem UtEnd.ptCapH {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array (hR : H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ hi = p.val + 2 ^ sb.val)) (C : PtCap st Pt OS s0) (hP : VcH H Pt) : - PtCap st (VcKeptR H Pt lo hi ∪ NewPt nt aligned us win) OS1 s' ∧ - VcH H' (VcKeptR H Pt lo hi ∪ NewPt nt aligned us win) := - ⟨UtEnd.pt (C.keptR fun y hy q m a v hc => - UtEnd.keyFresh D P B hcap U hR hy hc (RngKeyA.pt q m a v) (ptrA_pt q m a v) (hP q (C y hy q m a v hc))) U, + PtCap st (VcKeptR H Pt lo hi ∪ NewPt11 nt aligned us win) OS1 s' ∧ + VcH H' (VcKeptR H Pt lo hi ∪ NewPt11 nt aligned us win) := + ⟨UtEnd.ptN (C.keptR fun y hy q m a v hc => + UtEnd.keyFresh D P B hcap U hR hy hc (RngKeyA.pt q m a v) (ptrA_pt q m a v) (hP q (C y hy q m a v hc))) U + fun h11 j hj => ⟨h11, j, hj, rfl⟩, UtEnd.ptHA U X hW hP⟩ set_option maxHeartbeats 1000000 in diff --git a/proofs/Fl4ProofsA64/P1/S1aPtCol.lean b/proofs/Fl4ProofsA64/P1/S1aPtCol.lean index 814225a4b..cdafb51c2 100644 --- a/proofs/Fl4ProofsA64/P1/S1aPtCol.lean +++ b/proofs/Fl4ProofsA64/P1/S1aPtCol.lean @@ -2,8 +2,8 @@ P1 (aarch64, A64-S1A gen 20): **the page-table column `S1aPtCol` and the producer of a64's new `ArmDecHyps` fields** (Architect ruling 16:13Z, items 2 and 3, after the merge of a64 gens 157–160). -* **`PtHG H Pt`** (the generalised `PtH`): every table of `Pt` lies inside one `other` heap object, - `∃ q z, H q = some (.other z) ∧ q ≤ p ∧ p + 4096 ≤ q + 2 ^ z`. **`PtHG.ofVcH`** (S1aVcH's `VcH H Pt`, the gen-19 +* **`PtHG H Pt`** (the generalised `PtH`): every table of `Pt` is 4 KiB aligned (gen 34) and lies inside one `other` + heap object, `p % 4096 = 0 ∧ ∃ q z, H q = some (.other z) ∧ q ≤ p ∧ p + 4096 ≤ q + 2 ^ z`. **`PtHG.ofVcH`** (S1aVcH's `VcH H Pt`, the gen-19 `PtH`, is the case `q = p`, `z = 12`), **`PtHG.mono`**, **`PtHG.fit`** (no table wraps, from `HeapOK.fits`). * **`HiCap511 st OS s`**: every `HighVSpace p …` cap of an `OS` slot has a table descriptor at its root's entry 511 (`mem (p + 4088) & 3 = 3`; `init_high_vspace` writes it; handoff gen 19, item 3: what ASIDPool Assign's tag-2 entry @@ -38,12 +38,15 @@ plus the Stage-2 granule typing `S2DecTy` at the IPA width `n`); `S1aDecHyps.of` [P] record `hPl : ArchPlat ar` (QueueS2Ty) with `n := hPl.ipa`. S1aS2Dec's `S2DecTy.ofS2Ty` gives the Stage-2 part from QueueS2Ty's `S2Ty` + `S2OK` under two further facts (stop-first, not wired). +Gen 39: `s1aStepPt` takes `Hv : HvPt st Pt OS s` after `hdf` (passed to `s1aStepH`). + Named premises: none new (`mcp`, `cs`, `fh` are QueueDecTcb's [P] `TcbPlace.mcp` / `TcbPlace.curSc` / `SspHyps.fh`, a64's ruled `ArmDecHyps` fields). Case facts: none new (`HeapKsOff`, S1aPlace). -/ import Fl4ProofsA64.P1.S1aStepH import Fl4ProofsA64.P1.S1aPtCap import Fl4ProofsA64.P1.S1aVsDec +import Fl4ProofsA64.P1.S1aR2Frame open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P1 @@ -70,7 +73,7 @@ theorem HeapKsOff.ptAsWG (hK : HeapKsOff H kb) (hP : PtHG H Pt) (hkw : kb.val + have e1 := wadd_val (x := p) (y := o) (by omega) have e2 := wadd_val (x := kb) (y := o') (by omega) have e3 := congrArg UScalar.val e - obtain ⟨q, z, hq, g1, g2⟩ := hP p hp + obtain ⟨-, q, z, hq, g1, g2⟩ := hP p hp have hk := hK.2 q z hq generalize (2 : Nat) ^ z = Z at hk g2 rcases hk with hk | hk | ⟨hk1, hk2⟩ | ⟨hk1, hk2⟩ <;> omega @@ -128,14 +131,16 @@ theorem S1aDecHyps.of {n : U64} {s : S} {cap : capability.Cap} {extra : Aeneas.S Te ⊆ Pt ∧ VsTy st (L.ksb s) Pp Tb Lv s ∧ NoTag3 st Pp s ∧ HighRoot511 st Pp s ∧ S2DecTy st Pp Te Re n s) (C : S1aPtCol st H OS Pt s) (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) - (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok cap) : S1aDecHyps st H Pt n s cap where + (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok cap) (hdf : DevFrAl st OS s) : + S1aDecHyps st H Pt n s cap where mcp := mcp cs := cs fh := fh vs := let ⟨Pp, Tb, Lv, Te, Re, h1, h2, h3, ty, hN, hH, h2t⟩ := hvs ⟨Pp, Tb, Lv, Te, Re, h1, h2, h3, VsDecTy.ofS1a ty hN hH, h2t⟩ - ptCap := C.ptCapB P.heap P.src hcap + ptCap := fun p m a v e => let h := C.ptCapB P.heap P.src hcap p m a v e; ⟨h.1, h.2, (C.ph p h.1).1⟩ ptKs := C.ptKs P.heap hks B.ly.ksw + frAl := fun _ _ _ _ _ _ _ h => (hdf.invoked P.src hcap).aligned4K h end dec @@ -149,7 +154,7 @@ variable {Vq Vc Ub : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} { theorem syscall.decode_invocation.armQH_s1aPt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {Ub' : Set U64} (I : DelIn st ar H Cs OS Vq Ub' Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) @@ -162,22 +167,24 @@ theorem syscall.decode_invocation.armQH_s1aPt (hA : P0.ArchTotal ar) (hM : MaxSp (hvs : ∃ (Pp Tb : Set U64) (Lv : U64 → Nat) (Te : Set U64) (Re : U64 → Nat), Pp ⊆ Pt ∧ Tb ⊆ Pt ∧ Te ⊆ Pt ∧ VsTy st (L.ksb s) Pp Tb Lv s ∧ NoTag3 st Pp s ∧ HighRoot511 st Pp s ∧ S2DecTy st Pp Te Re hPl.ipa s) - (C : S1aPtCol st H OS Pt s) (len : U64) (blk call don fp : Bool) (buf : U64) : + (C : S1aPtCol st H OS Pt s) (hdf : DevFrAl 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 ⦃ r s' _ => S1aZ2 st H Cs OS Vq Vc Ub ia ie (DecArmKK3 cap lbl) s s' ∧ (HiCap511 st OS s' → S1aPtCol st H OS Pt s') ⦄ := WP.spec_mono (syscall.decode_invocation.armQH_s1a (Vc := Vc) (Ub := Ub) hA hM hPl I hKZ hPI D P B Y hcap hks a hc hIq - hSC (S1aDecHyps.of mcp cs fh hvs C P B hks hcap) len blk call don fp buf) + hSC (S1aDecHyps.of mcp cs fh hvs C P B hks hcap hdf) len blk call don fp buf) fun _ d => ⟨d, S1aPtCol.ofArmQIAt d.1 C⟩ variable {Uq : Set U64} -/-- (gen 21) **`s1aStepH` with its decode-hypothesis record built from the column** (`S1aDecHyps.of`; the column's -`PtCap ∧ PtHG` is `s1aStepH`'s `Cp`, and the post `S1aStep` carries it to the end). -/ -theorem syscall.decode_invocation.s1aStepPt (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} +/-- Build the common step's decode inputs from the active R2 witness and the placement column. -/ +theorem syscall.decode_invocation.s1aStepPt {Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) @@ -189,14 +196,20 @@ theorem syscall.decode_invocation.s1aStepPt (hA : P0.ArchTotal ar) (hM : MaxSpi (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (cs : L.mem s (scA (L.curW s)) ≠ 0#u64) (fh : ∀ t, cap = .Thread t → NullOrEp H (capA st s (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) - (hvs : ∃ (Pp Tb : Set U64) (Lv : U64 → Nat) (Te : Set U64) (Re : U64 → Nat), Pp ⊆ Pt ∧ Tb ⊆ Pt ∧ - Te ⊆ Pt ∧ VsTy st (L.ksb s) Pp Tb Lv s ∧ NoTag3 st Pp s ∧ HighRoot511 st Pp s ∧ - S2DecTy st Pp Te Re hPl.ipa s) - (Cq : S1aPtCol st H OS Pt s) (len : U64) (blk call don fp : Bool) (buf : U64) : + (R2 : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (Cq : S1aPtCol st H OS Pt s) (hdf : DevFrAl st OS s) (Hv : HvPt st Pt OS s) + (Ep : EptPlaced st H OS Pt s) (objects : PtObjects st H OS s) + (highObjects : HvObjects st H 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 ⦃ r s' _ => - S1aStep st Cs Ub ia ie s' ⦄ := - syscall.decode_invocation.s1aStepH hA hM hPl I hKZ hPI D P B Y hcap hks hfm hPN C Kc hal ⟨Cq.cap, Cq.ph⟩ a hc hIq - hSC (S1aDecHyps.of mcp cs fh hvs Cq P B hks hcap) len blk call don fp buf + S1aStep st Cs Ub ia ie s' ⦄ := by + obtain ⟨pools, tables, level, _, stage2, depth, width, hp, ht, he, ty, no3, hi, ty2, place2, heap2⟩ := + R2.hvs W.pools W.tables W.granules W.stage2 + have dec := S1aDecHyps.of mcp cs fh + ⟨pools, tables, level, Gran stage2 width, s2gRe stage2 depth, hp, ht, he, ty, no3, hi, + S2DecTy.ofTeH P.heap ty2 place2 heap2⟩ Cq P B hks hcap hdf + exact syscall.decode_invocation.s1aStepH hA hM hPl I W hKZ hPI D P B Y hcap hks hfm hPN C Kc hal ⟨Cq.cap, Cq.ph⟩ + hdf Hv Cq.hi Ep objects highObjects a hc hIq hSC dec len blk call don fp buf end top diff --git a/proofs/Fl4ProofsA64/P1/S1aPtStep.lean b/proofs/Fl4ProofsA64/P1/S1aPtStep.lean index b32d9a37e..2b898689c 100644 --- a/proofs/Fl4ProofsA64/P1/S1aPtStep.lean +++ b/proofs/Fl4ProofsA64/P1/S1aPtStep.lean @@ -28,6 +28,21 @@ P1 (aarch64, A64-S1A gen 21): **the page-table column across the S1a step arms R `HiCap511` is not carried by these arms (handoff gen 21): a retype's new `HighVSpace` caps need `init_high_vspace`'s entry-511 write, MakePool / ASIDPool Assign a footprint of their writes off the roots' `+ 4088` words. +(gen 33, Architect 00:25Z, G1) **`DevFrP`** / **`DevFrAl st OS s`** (`CapInv`: every device `Frame` cap of an `OS` slot +is aligned to its size, with a 4 KiB projection for a64's `ArmDecHyps.frAl`), **`DevFrAl.invoked`**, **`DevFrAl.empty`** +(null slots, `w0`). Its preservation across the S1a steps (Retype: `untyped.rs` `align_up(free_ref, obj_size)`) is +gen-34 work. + +(gen 34, Architect ruling H1) **`PtHG`'s body gains `p % 4096 = 0` per table** (the `ArmDecHyps.ptCap` alignment); +`PtHG.ofVcH` takes `HeapOK H` (`HeapOK.align` at 12 bits); `mono` / `grow` / `union` / `offR` / `poolEnd` carry the +conjunct; Retype's new tables by **`UtEnd.newPtAl`** (MdbUtV's `UtArgs.zalA`: `align_up` to 12 bits for type 11). + +(gen 39, Architect ruling L1: `NewPt` with type-14 roots) **`PtHG.keyOffNC`** / **`UtEnd.keyOff`** (the freshness +arguments of `PtCap.offNC` / `UtEnd.ptOff` at one range-keyed cap naming a table of `Pt`; those two are now their +instances, statements unchanged), **`UtEnd.bjAl`** (a creation base at an object size of at least 12 bits is 4 KiB +aligned; `UtEnd.newPtAl` and S1aDevFr's `UtEnd.devFr` read it), **`UtEnd.newPtH`** (a new type-11 / type-14 object is +`other 12` / `other 13`; `UtEnd.ptCapHG`'s heap side). + Named premises: none. Case facts: none new. -/ import Fl4ProofsA64.P1.S1aPtCap @@ -51,9 +66,10 @@ variable {OS Pt : Set U64} /-! ## The clauses (moved from S1aPtCol) -/ -/-- **Every table of `Pt` lies inside one `other` heap object** (module docstring; the generalised `PtH`). -/ +/-- **Every table of `Pt` is 4 KiB aligned and lies inside one `other` heap object** (module docstring; the +generalised `PtH`; the alignment conjunct: gen 34, Architect ruling H1). -/ def PtHG (H : Heap) (Pt : Set U64) : Prop := - ∀ p ∈ Pt, ∃ q z, H q = some (.other z) ∧ q.val ≤ p.val ∧ p.val + 4096 ≤ q.val + 2 ^ z + ∀ p ∈ Pt, p.val % 4096 = 0 ∧ ∃ q z, H q = some (.other z) ∧ q.val ≤ p.val ∧ p.val + 4096 ≤ q.val + 2 ^ z variable (st) in /-- **A `HighVSpace` cap's root has a table descriptor at entry 511** (module docstring). -/ @@ -67,15 +83,17 @@ structure S1aPtCol (H : Heap) (OS Pt : Set U64) (s : S) : Prop where ph : PtHG H Pt hi : HiCap511 st OS s -/-- The gen-19 `PtH` (`VcH H Pt`: every table a 4 KiB `other` object) is a `PtHG`. -/ -theorem PtHG.ofVcH (h : VcH H Pt) : PtHG H Pt := - fun p hp => ⟨p, 12, h p hp, le_refl _, by norm_num⟩ +/-- The gen-19 `PtH` (`VcH H Pt`: every table a 4 KiB `other` object, aligned by `HeapOK.align`) is a `PtHG`. -/ +theorem PtHG.ofVcH (hH : HeapOK H) (h : VcH H Pt) : PtHG H Pt := fun p hp => by + have ha := hH.align p _ (h p hp) + simp only [HKind.bits] at ha + exact ⟨by norm_num at ha; exact ha, p, 12, h p hp, le_refl _, by norm_num⟩ theorem PtHG.mono {Pt' : Set U64} (hs : Pt' ⊆ Pt) (h : PtHG H Pt) : PtHG H Pt' := fun p hp => h p (hs hp) /-- **No table of `Pt` wraps** (`HeapOK.fits` on the enclosing object). -/ theorem PtHG.fit (hH : HeapOK H) (h : PtHG H Pt) : ∀ p ∈ Pt, p.val + 4096 ≤ 2 ^ 64 := fun p hp => by - obtain ⟨q, z, hq, -, h2⟩ := h p hp + obtain ⟨-, q, z, hq, -, h2⟩ := h p hp have hf := hH.fits q _ hq simp only [HKind.bits] at hf omega @@ -97,11 +115,44 @@ theorem HiCap511.keep {s s' : S} (h : HiCap511 st OS s) (hc : ∀ y ∈ OS, capA theorem HiCap511.ofNoHv {s : S} (h : ∀ y ∈ OS, ∀ p m a, capA st s y ≠ .HighVSpace p m a) : HiCap511 st OS s := fun y hy p m a e => absurd e (h y hy p m a) +/-! ## Device-frame alignment -/ + +/-- A device frame is aligned to its frame size (l4v `valid_cap`'s `cap_aligned`). -/ +def DevFrP (c : capability.Cap) : Prop := + ∀ p sz r m e a v, c = .Frame p sz r true m e a v → + ∀ bits : U64, sz.bits = ok bits → p.val % 2 ^ bits.val = 0 + +/-- Device-frame alignment implies the 4 KiB alignment used by the decoder. -/ +theorem DevFrP.aligned4K {c : capability.Cap} (h : DevFrP c) {p r a v : U64} + {sz : capability.FrameSize} {m e : Bool} (hc : c = .Frame p sz r true m e a v) : + p.val % 4096 = 0 := by + obtain ⟨bits, hb⟩ : ∃ bits : U64, sz.bits = ok bits := by cases sz <;> exact ⟨_, rfl⟩ + have enough : 12 ≤ bits.val := by + cases sz <;> simp only [capability.FrameSize.bits] at hb <;> rw [← okinj hb] <;> decide + have divides : 4096 ∣ (2 : Nat) ^ bits.val := Nat.pow_dvd_pow 2 enough + exact Nat.mod_eq_zero_of_dvd (divides.trans (Nat.dvd_of_mod_eq_zero (h p sz r m e a v hc bits hb))) + +variable (st) in +/-- Every device frame cap in `OS` is aligned to its size. +`untyped.rs` retypes device frames at `align_up(free_ref, obj_size)`. -/ +def DevFrAl (OS : Set U64) (s : S) : Prop := CapInv st DevFrP OS s + +/-- Frame-size alignment at the invoked slot. -/ +theorem DevFrAl.invoked {s : S} (h : DevFrAl st OS s) {slot : U64} (hx : slot ∈ OS) {cap : capability.Cap} + (hcap : obj.Slot.cap st slot s = ok cap) : DevFrP cap := by + have e : capA st s slot = cap := okinj ((capA_eq s slot).symm.trans hcap) + rw [← e] + exact h slot hx + +/-- **Null `OS` slots** (`w0`). -/ +theorem DevFrAl.empty {s : S} (h : ∀ x ∈ OS, capA st s x = .Null) : DevFrAl st OS s := + CapInv.empty (fun _ _ _ _ _ _ _ e => by cases e) h + /-! ## `PtHG` along heap changes -/ /-- `PtHG` along a heap that grows. -/ theorem PtHG.grow {H' : Heap} (h : PtHG H Pt) (hg : ∀ q k, H q = some k → H' q = some k) : PtHG H' Pt := - fun p hp => let ⟨q, z, hq, g⟩ := h p hp; ⟨q, z, hg _ _ hq, g⟩ + fun p hp => let ⟨ha, q, z, hq, g⟩ := h p hp; ⟨ha, q, z, hg _ _ hq, g⟩ theorem PtHG.union {Pt' : Set U64} (h : PtHG H Pt) (h' : PtHG H Pt') : PtHG H (Pt ∪ Pt') := by rintro p (hp | hp) @@ -116,9 +167,9 @@ theorem PtHG.offR {H1 : Heap} {lo hi : Nat} (h : PtHG H Pt) (hk : ∀ q k, H q = some k → H1 q = some k ∨ (lo ≤ q.val ∧ q.val + 2 ^ k.bits ≤ hi)) : PtHG H1 (PtOffR Pt lo hi) := by rintro p ⟨hp, ho⟩ - obtain ⟨q, z, hq, g1, g2⟩ := h p hp + obtain ⟨ha, q, z, hq, g1, g2⟩ := h p hp rcases hk q _ hq with h1 | ⟨i1, i2⟩ - · exact ⟨q, z, h1, g1, g2⟩ + · exact ⟨ha, q, z, h1, g1, g2⟩ · exfalso simp only [HKind.bits] at i2 generalize (2 : Nat) ^ z = Z at i2 g2 @@ -135,18 +186,18 @@ theorem PtCap.offR {lo hi : Nat} {s : S} (C : PtCap st Pt OS s) section fresh variable {ia ie : Nat} -/-- **A childless RAM untyped's region holds no capped table** (module docstring). -/ -theorem PtCap.offNC {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot x p sb fi : U64} +/-- (gen 39) **A childless RAM untyped's region holds no capped table, at any range-keyed cap naming a table of `Pt`** +(`PtCap.offNC`'s argument at one cap). -/ +theorem PtHG.keyOffNC {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot x p sb fi : U64} (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (hx : x ∈ OS) (hcx : capA st s x = .Untyped p sb fi false) - (he : cdt.ensure_no_children st s x = ok (core.result.Result.Ok ())) (C : PtCap st Pt OS s) (hG : PtHG H Pt) : - ∀ y ∈ OS, ∀ t m a v, capA st s y = .PageTable t m a v → t.val + 4096 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ t.val := by - intro y hy t m a v hc - obtain ⟨q, z, hq, g1, g2⟩ := hG t (C y hy t m a v hc) + (he : cdt.ensure_no_children st s x = ok (core.result.Result.Ok ())) (hG : PtHG H Pt) {y t : U64} + (hy : y ∈ OS) (hk : RngKeyA (capA st s y)) (hpt : ptrA (capA st s y) = t) (ht : t ∈ Pt) : + t.val + 4096 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ t.val := by + obtain ⟨-, q, z, hq, g1, g2⟩ := hG t ht obtain ⟨G0, par0, hT0, -, -⟩ := B.sys.stz.1.1.tree - have hno := cdt.ensure_no_children.noKey P.os hT0.utRangeOrd B.sys.stz.1.2.1 hx hcx he y hy - (by rw [hc]; exact RngKeyA.pt t m a v) - rw [hc, ptrA_pt] at hno + have hno := cdt.ensure_no_children.noKey P.os hT0.utRangeOrd B.sys.stz.1.2.1 hx hcx he y hy hk + rw [hpt] at hno have hin := B.sys.ur.rin hx hcx q _ hq simp only [HKind.bits, MeetsR] at hin generalize (2 : Nat) ^ z = Z at hin g2 @@ -156,8 +207,19 @@ theorem PtCap.offNC {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot x · have := hin hm omega -/-- **At a creation's end no capped table meets the region** (module docstring). -/ -theorem UtEnd.ptOff {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} +/-- **A childless RAM untyped's region holds no capped table** (module docstring). -/ +theorem PtCap.offNC {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot x p sb fi : U64} + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (hx : x ∈ OS) + (hcx : capA st s x = .Untyped p sb fi false) + (he : cdt.ensure_no_children st s x = ok (core.result.Result.Ok ())) (C : PtCap st Pt OS s) (hG : PtHG H Pt) : + ∀ y ∈ OS, ∀ t m a v, capA st s y = .PageTable t m a v → t.val + 4096 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ t.val := by + intro y hy t m a v hc + exact PtHG.keyOffNC P B hx hcx he hG hy (by rw [hc]; exact RngKeyA.pt t m a v) (by rw [hc, ptrA_pt]) + (C y hy t m a v hc) + +/-- (gen 39) **At a creation's end no range-keyed cap's table of `Pt` meets the region** (`UtEnd.ptOff`'s argument +at one cap). -/ +theorem UtEnd.keyOff {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} {aligned nt us dest off win : U64} (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s0 (.Untyped p sb fi dev) extra) @@ -166,11 +228,10 @@ theorem UtEnd.ptOff {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array o (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) (hR : H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ hi = p.val + 2 ^ sb.val)) - (C : PtCap st Pt OS s0) (hG : PtHG H Pt) : - ∀ y ∈ OS, ∀ t m a v, capA st s0 y = .PageTable t m a v → t.val + 4096 ≤ lo ∨ hi ≤ t.val := by + (hG : PtHG H Pt) {y t : U64} (hy : y ∈ OS) (hk : RngKeyA (capA st s0 y)) (hpt : ptrA (capA st s0 y) = t) + (ht : t ∈ Pt) : t.val + 4096 ≤ lo ∨ hi ≤ t.val := by rcases hR with rfl | ⟨hd, ⟨w, he⟩, rfl, rfl⟩ - · intro y hy t m a v hc - obtain ⟨q, z, hq, g1, g2⟩ := hG t (C y hy t m a v hc) + · obtain ⟨-, q, z, hq, g1, g2⟩ := hG t ht have g := U.hole q _ hq simp only [HKind.bits] at g generalize (2 : Nat) ^ z = Z at g g2 @@ -178,7 +239,23 @@ theorem UtEnd.ptOff {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array o · subst hd cases w have R := UtDecP.of_live D B.sys P hcap B.ln B.vr B.ly - exact PtCap.offNC P B R.src R.cap he C hG + exact PtHG.keyOffNC P B R.src R.cap he hG hy hk hpt ht + +/-- **At a creation's end no capped table meets the region** (module docstring). -/ +theorem UtEnd.ptOff {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) + (hR : H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ + hi = p.val + 2 ^ sb.val)) + (C : PtCap st Pt OS s0) (hG : PtHG H Pt) : + ∀ y ∈ OS, ∀ t m a v, capA st s0 y = .PageTable t m a v → t.val + 4096 ≤ lo ∨ hi ≤ t.val := by + intro y hy t m a v hc + exact UtEnd.keyOff D P B hcap U hR hG hy (by rw [hc]; exact RngKeyA.pt t m a v) (by rw [hc, ptrA_pt]) + (C y hy t m a v hc) end fresh @@ -187,6 +264,75 @@ end fresh section rt variable {A : Type _} {ar : machine.Arch A} {ia ie : Nat} +/-- Each object in a Retype batch is aligned to the full object size. -/ +theorem UtEnd.bjAligned {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev reset : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) + (hU : UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) {j : Nat} (hj : j < win.val) : + (bjA aligned (zA nt.val us) j).val % 2 ^ (zA nt.val us).val = 0 := by + have R := UtDecP.of_live D B.sys P hcap B.ln B.vr B.ly + obtain ⟨ha, -⟩ := UtArgs.zalA R.ty R.ext R.cap R.utv hU + have hfit := U.A.aw + have hpf := U.A.pf + rw [(bj_facts (aligned := aligned) (z := zA nt.val us) hj (by omega)).1] + exact Nat.mod_eq_zero_of_dvd + (Nat.dvd_add (Nat.dvd_of_mod_eq_zero ha) ((dvd_refl _).mul_left j)) + +/-- (gen 39) **A creation base at an object size of at least 12 bits is 4 KiB aligned** (`UtArgs.zalA`: `align_up` to +the object size). -/ +theorem UtEnd.bjAl {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev reset : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) + (hU : UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) {j : Nat} (hj : j < win.val) + (hz : 12 ≤ (zA nt.val us).val) : (bjA aligned (zA nt.val us) j).val % 4096 = 0 := by + have divides : 4096 ∣ (2 : Nat) ^ (zA nt.val us).val := Nat.pow_dvd_pow 2 hz + exact Nat.mod_eq_zero_of_dvd + (divides.trans (Nat.dvd_of_mod_eq_zero (UtEnd.bjAligned D P B hcap U hU hj))) + +/-- **A retype's new page tables are 4 KiB aligned** (gen 34; `UtArgs.zalA`: `align_up` to the object size, 12 bits +for type 11). -/ +theorem UtEnd.newPtAl {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) + (hW : win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) : + ∀ v ∈ NewPt nt aligned us win, v.val % 4096 = 0 := by + rintro v ⟨h11, j, hj, rfl⟩ + rcases hW with h0 | ⟨_, hU⟩ + · omega + exact UtEnd.bjAl D P B hcap U hU hj (by rcases h11 with h | h <;> rw [h] <;> simp [zA]) + +/-- (gen 39) **A retype's new type-11 / type-14 object is an `other` object of at least 12 bits at its base** +(`UtEnd.hn` at `newKind`: `other 12` / `other 13`). -/ +theorem UtEnd.newPtH {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (U : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win) + (hW : win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) : + ∀ v ∈ NewPt nt aligned us win, ∃ z, 12 ≤ z ∧ H' v = some (.other z) := by + rintro v ⟨h11, j, hj, rfl⟩ + rcases hW with h0 | ⟨_, hU⟩ + · omega + have hd : dev = false := by + cases dev + · rfl + · exfalso + rcases h11 with h' | h' <;> rcases UtArgs.devK hU with h | h | h | h <;> omega + rcases h11 with h | h + · exact ⟨12, le_refl _, U.hn hd j hj _ (by rw [h]; simp [newKind])⟩ + · exact ⟨13, by norm_num, U.hn hd j hj _ (by rw [h]; simp [newKind])⟩ + /-- **`PtCap ∧ PtHG` at a creation's end over the grown slot set** (module docstring). -/ theorem UtEnd.ptCapHG {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} @@ -203,8 +349,12 @@ theorem UtEnd.ptCapHG {U0 Ac : Set U64} {s0 s1 s' : S} {extra : Aeneas.Std.Array PtHG H' (PtOffR Pt lo hi ∪ NewPt nt aligned us win) := by have hk : (L.ksb s').val + 788736 ≤ 2 ^ 64 := by rw [U.E.fr.1.trans U.w1.1]; exact B.ly.ksw refine ⟨CapInv.growN (P := PtCapP _) (UtEnd.pt (C.offR (UtEnd.ptOff D P B hcap U hR C hG)) U) (PtCapP.null _) - (U.freshN X hk), PtHG.union ((hG.offR X.kept).grow U.grow) fun v hv => ?_⟩ - exact PtHG.ofVcH (UtEnd.ptHA U X hW (VcH.empty H)) v (Or.inr hv) + (U.freshN X hk), PtHG.union ((hG.offR X.kept).grow U.grow) fun v hv => + let ⟨z, hz, hv'⟩ := UtEnd.newPtH U hW v hv + ⟨UtEnd.newPtAl D P B hcap U hW v hv, v, z, hv', le_refl _, by + have := Nat.pow_le_pow_right (n := 2) (by norm_num) hz + norm_num at this + omega⟩⟩ /-- **The untyped arm of `decode_invocation`: S1aRtV's joint post with `PtCap ∧ PtHG` at the one `(H', OS')`** (module docstring). -/ @@ -259,12 +409,12 @@ theorem PtHG.poolEnd {s : S} {x p sb fi : U64} (B : SysL st H Cs OS ia ie s) (hx have e4 : (2 : Nat) ^ 12 = 4096 := by norm_num have hRin := B.sys.ur.rin hx hcx intro t ht - obtain ⟨q, z, hq, g1, g2⟩ := h t ht + obtain ⟨ha, q, z, hq, g1, g2⟩ := h t ht by_cases hD : RegionD H p.val (p.val + 2 ^ sb.val) q · obtain ⟨i1, i2⟩ := RegionD.inside hRin hq hD simp only [HKind.bits, h12, e4] at i2 generalize (2 : Nat) ^ z = Z at i2 g2 - refine ⟨p, 12, (Heap.add_of_mem (N := (· = p)) (kd := .other sb.val) rfl).trans (by rw [h12]), by omega, ?_⟩ + refine ⟨ha, p, 12, (Heap.add_of_mem (N := (· = p)) (kd := .other sb.val) rfl).trans (by rw [h12]), by omega, ?_⟩ rw [e4] omega · have hqp : q ≠ p := by @@ -274,7 +424,7 @@ theorem PtHG.poolEnd {s : S} {x p sb fi : U64} (B : SysL st H Cs OS ia ie s) (hx have := @Nat.one_le_two_pow z have := @Nat.one_le_two_pow sb.val omega - exact ⟨q, z, (Heap.add_of_not (N := (· = p)) (kd := .other sb.val) hqp).trans ((Heap.drop_of_not hD).trans hq), + exact ⟨ha, q, z, (Heap.add_of_not (N := (· = p)) (kd := .other sb.val) hqp).trans ((Heap.drop_of_not hD).trans hq), g1, g2⟩ variable {OS Vc Ub : Set U64} diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AccessBits.lean b/proofs/Fl4ProofsA64/P1/S1aR2AccessBits.lean new file mode 100644 index 000000000..5ba9fb42b --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AccessBits.lean @@ -0,0 +1,107 @@ +/- +P1 (aarch64): descriptor tags and address bits are invariant under AF clearing. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AccessWrite + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "clearAF" => (fun w : U64 => w &&& ~~~1024#u64) + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {s q : S} {n : U64} + +private theorem clearAF_and (w mask : U64) (keeps : (~~~1024#u64) &&& mask = mask) : + clearAF w &&& mask = w &&& mask := by + apply eq_of_bv + let bits : BitVec 64 := (~~~1024#u64).bv + change (w.bv &&& bits) &&& mask.bv = w.bv &&& mask.bv + have keepBits : bits &&& mask.bv = mask.bv := congrArg (fun u : U64 => u.bv) keeps + rw [BitVec.and_assoc, keepBits] + +theorem S1aAccessWrite.mask (edit : S1aAccessWrite st OS Pt Hr s q) + {word : U64} (loc : PtW Pt word) (mask : U64) (keeps : (~~~1024#u64) &&& mask = mask) : + L.mem q word &&& mask = L.mem s word &&& mask := by + rcases edit.memory word loc with eq | clear + · rw [eq] + · rw [clear, clearAF_and _ _ keeps] + +theorem s1aAccessMaskStage1 : (~~~1024#u64) &&& vspace.ADDR_MASK = vspace.ADDR_MASK := by + apply UScalar.eq_of_val_eq + rw [UScalar.val_and, P0.Consts.vspace.ADDR_MASK.val_eq] + decide + +theorem s1aAccessMaskStage2 : (~~~1024#u64) &&& ept.ADDR_MASK = ept.ADDR_MASK := by + apply UScalar.eq_of_val_eq + rw [UScalar.val_and, P0.Consts.ept.ADDR_MASK.val_eq] + decide + +theorem S1aAccessWrite.zero (edit : S1aAccessWrite st OS Pt Hr s q) + {word : U64} (loc : PtW Pt word) (zero : L.mem s word = 0#u64) : L.mem q word = 0#u64 := by + rcases edit.memory word loc with same | clear + · exact same.trans zero + · rw [clear, zero] + decide + +theorem S1aAccessWrite.leaf (edit : S1aAccessWrite st OS Pt Hr s q) + {word : U64} (loc : PtW Pt word) (level : Nat) : + (s1aLeafValid (L.mem q word) level ↔ s1aLeafValid (L.mem s word) level) ∧ + s1aLeafTarget (L.mem q word) level = s1aLeafTarget (L.mem s word) level := by + constructor + · unfold s1aLeafValid + rw [edit.mask loc 3#u64 (by decide)] + · unfold s1aLeafTarget + rw [edit.mask loc vspace.ADDR_MASK s1aAccessMaskStage1] + +private theorem clearAF_zeroBit (v : U64) (zero : v.bv.getLsbD 10 = false) : clearAF v = v := by + apply eq_of_bv + apply BitVec.eq_of_getLsbD_eq + intro i hi + have mask : (1024#u64).bv.getLsbD i = decide (i = 10) := by + change (1024 : Nat).testBit i = decide (i = 10) + rw [show (1024 : Nat) = 2 ^ 10 from rfl, Nat.testBit_two_pow] + by_cases eq : i = 10 <;> simp [eq, eq_comm] + simp only [UScalar.bv_and, UScalar.bv_not, BitVec.getLsbD_and, BitVec.getLsbD_not, mask] + by_cases eq : i = 10 + · subst i + have clear : v.bv[10] = false := by simpa using zero + simp [clear] + · simp [eq, hi] + +private theorem alignedClearBit (v : U64) (al : v.val % 4096 = 0) : v.bv.getLsbD 10 = false := by + change v.val.testBit 10 = false + have bit := Nat.testBit_mod_two_pow v.val 12 10 + rw [show (2 : Nat) ^ 12 = 4096 from rfl, al] at bit + simpa using bit.symm + +private theorem alignTaggedBit (v : U64) (al : (v &&& ~~~3#u64).val % 4096 = 0) : + v.bv.getLsbD 10 = false := by + have bit := alignedClearBit (v &&& ~~~3#u64) al + simpa only [UScalar.bv_and, BitVec.getLsbD_and, + show (~~~3#u64).bv.getLsbD 10 = true by decide, Bool.and_true] using bit + +/-- Stage tags and allocator alignment put every active ASID entry outside +the bit affected by the access-flag mask. -/ +theorem S1aAccessWrite.pool (edit : S1aAccessWrite st OS Pt Hr s q) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (p : U64) (live : p ∈ PoolSet st Pp s) (o : U64) (bound : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) := by + have loc : PtW Pt (wa p o) := ⟨p, h.place.pools live, o, bound, al, rfl⟩ + by_cases empty : L.mem s (wa p o) = 0#u64 + · exact (edit.zero loc empty).trans empty.symm + have bit : (L.mem s (wa p o)).bv.getLsbD 10 = false := by + rcases h.core.stage2.tag p live o bound al empty with ⟨native, _⟩ | ⟨_, high⟩ | ⟨_, stage2, _⟩ + · have belongs := ((h.core.stage1.pool p live o bound al empty).1 native).1 + exact alignedClearBit _ (h.footprint _ (h.place.tables belongs)).1 + · exact alignTaggedBit _ (h.footprint _ (h.place.tables (h.place.high.sub high))).1 + · apply alignTaggedBit + have divides := h.place.stage2.al _ stage2 + rcases h.place.stage2.sz _ stage2 with size | size <;> rw [size] at divides <;> omega + exact (edit.memory _ loc).elim id (fun eq => eq.trans (clearAF_zeroBit _ bit)) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AccessPaths.lean b/proofs/Fl4ProofsA64/P1/S1aR2AccessPaths.lean new file mode 100644 index 000000000..4a7737e6a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AccessPaths.lean @@ -0,0 +1,145 @@ +/- +P1 (aarch64): active paths and raw table typing after access-flag clearing. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AccessBits +import Fl4ProofsA64.P1.S1aR2Transport + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {s q : S} {n : U64} + +private theorem S1aAccessWrite.stage1Back (edit : S1aAccessWrite st OS Pt Hr s q) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {t : U64} (path : VsReach st (PoolSet st Pp q) ∅ Lv q t) : + VsReach st (PoolSet st Pp s) ∅ Lv s t := by + induction path with + | hr empty => exact (Set.notMem_empty _ empty).elim + | @root0 p o live width al nz tag => + have pool := edit.table.toDel.poolSet live + rw [edit.pool h p pool o width al] at nz tag ⊢ + exact .root0 pool width al nz tag + | @root2 p o live width al tag => + have pool := edit.table.toDel.poolSet live + rw [edit.pool h p pool o width al] at tag ⊢ + exact .root2 pool width al tag + | @step p o _ depth width al tag ih => + have member := (h.core.stage1.sub.reach (hr_rt (by simp)) ih).1 + have loc : PtW Pt (wa p o) := ⟨p, h.place.tables member, o, width, al, rfl⟩ + rw [edit.mask loc 3#u64 (by decide)] at tag + rw [edit.mask loc vspace.ADDR_MASK s1aAccessMaskStage1] + exact .step ih depth width al tag + +private theorem S1aAccessWrite.stage2Back (edit : S1aAccessWrite st OS Pt Hr s q) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {t : U64} (path : S2Reach st (PoolSet st Pp q) Re bits q t) : + S2Reach st (PoolSet st Pp s) Re bits s t := by + induction path with + | @root p o live width al tag => + have pool := edit.table.toDel.poolSet live + rw [edit.pool h p pool o width al] at tag ⊢ + exact .root pool width al tag + | @step p o _ depth width al tag ih => + have member := (h.core.stage2.sub.reach ih).1 + have loc : PtW Pt (wa p o) := ptw_mono h.place.granules + (ptwb_gran h.place.stage2.sz ⟨p, member, o, width, al, rfl⟩) + rw [edit.mask loc 3#u64 (by decide)] at tag + rw [edit.mask loc ept.ADDR_MASK s1aAccessMaskStage2] + exact .step ih depth width al tag + +private theorem tab_of_asW (table : TabKeep st s q) {b : U64} (loc : AsW (L.ksb s) b) : + L.mem q b = L.mem s b := by + obtain ⟨o, lo, hi, al, rfl⟩ := loc + obtain ⟨i, offset⟩ := atOff_of_off lo hi al + simpa only [table.1, offset] using table.2 i + +theorem S1aAccessWrite.raw (edit : S1aAccessWrite st OS Pt Hr s q) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) : + VsLk st H OS Pp Tb Te Kt Lv Re bits q ∧ + VsTyR st (L.ksb q) (PoolSet st Pp q) ∅ Tb Lv q ∧ S2TyR st n (PoolSet st Pp q) Hr Te Re bits q := by + have unmapped := h.eptRoots.unmZ h.core heap h.pageTables + have zero x (hx : x ∈ OS) p size (cap : UnmCap (capA st s x) p size) o (bound : o.val < size) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) := by + obtain ⟨loc, _, wasZero⟩ := unmapped.words (kb := L.ksb s) hx cap.toSlot bound al + rcases loc with word | table + · exact (edit.zero word wasZero).trans wasZero.symm + · exact tab_of_asW edit.table table + refine ⟨h.core.lookup.keepImageOfReach (R2CapImage.keep edit.caps) (fun _ => edit.stage1Back h) + (fun _ => edit.stage2Back h) zero, ?_, ?_⟩ + · refine ⟨?_, ?_, ?_⟩ + · intro o lo hi al nz + rw [edit.table.poolSet_eq, edit.table.1] at * + have off : AsW (L.ksb s) (wa (L.ksb s) o) := ⟨o, lo, hi, al, rfl⟩ + rw [tab_of_asW edit.table off] at nz ⊢ + exact h.core.stage1.tbl o lo hi al nz + · intro p live o width al nz + have pool := edit.table.toDel.poolSet live + rw [edit.pool h p pool o width al] at nz ⊢ + exact h.core.stage1.pool p pool o width al nz + · intro p hp reach depth o width al tag + have loc : PtW Pt (wa p o) := ⟨p, h.place.tables hp, o, width, al, rfl⟩ + rw [edit.mask loc 3#u64 (by decide)] at tag + rw [edit.mask loc vspace.ADDR_MASK s1aAccessMaskStage1] + exact h.core.stage1.desc p hp (edit.stage1Back h reach) depth o width al tag + · refine ⟨?_, ?_, ?_⟩ + · intro p live o width al nz + have pool := edit.table.toDel.poolSet live + rw [edit.pool h p pool o width al] at nz ⊢ + exact h.core.stage2.tag p pool o width al nz + · intro r live + rw [edit.headers r live] + exact h.core.stage2.hi r live + · intro p hp reach depth o width al tag + have loc : PtW Pt (wa p o) := ptw_mono h.place.granules (ptwb_gran h.place.stage2.sz ⟨p, hp, o, width, al, rfl⟩) + rw [edit.mask loc 3#u64 (by decide)] at tag + rw [edit.mask loc ept.ADDR_MASK s1aAccessMaskStage2] + exact h.core.stage2.desc p hp (edit.stage2Back h reach) depth o width al tag + +private theorem S1aAccessWrite.pathBack (edit : S1aAccessWrite st OS Pt Hr s q) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {tag asid t : U64} {sh base : Nat} (path : S1aPath st Pp n q tag asid sh base t) : + S1aPath st Pp n s tag asid sh base t := by + have active {a raw : U64} (entry : ActiveAsidRoot st Pp q a raw) : ActiveAsidRoot st Pp s a raw := + entry.back edit.table.toDel (fun p hp o ho al => Or.inl (edit.pool h p hp o ho al)) + induction path with + | native entry kind => exact .native (active entry) kind + | @high a raw entry kind valid => + have old := active entry + obtain ⟨x, hx, cap⟩ := h.core.root.backed a raw old + rw [kind] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + have live : raw &&& ~~~3#u64 ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, a, cap⟩ + rw [edit.headers _ live] at valid ⊢ + exact .high old kind valid + | stage2 entry kind => exact .stage2 (active entry) kind + | child _ depth width al range table ih => + have loc := h.pathWord ih width al + rw [edit.mask loc 3#u64 (by decide)] at table + rw [edit.mask loc vspace.ADDR_MASK s1aAccessMaskStage1] + exact .child ih depth width al range table + +theorem S1aAccessWrite.backing (edit : S1aAccessWrite st OS Pt Hr s q) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : S1aPathBacking st H OS Pp Tb Te Lv Re bits n q where + tables k a sh b p path := h.paths.tables k a sh b p (edit.pathBack h path) + children k a sh b p path lo := by + obtain ⟨x, hx, va, cap, ref⟩ := h.paths.children k a sh b p (edit.pathBack h path) lo + exact ⟨x, hx, va, (edit.caps x hx).trans cap, ref⟩ + leaves k a sh b p path o width al range leaf := by + have prior := edit.pathBack h path + obtain ⟨tag, target⟩ := edit.leaf (h.pathWord prior width al) sh + dsimp only + rw [target] + obtain ⟨x, hx, sz, rights, dev, va, size, cap, ref, allocation⟩ := + h.paths.leaves k a sh b p prior o width al range (tag.1 leaf) + exact ⟨x, hx, sz, rights, dev, va, size, (edit.caps x hx).trans cap, ref, allocation⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AccessPost.lean b/proofs/Fl4ProofsA64/P1/S1aR2AccessPost.lean new file mode 100644 index 000000000..8228512f7 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AccessPost.lean @@ -0,0 +1,166 @@ +/- +P1 (aarch64): full R2 through TestAndClearAccessed. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AccessPaths +import Fl4ProofsA64.P1.S1aR2UnmapRoute + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {s q : S} {n : U64} + +private theorem S1aAccessWrite.rootSlots (edit : S1aAccessWrite st OS Pt Hr s q) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : S1aRootSlots st OS Kt n q := by + constructor + · intro x hx p m a c o bound al + have cap := (edit.caps x hx).symm.trans c + exact edit.zero ⟨p, (h.nativeRoots x hx p m a cap).2, o, bound.2, al, rfl⟩ + (h.rootSlots.native x hx p m a cap o bound al) + · intro x hx p m a va c o bound al + have cap := (edit.caps x hx).symm.trans c + have owned := (h.eptRoots x hx p 0#u64 m a va cap).2 + have loc := ptw_mono owned (ptwb_gran (fun _ _ => Or.inr rfl) + (show PtWb {p} (fun _ => 13) (wa p o) from ⟨p, Set.mem_singleton p, o, bound.2, al, rfl⟩)) + exact edit.zero loc (h.rootSlots.stage2 x hx p m a va cap o bound al) + · intro x hx p m a c o bound al tag + have cap := (edit.caps x hx).symm.trans c + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, m, a, cap⟩ + have loc : PtW Pt (wa p o) := ⟨p, h.place.tables (h.place.high.sub live), o, by omega, al, rfl⟩ + rw [edit.mask loc 3#u64 (by decide)] at tag + rw [edit.mask loc vspace.ADDR_MASK s1aAccessMaskStage1] + exact h.rootSlots.highCopies x hx p m a cap o bound al tag + · intro x hx p m a c o bound al + have cap := (edit.caps x hx).symm.trans c + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, m, a, cap⟩ + have placed := h.highFootprint ⟨p, live, Or.inr ⟨rfl, rfl⟩⟩ + exact edit.zero ⟨_, placed, o, bound.1, al, rfl⟩ (h.rootSlots.highPrivate x hx p m a cap o bound al) + +private theorem S1aAccessWrite.capRefs (edit : S1aAccessWrite st OS Pt Hr s q) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : S1aTableCaps st OS q := by + constructor + · intro x hx y hy k cx cy + rw [edit.caps x hx] at cx + rw [edit.caps y hy] at cy + rw [edit.caps x hx, edit.caps y hy] + exact h.capRefs.references x hx y hy k cx cy + · intro x hx y hy k cx cy empty + rw [edit.caps x hx] at cx empty + rw [edit.caps y hy] at cy + exact h.capRefs.unique x hx y hy k cx cy empty + · intro x hx p a c o bound al + have cap := (edit.caps x hx).symm.trans c + exact edit.zero ⟨p, (h.nativeRoots x hx p false a cap).2, o, bound, al, rfl⟩ + (h.capRefs.nativeEmpty x hx p a cap o bound al) + · intro x hx p a c o bound al + have cap := (edit.caps x hx).symm.trans c + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, false, a, cap⟩ + have placed := h.highFootprint ⟨p, live, Or.inr ⟨rfl, rfl⟩⟩ + exact edit.zero ⟨_, placed, o, bound, al, rfl⟩ (h.capRefs.highEmpty x hx p a cap o bound al) + +set_option maxHeartbeats 3000000 in +/-- An AF-only edit preserves the exact R2 record with all witnesses fixed. -/ +theorem S1aR2.ofAccessWrite + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (edit : S1aAccessWrite st OS Pt Hr s q) : + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := by + obtain ⟨lookup, ty1, ty2⟩ := edit.raw h heap + have root := h.core.root.keepImage edit.table.toDel (R2CapImage.keep edit.caps) + (fun p hp o width al => Or.inl (edit.pool h p hp o width al)) + have highSet : Hr = HvRt st OS q := by + rw [h.highRoots] + ext p + constructor <;> rintro ⟨x, hx, m, a, cap⟩ + · exact ⟨x, hx, m, a, (edit.caps x hx).trans cap⟩ + · exact ⟨x, hx, m, a, (edit.caps x hx).symm.trans cap⟩ + have closed t (ht : t ∈ Kt) (depth : Lv t < 3) (o : U64) (bound : o.val < 4096) (al : o.val % 8 = 0) + (tag : L.mem q (wa t o) &&& 3#u64 = 3#u64) : + wa (L.mem q (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + have loc : PtW Pt (wa t o) := ⟨t, h.place.tables (h.kernelTables.1 ht), o, bound, al, rfl⟩ + rw [edit.mask loc 3#u64 (by decide)] at tag + rw [edit.mask loc vspace.ADDR_MASK s1aAccessMaskStage1] + exact h.kernelClosed t ht depth o bound al tag + have routes : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := + ⟨lookup, root, h.core.heap, edit.backing h, edit.capRefs h, edit.rootSlots h, highSet, + (fun p hp => by rw [edit.headers p hp]; exact h.highLink p hp), + (fun x hx p m a c => h.highObjects x hx p m a ((edit.caps x hx).symm.trans c)), + (fun x hx p l m a v c => h.eptRoots x hx p l m a v ((edit.caps x hx).symm.trans c)), + (fun x hx p m a v c => h.pageObjects x hx p m a v ((edit.caps x hx).symm.trans c)), closed⟩ + have postKinds := kinds.keep fun x hx => by rw [edit.caps x hx]; exact ⟨Iff.rfl, fun _ => ⟨rfl, rfl⟩⟩ + exact { + core := ⟨lookup, routes.recoverWalk heap postKinds, root, ty1, ty2, h.core.heap⟩ + place := by rw [edit.table.1, edit.table.poolSet_eq]; exact h.place + poolCaps := h.poolCaps.keep edit.table (edit.pool h) (fun x hx _ _ => by rw [edit.caps x hx]) + capRefs := routes.capRefs + paths := routes.paths + pageTables := fun x hx p m a v c => h.pageTables x hx p m a v ((edit.caps x hx).symm.trans c) + footprint := h.footprint + pageObjects := routes.pageObjects + nativeRoots := fun x hx p m a c => h.nativeRoots x hx p m a ((edit.caps x hx).symm.trans c) + eptRoots := routes.eptRoots + highObjects := routes.highObjects + highHeaders := fun x hx p m a c => by + have live : p ∈ Hr := by rw [highSet]; exact ⟨x, hx, m, a, c⟩ + rw [edit.headers p live] + exact h.highHeaders x hx p m a ((edit.caps x hx).symm.trans c) + highLink := routes.highLink + highRoots := highSet + highFootprint := h.highFootprint + kernelTables := h.kernelTables + kernelClosed := closed + rootSlots := routes.rootSlots } + +/-- The syscall dispatch of TestAndClearAccessed is its decoder. -/ +theorem syscall.decode_invocation.accessRoute {A : Type _} {ar : machine.Arch A} {Q : S → Prop} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} (f : vspace.FrameCap) {a : A} {len : U64} + {blk call don fp : Bool} {buf : U64} + (top : vspace.decode_test_and_clear_accessed st ar s a f call ⦃ r => Q r.2.1 ⦄) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTestAndClearAccessed len slot + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) blk call don fp buf extra + ⦃ _ q _ => Q q ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + unfold vspace.decode_frame + simp only [vspace.as_frame, bind_ok, cur_thread_ok] + have neMap : fl4_abi.label.ARMPageTestAndClearAccessed ≠ fl4_abi.label.ARMPageMap := + lbl_ne_of_val (by simp [fl4_abi.label.ARMPageTestAndClearAccessed, fl4_abi.label.ARMPageMap]) + have neUnmap : fl4_abi.label.ARMPageTestAndClearAccessed ≠ fl4_abi.label.ARMPageUnmap := + lbl_ne_of_val (by simp [fl4_abi.label.ARMPageTestAndClearAccessed, fl4_abi.label.ARMPageUnmap]) + have neAddr : fl4_abi.label.ARMPageTestAndClearAccessed ≠ fl4_abi.label.ARMPageGetAddress := + lbl_ne_of_val (by simp [fl4_abi.label.ARMPageTestAndClearAccessed, fl4_abi.label.ARMPageGetAddress]) + try dsimp only + simp only [if_neg neMap, if_neg neUnmap, if_neg neAddr, ite_true, Bool.false_eq_true, ite_false, bind_ok, + vspace.is_cache_label.tca] + exact WP.spec_mono top fun _ h => h + +/-- The accessed-bit syscall preserves R2 in its successful and rejected paths. -/ +theorem syscall.decode_invocation.accessExactR2 + {A : Type _} {ar : machine.Arch A} {Cs Vc Ub U Ac Rp Nt : Set U64} {slot : U64} + {K : capability.Cap → Prop} {Ty : S → Prop} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hA : P0.ArchTotal ar) (f : vspace.FrameCap) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) extra) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTestAndClearAccessed len slot + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) blk call don fp buf extra ⦃ _ q _ => + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q ⦄ := by + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + refine syscall.decode_invocation.accessRoute (Q := S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n) f ?_ + exact WP.spec_mono (vspace.decode_test_and_clear_accessed.exactWrite hA h I d P B Y ptKs a f call) + fun _ effect => h.ofAccessWrite P.heap kinds effect + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AccessWrite.lean b/proofs/Fl4ProofsA64/P1/S1aR2AccessWrite.lean new file mode 100644 index 000000000..5735dbff6 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AccessWrite.lean @@ -0,0 +1,128 @@ +/- +P1 (aarch64): the exact memory and slot effects of TestAndClearAccessed. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aHiTca +import Fl4ProofsA64.P1.S1aR2Contract + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts + +local notation "wa" => core.num.U64.wrapping_add +local notation "clearAF" => (fun w : U64 => w &&& ~~~1024#u64) + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt Cs Vc Ub U Ac Rp Nt : Set U64} + {Lv Re bits : U64 → Nat} {s q : S} {n slot : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {cap : capability.Cap} + +/-- The access-flag operation keeps cap slots, ASID table and HighVSpace +headers. Each other VSpace word is kept or has only the access bit cleared. -/ +structure S1aAccessWrite (st : machine.Store S) [L : LawfulStore st] + (OS Pt Hr : Set U64) (s q : S) : Prop where + table : TabKeep st s q + headers : HrW st Hr s q + caps : ∀ x ∈ OS, capA st q x = capA st s x + memory : ∀ b, PtW Pt b → L.mem q b = L.mem s b ∨ L.mem q b = clearAF (L.mem s b) + +private theorem S1aAccessWrite.refl : S1aAccessWrite st OS Pt Hr s s := + ⟨⟨rfl, fun _ => rfl⟩, fun _ _ => rfl, fun _ _ => rfl, fun _ _ => Or.inl rfl⟩ + +private theorem vspace.reply1.afterAccessWrite + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (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 Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + {addr : U64} (loc : PtW (TbO Tb Hr) addr) (call : Bool) (rv : U64) : + vspace.reply1 st (L.wr s addr (clearAF (L.mem s addr))) (L.curW s) call rv + ⦃ out => S1aAccessWrite st OS Pt Hr s out ⦄ := by + have foot := ptw_mono (tbo_sub.trans h.place.tables) loc + have al := I.del.vr.al addr (Or.inl foot) + let mid := L.wr s addr (clearAF (L.mem s addr)) + have one : WritesIn st s mid (· = addr) := writesIn_wr al + have writes : WritesIn st s mid (PtW Pt) := one.mono (fun _ eq => eq.symm ▸ foot) + have tbl := TabKeep.ofW I.del.vr writes ptKs + obtain ⟨⟨sys, _⟩, kept⟩ := PtW.sysK P.heap P.os I.del.vr B Y D.bxi.blk writes + have capWords b (hb : PtW Pt b) : W7.CapW H.tcbs H.omega H.frame b := + Or.inr ⟨I.del.vr.om b (Or.inl hb), I.del.vr.sg b (Or.inl hb)⟩ + have queues := (blk_of_capw D.bxi.blk writes capWords).1 + have cur : L.curW s ∈ H.tcbs := D.bxi.1.choose_spec.choose_spec.curT + have runnable : ¬ BlockedR (L.mem mid (stA (L.curW s))) := by + rw [(capw_cur D.bxi.blk writes capWords (L.curW s) cur).2.2] + exact nbr_runnable D.run + have vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb mid) Pt := by + rw [tbl.1]; exact I.del.vr + rw [vspace.reply1_eq] + refine WP.spec_mono (vcpu.reply1.dfKn (Ko := ∅) queues cur runnable call rv) fun out ⟨reply, _⟩ => ?_ + obtain ⟨caps, tab⟩ := reply.osTab P.heap P.os queues.bxi sys vr P.core0 + have final b (hb : PtW Pt b) : L.mem out b = L.mem mid b := + reply.w.mem_eq (vr.al b (Or.inl hb)) (fun hw => DfW.notPtW queues.1.choose_spec.choose_spec vr hw hb) + refine ⟨tbl.trans tab, ?_, fun x hx => (caps.capA hx).trans (kept.capA hx), ?_⟩ + · intro root hr + have header : PtW Pt (wa root 4088#u64) := + ⟨root, h.place.tables (h.place.high.sub hr), 4088#u64, by decide, by decide, rfl⟩ + exact (final _ header).trans (one.mem_eq (I.del.vr.al _ (Or.inl header)) + (fun eq => h.place.high.tbo loc root hr eq.symm)) + · intro word hb + by_cases eq : word = addr + · subst word + exact Or.inr ((final _ hb).trans (L.mem_wr_same al)) + · exact Or.inl ((final _ hb).trans (one.mem_eq (I.del.vr.al _ (Or.inl hb)) eq)) + +set_option hygiene false in +local macro "accessError" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 S1aAccessWrite.refl + | (simp only [bind_ok, fl4_core_a64.error.illegal, fl4_core_a64.error.invalid_cap, fl4_core_a64.error.invalid_arg] + exact (WP.spec_ok _).2 S1aAccessWrite.refl)) + +set_option maxHeartbeats 3800000 in +/-- The concrete accessed-bit decoder frames the cap and root slots and +changes only the access flag of the leaf it reaches. -/ +theorem vspace.decode_test_and_clear_accessed.exactWrite (hA : P0.ArchTotal ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (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 Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) (a : A) (f : vspace.FrameCap) (call : Bool) : + vspace.decode_test_and_clear_accessed st ar s a f call ⦃ r => S1aAccessWrite st OS Pt Hr s r.2.1 ⦄ := by + unfold vspace.decode_test_and_clear_accessed + refine spec_ite (fun _ => by accessError) (fun _ => ?_) + refine WP.spec_bind (Pₘ := fun _ => True) (by cases f.size <;> exact (WP.spec_ok _).2 trivial) ?_ + rintro ⟨size, blocks⟩ _ + simp only [uncurry_apply_pair] + refine spec_ite (fun _ => by accessError) (fun _ => ?_) + refine spec_ite (fun _ => ?_) (fun _ => by accessError) + refine spec_ite (fun _ => by accessError) (fun _ => ?_) + refine WP.spec_bind (hA.hw_access_flag a) fun supported _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => by accessError) + refine WP.spec_bind (vspace.frame_root.ty h.core.stage1.sub rfl f.asid) fun root result => ?_ + rcases root with ⟨root, _⟩ | fault + swap + · accessError + obtain ⟨reachable, level⟩ := result _ rfl + try dsimp only + refine WP.spec_bind (vspace.mapped_entry.leafSlot h.core.stage1.sub reachable level { f with size := size }) fun selected loc => ?_ + rcases selected with _ | lu + · accessError + obtain ⟨p, hp, off, bound, aligned, address, belowRoot⟩ := loc lu rfl + have leaf : PtW (TbO Tb Hr) lu.slot := + ⟨p, ⟨hp.1, fun r => (Nat.ne_of_gt belowRoot) (h.place.high.lv p r)⟩, off, bound, aligned, address⟩ + rw [cur_thread_ok] + dsimp only + simp only [eq_of_spec_fd P0.Consts.vspace.D_AF.spec, lift, bind_ok] + refine WP.spec_bind (LawfulStore.fetch_and_spec s lu.slot _) ?_ + rintro ⟨old, out⟩ wrote + obtain ⟨read, state⟩ := Prod.mk.inj wrote + subst old + subst out + try simp only [uncurry_apply_pair, bind_ok] + have tail (r : U64) := vspace.reply1.afterAccessWrite h I D P B Y ptKs leaf call r + split + · exact WP.spec_bind (tail 1#u64) fun _ kept => (WP.spec_ok _).2 kept + · exact WP.spec_bind (tail 0#u64) fun _ kept => (WP.spec_ok _).2 kept + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AddPool.lean b/proofs/Fl4ProofsA64/P1/S1aR2AddPool.lean new file mode 100644 index 000000000..575fbcbcc --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AddPool.lean @@ -0,0 +1,577 @@ +/- +P1 (aarch64): publishing one empty ASID pool keeps R2. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Restrict + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {O Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s q : S} + +private theorem pageBase (t : U64) : wa t 0#u64 = t := by + apply UScalar.eq_of_val_eq + rw [wa_val] + have : t.val < 2 ^ 64 := by scalar_tac + simp [Nat.mod_eq_of_lt this] + +/-- Exact paths depend on the live ASID entries, the High headers and the walked words. -/ +theorem S1aPath.congrRoots {Pq : Set U64} {tag asid t : U64} {sh base : Nat} + (roots : ∀ a raw, ActiveAsidRoot st Pq q a raw ↔ ActiveAsidRoot st Pp s a raw) + (header : ∀ a raw, ActiveAsidRoot st Pp s a raw → raw &&& 3#u64 = 2#u64 → + L.mem q (wa (raw &&& ~~~3#u64) 4088#u64) = L.mem s (wa (raw &&& ~~~3#u64) 4088#u64)) + (words : ∀ tag a sh base t, S1aPath st Pp n s tag a sh base t → + ∀ o : U64, o.val < s1aTableWidth tag n sh → o.val % 8 = 0 → L.mem q (wa t o) = L.mem s (wa t o)) : + S1aPath st Pq n q tag asid sh base t ↔ S1aPath st Pp n s tag asid sh base t := by + constructor + · intro path + induction path with + | native entry kind => exact .native ((roots _ _).mp entry) kind + | high entry kind valid => + have before := (roots _ _).mp entry + have same := header _ _ before kind + rw [same] at valid ⊢ + exact .high before kind valid + | stage2 entry kind => exact .stage2 ((roots _ _).mp entry) kind + | child _ depth width al range valid before => + have same := words _ _ _ _ _ before _ width al + rw [same] at valid ⊢ + exact .child before depth width al range valid + · intro path + induction path with + | native entry kind => exact .native ((roots _ _).mpr entry) kind + | high entry kind valid => + have same := header _ _ entry kind + rw [← same] at valid ⊢ + exact .high ((roots _ _).mpr entry) kind valid + | stage2 entry kind => exact .stage2 ((roots _ _).mpr entry) kind + | child old depth width al range valid after => + have same := words _ _ _ _ _ old _ width al + rw [← same] at valid ⊢ + exact .child after depth width al range valid + +/-- An all-zero pool page contributes no Stage-1 reachability. -/ +theorem VsReach.zeroPool {P : Set U64} {p t : U64} + (zero : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s (wa p o) = 0#u64) : + VsReach st (insert p P) ∅ Lv s t ↔ VsReach st P ∅ Lv s t := by + refine ⟨fun reach => ?_, fun reach => reach.poolMono (Set.subset_insert _ _)⟩ + induction reach with + | hr bad => exact (Set.notMem_empty _ bad).elim + | root0 member bound al nz tag => + rcases member with rfl | member + · exact (nz (zero _ bound al)).elim + · exact .root0 member bound al nz tag + | root2 member bound al tag => + rcases member with rfl | member + · rw [zero _ bound al] at tag + exact ((by decide : (0#u64 &&& 3#u64) ≠ 2#u64) tag).elim + · exact .root2 member bound al tag + | step _ level bound al tag ih => exact .step ih level bound al tag + +/-- An all-zero pool page contributes no Stage-2 reachability. -/ +theorem S2Reach.zeroPool {P : Set U64} {p t : U64} + (zero : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s (wa p o) = 0#u64) : + S2Reach st (insert p P) Re bits s t ↔ S2Reach st P Re bits s t := by + refine ⟨fun reach => ?_, fun reach => reach.poolMono (Set.subset_insert _ _)⟩ + induction reach with + | root member bound al tag => + rcases member with rfl | member + · rw [zero _ bound al] at tag + exact ((by decide : (0#u64 &&& 3#u64) ≠ 1#u64) tag).elim + · exact .root member bound al tag + | step _ level bound al tag ih => exact .step ih level bound al tag + +/-- The effects of publishing the zeroed page `p` as the pool of a free ASID-table entry. -/ +structure S1aPoolAdded (st : machine.Store S) [L : LawfulStore st] (H : Heap) (O Pt : Set U64) (s q : S) + (x v p sb fi base i : U64) : Prop where + before : HeapOK H + after : HeapOK (PoolH H p sb.val) + page : sb.val = 12 + off : ∀ t k, H t = some k → t.val + 2 ^ k.bits ≤ p.val ∨ p.val + 4096 ≤ t.val + nonzero : p ≠ 0#u64 + ksb : L.ksb q = L.ksb s + index : i.val < 128 + low : base.val = i.val * 512 + free : L.mem s (wa (L.ksb s) (AtOff i)) = 0#u64 + written : L.mem q (wa (L.ksb s) (AtOff i)) = p + table : ∀ j, AtOff j ≠ AtOff i → L.mem q (wa (L.ksb s) (AtOff j)) = L.mem s (wa (L.ksb s) (AtOff j)) + words : ∀ b, PtW Pt b → L.mem q b = L.mem s b + zero : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa p o) = 0#u64 + source : capA st s x = .Untyped p sb fi false + sourceAfter : capA st q x = .Untyped p sb 4096#u64 false + empty : capA st s v = .Null + published : capA st q v = .AsidPool p base + target : v ∈ O + other : ∀ y ∈ O, y ≠ x → y ≠ v → capA st q y = capA st s y + +namespace S1aPoolAdded + +variable {x v p sb fi base i : U64} (E : S1aPoolAdded st H O Pt s q x v p sb fi base i) +include E + +theorem fresh : H p = none := by + cases found : H p with + | none => rfl + | some k => + have := E.off p k found + have := Nat.two_pow_pos k.bits + omega + +theorem grow {t : U64} {k : HKind} (obj : H t = some k) : PoolH H p sb.val t = some k := by + refine Heap.add_eq_some.2 (Or.inr ⟨?_, obj⟩) + rintro rfl + rw [E.fresh] at obj + cases obj + +theorem pool : PoolH H p sb.val p = some (.other 12) := by + rw [← E.page] + exact Heap.add_eq_some.2 (Or.inl ⟨rfl, rfl⟩) + +/-- Capabilities other than Null, Untyped and AsidPool are unchanged. -/ +theorem caps {y : U64} (hy : y ∈ O) {c : capability.Cap} (nonnull : c ≠ .Null) + (ut : ∀ a b d e, c ≠ .Untyped a b d e) (pool : ∀ a b, c ≠ .AsidPool a b) : + capA st q y = c ↔ capA st s y = c := by + by_cases source : y = x + · subst y + rw [E.source, E.sourceAfter] + exact ⟨fun h => (ut _ _ _ _ h.symm).elim, fun h => (ut _ _ _ _ h.symm).elim⟩ + by_cases target : y = v + · subst y + rw [E.empty, E.published] + exact ⟨fun h => (pool _ _ h.symm).elim, fun h => (nonnull h.symm).elim⟩ + rw [E.other y hy source target] + +theorem offset {j : U64} {t : U64} (word : L.mem s (wa (L.ksb s) (AtOff j)) = t) (nz : t ≠ 0#u64) : + AtOff j ≠ AtOff i := by + intro same + rw [same, E.free] at word + exact nz word.symm + +end S1aPoolAdded + +set_option maxHeartbeats 4000000 in +/-- R2 after the pool publication, over the grown heap, with the new page in both ghost sets. -/ +theorem S1aR2.addPool {x v p sb fi base i : U64} (h : S1aR2 st H O Pt Pp Tb Hr Te Kt Lv Re bits n s) + (E : S1aPoolAdded st H O Pt s q x v p sb fi base i) + (kinds : KindA st O q) (frames : FrameOK st (PoolH H p sb.val) O q) : + S1aR2 st (PoolH H p sb.val) O (insert p Pt) (insert p Pp) Tb (HvRt st O q) Te Kt Lv Re bits n q := by + -- the live pools + have noPage {t : U64} (active : t ∈ PoolSet st Pp s) : t ≠ p := by + rintro rfl + obtain ⟨_, j, lo, hi, al, word, nz⟩ := active + obtain ⟨index, eq⟩ := atOff_of_off lo hi al + let masked := index &&& 127#u64 + have small : masked.val < 128 := by + change (index &&& 127#u64).val < 128 + rw [and127_val] + omega + rw [← eq, ← AtOff.mask] at word + obtain ⟨_, _, obj, _⟩ := h.poolCaps.present masked small t word nz + rw [E.fresh] at obj + cases obj + have poolSet : PoolSet st (insert p Pp) q = insert p (PoolSet st Pp s) := by + ext t + constructor + · rintro ⟨member, o, lo, hi, al, word, nz⟩ + obtain ⟨j, eq⟩ := atOff_of_off lo hi al + rw [E.ksb, ← eq] at word + by_cases same : AtOff j = AtOff i + · rw [same, E.written] at word + exact Or.inl word.symm + rw [E.table j same] at word + have old : t ∈ Pp := by + rcases member with rfl | member + · have bounds := AtOff.v j + let masked := j &&& 127#u64 + have small : masked.val < 128 := by + change (j &&& 127#u64).val < 128 + rw [and127_val] + omega + rw [← AtOff.mask] at word + obtain ⟨_, _, obj, _⟩ := h.poolCaps.present masked small t word nz + rw [E.fresh] at obj + cases obj + · exact member + exact Or.inr ⟨old, AtOff j, (AtOff.v j).1, (AtOff.v j).2.1, (AtOff.v j).2.2, word, nz⟩ + · rintro (rfl | ⟨member, o, lo, hi, al, word, nz⟩) + · refine ⟨Set.mem_insert _ _, AtOff i, (AtOff.v i).1, (AtOff.v i).2.1, (AtOff.v i).2.2, ?_, E.nonzero⟩ + rw [E.ksb] + exact E.written + · obtain ⟨j, eq⟩ := atOff_of_off lo hi al + rw [← eq] at word lo hi al + refine ⟨Set.mem_insert_of_mem _ member, AtOff j, lo, hi, al, ?_, nz⟩ + rw [E.ksb, E.table j (E.offset word nz)] + exact word + have keep {b : U64} (placed : PtW Pt b) : L.mem q b = L.mem s b := E.words b placed + have poolWords : ∀ t ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem q (wa t o) = L.mem s (wa t o) := + fun t active o bound al => keep ⟨t, h.place.pools active, o, bound, al, rfl⟩ + have roots (asid raw : U64) : ActiveAsidRoot st (insert p Pp) q asid raw ↔ ActiveAsidRoot st Pp s asid raw := by + constructor + · rintro ⟨j, o, small, bound, al, value, t, active, entry, word, nz⟩ + rw [poolSet] at active + rcases active with rfl | active + · rw [E.zero o bound al] at word + exact (nz word.symm).elim + have different : AtOff j ≠ AtOff i := by + intro same + rw [E.ksb, same, E.written] at entry + exact noPage active entry.symm + rw [E.ksb, E.table j different] at entry + rw [poolWords t active o bound al] at word + exact ⟨j, o, small, bound, al, value, t, active, entry, word, nz⟩ + · rintro ⟨j, o, small, bound, al, value, t, active, entry, word, nz⟩ + have live : t ≠ 0#u64 := by + obtain ⟨_, _, _, _, _, _, live⟩ := active + exact live + refine ⟨j, o, small, bound, al, value, t, poolSet.symm ▸ Set.mem_insert_of_mem _ active, ?_, ?_, nz⟩ + · rw [E.ksb, E.table j (E.offset entry live)] + exact entry + · rw [poolWords t active o bound al] + exact word + -- reachability + have words1 {t : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) (o : U64) (bound : o.val < 4096) + (al : o.val % 8 = 0) : L.mem q (wa t o) = L.mem s (wa t o) := + keep (h.reachWord1 E.before reach bound al).1 + have words2 {t : U64} (reach : S2Reach st (PoolSet st Pp s) Re bits s t) (o : U64) (bound : o.val < 2 ^ bits t) + (al : o.val % 8 = 0) : L.mem q (wa t o) = L.mem s (wa t o) := + keep (h.reachWord2 E.before reach bound al).1 + have reach1 {t : U64} : VsReach st (PoolSet st (insert p Pp) q) ∅ Lv q t ↔ + VsReach st (PoolSet st Pp s) ∅ Lv s t := by + rw [poolSet, VsReach.zeroPool E.zero] + exact VsReach.congrWords poolWords (fun r reach => ⟨rfl, words1 reach⟩) + have reach2 {t : U64} : S2Reach st (PoolSet st (insert p Pp) q) Re bits q t ↔ + S2Reach st (PoolSet st Pp s) Re bits s t := by + rw [poolSet, S2Reach.zeroPool E.zero] + exact S2Reach.congrWords poolWords (fun r reach => words2 reach) + have tableCap {y : U64} (hy : y ∈ O) {c : capability.Cap} (cap : capA st q y = c) (nonnull : c ≠ .Null) + (ut : ∀ a b d e, c ≠ .Untyped a b d e) (pool : ∀ a b, c ≠ .AsidPool a b) : capA st s y = c := + (E.caps hy nonnull ut pool).mp cap + have keepCap {y : U64} (hy : y ∈ O) {c : capability.Cap} (cap : capA st s y = c) (nonnull : c ≠ .Null) + (ut : ∀ a b d e, c ≠ .Untyped a b d e) (pool : ∀ a b, c ≠ .AsidPool a b) : capA st q y = c := + (E.caps hy nonnull ut pool).mpr cap + have mappedShape {c : capability.Cap} {t : U64} (mapped : MapV c t) : + c ≠ .Null ∧ (∀ a b d e, c ≠ .Untyped a b d e) ∧ ∀ a b, c ≠ .AsidPool a b := by + rcases mapped with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, e, _⟩ | ⟨_, _, _, e⟩ <;> rw [e] <;> + exact ⟨(fun h => by cases h), (fun _ _ _ _ h => by cases h), (fun _ _ h => by cases h)⟩ + have namedShape {c : capability.Cap} {t : U64} (named : NamesV c t) : + c ≠ .Null ∧ (∀ a b d e, c ≠ .Untyped a b d e) ∧ ∀ a b, c ≠ .AsidPool a b := by + rcases named with ⟨_, _, _, e⟩ | ⟨_, _, e⟩ | ⟨_, _, e⟩ | ⟨_, _, _, e, _⟩ | ⟨_, _, _, _, e⟩ <;> rw [e] <;> + exact ⟨(fun h => by cases h), (fun _ _ _ _ h => by cases h), (fun _ _ h => by cases h)⟩ + have rootShape {c : capability.Cap} {r a g : U64} (mapped : MappedAsidRoot c r a g) : + c ≠ .Null ∧ (∀ a b d e, c ≠ .Untyped a b d e) ∧ ∀ a b, c ≠ .AsidPool a b := by + rcases mapped with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> rw [e] <;> + exact ⟨(fun h => by cases h), (fun _ _ _ _ h => by cases h), (fun _ _ h => by cases h)⟩ + have keyShape {c : capability.Cap} {k : Nat × U64} (key : s1aTableKey c = some k) : + c ≠ .Null ∧ (∀ a b d e, c ≠ .Untyped a b d e) ∧ ∀ a b, c ≠ .AsidPool a b := by + refine ⟨fun e => ?_, fun _ _ _ _ e => ?_, fun _ _ e => ?_⟩ <;> rw [e] at key <;> cases key + have capKey {y : U64} (hy : y ∈ O) {k : Nat × U64} (key : s1aTableKey (capA st q y) = some k) : + capA st s y = capA st q y := by + obtain ⟨a, b, c⟩ := keyShape key + exact tableCap hy rfl a b c + -- High roots + have highSet : HvRt st O q = HvRt st O s := by + ext R + constructor <;> rintro ⟨y, hy, m, a, cap⟩ + · exact ⟨y, hy, m, a, tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e)⟩ + · exact ⟨y, hy, m, a, keepCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e)⟩ + have oldRoots : HvRt st O s = Hr := h.highRoots.symm + have rootWord {R o : U64} (member : R ∈ Hr) (bound : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa R o) = L.mem s (wa R o) := + keep ⟨R, h.place.tables (h.place.high.sub member), o, bound, al, rfl⟩ + have privateWord {R o : U64} (member : R ∈ Hr) (bound : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa (wa R 4096#u64) o) = L.mem s (wa (wa R 4096#u64) o) := + keep ⟨_, h.highFootprint ⟨R, member, Or.inr ⟨rfl, rfl⟩⟩, o, bound, al, rfl⟩ + have header (R : U64) (member : R ∈ Hr) : L.mem q (wa R 4088#u64) = L.mem s (wa R 4088#u64) := + rootWord member (by decide) (by decide) + have highMember {y R a : U64} {m : Bool} (hy : y ∈ O) (cap : capA st s y = .HighVSpace R m a) : R ∈ Hr := by + rw [h.highRoots] + exact ⟨y, hy, m, a, cap⟩ + have headerRoot (asid raw : U64) (active : ActiveAsidRoot st Pp s asid raw) (tag : raw &&& 3#u64 = 2#u64) : + L.mem q (wa (raw &&& ~~~3#u64) 4088#u64) = L.mem s (wa (raw &&& ~~~3#u64) 4088#u64) := by + obtain ⟨y, hy, backed⟩ := h.core.root.backed asid raw active + rw [tag] at backed + rcases backed with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + exact header _ (highMember hy cap) + have pathWords {tag asid t o : U64} {sh va : Nat} (path : S1aPath st Pp n s tag asid sh va t) + (bound : o.val < s1aTableWidth tag n sh) (al : o.val % 8 = 0) : L.mem q (wa t o) = L.mem s (wa t o) := + keep (h.storageWord E.before path (lt_of_lt_of_le bound (s1aTableWidth.leStorage tag n sh)) al).1 + have paths (tag asid t : U64) (sh va : Nat) : S1aPath st (insert p Pp) n q tag asid sh va t ↔ + S1aPath st Pp n s tag asid sh va t := + S1aPath.congrRoots roots headerRoot (fun _ _ _ _ _ path _ bound al => pathWords path bound al) + have lookup : VsLk st (PoolH H p sb.val) O (insert p Pp) Tb Te Kt Lv Re bits q := by + refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ + · intro t reach member outside + obtain ⟨y, hy, mapped⟩ := h.core.lookup.bk1 t (reach1.mp reach) member outside + obtain ⟨a, b, c⟩ := mappedShape mapped + exact ⟨y, hy, (keepCap hy rfl a b c).symm ▸ mapped⟩ + · intro t reach member + obtain ⟨y, hy, mapped⟩ := h.core.lookup.bk2 t (reach2.mp reach) member + obtain ⟨a, b, c⟩ := mappedShape mapped + exact ⟨y, hy, (keepCap hy rfl a b c).symm ▸ mapped⟩ + · intro t kernel y hy named + obtain ⟨a, b, c⟩ := namedShape named + exact h.core.lookup.kt t kernel y hy ((tableCap hy rfl a b c).symm ▸ named) + · intro y hy z hz t width unm mapped + obtain ⟨a, b, c⟩ := namedShape unm.names + obtain ⟨a', b', c'⟩ := mappedShape mapped + exact h.core.lookup.ex y hy z hz t width ((tableCap hy rfl a b c).symm ▸ unm) + ((tableCap hz rfl a' b' c').symm ▸ mapped) + · intro y hy t width unm o bound al + obtain ⟨a, b, c⟩ := namedShape unm.names + have old : UnmCap (capA st s y) t width := (tableCap hy rfl a b c).symm ▸ unm + have same : L.mem q (wa t o) = L.mem s (wa t o) := by + rcases old with ⟨wide, asid, va, cap⟩ | ⟨wide, asid, va, cap⟩ + · exact keep ⟨t, h.pageTables y hy t false asid va cap, o, wide ▸ bound, al, rfl⟩ + · have granules := (h.eptRoots y hy t 0#u64 false asid va cap).2 + have word : PtWb {t} (fun _ => 13) (wa t o) := + ⟨t, Set.mem_singleton t, o, show o.val < 2 ^ 13 by rw [wide] at bound; exact bound, al, rfl⟩ + exact keep (ptw_mono granules (ptwb_gran (fun _ _ => Or.inr rfl) word)) + rw [same] + exact h.core.lookup.zr y hy t width old o bound al + · intro y hy t width unm + obtain ⟨a, b, c⟩ := namedShape unm.names + obtain ⟨z, exactSize, obj⟩ := h.core.lookup.vh.1 y hy t width ((tableCap hy rfl a b c).symm ▸ unm) + exact ⟨z, exactSize, E.grow obj⟩ + · intro t reach member outside + rcases h.core.lookup.vh.2.1 t (reach1.mp reach) member outside with plain | ⟨R, obj, which, y, hy, a, cap⟩ + · exact Or.inl (E.grow plain) + · exact Or.inr ⟨R, E.grow obj, which, y, hy, a, + keepCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e)⟩ + · intro t reach member + exact E.grow (h.core.lookup.vh.2.2 t (reach2.mp reach) member) + have agreement : RootAgreement st O (insert p Pp) q := by + refine ⟨fun asid raw entry => ?_, fun y hy z hz root a b tag tag' cy cz => ?_⟩ + · obtain ⟨y, hy, backed⟩ := h.core.root.backed asid raw ((roots asid raw).mp entry) + obtain ⟨a, b, c⟩ := rootShape backed + exact ⟨y, hy, (keepCap hy rfl a b c).symm ▸ backed⟩ + · obtain ⟨a1, b1, c1⟩ := rootShape cy + obtain ⟨a2, b2, c2⟩ := rootShape cz + exact h.core.root.agree y hy z hz root a b tag tag' ((tableCap hy rfl a1 b1 c1).symm ▸ cy) + ((tableCap hz rfl a2 b2 c2).symm ▸ cz) + have capRefs : S1aTableCaps st O q := by + refine ⟨fun y hy z hz k ky kz => ?_, fun y hy z hz k ky kz none => ?_, fun y hy t a cap o bound al => ?_, + fun y hy t a cap o bound al => ?_⟩ + · have sy := capKey hy ky + have sz := capKey hz kz + rw [← sy, ← sz] + exact h.capRefs.references y hy z hz k (sy ▸ ky) (sz ▸ kz) + · have sy := capKey hy ky + have sz := capKey hz kz + exact h.capRefs.unique y hy z hz k (sy ▸ ky) (sz ▸ kz) (sy ▸ none) + · have old := tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e) + rw [keep ⟨t, (h.nativeRoots y hy t false a old).2, o, bound, al, rfl⟩] + exact h.capRefs.nativeEmpty y hy t a old o bound al + · have old := tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e) + rw [privateWord (highMember hy old) bound al] + exact h.capRefs.highEmpty y hy t a old o bound al + have exactPaths : S1aPathBacking st (PoolH H p sb.val) O (insert p Pp) Tb Te Lv Re bits n q := by + refine ⟨fun tag asid sh va t path => h.paths.tables tag asid sh va t ((paths _ _ _ _ _).mp path), + fun tag asid sh va t path child => ?_, fun tag asid sh va t path o bound al range valid => ?_⟩ + · obtain ⟨y, hy, address, cap, ref⟩ := h.paths.children tag asid sh va t ((paths _ _ _ _ _).mp path) child + exact ⟨y, hy, address, keepCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) + (fun _ _ e => by cases e), ref⟩ + · have before := (paths _ _ _ _ _).mp path + rw [pathWords before bound al] at valid ⊢ + obtain ⟨y, hy, sz, rights, device, address, size, cap, ref, _⟩ := + h.paths.leaves tag asid sh va t before o bound al range valid + 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 + 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⟩ + · 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⟩ + have highLink : ∀ R ∈ HvRt st O q, + wa (L.mem q (wa R 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE = wa R 4096#u64 := by + intro R member + rw [highSet, oldRoots] at member + rw [header R member] + exact h.highLink R member + have highObj : HvObjects st (PoolH H p sb.val) O q := fun y hy t m a cap => + E.grow (h.highObjects y hy t m a + (tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e))) + have ept : EptPlaced st (PoolH H p sb.val) O (insert p Pt) q := by + intro y hy t l m a va cap + have old := tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e) + obtain ⟨obj, granules⟩ := h.eptRoots y hy t l m a va old + exact ⟨E.grow obj, fun g member => Set.mem_insert_of_mem _ (granules member)⟩ + have pageObj : PtObjects st (PoolH H p sb.val) O q := fun y hy t m a va cap => + E.grow (h.pageObjects y hy t m a va + (tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e))) + have closed : ∀ t ∈ Kt, Lv t < 3 → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + (L.mem q (wa t o) &&& 3#u64) = 3#u64 → + wa (L.mem q (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + intro t member level o bound al edge + rw [keep ⟨t, h.place.tables (h.kernelTables.1 member), o, bound, al, rfl⟩] at edge ⊢ + exact h.kernelClosed t member level o bound al edge + have rootSlots : S1aRootSlots st O Kt n q := by + refine ⟨fun y hy t m a cap o bound al => ?_, fun y hy t m a va cap o bound al => ?_, + fun y hy t m a cap o bound al edge => ?_, fun y hy t m a cap o bound al => ?_⟩ + · have old := tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e) + rw [keep ⟨t, (h.nativeRoots y hy t m a old).2, o, bound.2, al, rfl⟩] + exact h.rootSlots.native y hy t m a old o bound al + · have old := tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e) + have granules := (h.eptRoots y hy t _ m a va old).2 + have word : PtWb {t} (fun _ => 13) (wa t o) := ⟨t, Set.mem_singleton t, o, bound.2, al, rfl⟩ + rw [keep (ptw_mono granules (ptwb_gran (fun _ _ => Or.inr rfl) word))] + exact h.rootSlots.stage2 y hy t m a va old o bound al + · have old := tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e) + rw [rootWord (highMember hy old) (by omega) al] at edge ⊢ + exact h.rootSlots.highCopies y hy t m a old o bound al edge + · have old := tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e) + rw [privateWord (highMember hy old) bound.1 al] + exact h.rootSlots.highPrivate y hy t m a old o bound al + have routes : S1aRouteFacts st (PoolH H p sb.val) O (insert p Pt) (insert p Pp) Tb (HvRt st O q) Te Kt + Lv Re bits n q := + ⟨lookup, agreement, typedHeap, exactPaths, capRefs, rootSlots, rfl, highLink, highObj, ept, pageObj, closed⟩ + have pageAl : p.val % 4096 = 0 := by + have al := E.after.align p _ E.pool + simpa [HKind.bits] using al + have footprint : PtHG (PoolH H p sb.val) (insert p Pt) := by + rintro t (rfl | member) + · exact ⟨pageAl, t, 12, E.pool, le_rfl, by norm_num⟩ + · obtain ⟨al, b, z, obj, low, high⟩ := h.footprint t member + exact ⟨al, b, z, E.grow obj, low, high⟩ + have poolCaps : S1aPoolCaps st (PoolH H p sb.val) O (insert p Pt) (insert p Pp) q := by + have sameIndex {j k : U64} (hj : j.val < 128) (hk : k.val < 128) (same : AtOff j = AtOff k) : j = k := by + have := AtOff.eq_iff.1 same + exact UScalar.eq_of_val_eq (by omega) + have oldWord {j t : U64} (nz : t ≠ 0#u64) (different : AtOff j ≠ AtOff i) + (word : L.mem q (wa (L.ksb q) (AtOff j)) = t) : L.mem s (wa (L.ksb s) (AtOff j)) = t := by + rwa [E.ksb, E.table j different] at word + have newWord {j t : U64} (same : AtOff j = AtOff i) (word : L.mem q (wa (L.ksb q) (AtOff j)) = t) : t = p := by + rw [E.ksb, same, E.written] at word + exact word.symm + have absent {j : U64} (hj : j.val < 128) (word : L.mem s (wa (L.ksb s) (AtOff j)) = p) : False := by + obtain ⟨_, _, obj, _⟩ := h.poolCaps.present j hj p word E.nonzero + rw [E.fresh] at obj + cases obj + refine ⟨fun j hj t word nz => ?_, fun y hy t b cap => ?_, fun j k t hj hk nz wj wk => ?_, fun raw entry => ?_⟩ + · by_cases same : AtOff j = AtOff i + · obtain rfl := newWord same word + obtain rfl := sameIndex hj E.index same + exact ⟨Set.mem_insert _ _, Set.mem_insert _ _, E.pool, v, E.target, base, E.published, E.low⟩ + · obtain ⟨active, member, obj, y, hy, b, cap, low⟩ := h.poolCaps.present j hj t (oldWord nz same word) nz + have source : y ≠ x := fun e => by rw [e, E.source] at cap; cases cap + have target : y ≠ v := fun e => by rw [e, E.empty] at cap; cases cap + exact ⟨Set.mem_insert_of_mem _ active, Set.mem_insert_of_mem _ member, E.grow obj, y, hy, b, + (E.other y hy source target).trans cap, low⟩ + · by_cases target : y = v + · rw [target, E.published] at cap + cases cap + refine ⟨i, E.index, E.low, E.nonzero, ?_⟩ + rw [E.ksb] + exact E.written + have source : y ≠ x := fun e => by rw [e, E.sourceAfter] at cap; cases cap + rw [E.other y hy source target] at cap + obtain ⟨j, hj, low, nz, word⟩ := h.poolCaps.cap y hy t b cap + refine ⟨j, hj, low, nz, ?_⟩ + rw [E.ksb, E.table j (E.offset word nz)] + exact word + · by_cases first : AtOff j = AtOff i + · by_cases second : AtOff k = AtOff i + · exact sameIndex hj hk (first.trans second.symm) + · obtain rfl := newWord first wj + exact (absent hk (oldWord nz second wk)).elim + · by_cases second : AtOff k = AtOff i + · obtain rfl := newWord second wk + exact (absent hj (oldWord nz first wj)).elim + · exact h.poolCaps.index j k t hj hk nz (oldWord nz first wj) (oldWord nz second wk) + · exact h.poolCaps.noZero raw ((roots _ _).mp entry) + have stage1 : VsTyR st (L.ksb s) (PoolSet st (insert p Pp) q) ∅ Tb Lv q := by + refine ⟨fun o lo hi al nz => ?_, fun t active o bound al nz => ?_, fun t member reach level o bound al edge => ?_⟩ + · refine ⟨?_, o, lo, hi, al, by rw [E.ksb], nz⟩ + obtain ⟨j, eq⟩ := atOff_of_off lo hi al + rw [← eq] at nz ⊢ + by_cases same : AtOff j = AtOff i + · rw [same, E.written] + exact Set.mem_insert _ _ + · rw [E.table j same] at nz ⊢ + have b := AtOff.v j + exact Set.mem_insert_of_mem _ (h.core.stage1.tbl _ b.1 b.2.1 b.2.2 nz).1 + · rw [poolSet] at active + rcases active with rfl | active + · exact (nz (E.zero o bound al)).elim + rw [poolWords t active o bound al] at nz ⊢ + exact h.core.stage1.pool t active o bound al nz + · have before := reach1.mp reach + rw [words1 before o bound al] at edge ⊢ + exact h.core.stage1.desc t member before level o bound al edge + have stage2 : S2TyR st n (PoolSet st (insert p Pp) q) (HvRt st O q) Te Re bits q := by + rw [highSet, oldRoots] + refine ⟨fun t active o bound al nz => ?_, fun R member => ?_, fun t member reach level o bound al edge => ?_⟩ + · rw [poolSet] at active + rcases active with rfl | active + · exact (nz (E.zero o bound al)).elim + rw [poolWords t active o bound al] at nz ⊢ + exact h.core.stage2.tag t active o bound al nz + · rw [header R member] + exact h.core.stage2.hi R member + · have before := reach2.mp reach + rw [words2 before o bound al] at edge ⊢ + exact h.core.stage2.desc t member before level o bound al edge + have place : S1aR2Place (insert p Pt) (PoolSet st (insert p Pp) q) Tb (HvRt st O q) Te Lv bits (L.ksb q) := by + rw [highSet, oldRoots, E.ksb] + refine ⟨?_, fun t member => Set.mem_insert_of_mem _ (h.place.tables member), + fun g member => Set.mem_insert_of_mem _ (h.place.granules member), ?_, h.place.stage2⟩ + · rw [poolSet] + rintro t (rfl | active) + · exact Set.mem_insert _ _ + · exact Set.mem_insert_of_mem _ (h.place.pools active) + · refine ⟨h.place.high.sub, h.place.high.lv, h.place.high.tb, ?_, h.place.high.asw⟩ + intro t active o bound al R member + rw [poolSet] at active + rcases active with rfl | active + · have obj : H R = some (.other 13) := by + rw [h.highRoots] at member + obtain ⟨y, hy, m, a, cap⟩ := member + exact h.highObjects y hy R m a cap + have different : t ≠ R := by + rintro rfl + rw [E.fresh] at obj + cases obj + exact heap_wa_ne E.after E.pool (E.grow obj) different (by simpa [HKind.bits] using bound) + (by simp [HKind.bits]) + · exact h.place.high.pp t active o bound al R member + exact { + core := ⟨lookup, routes.recoverWalk E.after kinds, agreement, by rw [E.ksb]; exact stage1, stage2, typedHeap⟩ + place := place + poolCaps := poolCaps + capRefs := capRefs + paths := exactPaths + pageTables := fun y hy t m a va cap => Set.mem_insert_of_mem _ (h.pageTables y hy t m a va + (tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e))) + footprint := footprint + pageObjects := pageObj + nativeRoots := fun y hy t m a cap => by + obtain ⟨obj, member⟩ := h.nativeRoots y hy t m a + (tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e)) + exact ⟨E.grow obj, Set.mem_insert_of_mem _ member⟩ + eptRoots := ept + highObjects := highObj + highHeaders := fun y hy t m a cap => by + have old := tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) (fun _ _ e => by cases e) + rw [header t (highMember hy old)] + exact h.highHeaders y hy t m a old + highLink := highLink + highRoots := rfl + highFootprint := fun g member => by + rw [highSet, oldRoots] at member + exact Set.mem_insert_of_mem _ (h.highFootprint member) + kernelTables := ⟨h.kernelTables.1, fun t member => E.grow (h.kernelTables.2 t member)⟩ + kernelClosed := closed + rootSlots := rootSlots } + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Assign.lean b/proofs/Fl4ProofsA64/P1/S1aR2Assign.lean new file mode 100644 index 000000000..c64ecb57d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Assign.lean @@ -0,0 +1,237 @@ +/- +P1 (aarch64, A64-S1A): Exact ASID entries and root-cap agreement through Assign. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Contract + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {OS Pp : Set U64} {s s' : S} + +/-- The Assign scan returns 512 or a nonzero ASID whose pool word is empty. -/ +theorem vspace.decode_loop1.emptyWord (base pool start : U64) (bound : start.val ≤ 512) : + vspace.decode_loop1 st s base pool start ⦃ j => + j.val ≤ 512 ∧ (j.val < 512 → + wa base j ≠ 0#u64 ∧ L.mem s (wa pool (core.num.U64.wrapping_mul j 8#u64)) = 0#u64) ⦄ := by + unfold vspace.decode_loop1 + apply loop.spec_decr_nat (measure := fun j : U64 => 512 - j.val) (inv := fun j => j.val ≤ 512) + · intro j hj + unfold vspace.decode_loop1.body + split + · rename_i below + have hlt : j.val < 512 := by simpa using below + simp only [lift, bind_ok] + split + · step as ⟨next, inc⟩ + have progress : next.val ≤ 512 ∧ 512 - next.val < 512 - j.val := by scalar_tac + first | exact (WP.spec_ok _).2 progress | exact progress + · rename_i nonzero + step as ⟨off, scaled⟩ + have same : off = core.num.U64.wrapping_mul j 8#u64 := + UScalar.eq_of_val_eq (by rw [mul8_val (by omega : j.val ≤ 511)]; exact scaled) + try simp only [lift, bind_ok] + rw [L.read_eq, bind_ok] + split + · step as ⟨next, inc⟩ + have progress : next.val ≤ 512 ∧ 512 - next.val < 512 - j.val := by scalar_tac + first | exact (WP.spec_ok _).2 progress | exact progress + · rename_i zero + exact (WP.spec_ok _).2 ⟨hj, fun _ => ⟨nonzero, UScalar.eq_of_val_eq (by simpa [same] using zero)⟩⟩ + · rename_i notBelow + exact (WP.spec_ok _).2 ⟨hj, fun h => (notBelow (by simpa using h)).elim⟩ + · exact bound + +omit L in +/-- The three root kinds use identical free-entry scans. -/ +theorem vspace.decode_loop2.eq_loop1 (base pool start : U64) : + vspace.decode_loop2 st s base pool start = vspace.decode_loop1 st s base pool start := rfl + +omit L in +theorem vspace.decode_loop3.eq_loop1 (base pool start : U64) : + vspace.decode_loop3 st s base pool start = vspace.decode_loop1 st s base pool start := rfl + + +/-- At an aligned pool base, the ASID written by Assign selects exactly the +pool word the scan checked. -/ +theorem assign_asid_offset {base index entry : U64} (hbase : base.val = index.val * 512) + (hi : index.val < 128) (he : entry.val < 512) : + (wa base entry).val = index.val * 512 + entry.val ∧ + (wa base entry &&& 511#u64) = entry := by + have value : (wa base entry).val = index.val * 512 + entry.val := by + rw [wadd_val (by rw [hbase]; omega), hbase] + refine ⟨value, UScalar.eq_of_val_eq ?_⟩ + rw [UScalar.val_and, value, show (511#u64 : U64).val = 2 ^ 9 - 1 by rfl, + Nat.and_two_pow_sub_one_eq_mod] + omega + +/-- A successful concrete lookup comes from the exact active pool and offset +selected by its ASID. -/ +theorem vspace.find_asid_raw.active {Tb : Set U64} {Lv : U64 → Nat} + (ty : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ Tb Lv s) (asid : U64) : + vspace.find_asid_raw st s asid ⦃ r => + ∀ raw, r = .Ok raw → ActiveAsidRoot st Pp s asid raw ⦄ := by + unfold vspace.find_asid_raw vspace.ASID_BITS vspace.ASID_LOW_BITS + step as ⟨upper, hu⟩ + split + · exact (WP.spec_ok _).2 fun _ h => by cases h + rename_i highZero + have zero : upper.val = 0 := by simpa using highZero + have bound : asid.val < 65536 := by + rw [hu, Nat.shiftRight_eq_div_pow] at zero + change asid.val / 65536 = 0 at zero + omega + step as ⟨i, hi⟩ + rw [vspace.asid_table.eq, bind_ok] + split + · exact (WP.spec_ok _).2 fun _ h => by cases h + rename_i poolNZ + let pool := L.mem s (wa (L.ksb s) (AtOff i)) + have poolActive : pool ∈ PoolSet st Pp s := + ty.tbl (AtOff i) (AtOff.v i).1 (AtOff.v i).2.1 (AtOff.v i).2.2 poolNZ + let off := core.num.U64.wrapping_mul (asid &&& 511#u64) 8#u64 + have indexVal : i.val = asid.val / 512 := by + rw [hi, Nat.shiftRight_eq_div_pow] + have offsetVal : off.val = (asid.val % 512) * 8 := by + rw [mul8_val (and511 asid), UScalar.val_and, show (511#u64 : U64).val = 2 ^ 9 - 1 by rfl, + Nat.and_two_pow_sub_one_eq_mod] + simp only [lift, bind_ok, L.read_eq] + split + · exact (WP.spec_ok _).2 fun _ h => by cases h + rename_i rawNZ + refine (WP.spec_ok _).2 ?_ + intro raw same + cases same + exact ⟨i, off, by rw [indexVal]; omega, by rw [offsetVal]; omega, by rw [offsetVal]; omega, + by rw [indexVal, offsetVal]; omega, pool, poolActive, rfl, rfl, rawNZ⟩ + +/-- The successful lookup has a live cap matching its kind, pointer and ASID. -/ +theorem S1aR2Core.findBacked {H : Heap} {Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n asid raw : U64} + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (lookup : vspace.find_asid_raw st s asid = ok (.Ok raw)) : + ∃ x ∈ OS, MappedAsidRoot (capA st s x) (raw &&& ~~~3#u64) asid (raw &&& 3#u64) := by + have active := vspace.find_asid_raw.active h.stage1 asid + rw [lookup, WP.spec_ok] at active + exact h.root.backed asid raw (active raw rfl) + +/-- A pool word written while the ASID table is fixed can only affect the ASID +formed from the active pool index and that word's offset. -/ +theorem ActiveAsidRoot.replaceWord {pool off index asid raw value : U64} + (idx : PoolIdx st OS s) (named : PoolNamed st OS s) (table : TabKeep st s s') + (indexBound : index.val < 128) (nonzero : pool ≠ 0#u64) + (atIndex : L.mem s (wa (L.ksb s) (AtOff index)) = pool) + (write : L.mem s' (wa pool off) = value) + (frame : ∀ q ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + (q ≠ pool ∨ o ≠ off) → L.mem s' (wa q o) = L.mem s (wa q o)) + (entry : ActiveAsidRoot st Pp s' asid raw) : + ActiveAsidRoot st Pp s asid raw ∨ (asid.val = index.val * 512 + off.val / 8 ∧ raw = value) := by + obtain ⟨i, o, hi, ho, h8, ha, q, hq, hTable, hWord, hn⟩ := entry + have beforePool := table.toDel.poolSet hq + have beforeTable := (table.2 i).symm.trans hTable + by_cases hp : q = pool + · by_cases hOff : o = off + · have same := idx.activeInjective named hi indexBound nonzero (beforeTable.trans hp) atIndex + rw [hp, hOff] at hWord + exact Or.inr ⟨by rw [← same, ← hOff]; exact ha, hWord.symm.trans write⟩ + · exact Or.inl ⟨i, o, hi, ho, h8, ha, q, beforePool, beforeTable, + (frame q beforePool o ho h8 (Or.inr hOff)).symm.trans hWord, hn⟩ + · exact Or.inl ⟨i, o, hi, ho, h8, ha, q, beforePool, beforeTable, + (frame q beforePool o ho h8 (Or.inl hp)).symm.trans hWord, hn⟩ + +private theorem mappedRootFields {c : capability.Cap} {p q a b tag tag' : U64} + (h : MappedAsidRoot c p a tag) (h' : MappedAsidRoot c q b tag') : + p = q ∧ a = b := by + rcases h with ⟨_, rfl⟩ | ⟨_, _, rfl⟩ | ⟨_, rfl⟩ <;> + rcases h' with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e <;> exact ⟨rfl, rfl⟩ + +/-- Assign preserves root agreement when its cap rewrite names a previously +unassigned object and the ASID-pool write is the matching entry. -/ +theorem RootAgreement.assignWord {slot pool off index assigned value : U64} + (old : RootAgreement st OS Pp s) (idx : PoolIdx st OS s) (named : PoolNamed st OS s) + (table : TabKeep st s s') (member : slot ∈ OS) + (indexBound : index.val < 128) (nonzero : pool ≠ 0#u64) + (atIndex : L.mem s (wa (L.ksb s) (AtOff index)) = pool) + (asidValue : assigned.val = index.val * 512 + off.val / 8) + (write : L.mem s' (wa pool off) = value) + (frame : ∀ q ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + (q ≠ pool ∨ o ≠ off) → L.mem s' (wa q o) = L.mem s (wa q o)) + (keep : ∀ x ∈ OS, x ≠ slot → capA st s' x = capA st s x) + (wasUnmapped : ∀ p a tag, ¬ MappedAsidRoot (capA st s slot) p a tag) + (fresh : ∀ x ∈ OS, ∀ a tag, ¬ MappedAsidRoot (capA st s x) (value &&& ~~~3#u64) a tag) + (new : MappedAsidRoot (capA st s' slot) (value &&& ~~~3#u64) assigned (value &&& 3#u64)) : + RootAgreement st OS Pp s' where + backed asid raw entry := by + rcases entry.replaceWord idx named table indexBound nonzero atIndex write frame with before | ⟨ea, rfl⟩ + · obtain ⟨x, hx, cap⟩ := old.backed asid raw before + have ne : x ≠ slot := fun eq => by subst x; exact wasUnmapped _ _ _ cap + exact ⟨x, hx, (keep x hx ne).symm ▸ cap⟩ + · have same := UScalar.eq_of_val_eq (ea.trans asidValue.symm) + subst asid + exact ⟨slot, member, new⟩ + agree x hx y hy p a b tag tag' cx cy := by + by_cases ex : x = slot + · subst x + obtain ⟨obj, ea⟩ := mappedRootFields cx new + by_cases ey : y = slot + · subst y + exact ea.trans (mappedRootFields cy new).2.symm + · rw [keep y hy ey, obj] at cy + exact (fresh y hy _ _ cy).elim + · by_cases ey : y = slot + · subst y + have obj := (mappedRootFields cy new).1 + rw [keep x hx ex, obj] at cx + exact (fresh x hx _ _ cx).elim + · rw [keep x hx ex] at cx + rw [keep y hy ey] at cy + exact old.agree x hx y hy p a b tag tag' cx cy + +/-- The old pool-index proof follows from the exact reverse table link. -/ +theorem S1aPoolCaps.toIdx {H : Heap} {Pt : Set U64} + (h : S1aPoolCaps st H OS Pt Pp s) : PoolIdx st OS s := by + intro x hx p base cap + obtain ⟨index, range, align, nz, link⟩ := h.cap x hx p base cap + have bits : base.val >>> 9 = index.val := by + rw [Nat.shiftRight_eq_div_pow, align] + omega + refine ⟨by rwa [bits], ?_⟩ + intro i bound + rw [vspace.asid_table.eq, WP.spec_ok] + intro entry _ + exact (congrArg UScalar.val (h.index i index p bound range nz entry link)).trans bits.symm + +/-- Assign neither replaces a pool cap nor changes its ASID-table word. +Every active entry produced by the pool write uses its selected nonzero ASID. -/ +theorem S1aPoolCaps.assign {H : Heap} {Vc Ub Pt : Set U64} {asid : U64} + (before : S1aPoolCaps st H OS Pt Pp s) (assign : AsgPost st H OS s s') + (layout : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (entries : ∀ a raw, ActiveAsidRoot st Pp s' a raw → ActiveAsidRoot st Pp s a raw ∨ a = asid) + (nonzero : asid ≠ 0#u64) : S1aPoolCaps st H OS Pt Pp s' := by + have word i : L.mem s' (wa (L.ksb s') (AtOff i)) = L.mem s (wa (L.ksb s) (AtOff i)) := by + rw [assign.ksb] + exact assign.tab layout i + have pool (c : capability.Cap) (p base : U64) (root : VsRootK c) : + c ≠ .AsidPool p base := by + rcases root with ⟨_, _, _, rfl⟩ | ⟨_, _, _, _, _, rfl⟩ | ⟨_, _, _, rfl⟩ <;> intro h <;> cases h + refine ⟨?_, ?_, ?_, ?_⟩ + · intro i hi p hp nz + obtain ⟨member, placed, obj, x, hx, base, cap, eq⟩ := before.present i hi p ((word i).symm.trans hp) nz + have keep := (assign.cap x hx).resolve_right (fun changed => pool _ p base changed.1 cap) + exact ⟨member, placed, obj, x, hx, base, keep.trans cap, eq⟩ + · intro x hx p base cap + have keep := (assign.cap x hx).resolve_right (fun changed => pool _ p base changed.2 cap) + obtain ⟨i, hi, eq, nz, entry⟩ := before.cap x hx p base (keep.symm.trans cap) + exact ⟨i, hi, eq, nz, (word i).trans entry⟩ + · intro i j p hi hj nz lhs rhs + exact before.index i j p hi hj nz ((word i).symm.trans lhs) ((word j).symm.trans rhs) + · intro raw active + rcases entries _ _ active with old | assigned + · exact before.noZero raw old + · exact nonzero assigned.symm + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignCaps.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignCaps.lean new file mode 100644 index 000000000..4b24d1035 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignCaps.lean @@ -0,0 +1,156 @@ +/- +P1 (aarch64): live cap and pool invariants across a root publication. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignPaths + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +/-- The publication changes the mapping metadata of a single root. -/ +theorem S1aAssignWrite.selectedCaps + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) : + (∃ a, capA st s x = .Pml4 root false a ∧ capA st q x = .Pml4 root true asid) ∨ + (∃ a, capA st s x = .HighVSpace root false a ∧ capA st q x = .HighVSpace root true asid) ∨ + (∃ a v v', capA st s x = .Ept root 0#u64 false a v ∧ capA st q x = .Ept root 0#u64 true asid v') := by + rcases event.before with ⟨old, a, before⟩ | ⟨old, a, before⟩ | ⟨old, a, v, before⟩ <;> + rcases event.after with ⟨new, after⟩ | ⟨new, v', after⟩ | ⟨new, after⟩ <;> + rw [old] at new + all_goals cases new + · exact Or.inl ⟨a, before, after⟩ + · exact Or.inr (Or.inl ⟨a, before, after⟩) + · exact Or.inr (Or.inr ⟨a, v, v', before, after⟩) + +private theorem S1aAssignWrite.refUpdate + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) : + ∃ key, s1aTableKey (capA st s x) = some key ∧ s1aTableKey (capA st q x) = some key ∧ + s1aTableRef (capA st s x) = none ∧ s1aTableRef (capA st q x) ≠ none := by + rcases event.selectedCaps with ⟨_, before, after⟩ | ⟨_, before, after⟩ | ⟨_, _, _, before, after⟩ <;> + simp [before, after, s1aTableKey, s1aTableRef] + +/-- The selected slot is the only change; ordinary caps may be transported in either direction. -/ +theorem S1aAssignWrite.capIff + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y : U64} (member : y ∈ OS) {c : capability.Cap} + (before : ¬ S1aUnassignedRoot c root tag) (after : ¬ MappedAsidRoot c root asid tag) : + capA st q y = c ↔ capA st s y = c := by + by_cases same : y = x + · subst y + exact ⟨fun eq => (after (eq ▸ event.after)).elim, fun eq => (before (eq ▸ event.before)).elim⟩ + · rw [event.write.other y member same] + +local macro "assignBefore" : tactic => `(tactic| + (intro eq; rcases eq with ⟨_, _, bad⟩ | ⟨_, _, bad⟩ | ⟨_, _, _, bad⟩ <;> cases bad)) + +local macro "assignAfter" : tactic => `(tactic| + (intro eq; rcases eq with ⟨_, bad⟩ | ⟨_, _, bad⟩ | ⟨_, bad⟩ <;> cases bad)) + +private theorem S1aAssignWrite.poolCapIff + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y p base : U64} (member : y ∈ OS) : + capA st q y = .AsidPool p base ↔ capA st s y = .AsidPool p base := by + exact event.capIff member (by assignBefore) (by assignAfter) + +/-- Assign leaves all PageTable capability metadata intact. -/ +theorem S1aAssignWrite.pageTableIff + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y p a v : U64} {m : Bool} (member : y ∈ OS) : + capA st q y = .PageTable p m a v ↔ capA st s y = .PageTable p m a v := by + exact event.capIff member (by assignBefore) (by assignAfter) + +private theorem S1aAssignWrite.frameIff + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y p r a v : U64} {sz : capability.FrameSize} {d m e : Bool} (member : y ∈ OS) : + capA st q y = .Frame p sz r d m e a v ↔ capA st s y = .Frame p sz r d m e a v := by + exact event.capIff member (by assignBefore) (by assignAfter) + +theorem S1aAssignWrite.poolCaps + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (named : PoolNamed st OS s) (table : TabKeep st s q) : S1aPoolCaps st H OS Pt Pp q := by + refine ⟨?_, ?_, ?_, ?_⟩ + · intro i hi p reads hp + rw [table.2 i] at reads + obtain ⟨a, b, c, y, hy, base, cap, value⟩ := h.poolCaps.present i hi p reads hp + exact ⟨a, b, c, y, hy, base, (event.poolCapIff hy).mpr cap, value⟩ + · intro y hy p base cap + obtain ⟨i, hi, value, hp, reads⟩ := h.poolCaps.cap y hy p base ((event.poolCapIff hy).mp cap) + exact ⟨i, hi, value, hp, (table.2 i).trans reads⟩ + · intro i j p hi hj hp left right + exact h.poolCaps.index i j p hi hj hp ((table.2 i).symm.trans left) ((table.2 j).symm.trans right) + · intro raw entry + rcases event.entry h heap named table entry with prior | ⟨eq, _⟩ + · exact h.poolCaps.noZero raw prior + · exact event.asidNonzero eq.symm + +/-- The root publication preserves every table key, with only the selected reference changing. -/ +theorem S1aAssignWrite.referenceAgreement + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) (refs : S1aTableCaps st OS s) : + (∀ y ∈ OS, ∀ z ∈ OS, ∀ k, s1aTableKey (capA st q y) = some k → + s1aTableKey (capA st q z) = some k → s1aTableRef (capA st q y) = s1aTableRef (capA st q z)) ∧ + (∀ y ∈ OS, ∀ z ∈ OS, ∀ k, s1aTableKey (capA st q y) = some k → + s1aTableKey (capA st q z) = some k → s1aTableRef (capA st q y) = none → z = y) := by + obtain ⟨key, oldKey, newKey, oldRef, newRef⟩ := event.refUpdate + have keys (y : U64) (hy : y ∈ OS) : s1aTableKey (capA st q y) = s1aTableKey (capA st s y) := by + by_cases same : y = x + · rw [same, oldKey, newKey] + · rw [event.write.other y hy same] + have unique (y : U64) (hy : y ∈ OS) (atKey : s1aTableKey (capA st q y) = some key) : y = x := + refs.unique x event.rootSlot y hy key oldKey ((keys y hy).symm.trans atKey) oldRef + have atSelected (y : U64) (hy : y ∈ OS) {z : U64} {k : Nat × U64} + (there : z = x) (cy : s1aTableKey (capA st q y) = some k) + (cz : s1aTableKey (capA st q z) = some k) : y = x := by + rw [there, newKey] at cz + exact unique y hy (cy.trans cz.symm) + refine ⟨?_, ?_⟩ + · intro y hy z hz k cy cz + by_cases here : y = x + · have eq := atSelected z hz here cz cy + rw [here, eq] + · by_cases there : z = x + · exact (here (atSelected y hy there cy cz)).elim + · rw [event.write.other y hy here, event.write.other z hz there] + exact refs.references y hy z hz k ((keys y hy).symm.trans cy) ((keys z hz).symm.trans cz) + · intro y hy z hz k cy cz empty + by_cases here : y = x + · exact (newRef (here ▸ empty)).elim + · by_cases there : z = x + · exact (here (atSelected y hy there cy cz)).elim + · rw [event.write.other y hy here] at empty + exact refs.unique y hy z hz k ((keys y hy).symm.trans cy) ((keys z hz).symm.trans cz) empty + +/-- Old paths retain their exact PageTable and frame caps. A new root has no child or leaf. -/ +theorem S1aAssignWrite.pathBacking + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (named : PoolNamed st OS s) (kinds : KindA st OS s) (table : TabKeep st s q) + {Tb' Te' : Set U64} {Lv' Re' bits' : U64 → Nat} + (geometry : ∀ k a sh b t, S1aPath st Pp n q k a sh b t → + if k = 1#u64 then t ∈ Te' ∧ sh = 12 + 9 * Re' t ∧ s1aTableWidth k n sh ≤ 2 ^ bits' t + else t ∈ Tb' ∧ sh + 9 * Lv' t = 39) : + S1aPathBacking st H OS Pp Tb' Te' Lv' Re' bits' n q := by + refine ⟨geometry, ?_, ?_⟩ + · intro k a sh b t path deep + rcases event.pathCases h heap named kinds table path with old | ⟨stage, _, level, _, _⟩ + · obtain ⟨y, hy, va, cap, addr⟩ := h.paths.children k a sh b t old deep + exact ⟨y, hy, va, (event.pageTableIff hy).mpr cap, addr⟩ + · rw [stage, level] at deep + exact (Nat.lt_irrefl _ deep).elim + · intro k a sh b t path o width aligned inside valid + rcases event.pathCases h heap named kinds table path with old | fresh + · rw [event.oldPathWord h heap kinds old width aligned] at valid ⊢ + obtain ⟨y, hy, sz, r, d, va, size, cap, addr, storage⟩ := + h.paths.leaves k a sh b t old o width aligned inside valid + exact ⟨y, hy, sz, r, d, va, size, (event.frameIff hy).mpr cap, addr, storage⟩ + · rw [event.assignedEmpty h heap kinds fresh width aligned] at valid + rcases valid with ⟨_, bad⟩ | ⟨_, bad⟩ <;> cases bad + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignD.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignD.lean new file mode 100644 index 000000000..5e6445b04 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignD.lean @@ -0,0 +1,255 @@ +/- +P1 (aarch64, A64-S1A gen 41): ASIDPool Assign keeps R2 from the assigned root's descriptor facts alone. + +`S1aR2.ofAssign` reads the full `VsTy` only at the newly reachable tables of a tag-2 Assign: the root, its private +level-1 table and the kernel tables (`S1aAssignRawStage1`). `S1aAssignDesc` is `VsTy.desc` at exactly those tables; +`highChildD`, `stage1TypingD`, `geometryD`, `ofAssignD` and `assignExactR2D` are the old lemmas over it (same +proofs). Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignPost +import Fl4ProofsA64.P1.S1aR2AssignPlace + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +variable (st) in +/-- **`VsTy.desc` at the tables a tag-2 Assign of `root` makes reachable**: the root, its private level-1 table and +the kernel tables. -/ +def S1aAssignDesc (Tb Kt : Set U64) (Lv : U64 → Nat) (s : S) (root : U64) : Prop := + ∀ p, (p = root ∨ p = wa root 4096#u64 ∨ p ∈ Kt) → p ∈ Tb → Lv p < 3 → ∀ o : U64, o.val < 4096 → + o.val % 8 = 0 → (L.mem s (wa p o) &&& 3#u64) = 3#u64 → + wa (L.mem s (wa p o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Tb ∧ + Lv (wa (L.mem s (wa p o) &&& vspace.ADDR_MASK) layout.PPTR_BASE) = Lv p + 1 + +/-- The full typing gives the descriptor facts. -/ +theorem VsTy.assignDesc {kb : U64} (ty : VsTy st kb Pp Tb Lv s) (r : U64) : S1aAssignDesc st Tb Kt Lv s r := + fun p _ member level o width al edge => ty.desc p member level o width al edge + +/-- `highChild` from the Assign root's descriptor facts. -/ +theorem S1aAssignWrite.highChildD + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (dsc : S1aAssignDesc st Tb Kt Lv s root) (tg : tag = 2#u64) : + wa root 4096#u64 ∈ Tb ∧ Lv (wa root 4096#u64) = 1 := by + have member := ev.highMember h tg + have level := h.place.high.lv root member + have edge := h.core.stage2.hi root member + have child := dsc root (Or.inl rfl) (h.place.high.sub member) (by omega) 4088#u64 (by decide) (by decide) edge + simpa only [h.highLink root member, level, Nat.zero_add] using child + +set_option maxHeartbeats 3500000 in +/-- `stage1Typing` from the Assign root's descriptor facts. -/ +theorem S1aAssignWrite.stage1TypingD + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + (table : TabKeep st s q) (dsc : tag = 2#u64 → S1aAssignDesc st Tb Kt Lv s root) : + VsTyR st (L.ksb q) (PoolSet st Pp q) ∅ (s1aAssignTables tag root Tb) (s1aAssignLv tag root Lv) q := by + refine ⟨?_, ?_, ?_⟩ + · intro o lo hi al nz + have kept := table.off lo hi al + rw [kept] at nz ⊢ + exact table.poolSet_eq.symm ▸ h.core.stage1.tbl o lo hi al nz + · intro p live o width al nz + rw [table.poolSet_eq] at live + exact ev.stage1RootTyping h heap kinds live width al nz + · intro p member path level o width al edge + rcases ev.rawStage1 h heap kinds table path with prior | ⟨tg, rfl⟩ | ⟨tg, which⟩ + · have priorMember := h.core.stage1.reachableMember prior + have loc : PtW Pt (wa p o) := ⟨p, h.place.tables priorMember, o, width, al, rfl⟩ + have kept := ev.edgeKept h heap loc edge + rw [(ev.stage1KeepType h heap kinds prior).2] at level + have parentDepth := (ev.stage1KeepType h heap kinds prior).2 + rw [parentDepth] + rw [kept] at edge ⊢ + obtain ⟨child, same⟩ := ev.stage1KeepType h heap kinds (.step prior level width al edge) + exact ⟨child, same.trans (h.core.stage1.desc p priorMember prior level o width al edge).2⟩ + · exact (ev.nativeNoEdge h heap tg width al edge).elim + · have unchanged : s1aAssignLv tag root Lv = Lv := by simp [s1aAssignLv, tg] + have sameTables : s1aAssignTables tag root Tb = Tb := by simp [s1aAssignTables, tg] + rw [sameTables] at member + rw [unchanged] at level + have loc : PtW Pt (wa p o) := ⟨p, h.place.tables member, o, width, al, rfl⟩ + have kept := ev.edgeKept h heap loc edge + rw [kept] at edge + rw [kept, unchanged, sameTables] + exact dsc tg p which member level o width al edge + +set_option maxHeartbeats 3300000 in +theorem S1aAssignWrite.geometryD + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (named : PoolNamed st OS s) (kinds : KindA st OS s) (table : TabKeep st s q) + (dsc : tag = 2#u64 → S1aAssignDesc st Tb Kt Lv s root) + {k a t : U64} {sh b : Nat} (path : S1aPath st Pp n q k a sh b t) : + if k = 1#u64 then + t ∈ s1aAssignEpt tag root Te ∧ sh = 12 + 9 * s1aAssignRe tag root n Re t ∧ + s1aTableWidth k n sh ≤ 2 ^ s1aAssignBits tag root bits t + else t ∈ s1aAssignTables tag root Tb ∧ sh + 9 * s1aAssignLv tag root Lv t = 39 := by + rcases ev.pathCases h heap named kinds table path with old | fresh + · have typed := h.paths.tables k a sh b t old + by_cases stage : k = 1#u64 + · subst k + rw [if_pos rfl] at typed ⊢ + have reach := old.toStage2 fun sh' b' t' earlier => + (show _ ∧ _ ∧ _ from h.paths.tables 1#u64 a sh' b' t' earlier).2 + obtain ⟨m, depth, storage⟩ := ev.stage2KeepType h reach + rw [depth, storage] + exact ⟨m, typed.2⟩ + · rw [if_neg stage] at typed ⊢ + have priorDepth (sh' b' : Nat) (t' : U64) (earlier : S1aPath st Pp n s k a sh' b' t') : + sh' + 9 * Lv t' = 39 := by + have geom := h.paths.tables k a sh' b' t' earlier + rw [if_neg stage] at geom + exact geom.2 + have highDepth (id raw : U64) (entry : ActiveAsidRoot st Pp s id raw) (tg : raw &&& 3#u64 = 2#u64) : + Lv (raw &&& ~~~3#u64) = 0 := by + obtain ⟨_, o, _, width, al, _, p, hp, _, word, nz⟩ := entry + rw [← word] at tg ⊢ + exact ((h.core.stage1.pool p hp o width al (fun zero => nz (word ▸ zero))).2 tg).2 + have reach := old.toStage1 stage priorDepth highDepth + obtain ⟨m, depth⟩ := ev.stage1KeepType h heap kinds reach + rw [depth] + exact ⟨m, typed.2⟩ + · obtain ⟨stage, id, depth, _, base⟩ := fresh + subst k a sh t + rcases ev.before with ⟨tg, _⟩ | ⟨tg, _⟩ | ⟨tg, _⟩ + · subst tag + norm_num [s1aAssignTables, s1aAssignLv, s1aTopShift, + show (0#u64 : U64) ≠ 1#u64 by decide, show (0#u64 : U64) ≠ 2#u64 by decide] + · obtain ⟨member, level⟩ := ev.highChildD h (dsc tg) tg + simp [tg, s1aAssignTables, s1aAssignLv, s1aTopShift, member, level] + · subst tag + have width := s1aTableWidth.leStorage 1#u64 n (s1aTopShift 1#u64 n) + simp only [s1aTableStorage, and_self, ite_true] at width + have top : s1aTopShift 1#u64 n = 12 + 9 * (s2lv n - 1) := by + simp only [s1aTopShift, s2lv, show (1#u64 : U64) ≠ 0#u64 by decide, + show (1#u64 : U64) ≠ 2#u64 by decide, ite_false] + split <;> decide + simpa [s1aAssignEpt, s1aAssignRe, s1aAssignBits, top] using width + +set_option maxHeartbeats 3700000 in +/-- Assign grows the selected table witnesses on the original heap, slots and footprint. -/ +theorem S1aR2.ofAssignD + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (dsc : tag = 2#u64 → S1aAssignDesc st Tb Kt Lv s root) + (heap : HeapOK H) (named : PoolNamed st OS s) (kinds : KindA st OS s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) : + ∃ Tb' Te' Lv' Re' bits', S1aR2 st H OS Pt Pp Tb' Hr Te' Kt Lv' Re' bits' n q := by + let Tb' := s1aAssignTables tag root Tb + let Te' := s1aAssignEpt tag root Te + let Lv' := s1aAssignLv tag root Lv + let Re' := s1aAssignRe tag root n Re + let bits' := s1aAssignBits tag root bits + refine ⟨Tb', Te', Lv', Re', bits', ?_⟩ + have tab := ev.table h ptKs + obtain ⟨granules, size, typedHeap⟩ := ev.stage2Placement h heap kinds + obtain ⟨tables, highPlace⟩ := ev.stage1Placement h heap + have lookup := ev.lookup h heap kinds tab typedHeap + have agree := ev.rootAgreement h heap named kinds tab + have exactPaths : S1aPathBacking st H OS Pp Tb' Te' Lv' Re' bits' n q := + ev.pathBacking h heap named kinds tab (fun _ _ _ _ _ => ev.geometryD h heap named kinds tab dsc) + have highSet : Hr = HvRt st OS q := h.highRoots.trans ev.highSet + have header p (live : p ∈ Hr) : L.mem q (wa p 4088#u64) = L.mem s (wa p 4088#u64) := + ev.highHeader h heap kinds p live 4088#u64 (by decide) (by decide) + have highObj : HvObjects st H OS q := by + intro y hy p m a cap + obtain ⟨oldM, oldA, prior⟩ := ev.highSource hy cap + exact h.highObjects y hy p oldM oldA prior + have ept : EptPlaced st H OS Pt q := by + intro y hy p l m a v cap + obtain ⟨oldM, oldA, oldV, prior⟩ := ev.eptSource hy cap + exact h.eptRoots y hy p l oldM oldA oldV prior + have kernelMember : Kt ⊆ Tb' := by + intro t ht + have member := h.kernelTables.1 ht + dsimp [Tb', s1aAssignTables] + split + · exact Set.mem_insert_of_mem _ member + · exact member + have closed t (ht : t ∈ Kt) (depth : Lv' t < 3) (o : U64) (width : o.val < 4096) (al : o.val % 8 = 0) + (edge : L.mem q (wa t o) &&& 3#u64 = 3#u64) : + wa (L.mem q (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + have level : Lv' t = Lv t := by + dsimp [Lv', s1aAssignLv] + split + · rename_i stage + apply Function.update_of_ne + intro eq + obtain ⟨a, cap⟩ := ev.nativeCap stage + exact h.core.lookup.kt t ht x ev.rootSlot (Or.inr (Or.inl ⟨false, a, eq.symm ▸ cap⟩)) + · rfl + rw [level] at depth + have loc : PtW Pt (wa t o) := ⟨t, h.place.tables (h.kernelTables.1 ht), o, width, al, rfl⟩ + have kept := ev.edgeKept h heap loc edge + rw [kept] at edge ⊢ + exact h.kernelClosed t ht depth o width al edge + have routes : S1aRouteFacts st H OS Pt Pp Tb' Hr Te' Kt Lv' Re' bits' n q := + ⟨lookup, agree, typedHeap, exactPaths, ev.tableCaps h heap kinds, ev.rootSlots h heap kinds, highSet, + (fun p live => by rw [header p live]; exact h.highLink p live), highObj, ept, + (fun y hy p m a v cap => h.pageObjects y hy p m a v ((ev.pageTableIff hy).mp cap)), closed⟩ + exact { + core := ⟨lookup, routes.recoverWalk heap (ev.kindPost kinds), agree, + ev.stage1TypingD h heap kinds tab dsc, ev.stage2Typing h heap kinds tab, typedHeap⟩ + place := by rw [tab.1, tab.poolSet_eq]; exact ⟨h.place.pools, tables, granules, highPlace, size⟩ + poolCaps := ev.poolCaps h heap named tab + capRefs := routes.capRefs + paths := exactPaths + pageTables := fun y hy p m a v cap => h.pageTables y hy p m a v ((ev.pageTableIff hy).mp cap) + footprint := h.footprint + pageObjects := routes.pageObjects + nativeRoots := fun y hy p m a cap => by + obtain ⟨oldM, oldA, prior⟩ := ev.nativeSource hy cap + exact h.nativeRoots y hy p oldM oldA prior + eptRoots := ept + highObjects := highObj + highHeaders := fun y hy p m a cap => by + have member : p ∈ Hr := by rw [highSet]; exact ⟨y, hy, m, a, cap⟩ + rw [header p member] + exact h.core.stage2.hi p member + highLink := routes.highLink + highRoots := highSet + highFootprint := h.highFootprint + kernelTables := ⟨kernelMember, h.kernelTables.2⟩ + kernelClosed := closed + rootSlots := routes.rootSlots } + +section dispatch + +variable {A : Type _} {ar : machine.Arch A} {Cs Vc Ub U Ac Rp Nt : Set U64} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot base : U64} + +/-- The concrete Assign dispatch preserves R2 on all outcomes, from the assigned root's descriptor facts. -/ +theorem syscall.decode_invocation.assignExactR2D + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (dsc : ∀ y ∈ OS, ∀ r a, capA st s y = .HighVSpace r false a → S1aAssignDesc st Tb Kt Lv s r) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.AsidPool pool base) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (src : obj.Slot.cap st slot s = ok (.AsidPool pool base)) + (named : PoolNamed st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMASIDPoolAssign len slot + (.AsidPool pool base) blk call don fp buf extra ⦃ _ q _ => + ∃ Tb' Te' Lv' Re' bits', S1aR2 st H OS Pt Pp Tb' Hr Te' Kt Lv' Re' bits' n q ⦄ := by + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono (vspace.decode.assignExactWrite h vr D P src a len buf call) ?_ + rintro ⟨_, q, _⟩ (reject | ⟨x, root, tag, asid, index, off, ev⟩) + · change q = s at reject + subst q + exact ⟨Tb, Te, Lv, Re, bits, h⟩ + · exact h.ofAssignD (fun tg => let ⟨a, c⟩ := ev.highCap tg; dsc x ev.rootSlot root a c) P.heap named kinds ptKs ev + +end dispatch + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignLive.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignLive.lean new file mode 100644 index 000000000..023a7d09d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignLive.lean @@ -0,0 +1,181 @@ +/- +P1 (aarch64): all-live root memory is disjoint from ASIDPool Assign. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignPlace + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +theorem S1aAssignWrite.nativeSource + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y p a : U64} {m : Bool} (hy : y ∈ OS) (cap : capA st q y = .Pml4 p m a) : + ∃ m' a', capA st s y = .Pml4 p m' a' := by + by_cases same : y = x + · subst y + rcases ev.selectedCaps with ⟨_, before, after⟩ | ⟨_, _, after⟩ | ⟨_, _, _, _, after⟩ <;> + rw [after] at cap <;> cases cap + exact ⟨false, _, before⟩ + · exact ⟨m, a, (ev.write.other y hy same).symm.trans cap⟩ + +theorem S1aAssignWrite.highSource + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y p a : U64} {m : Bool} (hy : y ∈ OS) (cap : capA st q y = .HighVSpace p m a) : + ∃ m' a', capA st s y = .HighVSpace p m' a' := by + by_cases same : y = x + · subst y + rcases ev.selectedCaps with ⟨_, _, after⟩ | ⟨_, before, after⟩ | ⟨_, _, _, _, after⟩ <;> + rw [after] at cap <;> cases cap + exact ⟨false, _, before⟩ + · exact ⟨m, a, (ev.write.other y hy same).symm.trans cap⟩ + +theorem S1aAssignWrite.eptSource + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y p l a v : U64} {m : Bool} (hy : y ∈ OS) (cap : capA st q y = .Ept p l m a v) : + ∃ m' a' v', capA st s y = .Ept p l m' a' v' := by + by_cases same : y = x + · subst y + rcases ev.selectedCaps with ⟨_, _, after⟩ | ⟨_, _, after⟩ | ⟨_, _, _, before, after⟩ <;> + rw [after] at cap <;> cases cap + exact ⟨false, _, _, before⟩ + · exact ⟨m, a, v, (ev.write.other y hy same).symm.trans cap⟩ + +theorem S1aAssignWrite.highSet + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) : + HvRt st OS s = HvRt st OS q := by + ext p + constructor <;> rintro ⟨y, hy, m, a, cap⟩ + · by_cases same : y = x + · subst y + rcases ev.selectedCaps with ⟨_, before, _⟩ | ⟨_, before, after⟩ | ⟨_, _, _, before, _⟩ <;> + rw [before] at cap <;> cases cap + exact ⟨x, hy, true, asid, after⟩ + · exact ⟨y, hy, m, a, (ev.write.other y hy same).trans cap⟩ + · obtain ⟨m', a', old⟩ := ev.highSource hy cap + exact ⟨y, hy, m', a', old⟩ + +theorem S1aAssignWrite.kindPost + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) (kinds : KindA st OS s) : + KindA st OS q := by + apply kinds.keep + intro y hy + by_cases same : y = x + · subst y + rcases ev.selectedCaps with ⟨a, before, after⟩ | ⟨a, before, after⟩ | ⟨a, v, v', before, after⟩ + · rw [before, after, (assignNativeKey root false a).2, (assignNativeKey root true asid).2] + exact ⟨⟨fun _ => (assignNativeKey root false a).1, fun _ => (assignNativeKey root true asid).1⟩, fun _ => ⟨rfl, rfl⟩⟩ + · rw [before, after, ptrA_hv, ptrA_hv] + exact ⟨⟨fun _ => RngKeyA.hv _ _ _, fun _ => RngKeyA.hv _ _ _⟩, fun _ => ⟨rfl, rfl⟩⟩ + · rw [before, after, ptrA_ept, ptrA_ept] + exact ⟨⟨fun _ => RngKeyA.ept _ _ _ _ _, fun _ => RngKeyA.ept _ _ _ _ _⟩, fun _ => ⟨rfl, rfl⟩⟩ + · rw [ev.write.other y hy same] + exact ⟨Iff.rfl, fun _ => ⟨rfl, rfl⟩⟩ + +private theorem S1aAssignWrite.nativeWord + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {y p a o : U64} {m : Bool} (hy : y ∈ OS) (cap : capA st s y = .Pml4 p m a) + (bound : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) := by + obtain ⟨obj, placed⟩ := h.nativeRoots y hy p m a cap + exact ev.write.memory _ (Or.inl ⟨p, placed, o, bound, al, rfl⟩) + (ev.offObject h heap kinds hy obj (cap ▸ (assignNativeKey p m a).1) (cap ▸ (assignNativeKey p m a).2) + (by simp [cap, kindA]) bound) + +private theorem S1aAssignWrite.eptWord + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {y p a v o : U64} {m : Bool} (hy : y ∈ OS) (cap : capA st s y = .Ept p 0#u64 m a v) + (bound : o.val < 8192) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) := by + obtain ⟨obj, placed⟩ := h.eptRoots y hy p 0#u64 m a v cap + have loc := ptw_mono placed (ptwb_gran (fun _ _ => Or.inr rfl) + (show PtWb {p} (fun _ => 13) (wa p o) from ⟨p, Set.mem_singleton p, o, bound, al, rfl⟩)) + exact ev.write.memory _ (Or.inl loc) + (ev.offObject h heap kinds hy obj (cap ▸ RngKeyA.ept _ _ _ _ _) (cap ▸ ptrA_ept _ _ _ _ _) + (by simp [cap, kindA]) bound) + +private theorem S1aAssignWrite.highPrivateWord + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {y p a o : U64} {m : Bool} (hy : y ∈ OS) (cap : capA st s y = .HighVSpace p m a) + (bound : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa (wa p 4096#u64) o) = L.mem s (wa (wa p 4096#u64) o) := by + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨y, hy, m, a, cap⟩ + have point := h.highFootprint ⟨p, live, Or.inr ⟨rfl, rfl⟩⟩ + have fits : (4096#u64 : U64).val + o.val < 2 ^ 64 := by change 4096 + o.val < 2 ^ 64; omega + have inside : (wa 4096#u64 o).val < 2 ^ 13 := by rw [wadd_val fits]; change 4096 + o.val < 8192; omega + refine ev.write.memory _ (Or.inl ⟨_, point, o, bound, al, rfl⟩) ?_ + rw [waddA_assoc p 4096#u64 o fits] + exact ev.offObject h heap kinds hy (h.highObjects y hy p m a cap) + (cap ▸ RngKeyA.hv _ _ _) (cap ▸ ptrA_hv _ _ _) (by simp [cap, kindA]) inside + +theorem S1aAssignWrite.rootSlots + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) : + S1aRootSlots st OS Kt n q where + native y hy p m a cap o bound al := by + obtain ⟨m', a', old⟩ := ev.nativeSource hy cap + rw [ev.nativeWord h heap kinds hy old bound.2 al] + exact h.rootSlots.native y hy p m' a' old o bound al + stage2 y hy p m a v cap o bound al := by + obtain ⟨m', a', v', old⟩ := ev.eptSource hy cap + rw [ev.eptWord h heap kinds hy old bound.2 al] + exact h.rootSlots.stage2 y hy p m' a' v' old o bound al + highCopies y hy p m a cap o bound al edge := by + obtain ⟨m', a', old⟩ := ev.highSource hy cap + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨y, hy, m', a', old⟩ + rw [ev.highHeader h heap kinds p live o (by omega) al] at edge ⊢ + exact h.rootSlots.highCopies y hy p m' a' old o bound al edge + highPrivate y hy p m a cap o bound al := by + obtain ⟨m', a', old⟩ := ev.highSource hy cap + rw [ev.highPrivateWord h heap kinds hy old bound.1 al] + exact h.rootSlots.highPrivate y hy p m' a' old o bound al + +theorem S1aAssignWrite.tableCaps + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) : + S1aTableCaps st OS q := by + obtain ⟨agree, unique⟩ := ev.referenceAgreement h.capRefs + have different (y : U64) (cap : + (∃ p a, capA st q y = .Pml4 p false a) ∨ (∃ p a, capA st q y = .HighVSpace p false a)) : y ≠ x := by + intro same + subst y + rcases ev.selectedCaps with ⟨_, _, new⟩ | ⟨_, _, new⟩ | ⟨_, _, _, _, new⟩ <;> + rw [new] at cap <;> rcases cap with ⟨_, _, eq⟩ | ⟨_, _, eq⟩ <;> cases eq + refine ⟨agree, unique, ?_, ?_⟩ + · intro y hy p a cap o bound al + have old := (ev.write.other y hy (different y (Or.inl ⟨p, a, cap⟩))).symm.trans cap + rw [ev.nativeWord h heap kinds hy old bound al] + exact h.capRefs.nativeEmpty y hy p a old o bound al + · intro y hy p a cap o bound al + have old := (ev.write.other y hy (different y (Or.inr ⟨p, a, cap⟩))).symm.trans cap + rw [ev.highPrivateWord h heap kinds hy old bound al] + exact h.capRefs.highEmpty y hy p a old o bound al + +/-- The pool write is disjoint from the complete allocation of every cap +that stays unmapped. -/ +theorem S1aAssignWrite.unmappedZero + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {y p o : U64} {size : Nat} (hy : y ∈ OS) (unmapped : UnmCap (capA st s y) p size) + (bound : o.val < size) (al : o.val % 8 = 0) : + L.mem q (wa p o) = 0#u64 := by + have old := h.core.lookup.zr y hy p size unmapped o bound al + rcases unmapped with ⟨rfl, a, v, cap⟩ | ⟨rfl, a, v, cap⟩ + · have obj := h.pageObjects y hy p false a v cap + have loc : PtW Pt (wa p o) := ⟨p, h.pageTables y hy p false a v cap, o, bound, al, rfl⟩ + exact (ev.write.memory _ (Or.inl loc) + (ev.offObject h heap kinds hy obj (cap ▸ RngKeyA.pt _ _ _ _) (cap ▸ ptrA_pt _ _ _ _) + (by simp [cap, kindA]) bound)).trans old + · exact (ev.eptWord h heap kinds hy cap bound al).trans old + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignLookup.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignLookup.lean new file mode 100644 index 000000000..c973f830d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignLookup.lean @@ -0,0 +1,173 @@ +/- +P1 (aarch64): raw table backing after a root publication. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignLive + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +private theorem S1aAssignWrite.keepNames + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y p : U64} (hy : y ∈ OS) : NamesV (capA st q y) p ↔ NamesV (capA st s y) p := by + by_cases same : y = x + · subst y + rcases ev.selectedCaps with ⟨_, old, new⟩ | ⟨_, old, new⟩ | ⟨_, _, _, old, new⟩ <;> + rw [old, new] <;> simp [NamesV] + · rw [ev.write.other y hy same] + +private theorem S1aAssignWrite.keepMapped + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y p : U64} (hy : y ∈ OS) (cap : MapV (capA st s y) p) : + MapV (capA st q y) p := by + have different : y ≠ x := by + intro same + subst y + rcases ev.before with ⟨_, _, old⟩ | ⟨_, _, old⟩ | ⟨_, _, _, old⟩ <;> simp [old, MapV] at cap + rw [ev.write.other y hy different] + exact cap + +private theorem S1aAssignWrite.unmappedSource + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + {y p : U64} {size : Nat} (hy : y ∈ OS) (cap : UnmCap (capA st q y) p size) : + UnmCap (capA st s y) p size ∧ y ≠ x := by + have different : y ≠ x := by + intro same + subst y + rcases ev.after with ⟨_, new⟩ | ⟨_, _, new⟩ | ⟨_, new⟩ <;> simp [new, UnmCap] at cap + exact ⟨by simpa only [ev.write.other y hy different] using cap, different⟩ + +private theorem S1aAssignWrite.stage1NewBacking + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {p : U64} (new : S1aAssignRawStage1 tag root Kt p) (nok : p ∉ Kt) : + MapV (capA st q x) p ∧ S1GranuleH st H OS q p := by + rcases new with ⟨tg, eq⟩ | ⟨tg, side⟩ + · obtain ⟨a, old⟩ := ev.nativeCap tg + rcases ev.after with ⟨_, cap⟩ | ⟨bad, _⟩ | ⟨bad, _⟩ + · subst p + exact ⟨Or.inr (Or.inl ⟨asid, cap⟩), Or.inl (h.nativeRoots x ev.rootSlot root false a old).1⟩ + · rw [tg] at bad + cases bad + · rw [tg] at bad + cases bad + · obtain ⟨a, old⟩ := ev.highCap tg + rcases ev.after with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · rw [tg] at bad + cases bad + · rw [tg] at bad + cases bad + · have actual : p = root ∨ p = wa root 4096#u64 := side.elim Or.inl (fun right => Or.inr (right.resolve_right nok)) + refine ⟨?_, Or.inr ⟨root, h.highObjects x ev.rootSlot root false a old, actual, x, ev.rootSlot, asid, cap⟩⟩ + rcases actual with eq | eq + · subst p + exact Or.inr (Or.inr (Or.inl ⟨asid, cap⟩)) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨root, asid, cap, eq⟩))) + +private theorem S1aAssignWrite.noUnmappedOverlap + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {y p : U64} {size : Nat} (hy : y ∈ OS) (different : y ≠ x) (unm : UnmCap (capA st s y) p size) + (mapped : MapV (capA st q x) p) : False := by + have unf := h.core.lookup.vh.1 y hy p size unm + have selectedKey := ev.before.rangeKey + have unmKey : RngKeyA (capA st s y) ∧ ptrA (capA st s y) = p ∧ + (kindA (capA st s y) = 14 ∨ kindA (capA st s y) = 19) := by + rcases unm with ⟨_, a, v, cap⟩ | ⟨_, a, v, cap⟩ + · rw [cap] + exact ⟨RngKeyA.pt _ _ _ _, ptrA_pt _ _ _ _, Or.inl rfl⟩ + · rw [cap] + exact ⟨RngKeyA.ept _ _ _ _ _, ptrA_ept _ _ _ _ _, Or.inr rfl⟩ + have sameKind (equal : root = p) : kindA (capA st s x) = kindA (capA st s y) := + kinds.kind x ev.rootSlot y hy selectedKey.1 unmKey.1 (by rw [selectedKey.2, unmKey.2.1, equal]) + rcases ev.selectedCaps with ⟨a, old, cap⟩ | ⟨a, old, cap⟩ | ⟨a, v, v', old, cap⟩ + · have kind := sameKind (by simpa [cap, MapV] using mapped) + have choices := unmKey.2.2 + rw [← kind, old] at choices + simp [kindA] at choices + · have base : root = p ∨ p = wa root 4096#u64 := by simpa [cap, MapV, and_comm] using mapped + rcases base with equal | privateTable + · have kind := sameKind equal + have choices := unmKey.2.2 + rw [← kind, old] at choices + simp [kindA] at choices + · obtain ⟨z, _, obj⟩ := unf + have high := h.highObjects x ev.rootSlot root false a old + have noSame : p ≠ root := by + intro equal + have fits := heap.fits root _ high + simp only [HKind.bits] at fits + have grow : (wa root 4096#u64).val = root.val + 4096 := by + have within : root.val + (4096#u64 : U64).val < 2 ^ 64 := by change root.val + 4096 < 2 ^ 64; omega + exact wadd_val within + have vals := congrArg UScalar.val (privateTable.symm.trans equal) + omega + have apart := tableWordsNe heap obj high (o := 0#u64) (o' := 4096#u64) noSame + (by simpa using Nat.two_pow_pos z) (by decide) + exact apart (by rw [← privateTable]; apply UScalar.eq_of_val_eq; simp [core.num.U64.wrapping_add_val_eq]) + · have equal : root = p := by simpa [cap, MapV] using mapped + subst p + rcases unm with ⟨_, id, va, e⟩ | ⟨_, id, va, e⟩ + · have kind := sameKind rfl + simp [old, e, kindA] at kind + · exact different (h.capRefs.unique x ev.rootSlot y hy (2, root) + (by rw [old]; rfl) (by rw [e]; rfl) (by rw [old]; rfl)) + +set_option maxHeartbeats 3700000 in +/-- Every new reachable non-kernel table belongs to the assigned root. +All other exact backing and unmapped-object facts carry through the write. -/ +theorem S1aAssignWrite.lookup + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + (table : TabKeep st s q) (teHeap : TeH H (s1aAssignEpt tag root Te) + (s1aAssignRe tag root n Re) (s1aAssignBits tag root bits) n) : + VsLk st H OS Pp (s1aAssignTables tag root Tb) (s1aAssignEpt tag root Te) Kt + (s1aAssignLv tag root Lv) (s1aAssignRe tag root n Re) (s1aAssignBits tag root bits) q := by + refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ + · intro p reach _ nok + rcases ev.rawStage1 h heap kinds table reach with old | fresh + · obtain ⟨y, hy, map⟩ := h.core.lookup.bk1 p old (h.core.stage1.reachableMember old) nok + exact ⟨y, hy, ev.keepMapped hy map⟩ + · exact ⟨x, ev.rootSlot, (ev.stage1NewBacking h fresh nok).1⟩ + · intro p reach _ + rcases ev.rawStage2 h heap table reach with old | ⟨tg, eq⟩ + · obtain ⟨y, hy, map⟩ := h.core.lookup.bk2 p old (h.core.stage2.reachableMember old) + exact ⟨y, hy, ev.keepMapped hy map⟩ + · subst p + rcases ev.after with ⟨bad, _⟩ | ⟨_, va, cap⟩ | ⟨bad, _⟩ + · rw [tg] at bad + cases bad + · exact ⟨x, ev.rootSlot, Or.inr (Or.inr (Or.inr (Or.inr ⟨0#u64, asid, va, cap⟩)))⟩ + · rw [tg] at bad + cases bad + · exact fun p hp y hy named => h.core.lookup.kt p hp y hy ((ev.keepNames hy).mp named) + · intro y hy z hz p size unm mapped + obtain ⟨prior, different⟩ := ev.unmappedSource hy unm + by_cases here : z = x + · subst z + exact ev.noUnmappedOverlap h heap kinds hy different prior mapped + · exact h.core.lookup.ex y hy z hz p size prior (by simpa only [ev.write.other z hz here] using mapped) + · exact fun y hy p size cap o width al => ev.unmappedZero h heap kinds hy (ev.unmappedSource hy cap).1 width al + · refine ⟨?_, ?_, fun p _ hp => (teHeap p hp).1⟩ + · exact fun y hy p size cap => h.core.lookup.vh.1 y hy p size (ev.unmappedSource hy cap).1 + · intro p reach _ nok + rcases ev.rawStage1 h heap kinds table reach with old | fresh + · rcases h.core.lookup.vh.2.1 p old (h.core.stage1.reachableMember old) nok with object | high + · exact Or.inl object + · obtain ⟨r, obj, place, y, hy, a, cap⟩ := high + have different : y ≠ x := by + intro same + subst y + rcases ev.before with ⟨_, _, old⟩ | ⟨_, _, old⟩ | ⟨_, _, _, old⟩ <;> rw [old] at cap <;> cases cap + exact Or.inr ⟨r, obj, place, y, hy, a, (ev.write.other y hy different).trans cap⟩ + · exact (ev.stage1NewBacking h fresh nok).2 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignPaths.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignPaths.lean new file mode 100644 index 000000000..801d90b91 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignPaths.lean @@ -0,0 +1,181 @@ +/- +P1 (aarch64): Assign adds one empty active user root. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignRoot +import Fl4ProofsA64.P1.S1aR2Transport + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +theorem S1aAssignWrite.offObject + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {y p delta : U64} {size : Nat} (live : y ∈ OS) (object : H p = some (.other size)) + (key : RngKeyA (capA st s y)) (ptr : ptrA (capA st s y) = p) + (notPool : kindA (capA st s y) ≠ 21) (bound : delta.val < 2 ^ size) : + wa p delta ≠ wa pool off := by + obtain ⟨_, _, poolObj, slot, member, base, cap, _⟩ := + h.poolCaps.present index event.poolIndex pool event.poolLink event.poolNonzero + have distinct : p ≠ pool := by + intro eq + apply notPool + have kind := kinds.kind y live slot member key (cap ▸ RngKeyA.ap _ _) + (by rw [ptr, cap, ptrA_ap, eq]) + simpa only [cap, kindA] using kind + exact tableWordsNe heap object poolObj distinct bound event.offBound + +/-- Every live HighVSpace header word is disjoint from the selected pool write. -/ +theorem S1aAssignWrite.highHeader + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + (r : U64) (live : r ∈ Hr) (o : U64) (bound : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa r o) = L.mem s (wa r o) := by + have loc : PtW Pt (wa r o) := ⟨r, h.place.tables (h.place.high.sub live), o, bound, al, rfl⟩ + rw [h.highRoots] at live + obtain ⟨y, hy, m, a, cap⟩ := live + exact event.write.memory _ (Or.inl loc) (event.offObject h heap kinds hy (h.highObjects y hy r m a cap) + (cap ▸ RngKeyA.hv _ _ _) (by rw [cap, ptrA_hv]) (by simp [cap, kindA]) (by omega)) + +/-- Every previously active user descriptor is disjoint from the Assign pool write. -/ +theorem S1aAssignWrite.oldPathWord + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {k a t o : U64} {sh b : Nat} (path : S1aPath st Pp n s k a sh b t) + (bound : o.val < s1aTableWidth k n sh) (al : o.val % 8 = 0) : + L.mem q (wa t o) = L.mem s (wa t o) := + event.write.memory _ (Or.inl (h.pathWord path bound al)) + (h.pathWordOffPool heap kinds path bound event.poolLive event.offBound) + +/-- The Assign word has a root tag. Any table edge at an aligned VSpace word is kept. -/ +theorem S1aAssignWrite.edgeKept + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + {addr : U64} (loc : PtW Pt addr) (edge : L.mem q addr &&& 3#u64 = 3#u64) : + L.mem q addr = L.mem s addr := by + refine event.write.memory addr (Or.inl loc) fun same => ?_ + rw [same, event.write.descriptor, (event.value h heap).2] at edge + rcases event.before with ⟨eq, _⟩ | ⟨eq, _⟩ | ⟨eq, _⟩ <;> rw [eq] at edge <;> cases edge + +/-- The new entry and the old entries partition all post-Assign pool reads. -/ +theorem S1aAssignWrite.poolWord + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + {p o : U64} (live : p ∈ PoolSet st Pp s) (bound : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) ∨ L.mem q (wa p o) = root ||| tag := by + by_cases base : p = pool + · by_cases delta : o = off + · rw [base, delta] + exact Or.inr event.write.descriptor + · exact Or.inl (event.poolFrame h heap p live o bound al (Or.inr delta)) + · exact Or.inl (event.poolFrame h heap p live o bound al (Or.inl base)) + +/-- The new root's exact user address and table base, as used by the executable walk. -/ +def S1aAssignedPath (n root tag asid k a : U64) (sh b : Nat) (t : U64) : Prop := + k = tag ∧ a = asid ∧ sh = s1aTopShift tag n ∧ b = (if tag = 2#u64 then 2 ^ 64 - 2 ^ 39 else 0) ∧ + t = (if tag = 2#u64 then wa root 4096#u64 else root) + +/-- Assign publishes an empty table at the newly selected user root. -/ +theorem S1aAssignWrite.assignedEmpty + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {k a t o : U64} {sh b : Nat} (fresh : S1aAssignedPath n root tag asid k a sh b t) + (bound : o.val < s1aTableWidth k n sh) (al : o.val % 8 = 0) : + L.mem q (wa t o) = 0#u64 := by + obtain ⟨stage, id, level, _, base⟩ := fresh + subst k a sh t + have extent := lt_of_lt_of_le bound (s1aTableWidth.leStorage tag n (s1aTopShift tag n)) + have key := event.before.rangeKey + rcases event.before with ⟨rfl, id, cap⟩ | ⟨rfl, id, cap⟩ | ⟨rfl, id, va, cap⟩ + · have inside : o.val < 4096 := by simpa [s1aTableStorage] using extent + have nroot := h.nativeRoots x event.rootSlot root false id cap + have loc : PtW Pt (wa root o) := ⟨root, nroot.2, o, inside, al, rfl⟩ + have diff := event.offObject h heap kinds (delta := o) event.rootSlot nroot.1 key.1 key.2 (by simp [cap, kindA]) (by omega) + have old := h.capRefs.nativeEmpty x event.rootSlot root id cap o inside al + simpa only [show (0#u64 : U64) ≠ 2#u64 by decide, ite_false] using + (event.write.memory _ (Or.inl loc) diff).trans old + · have inside : o.val < 4096 := by simpa [s1aTableStorage] using extent + have live : root ∈ Hr := by rw [h.highRoots]; exact ⟨x, event.rootSlot, false, id, cap⟩ + have fits : (4096#u64 : U64).val + o.val < 2 ^ 64 := by change 4096 + o.val < 2 ^ 64; omega + have offset : (wa 4096#u64 o).val < 2 ^ 13 := by rw [wadd_val fits]; change 4096 + o.val < 2 ^ 13; omega + have loc : PtW Pt (wa (wa root 4096#u64) o) := + ⟨_, h.highFootprint ⟨root, live, Or.inr ⟨rfl, rfl⟩⟩, o, inside, al, rfl⟩ + have diff : wa (wa root 4096#u64) o ≠ wa pool off := by + rw [waddA_assoc root 4096#u64 o fits] + exact event.offObject h heap kinds event.rootSlot (h.highObjects x event.rootSlot root false id cap) + key.1 key.2 (by simp [cap, kindA]) offset + have old := h.capRefs.highEmpty x event.rootSlot root id cap o inside al + change L.mem q (wa (wa root 4096#u64) o) = 0#u64 + exact (event.write.memory _ (Or.inl loc) diff).trans old + · have inside : o.val < 8192 := by simpa [s1aTableStorage] using extent + obtain ⟨obj, granules⟩ := h.eptRoots x event.rootSlot root 0#u64 false id va cap + have loc := ptw_mono granules (ptwb_gran (fun _ _ => Or.inr rfl) + (show PtWb {root} (fun _ => 13) (wa root o) from ⟨root, Set.mem_singleton root, o, inside, al, rfl⟩)) + have diff := event.offObject h heap kinds (delta := o) event.rootSlot obj key.1 key.2 (by simp [cap, kindA]) (by omega) + have old := h.core.lookup.zr x event.rootSlot root 8192 (Or.inr ⟨rfl, id, va, cap⟩) o inside al + simpa only [show (1#u64 : U64) ≠ 2#u64 by decide, ite_false] using + (event.write.memory _ (Or.inl loc) diff).trans old + +set_option maxHeartbeats 3000000 in +/-- A post-Assign active path is an old path or the newly assigned user root. +The new root has no child edge. -/ +theorem S1aAssignWrite.pathCases + (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (named : PoolNamed st OS s) (kinds : KindA st OS s) (table : TabKeep st s q) + {k a t : U64} {sh b : Nat} (path : S1aPath st Pp n q k a sh b t) : + S1aPath st Pp n s k a sh b t ∨ S1aAssignedPath n root tag asid k a sh b t := by + obtain ⟨rootValue, tagValue⟩ := event.value h heap + have header (r : U64) (live : r ∈ Hr) := + event.highHeader h heap kinds r live 4088#u64 (by decide) (by decide) + induction path with + | @native a raw entry kind => + rcases event.entry h heap named table entry with prior | ⟨ids, rfl⟩ + · exact Or.inl (.native prior kind) + · have stage : tag = 0#u64 := tagValue.symm.trans kind + subst tag + rw [show (root ||| 0#u64) = root by apply UScalar.eq_of_val_eq; simp [UScalar.val_or]] + exact Or.inr ⟨rfl, ids, rfl, rfl, rfl⟩ + | @high a raw entry kind valid => + rcases event.entry h heap named table entry with prior | ⟨ids, rfl⟩ + · obtain ⟨y, hy, cap⟩ := h.core.root.backed a raw prior + rw [kind] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + have live : raw &&& ~~~3#u64 ∈ Hr := by rw [h.highRoots]; exact ⟨y, hy, true, a, cap⟩ + rw [header _ live] at valid ⊢ + exact Or.inl (.high prior kind valid) + · have stage : tag = 2#u64 := tagValue.symm.trans kind + subst tag + have live : root ∈ Hr := by + rw [h.highRoots] + rcases event.before with ⟨bad, _⟩ | ⟨_, id, cap⟩ | ⟨bad, _⟩ + · cases bad + · exact ⟨x, event.rootSlot, false, id, cap⟩ + · cases bad + rw [rootValue, header _ live, h.highLink root live] + exact Or.inr ⟨rfl, ids, rfl, rfl, rfl⟩ + | @stage2 a raw entry kind => + rcases event.entry h heap named table entry with prior | ⟨ids, rfl⟩ + · exact Or.inl (.stage2 prior kind) + · have stage : tag = 1#u64 := tagValue.symm.trans kind + subst tag + rw [rootValue] + exact Or.inr ⟨rfl, ids, rfl, rfl, rfl⟩ + | child _ depth width al range edge ih => + rcases ih with prior | added + · rw [event.oldPathWord h heap kinds prior width al] at edge ⊢ + exact Or.inl (.child prior depth width al range edge) + · rw [event.assignedEmpty h heap kinds added width al] at edge + cases edge + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignPlace.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignPlace.lean new file mode 100644 index 000000000..659fa13bc --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignPlace.lean @@ -0,0 +1,162 @@ +/- +P1 (aarch64): placement and exact path typing of an assigned root. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignStage1 + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +theorem S1aAssignWrite.stage2Placement + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) : + let Te' := s1aAssignEpt tag root Te + let bits' := s1aAssignBits tag root bits + Gran Te' bits' ⊆ Pt ∧ S2OK Te' bits' Hr ∧ TeH H Te' (s1aAssignRe tag root n Re) bits' n := by + by_cases stage : tag = 1#u64 + · have cap := ev.unmappedStage2 stage + obtain ⟨_, a, va, eq⟩ := cap.resolve_left (by rintro ⟨bad, _⟩; omega) + have ⟨object, placed⟩ := h.eptRoots x ev.rootSlot root 0#u64 false a va eq + simp only [s1aAssignEpt, s1aAssignRe, s1aAssignBits, if_pos stage] + refine ⟨?_, ⟨?_, ?_, ?_⟩, ?_⟩ + · rintro g ⟨p, hp, side⟩ + by_cases same : p = root + · subst p + rw [Function.update_self] at side + exact placed ⟨root, Set.mem_singleton root, side⟩ + · rcases side with here | ⟨size, next⟩ + · exact h.place.granules ⟨p, (Set.mem_insert_iff.mp hp).resolve_left same, Or.inl here⟩ + · rw [Function.update_of_ne same] at size + exact h.place.granules ⟨p, (Set.mem_insert_iff.mp hp).resolve_left same, Or.inr ⟨size, next⟩⟩ + · intro p hp + by_cases same : p = root + · simp [same] + · rw [Function.update_of_ne same] + exact h.place.stage2.sz p ((Set.mem_insert_iff.mp hp).resolve_left same) + · intro p hp + by_cases same : p = root + · subst p + rw [Function.update_self] + exact Nat.dvd_of_mod_eq_zero (heap.align root _ object) + · rw [Function.update_of_ne same] + exact h.place.stage2.al p ((Set.mem_insert_iff.mp hp).resolve_left same) + · rintro _ ⟨p, hp, o, width, al, rfl⟩ r hr + by_cases same : p = root + · subst p + rw [Function.update_self] at width + have capless := h.highRoots ▸ hr + obtain ⟨y, hy, m, id, c⟩ := capless + have high := h.highObjects y hy r m id c + have key := ev.before.rangeKey + have different : root ≠ r := by + intro same + have matchKind := kinds.kind x ev.rootSlot y hy key.1 (c ▸ RngKeyA.hv r m id) + (by rw [key.2, c, ptrA_hv, same]) + simp [eq, c, kindA] at matchKind + exact tableWordsNe heap object high different width (by decide) + · rw [Function.update_of_ne same] at width + exact h.place.stage2.hr _ ⟨p, (Set.mem_insert_iff.mp hp).resolve_left same, o, width, al, rfl⟩ r hr + · intro p hp + by_cases same : p = root + · subst p + rw [Function.update_self] + exact ⟨object, fun _ => rfl⟩ + · rw [Function.update_of_ne same, Function.update_of_ne same] + exact h.core.heap p ((Set.mem_insert_iff.mp hp).resolve_left same) + · simpa only [s1aAssignEpt, s1aAssignRe, s1aAssignBits, if_neg stage] using + ⟨h.place.granules, h.place.stage2, h.core.heap⟩ + +theorem S1aAssignWrite.stage1Placement + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) : + let Tb' := s1aAssignTables tag root Tb + let Lv' := s1aAssignLv tag root Lv + Tb' ⊆ Pt ∧ HrOK (L.ksb s) (PoolSet st Pp s) Tb' Lv' Hr := by + by_cases stage : tag = 0#u64 + · obtain ⟨a, cap⟩ := ev.nativeCap stage + obtain ⟨object, placed⟩ := h.nativeRoots x ev.rootSlot root false a cap + have high (r : U64) (live : r ∈ Hr) : H r = some (.other 13) := by + rw [h.highRoots] at live + obtain ⟨y, hy, m, id, cap⟩ := live + exact h.highObjects y hy r m id cap + have different (r : U64) (live : r ∈ Hr) : root ≠ r := by + intro eq + have obj := high r live + rw [← eq, object] at obj + cases obj + simp only [s1aAssignTables, s1aAssignLv, if_pos stage] + refine ⟨?_, ⟨fun _ live => Set.mem_insert_of_mem _ (h.place.high.sub live), ?_, ?_, h.place.high.pp, h.place.high.asw⟩⟩ + · intro p hp + exact (Set.mem_insert_iff.mp hp).elim (fun eq => eq.symm ▸ placed) (fun hp => h.place.tables hp) + · intro r live + rw [Function.update_of_ne (different r live).symm] + exact h.place.high.lv r live + · intro t ht o width al r live equal + rcases Set.mem_insert_iff.mp ht with eq | prior + · subst t + exact (tableWordsNe heap object (high r live) (different r live) width (by decide) equal).elim + · exact h.place.high.tb t prior o width al r live equal + · simpa only [s1aAssignTables, s1aAssignLv, if_neg stage] using ⟨h.place.tables, h.place.high⟩ + +set_option maxHeartbeats 3300000 in +theorem S1aAssignWrite.geometry + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (named : PoolNamed st OS s) (kinds : KindA st OS s) (table : TabKeep st s q) + (ty : VsTy st (L.ksb s) Pp Tb Lv s) + {k a t : U64} {sh b : Nat} (path : S1aPath st Pp n q k a sh b t) : + if k = 1#u64 then + t ∈ s1aAssignEpt tag root Te ∧ sh = 12 + 9 * s1aAssignRe tag root n Re t ∧ + s1aTableWidth k n sh ≤ 2 ^ s1aAssignBits tag root bits t + else t ∈ s1aAssignTables tag root Tb ∧ sh + 9 * s1aAssignLv tag root Lv t = 39 := by + rcases ev.pathCases h heap named kinds table path with old | fresh + · have typed := h.paths.tables k a sh b t old + by_cases stage : k = 1#u64 + · subst k + rw [if_pos rfl] at typed ⊢ + have reach := old.toStage2 fun sh' b' t' earlier => + (show _ ∧ _ ∧ _ from h.paths.tables 1#u64 a sh' b' t' earlier).2 + obtain ⟨m, depth, storage⟩ := ev.stage2KeepType h reach + rw [depth, storage] + exact ⟨m, typed.2⟩ + · rw [if_neg stage] at typed ⊢ + have priorDepth (sh' b' : Nat) (t' : U64) (earlier : S1aPath st Pp n s k a sh' b' t') : + sh' + 9 * Lv t' = 39 := by + have geom := h.paths.tables k a sh' b' t' earlier + rw [if_neg stage] at geom + exact geom.2 + have highDepth (id raw : U64) (entry : ActiveAsidRoot st Pp s id raw) (tg : raw &&& 3#u64 = 2#u64) : + Lv (raw &&& ~~~3#u64) = 0 := by + obtain ⟨_, o, _, width, al, _, p, hp, _, word, nz⟩ := entry + rw [← word] at tg ⊢ + exact ((h.core.stage1.pool p hp o width al (fun zero => nz (word ▸ zero))).2 tg).2 + have reach := old.toStage1 stage priorDepth highDepth + obtain ⟨m, depth⟩ := ev.stage1KeepType h heap kinds reach + rw [depth] + exact ⟨m, typed.2⟩ + · obtain ⟨stage, id, depth, _, base⟩ := fresh + subst k a sh t + rcases ev.before with ⟨tg, _⟩ | ⟨tg, _⟩ | ⟨tg, _⟩ + · subst tag + norm_num [s1aAssignTables, s1aAssignLv, s1aTopShift, + show (0#u64 : U64) ≠ 1#u64 by decide, show (0#u64 : U64) ≠ 2#u64 by decide] + · obtain ⟨member, level⟩ := ev.highChild h ty tg + simp [tg, s1aAssignTables, s1aAssignLv, s1aTopShift, member, level] + · subst tag + have width := s1aTableWidth.leStorage 1#u64 n (s1aTopShift 1#u64 n) + simp only [s1aTableStorage, and_self, ite_true] at width + have top : s1aTopShift 1#u64 n = 12 + 9 * (s2lv n - 1) := by + simp only [s1aTopShift, s2lv, show (1#u64 : U64) ≠ 0#u64 by decide, + show (1#u64 : U64) ≠ 2#u64 by decide, ite_false] + split <;> decide + simpa [s1aAssignEpt, s1aAssignRe, s1aAssignBits, top] using width + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignPost.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignPost.lean new file mode 100644 index 000000000..ee821d178 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignPost.lean @@ -0,0 +1,135 @@ +/- +P1 (aarch64): full R2 preservation at the concrete ASIDPool Assign dispatcher. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignLookup + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +set_option maxHeartbeats 3700000 in +/-- Assign grows the selected table witnesses on the original heap, slots and footprint. -/ +theorem S1aR2.ofAssign + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (heap : HeapOK H) (named : PoolNamed st OS s) (kinds : KindA st OS s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) : + ∃ Tb' Te' Lv' Re' bits', S1aR2 st H OS Pt Pp Tb' Hr Te' Kt Lv' Re' bits' n q := by + let Tb' := s1aAssignTables tag root Tb + let Te' := s1aAssignEpt tag root Te + let Lv' := s1aAssignLv tag root Lv + let Re' := s1aAssignRe tag root n Re + let bits' := s1aAssignBits tag root bits + refine ⟨Tb', Te', Lv', Re', bits', ?_⟩ + have tab := ev.table h ptKs + obtain ⟨granules, size, typedHeap⟩ := ev.stage2Placement h heap kinds + obtain ⟨tables, highPlace⟩ := ev.stage1Placement h heap + have lookup := ev.lookup h heap kinds tab typedHeap + have agree := ev.rootAgreement h heap named kinds tab + have exactPaths : S1aPathBacking st H OS Pp Tb' Te' Lv' Re' bits' n q := + ev.pathBacking h heap named kinds tab (fun _ _ _ _ _ => ev.geometry h heap named kinds tab W.ty.1) + have highSet : Hr = HvRt st OS q := h.highRoots.trans ev.highSet + have header p (live : p ∈ Hr) : L.mem q (wa p 4088#u64) = L.mem s (wa p 4088#u64) := + ev.highHeader h heap kinds p live 4088#u64 (by decide) (by decide) + have highObj : HvObjects st H OS q := by + intro y hy p m a cap + obtain ⟨oldM, oldA, prior⟩ := ev.highSource hy cap + exact h.highObjects y hy p oldM oldA prior + have ept : EptPlaced st H OS Pt q := by + intro y hy p l m a v cap + obtain ⟨oldM, oldA, oldV, prior⟩ := ev.eptSource hy cap + exact h.eptRoots y hy p l oldM oldA oldV prior + have kernelMember : Kt ⊆ Tb' := by + intro t ht + have member := h.kernelTables.1 ht + dsimp [Tb', s1aAssignTables] + split + · exact Set.mem_insert_of_mem _ member + · exact member + have closed t (ht : t ∈ Kt) (depth : Lv' t < 3) (o : U64) (width : o.val < 4096) (al : o.val % 8 = 0) + (edge : L.mem q (wa t o) &&& 3#u64 = 3#u64) : + wa (L.mem q (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + have level : Lv' t = Lv t := by + dsimp [Lv', s1aAssignLv] + split + · rename_i stage + apply Function.update_of_ne + intro eq + obtain ⟨a, cap⟩ := ev.nativeCap stage + exact h.core.lookup.kt t ht x ev.rootSlot (Or.inr (Or.inl ⟨false, a, eq.symm ▸ cap⟩)) + · rfl + rw [level] at depth + have loc : PtW Pt (wa t o) := ⟨t, h.place.tables (h.kernelTables.1 ht), o, width, al, rfl⟩ + have kept := ev.edgeKept h heap loc edge + rw [kept] at edge ⊢ + exact h.kernelClosed t ht depth o width al edge + have routes : S1aRouteFacts st H OS Pt Pp Tb' Hr Te' Kt Lv' Re' bits' n q := + ⟨lookup, agree, typedHeap, exactPaths, ev.tableCaps h heap kinds, ev.rootSlots h heap kinds, highSet, + (fun p live => by rw [header p live]; exact h.highLink p live), highObj, ept, + (fun y hy p m a v cap => h.pageObjects y hy p m a v ((ev.pageTableIff hy).mp cap)), closed⟩ + exact { + core := ⟨lookup, routes.recoverWalk heap (ev.kindPost kinds), agree, + ev.stage1Typing h heap kinds tab W.ty.1, ev.stage2Typing h heap kinds tab, typedHeap⟩ + place := by rw [tab.1, tab.poolSet_eq]; exact ⟨h.place.pools, tables, granules, highPlace, size⟩ + poolCaps := ev.poolCaps h heap named tab + capRefs := routes.capRefs + paths := exactPaths + pageTables := fun y hy p m a v cap => h.pageTables y hy p m a v ((ev.pageTableIff hy).mp cap) + footprint := h.footprint + pageObjects := routes.pageObjects + nativeRoots := fun y hy p m a cap => by + obtain ⟨oldM, oldA, prior⟩ := ev.nativeSource hy cap + exact h.nativeRoots y hy p oldM oldA prior + eptRoots := ept + highObjects := highObj + highHeaders := fun y hy p m a cap => by + have member : p ∈ Hr := by rw [highSet]; exact ⟨y, hy, m, a, cap⟩ + rw [header p member] + exact h.core.stage2.hi p member + highLink := routes.highLink + highRoots := highSet + highFootprint := h.highFootprint + kernelTables := ⟨kernelMember, h.kernelTables.2⟩ + kernelClosed := closed + rootSlots := routes.rootSlots } + +section dispatch + +variable {A : Type _} {ar : machine.Arch A} {Cs Vc Ub U Ac Rp Nt : Set U64} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot base : U64} + +/-- The concrete Assign dispatch preserves R2 on all outcomes, using the existing HighVSpace typing. -/ +theorem syscall.decode_invocation.assignExactR2 + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits n s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.AsidPool pool base) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (src : obj.Slot.cap st slot s = ok (.AsidPool pool base)) + (named : PoolNamed st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMASIDPoolAssign len slot + (.AsidPool pool base) blk call don fp buf extra ⦃ _ q _ => + ∃ Tb' Te' Lv' Re' bits', S1aR2 st H OS Pt Pp Tb' Hr Te' Kt Lv' Re' bits' n q ⦄ := by + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono (vspace.decode.assignExactWrite h vr D P src a len buf call) ?_ + rintro ⟨_, q, _⟩ (reject | ⟨x, root, tag, asid, index, off, ev⟩) + · change q = s at reject + subst q + exact ⟨Tb, Te, Lv, Re, bits, h⟩ + · exact h.ofAssign W P.heap named kinds ptKs ev + +end dispatch + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignRoot.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignRoot.lean new file mode 100644 index 000000000..9421caddf --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignRoot.lean @@ -0,0 +1,133 @@ +/- +P1 (aarch64): ASID-pool and cap agreement through the exact Assign write. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignWrite +import Fl4ProofsA64.P1.S1aR2UnmapRoute + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +theorem assignNativeKey (p : U64) (m : Bool) (a : U64) : + RngKeyA (.Pml4 p m a) ∧ ptrA (.Pml4 p m a) = p := + ⟨⟨(okinj (physA_eq (.Pml4 p m a))).symm, rfl, rfl⟩, (okinj (ptrA_eq (.Pml4 p m a))).symm⟩ + +theorem S1aUnassignedRoot.rangeKey {c : capability.Cap} {p k : U64} + (h : S1aUnassignedRoot c p k) : RngKeyA c ∧ ptrA c = p := by + rcases h with ⟨_, a, rfl⟩ | ⟨_, a, rfl⟩ | ⟨_, a, v, rfl⟩ + · exact assignNativeKey p false a + · exact ⟨RngKeyA.hv p false a, ptrA_hv p false a⟩ + · exact ⟨RngKeyA.ept p 0#u64 false a v, ptrA_ept p 0#u64 false a v⟩ + +private theorem MappedAsidRoot.assignRangeKey {c : capability.Cap} {p a k : U64} + (h : MappedAsidRoot c p a k) : RngKeyA c ∧ ptrA c = p := by + rcases h with ⟨_, rfl⟩ | ⟨_, v, rfl⟩ | ⟨_, rfl⟩ + · exact assignNativeKey p true a + · exact ⟨RngKeyA.ept p 0#u64 true a v, ptrA_ept p 0#u64 true a v⟩ + · exact ⟨RngKeyA.hv p true a, ptrA_hv p true a⟩ + +/-- An unassigned root cannot have a live mapped peer at its physical base. -/ +theorem S1aAssignWrite.fresh (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (refs : S1aTableCaps st OS s) (kinds : KindA st OS s) : + ∀ y ∈ OS, ∀ a k, ¬ MappedAsidRoot (capA st s y) root a k := by + intro y hy a k candidate + have left := event.before.rangeKey + have right := candidate.assignRangeKey + have kind := kinds.kind x event.rootSlot y hy left.1 right.1 (left.2.trans right.2.symm) + rcases event.before with ⟨_, i, hx⟩ | ⟨_, i, hx⟩ | ⟨_, i, v, hx⟩ <;> + rcases candidate with ⟨_, eq⟩ | ⟨_, va, eq⟩ | ⟨_, eq⟩ <;> + simp only [hx, eq, kindA] at kind + all_goals try omega + all_goals + have linked := refs.references x event.rootSlot y hy _ + (by rw [hx]; rfl) (by rw [eq]; rfl) + rw [hx, eq] at linked + cases linked + +theorem S1aAssignWrite.value (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) : + (root ||| tag) &&& ~~~3#u64 = root ∧ (root ||| tag) &&& 3#u64 = tag := by + have rootAl : root.val % 4 = 0 := by + have big : root.val % 4096 = 0 := by + rcases event.before with ⟨_, a, cap⟩ | ⟨_, a, cap⟩ | ⟨_, a, v, cap⟩ + · exact (h.footprint root (h.nativeRoots x event.rootSlot root false a cap).2).1 + · have exactHeap := h.highObjects x event.rootSlot root false a cap + have aligned := heap.align root _ exactHeap + simp only [HKind.bits] at aligned + omega + · have exactHeap := (h.eptRoots x event.rootSlot root 0#u64 false a v cap).1 + have aligned := heap.align root _ exactHeap + simp only [HKind.bits] at aligned + omega + omega + have low : tag &&& 3#u64 = tag := by + rcases event.before with ⟨rfl, _⟩ | ⟨rfl, _⟩ | ⟨rfl, _⟩ <;> decide + have baseClear := mask_of_aligned rootAl + exact ⟨by simpa only [baseClear, low] using ts_end root tag, + by simpa only [baseClear, low] using ts_state root tag⟩ + +theorem S1aAssignWrite.table (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) : TabKeep st s q := by + have loc : PtW Pt (wa pool off) := + ⟨pool, h.place.pools event.poolLive, off, event.offBound, event.offAligned, rfl⟩ + refine ⟨event.write.base, fun i => ?_⟩ + rw [event.write.base] + exact event.write.memory _ (Or.inr (asW_at _ i)) (fun eq => ptKs _ loc (eq ▸ asW_at _ i)) + +/-- Every other pool word agrees with its old value, including a different +offset of the assigned pool. -/ +theorem S1aAssignWrite.poolFrame (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (p : U64) (live : p ∈ PoolSet st Pp s) (o : U64) (bound : o.val < 4096) + (aligned : o.val % 8 = 0) (different : p ≠ pool ∨ o ≠ off) : + L.mem q (wa p o) = L.mem s (wa p o) := by + have pPt := h.place.pools live + have poolPt := h.place.pools event.poolLive + refine event.write.memory _ (Or.inl ⟨p, pPt, o, bound, aligned, rfl⟩) fun eq => ?_ + have pFine := (h.footprint p pPt).1 + have poolFine := (h.footprint pool poolPt).1 + have pFit := h.footprint.fit heap p pPt + have poolFit := h.footprint.fit heap pool poolPt + have offFits := event.offBound + have values := congrArg UScalar.val eq + rw [wadd_val (by omega : p.val + o.val < 2 ^ 64), + wadd_val (by omega : pool.val + off.val < 2 ^ 64)] at values + have hNat : p.val = pool.val ∧ o.val = off.val := by omega + exact different.elim (fun h => h (UScalar.eq_of_val_eq hNat.1)) (fun h => h (UScalar.eq_of_val_eq hNat.2)) + +/-- The exact successor either retains a previous active entry or selects the +newly assigned ASID and root. -/ +theorem S1aAssignWrite.entry (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (named : PoolNamed st OS s) + (table : TabKeep st s q) {a raw : U64} (next : ActiveAsidRoot st Pp q a raw) : + ActiveAsidRoot st Pp s a raw ∨ a = asid ∧ raw = root ||| tag := by + rcases next.replaceWord h.poolCaps.toIdx named table event.poolIndex event.poolNonzero event.poolLink + event.write.descriptor (event.poolFrame h heap) with keep | ⟨address, raw⟩ + · exact Or.inl keep + · exact Or.inr ⟨UScalar.eq_of_val_eq (address.trans event.asidValue.symm), raw⟩ + +theorem S1aAssignWrite.rootAgreement (event : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (named : PoolNamed st OS s) + (kinds : KindA st OS s) (table : TabKeep st s q) : RootAgreement st OS Pp q := by + have ⟨rootValue, tagValue⟩ := event.value h heap + refine h.core.root.assignWord h.poolCaps.toIdx named table event.rootSlot event.poolIndex + event.poolNonzero event.poolLink event.asidValue event.write.descriptor (event.poolFrame h heap) event.write.other + ?_ ?_ ?_ + · intro p a k candidate + rcases event.before with ⟨_, id, cap⟩ | ⟨_, id, cap⟩ | ⟨_, id, v, cap⟩ <;> + rw [cap] at candidate <;> rcases candidate with ⟨_, bad⟩ | ⟨_, _, bad⟩ | ⟨_, bad⟩ <;> cases bad + · rw [rootValue] + exact event.fresh h.capRefs kinds + · rw [rootValue, tagValue] + exact event.after + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignStage1.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignStage1.lean new file mode 100644 index 000000000..dd64a8185 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignStage1.lean @@ -0,0 +1,259 @@ +/- +P1 (aarch64): the Native and HighVSpace raw graph after ASIDPool Assign. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignStage2 +import Fl4ProofsA64.P1.S1aHiDel + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +/-- Only a native Assign needs a new Stage-1 table witness. The all-live +HighVSpace header and its private L1 already have their exact levels. -/ +def s1aAssignTables (tag root : U64) (Tb : Set U64) : Set U64 := + if tag = 0#u64 then insert root Tb else Tb + +def s1aAssignLv (tag root : U64) (Lv : U64 → Nat) : U64 → Nat := + if tag = 0#u64 then Function.update Lv root 0 else Lv + +theorem S1aAssignWrite.nativeCap + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) (tg : tag = 0#u64) : + ∃ a, capA st s x = .Pml4 root false a := by + rcases ev.before with ⟨_, a, cap⟩ | ⟨eq, _⟩ | ⟨eq, _⟩ + · exact ⟨a, cap⟩ + · rw [tg] at eq + cases eq + · rw [tg] at eq + cases eq + +theorem S1aAssignWrite.highCap + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) (tg : tag = 2#u64) : + ∃ a, capA st s x = .HighVSpace root false a := by + rcases ev.before with ⟨eq, _⟩ | ⟨_, a, cap⟩ | ⟨eq, _⟩ + · rw [tg] at eq + cases eq + · exact ⟨a, cap⟩ + · rw [tg] at eq + cases eq + +private theorem S1aAssignWrite.nativeNotKernel + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (tg : tag = 0#u64) : root ∉ Kt := by + obtain ⟨a, cap⟩ := ev.nativeCap tg + exact fun member => h.core.lookup.kt root member x ev.rootSlot (Or.inr (Or.inl ⟨false, a, cap⟩)) + +private theorem S1aAssignWrite.nativeNotBacked + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (kinds : KindA st OS s) (tg : tag = 0#u64) + {y : U64} (hy : y ∈ OS) (backed : MapV (capA st s y) root) : False := by + obtain ⟨a, cap⟩ := ev.nativeCap tg + have own := (h.nativeRoots x ev.rootSlot root false a cap).1 + have key := ev.before.rangeKey + have sameKind (k : RngKeyA (capA st s y)) (p : ptrA (capA st s y) = root) : + kindA (capA st s y) = 17 := by + have equal := kinds.kind y hy x ev.rootSlot k key.1 (p.trans key.2.symm) + simpa [cap, kindA] using equal + rcases backed with ⟨b, va, table⟩ | ⟨b, native⟩ | ⟨b, high⟩ | ⟨r, b, high, place⟩ | ⟨lev, b, va, ept⟩ + · have eq := sameKind (table ▸ RngKeyA.pt _ _ _ _) (table ▸ ptrA_pt _ _ _ _) + simp [table, kindA] at eq + · exact ev.fresh h.capRefs kinds y hy b 0#u64 (Or.inl ⟨rfl, native⟩) + · have obj := h.highObjects y hy root true b high + rw [own] at obj + cases obj + · have obj := h.highObjects y hy r true b high + have ne : root ≠ r := by + rintro rfl + rw [own] at obj + cases obj + have apart := tableWordsNe heap own obj (o := 0#u64) (o' := 4096#u64) ne (by decide) (by decide) + exact apart (by rw [place]; apply UScalar.eq_of_val_eq; simp [core.num.U64.wrapping_add_val_eq]) + · have eq := sameKind (ept ▸ RngKeyA.ept _ _ _ _ _) (ept ▸ ptrA_ept _ _ _ _ _) + simp [ept, kindA] at eq + +theorem S1aAssignWrite.stage1KeepType + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {p : U64} (old : VsReach st (PoolSet st Pp s) ∅ Lv s p) : + p ∈ s1aAssignTables tag root Tb ∧ s1aAssignLv tag root Lv p = Lv p := by + have prior := h.core.stage1.reachableMember old + by_cases tg : tag = 0#u64 + · have different : p ≠ root := by + intro eq + subst p + obtain ⟨y, hy, backed⟩ := h.core.lookup.bk1 root old prior (ev.nativeNotKernel h tg) + exact ev.nativeNotBacked h heap kinds tg hy backed + simp [s1aAssignTables, s1aAssignLv, tg, Function.update_of_ne different, prior] + · simp [s1aAssignTables, s1aAssignLv, tg, prior] + +theorem S1aAssignWrite.highMember + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (tg : tag = 2#u64) : root ∈ Hr := by + obtain ⟨a, cap⟩ := ev.highCap tg + rw [h.highRoots] + exact ⟨x, ev.rootSlot, false, a, cap⟩ + +/-- The existing typing of the all-live header fixes the depth of its private table. -/ +theorem S1aAssignWrite.highChild + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (ty : VsTy st (L.ksb s) Pp Tb Lv s) (tg : tag = 2#u64) : + wa root 4096#u64 ∈ Tb ∧ Lv (wa root 4096#u64) = 1 := by + have member := ev.highMember h tg + have level := h.place.high.lv root member + have edge := h.core.stage2.hi root member + have child := ty.desc root (h.place.high.sub member) (by omega) 4088#u64 (by decide) (by decide) edge + simpa only [h.highLink root member, level, Nat.zero_add] using child + +/-- The raw graph gains the assigned root and, for HighVSpace, its private L1 +and any newly reachable copied kernel tables. -/ +def S1aAssignRawStage1 (tag root : U64) (Kt : Set U64) (p : U64) : Prop := + (tag = 0#u64 ∧ p = root) ∨ + (tag = 2#u64 ∧ (p = root ∨ p = wa root 4096#u64 ∨ p ∈ Kt)) + +theorem S1aAssignWrite.nativeNoEdge + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (tg : tag = 0#u64) + {o : U64} (width : o.val < 4096) (al : o.val % 8 = 0) + (edge : L.mem q (wa root o) &&& 3#u64 = 3#u64) : False := by + obtain ⟨a, cap⟩ := ev.nativeCap tg + have loc : PtW Pt (wa root o) := ⟨root, (h.nativeRoots x ev.rootSlot root false a cap).2, o, width, al, rfl⟩ + rw [ev.edgeKept h heap loc edge, h.capRefs.nativeEmpty x ev.rootSlot root a cap o width al] at edge + cases edge + +private theorem S1aAssignWrite.highPrivateNoEdge + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (tg : tag = 2#u64) + {o : U64} (width : o.val < 4096) (al : o.val % 8 = 0) + (edge : L.mem q (wa (wa root 4096#u64) o) &&& 3#u64 = 3#u64) : False := by + obtain ⟨a, cap⟩ := ev.highCap tg + have loc : PtW Pt (wa (wa root 4096#u64) o) := + ⟨_, h.highFootprint ⟨root, ev.highMember h tg, Or.inr ⟨rfl, rfl⟩⟩, o, width, al, rfl⟩ + rw [ev.edgeKept h heap loc edge, h.capRefs.highEmpty x ev.rootSlot root a cap o width al] at edge + cases edge + +set_option maxHeartbeats 3500000 in +theorem S1aAssignWrite.rawStage1 + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (kinds : KindA st OS s) (table : TabKeep st s q) + {p : U64} (reach : VsReach st (PoolSet st Pp q) ∅ (s1aAssignLv tag root Lv) q p) : + VsReach st (PoolSet st Pp s) ∅ Lv s p ∨ S1aAssignRawStage1 tag root Kt p := by + have ⟨value, low⟩ := ev.value h heap + induction reach with + | hr live => exact (Set.notMem_empty _ live).elim + | @root0 p o live width al nz kind => + rw [table.poolSet_eq] at live + rcases ev.poolWord h heap live width al with old | added + · rw [old] at nz kind ⊢ + exact Or.inl (.root0 live width al nz kind) + · rw [added, low] at kind + rw [added, kind, show root ||| 0#u64 = root by apply UScalar.eq_of_val_eq; simp [UScalar.val_or]] + exact Or.inr (Or.inl ⟨rfl, rfl⟩) + | @root2 p o live width al kind => + rw [table.poolSet_eq] at live + rcases ev.poolWord h heap live width al with old | added + · rw [old] at kind ⊢ + exact Or.inl (.root2 live width al kind) + · rw [added, low] at kind + rw [added, value] + exact Or.inr (Or.inr ⟨kind, Or.inl rfl⟩) + | @step p o _ level width al edge ih => + rcases ih with old | ⟨tg, native⟩ | ⟨tg, header | privateTable | kernel⟩ + · have placed := h.place.tables (h.core.stage1.reachableMember old) + have kept := ev.edgeKept h heap (⟨p, placed, o, width, al, rfl⟩ : PtW Pt (wa p o)) edge + rw [(ev.stage1KeepType h heap kinds old).2] at level + rw [kept] at edge ⊢ + exact Or.inl (.step old level width al edge) + · subst p + exact (ev.nativeNoEdge h heap tg width al edge).elim + · subst p + obtain ⟨a, cap⟩ := ev.highCap tg + rw [ev.highHeader h heap kinds root (ev.highMember h tg) o width al] at edge ⊢ + by_cases copies : o.val < 4088 + · exact Or.inr (Or.inr ⟨tg, Or.inr (Or.inr (h.rootSlots.highCopies x ev.rootSlot root false a cap o copies al edge))⟩) + · have last : o = 4088#u64 := UScalar.eq_of_val_eq (by change o.val = 4088; omega) + rw [last, h.highLink root (ev.highMember h tg)] + exact Or.inr (Or.inr ⟨tg, Or.inr (Or.inl rfl)⟩) + · subst p + exact (ev.highPrivateNoEdge h heap tg width al edge).elim + · have placed := h.place.tables (h.kernelTables.1 kernel) + have kept := ev.edgeKept h heap (⟨p, placed, o, width, al, rfl⟩ : PtW Pt (wa p o)) edge + rw [kept] at edge ⊢ + have depth : Lv p < 3 := by + simpa only [s1aAssignLv, tg, show (2#u64 : U64) ≠ 0#u64 by decide, ite_false] using level + exact Or.inr (Or.inr ⟨tg, Or.inr (Or.inr (h.kernelClosed p kernel depth o width al edge))⟩) + +theorem S1aAssignWrite.stage1RootTyping + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + {p o : U64} (live : p ∈ PoolSet st Pp s) (width : o.val < 4096) (al : o.val % 8 = 0) + (nz : L.mem q (wa p o) ≠ 0#u64) : + ((L.mem q (wa p o) &&& 3#u64) = 0#u64 → + L.mem q (wa p o) ∈ s1aAssignTables tag root Tb ∧ + s1aAssignLv tag root Lv (L.mem q (wa p o)) = 0) ∧ + ((L.mem q (wa p o) &&& 3#u64) = 2#u64 → + (L.mem q (wa p o) &&& ~~~3#u64) ∈ s1aAssignTables tag root Tb ∧ + s1aAssignLv tag root Lv (L.mem q (wa p o) &&& ~~~3#u64) = 0) := by + rcases ev.poolWord h heap live width al with old | added + · rw [old] at nz ⊢ + obtain ⟨native, high⟩ := h.core.stage1.pool p live o width al nz + refine ⟨fun tg => ?_, fun tg => ?_⟩ + · obtain ⟨member, same⟩ := ev.stage1KeepType h heap kinds (.root0 live width al nz tg) + exact ⟨member, same.trans (native tg).2⟩ + · obtain ⟨member, same⟩ := ev.stage1KeepType h heap kinds (.root2 live width al tg) + exact ⟨member, same.trans (high tg).2⟩ + · have ⟨value, low⟩ := ev.value h heap + rw [added, value, low] + refine ⟨fun tg => ?_, fun tg => ?_⟩ + · rw [tg, show root ||| 0#u64 = root by apply UScalar.eq_of_val_eq; simp [UScalar.val_or]] + simp [s1aAssignTables, s1aAssignLv, tg] + · have member := ev.highMember h tg + simpa [s1aAssignTables, s1aAssignLv, tg] using ⟨h.place.high.sub member, h.place.high.lv root member⟩ + +set_option maxHeartbeats 3500000 in +/-- The narrowed Stage-1 typing at the same post state as the exact Assign write. -/ +theorem S1aAssignWrite.stage1Typing + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + (table : TabKeep st s q) (ty : VsTy st (L.ksb s) Pp Tb Lv s) : + VsTyR st (L.ksb q) (PoolSet st Pp q) ∅ (s1aAssignTables tag root Tb) (s1aAssignLv tag root Lv) q := by + refine ⟨?_, ?_, ?_⟩ + · intro o lo hi al nz + have kept := table.off lo hi al + rw [kept] at nz ⊢ + exact table.poolSet_eq.symm ▸ h.core.stage1.tbl o lo hi al nz + · intro p live o width al nz + rw [table.poolSet_eq] at live + exact ev.stage1RootTyping h heap kinds live width al nz + · intro p member path level o width al edge + rcases ev.rawStage1 h heap kinds table path with prior | ⟨tg, rfl⟩ | ⟨tg, _⟩ + · have priorMember := h.core.stage1.reachableMember prior + have loc : PtW Pt (wa p o) := ⟨p, h.place.tables priorMember, o, width, al, rfl⟩ + have kept := ev.edgeKept h heap loc edge + rw [(ev.stage1KeepType h heap kinds prior).2] at level + have parentDepth := (ev.stage1KeepType h heap kinds prior).2 + rw [parentDepth] + rw [kept] at edge ⊢ + obtain ⟨child, same⟩ := ev.stage1KeepType h heap kinds (.step prior level width al edge) + exact ⟨child, same.trans (h.core.stage1.desc p priorMember prior level o width al edge).2⟩ + · exact (ev.nativeNoEdge h heap tg width al edge).elim + · have unchanged : s1aAssignLv tag root Lv = Lv := by simp [s1aAssignLv, tg] + have sameTables : s1aAssignTables tag root Tb = Tb := by simp [s1aAssignTables, tg] + rw [sameTables] at member + rw [unchanged] at level + have loc : PtW Pt (wa p o) := ⟨p, h.place.tables member, o, width, al, rfl⟩ + have kept := ev.edgeKept h heap loc edge + rw [kept] at edge + rw [kept, unchanged, sameTables] + exact ty.desc p member level o width al edge + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignStage2.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignStage2.lean new file mode 100644 index 000000000..c76b1449b --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignStage2.lean @@ -0,0 +1,166 @@ +/- +P1 (aarch64): raw Stage-2 reachability and typing across ASIDPool Assign. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AssignCaps +import Fl4ProofsA64.P1.S1aR2MapReach + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {pool x root tag asid index off : U64} + +/-- The Stage-2 witnesses grow only for a Stage-2 root publication. -/ +def s1aAssignEpt (tag root : U64) (Te : Set U64) : Set U64 := + if tag = 1#u64 then insert root Te else Te + +def s1aAssignRe (tag root n : U64) (Re : U64 → Nat) : U64 → Nat := + if tag = 1#u64 then Function.update Re root (s2lv n - 1) else Re + +def s1aAssignBits (tag root : U64) (bits : U64 → Nat) : U64 → Nat := + if tag = 1#u64 then Function.update bits root 13 else bits + +theorem S1aAssignWrite.unmappedStage2 + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) (tg : tag = 1#u64) : + UnmCap (capA st s x) root 8192 := by + rcases ev.before with ⟨eq, _⟩ | ⟨eq, _⟩ | ⟨_, a, va, cap⟩ + · rw [tg] at eq + cases eq + · rw [tg] at eq + cases eq + · exact Or.inr ⟨rfl, a, va, cap⟩ + +theorem S1aAssignWrite.stage2KeepType + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {p : U64} (old : S2Reach st (PoolSet st Pp s) Re bits s p) : + p ∈ s1aAssignEpt tag root Te ∧ s1aAssignRe tag root n Re p = Re p ∧ + s1aAssignBits tag root bits p = bits p := by + have prior := h.core.stage2.reachableMember old + by_cases tg : tag = 1#u64 + · have different : p ≠ root := by + rintro rfl + exact h.core.lookup.unmR2 ev.rootSlot (ev.unmappedStage2 tg) ⟨prior, old⟩ + simp [s1aAssignEpt, s1aAssignRe, s1aAssignBits, tg, Function.update_of_ne different, prior] + · simp [s1aAssignEpt, s1aAssignRe, s1aAssignBits, tg, prior] + +private theorem S1aAssignWrite.stage2RootNoEdge + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (tg : tag = 1#u64) {o : U64} (width : o.val < 2 ^ s1aAssignBits tag root bits root) + (al : o.val % 8 = 0) (edge : L.mem q (wa root o) &&& 3#u64 = 3#u64) : False := by + have size : s1aAssignBits tag root bits root = 13 := by simp [s1aAssignBits, tg] + rw [size] at width + have cap := ev.unmappedStage2 tg + obtain ⟨_, a, va, eq⟩ := cap.resolve_left (by rintro ⟨bad, _⟩; omega) + have loc := ptw_mono (h.eptRoots x ev.rootSlot root 0#u64 false a va eq).2 + (ptwb_gran (fun _ _ => Or.inr rfl) + (show PtWb {root} (fun _ => 13) (wa root o) from ⟨root, Set.mem_singleton root, o, width, al, rfl⟩)) + rw [ev.edgeKept h heap loc edge, h.core.lookup.zr x ev.rootSlot root 8192 cap o width al] at edge + cases edge + +set_option maxHeartbeats 2900000 in +/-- Raw IPA reach can gain only the assigned root, whose words were zero. -/ +theorem S1aAssignWrite.rawStage2 + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (table : TabKeep st s q) + {p : U64} (reach : S2Reach st (PoolSet st Pp q) (s1aAssignRe tag root n Re) (s1aAssignBits tag root bits) q p) : + S2Reach st (PoolSet st Pp s) Re bits s p ∨ tag = 1#u64 ∧ p = root := by + have ⟨value, low⟩ := ev.value h heap + induction reach with + | @root p o live width al kind => + rw [table.poolSet_eq] at live + rcases ev.poolWord h heap live width al with old | added + · rw [old] at kind ⊢ + exact Or.inl (.root live width al kind) + · rw [added, value] + rw [added, low] at kind + exact Or.inr ⟨kind, rfl⟩ + | @step p o _ level width al edge ih => + rcases ih with old | ⟨tg, rfl⟩ + · obtain ⟨_, depth, size⟩ := ev.stage2KeepType h old + rw [depth] at level + rw [size] at width + have loc := ptw_mono h.place.granules + (ptwb_gran h.place.stage2.sz ⟨p, h.core.stage2.reachableMember old, o, width, al, rfl⟩) + have kept := ev.edgeKept h heap loc edge + rw [kept] at edge ⊢ + exact Or.inl (.step old level width al edge) + · exact (ev.stage2RootNoEdge h heap tg width al edge).elim + +private theorem S1aAssignWrite.stage2RootTyping + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + {p o : U64} (live : p ∈ PoolSet st Pp s) (width : o.val < 4096) (al : o.val % 8 = 0) + (nz : L.mem q (wa p o) ≠ 0#u64) : + ((L.mem q (wa p o) &&& 3#u64) = 0#u64 ∧ L.mem q (wa p o) ∉ Hr) ∨ + ((L.mem q (wa p o) &&& 3#u64) = 2#u64 ∧ (L.mem q (wa p o) &&& ~~~3#u64) ∈ Hr) ∨ + ((L.mem q (wa p o) &&& 3#u64) = 1#u64 ∧ + (L.mem q (wa p o) &&& ~~~3#u64) ∈ s1aAssignEpt tag root Te ∧ + s1aAssignRe tag root n Re (L.mem q (wa p o) &&& ~~~3#u64) + 1 = s2lv n ∧ + s2rb n ≤ s1aAssignBits tag root bits (L.mem q (wa p o) &&& ~~~3#u64)) := by + rcases ev.poolWord h heap live width al with old | added + · rw [old] at nz ⊢ + rcases h.core.stage2.tag p live o width al nz with native | high | ⟨stage, _, depth, size⟩ + · exact Or.inl native + · exact Or.inr (Or.inl high) + · obtain ⟨member, sameDepth, sameSize⟩ := ev.stage2KeepType h (.root live width al stage) + exact Or.inr (Or.inr ⟨stage, member, by rw [sameDepth]; exact depth, by simpa only [sameSize] using size⟩) + · have ⟨value, low⟩ := ev.value h heap + rw [added, value, low] + rcases ev.before with ⟨tg, a, cap⟩ | ⟨tg, a, cap⟩ | ⟨tg, a, va, cap⟩ + · refine Or.inl ⟨tg, fun member => ?_⟩ + have zeroTag : root ||| tag = root := by rw [tg]; apply UScalar.eq_of_val_eq; simp [UScalar.val_or] + rw [zeroTag] at member + have native := (h.nativeRoots x ev.rootSlot root false a cap).1 + rw [h.highRoots] at member + obtain ⟨y, hy, m, a', cp⟩ := member + have high := h.highObjects y hy root m a' cp + rw [native] at high + cases high + · refine Or.inr (Or.inl ⟨tg, ?_⟩) + rw [h.highRoots] + exact ⟨x, ev.rootSlot, false, a, cap⟩ + · refine Or.inr (Or.inr ⟨tg, ?_, ?_, ?_⟩) + · simp [s1aAssignEpt, tg] + · simp [s1aAssignRe, tg] + have bound := s2lv_ge n + omega + · simp [s1aAssignBits, tg, s2rb] + split <;> decide + +set_option maxHeartbeats 3100000 in +/-- The narrowed Stage-2 typing at the same post state as the exact Assign write. -/ +theorem S1aAssignWrite.stage2Typing + (ev : S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (kinds : KindA st OS s) (table : TabKeep st s q) : + S2TyR st n (PoolSet st Pp q) Hr (s1aAssignEpt tag root Te) + (s1aAssignRe tag root n Re) (s1aAssignBits tag root bits) q := by + refine ⟨?_, ?_, ?_⟩ + · intro p live o width al nz + rw [table.poolSet_eq] at live + exact ev.stage2RootTyping h heap live width al nz + · intro r live + rw [ev.highHeader h heap kinds r live 4088#u64 (by decide) (by decide)] + exact h.core.stage2.hi r live + · intro p _ path deep o width al edge + rcases ev.rawStage2 h heap table path with prior | ⟨tg, rfl⟩ + · obtain ⟨_, depth, size⟩ := ev.stage2KeepType h prior + rw [depth] at deep ⊢ + rw [size] at width + have placed := h.core.stage2.reachableMember prior + have loc := ptw_mono h.place.granules (ptwb_gran h.place.stage2.sz ⟨p, placed, o, width, al, rfl⟩) + have kept := ev.edgeKept h heap loc edge + rw [kept] at edge ⊢ + obtain ⟨member, childDepth, _⟩ := ev.stage2KeepType h (.step prior deep width al edge) + exact ⟨member, by rw [childDepth]; exact (h.core.stage2.desc p placed prior deep o width al edge).2⟩ + · exact (ev.stage2RootNoEdge h heap tg width al edge).elim + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2AssignWrite.lean b/proofs/Fl4ProofsA64/P1/S1aR2AssignWrite.lean new file mode 100644 index 000000000..ddedac5fa --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2AssignWrite.lean @@ -0,0 +1,192 @@ +/- +P1 (aarch64): the concrete ASID-pool and root-cap writes of Assign. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Assign +import Fl4ProofsA64.P1.S1aR2MapWrite + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "wm" => core.num.U64.wrapping_mul + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt Cs Vc Ub U Ac Rp Nt : Set U64} + {Lv Re bits : U64 → Nat} {s q : S} {n slot pool base : U64} + {A : Type _} {ar : machine.Arch A} {extra : Aeneas.Std.Array obj.Slot 3#usize} + +/-- Only an unassigned native, HighVSpace or level-zero Stage-2 root is assignable. -/ +def S1aUnassignedRoot (c : capability.Cap) (root tag : U64) : Prop := + (tag = 0#u64 ∧ ∃ asid, c = .Pml4 root false asid) ∨ + (tag = 2#u64 ∧ ∃ asid, c = .HighVSpace root false asid) ∨ + (tag = 1#u64 ∧ ∃ asid va, c = .Ept root 0#u64 false asid va) + +/-- Publication writes one mapped root capability and one scanned empty pool entry. -/ +structure S1aAssignWrite (st : machine.Store S) [L : LawfulStore st] + (OS Pt Pp : Set U64) (s q : S) (pool x root tag asid index off : U64) : Prop where + poolLive : pool ∈ PoolSet st Pp s + poolIndex : index.val < 128 + poolLink : L.mem s (wa (L.ksb s) (AtOff index)) = pool + poolNonzero : pool ≠ 0#u64 + offBound : off.val < 4096 + offAligned : off.val % 8 = 0 + asidValue : asid.val = index.val * 512 + off.val / 8 + asidNonzero : asid ≠ 0#u64 + empty : L.mem s (wa pool off) = 0#u64 + rootSlot : x ∈ OS + before : S1aUnassignedRoot (capA st s x) root tag + after : MappedAsidRoot (capA st q x) root asid tag + write : S1aMapWrite st OS Pt s q x (wa pool off) (root ||| tag) (capA st q x) + +private theorem assignPoolIndex {i : U64} (shift : i.val = base.val >>> vspace.ASID_LOW_BITS.val) + {j : U64} (align : base.val = j.val * 512) : i = j := by + apply UScalar.eq_of_val_eq + rw [shift, P0.Consts.vspace.ASID_LOW_BITS.val_eq, Nat.shiftRight_eq_div_pow, align] + omega + +private theorem assignInPool (h : S1aPoolCaps st H OS Pt Pp s) {i : U64} + (hi : i.val < 128) (link : L.mem s (wa (L.ksb s) (AtOff i)) = pool) (nz : pool ≠ 0#u64) : + pool ∈ PoolSet st Pp s := by + have member := (h.present i hi pool link nz).1 + obtain ⟨lo, high, aligned⟩ := AtOff.v i + exact ⟨member, AtOff i, lo, high, aligned, link, nz⟩ + +private theorem assignWriteTail + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (os : OSOK H.tcbs H.omega H.frame OS) + (poolCaps : S1aPoolCaps st H OS Pt Pp s) {mid : S} + {x root tag asid index off : U64} {nc : capability.Cap} + (hi : index.val < 128) (link : L.mem s (wa (L.ksb s) (AtOff index)) = pool) + (nz : pool ≠ 0#u64) (width : off.val < 4096) (aligned : off.val % 8 = 0) + (asidEq : asid.val = index.val * 512 + off.val / 8) (nonzero : asid ≠ 0#u64) + (empty : L.mem s (wa pool off) = 0#u64) (member : x ∈ OS) + (before : S1aUnassignedRoot (capA st s x) root tag) (mapped : MappedAsidRoot nc root asid tag) + (cap : capA st mid x = nc) (keep : VsKeep st (L.ksb s) Pt s mid) + (other : ∀ y ∈ OS, y ≠ x → capA st mid y = capA st s y) + (baseEq : L.ksb mid = L.ksb s) : + st.write mid (wa pool off) (root ||| tag) ⦃ q => + S1aAssignWrite st OS Pt Pp s q pool x root tag asid index off ⦄ := by + have live := assignInPool poolCaps hi link nz + have word : PtW Pt (wa pool off) := ⟨pool, (poolCaps.present index hi pool link nz).2.1, off, width, aligned, rfl⟩ + have al := vr.al _ (Or.inl word) + refine WP.spec_mono (LawfulStore.write_spec mid (wa pool off) (root ||| tag)) fun out eq => ?_ + subst out + have edit := S1aMapWrite.ofTail (word := root ||| tag) vr os member baseEq keep cap other word (writesIn_wr al) (L.mem_wr_same al) + have after := edit.cap.symm ▸ mapped + have store : S1aMapWrite st OS Pt s _ x (wa pool off) (root ||| tag) (capA st _ x) := + edit.cap.symm ▸ edit + exact ⟨live, hi, link, nz, width, aligned, asidEq, nonzero, empty, member, before, after, store⟩ + +set_option hygiene false in +local macro "assignReject" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 (Or.inl rfl) + | (simp only [error.invalid_cap, error.truncated, error.illegal, bind_ok] + exact (WP.spec_ok _).2 (Or.inl rfl))) + +set_option hygiene false in +local macro "assignExactTail" : tactic => `(tactic| + ( + step as ⟨idx, shifted⟩ + have idEq := assignPoolIndex shifted baseAligned + subst idx + rw [vspace.asid_table.eq, bind_ok, poolLink] + rw [if_neg poolNz] + have checkPool : (pool != pool) = false := by simp + simp only [checkPool, Bool.false_eq_true, ite_false] + refine WP.spec_bind (vspace.decode_loop1.emptyWord (s := s) base pool 0#u64 (by decide)) fun entry ⟨bound, empty⟩ => ?_ + refine spec_ite (fun _ => by assignReject) (fun full => ?_) + have entryBound : entry.val < 512 := by + have notFull : entry.val ≠ 512 := by + intro eq + exact full (UScalar.eq_of_val_eq eq) + omega + obtain ⟨idNonzero, emptyWord⟩ := empty entryBound + obtain ⟨idVal, idLow⟩ := assign_asid_offset baseAligned idxBound entryBound + simp only [lift, bind_ok] + refine WP.spec_bind (sched.set_thread_state.mapCap vr P.os member D) fun start capWrite => ?_ + have idBound : (wa base entry).val < 2 ^ 20 := by rw [idVal]; omega + have rt := roundTrip (wa base entry) idBound + have next := mapped (wa base entry) + simp only [vspace.ROOT_S1, vspace.ROOT_S2, vspace.ROOT_HIGH, if_pos rfl, + show (0#u64 : U64) ≠ 1#u64 by decide, show (0#u64 : U64) ≠ 2#u64 by decide, + show (2#u64 : U64) ≠ 1#u64 by decide, ite_false] + refine WP.spec_bind (capWrite _ _ rt) fun q ⟨baseEq, keep, setCap, other⟩ => ?_ + simp only [lift, bind_ok, idLow] + step as ⟨off, offsetVal⟩ + have offset : off = wm entry 8#u64 := + UScalar.eq_of_val_eq (by rw [mul8_val (by omega : entry.val ≤ 511)]; simpa using offsetVal) + rw [offset] at offsetVal + simp only [lift, bind_ok, offset] + refine WP.spec_bind (assignWriteTail vr P.os h.poolCaps idxBound poolLink poolNz + (by omega) (by omega) (by omega) idNonzero emptyWord member before next setCap keep other baseEq) fun out effect => ?_ + exact (WP.spec_ok _).2 (Or.inr ⟨x, root, _, _, _, _, effect⟩) + )) + +set_option maxHeartbeats 4000000 in +/-- The Assign decoder publishes exactly one matched root and scanned pool +word in any of its three successful arms. Every rejection keeps the input state. -/ +theorem vspace.decode.assignExactWrite + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.AsidPool pool base) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (src : obj.Slot.cap st slot s = ok (.AsidPool pool base)) + (a : A) (len buf : U64) (call : Bool) : + vspace.decode st ar s a fl4_abi.label.ARMASIDPoolAssign len slot (.AsidPool pool base) call buf extra ⦃ r => + r.2.1 = s ∨ ∃ x root tag asid index off, + S1aAssignWrite st OS Pt Pp s r.2.1 pool x root tag asid index off ⦄ := by + have cap := okinj ((capA_eq s slot).symm.trans src) + obtain ⟨idx, idxBound, baseAligned, poolNz, poolLink⟩ := h.poolCaps.cap slot P.src pool base cap + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + try dsimp only + have lbl : (fl4_abi.label.ARMASIDPoolAssign != fl4_abi.label.ARMASIDPoolAssign) = false := by simp + simp only [lbl, Bool.false_eq_true, ite_false] + refine WP.spec_bind (vspace.extra.memA extra 0#usize) fun o slotInfo => ?_ + rcases o with _ | x + · assignReject + have member := P.ext x (slotInfo x rfl).1 (slotInfo x rfl).2 + try dsimp only + rw [capA_eq, bind_ok] + have wf : CapRt.EncWf (capA st s x) := CapRt.decodeF_encWf _ _ + generalize old : capA st s x = c at wf + cases c <;> try assignReject + case Pml4 root m oldId => + try dsimp only + refine spec_ite (fun _ => by assignReject) (fun no => ?_) + have no := Bool.eq_false_of_not_eq_true no + have before : S1aUnassignedRoot (capA st s x) root 0#u64 := Or.inl ⟨rfl, oldId, old.trans (by rw [no])⟩ + have roundTrip := fun (id : U64) (_ : id.val < 2 ^ 20) => CapRt.rt_Pml4 root true id wf + have mapped := fun id => show MappedAsidRoot (.Pml4 root true id) root id 0#u64 from Or.inl ⟨rfl, rfl⟩ + assignExactTail + case Ept root level m oldId oldVa => + try dsimp only + split + · rename_i levelZero + try subst levelZero + try dsimp only + refine spec_ite (fun _ => by assignReject) (fun no => ?_) + have no := Bool.eq_false_of_not_eq_true no + have before : S1aUnassignedRoot (capA st s x) root 1#u64 := + Or.inr (Or.inr ⟨rfl, oldId, oldVa, old.trans (by rw [no]; congr 1 <;> decide)⟩) + have roundTrip (id : U64) (bound : id.val < 2 ^ 20) := + CapRt.rt_Ept root 0#u64 true id 0#u64 ⟨wf.1, by decide, bound, by decide⟩ + have mapped (id : U64) : MappedAsidRoot (.Ept root 0#u64 true id 0#u64) root id 1#u64 := + Or.inr (Or.inl ⟨rfl, 0#u64, rfl⟩) + simp only [vspace.decode_loop2.eq_loop1] + assignExactTail + · assignReject + case HighVSpace root m oldId => + try dsimp only + refine spec_ite (fun _ => by assignReject) (fun no => ?_) + have no := Bool.eq_false_of_not_eq_true no + have before : S1aUnassignedRoot (capA st s x) root 2#u64 := Or.inr (Or.inl ⟨rfl, oldId, old.trans (by rw [no])⟩) + have roundTrip := fun (id : U64) (_ : id.val < 2 ^ 20) => CapRt.rt_HighVSpace root true id wf + have mapped := fun id => show MappedAsidRoot (.HighVSpace root true id) root id 2#u64 from Or.inr (Or.inr ⟨rfl, rfl⟩) + simp only [vspace.decode_loop3.eq_loop1] + assignExactTail + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Caps.lean b/proofs/Fl4ProofsA64/P1/S1aR2Caps.lean new file mode 100644 index 000000000..1e968d37a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Caps.lean @@ -0,0 +1,93 @@ +/- +P1 (aarch64, A64-S1A): Table capability metadata through capability transformers. +Named premises: none. +-/ +import Fl4ProofsA64.P1.MdbCnArmQ +import Fl4ProofsA64.P1.S1aVsUnm + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +/-- The capability kinds used as roots or child tables in R2. -/ +def R2TableCap : capability.Cap → Prop + | .PageTable .. | .Pml4 .. | .HighVSpace .. | .Ept .. => True + | _ => False + +/-- The transformer preserves all fields of a table capability. -/ +def R2TableFields (after before : capability.Cap) : Prop := + R2TableCap before → after = before + +theorem R2TableFields.refl (c : capability.Cap) : R2TableFields c c := fun _ => rfl + +theorem R2TableFields.trans {a b c : capability.Cap} + (ab : R2TableFields a b) (bc : R2TableFields b c) : R2TableFields a c := by + intro hc + have e := bc hc + exact (ab (e.symm ▸ hc)).trans e + +theorem R2TableFields.iff_eq {after before c : capability.Cap} (fields : R2TableFields after before) + (fe : FE after before) (hc : R2TableCap c) : after = c ↔ before = c := by + constructor + · intro eq + subst c + have nz : kindA after ≠ 0 := by cases after <;> simp_all [R2TableCap, kindA] + have eq := fe.kind nz + have hb : R2TableCap before := by + cases after <;> try contradiction + all_goals cases before <;> simp_all [R2TableCap, kindA] + exact (fields hb).symm + · intro eq + subst c + exact fields hc + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + +theorem capability.mask_cap_rights.r2TableFields (rights : capability.Rights) (c : capability.Cap) : + capability.mask_cap_rights rights c ⦃ d => R2TableFields d c ⦄ := by + have fallback (hc : ¬ R2TableCap c) : + capability.mask_cap_rights rights c ⦃ d => R2TableFields d c ⦄ := + WP.spec_mono (P0.capability.mask_cap_rights.p0 rights c) fun _ _ h => (hc h).elim + cases c <;> first + | solve | apply fallback; simp [R2TableCap] + | simp only [capability.mask_cap_rights] + exact (WP.spec_ok _).2 (R2TableFields.refl _) + +theorem objects.update_cap_data.r2TableFields (preserve : Bool) (data : U64) (c : capability.Cap) : + objects.update_cap_data preserve data c ⦃ d => R2TableFields d c ⦄ := by + have fallback (hc : ¬ R2TableCap c) : + objects.update_cap_data preserve data c ⦃ d => R2TableFields d c ⦄ := + WP.spec_mono (P0.objects.update_cap_data.p0 preserve data c) fun _ _ h => (hc h).elim + cases c <;> first + | solve | apply fallback; simp [R2TableCap] + | simp only [objects.update_cap_data] + exact (WP.spec_ok _).2 (R2TableFields.refl _) + +theorem objects.derive_cap.r2TableFields (s : S) (slot : U64) (c : capability.Cap) : + objects.derive_cap st s slot c ⦃ r => ∀ d, r = .Ok d → R2TableFields d c ⦄ := by + have fallback (hc : ¬ R2TableCap c) : + objects.derive_cap st s slot c ⦃ r => ∀ d, r = .Ok d → R2TableFields d c ⦄ := + WP.spec_mono (P0.objects.derive_cap.p0 st s slot c L.total) fun _ _ _ _ h => (hc h).elim + cases c <;> first + | solve | apply fallback; simp [R2TableCap] + | simp only [objects.derive_cap] + split + · exact (WP.spec_ok _).2 fun _ e => by cases e; exact R2TableFields.refl _ + · try simp only [error.illegal] + exact (WP.spec_ok _).2 fun _ e => by cases e + +/-- Copying or minting a table cap retains its mapped flag, ASID and address. -/ +theorem cnode.copied_cap.r2TableFields (s : S) (lbl len buf src : U64) (c : capability.Cap) : + cnode.copied_cap st s lbl len buf src c ⦃ r => ∀ nc, r = .Ok (nc, false) → R2TableFields nc c ⦄ := + cnode.copied_cap.uaG (R := R2TableFields) R2TableFields.trans capability.mask_cap_rights.r2TableFields + objects.update_cap_data.r2TableFields (objects.derive_cap.r2TableFields (st := st)) s lbl len buf src c + +/-- Moving or mutating a table cap retains its mapped flag, ASID and address. -/ +theorem cnode.copied_cap.r2TableFieldsMove (s : S) (lbl len buf src : U64) (c : capability.Cap) + (hl : lbl = fl4_abi.label.CNodeMove ∨ lbl = fl4_abi.label.CNodeMutate) : + cnode.copied_cap st s lbl len buf src c ⦃ r => ∀ nc b, r = .Ok (nc, b) → R2TableFields nc c ⦄ := + cnode.copied_cap.uaMG (R := R2TableFields) R2TableFields.refl objects.update_cap_data.r2TableFields + s lbl len buf src c hl + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2CnodeImage.lean b/proofs/Fl4ProofsA64/P1/S1aR2CnodeImage.lean new file mode 100644 index 000000000..0e8c72d88 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2CnodeImage.lean @@ -0,0 +1,364 @@ +/- +P1 (aarch64): CNode Copy, Mint, Move, Mutate and Rotate keep R2 (A64-S1A gen 41). + +The transformers keep every capability R2 reads or make it unread; a derived table capability is mapped. The +slot walk is `S1aR2Image`'s at the slot image `S1aSlotImage`. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2OfImage +import Fl4ProofsA64.P1.S1aR2Image +import Fl4ProofsA64.P1.S1aR2Keep +import Fl4ProofsA64.P1.MdbUt + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {OS : Set U64} {s s' : S} + +/-! ## The capability transformers -/ + +def S1aIsFrame : capability.Cap → Prop + | .Frame .. => True + | _ => False + +/-- Copying: frames stay frames, any other capability R2 reads afterwards is unchanged. -/ +def S1aCopyRel (after before : capability.Cap) : Prop := + (S1aIsFrame after ↔ S1aIsFrame before) ∧ (¬ S1aIsFrame before → S1aR2Reads after → after = before) + +/-- Moving: a capability R2 reads on either side is unchanged. -/ +def S1aMoveRel (after before : capability.Cap) : Prop := S1aR2Reads after ∨ S1aR2Reads before → after = before + +/-- A derived capability: never a mapped frame, and a table capability is mapped. -/ +def S1aDerived (c : capability.Cap) : Prop := + (S1aIsFrame c → ¬ S1aR2Reads c) ∧ ∀ k, s1aTableKey c = some k → s1aTableRef c ≠ none + +theorem S1aCopyRel.refl (c : capability.Cap) : S1aCopyRel c c := ⟨Iff.rfl, fun _ _ => rfl⟩ + +theorem S1aCopyRel.trans {a b c : capability.Cap} (first : S1aCopyRel a b) (second : S1aCopyRel b c) : + S1aCopyRel a c := by + refine ⟨first.1.trans second.1, fun plain reads => ?_⟩ + have eq := first.2 (fun h => plain (second.1.1 h)) reads + exact eq.trans (second.2 plain (eq ▸ reads)) + +theorem S1aMoveRel.refl (c : capability.Cap) : S1aMoveRel c c := fun _ => rfl + +theorem objects.update_cap_data.s1aRel (pr : Bool) (data : U64) (c : capability.Cap) : + objects.update_cap_data pr data c ⦃ m => S1aCopyRel m c ∧ S1aMoveRel m c ⦄ := by + refine WP.spec_mono (spec_eqv (P0.objects.update_cap_data.p0 pr data c)) fun m ⟨eq, _⟩ => ?_ + have cases : m = c ∨ ((¬ S1aR2Reads c ∧ ¬ S1aR2Reads m) ∧ ¬ S1aIsFrame c ∧ ¬ S1aIsFrame m) := by + cases c + case CNode p r g b => + simp only [objects.update_cap_data, lift, bind_ok] at eq + split at eq + · have same := okinj eq + subst same + exact Or.inr ⟨⟨id, id⟩, id, id⟩ + · obtain ⟨_, -, eq⟩ := bind_eq_ok eq + obtain ⟨_, -, eq⟩ := bind_eq_ok eq + have same := okinj eq + subst same + exact Or.inr ⟨⟨id, id⟩, id, id⟩ + all_goals (simp only [objects.update_cap_data] at eq) + all_goals (repeat' split at eq) + all_goals (have same := okinj eq; subst same) + all_goals first + | exact Or.inl rfl + | exact Or.inr ⟨⟨id, id⟩, id, id⟩ + rcases cases with rfl | ⟨⟨unread, unread'⟩, plain, plain'⟩ + · exact ⟨.refl _, .refl _⟩ + · exact ⟨⟨⟨fun h => absurd h plain', fun h => absurd h plain⟩, fun _ h => absurd h unread'⟩, + fun h => h.elim (absurd · unread') (absurd · unread)⟩ + +theorem capability.mask_cap_rights.s1aRel (r : capability.Rights) (c : capability.Cap) : + capability.mask_cap_rights r c ⦃ m => S1aCopyRel m c ⦄ := by + have unread {m c : capability.Cap} (h : ¬ S1aR2Reads m) (pm : ¬ S1aIsFrame m) (pc : ¬ S1aIsFrame c) : + S1aCopyRel m c := + ⟨⟨fun x => absurd x pm, fun x => absurd x pc⟩, fun _ x => absurd x h⟩ + 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 (unread id id id) + 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 (unread id id id) + case Reply p g => + cases g <;> simp only [capability.mask_cap_rights, Bool.false_eq_true, ↓reduceIte] <;> + exact (WP.spec_ok _).2 (unread id id id) + 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 ⟨Iff.rfl, fun h => absurd trivial h⟩ + all_goals (simp only [capability.mask_cap_rights]; exact (WP.spec_ok _).2 (.refl _)) + +theorem objects.derive_cap.s1aRel (s : S) (slot : U64) (c : capability.Cap) : + objects.derive_cap st s slot c ⦃ r => ∀ d, r = .Ok d → S1aCopyRel d c ∧ S1aDerived d ⦄ := by + have plain {c : capability.Cap} (pf : ¬ S1aIsFrame c) (nk : s1aTableKey c = none) : S1aDerived c := + ⟨fun h => absurd h pf, fun k h => by rw [nk] at h; cases h⟩ + have gone {c : capability.Cap} (pf : ¬ S1aIsFrame c) : S1aCopyRel .Null c := + ⟨⟨fun h => h.elim, fun h => absurd h pf⟩, fun _ h => h.elim⟩ + 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 L.total) fun r _ => ?_ + rcases r with u | e + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨.refl _, plain id rfl⟩ + · simp only [core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, + core.convert.FromSame.from, bind_ok, bind_tc_ok] + exact (WP.spec_ok _).2 fun _ e => by cases e + case Frame p sz rt dv mp ep asd va => + simp only [objects.derive_cap] + exact (WP.spec_ok _).2 fun _ e => by + cases e + exact ⟨⟨Iff.rfl, fun h => absurd trivial h⟩, fun _ h => (by cases h), fun _ h => (by cases h)⟩ + case IrqControl => + simp only [objects.derive_cap] + exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨gone id, plain id rfl⟩ + case Zombie p t m => + simp only [objects.derive_cap] + exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨gone id, plain id rfl⟩ + case IoPortControl => + simp only [objects.derive_cap] + exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨gone id, plain id rfl⟩ + case PageTable p m a v => + cases m <;> simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte, error.illegal] + · exact (WP.spec_ok _).2 fun _ e => by cases e + · exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨.refl _, fun h => h.elim, fun _ _ h => by cases h⟩ + case PageDirectory p m a v => + cases m <;> simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte, error.illegal] + · exact (WP.spec_ok _).2 fun _ e => by cases e + · exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨.refl _, plain id rfl⟩ + case Pdpt p m a v => + cases m <;> simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte, error.illegal] + · exact (WP.spec_ok _).2 fun _ e => by cases e + · exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨.refl _, plain id rfl⟩ + case Pml4 p m a => + cases m <;> simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte, error.illegal] + · exact (WP.spec_ok _).2 fun _ e => by cases e + · exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨.refl _, fun h => h.elim, fun _ _ h => by cases h⟩ + case Ept p l m a v => + cases m <;> simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte, error.illegal] + · exact (WP.spec_ok _).2 fun _ e => by cases e + · exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨.refl _, fun h => h.elim, fun _ _ h => by cases h⟩ + case HighVSpace p m a => + cases m <;> simp only [objects.derive_cap, Bool.false_eq_true, ↓reduceIte, error.illegal] + · exact (WP.spec_ok _).2 fun _ e => by cases e + · exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨.refl _, fun h => h.elim, fun _ _ h => by cases h⟩ + all_goals (simp only [objects.derive_cap]; exact (WP.spec_ok _).2 fun _ e => by cases e; exact ⟨.refl _, plain id rfl⟩) + +/-- The capability Copy and Mint insert. -/ +theorem cnode.copied_cap.s1aCopy (s : S) (lbl len buf src : U64) (c : capability.Cap) : + cnode.copied_cap st s lbl len buf src c ⦃ r => ∀ nc, r = .Ok (nc, false) → + S1aCopyRel nc c ∧ S1aDerived nc ⦄ := + WP.spec_mono (cnode.copied_cap.chainG (R := S1aCopyRel) (D := fun d m => S1aCopyRel d m ∧ S1aDerived d) + S1aCopyRel.trans capability.mask_cap_rights.s1aRel + (fun pr data c => WP.spec_mono (objects.update_cap_data.s1aRel pr data c) fun _ h => h.1) + (objects.derive_cap.s1aRel (st := st)) s lbl len buf src c) fun _ h nc e => by + obtain ⟨m, first, second, derived⟩ := h nc e + exact ⟨second.trans first, derived⟩ + +theorem S1aDerived.same {c before : capability.Cap} (d : S1aDerived c) (rel : S1aCopyRel c before) + (reads : S1aR2Reads c) : c = before := + rel.2 (fun frame => d.1 (rel.1.2 frame) reads) reads + +/-! ## The slot operations -/ + +/-- A move into an empty slot, up to capabilities R2 does not read. -/ +theorem S1aSlotImage.move (refs : S1aRefs st OS s) {src dest : U64} {c : capability.Cap} (hs : src ∈ OS) + (hd : dest ∈ OS) (empty : capA st s dest = .Null) (new : capA st s' dest = c) (clear : capA st s' src = .Null) + (rel : S1aMoveRel c (capA st s src)) + (keep : ∀ z ∈ OS, z ≠ src → z ≠ dest → capA st s' z = capA st s z) : S1aSlotImage st OS s s' := by + refine .swap refs hs hd (Or.inl (clear.trans empty.symm)) ?_ keep + by_cases reads : S1aR2Reads c ∨ S1aR2Reads (capA st s src) + · exact Or.inl (new.trans (rel reads)) + · exact Or.inr ⟨fun h => reads (Or.inr h), fun h => reads (Or.inl (new ▸ h))⟩ + +/-- `insert_with_cap` leaves its source, or turns an untyped source's free index. -/ +theorem S1aCapSame.insertSource {src : U64} (full : FullA (capA st s' src) (capA st s src)) : + S1aCapSame st s s' src := by + rcases full with same | ⟨p, b, i, e, i1, before, after, -⟩ + · exact Or.inl same + · exact Or.inr ⟨by rw [before]; exact id, by rw [after]; exact id⟩ + +section cnode + +variable {H : Heap} {Cs : Set U64} + (place : OSOK H.tcbs H.omega H.frame OS) (win : WinOK H.tcbs H.omega) + (mdb : MdbST st OS s) (refs : S1aRefs st OS s) + +include place win refs + +omit mdb in +private theorem keepImage {q : S} (keep : OSKeep st OS s q) : S1aSlotImage st OS s q := + .ofSame refs fun _ hy => Or.inl (keep.capA hy) + +omit mdb in +private theorem cdt.move_cap.s1aImage {q : S} (refsq : S1aRefs st OS q) (hma : MdbS st OS q) {src dest : U64} + {c : capability.Cap} (hs : src ∈ OS) (hd : dest ∈ OS) (ne : src ≠ dest) (encoding : CapRt.EncWf c) + (empty : capA st q dest = .Null) (rel : S1aMoveRel c (capA st q src)) : + cdt.move_cap st q c src dest ⦃ s' => S1aSlotImage st OS q s' ∧ capA st s' src = .Null ∧ + ∀ z ∈ OS, z ≠ src → z ≠ dest → capA st s' z = capA st q z ⦄ := by + obtain ⟨prev, next⟩ := hma.lnk place hs + refine WP.spec_mono (cdt.move_cap.lrF place (LR.self q) hs hd ne (place.canon win hd) encoding prev next) ?_ + rintro s' ⟨_, _, write, clear, keep⟩ + exact ⟨.move refsq hs hd empty write clear rel keep, clear, keep⟩ + +include mdb + +private theorem copyMoveImage {lbl len buf dest : U64} + (hl : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate) (hd : dest ∈ OS) : + CpMv st OS s lbl len buf dest (S1aSlotImage st OS s) := by + intro s2 src c keep _ hs full empty eq _ + have enc : CapRt.EncWf (capA st s src) := CapRt.decodeF_encWf _ _ + have hm := cnode.copied_cap.lblT hl enc eq + have wf := cnode.copied_cap.mv (st := st) s lbl len buf src (capA st s src) hm enc + have rel := cnode.copied_cap.uaMG (st := st) (R := S1aMoveRel) S1aMoveRel.refl + (fun pr data c => WP.spec_mono (objects.update_cap_data.s1aRel pr data c) fun _ h => h.2) + s lbl len buf src (capA st s src) hm + rw [eq, WP.spec_ok] at wf rel + have ne : src ≠ dest := fun e => full (by rwa [e]) + have first := keepImage place win refs keep + refine WP.spec_mono (cdt.move_cap.s1aImage place win refs (first.refs refs) (mdb.mdbS.keep keep) hs hd ne + (wf c true rfl).2.2 (by rwa [keep.capA hd]) (by rw [keep.capA hs]; exact rel c true rfl)) ?_ + exact fun _ post => first.trans post.1 + +private theorem copyInsertImage {lbl len buf dest : U64} + (hl : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate) (hd : dest ∈ OS) : + CpIns st OS s lbl len buf dest (S1aSlotImage st OS s) := by + intro s2 src c keep _ hs full empty eq _ + have enc : CapRt.EncWf (capA st s src) := CapRt.decodeF_encWf _ _ + have hc := cnode.copied_cap.lblF hl enc eq + have wf := cnode.copied_cap.wf (st := st) s lbl len buf src (capA st s src) hc enc + have rel := cnode.copied_cap.s1aCopy (st := st) s lbl len buf src (capA st s src) + rw [eq, WP.spec_ok] at wf rel + obtain ⟨copied, derived⟩ := rel c rfl + have ne : src ≠ dest := fun e => full (by rwa [e]) + obtain ⟨_, next⟩ := (mdb.mdbS.keep keep).lnk place hs + have first := keepImage place win refs keep + refine WP.spec_mono (WP.spec_and (cdt.insert_with_cap.lrF place (LR.self s2) hs hd ne (place.canon win hd) + (keep.capA hs) full (wf c false rfl).2 next) + (cdt.insert_with_cap.srcF place hs hd ne (keep.capA hs) (wf c false rfl).2 next)) ?_ + rintro s' ⟨⟨_, _, write, _, _, stay, _⟩, turned⟩ + refine first.trans (.copy (first.refs refs) hs hd ne (by rwa [keep.capA hd]) write + (fun reads => by rw [keep.capA hs]; exact derived.same copied reads) derived.2 + (S1aCapSame.insertSource (by rw [keep.capA hs]; exact turned)) stay) + +omit place win mdb refs in +private theorem rotateRel {c nc : capability.Cap} {data : U64} + (eq : objects.update_cap_data true data c = ok nc) (enc : CapRt.EncWf c) : + CapRt.EncWf nc ∧ S1aMoveRel nc c := by + have wf := objects.update_cap_data.wf true data c enc + have rel := objects.update_cap_data.s1aRel true data c + rw [eq, WP.spec_ok] at wf rel + exact ⟨wf, rel.2⟩ + +private theorem rotateSwapImage {dest : U64} : + RtSw st OS s dest (S1aSlotImage st OS s) := by + intro s3 src pivot sd pd c d keep _ hs hp ne _ _ _ _ ec ed _ _ + obtain ⟨fc, mc⟩ := rotateRel ec (CapRt.decodeF_encWf _ _) + obtain ⟨fd, md⟩ := rotateRel ed (CapRt.decodeF_encWf _ _) + have h := mdb.mdbS.keep keep + obtain ⟨prev1, next1⟩ := h.lnk place hs + obtain ⟨prev2, next2⟩ := h.lnk place hp + have first := keepImage place win refs keep + refine WP.spec_mono (cdt.swap.lrWF place (LR.self s3) hs hp ne.symm (place.canon win hs) + (place.canon win hp) fc fd prev1 next1 prev2 next2) ?_ + rintro s' ⟨_, _, es, ep, stay⟩ + have moved {after : capability.Cap} {x y : U64} (hy : y ∈ OS) (new : capA st s' x = after) + (rel : S1aMoveRel after (capA st s y)) : + capA st s' x = capA st s3 y ∨ (¬ S1aR2Reads (capA st s3 y) ∧ ¬ S1aR2Reads (capA st s' x)) := by + rw [keep.capA hy] + by_cases reads : S1aR2Reads after ∨ S1aR2Reads (capA st s y) + · exact Or.inl (new.trans (rel reads)) + · exact Or.inr ⟨fun h => reads (Or.inr h), fun h => reads (Or.inl (new ▸ h))⟩ + exact first.trans (.swap (first.refs refs) hs hp (moved hp es md) (moved hs ep mc) stay) + +private theorem rotateMoveImage {dest : U64} (hd : dest ∈ OS) : + RtMv st OS s dest (S1aSlotImage st OS s) := by + intro s3 src pivot sd pd c d keep _ hs hp ne npd _ full nsd empty ec ed _ nonnull + obtain ⟨fc, mc⟩ := rotateRel ec (CapRt.decodeF_encWf _ _) + obtain ⟨fd, md⟩ := rotateRel ed (CapRt.decodeF_encWf _ _) + have same := keep.capA hp + have empty3 : capA st s3 dest = .Null := by rwa [keep.capA hd] + have m3 := mdb.mdbS.keep keep + have alike := objects.update_cap_data.al true pd (capA st s pivot) + rw [ed, WP.spec_ok] at alike + have first := keepImage place win refs keep + refine WP.spec_mono (WP.spec_and + (cdt.move_cap.mdbS place m3 hp (by rwa [same]) hd empty3 (place.canon win hd) fd nonnull + (by rw [same]; exact alike.ne nonnull)) + (cdt.move_cap.s1aImage place win refs (first.refs refs) m3 hp hd npd fd empty3 (by rw [same]; exact md))) ?_ + rintro s4 ⟨m4, i4, clear, stay⟩ + have original : capA st s4 src = capA st s src := (stay src hs ne.symm nsd).trans (keep.capA hs) + have second := first.trans i4 + refine WP.spec_mono (cdt.move_cap.s1aImage place win refs (second.refs refs) m4 hs hp ne.symm fc clear + (by rw [original]; exact mc)) fun _ post => ?_ + exact second.trans post.1 + +variable {A : Type _} {ar : machine.Arch A} {Rp Nt X : Set U64} + {Q : U64 → U64 → List U64} {Rq : U64 → List U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (queues : SchedQueuesInvX st H.tcbs Cs H.omega H X s Q Rq) + (slots : SlotTy st H.tcbs H.omega H.frame H Rp Nt OS s) + (extras : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) +include queues slots extras + +private theorem cnode.decode_copy.s1aImage {lbl len buf dest : U64} (hd : dest ∈ OS) + (hl : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate) : + cnode.decode_copy st s lbl len buf extra dest ⦃ r => S1aSlotImage st OS s r.2 ⦄ := + cnode.decode_copy.genR place queues (keepImage place win refs (OSKeep.rfl' s)) + (fun sl hsl hn i d => lookup_src_in slots _ (RootOK.of_slot slots (extras sl hsl hn) (capA_eq s sl)) i d) + ((copyMoveImage place win mdb refs hl hd).toR _) ((copyInsertImage place win mdb refs hl hd).toR _) + +private theorem cnode.decode_rotate.s1aImage {len buf dest : U64} (hd : dest ∈ OS) : + cnode.decode_rotate st s len buf extra dest ⦃ r => S1aSlotImage st OS s r.2 ⦄ := + cnode.decode_rotate.genPR (Pv := fun _ => True) place queues slots + (keepImage place win refs (OSKeep.rfl' s)) extras + (fun sl hsl hn i d => WP.spec_mono + (lookup_piv_in slots _ (RootOK.of_slot slots (extras sl hsl hn) (capA_eq s sl)) i d) + fun _ h x e => ⟨h x e, trivial⟩) + (((rotateSwapImage place win mdb refs).toP _).toR _) (((rotateMoveImage place win mdb refs hd).toP _).toR _) + +/-- Copy, mint, move, mutate and rotate keep the image of the capabilities R2 reads. -/ +theorem cnode.decode.s1aImage (a : A) {lbl len buf : U64} (c : capability.Cap) (root : RootOK OS c) + (labels : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) : + cnode.decode st ar s a lbl len c buf extra ⦃ _ s' _ => S1aSlotImage st OS s s' ⦄ := + cnode.decode.cnodeG (keepImage place win refs (OSKeep.rfl' s)) a labels c (lookup_tgt_in slots c root) + (fun hl _ hd => cnode.decode_copy.s1aImage place win mdb refs queues slots extras hd hl) + fun _ hd => cnode.decode_rotate.s1aImage place win mdb refs queues slots extras hd + +end cnode + +/-- **The CNode Copy, Mint, Move, Mutate and Rotate arm keeps R2.** -/ +theorem syscall.decode_invocation.cnodeExactR2 + {H : Heap} {Cs Vc Ub U Ac Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} {c : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot lbl : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (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 c 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) (source : obj.Slot.cap st slot s = ok c) (family : capFam c = .cnode) + (labels : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot c blk call don fp buf extra ⦃ _ s' _ => + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + obtain ⟨_, _, queues⟩ := D.bxi.1 + have refs := h.capRefs.refs + have image : syscall.decode_invocation st ar s a lbl len slot c blk call don fp buf extra ⦃ _ s' _ => + S1aSlotImage st OS s s' ⦄ := + syscall.decode_invocation.cnodeG (.ofSame refs fun _ _ => Or.inl rfl) a len slot c blk call don fp buf extra + family (cnode.decode.s1aImage P.os P.win B.sys.stz.1.1 refs queues P.ty P.ext a c + (RootOK.of_slot P.ty P.src source) labels) + exact WP.spec_mono (WP.spec_and + (syscall.decode_invocation.cnode_armQIKAt D P B Y I.del.vr a len blk call don fp buf labels family source) + image) fun _ ⟨⟨_, _, mem⟩, slots⟩ => h.ofImage mem.1 (mem.vsKeep I.del.vr I.fu) slots + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Contract.lean b/proofs/Fl4ProofsA64/P1/S1aR2Contract.lean new file mode 100644 index 000000000..f0f9bb2d0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Contract.lean @@ -0,0 +1,172 @@ +/- +P1 (aarch64): active VSpace paths and exact backing capabilities. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Ept + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + +/-- The width selected by the concrete Stage-2 walker. -/ +def s1aIpaWidth (n : U64) : Nat := if n.val ≤ 42 then 40 else if n.val = 44 then 44 else 48 + +def s1aTopShift (tag n : U64) : Nat := + if tag = 0#u64 then 39 else if tag = 2#u64 then 30 else if n.val ≤ 42 then 30 else 39 + +/-- Bytes occupied by the usable descriptor slots at this level. -/ +def s1aTableWidth (tag n : U64) (shift : Nat) : Nat := + if shift = s1aTopShift tag n then + if tag = 1#u64 then 8 * 2 ^ (s1aIpaWidth n - shift) + else if tag = 0#u64 then 2048 else 4096 + else 4096 + +def s1aUserRange (tag n : U64) (first size : Nat) : Prop := + if tag = 0#u64 then first + size ≤ fl4_abi.consts.USER_TOP.val + 1 + else if tag = 2#u64 then fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ first ∧ first + size ≤ fl4_abi.consts.HIGH_VSPACE_TOP.val + else first + size ≤ 2 ^ s1aIpaWidth n + +/-- PageTable caps sign-extend bit 47 on decode. Stage 2 consumes the IPA bits only. -/ +def s1aCapAddress (tag n va : U64) : Nat := + if tag = 1#u64 then va.val % 2 ^ s1aIpaWidth n else va.val + +/-- Exact active paths to translation tables. The HighVSpace walk starts at +the header's private L1 table. Kernel TTBR1 entries 0–510 are outside this walk. -/ +inductive S1aPath (st : machine.Store S) [L : LawfulStore st] (Pp : Set U64) (n : U64) (s : S) : + U64 → U64 → Nat → Nat → U64 → Prop + | native {asid raw : U64} : ActiveAsidRoot st Pp s asid raw → raw &&& 3#u64 = 0#u64 → + S1aPath st Pp n s 0#u64 asid 39 0 raw + | high {asid raw : U64} : ActiveAsidRoot st Pp s asid raw → raw &&& 3#u64 = 2#u64 → + (L.mem s (wa (raw &&& ~~~3#u64) 4088#u64) &&& 3#u64) = 3#u64 → + S1aPath st Pp n s 2#u64 asid 30 (2 ^ 64 - 2 ^ 39) + (wa (L.mem s (wa (raw &&& ~~~3#u64) 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE) + | stage2 {asid raw : U64} : ActiveAsidRoot st Pp s asid raw → raw &&& 3#u64 = 1#u64 → + S1aPath st Pp n s 1#u64 asid (s1aTopShift 1#u64 n) 0 (raw &&& ~~~3#u64) + | child {tag asid t o : U64} {shift vaBase : Nat} : + S1aPath st Pp n s tag asid shift vaBase t → + 12 < shift → o.val < s1aTableWidth tag n shift → o.val % 8 = 0 → + s1aUserRange tag n (vaBase + o.val / 8 * 2 ^ shift) (2 ^ shift) → + (L.mem s (wa t o) &&& 3#u64) = 3#u64 → + S1aPath st Pp n s tag asid (shift - 9) (vaBase + o.val / 8 * 2 ^ shift) + (wa (L.mem s (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE) + +/-- The page or block target, with the level's low output-address bits removed. -/ +def s1aLeafTarget (entry : U64) (shift : Nat) : U64 := + wa (entry &&& vspace.ADDR_MASK &&& ~~~(⟨BitVec.ofNat 64 (2 ^ shift - 1)⟩ : U64)) layout.PPTR_BASE + +def s1aLeafValid (entry : U64) (shift : Nat) : Prop := + (shift = 12 ∧ entry &&& 3#u64 = 3#u64) ∨ + (shift ≠ 12 ∧ entry &&& 3#u64 = 1#u64) + +/-- Metadata shared by caps to a table. Roots and ordinary tables have distinct keys. +The saved PageTable address is compared to a path using `s1aCapAddress`. -/ +def s1aTableKey : capability.Cap → Option (Nat × U64) + | .PageTable p .. => some (0, p) + | .Pml4 p .. => some (1, p) + | .Ept p .. => some (2, p) + | .HighVSpace p .. => some (3, p) + | _ => none + +def s1aTableRef : capability.Cap → Option (U64 × U64) + | .PageTable _ true a v => some (a, v) + | .Pml4 _ true a | .HighVSpace _ true a => some (a, 0#u64) + | .Ept _ _ true a v => some (a, v) + | _ => none + +structure S1aPoolCaps (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt Pp : Set U64) (s : S) : Prop where + present : ∀ i : U64, i.val < 128 → ∀ p, L.mem s (wa (L.ksb s) (AtOff i)) = p → p ≠ 0#u64 → + p ∈ Pp ∧ p ∈ Pt ∧ H p = some (.other 12) ∧ + ∃ x ∈ OS, ∃ base : U64, capA st s x = .AsidPool p base ∧ base.val = i.val * 512 + cap : ∀ x ∈ OS, ∀ p base, capA st s x = .AsidPool p base → + ∃ i : U64, i.val < 128 ∧ base.val = i.val * 512 ∧ p ≠ 0#u64 ∧ L.mem s (wa (L.ksb s) (AtOff i)) = p + index : ∀ i j p : U64, i.val < 128 → j.val < 128 → p ≠ 0#u64 → + L.mem s (wa (L.ksb s) (AtOff i)) = p → L.mem s (wa (L.ksb s) (AtOff j)) = p → i = j + noZero : ∀ raw, ¬ ActiveAsidRoot st Pp s 0#u64 raw + +structure S1aTableCaps (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s : S) : Prop where + references : ∀ x ∈ OS, ∀ y ∈ OS, ∀ k, s1aTableKey (capA st s x) = some k → + s1aTableKey (capA st s y) = some k → s1aTableRef (capA st s x) = s1aTableRef (capA st s y) + unique : ∀ x ∈ OS, ∀ y ∈ OS, ∀ k, s1aTableKey (capA st s x) = some k → + s1aTableKey (capA st s y) = some k → s1aTableRef (capA st s x) = none → y = x + nativeEmpty : ∀ x ∈ OS, ∀ p a, capA st s x = .Pml4 p false a → + ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s (wa p o) = 0#u64 + highEmpty : ∀ x ∈ OS, ∀ p a, capA st s x = .HighVSpace p false a → + ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s (wa (wa p 4096#u64) o) = 0#u64 + +structure S1aPathBacking (st : machine.Store S) [L : LawfulStore st] + (H : Heap) (OS Pp Tb Te : Set U64) (Lv Re bits : U64 → Nat) (n : U64) (s : S) : Prop where + tables : ∀ tag asid shift vaBase t, S1aPath st Pp n s tag asid shift vaBase t → + (if tag = 1#u64 then t ∈ Te ∧ shift = 12 + 9 * Re t ∧ s1aTableWidth tag n shift ≤ 2 ^ bits t + else t ∈ Tb ∧ shift + 9 * Lv t = 39) + children : ∀ tag asid shift vaBase t, S1aPath st Pp n s tag asid shift vaBase t → + shift < s1aTopShift tag n → + ∃ x ∈ OS, ∃ va, capA st s x = .PageTable t true asid va ∧ s1aCapAddress tag n va = vaBase + leaves : ∀ tag asid shift vaBase t, S1aPath st Pp n s tag asid shift vaBase t → + ∀ o : U64, o.val < s1aTableWidth tag n shift → o.val % 8 = 0 → + s1aUserRange tag n (vaBase + o.val / 8 * 2 ^ shift) (2 ^ shift) → + s1aLeafValid (L.mem s (wa t o)) shift → + let p := s1aLeafTarget (L.mem s (wa t o)) shift + ∃ x ∈ OS, ∃ sz rights dev va, sz.bits = ok (⟨BitVec.ofNat 64 shift⟩ : U64) ∧ + capA st s x = .Frame p sz rights dev true (tag == 1#u64) asid va ∧ + s1aCapAddress tag n va = vaBase + o.val / 8 * 2 ^ shift ∧ + (dev = true ∨ ∃ base z, H base = some (.other z) ∧ base.val ≤ p.val ∧ + p.val + 2 ^ shift ≤ base.val + 2 ^ z) + +/-- The aligned words of a root outside its executable walk. -/ +def S1aRootZero (st : machine.Store S) [L : LawfulStore st] (s : S) (p : U64) + (unused : Nat → Prop) : Prop := + ∀ o : U64, unused o.val → o.val % 8 = 0 → L.mem s (wa p o) = 0#u64 + +/-- A HighVSpace header's copied table descriptors enter the kernel subtree. -/ +def S1aHighCopies (st : machine.Store S) [L : LawfulStore st] (Kt : Set U64) (s : S) (p : U64) : Prop := + ∀ o : U64, o.val < 4088 → o.val % 8 = 0 → + (L.mem s (wa p o) &&& 3#u64) = 3#u64 → + wa (L.mem s (wa p o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt + +/-- The words beyond the HighVSpace window in its private level-1 granule. -/ +def s1aHighUnused (o : Nat) : Prop := o < 4096 ∧ (o < 384 * 8 ∨ 496 * 8 ≤ o) + +/-- The root domains hold for live caps including detached mapped roots. -/ +structure S1aRootSlots (st : machine.Store S) [L : LawfulStore st] (OS Kt : Set U64) + (n : U64) (s : S) : Prop where + native : ∀ x ∈ OS, ∀ p m a, capA st s x = .Pml4 p m a → + S1aRootZero st s p (fun o => 2048 ≤ o ∧ o < 4096) + stage2 : ∀ x ∈ OS, ∀ p m a v, capA st s x = .Ept p 0#u64 m a v → + S1aRootZero st s p (fun o => s1aTableWidth 1#u64 n (s1aTopShift 1#u64 n) ≤ o ∧ o < 8192) + highCopies : ∀ x ∈ OS, ∀ p m a, capA st s x = .HighVSpace p m a → + S1aHighCopies st Kt s p + highPrivate : ∀ x ∈ OS, ∀ p m a, capA st s x = .HighVSpace p m a → + S1aRootZero st s (wa p 4096#u64) s1aHighUnused + +/-- The common R2 witness shares the heap, cap slots and VSpace footprint. +The concrete path domain and all-live HighVSpace headers serve different walks. -/ +structure S1aR2 (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt Pp Tb Hr Te Kt : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (s : S) : Prop where + core : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s + place : S1aR2Place Pt (PoolSet st Pp s) Tb Hr Te Lv bits (L.ksb s) + poolCaps : S1aPoolCaps st H OS Pt Pp s + capRefs : S1aTableCaps st OS s + paths : S1aPathBacking st H OS Pp Tb Te Lv Re bits n s + pageTables : PtCap st Pt OS s + footprint : PtHG H Pt + pageObjects : PtObjects st H OS s + nativeRoots : ∀ x ∈ OS, ∀ p m a, capA st s x = .Pml4 p m a → H p = some (.other 12) ∧ p ∈ Pt + eptRoots : EptPlaced st H OS Pt s + highObjects : HvObjects st H OS s + highHeaders : HiCap511 st OS s + highLink : ∀ p ∈ Hr, + wa (L.mem s (wa p 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE = wa p 4096#u64 + highRoots : Hr = HvRt st OS s + highFootprint : Gran Hr (fun _ => 13) ⊆ Pt + kernelTables : Kt ⊆ Tb ∧ ∀ t ∈ Kt, H t = some (.other 12) + kernelClosed : ∀ t ∈ Kt, Lv t < 3 → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + (L.mem s (wa t o) &&& 3#u64) = 3#u64 → + wa (L.mem s (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt + rootSlots : S1aRootSlots st OS Kt n s + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Del.lean b/proofs/Fl4ProofsA64/P1/S1aR2Del.lean new file mode 100644 index 000000000..abbc3c3b9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Del.lean @@ -0,0 +1,139 @@ +/- +P1 (aarch64): R2 over a slot set with excepted slots (A64-S1A gen 41, ruling of 18:45Z). + +Between the finalisation of a capability and the `empty_slot` of its slot, R2 holds over the other slots +only (for a final ASID pool cap `S1aPoolCaps.cap` is false over all of `OS`). `S1aR2Del` is that +pending predicate of the deletion loop (`LoopMP.Pn`); once the excepted slots are empty it is R2 again. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Contract +import Fl4ProofsA64.P1.S1aR2Keep + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS O' Pt Pp Tb Hr Te Kt E : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} + +/-- The capabilities R2 reads: table, mapped-frame and ASID-pool capabilities. -/ +def S1aR2Reads : capability.Cap → Prop + | .PageTable .. | .Pml4 .. | .HighVSpace .. | .Ept .. | .AsidPool .. => True + | .Frame _ _ _ _ mapped _ _ _ => mapped = true + | _ => False + +/-- R2 reads a slot set only through the capabilities of `S1aR2Reads`. -/ +theorem S1aR2.congrSlots (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (back : ∀ y ∈ O', S1aR2Reads (capA st s y) → y ∈ OS) + (forth : ∀ y ∈ OS, S1aR2Reads (capA st s y) → ∃ z ∈ O', capA st s z = capA st s y) : + S1aR2 st H O' Pt Pp Tb Hr Te Kt Lv Re bits n s := by + have old {y : U64} (hy : y ∈ O') {c : capability.Cap} (cap : capA st s y = c) (reads : S1aR2Reads c) : y ∈ OS := + back y hy (cap ▸ reads) + have new {y : U64} (hy : y ∈ OS) {c : capability.Cap} (cap : capA st s y = c) (reads : S1aR2Reads c) : + ∃ z ∈ O', capA st s z = c := by + obtain ⟨z, hz, same⟩ := forth y hy (cap ▸ reads) + exact ⟨z, hz, same.trans cap⟩ + have nonnull {c : capability.Cap} {k : Nat × U64} (key : s1aTableKey c = some k) : S1aR2Reads c := by + cases c <;> first | trivial | cases key + have mapped {c : capability.Cap} {t : U64} (m : MapV c t) : S1aR2Reads c := by + rcases m with ⟨_, _, rfl⟩ | ⟨_, rfl⟩ | ⟨_, rfl⟩ | ⟨_, _, rfl, _⟩ | ⟨_, _, _, rfl⟩ <;> trivial + have named {c : capability.Cap} {t : U64} (m : NamesV c t) : S1aR2Reads c := by + rcases m with ⟨_, _, _, rfl⟩ | ⟨_, _, rfl⟩ | ⟨_, _, rfl⟩ | ⟨_, _, _, rfl, _⟩ | ⟨_, _, _, _, rfl⟩ <;> trivial + have rooted {c : capability.Cap} {r a g : U64} (m : MappedAsidRoot c r a g) : S1aR2Reads c := by + rcases m with ⟨_, rfl⟩ | ⟨_, _, rfl⟩ | ⟨_, rfl⟩ <;> trivial + have lookup : VsLk st H O' Pp Tb Te Kt Lv Re bits s := by + refine ⟨fun t reach member outside => ?_, fun t reach member => ?_, fun t kernel y hy m => ?_, + fun x hx y hy p w unm m => ?_, fun x hx p w unm => ?_, ⟨fun x hx p w unm => ?_, + fun t reach member outside => ?_, h.core.lookup.vh.2.2⟩⟩ + · obtain ⟨y, hy, m⟩ := h.core.lookup.bk1 t reach member outside + obtain ⟨z, hz, same⟩ := new hy rfl (mapped m) + exact ⟨z, hz, same.symm ▸ m⟩ + · obtain ⟨y, hy, m⟩ := h.core.lookup.bk2 t reach member + obtain ⟨z, hz, same⟩ := new hy rfl (mapped m) + exact ⟨z, hz, same.symm ▸ m⟩ + · exact h.core.lookup.kt t kernel y (old hy rfl (named m)) m + · exact h.core.lookup.ex x (old hx rfl (named unm.names)) y (old hy rfl (mapped m)) p w unm m + · exact h.core.lookup.zr x (old hx rfl (named unm.names)) p w unm + · exact h.core.lookup.vh.1 x (old hx rfl (named unm.names)) p w unm + · rcases h.core.lookup.vh.2.1 t reach member outside with plain | ⟨R, obj, which, y, hy, a, cap⟩ + · exact Or.inl plain + · obtain ⟨z, hz, same⟩ := new hy cap trivial + exact Or.inr ⟨R, obj, which, z, hz, a, same⟩ + have walk : PtFndAll st O' Pp Lv Re bits n s := fun y hy p a v cap => + h.core.walk y (old hy cap trivial) p a v cap + have agreement : RootAgreement st O' Pp s := by + refine ⟨fun asid raw entry => ?_, fun x hx y hy root a b tag tag' cx cy => + h.core.root.agree x (old hx rfl (rooted cx)) y (old hy rfl (rooted cy)) root a b tag tag' cx cy⟩ + obtain ⟨y, hy, backed⟩ := h.core.root.backed asid raw entry + obtain ⟨z, hz, same⟩ := new hy rfl (rooted backed) + exact ⟨z, hz, same.symm ▸ backed⟩ + have stage2 : S2TyR st n (PoolSet st Pp s) Hr Te Re bits s := h.core.stage2 + have table {y : U64} (hy : y ∈ O') {c : capability.Cap} (cap : capA st s y = c) (reads : S1aR2Reads c) : y ∈ OS := + old hy cap reads + exact { + core := ⟨lookup, walk, agreement, h.core.stage1, stage2, h.core.heap⟩ + place := h.place + poolCaps := ⟨fun i hi p word nz => by + obtain ⟨active, member, obj, x, hx, base, cap, low⟩ := h.poolCaps.present i hi p word nz + obtain ⟨z, hz, same⟩ := new hx cap trivial + exact ⟨active, member, obj, z, hz, base, same, low⟩, + fun x hx p base cap => h.poolCaps.cap x (table hx cap trivial) p base cap, + h.poolCaps.index, h.poolCaps.noZero⟩ + capRefs := ⟨fun x hx y hy k kx ky => h.capRefs.references x (old hx rfl (nonnull kx)) y (old hy rfl (nonnull ky)) + k kx ky, + fun x hx y hy k kx ky none => h.capRefs.unique x (old hx rfl (nonnull kx)) y (old hy rfl (nonnull ky)) + k kx ky none, + fun x hx p a cap => h.capRefs.nativeEmpty x (table hx cap trivial) p a cap, + fun x hx p a cap => h.capRefs.highEmpty x (table hx cap trivial) p a cap⟩ + paths := ⟨h.paths.tables, fun tag asid sh va t path child => by + obtain ⟨x, hx, address, cap, ref⟩ := h.paths.children tag asid sh va t path child + obtain ⟨z, hz, same⟩ := new hx cap trivial + exact ⟨z, hz, address, same, ref⟩, + fun tag asid sh va t path o bound al range valid => by + obtain ⟨x, hx, sz, rights, dev, address, size, cap, ref, obj⟩ := + h.paths.leaves tag asid sh va t path o bound al range valid + obtain ⟨z, hz, same⟩ := new hx cap rfl + exact ⟨z, hz, sz, rights, dev, address, size, same, ref, obj⟩⟩ + pageTables := fun x hx p m a v cap => h.pageTables x (table hx cap trivial) p m a v cap + footprint := h.footprint + pageObjects := fun x hx p m a v cap => h.pageObjects x (table hx cap trivial) p m a v cap + nativeRoots := fun x hx p m a cap => h.nativeRoots x (table hx cap trivial) p m a cap + eptRoots := fun x hx p l m a v cap => h.eptRoots x (table hx cap trivial) p l m a v cap + highObjects := fun x hx p m a cap => h.highObjects x (table hx cap trivial) p m a cap + highHeaders := fun x hx p m a cap => h.highHeaders x (table hx cap trivial) p m a cap + highLink := h.highLink + highRoots := by + rw [h.highRoots] + ext R + constructor <;> rintro ⟨x, hx, m, a, cap⟩ + · obtain ⟨z, hz, same⟩ := new hx cap trivial + exact ⟨z, hz, m, a, same⟩ + · exact ⟨x, old hx cap trivial, m, a, cap⟩ + highFootprint := h.highFootprint + kernelTables := h.kernelTables + kernelClosed := h.kernelClosed + rootSlots := ⟨fun x hx p m a cap => h.rootSlots.native x (table hx cap trivial) p m a cap, + fun x hx p m a v cap => h.rootSlots.stage2 x (table hx cap trivial) p m a v cap, + fun x hx p m a cap => h.rootSlots.highCopies x (table hx cap trivial) p m a cap, + fun x hx p m a cap => h.rootSlots.highPrivate x (table hx cap trivial) p m a cap⟩ } + +/-- The deletion loop's invariant: R2 outside the finalised, not yet emptied slots `E`. -/ +def S1aR2Del (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt Pp Tb Hr Te Kt : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (E : Set U64) (s : S) : Prop := + E ⊆ OS ∧ S1aR2 st H (OS \ E) Pt Pp Tb Hr Te Kt Lv Re bits n s + +/-- The loop is entered with no exception. -/ +theorem S1aR2.toDel (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + S1aR2Del st H OS Pt Pp Tb Hr Te Kt Lv Re bits n ∅ s := + ⟨Set.empty_subset _, by rwa [Set.sdiff_empty]⟩ + +/-- Once every excepted slot is empty the invariant is exactly R2. -/ +theorem S1aR2Del.exit (h : S1aR2Del st H OS Pt Pp Tb Hr Te Kt Lv Re bits n E s) + (emptied : ∀ x ∈ E, capA st s x = .Null) : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s := + h.2.congrSlots (fun y hy reads => ⟨hy, fun member => by rw [emptied y member] at reads; exact reads⟩) + (fun y hy _ => ⟨y, hy.1, rfl⟩) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2DelArm.lean b/proofs/Fl4ProofsA64/P1/S1aR2DelArm.lean new file mode 100644 index 000000000..ce7e896f8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2DelArm.lean @@ -0,0 +1,500 @@ +/- +P1 (aarch64): R2 across the arms that delete a capability: CNode Delete and Revoke, the IRQ handler's Clear and +Set, and TCB SetSchedParams (A64-S1A gen 41). + +Each arm keeps `S1aDelKeep` (R2, with the live HighVSpace roots inside the entry's `Hr`) on every return. The +witnesses are those of the arm's deletion typing `HiDelTy`, which supplies the start's placement. +Case fact: `HiDelTy`. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Delete +import Fl4ProofsA64.P1.S1aHiDelDec + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Pt U Ac Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {ia ie : Nat} {A : Type _} + {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} {n : U64} + +theorem S2Q.vsCap {c : capability.Cap} (h : S2Q c) : S1aVsCap c := by + cases c <;> first | trivial | simp [S2Q, PtQ, VsQ, VsCap] at h + +theorem S1aR2.toDelKeep {s : S} (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s := + ⟨h.toDelM, h.highRoots.symm.subset⟩ + +/-- A post keeping the VSpace words and every capability R2 reads keeps `S1aDelKeep`. -/ +theorem S1aDelKeep.same {s r : S} (h : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (base : L.ksb r = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s r) (caps : ∀ y ∈ OS, S1aCapSame st s r y) : + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r := by + refine ⟨S1aDelM.keep h.1 base mem caps, ?_⟩ + rintro p ⟨y, hy, m, a, eq⟩ + rcases caps y hy with same | ⟨-, unread⟩ + · exact h.2 ⟨y, hy, m, a, same.symm.trans eq⟩ + · rw [eq] at unread + exact absurd trivial unread + +/-- The slot-keeping form: a step from a state of the arm, with the entry's base. -/ +theorem S1aDelKeep.osKeep {q r : S} {kb : U64} (h : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q) + (hq : L.ksb q = kb) (hr : L.ksb r = kb) (mem : VsKeep st kb Pt q r) (keep : OSKeep st OS q r) : + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r := + h.same (hr.trans hq.symm) (hq.symm ▸ mem) fun _ hy => Or.inl (keep.capA hy) + +/-- **One exposed deletion of a slot off the IRQ node, at the arm's `DelR`.** -/ +theorem cdt.delete.r2R {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (vsK : ∀ c, K c → S1aVsCap c) + (hPl : ArchPlat ar) (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s0)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) {a : A} {x : U64} + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (hx : x ∈ OSN OS (L.ksb s0)) + (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) : + cdt.delete st ar s a x true ⦃ r => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa r.2.1 ⦄ := by + have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 + rw [R.jv.ksb] at hD + exact cdt.delete.r2G I.del I.fin I.tyk I.kl vsK hPl place ptKs R.jv hx.1 hx.2 hD (fun c hc => hD x hx c hc) + rfl rfl R.irq R.ty R.sys R.sym K2 + +/-- **Revoke at the arm's `DelR`.** -/ +theorem cdt.revoke.r2R {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (vsK : ∀ c, K c → S1aVsCap c) + (hPl : ArchPlat ar) (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s0)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) {a : A} {x : U64} + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (hx : x ∈ OS) + (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) : + cdt.revoke st ar s a x ⦃ r => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa r.2.1 ⦄ := by + have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 + rw [R.jv.ksb] at hD + exact cdt.revoke.r2 I.del I.fin I.tyk I.kl vsK hPl place ptKs (fun y hy hib => ⟨hy, hib⟩) + ⟨R.jv, R.ty, R.sys, R.sym, hD, rfl, rfl, R.irq⟩ K2 hx + +/-- The caller's restart from the entry keeps the typing context and R2. -/ +theorem tcb.restart_caller.r2Keep {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) (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => + DelR st H Cs OS Vc Ub Ac Ty ia ie s s1 ∧ S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s1 ⦄ := by + have restart := WP.spec_and + (tcb.restart_caller.delR I D P B Y (Stalled.refl0 D) (DF.refl s) (DS.refl s) (VsKeep.refl s)) + (tcb.restart_caller.armVsK I D P B (Stalled.refl0 D) (DF.refl s) (DS.refl s)) + have eq : tcb.restart_caller st s = sched.set_thread_state st s (L.curW s) sched.TS_RESTART := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok] + rw [eq] at restart + refine WP.spec_mono restart fun s1 ⟨⟨_, R⟩, keep, os⟩ => ⟨R, ?_⟩ + exact K2.osKeep rfl keep.1 (keep.2 Ub Pt I.del.vr I.fu) os + +/-! ## CNode Delete and Revoke -/ + +set_option maxHeartbeats 2000000 in +/-- **CNode Delete and Revoke keep any state assertion** carried across the caller's restart and the walk. -/ +theorem cnode.decode.rvDelPhi {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) + (hcap : obj.Slot.cap st slot s = ok cap) {a : A} {Φ : S → Prop} (entry : Φ s) + (restart : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => + DelR st H Cs OS Vc Ub Ac Ty ia ie s s1 ∧ Φ s1 ⦄) + (delete : ∀ q x, DelR st H Cs OS Vc Ub Ac Ty ia ie s q → x ∈ OSN OS (L.ksb s) → Φ q → + cdt.delete st ar q a x true ⦃ r => Φ r.2.1 ⦄) + (revoke : ∀ q x, DelR st H Cs OS Vc Ub Ac Ty ia ie s q → x ∈ OS → Φ q → + cdt.revoke st ar q a x ⦃ r => Φ r.2.1 ⦄) + {lbl len buf : U64} (hl : lbl = fl4_abi.label.CNodeRevoke ∨ lbl = fl4_abi.label.CNodeDelete) : + cnode.decode st ar s a lbl len cap buf extra ⦃ r => Φ r.2.1 ⦄ := by + have root := RootOK.of_slot P.ty P.src hcap + have held : Held st OS s cap := ⟨slot, P.src, okinj ((capA_eq s slot).symm.trans hcap)⟩ + have hnc : ¬ (lbl ≥ fl4_abi.label.CNodeCopy) := hl.elim (fun h => h ▸ lbl_rv_c) (fun h => h ▸ lbl_c1) + unfold cnode.decode + simp only [error.illegal, error.truncated, bind_ok] + iterate 3 + split + · exact (WP.spec_ok _).2 entry + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun idx _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun depth _ => ?_ + refine WP.spec_bind (lookup_tgt_irq P.heap P.ty B.cn cap root held idx depth) fun result found => ?_ + rcases result with v | e + swap + · 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] + exact (WP.spec_ok _).2 entry + obtain ⟨hv, cov, -, -⟩ := found v rfl + have off := (SlotCov.offs P.heap B cov).1 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + rcases hl with rfl | rfl <;> + repeat (first + | exact WP.spec_bind restart fun _ d => revoke _ _ d.1 hv d.2 + | exact WP.spec_bind restart fun _ d => delete _ _ d.1 ⟨hv, off⟩ d.2 + | (refine spec_ite (fun hc => ?_) fun hc => ?_ <;> + try (exfalso; revert hc; decide))) + all_goals contradiction + +set_option maxHeartbeats 2000000 in +/-- **CNode Delete and Revoke keep R2**, including error and preemption exits. -/ +theorem cnode.decode.rvDelR2 {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) (vsK : ∀ c, K c → S1aVsCap c) (hPl : ArchPlat ar) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (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) + (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (a : A) {lbl len buf : U64} + (hl : lbl = fl4_abi.label.CNodeRevoke ∨ lbl = fl4_abi.label.CNodeDelete) : + cnode.decode st ar s a lbl len cap buf extra ⦃ r => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa r.2.1 ⦄ := by + exact cnode.decode.rvDelPhi I D P B hcap (Φ := S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) K2 + (tcb.restart_caller.r2Keep I D P B Y K2) + (fun _ _ R hx h => cdt.delete.r2R I vsK hPl place ptKs R hx h) + (fun _ _ R hx h => cdt.revoke.r2R I vsK hPl place ptKs R hx h) hl + +/-- The syscall dispatch to CNode Delete and Revoke keeps R2. -/ +theorem syscall.decode_invocation.cnodeRvDel_r2 {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) (hPl : ArchPlat ar) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa 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) (hf : capFam cap = .cnode) + (hks : HeapKsOff H (L.ksb s)) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.CNodeRevoke ∨ lbl = fl4_abi.label.CNodeDelete) (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 ⦃ r s' _ => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := + have J := I.forHiDel hPl W + syscall.decode_invocation.cnodeG (P := S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) R.toDelKeep a len + slot cap blk call don fp buf extra hf + (WP.spec_mono (cnode.decode.rvDelR2 J (fun _ h => h.vsCap) hPl + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + (hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap)) D P B Y hcap R.toDelKeep a hl) fun r h => by + obtain ⟨_, _, _⟩ := r + exact h) + +/-! ## The IRQ handler -/ + +set_option maxHeartbeats 2000000 in +/-- A single IRQ-node deletion keeps R2. -/ +theorem cdt.delete_one.r2 {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (a : A) {i : U64} (hi : i.val < 5376) + (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + cdt.delete_one st ar s a (irqSlotA (L.ksb s0) i) ⦃ r => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r.1 ⦄ := by + let x := irqSlotA (L.ksb s0) i + have hx : x ∈ OS := I.del.irq.1 i hi + unfold cdt.delete_one + rw [← show x = irqSlotA (L.ksb s0) i from rfl, capA_eq, bind_ok] + have hc := R.irq i hi (capA st s x) (capA_eq s x) + have unread : ¬ S1aR2Reads (capA st s x) := by + rcases hc with ⟨n, b0, b1, b2, h⟩ | h <;> rw [h] <;> exact fun h => h + refine WP.spec_bind (P0.capability.Cap.is_null.p0 _) fun _ _ => ?_ + split + · exact (WP.spec_ok _).2 K2 + refine WP.spec_bind (P0.cdt.is_final_capability_with_cap.p0 st s x _ L.total) fun fin _ => ?_ + have hn : ∀ j, capA st s x ≠ .IrqHandler j := by + rcases hc with ⟨n, b0, b1, b2, h⟩ | h <;> rw [h] <;> intro j e <;> cases e + rw [← fc_eq_fco ar s a fin hn] + refine WP.spec_bind (WP.spec_and + (finVK I.del.arch I.del.os I.del.sca I.del.vc I.del.vr R.jv I.del.irq R.irq hx (capA_eq s x) + (Or.inl (Or.inl (Or.inl (zl_irqNt hc)))) a fin) + (finL I.del.arch I.del.os I.del.sca I.del.vc R.jv hx (capA_eq s x) (zl_irqNt hc) a fin)) ?_ + rintro ⟨⟨rem, cl⟩, s2, a2⟩ ⟨mem, both, j2, os⟩ + simp only [Prod.mk.injEq] at both + obtain ⟨rfl, rfl⟩ := both + have base : L.ksb s2 = L.ksb s := j2.ksb.trans R.jv.ksb.symm + have K3 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s2 := + K2.osKeep R.jv.ksb j2.ksb mem os + refine WP.spec_mono (WP.spec_and (cdt.empty_slot.vk I.del.arch I.del.os I.del.vr j2 hx (Or.inl rfl) j2.ksb) + (cdt.empty_slot.zs I.del.arch I.del.os I.del.vc j2 hx (Or.inl rfl) I.del.irqSt)) + fun r ⟨mem3, j3, ck, null, _, _⟩ => ?_ + refine K3.same (j3.ksb.trans j2.ksb.symm) (j2.ksb.symm ▸ mem3) fun y hy => ?_ + by_cases same : y = x + · rw [same] + have emptied : capA st r.1 x = .Null := capA_okZ null + refine Or.inr ⟨?_, by rw [emptied]; exact fun h => h⟩ + rw [os.capA hx] + exact unread + · exact Or.inl (capA_okZ ((ck.cap hy same).trans (capA_eq s2 y))) + +/-- The insert of an unread capability into an empty slot keeps R2. -/ +theorem cdt.insert_with_cap.r2 {s : S} {kb : U64} (hO : OSOK H.tcbs H.omega H.frame OS) + (hR : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub kb Pt) (base : L.ksb s = kb) (hm : MdbS st OS s) + {src dest : U64} {nc sc : capability.Cap} (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) + (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hsc0 : sc ≠ .Null) (hw : CapRt.EncWf nc) + (newUnread : ¬ S1aR2Reads nc) (srcUnread : ¬ S1aR2Reads sc) (empty : capA st s dest = .Null) + (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + cdt.insert_with_cap st s nc sc src dest ⦃ s' => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + refine WP.spec_mono (cdt.insert_with_cap.lrF hO.inOS (LR.self s) hsrc hd hsd hdc hsc hsc0 hw (hm.lnk hO hsrc).2) + fun s' ⟨writes, _, new, _, _, other, source⟩ => ?_ + refine K2.same writes.1 (base.symm ▸ vsk_cw0 hR writes) fun y hy => ?_ + by_cases atDest : y = dest + · exact Or.inr ⟨by rw [atDest, empty]; exact fun h => h, by rw [atDest, new]; exact newUnread⟩ + by_cases atSrc : y = src + · rcases source with same | ⟨p, b, i, d, untyped⟩ + · exact Or.inl (atSrc ▸ same) + · exact Or.inr ⟨by rw [atSrc, hsc]; exact srcUnread, by rw [atSrc, untyped]; exact fun h => h⟩ + exact Or.inl (other y hy atSrc atDest) + +set_option maxHeartbeats 2000000 in +/-- Clearing an IRQ handler keeps any state assertion carried across the restart and the IRQ node's deletion. -/ +theorem interrupt.decode_irq_handler.clearPhi {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {a : A} + {lbl irq : U64} (hl : lbl = fl4_abi.label.IRQClearIRQHandler) {Φ : S → Prop} + (restart : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => + DelR st H Cs OS Vc Ub Ac Ty ia ie s s1 ∧ Φ s1 ⦄) + (one : ∀ q, DelR st H Cs OS Vc Ub Ac Ty ia ie s q → Φ q → + cdt.delete_one st ar q a (irqSlotA (L.ksb s) irq) ⦃ r => Φ r.1 ⦄) : + interrupt.decode_irq_handler st ar s a lbl irq extra ⦃ r => Φ r.2.1 ⦄ := by + subst lbl + unfold interrupt.decode_irq_handler + rw [cur_thread_ok, bind_ok, if_neg (by simp [fl4_abi.label.IRQClearIRQHandler, fl4_abi.label.IRQAckIRQ]), + if_neg (by simp [fl4_abi.label.IRQClearIRQHandler, fl4_abi.label.IRQSetIRQHandler]), if_pos rfl] + refine WP.spec_bind restart fun s1 post => ?_ + refine WP.spec_bind (interrupt.irq_slot.val s1 irq) fun _ eq => ?_ + rw [eq, post.1.jv.ksb] + refine WP.spec_bind (one _ post.1 post.2) ?_ + rintro ⟨s2, _⟩ h + exact (WP.spec_ok _).2 h + +set_option maxHeartbeats 2000000 in +/-- Clearing an IRQ handler keeps R2. -/ +theorem interrupt.decode_irq_handler.clear_r2 {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) (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (a : A) {lbl irq : U64} + (hl : lbl = fl4_abi.label.IRQClearIRQHandler) (hi : irq.val < 5376) : + interrupt.decode_irq_handler st ar s a lbl irq extra ⦃ r => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r.2.1 ⦄ := by + exact interrupt.decode_irq_handler.clearPhi hl (Φ := S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n) + (tcb.restart_caller.r2Keep I D P B Y K2) (fun _ R h => cdt.delete_one.r2 I R a hi h) + +set_option hygiene false in +/-- An IRQ decode exit that leaves the initial state intact. -/ +local macro "irqR2Leaf" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 entry + | (simp only [error.invalid_cap, error.truncated, error.illegal, bind_ok, + core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, + core.convert.FromSame.from, bind_tc_ok] + exact (WP.spec_ok _).2 entry)) + +set_option maxHeartbeats 3000000 in +/-- Setting an IRQ handler keeps any state assertion carried across the restart, the IRQ node's deletion and the +notification insert. -/ +theorem interrupt.decode_irq_handler.setPhi {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + {cap : capability.Cap} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + {a : A} {lbl irq : U64} (hl : lbl = fl4_abi.label.IRQSetIRQHandler) (hi : irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) {Φ : S → Prop} (entry : Φ s) + (restart : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => + DelR st H Cs OS Vc Ub Ac Ty ia ie s s1 ∧ Φ s1 ∧ OSKeep st OS s s1 ⦄) + (one : ∀ q, DelR st H Cs OS Vc Ub Ac Ty ia ie s q → Φ q → + cdt.delete_one st ar q a (irqSlotA (L.ksb s) irq) ⦃ r => Φ r.1 ⦄) + (insert : ∀ q x m b send recv, Φ q → L.ksb q = L.ksb s → MdbS st OS q → x ∈ OS → irqSlotA (L.ksb s) irq ∈ OS → + x ≠ irqSlotA (L.ksb s) irq → obj.sext48 (irqSlotA (L.ksb s) irq) = ok (irqSlotA (L.ksb s) irq) → + capA st q x = .Notification m b send recv → CapRt.EncWf (.Notification m b send recv) → + capA st q (irqSlotA (L.ksb s) irq) = .Null → + cdt.insert_with_cap st q (.Notification m b send recv) (.Notification m b send recv) x (irqSlotA (L.ksb s) irq) + ⦃ q' => Φ q' ⦄) : + interrupt.decode_irq_handler st ar s a lbl irq extra ⦃ r => Φ r.2.1 ⦄ := by + subst lbl + unfold interrupt.decode_irq_handler + rw [cur_thread_ok, bind_ok, if_neg (by simp [fl4_abi.label.IRQSetIRQHandler, fl4_abi.label.IRQAckIRQ]), if_pos rfl] + have valid : (0#usize).val < extra.val.length := by simp [extra.property] + refine WP.spec_bind (Aeneas.Std.Array.index_usize_spec extra 0#usize valid) fun x e => ?_ + have hmem : x ∈ extra.val := e ▸ List.getElem_mem valid + simp only [obj.Slot.is_null, bind_ok] + split + · irqR2Leaf + rename_i hn + have hx0 : x ≠ 0#u64 := by simpa using hn + have hx := P.ext x hmem hx0 + have off := (SlotCov.offs P.heap B (hSC x hmem hx0)).1 + rw [capA_eq, bind_ok] + have hw : CapRt.EncWf (capA st s x) := CapRt.decodeF_encWf _ _ + generalize hc : capA st s x = c at hw + cases c <;> try irqR2Leaf + rename_i m b send recv + dsimp only + split + swap + · irqR2Leaf + refine WP.spec_bind restart fun s1 ⟨post, kept1, keep⟩ => ?_ + refine WP.spec_bind (interrupt.irq_slot.val s1 irq) fun _ eq => ?_ + rw [eq, post.jv.ksb] + refine WP.spec_bind (WP.spec_and (cdt.delete_one.irqLK I post a hi) (one _ post kept1)) ?_ + rintro ⟨s2, _⟩ ⟨⟨B2, j2, _, null, kept⟩, K3⟩ + have stays : capA st s2 x = .Notification m b send recv := (kept x hx off).trans ((keep.capA hx).trans hc) + have hd := I.del.irq.1 irq hi + have apart : x ≠ irqSlotA (L.ksb s) irq := fun he => off ⟨irq, hi, he⟩ + unfold cdt.insert + simp only [uncurry_apply_pair] + rw [capA_eq, bind_ok, stays] + refine WP.spec_bind (insert s2 x m b send recv K3 j2.ksb B2.1.sys.stz.1.1.mdbS hx hd apart + (P.os.canon P.win hd) stays hw null) fun _ K4 => ?_ + exact (WP.spec_ok _).2 K4 + +set_option maxHeartbeats 3000000 in +/-- Setting an IRQ handler keeps R2 through the clear and the notification insert. -/ +theorem interrupt.decode_irq_handler.set_r2 {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) (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (a : A) {lbl irq : U64} + (hl : lbl = fl4_abi.label.IRQSetIRQHandler) (hi : irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) : + interrupt.decode_irq_handler st ar s a lbl irq extra ⦃ r => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r.2.1 ⦄ := by + have q := (Stalled.refl0 D).bxi.1.choose_spec.choose_spec + refine interrupt.decode_irq_handler.setPhi (Ac := Ac) (cap := cap) I P B hl hi hSC + (Φ := S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n) K2 ?_ + (fun _ R h => cdt.delete_one.r2 I R a hi h) + (fun _ _ _ _ _ _ h base hm hx hd apart canon stays hw null => cdt.insert_with_cap.r2 I.del.os I.del.vr base hm hx + hd apart canon stays (fun e => by cases e) hw (fun h => h) (fun h => h) null h) + refine WP.spec_mono (WP.spec_and (tcb.restart_caller.r2Keep I D P B Y K2) + (show sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => OSKeep st OS s s1 ⦄ by + have words := tcb.restart_caller.sts (q.nodes _ q.cur) (q.tcbs _ q.curT) + simp only [tcb.restart_caller, cur_thread_ok, bind_ok] at words + exact WP.spec_mono words fun _ w => stt_osk P.os q q.curT w)) + fun _ ⟨⟨R, h⟩, keep⟩ => ⟨R, h, keep⟩ + +/-! ## SetSchedParams' fault-handler install -/ + +theorem faults.valid_fault_handler.unread {c : capability.Cap} (h : faults.valid_fault_handler c = ok true) : + ¬ S1aR2Reads c := by + cases c <;> simp only [faults.valid_fault_handler] at h <;> + first + | exact fun reads => reads + | exact absurd (okinj h) (by decide) + +set_option maxHeartbeats 2000000 in +/-- The fault-handler install (the deletion of the old slot-3 cap, then an unread insert) keeps R2. -/ +theorem tcb.install_tcb_cap.r2F {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (vsK : ∀ c, K c → S1aVsCap c) + (hPl : ArchPlat ar) (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s0)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) {a : A} {target slot src : U64} + {nc : capability.Cap} (hb : BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac s) + (ht : target ∈ H.tcbs) (hslot : slot ∈ OS) (hsrc : src ∈ OS) + (hnc : nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) + (hfh : NullOrEp H (capA st s (slotIdx target layout.tcb.SLOT_FAULT_HANDLER))) + (unread : ¬ S1aR2Reads nc) (source : capA st s src = nc) + (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) : + tcb.install_tcb_cap st ar s a target slot layout.tcb.SLOT_FAULT_HANDLER nc src ⦃ r => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa r.2.1 ⦄ := by + have hi : layout.tcb.SLOT_FAULT_HANDLER.val < 7 := by simp [layout.tcb.SLOT_FAULT_HANDLER] + have hx := R.slot I ht hi + have hO := I.del.os + unfold tcb.install_tcb_cap + rw [tcb_slot_val] + simp only [bind_ok] + refine WP.spec_bind (WP.spec_and (WP.spec_and (WP.spec_and (cdt.delete.delRP I hKZ hPI R Q hx) + (cdt.delete.r2R I vsK hPl place ptKs R hx K2)) (cdt.delete.nullR I R hx)) + (cdt.delete.ep8 hO I.del.sca s a hx.1 hb R.jv.1.2 R.sys.sys.stz.1.1.mdbS hfh)) ?_ + rintro ⟨r, s1, a1⟩ ⟨⟨⟨⟨R1, -⟩, K3⟩, n1⟩, -, -, -, c1⟩ + try simp only [uncurry_apply_pair] at R1 K3 n1 c1 ⊢ + rcases r with v | e + swap + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 K3 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + have empty : capA st s1 (slotIdx target layout.tcb.SLOT_FAULT_HANDLER) = .Null := + okinj ((capA_eq s1 _).symm.trans (n1 v rfl)) + refine WP.spec_bind (spec_eqv (P0.capability.Cap.is_null.p0 nc)) fun bn hbn => ?_ + split + · exact (WP.spec_ok _).2 K3 + rename_i hbf + have hnc0 : nc ≠ .Null := by + rintro rfl + apply hbf + simpa [capability.Cap.is_null] using hbn.symm + refine WP.spec_bind (tcb.still_valid.soa s1 target slot nc src) fun b hb' => ?_ + split + swap + · exact (WP.spec_ok _).2 K3 + rename_i hbt + obtain ⟨-, hso, -⟩ := hb' hbt + obtain ⟨hK, hw⟩ := hnc hnc0 + have C := InsC.of_soa hK hso + have hxy : src ≠ slotIdx target layout.tcb.SLOT_FAULT_HANDLER := fun e => C.nn (by rw [e]; exact empty) + have stays : capA st s1 src = nc := (c1 src hsrc hxy).trans source + unfold cdt.insert + rw [capA_eq, bind_ok, stays] + refine WP.spec_bind (cdt.insert_with_cap.r2 hO I.del.vr R1.jv.ksb R1.sys.sys.stz.1.1.mdbS hsrc hx.1 hxy + (I.del.dcan _ hx) stays hnc0 hw unread unread empty K3) fun _ K4 => ?_ + exact (WP.spec_ok _).2 K4 + +/-! ## SetSchedParams -/ + +set_option maxHeartbeats 3000000 in +/-- **SetSchedParams keeps any state assertion** carried across its slot-keeping steps and the fault-handler +install. -/ +theorem syscall.decode_invocation.ssp_phi (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (J : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (z : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + {m : U64} (Hy : ArmDecHyps st H Pt m s (.Thread t)) {Φ : S → Prop} (entry : Φ s) + (keep : ∀ q r : S, Φ q → L.ksb q = L.ksb s → L.ksb r = L.ksb s → VsKeep st (L.ksb s) Pt q r → + OSKeep st OS q r → Φ r) + (install : ∀ (q : S) (a : A) (nc : capability.Cap) (src : U64), Φ q → DelR st H Cs OS Vc Ub Ac Ty ia ie s q → + PoolR st OS s q → (ArmVsZ st H OS Vc s q ∧ FrC st OS s q) → + BlkOK st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac q → + NullOrEp H (capA st q (slotIdx t layout.tcb.SLOT_FAULT_HANDLER)) → + (nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) → faults.valid_fault_handler nc = ok true → + src ∈ OS → capA st q src = nc → + tcb.install_tcb_cap st ar q a t slot layout.tcb.SLOT_FAULT_HANDLER nc src ⦃ r => Φ r.2.1 ⦄) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.TCBSetSchedParams) (len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => Φ s' ⦄ := by + subst lbl + refine syscall.decode_invocation.tcbG (Φ := Φ) entry a len + blk call don fp buf fun _ _ eq => ?_ + subst eq + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.delS hA D J a t) ?_ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ + try simp only [uncurry_apply_pair] + iterate 11 + refine spec_ite (fun hc => ?_) fun _ => ?_ + · exfalso + first | exact hc | (apply hc; contradiction) | exact absurd hc (lbl_ne_of_val (by + simp [fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, + fl4_abi.label.TCBConfigure, fl4_abi.label.TCBSetPriority, fl4_abi.label.TCBSetMCPriority, + fl4_abi.label.TCBSetSchedParams, fl4_abi.label.TCBSetTimeoutEndpoint, fl4_abi.label.TCBSetIPCBuffer, + fl4_abi.label.TCBSetSpace, fl4_abi.label.TCBSuspend, fl4_abi.label.TCBResume, + fl4_abi.label.TCBBindNotification, fl4_abi.label.TCBUnbindNotification, fl4_abi.label.TCBSetTLSBase, + fl4_abi.label.TCBSetPACKeys, fl4_abi.label.TCBSetHighVSpace, fl4_abi.label.TCBSetBreakpoint, + fl4_abi.label.TCBGetBreakpoint, fl4_abi.label.TCBUnsetBreakpoint, + fl4_abi.label.TCBConfigureSingleStepping, fl4_abi.label.TCBSetEPTRoot, fl4_abi.label.TCBSetFlags, + fl4_abi.label.TCBSetTimer, fl4_abi.label.TCBReadFPU, core.num.U64.MAX, U64.rMax])) + refine spec_ite (fun _ => ?_) (fun hc => absurd (by first | rfl | trivial) hc) + exact WP.spec_mono (tcb.decode_set_sched_params.armQIPAt J z hPI D P B Y hks hcap Hy h1 d1 ds1 vk1 (Φ := Φ) + entry keep install) fun _ d => d.2.2.2 + +set_option maxHeartbeats 3000000 in +/-- **SetSchedParams keeps R2** on every return. -/ +theorem syscall.decode_invocation.ssp_r2 (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + {m : U64} (Hy : ArmDecHyps st H Pt m s (.Thread t)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetSchedParams) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDel hPl W + have z := W.finKZ (hPl := hPl) I + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + exact syscall.decode_invocation.ssp_phi hA J z hPI D P B Y hks hcap Hy + (Φ := S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) R.toDelKeep + (fun q r Kq hq hr mem keep => Kq.osKeep hq hr mem keep) + (fun q a nc src Kq Rq Qq _ blk hfh hnc valid hsrc source => + tcb.install_tcb_cap.r2F J (fun _ h => h.vsCap) hPl place ptKs z hPI Rq Qq blk (D.cap.2.1 t rfl) P.src hsrc hnc + hfh (faults.valid_fault_handler.unread valid) source Kq) + a hl len blk call don fp buf + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Delete.lean b/proofs/Fl4ProofsA64/P1/S1aR2Delete.lean new file mode 100644 index 000000000..2c0a3708a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Delete.lean @@ -0,0 +1,116 @@ +/- +P1 (aarch64): `cdt.delete` and `cdt.revoke` keep R2 (A64-S1A gen 41). + +R2 is added to the deletion loops' field `ciM (fieldI)` with `LoopMP.r2M`; `S1aFinVs.of` discharges the +VSpace finalisation. The live HighVSpace roots stay inside the set the start's placement covers. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FinAlias +import Fl4ProofsA64.P1.MdbLiveY +import Fl4ProofsA64.P1.S1aHiCap + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {Cs Ac OS D Vc Ub Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {K : capability.Cap → Prop} {Ty : S → Prop} {ia ie : Nat} {s0 s : S} {x I Is : U64} + +/-- What the deletion keeps for R2: R2 itself, and the live HighVSpace roots inside `Hr`. -/ +def S1aDelKeep (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt Pp Tb Hr Te Kt : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (s : S) : Prop := + S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s ∧ HvRt st OS s ⊆ Hr + +/-- The deletion loop's field with R2. -/ +theorem LoopMP.r2Del (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) + (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (vsK : ∀ c, K c → S1aVsCap c) (hPl : ArchPlat ar) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s0)) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) + (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (R : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) : + ∃ (Zr : S → U64 → U64 → U64 → U64 → Prop) (Pn : S → U64 → Prop) (M : S → Prop), + LoopMP st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Pn M ∧ M s ∧ + ∀ q, M q → S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q := by + let P : capability.Cap → Prop := fun c => ∀ p m a, c = .HighVSpace p m a → p ∈ Hr + have closed : CapSrcClosed P := HvRootP.closed (fun p => p ∈ Hr) + have base := LoopME.ciM closed.null closed.zombie E.arch E.os E.sca E.vc E.dom E.dcan E.vr hK hTy E.wu E.irq + E.irqSt (E.fieldI (Cs := Cs) (Ac := Ac) (ia := ia) (ie := ie) hK hTy hKL s I Is) + (fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + have high : ∀ q, CapInv st P OS q → HvRt st OS q ⊆ Hr := by + rintro q inv p ⟨y, hy, m, a, eq⟩ + exact inv y hy p m a eq + refine ⟨_, _, _, LoopMP.r2M (Pt := Pt) (Pp := Pp) (Tb := Tb) (Te := Te) (Kt := Kt) (Lv := Lv) (Re := Re) + (bits := bits) (n := hPl.ipa) E vsK base.toP (fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + (S1aFinVs.of E.arch hPl E.os E.vr E.heap place ptKs (fun _ hC => hC.ksb) (fun _ m => high _ m.2) + (fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS)), ?_, fun q m => ⟨m.2, high q m.1.2⟩⟩ + refine ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨Y, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt hI hIs).idSc B.sc⟩, + CtOff.ks h.ksb.symm B.ct⟩, FrOff.ks h.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, ?_⟩, R.1⟩ + intro y hy p m a eq + exact R.2 ⟨y, hy, m, a, eq⟩ + +set_option maxHeartbeats 2000000 in +/-- **One deletion off the IRQ node keeps R2.** -/ +theorem cdt.delete.r2G (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) + (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (vsK : ∀ c, K c → S1aVsCap c) (hPl : ArchPlat ar) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s0)) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) {a : A} + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) (hx : x ∈ OS) + (hxI : ¬ IslN (L.ksb s0) x) (hD : DomQ st K Vc D H.scs H.tcbs I Is s) (hX : XQ st K Vc D H.scs H.tcbs I Is x s) + (hI : L.idleW s = I) (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) + (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (R : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) : + cdt.delete st ar s a x true ⦃ r => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa r.2.1 ⦄ := by + obtain ⟨Zr, Pn, M, field, start, done⟩ := + LoopMP.r2Del (D := D) E hK hTy hKL vsK hPl place ptKs h hI hIs B Y R + exact WP.spec_mono (cdt.delete.zqIGTMPQ (a := a) E.arch E.os E.sca E.vc E.dom E.dcan E.vr hK hTy E.wu E.irq + E.irqSt h hx hxI hD hX hI hIs hN hY field start) fun _ post => done _ post.2.2.1 + +set_option maxHeartbeats 2000000 in +/-- **The deletion of an IRQ-node slot keeps R2.** -/ +theorem cdt.delete.r2I (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) + (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (vsK : ∀ c, K c → S1aVsCap c) (hPl : ArchPlat ar) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s0)) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) {a : A} + (h : JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0 s) + (hxI : IslN (L.ksb s0) x) (hD : DomQ st K Vc D H.scs H.tcbs I Is s) (hI : L.idleW s = I) + (hIs : L.mem s (scA I) = Is) (hN : IrqN st (L.ksb s0) s) (hY : Ty s) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (R : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) : + cdt.delete st ar s a x true ⦃ r => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa r.2.1 ⦄ := by + obtain ⟨Zr, Pn, M, field, start, done⟩ := + LoopMP.r2Del (D := D) E hK hTy hKL vsK hPl place ptKs h hI hIs B Y R + exact WP.spec_mono (cdt.delete.irqMPQ (a := a) E hK hTy h hxI hD hI hIs hN hY field start) + fun _ post => done _ post.2.2.1 + +set_option maxHeartbeats 2000000 in +/-- **`cdt.revoke` keeps R2** on every return, including a preempted one. -/ +theorem cdt.revoke.r2 (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (hK : FinKT st ar (L.ksb s0) Pt Ty K) + (hTy : TyK st (L.ksb s0) Pt Ty) (hKL : ∀ c, K c → NoLiveK c) (vsK : ∀ c, K c → S1aVsCap c) (hPl : ArchPlat ar) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s0)) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) + (hDall : ∀ y ∈ OS, ¬ IslN (L.ksb s0) y → y ∈ D) {a : A} + (Q : DelQ st H Cs OS D Vc Ub Ac K Ty ia ie I Is s0 s) + (R : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (hx : x ∈ OS) : + cdt.revoke st ar s a x ⦃ r => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa r.2.1 ⦄ := by + refine WP.spec_mono (cdt.revoke.gen (Pr := S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) + E hK hTy hKL hDall (fun s1 a1 y Q1 p1 hy => ?_) (fun s1 a1 Q1 p1 => ?_) Q R hx) fun _ done => done.2 + · by_cases node : IslN (L.ksb s0) y + · exact cdt.delete.r2I E hK hTy hKL vsK hPl place ptKs Q1.jv node Q1.dom Q1.idle Q1.isc Q1.irq Q1.ty + Q1.sys Q1.sym p1 + · exact cdt.delete.r2G E hK hTy hKL vsK hPl place ptKs Q1.jv hy node Q1.dom + (fun c hc => Q1.dom y (hDall _ hy node) c hc) Q1.idle Q1.isc Q1.irq Q1.ty Q1.sys Q1.sym p1 + · refine WP.spec_mono (WP.spec_and + (sched.preemption_point.jv E.arch E.os E.vc Q1.jv (by rw [Q1.jv.ksb]; exact E.wu)) + (sched.preemption_point.vk E.arch E.vr Q1.jv Q1.jv.ksb)) fun r ⟨⟨after, kept, _⟩, mem⟩ => ?_ + have caps : ∀ y ∈ OS, capA st r.2.1 y = capA st s1 y := fun y hy => by + have same := kept y hy + have words : obj.Slot.cap st y r.2.1 = obj.Slot.cap st y s1 := by + rw [DPF.slot_cap_dec, DPF.slot_cap_dec, same.1, same.2.1] + exact okinj ((capA_eq _ _).symm.trans (words.trans (capA_eq _ _))) + refine ⟨S1aDelM.keep p1.1 (after.ksb.trans Q1.jv.ksb.symm) (by rw [Q1.jv.ksb]; exact mem) + (fun y hy => Or.inl (caps y hy)), ?_⟩ + rintro p ⟨y, hy, m, a, eq⟩ + exact p1.2 ⟨y, hy, m, a, (caps y hy).symm.trans eq⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Domains.lean b/proofs/Fl4ProofsA64/P1/S1aR2Domains.lean new file mode 100644 index 000000000..12fddba36 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Domains.lean @@ -0,0 +1,497 @@ +/- +P1 (aarch64): relate raw VSpace reachability to the executable root domains. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Contract +import Fl4ProofsA64.P1.S1aR2Shrink + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} + +/-- A walk is at its initial table or lies in a previously admitted descriptor interval. -/ +theorem S1aPath.geometry {tag asid t : U64} {sh va : Nat} + (h : S1aPath st Pp n s tag asid sh va t) : + (sh = 12 ∨ sh = 21 ∨ sh = 30 ∨ sh = 39) ∧ + (sh = s1aTopShift tag n ∧ va = (if tag = 2#u64 then 2 ^ 64 - 2 ^ 39 else 0) ∨ + sh < s1aTopShift tag n ∧ s1aUserRange tag n va (2 ^ (sh + 9))) := by + induction h with + | native => exact ⟨Or.inr (Or.inr (Or.inr rfl)), Or.inl ⟨rfl, rfl⟩⟩ + | high => exact ⟨Or.inr (Or.inr (Or.inl rfl)), Or.inl ⟨rfl, rfl⟩⟩ + | stage2 => + refine ⟨?_, Or.inl ⟨rfl, rfl⟩⟩ + simp only [s1aTopShift, show (1#u64 : U64) ≠ 0#u64 by decide, + show (1#u64 : U64) ≠ 2#u64 by decide, ite_false] + split <;> simp_all + | @child tag asid t o sh va p deeper width aligned window edge ih => + have parent : sh ≤ s1aTopShift tag n := ih.2.elim (fun h => h.1.le) (fun h => h.1.le) + exact ⟨by rcases ih.1 with e | e | e | e <;> omega, + Or.inr ⟨by omega, by simpa only [Nat.sub_add_cancel (by omega : 9 ≤ sh)] using window⟩⟩ + +private theorem rangeOfSubinterval {tag : U64} {b v span len : Nat} + (h : s1aUserRange tag n b span) (lo : b ≤ v) (hi : v + len ≤ b + span) : + s1aUserRange tag n v len := by + unfold s1aUserRange at h ⊢ + by_cases hn : tag = 0#u64 + · simp only [hn, ite_true] at h ⊢ + omega + · rw [if_neg hn] at h ⊢ + by_cases hh : tag = 2#u64 + · rw [if_pos hh] at h ⊢ + exact ⟨by omega, by omega⟩ + · rw [if_neg hh] at h ⊢ + omega + +private theorem subintervalBound {base sh i count : Nat} (hi : i < count) : + base + i * 2 ^ sh + 2 ^ sh ≤ base + count * 2 ^ sh := by + have scaled := Nat.mul_le_mul_right (2 ^ sh) (Nat.succ_le_of_lt hi) + rw [Nat.succ_mul] at scaled + omega + +private theorem stage2TopLe (n : U64) : s1aTopShift 1#u64 n ≤ s1aIpaWidth n := by + unfold s1aTopShift s1aIpaWidth + simp only [show (1#u64 : U64) ≠ 0#u64 by decide, show (1#u64 : U64) ≠ 2#u64 by decide, ite_false] + split <;> simp_all + split <;> decide + +private theorem widthChild {tag : U64} {sh : Nat} (h : sh < s1aTopShift tag n) : + s1aTableWidth tag n sh = 4096 := by + simp [s1aTableWidth, Nat.ne_of_lt h] + +/-- A valid word inside a walk table has a complete user-range interval. At the private +HighVSpace L1, the explicit interval bounds identify the window entries. -/ +theorem S1aPath.slotRange {tag asid t : U64} {sh va : Nat} {o : U64} + (h : S1aPath st Pp n s tag asid sh va t) (width : o.val < s1aTableWidth tag n sh) + (high : tag = 2#u64 → sh = s1aTopShift tag n → 384 * 8 ≤ o.val ∧ o.val < 496 * 8) : + s1aUserRange tag n (va + o.val / 8 * 2 ^ sh) (2 ^ sh) := by + rcases h.geometry.2 with ⟨eq, base⟩ | ⟨lt, full⟩ + · cases h with + | native => + change o.val < 2048 at width + have w := subintervalBound (base := 0) (sh := 39) (show o.val / 8 < 256 by omega) + simpa [s1aUserRange, P0.Consts.fl4_abi.consts.USER_TOP.val_eq] using w + | high => + have win := high rfl rfl + simp only [s1aUserRange, show (2#u64 : U64) ≠ 0#u64 by decide, ite_false, ite_true, + P0.Consts.fl4_abi.consts.HIGH_VSPACE_BASE.val_eq, P0.Consts.fl4_abi.consts.HIGH_VSPACE_TOP.val_eq] + norm_num at win ⊢ + omega + | stage2 => + let top := s1aTopShift 1#u64 n + have hw : o.val < 8 * 2 ^ (s1aIpaWidth n - top) := by + simpa [s1aTableWidth, top] using width + have idx : o.val / 8 < 2 ^ (s1aIpaWidth n - top) := by omega + have w := subintervalBound (base := 0) (sh := top) idx + rw [← pow_add, Nat.sub_add_cancel (stage2TopLe n)] at w + simpa [s1aUserRange, top] using w + | child parent deep _ _ _ _ => + have hp := parent.geometry.2 + have htop := hp.elim (fun z => z.1.le) (fun z => z.1.le) + omega + · rw [widthChild lt] at width + have w := subintervalBound (base := va) (sh := sh) (show o.val / 8 < 512 by omega) + have span : 512 * 2 ^ sh = 2 ^ (sh + 9) := by rw [pow_add, Nat.mul_comm]; rfl + rw [span] at w + exact rangeOfSubinterval full (Nat.le_add_right _ _) w + +/-- The exact path and heap facts used to reconstruct executable walks. +All fields are projections of R2 other than its executable walk conclusion. -/ +structure S1aRouteFacts (st : machine.Store S) [L : LawfulStore st] + (H : Heap) (OS Pt Pp Tb Hr Te Kt : Set U64) (Lv Re bits : U64 → Nat) (n : U64) (s : S) : Prop where + lookup : VsLk st H OS Pp Tb Te Kt Lv Re bits s + root : RootAgreement st OS Pp s + heap : TeH H Te Re bits n + paths : S1aPathBacking st H OS Pp Tb Te Lv Re bits n s + capRefs : S1aTableCaps st OS s + rootSlots : S1aRootSlots st OS Kt n s + highRoots : Hr = HvRt st OS s + highLink : ∀ p ∈ Hr, + wa (L.mem s (wa p 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE = wa p 4096#u64 + highObjects : HvObjects st H OS s + eptRoots : EptPlaced st H OS Pt s + pageObjects : PtObjects st H OS s + kernelClosed : ∀ t ∈ Kt, Lv t < 3 → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + (L.mem s (wa t o) &&& 3#u64) = 3#u64 → + wa (L.mem s (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt + +/-- The common R2 record supplies all the structural facts for its walks. -/ +theorem S1aR2.routeFacts (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s := + ⟨h.core.lookup, h.core.root, h.core.heap, h.paths, h.capRefs, h.rootSlots, h.highRoots, h.highLink, + h.highObjects, h.eptRoots, h.pageObjects, h.kernelClosed⟩ + +private theorem S1aRouteFacts.nativeCap (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {asid raw : U64} (entry : ActiveAsidRoot st Pp s asid raw) + (tag : raw &&& 3#u64 = 0#u64) : + ∃ x ∈ OS, capA st s x = .Pml4 raw true asid := by + obtain ⟨x, hx, cap⟩ := h.root.backed asid raw entry + rw [tag, and_not_of raw 3#u64 tag] at cap + rcases cap with ⟨_, h⟩ | ⟨bad, _⟩ | ⟨bad, _⟩ + · exact ⟨x, hx, h⟩ + · cases bad + · cases bad + +private theorem S1aRouteFacts.highCap (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {asid raw : U64} (entry : ActiveAsidRoot st Pp s asid raw) + (tag : raw &&& 3#u64 = 2#u64) : + ∃ x ∈ OS, capA st s x = .HighVSpace (raw &&& ~~~3#u64) true asid := by + obtain ⟨x, hx, cap⟩ := h.root.backed asid raw entry + rw [tag] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, h⟩ + · cases bad + · cases bad + · exact ⟨x, hx, h⟩ + +private theorem S1aRouteFacts.stage2Cap (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {asid raw : U64} (entry : ActiveAsidRoot st Pp s asid raw) + (tag : raw &&& 3#u64 = 1#u64) : + ∃ x ∈ OS, ∃ v, capA st s x = .Ept (raw &&& ~~~3#u64) 0#u64 true asid v := by + obtain ⟨x, hx, cap⟩ := h.root.backed asid raw entry + rw [tag] at cap + rcases cap with ⟨bad, _⟩ | ⟨_, v, h⟩ | ⟨bad, _⟩ + · cases bad + · exact ⟨x, hx, v, h⟩ + · cases bad + +/-- Physical storage of a walk table, including the unused root words. +A Stage-2 root occupies two granules for every configured IPA width. -/ +def s1aTableStorage (tag n : U64) (level : Nat) : Nat := + if tag = 1#u64 ∧ level = s1aTopShift tag n then 8192 else 4096 + +/-- An executable slot fits inside the physical table allocation. -/ +theorem s1aTableWidth.leStorage (tag n : U64) (level : Nat) : + s1aTableWidth tag n level ≤ s1aTableStorage tag n level := by + by_cases top : level = s1aTopShift tag n + · by_cases stage : tag = 1#u64 + · subst tag level + simp only [s1aTableStorage, s1aTableWidth, ite_true, and_self, s1aIpaWidth, s1aTopShift, + show (1#u64 : U64) ≠ 0#u64 by decide, show (1#u64 : U64) ≠ 2#u64 by decide, ite_false] + split + · decide + · split <;> decide + · simp only [s1aTableStorage, s1aTableWidth, top, stage, if_true, if_false, false_and] + split <;> decide + · simp only [s1aTableStorage, s1aTableWidth, top, and_false, if_false, le_refl] + +/-- An active descriptor belongs to the object named by the corresponding +root cap or PageTable cap. HighVSpace walks use the second granule of the root. -/ +theorem S1aR2.pathStorageOwner (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {tag asid t o : U64} {sh base : Nat} (path : S1aPath st Pp n s tag asid sh base t) + (bound : o.val < s1aTableStorage tag n sh) : + ∃ x ∈ OS, ∃ p delta : U64, ∃ z : Nat, + H p = some (.other z) ∧ 12 ≤ z ∧ delta.val < 2 ^ z ∧ + wa t o = wa p delta ∧ MapV (capA st s x) p ∧ RngKeyA (capA st s x) ∧ ptrA (capA st s x) = p ∧ + let k := kindA (capA st s x) + k ∈ ({14, 17, 19, 25} : Set Nat) ∧ + t = (if k = 25 then wa p 4096#u64 else p) ∧ + delta.val = (if k = 25 then 4096 else 0) + o.val ∧ + (k = 14 ↔ sh < s1aTopShift tag n) ∧ + (k ≠ 14 → ∃ raw, ActiveAsidRoot st Pp s asid raw ∧ (raw &&& ~~~3#u64) = p) ∧ + (k = 17 → tag = 0#u64 ∧ sh = 39) ∧ + (k = 19 → tag = 1#u64 ∧ sh = s1aTopShift 1#u64 n) ∧ + (k = 25 → tag = 2#u64 ∧ sh = 30 ∧ base = 2 ^ 64 - 2 ^ 39) := by + cases path with + | native active tag => + obtain ⟨x, hx, cap⟩ := h.routeFacts.nativeCap active tag + have named (p a : U64) : RngKeyA (.Pml4 p true a) ∧ ptrA (.Pml4 p true a) = p := by + have phys := physA_eq (.Pml4 p true a) + have ptr := ptrA_eq (.Pml4 p true a) + simp only [objects.cap_is_physical] at phys + simp only [capability.Cap.ptr] at ptr + exact ⟨⟨(okinj phys).symm, rfl, rfl⟩, (okinj ptr).symm⟩ + change o.val < 4096 at bound + refine ⟨x, hx, _, o, 12, (h.nativeRoots x hx _ true _ cap).1, by decide, by omega, rfl, ?_⟩ + rw [cap] + exact ⟨Or.inr (Or.inl ⟨_, rfl⟩), (named _ _).1, (named _ _).2, by simp [kindA], by simp [kindA], by simp [kindA], + by simp [kindA, s1aTopShift], (fun _ => ⟨_, active, and_not_of _ _ tag⟩), by simp [kindA], by simp [kindA], by simp [kindA]⟩ + | @high _ raw active tag header => + obtain ⟨x, hx, cap⟩ := h.routeFacts.highCap active tag + let root := raw &&& ~~~3#u64 + have membership : root ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, asid, cap⟩ + have link := h.highLink root membership + change o.val < 4096 at bound + let delta := wa 4096#u64 o + have granule : (4096#u64 : U64).val = 4096 := rfl + have span : (4096#u64 : U64).val + o.val < 2 ^ 64 := by rw [granule]; omega + have off : delta.val = 4096 + o.val := (wadd_val span).trans (congrArg (· + o.val) granule) + refine ⟨x, hx, root, delta, 13, h.highObjects x hx root true asid cap, by decide, by omega, ?_, ?_⟩ + · rw [show _ = wa root 4096#u64 from link] + exact waddA_assoc root 4096#u64 o span + · rw [cap] + exact ⟨Or.inr (Or.inr (Or.inl ⟨_, rfl⟩)), RngKeyA.hv _ _ _, ptrA_hv _ _ _, by simp [kindA], by simpa only [kindA, if_pos rfl, ite_true] using link, + by simpa only [kindA, if_pos rfl, ite_true] using off, by simp [kindA, s1aTopShift], (fun _ => ⟨raw, active, rfl⟩), by simp [kindA], by simp [kindA], by simp [kindA]⟩ + | @stage2 _ raw active tag => + obtain ⟨x, hx, va, cap⟩ := h.routeFacts.stage2Cap active tag + let root := raw &&& ~~~3#u64 + rw [s1aTableStorage, if_pos ⟨rfl, rfl⟩] at bound + refine ⟨x, hx, root, o, 13, (h.eptRoots x hx root 0#u64 true asid va cap).1, by decide, bound, rfl, ?_⟩ + rw [cap] + exact ⟨Or.inr (Or.inr (Or.inr (Or.inr ⟨_, _, _, rfl⟩))), RngKeyA.ept _ _ _ _ _, ptrA_ept _ _ _ _ _, by simp [kindA], by rfl, by simp [kindA], + by simp [kindA], (fun _ => ⟨raw, active, rfl⟩), by simp [kindA], by simp [kindA], by simp [kindA]⟩ + | @child k _ _ _ sh _ parent deep extent al range edge => + let next := S1aPath.child parent deep extent al range edge + have upper := parent.geometry.2.elim (fun h => h.1.le) (fun h => h.1.le) + have below : sh - 9 < s1aTopShift tag n := by omega + obtain ⟨x, hx, va, cap, ref⟩ := h.paths.children _ _ _ _ _ next below + rw [s1aTableStorage, if_neg (fun e => (Nat.ne_of_lt below) e.2)] at bound + refine ⟨x, hx, _, o, 12, h.pageObjects x hx _ true _ va cap, by decide, bound, rfl, ?_⟩ + rw [cap] + exact ⟨Or.inl ⟨_, _, rfl⟩, RngKeyA.pt _ _ _ _, ptrA_pt _ _ _ _, by simp [kindA], by simp [kindA], by simp [kindA], + by simp [kindA, below], by simp [kindA], by simp [kindA], by simp [kindA], by simp [kindA]⟩ + +/-- An active descriptor belongs to the object named by the corresponding +root cap or PageTable cap. HighVSpace walks use the second granule of the root. -/ +theorem S1aR2.pathStorageWord (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {tag asid t o : U64} {sh base : Nat} (path : S1aPath st Pp n s tag asid sh base t) + (bound : o.val < s1aTableStorage tag n sh) : + ∃ x ∈ OS, ∃ p delta : U64, ∃ z : Nat, + H p = some (.other z) ∧ 12 ≤ z ∧ delta.val < 2 ^ z ∧ + wa t o = wa p delta ∧ MapV (capA st s x) p ∧ RngKeyA (capA st s x) ∧ ptrA (capA st s x) = p ∧ + let k := kindA (capA st s x) + k ∈ ({14, 17, 19, 25} : Set Nat) ∧ + t = (if k = 25 then wa p 4096#u64 else p) ∧ + delta.val = (if k = 25 then 4096 else 0) + o.val ∧ + (k = 14 ↔ sh < s1aTopShift tag n) ∧ + (k ≠ 14 → ∃ raw, ActiveAsidRoot st Pp s asid raw ∧ (raw &&& ~~~3#u64) = p) := by + obtain ⟨x, hx, p, delta, z, obj, size, off, word, cap, key, ptr, kind, tab, d, child, root, _⟩ := + h.pathStorageOwner path bound + exact ⟨x, hx, p, delta, z, obj, size, off, word, cap, key, ptr, kind, tab, d, child, root⟩ + +/-- An active descriptor belongs to the object named by the corresponding +root cap or PageTable cap. HighVSpace walks use the second granule of the root. -/ +theorem S1aR2.pathWordObject (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {tag asid t o : U64} {sh base : Nat} (path : S1aPath st Pp n s tag asid sh base t) + (bound : o.val < s1aTableWidth tag n sh) : + ∃ x ∈ OS, ∃ p delta : U64, ∃ z : Nat, + H p = some (.other z) ∧ 12 ≤ z ∧ delta.val < 2 ^ z ∧ + wa t o = wa p delta ∧ MapV (capA st s x) p ∧ RngKeyA (capA st s x) ∧ ptrA (capA st s x) = p ∧ + let k := kindA (capA st s x) + k ∈ ({14, 17, 19, 25} : Set Nat) ∧ + t = (if k = 25 then wa p 4096#u64 else p) ∧ + delta.val = (if k = 25 then 4096 else 0) + o.val ∧ + (k = 14 ↔ sh < s1aTopShift tag n) ∧ + (k ≠ 14 → ∃ raw, ActiveAsidRoot st Pp s asid raw ∧ (raw &&& ~~~3#u64) = p) := + h.pathStorageWord path (lt_of_lt_of_le bound (s1aTableWidth.leStorage tag n sh)) + +/-- A descriptor selected by an active walk cannot share a pool word. -/ +theorem S1aR2.pathWordOffPool (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + {tag asid t o pool off : U64} {sh base : Nat} (path : S1aPath st Pp n s tag asid sh base t) + (bound : o.val < s1aTableWidth tag n sh) (active : pool ∈ PoolSet st Pp s) (below : off.val < 4096) : + wa t o ≠ wa pool off := by + obtain ⟨x, hx, p, delta, z, obj, _, deltaBound, address, _, key, ptr, kind, _⟩ := h.pathWordObject path bound + obtain ⟨_, idxOff, lo, hi, al, lookup, live⟩ := active + obtain ⟨idx, eq⟩ := atOff_of_off lo hi al + let index := idx &&& 127#u64 + have iv : index.val = idx.val % 128 := by + simp only [index, UScalar.val_and, show (127#u64 : U64).val = 2 ^ 7 - 1 by rfl, Nat.and_two_pow_sub_one_eq_mod] + have indexBound : index.val < 128 := iv ▸ Nat.mod_lt _ (by decide) + have same : AtOff index = idxOff := by + rw [← eq] + apply UScalar.eq_of_val_eq + rw [AtOff.val_eq, AtOff.val_eq, Nat.mod_eq_of_lt indexBound, iv] + rw [← same] at lookup + obtain ⟨_, _, poolObj, y, hy, capBase, cap, _⟩ := h.poolCaps.present index indexBound pool lookup live + have apart : p ≠ pool := by + intro e + have sameKind := kinds.kind x hx y hy key (by rw [cap]; exact RngKeyA.ap _ _) + (by rw [ptr, e, cap, ptrA_ap]) + rw [cap] at sameKind + change kindA (capA st s x) = 21 at sameKind + rw [sameKind] at kind + simpa using kind + rw [address] + exact tableWordsNe heap obj poolObj apart deltaBound below + +private theorem s1aNonzero {w tag : U64} (hne : tag ≠ 0#u64) (h : w &&& 3#u64 = tag) : + w ≠ 0#u64 := by + rintro rfl + exact hne h.symm + +private theorem edgeNotZero {w : U64} (e : w &&& 3#u64 = 3#u64) : w ≠ 0#u64 := + s1aNonzero (by decide) e + +private theorem S1aRouteFacts.highMember (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {x p a : U64} (hx : x ∈ OS) (cap : capA st s x = .HighVSpace p true a) : p ∈ Hr := by + rw [h.highRoots] + exact ⟨x, hx, true, a, cap⟩ + +theorem S1aRouteFacts.stage1Slot (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {tag asid p o : U64} {sh va : Nat} (stage : tag = 0#u64 ∨ tag = 2#u64) + (path : S1aPath st Pp n s tag asid sh va p) (bound : o.val < 4096) (al : o.val % 8 = 0) + (edge : L.mem s (wa p o) &&& 3#u64 = 3#u64) : + o.val < s1aTableWidth tag n sh ∧ s1aUserRange tag n (va + o.val / 8 * 2 ^ sh) (2 ^ sh) := by + have original := path + cases path with + | native entry kind => + obtain ⟨x, hx, cap⟩ := h.nativeCap entry kind + have width : o.val < 2048 := by + by_contra hn + exact edgeNotZero edge (h.rootSlots.native x hx _ true _ cap o ⟨by omega, bound⟩ al) + exact ⟨width, original.slotRange width (fun bad _ => by cases bad)⟩ + | high entry kind _ => + obtain ⟨x, hx, cap⟩ := h.highCap entry kind + rw [h.highLink _ (h.highMember hx cap)] at edge + have window : 384 * 8 ≤ o.val ∧ o.val < 496 * 8 := by + by_contra hn + have unused : s1aHighUnused o.val := ⟨bound, by omega⟩ + exact edgeNotZero edge (h.rootSlots.highPrivate x hx _ true _ cap o unused al) + exact ⟨bound, original.slotRange bound (fun _ _ => window)⟩ + | stage2 => + rcases stage with z | z <;> cases z + | @child _ _ _ _ parentSh _ parent deep _ _ _ _ => + have old := parent.geometry.2.elim (fun z => z.1.le) (fun z => z.1.le) + have inner : parentSh - 9 < s1aTopShift tag n := by omega + have width : o.val < s1aTableWidth tag n (parentSh - 9) := by rwa [widthChild inner] + exact ⟨width, original.slotRange width (fun _ equal => (Nat.ne_of_lt inner equal).elim)⟩ + +private theorem S1aRouteFacts.stage2Slot (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {asid p o : U64} {sh va : Nat} + (path : S1aPath st Pp n s 1#u64 asid sh va p) (bound : o.val < 2 ^ bits p) (al : o.val % 8 = 0) + (edge : L.mem s (wa p o) &&& 3#u64 = 3#u64) : + o.val < s1aTableWidth 1#u64 n sh ∧ s1aUserRange 1#u64 n (va + o.val / 8 * 2 ^ sh) (2 ^ sh) := by + have original := path + have typed : p ∈ Te := by simpa using (h.paths.tables _ _ _ _ _ path).1 + have heap := (h.heap p typed).1 + have width : o.val < s1aTableWidth 1#u64 n sh := by + cases path with + | stage2 entry kind => + obtain ⟨x, hx, v, cap⟩ := h.stage2Cap entry kind + have size : bits _ = 13 := HKind.other.inj (Option.some.inj (heap.symm.trans (h.eptRoots x hx _ _ _ _ _ cap).1)) + rw [size] at bound + by_contra hn + exact edgeNotZero edge (h.rootSlots.stage2 x hx _ true _ v cap o ⟨by omega, bound⟩ al) + | @child _ _ _ _ parentSh _ parent deep _ _ _ _ => + have old := parent.geometry.2.elim (fun z => z.1.le) (fun z => z.1.le) + have inner : parentSh - 9 < s1aTopShift 1#u64 n := by omega + obtain ⟨x, hx, v, cap, _⟩ := h.paths.children _ _ _ _ _ original inner + have size := HKind.other.inj (Option.some.inj (heap.symm.trans (h.pageObjects x hx _ true _ v cap))) + rw [size] at bound + rw [widthChild inner] + exact bound + exact ⟨width, path.slotRange width (fun bad _ => by cases bad)⟩ + +/-- Raw Stage-1 reachability is a High header, a kernel table, or an exact user walk. -/ +theorem S1aRouteFacts.classifyStage1 (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {p : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s p) : + p ∈ Kt ∨ + (∃ raw asid, ActiveAsidRoot st Pp s asid raw ∧ raw &&& 3#u64 = 2#u64 ∧ p = raw &&& ~~~3#u64) ∨ + ∃ tag asid sh va, (tag = 0#u64 ∨ tag = 2#u64) ∧ S1aPath st Pp n s tag asid sh va p := by + induction reach with + | hr bad => exact (Set.notMem_empty _ bad).elim + | root0 hp ho al nz tag => + obtain ⟨asid, entry⟩ := ActiveAsidRoot.forWord hp ho al nz + exact Or.inr (Or.inr ⟨0#u64, asid, 39, 0, Or.inl rfl, .native entry tag⟩) + | root2 hp ho al tag => + obtain ⟨asid, entry⟩ := ActiveAsidRoot.forWord hp ho al (s1aNonzero (by decide) tag) + exact Or.inr (Or.inl ⟨_, asid, entry, tag, rfl⟩) + | @step p o _ lv ho al edge ih => + rcases ih with kt | ⟨raw, asid, entry, tag, rfl⟩ | ⟨tag, asid, sh, va, stage, walk⟩ + · exact Or.inl (h.kernelClosed p kt lv o ho al edge) + · obtain ⟨x, hx, cap⟩ := h.highCap entry tag + by_cases off : o.val < 4088 + · exact Or.inl (h.rootSlots.highCopies x hx _ true asid cap o off al edge) + · have last : o = 4088#u64 := UScalar.eq_of_val_eq (by + change o.val = 4088 + omega) + subst o + exact Or.inr (Or.inr ⟨2#u64, asid, 30, 2 ^ 64 - 2 ^ 39, Or.inr rfl, .high entry tag edge⟩) + · have geom := h.paths.tables _ _ _ _ _ walk + have level : sh + 9 * Lv p = 39 := by + rcases stage with rfl | rfl <;> exact (show _ ∧ _ from geom).2 + have deep : 12 < sh := by omega + obtain ⟨width, range⟩ := h.stage1Slot stage walk ho al edge + exact Or.inr (Or.inr ⟨tag, asid, sh - 9, va + o.val / 8 * 2 ^ sh, stage, + .child walk deep width al range edge⟩) + +/-- Raw Stage-2 reachability follows the exact IPA walk. -/ +theorem S1aRouteFacts.classifyStage2 (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {p : U64} (reach : S2Reach st (PoolSet st Pp s) Re bits s p) : + ∃ asid sh va, S1aPath st Pp n s 1#u64 asid sh va p := by + induction reach with + | root hp ho al tag => + obtain ⟨asid, entry⟩ := ActiveAsidRoot.forWord hp ho al (s1aNonzero (by decide) tag) + exact ⟨asid, _, 0, .stage2 entry tag⟩ + | @step p o _ lv ho al edge ih => + obtain ⟨asid, sh, va, walk⟩ := ih + have geom := h.paths.tables _ _ _ _ _ walk + have level : sh = 12 + 9 * Re p := (show _ ∧ _ ∧ _ from geom).2.1 + have deep : 12 < sh := by omega + obtain ⟨width, range⟩ := h.stage2Slot walk ho al edge + have masks : ept.ADDR_MASK = vspace.ADDR_MASK := UScalar.eq_of_val_eq (by + simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + rw [masks] + exact ⟨asid, sh - 9, va + o.val / 8 * 2 ^ sh, .child walk deep width al range edge⟩ + +/-- A raw Stage-1 edge to a table outside the kernel tree is a live `HighVSpace` header's private +entry or an edge of an executable user path. -/ +theorem S1aRouteFacts.classifyEdge1 (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {t p o : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s p) (level : Lv p < 3) + (width : o.val < 4096) (al : o.val % 8 = 0) (edge : (L.mem s (wa p o) &&& 3#u64) = 3#u64) + (target : wa (L.mem s (wa p o) &&& vspace.ADDR_MASK) layout.PPTR_BASE = t) (noKernel : t ∉ Kt) : + (∃ x ∈ OS, ∃ asid, capA st s x = .HighVSpace p true asid ∧ wa p 4096#u64 = t ∧ o = 4088#u64) ∨ + ∃ tag asid sh va, (tag = 0#u64 ∨ tag = 2#u64) ∧ S1aPath st Pp n s tag asid sh va p ∧ + 12 < sh ∧ o.val < s1aTableWidth tag n sh ∧ s1aUserRange tag n (va + o.val / 8 * 2 ^ sh) (2 ^ sh) := by + rcases h.classifyStage1 reach with kernel | ⟨raw, asid, entry, kind, rfl⟩ | ⟨tag, asid, sh, va, stage, walk⟩ + · exact (noKernel (target ▸ h.kernelClosed p kernel level o width al edge)).elim + · obtain ⟨x, hs, capHigh⟩ := h.highCap entry kind + by_cases copied : o.val < 4088 + · exact (noKernel (target ▸ h.rootSlots.highCopies x hs _ true asid capHigh o copied al edge)).elim + · have last : o = 4088#u64 := UScalar.eq_of_val_eq (by change o.val = 4088; omega) + subst o + rw [h.highLink _ (h.highMember hs capHigh)] at target + exact Or.inl ⟨x, hs, asid, capHigh, target, rfl⟩ + · obtain ⟨inWidth, range⟩ := h.stage1Slot stage walk width al edge + have exactLevel := h.paths.tables _ _ _ _ _ walk + have depth : sh + 9 * Lv p = 39 := by rcases stage with rfl | rfl <;> exact (show _ ∧ _ from exactLevel).2 + exact Or.inr ⟨tag, asid, sh, va, stage, walk, by omega, inWidth, range⟩ + +/-- A raw Stage-1 parent of an ordinary PageTable is an executable user path. -/ +theorem S1aRouteFacts.classifyPageTableParent1 (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) {slot ptr a v b : U64} {m : Bool} (hx : slot ∈ OS) + (cap : capA st s slot = .PageTable ptr m a v) + (parent : VsNm st (PoolSet st Pp s) ∅ Lv s ptr b) : + ∃ tag asid sh va p o, (tag = 0#u64 ∨ tag = 2#u64) ∧ S1aPath st Pp n s tag asid sh va p ∧ + 12 < sh ∧ o.val < s1aTableWidth tag n sh ∧ o.val % 8 = 0 ∧ b = wa p o ∧ + s1aUserRange tag n (va + o.val / 8 * 2 ^ sh) (2 ^ sh) := by + obtain ⟨p, o, reach, level, width, al, rfl, edge, target⟩ := parent + have noKernel : ptr ∉ Kt := fun hk => h.lookup.kt ptr hk slot hx (Or.inl ⟨m, a, v, cap⟩) + rcases h.classifyEdge1 reach level width al edge target noKernel with + ⟨x, hs, _, capHigh, second, _⟩ | ⟨tag, asid, sh, va, stage, walk, deep, inWidth, range⟩ + · exact (h.highObjects.second_ne heap hs capHigh (h.pageObjects slot hx ptr m a v cap) second).elim + · exact ⟨tag, asid, sh, va, p, o, stage, walk, deep, inWidth, al, rfl, range⟩ + +/-- A raw Stage-2 parent of a PageTable is in the executable IPA domain. -/ +theorem S1aRouteFacts.classifyPageTableParent2 (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {ptr b : U64} (parent : S2Nm st (PoolSet st Pp s) Re bits s ptr b) : + ∃ asid sh va p o, S1aPath st Pp n s 1#u64 asid sh va p ∧ + 12 < sh ∧ o.val < s1aTableWidth 1#u64 n sh ∧ o.val % 8 = 0 ∧ b = wa p o ∧ + s1aUserRange 1#u64 n (va + o.val / 8 * 2 ^ sh) (2 ^ sh) := by + obtain ⟨p, o, reach, level, width, al, rfl, edge, _⟩ := parent + obtain ⟨asid, sh, va, walk⟩ := h.classifyStage2 reach + obtain ⟨inWidth, range⟩ := h.stage2Slot walk width al edge + have exactLevel := h.paths.tables _ _ _ _ _ walk + have depth : sh = 12 + 9 * Re p := (show _ ∧ _ ∧ _ from exactLevel).2.1 + exact ⟨asid, sh, va, p, o, walk, by omega, inWidth, al, rfl, range⟩ + +/-- Raw Stage-1 reachability is a High header, a kernel table, or an exact user walk. -/ +theorem S1aR2.classifyStage1 (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {p : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s p) : + p ∈ Kt ∨ + (∃ raw asid, ActiveAsidRoot st Pp s asid raw ∧ raw &&& 3#u64 = 2#u64 ∧ p = raw &&& ~~~3#u64) ∨ + ∃ tag asid sh va, (tag = 0#u64 ∨ tag = 2#u64) ∧ S1aPath st Pp n s tag asid sh va p := + h.routeFacts.classifyStage1 reach + +/-- Raw Stage-2 reachability follows the exact IPA walk. -/ +theorem S1aR2.classifyStage2 (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {p : U64} (reach : S2Reach st (PoolSet st Pp s) Re bits s p) : + ∃ asid sh va, S1aPath st Pp n s 1#u64 asid sh va p := + h.routeFacts.classifyStage2 reach + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Ept.lean b/proofs/Fl4ProofsA64/P1/S1aR2Ept.lean new file mode 100644 index 000000000..cf56e62cc --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Ept.lean @@ -0,0 +1,546 @@ +/- +P1 (aarch64, A64-S1A): Heap objects for table capabilities and the Stage-2 footprint. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Keep +import Fl4ProofsA64.P1.S1aBootW1 +import Fl4ProofsA64.P1.S1aHiRetype + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS Cs Pt Rp Nt : Set U64} {ia ie : Nat} {s s' : S} + +private theorem alikeEpt {p l a va : U64} {m : Bool} {c : capability.Cap} + (h : AlikeA (.Ept p l m a va) c) : ∃ l' m' a' va', c = .Ept p l' m' a' va' := by + obtain ⟨cls, kind⟩ := h.2 (h.1.1 (RngKeyA.ept p l m a va)) + cases c + all_goals try (exfalso; simp [kindA] at kind; done) + rename_i q l' m' a' va' + have same := ptrA_of_cls cls + rw [ptrA_ept, ptrA_ept] at same + exact ⟨l', m', a', va', by rw [same]⟩ + +/-- An Ept capability names an 8 KiB object with both granules in the VSpace footprint. -/ +def EptPlaceP (H : Heap) (Pt : Set U64) (c : capability.Cap) : Prop := + ∀ p l m a v, c = .Ept p l m a v → H p = some (.other 13) ∧ Gran {p} (fun _ => 13) ⊆ Pt + +def EptPlaced (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt : Set U64) (s : S) : Prop := + CapInv st (EptPlaceP H Pt) OS s + +theorem EptPlaceP.closed : CapSrcClosed (EptPlaceP H Pt) where + null := fun _ _ _ _ _ e => by cases e + zombie := fun _ _ _ _ _ _ _ _ e => by cases e + ut := fun _ _ _ _ _ _ _ _ _ e => by cases e + irq := fun _ _ _ _ _ _ e => by cases e + sub := fun _ _ _ _ _ _ _ _ e => by cases e + der := by + intro d c hc _ valid p l m a va he + subst d + rcases hc with alike | impossible + · obtain ⟨l', m', a', va', ec⟩ := alikeEpt alike + exact valid p l' m' a' va' ec + · cases impossible + remap := by + intro d c hm valid p l m a va hd + subst d + rcases hm with ⟨_, _, _, _, _, _, _, _, _, _, _, _, -, ed⟩ | ⟨_, _, _, _, _, _, _, -, ed⟩ | + ⟨_, _, _, _, _, -, ed⟩ | ⟨_, _, _, _, _, -, ed⟩ | ⟨q, level, old, asid, v, _, _, _, ec, ed⟩ <;> cases ed + exact valid _ _ old asid v ec + +theorem ArmQIAt.eptPlaced {Vc : Set U64} (h : ArmQIAt st H Cs OS Vc ia ie s s') + (pre : EptPlaced st H OS Pt s) : EptPlaced st H OS Pt s' := + h.capInv EptPlaceP.closed pre + +theorem AsgPost.eptPlaced (h : AsgPost st H OS s s') (pre : EptPlaced st H OS Pt s) : + EptPlaced st H OS Pt s' := by + intro x hx p l m a v cap + rcases h.al x hx with same | alike + · rw [same] at cap + exact pre x hx p l m a v cap + · rw [cap] at alike + obtain ⟨l', m', a', v', old⟩ := alikeEpt alike + exact pre x hx p l' m' a' v' old + +theorem EptPlaced.mono {Pt' : Set U64} (h : EptPlaced st H OS Pt s) (sub : Pt ⊆ Pt') : + EptPlaced st H OS Pt' s := fun x hx p l m a v cap => + let ⟨obj, granules⟩ := h x hx p l m a v cap + ⟨obj, granules.trans sub⟩ + +theorem EptPlaced.unmZ {Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + (h : EptPlaced st H OS Pt s) (r2 : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (pt : PtCap st Pt OS s) : + UnmZ st OS Pt (S2Rt st (PoolSet st Pp s) Te Re bits s) bits s := + r2.lookup.unmZPlaced heap pt fun x hx p a v eq => (h x hx p 0#u64 false a v eq).2 + +/-- Each PageTable cap names a 4 KiB heap object, including after detachment. -/ +def PtObjects (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS : Set U64) (s : S) : Prop := + PtCap st {p | H p = some (.other 12)} OS s + +/-- A HighVSpace cap names an exact 8 KiB object, including before ASID assignment. -/ +def HvObjects (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS : Set U64) (s : S) : Prop := + CapInv st (fun c => ∀ p m a, c = .HighVSpace p m a → H p = some (.other 13)) OS s + +theorem ArmQIAt.hvObjects {Vc : Set U64} (h : ArmQIAt st H Cs OS Vc ia ie s s') + (pre : HvObjects st H OS s) : HvObjects st H OS s' := + h.capInv (HvRootP.closed _) pre + +theorem AsgPost.hvObjects (h : AsgPost st H OS s s') (pre : HvObjects st H OS s) : + HvObjects st H OS s' := by + intro x hx p m a cap + rcases h.al x hx with kept | alike + · rw [kept] at cap + exact pre x hx p m a cap + · rw [cap] at alike + obtain ⟨m', a', old⟩ := al_hv alike + exact pre x hx p m' a' old + +theorem PtObjects.poolEnd {x v p sb fi i base slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (hx : x ∈ OS) (src : capA st s x = .Untyped p sb fi false) + (empty : cdt.ensure_no_children st s x = ok (.Ok ())) + (post : PoolPost st H OS s s' x v p sb i base) + (caps : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st s' y = capA st s y ∨ ∃ p' b' i' d', capA st s' y = .Untyped p' b' i' d') + (pre : PtObjects st H OS s) : + PtObjects 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) s' := by + have geom : PtHG H {p | H p = some (.other 12)} := PtHG.ofVcH P.heap fun _ hp => hp + have kept := pre.keptR (fun y hy t m a va cap => by + have obj : H t = some (.other 12) := pre y hy t m a va cap + have outside := PtHG.keyOffNC P B hx src empty geom hy + (by rw [cap]; exact RngKeyA.pt _ _ _ _) (by rw [cap, ptrA_pt]) obj + intro rem + obtain ⟨lo, hi⟩ := RegionD.inside (B.sys.ur.rin hx src) obj rem + simp only [HKind.bits] at hi + norm_num at hi + omega) + intro y hy t m a va cap + obtain ⟨obj, off⟩ := (PtCap.poolEnd post caps kept) y hy t m a va cap + have diff : t ≠ p := by + rintro rfl + apply off + simp only [RegionD, obj, Option.elim, MeetsR, HKind.bits] + norm_num + exact (Heap.add_of_not (N := (· = p)) (kd := .other sb.val) diff).trans ((Heap.drop_of_not off).trans obj) + + +private theorem vsCapObject {x p : U64} {size : Nat} + (tables : PtObjects st H OS s) (ept : EptPlaced st H OS Pt s) (hx : x ∈ OS) + (cap : VsC st x p size s) : + ∃ z, size = 2 ^ z ∧ H p = some (.other z) ∧ RngKeyA (capA st s x) ∧ + ptrA (capA st s x) = p ∧ kindA (capA st s x) ≠ 21 := by + rcases cap with ⟨rfl, m, a, v, hc⟩ | ⟨rfl, m, a, v, hc⟩ + · have eq := okinj ((capA_eq s x).symm.trans hc) + refine ⟨12, by norm_num, tables x hx p m a v eq, ?_⟩ + rw [eq] + exact ⟨RngKeyA.pt _ _ _ _, ptrA_pt _ _ _ _, by change 14 ≠ 21; decide⟩ + · have eq := okinj ((capA_eq s x).symm.trans hc) + refine ⟨13, by norm_num, (ept x hx p 0#u64 m a v eq).1, ?_⟩ + rw [eq] + exact ⟨RngKeyA.ept _ _ _ _ _, ptrA_ept _ _ _ _ _, by change 19 ≠ 21; decide⟩ + +theorem tableWordsNe (heap : HeapOK H) {p q o o' : U64} {z z' : Nat} + (hp : H p = some (.other z)) (hq : H q = some (.other z')) (ne : p ≠ q) + (lo : o.val < 2 ^ z) (lo' : o'.val < 2 ^ z') : + wa p o ≠ wa q o' := by + have pf := heap.fits p _ hp + have qf := heap.fits q _ hq + have sep := heap.disj p _ q _ hp hq ne + simp only [HKind.bits] at pf qf sep + intro eq + have hv := congrArg UScalar.val eq + rw [wadd_val (by omega : p.val + o.val < 2 ^ 64), + wadd_val (by omega : q.val + o'.val < 2 ^ 64)] at hv + rcases sep with h | h <;> omega + +/-- An exact PageTable object cannot overlap the second granule of a live HighVSpace. -/ +theorem HvObjects.second_ne (high : HvObjects st H OS s) (heap : HeapOK H) + {x r p : U64} {m : Bool} {a : U64} (hx : x ∈ OS) + (cap : capA st s x = .HighVSpace r m a) (table : H p = some (.other 12)) : + wa r 4096#u64 ≠ p := by + have root := high x hx r m a cap + have distinct : r ≠ p := by + rintro rfl + rw [table] at root + cases root + have separate := tableWordsNe heap root table distinct (o := 4096#u64) (o' := 0#u64) + (by decide) (by decide) + simpa [SFF.wadd0'] using separate + +/-- Exact table objects and active pool placement supply the two separation +clauses of the existing unmap case fact. -/ +theorem UnmU.ofTableObjects {Pp : Set U64} + (heap : HeapOK H) (tables : PtObjects st H OS s) (ept : EptPlaced st H OS Pt s) + (pools : PoolObj st H s) (named : PoolNamed st OS s) (kinds : KindA st OS s) + (unique : ∀ x ∈ OS, ∀ y ∈ OS, ∀ p size, UnmC st x p size s → NmC st y p s → y = x) : + UnmU st OS (PoolSet st Pp s) s where + one := unique + dis x hx y hy p q size size' c d ne o o' ho _ ho' _ := by + obtain ⟨z, rfl, hp, _⟩ := vsCapObject tables ept hx c + obtain ⟨z', rfl, hq, _⟩ := vsCapObject tables ept hy d + exact tableWordsNe heap hp hq ne ho ho' + pool x hx p size c o ho _ := by + rintro ⟨q, hq, o', ho', _, eq⟩ + obtain ⟨_, off, low, high, align, entry, nz⟩ := hq + obtain ⟨i, asidOff⟩ := atOff_of_off low high align + have poolCap := named i + rw [vspace.asid_table.eq, asidOff, entry, WP.spec_ok] at poolCap + obtain ⟨y, hy, base, hc⟩ := poolCap nz + obtain ⟨z, rfl, hp, key, ptr, kind⟩ := vsCapObject tables ept hx c + have hobj := pool_of_poolObjO pools low high align (by rwa [entry]) + rw [entry] at hobj + have key' : RngKeyA (capA st s y) := by rw [hc]; exact RngKeyA.ap _ _ + have neq : p ≠ q := by + intro same + apply kind + have sameKind := kinds.kind x hx y hy key key' (by rw [ptr, hc, ptrA_ap, same]) + rw [hc] at sameKind + exact sameKind + exact tableWordsNe heap hp hobj neq ho (by simpa using ho') eq + + +/-- A nonzero pool appears at most once among the real ASID-table indices. -/ +theorem PoolIdx.activeInjective (idx : PoolIdx st OS s) (named : PoolNamed st OS s) + {i j p : U64} (hi : i.val < 128) (hj : j.val < 128) (hn : p ≠ 0#u64) + (left : L.mem s (wa (L.ksb s) (AtOff i)) = p) (right : L.mem s (wa (L.ksb s) (AtOff j)) = p) : + i = j := by + have poolCap := named i + rw [vspace.asid_table.eq, left, WP.spec_ok] at poolCap + obtain ⟨slot, member, base, cap⟩ := poolCap hn + have sameIndex := (idx.get member cap).2 + exact UScalar.eq_of_val_eq ((sameIndex i hi left hn).trans (sameIndex j hj right hn).symm) + +/-- The allocation bases of Stage-2 VSpace objects in a retype. -/ +def NewEpt (nt aligned us win : U64) : Set U64 := + {p | nt.val = 13 ∧ ∃ j, j < win.val ∧ p = bjA aligned (zA nt.val us) j} + +private theorem newCapA_ept {nt : Nat} (bound : nt < 15) {base us p l a v : U64} + {dev m : Bool} (h : newCapA nt base us dev = .Ept p l m a v) : + nt = 13 ∧ p = base := by + interval_cases nt <;> simp [newCapA] at h ⊢ + exact h.1.symm + +private theorem eptOffNC {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot x p sb fi y t : U64} + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (hx : x ∈ OS) + (src : capA st s x = .Untyped p sb fi false) + (empty : cdt.ensure_no_children st s x = ok (.Ok ())) (hy : y ∈ OS) + (key : RngKeyA (capA st s y)) (base : ptrA (capA st s y) = t) (obj : H t = some (.other 13)) : + t.val + 8192 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ t.val := by + obtain ⟨_, _, ht, _, _⟩ := B.sys.stz.1.1.tree + have outside := cdt.ensure_no_children.noKey P.os ht.utRangeOrd B.sys.stz.1.2.1 hx src empty y hy key + rw [base] at outside + have inside := B.sys.ur.rin hx src t _ obj + simp only [HKind.bits, MeetsR] at inside + norm_num at inside + by_contra hh + have contained := inside (by omega) (by omega) + exact outside ⟨contained.1, by omega⟩ + +private theorem poolKeeps8K {x p sb fi t : U64} + (B : SysL st H Cs OS ia ie s) (hx : x ∈ OS) + (src : capA st s x = .Untyped p sb fi false) (size : sb = fl4_abi.consts.bits.ASID_POOL) + (obj : H t = some (.other 13)) : + PoolH (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) p sb.val t = some (.other 13) := by + have sb12 : sb.val = 12 := by rw [size]; first | rfl | decide | simp [fl4_abi.consts.bits.ASID_POOL] + have off : ¬ RegionD H p.val (p.val + 2 ^ sb.val) t := by + intro rem + obtain ⟨lo, hi⟩ := RegionD.inside (B.sys.ur.rin hx src) obj rem + simp only [HKind.bits, sb12] at hi + norm_num at hi + omega + have diff : t ≠ p := by + rintro rfl + apply off + simp only [RegionD, obj, Option.elim, MeetsR, HKind.bits, sb12] + norm_num + exact (Heap.add_of_not (N := (· = p)) (kd := .other sb.val) diff).trans ((Heap.drop_of_not off).trans obj) + +/-- MakePool's 4 KiB region cannot contain a live 8 KiB Stage-2 root. -/ +theorem EptPlaced.poolEnd {x v p sb fi i base : U64} + (B : SysL st H Cs OS ia ie s) (hx : x ∈ OS) + (src : capA st s x = .Untyped p sb fi false) (size : sb = fl4_abi.consts.bits.ASID_POOL) + (post : PoolPost st H OS s s' x v p sb i base) + (caps : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st s' y = capA st s y ∨ ∃ p' b' i' d', capA st s' y = .Untyped p' b' i' d') + (pre : EptPlaced st H OS Pt s) : + EptPlaced 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 s' := by + intro y hy t l m a va cap + have ne : y ≠ v := fun eq => by subst y; rw [post.capV] at cap; cases cap + rcases caps y hy ne with kept | ⟨_, _, _, _, unt⟩ + swap + · rw [unt] at cap + cases cap + rw [kept] at cap + obtain ⟨obj, granules⟩ := pre y hy.1 t l m a va cap + exact ⟨poolKeeps8K B hx src size obj, granules⟩ + +theorem HvObjects.poolEnd {x v p sb fi i base : U64} + (B : SysL st H Cs OS ia ie s) (hx : x ∈ OS) + (src : capA st s x = .Untyped p sb fi false) (size : sb = fl4_abi.consts.bits.ASID_POOL) + (post : PoolPost st H OS s s' x v p sb i base) + (caps : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st s' y = capA st s y ∨ ∃ p' b' i' d', capA st s' y = .Untyped p' b' i' d') + (pre : HvObjects st H OS s) : + HvObjects 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) s' := by + have before : HvPt st {t | H t = some (.other 13)} OS s := pre + intro y hy t m a cap + exact poolKeeps8K B hx src size (HvPt.poolEnd post caps before y hy t m a cap) + +section retype + +variable {U Ac : Set U64} {s0 s1 endState : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot p sb fi : U64} {dev : Bool} {H1 H' : Heap} {OS1 : Set U64} {lo hi : Nat} + {aligned nt us dest off win : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 + (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) + (B : SysL st H Cs OS ia ie s0) (source : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) + (E : UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 endState lo hi aligned nt us dest off win) + (X : UtX H H1 lo hi us) + (reset : H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ + lo = p.val ∧ hi = p.val + 2 ^ sb.val)) + (window : win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) + +include D P B source E X reset window + +omit X window in +private theorem eptOldOff {t y : U64} (hy : y ∈ OS) (obj : H t = some (.other 13)) + (key : RngKeyA (capA st s0 y)) (base : ptrA (capA st s0 y) = t) : + t.val + 8192 ≤ lo ∨ hi ≤ t.val := by + rcases reset with same | ⟨ram, ⟨v, empty⟩, rfl, rfl⟩ + · have outside := E.hole t _ (same.symm ▸ obj) + simpa [HKind.bits] using outside + · subst dev + cases v + have pre := UtDecP.of_live D B.sys P source B.ln B.vr B.ly + exact eptOffNC P B pre.src pre.cap empty hy key base obj + +omit X reset in +private theorem eptNewGeom {j : Nat} (hj : j < win.val) (kind : nt.val = 13) : + H' (bjA aligned (zA nt.val us) j) = some (.other 13) ∧ + (bjA aligned (zA nt.val us) j).val % 4096 = 0 ∧ + (bjA aligned (zA nt.val us) j).val + 8192 ≤ 2 ^ 64 := by + rcases window with no | ⟨_, args⟩ + · omega + have ram : dev = false := by + cases dev + · rfl + · exfalso + rcases UtArgs.devK args with h | h | h | h <;> omega + have typed := E.hn ram j hj (.other 13) (by rw [kind]; simp [newKind]) + have align := UtEnd.bjAl D P B source E args hj (by rw [kind]; simp [zA]) + have fit := (bj_facts hj (E.A.aw.trans E.A.pf)).2 + have exponent : (zA nt.val us).val = 13 := by rw [kind]; simp [zA] + have total := E.A.aw.trans E.A.pf + rw [exponent] at fit total + norm_num at fit total + exact ⟨typed, align, fit.trans total⟩ + +/-- A retype preserves old Ept objects and adds the two granules of each new Stage-2 root. -/ +theorem UtEnd.eptPlaced (old : EptPlaced st H OS Pt s0) : + EptPlaced st H' (OS1 ∪ NewSl dev nt us aligned win) + (PtOffR Pt lo hi ∪ Gran (NewEpt nt aligned us win) (fun _ => 13)) endState := by + have ksb : (L.ksb endState).val + 788736 ≤ 2 ^ 64 := by rw [E.E.fr.1.trans E.w1.1]; exact B.ly.ksw + apply CapInv.growN (P := EptPlaceP H' _) _ (EptPlaceP.closed.null) (E.freshN X ksb) + intro x hx t l m a v cap + by_cases same : x = slot + · subst x + obtain ⟨_, write⟩ := E.E.src + rw [write] at cap + cases cap + by_cases new : ∃ j, j < win.val ∧ x = djA dest off j + · obtain ⟨j, hj, rfl⟩ := new + rw [E.E.new j hj] at cap + obtain ⟨kind, rfl⟩ := newCapA_ept E.A.hn cap + refine ⟨(eptNewGeom D P B source E window hj kind).1, ?_⟩ + rintro q ⟨t, ht, granule⟩ + have same : t = bjA aligned (zA nt.val us) j := Set.mem_singleton_iff.mp ht + subst t + exact Or.inr ⟨_, ⟨kind, j, hj, rfl⟩, granule⟩ + rw [E.E.keep x hx same (fun j hj eq => new ⟨j, hj, eq⟩), E.k1 x hx same] at cap + obtain ⟨obj, granules⟩ := old x (E.os x hx) t l m a v cap + have outside := eptOldOff D P B source E reset (E.os x hx) obj + (by rw [cap]; exact RngKeyA.ept _ _ _ _ _) (by rw [cap, ptrA_ept]) + have kept : H1 t = some (.other 13) := by + rcases X.kept t _ obj with kept | gone + · exact kept + · simp only [HKind.bits] at gone + norm_num at gone + omega + have fit := P.heap.fits t _ obj + have upper : (wa t 4096#u64).val = t.val + 4096 := by + change t.val + 8192 ≤ 2 ^ 64 at fit + exact wadd_val (by change t.val + 4096 < 2 ^ 64; omega) + refine ⟨E.grow t _ kept, fun q hq => Or.inl ⟨granules hq, ?_⟩⟩ + obtain ⟨t', mem, same | ⟨_, same⟩⟩ := hq + · obtain rfl : t' = t := Set.mem_singleton_iff.mp mem + rw [same] + omega + · obtain rfl : t' = t := Set.mem_singleton_iff.mp mem + rw [same, upper] + omega + +omit X reset in +/-- The new Ept granules satisfy the existing typed footprint condition. -/ +theorem UtEnd.newEptPtHG : + PtHG H' (Gran (NewEpt nt aligned us win) (fun _ => 13)) := by + intro q hq + obtain ⟨t, ⟨kind, j, hj, rfl⟩, same | ⟨_, same⟩⟩ := hq <;> subst q + · obtain ⟨obj, align, _⟩ := eptNewGeom D P B source E window hj kind + exact ⟨align, _, 13, obj, le_rfl, by norm_num⟩ + · obtain ⟨obj, align, fit⟩ := eptNewGeom D P B source E window hj kind + have upper : (wa (bjA aligned (zA nt.val us) j) 4096#u64).val = + (bjA aligned (zA nt.val us) j).val + 4096 := by + exact wadd_val (by change (bjA aligned (zA nt.val us) j).val + 4096 < 2 ^ 64; omega) + exact ⟨by rw [upper]; omega, _, 13, obj, by rw [upper]; omega, by rw [upper]; norm_num⟩ + +/-- Retype preserves exact PageTable objects and creates the new ones at type 11's bases. -/ +theorem UtEnd.ptObjects (old : PtObjects st H OS s0) : + PtObjects st H' (OS1 ∪ NewSl dev nt us aligned win) endState := by + have ksb : (L.ksb endState).val + 788736 ≤ 2 ^ 64 := by rw [E.E.fr.1.trans E.w1.1]; exact B.ly.ksw + obtain ⟨cap, obj⟩ := UtEnd.ptCapH D P B source E X window reset old (fun _ h => h) + exact CapInv.growN (P := PtCapP {p | H' p = some (.other 12)}) + (fun y hy t m a v eq => obj t (cap y hy t m a v eq)) (PtCapP.null _) (E.freshN X ksb) + +/-- Retype preserves live HighVSpace objects and adds exactly the type 14 objects. -/ +theorem UtEnd.hvObjects (old : HvObjects st H OS s0) : + HvObjects st H' (OS1 ∪ NewSl dev nt us aligned win) endState := by + have ksb : (L.ksb endState).val + 788736 ≤ 2 ^ 64 := by + rw [E.E.fr.1.trans E.w1.1] + exact B.ly.ksw + apply CapInv.growN (P := fun c => ∀ t m a, c = .HighVSpace t m a → H' t = some (.other 13)) + _ (fun _ _ _ e => by cases e) (E.freshN X ksb) + intro x hx t m a cap + by_cases same : x = slot + · subst x + obtain ⟨_, write⟩ := E.E.src + rw [write] at cap + cases cap + by_cases new : ∃ j, j < win.val ∧ x = djA dest off j + · obtain ⟨j, hj, rfl⟩ := new + rw [E.E.new j hj] at cap + obtain ⟨kind, rfl⟩ := newCapA_hv E.A.hn cap + rcases window with zero | ⟨_, args⟩ + · omega + have ram : dev = false := by + cases dev + · rfl + · exfalso + rcases UtArgs.devK args with h | h | h | h <;> omega + exact E.hn ram j hj (.other 13) (by rw [kind]; simp [newKind]) + rw [E.E.keep x hx same (fun j hj eq => new ⟨j, hj, eq⟩), E.k1 x hx same] at cap + have obj := old x (E.os x hx) t m a cap + have outside := eptOldOff D P B source E reset (E.os x hx) obj + (by rw [cap]; exact RngKeyA.hv _ _ _) (by rw [cap, ptrA_hv]) + apply E.grow + rcases X.kept t _ obj with kept | gone + · exact kept + · simp only [HKind.bits] at gone + norm_num at gone + omega + +/-- The ordinary and Stage-2 retype footprints share one post-state heap and slot set. -/ +theorem UtEnd.eptAndPt (old : EptPlaced st H OS Pt s0) (pt : PtCap st Pt OS s0) (heap : PtHG H Pt) + (hv : HvPt st Pt OS s0) : + ∃ Pt' : Set U64, EptPlaced st H' (OS1 ∪ NewSl dev nt us aligned win) Pt' endState ∧ + PtCap st Pt' (OS1 ∪ NewSl dev nt us aligned win) endState ∧ + HvPt st Pt' (OS1 ∪ NewSl dev nt us aligned win) endState ∧ PtHG H' Pt' := by + let stage2 := Gran (NewEpt nt aligned us win) (fun _ => 13) + let base := PtOffR Pt lo hi + let stage1 := NewPt nt aligned us win + let all := (base ∪ stage1) ∪ stage2 + have incl1 : base ∪ stage1 ⊆ all := fun _ hg => Or.inl hg + have incl2 : base ∪ stage2 ⊆ all := fun _ hg => hg.elim (fun hb => Or.inl (Or.inl hb)) Or.inr + obtain ⟨placed, typed⟩ := UtEnd.ptCapHG D P B source E X window reset pt heap + exact ⟨all, (UtEnd.eptPlaced D P B source E X reset window old).mono incl2, + (fun x hx p m a v hc => incl1 (placed x hx p m a v hc)), + HvPt.mono incl1 (UtEnd.hvPtN D P B source E X reset heap hv), + PtHG.union typed (UtEnd.newEptPtHG D P B source E window)⟩ + +end retype + +/-- Retype exports Stage-2 root placement over the same heap, slots and footprint +as the ordinary table and reserved HighVSpace facts. -/ +theorem syscall.decode_invocation.retype_eptPlaced {A : Type _} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) {U Ac Sg Scs Vq Uq Vc Ub : Set U64} {Z : U64 → Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) + (source : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (masks : A64FrameMasks st s) + (vr : VrOK H.omega Sg Scs Z OS Vq Uq (L.ksb s) Pt) (pools : PoolNamed st OS s) + (C : S1aArmCol st H Cs OS Vc Ub s) (K : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) + (vc : VcCap st Vc OS s) (pt : PtCap st Pt OS s) (ptHeap : PtHG H Pt) + (ept : EptPlaced st H OS Pt s) (frame : DevFrAl st OS s) + (hv : HvPt st Pt OS s) (hi : HiCap511 st OS s) (objects : PtObjects st H OS s) + (highObjects : HvObjects st H OS s) (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Untyped p sb fi dev) blk call don fp buf extra ⦃ _ s' _ => + ∃ (H' : Heap) (OS' Vn Vc' Pt' : Set U64), ArmQIVAt st H Cs OS ia ie s H' OS' Vn s' ∧ TabKeep st s s' ∧ + Vc' ⊆ Vc ∪ Vn ∧ VcCap st Vc' OS' s' ∧ S1aArmCol st H' Cs OS' Vc' Ub s' ∧ S1aCapCol st H' OS' Ub s' ∧ + EptPlaced st H' OS' Pt' s' ∧ PtCap st Pt' OS' s' ∧ HvPt st Pt' OS' s' ∧ PtHG H' Pt' ∧ DevFrAl st OS' s' ∧ + HiCap511 st OS' s' ∧ PtObjects st H' OS' s' ∧ HvObjects st H' OS' s' ⦄ := by + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + refine WP.spec_mono (WP.spec_and + (untyped.decode.s1aRtVJH hA D P B Y source masks vr pools C K hal vc a lbl len buf + (fun H' O endState => + (∃ Pt' : Set U64, EptPlaced st H' O Pt' endState ∧ PtCap st Pt' O endState ∧ HvPt st Pt' O endState ∧ + PtHG H' Pt' ∧ DevFrAl st O endState) ∧ + (HrW st (HvRt st OS s) s endState → HiCap511 st O endState) ∧ PtObjects st H' O endState ∧ HvObjects st H' O endState) + ⟨⟨Pt, ept, pt, hv, ptHeap, frame⟩, fun _ => hi, objects, highObjects⟩ ?_) + (untyped.decode.keepOldHi hA D P B source masks vr ptHeap hv a lbl len buf)) ?_ + · intro _ _ _ _ _ _ _ _ _ _ _ _ _ E X hw hp init + obtain ⟨_, e1, e2, e3, e4⟩ := UtEnd.eptAndPt D P B source E X hp hw ept pt ptHeap hv + exact ⟨⟨_, e1, e2, e3, e4, UtEnd.devFrN D P B source E X hw frame⟩, + fun keep => E.hiCap511 X B.ly.ksw init keep hi, UtEnd.ptObjects D P B source E X hp hw objects, + UtEnd.hvObjects D P B source E X hp hw highObjects⟩ + · rintro _ ⟨⟨H', OS', Vn, Vc', ⟨h1, h2, h3, h4, h5, h6⟩, ⟨Pt', e1, e2, e3, e4, e5⟩, finish, objects', highObjects'⟩, keep⟩ + exact ⟨H', OS', Vn, Vc', Pt', h1, h2, h3, h4, h5, h6, e1, e2, e3, e4, e5, finish keep, objects', highObjects'⟩ + +namespace BootWit + +theorem w0_hvObjects {kb ib r now mt : U64} {nc : Nat} (P : BootLay kb ib nc) : + HvObjects bst (bootH kb ib nc) (bootOS kb ib nc) (bootS kb ib nc r now mt) := by + intro x hx _ _ _ cap + rw [boot_null P x hx] at cap + cases cap + +theorem w1_hvObjects {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} (P : BootLay1 kb ib nc) : + HvObjects bst (w1H kb ib nc) (w1OS kb ib nc) (w1S kb ib nc r now mt sl uw) := + fun _ hx p m a cap => ((w1_ptCapK P hx).2 p m a cap).elim + +theorem w0_ptObjects {kb ib r now mt : U64} {nc : Nat} (P : BootLay kb ib nc) : + PtObjects bst (bootH kb ib nc) (bootOS kb ib nc) (bootS kb ib nc r now mt) := by + intro x hx _ _ _ _ cap + rw [boot_null P x hx] at cap + cases cap + +theorem w1_ptObjects {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} (P : BootLay1 kb ib nc) : + PtObjects bst (w1H kb ib nc) (w1OS kb ib nc) (w1S kb ib nc r now mt sl uw) := + fun _ hx t m a v cap => w1_pt t ((w1_ptCapK P hx).1 t m a v cap) + +theorem w0_eptPlaced {kb ib r now mt : U64} {nc : Nat} (P : BootLay kb ib nc) (Pt : Set U64) : + EptPlaced bst (bootH kb ib nc) (bootOS kb ib nc) Pt (bootS kb ib nc r now mt) := by + intro x hx _ _ _ _ _ hc + rw [boot_null P x hx] at hc + cases hc + +set_option maxHeartbeats 2000000 in +theorem w1_eptPlaced {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} (P : BootLay1 kb ib nc) (Pt : Set U64) : + EptPlaced bst (w1H kb ib nc) (w1OS kb ib nc) Pt (w1S kb ib nc r now mt sl uw) := by + intro x hx p l m a v cap + rcases w1_capS P hx with e | ⟨i, _, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, _, _, e⟩ <;> + rw [e] at cap <;> try cases cap + all_goals (revert cap; capsplit (intro cap; cases cap)) + +end BootWit + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Field.lean b/proofs/Fl4ProofsA64/P1/S1aR2Field.lean new file mode 100644 index 000000000..2ee74cf65 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Field.lean @@ -0,0 +1,170 @@ +/- +P1 (aarch64): R2 as a field of the deletion loops (A64-S1A gen 41). + +`LoopMP.r2M` adds R2 to a `LoopMP` field whose invariant gives `MdbS`: `M` gains `S1aDelM`, `Pn` gains +`S1aDelPn`, `Zr` gains that the slot's capability is not read by R2. The finalisation of a VSpace +capability is the one obligation left to the caller (`S1aFinVs`); every other step is proved here. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Loop +import Fl4ProofsA64.P1.QueueZombieQ +import Fl4ProofsA64.P1.QueueVsKeep +import Fl4ProofsA64.P1.MdbDelIn +import Fl4ProofsA64.P1.MdbCapI + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {Cs Ac OS D Vc Ub Pt Pp Tb Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {K : capability.Cap → Prop} {Ty : S → Prop} {s0 : S} + +/-- The capability kinds of the VSpace layer, whose finalisation may write translation state. -/ +def S1aVsCap : capability.Cap → Prop + | .PageTable .. | .PageDirectory .. | .Pdpt .. | .Pml4 .. | .HighVSpace .. | .Ept .. | .Frame .. + | .AsidPool .. => True + | _ => False + +theorem S1aVsCap.unread {c : capability.Cap} (h : ¬ S1aVsCap c) : ¬ S1aR2Reads c := fun reads => by + cases c <;> first | exact h trivial | exact reads + +/-- The remaining obligation: finalising a VSpace capability leaves R2 over the other slots. -/ +def S1aFinVs (st : machine.Store S) [L : LawfulStore st] (ar : machine.Arch A) (OS : Set U64) + (C M0 : S → Prop) (X : S → U64 → capability.Cap → Prop) (H : Heap) (Pt Pp Tb Te Kt : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) : Prop := + ∀ (s : S) (a : A) (x : U64) (c : capability.Cap) (f : Bool), C s → M0 s → + S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s → x ∈ OS → obj.Slot.cap st x s = ok c → X s x c → + cdt.is_final_capability_with_cap st s x c = ok f → S1aVsCap c → + objects.finalise_cap st ar s a c f false ⦃ r => r.1.1 = .Null ∧ + S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n r.2.1 x ⦄ + +/-- A write set of slot words keeps every VSpace word. -/ +private theorem vsKeepSlots {Omega Sg Scs : Set U64} {Z : U64 → Nat} {kb : U64} + (vr : VrOK Omega Sg Scs Z OS Vc Ub kb Pt) {s s' : S} + (w : WritesIn st s s' (W7.CapW ∅ {b | InOS OS b} ∅)) : VsKeep st kb Pt s s' := fun b hb => by + have hA : VsR kb Pt b := hb + exact w.mem_eq (vr.al _ hA) fun hc => by + rcases hc with ⟨t, ht, -⟩ | ⟨hin, -⟩ + · exact absurd ht (Set.notMem_empty t) + · exact vr.os _ hA hin + +/-- The in-place `Zombie` write: its slot and the other capabilities. -/ +theorem obj.Slot.set_cap.zombieCaps {T Omega Sg : Set U64} (hO : OSOK T Omega Sg OS) {s : S} {x p t n : U64} + (hx : x ∈ OS) (hp : Canon p) : + obj.Slot.set_cap st x s (.Zombie p t n) ⦃ s' => L.ksb s' = L.ksb s ∧ (∃ t', capA st s' x = .Zombie p t' n) ∧ + ∀ y ∈ OS, y ≠ x → capA st s' y = capA st s y ⦄ := by + rw [set_cap_zombie, WP.spec_ok] + exact ⟨by simp, ⟨_, capA_wr2_self hO hx (decode_zw p t n hp)⟩, fun _ hy e => capA_wr2_other hO hx hy e⟩ + +set_option maxHeartbeats 2000000 in +/-- R2 added to a `LoopMP` field of the deletion loops. -/ +theorem LoopMP.r2M {M0 : S → Prop} {Zr : S → U64 → U64 → U64 → U64 → Prop} {Pn : S → U64 → Prop} + (E : DelS ar H OS D Vc Ub Pt (L.ksb s0)) (vsK : ∀ c, K c → S1aVsCap c) + (hM : LoopMP st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) Zr Pn M0) + (hMS : ∀ s, M0 s → MdbS st OS s) + (hFin : S1aFinVs st ar OS (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + M0 (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) H Pt Pp Tb Te Kt Lv Re bits n) : + LoopMP st ar OS D (JV st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac OS Vc Ub s0) + (XQF st K Vc D H.scs H.tcbs Ty (L.ksb s0)) + (fun s x p t n' => Zr s x p t n' ∧ ¬ S1aR2Reads (capA st s x)) + (fun s x => Pn s x ∧ S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n s x) + (fun s => M0 s ∧ S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s) where + fin s a x c f hC m hx hc hX hf := by + have base := hM.fin s a x c f hC m.1 hx hc hX hf + have capx : capA st s x = c := okinj ((capA_eq s x).symm.trans hc) + by_cases vs : S1aVsCap c + · refine WP.spec_mono (WP.spec_and base (hFin s a x c f hC m.1 m.2 hx hc hX hf vs)) ?_ + rintro r ⟨⟨z, p, q⟩, null, pending⟩ + have removable : cdt.cap_removable r.1.1 x = ok true := by rw [null]; rfl + exact ⟨fun p' t n' e => (by rw [null] at e; cases e), + fun h => ⟨p h, pending⟩, fun h => (h removable).elim⟩ + · obtain ⟨zq, _, irq⟩ := hX + have zs : ZS Vc D H.scs (L.idleW s) (L.mem s (scA (L.idleW s))) c := + zq.elim (fun h => h.1) (fun h => (vs (vsK c h)).elim) + have words := finVK E.arch E.os E.sca E.vc E.vr hC E.irq irq hx hc zs a f + have slots := finXS (ar := ar) E.arch E.os E.sca E.vc hC E.irq irq hx hc zs a f + refine WP.spec_mono (WP.spec_and base (WP.spec_and slots words)) ?_ + rintro r ⟨⟨z, p, q⟩, ⟨_, after, kept, _⟩, mem⟩ + have ksb : L.ksb r.2.1 = L.ksb s := after.ksb.trans hC.ksb.symm + have memHere : VsKeep st (L.ksb s) Pt s r.2.1 := by rw [hC.ksb]; exact mem + have caps : ∀ y ∈ OS, S1aCapSame st s r.2.1 y := by + intro y hy + rcases kept y hy with same | ⟨node, empty⟩ + · exact Or.inl (okinj ((capA_eq _ _).symm.trans (same.trans (capA_eq _ _)))) + · refine Or.inr ⟨?_, ?_⟩ + · obtain ⟨i, hi, rfl⟩ := node + rcases irq i hi _ (capA_eq s _) with ⟨_, _, _, _, e⟩ | e <;> (rw [e]; exact id) + · rw [okinj ((capA_eq _ _).symm.trans empty)] + exact id + have next := S1aDelM.keep m.2 ksb memHere caps + have unread : ¬ S1aR2Reads (capA st r.2.1 x) := by + rcases kept x hx with same | ⟨_, empty⟩ + · rw [okinj ((capA_eq _ _).symm.trans (same.trans hc))] + exact S1aVsCap.unread vs + · rw [okinj ((capA_eq _ _).symm.trans empty)] + exact id + exact ⟨fun p' t n' e => ⟨z p' t n' e, unread⟩, fun h => ⟨p h, next.drop unread⟩, + fun h => ⟨q h, next⟩⟩ + en s x m hc := ⟨hM.en s x m.1 hc, m.2.drop (by rw [okinj ((capA_eq s x).symm.trans hc)]; exact id)⟩ + setz s x p t n' hC m hx hp hz := by + obtain ⟨Ac', hb⟩ := hC.1.parts + have q := hb.1.choose_spec.choose_spec + refine WP.spec_mono (WP.spec_and (hM.setz s x p t n' hC m.1 hx hp hz.1) + (WP.spec_and (W7.obj.Slot.set_cap.capw (osw E.os hx)) (obj.Slot.set_cap.zombieCaps E.os hx hp))) ?_ + rintro s' ⟨m0, w, base, ⟨t', here⟩, other⟩ + refine ⟨m0, ?_⟩ + have mem : VsKeep st (L.ksb s) Pt s s' := by rw [hC.ksb]; exact vsk_cw q E.vr w + refine S1aDelM.keep m.2 base mem fun y hy => ?_ + by_cases e : y = x + · subst e + exact Or.inr ⟨hz.2, by rw [here]; exact id⟩ + · exact Or.inl (other y hy e) + setd s x p t n' hC m hx hp hz he hn := by + obtain ⟨Ac', hb⟩ := hC.1.parts + have q := hb.1.choose_spec.choose_spec + refine WP.spec_mono (WP.spec_and (hM.setd s x p t n' hC m.1 hx hp hz he hn) + (WP.spec_and (W7.obj.Slot.set_cap.capw (osw E.os hx)) (obj.Slot.set_cap.zombieCaps E.os hx hp))) ?_ + rintro s' ⟨m0, w, base, ⟨t', here⟩, other⟩ + refine ⟨m0, ?_⟩ + have mem : VsKeep st (L.ksb s) Pt s s' := by rw [hC.ksb]; exact vsk_cw q E.vr w + refine S1aDelM.keep m.2 base mem fun y hy => ?_ + by_cases e : y = x + · subst e + refine Or.inr ⟨?_, by rw [here]; exact id⟩ + rw [okinj ((capA_eq s y).symm.trans hz)] + exact id + · exact Or.inl (other y hy e) + swap s p y hC m hp hy hne hz := by + have words := cdt.cap_swap_for_delete.capxW E.os (hMS s m.1) (E.dom hp) (E.dom hy) (E.dcan p hp) (E.dcan y hy) + refine WP.spec_mono (WP.spec_and (hM.swap s p y hC m.1 hp hy hne hz) words) ?_ + rintro s' ⟨m0, w, first, second, other⟩ + have mem : VsKeep st (L.ksb s) Pt s s' := by rw [hC.ksb]; exact vsKeepSlots E.vr w + exact ⟨m0, m.2.swap (E.dom hp) (E.dom hy) w.1 mem first second other⟩ + pre s a hC m := by + refine WP.spec_mono (WP.spec_and (hM.pre s a hC m.1) (WP.spec_and + (sched.preemption_point.jv E.arch E.os E.vc hC (by rw [hC.ksb]; exact E.wu)) + (sched.preemption_point.vk E.arch E.vr hC hC.ksb))) ?_ + rintro r ⟨m0, ⟨after, kept, _⟩, mem⟩ + refine ⟨m0, S1aDelM.keep m.2 (after.ksb.trans hC.ksb.symm) (by rw [hC.ksb]; exact mem) + fun y hy => Or.inl ?_⟩ + have same := kept y hy + have words : obj.Slot.cap st y r.2.1 = obj.Slot.cap st y s := by + rw [DPF.slot_cap_dec, DPF.slot_cap_dec, same.1, same.2.1] + exact okinj ((capA_eq _ _).symm.trans (words.trans (capA_eq _ _))) + emp s a x cl hC m hx hcl := by + refine WP.spec_mono (WP.spec_and (hM.emp s a x cl hC m.1 hx hcl) (WP.spec_and + (cdt.empty_slot.zs E.arch E.os E.vc hC hx hcl E.irqSt) + (cdt.empty_slot.vk E.arch E.os E.vr hC hx hcl hC.ksb))) ?_ + rintro r ⟨m0, ⟨after, kept, empty, _⟩, mem⟩ + refine ⟨m0, ?_⟩ + refine S1aDelPn.restore m.2 (after.ksb.trans hC.ksb.symm) (by rw [hC.ksb]; exact mem) + (fun y hy e => Or.inl ?_) (by rw [okinj ((capA_eq _ _).symm.trans empty)]; exact id) + have same := kept y hy e + have words : obj.Slot.cap st y r.1 = obj.Slot.cap st y s := by + rw [DPF.slot_cap_dec, DPF.slot_cap_dec, same.1, same.2] + exact okinj ((capA_eq _ _).symm.trans (words.trans (capA_eq _ _))) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FinAlias.lean b/proofs/Fl4ProofsA64/P1/S1aR2FinAlias.lean new file mode 100644 index 000000000..2a0550f99 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FinAlias.lean @@ -0,0 +1,149 @@ +/- +P1 (aarch64): finalising the `PageDirectory` / `Pdpt` alias capabilities and assembling the VSpace +finalisation obligation (A64-S1A gen 41). + +R2 does not read these two kinds. Their finalisation runs `unmap_page_table`, which only clears +descriptors: R2 survives it whatever table it is asked for. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FinRoot +import Fl4ProofsA64.P1.S1aR2FinFrame + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Vc Ub T Ω Sg Scs : Set U64} {Z : U64 → Nat} {Lv Re bits : U64 → Nat} + {n x : U64} {s q : S} + +/-- A write that only keeps or clears VSpace words, away from the ASID table and the HighVSpace +headers, keeps R2. -/ +theorem S1aR2.clearing (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (kinds : KindA st OS s) (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (table : TabKeep st s q) (mem : VsZ st (L.ksb s) Pt s q) (headers : HrW st Hr s q) + (caps : ∀ y ∈ OS, capA st q y = capA st s y) : + S1aR2 st H OS Pt Pp Tb (HvRt st OS q) Te Kt Lv Re bits n q := by + have tab := table.toDel + have poolWord (p : U64) (hp : p ∈ PoolSet st Pp s) (o : U64) (ho : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) ∨ L.mem q (wa p o) = 0#u64 := + mem _ (Or.inl ⟨p, h.place.pools hp, o, ho, al, rfl⟩) + have highSame : HvRt st OS q = Hr := by + rw [h.highRoots] + ext p + constructor <;> rintro ⟨y, hy, m, a, eq⟩ + · exact ⟨y, hy, m, a, (caps y hy).symm.trans eq⟩ + · exact ⟨y, hy, m, a, (caps y hy).trans eq⟩ + have rootBack : ∀ a raw, ActiveAsidRoot st Pp q a raw → ActiveAsidRoot st Pp s a raw := + fun _ _ e => e.back tab poolWord + have back : ∀ tag a sh va t, S1aPath st Pp n q tag a sh va t → S1aPath st Pp n s tag a sh va t := by + intro _ _ _ _ _ path + refine path.back rootBack (fun a raw entry kind => ?_) + (fun _ _ _ _ _ old _ bd al => mem _ (Or.inl (h.pathWord old bd al))) + obtain ⟨y, hy, backed⟩ := h.core.root.backed a raw entry + rw [kind] at backed + rcases backed with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, backed⟩ + · cases bad + · cases bad + exact headers _ (by rw [h.highRoots]; exact ⟨y, hy, true, a, backed⟩) + refine h.zeroedOn heap kinds tab mem headers (Set.Subset.refl _) caps + (VsLk.activeZero h.core place tab mem caps (h.eptRoots.unmZ h.core heap h.pageTables)) + (h.core.root.activeZero place.pools tab mem caps) (h.core.stage1.activeZero place.pools place.tables tab mem) + (by rw [highSame]; exact h.core.stage2.activeZero place.pools place.granules place.stage2 tab mem headers) + (h.poolCaps.zero table poolWord (fun y hy _ _ => by rw [caps y hy])) + (h.paths.shrink back + (fun tag a sh va t path _ bd al => mem _ (Or.inl (h.pathWord (back tag a sh va t path) bd al))) + (fun _ _ _ _ _ _ _ y hy _ eq => ⟨y, hy, (caps y hy).trans eq⟩) + (fun _ _ _ _ _ _ _ _ y hy _ _ _ _ _ => ⟨y, hy, caps y hy⟩)) + +/-- Finalising a `PageDirectory` or `Pdpt` capability: `(Null, Null)`, and R2 over the other slots. -/ +theorem S1aFin.alias (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (hO : OSOK T Ω Sg OS) + (vr : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s) Pt) (heap : HeapOK H) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) (high : HvRt st OS s ⊆ Hr) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (M : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa s) (kinds : KindA st OS s) (hx : x ∈ OS) + {ptr asid va : U64} {m f : Bool} {c : capability.Cap} (cap : capA st s x = c) + (alias_ : c = .PageDirectory ptr m asid va ∨ c = .Pdpt ptr m asid va) (a : A) : + objects.finalise_cap st ar s a c f false ⦃ r => r.1.1 = .Null ∧ + S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa r.2.1 x ⦄ := by + have R : S1aR2 st H OS Pt Pp Tb (HvRt st OS s) Te Kt Lv Re bits hPl.ipa s := M + have here : S1aR2Place Pt Pp Tb (HvRt st OS s) Te Lv bits (L.ksb s) := place.monoHigh high + have aligned b (hb : VsR (L.ksb s) Pt b) : Aligned b := vr.al b hb + have unread : ¬ S1aR2Reads (capA st s x) := by + rw [cap] + rcases alias_ with rfl | rfl <;> exact id + have untouched : S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa s x := M.drop unread + have walk : vspace.unmap_page_table st ar s a asid va ptr ⦃ r => + S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa r.1 x ⦄ := by + refine WP.spec_mono (vspace.unmap_page_table.activeWrites hA hPl a R.core here aligned asid va ptr) + fun r ⟨words, headers, write⟩ => ?_ + have writes := Wr0.w (fun b hb => vr.al b (Or.inl hb)) write + have table : TabKeep st s r.1 := ⟨writes.1, fun i => by + rw [writes.1] + exact writes.mem_eq (vr.al _ (Or.inr (asW_at _ i))) (fun p => ptKs _ p (asW_at _ i))⟩ + have caps : ∀ y ∈ OS, capA st r.1 y = capA st s y := fun y hy => by + have keep := capk_vsr vr hO (writes.mono fun _ hw => Or.inl hw) y hy + rw [capA_eq, capA_eq] at keep + exact okinj keep + refine (R.clearing heap kinds here table words headers caps).toDelM.drop ?_ + rw [caps x hx] + exact unread + rcases alias_ with rfl | rfl + all_goals + rw [fin_cap_eq_obj (by simp)] + unfold objects.finalise_cap_object + dsimp only + cases f + · simp only [Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 ⟨rfl, untouched⟩ + cases m + · simp only [Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 ⟨rfl, untouched⟩ + simp only [↓reduceIte] + · refine WP.spec_bind (Pₘ := fun r : S × A => S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa r.1 x) ?_ + fun r pending => (WP.spec_ok _).2 ⟨rfl, pending⟩ + unfold vspace.unmap_page_directory + exact walk + · refine WP.spec_bind (Pₘ := fun r : S × A => S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa r.1 x) ?_ + fun r pending => (WP.spec_ok _).2 ⟨rfl, pending⟩ + unfold vspace.unmap_pdpt + exact walk + +/-- The VSpace finalisation obligation of `LoopMP.r2M`, from the context of the loop's start. -/ +theorem S1aFinVs.of {C M0 : S → Prop} {X : S → U64 → capability.Cap → Prop} {kb : U64} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (hO : OSOK H.tcbs H.omega H.frame OS) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub kb Pt) (heap : HeapOK H) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits kb) (ptKs : ∀ b, PtW Pt b → ¬ AsW kb b) + (base : ∀ s, C s → L.ksb s = kb) (high : ∀ s, M0 s → HvRt st OS s ⊆ Hr) (mdb : ∀ s, M0 s → MdbS st OS s) : + S1aFinVs st ar OS C M0 X H Pt Pp Tb Te Kt Lv Re bits hPl.ipa := by + intro s a x c f hC m0 M hx hc _ final vs + have ksb := base s hC + subst ksb + have here := high s m0 + have mdbs := mdb s m0 + have kinds : KindA st OS s := by + obtain ⟨_, _, _, hK, _, _⟩ := mdbs + exact hK + have cap : capA st s x = c := okinj ((capA_eq s x).symm.trans hc) + cases c with + | PageTable ptr mapped asid va => exact S1aFin.pageTable hA hPl hO vr heap place here ptKs M mdbs hx cap final a + | PageDirectory ptr mapped asid va => + exact S1aFin.alias hA hPl hO vr heap place here ptKs M kinds hx cap (Or.inl rfl) a + | Pdpt ptr mapped asid va => exact S1aFin.alias hA hPl hO vr heap place here ptKs M kinds hx cap (Or.inr rfl) a + | Pml4 ptr mapped asid => + exact S1aFin.root hA hO vr heap place here ptKs M mdbs hx cap (Or.inl ⟨_, _, rfl⟩) final a + | HighVSpace ptr mapped asid => + exact S1aFin.root hA hO vr heap place here ptKs M mdbs hx cap (Or.inr (Or.inl ⟨_, _, rfl⟩)) final a + | Ept ptr level mapped asid va => + by_cases zero : level = 0#u64 + · subst zero + exact S1aFin.root hA hO vr heap place here ptKs M mdbs hx cap (Or.inr (Or.inr ⟨_, _, _, rfl⟩)) final a + · exact S1aFin.eptInner hO heap M mdbs hx cap zero final a + | Frame ptr size rights dev mapped ept asid va => + exact S1aFin.frame hA hPl vr hO heap place here M kinds hx ptKs ⟨ptr, size, rights, dev, mapped, ept, asid, va⟩ cap f a + | AsidPool ptr base' => exact S1aFin.pool hA hO vr heap place here M mdbs hx cap final a + | _ => exact vs.elim + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FinFrame.lean b/proofs/Fl4ProofsA64/P1/S1aR2FinFrame.lean new file mode 100644 index 000000000..6758f1fbf --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FinFrame.lean @@ -0,0 +1,74 @@ +/- +P1 (aarch64): finalising a frame capability leaves R2 over the other slots (A64-S1A gen 41). + +The finalisation unmaps the leaf the capability recorded; it does not rewrite the capability. R2 over +the other slots is read off the state in which it is also reset: that write touches only the slot. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Field +import Fl4ProofsA64.P1.S1aR2Zeroed +import Fl4ProofsA64.P1.S1aR2FrameUnmapPost + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Vc Ub : Set U64} {Lv Re bits : U64 → Nat} {x : U64} {s : S} + +/-- Finalising a frame capability: `(Null, Null)`, and R2 over the other slots. -/ +theorem S1aFin.frame (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (os : OSOK H.tcbs H.omega H.frame OS) (heap : HeapOK H) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) (high : HvRt st OS s ⊆ Hr) + (M : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa s) (kinds : KindA st OS s) (hx : x ∈ OS) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) (f : vspace.FrameCap) + (cap : capA st s x = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + (fin : Bool) (a : A) : + objects.finalise_cap st ar s a (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + fin false ⦃ r => r.1.1 = .Null ∧ S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa r.2.1 x ⦄ := by + have hS : P0.StoreTotal st := L.total + have R : S1aR2 st H OS Pt Pp Tb (HvRt st OS s) Te Kt Lv Re bits hPl.ipa s := M + have aligned b (hb : PtW Pt b) : Aligned b := vr.al b (Or.inl hb) + have here : S1aR2Place Pt Pp Tb (HvRt st OS s) Te Lv bits (L.ksb s) := place.monoHigh high + rw [fin_cap_eq_obj (by simp)] + unfold objects.finalise_cap_object + dsimp only + refine WP.spec_bind (s1aFrameRemove (f := f) hA hPl a R aligned) ?_ + rintro ⟨mid, a1⟩ ⟨zero, clear⟩ + simp only at zero clear + have pending : S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa mid x := by + have wf : CapRt.EncWf (capA st s x) := CapRt.decodeF_encWf _ _ + rw [cap] at wf + have wf' : CapRt.EncWf (.Frame f.ptr f.size f.rights f.is_device false false 0#u64 0#u64) := by + cases stage : f.is_ept <;> simp only [stage, CapRt.EncWf] at wf <;> + exact ⟨wf.1, wf.2.1, by simp, canon0⟩ + have sub : TbO Tb (HvRt st OS s) ∪ Gran Te bits ⊆ Pt := + Set.union_subset (tbo_sub.trans here.tables) here.granules + have keep := TabKeep.ofW vr ((zero.mono sub).w aligned) ptKs + have inMid : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb mid) Pt := by + rw [keep.1]; exact vr + have both := WP.spec_and + (obj.Slot.set_cap.frameUnmapTail R vr os hx cap ptKs zero clear) + (obj.Slot.set_cap.exactMap inMid os hx (CapRt.rt_Frame _ _ _ _ _ _ _ _ wf')) + obtain ⟨q, written⟩ := DPF.spec_tot (P0.obj.Slot.set_cap.p0 st x mid + (.Frame f.ptr f.size f.rights f.is_device false false 0#u64 0#u64) hS) + rw [written, WP.spec_ok] at both + obtain ⟨effect, base, words, reset, other⟩ := both + have post := S1aR2.ofFrameUnmap R here heap kinds cap effect + have dropped : S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa q x := + post.toDelM.drop (by rw [reset]; exact fun h => by cases h) + refine S1aDelM.keep dropped base.symm (fun b hb => ?_) (fun y hy => Or.inl (other y hy.1 hy.2).symm) + rw [base] at hb + exact (words b hb).symm + split + · split + · refine WP.spec_bind (P0.objects.retire_dma_frame.p0 st ar mid a1 f.ptr f.size hS hA) fun a2 _ => ?_ + exact (WP.spec_ok _).2 ⟨rfl, pending⟩ + · exact (WP.spec_ok _).2 ⟨rfl, pending⟩ + · exact (WP.spec_ok _).2 ⟨rfl, pending⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FinPool.lean b/proofs/Fl4ProofsA64/P1/S1aR2FinPool.lean new file mode 100644 index 000000000..ae810e897 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FinPool.lean @@ -0,0 +1,235 @@ +/- +P1 (aarch64): finalising an ASID-pool capability leaves R2 over the other slots (A64-S1A gen 41). + +A non-final pool cap has a copy and its finalisation does nothing. A final one is the only capability of +its pool, and `delete_asid_pool` clears exactly its ASID-table entry. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Field +import Fl4ProofsA64.P1.S1aR2Zeroed +import Fl4ProofsA64.P1.MdbPoolDelR + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Vc Ub T Ω Sg : Set U64} {Lv Re bits : U64 → Nat} {n x p base : U64} {s : S} + +/-- R2 may drop a slot whose capability another slot holds. -/ +theorem S1aDelM.dropCopy (h : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s) {y : U64} (hy : y ∈ OS) (ne : y ≠ x) + (same : capA st s y = capA st s x) : S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n s x := + (S1aR2.congrSlots (O' := OS \ {x}) h (fun _ hz _ => hz.1) (fun z hz _ => by + by_cases e : z = x + · exact ⟨y, ⟨hy, ne⟩, e ▸ same⟩ + · exact ⟨z, ⟨hz, e⟩, rfl⟩)).toDelM + +/-- The entry write of `delete_asid_pool`. -/ +theorem vspace.delete_asid_pool.exact (hA : P0.ArchTotal ar) (a : A) {i : U64} (small : i.val < 128) + (low : base.val = i.val * 512) (nz : p ≠ 0#u64) (word : L.mem s (wa (L.ksb s) (AtOff i)) = p) : + vspace.delete_asid_pool st ar s a base p ⦃ r => r.1 = L.wr s (wa (L.ksb s) (AtOff i)) 0#u64 ⦄ := by + have hS : P0.StoreTotal st := L.total + have shift : (base >>> vspace.ASID_LOW_BITS : Result U64) ⦃ z => z = i ⦄ := by + refine WP.spec_mono (U64.ShiftRight_spec base vspace.ASID_LOW_BITS (by simp)) fun z hz => ?_ + apply UScalar.eq_of_val_eq + rw [hz.1] + simp only [vspace.ASID_LOW_BITS.val_eq, Nat.shiftRight_eq_div_pow, low] + omega + unfold vspace.delete_asid_pool + refine WP.spec_bind shift fun j hj => ?_ + subst j + rw [vspace.asid_table.eq, bind_ok, word] + rw [if_neg (by simp)] + refine WP.spec_bind (P0.vspace.delete_asid_pool_loop.p0 st ar s a base p 0#u64 hS hA) fun a1 _ => ?_ + refine WP.spec_bind shift fun j hj => ?_ + subst j + rw [vspace.set_asid_table.eq, bind_ok] + step with sched.cur_thread.spec as ⟨ct, _⟩ + exact WP.spec_mono (vspace.set_vm_root.same hA _ a1 ct) fun r e => by rw [e] + +/-- A final ASID-pool capability is the only capability naming its pool. -/ +theorem is_final.pool_only (hO : OSOK T Ω Sg OS) (mdb : MdbS st OS s) (hx : x ∈ OS) + (cap : capA st s x = .AsidPool p base) + (final : cdt.is_final_capability_with_cap st s x (.AsidPool p base) = ok true) : + ∀ y ∈ OS, y ≠ x → ∀ q b, capA st s y = .AsidPool q b → q ≠ p := by + obtain ⟨G, hM, hRO, hK, -, hC⟩ := mdb + intro y hy ne q b other same + subst q + have key (b' : U64) : RngKeyA (.AsidPool p b') := RngKeyA.ap p b' + refine final_uniq hO.nz hM hRO hK hC hx cap (key base) (ptrA_ap p base) (fun d kind cls => ?_) final y hy ne + (by rw [other]; exact key b) (by rw [other, ptrA_ap]) + have ptr : ptrA d = p := (ptrA_of_cls cls).trans (ptrA_ap p base) + cases d <;> simp only [kindA] at kind <;> try omega + case AsidPool q b' => + rw [ptrA_ap] at ptr + subst q + simp only [objects.same_object_as, objects.same_region_as, if_true, and_self] + +/-- Finalising an ASID-pool capability: `(Null, Null)`, and R2 over the other slots. -/ +theorem S1aFin.pool (hA : P0.ArchTotal ar) (hO : OSOK T Ω Sg OS) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (heap : HeapOK H) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) (high : HvRt st OS s ⊆ Hr) + (M : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s) (mdb : MdbS st OS s) (hx : x ∈ OS) + (cap : capA st s x = .AsidPool p base) {f : Bool} + (final : cdt.is_final_capability_with_cap st s x (.AsidPool p base) = ok f) (a : A) : + objects.finalise_cap st ar s a (.AsidPool p base) f false ⦃ r => r.1.1 = .Null ∧ + S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n r.2.1 x ⦄ := by + have R : S1aR2 st H OS Pt Pp Tb (HvRt st OS s) Te Kt Lv Re bits n s := M + obtain ⟨i, small, low, nz, word⟩ := R.poolCaps.cap x hx p base cap + rw [fin_cap_eq_obj (by simp)] + unfold objects.finalise_cap_object + cases f + · simp only [Bool.false_eq_true, ↓reduceIte, bind_ok, WP.spec_ok] + refine ⟨trivial, ?_⟩ + obtain ⟨y, hy, ne, b', other⟩ := is_final.pool_alt hO mdb hx cap final + obtain ⟨j, smallJ, lowJ, _, wordJ⟩ := R.poolCaps.cap y hy p b' other + have index : i = j := R.poolCaps.index i j p small smallJ nz word wordJ + have bases : b' = base := UScalar.eq_of_val_eq (by rw [lowJ, low, index]) + exact M.dropCopy hy ne (by rw [other, cap, bases]) + simp only [↓reduceIte] + refine WP.spec_bind (vspace.delete_asid_pool.exact hA a small low nz word) ?_ + rintro ⟨s', a'⟩ written + simp only at written + subst s' + refine (WP.spec_ok _).2 ⟨rfl, ?_⟩ + set w := wa (L.ksb s) (AtOff i) with hw + have table : VsR (L.ksb s) Pt w := Or.inr (asW_at _ i) + have aligned : Aligned w := vr.al w table + have ksb : L.ksb (L.wr s w 0#u64) = L.ksb s := LawfulStore.ksb_wr _ _ _ + have words (b : U64) (hb : Aligned b) : L.mem (L.wr s w 0#u64) b = if b = w then 0#u64 else L.mem s b := by + split + · rename_i e + rw [e] + exact L.mem_wr_same aligned + · rename_i ne + exact L.mem_wr_ne aligned hb (fun e => ne (UScalar.eq_of_val_eq e.symm)) + have mem : VsZ st (L.ksb s) Pt s (L.wr s w 0#u64) := fun b hb => by + rw [words b (vr.al b hb)] + split + · exact Or.inr rfl + · exact Or.inl rfl + have tab : TabKeepOrZero st s (L.wr s w 0#u64) := ⟨ksb, fun j => by + rw [ksb] + exact mem _ (Or.inr (asW_at _ j))⟩ + have caps (y : U64) (hy : y ∈ OS) : capA st (L.wr s w 0#u64) y = capA st s y := + capA_wr_off hO hy aligned (fun h => vr.os _ table ⟨y, hy, h⟩) + have headers : HrW st (HvRt st OS s) s (L.wr s w 0#u64) := fun R' hR => by + have live : VsR (L.ksb s) Pt (wa R' 4088#u64) := + Or.inl ⟨R', R.place.tables (R.place.high.sub hR), 4088#u64, by decide, by decide, rfl⟩ + rw [words _ (vr.al _ live), ite_eq_right] + intro e + exact R.place.high.asw R' hR (e ▸ asW_at (L.ksb s) i) + have here : S1aR2Place Pt Pp Tb (HvRt st OS s) Te Lv bits (L.ksb s) := place.monoHigh high + have sub : OS \ {x} ⊆ OS := fun _ h => h.1 + have same (y : U64) (hy : y ∈ OS \ {x}) := caps y hy.1 + have unmapped := R.eptRoots.unmZ R.core heap R.pageTables + have full := VsLk.activeZero R.core here tab mem caps unmapped + have notPool (y : U64) (c : capability.Cap) (eq : capA st s y = c) (kind : ∀ q b, c ≠ .AsidPool q b) : y ≠ x := + fun e => kind p base (eq.symm.trans (e ▸ cap)) + have keepWitness {y : U64} (hy : y ∈ OS) {c : capability.Cap} (eq : capA st (L.wr s w 0#u64) y = c) + (kind : ∀ q b, c ≠ .AsidPool q b) : y ∈ OS \ {x} := + ⟨hy, notPool y c ((caps y hy).symm.trans eq) kind⟩ + have mapped {y : U64} (hy : y ∈ OS) {t : U64} (m : MapV (capA st (L.wr s w 0#u64) y) t) : y ∈ OS \ {x} := + keepWitness hy rfl fun q b e => by + rw [e] at m + rcases m with ⟨_, _, e'⟩ | ⟨_, e'⟩ | ⟨_, e'⟩ | ⟨_, _, e', _⟩ | ⟨_, _, _, e'⟩ <;> cases e' + have lookup : VsLk st H (OS \ {x}) Pp Tb Te Kt Lv Re bits (L.wr s w 0#u64) := by + refine ⟨fun t reach member outside => ?_, fun t reach member => ?_, fun t kernel y hy m => ?_, + fun u hu y hy q size unm m => ?_, fun u hu q size unm => ?_, ⟨fun u hu q size unm => ?_, + fun t reach member outside => ?_, full.vh.2.2⟩⟩ + · obtain ⟨y, hy, m⟩ := full.bk1 t reach member outside + exact ⟨y, mapped hy m, m⟩ + · obtain ⟨y, hy, m⟩ := full.bk2 t reach member + exact ⟨y, mapped hy m, m⟩ + · exact full.kt t kernel y hy.1 m + · exact full.ex u hu.1 y hy.1 q size unm m + · exact full.zr u hu.1 q size unm + · exact full.vh.1 u hu.1 q size unm + · rcases full.vh.2.1 t reach member outside with plain | ⟨R', obj, which, y, hy, a'', eq⟩ + · exact Or.inl plain + · exact Or.inr ⟨R', obj, which, y, keepWitness hy eq (fun _ _ e => by cases e), a'', eq⟩ + have rootFull := R.core.root.activeZero here.pools tab mem caps + have root : RootAgreement st (OS \ {x}) Pp (L.wr s w 0#u64) := by + refine ⟨fun asid raw entry => ?_, fun u hu y hy r' a1 a2 t1 t2 c1 c2 => + rootFull.agree u hu.1 y hy.1 r' a1 a2 t1 t2 c1 c2⟩ + obtain ⟨y, hy, backed⟩ := rootFull.backed asid raw entry + refine ⟨y, keepWitness hy rfl fun q b e => ?_, backed⟩ + rw [e] at backed + rcases backed with ⟨_, e'⟩ | ⟨_, _, e'⟩ | ⟨_, e'⟩ <;> cases e' + have stage1 := R.core.stage1.activeZero here.pools here.tables tab mem + have highSame : HvRt st (OS \ {x}) (L.wr s w 0#u64) = HvRt st OS s := by + ext q + constructor + · rintro ⟨y, hy, m, a'', eq⟩ + exact ⟨y, hy.1, m, a'', (same y hy).symm.trans eq⟩ + · rintro ⟨y, hy, m, a'', eq⟩ + have ne : y ≠ x := notPool y _ eq (fun _ _ e => by cases e) + exact ⟨y, ⟨hy, ne⟩, m, a'', (caps y hy).trans eq⟩ + have stage2 : S2TyR st n (PoolSet st Pp (L.wr s w 0#u64)) (HvRt st (OS \ {x}) (L.wr s w 0#u64)) Te Re bits + (L.wr s w 0#u64) := by + rw [highSame] + exact R.core.stage2.activeZero here.pools here.granules here.stage2 tab mem headers + have poolWord (q : U64) (hq : q ∈ PoolSet st Pp s) (o : U64) (ho : o.val < 4096) (al : o.val % 8 = 0) : + L.mem (L.wr s w 0#u64) (wa q o) = L.mem s (wa q o) ∨ L.mem (L.wr s w 0#u64) (wa q o) = 0#u64 := + mem _ (Or.inl ⟨q, here.pools hq.1, o, ho, al, rfl⟩) + have entry (j : U64) {q : U64} (read : L.mem (L.wr s w 0#u64) (wa (L.ksb s) (AtOff j)) = q) (live : q ≠ 0#u64) : + L.mem s (wa (L.ksb s) (AtOff j)) = q ∧ wa (L.ksb s) (AtOff j) ≠ w := by + rw [words _ (vr.al _ (Or.inr (asW_at _ j)))] at read + split at read + · exact (live read.symm).elim + · rename_i ne + exact ⟨read, ne⟩ + have pools : S1aPoolCaps st H (OS \ {x}) Pt Pp (L.wr s w 0#u64) := by + refine ⟨fun j hj q read live => ?_, fun y hy q b eq => ?_, fun j k q hj hk live rj rk => ?_, + fun raw active => R.poolCaps.noZero raw (active.back tab poolWord)⟩ + · rw [ksb] at read + obtain ⟨old, away⟩ := entry j read live + obtain ⟨active, member, obj, y, hy, b, eq, bl⟩ := R.poolCaps.present j hj q old live + have ne : y ≠ x := fun e => by + rw [e, cap] at eq + injection eq with _ bases + have : j = i := UScalar.eq_of_val_eq (by have := congrArg UScalar.val bases; omega) + exact away (by rw [this]) + exact ⟨active, member, obj, y, ⟨hy, ne⟩, b, (caps y hy).trans eq, bl⟩ + · have prior := (same y hy).symm.trans eq + obtain ⟨j, hj, bl, live, old⟩ := R.poolCaps.cap y hy.1 q b prior + refine ⟨j, hj, bl, live, ?_⟩ + rw [ksb, words _ (vr.al _ (Or.inr (asW_at _ j))), ite_eq_right, old] + intro same' + have other := is_final.pool_only hO mdb hx cap final y hy.1 hy.2 q b prior + have hit : L.mem s (wa (L.ksb s) (AtOff j)) = p := by rw [same']; exact word + exact other (old.symm.trans hit) + · rw [ksb] at rj rk + exact R.poolCaps.index j k q hj hk live (entry j rj live).1 (entry k rk live).1 + have rootBack : ∀ asid raw, ActiveAsidRoot st Pp (L.wr s w 0#u64) asid raw → ActiveAsidRoot st Pp s asid raw := + fun _ _ e => e.back tab poolWord + have pathBack : ∀ tag asid sh va t, S1aPath st Pp n (L.wr s w 0#u64) tag asid sh va t → + S1aPath st Pp n s tag asid sh va t := fun _ _ _ _ _ path => by + refine path.back rootBack (fun asid raw rootEntry kind => ?_) + (fun _ _ _ _ _ old _ bd al => mem _ (Or.inl (R.pathWord old bd al))) + obtain ⟨y, hy, backed⟩ := R.core.root.backed asid raw rootEntry + rw [kind] at backed + rcases backed with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, backed⟩ + · cases bad + · cases bad + exact headers _ ⟨y, hy, true, asid, backed⟩ + have full' : S1aPathBacking st H OS Pp Tb Te Lv Re bits n (L.wr s w 0#u64) := + R.paths.shrink pathBack + (fun tag asid sh va t path _ bd al => mem _ (Or.inl (R.pathWord (pathBack tag asid sh va t path) bd al))) + (fun _ _ _ _ _ _ _ y hy _ eq => ⟨y, hy, (caps y hy).trans eq⟩) + (fun _ _ _ _ _ _ _ _ y hy _ _ _ _ _ => ⟨y, hy, caps y hy⟩) + have paths : S1aPathBacking st H (OS \ {x}) Pp Tb Te Lv Re bits n (L.wr s w 0#u64) := by + refine ⟨full'.tables, fun tag asid sh va t path child => ?_, + fun tag asid sh va t path o bound al range valid => ?_⟩ + · obtain ⟨y, hy, address, eq, ref⟩ := full'.children tag asid sh va t path child + exact ⟨y, keepWitness hy eq (fun _ _ e => by cases e), address, eq, ref⟩ + · obtain ⟨y, hy, sz, rights, dev, address, size, eq, ref, object⟩ := + full'.leaves tag asid sh va t path o bound al range valid + exact ⟨y, keepWitness hy eq (fun _ _ e => by cases e), sz, rights, dev, address, size, eq, ref, object⟩ + have done := R.zeroedOn heap (by obtain ⟨_, _, _, hK, _, _⟩ := mdb; exact hK) tab mem headers sub same lookup + root stage1 stage2 pools paths + exact done + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FinPt.lean b/proofs/Fl4ProofsA64/P1/S1aR2FinPt.lean new file mode 100644 index 000000000..3d21735ed --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FinPt.lean @@ -0,0 +1,266 @@ +/- +P1 (aarch64): finalising a PageTable capability leaves R2 over the other slots (A64-S1A gen 41). + +A non-final PageTable cap has an exact copy. A final unmapped one backs nothing. A final mapped one is the +only namer of its table, which `unmap_page_table` makes unreachable; the table's words are not zeroed and +the capability is not rewritten. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FinPool +import Fl4ProofsA64.P1.S1aR2UnmapS1 +import Fl4ProofsA64.P1.S1aR2UnmapS2 + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Vc Ub T Ω Sg Scs : Set U64} {Z : U64 → Nat} {Lv Re bits : U64 → Nat} + {n x ptr asid va : U64} {s q : S} {mapped : Bool} + +theorem so_pt_inv {p a v : U64} {m : Bool} {d : capability.Cap} + (h : objects.same_object_as (.PageTable p m a v) d = ok true) : ∃ m' a' v', d = .PageTable p m' a' v' := by + cases d <;> simp only [objects.same_object_as, objects.same_region_as] at h <;> + (try (simp at h; done)) <;> (repeat' (split at h)) <;> (try (simp at h; done)) <;> (try subst_vars) <;> + exact ⟨_, _, _, rfl⟩ + +theorem so_pt_inv' {p a v : U64} {m : Bool} {d : capability.Cap} + (h : objects.same_object_as d (.PageTable p m a v) = ok true) : ∃ m' a' v', d = .PageTable p m' a' v' := by + cases d <;> simp only [objects.same_object_as, objects.same_region_as] at h <;> + (try (simp at h; done)) <;> (repeat' (split at h)) <;> (try (simp at h; done)) <;> (try subst_vars) <;> + exact ⟨_, _, _, rfl⟩ + +/-- A non-final PageTable capability has an exact copy in another slot. -/ +theorem is_final.pt_copy (hO : OSOK T Ω Sg OS) (mdb : MdbS st OS s) (refs : S1aTableCaps st OS s) (hx : x ∈ OS) + (cap : capA st s x = .PageTable ptr mapped asid va) + (nonfinal : cdt.is_final_capability_with_cap st s x (.PageTable ptr mapped asid va) = ok false) : + ∃ y ∈ OS, y ≠ x ∧ capA st s y = capA st s x := by + obtain ⟨G, hM, -, -, -, -⟩ := mdb + obtain ⟨y, hy, ne, so⟩ := nonfinal_nb hO.nz hM hx cap (fun e => by cases e) nonfinal + obtain ⟨m', a', v', other⟩ : ∃ m' a' v', capA st s y = .PageTable ptr m' a' v' := + so.elim so_pt_inv' so_pt_inv + have kx : s1aTableKey (capA st s x) = some (0, ptr) := by rw [cap]; rfl + have ky : s1aTableKey (capA st s y) = some (0, ptr) := by rw [other]; rfl + have same := refs.references x hx y hy _ kx ky + have live : s1aTableRef (capA st s x) ≠ none := fun none => ne (refs.unique x hx y hy _ kx ky none) + refine ⟨y, hy, ne, ?_⟩ + rw [cap] at same live ⊢ + rw [other] at same ⊢ + cases mapped + · exact (live rfl).elim + cases m' + · cases same + · injection same with same + injection same with asids vas + rw [asids, vas] + +/-- R2 over the other slots after a keep-or-clear step that leaves the capabilities alone, when slot `x` +is no longer the only witness of anything R2 asks for: its mapped tables are named elsewhere if still +reached, no active ASID entry is backed by it, and no surviving path enters a table through it. -/ +theorem S1aR2.dropSlot (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (kinds : KindA st OS s) (table : TabKeep st s q) (mem : VsZ st (L.ksb s) Pt s q) (headers : HrW st Hr s q) + (caps : ∀ y ∈ OS, capA st q y = capA st s y) + (lookup : VsLk st H OS Pp Tb Te Kt Lv Re bits q) (root : RootAgreement st OS Pp q) + (stage1 : VsTyR st (L.ksb q) (PoolSet st Pp q) ∅ Tb Lv q) + (stage2 : S2TyR st n (PoolSet st Pp q) Hr Te Re bits q) + (plain : (∀ p b, capA st s x ≠ .AsidPool p b) ∧ + ∀ p sz r d m e a v, capA st s x ≠ .Frame p sz r d m e a v) + (maps : ∀ t, MapV (capA st s x) t → + VsReach st (PoolSet st Pp q) ∅ Lv q t ∨ S2Reach st (PoolSet st Pp q) Re bits q t → + (∀ R a, capA st s x ≠ .HighVSpace R true a) ∧ ∃ y ∈ OS, y ≠ x ∧ MapV (capA st q y) t) + (entries : ∀ a raw, ActiveAsidRoot st Pp q a raw → + ¬ MappedAsidRoot (capA st s x) (raw &&& ~~~3#u64) a (raw &&& 3#u64)) + (children : S1aPathBacking st H OS Pp Tb Te Lv Re bits n q → ∀ tag a sh b t, + S1aPath st Pp n q tag a sh b t → sh < s1aTopShift tag n → + ∀ address, capA st s x ≠ .PageTable t true a address) : + S1aR2 st H (OS \ {x}) Pt Pp Tb (HvRt st (OS \ {x}) q) Te Kt Lv Re bits n q := by + have sub : OS \ {x} ⊆ OS := fun _ h => h.1 + have same (y : U64) (hy : y ∈ OS \ {x}) := caps y hy.1 + have notX (y : U64) (hy : y ∈ OS) {c : capability.Cap} (eq : capA st q y = c) (differs : capA st s x ≠ c) : + y ∈ OS \ {x} := + ⟨hy, fun e => differs (((congrArg (capA st s) e).symm.trans (caps y hy).symm).trans eq)⟩ + have tab := table.toDel + have poolWord (p : U64) (hp : p ∈ PoolSet st Pp s) (o : U64) (ho : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) ∨ L.mem q (wa p o) = 0#u64 := + mem _ (Or.inl ⟨p, h.place.pools hp, o, ho, al, rfl⟩) + have highSub : HvRt st (OS \ {x}) q ⊆ Hr := by + rintro p ⟨y, hy, m, a, eq⟩ + rw [h.highRoots] + exact ⟨y, hy.1, m, a, (same y hy).symm.trans eq⟩ + have witness {y t : U64} (hy : y ∈ OS) (m : MapV (capA st q y) t) + (reach : VsReach st (PoolSet st Pp q) ∅ Lv q t ∨ S2Reach st (PoolSet st Pp q) Re bits q t) : + ∃ z ∈ OS \ {x}, MapV (capA st q z) t := by + by_cases e : y = x + · rw [e, caps x (e ▸ hy)] at m + obtain ⟨_, z, hz, ne, mapped⟩ := maps t m reach + exact ⟨z, ⟨hz, ne⟩, mapped⟩ + · exact ⟨y, ⟨hy, e⟩, m⟩ + have lookup' : VsLk st H (OS \ {x}) Pp Tb Te Kt Lv Re bits q := by + refine ⟨fun t reach member outside => ?_, fun t reach member => ?_, fun t kernel y hy m => ?_, + fun u hu y hy p size unm m => ?_, fun u hu p size unm => ?_, ⟨fun u hu p size unm => ?_, + fun t reach member outside => ?_, lookup.vh.2.2⟩⟩ + · obtain ⟨y, hy, m⟩ := lookup.bk1 t reach member outside + exact witness hy m (Or.inl reach) + · obtain ⟨y, hy, m⟩ := lookup.bk2 t reach member + exact witness hy m (Or.inr reach) + · exact lookup.kt t kernel y hy.1 m + · exact lookup.ex u hu.1 y hy.1 p size unm m + · exact lookup.zr u hu.1 p size unm + · exact lookup.vh.1 u hu.1 p size unm + · rcases lookup.vh.2.1 t reach member outside with direct | ⟨R, obj, which, y, hy, a, eq⟩ + · exact Or.inl direct + · refine Or.inr ⟨R, obj, which, y, ⟨hy, fun e => ?_⟩, a, eq⟩ + change y = x at e + rw [e] at eq hy + rw [caps x hy] at eq + have named : MapV (capA st s x) t := by + rw [eq] + rcases which with rfl | which + · exact Or.inr (Or.inr (Or.inl ⟨a, rfl⟩)) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨R, a, rfl, which⟩))) + exact (maps t named (Or.inl reach)).1 R a eq + have root' : RootAgreement st (OS \ {x}) Pp q := by + refine ⟨fun a raw entry => ?_, fun u hu y hy r a1 a2 t1 t2 c1 c2 => root.agree u hu.1 y hy.1 r a1 a2 t1 t2 c1 c2⟩ + obtain ⟨y, hy, backed⟩ := root.backed a raw entry + refine ⟨y, ⟨hy, fun e => ?_⟩, backed⟩ + change y = x at e + rw [e] at backed hy + rw [caps x hy] at backed + exact entries a raw entry backed + have pools : S1aPoolCaps st H (OS \ {x}) Pt Pp q := by + have full := h.poolCaps.zero table poolWord (fun y hy _ _ => by rw [caps y hy]) + refine ⟨fun i hi p word nz => ?_, fun y hy p b eq => full.cap y hy.1 p b eq, full.index, full.noZero⟩ + obtain ⟨active, member, obj, y, hy, b, eq, low⟩ := full.present i hi p word nz + exact ⟨active, member, obj, y, notX y hy eq (plain.1 p b), b, eq, low⟩ + have back {tag a t : U64} {sh b : Nat} (path : S1aPath st Pp n q tag a sh b t) : S1aPath st Pp n s tag a sh b t := by + refine path.back (fun _ _ e => e.back tab poolWord) (fun a raw entry kind => ?_) + (fun _ _ _ _ _ old _ bd al => mem _ (Or.inl (h.pathWord old bd al))) + obtain ⟨y, hy, backed⟩ := h.core.root.backed a raw entry + rw [kind] at backed + rcases backed with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, backed⟩ + · cases bad + · cases bad + exact headers _ (by rw [h.highRoots]; exact ⟨y, hy, true, a, backed⟩) + have full : S1aPathBacking st H OS Pp Tb Te Lv Re bits n q := + h.paths.shrink (fun _ _ _ _ _ path => back path) + (fun _ _ _ _ _ path _ bd al => mem _ (Or.inl (h.pathWord (back path) bd al))) + (fun _ _ _ _ _ _ _ y hy _ eq => ⟨y, hy, (caps y hy).trans eq⟩) + (fun _ _ _ _ _ _ _ _ y hy _ _ _ _ _ => ⟨y, hy, caps y hy⟩) + have paths : S1aPathBacking st H (OS \ {x}) Pp Tb Te Lv Re bits n q := by + refine ⟨full.tables, fun tag a sh b t path child => ?_, fun tag a sh va t path o bound al range valid => ?_⟩ + · obtain ⟨y, hy, saved, eq, ref⟩ := full.children tag a sh b t path child + refine ⟨y, ⟨hy, fun e => ?_⟩, saved, eq, ref⟩ + change y = x at e + rw [e] at eq hy + rw [caps x hy] at eq + exact children full tag a sh b t path child saved eq + · obtain ⟨y, hy, sz, rights, dev, address, size, eq, ref, object⟩ := + full.leaves tag a sh va t path o bound al range valid + exact ⟨y, notX y hy eq (plain.2 _ _ _ _ _ _ _ _), sz, rights, dev, address, size, eq, ref, object⟩ + have stage2' : S2TyR st n (PoolSet st Pp q) (HvRt st (OS \ {x}) q) Te Re bits q := by + refine ⟨fun p hp o ho al nz => ?_, fun R hR => stage2.hi R (highSub hR), stage2.desc⟩ + rcases stage2.tag p hp o ho al nz with ⟨kind, away⟩ | ⟨kind, member⟩ | two + · exact Or.inl ⟨kind, fun now => away (highSub now)⟩ + · obtain ⟨a, entry⟩ := ActiveAsidRoot.forWord hp ho al nz + obtain ⟨y, hy, backed⟩ := root'.backed a _ entry + rw [kind] at backed + rcases backed with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, backed⟩ + · cases bad + · cases bad + exact Or.inr (Or.inl ⟨kind, y, hy, true, a, backed⟩) + · exact Or.inr (Or.inr two) + exact h.zeroedOn heap kinds tab mem headers sub same lookup' root' stage1 stage2' pools paths + +/-- `dropSlot` for a PageTable slot whose table, if the slot is mapped, no surviving walk reaches. -/ +theorem S1aR2.dropPageTable (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (kinds : KindA st OS s) (cap : capA st s x = .PageTable ptr mapped asid va) + (table : TabKeep st s q) (mem : VsZ st (L.ksb s) Pt s q) (headers : HrW st Hr s q) + (caps : ∀ y ∈ OS, capA st q y = capA st s y) + (lookup : VsLk st H OS Pp Tb Te Kt Lv Re bits q) (root : RootAgreement st OS Pp q) + (stage1 : VsTyR st (L.ksb q) (PoolSet st Pp q) ∅ Tb Lv q) + (stage2 : S2TyR st n (PoolSet st Pp q) Hr Te Re bits q) + (idle : mapped = false ∨ (¬ VsReach st (PoolSet st Pp q) ∅ Lv q ptr ∧ ¬ S2Reach st (PoolSet st Pp q) Re bits q ptr)) : + S1aR2 st H (OS \ {x}) Pt Pp Tb (HvRt st (OS \ {x}) q) Te Kt Lv Re bits n q := by + refine h.dropSlot heap kinds table mem headers caps lookup root stage1 stage2 + ⟨fun _ _ e => (by rw [cap] at e; cases e), fun _ _ _ _ _ _ _ _ e => (by rw [cap] at e; cases e)⟩ + (fun t m reach => ?_) (fun a raw _ backed => ?_) (fun full tag a sh b t path _ address e => ?_) + · rw [cap] at m + rcases m with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, e, _⟩ | ⟨_, _, _, e⟩ <;> cases e + rcases idle with idle | ⟨no1, no2⟩ + · cases idle + · exact (reach.elim no1 no2).elim + · rw [cap] at backed + rcases backed with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e + · rw [cap] at e + injection e with same live _ _ + rcases idle with idle | ⟨no1, no2⟩ + · rw [idle] at live + cases live + subst same + have typed1 {a' t' : U64} {sh' b' : Nat} {tag' : U64} (ne : tag' ≠ 1#u64) + (p : S1aPath st Pp n q tag' a' sh' b' t') : sh' + 9 * Lv t' = 39 := by + have shape := full.tables _ _ _ _ _ p + rw [ite_eq_right ne] at shape + exact shape.2 + have typed2 {a' t' : U64} {sh' b' : Nat} (p : S1aPath st Pp n q 1#u64 a' sh' b' t') : + sh' = 12 + 9 * Re t' ∧ s1aTableWidth 1#u64 n sh' ≤ 2 ^ bits t' := + (show _ ∧ _ ∧ _ from full.tables _ _ _ _ _ p).2 + have highLv a' raw (e : ActiveAsidRoot st Pp q a' raw) (tag' : raw &&& 3#u64 = 2#u64) : + Lv (raw &&& ~~~3#u64) = 0 := by + obtain ⟨_, o, _, ho, al, _, p, hp, _, word, nz⟩ := e + subst raw + exact ((stage1.pool p hp o ho al nz).2 tag').2 + by_cases stage : tag = 1#u64 + · subst tag + exact no2 (path.toStage2 (fun _ _ _ p => typed2 p)) + · exact no1 (path.toStage1 stage (fun _ _ _ p => typed1 stage p) highLv) + +/-- Finalising a PageTable capability: `(Null, Null)`, and R2 over the other slots. -/ +theorem S1aFin.pageTable (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (hO : OSOK T Ω Sg OS) + (vr : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s) Pt) (heap : HeapOK H) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) (high : HvRt st OS s ⊆ Hr) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (M : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa s) (mdb : MdbS st OS s) (hx : x ∈ OS) + (cap : capA st s x = .PageTable ptr mapped asid va) {f : Bool} + (final : cdt.is_final_capability_with_cap st s x (.PageTable ptr mapped asid va) = ok f) (a : A) : + objects.finalise_cap st ar s a (.PageTable ptr mapped asid va) f false ⦃ r => r.1.1 = .Null ∧ + S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits hPl.ipa r.2.1 x ⦄ := by + have R : S1aR2 st H OS Pt Pp Tb (HvRt st OS s) Te Kt Lv Re bits hPl.ipa s := M + have kinds : KindA st OS s := by + obtain ⟨_, _, _, hK, _, _⟩ := mdb + exact hK + rw [fin_cap_eq_obj (by simp)] + unfold objects.finalise_cap_object + dsimp only + cases f + · simp only [Bool.false_and, Bool.false_eq_true, ↓reduceIte, bind_ok, WP.spec_ok] + refine ⟨trivial, ?_⟩ + obtain ⟨y, hy, ne, same⟩ := is_final.pt_copy hO mdb R.capRefs hx cap final + exact M.dropCopy hy ne same + cases mapped + · simp only [Bool.true_and, Bool.false_eq_true, ↓reduceIte, bind_ok, WP.spec_ok] + refine ⟨trivial, ?_⟩ + exact (R.dropPageTable heap kinds cap (TabKeep.refl s) (VsZ.refl s) (fun _ _ => rfl) (fun _ _ => rfl) + R.core.lookup R.core.root R.core.stage1 R.core.stage2 (Or.inl rfl)).toDelM + simp only [↓reduceIte] + have here : S1aR2Place Pt Pp Tb (HvRt st OS s) Te Lv bits (L.ksb s) := place.monoHigh high + have found := R.core.walk x hx ptr asid va cap + have lookup := vspace.unmap_page_table.activeLookup hA hPl a vr hO heap R.pageTables R.eptRoots R.core here found + have effects := vspace.unmap_page_table.activeUnr hA hPl a R.core here vr.al found + refine WP.spec_bind (WP.spec_and lookup effects) ?_ + rintro ⟨out, a'⟩ ⟨⟨look, root, stage1, stage2, _, no2, no1⟩, words, headers, _, _, write⟩ + simp only at look root stage1 stage2 no2 no1 words headers write + have writes := Wr0.w (fun b hb => vr.al b (Or.inl hb)) write + have table : TabKeep st s out := ⟨writes.1, fun i => by + rw [writes.1] + exact writes.mem_eq (vr.al _ (Or.inr (asW_at _ i))) (fun p => ptKs _ p (asW_at _ i))⟩ + have caps : ∀ y ∈ OS, capA st out y = capA st s y := fun y hy => by + have keep := capk_vsr vr hO (writes.mono fun _ hw => Or.inl hw) y hy + rw [capA_eq, capA_eq] at keep + exact okinj keep + refine (WP.spec_ok _).2 ⟨rfl, ?_⟩ + exact (R.dropPageTable heap kinds cap table words headers caps look root stage1 stage2 (Or.inr ⟨no1, no2⟩)).toDelM + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FinRoot.lean b/proofs/Fl4ProofsA64/P1/S1aR2FinRoot.lean new file mode 100644 index 000000000..f8f6f4944 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FinRoot.lean @@ -0,0 +1,652 @@ +/- +P1 (aarch64): finalising a VSpace root capability leaves R2 over the other slots (A64-S1A gen 41). + +`Pml4`, `HighVSpace` and level-0 `Ept` caps. A non-final cap has an exact copy. A final mapped one is the +only namer of its root: `delete_asid` clears its ASID entry, after which no walk reaches the root (or a +`HighVSpace` root's private level-1 granule). Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FinPt +import Fl4ProofsA64.P1.S1aR2RetypeNew + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Vc Ub T Ω Sg Scs : Set U64} {Z : U64 → Nat} {Lv Re bits : U64 → Nat} + {n x ptr asid tag raw : U64} {s q : S} + +/-- `delete_asid` of an active entry's own root clears exactly that entry. -/ +theorem vspace.delete_asid.exact (hA : P0.ArchTotal ar) (a : A) {i o pool root : U64} (width : o.val < 4096) + (al : o.val % 8 = 0) (index : asid.val = i.val * 512 + o.val / 8) + (entry : L.mem s (wa (L.ksb s) (AtOff i)) = pool) (small : i.val < 128) (nz : pool ≠ 0#u64) + (word : L.mem s (wa pool o) = root) : + vspace.delete_asid st ar s a asid root ⦃ r => r.1 = L.wr s (wa pool o) 0#u64 ⦄ := by + have hS : P0.StoreTotal st := L.total + have shift : (asid >>> vspace.ASID_LOW_BITS : Result U64) ⦃ z => z = i ⦄ := by + refine WP.spec_mono (U64.ShiftRight_spec asid vspace.ASID_LOW_BITS (by simp)) fun z hz => ?_ + apply UScalar.eq_of_val_eq + rw [hz.1] + simp only [vspace.ASID_LOW_BITS.val_eq, Nat.shiftRight_eq_div_pow, index] + omega + have low : core.num.U64.wrapping_mul (asid &&& 511#u64) 8#u64 = o := UScalar.eq_of_val_eq (by + rw [mul8_val (and511 asid), UScalar.val_and, show (511#u64 : U64).val = 2 ^ 9 - 1 by rfl, + Nat.and_two_pow_sub_one_eq_mod, index] + omega) + unfold vspace.delete_asid + refine WP.spec_bind shift fun j hj => ?_ + subst j + rw [vspace.asid_table.eq, bind_ok, entry] + rw [if_neg nz] + simp only [lift, bind_ok, L.read_eq, low, word, ↓reduceIte] + refine WP.spec_bind (Pₘ := fun _ => True) ?_ fun a1 _ => ?_ + · split + · exact hA.invalidate_stage2_vmid a asid + · split + · exact hA.invalidate_high_vspace a _ + · exact hA.invalidate_asid a asid + step with LawfulStore.write_spec as ⟨s1, e1⟩ + step with sched.cur_thread.spec as ⟨ct, _⟩ + refine WP.spec_mono (vspace.set_vm_root.same hA s1 a1 ct) fun r e => ?_ + rw [e, e1] + +/-- After `delete_asid` of a mapped root capability's ASID, no active entry names its object: every +other root capability of the object records the same ASID. -/ +theorem vspace.delete_asid.rootGone (hA : P0.ArchTotal ar) (a : A) + (vr : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s) Pt) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (hx : x ∈ OS) {root : U64} + (mapped : MappedAsidRoot (capA st s x) ptr asid tag) + (rootPtr : root &&& ~~~3#u64 = ptr) (rootTag : root &&& 3#u64 = tag) + (split : ∀ w : U64, w &&& ~~~3#u64 = ptr → w &&& 3#u64 = tag → w = root) + (kinds : KindA st OS s) : + vspace.delete_asid st ar s a asid root ⦃ r => TabKeep st s r.1 ∧ VsZ st (L.ksb s) Pt s r.1 ∧ + Wr0 st (PoolSet st Pp s) s r.1 ∧ ∀ a' w, ActiveAsidRoot st Pp r.1 a' w → w &&& ~~~3#u64 ≠ ptr ⦄ := by + have pools : ∀ p ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → PtW Pt (wa p o) := + fun p hp o ho al => ⟨p, h.place.pools hp, o, ho, al, rfl⟩ + have ptPool : PtPool st (PoolSet st Pp s) s asid := fun i => by + refine WP.spec_mono (vspace.asid_table.w s i) fun pool ⟨o, lo, hi, al, e⟩ nz => ?_ + obtain ⟨j, ej⟩ := atOff_of_off lo hi al + have word : L.mem s (wa (L.ksb s) (AtOff (j &&& 127#u64))) = pool := by + rw [AtOff.mask, ej, e] + have small : (j &&& 127#u64).val < 128 := by + rw [UScalar.val_and] + exact Nat.lt_of_le_of_lt Nat.and_le_right (by decide) + have listed := (h.poolCaps.present _ small pool word nz).1 + have member : pool ∈ PoolSet st Pp s := ⟨listed, o, lo, hi, al, e.symm, nz⟩ + refine ⟨pool, member, _, ?_, ?_, rfl⟩ + · rw [mul8_val (and511 asid)]; have := and511 asid; omega + · rw [mul8_val (and511 asid)]; omega + have owns : ∀ a' w, ActiveAsidRoot st Pp s a' w → w &&& ~~~3#u64 = ptr → a' = asid ∧ w = root := by + intro a' w entry named + obtain ⟨y, hy, backed⟩ := h.core.root.backed a' w entry + rw [named] at backed + have facts {c : capability.Cap} {p a'' t : U64} (m : MappedAsidRoot c p a'' t) : + RngKeyA c ∧ ptrA c = p ∧ ((t = 0#u64 ∧ kindA c = kindA (.Pml4 p true a'')) ∨ + (t = 1#u64 ∧ kindA c = kindA (.Ept p 0#u64 true a'' 0#u64)) ∨ + (t = 2#u64 ∧ kindA c = kindA (.HighVSpace p true a''))) := by + rcases m with ⟨e, rfl⟩ | ⟨e, v, rfl⟩ | ⟨e, rfl⟩ + · exact ⟨RngKeyA.pml4 _ _ _, ptrA_pml4 _ _ _, Or.inl ⟨e, rfl⟩⟩ + · exact ⟨RngKeyA.ept _ _ _ _ _, ptrA_ept _ _ _ _ _, Or.inr (Or.inl ⟨e, rfl⟩)⟩ + · exact ⟨RngKeyA.hv _ _ _, ptrA_hv _ _ _, Or.inr (Or.inr ⟨e, rfl⟩)⟩ + obtain ⟨keyY, ptrY, kindY⟩ := facts backed + obtain ⟨keyX, ptrX, kindX⟩ := facts mapped + have equal := kinds.kind x hx y hy keyX keyY (ptrX.trans ptrY.symm) + have kind : w &&& 3#u64 = tag := by + rcases kindY with ⟨e1, k1⟩ | ⟨e1, k1⟩ | ⟨e1, k1⟩ <;> rcases kindX with ⟨e2, k2⟩ | ⟨e2, k2⟩ | ⟨e2, k2⟩ <;> + first + | exact e1.trans e2.symm + | (rw [k1, k2] at equal; simp [kindA] at equal) + exact ⟨(h.core.root.agree x hx y hy ptr asid a' tag _ mapped backed).symm, split w named kind⟩ + have writes := vspace.delete_asid.z (st := st) hA s a asid root ptPool + have cleared : ∀ i o pool : U64, i.val < 128 → o.val < 4096 → o.val % 8 = 0 → asid.val = i.val * 512 + o.val / 8 → + L.mem s (wa (L.ksb s) (AtOff i)) = pool → pool ∈ PoolSet st Pp s → L.mem s (wa pool o) = root → + vspace.delete_asid st ar s a asid root ⦃ r => L.mem r.1 (wa pool o) = 0#u64 ⦄ := by + intro i o pool small width al index entry member word + have nz : pool ≠ 0#u64 := by + obtain ⟨_, _, _, _, _, _, nz⟩ := member + exact nz + refine WP.spec_mono (vspace.delete_asid.exact hA a width al index entry small nz word) fun r e => ?_ + rw [e] + exact L.mem_wr_same (vr.al _ (Or.inl (pools pool member o width al))) + obtain ⟨r, result⟩ := DPF.spec_tot (WP.spec_mono writes fun _ _ => trivial) + rw [result, WP.spec_ok] + rw [result, WP.spec_ok] at writes + have inside : PoolSet st Pp s ⊆ Pt := fun _ hp => h.place.pools hp + have words := (Wr0.w (fun b hb => vr.al b (Or.inl (ptw_mono inside hb))) writes).mono fun _ hb => ptw_mono inside hb + have table : TabKeep st s r.1 := ⟨words.1, fun i => by + rw [words.1] + exact words.mem_eq (vr.al _ (Or.inr (asW_at _ i))) (fun p => ptKs _ p (asW_at _ i))⟩ + have mem : VsZ st (L.ksb s) Pt s r.1 := Wr0.vsz vr.al inside writes + refine ⟨table, mem, writes, fun a' w entry named => ?_⟩ + have prior := entry.back table.toDel (fun p hp o ho al => mem _ (Or.inl (pools p hp o ho al))) + obtain ⟨same, whole⟩ := owns a' w prior named + have nonzero : w ≠ 0#u64 := by + obtain ⟨_, _, _, _, _, _, _, _, _, _, nz⟩ := prior + exact nz + obtain ⟨i, o, small, width, al, index, pool, member, tableWord, word, _⟩ := prior + obtain ⟨i', o', small', width', al', index', pool', _, tableWord', word', _⟩ := entry + have ei : i' = i := UScalar.eq_of_val_eq (by omega) + have eo : o' = o := UScalar.eq_of_val_eq (by omega) + rw [table.2, ei, tableWord] at tableWord' + subst pool' + rw [eo] at word' + have zero := cleared i o pool small width al (same ▸ index) tableWord member (word.trans whole) + rw [result, WP.spec_ok] at zero + exact nonzero (word'.symm.trans zero) + + +/-- The root objects of the three VSpace root capability kinds. -/ +def S1aRootCap (c : capability.Cap) (p : U64) : Prop := + (∃ m a, c = .Pml4 p m a) ∨ (∃ m a, c = .HighVSpace p m a) ∨ (∃ m a v, c = .Ept p 0#u64 m a v) + +private theorem S1aPath.childShift {sh : Nat} {tag' asid' t : U64} {va : Nat} + (path : S1aPath st Pp n s tag' asid' sh va t) : sh - 9 < s1aTopShift tag' n ∨ ¬ 12 < sh := by + by_cases deep : 12 < sh + · have hi := path.geometry.2.elim (fun h => h.1.le) (fun h => h.1.le) + exact Or.inl (by omega) + · exact Or.inr deep + +/-- After the ASID entries naming a root object are gone, no walk reaches any table the root maps. -/ +theorem S1aR2.rootUnreached (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (kinds : KindA st OS s) (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (table : TabKeep st s q) (mem : VsZ st (L.ksb s) Pt s q) (hx : x ∈ OS) + (root : S1aRootCap (capA st s x) ptr) + (gone : ∀ a w, ActiveAsidRoot st Pp q a w → w &&& ~~~3#u64 ≠ ptr) + {t : U64} (mapped : MapV (capA st s x) t) : + ¬ VsReach st (PoolSet st Pp q) ∅ Lv q t ∧ ¬ S2Reach st (PoolSet st Pp q) Re bits q t := by + have tab := table.toDel + have poolWord (p : U64) (hp : p ∈ PoolSet st Pp s) (o : U64) (ho : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) ∨ L.mem q (wa p o) = 0#u64 := + mem _ (Or.inl ⟨p, h.place.pools hp, o, ho, al, rfl⟩) + have shape : ∃ k : HKind, H ptr = some k ∧ (k = .other 12 ∨ k = .other 13) := by + rcases root with ⟨m, a, e⟩ | ⟨m, a, e⟩ | ⟨m, a, v, e⟩ + · exact ⟨_, (h.nativeRoots x hx ptr m a e).1, Or.inl rfl⟩ + · exact ⟨_, h.highObjects x hx ptr m a e, Or.inr rfl⟩ + · exact ⟨_, (h.eptRoots x hx ptr 0#u64 m a v e).1, Or.inr rfl⟩ + have kx : RngKeyA (capA st s x) ∧ ptrA (capA st s x) = ptr := by + rcases root with ⟨m, a, e⟩ | ⟨m, a, e⟩ | ⟨m, a, v, e⟩ <;> rw [e] + · exact ⟨RngKeyA.pml4 _ _ _, ptrA_pml4 _ _ _⟩ + · exact ⟨RngKeyA.hv _ _ _, ptrA_hv _ _ _⟩ + · exact ⟨RngKeyA.ept _ _ _ _ _, ptrA_ept _ _ _ _ _⟩ + have notTable (y : U64) (hy : y ∈ OS) (a v : U64) (cap : capA st s y = .PageTable ptr true a v) : False := by + have key : RngKeyA (capA st s y) ∧ ptrA (capA st s y) = ptr := by + rw [cap] + exact ⟨RngKeyA.pt _ _ _ _, ptrA_pt _ _ _ _⟩ + have same := kinds.kind x hx y hy kx.1 key.1 (kx.2.trans key.2.symm) + rw [cap] at same + rcases root with ⟨m, a', e⟩ | ⟨m, a', e⟩ | ⟨m, a', v', e⟩ <;> rw [e] at same <;> cases same + let bad : U64 → Prop := fun u => u = ptr ∨ (u = wa ptr 4096#u64 ∧ ∃ m a, capA st s x = .HighVSpace ptr m a) + have target : bad t := by + rcases root with ⟨m, a, e⟩ | ⟨m, a, e⟩ | ⟨m, a, v, e⟩ <;> rw [e] at mapped <;> + rcases mapped with ⟨_, _, c⟩ | ⟨_, c⟩ | ⟨_, c⟩ | ⟨_, _, c, d⟩ | ⟨_, _, _, c⟩ <;> cases c + · exact Or.inl rfl + · exact Or.inl rfl + · exact Or.inr ⟨d, _, _, e⟩ + · exact Or.inl rfl + have outside (u : U64) (is : bad u) : u ∉ Kt := fun hk => by + refine h.core.lookup.kt u hk x hx ?_ + rcases is with rfl | ⟨rfl, m, a, e⟩ + · rcases root with ⟨m, a, e⟩ | ⟨m, a, e⟩ | ⟨m, a, v, e⟩ + · exact Or.inr (Or.inl ⟨m, a, e⟩) + · exact Or.inr (Or.inr (Or.inl ⟨m, a, e⟩)) + · exact Or.inr (Or.inr (Or.inr (Or.inr ⟨_, m, a, v, e⟩))) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨ptr, m, a, e, rfl⟩))) + -- another object cannot start at the private level-1 granule + have second (u y : U64) (k : HKind) (obj : H y = some k) (large : 0 < 2 ^ k.bits) + (at4096 : u = wa ptr 4096#u64) (high : H ptr = some (.other 13)) (eq : y = u) : False := by + have differs : ptr ≠ y := by + intro e + have value := congrArg UScalar.val (e.trans (eq.trans at4096)) + have fit := heap.fits ptr _ high + change ptr.val + 2 ^ 13 ≤ 2 ^ 64 at fit + rw [wadd_val (by change ptr.val + 4096 < 2 ^ 64; omega)] at value + change ptr.val = ptr.val + 4096 at value + omega + refine heap_wa_ne (o := 4096#u64) (o' := 0#u64) heap high obj differs (by change 4096 < 2 ^ 13; norm_num) + (by simpa using large) ?_ + rw [SFF.wadd0', eq, at4096] + have table' (u : U64) (is : bad u) (y : U64) (hy : y ∈ OS) (a v : U64) (cap : capA st s y = .PageTable u true a v) : + False := by + rcases is with e | ⟨e, m, b, c⟩ + · exact notTable y hy a v (e ▸ cap) + · exact second u u _ (h.pageObjects y hy u true a v cap) (Nat.two_pow_pos _) e (h.highObjects x hx ptr m b c) rfl + have entry (u : U64) (is : bad u) (a w : U64) (active : ActiveAsidRoot st Pp q a w) + (points : w &&& ~~~3#u64 = u) : False := by + rcases is with e | ⟨e, m, b, c⟩ + · exact gone a w active (points.trans e) + have high := h.highObjects x hx ptr m b c + obtain ⟨y, hy, backed⟩ := h.core.root.backed a w (active.back tab poolWord) + rw [points] at backed + rcases backed with ⟨_, c⟩ | ⟨_, v, c⟩ | ⟨_, c⟩ + · exact second u u _ (h.nativeRoots y hy u true a c).1 (Nat.two_pow_pos _) e high rfl + · exact second u u _ (h.eptRoots y hy u 0#u64 true a v c).1 (Nat.two_pow_pos _) e high rfl + · exact second u u _ (h.highObjects y hy u true a c) (Nat.two_pow_pos _) e high rfl + constructor + · intro reach + have general : ∀ u, VsReach st (PoolSet st Pp q) ∅ Lv q u → bad u → False := by + intro u reached + induction reached with + | hr member => exact fun _ => member + | @root0 p o pool width al nz tag => + intro is + obtain ⟨a, active⟩ := ActiveAsidRoot.forWord pool width al nz + exact entry _ is a _ active (maskedRoot tag) + | @root2 p o pool width al tag => + intro is + have nz : L.mem q (wa p o) ≠ 0#u64 := fun z => by rw [z] at tag; contradiction + obtain ⟨a, active⟩ := ActiveAsidRoot.forWord pool width al nz + exact entry _ is a _ active rfl + | @step p o prev level width al edge ih => + intro is + have old := prev.activeZero h.core.stage1 place.pools place.tables tab mem + have word : PtW Pt (wa p o) := + ⟨p, place.tables (h.core.stage1.sub.reach (hr_rt (by simp)) old).1, o, width, al, rfl⟩ + have keep : L.mem q (wa p o) = L.mem s (wa p o) := + (mem _ (Or.inl word)).resolve_right (fun z => by rw [z] at edge; contradiction) + rw [keep] at edge is + have out := outside _ is + generalize child : wa (L.mem s (wa p o) &&& vspace.ADDR_MASK) layout.PPTR_BASE = u at is out + rcases h.routeFacts.classifyEdge1 old level width al edge child out with + ⟨y, hy, a, cap, link, _⟩ | ⟨tag', asid', sh, va, _, path, deep, inWidth, range⟩ + · rcases is with same | ⟨same, m', a', c⟩ + · have object := h.highObjects y hy p true a cap + have differs : p ≠ ptr := by + intro c + have value := congrArg UScalar.val (link.trans (same.trans c.symm)) + have fit := heap.fits p _ object + change p.val + 2 ^ 13 ≤ 2 ^ 64 at fit + rw [wadd_val (by change p.val + 4096 < 2 ^ 64; omega)] at value + change p.val + 4096 = p.val at value + omega + obtain ⟨k, obj, _⟩ := shape + refine heap_wa_ne (o := 4096#u64) (o' := 0#u64) heap object obj differs + (by change 4096 < 2 ^ 13; norm_num) (by simp) ?_ + rw [SFF.wadd0', link, same] + · refine ih (Or.inl (UScalar.eq_of_val_eq ?_)) + have v := congrArg UScalar.val (link.trans same) + have fitP := heap.fits p _ (h.highObjects y hy p true a cap) + have fitPtr := heap.fits ptr _ (h.highObjects x hx ptr m' a' c) + change p.val + 2 ^ 13 ≤ 2 ^ 64 at fitP + change ptr.val + 2 ^ 13 ≤ 2 ^ 64 at fitPtr + rw [wadd_val (by change p.val + 4096 < 2 ^ 64; omega), + wadd_val (by change ptr.val + 4096 < 2 ^ 64; omega)] at v + change p.val + 4096 = ptr.val + 4096 at v + omega + · have next := path.child deep inWidth al range edge + rw [child] at next + have below := (S1aPath.childShift path).resolve_right (fun no => no deep) + obtain ⟨y, hy, v, cap, _⟩ := h.paths.children _ _ _ _ _ next below + exact table' u is y hy _ v cap + exact general t reach target + · intro reach + have general : ∀ u, S2Reach st (PoolSet st Pp q) Re bits q u → bad u → False := by + intro u reached + cases reached with + | @root p o pool width al tag => + intro is + have nz : L.mem q (wa p o) ≠ 0#u64 := fun z => by rw [z] at tag; contradiction + obtain ⟨a, active⟩ := ActiveAsidRoot.forWord pool width al nz + exact entry _ is a _ active rfl + | @step p o prev level width al edge => + intro is + have old := prev.activeZero h.core.stage2 place.pools place.granules place.stage2 tab mem + have word : PtWb (S2Rt st (PoolSet st Pp s) Te Re bits s) bits (wa p o) := + ⟨p, ⟨(h.core.stage2.sub.reach old).1, old⟩, o, width, al, rfl⟩ + have keep : L.mem q (wa p o) = L.mem s (wa p o) := + (mem _ (Or.inl (ptw_mono place.granules (ptwb_gran place.stage2.sz + (ptwb_mono S2Rt_sub word))))).resolve_right (fun z => by rw [z] at edge; contradiction) + rw [keep] at edge is + obtain ⟨asid', sh, va, p', o', path, deep, inWidth, al', same, range⟩ := + h.routeFacts.classifyPageTableParent2 (ptr := wa (L.mem s (wa p o) &&& ept.ADDR_MASK) layout.PPTR_BASE) + ⟨p, o, old, level, width, al, rfl, edge, rfl⟩ + have masks : ept.ADDR_MASK = vspace.ADDR_MASK := UScalar.eq_of_val_eq (by + simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + have edge' : L.mem s (wa p' o') &&& 3#u64 = 3#u64 := same ▸ edge + have next := path.child deep inWidth al' range edge' + rw [← same, ← masks] at next + have below : sh - 9 < s1aTopShift 1#u64 n := (S1aPath.childShift path).resolve_right (fun no => no deep) + obtain ⟨y, hy, v, cap, _⟩ := h.paths.children _ _ _ _ _ next below + exact table' _ is y hy _ v cap + exact general t reach target + +set_option hygiene false in +local macro "soaInv" : tactic => `(tactic| + (rcases so with so | so <;> cases d <;> simp only [objects.same_object_as, objects.same_region_as] at so <;> + (try (simp at so; done)) <;> (repeat' (split at so)) <;> (try (simp at so; done)) <;> (try subst_vars))) + +private theorem so_pml4 {p a : U64} {m : Bool} {d : capability.Cap} + (so : objects.same_object_as d (.Pml4 p m a) = ok true ∨ objects.same_object_as (.Pml4 p m a) d = ok true) : + ∃ m' a', d = .Pml4 p m' a' := by + soaInv <;> exact ⟨_, _, rfl⟩ + +private theorem so_high {p a : U64} {m : Bool} {d : capability.Cap} + (so : objects.same_object_as d (.HighVSpace p m a) = ok true ∨ + objects.same_object_as (.HighVSpace p m a) d = ok true) : ∃ m' a', d = .HighVSpace p m' a' := by + soaInv <;> exact ⟨_, _, rfl⟩ + +private theorem so_ept {p l a v : U64} {m : Bool} {d : capability.Cap} + (so : objects.same_object_as d (.Ept p l m a v) = ok true ∨ objects.same_object_as (.Ept p l m a v) d = ok true) : + ∃ m' a' v', d = .Ept p l m' a' v' := by + soaInv <;> simp_all + +/-- A non-final root capability has an exact copy in another slot. -/ +theorem is_final.root_copy (hO : OSOK T Ω Sg OS) (mdb : MdbS st OS s) (refs : S1aTableCaps st OS s) (hx : x ∈ OS) + {c : capability.Cap} (cap : capA st s x = c) (root : S1aRootCap c ptr) + (nonfinal : cdt.is_final_capability_with_cap st s x c = ok false) : + ∃ y ∈ OS, y ≠ x ∧ capA st s y = capA st s x := by + obtain ⟨G, hM, -, -, -, -⟩ := mdb + have nonnull : c ≠ .Null := by + rcases root with ⟨_, _, rfl⟩ | ⟨_, _, rfl⟩ | ⟨_, _, _, rfl⟩ <;> exact fun e => by cases e + obtain ⟨y, hy, ne, so⟩ := nonfinal_nb hO.nz hM hx cap nonnull nonfinal + refine ⟨y, hy, ne, ?_⟩ + have shared (k : Nat × U64) (kx : s1aTableKey (capA st s x) = some k) (ky : s1aTableKey (capA st s y) = some k) : + s1aTableRef (capA st s x) = s1aTableRef (capA st s y) ∧ s1aTableRef (capA st s x) ≠ none := + ⟨refs.references x hx y hy k kx ky, fun none => ne (refs.unique x hx y hy k kx ky none)⟩ + rcases root with ⟨m, a, rfl⟩ | ⟨m, a, rfl⟩ | ⟨m, a, v, rfl⟩ + · obtain ⟨m', a', other⟩ := so_pml4 so + obtain ⟨same, live⟩ := shared (1, ptr) (by rw [cap]; rfl) (by rw [other]; rfl) + rw [cap] at same live ⊢ + rw [other] at same ⊢ + cases m + · exact (live rfl).elim + cases m' + · cases same + injection same with same + injection same with asids _ + rw [asids] + · obtain ⟨m', a', other⟩ := so_high so + obtain ⟨same, live⟩ := shared (3, ptr) (by rw [cap]; rfl) (by rw [other]; rfl) + rw [cap] at same live ⊢ + rw [other] at same ⊢ + cases m + · exact (live rfl).elim + cases m' + · cases same + injection same with same + injection same with asids _ + rw [asids] + · obtain ⟨m', a', v', other⟩ := so_ept so + obtain ⟨same, live⟩ := shared (2, ptr) (by rw [cap]; rfl) (by rw [other]; rfl) + rw [cap] at same live ⊢ + rw [other] at same ⊢ + cases m + · exact (live rfl).elim + cases m' + · cases same + injection same with same + injection same with asids vas + rw [asids, vas] + +/-- A mapped root's own `delete_asid` leaves R2 over the other slots. -/ +theorem S1aFin.deleteRoot (hA : P0.ArchTotal ar) (a : A) (hO : OSOK T Ω Sg OS) + (vr : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s) Pt) (heap : HeapOK H) + (place : S1aR2Place Pt Pp Tb (HvRt st OS s) Te Lv bits (L.ksb s)) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (R : S1aR2 st H OS Pt Pp Tb (HvRt st OS s) Te Kt Lv Re bits n s) (kinds : KindA st OS s) (hx : x ∈ OS) + (root : S1aRootCap (capA st s x) ptr) (mapped : MappedAsidRoot (capA st s x) ptr asid tag) + (small : tag = 0#u64 ∨ tag = 1#u64 ∨ tag = 2#u64) {word : U64} (whole : word = ptr ||| tag) : + vspace.delete_asid st ar s a asid word ⦃ r => S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n r.1 x ⦄ := by + have aligned : ptr &&& 3#u64 = 0#u64 := by + have page : ptr.val % 4096 = 0 := by + rcases root with ⟨m, a', e⟩ | ⟨m, a', e⟩ | ⟨m, a', v, e⟩ + · have al := heap.align ptr _ (R.nativeRoots x hx ptr m a' e).1 + change ptr.val % 2 ^ 12 = 0 at al + omega + · have al := heap.align ptr _ (R.highObjects x hx ptr m a' e) + change ptr.val % 2 ^ 13 = 0 at al + omega + · have al := heap.align ptr _ (R.eptRoots x hx ptr 0#u64 m a' v e).1 + change ptr.val % 2 ^ 13 = 0 at al + omega + apply UScalar.eq_of_val_eq + rw [UScalar.val_and, show (3#u64 : U64).val = 2 ^ 2 - 1 from rfl, Nat.and_two_pow_sub_one_eq_mod] + change ptr.val % 4 = 0 + omega + have low : ptr &&& ~~~3#u64 = ptr := maskedRoot aligned + have join (w g : U64) (high : w &&& ~~~3#u64 = ptr) (kind : w &&& 3#u64 = g) : w = ptr ||| g := by + apply UScalar.eq_of_val_eq + have h1 := congrArg UScalar.bv high + have h2 := congrArg UScalar.bv kind + change w.bv &&& ~~~3#64 = ptr.bv at h1 + change w.bv &&& 3#64 = g.bv at h2 + change w.bv.toNat = (ptr.bv ||| g.bv).toNat + congr 1 + rw [← h1, ← h2, ← BitVec.and_or_distrib_left, BitVec.not_or_self, BitVec.and_allOnes] + have split : (ptr ||| tag) &&& ~~~3#u64 = ptr ∧ (ptr ||| tag) &&& 3#u64 = tag := by + have l1 := congrArg UScalar.bv low + have a1 := congrArg UScalar.bv aligned + change ptr.bv &&& ~~~3#64 = ptr.bv at l1 + change ptr.bv &&& 3#64 = 0#64 at a1 + have tags : tag.bv &&& ~~~3#64 = 0#64 ∧ tag.bv &&& 3#64 = tag.bv := by + rcases small with rfl | rfl | rfl <;> exact ⟨by decide, by decide⟩ + constructor <;> apply UScalar.eq_of_val_eq + · change ((ptr.bv ||| tag.bv) &&& ~~~3#64).toNat = ptr.bv.toNat + rw [BitVec.and_or_distrib_right, l1, tags.1, BitVec.or_zero] + · change ((ptr.bv ||| tag.bv) &&& 3#64).toNat = tag.bv.toNat + rw [BitVec.and_or_distrib_right, a1, tags.2, BitVec.zero_or] + subst whole + refine WP.spec_mono (vspace.delete_asid.rootGone hA a vr ptKs R hx mapped split.1 split.2 + (fun w high kind => join w tag high kind) kinds) fun r ⟨table, mem, writes, gone⟩ => ?_ + have inside : PoolSet st Pp s ⊆ Pt := fun _ hp => R.place.pools hp + have words := (Wr0.w (fun b hb => vr.al b (Or.inl (ptw_mono inside hb))) writes).mono fun _ hb => ptw_mono inside hb + have caps : ∀ y ∈ OS, capA st r.1 y = capA st s y := fun y hy => by + have keep := capk_vsr vr hO (words.mono fun _ hw => Or.inl hw) y hy + rw [capA_eq, capA_eq] at keep + exact okinj keep + have headers : HrW st (HvRt st OS s) s r.1 := by + refine Wr0.hrw (fun b hb => vr.al b (Or.inl (ptw_mono inside hb))) + (fun h hh => vr.al _ (Or.inl ⟨h, R.place.tables (R.place.high.sub hh), 4088#u64, by decide, by decide, rfl⟩)) + (fun b hb h hh => ?_) writes + obtain ⟨p, hp, o, ho, al, rfl⟩ := hb + exact place.high.pp p hp.1 o ho al h hh + have tab := table.toDel + have lookup := VsLk.activeZero R.core place tab mem caps (R.eptRoots.unmZ R.core heap R.pageTables) + have rootAgree := R.core.root.activeZero place.pools tab mem caps + have stage1 := R.core.stage1.activeZero place.pools place.tables tab mem + have stage2 := R.core.stage2.activeZero place.pools place.granules place.stage2 tab mem headers + have unreached (t : U64) (m : MapV (capA st s x) t) := R.rootUnreached heap kinds place table mem hx root gone m + have rooted : (∀ p b, capA st s x ≠ .AsidPool p b) ∧ + ∀ p sz r' d m e a' v, capA st s x ≠ .Frame p sz r' d m e a' v := by + rcases root with ⟨_, _, e⟩ | ⟨_, _, e⟩ | ⟨_, _, _, e⟩ <;> rw [e] <;> + exact ⟨fun _ _ h => (by cases h), fun _ _ _ _ _ _ _ _ h => (by cases h)⟩ + exact (R.dropSlot heap kinds table mem headers caps lookup rootAgree stage1 stage2 rooted + (fun t m reach => (reach.elim (unreached t m).1 (unreached t m).2).elim) + (fun a' w active backed => by + have named : w &&& ~~~3#u64 = ptr := by + rcases root with ⟨_, _, e⟩ | ⟨_, _, e⟩ | ⟨_, _, _, e⟩ <;> rw [e] at backed <;> + rcases backed with ⟨_, h⟩ | ⟨_, _, h⟩ | ⟨_, h⟩ <;> cases h <;> rfl + exact gone a' w active named) + (fun _ _ _ _ _ _ _ _ _ e => by + rcases root with ⟨_, _, h⟩ | ⟨_, _, h⟩ | ⟨_, _, _, h⟩ <;> rw [h] at e <;> cases e)).toDelM + +/-- Finalising a VSpace root capability: `(Null, Null)`, and R2 over the other slots. -/ +theorem S1aFin.root (hA : P0.ArchTotal ar) (hO : OSOK T Ω Sg OS) + (vr : VrOK Ω Sg Scs Z OS Vc Ub (L.ksb s) Pt) (heap : HeapOK H) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) (high : HvRt st OS s ⊆ Hr) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (M : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s) (mdb : MdbS st OS s) (hx : x ∈ OS) + {c : capability.Cap} (cap : capA st s x = c) (root : S1aRootCap c ptr) {f : Bool} + (final : cdt.is_final_capability_with_cap st s x c = ok f) (a : A) : + objects.finalise_cap st ar s a c f false ⦃ r => r.1.1 = .Null ∧ + S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n r.2.1 x ⦄ := by + have R : S1aR2 st H OS Pt Pp Tb (HvRt st OS s) Te Kt Lv Re bits n s := M + have kinds : KindA st OS s := by + obtain ⟨_, _, _, hK, _, _⟩ := mdb + exact hK + have here : S1aR2Place Pt Pp Tb (HvRt st OS s) Te Lv bits (L.ksb s) := place.monoHigh high + have copy (no : f = false) : S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n s x := by + obtain ⟨y, hy, ne, same⟩ := is_final.root_copy hO mdb R.capRefs hx cap root (no ▸ final) + exact M.dropCopy hy ne same + have rootX : S1aRootCap (capA st s x) ptr := by rw [cap]; exact root + -- a final cap with nothing to clear leaves the state + have idle (plain : (∀ p b, c ≠ .AsidPool p b) ∧ (∀ p sz r d m e a' v, c ≠ .Frame p sz r d m e a' v) ∧ + ∀ t m a' v, c ≠ .PageTable t m a' v) + (maps : ∀ t, MapV c t → VsReach st (PoolSet st Pp s) ∅ Lv s t ∨ S2Reach st (PoolSet st Pp s) Re bits s t → + (∀ R' a', c ≠ .HighVSpace R' true a') ∧ ∃ y ∈ OS, y ≠ x ∧ MapV (capA st s y) t) + (entries : ∀ r' a' t, ¬ MappedAsidRoot c r' a' t) : + S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n s x := + (R.dropSlot heap kinds (TabKeep.refl s) (VsZ.refl s) (fun _ _ => rfl) (fun _ _ => rfl) R.core.lookup + R.core.root R.core.stage1 R.core.stage2 + ⟨fun p b => cap ▸ plain.1 p b, fun p sz r d m e a' v => cap ▸ plain.2.1 p sz r d m e a' v⟩ + (fun t m reach => cap ▸ maps t (cap ▸ m) reach) (fun a' w _ => cap ▸ entries _ _ _) + (fun _ _ _ _ _ t _ _ address => cap ▸ plain.2.2 t true _ address)).toDelM + have run (asid tag word : U64) (mapped : MappedAsidRoot c ptr asid tag) + (small : tag = 0#u64 ∨ tag = 1#u64 ∨ tag = 2#u64) (whole : word = ptr ||| tag) : + vspace.delete_asid st ar s a asid word ⦃ r => S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n r.1 x ⦄ := + S1aFin.deleteRoot hA a hO vr heap here ptKs R kinds hx rootX (by rw [cap]; exact mapped) small whole + rcases root with ⟨m, asid, rfl⟩ | ⟨m, asid, rfl⟩ | ⟨m, asid, v, rfl⟩ + · rw [fin_cap_eq_obj (by simp)] + unfold objects.finalise_cap_object + dsimp only + cases f + · simp only [Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 ⟨rfl, copy rfl⟩ + cases m + · simp only [Bool.false_eq_true, ↓reduceIte] + refine (WP.spec_ok _).2 ⟨rfl, idle ⟨fun _ _ e => (by cases e), fun _ _ _ _ _ _ _ _ e => (by cases e), + fun _ _ _ _ e => (by cases e)⟩ (fun t mapV _ => ?_) (fun _ _ _ e => ?_)⟩ + · rcases mapV with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, e, _⟩ | ⟨_, _, _, e⟩ <;> cases e + · rcases e with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e + simp only [↓reduceIte] + refine WP.spec_bind (run asid 0#u64 ptr (Or.inl ⟨rfl, rfl⟩) (Or.inl rfl) ?_) ?_ + · apply UScalar.eq_of_val_eq + rw [UScalar.val_or] + exact (Nat.or_zero _).symm + rintro ⟨s', a'⟩ pending + exact (WP.spec_ok _).2 ⟨rfl, pending⟩ + · rw [fin_cap_eq_obj (by simp)] + unfold objects.finalise_cap_object + dsimp only + cases f + · simp only [Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 ⟨rfl, copy rfl⟩ + cases m + · simp only [Bool.false_eq_true, ↓reduceIte] + refine (WP.spec_ok _).2 ⟨rfl, idle ⟨fun _ _ e => (by cases e), fun _ _ _ _ _ _ _ _ e => (by cases e), + fun _ _ _ _ e => (by cases e)⟩ (fun t mapV _ => ?_) (fun _ _ _ e => ?_)⟩ + · rcases mapV with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, e, _⟩ | ⟨_, _, _, e⟩ <;> cases e + · rcases e with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e + simp only [↓reduceIte, lift, bind_ok] + refine WP.spec_bind (run asid 2#u64 _ (Or.inr (Or.inr ⟨rfl, rfl⟩)) (Or.inr (Or.inr rfl)) ?_) ?_ + · rw [show vspace.ROOT_HIGH = 2#u64 from UScalar.eq_of_val_eq (by simp)] + rintro ⟨s', a'⟩ pending + exact (WP.spec_ok _).2 ⟨rfl, pending⟩ + · rw [fin_cap_eq_obj (by simp)] + unfold objects.finalise_cap_object + dsimp only + cases f + · simp only [Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 ⟨rfl, copy rfl⟩ + simp only [↓reduceIte] + refine WP.spec_bind (Pₘ := fun r : S × A => S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n r.1 x) ?_ ?_ + swap + · rintro ⟨s', a'⟩ pending + exact (WP.spec_ok _).2 ⟨rfl, pending⟩ + have plain : (∀ p b, capability.Cap.Ept ptr 0#u64 m asid v ≠ .AsidPool p b) := fun _ _ e => by cases e + unfold ept.finalise + dsimp only + cases m + · have none : S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n s x := + idle ⟨plain, fun _ _ _ _ _ _ _ _ e => (by cases e), fun _ _ _ _ e => (by cases e)⟩ + (fun t mapV _ => by + rcases mapV with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, e, _⟩ | ⟨_, _, _, e⟩ <;> cases e) + (fun _ _ _ e => by rcases e with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e) + simp only [Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 none + simp only [↓reduceIte, lift, bind_ok] + exact run asid 1#u64 _ (Or.inr (Or.inl ⟨rfl, v, rfl⟩)) (Or.inr (Or.inl rfl)) + (by rw [show vspace.ROOT_S2 = 1#u64 from UScalar.eq_of_val_eq (by simp)]) + +/-- Finalising a Stage-2 cap above level 0: nothing is written, and each table it maps that is still +reached has another namer. -/ +theorem S1aFin.eptInner (hO : OSOK T Ω Sg OS) (heap : HeapOK H) + (M : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s) (mdb : MdbS st OS s) (hx : x ∈ OS) + {level asid v : U64} {m : Bool} (cap : capA st s x = .Ept ptr level m asid v) (inner : level ≠ 0#u64) {f : Bool} + (final : cdt.is_final_capability_with_cap st s x (.Ept ptr level m asid v) = ok f) (a : A) : + objects.finalise_cap st ar s a (.Ept ptr level m asid v) f false ⦃ r => r.1.1 = .Null ∧ + S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n r.2.1 x ⦄ := by + have R : S1aR2 st H OS Pt Pp Tb (HvRt st OS s) Te Kt Lv Re bits n s := M + have kinds : KindA st OS s := by + obtain ⟨_, _, _, hK, _, _⟩ := mdb + exact hK + rw [fin_cap_eq_obj (by simp)] + unfold objects.finalise_cap_object + dsimp only + have pending : S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n s x := by + refine (R.dropSlot heap kinds (TabKeep.refl s) (VsZ.refl s) (fun _ _ => rfl) (fun _ _ => rfl) R.core.lookup + R.core.root R.core.stage1 R.core.stage2 + ⟨fun _ _ e => (by rw [cap] at e; cases e), fun _ _ _ _ _ _ _ _ e => (by rw [cap] at e; cases e)⟩ + (fun t mapV reach => ?_) (fun _ _ _ e => ?_) + (fun _ _ _ _ _ _ _ _ _ e => (by rw [cap] at e; cases e))).toDelM + swap + · rw [cap] at e + rcases e with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e + exact inner rfl + refine ⟨fun _ _ e => (by rw [cap] at e; cases e), ?_⟩ + have outside : t ∉ Kt := fun hk => R.core.lookup.kt t hk x hx mapV.names + have other {y : U64} (differs : capA st s y ≠ .Ept ptr level m asid v) : y ≠ x := + fun e => differs (e ▸ cap) + have rooted (a' w : U64) (entry : ActiveAsidRoot st Pp s a' w) (points : w &&& ~~~3#u64 = t) : + ∃ y ∈ OS, y ≠ x ∧ MapV (capA st s y) t := by + obtain ⟨y, hy, backed⟩ := R.core.root.backed a' w entry + rw [points] at backed + rcases backed with ⟨_, e⟩ | ⟨_, v', e⟩ | ⟨_, e⟩ + · exact ⟨y, hy, other (by rw [e]; exact fun h => by cases h), Or.inr (Or.inl ⟨_, e⟩)⟩ + · refine ⟨y, hy, other ?_, Or.inr (Or.inr (Or.inr (Or.inr ⟨_, _, _, e⟩)))⟩ + rw [e] + intro h + injection h with _ levels + exact inner levels.symm + · exact ⟨y, hy, other (by rw [e]; exact fun h => by cases h), Or.inr (Or.inr (Or.inl ⟨_, e⟩))⟩ + have child {tag' asid' u : U64} {sh va : Nat} (path : S1aPath st Pp n s tag' asid' sh va u) + (below : sh < s1aTopShift tag' n) (same : u = t) : ∃ y ∈ OS, y ≠ x ∧ MapV (capA st s y) t := by + obtain ⟨y, hy, v', e, _⟩ := R.paths.children _ _ _ _ _ path below + rw [same] at e + exact ⟨y, hy, other (by rw [e]; exact fun h => by cases h), Or.inl ⟨_, _, e⟩⟩ + rcases reach with reach | reach + · cases reach with + | hr member => exact member.elim + | @root0 p o pool width al nz tag => + obtain ⟨a', active⟩ := ActiveAsidRoot.forWord pool width al nz + exact rooted a' _ active (maskedRoot tag) + | @root2 p o pool width al tag => + have nz : L.mem s (wa p o) ≠ 0#u64 := fun z => by rw [z] at tag; contradiction + obtain ⟨a', active⟩ := ActiveAsidRoot.forWord pool width al nz + exact rooted a' _ active rfl + | @step p o prev level' width al edge => + rcases R.routeFacts.classifyEdge1 prev level' width al edge rfl outside with + ⟨y, hy, a', e, link, _⟩ | ⟨tag', asid', sh, va, _, path, deep, inWidth, range⟩ + · exact ⟨y, hy, other (by rw [e]; exact fun h => by cases h), + Or.inr (Or.inr (Or.inr (Or.inl ⟨p, a', e, link.symm⟩)))⟩ + · exact child (path.child deep inWidth al range edge) + ((S1aPath.childShift path).resolve_right (fun no => no deep)) rfl + · cases reach with + | @root p o pool width al tag => + have nz : L.mem s (wa p o) ≠ 0#u64 := fun z => by rw [z] at tag; contradiction + obtain ⟨a', active⟩ := ActiveAsidRoot.forWord pool width al nz + exact rooted a' _ active rfl + | @step p o prev level' width al edge => + obtain ⟨asid', sh, va, p', o', path, deep, inWidth, al', same, range⟩ := + R.routeFacts.classifyPageTableParent2 (ptr := wa (L.mem s (wa p o) &&& ept.ADDR_MASK) layout.PPTR_BASE) + ⟨p, o, prev, level', width, al, rfl, edge, rfl⟩ + have masks : ept.ADDR_MASK = vspace.ADDR_MASK := UScalar.eq_of_val_eq (by + simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + have next := path.child deep inWidth al' range (same ▸ edge) + rw [← same, ← masks] at next + exact child next ((S1aPath.childShift path).resolve_right (fun no => no deep)) rfl + cases f + · simp only [Bool.false_eq_true, ↓reduceIte] + exact (WP.spec_ok _).2 ⟨rfl, pending⟩ + simp only [↓reduceIte] + unfold ept.finalise + dsimp only + refine WP.spec_bind (Pₘ := fun r : S × A => r = (s, a)) ?_ (fun r e => ?_) + · split + · exact absurd rfl (by assumption : (0#u64 : U64) ≠ 0#u64) + · exact (WP.spec_ok _).2 rfl + · subst e + exact (WP.spec_ok _).2 ⟨rfl, pending⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Frame.lean b/proofs/Fl4ProofsA64/P1/S1aR2Frame.lean new file mode 100644 index 000000000..ecf3aae8a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Frame.lean @@ -0,0 +1,264 @@ +/- +P1 (aarch64, A64-S1A gen 41): R2 framing for the caller's restart and cache invocations. +Restart writes only outside unmapped table objects. The cache paths keep the store or restart the caller. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aVsUnm +import Fl4ProofsA64.P1.S1aS2Dec +import Fl4ProofsA64.P1.S1aVsDec +import Fl4ProofsA64.P1.S1aBootU +import Fl4ProofsA64.P1.MdbVsFlQ +import Fl4ProofsA64.P1.MdbEptQ + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS Cs Vc Ub Pt Pp Tb Hr Te Kt U Ac : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {cap : capability.Cap} + +/-- The placement of R2's tables and pools, including detached HighVSpace roots. -/ +structure S1aR2Place (Pt Pp Tb Hr Te : Set U64) (Lv bits : U64 → Nat) (kb : U64) : Prop where + pools : Pp ⊆ Pt + tables : Tb ⊆ Pt + granules : Gran Te bits ⊆ Pt + high : HrOK kb Pp Tb Lv Hr + stage2 : S2OK Te bits Hr + +/-- **`hD` from the heap**: no Stage-2 object starts at a 13-bit object's upper granule (`HeapOK.disj` / `fits`). -/ +theorem TeH.hD {Te : Set U64} {Re bits : U64 → Nat} {n : U64} (hH : HeapOK H) (h : TeH H Te Re bits n) : + ∀ p ∈ Te, bits p = 13 → wa p 4096#u64 ∉ Te := by + intro p hp h13 hq + have e1 := (h p hp).1 + have e2 := (h _ hq).1 + have hf := hH.fits p _ e1 + simp only [HKind.bits, h13] at hf + norm_num at hf + have h4 : (4096#u64 : U64).val = 4096 := by simp + have hv : (wa p 4096#u64).val = p.val + 4096 := by rw [wadd_val (by rw [h4]; omega), h4] + have hne : p ≠ wa p 4096#u64 := fun e => by have := congrArg UScalar.val e; omega + have hd := hH.disj p _ _ _ e1 e2 hne + simp only [HKind.bits, h13] at hd + rw [hv] at hd + have h1 := @Nat.one_le_two_pow (bits (wa p 4096#u64)) + generalize (2 : Nat) ^ bits (wa p 4096#u64) = Z at hd h1 + norm_num at hd + omega + +/-- **S1aS2Dec's `S2DecTy.ofS2Ty` with `hR` / `hD` from `TeH`.** -/ +theorem S2DecTy.ofTeH {n : U64} {Pp Hr Te : Set U64} {Re bits : U64 → Nat} (hH : HeapOK H) + (h : S2Ty st n Pp Hr Te Re bits s) (hS : S2OK Te bits Hr) (hT : TeH H Te Re bits n) : + S2DecTy st Pp (Gran Te bits) (s2gRe Te Re) n s := + S2DecTy.ofS2Ty h hS (fun r hr => (hT r hr).2) (TeH.hD hH hT) + +/-- The active R2 typings supply the decoder witness over reachable tables. -/ +theorem S1aR2Core.hvs {Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (hp : Pp ⊆ Pt) (ht : Tb ⊆ Pt) (he : Gran Te bits ⊆ Pt) (hs : S2OK Te bits Hr) : + ∃ (Pp' Tb' : Set U64) (Lv' : U64 → Nat) (Hr' Te' : Set U64) (Re' bits' : U64 → Nat), + Pp' ⊆ Pt ∧ Tb' ⊆ Pt ∧ Gran Te' bits' ⊆ Pt ∧ VsTy st (L.ksb s) Pp' Tb' Lv' s ∧ + NoTag3 st Pp' s ∧ HighRoot511 st Pp' s ∧ S2Ty st n Pp' Hr' Te' Re' bits' s ∧ + S2OK Te' bits' Hr' ∧ TeH H Te' Re' bits' n := by + have hPools : PoolSet st Pp s ⊆ Pt := fun _ hpool => hp hpool.1 + have hHeap : TeH H (S2Rt st (PoolSet st Pp s) Te Re bits s) Re bits n := fun p hp' => h.heap p hp'.1 + refine ⟨PoolSet st Pp s, _, Lv, Hr, _, Re, bits, hPools, VsRt_sub.trans ht, + (gran_mono S2Rt_sub).trans he, h.stage1.sub, ?_, ?_, h.stage2.sub, S2OK.sub hs S2Rt_sub, hHeap⟩ + · intro p hp' o ho h8 hn h3 + rcases h.stage2.tag p hp' o ho h8 hn with ⟨e, -⟩ | ⟨e, -⟩ | ⟨e, -⟩ <;> + rw [e] at h3 <;> exact (by decide : _ ≠ _) h3 + · intro p hp' o ho h8 hn h2 + rcases h.stage2.tag p hp' o ho h8 hn with ⟨e, -⟩ | ⟨_, hr⟩ | ⟨e, -⟩ + · rw [e] at h2 + exact ((by decide : _ ≠ _) h2).elim + · exact h.stage2.hi _ hr + · rw [e] at h2 + exact ((by decide : _ ≠ _) h2).elim + +/-- The caller's restart preserves the entire active-pool R2 witness. -/ +theorem sched.set_thread_state.restartR2 (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (W : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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) : + sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s' => + S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + obtain ⟨Q, R, queues⟩ := D.bxi.1 + have node := queues.nodes _ queues.cur + have cur : L.curW s ∈ H.tcbs := queues.curT + have actionBound : layout.node.SCHED_ACTION.val < 4288 := by rw [act_val]; omega + have stateVal : (stA (L.curW s)).val = (L.curW s).val + 3328 := by + rw [stA_eq, field_val (queues.tcbs _ cur) (by simp)] + simp + refine WP.spec_mono + (WP.spec_and (sched.set_thread_state.unmMid I D) (sts_fine s _ sched.TS_RESTART node (queues.tcbs _ cur))) + fun _ ⟨⟨mid, keep⟩, writes⟩ => ?_ + refine h.keep W.pools W.tables W.granules W.stage2 W.high writes.1 keep + (fun _ hx => mid.k.capA hx) ?_ + intro x hx p size hu o ho h8 + obtain ⟨z, rfl, hp⟩ := h.lookup.vh.1 x hx p size hu + have hz : 3 ≤ z := by + by_contra hlt + have e : (2 : Nat) ^ z = 4096 ∨ (2 : Nat) ^ z = 8192 := hu.imp And.left And.left + have hlt' : z < 3 := by omega + interval_cases z <;> norm_num at e + obtain ⟨al, _, lo, hi⟩ := heap_word I.del.heap hp hz h8 ho + have out := queues.omega _ (HeapOK.otherW I.del.heap hp al lo hi).1 + refine writes.mem_eq al ?_ + rintro (state | action) + · have eq := congrArg UScalar.val state + rw [stateVal] at eq + have outside := out.2.1 _ cur + omega + · have eq := congrArg UScalar.val action + rw [nodeAt_val node actionBound] at eq + have outside := out.2.2 _ queues.cur + omega + +/-- Restarting via the TCB helper also preserves the active-pool R2 witness. -/ +theorem tcb.restart_caller.r2 (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (W : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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) : + tcb.restart_caller st s ⦃ s' => S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + unfold tcb.restart_caller + rw [cur_thread_ok, bind_ok] + exact sched.set_thread_state.restartR2 h W I D + +set_option hygiene false in +local macro "cacheR2Leaf" : tactic => `(tactic| first + | solve | apply (WP.spec_ok _).2; assumption + | solve + | 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, lift, + error.illegal, error.truncated, error.range, error.invalid_cap, error.invalid_arg, vspace.failed_lookup] + first | assumption | (apply (WP.spec_ok _).2; assumption) + ) + +local syntax "flushR2" : tactic +macro_rules + | `(tactic| flushR2) => `(tactic| first + | cacheR2Leaf + | (rdOneQ <;> flushR2)) + +local syntax "eptR2" : tactic +macro_rules + | `(tactic| eptR2) => `(tactic| first + | cacheR2Leaf + | (eptOneQ <;> eptR2)) + +section cache + +variable {Inv : S → Prop} (inv : Inv s) + (rst : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ Inv ⦄) + (hA : P0.ArchTotal ar) +include inv rst hA + +set_option maxRecDepth 20000 in +set_option maxHeartbeats 4000000 in +private theorem vspace.decode_vspace_flush.r2 (a : A) (lbl len ptr : U64) (m : Bool) (asid buf : U64) : + vspace.decode_vspace_flush st ar s a lbl len (.Pml4 ptr m asid) buf ⦃ _ s' _ => + Inv s' ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold vspace.decode_vspace_flush + try simp only [lift, bind_ok] + flushR2 + +set_option maxRecDepth 20000 in +set_option maxHeartbeats 4000000 in +private theorem vspace.decode_page_flush.r2 (a : A) (lbl len : U64) (f : vspace.FrameCap) (buf : U64) : + vspace.decode_page_flush st ar s a lbl len f buf ⦃ _ s' _ => + Inv s' ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold vspace.decode_page_flush ept.flush_frame + try simp only [lift, bind_ok] + flushR2 + +set_option maxRecDepth 20000 in +set_option maxHeartbeats 4000000 in +private theorem ept.decode.r2 (a : A) (lbl len : U64) (c : capability.Cap) (slot buf : U64) : + ept.decode st ar s a lbl len c slot buf extra ⦃ _ s' _ => + Inv s' ⦄ := by + have hS : P0.StoreTotal st := L.total + unfold ept.decode + simp only [lift, bind_ok] + eptR2 + +end cache + +/-- Root cache, frame cache, Stage-2 cache and the rejected legacy table caps. -/ +def DecArmR2Cache (cap : capability.Cap) (lbl : U64) : Prop := + (∃ p m a, cap = .Pml4 p m a) ∨ (∃ p l m a v, cap = .Ept p l m a v) ∨ + (∃ p m a v, cap = .PageDirectory p m a v) ∨ (∃ p m a v, cap = .Pdpt p m a v) ∨ + (∃ p z r dev m e a v, cap = .Frame p z r dev m e a v ∧ + (lbl = fl4_abi.label.ARMPageClean_Data ∨ lbl = fl4_abi.label.ARMPageInvalidate_Data ∨ + lbl = fl4_abi.label.ARMPageCleanInvalidate_Data ∨ lbl = fl4_abi.label.ARMPageUnify_Instruction)) + +/-- Cache invocations keep any state assertion carried through caller restart. -/ +theorem syscall.decode_invocation.cacheInvariant + {Inv : S → Prop} (inv : Inv s) + (rst : sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ Inv ⦄) + (hA : P0.ArchTotal ar) (a : A) {lbl : U64} (hc : DecArmR2Cache cap lbl) + (len slot : 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' _ => + Inv s' ⦄ := by + rcases hc with ⟨p, m, asid, rfl⟩ | ⟨p, l, m, asid, v, rfl⟩ | + ⟨p, m, asid, v, rfl⟩ | ⟨p, m, asid, v, rfl⟩ | ⟨p, z, r, dev, m, e, asid, va, rfl, hl⟩ + · unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + try dsimp only + iterate 4 + refine spec_ite (fun _ => vspace.decode_vspace_flush.r2 inv rst hA a lbl len p m asid buf) + (fun _ => ?_) + simp only [error.illegal, bind_ok] + exact (WP.spec_ok _).2 inv + · unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + exact ept.decode.r2 inv rst hA a lbl len _ slot buf + · unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + simp only [cur_thread_ok, bind_ok, error.invalid_cap] + exact (WP.spec_ok _).2 inv + · unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + simp only [cur_thread_ok, bind_ok, error.invalid_cap] + exact (WP.spec_ok _).2 inv + · have hlabel : lbl ≠ fl4_abi.label.ARMPageMap ∧ lbl ≠ fl4_abi.label.ARMPageUnmap := by + rcases hl with rfl | rfl | rfl | rfl <;> constructor <;> apply lbl_ne_of_val <;> + simp [fl4_abi.label.ARMPageClean_Data, fl4_abi.label.ARMPageInvalidate_Data, + fl4_abi.label.ARMPageCleanInvalidate_Data, fl4_abi.label.ARMPageUnify_Instruction, + fl4_abi.label.ARMPageMap, fl4_abi.label.ARMPageUnmap] + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + try dsimp only + unfold vspace.decode_frame + simp only [vspace.as_frame, bind_ok, cur_thread_ok] + refine spec_ite (fun h => absurd h hlabel.1) (fun _ => ?_) + refine spec_ite (fun h => absurd h hlabel.2) (fun _ => ?_) + rw [vspace.is_cache_label.of hl, bind_ok] + exact spec_ite (fun _ => vspace.decode_page_flush.r2 inv rst hA a lbl len _ buf) + (fun h => absurd rfl h) + +/-- The cache invocations preserve R2, including every active ASID walk. -/ +theorem syscall.decode_invocation.cache_r2 + (inv : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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) + (hA : P0.ArchTotal ar) (a : A) {lbl : U64} (hc : DecArmR2Cache cap lbl) + (len slot : 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' _ => + S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := + syscall.decode_invocation.cacheInvariant inv (sched.set_thread_state.restartR2 inv place I D) + hA a hc len slot blk call don fp buf + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameBacking.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameBacking.lean new file mode 100644 index 000000000..6d00a333c --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameBacking.lean @@ -0,0 +1,112 @@ +/- +P1 (aarch64): active leaf backing through a Frame Map capability rewrite. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameMapWrite +import Fl4ProofsA64.P1.S1aR2SlotUnique + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {s q : S} {n tag slot : U64} + +private theorem frameShiftWord {shift : U64} {size : capability.FrameSize} (sz : size.bits = ok shift) : + (⟨BitVec.ofNat 64 shift.val⟩ : U64) = shift := by + have levels := s1aFrameShift sz + apply UScalar.eq_of_val_eq + change shift.val % 2 ^ 64 = shift.val + exact Nat.mod_eq_of_lt (by omega) + +private theorem s1aLeafNonzero {word : U64} {level : Nat} (valid : s1aLeafValid word level) : + word ≠ 0#u64 := by + rintro rfl + rcases valid with ⟨_, page⟩ | ⟨_, block⟩ + · exact (by decide : (0#u64 &&& 3#u64) ≠ 3#u64) page + · exact (by decide : (0#u64 &&& 3#u64) ≠ 1#u64) block + +set_option maxHeartbeats 3500000 in +/-- The rewritten cap can have backed an old leaf only at the selected slot. +All other leaves keep their witness, and the published leaf has the new cap. -/ +theorem S1aFrameMap.backing {f : vspace.FrameCap} (effect : S1aFrameMap st OS Pt Pp n tag s q slot f) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (ram : FrameOK st H OS s) (member : slot ∈ OS) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) : + S1aPathBacking st H OS Pp Tb Te Lv Re bits n q := by + obtain ⟨asid, va, addr, word, shift, size, selected, aligned, stop, remap, leaf, write⟩ := effect.edit + have encodedSize := frameShiftWord size + have wordShape : word = 0#u64 ∨ s1aLeafValid word shift.val := + leaf.imp And.left And.left + have paths := write.framePaths h heap kinds ptKs selected stop wordShape + obtain ⟨t, b, offset, route, width, offsetAl, position, first, range⟩ := selected.alignedAddress + have selectedBase : s1aCapAddress tag n va = b + offset.val / 8 * 2 ^ shift.val := by + rw [← first, Nat.div_mul_cancel (Nat.dvd_of_mod_eq_zero aligned)] + refine ⟨fun k a sh base p path => h.paths.tables k a sh base p ((paths k a sh base p).1 path), ?_, ?_⟩ + · intro k a sh base p path child + obtain ⟨x, hx, saved, cap, ref⟩ := h.paths.children k a sh base p ((paths k a sh base p).1 path) child + have different : x ≠ slot := by + rintro rfl + rw [old] at cap + cases cap + exact ⟨x, hx, saved, (write.other x hx different).trans cap, ref⟩ + · intro k a sh base p path o bound al inRange valid + have prior := (paths k a sh base p).1 path + dsimp only + by_cases selectedWord : wa p o = addr + · obtain ⟨rfl, rfl, rfl, rfl, rfl, rfl⟩ := + h.samePathWord heap kinds prior route bound width (selectedWord.trans position) + rw [selectedWord, write.descriptor] at valid ⊢ + obtain ⟨_, target⟩ := leaf.resolve_left (fun e => s1aLeafNonzero valid e.1) + have cap := write.cap + rw [if_neg (s1aLeafNonzero valid)] at cap + rw [target] + refine ⟨slot, member, f.size, f.rights, f.is_device, va, by rw [encodedSize]; exact size, + cap, selectedBase, ?_⟩ + 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⟩ + · exact Or.inl rfl + · have keep := write.memory _ (Or.inl (h.pathWord prior bound al)) selectedWord + rw [keep] at valid ⊢ + obtain ⟨x, hx, sz, rights, dev, saved, szOk, cap, savedRef, object⟩ := + h.paths.leaves k a sh base p prior o bound al inRange valid + have different : x ≠ slot := by + rintro rfl + rw [old] at cap + injection cap with _ sameSize _ _ _ _ sameId sameSaved + have nonzero : f.asid ≠ 0#u64 := by + rw [sameId] + obtain ⟨raw, active, _⟩ := prior.rootEntry + rintro rfl + exact h.poolCaps.noZero raw active + obtain ⟨_, idEq, vaEq⟩ := remap nonzero + have sameAsid : a = asid := sameId.symm.trans idEq + rw [sameAsid] at prior + have sameStage := prior.sameTag route + subst k + have scalar : shift = (⟨BitVec.ofNat 64 sh⟩ : U64) := okinj (size.symm.trans (sameSize ▸ szOk)) + have hsh : sh < 64 := by rcases prior.geometry.1 with x | x | x | x <;> omega + have sameLevel : sh = shift.val := by + have eq := congrArg UScalar.val scalar + change shift.val = sh % 2 ^ 64 at eq + rw [Nat.mod_eq_of_lt (by omega : sh < 2 ^ 64)] at eq + exact eq.symm + rw [← sameSaved, vaEq] at savedRef + have oldSlot : S1aSlotAt st Pp n s tag asid (s1aCapAddress tag n va) sh (wa p o) := by + refine ⟨p, base, o, prior, bound, al, rfl, Nat.mod_eq_zero_of_dvd prior.baseAligned, ?_, ?_, inRange⟩ + · rw [savedRef] + · rw [savedRef] + exact Nat.lt_add_of_pos_right (by positivity) + have atDepth : S1aSlotAt st Pp n s tag asid (s1aCapAddress tag n va) shift.val (wa p o) := + sameLevel ▸ oldSlot + exact selectedWord (atDepth.unique selected) + exact ⟨x, hx, sz, rights, dev, saved, szOk, (write.other x hx different).trans cap, savedRef, object⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameClear.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameClear.lean new file mode 100644 index 000000000..c3742457d --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameClear.lean @@ -0,0 +1,146 @@ +/- +P1 (aarch64): Unmap clears every active leaf backed by its invoked frame. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameUnmapWalk +import Fl4ProofsA64.P1.S1aR2MapRoots + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {s : S} + {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {n tag asid addr va ptr shift : U64} {sz : capability.FrameSize} + +private theorem vspace.unmap_root.native {raw : U64} (active : ActiveAsidRoot st Pp s asid raw) + (kind : raw &&& 3#u64 = 0#u64) : vspace.unmap_root st s asid = ok (some (raw, false)) := by + unfold vspace.unmap_root + simp only [active.find, bind_ok, lift, vspace.ROOT_TAG, vspace.ROOT_S1, kind, ite_true] + +private theorem vspace.unmap_root.high {raw : U64} (active : ActiveAsidRoot st Pp s asid raw) + (kind : raw &&& 3#u64 = 2#u64) : vspace.unmap_root st s asid = ok (some (raw &&& ~~~3#u64, true)) := by + unfold vspace.unmap_root + simp only [active.find, bind_ok, lift, vspace.ROOT_TAG, vspace.ROOT_S1, vspace.ROOT_HIGH, kind, + show (2#u64 : U64) ≠ 0#u64 by decide, ite_false, ite_true] + +private theorem ept.find.ofActive {raw : U64} (active : ActiveAsidRoot st Pp s asid raw) + (kind : raw &&& 3#u64 = 1#u64) : ept.find st s asid = ok (.Ok (raw &&& ~~~3#u64)) := by + unfold ept.find + rw [active.find, bind_ok] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, lift, vspace.ROOT_TAG, vspace.ROOT_S2, kind] + rfl + +private theorem vspace.unmap_page.atSlot {root : U64} {high : Bool} + (hA : P0.ArchTotal ar) (a : A) + (rootOk : vspace.unmap_root st s asid = ok (some (root, high))) + (walk : vspace.lookup_pt_slot st s root va ⦃ lu => lu.shift = shift ∧ lu.slot = addr ⦄) + (size : sz.bits = ok shift) (valid : s1aLeafValid (L.mem s addr) shift.val) + (target : s1aLeafTarget (L.mem s addr) shift.val = ptr) (aligned : Aligned addr) : + vspace.unmap_page st ar s a sz asid va ptr ⦃ r => L.mem r.1 addr = 0#u64 ⦄ := by + unfold vspace.unmap_page + rw [rootOk, bind_ok] + refine WP.spec_bind walk fun lu ⟨sh, loc⟩ => ?_ + rw [show vspace.page_shift sz = ok shift from size, bind_ok, sh, loc] + have noDiff : (shift != shift) = false := by simp + simp only [noDiff, Bool.false_eq_true, ite_false] + rw [L.read_eq, bind_ok] + refine WP.spec_bind (vspace.is_page.exact (L.mem s addr) shift) fun validBit iff => ?_ + rw [iff.mpr valid] + simp only [ite_true, vspace.page_base.exact size target, eq_of_spec_fd (paddr_spec ptr), bind_ok] + have same : (ws ptr layout.PPTR_BASE != ws ptr layout.PPTR_BASE) = false := by simp + simp only [same, Bool.false_eq_true, ite_false] + refine WP.spec_bind (LawfulStore.write_spec s addr 0#u64) fun q eq => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine WP.spec_bind (hA.invalidate_high_page a va) fun a' _ => ?_ + exact (WP.spec_ok _).2 (eq.symm ▸ L.mem_wr_same aligned) + · refine WP.spec_bind (hA.invalidate_page a asid va) fun a' _ => ?_ + exact (WP.spec_ok _).2 (eq.symm ▸ L.mem_wr_same aligned) + +private theorem S1aSlotAt.stage1Address + (atSlot : S1aSlotAt st Pp n s tag asid va.val shift.val addr) : + (tag = 0#u64 → va.val < 2 ^ 47) ∧ + (tag = 2#u64 → fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ va.val ∧ va.val < fl4_abi.consts.HIGH_VSPACE_TOP.val) := by + obtain ⟨p, base, o, path, width, align, loc, bAligned, lo, hi, region⟩ := atSlot.entry + change base + o.val / 8 * 2 ^ shift.val ≤ va.val at lo + change va.val < base + o.val / 8 * 2 ^ shift.val + 2 ^ shift.val at hi + constructor + · intro kind + rw [kind] at region + change base + o.val / 8 * 2 ^ shift.val + 2 ^ shift.val ≤ fl4_abi.consts.USER_TOP.val + 1 at region + rw [P0.Consts.fl4_abi.consts.USER_TOP.val_eq] at region + omega + · intro kind + rw [kind] at region + change fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ base + o.val / 8 * 2 ^ shift.val ∧ + base + o.val / 8 * 2 ^ shift.val + 2 ^ shift.val ≤ fl4_abi.consts.HIGH_VSPACE_TOP.val at region + exact ⟨le_trans region.1 lo, lt_of_lt_of_le hi region.2⟩ + +set_option maxHeartbeats 3600000 in +/-- A Stage-1 frame that backs an active leaf causes that leaf to be zeroed, +whether its root is native or HighVSpace. -/ +theorem vspace.unmap_page.clearsActiveLeaf (hA : P0.ArchTotal ar) (a : A) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (stage : tag = 0#u64 ∨ tag = 2#u64) + (atSlot : S1aSlotAt st Pp n s tag asid va.val shift.val addr) + (size : sz.bits = ok shift) (valid : s1aLeafValid (L.mem s addr) shift.val) + (target : s1aLeafTarget (L.mem s addr) shift.val = ptr) (aligned : Aligned addr) : + vspace.unmap_page st ar s a sz asid va ptr ⦃ r => L.mem r.1 addr = 0#u64 ⦄ := by + obtain ⟨_, _, _, path, _⟩ := atSlot.entry + obtain ⟨raw, active, rootTag⟩ := path.rootEntry + obtain ⟨lowWindow, highWindow⟩ := atSlot.stage1Address + rcases stage with rfl | rfl + · refine vspace.unmap_page.atSlot hA a (vspace.unmap_root.native active rootTag) ?_ size valid target aligned + refine WP.spec_mono (vspace.lookup_pt_slot.nativeStop (n := n) raw va (.native active rootTag) (lowWindow rfl)) ?_ + intro lu ⟨slot, stop⟩ + obtain ⟨eq, loc⟩ := atSlot.leafStop slot valid stop + exact ⟨UScalar.eq_of_val_eq eq.symm, loc.symm⟩ + · obtain ⟨x, hx, cap⟩ := h.core.root.backed asid raw active + rw [rootTag] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + let root := raw &&& ~~~3#u64 + have header := h.highHeaders x hx root true asid cap + have ⟨lower, upper⟩ := highWindow rfl + refine vspace.unmap_page.atSlot hA a (vspace.unmap_root.high active rootTag) ?_ size valid target aligned + refine WP.spec_mono (vspace.lookup_pt_slot.highStop (n := n) root va header (.high active rootTag header) lower upper) ?_ + intro lu ⟨slot, stop⟩ + obtain ⟨eq, loc⟩ := atSlot.leafStop slot valid stop + exact ⟨UScalar.eq_of_val_eq eq.symm, loc.symm⟩ + +set_option maxHeartbeats 2400000 in +/-- Stage-2 Unmap zeroes a backed active leaf at the hardware-normalized IPA. -/ +theorem ept.unmap.clearsActiveLeaf (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (a : A) + (atSlot : S1aSlotAt st Pp hPl.ipa s 1#u64 asid (s1aCapAddress 1#u64 hPl.ipa va) shift.val addr) + (size : sz.bits = ok shift) (valid : s1aLeafValid (L.mem s addr) shift.val) + (target : s1aLeafTarget (L.mem s addr) shift.val = ptr) (aligned : Aligned addr) : + ept.unmap st ar s a asid va ptr shift false ⦃ r => L.mem r.1 addr = 0#u64 ⦄ := by + obtain ⟨_, _, _, path, _⟩ := atSlot.entry + obtain ⟨raw, active, rootTag⟩ := path.rootEntry + unfold ept.unmap + rw [ept.find.ofActive active rootTag, bind_ok, hPl.ipa_eq a] + dsimp only + rw [bind_ok] + refine WP.spec_bind (ept.lookup_slot.exactStop (n := hPl.ipa) _ va (.stage2 active rootTag)) fun lu ⟨slot, stop⟩ => ?_ + obtain ⟨valEq, loc⟩ := atSlot.leafStop slot valid stop + have sh : lu.shift = shift := UScalar.eq_of_val_eq valEq.symm + rw [sh, ← loc] + have noDiff : (shift != shift) = false := by simp + simp only [noDiff, Bool.false_eq_true, ite_false] + rw [L.read_eq, bind_ok] + refine WP.spec_bind (ept.is_leaf.exact (L.mem s addr) shift) fun validBit iff => ?_ + rw [iff.mpr valid] + simp only [ite_true, ept.leaf_base.exact size target, eq_of_spec_fd (paddr_spec ptr), bind_ok] + have same : (ws ptr layout.PPTR_BASE != ws ptr layout.PPTR_BASE) = false := by simp + simp only [same, Bool.false_eq_true, ite_false] + refine WP.spec_bind (LawfulStore.write_spec s addr 0#u64) fun q eq => ?_ + refine WP.spec_bind (hA.invalidate_stage2_page a asid va) fun a' _ => ?_ + exact (WP.spec_ok _).2 (eq.symm ▸ L.mem_wr_same aligned) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameMapDecode.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapDecode.lean new file mode 100644 index 000000000..74a19e373 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapDecode.lean @@ -0,0 +1,193 @@ +/- +P1 (aarch64): exact Frame Map at the syscall decoder. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameMapStage1 +import Fl4ProofsA64.P1.S1aR2FrameMapStage2 + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Vc Ub Cs U Ac Rp Nt : Set U64} {Lv Re bits : U64 → Nat} {s : S} + {slot : U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + +set_option hygiene false in +local macro "frameDecodeError" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 (Or.inl rfl) + | (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.truncated, error.invalid_cap, error.invalid_arg] + exact (WP.spec_ok _).2 (Or.inl rfl))) + +set_option hygiene false in +local macro "nativeFrameFinish" : tactic => `(tactic| + ( + by_cases lower : va.val < 2 ^ 47 + · refine WP.spec_mono (vspace.frameMapFinish1 (tag := 0#u64) hA h vr P.os P.src d + canon right vaCanon size (alignment shift size) vaAligned (by decide) remap + (vspace.lookup_pt_slot.nativeStop root va path lower) root a false) ?_ + exact fun _ result => result.imp id (fun effect => ⟨0#u64, effect⟩) + · have upper := (canon_lt vaCanon).resolve_left lower + have empty := h.rootSlots.native x live root true asid rootAt + refine WP.spec_bind (vspace.lookup_pt_slot.nativeUpper root va empty (s1aNativeHighIndex va upper)) fun lu top => ?_ + refine spec_ite (fun _ => by frameDecodeError) (fun contradiction => ?_) + have eq : lu.shift = shift := by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using contradiction + have sz := s1aFrameShift size + have same := congrArg UScalar.val eq + omega + )) + +set_option hygiene false in +local macro "nativeFrameDecode" : tactic => `(tactic| + ( + refine WP.spec_bind (vspace.check_vspace.path h (capA st s x) 1#u64) fun r selected => ?_ + rcases r with ⟨root, asid⟩ | ex + swap + · frameDecodeError + obtain ⟨rootAt, path⟩ := selected root asid rfl + simp only [irq_branch_ok, bind_ok, lift] + refine WP.spec_bind (vspace.page_shift.exact f.size) fun shift size => ?_ + try simp only [lift, bind_ok] + refine WP.spec_bind (s1aFrameScale size) fun scale scaleEq => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by frameDecodeError) (fun notMisaligned => ?_) + have mask : va &&& ws scale 1#u64 = 0#u64 := by + simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using notMisaligned + have vaAligned := s1aFrameVAAligned mask scaleEq + refine spec_ite (fun nonzero => ?_) (fun zero => ?_) + · refine spec_ite (fun _ => by frameDecodeError) (fun changedAsid => ?_) + refine spec_ite (fun _ => by frameDecodeError) (fun changedVa => ?_) + have remap : f.asid ≠ 0#u64 → f.is_ept = false ∧ f.asid = asid ∧ f.vaddr = va := by + intro h + exact ⟨saved h, by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using changedAsid, + by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using changedVa⟩ + have equal : f.vaddr = va := by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using changedVa + have vaCanon : CapRt.Canonical va := equal ▸ savedCanon (bne_iff_ne.1 nonzero) + nativeFrameFinish + · refine WP.spec_bind (s1aFrameScale size) fun scale' _ => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by frameDecodeError) (fun lastBound => ?_) + refine spec_ite (fun _ => by frameDecodeError) (fun noWrap => ?_) + have remap : f.asid ≠ 0#u64 → f.is_ept = false ∧ f.asid = asid ∧ f.vaddr = va := + fun h => (zero (bne_iff_ne.2 h)).elim + have lo : va.val ≤ (wa va (ws scale' 1#u64)).val := Nat.le_of_not_gt noWrap + have hi : (wa va (ws scale' 1#u64)).val ≤ fl4_abi.consts.USER_TOP.val := Nat.le_of_not_gt lastBound + rw [P0.Consts.fl4_abi.consts.USER_TOP.val_eq] at hi + have vaCanon : CapRt.Canonical va := canon_of_lt (Or.inl (by omega)) + nativeFrameFinish + )) + +set_option hygiene false in +local macro "stage1FrameDecode" : tactic => `(tactic| + ( + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun high _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine WP.spec_mono (vspace.decode_high_page_map.exactEffect hA h vr P.os P.src d f canon right + alignment saved live _ rfl a va vm attr) ?_ + exact fun _ result => result.imp id (fun effect => ⟨2#u64, effect⟩) + nativeFrameDecode + )) + +set_option maxHeartbeats 4000000 in +/-- Page Map either leaves the state unchanged or reports the concrete edit +for the root kind reached by the decoder. -/ +theorem vspace.decode_page_map.exactEffect (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (f : vspace.FrameCap) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) extra) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + (alignment : ∀ sh, f.size.bits = ok sh → f.ptr.val % 2 ^ sh.val = 0) + (a : A) (len buf : U64) : + vspace.decode_page_map st ar s a len slot f buf extra ⦃ r => + r.2.1 = s ∨ ∃ tag, S1aFrameMap st OS Pt Pp hPl.ipa tag s r.2.1 slot f ⦄ := by + have wf := CapRt.decodeF_encWf (L.mem s slot).bv (L.mem s (wa slot 8#u64)).bv + change CapRt.EncWf (capA st s slot) at wf + rw [old] at wf + have common : CapRt.Canonical f.ptr ∧ f.rights.val < 4 := by + cases e : f.is_ept <;> simp only [e, CapRt.EncWf] at wf <;> exact ⟨wf.1, wf.2.1⟩ + obtain ⟨canon, right⟩ := common + have savedStage1 : f.is_ept = false → CapRt.Canonical f.vaddr := fun e => by + simp only [e, CapRt.EncWf] at wf + exact wf.2.2.2 + have savedStage2 : f.is_ept = true → f.vaddr.val < 2 ^ 48 := fun e => by + simp only [e, CapRt.EncWf] at wf + exact wf.2.2.2 + unfold vspace.decode_page_map + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (vspace.extra.memA extra 0#usize) fun o read => ?_ + rcases o with _ | x + · frameDecodeError + have live := P.ext x (read x rfl).1 (read x rfl).2 + try dsimp only + refine spec_ite (fun _ => ?_) (fun _ => by frameDecodeError) + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun va _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun _ _ => ?_ + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun attr _ => ?_ + refine WP.spec_bind (P0.capability.Rights.from_word.p0 _) fun _ _ => ?_ + refine WP.spec_bind (P0.capability.mask_vm_rights.p0 _ _) fun vm _ => ?_ + rw [capA_eq, bind_ok] + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun b _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine WP.spec_bind (ept.root.path h _ 1#u64) fun r selected => ?_ + rcases r with ⟨root, asid⟩ | ex + swap + · frameDecodeError + have path := selected (root, asid) rfl + simp only [irq_branch_ok, bind_ok] + have finish (saved : f.asid ≠ 0#u64 → f.is_ept = true ∧ f.vaddr.val < 2 ^ 48) := + WP.spec_mono (ept.map_frame.exactEffect hA hPl h vr P.os P.src d f canon right alignment saved path a va vm attr) + fun r result => + show r.2.1 = s ∨ ∃ tag, S1aFrameMap st OS Pt Pp hPl.ipa tag s r.2.1 slot f from + result.imp id (fun effect => ⟨1#u64, effect⟩) + refine spec_ite (fun _ => ?_) (fun zero => ?_) + · refine spec_ite (fun isEpt => ?_) (fun _ => by frameDecodeError) + exact finish fun _ => ⟨isEpt, savedStage2 isEpt⟩ + · exact finish fun ne => (zero (bne_iff_ne.mpr ne)).elim + refine spec_ite (fun _ => ?_) (fun zero => ?_) + · refine spec_ite (fun _ => by frameDecodeError) (fun notEpt => ?_) + have stored : f.is_ept = false := Bool.eq_false_of_not_eq_true notEpt + have saved : f.asid ≠ 0#u64 → f.is_ept = false := fun _ => stored + have savedCanon : f.asid ≠ 0#u64 → CapRt.Canonical f.vaddr := fun _ => savedStage1 stored + stage1FrameDecode + · have saved : f.asid ≠ 0#u64 → f.is_ept = false := fun ne => (zero (bne_iff_ne.mpr ne)).elim + have savedCanon : f.asid ≠ 0#u64 → CapRt.Canonical f.vaddr := fun ne => (zero (bne_iff_ne.mpr ne)).elim + stage1FrameDecode + +/-- The concrete ARMPageMap syscall returns the exact decoder edit for all three +root kinds, using size alignment from the source cap and kernel heap. -/ +theorem syscall.decode_invocation.frameMapExactEffect (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (ram : FrameOK st H OS s) (dev : DevFrAl st OS s) + {ptr rights oldAsid oldVa : U64} {sz : capability.FrameSize} {device mapped oldStage : Bool} + (cap : obj.Slot.cap st slot s = ok (.Frame ptr sz rights device mapped oldStage oldAsid oldVa)) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame ptr sz rights device mapped oldStage oldAsid oldVa) extra) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageMap len slot + (.Frame ptr sz rights device mapped oldStage oldAsid oldVa) blk call don fp buf extra ⦃ _ q _ => + q = s ∨ ∃ tag, S1aFrameMap st OS Pt Pp hPl.ipa tag s q slot + ⟨ptr, sz, rights, device, mapped, oldStage, oldAsid, oldVa⟩ ⦄ := by + have old := okinj ((capA_eq s slot).symm.trans cap) + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + unfold vspace.decode_frame + simp only [vspace.as_frame, bind_ok] + rw [cur_thread_ok, bind_ok, ite_true] + exact vspace.decode_page_map.exactEffect hA hPl h vr P + ⟨ptr, sz, rights, device, mapped, oldStage, oldAsid, oldVa⟩ d old + (fun _ size => s1aFrameAligned P.heap ram dev P.src old size) a len buf + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameMapPost.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapPost.lean new file mode 100644 index 000000000..b23eb8cec --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapPost.lean @@ -0,0 +1,167 @@ +/- +P1 (aarch64): full R2 through the exact Frame Map syscall. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameMapDecode +import Fl4ProofsA64.P1.S1aR2FrameBacking +import Fl4ProofsA64.P1.S1aR2FrameRaw +import Fl4ProofsA64.P1.S1aR2MapCaps +import Fl4ProofsA64.P1.S1aR2Image +import Fl4ProofsA64.P1.S1aR2UnmapRoute + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {s q : S} {n tag slot : U64} + +set_option maxHeartbeats 3900000 in +/-- A Frame Map preserves full R2 on the same heap, slots, footprint, and +table witnesses. Only the selected leaf and the invoked frame metadata can change. -/ +theorem S1aR2.ofFrameMap {f : vspace.FrameCap} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (ram : FrameOK st H OS s) (member : slot ∈ OS) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + (event : S1aFrameMap st OS Pt Pp n tag s q slot f) : + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := by + obtain ⟨asid, va, addr, word, sh, _, selected, _, _, _, leaf, write⟩ := event.edit + obtain ⟨mapped, stage, ref, saved, output⟩ : ∃ mapped stage ref saved, + capA st q slot = .Frame f.ptr f.size f.rights f.is_device mapped stage ref saved := by + by_cases empty : word = 0#u64 + · exact ⟨false, false, 0#u64, 0#u64, by simpa only [if_pos empty] using write.cap⟩ + · exact ⟨true, tag == 1#u64, asid, va, by simpa only [if_neg empty] using write.cap⟩ + have same x (hx : x ∈ OS) (c : capability.Cap) + (notFrame : ∀ m e a v, c ≠ .Frame f.ptr f.size f.rights f.is_device m e a v) : + capA st q x = c ↔ capA st s x = c := by + by_cases eq : x = slot + · rw [eq, old, output] + exact ⟨fun eq => (notFrame _ _ _ _ eq.symm).elim, fun eq => (notFrame _ _ _ _ eq.symm).elim⟩ + · rw [write.other x hx eq] + have tableEq x (hx : x ∈ OS) c (hc : R2TableCap c) : + capA st q x = c ↔ capA st s x = c := + same x hx c fun _ _ _ _ eq => by rw [eq] at hc; exact hc + have rootBack x (hx : x ∈ OS) c (kind : kindA c = 17 ∨ kindA c = 19 ∨ kindA c = 25) + (cap : capA st q x = c) : capA st s x = c := + (same x hx c (by intro _ _ _ _ eq; rw [eq] at kind; simp [kindA] at kind)).1 cap + have image : R2CapImage st OS s q := by + intro c hc + constructor <;> rintro ⟨x, hx, eq⟩ + · exact ⟨x, hx, (tableEq x hx c hc).1 eq⟩ + · exact ⟨x, hx, (tableEq x hx c hc).2 eq⟩ + obtain ⟨keep, pools⟩ := write.keepAsid h heap kinds ptKs selected + have wordShape : word = 0#u64 ∨ s1aLeafValid word sh.val := leaf.imp And.left And.left + obtain ⟨ty1, reach1⟩ := write.frameRawStage1 h heap kinds ptKs selected wordShape + obtain ⟨ty2, reach2⟩ := write.frameRawStage2 h heap kinds ptKs selected wordShape + have lookup := h.core.lookup.keepImageOfReach image reach1 reach2 + (fun _ hx _ _ cap _ bound al => write.keepUnmappedWordOfWrite h heap selected hx cap bound al) + have root := h.core.root.keepImage keep.toDel image (fun p hp o bound al => Or.inl (pools p hp o bound al)) + have slotRules := write.rootSlotsOfCaps h heap kinds selected rootBack + obtain ⟨emptyNative, emptyHigh⟩ := write.emptyRootsOfCaps h heap kinds selected rootBack + have tableSame x (hx : x ∈ OS) k (key : s1aTableKey (capA st q x) = some k) : + capA st q x = capA st s x := by + apply write.other x hx + rintro rfl + rw [output] at key + cases key + have refs : S1aTableCaps st OS q := by + refine ⟨?_, ?_, emptyNative, emptyHigh⟩ + · intro x hx y hy k xKey yKey + have xEq := tableSame x hx k xKey + have yEq := tableSame y hy k yKey + rw [xEq, yEq] + exact h.capRefs.references x hx y hy k (xEq ▸ xKey) (yEq ▸ yKey) + · intro x hx y hy k xKey yKey none + have xEq := tableSame x hx k xKey + have yEq := tableSame y hy k yKey + exact h.capRefs.unique x hx y hy k (xEq ▸ xKey) (yEq ▸ yKey) (xEq ▸ none) + have header p (hp : p ∈ Hr) : L.mem q (wa p 4088#u64) = L.mem s (wa p 4088#u64) := + write.highHeader h heap kinds selected hp 4088#u64 (by decide) (by decide) + have highSet : Hr = HvRt st OS q := by + rw [h.highRoots] + ext p + constructor <;> rintro ⟨x, hx, m, a, cap⟩ + · exact ⟨x, hx, m, a, (tableEq x hx (.HighVSpace p m a) trivial).2 cap⟩ + · exact ⟨x, hx, m, a, (tableEq x hx (.HighVSpace p m a) trivial).1 cap⟩ + have closed t (ht : t ∈ Kt) (depth : Lv t < 3) (o : U64) (bound : o.val < 4096) (al : o.val % 8 = 0) + (valid : L.mem q (wa t o) &&& 3#u64 = 3#u64) : + wa (L.mem q (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + have loc : PtW Pt (wa t o) := ⟨t, h.place.tables (h.kernelTables.1 ht), o, bound, al, rfl⟩ + rw [write.memory _ (Or.inl loc) (h.pathOffKernel heap selected ht o bound)] at valid ⊢ + exact h.kernelClosed t ht depth o bound al valid + have kindPost : KindA st OS q := by + apply kinds.keep + intro x hx + by_cases eq : x = slot + · rw [eq, old, output] + simp only [RngKeyA, isFrA, Bool.true_eq_false, and_false, iff_self, false_implies, and_self] + · rw [write.other x hx eq] + exact ⟨Iff.rfl, fun _ => ⟨rfl, rfl⟩⟩ + have routes : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := + ⟨lookup, root, h.core.heap, event.backing h heap kinds ptKs ram member old, refs, slotRules, highSet, + (fun p hp => by rw [header p hp]; exact h.highLink p hp), + (fun x hx p m a c => h.highObjects x hx p m a ((tableEq x hx (.HighVSpace p m a) trivial).1 c)), + (fun x hx p l m a v c => h.eptRoots x hx p l m a v ((tableEq x hx (.Ept p l m a v) trivial).1 c)), + (fun x hx p m a v c => h.pageObjects x hx p m a v ((tableEq x hx (.PageTable p m a v) trivial).1 c)), closed⟩ + exact { + core := ⟨lookup, routes.recoverWalk heap kindPost, root, ty1, ty2, h.core.heap⟩ + place := by rw [keep.1, keep.poolSet_eq]; exact h.place + poolCaps := h.poolCaps.keep keep pools (fun x hx p a => same x hx _ (by intro _ _ _ _ eq; cases eq)) + capRefs := refs + paths := routes.paths + pageTables := fun x hx p m a v c => h.pageTables x hx p m a v ((tableEq x hx (.PageTable p m a v) trivial).1 c) + footprint := h.footprint + pageObjects := routes.pageObjects + nativeRoots := fun x hx p m a c => h.nativeRoots x hx p m a ((tableEq x hx (.Pml4 p m a) trivial).1 c) + eptRoots := routes.eptRoots + highObjects := routes.highObjects + highHeaders := fun x hx p m a c => by + have live : p ∈ Hr := by rw [highSet]; exact ⟨x, hx, m, a, c⟩ + rw [header p live] + exact h.highHeaders x hx p m a ((tableEq x hx (.HighVSpace p m a) trivial).1 c) + highLink := routes.highLink + highRoots := highSet + highFootprint := h.highFootprint + kernelTables := h.kernelTables + kernelClosed := closed + rootSlots := slotRules } + +section dispatch + +variable {A : Type _} {ar : machine.Arch A} {Cs Vc Ub U Ac Rp Nt : Set U64} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +/-- The concrete ARMPageMap dispatch carries full R2 through fresh mappings, +remaps, Stage-2 rights-denied clears, and every rejected request. -/ +theorem syscall.decode_invocation.frameMapExactR2 (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (B : SysL st H Cs OS ia ie s) (dev : DevFrAl st OS s) + {ptr rights oldAsid oldVa : U64} {sz : capability.FrameSize} {device mapped oldStage : Bool} + (cap : obj.Slot.cap st slot s = ok (.Frame ptr sz rights device mapped oldStage oldAsid oldVa)) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame ptr sz rights device mapped oldStage oldAsid oldVa) extra) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageMap len slot + (.Frame ptr sz rights device mapped oldStage oldAsid oldVa) blk call don fp buf extra ⦃ _ q _ => + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ⦄ := by + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + have old := okinj ((capA_eq s slot).symm.trans cap) + refine WP.spec_mono (syscall.decode_invocation.frameMapExactEffect hA hPl h vr P B.sys.fr dev cap d + a len blk call don fp buf) ?_ + rintro ⟨_, q, _⟩ (eq | ⟨tag, edit⟩) + · change q = s at eq + subst q + exact h + · exact h.ofFrameMap P.heap kinds ptKs B.sys.fr P.src old edit + +end dispatch + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameMapStage1.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapStage1.lean new file mode 100644 index 000000000..b7adb5a96 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapStage1.lean @@ -0,0 +1,164 @@ +/- +P1 (aarch64): exact Native and HighVSpace Frame Map publication. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameMapWrite +import Fl4ProofsA64.P1.S1aR2MapRoots + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Vc Ub Cs U Ac : Set U64} {Lv Re bits : U64 → Nat} + {s : S} {n slot tag root asid va vm attr shift : U64} {c : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {f : vspace.FrameCap} + +/-- The accepted Stage-1 walk leads to the exact leaf edit, including the +updated cap's unchanged pointer, size, type, and rights. -/ +theorem vspace.frameMapFinish1 (hA : P0.ArchTotal ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (os : OSOK H.tcbs H.omega H.frame OS) + (member : slot ∈ OS) (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s c extra) + (canon : CapRt.Canonical f.ptr) (right : f.rights.val < 4) (uCanonical : CapRt.Canonical va) + (size : f.size.bits = ok shift) (alignment : f.ptr.val % 2 ^ shift.val = 0) + (vaAligned : va.val % 2 ^ shift.val = 0) (stage : tag ≠ 1#u64) + (remap : f.asid ≠ 0#u64 → f.is_ept = false ∧ f.asid = asid ∧ f.vaddr = va) + (walk : vspace.lookup_pt_slot st s root va ⦃ lu => + S1aSlotAt st Pp n s tag asid va.val lu.shift.val lu.slot ∧ + (12 < lu.shift.val → L.mem s lu.slot &&& 3#u64 ≠ 3#u64) ⦄) + (installedRoot : U64) (a : A) (high : Bool) : + (do + let lu ← vspace.lookup_pt_slot st s root va + if lu.shift != shift then + ok (core.result.Result.Err (error.Exc.Sys + (error.SysError.FailedLookup false (error.LookupFault.MissingCapability lu.shift))), s, a) + else + let r ← vspace.rights_readable f.rights + let pa ← layout.paddr f.ptr + let word ← vspace.make_user_page pa vm r attr shift + let r ← sched.set_thread_state st s (L.curW s) sched.TS_RESTART + let m ← obj.Slot.set_cap st slot r (.Frame f.ptr f.size f.rights f.is_device true false asid va) + let (out, h') ← vspace.install_page st ar m a lu word installedRoot asid va f attr high + ok (core.result.Result.Ok (), out, h')) ⦃ r => + r.2.1 = s ∨ S1aFrameMap st OS Pt Pp n tag s r.2.1 slot f ⦄ := by + have sizes := s1aFrameShift size + have szLow : 12 ≤ shift.val := by omega + have szHigh : shift.val ≤ 30 := by omega + have tagValue : (tag == 1#u64) = false := by simpa using stage + refine WP.spec_bind walk fun lu ⟨found, stop⟩ => ?_ + refine spec_ite (fun _ => (WP.spec_ok _).2 (Or.inl rfl)) (fun wrongSize => ?_) + have resShift : lu.shift = shift := by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using wrongSize + have atShift : S1aSlotAt st Pp n s tag asid va.val shift.val lu.slot := resShift ▸ found + have noEdge : 12 < shift.val → L.mem s lu.slot &&& 3#u64 ≠ 3#u64 := resShift ▸ stop + obtain ⟨_, _, _, route, width, aligned, position, _, _, _⟩ := atShift.entry + have inside : PtW Pt lu.slot := position.symm ▸ h.pathWord route width aligned + refine WP.spec_bind (P0.vspace.rights_readable.p0 f.rights) fun read _ => ?_ + rw [show layout.paddr f.ptr = ok (ws f.ptr layout.PPTR_BASE) by rfl, bind_ok] + refine WP.spec_bind (vspace.make_user_page.exactLeaf vm read attr canon szLow szHigh alignment) + fun word ⟨valid, target⟩ => ?_ + refine WP.spec_bind (sched.set_thread_state.frameMapTail1 vr os member d inside hA a f + installedRoot asid va attr word high ⟨canon, right, route.asidFits, uCanonical⟩) fun q write => ?_ + refine WP.spec_bind write fun m tail => ?_ + refine WP.spec_bind tail ?_ + rintro ⟨out, h'⟩ edit + have nonzero : word ≠ 0#u64 := by + rintro rfl + rcases valid with ⟨_, page⟩ | ⟨_, block⟩ + · exact (by decide : (0#u64 &&& 3#u64) ≠ 3#u64) page + · exact (by decide : (0#u64 &&& 3#u64) ≠ 1#u64) block + have path' : S1aSlotAt st Pp n s tag asid (s1aCapAddress tag n va) shift.val lu.slot := by + simpa only [s1aCapAddress, if_neg stage] using atShift + have addrAligned : s1aCapAddress tag n va % 2 ^ shift.val = 0 := by + simpa only [s1aCapAddress, if_neg stage] using vaAligned + exact (WP.spec_ok _).2 (Or.inr ⟨asid, va, lu.slot, word, shift, size, path', addrAligned, noEdge, + by simpa only [tagValue] using remap, Or.inr ⟨valid, target⟩, + by simpa only [if_neg nonzero, tagValue] using edit⟩) + +/-- A canonical upper-half address selects a reserved Native L0 word. -/ +theorem s1aNativeHighIndex (va : U64) (upper : 2 ^ 64 - 2 ^ 47 ≤ va.val) : + 256 ≤ (va.val >>> 39) &&& 511 := by + have fits := va.bv.isLt + change va.val < 2 ^ 64 at fits + rw [Nat.shiftRight_eq_div_pow, show 511 = 2 ^ 9 - 1 by decide, Nat.and_two_pow_sub_one_eq_mod] + norm_num at upper fits ⊢ + omega + +set_option hygiene false in +local macro "frameMapError1" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 (Or.inl rfl) + | (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.invalid_cap, error.invalid_arg] + exact (WP.spec_ok _).2 (Or.inl rfl))) + +set_option hygiene false in +local macro "frameHighBounds" : tactic => `(tactic| + (try simp only [lift, bind_ok] + refine WP.spec_bind (s1aFrameScale size) fun scale' _ => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by frameMapError1) (fun below => ?_) + refine spec_ite (fun _ => by frameMapError1) (fun above => ?_) + refine spec_ite (fun _ => by frameMapError1) (fun noWrap => ?_) + have lower : fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ va.val := Nat.le_of_not_gt below + have monotone : va.val ≤ (wa va (ws scale' 1#u64)).val := Nat.le_of_not_gt noWrap + have window : (wa va (ws scale' 1#u64)).val < fl4_abi.consts.HIGH_VSPACE_TOP.val := Nat.lt_of_not_ge above + have upper := lt_of_le_of_lt monotone window + have canonVa : CapRt.Canonical va := canon_of_lt (Or.inr (by + rw [P0.Consts.fl4_abi.consts.HIGH_VSPACE_BASE.val_eq] at lower + omega)) + exact vspace.frameMapFinish1 hA h vr os member d canon right canonVa size + (alignment shift size) vaAligned (by decide) remap + (vspace.lookup_pt_slot.highStop root va header path lower upper) 0#u64 a true)) + +set_option maxHeartbeats 3000000 in +/-- Both HighVSpace map branches use the private walk and retain the saved +reference. Errors return the prior state. -/ +theorem vspace.decode_high_page_map.exactEffect (hA : P0.ArchTotal ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (os : OSOK H.tcbs H.omega H.frame OS) + (member : slot ∈ OS) (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s c extra) + (f : vspace.FrameCap) (canon : CapRt.Canonical f.ptr) (right : f.rights.val < 4) + (alignment : ∀ sh, f.size.bits = ok sh → f.ptr.val % 2 ^ sh.val = 0) + (saved : f.asid ≠ 0#u64 → f.is_ept = false) + {x : U64} (live : x ∈ OS) (extraCap : capability.Cap) (rootCap : capA st s x = extraCap) + (a : A) (va vm attr : U64) : + vspace.decode_high_page_map st ar s a slot f extraCap va vm attr ⦃ r => + r.2.1 = s ∨ S1aFrameMap st OS Pt Pp n 2#u64 s r.2.1 slot f ⦄ := by + unfold vspace.decode_high_page_map + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (vspace.check_high_vspace.path h extraCap 1#u64) fun r selected => ?_ + rcases r with ⟨root, asid⟩ | e + swap + · frameMapError1 + have eq := rootCap.trans (selected root asid rfl).1 + have path := (selected root asid rfl).2 + have liveRoot : root ∈ Hr := by rw [h.highRoots]; exact ⟨x, live, true, asid, eq⟩ + have header := h.highHeaders x live root true asid eq + rw [← h.highLink root liveRoot] at path + simp only [irq_branch_ok, bind_ok, lift] + refine WP.spec_bind (vspace.page_shift.exact f.size) fun shift size => ?_ + try simp only [lift, bind_ok] + refine WP.spec_bind (s1aFrameScale size) fun scale scaleEq => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by frameMapError1) (fun notMisaligned => ?_) + have mask : va &&& ws scale 1#u64 = 0#u64 := by + simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using notMisaligned + have vaAligned := s1aFrameVAAligned mask scaleEq + refine spec_ite (fun _ => ?_) (fun zero => ?_) + · refine spec_ite (fun _ => by frameMapError1) (fun changedAsid => ?_) + refine spec_ite (fun _ => by frameMapError1) (fun changedVa => ?_) + have remap : f.asid ≠ 0#u64 → f.is_ept = false ∧ f.asid = asid ∧ f.vaddr = va := by + intro h + exact ⟨saved h, by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using changedAsid, + by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using changedVa⟩ + frameHighBounds + · have remap : f.asid ≠ 0#u64 → f.is_ept = false ∧ f.asid = asid ∧ f.vaddr = va := + fun h => (zero (bne_iff_ne.2 h)).elim + frameHighBounds + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameMapStage2.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapStage2.lean new file mode 100644 index 000000000..f3bf8efd8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapStage2.lean @@ -0,0 +1,134 @@ +/- +P1 (aarch64): exact Stage-2 Frame Map, including a rights-denied clear. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameMapWrite +import Fl4ProofsA64.P1.S1aR2MapStage2 + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Vc Ub Cs U Ac : Set U64} {Lv Re bits : U64 → Nat} + {s q : S} {n tag slot : U64} {c : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} + +set_option hygiene false in +local macro "exactFrameError" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 (Or.inl rfl) + | (simp only [error.invalid_cap, error.invalid_arg, bind_ok] + exact (WP.spec_ok _).2 (Or.inl rfl))) + +set_option hygiene false in +local macro "exactFrameFinish" : tactic => `(tactic| + ( + refine WP.spec_bind (ept.lookup_slot.exactStop root ipa path) fun lu ⟨found, stop⟩ => ?_ + refine spec_ite (fun _ => by exactFrameError) (fun wrongSize => ?_) + have luShift : lu.shift = shift := by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using wrongSize + have atShift : S1aSlotAt st Pp n s 1#u64 asid (s1aCapAddress 1#u64 n ipa) shift.val lu.slot := + luShift ▸ found + have noEdge : 12 < shift.val → L.mem s lu.slot &&& 3#u64 ≠ 3#u64 := luShift ▸ stop + obtain ⟨_, _, _, walk, width, aligned, position, _, _, _⟩ := atShift.entry + have inside : PtW Pt lu.slot := position.symm ▸ h.pathWord walk width aligned + refine WP.spec_bind (P0.vspace.rights_readable.p0 f.rights) fun read _ => ?_ + rw [show layout.paddr f.ptr = ok (ws f.ptr layout.PPTR_BASE) by rfl, bind_ok] + refine WP.spec_bind (ept.make_s2_leaf.exactLeaf vm read attr canon szLow szHigh (alignment shift size)) + fun word effect => ?_ + rw [cur_thread_ok, bind_ok] + let mapped := if word = 0#u64 then .Frame f.ptr f.size f.rights f.is_device false false 0#u64 0#u64 + else capability.Cap.Frame f.ptr f.size f.rights f.is_device true true asid ipa + have enc : CapRt.EncWf mapped := by + dsimp only [mapped] + split + · exact ⟨canon, right, by decide, by + exact Or.inl fun j hj _ => by simp⟩ + · exact ⟨canon, right, idBound, ipaFits⟩ + have frame : ∃ sz r m e id va, mapped = .Frame f.ptr sz r f.is_device m e id va := by + dsimp only [mapped] + split <;> exact ⟨_, _, _, _, _, _, rfl⟩ + refine WP.spec_bind (sched.set_thread_state.frameMapTail2 vr os member d inside hA a + root asid ipa f.ptr attr word f.is_device mapped enc frame) fun r write => ?_ + have finish (q : S × A) (hw : S1aMapWrite st OS Pt s q.1 slot lu.slot word mapped) : + S1aFrameMap st OS Pt Pp n 1#u64 s q.1 slot f := by + refine ⟨asid, ipa, lu.slot, word, shift, size, atShift, normAl, noEdge, remap, ?_, hw⟩ + exact effect.imp (fun zero => ⟨zero, rfl⟩) id + by_cases zero : word = 0#u64 + · have cmp : (word != 0#u64) = false := by simp [zero] + simp only [cmp, Bool.false_eq_true, ↓reduceIte] + have tail := write + simp only [mapped, if_pos zero] at tail + refine WP.spec_bind tail fun m eq => ?_ + refine WP.spec_bind eq ?_ + rintro ⟨q, out⟩ hw + exact (WP.spec_ok _).2 (Or.inr (finish (q, out) (by simpa only [mapped, if_pos zero] using hw))) + · have cmp : (word != 0#u64) = true := bne_iff_ne.2 zero + simp only [cmp, ↓reduceIte] + have tail := write + simp only [mapped, if_neg zero] at tail + refine WP.spec_bind tail fun m eq => ?_ + refine WP.spec_bind eq ?_ + rintro ⟨q, out⟩ hw + exact (WP.spec_ok _).2 (Or.inr (finish (q, out) (by simpa only [mapped, if_neg zero] using hw))))) + +set_option maxHeartbeats 3800000 in +/-- The Stage-2 fresh and remap branches select a leaf slot, retain the exact +cap address and ASID, and report the actual final word and cap. -/ +theorem ept.map_frame.exactEffect (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (os : OSOK H.tcbs H.omega H.frame OS) + (member : slot ∈ OS) (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s c extra) + (f : vspace.FrameCap) (canon : CapRt.Canonical f.ptr) (right : f.rights.val < 4) + (alignment : ∀ sh, f.size.bits = ok sh → f.ptr.val % 2 ^ sh.val = 0) + (saved : f.asid ≠ 0#u64 → f.is_ept = true ∧ f.vaddr.val < 2 ^ 48) + {root asid : U64} (path : S1aPath st Pp hPl.ipa s 1#u64 asid (s1aTopShift 1#u64 hPl.ipa) 0 root) + (a : A) (ipa vm attr : U64) : + ept.map_frame st ar s a root asid ipa vm attr f.ptr f.size f.rights f.is_device f.asid f.vaddr slot ⦃ r => + r.2.1 = s ∨ S1aFrameMap st OS Pt Pp hPl.ipa 1#u64 s r.2.1 slot f ⦄ := by + let n := hPl.ipa + unfold ept.map_frame + refine WP.spec_bind (capability.FrameSize.bits.exact f.size) fun shift size => ?_ + have sizes := s1aFrameShift size + have szLow : 12 ≤ shift.val := by omega + have szHigh : shift.val ≤ 30 := by omega + rw [hPl.ipa_eq a, bind_ok] + try simp only [lift, bind_ok] + refine WP.spec_bind (s1aFrameScale size) fun scale scaleEq => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => by exactFrameError) (fun notMisaligned => ?_) + have mask : ipa &&& ws scale 1#u64 = 0#u64 := by + simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using notMisaligned + have vaAl := s1aFrameVAAligned mask scaleEq + have normAl := s1aFrameNormalized (va := ipa) (tag := 1#u64) (n := n) szHigh vaAl + have idBound := path.asidFits + refine spec_ite (fun nonzero => ?_) (fun zero => ?_) + · refine spec_ite (fun _ => by exactFrameError) (fun changedAsid => ?_) + refine spec_ite (fun _ => by exactFrameError) (fun changedVa => ?_) + have remap : f.asid ≠ 0#u64 → f.is_ept = (1#u64 == 1#u64) ∧ f.asid = asid ∧ f.vaddr = ipa := by + intro h + exact ⟨(saved h).1, by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using changedAsid, + by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using changedVa⟩ + have ipaFits : ipa.val < 2 ^ 48 := by + rw [← (remap (bne_iff_ne.1 nonzero)).2.2] + exact (saved (bne_iff_ne.1 nonzero)).2 + exactFrameFinish + · try simp only [lift, bind_ok] + refine WP.spec_bind (s1aFrameScale size) fun upperScale _ => ?_ + try simp only [lift, bind_ok] + refine WP.spec_bind (ept.ipa_limit.exact n) fun max maxEq => ?_ + refine spec_ite (fun _ => by exactFrameError) (fun lastBound => ?_) + refine spec_ite (fun _ => by exactFrameError) (fun noWrap => ?_) + have remap : f.asid ≠ 0#u64 → f.is_ept = (1#u64 == 1#u64) ∧ f.asid = asid ∧ f.vaddr = ipa := + fun h => (zero (bne_iff_ne.2 h)).elim + have ipaFits : ipa.val < 2 ^ 48 := by + have lo : ipa.val ≤ (wa ipa (ws upperScale 1#u64)).val := Nat.le_of_not_gt noWrap + have hi : (wa ipa (ws upperScale 1#u64)).val ≤ max.val := Nat.le_of_not_gt lastBound + have width : (2 : Nat) ^ s1aIpaWidth n ≤ 2 ^ 48 := + Nat.pow_le_pow_right (by decide) (s1aIpaWidthBounds n).2 + omega + exactFrameFinish + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameMapWrite.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapWrite.lean new file mode 100644 index 000000000..e789489f8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameMapWrite.lean @@ -0,0 +1,149 @@ +/- +P1 (aarch64): capability and leaf effects of the Frame Map tail. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameWord +import Fl4ProofsA64.P1.S1aR2FramePaths +import Fl4ProofsA64.P1.S1aR2MapReference + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "ws" => core.num.U64.wrapping_sub + +section words + +/-- The executable granule shift is the requested frame size. -/ +theorem capability.FrameSize.bits.exact (size : capability.FrameSize) : + size.bits ⦃ sh => size.bits = ok sh ⦄ := by + cases size <;> exact (WP.spec_ok _).2 rfl + +theorem vspace.page_shift.exact (size : capability.FrameSize) : + vspace.page_shift size ⦃ sh => size.bits = ok sh ⦄ := by + unfold vspace.page_shift + exact capability.FrameSize.bits.exact size + +theorem s1aFrameScale {sz : capability.FrameSize} {shift : U64} (size : sz.bits = ok shift) : + (1#u64 <<< (shift &&& 63#u64) : Result U64) ⦃ scale => scale.val = 2 ^ shift.val ⦄ := by + have levels := s1aFrameShift size + have mask : shift &&& 63#u64 = shift := UScalar.eq_of_val_eq (by + rw [UScalar.val_and, show (63#u64 : U64).val = 2 ^ 6 - 1 by rfl, + Nat.and_two_pow_sub_one_eq_mod, Nat.mod_eq_of_lt (by omega : shift.val < 64)]) + rw [mask] + refine WP.spec_mono (U64.ShiftLeft_spec 1#u64 shift (by omega)) fun out eq => ?_ + rw [eq.1, show (1#u64 : U64).val = 1 from rfl, Nat.one_shiftLeft, U64.size_def, U64.numBits] + change 2 ^ shift.val % 2 ^ 64 = 2 ^ shift.val + exact Nat.mod_eq_of_lt (Nat.pow_lt_pow_right (by decide) (by omega)) + +theorem s1aFrameVAAligned {va scale : U64} {level : Nat} + (h : va &&& ws scale 1#u64 = 0#u64) (scaleEq : scale.val = 2 ^ level) : + va.val % 2 ^ level = 0 := by + have positive : 0 < scale.val := by rw [scaleEq]; positivity + have eq := congrArg UScalar.val h + rw [UScalar.val_and, wsub1_le (by omega), scaleEq, Nat.and_two_pow_sub_one_eq_mod] at eq + exact eq + +theorem s1aFrameAligned4K {ptr : U64} {level : Nat} + (aligned : ptr.val % 2 ^ level = 0) (levelBound : 12 ≤ level) : + ptr.val % 4096 = 0 := by + have divides : (2 : Nat) ^ 12 ∣ 2 ^ level := Nat.pow_dvd_pow 2 levelBound + exact Nat.mod_eq_zero_of_dvd (divides.trans (Nat.dvd_of_mod_eq_zero aligned)) + +theorem s1aIpaWidthBounds (n : U64) : 40 ≤ s1aIpaWidth n ∧ s1aIpaWidth n ≤ 48 := by + unfold s1aIpaWidth + split <;> (first | split | skip) <;> omega + +theorem s1aFrameNormalized {va tag n : U64} {level : Nat} (small : level ≤ 30) + (aligned : va.val % 2 ^ level = 0) : s1aCapAddress tag n va % 2 ^ level = 0 := by + unfold s1aCapAddress + split + · have divides : (2 : Nat) ^ level ∣ 2 ^ s1aIpaWidth n := + Nat.pow_dvd_pow 2 (by have := (s1aIpaWidthBounds n).1; omega) + rwa [Nat.mod_mod_of_dvd _ divides] + · exact aligned + +theorem vspace.make_user_page.exactLeaf {p : U64} {level : U64} (vm : U64) (read : Bool) (attr : U64) + (canon : CapRt.Canonical p) (lo : 12 ≤ level.val) (hi : level.val ≤ 30) + (aligned : p.val % 2 ^ level.val = 0) : + vspace.make_user_page (ws p layout.PPTR_BASE) vm read attr level ⦃ word => + s1aLeafValid word level.val ∧ s1aLeafTarget word level.val = p ⦄ := + WP.spec_mono (WP.spec_and (vspace.make_user_page.leafValid _ vm read attr level) + (s1page_desc canon (s1aFrameAligned4K aligned lo) vm read attr level)) fun _ ⟨valid, desc⟩ => + ⟨valid, s1aLeafTarget.ofDescTo desc (by omega) aligned⟩ + +theorem ept.make_s2_leaf.exactLeaf {p : U64} {level : U64} (vm : U64) (read : Bool) (attr : U64) + (canon : CapRt.Canonical p) (lo : 12 ≤ level.val) (hi : level.val ≤ 30) + (aligned : p.val % 2 ^ level.val = 0) : + ept.make_s2_leaf (ws p layout.PPTR_BASE) vm read attr level ⦃ word => + word = 0#u64 ∨ (s1aLeafValid word level.val ∧ s1aLeafTarget word level.val = p) ⦄ := by + refine WP.spec_mono (WP.spec_and (ept.make_s2_leaf.leafValid _ vm read attr level) + (s2leaf_desc canon (s1aFrameAligned4K aligned lo) vm read attr level)) ?_ + rintro word ⟨zero | valid, zero' | desc⟩ + · exact Or.inl zero + · exact Or.inl zero + · exact Or.inl zero' + · exact Or.inr ⟨valid, s1aLeafTarget.ofDescTo desc (by omega) aligned⟩ + +end words + +section stores + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Vc Ub Cs U Ac : Set U64} {s : S} {slot : U64} {source : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +/-- Exact successful Frame Map effect at the active slot and capability. -/ +structure S1aFrameMap (st : machine.Store S) [L : LawfulStore st] + (OS Pt Pp : Set U64) (n tag : U64) (s q : S) (slot : U64) (f : vspace.FrameCap) : Prop where + edit : ∃ asid va addr word shift : U64, + f.size.bits = ok shift ∧ S1aSlotAt st Pp n s tag asid (s1aCapAddress tag n va) shift.val addr ∧ + s1aCapAddress tag n va % 2 ^ shift.val = 0 ∧ + (12 < shift.val → L.mem s addr &&& 3#u64 ≠ 3#u64) ∧ + (f.asid ≠ 0#u64 → f.is_ept = (tag == 1#u64) ∧ f.asid = asid ∧ f.vaddr = va) ∧ + ((word = 0#u64 ∧ tag = 1#u64) ∨ (s1aLeafValid word shift.val ∧ s1aLeafTarget word shift.val = f.ptr)) ∧ + S1aMapWrite st OS Pt s q slot addr word + (if word = 0#u64 then .Frame f.ptr f.size f.rights f.is_device false false 0#u64 0#u64 + else .Frame f.ptr f.size f.rights f.is_device true (tag == 1#u64) asid va) + +theorem sched.set_thread_state.frameMapTail1 + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (os : OSOK H.tcbs H.omega H.frame OS) + (member : slot ∈ OS) (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s source extra) + {lu : vspace.PtSlot} (inside : PtW Pt lu.slot) (hA : P0.ArchTotal ar) (a : A) + (f : vspace.FrameCap) (root asid va attr word : U64) (high : Bool) + (encoded : CapRt.EncWf (.Frame f.ptr f.size f.rights f.is_device true false asid va)) : + let mapped := capability.Cap.Frame f.ptr f.size f.rights f.is_device true false asid va + sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ r => + obj.Slot.set_cap st slot r mapped ⦃ m => + vspace.install_page st ar m a lu word root asid va f attr high ⦃ q => + S1aMapWrite st OS Pt s q.1 slot lu.slot word mapped ⦄ ⦄ ⦄ := by + dsimp only + have rt := CapRt.rt_Frame f.ptr f.size f.rights f.is_device true false asid va encoded + refine WP.spec_mono (sched.set_thread_state.mapCap vr os member d) fun r restart => ?_ + refine WP.spec_mono (restart _ _ rt) fun m ⟨base, mem, cap, others⟩ => ?_ + refine WP.spec_mono (vspace.install_page.slotE hA (vr.al _ (Or.inl inside)) m a word root asid va f attr high) + fun q ⟨writes, stored⟩ => ?_ + exact S1aMapWrite.ofTail vr os member base mem cap others inside writes stored + +theorem sched.set_thread_state.frameMapTail2 + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (os : OSOK H.tcbs H.omega H.frame OS) + (member : slot ∈ OS) (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s source extra) + {lu : ept.S2Slot} (inside : PtW Pt lu.slot) (hA : P0.ArchTotal ar) (a : A) + (root asid ipa ptr attr word : U64) (dev : Bool) (mapped : capability.Cap) (encoded : CapRt.EncWf mapped) + (isFrame : ∃ sz r m e id va, mapped = .Frame ptr sz r dev m e id va) : + sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ r => + obj.Slot.set_cap st slot r mapped ⦃ m => + ept.install_s2_leaf st ar m a lu word root asid ipa ptr dev attr ⦃ q => + S1aMapWrite st OS Pt s q.1 slot lu.slot word mapped ⦄ ⦄ ⦄ := by + obtain ⟨sz, r, m, e, id, va, rfl⟩ := isFrame + have rt := CapRt.rt_Frame ptr sz r dev m e id va encoded + refine WP.spec_mono (sched.set_thread_state.mapCap vr os member d) fun r restart => ?_ + refine WP.spec_mono (restart _ _ rt) fun m ⟨base, mem, cap, others⟩ => ?_ + refine WP.spec_mono (ept.install_s2_leaf.exactWord hA (vr.al _ (Or.inl inside)) m a word root asid ipa ptr dev attr) + fun q ⟨writes, stored⟩ => ?_ + exact S1aMapWrite.ofTail vr os member base mem cap others inside writes stored + +end stores + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FramePaths.lean b/proofs/Fl4ProofsA64/P1/S1aR2FramePaths.lean new file mode 100644 index 000000000..a4691b892 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FramePaths.lean @@ -0,0 +1,86 @@ +/- +P1 (aarch64): active table paths across a single frame-descriptor write. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapPlacement + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {slot addr word tag asid : U64} {level va : Nat} {cap : capability.Cap} + +/-- A leaf or a zero cannot serve as a table edge above the last level. -/ +theorem s1aLeafNotTable {word : U64} {level : Nat} + (leaf : word = 0#u64 ∨ s1aLeafValid word level) + (above : 12 < level) : (word &&& 3#u64) ≠ 3#u64 := by + rcases leaf with rfl | (⟨page, _⟩ | ⟨_, block⟩) + · decide + · omega + · rw [block] + decide + +set_option maxHeartbeats 2900000 in +/-- At its exact termination slot a frame write changes no active table edge. -/ +theorem S1aMapWrite.framePaths + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (selected : S1aSlotAt st Pp n s tag asid va level addr) + (oldStop : 12 < level → (L.mem s addr &&& 3#u64) ≠ 3#u64) + (leaf : word = 0#u64 ∨ s1aLeafValid word level) + (write : S1aMapWrite st OS Pt s q slot addr word cap) : + ∀ k a sh b p, S1aPath st Pp n q k a sh b p ↔ S1aPath st Pp n s k a sh b p := by + have active (a raw : U64) := write.activeAsid h heap kinds ptKs selected (a := a) (raw := raw) + have high (a raw : U64) (e : ActiveAsidRoot st Pp s a raw) (k : raw &&& 3#u64 = 2#u64) : + L.mem q (wa (raw &&& ~~~3#u64) 4088#u64) = L.mem s (wa (raw &&& ~~~3#u64) 4088#u64) := by + obtain ⟨x, hx, cap⟩ := h.core.root.backed a raw e + rw [k] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + have live : raw &&& ~~~3#u64 ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, a, cap⟩ + exact write.highHeader h heap kinds selected live 4088#u64 (by decide) (by decide) + intro k a sh b p + have equalLevel {k a t o : U64} {ℓ start : Nat} (prior : S1aPath st Pp n s k a ℓ start t) + (width : o.val < s1aTableWidth k n ℓ) (eq : wa t o = addr) : ℓ = level := by + obtain ⟨_, _, _, walk, chosenWidth, _, position, _, _, _⟩ := selected.entry + exact (h.samePathWord heap kinds prior walk width chosenWidth (eq.trans position)).2.2.1 + constructor + · intro path + induction path with + | native e tag => exact .native ((active _ _).1 e) tag + | stage2 e tag => exact .stage2 ((active _ _).1 e) tag + | high e tag valid => + have old := (active _ _).1 e + rw [high _ _ old tag] at valid ⊢ + exact .high old tag valid + | @child k a p o sh b _ depth width al range valid ih => + have different : wa p o ≠ addr := by + intro eq + have editLevel := equalLevel ih width eq + rw [eq, write.descriptor] at valid + exact s1aLeafNotTable leaf (editLevel ▸ depth) valid + rw [write.memory _ (Or.inl (h.pathWord ih width al)) different] at valid ⊢ + exact .child ih depth width al range valid + · intro path + induction path with + | native e tag => exact .native ((active _ _).2 e) tag + | stage2 e tag => exact .stage2 ((active _ _).2 e) tag + | high e tag valid => + rw [← high _ _ e tag] at valid ⊢ + exact .high ((active _ _).2 e) tag valid + | @child k a p o sh b prior depth width al range valid ih => + have different : wa p o ≠ addr := by + intro eq + have editLevel := equalLevel prior width eq + rw [eq] at valid + exact oldStop (editLevel ▸ depth) valid + rw [← write.memory _ (Or.inl (h.pathWord prior width al)) different] at valid ⊢ + exact .child ih depth width al range valid + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameRaw.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameRaw.lean new file mode 100644 index 000000000..fdcd3ed61 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameRaw.lean @@ -0,0 +1,119 @@ +/- +P1 (aarch64): raw reachability and typing after an exact frame-descriptor write. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FramePaths +import Fl4ProofsA64.P1.S1aR2MapReach + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {slot addr word tag asid : U64} {level va : Nat} {cap : capability.Cap} + +set_option maxHeartbeats 2300000 in +/-- An exact frame write leaves the narrowed Stage-1 typing valid on the +same tables and permits no new raw reachable table. -/ +theorem S1aMapWrite.frameRawStage1 + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (atSlot : S1aSlotAt st Pp n s tag asid va level addr) + (leaf : word = 0#u64 ∨ s1aLeafValid word level) + (write : S1aMapWrite st OS Pt s q slot addr word cap) : + VsTyR st (L.ksb q) (PoolSet st Pp q) ∅ Tb Lv q ∧ + ∀ p, VsReach st (PoolSet st Pp q) ∅ Lv q p → VsReach st (PoolSet st Pp s) ∅ Lv s p := by + obtain ⟨tab, pools⟩ := write.keepAsid h heap kinds ptKs atSlot + have edge {p o : U64} (prior : VsReach st (PoolSet st Pp s) ∅ Lv s p) (depth : Lv p < 3) + (width : o.val < 4096) (al : o.val % 8 = 0) + (valid : L.mem q (wa p o) &&& 3#u64 = 3#u64) : L.mem q (wa p o) = L.mem s (wa p o) := by + have different : wa p o ≠ addr := by + intro eq + have levelEq := (h.mapStage1Source heap kinds atSlot prior width eq).2 + rw [eq, write.descriptor] at valid + exact s1aLeafNotTable leaf (by omega) valid + have placed := h.core.stage1.reachableMember prior + exact write.memory _ (Or.inl ⟨p, h.place.tables placed, o, width, al, rfl⟩) different + have back : ∀ p, VsReach st (PoolSet st Pp q) ∅ Lv q p → VsReach st (PoolSet st Pp s) ∅ Lv s p := by + rw [tab.poolSet_eq] + intro p reached + induction reached with + | hr live => exact live.elim + | root0 live bound al nz tagged => + rw [pools _ live _ bound al] at nz tagged ⊢ + exact .root0 live bound al nz tagged + | root2 live bound al tagged => + rw [pools _ live _ bound al] at tagged ⊢ + exact .root2 live bound al tagged + | step _ depth width al tagged prior => + have kept := edge prior depth width al tagged + rw [kept] at tagged ⊢ + exact .step prior depth width al tagged + refine ⟨⟨?_, ?_, ?_⟩, back⟩ + · intro o lo hi al nz + rw [tab.off lo hi al] at nz ⊢ + rw [tab.poolSet_eq] + exact h.core.stage1.tbl o lo hi al nz + · intro p hp o bound al nz + have old : p ∈ PoolSet st Pp s := tab.poolSet_eq ▸ hp + rw [pools p old o bound al] at nz ⊢ + exact h.core.stage1.pool p old o bound al nz + · intro p hp reached depth o bound al tagged + have prior := back p reached + have kept := edge prior depth bound al tagged + rw [kept] at tagged ⊢ + exact h.core.stage1.desc p hp prior depth o bound al tagged + +set_option maxHeartbeats 2300000 in +/-- An exact frame write leaves Stage-2 table layout and typing valid and +permits no new raw reachable table. -/ +theorem S1aMapWrite.frameRawStage2 + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (atSlot : S1aSlotAt st Pp n s tag asid va level addr) + (leaf : word = 0#u64 ∨ s1aLeafValid word level) + (write : S1aMapWrite st OS Pt s q slot addr word cap) : + S2TyR st n (PoolSet st Pp q) Hr Te Re bits q ∧ + ∀ p, S2Reach st (PoolSet st Pp q) Re bits q p → S2Reach st (PoolSet st Pp s) Re bits s p := by + obtain ⟨tab, pools⟩ := write.keepAsid h heap kinds ptKs atSlot + have edge {p o : U64} (prior : S2Reach st (PoolSet st Pp s) Re bits s p) (depth : 0 < Re p) + (width : o.val < 2 ^ bits p) (al : o.val % 8 = 0) + (valid : L.mem q (wa p o) &&& 3#u64 = 3#u64) : L.mem q (wa p o) = L.mem s (wa p o) := by + have different : wa p o ≠ addr := by + intro eq + have levelEq := (h.mapStage2Source heap kinds atSlot prior width eq).2 + rw [eq, write.descriptor] at valid + exact s1aLeafNotTable leaf (by omega) valid + have placed := h.core.stage2.reachableMember prior + have loc := ptw_mono h.place.granules (ptwb_gran h.place.stage2.sz ⟨p, placed, o, width, al, rfl⟩) + exact write.memory _ (Or.inl loc) different + have back : ∀ p, S2Reach st (PoolSet st Pp q) Re bits q p → S2Reach st (PoolSet st Pp s) Re bits s p := by + rw [tab.poolSet_eq] + intro p reached + induction reached with + | root live bound al tagged => + rw [pools _ live _ bound al] at tagged ⊢ + exact .root live bound al tagged + | step _ depth width al tagged prior => + have kept := edge prior depth width al tagged + rw [kept] at tagged ⊢ + exact .step prior depth width al tagged + refine ⟨⟨?_, ?_, ?_⟩, back⟩ + · intro p hp o bound al nz + have old : p ∈ PoolSet st Pp s := tab.poolSet_eq ▸ hp + rw [pools p old o bound al] at nz ⊢ + exact h.core.stage2.tag p old o bound al nz + · intro root live + rw [write.highHeader h heap kinds atSlot live 4088#u64 (by decide) (by decide)] + exact h.core.stage2.hi root live + · intro p hp reached depth o bound al tagged + have prior := back p reached + have kept := edge prior depth bound al tagged + rw [kept] at tagged ⊢ + exact h.core.stage2.desc p hp prior depth o bound al tagged + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameRemove.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameRemove.lean new file mode 100644 index 000000000..28e4a7014 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameRemove.lean @@ -0,0 +1,228 @@ +/- +P1 (aarch64): frame removal clears the leaves witnessed by the saved cap. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameClear +import Fl4ProofsA64.P1.S1aR2FrameMapPost + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {s q : S} {n : U64} {f : vspace.FrameCap} + {A : Type _} {ar : machine.Arch A} + +/-- Every active leaf identified by this cap's mapped fields has been cleared. -/ +def S1aFrameCleared (st : machine.Store S) [L : LawfulStore st] (Pp : Set U64) + (n : U64) (s q : S) (f : vspace.FrameCap) : Prop := + ∀ tag shift addr : U64, f.mapped = true → f.is_ept = (tag == 1#u64) → + f.size.bits = ok shift → + S1aSlotAt st Pp n s tag f.asid (s1aCapAddress tag n f.vaddr) shift.val addr → + s1aLeafValid (L.mem s addr) shift.val → + s1aLeafTarget (L.mem s addr) shift.val = f.ptr → L.mem q addr = 0#u64 + +private theorem S1aPath.frameStage {tag asid t : U64} {sh base : Nat} + (path : S1aPath st Pp n s tag asid sh base t) : tag = 0#u64 ∨ tag = 2#u64 ∨ tag = 1#u64 := by + induction path with + | native => exact Or.inl rfl + | high => exact Or.inr (Or.inl rfl) + | stage2 => exact Or.inr (Or.inr rfl) + | child _ _ _ _ _ _ ih => exact ih + +private theorem S1aSlotAt.frameStage {tag asid addr : U64} {address sh : Nat} + (slot : S1aSlotAt st Pp n s tag asid address sh addr) : tag = 0#u64 ∨ tag = 2#u64 ∨ tag = 1#u64 := by + obtain ⟨_, _, _, path, _⟩ := slot.entry + exact path.frameStage + +private theorem S1aR2.alignedSlot (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (aligned : ∀ b, PtW Pt b → Aligned b) {tag asid addr : U64} {address sh : Nat} + (slot : S1aSlotAt st Pp n s tag asid address sh addr) : Aligned addr := by + obtain ⟨_, _, _, path, width, al, rfl, _⟩ := slot.entry + exact aligned _ (h.pathWord path width al) + +private theorem S1aR2.noFrameLeaf (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (absent : f.mapped ≠ true ∨ f.asid = 0#u64) : S1aFrameCleared st Pp n s s f := by + intro tag shift addr mapped _ _ slot _ _ + rcases absent with unmapped | zero + · exact (unmapped mapped).elim + · obtain ⟨_, _, _, path, _⟩ := slot.entry + obtain ⟨raw, root, _⟩ := path.rootEntry + rw [zero] at root + exact (h.poolCaps.noZero raw root).elim + +private theorem vspace.unmap_page.clearsFrame (hA : P0.ArchTotal ar) (a : A) (stage : f.is_ept = false) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (aligned : ∀ b, PtW Pt b → Aligned b) : + vspace.unmap_page st ar s a f.size f.asid f.vaddr f.ptr ⦃ r => S1aFrameCleared st Pp n s r.1 f ⦄ := by + obtain ⟨r, result⟩ := DPF.spec_tot + (P0.vspace.unmap_page.p0 st ar s a f.size f.asid f.vaddr f.ptr L.total hA) + rw [result, WP.spec_ok] + intro tag shift addr _ rootKind size slot valid target + have nonEpt : tag ≠ 1#u64 := by + rintro rfl + rw [stage] at rootKind + simp at rootKind + have kind : tag = 0#u64 ∨ tag = 2#u64 := + slot.frameStage.imp_right (fun e => e.resolve_right nonEpt) + rw [s1aCapAddress, ite_eq_right nonEpt] at slot + have clear := vspace.unmap_page.clearsActiveLeaf hA a h kind slot size valid target (h.alignedSlot aligned slot) + rwa [result, WP.spec_ok] at clear + +private theorem ept.unmap.clearsFrame (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (a : A) + (stage : f.is_ept = true) {sh : U64} (size : f.size.bits = ok sh) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (aligned : ∀ b, PtW Pt b → Aligned b) : + ept.unmap st ar s a f.asid f.vaddr f.ptr sh false ⦃ r => S1aFrameCleared st Pp hPl.ipa s r.1 f ⦄ := by + obtain ⟨r, result⟩ := DPF.spec_tot + (P0.ept.unmap.p0 st ar s a f.asid f.vaddr f.ptr sh false L.total hA) + rw [result, WP.spec_ok] + intro tag shift addr _ rootKind size' slot valid target + rw [stage] at rootKind + have kind : tag = 1#u64 := by simpa using rootKind.symm + subst tag + have eq := okinj (size'.symm.trans size) + subst shift + have clear := ept.unmap.clearsActiveLeaf hA hPl a slot size valid target (h.alignedSlot aligned slot) + rwa [result, WP.spec_ok] at clear + +private theorem vspace.unmap_page.frameFootprint (hA : P0.ArchTotal ar) (a : A) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + vspace.unmap_page st ar s a f.size f.asid f.vaddr f.ptr ⦃ r => Wr0 st (TbO Tb Hr) s r.1 ⦄ := by + let tables := VsRt st (PoolSet st Pp s) ∅ Tb Lv s + have place : HrOK (L.ksb s) (PoolSet st Pp s) tables Lv (Hr ∩ tables) := + ⟨fun _ hp => hp.2, fun p hp => h.place.high.lv p hp.1, + fun t ht o ho al r hr => h.place.high.tb t ht.1 o ho al r hr.1, + fun p hp o ho al r hr => h.place.high.pp p hp o ho al r hr.1, + fun r hr => h.place.high.asw r hr.1⟩ + exact WP.spec_mono (vspace.unmap_page.hr hA place h.core.stage1.sub rfl a f.size f.asid f.vaddr f.ptr) + fun _ writes => writes.mono (show TbO tables (Hr ∩ tables) ⊆ TbO Tb Hr from + fun _ ht => ⟨ht.1.1, fun hr => ht.2 ⟨hr, ht.1⟩⟩) + +theorem s1aFrameRemove (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (a : A) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (aligned : ∀ b, PtW Pt b → Aligned b) : + (if f.mapped then + if f.asid != 0#u64 then + if f.is_ept then do + let sh ← f.size.bits + ept.unmap st ar s a f.asid f.vaddr f.ptr sh false + else vspace.unmap_page st ar s a f.size f.asid f.vaddr f.ptr + else ok (s, a) + else ok (s, a)) ⦃ r => Wr0 st (TbO Tb Hr ∪ Gran Te bits) s r.1 ∧ + S1aFrameCleared st Pp hPl.ipa s r.1 f ⦄ := by + refine spec_ite (fun _ => ?_) (fun unmapped => (WP.spec_ok _).2 ⟨Wr0.refl _, h.noFrameLeaf (Or.inl unmapped)⟩) + refine spec_ite (fun _ => ?_) (fun zero => ?_) + · refine spec_ite (fun stage => ?_) (fun stage => ?_) + · refine WP.spec_bind (vspace.page_shift.exact f.size) fun sh size => ?_ + refine WP.spec_and ?_ (ept.unmap.clearsFrame hA hPl a stage size h aligned) + exact WP.spec_mono (ept.unmap.z hA hPl h.core.stage1.sub h.core.stage2.sub + (S2OK.sub h.place.stage2 S2Rt_sub) rfl a f.asid f.vaddr f.ptr sh false) + fun _ writes => writes.mono ((gran_mono S2Rt_sub).trans Set.subset_union_right) + · refine WP.spec_and ?_ (vspace.unmap_page.clearsFrame hA a (Bool.eq_false_of_not_eq_true stage) h aligned) + exact WP.spec_mono (vspace.unmap_page.frameFootprint (f := f) hA a h) + fun _ writes => writes.mono Set.subset_union_left + · have z : f.asid = 0#u64 := by simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using zero + exact (WP.spec_ok _).2 ⟨Wr0.refl _, h.noFrameLeaf (Or.inr z)⟩ + +/-- The memory and capability effects of a frame unmap, measured after caller restart. -/ +structure S1aFrameUnmap (st : machine.Store S) [L : LawfulStore st] + (OS Pt Pp Hr : Set U64) (n : U64) (s q : S) (slot : U64) (f : vspace.FrameCap) : Prop where + table : TabKeep st s q + memory : VsZ st (L.ksb s) Pt s q + headers : HrW st Hr s q + clear : S1aFrameCleared st Pp n s q f + cap : capA st q slot = .Frame f.ptr f.size f.rights f.is_device false false 0#u64 0#u64 + other : ∀ x ∈ OS, x ≠ slot → capA st q x = capA st s x + +theorem obj.Slot.set_cap.frameUnmapTail {Vc Ub : Set U64} {slot : U64} {mid : S} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (os : OSOK H.tcbs H.omega H.frame OS) (member : slot ∈ OS) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (zero : Wr0 st (TbO Tb Hr ∪ Gran Te bits) s mid) (clear : S1aFrameCleared st Pp n s mid f) : + obj.Slot.set_cap st slot mid (.Frame f.ptr f.size f.rights f.is_device false false 0#u64 0#u64) ⦃ q => + S1aFrameUnmap st OS Pt Pp Hr n s q slot f ⦄ := by + have sub : TbO Tb Hr ∪ Gran Te bits ⊆ Pt := + Set.union_subset (tbo_sub.trans h.place.tables) h.place.granules + have aligned b (hb : PtW Pt b) := vr.al b (Or.inl hb) + have writes := (zero.mono sub).w aligned + have keep := TabKeep.ofW vr writes ptKs + have hiWord R (hR : R ∈ Hr) : PtW Pt (wa R 4088#u64) := + ⟨R, h.place.tables (h.place.high.sub hR), 4088#u64, by decide, by decide, rfl⟩ + have headers := zero.hrw (fun b hb => aligned b (ptw_mono sub hb)) + (fun R hR => aligned _ (hiWord R hR)) (fun _ hb => s2_ne h.place.high h.place.stage2 hb) + have inMid : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb mid) Pt := by + rw [keep.1]; exact vr + have wf : CapRt.EncWf (capA st s slot) := CapRt.decodeF_encWf _ _ + rw [old] at wf + have wf' : CapRt.EncWf (.Frame f.ptr f.size f.rights f.is_device false false 0#u64 0#u64) := by + cases stage : f.is_ept <;> simp only [stage, CapRt.EncWf] at wf <;> + exact ⟨wf.1, wf.2.1, by simp, canon0⟩ + refine WP.spec_mono (obj.Slot.set_cap.exactMap inMid os member (CapRt.rt_Frame _ _ _ _ _ _ _ _ wf')) + fun q ⟨base, words, cap, other⟩ => ?_ + have tail : TabKeep st mid q := ⟨base, fun i => by rw [base]; exact words _ (Or.inr (asW_at _ i))⟩ + rw [keep.1] at words + have z := (zero.mono sub).vsz (kb := L.ksb s) vr.al + refine ⟨keep.trans tail, z.trans (fun b hb => Or.inl (words b hb)), ?_, ?_, cap, ?_⟩ + · exact fun R hR => (words _ (Or.inl (hiWord R hR))).trans (headers R hR) + · intro tag sh addr mapped stage size slot leaf target + have loc : PtW Pt addr := by + obtain ⟨_, _, _, path, width, al, rfl, _⟩ := slot.entry + exact h.pathWord path width al + exact (words addr (Or.inl loc)).trans (clear tag sh addr mapped stage size slot leaf target) + · intro x hx ne + have preserves := capk_vsr vr os (writes.mono fun _ hb => Or.inl hb) x hx + rw [capA_eq, capA_eq] at preserves + exact (other x hx ne).trans (okinj preserves) + +set_option maxHeartbeats 3400000 in +/-- Concrete ARMPageUnmap clears any active leaf backed by the invoked +capability and resets that capability in place. -/ +theorem vspace.decode_frame.unmapExactEffect + {Cs Vc Ub U Ac : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} {slot : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (f : vspace.FrameCap) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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 f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) extra) + (member : slot ∈ OS) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) (a : A) (len buf : U64) (call : Bool) : + vspace.decode_frame st ar s a fl4_abi.label.ARMPageUnmap len slot + (.Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) call buf extra ⦃ r => + ∃ start, S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa start ∧ + S1aFrameUnmap st OS Pt Pp Hr hPl.ipa start r.2.1 slot f ∧ + capA st start slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr ∧ + (∀ x ∈ OS, capA st start x = capA st s x) ∧ L.ksb start = L.ksb s ⦄ := by + unfold vspace.decode_frame + simp only [vspace.as_frame, bind_ok, cur_thread_ok] + have ne : fl4_abi.label.ARMPageUnmap ≠ fl4_abi.label.ARMPageMap := + lbl_ne_of_val (by simp [fl4_abi.label.ARMPageMap, fl4_abi.label.ARMPageUnmap]) + try dsimp only + rw [if_neg ne] + simp only [ite_true] + have restart := WP.spec_and (sched.set_thread_state.restartR2 h.core place I D) + (sched.set_thread_state.unmMid I D) + refine WP.spec_bind restart fun start ⟨core, mid, keep⟩ => ?_ + have caps : ∀ x ∈ OS, capA st start x = capA st s x := fun _ hx => mid.k.capA hx + have before := h.keep core mid.tz.1 keep caps + have vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb start) Pt := by + rw [mid.tz.1]; exact I.del.vr + have old' := (caps slot member).trans old + have unchanged b (hb : PtW Pt b) : ¬ AsW (L.ksb start) b := by rw [mid.tz.1]; exact ptKs b hb + refine WP.spec_bind (s1aFrameRemove (f := f) hA hPl a before (fun b hb => vr.al b (Or.inl hb))) ?_ + rintro ⟨out, arch⟩ ⟨zero, clear⟩ + simp only [uncurry_apply_pair, vspace.unmapped_frame, bind_ok] + refine WP.spec_bind (obj.Slot.set_cap.frameUnmapTail before vr I.del.os member old' unchanged zero clear) + fun q effect => ?_ + exact (WP.spec_ok _).2 ⟨start, before, effect, old', caps, mid.tz.1⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapPost.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapPost.lean new file mode 100644 index 000000000..a9705e7f9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapPost.lean @@ -0,0 +1,238 @@ +/- +P1 (aarch64): full R2 through the exact Frame Unmap syscall. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameRemove + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {s q : S} {n slot : U64} {f : vspace.FrameCap} + +private theorem S1aFrameUnmap.tableCap + (effect : S1aFrameUnmap st OS Pt Pp Hr n s q slot f) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + {x : U64} (hx : x ∈ OS) {c : capability.Cap} (type : R2TableCap c) : + capA st q x = c ↔ capA st s x = c := by + by_cases same : x = slot + · subst x + rw [effect.cap, old] + constructor <;> intro eq <;> rw [← eq] at type <;> exact type.elim + · rw [effect.other x hx same] + +private theorem S1aFrameUnmap.nonFrame + (effect : S1aFrameUnmap st OS Pt Pp Hr n s q slot f) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + {x : U64} (hx : x ∈ OS) {c : capability.Cap} + (kind : ∀ m e a v, c ≠ .Frame f.ptr f.size f.rights f.is_device m e a v) : + capA st q x = c ↔ capA st s x = c := by + by_cases same : x = slot + · subst x + rw [effect.cap, old] + exact ⟨fun eq => (kind _ _ _ _ eq.symm).elim, fun eq => (kind _ _ _ _ eq.symm).elim⟩ + · rw [effect.other x hx same] + +private theorem S1aFrameUnmap.poolWord + (effect : S1aFrameUnmap st OS Pt Pp Hr n s q slot f) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (p : U64) (live : p ∈ PoolSet st Pp s) (o : U64) (bound : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) ∨ L.mem q (wa p o) = 0#u64 := + effect.memory _ (Or.inl ⟨p, h.place.pools live, o, bound, al, rfl⟩) + +private theorem S1aFrameUnmap.pathBack + (effect : S1aFrameUnmap st OS Pt Pp Hr n s q slot f) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {tag a p : U64} {sh base : Nat} (path : S1aPath st Pp n q tag a sh base p) : + S1aPath st Pp n s tag a sh base p := by + refine path.back (fun _ _ e => e.back effect.table.toDel (effect.poolWord h)) ?_ + (fun _ _ _ _ _ before _ width al => effect.memory _ (Or.inl (h.pathWord before width al))) + intro a raw entry kind + obtain ⟨x, hx, cap⟩ := h.core.root.backed a raw entry + rw [kind] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + exact effect.headers _ (by rw [h.highRoots]; exact ⟨x, hx, true, a, cap⟩) + +private theorem S1aFrameUnmap.backing + (effect : S1aFrameUnmap st OS Pt Pp Hr n s q slot f) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) : + S1aPathBacking st H OS Pp Tb Te Lv Re bits n q := by + refine ⟨fun k a sh b p path => h.paths.tables k a sh b p (effect.pathBack h path), ?_, ?_⟩ + · intro k a sh b p path child + obtain ⟨x, hx, saved, cap, ref⟩ := h.paths.children k a sh b p (effect.pathBack h path) child + exact ⟨x, hx, saved, (effect.tableCap old hx (c := .PageTable p true a saved) trivial).2 cap, ref⟩ + · intro k a sh b p path o bound al window valid + have prior := effect.pathBack h path + have nz : L.mem q (wa p o) ≠ 0#u64 := by + intro z + rw [z] at valid + rcases valid with ⟨_, bad⟩ | ⟨_, bad⟩ <;> cases bad + have word := (effect.memory _ (Or.inl (h.pathWord prior bound al))).resolve_right nz + rw [word] at valid ⊢ + obtain ⟨x, hx, sz, rights, dev, va, size, cap, ref, object⟩ := h.paths.leaves k a sh b p prior o bound al window valid + have survives : x ≠ slot := by + rintro rfl + rw [old] at cap + injection cap with target sameSize _ _ mapped stage asid saved + let shift : U64 := ⟨BitVec.ofNat 64 sh⟩ + have shiftVal : shift.val = sh := by + have levels := prior.geometry.1 + change sh % 2 ^ 64 = sh + exact Nat.mod_eq_of_lt (by rcases levels with h | h | h | h <;> omega) + have selected : S1aSlotAt st Pp n s k f.asid (s1aCapAddress k n f.vaddr) shift.val (wa p o) := by + rw [shiftVal, asid, saved] + refine ⟨p, b, o, prior, bound, al, rfl, Nat.mod_eq_zero_of_dvd prior.baseAligned, ?_, ?_, window⟩ + · rw [ref] + · rw [ref] + exact Nat.lt_add_of_pos_right (by positivity) + apply nz (effect.clear k shift _ mapped stage (sameSize.symm ▸ size) selected + (shiftVal.symm ▸ valid) (shiftVal.symm ▸ target.symm)) + exact ⟨x, hx, sz, rights, dev, va, size, (effect.other x hx survives).trans cap, ref, object⟩ + +set_option maxHeartbeats 3800000 in +/-- Frame Unmap preserves full R2 on the same heap, slots, footprint and table witnesses. -/ +theorem S1aR2.ofFrameUnmap + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (heap : HeapOK H) (kinds : KindA st OS s) + (old : capA st s slot = .Frame f.ptr f.size f.rights f.is_device f.mapped f.is_ept f.asid f.vaddr) + (effect : S1aFrameUnmap st OS Pt Pp Hr n s q slot f) : + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := by + have same x (hx : x ∈ OS) c (hc : R2TableCap c) := effect.tableCap old hx hc + have image : R2CapImage st OS s q := by + intro c hc + constructor <;> rintro ⟨x, hx, cap⟩ + · exact ⟨x, hx, (same x hx c hc).1 cap⟩ + · exact ⟨x, hx, (same x hx c hc).2 cap⟩ + have ty1 := h.core.stage1.activeZero place.pools h.place.tables effect.table.toDel effect.memory + have ty2 := h.core.stage2.activeZero place.pools h.place.granules h.place.stage2 + effect.table.toDel effect.memory effect.headers + have root := h.core.root.keepImage effect.table.toDel image (effect.poolWord h) + have reach1 p (r : VsReach st (PoolSet st Pp q) ∅ Lv q p) := + r.activeZero h.core.stage1 place.pools h.place.tables effect.table.toDel effect.memory + have reach2 p (r : S2Reach st (PoolSet st Pp q) Re bits q p) := + r.activeZero h.core.stage2 place.pools h.place.granules h.place.stage2 effect.table.toDel effect.memory + have unmapped := h.eptRoots.unmZ h.core heap h.pageTables + have lookup := h.core.lookup.keepImageOfReach image reach1 reach2 (fun x hx _ _ c _ bound al => by + obtain ⟨word, _, zero⟩ := unmapped.words (kb := L.ksb s) hx c.toSlot bound al + exact (effect.memory _ word).elim id (·.trans zero.symm)) + have highSet : Hr = HvRt st OS q := by + rw [h.highRoots] + ext p + constructor <;> rintro ⟨x, hx, m, a, cap⟩ + · exact ⟨x, hx, m, a, (same x hx (.HighVSpace p m a) trivial).2 cap⟩ + · exact ⟨x, hx, m, a, (same x hx (.HighVSpace p m a) trivial).1 cap⟩ + have memory b (hb : PtW Pt b) := effect.memory b (Or.inl hb) + have tableSame x (hx : x ∈ OS) k (key : s1aTableKey (capA st q x) = some k) : + capA st q x = capA st s x := by + apply effect.other x hx + rintro rfl + rw [effect.cap] at key + cases key + have refs : S1aTableCaps st OS q := by + constructor + · intro x hx y hy k xKey yKey + have xEq := tableSame x hx k xKey + have yEq := tableSame y hy k yKey + rw [xEq, yEq] + exact h.capRefs.references x hx y hy k (xEq ▸ xKey) (yEq ▸ yKey) + · intro x hx y hy k xKey yKey none + have xEq := tableSame x hx k xKey + have yEq := tableSame y hy k yKey + exact h.capRefs.unique x hx y hy k (xEq ▸ xKey) (yEq ▸ yKey) (xEq ▸ none) + · intro x hx p a eq o ho al + have before := (same x hx (.Pml4 p false a) trivial).1 eq + exact (memory _ ⟨p, (h.nativeRoots x hx p false a before).2, o, ho, al, rfl⟩).elim + (·.trans (h.capRefs.nativeEmpty x hx p a before o ho al)) id + · intro x hx p a eq o ho al + have before := (same x hx (.HighVSpace p false a) trivial).1 eq + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, false, a, before⟩ + exact (memory _ ⟨_, h.highFootprint ⟨p, live, Or.inr ⟨rfl, rfl⟩⟩, o, ho, al, rfl⟩).elim + (·.trans (h.capRefs.highEmpty x hx p a before o ho al)) id + have closed t (ht : t ∈ Kt) (depth : Lv t < 3) (o : U64) (bound : o.val < 4096) (al : o.val % 8 = 0) + (valid : L.mem q (wa t o) &&& 3#u64 = 3#u64) : + wa (L.mem q (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + rcases memory _ ⟨t, h.place.tables (h.kernelTables.1 ht), o, bound, al, rfl⟩ with eq | empty + · rw [eq] at valid ⊢ + exact h.kernelClosed t ht depth o bound al valid + · rw [empty] at valid + cases valid + have kindPost : KindA st OS q := by + apply kinds.keep + intro x hx + by_cases eq : x = slot + · rw [eq, old, effect.cap] + simp only [RngKeyA, isFrA, Bool.true_eq_false, and_false, iff_self, false_implies, and_self] + · rw [effect.other x hx eq] + exact ⟨Iff.rfl, fun _ => ⟨rfl, rfl⟩⟩ + have routes : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q := + ⟨lookup, root, h.core.heap, effect.backing h old, refs, h.rootSlotsOfZero (fun x hx => image.back hx) memory, + highSet, (fun p hp => by rw [effect.headers p hp]; exact h.highLink p hp), + (fun x hx p m a c => h.highObjects x hx p m a ((same x hx (.HighVSpace p m a) trivial).1 c)), + (fun x hx p l m a v c => h.eptRoots x hx p l m a v ((same x hx (.Ept p l m a v) trivial).1 c)), + (fun x hx p m a v c => h.pageObjects x hx p m a v ((same x hx (.PageTable p m a v) trivial).1 c)), closed⟩ + exact { + core := ⟨lookup, routes.recoverWalk heap kindPost, root, ty1, ty2, h.core.heap⟩ + place := by rw [effect.table.1, effect.table.poolSet_eq]; exact h.place + poolCaps := h.poolCaps.zero effect.table (effect.poolWord h) + (fun x hx _ _ => effect.nonFrame old hx (fun _ _ _ _ eq => by cases eq)) + capRefs := refs + paths := routes.paths + pageTables := fun x hx p m a v c => h.pageTables x hx p m a v ((same x hx (.PageTable p m a v) trivial).1 c) + footprint := h.footprint + pageObjects := routes.pageObjects + nativeRoots := fun x hx p m a c => h.nativeRoots x hx p m a ((same x hx (.Pml4 p m a) trivial).1 c) + eptRoots := routes.eptRoots + highObjects := routes.highObjects + highHeaders := fun x hx p m a c => by + have live : p ∈ Hr := by rw [highSet]; exact ⟨x, hx, m, a, c⟩ + rw [effect.headers p live] + exact h.highHeaders x hx p m a ((same x hx (.HighVSpace p m a) trivial).1 c) + highLink := routes.highLink + highRoots := highSet + highFootprint := h.highFootprint + kernelTables := h.kernelTables + kernelClosed := closed + rootSlots := routes.rootSlots } + +/-- ARMPageUnmap preserves the concrete R2 record at the common syscall boundary. -/ +theorem syscall.decode_invocation.frameUnmapExactR2 + {A : Type _} {ar : machine.Arch A} {Cs Vc Ub U Ac Rp Nt : Set U64} + {K : capability.Cap → Prop} {Ty : S → Prop} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (B : SysL st H Cs OS ia ie s) + {ptr rights asid va : U64} {sz : capability.FrameSize} {device mapped stage : Bool} + (cap : obj.Slot.cap st slot s = ok (.Frame ptr sz rights device mapped stage asid va)) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Frame ptr sz rights device mapped stage asid va) extra) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageUnmap len slot + (.Frame ptr sz rights device mapped stage asid va) blk call don fp buf extra ⦃ _ q _ => + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ⦄ := by + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + have old := okinj ((capA_eq s slot).symm.trans cap) + let frame : vspace.FrameCap := ⟨ptr, sz, rights, device, mapped, stage, asid, va⟩ + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono (vspace.decode_frame.unmapExactEffect hA hPl frame h place I d P.src old ptKs a len buf call) ?_ + rintro ⟨_, q, _⟩ ⟨start, before, effect, old', caps, base⟩ + exact before.ofFrameUnmap (by rw [base]; exact place) P.heap (kinds.keep fun x hx => by rw [caps x hx]; exact ⟨Iff.rfl, fun _ => ⟨rfl, rfl⟩⟩) + old' effect + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapWalk.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapWalk.lean new file mode 100644 index 000000000..001e456b1 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapWalk.lean @@ -0,0 +1,93 @@ +/- +P1 (aarch64): a leaf on the active path is the executable lookup's stopping word. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2SlotUnique +import Fl4ProofsA64.P1.S1aR2FrameUnmapWord + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {s : S} + {Pp : Set U64} {n tag asid addr : U64} {address level higher : Nat} + +private theorem s1aWindowEnd {shift off base : Nat} (width : off < 4096) : + base + off / 8 * 2 ^ shift + 2 ^ shift ≤ base + 2 ^ (shift + 9) := by + have le := Nat.mul_le_mul_right (2 ^ shift) (show off / 8 + 1 ≤ 512 by omega) + rw [Nat.add_mul, Nat.one_mul] at le + rw [pow_add, Nat.mul_comm (2 ^ shift) (2 ^ 9)] + simpa only [← Nat.add_assoc, show (2 : Nat) ^ 9 = 512 from rfl] using Nat.add_le_add_left le base + +set_option maxHeartbeats 2300000 in +/-- Above the selected slot, the same address crosses a table descriptor +at every intermediate translation level. -/ +theorem S1aSlotAt.ancestor (chosen : S1aSlotAt st Pp n s tag asid address level addr) + (higherLevel : higher = 12 ∨ higher = 21 ∨ higher = 30 ∨ higher = 39) + (depth : level < higher) (top : higher ≤ s1aTopShift tag n) : + ∃ word, S1aSlotAt st Pp n s tag asid address higher word ∧ L.mem s word &&& 3#u64 = 3#u64 := by + obtain ⟨t, base, o, path, bound, offsetAl, located, baseAl, low, high, range⟩ := chosen.entry + clear chosen offsetAl located baseAl range + induction path generalizing o with + | native => + have cap : s1aTopShift 0#u64 n = 39 := rfl + omega + | high => + have cap : s1aTopShift 2#u64 n = 30 := rfl + omega + | stage2 => omega + | @child k a p parentOff sh parentBase parent deep parentWidth parentAl parentRange table ih => + obtain ⟨shapes, hsh⟩ := parent.geometry + have topOfParent := hsh.elim (fun e => e.1.le) (fun e => e.1.le) + have childBelow : sh - 9 < s1aTopShift k n := by omega + have within : o.val < 4096 := by + simpa only [s1aTableWidth, if_neg childBelow.ne] using bound + have endOfChild := s1aWindowEnd (shift := sh - 9) (base := parentBase + parentOff.val / 8 * 2 ^ sh) within + rw [Nat.sub_add_cancel (by omega : 9 ≤ sh)] at endOfChild + have parentLow : parentBase + parentOff.val / 8 * 2 ^ sh ≤ address := by omega + have parentHigh : address < parentBase + parentOff.val / 8 * 2 ^ sh + 2 ^ sh := by omega + by_cases exactLevel : sh = higher + · subst higher + exact ⟨wa p parentOff, ⟨p, parentBase, parentOff, parent, parentWidth, parentAl, rfl, + Nat.mod_eq_zero_of_dvd parent.baseAligned, parentLow, parentHigh, parentRange⟩, table⟩ + · have higherThanParent : sh < higher := by omega + apply ih (o := parentOff) <;> assumption + +/-- Two terminal slots for the same ASID and effective address have the +same level and location. -/ +theorem S1aSlotAt.sameStop {level' : Nat} {addr' : U64} + (p : S1aSlotAt st Pp n s tag asid address level addr) + (q : S1aSlotAt st Pp n s tag asid address level' addr') + (pStop : 12 < level → L.mem s addr &&& 3#u64 ≠ 3#u64) + (qStop : 12 < level' → L.mem s addr' &&& 3#u64 ≠ 3#u64) : + level = level' ∧ addr = addr' := by + have pLevels := p.levels + have qLevels := q.levels + have pLimit : level ≤ s1aTopShift tag n := by + obtain ⟨_, _, _, path, _⟩ := p.entry + exact path.geometry.2.elim (fun e => e.1.le) (fun e => e.1.le) + have qLimit : level' ≤ s1aTopShift tag n := by + obtain ⟨_, _, _, path, _⟩ := q.entry + exact path.geometry.2.elim (fun e => e.1.le) (fun e => e.1.le) + have size : level = level' := by + rcases lt_trichotomy level level' with smaller | equal | larger + · obtain ⟨word, atWord, table⟩ := p.ancestor qLevels smaller qLimit + exact (qStop (by omega) (atWord.unique q ▸ table)).elim + · exact equal + · obtain ⟨word, atWord, table⟩ := q.ancestor pLevels larger pLimit + exact (pStop (by omega) (atWord.unique p ▸ table)).elim + exact ⟨size, p.unique (size.symm ▸ q)⟩ + +/-- An existing leaf at an active slot is the unique terminal descriptor. -/ +theorem S1aSlotAt.leafStop {level' : Nat} {addr' : U64} + (leafSlot : S1aSlotAt st Pp n s tag asid address level addr) + (lookup : S1aSlotAt st Pp n s tag asid address level' addr') + (leaf : s1aLeafValid (L.mem s addr) level) + (stop : 12 < level' → L.mem s addr' &&& 3#u64 ≠ 3#u64) : + level = level' ∧ addr = addr' := + leafSlot.sameStop lookup (fun deep => s1aLeafNotTable (Or.inr leaf) deep) stop + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapWord.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapWord.lean new file mode 100644 index 000000000..e48c3e3b3 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameUnmapWord.lean @@ -0,0 +1,92 @@ +/- +P1 (aarch64): exact leaf recognition and output address for Frame Unmap. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2FrameMapWrite + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +/-- The executable leaf test agrees with the descriptor tag at each level. -/ +theorem ept.is_leaf.exact (e shift : U64) : + ept.is_leaf e shift ⦃ b => b = true ↔ s1aLeafValid e shift.val ⦄ := by + unfold ept.is_leaf + rw [eq_of_spec_fd P0.Consts.ept.D_VALID.spec, eq_of_spec_fd P0.Consts.ept.D_TABLE_OR_PAGE.spec] + have page : shift = ept.PAGE_BITS ↔ shift.val = 12 := + ⟨fun h => (congrArg UScalar.val h).trans P0.Consts.ept.PAGE_BITS.val_eq, + fun h => UScalar.eq_of_val_eq (h.trans P0.Consts.ept.PAGE_BITS.val_eq.symm)⟩ + have combined : (1#u64 ||| 2#u64) = 3#u64 := by decide + refine spec_ite (fun same => ?_) (fun different => ?_) + · simp only [lift, bind_ok, combined] + exact (WP.spec_ok _).2 (by simp [s1aLeafValid, page.mp same]) + · simp only [lift, bind_ok, combined] + exact (WP.spec_ok _).2 (by simp [s1aLeafValid, page.not.mp different]) + +theorem vspace.is_page.exact (e shift : U64) : + vspace.is_page e shift ⦃ b => b = true ↔ s1aLeafValid e shift.val ⦄ := by + have same : vspace.is_page e shift = ept.is_leaf e shift := by + unfold vspace.is_page ept.is_leaf vspace.PAGE_BITS ept.PAGE_BITS vspace.D_VALID ept.D_VALID + vspace.D_TABLE_OR_PAGE ept.D_TABLE_OR_PAGE + rfl + rw [same] + exact ept.is_leaf.exact e shift + +private theorem s1aLeafAddress (e shift : U64) {scale : U64} (scaleEq : scale.val = 2 ^ shift.val) + (limit : shift.val ≤ 30) : + s1aLeafTarget e shift.val = + wa ((e &&& vspace.ADDR_MASK) &&& ~~~(ws scale 1#u64)) layout.PPTR_BASE := by + have small := Nat.pow_lt_pow_right (by decide : (1 : Nat) < 2) (by omega : shift.val < 64) + have positive : 0 < scale.val := by rw [scaleEq]; positivity + have valEq : (ws scale 1#u64).val = 2 ^ shift.val - 1 := by + rw [wsub1_le (by omega), scaleEq] + have mask : (⟨BitVec.ofNat 64 (2 ^ shift.val - 1)⟩ : U64) = ws scale 1#u64 := by + apply UScalar.eq_of_val_eq + change (2 ^ shift.val - 1) % 2 ^ 64 = (ws scale 1#u64).val + rw [valEq, Nat.mod_eq_of_lt (by omega)] + unfold s1aLeafTarget + rw [mask] + +/-- The leaf-base guard succeeds when the active descriptor names the cap's frame. -/ +theorem ept.leaf_base.exact {size : capability.FrameSize} {e ptr shift : U64} + (sh : size.bits = ok shift) (target : s1aLeafTarget e shift.val = ptr) : + ept.leaf_base e shift = ok (ws ptr layout.PPTR_BASE) := by + have levels := s1aFrameShift sh + have masks : ept.ADDR_MASK = vspace.ADDR_MASK := + UScalar.eq_of_val_eq (by simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + have spec : ept.leaf_base e shift ⦃ physical => wa physical layout.PPTR_BASE = ptr ⦄ := by + unfold ept.leaf_base + simp only [lift, bind_ok, masks] + refine WP.spec_bind (s1aFrameScale sh) fun scale eq => ?_ + exact (WP.spec_ok _).2 ((s1aLeafAddress e shift eq (by omega)).symm.trans target) + obtain ⟨out, okOut, addr⟩ := spec_exists_u spec + rw [okOut] + congr 1 + apply UScalar.eq_of_val_eq + have h := congrArg UScalar.val addr + have size64 : UScalar.size UScalarTy.U64 = 2 ^ 64 := by simp [UScalar.size_def, UScalarTy.numBits] + rw [core.num.U64.wrapping_add_val_eq, size64] at h + rw [core.num.U64.wrapping_sub_val_eq, size64] + have pBound := out.bv.isLt + change out.val < 2 ^ 64 at pBound + have base : layout.PPTR_BASE.val < 2 ^ 64 := layout.PPTR_BASE.bv.isLt + change (out.val + layout.PPTR_BASE.val) % 2 ^ 64 = ptr.val at h + change out.val = (ptr.val + (2 ^ 64 - layout.PPTR_BASE.val)) % 2 ^ 64 + omega + +theorem vspace.page_base.exact {size : capability.FrameSize} {e ptr shift : U64} + (sh : size.bits = ok shift) (target : s1aLeafTarget e shift.val = ptr) : + vspace.page_base e shift = ok (ws ptr layout.PPTR_BASE) := by + have masks : ept.ADDR_MASK = vspace.ADDR_MASK := + UScalar.eq_of_val_eq (by simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + have same : vspace.page_base e shift = ept.leaf_base e shift := by + unfold vspace.page_base ept.leaf_base + rw [masks] + rw [same] + exact ept.leaf_base.exact sh target + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2FrameWord.lean b/proofs/Fl4ProofsA64/P1/S1aR2FrameWord.lean new file mode 100644 index 000000000..3c55ac1a4 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2FrameWord.lean @@ -0,0 +1,133 @@ +/- +P1 (aarch64): exact leaf descriptor tags for the Frame Map decoders. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapWalk +import Fl4ProofsA64.P1.MdbArmVsV + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +private theorem leafBitsUnion (x y : Nat) : + (x ||| y) &&& 3 = (x &&& 3) ||| (y &&& 3) := by + apply Nat.eq_of_testBit_eq + intro i + simp only [Nat.testBit_and, Nat.testBit_or] + cases x.testBit i <;> cases y.testBit i <;> cases (3 : Nat).testBit i <;> rfl + +private theorem leafBitsAddress (x mask : Nat) (hm : mask &&& 3 = 0) : + (x &&& mask) &&& 3 = 0 := by + rw [Nat.and_assoc, hm, Nat.and_zero] + +private theorem leafBitsShift (x i : Nat) (hi : 2 ≤ i) : + ((x <<< i) % 2 ^ 64) &&& 3 = 0 := by + rw [show 3 = 2 ^ 2 - 1 by decide, Nat.and_two_pow_sub_one_eq_mod] + rw [show 2 ^ 64 = 4 * 2 ^ 62 by decide, Nat.mod_mul_right_mod] + rw [Nat.shiftLeft_eq, show i = 2 + (i - 2) by omega, pow_add] + rw [Nat.mul_left_comm x] + simp + +private theorem validOfLeafBits {v sh : U64} + (h : v.val &&& 3 = if sh.val = 12 then 3 else 1) : + s1aLeafValid v sh.val := by + by_cases isPage : sh.val = 12 + · left + refine ⟨isPage, UScalar.eq_of_val_eq ?_⟩ + simpa only [UScalar.val_and, show (3#u64 : U64).val = 3 by rfl, isPage, ite_true] using h + · right + refine ⟨isPage, UScalar.eq_of_val_eq ?_⟩ + simpa only [UScalar.val_and, show (3#u64 : U64).val = 3 by rfl, + show (1#u64 : U64).val = 1 by rfl, isPage, ite_false] using h + +private theorem pageShift {shift tag : U64} (bits : tag.val = 12) : + shift = tag ↔ shift.val = 12 := + ⟨fun h => (congrArg UScalar.val h).trans bits, fun h => UScalar.eq_of_val_eq (h.trans bits.symm)⟩ + +private theorem pageBits {shift k : U64} + (h : k.val = if shift.val = 12 then 3 else 1) : + k.val &&& 3 = if shift.val = 12 then 3 else 1 := by + by_cases page : shift.val = 12 <;> simp only [h, page, ite_true, ite_false] <;> decide + +set_option maxHeartbeats 1800000 in +/-- Stage-1 leaf descriptors set precisely the page or block tag for the requested shift. -/ +theorem vspace.make_user_page.leafValid (pa vm : U64) (read : Bool) (attr shift : U64) : + vspace.make_user_page pa vm read attr shift ⦃ v => s1aLeafValid v shift.val ⦄ := by + unfold vspace.make_user_page + rw [eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, eq_of_spec_fd P0.Consts.vspace.D_TABLE_OR_PAGE.spec, + eq_of_spec_fd P0.Consts.vspace.D_SH_INNER.spec, eq_of_spec_fd P0.Consts.vspace.D_AF.spec, + eq_of_spec_fd P0.Consts.vspace.D_NG.spec, eq_of_spec_fd P0.Consts.vspace.D_PXN.spec, + eq_of_spec_fd P0.Consts.vspace.D_UXN.spec] + simp only [lift, bind_ok] + refine WP.spec_bind (P0.vspace.exec_never.p0 _ _) fun xn _ => ?_ + refine WP.spec_bind (Pₘ := fun p : U64 × U64 => p.2.val &&& 3 = 0) ?_ ?_ + · split <;> exact (WP.spec_ok _).2 (by decide) + rintro ⟨idx, sh⟩ shLow + try dsimp only + have page := pageShift (shift := shift) P0.Consts.vspace.PAGE_BITS.val_eq + refine WP.spec_bind (Pₘ := fun v : U64 => v.val = if shift.val = 12 then 3 else 1) ?_ fun i2 tag => ?_ + · split + · rename_i eq + exact (WP.spec_ok _).2 (by rw [if_pos (page.mp eq)]; decide) + · rename_i ne + exact (WP.spec_ok _).2 (by rw [if_neg (page.not.mp ne)]; decide) + refine WP.spec_bind (U64.ShiftLeft_spec idx vspace.D_ATTR_SHIFT (by simp)) fun atShift hAt => ?_ + refine WP.spec_bind (P0.vspace.ap_bits.p0 vm) fun ap _ => ?_ + refine WP.spec_bind (U64.ShiftLeft_spec ap vspace.D_AP_SHIFT (by simp)) fun apShift hAp => ?_ + refine WP.spec_bind (Pₘ := fun v : U64 => v.val &&& 3 = 0) ?_ fun i16 xnLow => ?_ + · split <;> exact (WP.spec_ok _).2 (by decide) + have atLow : atShift.val &&& 3 = 0 := by + rw [hAt.1, P0.Consts.vspace.D_ATTR_SHIFT.val_eq, U64.size_def, U64.numBits] + exact leafBitsShift idx.val 2 (by decide) + have apLow : apShift.val &&& 3 = 0 := by + rw [hAp.1, P0.Consts.vspace.D_AP_SHIFT.val_eq, U64.size_def, U64.numBits] + exact leafBitsShift ap.val 6 (by decide) + refine (WP.spec_ok _).2 (validOfLeafBits ?_) + simp only [UScalar.val_or, UScalar.val_and, leafBitsUnion, P0.Consts.vspace.ADDR_MASK.val_eq, + leafBitsAddress pa.val _ (by decide : (281474976706560 : Nat) &&& 3 = 0), + pageBits tag, atLow, apLow, shLow, xnLow, + show (1024#u64 : U64).val &&& 3 = 0 by decide, + show (2048#u64 : U64).val &&& 3 = 0 by decide, + show (9007199254740992#u64 : U64).val &&& 3 = 0 by decide, + Nat.zero_or, Nat.or_zero] + +set_option maxHeartbeats 1800000 in +/-- Stage-2 Frame Map emits zero for denied rights and a valid leaf otherwise. -/ +theorem ept.make_s2_leaf.leafValid (pa vm : U64) (read : Bool) (attr shift : U64) : + ept.make_s2_leaf pa vm read attr shift ⦃ v => v = 0#u64 ∨ s1aLeafValid v shift.val ⦄ := by + unfold ept.make_s2_leaf + rw [eq_of_spec_fd P0.Consts.ept.S2_AP_RW.spec, eq_of_spec_fd P0.Consts.ept.S2_AP_RO.spec, + eq_of_spec_fd P0.Consts.ept.S2_MEMATTR_NORMAL_WB.spec, eq_of_spec_fd P0.Consts.ept.S2_MEMATTR_DEVICE.spec, + eq_of_spec_fd P0.Consts.ept.S2_SH_INNER.spec, eq_of_spec_fd P0.Consts.ept.S2_AF.spec, + eq_of_spec_fd P0.Consts.ept.S2_XN.spec, eq_of_spec_fd P0.Consts.ept.D_VALID.spec, + eq_of_spec_fd P0.Consts.ept.D_TABLE_OR_PAGE.spec] + simp only [lift, bind_ok] + refine spec_ite (fun _ => ?_) (fun _ => spec_ite (fun _ => ?_) (fun _ => (WP.spec_ok _).2 (Or.inl rfl))) + all_goals + refine WP.spec_bind (P0.vspace.exec_never.p0 attr read) fun xn _ => ?_ + refine WP.spec_bind (Pₘ := fun p : U64 × U64 => p.1.val &&& 3 = 0 ∧ p.2.val &&& 3 = 0) + (by split <;> exact (WP.spec_ok _).2 ⟨by decide, by decide⟩) ?_ + rintro ⟨memAttr, sh⟩ ⟨memLow, shLow⟩ + try dsimp only + try simp only [lift, bind_ok] + have page := pageShift (shift := shift) P0.Consts.ept.PAGE_BITS.val_eq + refine WP.spec_bind (Pₘ := fun v : U64 => v.val = if shift.val = 12 then 3 else 1) ?_ fun i2 tag => ?_ + · split + · rename_i eq + exact (WP.spec_ok _).2 (by rw [if_pos (page.mp eq)]; decide) + · rename_i ne + exact (WP.spec_ok _).2 (by rw [if_neg (page.not.mp ne)]; decide) + try simp only [lift, bind_ok] + refine WP.spec_bind (Pₘ := fun v : U64 => v.val &&& 3 = 0) ?_ fun xnBits xnLow => ?_ + · split <;> exact (WP.spec_ok _).2 (by decide) + refine (WP.spec_ok _).2 (Or.inr (validOfLeafBits ?_)) + simp only [UScalar.val_or, UScalar.val_and, leafBitsUnion, P0.Consts.ept.ADDR_MASK.val_eq, + leafBitsAddress pa.val _ (by decide : (281474976706560 : Nat) &&& 3 = 0), + pageBits tag, memLow, shLow, xnLow, + show (64#u64 : U64).val &&& 3 = 0 by decide, + show (192#u64 : U64).val &&& 3 = 0 by decide, + show (1024#u64 : U64).val &&& 3 = 0 by decide, + Nat.zero_or, Nat.or_zero] + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Image.lean b/proofs/Fl4ProofsA64/P1/S1aR2Image.lean new file mode 100644 index 000000000..5dcc29a59 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Image.lean @@ -0,0 +1,388 @@ +/- +P1 (aarch64, A64-S1A): The table capability image across slot operations. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Caps +import Fl4ProofsA64.P1.S1aR2Frame + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {OS : Set U64} {s s' : S} + +/-- Each table capability retains an exact witness in the slot set, in both directions. -/ +def R2CapImage (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s s' : S) : Prop := + ∀ c, R2TableCap c → + ((∃ x ∈ OS, capA st s' x = c) ↔ (∃ x ∈ OS, capA st s x = c)) + +theorem R2CapImage.ofSlots + (forward : ∀ x ∈ OS, R2TableCap (capA st s x) → ∃ y ∈ OS, capA st s' y = capA st s x) + (backward : ∀ x ∈ OS, R2TableCap (capA st s' x) → ∃ y ∈ OS, capA st s y = capA st s' x) : + R2CapImage st OS s s' := by + intro c hc + constructor + · rintro ⟨x, hx, rfl⟩ + exact backward x hx hc + · rintro ⟨x, hx, rfl⟩ + exact forward x hx hc + +theorem R2CapImage.keep (eq : ∀ x ∈ OS, capA st s' x = capA st s x) : R2CapImage st OS s s' := + .ofSlots (fun x hx _ => ⟨x, hx, eq x hx⟩) (fun x hx _ => ⟨x, hx, (eq x hx).symm⟩) + +theorem R2CapImage.trans {s₀ : S} (h : R2CapImage st OS s₀ s) (h' : R2CapImage st OS s s') : + R2CapImage st OS s₀ s' := fun c hc => (h' c hc).trans (h c hc) + +/-- Insertion and move differ at the source only. In both operations the destination +receives the source's exact table metadata and the source retains its old cap or a non-table cap. -/ +theorem R2CapImage.writeDest {src dest : U64} {c : capability.Cap} + (hs : src ∈ OS) (hd : dest ∈ OS) + (empty : capA st s dest = .Null) + (write : capA st s' dest = c) + (source : capA st s' src = capA st s src ∨ ¬ R2TableCap (capA st s' src)) + (keep : ∀ x ∈ OS, x ≠ src → x ≠ dest → capA st s' x = capA st s x) + (fields : ∀ k, R2TableCap k → (c = k ↔ capA st s src = k)) : + R2CapImage st OS s s' := by + apply R2CapImage.ofSlots + · intro x hx h + by_cases e : x = src + · subst x + exact ⟨dest, hd, write.trans ((fields _ h).2 rfl)⟩ + have ne : x ≠ dest := fun q => by subst x; rw [empty] at h; exact h + exact ⟨x, hx, keep x hx e ne⟩ + · intro x hx h + by_cases e : x = dest + · subst x + exact ⟨src, hs, (fields _ h).1 write.symm⟩ + by_cases ne : x = src + · subst x + exact ⟨src, hs, (source.resolve_right (fun f => f h)).symm⟩ + exact ⟨x, hx, (keep x hx ne e).symm⟩ + +theorem R2CapImage.swap {x y : U64} {c d : capability.Cap} (hx : x ∈ OS) (hy : y ∈ OS) + (ex : capA st s' x = d) (ey : capA st s' y = c) + (keep : ∀ z ∈ OS, z ≠ x → z ≠ y → capA st s' z = capA st s z) + (cx : ∀ k, R2TableCap k → (c = k ↔ capA st s x = k)) + (cy : ∀ k, R2TableCap k → (d = k ↔ capA st s y = k)) : + R2CapImage st OS s s' := by + apply R2CapImage.ofSlots + · intro z hz h + by_cases h1 : z = x + · subst z; exact ⟨y, hy, ey.trans ((cx _ h).2 rfl)⟩ + by_cases h2 : z = y + · subst z; exact ⟨x, hx, ex.trans ((cy _ h).2 rfl)⟩ + exact ⟨z, hz, keep z hz h1 h2⟩ + · intro z hz h + by_cases h1 : z = x + · subst z; exact ⟨y, hy, (cy _ h).1 ex.symm⟩ + by_cases h2 : z = y + · subst z; exact ⟨x, hx, (cx _ h).1 ey.symm⟩ + exact ⟨z, hz, (keep z hz h1 h2).symm⟩ + +namespace R2TableCap + +theorem names {c : capability.Cap} {p : U64} (h : NamesV c p) : R2TableCap c := by + rcases h with ⟨m, a, v, rfl⟩ | ⟨m, a, rfl⟩ | ⟨m, a, rfl⟩ | + ⟨r, m, a, rfl, _⟩ | ⟨l, m, a, v, rfl⟩ <;> trivial + +theorem root {c : capability.Cap} {p a tag : U64} (h : MappedAsidRoot c p a tag) : + R2TableCap c := by + rcases h with ⟨_, rfl⟩ | ⟨_, v, rfl⟩ | ⟨_, rfl⟩ <;> trivial + +end R2TableCap + +theorem R2CapImage.back {x : U64} (h : R2CapImage st OS s s') (hx : x ∈ OS) + (kind : R2TableCap (capA st s' x)) : ∃ y ∈ OS, capA st s y = capA st s' x := + (h _ kind).1 ⟨x, hx, rfl⟩ + +theorem R2CapImage.forward {x : U64} (h : R2CapImage st OS s s') (hx : x ∈ OS) + (kind : R2TableCap (capA st s x)) : ∃ y ∈ OS, capA st s' y = capA st s x := + (h _ kind).2 ⟨x, hx, rfl⟩ + +local notation "wa" => core.num.U64.wrapping_add + +/-- Root agreement survives exact table-cap moves and copies when the active entries +are kept or cleared. -/ +theorem RootAgreement.keepImage {Pp : Set U64} (h : RootAgreement st OS Pp s) + (table : TabKeepOrZero st s s') (caps : R2CapImage st OS s s') + (pool : ∀ p ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o) ∨ L.mem s' (wa p o) = 0#u64) : + RootAgreement st OS Pp s' where + backed a raw hr := by + obtain ⟨x, hx, old⟩ := h.backed a raw (hr.back table pool) + obtain ⟨y, hy, eq⟩ := caps.forward hx (R2TableCap.root old) + exact ⟨y, hy, eq.symm ▸ old⟩ + agree x hx y hy p a b tag tag' cx cy := by + obtain ⟨u, hu, eqx⟩ := caps.back hx (R2TableCap.root cx) + obtain ⟨v, hv, eqy⟩ := caps.back hy (R2TableCap.root cy) + exact h.agree u hu v hv p a b tag tag' (eqx.symm ▸ cx) (eqy.symm ▸ cy) + +section frame + +variable {H : Heap} {Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + +/-- A frame on memory and the exact table-cap image preserve lookup and zeroing. -/ +theorem VsLk.keepImageOfReach (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) (caps : R2CapImage st OS s s') + (r1 : ∀ p, VsReach st (PoolSet st Pp s') ∅ Lv s' p → VsReach st (PoolSet st Pp s) ∅ Lv s p) + (r2 : ∀ p, S2Reach st (PoolSet st Pp s') Re bits s' p → S2Reach st (PoolSet st Pp s) Re bits s p) + (zero : ∀ x ∈ OS, ∀ p size, UnmCap (capA st s x) p size → ∀ o : U64, o.val < size → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) : VsLk st H OS Pp Tb Te Kt Lv Re bits s' := by + have unm : ∀ x ∈ OS, ∀ p size, UnmCap (capA st s' x) p size → + ∃ y ∈ OS, UnmCap (capA st s y) p size := + fun x hx p size hm => by + obtain ⟨y, hy, eq⟩ := caps.back hx (R2TableCap.names hm.names) + exact ⟨y, hy, eq.symm ▸ hm⟩ + have backMap : ∀ p, (∃ x ∈ OS, MapV (capA st s x) p) → ∃ y ∈ OS, MapV (capA st s' y) p := + fun p ⟨x, hx, hm⟩ => by + obtain ⟨y, hy, eq⟩ := caps.forward hx (R2TableCap.names hm.names) + exact ⟨y, hy, eq.symm ▸ hm⟩ + refine ⟨fun p hr ht hk => backMap p (h.bk1 p (r1 p hr) ht hk), + fun p hr ht => backMap p (h.bk2 p (r2 p hr) ht), ?_, ?_, ?_, ?_⟩ + · intro p hp x hx named + obtain ⟨y, hy, eq⟩ := caps.back hx (R2TableCap.names named) + exact h.kt p hp y hy (eq.symm ▸ named) + · intro x hx y hy p size hm mapped + obtain ⟨a, ha, old⟩ := unm x hx p size hm + obtain ⟨b, hb, eq⟩ := caps.back hy (R2TableCap.names mapped.names) + exact h.ex a ha b hb p size old (eq.symm ▸ mapped) + · intro x hx p size hm o ho h8 + obtain ⟨y, hy, old⟩ := unm x hx p size hm + exact (zero y hy p size old o ho h8).trans (h.zr y hy p size old o ho h8) + · refine ⟨?_, ?_, fun p hr ht => h.vh.2.2 p (r2 p hr) ht⟩ + · intro x hx p size hm + obtain ⟨y, hy, old⟩ := unm x hx p size hm + exact h.vh.1 y hy p size old + · intro p reach ht hk + rcases h.vh.2.1 p (r1 p reach) ht hk with exact4 | ⟨r, heap, granule, x, hx, a, cap⟩ + · exact Or.inl exact4 + have kind : R2TableCap (capA st s x) := by rw [cap]; trivial + obtain ⟨y, hy, eq⟩ := caps.forward hx kind + exact Or.inr ⟨r, heap, granule, y, hy, a, eq.trans cap⟩ + +/-- Exact table-cap moves and keeping writes preserve lookup and zeroing. -/ +theorem VsLk.keepImage (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) (caps : R2CapImage st OS s s') + (table : TabKeepOrZero st s s') + (hp : ∀ p ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s' (wa p o) = L.mem s (wa p o)) + (h1 : ∀ p, VsReach st (PoolSet st Pp s) ∅ Lv s p → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + (h2 : ∀ p, S2Reach st (PoolSet st Pp s) Re bits s p → ∀ o : U64, o.val < 2 ^ bits p → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + (zero : ∀ x ∈ OS, ∀ p size, UnmCap (capA st s x) p size → ∀ o : U64, o.val < size → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) : VsLk st H OS Pp Tb Te Kt Lv Re bits s' := by + have r1 : ∀ p, VsReach st (PoolSet st Pp s') ∅ Lv s' p → VsReach st (PoolSet st Pp s) ∅ Lv s p := + fun _ => VsReach.backOf table.poolSet hp h1 + have r2 : ∀ p, S2Reach st (PoolSet st Pp s') Re bits s' p → S2Reach st (PoolSet st Pp s) Re bits s p := + fun _ => S2Reach.backOf table.poolSet hp h2 + exact h.keepImageOfReach caps r1 r2 zero + +/-- `keepImage` from the placement of the active pools only (the form R2 itself carries). -/ +theorem S1aR2Core.keepImageActive (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt (PoolSet st Pp s) Tb Hr Te Lv bits (L.ksb s)) + (base : L.ksb s' = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s s') + (caps : R2CapImage st OS s s') + (zero : ∀ x ∈ OS, ∀ p size, UnmCap (capA st s x) p size → ∀ o : U64, o.val < size → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' := by + have table : TabKeep st s s' := ⟨base, fun i => by rw [base]; exact mem _ (Or.inr (asW_at _ i))⟩ + have includePool : PoolSet st Pp s ⊆ Pt := fun _ hp => place.pools hp + have keepPool p (hp : p ∈ PoolSet st Pp s) o (ho : o.val < 4096) (h8 : o.val % 8 = 0) : + L.mem s' (wa p o) = L.mem s (wa p o) := + mem _ (Or.inl ⟨p, includePool hp, o, ho, h8, rfl⟩) + have keep1 p (hp : VsReach st (PoolSet st Pp s) ∅ Lv s p) o (ho : o.val < 4096) (h8 : o.val % 8 = 0) : + L.mem s' (wa p o) = L.mem s (wa p o) := + mem _ (Or.inl ⟨p, place.tables (h.stage1.sub.reach (hr_rt (by simp)) hp).1, o, ho, h8, rfl⟩) + have keep2 p (hp : S2Reach st (PoolSet st Pp s) Re bits s p) o + (ho : o.val < 2 ^ bits p) (h8 : o.val % 8 = 0) : L.mem s' (wa p o) = L.mem s (wa p o) := + mem _ (Or.inl (ptw_mono place.granules (ptwb_gran place.stage2.sz + ⟨p, (h.stage2.sub.reach hp).1, o, ho, h8, rfl⟩))) + have keepHeader : HrW st Hr s s' := fun r hr => + mem _ (Or.inl ⟨r, place.tables (place.high.sub hr), 4088#u64, by simp, by simp, rfl⟩) + have placeHigh : HrOK (L.ksb s) (PoolSet st Pp s) Tb Lv Hr := place.high + refine ⟨h.lookup.keepImage caps table.toDel keepPool keep1 keep2 zero, ?_, + h.root.keepImage table.toDel caps (fun p hp o ho h8 => Or.inl (keepPool p hp o ho h8)), ?_, ?_, h.heap⟩ + · intro x hx p a va hm + have kind : R2TableCap (capA st s' x) := by rw [hm]; trivial + obtain ⟨y, hy, eq⟩ := caps.back hx kind + rw [table.poolSet_eq (Pp := Pp)] + exact (h.walk y hy p a va (eq.trans hm)).vkSeed (by simp) includePool place.tables place.granules + place.stage2 placeHigh h.stage1 h.stage2 rfl base mem + · rw [base, table.poolSet_eq (Pp := Pp)] + exact h.stage1.keepZ includePool place.tables (by simp) mem.vsz + · rw [table.poolSet_eq (Pp := Pp)] + exact h.stage2.keep includePool place.granules place.stage2 mem.vsz keepHeader + +/-- A fixed VSpace layout and the same table caps, possibly in different slots, +preserve the entire R2 bundle. -/ +theorem S1aR2Core.keepImage (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (base : L.ksb s' = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s s') + (caps : R2CapImage st OS s s') + (zero : ∀ x ∈ OS, ∀ p size, UnmCap (capA st s x) p size → ∀ o : U64, o.val < size → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' := + h.keepImageActive ⟨fun _ hp => place.pools hp.1, place.tables, place.granules, + { place.high with pp := fun p hp => place.high.pp p hp.1 }, place.stage2⟩ base mem caps zero + +end frame + +section cnode + +variable {H : Heap} {Cs : Set U64} + (place : OSOK H.tcbs H.omega H.frame OS) (win : WinOK H.tcbs H.omega) + (mdb : MdbST st OS s) + +include place win + +private theorem cdt.move_cap.r2Image (hma : MdbS st OS s) {src dest : U64} {c : capability.Cap} + (hs : src ∈ OS) (hd : dest ∈ OS) (ne : src ≠ dest) + (encoding : CapRt.EncWf c) (empty : capA st s dest = .Null) + (fields : ∀ k, R2TableCap k → (c = k ↔ capA st s src = k)) : + cdt.move_cap st s c src dest ⦃ s' => R2CapImage st OS s s' ∧ capA st s' src = .Null ∧ + ∀ z ∈ OS, z ≠ src → z ≠ dest → capA st s' z = capA st s z ⦄ := by + obtain ⟨prev, next⟩ := hma.lnk place hs + refine WP.spec_mono (cdt.move_cap.lrF place (LR.self s) hs hd ne (place.canon win hd) encoding prev next) ?_ + rintro s' ⟨_, _, write, clear, keep⟩ + have clean : ¬ R2TableCap (capA st s' src) := by simp [clear, R2TableCap] + exact ⟨R2CapImage.writeDest hs hd empty write (Or.inr clean) keep fields, clear, keep⟩ + +include mdb + +private theorem copyMoveImage {lbl len buf dest : U64} + (hl : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate) (hd : dest ∈ OS) : + CpMv st OS s lbl len buf dest (R2CapImage st OS s) := by + intro s2 src c keep _ hs full empty eq _ + have enc : CapRt.EncWf (capA st s src) := CapRt.decodeF_encWf _ _ + have hm := cnode.copied_cap.lblT hl enc eq + have wf := cnode.copied_cap.mv (st := st) s lbl len buf src (capA st s src) hm enc + have fields := cnode.copied_cap.r2TableFieldsMove (st := st) s lbl len buf src (capA st s src) hm + have fe := cnode.copied_cap.feM (st := st) s lbl len buf src (capA st s src) hm + rw [eq, WP.spec_ok] at wf fields fe + have ne : src ≠ dest := fun e => full (by rwa [e]) + refine WP.spec_mono (cdt.move_cap.r2Image place win (mdb.mdbS.keep keep) hs hd ne + (wf c true rfl).2.2 (by rwa [keep.capA hd]) (fun k hk => ?_)) ?_ + · rw [keep.capA hs] + exact (fields c true rfl).iff_eq (fe c true rfl) hk + · exact fun _ post => (R2CapImage.keep (fun _ hx => keep.capA hx)).trans post.1 + +private theorem copyInsertImage {lbl len buf dest : U64} + (hl : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate) (hd : dest ∈ OS) : + CpIns st OS s lbl len buf dest (R2CapImage st OS s) := by + intro s2 src c keep _ hs full empty eq _ + have enc : CapRt.EncWf (capA st s src) := CapRt.decodeF_encWf _ _ + have hc := cnode.copied_cap.lblF hl enc eq + have wf := cnode.copied_cap.wf (st := st) s lbl len buf src (capA st s src) hc enc + have fields := cnode.copied_cap.r2TableFields (st := st) s lbl len buf src (capA st s src) + have fe := cnode.copied_cap.fe (st := st) s lbl len buf src (capA st s src) + rw [eq, WP.spec_ok] at wf fields fe + have ne : src ≠ dest := fun e => full (by rwa [e]) + obtain ⟨_, next⟩ := (mdb.mdbS.keep keep).lnk place hs + refine WP.spec_mono (cdt.insert_with_cap.lrF place (LR.self s2) hs hd ne (place.canon win hd) + (keep.capA hs) full (wf c false rfl).2 next) ?_ + rintro s' ⟨_, _, write, _, _, stay, source⟩ + have keepSrc : capA st s' src = capA st s2 src ∨ ¬ R2TableCap (capA st s' src) := by + rcases source with eq | ⟨p, b, i, d, eq⟩ + · exact Or.inl eq + · exact Or.inr (by simp [eq, R2TableCap]) + refine (R2CapImage.keep (fun _ hx => keep.capA hx)).trans + (R2CapImage.writeDest hs hd (by rwa [keep.capA hd]) write keepSrc stay fun k hk => ?_) + rw [keep.capA hs] + exact (fields c rfl).iff_eq (fe c rfl) hk + +omit place win mdb in +private theorem rotateFields {c nc : capability.Cap} {data : U64} + (eq : objects.update_cap_data true data c = ok nc) (enc : CapRt.EncWf c) : + CapRt.EncWf nc ∧ (∀ k, R2TableCap k → (nc = k ↔ c = k)) := by + have wf := objects.update_cap_data.wf true data c enc + have fields := objects.update_cap_data.r2TableFields true data c + have fe := objects.update_cap_data.fe true data c + rw [eq, WP.spec_ok] at wf fields fe + exact ⟨wf, fun _ hc => fields.iff_eq fe hc⟩ + +private theorem rotateSwapImage {dest : U64} : + RtSw st OS s dest (R2CapImage st OS s) := by + intro s3 src pivot sd pd c d keep _ hs hp ne _ _ _ _ ec ed _ _ + obtain ⟨fc, mc⟩ := rotateFields ec (CapRt.decodeF_encWf _ _) + obtain ⟨fd, md⟩ := rotateFields ed (CapRt.decodeF_encWf _ _) + have h := mdb.mdbS.keep keep + obtain ⟨prev1, next1⟩ := h.lnk place hs + obtain ⟨prev2, next2⟩ := h.lnk place hp + refine WP.spec_mono (cdt.swap.lrWF place (LR.self s3) hs hp ne.symm (place.canon win hs) + (place.canon win hp) fc fd prev1 next1 prev2 next2) ?_ + rintro s' ⟨_, _, es, ep, stay⟩ + exact (R2CapImage.keep (fun _ hx => keep.capA hx)).trans (R2CapImage.swap hs hp es ep stay + (fun k hk => by rw [keep.capA hs]; exact mc k hk) (fun k hk => by rw [keep.capA hp]; exact md k hk)) + +private theorem rotateMoveImage {dest : U64} (hd : dest ∈ OS) : + RtMv st OS s dest (R2CapImage st OS s) := by + intro s3 src pivot sd pd c d keep _ hs hp ne npd _ full nsd empty ec ed _ nonnull + obtain ⟨fc, mc⟩ := rotateFields ec (CapRt.decodeF_encWf _ _) + obtain ⟨fd, md⟩ := rotateFields ed (CapRt.decodeF_encWf _ _) + have same := keep.capA hp + have empty3 : capA st s3 dest = .Null := by rwa [keep.capA hd] + have m3 := mdb.mdbS.keep keep + have alike := objects.update_cap_data.al true pd (capA st s pivot) + rw [ed, WP.spec_ok] at alike + refine WP.spec_mono (WP.spec_and + (cdt.move_cap.mdbS place m3 hp (by rwa [same]) hd empty3 (place.canon win hd) fd nonnull + (by rw [same]; exact alike.ne nonnull)) + (cdt.move_cap.r2Image place win m3 hp hd npd fd empty3 (fun k hk => by rw [same]; exact md k hk))) ?_ + rintro s4 ⟨m4, i4, clear, stay⟩ + have original : capA st s4 src = capA st s src := (stay src hs ne.symm nsd).trans (keep.capA hs) + refine WP.spec_mono (cdt.move_cap.r2Image place win m4 hs hp ne.symm fc clear + (fun k hk => by rw [original]; exact mc k hk)) fun _ post => ?_ + exact ((R2CapImage.keep (fun _ hx => keep.capA hx)).trans i4).trans post.1 + +variable {A : Type _} {ar : machine.Arch A} {Rp Nt X : Set U64} + {Q : U64 → U64 → List U64} {Rq : U64 → List U64} {extra : Aeneas.Std.Array obj.Slot 3#usize} + (queues : SchedQueuesInvX st H.tcbs Cs H.omega H X s Q Rq) + (slots : SlotTy st H.tcbs H.omega H.frame H Rp Nt OS s) + (extras : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∈ OS) +include queues slots extras + +private theorem cnode.decode_copy.r2Image {lbl len buf dest : U64} (hd : dest ∈ OS) + (hl : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate) : + cnode.decode_copy st s lbl len buf extra dest ⦃ r => R2CapImage st OS s r.2 ⦄ := + cnode.decode_copy.genR place queues (R2CapImage.keep fun _ _ => rfl) + (fun sl hsl hn i d => lookup_src_in slots _ (RootOK.of_slot slots (extras sl hsl hn) (capA_eq s sl)) i d) + ((copyMoveImage place win mdb hl hd).toR _) ((copyInsertImage place win mdb hl hd).toR _) + +private theorem cnode.decode_rotate.r2Image {len buf dest : U64} (hd : dest ∈ OS) : + cnode.decode_rotate st s len buf extra dest ⦃ r => R2CapImage st OS s r.2 ⦄ := + cnode.decode_rotate.genPR (Pv := fun _ => True) place queues slots (R2CapImage.keep fun _ _ => rfl) extras + (fun sl hsl hn i d => WP.spec_mono + (lookup_piv_in slots _ (RootOK.of_slot slots (extras sl hsl hn) (capA_eq s sl)) i d) + fun _ h x e => ⟨h x e, trivial⟩) + (((rotateSwapImage place win mdb).toP _).toR _) (((rotateMoveImage place win mdb hd).toP _).toR _) + +/-- Copy, mint, move, mutate and rotate preserve the exact live table capability image. -/ +theorem cnode.decode.r2Image (a : A) {lbl len buf : U64} (c : capability.Cap) (root : RootOK OS c) + (labels : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) : + cnode.decode st ar s a lbl len c buf extra ⦃ _ s' _ => R2CapImage st OS s s' ⦄ := + cnode.decode.cnodeG (R2CapImage.keep fun _ _ => rfl) a labels c (lookup_tgt_in slots c root) + (fun hl _ hd => cnode.decode_copy.r2Image place win mdb queues slots extras hd hl) + fun _ hd => cnode.decode_rotate.r2Image place win mdb queues slots extras hd + +end cnode + +/-- The CNode arm of the syscall dispatcher preserves every table cap's exact metadata. -/ +theorem syscall.decode_invocation.cnode_r2Image + {H : Heap} {Cs U Ac Rp Nt : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {c : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot lbl : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s c extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (hc : obj.Slot.cap st slot s = ok c) (family : capFam c = .cnode) + (labels : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot c blk call don fp buf extra ⦃ _ s' _ => + R2CapImage st OS s s' ⦄ := by + obtain ⟨_, _, queues⟩ := D.bxi.1 + exact syscall.decode_invocation.cnodeG (R2CapImage.keep fun _ _ => rfl) a len slot c blk call don fp buf extra + family (cnode.decode.r2Image P.os P.win B.sys.stz.1.1 queues P.ty P.ext a c + (RootOK.of_slot P.ty P.src hc) labels) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Install.lean b/proofs/Fl4ProofsA64/P1/S1aR2Install.lean new file mode 100644 index 000000000..bc1a03bbe --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Install.lean @@ -0,0 +1,386 @@ +/- +P1 (aarch64): R2 through a TCB slot install (A64-S1A gen 41). + +`install_tcb_cap` deletes the old cap and inserts the new one if the source still names the same object. The +deletion preserves every cap predicate that holds of `Null` and zombies, so a root cap read before it still +equals the source's cap afterwards. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2DelArm +import Fl4ProofsA64.P1.S1aR2CnodeImage + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Pt U Ac Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {ia ie : Nat} {A : Type _} + {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} {n : U64} + +theorem S1aDelKeep.ofImage {s r : S} (h : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (base : L.ksb r = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s r) (image : S1aSlotImage st OS s r) : + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r := by + have R := S1aR2.ofImage h.1 base mem image + refine ⟨?_, R.highRoots.symm.subset.trans h.2⟩ + unfold S1aDelM + rwa [← R.highRoots] + +/-- The insert of an unread capability, or of the source's own mapped one, into an empty slot keeps R2. -/ +theorem cdt.insert_with_cap.r2C {s : S} {kb : U64} (hO : OSOK H.tcbs H.omega H.frame OS) + (hR : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub kb Pt) (base : L.ksb s = kb) (hm : MdbS st OS s) + {src dest : U64} {nc sc : capability.Cap} (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) + (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hsc0 : sc ≠ .Null) (hw : CapRt.EncWf nc) + (same : S1aR2Reads nc → nc = sc) (mapped : ∀ k, s1aTableKey nc = some k → s1aTableRef nc ≠ none) + (empty : capA st s dest = .Null) + (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + cdt.insert_with_cap st s nc sc src dest ⦃ s' => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + have next := (hm.lnk hO hsrc).2 + refine WP.spec_mono (WP.spec_and (cdt.insert_with_cap.lrF hO.inOS (LR.self s) hsrc hd hsd hdc hsc hsc0 hw next) + (cdt.insert_with_cap.srcF hO hsrc hd hsd hsc hw next)) fun s' ⟨⟨writes, _, new, _, _, other, _⟩, turned⟩ => ?_ + refine K2.ofImage writes.1 (base.symm ▸ vsk_cw0 hR writes) (.copy K2.1.capRefs.refs hsrc hd hsd empty new + (fun reads => (same reads).trans hsc.symm) mapped (S1aCapSame.insertSource (hsc.symm ▸ turned)) other) + +/-- A deletion keeps every cap predicate holding of `Null` and the zombies. -/ +theorem cdt.delete.capInvR {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) {a : A} {x : U64} + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (hx : x ∈ OSN OS (L.ksb s0)) {P : capability.Cap → Prop} + (null : P .Null) (zombie : ∀ p t n, P (.Zombie p t n)) (h : CapInv st P OS s) : + cdt.delete st ar s a x true ⦃ r => CapInv st P OS r.2.1 ⦄ := by + have hD := DomQ.of_sysL (K := K) I.del.heap R.jv R.sys R.vc I.ts I.s2 + rw [R.jv.ksb] at hD + have E := I.del + have field := LoopME.ciM (P := P) null zombie E.arch E.os E.sca E.vc E.dom E.dcan E.vr I.fin I.tyk E.wu E.irq + E.irqSt (E.fieldI (Cs := Cs) (Ac := Ac) (ia := ia) (ie := ie) I.fin I.tyk I.kl s (L.idleW s) + (L.mem s (scA (L.idleW s)))) + (fun _ m => m.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.mdbS) + have B := R.sys + refine WP.spec_mono (cdt.delete.zqIGTMPQ (a := a) E.arch E.os E.sca E.vc E.dom E.dcan E.vr I.fin I.tyk E.wu E.irq + E.irqSt R.jv hx.1 hx.2 hD (fun c hc => hD x hx c hc) rfl rfl R.irq R.ty field.toP ?_) fun _ post => post.2.2.1.2 + exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨B.sys.start, ⟨R.sym, B.vr, B.ly⟩⟩, B.ln⟩, BufInv.of B.cn B.bh⟩, (B.ci.idleAt rfl rfl).idSc B.sc⟩, + CtOff.ks R.jv.ksb.symm B.ct⟩, FrOff.ks R.jv.ksb.symm B.fo⟩, B.ep⟩, B.ipc⟩, h⟩ + +/-- The capabilities a TCB slot install copies that R2 reads: mapped roots. -/ +def S1aInstallRoot (c : capability.Cap) : Prop := + (∃ p a, c = .Pml4 p true a) ∨ (∃ p a, c = .HighVSpace p true a) ∨ ∃ p l a v, c = .Ept p l true a v + +/-- `d` carries the reference of `c` if they name the same table. -/ +def S1aRefAt (c d : capability.Cap) : Prop := + ∀ k, s1aTableKey c = some k → s1aTableKey d = some k → s1aTableRef d = s1aTableRef c + +/-- No step from `s` to `r` introduces a new reference to a table. -/ +def S1aRefsMono (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s r : S) : Prop := + ∀ c, CapInv st (S1aRefAt c) OS s → CapInv st (S1aRefAt c) OS r + +theorem S1aRefsMono.refl (s : S) : S1aRefsMono st OS s s := fun _ h => h + +theorem S1aRefsMono.trans {s q r : S} (first : S1aRefsMono st OS s q) (second : S1aRefsMono st OS q r) : + S1aRefsMono st OS s r := fun c h => second c (first c h) + +theorem S1aRefsMono.keep {s r : S} (keep : OSKeep st OS s r) : S1aRefsMono st OS s r := + fun _ h y hy => (keep.capA hy).symm ▸ h y hy + +theorem S1aRefAt.unkeyed {c d : capability.Cap} (h : s1aTableKey d = none) : S1aRefAt c d := + fun k _ key => by rw [h] at key; cases key + +/-- At R2, a slot's capability gives the reference of every capability of its table. -/ +theorem S1aRefAt.ofSlot {s : S} (refs : S1aRefs st OS s) {src : U64} (hs : src ∈ OS) : + CapInv st (S1aRefAt (capA st s src)) OS s := + fun y hy k key other => refs.references y hy src hs k other key + +/-- An insert of an unkeyed capability, or of the source's own, introduces no reference. -/ +theorem S1aRefsMono.insert {s r : S} {src dest : U64} (hs : src ∈ OS) + (new : capA st r dest = capA st s src ∨ s1aTableKey (capA st r dest) = none) + (source : S1aCapSame st s r src) (keep : ∀ z ∈ OS, z ≠ src → z ≠ dest → capA st r z = capA st s z) : + S1aRefsMono st OS s r := by + intro c h y hy + by_cases hd : y = dest + · rw [hd] + rcases new with same | none + · exact same.symm ▸ h src hs + · exact .unkeyed none + by_cases hsrc : y = src + · rcases source with same | ⟨_, unread⟩ + · rw [hsrc, same] + exact h src hs + · refine .unkeyed ?_ + rw [hsrc] + cases other : s1aTableKey (capA st r src) with + | none => rfl + | some k => exact absurd (s1aTableKey.reads other) unread + rw [keep y hy hsrc hd] + exact h y hy + +/-- A deletion introduces no reference. -/ +theorem cdt.delete.refsR {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) {a : A} {x : U64} + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (hx : x ∈ OSN OS (L.ksb s0)) : + cdt.delete st ar s a x true ⦃ r => S1aRefsMono st OS s r.2.1 ⦄ := by + refine WP.spec_mono (cdt.delete.capInvR I R hx + (P := fun d => ∀ c, CapInv st (S1aRefAt c) OS s → S1aRefAt c d) + (fun c _ => .unkeyed rfl) (fun _ _ _ c _ => .unkeyed rfl) (fun y hy c h => h y hy)) + fun r h c start y hy => h y hy c start + +theorem objects.same_object_as.root {nc sc : capability.Cap} (root : S1aInstallRoot nc) + (h : objects.same_object_as nc sc = ok true) (refs : S1aRefAt nc sc) : sc = nc := by + rcases root with ⟨p, a, rfl⟩ | ⟨p, a, rfl⟩ | ⟨p, l, a, v, rfl⟩ + · cases sc with + | Pml4 q m b => + have same : q = p := by + simp only [objects.same_object_as, objects.same_region_as] at h + (repeat' split at h) <;> simp_all + subst q + have agree := refs (1, p) rfl rfl + cases m <;> simp [s1aTableRef] at agree ⊢ + exact agree + | _ => simp [objects.same_object_as, objects.same_region_as] at h + · cases sc with + | HighVSpace q m b => + have same : q = p := by + simp only [objects.same_object_as, objects.same_region_as] at h + (repeat' split at h) <;> simp_all + subst q + have agree := refs (3, p) rfl rfl + cases m <;> simp [s1aTableRef] at agree ⊢ + exact agree + | _ => simp [objects.same_object_as, objects.same_region_as] at h + · cases sc with + | Ept q level m b w => + have same : q = p ∧ level = l := by + simp only [objects.same_object_as, objects.same_region_as] at h + (repeat' split at h) <;> simp_all + obtain ⟨rfl, rfl⟩ := same + have agree := refs (2, q) rfl rfl + cases m <;> simp [s1aTableRef] at agree ⊢ + exact agree + | _ => simp [objects.same_object_as, objects.same_region_as] at h + +theorem S1aInstallRoot.mapped {c : capability.Cap} (h : S1aInstallRoot c) : s1aTableRef c ≠ none := by + rcases h with ⟨p, a, rfl⟩ | ⟨p, a, rfl⟩ | ⟨p, l, a, v, rfl⟩ <;> exact fun h => by cases h + +/-- `insert_with_cap` of an unkeyed capability, or of the source's own, introduces no reference. -/ +theorem cdt.insert_with_cap.refs {s : S} (hO : OSOK H.tcbs H.omega H.frame OS) (hm : MdbS st OS s) + {src dest : U64} {nc sc : capability.Cap} (hsrc : src ∈ OS) (hd : dest ∈ OS) (hsd : src ≠ dest) + (hdc : obj.sext48 dest = ok dest) (hsc : capA st s src = sc) (hsc0 : sc ≠ .Null) (hw : CapRt.EncWf nc) + (new : nc = capA st s src ∨ s1aTableKey nc = none) : + cdt.insert_with_cap st s nc sc src dest ⦃ s' => S1aRefsMono st OS s s' ⦄ := by + have next := (hm.lnk hO hsrc).2 + refine WP.spec_mono (WP.spec_and (cdt.insert_with_cap.lrF hO.inOS (LR.self s) hsrc hd hsd hdc hsc hsc0 hw next) + (cdt.insert_with_cap.srcF hO hsrc hd hsd hsc hw next)) fun s' ⟨⟨_, _, written, _, _, other, _⟩, turned⟩ => ?_ + exact .insert hsrc (by rw [written]; exact new) (S1aCapSame.insertSource (hsc.symm ▸ turned)) other + +set_option maxHeartbeats 3000000 in +/-- **A TCB slot install keeps any state assertion** carried across the slot's deletion and the one insert. -/ +theorem tcb.install_tcb_cap.phi {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) {a : A} {target slot index src : U64} + {nc : capability.Cap} (ht : target ∈ H.tcbs) (hi : index.val < 7) (hsrc : src ≠ 0#u64 → src ∈ OS) + (hnc : nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) {Φ : S → Prop} + (del : cdt.delete st ar s a (slotIdx target index) true ⦃ r => Φ r.2.1 ⦄) + (ins : ∀ q, Φ q → DelR st H Cs OS Vc Ub Ac Ty ia ie s0 q → src ∈ OS → src ≠ slotIdx target index → + capA st q (slotIdx target index) = .Null → objects.same_object_as nc (capA st q src) = ok true → + TcbK nc → CapRt.EncWf nc → capA st q src ≠ .Null → + cdt.insert_with_cap st q nc (capA st q src) src (slotIdx target index) ⦃ q' => Φ q' ⦄) : + tcb.install_tcb_cap st ar s a target slot index nc src ⦃ r => Φ r.2.1 ⦄ := by + have hx := R.slot I ht hi + unfold tcb.install_tcb_cap + rw [tcb_slot_val] + simp only [bind_ok] + refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.delete.delRP I hKZ hPI R Q hx) del) + (cdt.delete.nullR I R hx)) ?_ + rintro ⟨r, s1, a1⟩ ⟨⟨⟨R1, -⟩, K3⟩, n1⟩ + try simp only [uncurry_apply_pair] at R1 K3 n1 ⊢ + rcases r with v | e + swap + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 K3 + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + have empty : capA st s1 (slotIdx target index) = .Null := okinj ((capA_eq s1 _).symm.trans (n1 v rfl)) + refine WP.spec_bind (spec_eqv (P0.capability.Cap.is_null.p0 nc)) fun bn hbn => ?_ + split + · exact (WP.spec_ok _).2 K3 + rename_i hbf + have hnc0 : nc ≠ .Null := by + rintro rfl + apply hbf + simpa [capability.Cap.is_null] using hbn.symm + refine WP.spec_bind (tcb.still_valid.soa s1 target slot nc src) fun b hb' => ?_ + split + swap + · exact (WP.spec_ok _).2 K3 + rename_i hbt + obtain ⟨hs0, hso, -⟩ := hb' hbt + obtain ⟨hK, hw⟩ := hnc hnc0 + have C := InsC.of_soa hK hso + have hxy : src ≠ slotIdx target index := fun e => C.nn (by rw [e]; exact empty) + unfold cdt.insert + rw [capA_eq, bind_ok] + refine WP.spec_bind (ins s1 K3 R1 (hsrc hs0) hxy empty hso hK hw C.nn) fun _ K4 => ?_ + exact (WP.spec_ok _).2 K4 + +set_option maxHeartbeats 3000000 in +/-- **A TCB slot install keeps R2** when the new capability is unread, or a mapped root whose reference the +entry's slots agree on. -/ +theorem tcb.install_tcb_cap.r2G {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (vsK : ∀ c, K c → S1aVsCap c) + (hPl : ArchPlat ar) (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s0)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) {a : A} {target slot index src : U64} + {nc : capability.Cap} (ht : target ∈ H.tcbs) (hi : index.val < 7) (hsrc : src ≠ 0#u64 → src ∈ OS) + (hnc : nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) + (root : S1aR2Reads nc → CapInv st (S1aRefAt nc) OS s ∧ S1aInstallRoot nc) + (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) : + tcb.install_tcb_cap st ar s a target slot index nc src ⦃ r => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa r.2.1 ∧ S1aRefsMono st OS s r.2.1 ⦄ := by + have hx := R.slot I ht hi + have hO := I.del.os + refine tcb.install_tcb_cap.phi I hKZ hPI R Q ht hi hsrc hnc + (Φ := fun q => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ∧ S1aRefsMono st OS s q) + (WP.spec_and (cdt.delete.r2R I vsK hPl place ptKs R hx K2) (cdt.delete.refsR I R hx)) + fun q ⟨K3, M1⟩ R1 hsO hxy empty hso _ hw nn => ?_ + have copied : S1aR2Reads nc → nc = capA st q src := fun reads => + (objects.same_object_as.root (root reads).2 hso (M1 nc (root reads).1 src hsO)).symm + have mapped : ∀ k, s1aTableKey nc = some k → s1aTableRef nc ≠ none := fun k key => + (root (s1aTableKey.reads key)).2.mapped + refine WP.spec_mono (WP.spec_and (cdt.insert_with_cap.r2C hO I.del.vr R1.jv.ksb R1.sys.sys.stz.1.1.mdbS hsO hx.1 + hxy (I.del.dcan _ hx) rfl nn hw copied mapped empty K3) + (cdt.insert_with_cap.refs hO R1.sys.sys.stz.1.1.mdbS hsO hx.1 hxy (I.del.dcan _ hx) rfl nn hw (by + by_cases reads : S1aR2Reads nc + · exact Or.inl (copied reads) + · refine Or.inr ?_ + cases key : s1aTableKey nc with + | none => rfl + | some k => exact absurd (s1aTableKey.reads key) reads))) fun _ ⟨K4, M2⟩ => ⟨K4, M1.trans M2⟩ + +/-- `obj.Tcb.set_ipc_buffer` writes a TCB word: no VSpace word and no slot. -/ +theorem obj.Tcb.set_ipc_buffer.vk {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) {t v : U64} (ht : t ∈ H.tcbs) : + obj.Tcb.set_ipc_buffer st t s v ⦃ s' => L.ksb s' = L.ksb s ∧ VsKeep st (L.ksb s0) Pt s s' ⦄ := by + refine WP.spec_mono (obj.Tcb.set_ipc_buffer.wr s t v) fun s' e => ?_ + subst e + obtain ⟨_, hb⟩ := R.jv.1.parts + have q := hb.1.choose_spec.choose_spec + have w : WritesIn st s (L.wr s (wa t 3512#u64) v) (· = wa t 3512#u64) := + writesIn_wr (field_aligned (q.tcbs t ht) (by simp) (by simp)) + exact ⟨w.1, VsKeep.of_w I.del.vr.al w fun b hb same => + out_ne_field (q.omega _ (I.del.vr.om b hb)) ht (q.tcbs t ht) (K := 3512#u64) (by simp) (by rw [same])⟩ + +set_option maxHeartbeats 3000000 in +/-- **The IPC buffer install keeps any state assertion** carried across the slot's deletion, steps that keep every +slot and VSpace word, and the one frame insert. -/ +theorem tcb.install_buffer.phi {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (h0 : 0#u64 ∈ Cs) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) {a : A} {t slot baddr : U64} + {buffer : capability.Cap × obj.Slot} (ht : t ∈ H.tcbs) (hslot : slot ∈ OS) (hal : baddr.val % 1024 = 0) + (hbuf : buffer.2 ≠ 0#u64 → buffer.2 ∈ OS ∧ (∃ p sz rights m e aid va, + buffer.1 = .Frame p sz rights false m e aid va) ∧ CapRt.EncWf buffer.1) {Φ : S → Prop} + (del : cdt.delete st ar s a (slotIdx t layout.tcb.SLOT_BUFFER) true ⦃ r => Φ r.2.1 ⦄) + (keep : ∀ q r : S, Φ q → L.ksb q = L.ksb s0 → L.ksb r = L.ksb s0 → VsKeep st (L.ksb s0) Pt q r → + OSKeep st OS q r → Φ r) + (ins : ∀ q, Φ q → DelR st H Cs OS Vc Ub Ac Ty ia ie s0 q → buffer.2 ≠ 0#u64 → buffer.2 ∈ OS → + buffer.2 ≠ slotIdx t layout.tcb.SLOT_BUFFER → capA st q (slotIdx t layout.tcb.SLOT_BUFFER) = .Null → + (∃ p sz rights m e aid va, buffer.1 = .Frame p sz rights false m e aid va) → capA st q buffer.2 ≠ .Null → + CapRt.EncWf buffer.1 → + cdt.insert_with_cap st q buffer.1 (capA st q buffer.2) buffer.2 (slotIdx t layout.tcb.SLOT_BUFFER) + ⦃ q' => Φ q' ⦄) : + tcb.install_buffer st ar s a t slot baddr buffer ⦃ r => Φ r.2.1 ⦄ := by + have hi : layout.tcb.SLOT_BUFFER.val < 7 := by simp [layout.tcb.SLOT_BUFFER] + have hx := R.slot I ht hi + unfold tcb.install_buffer + rw [tcb_slot_val, bind_ok] + refine WP.spec_bind (WP.spec_and (WP.spec_and (cdt.delete.delR I R hx) (cdt.delete.nullR I R hx)) del) ?_ + rintro ⟨r, s1, a1⟩ ⟨⟨R1, n1⟩, K3⟩ + try simp only [uncurry_apply_pair] at R1 n1 K3 ⊢ + cases r with + | Err ex => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from, + bind_tc_ok] + exact (WP.spec_ok _).2 K3 + | Ok v => + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + refine WP.spec_bind (WP.spec_and (obj.Tcb.set_ipc_buffer.delR I R1 ht hal) + (obj.Tcb.set_ipc_buffer.vk I R1 ht)) fun s2 ⟨⟨R2, k2⟩, base2, mem2⟩ => ?_ + have K4 : Φ s2 := keep s1 s2 K3 R1.jv.ksb (base2.trans R1.jv.ksb) mem2 k2 + obtain ⟨c, src⟩ := buffer + try simp only [uncurry_apply_pair] + refine WP.spec_bind (tcb.still_valid.soa s2 t slot c src) fun b hb => ?_ + refine WP.spec_bind (Pₘ := fun s3 => Φ s3 ∧ L.ksb s3 = L.ksb s0 ∧ SysL st H Cs OS ia ie s3 ∧ + ∃ Ac' : Set U64, BXI st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits Ac' s3) ?_ ?_ + · split + swap + · exact (WP.spec_ok _).2 ⟨K4, R2.jv.ksb, R2.sys, R2.jv.1.parts⟩ + rename_i valid + obtain ⟨hnz, hsame, hthread⟩ := hb valid + obtain ⟨hs, ⟨p, sz, rights, m, e, aid, va, rfl⟩, hw⟩ := hbuf hnz + obtain ⟨_, _, _, _, _, source⟩ := soa_frame hsame + have C : InsC (.Frame p sz rights false m e aid va) (capA st s2 src) := by rw [source]; exact InsC.frame + have empty : capA st s2 (slotIdx t layout.tcb.SLOT_BUFFER) = .Null := + (k2.capA hx.1).trans (okinj ((capA_eq s1 _).symm.trans (n1 v rfl))) + have apart : src ≠ slotIdx t layout.tcb.SLOT_BUFFER := fun eq => C.nn (eq ▸ empty) + obtain ⟨_, blk2⟩ := R2.jv.1.parts + have canon := I.del.dcan _ hx + have hm := R2.sys.sys.stz.1.1.mdbS + unfold cdt.insert + rw [capA_eq, bind_ok] + refine WP.spec_mono (WP.spec_and (WP.spec_and (cdt.insert_with_cap.sysLVB I.del.heap I.del.os + blk2 R2.sys R2.sym R2.vc hs hx.1 apart canon rfl empty + (Or.inr ⟨Or.inr ⟨p, sz, rights, m, e, aid, va, rfl⟩, + ⟨(fun _ _ _ _ h => by cases h), (fun _ _ _ h => by cases h)⟩⟩) + ⟨slot, hslot, by rw [soa_thread hthread]; exact CovZ.tcbSlot I.del.heap ht hi⟩ hw (fun h => by cases h) C + (tcb_slot_notEptS I.del.heap ht hi (by simp [layout.tcb.SLOT_BUFFER]))) + (cdt.insert_with_cap.lrF I.del.os (LR.self s2) hs hx.1 apart canon rfl C.nn hw (hm.lnk I.del.os hs).2)) + (ins s2 K4 R2 hnz hs apart empty ⟨p, sz, rights, m, e, aid, va, rfl⟩ C.nn hw)) ?_ + rintro s3 ⟨⟨⟨B3, _, _⟩, w, _⟩, K5⟩ + exact ⟨K5, w.1.trans R2.jv.ksb, B3, (Cur0R.capw7 R2.jv.1.1 w fun _ h => h).bxi⟩ + · rintro s3 ⟨K5, kb3, B3, A3, hb3⟩ + refine WP.spec_bind (sched.cur_thread.spec s3) fun _ _ => ?_ + simp only [obj.Tcb.Insts.CoreCmpPartialEqTcb.eq, bind_ok] + split + swap + · exact (WP.spec_ok _).2 K5 + refine WP.spec_bind (sched.reschedule_required.dfK s3 hb3.blk) fun s4 ⟨_, w, lv⟩ => ?_ + have vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s3) Pt := kb3.symm ▸ I.del.vr + have q := hb3.1.choose_spec.choose_spec + have table := TabF.of vr q B3.ly.ksw h0 + have d : DF st H Cs (L.curW s3) ∅ s3 s4 := DF.ofKL w lv (LvF.none_le _) + have words := VsKeep.of_w vr.al d.w (fun b hV hD => hV.elim (DfW.notPtW q vr hD) + (DfW.notAsW I.del.heap table vr q.nodes hD)) + have slots : OSKeep st OS s3 s4 := OSKeep.of_in I.del.os d.w fun x hx b hb h1 h2 hF => by + rcases hF with hk | ⟨o, ho, _, _, _⟩ + · exact kw7_not_os (Scs := ∅) (Z := H.scBits) (Es := ∅) q hb3.blk.2.2.2.2.sub + (fun _ _ c hc => absurd hc (Set.notMem_empty c)) (fun e he => absurd he (Set.notMem_empty e)) hx hb h1 + h2 (K8.KW.to7 hk) + · exact absurd ho (Set.notMem_empty _) + exact (WP.spec_ok _).2 (keep s3 s4 K5 kb3 (d.w.1.trans kb3) (kb3 ▸ words) slots) + +set_option maxHeartbeats 3000000 in +/-- **The IPC buffer install keeps R2**: the new capability, if any, is unread. -/ +theorem tcb.install_buffer.r2 {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (vsK : ∀ c, K c → S1aVsCap c) + (hPl : ArchPlat ar) (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s0)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s0) b) (h0 : 0#u64 ∈ Cs) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) {a : A} {t slot baddr : U64} + {buffer : capability.Cap × obj.Slot} (ht : t ∈ H.tcbs) (hslot : slot ∈ OS) (hal : baddr.val % 1024 = 0) + (hbuf : buffer.2 ≠ 0#u64 → buffer.2 ∈ OS ∧ (∃ p sz rights m e aid va, + buffer.1 = .Frame p sz rights false m e aid va) ∧ CapRt.EncWf buffer.1) + (unread : buffer.2 ≠ 0#u64 → ¬ S1aR2Reads buffer.1) + (K2 : S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) : + tcb.install_buffer st ar s a t slot baddr buffer ⦃ r => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa r.2.1 ∧ S1aRefsMono st OS s r.2.1 ⦄ := by + have hi : layout.tcb.SLOT_BUFFER.val < 7 := by simp [layout.tcb.SLOT_BUFFER] + have hx := R.slot I ht hi + refine tcb.install_buffer.phi I h0 R ht hslot hal hbuf + (Φ := fun q => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ∧ S1aRefsMono st OS s q) + (WP.spec_and (cdt.delete.r2R I vsK hPl place ptKs R hx K2) (cdt.delete.refsR I R hx)) + (fun q r h hq hr mem same => ⟨h.1.osKeep hq hr mem same, h.2.trans (.keep same)⟩) + fun q ⟨K4, M2⟩ R2 hnz hs apart empty ⟨p, sz, rights, m, e, aid, va, shape⟩ nn hw => ?_ + have plain := unread hnz + rw [shape] at plain hw ⊢ + have nokey : s1aTableKey (.Frame p sz rights false m e aid va) = none := rfl + have hm := R2.sys.sys.stz.1.1.mdbS + have canon := I.del.dcan _ hx + refine WP.spec_mono (WP.spec_and (cdt.insert_with_cap.r2C I.del.os I.del.vr R2.jv.ksb hm hs hx.1 apart canon rfl nn hw + (fun reads => absurd reads plain) (fun k key => by rw [nokey] at key; cases key) empty K4) + (cdt.insert_with_cap.refs I.del.os hm hs hx.1 apart canon rfl nn hw (Or.inr nokey))) + fun _ ⟨K5, M3⟩ => ⟨K5, M2.trans M3⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Keep.lean b/proofs/Fl4ProofsA64/P1/S1aR2Keep.lean new file mode 100644 index 000000000..ab86d09b3 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Keep.lean @@ -0,0 +1,86 @@ +/- +P1 (aarch64, A64-S1A): R2 across invocations with a VSpace memory frame. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Image +import Fl4ProofsA64.P1.S1aHiK + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS Cs Vc Ub Pt Pp Tb Hr Te Kt U Ac : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s s' : S} + {ia ie : Nat} {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {cap : capability.Cap} {slot lbl : U64} + +local notation "wa" => core.num.U64.wrapping_add + +theorem UnmCap.toSlot {x p : U64} {size : Nat} (h : UnmCap (capA st s x) p size) : UnmC st x p size s := by + rcases h with ⟨hn, a, v, e⟩ | ⟨hn, a, v, e⟩ + · exact Or.inl ⟨hn, a, v, (capA_eq s x).trans (congrArg ok e)⟩ + · exact Or.inr ⟨hn, a, v, (capA_eq s x).trans (congrArg ok e)⟩ + +/-- The decoder's unmapped-object case follows from R2 and the two table placements. -/ +theorem VsLk.unmZPlaced (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) (heap : HeapOK H) + (pt : PtCap st Pt OS s) + (ept : ∀ x ∈ OS, ∀ p a v, capA st s x = .Ept p 0#u64 false a v → Gran {p} (fun _ => 13) ⊆ Pt) : + UnmZ st OS Pt (S2Rt st (PoolSet st Pp s) Te Re bits s) bits s where + pt x hx p a v cap := by + have e := okinj ((capA_eq s x).symm.trans cap) + have hu : UnmC st x p 4096 s := Or.inl ⟨rfl, _, _, cap⟩ + exact ⟨pt x hx p false a v e, fun _ ho al => ⟨h.unmCTZ heap hx hu ho, h.unmCZ hx hu ho al⟩⟩ + ept x hx p a v cap := by + have e := okinj ((capA_eq s x).symm.trans cap) + have hu : UnmC st x p 8192 s := Or.inr ⟨rfl, _, _, cap⟩ + exact ⟨ept x hx p a v e, fun _ ho al => ⟨h.unmCTZ heap hx hu ho, h.unmCZ hx hu ho al⟩⟩ + +/-- A keeping arm transports R2 when its unmapped objects are included in the +existing VSpace footprint. -/ +theorem S1aR2Core.ofKeepingArm (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (layout : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (unmapped : UnmZ st OS Pt (S2Rt st (PoolSet st Pp s) Te Re bits s) bits s) + (mem : ArmVsK st H OS Vc s s') (image : R2CapImage st OS s s') : + S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' := by + have keep := mem.vsKeep I.del.vr I.fu + apply h.keepImage layout mem.1 keep image + exact fun x hx p size cap o ho al => keep _ (unmapped.words (kb := L.ksb s) hx (UnmCap.toSlot cap) ho al).1 + +section +variable (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (layout : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (unmapped : UnmZ st OS Pt (S2Rt st (PoolSet st Pp s) Te Re bits s) bits 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) (source : obj.Slot.cap st slot s = ok cap) +include h layout I unmapped D P B Y source + +/-- The exact-capability keeping arms transport the R2 bundle. -/ +theorem syscall.decode_invocation.keeping_r2 (hA : P0.ArchTotal ar) (hks : HeapKsOff H (L.ksb s)) + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) + (sc : L.mem s (scA (L.curW s)) ≠ 0#u64) (arm : DecArmKK3 cap lbl) + (a : A) (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' _ => + S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := + WP.spec_mono (syscall.decode_invocation.armKK3At hA I D P B Y source hks mcp sc a arm len blk call don fp buf) + fun _ ⟨_, _, caps, mem⟩ => + h.ofKeepingArm layout I unmapped mem (R2CapImage.keep (fun _ hx => caps.capA hx)) + +/-- Copy, mint, move, mutate, and rotate transport R2 with the same VSpace frame. -/ +theorem syscall.decode_invocation.cnode_r2 (family : capFam cap = .cnode) + (labels : lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ lbl = fl4_abi.label.CNodeMove ∨ + lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) + (a : A) (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' _ => + S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := + WP.spec_mono (WP.spec_and + (syscall.decode_invocation.cnode_armQIKAt D P B Y I.del.vr a len blk call don fp buf labels family source) + (syscall.decode_invocation.cnode_r2Image D P B source family labels a len blk call don fp buf)) + fun _ ⟨⟨_, _, mem⟩, caps⟩ => h.ofKeepingArm layout I unmapped mem caps + +end + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2KeepArms.lean b/proofs/Fl4ProofsA64/P1/S1aR2KeepArms.lean new file mode 100644 index 000000000..cebdb465c --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2KeepArms.lean @@ -0,0 +1,116 @@ +/- +P1 (aarch64): R2 across the arms that keep every capability R2 reads: Page GetAddress, the notification +invocation, TCB Suspend and ReadRegisters, the VCPU invocations, IrqControl and the endpoint send (A64-S1A +gen 41). + +Their tops export `ArmVsK` (the VSpace words) with `OSKeep` (every slot word), for IrqControl `IrqSlots` +(only the handler's insert), and for the endpoint `XferSlots` (at most one derived copy). Named premises: [P] `MaxSpi` (IrqControl, as in its top). +-/ +import Fl4ProofsA64.P1.S1aR2CnodeImage +import Fl4ProofsA64.P1.MdbArmQHD + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {ia ie : Nat} {A : Type _} + {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- An arm keeping the VSpace words and every slot keeps R2. -/ +theorem S1aR2.ofArmKeep {s r : S} (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) (mem : ArmVsK st H OS Vc s r) (slots : OSKeep st OS s r) : + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r := + h.ofImage mem.1 (mem.2 Ub Pt I.del.vr I.fu) + (.ofSame h.capRefs.refs fun _ hy => Or.inl (slots.capA hy)) + +/-- The invocations that keep every capability slot. -/ +def DecArmR2Keep (cap : capability.Cap) (lbl : U64) : Prop := + (∃ n b sd rv, cap = .Notification n b sd rv) ∨ + (∃ t, cap = .Thread t ∧ (lbl = fl4_abi.label.TCBSuspend ∨ lbl = fl4_abi.label.TCBReadRegisters)) ∨ + (∃ v, cap = .Vcpu v ∧ (lbl = fl4_abi.label.ARMVCPURun ∨ lbl = fl4_abi.label.ARMVCPUAckVPPI ∨ + lbl = fl4_abi.label.ARMVCPUWriteReg ∨ lbl = fl4_abi.label.ARMVCPUInjectIRQ ∨ + lbl = fl4_abi.label.ARMVCPUReadState ∨ lbl = fl4_abi.label.ARMVCPUWriteState ∨ + lbl = fl4_abi.label.ARMVCPUSetTCB)) ∨ + (∃ p sz r d m e a v, cap = .Frame p sz r d m e a v ∧ lbl = fl4_abi.label.ARMPageGetAddress) + +/-- **The slot-keeping invocations keep R2.** -/ +theorem syscall.decode_invocation.keepSlotsExactR2 (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot lbl : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok cap) + (arm : DecArmR2Keep cap lbl) (a : A) (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' _ => + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + have close {m : Result ((core.result.Result Unit error.Exc) × S × A)} + (top : m ⦃ r s' _ => ArmQIAt st H Cs OS Vc ia ie s s' ∧ TabKeepOrZero st s s' ∧ ArmVsK st H OS Vc s s' ∧ + OSKeep st OS s s' ⦄) : + m ⦃ _ s' _ => S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := + WP.spec_mono top fun r d => by + obtain ⟨_, _, _⟩ := r + exact h.ofArmKeep I d.2.2.1 d.2.2.2 + rcases arm with ⟨m, b, sd, rv, rfl⟩ | ⟨t, rfl, hl | hl⟩ | + ⟨v, rfl, hl | hl | hl | hl | hl | hl | hl⟩ | ⟨p, sz, r, d, m, e, asid, va, rfl, hl⟩ + · exact close (syscall.decode_invocation.ntfn_armSAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + · exact close (syscall.decode_invocation.suspend_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.readRegs_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.run_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.ackVppi_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.vcWr_armSAt hA I D P B Y hks hcap a (Or.inl hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.vcWr_armSAt hA I D P B Y hks hcap a (Or.inr hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.vcSt_armSAt hA I D P B Y hks hcap a (Or.inl hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.vcSt_armSAt hA I D P B Y hks hcap a (Or.inr hl) len blk call don fp buf) + · exact close (syscall.decode_invocation.setTcb_armSAt hA I D P B Y hks hcap a hl len blk call don fp buf) + · exact close (syscall.decode_invocation.getAddr_armSAt I D P B Y hks a hl len blk call don fp buf) + +/-- **The IrqControl invocations keep R2**: the one insert is of a handler capability R2 does not read. -/ +theorem syscall.decode_invocation.irqCtlExactR2 (hA : P0.ArchTotal ar) (hM : MaxSpi ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (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 .IrqControl 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 .IrqControl) (a : A) (lbl len : U64) + (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot .IrqControl blk call don fp buf extra ⦃ _ s' _ => + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + refine WP.spec_mono (syscall.decode_invocation.irqCtl_armSAt hA hM I D P B Y hcap a lbl len blk call don fp buf) + fun r d => ?_ + obtain ⟨_, s', _⟩ := r + obtain ⟨-, -, mem, slots⟩ := d + refine h.ofImage mem.1 (mem.2 Ub Pt I.del.vr I.fu) (.ofSame h.capRefs.refs fun y hy => ?_) + rcases slots y hy with same | ⟨old, i, new⟩ + · exact Or.inl same + · exact Or.inr ⟨by rw [old]; exact id, by rw [new]; exact id⟩ + +/-- A transfer's slot fact gives the image of the capabilities R2 reads. -/ +theorem XferSlots.s1aImage {s r : S} (refs : S1aRefs st OS s) (h : XferSlots st OS s r) : + S1aSlotImage st OS s r := by + rcases h with same | ⟨src, hs, dest, hd, ne, empty, ⟨q, c, derived, new⟩, turned, others⟩ + · exact .ofSame refs fun y hy => Or.inl (same y hy) + have rel := objects.derive_cap.s1aRel (st := st) q src (capA st s src) + rw [derived, WP.spec_ok] at rel + obtain ⟨copied, fresh⟩ := rel c rfl + exact .copy refs hs hd ne empty new (fresh.same copied) fresh.2 (S1aCapSame.insertSource turned) others + +/-- **The endpoint invocation keeps R2**: the send's one capability transfer is a derived copy. -/ +theorem syscall.decode_invocation.endpointExactR2 (hA : P0.ArchTotal ar) {s : S} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot e b : U64} {sd rv g gr : Bool} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (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 (.Endpoint e b sd rv g gr) + extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (hcap : obj.Slot.cap st slot s = ok (.Endpoint e b sd rv g gr)) (a : A) (lbl len : U64) (blk call don fp : Bool) + (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Endpoint e b sd rv g gr) blk call don fp buf extra + ⦃ _ s' _ => S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + refine WP.spec_mono (syscall.decode_invocation.ep_armSAt hA I D P B Y hks hcap a lbl len blk call don fp buf) + fun r d => ?_ + obtain ⟨_, s', _⟩ := r + obtain ⟨-, -, mem, slots⟩ := d + exact h.ofImage mem.1 (mem.2 Ub Pt I.del.vr I.fu) (slots.s1aImage h.capRefs.refs) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2KtDel.lean b/proofs/Fl4ProofsA64/P1/S1aR2KtDel.lean new file mode 100644 index 000000000..96ddac772 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2KtDel.lean @@ -0,0 +1,271 @@ +/- +P1 (aarch64): R2 together with the kernel-table / Untyped separation through the arms that delete: CNode Delete and +Revoke, the IRQ handler, the TCB installs, SetEPTRoot and SetSchedParams (A64-S1A gen 41). + +Each arm's walk is stated for any state assertion carried across its steps; here the assertion is `S1aDelKt`, R2's +deletion form with `S1aKtUt`. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aKtUtDel +import Fl4ProofsA64.P1.S1aR2TcbArm + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Pt U Ac Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {ia ie : Nat} {A : Type _} + {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} {n : U64} + +/-- The deletion form of R2 with the kernel-table / Untyped separation. -/ +def S1aDelKt (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt Pp Tb Hr Te Kt : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (s : S) : Prop := + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s ∧ S1aKtUt st OS Kt s + +theorem S1aDelKt.osKeep {q r : S} {kb : U64} (h : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q) + (hq : L.ksb q = kb) (hr : L.ksb r = kb) (mem : VsKeep st kb Pt q r) (keep : OSKeep st OS q r) : + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r := + ⟨h.1.osKeep hq hr mem keep, h.2.keep keep⟩ + +theorem TcbK.notUntyped {c : capability.Cap} (h : TcbK c) : ∀ p b i d, c ≠ .Untyped p b i d := by + intro p b i d e + subst e + rcases h with ⟨_, _, _, _, _, _, e⟩ | ⟨_, _, _, _, e⟩ | ⟨_, _, _, e⟩ | ⟨_, _, _, _, _, e⟩ | ⟨_, _, _, e⟩ <;> + cases e + +/-! ## The TCB slot installs -/ + +theorem tcb.install_tcb_cap.ktUt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) + (hKZ : FinKZ st ar (L.ksb s0) Pt Ty K) (hPI : PoolIdx st OS s0) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) (Q : PoolR st OS s0 s) {a : A} {target slot index src : U64} + {nc : capability.Cap} (ht : target ∈ H.tcbs) (hi : index.val < 7) (hsrc : src ≠ 0#u64 → src ∈ OS) + (hnc : nc ≠ .Null → TcbK nc ∧ CapRt.EncWf nc) (sep : S1aKtUt st OS Kt s) : + tcb.install_tcb_cap st ar s a target slot index nc src ⦃ r => S1aKtUt st OS Kt r.2.1 ⦄ := + have hx := R.slot I ht hi + tcb.install_tcb_cap.phi I hKZ hPI R Q ht hi hsrc hnc (Φ := S1aKtUt st OS Kt) (cdt.delete.ktUtR I R hx sep) + fun _ h R1 hsO hxy _ _ hK hw nn => cdt.insert_with_cap.ktUt I.del.os R1.sys.sys.stz.1.1.mdbS hsO hx.1 hxy + (I.del.dcan _ hx) rfl nn hw hK.notUntyped h + +theorem tcb.install_buffer.ktUt {s0 s : S} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s0) (h0 : 0#u64 ∈ Cs) + (R : DelR st H Cs OS Vc Ub Ac Ty ia ie s0 s) {a : A} {t slot baddr : U64} + {buffer : capability.Cap × obj.Slot} (ht : t ∈ H.tcbs) (hslot : slot ∈ OS) (hal : baddr.val % 1024 = 0) + (hbuf : buffer.2 ≠ 0#u64 → buffer.2 ∈ OS ∧ (∃ p sz rights m e aid va, + buffer.1 = .Frame p sz rights false m e aid va) ∧ CapRt.EncWf buffer.1) (sep : S1aKtUt st OS Kt s) : + tcb.install_buffer st ar s a t slot baddr buffer ⦃ r => S1aKtUt st OS Kt r.2.1 ⦄ := + have hx := R.slot I ht (show layout.tcb.SLOT_BUFFER.val < 7 by simp [layout.tcb.SLOT_BUFFER]) + tcb.install_buffer.phi I h0 R ht hslot hal hbuf (Φ := S1aKtUt st OS Kt) (cdt.delete.ktUtR I R hx sep) + (fun _ _ h _ _ _ same => S1aKtUt.keep h same) + fun _ h R2 _ hs apart _ shape nn hw => cdt.insert_with_cap.ktUt I.del.os R2.sys.sys.stz.1.1.mdbS hs hx.1 apart + (I.del.dcan _ hx) rfl nn hw (fun _ _ _ _ bad => by + obtain ⟨_, _, _, _, _, _, _, frame⟩ := shape + rw [frame] at bad + cases bad) h + +/-- The install steps of the TCB walks keep the separation. -/ +theorem S1aTcbSteps.ktUt {s s1 : S} {t slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (ht : t ∈ H.tcbs) (hslot : slot ∈ OS) + (h0 : 0#u64 ∈ Cs) : + S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot (S1aKtUt st OS Kt) (fun _ => True) + (fun _ => True) where + keep _ _ h _ _ _ same := S1aKtUt.keep h same + install _ _ _ _ _ h R Q _ hi _ _ hsrc hnc _ := tcb.install_tcb_cap.ktUt I hKZ hPI R Q ht hi hsrc hnc h + buffer _ _ _ _ h R hal hbuf _ := tcb.install_buffer.ktUt I h0 R ht hslot hal hbuf h + unread _ _ := True.intro + roots cd vd cs vs _ _ := + WP.spec_mono (tcb.derive_roots.tk s1 t cd vd cs vs) fun _ _ _ _ _ => ⟨True.intro, True.intro⟩ + high _ _ _ _ _ := True.intro + derived baddr bslot _ := WP.spec_mono (tcb.derive_for_buffer.buf s1 baddr bslot) fun _ _ _ _ _ => True.intro + +/-- Two sets of install steps carry both assertions. -/ +theorem S1aTcbSteps.and {s s1 : S} {t slot : U64} {Φ Ψ : S → Prop} {G G' : capability.Cap → Prop} + {B B' : capability.Cap × obj.Slot → Prop} + (x : S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot Φ G B) + (y : S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot Ψ G' B') : + S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot (fun q => Φ q ∧ Ψ q) (fun c => G c ∧ G' c) + (fun b => B b ∧ B' b) where + keep q r h hq hr mem same := ⟨x.keep q r h.1 hq hr mem same, y.keep q r h.2 hq hr mem same⟩ + install q a index nc src h R Q Z hi hi2 hi5 hsrc hnc good := + WP.spec_and (x.install q a index nc src h.1 R Q Z hi hi2 hi5 hsrc hnc good.1) + (y.install q a index nc src h.2 R Q Z hi hi2 hi5 hsrc hnc good.2) + buffer q a baddr buffer h R hal hbuf good := + WP.spec_and (x.buffer q a baddr buffer h.1 R hal hbuf good.1) (y.buffer q a baddr buffer h.2 R hal hbuf good.2) + unread nc h := ⟨x.unread nc h, y.unread nc h⟩ + roots cd vd cs vs hcs hvs := + WP.spec_mono (WP.spec_and (x.roots cd vd cs vs hcs hvs) (y.roots cd vd cs vs hcs hvs)) + fun _ h cc vc e => ⟨⟨(h.1 cc vc e).1, (h.2 cc vc e).1⟩, ⟨(h.1 cc vc e).2, (h.2 cc vc e).2⟩⟩ + high z hz p a cap := ⟨x.high z hz p a cap, y.high z hz p a cap⟩ + derived baddr bslot hs := + WP.spec_mono (WP.spec_and (x.derived baddr bslot hs) (y.derived baddr bslot hs)) + fun _ h c src e => ⟨h.1 c src e, h.2 c src e⟩ + +/-- The caller's restart keeps every capability slot. -/ +theorem sched.set_thread_state.restartOs {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot : U64} (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) : + sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ s1 => OSKeep st OS s s1 ⦄ := by + have q := (Stalled.refl0 D).bxi.1.choose_spec.choose_spec + have words := tcb.restart_caller.sts (q.nodes _ q.cur) (q.tcbs _ q.curT) + simp only [tcb.restart_caller, cur_thread_ok, bind_ok] at words + exact WP.spec_mono words fun _ w => stt_osk P.os q q.curT w + +/-! ## The dispatcher arms -/ + +/-- SetHighVSpace, SetSpace, SetIPCBuffer, Configure and SetTimeoutEndpoint keep R2 and the separation. -/ +theorem syscall.decode_invocation.tcbInstall_kt (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetHighVSpace ∨ lbl = fl4_abi.label.TCBSetSpace ∨ + lbl = fl4_abi.label.TCBSetIPCBuffer ∨ lbl = fl4_abi.label.TCBConfigure ∨ + lbl = fl4_abi.label.TCBSetTimeoutEndpoint) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDel hPl W + have z := W.finKZ (hPl := hPl) I + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have ht := D.cap.2.1 t rfl + exact WP.spec_mono (syscall.decode_invocation.tcbInstall_phi hA J z hPI D P B Y + (Φ := fun q => S1aTcbKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s q ∧ S1aKtUt st OS Kt q) + ⟨⟨R.toDelKeep, .refl s⟩, sep⟩ + (fun s1 ds1 => (S1aTcbSteps.r2 (Re := Re) (Kt := Kt) (Ac := Ac) (ia := ia) (ie := ie) (s1 := s1) (t := t) + (slot := slot) J (fun _ h => h.vsCap) hPl place ptKs z hPI ht P.src P.core0 R.capRefs.refs ds1.1).and + (S1aTcbSteps.ktUt J z hPI ht P.src P.core0)) + a hl len blk call don fp buf) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨h.1.1, h.2⟩ + +/-- SetEPTRoot keeps R2 and the separation. -/ +theorem syscall.decode_invocation.setEpt_kt (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) (a : A) + (hXE : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∉ EptS H.tcbs) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.TCBSetEPTRoot len slot (.Thread t) blk call don fp buf extra + ⦃ r s' _ => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDel hPl W + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have entry : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s := ⟨R.toDelKeep, sep⟩ + refine syscall.decode_invocation.tcbG (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) entry + a len blk call don fp buf fun _ _ eq => ?_ + subst eq + refine WP.spec_mono (tcb.decode.setEpt_s1aPhi hA J D P B Y hXE + (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) entry + (fun q r h hq hr mem same => h.osKeep hq hr mem same) + (fun q a x h Rq hx => WP.spec_and (cdt.delete.r2R J (fun _ h => h.vsCap) hPl place ptKs Rq hx h.1) + (cdt.delete.ktUtR J Rq hx h.2)) + (fun q src dest nc h Rq hs hd ne can source wf empty ept => by + obtain ⟨p, l, m, v, rfl⟩ := ept + have hm := Rq.sys.sys.stz.1.1.mdbS + exact WP.spec_and (cdt.insert_with_cap.r2C I.del.os I.del.vr Rq.jv.ksb hm hs hd ne can source + (fun e => by cases e) wf (fun _ => rfl) (fun _ _ none => by cases none) empty h.1) + (cdt.insert_with_cap.ktUt I.del.os hm hs hd ne can source (fun e => by cases e) wf + (fun _ _ _ _ e => by cases e) h.2))) fun _ h => h.2 + +/-- SetSchedParams keeps R2 and the separation. -/ +theorem syscall.decode_invocation.ssp_kt (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + {m : U64} (Hy : ArmDecHyps st H Pt m s (.Thread t)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetSchedParams) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDel hPl W + have z := W.finKZ (hPl := hPl) I + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have ht := D.cap.2.1 t rfl + exact syscall.decode_invocation.ssp_phi hA J z hPI D P B Y hks hcap Hy + (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) ⟨R.toDelKeep, sep⟩ + (fun q r h hq hr mem keep => h.osKeep hq hr mem keep) + (fun q a nc src h Rq Qq _ blk hfh hnc valid hsrc source => WP.spec_and + (tcb.install_tcb_cap.r2F J (fun _ h => h.vsCap) hPl place ptKs z hPI Rq Qq blk ht P.src hsrc hnc + hfh (faults.valid_fault_handler.unread valid) source h.1) + (tcb.install_tcb_cap.ktUt J z hPI Rq Qq ht (by simp [layout.tcb.SLOT_FAULT_HANDLER]) (fun _ => hsrc) hnc h.2)) + a hl len blk call don fp buf + +/-- CNode Delete and Revoke keep R2 and the separation. -/ +theorem syscall.decode_invocation.cnodeRvDel_kt {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) (hPl : ArchPlat ar) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa 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) (hf : capFam cap = .cnode) + (hks : HeapKsOff H (L.ksb s)) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (sep : S1aKtUt st OS Kt s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.CNodeRevoke ∨ lbl = fl4_abi.label.CNodeDelete) (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 ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDel hPl W + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have entry : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s := ⟨R.toDelKeep, sep⟩ + have vsK : ∀ c, S2Q c → S1aVsCap c := fun _ h => h.vsCap + refine syscall.decode_invocation.cnodeG (P := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) entry a len + slot cap blk call don fp buf extra hf + (WP.spec_mono (cnode.decode.rvDelPhi J D P B hcap + (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) entry + (WP.spec_mono (WP.spec_and (tcb.restart_caller.r2Keep J D P B Y entry.1) + (sched.set_thread_state.restartOs P D)) fun _ ⟨⟨Rq, h⟩, keep⟩ => ⟨Rq, h, sep.keep keep⟩) + (fun _ _ Rq hx h => WP.spec_and (cdt.delete.r2R J vsK hPl place ptKs Rq hx h.1) (cdt.delete.ktUtR J Rq hx h.2)) + (fun _ _ Rq hx h => WP.spec_and (cdt.revoke.r2R J vsK hPl place ptKs Rq hx h.1) (cdt.revoke.ktUtR J Rq hx h.2)) + hl) fun r h => by + obtain ⟨_, _, _⟩ := r + exact h) + +/-- IRQ ClearIRQHandler and SetIRQHandler keep R2 and the separation. -/ +theorem syscall.decode_invocation.irqHandler_kt {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot irq : 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 (.IrqHandler irq) 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) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (a : A) {lbl : U64} (hl : lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) + (hi : irq.val < 5376) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.IrqHandler irq) blk call don fp buf extra ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + have entry : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s := ⟨R.toDelKeep, sep⟩ + have restart := WP.spec_and (tcb.restart_caller.r2Keep I D P B Y entry.1) (sched.set_thread_state.restartOs P D) + have one (q : S) (Rq : DelR st H Cs OS Vc Ub Ac Ty ia ie s q) + (h : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q) : + cdt.delete_one st ar q a (irqSlotA (L.ksb s) irq) ⦃ r => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r.1 ⦄ := + WP.spec_and (cdt.delete_one.r2 I Rq a hi h.1) (cdt.delete_one.ktUt I Rq a hi h.2) + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + dsimp only + have done : interrupt.decode_irq_handler st ar s a lbl irq extra ⦃ r => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n r.2.1 ⦄ := by + rcases hl with hl | hl + · exact interrupt.decode_irq_handler.clearPhi hl (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n) + (WP.spec_mono restart fun _ ⟨⟨Rq, h⟩, keep⟩ => ⟨Rq, h, sep.keep keep⟩) one + · refine interrupt.decode_irq_handler.setPhi (cap := .IrqHandler irq) I P B hl hi hSC + (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n) entry + (WP.spec_mono restart fun _ ⟨⟨Rq, h⟩, keep⟩ => ⟨Rq, ⟨h, sep.keep keep⟩, keep⟩) one ?_ + intro q x m b send recv h base hm hx hd apart canon stays hw null + exact WP.spec_and (cdt.insert_with_cap.r2 I.del.os I.del.vr base hm hx hd apart canon stays + (fun e => by cases e) hw (fun h => h) (fun h => h) null h.1) + (cdt.insert_with_cap.ktUt I.del.os hm hx hd apart canon stays (fun e => by cases e) hw + (fun _ _ _ _ e => by cases e) h.2) + exact WP.spec_mono done fun r h => by + obtain ⟨_, _, _⟩ := r + exact h + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2KtLevel.lean b/proofs/Fl4ProofsA64/P1/S1aR2KtLevel.lean new file mode 100644 index 000000000..550bdc774 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2KtLevel.lean @@ -0,0 +1,197 @@ +/- +P1 (aarch64, A64-S1A gen 41): R2's levels on the kernel tables and the unreached unmapped HighVSpace roots. + +* `S1aR2.ktLevel`: a reachable kernel table has R2's level `Lv` equal to the column's `KLv` (`S1aHiK`): a reachable + parent of a kernel table is a kernel table, an active HighVSpace header (`o < 4088`), never a user path table + (its children are PageTable-capped, `VsLk.kt`). +* `S1aR2.unmappedRootUnreached`, `S1aR2.unmappedPrivateUnreached`: the root of an unmapped HighVSpace cap and its + private level-1 table are not reachable. + +Named premises: none. New theorems only. +-/ +import Fl4ProofsA64.P1.S1aKtLvCol + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {s : S} + +private theorem nz_of_tag2 {w : U64} (h : w &&& 3#u64 = 2#u64) : w ≠ 0#u64 := by + rintro rfl; cases h + +/-- The cap of an active native entry. -/ +theorem S1aR2.nativeOf (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) {asid raw : U64} + (entry : ActiveAsidRoot st Pp s asid raw) (tag : raw &&& 3#u64 = 0#u64) : + ∃ x ∈ OS, capA st s x = .Pml4 raw true asid := by + obtain ⟨x, hx, cap⟩ := R.core.root.backed asid raw entry + rw [tag, and_not_of raw 3#u64 tag] at cap + rcases cap with ⟨_, h⟩ | ⟨bad, _⟩ | ⟨bad, _⟩ + · exact ⟨x, hx, h⟩ + · cases bad + · cases bad + +/-- The cap of an active HighVSpace entry. -/ +theorem S1aR2.highOf (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) {asid raw : U64} + (entry : ActiveAsidRoot st Pp s asid raw) (tag : raw &&& 3#u64 = 2#u64) : + ∃ x ∈ OS, capA st s x = .HighVSpace (raw &&& ~~~3#u64) true asid := by + obtain ⟨x, hx, cap⟩ := R.core.root.backed asid raw entry + rw [tag] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, h⟩ + · cases bad + · cases bad + · exact ⟨x, hx, h⟩ + +/-- A user path's child below a level-`< 3` table is PageTable-capped, hence not a kernel table. -/ +theorem S1aR2.pathChildNotKt (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {tag asid p o : U64} {sh va : Nat} (stage : tag = 0#u64 ∨ tag = 2#u64) + (walk : S1aPath st Pp n s tag asid sh va p) (lv : Lv p < 3) (ho : o.val < 4096) (al : o.val % 8 = 0) + (edge : (L.mem s (wa p o) &&& 3#u64) = 3#u64) : + wa (L.mem s (wa p o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∉ Kt := by + intro hk + have geom := R.paths.tables _ _ _ _ _ walk + have depth : sh + 9 * Lv p = 39 := by + rcases stage with rfl | rfl <;> exact (show _ ∧ _ from geom).2 + have deep : 12 < sh := by omega + obtain ⟨width, range⟩ := R.routeFacts.stage1Slot stage walk ho al edge + have child := S1aPath.child walk deep width al range edge + have top : sh ≤ s1aTopShift tag n := walk.geometry.2.elim (fun h => h.1.le) (fun h => h.1.le) + obtain ⟨x, hx, va', cap, -⟩ := R.paths.children _ _ _ _ _ child (by omega) + exact R.core.lookup.kt _ hk x hx (Or.inl ⟨true, asid, va', cap⟩) + +/-- **A reachable kernel table has R2's level equal to the column's.** -/ +theorem S1aR2.ktLevel (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (K : S1aHiK st OS Kt KLv s) + {t : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) : t ∈ Kt → Lv t = KLv t := by + induction reach with + | hr bad => exact (Set.notMem_empty _ bad).elim + | root0 hp ho al nz tag => + intro hk + obtain ⟨asid, entry⟩ := ActiveAsidRoot.forWord hp ho al nz + obtain ⟨x, hx, cap⟩ := R.nativeOf entry tag + exact (R.core.lookup.kt _ hk x hx (Or.inr (Or.inl ⟨true, asid, cap⟩))).elim + | root2 hp ho al tag => + intro hk + obtain ⟨asid, entry⟩ := ActiveAsidRoot.forWord hp ho al (nz_of_tag2 tag) + obtain ⟨x, hx, cap⟩ := R.highOf entry tag + exact (R.core.lookup.kt _ hk x hx (Or.inr (Or.inr (Or.inl ⟨true, asid, cap⟩)))).elim + | @step p o hpr lv ho al edge ih => + intro hk + have desc := R.core.stage1.desc p (R.core.stage1.reachableMember hpr) hpr lv o ho al edge + rcases R.classifyStage1 hpr with kt | ⟨raw, asid, entry, kind, rfl⟩ | ⟨tag, asid, sh, va, stage, walk⟩ + · have e := ih kt + have k := (K.kt p kt (by omega) o ho al edge).2 + unfold kChild at k + omega + · obtain ⟨x, hx, cap⟩ := R.highOf entry kind + have member : (raw &&& ~~~3#u64) ∈ Hr := by rw [R.highRoots]; exact ⟨x, hx, true, asid, cap⟩ + have zero := R.place.high.lv _ member + by_cases off : o.val < 4088 + · have k := (K.hdr x hx _ true asid cap o off al edge).2 + unfold kChild at k + omega + · have last : o = 4088#u64 := UScalar.eq_of_val_eq (by change o.val = 4088; omega) + subst last + rw [R.highLink _ member] at hk + exact (R.core.lookup.kt _ hk x hx (Or.inr (Or.inr (Or.inr (Or.inl ⟨_, true, asid, cap, rfl⟩))))).elim + · exact (R.pathChildNotKt stage walk lv ho al edge hk).elim + +/-- An unmapped and a mapped HighVSpace cap never share a root. -/ +theorem S1aR2.unmappedNotMapped (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {x y r a a' : U64} (hx : x ∈ OS) (hy : y ∈ OS) (cx : capA st s x = .HighVSpace r true a') + (cy : capA st s y = .HighVSpace r false a) : False := by + have e := R.capRefs.references x hx y hy (3, r) (by rw [cx]; rfl) (by rw [cy]; rfl) + rw [cx, cy] at e + cases e + +private theorem hv_al (heap : HeapOK H) {r : U64} (h : H r = some (.other 13)) : + r.val % 8192 = 0 ∧ r.val + 8192 ≤ 2 ^ 64 := by + have a := heap.align r _ h + have f := heap.fits r _ h + simp only [HKind.bits] at a f + norm_num at a f + exact ⟨a, by omega⟩ + +private theorem wa4096 {r : U64} (f : r.val + 8192 ≤ 2 ^ 64) : (wa r 4096#u64).val = r.val + 4096 := by + have h4 : (4096#u64 : U64).val = 4096 := by simp + rw [wadd_val (by rw [h4]; omega), h4] + +/-- An 8 KiB object's second granule is no 8 KiB object. -/ +theorem second_not_hv (heap : HeapOK H) {r q : U64} (hr : H r = some (.other 13)) (hq : H q = some (.other 13)) + (e : wa r 4096#u64 = q) : False := by + obtain ⟨ar, fr⟩ := hv_al heap hr + obtain ⟨aq, _⟩ := hv_al heap hq + have v := congrArg UScalar.val e + rw [wa4096 fr] at v + omega + +/-- **The root of an unmapped HighVSpace cap is not reachable.** -/ +theorem S1aR2.unmappedRootUnreached (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + {y r a : U64} (hy : y ∈ OS) (cap : capA st s y = .HighVSpace r false a) : + ¬ VsReach st (PoolSet st Pp s) ∅ Lv s r := by + intro reach + have obj := R.highObjects y hy r false a cap + rcases R.classifyStage1 reach with kt | ⟨raw, asid, entry, kind, e⟩ | ⟨tag, asid, sh, va, stage, walk⟩ + · exact R.core.lookup.kt _ kt y hy (Or.inr (Or.inr (Or.inl ⟨false, a, cap⟩))) + · obtain ⟨x, hx, c⟩ := R.highOf entry kind + rw [← e] at c + exact R.unmappedNotMapped hx hy c cap + · rcases Nat.lt_or_ge sh (s1aTopShift tag n) with below | atTop + · obtain ⟨x, hx, va', c, -⟩ := R.paths.children _ _ _ _ _ walk below + have pt : H r = some (.other 12) := R.pageObjects x hx r true asid va' c + rw [obj] at pt; cases pt + · cases walk with + | @native _ raw entry kind => + obtain ⟨x, hx, c⟩ := R.nativeOf entry kind + have pt := (R.nativeRoots x hx _ true _ c).1 + rw [obj] at pt; cases pt + | @high _ raw entry kind edge => + obtain ⟨x, hx, c⟩ := R.highOf entry kind + have member : (raw &&& ~~~3#u64) ∈ Hr := by rw [R.highRoots]; exact ⟨x, hx, true, _, c⟩ + exact second_not_hv heap (R.highObjects x hx _ true _ c) obj (R.highLink _ member).symm + | stage2 => rcases stage with z | z <;> exact absurd z (by decide) + | @child _ _ _ _ psh _ parent deep _ _ _ _ => + have := parent.geometry.2.elim (fun h => h.1.le) (fun h => h.1.le) + omega + +/-- **The private level-1 table of an unmapped HighVSpace cap is not reachable.** -/ +theorem S1aR2.unmappedPrivateUnreached (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + {y r a : U64} (hy : y ∈ OS) (cap : capA st s y = .HighVSpace r false a) : + ¬ VsReach st (PoolSet st Pp s) ∅ Lv s (wa r 4096#u64) := by + intro reach + have obj := R.highObjects y hy r false a cap + rcases R.classifyStage1 reach with kt | ⟨raw, asid, entry, kind, e⟩ | ⟨tag, asid, sh, va, stage, walk⟩ + · exact R.core.lookup.kt _ kt y hy (Or.inr (Or.inr (Or.inr (Or.inl ⟨r, false, a, cap, rfl⟩)))) + · obtain ⟨x, hx, c⟩ := R.highOf entry kind + exact second_not_hv heap obj (R.highObjects x hx _ true asid c) e + · rcases Nat.lt_or_ge sh (s1aTopShift tag n) with below | atTop + · obtain ⟨x, hx, va', c, -⟩ := R.paths.children _ _ _ _ _ walk below + exact R.highObjects.second_ne heap hy cap (R.pageObjects x hx _ true asid va' c) rfl + · obtain ⟨t, ht⟩ : ∃ t, t = wa r 4096#u64 := ⟨_, rfl⟩ + rw [← ht] at walk + cases walk with + | @native _ raw entry kind => + obtain ⟨x, hx, c⟩ := R.nativeOf entry kind + exact R.highObjects.second_ne heap hy cap (R.nativeRoots x hx _ true _ c).1 ht.symm + | @high _ raw entry kind edge => + obtain ⟨x, hx, c⟩ := R.highOf entry kind + have member : (raw &&& ~~~3#u64) ∈ Hr := by rw [R.highRoots]; exact ⟨x, hx, true, _, c⟩ + rw [R.highLink _ member] at ht + have fr := (hv_al heap obj).2 + have fq := (hv_al heap (R.highObjects x hx _ true _ c)).2 + have same : (raw &&& ~~~3#u64) = r := by + apply UScalar.eq_of_val_eq + have v := congrArg UScalar.val ht + rw [wa4096 fq, wa4096 fr] at v + omega + rw [same] at c + exact R.unmappedNotMapped hx hy c cap + | stage2 => rcases stage with z | z <;> exact absurd z (by decide) + | @child _ _ _ _ psh _ parent deep _ _ _ _ => + have := parent.geometry.2.elim (fun h => h.1.le) (fun h => h.1.le) + omega + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Loop.lean b/proofs/Fl4ProofsA64/P1/S1aR2Loop.lean new file mode 100644 index 000000000..9b047f898 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Loop.lean @@ -0,0 +1,99 @@ +/- +P1 (aarch64): the R2 invariant and pending predicate of the deletion loops (A64-S1A gen 41). + +`S1aDelM` is R2 with `Hr` read off the live HighVSpace capabilities; `S1aDelPn s x` is the same over the +slots other than `x` (`LoopMP.Pn`: slot `x` has been finalised and `empty_slot` comes next). The lemmas here +are the loop steps that do not depend on the finalised capability. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Del +import Fl4ProofsA64.P1.S1aR2Slots + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n x : U64} {s r : S} + +/-- R2 with the HighVSpace set read off the slots. -/ +def S1aDelM (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt Pp Tb Te Kt : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (s : S) : Prop := + S1aR2 st H OS Pt Pp Tb (HvRt st OS s) Te Kt Lv Re bits n s + +/-- R2 over the slots other than the finalised slot `x`. -/ +def S1aDelPn (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt Pp Tb Te Kt : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (s : S) (x : U64) : Prop := + S1aDelM st H (OS \ {x}) Pt Pp Tb Te Kt Lv Re bits n s + +theorem S1aR2.toDelM (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s := by + unfold S1aDelM + rwa [← h.highRoots] + +/-- A slot whose capability R2 does not read may be left out. -/ +theorem S1aDelM.drop (h : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s) (unread : ¬ S1aR2Reads (capA st s x)) : + S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n s x := + (S1aR2.congrSlots (O' := OS \ {x}) h (fun _ hy _ => hy.1) + (fun y hy reads => ⟨y, ⟨hy, fun same => unread (Set.mem_singleton_iff.1 same ▸ reads)⟩, rfl⟩)).toDelM + +/-- The capability at a slot is the same, or R2 reads neither the old nor the new one. -/ +def S1aCapSame (st : machine.Store S) [L : LawfulStore st] (s r : S) (y : U64) : Prop := + capA st r y = capA st s y ∨ (¬ S1aR2Reads (capA st s y) ∧ ¬ S1aR2Reads (capA st r y)) + +/-- A post keeping the VSpace words and every capability R2 reads keeps `M`. -/ +theorem S1aDelM.keep (h : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s) + (base : L.ksb r = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s r) (caps : ∀ y ∈ OS, S1aCapSame st s r y) : + S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n r := by + have same : ∀ y ∈ {y | y ∈ OS ∧ capA st r y = capA st s y}, capA st r y = capA st s y := fun _ hy => hy.2 + have unchanged {y : U64} (hy : y ∈ OS) (ne : capA st r y ≠ capA st s y) : + ¬ S1aR2Reads (capA st s y) ∧ ¬ S1aR2Reads (capA st r y) := (caps y hy).resolve_left ne + have narrow := (S1aR2.congrSlots (O' := {y | y ∈ OS ∧ capA st r y = capA st s y}) h (fun _ hy _ => hy.1) + (fun y hy reads => ⟨y, ⟨hy, by_contra fun ne => (unchanged hy ne).1 reads⟩, rfl⟩)).toDelM + have moved : S1aDelM st H {y | y ∈ OS ∧ capA st r y = capA st s y} Pt Pp Tb Te Kt Lv Re bits n r := + (S1aR2.permute narrow base mem id (fun _ hy => hy) same (fun _ _ _ _ e => e) + (fun y hy => ⟨y, hy, rfl⟩)).toDelM + exact (S1aR2.congrSlots (O' := OS) moved + (fun y hy reads => ⟨hy, by_contra fun ne => (unchanged hy ne).2 reads⟩) (fun y hy _ => ⟨y, hy.1, rfl⟩)).toDelM + +/-- Once the pending slot holds a capability R2 does not read, `M` holds again. -/ +theorem S1aDelPn.restore (h : S1aDelPn st H OS Pt Pp Tb Te Kt Lv Re bits n s x) + (base : L.ksb r = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s r) + (other : ∀ y ∈ OS, y ≠ x → S1aCapSame st s r y) (unread : ¬ S1aR2Reads (capA st r x)) : + S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n r := by + have kept : S1aDelM st H (OS \ {x}) Pt Pp Tb Te Kt Lv Re bits n r := + S1aDelM.keep h base mem (fun y hy => other y hy.1 hy.2) + exact (S1aR2.congrSlots (O' := OS) kept + (fun y hy reads => ⟨hy, fun same => unread (Set.mem_singleton_iff.1 same ▸ reads)⟩) + (fun y hy _ => ⟨y, hy.1, rfl⟩)).toDelM + +/-- `cap_swap_for_delete` keeps `M`. -/ +theorem S1aDelM.swap (h : S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n s) {p y : U64} (hp : p ∈ OS) (hy : y ∈ OS) + (base : L.ksb r = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s r) + (first : capA st r p = capA st s y) (second : capA st r y = capA st s p) + (other : ∀ z ∈ OS, z ≠ p → z ≠ y → capA st r z = capA st s z) : + S1aDelM st H OS Pt Pp Tb Te Kt Lv Re bits n r := by + refine (S1aR2.permute h base mem (Equiv.swap p y) (fun z hz => ?_) (fun z hz => ?_) + (fun _ _ _ _ same => (Equiv.swap p y).injective same) (fun z hz => ?_)).toDelM + · rw [Equiv.swap_apply_def] + split + · exact hy + split + · exact hp + exact hz + · rw [Equiv.swap_apply_def] + split + · rename_i e; rw [e]; exact first + split + · rename_i e; rw [e]; exact second + rename_i a b + exact other z hz a b + · refine ⟨Equiv.swap p y z, ?_, Equiv.swap_apply_self p y z⟩ + rw [Equiv.swap_apply_def] + split + · exact hy + split + · exact hp + exact hz + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MakePool.lean b/proofs/Fl4ProofsA64/P1/S1aR2MakePool.lean new file mode 100644 index 000000000..a0bdb671f --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MakePool.lean @@ -0,0 +1,187 @@ +/- +P1 (aarch64): full R2 at the concrete ASIDControl MakePool dispatcher, on the returned heap and slots. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2AddPool +import Fl4ProofsA64.P1.MdbPoolA +import Fl4ProofsA64.P1.S1aKtUt + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} + +set_option maxHeartbeats 4000000 in +/-- MakePool keeps R2 and the separation, with the pool end named (the arm's source, slot and pool post). -/ +theorem syscall.decode_invocation.makePoolEndR2 {U Ac Vc Ub : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s .AsidControl 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) (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (covered : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) (hks : HeapKsOff H (L.ksb s)) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (a : A) {lbl : U64} (label : lbl = fl4_abi.label.ARMASIDControlMakePool) (len : 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 ∧ + 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 → + capA st q y = capA st s y ∨ ∃ p' b' i' d', capA st q y = .Untyped p' b' i' d') ∧ + 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 ∧ + 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, + E, kept, sourceAfter, sourceKept, empty⟩) + · change q = s at same + subst q + exact Or.inl ⟨rfl, h, sep⟩ + have page : sb.val = 12 := by rw [size]; first | rfl | decide | simp [fl4_abi.consts.bits.ASID_POOL] + have width : (2 : Nat) ^ sb.val = 4096 := by rw [page]; norm_num + have region := B.sys.ur.rin hx source + have drop {t : U64} {k : HKind} (obj : (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) t = some k) : + ¬ RegionD H p.val (p.val + 2 ^ sb.val) t ∧ H t = some k := Heap.drop_eq_some.1 obj + have outside {t : U64} {k : HKind} (obj : (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) t = some k) : + t.val + 2 ^ k.bits ≤ p.val ∨ p.val + 4096 ≤ t.val := by + obtain ⟨away, found⟩ := drop obj + by_contra overlap + apply away + unfold RegionD MeetsR + rw [found] + change ¬ (t.val + 2 ^ k.bits ≤ p.val ∨ p.val + 2 ^ sb.val ≤ t.val) + rw [width] + exact overlap + have survive : ∀ t k, H t = some k → + (t ∈ Kt ∨ ∃ y ∈ OS, RngKeyA (capA st s y) ∧ ptrA (capA st s y) = t) → + (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) t = some k := by + intro t k obj held + refine Heap.drop_eq_some.2 ⟨fun meets => ?_, obj⟩ + obtain ⟨above, below⟩ := RegionD.inside region obj meets + have positive := Nat.two_pow_pos k.bits + rcases held with kernel | held + · have off := sep t kernel x hx p sb fi false source + have table := h.kernelTables.2 t kernel + rw [obj] at table + obtain rfl := Option.some.inj table + change p.val + 2 ^ sb.val ≥ t.val + 4096 at below + omega + · obtain ⟨y, hy, key, ptr⟩ := held + obtain ⟨G, par, tree, _, _⟩ := B.sys.stz.1.1.tree + have off := cdt.ensure_no_children.noKey P.os tree.utRangeOrd B.sys.stz.1.2.1 hx source childless y hy key + rw [ptr] at off + exact off ⟨above, by omega⟩ + have nonnull : ∀ y ∈ OS, capA st s y ≠ .Null → y ∈ OffR p.val (p.val + 2 ^ sb.val) OS := by + intro y hy live + by_cases first : y = x + · exact first.symm ▸ sourceKept + by_cases second : y = v + · exact second.symm ▸ post.vR + exact (post.kept y hy first second live).1 + have restriction : S1aRestrict st H (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) OS + (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 => + 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) + 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 + (OffR p.val (p.val + 2 ^ sb.val) OS) ia ie q := E.1 + obtain ⟨_, _, _, kindsAfter, _, _⟩ := after.sys.stz.1.1.mdbS + have positive : 0 < p.val := B.ly.ut0 x hx p sb fi source + have separated : ∀ b, PtW (s1aKeptPt (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) Pt) b → L.mem q b = L.mem s b := by + rintro b ⟨t, ⟨member, placed⟩, o, bound, al, rfl⟩ + have notAs : ¬ AsW (L.ksb s) (wa t o) := + HeapKsOff.ptAsWG hks h.footprint B.ly.ksw (h.footprint.fit P.heap) _ ⟨t, member, o, bound, al, rfl⟩ + rcases post.vs Vc Ub Pt vr _ (Or.inl ⟨t, member, o, bound, al, rfl⟩) with same | inside | table + · exact same + · obtain ⟨_, base', z, obj, start, finish⟩ := placed t rfl + have off := outside obj + have fit := P.heap.fits base' _ (drop obj).2 + change base'.val + 2 ^ z ≤ 2 ^ 64 at fit + change base'.val + 2 ^ z ≤ p.val ∨ p.val + 4096 ≤ base'.val at off + have value : (wa t o).val = t.val + o.val := wadd_val (by omega) + omega + · exact (notAs (table ▸ asW_at (L.ksb s) i)).elim + have added : S1aPoolAdded st (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) + (OffR p.val (p.val + 2 ^ sb.val) OS) (s1aKeptPt (H.drop (RegionD H p.val (p.val + 2 ^ sb.val))) Pt) + s q x v p sb fi base i := by + refine { + before := restriction.heapOK + after := post.heap + page := page + off := fun t k obj => outside obj + nonzero := fun zero => by rw [zero] at positive; exact (by decide : ¬ 0 < (0#u64 : U64).val) positive + ksb := post.ksb + index := small + low := low + free := free + written := post.tabI + table := post.tab + words := separated + zero := fun o bound al => ?_ + source := source + sourceAfter := sourceAfter + empty := empty + published := post.capV + target := post.vR + other := kept } + have align := post.heap.align p (.other sb.val) (Heap.add_eq_some.2 (Or.inl ⟨rfl, rfl⟩)) + have fit := post.heap.fits p (.other sb.val) (Heap.add_eq_some.2 (Or.inl ⟨rfl, rfl⟩)) + change p.val % 2 ^ sb.val = 0 at align + change p.val + 2 ^ sb.val ≤ 2 ^ 64 at fit + rw [width] at align fit + have value : (wa p o).val = p.val + o.val := wadd_val (by omega) + exact post.zr _ (by unfold Aligned; rw [value]; omega) (by rw [value]; omega) (by rw [value, width]; omega) + have final := shrunk.addPool added kindsAfter after.sys.fr + have others : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st q y = capA st s y ∨ ∃ p' b' i' d', capA st q y = .Untyped p' b' i' d' := fun y hy second => by + 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, ?_⟩ + intro t member u hu p' b' i' d' cap + by_cases first : u = x + · rw [first, sourceAfter] at cap + cases cap + exact sep t member x hx p sb fi false source + by_cases second : u = v + · rw [second, post.capV] at cap + cases cap + rw [kept u hu first second] at cap + exact sep t member u hu.1 p' b' i' d' cap + +set_option maxHeartbeats 4000000 in +/-- MakePool returns R2 and the kernel-table separation on every outcome. The success post is over +the pool heap and the slots outside the consumed region, with the new page in both ghost sets. -/ +theorem syscall.decode_invocation.makePoolExactR2 {U Ac Vc Ub : Set U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s .AsidControl 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) (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (covered : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) (hks : HeapKsOff H (L.ksb s)) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (a : A) {lbl : U64} (label : lbl = fl4_abi.label.ARMASIDControlMakePool) (len : 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) ∨ + ∃ (H' : Heap) (OS' Pt' Pp' Tb' Te' : Set U64), ArmQIEnd st H Cs OS Vc ia ie s H' OS' q ∧ + 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⟩) + · exact Or.inl same + · exact Or.inr ⟨_, _, _, _, _, _, E, final, kt⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapBacking.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapBacking.lean new file mode 100644 index 000000000..4ce01dbf9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapBacking.lean @@ -0,0 +1,118 @@ +/- +P1 (aarch64): backing of exact active paths after PageTable Map. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapPaths + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {slot addr word tag asid ptr saved : U64} {level va : Nat} + +private theorem widthPos (tag n : U64) (level : Nat) : 0 < s1aTableWidth tag n level := by + unfold s1aTableWidth + split + · split + · positivity + · split <;> decide + · decide + +/-- An unmapped PageTable's object is distinct from every old active walk table. -/ +theorem S1aR2.pathNeUnmapped (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) {x a v k id t : U64} {ℓ base : Nat} (hx : x ∈ OS) + (cap : capA st s x = .PageTable ptr false a v) + (path : S1aPath st Pp n s k id ℓ base t) : t ≠ ptr := by + have bound : (0#u64 : U64).val < s1aTableWidth k n ℓ := widthPos k n ℓ + obtain ⟨y, hy, p, d, z, obj, _, span, addr, map, _⟩ := h.pathWordObject path bound + have unmapped : UnmCap (capA st s x) ptr 4096 := Or.inl ⟨rfl, a, v, cap⟩ + have ne : p ≠ ptr := fun e => h.core.lookup.ex x hx y hy ptr 4096 unmapped (e ▸ map) + intro e + have different := tableWordsNe heap obj (h.pageObjects x hx ptr false a v cap) ne span + (by decide : (0#u64 : U64).val < 2 ^ 12) + exact different (addr.symm.trans (congrArg (wa · 0#u64) e)) + +set_option maxHeartbeats 3800000 in +/-- The PageTable Map adds the new table at the selected level. All prior +child-cap and frame-leaf backing survives. -/ +theorem S1aTablePaths.backing {oldAsid oldVa : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (member : slot ∈ OS) (before : capA st s slot = .PageTable ptr false oldAsid oldVa) + (atSlot : S1aSlotAt st Pp n s tag asid va level addr) + (deep : 12 < level) (tagged : word &&& 3#u64 = 3#u64) + (write : S1aMapWrite st OS Pt s q slot addr word (.PageTable ptr true asid saved)) + (paths : S1aTablePaths st Pp n s q tag asid (level - 9) (s1aCapAddress tag n saved) ptr) : + let Tb' := if tag = 1#u64 then Tb else insert ptr Tb + let Lv' := if tag = 1#u64 then Lv else Function.update Lv ptr ((39 - level) / 9 + 1) + let Te' := if tag = 1#u64 then insert ptr Te else Te + let Re' := if tag = 1#u64 then Function.update Re ptr ((level - 12) / 9 - 1) else Re + let bits' := if tag = 1#u64 then Function.update bits ptr 12 else bits + S1aPathBacking st H OS Pp Tb' Te' Lv' Re' bits' n q := by + dsimp only + obtain ⟨t, base, o, chosen, below, aligned, position, _, _, _⟩ := atSlot.entry + have levels := atSlot.levels + have within : level - 9 < s1aTopShift tag n := by + have top := chosen.geometry.2.elim (fun e => e.1.le) (fun e => e.1.le) + omega + have newWidth : s1aTableWidth tag n (level - 9) = 4096 := by + rw [s1aTableWidth, if_neg (Nat.ne_of_lt within)] + refine ⟨?_, ?_, ?_⟩ + · intro k a ℓ b p path + rcases paths.classify k a ℓ b p path with old | ⟨rfl, rfl, rfl, rfl, rfl⟩ + · have different := h.pathNeUnmapped heap member before old + have prior := h.paths.tables k a ℓ b p old + by_cases stage : k = 1#u64 <;> by_cases editStage : tag = 1#u64 <;> + simp only [stage, editStage, if_true, if_false, Function.update_of_ne different] at prior ⊢ + · exact ⟨Set.mem_insert_of_mem _ prior.1, prior.2⟩ + · exact prior + · exact prior + · exact ⟨Set.mem_insert_of_mem _ prior.1, prior.2⟩ + · by_cases stage : k = 1#u64 + · have width1 := newWidth + rw [stage] at width1 + simp only [stage, if_true, Function.update_self, Set.mem_insert_iff, true_or, true_and, width1] + refine ⟨?_, by decide⟩ + rcases levels with e | e | e | e <;> omega + · simp only [stage, if_false, Function.update_self, Set.mem_insert_iff, true_or, true_and] + rcases levels with e | e | e | e <;> omega + · intro k a ℓ b p path belowTop + rcases paths.classify k a ℓ b p path with old | ⟨rfl, rfl, rfl, rfl, rfl⟩ + · obtain ⟨x, hx, va, cap, ref⟩ := h.paths.children k a ℓ b p old belowTop + have other : x ≠ slot := by + rintro rfl + rw [before] at cap + cases cap + exact ⟨x, hx, va, (write.other x hx other).trans cap, ref⟩ + · exact ⟨slot, member, saved, write.cap, rfl⟩ + · intro k a ℓ b p path i width al range valid + rcases paths.classify k a ℓ b p path with old | ⟨rfl, rfl, rfl, rfl, rfl⟩ + · have different : wa p i ≠ addr := by + intro atEdit + have same := h.samePathWord heap kinds old chosen width below (atEdit.trans position) + rw [atEdit, write.descriptor, same.2.2.1] at valid + rcases valid with ⟨e, _⟩ | ⟨_, e⟩ + · omega + · rw [tagged] at e + exact (by decide : (3#u64 : U64) ≠ 1#u64) e + have keep := write.memory _ (Or.inl (h.pathWord old width al)) different + rw [keep] at valid ⊢ + obtain ⟨x, hx, size, rights, dev, saved, shift, cap, ref, obj⟩ := + h.paths.leaves k a ℓ b p old i width al range valid + have other : x ≠ slot := by + rintro rfl + rw [before] at cap + cases cap + exact ⟨x, hx, size, rights, dev, saved, shift, (write.other x hx other).trans cap, ref, obj⟩ + · rw [newWidth] at width + rw [paths.empty i width al] at valid + rcases valid with ⟨_, e⟩ | ⟨_, e⟩ + · exact ((by decide : (0#u64 &&& 3#u64) ≠ 3#u64) e).elim + · exact ((by decide : (0#u64 &&& 3#u64) ≠ 1#u64) e).elim + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapCaps.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapCaps.lean new file mode 100644 index 000000000..a512b89af --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapCaps.lean @@ -0,0 +1,100 @@ +/- +P1 (aarch64): exact cap and unmapped-object preservation through PageTable Map. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapRootSlots + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {slot addr word tag asid ptr vaSaved : U64} {level va : Nat} + +/-- A PageTable Map changes metadata at the invoked slot while keeping every +table-cap key and every other slot. -/ +theorem S1aMapWrite.tableKeys {oldAsid oldVa : U64} + (before : capA st s slot = .PageTable ptr false oldAsid oldVa) + (write : S1aMapWrite st OS Pt s q slot addr word (.PageTable ptr true asid vaSaved)) : + ∀ x ∈ OS, s1aTableKey (capA st q x) = s1aTableKey (capA st s x) := by + intro x hx + by_cases same : x = slot + · rw [same, write.cap, before] + rfl + · rw [write.other x hx same] + +/-- A previously unmapped PageTable had a unique cap, so publishing it +preserves exact cap-reference agreement and the uniqueness of other unmapped caps. -/ +theorem S1aMapWrite.tableCaps {oldAsid oldVa : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (member : slot ∈ OS) (before : capA st s slot = .PageTable ptr false oldAsid oldVa) + (write : S1aMapWrite st OS Pt s q slot addr word (.PageTable ptr true asid vaSaved)) : + S1aTableCaps st OS q := by + have keys := write.tableKeys before + have sameSlot (x : U64) (hx : x ∈ OS) (key : s1aTableKey (capA st q x) = some (0, ptr)) : x = slot := + h.capRefs.unique slot member x hx _ (by rw [before]; rfl) ((keys x hx).symm.trans key) (by rw [before]; rfl) + obtain ⟨native, high⟩ := write.emptyRoots h heap kinds path + refine ⟨?_, ?_, native, high⟩ + · intro x hx y hy k cx cy + by_cases eq : x = slot + · have key : k = (0, ptr) := by rw [eq, write.cap] at cx; exact (Option.some.inj cx).symm + rw [key] at cy + rw [eq, sameSlot y hy cy] + · by_cases same : y = slot + · have key : k = (0, ptr) := by rw [same, write.cap] at cy; exact (Option.some.inj cy).symm + rw [key] at cx + exact (eq (sameSlot x hx cx)).elim + · rw [write.other x hx eq, write.other y hy same] + exact h.capRefs.references x hx y hy k ((keys x hx).symm.trans cx) ((keys y hy).symm.trans cy) + · intro x hx y hy k cx cy empty + by_cases eq : x = slot + · rw [eq, write.cap] at empty + cases empty + · by_cases same : y = slot + · have key : k = (0, ptr) := by rw [same, write.cap] at cy; exact (Option.some.inj cy).symm + rw [key] at cx + exact (eq (sameSlot x hx cx)).elim + · rw [write.other x hx eq] at empty + exact h.capRefs.unique x hx y hy k ((keys x hx).symm.trans cx) ((keys y hy).symm.trans cy) empty + +/-- A Map in the active user window preserves every word of an unmapped +object whose cap survives. -/ +theorem S1aMapWrite.keepUnmappedWordOfWrite {written : capability.Cap} {x p o : U64} {size : Nat} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (write : S1aMapWrite st OS Pt s q slot addr word written) + (hx : x ∈ OS) (cap : UnmCap (capA st s x) p size) + (bound : o.val < size) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) := by + obtain ⟨z, span, object⟩ := h.core.lookup.vh.1 x hx p size cap + have loc : PtW Pt (wa p o) := by + rcases cap with ⟨rfl, a, v, e⟩ | ⟨rfl, a, v, e⟩ + · exact ⟨p, h.pageTables x hx p false a v e, o, bound, al, rfl⟩ + · have words : PtWb {p} (fun _ => 13) (wa p o) := + ⟨p, Set.mem_singleton p, o, bound, al, rfl⟩ + exact ptw_mono (h.eptRoots x hx p 0#u64 false a v e).2 (ptwb_gran (fun _ _ => Or.inr rfl) words) + obtain ⟨t, base, off, walk, width, _, position, _, _, _⟩ := path.entry + obtain ⟨y, hy, owner, delta, z', obj, _, limit, atWord, backed, _⟩ := h.pathWordObject walk width + have apart : p ≠ owner := fun e => h.core.lookup.ex x hx y hy p size cap (e.symm ▸ backed) + have different : wa p o ≠ addr := by + rw [position, atWord] + exact tableWordsNe heap object obj apart (span ▸ bound) limit + exact write.memory _ (Or.inl loc) different + +/-- A PageTable Map keeps the words of objects that remain unmapped. -/ +theorem S1aMapWrite.keepUnmappedWord {x p o : U64} {size : Nat} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (write : S1aMapWrite st OS Pt s q slot addr word (.PageTable ptr true asid vaSaved)) + (hx : x ∈ OS) (cap : UnmCap (capA st s x) p size) + (bound : o.val < size) (al : o.val % 8 = 0) : + L.mem q (wa p o) = L.mem s (wa p o) := + write.keepUnmappedWordOfWrite h heap path hx cap bound al + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapDispatch.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapDispatch.lean new file mode 100644 index 000000000..fcf8fd1fa --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapDispatch.lean @@ -0,0 +1,76 @@ +/- +P1 (aarch64): full R2 through the PageTable Map syscall decoder. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapPost + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Cs Vc Ub U Ac Rp Nt : Set U64} {Lv Re bits : U64 → Nat} + {s : S} {slot ptr oldAsid oldVa : U64} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +/-- A PageTable Map on an already mapped cap is rejected before a state write. -/ +theorem vspace.decode_page_table.mapMappedKeeps (a : A) (len buf : U64) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableMap len slot + (.PageTable ptr true oldAsid oldVa) buf extra ⦃ r => r.2.1 = s ⦄ := by + have different : fl4_abi.label.ARMPageTableMap ≠ fl4_abi.label.ARMPageTableUnmap := lbl_ne_of_val + (by simp [fl4_abi.label.ARMPageTableMap, fl4_abi.label.ARMPageTableUnmap]) + unfold vspace.decode_page_table + rw [cur_thread_ok, bind_ok] + dsimp only + have same : (fl4_abi.label.ARMPageTableMap != fl4_abi.label.ARMPageTableMap) = false := by simp + simp only [different, same, Bool.false_eq_true, ↓reduceIte] + refine WP.spec_bind (P0.vspace.extra.p0 extra 0#usize) fun x _ => ?_ + rcases x with _ | x + · simp only [error.truncated, bind_ok] + exact (WP.spec_ok _).2 rfl + try dsimp only + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · simp only [error.invalid_cap, bind_ok] + exact (WP.spec_ok _).2 rfl + · simp only [error.truncated, bind_ok] + exact (WP.spec_ok _).2 rfl + +/-- Every PageTable Map branch returns R2 on the same heap, cap slots, and +footprint. On success only the selected stage's table witnesses grow. -/ +theorem syscall.decode_invocation.pageTableMapExactR2 (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + {mapped : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.PageTable ptr mapped oldAsid oldVa) extra) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr mapped oldAsid oldVa)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableMap len slot + (.PageTable ptr mapped oldAsid oldVa) blk call don fp buf extra ⦃ _ q _ => + ∃ Tb' Te' Lv' Re' bits', S1aR2 st H OS Pt Pp Tb' Hr Te' Kt Lv' Re' bits' hPl.ipa q ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + cases mapped + · have old := okinj ((capA_eq s slot).symm.trans cap) + have al := (h.footprint ptr (h.pageTables slot P.src ptr false oldAsid oldVa old)).1 + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + refine WP.spec_mono (vspace.decode_page_table.mapExactEffect hPl h vr P D (canon_pt cap) al a len buf) ?_ + rintro ⟨_, q, _⟩ (eq | ⟨tag, event⟩) + · change q = s at eq + subst q + exact ⟨Tb, Te, Lv, Re, bits, h⟩ + · exact h.ofTableMap P.heap kinds ptKs P.src old event + · refine WP.spec_mono (vspace.decode_page_table.mapMappedKeeps (st := st) (ar := ar) + (s := s) (slot := slot) (ptr := ptr) (oldAsid := oldAsid) (oldVa := oldVa) (extra := extra) a len buf) ?_ + rintro ⟨_, q, _⟩ eq + change q = s at eq + subst q + exact ⟨Tb, Te, Lv, Re, bits, h⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapGrow.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapGrow.lean new file mode 100644 index 000000000..dc8f72f1f --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapGrow.lean @@ -0,0 +1,122 @@ +/- +P1 (aarch64): placement of the one table inserted by PageTable Map. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapCaps + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} + {slot ptr ad va : U64} + +private theorem liveHighObject (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {r : U64} (live : r ∈ Hr) : H r = some (.other 13) := by + rw [h.highRoots] at live + obtain ⟨x, hx, mapped, asid, cap⟩ := live + exact h.highObjects x hx r mapped asid cap + +private theorem pageOffHighHeader (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (member : slot ∈ OS) (cap : capA st s slot = .PageTable ptr false ad va) + {root o : U64} (live : root ∈ Hr) (width : o.val < 4096) : wa ptr o ≠ wa root 4088#u64 := by + have page := h.pageObjects slot member ptr false ad va cap + have high := liveHighObject h live + have ne : ptr ≠ root := by + rintro rfl + rw [page] at high + cases high + exact tableWordsNe heap page high ne width (by decide) + +set_option maxHeartbeats 2100000 in +/-- The new Stage-1 child is in the shared footprint and off every HighVSpace header. -/ +theorem S1aR2.growStage1Place (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (member : slot ∈ OS) (cap : capA st s slot = .PageTable ptr false ad va) + (depth : Nat) : + S1aR2Place Pt (PoolSet st Pp s) (insert ptr Tb) Hr Te (Function.update Lv ptr depth) bits (L.ksb s) := by + have page := h.pageObjects slot member ptr false ad va cap + have placed := h.pageTables slot member ptr false ad va cap + refine ⟨h.place.pools, ?_, h.place.granules, ?_, h.place.stage2⟩ + · intro t ht + rcases Set.mem_insert_iff.mp ht with rfl | prior + · exact placed + · exact h.place.tables prior + · refine ⟨(fun r hr => Set.mem_insert_of_mem _ (h.place.high.sub hr)), ?_, ?_, h.place.high.pp, h.place.high.asw⟩ + · intro r hr + have ne : r ≠ ptr := by + rintro rfl + have high := liveHighObject h hr + rw [page] at high + cases high + rw [Function.update_of_ne ne] + exact h.place.high.lv r hr + · intro t ht o bound al r hr eq + rcases Set.mem_insert_iff.mp ht with rfl | prior + · exact (pageOffHighHeader h heap member cap hr bound eq).elim + · exact h.place.high.tb t prior o bound al r hr eq + +set_option maxHeartbeats 2400000 in +/-- The Stage-2 child adds one 4 KiB object within the shared footprint. -/ +theorem S1aR2.growStage2Place (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (member : slot ∈ OS) (cap : capA st s slot = .PageTable ptr false ad va) : + S1aR2Place Pt (PoolSet st Pp s) Tb Hr (insert ptr Te) Lv (Function.update bits ptr 12) (L.ksb s) := by + have placed := h.pageTables slot member ptr false ad va cap + refine ⟨h.place.pools, h.place.tables, ?_, h.place.high, ?_⟩ + · rintro g ⟨p, hp, here | ⟨size, next⟩⟩ + · by_cases eq : p = ptr + · rw [here, eq] + exact placed + · rw [here] + exact h.place.granules ⟨p, (Set.mem_insert_iff.mp hp).resolve_left eq, Or.inl rfl⟩ + · by_cases eq : p = ptr + · rw [eq, Function.update_self] at size + cases size + · rw [Function.update_of_ne eq] at size + exact h.place.granules ⟨p, (Set.mem_insert_iff.mp hp).resolve_left eq, Or.inr ⟨size, next⟩⟩ + · refine ⟨?_, ?_, ?_⟩ + · intro p hp + by_cases eq : p = ptr + · rw [eq, Function.update_self] + exact Or.inl rfl + · rw [Function.update_of_ne eq] + exact h.place.stage2.sz p ((Set.mem_insert_iff.mp hp).resolve_left eq) + · intro p hp + by_cases eq : p = ptr + · rw [eq, Function.update_self] + exact Nat.dvd_of_mod_eq_zero (h.footprint ptr placed).1 + · rw [Function.update_of_ne eq] + exact h.place.stage2.al p ((Set.mem_insert_iff.mp hp).resolve_left eq) + · rintro _ ⟨p, hp, o, bound, al, rfl⟩ r hr + by_cases eq : p = ptr + · rw [eq, Function.update_self] at bound + rw [eq] + exact pageOffHighHeader h heap member cap hr bound + · rw [Function.update_of_ne eq] at bound + exact h.place.stage2.hr _ ⟨p, (Set.mem_insert_iff.mp hp).resolve_left eq, o, bound, al, rfl⟩ r hr + +/-- A mapped Stage-2 child has the exact 4 KiB allocation and lies below the IPA root. -/ +theorem S1aR2.growStage2Heap (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (member : slot ∈ OS) (cap : capA st s slot = .PageTable ptr false ad va) + {asid addr : U64} {value level : Nat} + (path : S1aSlotAt st Pp n s 1#u64 asid value level addr) (deep : 12 < level) : + TeH H (insert ptr Te) (Function.update Re ptr ((level - 12) / 9 - 1)) (Function.update bits ptr 12) n := by + obtain ⟨_, _, _, walk, _⟩ := path.entry + have levelBound := walk.geometry.2.elim (fun h => h.1.le) (fun h => h.1.le) + have levels := path.levels + have childLevel : (level - 12) / 9 - 1 + 1 < s2lv n := by + simp only [s1aTopShift, show (1#u64 : U64) ≠ 0#u64 by decide, show (1#u64 : U64) ≠ 2#u64 by decide, + ite_false] at levelBound + by_cases small : n.val ≤ 42 <;> simp only [s2lv, small, ite_true, ite_false] at levelBound ⊢ + all_goals rcases levels with e | e | e | e <;> omega + intro p hp + by_cases eq : p = ptr + · rw [eq, Function.update_self, Function.update_self] + exact ⟨h.pageObjects slot member ptr false ad va cap, fun impossible => (Nat.ne_of_lt childLevel impossible).elim⟩ + · rw [Function.update_of_ne eq, Function.update_of_ne eq] + exact h.core.heap p ((Set.mem_insert_iff.mp hp).resolve_left eq) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapHigh.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapHigh.lean new file mode 100644 index 000000000..8dd195c1b --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapHigh.lean @@ -0,0 +1,87 @@ +/- +P1 (aarch64): exact HighVSpace Map walks. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapHighEntry + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {Pp : Set U64} {n asid : U64} {s : S} + +private theorem highSlotRange (v o : Nat) + (index : o = ((v >>> 30) &&& 511) * 8) + (lo : fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ v) + (hi : v < fl4_abi.consts.HIGH_VSPACE_TOP.val) : + o < 4096 ∧ o % 8 = 0 ∧ + let first := (2 ^ 64 - 2 ^ 39) + o / 8 * 2 ^ 30 + first ≤ v ∧ v < first + 2 ^ 30 ∧ s1aUserRange 2#u64 n first (2 ^ 30) := by + rw [P0.Consts.fl4_abi.consts.HIGH_VSPACE_BASE.val_eq] at lo + rw [P0.Consts.fl4_abi.consts.HIGH_VSPACE_TOP.val_eq] at hi + have left : (2 ^ 64 - 2 ^ 39) ≤ v := le_trans (by decide) lo + have right : v < (2 ^ 64 - 2 ^ 39) + 2 ^ (30 + 9) := lt_trans hi (by decide) + rw [s1aChildIndex v (2 ^ 64 - 2 ^ 39) 30 (Or.inr (Or.inr rfl)) (by decide) left right] at index + simp only [s1aUserRange, show (2#u64 : U64) ≠ 0#u64 by decide, ite_false, ite_true, + P0.Consts.fl4_abi.consts.HIGH_VSPACE_BASE.val_eq, P0.Consts.fl4_abi.consts.HIGH_VSPACE_TOP.val_eq] + norm_num at lo hi index right ⊢ + omega + +private theorem highFirstSlot {t v next off : U64} + (path : S1aPath st Pp n s 2#u64 asid 30 (2 ^ 64 - 2 ^ 39) t) + (index : off.val = ((v.val >>> 30) &&& 511) * 8) + (place : next = wa t off) + (lo : fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ v.val) + (hi : v.val < fl4_abi.consts.HIGH_VSPACE_TOP.val) : + S1aSlotAt st Pp n s 2#u64 asid v.val 30 next := by + obtain ⟨bound, aligned, range⟩ := highSlotRange (n := n) _ _ index lo hi + exact ⟨t, _, off, path, bound, aligned, place, by decide, range⟩ + +set_option maxHeartbeats 900000 in +/-- A HighVSpace walk enters its private table through L0[511]. -/ +theorem vspace.lookup_pt_slot.highStop (root va : U64) + (header : L.mem s (wa root 4088#u64) &&& 3#u64 = 3#u64) + (path : S1aPath st Pp n s 2#u64 asid 30 (2 ^ 64 - 2 ^ 39) + (wa (L.mem s (wa root 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE)) + (lo : fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ va.val) + (hi : va.val < fl4_abi.consts.HIGH_VSPACE_TOP.val) : + vspace.lookup_pt_slot st s root va ⦃ result => + S1aSlotAt st Pp n s 2#u64 asid va.val result.shift.val result.slot ∧ + (12 < result.shift.val → (L.mem s result.slot &&& 3#u64) ≠ 3#u64) ⦄ := by + let t := wa (L.mem s (wa root 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE + obtain ⟨next, nextOk, off, index, position⟩ := + spec_exists_u (vspace.entry_addr.exactOffset t va 30#u64 (by decide)) + have first : S1aSlotAt st Pp n s 2#u64 asid va.val 30 next := + highFirstSlot path index position lo hi + have start : ExactSlot (st := st) (Pp := Pp) (n := n) (s := s) (tag := 2#u64) + (asid := asid) (address := va.val) (30#u64, next, 2#u64) := + ⟨by simp only; decide, by simp only; decide, first⟩ + unfold vspace.lookup_pt_slot + rw [show vspace.TOP_LEVEL_SHIFT = 39#u64 by unfold vspace.TOP_LEVEL_SHIFT; rfl] + have entry : vspace.entry_addr root va 39#u64 = ok (wa root 4088#u64) := + highLookupHeader root va (highLookupIndex lo hi) + have loopEq : vspace.lookup_pt_slot_loop st s va 39#u64 (wa root 4088#u64) 3#u64 = + vspace.lookup_pt_slot_loop st s va 30#u64 next 2#u64 := + vspace.lookup_pt_slot_loop.highHeaderStep va (wa root 4088#u64) next header nextOk + simp only [entry, bind_ok, loopEq] + refine WP.spec_bind (vspace.lookup_pt_slot_loop.exactStop va 30#u64 next 2#u64 start) ?_ + rintro ⟨_, _⟩ exactSlot + exact (WP.spec_ok _).2 exactSlot + +/-- A HighVSpace walk selects an exact slot in the private walk. -/ +theorem vspace.lookup_pt_slot.highPath (root va : U64) + (header : L.mem s (wa root 4088#u64) &&& 3#u64 = 3#u64) + (path : S1aPath st Pp n s 2#u64 asid 30 (2 ^ 64 - 2 ^ 39) + (wa (L.mem s (wa root 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE)) + (lo : fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ va.val) + (hi : va.val < fl4_abi.consts.HIGH_VSPACE_TOP.val) : + vspace.lookup_pt_slot st s root va ⦃ result => + S1aSlotAt st Pp n s 2#u64 asid va.val result.shift.val result.slot ⦄ := + WP.spec_mono (vspace.lookup_pt_slot.highStop root va header path lo hi) fun _ found => found.1 + + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapHighEntry.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapHighEntry.lean new file mode 100644 index 000000000..094fe4605 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapHighEntry.lean @@ -0,0 +1,60 @@ +/- +P1 (aarch64): Select the private HighVSpace table at the first walk step. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapWalk + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {Pp : Set U64} {n asid : U64} {s : S} + +theorem highLookupIndex {v : U64} + (lo : fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ v.val) + (hi : v.val < fl4_abi.consts.HIGH_VSPACE_TOP.val) : + (v.val >>> 39) &&& 511 = 511 := by + rw [Nat.shiftRight_eq_div_pow, show (511 : Nat) = 2 ^ 9 - 1 from rfl, Nat.and_two_pow_sub_one_eq_mod] + rw [P0.Consts.fl4_abi.consts.HIGH_VSPACE_BASE.val_eq] at lo + rw [P0.Consts.fl4_abi.consts.HIGH_VSPACE_TOP.val_eq] at hi + norm_num at lo hi ⊢ + omega + +theorem highLookupHeader (p v : U64) (idx : (v.val >>> 39) &&& 511 = 511) : + vspace.entry_addr p v 39#u64 = ok (wa p 4088#u64) := by + obtain ⟨slot, step, off, index, place⟩ := + spec_exists_u (vspace.entry_addr.exactOffset p v 39#u64 (by decide)) + have address : off = 4088#u64 := UScalar.eq_of_val_eq (by + rw [index, show (39#u64 : U64).val = 39 from rfl, idx]; rfl) + rw [step, place, address] + +private theorem highHeaderIsTable {word : U64} (h : word &&& 3#u64 = 3#u64) : + vspace.is_table word 39#u64 = ok true := by + unfold vspace.is_table vspace.PAGE_BITS + rw [ite_eq_left (by decide : (39#u64 : U64) > 12#u64), + 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, show (1#u64 ||| 2#u64) = 3#u64 by decide, h] + rfl + +theorem vspace.lookup_pt_slot_loop.highHeaderStep (v slot next : U64) + (tag : L.mem s slot &&& 3#u64 = 3#u64) + (addr : vspace.entry_addr (wa (L.mem s slot &&& vspace.ADDR_MASK) layout.PPTR_BASE) v 30#u64 = ok next) : + vspace.lookup_pt_slot_loop st s v 39#u64 slot 3#u64 = + vspace.lookup_pt_slot_loop st s v 30#u64 next 2#u64 := by + have one : vspace.lookup_pt_slot_loop.body st s v 39#u64 slot 3#u64 = + ok (.cont (30#u64, next, 2#u64)) := by + unfold vspace.lookup_pt_slot_loop.body + rw [ite_eq_left (by decide : (3#u64 : U64) > 0#u64), L.read_eq, bind_ok, highHeaderIsTable tag, bind_ok] + simp only [ite_eq_left rfl, lift, bind_ok, vspace.table_of, layout.pptr] + rw [show (3#u64 : U64) - 1#u64 = ok 2#u64 by rfl, bind_ok] + have sh : core.num.U64.wrapping_sub 39#u64 9#u64 = 30#u64 := rfl + rw [sh, addr, bind_ok, ite_true] + conv_lhs => + rw [vspace.lookup_pt_slot_loop.unfoldOnce, one, bind_ok] + + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapNative.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapNative.lean new file mode 100644 index 000000000..421780d8a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapNative.lean @@ -0,0 +1,83 @@ +/- +P1 (aarch64): exact native Map walks. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapWalk + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +section walk +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {Pp : Set U64} {n tag asid : U64} {s : S} {address : Nat} + +/-- A native walk starts at a user slot in the lower half of the root. -/ +theorem vspace.lookup_pt_slot.nativeStop (root va : U64) + (path : S1aPath st Pp n s 0#u64 asid 39 0 root) + (lower : va.val < 2 ^ 47) : + vspace.lookup_pt_slot st s root va ⦃ result => + S1aSlotAt st Pp n s 0#u64 asid va.val result.shift.val result.slot ∧ + (12 < result.shift.val → (L.mem s result.slot &&& 3#u64) ≠ 3#u64) ⦄ := by + unfold vspace.lookup_pt_slot + rw [show vspace.TOP_LEVEL_SHIFT = 39#u64 by unfold vspace.TOP_LEVEL_SHIFT; rfl] + refine WP.spec_bind (vspace.entry_addr.exactOffset root va 39#u64 (by decide)) ?_ + rintro slot ⟨off, index, location⟩ + have shift : (39#u64 : U64).val = 39 := rfl + have small : va.val / 2 ^ 39 < 256 := by norm_num at lower ⊢; omega + rw [shift, Nat.shiftRight_eq_div_pow, show (511 : Nat) = 2 ^ 9 - 1 from rfl, + Nat.and_two_pow_sub_one_eq_mod, Nat.mod_eq_of_lt (by omega : va.val / 2 ^ 39 < 2 ^ 9)] at index + have start : S1aSlotAt st Pp n s 0#u64 asid va.val 39 slot := by + refine ⟨root, 0, off, path, ?_, by omega, location, by decide, ?_⟩ + · simp [s1aTableWidth, s1aTopShift] + omega + · have base : off.val / 8 = va.val / 2 ^ 39 := by omega + simp only [Nat.zero_add, base, s1aUserRange, P0.Consts.fl4_abi.consts.USER_TOP.val_eq] + norm_num at * + omega + refine WP.spec_bind (vspace.lookup_pt_slot_loop.exactStop (tag := 0#u64) va 39#u64 slot 3#u64 + (show _ from ⟨by simp only; decide, by simp only; decide, start⟩)) ?_ + rintro ⟨_, _⟩ exactSlot + exact (WP.spec_ok _).2 exactSlot + +/-- A native walk selects an exact slot in the lower half. -/ +theorem vspace.lookup_pt_slot.nativePath (root va : U64) + (path : S1aPath st Pp n s 0#u64 asid 39 0 root) + (lower : va.val < 2 ^ 47) : + vspace.lookup_pt_slot st s root va ⦃ result => + S1aSlotAt st Pp n s 0#u64 asid va.val result.shift.val result.slot ⦄ := + WP.spec_mono (vspace.lookup_pt_slot.nativeStop root va path lower) fun _ found => found.1 + +/-- A native address whose L0 index is outside the lower half cannot reach +a slot at any frame's mapping level. -/ +theorem vspace.lookup_pt_slot.nativeUpper (root va : U64) + (empty : S1aRootZero st s root (fun o => 2048 ≤ o ∧ o < 4096)) + (upper : 256 ≤ (va.val >>> 39) &&& 511) : + vspace.lookup_pt_slot st s root va ⦃ result => result.shift.val = 39 ⦄ := by + unfold vspace.lookup_pt_slot + rw [show vspace.TOP_LEVEL_SHIFT = 39#u64 by unfold vspace.TOP_LEVEL_SHIFT; rfl] + refine WP.spec_bind (vspace.entry_addr.exactOffset root va 39#u64 (by decide)) ?_ + rintro slot ⟨off, index, position⟩ + have limit : (va.val >>> 39) &&& 511 ≤ 511 := Nat.and_le_right + rw [show (39#u64 : U64).val = 39 from rfl] at index + have zero := empty off ⟨by omega, by omega⟩ (by omega) + have word : L.mem s slot = 0#u64 := position ▸ zero + have notTable : vspace.is_table 0#u64 39#u64 = ok false := by + unfold vspace.is_table vspace.PAGE_BITS + rw [ite_eq_left (by decide : (39#u64 : U64) > 12#u64), + 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] + exact congrArg ok (by decide) + have step : vspace.lookup_pt_slot_loop.body st s va 39#u64 slot 3#u64 = + ok (.done (39#u64, slot)) := by + unfold vspace.lookup_pt_slot_loop.body + rw [ite_eq_left (by decide : (3#u64 : U64) > 0#u64), L.read_eq, bind_ok, word, + notTable, bind_ok] + rfl + rw [vspace.lookup_pt_slot_loop.unfoldOnce, step, bind_ok, bind_ok] + exact (WP.spec_ok _).2 rfl + +end walk + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapPaths.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapPaths.lean new file mode 100644 index 000000000..695801cb6 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapPaths.lean @@ -0,0 +1,143 @@ +/- +P1 (aarch64): exact active paths after a PageTable Map. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapPlacement + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {n : U64} {s q : S} {slot addr word tag asid ptr t : U64} {level base : Nat} + +private theorem notTableWord {w : U64} (invalid : w &&& 1#u64 = 0#u64) + (table : w &&& 3#u64 = 3#u64) : False := by + have bits := congrArg (fun x : U64 => x.bv &&& 1#64) table + have clear := congrArg UScalar.bv invalid + change (w.bv &&& 3#64) &&& 1#64 = 3#64 &&& 1#64 at bits + change w.bv &&& 1#64 = 0#64 at clear + rw [BitVec.and_assoc, show 3#64 &&& 1#64 = 1#64 by decide, clear] at bits + exact (by decide : (0#64 : BitVec 64) ≠ 1#64) bits + +private theorem mapDescriptorTarget (desc : DescTo word ptr) : + wa (word &&& vspace.ADDR_MASK) layout.PPTR_BASE = ptr := by + have maskEq : ept.ADDR_MASK = vspace.ADDR_MASK := + UScalar.eq_of_val_eq (by simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + exact desc.elim id (fun e => by rwa [maskEq] at e) + +/-- A table publication keeps all previous active paths and adds only the selected child. -/ +structure S1aTablePaths (st : machine.Store S) [L : LawfulStore st] (Pp : Set U64) + (n : U64) (s q : S) (tag asid : U64) (sh base : Nat) (ptr : U64) : Prop where + kept : ∀ k a ℓ b p, S1aPath st Pp n s k a ℓ b p → S1aPath st Pp n q k a ℓ b p + added : S1aPath st Pp n q tag asid sh base ptr + classify : ∀ k a ℓ b p, S1aPath st Pp n q k a ℓ b p → + S1aPath st Pp n s k a ℓ b p ∨ (k = tag ∧ a = asid ∧ ℓ = sh ∧ b = base ∧ p = ptr) + empty : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa ptr o) = 0#u64 + +set_option maxHeartbeats 3300000 in +/-- Exact Map publication extends the active walks by the newly mapped empty table. -/ +theorem S1aMapWrite.tablePaths {off ad oldVa saved : U64} {va : Nat} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (member : slot ∈ OS) (before : capA st s slot = .PageTable ptr false ad oldVa) + (atSlot : S1aSlotAt st Pp n s tag asid va level addr) + (parent : S1aPath st Pp n s tag asid level base t) + (chosenWidth : off.val < s1aTableWidth tag n level) (aligned : off.val % 8 = 0) + (position : addr = wa t off) (range : s1aUserRange tag n (base + off.val / 8 * 2 ^ level) (2 ^ level)) + (deep : 12 < level) (invalid : L.mem s addr &&& 1#u64 = 0#u64) + (tagged : word &&& 3#u64 = 3#u64) (names : DescTo word ptr) + (write : S1aMapWrite st OS Pt s q slot addr word (.PageTable ptr true asid saved)) : + S1aTablePaths st Pp n s q tag asid (level - 9) (base + off.val / 8 * 2 ^ level) ptr := by + have active (a raw : U64) := write.activeAsid h heap kinds ptKs atSlot (a := a) (raw := raw) + have high (a raw : U64) (e : ActiveAsidRoot st Pp s a raw) (k : raw &&& 3#u64 = 2#u64) : + L.mem q (wa (raw &&& ~~~3#u64) 4088#u64) = L.mem s (wa (raw &&& ~~~3#u64) 4088#u64) := by + obtain ⟨x, hx, cap⟩ := h.core.root.backed a raw e + rw [k] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + have live : raw &&& ~~~3#u64 ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, a, cap⟩ + exact write.highHeader h heap kinds atSlot live 4088#u64 (by decide) (by decide) + have keep : ∀ k a ℓ b p, S1aPath st Pp n s k a ℓ b p → S1aPath st Pp n q k a ℓ b p := by + intro k a ℓ b p path + induction path with + | native e tag => exact .native ((active _ _).2 e) tag + | stage2 e tag => exact .stage2 ((active _ _).2 e) tag + | high e tag valid => + rw [← high _ _ e tag] at valid ⊢ + exact .high ((active _ _).2 e) tag valid + | @child k a p o sh b prior deep width al range valid ih => + have different : wa p o ≠ addr := by + intro eq + rw [eq] at valid + exact notTableWord invalid valid + rw [← write.memory _ (Or.inl (h.pathWord prior width al)) different] at valid ⊢ + exact .child ih deep width al range valid + have target := mapDescriptorTarget names + have new : S1aPath st Pp n q tag asid (level - 9) (base + off.val / 8 * 2 ^ level) ptr := by + have eq : L.mem q (wa t off) = word := position ▸ write.descriptor + have atWord : L.mem q (wa t off) &&& 3#u64 = 3#u64 := eq.symm ▸ tagged + have path := S1aPath.child (keep _ _ _ _ _ parent) deep chosenWidth aligned range atWord + rwa [eq, target] at path + have unmapped : UnmCap (capA st s slot) ptr 4096 := Or.inl ⟨rfl, ad, oldVa, before⟩ + have empty : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa ptr o) = 0#u64 := by + obtain ⟨x, hx, p, d, z, obj, _, limit, address, mapped, _⟩ := h.pathWordObject parent chosenWidth + have absent : p ≠ ptr := fun eq => h.core.lookup.ex slot member x hx ptr 4096 unmapped (eq ▸ mapped) + intro o bound al + have different := tableWordsNe heap obj (h.pageObjects slot member ptr false ad oldVa before) + absent limit bound + have slotNe : addr ≠ wa ptr o := by rw [position, address]; exact different + have loc : PtW Pt (wa ptr o) := ⟨ptr, h.pageTables slot member ptr false ad oldVa before, o, bound, al, rfl⟩ + exact (write.memory _ (Or.inl loc) slotNe.symm).trans (h.core.lookup.zr slot member ptr 4096 unmapped o bound al) + have limit : level - 9 < s1aTopShift tag n := by + have height := parent.geometry.2.elim (fun e => e.1.le) (fun e => e.1.le) + omega + refine ⟨keep, new, ?_, empty⟩ + intro k a ℓ b p path + induction path with + | native e tag => exact Or.inl (.native ((active _ _).1 e) tag) + | stage2 e tag => exact Or.inl (.stage2 ((active _ _).1 e) tag) + | high e tag valid => + have beforeRoot := (active _ _).1 e + rw [high _ _ beforeRoot tag] at valid ⊢ + exact Or.inl (.high beforeRoot tag valid) + | @child k a p o sh b _ deep width al range valid ih => + rcases ih with prior | ⟨kind, id, height, first, pointer⟩ + · by_cases atWrite : wa p o = addr + · obtain ⟨kind, id, height, first, table, delta⟩ := + h.samePathWord heap kinds prior parent width chosenWidth (atWrite.trans position) + rw [atWrite, write.descriptor, target] + exact Or.inr ⟨kind, id, congrArg (· - 9) height, by rw [first, delta, height], rfl⟩ + · rw [write.memory _ (Or.inl (h.pathWord prior width al)) atWrite] at valid ⊢ + exact Or.inl (.child prior deep width al range valid) + · have bound : o.val < 4096 := by + rw [kind, height, s1aTableWidth, if_neg (Nat.ne_of_lt limit)] at width + exact width + rw [pointer, empty o bound al] at valid + exact ((by decide : (0#u64 &&& 3#u64) ≠ 3#u64) valid).elim + +/-- The concrete PageTable Map post supplies the path transition with the +saved address of the newly reachable child. -/ +theorem S1aTableMap.activePaths {ad oldVa : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (member : slot ∈ OS) (before : capA st s slot = .PageTable ptr false ad oldVa) + (edit : S1aTableMap st OS Pt Pp n tag s q slot ptr) : + ∃ asid saved : U64, ∃ level : Nat, + S1aTablePaths st Pp n s q tag asid (level - 9) (s1aCapAddress tag n saved) ptr ∧ + capA st q slot = .PageTable ptr true asid saved := by + obtain ⟨a, va, saved, addr, word, shift, path, deep, invalid, tagged, target, savedBase, write⟩ := edit.edit + obtain ⟨p, b, o, parent, width, aligned, position, base, range⟩ := path.alignedAddress + have transition := write.tablePaths h heap kinds ptKs member before path parent width aligned position range + deep invalid tagged target + rw [← base, ← savedBase] at transition + exact ⟨a, saved, shift, transition, write.cap⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapPlacement.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapPlacement.lean new file mode 100644 index 000000000..0b5d841d6 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapPlacement.lean @@ -0,0 +1,218 @@ +/- +P1 (aarch64): exact Map preserves the active ASID entries. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapStage1Post + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {slot addr word tag asid : U64} {level va : Nat} {cap : capability.Cap} + +/-- Two active table words for the same word agree on stage, ASID, level and address. -/ +theorem S1aR2.sameStorageWord (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + {tag' a' t t' o o' : U64} {level' base base' : Nat} + (path : S1aPath st Pp n s tag asid level base t) + (path' : S1aPath st Pp n s tag' a' level' base' t') + (below : o.val < s1aTableStorage tag n level) (below' : o'.val < s1aTableStorage tag' n level') + (eq : wa t o = wa t' o') : + tag = tag' ∧ asid = a' ∧ level = level' ∧ base = base' ∧ t = t' ∧ o = o' := by + obtain ⟨x, hx, p, d, z, obj, _, off, address, _, key, ptr, _, tab, delta, child, root⟩ := + h.pathStorageWord path below + obtain ⟨x', hx', p', d', z', obj', _, off', address', _, key', ptr', _, tab', delta', child', root'⟩ := + h.pathStorageWord path' below' + have words := address.symm.trans (eq.trans address') + have bases : p = p' := by + by_contra ne + exact tableWordsNe heap obj obj' ne off off' words + cases bases + have kind := kinds.kind x hx x' hx' key key' (ptr.trans ptr'.symm) + have tables : t = t' := by rw [tab, tab', kind] + cases tables + have offs : o = o' := by + apply UScalar.eq_of_val_eq + have fits := heap.fits p _ obj + have fits' := heap.fits p _ obj' + simp only [HKind.bits] at fits fits' + have w := congrArg UScalar.val words + rw [wadd_val (by omega : p.val + d.val < 2 ^ 64), + wadd_val (by omega : p.val + d'.val < 2 ^ 64)] at w + rw [kind] at delta + omega + by_cases isChild : kindA (capA st s x) = 14 + · have c := h.paths.childAgreement h.capRefs path path' (child.1 isChild) (child'.1 (kind.symm.trans isChild)) + exact ⟨c.1, c.2.1, c.2.2.1, c.2.2.2, rfl, offs⟩ + · have otherRoot : kindA (capA st s x') ≠ 14 := by rwa [← kind] + obtain ⟨raw, r, addr⟩ := root isChild + obtain ⟨raw', r', addr'⟩ := root' otherRoot + have ids := h.core.root.asid_unique r r' (addr.trans addr'.symm) + cases ids + have tags := path.sameTag path' + cases tags + rcases path.geometry.2 with ⟨top, loc⟩ | ⟨low, _⟩ + · rcases path'.geometry.2 with ⟨top', loc'⟩ | ⟨low, _⟩ + · exact ⟨rfl, rfl, top.trans top'.symm, loc.trans loc'.symm, rfl, offs⟩ + · exact (otherRoot (child'.2 low)).elim + · exact (isChild (child.2 low)).elim + +/-- Two active walk slots for the same word agree on stage, ASID, level and address. -/ +theorem S1aR2.samePathWord (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + {tag' a' t t' o o' : U64} {level' base base' : Nat} + (path : S1aPath st Pp n s tag asid level base t) + (path' : S1aPath st Pp n s tag' a' level' base' t') + (below : o.val < s1aTableWidth tag n level) (below' : o'.val < s1aTableWidth tag' n level') + (eq : wa t o = wa t' o') : + tag = tag' ∧ asid = a' ∧ level = level' ∧ base = base' ∧ t = t' ∧ o = o' := + h.sameStorageWord heap kinds path path' (lt_of_lt_of_le below (s1aTableWidth.leStorage tag n level)) + (lt_of_lt_of_le below' (s1aTableWidth.leStorage tag' n level')) eq + +/-- A valid raw Stage-2 table lies within the claimed physical allocation. -/ +theorem S1aR2.stage2Storage (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {b : Nat} {p : U64} (walk : S1aPath st Pp n s 1#u64 asid level b p) : + 2 ^ bits p ≤ s1aTableStorage 1#u64 n level := by + have placed : p ∈ Te := (show _ ∧ _ ∧ _ from h.paths.tables _ _ _ _ _ walk).1 + rcases walk.geometry.2 with ⟨top, _⟩ | ⟨child, _⟩ + · rw [s1aTableStorage, if_pos ⟨rfl, top⟩] + rcases h.place.stage2.sz p placed with e | e <;> rw [e] <;> decide + · obtain ⟨x, hx, saved, cap, _⟩ := h.paths.children _ _ _ _ _ walk child + have object := h.pageObjects x hx p true asid saved cap + have bitsEq : bits p = 12 := by + have e := (h.core.heap p placed).1.symm.trans object + exact HKind.other.inj (Option.some.inj e) + rw [bitsEq, s1aTableStorage, if_neg (fun e => (Nat.ne_of_lt child) e.2)] + decide + +/-- A chosen descriptor is disjoint from the kernel's copied tables. -/ +theorem S1aR2.pathOffKernel (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (path : S1aSlotAt st Pp n s tag asid va level addr) + {p : U64} (member : p ∈ Kt) (o : U64) (bound : o.val < 4096) : wa p o ≠ addr := by + obtain ⟨t, base, off, walk, width, al, position, _, _, _⟩ := path.entry + obtain ⟨x, hx, owner, delta, z, obj, _, span, word, mapped, _⟩ := h.pathWordObject walk width + have different : p ≠ owner := fun e => h.core.lookup.kt p member x hx (e.symm ▸ mapped.names) + rw [position, word] + exact tableWordsNe heap (h.kernelTables.2 p member) obj different bound span + +/-- A Map write is disjoint from the ASID table and the active pools. -/ +theorem S1aMapWrite.keepAsid (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (write : S1aMapWrite st OS Pt s q slot addr word cap) : + TabKeep st s q ∧ + ∀ p ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa p o) = L.mem s (wa p o) := by + obtain ⟨t, base, off, walk, width, al, position, _, _, _⟩ := path.entry + have target : PtW Pt addr := position ▸ h.pathWord walk width al + refine ⟨⟨write.base, fun i => ?_⟩, ?_⟩ + · have atWord := asW_at (L.ksb s) i + rw [write.base] + exact write.memory _ (Or.inr atWord) (fun eq => ptKs addr target (eq ▸ atWord)) + · intro p active o below aligned + have different : addr ≠ wa p o := position ▸ h.pathWordOffPool heap kinds walk width active below + exact write.memory _ (Or.inl ⟨p, h.place.pools active, o, below, aligned, rfl⟩) different.symm + +/-- An active user slot cannot alias a word in a live HighVSpace header. -/ +theorem S1aR2.pathOffHighHeader (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + {r : U64} (live : r ∈ Hr) (o : U64) (bound : o.val < 4096) : + wa r o ≠ addr := by + obtain ⟨t, base, off, walk, width, al, position, _, _, _⟩ := path.entry + obtain ⟨x, hx, p, d, z, obj, _, offBound, address, _, key, ptr, _, _, delta, _, _⟩ := + h.pathWordObject walk width + have rLive : r ∈ HvRt st OS s := h.highRoots ▸ live + obtain ⟨y, hy, m, a, capEq⟩ := rLive + have rootObj := h.highObjects y hy r m a capEq + rw [position, address] + intro eq + have baseEq : p = r := by + by_contra ne + exact tableWordsNe heap obj rootObj ne offBound (by omega : o.val < 2 ^ 13) eq.symm + cases baseEq + have kind := kinds.kind x hx y hy key (by rw [capEq]; exact RngKeyA.hv _ _ _) + (by rw [ptr, capEq, ptrA_hv]) + rw [capEq] at kind + change kindA (capA st s x) = 25 at kind + rw [kind, if_pos rfl] at delta + have fits := heap.fits r _ obj + have rootFits := heap.fits r _ rootObj + simp only [HKind.bits] at fits rootFits + have value := congrArg UScalar.val eq + rw [wadd_val (by omega : r.val + o.val < 2 ^ 64), wadd_val (by omega : r.val + d.val < 2 ^ 64)] at value + omega + +/-- A Map in the user walk preserves the entire header of each live HighVSpace. -/ +theorem S1aMapWrite.highHeader (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (write : S1aMapWrite st OS Pt s q slot addr word cap) + {r : U64} (live : r ∈ Hr) (o : U64) (bound : o.val < 4096) (aligned : o.val % 8 = 0) : + L.mem q (wa r o) = L.mem s (wa r o) := by + exact write.memory _ (Or.inl ⟨r, h.place.tables (h.place.high.sub live), o, bound, aligned, rfl⟩) + (h.pathOffHighHeader heap kinds path live o bound) + +/-- The exact ASID entries survive a Map even when its descriptor changes. -/ +theorem S1aMapWrite.activeAsid (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (write : S1aMapWrite st OS Pt s q slot addr word cap) {a raw : U64} : + ActiveAsidRoot st Pp q a raw ↔ ActiveAsidRoot st Pp s a raw := by + obtain ⟨tab, pools⟩ := write.keepAsid h heap kinds ptKs path + constructor + · exact ActiveAsidRoot.back tab.toDel (fun p hp o bound al => Or.inl (pools p hp o bound al)) + · have rev : TabKeep st q s := ⟨tab.1.symm, fun i => (tab.2 i).symm⟩ + exact ActiveAsidRoot.back rev.toDel (fun p hp o bound al => + Or.inl (pools p (tab.poolSet_eq ▸ hp) o bound al).symm) + +/-- A selected Map slot that belongs to raw Stage 1 comes from the same +user table and level as the concrete selected slot. -/ +theorem S1aR2.mapStage1Source (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + {p o : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s p) + (width : o.val < 4096) (selected : wa p o = addr) : + tag ≠ 1#u64 ∧ level + 9 * Lv p = 39 := by + rcases h.classifyStage1 reach with kernel | ⟨raw, a, active, kind, rfl⟩ | ⟨k, a, sh, b, stage, walk⟩ + · exact (h.pathOffKernel heap path kernel o width selected).elim + · obtain ⟨x, hx, cap⟩ := h.core.root.backed a raw active + rw [kind] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + have live : raw &&& ~~~3#u64 ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, a, cap⟩ + exact (h.pathOffHighHeader heap kinds path live o width selected).elim + · obtain ⟨t, first, off, chosen, bound, al, position, _, _, _⟩ := path.entry + have ne : k ≠ 1#u64 := by rcases stage with rfl | rfl <;> decide + have inStorage : o.val < s1aTableStorage k n sh := by + rw [s1aTableStorage, if_neg (fun e => ne e.1)] + exact width + have equal := h.sameStorageWord heap kinds walk chosen inStorage + (lt_of_lt_of_le bound (s1aTableWidth.leStorage tag n level)) (selected.trans position) + have shape := h.paths.tables k a sh b p walk + rw [if_neg ne] at shape + exact ⟨equal.1 ▸ ne, equal.2.2.1 ▸ shape.2⟩ + +/-- A selected Map slot that belongs to raw Stage 2 comes from the same +IPA table and level as the concrete selected slot. -/ +theorem S1aR2.mapStage2Source (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + {p o : U64} (reach : S2Reach st (PoolSet st Pp s) Re bits s p) + (width : o.val < 2 ^ bits p) (selected : wa p o = addr) : + tag = 1#u64 ∧ level = 12 + 9 * Re p := by + obtain ⟨a, sh, b, walk⟩ := h.classifyStage2 reach + obtain ⟨t, first, off, chosen, bound, al, position, _, _, _⟩ := path.entry + have equal := h.sameStorageWord heap kinds walk chosen (lt_of_lt_of_le width (h.stage2Storage walk)) + (lt_of_lt_of_le bound (s1aTableWidth.leStorage tag n level)) (selected.trans position) + have depth := (show _ ∧ _ ∧ _ from h.paths.tables _ _ _ _ _ walk).2.1 + exact ⟨equal.1.symm, equal.2.2.1.symm.trans depth⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapPost.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapPost.lean new file mode 100644 index 000000000..441947679 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapPost.lean @@ -0,0 +1,200 @@ +/- +P1 (aarch64): full R2 after the exact PageTable Map effects. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapGrow +import Fl4ProofsA64.P1.S1aR2UnmapRoute + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s q : S} + {slot ptr tag oldAsid oldVa : U64} + +set_option maxHeartbeats 3900000 in +/-- The concrete Map inserts exactly the published table into the selected +stage's witnesses and preserves R2 on the same heap, slots and footprint. -/ +theorem S1aR2.ofTableMap (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (member : slot ∈ OS) (old : capA st s slot = .PageTable ptr false oldAsid oldVa) + (event : S1aTableMap st OS Pt Pp n tag s q slot ptr) : + ∃ Tb' Te' Lv' Re' bits', S1aR2 st H OS Pt Pp Tb' Hr Te' Kt Lv' Re' bits' n q := by + obtain ⟨a, va, saved, addr, word, level, path, above, invalid, valid, target, savedBase, write⟩ := event.edit + obtain ⟨t, base, o, parent, width, al, position, baseAt, range⟩ := path.alignedAddress + have paths := write.tablePaths h heap kinds ptKs member old path parent width al position range above invalid valid target + rw [← baseAt, ← savedBase] at paths + let Tb' := if tag = 1#u64 then Tb else insert ptr Tb + let Lv' := if tag = 1#u64 then Lv else Function.update Lv ptr ((39 - level) / 9 + 1) + let Te' := if tag = 1#u64 then insert ptr Te else Te + let Re' := if tag = 1#u64 then Function.update Re ptr ((level - 12) / 9 - 1) else Re + let bits' := if tag = 1#u64 then Function.update bits ptr 12 else bits + refine ⟨Tb', Te', Lv', Re', bits', ?_⟩ + obtain ⟨tab, pools⟩ := write.keepAsid h heap kinds ptKs path + have pathBacking : S1aPathBacking st H OS Pp Tb' Te' Lv' Re' bits' n q := + paths.backing h heap kinds member old path above valid write + have refs := write.tableCaps h heap kinds path member old + have rootSlots := write.rootSlots h heap kinds path + have teHeap : TeH H Te' Re' bits' n := by + by_cases stage : tag = 1#u64 + · simpa only [Te', Re', bits', stage, ite_true] using h.growStage2Heap member old (stage ▸ path) above + · simpa only [Te', Re', bits', stage, ite_false] using h.core.heap + have place : S1aR2Place Pt (PoolSet st Pp q) Tb' Hr Te' Lv' bits' (L.ksb q) := by + rw [tab.1, tab.poolSet_eq] + by_cases stage : tag = 1#u64 + · simpa only [Tb', Te', Lv', bits', stage, ite_true] using h.growStage2Place heap member old + · simpa only [Tb', Te', Lv', bits', stage, ite_false] using h.growStage1Place heap member old ((39 - level) / 9 + 1) + have reflect (P : capability.Cap → Prop) + (atInvoked : P (.PageTable ptr true a saved) ↔ P (.PageTable ptr false oldAsid oldVa)) + (x : U64) (hx : x ∈ OS) : P (capA st q x) ↔ P (capA st s x) := by + by_cases eq : x = slot + · rw [eq, write.cap, old] + exact atInvoked + · rw [write.other x hx eq] + have same x (hx : x ∈ OS) (c : capability.Cap) + (pre : c ≠ .PageTable ptr false oldAsid oldVa) (post : c ≠ .PageTable ptr true a saved) : + capA st q x = c ↔ capA st s x = c := + reflect (· = c) ⟨fun e => (post e.symm).elim, fun e => (pre e.symm).elim⟩ x hx + have root : RootAgreement st OS Pp q := by + have rootCap x hx p a k := reflect (fun c => MappedAsidRoot c p a k) (by simp [MappedAsidRoot]) x hx + constructor + · intro asid raw e + obtain ⟨x, hx, c⟩ := h.core.root.backed asid raw ((write.activeAsid h heap kinds ptKs path).1 e) + exact ⟨x, hx, (rootCap x hx _ _ _).2 c⟩ + · intro x hx y hy p a b k k' c c' + exact h.core.root.agree x hx y hy p a b k k' ((rootCap x hx p a k).1 c) ((rootCap y hy p b k').1 c') + have keepHigh x (hx : x ∈ OS) p m a : + capA st q x = .HighVSpace p m a ↔ capA st s x = .HighVSpace p m a := + same x hx _ (by intro e; cases e) (by intro e; cases e) + have highSet : Hr = HvRt st OS q := by + rw [h.highRoots] + ext p + constructor <;> rintro ⟨x, hx, m, a, c⟩ + · exact ⟨x, hx, m, a, (keepHigh x hx p m a).2 c⟩ + · exact ⟨x, hx, m, a, (keepHigh x hx p m a).1 c⟩ + have highObj : HvObjects st H OS q := fun x hx p m a e => + h.highObjects x hx p m a ((keepHigh x hx p m a).1 e) + have ept : EptPlaced st H OS Pt q := fun x hx p l m a v e => + h.eptRoots x hx p l m a v ((same x hx _ (by intro e; cases e) (by intro e; cases e)).1 e) + have pageBase x (hx : x ∈ OS) p m a v (cap : capA st q x = .PageTable p m a v) : + p ∈ Pt ∧ H p = some (.other 12) := by + by_cases eq : x = slot + · rw [eq, write.cap] at cap + cases cap + exact ⟨h.pageTables slot member ptr false oldAsid oldVa old, h.pageObjects slot member ptr false oldAsid oldVa old⟩ + · have prior := (write.other x hx eq).symm.trans cap + exact ⟨h.pageTables x hx p m a v prior, h.pageObjects x hx p m a v prior⟩ + have header r (hr : r ∈ Hr) : L.mem q (wa r 4088#u64) = L.mem s (wa r 4088#u64) := + write.highHeader h heap kinds path hr 4088#u64 (by decide) (by decide) + have link r (hr : r ∈ Hr) : + wa (L.mem q (wa r 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE = wa r 4096#u64 := by + rw [header r hr] + exact h.highLink r hr + have oldUnmapped : UnmCap (capA st s slot) ptr 4096 := Or.inl ⟨rfl, oldAsid, oldVa, old⟩ + have noKernel := h.core.lookup.unmKt member oldUnmapped + have closed t (ht : t ∈ Kt) (depth : Lv' t < 3) (o : U64) (bound : o.val < 4096) + (al : o.val % 8 = 0) (valid : L.mem q (wa t o) &&& 3#u64 = 3#u64) : + wa (L.mem q (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + have ne : t ≠ ptr := fun e => noKernel (e ▸ ht) + have kLevel : Lv' t = Lv t := by dsimp [Lv']; split <;> simp only [Function.update_of_ne ne] + have address : PtW Pt (wa t o) := ⟨t, h.place.tables (h.kernelTables.1 ht), o, bound, al, rfl⟩ + rw [write.memory _ (Or.inl address) (h.pathOffKernel heap path ht o bound)] at valid ⊢ + exact h.kernelClosed t ht (kLevel ▸ depth) o bound al valid + have priorUnmapped x (hx : x ∈ OS) p size (cap : UnmCap (capA st q x) p size) : + UnmCap (capA st s x) p size ∧ x ≠ slot := by + have different : x ≠ slot := by rintro rfl; simp [write.cap, UnmCap] at cap + exact ⟨by simpa only [write.other x hx different] using cap, different⟩ + have oldMap x (hx : x ∈ OS) p (cap : MapV (capA st s x) p) : MapV (capA st q x) p := by + have different : x ≠ slot := by rintro rfl; simp [old, MapV] at cap + simpa only [write.other x hx different] using cap + have newMapped : MapV (capA st q slot) ptr := Or.inl ⟨a, saved, write.cap⟩ + have raw1 := write.rawStage1 h heap kinds ptKs member old path target paths.empty + have raw2 := write.rawStage2 h heap kinds ptKs member old path target paths.empty + have lookup : VsLk st H OS Pp Tb' Te' Kt Lv' Re' bits' q := by + refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ + · intro p reached _ hk + rcases raw1 p reached with prior | ⟨_, rfl⟩ + · obtain ⟨x, hx, c⟩ := h.core.lookup.bk1 p prior (h.core.stage1.reachableMember prior) hk + exact ⟨x, hx, oldMap x hx p c⟩ + · exact ⟨slot, member, newMapped⟩ + · intro p reached _ + rcases raw2 p reached with prior | ⟨_, rfl⟩ + · obtain ⟨x, hx, c⟩ := h.core.lookup.bk2 p prior (h.core.stage2.reachableMember prior) + exact ⟨x, hx, oldMap x hx p c⟩ + · exact ⟨slot, member, newMapped⟩ + · intro p hk x hx cap + by_cases eq : x = slot + · simp [eq, write.cap, NamesV] at cap + exact noKernel (cap ▸ hk) + · exact h.core.lookup.kt p hk x hx (by simpa only [write.other x hx eq] using cap) + · intro x hx y hy p size unm mapped + obtain ⟨before, different⟩ := priorUnmapped x hx p size unm + by_cases eq : y = slot + · have sameBase : ptr = p := by simpa [eq, write.cap, MapV] using mapped + have unmAtPtr : UnmCap (capA st s x) ptr size := sameBase.symm ▸ before + rcases unmAtPtr with ⟨_, oldA, oldV, oldPage⟩ | ⟨_, oldA, oldV, oldEpt⟩ + · exact different (h.capRefs.unique slot member x hx (0, ptr) (by rw [old]; rfl) + (by rw [oldPage]; rfl) (by rw [old]; rfl)) + · have two := (h.eptRoots x hx ptr 0#u64 false oldA oldV oldEpt).1 + rw [h.pageObjects slot member ptr false oldAsid oldVa old] at two + cases two + · exact h.core.lookup.ex x hx y hy p size before (by simpa only [write.other y hy eq] using mapped) + · intro x hx p size cap o bound al + have oldCap := (priorUnmapped x hx p size cap).1 + exact (write.keepUnmappedWord h heap path hx oldCap bound al).trans + (h.core.lookup.zr x hx p size oldCap o bound al) + · refine ⟨fun x hx p size cap => h.core.lookup.vh.1 x hx p size (priorUnmapped x hx p size cap).1, ?_, ?_⟩ + · intro p reached _ hk + rcases raw1 p reached with prior | ⟨_, rfl⟩ + · rcases h.core.lookup.vh.2.1 p prior (h.core.stage1.reachableMember prior) hk with obj | ⟨r, obj, loc, x, hx, a, eq⟩ + · exact Or.inl obj + · exact Or.inr ⟨r, obj, loc, x, hx, a, (keepHigh x hx r true a).2 eq⟩ + · exact Or.inl (h.pageObjects slot member _ false oldAsid oldVa old) + · exact fun p _ hp => (teHeap p hp).1 + have kindPost : KindA st OS q := by + apply kinds.keep + intro x hx + by_cases eq : x = slot + · rw [eq, write.cap, old] + exact ⟨⟨fun _ => RngKeyA.pt _ _ _ _, fun _ => RngKeyA.pt _ _ _ _⟩, + fun _ => ⟨by rw [ptrA_pt, ptrA_pt], rfl⟩⟩ + · rw [write.other x hx eq] + exact ⟨Iff.rfl, fun _ => ⟨rfl, rfl⟩⟩ + have route : S1aRouteFacts st H OS Pt Pp Tb' Hr Te' Kt Lv' Re' bits' n q := + ⟨lookup, root, teHeap, pathBacking, refs, rootSlots, highSet, link, highObj, ept, + (fun x hx p m a v eq => (pageBase x hx p m a v eq).2), closed⟩ + exact { + core := ⟨lookup, route.recoverWalk heap kindPost, root, + write.stage1Typed h heap kinds ptKs member old path target paths.empty, + write.stage2Typed h heap kinds ptKs member old path target paths.empty, teHeap⟩ + place := place + poolCaps := h.poolCaps.keep tab pools (fun x hx p a => same x hx _ (by intro e; cases e) (by intro e; cases e)) + capRefs := refs + paths := pathBacking + pageTables := fun x hx p m a v eq => (pageBase x hx p m a v eq).1 + footprint := h.footprint + pageObjects := route.pageObjects + nativeRoots := fun x hx p m a c => h.nativeRoots x hx p m a + ((same x hx _ (by intro e; cases e) (by intro e; cases e)).1 c) + eptRoots := ept + highObjects := highObj + highHeaders := fun x hx p m a c => by + have live : p ∈ Hr := by rw [highSet]; exact ⟨x, hx, m, a, c⟩ + rw [header p live] + exact h.highHeaders x hx p m a ((keepHigh x hx p m a).1 c) + highLink := link + highRoots := highSet + highFootprint := h.highFootprint + kernelTables := ⟨fun t ht => by + by_cases stage : tag = 1#u64 + · simpa only [Tb', stage, ite_true] using h.kernelTables.1 ht + · simpa only [Tb', stage, ite_false] using Set.mem_insert_of_mem ptr (h.kernelTables.1 ht), + h.kernelTables.2⟩ + kernelClosed := closed + rootSlots := rootSlots } + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapReach.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapReach.lean new file mode 100644 index 000000000..10ce032a8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapReach.lean @@ -0,0 +1,151 @@ +/- +P1 (aarch64): raw Stage-1 and Stage-2 reachability after PageTable Map. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapBacking + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {slot addr word tag asid ptr : U64} {level va : Nat} {cap : capability.Cap} + +/-- The active Stage-1 typing includes every raw reachable table. -/ +theorem VsTyR.reachableMember + (ty : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ Tb Lv s) + {p : U64} (path : VsReach st (PoolSet st Pp s) ∅ Lv s p) : p ∈ Tb := by + induction path with + | hr live => exact False.elim live + | root0 live bound al nz tag => exact ((ty.pool _ live _ bound al nz).1 tag).1 + | @root2 p o live bound al tag => + have nz : L.mem s (wa p o) ≠ 0#u64 := by + intro zero + rw [zero] at tag + cases tag + exact ((ty.pool _ live _ bound al nz).2 tag).1 + | step _ level bound al tag ih => exact (ty.desc _ ih ‹_› level _ bound al tag).1 + +/-- The active Stage-2 typing includes every raw reachable table. -/ +theorem S2TyR.reachableMember (ty : S2TyR st n (PoolSet st Pp s) Hr Te Re bits s) + {p : U64} (path : S2Reach st (PoolSet st Pp s) Re bits s p) : p ∈ Te := by + induction path with + | @root p o live bound al tag => + have nz : L.mem s (wa p o) ≠ 0#u64 := by + intro zero + rw [zero] at tag + cases tag + rcases ty.tag _ live _ bound al nz with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, member, _⟩ + · rw [tag] at bad + cases bad + · rw [tag] at bad + cases bad + · exact member + | step _ level bound al tag ih => exact (ty.desc _ ih ‹_› level _ bound al tag).1 + +theorem DescTo.tableTargets (target : DescTo word ptr) : + wa (word &&& vspace.ADDR_MASK) layout.PPTR_BASE = ptr ∧ + wa (word &&& ept.ADDR_MASK) layout.PPTR_BASE = ptr := by + have masks : ept.ADDR_MASK = vspace.ADDR_MASK := + UScalar.eq_of_val_eq (by simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + unfold DescTo at target + rw [masks] at target ⊢ + exact ⟨target.elim id id, target.elim id id⟩ + +set_option maxHeartbeats 3000000 in +/-- A PageTable Map adds only the published child to raw Stage-1 reachability. -/ +theorem S1aMapWrite.rawStage1 {ad oldVa : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (member : slot ∈ OS) (before : capA st s slot = .PageTable ptr false ad oldVa) + (selected : S1aSlotAt st Pp n s tag asid va level addr) (target : DescTo word ptr) + (write : S1aMapWrite st OS Pt s q slot addr word cap) + (empty : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa ptr o) = 0#u64) : + let Lv' := if tag = 1#u64 then Lv else Function.update Lv ptr ((39 - level) / 9 + 1) + ∀ p, VsReach st (PoolSet st Pp q) ∅ Lv' q p → + VsReach st (PoolSet st Pp s) ∅ Lv s p ∨ (tag ≠ 1#u64 ∧ p = ptr) := by + obtain ⟨tab, pools⟩ := write.keepAsid h heap kinds ptKs selected + have samePools : PoolSet st Pp q = PoolSet st Pp s := tab.poolSet_eq + have unmapped : UnmCap (capA st s slot) ptr 4096 := Or.inl ⟨rfl, ad, oldVa, before⟩ + let Lv' := if tag = 1#u64 then Lv else Function.update Lv ptr ((39 - level) / 9 + 1) + change ∀ p, VsReach st (PoolSet st Pp q) ∅ Lv' q p → _ + rw [samePools] + intro p reach + induction reach with + | hr live => exact False.elim live + | root0 live bound al nz tg => + rw [pools _ live _ bound al] at nz tg ⊢ + exact Or.inl (.root0 live bound al nz tg) + | root2 live bound al tg => + rw [pools _ live _ bound al] at tg ⊢ + exact Or.inl (.root2 live bound al tg) + | @step p o _ below width al tagged ih => + rcases ih with old | ⟨stage, same⟩ + · have placed := h.core.stage1.reachableMember old + have diff : p ≠ ptr := fun eq => h.core.lookup.unmR1 member unmapped (eq ▸ ⟨placed, old⟩) + have depth : Lv' p = Lv p := by + dsimp [Lv'] + split <;> simp only [Function.update_of_ne diff] + rw [depth] at below + by_cases atEdit : wa p o = addr + · rw [atEdit, write.descriptor, target.tableTargets.1] + exact Or.inr ⟨(h.mapStage1Source heap kinds selected old width atEdit).1, rfl⟩ + · rw [write.memory _ (Or.inl ⟨p, h.place.tables placed, o, width, al, rfl⟩) atEdit] at tagged ⊢ + exact Or.inl (.step old below width al tagged) + · rw [same, empty o width al] at tagged + exact ((by decide : (0#u64 &&& 3#u64) ≠ 3#u64) tagged).elim + +set_option maxHeartbeats 3000000 in +/-- A PageTable Map adds only the published child to raw Stage-2 reachability. -/ +theorem S1aMapWrite.rawStage2 {ad oldVa : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (member : slot ∈ OS) (before : capA st s slot = .PageTable ptr false ad oldVa) + (selected : S1aSlotAt st Pp n s tag asid va level addr) (target : DescTo word ptr) + (write : S1aMapWrite st OS Pt s q slot addr word cap) + (empty : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa ptr o) = 0#u64) : + let Re' := if tag = 1#u64 then Function.update Re ptr ((level - 12) / 9 - 1) else Re + let bits' := if tag = 1#u64 then Function.update bits ptr 12 else bits + ∀ p, S2Reach st (PoolSet st Pp q) Re' bits' q p → + S2Reach st (PoolSet st Pp s) Re bits s p ∨ (tag = 1#u64 ∧ p = ptr) := by + obtain ⟨tab, pools⟩ := write.keepAsid h heap kinds ptKs selected + have samePools : PoolSet st Pp q = PoolSet st Pp s := tab.poolSet_eq + have unmapped : UnmCap (capA st s slot) ptr 4096 := Or.inl ⟨rfl, ad, oldVa, before⟩ + let Re' := if tag = 1#u64 then Function.update Re ptr ((level - 12) / 9 - 1) else Re + let bits' := if tag = 1#u64 then Function.update bits ptr 12 else bits + change ∀ p, S2Reach st (PoolSet st Pp q) Re' bits' q p → _ + rw [samePools] + intro p reach + induction reach with + | root live bound al tg => + rw [pools _ live _ bound al] at tg ⊢ + exact Or.inl (.root live bound al tg) + | @step p o _ below width al tagged ih => + rcases ih with old | ⟨stage, same⟩ + · have placed := h.core.stage2.reachableMember old + have diff : p ≠ ptr := fun eq => h.core.lookup.unmR2 member unmapped (eq ▸ ⟨placed, old⟩) + have depth : Re' p = Re p := by + dsimp [Re'] + split <;> simp only [Function.update_of_ne diff] + have bitEq : bits' p = bits p := by + dsimp [bits'] + split <;> simp only [Function.update_of_ne diff] + rw [depth] at below + rw [bitEq] at width + by_cases atEdit : wa p o = addr + · rw [atEdit, write.descriptor, target.tableTargets.2] + exact Or.inr ⟨(h.mapStage2Source heap kinds selected old width atEdit).1, rfl⟩ + · have loc := ptw_mono h.place.granules (ptwb_gran h.place.stage2.sz ⟨p, placed, o, width, al, rfl⟩) + rw [write.memory _ (Or.inl loc) atEdit] at tagged ⊢ + exact Or.inl (.step old below width al tagged) + · rw [same] at width tagged + have limit : bits' ptr = 12 := by simp [bits', stage] + rw [limit] at width + rw [empty o width al] at tagged + exact ((by decide : (0#u64 &&& 3#u64) ≠ 3#u64) tagged).elim + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapReference.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapReference.lean new file mode 100644 index 000000000..eb216e0fb --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapReference.lean @@ -0,0 +1,127 @@ +/- +P1 (aarch64): exact reference metadata written by PageTable Map. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapStage2 +import Fl4ProofsA64.P1.S1aR2UnmapAddress +import Fl4ProofsA64.P1.S1aR2PathReference + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {s : S} + {Pp : Set U64} {n tag asid slot : U64} {level address : Nat} + +/-- The walk returns one of the concrete page-table levels. -/ +theorem S1aSlotAt.levels (atSlot : S1aSlotAt st Pp n s tag asid address level slot) : + level = 12 ∨ level = 21 ∨ level = 30 ∨ level = 39 := by + obtain ⟨_, _, _, path, _⟩ := atSlot.entry + exact path.geometry.1 + +/-- Aligning the walked address to the returned level gives the slot's exact base. -/ +theorem S1aSlotAt.alignedAddress (atSlot : S1aSlotAt st Pp n s tag asid address level slot) : + ∃ p b o, S1aPath st Pp n s tag asid level b p ∧ + o.val < s1aTableWidth tag n level ∧ o.val % 8 = 0 ∧ + slot = core.num.U64.wrapping_add p o ∧ + address / 2 ^ level * 2 ^ level = b + o.val / 8 * 2 ^ level ∧ + s1aUserRange tag n (b + o.val / 8 * 2 ^ level) (2 ^ level) := by + obtain ⟨p, b, o, path, width, al, whereAt, baseAligned, low, high, valid⟩ := atSlot.entry + let span : Nat := 2 ^ level + have nonzero : 0 < span := by dsimp [span]; positivity + have divide : span ∣ b + o.val / 8 * span := + Nat.dvd_add ((Nat.pow_dvd_pow 2 (by omega : level ≤ level + 9)).trans (Nat.dvd_of_mod_eq_zero baseAligned)) + ((dvd_refl _).mul_left _) + obtain ⟨page, paged⟩ := divide + have bounds : page * span ≤ address ∧ address < (page + 1) * span := by + have e : b + o.val / 8 * span = page * span := paged.trans (Nat.mul_comm _ _) + change b + o.val / 8 * span ≤ address at low + change address < b + o.val / 8 * span + span at high + rw [e] at low high + refine ⟨low, ?_⟩ + rw [Nat.add_mul, Nat.one_mul] + exact high + have pageEq : address / span = page := by + have lower := (Nat.le_div_iff_mul_le nonzero).2 bounds.1 + have upper := (Nat.div_lt_iff_lt_mul nonzero).2 bounds.2 + omega + refine ⟨p, b, o, path, width, al, whereAt, ?_, valid⟩ + change address / span * span = b + o.val / 8 * span + rw [pageEq, paged, Nat.mul_comm] + +/-- The shift-and-mask expression used by Map saves the selected address prefix. +The bit-vector argument is the same one as x86 IpcBuf's `and_not_mask_toNat`. -/ +theorem s1aMapBase (v scale : U64) {k : Nat} + (bits : k = 12 ∨ k = 21 ∨ k = 30 ∨ k = 39) (scaled : scale.val = 2 ^ k) : + (v &&& ~~~(ws scale 1#u64)).val = v.val / 2 ^ k * 2 ^ k := by + have positive : 0 < scale.val := by rw [scaled]; positivity + have mask : (ws scale 1#u64).val = 2 ^ k - 1 := by + rw [wsub1_le (by omega), scaled] + have shape : (ws scale 1#u64).bv = BitVec.ofNat 64 (2 ^ k - 1) := BitVec.eq_of_toNat_eq (by + rw [BitVec.toNat_ofNat] + have small : k < 64 := by rcases bits with e | e | e | e <;> omega + have power := Nat.pow_lt_pow_right (by decide : 1 < 2) small + exact mask.trans (Nat.mod_eq_of_lt (by omega)).symm) + have e : ~~~(BitVec.ofNat 64 (2 ^ k - 1)) = BitVec.allOnes 64 <<< k := by + rcases bits with rfl | rfl | rfl | rfl <;> decide + change (v.bv &&& ~~~(ws scale 1#u64).bv).toNat = _ + rw [shape, e, ← BitVec.shiftLeft_ushiftRight] + simp only [BitVec.toNat_shiftLeft, BitVec.toNat_ushiftRight, Nat.shiftLeft_eq, Nat.shiftRight_eq_div_pow] + change (v.val / 2 ^ k * 2 ^ k) % 2 ^ 64 = _ + exact Nat.mod_eq_of_lt (lt_of_le_of_lt (Nat.div_mul_le_self _ _) v.bv.isLt) + +/-- The ASID selected by an active path fits the capability's saved field. -/ +theorem S1aPath.asidFits {p : U64} {base : Nat} + (route : S1aPath st Pp n s tag asid level base p) : asid.val < 2 ^ 20 := by + obtain ⟨_, active, _⟩ := route.rootEntry + obtain ⟨i, o, hi, ho, _, value, _⟩ := active + rw [value] + omega + +/-- The Stage-2 bounds check uses the same IPA width as the exact walk. -/ +theorem ept.ipa_limit.exact (n : U64) : + ept.ipa_limit n ⦃ max => max.val + 1 = 2 ^ s1aIpaWidth n ⦄ := by + unfold ept.ipa_limit ept.geom + by_cases small : n ≤ 42#u64 + · rw [ite_eq_left small, bind_ok] + have h : n.val ≤ 42 := small + rw [s1aIpaWidth, ite_eq_left h] + refine WP.spec_bind (U64.ShiftLeft_spec 1#u64 40#u64 (by decide)) fun k hk => ?_ + have e : k = 1099511627776#u64 := UScalar.eq_of_val_eq (by + rw [hk.1] + simp only [show (1#u64 : U64).val = 1 from rfl, + show (40#u64 : U64).val = 40 from rfl, Nat.one_shiftLeft, U64.size, U64.numBits] + norm_num) + subst k + exact (WP.spec_ok _).2 (by decide) + · rw [ite_eq_right small] + by_cases mid : n = 44#u64 + · rw [ite_eq_left mid, bind_ok] + have h : ¬ n.val ≤ 42 := small + have e : n.val = 44 := congrArg UScalar.val mid + rw [s1aIpaWidth, ite_eq_right h, ite_eq_left e] + refine WP.spec_bind (U64.ShiftLeft_spec 1#u64 44#u64 (by decide)) fun k hk => ?_ + have e : k = 17592186044416#u64 := UScalar.eq_of_val_eq (by + rw [hk.1] + simp only [show (1#u64 : U64).val = 1 from rfl, + show (44#u64 : U64).val = 44 from rfl, Nat.one_shiftLeft, U64.size, U64.numBits] + norm_num) + subst k + exact (WP.spec_ok _).2 (by decide) + · rw [ite_eq_right mid, bind_ok] + have h : ¬ n.val ≤ 42 := small + have e : n.val ≠ 44 := fun q => mid (UScalar.eq_of_val_eq q) + rw [s1aIpaWidth, ite_eq_right h, ite_eq_right e] + refine WP.spec_bind (U64.ShiftLeft_spec 1#u64 48#u64 (by decide)) fun k hk => ?_ + have e : k = 281474976710656#u64 := UScalar.eq_of_val_eq (by + rw [hk.1] + simp only [show (1#u64 : U64).val = 1 from rfl, + show (48#u64 : U64).val = 48 from rfl, Nat.one_shiftLeft, U64.size, U64.numBits] + norm_num) + subst k + exact (WP.spec_ok _).2 (by decide) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapRootSlots.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapRootSlots.lean new file mode 100644 index 000000000..a080ced0b --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapRootSlots.lean @@ -0,0 +1,236 @@ +/- +P1 (aarch64): PageTable Map preserves the domains of every live root. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapTypes + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {slot addr word tag asid ptr saved : U64} {level va : Nat} + +private theorem nativeKey (p : U64) (m : Bool) (a : U64) : + RngKeyA (.Pml4 p m a) ∧ ptrA (.Pml4 p m a) = p := by + have phys := physA_eq (.Pml4 p m a) + have pointer := ptrA_eq (.Pml4 p m a) + simp only [objects.cap_is_physical] at phys + simp only [capability.Cap.ptr] at pointer + exact ⟨⟨(okinj phys).symm, rfl, rfl⟩, (okinj pointer).symm⟩ + +/-- When a named object contains the selected slot, its object-relative offset +comes from the corresponding cap kind and the executable user window. -/ +private theorem selectedWithinNamed (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + {x p offset : U64} {z : Nat} (hx : x ∈ OS) (object : H p = some (.other z)) + (key : RngKeyA (capA st s x)) (pointer : ptrA (capA st s x) = p) + (bound : offset.val < 2 ^ z) (address : wa p offset = addr) : + ∃ off : U64, ∃ base : Nat, ∃ y ∈ OS, + MapV (capA st s y) p ∧ ptrA (capA st s y) = p ∧ kindA (capA st s y) = kindA (capA st s x) ∧ + off.val < s1aTableWidth tag n level ∧ + offset.val = (if kindA (capA st s x) = 25 then 4096 else 0) + off.val ∧ + s1aUserRange tag n (base + off.val / 8 * 2 ^ level) (2 ^ level) ∧ + (kindA (capA st s x) = 17 → tag = 0#u64 ∧ level = 39) ∧ + (kindA (capA st s x) = 19 → tag = 1#u64 ∧ level = s1aTopShift 1#u64 n) ∧ + (kindA (capA st s x) = 25 → tag = 2#u64 ∧ level = 30 ∧ base = 2 ^ 64 - 2 ^ 39) := by + obtain ⟨t, base, off, walk, limit, al, position, _, _, _, range⟩ := path.entry + obtain ⟨y, hy, owner, delta, z', obj, _, inside, word, mapped, key', pointer', _, _, offsetEq, _, _, + native, stage2, high⟩ := h.pathStorageOwner walk (lt_of_lt_of_le limit (s1aTableWidth.leStorage tag n level)) + have words := address.trans (position.trans word) + have sameObject : owner = p := by + by_contra ne + exact tableWordsNe heap obj object ne inside bound words.symm + cases sameObject + have kind := kinds.kind y hy x hx key' key (pointer'.trans pointer.symm) + have sameOffset : offset.val = delta.val := by + have fits := heap.fits p _ object + have fits' := heap.fits p _ obj + simp only [HKind.bits] at fits fits' + have e := congrArg UScalar.val words + rw [wadd_val (by omega : p.val + offset.val < 2 ^ 64), + wadd_val (by omega : p.val + delta.val < 2 ^ 64)] at e + omega + rw [kind] at offsetEq native stage2 high + exact ⟨off, base, y, hy, mapped, pointer', kind, limit, sameOffset.trans offsetEq, range, native, stage2, high⟩ + +private theorem rootCapKept (write : S1aMapWrite st OS Pt s q slot addr word (.PageTable ptr true asid saved)) + {x : U64} (hx : x ∈ OS) {cap : capability.Cap} + (different : cap ≠ .PageTable ptr true asid saved) (eq : capA st q x = cap) : + capA st s x = cap := by + by_cases same : x = slot + · rw [same, write.cap] at eq + exact (different eq.symm).elim + · exact (write.other x hx same).symm.trans eq + +set_option maxHeartbeats 3400000 in +/-- An exact user-slot write preserves the root domains when the root caps survive. -/ +theorem S1aMapWrite.rootSlotsOfCaps {written : capability.Cap} (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (write : S1aMapWrite st OS Pt s q slot addr word written) + (keep : ∀ x ∈ OS, ∀ c, (kindA c = 17 ∨ kindA c = 19 ∨ kindA c = 25) → capA st q x = c → capA st s x = c) : + S1aRootSlots st OS Kt n q := by + constructor + · intro x hx p m a cap o ⟨lower, bound⟩ al + have old := keep x hx _ (by simp [kindA]) cap + have obj := h.nativeRoots x hx p m a old + have outside : wa p o ≠ addr := by + intro eq + have keys := nativeKey p m a + obtain ⟨off, _, _, _, _, _, _, width, offset, _, origin, _⟩ := + selectedWithinNamed h heap kinds path hx obj.1 (old ▸ keys.1) (old ▸ keys.2) bound eq + have kind : kindA (capA st s x) = 17 := by rw [old]; rfl + obtain ⟨stage, shift⟩ := origin kind + rw [stage, shift] at width + change off.val < 2048 at width + rw [kind] at offset + simp only [show (17 : Nat) ≠ 25 by decide, if_false, Nat.zero_add] at offset + omega + rw [write.memory _ (Or.inl ⟨p, obj.2, o, bound, al, rfl⟩) outside] + exact h.rootSlots.native x hx p m a old o ⟨lower, bound⟩ al + · intro x hx p m a v cap o ⟨lower, bound⟩ al + have old := keep x hx _ (by simp [kindA]) cap + have obj := h.eptRoots x hx p 0#u64 m a v old + have outside : wa p o ≠ addr := by + intro eq + obtain ⟨off, _, _, _, _, _, _, width, offset, _, _, origin, _⟩ := + selectedWithinNamed h heap kinds path hx obj.1 (old ▸ RngKeyA.ept p 0#u64 m a v) + (old ▸ ptrA_ept p 0#u64 m a v) bound eq + have kind : kindA (capA st s x) = 19 := by rw [old]; rfl + obtain ⟨stage, shift⟩ := origin kind + rw [stage, shift] at width + rw [kind] at offset + simp only [show (19 : Nat) ≠ 25 by decide, if_false, Nat.zero_add] at offset + omega + have word : PtWb {p} (fun _ => 13) (wa p o) := ⟨p, Set.mem_singleton p, o, bound, al, rfl⟩ + have loc := ptw_mono obj.2 (ptwb_gran (fun _ _ => Or.inr rfl) word) + rw [write.memory _ (Or.inl loc) outside] + exact h.rootSlots.stage2 x hx p m a v old o ⟨lower, bound⟩ al + · intro x hx p m a cap o bound al valid + have old := keep x hx _ (by simp [kindA]) cap + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, m, a, old⟩ + have keep := write.highHeader h heap kinds path live o (by omega) al + rw [keep] at valid ⊢ + exact h.rootSlots.highCopies x hx p m a old o bound al valid + · intro x hx p m a cap o unused al + have old := keep x hx _ (by simp [kindA]) cap + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, m, a, old⟩ + have obj := h.highObjects x hx p m a old + have outside : wa (wa p 4096#u64) o ≠ addr := by + intro eq + have granule : (4096#u64 : U64).val = 4096 := rfl + have span : (4096#u64 : U64).val + o.val < 2 ^ 64 := by rw [granule]; have := unused.1; omega + let delta := wa 4096#u64 o + have deltaVal : delta.val = 4096 + o.val := (wadd_val span).trans (congrArg (· + o.val) granule) + have inObject : delta.val < 2 ^ 13 := by rw [deltaVal]; have := unused.1; omega + have atWord : wa p delta = addr := (waddA_assoc p 4096#u64 o span).symm.trans eq + obtain ⟨off, base, _, _, _, _, _, _, offset, range, _, _, origin⟩ := + selectedWithinNamed h heap kinds path hx obj (old ▸ RngKeyA.hv p m a) + (old ▸ ptrA_hv p m a) inObject atWord + have kind : kindA (capA st s x) = 25 := by rw [old]; rfl + obtain ⟨stage, shift, initial⟩ := origin kind + rw [kind] at offset + simp only [ite_eq_left rfl, ite_true, deltaVal] at offset + have same : o.val = off.val := by omega + rw [stage, shift, initial, ← same] at range + simp only [s1aUserRange, show (2#u64 : U64) ≠ 0#u64 by decide, if_false, ite_eq_left rfl, ite_true, + P0.Consts.fl4_abi.consts.HIGH_VSPACE_BASE.val_eq, P0.Consts.fl4_abi.consts.HIGH_VSPACE_TOP.val_eq] at range + norm_num at range + rcases unused.2 with under | over <;> omega + have placed := h.highFootprint ⟨p, live, Or.inr ⟨rfl, rfl⟩⟩ + rw [write.memory _ (Or.inl ⟨_, placed, o, unused.1, al, rfl⟩) outside] + exact h.rootSlots.highPrivate x hx p m a old o unused al + +/-- PageTable Map preserves the approved zero and copied-subtree root slots. -/ +theorem S1aMapWrite.rootSlots (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (write : S1aMapWrite st OS Pt s q slot addr word (.PageTable ptr true asid saved)) : + S1aRootSlots st OS Kt n q := + write.rootSlotsOfCaps h heap kinds path fun x hx c kind eq => + rootCapKept write hx (by + intro same + rw [same] at kind + simp [kindA] at kind) eq + +private theorem mapVNative {p : U64} {c : capability.Cap} + (kind : kindA c = 17) (mapped : MapV c p) : ∃ a, c = .Pml4 p true a := by + cases c <;> simp_all [kindA, MapV] + +private theorem mapVHigh {p : U64} {c : capability.Cap} + (kind : kindA c = 25) (pointer : ptrA c = p) (mapped : MapV c p) : + ∃ a, c = .HighVSpace p true a := by + cases c <;> simp_all [kindA, MapV, ptrA_hv] + exact mapped.elim id And.left + +/-- User-slot writes cannot populate either kind of unassigned Stage-1 root. -/ +theorem S1aMapWrite.emptyRootsOfCaps {written : capability.Cap} (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (write : S1aMapWrite st OS Pt s q slot addr word written) + (keep : ∀ x ∈ OS, ∀ c, (kindA c = 17 ∨ kindA c = 19 ∨ kindA c = 25) → capA st q x = c → capA st s x = c) : + (∀ x ∈ OS, ∀ p a, capA st q x = .Pml4 p false a → + ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa p o) = 0#u64) ∧ + (∀ x ∈ OS, ∀ p a, capA st q x = .HighVSpace p false a → + ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa (wa p 4096#u64) o) = 0#u64) := by + constructor + · intro x hx p a cap o bound al + have old := keep x hx _ (by simp [kindA]) cap + have obj := h.nativeRoots x hx p false a old + have off : wa p o ≠ addr := by + intro eq + have keys := nativeKey p false a + obtain ⟨_, _, y, hy, mapped, _, kind, _⟩ := + selectedWithinNamed h heap kinds path hx obj.1 (old ▸ keys.1) (old ▸ keys.2) bound eq + rw [old] at kind + obtain ⟨other, assigned⟩ := mapVNative kind mapped + have refs := h.capRefs.references x hx y hy (1, p) (by rw [old]; rfl) (by rw [assigned]; rfl) + rw [old, assigned] at refs + cases refs + rw [write.memory _ (Or.inl ⟨p, obj.2, o, bound, al, rfl⟩) off] + exact h.capRefs.nativeEmpty x hx p a old o bound al + · intro x hx p a cap o bound al + have old := keep x hx _ (by simp [kindA]) cap + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, false, a, old⟩ + have off : wa (wa p 4096#u64) o ≠ addr := by + intro eq + have granule : (4096#u64 : U64).val = 4096 := rfl + have span : (4096#u64 : U64).val + o.val < 2 ^ 64 := by rw [granule]; omega + let delta := wa 4096#u64 o + have deltaVal : delta.val = 4096 + o.val := (wadd_val span).trans (congrArg (· + o.val) granule) + have inside : delta.val < 2 ^ 13 := by rw [deltaVal]; omega + have location : wa p delta = addr := (waddA_assoc p 4096#u64 o span).symm.trans eq + obtain ⟨_, _, y, hy, mapped, ptr, kind, _⟩ := + selectedWithinNamed h heap kinds path hx (h.highObjects x hx p false a old) + (old ▸ RngKeyA.hv p false a) (old ▸ ptrA_hv p false a) inside location + rw [old] at kind + obtain ⟨other, assigned⟩ := mapVHigh kind ptr mapped + have refs := h.capRefs.references x hx y hy (3, p) (by rw [old]; rfl) (by rw [assigned]; rfl) + rw [old, assigned] at refs + cases refs + have placed := h.highFootprint ⟨p, live, Or.inr ⟨rfl, rfl⟩⟩ + rw [write.memory _ (Or.inl ⟨_, placed, o, bound, al, rfl⟩) off] + exact h.capRefs.highEmpty x hx p a old o bound al + +/-- An exact user-slot write preserves the empty unassigned Stage-1 roots. -/ +theorem S1aMapWrite.emptyRoots (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) + (path : S1aSlotAt st Pp n s tag asid va level addr) + (write : S1aMapWrite st OS Pt s q slot addr word (.PageTable ptr true asid saved)) : + (∀ x ∈ OS, ∀ p a, capA st q x = .Pml4 p false a → + ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa p o) = 0#u64) ∧ + (∀ x ∈ OS, ∀ p a, capA st q x = .HighVSpace p false a → + ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa (wa p 4096#u64) o) = 0#u64) := + write.emptyRootsOfCaps h heap kinds path fun x hx c kind eq => + rootCapKept write hx (by + intro same + rw [same] at kind + simp [kindA] at kind) eq + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapRoots.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapRoots.lean new file mode 100644 index 000000000..7c3e7fe77 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapRoots.lean @@ -0,0 +1,156 @@ +/- +P1 (aarch64): exact ASID root Map walks. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Domains +import Fl4ProofsA64.P1.S1aR2Assign + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +section roots + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} + +/-- A concrete native ASID lookup seeds the exact user walk. -/ +theorem vspace.find_asid.path (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (asid : U64) : + vspace.find_asid st s asid ⦃ r => ∀ root, r = .Ok root → + S1aPath st Pp n s 0#u64 asid 39 0 root ⦄ := by + unfold vspace.find_asid + refine WP.spec_bind (vspace.find_asid_raw.active h.core.stage1 asid) fun r active => ?_ + rcases r with raw | fault + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, lift, vspace.ROOT_TAG, vspace.ROOT_S1] + split + · exact (WP.spec_ok _).2 fun _ eq => by cases eq + · rename_i tag + refine (WP.spec_ok _).2 fun root eq => ?_ + cases eq + exact .native (active _ rfl) (by apply UScalar.eq_of_val_eq; simpa using tag) + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, bind_tc_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + exact (WP.spec_ok _).2 fun _ eq => by cases eq + +/-- A concrete Stage-2 ASID lookup seeds the walk at the selected top level. -/ +theorem ept.find.path (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (asid : U64) : + ept.find st s asid ⦃ r => ∀ root, r = .Ok root → + S1aPath st Pp n s 1#u64 asid (s1aTopShift 1#u64 n) 0 root ⦄ := by + unfold ept.find + refine WP.spec_bind (vspace.find_asid_raw.active h.core.stage1 asid) fun r active => ?_ + rcases r with raw | fault + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, lift, vspace.ROOT_TAG, vspace.ROOT_S2] + split + · exact (WP.spec_ok _).2 fun _ eq => by cases eq + · rename_i tag + refine (WP.spec_ok _).2 fun root eq => ?_ + cases eq + exact .stage2 (active _ rfl) (by apply UScalar.eq_of_val_eq; simpa using tag) + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, bind_tc_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + exact (WP.spec_ok _).2 fun _ eq => by cases eq + +/-- The Stage-2 root check seeds the active walk at the configured top level. -/ +theorem ept.root.path (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (c : capability.Cap) (arg : U64) : + ept.root st s c arg ⦃ r => ∀ v, r = .Ok v → + S1aPath st Pp n s 1#u64 v.2 (s1aTopShift 1#u64 n) 0 v.1 ⦄ := by + unfold ept.root + split + all_goals try (simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun v e => by cases e) + split + all_goals try (simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun v e => by cases e) + split + all_goals try (simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun v e => by cases e) + refine WP.spec_bind (ept.find.path h _) fun r hr => ?_ + refine WP.spec_bind (root_map_ok (st := st) r) fun r1 hr1 => ?_ + rcases r1 with v | e + · simp only [irq_branch_ok, bind_ok] + split + · simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun w e => by cases e + · exact (WP.spec_ok _).2 fun w e => by cases e; exact hr v (hr1 v rfl) + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, + core.convert.FromSame.from, bind_tc_ok] + exact (WP.spec_ok _).2 fun w e => by cases e + +/-- A concrete HighVSpace lookup enters the private level-1 granule. -/ +theorem vspace.find_high_asid.path (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (asid : U64) : + vspace.find_high_asid st s asid ⦃ r => ∀ root, r = .Ok root → + S1aPath st Pp n s 2#u64 asid 30 (2 ^ 64 - 2 ^ 39) + (core.num.U64.wrapping_add root 4096#u64) ⦄ := by + unfold vspace.find_high_asid + refine WP.spec_bind (vspace.find_asid_raw.active h.core.stage1 asid) fun r result => ?_ + rcases r with raw | fault + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, lift, vspace.ROOT_TAG, vspace.ROOT_HIGH] + split + · exact (WP.spec_ok _).2 fun _ eq => by cases eq + · rename_i tagged + have tag : raw &&& 3#u64 = 2#u64 := by + apply UScalar.eq_of_val_eq + simpa using tagged + have entry := result raw rfl + obtain ⟨x, hx, cap⟩ := h.core.root.backed asid raw entry + rw [tag] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, found⟩ + · exact ((by decide : 2#u64 ≠ 0#u64) bad).elim + · exact ((by decide : 2#u64 ≠ 1#u64) bad).elim + · have live : raw &&& ~~~3#u64 ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, asid, found⟩ + refine (WP.spec_ok _).2 fun root eq => ?_ + cases eq + rw [← h.highLink _ live] + exact .high entry tag (h.highHeaders x hx _ true asid found) + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, bind_tc_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + exact (WP.spec_ok _).2 fun _ eq => by cases eq + +/-- The native root check returns the root and ASID of the active path. -/ +theorem vspace.check_vspace.path (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (c : capability.Cap) (arg : U64) : + vspace.check_vspace st s c arg ⦃ r => ∀ root asid, r = .Ok (root, asid) → + c = .Pml4 root true asid ∧ S1aPath st Pp n s 0#u64 asid 39 0 root ⦄ := by + unfold vspace.check_vspace + split + all_goals try (simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun _ _ e => by cases e) + split + all_goals try (simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun _ _ e => by cases e) + rename_i mapped + simp only [vspace.find_vspace_for_asid] + refine WP.spec_bind (vspace.find_asid.path h _) fun r path => ?_ + rcases r with root | e + · dsimp only + split + · simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun _ _ e => by cases e + · rename_i same + simp only [bne_iff_ne, ne_eq, Decidable.not_not] at same + subst same + exact (WP.spec_ok _).2 fun _ _ e => by cases e; exact ⟨by rw [mapped], path _ rfl⟩ + · exact (WP.spec_ok _).2 fun _ _ e => by cases e + +/-- The HighVSpace root check returns a native high root and its private path. -/ +theorem vspace.check_high_vspace.path (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (c : capability.Cap) (arg : U64) : + vspace.check_high_vspace st s c arg ⦃ r => ∀ root asid, r = .Ok (root, asid) → + c = .HighVSpace root true asid ∧ S1aPath st Pp n s 2#u64 asid 30 (2 ^ 64 - 2 ^ 39) + (core.num.U64.wrapping_add root 4096#u64) ⦄ := by + unfold vspace.check_high_vspace + split + all_goals try (simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun _ _ e => by cases e) + split + all_goals try (simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun _ _ e => by cases e) + rename_i mapped + refine WP.spec_bind (vspace.find_high_asid.path h _) fun r path => ?_ + rcases r with root | e + · dsimp only + split + · simp only [error.invalid_cap]; exact (WP.spec_ok _).2 fun _ _ e => by cases e + · rename_i same + simp only [bne_iff_ne, ne_eq, Decidable.not_not] at same + subst same + exact (WP.spec_ok _).2 fun _ _ e => by cases e; exact ⟨by rw [mapped], path _ rfl⟩ + · exact (WP.spec_ok _).2 fun _ _ e => by cases e + +end roots + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapStage1Post.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapStage1Post.lean new file mode 100644 index 000000000..287d9b0a5 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapStage1Post.lean @@ -0,0 +1,227 @@ +/- +P1 (aarch64): the Stage-1 PageTable Map publication. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapHigh +import Fl4ProofsA64.P1.S1aR2MapReference +import Fl4ProofsA64.P1.S1aR2MapRoots +import Fl4ProofsA64.P1.S1aR2MapStage2Post +import Fl4ProofsA64.P1.S1aR2MapWrite +import Fl4ProofsA64.P1.S1aR2MapNative + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt Cs Vc Ub U Ac : Set U64} {Lv Re bits : U64 → Nat} + {n tag : U64} {s : S} {cap : capability.Cap} {slot ptr : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +private theorem highCanonical (v : U64) (lo : 2 ^ 64 - 2 ^ 47 ≤ v.val) : + CapRt.Canonical v := by + apply Or.inr + have vLt := v.bv.isLt + have small : (~~~v.bv).toNat < 2 ^ 47 := by + rw [BitVec.toNat_not] + change 2 ^ 64 - 1 - v.val < 2 ^ 47 + omega + intro j hj ge + have zero := CapRt.high_bits_false small j hj ge + simpa using zero + +/-- A successful table publication uses the aligned base of the chosen user slot. -/ +structure S1aTableMap (st : machine.Store S) [L : LawfulStore st] + (OS Pt Pp : Set U64) (n tag : U64) (s q : S) (slot ptr : U64) : Prop where + edit : ∃ asid va saved addr word : U64, ∃ level : Nat, + S1aSlotAt st Pp n s tag asid va.val level addr ∧ 12 < level ∧ + L.mem s addr &&& 1#u64 = 0#u64 ∧ + (word &&& 3#u64) = 3#u64 ∧ DescTo word ptr ∧ + s1aCapAddress tag n saved = va.val / 2 ^ level * 2 ^ level ∧ + S1aMapWrite st OS Pt s q slot addr word (.PageTable ptr true asid saved) + +private theorem mapStage1Cap {asid va shift addr scale : U64} + (kind : tag = 0#u64 ∨ tag = 2#u64) + (atSlot : S1aSlotAt st Pp n s tag asid va.val shift.val addr) + (ptrCanon : CapRt.Canonical ptr) (scaled : scale.val = 2 ^ shift.val) : + let saved := va &&& ~~~(ws scale 1#u64) + let mapped := capability.Cap.PageTable ptr true asid saved + saved.val = va.val / 2 ^ shift.val * 2 ^ shift.val ∧ + CapRt.decodeF (CapRt.encodeF mapped).1 (CapRt.encodeF mapped).2 = mapped := by + dsimp only + let saved := va &&& ~~~(ws scale 1#u64) + have valEq := s1aMapBase va scale atSlot.levels scaled + obtain ⟨_, _, _, path, _, _, _, base, range⟩ := atSlot.alignedAddress + have savedAt : saved.val = _ := valEq.trans base + have canon : CapRt.Canonical saved := by + rw [← savedAt] at range + rcases kind with rfl | rfl + · have low : saved.val < 2 ^ 47 := by + simp only [s1aUserRange, ite_eq_left rfl, ite_true, + P0.Consts.fl4_abi.consts.USER_TOP.val_eq] at range + have pos : 0 < 2 ^ shift.val := by positivity + rw [savedAt] at range ⊢ + omega + exact Or.inl (CapRt.high_bits_false low) + · simp only [s1aUserRange, show (2#u64 : U64) ≠ 0#u64 by decide, ite_false, ite_eq_left rfl, + ite_true, P0.Consts.fl4_abi.consts.HIGH_VSPACE_BASE.val_eq] at range + exact highCanonical saved (le_trans (by decide) range.1) + exact ⟨valEq, CapRt.rt_PageTable ptr true asid saved ⟨ptrCanon, path.asidFits, canon⟩⟩ + +set_option hygiene false in +/-- Shared publication after a Stage-1 walk has selected its parent slot. -/ +local macro "stage1TableTail" "[" stage:term "," stageTag:term "]" : tactic => `(tactic| ( + rw [L.read_eq, bind_ok, eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, bind_ok] + try simp only [lift, bind_ok] + refine spec_ite (fun _ => (WP.spec_ok _).2 (Or.inl rfl)) (fun old => ?_) + have invalid : L.mem s lu.slot &&& 1#u64 = 0#u64 := by + simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using old + have levels := found.levels + have shiftLt : lu.shift.val < 64 := by rcases levels with e | e | e | e <;> omega + have nonSmall : lu.shift.val ≠ 12 := by + intro small + apply nonLeaf + exact UScalar.eq_of_val_eq (small.trans P0.Consts.vspace.PAGE_BITS.val_eq.symm) + have above : 12 < lu.shift.val := by rcases levels with e | e | e | e <;> omega + refine WP.spec_bind (shl1_val shiftLt) fun scale scaled => ?_ + obtain ⟨saved, capEq⟩ := mapStage1Cap $stage found ptrCanon scaled + try simp only [lift, bind_ok] + refine WP.spec_bind (sched.set_thread_state.mapCap vr os hx d) fun q hcap => ?_ + refine WP.spec_bind (hcap _ _ capEq) fun m ⟨ks, same, written, other⟩ => ?_ + refine WP.spec_bind (paddr_spec ptr) fun pa eq => ?_ + subst pa + have physical := paddr_ok ptrCanon ptrAligned + refine WP.spec_bind (s1tab_v _ physical.1 physical.2) fun word ⟨valid, target⟩ => ?_ + obtain ⟨_, _, _, path, width, al, position, _, _⟩ := found.entry + have address : PtW Pt lu.slot := position ▸ h.pathWord path width al + have aw := vr.al _ (Or.inl address) + refine WP.spec_bind (LawfulStore.write_spec m lu.slot word) fun out eq => ?_ + subst out + have publication : S1aTableMap st OS Pt Pp n $stageTag s (L.wr m lu.slot word) slot ptr := + ⟨asid, va, _, lu.slot, word, lu.shift.val, found, above, invalid, valid, descTo_of target, + by simpa only [s1aCapAddress, ite_eq_right (by decide : $stageTag ≠ 1#u64)] using saved, + S1aMapWrite.ofTail vr os hx ks same written other address (writesIn_wr aw) (L.mem_wr_same aw)⟩ + first + | exact (WP.spec_ok _).2 (Or.inr publication) + | exact (WP.spec_ok _).2 (Or.inr ⟨$stageTag, publication⟩))) + +set_option maxHeartbeats 2600000 in +/-- HighVSpace PageTable Map publishes a typed descriptor and the saved private-walk address. -/ +theorem vspace.map_high_page_table.exactEffect + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (os : OSOK H.tcbs H.omega H.frame OS) (hx : slot ∈ OS) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (ptrCanon : CapRt.Canonical ptr) (ptrAligned : ptr.val % 4096 = 0) + {x : U64} (live : x ∈ OS) {vcap : capability.Cap} (rootCap : capA st s x = vcap) (va : U64) : + vspace.map_high_page_table st s slot ptr vcap va ⦃ r => + r.2 = s ∨ S1aTableMap st OS Pt Pp n 2#u64 s r.2 slot ptr ⦄ := by + unfold vspace.map_high_page_table + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (vspace.check_high_vspace.path h vcap 1#u64) fun r selected => ?_ + rcases r with ⟨root, asid⟩ | e + swap + · simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, bind_tc_ok, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + exact (WP.spec_ok _).2 (Or.inl rfl) + obtain ⟨capEq, route⟩ := selected root asid rfl + have rootAt := rootCap.trans capEq + have liveRoot : root ∈ Hr := by rw [h.highRoots]; exact ⟨x, live, true, asid, rootAt⟩ + have header := h.highHeaders x live root true asid rootAt + rw [← h.highLink root liveRoot] at route + simp only [irq_branch_ok, bind_ok, lift] + refine spec_ite (fun _ => by simp only [error.invalid_arg, bind_ok]; exact (WP.spec_ok _).2 (Or.inl rfl)) (fun lo => ?_) + refine spec_ite (fun _ => by simp only [error.invalid_arg, bind_ok]; exact (WP.spec_ok _).2 (Or.inl rfl)) (fun hi => ?_) + have low : fl4_abi.consts.HIGH_VSPACE_BASE.val ≤ va.val := Nat.le_of_not_gt lo + have high : va.val < fl4_abi.consts.HIGH_VSPACE_TOP.val := Nat.lt_of_not_ge hi + refine WP.spec_bind (vspace.lookup_pt_slot.highPath root va header route low high) fun lu found => ?_ + refine spec_ite (fun _ => (WP.spec_ok _).2 (Or.inl rfl)) (fun nonLeaf => ?_) + refine spec_ite (fun _ => (WP.spec_ok _).2 (Or.inl rfl)) (fun _ => ?_) + stage1TableTail [Or.inr rfl, 2#u64] + +set_option hygiene false in +local macro "tableMapError" : tactic => `(tactic| first + | exact (WP.spec_ok _).2 (Or.inl rfl) + | (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.truncated, error.invalid_cap, error.invalid_arg] + exact (WP.spec_ok _).2 (Or.inl rfl))) + +set_option maxHeartbeats 3600000 in +/-- PageTable Map reports the exact publication for each accepted root kind. -/ +theorem vspace.decode_page_table.mapExactEffect {A : Type _} {ar : machine.Arch A} + {Rp Nt : Set U64} {ad oldVa : U64} + (hPl : ArchPlat ar) (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.PageTable ptr false ad oldVa) extra) + (ptrCanon : CapRt.Canonical ptr) (ptrAligned : ptr.val % 4096 = 0) + (a : A) (len buf : U64) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableMap len slot + (.PageTable ptr false ad oldVa) buf extra ⦃ r => r.2.1 = s ∨ + ∃ tag, S1aTableMap st OS Pt Pp hPl.ipa tag s r.2.1 slot ptr ⦄ := by + have hne : fl4_abi.label.ARMPageTableMap ≠ fl4_abi.label.ARMPageTableUnmap := lbl_ne_of_val + (by simp [fl4_abi.label.ARMPageTableMap, fl4_abi.label.ARMPageTableUnmap]) + let n := hPl.ipa + have os := P.os + have hx := P.src + unfold vspace.decode_page_table + rw [cur_thread_ok, bind_ok] + dsimp only + have hsame : (fl4_abi.label.ARMPageTableMap != fl4_abi.label.ARMPageTableMap) = false := by simp + simp only [hne, hsame, Bool.false_eq_true, ↓reduceIte] + refine WP.spec_bind (vspace.extra.memA extra 0#usize) fun x read => ?_ + rcases x with _ | x + · tableMapError + have live := P.ext x (read x rfl).1 (read x rfl).2 + try dsimp only + refine spec_ite (fun _ => ?_) (fun _ => by tableMapError) + refine WP.spec_bind (P0.msg.syscall_arg.p0 st s _ buf _ L.total) fun va _ => ?_ + rw [capA_eq, bind_ok] + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun high _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine WP.spec_bind (vspace.map_high_page_table.exactEffect h vr os hx d ptrCanon ptrAligned live rfl va) ?_ + rintro ⟨r, q⟩ (eq | effect) + · exact (WP.spec_ok _).2 (Or.inl eq) + · exact (WP.spec_ok _).2 (Or.inr ⟨2#u64, effect⟩) + refine WP.spec_bind (P0.vspace.is_valid_vtable_root.p0 (capA st s x)) fun valid _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => by tableMapError) + refine WP.spec_bind (Pₘ := fun _ => True) (by split <;> exact (WP.spec_ok _).2 trivial) fun stage2 _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine WP.spec_bind (ept.root.path h _ 1#u64) fun r selected => ?_ + rcases r with ⟨root, asid⟩ | e + swap + · tableMapError + simp only [irq_branch_ok, bind_ok] + refine WP.spec_mono (ept.map_table.exactEffect hPl h vr os hx d (selected _ rfl) ptrCanon ptrAligned a) ?_ + rintro ⟨r, q, b⟩ (eq | ⟨lu, word, saved, found, nonLeaf, invalid, valid, target, aligned, write⟩) + · exact Or.inl eq + have above : 12 < lu.shift.val := by + have nonSmall : lu.shift.val ≠ 12 := by + intro small + apply nonLeaf + exact UScalar.eq_of_val_eq (small.trans P0.Consts.ept.PAGE_BITS.val_eq.symm) + rcases found.levels with e | e | e | e <;> omega + exact Or.inr ⟨1#u64, ⟨asid, va, saved, lu.slot, word, lu.shift.val, + found, above, invalid, valid, target, aligned, write⟩⟩ + refine spec_ite (fun _ => by tableMapError) (fun bounded => ?_) + have lower : va.val < 2 ^ 47 := by + have notAbove : ¬ fl4_abi.consts.USER_TOP.val < va.val := bounded + rw [P0.Consts.fl4_abi.consts.USER_TOP.val_eq] at notAbove + omega + refine WP.spec_bind (vspace.check_vspace.path h _ 1#u64) fun r selected => ?_ + rcases r with ⟨root, asid⟩ | e + swap + · tableMapError + simp only [irq_branch_ok, bind_ok] + have route := (selected root asid rfl).2 + refine WP.spec_bind (vspace.lookup_pt_slot.nativePath root va route lower) fun lu found => ?_ + refine spec_ite (fun _ => (WP.spec_ok _).2 (Or.inl rfl)) (fun nonLeaf => ?_) + stage1TableTail [Or.inl rfl, 0#u64] + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapStage2.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapStage2.lean new file mode 100644 index 000000000..93e312886 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapStage2.lean @@ -0,0 +1,120 @@ +/- +P1 (aarch64): exact Stage-2 Map walks. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapWalk + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +section walk +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {Pp : Set U64} {n tag asid : U64} {s : S} {address : Nat} + +theorem ept.geom.exact (n : U64) : + ept.geom n ⦃ g => g.top_shift.val = s1aTopShift 1#u64 n ∧ + g.top_shift.val ≤ s1aIpaWidth n ∧ + g.top_mask.val = 2 ^ (s1aIpaWidth n - g.top_shift.val) - 1 ∧ + g.top_mask.val ≤ 1023 ∧ (g.levels.val = 3 ∧ g.top_shift.val = 30 ∨ + g.levels.val = 4 ∧ g.top_shift.val = 39) ⦄ := by + unfold ept.geom + split + · rename_i small + have h : n.val ≤ 42 := by scalar_tac + exact (WP.spec_ok _).2 (by simp [s1aTopShift, s1aIpaWidth, h] <;> decide) + · rename_i large + have h : ¬ n.val ≤ 42 := by scalar_tac + split + · rename_i bits + have w : n.val = 44 := by scalar_tac + exact (WP.spec_ok _).2 (by simp [s1aTopShift, s1aIpaWidth, h, w] <;> decide) + · rename_i bits + have w : n.val ≠ 44 := by scalar_tac + exact (WP.spec_ok _).2 (by simp [s1aTopShift, s1aIpaWidth, h, w] <;> decide) + +private theorem s1aRootBlock (value count unit : Nat) (countPos : 0 < count) (unitPos : 0 < unit) : + let index := (value / unit) % count + let start := index * unit + start ≤ value % (count * unit) ∧ value % (count * unit) < start + unit ∧ start + unit ≤ count * unit := by + let index := value / unit % count + let start := index * unit + have iBound : index < count := Nat.mod_lt _ countPos + have remBound : value % unit < unit := Nat.mod_lt _ unitPos + have last : start + unit ≤ count * unit := by + have bound := Nat.mul_le_mul_right unit (show index + 1 ≤ count by omega) + simpa [Nat.add_mul, start] using bound + have interval : start + value % unit < count * unit := by omega + have decompose : value = value / unit / count * (count * unit) + (start + value % unit) := by + have q := Nat.div_add_mod (value / unit) count + calc + value = value / unit * unit + value % unit := by rw [Nat.mul_comm]; exact (Nat.div_add_mod _ _).symm + _ = (count * (value / unit / count) + index) * unit + value % unit := by rw [q] + _ = _ := by dsimp only [start]; ring + have normal : value % (count * unit) = start + value % unit := by + conv_lhs => lhs; rw [decompose] + rw [Nat.add_mod, Nat.mul_mod, Nat.mod_self, Nat.mul_zero, Nat.zero_mod, Nat.zero_add, Nat.mod_mod] + exact Nat.mod_eq_of_lt interval + change start ≤ value % (count * unit) ∧ value % (count * unit) < start + unit ∧ start + unit ≤ count * unit + rw [normal] + omega + +/-- A Stage-2 walk uses all and only the selected IPA bits from its root onwards. -/ +theorem ept.lookup_slot.exactStop (root ipa : U64) + (path : S1aPath st Pp n s 1#u64 asid (s1aTopShift 1#u64 n) 0 root) : + ept.lookup_slot st s root ipa n ⦃ result => + S1aSlotAt st Pp n s 1#u64 asid (s1aCapAddress 1#u64 n ipa) result.shift.val result.slot ∧ + (12 < result.shift.val → (L.mem s result.slot &&& 3#u64) ≠ 3#u64) ⦄ := by + unfold ept.lookup_slot + refine WP.spec_bind (ept.geom.exact n) fun g ⟨top, width, mask, maskBound, levels⟩ => ?_ + have shBound : g.top_shift.val < 64 := by omega + refine WP.spec_bind (ept.entry_addr.exactOffset root ipa g.top_shift g.top_mask shBound maskBound) ?_ + rintro slot ⟨off, offset, location⟩ + simp only [lift, bind_ok] + let count := 2 ^ (s1aIpaWidth n - g.top_shift.val) + let unit := 2 ^ g.top_shift.val + have countPos : 0 < count := by dsimp [count]; positivity + have unitPos : 0 < unit := by dsimp [unit]; positivity + have total : count * unit = 2 ^ s1aIpaWidth n := by + dsimp only [count, unit] + rw [← Nat.pow_add, Nat.sub_add_cancel width] + have offsetEq : off.val = ipa.val / unit % count * 8 := by + rw [offset, mask, Nat.shiftRight_eq_div_pow, Nat.and_two_pow_sub_one_eq_mod] + have slotIndex : off.val / 8 = ipa.val / unit % count := by omega + have below := Nat.mod_lt (ipa.val / unit) countPos + have covers := s1aRootBlock ipa.val count unit countPos unitPos + have base : S1aSlotAt st Pp n s 1#u64 asid (s1aCapAddress 1#u64 n ipa) g.top_shift.val slot := by + refine ⟨root, 0, off, top ▸ path, ?_, by omega, location, by simp, ?_⟩ + · unfold s1aTableWidth + rw [ite_eq_left top] + change off.val < 8 * count + omega + · simp only [Nat.zero_add, slotIndex, s1aCapAddress, s1aUserRange, ↓reduceIte] + change (ipa.val / unit % count) * unit ≤ ipa.val % 2 ^ s1aIpaWidth n ∧ + ipa.val % 2 ^ s1aIpaWidth n < (ipa.val / unit % count) * unit + unit ∧ + (ipa.val / unit % count) * unit + unit ≤ 2 ^ s1aIpaWidth n + rw [← total] + exact covers + let rem := core.num.U64.wrapping_sub g.levels 1#u64 + have remVal : rem.val = g.levels.val - 1 := by + dsimp only [rem] + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits] + omega + refine WP.spec_bind (ept.lookup_slot_loop.exactStop (tag := 1#u64) (asid := asid) + (address := s1aCapAddress 1#u64 n ipa) ipa g.top_shift slot rem + (fun k h => by simpa [s1aCapAddress] using s1aIpaChildIndex n ipa.val k h) + (show _ from ⟨by simp only; omega, by simp only; omega, base⟩)) ?_ + rintro ⟨_, _⟩ exactSlot + exact (WP.spec_ok _).2 exactSlot + +/-- A Stage-2 walk selects an exact slot at the effective IPA. -/ +theorem ept.lookup_slot.exactPath (root ipa : U64) + (path : S1aPath st Pp n s 1#u64 asid (s1aTopShift 1#u64 n) 0 root) : + ept.lookup_slot st s root ipa n ⦃ result => + S1aSlotAt st Pp n s 1#u64 asid (s1aCapAddress 1#u64 n ipa) result.shift.val result.slot ⦄ := + WP.spec_mono (ept.lookup_slot.exactStop root ipa path) fun _ found => found.1 + +end walk + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapStage2Post.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapStage2Post.lean new file mode 100644 index 000000000..cc7e3688a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapStage2Post.lean @@ -0,0 +1,79 @@ +/- +P1 (aarch64): exact historical state for a Stage-2 table map. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapReference +import Fl4ProofsA64.P1.S1aR2MapWrite +import Fl4ProofsA64.P1.S1aR2Transport + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {A : Type _} {ar : machine.Arch A} + {H : Heap} {OS Pt Pp Tb Hr Te Kt Cs Vc Ub U Ac : Set U64} {Lv Re bits : U64 → Nat} + {s : S} {cap : capability.Cap} {slot ptr root asid ipa : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +set_option maxHeartbeats 3000000 in +/-- Stage-2 PageTable Map returns the selected active slot, the table descriptor, +and the exact cap written after the caller restart. -/ +theorem ept.map_table.exactEffect (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (os : OSOK H.tcbs H.omega H.frame OS) (hx : slot ∈ OS) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (route : S1aPath st Pp hPl.ipa s 1#u64 asid (s1aTopShift 1#u64 hPl.ipa) 0 root) + (canonical : CapRt.Canonical ptr) (aligned : ptr.val % 4096 = 0) (a : A) : + ept.map_table st ar s a root asid ipa ptr slot ⦃ _ out _ => out = s ∨ + ∃ lu : ept.S2Slot, ∃ word saved : U64, + S1aSlotAt st Pp hPl.ipa s 1#u64 asid ipa.val lu.shift.val lu.slot ∧ + lu.shift ≠ ept.PAGE_BITS ∧ L.mem s lu.slot &&& 1#u64 = 0#u64 ∧ + (word &&& 3#u64) = 3#u64 ∧ DescTo word ptr ∧ + s1aCapAddress 1#u64 hPl.ipa saved = ipa.val / 2 ^ lu.shift.val * 2 ^ lu.shift.val ∧ + S1aMapWrite st OS Pt s out slot lu.slot word (.PageTable ptr true asid saved) ⦄ := by + unfold ept.map_table + rw [hPl.ipa_eq a, bind_ok] + refine WP.spec_bind (ept.ipa_limit.exact _) fun max limit => ?_ + refine spec_ite (fun _ => by simp only [error.invalid_arg, bind_ok]; exact (WP.spec_ok _).2 (Or.inl rfl)) + (fun bounded => ?_) + have ipaLt : ipa.val < 2 ^ s1aIpaWidth hPl.ipa := by + have below : ¬ max.val < ipa.val := bounded + omega + refine WP.spec_bind (ept.lookup_slot.exactPath root ipa route) fun lu found => ?_ + have atIpa : S1aSlotAt st Pp hPl.ipa s 1#u64 asid ipa.val lu.shift.val lu.slot := by + simpa only [s1aCapAddress, ite_eq_left rfl, ite_true, Nat.mod_eq_of_lt ipaLt] using found + have levels := atIpa.levels + have shiftLt : lu.shift.val < 64 := by rcases levels with e | e | e | e <;> omega + refine spec_ite (fun _ => (WP.spec_ok _).2 (Or.inl rfl)) (fun nonLeaf => ?_) + rw [L.read_eq, bind_ok, eq_of_spec_fd P0.Consts.ept.D_VALID.spec, bind_ok] + simp only [lift, bind_ok] + refine spec_ite (fun _ => (WP.spec_ok _).2 (Or.inl rfl)) (fun old => ?_) + have invalid : L.mem s lu.slot &&& 1#u64 = 0#u64 := by + simpa only [bne_iff_ne, ne_eq, Decidable.not_not] using old + refine WP.spec_bind (shl1_val shiftLt) fun scale scaled => ?_ + let base := ipa &&& ~~~(core.num.U64.wrapping_sub scale 1#u64) + have baseValue : base.val = ipa.val / 2 ^ lu.shift.val * 2 ^ lu.shift.val := + s1aMapBase ipa scale levels scaled + have baseBound : base.val < 2 ^ s1aIpaWidth hPl.ipa := + lt_of_le_of_lt (baseValue.symm ▸ Nat.div_mul_le_self ipa.val _) ipaLt + obtain ⟨saved, decode, savedValue⟩ := s1aPageTableEncodeS2 ptr asid base hPl.ipa canonical route.asidFits baseBound + try simp only [lift, bind_ok] + rw [cur_thread_ok, bind_ok] + refine WP.spec_bind (sched.set_thread_state.mapCap vr os hx d) fun q hcap => ?_ + refine WP.spec_bind (hcap _ _ decode) fun m ⟨ks, same, written, other⟩ => ?_ + refine WP.spec_bind (paddr_spec ptr) fun pa eq => ?_ + subst pa + have addr := paddr_ok canonical aligned + refine WP.spec_bind (s2tab_v _ addr.1 addr.2) fun word ⟨valid, target⟩ => ?_ + obtain ⟨t, b, o, path, width, al, position, _, _⟩ := found.entry + have address : PtW Pt lu.slot := position ▸ h.pathWord path width al + have aw := vr.al _ (Or.inl address) + refine WP.spec_bind (LawfulStore.write_spec m lu.slot word) fun out eq => ?_ + subst out + exact (WP.spec_ok _).2 (Or.inr ⟨lu, word, saved, atIpa, nonLeaf, invalid, valid, descTo_ofE target, + savedValue.trans baseValue, S1aMapWrite.ofTail vr os hx ks same written other address (writesIn_wr aw) (L.mem_wr_same aw)⟩) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapTypes.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapTypes.lean new file mode 100644 index 000000000..fa9460b70 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapTypes.lean @@ -0,0 +1,154 @@ +/- +P1 (aarch64): active VSpace typing after the PageTable descriptor write. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapReach + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s q : S} {slot addr word tag asid ptr : U64} {level va : Nat} {cap : capability.Cap} + +set_option maxHeartbeats 3500000 in +/-- The Stage-1 typing changes depth only at the newly mapped PageTable. -/ +theorem S1aMapWrite.stage1Typed {ad oldVa : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (member : slot ∈ OS) (before : capA st s slot = .PageTable ptr false ad oldVa) + (walk : S1aSlotAt st Pp n s tag asid va level addr) (target : DescTo word ptr) + (write : S1aMapWrite st OS Pt s q slot addr word cap) + (empty : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa ptr o) = 0#u64) : + let Tb' := if tag = 1#u64 then Tb else insert ptr Tb + let Lv' := if tag = 1#u64 then Lv else Function.update Lv ptr ((39 - level) / 9 + 1) + VsTyR st (L.ksb q) (PoolSet st Pp q) ∅ Tb' Lv' q := by + let Tb' := if tag = 1#u64 then Tb else insert ptr Tb + let Lv' := if tag = 1#u64 then Lv else Function.update Lv ptr ((39 - level) / 9 + 1) + change VsTyR st (L.ksb q) (PoolSet st Pp q) ∅ Tb' Lv' q + obtain ⟨tab, pools⟩ := write.keepAsid h heap kinds ptKs walk + have unmapped : UnmCap (capA st s slot) ptr 4096 := Or.inl ⟨rfl, ad, oldVa, before⟩ + have keepLevel (p : U64) (reach : VsReach st (PoolSet st Pp s) ∅ Lv s p) : Lv' p = Lv p := by + have diff : p ≠ ptr := fun e => h.core.lookup.unmR1 member unmapped + (e ▸ ⟨h.core.stage1.reachableMember reach, reach⟩) + dsimp [Lv'] + split <;> simp only [Function.update_of_ne diff] + have embed : Tb ⊆ Tb' := by + intro p hp + dsimp [Tb'] + split + · exact hp + · exact Set.mem_insert_of_mem _ hp + have raw := write.rawStage1 h heap kinds ptKs member before walk target empty + refine ⟨?_, ?_, ?_⟩ + · intro o lo hi al nz + rw [tab.off lo hi al] at nz ⊢ + have p := h.core.stage1.tbl o lo hi al nz + rw [tab.poolSet_eq] + exact p + · intro p hp o bound al nz + have hp' : p ∈ PoolSet st Pp s := tab.poolSet_eq ▸ hp + rw [pools p hp' o bound al] at nz ⊢ + have flags := h.core.stage1.pool p hp' o bound al nz + constructor + · intro tagged + have root : VsReach st (PoolSet st Pp s) ∅ Lv s (L.mem s (wa p o)) := + .root0 hp' bound al nz tagged + obtain ⟨inTables, depth⟩ := flags.1 tagged + exact ⟨embed inTables, (keepLevel _ root).trans depth⟩ + · intro tagged + have root : VsReach st (PoolSet st Pp s) ∅ Lv s (L.mem s (wa p o) &&& ~~~3#u64) := + .root2 hp' bound al tagged + obtain ⟨inTables, depth⟩ := flags.2 tagged + exact ⟨embed inTables, (keepLevel _ root).trans depth⟩ + · intro p _ reach depth o bound al tagged + rcases raw p reach with prior | ⟨_, rfl⟩ + · have atParent := keepLevel p prior + rw [atParent] at depth ⊢ + have placed := h.core.stage1.reachableMember prior + by_cases changed : wa p o = addr + · obtain ⟨stage, selectedLevel⟩ := h.mapStage1Source heap kinds walk prior bound changed + rw [changed, write.descriptor, target.tableTargets.1] + have lv : (39 - level) / 9 = Lv p := by omega + simp [Tb', Lv', stage, lv] + · have location : PtW Pt (wa p o) := ⟨p, h.place.tables placed, o, bound, al, rfl⟩ + rw [write.memory _ (Or.inl location) changed] at tagged ⊢ + obtain ⟨child, childDepth⟩ := h.core.stage1.desc p placed prior depth o bound al tagged + have oldChild := VsReach.step prior depth bound al tagged + exact ⟨embed child, (keepLevel _ oldChild).trans childDepth⟩ + · rw [empty o bound al] at tagged + exact ((by decide : (0#u64 &&& 3#u64) ≠ 3#u64) tagged).elim + +set_option maxHeartbeats 3500000 in +/-- The Stage-2 typing adds the published child at the selected IPA level. -/ +theorem S1aMapWrite.stage2Typed {ad oldVa : U64} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (member : slot ∈ OS) (before : capA st s slot = .PageTable ptr false ad oldVa) + (walk : S1aSlotAt st Pp n s tag asid va level addr) (target : DescTo word ptr) + (write : S1aMapWrite st OS Pt s q slot addr word cap) + (empty : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa ptr o) = 0#u64) : + let Te' := if tag = 1#u64 then insert ptr Te else Te + let Re' := if tag = 1#u64 then Function.update Re ptr ((level - 12) / 9 - 1) else Re + let bits' := if tag = 1#u64 then Function.update bits ptr 12 else bits + S2TyR st n (PoolSet st Pp q) Hr Te' Re' bits' q := by + let Te' := if tag = 1#u64 then insert ptr Te else Te + let Re' := if tag = 1#u64 then Function.update Re ptr ((level - 12) / 9 - 1) else Re + let bits' := if tag = 1#u64 then Function.update bits ptr 12 else bits + change S2TyR st n (PoolSet st Pp q) Hr Te' Re' bits' q + obtain ⟨tab, pools⟩ := write.keepAsid h heap kinds ptKs walk + have unmapped : UnmCap (capA st s slot) ptr 4096 := Or.inl ⟨rfl, ad, oldVa, before⟩ + have keepLevel (p : U64) (reach : S2Reach st (PoolSet st Pp s) Re bits s p) : + Re' p = Re p ∧ bits' p = bits p := by + have diff : p ≠ ptr := fun e => h.core.lookup.unmR2 member unmapped + (e ▸ ⟨h.core.stage2.reachableMember reach, reach⟩) + dsimp [Re', bits'] + split <;> simp only [Function.update_of_ne diff, and_self] + have embed : Te ⊆ Te' := by + intro p hp + dsimp [Te'] + split + · exact Set.mem_insert_of_mem _ hp + · exact hp + have raw := write.rawStage2 h heap kinds ptKs member before walk target empty + refine ⟨?_, ?_, ?_⟩ + · intro p hp o bound al nz + have hp' : p ∈ PoolSet st Pp s := tab.poolSet_eq ▸ hp + rw [pools p hp' o bound al] at nz ⊢ + rcases h.core.stage2.tag p hp' o bound al nz with one | other | ⟨tagged, inTables, depth, span⟩ + · exact Or.inl one + · exact Or.inr (Or.inl other) + · have root : S2Reach st (PoolSet st Pp s) Re bits s (L.mem s (wa p o) &&& ~~~3#u64) := + .root hp' bound al tagged + obtain ⟨levelEq, bitsEq⟩ := keepLevel _ root + exact Or.inr (Or.inr ⟨tagged, embed inTables, by rwa [levelEq], by rwa [bitsEq]⟩) + · intro root live + rw [write.highHeader h heap kinds walk live 4088#u64 (by decide) (by decide)] + exact h.core.stage2.hi root live + · intro p _ reach depth o bound al tagged + rcases raw p reach with prior | ⟨stage, same⟩ + · obtain ⟨atParent, bitEq⟩ := keepLevel p prior + rw [atParent] at depth ⊢ + rw [bitEq] at bound + have placed := h.core.stage2.reachableMember prior + by_cases changed : wa p o = addr + · obtain ⟨stage, selectedLevel⟩ := h.mapStage2Source heap kinds walk prior bound changed + rw [changed, write.descriptor, target.tableTargets.2] + have re : (level - 12) / 9 = Re p := by omega + simp only [Te', Re', stage, if_true, Set.mem_insert_iff, true_or, true_and, Function.update_self, re] + omega + · have location := ptw_mono h.place.granules (ptwb_gran h.place.stage2.sz ⟨p, placed, o, bound, al, rfl⟩) + rw [write.memory _ (Or.inl location) changed] at tagged ⊢ + obtain ⟨child, childDepth⟩ := h.core.stage2.desc p placed prior depth o bound al tagged + have oldChild := S2Reach.step prior depth bound al tagged + exact ⟨embed child, by rw [(keepLevel _ oldChild).1]; exact childDepth⟩ + · have span : bits' ptr = 12 := by simp [bits', stage] + rw [same, span] at bound + rw [same, empty o bound al] at tagged + exact ((by decide : (0#u64 &&& 3#u64) ≠ 3#u64) tagged).elim + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapWalk.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapWalk.lean new file mode 100644 index 000000000..12ded03b9 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapWalk.lean @@ -0,0 +1,368 @@ +/- +P1 (aarch64): exact descriptor slots and shared table descent. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Domains + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +private theorem unpackF_mask (word : BitVec 64) : + CapRt.unpackF word &&& CapRt.M48 = word &&& CapRt.M48 := by + unfold CapRt.unpackF + split <;> apply BitVec.eq_of_getElem_eq <;> intro i hi + all_goals simp only [BitVec.getElem_and, BitVec.getElem_or] + all_goals interval_cases i <;> simp [CapRt.M48] + +/-- Cap decoding preserves exactly the IPA bits consumed in the Stage-2 walk. -/ +theorem s1aCapAddress_unpack (n va : U64) : + s1aCapAddress 1#u64 n (⟨CapRt.unpackF va.bv⟩ : U64) = va.val % 2 ^ s1aIpaWidth n := by + have low : (CapRt.unpackF va.bv).toNat % 2 ^ 48 = va.val % 2 ^ 48 := by + have bits := congrArg BitVec.toNat (unpackF_mask va.bv) + change (CapRt.unpackF va.bv).toNat % 2 ^ 48 = va.bv.toNat % 2 ^ 48 + simpa only [BitVec.toNat_and, show CapRt.M48.toNat = 2 ^ 48 - 1 from rfl, + Nat.and_two_pow_sub_one_eq_mod] using bits + have dvd : (2 : Nat) ^ s1aIpaWidth n ∣ 2 ^ 48 := by + unfold s1aIpaWidth + split + · decide + · split <;> decide + unfold s1aCapAddress + rw [ite_eq_left rfl] + change (CapRt.unpackF va.bv).toNat % 2 ^ s1aIpaWidth n = va.val % 2 ^ s1aIpaWidth n + rw [← Nat.mod_mod_of_dvd _ dvd, low, Nat.mod_mod_of_dvd _ dvd] + +/-- The cap written by Stage-2 PageTable Map preserves the ASID and the +walk address after normalization, including when the saved address has bit 47 set. -/ +theorem s1aPageTableEncodeS2 (p asid va n : U64) (ptr : CapRt.Canonical p) + (id : asid.val < 2 ^ 20) (bound : va.val < 2 ^ s1aIpaWidth n) : + let c := capability.Cap.PageTable p true asid va + ∃ saved, CapRt.decodeF (CapRt.encodeF c).1 (CapRt.encodeF c).2 = .PageTable p true asid saved ∧ + s1aCapAddress 1#u64 n saved = va.val := by + let saved : U64 := ⟨CapRt.unpackF va.bv⟩ + have encode : CapRt.encodeF (.PageTable p true asid va) = CapRt.encodeF (.PageTable p true asid saved) := by + simp only [CapRt.encodeF] + have low : saved.bv &&& 0xffffffffffff#64 = va.bv &&& 0xffffffffffff#64 := unpackF_mask va.bv + rw [low] + refine ⟨saved, ?_, (s1aCapAddress_unpack n va).trans (Nat.mod_eq_of_lt bound)⟩ + rw [encode] + exact CapRt.rt_PageTable p true asid saved ⟨ptr, id, CapRt.unpackF_canonical va.bv⟩ + +/-- Size alignment makes the descriptor's recorded target equal to its +output base at the selected page or block level. -/ +theorem s1aLeafTarget.ofDescTo {word p : U64} {shift : Nat} (desc : DescTo word p) + (bound : shift ≤ 47) (aligned : p.val % 2 ^ shift = 0) : + s1aLeafTarget word shift = p := by + let address := word &&& vspace.ADDR_MASK + have maskEq : ept.ADDR_MASK = vspace.ADDR_MASK := + UScalar.eq_of_val_eq (by simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + have recorded : core.num.U64.wrapping_add address layout.PPTR_BASE = p := + desc.elim id (fun h => by rwa [maskEq] at h) + have power : (2 : Nat) ^ shift ∣ 2 ^ 47 := Nat.pow_dvd_pow 2 bound + have baseAligned : (2 : Nat) ^ shift ∣ layout.PPTR_BASE.val := by + rw [P0.Consts.layout.PPTR_BASE.val_eq] + exact power.trans (by decide) + have wraps : (2 : Nat) ^ shift ∣ UScalar.size UScalarTy.U64 := by + have size : UScalar.size UScalarTy.U64 = 2 ^ 64 := by simp [UScalar.size_def, UScalarTy.numBits] + rw [size] + exact Nat.pow_dvd_pow 2 (by omega) + have addrAligned : address.val % 2 ^ shift = 0 := by + have eq := congrArg UScalar.val recorded + rw [core.num.U64.wrapping_add_val_eq] at eq + rw [← eq, Nat.mod_mod_of_dvd _ wraps, Nat.add_mod, + Nat.mod_eq_zero_of_dvd baseAligned, Nat.add_zero, Nat.mod_mod] at aligned + exact aligned + let mask : U64 := ⟨BitVec.ofNat 64 (2 ^ shift - 1)⟩ + have maskVal : mask.val = 2 ^ shift - 1 := by + change (2 ^ shift - 1) % (2 ^ 64) = 2 ^ shift - 1 + apply Nat.mod_eq_of_lt + have small := Nat.pow_lt_pow_right (by decide : 1 < 2) (by omega : shift < 64) + omega + have zero : address &&& mask = 0#u64 := UScalar.eq_of_val_eq (by + rw [UScalar.val_and, maskVal, Nat.and_two_pow_sub_one_eq_mod] + exact addrAligned) + unfold s1aLeafTarget + change core.num.U64.wrapping_add (address &&& ~~~mask) layout.PPTR_BASE = p + rw [and_not_of address mask zero] + exact recorded + +section frame + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} {OS : Set U64} {s : S} + +/-- Recover size alignment from the device-frame invariant or the typed heap. -/ +theorem s1aFrameAligned (heap : HeapOK H) (ram : FrameOK st H OS s) (device : DevFrAl st OS s) + {x p rights asid va bits : U64} {sz : capability.FrameSize} {dev mapped ept : Bool} + (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 device x hx p sz rights mapped ept asid va cap bits size + +end frame + +section entry + +/-- The walk reads a stride-eight descriptor at the exact masked index. -/ +theorem ept.entry_addr.exactOffset (t va sh mask : U64) (hsh : sh.val < 64) (hmask : mask.val ≤ 1023) : + ept.entry_addr t va sh mask ⦃ addr => ∃ off : U64, + off.val = ((va.val >>> sh.val) &&& mask.val) * 8 ∧ + addr = core.num.U64.wrapping_add t off ⦄ := by + unfold ept.entry_addr + simp only [lift, bind_ok] + have reduced : (sh &&& 63#u64).val = sh.val := by + rw [UScalar.val_and, show (63#u64 : U64).val = 2 ^ 6 - 1 from rfl, + Nat.and_two_pow_sub_one_eq_mod, Nat.mod_eq_of_lt hsh] + have h63 : (sh &&& 63#u64).val < 64 := by rwa [reduced] + step as ⟨idx, shifted⟩ + have bound : (idx &&& mask).val ≤ 1023 := by + rw [UScalar.val_and] + exact Nat.le_trans Nat.and_le_right hmask + let off := core.num.U64.wrapping_mul (idx &&& mask) 8#u64 + have offset : off.val = ((va.val >>> sh.val) &&& mask.val) * 8 := by + have wrap : off.val = (idx &&& mask).val * 8 := by + dsimp [off] + rw [UScalar.val_and] at bound + simp [core.num.U64.wrapping_mul_val_eq, U64.size_def, U64.numBits] + omega + rw [wrap, UScalar.val_and, shifted, reduced] + exact ⟨off, offset, rfl⟩ + +/-- Native and HighVSpace use the same address arithmetic with a nine-bit index. -/ +theorem vspace.entry_addr.exactOffset (t va sh : U64) (hsh : sh.val < 64) : + vspace.entry_addr t va sh ⦃ addr => ∃ off : U64, + off.val = ((va.val >>> sh.val) &&& 511) * 8 ∧ + addr = core.num.U64.wrapping_add t off ⦄ := by + change ept.entry_addr t va sh 511#u64 ⦃ addr => ∃ off : U64, + off.val = ((va.val >>> sh.val) &&& 511) * 8 ∧ addr = core.num.U64.wrapping_add t off ⦄ + exact ept.entry_addr.exactOffset t va sh 511#u64 hsh (by decide) + +end entry + +/-- The walked slot covers the normalized address at its page-table level. -/ +structure S1aSlotAt {S : Type _} (st : machine.Store S) [L : LawfulStore st] + (Pp : Set U64) (n : U64) (s : S) (tag asid : U64) (address shift : Nat) (slot : U64) : Prop where + entry : ∃ t : U64, ∃ base : Nat, ∃ off : U64, + S1aPath st Pp n s tag asid shift base t ∧ off.val < s1aTableWidth tag n shift ∧ + off.val % 8 = 0 ∧ slot = core.num.U64.wrapping_add t off ∧ + base % 2 ^ (shift + 9) = 0 ∧ + let first := base + off.val / 8 * 2 ^ shift + first ≤ address ∧ address < first + 2 ^ shift ∧ s1aUserRange tag n first (2 ^ shift) + +theorem s1aChildIndex (address base shift : Nat) + (level : shift = 12 ∨ shift = 21 ∨ shift = 30) + (aligned : base % 2 ^ (shift + 9) = 0) (lo : base ≤ address) + (hi : address < base + 2 ^ (shift + 9)) : + (address >>> shift) &&& 511 = (address - base) / 2 ^ shift := by + rw [Nat.shiftRight_eq_div_pow, show 511 = 2 ^ 9 - 1 by decide, Nat.and_two_pow_sub_one_eq_mod] + rcases level with rfl | rfl | rfl <;> norm_num at * <;> omega + +theorem s1aIpaChildIndex (n : U64) (va shift : Nat) + (level : shift = 12 ∨ shift = 21 ∨ shift = 30) : + (va >>> shift) &&& 511 = ((va % 2 ^ s1aIpaWidth n) >>> shift) &&& 511 := by + simp only [Nat.shiftRight_eq_div_pow, show 511 = 2 ^ 9 - 1 by decide, Nat.and_two_pow_sub_one_eq_mod] + unfold s1aIpaWidth + split + · rcases level with rfl | rfl | rfl <;> norm_num <;> omega + · split <;> rcases level with rfl | rfl | rfl <;> norm_num <;> omega + +/-- A valid frame size has one of the shifts supported by the concrete map. -/ +theorem s1aFrameShift {size : capability.FrameSize} {bits : U64} (h : size.bits = ok bits) : + bits.val = 12 ∨ bits.val = 21 ∨ bits.val = 30 := by + cases size <;> simp only [capability.FrameSize.bits] at h <;> rw [← okinj h] <;> decide + +private theorem S1aPath.shift_le {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {Pp : Set U64} {n tag a t : U64} {s : S} {shift base : Nat} + (path : S1aPath st Pp n s tag a shift base t) : shift ≤ s1aTopShift tag n := by + exact path.geometry.2.elim (fun h => h.1.le) (fun h => h.1.le) + +/-- Descending through a table descriptor selects the corresponding subrange. -/ +theorem S1aSlotAt.child {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {Pp : Set U64} {n tag a slot off next : U64} {s : S} {address shift : Nat} + (parent : S1aSlotAt st Pp n s tag a address shift slot) + (level : shift = 21 ∨ shift = 30 ∨ shift = 39) + (valid : (L.mem s slot &&& 3#u64) = 3#u64) + (index : off.val = ((address >>> (shift - 9)) &&& 511) * 8) + (nextAddr : next = core.num.U64.wrapping_add + (core.num.U64.wrapping_add (L.mem s slot &&& vspace.ADDR_MASK) layout.PPTR_BASE) off) : + S1aSlotAt st Pp n s tag a address (shift - 9) next := by + obtain ⟨t, base, word, path, width, stride, slotEq, baseAlign, start, finish, region⟩ := parent.entry + let first := base + word.val / 8 * 2 ^ shift + change first ≤ address at start + change address < first + 2 ^ shift at finish + have depth : 12 < shift := by omega + have nextDepth : shift - 9 < s1aTopShift tag n := by have := path.shift_le; omega + have nextLevel : shift - 9 = 12 ∨ shift - 9 = 21 ∨ shift - 9 = 30 := by omega + have endEq : shift - 9 + 9 = shift := by omega + have childAlign : first % 2 ^ (shift - 9 + 9) = 0 := by + rw [endEq] + have divides : (2 : Nat) ^ shift ∣ 2 ^ (shift + 9) := Nat.pow_dvd_pow 2 (by omega) + exact Nat.mod_eq_zero_of_dvd + (Nat.dvd_add (divides.trans (Nat.dvd_of_mod_eq_zero baseAlign)) ((dvd_refl _).mul_left _)) + have idx := s1aChildIndex address first (shift - 9) nextLevel childAlign start (by rwa [endEq]) + rw [idx] at index + have desc : (L.mem s (core.num.U64.wrapping_add t word) &&& 3#u64) = 3#u64 := slotEq ▸ valid + have path' := S1aPath.child path depth width stride region desc + let unit : Nat := 2 ^ (shift - 9) + have positive : 0 < unit := by dsimp [unit]; positivity + have scale : 512 * unit = 2 ^ shift := by + dsimp only [unit] + rw [show (512 : Nat) = 2 ^ 9 from rfl, ← Nat.pow_add, show 9 + (shift - 9) = shift by omega] + change off.val = (address - first) / unit * 8 at index + have offDiv : off.val / 8 = (address - first) / unit := by omega + have indexBound : (address - first) / unit < 512 := (Nat.div_lt_iff_lt_mul positive).2 (by rw [scale]; omega) + have parts := Nat.div_add_mod (address - first) unit + have remainder := Nat.mod_lt (address - first) positive + have blockEnd : (off.val / 8 + 1) * unit ≤ 512 * unit := + Nat.mul_le_mul_right unit (by omega) + rw [Nat.add_mul, Nat.one_mul, scale] at blockEnd + refine ⟨_, first, off, path', ?_, by omega, ?_, childAlign, ?_, ?_, ?_⟩ + · rw [s1aTableWidth, ite_eq_right nextDepth.ne] + omega + · rwa [slotEq] at nextAddr + · change first + off.val / 8 * unit ≤ address + rw [offDiv, Nat.mul_comm] + omega + · change address < first + off.val / 8 * unit + unit + rw [offDiv, Nat.mul_comm] + omega + · apply path'.slotRange + · rw [s1aTableWidth, ite_eq_right nextDepth.ne] + omega + · exact fun _ h => (nextDepth.ne h).elim + +section walk +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {Pp : Set U64} {n tag asid : U64} {s : S} {address : Nat} + +abbrev ExactSlot (x : U64 × U64 × U64) : Prop := + x.2.2.val ≤ 3 ∧ x.1.val = 12 + 9 * x.2.2.val ∧ + S1aSlotAt st Pp n s tag asid address x.1.val x.2.1 + +private theorem ept.is_table.edge (e sh : U64) : + ept.is_table e sh ⦃ b => b = true ↔ 12 < sh.val ∧ (e &&& 3#u64) = 3#u64 ⦄ := by + unfold ept.is_table + split + · rename_i above + rw [eq_of_spec_fd P0.Consts.ept.D_VALID.spec, eq_of_spec_fd P0.Consts.ept.D_TABLE_OR_PAGE.spec] + have combined : (1#u64 ||| 2#u64) = 3#u64 := by decide + simp only [lift, bind_ok, combined] + have h : 12 < sh.val := by simpa [P0.Consts.ept.PAGE_BITS.val_eq] using above + exact (WP.spec_ok _).2 (by simp [h]) + · rename_i notAbove + have h : ¬ 12 < sh.val := by simpa [P0.Consts.ept.PAGE_BITS.val_eq] using notAbove + exact (WP.spec_ok _).2 (by simp [h]) + +set_option maxHeartbeats 2000000 in +/-- Both hardware translation stages use the same descent after the initial slot. -/ +theorem ept.lookup_slot_loop.exactStop (va shift slot rem : U64) + (index : ∀ k, k = 12 ∨ k = 21 ∨ k = 30 → (va.val >>> k) &&& 511 = (address >>> k) &&& 511) + (init : ExactSlot (st := st) (Pp := Pp) (n := n) (s := s) (tag := tag) (asid := asid) + (address := address) (shift, slot, rem)) : + ept.lookup_slot_loop st s va shift slot rem ⦃ result => + S1aSlotAt st Pp n s tag asid address result.1.val result.2 ∧ + (12 < result.1.val → (L.mem s result.2 &&& 3#u64) ≠ 3#u64) ⦄ := by + unfold ept.lookup_slot_loop + apply loop.spec_decr_nat (measure := fun x => x.2.2.val) + (inv := ExactSlot (st := st) (Pp := Pp) (n := n) (s := s) (tag := tag) (asid := asid) (address := address)) + · rintro ⟨sh, sl, rm⟩ ⟨rmBound, shEq, current⟩ + simp only at rmBound shEq current + dsimp only + unfold ept.lookup_slot_loop.body + split + · rename_i live + have positive : 0 < rm.val := by simpa using live + rw [L.read_eq, bind_ok] + refine WP.spec_bind (ept.is_table.edge _ sh) fun table result => ?_ + split + · rename_i yes + have parentLevel : sh.val = 21 ∨ sh.val = 30 ∨ sh.val = 39 := by omega + have childLevel : sh.val - 9 = 12 ∨ sh.val - 9 = 21 ∨ sh.val - 9 = 30 := by omega + let deeper := core.num.U64.wrapping_sub sh 9#u64 + have deeperVal : deeper.val = sh.val - 9 := by + dsimp only [deeper] + simp [core.num.U64.wrapping_sub_val_eq, U64.size_def, U64.numBits] + omega + have deeperBound : deeper.val < 64 := by omega + have sameMask : ept.ADDR_MASK = vspace.ADDR_MASK := + UScalar.eq_of_val_eq (by simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + step as ⟨rm', rmEq⟩ + simp only [lift, bind_ok, ept.table_of, layout.pptr, sameMask] + refine WP.spec_bind (ept.entry_addr.exactOffset _ va deeper 511#u64 deeperBound (by decide)) ?_ + rintro next ⟨off, offEq, nextEq⟩ + have pos : off.val = ((address >>> (sh.val - 9)) &&& 511) * 8 := by + rw [offEq, deeperVal, show (511#u64 : U64).val = 511 from rfl, index _ childLevel] + have found := current.child parentLevel (result.mp yes).2 pos nextEq + have exactNext : ExactSlot (st := st) (Pp := Pp) (n := n) (s := s) (tag := tag) (asid := asid) + (address := address) (deeper, next, rm') := by + refine ⟨by simp only; omega, ?_, ?_⟩ + · simp only; rw [deeperVal]; omega + · simp only; rw [deeperVal]; exact found + refine (WP.spec_ok _).2 ?_ + exact ⟨exactNext.1, exactNext.2.1, exactNext.2.2, by change rm'.val < rm.val; omega⟩ + · rename_i no + exact (WP.spec_ok _).2 ⟨current, fun above entry => no (result.mpr ⟨above, entry⟩)⟩ + · rename_i done + have remZero : ¬ 0 < rm.val := by simpa using done + exact (WP.spec_ok _).2 ⟨current, fun above => by + change 12 < sh.val at above + omega⟩ + · exact init + +/-- Both hardware translation stages use the same descent after the initial slot. -/ +theorem ept.lookup_slot_loop.exactPath (va shift slot rem : U64) + (index : ∀ k, k = 12 ∨ k = 21 ∨ k = 30 → (va.val >>> k) &&& 511 = (address >>> k) &&& 511) + (init : ExactSlot (st := st) (Pp := Pp) (n := n) (s := s) (tag := tag) (asid := asid) + (address := address) (shift, slot, rem)) : + ept.lookup_slot_loop st s va shift slot rem ⦃ result => + S1aSlotAt st Pp n s tag asid address result.1.val result.2 ⦄ := + WP.spec_mono (ept.lookup_slot_loop.exactStop va shift slot rem index init) fun _ h => h.1 + +omit L in +theorem vspace.lookup_pt_slot_loop.unfoldOnce (va sh slot rem : U64) : + vspace.lookup_pt_slot_loop st s va sh slot rem = + (do + let step ← vspace.lookup_pt_slot_loop.body st s va sh slot rem + match step with + | .cont (nextShift, nextSlot, nextRem) => + vspace.lookup_pt_slot_loop st s va nextShift nextSlot nextRem + | .done result => ok result) := by + conv_lhs => unfold vspace.lookup_pt_slot_loop; rw [loop] + congr 1 + funext step + cases step with + | cont args => obtain ⟨_, _, _⟩ := args; rfl + | done result => rfl + +omit L in +private theorem lookupLoopEq (va shift slot rem : U64) : + vspace.lookup_pt_slot_loop st s va shift slot rem = ept.lookup_slot_loop st s va shift slot rem := by + unfold vspace.lookup_pt_slot_loop ept.lookup_slot_loop vspace.lookup_pt_slot_loop.body ept.lookup_slot_loop.body + vspace.is_table ept.is_table vspace.entry_addr ept.entry_addr vspace.table_of ept.table_of + vspace.PAGE_BITS ept.PAGE_BITS vspace.D_VALID ept.D_VALID vspace.D_TABLE_OR_PAGE ept.D_TABLE_OR_PAGE + vspace.ADDR_MASK ept.ADDR_MASK + rfl + +/-- At a termination above L3, the descriptor is not a table edge. -/ +theorem vspace.lookup_pt_slot_loop.exactStop (va shift slot rem : U64) + (init : ExactSlot (st := st) (Pp := Pp) (n := n) (s := s) (tag := tag) (asid := asid) + (address := va.val) (shift, slot, rem)) : + vspace.lookup_pt_slot_loop st s va shift slot rem ⦃ result => + S1aSlotAt st Pp n s tag asid va.val result.1.val result.2 ∧ + (12 < result.1.val → (L.mem s result.2 &&& 3#u64) ≠ 3#u64) ⦄ := by + rw [lookupLoopEq] + exact ept.lookup_slot_loop.exactStop va shift slot rem (fun _ _ => rfl) init + +/-- The native and HighVSpace walks reuse the same exact slot invariant. -/ +theorem vspace.lookup_pt_slot_loop.exactPath (va shift slot rem : U64) + (init : ExactSlot (st := st) (Pp := Pp) (n := n) (s := s) (tag := tag) (asid := asid) + (address := va.val) (shift, slot, rem)) : + vspace.lookup_pt_slot_loop st s va shift slot rem ⦃ result => + S1aSlotAt st Pp n s tag asid va.val result.1.val result.2 ⦄ := by + rw [lookupLoopEq] + exact ept.lookup_slot_loop.exactPath va shift slot rem (fun _ _ => rfl) init +end walk + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2MapWrite.lean b/proofs/Fl4ProofsA64/P1/S1aR2MapWrite.lean new file mode 100644 index 000000000..0374494a0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2MapWrite.lean @@ -0,0 +1,124 @@ +/- +P1 (aarch64): exact descriptor and capability effects of Map. +Named premises: none. +-/ +import Fl4ProofsA64.P1.MdbEptMapQ + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Vc Ub : Set U64} + {s : S} {x : U64} + +/-- A decoded cap rewrite preserves every VSpace word and all other cap slots. -/ +theorem obj.Slot.set_cap.exactMap + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (os : OSOK H.tcbs H.omega H.frame OS) (hx : x ∈ OS) {written decoded : capability.Cap} + (cap : CapRt.decodeF (CapRt.encodeF written).1 (CapRt.encodeF written).2 = decoded) : + obj.Slot.set_cap st x s written ⦃ q => + L.ksb q = L.ksb s ∧ VsKeep st (L.ksb s) Pt s q ∧ capA st q x = decoded ∧ + (∀ y ∈ OS, y ≠ x → capA st q y = capA st s y) ⦄ := by + rw [set_cap_eq (CapRt.encode_eq written), WP.spec_ok] + obtain ⟨mem, _, _⟩ := wr2_cap (st := st) (s := s) vr os hx + (w0 := ⟨(CapRt.encodeF written).1⟩) (w1 := ⟨(CapRt.encodeF written).2⟩) + refine ⟨by rw [L.ksb_wr, L.ksb_wr], mem, ?_, fun y hy ne => capA_wr2_other os hx hy ne⟩ + apply capA_wr2_self os hx + rw [CapRt.decode_eq] + exact congrArg ok cap + +/-- Restarting the caller before the Map cap update keeps the old VSpace +words and all other cap slots through both steps. -/ +theorem sched.set_thread_state.mapCap {Cs U Ac : Set U64} {c : capability.Cap} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (os : OSOK H.tcbs H.omega H.frame OS) (hx : x ∈ OS) + (d : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s c extra) : + sched.set_thread_state st s (L.curW s) sched.TS_RESTART ⦃ q => + ∀ written decoded : capability.Cap, + CapRt.decodeF (CapRt.encodeF written).1 (CapRt.encodeF written).2 = decoded → + obj.Slot.set_cap st x q written ⦃ out => + L.ksb out = L.ksb s ∧ VsKeep st (L.ksb s) Pt s out ∧ capA st out x = decoded ∧ + (∀ y ∈ OS, y ≠ x → capA st out y = capA st s y) ⦄ ⦄ := by + have queues := d.bxi.1.choose_spec.choose_spec + refine WP.spec_mono (stt_vk vr queues queues.curT) fun q ⟨restart, same⟩ written decoded hc => ?_ + have vrq : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb q) Pt := by + rw [restart.1]; exact vr + refine WP.spec_mono (obj.Slot.set_cap.exactMap vrq os hx hc) fun out ⟨base, memory, cap, other⟩ => ?_ + rw [restart.1] at memory + refine ⟨base.trans restart.1, same.trans memory, cap, ?_⟩ + intro y hy ne + have eq := stt_capk os queues queues.curT restart y hy + rw [capA_eq, capA_eq] at eq + exact (other y hy ne).trans (okinj eq) + +/-- The Map tail writes just the chosen descriptor and the invoked capability. +The old and new VSpace words agree outside the chosen descriptor slot. -/ +structure S1aMapWrite (st : machine.Store S) [L : LawfulStore st] + (OS Pt : Set U64) (s q : S) (x addr word : U64) (decoded : capability.Cap) : Prop where + base : L.ksb q = L.ksb s + memory : ∀ b, VsR (L.ksb s) Pt b → b ≠ addr → L.mem q b = L.mem s b + descriptor : L.mem q addr = word + cap : capA st q x = decoded + other : ∀ y ∈ OS, y ≠ x → capA st q y = capA st s y + +/-- Both the leaf installer and the table store preserve the exact cap result +when their descriptor address is in the VSpace footprint. -/ +theorem S1aMapWrite.ofTail {m q : S} {addr word : U64} {decoded : capability.Cap} + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) + (os : OSOK H.tcbs H.omega H.frame OS) (hx : x ∈ OS) + (base : L.ksb m = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s m) + (cap : capA st m x = decoded) (other : ∀ y ∈ OS, y ≠ x → capA st m y = capA st s y) + (target : PtW Pt addr) (writes : WritesIn st m q (· = addr)) (stored : L.mem q addr = word) : + S1aMapWrite st OS Pt s q x addr word decoded := by + have kept y (hy : y ∈ OS) : capA st q y = capA st m y := by + have eq := capk_vsr vr os (writes.mono fun b e => Or.inl (e.symm ▸ target)) y hy + rw [capA_eq, capA_eq] at eq + exact okinj eq + exact ⟨writes.1.trans base, + fun b hb ne => (writes.mem_eq (vr.al b hb) ne).trans (mem b hb), + stored, (kept x hx).trans cap, fun y hy ne => (kept y hy).trans (other y hy ne)⟩ + +section stage2 + +variable {A : Type _} {ar : machine.Arch A} + +set_option maxHeartbeats 1600000 in +/-- The Stage-2 installer always ends with the supplied leaf word. A +break-before-make clear may precede this final store. -/ +theorem ept.install_s2_leaf.exactWord (hA : P0.ArchTotal ar) {lu : ept.S2Slot} (al : Aligned lu.slot) + (s : S) (a : A) (e root asid ipa ptr : U64) (dev : Bool) (attr : U64) : + ept.install_s2_leaf st ar s a lu e root asid ipa ptr dev attr ⦃ r => + WritesIn st s r.1 (· = lu.slot) ∧ L.mem r.1 lu.slot = e ⦄ := by + have write (q : S) (frame : WritesIn st s q (· = lu.slot)) : + st.write q lu.slot e ⦃ out => WritesIn st s out (· = lu.slot) ∧ L.mem out lu.slot = e ⦄ := + WP.spec_mono (LawfulStore.write_spec q lu.slot e) fun out eq => by + subst out + exact ⟨frame.trans1 (writesIn_wr al), L.mem_wr_same al⟩ + have install (op : Result A) (total : op ⦃ _ => True ⦄) (q : S) + (frame : WritesIn st s q (· = lu.slot)) : + (do let aq ← op; let out ← st.write q lu.slot e; ok (out, aq)) ⦃ r => + WritesIn st s r.1 (· = lu.slot) ∧ L.mem r.1 lu.slot = e ⦄ := + WP.spec_bind total fun aq _ => WP.spec_bind (write q frame) fun out result => (WP.spec_ok _).2 result + have clear : st.write s lu.slot 0#u64 ⦃ q => WritesIn st s q (· = lu.slot) ⦄ := + WP.spec_mono (LawfulStore.write_spec s lu.slot 0#u64) fun q eq => by subst q; exact writesIn_wr al + unfold ept.install_s2_leaf + refine WP.spec_bind (LawfulStore.read_spec s lu.slot) fun old _ => ?_ + refine WP.spec_bind (P0.ept.is_leaf.p0 old lu.shift) fun b _ => ?_ + try simp only [lift, bind_ok] + refine spec_ite (fun _ => ?_) (fun _ => install _ (by copT) s (WritesIn.refl s _)) + refine spec_ite (fun _ => ?_) (fun _ => + WP.spec_bind clear fun q frame => WP.spec_bind (hA.invalidate_stage2_page a asid ipa) fun _ _ => + install _ (by copT) q frame) + refine WP.spec_bind P0.ept.S2_BBM_MASK.p0 fun mask _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => ?_) + · refine WP.spec_bind (write s (WritesIn.refl s _)) fun q hw => ?_ + refine WP.spec_bind (hA.invalidate_stage2_page a asid ipa) fun _ _ => (WP.spec_ok _).2 hw + · refine WP.spec_bind clear fun q frame => ?_ + refine WP.spec_bind (hA.invalidate_stage2_page a asid ipa) fun _ _ => install _ (by copT) q frame + +end stage2 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2OfImage.lean b/proofs/Fl4ProofsA64/P1/S1aR2OfImage.lean new file mode 100644 index 000000000..688e9fef8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2OfImage.lean @@ -0,0 +1,107 @@ +/- +P1 (aarch64): the slot operations that give a slot image (`S1aR2Transfer`): relabellings, swaps, moves and +copies (A64-S1A gen 41). Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Transfer +import Fl4ProofsA64.P1.S1aR2Delete + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {OS : Set U64} {s s' : S} + +theorem S1aSlotImage.trans {s'' : S} (I : S1aSlotImage st OS s s') (J : S1aSlotImage st OS s' s'') : + S1aSlotImage st OS s s'' := by + refine ⟨fun y hy reads => ?_, fun x hx reads => ?_, J.unique⟩ + · obtain ⟨x, hx, same⟩ := J.back y hy reads + obtain ⟨w, hw, first⟩ := I.back x hx (same.symm ▸ reads) + exact ⟨w, hw, first.trans same⟩ + · obtain ⟨y, hy, same⟩ := I.forth x hx reads + obtain ⟨z, hz, second⟩ := J.forth y hy (same.symm ▸ reads) + exact ⟨z, hz, second.trans same⟩ + +/-- A relabelling of the slots up to unread capabilities: swaps, moves and unread writes. -/ +theorem S1aSlotImage.perm (refs : S1aRefs st OS s) (σ : Equiv.Perm U64) + (into : ∀ y ∈ OS, σ y ∈ OS) (onto : ∀ x ∈ OS, σ.symm x ∈ OS) + (caps : ∀ y ∈ OS, capA st s' y = capA st s (σ y) ∨ + (¬ S1aR2Reads (capA st s (σ y)) ∧ ¬ S1aR2Reads (capA st s' y))) : S1aSlotImage st OS s s' := by + have old (y : U64) (hy : y ∈ OS) (reads : S1aR2Reads (capA st s' y)) : capA st s' y = capA st s (σ y) := + (caps y hy).elim id fun h => absurd reads h.2 + refine ⟨fun y hy reads => ⟨σ y, into y hy, (old y hy reads).symm⟩, fun x hx reads => ⟨σ.symm x, onto x hx, ?_⟩, + fun y hy z hz k ky kz empty => ?_⟩ + · rcases caps _ (onto x hx) with same | ⟨unread, _⟩ + · rwa [Equiv.apply_symm_apply] at same + · rw [Equiv.apply_symm_apply] at unread + exact absurd reads unread + · have ey := old y hy (s1aTableKey.reads ky) + have ez := old z hz (s1aTableKey.reads kz) + rw [ey] at ky empty + rw [ez] at kz + exact σ.injective (refs.unique _ (into y hy) _ (into z hz) k ky kz empty) + +/-- Slots that keep their capability, or change between capabilities R2 does not read, give the image. -/ +theorem S1aSlotImage.ofSame (refs : S1aRefs st OS s) (caps : ∀ y ∈ OS, S1aCapSame st s s' y) : + S1aSlotImage st OS s s' := + .perm refs (Equiv.refl _) (fun _ hy => hy) (fun _ hx => hx) caps + +/-- Two slots exchange their capabilities, up to capabilities R2 does not read. -/ +theorem S1aSlotImage.swap (refs : S1aRefs st OS s) {x y : U64} (hx : x ∈ OS) (hy : y ∈ OS) + (first : capA st s' x = capA st s y ∨ (¬ S1aR2Reads (capA st s y) ∧ ¬ S1aR2Reads (capA st s' x))) + (second : capA st s' y = capA st s x ∨ (¬ S1aR2Reads (capA st s x) ∧ ¬ S1aR2Reads (capA st s' y))) + (keep : ∀ z ∈ OS, z ≠ x → z ≠ y → capA st s' z = capA st s z) : S1aSlotImage st OS s s' := by + have into : ∀ z ∈ OS, Equiv.swap x y z ∈ OS := fun z hz => by + rw [Equiv.swap_apply_def] + split + · exact hy + split + · exact hx + exact hz + refine .perm refs (Equiv.swap x y) into (fun z hz => by rw [Equiv.symm_swap]; exact into z hz) fun z hz => ?_ + by_cases h1 : z = x + · rw [h1, Equiv.swap_apply_left] + exact first + by_cases h2 : z = y + · rw [h2, Equiv.swap_apply_right] + exact second + rw [Equiv.swap_apply_of_ne_of_ne h1 h2] + exact Or.inl (keep z hz h1 h2) + +/-- A copy into an empty slot: the new capability is unread or the source's own, and a copied table +capability is mapped. -/ +theorem S1aSlotImage.copy (refs : S1aRefs st OS s) {src dest : U64} {c : capability.Cap} + (hs : src ∈ OS) (hd : dest ∈ OS) (ne : src ≠ dest) (empty : capA st s dest = .Null) + (new : capA st s' dest = c) (same : S1aR2Reads c → c = capA st s src) + (mapped : ∀ k, s1aTableKey c = some k → s1aTableRef c ≠ none) (source : S1aCapSame st s s' src) + (keep : ∀ z ∈ OS, z ≠ src → z ≠ dest → capA st s' z = capA st s z) : S1aSlotImage st OS s s' := by + have nothing : ¬ S1aR2Reads (capA st s dest) := by rw [empty]; exact fun h => h + have other (y : U64) (hy : y ∈ OS) (nd : y ≠ dest) (reads : S1aR2Reads (capA st s' y) ∨ S1aR2Reads (capA st s y)) : + capA st s' y = capA st s y := by + by_cases h : y = src + · subst h + exact source.elim id fun u => (reads.elim u.2 u.1).elim + exact keep y hy h nd + refine ⟨fun y hy reads => ?_, fun x hx reads => ?_, fun y hy z hz k ky kz none => ?_⟩ + · by_cases h : y = dest + · rw [h, new] at reads ⊢ + exact ⟨src, hs, (same reads).symm⟩ + exact ⟨y, hy, (other y hy h (Or.inl reads)).symm⟩ + · have nd : x ≠ dest := fun e => nothing (e ▸ reads) + exact ⟨x, hx, other x hx nd (Or.inr reads)⟩ + · have notDest : y ≠ dest := fun e => by + rw [e, new] at ky none + exact mapped k ky none + have ey := other y hy notDest (Or.inl (s1aTableKey.reads ky)) + rw [ey] at ky none + by_cases h : z = dest + · rw [h, new] at kz + have copied := same (s1aTableKey.reads kz) + have key : s1aTableKey (capA st s src) = some k := copied ▸ kz + have agree := refs.references y hy src hs k ky key + exact absurd (copied ▸ agree.symm.trans none) (mapped k kz) + rw [other z hz h (Or.inl (s1aTableKey.reads kz))] at kz + exact refs.unique y hy z hz k ky kz none + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2PathReference.lean b/proofs/Fl4ProofsA64/P1/S1aR2PathReference.lean new file mode 100644 index 000000000..90eeb2b1a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2PathReference.lean @@ -0,0 +1,70 @@ +/- +P1 (aarch64): exact walks that reach a mapped child agree with its saved reference. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Domains + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pp Tb Te : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} + +/-- The ASID and tag come from the active root even at the end of a path. -/ +theorem S1aPath.rootEntry {tag asid t : U64} {sh base : Nat} + (p : S1aPath st Pp n s tag asid sh base t) : + ∃ raw, ActiveAsidRoot st Pp s asid raw ∧ raw &&& 3#u64 = tag := by + induction p with + | native entry kind => exact ⟨_, entry, kind⟩ + | high entry kind _ => exact ⟨_, entry, kind⟩ + | stage2 entry kind => exact ⟨_, entry, kind⟩ + | child _ _ _ _ _ _ ih => exact ih + +/-- The active ASID can only select one translation stage. -/ +theorem S1aPath.sameTag {tag tag' asid t t' : U64} {sh sh' b b' : Nat} + (p : S1aPath st Pp n s tag asid sh b t) (q : S1aPath st Pp n s tag' asid sh' b' t') : + tag = tag' := by + obtain ⟨raw, ep, hp⟩ := p.rootEntry + obtain ⟨other, eq, hq⟩ := q.rootEntry + have same := okinj (ep.find.symm.trans eq.find) + cases same + exact hp.symm.trans hq + +/-- Every active path to a child table agrees with any mapped cap for +that table. This applies to both roots' address conventions. -/ +theorem S1aPathBacking.childRef (h : S1aPathBacking st H OS Pp Tb Te Lv Re bits n s) + (caps : S1aTableCaps st OS s) {tag asid t x savedAsid va : U64} {sh b : Nat} + (p : S1aPath st Pp n s tag asid sh b t) (child : sh < s1aTopShift tag n) + (member : x ∈ OS) (cap : capA st s x = .PageTable t true savedAsid va) : + savedAsid = asid ∧ s1aCapAddress tag n va = b := by + obtain ⟨y, hy, saved, same, addr⟩ := h.children tag asid sh b t p child + have ref := caps.references x member y hy (0, t) (by rw [cap]; rfl) (by rw [same]; rfl) + rw [cap, same] at ref + change some (savedAsid, va) = some (asid, saved) at ref + cases ref + exact ⟨rfl, addr⟩ + +/-- A descendant named from two active paths has the same stage, ASID, +level and reference prefix. -/ +theorem S1aPathBacking.childAgreement (h : S1aPathBacking st H OS Pp Tb Te Lv Re bits n s) + (caps : S1aTableCaps st OS s) {t tag a tag' a' : U64} {sh b sh' b' : Nat} + (p : S1aPath st Pp n s tag a sh b t) (q : S1aPath st Pp n s tag' a' sh' b' t) + (child : sh < s1aTopShift tag n) (child' : sh' < s1aTopShift tag' n) : + tag = tag' ∧ a = a' ∧ sh = sh' ∧ b = b' := by + obtain ⟨x, hx, va, cap, bval⟩ := h.children tag a sh b t p child + obtain ⟨aeq, bref⟩ := h.childRef caps q child' hx cap + subst a' + have stage := p.sameTag q + subst tag' + have t1 := h.tables tag a sh b t p + have t2 := h.tables tag a sh' b' t q + refine ⟨rfl, rfl, ?_, bval.symm.trans bref⟩ + by_cases stage : tag = 1#u64 + · rw [ite_eq_left stage] at t1 t2 + exact t1.2.1.trans t2.2.1.symm + · rw [ite_eq_right stage] at t1 t2 + omega + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2PtUnmap.lean b/proofs/Fl4ProofsA64/P1/S1aR2PtUnmap.lean new file mode 100644 index 000000000..0058cc196 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2PtUnmap.lean @@ -0,0 +1,424 @@ +/- +P1 (aarch64, A64-S1A): lookup and concrete effects of PageTableUnmap. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Shrink + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s s' : S} + +/-- The ASID and virtual address fields of an unmapped PageTable cap are +irrelevant to R2. Keeping memory and resetting only those fields preserves R2. -/ +theorem S1aR2Core.resetUnmappedPageTable {slot ptr oldAsid oldVa : U64} + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (ks : L.ksb s' = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s s') + (unmapped : UnmZ st OS Pt (S2Rt st (PoolSet st Pp s) Te Re bits s) bits s) + (old : capA st s slot = .PageTable ptr false oldAsid oldVa) + (new : capA st s' slot = .PageTable ptr false 0#u64 0#u64) + (keep : ∀ x ∈ OS, x ≠ slot → capA st s' x = capA st s x) : + S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' := by + have poolMem q (hq : q ∈ PoolSet st Pp s) (o : U64) (ho : o.val < 4096) (h8 : o.val % 8 = 0) : + L.mem s' (wa q o) = L.mem s (wa q o) := + mem _ (Or.inl ⟨q, place.pools hq.1, o, ho, h8, rfl⟩) + have table : TabKeep st s s' := ⟨ks, fun i => by rw [ks]; exact mem _ (Or.inr (asW_at _ i))⟩ + have tab := table.toDel + have zero := mem.vsz + have desc1 p (reach : VsReach st (PoolSet st Pp s') ∅ Lv s' p) := + reach.activeZero h.stage1 place.pools place.tables tab zero + have desc2 p (reach : S2Reach st (PoolSet st Pp s') Re bits s' p) := + reach.activeZero h.stage2 place.pools place.granules place.stage2 tab zero + have mapped x (hx : x ∈ OS) p : MapV (capA st s' x) p ↔ MapV (capA st s x) p := by + by_cases e : x = slot + · subst x; simp [new, old, MapV] + · rw [keep x hx e] + have named x (hx : x ∈ OS) p : NamesV (capA st s' x) p ↔ NamesV (capA st s x) p := by + by_cases e : x = slot + · subst x; simp [new, old, NamesV] + · rw [keep x hx e] + have unm x (hx : x ∈ OS) p sz : UnmCap (capA st s' x) p sz ↔ UnmCap (capA st s x) p sz := by + by_cases e : x = slot + · subst x; simp [new, old, UnmCap] + · rw [keep x hx e] + have root x (hx : x ∈ OS) p a tag : + MappedAsidRoot (capA st s' x) p a tag ↔ MappedAsidRoot (capA st s x) p a tag := by + by_cases e : x = slot + · subst x; simp [new, old, MappedAsidRoot] + · rw [keep x hx e] + have header : HrW st Hr s s' := fun r hr => + mem _ (Or.inl ⟨r, place.tables (place.high.sub hr), 4088#u64, by simp, by simp, rfl⟩) + refine ⟨?_, ?_, ?_, h.stage1.activeZero place.pools place.tables tab zero, + h.stage2.activeZero place.pools place.granules place.stage2 tab zero header, h.heap⟩ + · refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ + · intro p reach ht hk + obtain ⟨x, hx, hxmap⟩ := h.lookup.bk1 p (desc1 p reach) ht hk + exact ⟨x, hx, (mapped x hx p).2 hxmap⟩ + · intro p reach ht + obtain ⟨x, hx, hxmap⟩ := h.lookup.bk2 p (desc2 p reach) ht + exact ⟨x, hx, (mapped x hx p).2 hxmap⟩ + · intro p hp x hx capNamed + exact h.lookup.kt p hp x hx ((named x hx p).1 capNamed) + · intro x hx y hy p sz u m + exact h.lookup.ex x hx y hy p sz ((unm x hx p sz).1 u) ((mapped y hy p).1 m) + · intro x hx p sz u o ho h8 + have oldUnm := (unm x hx p sz).1 u + obtain ⟨word, _, empty⟩ := unmapped.words (kb := L.ksb s) hx oldUnm.toSlot ho h8 + exact (mem _ word).trans empty + · refine ⟨fun x hx p sz u => h.lookup.vh.1 x hx p sz ((unm x hx p sz).1 u), ?_, + fun p reach hp => h.lookup.vh.2.2 p (desc2 p reach) hp⟩ + intro p reach hp hk + rcases h.lookup.vh.2.1 p (desc1 p reach) hp hk with hheap | ⟨r, hr, granule, x, hx, a, cap⟩ + · exact Or.inl hheap + · have ne : x ≠ slot := by rintro rfl; rw [old] at cap; cases cap + exact Or.inr ⟨r, hr, granule, x, hx, a, (keep x hx ne).trans cap⟩ + · intro x hx p a va cap + have ne : x ≠ slot := by rintro rfl; rw [new] at cap; cases cap + rw [keep x hx ne] at cap + rw [table.poolSet_eq (Pp := Pp)] + have pools : PoolSet st Pp s ⊆ Pt := fun _ hp => place.pools hp.1 + have high : HrOK (L.ksb s) (PoolSet st Pp s) Tb Lv Hr := + { place.high with pp := fun q hq => place.high.pp q hq.1 } + exact (h.walk x hx p a va cap).vkSeed (by simp) pools place.tables place.granules + place.stage2 high h.stage1 h.stage2 rfl ks mem + · refine ⟨?_, ?_⟩ + · intro a raw entry + obtain ⟨x, hx, cap⟩ := h.root.backed a raw (entry.back tab (fun q hq o ho h8 => + Or.inl (poolMem q hq o ho h8))) + exact ⟨x, hx, (root x hx _ _ _).2 cap⟩ + · intro x hx y hy p a b tag tag' cx cy + exact h.root.agree x hx y hy p a b tag tag' ((root x hx p a tag).1 cx) ((root y hy p b tag').1 cy) + +section decode +variable {A : Type _} {ar : machine.Arch A} {Cs Vc Ub U Ac Rp Nt : Set U64} + {K : capability.Cap → Prop} {Ty : S → Prop} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {slot ptr asid va : U64} + +variable + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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 + (.PageTable ptr false asid va) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr false asid va)) + (pt : PtCap st Pt OS s) (ept : EptPlaced st H OS Pt s) +include h place I D P cap pt ept + +omit h place pt ept in +/-- An already unmapped PageTable decoder keeps VSpace memory and rewrites +only the invoked capability when it restarts the caller. -/ +theorem vspace.decode_page_table.unmapUnmappedInvariant {Inv : S → Prop} + (entry : Inv s) + (reset : ∀ q, L.ksb q = L.ksb s → VsKeep st (L.ksb s) Pt s q → + capA st q slot = .PageTable ptr false 0#u64 0#u64 → + (∀ x ∈ OS, x ≠ slot → capA st q x = capA st s x) → Inv q) + (a : A) (len buf : U64) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap len slot (.PageTable ptr false asid va) + buf extra ⦃ _ q _ => Inv q ⦄ := by + have queues := D.bxi.1.choose_spec.choose_spec + unfold vspace.decode_page_table + rw [cur_thread_ok, bind_ok] + dsimp only + rw [if_pos rfl] + refine WP.spec_bind (P0.cdt.is_final_capability.p0 st s slot L.total) fun final _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => (WP.spec_ok _).2 entry) + refine WP.spec_bind (stt_vk I.del.vr queues queues.curT) fun q ⟨w, frame⟩ => ?_ + simp only [Bool.false_eq_true, if_false, bind_ok, uncurry_apply_pair] + refine WP.spec_bind (set_cap_ptu I.del.vr P.os P.src (canon_pt cap) q) fun out ⟨same, kept, written, base⟩ => ?_ + have newCap := okinj ((capA_eq out slot).symm.trans written) + have others : ∀ x ∈ OS, x ≠ slot → capA st out x = capA st s x := by + intro x hx ne + have keep := (kept x hx ne).trans (stt_capk P.os queues queues.curT w x hx) + rw [capA_eq, capA_eq] at keep + exact okinj keep + exact (WP.spec_ok _).2 (reset out (base.trans w.1) (frame.trans same) newCap others) + +/-- PageTableUnmap on an already unmapped cap preserves the lookup and typing core of R2. -/ +theorem vspace.decode_page_table.unmapUnmappedR2 (a : A) (len buf : U64) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap len slot (.PageTable ptr false asid va) + buf extra ⦃ _ q _ => S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n q ⦄ := by + have oldCap := okinj ((capA_eq s slot).symm.trans cap) + exact vspace.decode_page_table.unmapUnmappedInvariant I D P cap h + (fun _ base mem newCap others => h.resetUnmappedPageTable place base mem + (ept.unmZ h P.heap pt) oldCap newCap others) a len buf + +/-- The unmapped PageTableUnmap case reaches the R2 post at syscall dispatch. -/ +theorem syscall.decode_invocation.unmapUnmappedR2 (a : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.ARMPageTableUnmap len slot (.PageTable ptr false asid va) + blk call don fp buf extra ⦃ _ q _ => S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n q ⦄ := by + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + exact vspace.decode_page_table.unmapUnmappedR2 h place I D P cap pt ept a len buf + +end decode + +section mapped + +/-- Finality excludes the other PageTable caps. Object kind and heap separation +exclude every other way a mapped cap could name the same table. -/ +theorem MapV.notOfFinalPageTable {slot ptr asid va : U64} + (heap : HeapOK H) (high : HvObjects st H OS s) (kinds : KindA st OS s) + (member : slot ∈ OS) (cap : capA st s slot = .PageTable ptr true asid va) + (object : H ptr = some (.other 12)) + (uniqueCap : ∀ y ∈ OS, y ≠ slot → ¬ NmC st y ptr s) : + ∀ y ∈ OS, y ≠ slot → ¬ MapV (capA st s y) ptr := by + intro y hy different mapped + have otherKind : RngKeyA (capA st s y) → ptrA (capA st s y) = ptr → + kindA (capA st s y) ≠ 14 → False := by + intro key base kind + have same := kinds.kind y hy slot member key (by rw [cap]; exact RngKeyA.pt _ _ _ _) + (by rw [base, cap, ptrA_pt]) + rw [cap] at same + exact kind same + rcases mapped with ⟨a, v, eq⟩ | ⟨a, eq⟩ | ⟨a, eq⟩ | ⟨r, a, eq, addr⟩ | ⟨level, a, v, eq⟩ + · exact uniqueCap y hy different (NmC_iff.mpr (Or.inl ⟨true, a, v, eq⟩)) + · have phys := physA_eq (.Pml4 ptr true a) + have base := ptrA_eq (.Pml4 ptr true a) + simp only [objects.cap_is_physical] at phys + simp only [capability.Cap.ptr] at base + apply otherKind <;> rw [eq] + · exact ⟨(okinj phys).symm, rfl, rfl⟩ + · exact (okinj base).symm + · simp [kindA] + · apply otherKind <;> rw [eq] + · exact RngKeyA.hv _ _ _ + · exact ptrA_hv _ _ _ + · simp [kindA] + · exact high.second_ne heap hy eq object addr.symm + · exact uniqueCap y hy different (NmC_iff.mpr (Or.inr ⟨level, true, a, v, eq⟩)) + +/-- Once both active walks exclude the target, the exact four-KiB clear and +the cap rewrite preserve lookup, heap backing, and unmapped-object zeroes. -/ +theorem S1aR2Core.clearMappedPageTable {slot ptr asid va : U64} + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (tab : TabKeepOrZero st s s') (z : VsZ st (L.ksb s) Pt s s') + (unmapped : UnmZ st OS Pt (S2Rt st (PoolSet st Pp s) Te Re bits s) bits s) + (absent1 : ¬ VsReach st (PoolSet st Pp s') ∅ Lv s' ptr) + (absent2 : ¬ S2Reach st (PoolSet st Pp s') Re bits s' ptr) + (object : H ptr = some (.other 12)) + (old : capA st s slot = .PageTable ptr true asid va) + (new : capA st s' slot = .PageTable ptr false 0#u64 0#u64) + (other : ∀ x ∈ OS, x ≠ slot → capA st s' x = capA st s x) + (noAlias : ∀ y ∈ OS, y ≠ slot → ¬ MapV (capA st s y) ptr) + (zero : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s' (wa ptr o) = 0#u64) : + VsLk st H OS Pp Tb Te Kt Lv Re bits s' := by + have desc1 t (reach : VsReach st (PoolSet st Pp s') ∅ Lv s' t) := + reach.activeZero h.stage1 place.pools place.tables tab z + have desc2 t (reach : S2Reach st (PoolSet st Pp s') Re bits s' t) := + reach.activeZero h.stage2 place.pools place.granules place.stage2 tab z + have preName t (mapped : MapV (capA st s slot) t) : ptr = t := by + simpa [MapV, old] using mapped + have postUnmapped p size (cap : UnmCap (capA st s' slot) p size) : ptr = p ∧ size = 4096 := by + simpa [UnmCap, new, and_comm] using cap + have carry t (distinct : ptr ≠ t) (backed : ∃ x ∈ OS, MapV (capA st s x) t) : + ∃ x ∈ OS, MapV (capA st s' x) t := by + obtain ⟨x, hx, hxmap⟩ := backed + have different : x ≠ slot := by + rintro rfl + exact distinct (preName _ hxmap) + exact ⟨x, hx, (other x hx different).symm ▸ hxmap⟩ + refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ + · intro p reach ht hk + exact carry p (fun eq => absent1 (eq.symm ▸ reach)) (h.lookup.bk1 p (desc1 p reach) ht hk) + · intro p reach ht + exact carry p (fun eq => absent2 (eq.symm ▸ reach)) (h.lookup.bk2 p (desc2 p reach) ht) + · intro p hp x hx named + apply h.lookup.kt p hp x hx + by_cases he : x = slot + · subst x + simpa [NamesV, old] using (show ptr = p by simpa [NamesV, new] using named) + · rwa [other x hx he] at named + · intro x hx y hy p size hu hm + by_cases ey : y = slot + · subst y + simp [MapV, new] at hm + rw [other y hy ey] at hm + by_cases ex : x = slot + · subst x + obtain ⟨rfl, _⟩ := postUnmapped p size hu + exact noAlias y hy ey hm + rw [other x hx ex] at hu + exact h.lookup.ex x hx y hy p size hu hm + · intro x hx p size hu o ho h8 + by_cases ex : x = slot + · subst x + obtain ⟨rfl, rfl⟩ := postUnmapped p size hu + exact zero o ho h8 + rw [other x hx ex] at hu + obtain ⟨word, _, empty⟩ := unmapped.words (kb := L.ksb s) hx hu.toSlot ho h8 + exact (z _ word).elim (·.trans empty) id + · refine ⟨?_, ?_, fun p reach hp => h.lookup.vh.2.2 p (desc2 p reach) hp⟩ + · intro x hx p size hu + by_cases ex : x = slot + · subst x + obtain ⟨rfl, rfl⟩ := postUnmapped p size hu + exact ⟨12, by decide, object⟩ + rw [other x hx ex] at hu + exact h.lookup.vh.1 x hx p size hu + · intro p reach hp hk + rcases h.lookup.vh.2.1 p (desc1 p reach) hp hk with obj | ⟨r, obj, granule, x, hx, a, cap⟩ + · exact Or.inl obj + · have different : x ≠ slot := by rintro rfl; rw [old] at cap; cases cap + exact Or.inr ⟨r, obj, granule, x, hx, a, (other x hx different).trans cap⟩ + +/-- The exact post of a final mapped PageTable unmap. -/ +structure S1aPageTableClear (st : machine.Store S) [L : LawfulStore st] + (H : Heap) (OS Pt Pp Tb Hr Te Kt : Set U64) (Lv Re bits : U64 → Nat) + (s out : S) (slot ptr : U64) : Prop where + lookup : VsLk st H OS Pp Tb Te Kt Lv Re bits out + table : TabKeep st s out + headers : HrW st Hr s out + finality : ∀ y ∈ OS, y ≠ slot → ¬ NmC st y ptr s + memory : VsZ st (L.ksb s) Pt s out + cap : capA st out slot = .PageTable ptr false 0#u64 0#u64 + other : ∀ x ∈ OS, x ≠ slot → capA st out x = capA st s x + absent1 : ¬ VsReach st (PoolSet st Pp out) ∅ Lv out ptr + absent2 : ¬ S2Reach st (PoolSet st Pp out) Re bits out ptr + empty : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem out (wa ptr o) = 0#u64 + +set_option maxHeartbeats 3000000 in +/-- The mapped unmap decoder preserves lookup and the unmapped-object facts +through caller restart, the active walk, the explicit object zero, and the cap write. -/ +theorem vspace.decode_page_table.unmapMappedEffect {A : Type _} {ar : machine.Arch A} + {Cs Vc Ub U Ac Rp Nt : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot ptr asid va : U64} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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 + (.PageTable ptr true asid va) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr true asid va)) + (pt : PtCap st Pt OS s) (ept : EptPlaced st H OS Pt s) + (objects : PtObjects st H OS s) (high : HvObjects st H OS s) + (headerObjects : ∀ r ∈ Hr, H r = some (.other 13)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (a : A) (len buf : U64) : + vspace.decode_page_table st ar s a fl4_abi.label.ARMPageTableUnmap len slot (.PageTable ptr true asid va) + buf extra ⦃ _ q _ => q = s ∨ S1aPageTableClear st H OS Pt Pp Tb Hr Te Kt Lv Re bits s q slot ptr ⦄ := by + have vr := I.del.vr + have queues := D.bxi.1.choose_spec.choose_spec + have oldCap := okinj ((capA_eq s slot).symm.trans cap) + have pageObject : H ptr = some (.other 12) := objects slot P.src ptr true asid va oldCap + have ptrPlaced := pt slot P.src ptr true asid va oldCap + have ptrAligned : Aligned ptr := by + apply vr.al + exact Or.inl ⟨ptr, ptrPlaced, 0#u64, by simp, by simp, (SFF.wadd0' ptr).symm⟩ + have fits : ptr.val + 4096 ≤ 2 ^ 64 := P.heap.fits ptr _ pageObject + have unmapped := ept.unmZ h P.heap pt + obtain ⟨_, linked, ranges, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + unfold vspace.decode_page_table + rw [cur_thread_ok, bind_ok] + dsimp only + rw [if_pos rfl] + by_cases uniqueCap : ∀ y ∈ OS, y ≠ slot → ¬ NmC st y ptr s + swap + · simp only [not_forall, not_not] at uniqueCap + obtain ⟨y, hy, different, named⟩ := uniqueCap + rw [is_final.false_nmO P.os linked ranges kinds P.src cap hy different named, bind_ok] + exact spec_ite (fun e => absurd e (by decide)) (fun _ => (WP.spec_ok _).2 (Or.inl rfl)) + refine WP.spec_bind (P0.cdt.is_final_capability.p0 st s slot L.total) fun final _ => ?_ + refine spec_ite (fun _ => ?_) (fun _ => (WP.spec_ok _).2 (Or.inl rfl)) + refine WP.spec_bind (stt_vk vr queues queues.curT) fun q ⟨restart, frame⟩ => ?_ + have caps1 x (hx : x ∈ OS) : capA st q x = capA st s x := by + have kept := stt_capk P.os queues queues.curT restart x hx + rw [capA_eq, capA_eq] at kept + exact okinj kept + have r2q := h.keep place.pools place.tables place.granules place.stage2 place.high restart.1 frame caps1 + (fun x hx _ _ hu _ ho al => frame _ (unmapped.words (kb := L.ksb s) hx hu.toSlot ho al).1) + have placeq : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb q) := by rw [restart.1]; exact place + have vrq : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb q) Pt := by rw [restart.1]; exact vr + have found := r2q.walk slot P.src ptr asid va ((caps1 slot P.src).trans oldCap) + simp only [ite_true, ite_eq_left rfl, Std.bind_assoc, uncurry_apply_pair] + refine WP.spec_bind (vspace.unmap_page_table.activeUnr hA hPl a r2q placeq vrq.al found) ?_ + rintro ⟨m, a'⟩ ⟨cleared, highKeep, parent2, parent1, write⟩ + simp only [Std.bind_assoc, uncurry_apply_pair] + have writesM := Wr0.w (fun b hb => vrq.al b (Or.inl hb)) write + have tabM : TabKeepOrZero st q m := ⟨writesM.1, fun j => by + rw [writesM.1] + exact cleared _ (Or.inr (asW_at (L.ksb q) j))⟩ + have rootM := found.root.activeZero place.pools tabM cleared + have notReach1 : ¬ VsReach st (PoolSet st Pp m) ∅ Lv m ptr := by + apply VsReach.falseOfNoParent rootM + rintro ⟨b, p, o, reach, level, width, al, addr, tag, target⟩ + exact parent1 ⟨b, p, o, reach.poolMono tabM.poolSet, level, width, al, addr, tag, target⟩ + have notReach2 : ¬ S2Reach st (PoolSet st Pp m) Re bits m ptr := by + apply S2Reach.falseOfNoParent rootM + rintro ⟨b, p, o, reach, level, width, al, addr, tag, target⟩ + exact parent2 ⟨b, p, o, reach.poolMono tabM.poolSet, level, width, al, addr, tag, target⟩ + have mid1 := r2q.stage1.activeZero place.pools place.tables tabM cleared + have mid2 := r2q.stage2.activeZero place.pools place.granules place.stage2 tabM cleared highKeep + have baseM := writesM.1.trans restart.1 + have beforeZero : ∀ x ∈ OS, obj.Slot.cap st x m = obj.Slot.cap st x s := + fun x hx => (capk_vsr vrq P.os (writesM.mono fun _ hw => Or.inl hw) x hx).trans + (stt_capk P.os queues queues.curT restart x hx) + refine WP.spec_bind (LawfulStore.zero_spec m ptr 4096#u64) fun qz ze => ?_ + subst qz + simp only [bind_ok, uncurry_apply_pair] + refine WP.spec_bind (set_cap_ptu vr P.os P.src (canon_pt cap) _) fun out ⟨keep, others, written, kout⟩ => ?_ + have zeroWrites : WritesIn st m (L.zr m ptr 4096#u64) (PtW Pt) := + ⟨L.ksb_zr _ _ _, L.cpu_zr _ _ _, fun b hb hn => zr_ptw ptrAligned fits hb + (fun ⟨o, ho, al, addr⟩ => hn ⟨ptr, ptrPlaced, o, ho, al, addr⟩)⟩ + have baseOut := kout.trans ((L.ksb_zr _ _ _).trans baseM) + have after : VsZ st (L.ksb s) Pt m out := (zr_vsz vr.al ptrAligned fits).trans keep.vsz + have afterM : VsZ st (L.ksb m) Pt m out := by rw [baseM]; exact after + have post : VsZ st (L.ksb s) Pt s out := by + have cleared' : VsZ st (L.ksb s) Pt q m := by rw [← restart.1]; exact cleared + exact frame.vsz.trans (cleared'.trans after) + have tabOut : TabKeepOrZero st m out := ⟨baseOut.trans baseM.symm, fun j => by + rw [baseOut, baseM] + exact after _ (Or.inr (asW_at (L.ksb s) j))⟩ + have tab : TabKeepOrZero st s out := ⟨baseOut, fun j => by + rw [baseOut] + exact post _ (Or.inr (asW_at (L.ksb s) j))⟩ + have keptCaps : ∀ x ∈ OS, x ≠ slot → capA st out x = capA st s x := by + intro x hx different + have eq := (others x hx different).trans ((capk_vsr vr P.os (zeroWrites.mono fun _ hw => Or.inl hw) x hx).trans (beforeZero x hx)) + rw [capA_eq, capA_eq] at eq + exact okinj eq + have newCap := okinj ((capA_eq out slot).symm.trans written) + have absent1 : ¬ VsReach st (PoolSet st Pp out) ∅ Lv out ptr := + fun reach => notReach1 (reach.activeZero mid1 place.pools place.tables tabOut afterM) + have absent2 : ¬ S2Reach st (PoolSet st Pp out) Re bits out ptr := + fun reach => notReach2 (reach.activeZero mid2 place.pools place.granules place.stage2 tabOut afterM) + have empty (o : U64) (ho : o.val < 4096) (al : o.val % 8 = 0) : L.mem out (wa ptr o) = 0#u64 := by + rw [keep _ (Or.inl ⟨ptr, ptrPlaced, o, ho, al, rfl⟩)] + exact zr_ptw0 ptrAligned fits ho al + have lookup := h.clearMappedPageTable place tab post unmapped absent1 absent2 + pageObject oldCap newCap keptCaps (MapV.notOfFinalPageTable P.heap high kinds P.src oldCap pageObject uniqueCap) empty + have asids : TabKeep st s out := ⟨baseOut, fun i => by + rw [baseOut] + have wi := asW_at (L.ksb s) i + have ow := vr.al _ (Or.inr wi) + exact (keep _ (Or.inr wi)).trans + ((zeroWrites.mem_eq ow (fun p => ptKs _ p wi)).trans + ((writesM.mem_eq ow (fun p => ptKs _ p wi)).trans (frame _ (Or.inr wi))))⟩ + have headers : HrW st Hr s out := by + intro r hr + have placeWord : PtW Pt (wa r 4088#u64) := + ⟨r, place.tables (place.high.sub hr), 4088#u64, by decide, by decide, rfl⟩ + have obj := headerObjects r hr + have distinct : r ≠ ptr := by rintro rfl; rw [pageObject] at obj; cases obj + have outside : ¬ ∃ o : U64, o.val < 4096 ∧ o.val % 8 = 0 ∧ wa r 4088#u64 = wa ptr o := by + rintro ⟨o, ho, _, eq⟩ + exact tableWordsNe P.heap obj pageObject distinct (by decide) ho eq + exact (keep _ (Or.inl placeWord)).trans + ((zr_ptw ptrAligned fits (vr.al _ (Or.inl placeWord)) outside).trans + ((highKeep r hr).trans (frame _ (Or.inl placeWord)))) + exact (WP.spec_ok _).2 (Or.inr ⟨lookup, asids, headers, uniqueCap, post, newCap, keptCaps, absent1, absent2, empty⟩) + + +end mapped + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Relabel.lean b/proofs/Fl4ProofsA64/P1/S1aR2Relabel.lean new file mode 100644 index 000000000..63b534d52 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Relabel.lean @@ -0,0 +1,218 @@ +/- +P1 (aarch64, A64-S1A gen 41): R2 relabelled on its unreachable tables, giving the Assign root's descriptor facts +(Architect ruling D3, form C). + +R2 types only reachable tables, so its level witness on unreachable kernel tables and on the private level-1 tables +of unmapped HighVSpace roots is free. `relLv` keeps `Lv` on every reachable table and sets the column's `KLv` on the +kernel tables and `1` on those private tables (`Priv`), which join the table set. `S1aR2.relabel`: R2 holds at +`(Tb ∪ Priv, relLv)`. `S1aR2.assignDescK`: there, every unmapped HighVSpace root has `S1aAssignDesc`. + +Named premises: none. New definitions and theorems only. +-/ +import Fl4ProofsA64.P1.S1aR2KtLevel + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {s : S} + +variable (st) in +/-- The private level-1 tables of the unmapped HighVSpace caps. -/ +def Priv (OS : Set U64) (s : S) : Set U64 := + {q | ∃ y ∈ OS, ∃ r a, capA st s y = .HighVSpace r false a ∧ q = wa r 4096#u64} + +open Classical in +variable (st) in +/-- **The relabelled level** (module docstring). -/ +noncomputable def relLv (OS Pp Kt : Set U64) (Lv KLv : U64 → Nat) (s : S) (t : U64) : Nat := + if VsReach st (PoolSet st Pp s) ∅ Lv s t then Lv t else if t ∈ Kt then KLv t + else if t ∈ Priv st OS s then 1 else Lv t + +theorem relLv_reach {t : U64} (h : VsReach st (PoolSet st Pp s) ∅ Lv s t) : + relLv st OS Pp Kt Lv KLv s t = Lv t := by + unfold relLv; rw [if_pos h] + +theorem relLv_iff {t : U64} : + VsReach st (PoolSet st Pp s) ∅ (relLv st OS Pp Kt Lv KLv s) s t ↔ VsReach st (PoolSet st Pp s) ∅ Lv s t := + VsReach.congrWords (q := s) (fun _ _ _ _ _ => rfl) (fun _ hp => ⟨relLv_reach hp, fun _ _ _ => rfl⟩) + +section +variable (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (K : S1aHiK st OS Kt KLv s) +include R K + +theorem relLv_kt {t : U64} (ht : t ∈ Kt) : relLv st OS Pp Kt Lv KLv s t = KLv t := by + unfold relLv + by_cases h : VsReach st (PoolSet st Pp s) ∅ Lv s t + · rw [if_pos h]; exact R.ktLevel K h ht + · rw [if_neg h, if_pos ht] + +include heap in +theorem relLv_root {r : U64} (hr : r ∈ Hr) : relLv st OS Pp Kt Lv KLv s r = 0 := by + have zero := R.place.high.lv r hr + have hr' : r ∈ HvRt st OS s := R.highRoots ▸ hr + obtain ⟨y, hy, m, a, cap⟩ := hr' + unfold relLv + by_cases h : VsReach st (PoolSet st Pp s) ∅ Lv s r + · rw [if_pos h]; exact zero + · rw [if_neg h] + have nk : r ∉ Kt := fun hk => R.core.lookup.kt _ hk y hy (Or.inr (Or.inr (Or.inl ⟨m, a, cap⟩))) + have np : r ∉ Priv st OS s := by + rintro ⟨y', hy', r', a', cap', rfl⟩ + exact second_not_hv heap (R.highObjects y' hy' r' false a' cap') (R.highObjects y hy _ m a cap) rfl + rw [if_neg nk, if_neg np]; exact zero + +include heap in +theorem relLv_priv {y r a : U64} (hy : y ∈ OS) (cap : capA st s y = .HighVSpace r false a) : + relLv st OS Pp Kt Lv KLv s (wa r 4096#u64) = 1 := by + unfold relLv + have nr := R.unmappedPrivateUnreached heap hy cap + have nk : wa r 4096#u64 ∉ Kt := fun hk => + R.core.lookup.kt _ hk y hy (Or.inr (Or.inr (Or.inr (Or.inl ⟨r, false, a, cap, rfl⟩)))) + rw [if_neg nr, if_neg nk, if_pos ⟨y, hy, r, a, cap, rfl⟩] + +end + +private theorem val4096 {r : U64} (f : r.val + 8192 ≤ 2 ^ 64) : (wa r 4096#u64).val = r.val + 4096 := by + have h4 : (4096#u64 : U64).val = 4096 := by simp + rw [wadd_val (by rw [h4]; omega), h4] + +private theorem hvAl (heap : HeapOK H) {r : U64} (h : H r = some (.other 13)) : + r.val % 8192 = 0 ∧ r.val + 8192 ≤ 2 ^ 64 := by + have a := heap.align r _ h + have f := heap.fits r _ h + simp only [HKind.bits] at a f + norm_num at a f + exact ⟨a, by omega⟩ + +/-- A private-table word is no header `+ 4088` word. -/ +theorem priv_ne_hdr (heap : HeapOK H) {r R o : U64} (hr : H r = some (.other 13)) (hR : H R = some (.other 13)) + (ho : o.val < 4096) : wa (wa r 4096#u64) o ≠ wa R 4088#u64 := by + intro e + obtain ⟨ar, fr⟩ := hvAl heap hr + obtain ⟨aR, fR⟩ := hvAl heap hR + have h88 : (4088#u64 : U64).val = 4088 := by simp + have v := congrArg UScalar.val e + rw [wadd_val (by rw [val4096 fr]; omega), val4096 fr, wadd_val (by rw [h88]; omega), h88] at v + by_cases same : r = R + · subst same; omega + · have d := heap.disj r _ R _ hr hR same + simp only [HKind.bits] at d + norm_num at d + omega + +/-- **R2 at the relabelled witnesses.** -/ +theorem S1aR2.relabel (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (K : S1aHiK st OS Kt KLv s) : + S1aR2 st H OS Pt Pp (Tb ∪ Priv st OS s) Hr Te Kt (relLv st OS Pp Kt Lv KLv s) Re bits n s := by + have iff : ∀ t, VsReach st (PoolSet st Pp s) ∅ (relLv st OS Pp Kt Lv KLv s) s t ↔ + VsReach st (PoolSet st Pp s) ∅ Lv s t := fun _ => relLv_iff + have mem : ∀ t, VsReach st (PoolSet st Pp s) ∅ Lv s t → t ∈ Tb := fun _ h => R.core.stage1.reachableMember h + have privPt : Priv st OS s ⊆ Pt := by + rintro q ⟨y, hy, r, a, cap, rfl⟩ + have hr : r ∈ Hr := by rw [R.highRoots]; exact ⟨y, hy, false, a, cap⟩ + exact R.highFootprint ⟨r, hr, Or.inr ⟨rfl, rfl⟩⟩ + have nm : ∀ ptr b, VsNm st (PoolSet st Pp s) ∅ (relLv st OS Pp Kt Lv KLv s) s ptr b → + VsNm st (PoolSet st Pp s) ∅ Lv s ptr b := by + rintro ptr b ⟨p, o, reach, lv, rest⟩ + have r' := (iff p).1 reach + exact ⟨p, o, r', by rw [← relLv_reach r']; exact lv, rest⟩ + have lookup : VsLk st H OS Pp (Tb ∪ Priv st OS s) Te Kt (relLv st OS Pp Kt Lv KLv s) Re bits s := + { R.core.lookup with + bk1 := fun t reach _ nk => R.core.lookup.bk1 t ((iff t).1 reach) (mem t ((iff t).1 reach)) nk + vh := ⟨R.core.lookup.vh.1, + fun t reach _ nk => R.core.lookup.vh.2.1 t ((iff t).1 reach) (mem t ((iff t).1 reach)) nk, + R.core.lookup.vh.2.2⟩ } + have walk : PtFndAll st OS Pp (relLv st OS Pp Kt Lv KLv s) Re bits n s := by + intro y hy p asid va cap + have f := R.core.walk y hy p asid va cap + exact ⟨f.root, f.s2, fun b h => f.s1 b (nm p b h)⟩ + have stage1 : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ (Tb ∪ Priv st OS s) (relLv st OS Pp Kt Lv KLv s) s := by + refine ⟨R.core.stage1.tbl, fun p hp o ho al nz => ?_, fun p _ reach lv o ho al edge => ?_⟩ + · obtain ⟨a0, a2⟩ := R.core.stage1.pool p hp o ho al nz + refine ⟨fun t0 => ?_, fun t2 => ?_⟩ + · obtain ⟨m, l⟩ := a0 t0 + exact ⟨Or.inl m, by rw [relLv_reach (.root0 hp ho al nz t0)]; exact l⟩ + · obtain ⟨m, l⟩ := a2 t2 + exact ⟨Or.inl m, by rw [relLv_reach (.root2 hp ho al t2)]; exact l⟩ + · have r' := (iff p).1 reach + have e := relLv_reach (OS := OS) (Kt := Kt) (KLv := KLv) r' + rw [e] at lv ⊢ + obtain ⟨m, l⟩ := R.core.stage1.desc p (mem p r') r' lv o ho al edge + exact ⟨Or.inl m, by rw [relLv_reach (.step r' lv ho al edge)]; exact l⟩ + have high : HrOK (L.ksb s) (PoolSet st Pp s) (Tb ∪ Priv st OS s) (relLv st OS Pp Kt Lv KLv s) Hr := by + refine ⟨fun r hr => Or.inl (R.place.high.sub hr), fun r hr => relLv_root R heap K hr, + fun t ht o ho al r hr e => ?_, R.place.high.pp, R.place.high.asw⟩ + rcases ht with ht | ⟨y, hy, r0, a, cap, rfl⟩ + · exact R.place.high.tb t ht o ho al r hr e + · have hr' : r ∈ HvRt st OS s := R.highRoots ▸ hr + obtain ⟨y', hy', m', a', cap'⟩ := hr' + exact (priv_ne_hdr heap (R.highObjects y hy r0 false a cap) (R.highObjects y' hy' r m' a' cap') ho e).elim + have paths : S1aPathBacking st H OS Pp (Tb ∪ Priv st OS s) Te (relLv st OS Pp Kt Lv KLv s) Re bits n s := by + refine ⟨fun tag asid shift vaBase t p => ?_, R.paths.children, R.paths.leaves⟩ + have old := R.paths.tables tag asid shift vaBase t p + by_cases stage : tag = 1#u64 + · rw [if_pos stage] at old ⊢; exact old + · rw [if_neg stage] at old ⊢ + have reach := p.toStage1 stage + (fun k b t' q => by + have g := R.paths.tables tag asid k b t' q + rw [if_neg stage] at g + exact g.2) + (fun a raw entry kind => by + obtain ⟨x, hx, cap⟩ := R.highOf entry kind + exact R.place.high.lv _ (by rw [R.highRoots]; exact ⟨x, hx, true, a, cap⟩)) + rw [relLv_reach reach] + exact ⟨Or.inl old.1, old.2⟩ + exact { + core := { R.core with lookup := lookup, walk := walk, stage1 := stage1 } + place := ⟨R.place.pools, Set.union_subset R.place.tables privPt, R.place.granules, high, R.place.stage2⟩ + poolCaps := R.poolCaps + capRefs := R.capRefs + paths := paths + pageTables := R.pageTables + footprint := R.footprint + pageObjects := R.pageObjects + nativeRoots := R.nativeRoots + eptRoots := R.eptRoots + highObjects := R.highObjects + highHeaders := R.highHeaders + highLink := R.highLink + highRoots := R.highRoots + highFootprint := R.highFootprint + kernelTables := ⟨fun t ht => Or.inl (R.kernelTables.1 ht), R.kernelTables.2⟩ + kernelClosed := fun t ht lv o ho al edge => by + rw [relLv_kt R K ht] at lv + exact (K.kt t ht lv o ho al edge).1 + rootSlots := R.rootSlots } + +/-- **The Assign root's descriptor facts at the relabelled witnesses.** -/ +theorem S1aR2.assignDescK (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) + (K : S1aHiK st OS Kt KLv s) : + ∀ y ∈ OS, ∀ r a, capA st s y = .HighVSpace r false a → + S1aAssignDesc st (Tb ∪ Priv st OS s) Kt (relLv st OS Pp Kt Lv KLv s) s r := by + intro y hy r a cap p which _ lv o ho al edge + have hr : r ∈ Hr := by rw [R.highRoots]; exact ⟨y, hy, false, a, cap⟩ + rcases which with rfl | rfl | hk + · rw [relLv_root R heap K hr] + by_cases off : o.val < 4088 + · obtain ⟨ck, cl⟩ := K.hdr y hy p false a cap o off al edge + unfold kChild at ck cl + exact ⟨Or.inl (R.kernelTables.1 ck), by rw [relLv_kt R K ck, cl]⟩ + · have last : o = 4088#u64 := UScalar.eq_of_val_eq (by change o.val = 4088; omega) + subst last + rw [R.highLink p hr] + exact ⟨Or.inr ⟨y, hy, p, a, cap, rfl⟩, by rw [relLv_priv R heap K hy cap]⟩ + · have z := R.capRefs.highEmpty y hy r a cap o ho al + rw [z] at edge + exact absurd edge (by decide) + · rw [relLv_kt R K hk] at lv ⊢ + obtain ⟨ck, cl⟩ := K.kt p hk lv o ho al edge + unfold kChild at ck cl + exact ⟨Or.inl (R.kernelTables.1 ck), by rw [relLv_kt R K ck, cl]⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Restrict.lean b/proofs/Fl4ProofsA64/P1/S1aR2Restrict.lean new file mode 100644 index 000000000..94174f3c8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Restrict.lean @@ -0,0 +1,319 @@ +/- +P1 (aarch64): R2 survives dropping unreferenced heap objects and null slots at one state. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2RetypeNew +import Fl4ProofsA64.P1.S1aR2UnmapRoute + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H H' : Heap} {OS O' Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} + +private theorem baseWord (t : U64) : wa t 0#u64 = t := by + apply UScalar.eq_of_val_eq + rw [wa_val] + have : t.val < 2 ^ 64 := by scalar_tac + simp [Nat.mod_eq_of_lt this] + +/-- The footprint pages that still lie inside an object of the smaller heap. -/ +def s1aKeptPt (H' : Heap) (Pt : Set U64) : Set U64 := {t | t ∈ Pt ∧ PtHG H' {t}} + +/-- The data of a heap and slot restriction that keeps every referenced object. -/ +structure S1aRestrict (st : machine.Store S) [L : LawfulStore st] (H H' : Heap) (OS O' Kt : Set U64) (s : S) : Prop where + heap : HeapOK H + sub : ∀ t k, H' t = some k → H t = some k + slots : O' ⊆ OS + nonnull : ∀ y ∈ OS, capA st s y ≠ .Null → y ∈ O' + survive : ∀ t k, H t = some k → (t ∈ Kt ∨ ∃ y ∈ OS, RngKeyA (capA st s y) ∧ ptrA (capA st s y) = t) → + H' t = some k + +namespace S1aRestrict + +variable (E : S1aRestrict st H H' OS O' Kt s) +include E + +theorem heapOK : HeapOK H' := + ⟨fun p k obj => E.heap.align p k (E.sub p k obj), fun p k obj => E.heap.fits p k (E.sub p k obj), + fun p k obj => E.heap.lt64 p k (E.sub p k obj), fun p z obj => E.heap.scmin p z (E.sub p _ obj), + fun p k q k' obj obj' ne => E.heap.disj p k q k' (E.sub p k obj) (E.sub q k' obj') ne⟩ + +theorem keep {y : U64} (hy : y ∈ OS) {c : capability.Cap} (cap : capA st s y = c) (nonnull : c ≠ .Null) : y ∈ O' := + E.nonnull y hy (cap ▸ nonnull) + +/-- The object named by a live table or pool capability survives. -/ +theorem named {y t : U64} {k : HKind} (hy : y ∈ OS) {c : capability.Cap} (cap : capA st s y = c) + (key : RngKeyA c) (ptr : ptrA c = t) (obj : H t = some k) : H' t = some k := + E.survive t k obj (Or.inr ⟨y, hy, cap.symm ▸ key, cap.symm ▸ ptr⟩) + +/-- A heap object whose first word is owned survives. -/ +theorem objKeep {t : U64} {k : HKind} (obj : H t = some k) (own : S1aRetypeWordOwner st H OS Kt s t) : + H' t = some k := by + obtain ⟨r, kind, found, inside, kernel | held⟩ := own + all_goals + have same : r = t := by + by_contra different + have disjoint := E.heap.disj r kind t k found obj different + have positive := Nat.two_pow_pos k.bits + unfold InObj at inside + generalize kind.bits = width at disjoint inside + generalize k.bits = other at disjoint positive + generalize (2 : Nat) ^ width = A at disjoint inside + generalize (2 : Nat) ^ other = B at disjoint positive + omega + subst r + rw [obj] at found + obtain rfl := Option.some.inj found + · exact E.survive t _ obj (Or.inl kernel.1) + · exact E.survive t _ obj (Or.inr held) + +/-- A footprint page whose first word is owned stays in the footprint. -/ +theorem placed (footprint : PtHG H Pt) {t : U64} (member : t ∈ Pt) (own : S1aRetypeWordOwner st H OS Kt s t) : + t ∈ s1aKeptPt H' Pt := by + obtain ⟨al, base, z, object, low, high⟩ := footprint t member + refine ⟨member, fun u hu => ?_⟩ + obtain rfl := Set.mem_singleton_iff.mp hu + refine ⟨al, base, z, ?_, low, high⟩ + obtain ⟨r, kind, found, inside, held⟩ := own + have same : r = base := by + by_contra different + have disjoint := E.heap.disj r kind base (.other z) found object different + unfold InObj at inside + rw [show HKind.bits (.other z) = z from rfl] at disjoint + generalize kind.bits = width at disjoint inside + generalize (2 : Nat) ^ z = Z at disjoint high + generalize (2 : Nat) ^ width = K at disjoint inside + omega + subst r + rw [object] at found + obtain rfl := Option.some.inj found + rcases held with kernel | held + · exact E.survive _ _ object (Or.inl kernel.1) + · exact E.survive _ _ object (Or.inr held) + +/-- A page inside a surviving object stays in the footprint. -/ +theorem inside {t q : U64} {z : Nat} (member : t ∈ Pt) (al : t.val % 4096 = 0) (obj : H' q = some (.other z)) + (low : q.val ≤ t.val) (high : t.val + 4096 ≤ q.val + 2 ^ z) : t ∈ s1aKeptPt H' Pt := by + refine ⟨member, fun u hu => ?_⟩ + obtain rfl := Set.mem_singleton_iff.mp hu + exact ⟨al, q, z, obj, low, high⟩ + +/-- Both granules of a surviving 8 KiB object, and the page of a surviving 4 KiB one, stay placed. -/ +theorem granule {t g : U64} {z : Nat} (obj : H' t = some (.other z)) (size : z = 12 ∨ z = 13) + (which : g = t ∨ (z = 13 ∧ g = wa t 4096#u64)) (member : g ∈ Pt) : g ∈ s1aKeptPt H' Pt := by + have al := E.heapOK.align t _ obj + have fit := E.heapOK.fits t _ obj + change t.val % 2 ^ z = 0 at al + change t.val + 2 ^ z ≤ 2 ^ 64 at fit + have base : t.val % 4096 = 0 := by rcases size with rfl | rfl <;> norm_num at al <;> omega + rcases which with rfl | ⟨wide, rfl⟩ + · exact E.inside member base obj le_rfl (by rcases size with rfl | rfl <;> norm_num) + · subst wide + norm_num at al fit + have v : (wa t 4096#u64).val = t.val + 4096 := wadd_val (by change t.val + 4096 < 2 ^ 64; omega) + exact E.inside member (by rw [v]; omega) obj (by rw [v]; omega) (by rw [v]; norm_num) + +end S1aRestrict + +set_option maxHeartbeats 4000000 in +/-- R2 over the smaller heap and slot set, with the table witnesses pruned to surviving objects. -/ +theorem S1aR2.restrict (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (E : S1aRestrict st H H' OS O' Kt s) (kinds : KindA st OS s) (frames : FrameOK st H' O' s) : + S1aR2 st H' O' (s1aKeptPt H' Pt) Pp {t | t ∈ Tb ∧ t ∈ s1aKeptPt H' Pt} (HvRt st O' s) + {t | t ∈ Te ∧ H' t = some (.other (bits t))} Kt Lv Re bits n s := by + have roots : HvRt st O' s ⊆ Hr := by + rintro R ⟨y, hy, m, a, cap⟩ + rw [h.highRoots] + exact ⟨y, E.slots hy, m, a, cap⟩ + have kinds' : KindA st O' s := ⟨fun x hx y hy => kinds.kind x (E.slots hx) y (E.slots hy)⟩ + have heap' := E.heapOK + have pageObj : PtObjects st H' O' s := fun y hy t m a v cap => + E.named (E.slots hy) cap (RngKeyA.pt t m a v) (ptrA_pt t m a v) (h.pageObjects y (E.slots hy) t m a v cap) + have highObj : HvObjects st H' O' s := fun y hy t m a cap => + E.named (E.slots hy) cap (RngKeyA.hv t m a) (ptrA_hv t m a) (h.highObjects y (E.slots hy) t m a cap) + have nativeObj : ∀ y ∈ O', ∀ t m a, capA st s y = .Pml4 t m a → + H' t = some (.other 12) ∧ t ∈ s1aKeptPt H' Pt := by + intro y hy t m a cap + obtain ⟨obj, member⟩ := h.nativeRoots y (E.slots hy) t m a cap + have kept := E.named (E.slots hy) cap (RngKeyA.pml4 t m a) (ptrA_pml4 t m a) obj + exact ⟨kept, E.granule kept (Or.inl rfl) (Or.inl rfl) member⟩ + have ept : EptPlaced st H' O' (s1aKeptPt H' Pt) s := by + intro y hy t l m a v cap + obtain ⟨obj, granules⟩ := h.eptRoots y (E.slots hy) t l m a v cap + have kept := E.named (E.slots hy) cap (RngKeyA.ept t l m a v) (ptrA_ept t l m a v) obj + refine ⟨kept, fun g member => ?_⟩ + have placed := granules member + obtain ⟨u, hu, which⟩ := member + obtain rfl := Set.mem_singleton_iff.mp hu + exact E.granule kept (Or.inr rfl) which placed + have highPages : Gran (HvRt st O' s) (fun _ => 13) ⊆ s1aKeptPt H' Pt := by + rintro g ⟨R, member, which⟩ + have placed : g ∈ Pt := h.highFootprint ⟨R, roots member, which⟩ + obtain ⟨y, hy, m, a, cap⟩ := member + exact E.granule (highObj y hy R m a cap) (Or.inr rfl) which placed + have poolPage {t : U64} (active : t ∈ PoolSet st Pp s) : t ∈ s1aKeptPt H' Pt := by + have own := (h.poolWordOwner E.heap active (o := 0#u64) (by decide) (by decide)).2 + rw [baseWord] at own + exact E.placed h.footprint (h.place.pools active) own + have reach1 {t : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) (member : t ∈ Tb) : + t ∈ s1aKeptPt H' Pt := by + have own := (h.reachWord1 E.heap reach (o := 0#u64) (by decide) (by decide)).2 + rw [baseWord] at own + exact E.placed h.footprint (h.place.tables member) own + have reach2 {t : U64} (reach : S2Reach st (PoolSet st Pp s) Re bits s t) (member : t ∈ Te) : + H' t = some (.other (bits t)) := by + have own := (h.reachWord2 E.heap reach (o := 0#u64) (Nat.two_pow_pos _) (by decide)).2 + rw [baseWord] at own + exact E.objKeep (h.core.heap t member).1 own + have mapped {y t : U64} (hy : y ∈ OS) (named : MapV (capA st s y) t) : y ∈ O' := by + refine E.nonnull y hy fun empty => ?_ + rw [empty] at named + rcases named with ⟨_, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, e, _⟩ | ⟨_, _, _, e⟩ <;> cases e + have lookup : VsLk st H' O' Pp {t | t ∈ Tb ∧ t ∈ s1aKeptPt H' Pt} {t | t ∈ Te ∧ H' t = some (.other (bits t))} + Kt Lv Re bits s := by + refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ + · intro t reach member outside + obtain ⟨y, hy, named⟩ := h.core.lookup.bk1 t reach member.1 outside + exact ⟨y, mapped hy named, named⟩ + · intro t reach member + obtain ⟨y, hy, named⟩ := h.core.lookup.bk2 t reach member.1 + exact ⟨y, mapped hy named, named⟩ + · exact fun t kernel y hy => h.core.lookup.kt t kernel y (E.slots hy) + · exact fun x hx y hy => h.core.lookup.ex x (E.slots hx) y (E.slots hy) + · exact fun x hx => h.core.lookup.zr x (E.slots hx) + · intro x hx t width unm + obtain ⟨z, exactSize, obj⟩ := h.core.lookup.vh.1 x (E.slots hx) t width unm + refine ⟨z, exactSize, ?_⟩ + rcases unm with ⟨_, a, v, cap⟩ | ⟨_, a, v, cap⟩ + · exact E.named (E.slots hx) cap (RngKeyA.pt _ _ _ _) (ptrA_pt _ _ _ _) obj + · exact E.named (E.slots hx) cap (RngKeyA.ept _ _ _ _ _) (ptrA_ept _ _ _ _ _) obj + · intro t reach member outside + rcases h.core.lookup.vh.2.1 t reach member.1 outside with plain | ⟨R, obj, which, y, hy, a, cap⟩ + · have own := (h.reachWord1 E.heap reach (o := 0#u64) (by decide) (by decide)).2 + rw [baseWord] at own + exact Or.inl (E.objKeep plain own) + · have live := E.keep hy cap (fun e => by cases e) + exact Or.inr ⟨R, E.named hy cap (RngKeyA.hv _ _ _) (ptrA_hv _ _ _) obj, which, y, live, a, cap⟩ + · exact fun t _ member => member.2 + have agreement : RootAgreement st O' Pp s := by + refine ⟨fun asid raw entry => ?_, fun x hx y hy => h.core.root.agree x (E.slots hx) y (E.slots hy)⟩ + obtain ⟨x, hx, backed⟩ := h.core.root.backed asid raw entry + refine ⟨x, E.nonnull x hx (fun empty => ?_), backed⟩ + rw [empty] at backed + rcases backed with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e + have capRefs : S1aTableCaps st O' s := + ⟨fun x hx y hy => h.capRefs.references x (E.slots hx) y (E.slots hy), + fun x hx y hy => h.capRefs.unique x (E.slots hx) y (E.slots hy), + fun x hx => h.capRefs.nativeEmpty x (E.slots hx), fun x hx => h.capRefs.highEmpty x (E.slots hx)⟩ + have exactPaths : S1aPathBacking st H' O' Pp {t | t ∈ Tb ∧ t ∈ s1aKeptPt H' Pt} + {t | t ∈ Te ∧ H' t = some (.other (bits t))} Lv Re bits n s := by + have pathOwn {tag asid t : U64} {sh va : Nat} (path : S1aPath st Pp n s tag asid sh va t) : + S1aRetypeWordOwner st H OS Kt s t := by + have positive : 0 < s1aTableStorage tag n sh := by + unfold s1aTableStorage + split <;> decide + have own := (h.storageWord E.heap path (o := 0#u64) positive (by decide)).2 + rwa [baseWord] at own + refine ⟨fun tag asid sh va t path => ?_, fun tag asid sh va t path child => ?_, + fun tag asid sh va t path o bound al range valid => ?_⟩ + · have typed := h.paths.tables tag asid sh va t path + by_cases stage : tag = 1#u64 + · rw [ite_eq_left stage] at typed ⊢ + exact ⟨⟨typed.1, E.objKeep (h.core.heap t typed.1).1 (pathOwn path)⟩, typed.2⟩ + · rw [ite_eq_right stage] at typed ⊢ + exact ⟨⟨typed.1, E.placed h.footprint (h.place.tables typed.1) (pathOwn path)⟩, typed.2⟩ + · obtain ⟨x, hx, address, cap, ref⟩ := h.paths.children tag asid sh va t path child + exact ⟨x, E.keep hx cap (fun e => by cases e), address, cap, ref⟩ + · obtain ⟨x, hx, sz, rights, device, address, size, cap, ref, _⟩ := + h.paths.leaves tag asid sh va t path o bound al range valid + 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 + 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⟩ + · 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⟩ + have highPlace : HrOK (L.ksb s) (PoolSet st Pp s) {t | t ∈ Tb ∧ t ∈ s1aKeptPt H' Pt} Lv (HvRt st O' s) := by + refine ⟨fun R member => ⟨h.place.high.sub (roots member), highPages ⟨R, member, Or.inl rfl⟩⟩, + fun R member => h.place.high.lv R (roots member), + fun t table o bound al R member => h.place.high.tb t table.1 o bound al R (roots member), + fun t active o bound al R member => h.place.high.pp t active o bound al R (roots member), + fun R member => h.place.high.asw R (roots member)⟩ + have stage2Place : S2OK {t | t ∈ Te ∧ H' t = some (.other (bits t))} bits (HvRt st O' s) := by + refine ⟨fun t member => h.place.stage2.sz t member.1, fun t member => h.place.stage2.al t member.1, ?_⟩ + rintro b ⟨t, member, o, bound, al, rfl⟩ R root + exact h.place.stage2.hr _ ⟨t, member.1, o, bound, al, rfl⟩ R (roots root) + have highLink : ∀ R ∈ HvRt st O' s, + wa (L.mem s (wa R 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE = wa R 4096#u64 := + fun R member => h.highLink R (roots member) + have closed := h.kernelClosed + have rootSlots : S1aRootSlots st O' Kt n s := + ⟨fun x hx => h.rootSlots.native x (E.slots hx), fun x hx => h.rootSlots.stage2 x (E.slots hx), + fun x hx => h.rootSlots.highCopies x (E.slots hx), fun x hx => h.rootSlots.highPrivate x (E.slots hx)⟩ + have routes : S1aRouteFacts st H' O' (s1aKeptPt H' Pt) Pp {t | t ∈ Tb ∧ t ∈ s1aKeptPt H' Pt} (HvRt st O' s) + {t | t ∈ Te ∧ H' t = some (.other (bits t))} Kt Lv Re bits n s := + ⟨lookup, agreement, typedHeap, exactPaths, capRefs, rootSlots, rfl, highLink, highObj, ept, pageObj, closed⟩ + have kernel {t : U64} (member : t ∈ Kt) : H' t = some (.other 12) := + E.survive t _ (h.kernelTables.2 t member) (Or.inl member) + refine { + core := ⟨lookup, routes.recoverWalk heap' kinds', agreement, ?_, ?_, typedHeap⟩ + place := ⟨fun t active => poolPage active, fun t member => member.2, ?_, highPlace, stage2Place⟩ + poolCaps := ?_ + capRefs := capRefs + paths := exactPaths + pageTables := fun y hy t m a v cap => ?_ + footprint := fun t member => member.2 t rfl + pageObjects := pageObj + nativeRoots := nativeObj + eptRoots := ept + highObjects := highObj + highHeaders := fun x hx => h.highHeaders x (E.slots hx) + highLink := highLink + highRoots := rfl + highFootprint := highPages + kernelTables := ⟨fun t member => ⟨h.kernelTables.1 member, + E.granule (kernel member) (Or.inl rfl) (Or.inl rfl) (h.place.tables (h.kernelTables.1 member))⟩, + fun t member => kernel member⟩ + kernelClosed := closed + rootSlots := rootSlots } + · refine ⟨h.core.stage1.tbl, fun t active o bound al nz => ?_, fun t member reach level o bound al edge => ?_⟩ + · have old := h.core.stage1.pool t active o bound al nz + refine ⟨fun tag => ?_, fun tag => ?_⟩ + · have walk := VsReach.root0 (Hr := ∅) (Lv := Lv) active bound al nz tag + exact ⟨⟨(old.1 tag).1, reach1 walk (old.1 tag).1⟩, (old.1 tag).2⟩ + · have walk := VsReach.root2 (Hr := ∅) (Lv := Lv) active bound al tag + exact ⟨⟨(old.2 tag).1, reach1 walk (old.2 tag).1⟩, (old.2 tag).2⟩ + · obtain ⟨target, next⟩ := h.core.stage1.desc t member.1 reach level o bound al edge + exact ⟨⟨target, reach1 (VsReach.step reach level bound al edge) target⟩, next⟩ + · refine ⟨fun t active o bound al nz => ?_, fun R member => h.core.stage2.hi R (roots member), + fun t member reach level o bound al edge => ?_⟩ + · rcases h.core.stage2.tag t active o bound al nz with ⟨tag, outside⟩ | ⟨tag, held⟩ | ⟨tag, member, level, size⟩ + · exact Or.inl ⟨tag, fun member => outside (roots member)⟩ + · rw [h.highRoots] at held + obtain ⟨y, hy, m, a, cap⟩ := held + exact Or.inr (Or.inl ⟨tag, y, E.keep hy cap (fun e => by cases e), m, a, cap⟩) + · have walk := S2Reach.root (Re := Re) (bits := bits) active bound al tag + exact Or.inr (Or.inr ⟨tag, ⟨member, reach2 walk member⟩, level, size⟩) + · obtain ⟨target, next⟩ := h.core.stage2.desc t member.1 reach level o bound al edge + exact ⟨⟨target, reach2 (S2Reach.step reach level bound al edge) target⟩, next⟩ + · rintro g ⟨t, member, which⟩ + exact E.granule member.2 (h.place.stage2.sz t member.1) which (h.place.granules ⟨t, member.1, which⟩) + · refine ⟨fun i hi p word nz => ?_, fun x hx p base cap => h.poolCaps.cap x (E.slots hx) p base cap, + h.poolCaps.index, h.poolCaps.noZero⟩ + obtain ⟨active, member, obj, x, hx, base, cap, low⟩ := h.poolCaps.present i hi p word nz + have kept := E.named hx cap (RngKeyA.ap p base) (ptrA_ap p base) obj + exact ⟨active, E.granule kept (Or.inl rfl) (Or.inl rfl) member, kept, x, + E.keep hx cap (fun e => by cases e), base, cap, low⟩ + · have member := h.pageTables y (E.slots hy) t m a v cap + exact E.granule (pageObj y hy t m a v cap) (Or.inl rfl) (Or.inl rfl) member + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2RetypeEnd.lean b/proofs/Fl4ProofsA64/P1/S1aR2RetypeEnd.lean new file mode 100644 index 000000000..f7f12961b --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2RetypeEnd.lean @@ -0,0 +1,221 @@ +/- +P1 (aarch64): old objects, new objects and capability provenance at a Retype creation end. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2RetypeFrame +import Fl4ProofsA64.P1.S1aR2RetypeHigh + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H H1 H' : Heap} {Cs OS OS1 Pt Kt U0 Ac : Set U64} {s s1 q : S} {ia ie lo hi : Nat} + {slot p sb fi aligned nt us dest off win : U64} {dev : Bool} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +/-- The inputs and the single creation end of one Retype decode. -/ +structure S1aRtIn (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Cs OS U0 Ac : Set U64) (s : S) + (ia ie : Nat) (slot p sb fi : U64) (dev : Bool) (extra : Aeneas.Std.Array obj.Slot 3#usize) + (H1 H' : Heap) (OS1 : Set U64) (s1 q : S) (lo hi : Nat) (aligned nt us dest off win : U64) : Prop where + pre : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U0 Ac s (.Untyped p sb fi dev) extra + place : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot + sys : SysL st H Cs OS ia ie s + source : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev) + creation : UtEnd st H Cs OS s slot p sb dev H1 H' OS1 s1 q lo hi aligned nt us dest off win + kept : UtX H H1 lo hi us + window : win.val = 0 ∨ ∃ reset, UtArgs st s extra slot p sb fi dev reset aligned nt us dest off win + reset : H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s slot = ok (.Ok v)) ∧ lo = p.val ∧ + hi = p.val + 2 ^ sb.val) + +/-- The slots at the creation end. -/ +abbrev s1aRtSlots (OS1 : Set U64) (dev : Bool) (nt us aligned win : U64) : Set U64 := + OS1 ∪ NewSl dev nt us aligned win + +namespace S1aRtIn + +variable (E : S1aRtIn st H Cs OS U0 Ac s ia ie slot p sb fi dev extra H1 H' OS1 s1 q lo hi aligned nt us dest off win) +include E + +theorem sourceCap : capA st s slot = .Untyped p sb fi dev := + okinj ((capA_eq s slot).symm.trans E.source) + +theorem ksb : L.ksb q = L.ksb s := E.creation.E.fr.1.trans E.creation.w1.1 + +/-- An object holding the target of a live range-keyed cap survives the reset and the creation. -/ +theorem old {t : U64} {k : HKind} (obj : H t = some k) + (held : ∃ y ∈ OS, RngKeyA (capA st s y) ∧ InObj t k (ptrA (capA st s y))) : + H' t = some k ∧ (t.val + 2 ^ k.bits ≤ lo ∨ hi ≤ t.val) := by + have survive : H1 t = some k := by + rcases E.reset with same | ⟨ram, ⟨v, childless⟩, low, high⟩ + · exact same.symm ▸ obj + rcases E.kept.kept t k obj with kept | ⟨above, below⟩ + · exact kept + obtain ⟨y, hy, key, inside⟩ := held + obtain ⟨_, _, tree, _, _⟩ := E.sys.sys.stz.1.1.tree + have source := E.sourceCap + rw [ram] at source + cases v + have outside := cdt.ensure_no_children.noKey E.place.os tree.utRangeOrd E.sys.sys.stz.1.2.1 + E.place.src source childless y hy key + unfold InObj at inside + exact (outside (by omega)).elim + exact ⟨E.creation.grow t k survive, E.creation.hole t k survive⟩ + +/-- A kernel table survives the creation. -/ +theorem kernel (sep : S1aKtUt st OS Kt s) {t : U64} (member : t ∈ Kt) (obj : H t = some (.other 12)) : + H' t = some (.other 12) ∧ (t.val + 4096 ≤ lo ∨ hi ≤ t.val) := + E.creation.kernelTables E.kept E.reset E.sourceCap sep member obj + +/-- The object of every owned VSpace word survives, off the hole. -/ +theorem owner (sep : S1aKtUt st OS Kt s) {b : U64} (own : S1aRetypeWordOwner st H OS Kt s b) : + ∃ t k, H t = some k ∧ InObj t k b ∧ H' t = some k ∧ (t.val + 2 ^ k.bits ≤ lo ∨ hi ≤ t.val) := by + obtain ⟨t, k, obj, inside, kernel | ⟨y, hy, key, ptr⟩⟩ := own + · obtain ⟨member, rfl⟩ := kernel + exact ⟨t, _, obj, inside, E.kernel sep member obj⟩ + · refine ⟨t, k, obj, inside, E.old obj ⟨y, hy, key, ?_⟩⟩ + rw [ptr] + exact ⟨le_rfl, Nat.lt_add_of_pos_right (Nat.two_pow_pos _)⟩ + +/-- A placed table whose base word is owned stays outside the hole. -/ +theorem tableOff (sep : S1aKtUt st OS Kt s) (footprint : PtHG H Pt) {t : U64} (member : t ∈ Pt) + (own : S1aRetypeWordOwner st H OS Kt s t) : t ∈ PtOffR Pt lo hi := by + obtain ⟨_, base, z, object, low, high⟩ := footprint t member + obtain ⟨r, k, obj, inside, _, outside⟩ := E.owner sep own + have same : r = base := by + by_contra different + have disjoint := E.place.heap.disj r k base (.other z) obj object different + unfold InObj at inside + rw [show HKind.bits (.other z) = z from rfl] at disjoint + generalize k.bits = width at disjoint inside + generalize (2 : Nat) ^ z = Z at disjoint high + generalize (2 : Nat) ^ width = K at disjoint inside + omega + subst base + rw [obj] at object + obtain rfl := Option.some.inj object + refine ⟨member, ?_⟩ + simp only [HKind.bits] at outside + generalize (2 : Nat) ^ z = Z at outside high + omega + +/-- Every non-null capability other than an Untyped at the end is a kept one or a fresh one. -/ +theorem capAt {x : U64} (member : x ∈ s1aRtSlots OS1 dev nt us aligned win) {c : capability.Cap} + (cap : capA st q x = c) (nonnull : c ≠ .Null) (other : ∀ a b d e, c ≠ .Untyped a b d e) : + (x ∈ OS ∧ x ≠ slot ∧ capA st s x = c) ∨ + (∃ j, j < win.val ∧ x = djA dest off j ∧ c = newCapA nt.val (bjA aligned (zA nt.val us) j) us dev) := by + have fit : (L.ksb q).val + 788736 ≤ 2 ^ 64 := by + rw [E.ksb] + exact E.sys.ly.ksw + rcases member with member | member + · have source : x ≠ slot := by + rintro rfl + obtain ⟨index, write⟩ := E.creation.E.src + exact other _ _ _ _ (cap.symm.trans write) + by_cases new : ∃ j, j < win.val ∧ x = djA dest off j + · obtain ⟨j, hj, rfl⟩ := new + exact Or.inr ⟨j, hj, rfl, cap.symm.trans (E.creation.E.new j hj)⟩ + · refine Or.inl ⟨E.creation.os x member, source, ?_⟩ + rw [← cap, E.creation.E.keep x member source (fun j hj eq => new ⟨j, hj, eq⟩), + E.creation.k1 x member source] + · exact (nonnull (cap.symm.trans ((E.creation.freshN E.kept fit).null x member))).elim + +/-- Every non-null capability apart from the source is kept. -/ +theorem capKeep {y : U64} (member : y ∈ OS) (nonnull : capA st s y ≠ .Null) (other : y ≠ slot) : + y ∈ s1aRtSlots OS1 dev nt us aligned win ∧ capA st q y = capA st s y := + let ⟨kept, cap⟩ := E.creation.capFwd member nonnull other + ⟨Or.inl kept, cap⟩ + +/-- A destination slot of the batch holds the fresh capability. -/ +theorem newSlot {j : Nat} (hj : j < win.val) : + djA dest off j ∈ s1aRtSlots OS1 dev nt us aligned win ∧ + capA st q (djA dest off j) = newCapA nt.val (bjA aligned (zA nt.val us) j) us dev := + ⟨Or.inl (E.creation.dO j hj), E.creation.E.new j hj⟩ + +/-- A new table or root has an exact aligned object inside the hole. -/ +theorem newObj {j : Nat} (hj : j < win.val) (kind : nt.val = 8 ∨ nt.val = 11 ∨ nt.val = 13 ∨ nt.val = 14) : + let t := bjA aligned (zA nt.val us) j + let z := (zA nt.val us).val + dev = false ∧ (z = 12 ∨ z = 13) ∧ H' t = some (.other z) ∧ t.val % 2 ^ z = 0 ∧ + t.val + 2 ^ z ≤ 2 ^ 64 ∧ lo ≤ t.val ∧ t.val + 2 ^ z ≤ hi := by + intro t z + rcases E.window with none | ⟨reset, args⟩ + · omega + have ram : dev = false := by + cases h : dev + · rfl + · rw [h] at args + rcases UtArgs.devK args with e | e | e | e <;> omega + have size : z = 12 ∨ z = 13 := by + rcases kind with e | e | e | e <;> simp [z, e, zA] + have typed : H' t = some (.other z) := + E.creation.hn ram j hj (.other z) (by rcases kind with e | e | e | e <;> simp [z, e, zA, newKind]) + have align := UtEnd.bjAligned E.pre E.place E.sys E.source E.creation args hj + have total := E.creation.A.aw.trans E.creation.A.pf + obtain ⟨value, inside⟩ := bj_facts hj total + obtain ⟨low, high⟩ := E.creation.whR ram + refine ⟨ram, size, typed, align, inside.trans total, ?_, inside.trans high⟩ + change lo ≤ (bjA aligned (zA nt.val us) j).val + omega + +/-- Fresh batch positions with equal bases are equal. -/ +theorem baseInj {i j : Nat} (hi' : i < win.val) (hj : j < win.val) + (same : bjA aligned (zA nt.val us) i = bjA aligned (zA nt.val us) j) : i = j := by + have total := E.creation.A.aw.trans E.creation.A.pf + have value := congrArg UScalar.val same + rw [(bj_facts hi' total).1, (bj_facts hj total).1] at value + exact Nat.eq_of_mul_eq_mul_right (Nat.two_pow_pos _) (Nat.add_left_cancel value) + +/-- A destination slot of a childless RAM source lies outside the source's region. -/ +theorem destOff {j : Nat} (hj : j < win.val) (ram : dev = false) + (childless : cdt.ensure_no_children st s slot = ok (.Ok ())) : + (djA dest off j).val + 32 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ (djA dest off j).val := by + obtain ⟨z, hz, base, radix, guard, bits, cap, i, index, address⟩ := E.creation.dcv j hj + have object := (E.sys.cn z hz).1 base radix guard bits cap + have fit := E.place.heap.fits base _ object + have small := E.place.heap.lt64 base _ object + simp only [HKind.bits] at fit small + have radix64 : radix.val % 64 = radix.val := Nat.mod_eq_of_lt (by omega) + rw [radix64] at index + have pow : 2 ^ (radix.val + 5) = 2 ^ radix.val * 32 := by rw [Nat.pow_add] + have value : (slotIdx base i).val = base.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 + have source := E.sourceCap + rw [ram] at source + have key : RngKeyA (capA st s z) := by + rw [cap] + exact ⟨physA_cnode _ _ _ _, rfl, rfl⟩ + have named : ptrA (capA st s z) = base := by + rw [cap, ptrA_cnode] + rw [address] + by_contra overlap + have off (b : U64) (low : (slotIdx base i).val ≤ b.val) (high : b.val < (slotIdx base i).val + 32) : + ¬ (p.val ≤ b.val ∧ b.val < p.val + 2 ^ sb.val) := + untypedWordOffNamed E.place E.sys source childless object + (by unfold InObj; simp only [HKind.bits]; omega) ⟨z, hz, key, named⟩ + have positive := Nat.two_pow_pos sb.val + by_cases first : p.val ≤ (slotIdx base i).val + · exact off _ le_rfl (by omega) ⟨first, by omega⟩ + · exact off p (by omega) (by omega) ⟨le_rfl, by omega⟩ + +/-- Every new HighVSpace root of the batch is initialized. -/ +theorem highInit (init : ∀ x ∈ OS, capA st s x = .Null → + (cdt.ensure_no_children st s slot = ok (.Ok ()) → x.val + 32 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ x.val) → + ∀ t m asid, capA st q x = .HighVSpace t m asid → S1aHighInit st Kt q t) + {j : Nat} (hj : j < win.val) (high : nt.val = 14) : + S1aHighInit st Kt q (bjA aligned (zA nt.val us) j) := by + have ram := (E.newObj hj (Or.inr (Or.inr (Or.inr high)))).1 + refine init (djA dest off j) (E.creation.os _ (E.creation.dO j hj)) (E.creation.A.dn0 j hj) + (E.destOff hj ram) _ false 0#u64 ?_ + rw [(E.newSlot hj).2, high] + simp [newCapA] + +end S1aRtIn + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2RetypeFrame.lean b/proofs/Fl4ProofsA64/P1/S1aR2RetypeFrame.lean new file mode 100644 index 000000000..2e490a7f4 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2RetypeFrame.lean @@ -0,0 +1,346 @@ +/- +P1 (aarch64): Retype preserves the words of live VSpace objects and static kernel tables. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aHiRetype +import Fl4ProofsA64.P1.S1aKtUt +import Fl4ProofsA64.P1.S1aR2Transport +import Fl4ProofsA64.P1.S1aR2Domains + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {A : Type _} {ar : machine.Arch A} {H : Heap} {Cs OS Pp Pt Tb Hr Te Kt : Set U64} + {Lv Re bits : U64 → Nat} {n : U64} {s : S} {ia ie : Nat} + {slot p sb fi : U64} {dev : Bool} {extra : Aeneas.Std.Array obj.Slot 3#usize} + {U Ac Sg Scs Vc Ub : Set U64} {Z : U64 → Nat} + +/-- A RAM reset cannot write a word in any object still named by a range-keyed cap. -/ +theorem untypedWordOffNamed + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) + (B : SysL st H Cs OS ia ie s) (source : capA st s slot = .Untyped p sb fi false) + (childless : cdt.ensure_no_children st s slot = ok (.Ok ())) + {t b : U64} {k : HKind} (obj : H t = some k) (inside : InObj t k b) + (held : ∃ y ∈ OS, RngKeyA (capA st s y) ∧ ptrA (capA st s y) = t) : + ¬ (p.val ≤ b.val ∧ b.val < p.val + 2 ^ sb.val) := by + obtain ⟨y, hy, key, ptr⟩ := held + obtain ⟨_, _, tree, _, _⟩ := B.sys.stz.1.1.tree + have outside := cdt.ensure_no_children.noKey P.os tree.utRangeOrd B.sys.stz.1.2.1 + P.src source childless y hy key + rw [ptr] at outside + intro touch + have meets : RegionD H p.val (p.val + 2 ^ sb.val) t := by + unfold RegionD MeetsR + rw [obj] + change ¬ (t.val + 2 ^ k.bits ≤ p.val ∨ p.val + 2 ^ sb.val ≤ t.val) + obtain ⟨left, right⟩ := inside + omega + obtain ⟨lo, hi⟩ := RegionD.inside (B.sys.ur.rin P.src source) obj meets + exact outside ⟨lo, by have := Nat.two_pow_pos k.bits; omega⟩ + +/-- The heap object containing a VSpace word, with a live cap or a static kernel allocation. -/ +def S1aRetypeWordOwner (st : machine.Store S) [LawfulStore st] (H : Heap) + (OS Kt : Set U64) (s : S) (b : U64) : Prop := + ∃ t k, H t = some k ∧ InObj t k b ∧ + ((t ∈ Kt ∧ k = .other 12) ∨ ∃ y ∈ OS, RngKeyA (capA st s y) ∧ ptrA (capA st s y) = t) + +theorem inObjWord (heap : HeapOK H) {t o : U64} {k : HKind} + (obj : H t = some k) (off : o.val < 2 ^ k.bits) : InObj t k (wa t o) := by + have fit := heap.fits t k obj + have address : (wa t o).val = t.val + o.val := wadd_val (by omega) + exact ⟨by omega, by omega⟩ + +/-- Any placed word owned by an old live cap or a static kernel page survives Retype. -/ +theorem untyped.decode.keepOwnedVsWords (total : P0.ArchTotal ar) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Untyped p sb fi dev) 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) + (cap : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (masks : A64FrameMasks st s) + (vr : VrOK H.omega Sg Scs Z OS Vc Ub (L.ksb s) Pt) (sep : S1aKtUt st OS Kt s) + (a : A) (lbl len buf : U64) : + untyped.decode st ar s a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + ∀ b, VsR (L.ksb s) Pt b → S1aRetypeWordOwner st H OS Kt s b → L.mem s' b = L.mem s b ⦄ := by + have source : capA st s slot = .Untyped p sb fi dev := okinj ((capA_eq s slot).symm.trans cap) + let X : Set U64 := {b | VsR (L.ksb s) Pt b ∧ S1aRetypeWordOwner st H OS Kt s b} + refine WP.spec_mono (untyped.decode.keepVsWords total D P B cap masks vr + (X := X) (fun _ h => h.1) ?_ ?_ a lbl len buf) + (fun _ keep b placed owner => keep b ⟨placed, owner⟩) + · intro ram b hb touch + obtain ⟨t, k, obj, ⟨lo, hi⟩, _⟩ := hb.2 + have R := UtDecP.of_live D B.sys P cap B.ln B.vr B.ly + obtain ⟨⟨_, _, valid, _, _⟩, _, _⟩ := R.stz + have off := valid slot P.src p sb fi (ram ▸ source) t k obj + rcases off with left | right <;> omega + · intro ram childless b hb + obtain ⟨t, k, obj, inside, kernel | held⟩ := hb.2 + · obtain ⟨ht, rfl⟩ := kernel + have off := sep t ht slot P.src p sb fi dev source + obtain ⟨lo, hi⟩ := inside + change b.val < t.val + 4096 at hi + rcases off with left | right <;> omega + · exact untypedWordOffNamed P B (ram ▸ source) childless obj inside held + +/-- Retype preserves every descriptor word of the fixed kernel table set. -/ +theorem untyped.decode.keepKernelTables (total : P0.ArchTotal ar) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Untyped p sb fi dev) 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) + (cap : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (masks : A64FrameMasks st s) + (vr : VrOK H.omega Sg Scs Z OS Vc Ub (L.ksb s) Pt) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (a : A) (lbl len buf : U64) : + untyped.decode st ar s a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + ∀ b, PtW Kt b → L.mem s' b = L.mem s b ⦄ := by + refine WP.spec_mono (untyped.decode.keepOwnedVsWords total D P B cap masks vr sep a lbl len buf) ?_ + rintro _ keep _ ⟨t, ht, o, low, aligned, rfl⟩ + have obj := h.kernelTables.2 t ht + exact keep _ (Or.inl ⟨t, h.place.tables (h.kernelTables.1 ht), o, low, aligned, rfl⟩) + ⟨t, .other 12, obj, inObjWord P.heap obj low, Or.inl ⟨ht, rfl⟩⟩ + +section paths + +variable {q : S} + +/-- The live ASID table and active pool words determine the same entries. -/ +theorem TabKeep.activeRootIff (tab : TabKeep st s q) + (poolWords : ∀ t ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem q (wa t o) = L.mem s (wa t o)) {asid raw : U64} : + ActiveAsidRoot st Pp q asid raw ↔ ActiveAsidRoot st Pp s asid raw := by + refine ⟨fun h => h.back tab.toDel (fun t ht o ho al => Or.inl (poolWords t ht o ho al)), ?_⟩ + rintro ⟨i, o, hi, ho, al, asidVal, t, ht, entry, word, nz⟩ + exact ⟨i, o, hi, ho, al, asidVal, t, tab.poolSet_eq.symm ▸ ht, (tab.2 i).trans entry, + (poolWords t ht o ho al).trans word, nz⟩ + +/-- Exact memory agreement on the live walk gives path preservation in both directions. -/ +theorem S1aPath.iffOfWords + (roots : ∀ a raw, ActiveAsidRoot st Pp q a raw ↔ ActiveAsidRoot st Pp s a raw) + (header : ∀ a raw, ActiveAsidRoot st Pp s a raw → raw &&& 3#u64 = 2#u64 → + L.mem q (wa (raw &&& ~~~3#u64) 4088#u64) = L.mem s (wa (raw &&& ~~~3#u64) 4088#u64)) + (words : ∀ tag a sh base t, S1aPath st Pp n s tag a sh base t → + ∀ o : U64, o.val < s1aTableWidth tag n sh → o.val % 8 = 0 → + L.mem q (wa t o) = L.mem s (wa t o)) + {tag asid t : U64} {sh base : Nat} : + S1aPath st Pp n q tag asid sh base t ↔ S1aPath st Pp n s tag asid sh base t := by + refine ⟨S1aPath.backIf (fun a raw => (roots a raw).mp) header + (fun k a level va p path o bound al _ => words k a level va p path o bound al), ?_⟩ + intro path + induction path with + | native entry kind => exact .native ((roots _ _).mpr entry) kind + | high entry kind valid => + have keep := header _ _ entry kind + rw [← keep] at valid ⊢ + exact .high ((roots _ _).mpr entry) kind valid + | stage2 entry kind => exact .stage2 ((roots _ _).mpr entry) kind + | child old depth bound al range valid ih => + have keep := words _ _ _ _ _ old _ bound al + rw [← keep] at valid ⊢ + exact .child ih depth bound al range valid + +theorem S1aR2.poolWordOwner (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) {t o : U64} (active : t ∈ PoolSet st Pp s) (bound : o.val < 4096) + (al : o.val % 8 = 0) : + PtW Pt (wa t o) ∧ S1aRetypeWordOwner st H OS Kt s (wa t o) := by + obtain ⟨_, off, lo, hi, aligned, entry, nz⟩ := active + obtain ⟨j, eq⟩ := atOff_of_off lo hi aligned + let idx := j &&& 127#u64 + have idxBound : idx.val < 128 := by + change (j &&& 127#u64).val < 128 + rw [UScalar.val_and] + exact Nat.lt_of_le_of_lt Nat.and_le_right (by decide) + rw [← eq, ← AtOff.mask] at entry + obtain ⟨_, placed, obj, x, hx, base, cap, _⟩ := h.poolCaps.present idx idxBound t entry nz + refine ⟨⟨t, placed, o, bound, al, rfl⟩, t, .other 12, obj, inObjWord heap obj bound, Or.inr ⟨x, hx, ?_⟩⟩ + rw [cap] + exact ⟨RngKeyA.ap t base, ptrA_ap t base⟩ + +theorem S1aR2.highWordOwner (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) {asid raw : U64} (active : ActiveAsidRoot st Pp s asid raw) (tag : raw &&& 3#u64 = 2#u64) : + PtW Pt (wa (raw &&& ~~~3#u64) 4088#u64) ∧ + S1aRetypeWordOwner st H OS Kt s (wa (raw &&& ~~~3#u64) 4088#u64) := by + obtain ⟨x, hx, backed⟩ := h.core.root.backed asid raw active + rw [tag] at backed + rcases backed with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + let root := raw &&& ~~~3#u64 + have held : root ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, asid, cap⟩ + have obj := h.highObjects x hx root true asid cap + refine ⟨⟨root, h.highFootprint ⟨root, held, Or.inl rfl⟩, 4088#u64, by decide, by decide, rfl⟩, + root, .other 13, obj, inObjWord heap obj (by decide), Or.inr ⟨x, hx, ?_⟩⟩ + rw [cap] + exact ⟨RngKeyA.hv root true asid, ptrA_hv root true asid⟩ + +private theorem S1aR2.pathWordOwner (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) {tag asid t o : U64} {sh base : Nat} (path : S1aPath st Pp n s tag asid sh base t) + (width : o.val < s1aTableWidth tag n sh) : + S1aRetypeWordOwner st H OS Kt s (wa t o) := by + obtain ⟨x, hx, root, off, z, obj, _, bound, address, _, key, ptr, _⟩ := h.pathWordObject path width + rw [address] + exact ⟨root, .other z, obj, inObjWord heap obj bound, Or.inr ⟨x, hx, key, ptr⟩⟩ + +/-- Retype preserves the live ASID entries and every executable user path. -/ +theorem untyped.decode.keepActivePaths (total : P0.ArchTotal ar) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s + (.Untyped p sb fi dev) 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) + (cap : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (masks : A64FrameMasks st s) + (vr : VrOK H.omega Sg Scs Z OS Vc Ub (L.ksb s) Pt) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (a : A) (lbl len buf : U64) : + untyped.decode st ar s a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + (∀ asid raw, ActiveAsidRoot st Pp s' asid raw ↔ ActiveAsidRoot st Pp s asid raw) ∧ + (∀ tag asid sh base t, S1aPath st Pp n s' tag asid sh base t ↔ S1aPath st Pp n s tag asid sh base t) ⦄ := by + refine WP.spec_mono (WP.spec_and (untyped.decode.tabK total D P B cap masks vr a lbl len buf) + (untyped.decode.keepOwnedVsWords total D P B cap masks vr sep a lbl len buf)) ?_ + rintro ⟨_, s', _⟩ ⟨writes, keep⟩ + have tab : TabKeep st s s' := TabKeep.ofW vr writes fun _ h => h + have roots asid raw : ActiveAsidRoot st Pp s' asid raw ↔ ActiveAsidRoot st Pp s asid raw := + tab.activeRootIff fun t ht o width al => + let ⟨placed, owner⟩ := h.poolWordOwner P.heap ht width al + keep _ (Or.inl placed) owner + refine ⟨roots, fun tag asid sh base t => S1aPath.iffOfWords roots ?_ ?_⟩ + · intro asid raw entry tag + obtain ⟨placed, owner⟩ := h.highWordOwner P.heap entry tag + exact keep _ (Or.inl placed) owner + · intro tag asid sh base t path o width al + exact keep _ (Or.inl (h.pathWord path width al)) (h.pathWordOwner P.heap path width) + +/-- Every allocated descriptor word of a table on an exact user walk is owned and placed. -/ +theorem S1aR2.storageWord (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) {tag asid t o : U64} {sh base : Nat} (path : S1aPath st Pp n s tag asid sh base t) + (bound : o.val < s1aTableStorage tag n sh) (al : o.val % 8 = 0) : + PtW Pt (wa t o) ∧ S1aRetypeWordOwner st H OS Kt s (wa t o) := by + obtain ⟨x, hx, root, delta, z, obj, _, deltaBound, address, _, key, ptr, _, which, offset, _, _, _, _, upper⟩ := + h.pathStorageOwner path bound + refine ⟨?_, root, .other z, obj, address.symm ▸ inObjWord heap obj deltaBound, Or.inr ⟨x, hx, key, ptr⟩⟩ + have typed := h.paths.tables tag asid sh base t path + by_cases stage : tag = 1#u64 + · rw [ite_eq_left stage] at typed + have plain : kindA (capA st s x) ≠ 25 := fun eq => by + have bad := (upper eq).1 + rw [stage] at bad + exact (by decide : (1#u64 : U64) ≠ 2#u64) bad + rw [ite_eq_right plain] at which offset + have object : H t = some (.other z) := which ▸ obj + have same : z = bits t := by + have other := (h.core.heap t typed.1).1 + rw [object] at other + exact HKind.other.inj (Option.some.inj other) + have inside : o.val < 2 ^ bits t := by + rw [← same] + omega + exact ptw_mono h.place.granules (ptwb_gran h.place.stage2.sz ⟨t, typed.1, o, inside, al, rfl⟩) + · rw [ite_eq_right stage] at typed + have small : s1aTableStorage tag n sh = 4096 := by simp [s1aTableStorage, stage] + exact ⟨t, h.place.tables typed.1, o, small ▸ bound, al, rfl⟩ + +/-- Every word of a raw Stage-1 reachable table is owned and placed. -/ +theorem S1aR2.reachWord1 (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) {t o : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) (bound : o.val < 4096) + (al : o.val % 8 = 0) : PtW Pt (wa t o) ∧ S1aRetypeWordOwner st H OS Kt s (wa t o) := by + rcases h.classifyStage1 reach with kernel | ⟨raw, asid, active, tag, rfl⟩ | ⟨tag, asid, sh, va, stage, path⟩ + · have obj := h.kernelTables.2 t kernel + exact ⟨⟨t, h.place.tables (h.kernelTables.1 kernel), o, bound, al, rfl⟩, + t, .other 12, obj, inObjWord heap obj bound, Or.inl ⟨kernel, rfl⟩⟩ + · obtain ⟨x, hx, backed⟩ := h.core.root.backed asid raw active + rw [tag] at backed + rcases backed with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + have held : (raw &&& ~~~3#u64) ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, asid, cap⟩ + have obj := h.highObjects x hx _ true asid cap + refine ⟨⟨_, h.highFootprint ⟨_, held, Or.inl rfl⟩, o, bound, al, rfl⟩, _, .other 13, obj, + inObjWord heap obj (lt_trans bound (by decide)), Or.inr ⟨x, hx, ?_⟩⟩ + rw [cap] + exact ⟨RngKeyA.hv _ true asid, ptrA_hv _ true asid⟩ + · have plain : tag ≠ 1#u64 := by rcases stage with rfl | rfl <;> decide + have small : s1aTableStorage tag n sh = 4096 := by simp [s1aTableStorage, plain] + exact h.storageWord heap path (small.symm ▸ bound) al + +/-- Every word a raw Stage-2 walk can read is owned and placed. -/ +theorem S1aR2.reachWord2 (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) {t o : U64} (reach : S2Reach st (PoolSet st Pp s) Re bits s t) (bound : o.val < 2 ^ bits t) + (al : o.val % 8 = 0) : PtW Pt (wa t o) ∧ S1aRetypeWordOwner st H OS Kt s (wa t o) := by + obtain ⟨asid, sh, va, path⟩ := h.classifyStage2 reach + have typed := h.paths.tables _ asid sh va t path + rw [ite_eq_left rfl] at typed + have size : 2 ^ bits t ≤ s1aTableStorage 1#u64 n sh := by + rcases path.geometry.2 with ⟨top, _⟩ | ⟨below, _⟩ + · rw [s1aTableStorage, ite_eq_left ⟨rfl, top⟩] + rcases h.place.stage2.sz t typed.1 with e | e <;> rw [e] <;> decide + · obtain ⟨x, hx, address, cap, _⟩ := h.paths.children _ asid sh va t path below + have table := h.pageObjects x hx t true asid address cap + have other := (h.core.heap t typed.1).1 + change H t = some (.other 12) at table + rw [table] at other + rw [← HKind.other.inj (Option.some.inj other), s1aTableStorage, + ite_eq_right (fun e => (Nat.ne_of_lt below) e.2)] + decide + exact h.storageWord heap path (lt_of_lt_of_le bound size) al + +/-- Raw Stage-1 reachability depends only on the live pool words and the reached tables. -/ +theorem VsReach.congrWords {q : S} {P : Set U64} {Lv Lv' : U64 → Nat} {t : U64} + (pools : ∀ p ∈ P, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa p o) = L.mem s (wa p o)) + (keep : ∀ p, VsReach st P ∅ Lv s p → Lv' p = Lv p ∧ + ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa p o) = L.mem s (wa p o)) : + VsReach st P ∅ Lv' q t ↔ VsReach st P ∅ Lv s t := by + constructor + · intro reach + induction reach with + | hr bad => exact (Set.notMem_empty _ bad).elim + | root0 hp bound al nz tag => + rw [pools _ hp _ bound al] at nz tag ⊢ + exact .root0 hp bound al nz tag + | root2 hp bound al tag => + rw [pools _ hp _ bound al] at tag ⊢ + exact .root2 hp bound al tag + | step _ level bound al tag ih => + obtain ⟨lv, words⟩ := keep _ ih + rw [words _ bound al] at tag ⊢ + exact .step ih (lv ▸ level) bound al tag + · intro reach + induction reach with + | hr bad => exact (Set.notMem_empty _ bad).elim + | root0 hp bound al nz tag => + rw [← pools _ hp _ bound al] at nz tag ⊢ + exact .root0 hp bound al nz tag + | root2 hp bound al tag => + rw [← pools _ hp _ bound al] at tag ⊢ + exact .root2 hp bound al tag + | step old level bound al tag ih => + obtain ⟨lv, words⟩ := keep _ old + rw [← words _ bound al] at tag ⊢ + exact .step ih (lv.symm ▸ level) bound al tag + +/-- Raw Stage-2 reachability depends only on the live pool words and the reached tables. -/ +theorem S2Reach.congrWords {q : S} {P : Set U64} {Re bits : U64 → Nat} {t : U64} + (pools : ∀ p ∈ P, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa p o) = L.mem s (wa p o)) + (keep : ∀ p, S2Reach st P Re bits s p → + ∀ o : U64, o.val < 2 ^ bits p → o.val % 8 = 0 → L.mem q (wa p o) = L.mem s (wa p o)) : + S2Reach st P Re bits q t ↔ S2Reach st P Re bits s t := by + constructor + · intro reach + induction reach with + | root hp bound al tag => + rw [pools _ hp _ bound al] at tag ⊢ + exact .root hp bound al tag + | step _ level bound al tag ih => + rw [keep _ ih _ bound al] at tag ⊢ + exact .step ih level bound al tag + · intro reach + induction reach with + | root hp bound al tag => + rw [← pools _ hp _ bound al] at tag ⊢ + exact .root hp bound al tag + | step old level bound al tag ih => + rw [← keep _ old _ bound al] at tag ⊢ + exact .step ih level bound al tag + +end paths + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2RetypeHigh.lean b/proofs/Fl4ProofsA64/P1/S1aR2RetypeHigh.lean new file mode 100644 index 000000000..777485c6e --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2RetypeHigh.lean @@ -0,0 +1,131 @@ +/- +P1 (aarch64): every HighVSpace root that Retype creates is initialized at the decode's end. +Named premises: none. KTab is the existing architecture premise. +-/ +import Fl4ProofsA64.P1.S1aR2RootInit +import Fl4ProofsA64.P1.S1aHiRetype + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {A : Type _} {ar : machine.Arch A} {Kt : Set U64} {KLv : U64 → Nat} + {OS Cs Rp Nt Sg : Set U64} {ia ie : Nat} + +/-- A slot of `O` that was null and now holds a HighVSpace cap names an initialized root. -/ +def S1aNewHigh (st : machine.Store S) [L : LawfulStore st] (Kt O : Set U64) (s s' : S) : Prop := + ∀ x ∈ O, capA st s x = .Null → ∀ q m asid, capA st s' x = .HighVSpace q m asid → S1aHighInit st Kt s' q + +/-- A RAM creation initializes every HighVSpace root it names. -/ +theorem untyped.retype.newHighInit (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) + {H1 : Heap} {OS1 : Set U64} {s : S} {slot p sb fi base nt us dest off win : U64} + (C : CrtP st H1 Cs Sg OS1 s slot p sb fi false base nt us dest off win) (positive : 0 < base.val) + (full : base.val % 2 ^ (zA nt.val us).val = 0) (a : A) : + untyped.retype st ar s a slot false base nt us dest off win false ⦃ r => + S1aNewHigh st Kt OS1 s r.2.1 ⦄ := by + have finish {q : S} (E : CrtE st H1 Sg OS1 s q slot p sb false base nt us dest off win) + (batch : nt.val = 14 → S1aHighBatch st Kt q base (zA nt.val us) win.val) : + S1aNewHigh st Kt OS1 s q := by + intro x hx empty t m asid cap + have other : x ≠ slot := by + rintro rfl + rw [C.cap] at empty + cases empty + by_cases new : ∃ j, j < win.val ∧ x = djA dest off j + · obtain ⟨j, hj, rfl⟩ := new + rw [E.new j hj] at cap + obtain ⟨high, rfl⟩ := newCapA_hv C.hn cap + exact batch high j hj + · rw [E.keep x hx other (fun j hj eq => new ⟨j, hj, eq⟩), empty] at cap + cases cap + by_cases high : nt.val = 14 + · exact WP.spec_mono (WP.spec_and (untyped.retype.liveR hA C positive a) + (untyped.retype.highRootSlots hA K C high full a)) fun _ ⟨⟨E, _⟩, batch⟩ => finish E fun _ => batch + · exact WP.spec_mono (untyped.retype.liveR hA C positive a) fun _ ⟨E, _⟩ => finish E fun h => (high h).elim + +set_option maxHeartbeats 4000000 in +/-- At the decode's end each newly named HighVSpace root is initialized. A RAM reset drops the +slots of its region, so the claim is about slots outside it. -/ +theorem untyped.decode.newHighInit (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) {U Ac : Set U64} + {s : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (cap : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (mask : A64FrameMasks st s) + (a : A) (lbl len buf : U64) : + untyped.decode st ar s a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + ∀ x ∈ OS, capA st s x = .Null → + (cdt.ensure_no_children st s slot = ok (.Ok ()) → x.val + 32 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ x.val) → + ∀ q m asid, capA st s' x = .HighVSpace q m asid → S1aHighInit st Kt s' q ⦄ := by + have R := UtDecP.of_live D B.sys P cap B.ln B.vr B.ly + obtain ⟨_, hb⟩ := R.blk + obtain ⟨_, _, q⟩ := hb.1 + let Goal : S → Prop := fun s' => ∀ x ∈ OS, capA st s x = .Null → + (cdt.ensure_no_children st s slot = ok (.Ok ()) → x.val + 32 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ x.val) → + ∀ t m asid, capA st s' x = .HighVSpace t m asid → S1aHighInit st Kt s' t + have decoded : untyped.decode st ar s a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => Goal s' ⦄ := by + refine untyped.decode.decG (P := fun _ s' => Goal s') hA a lbl len slot buf p sb fi dev ?_ + (fun h => (mask.noShare h).elim) ?_ + · intro _ x _ empty _ t m asid held + rw [empty] at held + cases held + intro s2 reset aligned nt us dest off win e args + have keep := (restart_frame (OS := OS) R.os q e).1 + have arith := UtArgs.arithA R.ty R.ext R.cap R.utv args + have full := (UtArgs.zalA R.ty R.ext R.cap R.utv args).1 + have positive (hd : dev = false) : 0 < aligned.val := + lt_of_lt_of_le (B.ly.ut0 slot R.src p sb fi (hd ▸ R.cap)) (CrtA.of_args R args).pa + have device (hd : dev = true) {s1 s' : S} {OS1 : Set U64} {H1 : Heap} + (E : CrtE st H1 H.frame OS1 s1 s' slot p sb true aligned nt us dest off win) + {x : U64} (hx : x ∈ OS1) (other : x ≠ slot) (empty : capA st s1 x = .Null) + {t asid : U64} {m : Bool} (held : capA st s' x = .HighVSpace t m asid) : False := by + by_cases new : ∃ j, j < win.val ∧ x = djA dest off j + · obtain ⟨j, hj, rfl⟩ := new + rw [E.new j hj] at held + exact (arith.1 hd).2.2 (newCapA_hv (CrtA.of_args R args).hn held).1 + · rw [E.keep x hx other (fun j hj eq => new ⟨j, hj, eq⟩), empty] at held + cases held + have source {x : U64} (empty : capA st s x = .Null) : x ≠ slot := by + rintro rfl + rw [R.cap] at empty + cases empty + cases reset + · have C := CrtP.of0 R e args + cases dev + · refine WP.spec_mono (untyped.retype.newHighInit hA K C (positive rfl) full a) ?_ + intro _ new x hx empty _ + exact new x hx ((keep.capA hx).trans empty) + · refine WP.spec_mono (untyped.retype.liveD C a) fun _ ⟨E, _⟩ x hx empty _ t m asid held => ?_ + exact (device rfl E hx (source empty) ((keep.capA hx).trans empty) held).elim + have childless : cdt.ensure_no_children st s slot = ok (.Ok ()) := by + have resetArgs := args + obtain ⟨_, _, _, _, _, _, _, _, _, _, resetEq, _⟩ := resetArgs + obtain ⟨v, nc⟩ := resetEq.1 rfl + cases v + exact nc + cases dev + · refine WP.spec_mono (untyped.retype.stZFCRUG hA R e a args + (fun _ O s' => O = OffR p.val (p.val + 2 ^ sb.val) OS ∧ S1aNewHigh st Kt O s s') ?_ ?_) ?_ + · intro s1 _ _ _ same + refine ⟨rfl, fun x hx empty t m asid held => ?_⟩ + rw [same x hx (source empty), empty] at held + cases held + · intro s1 a1 _ same C H' _ _ _ _ + refine WP.spec_mono (untyped.retype.newHighInit hA K C (positive rfl) full a1) ?_ + intro _ new + exact ⟨rfl, fun x hx empty => new x hx ((same x hx (source empty)).trans empty)⟩ + · rintro _ ⟨_, _, _, _, _, _, rfl, new⟩ x hx empty off + exact new x ⟨hx, off childless⟩ empty + · refine WP.spec_mono (untyped.retype.stZFCRdUG hA R e a args + (fun _ O s' => O = OS ∧ S1aNewHigh st Kt O s s') ?_) ?_ + · intro s1 a1 _ same C H' _ _ _ _ + refine WP.spec_mono (untyped.retype.liveD C a1) fun _ ⟨E, _⟩ => ⟨rfl, fun x hx empty t m asid held => ?_⟩ + exact (device rfl E hx (source empty) ((same x hx (source empty)).trans empty) held).elim + · rintro _ ⟨_, _, _, _, _, _, rfl, new⟩ x hx empty _ + exact new x hx empty + exact WP.spec_mono decoded fun _ h => h + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2RetypeNew.lean b/proofs/Fl4ProofsA64/P1/S1aR2RetypeNew.lean new file mode 100644 index 000000000..cb08afdee --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2RetypeNew.lean @@ -0,0 +1,152 @@ +/- +P1 (aarch64): the VSpace shape of fresh capabilities and the grown heap at a Retype creation end. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2RetypeEnd + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H H1 H' : Heap} {Cs OS OS1 Pt Kt U0 Ac : Set U64} {s s1 q : S} {ia ie lo hi : Nat} + {slot p sb fi aligned nt us dest off win : U64} {dev : Bool} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +section shape +variable {n : Nat} {base size : U64} {device : Bool} + +/-- A fresh capability maps no table. -/ +theorem newCapA_notMapV (bound : n < 15) (t : U64) : ¬ MapV (newCapA n base size device) t := by + interval_cases n <;> simp [newCapA, MapV] + +/-- A fresh capability is no mapped ASID root. -/ +theorem newCapA_notMappedRoot (bound : n < 15) (root asid tag : U64) : + ¬ MappedAsidRoot (newCapA n base size device) root asid tag := by + interval_cases n <;> simp [newCapA, MappedAsidRoot] + +/-- A fresh table capability is unmapped and keyed by its base. -/ +theorem newCapA_tableKey (bound : n < 15) {k : Nat × U64} (h : s1aTableKey (newCapA n base size device) = some k) : + (n = 8 ∨ n = 11 ∨ n = 13 ∨ n = 14) ∧ k.2 = base ∧ s1aTableRef (newCapA n base size device) = none := by + interval_cases n <;> simp [newCapA, s1aTableKey, s1aTableRef] at h ⊢ <;> subst h <;> rfl + +theorem newCapA_pml4 (bound : n < 15) {t asid : U64} {mapped : Bool} + (h : newCapA n base size device = .Pml4 t mapped asid) : n = 8 ∧ t = base ∧ mapped = false := by + interval_cases n <;> simp [newCapA] at h ⊢ + exact ⟨h.1.symm, h.2.1⟩ + +theorem newCapA_eptShape (bound : n < 15) {t level asid va : U64} {mapped : Bool} + (h : newCapA n base size device = .Ept t level mapped asid va) : + n = 13 ∧ t = base ∧ level = 0#u64 ∧ mapped = false := by + interval_cases n <;> simp [newCapA] at h ⊢ + exact ⟨h.1.symm, h.2.1.symm, h.2.2.1⟩ + +/-- A fresh capability names only its own table granules. -/ +theorem newCapA_namesV (bound : n < 15) {t : U64} (h : NamesV (newCapA n base size device) t) : + (n = 8 ∨ n = 11 ∨ n = 13 ∨ n = 14) ∧ (t = base ∨ (n = 14 ∧ t = wa base 4096#u64)) := by + rcases h with ⟨m, a, v, e⟩ | ⟨m, a, e⟩ | ⟨m, a, e⟩ | ⟨R, m, a, e, granule⟩ | ⟨l, m, a, v, e⟩ + · obtain ⟨kind, same⟩ := newCapA_pt bound e + exact ⟨by omega, Or.inl same⟩ + · obtain ⟨kind, same, _⟩ := newCapA_pml4 bound e + exact ⟨by omega, Or.inl same⟩ + · obtain ⟨kind, same⟩ := newCapA_hv bound e + exact ⟨by omega, Or.inl same⟩ + · obtain ⟨kind, same⟩ := newCapA_hv bound e + exact ⟨by omega, Or.inr ⟨kind, same ▸ granule⟩⟩ + · obtain ⟨kind, same, _⟩ := newCapA_eptShape bound e + exact ⟨by omega, Or.inl same⟩ + +theorem newCapA_unm (bound : n < 15) {t : U64} {width : Nat} (h : UnmCap (newCapA n base size device) t width) : + t = base ∧ ((n = 11 ∧ width = 4096) ∨ (n = 13 ∧ width = 8192)) := by + rcases h with ⟨wide, a, v, e⟩ | ⟨wide, a, v, e⟩ + · obtain ⟨kind, same⟩ := newCapA_pt bound e + exact ⟨same, Or.inl ⟨kind, wide⟩⟩ + · obtain ⟨kind, same, _⟩ := newCapA_eptShape bound e + exact ⟨same, Or.inr ⟨kind, wide⟩⟩ + +end shape + +theorem RngKeyA.pml4 (t : U64) (mapped : Bool) (asid : U64) : RngKeyA (.Pml4 t mapped asid) := by + have h := physA_eq (.Pml4 t mapped asid) + simp only [objects.cap_is_physical] at h + exact ⟨(okinj h).symm, rfl, rfl⟩ + +theorem ptrA_pml4 (t : U64) (mapped : Bool) (asid : U64) : ptrA (.Pml4 t mapped asid) = t := by + have h := ptrA_eq (.Pml4 t mapped asid) + simp only [capability.Cap.ptr] at h + exact (okinj h).symm + +namespace S1aRtIn + +variable (E : S1aRtIn st H Cs OS U0 Ac s ia ie slot p sb fi dev extra H1 H' OS1 s1 q lo hi aligned nt us dest off win) +include E + +/-- The heap at the creation end is well formed. -/ +theorem heapOK : HeapOK H' := by + have old := E.creation.hp1 + have total := E.creation.A.aw.trans E.creation.A.pf + have fresh : ∀ t k, H' t = some k → H1 t = some k ∨ + (dev = false ∧ ∃ j, j < win.val ∧ t = bjA aligned (zA nt.val us) j ∧ k.bits = (zA nt.val us).val ∧ + newKind nt.val us.val = some k) := by + intro t k obj + rcases E.creation.ex t k obj with kept | ⟨ram, j, hj, base, kind⟩ + · exact Or.inl kept + · exact Or.inr ⟨ram, j, hj, base, newKind_bitsA kind E.creation.A.hn E.kept.us64, kind⟩ + have args {j : Nat} (hj : j < win.val) : ∃ reset, UtArgs st s extra slot p sb fi dev reset aligned nt us dest off win := + E.window.resolve_left (by omega) + have align {j : Nat} (hj : j < win.val) : + (bjA aligned (zA nt.val us) j).val % 2 ^ (zA nt.val us).val = 0 := + let ⟨_, h⟩ := args hj + UtEnd.bjAligned E.pre E.place E.sys E.source E.creation h hj + have small {j : Nat} (hj : j < win.val) : (zA nt.val us).val ≤ 47 := by + obtain ⟨_, h⟩ := args hj + have R := UtDecP.of_live E.pre E.sys.sys E.place E.source E.sys.ln E.sys.vr E.sys.ly + exact (UtArgs.zalA R.ty R.ext R.cap R.utv h).2 + have fits {j : Nat} (hj : j < win.val) : + (bjA aligned (zA nt.val us) j).val + 2 ^ (zA nt.val us).val ≤ 2 ^ 64 := + (bj_facts hj total).2.trans total + have apart {t j : U64} {k : HKind} {i : Nat} (kept : H1 t = some k) (hi' : i < win.val) (ram : dev = false) + (size : j = bjA aligned (zA nt.val us) i) : + t.val + 2 ^ k.bits ≤ j.val ∨ j.val + 2 ^ (zA nt.val us).val ≤ t.val := by + have outside := E.creation.hole t k kept + obtain ⟨low, high⟩ := E.creation.whR ram + obtain ⟨value, inside⟩ := bj_facts hi' total + rw [size] + omega + refine ⟨fun t k obj => ?_, fun t k obj => ?_, fun t k obj => ?_, fun t z obj => ?_, + fun t k u k' obj obj' different => ?_⟩ + · rcases fresh t k obj with kept | ⟨_, j, hj, rfl, bits, _⟩ + · exact old.align t k kept + · rw [bits]; exact align hj + · rcases fresh t k obj with kept | ⟨_, j, hj, rfl, bits, _⟩ + · exact old.fits t k kept + · rw [bits]; exact fits hj + · rcases fresh t k obj with kept | ⟨_, j, hj, rfl, bits, _⟩ + · exact old.lt64 t k kept + · rw [bits]; exact lt_of_le_of_lt (small hj) (by decide) + · rcases fresh t _ obj with kept | ⟨_, j, hj, _, _, kind⟩ + · exact old.scmin t z kept + · obtain ⟨five, rfl⟩ := newKind_sc kind + exact E.creation.A.sc five + · rcases fresh t k obj with kept | ⟨ram, i, hi', base, bits, _⟩ + · rcases fresh u k' obj' with kept' | ⟨ram, j, hj, base, bits, _⟩ + · exact old.disj t k u k' kept kept' different + · rw [bits]; exact apart kept hj ram base + · rcases fresh u k' obj' with kept' | ⟨_, j, hj, base', bits', _⟩ + · rw [bits]; exact (apart kept' hi' ram base).symm + · have ne : i ≠ j := fun eq => different (by rw [base, base', eq]) + rw [bits, bits', base, base', (bj_facts hi' total).1, (bj_facts hj total).1] + rcases Nat.lt_or_gt_of_ne ne with lt | lt + · have step := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt lt) + rw [Nat.succ_mul] at step + omega + · have step := Nat.mul_le_mul_right (2 ^ (zA nt.val us).val) (Nat.succ_le_of_lt lt) + rw [Nat.succ_mul] at step + omega + +end S1aRtIn + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2RetypePost.lean b/proofs/Fl4ProofsA64/P1/S1aR2RetypePost.lean new file mode 100644 index 000000000..fbf26c43e --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2RetypePost.lean @@ -0,0 +1,899 @@ +/- +P1 (aarch64): the full VSpace record at a Retype creation end, on the end heap and slots. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2RetypeNew +import Fl4ProofsA64.P1.S1aR2UnmapRoute + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H H1 H' : Heap} {Cs OS OS1 Pt Pp Tb Hr Te Kt U0 Ac : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + {s s1 q : S} {ia ie lo hi : Nat} + {slot p sb fi aligned nt us dest off win : U64} {dev : Bool} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + +/-- The batch bases when the object type is `kind`. -/ +def s1aNewT (aligned nt us win : U64) (kind : Nat) : Set U64 := + {t | nt.val = kind ∧ ∃ j, j < win.val ∧ t = bjA aligned (zA nt.val us) j} + +/-- The VSpace footprint after Retype: surviving pages and every new table granule. -/ +def s1aRtPt (Pt : Set U64) (lo hi : Nat) (aligned nt us win : U64) : Set U64 := + PtOffR Pt lo hi ∪ NewPt nt aligned us win ∪ Gran (NewEpt nt aligned us win) (fun _ => 13) ∪ + s1aNewT aligned nt us win 8 ∪ Gran (s1aNewT aligned nt us win 14) (fun _ => 13) + +/-- Surviving Stage-1 table witnesses and the new HighVSpace roots. -/ +def s1aRtTb (Tb Pt : Set U64) (lo hi : Nat) (aligned nt us win : U64) : Set U64 := + {t | t ∈ Tb ∧ t ∈ PtOffR Pt lo hi} ∪ s1aNewT aligned nt us win 14 + +/-- Surviving Stage-2 table witnesses. -/ +def s1aRtTe (H' : Heap) (Te : Set U64) (bits : U64 → Nat) (lo hi : Nat) : Set U64 := + {t | t ∈ Te ∧ H' t = some (.other (bits t)) ∧ (t.val + 2 ^ bits t ≤ lo ∨ hi ≤ t.val)} + +open Classical in +/-- New HighVSpace roots are level-zero tables. -/ +noncomputable def s1aRtLv (Lv : U64 → Nat) (aligned nt us win : U64) : U64 → Nat := + fun t => if t ∈ s1aNewT aligned nt us win 14 then 0 else Lv t + +private theorem wordZero (t : U64) : wa t 0#u64 = t := by + apply UScalar.eq_of_val_eq + rw [wa_val] + have : t.val < 2 ^ 64 := by scalar_tac + simp [Nat.mod_eq_of_lt this] + +namespace S1aRtIn + +variable (E : S1aRtIn st H Cs OS U0 Ac s ia ie slot p sb fi dev extra H1 H' OS1 s1 q lo hi aligned nt us dest off win) +include E + +/-- A heap object whose first word is owned survives off the hole. -/ +theorem objOff (sep : S1aKtUt st OS Kt s) {t : U64} {k : HKind} (obj : H t = some k) + (own : S1aRetypeWordOwner st H OS Kt s t) : H' t = some k ∧ (t.val + 2 ^ k.bits ≤ lo ∨ hi ≤ t.val) := by + obtain ⟨r, kind, found, inside, after, outside⟩ := E.owner sep own + have same : r = t := by + by_contra different + have disjoint := E.place.heap.disj r kind t k found obj different + have positive := Nat.two_pow_pos k.bits + unfold InObj at inside + generalize kind.bits = width at disjoint inside + generalize k.bits = other at disjoint positive + generalize (2 : Nat) ^ width = A at disjoint inside + generalize (2 : Nat) ^ other = B at disjoint positive + omega + subst r + rw [obj] at found + obtain rfl := Option.some.inj found + exact ⟨after, outside⟩ + +/-- A table named by an old capability survives off the hole. -/ +theorem tableObj (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) {y : U64} (hy : y ∈ OS) {k : Nat × U64} + (key : s1aTableKey (capA st s y) = some k) : + ∃ z, 12 ≤ z ∧ H k.2 = some (.other z) ∧ H' k.2 = some (.other z) ∧ (k.2.val + 2 ^ z ≤ lo ∨ hi ≤ k.2.val) := by + have finish {t : U64} {z : Nat} (size : 12 ≤ z) (obj : H t = some (.other z)) + (range : RngKeyA (capA st s y)) (named : ptrA (capA st s y) = t) : + ∃ z, 12 ≤ z ∧ H t = some (.other z) ∧ H' t = some (.other z) ∧ (t.val + 2 ^ z ≤ lo ∨ hi ≤ t.val) := by + refine ⟨z, size, obj, E.old obj ⟨y, hy, range, ?_⟩⟩ + rw [named] + exact ⟨le_rfl, Nat.lt_add_of_pos_right (Nat.two_pow_pos _)⟩ + cases cap : capA st s y <;> rw [cap] at key <;> simp only [s1aTableKey] at key <;> try (cases key; done) + all_goals obtain rfl := Option.some.inj key + case PageTable t m a v => + exact finish le_rfl (h.pageObjects y hy t m a v cap) (cap ▸ RngKeyA.pt t m a v) (cap ▸ ptrA_pt t m a v) + case Pml4 t m a => + exact finish le_rfl (h.nativeRoots y hy t m a cap).1 (cap ▸ RngKeyA.pml4 t m a) (cap ▸ ptrA_pml4 t m a) + case Ept t l m a v => + exact finish (by decide) (h.eptRoots y hy t l m a v cap).1 (cap ▸ RngKeyA.ept t l m a v) + (cap ▸ ptrA_ept t l m a v) + case HighVSpace t m a => + exact finish (by decide) (h.highObjects y hy t m a cap) (cap ▸ RngKeyA.hv t m a) (cap ▸ ptrA_hv t m a) + +/-- A table granule named by an old capability lies outside the hole. -/ +theorem namedOff (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) {y t : U64} (hy : y ∈ OS) + (named : NamesV (capA st s y) t) : t.val + 4096 ≤ lo ∨ hi ≤ t.val := by + have base {k : Nat × U64} (key : s1aTableKey (capA st s y) = some k) : + k.2.val + 4096 ≤ lo ∨ hi ≤ k.2.val := by + obtain ⟨z, size, _, _, outside⟩ := E.tableObj h hy key + have := Nat.pow_le_pow_right (n := 2) (by decide) size + norm_num at this + omega + rcases named with ⟨m, a, v, cap⟩ | ⟨m, a, cap⟩ | ⟨m, a, cap⟩ | ⟨R, m, a, cap, rfl⟩ | ⟨l, m, a, v, cap⟩ + · exact base (k := (0, t)) (by rw [cap]; rfl) + · exact base (k := (1, t)) (by rw [cap]; rfl) + · exact base (k := (3, t)) (by rw [cap]; rfl) + · have obj := h.highObjects y hy R m a cap + have after := (E.old obj ⟨y, hy, cap ▸ RngKeyA.hv R m a, + by rw [cap, ptrA_hv]; exact ⟨le_rfl, Nat.lt_add_of_pos_right (Nat.two_pow_pos _)⟩⟩).2 + have fit := E.place.heap.fits R _ obj + change R.val + 8192 ≤ 2 ^ 64 at fit + change R.val + 8192 ≤ lo ∨ hi ≤ R.val at after + have value : (wa R 4096#u64).val = R.val + 4096 := wadd_val (by change R.val + 4096 < 2 ^ 64; omega) + omega + · exact base (k := (2, t)) (by rw [cap]; rfl) + +/-- A new table base has an exact object in the hole. -/ +theorem newT {kind : Nat} (allowed : kind = 8 ∨ kind = 11 ∨ kind = 13 ∨ kind = 14) {t : U64} + (member : t ∈ s1aNewT aligned nt us win kind) : + ∃ z, (z = 12 ∨ z = 13) ∧ (kind = 14 → z = 13) ∧ (kind = 8 → z = 12) ∧ H' t = some (.other z) ∧ + t.val % 2 ^ z = 0 ∧ t.val + 2 ^ z ≤ 2 ^ 64 ∧ lo ≤ t.val ∧ t.val + 2 ^ z ≤ hi := by + obtain ⟨type, j, hj, rfl⟩ := member + obtain ⟨_, size, obj, al, fit, low, high⟩ := E.newObj hj (type ▸ allowed) + refine ⟨_, size, fun e => ?_, fun e => ?_, obj, al, fit, low, high⟩ + · rw [type, e]; simp [zA] + · rw [type, e]; simp [zA] + +theorem newPt_sub : NewPt nt aligned us win ⊆ s1aRtPt Pt lo hi aligned nt us win := + fun _ h => Or.inl (Or.inl (Or.inl (Or.inr h))) + +/-- The record's placement and slot facts, ready to be combined with the walks. -/ +theorem footprintAt (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (kept : PtHG H' (PtOffR Pt lo hi ∪ NewPt nt aligned us win)) : + PtHG H' (s1aRtPt Pt lo hi aligned nt us win) := by + refine PtHG.union (PtHG.union (PtHG.union kept + (UtEnd.newEptPtHG E.pre E.place E.sys E.source E.creation E.window)) ?_) ?_ + · intro t member + obtain ⟨z, size, _, native, obj, al, fit, _, _⟩ := E.newT (Or.inl rfl) member + obtain rfl := native rfl + exact ⟨al, t, 12, obj, le_rfl, le_rfl⟩ + · intro g hg + obtain ⟨t, member, which⟩ := hg + obtain ⟨z, _, high, _, obj, al, fit, _, _⟩ := E.newT (Or.inr (Or.inr (Or.inr rfl))) member + obtain rfl := high rfl + norm_num at al fit + rcases which with rfl | ⟨_, rfl⟩ + · exact ⟨by omega, g, 13, obj, le_rfl, by norm_num⟩ + · have value : (wa t 4096#u64).val = t.val + 4096 := wadd_val (by change t.val + 4096 < 2 ^ 64; omega) + exact ⟨by rw [value]; omega, t, 13, obj, by rw [value]; omega, by rw [value]; norm_num⟩ + +set_option maxHeartbeats 4000000 in +/-- Retype establishes the full R2 record. The walk words and paths come from the decode's frame, +the new HighVSpace roots from its initializer, and kind and frame placement from the end state. -/ +theorem r2 (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (words : ∀ b, VsR (L.ksb s) Pt b → S1aRetypeWordOwner st H OS Kt s b → L.mem q b = L.mem s b) + (tab : TabKeep st s q) + (roots : ∀ asid raw, ActiveAsidRoot st Pp q asid raw ↔ ActiveAsidRoot st Pp s asid raw) + (paths : ∀ tag asid sh base t, S1aPath st Pp n q tag asid sh base t ↔ S1aPath st Pp n s tag asid sh base t) + (init : ∀ x ∈ OS, capA st s x = .Null → + (cdt.ensure_no_children st s slot = ok (.Ok ()) → x.val + 32 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ x.val) → + ∀ t m asid, capA st q x = .HighVSpace t m asid → S1aHighInit st Kt q t) + (kinds : KindA st (s1aRtSlots OS1 dev nt us aligned win) q) + (frames : FrameOK st H' (s1aRtSlots OS1 dev nt us aligned win) q) + (headers : HiCap511 st (s1aRtSlots OS1 dev nt us aligned win) q) + (ksOff : HeapKsOff H' (L.ksb s)) + (tables : PtCap st (PtOffR Pt lo hi ∪ NewPt nt aligned us win) (s1aRtSlots OS1 dev nt us aligned win) q ∧ + PtHG H' (PtOffR Pt lo hi ∪ NewPt nt aligned us win)) : + S1aR2 st H' (s1aRtSlots OS1 dev nt us aligned win) (s1aRtPt Pt lo hi aligned nt us win) Pp + (s1aRtTb Tb Pt lo hi aligned nt us win) (HvRt st (s1aRtSlots OS1 dev nt us aligned win) q) + (s1aRtTe H' Te bits lo hi) Kt (s1aRtLv Lv aligned nt us win) Re bits n q := by + have heap' := E.heapOK + have hn := E.creation.A.hn + have highKind : (14 : Nat) = 8 ∨ (14 : Nat) = 11 ∨ (14 : Nat) = 13 ∨ (14 : Nat) = 14 := by decide + have pools : PoolSet st Pp q = PoolSet st Pp s := tab.poolSet_eq + have notSource {x : U64} (empty : capA st s x ≠ .Null) (ut : ∀ a b c d, capA st s x ≠ .Untyped a b c d) : + x ≠ slot := by + rintro rfl + exact ut _ _ _ _ E.sourceCap + have keepCap {y : U64} (hy : y ∈ OS) {c : capability.Cap} (cap : capA st s y = c) (nonnull : c ≠ .Null) + (ut : ∀ a b d e, c ≠ .Untyped a b d e) : + y ∈ s1aRtSlots OS1 dev nt us aligned win ∧ capA st q y = c := by + have source : y ≠ slot := notSource (cap ▸ nonnull) (fun a b d e => cap ▸ ut a b d e) + obtain ⟨member, same⟩ := E.capKeep hy (cap ▸ nonnull) source + exact ⟨member, same.trans cap⟩ + have tableCap {x : U64} (hx : x ∈ s1aRtSlots OS1 dev nt us aligned win) {c : capability.Cap} + (cap : capA st q x = c) (nonnull : c ≠ .Null) (ut : ∀ a b d e, c ≠ .Untyped a b d e) : + (x ∈ OS ∧ capA st s x = c) ∨ + (∃ j, j < win.val ∧ x = djA dest off j ∧ c = newCapA nt.val (bjA aligned (zA nt.val us) j) us dev) := by + rcases E.capAt hx cap nonnull ut with ⟨member, _, old⟩ | new + · exact Or.inl ⟨member, old⟩ + · exact Or.inr new + have obj {t : U64} {k : HKind} (found : H t = some k) (own : S1aRetypeWordOwner st H OS Kt s t) := + E.objOff sep found own + have keep {b : U64} (placed : PtW Pt b) (own : S1aRetypeWordOwner st H OS Kt s b) : L.mem q b = L.mem s b := + words b (Or.inl placed) own + have offPt {t : U64} (placed : t ∈ Pt) (own : S1aRetypeWordOwner st H OS Kt s t) : t ∈ PtOffR Pt lo hi := + E.tableOff sep h.footprint placed own + have offNotNew {t : U64} (outside : t.val + 4096 ≤ lo ∨ hi ≤ t.val) {kind : Nat} + (allowed : kind = 8 ∨ kind = 11 ∨ kind = 13 ∨ kind = 14) : t ∉ s1aNewT aligned nt us win kind := by + intro member + obtain ⟨z, size, _, _, _, _, _, low, high⟩ := E.newT allowed member + rcases size with rfl | rfl <;> norm_num at high <;> omega + have lvOld {t : U64} (outside : t.val + 4096 ≤ lo ∨ hi ≤ t.val) : + s1aRtLv Lv aligned nt us win t = Lv t := by + unfold s1aRtLv + rw [if_neg (offNotNew outside highKind)] + have lvNew {t : U64} (member : t ∈ s1aNewT aligned nt us win 14) : s1aRtLv Lv aligned nt us win t = 0 := by + unfold s1aRtLv + rw [if_pos member] + have ptFit {t : U64} (placed : t ∈ Pt) : t.val + 4096 ≤ 2 ^ 64 := h.footprint.fit E.place.heap t placed + have value {t o : U64} (fit : t.val + 8192 ≤ 2 ^ 64) (bound : o.val < 8192) : (wa t o).val = t.val + o.val := + wadd_val (by omega) + have valuePage {t o : U64} (fit : t.val + 4096 ≤ 2 ^ 64) (bound : o.val < 4096) : + (wa t o).val = t.val + o.val := wadd_val (by omega) + -- the live pool pages + have poolOwn {t : U64} (active : t ∈ PoolSet st Pp s) {o : U64} (bound : o.val < 4096) (al : o.val % 8 = 0) := + h.poolWordOwner E.place.heap active bound al + have poolWords : ∀ t ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem q (wa t o) = L.mem s (wa t o) := fun t ht o bound al => + let ⟨placed, own⟩ := poolOwn ht bound al + keep placed own + have poolOff {t : U64} (active : t ∈ PoolSet st Pp s) : t ∈ PtOffR Pt lo hi := by + have own := (poolOwn active (o := 0#u64) (by decide) (by decide)).2 + rw [wordZero] at own + exact offPt (h.place.pools active) own + -- raw reachability + have off1 {t : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) (member : t ∈ Tb) : + t ∈ PtOffR Pt lo hi := by + have own := (h.reachWord1 E.place.heap reach (o := 0#u64) (by decide) (by decide)).2 + rw [wordZero] at own + exact offPt (h.place.tables member) own + have words1 {t : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) (o : U64) (bound : o.val < 4096) + (al : o.val % 8 = 0) : L.mem q (wa t o) = L.mem s (wa t o) := + let ⟨placed, own⟩ := h.reachWord1 E.place.heap reach bound al + keep placed own + have off1' {t : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) : t.val + 4096 ≤ lo ∨ hi ≤ t.val := by + obtain ⟨placed, own⟩ := h.reachWord1 E.place.heap reach (o := 0#u64) (by decide) (by decide) + rw [wordZero] at own placed + have member : t ∈ Pt := by + rcases h.classifyStage1 reach with kernel | ⟨raw, asid, active, tag, rfl⟩ | ⟨tag, asid, sh, va, stage, path⟩ + · exact h.place.tables (h.kernelTables.1 kernel) + · obtain ⟨x, hx, backed⟩ := h.core.root.backed asid raw active + rw [tag] at backed + rcases backed with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · cases bad + · cases bad + have held : (raw &&& ~~~3#u64) ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, asid, cap⟩ + exact h.place.tables (h.place.high.sub held) + · have typed := h.paths.tables tag asid sh va t path + have plain : tag ≠ 1#u64 := by rcases stage with rfl | rfl <;> decide + rw [ite_eq_right plain] at typed + exact h.place.tables typed.1 + exact (offPt member own).2 + have lvReach {t : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) : + s1aRtLv Lv aligned nt us win t = Lv t := lvOld (off1' reach) + have reach1 {t : U64} : VsReach st (PoolSet st Pp s) ∅ (s1aRtLv Lv aligned nt us win) q t ↔ + VsReach st (PoolSet st Pp s) ∅ Lv s t := + VsReach.congrWords poolWords (fun r reach => ⟨lvReach reach, words1 reach⟩) + have tbOld {t : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) + (member : t ∈ s1aRtTb Tb Pt lo hi aligned nt us win) : t ∈ Tb := by + rcases member with ⟨member, _⟩ | new + · exact member + · exact (offNotNew (off1' reach) highKind new).elim + have tbKeep {t : U64} (reach : VsReach st (PoolSet st Pp s) ∅ Lv s t) (member : t ∈ Tb) : + t ∈ s1aRtTb Tb Pt lo hi aligned nt us win := Or.inl ⟨member, off1 reach member⟩ + have words2 {t : U64} (reach : S2Reach st (PoolSet st Pp s) Re bits s t) (o : U64) (bound : o.val < 2 ^ bits t) + (al : o.val % 8 = 0) : L.mem q (wa t o) = L.mem s (wa t o) := + let ⟨placed, own⟩ := h.reachWord2 E.place.heap reach bound al + keep placed own + have reach2 {t : U64} : S2Reach st (PoolSet st Pp s) Re bits q t ↔ S2Reach st (PoolSet st Pp s) Re bits s t := + S2Reach.congrWords poolWords (fun r reach => words2 reach) + have teKeep {t : U64} (reach : S2Reach st (PoolSet st Pp s) Re bits s t) (member : t ∈ Te) : + t ∈ s1aRtTe H' Te bits lo hi := by + have own := (h.reachWord2 E.place.heap reach (o := 0#u64) (Nat.two_pow_pos _) (by decide)).2 + rw [wordZero] at own + exact ⟨member, obj (h.core.heap t member).1 own⟩ + -- HighVSpace roots, old and new + have oldRoot {y R asid : U64} {m : Bool} (hy : y ∈ OS) (cap : capA st s y = .HighVSpace R m asid) : + R ∈ Hr ∧ H R = some (.other 13) ∧ H' R = some (.other 13) ∧ (R.val + 8192 ≤ lo ∨ hi ≤ R.val) := by + have held : R ∈ Hr := by rw [h.highRoots]; exact ⟨y, hy, m, asid, cap⟩ + have found := h.highObjects y hy R m asid cap + refine ⟨held, found, E.old found ⟨y, hy, cap ▸ RngKeyA.hv R m asid, ?_⟩⟩ + rw [cap, ptrA_hv] + exact ⟨le_rfl, Nat.lt_add_of_pos_right (Nat.two_pow_pos _)⟩ + have newRoot {R : U64} (member : R ∈ s1aNewT aligned nt us win 14) : + R ∈ HvRt st (s1aRtSlots OS1 dev nt us aligned win) q := by + obtain ⟨type, j, hj, rfl⟩ := member + obtain ⟨slotMember, cap⟩ := E.newSlot hj + refine ⟨_, slotMember, false, 0#u64, cap.trans ?_⟩ + rw [type] + simp [newCapA] + have rootCases {R : U64} (member : R ∈ HvRt st (s1aRtSlots OS1 dev nt us aligned win) q) : + (∃ y ∈ OS, ∃ m asid, capA st s y = .HighVSpace R m asid) ∨ R ∈ s1aNewT aligned nt us win 14 := by + obtain ⟨y, hy, m, asid, cap⟩ := member + rcases tableCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨old, before⟩ | ⟨j, hj, _, new⟩ + · exact Or.inl ⟨y, old, m, asid, before⟩ + · obtain ⟨type, base⟩ := newCapA_hv hn new.symm + exact Or.inr ⟨type, j, hj, base⟩ + have newInit {R : U64} (member : R ∈ s1aNewT aligned nt us win 14) : S1aHighInit st Kt q R := by + obtain ⟨type, j, hj, rfl⟩ := member + exact E.highInit init hj type + have rootPlaced {R : U64} (held : R ∈ Hr) (outside : R.val + 8192 ≤ lo ∨ hi ≤ R.val) {g : U64} + (granule : g = R ∨ g = wa R 4096#u64) : g ∈ PtOffR Pt lo hi := by + have placed : g ∈ Pt := h.highFootprint (granule.elim (fun e => ⟨R, held, Or.inl e⟩) + (fun e => ⟨R, held, Or.inr ⟨rfl, e⟩⟩)) + have fit := E.place.heap.fits R (.other 13) (by + rw [h.highRoots] at held + obtain ⟨y, hy, m, asid, cap⟩ := held + exact h.highObjects y hy R m asid cap) + change R.val + 8192 ≤ 2 ^ 64 at fit + refine ⟨placed, ?_⟩ + rcases granule with rfl | rfl + · omega + · have v : (wa R 4096#u64).val = R.val + 4096 := wadd_val (by change R.val + 4096 < 2 ^ 64; omega) + omega + have rootWords {y R asid : U64} {m : Bool} (hy : y ∈ OS) (cap : capA st s y = .HighVSpace R m asid) + {g o : U64} (granule : g = R ∨ g = wa R 4096#u64) (bound : o.val < 4096) (al : o.val % 8 = 0) : + L.mem q (wa g o) = L.mem s (wa g o) := by + obtain ⟨held, found, _, _⟩ := oldRoot hy cap + have placed : g ∈ Pt := h.highFootprint (granule.elim (fun e => ⟨R, held, Or.inl e⟩) + (fun e => ⟨R, held, Or.inr ⟨rfl, e⟩⟩)) + have fit := E.place.heap.fits R _ found + change R.val + 8192 ≤ 2 ^ 64 at fit + refine keep ⟨g, placed, o, bound, al, rfl⟩ ⟨R, .other 13, found, ?_, Or.inr ⟨y, hy, ?_⟩⟩ + · have word : (wa g o).val = R.val + (g.val - R.val) + o.val ∧ g.val - R.val ≤ 4096 ∧ R.val ≤ g.val := by + rcases granule with rfl | rfl + · rw [value fit (by omega)]; omega + · have v : (wa R 4096#u64).val = R.val + 4096 := wadd_val (by change R.val + 4096 < 2 ^ 64; omega) + have w : (wa (wa R 4096#u64) o).val = R.val + 4096 + o.val := by + rw [wadd_val (by omega), v] + omega + unfold InObj + change R.val ≤ (wa g o).val ∧ (wa g o).val < R.val + 8192 + omega + · rw [cap] + exact ⟨RngKeyA.hv R m asid, ptrA_hv R m asid⟩ + -- the footprint + have footprint := E.footprintAt h tables.2 + have keptSub : PtOffR Pt lo hi ∪ NewPt nt aligned us win ⊆ s1aRtPt Pt lo hi aligned nt us win := + fun _ g => Or.inl (Or.inl (Or.inl g)) + have offSub : PtOffR Pt lo hi ⊆ s1aRtPt Pt lo hi aligned nt us win := fun _ g => keptSub (Or.inl g) + have highNewSub : s1aNewT aligned nt us win 14 ⊆ s1aRtPt Pt lo hi aligned nt us win := by + rintro t ⟨type, j, hj, rfl⟩ + exact E.newPt_sub ⟨Or.inr type, j, hj, rfl⟩ + have highGran : Gran (HvRt st (s1aRtSlots OS1 dev nt us aligned win) q) (fun _ => 13) ⊆ + s1aRtPt Pt lo hi aligned nt us win := by + rintro g ⟨R, member, which⟩ + rcases rootCases member with ⟨y, hy, m, asid, cap⟩ | new + · obtain ⟨held, _, _, outside⟩ := oldRoot hy cap + exact offSub (rootPlaced held outside (which.imp_right And.right)) + · exact Or.inr ⟨R, new, which⟩ + have notAs : ∀ b, PtW (s1aRtPt Pt lo hi aligned nt us win) b → ¬ AsW (L.ksb s) b := + HeapKsOff.ptAsWG ksOff footprint E.sys.ly.ksw (footprint.fit heap') + have tbSub : s1aRtTb Tb Pt lo hi aligned nt us win ⊆ s1aRtPt Pt lo hi aligned nt us win := by + rintro t (⟨_, outside⟩ | new) + · exact offSub outside + · exact highNewSub new + have teSub : Gran (s1aRtTe H' Te bits lo hi) bits ⊆ s1aRtPt Pt lo hi aligned nt us win := by + rintro g ⟨t, ⟨member, found, outside⟩, which⟩ + have placed : g ∈ Pt := h.place.granules ⟨t, member, which⟩ + have size := h.place.stage2.sz t member + have fit := heap'.fits t _ found + change t.val + 2 ^ bits t ≤ 2 ^ 64 at fit + refine offSub ⟨placed, ?_⟩ + rcases which with rfl | ⟨wide, rfl⟩ + · rcases size with e | e <;> rw [e] at outside <;> norm_num at outside <;> omega + · rw [wide] at outside fit + norm_num at outside fit + have v : (wa t 4096#u64).val = t.val + 4096 := wadd_val (by change t.val + 4096 < 2 ^ 64; omega) + omega + -- a word of an old table never meets a new object + have apart {t o R k : U64} (outside : t.val + 4096 ≤ lo ∨ hi ≤ t.val) (fit : t.val + 4096 ≤ 2 ^ 64) + (bound : o.val < 4096) (member : R ∈ s1aNewT aligned nt us win 14) (offset : k.val < 4096) : + wa t o ≠ wa R k := by + obtain ⟨z, _, wide, _, _, _, rfit, low, high⟩ := E.newT highKind member + obtain rfl := wide rfl + norm_num at rfit high + have rfit : R.val + 8192 ≤ 2 ^ 64 := by omega + intro same + have v := congrArg UScalar.val same + rw [valuePage fit bound, value rfit (by omega)] at v + omega + have newValue {R k : U64} (member : R ∈ s1aNewT aligned nt us win 14) (bound : k.val < 8192) : + (wa R k).val = R.val + k.val ∧ R.val % 8192 = 0 := by + obtain ⟨z, _, wide, _, _, al, rfit, _, _⟩ := E.newT highKind member + obtain rfl := wide rfl + norm_num at al rfit + exact ⟨value (by omega) bound, al⟩ + have highPlace : HrOK (L.ksb s) (PoolSet st Pp s) (s1aRtTb Tb Pt lo hi aligned nt us win) + (s1aRtLv Lv aligned nt us win) (HvRt st (s1aRtSlots OS1 dev nt us aligned win) q) := by + refine ⟨?_, ?_, ?_, ?_, ?_⟩ + · intro R member + rcases rootCases member with ⟨y, hy, m, asid, cap⟩ | new + · obtain ⟨held, _, _, outside⟩ := oldRoot hy cap + exact Or.inl ⟨h.place.high.sub held, rootPlaced held outside (Or.inl rfl)⟩ + · exact Or.inr new + · intro R member + rcases rootCases member with ⟨y, hy, m, asid, cap⟩ | new + · obtain ⟨held, _, _, outside⟩ := oldRoot hy cap + rw [lvOld (by omega)] + exact h.place.high.lv R held + · exact lvNew new + · intro t table o bound al R member same + rcases rootCases member with ⟨y, hy, m, asid, cap⟩ | new + · obtain ⟨held, found, _, outside⟩ := oldRoot hy cap + rcases table with ⟨table, _⟩ | fresh + · exact h.place.high.tb t table o bound al R held same + · have fit := E.place.heap.fits R _ found + change R.val + 8192 ≤ 2 ^ 64 at fit + exact (apart (t := R) (o := 4088#u64) (by omega) (by omega) (by decide) fresh bound same.symm).elim + · rcases table with ⟨_, outside⟩ | fresh + · exact (apart outside.2 (ptFit outside.1) bound new (by decide) same).elim + · obtain ⟨v1, a1⟩ := newValue fresh (k := o) (by omega) + obtain ⟨v2, a2⟩ := newValue new (k := 4088#u64) (by decide) + have v := congrArg UScalar.val same + rw [v1, v2, show (4088#u64 : U64).val = 4088 from rfl] at v + exact UScalar.eq_of_val_eq (by omega) + · intro t active o bound al R member same + rcases rootCases member with ⟨y, hy, m, asid, cap⟩ | new + · exact h.place.high.pp t active o bound al R (oldRoot hy cap).1 same + · have outside := poolOff active + exact apart outside.2 (ptFit outside.1) bound new (by decide) same + · intro R member word + rcases rootCases member with ⟨y, hy, m, asid, cap⟩ | new + · exact h.place.high.asw R (oldRoot hy cap).1 word + · exact notAs _ ⟨R, highNewSub new, 4088#u64, by decide, by decide, rfl⟩ word + have stage2Place : S2OK (s1aRtTe H' Te bits lo hi) bits (HvRt st (s1aRtSlots OS1 dev nt us aligned win) q) := by + refine ⟨fun t member => h.place.stage2.sz t member.1, fun t member => h.place.stage2.al t member.1, ?_⟩ + rintro b ⟨t, ⟨member, found, outside⟩, o, bound, al, rfl⟩ R root same + rcases rootCases root with ⟨y, hy, m, asid, cap⟩ | new + · exact h.place.stage2.hr _ ⟨t, member, o, bound, al, rfl⟩ R (oldRoot hy cap).1 same + · obtain ⟨z, _, wide, _, _, _, rfit, low, high⟩ := E.newT highKind new + obtain rfl := wide rfl + norm_num at rfit high + have word := h.place.stage2.val member bound + have v := congrArg UScalar.val same + rw [word, value (t := R) (o := 4088#u64) (by omega) (by decide), show (4088#u64 : U64).val = 4088 from rfl] at v + omega + have place : S1aR2Place (s1aRtPt Pt lo hi aligned nt us win) (PoolSet st Pp s) + (s1aRtTb Tb Pt lo hi aligned nt us win) (HvRt st (s1aRtSlots OS1 dev nt us aligned win) q) + (s1aRtTe H' Te bits lo hi) (s1aRtLv Lv aligned nt us win) bits (L.ksb s) := + ⟨fun t active => offSub (poolOff active), tbSub, teSub, highPlace, stage2Place⟩ + -- caps against objects + have oldNeNew {y : U64} (hy : y ∈ OS) {k : Nat × U64} (key : s1aTableKey (capA st s y) = some k) {j : Nat} + (hj : j < win.val) (allowed : nt.val = 8 ∨ nt.val = 11 ∨ nt.val = 13 ∨ nt.val = 14) + (same : k.2 = bjA aligned (zA nt.val us) j) : False := by + obtain ⟨z, size, _, _, outside⟩ := E.tableObj h hy key + obtain ⟨_, sizes, _, _, _, low, high⟩ := E.newObj hj allowed + rw [same] at outside + have big := Nat.pow_le_pow_right (n := 2) (by decide) size + norm_num at big + rcases sizes with e | e <;> rw [e] at high <;> norm_num at high <;> omega + have oldMapped {y t : U64} (hy : y ∈ s1aRtSlots OS1 dev nt us aligned win) (mapped : MapV (capA st q y) t) : + y ∈ OS ∧ MapV (capA st s y) t := by + have shape : capA st q y ≠ .Null ∧ ∀ a b d e, capA st q y ≠ .Untyped a b d e := by + rcases mapped with ⟨a, v, e⟩ | ⟨a, e⟩ | ⟨a, e⟩ | ⟨R, a, e, _⟩ | ⟨l, a, v, e⟩ <;> + rw [e] <;> exact ⟨(fun e => by cases e), (fun _ _ _ _ e => by cases e)⟩ + rcases tableCap hy rfl shape.1 shape.2 with ⟨old, same⟩ | ⟨j, _, _, new⟩ + · exact ⟨old, same.symm ▸ mapped⟩ + · rw [new] at mapped + exact (newCapA_notMapV hn _ mapped).elim + have keepMapped {y t : U64} (hy : y ∈ OS) (mapped : MapV (capA st s y) t) : + y ∈ s1aRtSlots OS1 dev nt us aligned win ∧ capA st q y = capA st s y := by + have shape : capA st s y ≠ .Null ∧ ∀ a b d e, capA st s y ≠ .Untyped a b d e := by + rcases mapped with ⟨a, v, e⟩ | ⟨a, e⟩ | ⟨a, e⟩ | ⟨R, a, e, _⟩ | ⟨l, a, v, e⟩ <;> + rw [e] <;> exact ⟨(fun e => by cases e), (fun _ _ _ _ e => by cases e)⟩ + exact keepCap hy rfl shape.1 shape.2 + have rootBacked : RootAgreement st (s1aRtSlots OS1 dev nt us aligned win) Pp q := by + refine ⟨fun asid raw entry => ?_, fun x hx y hy root a b tag tag' cx cy => ?_⟩ + · obtain ⟨x, hx, backed⟩ := h.core.root.backed asid raw ((roots asid raw).mp entry) + have shape : capA st s x ≠ .Null ∧ ∀ a b d e, capA st s x ≠ .Untyped a b d e := by + rcases backed with ⟨_, e⟩ | ⟨_, v, e⟩ | ⟨_, e⟩ <;> + rw [e] <;> exact ⟨(fun e => by cases e), (fun _ _ _ _ e => by cases e)⟩ + obtain ⟨member, same⟩ := keepCap hx rfl shape.1 shape.2 + exact ⟨x, member, same.symm ▸ backed⟩ + · have old {z r : U64} {i t : U64} (hz : z ∈ s1aRtSlots OS1 dev nt us aligned win) + (mapped : MappedAsidRoot (capA st q z) r i t) : z ∈ OS ∧ MappedAsidRoot (capA st s z) r i t := by + have shape : capA st q z ≠ .Null ∧ ∀ a b d e, capA st q z ≠ .Untyped a b d e := by + rcases mapped with ⟨_, e⟩ | ⟨_, v, e⟩ | ⟨_, e⟩ <;> + rw [e] <;> exact ⟨(fun e => by cases e), (fun _ _ _ _ e => by cases e)⟩ + rcases tableCap hz rfl shape.1 shape.2 with ⟨member, same⟩ | ⟨j, _, _, new⟩ + · exact ⟨member, same.symm ▸ mapped⟩ + · rw [new] at mapped + exact (newCapA_notMappedRoot hn _ _ _ mapped).elim + obtain ⟨xo, cxo⟩ := old hx cx + obtain ⟨yo, cyo⟩ := old hy cy + exact h.core.root.agree x xo y yo root a b tag tag' cxo cyo + have kernelOff {t : U64} (member : t ∈ Kt) := E.kernel sep member (h.kernelTables.2 t member) + -- unmapped caps + have unmShape {c : capability.Cap} {t : U64} {width : Nat} (unm : UnmCap c t width) : + c ≠ .Null ∧ (∀ a b d e, c ≠ .Untyped a b d e) ∧ NamesV c t := by + refine ⟨?_, ?_, unm.names⟩ <;> rcases unm with ⟨_, a, v, e⟩ | ⟨_, a, v, e⟩ <;> rw [e] + · exact fun e => by cases e + · exact fun e => by cases e + · exact fun _ _ _ _ e => by cases e + · exact fun _ _ _ _ e => by cases e + have lookup : VsLk st H' (s1aRtSlots OS1 dev nt us aligned win) Pp (s1aRtTb Tb Pt lo hi aligned nt us win) + (s1aRtTe H' Te bits lo hi) Kt (s1aRtLv Lv aligned nt us win) Re bits q := by + refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ + · intro t reach member outside + rw [pools] at reach + have old := reach1.mp reach + obtain ⟨y, hy, mapped⟩ := h.core.lookup.bk1 t old (tbOld old member) outside + obtain ⟨after, same⟩ := keepMapped hy mapped + exact ⟨y, after, same.symm ▸ mapped⟩ + · intro t reach member + rw [pools] at reach + obtain ⟨y, hy, mapped⟩ := h.core.lookup.bk2 t (reach2.mp reach) member.1 + obtain ⟨after, same⟩ := keepMapped hy mapped + exact ⟨y, after, same.symm ▸ mapped⟩ + · intro t kernel y hy named + have shape : capA st q y ≠ .Null ∧ ∀ a b d e, capA st q y ≠ .Untyped a b d e := by + rcases named with ⟨m, a, v, e⟩ | ⟨m, a, e⟩ | ⟨m, a, e⟩ | ⟨R, m, a, e, _⟩ | ⟨l, m, a, v, e⟩ <;> + rw [e] <;> exact ⟨(fun e => by cases e), (fun _ _ _ _ e => by cases e)⟩ + rcases tableCap hy rfl shape.1 shape.2 with ⟨old, same⟩ | ⟨j, hj, _, new⟩ + · exact h.core.lookup.kt t kernel y old (same.symm ▸ named) + · rw [new] at named + obtain ⟨allowed, which⟩ := newCapA_namesV hn named + obtain ⟨_, sizes, _, _, fit, low, high⟩ := E.newObj hj allowed + have outside := (kernelOff kernel).2 + rcases which with rfl | ⟨type, rfl⟩ + · rcases sizes with e | e <;> rw [e] at high <;> norm_num at high <;> omega + · have wide : (zA nt.val us).val = 13 := by rw [type]; simp [zA] + rw [wide] at high fit + norm_num at high fit + have v : (wa (bjA aligned (zA nt.val us) j) 4096#u64).val = (bjA aligned (zA nt.val us) j).val + 4096 := + wadd_val (by change (bjA aligned (zA nt.val us) j).val + 4096 < 2 ^ 64; omega) + omega + · intro x hx y hy t width unm mapped + obtain ⟨yo, before⟩ := oldMapped hy mapped + obtain ⟨nonnull, ut, _⟩ := unmShape unm + rcases tableCap hx rfl nonnull ut with ⟨xo, same⟩ | ⟨j, hj, _, new⟩ + · exact h.core.lookup.ex x xo y yo t width (same.symm ▸ unm) before + · rw [new] at unm + obtain ⟨rfl, which⟩ := newCapA_unm hn unm + have allowed : nt.val = 8 ∨ nt.val = 11 ∨ nt.val = 13 ∨ nt.val = 14 := by omega + have outside := E.namedOff h yo before.names + obtain ⟨_, sizes, _, _, _, low, high⟩ := E.newObj hj allowed + rcases sizes with e | e <;> rw [e] at high <;> norm_num at high <;> omega + · intro x hx t width unm o bound al + obtain ⟨nonnull, ut, _⟩ := unmShape unm + rcases tableCap hx rfl nonnull ut with ⟨xo, same⟩ | ⟨j, hj, _, new⟩ + · have before : UnmCap (capA st s x) t width := same.symm ▸ unm + obtain ⟨z, exactSize, found⟩ := h.core.lookup.vh.1 x xo t width before + have kept : L.mem q (wa t o) = L.mem s (wa t o) := by + have inside : o.val < 2 ^ z := exactSize ▸ bound + rcases before with ⟨wide, a, v, cap⟩ | ⟨wide, a, v, cap⟩ + · refine keep ⟨t, h.pageTables x xo t false a v cap, o, wide ▸ bound, al, rfl⟩ + ⟨t, .other z, found, inObjWord E.place.heap found inside, Or.inr ⟨x, xo, ?_⟩⟩ + rw [cap] + exact ⟨RngKeyA.pt _ _ _ _, ptrA_pt _ _ _ _⟩ + · have granules := (h.eptRoots x xo t 0#u64 false a v cap).2 + have word : PtWb {t} (fun _ => 13) (wa t o) := + ⟨t, Set.mem_singleton t, o, show o.val < 2 ^ 13 by rw [wide] at bound; exact bound, al, rfl⟩ + refine keep (ptw_mono granules (ptwb_gran (fun _ _ => Or.inr rfl) word)) + ⟨t, .other z, found, inObjWord E.place.heap found inside, Or.inr ⟨x, xo, ?_⟩⟩ + rw [cap] + exact ⟨RngKeyA.ept _ _ _ _ _, ptrA_ept _ _ _ _ _⟩ + rw [kept] + exact h.core.lookup.zr x xo t width before o bound al + · rw [new] at unm + obtain ⟨rfl, which⟩ := newCapA_unm hn unm + have allowed : nt.val = 8 ∨ nt.val = 11 ∨ nt.val = 13 ∨ nt.val = 14 := by omega + obtain ⟨ram, _, _, al8, _, _, _⟩ := E.newObj hj allowed + have creation := E.creation.E + rw [ram] at creation + have base8 := E.creation.A.al + have total := E.creation.A.aw.trans E.creation.A.pf + refine CrtE.zeroTable creation (by omega) base8 total hj o ?_ al + rcases which with ⟨type, rfl⟩ | ⟨type, rfl⟩ + · rw [show (zA nt.val us).val = 12 by rw [type]; simp [zA]] + exact bound + · rw [show (zA nt.val us).val = 13 by rw [type]; simp [zA]] + exact bound + · intro x hx t width unm + obtain ⟨nonnull, ut, _⟩ := unmShape unm + rcases tableCap hx rfl nonnull ut with ⟨xo, same⟩ | ⟨j, hj, _, new⟩ + · have before : UnmCap (capA st s x) t width := same.symm ▸ unm + obtain ⟨z, exactSize, found⟩ := h.core.lookup.vh.1 x xo t width before + have key : ∃ k : Nat × U64, s1aTableKey (capA st s x) = some k ∧ k.2 = t := by + rcases before with ⟨_, a, v, cap⟩ | ⟨_, a, v, cap⟩ + · exact ⟨(0, t), by rw [cap]; rfl, rfl⟩ + · exact ⟨(2, t), by rw [cap]; rfl, rfl⟩ + obtain ⟨k, key, rfl⟩ := key + obtain ⟨z', _, found', after, _⟩ := E.tableObj h xo key + exact ⟨z, exactSize, by rw [after, ← found', found]⟩ + · rw [new] at unm + obtain ⟨rfl, which⟩ := newCapA_unm hn unm + have allowed : nt.val = 8 ∨ nt.val = 11 ∨ nt.val = 13 ∨ nt.val = 14 := by omega + obtain ⟨_, _, found, _, _, _, _⟩ := E.newObj hj allowed + refine ⟨_, ?_, found⟩ + rcases which with ⟨type, rfl⟩ | ⟨type, rfl⟩ + · rw [show (zA nt.val us).val = 12 by rw [type]; simp [zA]] + norm_num + · rw [show (zA nt.val us).val = 13 by rw [type]; simp [zA]] + norm_num + · intro t reach member outside + rw [pools] at reach + have old := reach1.mp reach + rcases h.core.lookup.vh.2.1 t old (tbOld old member) outside with plain | ⟨R, found, granule, y, hy, a, cap⟩ + · have own := (h.reachWord1 E.place.heap old (o := 0#u64) (by decide) (by decide)).2 + rw [wordZero] at own + exact Or.inl (obj plain own).1 + · obtain ⟨_, _, after, _⟩ := oldRoot hy cap + obtain ⟨member', same⟩ := keepCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) + exact Or.inr ⟨R, after, granule, y, member', a, same⟩ + · intro t _ member + exact member.2.1 + have exactPaths : S1aPathBacking st H' (s1aRtSlots OS1 dev nt us aligned win) Pp + (s1aRtTb Tb Pt lo hi aligned nt us win) (s1aRtTe H' Te bits lo hi) (s1aRtLv Lv aligned nt us win) + Re bits n q := by + have pathOwn {tag asid t : U64} {sh va : Nat} (path : S1aPath st Pp n s tag asid sh va t) : + S1aRetypeWordOwner st H OS Kt s t := by + have positive : 0 < s1aTableStorage tag n sh := by + unfold s1aTableStorage + split <;> decide + have own := (h.storageWord E.place.heap path (o := 0#u64) positive (by decide)).2 + rwa [wordZero] at own + have pathWords {tag asid t o : U64} {sh va : Nat} (path : S1aPath st Pp n s tag asid sh va t) + (bound : o.val < s1aTableWidth tag n sh) (al : o.val % 8 = 0) : L.mem q (wa t o) = L.mem s (wa t o) := + let ⟨placed, own⟩ := h.storageWord E.place.heap path + (lt_of_lt_of_le bound (s1aTableWidth.leStorage tag n sh)) al + keep placed own + refine ⟨fun tag asid sh va t path => ?_, fun tag asid sh va t path child => ?_, + fun tag asid sh va t path o bound al range valid => ?_⟩ + · have before := (paths _ _ _ _ _).mp path + have typed := h.paths.tables tag asid sh va t before + by_cases stage : tag = 1#u64 + · rw [ite_eq_left stage] at typed ⊢ + have found := (h.core.heap t typed.1).1 + exact ⟨⟨typed.1, obj found (pathOwn before)⟩, typed.2⟩ + · rw [ite_eq_right stage] at typed ⊢ + have outside := offPt (h.place.tables typed.1) (pathOwn before) + exact ⟨Or.inl ⟨typed.1, outside⟩, by rw [lvOld outside.2]; exact typed.2⟩ + · obtain ⟨x, hx, address, cap, ref⟩ := h.paths.children tag asid sh va t ((paths _ _ _ _ _).mp path) child + obtain ⟨member, same⟩ := keepCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) + exact ⟨x, member, address, same, ref⟩ + · have before := (paths _ _ _ _ _).mp path + have word := pathWords before bound al + rw [word] at valid ⊢ + obtain ⟨x, hx, sz, rights, device, address, size, cap, ref, found⟩ := + h.paths.leaves tag asid sh va t before o bound al range valid + 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 + 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⟩ + · 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 + intro R member + rcases rootCases member with ⟨y, hy, m, asid, cap⟩ | new + · rw [rootWords hy cap (Or.inl rfl) (o := 4088#u64) (by decide) (by decide)] + exact h.highLink R (oldRoot hy cap).1 + · exact (newInit new).2.1 + have highObj : HvObjects st H' (s1aRtSlots OS1 dev nt us aligned win) q := + UtEnd.hvObjects E.pre E.place E.sys E.source E.creation E.kept E.reset E.window h.highObjects + have ept : EptPlaced st H' (s1aRtSlots OS1 dev nt us aligned win) (s1aRtPt Pt lo hi aligned nt us win) q := by + have placed := UtEnd.eptPlaced E.pre E.place E.sys E.source E.creation E.kept E.reset E.window h.eptRoots + exact placed.mono fun g member => + member.elim (fun kept => offSub kept) (fun new => Or.inl (Or.inl (Or.inr new))) + have pageObj : PtObjects st H' (s1aRtSlots OS1 dev nt us aligned win) q := + UtEnd.ptObjects E.pre E.place E.sys E.source E.creation E.kept E.reset E.window h.pageObjects + have closed : ∀ t ∈ Kt, s1aRtLv Lv aligned nt us win t < 3 → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + (L.mem q (wa t o) &&& 3#u64) = 3#u64 → + wa (L.mem q (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + intro t member level o bound al edge + rw [lvOld (kernelOff member).2] at level + have found := h.kernelTables.2 t member + have word : L.mem q (wa t o) = L.mem s (wa t o) := + keep ⟨t, h.place.tables (h.kernelTables.1 member), o, bound, al, rfl⟩ + ⟨t, .other 12, found, inObjWord E.place.heap found bound, Or.inl ⟨member, rfl⟩⟩ + rw [word] at edge ⊢ + exact h.kernelClosed t member level o bound al edge + have rootSlots : S1aRootSlots st (s1aRtSlots OS1 dev nt us aligned win) Kt n q := by + have creationRam {j : Nat} (hj : j < win.val) (allowed : nt.val = 8 ∨ nt.val = 11 ∨ nt.val = 13 ∨ nt.val = 14) : + CrtE st H1 H.frame OS1 s1 q slot p sb false aligned nt us dest off win := by + have creation := E.creation.E + rwa [(E.newObj hj allowed).1] at creation + have total := E.creation.A.aw.trans E.creation.A.pf + refine ⟨?_, ?_, ?_, ?_⟩ + · intro x hx t m a cap o bound al + rcases tableCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨xo, before⟩ | ⟨j, hj, _, new⟩ + · have found := (h.nativeRoots x xo t m a before).1 + have word : L.mem q (wa t o) = L.mem s (wa t o) := by + refine keep ⟨t, (h.nativeRoots x xo t m a before).2, o, bound.2, al, rfl⟩ + ⟨t, .other 12, found, inObjWord E.place.heap found bound.2, Or.inr ⟨x, xo, ?_⟩⟩ + rw [before] + exact ⟨RngKeyA.pml4 _ _ _, ptrA_pml4 _ _ _⟩ + rw [word] + exact h.rootSlots.native x xo t m a before o bound al + · obtain ⟨type, rfl, _⟩ := newCapA_pml4 hn new.symm + exact CrtE.nativeRootSlots (creationRam hj (Or.inl type)) type E.creation.A.al total hj o bound al + · intro x hx t m a v cap o bound al + rcases tableCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨xo, before⟩ | ⟨j, hj, _, new⟩ + · obtain ⟨found, granules⟩ := h.eptRoots x xo t _ m a v before + have word : PtWb {t} (fun _ => 13) (wa t o) := ⟨t, Set.mem_singleton t, o, bound.2, al, rfl⟩ + have same : L.mem q (wa t o) = L.mem s (wa t o) := by + refine keep (ptw_mono granules (ptwb_gran (fun _ _ => Or.inr rfl) word)) + ⟨t, .other 13, found, inObjWord E.place.heap found bound.2, Or.inr ⟨x, xo, ?_⟩⟩ + rw [before] + exact ⟨RngKeyA.ept _ _ _ _ _, ptrA_ept _ _ _ _ _⟩ + rw [same] + exact h.rootSlots.stage2 x xo t m a v before o bound al + · obtain ⟨type, rfl, _, _⟩ := newCapA_eptShape hn new.symm + exact CrtE.stage2RootSlots (creationRam hj (Or.inr (Or.inr (Or.inl type)))) type E.creation.A.al total hj + n o bound al + · intro x hx t m a cap o bound al edge + rcases tableCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨xo, before⟩ | ⟨j, hj, _, new⟩ + · rw [rootWords xo before (Or.inl rfl) (by omega) al] at edge ⊢ + exact h.rootSlots.highCopies x xo t m a before o bound al edge + · obtain ⟨type, base⟩ := newCapA_hv hn new.symm + exact (newInit ⟨type, j, hj, base⟩).1 o bound al edge + · intro x hx t m a cap o bound al + rcases tableCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨xo, before⟩ | ⟨j, hj, _, new⟩ + · rw [rootWords xo before (Or.inr rfl) bound.1 al] + exact h.rootSlots.highPrivate x xo t m a before o bound al + · obtain ⟨type, base⟩ := newCapA_hv hn new.symm + exact (newInit ⟨type, j, hj, base⟩).2.2 o bound.1 al + have capRefs : S1aTableCaps st (s1aRtSlots OS1 dev nt us aligned win) q := by + have classify {x : U64} (hx : x ∈ s1aRtSlots OS1 dev nt us aligned win) {k : Nat × U64} + (key : s1aTableKey (capA st q x) = some k) : + (x ∈ OS ∧ capA st s x = capA st q x) ∨ + (∃ j, j < win.val ∧ x = djA dest off j ∧ k.2 = bjA aligned (zA nt.val us) j ∧ + (nt.val = 8 ∨ nt.val = 11 ∨ nt.val = 13 ∨ nt.val = 14) ∧ s1aTableRef (capA st q x) = none) := by + have shape : capA st q x ≠ .Null ∧ ∀ a b d e, capA st q x ≠ .Untyped a b d e := by + constructor + · intro e; rw [e] at key; cases key + · intro a b d e eq; rw [eq] at key; cases key + rcases tableCap hx rfl shape.1 shape.2 with old | ⟨j, hj, slotEq, new⟩ + · exact Or.inl old + · rw [new] at key ⊢ + obtain ⟨allowed, base, empty⟩ := newCapA_tableKey hn key + exact Or.inr ⟨j, hj, slotEq, base, allowed, empty⟩ + refine ⟨?_, ?_, ?_, ?_⟩ + · intro x hx y hy k kx ky + rcases classify hx kx with ⟨xo, sx⟩ | ⟨i, hi', _, bi, ai, ei⟩ + · rcases classify hy ky with ⟨yo, sy⟩ | ⟨j, hj, _, bj, aj, _⟩ + · rw [← sx, ← sy] + exact h.capRefs.references x xo y yo k (sx ▸ kx) (sy ▸ ky) + · exact (oldNeNew xo (sx ▸ kx) hj aj bj).elim + · rcases classify hy ky with ⟨yo, sy⟩ | ⟨j, hj, _, bj, aj, ej⟩ + · exact (oldNeNew yo (sy ▸ ky) hi' ai bi).elim + · rw [ei, ej] + · intro x hx y hy k kx ky empty + rcases classify hx kx with ⟨xo, sx⟩ | ⟨i, hi', xi, bi, ai, _⟩ + · rcases classify hy ky with ⟨yo, sy⟩ | ⟨j, hj, _, bj, aj, _⟩ + · exact h.capRefs.unique x xo y yo k (sx ▸ kx) (sy ▸ ky) (sx ▸ empty) + · exact (oldNeNew xo (sx ▸ kx) hj aj bj).elim + · rcases classify hy ky with ⟨yo, sy⟩ | ⟨j, hj, yj, bj, _, _⟩ + · exact (oldNeNew yo (sy ▸ ky) hi' ai bi).elim + · have same := E.baseInj hj hi' (bj.symm.trans bi) + rw [yj, xi, same] + · intro x hx t a cap o bound al + rcases tableCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨xo, before⟩ | ⟨j, hj, _, new⟩ + · have found := (h.nativeRoots x xo t false a before).1 + have word : L.mem q (wa t o) = L.mem s (wa t o) := by + refine keep ⟨t, (h.nativeRoots x xo t false a before).2, o, bound, al, rfl⟩ + ⟨t, .other 12, found, inObjWord E.place.heap found bound, Or.inr ⟨x, xo, ?_⟩⟩ + rw [before] + exact ⟨RngKeyA.pml4 _ _ _, ptrA_pml4 _ _ _⟩ + rw [word] + exact h.capRefs.nativeEmpty x xo t a before o bound al + · obtain ⟨type, rfl, _⟩ := newCapA_pml4 hn new.symm + have creation := E.creation.E + rw [(E.newObj hj (Or.inl type)).1] at creation + refine CrtE.zeroTable creation (Or.inl type) E.creation.A.al (E.creation.A.aw.trans E.creation.A.pf) hj o ?_ al + rw [show (zA nt.val us).val = 12 by rw [type]; simp [zA]] + exact bound + · intro x hx t a cap o bound al + rcases tableCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨xo, before⟩ | ⟨j, hj, _, new⟩ + · rw [rootWords xo before (Or.inr rfl) bound al] + exact h.capRefs.highEmpty x xo t a before o bound al + · obtain ⟨type, base⟩ := newCapA_hv hn new.symm + exact (newInit ⟨type, j, hj, base⟩).2.2 o bound al + have poolCaps : S1aPoolCaps st H' (s1aRtSlots OS1 dev nt us aligned win) (s1aRtPt Pt lo hi aligned nt us win) Pp q := by + refine ⟨?_, ?_, ?_, ?_⟩ + · intro i hi' t word nz + have before := (tab.2 i).symm.trans word + obtain ⟨active, placed, found, x, hx, base, cap, low⟩ := h.poolCaps.present i hi' t before nz + have after := E.old found ⟨x, hx, cap ▸ RngKeyA.ap t base, + by rw [cap, ptrA_ap]; exact ⟨le_rfl, Nat.lt_add_of_pos_right (Nat.two_pow_pos _)⟩⟩ + obtain ⟨member, same⟩ := keepCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) + refine ⟨active, offSub ⟨placed, ?_⟩, after.1, x, member, base, same, low⟩ + have outside := after.2 + change t.val + 4096 ≤ lo ∨ hi ≤ t.val at outside + exact outside + · intro x hx t base cap + rcases tableCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨xo, before⟩ | ⟨j, _, _, new⟩ + · obtain ⟨i, hi', low, nz, word⟩ := h.poolCaps.cap x xo t base before + exact ⟨i, hi', low, nz, (tab.2 i).trans word⟩ + · exact (newCapA_ne_ap hn _ _ _ _ _ new.symm).elim + · intro i j t hi' hj nz wi wj + exact h.poolCaps.index i j t hi' hj nz ((tab.2 i).symm.trans wi) ((tab.2 j).symm.trans wj) + · intro raw entry + exact h.poolCaps.noZero raw ((roots _ _).mp entry) + have stage1 : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ (s1aRtTb Tb Pt lo hi aligned nt us win) + (s1aRtLv Lv aligned nt us win) q := by + refine ⟨?_, ?_, ?_⟩ + · intro o low high al nz + have word : L.mem q (wa (L.ksb s) o) = L.mem s (wa (L.ksb s) o) := by + have same := tab.off low high al + rwa [E.ksb] at same + rw [word] at nz ⊢ + exact h.core.stage1.tbl o low high al nz + · intro t active o bound al nz + rw [poolWords t active o bound al] at nz ⊢ + have old := h.core.stage1.pool t active o bound al nz + refine ⟨fun tag => ?_, fun tag => ?_⟩ + · have reach := VsReach.root0 (Hr := ∅) (Lv := Lv) active bound al nz tag + obtain ⟨member, level⟩ := old.1 tag + exact ⟨tbKeep reach member, (lvReach reach).trans level⟩ + · have reach := VsReach.root2 (Hr := ∅) (Lv := Lv) active bound al tag + obtain ⟨member, level⟩ := old.2 tag + exact ⟨tbKeep reach member, (lvReach reach).trans level⟩ + · intro t member reach level o bound al edge + have before := reach1.mp reach + rw [words1 before o bound al] at edge ⊢ + rw [lvReach before] at level ⊢ + obtain ⟨target, next⟩ := h.core.stage1.desc t (tbOld before member) before level o bound al edge + have step := VsReach.step before level bound al edge + exact ⟨tbKeep step target, (lvReach step).trans next⟩ + have stage2 : S2TyR st n (PoolSet st Pp s) (HvRt st (s1aRtSlots OS1 dev nt us aligned win) q) + (s1aRtTe H' Te bits lo hi) Re bits q := by + refine ⟨?_, ?_, ?_⟩ + · intro t active o bound al nz + rw [poolWords t active o bound al] at nz ⊢ + rcases h.core.stage2.tag t active o bound al nz with ⟨tag, outside⟩ | ⟨tag, held⟩ | ⟨tag, member, level, size⟩ + · refine Or.inl ⟨tag, fun member => ?_⟩ + rcases rootCases member with ⟨y, hy, m, asid, cap⟩ | new + · exact outside (oldRoot hy cap).1 + · have reach := VsReach.root0 (Hr := ∅) (Lv := Lv) active bound al nz tag + exact offNotNew (off1' reach) highKind new + · refine Or.inr (Or.inl ⟨tag, ?_⟩) + rw [h.highRoots] at held + obtain ⟨y, hy, m, asid, cap⟩ := held + obtain ⟨member, same⟩ := keepCap hy cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) + exact ⟨y, member, m, asid, same⟩ + · have reach := S2Reach.root (Re := Re) (bits := bits) active bound al tag + exact Or.inr (Or.inr ⟨tag, teKeep reach member, level, size⟩) + · intro R member + obtain ⟨y, hy, m, asid, cap⟩ := member + exact headers y hy R m asid cap + · intro t member reach level o bound al edge + have before := reach2.mp reach + rw [words2 before o bound al] at edge ⊢ + obtain ⟨target, next⟩ := h.core.stage2.desc t member.1 before level o bound al edge + exact ⟨teKeep (S2Reach.step before level bound al edge) target, next⟩ + have typedHeap : TeH H' (s1aRtTe H' Te bits lo hi) Re bits n := + fun t member => ⟨member.2.1, (h.core.heap t member.1).2⟩ + have routes : S1aRouteFacts st H' (s1aRtSlots OS1 dev nt us aligned win) (s1aRtPt Pt lo hi aligned nt us win) Pp + (s1aRtTb Tb Pt lo hi aligned nt us win) (HvRt st (s1aRtSlots OS1 dev nt us aligned win) q) + (s1aRtTe H' Te bits lo hi) Kt (s1aRtLv Lv aligned nt us win) Re bits n q := + ⟨lookup, rootBacked, typedHeap, exactPaths, capRefs, rootSlots, rfl, highLink, highObj, ept, pageObj, closed⟩ + have ksb : L.ksb q = L.ksb s := E.ksb + exact { + core := ⟨lookup, routes.recoverWalk heap' kinds, rootBacked, + by rw [ksb, pools]; exact stage1, by rw [pools]; exact stage2, typedHeap⟩ + place := by rw [ksb, pools]; exact place + poolCaps := poolCaps + capRefs := capRefs + paths := exactPaths + pageTables := fun y hy t m a v cap => + keptSub (tables.1 y hy t m a v cap) + footprint := footprint + pageObjects := pageObj + nativeRoots := fun x hx t m a cap => by + rcases tableCap hx cap (fun e => by cases e) (fun _ _ _ _ e => by cases e) with ⟨xo, before⟩ | ⟨j, hj, _, new⟩ + · obtain ⟨found, placed⟩ := h.nativeRoots x xo t m a before + have after := E.old found ⟨x, xo, before ▸ RngKeyA.pml4 t m a, + by rw [before, ptrA_pml4]; exact ⟨le_rfl, Nat.lt_add_of_pos_right (Nat.two_pow_pos _)⟩⟩ + have outside := after.2 + change t.val + 4096 ≤ lo ∨ hi ≤ t.val at outside + exact ⟨after.1, offSub ⟨placed, outside⟩⟩ + · obtain ⟨type, rfl, _⟩ := newCapA_pml4 hn new.symm + have fresh : bjA aligned (zA nt.val us) j ∈ s1aNewT aligned nt us win 8 := ⟨type, j, hj, rfl⟩ + obtain ⟨z, _, _, native, found, _⟩ := E.newT (Or.inl rfl) fresh + obtain rfl := native rfl + exact ⟨found, Or.inl (Or.inr fresh)⟩ + eptRoots := ept + highObjects := highObj + highHeaders := headers + highLink := highLink + highRoots := rfl + highFootprint := highGran + kernelTables := ⟨fun t member => by + have outside := (kernelOff member).2 + exact Or.inl ⟨h.kernelTables.1 member, h.place.tables (h.kernelTables.1 member), outside⟩, + fun t member => (kernelOff member).1⟩ + kernelClosed := closed + rootSlots := rootSlots } + +end S1aRtIn + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2RetypeTop.lean b/proofs/Fl4ProofsA64/P1/S1aR2RetypeTop.lean new file mode 100644 index 000000000..dd5a8f353 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2RetypeTop.lean @@ -0,0 +1,87 @@ +/- +P1 (aarch64): full R2 at the concrete Untyped Retype dispatcher, on the returned heap and slots. +Named premises: none new. KTab is the existing architecture premise. +-/ +import Fl4ProofsA64.P1.S1aR2RetypePost +import Fl4ProofsA64.P1.S1aR2Ept +import Fl4ProofsA64.P1.S1aRtV + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {s : S} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} + +/-- Retype keeps the common slot facts and returns R2 and the kernel-table separation over the same +heap and slot set, with the same kernel tables. Reset preemption and rejection are included. -/ +theorem syscall.decode_invocation.untypedExactR2 (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) + {U Ac Sg Scs Vq Uq Vc Ub : Set U64} {Z : U64 → Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Untyped p sb fi dev) 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) + (source : obj.Slot.cap st slot s = ok (.Untyped p sb fi dev)) (masks : A64FrameMasks st s) + (vr : VrOK H.omega Sg Scs Z OS Vq Uq (L.ksb s) Pt) (pools : PoolNamed st OS s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) + (vc : VcCap st Vc OS s) (frame : DevFrAl st OS s) (hi : HiCap511 st OS s) (hks : HeapKsOff H (L.ksb s)) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (sep : S1aKtUt st OS Kt s) + (a : A) (lbl len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Untyped p sb fi dev) blk call don fp buf extra ⦃ _ q _ => + ∃ (H' : Heap) (OS' Vn Vc' Pt' Tb' Te' : Set U64) (Lv' : U64 → Nat), + ArmQIVAt st H Cs OS ia ie s H' OS' Vn q ∧ TabKeep st s q ∧ Vc' ⊆ Vc ∪ Vn ∧ VcCap st Vc' OS' q ∧ + S1aArmCol st H' Cs OS' Vc' Ub q ∧ S1aCapCol st H' OS' Ub q ∧ DevFrAl st OS' q ∧ HiCap511 st OS' q ∧ + S1aR2 st H' OS' Pt' Pp Tb' (HvRt st OS' q) Te' Kt Lv' Re bits n q ∧ S1aKtUt st OS' Kt q ⦄ := by + have R := UtDecP.of_live D B.sys P source B.ln B.vr B.ly + have capSource : capA st s slot = .Untyped p sb fi dev := okinj ((capA_eq s slot).symm.trans source) + have offState : dev = false → + (L.ksb s).val + 788736 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ (L.ksb s).val := fun ram => by + subst ram + exact (R.stz.2.2 slot R.src p sb fi R.cap).2 + unfold syscall.decode_invocation + step with sched.cur_thread.spec as ⟨ct, _⟩ + refine WP.spec_mono (WP.spec_and + (untyped.decode.s1aRtVJH hA D P B Y source masks vr pools C Kc hal vc a lbl len buf + (fun H' O q => + (KindA st O q → FrameOK st H' O q → + (∀ b, VsR (L.ksb s) Pt b → S1aRetypeWordOwner st H OS Kt s b → L.mem q b = L.mem s b) → + TabKeep st s q → + (∀ asid raw, ActiveAsidRoot st Pp q asid raw ↔ ActiveAsidRoot st Pp s asid raw) → + (∀ tag asid sh base t, S1aPath st Pp n q tag asid sh base t ↔ S1aPath st Pp n s tag asid sh base t) → + (∀ x ∈ OS, capA st s x = .Null → + (cdt.ensure_no_children st s slot = ok (.Ok ()) → x.val + 32 ≤ p.val ∨ p.val + 2 ^ sb.val ≤ x.val) → + ∀ t m asid, capA st q x = .HighVSpace t m asid → S1aHighInit st Kt q t) → + HiCap511 st O q → + ∃ (Pt' Tb' Te' : Set U64) (Lv' : U64 → Nat), + S1aR2 st H' O Pt' Pp Tb' (HvRt st O q) Te' Kt Lv' Re bits n q ∧ S1aKtUt st O Kt q) ∧ + (HrW st (HvRt st OS s) s q → HiCap511 st O q) ∧ DevFrAl st O q) + ⟨fun _ _ _ _ _ _ _ _ => ⟨Pt, Tb, Te, Lv, h.highRoots ▸ h, sep⟩, fun _ => hi, frame⟩ ?_) + (WP.spec_and (untyped.decode.keepOwnedVsWords hA D P B source masks vr sep a lbl len buf) + (WP.spec_and (untyped.decode.tabK hA D P B source masks vr a lbl len buf) + (WP.spec_and (untyped.decode.keepActivePaths hA D P B source masks vr h sep a lbl len buf) + (WP.spec_and (untyped.decode.newHighInit hA K D P B source masks a lbl len buf) + (untyped.decode.keepOldHi hA D P B source masks vr h.footprint + (show HvPt st Pt OS s from fun y hy t m asid cap => + h.highFootprint ⟨t, h.highRoots ▸ ⟨y, hy, m, asid, cap⟩, Or.inl rfl⟩) + a lbl len buf)))))) ?_ + · intro H1 H' OS1 s1 q lo hi' aligned nt us dest off win E X window reset init + have rt : S1aRtIn st H Cs OS U Ac s ia ie slot p sb fi dev extra H1 H' OS1 s1 q lo hi' aligned nt us dest off win := + ⟨D, P, B, source, E, X, window, reset⟩ + have ksOff : HeapKsOff H' (L.ksb s) := E.heapKsOff X offState hks + have tables := UtEnd.ptCapHG D P B source E X window reset h.pageTables h.footprint + refine ⟨fun kinds frames words tab roots paths fresh headers => ?_, + fun keep => E.hiCap511 X B.ly.ksw init keep hi, UtEnd.devFrN D P B source E X window frame⟩ + exact ⟨_, _, _, _, rt.r2 h sep words tab roots paths fresh kinds frames headers ksOff tables, + E.s1aKtUt X B.ly.ksw capSource sep⟩ + · rintro ⟨_, q, _⟩ ⟨⟨H', OS', Vn, Vc', ⟨h1, h2, h3, h4, h5, h6⟩, record, finish, devices⟩, + words, writes, ⟨roots, paths⟩, fresh, keep⟩ + have tab : TabKeep st s q := TabKeep.ofW vr writes fun _ h => h + have after : SysL st H' Cs OS' ia ie q := h1.1 + obtain ⟨_, _, _, kinds, _, _⟩ := after.sys.stz.1.1.mdbS + have headers := finish keep + obtain ⟨Pt', Tb', Te', Lv', r2, separate⟩ := + record kinds after.sys.fr words tab roots paths fresh headers + exact ⟨H', OS', Vn, Vc', Pt', Tb', Te', Lv', h1, h2, h3, h4, h5, h6, devices, headers, r2, separate⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2RootInit.lean b/proofs/Fl4ProofsA64/P1/S1aR2RootInit.lean new file mode 100644 index 000000000..a8027574c --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2RootInit.lean @@ -0,0 +1,381 @@ +/- +P1 (aarch64): initialize the root-slot contract at Retype. +Named premises: none. KTab is the existing architecture premise. +-/ +import Fl4ProofsA64.P1.MdbArmVsV +import Fl4ProofsA64.P1.S1aR2Contract +import Fl4ProofsA64.P1.S1aKTab +import Fl4ProofsA64.P1.S1aHiInit + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {A : Type _} {ar : machine.Arch A} + {Kt : Set U64} {KLv : U64 → Nat} + +private theorem rootWordVal {p o : U64} {limit : Nat} (fit : p.val + limit ≤ 2 ^ 64) + (bound : o.val < limit) : (wa p o).val = p.val + o.val := + wadd_val (by omega) + +private theorem rootWordAligned {p o : U64} (base : p.val % 8 = 0) (off : o.val % 8 = 0) : + Aligned (wa p o) := by + unfold Aligned + rw [wa_val] + omega + +private theorem highCopiesWrite {p i word : U64} {s : S} (al : p.val % 8 = 0) + (fit : p.val + 4096 ≤ 2 ^ 64) (bound : i.val < 4096) (iAl : i.val % 8 = 0) + (h : S1aHighCopies st Kt s p) + (copy : i.val < 4088 → word &&& 3#u64 = 3#u64 → + wa (word &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt) : + S1aHighCopies st Kt (L.wr s (wa p i) word) p := by + intro o ob oa edge + have hi := rootWordVal fit bound + have ho := rootWordVal fit (by omega : o.val < 4096) + have wi := rootWordAligned al iAl + by_cases eq : o = i + · subst o + rw [L.mem_wr_same wi] at edge ⊢ + exact copy ob edge + · have ne : (wa p i).val ≠ (wa p o).val := by + rw [hi, ho] + intro same + exact eq (UScalar.eq_of_val_eq (by omega)) + rw [L.mem_wr_ne wi (rootWordAligned al oa) ne] at edge ⊢ + exact h o ob oa edge + +set_option maxHeartbeats 2000000 in +private theorem vspace.initHighCopiesLoop (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) + (s : S) (a : A) {p : U64} (al : p.val % 8 = 0) (fit : p.val + 4096 ≤ 2 ^ 64) + (initial : S1aHighCopies st Kt s p) : + vspace.init_high_vspace_loop st ar s a p 0#u64 ⦃ out => S1aHighCopies st Kt out p ⦄ := by + have last : vspace.HIGH_L0_INDEX.val = 511 := by simp [vspace.HIGH_L0_INDEX] + unfold vspace.init_high_vspace_loop + refine loop.spec_decr_nat (measure := fun x => 511 - x.2.val) + (inv := fun x => x.2.val ≤ 511 ∧ S1aHighCopies st Kt x.1 p) _ _ _ ?_ ⟨by simp, initial⟩ + rintro ⟨q, i⟩ ⟨bound, copies⟩ + simp only at bound copies ⊢ + unfold vspace.init_high_vspace_loop.body + by_cases test : i < vspace.HIGH_L0_INDEX + · rw [if_pos test] + have before : i.val < 511 := by have ht : i.val < vspace.HIGH_L0_INDEX.val := test; omega + refine WP.spec_bind (spec_eqv (hA.kernel_ttbr1_entry a 0#u64 i)) fun word ⟨read, _⟩ => ?_ + refine WP.spec_bind (Pₘ := fun q' => S1aHighCopies st Kt q' p) ?_ fun q' result => ?_ + · split + · obtain ⟨off, eq, val⟩ := spec_exA (U64.mul_spec (x := i) (y := 8#u64) (by scalar_tac)) + rw [eq, bind_ok] + simp only [lift, bind_ok] + refine WP.spec_mono (LawfulStore.write_spec q _ _) fun q'' wr => ?_ + subst q'' + have vo : off.val = i.val * 8 := by simpa using val + exact highCopiesWrite al fit (by omega) (by omega) copies + (fun _ tag => (K.l0 a i word before read tag).1) + · exact (WP.spec_ok _).2 copies + · obtain ⟨next, eq, val⟩ := spec_exA (U64.add_spec (x := i) (y := 1#u64) (by scalar_tac)) + rw [eq, bind_ok, WP.spec_ok] + have vn : next.val = i.val + 1 := by simpa using val + have nextBound : next.val ≤ 511 := by omega + have decrease : 511 - next.val < 511 - i.val := by omega + first | exact ⟨⟨nextBound, result⟩, decrease⟩ | exact ⟨nextBound, result, decrease⟩ + · rw [if_neg test, WP.spec_ok] + exact copies + +set_option maxHeartbeats 2000000 in +/-- The HighVSpace initializer obtains all copied edges from the existing kernel table premise. -/ +theorem vspace.init_high_vspace.copies (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) + (s : S) (a : A) {p : U64} (al : p.val % 8 = 0) (fit : p.val + 4096 ≤ 2 ^ 64) + (zero : S1aRootZero st s p (· < 4088)) : + vspace.init_high_vspace st ar s a p ⦃ out => S1aHighCopies st Kt out.1 p ⦄ := by + have initial : S1aHighCopies st Kt s p := by + intro o ho h8 edge + rw [zero o ho h8] at edge + cases edge + unfold vspace.init_high_vspace + simp only [lift, bind_ok] + refine WP.spec_bind (vspace.initHighCopiesLoop hA K s a al fit initial) fun q copies => ?_ + have last : vspace.HIGH_L0_INDEX.val = 511 := by simp [vspace.HIGH_L0_INDEX] + obtain ⟨idx, eq, val⟩ := spec_exA (U64.mul_spec (x := vspace.HIGH_L0_INDEX) (y := 8#u64) + (by rw [last]; scalar_tac)) + have index : idx = 4088#u64 := UScalar.eq_of_val_eq (by simp only [val, last]; decide) + rw [eq, index, bind_ok] + try simp only [lift, bind_ok] + refine WP.spec_bind (P0.layout.paddr.p0 _) fun _ _ => ?_ + rw [eq_of_spec_fd P0.Consts.vspace.D_PXN_TABLE.spec, bind_ok, + eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, bind_ok, eq_of_spec_fd P0.Consts.vspace.D_TABLE_OR_PAGE.spec] + simp only [lift, bind_ok] + refine WP.spec_bind (LawfulStore.write_spec q _ _) fun _ wr => ?_ + subst wr + exact (WP.spec_ok _).2 (highCopiesWrite (i := 4088#u64) al fit (by decide) (by decide) copies + (fun outside _ => (by decide : ¬ (4088#u64 : U64).val < 4088) outside |>.elim)) + +private theorem highPrivateWord {p o : U64} (fit : p.val + 8192 ≤ 2 ^ 64) (bound : o.val < 4096) : + (wa (wa p 4096#u64) o).val = p.val + 4096 + o.val := by + have off : (4096#u64 : U64).val = 4096 := rfl + have part := rootWordVal fit (by decide : (4096#u64 : U64).val < 8192) + rw [rootWordVal (limit := 4096) (by rw [part, off]; omega) bound, part, off] + +private theorem highPrivateAddress {p : U64} (canon : CapRt.Canonical p) + (al : p.val % 8192 = 0) (fits : p.val + 8192 ≤ 2 ^ 64) : + CapRt.Canonical (wa p 4096#u64) ∧ (wa p 4096#u64).val % 4096 = 0 := by + have value : (wa p 4096#u64).val = p.val + 4096 := + rootWordVal (limit := 8192) fits (by decide) + exact ⟨canon_reg (sb := 13) canon al (by decide) (by omega) (by omega), by omega⟩ + +private theorem highPrivateDescriptor {p : U64} (canon : CapRt.Canonical p) (al : p.val % 4096 = 0) : + wa ((((ws p layout.PPTR_BASE &&& vspace.ADDR_MASK) ||| 576460752303423488#u64 ||| 1#u64 ||| 2#u64) + &&& vspace.ADDR_MASK)) layout.PPTR_BASE = p := by + have address := paddr_andM canon al + rw [address] + have masked : ((ws p layout.PPTR_BASE ||| 576460752303423488#u64 ||| 1#u64 ||| 2#u64) &&& vspace.ADDR_MASK) = + ws p layout.PPTR_BASE := by + apply UScalar.eq_of_val_eq + simp only [UScalar.val_and, UScalar.val_or, vspace.ADDR_MASK.val_eq] + let physical := (ws p layout.PPTR_BASE).val + change ((physical ||| 576460752303423488 ||| 1 ||| 2) &&& 281474976706560) = physical + rw [nat_or_offM (physical ||| 576460752303423488 ||| 1) (c := 2) (by decide), + nat_or_offM (physical ||| 576460752303423488) (c := 1) (by decide), + nat_or_offM physical (c := 576460752303423488) (by decide)] + simpa only [UScalar.val_and, vspace.ADDR_MASK.val_eq] using congrArg UScalar.val address + rw [masked, UScalar.eq_equiv_bv_eq] + simp [core.num.U64.wrapping_add_bv_eq, core.num.U64.wrapping_sub_bv_eq] + +/-- The initializer links entry 511 to the root's own private second granule. -/ +theorem vspace.init_high_vspace.privateLink (hA : P0.ArchTotal ar) (s : S) (a : A) {p : U64} + (canon : CapRt.Canonical p) (al : p.val % 8192 = 0) (fit : p.val + 8192 ≤ 2 ^ 64) : + vspace.init_high_vspace st ar s a p ⦃ out => + wa (L.mem out.1 (wa p 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE = wa p 4096#u64 ⦄ := by + have pAligned : p.val % 8 = 0 := by omega + have ⟨l1Canon, l1Aligned⟩ := highPrivateAddress canon al fit + unfold vspace.init_high_vspace + simp only [lift, bind_ok] + refine WP.spec_bind (vspace.init_high_vspace_loop.win hA s a pAligned (by omega)) fun q _ => ?_ + have last : vspace.HIGH_L0_INDEX.val = 511 := by simp [vspace.HIGH_L0_INDEX] + obtain ⟨idx, eq, val⟩ := spec_exA (U64.mul_spec (x := vspace.HIGH_L0_INDEX) (y := 8#u64) + (by rw [last]; scalar_tac)) + have index : idx = 4088#u64 := UScalar.eq_of_val_eq (by simp only [val, last]; decide) + rw [eq, index, bind_ok] + try simp only [lift, bind_ok] + refine WP.spec_bind (paddr_spec _) fun physical value => ?_ + subst value + rw [eq_of_spec_fd P0.Consts.vspace.D_PXN_TABLE.spec, bind_ok, + eq_of_spec_fd P0.Consts.vspace.D_VALID.spec, bind_ok, eq_of_spec_fd P0.Consts.vspace.D_TABLE_OR_PAGE.spec] + simp only [lift, bind_ok] + refine WP.spec_bind (LawfulStore.write_spec q _ _) fun _ wr => ?_ + subst wr + exact (WP.spec_ok _).2 (by + rw [L.mem_wr_same (rootWordAligned pAligned (by decide))] + exact highPrivateDescriptor l1Canon l1Aligned) + +/-- The initializer frames the entire private granule, including the user slots. -/ +theorem vspace.init_high_vspace.privateEmpty (hA : P0.ArchTotal ar) (s : S) (a : A) {p : U64} + (al : p.val % 8 = 0) (fit : p.val + 8192 ≤ 2 ^ 64) + (empty : S1aRootZero st s (wa p 4096#u64) (· < 4096)) : + vspace.init_high_vspace st ar s a p ⦃ out => + S1aRootZero st out.1 (wa p 4096#u64) (· < 4096) ⦄ := by + refine WP.spec_mono (vspace.init_high_vspace.win hA s a al (by omega)) fun _ writes o bound oa => ?_ + have address := highPrivateWord fit bound + exact (writes.mem_eq (by unfold Aligned; rw [address]; omega) (by simp only [InWin, address]; omega)).trans + (empty o bound oa) + +/-- A newly initialized HighVSpace root: copied kernel edges, the private link and an empty private granule. -/ +def S1aHighInit (st : machine.Store S) [L : LawfulStore st] (Kt : Set U64) (s : S) (p : U64) : Prop := + S1aHighCopies st Kt s p ∧ + wa (L.mem s (wa p 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE = wa p 4096#u64 ∧ + S1aRootZero st s (wa p 4096#u64) (· < 4096) + +/-- The HighVSpace initializer establishes all three clauses on a zeroed, aligned root. -/ +theorem vspace.init_high_vspace.rootSlots (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) + (s : S) (a : A) {p : U64} (canon : CapRt.Canonical p) (al : p.val % 8192 = 0) (fit : p.val + 8192 ≤ 2 ^ 64) + (header : S1aRootZero st s p (· < 4088)) + (privateZero : S1aRootZero st s (wa p 4096#u64) (· < 4096)) : + vspace.init_high_vspace st ar s a p ⦃ out => S1aHighInit st Kt out.1 p ⦄ := + WP.spec_and (vspace.init_high_vspace.copies hA K s a (by omega) (by omega) header) + (WP.spec_and (vspace.init_high_vspace.privateLink hA s a canon al fit) + (vspace.init_high_vspace.privateEmpty hA s a (by omega) fit privateZero)) + +set_option maxHeartbeats 2000000 in +/-- The type-14 initializer establishes `S1aHighInit`. -/ +theorem create_object.highRootSlots (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) + (s : S) (a : A) (nt p us : U64) (high : nt.val = 14) (canon : CapRt.Canonical p) + (al : p.val % 8192 = 0) (fit : p.val + 8192 ≤ 2 ^ 64) + (header : S1aRootZero st s p (· < 4088)) + (privateZero : S1aRootZero st s (wa p 4096#u64) (· < 4096)) : + objects.create_object st ar s a nt p us false ⦃ out => S1aHighInit st Kt out.2.1 p ⦄ := by + obtain rfl : nt = 14#u64 := UScalar.eq_of_val_eq (by simp [high]) + unfold objects.create_object objects.create_arch_object + simp (config := { decide := true }) only [fl4_abi.consts.object.Tcb, fl4_abi.consts.object.Endpoint, + fl4_abi.consts.object.Notification, fl4_abi.consts.object.CapTable, fl4_abi.consts.object.Untyped, + fl4_abi.consts.object.SchedContext, fl4_abi.consts.object.Reply, fl4_abi.consts.object.ArmPageTable, + fl4_abi.consts.object.ArmVSpace, fl4_abi.consts.object.ArmVcpu, fl4_abi.consts.object.ArmStage2VSpace, + fl4_abi.consts.object.ArmHighVSpace, ↓reduceIte, ite_true, ite_false] + refine WP.spec_bind (vspace.init_high_vspace.rootSlots hA K s a canon al fit header privateZero) ?_ + rintro ⟨q, a'⟩ h + exact (WP.spec_ok _).2 h + +private theorem highSlotsCongr {s q : S} {p : U64} + (keep : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem q (wa p o) = L.mem s (wa p o)) + (keepPrivate : ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem q (wa (wa p 4096#u64) o) = L.mem s (wa (wa p 4096#u64) o)) + (h : S1aHighInit st Kt s p) : S1aHighInit st Kt q p := by + refine ⟨fun o bound al edge => ?_, ?_, fun o bound al => (keepPrivate o bound al).trans (h.2.2 o bound al)⟩ + · rw [keep o (by omega) al] at edge ⊢ + exact h.1 o bound al edge + · rw [keep 4088#u64 (by decide) (by decide)] + exact h.2.1 + +/-- The initialized HighVSpace objects of the first `j` batch positions. -/ +def S1aHighBatch (st : machine.Store S) [L : LawfulStore st] (Kt : Set U64) + (s : S) (base size : U64) (j : Nat) : Prop := + ∀ i < j, S1aHighInit st Kt s (bjA base size i) + +private theorem highBatchAddr {base size : U64} {count n : Nat} (hsize : size.val = 13) + (bound : n < count) (al : base.val % 8 = 0) + (fit : base.val + count * 2 ^ size.val ≤ 2 ^ 64) : + (bjA base size n).val = base.val + n * 8192 ∧ + (bjA base size n).val % 8 = 0 ∧ (bjA base size n).val + 8192 ≤ 2 ^ 64 := by + obtain ⟨hv, ha, hwin⟩ := bj_win (z := size) bound fit al (by omega) + rw [hsize] at hv hwin fit + exact ⟨hv, ha, by omega⟩ + +private theorem create_object.highBatch (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) + {H1 : Heap} {s0 s : S} {a : A} {base nt us : U64} {j count : Nat} + (high : nt.val = 14) (hi : j < count) (al : base.val % 8 = 0) + (full : base.val % 8192 = 0) (canon : CapRt.Canonical (bjA base (zA nt.val us) j)) + (fit : base.val + count * 2 ^ (zA nt.val us).val ≤ 2 ^ 64) + (zero : ZTc st H1 s0 base (zA nt.val us) count s j) + (done : S1aHighBatch st Kt s base (zA nt.val us) j) : + objects.create_object st ar s a nt (bjA base (zA nt.val us) j) us false ⦃ out => + S1aHighBatch st Kt out.2.1 base (zA nt.val us) (j + 1) ⦄ := by + have size : (zA nt.val us).val = 13 := by rw [high, zA_14] + obtain ⟨hv, ha, hf⟩ := highBatchAddr size hi al fit + have upper : (j + 1) * 8192 ≤ count * 8192 := Nat.mul_le_mul_right _ (by omega) + have empty : ∀ b : U64, Aligned b → base.val + j * 8192 ≤ b.val → + b.val < base.val + count * 8192 → L.mem s b = 0#u64 := by + simpa only [size, show (2 : Nat) ^ 13 = 8192 by decide] using zero.2.1 + have aligned : (bjA base (zA nt.val us) j).val % 8192 = 0 := by rw [hv]; omega + refine WP.spec_mono (WP.spec_and (create_object.highRootSlots hA K s a nt _ us high canon aligned hf ?_ ?_) + (create_object.highW hA s a nt _ us false high ha (by omega))) ?_ + · intro o lim oa + have v := rootWordVal hf (by omega : o.val < 8192) + exact empty _ (rootWordAligned ha oa) (by rw [v, hv]; omega) (by rw [v, hv]; omega) + · intro o offBound oa + have v := highPrivateWord hf offBound + exact empty _ (by unfold Aligned; rw [v]; omega) (by rw [v, hv]; omega) (by rw [v, hv]; omega) + · rintro out ⟨current, _, framed⟩ i hi' + by_cases eq : i = j + · subst i + exact current + · have lt : i < j := by omega + obtain ⟨v, ai, fi⟩ := highBatchAddr size (lt_trans lt hi) al fit + refine highSlotsCongr ?_ ?_ (done i lt) + · intro o lim oa + have b := rootWordVal fi (by omega : o.val < 8192) + exact framed.mem_eq (rootWordAligned ai oa) (by simp only [InWin, b, hv, v]; omega) + · intro o offBound oa + have b := highPrivateWord fi offBound + exact framed.mem_eq (by unfold Aligned; rw [b]; omega) (by simp only [InWin, b, hv, v]; omega) + +private theorem highSlotsInWin {s q : S} {p : U64} (al : p.val % 8 = 0) + (fit : p.val + 8192 ≤ 2 ^ 64) + (keep : ∀ b : U64, Aligned b → InWin p 8192 b → L.mem q b = L.mem s b) + (old : S1aHighInit st Kt s p) : S1aHighInit st Kt q p := by + refine highSlotsCongr ?_ ?_ old + · intro o bound oa + have v := rootWordVal fit (by omega : o.val < 8192) + exact keep _ (rootWordAligned al oa) (by unfold InWin; rw [v]; omega) + · intro o offBound oa + have v := highPrivateWord fit offBound + exact keep _ (by unfold Aligned; rw [v]; omega) (by unfold InWin; rw [v]; omega) + +set_option maxRecDepth 4000 in +set_option maxHeartbeats 2000000 in +/-- The RAM Retype loop produces the HighVSpace slot facts at every new batch position. -/ +theorem untyped.retype.highRootSlots (hA : P0.ArchTotal ar) (K : KTab ar Kt KLv) + {H1 : Heap} {Cs Sg OS : Set U64} {s : S} {slot p sb fi base nt us dest off win : U64} + (C : CrtP st H1 Cs Sg OS s slot p sb fi false base nt us dest off win) (high : nt.val = 14) + (full : base.val % 2 ^ (zA nt.val us).val = 0) (a : A) : + untyped.retype st ar s a slot false base nt us dest off win false ⦃ out => + S1aHighBatch st Kt out.2.1 base (zA nt.val us) win.val ⦄ := by + obtain ⟨_, al, hfi, lower, upper, injective, canonical, _⟩ := C.ar + obtain ⟨⟨live, _, ut, UZ, _⟩, _, hks⟩ := C.stz + obtain ⟨G, par, mdb, _, _, null, _, tree, unique⟩ := live + have T : TreeA st OS G par s := ⟨mdb, tree, unique⟩ + have headAl := nodeAt_aligned C.n0 (by rw [debug_val] <;> omega) (by rw [debug_val] <;> omega) + have headOff := KsOffA.node hks C.core0 C.n0 (by rw [debug_val]; omega) + obtain ⟨_, _, fi'⟩ := ut_rangeA (capA_ut_b C.cap) (by + have h := T.ut.reg slot C.src (by rw [C.cap]; exact physA_ut _ _ _ _) + rwa [C.cap] at h) + have fit := upper.trans fi' + have size : (zA nt.val us).val = 13 := by rw [high, zA_14] + have wide : base.val % 8192 = 0 := by simpa only [size, show (2 : Nat) ^ 13 = 8192 by decide] using full + refine WP.spec_mono (untyped.retype.lvRG hA C.heap C.os T null ut UZ a C.src C.cap nt us dest off win base + false rfl C.hn C.hz al hfi lower upper headAl C.nc headOff C.hd C.dO C.dn C.dc injective canonical C.hus + (Z2 := fun q j => j ≤ win.val ∧ S1aHighBatch st Kt q base (zA nt.val us) j) ?_ ?_ ?_) fun _ h => h.2.2.2.2 + · intro q a' j hj zero _ inv + exact WP.spec_mono (create_object.highBatch hA K high hj al wide (canonical _ hj) fit zero inv.2) fun _ fresh => + ⟨by omega, fresh⟩ + · rintro q q' j ⟨count, batch⟩ writes + refine ⟨count, ?_⟩ + intro i hi + have lt := lt_of_lt_of_le hi count + obtain ⟨pos, ia, fi⟩ := highBatchAddr size lt al fit + have inBatch : (i + 1) * 8192 ≤ win.val * 8192 := Nat.mul_le_mul_right _ (by omega) + rw [size] at upper + norm_num at upper + refine highSlotsInWin ia fi ?_ (batch i hi) + intro b aligned inside + change (bjA base (zA nt.val us) i).val ≤ b.val ∧ + b.val < (bjA base (zA nt.val us) i).val + 8192 at inside + rw [pos] at inside + exact writes.mem_eq aligned (in_free_not_capw C.heap ut C.src C.cap (by omega) (by omega)) + · exact fun _ _ => ⟨Nat.zero_le _, fun _ hi => (Nat.not_lt_zero _ hi).elim⟩ + +section zeroBatch +variable {H1 : Heap} {Sg OS : Set U64} {s q : S} + {slot p sb base nt us dest off win : U64} {i : Nat} + +private theorem CrtE.zeroRootWord (E : CrtE st H1 Sg OS s q slot p sb false base nt us dest off win) + (nw : ¬ WKA nt) (al : base.val % 8 = 0) + (fit : base.val + win.val * 2 ^ (zA nt.val us).val ≤ 2 ^ 64) + (hi : i < win.val) (sizes : 3 ≤ (zA nt.val us).val) {o : U64} + (bound : o.val < 2 ^ (zA nt.val us).val) (oa : o.val % 8 = 0) : + L.mem q (wa (bjA base (zA nt.val us) i) o) = 0#u64 := by + obtain ⟨pos, ia, winEnd⟩ := bj_win (z := zA nt.val us) hi fit al sizes + have objectFits : (bjA base (zA nt.val us) i).val + 2 ^ (zA nt.val us).val ≤ 2 ^ 64 := winEnd.trans fit + have word := rootWordVal objectFits bound + exact E.zero rfl nw _ (rootWordAligned ia oa) (by rw [word, pos]; omega) (by rw [word]; omega) + +/-- A new ordinary table or root that writes no descriptors stays zero throughout its allocation. -/ +theorem CrtE.zeroTable (E : CrtE st H1 Sg OS s q slot p sb false base nt us dest off win) + (kind : nt.val = 8 ∨ nt.val = 11 ∨ nt.val = 13) (al : base.val % 8 = 0) + (fit : base.val + win.val * 2 ^ (zA nt.val us).val ≤ 2 ^ 64) (hi : i < win.val) : + S1aRootZero st q (bjA base (zA nt.val us) i) (· < 2 ^ (zA nt.val us).val) := by + have noWrites : ¬ WKA nt := by rcases kind with h | h | h <;> simp [WKA, h] + have size : 3 ≤ (zA nt.val us).val := by rcases kind with h | h | h <;> simp [zA, h] + exact fun _ bound aligned => E.zeroRootWord noWrites al fit hi size bound aligned + +/-- Retype's native root words are zero, including the upper half. -/ +theorem CrtE.nativeRootSlots (E : CrtE st H1 Sg OS s q slot p sb false base nt us dest off win) + (nt8 : nt.val = 8) (al : base.val % 8 = 0) + (fit : base.val + win.val * 2 ^ (zA nt.val us).val ≤ 2 ^ 64) (hi : i < win.val) : + S1aRootZero st q (bjA base (zA nt.val us) i) (fun o => 2048 ≤ o ∧ o < 4096) := by + have size : (zA nt.val us).val = 12 := by rw [nt8]; simp [zA] + exact fun _ bound oa => E.zeroRootWord (by simp [WKA, nt8]) al fit hi (by omega) (by simpa [size] using bound.2) oa + +/-- Retype's Stage-2 root words are zero throughout the full allocation. -/ +theorem CrtE.stage2RootSlots (E : CrtE st H1 Sg OS s q slot p sb false base nt us dest off win) + (nt13 : nt.val = 13) (al : base.val % 8 = 0) + (fit : base.val + win.val * 2 ^ (zA nt.val us).val ≤ 2 ^ 64) (hi : i < win.val) (n : U64) : + S1aRootZero st q (bjA base (zA nt.val us) i) + (fun o => s1aTableWidth 1#u64 n (s1aTopShift 1#u64 n) ≤ o ∧ o < 8192) := by + have size : (zA nt.val us).val = 13 := by rw [nt13]; simp [zA] + exact fun _ bound oa => E.zeroRootWord (by simp [WKA, nt13]) al fit hi (by omega) (by simpa [size] using bound.2) oa + +end zeroBatch + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Shrink.lean b/proofs/Fl4ProofsA64/P1/S1aR2Shrink.lean new file mode 100644 index 000000000..cef2fc5d8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Shrink.lean @@ -0,0 +1,421 @@ +/- +P1 (aarch64, A64-S1A): Active reachability through zeroing and ASID-pool detachment. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Ept +import Fl4ProofsA64.P1.S1aHiCap +import Fl4ProofsA64.P1.MdbPoolN +import Fl4ProofsA64.P1.QueueUnmR + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS Pt Pp Pp' Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s s' : S} + +local notation "wa" => core.num.U64.wrapping_add + +theorem VsReach.poolMono {t : U64} (h : VsReach st Pp Hr Lv s t) (sub : Pp ⊆ Pp') : + VsReach st Pp' Hr Lv s t := by + induction h with + | hr live => exact .hr live + | root0 pool within aligned nz tag => exact .root0 (sub pool) within aligned nz tag + | root2 pool within aligned tag => exact .root2 (sub pool) within aligned tag + | step _ level within aligned tag ih => exact .step ih level within aligned tag + +theorem S2Reach.poolMono {t : U64} (h : S2Reach st Pp Re bits s t) (sub : Pp ⊆ Pp') : + S2Reach st Pp' Re bits s t := by + induction h with + | root pool within aligned tag => exact .root (sub pool) within aligned tag + | step _ level within aligned tag ih => exact .step ih level within aligned tag + +/-- Clearing descriptors and detaching ASID pools only removes Stage-1 walks. -/ +theorem VsReach.activeZero {t : U64} (h : VsReach st (PoolSet st Pp s') ∅ Lv s' t) + (ty : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ Tb Lv s) + (pools : Pp ⊆ Pt) (tables : Tb ⊆ Pt) + (tab : TabKeepOrZero st s s') (z : VsZ st (L.ksb s) Pt s s') : + VsReach st (PoolSet st Pp s) ∅ Lv s t := + VsReach.vsz (fun p (hp : p ∈ PoolSet st Pp s) => pools hp.1) tables (by simp) ty z (h.poolMono tab.poolSet) + +/-- Clearing descriptors and detaching ASID pools only removes Stage-2 walks. -/ +theorem S2Reach.activeZero {t : U64} (h : S2Reach st (PoolSet st Pp s') Re bits s' t) + (ty : S2TyR st n (PoolSet st Pp s) Hr Te Re bits s) + (pools : Pp ⊆ Pt) (tables : Gran Te bits ⊆ Pt) (placement : S2OK Te bits Hr) + (tab : TabKeepOrZero st s s') (z : VsZ st (L.ksb s) Pt s s') : + S2Reach st (PoolSet st Pp s) Re bits s t := + S2Reach.vsz (fun p (hp : p ∈ PoolSet st Pp s) => pools hp.1) tables placement ty z (h.poolMono tab.poolSet) + +/-- A surviving Stage-1 descriptor names the same child at the same word. -/ +theorem VsNm.activeZero {t b : U64} (h : VsNm st (PoolSet st Pp s') ∅ Lv s' t b) + (ty : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ Tb Lv s) + (pools : Pp ⊆ Pt) (tables : Tb ⊆ Pt) + (tab : TabKeepOrZero st s s') (z : VsZ st (L.ksb s) Pt s s') : + VsNm st (PoolSet st Pp s) ∅ Lv s t b ∧ L.mem s' b = L.mem s b := by + obtain ⟨p, o, root, level, within, al, e, desc, target⟩ := h + exact VsNm.vsz (fun p (hp : p ∈ PoolSet st Pp s) => pools hp.1) tables (by simp) ty z + ⟨p, o, root.poolMono tab.poolSet, level, within, al, e, desc, target⟩ + +/-- A surviving Stage-2 descriptor names the same child at the same word. -/ +theorem S2Nm.activeZero {t b : U64} (h : S2Nm st (PoolSet st Pp s') Re bits s' t b) + (ty : S2TyR st n (PoolSet st Pp s) Hr Te Re bits s) + (pools : Pp ⊆ Pt) (tables : Gran Te bits ⊆ Pt) (placement : S2OK Te bits Hr) + (tab : TabKeepOrZero st s s') (z : VsZ st (L.ksb s) Pt s s') : + S2Nm st (PoolSet st Pp s) Re bits s t b ∧ L.mem s' b = L.mem s b := by + obtain ⟨p, o, root, level, within, al, e, desc, target⟩ := h + exact S2Nm.vsz (fun p (hp : p ∈ PoolSet st Pp s) => pools hp.1) tables placement ty z + ⟨p, o, root.poolMono tab.poolSet, level, within, al, e, desc, target⟩ + +/-- The active Stage-1 typing is closed under zeroing words and detaching ASID pools. -/ +theorem VsTyR.activeZero (h : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ Tb Lv s) + (pools : Pp ⊆ Pt) (tables : Tb ⊆ Pt) (tab : TabKeepOrZero st s s') + (z : VsZ st (L.ksb s) Pt s s') : VsTyR st (L.ksb s') (PoolSet st Pp s') ∅ Tb Lv s' := by + have sub := tab.poolSet (Pp := Pp) + have keep := h.keepZ (fun p (hp : p ∈ PoolSet st Pp s) => pools hp.1) tables (by simp) z + refine ⟨?_, fun p hp => keep.pool p (sub hp), fun p hp hr => keep.desc p hp (hr.poolMono sub)⟩ + intro o lo hi al nz + refine ⟨?_, o, lo, hi, al, rfl, nz⟩ + have nz' : L.mem s' (wa (L.ksb s) o) ≠ 0#u64 := by rwa [← tab.1] + rw [tab.1] + exact (keep.tbl o lo hi al nz').1 + +/-- The active Stage-2 typing survives zeroing and ASID-pool detachment when the +reserved words of the live HighVSpace roots are kept. -/ +theorem S2TyR.activeZero (h : S2TyR st n (PoolSet st Pp s) Hr Te Re bits s) + (pools : Pp ⊆ Pt) (tables : Gran Te bits ⊆ Pt) (placement : S2OK Te bits Hr) + (tab : TabKeepOrZero st s s') (z : VsZ st (L.ksb s) Pt s s') (hdr : HrW st Hr s s') : + S2TyR st n (PoolSet st Pp s') Hr Te Re bits s' := by + have sub := tab.poolSet (Pp := Pp) + have keep := h.keep (fun p (hp : p ∈ PoolSet st Pp s) => pools hp.1) tables placement z hdr + exact ⟨fun p hp => keep.tag p (sub hp), keep.hi, fun p hp hr => keep.desc p hp (hr.poolMono sub)⟩ + + +/-- Clearing pool or ASID-table words preserves the absence of a root alias. -/ +theorem NoRoot.activeZero {ptr : U64} (h : NoRoot st (PoolSet st Pp s) ∅ s ptr) + (pools : Pp ⊆ Pt) (tab : TabKeepOrZero st s s') (z : VsZ st (L.ksb s) Pt s s') : + NoRoot st (PoolSet st Pp s') ∅ s' ptr := by + have old := NoRoot.vsz (fun p (hp : p ∈ PoolSet st Pp s) => pools hp.1) h z + exact ⟨old.1, fun p hp => old.2 p (tab.poolSet hp)⟩ + + +/-- A table with no ASID root entry and no active parent is unreachable in Stage 1. -/ +theorem VsReach.falseOfNoParent {ptr : U64} (root : NoRoot st (PoolSet st Pp s) ∅ s ptr) + (parent : ¬ ∃ b, VsNm st (PoolSet st Pp s) ∅ Lv s ptr b) + (reach : VsReach st (PoolSet st Pp s) ∅ Lv s ptr) : False := by + cases reach with + | hr member => exact root.1 member + | @root0 p o pool width align nz tag => + exact (root.2 p pool o width align nz).1 tag rfl + | @root2 p o pool width align tag => + have nz : L.mem s (wa p o) ≠ 0#u64 := fun e => by rw [e] at tag; contradiction + exact (root.2 p pool o width align nz).2 (by rw [tag]; decide) rfl + | @step p o prev level width align tag => + exact parent ⟨wa p o, p, o, prev, level, width, align, rfl, tag, rfl⟩ + +/-- A table with no ASID root entry and no active parent is unreachable in Stage 2. -/ +theorem S2Reach.falseOfNoParent {ptr : U64} (root : NoRoot st (PoolSet st Pp s) ∅ s ptr) + (parent : ¬ ∃ b, S2Nm st (PoolSet st Pp s) Re bits s ptr b) + (reach : S2Reach st (PoolSet st Pp s) Re bits s ptr) : False := by + cases reach with + | @root p o pool width align tag => + have nz : L.mem s (wa p o) ≠ 0#u64 := fun e => by rw [e] at tag; contradiction + exact (root.2 p pool o width align nz).2 (by rw [tag]; decide) rfl + | @step p o prev level width align tag => + exact parent ⟨wa p o, p, o, prev, level, width, align, rfl, tag, rfl⟩ + +/-- Root agreement survives removal of ASID entries when the cap slots are fixed. -/ +theorem RootAgreement.activeZero (h : RootAgreement st OS Pp s) (pools : Pp ⊆ Pt) + (tab : TabKeepOrZero st s s') (z : VsZ st (L.ksb s) Pt s s') + (caps : ∀ x ∈ OS, capA st s' x = capA st s x) : + RootAgreement st OS Pp s' := + h.keep tab caps (fun p hp o ho h8 => z _ (Or.inl ⟨p, pools hp.1, o, ho, h8, rfl⟩)) + +/-- Clearing active descriptors with fixed caps preserves cap backing, heap +typing and zeroed unmapped objects. -/ +theorem VsLk.activeZero (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (tab : TabKeepOrZero st s s') (z : VsZ st (L.ksb s) Pt s s') + (caps : ∀ x ∈ OS, capA st s' x = capA st s x) + (unmapped : UnmZ st OS Pt (S2Rt st (PoolSet st Pp s) Te Re bits s) bits s) : + VsLk st H OS Pp Tb Te Kt Lv Re bits s' := by + have old1 (t : U64) (r : VsReach st (PoolSet st Pp s') ∅ Lv s' t) := + r.activeZero h.stage1 place.pools place.tables tab z + have old2 (t : U64) (r : S2Reach st (PoolSet st Pp s') Re bits s' t) := + r.activeZero h.stage2 place.pools place.granules place.stage2 tab z + refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ + · intro t r ht hk + obtain ⟨x, hx, cap⟩ := h.lookup.bk1 t (old1 t r) ht hk + exact ⟨x, hx, (caps x hx).symm ▸ cap⟩ + · intro t r ht + obtain ⟨x, hx, cap⟩ := h.lookup.bk2 t (old2 t r) ht + exact ⟨x, hx, (caps x hx).symm ▸ cap⟩ + · intro t ht x hx + rw [caps x hx] + exact h.lookup.kt t ht x hx + · intro x hx y hy p size hu + rw [caps x hx] at hu + rw [caps y hy] + exact h.lookup.ex x hx y hy p size hu + · intro x hx p size hu o ho h8 + rw [caps x hx] at hu + obtain ⟨word, _, zero⟩ := unmapped.words (kb := L.ksb s) hx hu.toSlot ho h8 + exact (z _ word).elim (·.trans zero) id + · refine ⟨?_, ?_, fun t r ht => h.lookup.vh.2.2 t (old2 t r) ht⟩ + · intro x hx p size hu + rw [caps x hx] at hu + exact h.lookup.vh.1 x hx p size hu + · intro t r ht hk + rcases h.lookup.vh.2.1 t (old1 t r) ht hk with obj | ⟨R, obj, granule, x, hx, asid, cap⟩ + · exact Or.inl obj + · exact Or.inr ⟨R, obj, granule, x, hx, asid, (caps x hx).trans cap⟩ + +/-- Every nonzero word in an active pool is selected by an exact ASID. -/ +theorem ActiveAsidRoot.forWord {pool o : U64} (hp : pool ∈ PoolSet st Pp s) + (ho : o.val < 4096) (aligned : o.val % 8 = 0) (nz : L.mem s (wa pool o) ≠ 0#u64) : + ∃ asid, ActiveAsidRoot st Pp s asid (L.mem s (wa pool o)) := by + have active := hp + obtain ⟨_, off, lo, hi, al, entry, _⟩ := hp + obtain ⟨j, ej⟩ := atOff_of_off lo hi al + let idx : U64 := j &&& 127#u64 + have idxBound : idx.val < 128 := by + change (j &&& 127#u64).val < 128 + rw [UScalar.val_and] + exact Nat.lt_of_le_of_lt Nat.and_le_right (by decide) + let asid : U64 := ⟨BitVec.ofNat 64 (idx.val * 512 + o.val / 8)⟩ + have asidVal : asid.val = idx.val * 512 + o.val / 8 := by + change (BitVec.ofNat 64 _).toNat = _ + simp only [BitVec.toNat_ofNat] + omega + exact ⟨asid, idx, o, idxBound, ho, aligned, asidVal, pool, active, + by rw [show AtOff idx = off from (AtOff.mask j).trans ej]; exact entry, rfl, nz⟩ + +theorem maskedRoot {raw : U64} (tag : (raw &&& 3#u64) = 0#u64) : + raw &&& ~~~3#u64 = raw := by + apply UScalar.eq_of_val_eq + have e := congrArg UScalar.bv tag + change raw.bv &&& (3#64) = 0#64 at e + change (raw.bv &&& ~~~3#64).toNat = raw.bv.toNat + congr 1 + calc + raw.bv &&& ~~~3#64 = (raw.bv &&& 3#64) ||| (raw.bv &&& ~~~3#64) := by rw [e, BitVec.zero_or] + _ = raw.bv := by rw [← BitVec.and_or_distrib_left, BitVec.or_not_self, BitVec.and_allOnes] + +private theorem MappedAsidRoot.kindFacts {c : capability.Cap} {p a tag : U64} + (h : MappedAsidRoot c p a tag) : RngKeyA c ∧ ptrA c = p ∧ kindA c ≠ 14 := by + rcases h with ⟨_, rfl⟩ | ⟨_, va, rfl⟩ | ⟨_, rfl⟩ + · have phys := physA_eq (.Pml4 p true a) + have ptr := ptrA_eq (.Pml4 p true a) + simp only [objects.cap_is_physical] at phys + simp only [capability.Cap.ptr] at ptr + exact ⟨⟨(okinj phys).symm, rfl, rfl⟩, (okinj ptr).symm, by change 17 ≠ 14; decide⟩ + · exact ⟨RngKeyA.ept _ _ _ _ _, ptrA_ept _ _ _ _ _, by change 19 ≠ 14; decide⟩ + · exact ⟨RngKeyA.hv _ _ _, ptrA_hv _ _ _, by change 25 ≠ 14; decide⟩ + +/-- A PageTable cap's object cannot also be an active ASID root. -/ +theorem RootAgreement.pageTableNoRoot (h : RootAgreement st OS Pp s) + (kinds : KindA st OS s) {x ptr a va : U64} {m : Bool} (hx : x ∈ OS) + (cap : capA st s x = .PageTable ptr m a va) : NoRoot st (PoolSet st Pp s) ∅ s ptr := by + refine ⟨by simp, ?_⟩ + intro pool hp o ho al nz + obtain ⟨asid, entry⟩ := ActiveAsidRoot.forWord hp ho al nz + obtain ⟨y, hy, root⟩ := h.backed _ _ entry + obtain ⟨key, base, kind⟩ := root.kindFacts + have avoid : (L.mem s (wa pool o) &&& ~~~3#u64) ≠ ptr := by + intro eq + have same := kinds.kind y hy x hx key (by rw [cap]; exact RngKeyA.pt _ _ _ _) + (by rw [base, cap, ptrA_pt, eq]) + exact kind (same.trans (by rw [cap]; rfl)) + exact ⟨fun tag => by rw [← maskedRoot tag]; exact avoid, fun _ => avoid⟩ + +/-- The HighVSpace roots named by entries of an active pool. -/ +def ActiveHigh (st : machine.Store S) [L : LawfulStore st] (Pp : Set U64) (s : S) : Set U64 := + {r | ∃ p ∈ PoolSet st Pp s, ∃ o : U64, o.val < 4096 ∧ o.val % 8 = 0 ∧ + (L.mem s (wa p o) &&& 3#u64) = 2#u64 ∧ r = (L.mem s (wa p o) &&& ~~~3#u64)} + +private theorem ActiveHigh.reach {r : U64} (h : r ∈ ActiveHigh st Pp s) : + VsReach st (PoolSet st Pp s) ∅ Lv s r := by + obtain ⟨p, hp, o, ho, al, tag, rfl⟩ := h + exact .root2 hp ho al tag + +private theorem VsReach.dropActiveHigh {r : U64} + (h : VsReach st (PoolSet st Pp s) (ActiveHigh st Pp s) Lv s r) : + VsReach st (PoolSet st Pp s) ∅ Lv s r := by + induction h with + | hr h => exact ActiveHigh.reach h + | root0 hp ho al nz tag => exact .root0 hp ho al nz tag + | root2 hp ho al tag => exact .root2 hp ho al tag + | step _ level ho al tag ih => exact .step ih level ho al tag + +private theorem VsReach.addSeeds {Pools Seeds : Set U64} {r : U64} + (h : VsReach st Pools ∅ Lv s r) : VsReach st Pools Seeds Lv s r := by + induction h with + | hr h => exact False.elim (Set.notMem_empty _ h) + | root0 hp ho al nz tag => exact .root0 hp ho al nz tag + | root2 hp ho al tag => exact .root2 hp ho al tag + | step _ level ho al tag ih => exact .step ih level ho al tag + +private theorem ActiveHigh.sub {r : U64} (h : r ∈ ActiveHigh st Pp s) + (ty : S2TyR st n (PoolSet st Pp s) Hr Te Re bits s) : r ∈ Hr := by + obtain ⟨p, hp, o, ho, al, tag, rfl⟩ := h + have nz : L.mem s (wa p o) ≠ 0#u64 := fun eq => by rw [eq] at tag; cases tag + rcases ty.tag p hp o ho al nz with ⟨tag0, _⟩ | ⟨_, live⟩ | ⟨tag1, _⟩ + · rw [tag0] at tag; cases tag + · exact live + · rw [tag1] at tag; cases tag + +private theorem S2TyR.activeHigh (ty : S2TyR st n (PoolSet st Pp s) Hr Te Re bits s) : + S2TyR st n (PoolSet st Pp s) (ActiveHigh st Pp s) Te Re bits s := by + refine ⟨?_, fun r hr => ty.hi r (ActiveHigh.sub hr ty), ty.desc⟩ + intro p hp o ho al nz + rcases ty.tag p hp o ho al nz with ⟨tag, off⟩ | ⟨tag, live⟩ | stage2 + · exact Or.inl ⟨tag, fun m => off (ActiveHigh.sub m ty)⟩ + · exact Or.inr (Or.inl ⟨tag, p, hp, o, ho, al, tag, rfl⟩) + · exact Or.inr (Or.inr stage2) + +private theorem S1aR2Core.highOfReach (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : HrOK (L.ksb s) Pp Tb Lv Hr) {r : U64} (live : r ∈ Hr) + (reach : VsReach st (PoolSet st Pp s) ∅ Lv s r) : r ∈ ActiveHigh st Pp s := by + cases reach with + | hr h => exact False.elim (Set.notMem_empty _ h) + | @root0 p o hp ho al nz tag => + rcases h.stage2.tag p hp o ho al nz with ⟨_, off⟩ | ⟨tag2, _⟩ | ⟨tag1, _⟩ + · exact (off live).elim + · rw [tag2] at tag; cases tag + · rw [tag1] at tag; cases tag + | @root2 p o hp ho al tag => exact ⟨p, hp, o, ho, al, tag, rfl⟩ + | @step p o parent level ho al tag => + have parentTable := (h.stage1.sub.reach (hr_rt (by simp)) parent).1 + have childLevel := (h.stage1.desc p parentTable parent level o ho al tag).2 + rw [place.lv _ live] at childLevel + omega + +private theorem PtFnd.activeHigh {asid va ptr : U64} + (h : PtFnd st n (PoolSet st Pp s) ∅ Lv Re bits s asid va ptr) : + PtFnd st n (PoolSet st Pp s) (ActiveHigh st Pp s) Lv Re bits s asid va ptr where + root := ⟨fun hR => by + obtain ⟨p, hp, o, ho, al, tag, eq⟩ := hR + have nz : L.mem s (wa p o) ≠ 0#u64 := fun e => by rw [e] at tag; cases tag + have notZero : (L.mem s (wa p o) &&& 3#u64) ≠ 0#u64 := by rw [tag]; decide + exact (h.root.2 p hp o ho al nz).2 notZero eq.symm, h.root.2⟩ + s2 := h.s2 + s1 b hb := by + obtain ⟨p, o, reach, level, ho, al, e, tag, target⟩ := hb + exact h.s1 b ⟨p, o, reach.dropActiveHigh, level, ho, al, e, tag, target⟩ + +/-- The typings and placement a walk needs, with the active HighVSpace roots as seeds. -/ +private theorem S1aR2Core.activeTyping (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) : + HrOK (L.ksb s) (PoolSet st Pp s) Tb Lv (ActiveHigh st Pp s) ∧ S2OK Te bits (ActiveHigh st Pp s) ∧ + VsTyR st (L.ksb s) (PoolSet st Pp s) (ActiveHigh st Pp s) Tb Lv s := by + have sub : ActiveHigh st Pp s ⊆ Hr := fun _ hr => ActiveHigh.sub hr h.stage2 + exact ⟨⟨fun _ hr => place.high.sub (sub hr), fun r hr => place.high.lv r (sub hr), + fun t ht o ho al r hr => place.high.tb t ht o ho al r (sub hr), + fun p hp o ho al r hr => place.high.pp p hp.1 o ho al r (sub hr), + fun r hr => place.high.asw r (sub hr)⟩, + ⟨place.stage2.sz, place.stage2.al, fun b hb r hr => place.stage2.hr b hb r (sub hr)⟩, + ⟨h.stage1.tbl, h.stage1.pool, fun p hp reach => h.stage1.desc p hp reach.dropActiveHigh⟩⟩ + +/-- A write inside the active walk footprint keeps or clears the VSpace words and keeps every live +HighVSpace root's reserved word. -/ +private theorem S1aR2Core.walkFacts {s' : S} (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (aligned : ∀ b, VsR (L.ksb s) Pt b → Aligned b) + (write : Wr0 st (TbO (VsRt st (PoolSet st Pp s) (ActiveHigh st Pp s) Tb Lv s) (ActiveHigh st Pp s) ∪ + Gran (S2Rt st (PoolSet st Pp s) Te Re bits s) bits) s s') : + VsZ st (L.ksb s) Pt s s' ∧ HrW st Hr s s' ∧ Wr0 st Pt s s' := by + have covers : TbO (VsRt st (PoolSet st Pp s) (ActiveHigh st Pp s) Tb Lv s) (ActiveHigh st Pp s) ∪ + Gran (S2Rt st (PoolSet st Pp s) Te Re bits s) bits ⊆ Pt := + Set.union_subset (fun _ ht => place.tables ht.1.1) ((gran_mono S2Rt_sub).trans place.granules) + have allHeaders : HrW st Hr s s' := by + refine Wr0.hrw (fun b hb => aligned b (Or.inl (ptw_mono covers hb))) + (fun r hr => aligned _ (Or.inl ⟨r, place.tables (place.high.sub hr), 4088#u64, by simp, by simp, rfl⟩)) + ?_ write + intro b hb r hr eq + rcases ptw_union hb with htb | hte + · obtain ⟨t, ht, o, ho, al, rfl⟩ := htb + have same := place.high.tb t ht.1.1 o ho al r hr eq + subst t + exact ht.2 (h.highOfReach place.high hr ht.1.2.dropActiveHigh) + · exact place.stage2.hr b (ptwb_mono S2Rt_sub (gran_ptwb (fun q (hq : q ∈ S2Rt st (PoolSet st Pp s) Te Re bits s) => place.stage2.sz q hq.1) hte)) r hr eq + exact ⟨Wr0.vsz aligned covers write, allHeaders, write.imp id fun ⟨b, hb, eq⟩ => ⟨b, ptw_mono covers hb, eq⟩⟩ + +/-- Whatever table it is asked for, `unmap_page_table` keeps or clears the VSpace words and keeps every +live HighVSpace root's reserved word. -/ +theorem vspace.unmap_page_table.activeWrites {A : Type _} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (a : A) + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (aligned : ∀ b, VsR (L.ksb s) Pt b → Aligned b) (asid va ptr : U64) : + vspace.unmap_page_table st ar s a asid va ptr ⦃ out => + VsZ st (L.ksb s) Pt s out.1 ∧ HrW st Hr s out.1 ∧ Wr0 st Pt s out.1 ⦄ := by + obtain ⟨high, s2place, h1⟩ := h.activeTyping place + exact WP.spec_mono + (vspace.unmap_page_table.s2R hA hPl high s2place h1 h.stage2.activeHigh rfl a asid va ptr) + fun _ write => h.walkFacts place aligned write + +/-- The concrete PageTable unmap walk erases every reachable parent of its target +and preserves the reserved word of every live HighVSpace root. -/ +theorem vspace.unmap_page_table.activeUnr {A : Type _} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (a : A) + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (aligned : ∀ b, VsR (L.ksb s) Pt b → Aligned b) {asid va ptr : U64} + (found : PtFnd st hPl.ipa (PoolSet st Pp s) ∅ Lv Re bits s asid va ptr) : + vspace.unmap_page_table st ar s a asid va ptr ⦃ out => + VsZ st (L.ksb s) Pt s out.1 ∧ HrW st Hr s out.1 ∧ + (¬ ∃ b, S2Nm st (PoolSet st Pp s) Re bits out.1 ptr b) ∧ + (¬ ∃ b, VsNm st (PoolSet st Pp s) ∅ Lv out.1 ptr b) ∧ Wr0 st Pt s out.1 ⦄ := by + obtain ⟨high, s2place, h1⟩ := h.activeTyping place + have hp : PoolSet st Pp s ⊆ Pt := fun _ hp => place.pools hp.1 + refine WP.spec_mono + (vspace.unmap_page_table.unr hA hPl high s2place aligned hp place.tables place.granules + h1 h.stage2.activeHigh rfl a found.activeHigh) ?_ + rintro out ⟨write, no2, no1⟩ + obtain ⟨words, allHeaders, written⟩ := h.walkFacts place aligned write + refine ⟨words, allHeaders, no2, ?_, written⟩ + rintro ⟨b, p, o, reach, level, ho, al, e, tag, target⟩ + exact no1 ⟨b, p, o, reach.addSeeds, level, ho, al, e, tag, target⟩ + +/-- The concrete walk preserves lookup backing, exact root-cap agreement and both typings. +The returned facts precede the wrapper's zeroing and cap rewrite. -/ +theorem vspace.unmap_page_table.activeLookup {A : Type _} {ar : machine.Arch A} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) (a : A) + {T Omega Sg Scs Vc Ub : Set U64} {Z : U64 → Nat} + (vr : VrOK Omega Sg Scs Z OS Vc Ub (L.ksb s) Pt) (slots : OSOK T Omega Sg OS) + (hh : HeapOK H) (pt : PtCap st Pt OS s) (ept : EptPlaced st H OS Pt s) + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) {asid va ptr : U64} + (found : PtFnd st hPl.ipa (PoolSet st Pp s) ∅ Lv Re bits s asid va ptr) : + vspace.unmap_page_table st ar s a asid va ptr ⦃ out => + VsLk st H OS Pp Tb Te Kt Lv Re bits out.1 ∧ RootAgreement st OS Pp out.1 ∧ + VsTyR st (L.ksb out.1) (PoolSet st Pp out.1) ∅ Tb Lv out.1 ∧ + S2TyR st hPl.ipa (PoolSet st Pp out.1) Hr Te Re bits out.1 ∧ + TeH H Te Re bits hPl.ipa ∧ + ¬ S2Reach st (PoolSet st Pp out.1) Re bits out.1 ptr ∧ + ¬ VsReach st (PoolSet st Pp out.1) ∅ Lv out.1 ptr ⦄ := by + refine WP.spec_mono + (vspace.unmap_page_table.activeUnr hA hPl a h place vr.al found) ?_ + rintro out ⟨z, headers, no2, no1, write⟩ + have writes := Wr0.w (fun b hb => vr.al b (Or.inl hb)) write + have tab : TabKeepOrZero st s out.1 := ⟨writes.1, fun i => by + rw [writes.1] + exact z _ (Or.inr (asW_at (L.ksb s) i))⟩ + have caps : ∀ x ∈ OS, capA st out.1 x = capA st s x := by + intro x hx + have keep := capk_vsr vr slots (writes.mono fun _ hw => Or.inl hw) x hx + rw [capA_eq, capA_eq] at keep + exact okinj keep + have no2' : ¬ ∃ b, S2Nm st (PoolSet st Pp out.1) Re bits out.1 ptr b := by + rintro ⟨b, p, o, reach, level, width, align, addr, tag, target⟩ + exact no2 ⟨b, p, o, reach.poolMono tab.poolSet, level, width, align, addr, tag, target⟩ + have no1' : ¬ ∃ b, VsNm st (PoolSet st Pp out.1) ∅ Lv out.1 ptr b := by + rintro ⟨b, p, o, reach, level, width, align, addr, tag, target⟩ + exact no1 ⟨b, p, o, reach.poolMono tab.poolSet, level, width, align, addr, tag, target⟩ + have noRoot := found.root.activeZero place.pools tab z + exact ⟨VsLk.activeZero h place tab z caps (ept.unmZ h hh pt), h.root.activeZero place.pools tab z caps, + h.stage1.activeZero place.pools place.tables tab z, + h.stage2.activeZero place.pools place.granules place.stage2 tab z headers, h.heap, + S2Reach.falseOfNoParent noRoot no2', VsReach.falseOfNoParent noRoot no1'⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2SlotUnique.lean b/proofs/Fl4ProofsA64/P1/S1aR2SlotUnique.lean new file mode 100644 index 000000000..db1062f1f --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2SlotUnique.lean @@ -0,0 +1,120 @@ +/- +P1 (aarch64): the uniqueness of a descriptor selected by an active ASID and address. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapReference +import Fl4ProofsA64.P1.S1aR2UnmapAddress + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {Pp : Set U64} {n tag asid : U64} {s : S} + {level base base' : Nat} {t t' o o' : U64} + +private theorem slotBaseOffset {level b b' : Nat} {o o' : U64} + (bAlign : 2 ^ (level + 9) ∣ b) (bAlign' : 2 ^ (level + 9) ∣ b') + (width : o.val < 4096) (width' : o'.val < 4096) + (same : b + o.val / 8 * 2 ^ level = b' + o'.val / 8 * 2 ^ level) : b = b' := by + let span : Nat := 2 ^ (level + 9) + let unit : Nat := 2 ^ level + have spanPos : 0 < span := by dsimp [span]; positivity + have scale : span = 512 * unit := by dsimp [span, unit]; rw [pow_add]; ring + have lo : o.val / 8 * unit < span := by + rw [scale] + exact Nat.mul_lt_mul_of_pos_right (by omega) (by dsimp [unit]; positivity) + have hi : o'.val / 8 * unit < span := by + rw [scale] + exact Nat.mul_lt_mul_of_pos_right (by omega) (by dsimp [unit]; positivity) + obtain ⟨i, bi⟩ := bAlign + obtain ⟨j, bj⟩ := bAlign' + change b = span * i at bi + change b' = span * j at bj + change b + o.val / 8 * unit = b' + o'.val / 8 * unit at same + have divEq := congrArg (fun a : Nat => a / span) same + rw [bi, bj, Nat.add_comm (span * i), + Nat.add_comm (span * j), Nat.add_mul_div_left _ _ spanPos, Nat.add_mul_div_left _ _ spanPos, + Nat.div_eq_of_lt lo, Nat.div_eq_of_lt hi, Nat.zero_add, Nat.zero_add] at divEq + rw [bi, bj, divEq] + +private theorem S1aPath.sameParentBase (p : S1aPath st Pp n s tag asid level base t) + (q : S1aPath st Pp n s tag asid level base' t') + (width : o.val < s1aTableWidth tag n level) (width' : o'.val < s1aTableWidth tag n level) + (atAddr : base + o.val / 8 * 2 ^ level = base' + o'.val / 8 * 2 ^ level) : base = base' := by + by_cases top : level = s1aTopShift tag n + · exact ((p.geometry.2.resolve_right (fun e => e.1.ne top)).2).trans + (q.geometry.2.resolve_right (fun e => e.1.ne top)).2.symm + · simp only [s1aTableWidth, if_neg top] at width width' + exact slotBaseOffset p.baseAligned q.baseAligned width width' atAddr + +set_option maxHeartbeats 2700000 in +/-- The ASID, stage, level and prefix identify the table on an active path. -/ +theorem S1aPath.sameTable (p : S1aPath st Pp n s tag asid level base t) + {level' : Nat} (q : S1aPath st Pp n s tag asid level' base' t') + (levelEq : level = level') (baseEq : base = base') : t = t' := by + induction p generalizing level' base' t' with + | native e kind => + cases q with + | native e' _ => exact core.result.Result.Ok.inj (okinj (e.find.symm.trans e'.find)) + | child prior depth _ _ _ _ => + have above := prior.geometry.2.elim (fun k => k.1.le) (fun k => k.1.le) + have top : s1aTopShift 0#u64 n = 39 := rfl + omega + | high e kind _ => + cases q with + | high e' _ _ => + rw [core.result.Result.Ok.inj (okinj (e.find.symm.trans e'.find))] + | child prior depth _ _ _ _ => + have above := prior.geometry.2.elim (fun k => k.1.le) (fun k => k.1.le) + have top : s1aTopShift 2#u64 n = 30 := rfl + omega + | stage2 e kind => + cases q with + | stage2 e' _ => + rw [core.result.Result.Ok.inj (okinj (e.find.symm.trans e'.find))] + | child prior depth _ _ _ _ => + have above := prior.geometry.2.elim (fun k => k.1.le) (fun k => k.1.le) + omega + | @child k a p off sh b prior depth width al range entry ih => + have above := prior.geometry.2.elim (fun k => k.1.le) (fun k => k.1.le) + cases q with + | native => + have top : s1aTopShift 0#u64 n = 39 := rfl + omega + | high => + have top : s1aTopShift 2#u64 n = 30 := rfl + omega + | stage2 => omega + | @child _ _ p' off' sh' b' prior' depth' width' al' range' entry' => + have heights : sh = sh' := by omega + subst sh' + have parents := prior.sameParentBase prior' width width' baseEq + have positions : off = off' := UScalar.eq_of_val_eq (by + rw [parents] at baseEq + have products : off.val / 8 * 2 ^ sh = off'.val / 8 * 2 ^ sh := Nat.add_left_cancel baseEq + have divided := Nat.eq_of_mul_eq_mul_right (by positivity : 0 < (2 : Nat) ^ sh) products + omega) + rw [ih prior' rfl parents, positions] + +/-- At a given level two walks for the same active ASID and effective address +return the same descriptor address. -/ +theorem S1aSlotAt.unique {address : Nat} {addr addr' : U64} + (p : S1aSlotAt st Pp n s tag asid address level addr) + (q : S1aSlotAt st Pp n s tag asid address level addr') : addr = addr' := by + obtain ⟨t, b, o, path, width, al, position, first, _⟩ := p.alignedAddress + obtain ⟨t', b', o', path', width', al', position', first', _⟩ := q.alignedAddress + have edit := first.symm.trans first' + have parent := path.sameParentBase path' width width' edit + have table := path.sameTable path' rfl parent + have off : o = o' := UScalar.eq_of_val_eq (by + rw [parent] at edit + have products := Nat.add_left_cancel edit + have slots := Nat.eq_of_mul_eq_mul_right (by positivity : 0 < (2 : Nat) ^ level) products + omega) + rw [position, position', table, off] + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Slots.lean b/proofs/Fl4ProofsA64/P1/S1aR2Slots.lean new file mode 100644 index 000000000..5108fd5b8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Slots.lean @@ -0,0 +1,32 @@ +/- +P1 (aarch64): R2 through a relabelling of the capability slots (A64-S1A gen 41). + +R2 reads the slots as a family of capabilities: a post that keeps the VSpace words and permutes the +capabilities among the slots of `OS` keeps it. This covers the unchanged-capability post and +`cap_swap_for_delete`. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Transfer + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s s' : S} + +/-- R2 is invariant under a permutation `f` of the slot capabilities that keeps the VSpace words. -/ +theorem S1aR2.permute (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (base : L.ksb s' = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s s') (f : U64 → U64) + (into : ∀ y ∈ OS, f y ∈ OS) (caps : ∀ y ∈ OS, capA st s' y = capA st s (f y)) + (inj : ∀ y ∈ OS, ∀ z ∈ OS, f y = f z → y = z) (onto : ∀ x ∈ OS, ∃ y ∈ OS, f y = x) : + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' := by + refine h.ofImage base mem ⟨fun y hy _ => ⟨f y, into y hy, (caps y hy).symm⟩, fun x hx _ => ?_, + fun y hy z hz k ky kz empty => ?_⟩ + · obtain ⟨y, hy, e⟩ := onto x hx + exact ⟨y, hy, by rw [caps y hy, e]⟩ + · rw [caps y hy] at ky empty + rw [caps z hz] at kz + exact inj z hz y hy (h.capRefs.unique _ (into y hy) _ (into z hz) k ky kz empty) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2TcbArm.lean b/proofs/Fl4ProofsA64/P1/S1aR2TcbArm.lean new file mode 100644 index 000000000..19177ed1f --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2TcbArm.lean @@ -0,0 +1,281 @@ +/- +P1 (aarch64): R2 across the TCB arms that install capabilities: SetSpace, Configure, SetIPCBuffer, +SetTimeoutEndpoint, SetHighVSpace and SetEPTRoot (A64-S1A gen 41). + +The walks are `S1aHiDelTcb`'s at the predicate `S1aTcbKeep`: R2, and no new table reference since the entry. +Case fact: `HiDelTy`. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Install + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub Pt U Ac Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {ia ie : Nat} {A : Type _} + {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-! ## The derived capabilities -/ + +theorem tcb.derive_with_data.s1aRel (s : S) (slot data : U64) : + tcb.derive_with_data st s slot data ⦃ r => ∀ d, r = .Ok d → + S1aCopyRel d (capA st s slot) ∧ S1aDerived d ⦄ := by + unfold tcb.derive_with_data + rw [capA_eq, bind_ok] + refine WP.spec_bind (Pₘ := fun c => S1aCopyRel c (capA st s slot)) ?_ fun c first => + WP.spec_mono (objects.derive_cap.s1aRel (st := st) s slot c) fun _ h d e => + ⟨(h d e).1.trans first, (h d e).2⟩ + split + · exact WP.spec_mono (objects.update_cap_data.s1aRel false data _) fun _ h => h.1 + · exact (WP.spec_ok _).2 (.refl _) + +theorem vspace.is_valid_vtable_root.root {c : capability.Cap} (h : vspace.is_valid_vtable_root c = ok true) : + S1aInstallRoot c := by + cases c <;> simp only [vspace.is_valid_vtable_root] at h <;> (repeat' split at h) <;> + first + | exact absurd (okinj h) (by decide) + | (subst_vars; exact Or.inl ⟨_, _, rfl⟩) + | (subst_vars; exact Or.inr (Or.inr ⟨_, _, _, _, rfl⟩)) + +theorem tcb.derive_roots.s1aRoots (s : S) (t cd vd cs vs : U64) : + tcb.derive_roots st s t cd vd cs vs ⦃ r => ∀ cc vc, r = .Ok (cc, vc) → + ¬ S1aR2Reads cc ∧ (S1aR2Reads vc → vc = capA st s vs ∧ S1aInstallRoot vc) ⦄ := by + have hS : P0.StoreTotal st := L.total + have fail : ∀ e : error.Exc, (do + let r ← core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual + (capability.Cap × capability.Cap) (core.convert.FromSame error.Exc) (.Err e) + ok r) ⦃ r => ∀ cc vc, r = .Ok (cc, vc) → + ¬ S1aR2Reads cc ∧ (S1aR2Reads vc → vc = capA st s vs ∧ S1aInstallRoot vc) ⦄ := fun e => by + simp [core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + unfold tcb.derive_roots + rw [tcb_slot_val, bind_ok] + refine WP.spec_bind (P0.cdt.slot_cap_long_running_delete.p0 st s _ hS) fun b _ => ?_ + split + · simp [error.illegal] + rw [tcb_slot_val, bind_ok] + refine WP.spec_bind (P0.cdt.slot_cap_long_running_delete.p0 st s _ hS) fun b1 _ => ?_ + split + · simp [error.illegal] + refine WP.spec_bind (tcb.derive_with_data.wf s cs cd) fun r _ => ?_ + rcases r with val | e + swap + · simp [core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + refine WP.spec_bind (spec_eqv (P0.tcb.is_cnode.p0 val)) fun b2 hb2 => ?_ + split + swap + · simp [error.illegal] + rename_i isCnode + refine WP.spec_bind (tcb.derive_with_data.s1aRel s vs vd) fun r1 rel => ?_ + rcases r1 with val1 | e + swap + · simp [core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + refine WP.spec_bind (spec_eqv (P0.vspace.is_valid_vtable_root.p0 val1)) fun b3 hb3 => ?_ + split + swap + · simp [error.illegal] + rename_i isRoot + refine (WP.spec_ok _).2 fun cc vc e => ?_ + cases e + have cnode : tcb.is_cnode val = ok true := isCnode ▸ hb2.1 + refine ⟨?_, fun reads => ?_⟩ + · revert cnode + cases val <;> intro cnode <;> first + | exact fun h => h + | (simp only [tcb.is_cnode] at cnode; exact absurd (okinj cnode) (by decide)) + obtain ⟨copied, derived⟩ := rel val1 rfl + exact ⟨derived.same copied reads, vspace.is_valid_vtable_root.root (isRoot ▸ hb3.1)⟩ + +theorem tcb.derive_for_buffer.s1aDerived (s : S) (baddr bslot : U64) : + tcb.derive_for_buffer st s baddr bslot ⦃ r => ∀ c src, r = .Ok (c, src) → src ≠ 0#u64 → S1aDerived c ⦄ := by + unfold tcb.derive_for_buffer + split + · rw [capA_eq, bind_ok] + rw [WP.spec_ok] + intro c src e nz + cases e + exact absurd rfl nz + rw [capA_eq, bind_ok] + refine WP.spec_bind (objects.derive_cap.s1aRel (st := st) s bslot _) fun r rel => ?_ + rcases r with val | e + swap + · simp [core.result.Result.Insts.CoreOpsTry.branch, + core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok] + refine WP.spec_bind (P0.vspace.check_valid_ipc_buffer.p0 _ val) fun r1 _ => ?_ + rcases r1 with u | e + swap + · simp [core.result.Result.Insts.CoreOpsTry_traitFromResidualResult.from_residual, core.convert.FromSame.from] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, WP.spec_ok] + intro c src e _ + cases e + exact (rel val rfl).2 + +/-! ## The walks' predicate -/ + +/-- R2, and no table reference that the entry's slots did not carry. -/ +def S1aTcbKeep (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt Pp Tb Hr Te Kt : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (s q : S) : Prop := + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q ∧ S1aRefsMono st OS s q + +/-- The install steps of the TCB walks keep R2. -/ +theorem S1aTcbSteps.r2 {s s1 : S} {t slot : U64} (J : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (vsK : ∀ c, K c → S1aVsCap c) (hPl : ArchPlat ar) (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (ht : t ∈ H.tcbs) (hslot : slot ∈ OS) (h0 : 0#u64 ∈ Cs) (refs : S1aRefs st OS s) (stall : OSKeep st OS s s1) : + S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot + (S1aTcbKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (fun c => S1aR2Reads c → CapInv st (S1aRefAt c) OS s ∧ S1aInstallRoot c) + (fun b => b.2 ≠ 0#u64 → ¬ S1aR2Reads b.1) where + keep q r h hq hr mem same := ⟨h.1.osKeep hq hr mem same, h.2.trans (.keep same)⟩ + install q a index nc src h R Q _ hi _ _ hsrc hnc good := + WP.spec_mono (tcb.install_tcb_cap.r2G J vsK hPl place ptKs hKZ hPI R Q ht hi hsrc hnc + (fun reads => ⟨h.2 nc (good reads).1, (good reads).2⟩) h.1) fun _ post => ⟨post.1, h.2.trans post.2⟩ + buffer q a baddr buffer h R hal hbuf unread := + WP.spec_mono (tcb.install_buffer.r2 J vsK hPl place ptKs h0 R ht hslot hal hbuf unread h.1) + fun _ post => ⟨post.1, h.2.trans post.2⟩ + unread nc h reads := by + rcases h with rfl | valid + · exact reads.elim + · exact absurd reads (faults.valid_fault_handler.unread valid) + roots cd vd cs vs _ hvs := + WP.spec_mono (tcb.derive_roots.s1aRoots s1 t cd vd cs vs) fun _ h cc vc e => by + obtain ⟨unread, root⟩ := h cc vc e + refine ⟨fun reads => absurd reads unread, fun reads => ⟨?_, (root reads).2⟩⟩ + rw [(root reads).1, stall.capA hvs] + exact .ofSlot refs hvs + high x hx p a cap _ := by + refine ⟨?_, Or.inr (Or.inl ⟨p, a, rfl⟩)⟩ + rw [← cap, stall.capA hx] + exact .ofSlot refs hx + derived baddr bslot _ := + WP.spec_mono (WP.spec_and (tcb.derive_for_buffer.s1aDerived s1 baddr bslot) + (tcb.derive_for_buffer.buf s1 baddr bslot)) fun _ ⟨derived, frames⟩ c src e nz => by + obtain ⟨-, frame⟩ := frames c src e + obtain ⟨-, ⟨p, sz, rights, m, ept, asid, va, shape⟩, -⟩ := frame nz + exact (derived c src e nz).1 (by rw [shape]; trivial) + +/-! ## The dispatcher arms -/ + +local macro "r2Label" : tactic => `(tactic| exact lbl_ne_of_val (by simp [ + fl4_abi.label.TCBReadRegisters, fl4_abi.label.TCBWriteRegisters, fl4_abi.label.TCBCopyRegisters, + fl4_abi.label.TCBConfigure, fl4_abi.label.TCBSetPriority, fl4_abi.label.TCBSetMCPriority, + fl4_abi.label.TCBSetSchedParams, fl4_abi.label.TCBSetTimeoutEndpoint, fl4_abi.label.TCBSetIPCBuffer, + fl4_abi.label.TCBSetSpace, fl4_abi.label.TCBSuspend, fl4_abi.label.TCBResume, fl4_abi.label.TCBBindNotification, + fl4_abi.label.TCBUnbindNotification, fl4_abi.label.TCBSetTLSBase, fl4_abi.label.TCBSetPACKeys, + fl4_abi.label.TCBSetHighVSpace, fl4_abi.label.TCBSetBreakpoint, fl4_abi.label.TCBGetBreakpoint, + fl4_abi.label.TCBUnsetBreakpoint, fl4_abi.label.TCBConfigureSingleStepping, fl4_abi.label.TCBSetEPTRoot, + fl4_abi.label.TCBSetFlags, fl4_abi.label.TCBSetTimer, fl4_abi.label.TCBReadFPU, core.num.U64.MAX, U64.rMax])) + +set_option hygiene false in +local macro "takeR2Arm" n:num : tactic => `(tactic| ( + iterate $n:num + refine spec_ite (fun h => absurd (hl.symm.trans h) ?_) fun _ => ?_ + · r2Label + refine spec_ite (fun _ => ?_) fun h => absurd hl h)) + +set_option maxHeartbeats 3000000 in +/-- **The five TCB install invocations keep any state assertion** that its install steps keep. -/ +theorem syscall.decode_invocation.tcbInstall_phi (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (J : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (z : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) {Φ : S → Prop} {G : capability.Cap → Prop} {Gb : capability.Cap × obj.Slot → Prop} + (entry : Φ s) + (walk : ∀ s1, DS st H.tcbs OS Vc s s1 → S1aTcbSteps st ar H Cs OS Vc Ub Pt Ac Ty ia ie s s1 t slot Φ G Gb) + (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetHighVSpace ∨ lbl = fl4_abi.label.TCBSetSpace ∨ + lbl = fl4_abi.label.TCBSetIPCBuffer ∨ lbl = fl4_abi.label.TCBConfigure ∨ + lbl = fl4_abi.label.TCBSetTimeoutEndpoint) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => Φ s' ⦄ := by + have ht := D.cap.2.1 t rfl + refine syscall.decode_invocation.tcbG (Φ := Φ) entry a len blk call don fp buf fun _ _ eq => ?_ + subst eq + unfold tcb.decode + refine WP.spec_bind (smp.remote_tcb_stall.delS hA D J a t) ?_ + rintro ⟨s1, a1⟩ ⟨⟨h1, d1⟩, ds1, vk1⟩ + try simp only [uncurry_apply_pair] + have steps := walk s1 ds1 + rcases hl with hl | hl | hl | hl | hl + · takeR2Arm 1 + unfold tcb.decode_arch + have hne : fl4_abi.label.TCBSetHighVSpace ≠ fl4_abi.label.TCBSetPACKeys := by r2Label + rw [if_neg (fun h => hne (hl.symm.trans h))] + exact WP.spec_mono (tcb.decode_set_high_vspace.s1aPhi J z hPI D P B Y h1 d1 ds1 vk1 steps entry) + fun _ h => h.2 + · takeR2Arm 13 + exact WP.spec_mono (tcb.decode_set_space.s1aPhi J z hPI D P B Y h1 d1 ds1 vk1 steps entry) fun _ h => h.2 + · takeR2Arm 12 + exact WP.spec_mono (tcb.decode_set_ipc_buffer.s1aPhi J D P B Y h1 d1 ds1 vk1 entry steps.keep steps.buffer + steps.derived) fun _ h => h.2 + · takeR2Arm 8 + exact WP.spec_mono (tcb.decode_configure.s1aPhi J z hPI D P B Y h1 d1 ds1 vk1 steps entry) fun _ h => h.2 + · takeR2Arm 14 + exact WP.spec_mono (tcb.decode_set_timeout_endpoint.s1aPhi J z hPI D P B Y h1 d1 ds1 vk1 steps entry) + fun _ h => h.2 + +set_option maxHeartbeats 3000000 in +/-- **SetHighVSpace, SetSpace, SetIPCBuffer, Configure and SetTimeoutEndpoint keep R2** on every return. -/ +theorem syscall.decode_invocation.tcbInstall_r2 (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetHighVSpace ∨ lbl = fl4_abi.label.TCBSetSpace ∨ + lbl = fl4_abi.label.TCBSetIPCBuffer ∨ lbl = fl4_abi.label.TCBConfigure ∨ + lbl = fl4_abi.label.TCBSetTimeoutEndpoint) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDel hPl W + have z := W.finKZ (hPl := hPl) I + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have K2 : S1aTcbKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s s := ⟨R.toDelKeep, .refl s⟩ + have ht := D.cap.2.1 t rfl + exact WP.spec_mono (syscall.decode_invocation.tcbInstall_phi hA J z hPI D P B Y + (Φ := S1aTcbKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) K2 + (fun s1 ds1 => S1aTcbSteps.r2 (Re := Re) (Kt := Kt) (Ac := Ac) (ia := ia) (ie := ie) (s1 := s1) (t := t) + (slot := slot) J (fun _ h => h.vsCap) hPl place ptKs z hPI ht P.src P.core0 R.capRefs.refs ds1.1) + a hl len blk call don fp buf) fun r h => by + obtain ⟨_, _, _⟩ := r + exact h.1 + +set_option maxHeartbeats 2000000 in +/-- **SetEPTRoot keeps R2** on every return. -/ +theorem syscall.decode_invocation.setEpt_r2 (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (a : A) + (hXE : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∉ EptS H.tcbs) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.TCBSetEPTRoot len slot (.Thread t) blk call don fp buf extra + ⦃ r s' _ => S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDel hPl W + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + refine syscall.decode_invocation.tcbG (Φ := S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) R.toDelKeep + a len blk call don fp buf fun _ _ eq => ?_ + subst eq + refine WP.spec_mono (tcb.decode.setEpt_s1aPhi hA J D P B Y hXE + (Φ := S1aDelKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) R.toDelKeep + (fun q r h hq hr mem same => h.osKeep hq hr mem same) + (fun q a x h Rq hx => cdt.delete.r2R J (fun _ h => h.vsCap) hPl place ptKs Rq hx h) + (fun q src dest nc h Rq hs hd ne can source wf empty ept => by + obtain ⟨p, l, m, v, rfl⟩ := ept + exact cdt.insert_with_cap.r2C I.del.os I.del.vr Rq.jv.ksb Rq.sys.sys.stz.1.1.mdbS hs hd ne can source + (fun e => by cases e) wf (fun _ => rfl) (fun _ _ none => by cases none) empty h)) fun _ h => h.2 + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Transfer.lean b/proofs/Fl4ProofsA64/P1/S1aR2Transfer.lean new file mode 100644 index 000000000..d95d4d773 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Transfer.lean @@ -0,0 +1,165 @@ +/- +P1 (aarch64): R2 through a post that keeps the VSpace words and the image of the capabilities R2 reads +(A64-S1A gen 41). + +Capabilities may be copied, moved or dropped between the slots, and unread capabilities may change freely, +as long as every read capability keeps a witness in both directions and an unmapped table capability stays in +one slot. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Del +import Fl4ProofsA64.P1.S1aR2Transport +import Fl4ProofsA64.P1.S1aR2Image + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s s' : S} + +/-- The capabilities R2 reads, after a step, are images of the ones before it, and conversely; an unmapped +table capability stays in one slot. -/ +structure S1aSlotImage (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s s' : S) : Prop where + back : ∀ y ∈ OS, S1aR2Reads (capA st s' y) → ∃ x ∈ OS, capA st s x = capA st s' y + forth : ∀ x ∈ OS, S1aR2Reads (capA st s x) → ∃ y ∈ OS, capA st s' y = capA st s x + unique : ∀ y ∈ OS, ∀ z ∈ OS, ∀ k, s1aTableKey (capA st s' y) = some k → + s1aTableKey (capA st s' z) = some k → s1aTableRef (capA st s' y) = none → z = y + +/-- The two cap-only clauses of `S1aTableCaps`: what a slot image needs, and keeps. -/ +structure S1aRefs (st : machine.Store S) [L : LawfulStore st] (OS : Set U64) (s : S) : Prop where + references : ∀ x ∈ OS, ∀ y ∈ OS, ∀ k, s1aTableKey (capA st s x) = some k → + s1aTableKey (capA st s y) = some k → s1aTableRef (capA st s x) = s1aTableRef (capA st s y) + unique : ∀ x ∈ OS, ∀ y ∈ OS, ∀ k, s1aTableKey (capA st s x) = some k → + s1aTableKey (capA st s y) = some k → s1aTableRef (capA st s x) = none → y = x + +theorem S1aTableCaps.refs (h : S1aTableCaps st OS s) : S1aRefs st OS s := ⟨h.references, h.unique⟩ + +theorem R2TableCap.reads {c : capability.Cap} (h : R2TableCap c) : S1aR2Reads c := by + cases c <;> first | trivial | exact h.elim + +theorem s1aTableKey.reads {c : capability.Cap} {k : Nat × U64} (h : s1aTableKey c = some k) : S1aR2Reads c := by + cases c <;> first | trivial | cases h + +/-- A slot image keeps the cap-only clauses. -/ +theorem S1aSlotImage.refs (I : S1aSlotImage st OS s s') (h : S1aRefs st OS s) : S1aRefs st OS s' := by + refine ⟨fun y hy z hz k ky kz => ?_, I.unique⟩ + obtain ⟨u, hu, eu⟩ := I.back y hy (s1aTableKey.reads ky) + obtain ⟨v, hv, ev⟩ := I.back z hz (s1aTableKey.reads kz) + rw [← eu] at ky ⊢ + rw [← ev] at kz ⊢ + exact h.references u hu v hv k ky kz + +/-- **R2 through a slot image over fixed VSpace words.** -/ +theorem S1aR2.ofImage (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (base : L.ksb s' = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s s') (I : S1aSlotImage st OS s s') : + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' := by + have back {y : U64} (hy : y ∈ OS) {c : capability.Cap} (eq : capA st s' y = c) (reads : S1aR2Reads c) : + ∃ x ∈ OS, capA st s x = c := by + obtain ⟨x, hx, same⟩ := I.back y hy (eq.symm ▸ reads) + exact ⟨x, hx, same.trans eq⟩ + have forth {x : U64} (hx : x ∈ OS) {c : capability.Cap} (eq : capA st s x = c) (reads : S1aR2Reads c) : + ∃ y ∈ OS, capA st s' y = c := by + obtain ⟨y, hy, same⟩ := I.forth x hx (eq.symm ▸ reads) + exact ⟨y, hy, same.trans eq⟩ + have image : R2CapImage st OS s s' := + .ofSlots (fun x hx kind => forth hx rfl kind.reads) (fun y hy kind => back hy rfl kind.reads) + have table : TabKeep st s s' := + ⟨base, fun i => by rw [base]; exact mem _ (Or.inr (asW_at _ i))⟩ + have poolWord p (hp : p ∈ PoolSet st Pp s) o (ho : o.val < 4096) (al : o.val % 8 = 0) : + L.mem s' (wa p o) = L.mem s (wa p o) := + mem _ (Or.inl ⟨p, h.place.pools hp, o, ho, al, rfl⟩) + have unmapped : ∀ x ∈ OS, ∀ p size, UnmCap (capA st s x) p size → ∀ o : U64, o.val < size → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o) := by + intro x hx p size cap o ho al + rcases cap with ⟨rfl, a, v, cap⟩ | ⟨rfl, a, v, cap⟩ + · exact mem _ (Or.inl ⟨p, h.pageTables x hx p false a v cap, o, ho, al, rfl⟩) + · have placed := (h.eptRoots x hx p 0#u64 false a v cap).2 + have word : PtWb {p} (fun _ => 13) (wa p o) := ⟨p, Set.mem_singleton p, o, ho, al, rfl⟩ + exact mem _ (Or.inl (ptw_mono placed (ptwb_gran (fun _ _ => Or.inr rfl) word))) + have core : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' := + h.core.keepImageActive h.place base mem image unmapped + have rootBack : ∀ a raw, ActiveAsidRoot st Pp s' a raw → ActiveAsidRoot st Pp s a raw := + fun _ _ entry => entry.back table.toDel (fun p hp o ho al => Or.inl (poolWord p hp o ho al)) + have pathBack : ∀ tag a sh va t, S1aPath st Pp n s' tag a sh va t → S1aPath st Pp n s tag a sh va t := + fun _ _ _ _ _ path => path.back rootBack + (fun _ _ root tag => mem _ (Or.inl (h.headerWord root tag))) + (fun _ _ _ _ _ old _ bd al => Or.inl (mem _ (Or.inl (h.pathWord old bd al)))) + have keepHeader p (hp : p ∈ Hr) : L.mem s' (wa p 4088#u64) = L.mem s (wa p 4088#u64) := + mem _ (Or.inl ⟨p, h.place.tables (h.place.high.sub hp), 4088#u64, by decide, by decide, rfl⟩) + have keepHigh : HvRt st OS s' = HvRt st OS s := by + ext p + constructor + · rintro ⟨y, hy, m, a, eq⟩ + obtain ⟨x, hx, old⟩ := back hy eq trivial + exact ⟨x, hx, m, a, old⟩ + · rintro ⟨x, hx, m, a, eq⟩ + obtain ⟨y, hy, new⟩ := forth hx eq trivial + exact ⟨y, hy, m, a, new⟩ + refine { + core := core + place := by rw [base, table.poolSet_eq]; exact h.place + poolCaps := ⟨fun i hi p word nz => by + obtain ⟨active, member, obj, x, hx, a, cap, low⟩ := + h.poolCaps.present i hi p ((table.2 i).symm.trans word) nz + obtain ⟨y, hy, new⟩ := forth hx cap trivial + exact ⟨active, member, obj, y, hy, a, new, low⟩, + fun y hy p a eq => by + obtain ⟨x, hx, old⟩ := back hy eq trivial + obtain ⟨i, hi, low, nz, word⟩ := h.poolCaps.cap x hx p a old + exact ⟨i, hi, low, nz, (table.2 i).trans word⟩, + fun i j p hi hj nz wi wj => + h.poolCaps.index i j p hi hj nz ((table.2 i).symm.trans wi) ((table.2 j).symm.trans wj), + fun raw entry => h.poolCaps.noZero raw (rootBack _ _ entry)⟩ + capRefs := ?_ + paths := h.paths.shrink pathBack + (fun tag a sh va t path _ bd al => Or.inl (mem _ (Or.inl (h.pathWord (pathBack tag a sh va t path) bd al)))) + (fun _ _ _ _ _ _ _ x hx _ eq => forth hx eq trivial) + (fun _ _ _ _ _ _ _ _ x hx _ _ _ _ eq => forth hx rfl (by rw [eq]; rfl)) + pageTables := fun y hy p m a v eq => by + obtain ⟨x, hx, old⟩ := back hy eq trivial + exact h.pageTables x hx p m a v old + footprint := h.footprint + pageObjects := fun y hy p m a v eq => by + obtain ⟨x, hx, old⟩ := back hy eq trivial + exact h.pageObjects x hx p m a v old + nativeRoots := fun y hy p m a eq => by + obtain ⟨x, hx, old⟩ := back hy eq trivial + exact h.nativeRoots x hx p m a old + eptRoots := fun y hy p l m a v eq => by + obtain ⟨x, hx, old⟩ := back hy eq trivial + exact h.eptRoots x hx p l m a v old + highObjects := fun y hy p m a eq => by + obtain ⟨x, hx, old⟩ := back hy eq trivial + exact h.highObjects x hx p m a old + highHeaders := fun y hy p m a eq => by + obtain ⟨x, hx, old⟩ := back hy eq trivial + have hp : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, m, a, old⟩ + rw [keepHeader p hp] + exact h.highHeaders x hx p m a old + highLink := fun p hp => by rw [keepHeader p hp]; exact h.highLink p hp + highRoots := h.highRoots.trans keepHigh.symm + highFootprint := h.highFootprint + kernelTables := h.kernelTables + kernelClosed := ?_ + rootSlots := h.rootSlotsOfZero (fun y hy kind => back hy rfl kind.reads) + (fun b hb => Or.inl (mem b (Or.inl hb))) + } + · refine ⟨(I.refs h.capRefs.refs).references, I.unique, ?_, ?_⟩ + · intro y hy p a eq o ho al + obtain ⟨x, hx, old⟩ := back hy eq trivial + rw [mem _ (Or.inl ⟨p, (h.nativeRoots x hx p false a old).2, o, ho, al, rfl⟩)] + exact h.capRefs.nativeEmpty x hx p a old o ho al + · intro y hy p a eq o ho al + obtain ⟨x, hx, old⟩ := back hy eq trivial + have hp : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, false, a, old⟩ + have granule := h.highFootprint ⟨p, hp, Or.inr ⟨rfl, rfl⟩⟩ + rw [mem _ (Or.inl ⟨_, granule, o, ho, al, rfl⟩)] + exact h.capRefs.highEmpty x hx p a old o ho al + · intro t ht level o ho al valid + rw [mem _ (Or.inl ⟨t, h.place.tables (h.kernelTables.1 ht), o, ho, al, rfl⟩)] at valid ⊢ + exact h.kernelClosed t ht level o ho al valid + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Transport.lean b/proofs/Fl4ProofsA64/P1/S1aR2Transport.lean new file mode 100644 index 000000000..3fbdae7db --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Transport.lean @@ -0,0 +1,309 @@ +/- +P1 (aarch64): transports for the exact VSpace record. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Contract +import Fl4ProofsA64.P1.S1aR2Keep + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {n : U64} {s s' : S} + +/-- Preserving the words of surviving table edges preserves their paths. -/ +theorem S1aPath.backIf {s s' : S} {Pp : Set U64} {n tag asid t : U64} {shift vaBase : Nat} + (root : ∀ a raw, ActiveAsidRoot st Pp s' a raw → ActiveAsidRoot st Pp s a raw) + (header : ∀ a raw, ActiveAsidRoot st Pp s a raw → raw &&& 3#u64 = 2#u64 → + L.mem s' (wa (raw &&& ~~~3#u64) 4088#u64) = L.mem s (wa (raw &&& ~~~3#u64) 4088#u64)) + (word : ∀ k a sh va p, S1aPath st Pp n s k a sh va p → + ∀ o : U64, o.val < s1aTableWidth k n sh → o.val % 8 = 0 → + L.mem s' (wa p o) &&& 3#u64 = 3#u64 → L.mem s' (wa p o) = L.mem s (wa p o)) + (path : S1aPath st Pp n s' tag asid shift vaBase t) : S1aPath st Pp n s tag asid shift vaBase t := by + induction path with + | native entry tag => exact .native (root _ _ entry) tag + | high entry tag valid => + have old := root _ _ entry + rw [header _ _ old tag] at valid ⊢ + exact .high old tag valid + | stage2 entry tag => exact .stage2 (root _ _ entry) tag + | child _ depth width aligned range valid ih => + have keep := word _ _ _ _ _ ih _ width aligned valid + rw [keep] at valid ⊢ + exact .child ih depth width aligned range valid + +/-- A path in the next state also existed in the prior state when active roots +can only disappear and every walked descriptor is kept or cleared. -/ +theorem S1aPath.back {s s' : S} {Pp : Set U64} {n tag asid t : U64} {shift vaBase : Nat} + (root : ∀ a raw, ActiveAsidRoot st Pp s' a raw → ActiveAsidRoot st Pp s a raw) + (header : ∀ a raw, ActiveAsidRoot st Pp s a raw → raw &&& 3#u64 = 2#u64 → + L.mem s' (wa (raw &&& ~~~3#u64) 4088#u64) = L.mem s (wa (raw &&& ~~~3#u64) 4088#u64)) + (word : ∀ k a sh va p, S1aPath st Pp n s k a sh va p → + ∀ o : U64, o.val < s1aTableWidth k n sh → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o) ∨ L.mem s' (wa p o) = 0#u64) + (path : S1aPath st Pp n s' tag asid shift vaBase t) : S1aPath st Pp n s tag asid shift vaBase t := + path.backIf root header fun k a sh va p old o width aligned valid => by + rcases word k a sh va p old o width aligned with eq | zero + · exact eq + · rw [zero] at valid + exact ((by decide : (0#u64 &&& 3#u64) ≠ 3#u64) valid).elim + +/-- Every descriptor the active user walk can read belongs to the shared footprint. -/ +theorem S1aR2.pathWord (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {tag asid t o : U64} {sh va : Nat} (path : S1aPath st Pp n s tag asid sh va t) + (bound : o.val < s1aTableWidth tag n sh) (aligned : o.val % 8 = 0) : PtW Pt (wa t o) := by + have typed := h.paths.tables tag asid sh va t path + by_cases stage : tag = 1#u64 + · rw [ite_eq_left stage] at typed + exact ptw_mono h.place.granules + (ptwb_gran h.place.stage2.sz ⟨t, typed.1, o, lt_of_lt_of_le bound typed.2.2, aligned, rfl⟩) + · rw [ite_eq_right stage] at typed + have size : s1aTableWidth tag n sh ≤ 4096 := by + unfold s1aTableWidth + split + · split <;> decide + · decide + exact ⟨t, h.place.tables typed.1, o, lt_of_lt_of_le bound size, aligned, rfl⟩ + +theorem S1aR2.headerWord (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + {a raw : U64} (entry : ActiveAsidRoot st Pp s a raw) (kind : raw &&& 3#u64 = 2#u64) : + PtW Pt (wa (raw &&& ~~~3#u64) 4088#u64) := by + obtain ⟨x, hx, cap⟩ := h.core.root.backed a raw entry + rw [kind] at cap + rcases cap with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, cap⟩ + · exact ((by decide : 2#u64 ≠ 0#u64) bad).elim + · exact ((by decide : 2#u64 ≠ 1#u64) bad).elim + · have live : (raw &&& ~~~3#u64) ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, true, a, cap⟩ + exact ⟨_, h.place.tables (h.place.high.sub live), 4088#u64, by decide, by decide, rfl⟩ + +/-- Surviving paths keep their typing and backing through operations that only +remove translation edges. Child and frame witnesses use the concrete cap post. -/ +theorem S1aPathBacking.shrink (h : S1aPathBacking st H OS Pp Tb Te Lv Re bits n s) + (back : ∀ tag a sh va t, S1aPath st Pp n s' tag a sh va t → S1aPath st Pp n s tag a sh va t) + (mem : ∀ tag a sh va t, S1aPath st Pp n s' tag a sh va t → ∀ o : U64, + o.val < s1aTableWidth tag n sh → o.val % 8 = 0 → + L.mem s' (wa t o) = L.mem s (wa t o) ∨ L.mem s' (wa t o) = 0#u64) + (tables : ∀ tag a sh va t, S1aPath st Pp n s' tag a sh va t → sh < s1aTopShift tag n → + ∀ x ∈ OS, ∀ address, capA st s x = .PageTable t true a address → + ∃ y ∈ OS, capA st s' y = .PageTable t true a address) + (frames : ∀ tag a sh va t, S1aPath st Pp n s' tag a sh va t → ∀ o : U64, + L.mem s' (wa t o) = L.mem s (wa t o) → + ∀ x ∈ OS, ∀ size rights dev address, + capA st s x = .Frame (s1aLeafTarget (L.mem s (wa t o)) sh) + size rights dev true (tag == 1#u64) a address → + ∃ y ∈ OS, capA st s' y = capA st s x) : + S1aPathBacking st H OS Pp Tb Te Lv Re bits n s' where + tables tag a sh va t path := h.tables tag a sh va t (back tag a sh va t path) + children tag a sh va t path child := by + obtain ⟨x, hx, address, eq, ref⟩ := h.children tag a sh va t (back tag a sh va t path) child + obtain ⟨y, hy, cap⟩ := tables tag a sh va t path child x hx address eq + exact ⟨y, hy, address, cap, ref⟩ + leaves tag a sh va t path o ho al range valid := by + rcases mem tag a sh va t path o ho al with word | zero + · rw [word] at valid ⊢ + obtain ⟨x, hx, sz, rights, dev, address, size, eq, ref, obj⟩ := + h.leaves tag a sh va t (back tag a sh va t path) o ho al range valid + obtain ⟨y, hy, cap⟩ := frames tag a sh va t path o word x hx sz rights dev address eq + exact ⟨y, hy, sz, rights, dev, address, size, cap.trans eq, ref, obj⟩ + · rw [zero] at valid + rcases valid with ⟨_, impossible⟩ | ⟨_, impossible⟩ + · exact ((by decide : (0#u64 &&& 3#u64) ≠ 3#u64) impossible).elim + · exact ((by decide : (0#u64 &&& 3#u64) ≠ 1#u64) impossible).elim + +/-- Exact pool-cap links survive when the ASID table and caps stay fixed and pool entries only clear. -/ +theorem S1aPoolCaps.zero (h : S1aPoolCaps st H OS Pt Pp s) + (table : TabKeep st s s') + (poolWord : ∀ p ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o) ∨ L.mem s' (wa p o) = 0#u64) + (cap : ∀ x ∈ OS, ∀ p a, capA st s' x = .AsidPool p a ↔ capA st s x = .AsidPool p a) : + S1aPoolCaps st H OS Pt Pp s' where + present i hi p word nz := by + obtain ⟨hp, placed, obj, x, hx, a, eq, low⟩ := h.present i hi p ((table.2 i).symm.trans word) nz + exact ⟨hp, placed, obj, x, hx, a, (cap x hx p a).2 eq, low⟩ + cap x hx p a eq := by + obtain ⟨i, hi, low, nz, word⟩ := h.cap x hx p a ((cap x hx p a).1 eq) + exact ⟨i, hi, low, nz, (table.2 i).trans word⟩ + index i j p hi hj nz wi wj := + h.index i j p hi hj nz ((table.2 i).symm.trans wi) ((table.2 j).symm.trans wj) + noZero raw entry := h.noZero raw (entry.back table.toDel poolWord) + +/-- Exact pool-cap links survive when the table, its pool words, and its caps stay fixed. -/ +theorem S1aPoolCaps.keep (h : S1aPoolCaps st H OS Pt Pp s) + (table : TabKeep st s s') + (poolWord : ∀ p ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + (cap : ∀ x ∈ OS, ∀ p a, capA st s' x = .AsidPool p a ↔ capA st s x = .AsidPool p a) : + S1aPoolCaps st H OS Pt Pp s' := + h.zero table (fun p hp o ho al => Or.inl (poolWord p hp o ho al)) cap + +/-- Root slots are preserved when old root capabilities survive and the relevant +words are kept or cleared. The surviving slots may have moved or been removed. -/ +theorem S1aR2.rootSlotsOfZero {OS' : Set U64} (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (caps : ∀ x ∈ OS', R2TableCap (capA st s' x) → ∃ y ∈ OS, capA st s y = capA st s' x) + (mem : ∀ b, PtW Pt b → L.mem s' b = L.mem s b ∨ L.mem s' b = 0#u64) : + S1aRootSlots st OS' Kt n s' := by + have source x (hx : x ∈ OS') c (kind : R2TableCap c) (eq : capA st s' x = c) := + caps x hx (eq.symm ▸ kind) + constructor + · intro x hx p m a cap o bound al + obtain ⟨y, hy, before⟩ := source x hx (.Pml4 p m a) trivial cap + have old := before.trans cap + have placed := (h.nativeRoots y hy p m a old).2 + exact (mem _ ⟨p, placed, o, bound.2, al, rfl⟩).elim + (·.trans (h.rootSlots.native y hy p m a old o bound al)) id + · intro x hx p m a v cap o bound al + obtain ⟨y, hy, before⟩ := source x hx (.Ept p 0#u64 m a v) trivial cap + have old := before.trans cap + have placed := (h.eptRoots y hy p 0#u64 m a v old).2 + have word : PtWb {p} (fun _ => 13) (wa p o) := + ⟨p, Set.mem_singleton p, o, bound.2, al, rfl⟩ + have address := ptw_mono placed (ptwb_gran (fun _ _ => Or.inr rfl) word) + exact (mem _ address).elim (·.trans (h.rootSlots.stage2 y hy p m a v old o bound al)) id + · intro x hx p m a cap o bound al tag + obtain ⟨y, hy, before⟩ := source x hx (.HighVSpace p m a) trivial cap + have old := before.trans cap + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨y, hy, m, a, old⟩ + rcases mem _ ⟨p, h.place.tables (h.place.high.sub live), o, by omega, al, rfl⟩ with same | empty + · rw [same] at tag ⊢ + exact h.rootSlots.highCopies y hy p m a old o bound al tag + · rw [empty] at tag + cases tag + · intro x hx p m a cap o bound al + obtain ⟨y, hy, before⟩ := source x hx (.HighVSpace p m a) trivial cap + have old := before.trans cap + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨y, hy, m, a, old⟩ + have placed := h.highFootprint ⟨p, live, Or.inr ⟨rfl, rfl⟩⟩ + exact (mem _ ⟨_, placed, o, bound.1, al, rfl⟩).elim + (·.trans (h.rootSlots.highPrivate y hy p m a old o bound al)) id + +/-- Exact R2 transport through a fixed-footprint and fixed-capability post. -/ +theorem S1aR2.keep (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (core : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s') + (base : L.ksb s' = L.ksb s) (mem : VsKeep st (L.ksb s) Pt s s') + (caps : ∀ x ∈ OS, capA st s' x = capA st s x) : + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' := by + have table : TabKeep st s s' := + ⟨base, fun i => by rw [base]; exact mem _ (Or.inr (asW_at _ i))⟩ + have poolWord p (hp : p ∈ PoolSet st Pp s) o (ho : o.val < 4096) (al : o.val % 8 = 0) : + L.mem s' (wa p o) = L.mem s (wa p o) := + mem _ (Or.inl ⟨p, h.place.pools hp, o, ho, al, rfl⟩) + have rootBack : ∀ a raw, ActiveAsidRoot st Pp s' a raw → ActiveAsidRoot st Pp s a raw := + fun _ _ entry => entry.back table.toDel (fun p hp o ho al => Or.inl (poolWord p hp o ho al)) + have pathBack : ∀ tag a sh va t, S1aPath st Pp n s' tag a sh va t → S1aPath st Pp n s tag a sh va t := + fun _ _ _ _ _ path => path.back rootBack + (fun _ _ root tag => mem _ (Or.inl (h.headerWord root tag))) + (fun _ _ _ _ _ old _ bd al => Or.inl (mem _ (Or.inl (h.pathWord old bd al)))) + have keepHeader p (hp : p ∈ Hr) : L.mem s' (wa p 4088#u64) = L.mem s (wa p 4088#u64) := + mem _ (Or.inl ⟨p, h.place.tables (h.place.high.sub hp), 4088#u64, by decide, by decide, rfl⟩) + have keepHigh : HvRt st OS s' = HvRt st OS s := by + ext p + constructor <;> rintro ⟨x, hx, m, a, eq⟩ + · exact ⟨x, hx, m, a, (caps x hx).symm.trans eq⟩ + · exact ⟨x, hx, m, a, (caps x hx).trans eq⟩ + refine { + core := core + place := by rw [base, table.poolSet_eq]; exact h.place + poolCaps := h.poolCaps.keep table poolWord (fun x hx _ _ => by rw [caps x hx]) + capRefs := ?_ + paths := h.paths.shrink pathBack + (fun tag a sh va t path _ bd al => Or.inl (mem _ (Or.inl (h.pathWord (pathBack tag a sh va t path) bd al)))) + (fun _ _ _ _ _ _ _ x hx _ eq => ⟨x, hx, (caps x hx).trans eq⟩) + (fun _ _ _ _ _ _ _ _ x hx _ _ _ _ _ => ⟨x, hx, caps x hx⟩) + pageTables := fun x hx p m a v eq => h.pageTables x hx p m a v ((caps x hx).symm.trans eq) + footprint := h.footprint + pageObjects := fun x hx p m a v eq => h.pageObjects x hx p m a v ((caps x hx).symm.trans eq) + nativeRoots := fun x hx p m a eq => h.nativeRoots x hx p m a ((caps x hx).symm.trans eq) + eptRoots := ?_ + highObjects := ?_ + highHeaders := ?_ + highLink := fun p hp => by rw [keepHeader p hp]; exact h.highLink p hp + highRoots := h.highRoots.trans keepHigh.symm + highFootprint := h.highFootprint + kernelTables := h.kernelTables + kernelClosed := ?_ + rootSlots := h.rootSlotsOfZero (fun x hx _ => ⟨x, hx, (caps x hx).symm⟩) + (fun b hb => Or.inl (mem b (Or.inl hb))) + } + · refine ⟨?_, ?_, ?_, ?_⟩ + · intro x hx y hy k kx ky + rw [caps x hx] at kx + rw [caps y hy] at ky + rw [caps x hx, caps y hy] + exact h.capRefs.references x hx y hy k kx ky + · intro x hx y hy k kx ky empty + rw [caps x hx] at kx empty + rw [caps y hy] at ky + exact h.capRefs.unique x hx y hy k kx ky empty + · intro x hx p a eq o ho al + have old := (caps x hx).symm.trans eq + rw [mem _ (Or.inl ⟨p, (h.nativeRoots x hx p false a old).2, o, ho, al, rfl⟩)] + exact h.capRefs.nativeEmpty x hx p a old o ho al + · intro x hx p a eq o ho al + have old := (caps x hx).symm.trans eq + have hp : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, false, a, old⟩ + have granule := h.highFootprint ⟨p, hp, Or.inr ⟨rfl, rfl⟩⟩ + rw [mem _ (Or.inl ⟨_, granule, o, ho, al, rfl⟩)] + exact h.capRefs.highEmpty x hx p a old o ho al + · intro x hx + rw [caps x hx] + exact h.eptRoots x hx + · intro x hx p m a eq + exact h.highObjects x hx p m a ((caps x hx).symm.trans eq) + · intro x hx p m a eq + have old := (caps x hx).symm.trans eq + have hp : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, hx, m, a, old⟩ + rw [keepHeader p hp] + exact h.highHeaders x hx p m a old + · intro t ht level o ho al valid + rw [mem _ (Or.inl ⟨t, h.place.tables (h.kernelTables.1 ht), o, ho, al, rfl⟩)] at valid ⊢ + exact h.kernelClosed t ht level o ho al valid + +section keeping + +variable {Cs Vc Ub U Ac : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} + {ia ie : Nat} {A : Type _} {ar : machine.Arch A} + {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot lbl : U64} + +/-- The keeping dispatcher arms whose post keeps every capability transport the full record. -/ +theorem syscall.decode_invocation.keepingExactR2 (hA : P0.ArchTotal ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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) (source : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) + (sc : L.mem s (scA (L.curW s)) ≠ 0#u64) (arm : DecArmKK3 cap lbl) + (a : A) (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' _ => + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + refine WP.spec_mono (syscall.decode_invocation.armKK3At hA I D P B Y source hks mcp sc a arm len blk call don fp buf) + (fun _ ⟨_, _, slots, mem⟩ => ?_) + have frozen : ∀ x ∈ OS, capA st _ x = capA st s x := fun _ hx => slots.capA hx + have unmapped := h.eptRoots.unmZ h.core P.heap h.pageTables + exact h.keep (h.core.ofKeepingArm place I unmapped mem (R2CapImage.keep frozen)) + mem.1 (mem.vsKeep I.del.vr I.fu) frozen + +/-- Cache-only dispatch, including rejected legacy caps, keeps the exact record. -/ +theorem syscall.decode_invocation.cacheExactR2 + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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) + (hA : P0.ArchTotal ar) (a : A) (arm : DecArmR2Cache cap lbl) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄ := by + refine syscall.decode_invocation.cacheInvariant h ?_ hA a arm len slot blk call don fp buf + refine WP.spec_mono (WP.spec_and (sched.set_thread_state.restartR2 h.core place I D) + (sched.set_thread_state.unmMid I D)) (fun _ ⟨core, mid, mem⟩ => ?_) + exact h.keep core mid.tz.1 mem (fun _ hx => mid.k.capA hx) + +end keeping + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2UnmapAddress.lean b/proofs/Fl4ProofsA64/P1/S1aR2UnmapAddress.lean new file mode 100644 index 000000000..2e6b6fdc3 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2UnmapAddress.lean @@ -0,0 +1,96 @@ +/- +P1 (aarch64): recover an executable slot from its exact walk interval. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapWalk + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {s : S} + {Pp : Set U64} {n tag asid table : U64} {shift base : Nat} + +def s1aWalkWord (x : Nat) : U64 := ⟨BitVec.ofNat 64 x⟩ + +theorem s1aWalkWord.val {x : Nat} (small : x < 2 ^ 64) : (s1aWalkWord x).val = x := by + change x % (2 ^ 64) = x + exact Nat.mod_eq_of_lt small + +/-- Every exact table path starts at an address aligned to a full table span. -/ +theorem S1aPath.baseAligned (p : S1aPath st Pp n s tag asid shift base table) : + 2 ^ (shift + 9) ∣ base := by + induction p with + | native => exact dvd_zero _ + | high => decide + | stage2 => exact dvd_zero _ + | @child k a t o sh v path deep w al r e ih => + rw [Nat.sub_add_cancel (by omega : 9 ≤ sh)] + have parentAligned : (2 : Nat) ^ sh ∣ v := (Nat.pow_dvd_pow 2 (by omega)).trans ih + exact Nat.dvd_add parentAligned ((dvd_refl _).mul_left _) + +private theorem intervalIndex {address base unit count i : Nat} + (p : 0 < unit) (aligned : unit * count ∣ base) (idx : i < count) + (lo : base + i * unit ≤ address) (hi : address < base + i * unit + unit) : + address / unit % count = i := by + obtain ⟨k, hk⟩ := aligned + have eq : base + i * unit = (count * k + i) * unit := by + rw [hk] + ring + have lower : count * k + i ≤ address / unit := (Nat.le_div_iff_mul_le p).2 (by rwa [eq] at lo) + have upper : address / unit < count * k + i + 1 := (Nat.div_lt_iff_lt_mul p).2 (by + rw [Nat.add_mul, Nat.one_mul, ← eq] + exact hi) + rw [show address / unit = count * k + i by omega, Nat.add_mod, + Nat.mul_mod_right, zero_add, Nat.mod_mod, Nat.mod_eq_of_lt idx] + +/-- A masked index recovers the word that covers the address. For the first +Stage-2 table the number of slots is the geometry's selected top-level width. -/ +theorem ept.entry_addr.ofInterval {table va sh mask o : U64} {base width : Nat} + (shift : sh.val < 64) (maskBound : mask.val ≤ 1023) (shape : mask.val = 2 ^ width - 1) + (span : 2 ^ (sh.val + width) ∣ base) (range : o.val < 8 * 2 ^ width) (aligned : o.val % 8 = 0) + (low : base + o.val / 8 * 2 ^ sh.val ≤ va.val) + (high : va.val < base + o.val / 8 * 2 ^ sh.val + 2 ^ sh.val) : + ept.entry_addr table va sh mask = ok (wa table o) := by + obtain ⟨slot, eq, u, hu, atWord⟩ := spec_exists_u (ept.entry_addr.exactOffset table va sh mask shift maskBound) + have unit : 0 < (2 : Nat) ^ sh.val := by positivity + have divides : (2 : Nat) ^ sh.val * 2 ^ width ∣ base := by rwa [← pow_add] + have idx := intervalIndex unit divides (show o.val / 8 < 2 ^ width by omega) low high + rw [shape, Nat.and_two_pow_sub_one_eq_mod, Nat.shiftRight_eq_div_pow, idx] at hu + have same : u = o := UScalar.eq_of_val_eq (by omega) + rw [eq, atWord, same] + +/-- High bits of a saved Stage-2 PageTable reference do not affect a slot +when all index bits lie within the platform IPA width. -/ +theorem ept.entry_addr.ofIpaInterval {table va sh mask o : U64} {base width : Nat} + (shift : sh.val < 64) (maskBound : mask.val ≤ 1023) (shape : mask.val = 2 ^ width - 1) + (fits : sh.val + width ≤ s1aIpaWidth n) (span : 2 ^ (sh.val + width) ∣ base) + (range : o.val < 8 * 2 ^ width) (aligned : o.val % 8 = 0) + (low : base + o.val / 8 * 2 ^ sh.val ≤ s1aCapAddress 1#u64 n va) + (high : s1aCapAddress 1#u64 n va < base + o.val / 8 * 2 ^ sh.val + 2 ^ sh.val) : + ept.entry_addr table va sh mask = ok (wa table o) := by + let excess := 2 ^ s1aIpaWidth n * (va.val / 2 ^ s1aIpaWidth n) + have covers := Nat.div_add_mod va.val (2 ^ s1aIpaWidth n) + change excess + va.val % 2 ^ s1aIpaWidth n = va.val at covers + rw [s1aCapAddress, ite_eq_left rfl] at low high + have lifted : (2 : Nat) ^ (sh.val + width) ∣ excess := + (Nat.pow_dvd_pow 2 fits).mul_right _ + exact ept.entry_addr.ofInterval shift maskBound shape (Nat.dvd_add span lifted) range aligned + (by omega : (base + excess) + o.val / 8 * 2 ^ sh.val ≤ va.val) + (by omega : va.val < (base + excess) + o.val / 8 * 2 ^ sh.val + 2 ^ sh.val) + +/-- The Stage-1 walk recovers a word using its fixed nine-bit level index. -/ +theorem vspace.entry_addr.ofInterval {table va sh o : U64} {base : Nat} + (shift : sh.val < 64) (span : 2 ^ (sh.val + 9) ∣ base) + (range : o.val < 4096) (aligned : o.val % 8 = 0) + (low : base + o.val / 8 * 2 ^ sh.val ≤ va.val) + (high : va.val < base + o.val / 8 * 2 ^ sh.val + 2 ^ sh.val) : + vspace.entry_addr table va sh = ok (wa table o) := by + change ept.entry_addr table va sh 511#u64 = ok (wa table o) + exact ept.entry_addr.ofInterval shift (by decide) (show (511#u64 : U64).val = 2 ^ 9 - 1 by decide) + span range aligned low high + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2UnmapPost.lean b/proofs/Fl4ProofsA64/P1/S1aR2UnmapPost.lean new file mode 100644 index 000000000..a25d8c60a --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2UnmapPost.lean @@ -0,0 +1,311 @@ +/- +P1 (aarch64): R2 after the exact mapped PageTable Unmap effects. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2PtUnmap +import Fl4ProofsA64.P1.S1aR2Transport +import Fl4ProofsA64.P1.S1aR2UnmapRoute + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {s out : S} + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} + {n slot ptr a va : U64} + +private theorem pageTable_of_key {c : capability.Cap} (key : s1aTableKey c = some (0, ptr)) : + ∃ m a va, c = .PageTable ptr m a va := by + cases c <;> simp_all [s1aTableKey] + +set_option maxHeartbeats 3000000 in +/-- Clearing an unreachable child and resetting its last live cap preserves the +full R2 record. The changed paths are reconstructed from the post-state words. -/ +theorem S1aR2.ofClearedPageTable + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (heap : HeapOK H) (kinds : KindA st OS s) + {mapped : Bool} (old : capA st s slot = .PageTable ptr mapped a va) + (post : S1aPageTableClear st H OS Pt Pp Tb Hr Te Kt Lv Re bits s out slot ptr) : + S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n out := by + have reflect (P : capability.Cap → Prop) + (caseSlot : P (.PageTable ptr false 0#u64 0#u64) ↔ P (.PageTable ptr mapped a va)) + (x : U64) (hx : x ∈ OS) : P (capA st out x) ↔ P (capA st s x) := by + by_cases eq : x = slot + · subst x; rwa [old, post.cap] + · rw [post.other x hx eq] + have same x (hx : x ∈ OS) (c : capability.Cap) + (before : c ≠ .PageTable ptr mapped a va) (after : c ≠ .PageTable ptr false 0#u64 0#u64) : + capA st out x = c ↔ capA st s x = c := + reflect (· = c) ⟨fun e => (after e.symm).elim, fun e => (before e.symm).elim⟩ x hx + have poolWord p (hp : p ∈ PoolSet st Pp s) (o : U64) (ho : o.val < 4096) (al : o.val % 8 = 0) := + post.memory _ (Or.inl ⟨p, h.place.pools hp, o, ho, al, rfl⟩) + have newRoot := fun x hx p asid tag => reflect (fun c => MappedAsidRoot c p asid tag) + (by simp [MappedAsidRoot]) x hx + have root : RootAgreement st OS Pp out := by + constructor + · intro asid raw e + obtain ⟨x, hx, c⟩ := h.core.root.backed asid raw (e.back post.table.toDel poolWord) + exact ⟨x, hx, (newRoot x hx _ _ _).2 c⟩ + · intro x hx y hy p ax ay tx ty cx cy + exact h.core.root.agree x hx y hy p ax ay tx ty ((newRoot x hx p ax tx).1 cx) ((newRoot y hy p ay ty).1 cy) + have stage1 := h.core.stage1.activeZero place.pools h.place.tables post.table.toDel post.memory + have stage2 := h.core.stage2.activeZero place.pools h.place.granules h.place.stage2 + post.table.toDel post.memory post.headers + have back {tag asid t : U64} {sh b : Nat} (p : S1aPath st Pp n out tag asid sh b t) : + S1aPath st Pp n s tag asid sh b t := by + refine p.back (fun _ _ e => e.back post.table.toDel poolWord) ?_ ?_ + · intro asid raw entry kind + obtain ⟨x, hx, c⟩ := h.core.root.backed asid raw entry + rw [kind] at c + rcases c with ⟨bad, _⟩ | ⟨bad, _⟩ | ⟨_, high⟩ + · cases bad + · cases bad + · exact post.headers _ (by rw [h.highRoots]; exact ⟨x, hx, true, asid, high⟩) + · exact fun _ _ _ _ _ oldPath _ width al => post.memory _ (Or.inl (h.pathWord oldPath width al)) + have typed1 {tag asid t : U64} {sh b : Nat} (ne : tag ≠ 1#u64) (p : S1aPath st Pp n out tag asid sh b t) : + sh + 9 * Lv t = 39 := by + have shape := h.paths.tables _ _ _ _ _ (back p) + rw [ite_eq_right ne] at shape + exact shape.2 + have typed2 {asid t : U64} {sh b : Nat} (p : S1aPath st Pp n out 1#u64 asid sh b t) : + sh = 12 + 9 * Re t ∧ s1aTableWidth 1#u64 n sh ≤ 2 ^ bits t := + (show _ ∧ _ ∧ _ from h.paths.tables _ _ _ _ _ (back p)).2 + have highLv asid raw (e : ActiveAsidRoot st Pp out asid raw) (tag : raw &&& 3#u64 = 2#u64) : + Lv (raw &&& ~~~3#u64) = 0 := by + obtain ⟨_, o, _, ho, al, _, p, hp, _, word, nz⟩ := e + subst raw + exact ((stage1.pool p hp o ho al nz).2 tag).2 + have paths : S1aPathBacking st H OS Pp Tb Te Lv Re bits n out := by + refine h.paths.shrink (fun _ _ _ _ _ p => back p) + (fun _ _ _ _ _ p _ width al => post.memory _ (Or.inl (h.pathWord (back p) width al))) ?_ ?_ + · intro tag asid sh b t p _ x hx saved c + have different : x ≠ slot := by + rintro rfl + rw [old] at c + cases c + by_cases stage : tag = 1#u64 + · subst tag + exact post.absent2 (p.toStage2 (fun _ _ _ q => typed2 q)) + · exact post.absent1 (p.toStage1 stage (fun _ _ _ q => typed1 stage q) highLv) + exact ⟨x, hx, (post.other x hx different).trans c⟩ + · intro _ _ _ _ _ _ _ _ x hx _ _ _ _ c + have different : x ≠ slot := by rintro rfl; rw [old] at c; cases c + exact ⟨x, hx, post.other x hx different⟩ + have refKey : s1aTableKey (capA st out slot) = some (0, ptr) := by rw [post.cap]; rfl + have noPeer x (hx : x ∈ OS) (ne : x ≠ slot) : + s1aTableKey (capA st out x) ≠ s1aTableKey (capA st out slot) := by + intro eq + rw [refKey, post.other x hx ne] at eq + obtain ⟨m, a, v, cap⟩ := pageTable_of_key eq + exact post.finality x hx ne (NmC_iff.mpr (Or.inl ⟨m, a, v, cap⟩)) + have nativeCaps x (hx : x ∈ OS) p m asid : + capA st out x = .Pml4 p m asid ↔ capA st s x = .Pml4 p m asid := + same x hx _ (by intro e; cases e) (by intro e; cases e) + have highCaps x (hx : x ∈ OS) p m asid : + capA st out x = .HighVSpace p m asid ↔ capA st s x = .HighVSpace p m asid := + same x hx _ (by intro e; cases e) (by intro e; cases e) + have highSet : Hr = HvRt st OS out := by + rw [h.highRoots] + ext p + constructor <;> rintro ⟨x, hx, m, a, e⟩ + · exact ⟨x, hx, m, a, (highCaps x hx p m a).2 e⟩ + · exact ⟨x, hx, m, a, (highCaps x hx p m a).1 e⟩ + have refs : S1aTableCaps st OS out := by + constructor + · intro x hx y hy k kx ky + by_cases ex : x = slot + · subst x + by_cases ey : y = slot + · subst y; rfl + · exact (noPeer y hy ey (ky.trans kx.symm)).elim + · by_cases ey : y = slot + · subst y; exact (noPeer x hx ex (kx.trans ky.symm)).elim + · simp only [post.other x hx ex, post.other y hy ey] at kx ky ⊢ + exact h.capRefs.references x hx y hy k kx ky + · intro x hx y hy k kx ky unassigned + by_cases ex : x = slot + · subst x + by_contra ey + exact noPeer y hy ey (ky.trans kx.symm) + · by_cases ey : y = slot + · subst y; exact (noPeer x hx ex (kx.trans ky.symm)).elim + · simp only [post.other x hx ex, post.other y hy ey] at kx ky unassigned + exact h.capRefs.unique x hx y hy k kx ky unassigned + · intro x hx p a c o ho al + have oldCap := (nativeCaps x hx p false a).1 c + have word : PtW Pt (wa p o) := ⟨p, (h.nativeRoots x hx p false a oldCap).2, o, ho, al, rfl⟩ + exact (post.memory _ (Or.inl word)).elim (·.trans (h.capRefs.nativeEmpty x hx p a oldCap o ho al)) id + · intro x hx p a c o ho al + have oldCap := (highCaps x hx p false a).1 c + have hp : p ∈ Hr := by rw [highSet]; exact ⟨x, hx, false, a, c⟩ + have word : PtW Pt (wa (wa p 4096#u64) o) := + ⟨_, h.highFootprint ⟨p, hp, Or.inr ⟨rfl, rfl⟩⟩, o, ho, al, rfl⟩ + exact (post.memory _ (Or.inl word)).elim (·.trans (h.capRefs.highEmpty x hx p a oldCap o ho al)) id + have pageBase x (hx : x ∈ OS) p m a v (cap : capA st out x = .PageTable p m a v) : + p ∈ Pt ∧ H p = some (.other 12) := by + by_cases ex : x = slot + · subst x; rw [post.cap] at cap; cases cap + exact ⟨h.pageTables slot hx ptr mapped _ _ old, h.pageObjects slot hx ptr mapped _ _ old⟩ + · have prior := (post.other x hx ex).symm.trans cap + exact ⟨h.pageTables x hx p m a v prior, h.pageObjects x hx p m a v prior⟩ + have highObj : HvObjects st H OS out := + fun x hx p m a c => h.highObjects x hx p m a ((highCaps x hx p m a).1 c) + have ept : EptPlaced st H OS Pt out := by + intro x hx p level m a v c + have oldCap := (same x hx (.Ept p level m a v) (by intro e; cases e) (by intro e; cases e)).1 c + exact h.eptRoots x hx p level m a v oldCap + have closed t (ht : t ∈ Kt) (level : Lv t < 3) (o : U64) (ho : o.val < 4096) (al : o.val % 8 = 0) + (tag : L.mem out (wa t o) &&& 3#u64 = 3#u64) : + wa (L.mem out (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + have word : PtW Pt (wa t o) := ⟨t, h.place.tables (h.kernelTables.1 ht), o, ho, al, rfl⟩ + rcases post.memory _ (Or.inl word) with eq | empty + · rw [eq] at tag ⊢ + exact h.kernelClosed t ht level o ho al tag + · rw [empty] at tag; cases tag + have unchanged : S1aRootSlots st (OS \ {slot}) Kt n out := + h.rootSlotsOfZero (fun x hx _ => ⟨x, hx.1, (post.other x hx.1 hx.2).symm⟩) + (fun b hb => post.memory b (Or.inl hb)) + have rootSlots : S1aRootSlots st OS Kt n out := by + constructor + · intro x hx p m a c + exact unchanged.native x ⟨hx, by rintro rfl; rw [post.cap] at c; cases c⟩ p m a c + · intro x hx p m a v c + exact unchanged.stage2 x ⟨hx, by rintro rfl; rw [post.cap] at c; cases c⟩ p m a v c + · intro x hx p m a c + exact unchanged.highCopies x ⟨hx, by rintro rfl; rw [post.cap] at c; cases c⟩ p m a c + · intro x hx p m a c + exact unchanged.highPrivate x ⟨hx, by rintro rfl; rw [post.cap] at c; cases c⟩ p m a c + have link : ∀ p ∈ Hr, + wa (L.mem out (wa p 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE = wa p 4096#u64 := by + intro p hp; rw [post.headers p hp]; exact h.highLink p hp + have domain : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n out := + ⟨post.lookup, root, h.core.heap, paths, refs, rootSlots, highSet, link, highObj, ept, + (fun x hx p m a v e => (pageBase x hx p m a v e).2), closed⟩ + have samePtr x (hx : x ∈ OS) : ptrA (capA st out x) = ptrA (capA st s x) := by + by_cases ex : x = slot + · subst x; rw [old, post.cap, ptrA_pt, ptrA_pt] + · rw [post.other x hx ex] + have sameKind x (hx : x ∈ OS) : kindA (capA st out x) = kindA (capA st s x) := by + by_cases ex : x = slot + · subst x; rw [old, post.cap]; rfl + · rw [post.other x hx ex] + have kinds' : KindA st OS out := by + constructor + intro x hx y hy rx ry eq + rw [samePtr x hx, samePtr y hy] at eq + rw [sameKind x hx, sameKind y hy] + have key := reflect RngKeyA ⟨fun _ => RngKeyA.pt _ _ _ _, fun _ => RngKeyA.pt _ _ _ _⟩ + exact kinds.kind x hx y hy ((key x hx).1 rx) ((key y hy).1 ry) eq + exact { + core := ⟨post.lookup, domain.recoverWalk heap kinds', root, stage1, stage2, h.core.heap⟩ + place := by rw [post.table.1, post.table.poolSet_eq]; exact h.place + poolCaps := h.poolCaps.zero post.table poolWord + (fun x hx p a => same x hx (.AsidPool p a) (by intro e; cases e) (by intro e; cases e)) + capRefs := refs + paths := paths + pageTables := fun x hx p m a v c => (pageBase x hx p m a v c).1 + footprint := h.footprint + pageObjects := domain.pageObjects + nativeRoots := fun x hx p m a c => h.nativeRoots x hx p m a ((nativeCaps x hx p m a).1 c) + eptRoots := ept + highObjects := highObj + highHeaders := fun x hx p m a c => by + have hp : p ∈ Hr := by rw [highSet]; exact ⟨x, hx, m, a, c⟩ + rw [post.headers p hp] + exact h.highHeaders x hx p m a ((highCaps x hx p m a).1 c) + highLink := link + highRoots := highSet + highFootprint := h.highFootprint + kernelTables := h.kernelTables + kernelClosed := closed + rootSlots := rootSlots } + +/-- The mapped PageTable Unmap dispatcher returns full R2 on the same heap, +slots and footprint, including when finality rejects the request. -/ +theorem syscall.decode_invocation.unmapMappedExactR2 + {A : Type _} {ar : machine.Arch A} {Cs Vc Ub U Ac Rp Nt : Set U64} + {K : capability.Cap → Prop} {Ty : S → Prop} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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 + (.PageTable ptr true a va) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr true a va)) + (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + (arch : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s arch fl4_abi.label.ARMPageTableUnmap len slot (.PageTable ptr true a va) + blk call don fp buf extra ⦃ _ q _ => S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa q ⦄ := by + have hiObj r (hr : r ∈ Hr) : H r = some (.other 13) := by + rw [h.highRoots] at hr + obtain ⟨x, hx, m, q, hc⟩ := hr + exact h.highObjects x hx r m q hc + have old := okinj ((capA_eq s slot).symm.trans cap) + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + refine WP.spec_mono + (vspace.decode_page_table.unmapMappedEffect hA hPl h.core place I D P B cap h.pageTables h.eptRoots + h.pageObjects h.highObjects hiObj ptKs arch len buf) ?_ + rintro ⟨_, q, _⟩ (eq | cleared) + · subst q; exact h + · exact h.ofClearedPageTable place P.heap kinds old cleared + +/-- The already-unmapped PageTable case returns full R2 without changing +the object or any ASID or VSpace word. -/ +theorem syscall.decode_invocation.unmapUnmappedExactR2 + {A : Type _} {ar : machine.Arch A} {Cs Vc Ub U Ac Rp Nt : Set U64} + {K : capability.Cap → Prop} {Ty : S → Prop} {ia ie : Nat} + {extra : Aeneas.Std.Array obj.Slot 3#usize} + (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s)) + (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 + (.PageTable ptr false a va) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s extra slot) (B : SysL st H Cs OS ia ie s) + (cap : obj.Slot.cap st slot s = ok (.PageTable ptr false a va)) + (arch : A) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s arch fl4_abi.label.ARMPageTableUnmap len slot (.PageTable ptr false a va) + blk call don fp buf extra ⦃ _ q _ => S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n q ⦄ := by + have old := okinj ((capA_eq s slot).symm.trans cap) + obtain ⟨_, _, _, kinds, _, _⟩ := B.sys.stz.1.1.mdbS + have key : s1aTableKey (capA st s slot) = some (0, ptr) := by rw [old]; rfl + have last y (hy : y ∈ OS) (ne : y ≠ slot) : ¬ NmC st y ptr s := by + intro names + obtain ⟨m, b, v, c⟩ : ∃ m b v, capA st s y = .PageTable ptr m b v := by + rcases NmC_iff.mp names with plain | ⟨l, m, b, v, ept⟩ + · exact plain + · obtain ⟨_, _, _, bad⟩ := kinds.pt_of P.src hy old (by rw [ept]; exact RngKeyA.ept _ _ _ _ _) + (by rw [ept, ptrA_ept]) + rw [ept] at bad + cases bad + exact ne (h.capRefs.unique slot P.src y hy (0, ptr) key (by rw [c]; rfl) (by rw [old]; rfl)) + unfold syscall.decode_invocation + rw [cur_thread_ok, bind_ok] + unfold vspace.decode + rw [cur_thread_ok, bind_ok] + refine vspace.decode_page_table.unmapUnmappedInvariant I D P cap h ?_ arch len buf + intro q base mem written others + have core := h.core.resetUnmappedPageTable place base mem (h.eptRoots.unmZ h.core P.heap h.pageTables) + old written others + have unmapped : UnmCap (capA st q slot) ptr 4096 := Or.inl ⟨rfl, 0#u64, 0#u64, written⟩ + have table : TabKeep st s q := ⟨base, fun i => by rw [base]; exact mem _ (Or.inr (asW_at (L.ksb s) i))⟩ + have hdr : HrW st Hr s q := fun r hr => mem _ + (Or.inl ⟨r, place.tables (place.high.sub hr), 4088#u64, by decide, by decide, rfl⟩) + have absent1 : ¬ VsReach st (PoolSet st Pp q) ∅ Lv q ptr := fun reach => + core.lookup.unmR1 P.src unmapped (core.stage1.sub.reach (by simp) reach) + have absent2 : ¬ S2Reach st (PoolSet st Pp q) Re bits q ptr := fun reach => + core.lookup.unmR2 P.src unmapped (core.stage2.sub.reach reach) + exact h.ofClearedPageTable place P.heap kinds old + ⟨core.lookup, table, hdr, last, mem.vsz, written, others, absent1, absent2, + fun _ ho al => core.lookup.unmZ P.src unmapped ho al⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2UnmapRoute.lean b/proofs/Fl4ProofsA64/P1/S1aR2UnmapRoute.lean new file mode 100644 index 000000000..061485dfb --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2UnmapRoute.lean @@ -0,0 +1,80 @@ +/- +P1 (aarch64): obtain concrete PageTable Unmap lookup from exact route backing. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2PathReference +import Fl4ProofsA64.P1.S1aR2UnmapS1 +import Fl4ProofsA64.P1.S1aR2UnmapS2 + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {s : S} + {H : Heap} {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} + +private theorem VsNm.tableWord {ptr b : U64} (parent : VsNm st (PoolSet st Pp s) ∅ Lv s ptr b) : + (L.mem s b &&& 3#u64) = 3#u64 ∧ wa (L.mem s b &&& vspace.ADDR_MASK) layout.PPTR_BASE = ptr := by + obtain ⟨_, _, _, _, _, _, _, tag, target⟩ := parent + exact ⟨tag, target⟩ + +private theorem S2Nm.tableWord {ptr b : U64} (parent : S2Nm st (PoolSet st Pp s) Re bits s ptr b) : + (L.mem s b &&& 3#u64) = 3#u64 ∧ wa (L.mem s b &&& ept.ADDR_MASK) layout.PPTR_BASE = ptr := by + obtain ⟨_, _, _, _, _, _, _, tag, target⟩ := parent + exact ⟨tag, target⟩ + +/-- Mapped PageTable capabilities locate their parent through their saved +references in either stage. Raw reachability is classified before the walk. -/ +theorem S1aRouteFacts.recoverWalk (h : S1aRouteFacts st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (heap : HeapOK H) (kinds : KindA st OS s) : + PtFndAll st OS Pp Lv Re bits n s := by + intro x hx ptr a v cap + refine ⟨h.root.pageTableNoRoot kinds hx cap, ?_, ?_⟩ + · intro b parent + obtain ⟨edge, target⟩ := parent.tableWord + obtain ⟨asid, sh, base, p, o, path, deep, width, al, rfl, range⟩ := + h.classifyPageTableParent2 parent + have masks : ept.ADDR_MASK = vspace.ADDR_MASK := UScalar.eq_of_val_eq (by + simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + have child := path.child deep width al range edge + rw [← masks, target] at child + have below : sh - 9 < s1aTopShift 1#u64 n := by + have hi := path.geometry.2.elim (fun h => h.1.le) (fun h => h.1.le) + omega + obtain ⟨id, saved⟩ := h.paths.childRef h.capRefs child below hx cap + subst asid + have typed k va t (p : S1aPath st Pp n s 1#u64 a k va t) : k = 12 + 9 * Re t := + (show _ ∧ _ ∧ _ from h.paths.tables _ _ _ _ _ p).2.1 + obtain ⟨raw, root, g, ⟨entry, kind, found, geom⟩, walk⟩ := + path.unmapFind2 typed deep width al range edge target saved + exact ⟨raw, root, g, entry.find, kind, found, geom, walk⟩ + · intro b parent + obtain ⟨edge, target⟩ := parent.tableWord + obtain ⟨tag, asid, sh, base, p, o, stage, path, deep, width, al, rfl, range⟩ := + h.classifyPageTableParent1 heap hx cap parent + have no2 : tag ≠ 1#u64 := by rcases stage with rfl | rfl <;> decide + have child := path.child deep width al range edge + rw [target] at child + have below : sh - 9 < s1aTopShift tag n := by + have hi := path.geometry.2.elim (fun h => h.1.le) (fun h => h.1.le) + omega + obtain ⟨id, saved⟩ := h.paths.childRef h.capRefs child below hx cap + subst asid + have typed k va t (p : S1aPath st Pp n s tag a k va t) : k + 9 * Lv t = 39 := by + have level := h.paths.tables _ _ _ _ _ p + rw [ite_eq_right no2] at level + exact level.2 + obtain ⟨raw, root, shift, level, ⟨entry, start⟩, walk⟩ := + path.unmapFind1 no2 typed deep width al range edge target (by simpa [s1aCapAddress, no2] using saved) + refine ⟨raw, root, shift, level, entry.find, ?_, ?_, walk⟩ + · rcases start with ⟨tag, _⟩ | ⟨tag, _⟩ <;> rw [tag] <;> decide + · rcases start with high | ⟨native, rootEq, shEq, levelEq⟩ + · exact Or.inl high + · have masked : raw &&& ~~~3#u64 = raw := and_not_of raw 3#u64 native + exact Or.inr ⟨by rw [native]; decide, rootEq.trans masked.symm, + shEq.trans (show vspace.TOP_LEVEL_SHIFT = 39#u64 by unfold vspace.TOP_LEVEL_SHIFT; rfl).symm, levelEq⟩ + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2UnmapS1.lean b/proofs/Fl4ProofsA64/P1/S1aR2UnmapS1.lean new file mode 100644 index 000000000..a45b5c1d0 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2UnmapS1.lean @@ -0,0 +1,163 @@ +/- +P1 (aarch64): execute a native or HighVSpace PageTable Unmap along an exact path. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2UnmapWalk +import Fl4ProofsA64.P1.S1aR2UnmapAddress + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {s : S} + {Pp : Set U64} {Lv : U64 → Nat} {n tag asid table ptr va : U64} {sh base target : Nat} + +/-- The parameters with which Stage-1 Unmap starts for an active ASID. -/ +def S1aUnmapStart1 (st : machine.Store S) [L : LawfulStore st] + (Pp : Set U64) (s : S) (asid raw table shift depth : U64) : Prop := + ActiveAsidRoot st Pp s asid raw ∧ + (((raw &&& 3#u64) = 2#u64 ∧ + table = wa (L.mem s (wa (raw &&& ~~~3#u64) 4088#u64) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∧ + shift = 30#u64 ∧ depth = 1#u64) ∨ + ((raw &&& 3#u64) = 0#u64 ∧ table = raw ∧ shift = 39#u64 ∧ depth = 0#u64)) + +private theorem stage1Width {tag n : U64} (notStage2 : tag ≠ 1#u64) (sh : Nat) : + s1aTableWidth tag n sh ≤ 4096 := by + simp only [s1aTableWidth, ite_eq_right notStage2] + split + · split <;> decide + · decide + +private theorem slotEnd {v o k : Nat} (bound : o < 4096) : + v + o / 8 * 2 ^ k + 2 ^ k ≤ v + 2 ^ (k + 9) := by + have le := Nat.mul_le_mul_right (2 ^ k) (show o / 8 + 1 ≤ 512 by omega) + rw [Nat.add_mul, Nat.one_mul] at le + rw [pow_add, Nat.mul_comm (2 ^ k) (2 ^ 9)] + simpa only [← Nat.add_assoc, show (2 : Nat) ^ 9 = 512 from rfl] using Nat.add_le_add_left le v + +set_option maxHeartbeats 2000000 in +/-- Stop the abstract trace at an ancestor of the wanted table. The actual +unmap loop has the same continuation at that ancestor. -/ +theorem S1aPath.unmapContinue1 (p : S1aPath st Pp n s tag asid sh base table) + (stage : tag ≠ 1#u64) + (typed : ∀ k b t, S1aPath st Pp n s tag asid k b t → k + 9 * Lv t = 39) + (targetLevel : target + 9 * Lv ptr = 39) (below : target < sh) + (lo : base ≤ va.val) (hi : va.val < base + 2 ^ (sh + 9)) + {shift level : U64} (shiftEq : shift.val = sh) (levelEq : shift.val + 9 * level.val = 39) : + ∃ raw first top start, S1aUnmapStart1 st Pp s asid raw first top start ∧ + vspace.unmap_page_table_loop st s va ptr first top start = + vspace.unmap_page_table_loop st s va ptr table shift level := by + induction p generalizing shift level with + | native entry kind => + have hsh : shift = 39#u64 := UScalar.eq_of_val_eq shiftEq + have hlv : level = 0#u64 := UScalar.eq_of_val_eq (by change level.val = 0; omega) + exact ⟨_, _, _, _, ⟨entry, Or.inr ⟨kind, rfl, hsh, hlv⟩⟩, rfl⟩ + | high entry kind _ => + have hsh : shift = 30#u64 := UScalar.eq_of_val_eq shiftEq + have hlv : level = 1#u64 := UScalar.eq_of_val_eq (by change level.val = 1; omega) + exact ⟨_, _, _, _, ⟨entry, Or.inl ⟨kind, rfl, hsh, hlv⟩⟩, rfl⟩ + | stage2 => exact (stage rfl).elim + | @child taskTag a t o parentSh parentBase parent deeper range align user valid ih => + let slot := wa t o + let next := wa (L.mem s slot &&& vspace.ADDR_MASK) layout.PPTR_BASE + have wanted : next ≠ ptr := by + intro eq + have here := typed _ _ _ (S1aPath.child parent deeper range align user valid) + change parentSh - 9 + 9 * Lv next = 39 at here + rw [eq] at here + omega + let parentShift := s1aWalkWord parentSh + let parentLevel := s1aWalkWord (level.val - 1) + have ps : parentShift.val = parentSh := s1aWalkWord.val (by omega) + have pl : parentLevel.val = level.val - 1 := s1aWalkWord.val (by omega) + have parentBound := typed _ _ _ parent + have parentDepth : parentShift.val + 9 * parentLevel.val = 39 := by omega + have live : parentLevel < 3#u64 := by change parentLevel.val < 3; omega + have shiftBack : ws parentShift 9#u64 = shift := UScalar.eq_of_val_eq (by + simp [core.num.U64.wrapping_sub_val_eq, ps, U64.size_def, U64.numBits] + omega) + obtain ⟨lv, step, lvEq⟩ := spec_exA (U64.add_spec (x := parentLevel) (y := 1#u64) (by scalar_tac)) + have lvSame : lv = level := UScalar.eq_of_val_eq (by + change lv.val = parentLevel.val + 1 at lvEq + omega) + subst lv + have childEnd : parentSh - 9 + 9 = parentSh := by omega + rw [childEnd] at hi + have limit := lt_of_lt_of_le range (stage1Width stage parentSh) + have entry : vspace.entry_addr t va parentShift = ok slot := by + exact vspace.entry_addr.ofInterval (base := parentBase) (by omega) + (by simpa only [ps] using parent.baseAligned) limit align + (by simpa only [ps] using lo) (by simpa only [ps] using hi) + obtain ⟨r, t0, top, l0, start, pre⟩ := ih stage typed (by omega) (by omega) + (lt_of_lt_of_le hi (slotEnd (k := parentSh) limit)) ps parentDepth + have one := vspace.unmap_page_table_loop.routeStep (s := s) (ptr := ptr) live + (by omega : 12 < parentShift.val) entry valid step + dsimp only at one + rw [ite_eq_right wanted, shiftBack] at one + exact ⟨r, t0, top, l0, start, pre.trans one⟩ + +/-- Following the saved Stage-1 reference reaches the exact parent word. -/ +theorem S1aPath.unmapFind1 (p : S1aPath st Pp n s tag asid sh base table) + (stage : tag ≠ 1#u64) + (typed : ∀ k b t, S1aPath st Pp n s tag asid k b t → k + 9 * Lv t = 39) + {o : U64} (deep : 12 < sh) (width : o.val < s1aTableWidth tag n sh) (align : o.val % 8 = 0) + (range : s1aUserRange tag n (base + o.val / 8 * 2 ^ sh) (2 ^ sh)) + (valid : L.mem s (wa table o) &&& 3#u64 = 3#u64) + (next : wa (L.mem s (wa table o) &&& vspace.ADDR_MASK) layout.PPTR_BASE = ptr) + (saved : va.val = base + o.val / 8 * 2 ^ sh) : + ∃ raw first top start, S1aUnmapStart1 st Pp s asid raw first top start ∧ + vspace.unmap_page_table_loop st s va ptr first top start = ok (some (wa table o)) := by + have child := p.child deep width align range valid + have targetDepth := typed _ _ _ child + rw [next] at targetDepth + have depth := typed _ _ _ p + let level := s1aWalkWord (Lv table) + let shift := s1aWalkWord sh + have val : level.val = Lv table := s1aWalkWord.val (by omega) + have shiftVal : shift.val = sh := s1aWalkWord.val (by omega) + have live : level < 3#u64 := by change level.val < 3; omega + have bound := lt_of_lt_of_le width (stage1Width stage sh) + have pos : 0 < (2 : Nat) ^ sh := by positivity + have large : va.val < base + o.val / 8 * 2 ^ sh + 2 ^ sh := by omega + obtain ⟨r, t0, sh0, l0, start, walk⟩ := p.unmapContinue1 (level := level) stage typed + targetDepth (by omega : sh - 9 < sh) (by omega) + (lt_of_lt_of_le large (slotEnd (k := sh) bound)) shiftVal (by omega) + have entry : vspace.entry_addr table va shift = ok (wa table o) := + vspace.entry_addr.ofInterval (base := base) (by omega) + (by simpa only [shiftVal] using p.baseAligned) bound align + (by rw [shiftVal, saved]) (by simpa only [shiftVal] using large) + obtain ⟨_, advance, _⟩ := spec_exA (U64.add_spec (x := level) (y := 1#u64) (by scalar_tac)) + have found := vspace.unmap_page_table_loop.routeStep (s := s) (ptr := ptr) live + (by omega : 12 < shift.val) entry valid advance + dsimp only at found + rw [ite_eq_left next] at found + exact ⟨r, t0, sh0, l0, start, walk.trans found⟩ + +/-- Every native or HighVSpace user path is also a raw Stage-1 reach. -/ +theorem S1aPath.toStage1 (p : S1aPath st Pp n s tag asid sh base table) + (stage : tag ≠ 1#u64) + (typed : ∀ k b t, S1aPath st Pp n s tag asid k b t → k + 9 * Lv t = 39) + (highLevel : ∀ a raw, ActiveAsidRoot st Pp s a raw → (raw &&& 3#u64) = 2#u64 → + Lv (raw &&& ~~~3#u64) = 0) : + VsReach st (PoolSet st Pp s) ∅ Lv s table := by + induction p with + | native entry kind => + obtain ⟨_, o, _, ho, al, _, pool, hp, _, word, nz⟩ := entry + subst_vars + exact .root0 hp ho al nz kind + | @high a raw entry kind valid => + have rootLevel := highLevel a raw entry kind + obtain ⟨_, o, _, ho, al, _, pool, hp, _, word, _⟩ := entry + subst_vars + exact .step (.root2 hp ho al kind) (by omega) (by decide) (by decide) valid + | stage2 => exact (stage rfl).elim + | @child k a t o sh base path deep width aligned range edge ih => + have depth := typed _ _ _ path + have bound := lt_of_lt_of_le width (stage1Width stage sh) + exact .step (ih stage typed) (by omega) bound aligned edge + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2UnmapS2.lean b/proofs/Fl4ProofsA64/P1/S1aR2UnmapS2.lean new file mode 100644 index 000000000..44a156e7e --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2UnmapS2.lean @@ -0,0 +1,227 @@ +/- +P1 (aarch64): execute a Stage-2 PageTable Unmap along an exact IPA path. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2UnmapWalk +import Fl4ProofsA64.P1.S1aR2UnmapAddress +import Fl4ProofsA64.P1.S1aR2MapStage2 + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {s : S} + {Pp : Set U64} {Re : U64 → Nat} {n asid table ptr va : U64} {sh base target : Nat} + +private def indexBits (n : U64) (sh : Nat) := + if sh = s1aTopShift 1#u64 n then s1aIpaWidth n - sh else 9 + +private theorem stage2Width (n : U64) (sh : Nat) : + s1aTableWidth 1#u64 n sh = 8 * 2 ^ indexBits n sh := by + unfold indexBits s1aTableWidth + split <;> rfl + +private theorem stage2Bounds (n : U64) : + 40 ≤ s1aIpaWidth n ∧ s1aTopShift 1#u64 n ≤ 39 ∧ + s1aTopShift 1#u64 n ≤ s1aIpaWidth n ∧ s1aIpaWidth n - s1aTopShift 1#u64 n ≤ 10 := by + simp only [s1aIpaWidth, s1aTopShift, show (1#u64 : U64) ≠ 0#u64 by decide, + show (1#u64 : U64) ≠ 2#u64 by decide, ite_false] + split + · decide + · split <;> decide + +private theorem S1aPath.ipaInterval (p : S1aPath st Pp n s 1#u64 asid sh base table) : + sh + indexBits n sh ≤ s1aIpaWidth n ∧ indexBits n sh ≤ 10 ∧ 2 ^ (sh + indexBits n sh) ∣ base := by + have ⟨ipaMin, topMax, topFit, topWidth⟩ := stage2Bounds n + rcases p.geometry with ⟨levels, ⟨top, origin⟩ | ⟨below, _⟩⟩ + · simp only [indexBits, top, ite_true] + simp only [show (1#u64 : U64) ≠ 2#u64 by decide, ite_false] at origin + exact ⟨by omega, topWidth, origin ▸ dvd_zero _⟩ + · have max : sh ≤ 30 := by rcases levels with e | e | e | e <;> omega + rw [indexBits, ite_eq_right below.ne] + exact ⟨by omega, by decide, p.baseAligned⟩ + +private theorem maskVal (n : U64) (sh : Nat) (small : indexBits n sh ≤ 10) : + (s1aWalkWord (2 ^ indexBits n sh - 1)).val = 2 ^ indexBits n sh - 1 := by + apply s1aWalkWord.val + have bound : (2 : Nat) ^ indexBits n sh ≤ 2 ^ 10 := Nat.pow_le_pow_right (by decide) small + omega + +/-- Stage-2 Unmap's starting geometry and ASID lookup. -/ +def S1aUnmapStart2 (st : machine.Store S) [L : LawfulStore st] + (Pp : Set U64) (s : S) (n asid raw table : U64) (g : ept.S2Geom) : Prop := + ActiveAsidRoot st Pp s asid raw ∧ raw &&& 3#u64 = 1#u64 ∧ + ept.find st s asid = ok (.Ok table) ∧ ept.geom n = ok g + +private theorem find2 {raw : U64} (entry : ActiveAsidRoot st Pp s asid raw) (kind : raw &&& 3#u64 = 1#u64) : + ept.find st s asid = ok (.Ok (raw &&& ~~~3#u64)) := by + unfold ept.find + rw [entry.find, bind_ok] + simp only [core.result.Result.Insts.CoreOpsTry.branch, bind_ok, lift, vspace.ROOT_TAG, vspace.ROOT_S2, kind] + rfl + +private theorem routeWidth {p : S1aPath st Pp n s 1#u64 asid sh base table} {o : U64} + (bound : o.val < s1aTableWidth 1#u64 n sh) + (sub : sh < s1aTopShift 1#u64 n) : + base + o.val / 8 * 2 ^ sh + 2 ^ sh ≤ base + 2 ^ (sh + 9) := by + rw [stage2Width, indexBits, ite_eq_right sub.ne] at bound + have scaled := Nat.mul_le_mul_right (2 ^ sh) (show o.val / 8 + 1 ≤ 512 by omega) + rw [Nat.add_mul, Nat.one_mul] at scaled + rw [pow_add, Nat.mul_comm (2 ^ sh) (2 ^ 9)] + simpa only [← Nat.add_assoc, show (2 : Nat) ^ 9 = 512 from rfl] using Nat.add_le_add_left scaled base + +set_option maxHeartbeats 2500000 in +/-- The concrete Stage-2 unmap loop reaches the continuation at any ancestor +selected by the saved IPA. -/ +theorem S1aPath.unmapContinue2 (p : S1aPath st Pp n s 1#u64 asid sh base table) + (typed : ∀ k b t, S1aPath st Pp n s 1#u64 asid k b t → k = 12 + 9 * Re t) + (targetLevel : target = 12 + 9 * Re ptr) (below : target < sh) + (lo : base ≤ s1aCapAddress 1#u64 n va) + (hi : sh < s1aTopShift 1#u64 n → s1aCapAddress 1#u64 n va < base + 2 ^ (sh + 9)) + {shift mask rem : U64} (shiftEq : shift.val = sh) + (maskEq : mask.val = 2 ^ indexBits n sh - 1) (remEq : shift.val = 12 + 9 * rem.val) : + ∃ raw first g, S1aUnmapStart2 st Pp s n asid raw first g ∧ + ept.unmap_table_loop st s va ptr first g.top_shift g.top_mask (ws g.levels 1#u64) = + ept.unmap_table_loop st s va ptr table shift mask rem := by + generalize stage : (1#u64 : U64) = k at p typed hi maskEq + induction p generalizing shift mask rem with + | native => cases stage + | high => cases stage + | @stage2 a raw entry kind => + obtain ⟨g, gOk, top, _, topMask, _, levels⟩ := spec_exists_u (ept.geom.exact n) + have shEq : g.top_shift = shift := UScalar.eq_of_val_eq (top.trans (by simpa only [stage] using shiftEq.symm)) + have widthEq : g.top_mask = mask := UScalar.eq_of_val_eq (by + rw [topMask, top, maskEq, indexBits] + simp only [stage, ite_true]) + have remaining : ws g.levels 1#u64 = rem := UScalar.eq_of_val_eq (by + rw [wsub1_le (by rcases levels with ⟨l, _⟩ | ⟨l, _⟩ <;> omega)] + have eq := congrArg UScalar.val shEq + rcases levels with ⟨l, t⟩ | ⟨l, t⟩ <;> omega) + exact ⟨_, _, g, ⟨entry, kind, find2 entry kind, gOk⟩, by rw [shEq, widthEq, remaining]⟩ + | @child k a t o pSh pBase parent deep width aligned range valid ih => + subst k + have here := S1aPath.child parent deep width aligned range valid + have topLe := parent.geometry.2.elim (fun a => a.1.le) (fun a => a.1.le) + have childBelow : pSh - 9 < s1aTopShift 1#u64 n := by omega + have lo' := lo + have hi' := hi childBelow + rw [Nat.sub_add_cancel (by omega : 9 ≤ pSh)] at hi' + let slot := wa t o + let next := wa (L.mem s slot &&& vspace.ADDR_MASK) layout.PPTR_BASE + have wanted : next ≠ ptr := by + intro eq + have d := typed _ _ _ here + change pSh - 9 = 12 + 9 * Re next at d + rw [eq] at d + omega + have P := typed _ _ _ parent + have Q := typed _ _ _ here + have ⟨fits, small, span⟩ := parent.ipaInterval + let shift' := s1aWalkWord pSh + let mask' := s1aWalkWord (2 ^ indexBits n pSh - 1) + let rem' := s1aWalkWord (rem.val + 1) + have sval : shift'.val = pSh := s1aWalkWord.val (by have := (stage2Bounds n).2.1; omega) + have rval : rem'.val = rem.val + 1 := s1aWalkWord.val (by have := (stage2Bounds n).2.1; omega) + have mval : mask'.val = 2 ^ indexBits n pSh - 1 := maskVal n pSh small + have lower : (9#u64 : U64).val ≤ shift'.val := by change 9 ≤ shift'.val; omega + have nextShift : ws shift' 9#u64 = shift := UScalar.eq_of_val_eq (by + rw [wsub_val lower, sval, shiftEq] <;> rfl) + have nextMask : 511#u64 = mask := UScalar.eq_of_val_eq (by + rw [maskEq, indexBits, ite_eq_right childBelow.ne]; rfl) + have live : rem' > 0#u64 := by change 0 < rem'.val; omega + obtain ⟨nr, step, nrEq⟩ := spec_ex_fd (U64.sub_spec (x := rem') (y := 1#u64) (by scalar_tac)) + have nrSame : nr = rem := UScalar.eq_of_val_eq (by + have e := nrEq.1 + change nr.val = rem'.val - 1 at e + omega) + subst nr + have entry : ept.entry_addr t va shift' mask' = ok slot := + ept.entry_addr.ofIpaInterval (n := n) (base := pBase) (width := indexBits n pSh) + (by have := (stage2Bounds n).2.1; omega) (by + have b : (2 : Nat) ^ indexBits n pSh ≤ 2 ^ 10 := Nat.pow_le_pow_right (by decide) small + omega) mval (by rwa [sval]) (by rwa [sval]) + (by rwa [← stage2Width]) aligned (by rwa [sval]) (by rwa [sval]) + have hereRem : shift'.val = 12 + 9 * rem'.val := by omega + obtain ⟨r, first, g, start, path⟩ := ih (by omega) (by omega) sval mval hereRem rfl typed + (fun sub => lt_of_lt_of_le hi' (routeWidth (p := parent) width sub)) + have one := ept.unmap_table_loop.routeStep (s := s) (ptr := ptr) live + (by omega : 12 < shift'.val) entry valid step + have maskSame : ept.ADDR_MASK = vspace.ADDR_MASK := UScalar.eq_of_val_eq (by + simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + dsimp only at one + rw [maskSame] at one + have ne : wa (L.mem s (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ≠ ptr := wanted + rw [ite_eq_right ne, nextShift, nextMask] at one + exact ⟨r, first, g, start, path.trans one⟩ + +/-- The saved Stage-2 reference finds its parent word, including when the +decoded PageTable cap sign-extends bit 47. -/ +theorem S1aPath.unmapFind2 (p : S1aPath st Pp n s 1#u64 asid sh base table) + (typed : ∀ k b t, S1aPath st Pp n s 1#u64 asid k b t → k = 12 + 9 * Re t) + {o : U64} (deep : 12 < sh) (width : o.val < s1aTableWidth 1#u64 n sh) (align : o.val % 8 = 0) + (range : s1aUserRange 1#u64 n (base + o.val / 8 * 2 ^ sh) (2 ^ sh)) + (valid : L.mem s (wa table o) &&& 3#u64 = 3#u64) + (next : wa (L.mem s (wa table o) &&& ept.ADDR_MASK) layout.PPTR_BASE = ptr) + (saved : s1aCapAddress 1#u64 n va = base + o.val / 8 * 2 ^ sh) : + ∃ raw first g, S1aUnmapStart2 st Pp s n asid raw first g ∧ + ept.unmap_table_loop st s va ptr first g.top_shift g.top_mask (ws g.levels 1#u64) = + ok (some (wa table o)) := by + have masks : ept.ADDR_MASK = vspace.ADDR_MASK := UScalar.eq_of_val_eq (by + simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + have child := p.child deep width align range valid + have targetDepth := typed _ _ _ child + rw [← masks, next] at targetDepth + have depth := typed _ _ _ p + have ⟨fits, small, span⟩ := p.ipaInterval + have size : sh ≤ 39 := by + rcases p.geometry.1 with e | e | e | e <;> omega + let rem := s1aWalkWord (Re table) + let shift := s1aWalkWord sh + let mask := s1aWalkWord (2 ^ indexBits n sh - 1) + have remVal : rem.val = Re table := s1aWalkWord.val (by omega) + have shVal : shift.val = sh := s1aWalkWord.val (by omega) + have mVal : mask.val = 2 ^ indexBits n sh - 1 := maskVal n sh small + have live : rem > 0#u64 := by change 0 < rem.val; omega + have pos : 0 < (2 : Nat) ^ sh := by positivity + have large : s1aCapAddress 1#u64 n va < base + o.val / 8 * 2 ^ sh + 2 ^ sh := by omega + obtain ⟨r, first, g, start, walk⟩ := p.unmapContinue2 (rem := rem) typed + targetDepth (by omega : sh - 9 < sh) (by omega) + (fun sub => lt_of_lt_of_le large (routeWidth (p := p) width sub)) shVal mVal (by omega) + have entry : ept.entry_addr table va shift mask = ok (wa table o) := + ept.entry_addr.ofIpaInterval (n := n) (base := base) (width := indexBits n sh) (by omega) + (by have b : (2 : Nat) ^ indexBits n sh ≤ 2 ^ 10 := Nat.pow_le_pow_right (by decide) small; omega) + mVal (by rwa [shVal]) (by rwa [shVal]) (by rwa [← stage2Width]) align + (by rw [shVal, saved]) (by rwa [shVal]) + obtain ⟨_, advance, _⟩ := spec_ex_fd (U64.sub_spec (x := rem) (y := 1#u64) (by scalar_tac)) + have found := ept.unmap_table_loop.routeStep (s := s) (ptr := ptr) live + (by omega : 12 < shift.val) entry valid advance + dsimp only at found + rw [ite_eq_left next] at found + exact ⟨r, first, g, start, walk.trans found⟩ + +/-- Every exact IPA path is also a raw Stage-2 reach. -/ +theorem S1aPath.toStage2 {bits : U64 → Nat} (p : S1aPath st Pp n s 1#u64 asid sh base table) + (typed : ∀ k b t, S1aPath st Pp n s 1#u64 asid k b t → + k = 12 + 9 * Re t ∧ s1aTableWidth 1#u64 n k ≤ 2 ^ bits t) : + S2Reach st (PoolSet st Pp s) Re bits s table := by + generalize stage : (1#u64 : U64) = k at p typed + induction p with + | native => cases stage + | high => cases stage + | @stage2 a raw entry kind => + obtain ⟨_, o, _, ho, al, _, pool, hp, _, word, _⟩ := entry + subst_vars + exact .root hp ho al kind + | @child k a t o sh base path deep width aligned range edge ih => + subst k + obtain ⟨depth, size⟩ := typed _ _ _ path + have maskSame : ept.ADDR_MASK = vspace.ADDR_MASK := UScalar.eq_of_val_eq (by + simp only [P0.Consts.ept.ADDR_MASK.val_eq, P0.Consts.vspace.ADDR_MASK.val_eq]) + rw [← maskSame] + exact .step (ih rfl typed) (by omega) (lt_of_lt_of_le width size) aligned edge + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2UnmapWalk.lean b/proofs/Fl4ProofsA64/P1/S1aR2UnmapWalk.lean new file mode 100644 index 000000000..9bd8d3597 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2UnmapWalk.lean @@ -0,0 +1,85 @@ +/- +P1 (aarch64): exact executable steps of the PageTable Unmap walks. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2MapWalk + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add +local notation "ws" => core.num.U64.wrapping_sub + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {s : S} + +/-- A non-leaf Stage-1 descriptor with both type bits set is followed. -/ +theorem vspace.is_table.ofTag {word shift : U64} (level : 12 < shift.val) + (tag : word &&& 3#u64 = 3#u64) : vspace.is_table word shift = ok true := by + have depth : shift > vspace.PAGE_BITS := by unfold vspace.PAGE_BITS; exact level + unfold vspace.is_table + rw [ite_eq_left depth, 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, show (1#u64 ||| 2#u64) = 3#u64 by decide, tag] + rfl + +/-- A non-leaf Stage-2 descriptor with both type bits set is followed. -/ +theorem ept.is_table.ofTag {word shift : U64} (level : 12 < shift.val) + (tag : word &&& 3#u64 = 3#u64) : ept.is_table word shift = ok true := by + have depth : shift > ept.PAGE_BITS := by unfold ept.PAGE_BITS; exact level + unfold ept.is_table + rw [ite_eq_left depth, eq_of_spec_fd P0.Consts.ept.D_VALID.spec, + eq_of_spec_fd P0.Consts.ept.D_TABLE_OR_PAGE.spec] + simp only [lift, bind_ok, show (1#u64 ||| 2#u64) = 3#u64 by decide, tag] + rfl + +/-- A Stage-1 Unmap step selects its parent slot or advances one table. -/ +theorem vspace.unmap_page_table_loop.routeStep {va ptr table sh level slot nextLevel : U64} + (live : level < 3#u64) (nonLeaf : 12 < sh.val) + (entry : vspace.entry_addr table va sh = ok slot) + (valid : L.mem s slot &&& 3#u64 = 3#u64) (advance : level + 1#u64 = ok nextLevel) : + let next := wa (L.mem s slot &&& vspace.ADDR_MASK) layout.PPTR_BASE + vspace.unmap_page_table_loop st s va ptr table sh level = + if next = ptr then ok (some slot) + else vspace.unmap_page_table_loop st s va ptr next (ws sh 9#u64) nextLevel := by + dsimp only + let next := wa (L.mem s slot &&& vspace.ADDR_MASK) layout.PPTR_BASE + have one : vspace.unmap_page_table_loop.body st s va ptr table sh level = + if next = ptr then ok (.done (some slot)) else ok (.cont (next, ws sh 9#u64, nextLevel)) := by + unfold vspace.unmap_page_table_loop.body + simp only [ite_eq_left live, entry, L.read_eq, vspace.is_table.ofTag nonLeaf valid, lift, + bind_ok, vspace.table_of, layout.pptr, ite_true, advance] + by_cases h : next = ptr <;> simp only [next] at h <;> simp [h, next] + unfold vspace.unmap_page_table_loop + conv_lhs => + rw [loop] + dsimp only + rw [one] + split <;> simp_all only [ite_true, ite_false, bind_ok] <;> rfl + +/-- A Stage-2 Unmap step selects its parent slot or advances one table. -/ +theorem ept.unmap_table_loop.routeStep {ipa ptr table sh mask rem slot nextRem : U64} + (live : rem > 0#u64) (nonLeaf : 12 < sh.val) + (entry : ept.entry_addr table ipa sh mask = ok slot) + (valid : L.mem s slot &&& 3#u64 = 3#u64) (advance : rem - 1#u64 = ok nextRem) : + let next := wa (L.mem s slot &&& ept.ADDR_MASK) layout.PPTR_BASE + ept.unmap_table_loop st s ipa ptr table sh mask rem = + if next = ptr then ok (some slot) + else ept.unmap_table_loop st s ipa ptr next (ws sh 9#u64) 511#u64 nextRem := by + dsimp only + let next := wa (L.mem s slot &&& ept.ADDR_MASK) layout.PPTR_BASE + have one : ept.unmap_table_loop.body st s ipa ptr table sh mask rem = + if next = ptr then ok (.done (some slot)) else ok (.cont (next, ws sh 9#u64, 511#u64, nextRem)) := by + unfold ept.unmap_table_loop.body + simp only [ite_eq_left live, entry, L.read_eq, ept.is_table.ofTag nonLeaf valid, lift, + bind_ok, ept.table_of, layout.pptr, ite_true, advance] + by_cases h : next = ptr <;> simp only [next] at h <;> simp [h, next] + unfold ept.unmap_table_loop + conv_lhs => + rw [loop] + dsimp only + rw [one] + split <;> simp_all only [ite_true, ite_false, bind_ok] <;> rfl + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aR2Zeroed.lean b/proofs/Fl4ProofsA64/P1/S1aR2Zeroed.lean new file mode 100644 index 000000000..0c06c0188 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aR2Zeroed.lean @@ -0,0 +1,110 @@ +/- +P1 (aarch64): R2 after a write that only keeps or clears the VSpace words (A64-S1A gen 41). + +A finalisation clears descriptors, ASID entries and nothing else, and drops its slot from the set R2 +reads. `S1aR2.zeroedOn` rebuilds every R2 field that follows from that; the caller supplies the five that +name a witnessing capability. Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aR2Loop +import Fl4ProofsA64.P1.S1aR2Shrink +import Fl4ProofsA64.P1.S1aR2UnmapRoute + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] + {H : Heap} {OS O' Pt Pp Tb Hr Hr' Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s q : S} + +/-- The VSpace placement holds for any smaller HighVSpace set. -/ +theorem S1aR2Place.monoHigh {kb : U64} (h : S1aR2Place Pt Pp Tb Hr Te Lv bits kb) (sub : Hr' ⊆ Hr) : + S1aR2Place Pt Pp Tb Hr' Te Lv bits kb := + ⟨h.pools, h.tables, h.granules, + ⟨sub.trans h.high.sub, fun R hR => h.high.lv R (sub hR), fun t ht o ho al R hR => h.high.tb t ht o ho al R (sub hR), + fun p hp o ho al R hR => h.high.pp p hp o ho al R (sub hR), fun R hR => h.high.asw R (sub hR)⟩, + ⟨h.stage2.sz, h.stage2.al, fun b hb R hR => h.stage2.hr b hb R (sub hR)⟩⟩ + +/-- R2 over the slots `O'` after a keep-or-clear step that leaves their capabilities alone. -/ +theorem S1aR2.zeroedOn (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) (heap : HeapOK H) (kinds : KindA st OS s) + (tab : TabKeepOrZero st s q) (mem : VsZ st (L.ksb s) Pt s q) (hdr : HrW st Hr s q) + (sub : O' ⊆ OS) (caps : ∀ y ∈ O', capA st q y = capA st s y) + (lookup : VsLk st H O' Pp Tb Te Kt Lv Re bits q) (root : RootAgreement st O' Pp q) + (stage1 : VsTyR st (L.ksb q) (PoolSet st Pp q) ∅ Tb Lv q) + (stage2 : S2TyR st n (PoolSet st Pp q) (HvRt st O' q) Te Re bits q) + (pools : S1aPoolCaps st H O' Pt Pp q) (paths : S1aPathBacking st H O' Pp Tb Te Lv Re bits n q) : + S1aR2 st H O' Pt Pp Tb (HvRt st O' q) Te Kt Lv Re bits n q := by + have old y (hy : y ∈ O') {c : capability.Cap} (eq : capA st q y = c) : capA st s y = c := (caps y hy).symm.trans eq + have highSub : HvRt st O' q ⊆ Hr := by + rintro p ⟨y, hy, m, a, eq⟩ + rw [h.highRoots] + exact ⟨y, sub hy, m, a, old y hy eq⟩ + have memory b (hb : PtW Pt b) := mem b (Or.inl hb) + have refs : S1aTableCaps st O' q := by + refine ⟨fun x hx y hy k kx ky => ?_, fun x hx y hy k kx ky none => ?_, fun x hx p a eq o ho al => ?_, + fun x hx p a eq o ho al => ?_⟩ + · rw [caps x hx] at kx ⊢ + rw [caps y hy] at ky ⊢ + exact h.capRefs.references x (sub hx) y (sub hy) k kx ky + · rw [caps x hx] at kx none + rw [caps y hy] at ky + exact h.capRefs.unique x (sub hx) y (sub hy) k kx ky none + · have prior := old x hx eq + exact (memory _ ⟨p, (h.nativeRoots x (sub hx) p false a prior).2, o, ho, al, rfl⟩).elim + (·.trans (h.capRefs.nativeEmpty x (sub hx) p a prior o ho al)) id + · have prior := old x hx eq + have live : p ∈ Hr := by rw [h.highRoots]; exact ⟨x, sub hx, false, a, prior⟩ + exact (memory _ ⟨_, h.highFootprint ⟨p, live, Or.inr ⟨rfl, rfl⟩⟩, o, ho, al, rfl⟩).elim + (·.trans (h.capRefs.highEmpty x (sub hx) p a prior o ho al)) id + have closed t (ht : t ∈ Kt) (depth : Lv t < 3) (o : U64) (bound : o.val < 4096) (al : o.val % 8 = 0) + (valid : L.mem q (wa t o) &&& 3#u64 = 3#u64) : + wa (L.mem q (wa t o) &&& vspace.ADDR_MASK) layout.PPTR_BASE ∈ Kt := by + rcases memory _ ⟨t, h.place.tables (h.kernelTables.1 ht), o, bound, al, rfl⟩ with eq | empty + · rw [eq] at valid ⊢ + exact h.kernelClosed t ht depth o bound al valid + · rw [empty] at valid + cases valid + have kindsAfter : KindA st O' q := ⟨fun x hx y hy kx ky same => by + rw [caps x hx] at kx same ⊢ + rw [caps y hy] at ky same ⊢ + exact kinds.kind x (sub hx) y (sub hy) kx ky same⟩ + have routes : S1aRouteFacts st H O' Pt Pp Tb (HvRt st O' q) Te Kt Lv Re bits n q := + ⟨lookup, root, h.core.heap, paths, refs, + h.rootSlotsOfZero (fun x hx _ => ⟨x, sub hx, (caps x hx).symm⟩) memory, rfl, + (fun p hp => by rw [hdr p (highSub hp)]; exact h.highLink p (highSub hp)), + (fun x hx p m a eq => h.highObjects x (sub hx) p m a (old x hx eq)), + (fun x hx => by rw [caps x hx]; exact h.eptRoots x (sub hx)), + (fun x hx p m a v eq => h.pageObjects x (sub hx) p m a v (old x hx eq)), closed⟩ + have placed : S1aR2Place Pt (PoolSet st Pp q) Tb (HvRt st O' q) Te Lv bits (L.ksb q) := by + rw [tab.1] + have narrow := h.place.monoHigh highSub + have poolSub := tab.poolSet (Pp := Pp) + exact ⟨poolSub.trans narrow.pools, narrow.tables, narrow.granules, + ⟨narrow.high.sub, narrow.high.lv, narrow.high.tb, fun p hp => narrow.high.pp p (poolSub hp), narrow.high.asw⟩, + narrow.stage2⟩ + exact { + core := ⟨lookup, routes.recoverWalk heap kindsAfter, root, stage1, stage2, h.core.heap⟩ + place := placed + poolCaps := pools + capRefs := refs + paths := paths + pageTables := fun x hx p m a v eq => h.pageTables x (sub hx) p m a v (old x hx eq) + footprint := h.footprint + pageObjects := routes.pageObjects + nativeRoots := fun x hx p m a eq => h.nativeRoots x (sub hx) p m a (old x hx eq) + eptRoots := routes.eptRoots + highObjects := routes.highObjects + highHeaders := fun x hx p m a eq => by + have live : p ∈ Hr := highSub ⟨x, hx, m, a, eq⟩ + rw [hdr p live] + exact h.highHeaders x (sub hx) p m a (old x hx eq) + highLink := routes.highLink + highRoots := rfl + highFootprint := fun b ⟨p, hp, which⟩ => h.highFootprint ⟨p, highSub hp, which⟩ + kernelTables := h.kernelTables + kernelClosed := closed + rootSlots := routes.rootSlots } + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aRtV.lean b/proofs/Fl4ProofsA64/P1/S1aRtV.lean index 9bf6f438f..4cd376b3f 100644 --- a/proofs/Fl4ProofsA64/P1/S1aRtV.lean +++ b/proofs/Fl4ProofsA64/P1/S1aRtV.lean @@ -54,7 +54,7 @@ variable {A : Type _} {ar : machine.Arch A} set_option maxHeartbeats 2000000 in /-- (gen 21) **The joint retype top with one more creation-end hook `J`** at the same `(H', OS')` (module docstring; `s1aRtV` is its instance at `J = True`; S1aPtStep's `untyped_s1aRtVPt` at `PtCap ∧ PtHG`). -/ -theorem untyped.decode.s1aRtVJ (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc' Ub' Pt Vc Ub : Set U64} {Z : U64 → Nat} +theorem untyped.decode.s1aRtVJH (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc' Ub' Pt Vc Ub : Set U64} {Z : U64 → Nat} {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) (Y : SymL st H Cs s0) @@ -67,18 +67,18 @@ theorem untyped.decode.s1aRtVJ (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc' Ub' Pt Vc (win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) → (H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ hi = p.val + 2 ^ sb.val)) → - J H' (OS1 ∪ NewSl dev nt us aligned win) s') : + WinHi st s' aligned nt us win.val → J H' (OS1 ∪ NewSl dev nt us aligned win) s') : untyped.decode st ar s0 a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => ∃ (H' : Heap) (OS' Vn Vc'' : Set U64), (ArmQIVAt st H Cs OS ia ie s0 H' OS' Vn s' ∧ TabKeep st s0 s' ∧ Vc'' ⊆ Vc ∪ Vn ∧ VcCap st Vc'' OS' s' ∧ S1aArmCol st H' Cs OS' Vc'' Ub s' ∧ S1aCapCol st H' OS' Ub s') ∧ J H' OS' s' ⦄ := by - refine WP.spec_mono (WP.spec_and (untyped.decode.blkI hA D P B hcap hfm a lbl len buf + refine WP.spec_mono (WP.spec_and (untyped.decode.blkIH hA D P B hcap hfm a lbl len buf (fun H' O s' => (RtArmI st H Cs OS s0 H' O s' ∧ S1aEndV st H Cs OS Vc Ub s0 H' O s') ∧ J H' O s') ⟨⟨RtArmI.init Y, S1aEndV.init C K hVC⟩, hJ0⟩ - fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp => + fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp WH => ⟨⟨UtEnd.rtArmI D P B Y hcap H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp, UtEnd.s1aEndV D P B hcap C K hal hVC H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp⟩, - hJ H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp⟩) + hJ H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp WH⟩) (untyped.decode.tabK hA D P B hcap hfm hvr a lbl len buf)) ?_ rintro ⟨r, s', a'⟩ ⟨⟨H', OS', B', hb', ⟨hR, hE⟩, hJ'⟩, hW⟩ have tk : TabKeep st s0 s' := TabKeep.ofW hvr hW fun _ h => h @@ -86,6 +86,29 @@ theorem untyped.decode.s1aRtVJ (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc' Ub' Pt Vc obtain ⟨Vn, Vc'', hVn, hVT, hsub, hC, hcol, hK⟩ := S1aEndV.fin P hvr hPN C B' hW hE exact ⟨H', OS', Vn, Vc'', ⟨hQ.reVn hVT hVn, tk, hsub, hC, hcol, hK⟩, hJ'⟩ +/-- The original post follows from the shared creation proof. -/ +theorem untyped.decode.s1aRtVJ (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc' Ub' Pt Vc Ub : Set U64} {Z : U64 → Nat} + {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s0 (.Untyped p sb fi dev) extra) + (P : SysPlace st H Cs H.frame Rp Nt OS s0 extra slot) (B : SysL st H Cs OS ia ie s0) (Y : SymL st H Cs s0) + (hcap : obj.Slot.cap st slot s0 = ok (.Untyped p sb fi dev)) (hfm : A64FrameMasks st s0) + (hvr : VrOK H.omega Sg Scs Z OS Vc' Ub' (L.ksb s0) Pt) (hPN : PoolNamed st OS s0) + (C : S1aArmCol st H Cs OS Vc Ub s0) (K : S1aCapCol st H OS Ub s0) (hal : ∀ b ∈ Ub, Aligned b) + (hVC : VcCap st Vc OS s0) (a : A) (lbl len buf : U64) (J : Heap → Set U64 → S → Prop) (hJ0 : J H OS s0) + (hJ : ∀ (H1 H' : Heap) (OS1 : Set U64) (s1 s' : S) (lo hi : Nat) (aligned nt us dest off win : U64), + UtEnd st H Cs OS s0 slot p sb dev H1 H' OS1 s1 s' lo hi aligned nt us dest off win → UtX H H1 lo hi us → + (win.val = 0 ∨ ∃ reset, UtArgs st s0 extra slot p sb fi dev reset aligned nt us dest off win) → + (H1 = H ∨ (dev = false ∧ (∃ v, cdt.ensure_no_children st s0 slot = ok (.Ok v)) ∧ lo = p.val ∧ + hi = p.val + 2 ^ sb.val)) → + J H' (OS1 ∪ NewSl dev nt us aligned win) s') : + untyped.decode st ar s0 a lbl len slot (.Untyped p sb fi dev) buf extra ⦃ r s' _ => + ∃ (H' : Heap) (OS' Vn Vc'' : Set U64), (ArmQIVAt st H Cs OS ia ie s0 H' OS' Vn s' ∧ TabKeep st s0 s' ∧ + Vc'' ⊆ Vc ∪ Vn ∧ VcCap st Vc'' OS' s' ∧ S1aArmCol st H' Cs OS' Vc'' Ub s' ∧ S1aCapCol st H' OS' Ub s') ∧ + J H' OS' s' ⦄ := + untyped.decode.s1aRtVJH hA D P B Y hcap hfm hvr hPN C K hal hVC a lbl len buf J hJ0 + fun H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp _ => + hJ H1 H' OS1 s1 s' lo hi aligned nt us dest off win E X hw hp + /-- **The joint retype top with one shared `Vn`** (module docstring; gen 21: `s1aRtVJ` at `J = True`). -/ theorem untyped.decode.s1aRtV (hA : P0.ArchTotal ar) {U Ac Sg Scs Vc' Ub' Pt Vc Ub : Set U64} {Z : U64 → Nat} {s0 : S} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot p sb fi : U64} {dev : Bool} diff --git a/proofs/Fl4ProofsA64/P1/S1aStep.lean b/proofs/Fl4ProofsA64/P1/S1aStep.lean index 7d684d66a..7c1a065cb 100644 --- a/proofs/Fl4ProofsA64/P1/S1aStep.lean +++ b/proofs/Fl4ProofsA64/P1/S1aStep.lean @@ -19,9 +19,21 @@ P1 (aarch64, A64-S1A gen 11): **one S1a step top over the `DecArmQZ2` arms, Unty `ArmQIAt.ptCap` (same `H`, `Pt`); Untyped by S1aPtStep's `untyped_s1aRtVPt` (`Pt' = PtOffR Pt lo hi ∪ NewPt …`); Assign by S1aPtCap's `AsgPost.ptCap` (same `H`, `Pt`); MakePool by S1aPtStep's `makePool_s1aPt` (same `Pt` at the pool heap and `OffR`). +* (gen 37, Architect 01:01Z item 1, closing I1) **`DevFrAl st OS' s'`** (S1aPtStep's) at the same end, from + `Df : DevFrAl st OS s` (new binder after `Cp`): `DecArmQZ2` by `ArmQIAt.devFr` (the cap-source clause at + `DevFrP`); Untyped by S1aDevFr's `untyped_s1aRtVDf` (`UtEnd.devFrN`); Assign by `AsgPost.devFr`; MakePool by + S1aDevFr's `makePool_s1aDf` (`DevFrAl.poolEnd`). * **`DecArmS1a`** := `DecArmQZ2 ∨ Untyped ∨ ASIDPool Assign ∨ ASIDControl MakePool` (gen 13: MakePool added); top **`syscall.decode_invocation.s1aStep`** (statement unchanged). +* (gen 39, Architect ruling L1) **`HvPt st Pt' OS' s'`** (S1aHvPt's: every `HighVSpace` cap's root in `Pt'`) beside + `PtCap`, from `Hv : HvPt st Pt OS s` (new binder after `Df`): `DecArmQZ2` by `ArmQIAt.hvPt`; Untyped by S1aHvPt's + `untyped_s1aRtVHv` (`UtEnd.hvPtN`, `Pt'` with the widened `NewPt`); Assign by `AsgPost.hvPt`; MakePool by S1aHvPt's + `makePool_s1aHv` (`HvPt.poolEnd`). + +Gen 41: the common post includes `HiCap511`, carried from `Hi` via the concrete Retype, +Assign and MakePool posts and the typed deletion / keeping dispatcher. + Named premises: none new (MdbSysZ's [P] `A64FrameMasks`, as `blkI`). Case facts: none new (a64's `armQZ2At` hypotheses, MdbPoolN's `PoolNamed`, and the column with `S1aCapCol` and aligned `Ub` at the start, as S1aRtTop). -/ @@ -29,6 +41,10 @@ import Fl4ProofsA64.P1.S1aArmZ2 import Fl4ProofsA64.P1.S1aRtV import Fl4ProofsA64.P1.S1aPoolEnd import Fl4ProofsA64.P1.S1aPtStep +import Fl4ProofsA64.P1.S1aDevFr +import Fl4ProofsA64.P1.S1aHiAsg +import Fl4ProofsA64.P1.S1aHiRetype +import Fl4ProofsA64.P1.S1aHiDispatch open Aeneas Aeneas.Std Result namespace Fl4ProofsA64.P1 @@ -48,7 +64,8 @@ variable (st) in def S1aStep (Cs Ub : Set U64) (ia ie : Nat) (s' : S) : Prop := ∃ (H' : Heap) (OS' Vc' Ub' Pt' : Set U64), SysL st H' Cs OS' ia ie s' ∧ SymL st H' Cs s' ∧ Ub' ⊆ Ub ∧ VcCap st Vc' OS' s' ∧ S1aArmCol st H' Cs OS' Vc' Ub' s' ∧ S1aCapCol st H' OS' Ub' s' ∧ - PtCap st Pt' OS' s' ∧ PtHG H' Pt' + PtCap st Pt' OS' s' ∧ HvPt st Pt' OS' s' ∧ PtHG H' Pt' ∧ DevFrAl st OS' s' ∧ HiCap511 st OS' s' ∧ + EptPlaced st H' OS' Pt' s' ∧ PtObjects st H' OS' s' ∧ HvObjects st H' OS' s' /-- **The arms of the S1a step top** (module docstring). -/ def DecArmS1a (cap : capability.Cap) (lbl : U64) : Prop := @@ -59,15 +76,20 @@ def DecArmS1a (cap : capability.Cap) (lbl : U64) : Prop := variable {Uq Pt : Set U64} {K : capability.Cap → Prop} {Ty : S → Prop} /-- **The S1a step top** (module docstring). -/ -theorem syscall.decode_invocation.s1aStep (hA : P0.ArchTotal ar) {s : S} {cap : capability.Cap} +theorem syscall.decode_invocation.s1aStep {Pp Tb Hr Te : Set U64} {Lv Re bits : U64 → Nat} + (hA : P0.ArchTotal ar) (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (hfm : A64FrameMasks st s) (hPN : PoolNamed st OS s) (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) - (Cp : PtCap st Pt OS s ∧ PtHG H Pt) (a : A) {lbl : U64} (hc : DecArmS1a cap lbl) + (Cp : PtCap st Pt OS s ∧ PtHG H Pt) (Df : DevFrAl st OS s) (Hv : HvPt st Pt OS s) (Hi : HiCap511 st OS s) + (Ep : EptPlaced st H OS Pt s) (objects : PtObjects st H OS s) + (highObjects : HvObjects st H OS s) (a : A) {lbl : U64} + (hc : DecArmS1a cap lbl) (hIq : ∀ irq, cap = .IrqHandler irq → (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) @@ -75,29 +97,34 @@ theorem syscall.decode_invocation.s1aStep (hA : P0.ArchTotal ar) {s : S} {cap : syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => S1aStep st Cs Ub ia ie s' ⦄ := by rcases hc with hc | ⟨p, sb, fi, dev, rfl⟩ | ⟨pp, ab, rfl, hl⟩ | ⟨rfl, hl⟩ - · refine WP.spec_mono (syscall.decode_invocation.armQZ2_s1a (Vc := Vc) (Ub := Ub) hA I hKZ hPI D P B Y hcap hks - a hc hIq hSC len blk call don fp buf) fun r d => ?_ + · refine WP.spec_mono (WP.spec_and + (syscall.decode_invocation.armQZ2_s1a (Vc := Vc) (Ub := Ub) hA I hKZ hPI D P B Y hcap hks + a hc hIq hSC len blk call don fp buf) + (syscall.decode_invocation.armQZ2_hi hA hPl I W Hv hPI D P B Y hcap hks a hc hIq hSC len blk call don fp buf)) + fun r ⟨d, hi⟩ => ?_ obtain ⟨_, _, _⟩ := r obtain ⟨Ub', hsub, hC, hK⟩ := (d.2.2.1 C).2 - exact ⟨H, OS, Vc, Ub', Pt, d.1.1, d.1.2.1, hsub, d.1.2.2.2.1 I.vcc, hC, hK, ArmQIAt.ptCap d.1 Cp.1, Cp.2⟩ - · refine WP.spec_mono (syscall.decode_invocation.untyped_s1aRtVPt hA D P B Y hcap hfm I.del.vr hPN C Kc hal I.vcc - Cp a lbl len blk call don fp buf) fun r d => ?_ + exact ⟨H, OS, Vc, Ub', Pt, d.1.1, d.1.2.1, hsub, d.1.2.2.2.1 I.vcc, hC, hK, ArmQIAt.ptCap d.1 Cp.1, d.1.hvPt Hv, Cp.2, + d.1.devFr Df, hi Hi, d.1.eptPlaced Ep, d.1.ptCap objects, d.1.hvObjects highObjects⟩ + · refine WP.spec_mono (syscall.decode_invocation.retype_eptPlaced hA D P B Y hcap hfm I.del.vr hPN C Kc hal I.vcc + Cp.1 Cp.2 Ep Df Hv Hi objects highObjects a lbl len blk call don fp buf) fun r d => ?_ obtain ⟨_, _, _⟩ := r - obtain ⟨H', OS', Vn, Vc'', Pt', hQ, -, -, hV, hC, hK, hPc, hPg⟩ := d - exact ⟨H', OS', Vc'', Ub, Pt', hQ.1, hQ.2.1, Set.Subset.refl _, hV, hC, hK, hPc, hPg⟩ - · refine WP.spec_mono (syscall.decode_invocation.assignLW D P B Y C.case.po a hl len blk call don fp buf) + obtain ⟨H', OS', Vn, Vc'', Pt', hQ, -, -, hV, hC, hK, hEp, hPc, hHv, hPg, hDf, hHi, objects', highObjects'⟩ := d + exact ⟨H', OS', Vc'', Ub, Pt', hQ.1, hQ.2.1, Set.Subset.refl _, hV, hC, hK, hPc, hHv, hPg, hDf, hHi, hEp, objects', highObjects'⟩ + · refine WP.spec_mono (syscall.decode_invocation.assignHi W I D P B Y C.case.po a hl len blk call don fp buf) fun r d => ?_ obtain ⟨_, s', _⟩ := r - have tk : TabKeep st s s' := ⟨d.2.2.ksb, fun j => by rw [d.2.2.ksb]; exact d.2.2.tab I.del.vr j⟩ + have tk : TabKeep st s s' := ⟨d.2.1.ksb, fun j => by rw [d.2.1.ksb]; exact d.2.1.tab I.del.vr j⟩ obtain ⟨Ub', hsub, hC, hK⟩ := S1aColU.of d.1.1 (S1aArmCol.ofTab tk C) - exact ⟨H, OS, Vc, Ub', Pt, d.1.1, d.1.2, hsub, d.2.2.vcCap I.vcc, hC, hK, d.2.2.ptCap Cp.1, Cp.2⟩ - · refine WP.spec_mono (syscall.decode_invocation.makePool_s1aPt D P B Y I.del.vr hSC C Kc hal Cp a hl len blk call - don fp buf) fun r d => ?_ + exact ⟨H, OS, Vc, Ub', Pt, d.1.1, d.1.2, hsub, d.2.1.vcCap I.vcc, hC, hK, d.2.1.ptCap Cp.1, d.2.1.hvPt Hv, Cp.2, + d.2.1.devFr Df, d.2.2 Hi, d.2.1.eptPlaced Ep, d.2.1.ptCap objects, d.2.1.hvObjects highObjects⟩ + · refine WP.spec_mono (syscall.decode_invocation.makePool_s1aHi W I D P B Y hSC C Kc hal Cp Df Hv Hi Ep objects highObjects a hl len + blk call don fp buf) fun r d => ?_ obtain ⟨_, s', _⟩ := r - rcases d with rfl | ⟨H', OS', E, hC, hPc, hPg⟩ - · exact ⟨H, OS, Vc, Ub, Pt, B, Y, Set.Subset.refl _, I.vcc, C, Kc, Cp⟩ + rcases d with rfl | ⟨H', OS', E, hC, ⟨hPc, hPg⟩, hHv, hDf, hHi, hEp, objects', highObjects'⟩ + · exact ⟨H, OS, Vc, Ub, Pt, B, Y, Set.Subset.refl _, I.vcc, C, Kc, Cp.1, Hv, Cp.2, Df, Hi, Ep, objects, highObjects⟩ · obtain ⟨Ub', hsub, hC', hK⟩ := S1aColU.of E.1 hC - exact ⟨H', OS', Vc, Ub', Pt, E.1, E.2.1, hsub, E.2.2.2.1 I.vcc, hC', hK, hPc, hPg⟩ + exact ⟨H', OS', Vc, Ub', Pt, E.1, E.2.1, hsub, E.2.2.2.1 I.vcc, hC', hK, hPc, hHv, hPg, hDf, hHi, hEp, objects', highObjects'⟩ end ST end R diff --git a/proofs/Fl4ProofsA64/P1/S1aStepH.lean b/proofs/Fl4ProofsA64/P1/S1aStepH.lean index 5371d7c13..6f4827cee 100644 --- a/proofs/Fl4ProofsA64/P1/S1aStepH.lean +++ b/proofs/Fl4ProofsA64/P1/S1aStepH.lean @@ -47,6 +47,9 @@ Gen 21 (Architect 16:30Z): S1aStep's `S1aStep` post carries `PtCap ∧ PtHG`; `S hypotheses plus `Hy : S1aDecHyps`, post `S1aStep` (`DecArmQH` by `armQH_s1a` + `S1aZ2.toStep`; the rest by `s1aStep`). Extended in place for new arms. `s1aStep` (hypothesis-free) is unchanged. +Gen 39 (Architect ruling L1): `S1aZ2.toStep` and `s1aStepH` take `Hv : HvPt st Pt OS s` after `Df` (S1aStep's post +carries S1aHvPt's `HvPt`; `DecArmQH` by `ArmQIAt.hvPt`). + Named premises: none. Case facts: none new (the record's fields are a64's ruled `ArmDecHyps` hypotheses, discharged at the entry layer from QueueDecTcb's [P] `TcbPlace` / `SspHyps`). -/ @@ -66,10 +69,6 @@ namespace ST variable {OS Vq Vc Ub : Set U64} {ia ie : Nat} {A : Type _} {ar : machine.Arch A} -/-- **`DecArmKK` and TCB SetPriority** (module docstring). -/ -def DecArmKK3 (cap : capability.Cap) (lbl : U64) : Prop := - DecArmKK cap lbl ∨ ∃ t, cap = .Thread t ∧ lbl = fl4_abi.label.TCBSetPriority - /-- **The S1a decode hypotheses discharged at the entry layer** (module docstring; a64's `ArmDecHyps`, no S1a-specific field so far). -/ structure S1aDecHyps (st : machine.Store S) [L : LawfulStore st] (H : Heap) (Pt : Set U64) (n : U64) (s : S) @@ -82,7 +81,7 @@ theorem syscall.decode_invocation.armQH_s1a (hA : P0.ArchTotal ar) (hM : MaxSpi {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} {Ub' : Set U64} (I : DelIn st ar H Cs OS Vq Ub' Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (a : A) @@ -97,13 +96,13 @@ theorem syscall.decode_invocation.armQH_s1a (hA : P0.ArchTotal ar) (hM : MaxSpi · exact WP.spec_mono (syscall.decode_invocation.armKKAt hA I D P B Y hcap hks a hk len blk call don fp buf) fun r d => by obtain ⟨_, _, _⟩ := r - exact S1aZ2.ofK d + exact S1aZ2.ofK ⟨d.1, d.2.1, d.2.2.1⟩ by_cases hp : ∃ t, cap = .Thread t ∧ lbl = fl4_abi.label.TCBSetPriority · obtain ⟨t, rfl, hl⟩ := hp exact WP.spec_mono (syscall.decode_invocation.prio_armQIKAt hA D P B Y I.del.vr hks I.del.sca hcap Hy.mcp Hy.cs a hl len blk call don fp buf) fun r d => by obtain ⟨_, _, _⟩ := r - exact S1aZ2.ofK d + exact S1aZ2.ofK ⟨d.1, d.2.1, d.2.2.1⟩ · exact WP.spec_mono (syscall.decode_invocation.armQHAt hA hM hPl I hKZ hPI D P B Y hcap hks a hc hIq hSC Hy.toArmDecHyps len blk call don fp buf) @@ -113,10 +112,12 @@ theorem syscall.decode_invocation.armQH_s1a (hA : P0.ArchTotal ar) (hM : MaxSpi /-- **An `S1aZ2` post is the common S1a step post** (at `H`, `OS`, `Vc` and the `S1aColU` witness). -/ theorem S1aZ2.toStep {kk : Prop} {s s' : S} (d : S1aZ2 st H Cs OS Vc Vc Ub ia ie kk s s') - (hv : VcCap st Vc OS s) (C : S1aArmCol st H Cs OS Vc Ub s) (Cp : PtCap st Pt OS s ∧ PtHG H Pt) : - S1aStep st Cs Ub ia ie s' := + (hv : VcCap st Vc OS s) (C : S1aArmCol st H Cs OS Vc Ub s) (Cp : PtCap st Pt OS s ∧ PtHG H Pt) + (Df : DevFrAl st OS s) (Hv : HvPt st Pt OS s) (Hi : HiCap511 st OS s') + (Ep : EptPlaced st H OS Pt s) (objects : PtObjects st H OS s) (highObjects : HvObjects st H OS s) : S1aStep st Cs Ub ia ie s' := have ⟨Ub', hsub, hC, hK⟩ := (d.2.2.1 C).2 - ⟨H, OS, Vc, Ub', Pt, d.1.1, d.1.2.1, hsub, d.1.2.2.2.1 hv, hC, hK, ArmQIAt.ptCap d.1 Cp.1, Cp.2⟩ + ⟨H, OS, Vc, Ub', Pt, d.1.1, d.1.2.1, hsub, d.1.2.2.2.1 hv, hC, hK, ArmQIAt.ptCap d.1 Cp.1, d.1.hvPt Hv, Cp.2, + d.1.devFr Df, Hi, d.1.eptPlaced Ep, d.1.ptCap objects, d.1.hvObjects highObjects⟩ /-- **The arms of the evolving S1a step top** (module docstring; extended in place; gen 22: the binders `st`, `s`, `extra` dropped with a64's `DecArmQH cap lbl`). -/ @@ -126,16 +127,20 @@ def DecArmS1aH (cap : capability.Cap) (lbl : U64) : Prop := variable {Uq : Set U64} /-- **The evolving S1a step top over the entry-hypothesis record** (module docstring). -/ -theorem syscall.decode_invocation.s1aStepH (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} +theorem syscall.decode_invocation.s1aStepH {Pp Tb Hr Te : Set U64} {Lv Re bits : U64 → Nat} + (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) - (hKZ : FinKZ st ar (L.ksb s) Ty K) (hPI : PoolIdx st OS s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) (hfm : A64FrameMasks st s) (hPN : PoolNamed st OS s) (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) - (Cp : PtCap st Pt OS s ∧ PtHG H Pt) (a : A) {lbl : U64} (hc : DecArmS1aH cap lbl) + (Cp : PtCap st Pt OS s ∧ PtHG H Pt) (Df : DevFrAl st OS s) (Hv : HvPt st Pt OS s) (Hi : HiCap511 st OS s) + (Ep : EptPlaced st H OS Pt s) (objects : PtObjects st H OS s) (highObjects : HvObjects st H OS s) (a : A) {lbl : U64} + (hc : DecArmS1aH cap lbl) (hIq : ∀ irq, cap = .IrqHandler irq → (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) (Hy : S1aDecHyps st H Pt hPl.ipa s cap) @@ -143,10 +148,13 @@ theorem syscall.decode_invocation.s1aStepH (hA : P0.ArchTotal ar) (hM : MaxSpi a syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ r s' _ => S1aStep st Cs Ub ia ie s' ⦄ := by rcases hc with hc | hc - · exact WP.spec_mono (syscall.decode_invocation.armQH_s1a (Vc := Vc) (Ub := Ub) hA hM hPl I hKZ hPI D P B Y hcap hks - a hc hIq hSC Hy len blk call don fp buf) fun _ d => d.toStep I.vcc C Cp - · exact syscall.decode_invocation.s1aStep hA I hKZ hPI D P B Y hcap hks hfm hPN C Kc hal Cp a hc hIq hSC len blk - call don fp buf + · exact WP.spec_mono (WP.spec_and + (syscall.decode_invocation.armQH_s1a (Vc := Vc) (Ub := Ub) hA hM hPl I hKZ hPI D P B Y hcap hks + a hc hIq hSC Hy len blk call don fp buf) + (syscall.decode_invocation.armQH_hi hA hM hPl I W Hv Cp.2 hPI D P B Y hcap hks Hy.toArmDecHyps a hc hIq hSC + len blk call don fp buf)) fun _ ⟨d, hi⟩ => d.toStep I.vcc C Cp Df Hv (hi Hi) Ep objects highObjects + · exact syscall.decode_invocation.s1aStep hA hPl I W hKZ hPI D P B Y hcap hks hfm hPN C Kc hal Cp Df Hv Hi Ep objects highObjects a hc hIq + hSC len blk call don fp buf end ST end R diff --git a/proofs/Fl4ProofsA64/P1/S1aStepR2.lean b/proofs/Fl4ProofsA64/P1/S1aStepR2.lean new file mode 100644 index 000000000..d8cb3ae48 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aStepR2.lean @@ -0,0 +1,285 @@ +/- +P1 (aarch64): the S1a step with R2 (A64-S1A gen 41, closing B2). + +`S1aStepR2` is S1aStep's common post together with R2 and the kernel-table / Untyped separation (`S1aKtUt`) at the +same end heap, slots and footprint, over the same fixed kernel table set. `s1aStepR2` proves it on every arm of +`DecArmS1aH` from R2 at entry: the decoder typing is derived from R2 (`S1aR2Core.hvs`), and every column of the post +that R2 states is taken from it or kept beside it. + +Named premises: [P] `P0.ArchTotal`, [P] `MaxSpi` (IrqControl), [P] `ArchPlat`, [P] `KTab` (Retype), +[P] `A64FrameMasks` (Retype), as in the arms' tops. +Case facts: the existing deletion typing `HiDelTy` at R2's witnesses (`W`), as the arms' tops take it. +-/ +import Fl4ProofsA64.P1.S1aStepH +import Fl4ProofsA64.P1.S1aPtCol +import Fl4ProofsA64.P1.S1aR2KtDel +import Fl4ProofsA64.P1.S1aKtUtArms +import Fl4ProofsA64.P1.S1aR2Transport +import Fl4ProofsA64.P1.S1aR2AssignPost +import Fl4ProofsA64.P1.S1aR2MakePool +import Fl4ProofsA64.P1.S1aR2RetypeTop + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt Pp Tb Hr Te Kt Uq : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- R2 at some witnesses of the walks. -/ +def S1aR2Ex (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pt Kt : Set U64) (n : U64) (s : S) : Prop := + ∃ (Pp Tb Hr Te : Set U64) (Lv Re bits : U64 → Nat), S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s + +theorem S1aR2.ex {s : S} (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : S1aR2Ex st H OS Pt Kt n s := + ⟨_, _, _, _, _, _, _, h⟩ + +theorem S1aDelKt.ex {s : S} (h : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + S1aKtUt st OS Kt s ∧ S1aR2Ex st H OS Pt Kt n s := + ⟨h.2, S1aR2.ex h.1.1⟩ + +/-- Every `HighVSpace` root is in the footprint. -/ +theorem S1aR2.hvPt {s : S} (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : HvPt st Pt OS s := by + intro y hy p m a cap + have held : p ∈ Hr := by + rw [h.highRoots] + exact ⟨y, hy, m, a, cap⟩ + exact h.highFootprint ⟨p, held, Or.inl rfl⟩ + +/-- The separation and R2, proved separately, of one invocation. -/ +private theorem both {α β : Type _} {m : Result (α × S × β)} {X : S → Prop} + (r2 : m ⦃ _ s' _ => X s' ⦄) (kt : m ⦃ _ s' _ => S1aKtUt st OS Kt s' ⦄) + (ex : ∀ s', X s' → S1aR2Ex st H OS Pt Kt n s') : + m ⦃ _ s' _ => S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt n s' ⦄ := + WP.spec_mono (WP.spec_and r2 kt) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨h.2, ex _ h.1⟩ + +private theorem deletion {α β : Type _} {m : Result (α × S × β)} + (d : m ⦃ _ s' _ => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄) : + m ⦃ _ s' _ => S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt n s' ⦄ := + WP.spec_mono d fun r h => by + obtain ⟨_, _, _⟩ := r + exact h.ex + +set_option maxHeartbeats 4000000 in +/-- **R2 and the separation on every `DecArmQH` arm**, at the entry's heap, slots and footprint. -/ +theorem syscall.decode_invocation.armQH_r2 (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} + {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) + (Df : DevFrAl st OS s) (Hy : S1aDecHyps st H Pt hPl.ipa s cap) (a : A) {lbl : U64} (hc : DecArmQH cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (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' _ => + S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt hPl.ipa s' ⦄ := by + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have vr := I.del.vr + have kept (arm : DecArmR2Keep cap lbl) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt hPl.ipa s' ⦄ := + both (syscall.decode_invocation.keepSlotsExactR2 hA R I D P B Y hks hcap arm a len blk call don fp buf) + (syscall.decode_invocation.keepSlots_ktUt hA sep I D P B Y hks hcap arm a len blk call don fp buf) + fun _ h => h.ex + have cache (arm : DecArmR2Cache cap lbl) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt hPl.ipa s' ⦄ := + both (syscall.decode_invocation.cacheExactR2 R place I D hA a arm len blk call don fp buf) + (syscall.decode_invocation.cache_ktUt sep I D hA a arm len slot blk call don fp buf) fun _ h => h.ex + rcases hc with (hc | hc) | ⟨t, rfl, hl⟩ | rfl | ⟨nt, b, sd, rv, rfl⟩ | ⟨e, b, sd, rv, g, gr, rfl⟩ | ⟨t, rfl, hl⟩ | + ⟨t, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | + ⟨p, m, x, rfl⟩ | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | hc | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | + ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | + ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | ⟨p, m, x, v, rfl, hl⟩ | ⟨p, m, x, v, rfl, hl⟩ | + ⟨p, l, m, x, v, rfl⟩ + · rcases hc with ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | + ⟨t, rfl, hl⟩ | ⟨irq, rfl, hl⟩ | ⟨irq, rfl, hl⟩ | ⟨hf, hl⟩ + · exact deletion (syscall.decode_invocation.tcbInstall_kt hA I hPl W hPI D P B Y hks R sep a (Or.inl hl) + len blk call don fp buf) + · exact deletion (syscall.decode_invocation.tcbInstall_kt hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inl hl)) len blk call don fp buf) + · exact deletion (syscall.decode_invocation.tcbInstall_kt hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inr (Or.inl hl))) len blk call don fp buf) + · exact deletion (syscall.decode_invocation.tcbInstall_kt hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inr (Or.inr (Or.inl hl)))) len blk call don fp buf) + · subst lbl + exact deletion (syscall.decode_invocation.setEpt_kt hA I hPl W D P B Y hks R sep a + (fun x hx h0 => (SlotCov.offs P.heap B (hSC x hx h0)).2.1) len blk call don fp buf) + · exact deletion (syscall.decode_invocation.tcbInstall_kt hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inr (Or.inr (Or.inr hl)))) len blk call don fp buf) + · exact deletion (syscall.decode_invocation.irqHandler_kt I D P B Y R sep a (Or.inl hl) + (hIq irq rfl (Or.inl hl)) hSC len blk call don fp buf) + · exact deletion (syscall.decode_invocation.irqHandler_kt I D P B Y R sep a (Or.inr hl) + (hIq irq rfl (Or.inr hl)) hSC len blk call don fp buf) + · exact deletion (syscall.decode_invocation.cnodeRvDel_kt I hPl W D P B Y hcap hf hks R sep a hl + len blk call don fp buf) + · by_cases copy : capFam cap = .cnode ∧ (lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ + lbl = fl4_abi.label.CNodeMove ∨ lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) + · exact both (syscall.decode_invocation.cnodeExactR2 R I D P B Y hcap copy.1 copy.2 a len blk call don fp buf) + (syscall.decode_invocation.cnode_s1aKtUt D P B sep a len blk call don fp buf copy.2 copy.1 hcap) + fun _ h => h.ex + have arm : DecArmKK3 cap lbl := hc.imp (fun h => ⟨h, copy⟩) id + refine both (syscall.decode_invocation.keepingExactR2 hA R place I D P B Y hcap hks Hy.mcp Hy.cs arm a len + blk call don fp buf) ?_ fun _ h => h.ex + rcases arm with kk | ⟨t, rfl, hl⟩ + · exact WP.spec_mono (syscall.decode_invocation.armKKAt hA I D P B Y hcap hks a kk len blk call don fp buf) + fun r d => by + obtain ⟨_, _, _⟩ := r + exact sep.keep d.2.2.1 + · exact WP.spec_mono (syscall.decode_invocation.prio_armQIKAt (Vc := Vc) hA D P B Y I.del.vr hks I.del.sca hcap Hy.mcp + Hy.cs a hl len blk call don fp buf) fun r d => by + obtain ⟨_, _, _⟩ := r + exact sep.keep d.2.2.1 + · exact deletion (syscall.decode_invocation.ssp_kt hA I hPl W hPI D P B Y hks hcap Hy.toArmDecHyps R sep a hl + len blk call don fp buf) + · exact both (syscall.decode_invocation.irqCtlExactR2 hA hM R I D P B Y hcap a lbl len blk call don fp buf) + (syscall.decode_invocation.irqCtl_ktUt hA hM sep I D P B Y hcap a lbl len blk call don fp buf) fun _ h => h.ex + · exact kept (Or.inl ⟨nt, b, sd, rv, rfl⟩) + · exact both (syscall.decode_invocation.endpointExactR2 hA R I D P B Y hks hcap a lbl len blk call don fp buf) + (syscall.decode_invocation.endpoint_ktUt hA sep I D P B Y hks hcap a lbl len blk call don fp buf) + fun _ h => h.ex + · exact kept (Or.inr (Or.inl ⟨t, rfl, Or.inl hl⟩)) + · exact kept (Or.inr (Or.inl ⟨t, rfl, Or.inr hl⟩)) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, Or.inl hl⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, Or.inr (Or.inl hl)⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, hl.elim (fun h => Or.inr (Or.inr (Or.inl h))) + (fun h => Or.inr (Or.inr (Or.inr (Or.inl h))))⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, hl.elim (fun h => Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))) + (fun h => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))))⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr hl)))))⟩))) + · exact cache (Or.inl ⟨p, m, x, rfl⟩) + · exact cache (Or.inr (Or.inr (Or.inr (Or.inr ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩)))) + · exact cache (hc.elim (fun h => Or.inr (Or.inr (Or.inl h))) (fun h => Or.inr (Or.inr (Or.inr (Or.inl h))))) + · exact kept (Or.inr (Or.inr (Or.inr ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩))) + · subst lbl + exact both (syscall.decode_invocation.frameUnmapExactR2 hA hPl R place I P B hcap D ptKs a len blk call don fp + buf) + (syscall.decode_invocation.frameUnmap_ktUt hA hPl sep R place I P hcap D ptKs a len blk call don fp buf) + fun _ h => h.ex + · subst lbl + let f : vspace.FrameCap := ⟨fp', fsz, fr, fd, fm, fe, fa, fv⟩ + exact both (syscall.decode_invocation.accessExactR2 hA f R I P B Y D ptKs a len blk call don fp buf) + (syscall.decode_invocation.access_ktUt hA f sep R I P B Y D ptKs a len blk call don fp buf) fun _ h => h.ex + · subst lbl + exact both (syscall.decode_invocation.frameMapExactR2 hA hPl R vr P B Df hcap D ptKs a len blk call don fp buf) + (syscall.decode_invocation.frameMap_ktUt hA hPl sep R vr P B Df hcap D a len blk call don fp buf) + fun _ h => h.ex + · subst lbl + exact both (syscall.decode_invocation.pageTableMapExactR2 hPl R vr P B D hcap ptKs a len blk call don fp buf) + (syscall.decode_invocation.pageTableMap_ktUt hPl sep R vr P D hcap a len blk call don fp buf) + fun _ ⟨_, _, _, _, _, h⟩ => h.ex + · subst lbl + refine both (X := S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) ?_ + (syscall.decode_invocation.pageTableUnmap_ktUt hA hPl sep R place I D P B hcap ptKs a len blk call don fp buf) + fun _ h => h.ex + cases m + · exact syscall.decode_invocation.unmapUnmappedExactR2 R place I D P B hcap a len blk call don fp buf + · exact syscall.decode_invocation.unmapMappedExactR2 hA hPl R place I D P B hcap ptKs a len blk call don fp buf + · exact cache (Or.inr (Or.inl ⟨p, l, m, x, v, rfl⟩)) + +/-- **The common S1a step post with R2**: `S1aStep`'s clauses, then R2 and the separation at the same heap, slots and +footprint. -/ +def S1aStepR2 (st : machine.Store S) [L : LawfulStore st] (Cs Ub Kt : Set U64) (ia ie : Nat) (n : U64) + (s' : S) : Prop := + ∃ (H' : Heap) (OS' Vc' Ub' Pt' : Set U64), (SysL st H' Cs OS' ia ie s' ∧ SymL st H' Cs s' ∧ Ub' ⊆ Ub ∧ + VcCap st Vc' OS' s' ∧ S1aArmCol st H' Cs OS' Vc' Ub' s' ∧ S1aCapCol st H' OS' Ub' s' ∧ + PtCap st Pt' OS' s' ∧ HvPt st Pt' OS' s' ∧ PtHG H' Pt' ∧ DevFrAl st OS' s' ∧ HiCap511 st OS' s' ∧ + EptPlaced st H' OS' Pt' s' ∧ PtObjects st H' OS' s' ∧ HvObjects st H' OS' s') ∧ + S1aKtUt st OS' Kt s' ∧ S1aR2Ex st H' OS' Pt' Kt n s' + +theorem S1aStepR2.toStep {s : S} (h : S1aStepR2 st Cs Ub Kt ia ie n s) : S1aStep st Cs Ub ia ie s := + let ⟨H', OS', Vc', Ub', Pt', step, _⟩ := h + ⟨H', OS', Vc', Ub', Pt', step⟩ + +/-- A post at an end whose footprint columns are R2's own. -/ +theorem S1aStepR2.ofR2 {H' : Heap} {OS' Vc' Ub' Pt' Pp' Tb' Hr' Te' : Set U64} {Lv' Re' bits' : U64 → Nat} {s : S} + (B : SysL st H' Cs OS' ia ie s) (Y : SymL st H' Cs s) (sub : Ub' ⊆ Ub) (vc : 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) + (sep : S1aKtUt st OS' Kt s) (R : S1aR2 st H' OS' Pt' Pp' Tb' Hr' Te' Kt Lv' Re' bits' n s) : + S1aStepR2 st Cs Ub Kt ia ie n s := + ⟨H', OS', Vc', Ub', Pt', ⟨B, Y, sub, vc, C, Kc, R.pageTables, R.hvPt, R.footprint, Df, R.highHeaders, R.eptRoots, + R.pageObjects, R.highObjects⟩, sep, R.ex⟩ + +set_option maxHeartbeats 4000000 in +/-- **The S1a step with R2** on every arm of `DecArmS1aH`. -/ +theorem syscall.decode_invocation.s1aStepR2 (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (KT : KTab ar Kt KLv) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) + (W : HiDelTy st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (hfm : A64FrameMasks st s) (hPN : PoolNamed st OS s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) (a : A) + {lbl : U64} (hc : DecArmS1aH cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (cs : L.mem s (scA (L.curW s)) ≠ 0#u64) + (fh : ∀ t, cap = .Thread t → NullOrEp H (capA st s (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) + (Df : DevFrAl st OS s) (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' _ => + S1aStepR2 st Cs Ub Kt ia ie hPl.ipa s' ⦄ := by + have Cp : PtCap st Pt OS s ∧ PtHG H Pt := ⟨R.pageTables, R.footprint⟩ + obtain ⟨pools, tables, level, _, stage2, depth, width, hp, ht, he, ty, no3, hi, ty2, place2, heap2⟩ := + R.core.hvs W.pools W.tables W.granules W.stage2 + have dec := S1aDecHyps.of mcp cs fh + ⟨pools, tables, level, Gran stage2 width, s2gRe stage2 depth, hp, ht, he, ty, no3, hi, + S2DecTy.ofTeH P.heap ty2 place2 heap2⟩ ⟨R.pageTables, R.footprint, R.highHeaders⟩ P B hks hcap Df + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have sameEnd (hq : DecArmQH cap lbl) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aStepR2 st Cs Ub Kt ia ie hPl.ipa s' ⦄ := by + refine WP.spec_mono (WP.spec_and (WP.spec_and + (syscall.decode_invocation.armQH_s1a (Vc := Vc) (Ub := Ub) hA hM hPl I hKZ hPI D P B Y hcap hks + a hq hIq hSC dec len blk call don fp buf) + (syscall.decode_invocation.armQH_hi hA hM hPl I W R.hvPt Cp.2 hPI D P B Y hcap hks dec.toArmDecHyps a hq hIq + hSC len blk call don fp buf)) + (syscall.decode_invocation.armQH_r2 hA hM hPl I W hPI D P B Y hcap hks R sep Df dec a hq hIq hSC len blk call + don fp buf)) fun r ⟨⟨d, high⟩, kt⟩ => ?_ + obtain ⟨_, _, _⟩ := r + obtain ⟨Ub', hsub, hC, hK⟩ := (d.2.2.1 C).2 + exact ⟨H, OS, Vc, Ub', Pt, ⟨d.1.1, d.1.2.1, hsub, d.1.2.2.2.1 I.vcc, hC, hK, ArmQIAt.ptCap d.1 Cp.1, + d.1.hvPt R.hvPt, Cp.2, d.1.devFr Df, high R.highHeaders, d.1.eptPlaced R.eptRoots, d.1.ptCap R.pageObjects, + d.1.hvObjects R.highObjects⟩, kt.1, kt.2⟩ + rcases hc with hq | hc | ⟨p, sb, fi, dev, rfl⟩ | ⟨pp, ab, rfl, hl⟩ | ⟨rfl, hl⟩ + · exact sameEnd hq + · exact sameEnd (Or.inl (hc.imp id Or.inl)) + · refine WP.spec_mono (syscall.decode_invocation.untypedExactR2 hA KT D P B Y hcap hfm I.del.vr hPN C Kc hal I.vcc + Df R.highHeaders hks R sep a lbl len blk call don fp buf) fun r d => ?_ + obtain ⟨_, _, _⟩ := r + obtain ⟨H', OS', Vn, Vc'', Pt', Tb', Te', Lv', hQ, -, -, hV, hC, hK, hDf, -, R', sep'⟩ := d + exact S1aStepR2.ofR2 hQ.1 hQ.2.1 (Set.Subset.refl _) hV hC hK hDf sep' R' + · subst lbl + refine WP.spec_mono (WP.spec_and + (syscall.decode_invocation.assignHi W I D P B Y C.case.po a rfl len blk call don fp buf) + (syscall.decode_invocation.assignExactR2 R W I.del.vr D P B hcap hPN ptKs a len blk call don fp buf)) + fun r ⟨d, ⟨_, _, _, _, _, R'⟩⟩ => ?_ + obtain ⟨_, s', _⟩ := r + have tk : TabKeep st s s' := ⟨d.2.1.ksb, fun j => by rw [d.2.1.ksb]; exact d.2.1.tab I.del.vr j⟩ + obtain ⟨Ub', hsub, hC, hK⟩ := S1aColU.of d.1.1 (S1aArmCol.ofTab tk C) + exact S1aStepR2.ofR2 d.1.1 d.1.2 hsub (d.2.1.vcCap I.vcc) hC hK (d.2.1.devFr Df) (d.2.1.ktUt sep) R' + · 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, + 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 + obtain ⟨Ub', hsub, hC, hK⟩ := S1aColU.of E.1 column + exact S1aStepR2.ofR2 E.1 E.2.1 hsub (E.2.2.2.1 I.vcc) hC hK (DevFrAl.poolEnd post others Df) sep' R' + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aStepR2A.lean b/proofs/Fl4ProofsA64/P1/S1aStepR2A.lean new file mode 100644 index 000000000..2536631d7 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aStepR2A.lean @@ -0,0 +1,358 @@ +/- +P1 (aarch64, A64-S1A gen 41): the S1a step with R2 without the external deletion typing (Architect ruling D1/D2, +2026-12-03). + +The deletion arms read the guarded witness `HiDelTyR` (S1aHiDelR), which R2 gives at its active pool set +(`HiDelTyR.ofR2`, `S1aR2.activePools`); the post's `HiCap511` column is the R2 post's `highHeaders`. Siblings: +`tcbInstall_ktR`, `setEpt_ktR`, `ssp_ktR`, `cnodeRvDel_ktR`, `armQH_r2R` (same proofs at `HiDelTyR`); +**`syscall.decode_invocation.s1aStepR2A`**: `s1aStepR2` with no `HiDelTy`, from R2 and the Assign root's descriptor +facts `S1aAssignDesc` (S1aR2AssignD). + +Named premises: [P] `P0.ArchTotal`, [P] `MaxSpi`, [P] `ArchPlat`, [P] `KTab`, [P] `A64FrameMasks`, as in +`s1aStepR2`. +-/ +import Fl4ProofsA64.P1.S1aHiDelR +import Fl4ProofsA64.P1.S1aR2AssignD + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt Pp Tb Hr Te Kt Uq : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- SetHighVSpace, SetSpace, SetIPCBuffer, Configure and SetTimeoutEndpoint keep R2 and the separation (guarded witness). -/ +theorem syscall.decode_invocation.tcbInstall_ktR (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetHighVSpace ∨ lbl = fl4_abi.label.TCBSetSpace ∨ + lbl = fl4_abi.label.TCBSetIPCBuffer ∨ lbl = fl4_abi.label.TCBConfigure ∨ + lbl = fl4_abi.label.TCBSetTimeoutEndpoint) + (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDelR hPl W + have z := W.finKZ (hPl := hPl) I + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have ht := D.cap.2.1 t rfl + exact WP.spec_mono (syscall.decode_invocation.tcbInstall_phi hA J z hPI D P B Y + (Φ := fun q => S1aTcbKeep st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s q ∧ S1aKtUt st OS Kt q) + ⟨⟨R.toDelKeep, .refl s⟩, sep⟩ + (fun s1 ds1 => (S1aTcbSteps.r2 (Re := Re) (Kt := Kt) (Ac := Ac) (ia := ia) (ie := ie) (s1 := s1) (t := t) + (slot := slot) J (fun _ h => h.vsCap) hPl place ptKs z hPI ht P.src P.core0 R.capRefs.refs ds1.1).and + (S1aTcbSteps.ktUt J z hPI ht P.src P.core0)) + a hl len blk call don fp buf) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨h.1.1, h.2⟩ + +/-- SetEPTRoot keeps R2 and the separation (guarded witness). -/ +theorem syscall.decode_invocation.setEpt_ktR (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) (a : A) + (hXE : ∀ x ∈ extra.val, x ≠ 0#u64 → x ∉ EptS H.tcbs) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a fl4_abi.label.TCBSetEPTRoot len slot (.Thread t) blk call don fp buf extra + ⦃ r s' _ => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDelR hPl W + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have entry : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s := ⟨R.toDelKeep, sep⟩ + refine syscall.decode_invocation.tcbG (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) entry + a len blk call don fp buf fun _ _ eq => ?_ + subst eq + refine WP.spec_mono (tcb.decode.setEpt_s1aPhi hA J D P B Y hXE + (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) entry + (fun q r h hq hr mem same => h.osKeep hq hr mem same) + (fun q a x h Rq hx => WP.spec_and (cdt.delete.r2R J (fun _ h => h.vsCap) hPl place ptKs Rq hx h.1) + (cdt.delete.ktUtR J Rq hx h.2)) + (fun q src dest nc h Rq hs hd ne can source wf empty ept => by + obtain ⟨p, l, m, v, rfl⟩ := ept + have hm := Rq.sys.sys.stz.1.1.mdbS + exact WP.spec_and (cdt.insert_with_cap.r2C I.del.os I.del.vr Rq.jv.ksb hm hs hd ne can source + (fun e => by cases e) wf (fun _ => rfl) (fun _ _ none => by cases none) empty h.1) + (cdt.insert_with_cap.ktUt I.del.os hm hs hd ne can source (fun e => by cases e) wf + (fun _ _ _ _ e => by cases e) h.2))) fun _ h => h.2 + +/-- SetSchedParams keeps R2 and the separation (guarded witness). -/ +theorem syscall.decode_invocation.ssp_ktR (hA : P0.ArchTotal ar) {s : S} {t : U64} + {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} (I : DelIn st ar H Cs OS Vc Ub Pt K Ty s) + (hPl : ArchPlat ar) (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s (.Thread t) extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hks : HeapKsOff H (L.ksb s)) (hcap : obj.Slot.cap st slot s = ok (.Thread t)) + {m : U64} (Hy : ArmDecHyps st H Pt m s (.Thread t)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.TCBSetSchedParams) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot (.Thread t) blk call don fp buf extra ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDelR hPl W + have z := W.finKZ (hPl := hPl) I + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have ht := D.cap.2.1 t rfl + exact syscall.decode_invocation.ssp_phi hA J z hPI D P B Y hks hcap Hy + (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) ⟨R.toDelKeep, sep⟩ + (fun q r h hq hr mem keep => h.osKeep hq hr mem keep) + (fun q a nc src h Rq Qq _ blk hfh hnc valid hsrc source => WP.spec_and + (tcb.install_tcb_cap.r2F J (fun _ h => h.vsCap) hPl place ptKs z hPI Rq Qq blk ht P.src hsrc hnc + hfh (faults.valid_fault_handler.unread valid) source h.1) + (tcb.install_tcb_cap.ktUt J z hPI Rq Qq ht (by simp [layout.tcb.SLOT_FAULT_HANDLER]) (fun _ => hsrc) hnc h.2)) + a hl len blk call don fp buf + +/-- CNode Delete and Revoke keep R2 and the separation (guarded witness). -/ +theorem syscall.decode_invocation.cnodeRvDel_ktR {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) (hPl : ArchPlat ar) + (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa 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) (hf : capFam cap = .cnode) + (hks : HeapKsOff H (L.ksb s)) (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) + (sep : S1aKtUt st OS Kt s) (a : A) {lbl : U64} + (hl : lbl = fl4_abi.label.CNodeRevoke ∨ lbl = fl4_abi.label.CNodeDelete) (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 ⦃ r s' _ => + S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s' ⦄ := by + have J := I.forHiDelR hPl W + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have entry : S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s := ⟨R.toDelKeep, sep⟩ + have vsK : ∀ c, S2Q c → S1aVsCap c := fun _ h => h.vsCap + refine syscall.decode_invocation.cnodeG (P := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) entry a len + slot cap blk call don fp buf extra hf + (WP.spec_mono (cnode.decode.rvDelPhi J D P B hcap + (Φ := S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) entry + (WP.spec_mono (WP.spec_and (tcb.restart_caller.r2Keep J D P B Y entry.1) + (sched.set_thread_state.restartOs P D)) fun _ ⟨⟨Rq, h⟩, keep⟩ => ⟨Rq, h, sep.keep keep⟩) + (fun _ _ Rq hx h => WP.spec_and (cdt.delete.r2R J vsK hPl place ptKs Rq hx h.1) (cdt.delete.ktUtR J Rq hx h.2)) + (fun _ _ Rq hx h => WP.spec_and (cdt.revoke.r2R J vsK hPl place ptKs Rq hx h.1) (cdt.revoke.ktUtR J Rq hx h.2)) + hl) fun r h => by + obtain ⟨_, _, _⟩ := r + exact h) + +/-- The separation and R2, proved separately, of one invocation. -/ +private theorem bothR {α β : Type _} {m : Result (α × S × β)} {X : S → Prop} + (r2 : m ⦃ _ s' _ => X s' ⦄) (kt : m ⦃ _ s' _ => S1aKtUt st OS Kt s' ⦄) + (ex : ∀ s', X s' → S1aR2Ex st H OS Pt Kt n s') : + m ⦃ _ s' _ => S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt n s' ⦄ := + WP.spec_mono (WP.spec_and r2 kt) fun r h => by + obtain ⟨_, _, _⟩ := r + exact ⟨h.2, ex _ h.1⟩ + +private theorem deletionR {α β : Type _} {m : Result (α × S × β)} + (d : m ⦃ _ s' _ => S1aDelKt st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s' ⦄) : + m ⦃ _ s' _ => S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt n s' ⦄ := + WP.spec_mono d fun r h => by + obtain ⟨_, _, _⟩ := r + exact h.ex + +/-- **`armQH_r2` at the guarded witness.** -/ +theorem syscall.decode_invocation.armQH_r2R (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} + {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) + (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) + (Df : DevFrAl st OS s) (Hy : S1aDecHyps st H Pt hPl.ipa s cap) (a : A) {lbl : U64} (hc : DecArmQH cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (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' _ => + S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt hPl.ipa s' ⦄ := by + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have vr := I.del.vr + have kept (arm : DecArmR2Keep cap lbl) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt hPl.ipa s' ⦄ := + bothR (syscall.decode_invocation.keepSlotsExactR2 hA R I D P B Y hks hcap arm a len blk call don fp buf) + (syscall.decode_invocation.keepSlots_ktUt hA sep I D P B Y hks hcap arm a len blk call don fp buf) + fun _ h => h.ex + have cache (arm : DecArmR2Cache cap lbl) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aKtUt st OS Kt s' ∧ S1aR2Ex st H OS Pt Kt hPl.ipa s' ⦄ := + bothR (syscall.decode_invocation.cacheExactR2 R place I D hA a arm len blk call don fp buf) + (syscall.decode_invocation.cache_ktUt sep I D hA a arm len slot blk call don fp buf) fun _ h => h.ex + rcases hc with (hc | hc) | ⟨t, rfl, hl⟩ | rfl | ⟨nt, b, sd, rv, rfl⟩ | ⟨e, b, sd, rv, g, gr, rfl⟩ | ⟨t, rfl, hl⟩ | + ⟨t, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | + ⟨p, m, x, rfl⟩ | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | hc | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | + ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | + ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | ⟨p, m, x, v, rfl, hl⟩ | ⟨p, m, x, v, rfl, hl⟩ | + ⟨p, l, m, x, v, rfl⟩ + · rcases hc with ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | + ⟨t, rfl, hl⟩ | ⟨irq, rfl, hl⟩ | ⟨irq, rfl, hl⟩ | ⟨hf, hl⟩ + · exact deletionR (syscall.decode_invocation.tcbInstall_ktR hA I hPl W hPI D P B Y hks R sep a (Or.inl hl) + len blk call don fp buf) + · exact deletionR (syscall.decode_invocation.tcbInstall_ktR hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inl hl)) len blk call don fp buf) + · exact deletionR (syscall.decode_invocation.tcbInstall_ktR hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inr (Or.inl hl))) len blk call don fp buf) + · exact deletionR (syscall.decode_invocation.tcbInstall_ktR hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inr (Or.inr (Or.inl hl)))) len blk call don fp buf) + · subst lbl + exact deletionR (syscall.decode_invocation.setEpt_ktR hA I hPl W D P B Y hks R sep a + (fun x hx h0 => (SlotCov.offs P.heap B (hSC x hx h0)).2.1) len blk call don fp buf) + · exact deletionR (syscall.decode_invocation.tcbInstall_ktR hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inr (Or.inr (Or.inr hl)))) len blk call don fp buf) + · exact deletionR (syscall.decode_invocation.irqHandler_kt I D P B Y R sep a (Or.inl hl) + (hIq irq rfl (Or.inl hl)) hSC len blk call don fp buf) + · exact deletionR (syscall.decode_invocation.irqHandler_kt I D P B Y R sep a (Or.inr hl) + (hIq irq rfl (Or.inr hl)) hSC len blk call don fp buf) + · exact deletionR (syscall.decode_invocation.cnodeRvDel_ktR I hPl W D P B Y hcap hf hks R sep a hl + len blk call don fp buf) + · by_cases copy : capFam cap = .cnode ∧ (lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ + lbl = fl4_abi.label.CNodeMove ∨ lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) + · exact bothR (syscall.decode_invocation.cnodeExactR2 R I D P B Y hcap copy.1 copy.2 a len blk call don fp buf) + (syscall.decode_invocation.cnode_s1aKtUt D P B sep a len blk call don fp buf copy.2 copy.1 hcap) + fun _ h => h.ex + have arm : DecArmKK3 cap lbl := hc.imp (fun h => ⟨h, copy⟩) id + refine bothR (syscall.decode_invocation.keepingExactR2 hA R place I D P B Y hcap hks Hy.mcp Hy.cs arm a len + blk call don fp buf) ?_ fun _ h => h.ex + rcases arm with kk | ⟨t, rfl, hl⟩ + · exact WP.spec_mono (syscall.decode_invocation.armKKAt hA I D P B Y hcap hks a kk len blk call don fp buf) + fun r d => by + obtain ⟨_, _, _⟩ := r + exact sep.keep d.2.2.1 + · exact WP.spec_mono (syscall.decode_invocation.prio_armQIKAt (Vc := Vc) hA D P B Y I.del.vr hks I.del.sca hcap Hy.mcp + Hy.cs a hl len blk call don fp buf) fun r d => by + obtain ⟨_, _, _⟩ := r + exact sep.keep d.2.2.1 + · exact deletionR (syscall.decode_invocation.ssp_ktR hA I hPl W hPI D P B Y hks hcap Hy.toArmDecHyps R sep a hl + len blk call don fp buf) + · exact bothR (syscall.decode_invocation.irqCtlExactR2 hA hM R I D P B Y hcap a lbl len blk call don fp buf) + (syscall.decode_invocation.irqCtl_ktUt hA hM sep I D P B Y hcap a lbl len blk call don fp buf) fun _ h => h.ex + · exact kept (Or.inl ⟨nt, b, sd, rv, rfl⟩) + · exact bothR (syscall.decode_invocation.endpointExactR2 hA R I D P B Y hks hcap a lbl len blk call don fp buf) + (syscall.decode_invocation.endpoint_ktUt hA sep I D P B Y hks hcap a lbl len blk call don fp buf) + fun _ h => h.ex + · exact kept (Or.inr (Or.inl ⟨t, rfl, Or.inl hl⟩)) + · exact kept (Or.inr (Or.inl ⟨t, rfl, Or.inr hl⟩)) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, Or.inl hl⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, Or.inr (Or.inl hl)⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, hl.elim (fun h => Or.inr (Or.inr (Or.inl h))) + (fun h => Or.inr (Or.inr (Or.inr (Or.inl h))))⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, hl.elim (fun h => Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))) + (fun h => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))))⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr hl)))))⟩))) + · exact cache (Or.inl ⟨p, m, x, rfl⟩) + · exact cache (Or.inr (Or.inr (Or.inr (Or.inr ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩)))) + · exact cache (hc.elim (fun h => Or.inr (Or.inr (Or.inl h))) (fun h => Or.inr (Or.inr (Or.inr (Or.inl h))))) + · exact kept (Or.inr (Or.inr (Or.inr ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩))) + · subst lbl + exact bothR (syscall.decode_invocation.frameUnmapExactR2 hA hPl R place I P B hcap D ptKs a len blk call don fp + buf) + (syscall.decode_invocation.frameUnmap_ktUt hA hPl sep R place I P hcap D ptKs a len blk call don fp buf) + fun _ h => h.ex + · subst lbl + let f : vspace.FrameCap := ⟨fp', fsz, fr, fd, fm, fe, fa, fv⟩ + exact bothR (syscall.decode_invocation.accessExactR2 hA f R I P B Y D ptKs a len blk call don fp buf) + (syscall.decode_invocation.access_ktUt hA f sep R I P B Y D ptKs a len blk call don fp buf) fun _ h => h.ex + · subst lbl + exact bothR (syscall.decode_invocation.frameMapExactR2 hA hPl R vr P B Df hcap D ptKs a len blk call don fp buf) + (syscall.decode_invocation.frameMap_ktUt hA hPl sep R vr P B Df hcap D a len blk call don fp buf) + fun _ h => h.ex + · subst lbl + exact bothR (syscall.decode_invocation.pageTableMapExactR2 hPl R vr P B D hcap ptKs a len blk call don fp buf) + (syscall.decode_invocation.pageTableMap_ktUt hPl sep R vr P D hcap a len blk call don fp buf) + fun _ ⟨_, _, _, _, _, h⟩ => h.ex + · subst lbl + refine bothR (X := S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa) ?_ + (syscall.decode_invocation.pageTableUnmap_ktUt hA hPl sep R place I D P B hcap ptKs a len blk call don fp buf) + fun _ h => h.ex + cases m + · exact syscall.decode_invocation.unmapUnmappedExactR2 R place I D P B hcap a len blk call don fp buf + · exact syscall.decode_invocation.unmapMappedExactR2 hA hPl R place I D P B hcap ptKs a len blk call don fp buf + · exact cache (Or.inr (Or.inl ⟨p, l, m, x, v, rfl⟩)) + +/-- **The S1a step with R2 from R2 alone** but the Assign root's descriptor facts (`dsc`). -/ +theorem syscall.decode_invocation.s1aStepR2A (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (KT : KTab ar Kt KLv) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) + (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (hfm : A64FrameMasks st s) (hPN : PoolNamed st OS s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) (a : A) + {lbl : U64} (hc : DecArmS1aH cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (cs : L.mem s (scA (L.curW s)) ≠ 0#u64) + (fh : ∀ t, cap = .Thread t → NullOrEp H (capA st s (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) + (Df : DevFrAl st OS s) + (dsc : ∀ y ∈ OS, ∀ r a, capA st s y = .HighVSpace r false a → S1aAssignDesc st Tb Kt Lv s r) (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' _ => + S1aStepR2 st Cs Ub Kt ia ie hPl.ipa s' ⦄ := by + have W := HiDelTyR.ofR2 R + replace R := R.activePools + have Cp : PtCap st Pt OS s ∧ PtHG H Pt := ⟨R.pageTables, R.footprint⟩ + obtain ⟨pools, tables, level, _, stage2, depth, width, hp, ht, he, ty, no3, hi, ty2, place2, heap2⟩ := + R.core.hvs W.pools W.tables W.granules W.stage2 + have dec := S1aDecHyps.of mcp cs fh + ⟨pools, tables, level, Gran stage2 width, s2gRe stage2 depth, hp, ht, he, ty, no3, hi, + S2DecTy.ofTeH P.heap ty2 place2 heap2⟩ ⟨R.pageTables, R.footprint, R.highHeaders⟩ P B hks hcap Df + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have sameEnd (hq : DecArmQH cap lbl) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aStepR2 st Cs Ub Kt ia ie hPl.ipa s' ⦄ := by + refine WP.spec_mono (WP.spec_and + (syscall.decode_invocation.armQH_s1a (Vc := Vc) (Ub := Ub) hA hM hPl I hKZ hPI D P B Y hcap hks + a hq hIq hSC dec len blk call don fp buf) + (syscall.decode_invocation.armQH_r2R hA hM hPl I W hPI D P B Y hcap hks R sep Df dec a hq hIq hSC len blk call + don fp buf)) fun r ⟨d, kt⟩ => ?_ + obtain ⟨_, _, _⟩ := r + obtain ⟨_, _, _, _, _, _, _, R'⟩ := kt.2 + obtain ⟨Ub', hsub, hC, hK⟩ := (d.2.2.1 C).2 + exact ⟨H, OS, Vc, Ub', Pt, ⟨d.1.1, d.1.2.1, hsub, d.1.2.2.2.1 I.vcc, hC, hK, ArmQIAt.ptCap d.1 Cp.1, + d.1.hvPt R.hvPt, Cp.2, d.1.devFr Df, R'.highHeaders, d.1.eptPlaced R.eptRoots, d.1.ptCap R.pageObjects, + d.1.hvObjects R.highObjects⟩, kt.1, kt.2⟩ + rcases hc with hq | hc | ⟨p, sb, fi, dev, rfl⟩ | ⟨pp, ab, rfl, hl⟩ | ⟨rfl, hl⟩ + · exact sameEnd hq + · exact sameEnd (Or.inl (hc.imp id Or.inl)) + · refine WP.spec_mono (syscall.decode_invocation.untypedExactR2 hA KT D P B Y hcap hfm I.del.vr hPN C Kc hal I.vcc + Df R.highHeaders hks R sep a lbl len blk call don fp buf) fun r d => ?_ + obtain ⟨_, _, _⟩ := r + obtain ⟨H', OS', Vn, Vc'', Pt', Tb', Te', Lv', hQ, -, -, hV, hC, hK, hDf, -, R', sep'⟩ := d + exact S1aStepR2.ofR2 hQ.1 hQ.2.1 (Set.Subset.refl _) hV hC hK hDf sep' R' + · subst lbl + refine WP.spec_mono (WP.spec_and + (syscall.decode_invocation.assignLW D P B Y C.case.po a rfl len blk call don fp buf) + (syscall.decode_invocation.assignExactR2D R dsc I.del.vr D P B hcap hPN ptKs a len blk call don fp buf)) + fun r ⟨d, ⟨_, _, _, _, _, R'⟩⟩ => ?_ + obtain ⟨_, s', _⟩ := r + have tk : TabKeep st s s' := ⟨d.2.2.ksb, fun j => by rw [d.2.2.ksb]; exact d.2.2.tab I.del.vr j⟩ + obtain ⟨Ub', hsub, hC, hK⟩ := S1aColU.of d.1.1 (S1aArmCol.ofTab tk C) + exact S1aStepR2.ofR2 d.1.1 d.1.2 hsub (d.2.2.vcCap I.vcc) hC hK (d.2.2.devFr Df) (d.2.2.ktUt sep) R' + · 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, + 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 + obtain ⟨Ub', hsub, hC, hK⟩ := S1aColU.of E.1 column + exact S1aStepR2.ofR2 E.1 E.2.1 hsub (E.2.2.2.1 I.vcc) hC hK (DevFrAl.poolEnd post others Df) sep' R' + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aStepR2Boot.lean b/proofs/Fl4ProofsA64/P1/S1aStepR2Boot.lean new file mode 100644 index 000000000..ec3f0cd50 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aStepR2Boot.lean @@ -0,0 +1,121 @@ +/- +P1 (aarch64): the S1a step's two entry witnesses hold together at boot (A64-S1A gen 41). + +`s1aStepR2` takes R2 and the deletion typing `HiDelTy` at the same witnesses, whose pool set must lie in the +footprint. The boot R2 theorems name every address as a possible pool, so R2 is first restated at the active pool +set (`S1aR2.activePools`); both witnesses then exist at `w0` and at the kernel-table variant of `w1`. +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aStepR2 +import Fl4ProofsA64.P1.S1aVsUnmB + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {OS Pt Pp Tb Hr Te Kt : Set U64} {Lv Re bits : U64 → Nat} {n : U64} {s : S} + +theorem PoolSet.idem : PoolSet st (PoolSet st Pp s) s = PoolSet st Pp s := + Set.ext fun _ => ⟨fun h => h.1, fun h => ⟨h, h.2⟩⟩ + +theorem ActiveAsidRoot.activePools : ActiveAsidRoot st (PoolSet st Pp s) s = ActiveAsidRoot st Pp s := by + funext asid raw + unfold ActiveAsidRoot + rw [PoolSet.idem] + +theorem S1aPath.activePools {tag asid t : U64} {shift vaBase : Nat} : + S1aPath st (PoolSet st Pp s) n s tag asid shift vaBase t ↔ S1aPath st Pp n s tag asid shift vaBase t := by + constructor <;> intro h <;> induction h with + | native root tag => exact .native (by simpa only [ActiveAsidRoot.activePools] using root) tag + | high root tag edge => exact .high (by simpa only [ActiveAsidRoot.activePools] using root) tag edge + | stage2 root tag => exact .stage2 (by simpa only [ActiveAsidRoot.activePools] using root) tag + | child _ deeper width aligned window edge ih => exact .child ih deeper width aligned window edge + +/-- **R2 reads its pool set only through the active pools.** -/ +theorem S1aR2.activePools (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) : + S1aR2 st H OS Pt (PoolSet st Pp s) Tb Hr Te Kt Lv Re bits n s := by + have same : PoolSet st (PoolSet st Pp s) s = PoolSet st Pp s := PoolSet.idem + have path {tag asid t : U64} {shift vaBase : Nat} + (p : S1aPath st (PoolSet st Pp s) n s tag asid shift vaBase t) : S1aPath st Pp n s tag asid shift vaBase t := + S1aPath.activePools.mp p + refine { h with core := ?_, place := ?_, poolCaps := ?_, paths := ?_ } + · refine { h.core with lookup := ?_, walk := ?_, root := ?_, stage1 := ?_, stage2 := ?_ } + · exact { h.core.lookup with + bk1 := by rw [same]; exact h.core.lookup.bk1 + bk2 := by rw [same]; exact h.core.lookup.bk2 + vh := by rw [same]; exact h.core.lookup.vh } + · unfold PtFndAll + rw [same] + exact h.core.walk + · exact ⟨by rw [ActiveAsidRoot.activePools]; exact h.core.root.backed, h.core.root.agree⟩ + · rw [same] + exact h.core.stage1 + · rw [same] + exact h.core.stage2 + · rw [same] + exact h.place + · refine { h.poolCaps with present := fun i hi p entry nonzero => ?_, noZero := ?_ } + · obtain ⟨member, rest⟩ := h.poolCaps.present i hi p entry nonzero + have bounds := AtOff.v i + exact ⟨⟨member, AtOff i, bounds.1, bounds.2.1, bounds.2.2, entry, nonzero⟩, rest⟩ + · rw [ActiveAsidRoot.activePools] + exact h.poolCaps.noZero + · exact ⟨fun _ _ _ _ _ p => h.paths.tables _ _ _ _ _ (path p), + fun _ _ _ _ _ p => h.paths.children _ _ _ _ _ (path p), + fun _ _ _ _ _ p => h.paths.leaves _ _ _ _ _ (path p)⟩ + +namespace BootWit + +set_option maxRecDepth 20000 in +set_option maxHeartbeats 4000000 in +/-- **At the pre-user boot state** both witnesses of `s1aStepR2` exist, with the separation. -/ +theorem w0_s1aStepEntry {kb ib r now mt : U64} {nc : Nat} (P : BootLay kb ib nc) + (Lv Re bits : U64 → Nat) (n : U64) : + ∃ Pp : Set U64, + HiDelTy bst ∅ (bootOS kb ib nc) Pp ∅ ∅ ∅ Lv Re bits n (bootS kb ib nc r now mt) ∧ + S1aR2 bst (bootH kb ib nc) (bootOS kb ib nc) ∅ Pp ∅ ∅ ∅ ∅ Lv Re bits n (bootS kb ib nc r now mt) ∧ + S1aKtUt bst (bootOS kb ib nc) ∅ (bootS kb ib nc r now mt) := by + obtain ⟨R, sep⟩ := w0_s1aR2 P Lv Re bits n (r := r) (now := now) (mt := mt) + have A := R.activePools + have sub := R.place.pools + have high : HvRt bst (bootOS kb ib nc) (bootS kb ib nc r now mt) = ∅ := A.highRoots.symm + refine ⟨_, ⟨sub, Set.empty_subset _, ?_, ?_, ?_, high.subset, ?_, ?_⟩, A, sep⟩ + · rintro q ⟨p, hp, -⟩ + exact hp.elim + · exact ⟨Set.empty_subset _, fun _ h => h.elim, fun _ h => h.elim, fun _ _ _ _ _ _ h => h.elim, + fun _ h => h.elim⟩ + · exact ⟨fun _ h => h.elim, fun _ h => h.elim, fun _ _ _ h => h.elim⟩ + · exact ⟨R.core.stage1.tbl, R.core.stage1.pool, fun _ h => h.elim⟩ + · exact ⟨R.core.stage2.tag, R.core.stage2.hi, fun _ h => h.elim⟩ + +set_option maxRecDepth 20000 in +set_option maxHeartbeats 4000000 in +/-- **At the user boot state with a kernel table** both witnesses of `s1aStepR2` exist, with the separation. -/ +theorem w1K_s1aStepEntry {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} (P : BootLay1 kb ib nc) + (Re bits : U64 → Nat) (n : U64) : + ∃ Pp : Set U64, + HiDelTy bst (w1Pt ∪ {bwv KTb}) (w1OS kb ib nc) Pp (insert (bwv KTb) w1Tb) ∅ ∅ + (Function.update w1Lv (bwv KTb) 1) Re bits n (w1S kb ib nc r now mt sl uw) ∧ + S1aR2 bst (KtH (w1H kb ib nc) {bwv KTb}) (w1OS kb ib nc) (w1Pt ∪ {bwv KTb}) Pp (insert (bwv KTb) w1Tb) ∅ ∅ + {bwv KTb} (Function.update w1Lv (bwv KTb) 1) Re bits n (w1S kb ib nc r now mt sl uw) ∧ + S1aKtUt bst (w1OS kb ib nc) {bwv KTb} (w1S kb ib nc r now mt sl uw) := by + obtain ⟨R, sep⟩ := w1K_s1aR2 P Re bits n (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) + have A := R.activePools + have sub := R.place.pools + have typed := w1K_vs P (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) + have high : HvRt bst (w1OS kb ib nc) (w1S kb ib nc r now mt sl uw) = ∅ := A.highRoots.symm + refine ⟨_, ⟨sub, typed.2, ?_, ?_, ?_, high.subset, typed.1, ?_⟩, A, sep⟩ + · rintro q ⟨p, hp, -⟩ + exact hp.elim + · exact ⟨Set.empty_subset _, fun _ h => h.elim, fun _ _ _ _ _ _ h => h.elim, fun _ _ _ _ _ _ h => h.elim, + fun _ h => h.elim⟩ + · exact ⟨fun _ h => h.elim, fun _ h => h.elim, fun _ _ _ h => h.elim⟩ + · exact ⟨R.core.stage2.tag, R.core.stage2.hi, fun _ h => h.elim⟩ + +end BootWit + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aStepR2K.lean b/proofs/Fl4ProofsA64/P1/S1aStepR2K.lean new file mode 100644 index 000000000..c130fc3cf --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aStepR2K.lean @@ -0,0 +1,263 @@ +/- +P1 (aarch64, A64-S1A gen 41): **the S1a step with R2 and the kernel-table column, chained** (Architect rulings D1–D3, +2026-12-03). + +`syscall.decode_invocation.s1aStepR2K` is `s1aStepR2` without the case witness `HiDelTy`: its inputs are R2 and the +column `S1aHiK` at the entry (with the existing `S1aKtUt` and case facts), and its post `S1aStepR2K` is +`S1aStepR2`'s with the column at the end slots. The Assign root's descriptor facts come from the relabelled R2 +(`S1aR2.relabel`, `S1aR2.assignDescK`), the deletion typing from R2 (`HiDelTyR.ofR2`), and the column from every +arm's word-keeping fact (`armQH_edge`, `assign_kt`, MakePool's pool post, `untypedExactR2K`). +`S1aStepR2K.toR2` projects to `s1aStepR2`'s post. + +Named premises: [P] `P0.ArchTotal`, [P] `MaxSpi`, [P] `ArchPlat`, [P] `KTab`, [P] `A64FrameMasks`, as in +`s1aStepR2`; unlike `s1aStepR2` it takes no `HiDelTy` and no `FinKZ`. +-/ +import Fl4ProofsA64.P1.S1aKtRetype + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +variable {S : Type _} {st : machine.Store S} [L : LawfulStore st] {H : Heap} + {Cs OS Vc Ub U Ac Pt Pp Tb Hr Te Kt Uq : Set U64} {Lv Re bits KLv : U64 → Nat} {n : U64} {ia ie : Nat} + {A : Type _} {ar : machine.Arch A} {K : capability.Cap → Prop} {Ty : S → Prop} + +/-- **The column's words through every `DecArmQH` arm.** -/ +theorem syscall.decode_invocation.armQH_edge (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) {s : S} + {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (hKZ : FinKZ st ar (L.ksb s) Pt Ty K) + (W : HiDelTyR st Pt OS Pp Tb Hr Te Lv Re bits hPl.ipa s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) + (Df : DevFrAl st OS s) (Hy : S1aDecHyps st H Pt hPl.ipa s cap) (a : A) {lbl : U64} (hc : DecArmQH cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (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' _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := by + have place : S1aR2Place Pt Pp Tb Hr Te Lv bits (L.ksb s) := + ⟨W.pools, W.tables, W.granules, W.high, W.stage2⟩ + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have vr := I.del.vr + have zEdge {α β : Type _} {m : Result (α × S × β)} {X : S → Prop} + (d : m ⦃ _ s' _ => X s' ∧ VsZ st (L.ksb s) Pt s s' ⦄) : + m ⦃ _ s' _ => EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := + WP.spec_mono d fun r h => by + obtain ⟨_, _, _⟩ := r + exact EdgeKeepOn.ofVsZ R h.2 + have kept (arm : DecArmR2Keep cap lbl) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := + syscall.decode_invocation.keepSlots_kt R I hA D P B Y hks hcap arm a len blk call don fp buf + have cache (arm : DecArmR2Cache cap lbl) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + EdgeKeepOn st (KtHdrW st OS Kt s) s s' ⦄ := + syscall.decode_invocation.cache_kt R I hA D a arm len blk call don fp buf + rcases hc with (hc | hc) | ⟨t, rfl, hl⟩ | rfl | ⟨nt, b, sd, rv, rfl⟩ | ⟨e, b, sd, rv, g, gr, rfl⟩ | ⟨t, rfl, hl⟩ | + ⟨t, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | ⟨v, rfl, hl⟩ | + ⟨p, m, x, rfl⟩ | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | hc | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | + ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | + ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩ | ⟨p, m, x, v, rfl, hl⟩ | ⟨p, m, x, v, rfl, hl⟩ | + ⟨p, l, m, x, v, rfl⟩ + · rcases hc with ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | ⟨t, rfl, hl⟩ | + ⟨t, rfl, hl⟩ | ⟨irq, rfl, hl⟩ | ⟨irq, rfl, hl⟩ | ⟨hf, hl⟩ + · exact zEdge (syscall.decode_invocation.tcbInstall_ktZ hA I hPl W hPI D P B Y hks R sep a (Or.inl hl) + len blk call don fp buf) + · exact zEdge (syscall.decode_invocation.tcbInstall_ktZ hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inl hl)) len blk call don fp buf) + · exact zEdge (syscall.decode_invocation.tcbInstall_ktZ hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inr (Or.inl hl))) len blk call don fp buf) + · exact zEdge (syscall.decode_invocation.tcbInstall_ktZ hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inr (Or.inr (Or.inl hl)))) len blk call don fp buf) + · subst lbl + exact zEdge (syscall.decode_invocation.setEpt_ktZ hA I hPl W D P B Y hks R sep a + (fun x hx h0 => (SlotCov.offs P.heap B (hSC x hx h0)).2.1) len blk call don fp buf) + · exact zEdge (syscall.decode_invocation.tcbInstall_ktZ hA I hPl W hPI D P B Y hks R sep a + (Or.inr (Or.inr (Or.inr (Or.inr hl)))) len blk call don fp buf) + · exact zEdge (syscall.decode_invocation.irqHandler_ktZ I hKZ D P B Y R sep a (Or.inl hl) + (hIq irq rfl (Or.inl hl)) hSC len blk call don fp buf) + · exact zEdge (syscall.decode_invocation.irqHandler_ktZ I hKZ D P B Y R sep a (Or.inr hl) + (hIq irq rfl (Or.inr hl)) hSC len blk call don fp buf) + · exact zEdge (syscall.decode_invocation.cnodeRvDel_ktZ I hPl W D P B Y hcap hf hks R sep a hl + len blk call don fp buf) + · by_cases copy : capFam cap = .cnode ∧ (lbl = fl4_abi.label.CNodeCopy ∨ lbl = fl4_abi.label.CNodeMint ∨ + lbl = fl4_abi.label.CNodeMove ∨ lbl = fl4_abi.label.CNodeMutate ∨ lbl = fl4_abi.label.CNodeRotate) + · exact syscall.decode_invocation.cnodeCopy_kt R I D P B Y hcap copy.1 copy.2 a len blk call don fp buf + have arm : DecArmKK3 cap lbl := hc.imp (fun h => ⟨h, copy⟩) id + exact syscall.decode_invocation.keeping_kt R I hA D P B Y hcap hks Hy.mcp Hy.cs arm a len blk call don fp buf + · exact zEdge (syscall.decode_invocation.ssp_ktZ hA I hPl W hPI D P B Y hks hcap Hy.toArmDecHyps R sep a hl + len blk call don fp buf) + · exact syscall.decode_invocation.irqCtl_kt R I hA hM D P B Y hcap a lbl len blk call don fp buf + · exact kept (Or.inl ⟨nt, b, sd, rv, rfl⟩) + · exact syscall.decode_invocation.endpoint_kt R I hA D P B Y hks hcap a lbl len blk call don fp buf + · exact kept (Or.inr (Or.inl ⟨t, rfl, Or.inl hl⟩)) + · exact kept (Or.inr (Or.inl ⟨t, rfl, Or.inr hl⟩)) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, Or.inl hl⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, Or.inr (Or.inl hl)⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, hl.elim (fun h => Or.inr (Or.inr (Or.inl h))) + (fun h => Or.inr (Or.inr (Or.inr (Or.inl h))))⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, hl.elim (fun h => Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))) + (fun h => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))))⟩))) + · exact kept (Or.inr (Or.inr (Or.inl ⟨v, rfl, Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr hl)))))⟩))) + · exact cache (Or.inl ⟨p, m, x, rfl⟩) + · exact cache (Or.inr (Or.inr (Or.inr (Or.inr ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩)))) + · exact cache (hc.elim (fun h => Or.inr (Or.inr (Or.inl h))) (fun h => Or.inr (Or.inr (Or.inr (Or.inl h))))) + · exact kept (Or.inr (Or.inr (Or.inr ⟨fp', fsz, fr, fd, fm, fe, fa, fv, rfl, hl⟩))) + · subst lbl + exact syscall.decode_invocation.frameUnmap_kt hA hPl R place I P hcap D ptKs a len blk call don fp buf + · subst lbl + let f : vspace.FrameCap := ⟨fp', fsz, fr, fd, fm, fe, fa, fv⟩ + exact syscall.decode_invocation.access_kt hA f R I P B Y D ptKs a len blk call don fp buf + · subst lbl + exact syscall.decode_invocation.frameMap_kt hA hPl R vr P B Df hcap D a len blk call don fp buf + · subst lbl + exact syscall.decode_invocation.pageTableMap_kt hPl R vr P B D hcap a len blk call don fp buf + · subst lbl + cases m + · exact syscall.decode_invocation.unmapUnmapped_kt R I D P hcap a len blk call don fp buf + · exact syscall.decode_invocation.unmapMapped_kt hA hPl R place I D P B hcap ptKs a len blk call don fp buf + · exact cache (Or.inr (Or.inl ⟨p, l, m, x, v, rfl⟩)) + +/-- **The S1a step post with the kernel-table column**: `S1aStepR2`'s, with `S1aHiK` at the end slots. -/ +def S1aStepR2K (st : machine.Store S) [L : LawfulStore st] (Cs Ub Kt : Set U64) (KLv : U64 → Nat) (ia ie : Nat) + (n : U64) (s' : S) : Prop := + ∃ (H' : Heap) (OS' Vc' Ub' Pt' : Set U64), (SysL st H' Cs OS' ia ie s' ∧ SymL st H' Cs s' ∧ Ub' ⊆ Ub ∧ + VcCap st Vc' OS' s' ∧ S1aArmCol st H' Cs OS' Vc' Ub' s' ∧ S1aCapCol st H' OS' Ub' s' ∧ + PtCap st Pt' OS' s' ∧ HvPt st Pt' OS' s' ∧ PtHG H' Pt' ∧ DevFrAl st OS' s' ∧ HiCap511 st OS' s' ∧ + EptPlaced st H' OS' Pt' s' ∧ PtObjects st H' OS' s' ∧ HvObjects st H' OS' s') ∧ + S1aKtUt st OS' Kt s' ∧ S1aR2Ex st H' OS' Pt' Kt n s' ∧ S1aHiK st OS' Kt KLv s' + +/-- `S1aStepR2K` projects to `S1aStepR2`. -/ +theorem S1aStepR2K.toR2 {s : S} (h : S1aStepR2K st Cs Ub Kt KLv ia ie n s) : S1aStepR2 st Cs Ub Kt ia ie n s := + let ⟨H', OS', Vc', Ub', Pt', step, sep, r2, _⟩ := h + ⟨H', OS', Vc', Ub', Pt', step, sep, r2⟩ + +/-- The column of `S1aStepR2K`. -/ +theorem S1aStepR2K.column {s : S} (h : S1aStepR2K st Cs Ub Kt KLv ia ie n s) : + ∃ (H' : Heap) (OS' Pt' : Set U64), S1aR2Ex st H' OS' Pt' Kt n s ∧ S1aKtUt st OS' Kt s ∧ + S1aHiK st OS' Kt KLv s := + let ⟨H', OS', _, _, Pt', _, sep, r2, col⟩ := h + ⟨H', OS', Pt', r2, sep, col⟩ + +/-- A post at an end whose footprint columns are R2's own, with the column. -/ +theorem S1aStepR2K.ofR2 {H' : Heap} {OS' Vc' Ub' Pt' Pp' Tb' Hr' Te' : Set U64} {Lv' Re' bits' : U64 → Nat} {s : S} + (B : SysL st H' Cs OS' ia ie s) (Y : SymL st H' Cs s) (sub : Ub' ⊆ Ub) (vc : 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) + (sep : S1aKtUt st OS' Kt s) (R : S1aR2 st H' OS' Pt' Pp' Tb' Hr' Te' Kt Lv' Re' bits' n s) + (col : S1aHiK st OS' Kt KLv s) : + S1aStepR2K st Cs Ub Kt KLv ia ie n s := + ⟨H', OS', Vc', Ub', Pt', ⟨B, Y, sub, vc, C, Kc, R.pageTables, R.hvPt, R.footprint, Df, R.highHeaders, R.eptRoots, + R.pageObjects, R.highObjects⟩, sep, R.ex, col⟩ + +/-- MakePool's pool post keeps the column. -/ +theorem S1aHiKeep.ofPool {s q : S} (h : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits n s) + (vr : VrOK H.omega H.frame H.scs H.scBits OS Vc Ub (L.ksb s) Pt) (ptKs : ∀ b, PtW Pt b → ¬ AsW (L.ksb s) b) + {x v p sb i base : U64} (post : PoolPost st H OS s q x v p sb i base) + (others : ∀ y ∈ OffR p.val (p.val + 2 ^ sb.val) OS, y ≠ v → + capA st q y = capA st s y ∨ ∃ p' b' i' d', capA st q y = .Untyped p' b' i' d') : + S1aHiKeep st OS (OffR p.val (p.val + 2 ^ sb.val) OS) Kt s q := by + refine ⟨EdgeKeepOn.ofKept fun b hb e => ?_, fun y hy R m a c => ?_⟩ + · have loc := h.ktHdrW hb + rcases post.vs Vc Ub Pt vr b (Or.inl loc) with kept | ⟨lo, hi⟩ | table + · exact kept + · rw [post.zr b (vr.al b (Or.inl loc)) lo hi] at e + exact absurd e (by decide) + · exact (ptKs b loc (by rw [table]; exact asW_at (L.ksb s) i)).elim + · have ne : y ≠ v := by + rintro rfl + rw [post.capV] at c + cases c + rcases others y hy ne with old | ⟨_, _, _, _, ut⟩ + · rw [old] at c + exact ⟨y, hy.1, m, a, c⟩ + · rw [ut] at c + cases c + +set_option maxHeartbeats 4000000 in +/-- **The S1a step, chained**: on every arm of `DecArmS1aH`, R2, the separation and the kernel-table column `KC` at +entry give `S1aStepR2K` at the end. The Assign root's descriptor facts are derived from `KC` (`S1aR2.assignDescK` on +the relabelled R2), and the deletion typing from R2 (`HiDelTyR.ofR2`, `DelIn.forHiDelR`, `HiDelTyR.finKZ`). -/ +theorem syscall.decode_invocation.s1aStepR2K (hA : P0.ArchTotal ar) (hM : MaxSpi ar) (hPl : ArchPlat ar) + (KT : KTab ar Kt KLv) {s : S} {cap : capability.Cap} {extra : Aeneas.Std.Array obj.Slot 3#usize} {slot : U64} + (I : DelIn st ar H Cs OS Vc Uq Pt K Ty s) (hPI : PoolIdx st OS s) + (D : DecPre st H.tcbs Cs H.omega H H.frame H.replies H.scs H.ntfns H.scBits U Ac s cap extra) + (P : SysPlace st H Cs H.frame H.replies H.ntfns OS s extra slot) (B : SysL st H Cs OS ia ie s) + (Y : SymL st H Cs s) (hcap : obj.Slot.cap st slot s = ok cap) (hks : HeapKsOff H (L.ksb s)) + (hfm : A64FrameMasks st s) (hPN : PoolNamed st OS s) + (C : S1aArmCol st H Cs OS Vc Ub s) (Kc : S1aCapCol st H OS Ub s) (hal : ∀ b ∈ Ub, Aligned b) (a : A) + {lbl : U64} (hc : DecArmS1aH cap lbl) + (hIq : ∀ irq, cap = .IrqHandler irq → + (lbl = fl4_abi.label.IRQClearIRQHandler ∨ lbl = fl4_abi.label.IRQSetIRQHandler) → irq.val < 5376) + (hSC : ∀ x ∈ extra.val, x ≠ 0#u64 → SlotCov st OS s x) + (mcp : ∀ y ∈ H.tcbs, (L.mem s (wa y 3440#u64)).val < 256) (cs : L.mem s (scA (L.curW s)) ≠ 0#u64) + (fh : ∀ t, cap = .Thread t → NullOrEp H (capA st s (slotIdx t layout.tcb.SLOT_FAULT_HANDLER))) + (R : S1aR2 st H OS Pt Pp Tb Hr Te Kt Lv Re bits hPl.ipa s) (sep : S1aKtUt st OS Kt s) + (Df : DevFrAl st OS s) (KC : S1aHiK st OS Kt KLv s) (len : U64) (blk call don fp : Bool) (buf : U64) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie hPl.ipa s' ⦄ := by + have dsc := R.assignDescK I.del.heap KC + replace R := R.relabel I.del.heap KC + have W := HiDelTyR.ofR2 R + replace R := R.activePools + have J := I.forHiDelR hPl W + have z := W.finKZ (hPl := hPl) I + have Cp : PtCap st Pt OS s ∧ PtHG H Pt := ⟨R.pageTables, R.footprint⟩ + obtain ⟨pools, tables, level, _, stage2, depth, width, hp, ht, he, ty, no3, hi, ty2, place2, heap2⟩ := + R.core.hvs W.pools W.tables W.granules W.stage2 + have dec := S1aDecHyps.of mcp cs fh + ⟨pools, tables, level, Gran stage2 width, s2gRe stage2 depth, hp, ht, he, ty, no3, hi, + S2DecTy.ofTeH P.heap ty2 place2 heap2⟩ ⟨R.pageTables, R.footprint, R.highHeaders⟩ P B hks hcap Df + have ptKs := hks.ptAsWG R.footprint B.ly.ksw (R.footprint.fit I.del.heap) + have sameEnd (hq : DecArmQH cap lbl) : + syscall.decode_invocation st ar s a lbl len slot cap blk call don fp buf extra ⦃ _ s' _ => + S1aStepR2K st Cs Ub Kt KLv ia ie hPl.ipa s' ⦄ := by + refine WP.spec_mono (WP.spec_and (WP.spec_and + (syscall.decode_invocation.armQH_s1a (Vc := Vc) (Ub := Ub) hA hM hPl J z hPI D P B Y hcap hks + a hq hIq hSC dec len blk call don fp buf) + (syscall.decode_invocation.armQH_r2R hA hM hPl I W hPI D P B Y hcap hks R sep Df dec a hq hIq hSC len blk call + don fp buf)) + (syscall.decode_invocation.armQH_edge hA hM hPl J z W hPI D P B Y hcap hks R sep Df dec a hq hIq hSC len blk + call don fp buf)) fun r ⟨⟨d, kt⟩, ed⟩ => ?_ + obtain ⟨_, _, _⟩ := r + obtain ⟨_, _, _, _, _, _, _, R'⟩ := kt.2 + obtain ⟨Ub', hsub, hC, hK⟩ := (d.2.2.1 C).2 + exact ⟨H, OS, Vc, Ub', Pt, ⟨d.1.1, d.1.2.1, hsub, d.1.2.2.2.1 I.vcc, hC, hK, ArmQIAt.ptCap d.1 Cp.1, + d.1.hvPt R.hvPt, Cp.2, d.1.devFr Df, R'.highHeaders, d.1.eptPlaced R.eptRoots, d.1.ptCap R.pageObjects, + d.1.hvObjects R.highObjects⟩, kt.1, kt.2, KC.keep ⟨ed, d.1.hiRoots R.highHeaders⟩⟩ + rcases hc with hq | hc | ⟨p, sb, fi, dev, rfl⟩ | ⟨pp, ab, rfl, hl⟩ | ⟨rfl, hl⟩ + · exact sameEnd hq + · exact sameEnd (Or.inl (hc.imp id Or.inl)) + · refine WP.spec_mono (syscall.decode_invocation.untypedExactR2K hA KT D P B Y hcap hfm I.del.vr hPN C Kc hal I.vcc + Df R.highHeaders hks R sep KC a lbl len blk call don fp buf) fun r d => ?_ + obtain ⟨_, _, _⟩ := r + obtain ⟨H', OS', Vn, Vc'', Pt', Tb', Te', Lv', hQ, -, -, hV, hC, hK, hDf, -, R', sep', col⟩ := d + exact S1aStepR2K.ofR2 hQ.1 hQ.2.1 (Set.Subset.refl _) hV hC hK hDf sep' R' col + · subst lbl + refine WP.spec_mono (WP.spec_and (WP.spec_and + (syscall.decode_invocation.assignLW D P B Y C.case.po a rfl len blk call don fp buf) + (syscall.decode_invocation.assignExactR2D R dsc I.del.vr D P B hcap hPN ptKs a len blk call don fp buf)) + (syscall.decode_invocation.assign_kt R I.del.vr D P hcap a len blk call don fp buf)) + fun r ⟨⟨d, ⟨_, _, _, _, _, R'⟩⟩, col⟩ => ?_ + obtain ⟨_, s', _⟩ := r + have tk : TabKeep st s s' := ⟨d.2.2.ksb, fun j => by rw [d.2.2.ksb]; exact d.2.2.tab I.del.vr j⟩ + obtain ⟨Ub', hsub, hC, hK⟩ := S1aColU.of d.1.1 (S1aArmCol.ofTab tk C) + exact S1aStepR2K.ofR2 d.1.1 d.1.2 hsub (d.2.2.vcCap I.vcc) hC hK (d.2.2.devFr Df) (d.2.2.ktUt sep) R' + (KC.keep col) + · 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, + 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 + obtain ⟨Ub', hsub, hC, hK⟩ := S1aColU.of E.1 column + exact S1aStepR2K.ofR2 E.1 E.2.1 hsub (E.2.2.2.1 I.vcc) hC hK (DevFrAl.poolEnd post others Df) sep' R' + (KC.keep (S1aHiKeep.ofPool R I.del.vr ptKs post others)) + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aStepR2KBoot.lean b/proofs/Fl4ProofsA64/P1/S1aStepR2KBoot.lean new file mode 100644 index 000000000..f3310d16b --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aStepR2KBoot.lean @@ -0,0 +1,62 @@ +/- +P1 (aarch64, A64-S1A gen 41): the entry of `s1aStepR2K` at boot. + +At the pre-user boot state and at the user boot state with a kernel table, R2, the separation and the kernel-table +column `S1aHiK` hold together, for any platform levels `KLv`: there is no HighVSpace cap, and the boot kernel table +holds no table descriptor (its level-1 typing and its closure in `{KTb}` contradict any descriptor). + +Named premises: none. +-/ +import Fl4ProofsA64.P1.S1aStepR2K +import Fl4ProofsA64.P1.S1aStepR2Boot + +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1.W7.R.ST +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +namespace BootWit + +set_option maxRecDepth 20000 in +set_option maxHeartbeats 4000000 in +/-- **At the pre-user boot state** the entry of `s1aStepR2K` holds. -/ +theorem w0_s1aStepEntryK {kb ib r now mt : U64} {nc : Nat} (P : BootLay kb ib nc) + (Lv Re bits KLv : U64 → Nat) (n : U64) : + ∃ Pp : Set U64, + S1aR2 bst (bootH kb ib nc) (bootOS kb ib nc) ∅ Pp ∅ ∅ ∅ ∅ Lv Re bits n (bootS kb ib nc r now mt) ∧ + S1aKtUt bst (bootOS kb ib nc) ∅ (bootS kb ib nc r now mt) ∧ + S1aHiK bst (bootOS kb ib nc) ∅ KLv (bootS kb ib nc r now mt) := by + obtain ⟨Pp, _, R, sep⟩ := w0_s1aStepEntry P Lv Re bits n (r := r) (now := now) (mt := mt) + refine ⟨Pp, R, sep, fun t ht => ht.elim, fun y hy root m a c => ?_⟩ + have held : root ∈ HvRt bst (bootOS kb ib nc) (bootS kb ib nc r now mt) := ⟨y, hy, m, a, c⟩ + rw [← R.highRoots] at held + exact held.elim + +set_option maxRecDepth 20000 in +set_option maxHeartbeats 4000000 in +/-- **At the user boot state with a kernel table** the entry of `s1aStepR2K` holds. -/ +theorem w1K_s1aStepEntryK {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} (P : BootLay1 kb ib nc) + (Re bits KLv : U64 → Nat) (n : U64) : + ∃ Pp : Set U64, + S1aR2 bst (KtH (w1H kb ib nc) {bwv KTb}) (w1OS kb ib nc) (w1Pt ∪ {bwv KTb}) Pp (insert (bwv KTb) w1Tb) ∅ ∅ + {bwv KTb} (Function.update w1Lv (bwv KTb) 1) Re bits n (w1S kb ib nc r now mt sl uw) ∧ + S1aKtUt bst (w1OS kb ib nc) {bwv KTb} (w1S kb ib nc r now mt sl uw) ∧ + S1aHiK bst (w1OS kb ib nc) {bwv KTb} KLv (w1S kb ib nc r now mt sl uw) := by + obtain ⟨Pp, W, R, sep⟩ := w1K_s1aStepEntry P Re bits n (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) + refine ⟨Pp, R, sep, fun t ht _ o ho al e => ?_, fun y hy root m a c => ?_⟩ + · have same : t = bwv KTb := ht + subst same + have level : Function.update w1Lv (bwv KTb) 1 (bwv KTb) = 1 := by simp + have desc := W.ty.1.desc _ (Set.mem_insert _ _) (by omega) o ho al e + have closed : _ = bwv KTb := R.kernelClosed _ ht (by omega) o ho al e + rw [closed] at desc + exact absurd desc.2 (by omega) + · have held : root ∈ HvRt bst (w1OS kb ib nc) (w1S kb ib nc r now mt sl uw) := ⟨y, hy, m, a, c⟩ + rw [← R.highRoots] at held + exact held.elim + +end BootWit + +end Fl4ProofsA64.P1.W7.R.ST diff --git a/proofs/Fl4ProofsA64/P1/S1aVsUnm.lean b/proofs/Fl4ProofsA64/P1/S1aVsUnm.lean new file mode 100644 index 000000000..ce07cc3d8 --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aVsUnm.lean @@ -0,0 +1,533 @@ +/- +P1 (aarch64, A64-S1A gen 26): **R2 — `valid_vs_lookup` over `Pt \ Kt` and the unmapped-object facts over the +reachable tables** (Architect ruling for gen 26; §167's B3; handoff gens 24–26). + +l4v's `valid_vs_lookup` ("a table reachable from a live ASID-pool entry is live and backed by a mapped cap") in +S1A's ghost terms, with reachability from the active pools `PoolSet st Pp s` and an empty extra Stage-1 root set: + +* **`MapV c t`** (`c` names `t` as a mapped VSpace table: a mapped `PageTable`, an assigned `Pml4` (`ROOT_S1`) or + `HighVSpace` (`ROOT_HIGH`) root, the own level-1 table `R + 4096` of an assigned `HighVSpace R`, a mapped `Ept`), + **`NamesV c t`** (any VSpace cap naming `t`, mapped or not; `MapV.names`, `UnmCap.names`). +* **`VsLk st H OS Pp Tb Te Kt Lv Re bits s`** (record, the R2 invariant): + `bk1` every Stage-1 table reachable from an active pool that is a `Tb` table **outside `Kt`** is backed by a + mapped cap of `OS`; `bk2` every reachable Stage-2 object of `Te` likewise; `kt` no cap of `OS` names a kernel + TTBR1 table (F1: the `Kt` tables are capless, referenced only by kernel TTBR1 L0 entries `0 … 510` and their + copies, so `ARMPageTableUnmap` / deletion never reach them through a cap); `ex` an unmapped `PageTable` / + level-0 `Ept` cap's object is named by no mapped cap (derive refuses unmapped caps, Map turns the one cap mapped + in place, Unmap only acts on the final cap: objects.rs:215–232, vspace.rs:1097–1157); `zr` an unmapped cap's + object is zero (`create_new_objects` zeroes, objects.rs:46–58; PageTable Unmap zeroes, vspace.rs:1097–1107). +* **The unmapped-object facts over the reachable tables** (the Queue line's case facts `UnmT` / `UnmZ`, object + level): **`VsLk.unmR1`** / **`VsLk.unmR2`** (an unmapped cap's object is no reachable `Tb` / `Te` table: + `p ∉ VsRt …` / `p ∉ S2Rt …`), **`VsLk.unmKt`** (nor a kernel table), **`VsLk.unmZ`** (its words are zero), and + the `UnmC` (QueueS2Unm, `obj.Slot.cap` form) versions **`VsLk.unmCR1`** / **`unmCR2`** / **`unmCZ`**. +* **Frame**: **`VsReach.back`** / **`S2Reach.back`** (reachability at `s'` is reachability at `s` when the pool + words and the reachable tables' words are kept), **`VsLk.keep`** (caps of `OS`, pool words, reachable tables' + words and unmapped objects' words kept). + +(gen 27, Architect 20:56Z, S1A-a) **`VsLk.vh`** (new field; `VsLk` gains the heap parameter `H`): unmapped caps' +objects, reachable non-`Kt` Stage-1 tables and reachable Stage-2 objects are exact `other` objects of `H`. The +word-level case facts follow by `HeapOK.disj` (**`heap_wa_ne`**): **`VsLk.unmT`** (QueueS1Map's `UnmT` at the +reachable tables `VsRt`, with the `Kt` tables `other 12` objects of `H`, **`KtH.kt`**), **`VsLk.unmTZ`** (`UnmZ`'s +"no `Te` word" at `S2Rt`), and their `UnmC` forms **`unmCT`** / **`unmCTZ`**. `VsLk.keep` carries `vh`. + +Gen 41 adds `RootAgreement` to `S1aR2Core`: an active ASID entry has a matching mapped root cap, and mapped copies +of a root agree on its ASID. `ActiveAsidRoot.find` connects the entry to the concrete ASID lookup. +`PtFnd` gives uniqueness of a reachable PageTable's parent descriptor and stage. `S1aR2Core.keep` frames the +common entry witness when its caps, VSpace words, and unmapped objects are kept. + +Named premises: none. Preservation across the concrete dispatcher arms is separate from these facts. +-/ +import Fl4ProofsA64.P1.S1aNonUser +import Fl4ProofsA64.P1.MdbTabKeep +import Fl4ProofsA64.P1.QueueUnmD +import Fl4ProofsA64.P1.MdbDer +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 + +/-! ## The caps -/ + +/-- **`c` names `t` as a mapped VSpace table** (module docstring). -/ +def MapV (c : capability.Cap) (t : U64) : Prop := + (∃ a v, c = .PageTable t true a v) ∨ (∃ a, c = .Pml4 t true a) ∨ (∃ a, c = .HighVSpace t true a) ∨ + (∃ R a, c = .HighVSpace R true a ∧ t = wa R 4096#u64) ∨ (∃ l a v, c = .Ept t l true a v) + +/-- **`c` names `t` as a VSpace table**, mapped or not. -/ +def NamesV (c : capability.Cap) (t : U64) : Prop := + (∃ m a v, c = .PageTable t m a v) ∨ (∃ m a, c = .Pml4 t m a) ∨ (∃ m a, c = .HighVSpace t m a) ∨ + (∃ R m a, c = .HighVSpace R m a ∧ t = wa R 4096#u64) ∨ (∃ l m a v, c = .Ept t l m a v) + +theorem MapV.names {c : capability.Cap} {t : U64} (h : MapV c t) : NamesV c t := by + rcases h with ⟨a, v, e⟩ | ⟨a, e⟩ | ⟨a, e⟩ | ⟨R, a, e, et⟩ | ⟨l, a, v, e⟩ + · exact Or.inl ⟨true, a, v, e⟩ + · exact Or.inr (Or.inl ⟨true, a, e⟩) + · exact Or.inr (Or.inr (Or.inl ⟨true, a, e⟩)) + · exact Or.inr (Or.inr (Or.inr (Or.inl ⟨R, true, a, e, et⟩))) + · exact Or.inr (Or.inr (Or.inr (Or.inr ⟨l, true, a, v, e⟩))) + +theorem UnmCap.names {c : capability.Cap} {p : U64} {n : Nat} (h : UnmCap c p n) : NamesV c p := by + rcases h with ⟨-, a, v, e⟩ | ⟨-, a, v, e⟩ + · exact Or.inl ⟨false, a, v, e⟩ + · exact Or.inr (Or.inr (Or.inr (Or.inr ⟨0#u64, false, a, v, e⟩))) + +theorem UnmC.capA {x p : U64} {n : Nat} {s : S} (h : UnmC st x p n s) : UnmCap (capA st s x) p n := by + rcases h with ⟨hn, a, v, e⟩ | ⟨hn, a, v, e⟩ + · exact Or.inl ⟨hn, a, v, (okinj ((capA_eq s x).symm.trans e))⟩ + · exact Or.inr ⟨hn, a, v, (okinj ((capA_eq s x).symm.trans e))⟩ + +/-! ## The invariant -/ + +/-- The heap object backing a non-kernel Stage-1 table granule. +A mapped HighVSpace names one object at its base, covering both its granules. -/ +def S1GranuleH (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS : Set U64) (s : S) (t : U64) : Prop := + H t = some (.other 12) ∨ ∃ R, H R = some (.other 13) ∧ + (t = R ∨ t = wa R 4096#u64) ∧ ∃ y ∈ OS, ∃ a, capA st s y = .HighVSpace R true a + +variable (st) in +/-- **`valid_vs_lookup` over `Pt \ Kt` with the unmapped-object facts** (module docstring). -/ +structure VsLk (H : Heap) (OS Pp Tb Te Kt : Set U64) (Lv Re bits : U64 → Nat) (s : S) : Prop where + bk1 : ∀ t, VsReach st (PoolSet st Pp s) ∅ Lv s t → t ∈ Tb → t ∉ Kt → ∃ y ∈ OS, MapV (capA st s y) t + bk2 : ∀ t, S2Reach st (PoolSet st Pp s) Re bits s t → t ∈ Te → ∃ y ∈ OS, MapV (capA st s y) t + kt : ∀ t ∈ Kt, ∀ y ∈ OS, ¬ NamesV (capA st s y) t + ex : ∀ x ∈ OS, ∀ y ∈ OS, ∀ p n, UnmCap (capA st s x) p n → ¬ MapV (capA st s y) p + zr : ∀ x ∈ OS, ∀ p n, UnmCap (capA st s x) p n → ∀ o : U64, o.val < n → o.val % 8 = 0 → L.mem s (wa p o) = 0#u64 + /-- Object exactness for unmapped caps and reachable Stage-2 objects, and the enclosing object + of each reachable non-kernel Stage-1 table granule. -/ + vh : (∀ x ∈ OS, ∀ p n, UnmCap (capA st s x) p n → ∃ z, n = 2 ^ z ∧ H p = some (.other z)) ∧ + (∀ t, VsReach st (PoolSet st Pp s) ∅ Lv s t → t ∈ Tb → t ∉ Kt → S1GranuleH st H OS s t) ∧ + (∀ t, S2Reach st (PoolSet st Pp s) Re bits s t → t ∈ Te → H t = some (.other (bits t))) + +variable {H : Heap} {OS Pp Tb Te Kt : Set U64} {Lv Re bits : U64 → Nat} {s : S} + +/-- Every mapped PageTable cap is consistent with its active ASID walk. -/ +def PtFndAll (st : machine.Store S) [L : LawfulStore st] (OS Pp : Set U64) (Lv Re bits : U64 → Nat) + (n : U64) (s : S) : Prop := + ∀ y ∈ OS, ∀ p asid va, capA st s y = .PageTable p true asid va → + PtFnd st n (PoolSet st Pp s) ∅ Lv Re bits s asid va p + +/-- A mapped Stage-1 PageTable has at most one reachable parent descriptor. -/ +theorem PtFnd.uniqueS1 {Hr : Set U64} {n a va ptr b b' : U64} (h : PtFnd st n Pp Hr Lv Re bits s a va ptr) + (hb : VsNm st Pp Hr Lv s ptr b) (hb' : VsNm st Pp Hr Lv s ptr b') : b = b' := by + obtain ⟨raw, t, sh, lv, hr, _, init, run⟩ := h.s1 b hb + obtain ⟨raw', t', sh', lv', hr', _, init', run'⟩ := h.s1 b' hb' + rw [hr] at hr' + have er : raw = raw' := core.result.Result.Ok.inj (okinj hr') + subst raw' + rcases init with ⟨tag, rfl, rfl, rfl⟩ | ⟨tag, rfl, rfl, rfl⟩ <;> + rcases init' with ⟨tag', rfl, rfl, rfl⟩ | ⟨tag', rfl, rfl, rfl⟩ + · exact Option.some.inj (okinj (run.symm.trans run')) + · exact (tag' tag).elim + · exact (tag tag').elim + · exact Option.some.inj (okinj (run.symm.trans run')) + +/-- A mapped Stage-2 PageTable has at most one reachable parent descriptor. -/ +theorem PtFnd.uniqueS2 {Hr : Set U64} {n a va ptr b b' : U64} (h : PtFnd st n Pp Hr Lv Re bits s a va ptr) + (hb : S2Nm st Pp Re bits s ptr b) (hb' : S2Nm st Pp Re bits s ptr b') : b = b' := by + obtain ⟨_, root, g, _, _, hf, hg, run⟩ := h.s2 b hb + obtain ⟨_, root', g', _, _, hf', hg', run'⟩ := h.s2 b' hb' + rw [hf] at hf' + rw [hg] at hg' + have er : root = root' := core.result.Result.Ok.inj (okinj hf') + have eg : g = g' := okinj hg' + subst root' + subst g' + exact Option.some.inj (okinj (run.symm.trans run')) + +/-- The one active ASID for a mapped PageTable selects just one translation stage. -/ +theorem PtFnd.oneStage {Hr : Set U64} {n a va ptr b b' : U64} (h : PtFnd st n Pp Hr Lv Re bits s a va ptr) + (hb : VsNm st Pp Hr Lv s ptr b) (hb' : S2Nm st Pp Re bits s ptr b') : False := by + obtain ⟨raw, _, _, _, hr, tag, _, _⟩ := h.s1 b hb + obtain ⟨raw', _, _, hr', tag', _, _, _⟩ := h.s2 b' hb' + rw [hr] at hr' + have er : raw = raw' := core.result.Result.Ok.inj (okinj hr') + rw [er] at tag + exact tag tag' + +/-- **The Stage-2 objects in the typed heap** (module docstring; the authorised `Te`–`H` link, a case fact of the +`hvs` witness): every object of `Te` is an `other (bits p)` object of `H`, and a top-level one (`Re p + 1 = s2lv n`, +a Stage-2 root) has 13 bits (`STAGE2_VSPACE = 13`, fl4-abi consts.rs:98; objects.rs:42). -/ +def TeH (H : Heap) (Te : Set U64) (Re bits : U64 → Nat) (n : U64) : Prop := + ∀ p ∈ Te, H p = some (.other (bits p)) ∧ (Re p + 1 = s2lv n → bits p = 13) + +/-- A live pool entry and the ASID that selects it. -/ +def ActiveAsidRoot (st : machine.Store S) [L : LawfulStore st] (Pp : Set U64) (s : S) + (asid raw : U64) : Prop := + ∃ i o : U64, i.val < 128 ∧ o.val < 4096 ∧ o.val % 8 = 0 ∧ asid.val = i.val * 512 + o.val / 8 ∧ + ∃ pool ∈ PoolSet st Pp s, L.mem s (wa (L.ksb s) (AtOff i)) = pool ∧ + L.mem s (wa pool o) = raw ∧ raw ≠ 0#u64 + +private theorem asid_low_offset (asid : U64) : + (core.num.U64.wrapping_mul (asid &&& 511#u64) 8#u64).val = (asid.val % 512) * 8 := by + rw [mul8_val (and511 asid), UScalar.val_and, show (511#u64 : U64).val = 2 ^ 9 - 1 by rfl, + Nat.and_two_pow_sub_one_eq_mod] + +/-- An active ASID entry is exactly what the concrete lookup reads at its ASID. -/ +theorem ActiveAsidRoot.find {asid raw : U64} (h : ActiveAsidRoot st Pp s asid raw) : + vspace.find_asid_raw st s asid = ok (.Ok raw) := by + obtain ⟨i, o, hi, ho, h8, ha, pool, hp, htab, hraw, hn⟩ := h + obtain ⟨_, _, _, _, _, _, hp0⟩ := hp + obtain ⟨high, eh, hv⟩ := spec_exists_u (U64.ShiftRight_spec (x := asid) (y := 16#u64) (by decide)) + obtain ⟨low, el, lv⟩ := spec_exists_u (U64.ShiftRight_spec (x := asid) (y := 9#u64) (by decide)) + have eh' : high = 0#u64 := UScalar.eq_of_val_eq (by + change high.val = 0 + rw [hv.1, Nat.shiftRight_eq_div_pow] + change asid.val / 65536 = 0 + omega) + have el' : low = i := UScalar.eq_of_val_eq (by + rw [lv.1, Nat.shiftRight_eq_div_pow] + change asid.val / 512 = i.val + omega) + have eo : core.num.U64.wrapping_mul (asid &&& 511#u64) 8#u64 = o := UScalar.eq_of_val_eq (by + rw [asid_low_offset, ha] + omega) + unfold vspace.find_asid_raw vspace.ASID_BITS vspace.ASID_LOW_BITS + rw [eh, eh', el, el'] + simp only [bind_ok, show (0#u64 != 0#u64) = false by rfl, Bool.false_eq_true, if_false, vspace.asid_table.eq] + rw [htab, if_neg hp0] + simp only [lift, bind_ok, L.read_eq, eo, hraw, if_neg hn] + +/-- A mapped root cap with the given object, ASID, and active pool-entry tag. -/ +def MappedAsidRoot (cap : capability.Cap) (root asid tag : U64) : Prop := + (tag = 0#u64 ∧ cap = .Pml4 root true asid) ∨ + (tag = 1#u64 ∧ ∃ va, cap = .Ept root 0#u64 true asid va) ∨ + (tag = 2#u64 ∧ cap = .HighVSpace root true asid) + +/-- Active entries have matching caps. Copies of the same mapped root retain its assigned ASID. -/ +structure RootAgreement (st : machine.Store S) [L : LawfulStore st] (OS Pp : Set U64) (s : S) : Prop where + backed : ∀ asid raw, ActiveAsidRoot st Pp s asid raw → + ∃ x ∈ OS, MappedAsidRoot (capA st s x) (raw &&& ~~~3#u64) asid (raw &&& 3#u64) + agree : ∀ x ∈ OS, ∀ y ∈ OS, ∀ root a b tag tag', + MappedAsidRoot (capA st s x) root a tag → MappedAsidRoot (capA st s y) root b tag' → a = b + +/-- An active root object is named at only one ASID. -/ +theorem RootAgreement.asid_unique (h : RootAgreement st OS Pp s) {a b raw raw' : U64} + (ha : ActiveAsidRoot st Pp s a raw) (hb : ActiveAsidRoot st Pp s b raw') + (root : (raw &&& ~~~3#u64) = (raw' &&& ~~~3#u64)) : a = b := by + obtain ⟨x, hx, cx⟩ := h.backed a raw ha + obtain ⟨y, hy, cy⟩ := h.backed b raw' hb + rw [← root] at cy + exact h.agree x hx y hy _ a b _ _ cx cy + +/-- R2's lookup and typing facts over the same active ASID pools. The Stage-2 typing retains its all-live +root set for the reserved entry clause. -/ +structure S1aR2Core (st : machine.Store S) [L : LawfulStore st] (H : Heap) (OS Pp Tb Hr Te Kt : Set U64) + (Lv Re bits : U64 → Nat) (n : U64) (s : S) : Prop where + lookup : VsLk st H OS Pp Tb Te Kt Lv Re bits s + walk : PtFndAll st OS Pp Lv Re bits n s + root : RootAgreement st OS Pp s + stage1 : VsTyR st (L.ksb s) (PoolSet st Pp s) ∅ Tb Lv s + stage2 : S2TyR st n (PoolSet st Pp s) Hr Te Re bits s + heap : TeH H Te Re bits n + +/-- The existing full typings provide the narrowed active-pool entry facts. -/ +theorem S1aR2Core.ofTy {Hr : Set U64} {n : U64} (lookup : VsLk st H OS Pp Tb Te Kt Lv Re bits s) + (walk : PtFndAll st OS Pp Lv Re bits n s) (root : RootAgreement st OS Pp s) + (vs : VsTy st (L.ksb s) Pp Tb Lv s) + (s2 : S2Ty st n Pp Hr Te Re bits s) (heap : TeH H Te Re bits n) : + S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s := + ⟨lookup, walk, root, (vsTy_entries vs).toR, + ⟨fun p hp o ho h8 nz => s2.tag p hp.1 o ho h8 nz, s2.hi, fun p hp _ => s2.desc p hp⟩, heap⟩ + +/-- The lookup fact needed by PageTableUnmap at the invoked mapped cap. -/ +theorem S1aR2Core.invoked {Hr : Set U64} {n : U64} (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + {slot ptr asid va : U64} (hs : slot ∈ OS) + (hc : obj.Slot.cap st slot s = ok (.PageTable ptr true asid va)) : + PtFnd st n (PoolSet st Pp s) ∅ Lv Re bits s asid va ptr := + h.walk slot hs ptr asid va (okinj ((capA_eq s slot).symm.trans hc)) + +/-! ## The unmapped-object facts over the reachable tables -/ + +/-- **An unmapped cap's object is no kernel table.** -/ +theorem VsLk.unmKt (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) {x p : U64} {n : Nat} (hx : x ∈ OS) + (hu : UnmCap (capA st s x) p n) : p ∉ Kt := fun hk => h.kt p hk x hx hu.names + +/-- **An unmapped cap's object is no reachable Stage-1 table** (`UnmT` over `VsRt`, object level). -/ +theorem VsLk.unmR1 (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) {x p : U64} {n : Nat} (hx : x ∈ OS) + (hu : UnmCap (capA st s x) p n) : p ∉ VsRt st (PoolSet st Pp s) ∅ Tb Lv s := fun ⟨ht, hr⟩ => by + obtain ⟨y, hy, m⟩ := h.bk1 p hr ht (h.unmKt hx hu) + exact h.ex x hx y hy p n hu m + +/-- **An unmapped cap's object is no reachable Stage-2 object** (`UnmZ`'s "off `Te`" over `S2Rt`, object level). -/ +theorem VsLk.unmR2 (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) {x p : U64} {n : Nat} (hx : x ∈ OS) + (hu : UnmCap (capA st s x) p n) : p ∉ S2Rt st (PoolSet st Pp s) Te Re bits s := fun ⟨ht, hr⟩ => by + obtain ⟨y, hy, m⟩ := h.bk2 p hr ht + exact h.ex x hx y hy p n hu m + +/-- **An unmapped cap's object is zero** (`UnmZ`'s zero words). -/ +theorem VsLk.unmZ (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) {x p : U64} {n : Nat} (hx : x ∈ OS) + (hu : UnmCap (capA st s x) p n) {o : U64} (ho : o.val < n) (h8 : o.val % 8 = 0) : L.mem s (wa p o) = 0#u64 := + h.zr x hx p n hu o ho h8 + +theorem VsLk.unmCR1 (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) {x p : U64} {n : Nat} (hx : x ∈ OS) + (hu : UnmC st x p n s) : p ∉ VsRt st (PoolSet st Pp s) ∅ Tb Lv s := h.unmR1 hx hu.capA + +theorem VsLk.unmCR2 (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) {x p : U64} {n : Nat} (hx : x ∈ OS) + (hu : UnmC st x p n s) : p ∉ S2Rt st (PoolSet st Pp s) Te Re bits s := h.unmR2 hx hu.capA + +theorem VsLk.unmCZ (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) {x p : U64} {n : Nat} (hx : x ∈ OS) + (hu : UnmC st x p n s) {o : U64} (ho : o.val < n) (h8 : o.val % 8 = 0) : L.mem s (wa p o) = 0#u64 := + h.unmZ hx hu.capA ho h8 + +/-! ## Word level (gen 27, S1A-a): `UnmT` / `UnmZ` over the reachable tables -/ + +/-- **Words of two distinct heap objects differ** (`HeapOK.disj`, `fits`). -/ +theorem heap_wa_ne {p q o o' : U64} {k k' : HKind} (hH : HeapOK H) (hp : H p = some k) (hq : H q = some k') + (hpq : p ≠ q) (ho : o.val < 2 ^ k.bits) (ho' : o'.val < 2 ^ k'.bits) : wa p o ≠ wa q o' := fun e => by + have f1 := hH.fits p k hp + have f2 := hH.fits q k' hq + have d := hH.disj p k q k' hp hq hpq + have e1 : (wa p o).val = p.val + o.val := wadd_val (by omega) + have e2 : (wa q o').val = q.val + o'.val := wadd_val (by omega) + have := congrArg UScalar.val e + omega + +/-- **Word-level `UnmT` over the reachable tables** (QueueS1Map's `UnmT` at `VsRt`): no word of an unmapped cap's +object is a word of a reachable Stage-1 table (`VsLk.vh` + `HeapOK.disj`; the `Kt` tables are `other 12` objects of +`H`, as in `KtH H Kt`). -/ +theorem VsLk.unmT (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) (hH : HeapOK H) + (hK : ∀ t ∈ Kt, H t = some (.other 12)) {x p : U64} {n : Nat} (hx : x ∈ OS) + (hu : UnmCap (capA st s x) p n) {o : U64} (ho : o.val < n) : + ¬ PtW (VsRt st (PoolSet st Pp s) ∅ Tb Lv s) (wa p o) := by + rintro ⟨q, hq, o', ho', -, e⟩ + obtain ⟨z, rfl, hp⟩ := h.vh.1 x hx p _ hu + have exact4 (hqH : H q = some (.other 12)) : False := + heap_wa_ne hH hp hqH (fun eq => h.unmR1 hx hu (by rw [eq]; exact hq)) (by simpa [HKind.bits] using ho) + (by simpa [HKind.bits] using ho') e + by_cases hk : q ∈ Kt + · exact exact4 (hK q hk) + rcases h.vh.2.1 q hq.2 hq.1 hk with ordinary | ⟨R, hR, granule, y, hy, a, hc⟩ + · exact exact4 ordinary + have diff : p ≠ R := by + intro eq + subst p + exact h.ex x hx y hy R _ hu (Or.inr (Or.inr (Or.inl ⟨a, hc⟩))) + have cover : R.val ≤ q.val ∧ q.val + 4096 ≤ R.val + 2 ^ (HKind.other 13).bits := by + rcases granule with rfl | rfl + · simp [HKind.bits] + · have fit := hH.fits R _ hR + change R.val + 8192 ≤ 2 ^ 64 at fit + have offset : (wa R 4096#u64).val = R.val + 4096 := + wadd_val (by change R.val + 4096 < 2 ^ 64; omega) + rw [offset] + simp [HKind.bits] + have fitP := hH.fits p _ hp + have fitR := hH.fits R _ hR + have disj := hH.disj p _ R _ hp hR diff + change p.val + 2 ^ z ≤ 2 ^ 64 at fitP + change R.val + 2 ^ (HKind.other 13).bits ≤ 2 ^ 64 at fitR + have valueP := wadd_val (x := p) (y := o) (by omega) + have valueQ := wadd_val (x := q) (y := o') (by omega) + have value := congrArg UScalar.val e + rw [valueP, valueQ] at value + change p.val + 2 ^ z ≤ R.val ∨ R.val + 2 ^ (HKind.other 13).bits ≤ p.val at disj + omega + +/-- **Word-level `UnmZ`'s "off `Te`" over the reachable Stage-2 objects** (QueueS2Map's `UnmZ` at `S2Rt`). -/ +theorem VsLk.unmTZ (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) (hH : HeapOK H) {x p : U64} {n : Nat} + (hx : x ∈ OS) (hu : UnmCap (capA st s x) p n) {o : U64} (ho : o.val < n) : + ¬ PtWb (S2Rt st (PoolSet st Pp s) Te Re bits s) bits (wa p o) := by + rintro ⟨q, hq, o', ho', -, e⟩ + obtain ⟨z, rfl, hp⟩ := h.vh.1 x hx p _ hu + have hpq : p ≠ q := fun e' => h.unmR2 hx hu (by rw [e']; exact hq) + exact heap_wa_ne hH hp (h.vh.2.2 q hq.2 hq.1) hpq (by simpa [HKind.bits] using ho) + (by simpa [HKind.bits] using ho') e + +/-- `VsLk.unmT` in `UnmC` form. -/ +theorem VsLk.unmCT (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) (hH : HeapOK H) + (hK : ∀ t ∈ Kt, H t = some (.other 12)) {x p : U64} {n : Nat} (hx : x ∈ OS) (hu : UnmC st x p n s) {o : U64} + (ho : o.val < n) : ¬ PtW (VsRt st (PoolSet st Pp s) ∅ Tb Lv s) (wa p o) := h.unmT hH hK hx hu.capA ho + +/-- `VsLk.unmTZ` in `UnmC` form. -/ +theorem VsLk.unmCTZ (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) (hH : HeapOK H) {x p : U64} {n : Nat} + (hx : x ∈ OS) (hu : UnmC st x p n s) {o : U64} (ho : o.val < n) : + ¬ PtWb (S2Rt st (PoolSet st Pp s) Te Re bits s) bits (wa p o) := h.unmTZ hH hx hu.capA ho + +/-! ## Frame -/ + +/-- **Stage-1 reachability at `s'` is reachability at `s`** when the pool words and the reachable tables' words +are kept. -/ +theorem VsReach.backOf {Pp' : Set U64} {s' : S} (sub : Pp' ⊆ Pp) + (hP : ∀ p ∈ Pp, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s' (wa p o) = L.mem s (wa p o)) + (hT : ∀ p, VsReach st Pp ∅ Lv s p → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + {t : U64} (h : VsReach st Pp' ∅ Lv s' t) : VsReach st Pp ∅ Lv s t := by + induction h with + | hr hR => exact absurd hR (by simp) + | @root0 p o hp ho h8 hne h0 => + rw [hP p (sub hp) o ho h8] at hne h0 ⊢ + exact .root0 (sub hp) ho h8 hne h0 + | @root2 p o hp ho h8 h2 => + rw [hP p (sub hp) o ho h8] at h2 ⊢ + exact .root2 (sub hp) ho h8 h2 + | @step p o _ hl ho h8 h3 ih => + rw [hT p ih o ho h8] at h3 ⊢ + exact .step ih hl ho h8 h3 + +theorem VsReach.back {s' : S} + (hP : ∀ p ∈ Pp, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s' (wa p o) = L.mem s (wa p o)) + (hT : ∀ p, VsReach st Pp ∅ Lv s p → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + {t : U64} (h : VsReach st Pp ∅ Lv s' t) : VsReach st Pp ∅ Lv s t := + VsReach.backOf (Set.Subset.refl _) hP hT h + +/-- **Stage-2 reachability at `s'` is reachability at `s`** (as `VsReach.back`). -/ +theorem S2Reach.backOf {Pp' : Set U64} {s' : S} (sub : Pp' ⊆ Pp) + (hP : ∀ p ∈ Pp, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s' (wa p o) = L.mem s (wa p o)) + (hT : ∀ p, S2Reach st Pp Re bits s p → ∀ o : U64, o.val < 2 ^ bits p → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + {t : U64} (h : S2Reach st Pp' Re bits s' t) : S2Reach st Pp Re bits s t := by + induction h with + | @root p o hp ho h8 h1 => + rw [hP p (sub hp) o ho h8] at h1 ⊢ + exact .root (sub hp) ho h8 h1 + | @step p o _ hr ho h8 h3 ih => + rw [hT p ih o ho h8] at h3 ⊢ + exact .step ih hr ho h8 h3 + +theorem S2Reach.back {s' : S} + (hP : ∀ p ∈ Pp, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s' (wa p o) = L.mem s (wa p o)) + (hT : ∀ p, S2Reach st Pp Re bits s p → ∀ o : U64, o.val < 2 ^ bits p → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + {t : U64} (h : S2Reach st Pp Re bits s' t) : S2Reach st Pp Re bits s t := + S2Reach.backOf (Set.Subset.refl _) hP hT h + +/-- Zeroing ASID table entries can only remove active pools. -/ +theorem TabKeepOrZero.poolSet {s' : S} (h : TabKeepOrZero st s s') : + PoolSet st Pp s' ⊆ PoolSet st Pp s := by + rintro p ⟨hp, o, lo, hi, aligned, word, nz⟩ + obtain ⟨j, eq⟩ := atOff_of_off lo hi aligned + rw [← eq] at word + rcases h.2 j with keep | zero + · obtain ⟨a, b, c⟩ := AtOff.v j + exact ⟨hp, AtOff j, a, b, c, keep.symm.trans word, nz⟩ + · exact (nz (word.symm.trans zero)).elim + +/-- With the same ASID-table words, the set of active pools is unchanged. -/ +theorem TabKeep.poolSet_eq {s' : S} (h : TabKeep st s s') : + PoolSet st Pp s' = PoolSet st Pp s := + Set.Subset.antisymm h.toDel.poolSet + (TabKeep.toDel (s := s') (s' := s) ⟨h.1.symm, fun i => (h.2 i).symm⟩).poolSet + +/-- No new active ASID entry arises by clearing ASID-table or pool words. -/ +theorem ActiveAsidRoot.back {s' : S} {asid raw : U64} (ht : TabKeepOrZero st s s') + (hp : ∀ pool ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa pool o) = L.mem s (wa pool o) ∨ L.mem s' (wa pool o) = 0#u64) + (h : ActiveAsidRoot st Pp s' asid raw) : ActiveAsidRoot st Pp s asid raw := by + obtain ⟨i, o, hi, ho, h8, ha, pool, hp', htable, hword, hn⟩ := h + have hp0 := ht.poolSet hp' + obtain ⟨_, _, _, _, _, _, hnPool⟩ := hp' + rcases ht.2 i with he | hz + · rcases hp pool hp0 o ho h8 with hw | hw + · exact ⟨i, o, hi, ho, h8, ha, pool, hp0, he.symm.trans htable, hw.symm.trans hword, hn⟩ + · exact (hn (hword.symm.trans hw)).elim + · exact (hnPool (htable.symm.trans hz)).elim + +/-- Root-cap agreement when caps are kept and ASID entries are kept or cleared. -/ +theorem RootAgreement.keep {s' : S} (h : RootAgreement st OS Pp s) (ht : TabKeepOrZero st s s') + (hc : ∀ x ∈ OS, capA st s' x = capA st s x) + (hp : ∀ pool ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa pool o) = L.mem s (wa pool o) ∨ L.mem s' (wa pool o) = 0#u64) : + RootAgreement st OS Pp s' where + backed a raw hr := by + obtain ⟨x, hx, cx⟩ := h.backed a raw (hr.back ht hp) + exact ⟨x, hx, by rwa [hc x hx]⟩ + agree x hx y hy ptr a b tag tag' cx cy := by + rw [hc x hx] at cx + rw [hc y hy] at cy + exact h.agree x hx y hy ptr a b tag tag' cx cy + +/-- A frame on ASID and table words preserves all mapped PageTable walks over active pools. -/ +theorem PtFndAll.keep {s' : S} {Hr Pt : Set U64} {kb n : U64} + (h : PtFndAll st OS Pp Lv Re bits n s) (hP : Pp ⊆ Pt) (hT : Tb ⊆ Pt) + (hE : Gran Te bits ⊆ Pt) (hS : S2OK Te bits Hr) (hH : HrOK kb Pp Tb Lv Hr) + (h0 : VsTyR st kb (PoolSet st Pp s) ∅ Tb Lv s) + (h2 : S2TyR st n (PoolSet st Pp s) Hr Te Re bits s) + (hb : L.ksb s = kb) (hTab : TabKeep st s s') (k : VsKeep st kb Pt s s') + (hc : ∀ x ∈ OS, capA st s' x = capA st s x) : PtFndAll st OS Pp Lv Re bits n s' := by + intro x hx p a va cx + rw [hc x hx] at cx + rw [hTab.poolSet_eq (Pp := Pp)] + have hH' : HrOK kb (PoolSet st Pp s) Tb Lv Hr := + { hH with pp := fun pool hp => hH.pp pool hp.1 } + have hp' : PoolSet st Pp s ⊆ Pt := fun _ hpool => hP hpool.1 + exact (h x hx p a va cx).vkSeed (by simp) hp' hT hE hS hH' h0 h2 hb hTab.1 k + +/-- **`VsLk` along a step keeping the caps of `OS`, the pool words, the reachable tables' words and the unmapped +objects' words** (module docstring). -/ +theorem VsLk.keep {s' : S} (h : VsLk st H OS Pp Tb Te Kt Lv Re bits s) (hc : ∀ y ∈ OS, capA st s' y = capA st s y) + (table : TabKeepOrZero st s s') + (hP : ∀ p ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → L.mem s' (wa p o) = L.mem s (wa p o)) + (hT1 : ∀ p, VsReach st (PoolSet st Pp s) ∅ Lv s p → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + (hT2 : ∀ p, S2Reach st (PoolSet st Pp s) Re bits s p → ∀ o : U64, o.val < 2 ^ bits p → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) + (hz : ∀ x ∈ OS, ∀ p n, UnmCap (capA st s x) p n → ∀ o : U64, o.val < n → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) : + VsLk st H OS Pp Tb Te Kt Lv Re bits s' where + bk1 t hr ht hk := by + obtain ⟨y, hy, m⟩ := h.bk1 t (VsReach.backOf table.poolSet hP hT1 hr) ht hk + exact ⟨y, hy, by rw [hc y hy]; exact m⟩ + bk2 t hr ht := by + obtain ⟨y, hy, m⟩ := h.bk2 t (S2Reach.backOf table.poolSet hP hT2 hr) ht + exact ⟨y, hy, by rw [hc y hy]; exact m⟩ + kt t ht y hy := by rw [hc y hy]; exact h.kt t ht y hy + ex x hx y hy p n hu := by rw [hc y hy]; rw [hc x hx] at hu; exact h.ex x hx y hy p n hu + zr x hx p n hu o ho h8 := by + rw [hc x hx] at hu + rw [hz x hx p n hu o ho h8] + exact h.zr x hx p n hu o ho h8 + vh := ⟨fun x hx p n hu => by rw [hc x hx] at hu; exact h.vh.1 x hx p n hu, + fun t hr ht hk => by + rcases h.vh.2.1 t (VsReach.backOf table.poolSet hP hT1 hr) ht hk with ordinary | ⟨R, hR, granule, y, hy, a, eq⟩ + · exact Or.inl ordinary + · exact Or.inr ⟨R, hR, granule, y, hy, a, (hc y hy).trans eq⟩, + fun t hr ht => h.vh.2.2 t (S2Reach.backOf table.poolSet hP hT2 hr) ht⟩ + +/-- The whole R2 entry witness frames through writes which keep VSpace words, caps and unmapped objects. -/ +theorem S1aR2Core.keep {s' : S} {Pt Hr : Set U64} {n : U64} + (h : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s) + (hP : Pp ⊆ Pt) (hT : Tb ⊆ Pt) (hE : Gran Te bits ⊆ Pt) (hS : S2OK Te bits Hr) + (hH : HrOK (L.ksb s) Pp Tb Lv Hr) (hb : L.ksb s' = L.ksb s) + (k : VsKeep st (L.ksb s) Pt s s') (hc : ∀ x ∈ OS, capA st s' x = capA st s x) + (hz : ∀ x ∈ OS, ∀ p size, UnmCap (capA st s x) p size → ∀ o : U64, o.val < size → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o)) : S1aR2Core st H OS Pp Tb Hr Te Kt Lv Re bits n s' := by + have ht : TabKeep st s s' := ⟨hb, fun i => by rw [hb]; exact k _ (Or.inr (asW_at _ i))⟩ + have hp' : PoolSet st Pp s ⊆ Pt := fun _ hp => hP hp.1 + have hp : ∀ p ∈ PoolSet st Pp s, ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o) := + fun p hp o ho h8 => k _ (Or.inl ⟨p, hp' hp, o, ho, h8, rfl⟩) + have h1 : ∀ p, VsReach st (PoolSet st Pp s) ∅ Lv s p → ∀ o : U64, o.val < 4096 → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o) := by + intro p hr o ho h8 + have hsub : (∅ : Set U64) ⊆ Tb := by simp + have hp := (h.stage1.sub.reach (hr_rt hsub) hr).1 + exact k _ (Or.inl ⟨p, hT hp, o, ho, h8, rfl⟩) + have h2 : ∀ p, S2Reach st (PoolSet st Pp s) Re bits s p → ∀ o : U64, o.val < 2 ^ bits p → o.val % 8 = 0 → + L.mem s' (wa p o) = L.mem s (wa p o) := by + intro p hr o ho h8 + exact k _ (Or.inl (ptw_mono hE (ptwb_gran hS.sz ⟨p, (h.stage2.sub.reach hr).1, o, ho, h8, rfl⟩))) + have hh : HrW st Hr s s' := fun R hR => k _ (Or.inl ⟨R, hT (hH.sub hR), 4088#u64, by simp, by simp, rfl⟩) + refine ⟨h.lookup.keep hc ht.toDel hp h1 h2 hz, h.walk.keep hP hT hE hS hH h.stage1 h.stage2 rfl ht k hc, + h.root.keep ht.toDel hc (fun p hm o ho h8 => Or.inl (hp p hm o ho h8)), ?_, ?_, h.heap⟩ + · rw [hb, ht.poolSet_eq (Pp := Pp)] + exact h.stage1.keepZ hp' hT (by simp) k.vsz + · rw [ht.poolSet_eq (Pp := Pp)] + exact h.stage2.keep hp' hE hS k.vsz hh + +end ST +end R +end W7 + +end + +end Fl4ProofsA64.P1 diff --git a/proofs/Fl4ProofsA64/P1/S1aVsUnmB.lean b/proofs/Fl4ProofsA64/P1/S1aVsUnmB.lean new file mode 100644 index 000000000..436a1385f --- /dev/null +++ b/proofs/Fl4ProofsA64/P1/S1aVsUnmB.lean @@ -0,0 +1,962 @@ +/- +P1 (aarch64, A64-S1A gen 26): **S1aVsUnm's `VsLk` at the boot witness `w1`**, with and without the kernel table +`kt` of S1aBootK (over A64-Boot's definitions only; no Boot file edited). + +* **`capOf_vs`** (BootMdb1's `capsplit`, as S1aBootW1's `capOf_ptK`): no root CNode slot holds an unmapped + `PageTable` / level-0 `Ept` cap, and every table a root CNode cap names is a page of `w1Pt`; **`w1_capV`** the same + for every `w1` slot (`w1_capS`). +* **`w1_backed`**: the four tables of `w1Tb` are backed by mapped caps (root slot 3 the `Pml4` of the VSpace root, + slots `16 + nc … 18 + nc` the mapped `PageTable`s `L1`, `L2`, `L3`). +* **`w1_vsLk`**: `VsLk` at `w1` with `Kt = ∅` and no Stage-2 objects (`Te = ∅`); **`w1K_vsLk`**: with `Kt = {kt}` + over S1aBootK's `w1K_vs` table set `insert kt w1Tb` (levels with `kt` at 1): `kt` is reachable only through kernel + TTBR1 copies and named by no cap. +* (gen 27) **`w1Tb_h`**: the four `w1Tb` tables are `other 12` objects of `w1H` (BootW1Items' `w1_pt`), giving + `VsLk.vh` at both witnesses (`KtH`'s `Heap.add_of_not` off `kt`). + +* (gen 41) Root-cap agreement and `PtFndAll` at both witnesses. At `w1` ASID 1 selects the boot VSpace; + each of its three mapped PageTables has a unique concrete unmap path. `w0_s1aR2Core` and `w1K_s1aR2Core` + assemble the common R2 entry facts. + +Named premises: none. Case facts: none. +-/ +import Fl4ProofsA64.P1.S1aVsUnm +import Fl4ProofsA64.P1.S1aBootK +import Fl4ProofsA64.P1.S1aR2Contract +open Aeneas Aeneas.Std Result + +namespace Fl4ProofsA64.P1 +open fl4_core_a64 Fl4ProofsA64.P0.Consts Fl4Proofs.P3 + +local notation "wa" => core.num.U64.wrapping_add + +namespace W7 +namespace R +namespace ST +namespace BootWit + +noncomputable section + +set_option maxHeartbeats 4000000 in +/-- **No root CNode slot holds an unmapped VSpace cap, and the tables its caps name are `w1Pt` pages.** -/ +theorem capOf_vs (nc i : Nat) : + (∀ p n, ¬ UnmCap (capOf nc i) p n) ∧ ∀ t, NamesV (capOf nc i) t → t ∈ w1Pt := by + capsplit (refine ⟨fun p n h => ?_, fun t h => ?_⟩ <;> + first + | (rcases h with ⟨-, a, v, h⟩ | ⟨-, a, v, h⟩ <;> cases h; done) + | (rcases h with ⟨m, a, v, h⟩ | ⟨m, a, h⟩ | ⟨m, a, h⟩ | ⟨R, m, a, h, -⟩ | ⟨l, m, a, v, h⟩ <;> cases h <;> + first | exact Or.inl vVS | exact w1Pt_l1 | exact w1Pt_l2 | exact w1Pt_l3)) + +private theorem capOf_root_asid (nc i : Nat) {ptr asid tag : U64} : + MappedAsidRoot (capOf nc i) ptr asid tag → asid = 1#u64 := by + capsplit (rintro (⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩) <;> cases e <;> rfl) + +/-- The initial kernel has empty ASID entries and null caps. -/ +theorem w0_rootAgreement {kb ib r now mt : U64} {nc : Nat} (P : BootLay kb ib nc) : + RootAgreement bst (bootOS kb ib nc) Set.univ (bootS kb ib nc r now mt) where + backed asid raw h := by + obtain ⟨i, o, _, _, _, _, pool, hp, ht, _, _⟩ := h + have hz : bL.mem (bootS kb ib nc r now mt) (wa kb (AtOff i)) = 0#u64 := + boot_asZero P _ (asW_at kb i) + change bL.mem (bootS kb ib nc r now mt) (wa kb (AtOff i)) = pool at ht + obtain ⟨_, _, _, _, _, _, hpool⟩ := hp + exact (hpool (ht.symm.trans hz)).elim + agree x hx _ _ _ _ _ _ _ hc _ := by + rw [boot_null P x hx] at hc + rcases hc with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e + +/-- There are no mapped page tables in the initial kernel's slots. -/ +theorem w0_ptFndAll {kb ib r now mt n : U64} {nc : Nat} (P : BootLay kb ib nc) (Lv Re bits : U64 → Nat) : + PtFndAll bst (bootOS kb ib nc) Set.univ Lv Re bits n (bootS kb ib nc r now mt) := by + intro x hx ptr a va hc + rw [boot_null P x hx] at hc + cases hc + +/-- The pre-user boot witness satisfies the R2 entry facts with no tables or roots. -/ +theorem w0_s1aR2Core {kb ib r now mt : U64} {nc : Nat} (P : BootLay kb ib nc) (Lv Re bits : U64 → Nat) (n : U64) : + S1aR2Core bst (bootH kb ib nc) (bootOS kb ib nc) Set.univ ∅ ∅ ∅ ∅ Lv Re bits n (bootS kb ib nc r now mt) := by + have emptyPool : ∀ q, q ∉ PoolSet bst Set.univ (bootS kb ib nc r now mt) := by + intro q hp + obtain ⟨_, o, h1, h2, h8, h, hn⟩ := hp + exact hn (h.symm.trans (boot_asZero P _ ⟨o, h1, h2, h8, rfl⟩)) + have noUnm : ∀ x ∈ bootOS kb ib nc, ∀ p z, ¬ UnmCap (capA bst (bootS kb ib nc r now mt) x) p z := by + intro x hx p z h + rw [boot_null P x hx] at h + rcases h with ⟨_, _, _, e⟩ | ⟨_, _, _, e⟩ <;> cases e + refine ⟨⟨fun _ _ h _ => (Set.notMem_empty _ h).elim, fun _ _ h => (Set.notMem_empty _ h).elim, + fun _ h => (Set.notMem_empty _ h).elim, fun x hx _ _ p z h => (noUnm x hx p z h).elim, + fun x hx p z h => (noUnm x hx p z h).elim, ⟨fun x hx p z h => (noUnm x hx p z h).elim, + fun _ _ h => (Set.notMem_empty _ h).elim, fun _ _ h => (Set.notMem_empty _ h).elim⟩⟩, + w0_ptFndAll P Lv Re bits, w0_rootAgreement P, ?_, ?_, fun _ h => (Set.notMem_empty _ h).elim⟩ + · exact ⟨fun o h1 h2 h8 hn => (hn (boot_asZero P _ ⟨o, h1, h2, h8, rfl⟩)).elim, + fun q hp => (emptyPool q hp).elim, fun _ h => (Set.notMem_empty _ h).elim⟩ + · exact ⟨fun q hp => (emptyPool q hp).elim, fun _ h => (Set.notMem_empty _ h).elim, + fun _ h => (Set.notMem_empty _ h).elim⟩ + +/-- The pre-user boot state has no live VSpace roots. -/ +theorem w0_rootSlots {kb ib r now mt : U64} {nc : Nat} (P : BootLay kb ib nc) (Kt : Set U64) (n : U64) : + S1aRootSlots bst (bootOS kb ib nc) Kt n (bootS kb ib nc r now mt) := by + constructor + · intro x hx p m a cap + rw [boot_null P x hx] at cap + cases cap + · intro x hx p m a v cap + rw [boot_null P x hx] at cap + cases cap + · intro x hx p m a cap + rw [boot_null P x hx] at cap + cases cap + · intro x hx p m a cap + rw [boot_null P x hx] at cap + cases cap + +/-- The complete R2 contract and kernel-table separation at the pre-user boot state. -/ +theorem w0_s1aR2 {kb ib r now mt : U64} {nc : Nat} (P : BootLay kb ib nc) + (Lv Re bits : U64 → Nat) (n : U64) : + S1aR2 bst (bootH kb ib nc) (bootOS kb ib nc) ∅ Set.univ ∅ ∅ ∅ ∅ Lv Re bits n + (bootS kb ib nc r now mt) ∧ S1aKtUt bst (bootOS kb ib nc) ∅ (bootS kb ib nc r now mt) := by + refine ⟨?_, w0_ktOutE.s1aKtUt⟩ + let s := bootS kb ib nc r now mt + have ash (i : U64) : bL.mem s (wa kb (AtOff i)) = 0#u64 := boot_asZero P _ (asW_at kb i) + have emptyPool : PoolSet bst Set.univ s ⊆ (∅ : Set U64) := by + rintro p ⟨_, o, lo, hi, al, write, nz⟩ + exact (nz (write.symm.trans (boot_asZero P _ ⟨o, lo, hi, al, rfl⟩))).elim + have emptyEntry a raw : ¬ ActiveAsidRoot bst Set.univ s a raw := by + rintro ⟨_, _, _, _, _, _, p, present, _, _, _⟩ + exact emptyPool present + have noPath tag a sh va t : ¬ S1aPath bst Set.univ n s tag a sh va t := by + intro h + induction h with + | native entry _ => exact emptyEntry _ _ entry + | high entry _ _ => exact emptyEntry _ _ entry + | stage2 entry _ => exact emptyEntry _ _ entry + | child _ _ _ _ _ _ ih => exact ih + have noKey : ∀ x ∈ bootOS kb ib nc, ∀ k, s1aTableKey (capA bst s x) ≠ some k := by + intro x hx k + rw [boot_null P x hx] + simp [s1aTableKey] + refine ⟨w0_s1aR2Core P Lv Re bits n, ⟨emptyPool, by simp, ?_, HrOK.empty, ⟨by simp, by simp, by simp⟩⟩, + ⟨?_, ?_, ?_, emptyEntry _⟩, ⟨?_, ?_, ?_, ?_⟩, ⟨?_, ?_, ?_⟩, ?_, + by simp [PtHG], w0_ptObjects P, ?_, w0_eptPlaced P ∅, w0_hvObjects P, ?_, by simp, ?_, ?_, by simp, by simp, w0_rootSlots P ∅ n⟩ + · rintro t ⟨p, hp, _⟩ + exact hp.elim + · intro i _ p eq hn + exact (hn (eq.symm.trans (ash i))).elim + · intro x hx p base eq + rw [boot_null P x hx] at eq + cases eq + · intro i j p hi hj hn eq _ + exact (hn (eq.symm.trans (ash i))).elim + · intro x hx _ _ k hk _ + exact (noKey x hx k hk).elim + · intro x hx _ _ k hk _ _ + exact (noKey x hx k hk).elim + · intro x hx p a eq + rw [boot_null P x hx] at eq + cases eq + · intro x hx p a eq + rw [boot_null P x hx] at eq + cases eq + · intro tag a sh va t h + exact (noPath tag a sh va t h).elim + · intro tag a sh va t h + exact (noPath tag a sh va t h).elim + · intro tag a sh va t h + exact (noPath tag a sh va t h).elim + · intro x hx p m a v eq + rw [boot_null P x hx] at eq + cases eq + · intro x hx p m a eq + rw [boot_null P x hx] at eq + cases eq + · exact HiCap511.ofNoHv (fun x hx p m a eq => by rw [boot_null P x hx] at eq; cases eq) + · ext p + simp only [Set.mem_empty_iff_false, false_iff] + rintro ⟨x, hx, m, a, eq⟩ + rw [boot_null P x hx] at eq + cases eq + · rintro t ⟨p, hp, _⟩ + exact hp.elim + +section w1 +variable {kb ib r now mt sl : U64} {nc : Nat} {uw : U64 → U64} (P : BootLay1 kb ib nc) +include P + +set_option hygiene false in +local notation "S1" => w1S kb ib nc r now mt sl uw +set_option hygiene false in +local notation "OS1" => w1OS kb ib nc + +omit P in +/-- (gen 27) **The `w1Tb` tables are `other 12` objects of `w1H`** (BootW1Items' `w1_pt`). -/ +theorem w1Tb_h {t : U64} (ht : t ∈ w1Tb) : w1H kb ib nc t = some (.other 12) := by + rcases ht with e | e | e | e + · exact w1_pt t (Or.inl e) + · exact w1_pt t (Or.inr (Or.inr (Or.inl e))) + · exact w1_pt t (Or.inr (Or.inr (Or.inr (Or.inl e)))) + · exact w1_pt t (Or.inr (Or.inr (Or.inr (Or.inr e)))) + +omit P in +/-- A cap that is no `PageTable`, `Pml4`, `HighVSpace` or `Ept` cap names no table. -/ +theorem vs_triv (c : capability.Cap) (h1 : ∀ t m a v, c ≠ .PageTable t m a v) (h2 : ∀ t m a, c ≠ .Pml4 t m a) + (h3 : ∀ t m a, c ≠ .HighVSpace t m a) (h4 : ∀ t l m a v, c ≠ .Ept t l m a v) : + (∀ p n, ¬ UnmCap c p n) ∧ ∀ t, NamesV c t → t ∈ w1Pt := by + refine ⟨fun p n h => ?_, fun t h => ?_⟩ + · rcases h with ⟨-, a, v, h⟩ | ⟨-, a, v, h⟩ + · exact h1 _ _ _ _ h + · exact h4 _ _ _ _ _ h + · rcases h with ⟨m, a, v, h⟩ | ⟨m, a, h⟩ | ⟨m, a, h⟩ | ⟨R, m, a, h, -⟩ | ⟨l, m, a, v, h⟩ + · exact absurd h (h1 _ _ _ _) + · exact absurd h (h2 _ _ _) + · exact absurd h (h3 _ _ _) + · exact absurd h (h3 _ _ _) + · exact absurd h (h4 _ _ _ _ _) + +/-- **Every `w1` slot: no unmapped VSpace cap, named tables in `w1Pt`.** -/ +theorem w1_capV {y : U64} (hy : y ∈ OS1) : + (∀ p n, ¬ UnmCap (capA bst S1 y) p n) ∧ ∀ t, NamesV (capA bst S1 y) t → t ∈ w1Pt := by + rcases w1_capS P hy with h | ⟨i, -, -, h⟩ | ⟨-, h⟩ | ⟨-, h⟩ | ⟨-, h⟩ | ⟨-, -, -, -, h⟩ <;> rw [h] + · exact vs_triv _ (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h) (fun _ _ _ h => by cases h) + (fun _ _ _ _ _ h => by cases h) + · exact capOf_vs nc i + · exact capOf_vs nc 2 + · exact capOf_vs nc 3 + · exact vs_triv _ (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h) (fun _ _ _ h => by cases h) + (fun _ _ _ _ _ h => by cases h) + · exact vs_triv _ (fun _ _ _ _ h => by cases h) (fun _ _ _ h => by cases h) (fun _ _ _ h => by cases h) + (fun _ _ _ _ _ h => by cases h) + +/-- A root CNode slot `i` and its cap. -/ +theorem w1_slotCap {i : Nat} (hi : i < 8192) : + bwv (RRb + 32 * i) ∈ OS1 ∧ capA bst S1 (bwv (RRb + 32 * i)) = capOf nc i := + ⟨slot_os hi, cap_root P hi (slotN hi)⟩ + +private theorem w1_root_asid {x ptr asid tag : U64} (hx : x ∈ OS1) + (hc : MappedAsidRoot (capA bst S1 x) ptr asid tag) : asid = 1#u64 := by + rcases w1_capS P hx with h | ⟨i, -, -, h⟩ | ⟨-, h⟩ | ⟨-, h⟩ | ⟨-, h⟩ | ⟨-, -, -, -, h⟩ <;> rw [h] at hc + · rcases hc with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e + · exact capOf_root_asid nc i hc + · exact capOf_root_asid nc 2 hc + · exact capOf_root_asid nc 3 hc + · rcases hc with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e + · rcases hc with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, e⟩ <;> cases e + +private theorem w1_asid_word (i : U64) (hi : i.val < 128) : + bL.mem S1 (wa kb (AtOff i)) = if i.val = 0 then bwv PLb else 0#u64 := by + have hoff := AtOff.val_eq i + rw [Nat.mod_eq_of_lt hi] at hoff + have hk := P.w0.kbw + have hv : (wa kb (AtOff i)).val = kb.val + (AtOff i).val := wadd_val (by omega) + show w1M kb ib nc r now mt sl uw _ = _ + by_cases e : i.val = 0 + · rw [if_pos e, w1M_ks P (o := 772352) (by omega) (by omega)] + unfold ksW1 + rw [if_neg (by omega), if_pos rfl] + · rw [if_neg e, w1M_ksOld P (by omega) hv (by omega) (by omega) (by omega)] + exact boot_asZero P.w0 _ (asW_at kb i) + +private theorem w1_pool_word (o : U64) (ho : o.val < 4096) : + bL.mem S1 (wa (bwv PLb) o) = if o.val = 8 then bwv VSb else 0#u64 := by + have hv := pgv vPL (by norm_num) ho + exact (w1M_root P (o := 397312 + o.val) (by omega) (by omega)).trans (rootW_pl ho _) + +/-- The initial user VSpace is backed by the root CNode's mapped cap at ASID 1. -/ +theorem w1_rootAgreement : RootAgreement bst OS1 Set.univ S1 where + backed asid raw h := by + obtain ⟨i, o, hi, ho, _, ha, pool, hp, ht, hw, hne⟩ := h + change bL.mem S1 (wa kb (AtOff i)) = pool at ht + obtain ⟨_, _, _, _, _, _, hpool⟩ := hp + have htab := w1_tab P (wa kb (AtOff i)) (asW_at kb i) (fun hz => hpool (ht.symm.trans hz)) + have hi0 : i.val = 0 := by + by_contra hne + have hz := w1_asid_word (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P i hi + rw [if_neg hne] at hz + exact hpool (ht.symm.trans hz) + rw [ht.symm.trans htab] at hw + have hm := w1_pool_word (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P o ho + change bL.mem S1 (wa (bwv PLb) o) = raw at hw + rw [hm] at hw + have e8 : o.val = 8 := by + by_contra hn + rw [if_neg hn] at hw + exact hne hw.symm + rw [if_pos e8] at hw + subst raw + have ea : asid = 1#u64 := UScalar.eq_of_val_eq (by rw [ha, hi0, e8]; rfl) + obtain ⟨hy, hc⟩ := w1_slotCap (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P (i := 3) (by omega) + refine ⟨_, hy, ?_⟩ + rw [hc, cap3, ea] + exact Or.inl ⟨rfl, rfl⟩ + agree _ hx _ hy _ _ _ _ _ cx cy := (w1_root_asid P hx cx).trans (w1_root_asid P hy cy).symm + +private theorem w1_active_pool {pool : U64} (hp : pool ∈ PoolSet bst Set.univ S1) : pool = bwv PLb := by + obtain ⟨_, o, h1, h2, h8, hm, hn⟩ := hp + change bL.mem S1 (wa kb o) = pool at hm + exact hm.symm.trans (w1_tab P _ ⟨o, h1, h2, h8, rfl⟩ (fun hz => hn (hm.symm.trans hz))) + +private theorem w1_active_root {pool o : U64} (hp : pool ∈ PoolSet bst Set.univ S1) (ho : o.val < 4096) + (hn : bL.mem S1 (wa pool o) ≠ 0#u64) : bL.mem S1 (wa pool o) = bwv VSb := by + rw [w1_active_pool P hp, w1_pool_word P o ho] at hn ⊢ + by_cases e : o.val = 8 + · rw [if_pos e] + · exact (hn (if_neg e)).elim + +private theorem w1_find : vspace.find_asid_raw bst S1 1#u64 = ok (.Ok (bwv VSb)) := by + have ht : bL.mem S1 (wa kb (AtOff 0#u64)) = bwv PLb := by + rw [w1_asid_word P _ (by simp)] + rfl + have hm : bL.mem S1 (wa (bwv PLb) 8#u64) = bwv VSb := by + rw [w1_pool_word P _ (by simp)] + rfl + have ⟨lo, hi, al⟩ := AtOff.v 0#u64 + have hp : bwv PLb ∈ PoolSet bst Set.univ S1 := ⟨trivial, AtOff 0#u64, lo, hi, al, ht, by decide⟩ + exact ActiveAsidRoot.find (Pp := Set.univ) (s := S1) + ⟨0#u64, 8#u64, by decide, by decide, by decide, rfl, bwv PLb, hp, ht, hm, by decide⟩ + +private theorem w1_noStage2 (Re bits : U64 → Nat) {p : U64} : + ¬ S2Reach bst (PoolSet bst Set.univ S1) Re bits S1 p := by + intro h + induction h with + | @root pool off hp ho _ tag => + have nz : bL.mem S1 (wa pool off) ≠ 0#u64 := by + intro e + rw [e] at tag + exact (show (0#u64 &&& 3#u64 : U64) ≠ 1#u64 by decide) tag + rw [w1_active_root P hp ho nz] at tag + exact (show (bwv VSb &&& 3#u64) ≠ 1#u64 by decide) tag + | step _ _ _ _ _ ih => exact ih + +omit P in +theorem capOf_tail (k : Nat) : capOf nc (16 + nc + k) = (tailC k).1 := by + unfold capOf; rw [slotC_hi (by omega), show 16 + nc + k - (16 + nc) = k by omega] + +/-- **The four `w1Tb` tables are backed by mapped caps** (module docstring). -/ +theorem w1_backed {t : U64} (ht : t ∈ w1Tb) : ∃ y ∈ OS1, MapV (capA bst S1 y) t := by + have h128 := P.w0.nc128 + have hpe : ∀ {n : Nat}, t.val = n → n < 2 ^ 64 → t = bwv n := fun e h => UScalar.eq_of_val_eq (by rw [e, wv h]) + rcases ht with e | e | e | e + · obtain rfl := hpe e (by norm_num) + obtain ⟨hy, hc⟩ := w1_slotCap (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P (i := 3) (by omega) + exact ⟨_, hy, by rw [hc, cap3]; exact Or.inr (Or.inl ⟨1#u64, rfl⟩)⟩ + · obtain rfl := hpe e (by norm_num) + obtain ⟨hy, hc⟩ := w1_slotCap (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P (i := 16 + nc + 0) + (by omega) + exact ⟨_, hy, by rw [hc, capOf_tail]; exact Or.inl ⟨1#u64, 0#u64, rfl⟩⟩ + · obtain rfl := hpe e (by norm_num) + obtain ⟨hy, hc⟩ := w1_slotCap (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P (i := 16 + nc + 1) + (by omega) + exact ⟨_, hy, by rw [hc, capOf_tail]; exact Or.inl ⟨1#u64, 0#u64, rfl⟩⟩ + · obtain rfl := hpe e (by norm_num) + obtain ⟨hy, hc⟩ := w1_slotCap (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P (i := 16 + nc + 2) + (by omega) + exact ⟨_, hy, by rw [hc, capOf_tail]; exact Or.inl ⟨1#u64, bwv 4194304, rfl⟩⟩ + +omit P in +private def W1PtCap (ptr asid va : U64) : Prop := + asid = 1#u64 ∧ ((ptr = bwv L1b ∧ va = 0#u64) ∨ (ptr = bwv L2b ∧ va = 0#u64) ∨ + (ptr = bwv L3b ∧ va = bwv 4194304)) + +omit P in +private theorem capOf_pt_cap (nc i : Nat) {ptr a va : U64} : + capOf nc i = .PageTable ptr true a va → W1PtCap ptr a va := by + capsplit (intro e; cases e <;> (refine ⟨rfl, ?_⟩; first + | exact Or.inl ⟨rfl, rfl⟩ + | exact Or.inr (Or.inl ⟨rfl, rfl⟩) + | exact Or.inr (Or.inr ⟨rfl, rfl⟩))) + +private theorem w1_pt_cap {x ptr a va : U64} (hx : x ∈ OS1) + (hc : capA bst S1 x = .PageTable ptr true a va) : W1PtCap ptr a va := by + rcases w1_capS P hx with h | ⟨i, -, -, h⟩ | ⟨-, h⟩ | ⟨-, h⟩ | ⟨-, h⟩ | ⟨-, -, -, -, h⟩ <;> rw [h] at hc + · cases hc + · exact capOf_pt_cap nc i hc + · exact capOf_pt_cap nc 2 hc + · exact capOf_pt_cap nc 3 hc + · cases hc + · cases hc + +private theorem w1_desc0 (o : U64) (ho : o.val < 4096) : + bL.mem S1 (wa (bwv VSb) o) = if o.val = 0 then bwv (tabE L1b) else 0#u64 := + (w1M_root P (o := 393216 + o.val) (by omega) + (pgv vVS (by norm_num) ho |>.trans (by omega))).trans (rootW_vs ho _) + +private theorem w1_desc1 (o : U64) (ho : o.val < 4096) : + bL.mem S1 (wa (bwv L1b) o) = if o.val = 0 then bwv (tabE L2b) else 0#u64 := + (w1M_root P (o := 413696 + o.val) (by omega) + (pgv vL1 (by norm_num) ho |>.trans (by omega))).trans (rootW_l1 ho _) + +private theorem w1_desc2 (o : U64) (ho : o.val < 4096) : + bL.mem S1 (wa (bwv L2b) o) = if o.val = 16 then bwv (tabE L3b) else 0#u64 := + (w1M_root P (o := 417792 + o.val) (by omega) + (pgv vL2 (by norm_num) ho |>.trans (by omega))).trans (rootW_l2 ho _) + +omit P in +private def W1Edge (ptr b : U64) : Prop := + (ptr = bwv L1b ∧ b = bwv VSb) ∨ (ptr = bwv L2b ∧ b = bwv L1b) ∨ + (ptr = bwv L3b ∧ b = wa (bwv L2b) 16#u64) + +private theorem w1_edge {Lv : U64 → Nat} (hlv : ∀ p ∈ w1Tb, Lv p = w1Lv p) + {p o : U64} (hp : p ∈ w1Tb) (hl : Lv p < 3) (ho : o.val < 4096) + (h3 : (bL.mem S1 (wa p o) &&& 3#u64) = 3#u64) : + W1Edge (wa (bL.mem S1 (wa p o) &&& vspace.ADDR_MASK) layout.PPTR_BASE) (wa p o) := by + rw [hlv p hp] at hl + have hpe {k : Nat} (e : p.val = k) (h : k < 2 ^ 64) : p = bwv k := + UScalar.eq_of_val_eq (by rw [e, wv h]) + rcases hp with e | e | e | e + · obtain rfl := hpe e (by norm_num) + rw [w1_desc0 P o ho] at h3 ⊢ + by_cases e0 : o.val = 0 + · have eo : o = 0#u64 := UScalar.eq_of_val_eq e0 + rw [if_pos e0, tabE1, eo] + exact Or.inl ⟨rfl, rfl⟩ + · rw [if_neg e0] at h3 + exact (and3z h3).elim + · obtain rfl := hpe e (by norm_num) + rw [w1_desc1 P o ho] at h3 ⊢ + by_cases e0 : o.val = 0 + · have eo : o = 0#u64 := UScalar.eq_of_val_eq e0 + rw [if_pos e0, tabE2, eo] + exact Or.inr (Or.inl ⟨rfl, rfl⟩) + · rw [if_neg e0] at h3 + exact (and3z h3).elim + · obtain rfl := hpe e (by norm_num) + rw [w1_desc2 P o ho] at h3 ⊢ + by_cases e16 : o.val = 16 + · have eo : o = 16#u64 := UScalar.eq_of_val_eq e16 + rw [if_pos e16, tabE3, eo] + exact Or.inr (Or.inr ⟨rfl, rfl⟩) + · rw [if_neg e16] at h3 + exact (and3z h3).elim + · obtain rfl := hpe e (by norm_num) + rw [lv_l3] at hl + omega + +private theorem w1_reach {Lv : U64 → Nat} (hlv : ∀ p ∈ w1Tb, Lv p = w1Lv p) {p : U64} + (h : VsReach bst (PoolSet bst Set.univ S1) ∅ Lv S1 p) : p ∈ w1Tb := by + induction h with + | hr hp => exact (Set.notMem_empty _ hp).elim + | root0 hp ho _ hn _ => + rw [w1_active_root P hp ho hn] + exact Or.inl vVS + | @root2 pool off hp ho _ h2 => + have hn : bL.mem S1 (wa pool off) ≠ 0#u64 := by + intro e + rw [e] at h2 + exact (show (0#u64 &&& 3#u64 : U64) ≠ 2#u64 by decide) h2 + rw [w1_active_root P hp ho hn] at h2 + exact ((show (bwv VSb &&& 3#u64) ≠ 2#u64 by decide) h2).elim + | step _ hl ho _ h3 ih => + rcases w1_edge P hlv ih hl ho h3 with ⟨e, -⟩ | ⟨e, -⟩ | ⟨e, -⟩ + · rw [e]; exact Or.inr (Or.inl vL1) + · rw [e]; exact Or.inr (Or.inr (Or.inl vL2)) + · rw [e]; exact Or.inr (Or.inr (Or.inr vL3)) + +omit P in +private theorem w1_loop_continue {ptr va table shift level slot word next level' : U64} + (hlevel : level < 3#u64) (ha : vspace.entry_addr table va shift = ok slot) + (hm : bL.mem S1 slot = word) (ht : vspace.is_table word shift = ok true) + (hp : vspace.table_of word = ok next) (hne : next ≠ ptr) (hs : level + 1#u64 = ok level') : + vspace.unmap_page_table_loop bst S1 va ptr table shift level = + vspace.unmap_page_table_loop bst S1 va ptr next (core.num.U64.wrapping_sub shift 9#u64) level' := by + have step : vspace.unmap_page_table_loop.body bst S1 va ptr table shift level = + ok (.cont (next, core.num.U64.wrapping_sub shift 9#u64, level')) := by + unfold vspace.unmap_page_table_loop.body + simp only [if_pos hlevel, ha, hm, ht, hp, hs, if_neg hne, lift, bind_ok, bL.read_eq, if_true] + unfold vspace.unmap_page_table_loop + conv_lhs => + rw [loop] + dsimp only + rw [step, bind_ok] + +omit P in +private theorem w1_loop_done {ptr va table shift level slot word : U64} + (hlevel : level < 3#u64) (ha : vspace.entry_addr table va shift = ok slot) + (hm : bL.mem S1 slot = word) (ht : vspace.is_table word shift = ok true) + (hp : vspace.table_of word = ok ptr) : + vspace.unmap_page_table_loop bst S1 va ptr table shift level = ok (some slot) := by + have step : vspace.unmap_page_table_loop.body bst S1 va ptr table shift level = + ok (.done (some slot)) := by + unfold vspace.unmap_page_table_loop.body + simp only [if_pos hlevel, ha, hm, ht, hp, lift, bind_ok, bL.read_eq, if_true, if_pos rfl] + unfold vspace.unmap_page_table_loop + rw [loop] + dsimp only + rw [step, bind_ok] + +omit P in +private theorem boot_is_table {e sh : U64} (hs : sh > vspace.PAGE_BITS) (he : (e &&& 3#u64) = 3#u64) : + vspace.is_table e sh = ok true := by + unfold vspace.is_table + rw [if_pos hs, 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 by decide, he] + simp + +omit P in +private theorem boot_entry {table va shift index : U64} (hs : shift &&& 63#u64 = shift) + (h : (va >>> shift : Result U64) = ok index) : + vspace.entry_addr table va shift = ok (wa table (core.num.U64.wrapping_mul (index &&& 511#u64) 8#u64)) := by + unfold vspace.entry_addr + simp only [hs, h, lift, bind_ok] + +set_option maxHeartbeats 2000000 in +private theorem w1_walk {ptr a va b : U64} (hc : W1PtCap ptr a va) (he : W1Edge ptr b) : + vspace.unmap_page_table_loop bst S1 va ptr (bwv VSb) vspace.TOP_LEVEL_SHIFT 0#u64 = ok (some b) := by + have h0 : bL.mem S1 (bwv VSb) = bwv (tabE L1b) := + w1_desc0 (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P 0#u64 (by simp) + have h1 : bL.mem S1 (bwv L1b) = bwv (tabE L2b) := + w1_desc1 (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P 0#u64 (by simp) + have h2 : bL.mem S1 (wa (bwv L2b) 16#u64) = bwv (tabE L3b) := by + rw [w1_desc2 P _ (by simp)] + rfl + have t0 := boot_is_table (e := bwv (tabE L1b)) (sh := 39#u64) (by unfold vspace.PAGE_BITS; decide) rfl + have t1 := boot_is_table (e := bwv (tabE L2b)) (sh := 30#u64) (by unfold vspace.PAGE_BITS; decide) rfl + have t2 := boot_is_table (e := bwv (tabE L3b)) (sh := 21#u64) (by unfold vspace.PAGE_BITS; decide) rfl + have p0 : vspace.table_of (bwv (tabE L1b)) = ok (bwv L1b) := by + simp only [vspace.table_of, layout.pptr, lift, bind_ok, tabE1] + have p1 : vspace.table_of (bwv (tabE L2b)) = ok (bwv L2b) := by + simp only [vspace.table_of, layout.pptr, lift, bind_ok, tabE2] + have p2 : vspace.table_of (bwv (tabE L3b)) = ok (bwv L3b) := by + simp only [vspace.table_of, layout.pptr, lift, bind_ok, tabE3] + have a0 : vspace.entry_addr (bwv VSb) 0#u64 39#u64 = ok (bwv VSb) := + boot_entry (index := 0#u64) rfl rfl + have a1 : vspace.entry_addr (bwv L1b) 0#u64 30#u64 = ok (bwv L1b) := + boot_entry (index := 0#u64) rfl rfl + have a0' : vspace.entry_addr (bwv VSb) (bwv 4194304) 39#u64 = ok (bwv VSb) := + boot_entry (index := 0#u64) rfl rfl + have a1' : vspace.entry_addr (bwv L1b) (bwv 4194304) 30#u64 = ok (bwv L1b) := + boot_entry (index := 0#u64) rfl rfl + have a2 : vspace.entry_addr (bwv L2b) (bwv 4194304) 21#u64 = ok (wa (bwv L2b) 16#u64) := + boot_entry (index := 2#u64) rfl rfl + rcases hc with ⟨_, ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, rfl⟩⟩ <;> + rcases he with ⟨hp, rfl⟩ | ⟨hp, rfl⟩ | ⟨hp, rfl⟩ <;> + try (exact ((by decide : _ ≠ _) hp).elim) + all_goals rw [show vspace.TOP_LEVEL_SHIFT = 39#u64 by unfold vspace.TOP_LEVEL_SHIFT; rfl] + · exact w1_loop_done (by decide) a0 h0 t0 p0 + · rw [w1_loop_continue (ptr := bwv L2b) (level := 0#u64) (level' := 1#u64) + (by decide) a0 h0 t0 p0 (by decide) rfl] + exact w1_loop_done (by decide) a1 h1 t1 p1 + · rw [w1_loop_continue (ptr := bwv L3b) (level := 0#u64) (level' := 1#u64) + (by decide) a0' h0 t0 p0 (by decide) rfl] + rw [show core.num.U64.wrapping_sub 39#u64 9#u64 = 30#u64 by rfl] + rw [w1_loop_continue (ptr := bwv L3b) (level := 1#u64) (level' := 2#u64) + (by decide) a1' h1 t1 p1 (by decide) rfl] + exact w1_loop_done (by decide) a2 h2 t2 p2 + +/-- At the user boot witness each mapped PageTable agrees with the unique active walk. -/ +theorem w1_ptFndAll (Lv Re bits : U64 → Nat) (hlv : ∀ t ∈ w1Tb, Lv t = w1Lv t) (n : U64) : + PtFndAll bst OS1 Set.univ Lv Re bits n S1 := by + intro x hx ptr a va hcap + have hc := w1_pt_cap P hx hcap + refine ⟨⟨by simp, ?_⟩, ?_, ?_⟩ + · intro pool hp o ho h8 hn + rw [w1_active_root P hp ho hn] + have hne : bwv VSb ≠ ptr := by + rcases hc.2 with ⟨rfl, -⟩ | ⟨rfl, -⟩ | ⟨rfl, -⟩ <;> decide + exact ⟨fun _ => hne, fun h => (h rfl).elim⟩ + · rintro b ⟨p, o, h, -⟩ + exact (w1_noStage2 P Re bits h).elim + · rintro b ⟨p, o, h, hl, ho, _, rfl, h3, et⟩ + have he := w1_edge P hlv (w1_reach P hlv h) hl ho h3 + rw [et] at he + refine ⟨bwv VSb, bwv VSb, vspace.TOP_LEVEL_SHIFT, 0#u64, ?_, by decide, Or.inr ⟨by decide, rfl, rfl, rfl⟩, + w1_walk P hc he⟩ + rw [hc.1] + exact w1_find P + +/-- **`VsLk` at `w1`** (module docstring; no kernel table, no Stage-2 object). -/ +theorem w1_vsLk (Re bits : U64 → Nat) : + VsLk bst (w1H kb ib nc) OS1 Set.univ w1Tb ∅ ∅ w1Lv Re bits S1 where + bk1 t hr ht _ := w1_backed P ht + bk2 t _ ht := absurd ht (by simp) + kt t ht := absurd ht (by simp) + ex x hx _ _ p n hu := absurd hu ((w1_capV P hx).1 p n) + zr x hx p n hu := absurd hu ((w1_capV P hx).1 p n) + vh := ⟨fun x hx p n hu => absurd hu ((w1_capV P hx).1 p n), fun t _ ht _ => Or.inl (w1Tb_h ht), + fun t _ ht => absurd ht (by simp)⟩ + +/-- **`VsLk` at `w1` with the kernel table `kt`** (module docstring). -/ +theorem w1K_vsLk (Re bits : U64 → Nat) : + VsLk bst (KtH (w1H kb ib nc) {bwv KTb}) OS1 Set.univ (insert (bwv KTb) w1Tb) ∅ {bwv KTb} + (Function.update w1Lv (bwv KTb) 1) Re bits S1 where + bk1 t hr ht hk := by + rcases ht with rfl | ht + · exact absurd rfl hk + · exact w1_backed P ht + bk2 t _ ht := absurd ht (by simp) + kt t ht y hy hn := by + have := (w1_capV P hy).2 t hn + rw [Set.mem_singleton_iff.1 ht] at this + rcases this with e | e | e | e | e <;> rw [vKT] at e <;> norm_num at e + ex x hx _ _ p n hu := absurd hu ((w1_capV P hx).1 p n) + zr x hx p n hu := absurd hu ((w1_capV P hx).1 p n) + vh := ⟨fun x hx p n hu => absurd hu ((w1_capV P hx).1 p n), fun t _ ht hk => by + rcases ht with rfl | ht + · exact absurd rfl hk + · exact Or.inl ((Heap.add_of_not (N := (· ∈ ({bwv KTb} : Set U64))) (kd := .other 12) hk).trans (w1Tb_h ht)), + fun t _ ht => absurd ht (by simp)⟩ + +/-- The user boot witness satisfies R2, including its capless kernel TTBR1 table. -/ +theorem w1K_s1aR2Core (Re bits : U64 → Nat) (n : U64) : + S1aR2Core bst (KtH (w1H kb ib nc) {bwv KTb}) OS1 Set.univ (insert (bwv KTb) w1Tb) ∅ ∅ {bwv KTb} + (Function.update w1Lv (bwv KTb) 1) Re bits n S1 := by + have hl p (hp : p ∈ w1Tb) : Function.update w1Lv (bwv KTb) 1 p = w1Lv p := by + refine Function.update_of_ne (fun e => ?_) _ _ + rw [e] at hp + rcases hp with e | e | e | e <;> rw [vKT] at e <;> norm_num at e + refine ⟨w1K_vsLk P Re bits, w1_ptFndAll P _ Re bits hl n, w1_rootAgreement P, (w1K_vs P).1.toR, ?_, + fun _ h => (Set.notMem_empty _ h).elim⟩ + refine ⟨fun pool hp o ho h8 hn => ?_, fun _ h => (Set.notMem_empty _ h).elim, + fun _ h => (Set.notMem_empty _ h).elim⟩ + rw [w1_active_root P hp ho hn] + exact Or.inl ⟨rfl, Set.notMem_empty _⟩ + +/-- The kernel table in the w1 B2 witness shares the same PageTable and Ept placement. -/ +theorem w1K_tableObjects (Pt : Set U64) : + PtObjects bst (KtH (w1H kb ib nc) {bwv KTb}) OS1 S1 ∧ + EptPlaced bst (KtH (w1H kb ib nc) {bwv KTb}) OS1 Pt S1 := by + constructor + · intro y hy t m a v cap + have orig := w1_ptObjects P y hy t m a v cap + by_cases member : t ∈ ({bwv KTb} : Set U64) + · exact KtH.kt _ member + · exact (Heap.add_of_not (kd := .other 12) member).trans orig + · intro y hy t l m a v cap + have none := w1_eptPlaced P ∅ y hy t l m a v cap + exact (Set.notMem_empty _ (none.2 ⟨t, Set.mem_singleton t, Or.inl rfl⟩)).elim + +theorem w1K_hvObjects : HvObjects bst (KtH (w1H kb ib nc) {bwv KTb}) OS1 S1 := + fun _ hx p m a cap => ((w1_ptCapK P hx).2 p m a cap).elim + +omit P in +private theorem capOf_poolExact (i : Nat) {p base : U64} : + capOf nc i = .AsidPool p base → p = bwv PLb ∧ base = 0#u64 := by + capsplit (intro e; cases e <;> exact ⟨rfl, rfl⟩) + +private theorem w1_poolExact {x p base : U64} (hx : x ∈ OS1) + (cap : capA bst S1 x = .AsidPool p base) : p = bwv PLb ∧ base = 0#u64 := by + rcases w1_capS P hx with e | ⟨i, _, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, _, _, e⟩ <;> rw [e] at cap + · cases cap + · exact capOf_poolExact i cap + · exact capOf_poolExact 2 cap + · exact capOf_poolExact 3 cap + · cases cap + · cases cap + +omit P in +private theorem capOf_nativeExact (i : Nat) {p a : U64} {m : Bool} : + capOf nc i = .Pml4 p m a → p = bwv VSb ∧ m = true ∧ a = 1#u64 := by + capsplit (intro e; cases e <;> exact ⟨rfl, rfl, rfl⟩) + +private theorem w1_nativeExact {x p a : U64} {m : Bool} (hx : x ∈ OS1) + (cap : capA bst S1 x = .Pml4 p m a) : p = bwv VSb ∧ m = true ∧ a = 1#u64 := by + rcases w1_capS P hx with e | ⟨i, _, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, _, _, e⟩ <;> rw [e] at cap + · cases cap + · exact capOf_nativeExact i cap + · exact capOf_nativeExact 2 cap + · exact capOf_nativeExact 3 cap + · cases cap + · cases cap + +omit P in +private def W1TableRef (key : Nat × U64) (ref : Option (U64 × U64)) : Prop := + (key = (1, bwv VSb) ∨ key = (0, bwv L1b) ∨ key = (0, bwv L2b)) ∧ ref = some (1#u64, 0#u64) ∨ + key = (0, bwv L3b) ∧ ref = some (1#u64, bwv 4194304) + +omit P in +private theorem capOf_tableRef (i : Nat) (k : Nat × U64) + (key : s1aTableKey (capOf nc i) = some k) : W1TableRef k (s1aTableRef (capOf nc i)) := by + revert key + capsplit (intro e; simp [fixC, tailC, frC, s1aTableKey] at e <;> + (rw [← e]; first + | exact Or.inl ⟨Or.inl rfl, rfl⟩ + | exact Or.inl ⟨Or.inr (Or.inl rfl), rfl⟩ + | exact Or.inl ⟨Or.inr (Or.inr rfl), rfl⟩ + | exact Or.inr ⟨rfl, rfl⟩)) + +private theorem w1_tableRef {x : U64} (hx : x ∈ OS1) {k : Nat × U64} + (key : s1aTableKey (capA bst S1 x) = some k) : W1TableRef k (s1aTableRef (capA bst S1 x)) := by + rcases w1_capS P hx with e | ⟨i, _, _, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, e⟩ | ⟨_, _, _, _, e⟩ <;> rw [e] at key ⊢ + · cases key + · exact capOf_tableRef i k key + · exact capOf_tableRef 2 k key + · exact capOf_tableRef 3 k key + · cases key + · cases key + +private theorem w1_asidIndex {i p : U64} (bound : i.val < 128) (nz : p ≠ 0#u64) + (eq : bL.mem S1 (wa kb (AtOff i)) = p) : i = 0#u64 ∧ p = bwv PLb := by + rw [w1_asid_word P i bound] at eq + by_cases zero : i.val = 0 + · rw [if_pos zero] at eq + exact ⟨UScalar.eq_of_val_eq zero, eq.symm⟩ + · exact (nz (eq.symm.trans (if_neg zero))).elim + +private theorem w1_entryExact {a raw : U64} (h : ActiveAsidRoot bst Set.univ S1 a raw) : + a = 1#u64 ∧ raw = bwv VSb := by + obtain ⟨x, hx, root⟩ := (w1_rootAgreement P).backed a raw h + have id := w1_root_asid P hx root + obtain ⟨_, o, _, ho, _, _, pool, active, _, word, nz⟩ := h + exact ⟨id, word.symm.trans (w1_active_root P active ho (fun e => nz (word.symm.trans e)))⟩ + +omit P in +private def W1Path (shift vaBase : Nat) (ptr : U64) : Prop := + (shift = 39 ∧ vaBase = 0 ∧ ptr = bwv VSb) ∨ + (shift = 30 ∧ vaBase = 0 ∧ ptr = bwv L1b) ∨ + (shift = 21 ∧ vaBase = 0 ∧ ptr = bwv L2b) ∨ + (shift = 12 ∧ vaBase = 4194304 ∧ ptr = bwv L3b) + +private theorem w1_path {tag a t n : U64} {shift vaBase : Nat} (path : S1aPath bst Set.univ n S1 tag a shift vaBase t) : + tag = 0#u64 ∧ a = 1#u64 ∧ W1Path shift vaBase t := by + induction path with + | native entry _ => + obtain ⟨a, raw⟩ := w1_entryExact P entry + exact ⟨rfl, a, Or.inl ⟨rfl, rfl, raw⟩⟩ + | high entry tag _ => + rw [(w1_entryExact P entry).2] at tag + exact ((by decide : (bwv VSb &&& 3#u64) ≠ 2#u64) tag).elim + | stage2 entry tag => + rw [(w1_entryExact P entry).2] at tag + exact ((by decide : (bwv VSb &&& 3#u64) ≠ 1#u64) tag).elim + | @child tag a t o shift vaBase _ level width _ _ descriptor ih => + obtain ⟨rfl, rfl, old⟩ := ih + rcases old with ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ + · have ho : o.val < 4096 := by + simp [s1aTableWidth, s1aTopShift] at width + omega + change (bL.mem S1 (wa (bwv VSb) o) &&& 3#u64) = 3#u64 at descriptor + rw [w1_desc0 P o ho] at descriptor ⊢ + by_cases e : o.val = 0 + · rw [if_pos e, tabE1, e] + exact ⟨rfl, rfl, Or.inr (Or.inl ⟨rfl, rfl, rfl⟩)⟩ + · rw [if_neg e] at descriptor + exact (and3z descriptor).elim + · have ho : o.val < 4096 := by simpa [s1aTableWidth, s1aTopShift] using width + change (bL.mem S1 (wa (bwv L1b) o) &&& 3#u64) = 3#u64 at descriptor + rw [w1_desc1 P o ho] at descriptor ⊢ + by_cases e : o.val = 0 + · rw [if_pos e, tabE2, e] + exact ⟨rfl, rfl, Or.inr (Or.inr (Or.inl ⟨rfl, rfl, rfl⟩))⟩ + · rw [if_neg e] at descriptor + exact (and3z descriptor).elim + · have ho : o.val < 4096 := by simpa [s1aTableWidth, s1aTopShift] using width + change (bL.mem S1 (wa (bwv L2b) o) &&& 3#u64) = 3#u64 at descriptor + rw [w1_desc2 P o ho] at descriptor ⊢ + by_cases e : o.val = 16 + · rw [if_pos e, tabE3, e] + exact ⟨rfl, rfl, Or.inr (Or.inr (Or.inr ⟨rfl, rfl, rfl⟩))⟩ + · rw [if_neg e] at descriptor + exact (and3z descriptor).elim + · omega + +private theorem w1_leafWord {o : U64} (ho : o.val < 4096) : + bL.mem S1 (wa (bwv L3b) o) = l3W o.val := by + have addr := pgv vL3 (by norm_num) ho + rw [show bL.mem S1 (wa (bwv L3b) o) = w1M kb ib nc r now mt sl uw (wa (bwv L3b) o) from rfl] + rw [w1M_root P (o := 421888 + o.val) (by omega) (addr.trans (by omega))] + unfold rootW + 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_pos (by omega), Nat.add_sub_cancel_left] + +set_option maxRecDepth 20000 in +set_option maxHeartbeats 4000000 in +private theorem w1_frameLeaf (j : Nat) (bound : j < 35) : + let p := s1aLeafTarget (l3W (8 * j)) 12 + ∃ x ∈ OS1, capA bst S1 x = .Frame p .Small 3#u64 false true false 1#u64 + (bwv (4194304 + j * 4096)) ∧ p ≠ bwv KTb := by + have ncBound := P.w0.nc128 + have slot i (hi : i < 8192) := w1_slotCap (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P hi + have atFixed i (hi : i < 16) : + ∃ x ∈ OS1, capA bst S1 x = (fixC i).1 := by + obtain ⟨hx, hc⟩ := slot i (by omega) + exact ⟨_, hx, hc.trans (capOf_lo hi)⟩ + have atTail k (hk : k < 37) : + ∃ x ∈ OS1, capA bst S1 x = (tailC k).1 := by + obtain ⟨hx, hc⟩ := slot (16 + nc + k) (by omega) + exact ⟨_, hx, hc.trans (capOf_tail k)⟩ + have emit {i} (haveCap : ∃ x ∈ OS1, capA bst S1 x = i) + (eq : i = .Frame (s1aLeafTarget (l3W (8 * j)) 12) .Small 3#u64 false true false 1#u64 + (bwv (4194304 + j * 4096))) (off : s1aLeafTarget (l3W (8 * j)) 12 ≠ bwv KTb) : + ∃ x ∈ OS1, capA bst S1 x = .Frame (s1aLeafTarget (l3W (8 * j)) 12) .Small 3#u64 false true false 1#u64 + (bwv (4194304 + j * 4096)) ∧ s1aLeafTarget (l3W (8 * j)) 12 ≠ bwv KTb := by + obtain ⟨x, hx, cap⟩ := haveCap + exact ⟨x, hx, cap.trans eq, off⟩ + unfold s1aLeafTarget vspace.ADDR_MASK layout.PPTR_BASE at emit ⊢ + cases j with + | zero => exact emit (atTail 35 (by decide)) (by rfl) (by decide) + | succ j => + cases j with + | zero => exact emit (atFixed 10 (by decide)) (by rfl) (by decide) + | succ j => + cases j with + | zero => exact emit (atFixed 9 (by decide)) (by rfl) (by decide) + | succ j => + have hj : j < 32 := by omega + apply emit (atTail (3 + j) (by omega)) + · interval_cases j <;> rfl + · interval_cases j <;> decide + + +set_option maxHeartbeats 4000000 in +private theorem w1_pathBacking (n : U64) (Re bits : U64 → Nat) : + S1aPathBacking bst (KtH (w1H kb ib nc) {bwv KTb}) OS1 Set.univ (insert (bwv KTb) w1Tb) ∅ + (Function.update w1Lv (bwv KTb) 1) Re bits n S1 where + tables tag a sh va t path := by + obtain ⟨rfl, rfl, h⟩ := w1_path P path + rcases h with ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ + · exact ⟨Or.inr (Or.inl vVS), by decide⟩ + · exact ⟨Or.inr (Or.inr (Or.inl vL1)), by decide⟩ + · exact ⟨Or.inr (Or.inr (Or.inr (Or.inl vL2))), by decide⟩ + · exact ⟨Or.inr (Or.inr (Or.inr (Or.inr vL3))), by decide⟩ + children tag a sh va t path child := by + obtain ⟨rfl, rfl, h⟩ := w1_path P path + rcases h with ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ + · simp [s1aTopShift] at child + · obtain ⟨member, cap⟩ := w1_slotCap P (i := 16 + nc + 0) (by have := P.w0.nc128; omega) + exact ⟨_, member, 0#u64, cap.trans (capOf_tail 0), rfl⟩ + · obtain ⟨member, cap⟩ := w1_slotCap P (i := 16 + nc + 1) (by have := P.w0.nc128; omega) + exact ⟨_, member, 0#u64, cap.trans (capOf_tail 1), rfl⟩ + · obtain ⟨member, cap⟩ := w1_slotCap P (i := 16 + nc + 2) (by have := P.w0.nc128; omega) + exact ⟨_, member, bwv 4194304, cap.trans (capOf_tail 2), rfl⟩ + leaves tag a sh vaBase t path o width al range valid := by + obtain ⟨rfl, rfl, h⟩ := w1_path P path + rcases h with ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ | ⟨rfl, rfl, rfl⟩ + · have ho : o.val < 4096 := by simp [s1aTableWidth, s1aTopShift] at width; omega + rw [w1_desc0 P o ho] at valid + split at valid + · exact ((by unfold s1aLeafValid; decide : ¬ s1aLeafValid (bwv (tabE L1b)) 39) valid).elim + · exact ((by unfold s1aLeafValid; decide : ¬ s1aLeafValid 0#u64 39) valid).elim + · have ho : o.val < 4096 := by simpa [s1aTableWidth, s1aTopShift] using width + rw [w1_desc1 P o ho] at valid + split at valid + · exact ((by unfold s1aLeafValid; decide : ¬ s1aLeafValid (bwv (tabE L2b)) 30) valid).elim + · exact ((by unfold s1aLeafValid; decide : ¬ s1aLeafValid 0#u64 30) valid).elim + · have ho : o.val < 4096 := by simpa [s1aTableWidth, s1aTopShift] using width + rw [w1_desc2 P o ho] at valid + split at valid + · exact ((by unfold s1aLeafValid; decide : ¬ s1aLeafValid (bwv (tabE L3b)) 21) valid).elim + · exact ((by unfold s1aLeafValid; decide : ¬ s1aLeafValid 0#u64 21) valid).elim + · have ho : o.val < 4096 := by simpa [s1aTableWidth, s1aTopShift] using width + have word := w1_leafWord (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P ho + have small : o.val < 280 := by + by_contra long + have edge : 280 ≤ o.val := Nat.le_of_not_gt long + have empty : l3W o.val = 0#u64 := by + unfold l3W + rw [if_neg (by omega), if_neg (by omega), if_neg (by omega), if_neg (by omega)] + rw [word, empty] at valid + exact (by unfold s1aLeafValid; decide : ¬ s1aLeafValid 0#u64 12) valid + let j := o.val / 8 + have val : o.val = 8 * j := by dsimp [j]; omega + have bound : j < 35 := by omega + have equal : bL.mem S1 (wa (bwv L3b) o) = l3W (8 * j) := by rw [word, val] + simp only [equal] + obtain ⟨x, hx, cap, off⟩ := + w1_frameLeaf (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P j bound + have addr : s1aCapAddress 0#u64 n (bwv (4194304 + j * 4096)) = + 4194304 + o.val / 8 * 2 ^ 12 := by + unfold s1aCapAddress + 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 (Heap.add_of_not (N := (· ∈ ({bwv KTb} : Set U64))) (kd := .other 12) + (fun h => off (Set.mem_singleton_iff.1 h))).trans old + +/-- Boot's native root has a single lower-half edge and no extended root caps. -/ +theorem w1_rootSlots (Kt : Set U64) (n : U64) : S1aRootSlots bst OS1 Kt n S1 := by + constructor + · intro x hx p m a cap o ho _ + obtain ⟨rfl, _, _⟩ := w1_nativeExact P hx cap + rw [w1_desc0 P o ho.2, ite_eq_right (by omega : o.val ≠ 0)] + · intro x hx p m a v cap + have absent := w1_eptPlaced P ∅ x hx p 0#u64 m a v cap + exact (Set.notMem_empty _ (absent.2 ⟨p, Set.mem_singleton p, Or.inl rfl⟩)).elim + · intro x hx p m a cap + exact ((w1_ptCapK P hx).2 p m a cap).elim + · intro x hx p m a cap + exact ((w1_ptCapK P hx).2 p m a cap).elim + +set_option maxRecDepth 20000 in +set_option maxHeartbeats 4000000 in +/-- The complete R2 contract and kernel-table separation at the user boot state. -/ +theorem w1K_s1aR2 (Re bits : U64 → Nat) (n : U64) : + S1aR2 bst (KtH (w1H kb ib nc) {bwv KTb}) OS1 (w1Pt ∪ {bwv KTb}) Set.univ + (insert (bwv KTb) w1Tb) ∅ ∅ {bwv KTb} (Function.update w1Lv (bwv KTb) 1) Re bits n S1 ∧ + S1aKtUt bst OS1 {bwv KTb} S1 := by + refine ⟨?_, (w1K_out P).s1aKtUt⟩ + have highAbsent : ∀ x ∈ OS1, ∀ p m a, capA bst S1 x ≠ .HighVSpace p m a := + fun _ hx p m a eq => (w1_ptCapK P hx).2 p m a eq + have highEmpty : HvRt bst OS1 S1 = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + rintro p ⟨x, hx, m, a, eq⟩ + exact highAbsent x hx p m a eq + have poolPlace : bwv PLb ∈ w1Pt ∪ ({bwv KTb} : Set U64) := Or.inl (Or.inr (Or.inl vPL)) + have poolExact : KtH (w1H kb ib nc) {bwv KTb} (bwv PLb) = some (.other 12) := + (Heap.add_of_not (N := (· ∈ ({bwv KTb} : Set U64))) (kd := .other 12) + (fun h => (by decide : bwv PLb ≠ bwv KTb) (Set.mem_singleton_iff.1 h))).trans (w1_pool (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P).obj + have ⟨pt, ept⟩ := w1K_tableObjects (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) + P (w1Pt ∪ {bwv KTb}) + refine ⟨w1K_s1aR2Core P Re bits n, ⟨fun p hp => ?_, (w1K_vs (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P).2, + ?_, HrOK.empty, + ⟨by simp, by simp, by simp⟩⟩, ⟨?_, ?_, ?_, ?_⟩, ⟨?_, ?_, ?_, ?_⟩, w1_pathBacking P n Re bits, + ?_, (w1K_bundle (r := r) (now := now) (mt := mt) (sl := sl) (uw := uw) P).2.2.2.1.ph, + pt, ?_, ept, w1K_hvObjects P, HiCap511.ofNoHv highAbsent, by simp, + highEmpty.symm, ?_, ?_, ?_, w1_rootSlots P {bwv KTb} n⟩ + · rwa [w1_active_pool P hp] + · rintro t ⟨p, hp, _⟩ + exact hp.elim + · intro i bound p word nz + obtain ⟨rfl, rfl⟩ := w1_asidIndex P bound nz word + obtain ⟨member, cap⟩ := w1_slotCap P (i := 6) (by decide) + exact ⟨trivial, poolPlace, poolExact, _, member, _, cap.trans (capOf_lo (by decide)), rfl⟩ + · intro x hx p base eq + obtain ⟨rfl, rfl⟩ := w1_poolExact P hx eq + refine ⟨0#u64, by decide, rfl, by decide, ?_⟩ + change bL.mem S1 (wa kb (AtOff 0#u64)) = bwv PLb + rw [w1_asid_word P 0#u64 (by decide), ite_eq_left (show (0#u64 : U64).val = 0 from rfl)] + · intro i j p hi hj nz left right + exact (w1_asidIndex P hi nz left).1.trans (w1_asidIndex P hj nz right).1.symm + · intro raw entry + exact (by decide : 0#u64 ≠ 1#u64) (w1_entryExact P entry).1 + · intro x hx y hy key kx ky + have left := w1_tableRef P hx kx + have right := w1_tableRef P hy ky + rcases left with ⟨kl, a⟩ | ⟨kl, a⟩ <;> rcases right with ⟨kr, b⟩ | ⟨kr, b⟩ + · exact a.trans b.symm + · rcases kl with rfl | rfl | rfl <;> exact ((by decide : _ ≠ _) kr).elim + · rcases kr with rfl | rfl | rfl <;> exact ((by decide : _ ≠ _) kl).elim + · exact a.trans b.symm + · intro x hx y hy k kx ky unm + rcases w1_tableRef P hx kx with ⟨_, eq⟩ | ⟨_, eq⟩ <;> rw [unm] at eq <;> cases eq + · intro x hx p a eq + exact (Bool.false_ne_true (w1_nativeExact P hx eq).2.1).elim + · intro x hx p a eq + exact (highAbsent x hx p false a eq).elim + · intro x hx p m a v cap + exact Or.inl ((w1_ptCapK P hx).1 p m a v cap) + · intro x hx p m a cap + obtain ⟨rfl, _, _⟩ := w1_nativeExact P hx cap + exact ⟨(Heap.add_of_not (N := (· ∈ ({bwv KTb} : Set U64))) (kd := .other 12) + (fun h => (by decide : bwv VSb ≠ bwv KTb) (Set.mem_singleton_iff.1 h))).trans (w1Tb_h (Or.inl vVS)), + Or.inl (Or.inl vVS)⟩ + · rintro t ⟨p, hp, _⟩ + exact hp.elim + · exact ⟨fun p hp => Or.inl hp, KtH.kt⟩ + · intro t ht _ o ho _ edge + obtain rfl := Set.mem_singleton_iff.1 ht + change (bL.mem S1 (wa (bwv KTb) o) &&& 3#u64) = 3#u64 at edge + rw [w1M_kt P ho] at edge + exact (and3z edge).elim + + +end w1 + +end + +end BootWit +end ST +end R +end W7 + +end Fl4ProofsA64.P1 diff --git a/proofs/scratch/a64/a64_ax2.lean b/proofs/scratch/a64/a64_ax2.lean index dee71a3a9..9c8cc6bb4 100644 --- a/proofs/scratch/a64/a64_ax2.lean +++ b/proofs/scratch/a64/a64_ax2.lean @@ -1,3 +1,42 @@ +import Fl4ProofsA64.P1.S1aKtVsArms +import Fl4ProofsA64.P1.S1aKtPoolArms +import Fl4ProofsA64.P1.S1aKtRetype +import Fl4ProofsA64.P1.S1aStepR2K +import Fl4ProofsA64.P1.S1aStepR2KBoot +import Fl4ProofsA64.P1.S1aKtLvCol +import Fl4ProofsA64.P1.S1aR2KtLevel +import Fl4ProofsA64.P1.S1aR2Relabel +import Fl4ProofsA64.P1.S1aKtArms +import Fl4ProofsA64.P1.S1aKtDelArms +import Fl4ProofsA64.P1.S1aHiDelR +import Fl4ProofsA64.P1.S1aR2AssignD +import Fl4ProofsA64.P1.S1aStepR2A +import Fl4ProofsA64.P1.S1aStepR2Boot +import Fl4ProofsA64.P1.S1aKtUtArms +import Fl4ProofsA64.P1.S1aKtUtDel +import Fl4ProofsA64.P1.S1aR2KtDel +import Fl4ProofsA64.P1.S1aStepR2 +import Fl4ProofsA64.P1.S1aR2KeepArms +import Fl4ProofsA64.P1.S1aR2Install +import Fl4ProofsA64.P1.S1aR2TcbArm +import Fl4ProofsA64.P1.S1aR2OfImage +import Fl4ProofsA64.P1.S1aR2CnodeImage +import Fl4ProofsA64.P1.S1aR2DelArm +import Fl4ProofsA64.P1.S1aR2Delete +import Fl4ProofsA64.P1.S1aR2FinAlias +import Fl4ProofsA64.P1.S1aR2FinRoot +import Fl4ProofsA64.P1.S1aR2FinPt +import Fl4ProofsA64.P1.S1aR2FinFrame +import Fl4ProofsA64.P1.S1aR2Zeroed +import Fl4ProofsA64.P1.S1aR2FinPool +import Fl4ProofsA64.P1.S1aR2Field +import Fl4ProofsA64.P1.S1aR2Slots +import Fl4ProofsA64.P1.S1aR2Del +import Fl4ProofsA64.P1.S1aR2MakePool +import Fl4ProofsA64.P1.S1aR2RetypeTop +import Fl4ProofsA64.P1.S1aR2RetypePost +import Fl4ProofsA64.P1.S1aR2RetypeEnd +import Fl4ProofsA64.P1.S1aR2RetypeHigh import Fl4ProofsA64.P1.Queue import Fl4ProofsA64.P1.QueueAppend import Fl4ProofsA64.P1.QueueBudget @@ -435,6 +474,7 @@ import Fl4ProofsA64.P1.MdbVsMapB import Fl4ProofsA64.P1.MdbVsMapC import Fl4ProofsA64.P1.MdbPtCapA import Fl4ProofsA64.P1.S1aPtStep +import Fl4ProofsA64.P1.S1aDevFr import Fl4ProofsA64.P1.MdbEptQ import Fl4ProofsA64.P1.MdbEptUnmQ import Fl4ProofsA64.P1.MdbEptMapQ @@ -458,6 +498,78 @@ import Fl4ProofsA64.P2.BootSysA import Fl4ProofsA64.P1.BootW1Win import Fl4ProofsA64.P1.S1aBootW1 import Fl4ProofsA64.P1.S1aS2Dec +import Fl4ProofsA64.P1.S1aKTab +import Fl4ProofsA64.P1.S1aKtUt +import Fl4ProofsA64.P1.S1aBootK +import Fl4ProofsA64.P1.S1aVsUnm +import Fl4ProofsA64.P1.S1aVsUnmB +import Fl4ProofsA64.P1.S1aR2Frame +import Fl4ProofsA64.P1.S1aR2Caps +import Fl4ProofsA64.P1.S1aR2Image +import Fl4ProofsA64.P1.S1aR2Shrink +import Fl4ProofsA64.P1.S1aR2Keep +import Fl4ProofsA64.P1.S1aR2Ept +import Fl4ProofsA64.P1.S1aR2Contract +import Fl4ProofsA64.P1.S1aR2Domains +import Fl4ProofsA64.P1.S1aR2RootInit +import Fl4ProofsA64.P1.S1aR2Transport +import Fl4ProofsA64.P1.S1aR2MapRoots +import Fl4ProofsA64.P1.S1aR2MapWalk +import Fl4ProofsA64.P1.S1aR2MapNative +import Fl4ProofsA64.P1.S1aR2MapHighEntry +import Fl4ProofsA64.P1.S1aR2MapHigh +import Fl4ProofsA64.P1.S1aR2MapStage2 +import Fl4ProofsA64.P1.S1aR2MapWrite +import Fl4ProofsA64.P1.S1aR2MapStage2Post +import Fl4ProofsA64.P1.S1aR2MapReference +import Fl4ProofsA64.P1.S1aR2MapStage1Post +import Fl4ProofsA64.P1.S1aR2MapPlacement +import Fl4ProofsA64.P1.S1aR2MapPaths +import Fl4ProofsA64.P1.S1aR2MapBacking +import Fl4ProofsA64.P1.S1aR2MapReach +import Fl4ProofsA64.P1.S1aR2MapTypes +import Fl4ProofsA64.P1.S1aR2MapRootSlots +import Fl4ProofsA64.P1.S1aR2MapCaps +import Fl4ProofsA64.P1.S1aR2MapGrow +import Fl4ProofsA64.P1.S1aR2MapPost +import Fl4ProofsA64.P1.S1aR2MapDispatch +import Fl4ProofsA64.P1.S1aR2FrameWord +import Fl4ProofsA64.P1.S1aR2FramePaths +import Fl4ProofsA64.P1.S1aR2FrameMapWrite +import Fl4ProofsA64.P1.S1aR2FrameMapStage1 +import Fl4ProofsA64.P1.S1aR2FrameMapStage2 +import Fl4ProofsA64.P1.S1aR2FrameMapDecode +import Fl4ProofsA64.P1.S1aR2FrameRaw +import Fl4ProofsA64.P1.S1aR2SlotUnique +import Fl4ProofsA64.P1.S1aR2FrameBacking +import Fl4ProofsA64.P1.S1aR2FrameMapPost +import Fl4ProofsA64.P1.S1aR2FrameUnmapPost +import Fl4ProofsA64.P1.S1aR2AccessPost +import Fl4ProofsA64.P1.S1aR2AssignRoot +import Fl4ProofsA64.P1.S1aR2AssignStage1 +import Fl4ProofsA64.P1.S1aR2AssignPost +import Fl4ProofsA64.P1.S1aR2RetypeFrame +import Fl4ProofsA64.P1.S1aR2PathReference +import Fl4ProofsA64.P1.S1aR2UnmapAddress +import Fl4ProofsA64.P1.S1aR2UnmapWalk +import Fl4ProofsA64.P1.S1aR2UnmapS1 +import Fl4ProofsA64.P1.S1aR2UnmapS2 +import Fl4ProofsA64.P1.S1aR2UnmapRoute +import Fl4ProofsA64.P1.S1aR2Assign +import Fl4ProofsA64.P1.S1aR2PtUnmap +import Fl4ProofsA64.P1.S1aR2UnmapPost +import Fl4ProofsA64.P1.MdbArmVs +import Fl4ProofsA64.P1.MdbArmVsF +import Fl4ProofsA64.P1.MdbArmVsG +import Fl4ProofsA64.P1.MdbDelVsZ +import Fl4ProofsA64.P1.MdbArmVsV +import Fl4ProofsA64.P1.S1aHiCap +import Fl4ProofsA64.P1.S1aHiK +import Fl4ProofsA64.P1.S1aHiDelDec +import Fl4ProofsA64.P1.S1aHiVs +import Fl4ProofsA64.P1.S1aHiAsg +import Fl4ProofsA64.P1.S1aHiRetype +import Fl4ProofsA64.P1.S1aHiDispatch open Lean Elab Command in #eval show CommandElabM Unit from do let env ← getEnv @@ -6560,3 +6672,1178 @@ open Lean Elab Command in #print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_ptCapK #print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_ptHG #print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_s1aPtCol +#print axioms Fl4ProofsA64.P1.W7.R.ST.KTab.empty +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtH.empty +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.empty +#print axioms Fl4ProofsA64.P1.W7.R.ST.two12 +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.addOKP +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.hg +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.heapOK +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.osok +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.ksOff +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.ptHG +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPtCol.addKt +#print axioms Fl4ProofsA64.P1.W7.R.ST.SymL.addKt +#print axioms Fl4ProofsA64.P1.W7.R.ST.SysL.addKt +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.vsr +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.vrOK +#print axioms Fl4ProofsA64.P1.W7.R.ST.vsr_unionK +#print axioms Fl4ProofsA64.P1.W7.R.ST.DelIn.addKt +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtBundle.addKt +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsTy.addZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsTy.assign2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.TeH.hD +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2DecTy.ofTeH +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDecHyps.ofT +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.vKT +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.kte3 +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.kteT +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1Ar_l0 +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1Ar_ktab +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_ktOutE +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_ktOutE +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_ktE +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.ktv +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.p18 +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.pT +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.p7 +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1M_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_out +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_bundle +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_bundleOf +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_vs +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_assign2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.MapV.names +#print axioms Fl4ProofsA64.P1.W7.R.ST.UnmCap.names +#print axioms Fl4ProofsA64.P1.W7.R.ST.UnmC.capA +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmKt +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmR1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmCR1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmCR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmCZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsReach.back +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Reach.back +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.capOf_vs +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.vs_triv +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_capV +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_slotCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.capOf_tail +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_backed +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_vsLk +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_vsLk +#print axioms Fl4ProofsA64.P1.W7.R.ST.heap_wa_ne +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmT +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmTZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmCT +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmCTZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtH.kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1Tb_h +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVs.get +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.vsKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.toVs +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVs.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.ofW +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.ofWA +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsWr.keepL +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVs.keepL +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsWr.keepR +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVs.keepR +#print axioms Fl4ProofsA64.P1.W7.R.ST.DfW.notPtW +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.ofDF +#print axioms Fl4ProofsA64.P1.W7.R.ST.omega_obj_frame +#print axioms Fl4ProofsA64.P1.W7.R.ST.DmW.notPtW +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.ofDM +#print axioms Fl4ProofsA64.P1.W7.R.ST.K8.KW.notPtWE +#print axioms Fl4ProofsA64.P1.W7.R.ST.TkW +#print axioms Fl4ProofsA64.P1.W7.R.ST.TkW.notPtW +#print axioms Fl4ProofsA64.P1.W7.R.ST.FrCw +#print axioms Fl4ProofsA64.P1.W7.R.ST.FrCw.notVsR +#print axioms Fl4ProofsA64.P1.W7.R.ST.FrCw.keepO +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.ofFoot +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsZ.toVs +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.toZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsZ.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsZ.thenOS +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtZ.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtZ.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtZ.ofKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtZ.wr0 +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtZ.zr +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsZ.ofDZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.andn_or_self +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVs.ofAf +#print axioms Fl4ProofsA64.P1.W7.R.ST.SusW.tk +#print axioms Fl4ProofsA64.P1.W7.R.ST.RunB.tk +#print axioms Fl4ProofsA64.P1.W7.R.ST.UnmMid.armVsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.sched.set_thread_state.unmMidZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.obj.Slot.set_cap.armVsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.frame_off_words +#print axioms Fl4ProofsA64.P1.W7.R.ST.finKZ_s2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsZG.step +#print axioms Fl4ProofsA64.P1.W7.R.ST.spec_vsZG +#print axioms Fl4ProofsA64.P1.W7.R.ST.vsk_cw0 +#print axioms Fl4ProofsA64.P1.W7.R.ST.vsz_finK +#print axioms Fl4ProofsA64.P1.W7.R.ST.VrOK.ofUb +#print axioms Fl4ProofsA64.P1.W7.R.ST.VcOK.inter +#print axioms Fl4ProofsA64.P1.W7.R.ST.RunBuf.frUb +#print axioms Fl4ProofsA64.P1.W7.R.ST.JV.inter +#print axioms Fl4ProofsA64.P1.W7.R.ST.obj.Slot.set_cap.vsZG +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.cap_swap_for_delete.vsZG +#print axioms Fl4ProofsA64.P1.W7.R.ST.sched.preemption_point.vsZG +#print axioms Fl4ProofsA64.P1.W7.R.ST.LoopME.vzM +#print axioms Fl4ProofsA64.P1.W7.R.ST.vsZG_self +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.vsZG0 +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.vsZI0 +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.vsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.revoke.vsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.FrUbA.null +#print axioms Fl4ProofsA64.P1.W7.R.ST.FrUbA.zombie +#print axioms Fl4ProofsA64.P1.W7.R.ST.FrC.ci +#print axioms Fl4ProofsA64.P1.W7.R.ST.FrC.of_ci +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsZ.toG +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsZ.ofG +#print axioms Fl4ProofsA64.P1.W7.R.ST.PlG.plW +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.armVsZG +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.armVsZI +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.armVsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.revoke.armVsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.FrCw.keepO +#print axioms Fl4ProofsA64.P1.W7.R.ST.lookup_bufKC +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.install_page.slotE +#print axioms Fl4ProofsA64.P1.W7.R.ST.nat_or_offM +#print axioms Fl4ProofsA64.P1.W7.R.ST.nat_small_offM +#print axioms Fl4ProofsA64.P1.W7.R.ST.paddr_ok +#print axioms Fl4ProofsA64.P1.W7.R.ST.paddr_andM +#print axioms Fl4ProofsA64.P1.W7.R.ST.descTo_of +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1page_v +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1page_desc +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1tab_desc +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.thenW +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.transV +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.vs +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVs.ofOne +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.ofDFBs +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.ofDFI +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.ofSspW +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsK.ofSusW +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsZ.thenK +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmVsZ.thenOne +#print axioms Fl4ProofsA64.P1.W7.R.ST.DF.armVsK +#print axioms Fl4ProofsA64.P1.W7.R.ST.DevFrAl.empty +#print axioms Fl4ProofsA64.P1.W7.R.ST.DevFrAl.invoked +#print axioms Fl4ProofsA64.P1.W7.R.ST.FootD.oskTabV +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtW.sysK +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.newPtAl +#print axioms Fl4ProofsA64.P1.W7.R.ST.XV.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.XV.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.XV.step +#print axioms Fl4ProofsA64.P1.W7.R.ST.XV.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.capOf_devFr +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete_one.irqM +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete_one.irqZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.insert_with_cap.armVsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.descTo_ofE +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.install_s2_leaf.slotE +#print axioms Fl4ProofsA64.P1.W7.R.ST.frame_al4k +#print axioms Fl4ProofsA64.P1.W7.R.ST.msg.buf_set.xv +#print axioms Fl4ProofsA64.P1.W7.R.ST.obj.Slot.set_cap.capEq +#print axioms Fl4ProofsA64.P1.W7.R.ST.paddr_andE +#print axioms Fl4ProofsA64.P1.W7.R.ST.paddr_spec +#print axioms Fl4ProofsA64.P1.W7.R.ST.s2leaf_desc +#print axioms Fl4ProofsA64.P1.W7.R.ST.s2leaf_v +#print axioms Fl4ProofsA64.P1.W7.R.ST.s2tab_desc +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_devFrAl +#print axioms Fl4ProofsA64.P1.W7.R.ST.DevFrP.null +#print axioms Fl4ProofsA64.P1.W7.R.ST.DevFrP.ut +#print axioms Fl4ProofsA64.P1.W7.R.ST.DevFrP.pool +#print axioms Fl4ProofsA64.P1.W7.R.ST.newCapA_devFr +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.devFr +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.devFrN +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapInv.poolEnd +#print axioms Fl4ProofsA64.P1.W7.R.ST.DevFrAl.poolEnd +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.null +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.zombie +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.ut +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.irq +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.al +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.remap +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.of_slot +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.ofOSK +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.setc +#print axioms Fl4ProofsA64.P1.W7.R.ST.CapSrc.inv +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtCapP.closed +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.capInv +#print axioms Fl4ProofsA64.P1.W7.R.ST.PoolR.capSrc +#print axioms Fl4ProofsA64.P1.W7.R.ST.DevFrP.closed +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.devFr +#print axioms Fl4ProofsA64.P1.W7.R.ST.AsgPost.devFr +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.untyped_s1aRtVDf +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.makePool_s1aDf +#print axioms Fl4ProofsA64.P1.W7.R.ST.PoolPost.armVs +#print axioms Fl4ProofsA64.P1.W7.R.ST.RngKeyA.hv +#print axioms Fl4ProofsA64.P1.W7.R.ST.ptrA_hv +#print axioms Fl4ProofsA64.P1.W7.R.ST.al_hv +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiCap511P.closed +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiCap511.capP +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.hiCapP +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiCap511.ofRt +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiCap511.ofArmVsK +#print axioms Fl4ProofsA64.P1.W7.R.ST.HvRootP.closed +#print axioms Fl4ProofsA64.P1.W7.R.ST.HvPt.rt +#print axioms Fl4ProofsA64.P1.W7.R.ST.HvPt.mono +#print axioms Fl4ProofsA64.P1.W7.R.ST.HvPt.ofNoHv +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.hvPt +#print axioms Fl4ProofsA64.P1.W7.R.ST.AsgPost.hvPt +#print axioms Fl4ProofsA64.P1.W7.R.ST.HvPt.poolEnd +#print axioms Fl4ProofsA64.P1.W7.R.ST.newCapA_hv +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.hvPt +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.hvPtN +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.untyped_s1aRtVHv +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.makePool_s1aHv +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_hvPt +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.ptN +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtHG.keyOffNC +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.keyOff +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.bjAl +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.newPtH +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.ptHA +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.ptCapH +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.s1aStep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aZ2.toStep +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.s1aStepH +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.s1aStepPt +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.restart_caller.armVsK +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiCap511.ofK +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armKK3At +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armKK3_hi +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armQHK_hi +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.insert_with_cap.armVsK +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_sched_params.armQITyAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.DelIn.forHiDel +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.finKZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiCap511.ofDelTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.revoke.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.insert_with_cap.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.cnode.decode.rvDelTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnodeRvDel_s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete_one.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.interrupt.decode_irq_handler.clear_s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.interrupt.decode_irq_handler.set_s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_high_vspace.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_timeout_endpoint.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.install_buffer.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_ipc_buffer.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_space.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_configure.s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode.setEpt_s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.del_s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.ssp_s1aTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armDel_hi + +-- A64-S1A gen 41. VSpace arms preserve HighVSpace entry 511. +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.word +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.aligned +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.keepWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.keepWrite +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.keepWr0 +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.keepSlot +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.keepStage1Leaf +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.keepInvalid +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.keepTableZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_frame.unmapHr +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_page_table.unmapHv +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.restartCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.map_table.keepHr +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.map_high_page_table.keepHr +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_page_table.mapHr +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_high_page_map.keepHr +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.map_frame.keepHr +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_page_map.keepHr +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.mapped_entry.leafSlot +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_test_and_clear_accessed.keepHr +#print axioms Fl4ProofsA64.P1.W7.R.ST.DecArmQHV +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armVs_hi + +-- A64-S1A gen 41. Assign, MakePool and Retype preserve HighVSpace entry 511. +#print axioms Fl4ProofsA64.P1.W7.R.ST.AsgPost.hiCap511 +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode.assignHr +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.assignHi +#print axioms Fl4ProofsA64.P1.W7.R.ST.PoolPost.hiCap511 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.makePool_s1aHi +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.init_high_vspace.hiTag +#print axioms Fl4ProofsA64.P1.W7.R.ST.create_object.highInit +#print axioms Fl4ProofsA64.P1.W7.R.ST.WinHi +#print axioms Fl4ProofsA64.P1.W7.R.ST.WinHi.addr +#print axioms Fl4ProofsA64.P1.W7.R.ST.WinHi.capw +#print axioms Fl4ProofsA64.P1.W7.R.ST.create_object.winHi +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.retype.liveRWH +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.retype.live0IBH +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.sysLBH +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.sysLNBH +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.blkIH +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.s1aRtVJH +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.keepOldHi +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.hiCap511 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.untyped_s1aRtVHi + +-- A64-S1A gen 41. Dispatcher and common step carry HighVSpace entry 511. +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.delOnly_hi +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armKQ2_hi +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armQZ2_hi +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armQH_hi + +-- A64-S1A gen 41. The enclosing object of a Stage-1 table granule. +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1GranuleH + +-- A64-S1A gen 41. Active ASID-pool reachability and the R2 entry facts. +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtFndAll +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.ofTy +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.invoked +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsReach.backOf +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Reach.backOf +#print axioms Fl4ProofsA64.P1.W7.R.ST.TabKeepOrZero.poolSet + +-- A64-S1A gen 41. R2 root agreement, active walks, and boot witnesses. +#print axioms Fl4ProofsA64.P1.W7.R.ST.ActiveAsidRoot +#print axioms Fl4ProofsA64.P1.W7.R.ST.ActiveAsidRoot.find +#print axioms Fl4ProofsA64.P1.W7.R.ST.ActiveAsidRoot.back +#print axioms Fl4ProofsA64.P1.W7.R.ST.MappedAsidRoot +#print axioms Fl4ProofsA64.P1.W7.R.ST.RootAgreement +#print axioms Fl4ProofsA64.P1.W7.R.ST.RootAgreement.asid_unique +#print axioms Fl4ProofsA64.P1.W7.R.ST.RootAgreement.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.TabKeep.poolSet_eq +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtFnd.vkSeed +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtFnd.uniqueS1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtFnd.uniqueS2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtFnd.oneStage +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtFndAll.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.hvs +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_rootAgreement +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_rootAgreement +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_ptFndAll +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_ptFndAll +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_s1aR2Core +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_s1aR2Core + +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Place +#print axioms Fl4ProofsA64.P1.W7.R.ST.sched.set_thread_state.restartR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.restart_caller.r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.DecArmR2Cache +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cache_r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2TableCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2TableFields +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2TableFields.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2TableFields.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2TableFields.iff_eq +#print axioms Fl4ProofsA64.P1.W7.R.ST.capability.mask_cap_rights.r2TableFields +#print axioms Fl4ProofsA64.P1.W7.R.ST.objects.update_cap_data.r2TableFields +#print axioms Fl4ProofsA64.P1.W7.R.ST.objects.derive_cap.r2TableFields +#print axioms Fl4ProofsA64.P1.W7.R.ST.cnode.copied_cap.r2TableFields +#print axioms Fl4ProofsA64.P1.W7.R.ST.cnode.copied_cap.r2TableFieldsMove +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2CapImage +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2CapImage.ofSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2CapImage.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2CapImage.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2CapImage.writeDest +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2CapImage.swap +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2TableCap.names +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2TableCap.root +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2CapImage.back +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2CapImage.forward +#print axioms Fl4ProofsA64.P1.W7.R.ST.RootAgreement.keepImage +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.keepImage +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.keepImage +#print axioms Fl4ProofsA64.P1.W7.R.ST.cnode.decode.r2Image +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnode_r2Image +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsReach.poolMono +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Reach.poolMono +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsReach.activeZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Reach.activeZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsNm.activeZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Nm.activeZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsTyR.activeZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2TyR.activeZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.ActiveAsidRoot.forWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.RootAgreement.pageTableNoRoot +#print axioms Fl4ProofsA64.P1.W7.R.ST.ActiveHigh +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.unmap_page_table.activeUnr +#print axioms Fl4ProofsA64.P1.W7.R.ST.UnmCap.toSlot +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.unmZPlaced +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.ofKeepingArm +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.keeping_r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnode_r2 + +#print axioms Fl4ProofsA64.P1.W7.R.ST.EptPlaceP +#print axioms Fl4ProofsA64.P1.W7.R.ST.EptPlaced +#print axioms Fl4ProofsA64.P1.W7.R.ST.EptPlaceP.closed +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.eptPlaced +#print axioms Fl4ProofsA64.P1.W7.R.ST.AsgPost.eptPlaced +#print axioms Fl4ProofsA64.P1.W7.R.ST.EptPlaced.mono +#print axioms Fl4ProofsA64.P1.W7.R.ST.EptPlaced.unmZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.NewEpt +#print axioms Fl4ProofsA64.P1.W7.R.ST.EptPlaced.poolEnd +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.eptPlaced +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.newEptPtHG +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.eptAndPt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.retype_eptPlaced +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_eptPlaced +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_eptPlaced + +#print axioms Fl4ProofsA64.P1.W7.R.ST.NoRoot.activeZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsReach.falseOfNoParent +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Reach.falseOfNoParent +#print axioms Fl4ProofsA64.P1.W7.R.ST.RootAgreement.activeZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.activeZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.unmap_page_table.activeLookup + +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.PtObjects.poolEnd +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.ptObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_ptObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_ptObjects + +#print axioms Fl4ProofsA64.P1.W7.R.ST.UnmU.ofTableObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.PoolIdx.activeInjective +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_tableObjects + +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_loop1.emptyWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_loop2.eq_loop1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_loop3.eq_loop1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.assign_asid_offset +#print axioms Fl4ProofsA64.P1.W7.R.ST.ActiveAsidRoot.replaceWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.RootAgreement.assignWord + +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.find_asid_raw.active +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.findBacked +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.resetUnmappedPageTable +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_page_table.unmapUnmappedR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.unmapUnmappedR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.HvObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.hvObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.AsgPost.hvObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.HvObjects.second_ne +#print axioms Fl4ProofsA64.P1.W7.R.ST.HvObjects.poolEnd +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.hvObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_hvObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_hvObjects +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_hvObjects + +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aIpaWidth +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aTopShift +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aTableWidth +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aUserRange +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aCapAddress +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aLeafTarget +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aLeafValid +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aTableKey +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aTableRef +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTableCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPathBacking +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_s1aR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_s1aR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.DevFrP.aligned4K +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.bjAligned + +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRootZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aHighCopies +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aHighUnused +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_rootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1_rootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.geometry +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.slotRange +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.classifyStage1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.classifyStage2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.init_high_vspace.copies +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.init_high_vspace.rootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.create_object.highRootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aHighBatch +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.retype.highRootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.CrtE.nativeRootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.CrtE.stage2RootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.backIf +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.back +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.pathWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPathBacking.shrink +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolCaps.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.rootSlotsOfZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.keepingExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cacheExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.find_asid.path +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.find.path +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.find_high_asid.path +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.check_vspace.path +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.check_high_vspace.path +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aCapAddress_unpack +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aPageTableEncodeS2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aLeafTarget.ofDescTo +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aFrameAligned +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.entry_addr.exactOffset +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.entry_addr.exactOffset +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aChildIndex +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aIpaChildIndex +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aFrameShift +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotAt.child +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.lookup_slot_loop.exactPath +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.lookup_pt_slot_loop.unfoldOnce +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.lookup_pt_slot_loop.exactPath +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.lookup_pt_slot.nativePath +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.lookup_pt_slot.nativeUpper +#print axioms Fl4ProofsA64.P1.W7.R.ST.highLookupIndex +#print axioms Fl4ProofsA64.P1.W7.R.ST.highLookupHeader +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.lookup_pt_slot_loop.highHeaderStep +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.lookup_pt_slot.highPath +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.lookup_slot.exactPath +#print axioms Fl4ProofsA64.P1.W7.R.ST.obj.Slot.set_cap.exactMap +#print axioms Fl4ProofsA64.P1.W7.R.ST.sched.set_thread_state.mapCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.ofTail +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.install_s2_leaf.exactWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.map_table.exactEffect +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolCaps.toIdx +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolCaps.assign +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cacheInvariant +#print axioms Fl4ProofsA64.P1.W7.R.ST.MapV.notOfFinalPageTable +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.clearMappedPageTable +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPageTableClear +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_page_table.unmapMappedEffect +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.rootEntry +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.sameTag +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPathBacking.childRef +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPathBacking.childAgreement +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aWalkWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aWalkWord.val +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.baseAligned +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.entry_addr.ofInterval +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.entry_addr.ofIpaInterval +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.entry_addr.ofInterval +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.is_table.ofTag +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.is_table.ofTag +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.unmap_page_table_loop.routeStep +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.unmap_table_loop.routeStep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aUnmapStart1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.unmapContinue1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.unmapFind1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aUnmapStart2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.unmapContinue2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.unmapFind2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRouteFacts.recoverWalk +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRouteFacts +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.routeFacts +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRouteFacts.classifyStage1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRouteFacts.classifyStage2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRouteFacts.classifyPageTableParent1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRouteFacts.classifyPageTableParent2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.geom.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ofClearedPageTable +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.unmapMappedExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.unmapUnmappedExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.toStage1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.toStage2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_page_table.unmapUnmappedInvariant +#print axioms Fl4ProofsA64.P1.W7.R.ST.tableWordsNe +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolCaps.zero +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.root.path +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotAt.levels +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotAt.alignedAddress +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aMapBase +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.asidFits +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.ipa_limit.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTableMap +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.map_high_page_table.exactEffect +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_page_table.mapExactEffect +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.pathWordObject +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.pathWordOffPool +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.samePathWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.keepAsid +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.highHeader +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.activeAsid +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTablePaths +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.tablePaths +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTableMap.activePaths +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aTableStorage +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aTableWidth.leStorage +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.pathStorageWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.sameStorageWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.stage2Storage +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.pathOffKernel +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.pathOffHighHeader +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.mapStage1Source +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.mapStage2Source +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.pathNeUnmapped +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTablePaths.backing +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsTyR.reachableMember +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2TyR.reachableMember +#print axioms Fl4ProofsA64.P1.W7.R.ST.DescTo.tableTargets +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.rawStage1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.rawStage2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.stage1Typed +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.stage2Typed +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.pathStorageOwner +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.rootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.emptyRoots +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.tableKeys +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.tableCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.keepUnmappedWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.growStage1Place +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.growStage2Place +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.growStage2Heap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ofTableMap +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_page_table.mapMappedKeeps +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.pageTableMapExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.lookup_slot_loop.exactStop +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.lookup_pt_slot_loop.exactStop +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.lookup_pt_slot.nativeStop +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.lookup_pt_slot.highStop +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.lookup_slot.exactStop +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.make_user_page.leafValid +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.make_s2_leaf.leafValid +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aLeafNotTable +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.framePaths +#print axioms Fl4ProofsA64.P1.W7.R.ST.capability.FrameSize.bits.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.page_shift.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aFrameScale +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aFrameVAAligned +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aFrameAligned4K +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aIpaWidthBounds +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aFrameNormalized +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.make_user_page.exactLeaf +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.make_s2_leaf.exactLeaf +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFrameMap +#print axioms Fl4ProofsA64.P1.W7.R.ST.sched.set_thread_state.frameMapTail1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.sched.set_thread_state.frameMapTail2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.frameMapFinish1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aNativeHighIndex +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_high_page_map.exactEffect +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.map_frame.exactEffect +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_page_map.exactEffect +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.frameMapExactEffect +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.frameRawStage1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.frameRawStage2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.sameTable +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotAt.unique +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFrameMap.backing +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ofFrameMap +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.frameMapExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.rootSlotsOfCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.emptyRootsOfCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMapWrite.keepUnmappedWordOfWrite +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsLk.keepImageOfReach +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.is_leaf.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.is_page.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.leaf_base.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.page_base.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotAt.ancestor +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotAt.sameStop +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotAt.leafStop +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.unmap_page.clearsActiveLeaf +#print axioms Fl4ProofsA64.P1.W7.R.ST.ept.unmap.clearsActiveLeaf +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFrameCleared +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFrameUnmap +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_frame.unmapExactEffect +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ofFrameUnmap +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.frameUnmapExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAccessWrite +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_test_and_clear_accessed.exactWrite +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAccessWrite.mask +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aAccessMaskStage1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aAccessMaskStage2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAccessWrite.zero +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAccessWrite.leaf +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAccessWrite.pool +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAccessWrite.raw +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAccessWrite.backing +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ofAccessWrite +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.accessExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aUnassignedRoot +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode.assignExactWrite +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.fresh +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.value +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.table +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.poolFrame +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.entry +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.rootAgreement +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aUnassignedRoot.rangeKey +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.highHeader +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.oldPathWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.edgeKept +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.poolWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignedPath +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.assignedEmpty +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.pathCases +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.selectedCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.capIff +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.pageTableIff +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.poolCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.referenceAgreement +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.pathBacking +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aAssignEpt +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aAssignRe +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aAssignBits +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.unmappedStage2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.stage2KeepType +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.rawStage2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.stage2Typing +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aAssignTables +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aAssignLv +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.nativeCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.highCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.stage1KeepType +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.highMember +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.highChild +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignRawStage1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.rawStage1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.stage1Typing +#print axioms Fl4ProofsA64.P1.W7.R.ST.assignNativeKey +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.offObject +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.stage2Placement +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.stage1Placement +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.geometry +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.nativeSource +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.highSource +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.eptSource +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.highSet +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.kindPost +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.rootSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.tableCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.unmappedZero +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.lookup +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ofAssign +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.assignExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUt.ofRanges +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUt.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUtCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUt.iff_capInv +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUtCap.fe +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.s1aKtUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.UtEnd.kernelTables +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnode_s1aKtUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.untyped_s1aKtUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtOut.s1aKtUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.keepVsWords +#print axioms Fl4ProofsA64.P1.W7.R.ST.untypedWordOffNamed +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRetypeWordOwner +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.keepOwnedVsWords +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.keepKernelTables +#print axioms Fl4ProofsA64.P1.W7.R.ST.TabKeep.activeRootIff +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.iffOfWords +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.keepActivePaths +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.init_high_vspace.privateLink +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.init_high_vspace.privateEmpty +#print axioms Fl4ProofsA64.P1.W7.R.ST.CrtE.zeroTable +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.retype.newHighInit +#print axioms Fl4ProofsA64.P1.W7.R.ST.untyped.decode.newHighInit +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.reachWord1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.reachWord2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsReach.congrWords +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Reach.congrWords +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.sourceCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.ksb +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.old +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.kernel +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.owner +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.tableOff +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.capAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.capKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.newSlot +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.newObj +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.baseInj +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.destOff +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.highInit +#print axioms Fl4ProofsA64.P1.W7.R.ST.newCapA_notMapV +#print axioms Fl4ProofsA64.P1.W7.R.ST.newCapA_notMappedRoot +#print axioms Fl4ProofsA64.P1.W7.R.ST.newCapA_namesV +#print axioms Fl4ProofsA64.P1.W7.R.ST.newCapA_tableKey +#print axioms Fl4ProofsA64.P1.W7.R.ST.newCapA_unm +#print axioms Fl4ProofsA64.P1.W7.R.ST.newCapA_pml4 +#print axioms Fl4ProofsA64.P1.W7.R.ST.newCapA_eptShape +#print axioms Fl4ProofsA64.P1.W7.R.ST.RngKeyA.pml4 +#print axioms Fl4ProofsA64.P1.W7.R.ST.ptrA_pml4 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.heapOK +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.objOff +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.tableObj +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.namedOff +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.newT +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.newPt_sub +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.footprintAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.poolWordOwner +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.highWordOwner +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.storageWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.inObjWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.untypedExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.makePool.finWIX +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.makePool.finEIPAtX +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode.makePoolLIEAtX +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.makePoolLIEAtX +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_loop0.free +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.restrict +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRestrict.heapOK +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRestrict.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRestrict.named +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRestrict.objKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRestrict.placed +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRestrict.inside +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRestrict.granule +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.congrRoots +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsReach.zeroPool +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Reach.zeroPool +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolAdded.fresh +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolAdded.grow +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolAdded.pool +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolAdded.caps +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPoolAdded.offset +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.addPool +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.makePoolExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.LoopME.toP +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.finalise_slot_deferred.zqGMPE +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete_deferred.zqGMPE +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.finalise_slot_immediate.zqGTMPQ +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.zqIGTMPQ +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.congrSlots +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Del +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.toDel +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Del.exit +#print axioms Fl4ProofsA64.P1.W7.R.ST.LoopMP +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Reads +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.permute +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Core.keepImageActive +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.headerWord +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelM +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelPn +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.toDelM +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelM.drop +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aCapSame +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelM.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelPn.restore +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelM.swap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aVsCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aVsCap.unread +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFinVs +#print axioms Fl4ProofsA64.P1.W7.R.ST.obj.Slot.set_cap.zombieCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.LoopMP.r2M +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Place.monoHigh +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.zeroedOn +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelM.dropCopy +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.delete_asid_pool.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.is_final.pool_only +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFin.pool +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFin.frame +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aFrameRemove +#print axioms Fl4ProofsA64.P1.W7.R.ST.obj.Slot.set_cap.frameUnmapTail +#print axioms Fl4ProofsA64.P1.W7.R.ST.so_pt_inv +#print axioms Fl4ProofsA64.P1.W7.R.ST.so_pt_inv +#print axioms Fl4ProofsA64.P1.W7.R.ST.is_final.pt_copy +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.dropPageTable +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFin.pageTable +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.delete_asid.exact +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.delete_asid.rootGone +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRootCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.rootUnreached +#print axioms Fl4ProofsA64.P1.W7.R.ST.is_final.root_copy +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFin.deleteRoot +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFin.root +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFin.eptInner +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.dropSlot +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRouteFacts.classifyEdge1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.maskedRoot +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.clearing +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFin.alias +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aFinVs.of +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.unmap_page_table.activeWrites +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.LoopMP.r2Del +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.r2G +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.r2I +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.revoke.r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.finalise_slot_immediate.irqMPQ +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.irqMPQ +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Q.vsCap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.toDelKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelKeep.same +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelKeep.osKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.r2R +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.revoke.r2R +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.restart_caller.r2Keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.cnode.decode.rvDelR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnodeRvDel_r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete_one.r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.insert_with_cap.r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.interrupt.decode_irq_handler.clear_r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.interrupt.decode_irq_handler.set_r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.faults.valid_fault_handler.unread +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.install_tcb_cap.r2F +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.ssp_r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_sched_params.armQIPAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTableCaps.refs +#print axioms Fl4ProofsA64.P1.W7.R.ST.R2TableCap.reads +#print axioms Fl4ProofsA64.P1.W7.R.ST.s1aTableKey.reads +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotImage.refs +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotImage.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotImage.perm +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotImage.ofSame +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotImage.swap +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotImage.copy +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ofImage +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aIsFrame +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aCopyRel +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMoveRel +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDerived +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aCopyRel.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aCopyRel.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aMoveRel.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.objects.update_cap_data.s1aRel +#print axioms Fl4ProofsA64.P1.W7.R.ST.capability.mask_cap_rights.s1aRel +#print axioms Fl4ProofsA64.P1.W7.R.ST.objects.derive_cap.s1aRel +#print axioms Fl4ProofsA64.P1.W7.R.ST.cnode.copied_cap.s1aCopy +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDerived.same +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aSlotImage.move +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aCapSame.insertSource +#print axioms Fl4ProofsA64.P1.W7.R.ST.cnode.decode.s1aImage +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnodeExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelKeep.ofImage +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.insert_with_cap.r2C +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.capInvR +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aInstallRoot +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRefAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRefsMono +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRefsMono.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRefsMono.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRefsMono.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRefAt.unkeyed +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRefAt.ofSlot +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRefsMono.insert +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.refsR +#print axioms Fl4ProofsA64.P1.W7.R.ST.objects.same_object_as.root +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aInstallRoot.mapped +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.insert_with_cap.refs +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.install_tcb_cap.r2G +#print axioms Fl4ProofsA64.P1.W7.R.ST.obj.Tcb.set_ipc_buffer.vk +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.install_buffer.r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.derive_with_data.s1aRel +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.is_valid_vtable_root.root +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.derive_roots.s1aRoots +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.derive_for_buffer.s1aDerived +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTcbKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTcbSteps.r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.tcbInstall_r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.setEpt_r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_high_vspace.s1aPhi +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_timeout_endpoint.s1aPhi +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_ipc_buffer.s1aPhi +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_set_space.s1aPhi +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_configure.s1aPhi +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode.setEpt_s1aPhi +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTcbSteps.trivial +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ofArmKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.DecArmR2Keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.keepSlotsExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.ntfn_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode.suspendSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.suspend_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.ackVppi_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.vcWr_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.vcSt_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.sched.set_thread_state.restart_reply_armS +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.getAddr_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode_read_registers.armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.decode.readRegsSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.readRegs_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.vcpu.decode_run.runS +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.run_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.vcpu.decode_set_tcb.armS +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.setTcb_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.irqCtlExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.IrqSlots.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.IrqSlots.after +#print axioms Fl4ProofsA64.P1.W7.R.ST.interrupt.invoke_irq_control.armS +#print axioms Fl4ProofsA64.P1.W7.R.ST.interrupt.decode_irq_control_msi.armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.interrupt.decode_irq_control.armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.irqCtl_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.XferSlots.s1aImage +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.endpointExactR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.XferSlots.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.XferSlots.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.XferSlots.before +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.insert.slots +#print axioms Fl4ProofsA64.P1.W7.R.ST.XJX.consS +#print axioms Fl4ProofsA64.P1.W7.R.ST.ipc.transfer_caps_loop.xjS +#print axioms Fl4ProofsA64.P1.W7.R.ST.ipc.do_normal_transfer.xjS +#print axioms Fl4ProofsA64.P1.W7.R.ST.ipc.do_ipc_transfer.xjS +#print axioms Fl4ProofsA64.P1.W7.R.ST.endpoint.send_ipc.recvS +#print axioms Fl4ProofsA64.P1.W7.R.ST.endpoint.send_block.sysS +#print axioms Fl4ProofsA64.P1.W7.R.ST.endpoint.send_ipc.blockS +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.ep_armSAt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUt.slots +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUt.at +#print axioms Fl4ProofsA64.P1.W7.R.ST.XferSlots.ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.IrqSlots.ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.keepSlots_ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.irqCtl_ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.endpoint_ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cache_ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.pageTableMap_ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.pageTableUnmap_ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.frameMap_ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.frameUnmap_ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.access_ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.AsgPost.ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUtCap.null +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aKtUtCap.zombie +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.ktUtR +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete.ktUtQ +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.revoke.ktUtR +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.delete_one.ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.cdt.insert_with_cap.ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelKt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelKt.osKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.TcbK.notUntyped +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.install_tcb_cap.ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.install_buffer.ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTcbSteps.ktUt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTcbSteps.and +#print axioms Fl4ProofsA64.P1.W7.R.ST.sched.set_thread_state.restartOs +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.tcbInstall_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.setEpt_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.ssp_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnodeRvDel_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.irqHandler_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2Ex +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ex +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aDelKt.ex +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.hvPt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armQH_r2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aStepR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aStepR2.toStep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aStepR2.ofR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.s1aStepR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.makePoolEndR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.tcbInstall_phi +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.ssp_phi +#print axioms Fl4ProofsA64.P1.W7.R.ST.cnode.decode.rvDelPhi +#print axioms Fl4ProofsA64.P1.W7.R.ST.interrupt.decode_irq_handler.clearPhi +#print axioms Fl4ProofsA64.P1.W7.R.ST.interrupt.decode_irq_handler.setPhi +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.install_tcb_cap.phi +#print axioms Fl4ProofsA64.P1.W7.R.ST.tcb.install_buffer.phi +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.accessRoute +#print axioms Fl4ProofsA64.P1.W7.R.ST.PoolSet.idem +#print axioms Fl4ProofsA64.P1.W7.R.ST.ActiveAsidRoot.activePools +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aPath.activePools +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.activePools +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_s1aStepEntry +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_s1aStepEntry +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTy.toR +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTyR.ofR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTyR.place +#print axioms Fl4ProofsA64.P1.HrOK.restrictT +#print axioms Fl4ProofsA64.P1.S2OK.restrictT +#print axioms Fl4ProofsA64.P1.W7.R.ST.S2Ty.restrictT +#print axioms Fl4ProofsA64.P1.W7.R.ST.tbo_restrict +#print axioms Fl4ProofsA64.P1.W7.R.ST.finKT_s2R +#print axioms Fl4ProofsA64.P1.W7.R.ST.tyk_s2R +#print axioms Fl4ProofsA64.P1.W7.R.ST.finKZ_s2R +#print axioms Fl4ProofsA64.P1.W7.R.ST.DelIn.forHiDelR +#print axioms Fl4ProofsA64.P1.W7.R.ST.HiDelTyR.finKZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignDesc +#print axioms Fl4ProofsA64.P1.W7.R.ST.VsTy.assignDesc +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.highChildD +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.stage1TypingD +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aAssignWrite.geometryD +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ofAssignD +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.assignExactR2D +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.tcbInstall_ktR +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.setEpt_ktR +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.ssp_ktR +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnodeRvDel_ktR +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armQH_r2R +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.s1aStepR2A +#print axioms Fl4ProofsA64.P1.W7.R.ST.kChild +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtHdrW +#print axioms Fl4ProofsA64.P1.W7.R.ST.EdgeKeepOn +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aHiKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aHiK.keep +#print axioms Fl4ProofsA64.P1.W7.R.ST.EdgeKeepOn.mono +#print axioms Fl4ProofsA64.P1.W7.R.ST.EdgeKeepOn.refl +#print axioms Fl4ProofsA64.P1.W7.R.ST.EdgeKeepOn.trans +#print axioms Fl4ProofsA64.P1.W7.R.ST.EdgeKeepOn.ofKept +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ktHdrW +#print axioms Fl4ProofsA64.P1.W7.R.ST.EdgeKeepOn.ofVsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.EdgeKeepOn.ofVsKeep +#print axioms Fl4ProofsA64.P1.W7.R.ST.ArmQIAt.hiRoots +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.nativeOf +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.highOf +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.pathChildNotKt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.ktLevel +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.unmappedNotMapped +#print axioms Fl4ProofsA64.P1.W7.R.ST.second_not_hv +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.unmappedRootUnreached +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.unmappedPrivateUnreached +#print axioms Fl4ProofsA64.P1.W7.R.ST.Priv +#print axioms Fl4ProofsA64.P1.W7.R.ST.relLv_reach +#print axioms Fl4ProofsA64.P1.W7.R.ST.relLv_iff +#print axioms Fl4ProofsA64.P1.W7.R.ST.relLv_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.relLv_root +#print axioms Fl4ProofsA64.P1.W7.R.ST.relLv_priv +#print axioms Fl4ProofsA64.P1.W7.R.ST.priv_ne_hdr +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.relabel +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aR2.assignDescK +#print axioms Fl4ProofsA64.P1.W7.R.ST.DelIn.withVsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.FinKZ.withVsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.EdgeKeepOn.ofArmVsK +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.keepSlots_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.irqCtl_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.endpoint_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnodeCopy_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.keeping_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cache_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aTcbSteps.vsZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.tcbInstall_ktZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.setEpt_ktZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.ssp_ktZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.cnodeRvDel_ktZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.irqHandler_ktZ +#print axioms Fl4ProofsA64.P1.W7.R.ST.EdgeKeepOn.ofMapWrite +#print axioms Fl4ProofsA64.P1.W7.R.ST.KtHdrW.ofCaps +#print axioms Fl4ProofsA64.P1.W7.R.ST.vspace.decode_frame.unmapExactEffectK +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.frameUnmap_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.access_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.frameMap_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.pageTableMap_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.unmapMapped_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.unmapUnmapped_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.assign_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.makePool_kt +#print axioms Fl4ProofsA64.P1.W7.R.ST.Kt1 +#print axioms Fl4ProofsA64.P1.W7.R.ST.Kt1.ktab +#print axioms Fl4ProofsA64.P1.W7.R.ST.Kt1.sub +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aRtIn.hiK +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.untypedExactR2K +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.armQH_edge +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aStepR2K +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aStepR2K.toR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aStepR2K.column +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aStepR2K.ofR2 +#print axioms Fl4ProofsA64.P1.W7.R.ST.S1aHiKeep.ofPool +#print axioms Fl4ProofsA64.P1.W7.R.ST.syscall.decode_invocation.s1aStepR2K +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w0_s1aStepEntryK +#print axioms Fl4ProofsA64.P1.W7.R.ST.BootWit.w1K_s1aStepEntryK