Re: [PATCH -tip] x86/idle: Work around LLVM assembler bug with MONITOR and MWAIT insn

From: Borislav Petkov
Date: Thu Apr 03 2025 - 04:25:53 EST


On Thu, Apr 03, 2025 at 09:04:37AM +0200, Uros Bizjak wrote:
> LLVM assembler is not able to assemble correct forms of MONITOR
> and MWAIT instructions with explicit operands:
>
> error: invalid operand for instruction
> monitor %rax,%ecx,%edx
> ^~~~
>
> Use instruction mnemonics with implicit operands when LLVM assembler
> is detected to work around this issue.
>
> Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
> 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>
> Fixes: cd3b85b27542 ("x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>")

No, you should whack that one - the toolchains are clearly not ready yet...

> +#ifdef CONFIG_LD_IS_LLD
> +# define ASM_MONITOR "monitor"
> +# define ASM_MWAIT "mwait"
> +#else
> +# define ASM_MONITOR "monitor %[eax], %[ecx], %[edx]"
> +# define ASM_MWAIT "mwait %[eax], %[ecx]"
> +#endif

... instead of piling more ifdeffery ontop and making the code uglier than
before.

Go fix the LLVM assembler to deal with explicit operands or GCC and LLVM
should agree on common syntax they both assemble or whatever and the kernel
should do *one* thing exactly and not carry toolchain-specific ifdeffery at
every spot.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette