Arrange to upgrade microcode on x86 test hosts.
PATCH v2 1/1 Arrange to upgrade microcode on x86 test hosts.
Both Xen and Linux support extracting a microcode update from an initramfs early during boot. This requires prepending a suitable uncompressed cpio archive containing the necessary files to the initrd.
Xen also supports loading the microcode cpio from any multiboot module, but for in order to allow the possibility of loading on native boots (e.g. for build jobs) we prefer the prepend method.
This patch provides mg-cpu-microcode-update which creates a suitable microcode cpio in the images directory and arranges for it to be added to the host during installation (so it is done before the kernel is installed and initramfs generated etc, saving faff). It also adds "ucode=scan" to the Xen command line when necessary.
The version of initramfs-tools in Wheezy does not yet support prepending things to the initrm, so we use a custom compression command which sneakily does it for us. This could be done better from Jessie onwards.
Note that Linux only supports this from v3.8 onwards, so this doesn't work for Wheezy (which uses v3.2). From Jessie onwards we should benefit from microcode updates even for native (build) jobs.
Tested on both Intel and AMD where it appeared to have the desired effect under Xen. Under native I only tried Wheezy which doesn't support early microcode.
Note that I've not bothered to implement late microcode updates, which would work on v3.2 too, since that would need a different set of files etc and it doesn't seem especially pressing.
---
Upon commit please run mg-cpu-microcode-update and set MicrocodeUpdateAmd64 and MicrocodeUpdateI386 to the resulting file in both production-config and production-config-cambridge (I will copy the binary to the Cambridge location)
v2:
Downcase local variables, avoid $CPIO/$cpio completely. Add /usr/sbin to $PATH.
Make mg-cpu-microcode-update idemotent and deterministic. Operate in locally constructed tmp dir.
Clone linux-firmware from git instead of curl on gitweb. More idiomatic Perl
Move log message to where everything is defined.
--- Osstest/Debian.pm | 44 ++++++++++++++++++++++++ mg-cpu-microcode-update | 82 +++++++++++++++++++++++++++++++++++++++++++++ production-config | 4 +++ production-config-cambridge | 4 +++ ts-xen-install | 7 ++++ 5 files changed, 141 insertions(+) create mode 100755 mg-cpu-microcode-update
Osstest/Debian.pm +44 -0
@@ -626,6 +626,48 @@ chroot /target chown -R \$u.\$u \$h/.ssh END } +sub preseed_microcode($$) +{ + my ($ho,$sfx) = @_; + my $prop = "MicrocodeUpdate".ucfirst($r{arch}); + return unless $c{$prop}; + logm("ucode=$prop $c{$prop}"); + my $ucode = get_filecontents("$c{Images}/$c{$prop}"); + my $cpio_url = create_webfile($ho, "microcode-cpio", + sub { + my $f = "$c{Images}/$c{$prop}"; + copy($f, $_[0]) or die "Copy $f failed: $!"; + }); + + # The ability to prepend from an initramfs-hook was not added + # until Jessie, therefore for Wheezy we use a custom compression + # method which sneaks the necessary cpio onto the front. + my $gzip_url = create_webfile($ho, "microcode-gzip",<<END); +#!/bin/bash +if [ -f /boot/microcode.cpio ]; then + cat /boot/microcode.cpio +fi +exec gzip +END + + preseed_hook_installscript($ho, $sfx, + '/usr/lib/base-installer.d/','osstest-microcode', <<END); +#!/bin/sh +set -ex + +mkdir -p /target/boot +wget -O /target/boot/microcode.cpio $cpio_url + +mkdir -p /target/usr/sbin +wget -O /target/usr/sbin/osstest-initramfs-gzip $gzip_url +chmod +x /target/usr/sbin/osstest-initramfs-gzip + +mkdir -p /target/etc/initramfs-tools/conf.d/ +echo COMPRESS=/usr/sbin/osstest-initramfs-gzip >> \\ + /target/etc/initramfs-tools/conf.d/osstest-initramfs-gzip.conf +END +} + sub preseed_base ($$$$;@) { my ($ho,$suite,$sfx,$extra_packages,%xopts) = @_;
@@ -941,6 +983,8 @@ d-i partman-auto/expert_recipe string \\ END + preseed_microcode($ho,$sfx); + $preseed_file .= preseed_hook_cmds(); if ($ho->{Flags}{'no-di-kernel'}) {
mg-cpu-microcode-update new file +82 -0
82 lines not on this page · raw message
production-config +4 -0
@@ -87,6 +87,10 @@ TftpPxeTemplatesReal pxelinux.cfg/%ipaddrhex% TftpPxeGroup osstest TftpDiVersion 2015-01-10 +# These should normally be the same. XXX update on commit. +MicrocodeUpdateAmd64 microcode.x86.YYYY-MM-DD.cpio +MicrocodeUpdateI386 microcode.x86.YYYY-MM-DD.cpio + XenUsePath /usr/groups/xencore/systems/bin/xenuse XenUseUser osstest
production-config-cambridge +4 -0
@@ -73,6 +73,10 @@ TftpPxeTemplates %ipaddrhex%/pxelinux.cfg TftpPxeGroup osstest TftpDiVersion 2015-01-10 +# These should normally be the same. XXX update on commit. +MicrocodeUpdateAmd64 microcode.x86.YYYY-MM-DD.cpio +MicrocodeUpdateI386 microcode.x86.YYYY-MM-DD.cpio + XenUsePath /usr/groups/xencore/systems/bin/xenuse XenUseUser osstest
ts-xen-install +7 -0
@@ -145,6 +145,13 @@ sub setupboot () { if (toolstack($ho)->{Dom0MemFixed}) { $xenhopt .= " dom0_mem=512M,max:512M"; } + + # If /boot/microcode.cpio is present then ts-host-install has + # arranged that it will be prepended to the initrd already, all we + # need to do is look for it. + $xenhopt .= " ucode=scan" + if target_file_exists($ho, "/boot/microcode.cpio"); + my $append= $r{xen_boot_append}; $xenhopt .= " $append" if defined $append; $append = get_host_property($ho, 'xen-commandline-append', undef);
Signature · 1 line
2.1.4
Ian Campbell writes ("[PATCH OSSTEST v2] Arrange to upgrade microcode on x86 test hosts."):
Quoted 4 lines
Both Xen and Linux support extracting a microcode update from an initramfs early during boot. This requires prepending a suitable uncompressed cpio archive containing the necessary files to the initrd.
...
Quoted 4 lines
Upon commit please run mg-cpu-microcode-update and set MicrocodeUpdateAmd64 and MicrocodeUpdateI386 to the resulting file in both production-config and production-config-cambridge (I will copy the binary to the Cambridge location)
Please, as discussed on irc, feel free to run this new mg-cpu-microcode-update on the production instance.
Ian.