Skip to content

Commit 5498872

Browse files
committed
locking/barriers: Use '__unqual_scalar_typeof' for load-acquire macros
Passing volatile-qualified pointers to the asm-generic implementations of the load-acquire macros results in a re-load from the stack due to the temporary result variable inheriting the volatile semantics thanks to the use of 'typeof()'. Define these temporary variables using 'unqual_scalar_typeof' to drop the volatile qualifier in the case that they are scalar types. Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Arnd Bergmann <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent dee081b commit 5498872

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

include/asm-generic/barrier.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ do { \
128128
#ifndef __smp_load_acquire
129129
#define __smp_load_acquire(p) \
130130
({ \
131-
typeof(*p) ___p1 = READ_ONCE(*p); \
131+
__unqual_scalar_typeof(*p) ___p1 = READ_ONCE(*p); \
132132
compiletime_assert_atomic_type(*p); \
133133
__smp_mb(); \
134-
___p1; \
134+
(typeof(*p))___p1; \
135135
})
136136
#endif
137137

@@ -183,10 +183,10 @@ do { \
183183
#ifndef smp_load_acquire
184184
#define smp_load_acquire(p) \
185185
({ \
186-
typeof(*p) ___p1 = READ_ONCE(*p); \
186+
__unqual_scalar_typeof(*p) ___p1 = READ_ONCE(*p); \
187187
compiletime_assert_atomic_type(*p); \
188188
barrier(); \
189-
___p1; \
189+
(typeof(*p))___p1; \
190190
})
191191
#endif
192192

@@ -229,14 +229,14 @@ do { \
229229
#ifndef smp_cond_load_relaxed
230230
#define smp_cond_load_relaxed(ptr, cond_expr) ({ \
231231
typeof(ptr) __PTR = (ptr); \
232-
typeof(*ptr) VAL; \
232+
__unqual_scalar_typeof(*ptr) VAL; \
233233
for (;;) { \
234234
VAL = READ_ONCE(*__PTR); \
235235
if (cond_expr) \
236236
break; \
237237
cpu_relax(); \
238238
} \
239-
VAL; \
239+
(typeof(*ptr))VAL; \
240240
})
241241
#endif
242242

@@ -250,10 +250,10 @@ do { \
250250
*/
251251
#ifndef smp_cond_load_acquire
252252
#define smp_cond_load_acquire(ptr, cond_expr) ({ \
253-
typeof(*ptr) _val; \
253+
__unqual_scalar_typeof(*ptr) _val; \
254254
_val = smp_cond_load_relaxed(ptr, cond_expr); \
255255
smp_acquire__after_ctrl_dep(); \
256-
_val; \
256+
(typeof(*ptr))_val; \
257257
})
258258
#endif
259259

0 commit comments

Comments
 (0)