Skip to content

Commit 4098260

Browse files
committed
Apply code reviews
1 parent 8067e49 commit 4098260

File tree

1 file changed

+74
-74
lines changed

1 file changed

+74
-74
lines changed

ArchSemArm/VMPromising.v

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,8 @@ Module TLB.
870870
(entries : gset (Entry.t (Ctxt.lvl ctxt))) (vatlb : t) : t :=
871871
hset (Ctxt.lvl ctxt) {[(Ctxt.nd ctxt) := entries]} vatlb.
872872

873-
Definition add (ctxt : Ctxt.t) (entry : Entry.t (Ctxt.lvl ctxt)) (vatlb : t) : t :=
873+
Definition insert (ctxt : Ctxt.t) (entry : Entry.t (Ctxt.lvl ctxt))
874+
(vatlb : t) : t :=
874875
let entries := get ctxt vatlb in
875876
hset (Ctxt.lvl ctxt) {[(Ctxt.nd ctxt) := entries ∪ {[ entry ]}]} vatlb.
876877

@@ -917,8 +918,9 @@ Module TLB.
917918
- Reads [ttbr] at [time], checks it is 64-bit.
918919
- Computes root entry address for [va], reads memory.
919920
- If entry is a table, builds a root context with ASID from TTBR
920-
and inserts it into VATLB.
921-
- Otherwise returns empty VATLB. *)
921+
and inserts it into the input VATLB instead of making a new one.
922+
- Returns the new VATLB and the boolean value
923+
if the new VATLB is different from the input *)
922924
Definition va_fill_root (vatlb : VATLB.t) (ts : TState.t)
923925
(init : Memory.initial)
924926
(mem : Memory.t)
@@ -927,8 +929,7 @@ Module TLB.
927929
(ttbr : reg) : result string (VATLB.t * bool) :=
928930
sregs ← othrow "TTBR should exist in initial state"
929931
$ TState.read_sreg_at ts ttbr time;
930-
fold_left (λ prev sreg,
931-
'(vatlb, is_changed) ← prev;
932+
foldlM (λ '(vatlb, is_changed) sreg,
932933
val_ttbr ← othrow "TTBR should be a 64 bit value"
933934
$ regval_to_val ttbr sreg.1;
934935
let entry_addr := next_entry_addr val_ttbr va in
@@ -941,13 +942,13 @@ Module TLB.
941942
let entry : Entry.t (Ctxt.lvl ctxt) := [#memval] in
942943
(* add the entry to vatlb only when it is not in the original vatlb *)
943944
if decide (entry ∉ (VATLB.get ctxt vatlb)) then
944-
Ok (VATLB.add ctxt entry vatlb, true)
945+
Ok (VATLB.insert ctxt entry vatlb, true)
945946
else Ok (vatlb, is_changed)
946947
else
947948
Ok (vatlb, is_changed)
948949
else
949950
Ok (vatlb, is_changed)
950-
) sregs (mret (vatlb, false)).
951+
) (vatlb, false) sregs.
951952

952953
(** Extend one level down from a parent table entry [te].
953954
- Requires [te] ∈ [vatlb] and ASID active for [ttbr].
@@ -984,7 +985,7 @@ Module TLB.
984985
let entry := Entry.append te next_pte (child_lvl_add_one _ _ e) in
985986
(* add the entry to vatlb only when it is not in the original vatlb *)
986987
if decide (entry ∉ (VATLB.get ctxt vatlb)) then
987-
Ok (VATLB.add ctxt entry vatlb, true)
988+
Ok (VATLB.insert ctxt entry vatlb, true)
988989
else Ok (vatlb, false)
989990
| None eq:_ => mthrow "An intermediate level should have a child level"
990991
end
@@ -1093,10 +1094,10 @@ Module TLB.
10931094
Definition tlbi_apply (tlbi : TLBI.t) (tlb : t) : t :=
10941095
set vatlb (filter (λ '(existT ctxt te), affects tlbi ctxt te)) tlb.
10951096

1096-
(** Get the TLB states up until the timestamp along with
1097-
a boolean value that shows if it is different from the previous tlb and
1098-
the timestamp used to compute that state. [list (TLB.t * bool * nat)] *)
1099-
Fixpoint snapshots_until_timestamp (ts : TState.t) (mem_init : Memory.initial)
1097+
(** Get the unique TLB states from [time_prev] to [time_prev + cnt]
1098+
along with their views as a [list (t * nat)].
1099+
The list is sorted in descending order by timestamp. *)
1100+
Fixpoint unique_snapshots_between (ts : TState.t) (mem_init : Memory.initial)
11001101
(mem : Memory.t)
11011102
(tlb_prev : t)
11021103
(time_prev cnt : nat)
@@ -1124,20 +1125,21 @@ Module TLB.
11241125
| true => (tlb, time_cur) :: acc
11251126
| false => acc
11261127
end in
1127-
snapshots_until_timestamp
1128+
unique_snapshots_between
11281129
ts mem_init mem tlb time_cur ccnt va ttbr acc
11291130
end.
11301131

1131-
(** Get the unique TLB states up until the timestamp along with the timestamp
1132-
used to compute that state. [list (TLB.t * nat)] *)
1132+
(** Get the unique TLB states up until the timestamp [time]
1133+
along with their views as a [list (TLB.t * nat)].
1134+
The list is sorted in descending order by timestamp. *)
11331135
Definition unique_snapshots_until_timestamp (ts : TState.t)
11341136
(mem_init : Memory.initial)
11351137
(mem : Memory.t)
11361138
(time : nat)
11371139
(va : bv 64)
11381140
(ttbr : reg) : result string (list (t * nat)) :=
11391141
'(tlb, _) ← update init ts mem_init mem 0 va ttbr;
1140-
snapshots_until_timestamp ts mem_init mem tlb 0 time va ttbr [(tlb, 0)].
1142+
unique_snapshots_between ts mem_init mem tlb 0 time va ttbr [(tlb, 0)].
11411143

11421144
Definition is_te_invalidated_by_tlbi
11431145
(tlbi : TLBI.t)
@@ -1155,7 +1157,7 @@ Module TLB.
11551157
(te : Entry.t (Ctxt.lvl ctxt))
11561158
(evs : list (Ev.t * nat)) : result string (option nat) :=
11571159
match evs with
1158-
| nil => mret None
1160+
| [] => mret None
11591161
| (ev, t) :: tl =>
11601162
match ev with
11611163
| Ev.Tlbi tlbi =>
@@ -1304,6 +1306,59 @@ Module TLB.
13041306
get_invalid_ptes_with_inv_time_by_lvl ts init mem tid tlb time lvl va asid ttbr
13051307
end;
13061308
mret $ List.concat fault_ptes.
1309+
1310+
Definition invalidation_time_lt (ti_old ti_new : option nat) : bool :=
1311+
match ti_old, ti_new with
1312+
| Some ti_old, Some ti_new => ti_old <? ti_new
1313+
| None, None => false
1314+
| None, Some _ => false
1315+
| Some _, None => true
1316+
end.
1317+
1318+
Definition is_new_entry (path : list val) (ti_new : option nat)
1319+
(entries : list (list val * nat * option nat)) : bool :=
1320+
forallb
1321+
(λ '(p, t, ti),
1322+
negb(path =? p) || invalidation_time_lt ti ti_new) entries.
1323+
1324+
(* Snapshots are sorted in the descending order of [trans_time].
1325+
Thus, we do not have to use [trans_time] to check the interval *)
1326+
Definition get_valid_entries_from_snapshots (snapshots : list (t * nat))
1327+
(mem : Memory.t)
1328+
(tid : nat)
1329+
(va : bv 64) (asid : bv 16) :
1330+
result string (list (list val * nat * option nat)) :=
1331+
foldrM (λ '(tlb, trans_time) entries,
1332+
candidates ← TLB.lookup mem tid tlb trans_time va asid;
1333+
let new :=
1334+
omap (λ '(path, ti_opt),
1335+
if decide (is_new_entry path ti_opt entries) then
1336+
Some (path, trans_time, ti_opt)
1337+
else None
1338+
) candidates in
1339+
mret (new ++ entries)
1340+
) snapshots [].
1341+
1342+
Definition get_invalid_entries_from_snapshots (snapshots : list (t * nat))
1343+
(ts : TState.t)
1344+
(init : Memory.initial)
1345+
(mem : Memory.t)
1346+
(tid : nat) (is_ets2 : bool)
1347+
(va : bv 64) (asid : bv 16) (ttbr : reg) :
1348+
result string (list (list val * nat * option nat)) :=
1349+
foldrM (λ '(tlb, trans_time) entries,
1350+
if decide (is_ets2 ∧ trans_time < ts.(TState.vwr) ⊔ ts.(TState.vrd)) then
1351+
mret entries
1352+
else
1353+
candidates ← TLB.get_invalid_ptes_with_inv_time ts init mem tid tlb trans_time va asid ttbr;
1354+
let new :=
1355+
omap (λ '(path, ti_opt),
1356+
if decide (is_new_entry path ti_opt entries) then
1357+
Some (path, trans_time, ti_opt)
1358+
else None
1359+
) candidates in
1360+
mret (new ++ entries)
1361+
) snapshots [].
13071362
End TLB.
13081363
Export (hints) TLB.
13091364

@@ -1683,61 +1738,6 @@ Definition ets3 (ts : TState.t) : result string bool :=
16831738
val ← othrow "The register value of ID_AA64MMFR1_EL1 is 64 bit" (regval_to_val mmfr1 regval);
16841739
mret (bv_extract 36 4 val =? 3%bv).
16851740

1686-
Definition new_invalidation_opt (ti_new ti_old : option nat) : bool :=
1687-
match ti_new, ti_old with
1688-
| Some ti_new, Some ti_old => ti_old <? ti_new
1689-
| None, None => false
1690-
| Some _, None => true
1691-
| None, Some _ => true
1692-
end.
1693-
1694-
Definition is_new_entry (path : list val) (ti_new : option nat)
1695-
(entries : list (list val * nat * option nat)) : bool :=
1696-
forallb
1697-
(λ '(p, t, ti),
1698-
negb(path =? p) || new_invalidation_opt ti_new ti) entries.
1699-
1700-
(* Snapshots are sorted in the descending order of `trans_time`.
1701-
Thus, we do not have to use `trans_time` to check the interval *)
1702-
Definition get_valid_entries_from_snapshots (snapshots : list (TLB.t * nat))
1703-
(mem : Memory.t)
1704-
(tid : nat)
1705-
(va : bv 64) (asid : bv 16) :
1706-
result string (list (list val * nat * option nat)) :=
1707-
fold_right (λ '(tlb, trans_time) entries,
1708-
candidates ← TLB.lookup mem tid tlb trans_time va asid;
1709-
prev ←@{result string} entries;
1710-
let new :=
1711-
omap (λ '(path, ti_opt),
1712-
if decide (is_new_entry path ti_opt prev) then
1713-
Some (path, trans_time, ti_opt)
1714-
else None
1715-
) candidates in
1716-
mret (new ++ prev)
1717-
) (mret nil) snapshots.
1718-
1719-
Definition get_invalid_entries_from_snapshots (snapshots : list (TLB.t * nat))
1720-
(ts : TState.t)
1721-
(init : Memory.initial)
1722-
(mem : Memory.t)
1723-
(tid : nat) (is_ets2 : bool)
1724-
(va : bv 64) (asid : bv 16) (ttbr : reg) :
1725-
result string (list (list val * nat * option nat)) :=
1726-
fold_right (λ '(tlb, trans_time) entries,
1727-
if decide (is_ets2 ∧ trans_time < ts.(TState.vwr) ⊔ ts.(TState.vrd)) then
1728-
entries
1729-
else
1730-
candidates ← TLB.get_invalid_ptes_with_inv_time ts init mem tid tlb trans_time va asid ttbr;
1731-
prev ←@{result string} entries;
1732-
let new :=
1733-
omap (λ '(path, ti_opt),
1734-
if decide (is_new_entry path ti_opt prev) then
1735-
Some (path, trans_time, ti_opt)
1736-
else None
1737-
) candidates in
1738-
mret (new ++ prev)
1739-
) (mret nil) snapshots.
1740-
17411741
Definition run_trans_start (trans_start : TranslationStartInfo)
17421742
(tid : nat) (init : Memory.initial) :
17431743
Exec.t (PPState.t TState.t Ev.t IIS.t) string unit :=
@@ -1758,9 +1758,9 @@ Definition run_trans_start (trans_start : TranslationStartInfo)
17581758
if decide (va_in_range va) then
17591759
ttbr ← mlift $ ttbr_of_regime va trans_start.(TranslationStartInfo_regime);
17601760
snapshots ← mlift $ TLB.unique_snapshots_until_timestamp ts init mem vmax_t va ttbr;
1761-
valid_entries ← mlift $ get_valid_entries_from_snapshots snapshots mem tid va asid;
1761+
valid_entries ← mlift $ TLB.get_valid_entries_from_snapshots snapshots mem tid va asid;
17621762
invalid_entries ← mlift $
1763-
get_invalid_entries_from_snapshots snapshots ts init mem tid is_ets2 va asid ttbr;
1763+
TLB.get_invalid_entries_from_snapshots snapshots ts init mem tid is_ets2 va asid ttbr;
17641764
(* update IIS with either a valid translation result or a fault *)
17651765
let valid_trs :=
17661766
map (λ '(path, t, ti),

0 commit comments

Comments
 (0)