Commit 2425ce84 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by James Hogan

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: default avatarMikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
parent d6d211db
...@@ -15,6 +15,7 @@ static inline void wr_fence(void) ...@@ -15,6 +15,7 @@ static inline void wr_fence(void)
volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_FENCE; volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_FENCE;
barrier(); barrier();
*flushptr = 0; *flushptr = 0;
barrier();
} }
#else /* CONFIG_METAG_META21 */ #else /* CONFIG_METAG_META21 */
...@@ -35,6 +36,7 @@ static inline void wr_fence(void) ...@@ -35,6 +36,7 @@ static inline void wr_fence(void)
*flushptr = 0; *flushptr = 0;
*flushptr = 0; *flushptr = 0;
*flushptr = 0; *flushptr = 0;
barrier();
} }
#endif /* !CONFIG_METAG_META21 */ #endif /* !CONFIG_METAG_META21 */
...@@ -68,6 +70,7 @@ static inline void fence(void) ...@@ -68,6 +70,7 @@ static inline void fence(void)
volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_ATOMIC_UNLOCK; volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_ATOMIC_UNLOCK;
barrier(); barrier();
*flushptr = 0; *flushptr = 0;
barrier();
} }
#define smp_mb() fence() #define smp_mb() fence()
#define smp_rmb() fence() #define smp_rmb() fence()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment