From nobody Sat May 4 07:41:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1558366070; cv=none; d=zoho.com; s=zohoarc; b=di7czAkgPspZcnq9WdO0lbd/MCrmVgEgHh+0YuuJRwtCzRNnNc7k0mY6snjumQiK+6w9x9yeCqoT8pvTXXSgMPxVFa6idnVqwQmESH3fg1HXPFQBZZhT97tsinlPPSfnwkWvvh812oF57LV0IYKx+AVEfRHbFEU2jSNyZWIFD/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558366070; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=bU8sx7c4gfMg/e8v8Vm8a6WsIdKyjcwaSosyJdhocig=; b=eZgC/RFbPbr2ToEjocbpkXlr4qweYB/hcuTyd+HRq4o9x4apqz6/6Jsb3SscI5dXBNAZCocI1kkr88vwNJKnLv8t6ZXek/9dVZNvJedZrekzVkxU/zgM80zYrFo/VRhSlT0uxx6eIcFCZc/oT4XEG/Xxj0lzMvLO5EBGSh2NEGU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1558366070500198.58956890932302; Mon, 20 May 2019 08:27:50 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hSkBO-0004sh-0h; Mon, 20 May 2019 15:26:34 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hSkBN-0004sc-Jq for xen-devel@lists.xenproject.org; Mon, 20 May 2019 15:26:33 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a3d2605a-7b13-11e9-bda7-9bde5fc7a186; Mon, 20 May 2019 15:26:30 +0000 (UTC) X-Inumbo-ID: a3d2605a-7b13-11e9-bda7-9bde5fc7a186 Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@MIAPEX02MSOL02.citrite.net Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=23.29.105.83; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 23.29.105.83 as permitted sender) identity=mailfrom; client-ip=23.29.105.83; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:23.29.105.83 ip4:162.221.156.83 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@MIAPEX02MSOL02.citrite.net) identity=helo; client-ip=23.29.105.83; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@MIAPEX02MSOL02.citrite.net"; x-conformance=sidf_compatible IronPort-SDR: 9zP0fkp1dGSe18+JR1CZgjlDbka9kCoonsXhXMfBZrLvxFtHXkvwGmfkXtX7/La4bQbNJmbS7I 8ranl0JejigCtbMrpjVccynVhXSVwIoby/bSQtVtIUSQysP3zeVZCUSNtKK7gAYf95YbDr6C85 OFPVr0lBehpm4YvuF80mRtRxilirDYcV5Bjx+dERgrtSfrGRWxwRuXd1OZOWwAIC3ZeqjB2X3c w6Kpe/V3uQGQvcZFCA+3OpgwEg5aE2XlDDCNGFXV+aKL6ZnmsUVyw/HXIfQUvIitlmx1nADDda 820= X-SBRS: 2.7 X-MesageID: 671591 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 23.29.105.83 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.60,491,1549947600"; d="scan'208";a="671591" From: Andrew Cooper To: Xen-devel Date: Mon, 20 May 2019 16:26:21 +0100 Message-ID: <1558365981-3175-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/cpuid: Don't use volatile asm statements X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Common use of the CPUID instruction operates without side effects. Let the compiler better optimise code by dropping the volatile qualifier. The only place where order matters is for Intel microcode loading, where executing a CPUID instruction is used for its side effect of updating MSR_IA32_UCODE_REV. The existing logic is buggy because GCC has been seen to reorder independent asm volatile statements. Opencode the two cases, with a compiler barrier to enforce the correct ordering of operations. While here, fix the comment, which isn't correct. The SDM doesn't state th= at a read of leaf 1 is required - just that a CPUID instruction is required. Using leaf 0 results in better code generation, following the write of 0 to MSR_IA32_UCODE_REV. Suggested-by: Jan Beulich Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/microcode_intel.c | 13 ++++++++----- xen/include/asm-x86/processor.h | 12 ++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/microcode_intel.c b/xen/arch/x86/microcode_intel.c index 22fdeca..088cfa2 100644 --- a/xen/arch/x86/microcode_intel.c +++ b/xen/arch/x86/microcode_intel.c @@ -99,6 +99,7 @@ static DEFINE_SPINLOCK(microcode_update_lock); static int collect_cpu_info(unsigned int cpu_num, struct cpu_signature *cs= ig) { struct cpuinfo_x86 *c =3D &cpu_data[cpu_num]; + unsigned long tmp; uint64_t msr_content; =20 BUG_ON(cpu_num !=3D smp_processor_id()); @@ -122,8 +123,9 @@ static int collect_cpu_info(unsigned int cpu_num, struc= t cpu_signature *csig) } =20 wrmsrl(MSR_IA32_UCODE_REV, 0x0ULL); - /* As documented in the SDM: Do a CPUID 1 here */ - cpuid_eax(1); + /* As documented in the SDM: Do a CPUID here. */ + asm volatile ( "cpuid" : "=3Da" (tmp) : "a" (0) + : "bx", "cx", "dx", "memory" ); =20 /* get the current revision from MSR 0x8B */ rdmsrl(MSR_IA32_UCODE_REV, msr_content); @@ -286,7 +288,7 @@ static int get_matching_microcode(const void *mc, unsig= ned int cpu) =20 static int apply_microcode(unsigned int cpu) { - unsigned long flags; + unsigned long flags, tmp; uint64_t msr_content; unsigned int val[2]; unsigned int cpu_num =3D raw_smp_processor_id(); @@ -305,8 +307,9 @@ static int apply_microcode(unsigned int cpu) wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)uci->mc.mc_intel->bits); wrmsrl(MSR_IA32_UCODE_REV, 0x0ULL); =20 - /* As documented in the SDM: Do a CPUID 1 here */ - cpuid_eax(1); + /* As documented in the SDM: Do a CPUID here. */ + asm volatile ( "cpuid" : "=3Da" (tmp) : "a" (0) + : "bx", "cx", "dx", "memory" ); =20 /* get the current revision from MSR 0x8B */ rdmsrl(MSR_IA32_UCODE_REV, msr_content); diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processo= r.h index cef3ffb..3c76e7e 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -185,7 +185,7 @@ unsigned int apicid_to_socket(unsigned int); * resulting in stale register contents being returned. */ #define cpuid(_op,_eax,_ebx,_ecx,_edx) \ - asm volatile ( "cpuid" \ + asm ( "cpuid" \ : "=3Da" (*(int *)(_eax)), \ "=3Db" (*(int *)(_ebx)), \ "=3Dc" (*(int *)(_ecx)), \ @@ -201,7 +201,7 @@ static inline void cpuid_count( unsigned int *ecx, unsigned int *edx) { - asm volatile ( "cpuid" + asm ( "cpuid" : "=3Da" (*eax), "=3Db" (*ebx), "=3Dc" (*ecx), "=3Dd" (*edx) : "0" (op), "c" (count) ); } @@ -213,7 +213,7 @@ static always_inline unsigned int cpuid_eax(unsigned in= t op) { unsigned int eax; =20 - asm volatile ( "cpuid" + asm ( "cpuid" : "=3Da" (eax) : "0" (op) : "bx", "cx", "dx" ); @@ -224,7 +224,7 @@ static always_inline unsigned int cpuid_ebx(unsigned in= t op) { unsigned int eax, ebx; =20 - asm volatile ( "cpuid" + asm ( "cpuid" : "=3Da" (eax), "=3Db" (ebx) : "0" (op) : "cx", "dx" ); @@ -235,7 +235,7 @@ static always_inline unsigned int cpuid_ecx(unsigned in= t op) { unsigned int eax, ecx; =20 - asm volatile ( "cpuid" + asm ( "cpuid" : "=3Da" (eax), "=3Dc" (ecx) : "0" (op) : "bx", "dx" ); @@ -246,7 +246,7 @@ static always_inline unsigned int cpuid_edx(unsigned in= t op) { unsigned int eax, edx; =20 - asm volatile ( "cpuid" + asm ( "cpuid" : "=3Da" (eax), "=3Dd" (edx) : "0" (op) : "bx", "cx" ); --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel