xref: /openbmc/linux/tools/memory-model/linux-kernel.cat (revision 1a00b4554d477f05199e22ee71ba4c2525ca44cb)
11c27b644SPaul E. McKenney// SPDX-License-Identifier: GPL-2.0+
21c27b644SPaul E. McKenney(*
31c27b644SPaul E. McKenney * Copyright (C) 2015 Jade Alglave <j.alglave@ucl.ac.uk>,
41c27b644SPaul E. McKenney * Copyright (C) 2016 Luc Maranget <luc.maranget@inria.fr> for Inria
51c27b644SPaul E. McKenney * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu>,
61c27b644SPaul E. McKenney *                    Andrea Parri <parri.andrea@gmail.com>
71c27b644SPaul E. McKenney *
8*1a00b455SAndrea Parri * An earlier version of this file appeared in the companion webpage for
91c27b644SPaul E. McKenney * "Frightening small children and disconcerting grown-ups: Concurrency
101c27b644SPaul E. McKenney * in the Linux kernel" by Alglave, Maranget, McKenney, Parri, and Stern,
11*1a00b455SAndrea Parri * which appeared in ASPLOS 2018.
121c27b644SPaul E. McKenney *)
131c27b644SPaul E. McKenney
1448d44d4eSAndrea Parri"Linux-kernel memory consistency model"
151c27b644SPaul E. McKenney
161c27b644SPaul E. McKenney(*
171c27b644SPaul E. McKenney * File "lock.cat" handles locks and is experimental.
181c27b644SPaul E. McKenney * It can be replaced by include "cos.cat" for tests that do not use locks.
191c27b644SPaul E. McKenney *)
201c27b644SPaul E. McKenney
211c27b644SPaul E. McKenneyinclude "lock.cat"
221c27b644SPaul E. McKenney
231c27b644SPaul E. McKenney(*******************)
241c27b644SPaul E. McKenney(* Basic relations *)
251c27b644SPaul E. McKenney(*******************)
261c27b644SPaul E. McKenney
271c27b644SPaul E. McKenney(* Fences *)
281c27b644SPaul E. McKenneylet rmb = [R \ Noreturn] ; fencerel(Rmb) ; [R \ Noreturn]
291c27b644SPaul E. McKenneylet wmb = [W] ; fencerel(Wmb) ; [W]
301c27b644SPaul E. McKenneylet mb = ([M] ; fencerel(Mb) ; [M]) |
31cac79a39SPaul E. McKenney	([M] ; fencerel(Before-atomic) ; [RMW] ; po? ; [M]) |
32cac79a39SPaul E. McKenney	([M] ; po? ; [RMW] ; fencerel(After-atomic) ; [M]) |
33cac79a39SPaul E. McKenney	([M] ; po? ; [LKW] ; fencerel(After-spinlock) ; [M])
341c27b644SPaul E. McKenneylet gp = po ; [Sync-rcu] ; po?
351c27b644SPaul E. McKenney
361c27b644SPaul E. McKenneylet strong-fence = mb | gp
371c27b644SPaul E. McKenney
381c27b644SPaul E. McKenney(* Release Acquire *)
391c27b644SPaul E. McKenneylet acq-po = [Acquire] ; po ; [M]
401c27b644SPaul E. McKenneylet po-rel = [M] ; po ; [Release]
411c27b644SPaul E. McKenneylet rfi-rel-acq = [Release] ; rfi ; [Acquire]
421c27b644SPaul E. McKenney
431c27b644SPaul E. McKenney(**********************************)
441c27b644SPaul E. McKenney(* Fundamental coherence ordering *)
451c27b644SPaul E. McKenney(**********************************)
461c27b644SPaul E. McKenney
471c27b644SPaul E. McKenney(* Sequential Consistency Per Variable *)
481c27b644SPaul E. McKenneylet com = rf | co | fr
491c27b644SPaul E. McKenneyacyclic po-loc | com as coherence
501c27b644SPaul E. McKenney
511c27b644SPaul E. McKenney(* Atomic Read-Modify-Write *)
521c27b644SPaul E. McKenneyempty rmw & (fre ; coe) as atomic
531c27b644SPaul E. McKenney
541c27b644SPaul E. McKenney(**********************************)
551c27b644SPaul E. McKenney(* Instruction execution ordering *)
561c27b644SPaul E. McKenney(**********************************)
571c27b644SPaul E. McKenney
581c27b644SPaul E. McKenney(* Preserved Program Order *)
591c27b644SPaul E. McKenneylet dep = addr | data
601c27b644SPaul E. McKenneylet rwdep = (dep | ctrl) ; [W]
611c27b644SPaul E. McKenneylet overwrite = co | fr
621c27b644SPaul E. McKenneylet to-w = rwdep | (overwrite & int)
63bf28ae56SAlan Sternlet to-r = addr | (dep ; rfi) | rfi-rel-acq
641c27b644SPaul E. McKenneylet fence = strong-fence | wmb | po-rel | rmb | acq-po
65bf28ae56SAlan Sternlet ppo = to-r | to-w | fence
661c27b644SPaul E. McKenney
671c27b644SPaul E. McKenney(* Propagation: Ordering from release operations and strong fences. *)
681c27b644SPaul E. McKenneylet A-cumul(r) = rfe? ; r
691c27b644SPaul E. McKenneylet cumul-fence = A-cumul(strong-fence | po-rel) | wmb
701c27b644SPaul E. McKenneylet prop = (overwrite & ext)? ; cumul-fence* ; rfe?
711c27b644SPaul E. McKenney
721c27b644SPaul E. McKenney(*
731c27b644SPaul E. McKenney * Happens Before: Ordering from the passage of time.
741c27b644SPaul E. McKenney * No fences needed here for prop because relation confined to one process.
751c27b644SPaul E. McKenney *)
761c27b644SPaul E. McKenneylet hb = ppo | rfe | ((prop \ id) & int)
771c27b644SPaul E. McKenneyacyclic hb as happens-before
781c27b644SPaul E. McKenney
791c27b644SPaul E. McKenney(****************************************)
801c27b644SPaul E. McKenney(* Write and fence propagation ordering *)
811c27b644SPaul E. McKenney(****************************************)
821c27b644SPaul E. McKenney
831c27b644SPaul E. McKenney(* Propagation: Each non-rf link needs a strong fence. *)
841c27b644SPaul E. McKenneylet pb = prop ; strong-fence ; hb*
851c27b644SPaul E. McKenneyacyclic pb as propagation
861c27b644SPaul E. McKenney
871c27b644SPaul E. McKenney(*******)
881c27b644SPaul E. McKenney(* RCU *)
891c27b644SPaul E. McKenney(*******)
901c27b644SPaul E. McKenney
911c27b644SPaul E. McKenney(*
921c27b644SPaul E. McKenney * Effect of read-side critical section proceeds from the rcu_read_lock()
931c27b644SPaul E. McKenney * onward on the one hand and from the rcu_read_unlock() backwards on the
941c27b644SPaul E. McKenney * other hand.
951c27b644SPaul E. McKenney *)
961c27b644SPaul E. McKenneylet rscs = po ; crit^-1 ; po?
971c27b644SPaul E. McKenney
981c27b644SPaul E. McKenney(*
991c27b644SPaul E. McKenney * The synchronize_rcu() strong fence is special in that it can order not
1001c27b644SPaul E. McKenney * one but two non-rf relations, but only in conjunction with an RCU
1011c27b644SPaul E. McKenney * read-side critical section.
1021c27b644SPaul E. McKenney *)
1031ee2da5fSAlan Sternlet rcu-link = hb* ; pb* ; prop
1041c27b644SPaul E. McKenney
1051c27b644SPaul E. McKenney(*
1069d036883SAlan Stern * Any sequence containing at least as many grace periods as RCU read-side
1079d036883SAlan Stern * critical sections (joined by rcu-link) acts as a generalized strong fence.
1081c27b644SPaul E. McKenney *)
1099d036883SAlan Sternlet rec rcu-fence = gp |
1109d036883SAlan Stern	(gp ; rcu-link ; rscs) |
1119d036883SAlan Stern	(rscs ; rcu-link ; gp) |
1129d036883SAlan Stern	(gp ; rcu-link ; rcu-fence ; rcu-link ; rscs) |
1139d036883SAlan Stern	(rscs ; rcu-link ; rcu-fence ; rcu-link ; gp) |
1149d036883SAlan Stern	(rcu-fence ; rcu-link ; rcu-fence)
1159d036883SAlan Stern
1169d036883SAlan Stern(* rb orders instructions just as pb does *)
1179d036883SAlan Sternlet rb = prop ; rcu-fence ; hb* ; pb*
1181c27b644SPaul E. McKenney
1191ee2da5fSAlan Sternirreflexive rb as rcu
1209d036883SAlan Stern
1219d036883SAlan Stern(*
1229d036883SAlan Stern * The happens-before, propagation, and rcu constraints are all
1239d036883SAlan Stern * expressions of temporal ordering.  They could be replaced by
1249d036883SAlan Stern * a single constraint on an "executes-before" relation, xb:
1259d036883SAlan Stern *
1269d036883SAlan Stern * let xb = hb | pb | rb
1279d036883SAlan Stern * acyclic xb as executes-before
1289d036883SAlan Stern *)
129