mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, hpa@zytor.com,
	andrew.cooper3@citrix.com, arjan.van.de.ven@intel.com,
	chang.seok.bae@intel.com
Subject: [PATCH v2 5/7] x86/microcode/intel: Select the lowest revision for incremental loading
Date: Mon, 16 Nov 2026 16:45:46 +0000	[thread overview]
Message-ID: <20261116164548.900486-6-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20261116164548.900486-1-chang.seok.bae@intel.com>

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@intel.com>
---
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


  parent reply	other threads:[~2026-11-16 17:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:45 [PATCH v2 0/7] x86/microcode: Incremental Loading and Early Minimum Revision Check Chang S. Bae
2026-11-16 16:45 ` [PATCH v2 1/7] x86/microcode: Avoid spurious base_rev= match Chang S. Bae
2026-11-16 16:45 ` [PATCH v2 2/7] x86/microcode: Accept a boolean for force_minrev parameter Chang S. Bae
2026-11-16 16:45 ` [PATCH v2 3/7] x86/microcode: Mark early_data __initdata Chang S. Bae
2026-11-16 16:45 ` [PATCH v2 4/7] x86/microcode: Introduce incremental late loading Chang S. Bae
2026-11-16 16:45 ` Chang S. Bae [this message]
2026-11-16 16:45 ` [PATCH RFC v2 6/7] x86/microcode: Decouple minimum revision check from " Chang S. Bae
2026-11-16 16:45 ` [PATCH RFC v2 7/7] x86/microcode/intel: Apply minimum revision check to early loading Chang S. Bae

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116164548.900486-6-chang.seok.bae@intel.com \
    --to=chang.seok.bae@intel.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=arjan.van.de.ven@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®