Skip to content

Commit d7a6db6

Browse files
committed
Prove 1 assume in Entry::replace
1 parent 1e5b8bf commit d7a6db6

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

lock-protocol/src/mm/page_table/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,16 @@ Sized {
429429
/// Set the physical address of the PTE.
430430
///
431431
/// This can be done for both present and absent PTEs.
432-
fn set_paddr(&mut self, paddr: Paddr);
432+
fn set_paddr(&mut self, paddr: Paddr)
433+
ensures
434+
self.pte_paddr() == paddr,
435+
self.pte_paddr_spec() == paddr,
436+
self.is_present() == old(self).is_present(),
437+
self.prop() == old(self).prop(),
438+
self.frame_paddr() == old(self).frame_paddr(),
439+
forall|level: PagingLevel| #[trigger]
440+
old(self).is_last_spec(level) <==> self.is_last_spec(level),
441+
;
433442

434443
// It seems we cannot specify a clone spec for a trait in Verus.
435444
fn clone_pte(&self) -> (res: Self)

lock-protocol/src/mm/page_table/node/entry.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use vstd::prelude::*;
2+
use vstd::calc;
23

34
use core::ops::Deref;
45
use std::marker::PhantomData;
@@ -226,12 +227,37 @@ impl<'a, 'rcu, C: PageTableConfig> Entry<'a, 'rcu, C> {
226227
self.pte = new_child.into_pte();
227228

228229
assert(spt.perms.contains_key(self.node.paddr()));
229-
230-
// TODO: should be trivial?
231-
assume(self.pte.pte_paddr_spec() == index_pte_paddr(
232-
self.node.paddr() as int,
233-
self.idx as int,
234-
));
230+
let pte_addr: usize = self.node.paddr() + self.idx * exec::SIZEOF_PAGETABLEENTRY;
231+
self.pte.set_paddr(pte_addr);
232+
proof {
233+
let idx_int = self.idx as int;
234+
let node_pa_int = self.node.paddr() as int;
235+
let size_int = exec::SIZEOF_PAGETABLEENTRY as int;
236+
let computed_addr_int = node_pa_int + idx_int * size_int;
237+
assert(pte_addr as int == computed_addr_int) by {
238+
calc! {
239+
(==)
240+
(pte_addr as int); {}
241+
((self.node.paddr() + self.idx * exec::SIZEOF_PAGETABLEENTRY) as int); {}
242+
(node_pa_int + idx_int * size_int);
243+
}
244+
};
245+
assert(index_pte_paddr(node_pa_int, idx_int) == computed_addr_int) by {
246+
calc! {
247+
(==)
248+
(index_pte_paddr(node_pa_int, idx_int)); {}
249+
(node_pa_int + idx_int * size_int);
250+
}
251+
};
252+
calc! {
253+
(==)
254+
(self.pte.pte_paddr_spec() as int); {}
255+
(self.pte.pte_paddr() as int); {}
256+
(pte_addr as int); {}
257+
computed_addr_int; {}
258+
index_pte_paddr(node_pa_int, idx_int);
259+
}
260+
}
235261
assume(spt.i_ptes.value().contains_key(self.pte.pte_paddr() as int));
236262
self.node.write_pte(
237263
self.idx,

0 commit comments

Comments
 (0)