From patchwork Mon Aug 19 01:25:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Gao X-Patchwork-Id: 11100117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5938B13A0 for ; Mon, 19 Aug 2019 01:23:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4983B2856D for ; Mon, 19 Aug 2019 01:23:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D9082858A; Mon, 19 Aug 2019 01:23:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4ECA72856D for ; Mon, 19 Aug 2019 01:23:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hzWMl-0001BC-Oa; Mon, 19 Aug 2019 01:21:47 +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 1hzWMj-00019z-N4 for xen-devel@lists.xenproject.org; Mon, 19 Aug 2019 01:21:45 +0000 X-Inumbo-ID: b519343a-c21f-11e9-8be5-12813bfff9fa Received: from mga03.intel.com (unknown [134.134.136.65]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b519343a-c21f-11e9-8be5-12813bfff9fa; Mon, 19 Aug 2019 01:21:45 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Aug 2019 18:21:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,403,1559545200"; d="scan'208";a="261683894" Received: from gao-cwp.sh.intel.com ([10.239.159.26]) by orsmga001.jf.intel.com with ESMTP; 18 Aug 2019 18:21:42 -0700 From: Chao Gao To: xen-devel@lists.xenproject.org Date: Mon, 19 Aug 2019 09:25:20 +0800 Message-Id: <1566177928-19114-8-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1566177928-19114-1-git-send-email-chao.gao@intel.com> References: <1566177928-19114-1-git-send-email-chao.gao@intel.com> Subject: [Xen-devel] [PATCH v9 07/15] microcode: remove pointless 'cpu' parameter 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: Ashok Raj , Wei Liu , Andrew Cooper , Jan Beulich , Chao Gao , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Some callbacks in microcode_ops or related functions take a cpu id parameter. But at current call sites, the cpu id parameter is always equal to current cpu id. Some of them even use an assertion to guarantee this. Remove this redundent 'cpu' parameter. Signed-off-by: Chao Gao Reviewed-by: Jan Beulich --- Changes in v9: - use a convenience variable 'cpu' in collect_cpu_info() on AMD side - rebase and fix conflicts Changes in v8: - Use current_cpu_data in collect_cpu_info() - keep the cpu parameter of check_final_patch_levels() - use smp_processor_id() in get_matching_microcode() rather than define a local variable and label it "__maybe_unused" --- xen/arch/x86/acpi/power.c | 2 +- xen/arch/x86/microcode.c | 20 ++++++++------------ xen/arch/x86/microcode_amd.c | 30 +++++++++++------------------- xen/arch/x86/microcode_intel.c | 35 +++++++++++++---------------------- xen/arch/x86/smpboot.c | 2 +- xen/include/asm-x86/microcode.h | 7 +++---- xen/include/asm-x86/processor.h | 2 +- 7 files changed, 38 insertions(+), 60 deletions(-) diff --git a/xen/arch/x86/acpi/power.c b/xen/arch/x86/acpi/power.c index aecc754..4f21903 100644 --- a/xen/arch/x86/acpi/power.c +++ b/xen/arch/x86/acpi/power.c @@ -253,7 +253,7 @@ static int enter_state(u32 state) console_end_sync(); - microcode_resume_cpu(0); + microcode_resume_cpu(); 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 552e7fe..3b87c72 100644 --- a/xen/arch/x86/microcode.c +++ b/xen/arch/x86/microcode.c @@ -196,19 +196,19 @@ struct microcode_info { char buffer[1]; }; -int microcode_resume_cpu(unsigned int cpu) +int microcode_resume_cpu(void) { int err; - struct cpu_signature *sig = &per_cpu(cpu_sig, cpu); + struct cpu_signature *sig = &this_cpu(cpu_sig); if ( !microcode_ops ) return 0; spin_lock(µcode_mutex); - err = microcode_ops->collect_cpu_info(cpu, sig); + err = microcode_ops->collect_cpu_info(sig); if ( likely(!err) ) - err = microcode_ops->apply_microcode(cpu); + err = microcode_ops->apply_microcode(); spin_unlock(µcode_mutex); return err; @@ -258,9 +258,9 @@ static int microcode_update_cpu(const void *buf, size_t size) spin_lock(µcode_mutex); - err = microcode_ops->collect_cpu_info(cpu, sig); + err = microcode_ops->collect_cpu_info(sig); if ( likely(!err) ) - err = microcode_ops->cpu_request_microcode(cpu, buf, size); + err = microcode_ops->cpu_request_microcode(buf, size); spin_unlock(µcode_mutex); return err; @@ -349,8 +349,6 @@ __initcall(microcode_init); int __init early_microcode_update_cpu(bool start_update) { - unsigned int cpu = smp_processor_id(); - struct cpu_signature *sig = &per_cpu(cpu_sig, cpu); int rc = 0; void *data = NULL; size_t len; @@ -369,7 +367,7 @@ int __init early_microcode_update_cpu(bool start_update) data = bootstrap_map(&ucode_mod); } - microcode_ops->collect_cpu_info(cpu, sig); + microcode_ops->collect_cpu_info(&this_cpu(cpu_sig)); if ( data ) { @@ -387,8 +385,6 @@ int __init early_microcode_update_cpu(bool start_update) int __init early_microcode_init(void) { - unsigned int cpu = smp_processor_id(); - struct cpu_signature *sig = &per_cpu(cpu_sig, cpu); int rc; rc = microcode_init_intel(); @@ -401,7 +397,7 @@ int __init early_microcode_init(void) if ( microcode_ops ) { - microcode_ops->collect_cpu_info(cpu, sig); + microcode_ops->collect_cpu_info(&this_cpu(cpu_sig)); if ( ucode_mod.mod_end || ucode_blob.size ) rc = early_microcode_update_cpu(true); diff --git a/xen/arch/x86/microcode_amd.c b/xen/arch/x86/microcode_amd.c index 9e4ec73..dd3821c 100644 --- a/xen/arch/x86/microcode_amd.c +++ b/xen/arch/x86/microcode_amd.c @@ -78,8 +78,9 @@ struct mpbhdr { static DEFINE_SPINLOCK(microcode_update_lock); /* See comment in start_update() for cases when this routine fails */ -static int collect_cpu_info(unsigned int cpu, struct cpu_signature *csig) +static int collect_cpu_info(struct cpu_signature *csig) { + unsigned int cpu = smp_processor_id(); struct cpuinfo_x86 *c = &cpu_data[cpu]; memset(csig, 0, sizeof(*csig)); @@ -153,17 +154,15 @@ static bool_t find_equiv_cpu_id(const struct equiv_cpu_entry *equiv_cpu_table, } static enum microcode_match_result microcode_fits( - const struct microcode_amd *mc_amd, unsigned int cpu) + const struct microcode_amd *mc_amd) { + unsigned int cpu = smp_processor_id(); const struct cpu_signature *sig = &per_cpu(cpu_sig, cpu); const struct microcode_header_amd *mc_header = mc_amd->mpb; const struct equiv_cpu_entry *equiv_cpu_table = mc_amd->equiv_cpu_table; unsigned int current_cpu_id; unsigned int equiv_cpu_id; - /* We should bind the task to the CPU */ - BUG_ON(cpu != raw_smp_processor_id()); - current_cpu_id = cpuid_eax(0x00000001); if ( !find_equiv_cpu_id(equiv_cpu_table, current_cpu_id, &equiv_cpu_id) ) @@ -192,9 +191,7 @@ static enum microcode_match_result microcode_fits( static bool match_cpu(const struct microcode_patch *patch) { - if ( !patch ) - return false; - return microcode_fits(patch->mc_amd, smp_processor_id()) == NEW_UCODE; + return patch && (microcode_fits(patch->mc_amd) == NEW_UCODE); } static struct microcode_patch *alloc_microcode_patch( @@ -251,18 +248,16 @@ static enum microcode_match_result compare_patch( return MIS_UCODE; } -static int apply_microcode(unsigned int cpu) +static int apply_microcode(void) { unsigned long flags; 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; const struct microcode_patch *patch = microcode_get_cache(); - /* We should bind the task to the CPU */ - BUG_ON(raw_smp_processor_id() != cpu); - if ( !match_cpu(patch) ) return -EINVAL; @@ -453,19 +448,16 @@ static bool_t check_final_patch_levels(unsigned int cpu) return 0; } -static int cpu_request_microcode(unsigned int cpu, const void *buf, - size_t bufsize) +static int cpu_request_microcode(const void *buf, size_t bufsize) { struct microcode_amd *mc_amd; size_t offset = 0; int error = 0; unsigned int current_cpu_id; unsigned int equiv_cpu_id; + unsigned int cpu = smp_processor_id(); const struct cpu_signature *sig = &per_cpu(cpu_sig, cpu); - /* We should bind the task to the CPU */ - BUG_ON(cpu != raw_smp_processor_id()); - current_cpu_id = cpuid_eax(0x00000001); if ( *(const uint32_t *)buf != UCODE_MAGIC ) @@ -558,14 +550,14 @@ static int cpu_request_microcode(unsigned int cpu, const void *buf, } /* Update cache if this patch covers current CPU */ - if ( microcode_fits(new_patch->mc_amd, cpu) != MIS_UCODE ) + if ( microcode_fits(new_patch->mc_amd) != MIS_UCODE ) microcode_update_cache(new_patch); else microcode_free_patch(new_patch); if ( match_cpu(microcode_get_cache()) ) { - error = apply_microcode(cpu); + error = apply_microcode(); if ( error ) break; } diff --git a/xen/arch/x86/microcode_intel.c b/xen/arch/x86/microcode_intel.c index fafaa79..a5452d4 100644 --- a/xen/arch/x86/microcode_intel.c +++ b/xen/arch/x86/microcode_intel.c @@ -96,13 +96,12 @@ struct extended_sigtable { /* serialize access to the physical write to MSR 0x79 */ static DEFINE_SPINLOCK(microcode_update_lock); -static int collect_cpu_info(unsigned int cpu_num, struct cpu_signature *csig) +static int collect_cpu_info(struct cpu_signature *csig) { + unsigned int cpu_num = smp_processor_id(); struct cpuinfo_x86 *c = &cpu_data[cpu_num]; uint64_t msr_content; - BUG_ON(cpu_num != smp_processor_id()); - memset(csig, 0, sizeof(*csig)); if ( (c->x86_vendor != X86_VENDOR_INTEL) || (c->x86 < 6) ) @@ -136,12 +135,12 @@ static int collect_cpu_info(unsigned int cpu_num, struct cpu_signature *csig) /* 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, unsigned int cpu) + const struct microcode_header_intel *mc_header) { const struct extended_sigtable *ext_header; const struct extended_signature *ext_sig; unsigned int i; - struct cpu_signature *cpu_sig = &per_cpu(cpu_sig, cpu); + struct cpu_signature *cpu_sig = &this_cpu(cpu_sig); unsigned int sig = cpu_sig->sig; unsigned int pf = cpu_sig->pf; unsigned int rev = cpu_sig->rev; @@ -264,8 +263,7 @@ static bool match_cpu(const struct microcode_patch *patch) if ( !patch ) return false; - return microcode_update_match(&patch->mc_intel->hdr, - smp_processor_id()) == NEW_UCODE; + return microcode_update_match(&patch->mc_intel->hdr) == NEW_UCODE; } static void free_patch(void *mc) @@ -289,7 +287,7 @@ static enum microcode_match_result compare_patch( * return 1 - found update * return < 0 - error */ -static int get_matching_microcode(const void *mc, unsigned int cpu) +static int get_matching_microcode(const void *mc) { const struct microcode_header_intel *mc_header = mc; unsigned long total_size = get_totalsize(mc_header); @@ -306,7 +304,7 @@ static int get_matching_microcode(const void *mc, unsigned int cpu) new_patch->mc_intel = new_mc; /* Make sure that this patch covers current CPU */ - if ( microcode_update_match(mc, cpu) == MIS_UCODE ) + if ( microcode_update_match(mc) == MIS_UCODE ) { microcode_free_patch(new_patch); return 0; @@ -316,24 +314,21 @@ static int get_matching_microcode(const void *mc, unsigned int cpu) pr_debug("microcode: CPU%d found a matching microcode update with" " version %#x (current=%#x)\n", - cpu, mc_header->rev, per_cpu(cpu_sig, cpu).rev); + smp_processor_id(), mc_header->rev, this_cpu(cpu_sig).rev); return 1; } -static int apply_microcode(unsigned int cpu) +static int apply_microcode(void) { unsigned long flags; uint64_t msr_content; unsigned int val[2]; unsigned int cpu_num = raw_smp_processor_id(); - struct cpu_signature *sig = &per_cpu(cpu_sig, cpu); + struct cpu_signature *sig = &this_cpu(cpu_sig); const struct microcode_intel *mc_intel; const struct microcode_patch *patch = microcode_get_cache(); - /* We should bind the task to the CPU */ - BUG_ON(cpu_num != cpu); - if ( !match_cpu(patch) ) return -EINVAL; @@ -398,22 +393,18 @@ static long get_next_ucode_from_buffer(void **mc, const u8 *buf, return offset + total_size; } -static int cpu_request_microcode(unsigned int cpu, const void *buf, - size_t size) +static int cpu_request_microcode(const void *buf, size_t size) { long offset = 0; int error = 0; void *mc; - /* We should bind the task to the CPU */ - BUG_ON(cpu != raw_smp_processor_id()); - while ( (offset = get_next_ucode_from_buffer(&mc, buf, size, offset)) > 0 ) { error = microcode_sanity_check(mc); if ( error ) break; - error = get_matching_microcode(mc, cpu); + error = get_matching_microcode(mc); if ( error < 0 ) break; /* @@ -431,7 +422,7 @@ static int cpu_request_microcode(unsigned int cpu, const void *buf, error = offset; if ( !error && match_cpu(microcode_get_cache()) ) - error = apply_microcode(cpu); + error = apply_microcode(); return error; } diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index 65e9cee..c818cfc 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -364,7 +364,7 @@ void start_secondary(void *unused) if ( system_state <= SYS_STATE_smp_boot ) early_microcode_update_cpu(false); else - microcode_resume_cpu(cpu); + microcode_resume_cpu(); /* * If MSR_SPEC_CTRL is available, apply Xen's default setting and discard diff --git a/xen/include/asm-x86/microcode.h b/xen/include/asm-x86/microcode.h index 5b8289f..35223eb 100644 --- a/xen/include/asm-x86/microcode.h +++ b/xen/include/asm-x86/microcode.h @@ -20,10 +20,9 @@ struct microcode_patch { }; struct microcode_ops { - int (*cpu_request_microcode)(unsigned int cpu, const void *buf, - size_t size); - int (*collect_cpu_info)(unsigned int cpu, struct cpu_signature *csig); - int (*apply_microcode)(unsigned int cpu); + int (*cpu_request_microcode)(const void *buf, size_t size); + int (*collect_cpu_info)(struct cpu_signature *csig); + int (*apply_microcode)(void); int (*start_update)(void); void (*free_patch)(void *mc); bool (*match_cpu)(const struct microcode_patch *patch); diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h index 2862321..104faa9 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -568,7 +568,7 @@ int guest_wrmsr_xen(struct vcpu *v, uint32_t idx, uint64_t val); void microcode_set_module(unsigned int); int microcode_update(XEN_GUEST_HANDLE_PARAM(const_void), unsigned long len); -int microcode_resume_cpu(unsigned int cpu); +int microcode_resume_cpu(void); int early_microcode_update_cpu(bool start_update); int early_microcode_init(void); int microcode_init_intel(void);