1// SPDX-License-Identifier: GPL-2.0+ 2(* 3 * Copyright (C) 2015 Jade Alglave <[email protected]>, 4 * Copyright (C) 2016 Luc Maranget <[email protected]> for Inria 5 * Copyright (C) 2017 Alan Stern <[email protected]>, 6 * Andrea Parri <[email protected]> 7 * 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. 12 *) 13 14"Linux-kernel memory consistency model" 15 16enum Accesses = 'once (*READ_ONCE,WRITE_ONCE*) || 17 'release (*smp_store_release*) || 18 'acquire (*smp_load_acquire*) || 19 'noreturn (* R of non-return RMW *) || 20 'mb (*xchg(),cmpxchg(),...*) 21instructions R[Accesses] 22instructions W[Accesses] 23instructions RMW[Accesses] 24 25enum Barriers = 'wmb (*smp_wmb*) || 26 'rmb (*smp_rmb*) || 27 'mb (*smp_mb*) || 28 'barrier (*barrier*) || 29 'rcu-lock (*rcu_read_lock*) || 30 'rcu-unlock (*rcu_read_unlock*) || 31 'sync-rcu (*synchronize_rcu*) || 32 'before-atomic (*smp_mb__before_atomic*) || 33 'after-atomic (*smp_mb__after_atomic*) || 34 'after-spinlock (*smp_mb__after_spinlock*) || 35 'after-unlock-lock (*smp_mb__after_unlock_lock*) || 36 'after-srcu-read-unlock (*smp_mb__after_srcu_read_unlock*) 37instructions F[Barriers] 38 39(* SRCU *) 40enum SRCU = 'srcu-lock || 'srcu-unlock || 'sync-srcu 41instructions SRCU[SRCU] 42(* All srcu events *) 43let Srcu = Srcu-lock | Srcu-unlock | Sync-srcu 44 45(* Compute matching pairs of nested Rcu-lock and Rcu-unlock *) 46let rcu-rscs = let rec 47 unmatched-locks = Rcu-lock \ domain(matched) 48 and unmatched-unlocks = Rcu-unlock \ range(matched) 49 and unmatched = unmatched-locks | unmatched-unlocks 50 and unmatched-po = [unmatched] ; po ; [unmatched] 51 and unmatched-locks-to-unlocks = 52 [unmatched-locks] ; po ; [unmatched-unlocks] 53 and matched = matched | (unmatched-locks-to-unlocks \ 54 (unmatched-po ; unmatched-po)) 55 in matched 56 57(* Validate nesting *) 58flag ~empty Rcu-lock \ domain(rcu-rscs) as unmatched-rcu-lock 59flag ~empty Rcu-unlock \ range(rcu-rscs) as unmatched-rcu-unlock 60 61(* Compute matching pairs of nested Srcu-lock and Srcu-unlock *) 62let carry-srcu-data = (data ; [~ Srcu-unlock] ; rf)* 63let srcu-rscs = ([Srcu-lock] ; carry-srcu-data ; data ; [Srcu-unlock]) & loc 64 65(* Validate nesting *) 66flag ~empty Srcu-lock \ domain(srcu-rscs) as unmatched-srcu-lock 67flag ~empty Srcu-unlock \ range(srcu-rscs) as unmatched-srcu-unlock 68flag ~empty (srcu-rscs^-1 ; srcu-rscs) \ id as multiple-srcu-matches 69 70(* Check for use of synchronize_srcu() inside an RCU critical section *) 71flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep 72 73(* Validate SRCU dynamic match *) 74flag ~empty different-values(srcu-rscs) as srcu-bad-value-match 75 76(* Compute marked and plain memory accesses *) 77let Marked = (~M) | IW | Once | Release | Acquire | domain(rmw) | range(rmw) | 78 LKR | LKW | UL | LF | RL | RU | Srcu-lock | Srcu-unlock 79let Plain = M \ Marked 80 81(* Redefine dependencies to include those carried through plain accesses *) 82let carry-dep = (data ; [~ Srcu-unlock] ; rfi)* 83let addr = carry-dep ; addr 84let ctrl = carry-dep ; ctrl 85let data = carry-dep ; data 86