cpu-features.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. Arm CPU Features
  2. ================
  3. CPU features are optional features that a CPU of supporting type may
  4. choose to implement or not. In QEMU, optional CPU features have
  5. corresponding boolean CPU proprieties that, when enabled, indicate
  6. that the feature is implemented, and, conversely, when disabled,
  7. indicate that it is not implemented. An example of an Arm CPU feature
  8. is the Performance Monitoring Unit (PMU). CPU types such as the
  9. Cortex-A15 and the Cortex-A57, which respectively implement Arm
  10. architecture reference manuals ARMv7-A and ARMv8-A, may both optionally
  11. implement PMUs. For example, if a user wants to use a Cortex-A15 without
  12. a PMU, then the ``-cpu`` parameter should contain ``pmu=off`` on the QEMU
  13. command line, i.e. ``-cpu cortex-a15,pmu=off``.
  14. As not all CPU types support all optional CPU features, then whether or
  15. not a CPU property exists depends on the CPU type. For example, CPUs
  16. that implement the ARMv8-A architecture reference manual may optionally
  17. support the AArch32 CPU feature, which may be enabled by disabling the
  18. ``aarch64`` CPU property. A CPU type such as the Cortex-A15, which does
  19. not implement ARMv8-A, will not have the ``aarch64`` CPU property.
  20. QEMU's support may be limited for some CPU features, only partially
  21. supporting the feature or only supporting the feature under certain
  22. configurations. For example, the ``aarch64`` CPU feature, which, when
  23. disabled, enables the optional AArch32 CPU feature, is only supported
  24. when using the KVM accelerator and when running on a host CPU type that
  25. supports the feature. While ``aarch64`` currently only works with KVM,
  26. it could work with TCG. CPU features that are specific to KVM are
  27. prefixed with "kvm-" and are described in "KVM VCPU Features".
  28. CPU Feature Probing
  29. ===================
  30. Determining which CPU features are available and functional for a given
  31. CPU type is possible with the ``query-cpu-model-expansion`` QMP command.
  32. Below are some examples where ``scripts/qmp/qmp-shell`` (see the top comment
  33. block in the script for usage) is used to issue the QMP commands.
  34. 1. Determine which CPU features are available for the ``max`` CPU type
  35. (Note, we started QEMU with qemu-system-aarch64, so ``max`` is
  36. implementing the ARMv8-A reference manual in this case)::
  37. (QEMU) query-cpu-model-expansion type=full model={"name":"max"}
  38. { "return": {
  39. "model": { "name": "max", "props": {
  40. "sve1664": true, "pmu": true, "sve1792": true, "sve1920": true,
  41. "sve128": true, "aarch64": true, "sve1024": true, "sve": true,
  42. "sve640": true, "sve768": true, "sve1408": true, "sve256": true,
  43. "sve1152": true, "sve512": true, "sve384": true, "sve1536": true,
  44. "sve896": true, "sve1280": true, "sve2048": true
  45. }}}}
  46. We see that the ``max`` CPU type has the ``pmu``, ``aarch64``, ``sve``, and many
  47. ``sve<N>`` CPU features. We also see that all the CPU features are
  48. enabled, as they are all ``true``. (The ``sve<N>`` CPU features are all
  49. optional SVE vector lengths (see "SVE CPU Properties"). While with TCG
  50. all SVE vector lengths can be supported, when KVM is in use it's more
  51. likely that only a few lengths will be supported, if SVE is supported at
  52. all.)
  53. (2) Let's try to disable the PMU::
  54. (QEMU) query-cpu-model-expansion type=full model={"name":"max","props":{"pmu":false}}
  55. { "return": {
  56. "model": { "name": "max", "props": {
  57. "sve1664": true, "pmu": false, "sve1792": true, "sve1920": true,
  58. "sve128": true, "aarch64": true, "sve1024": true, "sve": true,
  59. "sve640": true, "sve768": true, "sve1408": true, "sve256": true,
  60. "sve1152": true, "sve512": true, "sve384": true, "sve1536": true,
  61. "sve896": true, "sve1280": true, "sve2048": true
  62. }}}}
  63. We see it worked, as ``pmu`` is now ``false``.
  64. (3) Let's try to disable ``aarch64``, which enables the AArch32 CPU feature::
  65. (QEMU) query-cpu-model-expansion type=full model={"name":"max","props":{"aarch64":false}}
  66. {"error": {
  67. "class": "GenericError", "desc":
  68. "'aarch64' feature cannot be disabled unless KVM is enabled and 32-bit EL1 is supported"
  69. }}
  70. It looks like this feature is limited to a configuration we do not
  71. currently have.
  72. (4) Let's disable ``sve`` and see what happens to all the optional SVE
  73. vector lengths::
  74. (QEMU) query-cpu-model-expansion type=full model={"name":"max","props":{"sve":false}}
  75. { "return": {
  76. "model": { "name": "max", "props": {
  77. "sve1664": false, "pmu": true, "sve1792": false, "sve1920": false,
  78. "sve128": false, "aarch64": true, "sve1024": false, "sve": false,
  79. "sve640": false, "sve768": false, "sve1408": false, "sve256": false,
  80. "sve1152": false, "sve512": false, "sve384": false, "sve1536": false,
  81. "sve896": false, "sve1280": false, "sve2048": false
  82. }}}}
  83. As expected they are now all ``false``.
  84. (5) Let's try probing CPU features for the Cortex-A15 CPU type::
  85. (QEMU) query-cpu-model-expansion type=full model={"name":"cortex-a15"}
  86. {"return": {"model": {"name": "cortex-a15", "props": {"pmu": true}}}}
  87. Only the ``pmu`` CPU feature is available.
  88. A note about CPU feature dependencies
  89. -------------------------------------
  90. It's possible for features to have dependencies on other features. I.e.
  91. it may be possible to change one feature at a time without error, but
  92. when attempting to change all features at once an error could occur
  93. depending on the order they are processed. It's also possible changing
  94. all at once doesn't generate an error, because a feature's dependencies
  95. are satisfied with other features, but the same feature cannot be changed
  96. independently without error. For these reasons callers should always
  97. attempt to make their desired changes all at once in order to ensure the
  98. collection is valid.
  99. A note about CPU models and KVM
  100. -------------------------------
  101. Named CPU models generally do not work with KVM. There are a few cases
  102. that do work, e.g. using the named CPU model ``cortex-a57`` with KVM on a
  103. seattle host, but mostly if KVM is enabled the ``host`` CPU type must be
  104. used. This means the guest is provided all the same CPU features as the
  105. host CPU type has. And, for this reason, the ``host`` CPU type should
  106. enable all CPU features that the host has by default. Indeed it's even
  107. a bit strange to allow disabling CPU features that the host has when using
  108. the ``host`` CPU type, but in the absence of CPU models it's the best we can
  109. do if we want to launch guests without all the host's CPU features enabled.
  110. Enabling KVM also affects the ``query-cpu-model-expansion`` QMP command. The
  111. affect is not only limited to specific features, as pointed out in example
  112. (3) of "CPU Feature Probing", but also to which CPU types may be expanded.
  113. When KVM is enabled, only the ``max``, ``host``, and current CPU type may be
  114. expanded. This restriction is necessary as it's not possible to know all
  115. CPU types that may work with KVM, but it does impose a small risk of users
  116. experiencing unexpected errors. For example on a seattle, as mentioned
  117. above, the ``cortex-a57`` CPU type is also valid when KVM is enabled.
  118. Therefore a user could use the ``host`` CPU type for the current type, but
  119. then attempt to query ``cortex-a57``, however that query will fail with our
  120. restrictions. This shouldn't be an issue though as management layers and
  121. users have been preferring the ``host`` CPU type for use with KVM for quite
  122. some time. Additionally, if the KVM-enabled QEMU instance running on a
  123. seattle host is using the ``cortex-a57`` CPU type, then querying ``cortex-a57``
  124. will work.
  125. Using CPU Features
  126. ==================
  127. After determining which CPU features are available and supported for a
  128. given CPU type, then they may be selectively enabled or disabled on the
  129. QEMU command line with that CPU type::
  130. $ qemu-system-aarch64 -M virt -cpu max,pmu=off,sve=on,sve128=on,sve256=on
  131. The example above disables the PMU and enables the first two SVE vector
  132. lengths for the ``max`` CPU type. Note, the ``sve=on`` isn't actually
  133. necessary, because, as we observed above with our probe of the ``max`` CPU
  134. type, ``sve`` is already on by default. Also, based on our probe of
  135. defaults, it would seem we need to disable many SVE vector lengths, rather
  136. than only enabling the two we want. This isn't the case, because, as
  137. disabling many SVE vector lengths would be quite verbose, the ``sve<N>`` CPU
  138. properties have special semantics (see "SVE CPU Property Parsing
  139. Semantics").
  140. KVM VCPU Features
  141. =================
  142. KVM VCPU features are CPU features that are specific to KVM, such as
  143. paravirt features or features that enable CPU virtualization extensions.
  144. The features' CPU properties are only available when KVM is enabled and
  145. are named with the prefix "kvm-". KVM VCPU features may be probed,
  146. enabled, and disabled in the same way as other CPU features. Below is
  147. the list of KVM VCPU features and their descriptions.
  148. ``kvm-no-adjvtime``
  149. By default kvm-no-adjvtime is disabled. This means that by default
  150. the virtual time adjustment is enabled (vtime is not *not* adjusted).
  151. When virtual time adjustment is enabled each time the VM transitions
  152. back to running state the VCPU's virtual counter is updated to
  153. ensure stopped time is not counted. This avoids time jumps
  154. surprising guest OSes and applications, as long as they use the
  155. virtual counter for timekeeping. However it has the side effect of
  156. the virtual and physical counters diverging. All timekeeping based
  157. on the virtual counter will appear to lag behind any timekeeping
  158. that does not subtract VM stopped time. The guest may resynchronize
  159. its virtual counter with other time sources as needed.
  160. Enable kvm-no-adjvtime to disable virtual time adjustment, also
  161. restoring the legacy (pre-5.0) behavior.
  162. ``kvm-steal-time``
  163. Since v5.2, kvm-steal-time is enabled by default when KVM is
  164. enabled, the feature is supported, and the guest is 64-bit.
  165. When kvm-steal-time is enabled a 64-bit guest can account for time
  166. its CPUs were not running due to the host not scheduling the
  167. corresponding VCPU threads. The accounting statistics may influence
  168. the guest scheduler behavior and/or be exposed to the guest
  169. userspace.
  170. TCG VCPU Features
  171. =================
  172. TCG VCPU features are CPU features that are specific to TCG.
  173. Below is the list of TCG VCPU features and their descriptions.
  174. ``pauth-impdef``
  175. When ``FEAT_Pauth`` is enabled, either the *impdef* (Implementation
  176. Defined) algorithm is enabled or the *architected* QARMA algorithm
  177. is enabled. By default the impdef algorithm is disabled, and QARMA
  178. is enabled.
  179. The architected QARMA algorithm has good cryptographic properties,
  180. but can be quite slow to emulate. The impdef algorithm used by QEMU
  181. is non-cryptographic but significantly faster.
  182. SVE CPU Properties
  183. ==================
  184. There are two types of SVE CPU properties: ``sve`` and ``sve<N>``. The first
  185. is used to enable or disable the entire SVE feature, just as the ``pmu``
  186. CPU property completely enables or disables the PMU. The second type
  187. is used to enable or disable specific vector lengths, where ``N`` is the
  188. number of bits of the length. The ``sve<N>`` CPU properties have special
  189. dependencies and constraints, see "SVE CPU Property Dependencies and
  190. Constraints" below. Additionally, as we want all supported vector lengths
  191. to be enabled by default, then, in order to avoid overly verbose command
  192. lines (command lines full of ``sve<N>=off``, for all ``N`` not wanted), we
  193. provide the parsing semantics listed in "SVE CPU Property Parsing
  194. Semantics".
  195. SVE CPU Property Dependencies and Constraints
  196. ---------------------------------------------
  197. 1) At least one vector length must be enabled when ``sve`` is enabled.
  198. 2) If a vector length ``N`` is enabled, then, when KVM is enabled, all
  199. smaller, host supported vector lengths must also be enabled. If
  200. KVM is not enabled, then only all the smaller, power-of-two vector
  201. lengths must be enabled. E.g. with KVM if the host supports all
  202. vector lengths up to 512-bits (128, 256, 384, 512), then if ``sve512``
  203. is enabled, the 128-bit vector length, 256-bit vector length, and
  204. 384-bit vector length must also be enabled. Without KVM, the 384-bit
  205. vector length would not be required.
  206. 3) If KVM is enabled then only vector lengths that the host CPU type
  207. support may be enabled. If SVE is not supported by the host, then
  208. no ``sve*`` properties may be enabled.
  209. SVE CPU Property Parsing Semantics
  210. ----------------------------------
  211. 1) If SVE is disabled (``sve=off``), then which SVE vector lengths
  212. are enabled or disabled is irrelevant to the guest, as the entire
  213. SVE feature is disabled and that disables all vector lengths for
  214. the guest. However QEMU will still track any ``sve<N>`` CPU
  215. properties provided by the user. If later an ``sve=on`` is provided,
  216. then the guest will get only the enabled lengths. If no ``sve=on``
  217. is provided and there are explicitly enabled vector lengths, then
  218. an error is generated.
  219. 2) If SVE is enabled (``sve=on``), but no ``sve<N>`` CPU properties are
  220. provided, then all supported vector lengths are enabled, which when
  221. KVM is not in use means including the non-power-of-two lengths, and,
  222. when KVM is in use, it means all vector lengths supported by the host
  223. processor.
  224. 3) If SVE is enabled, then an error is generated when attempting to
  225. disable the last enabled vector length (see constraint (1) of "SVE
  226. CPU Property Dependencies and Constraints").
  227. 4) If one or more vector lengths have been explicitly enabled and at
  228. least one of the dependency lengths of the maximum enabled length
  229. has been explicitly disabled, then an error is generated (see
  230. constraint (2) of "SVE CPU Property Dependencies and Constraints").
  231. 5) When KVM is enabled, if the host does not support SVE, then an error
  232. is generated when attempting to enable any ``sve*`` properties (see
  233. constraint (3) of "SVE CPU Property Dependencies and Constraints").
  234. 6) When KVM is enabled, if the host does support SVE, then an error is
  235. generated when attempting to enable any vector lengths not supported
  236. by the host (see constraint (3) of "SVE CPU Property Dependencies and
  237. Constraints").
  238. 7) If one or more ``sve<N>`` CPU properties are set ``off``, but no ``sve<N>``,
  239. CPU properties are set ``on``, then the specified vector lengths are
  240. disabled but the default for any unspecified lengths remains enabled.
  241. When KVM is not enabled, disabling a power-of-two vector length also
  242. disables all vector lengths larger than the power-of-two length.
  243. When KVM is enabled, then disabling any supported vector length also
  244. disables all larger vector lengths (see constraint (2) of "SVE CPU
  245. Property Dependencies and Constraints").
  246. 8) If one or more ``sve<N>`` CPU properties are set to ``on``, then they
  247. are enabled and all unspecified lengths default to disabled, except
  248. for the required lengths per constraint (2) of "SVE CPU Property
  249. Dependencies and Constraints", which will even be auto-enabled if
  250. they were not explicitly enabled.
  251. 9) If SVE was disabled (``sve=off``), allowing all vector lengths to be
  252. explicitly disabled (i.e. avoiding the error specified in (3) of
  253. "SVE CPU Property Parsing Semantics"), then if later an ``sve=on`` is
  254. provided an error will be generated. To avoid this error, one must
  255. enable at least one vector length prior to enabling SVE.
  256. SVE CPU Property Examples
  257. -------------------------
  258. 1) Disable SVE::
  259. $ qemu-system-aarch64 -M virt -cpu max,sve=off
  260. 2) Implicitly enable all vector lengths for the ``max`` CPU type::
  261. $ qemu-system-aarch64 -M virt -cpu max
  262. 3) When KVM is enabled, implicitly enable all host CPU supported vector
  263. lengths with the ``host`` CPU type::
  264. $ qemu-system-aarch64 -M virt,accel=kvm -cpu host
  265. 4) Only enable the 128-bit vector length::
  266. $ qemu-system-aarch64 -M virt -cpu max,sve128=on
  267. 5) Disable the 512-bit vector length and all larger vector lengths,
  268. since 512 is a power-of-two. This results in all the smaller,
  269. uninitialized lengths (128, 256, and 384) defaulting to enabled::
  270. $ qemu-system-aarch64 -M virt -cpu max,sve512=off
  271. 6) Enable the 128-bit, 256-bit, and 512-bit vector lengths::
  272. $ qemu-system-aarch64 -M virt -cpu max,sve128=on,sve256=on,sve512=on
  273. 7) The same as (6), but since the 128-bit and 256-bit vector
  274. lengths are required for the 512-bit vector length to be enabled,
  275. then allow them to be auto-enabled::
  276. $ qemu-system-aarch64 -M virt -cpu max,sve512=on
  277. 8) Do the same as (7), but by first disabling SVE and then re-enabling it::
  278. $ qemu-system-aarch64 -M virt -cpu max,sve=off,sve512=on,sve=on
  279. 9) Force errors regarding the last vector length::
  280. $ qemu-system-aarch64 -M virt -cpu max,sve128=off
  281. $ qemu-system-aarch64 -M virt -cpu max,sve=off,sve128=off,sve=on
  282. SVE CPU Property Recommendations
  283. --------------------------------
  284. The examples in "SVE CPU Property Examples" exhibit many ways to select
  285. vector lengths which developers may find useful in order to avoid overly
  286. verbose command lines. However, the recommended way to select vector
  287. lengths is to explicitly enable each desired length. Therefore only
  288. example's (1), (4), and (6) exhibit recommended uses of the properties.
  289. SME CPU Property Examples
  290. -------------------------
  291. 1) Disable SME::
  292. $ qemu-system-aarch64 -M virt -cpu max,sme=off
  293. 2) Implicitly enable all vector lengths for the ``max`` CPU type::
  294. $ qemu-system-aarch64 -M virt -cpu max
  295. 3) Only enable the 256-bit vector length::
  296. $ qemu-system-aarch64 -M virt -cpu max,sme256=on
  297. 3) Enable the 256-bit and 1024-bit vector lengths::
  298. $ qemu-system-aarch64 -M virt -cpu max,sme256=on,sme1024=on
  299. 4) Disable the 512-bit vector length. This results in all the other
  300. lengths supported by ``max`` defaulting to enabled
  301. (128, 256, 1024 and 2048)::
  302. $ qemu-system-aarch64 -M virt -cpu max,sve512=off
  303. SVE User-mode Default Vector Length Property
  304. --------------------------------------------
  305. For qemu-aarch64, the cpu property ``sve-default-vector-length=N`` is
  306. defined to mirror the Linux kernel parameter file
  307. ``/proc/sys/abi/sve_default_vector_length``. The default length, ``N``,
  308. is in units of bytes and must be between 16 and 8192.
  309. If not specified, the default vector length is 64.
  310. If the default length is larger than the maximum vector length enabled,
  311. the actual vector length will be reduced. Note that the maximum vector
  312. length supported by QEMU is 256.
  313. If this property is set to ``-1`` then the default vector length
  314. is set to the maximum possible length.
  315. SME CPU Properties
  316. ==================
  317. The SME CPU properties are much like the SVE properties: ``sme`` is
  318. used to enable or disable the entire SME feature, and ``sme<N>`` is
  319. used to enable or disable specific vector lengths. Finally,
  320. ``sme_fa64`` is used to enable or disable ``FEAT_SME_FA64``, which
  321. allows execution of the "full a64" instruction set while Streaming
  322. SVE mode is enabled.
  323. SME is not supported by KVM at this time.
  324. At least one vector length must be enabled when ``sme`` is enabled,
  325. and all vector lengths must be powers of 2. The maximum vector
  326. length supported by qemu is 2048 bits. Otherwise, there are no
  327. additional constraints on the set of vector lengths supported by SME.
  328. SME User-mode Default Vector Length Property
  329. --------------------------------------------
  330. For qemu-aarch64, the cpu property ``sme-default-vector-length=N`` is
  331. defined to mirror the Linux kernel parameter file
  332. ``/proc/sys/abi/sme_default_vector_length``. The default length, ``N``,
  333. is in units of bytes and must be between 16 and 8192.
  334. If not specified, the default vector length is 32.
  335. As with ``sve-default-vector-length``, if the default length is larger
  336. than the maximum vector length enabled, the actual vector length will
  337. be reduced. If this property is set to ``-1`` then the default vector
  338. length is set to the maximum possible length.