From patchwork Fri Mar 20 21:24:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11450379 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 1CA771392 for ; Fri, 20 Mar 2020 21:26:12 +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 E40A120724 for ; Fri, 20 Mar 2020 21:26:11 +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="WATd6HA3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E40A120724 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass 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 1jFP8h-0003uH-1N; Fri, 20 Mar 2020 21:25:11 +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 1jFP8g-0003u3-8X for xen-devel@lists.xenproject.org; Fri, 20 Mar 2020 21:25:10 +0000 X-Inumbo-ID: 40a20f60-6af1-11ea-be18-12813bfff9fa Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 40a20f60-6af1-11ea-be18-12813bfff9fa; Fri, 20 Mar 2020 21:25:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584739500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RBQi4FtTtH8S07eLiEJoFsDh4jC3Cj57iZU7zh4E8vI=; b=WATd6HA3oxmlSZasq+bedkIMVhrQE3sBeMvzxDfy738S4mZoD1gZ+KUR kzLdsq5U4DhZytGcSCgE0EG7RtYjh3RtyyBJ+LGXUcVBfbGDLc62KGdFL IYiUrBbeN2D1sHZwx9lm3Rcdz+Pdr79YT6bbWNor6EHfxL29IBeRG9ASc 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: 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: 3TRS0Zvbb6fY/iambXIdHVxTEMdcb+NYBHI4vF4oQYessG6RNQU00guQJv8x/Le9EQh2bMTOfI AZON4BbKT/CyD4QiVVFY4d3j0UtszU0W/KPz6W3Aal3ZtgxXCEgofoa1f5k3LKS3GK4VSwJ/ZB Z/mEO1MEsjPWfU2PNcBhlAHoR6kgxvSJCXAeIeyLZ/lA0SrpiDY4ATu0BziIIl1V+ANqzeQ84E EqtYbrOnmDWzJeyou5yikJTNPzVsCVg5HgpaboBQMCTU9xIN1TBe5qIippuvK+FQb7LU9WyMJy ghY= X-SBRS: 2.7 X-MesageID: 14716098 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,286,1580792400"; d="scan'208";a="14716098" From: Andrew Cooper To: Xen-devel Date: Fri, 20 Mar 2020 21:24:50 +0000 Message-ID: <20200320212453.21685-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200320212453.21685-1-andrew.cooper3@citrix.com> References: <20200320212453.21685-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/4] x86/ucode: Fix error paths in apply_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 , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In the unlikley case that patch application completes, but the resutling revision isn't expected, sig->rev doesn't get updated to match reality. It will get adjusted the next time collect_cpu_info() gets called, but in the meantime Xen might operate on a state value. Nothing good will come of this. Rewrite the logic to always update the stashed revision, before worring about whether the attempt was a success or failure. Take the opportunity to make the printk() messages as consistent as possible. Signed-off-by: Andrew Cooper Reviewed-by: Wei Liu --- -CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné --- xen/arch/x86/cpu/microcode/amd.c | 14 +++++++------- xen/arch/x86/cpu/microcode/intel.c | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c index d4b2874de6..a053e43923 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -229,11 +229,11 @@ static enum microcode_match_result compare_patch( static int apply_microcode(const struct microcode_patch *patch) { - uint32_t rev; int hw_err; unsigned int cpu = smp_processor_id(); struct cpu_signature *sig = &per_cpu(cpu_sig, cpu); const struct microcode_header_amd *hdr; + uint32_t rev, old_rev = sig->rev; if ( !patch ) return -ENOENT; @@ -249,6 +249,7 @@ static int apply_microcode(const struct microcode_patch *patch) /* get patch id after patching */ rdmsrl(MSR_AMD_PATCHLEVEL, rev); + sig->rev = rev; /* * Some processors leave the ucode blob mapping as UC after the update. @@ -259,15 +260,14 @@ static int apply_microcode(const struct microcode_patch *patch) /* check current patch id and patch's id for match */ if ( hw_err || (rev != hdr->patch_id) ) { - printk(KERN_ERR "microcode: CPU%d update from revision " - "%#x to %#x failed\n", cpu, rev, hdr->patch_id); + printk(XENLOG_ERR + "microcode: CPU%u update rev %#x to %#x failed, result %#x\n", + cpu, old_rev, hdr->patch_id, rev); return -EIO; } - printk(KERN_WARNING "microcode: CPU%d updated from revision %#x to %#x\n", - cpu, sig->rev, hdr->patch_id); - - sig->rev = rev; + printk(XENLOG_WARNING "microcode: CPU%u updated from revision %#x to %#x\n", + cpu, old_rev, hdr->patch_id); return 0; } diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcode/intel.c index 5e9c2a9c7f..6ac5f98694 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -278,10 +278,10 @@ static enum microcode_match_result compare_patch( static int apply_microcode(const struct microcode_patch *patch) { uint64_t msr_content; - unsigned int val[2]; - unsigned int cpu_num = raw_smp_processor_id(); + unsigned int cpu = smp_processor_id(); struct cpu_signature *sig = &this_cpu(cpu_sig); const struct microcode_intel *mc_intel; + uint32_t rev, old_rev = sig->rev; if ( !patch ) return -ENOENT; @@ -302,20 +302,20 @@ static int apply_microcode(const struct microcode_patch *patch) /* get the current revision from MSR 0x8B */ rdmsrl(MSR_IA32_UCODE_REV, msr_content); - val[1] = (uint32_t)(msr_content >> 32); + sig->rev = rev = msr_content >> 32; - if ( val[1] != mc_intel->hdr.rev ) + if ( rev != mc_intel->hdr.rev ) { - printk(KERN_ERR "microcode: CPU%d update from revision " - "%#x to %#x failed. Resulting revision is %#x.\n", cpu_num, - sig->rev, mc_intel->hdr.rev, val[1]); + printk(XENLOG_ERR + "microcode: CPU%u update rev %#x to %#x failed, result %#x\n", + cpu, old_rev, mc_intel->hdr.rev, rev); return -EIO; } - printk(KERN_INFO "microcode: CPU%d updated from revision " - "%#x to %#x, date = %04x-%02x-%02x\n", - cpu_num, sig->rev, val[1], mc_intel->hdr.year, + + printk(XENLOG_WARNING + "microcode: CPU%u updated from revision %#x to %#x, date = %04x-%02x-%02x\n", + cpu, old_rev, rev, mc_intel->hdr.year, mc_intel->hdr.month, mc_intel->hdr.day); - sig->rev = val[1]; return 0; }