README 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. =====================================
  2. LINUX KERNEL MEMORY CONSISTENCY MODEL
  3. =====================================
  4. ============
  5. INTRODUCTION
  6. ============
  7. This directory contains the memory consistency model (memory model, for
  8. short) of the Linux kernel, written in the "cat" language and executable
  9. by the externally provided "herd7" simulator, which exhaustively explores
  10. the state space of small litmus tests.
  11. In addition, the "klitmus7" tool (also externally provided) may be used
  12. to convert a litmus test to a Linux kernel module, which in turn allows
  13. that litmus test to be exercised within the Linux kernel.
  14. ============
  15. REQUIREMENTS
  16. ============
  17. Version 7.49 of the "herd7" and "klitmus7" tools must be downloaded
  18. separately:
  19. https://github.com/herd/herdtools7
  20. See "herdtools7/INSTALL.md" for installation instructions.
  21. ==================
  22. BASIC USAGE: HERD7
  23. ==================
  24. The memory model is used, in conjunction with "herd7", to exhaustively
  25. explore the state space of small litmus tests.
  26. For example, to run SB+fencembonceonces.litmus against the memory model:
  27. $ herd7 -conf linux-kernel.cfg litmus-tests/SB+fencembonceonces.litmus
  28. Here is the corresponding output:
  29. Test SB+fencembonceonces Allowed
  30. States 3
  31. 0:r0=0; 1:r0=1;
  32. 0:r0=1; 1:r0=0;
  33. 0:r0=1; 1:r0=1;
  34. No
  35. Witnesses
  36. Positive: 0 Negative: 3
  37. Condition exists (0:r0=0 /\ 1:r0=0)
  38. Observation SB+fencembonceonces Never 0 3
  39. Time SB+fencembonceonces 0.01
  40. Hash=d66d99523e2cac6b06e66f4c995ebb48
  41. The "Positive: 0 Negative: 3" and the "Never 0 3" each indicate that
  42. this litmus test's "exists" clause can not be satisfied.
  43. See "herd7 -help" or "herdtools7/doc/" for more information.
  44. =====================
  45. BASIC USAGE: KLITMUS7
  46. =====================
  47. The "klitmus7" tool converts a litmus test into a Linux kernel module,
  48. which may then be loaded and run.
  49. For example, to run SB+fencembonceonces.litmus against hardware:
  50. $ mkdir mymodules
  51. $ klitmus7 -o mymodules litmus-tests/SB+fencembonceonces.litmus
  52. $ cd mymodules ; make
  53. $ sudo sh run.sh
  54. The corresponding output includes:
  55. Test SB+fencembonceonces Allowed
  56. Histogram (3 states)
  57. 644580 :>0:r0=1; 1:r0=0;
  58. 644328 :>0:r0=0; 1:r0=1;
  59. 711092 :>0:r0=1; 1:r0=1;
  60. No
  61. Witnesses
  62. Positive: 0, Negative: 2000000
  63. Condition exists (0:r0=0 /\ 1:r0=0) is NOT validated
  64. Hash=d66d99523e2cac6b06e66f4c995ebb48
  65. Observation SB+fencembonceonces Never 0 2000000
  66. Time SB+fencembonceonces 0.16
  67. The "Positive: 0 Negative: 2000000" and the "Never 0 2000000" indicate
  68. that during two million trials, the state specified in this litmus
  69. test's "exists" clause was not reached.
  70. And, as with "herd7", please see "klitmus7 -help" or "herdtools7/doc/"
  71. for more information.
  72. ====================
  73. DESCRIPTION OF FILES
  74. ====================
  75. Documentation/cheatsheet.txt
  76. Quick-reference guide to the Linux-kernel memory model.
  77. Documentation/explanation.txt
  78. Describes the memory model in detail.
  79. Documentation/recipes.txt
  80. Lists common memory-ordering patterns.
  81. Documentation/references.txt
  82. Provides background reading.
  83. linux-kernel.bell
  84. Categorizes the relevant instructions, including memory
  85. references, memory barriers, atomic read-modify-write operations,
  86. lock acquisition/release, and RCU operations.
  87. More formally, this file (1) lists the subtypes of the various
  88. event types used by the memory model and (2) performs RCU
  89. read-side critical section nesting analysis.
  90. linux-kernel.cat
  91. Specifies what reorderings are forbidden by memory references,
  92. memory barriers, atomic read-modify-write operations, and RCU.
  93. More formally, this file specifies what executions are forbidden
  94. by the memory model. Allowed executions are those which
  95. satisfy the model's "coherence", "atomic", "happens-before",
  96. "propagation", and "rcu" axioms, which are defined in the file.
  97. linux-kernel.cfg
  98. Convenience file that gathers the common-case herd7 command-line
  99. arguments.
  100. linux-kernel.def
  101. Maps from C-like syntax to herd7's internal litmus-test
  102. instruction-set architecture.
  103. litmus-tests
  104. Directory containing a few representative litmus tests, which
  105. are listed in litmus-tests/README. A great deal more litmus
  106. tests are available at https://github.com/paulmckrcu/litmus.
  107. lock.cat
  108. Provides a front-end analysis of lock acquisition and release,
  109. for example, associating a lock acquisition with the preceding
  110. and following releases and checking for self-deadlock.
  111. More formally, this file defines a performance-enhanced scheme
  112. for generation of the possible reads-from and coherence order
  113. relations on the locking primitives.
  114. README
  115. This file.
  116. ===========
  117. LIMITATIONS
  118. ===========
  119. The Linux-kernel memory model has the following limitations:
  120. 1. Compiler optimizations are not modeled. Of course, the use
  121. of READ_ONCE() and WRITE_ONCE() limits the compiler's ability
  122. to optimize, but there is Linux-kernel code that uses bare C
  123. memory accesses. Handling this code is on the to-do list.
  124. For more information, see Documentation/explanation.txt (in
  125. particular, the "THE PROGRAM ORDER RELATION: po AND po-loc"
  126. and "A WARNING" sections).
  127. 2. Multiple access sizes for a single variable are not supported,
  128. and neither are misaligned or partially overlapping accesses.
  129. 3. Exceptions and interrupts are not modeled. In some cases,
  130. this limitation can be overcome by modeling the interrupt or
  131. exception with an additional process.
  132. 4. I/O such as MMIO or DMA is not supported.
  133. 5. Self-modifying code (such as that found in the kernel's
  134. alternatives mechanism, function tracer, Berkeley Packet Filter
  135. JIT compiler, and module loader) is not supported.
  136. 6. Complete modeling of all variants of atomic read-modify-write
  137. operations, locking primitives, and RCU is not provided.
  138. For example, call_rcu() and rcu_barrier() are not supported.
  139. However, a substantial amount of support is provided for these
  140. operations, as shown in the linux-kernel.def file.
  141. The "herd7" tool has some additional limitations of its own, apart from
  142. the memory model:
  143. 1. Non-trivial data structures such as arrays or structures are
  144. not supported. However, pointers are supported, allowing trivial
  145. linked lists to be constructed.
  146. 2. Dynamic memory allocation is not supported, although this can
  147. be worked around in some cases by supplying multiple statically
  148. allocated variables.
  149. Some of these limitations may be overcome in the future, but others are
  150. more likely to be addressed by incorporating the Linux-kernel memory model
  151. into other tools.