From patchwork Sat Apr 5 01:25:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Mukhin X-Patchwork-Id: 14039068 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 0F8C4C36010 for ; Sat, 5 Apr 2025 01:25:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.938783.1339276 (Exim 4.92) (envelope-from ) id 1u0sHi-0007YD-Oy; Sat, 05 Apr 2025 01:25:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 938783.1339276; Sat, 05 Apr 2025 01:25:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1u0sHi-0007Y4-Ke; Sat, 05 Apr 2025 01:25:22 +0000 Received: by outflank-mailman (input) for mailman id 938783; Sat, 05 Apr 2025 01:25:21 +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 1u0sHg-0007Xy-G4 for xen-devel@lists.xenproject.org; Sat, 05 Apr 2025 01:25:21 +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 d364345d-11bc-11f0-9ffb-bf95429c2676; Sat, 05 Apr 2025 03:25:15 +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: d364345d-11bc-11f0-9ffb-bf95429c2676 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1743816312; x=1744075512; bh=sBsbW4LWF4zCxNUXqQukytdeUPM5cHk88crdpbHj+Ls=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=Jx3cKvChI0kTY2MIWjdo23RvCva8z8lzk8RpHsF1okJ8IM3tXXxrFkrFDmM30beLq 2/OUfhgO2gw/+ouBDvq7Kcg8t/id4ytIuvnzmK1Eu5UTlXjva6YDES8MBiw6nT+IMX zmrFwi5O0qdfmgORQ5hAEBFJNRP4D40/l9Uq1cNrmP7HhkHdXygs9AT4a9rgGIUp5J 8WSiYxn+choD7AobLOzZwy5UqR7dRUYJ09DOWBFV6Wxiau5VJB+4EZTZY5O3YtynPG VPhZlUTRbxnqWwyzfyX0/qanicRcJuoJzZOfSyKTxTzlrqXFppoUe4hXiKC3OOFzQ5 UxjIG+UOP9hxw== Date: Sat, 05 Apr 2025 01:25:07 +0000 To: xen-devel@lists.xenproject.org From: dmkhn@proton.me Cc: andrew.cooper3@citrix.com, jbeulich@suse.com, roger.pau@citrix.com, dmukhin@ford.com Subject: [PATCH v3] x86/emulate: Remove HAVE_AS_RDRAND and HAVE_AS_RDSEED Message-ID: <20250405012417.3108759-1-dmukhin@ford.com> Feedback-ID: 123220910:user:proton X-Pm-Message-ID: 1029feedc10450cedfe9e1a58beb8eea82b1bca1 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 --- Changes since v2: - updated arch_get_random() - Link to v2: https://lore.kernel.org/xen-devel/20250403182250.3329498-6-dmukhin@ford.com/ --- xen/arch/x86/arch.mk | 2 -- xen/arch/x86/include/asm/random.h | 2 +- xen/arch/x86/x86_emulate/0fc7.c | 15 +++++---------- 3 files changed, 6 insertions(+), 13 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/include/asm/random.h b/xen/arch/x86/include/asm/random.h index 9e1fe0bc1d..e1c1c765e1 100644 --- a/xen/arch/x86/include/asm/random.h +++ b/xen/arch/x86/include/asm/random.h @@ -8,7 +8,7 @@ static inline unsigned int arch_get_random(void) unsigned int val = 0; if ( cpu_has(¤t_cpu_data, X86_FEATURE_RDRAND) ) - asm volatile ( ".byte 0x0f,0xc7,0xf0" : "+a" (val) ); + asm volatile ( "rdrand %0" : "=a" (val) ); return val; } 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