dm: dm-zoned: use __bio_add_page for adding single metadata page
[linux-block.git] / tools / memory-model / linux-kernel.cat
CommitLineData
1c27b644
PM
1// SPDX-License-Identifier: GPL-2.0+
2(*
3 * Copyright (C) 2015 Jade Alglave <j.alglave@ucl.ac.uk>,
4 * Copyright (C) 2016 Luc Maranget <luc.maranget@inria.fr> for Inria
5 * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu>,
6 * Andrea Parri <parri.andrea@gmail.com>
7 *
1a00b455 8 * An earlier version of this file appeared in the companion webpage for
1c27b644
PM
9 * "Frightening small children and disconcerting grown-ups: Concurrency
10 * in the Linux kernel" by Alglave, Maranget, McKenney, Parri, and Stern,
1a00b455 11 * which appeared in ASPLOS 2018.
1c27b644
PM
12 *)
13
48d44d4e 14"Linux-kernel memory consistency model"
1c27b644
PM
15
16(*
17 * File "lock.cat" handles locks and is experimental.
18 * It can be replaced by include "cos.cat" for tests that do not use locks.
19 *)
20
21include "lock.cat"
22
23(*******************)
24(* Basic relations *)
25(*******************)
26
4494dd58
AS
27(* Release Acquire *)
28let acq-po = [Acquire] ; po ; [M]
29let po-rel = [M] ; po ; [Release]
ddfe1294 30let po-unlock-lock-po = po ; [UL] ; (po|rf) ; [LKR] ; po
4494dd58 31
1c27b644 32(* Fences *)
4494dd58
AS
33let R4rmb = R \ Noreturn (* Reads for which rmb works *)
34let rmb = [R4rmb] ; fencerel(Rmb) ; [R4rmb]
1c27b644
PM
35let wmb = [W] ; fencerel(Wmb) ; [W]
36let mb = ([M] ; fencerel(Mb) ; [M]) |
cac79a39
PM
37 ([M] ; fencerel(Before-atomic) ; [RMW] ; po? ; [M]) |
38 ([M] ; po? ; [RMW] ; fencerel(After-atomic) ; [M]) |
5b735eb1 39 ([M] ; po? ; [LKW] ; fencerel(After-spinlock) ; [M]) |
dd409de2
JO
40(*
41 * Note: The po-unlock-lock-po relation only passes the lock to the direct
42 * successor, perhaps giving the impression that the ordering of the
43 * smp_mb__after_unlock_lock() fence only affects a single lock handover.
44 * However, in a longer sequence of lock handovers, the implicit
45 * A-cumulative release fences of lock-release ensure that any stores that
46 * propagate to one of the involved CPUs before it hands over the lock to
47 * the next CPU will also propagate to the final CPU handing over the lock
48 * to the CPU that executes the fence. Therefore, all those stores are
49 * also affected by the fence.
50 *)
51 ([M] ; po-unlock-lock-po ;
02bae7a2
PM
52 [After-unlock-lock] ; po ; [M]) |
53 ([M] ; po? ; [Srcu-unlock] ; fencerel(After-srcu-read-unlock) ; [M])
a3f600d9 54let gp = po ; [Sync-rcu | Sync-srcu] ; po?
1c27b644
PM
55let strong-fence = mb | gp
56
4494dd58
AS
57let nonrw-fence = strong-fence | po-rel | acq-po
58let fence = nonrw-fence | wmb | rmb
0031e38a 59let barrier = fencerel(Barrier | Rmb | Wmb | Mb | Sync-rcu | Sync-srcu |
f9de4171
AS
60 Before-atomic | After-atomic | Acquire | Release |
61 Rcu-lock | Rcu-unlock | Srcu-lock | Srcu-unlock) |
0031e38a 62 (po ; [Release]) | ([Acquire] ; po)
1c27b644
PM
63
64(**********************************)
65(* Fundamental coherence ordering *)
66(**********************************)
67
68(* Sequential Consistency Per Variable *)
69let com = rf | co | fr
70acyclic po-loc | com as coherence
71
72(* Atomic Read-Modify-Write *)
73empty rmw & (fre ; coe) as atomic
74
75(**********************************)
76(* Instruction execution ordering *)
77(**********************************)
78
79(* Preserved Program Order *)
80let dep = addr | data
81let rwdep = (dep | ctrl) ; [W]
82let overwrite = co | fr
0031e38a 83let to-w = rwdep | (overwrite & int) | (addr ; [Plain] ; wmb)
aa568c26 84let to-r = (addr ; [R]) | (dep ; [Marked] ; rfi)
762e9357 85let ppo = to-r | to-w | (fence & int) | (po-unlock-lock-po & int)
1c27b644
PM
86
87(* Propagation: Ordering from release operations and strong fences. *)
d1a84ab1 88let A-cumul(r) = (rfe ; [Marked])? ; r
ebd50e29 89let rmw-sequence = (rf ; rmw)*
d1a84ab1 90let cumul-fence = [Marked] ; (A-cumul(strong-fence | po-rel) | wmb |
ebd50e29 91 po-unlock-lock-po) ; [Marked] ; rmw-sequence
d1a84ab1
AS
92let prop = [Marked] ; (overwrite & ext)? ; cumul-fence* ;
93 [Marked] ; rfe? ; [Marked]
1c27b644
PM
94
95(*
96 * Happens Before: Ordering from the passage of time.
97 * No fences needed here for prop because relation confined to one process.
98 *)
d1a84ab1 99let hb = [Marked] ; (ppo | rfe | ((prop \ id) & int)) ; [Marked]
1c27b644
PM
100acyclic hb as happens-before
101
102(****************************************)
103(* Write and fence propagation ordering *)
104(****************************************)
105
106(* Propagation: Each non-rf link needs a strong fence. *)
d1a84ab1 107let pb = prop ; strong-fence ; hb* ; [Marked]
1c27b644
PM
108acyclic pb as propagation
109
110(*******)
111(* RCU *)
112(*******)
113
114(*
284749b0 115 * Effects of read-side critical sections proceed from the rcu_read_unlock()
a3f600d9
AS
116 * or srcu_read_unlock() backwards on the one hand, and from the
117 * rcu_read_lock() or srcu_read_lock() forwards on the other hand.
284749b0
AS
118 *
119 * In the definition of rcu-fence below, the po term at the left-hand side
120 * of each disjunct and the po? term at the right-hand end have been factored
121 * out. They have been moved into the definitions of rcu-link and rb.
a3f600d9 122 * This was necessary in order to apply the "& loc" tests correctly.
1c27b644 123 *)
284749b0 124let rcu-gp = [Sync-rcu] (* Compare with gp *)
a3f600d9 125let srcu-gp = [Sync-srcu]
284749b0 126let rcu-rscsi = rcu-rscs^-1
a3f600d9 127let srcu-rscsi = srcu-rscs^-1
1c27b644
PM
128
129(*
130 * The synchronize_rcu() strong fence is special in that it can order not
131 * one but two non-rf relations, but only in conjunction with an RCU
132 * read-side critical section.
133 *)
284749b0 134let rcu-link = po? ; hb* ; pb* ; prop ; po
1c27b644 135
1c27b644 136(*
9d036883 137 * Any sequence containing at least as many grace periods as RCU read-side
15aa25cb
AS
138 * critical sections (joined by rcu-link) induces order like a generalized
139 * inter-CPU strong fence.
a3f600d9
AS
140 * Likewise for SRCU grace periods and read-side critical sections, provided
141 * the synchronize_srcu() and srcu_read_[un]lock() calls refer to the same
142 * struct srcu_struct location.
1c27b644 143 *)
15aa25cb 144let rec rcu-order = rcu-gp | srcu-gp |
284749b0 145 (rcu-gp ; rcu-link ; rcu-rscsi) |
a3f600d9 146 ((srcu-gp ; rcu-link ; srcu-rscsi) & loc) |
284749b0 147 (rcu-rscsi ; rcu-link ; rcu-gp) |
a3f600d9 148 ((srcu-rscsi ; rcu-link ; srcu-gp) & loc) |
15aa25cb
AS
149 (rcu-gp ; rcu-link ; rcu-order ; rcu-link ; rcu-rscsi) |
150 ((srcu-gp ; rcu-link ; rcu-order ; rcu-link ; srcu-rscsi) & loc) |
151 (rcu-rscsi ; rcu-link ; rcu-order ; rcu-link ; rcu-gp) |
152 ((srcu-rscsi ; rcu-link ; rcu-order ; rcu-link ; srcu-gp) & loc) |
153 (rcu-order ; rcu-link ; rcu-order)
154let rcu-fence = po ; rcu-order ; po?
155let fence = fence | rcu-fence
156let strong-fence = strong-fence | rcu-fence
9d036883
AS
157
158(* rb orders instructions just as pb does *)
15aa25cb 159let rb = prop ; rcu-fence ; hb* ; pb* ; [Marked]
1c27b644 160
1ee2da5f 161irreflexive rb as rcu
9d036883
AS
162
163(*
164 * The happens-before, propagation, and rcu constraints are all
165 * expressions of temporal ordering. They could be replaced by
166 * a single constraint on an "executes-before" relation, xb:
167 *
168 * let xb = hb | pb | rb
169 * acyclic xb as executes-before
170 *)
0031e38a
AS
171
172(*********************************)
173(* Plain accesses and data races *)
174(*********************************)
175
176(* Warn about plain writes and marked accesses in the same region *)
177let mixed-accesses = ([Plain & W] ; (po-loc \ barrier) ; [Marked]) |
178 ([Marked] ; (po-loc \ barrier) ; [Plain & W])
179flag ~empty mixed-accesses as mixed-accesses
180
181(* Executes-before and visibility *)
182let xbstar = (hb | pb | rb)*
0031e38a 183let vis = cumul-fence* ; rfe? ; [Marked] ;
15aa25cb 184 ((strong-fence ; [Marked] ; xbstar) | (xbstar & int))
0031e38a
AS
185
186(* Boundaries for lifetimes of plain accesses *)
187let w-pre-bounded = [Marked] ; (addr | fence)?
188let r-pre-bounded = [Marked] ; (addr | nonrw-fence |
189 ([R4rmb] ; fencerel(Rmb) ; [~Noreturn]))?
ebd50e29 190let w-post-bounded = fence? ; [Marked] ; rmw-sequence
0031e38a
AS
191let r-post-bounded = (nonrw-fence | ([~Noreturn] ; fencerel(Rmb) ; [R4rmb]))? ;
192 [Marked]
193
194(* Visibility and executes-before for plain accesses *)
4289ee7d
AS
195let ww-vis = fence | (strong-fence ; xbstar ; w-pre-bounded) |
196 (w-post-bounded ; vis ; w-pre-bounded)
197let wr-vis = fence | (strong-fence ; xbstar ; r-pre-bounded) |
198 (w-post-bounded ; vis ; r-pre-bounded)
199let rw-xbstar = fence | (r-post-bounded ; xbstar ; w-pre-bounded)
0031e38a
AS
200
201(* Potential races *)
202let pre-race = ext & ((Plain * M) | ((M \ IW) * Plain))
203
204(* Coherence requirements for plain accesses *)
205let wr-incoh = pre-race & rf & rw-xbstar^-1
206let rw-incoh = pre-race & fr & wr-vis^-1
207let ww-incoh = pre-race & co & ww-vis^-1
208empty (wr-incoh | rw-incoh | ww-incoh) as plain-coherence
209
210(* Actual races *)
211let ww-nonrace = ww-vis & ((Marked * W) | rw-xbstar) & ((W * Marked) | wr-vis)
212let ww-race = (pre-race & co) \ ww-nonrace
daebf24a 213let wr-race = (pre-race & (co? ; rf)) \ wr-vis \ rw-xbstar^-1
0031e38a
AS
214let rw-race = (pre-race & fr) \ rw-xbstar
215
216flag ~empty (ww-race | wr-race | rw-race) as data-race