tools: memory-model: Document that the LKMM can easily miss control dependencies
authorAlan Stern <stern@rowland.harvard.edu>
Sun, 4 Oct 2020 01:40:22 +0000 (21:40 -0400)
committerPaul E. McKenney <paulmck@kernel.org>
Mon, 26 Oct 2020 23:18:53 +0000 (16:18 -0700)
Add a small section to the litmus-tests.txt documentation file for
the Linux Kernel Memory Model explaining that the memory model often
fails to recognize certain control dependencies.

Suggested-by: Akira Yokosawa <akiyks@gmail.com>
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
tools/memory-model/Documentation/litmus-tests.txt

index 2f840dc..8a9d5d2 100644 (file)
@@ -946,6 +946,23 @@ Limitations of the Linux-kernel memory model (LKMM) include:
        carrying a dependency, then the compiler can break that dependency
        by substituting a constant of that value.
 
+       Conversely, LKMM sometimes doesn't recognize that a particular
+       optimization is not allowed, and as a result, thinks that a
+       dependency is not present (because the optimization would break it).
+       The memory model misses some pretty obvious control dependencies
+       because of this limitation.  A simple example is:
+
+               r1 = READ_ONCE(x);
+               if (r1 == 0)
+                       smp_mb();
+               WRITE_ONCE(y, 1);
+
+       There is a control dependency from the READ_ONCE to the WRITE_ONCE,
+       even when r1 is nonzero, but LKMM doesn't realize this and thinks
+       that the write may execute before the read if r1 != 0.  (Yes, that
+       doesn't make sense if you think about it, but the memory model's
+       intelligence is limited.)
+
 2.     Multiple access sizes for a single variable are not supported,
        and neither are misaligned or partially overlapping accesses.