Merge tag 'v4.16-rc2' into locking/core, to refresh the branch
[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 *
8 * An earlier version of this file appears in the companion webpage for
9 * "Frightening small children and disconcerting grown-ups: Concurrency
10 * in the Linux kernel" by Alglave, Maranget, McKenney, Parri, and Stern,
11 * which is to appear in ASPLOS 2018.
12 *)
13
14"Linux kernel memory model"
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
27(* Fences *)
28let rb-dep = [R] ; fencerel(Rb_dep) ; [R]
29let rmb = [R \ Noreturn] ; fencerel(Rmb) ; [R \ Noreturn]
30let wmb = [W] ; fencerel(Wmb) ; [W]
31let mb = ([M] ; fencerel(Mb) ; [M]) |
32 ([M] ; fencerel(Before_atomic) ; [RMW] ; po? ; [M]) |
33 ([M] ; po? ; [RMW] ; fencerel(After_atomic) ; [M]) |
34 ([M] ; po? ; [LKW] ; fencerel(After_spinlock) ; [M])
35let gp = po ; [Sync-rcu] ; po?
36
37let strong-fence = mb | gp
38
39(* Release Acquire *)
40let acq-po = [Acquire] ; po ; [M]
41let po-rel = [M] ; po ; [Release]
42let rfi-rel-acq = [Release] ; rfi ; [Acquire]
43
44(**********************************)
45(* Fundamental coherence ordering *)
46(**********************************)
47
48(* Sequential Consistency Per Variable *)
49let com = rf | co | fr
50acyclic po-loc | com as coherence
51
52(* Atomic Read-Modify-Write *)
53empty rmw & (fre ; coe) as atomic
54
55(**********************************)
56(* Instruction execution ordering *)
57(**********************************)
58
59(* Preserved Program Order *)
60let dep = addr | data
61let rwdep = (dep | ctrl) ; [W]
62let overwrite = co | fr
63let to-w = rwdep | (overwrite & int)
64let rrdep = addr | (dep ; rfi)
65let strong-rrdep = rrdep+ & rb-dep
66let to-r = strong-rrdep | rfi-rel-acq
67let fence = strong-fence | wmb | po-rel | rmb | acq-po
68let ppo = rrdep* ; (to-r | to-w | fence)
69
70(* Propagation: Ordering from release operations and strong fences. *)
71let A-cumul(r) = rfe? ; r
72let cumul-fence = A-cumul(strong-fence | po-rel) | wmb
73let prop = (overwrite & ext)? ; cumul-fence* ; rfe?
74
75(*
76 * Happens Before: Ordering from the passage of time.
77 * No fences needed here for prop because relation confined to one process.
78 *)
79let hb = ppo | rfe | ((prop \ id) & int)
80acyclic hb as happens-before
81
82(****************************************)
83(* Write and fence propagation ordering *)
84(****************************************)
85
86(* Propagation: Each non-rf link needs a strong fence. *)
87let pb = prop ; strong-fence ; hb*
88acyclic pb as propagation
89
90(*******)
91(* RCU *)
92(*******)
93
94(*
95 * Effect of read-side critical section proceeds from the rcu_read_lock()
96 * onward on the one hand and from the rcu_read_unlock() backwards on the
97 * other hand.
98 *)
99let rscs = po ; crit^-1 ; po?
100
101(*
102 * The synchronize_rcu() strong fence is special in that it can order not
103 * one but two non-rf relations, but only in conjunction with an RCU
104 * read-side critical section.
105 *)
106let link = hb* ; pb* ; prop
107
108(* Chains that affect the RCU grace-period guarantee *)
109let gp-link = gp ; link
110let rscs-link = rscs ; link
111
112(*
113 * A cycle containing at least as many grace periods as RCU read-side
114 * critical sections is forbidden.
115 *)
116let rec rcu-path =
117 gp-link |
118 (gp-link ; rscs-link) |
119 (rscs-link ; gp-link) |
120 (rcu-path ; rcu-path) |
121 (gp-link ; rcu-path ; rscs-link) |
122 (rscs-link ; rcu-path ; gp-link)
123
124irreflexive rcu-path as rcu