From nobody Sat Apr 27 07:45:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1585312200; cv=none; d=zohomail.com; s=zohoarc; b=bR4g7jPlDLuiidnVuePnAkyzuXcqJhpNVJCDUyIjUJ/OoM7bR/5gQ351oSVBGLX5GwUugbT7WrIl25qzoukcSf09Fc33wRUrqfsGObnERg7evME2WjNopAx/h/da8Z06403LhGA5AcTEVOPW4B9zBCC7iqPciLjVOS8s5PwBU2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585312200; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O4/43A5OqfBSTImqqhG9O33hTNi1OnJ1JF7KEZU5Dh8=; b=HEjB6wvS5ZwUO519edYUv6K/9xMaCnkMP9QOWZTb3fjzsqsPkm7GRzdZPZTUcLEeNTx8aDSdlhOw8geaGDw/YNuRwI4swoQ9kF9ezeoZ/Rsu6qob0DEUk91DQ7kbeohxZVGK1XBLTEAwGeOBPF3j8HAbT9hwVpcsvXEGtrrrYv8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585312200090441.2198091123827; Fri, 27 Mar 2020 05:30:00 -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 1jHo7A-0006DU-2B; Fri, 27 Mar 2020 12:29:32 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHo78-0006Ce-UN for xen-devel@lists.xenproject.org; Fri, 27 Mar 2020 12:29:30 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9ac2ef76-7026-11ea-92cf-bc764e2007e4; Fri, 27 Mar 2020 12:29:30 +0000 (UTC) X-Inumbo-ID: 9ac2ef76-7026-11ea-92cf-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1585312169; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uGU0V8wb/kKur660Cw0sPJOBaW2AFi9mmU5wv+RAVjk=; b=KLSrl3PWFqJlT/xpJBX2p5Z1TIXZLQxvb5q7VPbZcgkTwE2GbzNtCKMP UNcSb5Nhhk/VhNLbfxuKUzBXHqMXGu1yHYcxv9rhb56wBin8bZKNVjGz+ MbFbhRaUCp8U+BpgaYTJji282jtbySBUgspgnAi4cZZ3FHdj4HAX4kklV E=; Authentication-Results: esa5.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@mail.citrix.com Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.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:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: Wvyy931gahX+gSObvGG2rqMl07bkQAS4CIOceqWUdtwr1BiTDUZJrSRAZGiRfHYVHdDaTdF8Ls ESv+AhwSXVu6WF/dUnGI8FoTlHWVwzn3Zxk9oRDCns7Dijuc8rEeNEHiAsrEwM+bGlWU9aVPP5 cAqO1WngzxKK7Vuwj5F6Ijz19wo9yLbDH3KL1xpxWbzuLyf0v6D41N7gKkc3nfNSHtzG7z6BBN 1jpLhJuy2SsUdtkC0oWxDNt9EOjUZPPcO5T269a2kFRLyHKHHlcf+tbjcJRIrdOYn0L5GJthhg D/k= X-SBRS: 2.7 X-MesageID: 15078430 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,312,1580792400"; d="scan'208";a="15078430" From: Andrew Cooper To: Xen-devel Date: Fri, 27 Mar 2020 12:28:55 +0000 Message-ID: <20200327122901.11569-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200327122901.11569-1-andrew.cooper3@citrix.com> References: <20200327122901.11569-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH v2 1/7] x86/ucode: Remove unnecessary indirection in struct microcode_patch 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?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Currently, each cpu_request_microcode() allocates a struct microcode_patch, which is a single pointer to a separate allocated structure. This is wasteful. Fixing this is complicated because the common microcode_free_patch() code is responsible for freeing struct microcode_patch, despite this being asymmetr= ic with how it is allocated. Make struct microcode_patch fully opaque to the common logic. This involves moving the responsibility for freeing struct microcode_patch fully into the free_patch() hook. In each vendor logic, use some temporary ifdef-ary (cleaned up in subsequent changes) to reduce the churn as much as possible, and forgo allocating the intermediate pointer in cpu_request_microcode(). Suggested-by: Jan Beulich Signed-off-by: Jan Beulich Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * New --- xen/arch/x86/cpu/microcode/amd.c | 30 ++++++++++++------------------ xen/arch/x86/cpu/microcode/core.c | 3 +-- xen/arch/x86/cpu/microcode/intel.c | 31 ++++++++++++------------------- xen/arch/x86/cpu/microcode/private.h | 11 +++-------- 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/= amd.c index 122b8309af..1b9373f0d9 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -60,13 +60,16 @@ struct __packed microcode_header_amd { #define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000 #define UCODE_UCODE_TYPE 0x00000001 =20 -struct microcode_amd { +struct microcode_patch { void *mpb; size_t mpb_size; struct equiv_cpu_entry *equiv_cpu_table; size_t equiv_cpu_table_size; }; =20 +/* Temporary, until the microcode_* structure are disentangled. */ +#define microcode_amd microcode_patch + struct mpbhdr { uint32_t type; uint32_t len; @@ -177,13 +180,11 @@ static enum microcode_match_result microcode_fits( =20 static bool match_cpu(const struct microcode_patch *patch) { - return patch && (microcode_fits(patch->mc_amd) =3D=3D NEW_UCODE); + return patch && (microcode_fits(patch) =3D=3D NEW_UCODE); } =20 -static void free_patch(void *mc) +static void free_patch(struct microcode_patch *mc_amd) { - struct microcode_amd *mc_amd =3D mc; - if ( mc_amd ) { xfree(mc_amd->equiv_cpu_table); @@ -206,12 +207,12 @@ static enum microcode_match_result compare_header( static enum microcode_match_result compare_patch( const struct microcode_patch *new, const struct microcode_patch *old) { - const struct microcode_header_amd *new_header =3D new->mc_amd->mpb; - const struct microcode_header_amd *old_header =3D old->mc_amd->mpb; + const struct microcode_header_amd *new_header =3D new->mpb; + const struct microcode_header_amd *old_header =3D old->mpb; =20 /* Both patches to compare are supposed to be applicable to local CPU.= */ - ASSERT(microcode_fits(new->mc_amd) !=3D MIS_UCODE); - ASSERT(microcode_fits(old->mc_amd) !=3D MIS_UCODE); + ASSERT(microcode_fits(new) !=3D MIS_UCODE); + ASSERT(microcode_fits(old) !=3D MIS_UCODE); =20 return compare_header(new_header, old_header); } @@ -230,7 +231,7 @@ static int apply_microcode(const struct microcode_patch= *patch) if ( !match_cpu(patch) ) return -EINVAL; =20 - hdr =3D patch->mc_amd->mpb; + hdr =3D patch->mpb; =20 BUG_ON(local_irq_is_enabled()); =20 @@ -554,14 +555,7 @@ static struct microcode_patch *cpu_request_microcode(c= onst void *buf, { mc_amd->mpb =3D saved; mc_amd->mpb_size =3D saved_size; - patch =3D xmalloc(struct microcode_patch); - if ( patch ) - patch->mc_amd =3D mc_amd; - else - { - free_patch(mc_amd); - error =3D -ENOMEM; - } + patch =3D mc_amd; } else free_patch(mc_amd); diff --git a/xen/arch/x86/cpu/microcode/core.c b/xen/arch/x86/cpu/microcode= /core.c index 61150e04c8..b3e5913d49 100644 --- a/xen/arch/x86/cpu/microcode/core.c +++ b/xen/arch/x86/cpu/microcode/core.c @@ -245,8 +245,7 @@ static struct microcode_patch *parse_blob(const char *b= uf, size_t len) =20 static void microcode_free_patch(struct microcode_patch *microcode_patch) { - microcode_ops->free_patch(microcode_patch->mc); - xfree(microcode_patch); + microcode_ops->free_patch(microcode_patch); } =20 /* Return true if cache gets updated. Otherwise, return false */ diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index 78455aa0ae..a69f7fe1de 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -52,11 +52,14 @@ struct microcode_header_intel { unsigned int reserved[3]; }; =20 -struct microcode_intel { +struct microcode_patch { struct microcode_header_intel hdr; unsigned int bits[0]; }; =20 +/* Temporary, until the microcode_* structure are disentangled. */ +#define microcode_intel microcode_patch + /* microcode format is extended from prescott processors */ struct extended_signature { unsigned int sig; @@ -245,12 +248,12 @@ static bool match_cpu(const struct microcode_patch *p= atch) if ( !patch ) return false; =20 - return microcode_update_match(&patch->mc_intel->hdr) =3D=3D NEW_UCODE; + return microcode_update_match(&patch->hdr) =3D=3D NEW_UCODE; } =20 -static void free_patch(void *mc) +static void free_patch(struct microcode_patch *patch) { - xfree(mc); + xfree(patch); } =20 static enum microcode_match_result compare_patch( @@ -260,11 +263,10 @@ static enum microcode_match_result compare_patch( * Both patches to compare are supposed to be applicable to local CPU. * Just compare the revision number. */ - ASSERT(microcode_update_match(&old->mc_intel->hdr) !=3D MIS_UCODE); - ASSERT(microcode_update_match(&new->mc_intel->hdr) !=3D MIS_UCODE); + ASSERT(microcode_update_match(&old->hdr) !=3D MIS_UCODE); + ASSERT(microcode_update_match(&new->hdr) !=3D MIS_UCODE); =20 - return (new->mc_intel->hdr.rev > old->mc_intel->hdr.rev) ? NEW_UCODE - : OLD_UCODE; + return (new->hdr.rev > old->hdr.rev) ? NEW_UCODE : OLD_UCODE; } =20 static int apply_microcode(const struct microcode_patch *patch) @@ -281,7 +283,7 @@ static int apply_microcode(const struct microcode_patch= *patch) if ( !match_cpu(patch) ) return -EINVAL; =20 - mc_intel =3D patch->mc_intel; + mc_intel =3D patch; =20 BUG_ON(local_irq_is_enabled()); =20 @@ -372,16 +374,7 @@ static struct microcode_patch *cpu_request_microcode(c= onst void *buf, error =3D offset; =20 if ( saved ) - { - patch =3D xmalloc(struct microcode_patch); - if ( patch ) - patch->mc_intel =3D saved; - else - { - xfree(saved); - error =3D -ENOMEM; - } - } + patch =3D saved; =20 if ( error && !patch ) patch =3D ERR_PTR(error); diff --git a/xen/arch/x86/cpu/microcode/private.h b/xen/arch/x86/cpu/microc= ode/private.h index 230b935c94..df0d0852cd 100644 --- a/xen/arch/x86/cpu/microcode/private.h +++ b/xen/arch/x86/cpu/microcode/private.h @@ -11,13 +11,8 @@ enum microcode_match_result { MIS_UCODE, /* signature mismatched */ }; =20 -struct microcode_patch { - union { - struct microcode_intel *mc_intel; - struct microcode_amd *mc_amd; - void *mc; - }; -}; +/* Opaque. Internals are vendor-specific. */ +struct microcode_patch; =20 struct microcode_ops { /* @@ -62,7 +57,7 @@ struct microcode_ops { void (*end_update_percpu)(void); =20 /* Free a patch previously allocated by cpu_request_microcode(). */ - void (*free_patch)(void *mc); + void (*free_patch)(struct microcode_patch *patch); =20 /* * Is the microcode patch applicable for the current CPU, and newer th= an --=20 2.11.0 From nobody Sat Apr 27 07:45:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1585312184; cv=none; d=zohomail.com; s=zohoarc; b=eRgce+TwmduLgVcxM7yY+Y/P9ZDZicru63J9J7aMvIpXsX1oVuRd5hfR/BoaotXhVsYMQCQDoOhLabKmj9zHAE2vHbw+UXDhnru9pk1Ig/xfLwZvlhw4qQ1tbd3eZBkBZeu3A/V2/HPM1HP3eC2xvtqVDbiMp1WCfnIKDoZZoDE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585312184; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FsnTCkB4uPsC6VnzVrfpwUdOIBDGVXn1WTiY2KZOH0s=; b=ekzBVxjbVdbCLsBugMMuJqLkl6Rd0DCpMI9+66456fzy3u0g3uLcXgQHgdsT8rio6wWZGBKS19WebDtJs+UGw4+LU5YH/eusSbizYjxlOPy+PkDsQzBSXXigKNib5WI5cZiJMVDV+JYIhqekO5BMVaIG9gPbADmkubIXfQ+dFyo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585312184838396.1599790252152; Fri, 27 Mar 2020 05:29:44 -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 1jHo6r-00062W-SW; Fri, 27 Mar 2020 12:29:13 +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 1jHo6q-00062R-DV for xen-devel@lists.xenproject.org; Fri, 27 Mar 2020 12:29:12 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8fc40588-7026-11ea-8967-12813bfff9fa; Fri, 27 Mar 2020 12:29:11 +0000 (UTC) X-Inumbo-ID: 8fc40588-7026-11ea-8967-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1585312151; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F4zG2oS/V65anzLwMJhTAh9CXPgXHH8XLalce+FjePw=; b=KN420yusu1xzthHcujXFBdLHV6ux1TTPCZZvmpEN1+msZgWhBx718uf2 W+YZwqMWO5J/jfi2eSSgGI6dEKbkXbqJ/88pP0ZMhl88gUMNqVxgSCd78 gvb7wv97msViwiMrUs8LuBXGW0ew+/PVlDtIaA/n42WqcZwm1a+XYbPEs Y=; 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@mail.citrix.com Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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=162.221.158.21; 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 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; 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:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: cuN6gleoL2Ot3hA/q1ktS/2KJxPDeAUjxshhH3CM9nNRU9eQGhkTdgB5qPpQH19wWQK1UP3xsQ Vxe7ahwdmL/J52Dq2vxZT/LodVYDNcLNzJk0cYDxP0zIVU4MfFEyNQixvLVXU4oKJx9M3bcWCO S2rhgfMa6sc8V1Lnyxegur11Jl+o+qTbWjoKD9CF0bRD65gUuV6wMAIK/UlUIBEQS1M8vEqzMv tUNLyARkxbwoK6O13mdawPfURtIcU7ZS4WWIVIrMVvqGJWSmISXGNZSx0j4zvG/w0swpuA4T/4 TLw= X-SBRS: 2.7 X-MesageID: 14735335 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,312,1580792400"; d="scan'208";a="14735335" From: Andrew Cooper To: Xen-devel Date: Fri, 27 Mar 2020 12:28:56 +0000 Message-ID: <20200327122901.11569-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200327122901.11569-1-andrew.cooper3@citrix.com> References: <20200327122901.11569-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH v2 2/7] x86/ucode/intel: Adjust microcode_sanity_check() to not take void * 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 , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) microcode_sanity_check()'s callers actually call it with a mixture of microcode_intel(/patch) and microcode_header_intel pointers, which is fragi= le. Rework it to take struct microcode_patch *, which in turn requires microcode_update_match()'s type to be altered. No functional change - compiled binary is identical. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * Rebase over struct microcode_patch re-work --- xen/arch/x86/cpu/microcode/intel.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index a69f7fe1de..77539a00be 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -118,9 +118,9 @@ static int collect_cpu_info(struct cpu_signature *csig) return 0; } =20 -static int microcode_sanity_check(const void *mc) +static int microcode_sanity_check(const struct microcode_patch *mc) { - const struct microcode_header_intel *mc_header =3D mc; + const struct microcode_header_intel *mc_header =3D &mc->hdr; const struct extended_sigtable *ext_header =3D NULL; const struct extended_signature *ext_sig; unsigned long total_size, data_size, ext_table_size; @@ -152,7 +152,7 @@ static int microcode_sanity_check(const void *mc) "Small exttable size in microcode data file\n"); return -EINVAL; } - ext_header =3D mc + MC_HEADER_SIZE + data_size; + ext_header =3D (void *)mc + MC_HEADER_SIZE + data_size; if ( ext_table_size !=3D exttable_size(ext_header) ) { printk(KERN_ERR "microcode: error! " @@ -210,8 +210,9 @@ static int microcode_sanity_check(const void *mc) =20 /* Check an update against the CPU signature and current update revision */ static enum microcode_match_result microcode_update_match( - const struct microcode_header_intel *mc_header) + const struct microcode_patch *mc) { + const struct microcode_header_intel *mc_header =3D &mc->hdr; const struct extended_sigtable *ext_header; const struct extended_signature *ext_sig; unsigned int i; @@ -222,7 +223,7 @@ static enum microcode_match_result microcode_update_mat= ch( unsigned long data_size =3D get_datasize(mc_header); const void *end =3D (const void *)mc_header + get_totalsize(mc_header); =20 - ASSERT(!microcode_sanity_check(mc_header)); + ASSERT(!microcode_sanity_check(mc)); if ( sigmatch(sig, mc_header->sig, pf, mc_header->pf) ) return (mc_header->rev > rev) ? NEW_UCODE : OLD_UCODE; =20 @@ -248,7 +249,7 @@ static bool match_cpu(const struct microcode_patch *pat= ch) if ( !patch ) return false; =20 - return microcode_update_match(&patch->hdr) =3D=3D NEW_UCODE; + return microcode_update_match(patch) =3D=3D NEW_UCODE; } =20 static void free_patch(struct microcode_patch *patch) @@ -263,8 +264,8 @@ static enum microcode_match_result compare_patch( * Both patches to compare are supposed to be applicable to local CPU. * Just compare the revision number. */ - ASSERT(microcode_update_match(&old->hdr) !=3D MIS_UCODE); - ASSERT(microcode_update_match(&new->hdr) !=3D MIS_UCODE); + ASSERT(microcode_update_match(old) !=3D MIS_UCODE); + ASSERT(microcode_update_match(new) !=3D MIS_UCODE); =20 return (new->hdr.rev > old->hdr.rev) ? NEW_UCODE : OLD_UCODE; } @@ -361,7 +362,7 @@ static struct microcode_patch *cpu_request_microcode(co= nst void *buf, * If the new update covers current CPU, compare updates and store= the * one with higher revision. */ - if ( (microcode_update_match(&mc->hdr) !=3D MIS_UCODE) && + if ( (microcode_update_match(mc) !=3D MIS_UCODE) && (!saved || (mc->hdr.rev > saved->hdr.rev)) ) { xfree(saved); --=20 2.11.0 From nobody Sat Apr 27 07:45:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1585312197; cv=none; d=zohomail.com; s=zohoarc; b=N6UFWF8i1zaDcq0kdbPCu4pk9SOCzxaaw0TJ3XPc8UX39EjAOCBS1JSr/RZMvsp50Y+QagEXT0Dqwcw7hTp3T4O8lwzmxOeILf0ckZDjJogPvc/C8ciK4ilBmi4R5FolrggTdw9oOnm/7K4rM2Nb48OrjPvYpomoa/0lOogjI0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585312197; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bNDDM+ACabbz6cn7M0KM1ivh2jZdZf/IvygXDl9qi0U=; b=OyijL54bug1OX6yejkc9HDxrkxW43V9yV5b5VH5tMfDfnbGVkmT6UZDQFmYExKXPWrJo01bkyoRTlvBo4owypyBvl2I8TOeO9b2hMCc+d4Ek1swGRL1KVVObEpRI9Ubp0abeLk8ibBCZNpFeVJZJTFevKQAwLLg5Uz4J/9cz9JE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585312197615193.63963912103873; Fri, 27 Mar 2020 05:29:57 -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 1jHo76-0006B3-OM; Fri, 27 Mar 2020 12:29:28 +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 1jHo75-0006A5-EH for xen-devel@lists.xenproject.org; Fri, 27 Mar 2020 12:29:27 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 92fe760c-7026-11ea-8967-12813bfff9fa; Fri, 27 Mar 2020 12:29:17 +0000 (UTC) X-Inumbo-ID: 92fe760c-7026-11ea-8967-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1585312157; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qj7uuUM3UOJjx3jxggL5Q952gnP0pujxYRywhdKJVec=; b=WcYjknZwQiukrUaVgzZfX/MuNvgFb43MsA4q+ZEkOJqoa+EZ+UtnpZJy S7f0Ex5/F9h59C0dOv9MwgjBhS39eub8H5WZkvzk2uzhVOCHElUa7Y2aN 8zKUIPHrf2gpRu8epDdxeSqrwNt7HteKeAsIob0vTM1Ib6GVSUyypXE72 k=; 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@mail.citrix.com Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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=162.221.158.21; 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 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; 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:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: eIr0X/nW18uBV76A9TlW5wq8X3/D8xfRp411KuNQhazB6ixtNi78+AiyCNkvxaH65zF1lpIl+y GDBrlBQtYT5SID+917aamSPDNmcl1bcqxnSJ1fFlVLRtGRd6SxFfMaqDRt6JNqWoHPylLtoMlS cjmzutrV0NtJfaAmpy59FFGSiBi5U8Rqla7DqfyZcVpid/fdzsNM3NOJZ5Ez7jGJkafliSTdAT L3JwWBv/DdsuxoEfvJ9dUhPOLsh4sRMaZLuqk6PMjfybtuji0mI39JFycknxS0k6bBepXn/4NW 6Cc= X-SBRS: 2.7 X-MesageID: 14735339 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,312,1580792400"; d="scan'208";a="14735339" From: Andrew Cooper To: Xen-devel Date: Fri, 27 Mar 2020 12:28:57 +0000 Message-ID: <20200327122901.11569-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200327122901.11569-1-andrew.cooper3@citrix.com> References: <20200327122901.11569-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH v2 3/7] x86/ucode/intel: Remove gratuitous memory allocations from cpu_request_microcode() 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?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) cpu_request_microcode() needs to scan its container and duplicate one blob, but the get_next_ucode_from_buffer() helper duplicates every blob in turn. Furthermore, the length checking is only safe from overflow in 64bit builds. Delete get_next_ucode_from_buffer() and alter the purpose of the saved variable to simply point somewhere in buf until we're ready to return. This is only a modest reduction in absolute code size (-144), but avoids making memory allocations for every blob in the container. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * Rebase over struct microcode_patch re-work * Reinstate printk() for bad data --- xen/arch/x86/cpu/microcode/intel.c | 65 +++++++++++++++-------------------= ---- 1 file changed, 25 insertions(+), 40 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index 77539a00be..2b48959573 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -315,67 +315,52 @@ static int apply_microcode(const struct microcode_pat= ch *patch) return 0; } =20 -static long get_next_ucode_from_buffer(struct microcode_intel **mc, - const uint8_t *buf, unsigned long s= ize, - unsigned long offset) -{ - struct microcode_header_intel *mc_header; - unsigned long total_size; - - /* No more data */ - if ( offset >=3D size ) - return 0; - mc_header =3D (struct microcode_header_intel *)(buf + offset); - total_size =3D get_totalsize(mc_header); - - if ( (offset + total_size) > size ) - { - printk(KERN_ERR "microcode: error! Bad data in microcode data file= \n"); - return -EINVAL; - } - - *mc =3D xmemdup_bytes(mc_header, total_size); - if ( *mc =3D=3D NULL ) - return -ENOMEM; - - return offset + total_size; -} - static struct microcode_patch *cpu_request_microcode(const void *buf, size_t size) { - long offset =3D 0; int error =3D 0; - struct microcode_intel *mc, *saved =3D NULL; + const struct microcode_patch *saved =3D NULL; struct microcode_patch *patch =3D NULL; =20 - while ( (offset =3D get_next_ucode_from_buffer(&mc, buf, size, offset)= ) > 0 ) + while ( size ) { - error =3D microcode_sanity_check(mc); - if ( error ) + const struct microcode_patch *mc; + unsigned int blob_size; + + if ( size < MC_HEADER_SIZE || /* Insufficient space for head= er? */ + (mc =3D buf)->hdr.hdrver !=3D 1 || /* Unrecognised header ver= sion? */ + mc->hdr.ldrver !=3D 1 || /* Unrecognised loader versi= on? */ + size < (blob_size =3D /* Insufficient space for pa= tch? */ + get_totalsize(&mc->hdr)) ) { - xfree(mc); + error =3D -EINVAL; + printk(XENLOG_WARNING "microcode: Bad data in container\n"); break; } =20 + error =3D microcode_sanity_check(mc); + if ( error ) + break; + /* * If the new update covers current CPU, compare updates and store= the * one with higher revision. */ if ( (microcode_update_match(mc) !=3D MIS_UCODE) && (!saved || (mc->hdr.rev > saved->hdr.rev)) ) - { - xfree(saved); saved =3D mc; - } - else - xfree(mc); + + buf +=3D blob_size; + size -=3D blob_size; } - if ( offset < 0 ) - error =3D offset; =20 if ( saved ) - patch =3D saved; + { + patch =3D xmemdup_bytes(saved, get_totalsize(&saved->hdr)); + + if ( !patch ) + error =3D -ENOMEM; + } =20 if ( error && !patch ) patch =3D ERR_PTR(error); --=20 2.11.0 From nobody Sat Apr 27 07:45:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1585312192; cv=none; d=zohomail.com; s=zohoarc; b=J+Kaa73dsq3HgqfOzJLKJkhfRWjOyIwjldqAfGfdCpac26B+W3iok+b/BD0Onoh/BF/B4TpgVo0DScpq4NM4/5Hi9tXB5/6/ztEY3fVNauJmY0UO6ltVzRgm1O453DDIyiu1UWwSB1Y/7AgOEmMqBK5nAsBVsO3oqDwyCtGlaMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585312192; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KX94a6Eom4pPI0eCTArNcHGB30vRKRIYREsFT6ncdds=; b=CtfIBqtWGPWjzkO9yz8zRAD/GRQrqWqE44eIUm0SQUw6amQIBOxJeYwDEEKInmbpLJizVYwJZzzZ3hUX/nL0JjGDGvgddL+TN8XUSjZGGLcRtsGsu6Aw9bUSnBtQ51gfcRBcIDBBlkn5ha/vKb8PC/esGVwj4NxmysHQwosk7SQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585312192033545.3573555666192; Fri, 27 Mar 2020 05:29:52 -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 1jHo6y-000659-NH; Fri, 27 Mar 2020 12:29:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHo6x-00064N-Io for xen-devel@lists.xenproject.org; Fri, 27 Mar 2020 12:29:19 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9354cafc-7026-11ea-bec1-bc764e2007e4; Fri, 27 Mar 2020 12:29:17 +0000 (UTC) X-Inumbo-ID: 9354cafc-7026-11ea-bec1-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1585312157; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CAp4SToMrf/GE3/7UI4jSUn/5KncxmCv5YaP04nxZRY=; b=YGry3Q5RNcEl12Ue1TFqbLNA57d7qDktTrfghf7/RILyP/pUXMt+09ng TG1Jj+fI5ltARIdAdnhaJ9aLlxICXlMLmqDXdDD9ttCDh3tqYg7zduDof X+Y63/yHMaK7z7gP6IhjRIHMQ+sbvl/nHnWUpIGFBlYsIgvjlv4t3fvc5 A=; Authentication-Results: esa4.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@mail.citrix.com Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.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:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: FGLA8j93lMo7VHCZ24D8CeNId4D11kcjIWQuZsQ2FhPmMJuTfJsuj1q75Eo2XOxcNZSQiebfS/ oh+W7I7Ks6Wf7ewg0dRz4JRjU9Hnyk8emYGKKdcfXn2qY54Ry7+awlkdQf1xb2wlNaVRzNT3q4 4F22pD+J+bS2OgJ7ISJMNFbtBxn5jrByivCL2lme4DJXglpQkrOBrHckV5Vf10y5IhbyyEgiM/ IyyNTlNxjZjBQU7K4GO7sUFbAFEsjxQ2P6nMzNV+z3NJ8kelXww1TTe79RoMybtYYfOc9hqM0R kfo= X-SBRS: 2.7 X-MesageID: 15405103 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,312,1580792400"; d="scan'208";a="15405103" From: Andrew Cooper To: Xen-devel Date: Fri, 27 Mar 2020 12:28:58 +0000 Message-ID: <20200327122901.11569-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200327122901.11569-1-andrew.cooper3@citrix.com> References: <20200327122901.11569-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH v2 4/7] x86/ucode/intel: Reimplement get_{data, total}size() helpers 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?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Every caller actually passes a struct microcode_header_intel *, but it is m= ore helpful to us longterm to take struct microcode_patch *. Implement the helpers with proper types, and leave a comment explaining the Pentium Pro/II behaviour with empty {data,total}size fields. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * Rebase over struct microcode_patch re-work * Drop leading underscore --- xen/arch/x86/cpu/microcode/intel.c | 37 ++++++++++++++++++++++------------= --- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index 2b48959573..be2f4871dc 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -46,6 +46,12 @@ struct microcode_header_intel { unsigned int sig; unsigned int cksum; unsigned int ldrver; + + /* + * Microcode for the Pentium Pro and II had all further fields in the + * header reserved, had a fixed datasize of 2000 and totalsize of 2048, + * and didn't use platform flags despite the availability of the MSR. + */ unsigned int pf; unsigned int datasize; unsigned int totalsize; @@ -74,20 +80,21 @@ struct extended_sigtable { struct extended_signature sigs[0]; }; =20 -#define DEFAULT_UCODE_DATASIZE (2000) +#define PPRO_UCODE_DATASIZE 2000 #define MC_HEADER_SIZE (sizeof(struct microcode_header_intel)) -#define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE) #define EXT_HEADER_SIZE (sizeof(struct extended_sigtable)) #define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature)) #define DWSIZE (sizeof(u32)) -#define get_totalsize(mc) \ - (((struct microcode_intel *)mc)->hdr.totalsize ? \ - ((struct microcode_intel *)mc)->hdr.totalsize : \ - DEFAULT_UCODE_TOTALSIZE) =20 -#define get_datasize(mc) \ - (((struct microcode_intel *)mc)->hdr.datasize ? \ - ((struct microcode_intel *)mc)->hdr.datasize : DEFAULT_UCODE_DATA= SIZE) +static uint32_t get_datasize(const struct microcode_patch *patch) +{ + return patch->hdr.datasize ?: PPRO_UCODE_DATASIZE; +} + +static uint32_t get_totalsize(const struct microcode_patch *patch) +{ + return patch->hdr.totalsize ?: PPRO_UCODE_DATASIZE + MC_HEADER_SIZE; +} =20 #define sigmatch(s1, s2, p1, p2) \ (((s1) =3D=3D (s2)) && (((p1) & (p2)) || (((p1) =3D=3D 0) && ((p2)= =3D=3D 0)))) @@ -127,8 +134,8 @@ static int microcode_sanity_check(const struct microcod= e_patch *mc) unsigned int ext_sigcount =3D 0, i; uint32_t sum, orig_sum; =20 - total_size =3D get_totalsize(mc_header); - data_size =3D get_datasize(mc_header); + total_size =3D get_totalsize(mc); + data_size =3D get_datasize(mc); if ( (data_size + MC_HEADER_SIZE) > total_size ) { printk(KERN_ERR "microcode: error! " @@ -220,8 +227,8 @@ static enum microcode_match_result microcode_update_mat= ch( unsigned int sig =3D cpu_sig->sig; unsigned int pf =3D cpu_sig->pf; unsigned int rev =3D cpu_sig->rev; - unsigned long data_size =3D get_datasize(mc_header); - const void *end =3D (const void *)mc_header + get_totalsize(mc_header); + unsigned long data_size =3D get_datasize(mc); + const void *end =3D (const void *)mc_header + get_totalsize(mc); =20 ASSERT(!microcode_sanity_check(mc)); if ( sigmatch(sig, mc_header->sig, pf, mc_header->pf) ) @@ -331,7 +338,7 @@ static struct microcode_patch *cpu_request_microcode(co= nst void *buf, (mc =3D buf)->hdr.hdrver !=3D 1 || /* Unrecognised header ver= sion? */ mc->hdr.ldrver !=3D 1 || /* Unrecognised loader versi= on? */ size < (blob_size =3D /* Insufficient space for pa= tch? */ - get_totalsize(&mc->hdr)) ) + get_totalsize(mc)) ) { error =3D -EINVAL; printk(XENLOG_WARNING "microcode: Bad data in container\n"); @@ -356,7 +363,7 @@ static struct microcode_patch *cpu_request_microcode(co= nst void *buf, =20 if ( saved ) { - patch =3D xmemdup_bytes(saved, get_totalsize(&saved->hdr)); + patch =3D xmemdup_bytes(saved, get_totalsize(saved)); =20 if ( !patch ) error =3D -ENOMEM; --=20 2.11.0 From nobody Sat Apr 27 07:45:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1585312193; cv=none; d=zohomail.com; s=zohoarc; b=PENSAtiHY6IfGXzIKZdt8CubraqubCvCbIELI16bUp55pDWc1uOTiV9KlXR1HKagsqxd72N5RN/bYvss9QHMMSlU5fcXVICd0JwSQrja7MUkv8Vrp2Ub7Fn9X9TEKQ9XNOx1PWChqER1U9QNvSRjLjKCOwvbEBmzTsWm6D+G+qY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585312193; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N6QZ4zPJoeH2Lsi1AsmYkmCqOOYn1jaicoD9V6yR/tk=; b=E6Di4G6CWT/Ym57P4HmyAYiyeOIcmAWKFZEATUncXuHU1lUyTYPQy6U701sFZukwlKy/FqtLBnIp/mt3OnTsC023tJt2W/vNWHjWdcwV1deLCcwsNEihEhax9sRKxl+mn4Zg8D8N1xhimYJXM1d64krL2tQwFU+j5b9ae1QxJZg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585312193167813.833951442088; Fri, 27 Mar 2020 05:29:53 -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 1jHo72-00067W-4T; Fri, 27 Mar 2020 12:29:24 +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 1jHo70-00066f-Dx for xen-devel@lists.xenproject.org; Fri, 27 Mar 2020 12:29:22 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 91045498-7026-11ea-8967-12813bfff9fa; Fri, 27 Mar 2020 12:29:13 +0000 (UTC) X-Inumbo-ID: 91045498-7026-11ea-8967-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1585312153; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aOQlUyj0aHx/bC1hdUa1DyVAALcQFcK4rNJnckPxhno=; b=AxQql6ybB0bcOGdFP/4owGQNUpoE/iuy7/4igOwMfmwhT/iKS47AFcNp Yx+ZF82dT8hQxPX1FyqzscNFn94ELQzjz7OCBKDiWSponnXlzV8MtXg2p pKBV0231ZkMHZbHZv9z6bSD2vkk7e5PABN3z4OKsodCeUE6l9Hu9MsG3p U=; 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@mail.citrix.com Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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=162.221.158.21; 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 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; 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:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: txWd3qG08+z9TMDWOqNjmwOpNBCaT0IVXOHX6HNNim0xuU9KhHIUb62BTJlLnYflWD5n5PAWh8 eCp2sZ/jxASzmfA8FVy1HLSj0niEZXJ/ApP/yamh6x5A2OVD5tmKR+73QR0eYWmZhh8l6SOYVr hQf4En2f3UV3zy6E6O2rD4N4oM+N5DKKS6FGAx+D6afnXL7amzff5nVyoXEEWpg73f9tBDZr4W AOd/SjUArUzkPl9KtSU2UVY1MUln7/rYhbSpcRLMuecca0rdg5Xu+XRqHzJES69kXfGsAsKvTV 61c= X-SBRS: 2.7 X-MesageID: 14735337 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,312,1580792400"; d="scan'208";a="14735337" From: Andrew Cooper To: Xen-devel Date: Fri, 27 Mar 2020 12:28:59 +0000 Message-ID: <20200327122901.11569-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200327122901.11569-1-andrew.cooper3@citrix.com> References: <20200327122901.11569-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH v2 5/7] x86/ucode/intel: Clean up microcode_update_match() 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?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Implement a new get_ext_sigtable() helper to abstract the logic for identifying whether an extended signature table exists. As part of this, rename microcode_intel.bits to data and change its type so it can be useful= ly used in combination with the datasize header field. Also, replace the sigmatch() macro with a static inline with a more useful API, and an explanation of why it is safe to drop one of the previous conditionals. No practical change in behaviour. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * Rebase over struct microcode_patch re-work * Fix maches =3D> matches typo * Retain constness on cast through void * --- xen/arch/x86/cpu/microcode/intel.c | 77 +++++++++++++++++++++++++---------= ---- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index be2f4871dc..9d8d5bfc6e 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -60,7 +60,9 @@ struct microcode_header_intel { =20 struct microcode_patch { struct microcode_header_intel hdr; - unsigned int bits[0]; + + /* Microcode payload. Format is propriety and encrypted. */ + uint8_t data[]; }; =20 /* Temporary, until the microcode_* structure are disentangled. */ @@ -96,8 +98,41 @@ static uint32_t get_totalsize(const struct microcode_pat= ch *patch) return patch->hdr.totalsize ?: PPRO_UCODE_DATASIZE + MC_HEADER_SIZE; } =20 -#define sigmatch(s1, s2, p1, p2) \ - (((s1) =3D=3D (s2)) && (((p1) & (p2)) || (((p1) =3D=3D 0) && ((p2)= =3D=3D 0)))) +/* + * A piece of microcode has an extended signature table if there is space + * between the end of data[] and the total size. (This logic also works + * appropriately for Pentium Pro/II microcode, which has 0 for both size + * fields, and no extended signature table.) + */ +static const struct extended_sigtable *get_ext_sigtable( + const struct microcode_patch *patch) +{ + if ( patch->hdr.totalsize > (MC_HEADER_SIZE + patch->hdr.datasize) ) + return (const void *)&patch->data[patch->hdr.datasize]; + + return NULL; +} + +/* + * A piece of microcode is applicable for a CPU if: + * 1) the signatures (CPUID.1.EAX - Family/Model/Stepping) match, and + * 2) The Platform Flags bitmap intersect. + * + * A CPU will have a single Platform Flag bit, while the microcode may be + * common to multiple platforms and have multiple bits set. + * + * Note: The Pentium Pro/II microcode didn't use platform flags, and should + * treat 0 as a match. However, Xen being 64bit means that the CPU signat= ure + * won't match, allowing us to simplify the logic. + */ +static bool signature_matches(const struct cpu_signature *cpu_sig, + unsigned int ucode_sig, unsigned int ucode_p= f) +{ + if ( cpu_sig->sig !=3D ucode_sig ) + return false; + + return cpu_sig->pf & ucode_pf; +} =20 #define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_S= IZE) =20 @@ -219,36 +254,26 @@ static int microcode_sanity_check(const struct microc= ode_patch *mc) static enum microcode_match_result microcode_update_match( const struct microcode_patch *mc) { - const struct microcode_header_intel *mc_header =3D &mc->hdr; - const struct extended_sigtable *ext_header; - const struct extended_signature *ext_sig; + const struct extended_sigtable *ext; unsigned int i; struct cpu_signature *cpu_sig =3D &this_cpu(cpu_sig); - unsigned int sig =3D cpu_sig->sig; - unsigned int pf =3D cpu_sig->pf; - unsigned int rev =3D cpu_sig->rev; - unsigned long data_size =3D get_datasize(mc); - const void *end =3D (const void *)mc_header + get_totalsize(mc); =20 ASSERT(!microcode_sanity_check(mc)); - if ( sigmatch(sig, mc_header->sig, pf, mc_header->pf) ) - return (mc_header->rev > rev) ? NEW_UCODE : OLD_UCODE; =20 - ext_header =3D (const void *)(mc_header + 1) + data_size; - ext_sig =3D (const void *)(ext_header + 1); + /* Check the main microcode signature. */ + if ( signature_matches(cpu_sig, mc->hdr.sig, mc->hdr.pf) ) + goto found; =20 - /* - * Make sure there is enough space to hold an extended header and enou= gh - * array elements. - */ - if ( end <=3D (const void *)ext_sig ) - return MIS_UCODE; - - for ( i =3D 0; i < ext_header->count; i++ ) - if ( sigmatch(sig, ext_sig[i].sig, pf, ext_sig[i].pf) ) - return (mc_header->rev > rev) ? NEW_UCODE : OLD_UCODE; + /* If there is an extended signature table, check each of them. */ + if ( (ext =3D get_ext_sigtable(mc)) !=3D NULL ) + for ( i =3D 0; i < ext->count; ++i ) + if ( signature_matches(cpu_sig, ext->sigs[i].sig, ext->sigs[i]= .pf) ) + goto found; =20 return MIS_UCODE; + + found: + return mc->hdr.rev > cpu_sig->rev ? NEW_UCODE : OLD_UCODE; } =20 static bool match_cpu(const struct microcode_patch *patch) @@ -296,7 +321,7 @@ static int apply_microcode(const struct microcode_patch= *patch) BUG_ON(local_irq_is_enabled()); =20 /* write microcode via MSR 0x79 */ - wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc_intel->bits); + wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc_intel->data); wrmsrl(MSR_IA32_UCODE_REV, 0x0ULL); =20 /* As documented in the SDM: Do a CPUID 1 here */ --=20 2.11.0 From nobody Sat Apr 27 07:45:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1585312195; cv=none; d=zohomail.com; s=zohoarc; b=lb0p86Cjxuq2uf3kwwTe40qFe7eVPCdqbS2CB3Foj7jBshB4xQiOVwqrhK0BwY/IcBtMhQq6z0dWXhrw4HYhHB8mQN8E117aov1TbxZ5vURb4A+DK+9bebGE+DZf0ucaahFrNv30dBAFdB82Wv8zKi2/TwP8JYKlLcX83XaJUEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585312195; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RdLNoMVNGslfrX7+Bz1nsjs2JQQsuYnFjrZOzROO5BI=; b=lO4yY6z0p2W0RlNKCkdsh1335NdcVzCJLb4HH7j4mAfhjBfwtObV1lS5yoCTlSHivN1l7jq6JBk6/n8lhsd5G8Q8i1ahKAs9LgZm3+P1SEw2lRsLfzCU9KtgtOIP6HFu+ceSMp0MKTQbYBSYtsRP2O3p5ujFZFyCibNsXiCtjUE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585312195434147.52601814017294; Fri, 27 Mar 2020 05:29:55 -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 1jHo74-00069B-Ee; Fri, 27 Mar 2020 12:29:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHo72-00067w-Il for xen-devel@lists.xenproject.org; Fri, 27 Mar 2020 12:29:24 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9422b1ce-7026-11ea-bec1-bc764e2007e4; Fri, 27 Mar 2020 12:29:18 +0000 (UTC) X-Inumbo-ID: 9422b1ce-7026-11ea-bec1-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1585312158; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ooXOEb6013sZBrN5C8AYlh9+wFporvBvVrqbei2wcDA=; b=IK/CkETvgsGpDNEA+JdHHKIz1ClE+dG/WZMxoOSsZqj+ZOBkcak5t+Xr ToOQ5d41d9tHiLdxCmcbWtY3jIumKFdlM2s5pWHqDxb80RJFsWfQYUko4 tEHbJbRP9ndR+Orn/e9yBuoNxbCIcIGE8HtlEkKpW1n6OK2jqnJwXPwye 0=; Authentication-Results: esa4.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@mail.citrix.com Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa4.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:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: toLcN1Mrfc/d0RmtnpsU+UxxSF6LeB4NWpB1EG6NyjDX2ZzqoiP+Ymi0Nqqmn5aFdjpozxyBoo UX/qjoggZliHMnizW3gGhJzQihdP4skzSdH8l4HKkR0zZ+PMoGP1CaATphrqP/lzpADYrS6adp 1e5qtVuSvsj7bmuVdUQegnOaVomELmx/k5bS6iEP/kJPYxn+giJU/0LFFb5QGf1EutJIqQm1iT SJbNfG6jsN3HDIlhTmtmYv/CiQoUNZ43xxvuX0/GGo5K1erDZr3tD0zR0ZL7PwV+5AsW5Zth3E Hhs= X-SBRS: 2.7 X-MesageID: 15405104 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,312,1580792400"; d="scan'208";a="15405104" From: Andrew Cooper To: Xen-devel Date: Fri, 27 Mar 2020 12:29:00 +0000 Message-ID: <20200327122901.11569-7-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200327122901.11569-1-andrew.cooper3@citrix.com> References: <20200327122901.11569-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH v2 6/7] x86/ucode/intel: Clean up microcode_sanity_check() 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?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Rewrite the size checks in a way which doesn't depend on Xen being compiled= as 64bit. Introduce a check missing from the old code, that total_size is a multiple = of 1024 bytes, and drop unnecessary defines/macros/structures. No practical change in behaviour. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * Rebase over struct microcode_patch re-work * Retain constness on cast through void * * Reinstate printk()s for bad data --- xen/arch/x86/cpu/microcode/intel.c | 147 +++++++++++++++++----------------= ---- 1 file changed, 66 insertions(+), 81 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index 9d8d5bfc6e..1358a25032 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -69,24 +69,19 @@ struct microcode_patch { #define microcode_intel microcode_patch =20 /* microcode format is extended from prescott processors */ -struct extended_signature { - unsigned int sig; - unsigned int pf; - unsigned int cksum; -}; - struct extended_sigtable { unsigned int count; unsigned int cksum; unsigned int reserved[3]; - struct extended_signature sigs[0]; + struct { + unsigned int sig; + unsigned int pf; + unsigned int cksum; + } sigs[]; }; =20 #define PPRO_UCODE_DATASIZE 2000 #define MC_HEADER_SIZE (sizeof(struct microcode_header_intel)) -#define EXT_HEADER_SIZE (sizeof(struct extended_sigtable)) -#define EXT_SIGNATURE_SIZE (sizeof(struct extended_signature)) -#define DWSIZE (sizeof(u32)) =20 static uint32_t get_datasize(const struct microcode_patch *patch) { @@ -134,8 +129,6 @@ static bool signature_matches(const struct cpu_signatur= e *cpu_sig, return cpu_sig->pf & ucode_pf; } =20 -#define exttable_size(et) ((et)->count * EXT_SIGNATURE_SIZE + EXT_HEADER_S= IZE) - static int collect_cpu_info(struct cpu_signature *csig) { uint64_t msr_content; @@ -160,93 +153,85 @@ static int collect_cpu_info(struct cpu_signature *csi= g) return 0; } =20 -static int microcode_sanity_check(const struct microcode_patch *mc) +/* + * Sanity check a blob which is expected to be a microcode patch. The 48 = byte + * header is of a known format, and together with totalsize are within the + * bounds of the container. Everything else is unchecked. + */ +static int microcode_sanity_check(const struct microcode_patch *patch) { - const struct microcode_header_intel *mc_header =3D &mc->hdr; - const struct extended_sigtable *ext_header =3D NULL; - const struct extended_signature *ext_sig; - unsigned long total_size, data_size, ext_table_size; - unsigned int ext_sigcount =3D 0, i; - uint32_t sum, orig_sum; - - total_size =3D get_totalsize(mc); - data_size =3D get_datasize(mc); - if ( (data_size + MC_HEADER_SIZE) > total_size ) + const struct extended_sigtable *ext; + const uint32_t *ptr; + unsigned int total_size =3D get_totalsize(patch); + unsigned int data_size =3D get_datasize(patch); + unsigned int i, ext_size; + uint32_t sum; + + /* + * Total size must be a multiple of 1024 bytes. Data size and the hea= der + * must fit within it. + */ + if ( (total_size & 1023) || + data_size > (total_size - MC_HEADER_SIZE) ) { - printk(KERN_ERR "microcode: error! " - "Bad data size in microcode data file\n"); + printk(XENLOG_WARNING "microcode: Bad size\n"); return -EINVAL; } =20 - if ( (mc_header->ldrver !=3D 1) || (mc_header->hdrver !=3D 1) ) - { - printk(KERN_ERR "microcode: error! " - "Unknown microcode update format\n"); + /* Checksum the main header and data. */ + for ( sum =3D 0, ptr =3D (const uint32_t *)patch; + ptr < (const uint32_t *)&patch->data[data_size]; ++ptr ) + sum +=3D *ptr; + + if ( sum !=3D 0 ) return -EINVAL; - } - ext_table_size =3D total_size - (MC_HEADER_SIZE + data_size); - if ( ext_table_size ) + + /* Look to see if there is an extended signature table. */ + ext_size =3D total_size - data_size - MC_HEADER_SIZE; + + /* No extended signature table? All done. */ + if ( ext_size =3D=3D 0 ) { - if ( (ext_table_size < EXT_HEADER_SIZE) || - ((ext_table_size - EXT_HEADER_SIZE) % EXT_SIGNATURE_SIZE) ) - { - printk(KERN_ERR "microcode: error! " - "Small exttable size in microcode data file\n"); - return -EINVAL; - } - ext_header =3D (void *)mc + MC_HEADER_SIZE + data_size; - if ( ext_table_size !=3D exttable_size(ext_header) ) - { - printk(KERN_ERR "microcode: error! " - "Bad exttable size in microcode data file\n"); - return -EFAULT; - } - ext_sigcount =3D ext_header->count; + printk(XENLOG_WARNING "microcode: Bad checksum\n"); + return 0; } =20 - /* check extended table checksum */ - if ( ext_table_size ) + /* + * Check the structure of the extended signature table, ensuring that = it + * fits exactly in the remaining space. + */ + ext =3D (const void *)&patch->data[data_size]; + if ( ext_size < sizeof(*ext) || + (ext_size - sizeof(*ext)) % sizeof(ext->sigs[0]) || + (ext_size - sizeof(*ext)) / sizeof(ext->sigs[0]) !=3D ext->count ) { - uint32_t ext_table_sum =3D 0; - uint32_t *ext_tablep =3D (uint32_t *)ext_header; - - i =3D ext_table_size / DWSIZE; - while ( i-- ) - ext_table_sum +=3D ext_tablep[i]; - if ( ext_table_sum ) - { - printk(KERN_WARNING "microcode: aborting, " - "bad extended signature table checksum\n"); - return -EINVAL; - } + printk(XENLOG_WARNING "microcode: Bad sigtable size\n"); + return -EINVAL; } =20 - /* calculate the checksum */ - orig_sum =3D 0; - i =3D (MC_HEADER_SIZE + data_size) / DWSIZE; - while ( i-- ) - orig_sum +=3D ((uint32_t *)mc)[i]; - if ( orig_sum ) + /* Checksum the whole extended signature table. */ + for ( sum =3D 0, ptr =3D (const uint32_t *)ext; + ptr < (const uint32_t *)&ext->sigs[ext->count]; ++ptr ) + sum +=3D *ptr; + + if ( sum !=3D 0 ) { - printk(KERN_ERR "microcode: aborting, bad checksum\n"); + printk(XENLOG_WARNING "microcode: Bad sigtable checksum\n"); return -EINVAL; } - if ( !ext_table_size ) - return 0; - /* check extended signature checksum */ - for ( i =3D 0; i < ext_sigcount; i++ ) - { - ext_sig =3D (void *)ext_header + EXT_HEADER_SIZE + - EXT_SIGNATURE_SIZE * i; - sum =3D orig_sum - - (mc_header->sig + mc_header->pf + mc_header->cksum) - + (ext_sig->sig + ext_sig->pf + ext_sig->cksum); - if ( sum ) + + /* + * Checksum each indiviudal extended signature as if it had been in the + * main header. + */ + sum =3D patch->hdr.sig + patch->hdr.pf + patch->hdr.cksum; + for ( i =3D 0; i < ext->count; ++i ) + if ( sum !=3D (ext->sigs[i].sig + ext->sigs[i].pf + ext->sigs[i].c= ksum) ) { - printk(KERN_ERR "microcode: aborting, bad checksum\n"); + printk(XENLOG_WARNING "microcode: Bad sigtable checksum\n"); return -EINVAL; } - } + return 0; } =20 --=20 2.11.0 From nobody Sat Apr 27 07:45:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1585312187; cv=none; d=zohomail.com; s=zohoarc; b=BanqnlknN/G7JuRrw/PJVANwfpNKmNA3D4+bc48snhJ2SYIRhHBcW2dfz+cCZimhRlKeFtEijK73IoMbgaUuPo3tllxX7JJhqe3s9XjmkWDSvjrQoMJnzocTBZoQ9YwN9HnHDVgUklPHl3dpB0+EyMiU5/gbrlm49wmT7ufbdgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585312187; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5YLV0gPSNxd1R9biKySUbQc58E4XX7x5D0+xH+um+OI=; b=nY5TDXDj7CZkBu9tC+E9HphVI0OFTK/x2lTa6sGUa39qFe1gRoTHLV1mq8kZg485ho4Lt4+Cp/+mOBU/wlRo6xCJCUsUIiTJR2XpK66KK9H/gljPxNdlWxvxJDAeL3UaFgvek7aBs9GxP/aRbnAiNK0d+N41tOnHWTXCbcnFJQ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1585312187393565.3853185571143; Fri, 27 Mar 2020 05:29:47 -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 1jHo6u-000639-4o; Fri, 27 Mar 2020 12:29:16 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jHo6s-00062j-JA for xen-devel@lists.xenproject.org; Fri, 27 Mar 2020 12:29:14 +0000 Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 90fd4d1a-7026-11ea-92cf-bc764e2007e4; Fri, 27 Mar 2020 12:29:13 +0000 (UTC) X-Inumbo-ID: 90fd4d1a-7026-11ea-92cf-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1585312153; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HEbfsuxHnGsk48zaP0zHWQk3SdDz/jLLzcY8SW06DdQ=; b=QPs+YlxmNyrLf7l5yHApjB+lVvCbo1PB86WC2UJVvU6aIW9dJkb6wDEz dCEc0XF/578Jo8fP5XZa7Czh6F4MEmq+8kPHjWSI1lml5CxPVo7ZD9OQq qErYHhqSCNrpenK9zCwHvn4Umi2tqefQhcM6XHSQIEZ2CRaG9i4Ovjq+C A=; 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@mail.citrix.com Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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=162.221.158.21; 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 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; 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:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: ksXZKSMHLH3qFb9MyR/bMKJ7u5uxjQ0bGOVUD1DyfcQdiZcsHnesytwK6NbkQJOq1npnDnDi+I dYG4KJaB1oMAq9MUzkNjSVu4M1BpZbZck6vwMiHWZg6KLptRYdC3Iek+CvsZ2XQhoGnPI6FWJB TQmxx2kTzfYamZA0dS3A0EGD1I+i3d63w0cTVjsONgTEQS3d8iS4LqBjrJjRAFG0xEcBYMm0JH yI+KEf8vfOAZYaJ2j4Xdc6c1hzVHjlbUE+FPLESp7Rz5/Yw6SMv/Cb2zyhCAQ4vUJc7GA/1dRQ 8YY= X-SBRS: 2.7 X-MesageID: 14735338 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,312,1580792400"; d="scan'208";a="14735338" From: Andrew Cooper To: Xen-devel Date: Fri, 27 Mar 2020 12:29:01 +0000 Message-ID: <20200327122901.11569-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200327122901.11569-1-andrew.cooper3@citrix.com> References: <20200327122901.11569-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Xen-devel] [PATCH v2 7/7] x86/ucode/intel: Fold structures together 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?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) With all the necessary cleanup now in place, fold struct microcode_header_intel into struct microcode_patch and drop the struct microcode_intel temporary ifdef-ary. No functional change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 v2: * Rebase over struct microcode_patch re-work --- xen/arch/x86/cpu/microcode/intel.c | 56 ++++++++++++++--------------------= ---- 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index 1358a25032..9a8ef62e2b 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -32,17 +32,12 @@ =20 #define pr_debug(x...) ((void)0) =20 -struct microcode_header_intel { +struct microcode_patch { unsigned int hdrver; unsigned int rev; - union { - struct { - uint16_t year; - uint8_t day; - uint8_t month; - }; - unsigned int date; - }; + uint16_t year; + uint8_t day; + uint8_t month; unsigned int sig; unsigned int cksum; unsigned int ldrver; @@ -56,18 +51,11 @@ struct microcode_header_intel { unsigned int datasize; unsigned int totalsize; unsigned int reserved[3]; -}; - -struct microcode_patch { - struct microcode_header_intel hdr; =20 /* Microcode payload. Format is propriety and encrypted. */ uint8_t data[]; }; =20 -/* Temporary, until the microcode_* structure are disentangled. */ -#define microcode_intel microcode_patch - /* microcode format is extended from prescott processors */ struct extended_sigtable { unsigned int count; @@ -81,16 +69,16 @@ struct extended_sigtable { }; =20 #define PPRO_UCODE_DATASIZE 2000 -#define MC_HEADER_SIZE (sizeof(struct microcode_header_intel)) +#define MC_HEADER_SIZE offsetof(struct microcode_patch, data) =20 static uint32_t get_datasize(const struct microcode_patch *patch) { - return patch->hdr.datasize ?: PPRO_UCODE_DATASIZE; + return patch->datasize ?: PPRO_UCODE_DATASIZE; } =20 static uint32_t get_totalsize(const struct microcode_patch *patch) { - return patch->hdr.totalsize ?: PPRO_UCODE_DATASIZE + MC_HEADER_SIZE; + return patch->totalsize ?: PPRO_UCODE_DATASIZE + MC_HEADER_SIZE; } =20 /* @@ -102,8 +90,8 @@ static uint32_t get_totalsize(const struct microcode_pat= ch *patch) static const struct extended_sigtable *get_ext_sigtable( const struct microcode_patch *patch) { - if ( patch->hdr.totalsize > (MC_HEADER_SIZE + patch->hdr.datasize) ) - return (const void *)&patch->data[patch->hdr.datasize]; + if ( patch->totalsize > (MC_HEADER_SIZE + patch->datasize) ) + return (const void *)&patch->data[patch->datasize]; =20 return NULL; } @@ -224,7 +212,7 @@ static int microcode_sanity_check(const struct microcod= e_patch *patch) * Checksum each indiviudal extended signature as if it had been in the * main header. */ - sum =3D patch->hdr.sig + patch->hdr.pf + patch->hdr.cksum; + sum =3D patch->sig + patch->pf + patch->cksum; for ( i =3D 0; i < ext->count; ++i ) if ( sum !=3D (ext->sigs[i].sig + ext->sigs[i].pf + ext->sigs[i].c= ksum) ) { @@ -246,7 +234,7 @@ static enum microcode_match_result microcode_update_mat= ch( ASSERT(!microcode_sanity_check(mc)); =20 /* Check the main microcode signature. */ - if ( signature_matches(cpu_sig, mc->hdr.sig, mc->hdr.pf) ) + if ( signature_matches(cpu_sig, mc->sig, mc->pf) ) goto found; =20 /* If there is an extended signature table, check each of them. */ @@ -258,7 +246,7 @@ static enum microcode_match_result microcode_update_mat= ch( return MIS_UCODE; =20 found: - return mc->hdr.rev > cpu_sig->rev ? NEW_UCODE : OLD_UCODE; + return mc->rev > cpu_sig->rev ? NEW_UCODE : OLD_UCODE; } =20 static bool match_cpu(const struct microcode_patch *patch) @@ -284,7 +272,7 @@ static enum microcode_match_result compare_patch( ASSERT(microcode_update_match(old) !=3D MIS_UCODE); ASSERT(microcode_update_match(new) !=3D MIS_UCODE); =20 - return (new->hdr.rev > old->hdr.rev) ? NEW_UCODE : OLD_UCODE; + return new->rev > old->rev ? NEW_UCODE : OLD_UCODE; } =20 static int apply_microcode(const struct microcode_patch *patch) @@ -292,7 +280,6 @@ static int apply_microcode(const struct microcode_patch= *patch) uint64_t msr_content; unsigned int cpu =3D smp_processor_id(); struct cpu_signature *sig =3D &this_cpu(cpu_sig); - const struct microcode_intel *mc_intel; uint32_t rev, old_rev =3D sig->rev; =20 if ( !patch ) @@ -301,12 +288,10 @@ static int apply_microcode(const struct microcode_pat= ch *patch) if ( !match_cpu(patch) ) return -EINVAL; =20 - mc_intel =3D patch; - BUG_ON(local_irq_is_enabled()); =20 /* write microcode via MSR 0x79 */ - wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)mc_intel->data); + wrmsrl(MSR_IA32_UCODE_WRITE, (unsigned long)patch->data); wrmsrl(MSR_IA32_UCODE_REV, 0x0ULL); =20 /* As documented in the SDM: Do a CPUID 1 here */ @@ -316,18 +301,17 @@ static int apply_microcode(const struct microcode_pat= ch *patch) rdmsrl(MSR_IA32_UCODE_REV, msr_content); sig->rev =3D rev =3D msr_content >> 32; =20 - if ( rev !=3D mc_intel->hdr.rev ) + if ( rev !=3D patch->rev ) { printk(XENLOG_ERR "microcode: CPU%u update rev %#x to %#x failed, result %#x\= n", - cpu, old_rev, mc_intel->hdr.rev, rev); + cpu, old_rev, patch->rev, rev); return -EIO; } =20 printk(XENLOG_WARNING "microcode: CPU%u updated from revision %#x to %#x, date =3D %0= 4x-%02x-%02x\n", - cpu, old_rev, rev, mc_intel->hdr.year, - mc_intel->hdr.month, mc_intel->hdr.day); + cpu, old_rev, rev, patch->year, patch->month, patch->day); =20 return 0; } @@ -345,8 +329,8 @@ static struct microcode_patch *cpu_request_microcode(co= nst void *buf, unsigned int blob_size; =20 if ( size < MC_HEADER_SIZE || /* Insufficient space for head= er? */ - (mc =3D buf)->hdr.hdrver !=3D 1 || /* Unrecognised header ver= sion? */ - mc->hdr.ldrver !=3D 1 || /* Unrecognised loader versi= on? */ + (mc =3D buf)->hdrver !=3D 1 || /* Unrecognised header ver= sion? */ + mc->ldrver !=3D 1 || /* Unrecognised loader versi= on? */ size < (blob_size =3D /* Insufficient space for pa= tch? */ get_totalsize(mc)) ) { @@ -364,7 +348,7 @@ static struct microcode_patch *cpu_request_microcode(co= nst void *buf, * one with higher revision. */ if ( (microcode_update_match(mc) !=3D MIS_UCODE) && - (!saved || (mc->hdr.rev > saved->hdr.rev)) ) + (!saved || (mc->rev > saved->rev)) ) saved =3D mc; =20 buf +=3D blob_size; --=20 2.11.0