x86: Avoid using .byte for instructions where safe to do so
PATCH v2 1/1 x86: Avoid using .byte for instructions where safe to do so
The new toolchain baseline knows XGETBV, VPXOR and VPOR.
For the other cases using .byte, annotate the toolchain minima.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
v2
* CLZERO, {WR,RD}PKRU can't be named yet.
Pull out of previous series as it's somewhat unrelated. The XSAVE cleanup has other prerequiesites before it can move away from .byte.
--- xen/arch/x86/arch.mk | 4 +++ xen/arch/x86/include/asm/asm-defns.h | 1 + xen/arch/x86/include/asm/msr.h | 2 ++ xen/arch/x86/include/asm/prot-key.h | 4 +-- xen/arch/x86/include/asm/xstate.h | 3 +-- xen/arch/x86/x86_emulate/0f01.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 34 ++++++++++++-------------- 7 files changed, 27 insertions(+), 23 deletions(-)
xen/arch/x86/arch.mk +4 -0
@@ -17,7 +17,11 @@ CFLAGS-$(CONFIG_CC_IS_GCC) += -malign-data=abi $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) $(call cc-option-add,CFLAGS,CC,-Wnested-externs) $(call as-option-add,CFLAGS,CC,".equ \"x\"$(comma)1",-DHAVE_AS_QUOTED_SYM) + +# Binutils >= 2.31, Clang >= 7 $(call as-option-add,CFLAGS,CC,"movdiri %rax$(comma)(%rax)",-DHAVE_AS_MOVDIR) + +# Binutils >= 2.33, Clang >= 9 $(call as-option-add,CFLAGS,CC,"enqcmd (%rax)$(comma)%rax",-DHAVE_AS_ENQCMD) # Check to see whether the assembler supports the .nop directive.
xen/arch/x86/include/asm/asm-defns.h +1 -0
@@ -1,5 +1,6 @@#include <asm/page-bits.h> +/* binutils >= 2.26 or Clang >= 3.8 */ .macro clzero .byte 0x0f, 0x01, 0xfc .endm
xen/arch/x86/include/asm/msr.h +2 -0
@@ -63,6 +63,8 @@ static inline void wrmsrns(uint32_t msr, uint64_t val)/* * WRMSR is 2 bytes. WRMSRNS is 3 bytes. Pad WRMSR with a redundant CS * prefix to avoid a trailing NOP. +* +* Binutils >= 2.40, Clang >= 16 */ alternative_input(".byte 0x2e; wrmsr", ".byte 0x0f,0x01,0xc6", X86_FEATURE_WRMSRNS,
xen/arch/x86/include/asm/prot-key.h +2 -2
@@ -19,7 +19,7 @@ static inline uint32_t rdpkru(void) {uint32_t pkru; - asmvolatile (".byte 0x0f,0x01,0xee" + asmvolatile (".byte 0x0f,0x01,0xee" /* binutils >= 2.26 or Clang >= 3.8 */ :"=a" (pkru) :"c" (0 ) :"dx" );return pkru;
@@ -27,7 +27,7 @@ static inline uint32_t rdpkru(void)static inline void wrpkru (uint32_t pkru) { - asmvolatile (".byte 0x0f,0x01,0xef" + asmvolatile (".byte 0x0f,0x01,0xef" /* binutils >= 2.26 or Clang >= 3.8 */ ::"a" (pkru),"d" (0 ),"c" (0 ) ); }
xen/arch/x86/include/asm/xstate.h +1 -2
@@ -118,8 +118,7 @@ static inline uint64_t xgetbv(unsigned int index)uint32_t lo, hi;ASSERT (index);/* get_xcr0() should be used instead. */ - asmvolatile (".byte 0x0f,0x01,0xd0" /* xgetbv */ - :"=a" (lo),"=d" (hi) :"c" (index) ); + asmvolatile ("xgetbv" :"=a" (lo),"=d" (hi) :"c" (index) );return lo | ((uint64_t )hi <<32 ); }
xen/arch/x86/x86_emulate/0f01.c +1 -1
@@ -122,7 +122,7 @@ int x86emul_0f01(struct x86_emulate_state *s, {case vex_none:/* serialize */ host_and_vcpu_must_have (serialize); - asmvolatile (".byte 0x0f, 0x01, 0xe8" ); + asmvolatile (".byte 0x0f, 0x01, 0xe8" );/* Binutils >= 2.34, Clang >= 11 */ break ;case vex_f2:/* xsusldtrk */ vcpu_must_have (tsxldtrk);
xen/arch/x86/x86_emulate/x86_emulate.c +16 -18
@@ -4748,27 +4748,25 @@ x86_emulate(*/ if ( vex.l ) { -/* vpxor %xmmN, %xmmN, %xmmN */ - asmvolatile (".byte 0xc5,0xf9,0xef,0xc0" ); - asmvolatile (".byte 0xc5,0xf1,0xef,0xc9" ); - asmvolatile (".byte 0xc5,0xe9,0xef,0xd2" ); - asmvolatile (".byte 0xc5,0xe1,0xef,0xdb" ); - asmvolatile (".byte 0xc5,0xd9,0xef,0xe4" ); - asmvolatile (".byte 0xc5,0xd1,0xef,0xed" ); - asmvolatile (".byte 0xc5,0xc9,0xef,0xf6" ); - asmvolatile (".byte 0xc5,0xc1,0xef,0xff" ); + asmvolatile ("vpxor %xmm0, %xmm0, %xmm0" ); + asmvolatile ("vpxor %xmm1, %xmm1, %xmm1" ); + asmvolatile ("vpxor %xmm2, %xmm2, %xmm2" ); + asmvolatile ("vpxor %xmm3, %xmm3, %xmm3" ); + asmvolatile ("vpxor %xmm4, %xmm4, %xmm4" ); + asmvolatile ("vpxor %xmm5, %xmm5, %xmm5" ); + asmvolatile ("vpxor %xmm6, %xmm6, %xmm6" ); + asmvolatile ("vpxor %xmm7, %xmm7, %xmm7" ); }else { -/* vpor %xmmN, %xmmN, %xmmN */ - asmvolatile (".byte 0xc5,0xf9,0xeb,0xc0" ); - asmvolatile (".byte 0xc5,0xf1,0xeb,0xc9" ); - asmvolatile (".byte 0xc5,0xe9,0xeb,0xd2" ); - asmvolatile (".byte 0xc5,0xe1,0xeb,0xdb" ); - asmvolatile (".byte 0xc5,0xd9,0xeb,0xe4" ); - asmvolatile (".byte 0xc5,0xd1,0xeb,0xed" ); - asmvolatile (".byte 0xc5,0xc9,0xeb,0xf6" ); - asmvolatile (".byte 0xc5,0xc1,0xeb,0xff" ); + asmvolatile ("vpor %xmm0, %xmm0, %xmm0" ); + asmvolatile ("vpor %xmm1, %xmm1, %xmm1" ); + asmvolatile ("vpor %xmm2, %xmm2, %xmm2" ); + asmvolatile ("vpor %xmm3, %xmm3, %xmm3" ); + asmvolatile ("vpor %xmm4, %xmm4, %xmm4" ); + asmvolatile ("vpor %xmm5, %xmm5, %xmm5" ); + asmvolatile ("vpor %xmm6, %xmm6, %xmm6" ); + asmvolatile ("vpor %xmm7, %xmm7, %xmm7" ); }ASSERT (!state->simd_size);
Signature · 1 line
2.39.5
Quoted 7 lines · Andrew Cooper
The new toolchain baseline knows XGETBV, VPXOR and VPOR.
For the other cases using .byte, annotate the toolchain minima.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>
Le 09/04/2026 à 13:43, Andrew Cooper a écrit :
Quoted 154 lines
The new toolchain baseline knows XGETBV, VPXOR and VPOR.
For the other cases using .byte, annotate the toolchain minima.
No functional change.
Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>v2
* CLZERO, {WR,RD}PKRU can't be named yet.Pull out of previous series as it's somewhat unrelated. The XSAVE cleanup has other prerequiesites before it can move away from .byte.
--- xen/arch/x86/arch.mk | 4 +++ xen/arch/x86/include/asm/asm-defns.h | 1 + xen/arch/x86/include/asm/msr.h | 2 ++ xen/arch/x86/include/asm/prot-key.h | 4 +-- xen/arch/x86/include/asm/xstate.h | 3 +-- xen/arch/x86/x86_emulate/0f01.c | 2 +- xen/arch/x86/x86_emulate/x86_emulate.c | 34 ++++++++++++-------------- 7 files changed, 27 insertions(+), 23 deletions(-)xen/arch/x86/arch.mk +4
-0@@ -17,7 +17,11 @@ CFLAGS-$(CONFIG_CC_IS_GCC) += -malign-data=abi $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) $(call cc-option-add,CFLAGS,CC,-Wnested-externs) $(call as-option-add,CFLAGS,CC,".equ \"x\"$(comma)1",-DHAVE_AS_QUOTED_SYM) + +# Binutils >= 2.31, Clang >= 7 $(call as-option-add,CFLAGS,CC,"movdiri %rax$(comma)(%rax)",-DHAVE_AS_MOVDIR) + +# Binutils >= 2.33, Clang >= 9 $(call as-option-add,CFLAGS,CC,"enqcmd (%rax)$(comma)%rax",-DHAVE_AS_ENQCMD) # Check to see whether the assembler supports the .nop directive.xen/arch/x86/include/asm/asm-defns.h +1
-0@@ -1,5 +1,6 @@#include <asm/page-bits.h> +/* binutils >= 2.26 or Clang >= 3.8 */ .macro clzero .byte 0x0f, 0x01, 0xfc .endmxen/arch/x86/include/asm/msr.h +2
-0@@ -63,6 +63,8 @@ static inline void wrmsrns(uint32_t msr, uint64_t val)/* * WRMSR is 2 bytes. WRMSRNS is 3 bytes. Pad WRMSR with a redundant CS * prefix to avoid a trailing NOP. +* +* Binutils >= 2.40, Clang >= 16 */ alternative_input(".byte 0x2e; wrmsr", ".byte 0x0f,0x01,0xc6", X86_FEATURE_WRMSRNS,xen/arch/x86/include/asm/prot-key.h +2
-2@@ -19,7 +19,7 @@ static inline uint32_t rdpkru(void) {uint32_t pkru; - asmvolatile (".byte 0x0f,0x01,0xee" + asmvolatile (".byte 0x0f,0x01,0xee" /* binutils >= 2.26 or Clang >= 3.8 */ :"=a" (pkru) :"c" (0 ) :"dx" );return pkru;@@ -27,7 +27,7 @@ static inline uint32_t rdpkru(void)static inline void wrpkru (uint32_t pkru) { - asmvolatile (".byte 0x0f,0x01,0xef" + asmvolatile (".byte 0x0f,0x01,0xef" /* binutils >= 2.26 or Clang >= 3.8 */ ::"a" (pkru),"d" (0 ),"c" (0 ) ); }xen/arch/x86/include/asm/xstate.h +1
-2@@ -118,8 +118,7 @@ static inline uint64_t xgetbv(unsigned int index)uint32_t lo, hi;ASSERT (index);/* get_xcr0() should be used instead. */ - asmvolatile (".byte 0x0f,0x01,0xd0" /* xgetbv */ - :"=a" (lo),"=d" (hi) :"c" (index) ); + asmvolatile ("xgetbv" :"=a" (lo),"=d" (hi) :"c" (index) );return lo | ((uint64_t )hi <<32 ); }xen/arch/x86/x86_emulate/0f01.c +1
-1@@ -122,7 +122,7 @@ int x86emul_0f01(struct x86_emulate_state *s, {case vex_none:/* serialize */ host_and_vcpu_must_have (serialize); - asmvolatile (".byte 0x0f, 0x01, 0xe8" ); + asmvolatile (".byte 0x0f, 0x01, 0xe8" );/* Binutils >= 2.34, Clang >= 11 */ break ;case vex_f2:/* xsusldtrk */ vcpu_must_have (tsxldtrk);xen/arch/x86/x86_emulate/x86_emulate.c +9
-18@@ -4748,27 +4748,25 @@ x86_emulate(*/ if ( vex.l ) { -/* vpxor %xmmN, %xmmN, %xmmN */ - asmvolatile (".byte 0xc5,0xf9,0xef,0xc0" ); - asmvolatile (".byte 0xc5,0xf1,0xef,0xc9" ); - asmvolatile (".byte 0xc5,0xe9,0xef,0xd2" ); - asmvolatile (".byte 0xc5,0xe1,0xef,0xdb" ); - asmvolatile (".byte 0xc5,0xd9,0xef,0xe4" ); - asmvolatile (".byte 0xc5,0xd1,0xef,0xed" ); - asmvolatile (".byte 0xc5,0xc9,0xef,0xf6" ); - asmvolatile (".byte 0xc5,0xc1,0xef,0xff" ); + asmvolatile ("vpxor %xmm0, %xmm0, %xmm0" ); + asmvolatile ("vpxor %xmm1, %xmm1, %xmm1" ); + asmvolatile ("vpxor %xmm2, %xmm2, %xmm2" ); + asmvolatile ("vpxor %xmm3, %xmm3, %xmm3" ); + asmvolatile ("vpxor %xmm4, %xmm4, %xmm4" ); + asmvolatile ("vpxor %xmm5, %xmm5, %xmm5" ); + asmvolatile ("vpxor %xmm6, %xmm6, %xmm6" ); + asmvolatile ("vpxor %xmm7, %xmm7, %xmm7" ); }else { -/* vpor %xmmN, %xmmN, %xmmN */ - asmvolatile (".byte 0xc5,0xf9,0xeb,0xc0" ); - asmvolatile (".byte 0xc5,0xf1,0xeb,0xc9" ); - asmvolatile (".byte 0xc5,0xe9,0xeb,0xd2" ); - asmvolatile (".byte 0xc5,0xe1,0xeb,0xdb" ); - asmvolatile (".byte 0xc5,0xd9,0xeb,0xe4" ); - asmvolatile (".byte 0xc5,0xd1,0xeb,0xed" ); - asmvolatile (".byte 0xc5,0xc9,0xeb,0xf6" ); - asmvolatile (".byte 0xc5,0xc1,0xeb,0xff" ); + asmvolatile ("vpor %xmm0, %xmm0, %xmm0" );
xen/arch/x86/x86_emulate/x86_emulate.c x86_emulate( · line 4772
Quoted 10 lines
xen/arch/x86/x86_emulate/x86_emulate.c +7
-0+ asmvolatile ("vpor %xmm1, %xmm1, %xmm1" ); + asmvolatile ("vpor %xmm2, %xmm2, %xmm2" ); + asmvolatile ("vpor %xmm3, %xmm3, %xmm3" ); + asmvolatile ("vpor %xmm4, %xmm4, %xmm4" ); + asmvolatile ("vpor %xmm5, %xmm5, %xmm5" ); + asmvolatile ("vpor %xmm6, %xmm6, %xmm6" ); + asmvolatile ("vpor %xmm7, %xmm7, %xmm7" ); }ASSERT (!state->simd_size);
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech