From nobody Mon Feb 9 09:29:33 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1568272821; cv=none; d=zoho.com; s=zohoarc; b=mzUmFbU58boi7fOee5JD6o3q/15DcELyDjX71uMTEkWlRYNILl3aQx2nBAwoBC7hT8VRstWt8/MXuYwLOynSUidLGLq+vFcX6f3yxxkZXznv7Oi1gbLvp+FBDhm94KcjUaiby4lXnO/iT7uekewRnrn/cu1vUbmxd0MS+5JtOKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568272821; 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:ARC-Authentication-Results; bh=OPZRCMGxFo7KQNgXnNdVzXyHKrupydMOypaDJHuKedM=; b=WrIJY784P65HwAsFbbo7EEwdD+Q/0JMrQJjtSTBFM1rNnMFZfRVIUV6Sb2A1T/ftm9KjvQP9vKGcQBZ4uz7b4miHi425kWU3mfJ/NOHWFidzb0BW0tmZm5IAPhYoj2YmmW9Ym5KG8t6MmkWtZhd6Ii2/y7D0Y5BFSF5EY6TXzd8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) 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 1568272821423432.39905086458566; Thu, 12 Sep 2019 00:20:21 -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 1i8JNt-0001iZ-S2; Thu, 12 Sep 2019 07:19:17 +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 1i8JNt-0001i4-5j for xen-devel@lists.xenproject.org; Thu, 12 Sep 2019 07:19:17 +0000 Received: from mga01.intel.com (unknown [192.55.52.88]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 96bf3842-d52d-11e9-83e3-12813bfff9fa; Thu, 12 Sep 2019 07:18:59 +0000 (UTC) Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2019 00:18:58 -0700 Received: from gao-cwp.sh.intel.com ([10.239.159.26]) by orsmga006.jf.intel.com with ESMTP; 12 Sep 2019 00:18:56 -0700 X-Inumbo-ID: 96bf3842-d52d-11e9-83e3-12813bfff9fa X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,492,1559545200"; d="scan'208";a="189906302" From: Chao Gao To: xen-devel@lists.xenproject.org Date: Thu, 12 Sep 2019 15:22:23 +0800 Message-Id: <1568272949-1086-11-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1568272949-1086-1-git-send-email-chao.gao@intel.com> References: <1568272949-1086-1-git-send-email-chao.gao@intel.com> Subject: [Xen-devel] [PATCH v10 10/16] microcode: unify ucode loading during system bootup and resuming 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: Sergey Dyasli , Ashok Raj , Wei Liu , Andrew Cooper , Jan Beulich , Chao Gao , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" During system bootup and resuming, CPUs just load the cached ucode. So one unified function microcode_update_one() is introduced. It takes a boolean to indicate whether ->start_update should be called. Since early_microcode_update_cpu() is only called on BSP (APs call the unified function), start_update is always true and so remove this parameter. There is a functional change: ->start_update is called on BSP and ->end_update_percpu is called during system resuming. They are not invoked by previous microcode_resume_cpu(). Signed-off-by: Chao Gao Reviewed-by: Jan Beulich --- Changes in v10: - call ->start_update for system resume from suspension Changes in v9: - return -EOPNOTSUPP rather than 0 if microcode_ops is NULL in microcode_update_one() - rebase and fix conflicts. Changes in v8: - split out from the previous patch --- xen/arch/x86/acpi/power.c | 2 +- xen/arch/x86/microcode.c | 91 +++++++++++++++++++------------------= ---- xen/arch/x86/smpboot.c | 5 +-- xen/include/asm-x86/processor.h | 4 +- 4 files changed, 45 insertions(+), 57 deletions(-) diff --git a/xen/arch/x86/acpi/power.c b/xen/arch/x86/acpi/power.c index 269b140..01e6aec 100644 --- a/xen/arch/x86/acpi/power.c +++ b/xen/arch/x86/acpi/power.c @@ -278,7 +278,7 @@ static int enter_state(u32 state) =20 console_end_sync(); =20 - microcode_resume_cpu(); + microcode_update_one(true); =20 if ( !recheck_cpu_features(0) ) panic("Missing previously available feature(s)\n"); diff --git a/xen/arch/x86/microcode.c b/xen/arch/x86/microcode.c index d4738f6..c2ea20f 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -203,24 +203,6 @@ static struct microcode_patch *parse_blob(const char *= buf, size_t len) return NULL; } =20 -int microcode_resume_cpu(void) -{ - int err; - struct cpu_signature *sig =3D &this_cpu(cpu_sig); - - if ( !microcode_ops ) - return 0; - - spin_lock(µcode_mutex); - - err =3D microcode_ops->collect_cpu_info(sig); - if ( likely(!err) ) - err =3D microcode_ops->apply_microcode(microcode_cache); - spin_unlock(µcode_mutex); - - return err; -} - void microcode_free_patch(struct microcode_patch *microcode_patch) { microcode_ops->free_patch(microcode_patch->mc); @@ -394,11 +376,38 @@ static int __init microcode_init(void) } __initcall(microcode_init); =20 -int __init early_microcode_update_cpu(bool start_update) +/* Load a cached update to current cpu */ +int microcode_update_one(bool start_update) +{ + int err; + + if ( !microcode_ops ) + return -EOPNOTSUPP; + + microcode_ops->collect_cpu_info(&this_cpu(cpu_sig)); + + if ( start_update && microcode_ops->start_update ) + { + err =3D microcode_ops->start_update(); + if ( err ) + return err; + } + + err =3D microcode_update_cpu(NULL); + + if ( microcode_ops->end_update_percpu ) + microcode_ops->end_update_percpu(); + + return err; +} + +/* BSP calls this function to parse ucode blob and then apply an update. */ +int __init early_microcode_update_cpu(void) { int rc =3D 0; void *data =3D NULL; size_t len; + struct microcode_patch *patch; =20 if ( !microcode_ops ) return -ENOSYS; @@ -414,44 +423,26 @@ int __init early_microcode_update_cpu(bool start_upda= te) data =3D bootstrap_map(&ucode_mod); } =20 - microcode_ops->collect_cpu_info(&this_cpu(cpu_sig)); - if ( !data ) return -ENOMEM; =20 - if ( start_update ) + patch =3D parse_blob(data, len); + if ( IS_ERR(patch) ) { - struct microcode_patch *patch; - - patch =3D parse_blob(data, len); - if ( IS_ERR(patch) ) - { - printk(XENLOG_WARNING "Parsing microcode blob error %ld\n", - PTR_ERR(patch)); - return PTR_ERR(patch); - } - - if ( !patch ) - return -ENOENT; - - spin_lock(µcode_mutex); - rc =3D microcode_update_cache(patch); - spin_unlock(µcode_mutex); - ASSERT(rc); - - if ( microcode_ops->start_update ) - rc =3D microcode_ops->start_update(); - - if ( rc ) - return rc; + printk(XENLOG_WARNING "Parsing microcode blob error %ld\n", + PTR_ERR(patch)); + return PTR_ERR(patch); } =20 - rc =3D microcode_update_cpu(NULL); + if ( !patch ) + return -ENOENT; =20 - if ( microcode_ops->end_update_percpu ) - microcode_ops->end_update_percpu(); + spin_lock(µcode_mutex); + rc =3D microcode_update_cache(patch); + spin_unlock(µcode_mutex); + ASSERT(rc); =20 - return rc; + return microcode_update_one(true); } =20 int __init early_microcode_init(void) @@ -471,7 +462,7 @@ int __init early_microcode_init(void) microcode_ops->collect_cpu_info(&this_cpu(cpu_sig)); =20 if ( ucode_mod.mod_end || ucode_blob.size ) - rc =3D early_microcode_update_cpu(true); + rc =3D early_microcode_update_cpu(); } =20 return rc; diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 73a1afc..179f6b6 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -360,10 +360,7 @@ void start_secondary(void *unused) =20 initialize_cpu_data(cpu); =20 - if ( system_state <=3D SYS_STATE_smp_boot ) - early_microcode_update_cpu(false); - else - microcode_resume_cpu(); + microcode_update_one(false); =20 /* * If MSR_SPEC_CTRL is available, apply Xen's default setting and disc= ard diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processo= r.h index a673372..c92956f 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -569,9 +569,9 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint6= 4_t val); =20 void microcode_set_module(unsigned int); int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void), unsigned long len= ); -int microcode_resume_cpu(void); -int early_microcode_update_cpu(bool start_update); +int early_microcode_update_cpu(void); int early_microcode_init(void); +int microcode_update_one(bool start_update); int microcode_init_intel(void); int microcode_init_amd(void); =20 --=20 1.8.3.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel