Arrange to upgrade microcode on x86 test hosts.
PATCH v3 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.
---
v3:
- iucode-tool is iucode_tool in Wheezy, Jessie has both names
- This exact version mg-cpu-microcode-update has been run in colo, updated production-config*
- Avoid proxy with wget, since it was pointing at the apt-cache which gave "403 Sorry, not allowed to fetch that type of file:
fiano0_microcode-cpio"
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 -Y off -O /target/boot/microcode.cpio $cpio_url + +mkdir -p /target/usr/sbin +wget -Y off -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. +MicrocodeUpdateAmd64 microcode.x86.2015-06-12.cpio +MicrocodeUpdateI386 microcode.x86.2015-06-12.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. +MicrocodeUpdateAmd64 microcode.x86.2015-06-12.cpio +MicrocodeUpdateI386 microcode.x86.2015-06-12.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 v3] Arrange to upgrade microcode on x86 test hosts."):
Quoted 8 lines
---
v3:
- iucode-tool isiucode_toolin Wheezy, Jessie has both names
- This exact version mg-cpu-microcode-update has been run in colo, updated production-config*
- Avoid proxy with wget, since it was pointing at the apt-cache which gave "403 Sorry, not allowed to fetch that type of file:
fiano0_microcode-cpio"
But, it occurs to me:
Quoted 1 line
+wget -Y off -O /target/boot/microcode.cpio $cpio_url
...
Quoted 1 line
+wget -Y off -O /target/usr/sbin/osstest-initramfs-gzip $gzip_url
cf
Osstest/Debian.pm:wget -O .ssh/authorized_keys '$authkeys_url'
Osstest/Debian.pm:wget -O .ssh/known_hosts '$knownhosts_url'
Osstest/Debian.pm:wget -O \$r/tmp/dtbs.tar.gz $durl Osstest/Debian.pm:wget -O \$r/tmp/kern.deb $kurl Osstest/Debian.pm:wget -O \$r/tmp/initramfs-tools.deb $iurl
Osstest/Debian.pm: my $cmd_cmd= "wget -O $file '$url' && chmod +x $file && $file";
Osstest/Debian.pm:wget -O '$installer_pathname' '$url' Osstest/Debian.pm:wget -O overlay.tar '$url'
Osstest/Serial/http.pm: system_checked(qw(wget -nH --cut-dirs=1 -r -l1 --no-parent),
Perhaps wget in much of this should become $di_wget which contains `wget -Y off' ?
We don't really want to be fetching any of this stuff through the apt-cache. Currently it's presumably it's working by chance, either because of what might be thought of as a bug in the apt cacher, or because d-i's setting of http_proxy to the supplied cache is not quite universal.
Ian.
Quoted 12 lines · Ian Jackson
Ian Campbell writes ("[PATCH OSSTEST v3] Arrange to upgrade microcode on x86 test hosts."):
Quoted 8 lines
---
v3:
- iucode-tool isiucode_toolin Wheezy, Jessie has both names
- This exact version mg-cpu-microcode-update has been run in colo, updated production-config*
- Avoid proxy with wget, since it was pointing at the apt-cache which gave "403 Sorry, not allowed to fetch that type of file:
fiano0_microcode-cpio"Acked-by Ian Jackson <[email protected]>
[...]
Quoted 2 lines
Perhaps wget in much of this should become $di_wget which contains `wget -Y off' ?
I sent a separate patch to add -Y off everywhere. I could make it use $di_wget instead.
Quoted 5 lines
We don't really want to be fetching any of this stuff through the apt-cache. Currently it's presumably it's working by chance, either because of what might be thought of as a bug in the apt cacher, or because d-i's setting of
http_proxyto the supplied cache is not quite universal.
Right.