Skip to content

Commit 51f5fd2

Browse files
wildea01acmel
authored andcommitted
tools headers barrier: Fix arm64 tools build failure wrt smp_load_{acquire,release}
Cheers for reporting this. I managed to reproduce the build failure with gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1). The code in question is the arm64 versions of smp_load_acquire() and smp_store_release(). Unlike other architectures, these are not built around READ_ONCE() and WRITE_ONCE() since we have instructions we can use instead of fences. Bringing our macros up-to-date with those (i.e. tweaking the union initialisation and using the special "uXX_alias_t" types) appears to fix the issue for me. Committer notes: Testing it in the systems previously failing: # time dm android-ndk:r12b-arm \ android-ndk:r15c-arm \ debian:experimental-x-arm64 \ ubuntu:14.04.4-x-linaro-arm64 \ ubuntu:16.04-x-arm \ ubuntu:16.04-x-arm64 \ ubuntu:18.04-x-arm \ ubuntu:18.04-x-arm64 1 android-ndk:r12b-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 2 android-ndk:r15c-arm : Ok arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease) 3 debian:experimental-x-arm64 : Ok aarch64-linux-gnu-gcc (Debian 8.2.0-7) 8.2.0 4 ubuntu:14.04.4-x-linaro-arm64 : Ok aarch64-linux-gnu-gcc (Linaro GCC 5.5-2017.10) 5.5.0 5 ubuntu:16.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 6 ubuntu:16.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 7 ubuntu:18.04-x-arm : Ok arm-linux-gnueabihf-gcc (Ubuntu/Linaro 7.3.0-27ubuntu1~18.04) 7.3.0 8 ubuntu:18.04-x-arm64 : Ok aarch64-linux-gnu-gcc (Ubuntu/Linaro 7.3.0-27ubuntu1~18.04) 7.3.0 Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Will Deacon <will.deacon@arm.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Tested-by: Daniel Borkmann <daniel@iogearbox.net> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20181031174408.GA27871@arm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 29995d2 commit 51f5fd2

1 file changed

Lines changed: 67 additions & 66 deletions

File tree

‎tools/arch/arm64/include/asm/barrier.h‎

Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,75 @@
1414
#define wmb() asm volatile("dmb ishst" ::: "memory")
1515
#define rmb() asm volatile("dmb ishld" ::: "memory")
1616

17-
#define smp_store_release(p, v) \
18-
do { \
19-
union { typeof(*p) __val; char __c[1]; } __u = \
20-
{ .__val = (__force typeof(*p)) (v) }; \
21-
\
22-
switch (sizeof(*p)) { \
23-
case 1: \
24-
asm volatile ("stlrb %w1, %0" \
25-
: "=Q" (*p) \
26-
: "r" (*(__u8 *)__u.__c) \
27-
: "memory"); \
28-
break; \
29-
case 2: \
30-
asm volatile ("stlrh %w1, %0" \
31-
: "=Q" (*p) \
32-
: "r" (*(__u16 *)__u.__c) \
33-
: "memory"); \
34-
break; \
35-
case 4: \
36-
asm volatile ("stlr %w1, %0" \
37-
: "=Q" (*p) \
38-
: "r" (*(__u32 *)__u.__c) \
39-
: "memory"); \
40-
break; \
41-
case 8: \
42-
asm volatile ("stlr %1, %0" \
43-
: "=Q" (*p) \
44-
: "r" (*(__u64 *)__u.__c) \
45-
: "memory"); \
46-
break; \
47-
default: \
48-
/* Only to shut up gcc ... */ \
49-
mb(); \
50-
break; \
51-
} \
17+
#define smp_store_release(p, v) \
18+
do { \
19+
union { typeof(*p) __val; char __c[1]; } __u = \
20+
{ .__val = (v) }; \
21+
\
22+
switch (sizeof(*p)) { \
23+
case 1: \
24+
asm volatile ("stlrb %w1, %0" \
25+
: "=Q" (*p) \
26+
: "r" (*(__u8_alias_t *)__u.__c) \
27+
: "memory"); \
28+
break; \
29+
case 2: \
30+
asm volatile ("stlrh %w1, %0" \
31+
: "=Q" (*p) \
32+
: "r" (*(__u16_alias_t *)__u.__c) \
33+
: "memory"); \
34+
break; \
35+
case 4: \
36+
asm volatile ("stlr %w1, %0" \
37+
: "=Q" (*p) \
38+
: "r" (*(__u32_alias_t *)__u.__c) \
39+
: "memory"); \
40+
break; \
41+
case 8: \
42+
asm volatile ("stlr %1, %0" \
43+
: "=Q" (*p) \
44+
: "r" (*(__u64_alias_t *)__u.__c) \
45+
: "memory"); \
46+
break; \
47+
default: \
48+
/* Only to shut up gcc ... */ \
49+
mb(); \
50+
break; \
51+
} \
5252
} while (0)
5353

54-
#define smp_load_acquire(p) \
55-
({ \
56-
union { typeof(*p) __val; char __c[1]; } __u; \
57-
\
58-
switch (sizeof(*p)) { \
59-
case 1: \
60-
asm volatile ("ldarb %w0, %1" \
61-
: "=r" (*(__u8 *)__u.__c) \
62-
: "Q" (*p) : "memory"); \
63-
break; \
64-
case 2: \
65-
asm volatile ("ldarh %w0, %1" \
66-
: "=r" (*(__u16 *)__u.__c) \
67-
: "Q" (*p) : "memory"); \
68-
break; \
69-
case 4: \
70-
asm volatile ("ldar %w0, %1" \
71-
: "=r" (*(__u32 *)__u.__c) \
72-
: "Q" (*p) : "memory"); \
73-
break; \
74-
case 8: \
75-
asm volatile ("ldar %0, %1" \
76-
: "=r" (*(__u64 *)__u.__c) \
77-
: "Q" (*p) : "memory"); \
78-
break; \
79-
default: \
80-
/* Only to shut up gcc ... */ \
81-
mb(); \
82-
break; \
83-
} \
84-
__u.__val; \
54+
#define smp_load_acquire(p) \
55+
({ \
56+
union { typeof(*p) __val; char __c[1]; } __u = \
57+
{ .__c = { 0 } }; \
58+
\
59+
switch (sizeof(*p)) { \
60+
case 1: \
61+
asm volatile ("ldarb %w0, %1" \
62+
: "=r" (*(__u8_alias_t *)__u.__c) \
63+
: "Q" (*p) : "memory"); \
64+
break; \
65+
case 2: \
66+
asm volatile ("ldarh %w0, %1" \
67+
: "=r" (*(__u16_alias_t *)__u.__c) \
68+
: "Q" (*p) : "memory"); \
69+
break; \
70+
case 4: \
71+
asm volatile ("ldar %w0, %1" \
72+
: "=r" (*(__u32_alias_t *)__u.__c) \
73+
: "Q" (*p) : "memory"); \
74+
break; \
75+
case 8: \
76+
asm volatile ("ldar %0, %1" \
77+
: "=r" (*(__u64_alias_t *)__u.__c) \
78+
: "Q" (*p) : "memory"); \
79+
break; \
80+
default: \
81+
/* Only to shut up gcc ... */ \
82+
mb(); \
83+
break; \
84+
} \
85+
__u.__val; \
8586
})
8687

8788
#endif /* _TOOLS_LINUX_ASM_AARCH64_BARRIER_H */

0 commit comments

Comments
 (0)