linux-kernel.bell 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 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. "Linux-kernel memory consistency model"
  14. enum Accesses = 'ONCE (*READ_ONCE,WRITE_ONCE*) ||
  15. 'RELEASE (*smp_store_release*) ||
  16. 'ACQUIRE (*smp_load_acquire*) ||
  17. 'NORETURN (* R of non-return RMW *) ||
  18. 'MB (*xchg(),cmpxchg(),...*)
  19. instructions R[Accesses]
  20. instructions W[Accesses]
  21. instructions RMW[Accesses]
  22. enum Barriers = 'wmb (*smp_wmb*) ||
  23. 'rmb (*smp_rmb*) ||
  24. 'MB (*smp_mb*) ||
  25. 'barrier (*barrier*) ||
  26. 'rcu-lock (*rcu_read_lock*) ||
  27. 'rcu-unlock (*rcu_read_unlock*) ||
  28. 'sync-rcu (*synchronize_rcu*) ||
  29. 'before-atomic (*smp_mb__before_atomic*) ||
  30. 'after-atomic (*smp_mb__after_atomic*) ||
  31. 'after-spinlock (*smp_mb__after_spinlock*) ||
  32. 'after-unlock-lock (*smp_mb__after_unlock_lock*) ||
  33. 'after-srcu-read-unlock (*smp_mb__after_srcu_read_unlock*)
  34. instructions F[Barriers]
  35. (*
  36. * Filter out syntactic annotations that do not provide the corresponding
  37. * semantic ordering, such as Acquire on a store or Mb on a failed RMW.
  38. *)
  39. let FailedRMW = RMW \ (domain(rmw) | range(rmw))
  40. let Acquire = ACQUIRE \ W \ FailedRMW
  41. let Release = RELEASE \ R \ FailedRMW
  42. let Mb = MB \ FailedRMW
  43. let Noreturn = NORETURN \ W
  44. (* SRCU *)
  45. enum SRCU = 'srcu-lock || 'srcu-unlock || 'sync-srcu
  46. instructions SRCU[SRCU]
  47. (* All srcu events *)
  48. let Srcu = Srcu-lock | Srcu-unlock | Sync-srcu
  49. (* Compute matching pairs of nested Rcu-lock and Rcu-unlock *)
  50. let rcu-rscs = let rec
  51. unmatched-locks = Rcu-lock \ domain(matched)
  52. and unmatched-unlocks = Rcu-unlock \ range(matched)
  53. and unmatched = unmatched-locks | unmatched-unlocks
  54. and unmatched-po = [unmatched] ; po ; [unmatched]
  55. and unmatched-locks-to-unlocks =
  56. [unmatched-locks] ; po ; [unmatched-unlocks]
  57. and matched = matched | (unmatched-locks-to-unlocks \
  58. (unmatched-po ; unmatched-po))
  59. in matched
  60. (* Validate nesting *)
  61. flag ~empty Rcu-lock \ domain(rcu-rscs) as unmatched-rcu-lock
  62. flag ~empty Rcu-unlock \ range(rcu-rscs) as unmatched-rcu-unlock
  63. (* Compute matching pairs of nested Srcu-lock and Srcu-unlock *)
  64. let carry-srcu-data = (data ; [~ Srcu-unlock] ; rf)*
  65. let srcu-rscs = ([Srcu-lock] ; carry-srcu-data ; data ; [Srcu-unlock]) & loc
  66. (* Validate nesting *)
  67. flag ~empty Srcu-lock \ domain(srcu-rscs) as unmatched-srcu-lock
  68. flag ~empty Srcu-unlock \ range(srcu-rscs) as unmatched-srcu-unlock
  69. flag ~empty (srcu-rscs^-1 ; srcu-rscs) \ id as multiple-srcu-matches
  70. (* Check for use of synchronize_srcu() inside an RCU critical section *)
  71. flag ~empty rcu-rscs & (po ; [Sync-srcu] ; po) as invalid-sleep
  72. (* Validate SRCU dynamic match *)
  73. flag ~empty different-values(srcu-rscs) as srcu-bad-value-match
  74. (* Compute marked and plain memory accesses *)
  75. let Marked = (~M) | IW | ONCE | RELEASE | ACQUIRE | MB | RMW |
  76. LKR | LKW | UL | LF | RL | RU | Srcu-lock | Srcu-unlock
  77. let Plain = M \ Marked
  78. (* Redefine dependencies to include those carried through plain accesses *)
  79. let carry-dep = (data ; [~ Srcu-unlock] ; rfi)*
  80. let addr = carry-dep ; addr
  81. let ctrl = carry-dep ; ctrl
  82. let data = carry-dep ; data
  83. flag ~empty (if "lkmmv2" then 0 else _)
  84. as this-model-requires-variant-higher-than-lkmmv1