aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-powerpc/spinlock.h
diff options
context:
space:
mode:
authorAnton Blanchard <anton@samba.org>2006-01-12 23:37:17 -0500
committerPaul Mackerras <paulus@samba.org>2006-01-13 05:18:50 -0500
commit144b9c135b963bcb7f242c7b83bff930620d3161 (patch)
tree4b454f3e5e5921c5a528131dfa51df542259d918 /include/asm-powerpc/spinlock.h
parent3356bb9f7ba378a6e2709f9df95f4ea52111f4df (diff)
[PATCH] powerpc: use lwsync in atomics, bitops, lock functions
eieio is only a store - store ordering. When used to order an unlock operation loads may leak out of the critical region. This is potentially buggy, one example is if a user wants to atomically read a couple of values. We can solve this with an lwsync which orders everything except store - load. I removed the (now unused) EIEIO_ON_SMP macros and the c versions isync_on_smp and eieio_on_smp now we dont use them. I also removed some old comments that were used to identify inline spinlocks in assembly, they dont make sense now our locks are out of line. Another interesting thing was that read_unlock was using an eieio even though the rest of the spinlock code had already been converted to use lwsync. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'include/asm-powerpc/spinlock.h')
-rw-r--r--include/asm-powerpc/spinlock.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/include/asm-powerpc/spinlock.h b/include/asm-powerpc/spinlock.h
index 26b8744ed529..895cb6d3a42a 100644
--- a/include/asm-powerpc/spinlock.h
+++ b/include/asm-powerpc/spinlock.h
@@ -46,7 +46,7 @@ static __inline__ unsigned long __spin_trylock(raw_spinlock_t *lock)
46 46
47 token = LOCK_TOKEN; 47 token = LOCK_TOKEN;
48 __asm__ __volatile__( 48 __asm__ __volatile__(
49"1: lwarx %0,0,%2 # __spin_trylock\n\ 49"1: lwarx %0,0,%2\n\
50 cmpwi 0,%0,0\n\ 50 cmpwi 0,%0,0\n\
51 bne- 2f\n\ 51 bne- 2f\n\
52 stwcx. %1,0,%2\n\ 52 stwcx. %1,0,%2\n\
@@ -124,8 +124,8 @@ static void __inline__ __raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long
124 124
125static __inline__ void __raw_spin_unlock(raw_spinlock_t *lock) 125static __inline__ void __raw_spin_unlock(raw_spinlock_t *lock)
126{ 126{
127 __asm__ __volatile__(SYNC_ON_SMP" # __raw_spin_unlock" 127 __asm__ __volatile__("# __raw_spin_unlock\n\t"
128 : : :"memory"); 128 LWSYNC_ON_SMP: : :"memory");
129 lock->slock = 0; 129 lock->slock = 0;
130} 130}
131 131
@@ -167,7 +167,7 @@ static long __inline__ __read_trylock(raw_rwlock_t *rw)
167 long tmp; 167 long tmp;
168 168
169 __asm__ __volatile__( 169 __asm__ __volatile__(
170"1: lwarx %0,0,%1 # read_trylock\n" 170"1: lwarx %0,0,%1\n"
171 __DO_SIGN_EXTEND 171 __DO_SIGN_EXTEND
172" addic. %0,%0,1\n\ 172" addic. %0,%0,1\n\
173 ble- 2f\n" 173 ble- 2f\n"
@@ -192,7 +192,7 @@ static __inline__ long __write_trylock(raw_rwlock_t *rw)
192 192
193 token = WRLOCK_TOKEN; 193 token = WRLOCK_TOKEN;
194 __asm__ __volatile__( 194 __asm__ __volatile__(
195"1: lwarx %0,0,%2 # write_trylock\n\ 195"1: lwarx %0,0,%2\n\
196 cmpwi 0,%0,0\n\ 196 cmpwi 0,%0,0\n\
197 bne- 2f\n" 197 bne- 2f\n"
198 PPC405_ERR77(0,%1) 198 PPC405_ERR77(0,%1)
@@ -249,8 +249,9 @@ static void __inline__ __raw_read_unlock(raw_rwlock_t *rw)
249 long tmp; 249 long tmp;
250 250
251 __asm__ __volatile__( 251 __asm__ __volatile__(
252 "eieio # read_unlock\n\ 252 "# read_unlock\n\t"
2531: lwarx %0,0,%1\n\ 253 LWSYNC_ON_SMP
254"1: lwarx %0,0,%1\n\
254 addic %0,%0,-1\n" 255 addic %0,%0,-1\n"
255 PPC405_ERR77(0,%1) 256 PPC405_ERR77(0,%1)
256" stwcx. %0,0,%1\n\ 257" stwcx. %0,0,%1\n\
@@ -262,8 +263,8 @@ static void __inline__ __raw_read_unlock(raw_rwlock_t *rw)
262 263
263static __inline__ void __raw_write_unlock(raw_rwlock_t *rw) 264static __inline__ void __raw_write_unlock(raw_rwlock_t *rw)
264{ 265{
265 __asm__ __volatile__(SYNC_ON_SMP" # write_unlock" 266 __asm__ __volatile__("# write_unlock\n\t"
266 : : :"memory"); 267 LWSYNC_ON_SMP: : :"memory");
267 rw->lock = 0; 268 rw->lock = 0;
268} 269}
269 270