Skip to content

Commit ec299db

Browse files
PhaseII verified: Temporal logic and state machines (#213)
* MutexSpec init * MutexSpec init * Fix mutex spec * Use state_machine to characterize state predicates * Complete state machine definition * temporal logic init * Make `temporal_logic` compile * Add a test * Simplify stable def * Add TLA rules * Add some broadcasts * Use ext_euqal for Execution * Use broadcast to simplify proofs * Simplify rules * fmt * Simplify rules * Add a public broadcast group * Finish updating TLA rules * Migrate state_machine * Add mutex state machine * Add TLA-style transitions * add pub use * Merge temporal logic and state machine into vstd_extra to avoid compilation bugs * fmt * fmt * Model abstract lock * Prove the first TLA lemma * Add mutual_exclusion_lemma * Prove lemma_pc_stack_match in an ugly way * Update abstract_lock.rs * Minor * refactor code * Refactor code * Add two proofs * Fix crate name * Update abstract_lock.rs * Add rules and macros * prove: 1 admit in lemma_not_locked_iff_not_in_cs * prove: 2 `admit`s in `vstd_extra/rules` * Minor * Prove a set_prop_mutual_exclusion lemma * Add handy macros * prove: 6 `admit`s but modify a spec * Revert "prove: 6 `admit`s but modify a spec" This reverts commit 0901c02. * fix false spec identified by kverus * prove: 6 `admit`s in ostd sync spec * Simplify kverus code * Revert "Simplify kverus code" This reverts commit da21deb. * Revert "prove: 6 `admit`s in ostd sync spec" This reverts commit 97a0fd0. * Manually prove the first admit * Prove mutual_exclusion * Add a liveness lemma * fmt * Fix wrong spec * Simplify rules * Prove a new rule * Fix some macros * fmt * Add TLA rules * prove: `implies_tla_exists_by_witness` and `leads_to_tla_exists_by_witness` * simplify proof * Make rule names more clear * Fully prove a liveness property * Add a locked case * prove: lift_state_exists_leads_to_intro * prove: lemma_pc_stack_match_statdead_and_alive_lock_freee_pred_case_locked * Simplify AI proofs * Make SpinLock compile * Prove dead and alive lock free * Minor --------- Co-authored-by: Marsman1996 <lqliuyuwei@outlook.com>
1 parent 8a715a2 commit ec299db

18 files changed

Lines changed: 4856 additions & 31 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ostd/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ pub mod logger;*/
4444
pub mod mm;
4545
/*pub mod panic;
4646
pub mod prelude;
47-
pub mod smp;
47+
pub mod smp;*/
4848
pub mod sync;
49-
pub mod task;
49+
/* pub mod task;
5050
pub mod timer;
5151
pub mod trap;
5252
pub mod user;*/

ostd/src/sync/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// SPDX-License-Identifier: MPL-2.0
22
//! Useful synchronization primitives.
3-
mod guard;
4-
mod mutex;
5-
mod rcu;
6-
mod rwarc;
7-
mod rwlock;
8-
mod rwmutex;
3+
//mod guard;
4+
//mod mutex;
5+
//mod rcu;
6+
//mod rwarc;
7+
//mod rwlock;
8+
//mod rwmutex;
99
mod spin;
10-
mod wait;
11-
10+
//mod wait;
11+
/*
1212
pub(crate) use self::rcu::finish_grace_period;
1313
pub use self::{
1414
guard::{GuardTransfer, LocalIrqDisabled, PreemptDisabled, SpinGuardian, WriteIrqDisabled},
@@ -29,4 +29,4 @@ pub use self::{
2929
3030
pub(crate) fn init() {
3131
rcu::init();
32-
}
32+
}*/

ostd/src/sync/spin.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// SPDX-License-Identifier: MPL-2.0
2+
use vstd::prelude::*;
3+
use vstd::cell::{self, PCell};
4+
25
use alloc::sync::Arc;
36
use core::{
47
cell::UnsafeCell,
@@ -8,8 +11,8 @@ use core::{
811
sync::atomic::{AtomicBool, Ordering},
912
};
1013

11-
use super::{guard::SpinGuardian, LocalIrqDisabled, PreemptDisabled};
12-
use crate::task::atomic_mode::AsAtomicModeGuard;
14+
//use super::{guard::SpinGuardian, LocalIrqDisabled, PreemptDisabled};
15+
//use crate::task::atomic_mode::AsAtomicModeGuard;
1316

1417
/// A spin lock.
1518
///
@@ -27,32 +30,41 @@ use crate::task::atomic_mode::AsAtomicModeGuard;
2730
///
2831
/// [`disable_irq`]: Self::disable_irq
2932
#[repr(transparent)]
30-
pub struct SpinLock<T: ?Sized, G = PreemptDisabled> {
33+
#[verus_verify]
34+
//pub struct SpinLock<T: ?Sized, G = PreemptDisabled> {
35+
pub struct SpinLock<T,G> {
3136
phantom: PhantomData<G>,
3237
/// Only the last field of a struct may have a dynamically sized type.
3338
/// That's why SpinLockInner is put in the last field.
3439
inner: SpinLockInner<T>,
3540
}
3641

37-
struct SpinLockInner<T: ?Sized> {
42+
#[verus_verify]
43+
struct SpinLockInner<T> {
3844
lock: AtomicBool,
39-
val: UnsafeCell<T>,
45+
//val: UnsafeCell<T>,
46+
val: PCell<T>,
4047
}
4148

49+
verus!{
50+
#[verus_verify]
4251
impl<T, G> SpinLock<T, G> {
4352
/// Creates a new spin lock.
4453
pub const fn new(val: T) -> Self {
54+
let (val, Tracked(perm)) = PCell::new(val);
4555
let lock_inner = SpinLockInner {
4656
lock: AtomicBool::new(false),
47-
val: UnsafeCell::new(val),
57+
//val: UnsafeCell::new(val),
58+
val: val,
4859
};
4960
Self {
5061
phantom: PhantomData,
5162
inner: lock_inner,
5263
}
5364
}
5465
}
55-
66+
}
67+
/*
5668
impl<T: ?Sized> SpinLock<T, PreemptDisabled> {
5769
/// Converts the guard behavior from disabling preemption to disabling IRQs.
5870
pub fn disable_irq(&self) -> &SpinLock<T, LocalIrqDisabled> {
@@ -156,14 +168,14 @@ pub struct SpinLockGuard_<T: ?Sized, R: Deref<Target = SpinLock<T, G>>, G: SpinG
156168
guard: G::Guard,
157169
lock: R,
158170
}
159-
171+
/*
160172
impl<T: ?Sized, R: Deref<Target = SpinLock<T, G>>, G: SpinGuardian> AsAtomicModeGuard
161173
for SpinLockGuard_<T, R, G>
162174
{
163175
fn as_atomic_mode_guard(&self) -> &dyn crate::task::atomic_mode::InAtomicMode {
164176
self.guard.as_atomic_mode_guard()
165177
}
166-
}
178+
}*/
167179
168180
impl<T: ?Sized, R: Deref<Target = SpinLock<T, G>>, G: SpinGuardian> Deref
169181
for SpinLockGuard_<T, R, G>
@@ -210,3 +222,4 @@ unsafe impl<T: ?Sized + Sync, R: Deref<Target = SpinLock<T, G>> + Sync, G: SpinG
210222
for SpinLockGuard_<T, R, G>
211223
{
212224
}
225+
*/

specs/ostd/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ check_lifetime = true
2525
[dependencies]
2626
vstd = { workspace = true, optional = true }
2727
vstd_extra = { path = "../../vstd_extra" }
28-
aster_common = { path = "../../aster_common" }
28+
aster_common = { path = "../../aster_common" }

specs/ostd/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#![allow(non_snake_case)]
12
mod linked_list_specs;
23
mod meta_specs;
34
mod page_table_cursor_specs;
45
mod memory_region_specs;
6+
mod sync;
57
mod page_table_node_specs;
68

79
pub use linked_list_specs::*;

0 commit comments

Comments
 (0)