2
0

cpu-models-x86.rst.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. Recommendations for KVM CPU model configuration on x86 hosts
  2. ============================================================
  3. The information that follows provides recommendations for configuring
  4. CPU models on x86 hosts. The goals are to maximise performance, while
  5. protecting guest OS against various CPU hardware flaws, and optionally
  6. enabling live migration between hosts with heterogeneous CPU models.
  7. Two ways to configure CPU models with QEMU / KVM
  8. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  9. (1) **Host passthrough**
  10. This passes the host CPU model features, model, stepping, exactly to
  11. the guest. Note that KVM may filter out some host CPU model features
  12. if they cannot be supported with virtualization. Live migration is
  13. unsafe when this mode is used as libvirt / QEMU cannot guarantee a
  14. stable CPU is exposed to the guest across hosts. This is the
  15. recommended CPU to use, provided live migration is not required.
  16. (2) **Named model**
  17. QEMU comes with a number of predefined named CPU models, that
  18. typically refer to specific generations of hardware released by
  19. Intel and AMD. These allow the guest VMs to have a degree of
  20. isolation from the host CPU, allowing greater flexibility in live
  21. migrating between hosts with differing hardware. @end table
  22. In both cases, it is possible to optionally add or remove individual CPU
  23. features, to alter what is presented to the guest by default.
  24. Libvirt supports a third way to configure CPU models known as "Host
  25. model". This uses the QEMU "Named model" feature, automatically picking
  26. a CPU model that is similar the host CPU, and then adding extra features
  27. to approximate the host model as closely as possible. This does not
  28. guarantee the CPU family, stepping, etc will precisely match the host
  29. CPU, as they would with "Host passthrough", but gives much of the
  30. benefit of passthrough, while making live migration safe.
  31. ABI compatibility levels for CPU models
  32. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  33. The x86_64 architecture has a number of `ABI compatibility levels`_
  34. defined. Traditionally most operating systems and toolchains would
  35. only target the original baseline ABI. It is expected that in
  36. future OS and toolchains are likely to target newer ABIs. The
  37. table that follows illustrates which ABI compatibility levels
  38. can be satisfied by the QEMU CPU models. Note that the table only
  39. lists the long term stable CPU model versions (eg Haswell-v4).
  40. In addition to what is listed, there are also many CPU model
  41. aliases which resolve to a different CPU model version,
  42. depending on the machine type is in use.
  43. .. _ABI compatibility levels: https://gitlab.com/x86-psABIs/x86-64-ABI/
  44. .. csv-table:: x86-64 ABI compatibility levels
  45. :file: cpu-models-x86-abi.csv
  46. :widths: 40,15,15,15,15
  47. :header-rows: 2
  48. Preferred CPU models for Intel x86 hosts
  49. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  50. The following CPU models are preferred for use on Intel hosts.
  51. Administrators / applications are recommended to use the CPU model that
  52. matches the generation of the host CPUs in use. In a deployment with a
  53. mixture of host CPU models between machines, if live migration
  54. compatibility is required, use the newest CPU model that is compatible
  55. across all desired hosts.
  56. ``Cascadelake-Server``, ``Cascadelake-Server-noTSX``
  57. Intel Xeon Processor (Cascade Lake, 2019), with "stepping" levels 6
  58. or 7 only. (The Cascade Lake Xeon processor with *stepping 5 is
  59. vulnerable to MDS variants*.)
  60. ``Skylake-Server``, ``Skylake-Server-IBRS``, ``Skylake-Server-IBRS-noTSX``
  61. Intel Xeon Processor (Skylake, 2016)
  62. ``Skylake-Client``, ``Skylake-Client-IBRS``, ``Skylake-Client-noTSX-IBRS}``
  63. Intel Core Processor (Skylake, 2015)
  64. ``Broadwell``, ``Broadwell-IBRS``, ``Broadwell-noTSX``, ``Broadwell-noTSX-IBRS``
  65. Intel Core Processor (Broadwell, 2014)
  66. ``Haswell``, ``Haswell-IBRS``, ``Haswell-noTSX``, ``Haswell-noTSX-IBRS``
  67. Intel Core Processor (Haswell, 2013)
  68. ``IvyBridge``, ``IvyBridge-IBR``
  69. Intel Xeon E3-12xx v2 (Ivy Bridge, 2012)
  70. ``SandyBridge``, ``SandyBridge-IBRS``
  71. Intel Xeon E312xx (Sandy Bridge, 2011)
  72. ``Westmere``, ``Westmere-IBRS``
  73. Westmere E56xx/L56xx/X56xx (Nehalem-C, 2010)
  74. ``Nehalem``, ``Nehalem-IBRS``
  75. Intel Core i7 9xx (Nehalem Class Core i7, 2008)
  76. ``Penryn``
  77. Intel Core 2 Duo P9xxx (Penryn Class Core 2, 2007)
  78. ``Conroe``
  79. Intel Celeron_4x0 (Conroe/Merom Class Core 2, 2006)
  80. Important CPU features for Intel x86 hosts
  81. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  82. The following are important CPU features that should be used on Intel
  83. x86 hosts, when available in the host CPU. Some of them require explicit
  84. configuration to enable, as they are not included by default in some, or
  85. all, of the named CPU models listed above. In general all of these
  86. features are included if using "Host passthrough" or "Host model".
  87. ``pcid``
  88. Recommended to mitigate the cost of the Meltdown (CVE-2017-5754) fix.
  89. Included by default in Haswell, Broadwell & Skylake Intel CPU models.
  90. Should be explicitly turned on for Westmere, SandyBridge, and
  91. IvyBridge Intel CPU models. Note that some desktop/mobile Westmere
  92. CPUs cannot support this feature.
  93. ``spec-ctrl``
  94. Required to enable the Spectre v2 (CVE-2017-5715) fix.
  95. Included by default in Intel CPU models with -IBRS suffix.
  96. Must be explicitly turned on for Intel CPU models without -IBRS
  97. suffix.
  98. Requires the host CPU microcode to support this feature before it
  99. can be used for guest CPUs.
  100. ``stibp``
  101. Required to enable stronger Spectre v2 (CVE-2017-5715) fixes in some
  102. operating systems.
  103. Must be explicitly turned on for all Intel CPU models.
  104. Requires the host CPU microcode to support this feature before it can
  105. be used for guest CPUs.
  106. ``ssbd``
  107. Required to enable the CVE-2018-3639 fix.
  108. Not included by default in any Intel CPU model.
  109. Must be explicitly turned on for all Intel CPU models.
  110. Requires the host CPU microcode to support this feature before it
  111. can be used for guest CPUs.
  112. ``pdpe1gb``
  113. Recommended to allow guest OS to use 1GB size pages.
  114. Not included by default in any Intel CPU model.
  115. Should be explicitly turned on for all Intel CPU models.
  116. Note that not all CPU hardware will support this feature.
  117. ``md-clear``
  118. Required to confirm the MDS (CVE-2018-12126, CVE-2018-12127,
  119. CVE-2018-12130, CVE-2019-11091) fixes.
  120. Not included by default in any Intel CPU model.
  121. Must be explicitly turned on for all Intel CPU models.
  122. Requires the host CPU microcode to support this feature before it
  123. can be used for guest CPUs.
  124. ``mds-no``
  125. Recommended to inform the guest OS that the host is *not* vulnerable
  126. to any of the MDS variants ([MFBDS] CVE-2018-12130, [MLPDS]
  127. CVE-2018-12127, [MSBDS] CVE-2018-12126).
  128. This is an MSR (Model-Specific Register) feature rather than a CPUID feature,
  129. so it will not appear in the Linux ``/proc/cpuinfo`` in the host or
  130. guest. Instead, the host kernel uses it to populate the MDS
  131. vulnerability file in ``sysfs``.
  132. So it should only be enabled for VMs if the host reports @code{Not
  133. affected} in the ``/sys/devices/system/cpu/vulnerabilities/mds`` file.
  134. ``taa-no``
  135. Recommended to inform that the guest that the host is ``not``
  136. vulnerable to CVE-2019-11135, TSX Asynchronous Abort (TAA).
  137. This too is an MSR feature, so it does not show up in the Linux
  138. ``/proc/cpuinfo`` in the host or guest.
  139. It should only be enabled for VMs if the host reports ``Not affected``
  140. in the ``/sys/devices/system/cpu/vulnerabilities/tsx_async_abort``
  141. file.
  142. ``tsx-ctrl``
  143. Recommended to inform the guest that it can disable the Intel TSX
  144. (Transactional Synchronization Extensions) feature; or, if the
  145. processor is vulnerable, use the Intel VERW instruction (a
  146. processor-level instruction that performs checks on memory access) as
  147. a mitigation for the TAA vulnerability. (For details, refer to
  148. Intel's `deep dive into MDS
  149. <https://software.intel.com/security-software-guidance/insights/deep-dive-intel-analysis-microarchitectural-data-sampling>`_.)
  150. Expose this to the guest OS if and only if: (a) the host has TSX
  151. enabled; *and* (b) the guest has ``rtm`` CPU flag enabled.
  152. By disabling TSX, KVM-based guests can avoid paying the price of
  153. mitigating TSX-based attacks.
  154. Note that ``tsx-ctrl`` too is an MSR feature, so it does not show
  155. up in the Linux ``/proc/cpuinfo`` in the host or guest.
  156. To validate that Intel TSX is indeed disabled for the guest, there are
  157. two ways: (a) check for the *absence* of ``rtm`` in the guest's
  158. ``/proc/cpuinfo``; or (b) the
  159. ``/sys/devices/system/cpu/vulnerabilities/tsx_async_abort`` file in
  160. the guest should report ``Mitigation: TSX disabled``.
  161. Preferred CPU models for AMD x86 hosts
  162. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  163. The following CPU models are preferred for use on AMD hosts.
  164. Administrators / applications are recommended to use the CPU model that
  165. matches the generation of the host CPUs in use. In a deployment with a
  166. mixture of host CPU models between machines, if live migration
  167. compatibility is required, use the newest CPU model that is compatible
  168. across all desired hosts.
  169. ``EPYC``, ``EPYC-IBPB``
  170. AMD EPYC Processor (2017)
  171. ``Opteron_G5``
  172. AMD Opteron 63xx class CPU (2012)
  173. ``Opteron_G4``
  174. AMD Opteron 62xx class CPU (2011)
  175. ``Opteron_G3``
  176. AMD Opteron 23xx (Gen 3 Class Opteron, 2009)
  177. ``Opteron_G2``
  178. AMD Opteron 22xx (Gen 2 Class Opteron, 2006)
  179. ``Opteron_G1``
  180. AMD Opteron 240 (Gen 1 Class Opteron, 2004)
  181. Important CPU features for AMD x86 hosts
  182. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  183. The following are important CPU features that should be used on AMD x86
  184. hosts, when available in the host CPU. Some of them require explicit
  185. configuration to enable, as they are not included by default in some, or
  186. all, of the named CPU models listed above. In general all of these
  187. features are included if using "Host passthrough" or "Host model".
  188. ``ibpb``
  189. Required to enable the Spectre v2 (CVE-2017-5715) fix.
  190. Included by default in AMD CPU models with -IBPB suffix.
  191. Must be explicitly turned on for AMD CPU models without -IBPB suffix.
  192. Requires the host CPU microcode to support this feature before it
  193. can be used for guest CPUs.
  194. ``stibp``
  195. Required to enable stronger Spectre v2 (CVE-2017-5715) fixes in some
  196. operating systems.
  197. Must be explicitly turned on for all AMD CPU models.
  198. Requires the host CPU microcode to support this feature before it
  199. can be used for guest CPUs.
  200. ``virt-ssbd``
  201. Required to enable the CVE-2018-3639 fix
  202. Not included by default in any AMD CPU model.
  203. Must be explicitly turned on for all AMD CPU models.
  204. This should be provided to guests, even if amd-ssbd is also provided,
  205. for maximum guest compatibility.
  206. Note for some QEMU / libvirt versions, this must be force enabled when
  207. when using "Host model", because this is a virtual feature that
  208. doesn't exist in the physical host CPUs.
  209. ``amd-ssbd``
  210. Required to enable the CVE-2018-3639 fix
  211. Not included by default in any AMD CPU model.
  212. Must be explicitly turned on for all AMD CPU models.
  213. This provides higher performance than ``virt-ssbd`` so should be
  214. exposed to guests whenever available in the host. ``virt-ssbd`` should
  215. none the less also be exposed for maximum guest compatibility as some
  216. kernels only know about ``virt-ssbd``.
  217. ``amd-no-ssb``
  218. Recommended to indicate the host is not vulnerable CVE-2018-3639
  219. Not included by default in any AMD CPU model.
  220. Future hardware generations of CPU will not be vulnerable to
  221. CVE-2018-3639, and thus the guest should be told not to enable
  222. its mitigations, by exposing amd-no-ssb. This is mutually
  223. exclusive with virt-ssbd and amd-ssbd.
  224. ``pdpe1gb``
  225. Recommended to allow guest OS to use 1GB size pages
  226. Not included by default in any AMD CPU model.
  227. Should be explicitly turned on for all AMD CPU models.
  228. Note that not all CPU hardware will support this feature.
  229. Default x86 CPU models
  230. ^^^^^^^^^^^^^^^^^^^^^^
  231. The default QEMU CPU models are designed such that they can run on all
  232. hosts. If an application does not wish to do perform any host
  233. compatibility checks before launching guests, the default is guaranteed
  234. to work.
  235. The default CPU models will, however, leave the guest OS vulnerable to
  236. various CPU hardware flaws, so their use is strongly discouraged.
  237. Applications should follow the earlier guidance to setup a better CPU
  238. configuration, with host passthrough recommended if live migration is
  239. not needed.
  240. ``qemu32``, ``qemu64``
  241. QEMU Virtual CPU version 2.5+ (32 & 64 bit variants)
  242. ``qemu64`` is used for x86_64 guests and ``qemu32`` is used for i686
  243. guests, when no ``-cpu`` argument is given to QEMU, or no ``<cpu>`` is
  244. provided in libvirt XML.
  245. Other non-recommended x86 CPUs
  246. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  247. The following CPUs models are compatible with most AMD and Intel x86
  248. hosts, but their usage is discouraged, as they expose a very limited
  249. featureset, which prevents guests having optimal performance.
  250. ``kvm32``, ``kvm64``
  251. Common KVM processor (32 & 64 bit variants).
  252. Legacy models just for historical compatibility with ancient QEMU
  253. versions.
  254. ``486``, ``athlon``, ``phenom``, ``coreduo``, ``core2duo``, ``n270``, ``pentium``, ``pentium2``, ``pentium3``
  255. Various very old x86 CPU models, mostly predating the introduction
  256. of hardware assisted virtualization, that should thus not be
  257. required for running virtual machines.
  258. Syntax for configuring CPU models
  259. =================================
  260. The examples below illustrate the approach to configuring the various
  261. CPU models / features in QEMU and libvirt.
  262. QEMU command line
  263. ^^^^^^^^^^^^^^^^^
  264. Host passthrough:
  265. .. parsed-literal::
  266. |qemu_system| -cpu host
  267. Host passthrough with feature customization:
  268. .. parsed-literal::
  269. |qemu_system| -cpu host,vmx=off,...
  270. Named CPU models:
  271. .. parsed-literal::
  272. |qemu_system| -cpu Westmere
  273. Named CPU models with feature customization:
  274. .. parsed-literal::
  275. |qemu_system| -cpu Westmere,pcid=on,...
  276. Libvirt guest XML
  277. ^^^^^^^^^^^^^^^^^
  278. Host passthrough::
  279. <cpu mode='host-passthrough'/>
  280. Host passthrough with feature customization::
  281. <cpu mode='host-passthrough'>
  282. <feature name="vmx" policy="disable"/>
  283. ...
  284. </cpu>
  285. Host model::
  286. <cpu mode='host-model'/>
  287. Host model with feature customization::
  288. <cpu mode='host-model'>
  289. <feature name="vmx" policy="disable"/>
  290. ...
  291. </cpu>
  292. Named model::
  293. <cpu mode='custom'>
  294. <model name="Westmere"/>
  295. </cpu>
  296. Named model with feature customization::
  297. <cpu mode='custom'>
  298. <model name="Westmere"/>
  299. <feature name="pcid" policy="require"/>
  300. ...
  301. </cpu>