1 The Linux Microcode Loader 2 3Authors: Fenghua Yu <fenghua.yu@intel.com> 4 Borislav Petkov <bp@suse.de> 5 6The kernel has a x86 microcode loading facility which is supposed to 7provide microcode loading methods in the OS. Potential use cases are 8updating the microcode on platforms beyond the OEM End-Of-Life support, 9and updating the microcode on long-running systems without rebooting. 10 11The loader supports three loading methods: 12 131. Early load microcode 14======================= 15 16The kernel can update microcode very early during boot. Loading 17microcode early can fix CPU issues before they are observed during 18kernel boot time. 19 20The microcode is stored in an initrd file. During boot, it is read from 21it and loaded into the CPU cores. 22 23The format of the combined initrd image is microcode in (uncompressed) 24cpio format followed by the (possibly compressed) initrd image. The 25loader parses the combined initrd image during boot. 26 27The microcode files in cpio name space are: 28 29on Intel: kernel/x86/microcode/GenuineIntel.bin 30on AMD : kernel/x86/microcode/AuthenticAMD.bin 31 32During BSP (BootStrapping Processor) boot (pre-SMP), the kernel 33scans the microcode file in the initrd. If microcode matching the 34CPU is found, it will be applied in the BSP and later on in all APs 35(Application Processors). 36 37The loader also saves the matching microcode for the CPU in memory. 38Thus, the cached microcode patch is applied when CPUs resume from a 39sleep state. 40 41Here's a crude example how to prepare an initrd with microcode (this is 42normally done automatically by the distribution, when recreating the 43initrd, so you don't really have to do it yourself. It is documented 44here for future reference only). 45 46--- 47 #!/bin/bash 48 49 if [ -z "$1" ]; then 50 echo "You need to supply an initrd file" 51 exit 1 52 fi 53 54 INITRD="$1" 55 56 DSTDIR=kernel/x86/microcode 57 TMPDIR=/tmp/initrd 58 59 rm -rf $TMPDIR 60 61 mkdir $TMPDIR 62 cd $TMPDIR 63 mkdir -p $DSTDIR 64 65 if [ -d /lib/firmware/amd-ucode ]; then 66 cat /lib/firmware/amd-ucode/microcode_amd*.bin > $DSTDIR/AuthenticAMD.bin 67 fi 68 69 if [ -d /lib/firmware/intel-ucode ]; then 70 cat /lib/firmware/intel-ucode/* > $DSTDIR/GenuineIntel.bin 71 fi 72 73 find . | cpio -o -H newc >../ucode.cpio 74 cd .. 75 mv $INITRD $INITRD.orig 76 cat ucode.cpio $INITRD.orig > $INITRD 77 78 rm -rf $TMPDIR 79--- 80 81The system needs to have the microcode packages installed into 82/lib/firmware or you need to fixup the paths above if yours are 83somewhere else and/or you've downloaded them directly from the processor 84vendor's site. 85 862. Late loading 87=============== 88 89There are two legacy user space interfaces to load microcode, either through 90/dev/cpu/microcode or through /sys/devices/system/cpu/microcode/reload file 91in sysfs. 92 93The /dev/cpu/microcode method is deprecated because it needs a special 94userspace tool for that. 95 96The easier method is simply installing the microcode packages your distro 97supplies and running: 98 99# echo 1 > /sys/devices/system/cpu/microcode/reload 100 101as root. 102 103The loading mechanism looks for microcode blobs in 104/lib/firmware/{intel-ucode,amd-ucode}. The default distro installation 105packages already put them there. 106 1073. Builtin microcode 108==================== 109 110The loader supports also loading of a builtin microcode supplied through 111the regular builtin firmware method CONFIG_EXTRA_FIRMWARE. Only 64-bit is 112currently supported. 113 114Here's an example: 115 116CONFIG_EXTRA_FIRMWARE="intel-ucode/06-3a-09 amd-ucode/microcode_amd_fam15h.bin" 117CONFIG_EXTRA_FIRMWARE_DIR="/lib/firmware" 118 119This basically means, you have the following tree structure locally: 120 121/lib/firmware/ 122|-- amd-ucode 123... 124| |-- microcode_amd_fam15h.bin 125... 126|-- intel-ucode 127... 128| |-- 06-3a-09 129... 130 131so that the build system can find those files and integrate them into 132the final kernel image. The early loader finds them and applies them. 133 134Needless to say, this method is not the most flexible one because it 135requires rebuilding the kernel each time updated microcode from the CPU 136vendor is available. 137