From nobody Thu Mar 28 13:45:29 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=1584958695; cv=none; d=zohomail.com; s=zohoarc; b=GuY2q/weqcD5gMfS8bM8pikx33jeYXhTuI8uJbX3HZlw5UoGe0I+0He+gp7i2QGSWohpqrkydV1ria8JtQO9CI6G+tuwldQHdIxIuManWFMdHJKLsL/GNakS5teUVTfFvXhG/kxfxyqAI4FntjvkYlOShDr0ZdQXiKLsaoVNOiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584958695; 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=Q5Enh2Ia+Sp1rXx1oSZvt8xgzet1s43NtVL4hSC0vuc=; b=GXsgfYb1CTTm+77pS5LRHDG/m+U0J5J53zLEqK/GkrGNojyhy/mnaAwcUeRkxmDNcUnAw2BSpLEddDWr1Y0LfuLMkjt+thRzqrG/zVIxz4EirKiObxUBjJVll2jQOmWtSHlZ8hLdPXeEh6UZviSJHu+lDKPH/YNvLLtmUEXQk8M= 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 1584958695874790.0193949953386; Mon, 23 Mar 2020 03:18:15 -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 1jGK9L-0007Vk-Ar; Mon, 23 Mar 2020 10:17:39 +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 1jGK9J-0007VF-Gv for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 10:17:37 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 816027e1-6cef-11ea-829d-12813bfff9fa; Mon, 23 Mar 2020 10:17:32 +0000 (UTC) X-Inumbo-ID: 816027e1-6cef-11ea-829d-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584958652; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6EHUmISE0rB4Cji1BaxN5Ahahi+xG3W8SbhZePFiOBA=; b=fZk3aMQgJsMp8fHHaZcWBD2qVtIlWmZN7K7db5cyH7uFTAlH7dVMEfO3 3QTCd0fHeXjJIwBRhP37+ZYALnMlv3uB/AvjdQga7v7rnxEYzQFA5V6Q7 B0QYoIJyndC+E/8+eTQ0BDC0ruPcOdk7bebZm1iD0FNzA8tSjdTzT6U7u U=; Authentication-Results: esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.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=esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: erf+zgqO8iNIhBxXT49sTVGEdckxSl7VDMfVDjGRbbWl7caz4FuDWOfTutBt7Z+LSacQSvAesx ygUBqTy3gbVLvr5ZfcmMRp7TNvnVuN/ut3V4p82Hu2AmtPyz7OCqBusTlkAJn7XjoytHFZtyAs lR1qlO8k72xYwaQrboL7+t2jQxM13uWfUOmLhQqUVuN6GoA74nR9KTkhenpYnAsWTZPr0vswoP YwAFfz/jmunmw6LocQlFC+N9J2Of0uNIWmHh6jalAgUP1qA8xwpY076lh4JoxKQK+CwlPzCBoj nTY= X-SBRS: 2.7 X-MesageID: 14866919 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.72,296,1580792400"; d="scan'208";a="14866919" From: Andrew Cooper To: Xen-devel Date: Mon, 23 Mar 2020 10:17:18 +0000 Message-ID: <20200323101724.15655-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200323101724.15655-1-andrew.cooper3@citrix.com> References: <20200323101724.15655-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/7] x86/ucode: Document the behaviour of the microcode_ops hooks 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" X-ZohoMail-DKIM: fail (Header signature does not verify) ... and struct cpu_signature for good measure. No comment is passed on the suitability of the behaviour... Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/cpu/microcode/private.h | 46 ++++++++++++++++++++++++++++++++= ++++ xen/include/asm-x86/microcode.h | 5 ++++ 2 files changed, 51 insertions(+) diff --git a/xen/arch/x86/cpu/microcode/private.h b/xen/arch/x86/cpu/microc= ode/private.h index e64168a502..a2aec53047 100644 --- a/xen/arch/x86/cpu/microcode/private.h +++ b/xen/arch/x86/cpu/microcode/private.h @@ -14,14 +14,60 @@ enum microcode_match_result { struct microcode_patch; /* Opaque */ =20 struct microcode_ops { + /* + * Parse a microcode container. Format is vendor-specific. + * + * Search within the container for the patch, suitable for the current + * CPU, which has the highest revision. (Note: May be a patch which is + * older that what is running in the CPU. This is a feature, to better + * cope with corner cases from buggy firmware.) + * + * If one is found, allocate and return a struct microcode_patch + * encapsulating the appropriate microcode patch. Does not alias the + * original buffer. + * + * If one is not found, (nothing matches the current CPU), return NULL. + * Also may return ERR_PTR(-err), e.g. bad container, out of memory. + */ struct microcode_patch *(*cpu_request_microcode)(const void *buf, size_t size); + + /* Obtain microcode-relevant details for the current CPU. */ int (*collect_cpu_info)(struct cpu_signature *csig); + + /* + * Attempt to load the provided patch into the CPU. Returns -EIO if + * anything didn't go as expected. + */ int (*apply_microcode)(const struct microcode_patch *patch); + + /* + * Optional. If provided and applicable to the specific update attemp= t, + * is run once by the initiating CPU. Returning an error will abort t= he + * load attempt. + */ int (*start_update)(void); + + /* + * Optional. If provided, called on every CPU which completes a micro= code + * load. May be called in the case of some errors, and not others. M= ay + * be called even if start_update() wasn't. + */ void (*end_update_percpu)(void); + + /* Free a patch previously allocated by cpu_request_microcode(). */ void (*free_patch)(struct microcode_patch *patch); + + /* + * Is the microcode patch applicable for the current CPU, and newer th= an + * the currently running patch? + */ bool (*match_cpu)(const struct microcode_patch *patch); + + /* + * Given two patches, are they both applicable to the current CPU, and= is + * new a higher revision than old? + */ enum microcode_match_result (*compare_patch)( const struct microcode_patch *new, const struct microcode_patch *o= ld); }; diff --git a/xen/include/asm-x86/microcode.h b/xen/include/asm-x86/microcod= e.h index 89b9aaa02d..41e85a24d2 100644 --- a/xen/include/asm-x86/microcode.h +++ b/xen/include/asm-x86/microcode.h @@ -7,8 +7,13 @@ #include =20 struct cpu_signature { + /* CPU signature (CPUID.1.EAX). Only written on Intel. */ unsigned int sig; + + /* Platform Flags (only actually 1 bit). Only applicable to Intel. */ unsigned int pf; + + /* Microcode Revision. */ unsigned int rev; }; =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Mar 28 13:45:29 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=1584958702; cv=none; d=zohomail.com; s=zohoarc; b=hXgOQI/PgAaLAbG0qoMVV9GAjVGiADHEmjkmJe34a4WCjEBBmURfByTk3gGsz+hg/Opdfj4ZleTpgbH/b78GbbXZDV70l0uIjrQSsSPmeIRE7s5IZhX61+4iqTVPTbqJS+CJCXrJKP6vSDIuh0GfLmVKlz7kkTPOxsld8ugMA2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584958702; 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=zpHuQPz9Zpcb7552lvCgTALHYE7WpJA3lo7DqsTrg88=; b=N/T2g7jpM7gjohIbtLbd/F42XkVk8J+KBbv42/pf4Tt7vSlr7EVot1iTVtM0dJXzacje4eji92rPOS0l1982SpkVzOgnFB+U0Htcdgssh0ZKNlvTcWS5CZ/ehUngykAyQvF5YX51i7RpzwKWBLhs2mjnLl5CJQnB128S+dDao0w= 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 1584958702305360.8521292265382; Mon, 23 Mar 2020 03:18:22 -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 1jGK9S-0007Z1-Tq; Mon, 23 Mar 2020 10:17:46 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jGK9S-0007Ym-CV for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 10:17:46 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 855c6ce6-6cef-11ea-a6c1-bc764e2007e4; Mon, 23 Mar 2020 10:17:38 +0000 (UTC) X-Inumbo-ID: 855c6ce6-6cef-11ea-a6c1-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584958658; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DhcDOqjAEEu8+UEOwRSVuIVRyg3CjwPAxqeTQgZP7/U=; b=Dew8tMPsWXcSdsymQhlFlnlXW9RaSNf9F+fXiWXN9A1e6a+FRjf6rvoy NHpZ9wf9phQRSUQADX8JuVJ3fbxOQF9Ea0G5SgiPRVjkYfchd++TDjBOT Bn84lsnAOuHTS9bGPyR7KOo5dLGcWH9OJEmNR5inkyttEPzGGXaxtt+/D k=; 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: HW6sIBdcxZYmlcXwI557dXTUPzvU5cIlXgQugV2OxqjoXqd6pH6+nyqvdkPH7mIztXSFfzDCns dF3TJB9w7xfxE4ak5eqlTIS5Uhf5I+rRNdvJUf0oS0Ex36B+1kWG3eVKYkKL9lrvdePbc5Snz0 odsdl9QlG1qAQdT81dveayUl4kxO7gq23486mfmEUcRYEOiveGhsj4nqM/Owm7SlzDRdBec+nz aDDs1AESKw5vl5XWHLGXG0Bbv+tesgBwcAKoCFZYvVPCzGih5EPRi050HAvrGuaiN/jW51gKea GYE= X-SBRS: 2.7 X-MesageID: 15099733 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,296,1580792400"; d="scan'208";a="15099733" From: Andrew Cooper To: Xen-devel Date: Mon, 23 Mar 2020 10:17:19 +0000 Message-ID: <20200323101724.15655-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200323101724.15655-1-andrew.cooper3@citrix.com> References: <20200323101724.15655-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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 , 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" X-ZohoMail-DKIM: fail (Header signature does not verify) microcode_sanity_check()'s callers actually call it with a mixture of microcode_intel and microcode_header_intel pointers, which is fragile. Rework it to take struct microcode_intel *, 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: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- 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 f26511da98..f0beefe1bb 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -119,9 +119,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_intel *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; @@ -153,7 +153,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! " @@ -211,8 +211,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_intel *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; @@ -223,7 +224,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 @@ -249,7 +250,7 @@ static bool match_cpu(const struct microcode_patch *pat= ch) if ( !patch ) return false; =20 - return microcode_update_match(&patch->mc_intel->hdr) =3D=3D NEW_UCODE; + return microcode_update_match(patch->mc_intel) =3D=3D NEW_UCODE; } =20 static void free_patch(struct microcode_patch *patch) @@ -268,8 +269,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->mc_intel->hdr) !=3D MIS_UCODE); - ASSERT(microcode_update_match(&new->mc_intel->hdr) !=3D MIS_UCODE); + ASSERT(microcode_update_match(old->mc_intel) !=3D MIS_UCODE); + ASSERT(microcode_update_match(new->mc_intel) !=3D MIS_UCODE); =20 return (new->mc_intel->hdr.rev > old->mc_intel->hdr.rev) ? NEW_UCODE : OLD_UCODE; @@ -367,7 +368,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 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Mar 28 13:45:29 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=1584958719; cv=none; d=zohomail.com; s=zohoarc; b=dRgvY7cIl+neFi9TXe3pjkJOh0m1kMhulMYn+sLM1c6G5Rkzuwr26Jw3Y51T20N6wpS0CQNeZBC+1N6rKp9znIHI26UqKTJM2vOpgLk33PwkBrE1d1GV2CvLolppDJDLaB/6bWen7twOwtGOq3ysksDNn94qhBz/TVRpQ7eY6Qw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584958719; 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=D9tEUwM/Nq5y3/s4cfg9rxfaX72DzueAdr5vgEij/AI=; b=H8iD8e61VOeVS6eTzPX3ojfyJaizUmodGL0Y+sM9jC4blDBiPEMW1VKjBQCY3OIZ6O7B0wVYHvpP5ca4EnHYQVlDGPiY4pmdl1QkrxGMdWQ4Vl3aQhdpVmXAPvK7gGu6Y2ZhGKpiJwbNtWyx6l4w6fFJzqAXCNFyPXs3GYhtX4c= 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 1584958719670318.2624768848905; Mon, 23 Mar 2020 03:18:39 -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 1jGK9l-0007jo-01; Mon, 23 Mar 2020 10:18:04 +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 1jGK9k-0007jO-Iq for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 10:18:04 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 917515f1-6cef-11ea-829d-12813bfff9fa; Mon, 23 Mar 2020 10:17:59 +0000 (UTC) X-Inumbo-ID: 917515f1-6cef-11ea-829d-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584958679; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1FBUYOW6q9VnSkHwIeoLxYMh8A8QDKI33buuWHabfZM=; b=IJiJap0Ve1y56T4GJGagotI2aN+VZ2zzEW6fu3ebhh+3XmRO31ZT631A TdyHN0dbzq/U2kL96/8MzzSXpWl3sU+29vAbQjBAt0SvzQsXwh7EI2Bz+ OCORcHwdbb4WYo3PM5nArSCraAaNY9/rB8RKF+kP+0c5Q2zcDwR2/Mg0p M=; 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: cUSIDkbqAAfaLr/3qkFqxABdgttBjhonvt4Q/eur4ZmaJ17lCgvRYRZl8YaNsGOQYTkGkSkqJY IM/+IBS3GDo8inCtGj2p1D5YRAjYIgM/lveWBZ2loM5ldjEr6r6V02mFdbMgCmGeO4DAgg98ok L8rpaIiYnveh8C0aWJDPU8MK/uGAF0bQZiR39Pe7pUZbt1KJ2Y1Gu50zU7hzcn/EBVZejOugVy BqihKEIoAdsY5UBUaVgqAc5s8LRsdNzA72QE+q0tXHz9NzY3gxbRWUqe/A0lsOiZ/a7nIH/w+c vUM= X-SBRS: 2.7 X-MesageID: 14788291 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,296,1580792400"; d="scan'208";a="14788291" From: Andrew Cooper To: Xen-devel Date: Mon, 23 Mar 2020 10:17:20 +0000 Message-ID: <20200323101724.15655-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200323101724.15655-1-andrew.cooper3@citrix.com> References: <20200323101724.15655-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/cpu/microcode/intel.c | 69 ++++++++++++++--------------------= ---- 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index f0beefe1bb..0cceac6255 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -321,75 +321,58 @@ 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_intel *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_intel *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; 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 xmalloc(struct microcode_patch); if ( patch ) - patch->mc_intel =3D saved; - else { - xfree(saved); - error =3D -ENOMEM; + patch->mc_intel =3D xmemdup_bytes(saved, get_totalsize(&saved-= >hdr)); + if ( !patch->mc_intel ) + { + XFREE(patch); + error =3D -ENOMEM; + } } + else + error =3D -ENOMEM; } =20 if ( error && !patch ) --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Mar 28 13:45:29 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=1584958694; cv=none; d=zohomail.com; s=zohoarc; b=W0DF2V0Hsq1jwtCPF/6pYUyJAOWRrz5k/HmU0Wi7KnjEKHDJgRy9zrXVUe+MU6RGx5NuOwdnDgNPVr8aqAJgSUnUv2IxWvzrlRuE97XT0RJdL8G26ju7EcWc2S6X6iRY3ghQJIiXQHI9wlbeBcAHUhzD9r8q2gj+t/Aoj8q3W3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584958694; 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=bpkSWgizAz/LO+dRgWPhUlKnMhipvBlYQcvuNlifNx4=; b=gBjG3xzlWdc6PlrUktxVYbCYEYpyhHVm66tS77mgEYpJ0JxI0+2MVqx/nmoHHLZdULRfq+X7Km7N5uHTyVRPoQzroi6aeKKymVeqy70TdafSeqMSS0qN/bQVOl4eLJXZiinTXBptixVh4NDRDKWbVXPRq2pTOiwvFgnKWWqa4iU= 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 1584958694330173.55332590359524; Mon, 23 Mar 2020 03:18:14 -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 1jGK9K-0007VP-1V; Mon, 23 Mar 2020 10:17:38 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jGK9I-0007V9-E6 for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 10:17:36 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 83b2b51c-6cef-11ea-bec1-bc764e2007e4; Mon, 23 Mar 2020 10:17:35 +0000 (UTC) X-Inumbo-ID: 83b2b51c-6cef-11ea-bec1-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584958655; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NsMWDE7OwbNOm1ai+erLnQ/LhuB+0yZ90hzjAPNiNqA=; b=EnwnUPiFeASMTqH7qvDa6bDCr5LmFjNaEkmI01KPIJ13k3af+JVkHFOy cUAf+7B4SB8zO/yU0vaILUwGAEllYKix3yi2tjcHnRYxH9BveNZkT+vJH O9hGbCuZXVLHQoggiDJCSfCbATWm7hUJKg1jmgxou3gwbA8sJKDjwGot9 s=; 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: KNXa4Ac0u2amlyDvJh5MU16AJngNhYxgCGTCRhhRoN+tEIEtoLInY74p91IzAaCFTsvPWmjy3O miOT/WpeAqDNyOzDSAf/bi86P81vx11vf/l/Wrx2PsYan1mrZ2/vmF7te8EH0BxRH5qsRMcvts 1VGNo2Ds9UQigxPnadeE3RcSPD0uR5/tsIp932VWYth3IyYdaxYd8G1bciEr1LBdPbLO8H+TRZ NnCWGqHZCZsjRBa0VO6mgegwIdbdQRsTGiAn/YJnejCyqsESFn4ZSDNdv5KUe2dk/q/zmkQv73 Qac= X-SBRS: 2.7 X-MesageID: 15099728 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,296,1580792400"; d="scan'208";a="15099728" From: Andrew Cooper To: Xen-devel Date: Mon, 23 Mar 2020 10:17:21 +0000 Message-ID: <20200323101724.15655-5-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200323101724.15655-1-andrew.cooper3@citrix.com> References: <20200323101724.15655-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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. 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 --- xen/arch/x86/cpu/microcode/intel.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index 0cceac6255..dfe44679be 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -46,9 +46,16 @@ 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; + unsigned int _datasize; + unsigned int _totalsize; unsigned int reserved[3]; }; =20 @@ -75,20 +82,21 @@ struct microcode_patch { struct microcode_intel *mc_intel; }; =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) - -#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_header_intel *hdr) +{ + return hdr->_datasize ?: PPRO_UCODE_DATASIZE; +} + +static uint32_t get_totalsize(const struct microcode_header_intel *hdr) +{ + return 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)))) --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Mar 28 13:45:29 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=1584958710; cv=none; d=zohomail.com; s=zohoarc; b=itSLsV0sd8hwIvO1+TYlSezv5ST1ZEbIxkIJUmzFJhVGE2SM/YeEXv3OUph7qy9oyvsJbloCMkThO6yBIo3WcwQLBKgGzleU+huanVHxSPMvCudvlGQWeZ/NUiKpQsRQZt+mc2Tbp306iCOdRH+neuuBq6NK8xl51DbdCB6WlNk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584958710; 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=/dhXUETatQhMvGr2zJyIROMBFprZA6kK6sI8EIWJeHo=; b=Ts/0Hq0iyXpolIAsOiIEUZdH04HjVP6g1FxSAG/GmBcTXE3D/N+ZfHcHfnC7bqOIZzbstqdrlq09VP5eNDtAeSqBMQvV/gKzq6Aag1VUIRWYGFtxgPbo86mipjnoCWCllxHP2p3I/7l+FSEJZbfGukepaqFEIJPoVoOoHPetnq4= 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 1584958710679147.86956643485212; Mon, 23 Mar 2020 03:18:30 -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 1jGK9Y-0007bj-Cb; Mon, 23 Mar 2020 10:17:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jGK9X-0007bM-Ck for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 10:17:51 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8734dcb0-6cef-11ea-bec1-bc764e2007e4; Mon, 23 Mar 2020 10:17:41 +0000 (UTC) X-Inumbo-ID: 8734dcb0-6cef-11ea-bec1-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584958661; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YuwDMutCdhXNnj6m3wY7ONDkRuL1FQr6n5Vuwb42REI=; b=JTve5bus+HdOGgmWQ+te7ll5hLlq+Jmdl8DjJWpqY5TMsV1CTEBIGdVs utQZetnvximtbZ5JS6YDxrEI7tIp/VDVmX+KoIMrMbkMKjldt/kbeBufz sp5M1u35IPFOsrUk2yALOi8BykANgmdI9QoMqkywT1/LEfXg1q9AEDXRn c=; 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: LdN1PqWwHepdNHdWfPMrGcPm7lz8T7vhmmOi8EQkQWVazvDah3hEtGu6V4Ns8oqUCYsBn3IY/9 hoaWOvoGhCe8hOzNyewjzDBUMBBXbyz+1CAwljLO3eeEohzB156EUq9VF+jbdkfM04sBpxsXb0 IV7ESCBEut4+yBAiKVAcxOTOPRj7dtAuKXRkD+ivzDWhGjDQ6EUQSA7Osxppq94MRhgPP+sFzn pAZ82cbhGuZcfTOn6oY9dxEJ4sK0E+6r4Pl23SldjqEYw+9qu15/WhRUUlIxTbv15j4QAwOeaf Go4= X-SBRS: 2.7 X-MesageID: 15099737 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,296,1580792400"; d="scan'208";a="15099737" From: Andrew Cooper To: Xen-devel Date: Mon, 23 Mar 2020 10:17:22 +0000 Message-ID: <20200323101724.15655-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200323101724.15655-1-andrew.cooper3@citrix.com> References: <20200323101724.15655-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 --- xen/arch/x86/cpu/microcode/intel.c | 75 +++++++++++++++++++++++++---------= ---- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index dfe44679be..bc3bbf139e 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -61,7 +61,7 @@ struct microcode_header_intel { =20 struct microcode_intel { struct microcode_header_intel hdr; - unsigned int bits[0]; + uint8_t data[]; }; =20 /* microcode format is extended from prescott processors */ @@ -98,8 +98,41 @@ static uint32_t get_totalsize(const struct microcode_hea= der_intel *hdr) return 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_intel *mc) +{ + if ( mc->hdr._totalsize > (MC_HEADER_SIZE + mc->hdr._datasize) ) + return (void *)&mc->data[mc->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_maches(const struct cpu_signature *cpu_sig, + unsigned int ucode_sig, unsigned int ucode_pf) +{ + 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 @@ -221,36 +254,26 @@ static int microcode_sanity_check(const struct microc= ode_intel *mc) static enum microcode_match_result microcode_update_match( const struct microcode_intel *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_header); - const void *end =3D (const void *)mc_header + get_totalsize(mc_header); =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_maches(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_maches(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) @@ -303,7 +326,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 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Mar 28 13:45:29 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=1584958720; cv=none; d=zohomail.com; s=zohoarc; b=f31GAIZeaTR4Hk59MKnm04SCozqvUSZLQJK6cZO5TJHyweB1321ThCmrgFcpMiW0A6zZJB1pIwdUsrYT5DtY0NQ0uZJVrSKdP2aY3041Mk3wGec8ETk2poySdMsT+EzblShr9w+13f8GD8M9/pEtpP6vhuNJguaTuZ/EnsnGvTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584958720; 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=3UoBcQbaTp4Y7vKxbT7YsTcPhsq96rL9fS6hOFHHVpc=; b=kbrEcPXXHoOoJXp5fGPg1YbyIsfXBHNsc+W5RvM1XGB7qs0s64pyo18ldzCc98N/TNzl7nZ6PDq9z5jNADO0pK6H2jv23IRf5v6WaNUjMt5IOfWqX/eTChVOufkUAzOZue8T4CEG/33BLptdVvwpByHX/epHnMdIhCEDpvbP+F0= 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 1584958720258349.09422891604515; Mon, 23 Mar 2020 03:18:40 -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 1jGK9h-0007hC-La; Mon, 23 Mar 2020 10:18:01 +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 1jGK9f-0007g5-Ip for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 10:17:59 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 917515f0-6cef-11ea-829d-12813bfff9fa; Mon, 23 Mar 2020 10:17:58 +0000 (UTC) X-Inumbo-ID: 917515f0-6cef-11ea-829d-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584958678; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Sxrnn/HeXrku8q3Uxl6x5vwRPlCId0vHiJDnUachLKs=; b=AI1fMvmyXgJJ+EhVY+VxJvuu5UHWNDCAXyjjJvZk8tbt+nwWN8XNu73J jQieYs1mA9PwTOTCyzOcRxhSUn/f1GpT/bKkANCcttAgAyKEG3zzLeosl NN/daXGth3qYMf5BJdwhp2DF7Y51tO/+HAWRsgbfVptOxMq6G4/zHHM1E w=; 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: O9D3cZ3CyTubtCl/3yyBugdPbrryv9m1z6uZ8fS/Lx/iIuT4VMtjXrH6iJ+4chpiPS0ItyzPtt LZP5mChQCXrxB1daYh7jdA1C9bqBS6ZPbqANirvj+jcPhjHEejEgCGzwFdJvjjjVd/++dn1q/d Z51rcD+0YpclDytECYrZ+WM2stze2S2vOpBKcXUu/SN4DddDDJaWrN+SUB8FQYbdQ8RgOxU/QW tJoSk2bf7P09ucttqBfe0T9qmrI+Tu6MQpWhO6mScbHDcVCeC+QpbTBIr76PhA3jXfyUBKoqjP mWc= X-SBRS: 2.7 X-MesageID: 14788287 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,296,1580792400"; d="scan'208";a="14788287" From: Andrew Cooper To: Xen-devel Date: Mon, 23 Mar 2020 10:17:23 +0000 Message-ID: <20200323101724.15655-7-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200323101724.15655-1-andrew.cooper3@citrix.com> References: <20200323101724.15655-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 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 unnecessarily defines/macros/structures. No practical change in behaviour. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/cpu/microcode/intel.c | 147 +++++++++++++++------------------= ---- 1 file changed, 58 insertions(+), 89 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index bc3bbf139e..2cccf9c26d 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -65,17 +65,15 @@ struct microcode_intel { }; =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 struct microcode_patch { @@ -84,9 +82,6 @@ struct microcode_patch { =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_header_intel *hdr) { @@ -134,8 +129,6 @@ static bool signature_maches(const struct cpu_signature= *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,69 @@ static int collect_cpu_info(struct cpu_signature *csi= g) return 0; } =20 +/* + * 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_intel *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; - unsigned int ext_sigcount =3D 0, i; - uint32_t sum, orig_sum; - - total_size =3D get_totalsize(mc_header); - data_size =3D get_datasize(mc_header); - if ( (data_size + MC_HEADER_SIZE) > total_size ) - { - printk(KERN_ERR "microcode: error! " - "Bad data size in microcode data file\n"); + const struct extended_sigtable *ext; + unsigned int total_size =3D get_totalsize(&mc->hdr); + unsigned int data_size =3D get_datasize(&mc->hdr); + unsigned int i, ext_size; + uint32_t sum, *ptr; + + /* + * 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) ) 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 (uint32_t *)mc; + ptr < (uint32_t *)&mc->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 ) - { - 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; - } =20 - /* check extended table checksum */ - if ( ext_table_size ) - { - uint32_t ext_table_sum =3D 0; - uint32_t *ext_tablep =3D (uint32_t *)ext_header; + /* Look to see if there is an extended signature table. */ + ext_size =3D total_size - data_size - MC_HEADER_SIZE; =20 - 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; - } - } + /* No extended signature table? All done. */ + if ( ext_size =3D=3D 0 ) + return 0; =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 ) - { - printk(KERN_ERR "microcode: aborting, bad checksum\n"); + /* + * Check the structure of the extended signature table, ensuring that = it + * fits exactly in the remaining space. + */ + ext =3D (void *)&mc->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 ) 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 ) - { - printk(KERN_ERR "microcode: aborting, bad checksum\n"); + + /* Checksum the whole extended signature table. */ + for ( sum =3D 0, ptr =3D (uint32_t *)ext; + ptr < (uint32_t *)&ext->sigs[ext->count]; ++ptr ) + sum +=3D *ptr; + + if ( sum !=3D 0 ) + return -EINVAL; + + /* + * Checksum each indiviudal extended signature as if it had been in the + * main header. + */ + sum =3D mc->hdr.sig + mc->hdr.pf + mc->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) ) return -EINVAL; - } - } + return 0; } =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Mar 28 13:45:29 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=1584958703; cv=none; d=zohomail.com; s=zohoarc; b=CxTu/yBARayU57zWeA3Y+HZ7DN6SPgcDJloJqoTPwbFAENN3kFOHWVdz9Zypm5Q/z1h0YWiEcA6riKbDMM+NW6cvkIMd3tn7ocTqqqC3/z/GsA4BvGzEPrTkZMDRhMwQq8KSIYnvDYrHul2XaAl52UPI8m6cKPULwa+KXV3CZks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584958703; 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=sO4yXISJyA7ZmhEOCMm7goFdmorYJOPrsFGT1hyJTQk=; b=KNQXmG0Q5h9kUXLrjhmTTNMxdjz6XzvMISTVec2acKCpicjLzrVK2xI0OCZJlgmhOjOtUK0YC3DL3n/Ui2QHP+OyzE5pF9TqKSapRi+5BW4b9V5Q1Q0jnqGQU80oaUDIFNYxRnqAMEoFy1ofc447FDOfpuGlFdmYkFCPcXIHSL0= 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 1584958703313932.9136781649474; Mon, 23 Mar 2020 03:18:23 -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 1jGK9O-0007XJ-K0; Mon, 23 Mar 2020 10:17:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jGK9N-0007Ws-Cu for xen-devel@lists.xenproject.org; Mon, 23 Mar 2020 10:17:41 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 851d5bf0-6cef-11ea-bec1-bc764e2007e4; Mon, 23 Mar 2020 10:17:37 +0000 (UTC) X-Inumbo-ID: 851d5bf0-6cef-11ea-bec1-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584958657; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oY1vI/otJqmLyA7rCioLLDt00ejjHRZ/yqa6F3MCnfI=; b=MRHRvNGF6mkmgsQMuFbvGBb13vJgppMdp3mumG48Of5U3YvChL3bxU0l 9j7rqMTxf8u6/Dzy2JhS7YXYsyxzPpF3/6rB7f/96ijxtYZvbu0o++1TY cR/TY0Dk30eDMrVYCQTcR0Wu2tzx5vm/abfXX2uUpU+NhoYWJoZV1usl+ 8=; 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: T8aB5NzSWaUhgRXZotbC0J50HLLtbzCLOTtBisY27fKZRyy/vTO/Clc+mAstvNNw77gaHbLTvN DJ8BroynwEa0Ghfkorm9ko2BzPmbYc3Dgx5e/waYXaXLNF+KAPFrqTquoux4UKUiWy+HfWJjsE rhNDXbnsbAcpDU+uH4BRFvnGYz3Y+Ymu5XnCs2ZNjoSvVuMIhs6PmqfzcmneHtVJlekapGRhDq I5wAbwqNu7NqgTrHNYyVaJ0ubSxCsA1a/r729RwPPTxaG2SjDoxSLmOVai5kAeP6NeKyY+W69B WUQ= X-SBRS: 2.7 X-MesageID: 15099729 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,296,1580792400"; d="scan'208";a="15099729" From: Andrew Cooper To: Xen-devel Date: Mon, 23 Mar 2020 10:17:24 +0000 Message-ID: <20200323101724.15655-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200323101724.15655-1-andrew.cooper3@citrix.com> References: <20200323101724.15655-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 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?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Currently, we allocate an 8 byte struct microcode_patch to point at a separately allocated struct microcode_intel. This is wasteful. Fold struct microcode_header_intel and microcode_intel into microcode_patch= to simplify the code and remove a level of indirection. The two semantic changes are in free_patch() and cpu_request_microcode() wh= ich deal with the memory allocation aspects. Everything else is no functional change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 --- xen/arch/x86/cpu/microcode/intel.c | 103 +++++++++++++--------------------= ---- 1 file changed, 37 insertions(+), 66 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcod= e/intel.c index 2cccf9c26d..8f4ebbd759 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; @@ -57,10 +52,7 @@ struct microcode_header_intel { unsigned int _datasize; unsigned int _totalsize; unsigned int reserved[3]; -}; =20 -struct microcode_intel { - struct microcode_header_intel hdr; uint8_t data[]; }; =20 @@ -76,21 +68,17 @@ struct extended_sigtable { } sigs[]; }; =20 -struct microcode_patch { - struct microcode_intel *mc_intel; -}; - #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_header_intel *hdr) +static uint32_t get_datasize(const struct microcode_patch *mc) { - return hdr->_datasize ?: PPRO_UCODE_DATASIZE; + return mc->_datasize ?: PPRO_UCODE_DATASIZE; } =20 -static uint32_t get_totalsize(const struct microcode_header_intel *hdr) +static uint32_t get_totalsize(const struct microcode_patch *mc) { - return hdr->_totalsize ?: PPRO_UCODE_DATASIZE + MC_HEADER_SIZE; + return mc->_totalsize ?: PPRO_UCODE_DATASIZE + MC_HEADER_SIZE; } =20 /* @@ -100,10 +88,10 @@ static uint32_t get_totalsize(const struct microcode_h= eader_intel *hdr) * fields, and no extended signature table.) */ static const struct extended_sigtable *get_ext_sigtable( - const struct microcode_intel *mc) + const struct microcode_patch *mc) { - if ( mc->hdr._totalsize > (MC_HEADER_SIZE + mc->hdr._datasize) ) - return (void *)&mc->data[mc->hdr._datasize]; + if ( mc->_totalsize > (MC_HEADER_SIZE + mc->_datasize) ) + return (void *)&mc->data[mc->_datasize]; =20 return NULL; } @@ -158,11 +146,11 @@ static int collect_cpu_info(struct cpu_signature *csi= g) * 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_intel *mc) +static int microcode_sanity_check(const struct microcode_patch *mc) { const struct extended_sigtable *ext; - unsigned int total_size =3D get_totalsize(&mc->hdr); - unsigned int data_size =3D get_datasize(&mc->hdr); + unsigned int total_size =3D get_totalsize(mc); + unsigned int data_size =3D get_datasize(mc); unsigned int i, ext_size; uint32_t sum, *ptr; =20 @@ -211,7 +199,7 @@ static int microcode_sanity_check(const struct microcod= e_intel *mc) * Checksum each indiviudal extended signature as if it had been in the * main header. */ - sum =3D mc->hdr.sig + mc->hdr.pf + mc->hdr.cksum; + sum =3D mc->sig + mc->pf + mc->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) ) return -EINVAL; @@ -221,7 +209,7 @@ static int microcode_sanity_check(const struct microcod= e_intel *mc) =20 /* Check an update against the CPU signature and current update revision */ static enum microcode_match_result microcode_update_match( - const struct microcode_intel *mc) + const struct microcode_patch *mc) { const struct extended_sigtable *ext; unsigned int i; @@ -230,7 +218,7 @@ static enum microcode_match_result microcode_update_mat= ch( ASSERT(!microcode_sanity_check(mc)); =20 /* Check the main microcode signature. */ - if ( signature_maches(cpu_sig, mc->hdr.sig, mc->hdr.pf) ) + if ( signature_maches(cpu_sig, mc->sig, mc->pf) ) goto found; =20 /* If there is an extended signature table, check each of them. */ @@ -242,7 +230,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) @@ -250,16 +238,12 @@ static bool match_cpu(const struct microcode_patch *p= atch) if ( !patch ) return false; =20 - return microcode_update_match(patch->mc_intel) =3D=3D NEW_UCODE; + return microcode_update_match(patch) =3D=3D NEW_UCODE; } =20 static void free_patch(struct microcode_patch *patch) { - if ( patch ) - { - xfree(patch->mc_intel); - xfree(patch); - } + xfree(patch); } =20 static enum microcode_match_result compare_patch( @@ -269,11 +253,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) !=3D MIS_UCODE); - ASSERT(microcode_update_match(new->mc_intel) !=3D MIS_UCODE); + ASSERT(microcode_update_match(old) !=3D MIS_UCODE); + ASSERT(microcode_update_match(new) !=3D MIS_UCODE); =20 - return (new->mc_intel->hdr.rev > old->mc_intel->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) @@ -281,7 +264,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 ) @@ -290,12 +272,10 @@ static int apply_microcode(const struct microcode_pat= ch *patch) if ( !match_cpu(patch) ) return -EINVAL; =20 - mc_intel =3D patch->mc_intel; - 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 */ @@ -305,18 +285,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; } @@ -325,19 +304,19 @@ static struct microcode_patch *cpu_request_microcode(= const void *buf, size_t size) { int error =3D 0; - const struct microcode_intel *saved =3D NULL; + const struct microcode_patch *saved =3D NULL; struct microcode_patch *patch =3D NULL; =20 while ( size ) { - const struct microcode_intel *mc; + const struct microcode_patch *mc; 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->hdr)) ) + get_totalsize(mc)) ) { error =3D -EINVAL; break; @@ -352,7 +331,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; @@ -361,17 +340,9 @@ static struct microcode_patch *cpu_request_microcode(c= onst void *buf, =20 if ( saved ) { - patch =3D xmalloc(struct microcode_patch); - if ( patch ) - { - patch->mc_intel =3D xmemdup_bytes(saved, get_totalsize(&saved-= >hdr)); - if ( !patch->mc_intel ) - { - XFREE(patch); - error =3D -ENOMEM; - } - } - else + patch =3D xmemdup_bytes(saved, get_totalsize(saved)); + + if ( !patch ) error =3D -ENOMEM; } =20 --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel