From: David Howells <dhowells@redhat.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: David Howells <dhowells@redhat.com>,
torvalds@osdl.org, akpm@osdl.org, mingo@redhat.com,
alan@redhat.com, linux-arch@vger.kernel.org,
linuxppc64-dev@ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Document Linux's memory barriers [try #4]
Date: Tue, 14 Mar 2006 21:26:52 +0000 [thread overview]
Message-ID: <32068.1142371612@warthog.cambridge.redhat.com> (raw)
In-Reply-To: <m1veujy47r.fsf@ebiederm.dsl.xmission.com>
Eric W. Biederman <ebiederm@xmission.com> wrote:
> A small nit. You are not documenting the most subtle memory barrier:
> smp_read_barrier_depends(); Which is a deep requirement of the RCU
> code.
How about this the attached adjustment?
David
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
index 3ec9ff4..0c38bea 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -457,13 +457,14 @@ except in small and specific cases. In
EXPLICIT KERNEL MEMORY BARRIERS
===============================
-The Linux kernel has six basic CPU memory barriers:
+The Linux kernel has eight basic CPU memory barriers:
- MANDATORY SMP CONDITIONAL
- =============== ===============
- GENERAL mb() smp_mb()
- READ rmb() smp_rmb()
- WRITE wmb() smp_wmb()
+ TYPE MANDATORY SMP CONDITIONAL
+ =============== ======================= ===========================
+ GENERAL mb() smp_mb()
+ WRITE wmb() smp_wmb()
+ READ rmb() smp_rmb()
+ DATA DEPENDENCY read_barrier_depends() smp_read_barrier_depends()
General memory barriers give a guarantee that all memory accesses specified
before the barrier will appear to happen before all memory accesses specified
@@ -472,6 +473,36 @@ after the barrier with respect to the ot
Read and write memory barriers give similar guarantees, but only for memory
reads versus memory reads and memory writes versus memory writes respectively.
+Data dependency memory barriers ensure that if two reads are issued that
+depend on each other, that the first read is completed _before_ the dependency
+comes into effect. For instance, consider a case where the address used in
+the second read is calculated from the result of the first read:
+
+ CPU 1 CPU 2 COMMENT
+ =============== =============== =======================================
+ a == 0, b == 1 and p == &a, q == &a
+ b = 2;
+ smp_wmb(); Make sure b is changed before p
+ p = &b; q = p;
+ d = *q;
+
+then old data values may be used in the address calculation for the second
+value, potentially resulting in q == &b and d == 0 being seen, which is never
+correct. What is required is a data dependency memory barrier:
+
+ CPU 1 CPU 2 COMMENT
+ =============== =============== =======================================
+ a == 0, b == 1 and p == &a, q == &a
+ b = 2;
+ smp_wmb(); Make sure b is changed before p
+ p = &b; q = p;
+ smp_read_barrier_depends();
+ Make sure q is changed before d is read
+ d = *q;
+
+This forces the result to be either q == &a and d == 0 or q == &b and d == 2.
+The result of q == &b and d == 0 will never be seen.
+
All memory barriers imply compiler barriers.
SMP memory barriers are only compiler barriers on uniprocessor compiled systems
next prev parent reply other threads:[~2006-03-14 21:27 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20060315200956.4a9e2cb3.akpm@osdl.org>
2006-03-09 20:29 ` [PATCH] Document Linux's memory barriers [try #4] David Howells
2006-03-09 23:34 ` Paul Mackerras
2006-03-09 23:45 ` Michael Buesch
2006-03-09 23:56 ` Linus Torvalds
2006-03-10 0:07 ` Michael Buesch
2006-03-10 0:48 ` Alan Cox
2006-03-10 0:54 ` Paul Mackerras
2006-03-10 15:19 ` David Howells
2006-03-11 0:01 ` Paul Mackerras
2006-03-10 5:28 ` Nick Piggin
2006-03-15 11:10 ` David Howells
2006-03-15 11:51 ` Nick Piggin
2006-03-15 13:47 ` David Howells
2006-03-15 23:21 ` Nick Piggin
2006-03-12 17:15 ` Eric W. Biederman
2006-03-14 21:26 ` David Howells [this message]
2006-03-14 21:48 ` Paul Mackerras
2006-03-14 23:59 ` David Howells
2006-03-15 0:20 ` Linus Torvalds
2006-03-15 1:19 ` David Howells
2006-03-15 1:47 ` Linus Torvalds
2006-03-15 1:25 ` Nick Piggin
2006-03-15 0:54 ` Paul Mackerras
2006-03-15 14:23 ` [PATCH] Document Linux's memory barriers [try #5] David Howells
2006-03-16 23:17 ` Paul E. McKenney
2006-03-16 23:55 ` Linus Torvalds
2006-03-17 1:29 ` Paul E. McKenney
2006-03-17 5:32 ` Linus Torvalds
2006-03-17 6:23 ` Paul E. McKenney
2006-03-23 18:34 ` David Howells
2006-03-23 19:28 ` Linus Torvalds
2006-03-23 22:26 ` Paul E. McKenney
[not found] ` <21253.1142509812@warthog.cambridge.redhat.com>
[not found] ` <Pine.LNX.4.64.0603160914410.3618@g5.osdl.org>
2006-03-17 1:20 ` Nick Piggin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=32068.1142371612@warthog.cambridge.redhat.com \
--to=dhowells@redhat.com \
--cc=akpm@osdl.org \
--cc=alan@redhat.com \
--cc=ebiederm@xmission.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc64-dev@ozlabs.org \
--cc=mingo@redhat.com \
--cc=torvalds@osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox