[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250226175209.GNZ79UyXn5pODSYNrn@fat_crate.local>
Date: Wed, 26 Feb 2025 18:52:09 +0100
From: Borislav Petkov <bp@...en8.de>
To: "Chang S. Bae" <chang.seok.bae@...el.com>
Cc: linux-kernel@...r.kernel.org, x86@...nel.org, tglx@...utronix.de,
mingo@...hat.com, dave.hansen@...ux.intel.com
Subject: Re: [PATCH 3/6] x86/microcode/intel: Prepare for microcode staging
On Tue, Dec 10, 2024 at 05:42:09PM -0800, Chang S. Bae wrote:
> +static void stage_microcode(void)
> +{
> + unsigned int totalsize, pkg_id = UINT_MAX;
> + enum ucode_state state;
> + int cpu;
> + u64 pa;
> +
> + totalsize = get_totalsize(&ucode_patch_late->hdr);
> + if (!IS_ALIGNED(totalsize, sizeof(u32)))
> + return;
... lockdep assert hotplug lock held blabla...
> +
> + /*
> + * The MMIO address is unique per package, and all the SMT
> + * primary threads are online here. Find each MMIO space by
> + * their package ids to avoid duplicate staging.
> + */
> + for_each_cpu(cpu, cpu_online_mask) {
> + if (!topology_is_primary_thread(cpu) || topology_logical_package_id(cpu) == pkg_id)
> + continue;
if (!topology_is_primary_thread(cpu) ||
topology_logical_package_id(cpu) == pkg_id)
> + pkg_id = topology_logical_package_id(cpu);
> +
> + rdmsrl_on_cpu(cpu, MSR_IA32_MCU_STAGING_MBOX_ADDR, &pa);
> +
> + state = do_stage(pa, ucode_patch_late, totalsize);
> + if (state != UCODE_OK) {
> + pr_err("Error: staging failed with %s for CPU%d at package %u.\n",
> + state == UCODE_TIMEOUT ? "timeout" : "error state", cpu, pkg_id);
> + return;
> + }
> + }
> +
> + pr_info("Staging of patch revision 0x%x succeeded.\n",
> + ((struct microcode_header_intel *)ucode_patch_late)->rev);
> +}
> +
> static enum ucode_state __apply_microcode(struct ucode_cpu_info *uci,
> struct microcode_intel *mc,
> u32 *cur_rev)
> @@ -627,6 +662,7 @@ static struct microcode_ops microcode_intel_ops = {
> .collect_cpu_info = collect_cpu_info,
> .apply_microcode = apply_microcode_late,
> .finalize_late_load = finalize_late_load,
> + .stage_microcode = stage_microcode,
Btw, you can get rid of ->use_staging and simply check whether
->stage_microcode is not NULL.
> .use_nmi = IS_ENABLED(CONFIG_X86_64),
> };
>
> diff --git a/arch/x86/kernel/cpu/microcode/internal.h b/arch/x86/kernel/cpu/microcode/internal.h
> index b27cb8e1228d..158429d80f93 100644
> --- a/arch/x86/kernel/cpu/microcode/internal.h
> +++ b/arch/x86/kernel/cpu/microcode/internal.h
> @@ -120,11 +120,18 @@ void load_ucode_intel_bsp(struct early_load_data *ed);
> void load_ucode_intel_ap(void);
> void reload_ucode_intel(void);
> struct microcode_ops *init_intel_microcode(void);
> +static inline enum ucode_state do_stage(u64 pa, void *ucode_ptr, unsigned int totalsize)
> +{
> + pr_debug_once("Need to implement the staging code.\n");
> + return UCODE_ERROR;
> +}
> #else /* CONFIG_CPU_SUP_INTEL */
> static inline void load_ucode_intel_bsp(struct early_load_data *ed) { }
> static inline void load_ucode_intel_ap(void) { }
> static inline void reload_ucode_intel(void) { }
> static inline struct microcode_ops *init_intel_microcode(void) { return NULL; }
> +static inline enum ucode_state
> +do_stage(u64 pa, void *ucode_ptr, unsigned int totalsize) { return UCODE_ERROR; }
> #endif /* !CONFIG_CPU_SUP_INTEL */
>
You don't need to export those if staging is going to be done only by the
Intel side. Just keep everything in intel.c
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
Powered by blists - more mailing lists