microcode.txt 3.9 KB

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