Skip to content

Commit 740144b

Browse files
ChangSeokBaebp3tk0v
authored andcommitted
x86/microcode/intel: Establish staging control logic
When microcode staging is initiated, operations are carried out through an MMIO interface. Each package has a unique interface specified by the IA32_MCU_STAGING_MBOX_ADDR MSR, which maps to a set of 32-bit registers. Prepare staging with the following steps: 1. Ensure the microcode image is 32-bit aligned to match the MMIO register size. 2. Identify each MMIO interface based on its per-package scope. 3. Invoke the staging function for each identified interface, which will be implemented separately. [ bp: Improve error logging. ] Suggested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Tony Luck <tony.luck@intel.com> Tested-by: Anselm Busse <abusse@amazon.de> Link: https://lore.kernel.org/all/871pznq229.ffs@tglx
1 parent 7cdda85 commit 740144b

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

arch/x86/include/asm/msr-index.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,8 @@
12261226
#define MSR_IA32_VMX_VMFUNC 0x00000491
12271227
#define MSR_IA32_VMX_PROCBASED_CTLS3 0x00000492
12281228

1229+
#define MSR_IA32_MCU_STAGING_MBOX_ADDR 0x000007a5
1230+
12291231
/* Resctrl MSRs: */
12301232
/* - Intel: */
12311233
#define MSR_IA32_L3_QOS_CFG 0xc81

arch/x86/kernel/cpu/microcode/intel.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,56 @@ static __init struct microcode_intel *scan_microcode(void *data, size_t size,
299299
return size ? NULL : patch;
300300
}
301301

302+
/*
303+
* Handle the staging process using the mailbox MMIO interface.
304+
* Return 0 on success or an error code on failure.
305+
*/
306+
static int do_stage(u64 mmio_pa)
307+
{
308+
pr_debug_once("Staging implementation is pending.\n");
309+
return -EPROTONOSUPPORT;
310+
}
311+
312+
static void stage_microcode(void)
313+
{
314+
unsigned int pkg_id = UINT_MAX;
315+
int cpu, err;
316+
u64 mmio_pa;
317+
318+
if (!IS_ALIGNED(get_totalsize(&ucode_patch_late->hdr), sizeof(u32))) {
319+
pr_err("Microcode image 32-bit misaligned (0x%x), staging failed.\n",
320+
get_totalsize(&ucode_patch_late->hdr));
321+
return;
322+
}
323+
324+
lockdep_assert_cpus_held();
325+
326+
/*
327+
* The MMIO address is unique per package, and all the SMT
328+
* primary threads are online here. Find each MMIO space by
329+
* their package IDs to avoid duplicate staging.
330+
*/
331+
for_each_cpu(cpu, cpu_primary_thread_mask) {
332+
if (topology_logical_package_id(cpu) == pkg_id)
333+
continue;
334+
335+
pkg_id = topology_logical_package_id(cpu);
336+
337+
err = rdmsrq_on_cpu(cpu, MSR_IA32_MCU_STAGING_MBOX_ADDR, &mmio_pa);
338+
if (WARN_ON_ONCE(err))
339+
return;
340+
341+
err = do_stage(mmio_pa);
342+
if (err) {
343+
pr_err("Error: staging failed (%d) for CPU%d at package %u.\n",
344+
err, cpu, pkg_id);
345+
return;
346+
}
347+
}
348+
349+
pr_info("Staging of patch revision 0x%x succeeded.\n", ucode_patch_late->hdr.rev);
350+
}
351+
302352
static enum ucode_state __apply_microcode(struct ucode_cpu_info *uci,
303353
struct microcode_intel *mc,
304354
u32 *cur_rev)
@@ -627,6 +677,7 @@ static struct microcode_ops microcode_intel_ops = {
627677
.collect_cpu_info = collect_cpu_info,
628678
.apply_microcode = apply_microcode_late,
629679
.finalize_late_load = finalize_late_load,
680+
.stage_microcode = stage_microcode,
630681
.use_nmi = IS_ENABLED(CONFIG_X86_64),
631682
};
632683

0 commit comments

Comments
 (0)