From patchwork Thu Apr 3 18:23:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14037506 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF518C3600C for ; Thu, 3 Apr 2025 18:23:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.937046.1338125 (Exim 4.92) (envelope-from ) id 1u0PDb-00014N-LK; Thu, 03 Apr 2025 18:23:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 937046.1338125; Thu, 03 Apr 2025 18:23:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDb-00014G-Hq; Thu, 03 Apr 2025 18:23:11 +0000 Received: by outflank-mailman (input) for mailman id 937046; Thu, 03 Apr 2025 18:23:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDZ-0000KX-O6 for xen-devel@lists.xenproject.org; Thu, 03 Apr 2025 18:23:09 +0000 Received: from mail-24417.protonmail.ch (mail-24417.protonmail.ch [109.224.244.17]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b1bb9101-10b8-11f0-9eaa-5ba50f476ded; Thu, 03 Apr 2025 20:23:09 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b1bb9101-10b8-11f0-9eaa-5ba50f476ded DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743704587; x=1743963787; bh=qhdb/UMVIzJBSclTVMNrOhHVQ8qtT+hHFmjvP6GsCPc=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=XprKrZdJwozJ7RtPPi0NFr+5IjEy7TCwNSUl7Jq43C65XZess6+LStMze0I2lX3Vf fRr6Avgu/WF+GxGQFxy7tVdjS5xaG+hd8cG4uE735FGHLIAHoBrBFW9EEBlC7Ht0DX u3uHfKp/RHeyYhfVznI/vFqw6qBZb3bOM/9Woqr57vIjako+ye1lvYESGI/2/oWFh9 yeDO4ZPFH003yHDd4rMFaPY5LzACzB04Lsq3GQA7yuUgakuL7xjPrjBE6UT368VPiS jG3Z1tacs8ti8uzLGFv7kuSXd/cyqGADneoG/9zii+NM0js3ayTIIi3JGEJX3RZgiE lfouKZYwkSoYQ== Date: Thu, 03 Apr 2025 18:23:04 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org, dmukhin@ford.com Subject: [PATCH v2 1/6] x86/vmx: remove HAVE_AS_{EPT,VMX}, GAS_VMX_OP() and *_OPCODE Message-ID: <20250403182250.3329498-2-dmukhin@ford.com> In-Reply-To: <20250403182250.3329498-1-dmukhin@ford.com> References: <20250403182250.3329498-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 88bc866978d8a58d1e80d42e66ec5b77779ee0e0 MIME-Version: 1.0 From: Denis Mukhin The new toolchain baseline knows the VMX instructions, no need to carry the workaround in the code. Move asm for vmxoff directly on the only callsite in vmcs.c Updated formatting for all __xxx() calls to be consistent. Resolves: https://gitlab.com/xen-project/xen/-/work_items/202 Signed-off-by: Denis Mukhin --- xen/arch/x86/arch.mk | 4 +- xen/arch/x86/hvm/vmx/vmcs.c | 2 +- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 119 ++++--------------------- 3 files changed, 17 insertions(+), 108 deletions(-) diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk index 258e459bec..e9fa1c92d7 100644 --- a/xen/arch/x86/arch.mk +++ b/xen/arch/x86/arch.mk @@ -10,9 +10,7 @@ CFLAGS += -msoft-float $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) $(call cc-option-add,CFLAGS,CC,-Wnested-externs) -$(call as-option-add,CFLAGS,CC,"vmcall",-DHAVE_AS_VMX) $(call as-option-add,CFLAGS,CC,"crc32 %eax$(comma)%eax",-DHAVE_AS_SSE4_2) -$(call as-option-add,CFLAGS,CC,"invept (%rax)$(comma)%rax",-DHAVE_AS_EPT) $(call as-option-add,CFLAGS,CC,"rdrand %eax",-DHAVE_AS_RDRAND) $(call as-option-add,CFLAGS,CC,"rdfsbase %rax",-DHAVE_AS_FSGSBASE) $(call as-option-add,CFLAGS,CC,"xsaveopt (%rax)",-DHAVE_AS_XSAVEOPT) @@ -23,7 +21,7 @@ $(call as-option-add,CFLAGS,CC,"invpcid (%rax)$(comma)%rax",-DHAVE_AS_INVPCID) $(call as-option-add,CFLAGS,CC,"movdiri %rax$(comma)(%rax)",-DHAVE_AS_MOVDIR) $(call as-option-add,CFLAGS,CC,"enqcmd (%rax)$(comma)%rax",-DHAVE_AS_ENQCMD) -# Check to see whether the assmbler supports the .nop directive. +# Check to see whether the assembler supports the .nop directive. $(call as-option-add,CFLAGS,CC,\ ".L1: .L2: .nops (.L2 - .L1)$(comma)9",-DHAVE_AS_NOPS_DIRECTIVE) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 1d427100ce..aef746a293 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -811,7 +811,7 @@ void cf_check vmx_cpu_down(void) BUG_ON(!(read_cr4() & X86_CR4_VMXE)); this_cpu(vmxon) = 0; - __vmxoff(); + asm volatile ("vmxoff" : : : "memory"); local_irq_restore(flags); } diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h b/xen/arch/x86/include/asm/hvm/vmx/vmx.h index 7c6ba73407..ed6a6986b9 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h @@ -257,24 +257,6 @@ typedef union cr_access_qual { #define X86_SEG_AR_GRANULARITY (1u << 15) /* 15, granularity */ #define X86_SEG_AR_SEG_UNUSABLE (1u << 16) /* 16, segment unusable */ -#define VMCALL_OPCODE ".byte 0x0f,0x01,0xc1\n" -#define VMCLEAR_OPCODE ".byte 0x66,0x0f,0xc7\n" /* reg/opcode: /6 */ -#define VMLAUNCH_OPCODE ".byte 0x0f,0x01,0xc2\n" -#define VMPTRLD_OPCODE ".byte 0x0f,0xc7\n" /* reg/opcode: /6 */ -#define VMPTRST_OPCODE ".byte 0x0f,0xc7\n" /* reg/opcode: /7 */ -#define VMREAD_OPCODE ".byte 0x0f,0x78\n" -#define VMRESUME_OPCODE ".byte 0x0f,0x01,0xc3\n" -#define VMWRITE_OPCODE ".byte 0x0f,0x79\n" -#define INVEPT_OPCODE ".byte 0x66,0x0f,0x38,0x80\n" /* m128,r64/32 */ -#define INVVPID_OPCODE ".byte 0x66,0x0f,0x38,0x81\n" /* m128,r64/32 */ -#define VMXOFF_OPCODE ".byte 0x0f,0x01,0xc4\n" -#define VMXON_OPCODE ".byte 0xf3,0x0f,0xc7\n" - -#define MODRM_EAX_08 ".byte 0x08\n" /* ECX, [EAX] */ -#define MODRM_EAX_06 ".byte 0x30\n" /* [EAX], with reg/opcode: /6 */ -#define MODRM_EAX_07 ".byte 0x38\n" /* [EAX], with reg/opcode: /7 */ -#define MODRM_EAX_ECX ".byte 0xc1\n" /* EAX, ECX */ - extern uint8_t posted_intr_vector; #define cpu_has_vmx_ept_exec_only_supported \ @@ -310,97 +292,54 @@ extern uint8_t posted_intr_vector; #define INVVPID_ALL_CONTEXT 2 #define INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 3 -#ifdef HAVE_AS_VMX -# define GAS_VMX_OP(yes, no) yes -#else -# define GAS_VMX_OP(yes, no) no -#endif - static always_inline void __vmptrld(u64 addr) { - asm volatile ( -#ifdef HAVE_AS_VMX - "vmptrld %0\n" -#else - VMPTRLD_OPCODE MODRM_EAX_06 -#endif + asm volatile ( "vmptrld %0\n" /* CF==1 or ZF==1 --> BUG() */ UNLIKELY_START(be, vmptrld) _ASM_BUGFRAME_TEXT(0) UNLIKELY_END_SECTION : -#ifdef HAVE_AS_VMX : "m" (addr), -#else - : "a" (&addr), -#endif _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) - : "memory"); + : "memory" ); } static always_inline void __vmpclear(u64 addr) { - asm volatile ( -#ifdef HAVE_AS_VMX - "vmclear %0\n" -#else - VMCLEAR_OPCODE MODRM_EAX_06 -#endif + asm volatile ( "vmclear %0\n" /* CF==1 or ZF==1 --> BUG() */ UNLIKELY_START(be, vmclear) _ASM_BUGFRAME_TEXT(0) UNLIKELY_END_SECTION : -#ifdef HAVE_AS_VMX : "m" (addr), -#else - : "a" (&addr), -#endif _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) - : "memory"); + : "memory" ); } static always_inline void __vmread(unsigned long field, unsigned long *value) { - asm volatile ( -#ifdef HAVE_AS_VMX - "vmread %1, %0\n\t" -#else - VMREAD_OPCODE MODRM_EAX_ECX -#endif + asm volatile ( "vmread %1, %0\n\t" /* CF==1 or ZF==1 --> BUG() */ UNLIKELY_START(be, vmread) _ASM_BUGFRAME_TEXT(0) UNLIKELY_END_SECTION -#ifdef HAVE_AS_VMX : "=rm" (*value) : "r" (field), -#else - : "=c" (*value) - : "a" (field), -#endif _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) ); } static always_inline void __vmwrite(unsigned long field, unsigned long value) { - asm volatile ( -#ifdef HAVE_AS_VMX - "vmwrite %1, %0\n" -#else - VMWRITE_OPCODE MODRM_EAX_ECX -#endif + asm volatile ( "vmwrite %1, %0\n" /* CF==1 or ZF==1 --> BUG() */ UNLIKELY_START(be, vmwrite) _ASM_BUGFRAME_TEXT(0) UNLIKELY_END_SECTION : -#ifdef HAVE_AS_VMX : "r" (field) , "rm" (value), -#else - : "a" (field) , "c" (value), -#endif _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) ); } @@ -411,14 +350,13 @@ static inline enum vmx_insn_errno vmread_safe(unsigned long field, unsigned long ret = VMX_INSN_SUCCEED; bool fail_invalid, fail_valid; - asm volatile ( GAS_VMX_OP("vmread %[field], %[value]\n\t", - VMREAD_OPCODE MODRM_EAX_ECX) + asm volatile ( "vmread %[field], %[value]\n\t" ASM_FLAG_OUT(, "setc %[invalid]\n\t") ASM_FLAG_OUT(, "setz %[valid]\n\t") : ASM_FLAG_OUT("=@ccc", [invalid] "=rm") (fail_invalid), ASM_FLAG_OUT("=@ccz", [valid] "=rm") (fail_valid), - [value] GAS_VMX_OP("=rm", "=c") (*value) - : [field] GAS_VMX_OP("r", "a") (field)); + [value] "=rm" (*value) + : [field] "r" (field) ); if ( unlikely(fail_invalid) ) ret = VMX_INSN_FAIL_INVALID; @@ -434,14 +372,13 @@ static inline enum vmx_insn_errno vmwrite_safe(unsigned long field, unsigned long ret = VMX_INSN_SUCCEED; bool fail_invalid, fail_valid; - asm volatile ( GAS_VMX_OP("vmwrite %[value], %[field]\n\t", - VMWRITE_OPCODE MODRM_EAX_ECX) + asm volatile ( "vmwrite %[value], %[field]\n\t" ASM_FLAG_OUT(, "setc %[invalid]\n\t") ASM_FLAG_OUT(, "setz %[valid]\n\t") : ASM_FLAG_OUT("=@ccc", [invalid] "=rm") (fail_invalid), ASM_FLAG_OUT("=@ccz", [valid] "=rm") (fail_valid) - : [field] GAS_VMX_OP("r", "a") (field), - [value] GAS_VMX_OP("rm", "c") (value)); + : [field] "r" (field), + [value] "rm" (value) ); if ( unlikely(fail_invalid) ) ret = VMX_INSN_FAIL_INVALID; @@ -465,22 +402,13 @@ static always_inline void __invept(unsigned long type, uint64_t eptp) !cpu_has_vmx_ept_invept_single_context ) type = INVEPT_ALL_CONTEXT; - asm volatile ( -#ifdef HAVE_AS_EPT - "invept %0, %1\n" -#else - INVEPT_OPCODE MODRM_EAX_08 -#endif + asm volatile ( "invept %0, %1\n" /* CF==1 or ZF==1 --> BUG() */ UNLIKELY_START(be, invept) _ASM_BUGFRAME_TEXT(0) UNLIKELY_END_SECTION : -#ifdef HAVE_AS_EPT : "m" (operand), "r" (type), -#else - : "a" (&operand), "c" (type), -#endif _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) : "memory" ); } @@ -494,24 +422,14 @@ static always_inline void __invvpid(unsigned long type, u16 vpid, u64 gva) } operand = {vpid, 0, gva}; /* Fix up #UD exceptions which occur when TLBs are flushed before VMXON. */ - asm volatile ( "1: " -#ifdef HAVE_AS_EPT - "invvpid %0, %1\n" -#else - INVVPID_OPCODE MODRM_EAX_08 -#endif + asm volatile ( "1: invvpid %0, %1\n" /* CF==1 or ZF==1 --> BUG() */ UNLIKELY_START(be, invvpid) _ASM_BUGFRAME_TEXT(0) UNLIKELY_END_SECTION "\n" - "2:" - _ASM_EXTABLE(1b, 2b) + "2:" _ASM_EXTABLE(1b, 2b) : -#ifdef HAVE_AS_EPT : "m" (operand), "r" (type), -#else - : "a" (&operand), "c" (type), -#endif _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) : "memory" ); } @@ -552,13 +470,6 @@ static inline void vpid_sync_all(void) __invvpid(INVVPID_ALL_CONTEXT, 0, 0); } -static inline void __vmxoff(void) -{ - asm volatile ( - VMXOFF_OPCODE - : : : "memory" ); -} - int cf_check vmx_guest_x86_mode(struct vcpu *v); unsigned int vmx_get_cpl(void); From patchwork Thu Apr 3 18:23:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14037505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 28B5CC3600C for ; Thu, 3 Apr 2025 18:23:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.937052.1338135 (Exim 4.92) (envelope-from ) id 1u0PDm-0001QL-08; Thu, 03 Apr 2025 18:23:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 937052.1338135; Thu, 03 Apr 2025 18:23:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDl-0001QB-TI; Thu, 03 Apr 2025 18:23:21 +0000 Received: by outflank-mailman (input) for mailman id 937052; Thu, 03 Apr 2025 18:23:20 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDk-0001N1-6t for xen-devel@lists.xenproject.org; Thu, 03 Apr 2025 18:23:20 +0000 Received: from mail-24416.protonmail.ch (mail-24416.protonmail.ch [109.224.244.16]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b4e5688a-10b8-11f0-9ffb-bf95429c2676; Thu, 03 Apr 2025 20:23:14 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b4e5688a-10b8-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743704593; x=1743963793; bh=DAdmSxgvTyBN49WAdVm4Ym611V3JMucvy190nmerm+Q=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=Ht7/I1mJ/Y7K0M92SngQbabwHstOiBsqvjCe57WBxgMmdCKeNE6BfGqVyHeOVfAcK 5XruK6qxcqnEwUtVT1xp759lPbE/m7y3TYxp6U/m9annLLuNvulyUTLOdLOU1Z0NUW f5dYdnoCkFX5Ch8HDdvU12NEyTD7WzyBRv4OeeR2Fz8VnO4xzwRNj6jOLfv4U8V7Kk iY4zALiVDHmkPhiwAcXmtb/ThtSFmu61wUna7WW/sDZT7JlPdlHD1yD0GGChDuzNE3 Qixfkv+/26+TFS4lp6j8j2yKxlOa13xtNSUM3CJAN+3nGWfyTWL9B11v2z9ek7fsag sS4OGBBnFuxEA== Date: Thu, 03 Apr 2025 18:23:09 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org, dmukhin@ford.com Subject: [PATCH v2 2/6] x86/msr: remove HAVE_AS_FSGSBASE Message-ID: <20250403182250.3329498-3-dmukhin@ford.com> In-Reply-To: <20250403182250.3329498-1-dmukhin@ford.com> References: <20250403182250.3329498-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: f6e30f0fc17d05541119b496f78e8cadb4330eed MIME-Version: 1.0 From: Denis Mukhin The new toolchain baseline knows the {rd,wr}{f,g}sbase instructions, no need to carry the workaround in the code. Resolves: https://gitlab.com/xen-project/xen/-/work_items/207 Signed-off-by: Denis Mukhin Reviewed-by: Andrew Cooper --- xen/arch/x86/arch.mk | 1 - xen/arch/x86/include/asm/msr.h | 22 ---------------------- 2 files changed, 23 deletions(-) diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk index e9fa1c92d7..6d2876b1a8 100644 --- a/xen/arch/x86/arch.mk +++ b/xen/arch/x86/arch.mk @@ -12,7 +12,6 @@ $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) $(call cc-option-add,CFLAGS,CC,-Wnested-externs) $(call as-option-add,CFLAGS,CC,"crc32 %eax$(comma)%eax",-DHAVE_AS_SSE4_2) $(call as-option-add,CFLAGS,CC,"rdrand %eax",-DHAVE_AS_RDRAND) -$(call as-option-add,CFLAGS,CC,"rdfsbase %rax",-DHAVE_AS_FSGSBASE) $(call as-option-add,CFLAGS,CC,"xsaveopt (%rax)",-DHAVE_AS_XSAVEOPT) $(call as-option-add,CFLAGS,CC,"rdseed %eax",-DHAVE_AS_RDSEED) $(call as-option-add,CFLAGS,CC,"clwb (%rax)",-DHAVE_AS_CLWB) diff --git a/xen/arch/x86/include/asm/msr.h b/xen/arch/x86/include/asm/msr.h index 549d40b404..0d3b1d6374 100644 --- a/xen/arch/x86/include/asm/msr.h +++ b/xen/arch/x86/include/asm/msr.h @@ -152,11 +152,7 @@ static inline unsigned long __rdfsbase(void) { unsigned long base; -#ifdef HAVE_AS_FSGSBASE asm volatile ( "rdfsbase %0" : "=r" (base) ); -#else - asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xc0" : "=a" (base) ); -#endif return base; } @@ -165,31 +161,19 @@ static inline unsigned long __rdgsbase(void) { unsigned long base; -#ifdef HAVE_AS_FSGSBASE asm volatile ( "rdgsbase %0" : "=r" (base) ); -#else - asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xc8" : "=a" (base) ); -#endif return base; } static inline void __wrfsbase(unsigned long base) { -#ifdef HAVE_AS_FSGSBASE asm volatile ( "wrfsbase %0" :: "r" (base) ); -#else - asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd0" :: "a" (base) ); -#endif } static inline void __wrgsbase(unsigned long base) { -#ifdef HAVE_AS_FSGSBASE asm volatile ( "wrgsbase %0" :: "r" (base) ); -#else - asm volatile ( ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd8" :: "a" (base) ); -#endif } static inline unsigned long read_fs_base(void) @@ -253,15 +237,9 @@ static inline void write_gs_shadow(unsigned long base) if ( read_cr4() & X86_CR4_FSGSBASE ) { asm volatile ( "swapgs\n\t" -#ifdef HAVE_AS_FSGSBASE "wrgsbase %0\n\t" "swapgs" :: "r" (base) ); -#else - ".byte 0xf3, 0x48, 0x0f, 0xae, 0xd8\n\t" - "swapgs" - :: "a" (base) ); -#endif } else wrmsrl(MSR_SHADOW_GS_BASE, base); From patchwork Thu Apr 3 18:23:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14037507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AFDB6C3601E for ; Thu, 3 Apr 2025 18:23:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.937055.1338147 (Exim 4.92) (envelope-from ) id 1u0PDo-0001gw-A6; Thu, 03 Apr 2025 18:23:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 937055.1338147; Thu, 03 Apr 2025 18:23:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDo-0001gn-4W; Thu, 03 Apr 2025 18:23:24 +0000 Received: by outflank-mailman (input) for mailman id 937055; Thu, 03 Apr 2025 18:23:23 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDn-0001N1-FJ for xen-devel@lists.xenproject.org; Thu, 03 Apr 2025 18:23:23 +0000 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id b7974f18-10b8-11f0-9ffb-bf95429c2676; Thu, 03 Apr 2025 20:23:19 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b7974f18-10b8-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743704598; x=1743963798; bh=FAnFU2EE55zpL6ceZQ70EasVphCLs90kdKWYj30AMlo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=Fu9WAITLaHRFhN2dgRC4aZ+EaSzjlopic2qS6JU9L7+AuoWmTa/OBxhbrYfv0/R2w KzrQ6LO2pdS9QWg+LJALdAjcXwfyBJGgiAG4j8UkZ+ntlEjyN4k/ympVP1NfjRgZTm YkD7JWuTZoJPLs77h991CWBYVr4jnn1p54n5THLIQ250RzA3ZPzfDdCH7GFTOKtUXs ala24sSxS9ctUz34WqesHMED9pAGYB8Ind6m1Y473krIrjS7sUMoaFcWF7KUfOildr UTnJDwOGk81/qG4Od9XdBoyhSIQCZbdv5WWeyDSfZBzVopUjbmsGH/LEF/QgXaNQHG yL9hmMUerT0ow== Date: Thu, 03 Apr 2025 18:23:13 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org, dmukhin@ford.com Subject: [PATCH v2 3/6] x86/asm: remove HAVE_AS_INVPCID Message-ID: <20250403182250.3329498-4-dmukhin@ford.com> In-Reply-To: <20250403182250.3329498-1-dmukhin@ford.com> References: <20250403182250.3329498-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: f6f51d824233c96d4937b9d9c830236c66c51944 MIME-Version: 1.0 From: Denis Mukhin The new toolchain baseline knows the invpcid instruction, no need to carry the workaround in the code. Resolves: https://gitlab.com/xen-project/xen/-/work_items/209 Signed-off-by: Denis Mukhin Reviewed-by: Andrew Cooper --- xen/arch/x86/arch.mk | 1 - xen/arch/x86/include/asm/invpcid.h | 12 +----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk index 6d2876b1a8..dcc8c3c330 100644 --- a/xen/arch/x86/arch.mk +++ b/xen/arch/x86/arch.mk @@ -16,7 +16,6 @@ $(call as-option-add,CFLAGS,CC,"xsaveopt (%rax)",-DHAVE_AS_XSAVEOPT) $(call as-option-add,CFLAGS,CC,"rdseed %eax",-DHAVE_AS_RDSEED) $(call as-option-add,CFLAGS,CC,"clwb (%rax)",-DHAVE_AS_CLWB) $(call as-option-add,CFLAGS,CC,".equ \"x\"$(comma)1",-DHAVE_AS_QUOTED_SYM) -$(call as-option-add,CFLAGS,CC,"invpcid (%rax)$(comma)%rax",-DHAVE_AS_INVPCID) $(call as-option-add,CFLAGS,CC,"movdiri %rax$(comma)(%rax)",-DHAVE_AS_MOVDIR) $(call as-option-add,CFLAGS,CC,"enqcmd (%rax)$(comma)%rax",-DHAVE_AS_ENQCMD) diff --git a/xen/arch/x86/include/asm/invpcid.h b/xen/arch/x86/include/asm/invpcid.h index bf5c30313a..e116a34a6c 100644 --- a/xen/arch/x86/include/asm/invpcid.h +++ b/xen/arch/x86/include/asm/invpcid.h @@ -5,9 +5,6 @@ extern bool use_invpcid; -#define INVPCID_OPCODE ".byte 0x66, 0x0f, 0x38, 0x82\n" -#define MODRM_ECX_01 ".byte 0x01\n" - static inline void invpcid(unsigned int pcid, unsigned long addr, unsigned int type) { @@ -17,16 +14,9 @@ static inline void invpcid(unsigned int pcid, unsigned long addr, uint64_t addr; } desc = { .pcid = pcid, .addr = addr }; - asm volatile ( -#ifdef HAVE_AS_INVPCID - "invpcid %[desc], %q[type]" + asm volatile ( "invpcid %[desc], %q[type]" : /* No output */ : [desc] "m" (desc), [type] "r" (type) -#else - INVPCID_OPCODE MODRM_ECX_01 - : /* No output */ - : "a" (type), "c" (&desc) -#endif : "memory" ); } From patchwork Thu Apr 3 18:23:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14037509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 883E9C3600C for ; Thu, 3 Apr 2025 18:23:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.937061.1338156 (Exim 4.92) (envelope-from ) id 1u0PDt-00027S-G6; Thu, 03 Apr 2025 18:23:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 937061.1338156; Thu, 03 Apr 2025 18:23:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDt-00027L-D3; Thu, 03 Apr 2025 18:23:29 +0000 Received: by outflank-mailman (input) for mailman id 937061; Thu, 03 Apr 2025 18:23:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDs-0001N1-17 for xen-devel@lists.xenproject.org; Thu, 03 Apr 2025 18:23:28 +0000 Received: from mail-10629.protonmail.ch (mail-10629.protonmail.ch [79.135.106.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bc1f0e2c-10b8-11f0-9ffb-bf95429c2676; Thu, 03 Apr 2025 20:23:26 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bc1f0e2c-10b8-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743704605; x=1743963805; bh=0+5RP23zmphaABoW946e9TRg+3ezkXum7FCtTXRbuRo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=QEy3QHwFJ8D2CudLyCwp8udZXZNunfSRFnD3L5hlC6A0CHwawHqnMmFsIpoH3F1OQ XsLCUhXr7HE+xarwPhDDCwKHqzVX255L/UpyOGXh6sNrqtjWBJV7OAiIMcOeYgYRy/ YKJMfUebL07ejDcE3lf22xRET20jM+Kas1UNbAXfuNiCRKJnmZJcbnIwb3BLfnaSSx XZPHMo7LXhquFlVRtmxNtW3QocbTvj4iHHlqVoKNmvQJB0S69mT2b3M1JiZy0ai/Ij DjAAYwIv5ThL/+6bxXHBsR33w/bXI5+S4Rh5o4xvh5ZZhiQPl/ZusGDAGUDIvzztHa L0gJW2G/M51rg== Date: Thu, 03 Apr 2025 18:23:19 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org, dmukhin@ford.com Subject: [PATCH v2 4/6] x86/emulate: remove HAVE_AS_SSE4_2 Message-ID: <20250403182250.3329498-5-dmukhin@ford.com> In-Reply-To: <20250403182250.3329498-1-dmukhin@ford.com> References: <20250403182250.3329498-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 5284202ec3cab84c8f2b5e48a374d5a8cfe45ec7 MIME-Version: 1.0 From: Denis Mukhin The new toolchain baseline knows the crc32 instructions, no need to carry the workaround in the code. Resolves: https://gitlab.com/xen-project/xen/-/work_items/206 Signed-off-by: Denis Mukhin Reviewed-by: Andrew Cooper --- xen/arch/x86/arch.mk | 1 - xen/arch/x86/x86_emulate/x86_emulate.c | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk index dcc8c3c330..3bbaee2a44 100644 --- a/xen/arch/x86/arch.mk +++ b/xen/arch/x86/arch.mk @@ -10,7 +10,6 @@ CFLAGS += -msoft-float $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) $(call cc-option-add,CFLAGS,CC,-Wnested-externs) -$(call as-option-add,CFLAGS,CC,"crc32 %eax$(comma)%eax",-DHAVE_AS_SSE4_2) $(call as-option-add,CFLAGS,CC,"rdrand %eax",-DHAVE_AS_RDRAND) $(call as-option-add,CFLAGS,CC,"xsaveopt (%rax)",-DHAVE_AS_XSAVEOPT) $(call as-option-add,CFLAGS,CC,"rdseed %eax",-DHAVE_AS_RDSEED) diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c index 535d803588..55d36b9a26 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -6882,7 +6882,7 @@ x86_emulate( goto unhandleable; } break; -#ifdef HAVE_AS_SSE4_2 + case X86EMUL_OPC_F2(0x0f38, 0xf0): /* crc32 r/m8, r{32,64} */ case X86EMUL_OPC_F2(0x0f38, 0xf1): /* crc32 r/m{16,32,64}, r{32,64} */ host_and_vcpu_must_have(sse4_2); @@ -6901,17 +6901,16 @@ x86_emulate( asm ( "crc32l %1,%k0" : "+r" (dst.val) : "rm" (*(uint32_t *)&src.val) ); break; -# ifdef __x86_64__ +#ifdef __x86_64__ case 8: asm ( "crc32q %1,%0" : "+r" (dst.val) : "rm" (src.val) ); break; -# endif +#endif default: ASSERT_UNREACHABLE(); goto unhandleable; } break; -#endif case X86EMUL_OPC_VEX(0x0f38, 0xf2): /* andn r/m,r,r */ case X86EMUL_OPC_VEX(0x0f38, 0xf5): /* bzhi r,r/m,r */ From patchwork Thu Apr 3 18:23:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14037510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9EA47C3600C for ; Thu, 3 Apr 2025 18:23:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.937064.1338166 (Exim 4.92) (envelope-from ) id 1u0PDx-0002Va-P9; Thu, 03 Apr 2025 18:23:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 937064.1338166; Thu, 03 Apr 2025 18:23:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDx-0002VT-M0; Thu, 03 Apr 2025 18:23:33 +0000 Received: by outflank-mailman (input) for mailman id 937064; Thu, 03 Apr 2025 18:23:32 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PDw-0001N1-Mo for xen-devel@lists.xenproject.org; Thu, 03 Apr 2025 18:23:32 +0000 Received: from mail-24417.protonmail.ch (mail-24417.protonmail.ch [109.224.244.17]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id bec5eddf-10b8-11f0-9ffb-bf95429c2676; Thu, 03 Apr 2025 20:23:31 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: bec5eddf-10b8-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743704610; x=1743963810; bh=GQ/7FVabQDdWQQqA2ckOWpneHtYQWqdMr/r/gKDzsXM=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=FdEBnhhYepTdHVUzupYP2bMsW8MZKaFZoa8hR6sBqIZQM1f3tH0wrZvfE3SVTsCVA wpXf4hp6GVGyoRnLJ7GpGjL+aB1HP4gDwQJ2zAg0GTr7fwJ1wNgCrxc5BqSf7ikgBh 2HIlhN3ryC3V4q22iAgf2TXWDFCEUJhz61bAyg37TbFTjZeQazc46biHas9apQXjPV /RyU3+/2k96ShaxvW/O4tmwkzjVXsshKMXxbSpzqFOVTdyVllDTNS0+OJe0PIsE77H LboVB6CqUWTLcRE0FHTDMwTkQODqlV33GeejjXJWP9fQAlWVebyWGEr3cJlsjp/2hm BnNgdskJi7xLA== Date: Thu, 03 Apr 2025 18:23:26 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org, dmukhin@ford.com Subject: [PATCH v2 5/6] x86/emulate: remove HAVE_AS_RDRAND and HAVE_AS_RDSEED Message-ID: <20250403182250.3329498-6-dmukhin@ford.com> In-Reply-To: <20250403182250.3329498-1-dmukhin@ford.com> References: <20250403182250.3329498-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 8dd76c2aceb6a141989cabe4dc4ca563e968872c MIME-Version: 1.0 From: Denis Mukhin The new toolchain baseline knows the rdrand/rdseed instructions, no need to carry the workaround in the code. Resolves: https://gitlab.com/xen-project/xen/-/work_items/208 Signed-off-by: Denis Mukhin --- xen/arch/x86/arch.mk | 2 -- xen/arch/x86/x86_emulate/0fc7.c | 15 +++++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk index 3bbaee2a44..5577bf6241 100644 --- a/xen/arch/x86/arch.mk +++ b/xen/arch/x86/arch.mk @@ -10,9 +10,7 @@ CFLAGS += -msoft-float $(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS)) $(call cc-option-add,CFLAGS,CC,-Wnested-externs) -$(call as-option-add,CFLAGS,CC,"rdrand %eax",-DHAVE_AS_RDRAND) $(call as-option-add,CFLAGS,CC,"xsaveopt (%rax)",-DHAVE_AS_XSAVEOPT) -$(call as-option-add,CFLAGS,CC,"rdseed %eax",-DHAVE_AS_RDSEED) $(call as-option-add,CFLAGS,CC,"clwb (%rax)",-DHAVE_AS_CLWB) $(call as-option-add,CFLAGS,CC,".equ \"x\"$(comma)1",-DHAVE_AS_QUOTED_SYM) $(call as-option-add,CFLAGS,CC,"movdiri %rax$(comma)(%rax)",-DHAVE_AS_MOVDIR) diff --git a/xen/arch/x86/x86_emulate/0fc7.c b/xen/arch/x86/x86_emulate/0fc7.c index 5268d5cafd..58c8f79501 100644 --- a/xen/arch/x86/x86_emulate/0fc7.c +++ b/xen/arch/x86/x86_emulate/0fc7.c @@ -32,7 +32,6 @@ int x86emul_0fc7(struct x86_emulate_state *s, return X86EMUL_UNRECOGNIZED; case 6: /* rdrand */ -#ifdef HAVE_AS_RDRAND generate_exception_if(s->vex.pfx >= vex_f3, X86_EXC_UD); host_and_vcpu_must_have(rdrand); *dst = s->ea; @@ -43,12 +42,12 @@ int x86emul_0fc7(struct x86_emulate_state *s, : "=r" (dst->val), ASM_FLAG_OUT("=@ccc", "=qm") (carry) ); break; default: -# ifdef __x86_64__ +#ifdef __x86_64__ asm ( "rdrand %k0" ASM_FLAG_OUT(, "; setc %1") : "=r" (dst->val), ASM_FLAG_OUT("=@ccc", "=qm") (carry) ); break; case 8: -# endif +#endif asm ( "rdrand %0" ASM_FLAG_OUT(, "; setc %1") : "=r" (dst->val), ASM_FLAG_OUT("=@ccc", "=qm") (carry) ); break; @@ -57,9 +56,6 @@ int x86emul_0fc7(struct x86_emulate_state *s, if ( carry ) regs->eflags |= X86_EFLAGS_CF; break; -#else - return X86EMUL_UNIMPLEMENTED; -#endif case 7: /* rdseed / rdpid */ if ( s->vex.pfx == vex_f3 ) /* rdpid */ @@ -77,7 +73,7 @@ int x86emul_0fc7(struct x86_emulate_state *s, dst->bytes = 4; break; } -#ifdef HAVE_AS_RDSEED + generate_exception_if(s->vex.pfx >= vex_f3, X86_EXC_UD); host_and_vcpu_must_have(rdseed); *dst = s->ea; @@ -88,12 +84,12 @@ int x86emul_0fc7(struct x86_emulate_state *s, : "=r" (dst->val), ASM_FLAG_OUT("=@ccc", "=qm") (carry) ); break; default: -# ifdef __x86_64__ +#ifdef __x86_64__ asm ( "rdseed %k0" ASM_FLAG_OUT(, "; setc %1") : "=r" (dst->val), ASM_FLAG_OUT("=@ccc", "=qm") (carry) ); break; case 8: -# endif +#endif asm ( "rdseed %0" ASM_FLAG_OUT(, "; setc %1") : "=r" (dst->val), ASM_FLAG_OUT("=@ccc", "=qm") (carry) ); break; @@ -102,7 +98,6 @@ int x86emul_0fc7(struct x86_emulate_state *s, if ( carry ) regs->eflags |= X86_EFLAGS_CF; break; -#endif } } else From patchwork Thu Apr 3 18:23:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14037511 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C9BDC3600C for ; Thu, 3 Apr 2025 18:31:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.937117.1338177 (Exim 4.92) (envelope-from ) id 1u0PLS-0006LS-Hp; Thu, 03 Apr 2025 18:31:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 937117.1338177; Thu, 03 Apr 2025 18:31:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PLS-0006LL-Dn; Thu, 03 Apr 2025 18:31:18 +0000 Received: by outflank-mailman (input) for mailman id 937117; Thu, 03 Apr 2025 18:31:16 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0PE6-0001N1-A1 for xen-devel@lists.xenproject.org; Thu, 03 Apr 2025 18:23:42 +0000 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c31d4645-10b8-11f0-9ffb-bf95429c2676; Thu, 03 Apr 2025 20:23:38 +0200 (CEST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c31d4645-10b8-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743704617; x=1743963817; bh=D9HZ36OBMZA9sIUaGxeMjO+UOWm/VDTojn44aNu2MRk=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=e4hZb91LzXNCKy1yuTR+9aIzDdgYcKNqmytcq179tyDuwTc6KaVHptwjKxt6rDOgS 6vexmk8eVMhjjV0Td+ch6AhW8DOyblH44eyR2hJZC8qmdd2b6H9EaTUR8nH8mtkpEU ed6TvuMgm5/IwluVrFFYtocZlJv2KpFxPsjfqNCLISF6s3nDuXE3EOGgDkIiE8NoVF mF7b5Um7ycacVTAuisSbwzKuC71tO7/B+1RzPAF+L0Q4zsQdYswrlF8cn6PVQqn2p5 shI2XF0GDLp2n625HN5zWIewNVOKHlJ4d4wKc7n1EpWT3g1UDQU93zxyiqwRfo+Ufh qPO69uGACudmg== Date: Thu, 03 Apr 2025 18:23:32 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org, michal.orzel@amd.com, roger.pau@citrix.com, sstabellini@kernel.org, dmukhin@ford.com Subject: [PATCH v2 6/6] x86/vmx: rework VMX wrappers to use `asm goto()` Message-ID: <20250403182250.3329498-7-dmukhin@ford.com> In-Reply-To: <20250403182250.3329498-1-dmukhin@ford.com> References: <20250403182250.3329498-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: a796a4a4237e8e45901dcb32a84db62739145c57 MIME-Version: 1.0 From: Denis Mukhin Improve error handling in VMX wrappers by switching to `asm goto()` where possible. vmread_safe() kept as is because the minimally required baseline GCC does not support output operands in `asm goto`. Resolves: https://gitlab.com/xen-project/xen/-/work_items/210 Signed-off-by: Denis Mukhin --- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 141 +++++++++++++------------ 1 file changed, 73 insertions(+), 68 deletions(-) diff --git a/xen/arch/x86/include/asm/hvm/vmx/vmx.h b/xen/arch/x86/include/asm/hvm/vmx/vmx.h index ed6a6986b9..19d41f7b90 100644 --- a/xen/arch/x86/include/asm/hvm/vmx/vmx.h +++ b/xen/arch/x86/include/asm/hvm/vmx/vmx.h @@ -294,54 +294,57 @@ extern uint8_t posted_intr_vector; static always_inline void __vmptrld(u64 addr) { - asm volatile ( "vmptrld %0\n" - /* CF==1 or ZF==1 --> BUG() */ - UNLIKELY_START(be, vmptrld) - _ASM_BUGFRAME_TEXT(0) - UNLIKELY_END_SECTION - : - : "m" (addr), - _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) - : "memory" ); + asm goto ( "vmptrld %[addr]\n" + "jbe %l[vmfail]\n\t" + : + : [addr] "m" (addr) + : "memory" + : vmfail ); + return; + + vmfail: + BUG(); } static always_inline void __vmpclear(u64 addr) { - asm volatile ( "vmclear %0\n" - /* CF==1 or ZF==1 --> BUG() */ - UNLIKELY_START(be, vmclear) - _ASM_BUGFRAME_TEXT(0) - UNLIKELY_END_SECTION - : - : "m" (addr), - _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) - : "memory" ); + asm goto ( "vmclear %[addr]\n" + "jbe %l[vmfail]\n\t" + : + : [addr] "m" (addr) + : "memory" + : vmfail ); + return; + + vmfail: + BUG(); } static always_inline void __vmread(unsigned long field, unsigned long *value) { - asm volatile ( "vmread %1, %0\n\t" - /* CF==1 or ZF==1 --> BUG() */ - UNLIKELY_START(be, vmread) - _ASM_BUGFRAME_TEXT(0) - UNLIKELY_END_SECTION - : "=rm" (*value) - : "r" (field), - _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) - ); + bool vmfail; + + asm volatile ( "vmread %[field], %[value]\n\t" + "setbe %[vmfail]\n\t" + : [value] "=rm" (*value), [vmfail] "=rm" (vmfail) + : [field] "r" (field) + : "cc" ); + if ( vmfail ) + BUG(); } static always_inline void __vmwrite(unsigned long field, unsigned long value) { - asm volatile ( "vmwrite %1, %0\n" - /* CF==1 or ZF==1 --> BUG() */ - UNLIKELY_START(be, vmwrite) - _ASM_BUGFRAME_TEXT(0) - UNLIKELY_END_SECTION - : - : "r" (field) , "rm" (value), - _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) - ); + asm goto ( "vmwrite %[value], %[field]\n\t" + "jbe %l[vmfail]\n\t" + : + : [field] "r" (field), [value] "rm" (value) + : + : vmfail ); + return; + + vmfail: + BUG(); } static inline enum vmx_insn_errno vmread_safe(unsigned long field, @@ -369,22 +372,22 @@ static inline enum vmx_insn_errno vmread_safe(unsigned long field, static inline enum vmx_insn_errno vmwrite_safe(unsigned long field, unsigned long value) { - unsigned long ret = VMX_INSN_SUCCEED; - bool fail_invalid, fail_valid; + unsigned long ret; - asm volatile ( "vmwrite %[value], %[field]\n\t" - ASM_FLAG_OUT(, "setc %[invalid]\n\t") - ASM_FLAG_OUT(, "setz %[valid]\n\t") - : ASM_FLAG_OUT("=@ccc", [invalid] "=rm") (fail_invalid), - ASM_FLAG_OUT("=@ccz", [valid] "=rm") (fail_valid) - : [field] "r" (field), - [value] "rm" (value) ); + asm goto ( "vmwrite %[value], %[field]\n\t" + "jc %l[vmfail_invalid]\n\t" + "jz %l[vmfail_error]\n\t" + : + : [field] "r" (field), [value] "rm" (value) + : + : vmfail_invalid, vmfail_error ); + return VMX_INSN_SUCCEED; - if ( unlikely(fail_invalid) ) - ret = VMX_INSN_FAIL_INVALID; - else if ( unlikely(fail_valid) ) - __vmread(VM_INSTRUCTION_ERROR, &ret); + vmfail_invalid: + return VMX_INSN_FAIL_INVALID; + vmfail_error: + __vmread(VM_INSTRUCTION_ERROR, &ret); return ret; } @@ -402,15 +405,16 @@ static always_inline void __invept(unsigned long type, uint64_t eptp) !cpu_has_vmx_ept_invept_single_context ) type = INVEPT_ALL_CONTEXT; - asm volatile ( "invept %0, %1\n" - /* CF==1 or ZF==1 --> BUG() */ - UNLIKELY_START(be, invept) - _ASM_BUGFRAME_TEXT(0) - UNLIKELY_END_SECTION - : - : "m" (operand), "r" (type), - _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) - : "memory" ); + asm goto ( "invept %[operand], %[type]\n" + "jbe %l[vmfail]\n\t" + : + : [operand] "m" (operand), [type] "r" (type) + : "memory" + : vmfail ); + return; + + vmfail: + BUG(); } static always_inline void __invvpid(unsigned long type, u16 vpid, u64 gva) @@ -422,16 +426,17 @@ static always_inline void __invvpid(unsigned long type, u16 vpid, u64 gva) } operand = {vpid, 0, gva}; /* Fix up #UD exceptions which occur when TLBs are flushed before VMXON. */ - asm volatile ( "1: invvpid %0, %1\n" - /* CF==1 or ZF==1 --> BUG() */ - UNLIKELY_START(be, invvpid) - _ASM_BUGFRAME_TEXT(0) - UNLIKELY_END_SECTION "\n" - "2:" _ASM_EXTABLE(1b, 2b) - : - : "m" (operand), "r" (type), - _ASM_BUGFRAME_INFO(BUGFRAME_bug, __LINE__, __FILE__, 0) - : "memory" ); + asm goto ( "1: invvpid %[operand], %[type]\n" + " jbe %l[vmfail]\n\t" + "2:" _ASM_EXTABLE(1b, 2b) + : + : [operand] "m" (operand), [type] "r" (type) + : "memory" + : vmfail ); + return; + + vmfail: + BUG(); } static inline void ept_sync_all(void)