x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions
PATCH 1/4 x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions
MONITOR and MONITORX expect 32-bit unsigned integer argument in %ecx and %edx registers. MWAIT and MWAITX expect 32-bit usigned int argument in %eax and %ecx registers.
Fix the wrong argument type by changing the type of the corresponding function argument from "unsigned long" to u32.
--- arch/x86/include/asm/mwait.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
arch/x86/include/asm/mwait.h +5 -8
@@ -25,23 +25,21 @@#define TPAUSE_C01_STATE 1#define TPAUSE_C02_STATE 0 -static __always_inline void __monitor(const void *eax, unsigned long ecx, -unsigned long edx) +static __always_inline void __monitor(const void *eax, u32 ecx, u32 edx) {/* "monitor %eax, %ecx, %edx;" */ asmvolatile (".byte 0x0f, 0x01, 0xc8;" ::"a" (eax),"c" (ecx),"d" (edx)); } -static __always_inline void __monitorx(const void *eax, unsigned long ecx, -unsigned long edx) +static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx) {/* "monitorx %eax, %ecx, %edx;" */ asmvolatile (".byte 0x0f, 0x01, 0xfa;" ::"a" (eax),"c" (ecx),"d" (edx)); } -static __always_inline void __mwait(unsigned long eax, unsigned long ecx) +static __always_inline void __mwait(u32 eax, u32 ecx) {mds_idle_clear_cpu_buffers ();
@@ -76,8 +74,7 @@ static __always_inline void __mwait(unsigned long eax, unsigned long ecx)* EAX (logical) address to monitor * ECX #GP if not zero */ -static __always_inline void __mwaitx(unsigned long eax, unsigned long ebx, -unsigned long ecx) +static __always_inline void __mwaitx(u32 eax, u32 ebx, u32 ecx) {/* No MDS buffer clear as this is AMD/HYGON only */
@@ -95,7 +92,7 @@ static __always_inline void __mwaitx(unsigned long eax, unsigned long ebx,* executing mwait, it would otherwise go unnoticed and the next tick * would not be reprogrammed accordingly before mwait ever wakes up. */ -static __always_inline void __sti_mwait(unsigned long eax, unsigned long ecx) +static __always_inline void __sti_mwait(u32 eax, u32 ecx) {mds_idle_clear_cpu_buffers ();/* "mwait %eax, %ecx;" */
Signature · 1 line
2.42.0
PATCH 2/4 x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
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.
--- arch/x86/include/asm/mwait.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
arch/x86/include/asm/mwait.h +4 -9
@@ -27,9 +27,7 @@ static __always_inline void __monitor(const void *eax, u32 ecx, u32 edx) { -/* "monitor %eax, %ecx, %edx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xc8;" - ::"a" (eax),"c" (ecx),"d" (edx)); + asmvolatile ("monitor %0, %1, %2" ::"a" (eax),"c" (ecx),"d" (edx)); } static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx)
@@ -43,9 +41,7 @@ static __always_inline void __mwait(u32 eax, u32 ecx) {mds_idle_clear_cpu_buffers (); -/* "mwait %eax, %ecx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xc9;" - ::"a" (eax),"c" (ecx)); + asmvolatile ("mwait %0, %1" ::"a" (eax),"c" (ecx)); }/*
@@ -95,9 +91,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;" */ - asmvolatile ("sti; .byte 0x0f, 0x01, 0xc9;" - ::"a" (eax),"c" (ecx)); + + asmvolatile ("sti; mwait %0, %1" ::"a" (eax),"c" (ecx)); }/*
Signature · 1 line
2.42.0
[tip: x86/mm] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
The following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: cd3b85b27542968198e3d588a2bc0591930ee2ee Gitweb: https://git.kernel.org/tip/cd3b85b27542968198e3d588a2bc0591930ee2ee Author: Uros Bizjak <[email protected]> AuthorDate: Wed, 02 Apr 2025 20:08:06 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 02 Apr 2025 22:26:17 +02:00
x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
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.
--- arch/x86/include/asm/mwait.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
arch/x86/include/asm/mwait.h +4 -9
@@ -27,9 +27,7 @@ static __always_inline void __monitor(const void *eax, u32 ecx, u32 edx) { -/* "monitor %eax, %ecx, %edx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xc8;" - ::"a" (eax),"c" (ecx),"d" (edx)); + asmvolatile ("monitor %0, %1, %2" ::"a" (eax),"c" (ecx),"d" (edx)); } static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx)
@@ -43,9 +41,7 @@ static __always_inline void __mwait(u32 eax, u32 ecx) {mds_idle_clear_cpu_buffers (); -/* "mwait %eax, %ecx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xc9;" - ::"a" (eax),"c" (ecx)); + asmvolatile ("mwait %0, %1" ::"a" (eax),"c" (ecx)); }/*
@@ -95,9 +91,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;" */ - asmvolatile ("sti; .byte 0x0f, 0x01, 0xc9;" - ::"a" (eax),"c" (ecx)); + + asmvolatile ("sti; mwait %0, %1" ::"a" (eax),"c" (ecx)); }/*
Re: [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
In reply to Uros BizjakQuoted 7 lines · Uros Bizjak
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.
Hmm... Is it only me who gets these, please?
In file included from acpi/cstate.c:18:asm/mwait.h:30:15: error: invalid operand for instruction
30 | asm volatile("monitor %0, %1, %2" :: "a" (eax), "c" (ecx), "d" (edx));
| ^
<inline asm>:1:16: note: instantiated into assembly here
1 | monitor %rax, %ecx, %edx
| ^~~~~
In file included from acpi/cstate.c:18:asm/mwait.h:95:15: error: instruction requires: Not 64-bit mode
95 | asm volatile("sti; mwait %0, %1" :: "a" (eax), "c" (ecx));
| ^
<inline asm>:1:7: note: instantiated into assembly here
1 | sti; mwait %eax, %ecx
| ^
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Uros Bizjak
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.
Hmm... Is it only me who gets these, please?
Quoted 14 lines
In file included from
acpi/cstate.c:18:asm/mwait.h:30:15: error: invalid operand for instruction
30 | asmvolatile("monitor %0, %1, %2" :: "a" (eax), "c" (ecx), "d" (edx));
| ^
<inline asm>:1:16: note: instantiated into assembly here
1 | monitor %rax, %ecx, %edx
| ^~~~~
In file included fromacpi/cstate.c:18:asm/mwait.h:95:15: error: instruction requires: Not 64-bit mode
95 | asmvolatile("sti; mwait %0, %1" :: "a" (eax), "c" (ecx));
| ^
<inline asm>:1:7: note: instantiated into assembly here
1 | sti; mwait %eax, %ecx
| ^
FWIW, revert fixes the issue.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
Quoted 27 lines · Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Uros Bizjak
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.
Hmm... Is it only me who gets these, please?
Quoted 14 lines
In file included from
acpi/cstate.c:18:asm/mwait.h:30:15: error: invalid operand for instruction
30 | asmvolatile("monitor %0, %1, %2" :: "a" (eax), "c" (ecx), "d" (edx));
| ^
<inline asm>:1:16: note: instantiated into assembly here
1 | monitor %rax, %ecx, %edx
| ^~~~~
In file included fromacpi/cstate.c:18:asm/mwait.h:95:15: error: instruction requires: Not 64-bit mode
95 | asmvolatile("sti; mwait %0, %1" :: "a" (eax), "c" (ecx));
| ^
<inline asm>:1:7: note: instantiated into assembly here
1 | sti; mwait %eax, %ecx
| ^
Quoted 1 line
FWIW, revert fixes the issue.
All gone already, tomorrow's -next should be fine.
Thanks,
Ingo
Re: [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
Quoted 3 lines · Ingo Molnar
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Andy Shevchenko
On Wed, Apr 02, 2025 at 08:08:06PM +0200, Uros Bizjak wrote:
...
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 1 line
No functional change intended.
Hmm... Is it only me who gets these, please?
In file included from
acpi/cstate.c:18:asm/mwait.h:30:15: error: invalid operand for instruction
30 | asmvolatile("monitor %0, %1, %2" :: "a" (eax), "c" (ecx), "d" (edx));
| ^
<inline asm>:1:16: note: instantiated into assembly here
1 | monitor %rax, %ecx, %edx
| ^~~~~
In file included fromacpi/cstate.c:18:asm/mwait.h:95:15: error: instruction requires: Not 64-bit mode
95 | asmvolatile("sti; mwait %0, %1" :: "a" (eax), "c" (ecx));
| ^
<inline asm>:1:7: note: instantiated into assembly here
1 | sti; mwait %eax, %ecx
| ^
Quoted 3 lines
Quoted 1 line
FWIW, revert fixes the issue.
All gone already, tomorrow's -next should be fine.
Thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 3/4 x86/idle: Remove unneeded delimiters from asm templates
In reply to Uros BizjakDelimiters at the end of asm templates are not needed. Remove them to make asm instruction length calculations more accurate.
--- arch/x86/include/asm/mwait.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/x86/include/asm/mwait.h +7 -7
@@ -32,8 +32,8 @@ static __always_inline void __monitor(const void *eax, u32 ecx, u32 edx) static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx) { -/* "monitorx %eax, %ecx, %edx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xfa;" +/* "monitorx %eax, %ecx, %edx" */ + asmvolatile (".byte 0x0f, 0x01, 0xfa" ::"a" (eax),"c" (ecx),"d" (edx)); }
@@ -74,8 +74,8 @@ static __always_inline void __mwaitx(u32 eax, u32 ebx, u32 ecx) {/* No MDS buffer clear as this is AMD/HYGON only */ -/* "mwaitx %eax, %ebx, %ecx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xfb;" +/* "mwaitx %eax, %ebx, %ecx" */ + asmvolatile (".byte 0x0f, 0x01, 0xfb" ::"a" (eax),"b" (ebx),"c" (ecx)); }
@@ -133,13 +133,13 @@ static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned lo*/ static inline void __tpause (u32 ecx,u32 edx,u32 eax) { -/* "tpause %ecx, %edx, %eax;" */ +/* "tpause %ecx, %edx, %eax" */ #ifdef CONFIG_AS_TPAUSE - asmvolatile ("tpause %%ecx\n" + asmvolatile ("tpause %%ecx" : :"c" (ecx),"d" (edx),"a" (eax));#else - asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1\t\n" + asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1" : :"c" (ecx),"d" (edx),"a" (eax));#endif
Signature · 1 line
2.42.0
[tip: x86/mm] x86/idle: Remove .s output beautifying delimiters from simpler asm() templates
The following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 8ad521aaf7438e4fae996f51d02b960cc97a15a3 Gitweb: https://git.kernel.org/tip/8ad521aaf7438e4fae996f51d02b960cc97a15a3 Author: Uros Bizjak <[email protected]> AuthorDate: Wed, 02 Apr 2025 20:08:07 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 02 Apr 2025 22:36:57 +02:00
x86/idle: Remove .s output beautifying delimiters from simpler asm() templates
Delimiters in asm() templates such as ';', '\t' or '\n' are not required syntactically, they were used historically in the Linux kernel to prettify the compiler's .s output for people who were looking at compiler generated .s output.
Most x86 developers these days are primarily looking at:
1) objdump --disassemble-all .o
2) perf top's live kernel function annotation and disassembler feature that uses /dev/mem.
... because:
- this kind of assembler output is standardized regardless of compiler used,
- it's generally less messy looking,
- it gives ground-truth instead of being some intermediate layer in the toolchain that might or might not be the real deal,
- and on a live kernel it also sees through the kernel's various layers of runtime patching code obfuscation facilities, also known as: alternative-instructions, tracepoints and jump labels.
There are some cases where the .s output is the most useful tool, such as alternatives() code generation, but other than that these delimiters used in simple asm() statements mostly add noise to the source code side, which isn't desirable for assembly code that is fragile enough already.
Remove the delimiters for <asm/mwait.h>, which also happens to make the GCC inliner's asm() instruction length heuristics more accurate...
[ mingo: Wrote a new changelog to give historic context and
to give people a chance to object. :-) ]
--- arch/x86/include/asm/mwait.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/x86/include/asm/mwait.h +7 -7
@@ -32,8 +32,8 @@ static __always_inline void __monitor(const void *eax, u32 ecx, u32 edx) static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx) { -/* "monitorx %eax, %ecx, %edx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xfa;" +/* "monitorx %eax, %ecx, %edx" */ + asmvolatile (".byte 0x0f, 0x01, 0xfa" ::"a" (eax),"c" (ecx),"d" (edx)); }
@@ -74,8 +74,8 @@ static __always_inline void __mwaitx(u32 eax, u32 ebx, u32 ecx) {/* No MDS buffer clear as this is AMD/HYGON only */ -/* "mwaitx %eax, %ebx, %ecx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xfb;" +/* "mwaitx %eax, %ebx, %ecx" */ + asmvolatile (".byte 0x0f, 0x01, 0xfb" ::"a" (eax),"b" (ebx),"c" (ecx)); }
@@ -133,13 +133,13 @@ static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned lo*/ static inline void __tpause (u32 ecx,u32 edx,u32 eax) { -/* "tpause %ecx, %edx, %eax;" */ +/* "tpause %ecx, %edx, %eax" */ #ifdef CONFIG_AS_TPAUSE - asmvolatile ("tpause %%ecx\n" + asmvolatile ("tpause %%ecx" : :"c" (ecx),"d" (edx),"a" (eax));#else - asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1\t\n" + asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1" : :"c" (ecx),"d" (edx),"a" (eax));#endif
[tip: x86/mm] x86/idle: Remove .s output beautifying delimiters from simpler asm() templates
In reply to Uros BizjakThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 19c3dcd953bc8961ab486cf05f5dd45455393c42 Gitweb: https://git.kernel.org/tip/19c3dcd953bc8961ab486cf05f5dd45455393c42 Author: Uros Bizjak <[email protected]> AuthorDate: Wed, 02 Apr 2025 20:08:07 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Thu, 03 Apr 2025 13:19:18 +02:00
x86/idle: Remove .s output beautifying delimiters from simpler asm() templates
Delimiters in asm() templates such as ';', '\t' or '\n' are not required syntactically, they were used historically in the Linux kernel to prettify the compiler's .s output for people who were looking at compiler generated .s output.
Most x86 developers these days are primarily looking at:
1) objdump --disassemble-all .o
2) perf top's live kernel function annotation and disassembler feature that uses /dev/mem.
... because:
- this kind of assembler output is standardized regardless of compiler used,
- it's generally less messy looking,
- it gives ground-truth instead of being some intermediate layer in the toolchain that might or might not be the real deal,
- and on a live kernel it also sees through the kernel's various layers of runtime patching code obfuscation facilities, also known as: alternative-instructions, tracepoints and jump labels.
There are some cases where the .s output is the most useful tool, such as alternatives() code generation, but other than that these delimiters used in simple asm() statements mostly add noise to the source code side, which isn't desirable for assembly code that is fragile enough already.
Remove the delimiters for <asm/mwait.h>, which also happens to make the GCC inliner's asm() instruction length heuristics more accurate...
[ mingo: Wrote a new changelog to give historic context and
to give people a chance to object. :-) ]
--- arch/x86/include/asm/mwait.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/x86/include/asm/mwait.h +7 -7
@@ -34,8 +34,8 @@ static __always_inline void __monitor(const void *eax, u32 ecx, u32 edx) static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx) { -/* "monitorx %eax, %ecx, %edx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xfa;" +/* "monitorx %eax, %ecx, %edx" */ + asmvolatile (".byte 0x0f, 0x01, 0xfa" ::"a" (eax),"c" (ecx),"d" (edx)); }
@@ -78,8 +78,8 @@ static __always_inline void __mwaitx(u32 eax, u32 ebx, u32 ecx) {/* No MDS buffer clear as this is AMD/HYGON only */ -/* "mwaitx %eax, %ebx, %ecx;" */ - asmvolatile (".byte 0x0f, 0x01, 0xfb;" +/* "mwaitx %eax, %ebx, %ecx" */ + asmvolatile (".byte 0x0f, 0x01, 0xfb" ::"a" (eax),"b" (ebx),"c" (ecx)); }
@@ -138,13 +138,13 @@ static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned lo*/ static inline void __tpause (u32 ecx,u32 edx,u32 eax) { -/* "tpause %ecx, %edx, %eax;" */ +/* "tpause %ecx, %edx, %eax" */ #ifdef CONFIG_AS_TPAUSE - asmvolatile ("tpause %%ecx\n" + asmvolatile ("tpause %%ecx" : :"c" (ecx),"d" (edx),"a" (eax));#else - asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1\t\n" + asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1" : :"c" (ecx),"d" (edx),"a" (eax));#endif
PATCH 4/4 x86/idle: Remove CONFIG_AS_TPAUSE
In reply to Uros BizjakThere is no point to have CONFIG_AS_TPAUSE when the emitted assembly is always the same. Remove TPAUSE insn mnemonic and leave only the equivalent byte-wise definition. This will be changed back to insn mnemonic once binutils 2.31.1 is the minimum version to build the kernel.
--- arch/x86/Kconfig.assembler | 4 ---- arch/x86/include/asm/mwait.h | 11 ++--------- 2 files changed, 2 insertions(+), 13 deletions(-)
arch/x86/Kconfig.assembler +0 -4
@@ -15,10 +15,6 @@ config AS_SHA256_NI def_bool $(as-instr,sha256msg1 %xmm0$(comma)%xmm1) help Supported by binutils >= 2.24 and LLVM integrated assembler -config AS_TPAUSE - def_bool $(as-instr,tpause %ecx) - help - Supported by binutils >= 2.31.1 and LLVM integrated assembler >= V7 config AS_GFNI def_bool $(as-instr,vgf2p8mulb %xmm0$(comma)%xmm1$(comma)%xmm2)
arch/x86/include/asm/mwait.h +2 -9
@@ -133,16 +133,9 @@ static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned lo*/ static inline void __tpause (u32 ecx,u32 edx,u32 eax) { -/* "tpause %ecx, %edx, %eax" */ -#ifdef CONFIG_AS_TPAUSE - asmvolatile ("tpause %%ecx" - : - :"c" (ecx),"d" (edx),"a" (eax)); -#else +/* "tpause %ecx" */ asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1" - : - :"c" (ecx),"d" (edx),"a" (eax)); -#endif + ::"c" (ecx),"d" (edx),"a" (eax)); }#endif /* _ASM_X86_MWAIT_H */
Signature · 1 line
2.42.0
[tip: x86/mm] x86/idle: Remove CONFIG_AS_TPAUSE
The following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: cdc018e6b1c403b6a94416acea4649f9778c68c0 Gitweb: https://git.kernel.org/tip/cdc018e6b1c403b6a94416acea4649f9778c68c0 Author: Uros Bizjak <[email protected]> AuthorDate: Wed, 02 Apr 2025 20:08:08 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 02 Apr 2025 22:37:09 +02:00
x86/idle: Remove CONFIG_AS_TPAUSE
There is not much point in CONFIG_AS_TPAUSE at all when the emittedu assembly is always the same - it only obfuscates the __tpause() code in essence.
Remove the TPAUSE insn mnemonic from __tpause() and leave only the equivalent byte-wise definition. This can then be changed back to insn mnemonic once binutils 2.31.1 is the minimum version to build the kernel. (Right now it's 2.25.)
--- arch/x86/Kconfig.assembler | 4 ---- arch/x86/include/asm/mwait.h | 11 ++--------- 2 files changed, 2 insertions(+), 13 deletions(-)
arch/x86/Kconfig.assembler +0 -4
@@ -15,10 +15,6 @@ config AS_SHA256_NI def_bool $(as-instr,sha256msg1 %xmm0$(comma)%xmm1) help Supported by binutils >= 2.24 and LLVM integrated assembler -config AS_TPAUSE - def_bool $(as-instr,tpause %ecx) - help - Supported by binutils >= 2.31.1 and LLVM integrated assembler >= V7 config AS_GFNI def_bool $(as-instr,vgf2p8mulb %xmm0$(comma)%xmm1$(comma)%xmm2)
arch/x86/include/asm/mwait.h +2 -9
@@ -133,16 +133,9 @@ static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned lo*/ static inline void __tpause (u32 ecx,u32 edx,u32 eax) { -/* "tpause %ecx, %edx, %eax" */ -#ifdef CONFIG_AS_TPAUSE - asmvolatile ("tpause %%ecx" - : - :"c" (ecx),"d" (edx),"a" (eax)); -#else +/* "tpause %ecx" */ asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1" - : - :"c" (ecx),"d" (edx),"a" (eax)); -#endif + ::"c" (ecx),"d" (edx),"a" (eax)); }#endif /* _ASM_X86_MWAIT_H */
[tip: x86/mm] x86/idle: Remove CONFIG_AS_TPAUSE
In reply to Uros BizjakThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 6c921984e75c78e1c509d99b8cde04f1eadd46fb Gitweb: https://git.kernel.org/tip/6c921984e75c78e1c509d99b8cde04f1eadd46fb Author: Uros Bizjak <[email protected]> AuthorDate: Wed, 02 Apr 2025 20:08:08 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 02 Apr 2025 22:44:55 +02:00
x86/idle: Remove CONFIG_AS_TPAUSE
There is not much point in CONFIG_AS_TPAUSE at all when the emitted assembly is always the same - it only obfuscates the __tpause() code in essence.
Remove the TPAUSE insn mnemonic from __tpause() and leave only the equivalent byte-wise definition. This can then be changed back to insn mnemonic once binutils 2.31.1 is the minimum version to build the kernel. (Right now it's 2.25.)
--- arch/x86/Kconfig.assembler | 4 ---- arch/x86/include/asm/mwait.h | 11 ++--------- 2 files changed, 2 insertions(+), 13 deletions(-)
arch/x86/Kconfig.assembler +0 -4
@@ -15,10 +15,6 @@ config AS_SHA256_NI def_bool $(as-instr,sha256msg1 %xmm0$(comma)%xmm1) help Supported by binutils >= 2.24 and LLVM integrated assembler -config AS_TPAUSE - def_bool $(as-instr,tpause %ecx) - help - Supported by binutils >= 2.31.1 and LLVM integrated assembler >= V7 config AS_GFNI def_bool $(as-instr,vgf2p8mulb %xmm0$(comma)%xmm1$(comma)%xmm2)
arch/x86/include/asm/mwait.h +2 -9
@@ -133,16 +133,9 @@ static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned lo*/ static inline void __tpause (u32 ecx,u32 edx,u32 eax) { -/* "tpause %ecx, %edx, %eax" */ -#ifdef CONFIG_AS_TPAUSE - asmvolatile ("tpause %%ecx" - : - :"c" (ecx),"d" (edx),"a" (eax)); -#else +/* "tpause %ecx" */ asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1" - : - :"c" (ecx),"d" (edx),"a" (eax)); -#endif + ::"c" (ecx),"d" (edx),"a" (eax)); }#endif /* _ASM_X86_MWAIT_H */
[tip: x86/mm] x86/idle: Remove CONFIG_AS_TPAUSE
In reply to Uros BizjakThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: a72d55dc3bd6555cc1f97459b42b7f62ae480f13 Gitweb: https://git.kernel.org/tip/a72d55dc3bd6555cc1f97459b42b7f62ae480f13 Author: Uros Bizjak <[email protected]> AuthorDate: Wed, 02 Apr 2025 20:08:08 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Thu, 03 Apr 2025 13:19:18 +02:00
x86/idle: Remove CONFIG_AS_TPAUSE
There is not much point in CONFIG_AS_TPAUSE at all when the emitted assembly is always the same - it only obfuscates the __tpause() code in essence.
Remove the TPAUSE insn mnemonic from __tpause() and leave only the equivalent byte-wise definition. This can then be changed back to insn mnemonic once binutils 2.31.1 is the minimum version to build the kernel. (Right now it's 2.25.)
--- arch/x86/Kconfig.assembler | 4 ---- arch/x86/include/asm/mwait.h | 11 ++--------- 2 files changed, 2 insertions(+), 13 deletions(-)
arch/x86/Kconfig.assembler +0 -4
@@ -15,10 +15,6 @@ config AS_SHA256_NI def_bool $(as-instr,sha256msg1 %xmm0$(comma)%xmm1) help Supported by binutils >= 2.24 and LLVM integrated assembler -config AS_TPAUSE - def_bool $(as-instr,tpause %ecx) - help - Supported by binutils >= 2.31.1 and LLVM integrated assembler >= V7 config AS_GFNI def_bool $(as-instr,vgf2p8mulb %xmm0$(comma)%xmm1$(comma)%xmm2)
arch/x86/include/asm/mwait.h +2 -9
@@ -138,16 +138,9 @@ static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned lo*/ static inline void __tpause (u32 ecx,u32 edx,u32 eax) { -/* "tpause %ecx, %edx, %eax" */ -#ifdef CONFIG_AS_TPAUSE - asmvolatile ("tpause %%ecx" - : - :"c" (ecx),"d" (edx),"a" (eax)); -#else +/* "tpause %ecx" */ asmvolatile (".byte 0x66, 0x0f, 0xae, 0xf1" - : - :"c" (ecx),"d" (edx),"a" (eax)); -#endif + ::"c" (ecx),"d" (edx),"a" (eax)); }#endif /* _ASM_X86_MWAIT_H */
[tip: x86/mm] x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32'
In reply to Uros BizjakThe following commit has been merged into the x86/mm branch of tip:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 1ae899e413105aa81068d0282ab6e22974891d74 Gitweb: https://git.kernel.org/tip/1ae899e413105aa81068d0282ab6e22974891d74 Author: Uros Bizjak <[email protected]> AuthorDate: Wed, 02 Apr 2025 20:08:05 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 02 Apr 2025 22:26:17 +02:00
x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32'
MONITOR and MONITORX expect 32-bit unsigned integer arguments in the %ecx and %edx registers. MWAIT and MWAITX expect 32-bit usigned int argument in %eax and %ecx registers.
Some of the helpers around these instructions in <asm/mwait.h> are using too wide types (long), standardize on u32 instead that makes it clear that this is a hardware ABI.
[ mingo: Cleaned up the changelog. ]
--- arch/x86/include/asm/mwait.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
arch/x86/include/asm/mwait.h +5 -8
@@ -25,23 +25,21 @@#define TPAUSE_C01_STATE 1#define TPAUSE_C02_STATE 0 -static __always_inline void __monitor(const void *eax, unsigned long ecx, -unsigned long edx) +static __always_inline void __monitor(const void *eax, u32 ecx, u32 edx) {/* "monitor %eax, %ecx, %edx;" */ asmvolatile (".byte 0x0f, 0x01, 0xc8;" ::"a" (eax),"c" (ecx),"d" (edx)); } -static __always_inline void __monitorx(const void *eax, unsigned long ecx, -unsigned long edx) +static __always_inline void __monitorx(const void *eax, u32 ecx, u32 edx) {/* "monitorx %eax, %ecx, %edx;" */ asmvolatile (".byte 0x0f, 0x01, 0xfa;" ::"a" (eax),"c" (ecx),"d" (edx)); } -static __always_inline void __mwait(unsigned long eax, unsigned long ecx) +static __always_inline void __mwait(u32 eax, u32 ecx) {mds_idle_clear_cpu_buffers ();
@@ -76,8 +74,7 @@ static __always_inline void __mwait(unsigned long eax, unsigned long ecx)* EAX (logical) address to monitor * ECX #GP if not zero */ -static __always_inline void __mwaitx(unsigned long eax, unsigned long ebx, -unsigned long ecx) +static __always_inline void __mwaitx(u32 eax, u32 ebx, u32 ecx) {/* No MDS buffer clear as this is AMD/HYGON only */
@@ -95,7 +92,7 @@ static __always_inline void __mwaitx(unsigned long eax, unsigned long ebx,* executing mwait, it would otherwise go unnoticed and the next tick * would not be reprogrammed accordingly before mwait ever wakes up. */ -static __always_inline void __sti_mwait(unsigned long eax, unsigned long ecx) +static __always_inline void __sti_mwait(u32 eax, u32 ecx) {mds_idle_clear_cpu_buffers ();/* "mwait %eax, %ecx;" */
Re: [tip: x86/mm] x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32'
Quoted 15 lines · On 02/04/2025 9:43 pm, tip-bot2 for Uros Bizjak wrote:
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 1ae899e413105aa81068d0282ab6e22974891d74 Gitweb: https://git.kernel.org/tip/1ae899e413105aa81068d0282ab6e22974891d74 Author: Uros Bizjak <[email protected]> AuthorDate: Wed, 02 Apr 2025 20:08:05 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 02 Apr 2025 22:26:17 +02:00x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32'
MONITOR and MONITORX expect 32-bit unsigned integer arguments in the %ecx and %edx registers. MWAIT and MWAITX expect 32-bit usigned int argument in %eax and %ecx registers.
Quoted 7 lines
Some of the helpers around these instructions in <
asm/mwait.h> are using too wide types (long), standardize on u32 instead that makes it clear that this is a hardware ABI.[ mingo: Cleaned up the changelog. ]
Signed-off-by Uros Bizjak <[email protected]>
Something I noticed while looking over this is that you want to push the u32's up into the callers too.
mwait_idle_with_hints() with have (marginally) better code gen by swapping it's unsigned longs for u32's.
~Andrew
Ingo Molnar
AppliedQuoted 3 lines · Uros Bizjak
MONITOR and MONITORX expect 32-bit unsigned integer argument in %ecx and %edx registers. MWAIT and MWAITX expect 32-bit usigned int argument in %eax and %ecx registers.
Please always include a 0/4 cover letter as well for such series, which gives people a chance to reply to the whole series, instead of having to awkwardly pick a patch to reply to. :-)
Such as this general feedback:
I've applied this series with edits to the changelogs, note in particular:
patch #1:
- Changed verbiage from 'fix' to 'standardize to u32'. There was no bug to fix, using 'long' instead of 'int' is at worst an ineffiency.
patch #3:
- Provided much needed historic context behind ;, \t, \n beautifiers used in asm() statements. These aren't just random noise added in.
patch #4:
- Added in the current binutils version cutoff, to make it really clear why we cannot use the mnemonic yet, and how far away we are from doing so.
I've also extended the Cc: list in the commit to give people a chance to object, to patch #3 in particular:
8ad521aaf743 ("x86/idle: Remove .s output beautifying delimiters from simpler asm() templates")
Thanks,
Ingo
Quoted 14 lines · Ingo Molnar
Quoted 3 lines · Uros Bizjak
MONITOR and MONITORX expect 32-bit unsigned integer argument in %ecx and %edx registers. MWAIT and MWAITX expect 32-bit usigned int argument in %eax and %ecx registers.
Please always include a 0/4 cover letter as well for such series, which gives people a chance to reply to the whole series, instead of having to awkwardly pick a patch to reply to. :-)
Such as this general feedback:
Quoted 7 lines
I've applied this series with edits to the changelogs, note in particular:
patch #1:
- Changed verbiage from 'fix' to 'standardize to u32'. There was no bug to fix, using 'long' instead of 'int' is at worst an ineffiency.
Indeed, but when patch #2 introduces insn mnemonic:
asm volatile("monitor %0, %1, %2" :: "a" (eax), "c" (ecx), "d" (edx));
then the type decides between %rcx/%rdx and %ecx/%edx. Assembler checks arguments of MONITOR insn mnemonic and fails compilation with the former.
Quoted 4 lines
patch #3:
- Provided much needed historic context behind ;, \t, \n beautifiers used in
asm()statements. These aren't just random noise added in.
Please note that removed delimiters were at the end of asm template. The compiler adds \n\t at the end on its own, as demonstrated with the following example:
void foo (unsigned int a, unsigned long b)
{
asm ("foo %0 %1" :: "r" (a), "r" (b));
}
gcc -S (unredacted dump):
foo:
.LFB0:
.cfi_startproc
#APP
# 3 "tt.c" 1
foo %edi %rsi
# 0 "" 2
#NO_APP
ret
.cfi_endproc
.LFE0:
Please note that asm instructions are perfectly aligned. So, at the end of the day, the delimiters at the end of asm templates *are* just noise.
Thanks,
Uros.