x86/microcode: Check if any new features are present after a microcode reload.
Subsystems (2)
PATCH 1/1 x86/microcode: Check if any new features are present after a microcode reload.
When microcode is loaded later after system boot, new microcode could enumerate new features. It might not be possible to use these new features unless they are loaded during early boot via initrd or from the BIOS in some cases.
This patch attempts to simply check if there are any differences in feature set and warns user to use early microcode load before using the new features.
--- arch/x86/kernel/cpu/microcode/intel.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/microcode/intel.c +10 -3
@@ -39,6 +39,7 @@#include <asm/tlbflush.h> #include <asm/setup.h> #include <asm/msr.h> +#include "../kernel/cpu/cpu.h" /* get_cpu_cap() */ static const char ucode_path[] ="kernel/x86/microcode/GenuineIntel.bin" ;
@@ -776,7 +777,7 @@ static int apply_microcode_intel(int cpu) {struct microcode_intel *mc;struct ucode_cpu_info *uci; -struct cpuinfo_x86 *c; +struct cpuinfo_x86 *c, new_cpuinfo;static int prev_rev;u32 rev;
@@ -804,17 +805,23 @@ static int apply_microcode_intel(int cpu)return -1 ; } + c = &cpu_data (cpu);if (rev != prev_rev) {pr_info ("updated to revision 0x%x, date = %04x-%02x-%02x\n" , rev, mc->hdr.date &0xffff , mc->hdr.date >>24 , (mc->hdr.date >>16 ) &0xff ); +memset (&new_cpuinfo,0 ,sizeof (struct cpuinfo_x86 )); +get_cpu_cap (&new_cpuinfo); +if (memcmp (&c->x86_capability, &new_cpuinfo.x86_capability, +sizeof (new_cpuinfo.x86_capability))) { +pr_warn_once ("New features found in loaded microcode, but will be ignored\n" ); +pr_warn_once ("Please consider either early loading through initrd/built-in or a potential BIOS update.\n" ); + } prev_rev = rev; } - c = &cpu_data (cpu); - uci->cpu_sig.rev = rev; c->microcode = rev;
Signature · 1 line
2.7.4
Borislav Petkov
maintainerQuoted 50 lines · Ashok Raj
When microcode is loaded later after system boot, new microcode could enumerate new features. It might not be possible to use these new features unless they are loaded during early boot via initrd or from the BIOS in some cases.
This patch attempts to simply check if there are any differences in feature set and warns user to use early microcode load before using the new features.
Suggested-by Andi Kleen <[email protected]>Signed-off-by Ashok Raj <[email protected]>Cc Thomas Gleixner <[email protected]>Cc David Woodhouse <[email protected]>Cc Arjan van de Ven <[email protected]>Cc Dave Hansen <[email protected]>Cc Tony Luck <[email protected]>Cc Tim Chen <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Borislav Petkov <[email protected]>--- arch/x86/kernel/cpu/microcode/intel.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)arch/x86/kernel/cpu/microcode/intel.c +3
-1@@ -39,6 +39,7 @@#include <asm/tlbflush.h> #include <asm/setup.h> #include <asm/msr.h> +#include "../kernel/cpu/cpu.h" /* get_cpu_cap() */ static const char ucode_path[] ="kernel/x86/microcode/GenuineIntel.bin" ;@@ -776,7 +777,7 @@ static int apply_microcode_intel(int cpu) {struct microcode_intel *mc;struct ucode_cpu_info *uci; -struct cpuinfo_x86 *c; +struct cpuinfo_x86 *c, new_cpuinfo;static int prev_rev;u32 rev;@@ -804,17 +805,23 @@ static int apply_microcode_intel(int cpu)return -1 ; } + c = &cpu_data (cpu);if (rev != prev_rev) { pr_info("updated to revision 0x%x, date = %04x-%02x-%02x\n", rev,
arch/x86/kernel/cpu/microcode/intel.c static int apply_microcode_intel(int cpu) · line 821
Quoted 10 lines
arch/x86/kernel/cpu/microcode/intel.c +7
-0mc->hdr.date &0xffff , mc->hdr.date >>24 , (mc->hdr.date >> 16) & 0xff); +memset (&new_cpuinfo,0 ,sizeof (struct cpuinfo_x86 )); +get_cpu_cap (&new_cpuinfo); +if (memcmp (&c->x86_capability, &new_cpuinfo.x86_capability, +sizeof (new_cpuinfo.x86_capability))) { +pr_warn_once ("New features found in loaded microcode, but will be ignored\n" ); +pr_warn_once ("Please consider either early loading through initrd/built-in or a potential BIOS update.\n" ); + }
A bunch of notes about this:
1. this checking happens per-CPU. Instead, it should happen per CPU until the first CPU which encounters a CPUID bit change, prints the warning and then doesn't do it anymore. I'm going to also heavily assume this will happen immediately on the BSP and we simply forget all heterogeneous BSP/AP configurations which are simply bollocks.
2. the part until memcmp() needs to be a generic function in cpu/common.c or so which gets called by the microcode loader. This will facilitate doing 1. too.
3. (2) needs to happen in the generic microcode driver - arch/x86/kernel/cpu/microcode/core.c - not in intel.c For that to happen, you need a prepatch which changes the ->apply_microcode() functions to return a new value UCODE_UPDATED when the late update succeeds in the vendor driver.
In the UCODE_UPDATED case, you call the common.c function which checks whether it has ran already and if not, gets caps, checks and prints. If it has, you don't need to do anything.
And those three changes sound like three nicely separated patches to me.
Anyway, something along those lines...
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.