Skip to content

Commit 1f1a739

Browse files
chleroySasha Levin
authored and
Sasha Levin
committed
powerpc: Fix eh field when calling lwarx on PPC32
commit 18db466 upstream. Commit 9401f4e ("powerpc: Use lwarx/ldarx directly instead of PPC_LWARX/LDARX macros") properly handled the eh field of lwarx in asm/bitops.h but failed to clear it for PPC32 in asm/simple_spinlock.h So, do as in arch_atomic_try_cmpxchg_lock(), set it to 1 if PPC64 but set it to 0 if PPC32. For that use IS_ENABLED(CONFIG_PPC64) which returns 1 when CONFIG_PPC64 is set and 0 otherwise. Fixes: 9401f4e ("powerpc: Use lwarx/ldarx directly instead of PPC_LWARX/LDARX macros") Cc: [email protected] # v5.15+ Reported-by: Pali Rohár <[email protected]> Signed-off-by: Christophe Leroy <[email protected]> Tested-by: Pali Rohár <[email protected]> Reviewed-by: Segher Boessenkool <[email protected]> [mpe: Use symbolic names, use 'n' constraint per Segher] Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/a1176e19e627dd6a1b8d24c6c457a8ab874b7d12.1659430931.git.christophe.leroy@csgroup.eu Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 470ab1d commit 1f1a739

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

arch/powerpc/include/asm/simple_spinlock.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@ static inline int arch_spin_is_locked(arch_spinlock_t *lock)
4848
static inline unsigned long __arch_spin_trylock(arch_spinlock_t *lock)
4949
{
5050
unsigned long tmp, token;
51+
unsigned int eh = IS_ENABLED(CONFIG_PPC64);
5152

5253
token = LOCK_TOKEN;
5354
__asm__ __volatile__(
54-
"1: lwarx %0,0,%2,1\n\
55+
"1: lwarx %0,0,%2,%[eh]\n\
5556
cmpwi 0,%0,0\n\
5657
bne- 2f\n\
5758
stwcx. %1,0,%2\n\
5859
bne- 1b\n"
5960
PPC_ACQUIRE_BARRIER
6061
"2:"
6162
: "=&r" (tmp)
62-
: "r" (token), "r" (&lock->slock)
63+
: "r" (token), "r" (&lock->slock), [eh] "n" (eh)
6364
: "cr0", "memory");
6465

6566
return tmp;
@@ -156,17 +157,18 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
156157
static inline long __arch_read_trylock(arch_rwlock_t *rw)
157158
{
158159
long tmp;
160+
unsigned int eh = IS_ENABLED(CONFIG_PPC64);
159161

160162
__asm__ __volatile__(
161-
"1: lwarx %0,0,%1,1\n"
163+
"1: lwarx %0,0,%1,%[eh]\n"
162164
__DO_SIGN_EXTEND
163165
" addic. %0,%0,1\n\
164166
ble- 2f\n"
165167
" stwcx. %0,0,%1\n\
166168
bne- 1b\n"
167169
PPC_ACQUIRE_BARRIER
168170
"2:" : "=&r" (tmp)
169-
: "r" (&rw->lock)
171+
: "r" (&rw->lock), [eh] "n" (eh)
170172
: "cr0", "xer", "memory");
171173

172174
return tmp;
@@ -179,17 +181,18 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
179181
static inline long __arch_write_trylock(arch_rwlock_t *rw)
180182
{
181183
long tmp, token;
184+
unsigned int eh = IS_ENABLED(CONFIG_PPC64);
182185

183186
token = WRLOCK_TOKEN;
184187
__asm__ __volatile__(
185-
"1: lwarx %0,0,%2,1\n\
188+
"1: lwarx %0,0,%2,%[eh]\n\
186189
cmpwi 0,%0,0\n\
187190
bne- 2f\n"
188191
" stwcx. %1,0,%2\n\
189192
bne- 1b\n"
190193
PPC_ACQUIRE_BARRIER
191194
"2:" : "=&r" (tmp)
192-
: "r" (token), "r" (&rw->lock)
195+
: "r" (token), "r" (&rw->lock), [eh] "n" (eh)
193196
: "cr0", "memory");
194197

195198
return tmp;

0 commit comments

Comments
 (0)