[PATCH v2 5/7] x86/microcode/intel: Select the lowest revision for incremental loading
From: Chang S. Bae
Date: Mon Nov 16 2026 - 12:13:44 EST
The incremental loading logic in the core can repeatedly request a
microcode patch. The vendor parser currently selects the highest loadable
revision, which means no further patch can be selected after the first
update.
To load a concatenated multi-blob image incrementally, adjust the blob
parser to select the lowest loadable revision. This allows patches to be
applied in ascending revision order.
The legacy selection logic stays the same if incremental-loading isn't
configured.
Signed-off-by: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
---
V1 -> V2: Simplify the code a bit and massage code comment
---
arch/x86/kernel/cpu/microcode/core.c | 2 +-
arch/x86/kernel/cpu/microcode/intel.c | 25 +++++++++++++++++++++---
arch/x86/kernel/cpu/microcode/internal.h | 1 +
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index a5f6949e0d53..5c4922031d91 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -47,7 +47,7 @@ static struct microcode_ops *microcode_ops;
static bool dis_ucode_ldr;
bool force_minrev = IS_ENABLED(CONFIG_MICROCODE_LATE_FORCE_MINREV);
-static bool incremental_loading = IS_ENABLED(CONFIG_MICROCODE_LATE_INCREMENTAL_LOADING);
+bool incremental_loading = IS_ENABLED(CONFIG_MICROCODE_LATE_INCREMENTAL_LOADING);
/*
* Those below should be behind CONFIG_MICROCODE_DBG ifdeffery but in
diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
index 9f09d388ed20..74c2d014efa0 100644
--- a/arch/x86/kernel/cpu/microcode/intel.c
+++ b/arch/x86/kernel/cpu/microcode/intel.c
@@ -851,14 +851,32 @@ static bool ucode_validate_minrev(struct microcode_header_intel *mc_header)
return true;
}
+static bool is_revision_candidate(unsigned int cur_rev, unsigned int rev)
+{
+ /*
+ * A revision must be newer than the active microcode revision to be
+ * loadable.
+ */
+ if (rev <= boot_cpu_data.microcode)
+ return false;
+
+ return incremental_loading ? rev < cur_rev : rev > cur_rev;
+}
+
static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter)
{
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
+ unsigned int cur_rev, curr_mc_size = 0;
bool is_safe, new_is_safe = false;
- int cur_rev = uci->cpu_sig.rev;
- unsigned int curr_mc_size = 0;
u8 *new_mc = NULL, *mc = NULL;
+ /*
+ * Start from the boundary value for the revision search. With
+ * incremental loading, the search walks downward, while the legacy
+ * search walks upward.
+ */
+ cur_rev = incremental_loading ? UINT_MAX : 0;
+
while (iov_iter_count(iter)) {
struct microcode_header_intel mc_header;
unsigned int mc_size, data_size;
@@ -895,7 +913,7 @@ static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter)
intel_microcode_sanity_check(mc, true, MC_HEADER_TYPE_MICROCODE) < 0)
goto fail;
- if (cur_rev >= mc_header.rev)
+ if (!is_revision_candidate(cur_rev, mc_header.rev))
continue;
if (!intel_find_matching_signature(mc, &uci->cpu_sig))
@@ -999,6 +1017,7 @@ static struct microcode_ops microcode_intel_ops = {
.finalize_late_load = finalize_late_load,
.stage_microcode = stage_microcode,
.use_nmi = IS_ENABLED(CONFIG_X86_64),
+ .support_incremental = true,
};
static __init void calc_llc_size_per_core(struct cpuinfo_x86 *c)
diff --git a/arch/x86/kernel/cpu/microcode/internal.h b/arch/x86/kernel/cpu/microcode/internal.h
index ebf079e60c33..246aac4a11bc 100644
--- a/arch/x86/kernel/cpu/microcode/internal.h
+++ b/arch/x86/kernel/cpu/microcode/internal.h
@@ -101,6 +101,7 @@ static inline unsigned int x86_cpuid_family(void)
}
extern bool force_minrev;
+extern bool incremental_loading;
#ifdef CONFIG_CPU_SUP_AMD
void load_ucode_amd_bsp(struct early_load_data *ed, unsigned int family);
--
2.53.0