linux-kernel.cat 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 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 link = hb* ; pb* ; prop
  85. (* Chains that affect the RCU grace-period guarantee *)
  86. let gp-link = gp ; link
  87. let rscs-link = rscs ; link
  88. (*
  89. * A cycle containing at least as many grace periods as RCU read-side
  90. * critical sections is forbidden.
  91. *)
  92. let rec rcu-path =
  93. gp-link |
  94. (gp-link ; rscs-link) |
  95. (rscs-link ; gp-link) |
  96. (rcu-path ; rcu-path) |
  97. (gp-link ; rcu-path ; rscs-link) |
  98. (rscs-link ; rcu-path ; gp-link)
  99. irreflexive rcu-path as rcu