[tip: x86/asm] x86/asm: Use CLFLUSHOPT and CLWB mnemonics in <asm/special_insns.h>

From: tip-bot2 for Uros Bizjak
Date: Thu Mar 13 2025 - 07:05:25 EST


The following commit has been merged into the x86/asm branch of tip:

Commit-ID: cc2e9e09d1a3c59cfb138a0fc6ad6f624f3d4ac8
Gitweb: https://git.kernel.org/tip/cc2e9e09d1a3c59cfb138a0fc6ad6f624f3d4ac8
Author: Uros Bizjak <ubizjak@xxxxxxxxx>
AuthorDate: Thu, 13 Mar 2025 11:26:55 +01:00
Committer: Ingo Molnar <mingo@xxxxxxxxxx>
CommitterDate: Thu, 13 Mar 2025 11:50:14 +01:00

x86/asm: Use CLFLUSHOPT and CLWB mnemonics in <asm/special_insns.h>

Current minimum required version of binutils is 2.25,
which supports CLFLUSHOPT and CLWB instruction mnemonics.

Replace the byte-wise specification of CLFLUSHOPT and
CLWB with these proper mnemonics.

No functional change intended.

Signed-off-by: Uros Bizjak <ubizjak@xxxxxxxxx>
Signed-off-by: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Andy Lutomirski <luto@xxxxxxxxxx>
Cc: Brian Gerst <brgerst@xxxxxxxxx>
Cc: H. Peter Anvin <hpa@xxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Link: https://lore.kernel.org/r/20250313102715.333142-1-ubizjak@xxxxxxxxx
---
arch/x86/include/asm/special_insns.h | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
index 03e7c2d..856d4ad 100644
--- a/arch/x86/include/asm/special_insns.h
+++ b/arch/x86/include/asm/special_insns.h
@@ -176,9 +176,8 @@ static __always_inline void clflush(volatile void *__p)

static inline void clflushopt(volatile void *__p)
{
- alternative_io(".byte 0x3e; clflush %0",
- ".byte 0x66; clflush %0",
- X86_FEATURE_CLFLUSHOPT,
+ alternative_io("ds clflush %0",
+ "clflushopt %0", X86_FEATURE_CLFLUSHOPT,
"+m" (*(volatile char __force *)__p));
}

@@ -187,13 +186,10 @@ static inline void clwb(volatile void *__p)
volatile struct { char x[64]; } *p = __p;

asm volatile(ALTERNATIVE_2(
- ".byte 0x3e; clflush (%[pax])",
- ".byte 0x66; clflush (%[pax])", /* clflushopt (%%rax) */
- X86_FEATURE_CLFLUSHOPT,
- ".byte 0x66, 0x0f, 0xae, 0x30", /* clwb (%%rax) */
- X86_FEATURE_CLWB)
- : [p] "+m" (*p)
- : [pax] "a" (p));
+ "ds clflush %0",
+ "clflushopt %0", X86_FEATURE_CLFLUSHOPT,
+ "clwb %0", X86_FEATURE_CLWB)
+ : "+m" (*p));
}

#ifdef CONFIG_X86_USER_SHADOW_STACK