blob: 834107022c506e363cdad9c63b501bac537d7295 [file] [log] [blame]
Paul E. McKenney1c27b642018-01-18 19:58:55 -08001// 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 *
Andrea Parri1a00b4552018-05-14 16:33:56 -07008 * An earlier version of this file appeared in the companion webpage for
Paul E. McKenney1c27b642018-01-18 19:58:55 -08009 * "Frightening small children and disconcerting grown-ups: Concurrency
10 * in the Linux kernel" by Alglave, Maranget, McKenney, Parri, and Stern,
Andrea Parri1a00b4552018-05-14 16:33:56 -070011 * which appeared in ASPLOS 2018.
Paul E. McKenney1c27b642018-01-18 19:58:55 -080012 *)
13
Andrea Parri48d44d42018-02-20 15:25:01 -080014"Linux-kernel memory consistency model"
Paul E. McKenney1c27b642018-01-18 19:58:55 -080015
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
Alan Stern4494dd52019-04-22 12:17:45 -040027(* Release Acquire *)
28let acq-po = [Acquire] ; po ; [M]
29let po-rel = [M] ; po ; [Release]
30let po-unlock-rf-lock-po = po ; [UL] ; rf ; [LKR] ; po
31
Paul E. McKenney1c27b642018-01-18 19:58:55 -080032(* Fences *)
Alan Stern4494dd52019-04-22 12:17:45 -040033let R4rmb = R \ Noreturn (* Reads for which rmb works *)
34let rmb = [R4rmb] ; fencerel(Rmb) ; [R4rmb]
Paul E. McKenney1c27b642018-01-18 19:58:55 -080035let wmb = [W] ; fencerel(Wmb) ; [W]
36let mb = ([M] ; fencerel(Mb) ; [M]) |
Paul E. McKenneycac79a392018-02-20 15:25:11 -080037 ([M] ; fencerel(Before-atomic) ; [RMW] ; po? ; [M]) |
38 ([M] ; po? ; [RMW] ; fencerel(After-atomic) ; [M]) |
Andrea Parri5b735eb2018-12-03 15:04:49 -080039 ([M] ; po? ; [LKW] ; fencerel(After-spinlock) ; [M]) |
40 ([M] ; po ; [UL] ; (co | po) ; [LKW] ;
41 fencerel(After-unlock-lock) ; [M])
Alan Sterna3f600d2018-11-15 11:20:37 -050042let gp = po ; [Sync-rcu | Sync-srcu] ; po?
Paul E. McKenney1c27b642018-01-18 19:58:55 -080043let strong-fence = mb | gp
44
Alan Stern4494dd52019-04-22 12:17:45 -040045let nonrw-fence = strong-fence | po-rel | acq-po
46let fence = nonrw-fence | wmb | rmb
Paul E. McKenney1c27b642018-01-18 19:58:55 -080047
48(**********************************)
49(* Fundamental coherence ordering *)
50(**********************************)
51
52(* Sequential Consistency Per Variable *)
53let com = rf | co | fr
54acyclic po-loc | com as coherence
55
56(* Atomic Read-Modify-Write *)
57empty rmw & (fre ; coe) as atomic
58
59(**********************************)
60(* Instruction execution ordering *)
61(**********************************)
62
63(* Preserved Program Order *)
64let dep = addr | data
65let rwdep = (dep | ctrl) ; [W]
66let overwrite = co | fr
67let to-w = rwdep | (overwrite & int)
Alan Stern6e89e832018-09-26 11:29:17 -070068let to-r = addr | (dep ; rfi)
Alan Stern6e89e832018-09-26 11:29:17 -070069let ppo = to-r | to-w | fence | (po-unlock-rf-lock-po & int)
Paul E. McKenney1c27b642018-01-18 19:58:55 -080070
71(* Propagation: Ordering from release operations and strong fences. *)
72let A-cumul(r) = rfe? ; r
Alan Stern6e89e832018-09-26 11:29:17 -070073let cumul-fence = A-cumul(strong-fence | po-rel) | wmb | po-unlock-rf-lock-po
Paul E. McKenney1c27b642018-01-18 19:58:55 -080074let prop = (overwrite & ext)? ; cumul-fence* ; rfe?
75
76(*
77 * Happens Before: Ordering from the passage of time.
78 * No fences needed here for prop because relation confined to one process.
79 *)
80let hb = ppo | rfe | ((prop \ id) & int)
81acyclic hb as happens-before
82
83(****************************************)
84(* Write and fence propagation ordering *)
85(****************************************)
86
87(* Propagation: Each non-rf link needs a strong fence. *)
88let pb = prop ; strong-fence ; hb*
89acyclic pb as propagation
90
91(*******)
92(* RCU *)
93(*******)
94
95(*
Alan Stern284749b2018-11-15 11:19:58 -050096 * Effects of read-side critical sections proceed from the rcu_read_unlock()
Alan Sterna3f600d2018-11-15 11:20:37 -050097 * or srcu_read_unlock() backwards on the one hand, and from the
98 * rcu_read_lock() or srcu_read_lock() forwards on the other hand.
Alan Stern284749b2018-11-15 11:19:58 -050099 *
100 * In the definition of rcu-fence below, the po term at the left-hand side
101 * of each disjunct and the po? term at the right-hand end have been factored
102 * out. They have been moved into the definitions of rcu-link and rb.
Alan Sterna3f600d2018-11-15 11:20:37 -0500103 * This was necessary in order to apply the "& loc" tests correctly.
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800104 *)
Alan Stern284749b2018-11-15 11:19:58 -0500105let rcu-gp = [Sync-rcu] (* Compare with gp *)
Alan Sterna3f600d2018-11-15 11:20:37 -0500106let srcu-gp = [Sync-srcu]
Alan Stern284749b2018-11-15 11:19:58 -0500107let rcu-rscsi = rcu-rscs^-1
Alan Sterna3f600d2018-11-15 11:20:37 -0500108let srcu-rscsi = srcu-rscs^-1
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800109
110(*
111 * The synchronize_rcu() strong fence is special in that it can order not
112 * one but two non-rf relations, but only in conjunction with an RCU
113 * read-side critical section.
114 *)
Alan Stern284749b2018-11-15 11:19:58 -0500115let rcu-link = po? ; hb* ; pb* ; prop ; po
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800116
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800117(*
Alan Stern9d036882018-05-14 16:33:40 -0700118 * Any sequence containing at least as many grace periods as RCU read-side
119 * critical sections (joined by rcu-link) acts as a generalized strong fence.
Alan Sterna3f600d2018-11-15 11:20:37 -0500120 * Likewise for SRCU grace periods and read-side critical sections, provided
121 * the synchronize_srcu() and srcu_read_[un]lock() calls refer to the same
122 * struct srcu_struct location.
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800123 *)
Alan Sterna3f600d2018-11-15 11:20:37 -0500124let rec rcu-fence = rcu-gp | srcu-gp |
Alan Stern284749b2018-11-15 11:19:58 -0500125 (rcu-gp ; rcu-link ; rcu-rscsi) |
Alan Sterna3f600d2018-11-15 11:20:37 -0500126 ((srcu-gp ; rcu-link ; srcu-rscsi) & loc) |
Alan Stern284749b2018-11-15 11:19:58 -0500127 (rcu-rscsi ; rcu-link ; rcu-gp) |
Alan Sterna3f600d2018-11-15 11:20:37 -0500128 ((srcu-rscsi ; rcu-link ; srcu-gp) & loc) |
Alan Stern284749b2018-11-15 11:19:58 -0500129 (rcu-gp ; rcu-link ; rcu-fence ; rcu-link ; rcu-rscsi) |
Alan Sterna3f600d2018-11-15 11:20:37 -0500130 ((srcu-gp ; rcu-link ; rcu-fence ; rcu-link ; srcu-rscsi) & loc) |
Alan Stern284749b2018-11-15 11:19:58 -0500131 (rcu-rscsi ; rcu-link ; rcu-fence ; rcu-link ; rcu-gp) |
Alan Sterna3f600d2018-11-15 11:20:37 -0500132 ((srcu-rscsi ; rcu-link ; rcu-fence ; rcu-link ; srcu-gp) & loc) |
Alan Stern9d036882018-05-14 16:33:40 -0700133 (rcu-fence ; rcu-link ; rcu-fence)
134
135(* rb orders instructions just as pb does *)
Alan Stern284749b2018-11-15 11:19:58 -0500136let rb = prop ; po ; rcu-fence ; po? ; hb* ; pb*
Paul E. McKenney1c27b642018-01-18 19:58:55 -0800137
Alan Stern1ee2da52018-05-14 16:33:39 -0700138irreflexive rb as rcu
Alan Stern9d036882018-05-14 16:33:40 -0700139
140(*
141 * The happens-before, propagation, and rcu constraints are all
142 * expressions of temporal ordering. They could be replaced by
143 * a single constraint on an "executes-before" relation, xb:
144 *
145 * let xb = hb | pb | rb
146 * acyclic xb as executes-before
147 *)