From patchwork Tue Nov 26 15:41:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 11262653 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4058A6C1 for ; Tue, 26 Nov 2019 15:43:09 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1CCA12071E for ; Tue, 26 Nov 2019 15:43:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="RtnaTkDO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CCA12071E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iZcyW-0000fN-B0; Tue, 26 Nov 2019 15:42:00 +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 1iZcyU-0000fI-Qq for xen-devel@lists.xen.org; Tue, 26 Nov 2019 15:41:58 +0000 X-Inumbo-ID: 474b6f4e-1063-11ea-a3a3-12813bfff9fa Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 474b6f4e-1063-11ea-a3a3-12813bfff9fa; Tue, 26 Nov 2019 15:41:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1574782917; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=5gVG/XC7XwavO+7DQ/jwtK4GwpnwKEEesx+THdH6So4=; b=RtnaTkDO/rPUFweTIVfFdDMmlW/0xBHXL7HsJW1Ydj9gmrhHBjCboBxh bOO+hVxhy74vHlpY24DSBAdDKYnXcWl0fSrJiyygZXJfqKcz4k8a8Z3h0 lDWOzsN1Nb5j24sB/wbEimOhvYGWh1rm2LaC/5sS2tbDOTCLoUpgqkWPc 8=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=sergey.dyasli@citrix.com; spf=Pass smtp.mailfrom=sergey.dyasli@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa4.hc3370-68.iphmx.com: no sender authenticity information available from domain of sergey.dyasli@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa4.hc3370-68.iphmx.com; envelope-from="sergey.dyasli@citrix.com"; x-sender="sergey.dyasli@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.hc3370-68.iphmx.com: domain of sergey.dyasli@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="sergey.dyasli@citrix.com"; x-sender="sergey.dyasli@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="sergey.dyasli@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: T7xE2BAdjAbkECBuHmmCY/LcuDVuZ5SDfl9k7cMiivEmC6MTTb6Gj1TLm/SycTCIrkb4LDU1t3 SSypM5XG24PMZvq5qMEWX/PBlvJatgsSdnemTyX7nv6rih9BQHA95oaLRFX/i5joWgtOjfZ4eo 42xgeAacmSeMpplgDdrDCiKfCwT3q0cvVWHpXAw+BFN3nplqcnCqxN6Z/HSLtCA2FP4Wc1M5ji 1f6L/a2sDRSNh/JD/NuAvIcRbqt0KNjRCQsz3dzNzZjd+5RvpbbVZCI0yJc9vIZtbiNUMXc2xo fH8= X-SBRS: 2.7 X-MesageID: 9403139 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.69,246,1571716800"; d="scan'208";a="9403139" From: Sergey Dyasli To: Date: Tue, 26 Nov 2019 15:41:53 +0000 Message-ID: <20191126154153.12144-1-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 for 4.13] x86/microcode: refuse to load the same revision ucode 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: Juergen Gross , Sergey Dyasli , Andrew Cooper , Jan Beulich , Chao Gao , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Currently if a user tries to live-load the same or older ucode revision than CPU already has, he will get a single message in Xen log like: (XEN) 128 cores are to update their microcode No actual ucode loading will happen and this situation can be quite confusing. Fix this by starting ucode update only when the provided ucode revision is higher than the currently cached one (if any). This is based on the property that if microcode_cache exists, all CPUs in the system should have at least that ucode revision. Additionally, print a user friendly message if no matching or newer ucode can be found in the provided blob. This also requires ignoring -ENODATA in AMD-side code, otherwise the message given to the user is: (XEN) Parsing microcode blob error -61 Which actually means that a ucode blob was parsed fine, but no matching ucode was found. Signed-off-by: Sergey Dyasli Acked-by: Jan Beulich Reviewed-by: Chao Gao --- v2 --> v3: - move ucode comparison to generic code - ignore -ENODATA in a different code section v1 --> v2: - compare provided ucode with the currently cached one CC: Jan Beulich CC: Andrew Cooper CC: Roger Pau MonnĂ© CC: Chao Gao CC: Juergen Gross --- xen/arch/x86/microcode.c | 19 +++++++++++++++++++ xen/arch/x86/microcode_amd.c | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index 65d1f41e7c..44efc2d9b3 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -640,10 +640,29 @@ int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void) buf, unsigned long len) if ( !patch ) { + printk(XENLOG_WARNING "microcode: couldn't find any matching ucode in " + "the provided blob!\n"); ret = -ENOENT; goto put; } + /* + * If microcode_cache exists, all CPUs in the system should have at least + * that ucode revision. + */ + spin_lock(µcode_mutex); + if ( microcode_cache && + microcode_ops->compare_patch(patch, microcode_cache) != NEW_UCODE ) + { + spin_unlock(µcode_mutex); + printk(XENLOG_WARNING "microcode: couldn't find any newer revision " + "in the provided blob!\n"); + ret = -ENOENT; + + goto put; + } + spin_unlock(µcode_mutex); + if ( microcode_ops->start_update ) { ret = microcode_ops->start_update(); diff --git a/xen/arch/x86/microcode_amd.c b/xen/arch/x86/microcode_amd.c index 1e52f7f49a..00750f7bbb 100644 --- a/xen/arch/x86/microcode_amd.c +++ b/xen/arch/x86/microcode_amd.c @@ -502,6 +502,13 @@ static struct microcode_patch *cpu_request_microcode(const void *buf, if ( error ) { + /* + * -ENODATA here means that the blob was parsed fine but no matching + * ucode was found. Don't return it to the caller. + */ + if ( error == -ENODATA ) + error = 0; + xfree(mc_amd->equiv_cpu_table); xfree(mc_amd); goto out;