Skip to content

Commit 2425ce8

Browse files
Mikulas PatockaJames Hogan
authored andcommitted
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>
1 parent d6d211d commit 2425ce8

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎arch/metag/include/asm/barrier.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static inline void wr_fence(void)
1515
volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_FENCE;
1616
barrier();
1717
*flushptr = 0;
18+
barrier();
1819
}
1920

2021
#else /* CONFIG_METAG_META21 */
@@ -35,6 +36,7 @@ static inline void wr_fence(void)
3536
*flushptr = 0;
3637
*flushptr = 0;
3738
*flushptr = 0;
39+
barrier();
3840
}
3941

4042
#endif /* !CONFIG_METAG_META21 */
@@ -68,6 +70,7 @@ static inline void fence(void)
6870
volatile int *flushptr = (volatile int *) LINSYSEVENT_WR_ATOMIC_UNLOCK;
6971
barrier();
7072
*flushptr = 0;
73+
barrier();
7174
}
7275
#define smp_mb() fence()
7376
#define smp_rmb() fence()

0 commit comments

Comments
 (0)