18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci(* 38c2ecf20Sopenharmony_ci * Copyright (C) 2015 Jade Alglave <j.alglave@ucl.ac.uk>, 48c2ecf20Sopenharmony_ci * Copyright (C) 2016 Luc Maranget <luc.maranget@inria.fr> for Inria 58c2ecf20Sopenharmony_ci * Copyright (C) 2017 Alan Stern <stern@rowland.harvard.edu>, 68c2ecf20Sopenharmony_ci * Andrea Parri <parri.andrea@gmail.com> 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * An earlier version of this file appeared in the companion webpage for 98c2ecf20Sopenharmony_ci * "Frightening small children and disconcerting grown-ups: Concurrency 108c2ecf20Sopenharmony_ci * in the Linux kernel" by Alglave, Maranget, McKenney, Parri, and Stern, 118c2ecf20Sopenharmony_ci * which appeared in ASPLOS 2018. 128c2ecf20Sopenharmony_ci *) 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci"Linux-kernel memory consistency model" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cienum Accesses = 'once (*READ_ONCE,WRITE_ONCE*) || 178c2ecf20Sopenharmony_ci 'release (*smp_store_release*) || 188c2ecf20Sopenharmony_ci 'acquire (*smp_load_acquire*) || 198c2ecf20Sopenharmony_ci 'noreturn (* R of non-return RMW *) 208c2ecf20Sopenharmony_ciinstructions R[{'once,'acquire,'noreturn}] 218c2ecf20Sopenharmony_ciinstructions W[{'once,'release}] 228c2ecf20Sopenharmony_ciinstructions RMW[{'once,'acquire,'release}] 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cienum Barriers = 'wmb (*smp_wmb*) || 258c2ecf20Sopenharmony_ci 'rmb (*smp_rmb*) || 268c2ecf20Sopenharmony_ci 'mb (*smp_mb*) || 278c2ecf20Sopenharmony_ci 'barrier (*barrier*) || 288c2ecf20Sopenharmony_ci 'rcu-lock (*rcu_read_lock*) || 298c2ecf20Sopenharmony_ci 'rcu-unlock (*rcu_read_unlock*) || 308c2ecf20Sopenharmony_ci 'sync-rcu (*synchronize_rcu*) || 318c2ecf20Sopenharmony_ci 'before-atomic (*smp_mb__before_atomic*) || 328c2ecf20Sopenharmony_ci 'after-atomic (*smp_mb__after_atomic*) || 338c2ecf20Sopenharmony_ci 'after-spinlock (*smp_mb__after_spinlock*) || 348c2ecf20Sopenharmony_ci 'after-unlock-lock (*smp_mb__after_unlock_lock*) 358c2ecf20Sopenharmony_ciinstructions F[Barriers] 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci(* SRCU *) 388c2ecf20Sopenharmony_cienum SRCU = 'srcu-lock || 'srcu-unlock || 'sync-srcu 398c2ecf20Sopenharmony_ciinstructions SRCU[SRCU] 408c2ecf20Sopenharmony_ci(* All srcu events *) 418c2ecf20Sopenharmony_cilet Srcu = Srcu-lock | Srcu-unlock | Sync-srcu 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci(* Compute matching pairs of nested Rcu-lock and Rcu-unlock *) 448c2ecf20Sopenharmony_cilet rcu-rscs = let rec 458c2ecf20Sopenharmony_ci unmatched-locks = Rcu-lock \ domain(matched) 468c2ecf20Sopenharmony_ci and unmatched-unlocks = Rcu-unlock \ range(matched) 478c2ecf20Sopenharmony_ci and unmatched = unmatched-locks | unmatched-unlocks 488c2ecf20Sopenharmony_ci and unmatched-po = [unmatched] ; po ; [unmatched] 498c2ecf20Sopenharmony_ci and unmatched-locks-to-unlocks = 508c2ecf20Sopenharmony_ci [unmatched-locks] ; po ; [unmatched-unlocks] 518c2ecf20Sopenharmony_ci and matched = matched | (unmatched-locks-to-unlocks \ 528c2ecf20Sopenharmony_ci (unmatched-po ; unmatched-po)) 538c2ecf20Sopenharmony_ci in matched 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci(* Validate nesting *) 568c2ecf20Sopenharmony_ciflag ~empty Rcu-lock \ domain(rcu-rscs) as unbalanced-rcu-locking 578c2ecf20Sopenharmony_ciflag ~empty Rcu-unlock \ range(rcu-rscs) as unbalanced-rcu-locking 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci(* Compute matching pairs of nested Srcu-lock and Srcu-unlock *) 608c2ecf20Sopenharmony_cilet srcu-rscs = let rec 618c2ecf20Sopenharmony_ci unmatched-locks = Srcu-lock \ domain(matched) 628c2ecf20Sopenharmony_ci and unmatched-unlocks = Srcu-unlock \ range(matched) 638c2ecf20Sopenharmony_ci and unmatched = unmatched-locks | unmatched-unlocks 648c2ecf20Sopenharmony_ci and unmatched-po = ([unmatched] ; po ; [unmatched]) & loc 658c2ecf20Sopenharmony_ci and unmatched-locks-to-unlocks = 668c2ecf20Sopenharmony_ci ([unmatched-locks] ; po ; [unmatched-unlocks]) & loc 678c2ecf20Sopenharmony_ci and matched = matched | (unmatched-locks-to-unlocks \ 688c2ecf20Sopenharmony_ci (unmatched-po ; unmatched-po)) 698c2ecf20Sopenharmony_ci in matched 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci(* Validate nesting *) 728c2ecf20Sopenharmony_ciflag ~empty Srcu-lock \ domain(srcu-rscs) as unbalanced-srcu-locking 738c2ecf20Sopenharmony_ciflag ~empty Srcu-unlock \ range(srcu-rscs) as unbalanced-srcu-locking 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci(* Check for use of synchronize_srcu() inside an RCU critical section *) 768c2ecf20Sopenharmony_ciflag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci(* Validate SRCU dynamic match *) 798c2ecf20Sopenharmony_ciflag ~empty different-values(srcu-rscs) as srcu-bad-nesting 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci(* Compute marked and plain memory accesses *) 828c2ecf20Sopenharmony_cilet Marked = (~M) | IW | Once | Release | Acquire | domain(rmw) | range(rmw) | 838c2ecf20Sopenharmony_ci LKR | LKW | UL | LF | RL | RU 848c2ecf20Sopenharmony_cilet Plain = M \ Marked 85