diff options
author | Mikulas Patocka <mpatocka@redhat.com> | 2014-05-08 15:51:37 -0400 |
---|---|---|
committer | James Hogan <james.hogan@imgtec.com> | 2014-05-14 19:00:34 -0400 |
commit | 2425ce84026c385b73ae72039f90d042d49e0394 (patch) | |
tree | c7f5c430603383d0875633f983d0c21030b8d715 /arch/metag | |
parent | d6d211db37e75de2ddc3a4f979038c40df7cc79c (diff) |
metag: fix memory barriers
Volatile access doesn't really imply the compiler barrier. Volatile access
is only ordered with respect to other volatile accesses, it isn't ordered
with respect to general memory accesses. Gcc may reorder memory accesses
around volatile access, as we can see in this simple example (if we
compile it with optimization, both increments of *b will be collapsed to
just one):
void fn(volatile int *a, long *b)
{
(*b)++;
*a = 10;
(*b)++;
}
Consequently, we need the compiler barrier after a write to the volatile
variable, to make sure that the compiler doesn't reorder the volatile
write with something else.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Acked-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Diffstat (limited to 'arch/metag')
-rw-r--r-- | arch/metag/include/asm/barrier.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h index 5d6b4b407dda..2d6f0de77325 100644 --- a/arch/metag/include/asm/barrier.h +++ b/arch/metag/include/asm/barrier.h | |||
@@ -15,6 +15,7 @@ static inline void wr_fence(void) | |||
15 | volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_FENCE; | 15 | volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_FENCE; |
16 | barrier(); | 16 | barrier(); |
17 | *flushptr = 0; | 17 | *flushptr = 0; |
18 | barrier(); | ||
18 | } | 19 | } |
19 | 20 | ||
20 | #else /* CONFIG_METAG_META21 */ | 21 | #else /* CONFIG_METAG_META21 */ |
@@ -35,6 +36,7 @@ static inline void wr_fence(void) | |||
35 | *flushptr = 0; | 36 | *flushptr = 0; |
36 | *flushptr = 0; | 37 | *flushptr = 0; |
37 | *flushptr = 0; | 38 | *flushptr = 0; |
39 | barrier(); | ||
38 | } | 40 | } |
39 | 41 | ||
40 | #endif /* !CONFIG_METAG_META21 */ | 42 | #endif /* !CONFIG_METAG_META21 */ |
@@ -68,6 +70,7 @@ static inline void fence(void) | |||
68 | volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_ATOMIC_UNLOCK; | 70 | volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_ATOMIC_UNLOCK; |
69 | barrier(); | 71 | barrier(); |
70 | *flushptr = 0; | 72 | *flushptr = 0; |
73 | barrier(); | ||
71 | } | 74 | } |
72 | #define smp_mb() fence() | 75 | #define smp_mb() fence() |
73 | #define smp_rmb() fence() | 76 | #define smp_rmb() fence() |