Skip to content

Commit 67e1ac0

Browse files
ShaleXIONGShale Xiong
authored andcommitted
Add the fault check functionality related to pte value.
- add `check_fault` and `check_value` fields in `node` structure in `cycle.ml`, ,with default values being `None` for irrelevance. `check_fault` carries a boolean and a string, that is, if the event should fault and a label for the instruction. While `check_value` carries a boolean for if any memory effect check, i.e. read event, should be check. This two new variables enable generating fault and value check when there is previous change to pte or plain values respectively. - Introduce `can_fault` function in `Pteval`, which checks if `valid` is set, i.e., being 1, in AArch64, while always returns `true` for other platform. - In `final.ml` Use the FaultSet in `/lib` to track and rendering the `Fault`, which replace the existing `StringSet` solutions. In particular, there are two `FaultSet` that track postive and negative cases, i.e. `Fault(...)` and `~Fault(...)`. - Modify `AArch64Compile_gen.ml` for printing the label on load and store instruction, when a fault check is needed. The test for postive fault is a variant of `LB.litmus`. That is ``` diyone7 -arch AArch64 -variant kvm PodRW PteVA Rfe PodRW PteVA Rfe ``` This will generate a test: ``` AArch64 A "PodRWPPteVA RfePteVAP PodRWPPteVA RfePteVAP" Generator=diyone7 (version 7.58+1) Prefetch=0:x=F,0:y=W,1:y=F,1:x=W Com=Rf Rf Orig=PodRWPPteVA RfePteVAP PodRWPPteVA RfePteVAP { int y=0; int x=4; 0:X0=x; 0:X2=PTE(y); 0:X3=(oa:PA(y), valid:0); 1:X1=y; 1:X5=PTE(x); 1:X6=(oa:PA(x), valid:0); } P0 | P1 ; L01: | L00: ; LDR W1,[X0] | LDR W4,[X1] ; STR X3,[X2] | STR X6,[X5] ; exists (Fault(P0:L01,x) /\ Fault(P1:L00,y)) ``` that checks if both labelled-`LDR` triggers fault. This is in the same spirit of `catalogue/aarch64/tests/LB.litmus` that both `LDR` observe the the value written by `STR`. Regarding the test for much more common negetive fault, i.e. no fault. ``` diyone7 -arch AArch64 -variant kvm -oneloc PteVA TLBI-sync.ISHsWR Fri ``` This will generate a test: ``` AArch64 A "TLBI-sync.ISHsWRPteVAP FriPPteVA" Generator=diyone7 (version 7.58+1) Com=Fr Orig=TLBI-sync.ISHsWRPteVAP FriPPteVA { int x=0; 0:X0=PTE(x); 0:X1=(oa:PA(x), valid:0); 0:X2=x; } P0 ; STR X1,[X0] ; LSR X4,X2,herd#12 ; DSB ISH ; TLBI VAAE1IS,X4 ; DSB ISH ; L00: ; LDR W3,[X2] ; exists (~Fault(P0:L00,x)) ``` which check if the labelled-`LDR` triggers no fault because does not observe the previous `STR` on the PTE value of variable `x`. Minor improvement: - Merge the accumulators `cell` and `pte_cell` into CoSt `st` in cycle (`cycle.ml`) building, functions `do_set_write_v` and `do_set_read_v`. - Replace a few manual list foldings with a `List.fold_left`. - Add some explanatory comments on some single-latter variables. Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com> Signed-off-by: Shale Xiong <shale.xiong@arm.com,xiongshale@gmail.com>
1 parent da21aa8 commit 67e1ac0

8 files changed

Lines changed: 511 additions & 322 deletions

File tree

gen/AArch64Arch_gen.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,11 @@ let overwrite_value v ao w = match ao with
588588
match a with
589589
| Pte f,None -> do_setpteval a f p
590590
| _ -> Warn.user_error "Atom %s is not a pteval write" (pp_atom a)
591+
592+
let can_fault pte_val =
593+
let open AArch64PteVal in
594+
pte_val.valid = 0
595+
591596
end
592597

593598
(* Wide accesses *)

gen/AArch64Compile_gen.ml

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
229229
let cbz r1 lbl = I_CBZ (vloc,r1,BranchTarget.Lbl lbl)
230230
let do_cbnz v r1 lbl = I_CBNZ (v,r1,BranchTarget.Lbl lbl)
231231
let cbnz = do_cbnz vloc
232+
let is_branch l = match l with
233+
| Instruction ins -> begin match ins with
234+
| I_CBZ _|I_CBNZ _|I_TBNZ _|I_TBZ _|I_BR _|I_BLR _|I_RET _ -> true
235+
| _ -> false
236+
end
237+
| _ -> false
232238

233239
let do_cmpi v r i = op3i v SUBS ZR r i
234240
let cmpi r i = do_cmpi vloc r i
@@ -1723,7 +1729,35 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
17231729

17241730
let get_tagged_loc e = add_tag (as_data e.C.loc) e.C.tag
17251731

1726-
let emit_access st p init e =
1732+
let add_label_to_last_instructions e cs =
1733+
match e.C.check_fault with
1734+
| Some (label_name, _) ->
1735+
let rec do_rec = function
1736+
| [] -> assert false (* the `cs` should not be empty *)
1737+
| [instr] -> [Label(label_name, instr)]
1738+
| [instr;branch_instr] when is_branch branch_instr ->
1739+
[Label(label_name, instr);branch_instr]
1740+
| instr::rem -> instr::do_rec rem in
1741+
do_rec cs
1742+
| None -> cs
1743+
1744+
(* If there is a fault label in `e`, add the `index`-th label
1745+
to the first instruction in `cs` *)
1746+
let add_label_to_first_instructions e cs =
1747+
match e.C.check_fault with
1748+
| Some (label_name, _) ->
1749+
(* find the first non-label instruction *)
1750+
let rec do_rec cs = match cs with
1751+
| [] -> assert false (* the `cs` should not be empty *)
1752+
| instr::rem -> begin match instr with
1753+
(* skip label or instruction that is already labelled *)
1754+
| Label(_) -> instr::do_rec rem
1755+
|_ -> Label(label_name, instr)::rem
1756+
end in
1757+
do_rec cs
1758+
| None -> cs
1759+
1760+
let emit_access st p init e =
17271761
(* collapse the value `v` in event `e` to integer *)
17281762
let value = Code.value_to_int e.C.v in
17291763
match e.C.dir,e.C.loc with
@@ -1733,7 +1767,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
17331767
| R,Some (Instr, None) ->
17341768
let r,init,cs,st = LDR.emit_fetch st p init lab in
17351769
Some r,init,cs,st
1736-
(* Plain read from an instruction label is currently not supported,
1770+
(* Plain read from an instruction label is currently not supported,
17371771
but will be implemented in a future patch
17381772
| R, None ->
17391773
let r,init,cs,st = LDR.emit_load st p init lab in
@@ -1757,12 +1791,12 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
17571791
assert (Misc.is_none m) ;
17581792
Some (a,Some (MachSize.S128,0))
17591793
| _ -> Some (a,m) end in
1760-
begin match d,atom with
1794+
let regs,inits,cs,st = begin match d,atom with
17611795
| R,None ->
17621796
let r,init,cs,st = LDR.emit_load st p init loc in
17631797
Some r,init,cs,st
17641798
| R,Some (Acq _,None) ->
1765-
let r,init,cs,st = LDAR.emit_load st p init loc in
1799+
let r,init,cs,st = LDAR.emit_load st p init loc in
17661800
Some r,init,cs,st
17671801
| R,Some (Acq a,Some (sz,o)) ->
17681802
let module L =
@@ -1778,7 +1812,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
17781812
let cs2 = emit_ldr_addon a r in
17791813
Some r,init,cs@pseudo cs2,st
17801814
| R,Some (AcqPc _,None) ->
1781-
let r,init,cs,st = LDAPR.emit_load st p init loc in
1815+
let r,init,cs,st = LDAPR.emit_load st p init loc in
17821816
Some r,init,cs,st
17831817
| R,Some (AcqPc a,Some (sz,o)) ->
17841818
let module L =
@@ -1926,7 +1960,11 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
19261960
let init,cs,st = emit_store st p init loc value in
19271961
None,init,cs,st
19281962
| W,Some (Neon _,Some _) -> assert false
1929-
end
1963+
end in
1964+
(* Add a label to instructions `cs`, when a fault check is required. *)
1965+
(* Add a label to instructions `cs`, when a fault check is required. *)
1966+
let cs = add_label_to_last_instructions e cs in
1967+
regs,inits,cs,st
19301968
(* END of emit_access *)
19311969

19321970
let same_sz sz1 sz2 = match sz1,sz2 with
@@ -1945,7 +1983,6 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
19451983
check_cu (not (A64.do_cu || same_sz szr szw)) ;
19461984
ar,aw
19471985

1948-
19491986
let emit_addr_simple st p init er =
19501987
let rA,init,st = U.next_init st p init (get_tagged_loc er) in
19511988
rA,init,[],st
@@ -1956,6 +1993,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
19561993
let rW,init,csi,st = U.emit_mov st p init (Code.value_to_int ew.C.v) in
19571994
let arw = check_arw_lxsx er ew in
19581995
let init,cs,st = XSingle.emit_pair arw p st init rR rW rA ew in
1996+
let cs = add_label_to_first_instructions er cs in
19591997
rR,init,csi@caddr@cs,st
19601998

19611999
let emit_exch1 = do_emit_exch1 emit_addr_simple
@@ -1968,6 +2006,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
19682006
let arw = check_arw_lxsx er ew in
19692007
let init,cs,st =
19702008
XPair.emit_pair arw p st init (rR1,rR2) (rW1,rW2) rA ew in
2009+
let cs = add_label_to_first_instructions er cs in
19712010
rR1,init,csi@caddr@cs,st
19722011

19732012
let emit_exch22 = do_emit_exch22 emit_addr_simple
@@ -1980,6 +2019,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
19802019
let module X = ExclusivePair(XLoadPair)(XStore) in
19812020
let init,cs,st =
19822021
X.emit_pair arw p st init (rR1,rR2) rW rA ew in
2022+
let cs = add_label_to_first_instructions er cs in
19832023
rR1,init,csi@caddr@cs,st
19842024

19852025
let emit_exch21 = do_emit_exch21 emit_addr_simple
@@ -1993,6 +2033,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
19932033
let module X = ExclusivePair(XLoad)(XStorePair) in
19942034
let init,cs,st =
19952035
X.emit_pair arw p st init rR (rW1,rW2) rA ew in
2036+
let cs = add_label_to_first_instructions er cs in
19962037
rR,init,csi@caddr@cs,st
19972038

19982039
let emit_exch12 = do_emit_exch12 emit_addr_simple
@@ -2053,8 +2094,9 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
20532094
| Some (sz,o) ->
20542095
let rA,cs,st = sumi_addr st rA o in
20552096
cs@[ins_mixed sz a rW rR rA],st in
2097+
let cs = add_label_to_last_instructions er (pseudo cs) in
20562098
let cs2 = emit_ldr_addon opt rR in
2057-
rR,init,csi@csi2@pseudo (cs@cs2),st
2099+
rR,init,(csi@csi2@cs@pseudo cs2),st
20582100

20592101
let do_emit_ldop ins ins_mixed st p init er ew =
20602102
let rA,init,st =
@@ -2079,8 +2121,9 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
20792121
| Some (sz,o) ->
20802122
let rA,cs,st = sumi_addr st rA o in
20812123
cs@[cas_mixed sz a rS rT rA],st in
2124+
let cs = add_label_to_last_instructions er (pseudo cs) in
20822125
let cs2 = emit_ldr_addon opt rS in
2083-
rS,init,csS@csS2@csT@csT2@pseudo (cs@cs2),st
2126+
rS,init,csS@csS2@csT@csT2@cs@pseudo cs2,st
20842127

20852128
let emit_cas st p init er ew =
20862129
let rA,init,st =
@@ -2103,7 +2146,8 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
21032146
| Some (sz,o) ->
21042147
let rA,cs,st = sumi_addr st rA o in
21052148
cs@[stop_mixed op sz a rW rA],st in
2106-
None,init,csi@pseudo cs,st
2149+
let cs = add_label_to_last_instructions er (pseudo cs) in
2150+
None,init,csi@cs,st
21072151

21082152
let emit_stop op st p init er ew =
21092153
let rA,init,st =
@@ -2220,7 +2264,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
22202264
assert (Misc.is_none m) ;
22212265
Some (a,Some (MachSize.S128,0))
22222266
| _ -> Some (a,m) end in
2223-
begin match d,atom with
2267+
let regs,inits,cs,st = begin match d,atom with
22242268
| R,None ->
22252269
let r,init,cs,st =
22262270
LDR.emit_load_idx_var vloc vdep st p init loc r2 in
@@ -2434,8 +2478,10 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
24342478
None,init,pseudo cs0@cs,st
24352479
| W,Some (Neon _,Some _) -> assert false
24362480
| _,Some (Plain _,None) -> assert false
2437-
end
2438-
| _,Code _ -> Warn.fatal "No dependency to code location"
2481+
end in
2482+
(* Add a label to instructions `cs`, when a fault check is required. *)
2483+
regs,inits,(add_label_to_last_instructions e cs),st
2484+
| _,Code _ -> Warn.fatal "No dependency to code location"
24392485
(* END of emit_access_dep_addr *)
24402486

24412487
let emit_addr_dep csel vdep st p init loc rd =
@@ -2497,7 +2543,7 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
24972543
| _ -> Some (a,m) end in
24982544
(* collapse the value `v` in event `e` to integer *)
24992545
let value = Code.value_to_int e.C.v in
2500-
match e.C.dir,e.C.loc with
2546+
let regs,inits,cs,st = match e.C.dir,e.C.loc with
25012547
| None,_ -> Warn.fatal "TODO"
25022548
| Some R,_ -> Warn.fatal "data dependency to load"
25032549
| Some W,Data loc ->
@@ -2645,8 +2691,10 @@ module Make(Cfg:Config) : XXXCompile_gen.S =
26452691
None,init,cs2@cs,st
26462692
| Some (Pair _,Some _) -> assert false
26472693
end
2648-
| _,Code _ -> Warn.fatal "Not Yet (%s,dep_data)" (C.debug_evt e)
2649-
(* END of emit_access_dep_data *)
2694+
(* END of `Some W` *)
2695+
| _,Code _ -> Warn.fatal "Not Yet (%s,dep_data)" (C.debug_evt e) in
2696+
regs,inits,(add_label_to_last_instructions e cs),st
2697+
(* END of emit_access_dep_data *)
26502698

26512699
let is_ctrlisync = function
26522700
| D.CTRLISYNC -> true

gen/CCompile_gen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ module Make(O:Config) : Builder.S
826826
F.run evts m
827827
| Cycle -> F.check f
828828
| Observe -> F.observe f in
829-
(add_args env c,f []),
829+
(add_args env c,f (F.FaultSet.empty,F.FaultSet.empty)),
830830
(U.compile_prefetch_ios (List.length obsc) ios,
831831
U.compile_coms splitted),
832832
env

gen/archExtra_gen.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ module type S = sig
6262

6363
(* complete init with necessary information *)
6464
val complete_init : bool (* hexa *) -> Code.env -> init -> init
65+
val pp_env: init -> string
6566

6667

6768
(***********************)
@@ -189,7 +190,7 @@ and type special3 = I.special3
189190
| None -> "-"
190191
| Some v -> pp_initval v
191192

192-
let _pp_env env =
193+
let pp_env env =
193194
String.concat ", "
194195
(List.map (fun (loc,v) -> pp_location loc ^ "->" ^ ppo v) env)
195196

0 commit comments

Comments
 (0)