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 4/7] x86/microcode: Introduce incremental late loading
Date: Mon, 16 Nov 2026 16:45:45 +0000	[thread overview]
Message-ID: <20261116164548.900486-5-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20261116164548.900486-1-chang.seok.bae@intel.com>

The minimum revision requirement was introduced to handle dependencies
between microcode revisions. On the other hand, Intel has traditionally
distributed only the latest microcode blob in the repository [1].

Concatenating the dependent blobs into a single image may allow loading
the prerequisite revisions in sequence. The loader, however, currently
picks the highest revision from a multi-blob image, so it may skip the
minimum revision requirement.

If enforced, it skips revisions whose prerequisites have not been loaded,
possibly leaving the loading process at an intermediate revision. Then,
admins have to manually trigger another load to apply the remaining
higher revisions.

To avoid this manual step, introduce incremental late loading. After each
successful update, let the vendor-specific parser select the next blob.
If the parser selects the lowest loadable revision on each pass, the
loader can apply the blobs incrementally until no more blobs are
available.

For now, rejects this loading as the vendor-side blob parser is not ready
yet to support incremental blob selection.

To retain the existing behavior by default, provide a Kconfig option and
a kernel command-line option.

[1] https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files.git

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
---
V1 -> V2:
 * Rename to incremental loading
 * Reset incremental_loading=false if not supported
---
 .../admin-guide/kernel-parameters.txt         |  4 ++
 arch/x86/Kconfig                              | 13 +++++
 arch/x86/kernel/cpu/microcode/core.c          | 58 ++++++++++++++++++-
 arch/x86/kernel/cpu/microcode/internal.h      |  7 ++-
 4 files changed, 76 insertions(+), 6 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index a6d50cf6435c..af0630466dcc 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -4091,6 +4091,10 @@ Kernel parameters
 			for the runtime microcode loader according to <bool>. If
 			<bool> is not given, enable the enforcement.
 
+			incremental_loading=<bool>:
+			Enable or disable incremental microcode late loading
+			according to <bool>.
+
 	mitigations=
 			[X86,PPC,S390,ARM64,EARLY] Control optional mitigations for
 			CPU vulnerabilities.  This is a set of curated,
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 58dce0b66179..3ead806c9de2 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1353,6 +1353,19 @@ config MICROCODE_LATE_FORCE_MINREV
 
 	  If unsure say Y.
 
+config MICROCODE_LATE_INCREMENTAL_LOADING
+	bool "Incremental microcode late loading"
+	default n
+	depends on MICROCODE_LATE_LOADING
+	depends on CPU_SUP_INTEL
+	help
+	  Apply the microcode blobs in a concatenated image one at a time, in
+	  ascending revision order, so that revisions with prerequisites can be
+	  applied in a single load.
+
+	  This loading option can also be controlled via the
+	  "microcode=incremental_loading=" parameter on the kernel command line.
+
 config MICROCODE_DBG
 	bool "Enable microcode loader debugging"
 	default n
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index ed1eb6b753d6..a5f6949e0d53 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -47,6 +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);
 
 /*
  * Those below should be behind CONFIG_MICROCODE_DBG ifdeffery but in
@@ -166,6 +167,12 @@ static void __init early_parse_cmdline(void)
 				continue;
 			}
 
+			if (str_has_prefix(s, "incremental_loading=")) {
+				advance_option_argument(&s);
+				if (kstrtobool(s, &incremental_loading)) { ; }
+				continue;
+			}
+
 			if (!strcmp(s, "dis_ucode_ldr"))
 				dis_ucode_ldr = true;
 		}
@@ -750,16 +757,34 @@ static bool setup_cpus(void)
 	return true;
 }
 
+static void reset_ucode_ctrl(void)
+{
+	struct microcode_ctrl ctrl = { .ctrl = SCTRL_WAIT, .result = -1, };
+	unsigned int cpu;
+
+	for_each_cpu_and(cpu, cpu_present_mask, &cpus_booted_once_mask) {
+		ctrl.ctrl_cpu = per_cpu(ucode_ctrl.ctrl_cpu, cpu);
+		per_cpu(ucode_ctrl, cpu) = ctrl;
+	}
+}
+
 static int load_late_locked(void)
 {
+	enum ucode_state state;
+	int err;
+
 	if (!setup_cpus())
 		return -EBUSY;
 
-	switch (microcode_ops->request_microcode_fw(0, &microcode_fdev->dev)) {
+	state = microcode_ops->request_microcode_fw(0, &microcode_fdev->dev);
+next:
+	switch (state) {
 	case UCODE_NEW:
-		return load_late_stop_cpus(false);
+		err = load_late_stop_cpus(false);
+		break;
 	case UCODE_NEW_SAFE:
-		return load_late_stop_cpus(true);
+		err = load_late_stop_cpus(true);
+		break;
 	case UCODE_NFOUND:
 		return -ENOENT;
 	case UCODE_OK:
@@ -767,6 +792,28 @@ static int load_late_locked(void)
 	default:
 		return -EBADFD;
 	}
+
+	if (err)
+		return err;
+
+	/*
+	 * A multi-blob image is traditionally handled by selecting the highest
+	 * revision to load it in one shot. With incremental loading, the
+	 * vendor-specific parser instead selects the lowest loadable revision.
+	 *
+	 * After each successful update, find the next loadable blob to continue
+	 * the iteration. Stop if no more blobs are found.
+	 */
+	if (incremental_loading) {
+		state = microcode_ops->request_microcode_fw(0, &microcode_fdev->dev);
+		if (state == UCODE_NFOUND)
+			return 0;
+
+		reset_ucode_ctrl();
+		goto next;
+	}
+
+	return 0;
 }
 
 static ssize_t reload_store(struct device *dev,
@@ -915,6 +962,11 @@ static int __init microcode_init(void)
 	if (early_data.new_rev)
 		pr_info_once("Updated early from: 0x%08x\n", early_data.old_rev);
 
+	if (incremental_loading && !microcode_ops->support_incremental) {
+		pr_warn("Incremental late loading not supported, disabling\n");
+		incremental_loading = false;
+	}
+
 	microcode_fdev = faux_device_create("microcode", NULL, NULL);
 	if (!microcode_fdev)
 		return -ENODEV;
diff --git a/arch/x86/kernel/cpu/microcode/internal.h b/arch/x86/kernel/cpu/microcode/internal.h
index a10b547eda1e..ebf079e60c33 100644
--- a/arch/x86/kernel/cpu/microcode/internal.h
+++ b/arch/x86/kernel/cpu/microcode/internal.h
@@ -34,9 +34,10 @@ struct microcode_ops {
 	void			(*stage_microcode)(void);
 	int			(*collect_cpu_info)(int cpu, struct cpu_signature *csig);
 	void			(*finalize_late_load)(int result);
-	unsigned int		nmi_safe	: 1,
-				use_nmi		: 1,
-				use_staging	: 1;
+	unsigned int		nmi_safe	    : 1,
+				use_nmi		    : 1,
+				use_staging	    : 1,
+				support_incremental : 1;
 };
 
 struct early_load_data {
-- 
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 ` Chang S. Bae [this message]
2026-11-16 16:45 ` [PATCH v2 5/7] x86/microcode/intel: Select the lowest revision for incremental loading Chang S. Bae
2026-11-16 16:45 ` [PATCH RFC v2 6/7] x86/microcode: Decouple minimum revision check from late loading 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-5-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®