Skip to content

Commit 10223c5

Browse files
committed
arm64: barrier: Use '__unqual_scalar_typeof' for acquire/release macros
Passing volatile-qualified pointers to the arm64 implementations of the load-acquire/store-release macros results in a re-load from the stack and a bunch of associated stack-protector churn 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]> Acked-by: Mark Rutland <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 5498872 commit 10223c5

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

arch/arm64/include/asm/barrier.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ static inline unsigned long array_index_mask_nospec(unsigned long idx,
7676
#define __smp_store_release(p, v) \
7777
do { \
7878
typeof(p) __p = (p); \
79-
union { typeof(*p) __val; char __c[1]; } __u = \
80-
{ .__val = (__force typeof(*p)) (v) }; \
79+
union { __unqual_scalar_typeof(*p) __val; char __c[1]; } __u = \
80+
{ .__val = (__force __unqual_scalar_typeof(*p)) (v) }; \
8181
compiletime_assert_atomic_type(*p); \
8282
kasan_check_write(__p, sizeof(*p)); \
8383
switch (sizeof(*p)) { \
@@ -110,7 +110,7 @@ do { \
110110

111111
#define __smp_load_acquire(p) \
112112
({ \
113-
union { typeof(*p) __val; char __c[1]; } __u; \
113+
union { __unqual_scalar_typeof(*p) __val; char __c[1]; } __u; \
114114
typeof(p) __p = (p); \
115115
compiletime_assert_atomic_type(*p); \
116116
kasan_check_read(__p, sizeof(*p)); \
@@ -136,33 +136,33 @@ do { \
136136
: "Q" (*__p) : "memory"); \
137137
break; \
138138
} \
139-
__u.__val; \
139+
(typeof(*p))__u.__val; \
140140
})
141141

142142
#define smp_cond_load_relaxed(ptr, cond_expr) \
143143
({ \
144144
typeof(ptr) __PTR = (ptr); \
145-
typeof(*ptr) VAL; \
145+
__unqual_scalar_typeof(*ptr) VAL; \
146146
for (;;) { \
147147
VAL = READ_ONCE(*__PTR); \
148148
if (cond_expr) \
149149
break; \
150150
__cmpwait_relaxed(__PTR, VAL); \
151151
} \
152-
VAL; \
152+
(typeof(*ptr))VAL; \
153153
})
154154

155155
#define smp_cond_load_acquire(ptr, cond_expr) \
156156
({ \
157157
typeof(ptr) __PTR = (ptr); \
158-
typeof(*ptr) VAL; \
158+
__unqual_scalar_typeof(*ptr) VAL; \
159159
for (;;) { \
160160
VAL = smp_load_acquire(__PTR); \
161161
if (cond_expr) \
162162
break; \
163163
__cmpwait_relaxed(__PTR, VAL); \
164164
} \
165-
VAL; \
165+
(typeof(*ptr))VAL; \
166166
})
167167

168168
#include <asm-generic/barrier.h>

0 commit comments

Comments
 (0)