microcode.rst 4.0 KB

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