Skip to content

Commit fbfcd01

Browse files
andrea-parriIngo Molnar
authored andcommitted
locking/xchg/alpha: Remove superfluous memory barriers from the _local() variants
The following two commits: 79d4424 ("locking/xchg/alpha: Clean up barrier usage by using smp_mb() in place of __ASM__MB") 472e8c5 ("locking/xchg/alpha: Fix xchg() and cmpxchg() memory ordering bugs") ... ended up adding unnecessary barriers to the _local() variants on Alpha, which the previous code took care to avoid. Fix them by adding the smp_mb() into the cmpxchg() macro rather than into the ____cmpxchg() variants. Reported-by: Will Deacon <[email protected]> Signed-off-by: Andrea Parri <[email protected]> Cc: Alan Stern <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Ivan Kokshaysky <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Matt Turner <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Richard Henderson <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Fixes: 472e8c5 ("locking/xchg/alpha: Fix xchg() and cmpxchg() memory ordering bugs") Fixes: 79d4424 ("locking/xchg/alpha: Clean up barrier usage by using smp_mb() in place of __ASM__MB") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent bd5c0ba commit fbfcd01

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

arch/alpha/include/asm/cmpxchg.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,31 @@
3838
#define ____cmpxchg(type, args...) __cmpxchg ##type(args)
3939
#include <asm/xchg.h>
4040

41+
/*
42+
* The leading and the trailing memory barriers guarantee that these
43+
* operations are fully ordered.
44+
*/
4145
#define xchg(ptr, x) \
4246
({ \
47+
__typeof__(*(ptr)) __ret; \
4348
__typeof__(*(ptr)) _x_ = (x); \
44-
(__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, \
45-
sizeof(*(ptr))); \
49+
smp_mb(); \
50+
__ret = (__typeof__(*(ptr))) \
51+
__xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
52+
smp_mb(); \
53+
__ret; \
4654
})
4755

4856
#define cmpxchg(ptr, o, n) \
4957
({ \
58+
__typeof__(*(ptr)) __ret; \
5059
__typeof__(*(ptr)) _o_ = (o); \
5160
__typeof__(*(ptr)) _n_ = (n); \
52-
(__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
53-
(unsigned long)_n_, sizeof(*(ptr)));\
61+
smp_mb(); \
62+
__ret = (__typeof__(*(ptr))) __cmpxchg((ptr), \
63+
(unsigned long)_o_, (unsigned long)_n_, sizeof(*(ptr)));\
64+
smp_mb(); \
65+
__ret; \
5466
})
5567

5668
#define cmpxchg64(ptr, o, n) \

arch/alpha/include/asm/xchg.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,13 @@
1212
* Atomic exchange.
1313
* Since it can be used to implement critical sections
1414
* it must clobber "memory" (also for interrupts in UP).
15-
*
16-
* The leading and the trailing memory barriers guarantee that these
17-
* operations are fully ordered.
18-
*
1915
*/
2016

2117
static inline unsigned long
2218
____xchg(_u8, volatile char *m, unsigned long val)
2319
{
2420
unsigned long ret, tmp, addr64;
2521

26-
smp_mb();
2722
__asm__ __volatile__(
2823
" andnot %4,7,%3\n"
2924
" insbl %1,%4,%1\n"
@@ -38,7 +33,6 @@ ____xchg(_u8, volatile char *m, unsigned long val)
3833
".previous"
3934
: "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64)
4035
: "r" ((long)m), "1" (val) : "memory");
41-
smp_mb();
4236

4337
return ret;
4438
}
@@ -48,7 +42,6 @@ ____xchg(_u16, volatile short *m, unsigned long val)
4842
{
4943
unsigned long ret, tmp, addr64;
5044

51-
smp_mb();
5245
__asm__ __volatile__(
5346
" andnot %4,7,%3\n"
5447
" inswl %1,%4,%1\n"
@@ -63,7 +56,6 @@ ____xchg(_u16, volatile short *m, unsigned long val)
6356
".previous"
6457
: "=&r" (ret), "=&r" (val), "=&r" (tmp), "=&r" (addr64)
6558
: "r" ((long)m), "1" (val) : "memory");
66-
smp_mb();
6759

6860
return ret;
6961
}
@@ -73,7 +65,6 @@ ____xchg(_u32, volatile int *m, unsigned long val)
7365
{
7466
unsigned long dummy;
7567

76-
smp_mb();
7768
__asm__ __volatile__(
7869
"1: ldl_l %0,%4\n"
7970
" bis $31,%3,%1\n"
@@ -84,7 +75,6 @@ ____xchg(_u32, volatile int *m, unsigned long val)
8475
".previous"
8576
: "=&r" (val), "=&r" (dummy), "=m" (*m)
8677
: "rI" (val), "m" (*m) : "memory");
87-
smp_mb();
8878

8979
return val;
9080
}
@@ -94,7 +84,6 @@ ____xchg(_u64, volatile long *m, unsigned long val)
9484
{
9585
unsigned long dummy;
9686

97-
smp_mb();
9887
__asm__ __volatile__(
9988
"1: ldq_l %0,%4\n"
10089
" bis $31,%3,%1\n"
@@ -105,7 +94,6 @@ ____xchg(_u64, volatile long *m, unsigned long val)
10594
".previous"
10695
: "=&r" (val), "=&r" (dummy), "=m" (*m)
10796
: "rI" (val), "m" (*m) : "memory");
108-
smp_mb();
10997

11098
return val;
11199
}
@@ -135,21 +123,13 @@ ____xchg(, volatile void *ptr, unsigned long x, int size)
135123
* Atomic compare and exchange. Compare OLD with MEM, if identical,
136124
* store NEW in MEM. Return the initial value in MEM. Success is
137125
* indicated by comparing RETURN with OLD.
138-
*
139-
* The leading and the trailing memory barriers guarantee that these
140-
* operations are fully ordered.
141-
*
142-
* The trailing memory barrier is placed in SMP unconditionally, in
143-
* order to guarantee that dependency ordering is preserved when a
144-
* dependency is headed by an unsuccessful operation.
145126
*/
146127

147128
static inline unsigned long
148129
____cmpxchg(_u8, volatile char *m, unsigned char old, unsigned char new)
149130
{
150131
unsigned long prev, tmp, cmp, addr64;
151132

152-
smp_mb();
153133
__asm__ __volatile__(
154134
" andnot %5,7,%4\n"
155135
" insbl %1,%5,%1\n"
@@ -167,7 +147,6 @@ ____cmpxchg(_u8, volatile char *m, unsigned char old, unsigned char new)
167147
".previous"
168148
: "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64)
169149
: "r" ((long)m), "Ir" (old), "1" (new) : "memory");
170-
smp_mb();
171150

172151
return prev;
173152
}
@@ -177,7 +156,6 @@ ____cmpxchg(_u16, volatile short *m, unsigned short old, unsigned short new)
177156
{
178157
unsigned long prev, tmp, cmp, addr64;
179158

180-
smp_mb();
181159
__asm__ __volatile__(
182160
" andnot %5,7,%4\n"
183161
" inswl %1,%5,%1\n"
@@ -195,7 +173,6 @@ ____cmpxchg(_u16, volatile short *m, unsigned short old, unsigned short new)
195173
".previous"
196174
: "=&r" (prev), "=&r" (new), "=&r" (tmp), "=&r" (cmp), "=&r" (addr64)
197175
: "r" ((long)m), "Ir" (old), "1" (new) : "memory");
198-
smp_mb();
199176

200177
return prev;
201178
}
@@ -205,7 +182,6 @@ ____cmpxchg(_u32, volatile int *m, int old, int new)
205182
{
206183
unsigned long prev, cmp;
207184

208-
smp_mb();
209185
__asm__ __volatile__(
210186
"1: ldl_l %0,%5\n"
211187
" cmpeq %0,%3,%1\n"
@@ -219,7 +195,6 @@ ____cmpxchg(_u32, volatile int *m, int old, int new)
219195
".previous"
220196
: "=&r"(prev), "=&r"(cmp), "=m"(*m)
221197
: "r"((long) old), "r"(new), "m"(*m) : "memory");
222-
smp_mb();
223198

224199
return prev;
225200
}
@@ -229,7 +204,6 @@ ____cmpxchg(_u64, volatile long *m, unsigned long old, unsigned long new)
229204
{
230205
unsigned long prev, cmp;
231206

232-
smp_mb();
233207
__asm__ __volatile__(
234208
"1: ldq_l %0,%5\n"
235209
" cmpeq %0,%3,%1\n"
@@ -243,7 +217,6 @@ ____cmpxchg(_u64, volatile long *m, unsigned long old, unsigned long new)
243217
".previous"
244218
: "=&r"(prev), "=&r"(cmp), "=m"(*m)
245219
: "r"((long) old), "r"(new), "m"(*m) : "memory");
246-
smp_mb();
247220

248221
return prev;
249222
}

0 commit comments

Comments
 (0)