From: Jonas Oberhauser <jonas.oberhauser(a)huawei.com>
This the update and fixes for memory model, simplify the model by
removing redundancies, making semantics of seq-cst explicit, making ppo
a subset of po, making ppo locally computable, as well as eliminating
several spurious bugs in qspinlock and litmus tests, and ensuring
correct compilation to the official power model.
These issues were detected by Jonas Oberhauser, Viktor Vafeiadis,
and the authors of "Verifying and Optimizing Compact NUMA-Aware Locks
on Weak Memory Models", and the solutions are proposed by Jonas
Oberhauser and Viktor Vafeiadis.
Signed-off-by: Jonas Oberhauser <jonas.oberhauser(a)huawei.com>
Signed-off-by: Hanjun Guo <guohanjun(a)huawei.com>
---
tools/memory-model/linux-kernel.bell | 9 ++--
tools/memory-model/linux-kernel.cat | 100 +++++++++++++++++++----------------
2 files changed, 60 insertions(+), 49 deletions(-)
diff --git a/tools/memory-model/linux-kernel.bell b/tools/memory-model/linux-kernel.bell
index 5be86b1..880b28b 100644
--- a/tools/memory-model/linux-kernel.bell
+++ b/tools/memory-model/linux-kernel.bell
@@ -4,6 +4,8 @@
* Copyright (C) 2016 Luc Maranget <luc.maranget(a)inria.fr> for Inria
* Copyright (C) 2017 Alan Stern <stern(a)rowland.harvard.edu>,
* Andrea Parri <parri.andrea(a)gmail.com>
+ * Copyright (C) 2022 Jonas Oberhauser <jonas.oberhauser(a)huawei.com>
+ * Viktor Vafeiadis <viktor(a)mpi-sws.org>
*
* An earlier version of this file appeared in the companion webpage for
* "Frightening small children and disconcerting grown-ups: Concurrency
@@ -16,10 +18,11 @@
enum Accesses = 'once (*READ_ONCE,WRITE_ONCE*) ||
'release (*smp_store_release*) ||
'acquire (*smp_load_acquire*) ||
+ 'seq-cst (*smp_load, xchg...*) ||
'noreturn (* R of non-return RMW *)
-instructions R[{'once,'acquire,'noreturn}]
-instructions W[{'once,'release}]
-instructions RMW[{'once,'acquire,'release}]
+instructions R[{'seq-cst, 'once,'acquire,'noreturn}]
+instructions W[{'seq-cst, 'once,'release}]
+instructions RMW[{'seq-cst, 'once,'acquire,'release}]
enum Barriers = 'wmb (*smp_wmb*) ||
'rmb (*smp_rmb*) ||
diff --git a/tools/memory-model/linux-kernel.cat b/tools/memory-model/linux-kernel.cat
index d70315f..9f14d31 100644
--- a/tools/memory-model/linux-kernel.cat
+++ b/tools/memory-model/linux-kernel.cat
@@ -4,6 +4,8 @@
* Copyright (C) 2016 Luc Maranget <luc.maranget(a)inria.fr> for Inria
* Copyright (C) 2017 Alan Stern <stern(a)rowland.harvard.edu>,
* Andrea Parri <parri.andrea(a)gmail.com>
+ * Copyright (C) 2022 Jonas Oberhauser <jonas.oberhauser(a)huawei.com>,
+ * Viktor Vafeiadis <viktor(a)mpi-sws.org>
*
* An earlier version of this file appeared in the companion webpage for
* "Frightening small children and disconcerting grown-ups: Concurrency
@@ -25,25 +27,33 @@ include "lock.cat"
(*******************)
(* Release Acquire *)
+
let acq-po = [Acquire] ; po ; [M]
let po-rel = [M] ; po ; [Release]
let po-unlock-lock-po = po ; [UL] ; (po|rf) ; [LKR] ; po
(* Fences *)
-let R4rmb = R \ Noreturn (* Reads for which rmb works *)
-let rmb = [R4rmb] ; fencerel(Rmb) ; [R4rmb]
-let wmb = [W] ; fencerel(Wmb) ; [W]
-let mb = ([M] ; fencerel(Mb) ; [M]) |
- ([M] ; fencerel(Before-atomic) ; [RMW] ; po? ; [M]) |
- ([M] ; po? ; [RMW] ; fencerel(After-atomic) ; [M]) |
- ([M] ; po? ; [LKW] ; fencerel(After-spinlock) ; [M]) |
- ([M] ; po ; [UL] ; (co | po) ; [LKW] ;
- fencerel(After-unlock-lock) ; [M])
-let gp = po ; [Sync-rcu | Sync-srcu] ; po?
-let strong-fence = mb | gp
-
+let R4rmb = R \ Noreturn
+let rmb = [R4rmb] ; po ; [Rmb] ; po ; [R4rmb]
+let wmb = [W] ; po ; [Wmb] ; po ; [W]
+
+let rmb-plain = [R \ Noreturn] ; po ; [Rmb] ; po \ ( po ; [W] ; po-loc) ; [R \ Noreturn]
+let plain-wmb = [W] ; po \ (po-loc ; [W] ; po) ; [Wmb] ; po ; [W]
+let strong-fence =
+ [M] ; po ; [Mb] ; po ; [M]
+ | [M] ; po ; [Before-atomic] ; po ; [RMW] ; po? ; [M]
+ | [M] ; po? ; [RMW] ; po ; [After-atomic] ; po ; [M]
+ | [M] ; po? ; [LKW] ; po ; [After-spinlock] ; po ; [M]
+ | [M] ; po ; [UL] ; po ; [LKR] ; po ; [After-unlock-lock] ; po ; [M]
+ | [M] ; po? ; [SC] ; po ; [M]
+ | [M] ; po ; [SC] ; po? ; [M]
+ | po ; [Sync-rcu | Sync-srcu] ; po?
+let strong-sync = strong-fence
+ | ([M] ; po-unlock-lock-po ; [After-unlock-lock] ; po ; [M])
let nonrw-fence = strong-fence | po-rel | acq-po
let fence = nonrw-fence | wmb | rmb
+
+
let barrier = fencerel(Barrier | Rmb | Wmb | Mb | Sync-rcu | Sync-srcu |
Before-atomic | After-atomic | Acquire | Release |
Rcu-lock | Rcu-unlock | Srcu-lock | Srcu-unlock) |
@@ -64,35 +74,33 @@ empty rmw & (fre ; coe) as atomic
(* Instruction execution ordering *)
(**********************************)
+
(* Preserved Program Order *)
-let dep = addr | data
-let rwdep = (dep | ctrl) ; [W]
-let overwrite = co | fr
-let to-w = rwdep | (overwrite & int) | (addr ; [Plain] ; wmb)
-let to-r = addr | (dep ; [Marked] ; rfi)
-let ppo = to-r | to-w | fence | (po-unlock-lock-po & int)
+let dop = rmb-plain? ; (addr | data | ctrl | rfi)+; plain-wmb?
+let to-w = (dop | po-loc) ; [W]
+let lrs = ([W] ; po-loc ; [R]) \ (po-loc ; [W] ; po-loc)
+let to-r = addr | ((addr | data) ; lrs)
+let ppo = to-r | to-w | fence | (po ; [UL] ; po ; [LKR] ; po)
(* Propagation: Ordering from release operations and strong fences. *)
-let A-cumul(r) = (rfe ; [Marked])? ; r
-let cumul-fence = [Marked] ; (A-cumul(strong-fence | po-rel) | wmb |
- po-unlock-lock-po) ; [Marked]
-let prop = [Marked] ; (overwrite & ext)? ; cumul-fence* ;
- [Marked] ; rfe? ; [Marked]
+let cumul-fence = [Marked] ; (rfe? ; (po-rel ; (rfe ; rmw)*) | wmb | po-unlock-lock-po) ; [Marked]
+let prop = [Marked] ; ((co | fr) & ext) ; cumul-fence* ; [Marked] ; rfe? ; [Marked]
+
(*
* Happens Before: Ordering from the passage of time.
- * No fences needed here for prop because relation confined to one process.
*)
-let hb = [Marked] ; (ppo | rfe | ((prop \ id) & int)) ; [Marked]
-acyclic hb as happens-before
+let hb = [Marked] ; (ppo | rfe | prop ; strong-sync) ; [Marked]
+acyclic hb
+
+(* No fences needed here for prop because relation confined to one process. *)
+irreflexive (prop ; ppo*)
+
+
+
+
-(****************************************)
-(* Write and fence propagation ordering *)
-(****************************************)
-(* Propagation: Each non-rf link needs a strong fence. *)
-let pb = prop ; strong-fence ; hb* ; [Marked]
-acyclic pb as propagation
(*******)
(* RCU *)
@@ -118,7 +126,7 @@ let srcu-rscsi = srcu-rscs^-1
* one but two non-rf relations, but only in conjunction with an RCU
* read-side critical section.
*)
-let rcu-link = po? ; hb* ; pb* ; prop ; po
+let rcu-link = po? ; hb* ; prop? ; po
(*
* Any sequence containing at least as many grace periods as RCU read-side
@@ -139,20 +147,20 @@ let rec rcu-order = rcu-gp | srcu-gp |
((srcu-rscsi ; rcu-link ; rcu-order ; rcu-link ; srcu-gp) & loc) |
(rcu-order ; rcu-link ; rcu-order)
let rcu-fence = po ; rcu-order ; po?
-let fence = fence | rcu-fence
-let strong-fence = strong-fence | rcu-fence
+let fence-rcu = fence | rcu-fence
+let strong-sync-rcu = strong-sync | rcu-fence
-(* rb orders instructions just as pb does *)
-let rb = prop ; rcu-fence ; hb* ; pb* ; [Marked]
+(* rb orders instructions just as hb does *)
+let rb = prop? ; rcu-fence ; hb* ; [Marked]
irreflexive rb as rcu
(*
- * The happens-before, propagation, and rcu constraints are all
+ * The happens-before and rcu constraints are all
* expressions of temporal ordering. They could be replaced by
* a single constraint on an "executes-before" relation, xb:
*
- * let xb = hb | pb | rb
+ * let xb = hb | rb
* acyclic xb as executes-before
*)
@@ -166,24 +174,24 @@ let mixed-accesses = ([Plain & W] ; (po-loc \ barrier) ; [Marked]) |
flag ~empty mixed-accesses as mixed-accesses
(* Executes-before and visibility *)
-let xbstar = (hb | pb | rb)*
+let xbstar = (hb | rb)*
let vis = cumul-fence* ; rfe? ; [Marked] ;
- ((strong-fence ; [Marked] ; xbstar) | (xbstar & int))
+ ((strong-sync-rcu ; [Marked] ; xbstar) | (xbstar & int))
(* Boundaries for lifetimes of plain accesses *)
-let w-pre-bounded = [Marked] ; (addr | fence)?
+let w-pre-bounded = [Marked] ; (addr | fence-rcu)?
let r-pre-bounded = [Marked] ; (addr | nonrw-fence |
([R4rmb] ; fencerel(Rmb) ; [~Noreturn]))?
-let w-post-bounded = fence? ; [Marked]
+let w-post-bounded = fence-rcu? ; [Marked]
let r-post-bounded = (nonrw-fence | ([~Noreturn] ; fencerel(Rmb) ; [R4rmb]))? ;
[Marked]
(* Visibility and executes-before for plain accesses *)
-let ww-vis = fence | (strong-fence ; xbstar ; w-pre-bounded) |
+let ww-vis = (strong-sync-rcu ; xbstar ; w-pre-bounded) |
(w-post-bounded ; vis ; w-pre-bounded)
-let wr-vis = fence | (strong-fence ; xbstar ; r-pre-bounded) |
+let wr-vis = (strong-sync-rcu ; xbstar ; r-pre-bounded) |
(w-post-bounded ; vis ; r-pre-bounded)
-let rw-xbstar = fence | (r-post-bounded ; xbstar ; w-pre-bounded)
+let rw-xbstar = (r-post-bounded ; xbstar ; w-pre-bounded)
(* Potential races *)
let pre-race = ext & ((Plain * M) | ((M \ IW) * Plain))
--
1.7.12.4