* [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions
@ 2025-04-02 18:08 Uros Bizjak
2025-04-02 18:08 ` [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h> Uros Bizjak
` (4 more replies)
0 siblings, 5 replies; 18+ messages in thread
From: Uros Bizjak @ 2025-04-02 18:08 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
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.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/include/asm/mwait.h | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 54dc313bcdf0..3377869ff2e8 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -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;" */
asm volatile(".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;" */
asm volatile(".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;" */
--
2.42.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
2025-04-02 18:08 [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Uros Bizjak
@ 2025-04-02 18:08 ` Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] " tip-bot2 for Uros Bizjak
2025-04-03 15:28 ` [PATCH -tip 2/4] " Andy Shevchenko
2025-04-02 18:08 ` [PATCH -tip 3/4] x86/idle: Remove unneeded delimiters from asm templates Uros Bizjak
` (3 subsequent siblings)
4 siblings, 2 replies; 18+ messages in thread
From: Uros Bizjak @ 2025-04-02 18:08 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
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.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/include/asm/mwait.h | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 3377869ff2e8..006b150bcb5f 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -27,9 +27,7 @@
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));
+ asm volatile("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;" */
- asm volatile(".byte 0x0f, 0x01, 0xc9;"
- :: "a" (eax), "c" (ecx));
+ asm volatile("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;" */
- asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
- :: "a" (eax), "c" (ecx));
+
+ asm volatile("sti; mwait %0, %1" :: "a" (eax), "c" (ecx));
}
/*
--
2.42.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH -tip 3/4] x86/idle: Remove unneeded delimiters from asm templates
2025-04-02 18:08 [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Uros Bizjak
2025-04-02 18:08 ` [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h> Uros Bizjak
@ 2025-04-02 18:08 ` Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] x86/idle: Remove .s output beautifying delimiters from simpler asm() templates tip-bot2 for Uros Bizjak
2025-04-03 11:27 ` tip-bot2 for Uros Bizjak
2025-04-02 18:08 ` [PATCH -tip 4/4] x86/idle: Remove CONFIG_AS_TPAUSE Uros Bizjak
` (2 subsequent siblings)
4 siblings, 2 replies; 18+ messages in thread
From: Uros Bizjak @ 2025-04-02 18:08 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
Delimiters at the end of asm templates are not needed. Remove
them to make asm instruction length calculations more accurate.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/include/asm/mwait.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 006b150bcb5f..65228861b894 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -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;" */
- asm volatile(".byte 0x0f, 0x01, 0xfa;"
+ /* "monitorx %eax, %ecx, %edx" */
+ asm volatile(".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;" */
- asm volatile(".byte 0x0f, 0x01, 0xfb;"
+ /* "mwaitx %eax, %ebx, %ecx" */
+ asm volatile(".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
- asm volatile("tpause %%ecx\n"
+ asm volatile("tpause %%ecx"
:
: "c"(ecx), "d"(edx), "a"(eax));
#else
- asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1\t\n"
+ asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1"
:
: "c"(ecx), "d"(edx), "a"(eax));
#endif
--
2.42.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH -tip 4/4] x86/idle: Remove CONFIG_AS_TPAUSE
2025-04-02 18:08 [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Uros Bizjak
2025-04-02 18:08 ` [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h> Uros Bizjak
2025-04-02 18:08 ` [PATCH -tip 3/4] x86/idle: Remove unneeded delimiters from asm templates Uros Bizjak
@ 2025-04-02 18:08 ` Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] " tip-bot2 for Uros Bizjak
` (2 more replies)
2025-04-02 20:43 ` [tip: x86/mm] x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32' tip-bot2 for Uros Bizjak
2025-04-02 20:48 ` [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Ingo Molnar
4 siblings, 3 replies; 18+ messages in thread
From: Uros Bizjak @ 2025-04-02 18:08 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
There 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.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/Kconfig.assembler | 4 ----
arch/x86/include/asm/mwait.h | 11 ++---------
2 files changed, 2 insertions(+), 13 deletions(-)
diff --git a/arch/x86/Kconfig.assembler b/arch/x86/Kconfig.assembler
index 6d20a6ce0507..fa8858546d5e 100644
--- a/arch/x86/Kconfig.assembler
+++ b/arch/x86/Kconfig.assembler
@@ -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)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 65228861b894..5141d2acc0ef 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -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
- asm volatile("tpause %%ecx"
- :
- : "c"(ecx), "d"(edx), "a"(eax));
- #else
+ /* "tpause %ecx" */
asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1"
- :
- : "c"(ecx), "d"(edx), "a"(eax));
- #endif
+ :: "c" (ecx), "d" (edx), "a" (eax));
}
#endif /* _ASM_X86_MWAIT_H */
--
2.42.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [tip: x86/mm] x86/idle: Remove CONFIG_AS_TPAUSE
2025-04-02 18:08 ` [PATCH -tip 4/4] x86/idle: Remove CONFIG_AS_TPAUSE Uros Bizjak
@ 2025-04-02 20:43 ` tip-bot2 for Uros Bizjak
2025-04-02 20:55 ` tip-bot2 for Uros Bizjak
2025-04-03 11:27 ` tip-bot2 for Uros Bizjak
2 siblings, 0 replies; 18+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2025-04-02 20:43 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Andy Lutomirski, Brian Gerst,
Juergen Gross, Andrew Cooper, Rik van Riel, H. Peter Anvin,
Peter Zijlstra, Rafael J. Wysocki, Linus Torvalds, x86,
linux-kernel
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 <ubizjak@gmail.com>
AuthorDate: Wed, 02 Apr 2025 20:08:08 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
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.)
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250402180827.3762-4-ubizjak@gmail.com
---
arch/x86/Kconfig.assembler | 4 ----
arch/x86/include/asm/mwait.h | 11 ++---------
2 files changed, 2 insertions(+), 13 deletions(-)
diff --git a/arch/x86/Kconfig.assembler b/arch/x86/Kconfig.assembler
index 6d20a6c..fa88585 100644
--- a/arch/x86/Kconfig.assembler
+++ b/arch/x86/Kconfig.assembler
@@ -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)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 6522886..5141d2a 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -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
- asm volatile("tpause %%ecx"
- :
- : "c"(ecx), "d"(edx), "a"(eax));
- #else
+ /* "tpause %ecx" */
asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1"
- :
- : "c"(ecx), "d"(edx), "a"(eax));
- #endif
+ :: "c" (ecx), "d" (edx), "a" (eax));
}
#endif /* _ASM_X86_MWAIT_H */
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [tip: x86/mm] x86/idle: Remove .s output beautifying delimiters from simpler asm() templates
2025-04-02 18:08 ` [PATCH -tip 3/4] x86/idle: Remove unneeded delimiters from asm templates Uros Bizjak
@ 2025-04-02 20:43 ` tip-bot2 for Uros Bizjak
2025-04-03 11:27 ` tip-bot2 for Uros Bizjak
1 sibling, 0 replies; 18+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2025-04-02 20:43 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Andy Lutomirski, Brian Gerst,
Juergen Gross, Andrew Cooper, Rik van Riel, H. Peter Anvin,
Peter Zijlstra, Rafael J. Wysocki, Linus Torvalds, x86,
linux-kernel
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 <ubizjak@gmail.com>
AuthorDate: Wed, 02 Apr 2025 20:08:07 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
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. :-) ]
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250402180827.3762-3-ubizjak@gmail.com
---
arch/x86/include/asm/mwait.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 006b150..6522886 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -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;" */
- asm volatile(".byte 0x0f, 0x01, 0xfa;"
+ /* "monitorx %eax, %ecx, %edx" */
+ asm volatile(".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;" */
- asm volatile(".byte 0x0f, 0x01, 0xfb;"
+ /* "mwaitx %eax, %ebx, %ecx" */
+ asm volatile(".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
- asm volatile("tpause %%ecx\n"
+ asm volatile("tpause %%ecx"
:
: "c"(ecx), "d"(edx), "a"(eax));
#else
- asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1\t\n"
+ asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1"
:
: "c"(ecx), "d"(edx), "a"(eax));
#endif
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [tip: x86/mm] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
2025-04-02 18:08 ` [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h> Uros Bizjak
@ 2025-04-02 20:43 ` tip-bot2 for Uros Bizjak
2025-04-03 15:28 ` [PATCH -tip 2/4] " Andy Shevchenko
1 sibling, 0 replies; 18+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2025-04-02 20:43 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Andy Lutomirski, Brian Gerst,
Juergen Gross, Andrew Cooper, Rik van Riel, H. Peter Anvin,
Peter Zijlstra, Rafael J. Wysocki, Linus Torvalds, x86,
linux-kernel
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 <ubizjak@gmail.com>
AuthorDate: Wed, 02 Apr 2025 20:08:06 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
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.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250402180827.3762-2-ubizjak@gmail.com
---
arch/x86/include/asm/mwait.h | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 3377869..006b150 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -27,9 +27,7 @@
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));
+ asm volatile("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;" */
- asm volatile(".byte 0x0f, 0x01, 0xc9;"
- :: "a" (eax), "c" (ecx));
+ asm volatile("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;" */
- asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
- :: "a" (eax), "c" (ecx));
+
+ asm volatile("sti; mwait %0, %1" :: "a" (eax), "c" (ecx));
}
/*
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [tip: x86/mm] x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32'
2025-04-02 18:08 [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Uros Bizjak
` (2 preceding siblings ...)
2025-04-02 18:08 ` [PATCH -tip 4/4] x86/idle: Remove CONFIG_AS_TPAUSE Uros Bizjak
@ 2025-04-02 20:43 ` tip-bot2 for Uros Bizjak
2025-04-02 23:26 ` Andrew Cooper
2025-04-02 20:48 ` [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Ingo Molnar
4 siblings, 1 reply; 18+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2025-04-02 20:43 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Andy Lutomirski, Brian Gerst,
Juergen Gross, Andrew Cooper, Rik van Riel, H. Peter Anvin,
Peter Zijlstra, Rafael J. Wysocki, Linus Torvalds, x86,
linux-kernel
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 <ubizjak@gmail.com>
AuthorDate: Wed, 02 Apr 2025 20:08:05 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
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. ]
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250402180827.3762-1-ubizjak@gmail.com
---
arch/x86/include/asm/mwait.h | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 54dc313..3377869 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -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;" */
asm volatile(".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;" */
asm volatile(".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;" */
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions
2025-04-02 18:08 [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Uros Bizjak
` (3 preceding siblings ...)
2025-04-02 20:43 ` [tip: x86/mm] x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32' tip-bot2 for Uros Bizjak
@ 2025-04-02 20:48 ` Ingo Molnar
2025-04-02 21:18 ` Uros Bizjak
4 siblings, 1 reply; 18+ messages in thread
From: Ingo Molnar @ 2025-04-02 20:48 UTC (permalink / raw)
To: Uros Bizjak, Linus Torvalds
Cc: x86, linux-kernel, Thomas Gleixner, Borislav Petkov, Dave Hansen,
H. Peter Anvin
* Uros Bizjak <ubizjak@gmail.com> wrote:
> 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
^ permalink raw reply [flat|nested] 18+ messages in thread
* [tip: x86/mm] x86/idle: Remove CONFIG_AS_TPAUSE
2025-04-02 18:08 ` [PATCH -tip 4/4] x86/idle: Remove CONFIG_AS_TPAUSE Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] " tip-bot2 for Uros Bizjak
@ 2025-04-02 20:55 ` tip-bot2 for Uros Bizjak
2025-04-03 11:27 ` tip-bot2 for Uros Bizjak
2 siblings, 0 replies; 18+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2025-04-02 20:55 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Andy Lutomirski, Brian Gerst,
Juergen Gross, Andrew Cooper, Rik van Riel, H. Peter Anvin,
Peter Zijlstra, Rafael J. Wysocki, Linus Torvalds, x86,
linux-kernel
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 <ubizjak@gmail.com>
AuthorDate: Wed, 02 Apr 2025 20:08:08 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
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.)
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250402180827.3762-4-ubizjak@gmail.com
---
arch/x86/Kconfig.assembler | 4 ----
arch/x86/include/asm/mwait.h | 11 ++---------
2 files changed, 2 insertions(+), 13 deletions(-)
diff --git a/arch/x86/Kconfig.assembler b/arch/x86/Kconfig.assembler
index 6d20a6c..fa88585 100644
--- a/arch/x86/Kconfig.assembler
+++ b/arch/x86/Kconfig.assembler
@@ -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)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 6522886..5141d2a 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -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
- asm volatile("tpause %%ecx"
- :
- : "c"(ecx), "d"(edx), "a"(eax));
- #else
+ /* "tpause %ecx" */
asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1"
- :
- : "c"(ecx), "d"(edx), "a"(eax));
- #endif
+ :: "c" (ecx), "d" (edx), "a" (eax));
}
#endif /* _ASM_X86_MWAIT_H */
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions
2025-04-02 20:48 ` [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Ingo Molnar
@ 2025-04-02 21:18 ` Uros Bizjak
0 siblings, 0 replies; 18+ messages in thread
From: Uros Bizjak @ 2025-04-02 21:18 UTC (permalink / raw)
To: Ingo Molnar
Cc: Linus Torvalds, x86, linux-kernel, Thomas Gleixner,
Borislav Petkov, Dave Hansen, H. Peter Anvin
On Wed, Apr 2, 2025 at 10:48 PM Ingo Molnar <mingo@kernel.org> wrote:
>
>
> * Uros Bizjak <ubizjak@gmail.com> wrote:
>
> > 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.
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.
> 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.
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [tip: x86/mm] x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32'
2025-04-02 20:43 ` [tip: x86/mm] x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32' tip-bot2 for Uros Bizjak
@ 2025-04-02 23:26 ` Andrew Cooper
0 siblings, 0 replies; 18+ messages in thread
From: Andrew Cooper @ 2025-04-02 23:26 UTC (permalink / raw)
To: Uros Bizjak
Cc: Ingo Molnar, Andy Lutomirski, Brian Gerst, Juergen Gross,
Rik van Riel, H. Peter Anvin, Peter Zijlstra, Rafael J. Wysocki,
Linus Torvalds, x86, linux-kernel, linux-tip-commits
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 <ubizjak@gmail.com>
> AuthorDate: Wed, 02 Apr 2025 20:08:05 +02:00
> Committer: Ingo Molnar <mingo@kernel.org>
> 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. ]
>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
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
^ permalink raw reply [flat|nested] 18+ messages in thread
* [tip: x86/mm] x86/idle: Remove CONFIG_AS_TPAUSE
2025-04-02 18:08 ` [PATCH -tip 4/4] x86/idle: Remove CONFIG_AS_TPAUSE Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] " tip-bot2 for Uros Bizjak
2025-04-02 20:55 ` tip-bot2 for Uros Bizjak
@ 2025-04-03 11:27 ` tip-bot2 for Uros Bizjak
2 siblings, 0 replies; 18+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2025-04-03 11:27 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Andy Lutomirski, Brian Gerst,
Juergen Gross, Andrew Cooper, Rik van Riel, H. Peter Anvin,
Peter Zijlstra, Rafael J. Wysocki, Linus Torvalds, x86,
linux-kernel
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 <ubizjak@gmail.com>
AuthorDate: Wed, 02 Apr 2025 20:08:08 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
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.)
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250402180827.3762-4-ubizjak@gmail.com
---
arch/x86/Kconfig.assembler | 4 ----
arch/x86/include/asm/mwait.h | 11 ++---------
2 files changed, 2 insertions(+), 13 deletions(-)
diff --git a/arch/x86/Kconfig.assembler b/arch/x86/Kconfig.assembler
index 6d20a6c..fa88585 100644
--- a/arch/x86/Kconfig.assembler
+++ b/arch/x86/Kconfig.assembler
@@ -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)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 0e020a6..6a2ec20 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -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
- asm volatile("tpause %%ecx"
- :
- : "c"(ecx), "d"(edx), "a"(eax));
- #else
+ /* "tpause %ecx" */
asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1"
- :
- : "c"(ecx), "d"(edx), "a"(eax));
- #endif
+ :: "c" (ecx), "d" (edx), "a" (eax));
}
#endif /* _ASM_X86_MWAIT_H */
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [tip: x86/mm] x86/idle: Remove .s output beautifying delimiters from simpler asm() templates
2025-04-02 18:08 ` [PATCH -tip 3/4] x86/idle: Remove unneeded delimiters from asm templates Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] x86/idle: Remove .s output beautifying delimiters from simpler asm() templates tip-bot2 for Uros Bizjak
@ 2025-04-03 11:27 ` tip-bot2 for Uros Bizjak
1 sibling, 0 replies; 18+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2025-04-03 11:27 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Andy Lutomirski, Brian Gerst,
Juergen Gross, Andrew Cooper, Rik van Riel, H. Peter Anvin,
Peter Zijlstra, Rafael J. Wysocki, Linus Torvalds, x86,
linux-kernel
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 <ubizjak@gmail.com>
AuthorDate: Wed, 02 Apr 2025 20:08:07 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
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. :-) ]
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250402180827.3762-3-ubizjak@gmail.com
---
arch/x86/include/asm/mwait.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
index 3377869..0e020a6 100644
--- a/arch/x86/include/asm/mwait.h
+++ b/arch/x86/include/asm/mwait.h
@@ -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;" */
- asm volatile(".byte 0x0f, 0x01, 0xfa;"
+ /* "monitorx %eax, %ecx, %edx" */
+ asm volatile(".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;" */
- asm volatile(".byte 0x0f, 0x01, 0xfb;"
+ /* "mwaitx %eax, %ebx, %ecx" */
+ asm volatile(".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
- asm volatile("tpause %%ecx\n"
+ asm volatile("tpause %%ecx"
:
: "c"(ecx), "d"(edx), "a"(eax));
#else
- asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1\t\n"
+ asm volatile(".byte 0x66, 0x0f, 0xae, 0xf1"
:
: "c"(ecx), "d"(edx), "a"(eax));
#endif
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
2025-04-02 18:08 ` [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h> Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] " tip-bot2 for Uros Bizjak
@ 2025-04-03 15:28 ` Andy Shevchenko
2025-04-03 15:30 ` Andy Shevchenko
1 sibling, 1 reply; 18+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:28 UTC (permalink / raw)
To: Uros Bizjak
Cc: x86, linux-kernel, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
On Wed, Apr 02, 2025 at 08:08:06PM +0200, Uros Bizjak wrote:
> 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
| ^
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
2025-04-03 15:28 ` [PATCH -tip 2/4] " Andy Shevchenko
@ 2025-04-03 15:30 ` Andy Shevchenko
2025-04-03 15:33 ` Ingo Molnar
0 siblings, 1 reply; 18+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:30 UTC (permalink / raw)
To: Uros Bizjak
Cc: x86, linux-kernel, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
On Thu, Apr 03, 2025 at 06:28:13PM +0300, Andy Shevchenko wrote:
> On Wed, Apr 02, 2025 at 08:08:06PM +0200, Uros Bizjak wrote:
> > 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
> | ^
FWIW, revert fixes the issue.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
2025-04-03 15:30 ` Andy Shevchenko
@ 2025-04-03 15:33 ` Ingo Molnar
2025-04-03 15:41 ` Andy Shevchenko
0 siblings, 1 reply; 18+ messages in thread
From: Ingo Molnar @ 2025-04-03 15:33 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Uros Bizjak, x86, linux-kernel, Thomas Gleixner, Borislav Petkov,
Dave Hansen, H. Peter Anvin
* Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Thu, Apr 03, 2025 at 06:28:13PM +0300, Andy Shevchenko wrote:
> > On Wed, Apr 02, 2025 at 08:08:06PM +0200, Uros Bizjak wrote:
> > > 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
> > | ^
>
> FWIW, revert fixes the issue.
All gone already, tomorrow's -next should be fine.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h>
2025-04-03 15:33 ` Ingo Molnar
@ 2025-04-03 15:41 ` Andy Shevchenko
0 siblings, 0 replies; 18+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:41 UTC (permalink / raw)
To: Ingo Molnar
Cc: Uros Bizjak, x86, linux-kernel, Thomas Gleixner, Borislav Petkov,
Dave Hansen, H. Peter Anvin
On Thu, Apr 03, 2025 at 05:33:56PM +0200, Ingo Molnar wrote:
> * Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > On Thu, Apr 03, 2025 at 06:28:13PM +0300, Andy Shevchenko wrote:
> > > On Wed, Apr 02, 2025 at 08:08:06PM +0200, Uros Bizjak wrote:
...
> > > > 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
> > > | ^
> >
> > FWIW, revert fixes the issue.
>
> All gone already, tomorrow's -next should be fine.
Thanks!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2025-04-03 15:41 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02 18:08 [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Uros Bizjak
2025-04-02 18:08 ` [PATCH -tip 2/4] x86/idle: Use MONITOR and MWAIT mnemonics in <asm/mwait.h> Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] " tip-bot2 for Uros Bizjak
2025-04-03 15:28 ` [PATCH -tip 2/4] " Andy Shevchenko
2025-04-03 15:30 ` Andy Shevchenko
2025-04-03 15:33 ` Ingo Molnar
2025-04-03 15:41 ` Andy Shevchenko
2025-04-02 18:08 ` [PATCH -tip 3/4] x86/idle: Remove unneeded delimiters from asm templates Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] x86/idle: Remove .s output beautifying delimiters from simpler asm() templates tip-bot2 for Uros Bizjak
2025-04-03 11:27 ` tip-bot2 for Uros Bizjak
2025-04-02 18:08 ` [PATCH -tip 4/4] x86/idle: Remove CONFIG_AS_TPAUSE Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] " tip-bot2 for Uros Bizjak
2025-04-02 20:55 ` tip-bot2 for Uros Bizjak
2025-04-03 11:27 ` tip-bot2 for Uros Bizjak
2025-04-02 20:43 ` [tip: x86/mm] x86/idle: Standardize argument types for MONITOR{,X} and MWAIT{,X} instruction wrappers on 'u32' tip-bot2 for Uros Bizjak
2025-04-02 23:26 ` Andrew Cooper
2025-04-02 20:48 ` [PATCH -tip 1/4] x86/idle: Fix argument type for MONITOR{,X} and MWAIT{,X} instructions Ingo Molnar
2025-04-02 21:18 ` Uros Bizjak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox