85 lines · plain
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 Inria5 * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu>,6 * Andrea Parri <parri.andrea@gmail.com>7 *8 * An earlier version of this file appeared in the companion webpage for9 * "Frightening small children and disconcerting grown-ups: Concurrency10 * 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 *)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*) ||27 'barrier (*barrier*) ||28 'rcu-lock (*rcu_read_lock*) ||29 'rcu-unlock (*rcu_read_unlock*) ||30 'sync-rcu (*synchronize_rcu*) ||31 'before-atomic (*smp_mb__before_atomic*) ||32 'after-atomic (*smp_mb__after_atomic*) ||33 'after-spinlock (*smp_mb__after_spinlock*) ||34 'after-unlock-lock (*smp_mb__after_unlock_lock*) ||35 'after-srcu-read-unlock (*smp_mb__after_srcu_read_unlock*)36instructions F[Barriers]37 38(* SRCU *)39enum SRCU = 'srcu-lock || 'srcu-unlock || 'sync-srcu40instructions SRCU[SRCU]41(* All srcu events *)42let Srcu = Srcu-lock | Srcu-unlock | Sync-srcu43 44(* Compute matching pairs of nested Rcu-lock and Rcu-unlock *)45let rcu-rscs = let rec46 unmatched-locks = Rcu-lock \ domain(matched)47 and unmatched-unlocks = Rcu-unlock \ range(matched)48 and unmatched = unmatched-locks | unmatched-unlocks49 and unmatched-po = [unmatched] ; po ; [unmatched]50 and unmatched-locks-to-unlocks =51 [unmatched-locks] ; po ; [unmatched-unlocks]52 and matched = matched | (unmatched-locks-to-unlocks \53 (unmatched-po ; unmatched-po))54 in matched55 56(* Validate nesting *)57flag ~empty Rcu-lock \ domain(rcu-rscs) as unmatched-rcu-lock58flag ~empty Rcu-unlock \ range(rcu-rscs) as unmatched-rcu-unlock59 60(* Compute matching pairs of nested Srcu-lock and Srcu-unlock *)61let carry-srcu-data = (data ; [~ Srcu-unlock] ; rf)*62let srcu-rscs = ([Srcu-lock] ; carry-srcu-data ; data ; [Srcu-unlock]) & loc63 64(* Validate nesting *)65flag ~empty Srcu-lock \ domain(srcu-rscs) as unmatched-srcu-lock66flag ~empty Srcu-unlock \ range(srcu-rscs) as unmatched-srcu-unlock67flag ~empty (srcu-rscs^-1 ; srcu-rscs) \ id as multiple-srcu-matches68 69(* Check for use of synchronize_srcu() inside an RCU critical section *)70flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep71 72(* Validate SRCU dynamic match *)73flag ~empty different-values(srcu-rscs) as srcu-bad-value-match74 75(* Compute marked and plain memory accesses *)76let Marked = (~M) | IW | Once | Release | Acquire | domain(rmw) | range(rmw) |77 LKR | LKW | UL | LF | RL | RU | Srcu-lock | Srcu-unlock78let Plain = M \ Marked79 80(* Redefine dependencies to include those carried through plain accesses *)81let carry-dep = (data ; [~ Srcu-unlock] ; rfi)*82let addr = carry-dep ; addr83let ctrl = carry-dep ; ctrl84let data = carry-dep ; data85