blob: 9c42cd9ddcb41d1f2b30bdb672cf655d0dbb2390 [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
Mark Rutlandaf41db5e2018-07-16 11:05:57 -070016enum Accesses = 'once (*READ_ONCE,WRITE_ONCE*) ||
Paul E. McKenney1c27b642018-01-18 19:58:55 -080017 'release (*smp_store_release*) ||
18 'acquire (*smp_load_acquire*) ||
19 'noreturn (* R of non-return RMW *)
20instructions R[{'once,'acquire,'noreturn}]
21instructions W[{'once,'release}]
22instructions RMW[{'once,'acquire,'release}]
23
24enum Barriers = 'wmb (*smp_wmb*) ||
25 'rmb (*smp_rmb*) ||
26 'mb (*smp_mb*) ||
Paul E. McKenney1c27b642018-01-18 19:58:55 -080027 'rcu-lock (*rcu_read_lock*) ||
28 'rcu-unlock (*rcu_read_unlock*) ||
29 'sync-rcu (*synchronize_rcu*) ||
Paul E. McKenneycac79a32018-02-20 15:25:11 -080030 'before-atomic (*smp_mb__before_atomic*) ||
31 'after-atomic (*smp_mb__after_atomic*) ||
Andrea Parri5b735eb2018-12-03 15:04:49 -080032 'after-spinlock (*smp_mb__after_spinlock*) ||
33 'after-unlock-lock (*smp_mb__after_unlock_lock*)
Paul E. McKenney1c27b642018-01-18 19:58:55 -080034instructions F[Barriers]
35
Alan Sterna3f600d2018-11-15 11:20:37 -050036(* SRCU *)
37enum SRCU = 'srcu-lock || 'srcu-unlock || 'sync-srcu
38instructions SRCU[SRCU]
39(* All srcu events *)
40let Srcu = Srcu-lock | Srcu-unlock | Sync-srcu
41
Paul E. McKenney1c27b642018-01-18 19:58:55 -080042(* Compute matching pairs of nested Rcu-lock and Rcu-unlock *)
Alan Stern0172d9e2018-11-15 11:19:44 -050043let rcu-rscs = let rec
Paul E. McKenney1c27b642018-01-18 19:58:55 -080044 unmatched-locks = Rcu-lock \ domain(matched)
45 and unmatched-unlocks = Rcu-unlock \ range(matched)
46 and unmatched = unmatched-locks | unmatched-unlocks
47 and unmatched-po = [unmatched] ; po ; [unmatched]
48 and unmatched-locks-to-unlocks =
49 [unmatched-locks] ; po ; [unmatched-unlocks]
50 and matched = matched | (unmatched-locks-to-unlocks \
51 (unmatched-po ; unmatched-po))
52 in matched
53
54(* Validate nesting *)
Alan Stern0172d9e2018-11-15 11:19:44 -050055flag ~empty Rcu-lock \ domain(rcu-rscs) as unbalanced-rcu-locking
56flag ~empty Rcu-unlock \ range(rcu-rscs) as unbalanced-rcu-locking
Alan Sterna3f600d2018-11-15 11:20:37 -050057
58(* Compute matching pairs of nested Srcu-lock and Srcu-unlock *)
59let srcu-rscs = let rec
60 unmatched-locks = Srcu-lock \ domain(matched)
61 and unmatched-unlocks = Srcu-unlock \ range(matched)
62 and unmatched = unmatched-locks | unmatched-unlocks
63 and unmatched-po = ([unmatched] ; po ; [unmatched]) & loc
64 and unmatched-locks-to-unlocks =
65 ([unmatched-locks] ; po ; [unmatched-unlocks]) & loc
66 and matched = matched | (unmatched-locks-to-unlocks \
67 (unmatched-po ; unmatched-po))
68 in matched
69
70(* Validate nesting *)
71flag ~empty Srcu-lock \ domain(srcu-rscs) as unbalanced-srcu-locking
72flag ~empty Srcu-unlock \ range(srcu-rscs) as unbalanced-srcu-locking
73
74(* Check for use of synchronize_srcu() inside an RCU critical section *)
75flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep