Re: [PATCH 1/2] x86/percpu: Fix "multiple identical address spaces specified for type" clang warning

From: Nathan Chancellor
Date: Thu May 30 2024 - 11:58:07 EST


On Sun, May 26, 2024 at 07:55:52PM +0200, Uros Bizjak wrote:
> The clang build with named address spaces enabled currently fails with:
>
> error: multiple identical address spaces specified for type [-Werror,-Wduplicate-decl-specifier]
>
> The warning is emitted when accessing const_pcpu_hot structure,
> which is already declared in __seg_gs named address space.
>
> Use specialized accessor for __raw_cpu_read_const() instead, avoiding
> redeclaring __seg_gs named address space via __raw_cpu_read().
>
> Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>

Thanks, this resolves the warning for me when patch 2 is applied.

Acked-by: Nathan Chancellor <nathan@xxxxxxxxxx>

However, as both of us have noticed [1][2], there is a problem in LLVM's
x86 backend with the address space casting that the kernel does, so
patch 2 should not be merged.

[1]: https://github.com/ClangBuiltLinux/linux/issues/2013
[2]: https://github.com/llvm/llvm-project/issues/93449

> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Borislav Petkov <bp@xxxxxxxxx>
> Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
> Cc: Nathan Chancellor <nathan@xxxxxxxxxx>
> Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
> Cc: Bill Wendling <morbo@xxxxxxxxxx>
> Cc: Justin Stitt <justinstitt@xxxxxxxxxx>
> ---
> arch/x86/include/asm/percpu.h | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
> index c55a79d5feae..aeea5c8a17de 100644
> --- a/arch/x86/include/asm/percpu.h
> +++ b/arch/x86/include/asm/percpu.h
> @@ -160,7 +160,10 @@ do { \
> *(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)) = (val); \
> } while (0)
>
> -#define __raw_cpu_read_const(pcp) __raw_cpu_read(, , pcp)
> +#define __raw_cpu_read_const(pcp) \
> +({ \
> + *(typeof(pcp) *)(__force uintptr_t)(&(pcp)); \
> +})
>
> #else /* !CONFIG_USE_X86_SEG_SUPPORT: */
>
> --
> 2.42.0
>