1 // SPDX-License-Identifier: GPL-2.0+
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>
8 * An earlier version of this file appeared in the companion webpage for
9 * "Frightening small children and disconcerting grown-ups: Concurrency
10 * in the Linux kernel" by Alglave, Maranget, McKenney, Parri, and Stern,
11 * which appeared in ASPLOS 2018.
14 "Linux-kernel memory consistency model"
16 enum Accesses = 'once (*READ_ONCE,WRITE_ONCE*) ||
17 'release (*smp_store_release*) ||
18 'acquire (*smp_load_acquire*) ||
19 'noreturn (* R of non-return RMW *)
20 instructions R[{'once,'acquire,'noreturn}]
21 instructions W[{'once,'release}]
22 instructions RMW[{'once,'acquire,'release}]
24 enum Barriers = 'wmb (*smp_wmb*) ||
27 'rcu-lock (*rcu_read_lock*) ||
28 'rcu-unlock (*rcu_read_unlock*) ||
29 'sync-rcu (*synchronize_rcu*) ||
30 'before-atomic (*smp_mb__before_atomic*) ||
31 'after-atomic (*smp_mb__after_atomic*) ||
32 'after-spinlock (*smp_mb__after_spinlock*) ||
33 'after-unlock-lock (*smp_mb__after_unlock_lock*)
34 instructions F[Barriers]
37 enum SRCU = 'srcu-lock || 'srcu-unlock || 'sync-srcu
38 instructions SRCU[SRCU]
40 let Srcu = Srcu-lock | Srcu-unlock | Sync-srcu
42 (* Compute matching pairs of nested Rcu-lock and Rcu-unlock *)
43 let rcu-rscs = let rec
44 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))
54 (* Validate nesting *)
55 flag ~empty Rcu-lock \ domain(rcu-rscs) as unbalanced-rcu-locking
56 flag ~empty Rcu-unlock \ range(rcu-rscs) as unbalanced-rcu-locking
58 (* Compute matching pairs of nested Srcu-lock and Srcu-unlock *)
59 let 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))
70 (* Validate nesting *)
71 flag ~empty Srcu-lock \ domain(srcu-rscs) as unbalanced-srcu-locking
72 flag ~empty Srcu-unlock \ range(srcu-rscs) as unbalanced-srcu-locking
74 (* Check for use of synchronize_srcu() inside an RCU critical section *)
75 flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep
77 (* Validate SRCU dynamic match *)
78 flag ~empty different-values(srcu-rscs) as srcu-bad-nesting