Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 1 | // 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 Parri | 1a00b455 | 2018-05-14 16:33:56 -0700 | [diff] [blame] | 8 | * An earlier version of this file appeared in the companion webpage for |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 9 | * "Frightening small children and disconcerting grown-ups: Concurrency |
| 10 | * in the Linux kernel" by Alglave, Maranget, McKenney, Parri, and Stern, |
Andrea Parri | 1a00b455 | 2018-05-14 16:33:56 -0700 | [diff] [blame] | 11 | * which appeared in ASPLOS 2018. |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 12 | *) |
| 13 | |
Andrea Parri | 48d44d4 | 2018-02-20 15:25:01 -0800 | [diff] [blame] | 14 | "Linux-kernel memory consistency model" |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 15 | |
Mark Rutland | af41db5e | 2018-07-16 11:05:57 -0700 | [diff] [blame] | 16 | enum Accesses = 'once (*READ_ONCE,WRITE_ONCE*) || |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 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}] |
| 23 | |
| 24 | enum Barriers = 'wmb (*smp_wmb*) || |
| 25 | 'rmb (*smp_rmb*) || |
| 26 | 'mb (*smp_mb*) || |
Alan Stern | 0031e38 | 2019-04-22 12:18:09 -0400 | [diff] [blame] | 27 | 'barrier (*barrier*) || |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 28 | 'rcu-lock (*rcu_read_lock*) || |
| 29 | 'rcu-unlock (*rcu_read_unlock*) || |
| 30 | 'sync-rcu (*synchronize_rcu*) || |
Paul E. McKenney | cac79a39 | 2018-02-20 15:25:11 -0800 | [diff] [blame] | 31 | 'before-atomic (*smp_mb__before_atomic*) || |
| 32 | 'after-atomic (*smp_mb__after_atomic*) || |
Andrea Parri | 5b735eb | 2018-12-03 15:04:49 -0800 | [diff] [blame] | 33 | 'after-spinlock (*smp_mb__after_spinlock*) || |
| 34 | 'after-unlock-lock (*smp_mb__after_unlock_lock*) |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 35 | instructions F[Barriers] |
| 36 | |
Alan Stern | a3f600d | 2018-11-15 11:20:37 -0500 | [diff] [blame] | 37 | (* SRCU *) |
| 38 | enum SRCU = 'srcu-lock || 'srcu-unlock || 'sync-srcu |
| 39 | instructions SRCU[SRCU] |
| 40 | (* All srcu events *) |
| 41 | let Srcu = Srcu-lock | Srcu-unlock | Sync-srcu |
| 42 | |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 43 | (* Compute matching pairs of nested Rcu-lock and Rcu-unlock *) |
Alan Stern | 0172d9e | 2018-11-15 11:19:44 -0500 | [diff] [blame] | 44 | let rcu-rscs = let rec |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 45 | unmatched-locks = Rcu-lock \ domain(matched) |
| 46 | and unmatched-unlocks = Rcu-unlock \ range(matched) |
| 47 | and unmatched = unmatched-locks | unmatched-unlocks |
| 48 | and unmatched-po = [unmatched] ; po ; [unmatched] |
| 49 | and unmatched-locks-to-unlocks = |
| 50 | [unmatched-locks] ; po ; [unmatched-unlocks] |
| 51 | and matched = matched | (unmatched-locks-to-unlocks \ |
| 52 | (unmatched-po ; unmatched-po)) |
| 53 | in matched |
| 54 | |
| 55 | (* Validate nesting *) |
Alan Stern | 0172d9e | 2018-11-15 11:19:44 -0500 | [diff] [blame] | 56 | flag ~empty Rcu-lock \ domain(rcu-rscs) as unbalanced-rcu-locking |
| 57 | flag ~empty Rcu-unlock \ range(rcu-rscs) as unbalanced-rcu-locking |
Alan Stern | a3f600d | 2018-11-15 11:20:37 -0500 | [diff] [blame] | 58 | |
| 59 | (* Compute matching pairs of nested Srcu-lock and Srcu-unlock *) |
| 60 | let srcu-rscs = let rec |
| 61 | unmatched-locks = Srcu-lock \ domain(matched) |
| 62 | and unmatched-unlocks = Srcu-unlock \ range(matched) |
| 63 | and unmatched = unmatched-locks | unmatched-unlocks |
| 64 | and unmatched-po = ([unmatched] ; po ; [unmatched]) & loc |
| 65 | and unmatched-locks-to-unlocks = |
| 66 | ([unmatched-locks] ; po ; [unmatched-unlocks]) & loc |
| 67 | and matched = matched | (unmatched-locks-to-unlocks \ |
| 68 | (unmatched-po ; unmatched-po)) |
| 69 | in matched |
| 70 | |
| 71 | (* Validate nesting *) |
| 72 | flag ~empty Srcu-lock \ domain(srcu-rscs) as unbalanced-srcu-locking |
| 73 | flag ~empty Srcu-unlock \ range(srcu-rscs) as unbalanced-srcu-locking |
| 74 | |
| 75 | (* Check for use of synchronize_srcu() inside an RCU critical section *) |
| 76 | flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep |
Luc Maranget | 9393998 | 2018-12-27 16:27:12 +0100 | [diff] [blame] | 77 | |
| 78 | (* Validate SRCU dynamic match *) |
| 79 | flag ~empty different-values(srcu-rscs) as srcu-bad-nesting |
Alan Stern | d1a84ab | 2019-04-22 12:17:58 -0400 | [diff] [blame] | 80 | |
| 81 | (* Compute marked and plain memory accesses *) |
| 82 | let Marked = (~M) | IW | Once | Release | Acquire | domain(rmw) | range(rmw) | |
| 83 | LKR | LKW | UL | LF | RL | RU |
| 84 | let Plain = M \ Marked |