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*) || |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 27 | 'rcu-lock (*rcu_read_lock*) || |
| 28 | 'rcu-unlock (*rcu_read_unlock*) || |
| 29 | 'sync-rcu (*synchronize_rcu*) || |
Paul E. McKenney | cac79a39 | 2018-02-20 15:25:11 -0800 | [diff] [blame] | 30 | 'before-atomic (*smp_mb__before_atomic*) || |
| 31 | 'after-atomic (*smp_mb__after_atomic*) || |
Andrea Parri | 5b735eb | 2018-12-03 15:04:49 -0800 | [diff] [blame] | 32 | 'after-spinlock (*smp_mb__after_spinlock*) || |
| 33 | 'after-unlock-lock (*smp_mb__after_unlock_lock*) |
Paul E. McKenney | 1c27b64 | 2018-01-18 19:58:55 -0800 | [diff] [blame] | 34 | instructions F[Barriers] |
| 35 | |
| 36 | (* Compute matching pairs of nested Rcu-lock and Rcu-unlock *) |
| 37 | let matched = let rec |
| 38 | unmatched-locks = Rcu-lock \ domain(matched) |
| 39 | and unmatched-unlocks = Rcu-unlock \ range(matched) |
| 40 | and unmatched = unmatched-locks | unmatched-unlocks |
| 41 | and unmatched-po = [unmatched] ; po ; [unmatched] |
| 42 | and unmatched-locks-to-unlocks = |
| 43 | [unmatched-locks] ; po ; [unmatched-unlocks] |
| 44 | and matched = matched | (unmatched-locks-to-unlocks \ |
| 45 | (unmatched-po ; unmatched-po)) |
| 46 | in matched |
| 47 | |
| 48 | (* Validate nesting *) |
| 49 | flag ~empty Rcu-lock \ domain(matched) as unbalanced-rcu-locking |
| 50 | flag ~empty Rcu-unlock \ range(matched) as unbalanced-rcu-locking |
| 51 | |
| 52 | (* Outermost level of nesting only *) |
| 53 | let crit = matched \ (po^-1 ; matched ; po^-1) |