linux-kernel.bell 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. *
  8. * An earlier version of this file appears 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 is to appear in ASPLOS 2018.
  12. *)
  13. "Linux kernel memory model"
  14. enum Accesses = 'once (*READ_ONCE,WRITE_ONCE,ACCESS_ONCE*) ||
  15. 'release (*smp_store_release*) ||
  16. 'acquire (*smp_load_acquire*) ||
  17. 'noreturn (* R of non-return RMW *)
  18. instructions R[{'once,'acquire,'noreturn}]
  19. instructions W[{'once,'release}]
  20. instructions RMW[{'once,'acquire,'release}]
  21. enum Barriers = 'wmb (*smp_wmb*) ||
  22. 'rmb (*smp_rmb*) ||
  23. 'mb (*smp_mb*) ||
  24. 'rb_dep (*smp_read_barrier_depends*) ||
  25. 'rcu-lock (*rcu_read_lock*) ||
  26. 'rcu-unlock (*rcu_read_unlock*) ||
  27. 'sync-rcu (*synchronize_rcu*) ||
  28. 'before_atomic (*smp_mb__before_atomic*) ||
  29. 'after_atomic (*smp_mb__after_atomic*) ||
  30. 'after_spinlock (*smp_mb__after_spinlock*)
  31. instructions F[Barriers]
  32. (* Compute matching pairs of nested Rcu-lock and Rcu-unlock *)
  33. let matched = let rec
  34. unmatched-locks = Rcu-lock \ domain(matched)
  35. and unmatched-unlocks = Rcu-unlock \ range(matched)
  36. and unmatched = unmatched-locks | unmatched-unlocks
  37. and unmatched-po = [unmatched] ; po ; [unmatched]
  38. and unmatched-locks-to-unlocks =
  39. [unmatched-locks] ; po ; [unmatched-unlocks]
  40. and matched = matched | (unmatched-locks-to-unlocks \
  41. (unmatched-po ; unmatched-po))
  42. in matched
  43. (* Validate nesting *)
  44. flag ~empty Rcu-lock \ domain(matched) as unbalanced-rcu-locking
  45. flag ~empty Rcu-unlock \ range(matched) as unbalanced-rcu-locking
  46. (* Outermost level of nesting only *)
  47. let crit = matched \ (po^-1 ; matched ; po^-1)