diff options
author | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2016-01-14 17:17:04 -0500 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2016-03-14 18:52:17 -0400 |
commit | 92a84dd210b8263f765882d3ee1a1d5cd348c16a (patch) | |
tree | 84336d89daf350394d408b908363e6d29d3ff89c | |
parent | 0e4bd2aba3d0ae5caeb0d1a2b71f6fe6147c4d56 (diff) |
documentation: Subsequent writes ordered by rcu_dereference()
The current memory-barriers.txt does not address the possibility of
a write to a dereferenced pointer. This should be rare, but when it
happens, we need that write -not- to be clobbered by the initialization.
This commit therefore adds an example showing a data dependency ordering
a later data-dependent write.
Reported-by: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
-rw-r--r-- | Documentation/memory-barriers.txt | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt index 6bee0a2c43ab..e9ebeb3b1077 100644 --- a/Documentation/memory-barriers.txt +++ b/Documentation/memory-barriers.txt | |||
@@ -555,6 +555,30 @@ between the address load and the data load: | |||
555 | This enforces the occurrence of one of the two implications, and prevents the | 555 | This enforces the occurrence of one of the two implications, and prevents the |
556 | third possibility from arising. | 556 | third possibility from arising. |
557 | 557 | ||
558 | A data-dependency barrier must also order against dependent writes: | ||
559 | |||
560 | CPU 1 CPU 2 | ||
561 | =============== =============== | ||
562 | { A == 1, B == 2, C = 3, P == &A, Q == &C } | ||
563 | B = 4; | ||
564 | <write barrier> | ||
565 | WRITE_ONCE(P, &B); | ||
566 | Q = READ_ONCE(P); | ||
567 | <data dependency barrier> | ||
568 | *Q = 5; | ||
569 | |||
570 | The data-dependency barrier must order the read into Q with the store | ||
571 | into *Q. This prohibits this outcome: | ||
572 | |||
573 | (Q == B) && (B == 4) | ||
574 | |||
575 | Please note that this pattern should be rare. After all, the whole point | ||
576 | of dependency ordering is to -prevent- writes to the data structure, along | ||
577 | with the expensive cache misses associated with those writes. This pattern | ||
578 | can be used to record rare error conditions and the like, and the ordering | ||
579 | prevents such records from being lost. | ||
580 | |||
581 | |||
558 | [!] Note that this extremely counterintuitive situation arises most easily on | 582 | [!] Note that this extremely counterintuitive situation arises most easily on |
559 | machines with split caches, so that, for example, one cache bank processes | 583 | machines with split caches, so that, for example, one cache bank processes |
560 | even-numbered cache lines and the other bank processes odd-numbered cache | 584 | even-numbered cache lines and the other bank processes odd-numbered cache |