~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/memory-model/linux-kernel.cat

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/memory-model/linux-kernel.cat (Version linux-6.11.5) and /tools/memory-model/linux-kernel.cat (Version linux-5.4.284)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php