linux-kernel.cat 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. (*
  15. * File "lock.cat" handles locks and is experimental.
  16. * It can be replaced by include "cos.cat" for tests that do not use locks.
  17. *)
  18. include "lock.cat"
  19. (*******************)
  20. (* Basic relations *)
  21. (*******************)
  22. (* Fences *)
  23. let rmb = [R \ Noreturn] ; fencerel(Rmb) ; [R \ Noreturn]
  24. let wmb = [W] ; fencerel(Wmb) ; [W]
  25. let mb = ([M] ; fencerel(Mb) ; [M]) |
  26. ([M] ; fencerel(Before-atomic) ; [RMW] ; po? ; [M]) |
  27. ([M] ; po? ; [RMW] ; fencerel(After-atomic) ; [M]) |
  28. ([M] ; po? ; [LKW] ; fencerel(After-spinlock) ; [M])
  29. let gp = po ; [Sync-rcu] ; po?
  30. let strong-fence = mb | gp
  31. (* Release Acquire *)
  32. let acq-po = [Acquire] ; po ; [M]
  33. let po-rel = [M] ; po ; [Release]
  34. let rfi-rel-acq = [Release] ; rfi ; [Acquire]
  35. (**********************************)
  36. (* Fundamental coherence ordering *)
  37. (**********************************)
  38. (* Sequential Consistency Per Variable *)
  39. let com = rf | co | fr
  40. acyclic po-loc | com as coherence
  41. (* Atomic Read-Modify-Write *)
  42. empty rmw & (fre ; coe) as atomic
  43. (**********************************)
  44. (* Instruction execution ordering *)
  45. (**********************************)
  46. (* Preserved Program Order *)
  47. let dep = addr | data
  48. let rwdep = (dep | ctrl) ; [W]
  49. let overwrite = co | fr
  50. let to-w = rwdep | (overwrite & int)
  51. let to-r = addr | (dep ; rfi) | rfi-rel-acq
  52. let fence = strong-fence | wmb | po-rel | rmb | acq-po
  53. let ppo = to-r | to-w | fence
  54. (* Propagation: Ordering from release operations and strong fences. *)
  55. let A-cumul(r) = rfe? ; r
  56. let cumul-fence = A-cumul(strong-fence | po-rel) | wmb
  57. let prop = (overwrite & ext)? ; cumul-fence* ; rfe?
  58. (*
  59. * Happens Before: Ordering from the passage of time.
  60. * No fences needed here for prop because relation confined to one process.
  61. *)
  62. let hb = ppo | rfe | ((prop \ id) & int)
  63. acyclic hb as happens-before
  64. (****************************************)
  65. (* Write and fence propagation ordering *)
  66. (****************************************)
  67. (* Propagation: Each non-rf link needs a strong fence. *)
  68. let pb = prop ; strong-fence ; hb*
  69. acyclic pb as propagation
  70. (*******)
  71. (* RCU *)
  72. (*******)
  73. (*
  74. * Effect of read-side critical section proceeds from the rcu_read_lock()
  75. * onward on the one hand and from the rcu_read_unlock() backwards on the
  76. * other hand.
  77. *)
  78. let rscs = po ; crit^-1 ; po?
  79. (*
  80. * The synchronize_rcu() strong fence is special in that it can order not
  81. * one but two non-rf relations, but only in conjunction with an RCU
  82. * read-side critical section.
  83. *)
  84. let rcu-link = hb* ; pb* ; prop
  85. (*
  86. * Any sequence containing at least as many grace periods as RCU read-side
  87. * critical sections (joined by rcu-link) acts as a generalized strong fence.
  88. *)
  89. let rec rcu-fence = gp |
  90. (gp ; rcu-link ; rscs) |
  91. (rscs ; rcu-link ; gp) |
  92. (gp ; rcu-link ; rcu-fence ; rcu-link ; rscs) |
  93. (rscs ; rcu-link ; rcu-fence ; rcu-link ; gp) |
  94. (rcu-fence ; rcu-link ; rcu-fence)
  95. (* rb orders instructions just as pb does *)
  96. let rb = prop ; rcu-fence ; hb* ; pb*
  97. irreflexive rb as rcu
  98. (*
  99. * The happens-before, propagation, and rcu constraints are all
  100. * expressions of temporal ordering. They could be replaced by
  101. * a single constraint on an "executes-before" relation, xb:
  102. *
  103. * let xb = hb | pb | rb
  104. * acyclic xb as executes-before
  105. *)