2021-05-28 18:30:57

by Nathan Chancellor

[permalink] [raw]
Subject: [PATCH] powerpc/barrier: Avoid collision with clang's __lwsync macro

A change in clang 13 results in the __lwsync macro being defined as
__builtin_ppc_lwsync, which emits 'lwsync' or 'msync' depending on what
the target supports. This breaks the build because of -Werror in
arch/powerpc, along with thousands of warnings:

In file included from arch/powerpc/kernel/pmc.c:12:
In file included from include/linux/bug.h:5:
In file included from arch/powerpc/include/asm/bug.h:109:
In file included from include/asm-generic/bug.h:20:
In file included from include/linux/kernel.h:12:
In file included from include/linux/bitops.h:32:
In file included from arch/powerpc/include/asm/bitops.h:62:
arch/powerpc/include/asm/barrier.h:49:9: error: '__lwsync' macro redefined [-Werror,-Wmacro-redefined]
#define __lwsync() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
^
<built-in>:308:9: note: previous definition is here
#define __lwsync __builtin_ppc_lwsync
^
1 error generated.

Undefine this macro so that the runtime patching introduced by
commit 2d1b2027626d ("powerpc: Fixup lwsync at runtime") continues to
work properly with clang and the build no longer breaks.

Cc: [email protected]
Link: https://github.com/ClangBuiltLinux/linux/issues/1386
Link: https://github.com/llvm/llvm-project/commit/62b5df7fe2b3fda1772befeda15598fbef96a614
Signed-off-by: Nathan Chancellor <[email protected]>
---
arch/powerpc/include/asm/barrier.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
index 7ae29cfb06c0..f0e687236484 100644
--- a/arch/powerpc/include/asm/barrier.h
+++ b/arch/powerpc/include/asm/barrier.h
@@ -46,6 +46,8 @@
# define SMPWMB eieio
#endif

+/* clang defines this macro for a builtin, which will not work with runtime patching */
+#undef __lwsync
#define __lwsync() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
#define dma_rmb() __lwsync()
#define dma_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")

base-commit: 97e5bf604b7a0d6e1b3e00fe31d5fd4b9bffeaae
--
2.32.0.rc0


2021-06-01 18:26:08

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH] powerpc/barrier: Avoid collision with clang's __lwsync macro

On Fri, May 28, 2021 at 11:29 AM Nathan Chancellor <[email protected]> wrote:
>
> A change in clang 13 results in the __lwsync macro being defined as
> __builtin_ppc_lwsync, which emits 'lwsync' or 'msync' depending on what
> the target supports.

Indeed,
$ clang --target=powerpc64le-linux-gnu -mcpu=e500 -m32
for example.

Thanks for the patch!
Reviewed-by: Nick Desaulniers <[email protected]>

> This breaks the build because of -Werror in
> arch/powerpc, along with thousands of warnings:
>
> In file included from arch/powerpc/kernel/pmc.c:12:
> In file included from include/linux/bug.h:5:
> In file included from arch/powerpc/include/asm/bug.h:109:
> In file included from include/asm-generic/bug.h:20:
> In file included from include/linux/kernel.h:12:
> In file included from include/linux/bitops.h:32:
> In file included from arch/powerpc/include/asm/bitops.h:62:
> arch/powerpc/include/asm/barrier.h:49:9: error: '__lwsync' macro redefined [-Werror,-Wmacro-redefined]
> #define __lwsync() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
> ^
> <built-in>:308:9: note: previous definition is here
> #define __lwsync __builtin_ppc_lwsync
> ^
> 1 error generated.
>
> Undefine this macro so that the runtime patching introduced by
> commit 2d1b2027626d ("powerpc: Fixup lwsync at runtime") continues to
> work properly with clang and the build no longer breaks.
>
> Cc: [email protected]
> Link: https://github.com/ClangBuiltLinux/linux/issues/1386
> Link: https://github.com/llvm/llvm-project/commit/62b5df7fe2b3fda1772befeda15598fbef96a614
> Signed-off-by: Nathan Chancellor <[email protected]>
> ---
> arch/powerpc/include/asm/barrier.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
> index 7ae29cfb06c0..f0e687236484 100644
> --- a/arch/powerpc/include/asm/barrier.h
> +++ b/arch/powerpc/include/asm/barrier.h
> @@ -46,6 +46,8 @@
> # define SMPWMB eieio
> #endif
>
> +/* clang defines this macro for a builtin, which will not work with runtime patching */
> +#undef __lwsync
> #define __lwsync() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
> #define dma_rmb() __lwsync()
> #define dma_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
>
> base-commit: 97e5bf604b7a0d6e1b3e00fe31d5fd4b9bffeaae
> --
> 2.32.0.rc0
>


--
Thanks,
~Nick Desaulniers

2021-06-18 06:21:05

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH] powerpc/barrier: Avoid collision with clang's __lwsync macro

On Fri, 28 May 2021 11:27:52 -0700, Nathan Chancellor wrote:
> A change in clang 13 results in the __lwsync macro being defined as
> __builtin_ppc_lwsync, which emits 'lwsync' or 'msync' depending on what
> the target supports. This breaks the build because of -Werror in
> arch/powerpc, along with thousands of warnings:
>
> In file included from arch/powerpc/kernel/pmc.c:12:
> In file included from include/linux/bug.h:5:
> In file included from arch/powerpc/include/asm/bug.h:109:
> In file included from include/asm-generic/bug.h:20:
> In file included from include/linux/kernel.h:12:
> In file included from include/linux/bitops.h:32:
> In file included from arch/powerpc/include/asm/bitops.h:62:
> arch/powerpc/include/asm/barrier.h:49:9: error: '__lwsync' macro redefined [-Werror,-Wmacro-redefined]
> #define __lwsync() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
> ^
> <built-in>:308:9: note: previous definition is here
> #define __lwsync __builtin_ppc_lwsync
> ^
> 1 error generated.
>
> [...]

Applied to powerpc/next.

[1/1] powerpc/barrier: Avoid collision with clang's __lwsync macro
https://git.kernel.org/powerpc/c/015d98149b326e0f1f02e44413112ca8b4330543

cheers