CPU Microcode Loading on Linux
7 min read
A GRUB entry on one of my lab boxes reads like this:
initrd /amd-uc.img /initramfs-6.12.41.img
Two files on one initrd line. The second is the real initramfs; the first is a CPU microcode image, and it is the boot detail most people never look at until they grep dmesg after a kernel update and find the line they expected is missing. When microcode does not load, nothing breaks loudly. The machine boots, the workload runs, and the CPU quietly keeps the errata and the speculative-execution holes the vendor already published a fix for.
What microcode actually is
Modern x86 CPUs decode instructions into internal operations using a patchable table, and a microcode update replaces part of that table. The board's BIOS loads a copy at power-on; the kernel loads another copy early in boot.
The second load is the one that matters, because the OS copy is almost always newer. Board vendors stop shipping BIOS updates long before Intel and AMD stop shipping microcode. On out-of-support hardware (an R720xd, an H310M-E, anything a vendor walked away from) the BIOS copy can be years behind what sys-firmware/intel-microcode shipped last month.
What it buys you
The speculative-execution family is the loud category: Spectre v2 and its IBRS/IBPB/STIBP controls, MDS, TAA, SRBDS, Downfall (GDS), Zenbleed, Inception, RFDS. The split matters: the microcode delivers the mechanism, usually a new MSR or a flushing behaviour, and the kernel enables it. Without the microcode the kernel falls back to whatever software-only mitigation it has, which is slower, weaker, or on some issues simply unavailable.
The quiet category is plain errata: documented conditions where the CPU hangs or returns a wrong result under some combination of instructions and state. Every generation has an errata sheet, and those fixes arrive the same way.
Reading your current state
Three places, in increasing order of usefulness. First, the loaded revision:
grep -m1 microcode /proc/cpuinfo
microcode : 0x43
That is the revision in effect right now, whoever loaded it. It does not tell you whether the kernel did the loading.
For that, check the boot log:
dmesg | grep -i microcode
microcode: Current revision: 0x... and nothing else means the kernel found nothing newer than what the BIOS installed, which may be correct or may mean your image is not being loaded at all. updated early to revision 0x... is the line you want: the kernel found a newer blob and applied it before the rest of boot. If dmesg has rotated past it, journalctl -k -b or your syslog's boot record has the same lines.
The most useful view is the per-issue status the kernel exports:
grep . /sys/devices/system/cpu/vulnerabilities/*
On a Haswell-generation Xeon here that includes:
spectre_v2:Mitigation: Retpolines; IBPB: conditional; IBRS_FW; STIBP: conditional; RSB filling; PBRSB-eIBRS: Not affected; BHI: Not affected
mds:Mitigation: Clear CPU buffers; SMT vulnerable
srbds:Not affected
Read these as a report card. Vulnerable is the word to hunt for, and on several of these issues the reason is a missing microcode revision, which the kernel usually spells out in the same string. An active mitigation is not necessarily a complete one: SMT vulnerable above says the residual hole stays open until hyper-threading is off.
The cost, and which machines pay it
The penalty is not uniform, and it tracks how much of the fix is in hardware.
Sandy Bridge-EP and Ivy Bridge-EP (E5-26xx v1 and v2) pay the most: IBRS on those parts is a heavyweight MSR write on every kernel entry, and on syscall-heavy workloads the mitigated-versus-unmitigated gap runs into the high single digits or worse. Haswell and Broadwell sit in the middle. Skylake-SP and later (a Xeon Gold 52xx, say) are much lighter, because enhanced IBRS moves the work into hardware. On AMD, the Zen 2 and Zen 3 fixes for Zenbleed and Inception are cheap, and Zen 4 and later close to free.
mitigations=off on the kernel command line is the upper bound of what you could recover, and it is the wrong answer almost everywhere. These mitigations defend against code you did not intend to run: another tenant, a browser, a container, a CI job, an untrusted upload handler. A public-facing router stays fully mitigated, full stop. A single-tenant compute box running nothing but your own batch jobs is a different risk profile, and if you relax something there, relax one named mitigation whose threat model you have thought about rather than switching the whole set off with one word. Leaving the microcode out is never the way to buy performance: it costs you the errata fixes too.
Installing it
On Gentoo, Intel:
emerge -av sys-firmware/intel-microcode
The initramfs USE flag builds the early-load image at /boot/intel-uc.img. The split-ucode flag installs the per-CPU blobs under /lib/firmware/intel-ucode/, which is what you need for the built-in-kernel route below. Both can be on at once.
AMD microcode ships in sys-kernel/linux-firmware as amd-ucode/.
On Debian the packages are intel-microcode and amd64-microcode, and initramfs-tools prepends the early cpio to the initramfs for you when either is installed.
The three ways to load it
Separate early cpio image. List it first on the initrd line, as in the GRUB entry at the top of this post. GRUB concatenates the files it is given, and the kernel reads the uncompressed microcode cpio off the front before it touches the real initramfs. This is the method I recommend for anyone with a custom kernel or initramfs pipeline: it is kernel-independent, it updates when the package updates, and it needs no rebuild of anything.
Built into the kernel. Set CONFIG_EXTRA_FIRMWARE to your CPU's blob path and CONFIG_EXTRA_FIRMWARE_DIR to where the split blobs live:
CONFIG_EXTRA_FIRMWARE="intel-ucode/06-2d-07"
CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware"
This loads earliest of all, which is the argument for it. The costs: every microcode release means a kernel rebuild, and you must name your exact family-model-stepping blob. iucode_tool -S reports the signature of the running CPU; it is not installed by default, so check your distro for it before relying on it.
Prepended by the initramfs generator. genkernel --microcode, dracut with early_microcode=yes, mkinitcpio with its microcode hook. Convenient if you already use one of those, but the microcode is now tied to each initramfs build, and a hand-rolled generator that does not do the early-cpio dance silently gets you nothing.
Gotchas
The early cpio must be uncompressed and it must come first. Compress it or put it after the initramfs and the kernel will not find it, with no error beyond the missing updated early line.
kexec boot chains are the trap I have actually been bitten by. A kexec starts past the firmware, so the microcode image has to be passed through explicitly in the new boot's initrd list or it does not come along, the same class of problem as everything else in what kexec does not preserve.
Secure Boot signs the kernel and the bootloader, not microcode: the CPU authenticates the blob itself, so an unsigned early cpio is neither a Secure Boot failure nor a hole.
Late loading, writing to /sys/devices/system/cpu/microcode/reload on a running system, is the thing to stop reaching for. Current kernels restrict or refuse it where it is genuinely unsafe, and the sysfs entry may not exist at all depending on your kernel config. Reboot instead.
The habit that keeps all of this honest: after any kernel or microcode update, grep the boot log for the updated early line before you consider the machine done. It is the only check that proves the file on the initrd line is still doing its job, and if you have a kernel-build script, the assertion belongs in the script. The failure mode here is silence, so nothing else will tell you.
This pairs with the earlier post on CPU frequency governors on servers: both are boot-time CPU settings that cost nothing to get right and are invisible when they are wrong.