x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
authorUros Bizjak <ubizjak@gmail.com>
Thu, 3 Apr 2025 12:50:45 +0000 (14:50 +0200)
committerIngo Molnar <mingo@kernel.org>
Thu, 3 Apr 2025 14:28:38 +0000 (16:28 +0200)
Current minimum required version of binutils is 2.25,
which supports MONITOR and MWAIT instruction mnemonics.

Replace the byte-wise specification of MONITOR and
MWAIT with these proper mnemonics.

No functional change intended.

Note: LLVM assembler is not able to assemble correct forms of MONITOR
and MWAIT instructions with explicit operands and reports:

  error: invalid operand for instruction
          monitor %rax,%ecx,%edx
                       ^~~~
  # https://lore.kernel.org/oe-kbuild-all/202504030802.2lEVBSpN-lkp@intel.com/

Use instruction mnemonics with implicit operands to
work around this issue.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20250403125111.429805-1-ubizjak@gmail.com
arch/x86/include/asm/mwait.h

index 44d3bb2a259de62d586e7833f6df67707015bcc0..dd2b129b0418e79f9517e1c38ff390f9e75d7e1d 100644 (file)
 
 static __always_inline void __monitor(const void *eax, u32 ecx, u32 edx)
 {
-       /* "monitor %eax, %ecx, %edx;" */
-       asm volatile(".byte 0x0f, 0x01, 0xc8;"
-                    :: "a" (eax), "c" (ecx), "d"(edx));
+       /*
+        * Use the instruction mnemonic with implicit operands, as the LLVM
+        * assembler fails to assemble the mnemonic with explicit operands:
+        */
+       asm volatile("monitor" :: "a" (eax), "c" (ecx), "d" (edx));
 }
 
 static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx)
@@ -43,9 +45,11 @@ static __always_inline void __mwait(u32 eax, u32 ecx)
 {
        mds_idle_clear_cpu_buffers();
 
-       /* "mwait %eax, %ecx;" */
-       asm volatile(".byte 0x0f, 0x01, 0xc9;"
-                    :: "a" (eax), "c" (ecx));
+       /*
+        * Use the instruction mnemonic with implicit operands, as the LLVM
+        * assembler fails to assemble the mnemonic with explicit operands:
+        */
+       asm volatile("mwait" :: "a" (eax), "c" (ecx));
 }
 
 /*
@@ -95,9 +99,8 @@ static __always_inline void __mwaitx(u32 eax, u32 ebx, u32 ecx)
 static __always_inline void __sti_mwait(u32 eax, u32 ecx)
 {
        mds_idle_clear_cpu_buffers();
-       /* "mwait %eax, %ecx;" */
-       asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
-                    :: "a" (eax), "c" (ecx));
+
+       asm volatile("sti; mwait" :: "a" (eax), "c" (ecx));
 }
 
 /*