diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-04 14:46:02 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-04 14:46:02 -0700 |
commit | 2f624278626677bfaf73fef97f86b37981621f5c (patch) | |
tree | 011d5b7d5a6a74d476a80b513f3dd4d78762ed03 /include/linux/seqlock.h | |
parent | f0f376f204b6047bbb405180f796e93cc8444f09 (diff) | |
download | lwn-2f624278626677bfaf73fef97f86b37981621f5c.tar.gz lwn-2f624278626677bfaf73fef97f86b37981621f5c.zip |
Fix __read_seqcount_begin() to use ACCESS_ONCE for sequence value read
We really need to use a ACCESS_ONCE() on the sequence value read in
__read_seqcount_begin(), because otherwise the compiler might end up
reloading the value in between the test and the return of it. As a
result, it might end up returning an odd value (which means that a write
is in progress).
If the reader is then fast enough that that odd value is still the
current one when the read_seqcount_retry() is done, we might end up with
a "successful" read sequence, even despite the concurrent write being
active.
In practice this probably never really happens - there just isn't
anything else going on around the read of the sequence count, and the
common case is that we end up having a read barrier immediately
afterwards.
So the code sequence in which gcc might decide to reaload from memory is
small, and there's no reason to believe it would ever actually do the
reload. But if the compiler ever were to decide to do so, it would be
incredibly annoying to debug. Let's just make sure.
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/seqlock.h')
-rw-r--r-- | include/linux/seqlock.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h index c6db9fb33c44..bb1fac5b8ee8 100644 --- a/include/linux/seqlock.h +++ b/include/linux/seqlock.h @@ -141,7 +141,7 @@ static inline unsigned __read_seqcount_begin(const seqcount_t *s) unsigned ret; repeat: - ret = s->sequence; + ret = ACCESS_ONCE(s->sequence); if (unlikely(ret & 1)) { cpu_relax(); goto repeat; |