Skip to contentSkip to conversation

x86/idle: Work around LLVM assembler bug with MONITOR and MWAIT insn

PATCH In review Uros Bizjak 3 participants 3 messages Apr 3, 2025 x86

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/idle: Work around LLVM assembler bug with MONITOR and MWAIT insn

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 to work around this issue.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Fixes cd3b85b27542 ("x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>")

---
v2: Use instruction mnemonics with implicit operands.

---
 arch/x86/include/asm/mwait.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/include/asm/mwait.h +3 -3
index 5141d2acc0ef..8f2cfc9cc3d8 100644
@@ -27,7 +27,7 @@
 
 static __always_inline void __monitor(const void *eax, u32 ecx, u32 edx)
 {
-	asm volatile("monitor %0, %1, %2" :: "a" (eax), "c" (ecx), "d" (edx));
+	asm volatile("monitor" :: "a" (eax), "c" (ecx), "d" (edx));
 }
 
 static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx)
@@ -41,7 +41,7 @@ static __always_inline void __mwait(u32 eax, u32 ecx)
 {
 	mds_idle_clear_cpu_buffers();
 
-	asm volatile("mwait %0, %1" :: "a" (eax), "c" (ecx));
+	asm volatile("mwait" :: "a" (eax), "c" (ecx));
 }
 
 /*
@@ -92,7 +92,7 @@ static __always_inline void __sti_mwait(u32 eax, u32 ecx)
 {
 	mds_idle_clear_cpu_buffers();
 
-	asm volatile("sti; mwait %0, %1" :: "a" (eax), "c" (ecx));
+	asm volatile("sti; mwait" :: "a" (eax), "c" (ecx));
 }
 
 /*
Signature · 1 line
2.49.0
#1 lore raw
Quoted 10 lines · Uros Bizjak

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 to work around this issue.

Quoted 8 lines
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Fixes cd3b85b27542 ("x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>")

So I've zapped cd3b85b27542 instead - let's re-try it again and see if there's any code generation tradeoffs vs. the byte encodings?

Thanks,

Ingo

maintainer
#2 lore raw
Quoted 2 lines · Ingo Molnar

So I've zapped cd3b85b27542 instead - let's re-try it again and see if there's any code generation tradeoffs vs. the byte encodings?

Please.

And give the test bots some time to chew on them before committing and/or build-test with clang too.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

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