Scan initramfs for microcode cpio archive. (v1)
RFC PATCH 1/1 Scan initramfs for microcode cpio archive. (v1)
Greetings,
Please see the following patch which implements a mechanism to scan the initramfs for the format of an microcode files. This is a feature that the Linux kernel has since v3.10 - where it searches in the initramfs for an archive of the microcode blob. The format is documented in the Linux tree and the commit description contains it.
The tool to make this work is the initramfs creator. The author has provided an RFC patch: http://article.gmane.org/gmane.linux.kernel.initramfs/3318
which does that.
That, along with this patch, allows the Xen hypervisor to update the microcode during bootup. Please review attached RFC patch.
docs/misc/xen-command-line.markdown | 12 +++ xen/arch/x86/microcode.c | 160 ++++++++++++++++++++++++++++++++--- xen/common/Makefile | 2 +- xen/common/earlycpio.c | 151 +++++++++++++++++++++++++++++++++ xen/include/xen/earlycpio.h | 15 +++ 5 files changed, 326 insertions(+), 14 deletions(-)
Konrad Rzeszutek Wilk (1):
microcode: Scan the initramfs payload for microcode blob.
RFC PATCH 1/1 microcode: Scan the initramfs payload for microcode blob.
The Linux kernel is able to update the microcode during early bootup via inspection of the initramfs blob to see if there is an cpio image with certain microcode files. This is nicely documented in Linux's Documentation/x86/early-microcode.txt:
Early load microcode
====================
By Fenghua Yu <[email protected]>
Kernel can update microcode in early phase of boot time. Loading microcode early can fix CPU issues before they are observed during kernel boot time.
Microcode is stored in an initrd file. The microcode is read from the initrd file and loaded to CPUs during boot time.
The format of the combined initrd image is microcode in cpio format followed by the initrd image (maybe compressed). Kernel parses the combined initrd image during boot time. The microcode file in cpio name space is:kernel/x86/microcode/GenuineIntel.bin
During BSP boot (before SMP starts), if the kernel finds the microcode file in the initrd file, it parses the microcode and saves matching microcode in memory. If matching microcode is found, it will be uploaded in BSP and later on in all APs.
The cached microcode patch is applied when CPUs resume from a sleep state.
There are two legacy user space interfaces to load microcode, either through /dev/cpu/microcode or through /sys/devices/system/cpu/microcode/reload file in sysfs.
In addition to these two legacy methods, the early loading method described here is the third method with which microcode can be uploaded to a system's CPUs.
The following example script shows how to generate a new combined initrd file in /boot/initrd-3.5.0.ucode.img with original microcode microcode.bin and original initrd image /boot/initrd-3.5.0.img.
mkdir initrd
cd initrd
mkdir kernel
mkdir kernel/x86
mkdir kernel/x86/microcode
cp ../microcode.bin kernel/x86/microcode/GenuineIntel.bin find .|cpio -oc >../ucode.cpio
cd ..
cat ucode.cpio /boot/initrd-3.5.0.img >/boot/initrd-3.5.0.ucode.img
As such this code inspects the initrd to see if the microcode signatures are present and if so updates the hypervisor.
There is also the override boolean flag: "scan_ucode" to disable this code. Also if "ucode" command line parameter is used this code turns itself off.
When this code works, the hypervisor ring buffer will have:
(XEN) microcode: CPU0 updated from revision 0x25 to 0x28, date = 2012-04-24 .. and so on for all the other CPUs.
(This is an example from a SandyBridge CPU).
--- docs/misc/xen-command-line.markdown | 12 +++ xen/arch/x86/microcode.c | 160 ++++++++++++++++++++++++++++++++--- xen/common/Makefile | 2 +- xen/common/earlycpio.c | 151 +++++++++++++++++++++++++++++++++ xen/include/xen/earlycpio.h | 15 +++ 5 files changed, 326 insertions(+), 14 deletions(-) create mode 100644 xen/common/earlycpio.c create mode 100644 xen/include/xen/earlycpio.h
docs/misc/xen-command-line.markdown +12 -0
@@ -760,6 +760,18 @@ only available on 32-bit x86 platforms. `acpi` instructs Xen to reboot the host using RESET_REG in the ACPI FADT. +### scan_ucode +> `= <boolean>` + +> Default: `true` + +Flag to globally enable or disable support for scanning the multiboot images +for an cpio image that contains microcode, which are: + on Intel: kernel/x86/microcode/GenuineIntel.bin + on AMD : kernel/x86/microcode/AuthenticAMD.bin + +Note that is 'ucode' parameter is used this option becomes disabled. + ### sched > `= credit | credit2 | sedf | arinc653`
xen/arch/x86/microcode.c +147 -13
218 lines not on this page · raw message
xen/common/Makefile +1 -1
@@ -48,7 +48,7 @@ obj-y += radix-tree.o obj-y += rbtree.o obj-y += lzo.o -obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo,$(n).init.o) +obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma unlzo,$(n).init.o earlycpio.o) obj-$(perfc) += perfc.o obj-$(crash_debug) += gdbstub.o
xen/common/earlycpio.c new file +151 -0
151 lines not on this page · raw message
xen/include/xen/earlycpio.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef _EARLYCPIO_H +#define _EARLYCPIO_H + +#define MAX_CPIO_FILE_NAME 18 + +struct cpio_data { +void *data; +size_t size; +char name[MAX_CPIO_FILE_NAME ]; +}; + +struct cpio_data find_cpio_data (const char *path,void *data,size_t len, +long *offset); + +#endif /* _EARLYCPIO_H */
Signature · 1 line
1.7.7.6
Re: [RFC PATCH v1] microcode: Scan the initramfs payload for microcode blob.
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
docs/misc/xen-command-line.markdown +2
-0@@ -760,6 +760,18 @@ only available on 32-bit x86 platforms. `acpi` instructs Xen to reboot the host using RESET_REG in the ACPI FADT. +### scan_ucode +> `= <boolean>`
docs/misc/xen-command-line.markdown only available on 32-bit x86 platforms. · line 774
Quoted 10 lines
docs/misc/xen-command-line.markdown +10
-0+ +> Default: `true` + +Flag to globally enable or disable support for scanning the multiboot images +for an cpio image that contains microcode, which are: + on Intel: kernel/x86/microcode/GenuineIntel.bin + on AMD : kernel/x86/microcode/AuthenticAMD.bin + +Note that is 'ucode' parameter is used this option becomes disabled. +
I would want this to be an extension of the "ucode=" option, not an independent new one. E.g. "ucode=initrd" or "ucode=cpio:<num>" or some such.
Quoted 22 lines
xen/arch/x86/microcode.c +10
-0@@ -39,12 +39,33 @@#include <asm/setup.h> #include <asm/microcode.h> +#include <xen/earlycpio.h> +static module_t __initdata ucode_mod;static void *(*__initdata ucode_mod_map)(const module_t *);static signed int __initdata ucode_mod_idx;static bool_t __initdata ucode_mod_forced;static cpumask_t __initdata init_mask; +/* +* If we scan the initramfs.cpio for the early microcode code +* and find it, then 'ucode_blob' will contain the pointer +* and the size of said blob. It is allocated from Xen's heap +* memory. +*/ +struct ucode_mod_blob { +void *data;
xen/arch/x86/microcode.c line 67
Quoted 10 lines
xen/arch/x86/microcode.c +10
-0+size_t size; +}; + +static struct ucode_mod_blob __initdata ucode_blob; +/* +* By default we will parse the multiboot modules to see if there is +* cpio image with the microcode images. +*/ +static bool_t __initdata opt_scan_ucode =1 ; +boolean_param ("scan_ucode" , opt_scan_ucode);
I'm also unsure we really want this on by default. "ucode=<num>" also isn't having any "default on" effect.
Reviewing the rest of the patch requires clarification on the concept first, as asked for in response to the "overview" mail.
Jan
Re: [RFC PATCH v1] microcode: Scan the initramfs payload for microcode blob.
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
docs/misc/xen-command-line.markdown +0
-0@@ -760,6 +760,18 @@ only available on 32-bit x86 platforms. `acpi` instructs Xen to reboot the host using RESET_REG in the ACPI FADT.
Quoted 16 lines
docs/misc/xen-command-line.markdown only available on 32-bit x86 platforms. · line 774
Quoted 12 lines
docs/misc/xen-command-line.markdown +12
-0+### scan_ucode +> `= <boolean>` + +> Default: `true` + +Flag to globally enable or disable support for scanning the multiboot images +for an cpio image that contains microcode, which are: + on Intel: kernel/x86/microcode/GenuineIntel.bin + on AMD : kernel/x86/microcode/AuthenticAMD.bin + +Note that is 'ucode' parameter is used this option becomes disabled. +I would want this to be an extension of the "ucode=" option, not an independent new one. E.g. "ucode=initrd" or "ucode=cpio:<num>" or some such.
I believe that it would be best suited for users if said feature was turned on by default - and then if needed - can be turned off. Similarly to how HAP is enabled by default.
Using the over-ride in 'ucode' parse code is fine with me. I would propose 'ucode=noscan' or 'ucode=noauto' as the parameters.
Quoted 28 lines
Quoted 28 lines
xen/arch/x86/microcode.c +15
-0@@ -39,12 +39,33 @@#include <asm/setup.h> #include <asm/microcode.h> +#include <xen/earlycpio.h> +static module_t __initdata ucode_mod;static void *(*__initdata ucode_mod_map)(const module_t *);static signed int __initdata ucode_mod_idx;static bool_t __initdata ucode_mod_forced;static cpumask_t __initdata init_mask; +/* +* If we scan the initramfs.cpio for the early microcode code +* and find it, then 'ucode_blob' will contain the pointer +* and the size of said blob. It is allocated from Xen's heap +* memory. +*/ +struct ucode_mod_blob { +void *data; +size_t size; +}; + +static struct ucode_mod_blob __initdata ucode_blob; +/*
Quoted 8 lines
xen/arch/x86/microcode.c line 67
Quoted 5 lines
xen/arch/x86/microcode.c +5
-0+* By default we will parse the multiboot modules to see if there is +* cpio image with the microcode images. +*/ +static bool_t __initdata opt_scan_ucode =1 ; +boolean_param ("scan_ucode" , opt_scan_ucode);I'm also unsure we really want this on by default. "ucode=<num>" also isn't having any "default on" effect.
Correct. Because it ('ucode=<num>') is unable to figure out which of the multiboot payloads has the ucode. It needs the help from GRUB2 or other tools that construct the bootloader configuration files.
This code, similar to how XSM finds its policy, can find the microcode blob without the help of the bootloader.
In the Linux code if this feature is turned on it will _always_ search the initramfs. I think that idea makes sense here as well - we want to enable X feature if we detect that it exists.
Quoted 7 lines
Reviewing the rest of the patch requires clarification on the concept first, as asked for in response to the "overview" mail.
Jan
Re: [RFC PATCH v1] microcode: Scan the initramfs payload for microcode blob.
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Quoted 11 lines · Jan Beulich
xen/arch/x86/microcode.c line 67
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
xen/arch/x86/microcode.c +7
-0+static struct ucode_mod_blob __initdata ucode_blob; +/* +* By default we will parse the multiboot modules to see if there is +* cpio image with the microcode images. +*/ +static bool_t __initdata opt_scan_ucode =1 ; +boolean_param ("scan_ucode" , opt_scan_ucode);I'm also unsure we really want this on by default. "ucode=<num>" also isn't having any "default on" effect.
Quoted 3 lines
Correct. Because it ('ucode=<num>') is unable to figure out which of the multiboot payloads has the ucode. It needs the help from GRUB2 or other tools that construct the bootloader configuration files.
No - it could have been coded the same way as XSM. But when I put this together, the approach of looking just at the first few bytes and draw conclusions from that seemed to fragile to me. Admitted XSM at least has some kind signature there, but at least AMD ucode has too, so one could have used that. Still I think that having the user explicitly state what (s)he wants is better than this guesswork.
Quoted 6 lines
This code, similar to how XSM finds its policy, can find the microcode blob without the help of the bootloader.
In the Linux code if this feature is turned on it will _always_ search the initramfs. I think that idea makes sense here as well - we want to enable X feature if we detect that it exists.
Linux can safely always do that, because it can make assumptions about the format of the initrd. Xen otoh has to be careful not to mis-interpret a blob passed to a non-Linux Dom0 as a CPIO. How good the guarding against this is in the code I'll have to check (now that the question regarding the concatenation was answered By David).
Jan
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Greetings,
Please see the following patch which implements a mechanism to scan the initramfs for the format of an microcode files. This is a feature that the Linux kernel has since v3.10 - where it searches in the initramfs for an archive of the microcode blob. The format is documented in the Linux tree and the commit description contains it.
Quoted 4 lines
The tool to make this work is the initramfs creator. The author has provided an RFC patch:
http://article.gmane.org/gmane.linux.kernel.initramfs/3318
which does that.
Looking at that script change I'm getting the impression that the representation is as uncompressed cpio containing the ucode blobs followed by compressed cpio containing all the "normal" stuff. Which iiuc means that an unaware kernel can't deal with such an image (as the consumer needs to know that it has to skip the initial portion). Unless that understanding of mine is wrong - isn't that a rather bad design?
Jan
Quoted 14 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Greetings,
Please see the following patch which implements a mechanism to scan the initramfs for the format of an microcode files. This is a feature that the Linux kernel has since v3.10 - where it searches in the initramfs for an archive of the microcode blob. The format is documented in the Linux tree and the commit description contains it.
Quoted 4 lines
The tool to make this work is the initramfs creator. The author has provided an RFC patch:
http://article.gmane.org/gmane.linux.kernel.initramfs/3318
which does that.
Quoted 7 lines
Looking at that script change I'm getting the impression that the representation is as uncompressed cpio containing the ucode blobs followed by compressed cpio containing all the "normal" stuff. Which iiuc means that an unaware kernel can't deal with such an image (as the consumer needs to know that it has to skip the initial portion). Unless that understanding of mine is wrong - isn't that a rather bad design?
The kernel unpacks all cpio archives it finds in the initramfs image so the kernel doesn't have to be aware of the way tools have packed the filesystem into different cpio archive.
David
Quoted 14 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Konrad Rzeszutek Wilk
Greetings,
Please see the following patch which implements a mechanism to scan the initramfs for the format of an microcode files. This is a feature that the Linux kernel has since v3.10 - where it searches in the initramfs for an archive of the microcode blob. The format is documented in the Linux tree and the commit description contains it.
Quoted 4 lines
The tool to make this work is the initramfs creator. The author has provided an RFC patch:
http://article.gmane.org/gmane.linux.kernel.initramfs/3318
which does that.
Quoted 8 lines
Looking at that script change I'm getting the impression that the representation is as uncompressed cpio containing the ucode blobs followed by compressed cpio containing all the "normal" stuff. Which iiuc means that an unaware kernel can't deal with such an image (as the consumer needs to know that it has to skip the initial portion). Unless that understanding of mine is wrong - isn't that a rather bad design?
The kernel if compiled without EARLY_INITRAMFS.. and an initramfs _with_ the uncompressed cpio containing the ucode blob followed by compressed cpio containing the normal stuff boots. I tested this with a v3.9 and v3.11 kernel and both booted without trouble.
Quoted 3 lines
Jan