x86/microcode: Incremental Loading and Early Minimum Revision Check
Subsystems (4)
v2 cover x86/microcode: Incremental Loading and Early Minimum Revision Check
Hi all,
This series came up with the microcode loading issues [1] previously. The immediate fix, which prevents problematic blobs from being loaded, has been merged to the mainline and backported to stable trees. This revision follows up with two longer-term solutions addressing the underlying issues.
First, let me summarize the changes since the previous posting [2] in parts:
Part 1, patch 1-3: Preparatory fixes
* Only minor updates to changelogs and patch subjects.
Part 2, patch 4-5: Late-loading - incremental Loading
* Rename the approach to "incremental loading" to better describe the intention of advancing revisions through multiple updates.
* Move this part ahead of the early minimum revision check, since the check now recommends incremental loading when fails.
Part 3, patch 6-7: Early-loading - early minimum revision check
* Keep this part in RFC status for now, as the resulting tainting behavior wants more reviews
* Do not extend force_minrev to early loading, since doing so would reject all early loadings on AMD systems.
Below is more detail about the longer-term solutions, largely carried from the previous posting [2].
1. Incremental Late Loading
Looking at Intel microcode releases [3], the repository traditionally provides the latest blob. When updating from an older revision, admins may need to retrieve prerequisite older revisions from the git history. This can be inefficient and error-prone.
Intel will now concatenate prerequisite older blobs with the latest blob together into a multi-blob image. The kernel, however, currently selects the highest loadable revision, or at best one prerequisite when the minimum revision check is enforced. Admins may need to trigger multiple loads manually.
Instead the kernel loader can facilitate iterative loading to apply the available blobs incrementally. There are some possible ways to implement this:
(1) One is to rely on the minimum revision check and select the highest revision whose prerequisite has been loaded already.
(2) Another is to load the blobs sequentially according to the order in the image.
Both approaches have drawbacks: (1) depends on the minimum revision information being correct, while (2) is sensitive to blob ordering.
The approach here selects the lowest loadable revision on each iteration, so that the blobs to be applied incrementally (patch 4-5).
2. Early Minimum Revision Check
The minimum revision information can serve as a more general revision dependency check, rather than being limited to runtime changes. This part extends the minimum revision check to early loading (patch 6-7).
Although the implementation itself isn't complex, there are some user-visible consequences:
* For Intel, early loading of older patches without minimum revision information would result in kernel tainting.
* For AMD, the absence of the field could result in tainting _every_ successful update unless explicitly treating AMD patches as safe. To me, it is unclear whether the absence of this field reflects a lack of such dependencies or simply a difference in the vendor's microcode format.
* Another consideration is force_minrev. Extending it to early loading would reject all early loading on AMD systems, equivalent to disabling the loader entirely. Since the existing build-time and command-line option descriptions are specific to late loading, I have kept its semantics unchanged.
For now, I'm keeping this part as RFC material. Depending on the feedback, the series could move forward with a smaller series, leaving this part to follow after landing part1/2.
The patch set is available in this repository:
git://github.com/intel-staging/microcode.git incr-loading-and-early-minrev-v2
Thanks,
Chang
[1] GNR98. MCE When Early OS Microcode Update to MCU 0x1000405 Release or Later
[2] https://lore.kernel.org/lkml/[email protected]
[3] https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files.git
Chang S. Bae (7):
x86/microcode: Avoid spurious base_rev= match x86/microcode: Accept a boolean for force_minrev parameter x86/microcode: Mark early_data __initdata x86/microcode: Introduce incremental late loading x86/microcode/intel: Select the lowest revision for incremental
loading
x86/microcode: Decouple minimum revision check from late loading x86/microcode/intel: Apply minimum revision check to early loading
.../admin-guide/kernel-parameters.txt | 11 ++- arch/x86/Kconfig | 13 +++ arch/x86/kernel/cpu/microcode/core.c | 91 ++++++++++++++++--- arch/x86/kernel/cpu/microcode/intel.c | 63 ++++++++----- arch/x86/kernel/cpu/microcode/internal.h | 9 +- 5 files changed, 147 insertions(+), 40 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
Signature · 1 line
2.53.0
PATCH v2 1/7 x86/microcode: Avoid spurious base_rev= match
After base_rev= has been parsed, the remainder of the token is still compared against the other option names. Along with this, the substring check strstr() may also produce a spurious match.
Move on to the next token once the option has been parsed, and use str_has_prefix() instead.
---
V1 -> V2: Clarify the subject
--- arch/x86/kernel/cpu/microcode/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/core.c +2 -1
@@ -146,10 +146,11 @@ static void __init early_parse_cmdline(void)if (cmdline_find_option (boot_command_line,"microcode" , cmd_buf,sizeof (cmd_buf)) >0 ) {while ((s =strsep (&p,"," ))) {if (IS_ENABLED (CONFIG_MICROCODE_DBG )) { -if (strstr (s,"base_rev=" )) { +if (str_has_prefix (s,"base_rev=" )) {/* advance to the option arg */ strsep (&s,"=" );if (kstrtouint (s,16 , &base_rev)) { ; } +continue ; } }
Signature · 1 line
2.53.0
PATCH v2 2/7 x86/microcode: Accept a boolean for force_minrev parameter
In reply to Chang S. BaeThe microcode= command-line option allows controlling all microcode loading options. However, force_minrev can only enable minimum revision enforcement, not disable it.
The previous microcode.force_minrev= option accepted both boolean values, and the current behavior differs from the documentation in kernel-parameters.txt.
Add force_minrev= as a sub-option to explicitly enable or disable the minimum revision enforcement. Update the documentation accordingly.
While doing so, wrap strsep() in a descriptively named helper.
--- Documentation/admin-guide/kernel-parameters.txt | 7 ++++--- arch/x86/kernel/cpu/microcode/core.c | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -3
@@ -4086,9 +4086,10 @@ Kernel parameters dis_ucode_ldr: disable the microcode loader - force_minrev: - Enable or disable the microcode minimal revision - enforcement for the runtime microcode loader. + force_minrev[=<bool>]: + Enable or disable microcode minimal revision enforcement + for the runtime microcode loader according to <bool>. If + <bool> is not given, enable the enforcement. mitigations= [X86,PPC,S390,ARM64,EARLY] Control optional mitigations for
arch/x86/kernel/cpu/microcode/core.c +12 -3
@@ -138,6 +138,11 @@ bool __init microcode_loader_disabled(void)return dis_ucode_ldr; } +static inline void advance_option_argument (char **s) +{ +strsep (s,"=" ); +} +static void __init early_parse_cmdline (void ) {char cmd_buf[64 ] = {};
@@ -147,15 +152,19 @@ static void __init early_parse_cmdline(void)while ((s =strsep (&p,"," ))) {if (IS_ENABLED (CONFIG_MICROCODE_DBG )) {if (str_has_prefix (s,"base_rev=" )) { -/* advance to the option arg */ -strsep (&s,"=" ); +advance_option_argument (&s);if (kstrtouint (s,16 , &base_rev)) { ; }continue ; } } -if (!strcmp ("force_minrev" , s)) +if (!strcmp ("force_minrev" , s)) { force_minrev = true; + }else if (str_has_prefix (s,"force_minrev=" )) { +advance_option_argument (&s); +if (kstrtobool (s, &force_minrev)) { ; } +continue ; + }if (!strcmp (s,"dis_ucode_ldr" )) dis_ucode_ldr = true;
Signature · 1 line
2.53.0
PATCH v2 3/7 x86/microcode: Mark early_data __initdata
In reply to Chang S. Baeearly_data records the revisions seen during early loading, and microcode_init() is its last reader.
Mark the storage reclaimable afterwards.
--- arch/x86/kernel/cpu/microcode/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/microcode/core.c +1 -1
@@ -83,7 +83,7 @@ static u32 final_levels[] = { 0, /* T-101 terminator */ }; -struct early_load_data early_data; +struct early_load_data early_data__initdata ;/* * Check the current patch level on this CPU.
Signature · 1 line
2.53.0
PATCH v2 4/7 x86/microcode: Introduce incremental late loading
In reply to Chang S. BaeThe 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
---
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(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
@@ -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,
arch/x86/Kconfig +13 -0
@@ -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
arch/x86/kernel/cpu/microcode/core.c +55 -3
95 lines not on this page · raw message
arch/x86/kernel/cpu/microcode/internal.h +4 -3
@@ -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 {
Signature · 1 line
2.53.0
PATCH v2 5/7 x86/microcode/intel: Select the lowest revision for incremental loading
In reply to Chang S. BaeThe 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.
---
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(-)
arch/x86/kernel/cpu/microcode/core.c +1 -1
@@ -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
arch/x86/kernel/cpu/microcode/intel.c +22 -3
@@ -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)
arch/x86/kernel/cpu/microcode/internal.h +1 -0
@@ -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);
Signature · 1 line
2.53.0
RFC PATCH v2 6/7 x86/microcode: Decouple minimum revision check from late loading
In reply to Chang S. BaeThe microcode minimum revision check was originally introduced to express dependencies involving OS-visible changes, thus it has been limited to the late-load path.
In fact this can serve as a general guard against unsafe microcode loading. Make the check independent of the loading path in preparation for applying it to the early path as well.
For early-loading, establish a tracker to check whether an update satisfies the minimum revision requirement and taint the kernel if not.
Right now, no vendor code implements the check, so every early load taints the kernel.
Then, adjust the failure messages to suggest incremental updates, rather than early-loading, as a solution to address revision dependencies.
Keep the existing force_minrev semantics unchanged; it continues to apply only to late-loading.
---
V1 -> V2:
* Do not apply force_minrev to early loading; keep the current semantics
* Move after incremental-loading support
* Massage changelog
--- arch/x86/kernel/cpu/microcode/core.c | 13 ++++++++++--- arch/x86/kernel/cpu/microcode/intel.c | 7 +++---- arch/x86/kernel/cpu/microcode/internal.h | 1 + 3 files changed, 14 insertions(+), 7 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +10 -3
@@ -609,8 +609,8 @@ static int load_late_stop_cpus(bool is_safe)struct cpuinfo_x86 prev_info;if (!is_safe) { -pr_err ("Late microcode loading without minimal revision check.\n" ); -pr_err ("You should switch to early loading, if possible.\n" ); +pr_err ("Late microcode loading without minimum revision check.\n" ); +pr_err ("You should update microcode incrementally.\n" ); }/*
@@ -959,9 +959,16 @@ static int __init microcode_init(void)pr_info_once ("Current revision: 0x%08x\n" , (early_data.new_rev ?: early_data.old_rev)); -if (early_data.new_rev) +if (early_data.new_rev) {pr_info_once ("Updated early from: 0x%08x\n" , early_data.old_rev); +if (!early_data.is_safe) { +pr_err ("Early microcode loading without minimum revision check.\n" ); +pr_err ("You should update microcode incrementally.\n" ); +add_taint (TAINT_CPU_OUT_OF_SPEC ,LOCKDEP_STILL_OK ); + } + } +if (incremental_loading && !microcode_ops->support_incremental) {pr_warn ("Incremental late loading not supported, disabling\n" ); incremental_loading = false;
arch/x86/kernel/cpu/microcode/intel.c +3 -4
@@ -830,9 +830,8 @@ static bool ucode_validate_minrev(struct microcode_header_intel *mc_header)int cur_rev = boot_cpu_data.microcode;/* -* When late-loading, ensure the header declares a minimum revision -* required to perform a late-load. The previously reserved field -* is 0 in older microcode blobs. +* Ensure the header declares a minimum revision required to perform a +* load. The previously reserved field is 0 in older microcode blobs. */ if (!mc_header->min_req_ver) {pr_info ("Unsafe microcode update: Microcode header does not specify a required min version\n" );
@@ -845,7 +844,7 @@ static bool ucode_validate_minrev(struct microcode_header_intel *mc_header)*/ if (cur_rev < mc_header->min_req_ver) {pr_info ("Unsafe microcode update: Current revision 0x%x too old\n" , cur_rev); -pr_info ("Current should be at 0x%x or higher. Use early loading instead\n" , mc_header->min_req_ver); +pr_info ("Current should be at 0x%x or higher. Update incrementally.\n" , mc_header->min_req_ver);return false; }return true;
arch/x86/kernel/cpu/microcode/internal.h +1 -0
@@ -43,6 +43,7 @@ struct microcode_ops {struct early_load_data {u32 old_rev;u32 new_rev; +bool is_safe; };extern struct early_load_data early_data;
Signature · 1 line
2.53.0
RFC PATCH v2 7/7 x86/microcode/intel: Apply minimum revision check to early loading
In reply to Chang S. BaeThe minimum revision check is now generally applicable. Establish the minimum revision check on early loading. Load the patch but taint the kernel when the check fails.
Adjust the check function so that the early path can pass the current revision.
---
V1 -> V2: Drop force_minrev support
--- arch/x86/kernel/cpu/microcode/intel.c | 51 +++++++++++++-------------- 1 file changed, 25 insertions(+), 26 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +25 -26
@@ -766,6 +766,29 @@ static int __init save_builtin_microcode(void) }early_initcall (save_builtin_microcode); +static bool ucode_validate_minrev (u32 cur_rev,struct microcode_header_intel *mc_header) +{ +/* +* Ensure the header declares a minimum revision required to perform a +* load. The previously reserved field is 0 in older microcode blobs. +*/ +if (!mc_header->min_req_ver) { +pr_info ("Unsafe microcode update: Microcode header does not specify a required min version\n" ); +return false; + } + +/* +* Check whether the current revision is either greater or equal to +* the minimum revision specified in the header. +*/ +if (cur_rev < mc_header->min_req_ver) { +pr_info ("Unsafe microcode update: Current revision 0x%x too old.\n" , cur_rev); +pr_info ("Current should be at 0x%x or higher. Update incrementally.\n" , mc_header->min_req_ver); +return false; + } +return true; +} +/* Load microcode on BSP from initrd or builtin blobs */ void __init load_ucode_intel_bsp (struct early_load_data *ed) {
@@ -777,6 +800,7 @@ void __init load_ucode_intel_bsp(struct early_load_data *ed)if (uci.mc &&apply_microcode_early (&uci) ==UCODE_UPDATED ) { ucode_patch_va =UCODE_BSP_LOADED ; ed->new_rev = uci.cpu_sig.rev; + ed->is_safe =ucode_validate_minrev (ed->old_rev, uci.mc); } }
@@ -825,31 +849,6 @@ static enum ucode_state apply_microcode_late(int cpu)return ret; } -static bool ucode_validate_minrev (struct microcode_header_intel *mc_header) -{ -int cur_rev = boot_cpu_data.microcode; - -/* -* Ensure the header declares a minimum revision required to perform a -* load. The previously reserved field is 0 in older microcode blobs. -*/ -if (!mc_header->min_req_ver) { -pr_info ("Unsafe microcode update: Microcode header does not specify a required min version\n" ); -return false; - } - -/* -* Check whether the current revision is either greater or equal to -* to the minimum revision specified in the header. -*/ -if (cur_rev < mc_header->min_req_ver) { -pr_info ("Unsafe microcode update: Current revision 0x%x too old\n" , cur_rev); -pr_info ("Current should be at 0x%x or higher. Update incrementally.\n" , mc_header->min_req_ver); -return false; - } -return true; -} -static bool is_revision_candidate (unsigned int cur_rev,unsigned int rev) {/*
@@ -921,7 +920,7 @@ static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter)if (!revision_is_safe (&uci->cpu_sig, mc_header.rev))continue ; - is_safe =ucode_validate_minrev (&mc_header); + is_safe =ucode_validate_minrev (uci->cpu_sig.rev, &mc_header);if (force_minrev && !is_safe)continue ;
Signature · 1 line
2.53.0