From patchwork Fri Mar 20 21:24:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11450385 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 7EC081392 for ; Fri, 20 Mar 2020 21:26:15 +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 5814B20724 for ; Fri, 20 Mar 2020 21:26:15 +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="eEIlIbuv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5814B20724 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 1jFP8c-0003tQ-Ou; Fri, 20 Mar 2020 21:25:06 +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 1jFP8b-0003tA-8O for xen-devel@lists.xenproject.org; Fri, 20 Mar 2020 21:25:05 +0000 X-Inumbo-ID: 40a20f5e-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 40a20f5e-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=gRxI7Oc4Wp+Qk0hR4RDsw2VmblvMSH/qTYnP7wNUnfc=; b=eEIlIbuvrE6uH1T3FoOjHy/rSdAQYlMuo4kuFIF3rVl+h9+6VAtG0Wl1 aU4xuQzS4okpn3dI22BSSI82HEZnBxkWygMb5xkseV2R9VkeSzD6FE6Ad ROWjmHdJ4IPv00cC/g2O84Hw1sEHJjoIimyyjVIMEdN/TNl4q2zlfzItn Q=; 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: MB9IwGlG5PhaooFKrO4v/o/Rlk7htYlTa13v3F/pdJfFA5wsxypsY723eH1pdUiQ42QWcf8v25 LekmDdYiZ97KueKGcV3VepxlZC3DnwIisaHstyBkPgG0sIUVTBynNp6ygg3PxDP/qv+nW5MlaE F1USN1zk4YvtpukxvGWe3rwVxUJQWsiRLGazWxf/JCEQOcsd2GXT98W2OGjWVFQP4ByKH3rjKw nf/pSOtkIHh686VgmhBJ1iWyu31MU4XQBOtPxiJlRFO6aMjyamG/DiCHXJnQlZGpn7glWIx47W Xxg= X-SBRS: 2.7 X-MesageID: 14716097 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="14716097" From: Andrew Cooper To: Xen-devel Date: Fri, 20 Mar 2020 21:24:49 +0000 Message-ID: <20200320212453.21685-2-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 1/4] x86/ucode/amd: Fix assertion in compare_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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This is clearly a typo. Fixes: 9da23943ccd "microcode: introduce a global cache of ucode patch" 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c index 99e2449eee..d4b2874de6 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -222,7 +222,7 @@ static enum microcode_match_result compare_patch( /* Both patches to compare are supposed to be applicable to local CPU. */ ASSERT(microcode_fits(new->mc_amd) != MIS_UCODE); - ASSERT(microcode_fits(new->mc_amd) != MIS_UCODE); + ASSERT(microcode_fits(old->mc_amd) != MIS_UCODE); return compare_header(new_header, old_header); } 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; } From patchwork Fri Mar 20 21:24:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11450387 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 CE8E31392 for ; Fri, 20 Mar 2020 21:26:17 +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 AB40F20724 for ; Fri, 20 Mar 2020 21:26:17 +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="IsJ86K4j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB40F20724 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 1jFP8m-0003w5-B3; Fri, 20 Mar 2020 21:25:16 +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 1jFP8l-0003v9-8X for xen-devel@lists.xenproject.org; Fri, 20 Mar 2020 21:25:15 +0000 X-Inumbo-ID: 425a449b-6af1-11ea-be19-12813bfff9fa Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 425a449b-6af1-11ea-be19-12813bfff9fa; Fri, 20 Mar 2020 21:25:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584739502; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Yp/861rLdxwmVg8ZyVF+rmArBo6QMsLefGFaDVLdQSs=; b=IsJ86K4j3TmWhgWkUlCjKR8XAkKN6UO39jETlNGcL2aGPRqfalj6NkA6 280qz5eDajE2zzjWMcCg2q7LZMaaabVvqMwi+uytYjXmAx3Km15TLJuMb +6K+Rvi/dGrIOFyTzdZpgV1QIWMX4ZaRwAaei30nD4920fSRoUNGfCxwU I=; 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: /VJBbAEGva673Cp9VTThZmy4teoqf/DYPrD+56kE2+xteGpLwnkTX5Qq9w/B0LWymf6KW4zhrV UKzxdQWJUK5rMZraHSKArwYubalmx1wrSZFP1aD+7Xt1ZE867Uas2w00k7Rec7MVMfKy1gIrS9 tVBW/eG1iMtTflvBSrZVH0vlI5FMqinZGXXxrQN+Unjpbfo+G2PhqVlm/XULHm6zzXmZLg1KdN sB87NVE9asbQZNg07ndwSnrQWJyiC1tBjk7HvrSiybVgPPqf/hgmtsiqF0XH14VSXsxIlsyhYC dOg= X-SBRS: 2.7 X-MesageID: 14716099 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="14716099" From: Andrew Cooper To: Xen-devel Date: Fri, 20 Mar 2020 21:24:51 +0000 Message-ID: <20200320212453.21685-4-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 3/4] xen: Drop raw_smp_processor_id() 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: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Jan Beulich , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" There is only a single user of raw_smp_processor_id() left in the tree (and it is unconditionally compiled out). Drop the alias from all architectures. Signed-off-by: Andrew Cooper Acked-by: Julien Grall Reviewed-by: Wei Liu --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk --- xen/arch/x86/cpu/microcode/amd.c | 2 +- xen/include/asm-arm/smp.h | 2 +- xen/include/asm-x86/smp.h | 2 +- xen/include/xen/smp.h | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c index a053e43923..0998a36b5c 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -306,7 +306,7 @@ static int get_ucode_from_buffer_amd( memcpy(mc_amd->mpb, mpbuf->data, mpbuf->len); pr_debug("microcode: CPU%d size %zu, block size %u offset %zu equivID %#x rev %#x\n", - raw_smp_processor_id(), bufsize, mpbuf->len, *offset, + smp_processor_id(), bufsize, mpbuf->len, *offset, ((struct microcode_header_amd *)mc_amd->mpb)->processor_rev_id, ((struct microcode_header_amd *)mc_amd->mpb)->patch_id); diff --git a/xen/include/asm-arm/smp.h b/xen/include/asm-arm/smp.h index fdbcefa241..af5a2fe652 100644 --- a/xen/include/asm-arm/smp.h +++ b/xen/include/asm-arm/smp.h @@ -12,7 +12,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); #define cpu_is_offline(cpu) unlikely(!cpu_online(cpu)) -#define raw_smp_processor_id() (get_processor_id()) +#define smp_processor_id() get_processor_id() /* * Do we, for platform reasons, need to actually keep CPUs online when we diff --git a/xen/include/asm-x86/smp.h b/xen/include/asm-x86/smp.h index 6150363655..f7485f602e 100644 --- a/xen/include/asm-x86/smp.h +++ b/xen/include/asm-x86/smp.h @@ -53,7 +53,7 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm); * from the initial startup. We map APIC_BASE very early in page_setup(), * so this is correct in the x86 case. */ -#define raw_smp_processor_id() (get_processor_id()) +#define smp_processor_id() get_processor_id() void __stop_this_cpu(void); diff --git a/xen/include/xen/smp.h b/xen/include/xen/smp.h index a64c9b3882..d5a3644611 100644 --- a/xen/include/xen/smp.h +++ b/xen/include/xen/smp.h @@ -65,8 +65,6 @@ void smp_call_function_interrupt(void); void smp_send_call_function_mask(const cpumask_t *mask); -#define smp_processor_id() raw_smp_processor_id() - int alloc_cpu_id(void); extern void *stack_base[NR_CPUS]; From patchwork Fri Mar 20 21:24:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11450381 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 7D68417E6 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 5693220724 for ; Fri, 20 Mar 2020 21:26:12 +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="fPlCFntX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5693220724 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 1jFP8c-0003tJ-HC; Fri, 20 Mar 2020 21:25:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jFP8b-0003t6-2f for xen-devel@lists.xenproject.org; Fri, 20 Mar 2020 21:25:05 +0000 X-Inumbo-ID: 434b48b8-6af1-11ea-a6c1-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 434b48b8-6af1-11ea-a6c1-bc764e2007e4; Fri, 20 Mar 2020 21:25:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1584739504; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s0Zn8myHzjApfW+BC4Q0BA7rfRL+0OX3tz6cOs5uv+8=; b=fPlCFntXIqtYAZ/iIoew6FT38+PJceG/MiYzvkDz86cwZ/4yXZoPeOVD 9VVc92SzLFYhrNjdWxzBdBZ9WYXoQO+pBqtsN4GfJ8sFZMG9JBIk/n7jN wExoqDGb85eyVcyYdN8ez2hdAhVvKFhffUDtoWLYyxwFJsyYY20dLsWLY g=; 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: 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: JRHYcfyRl5KSUmPI3Ohe9Nq4kMcJOVMvaXu89Mq1qCEr/S+FFeoMI/DgBjxkOsSh+9jR+PVWAy oQ97mB4qZMzUL0EmNQRcDu3f86J94/T6RK8T4t18UXougtk3pv/8dzF7Y9EIf11PY0CZBujTqT rjpWYTWt41826lNJqe5TPFGuj3CyLP1PEAdpECTwwWV60TkjPLdg1CJHs7tTuWMbXSU6Mkw+HP qNJn10qMf/aAtFcy5r2DlFMBycKafvNkTw55hYwjfA2GV+En+W5mNAO+IR9cA9x0DccZxDxVSc ryk= X-SBRS: 2.7 X-MesageID: 14795899 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,286,1580792400"; d="scan'208";a="14795899" From: Andrew Cooper To: Xen-devel Date: Fri, 20 Mar 2020 21:24:52 +0000 Message-ID: <20200320212453.21685-5-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 4/4] xen: Introduce a xmemdup_bytes() helper 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_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Use it to simplify the x86 microcode logic, taking the opportunity to drop the -ENOMEM printks. Signed-off-by: Andrew Cooper Reviewed-by: Wei Liu Acked-by: Julien Grall --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné --- xen/arch/x86/cpu/microcode/amd.c | 9 ++------- xen/arch/x86/cpu/microcode/intel.c | 7 ++----- xen/include/xen/xmalloc.h | 11 +++++++++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/cpu/microcode/amd.c b/xen/arch/x86/cpu/microcode/amd.c index 0998a36b5c..12a3b6b32c 100644 --- a/xen/arch/x86/cpu/microcode/amd.c +++ b/xen/arch/x86/cpu/microcode/amd.c @@ -299,11 +299,10 @@ static int get_ucode_from_buffer_amd( return -EINVAL; } - mc_amd->mpb = xmalloc_bytes(mpbuf->len); + mc_amd->mpb = xmemdup_bytes(mpbuf->data, mpbuf->len); if ( !mc_amd->mpb ) return -ENOMEM; mc_amd->mpb_size = mpbuf->len; - memcpy(mc_amd->mpb, mpbuf->data, mpbuf->len); pr_debug("microcode: CPU%d size %zu, block size %u offset %zu equivID %#x rev %#x\n", smp_processor_id(), bufsize, mpbuf->len, *offset, @@ -336,14 +335,10 @@ static int install_equiv_cpu_table( return -EINVAL; } - mc_amd->equiv_cpu_table = xmalloc_bytes(mpbuf->len); + mc_amd->equiv_cpu_table = xmemdup_bytes(mpbuf->data, mpbuf->len); if ( !mc_amd->equiv_cpu_table ) - { - printk(KERN_ERR "microcode: Cannot allocate memory for equivalent cpu table\n"); return -ENOMEM; - } - memcpy(mc_amd->equiv_cpu_table, mpbuf->data, mpbuf->len); mc_amd->equiv_cpu_table_size = mpbuf->len; return 0; diff --git a/xen/arch/x86/cpu/microcode/intel.c b/xen/arch/x86/cpu/microcode/intel.c index 6ac5f98694..f26511da98 100644 --- a/xen/arch/x86/cpu/microcode/intel.c +++ b/xen/arch/x86/cpu/microcode/intel.c @@ -339,13 +339,10 @@ static long get_next_ucode_from_buffer(struct microcode_intel **mc, return -EINVAL; } - *mc = xmalloc_bytes(total_size); + *mc = xmemdup_bytes(mc_header, total_size); if ( *mc == NULL ) - { - printk(KERN_ERR "microcode: error! Can not allocate memory\n"); return -ENOMEM; - } - memcpy(*mc, (const void *)(buf + offset), total_size); + return offset + total_size; } diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h index f515ceee2a..16979a117c 100644 --- a/xen/include/xen/xmalloc.h +++ b/xen/include/xen/xmalloc.h @@ -51,6 +51,17 @@ #define xmalloc_bytes(_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES) #define xzalloc_bytes(_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES) +/* Allocate untyped storage and copying an existing instance. */ +#define xmemdup_bytes(_src, _nr) \ + ({ \ + unsigned long nr_ = (_nr); \ + void *dst_ = xmalloc_bytes(nr_); \ + \ + if ( dst_ ) \ + memcpy(dst_, _src, nr_); \ + dst_; \ + }) + /* Free any of the above. */ extern void xfree(void *);