[Qemu-devel] [PATCH] docs: add guidance on configuring CPU models for x86

Daniel P. Berrangé posted 1 patch 5 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20180615141609.20749-1-berrange@redhat.com
Test checkpatch passed
Test docker-mingw@fedora passed
Test docker-quick@centos7 passed
Test s390x passed
There is a newer version of this series
MAINTAINERS             |   1 +
docs/cpu-models-x86.txt | 400 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 401 insertions(+)
create mode 100644 docs/cpu-models-x86.txt
[Qemu-devel] [PATCH] docs: add guidance on configuring CPU models for x86
Posted by Daniel P. Berrangé 5 years, 9 months ago
With the recent set of CPU hardware vulnerabilities on x86, it is
increasingly difficult to understand which CPU configurations are
good to use and what flaws they might be vulnerable to.

This doc attempts to help management applications and administrators in
picking sensible CPU configuration on x86 hosts. It outlines which of
the named CPU models are good choices, and describes which extra CPU
flags should be enabled to allow the guest to mitigate hardware flaws.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 MAINTAINERS             |   1 +
 docs/cpu-models-x86.txt | 400 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 401 insertions(+)
 create mode 100644 docs/cpu-models-x86.txt

diff --git a/MAINTAINERS b/MAINTAINERS
index 8a94517e9e..4dc1d60fef 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -285,6 +285,7 @@ S: Maintained
 F: target/i386/
 F: hw/i386/
 F: disas/i386.c
+F: docs/cpu-models-x86.txt
 T: git git://github.com/ehabkost/qemu.git x86-next
 
 Xtensa
diff --git a/docs/cpu-models-x86.txt b/docs/cpu-models-x86.txt
new file mode 100644
index 0000000000..719e5a4226
--- /dev/null
+++ b/docs/cpu-models-x86.txt
@@ -0,0 +1,400 @@
+         Recommendations for KVM CPU model configuration on x86 hosts
+	 ============================================================
+
+Available KVM CPU models and features
+=====================================
+
+KVM/QEMU virtualization supports two ways to configure CPU models
+
+ 1. Host passthrough
+
+    This passes the host CPU model features, model, stepping, exactly to the
+    guest. Note that KVM may filter out some host CPU model features if they
+    cannot be supported with virtualization. Live migration is unsafe when
+    this mode is used as libvirt / QEMU cannot guarantee a stable CPU is
+    exposed to the guest across hosts. This is the recommended CPU to use,
+    provided live migration is not required.
+
+ 2. Named model
+
+    QEMU comes with a number of predefined named CPU models, that typically
+    refer to specific generations of hardware released by Intel and AMD.
+    These allow the guest VMs to have a degree of isolation from the host CPU,
+    allowing greater flexibility in live migrating between hosts with differing
+    hardware.
+
+In both cases, it is possible to optionally add or remove individual CPU
+features, to alter what is presented to the guest by default.
+
+Libvirt supports a third way to configure CPU models known as "Host model".
+This uses the QEMU "Named model" feature, automatically picking a CPU model
+that is similar the host CPU, and then adding extra features to approximate
+the host model as closely as possible. This does not guarantee the CPU family,
+stepping, etc will precisely match the host CPU, as they would with "Host
+passthrough", but gives much of the benefit of passthrough, while making
+live migration safe.
+
+
+Preferred CPU models for Intel x86 hosts
+----------------------------------------
+
+The following CPU models are preferred for use on Intel hosts. Administrators /
+applications are recommended to use the CPU model that matches the generation
+of the host CPUs in use. In a deployment with a mixture of host CPU models
+between machines, if live migration compatibility is required, use the newest
+CPU model that is compatible across all desired hosts.
+
+- Skylake-Server
+- Skylake-Server-IBRS
+
+  Intel Xeon Processor (Skylake, 2016)
+
+
+- Skylake-Client
+- Skylake-Client-IBRS
+
+  Intel Core Processor (Skylake, 2015)
+
+
+- Broadwell
+- Broadwell-IBRS
+- Broadwell-noTSX
+- Broadwell-noTSX-IBRS
+
+  Intel Core Processor (Broadwell, 2014)
+
+
+- Haswell
+- Haswell-IBRS
+- Haswell-noTSX
+- Haswell-noTSX-IBRS
+
+  Intel Core Processor (Haswell, 2013)
+
+
+- IvyBridge
+- IvyBridge-IBRS
+
+  Intel Xeon E3-12xx v2 (Ivy Bridge, 2012)
+
+
+- SandyBridge
+- SandyBridge-IBRS
+
+  Intel Xeon E312xx (Sandy Bridge, 2011)
+
+
+- Westmere
+- Westmere-IBRS
+
+  Westmere E56xx/L56xx/X56xx (Nehalem-C, 2010)
+
+
+- Nehalem
+- Nehalem-IBRS
+
+  Intel Core i7 9xx (Nehalem Class Core i7, 2008)
+
+
+- Penryn
+
+  Intel Core 2 Duo P9xxx (Penryn Class Core 2, 2007)
+
+
+- Conroe
+
+  Intel Celeron_4x0 (Conroe/Merom Class Core 2, 2006)
+
+
+Important CPU features for Intel x86 hosts
+------------------------------------------
+
+The following are important CPU features that should be used on Intel x86
+hosts, when available in the host CPU. Some of them require explicit
+configuration to enable, as they are not included by default in some, or all,
+of the named CPU models listed above. In general all of these features are
+included if using "Host passthrough" or "Host model".
+
+
+ - pcid
+
+   Recommended to mitigate the cost of the Meltdown (CVE-2017-5754) fix
+
+   Included by default in Haswell, Broadwell & Skylake Intel CPU models.
+
+   Should be explicitly turned on for Westmere, SandyBridge, and IvyBridge
+   Intel CPU models. Note that some desktop/mobile Westmere CPUs cannot
+   support this feature.
+
+
+ - spec-ctrl
+
+   Required to enable the Spectre (CVE-2017-5753 and CVE-2017-5715) fix,
+   in cases where retpolines are not sufficient.
+
+   Included by default in Intel CPU models with -IBRS suffix.
+
+   Must be explicitly turned on for Intel CPU models without -IBRS suffix.
+
+   Requires the host CPU microcode to support this feature before it
+   can be used for guest CPUs.
+
+
+ - ssbd
+
+   Required to enable the CVE-2018-3639 fix
+
+   Not included by default in any Intel CPU model.
+
+   Must be explicitly turned on for all Intel CPU models.
+
+   Requires the host CPU microcode to support this feature before it
+   can be used for guest CPUs.
+
+
+ - pdpe1gb
+
+   Recommended to allow guest OS to use 1GB size pages
+
+   Not included by default in any Intel CPU model.
+
+   Should be explicitly turned on for all Intel CPU models.
+
+   Note that not all CPU hardware will support this feature.
+
+
+
+Preferred CPU models for AMD x86 hosts
+--------------------------------------
+
+The following CPU models are preferred for use on Intel hosts. Administrators /
+applications are recommended to use the CPU model that matches the generation
+of the host CPUs in use. In a deployment with a mixture of host CPU models
+between machines, if live migration compatibility is required, use the newest
+CPU model that is compatible across all desired hosts.
+
+- EPYC
+- EPYC-IBPB
+
+  AMD EPYC Processor (2017)
+
+
+- Opteron_G5
+
+  AMD Opteron 63xx class CPU (2012)
+
+
+- Opteron_G4
+
+  AMD Opteron 62xx class CPU (2011)
+
+
+- Opteron_G3
+
+  AMD Opteron 23xx (Gen 3 Class Opteron, 2009)
+
+
+- Opteron_G2
+
+  AMD Opteron 22xx (Gen 2 Class Opteron, 2006)
+
+
+- Opteron_G1
+
+  AMD Opteron 240 (Gen 1 Class Opteron, 2004)
+
+
+Important CPU features for AMD x86 hosts
+----------------------------------------
+
+The following are important CPU features that should be used on AMD x86
+hosts, when available in the host CPU. Some of them require explicit
+configuration to enable, as they are not included by default in some, or all,
+of the named CPU models listed above. In general all of these features are
+included if using "Host passthrough" or "Host model".
+
+
+ - ibpb
+
+   Required to enable the Spectre (CVE-2017-5753 and CVE-2017-5715) fix,
+   in cases where retpolines are not sufficient.
+
+   Included by default in AMD CPU models with -IBPB suffix.
+
+   Must be explicitly turned on for AMD CPU models without -IBPB suffix.
+
+   Requires the host CPU microcode to support this feature before it
+   can be used for guest CPUs.
+
+
+ - virt-ssbd
+
+   Required to enable the CVE-2018-3639 fix
+
+   Not included by default in any AMD CPU model.
+
+   Must be explicitly turned on for all AMD CPU models.
+
+   This should be provided to guests, even if amd-ssbd is also
+   provided, for maximum guest compatibility.
+
+   Note for some QEMU / libvirt versions, this must be force enabled
+   when when using "Host model", because this is a virtual feature
+   that doesn't exist in the physical host CPUs.
+
+
+ - amd-ssbd
+
+   Required to enable the CVE-2018-3639 fix
+
+   Not included by default in any AMD CPU model.
+
+   Must be explicitly turned on for all AMD CPU models.
+
+   This provides higher performance than virt-ssbd so should be
+   exposed to guests whenever available in the host. virt-ssbd
+   should none the less also be exposed for maximum guest
+   compatability as some kernels only know about virt-ssbd.
+
+
+ - amd-no-ssb
+
+   Recommended to indicate the host is not vulnerable CVE-2018-3639
+
+   Not included by default in any AMD CPU model.
+
+   Future hardware genarations of CPU will not be vulnerable to
+   CVE-2018-3639, and thus the guest should be told not to enable
+   its mitigations, by exposing amd-no-ssb. This is mutually
+   exclusive with virt-ssbd and amd-ssbd.
+
+
+ - pdpe1gb
+
+   Recommended to allow guest OS to use 1GB size pages
+
+   Not included by default in any AMD CPU model.
+
+   Should be explicitly turned on for all AMD CPU models.
+
+   Note that not all CPU hardware will support this feature.
+
+
+Default x86 CPU models
+----------------------
+
+The default QEMU CPU models are designed such that they can run on all hosts.
+If an application does not wish to do perform any host compatibility checks
+before launching guests, the default is guaranteed to work.
+
+The default CPU models will, however, leave the guest OS vulnerable to various
+CPU hardware flaws, so their use is strongly discouraged. Applications should
+follow the guidance earlier to setup a better CPU configuration, with host
+passthrough recommended if live migration is not needed.
+
+- qemu32
+- qemu64
+
+  QEMU Virtual CPU version 2.5+ (32 & 64 bit variants)
+
+  qemu64 is used for x86_64 guests and qemu32 is used for i686 guests, when no
+  -cpu argument is given to QEMU, or no <cpu> is provided in libvirt XML.
+
+
+Other non-recommended x86 CPUs
+------------------------------
+
+The following CPUs models are compatible with most AMD and Intel x86 hosts, but
+their usage is discouraged, as they expose a very limited featureset, which
+prevents guests having optimal performance.
+
+- kvm32
+- kvm64
+
+  Common KVM processor (32 & 64 bit variants)
+
+  Legacy models just for historical compatibility with ancient QEMU versions.
+
+
+- 486
+- athlon
+- phenom
+- coreduo
+- core2duo
+- n270
+- pentium
+- pentium2
+- pentium3
+
+  Various very old x86 CPU models, mostly predating the introduction of
+  hardware assisted virtualization, that should thus not be required for
+  running virtual machines.
+
+
+Syntax for configuring CPU models in various applications
+=========================================================
+
+The example below illustrate the approach to configuring the various
+CPU models / features in different applications.
+
+QEMU command line
+------------------
+
+* Host passthrough:
+
+   $ qemu-system-x86_64 -cpu host
+
+   With feature customization:
+
+   $ qemu-system-x86_64 -cpu host,-vmx,...
+
+
+* Named CPU models:
+
+   $ qemu-system-x86_64 -cpu Westmere
+
+   With feature customization:
+
+   $ qemu-system-x86_64 -cpu Westmere,+pcid,...
+
+
+Libvirt guest XML
+-----------------
+
+* Host passthrough
+
+   <cpu mode='host-passthrough'/>
+
+   With feature customization:
+
+   <cpu mode='host-passthrough'>
+       <feature name="vmx" policy="disable"/>
+       ...
+   </cpu>
+
+
+* Host model
+
+   <cpu mode='host-model'/>
+
+   With feature customization:
+
+   <cpu mode='host-model'>
+       <feature name="vmx" policy="disable"/>
+       ...
+   </cpu>
+
+
+* Named model
+
+   <cpu mode='custom'>
+       <model name="Westmere"/>
+   </cpu>
+
+   With feature customization:
+
+   <cpu mode='custom'>
+       <model name="Westmere"/>
+       <feature name="pcid" policy="require"/>
+       ...
+   </cpu>
-- 
2.17.0


Re: [Qemu-devel] [PATCH] docs: add guidance on configuring CPU models for x86
Posted by Eduardo Habkost 5 years, 9 months ago
On Fri, Jun 15, 2018 at 03:16:09PM +0100, Daniel P. Berrangé wrote:
> With the recent set of CPU hardware vulnerabilities on x86, it is
> increasingly difficult to understand which CPU configurations are
> good to use and what flaws they might be vulnerable to.
> 
> This doc attempts to help management applications and administrators in
> picking sensible CPU configuration on x86 hosts. It outlines which of
> the named CPU models are good choices, and describes which extra CPU
> flags should be enabled to allow the guest to mitigate hardware flaws.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Thank you very much.

I wonder how we could reference this from the man page and
qemu-doc.html without saying "look at the QEMU source tree".

(I'm not willing to rewrite this using texinfo to make that
happen.)


-- 
Eduardo

Re: [Qemu-devel] [PATCH] docs: add guidance on configuring CPU models for x86
Posted by Markus Armbruster 5 years, 9 months ago
Eduardo Habkost <ehabkost@redhat.com> writes:

> On Fri, Jun 15, 2018 at 03:16:09PM +0100, Daniel P. Berrangé wrote:
>> With the recent set of CPU hardware vulnerabilities on x86, it is
>> increasingly difficult to understand which CPU configurations are
>> good to use and what flaws they might be vulnerable to.
>> 
>> This doc attempts to help management applications and administrators in
>> picking sensible CPU configuration on x86 hosts. It outlines which of
>> the named CPU models are good choices, and describes which extra CPU
>> flags should be enabled to allow the guest to mitigate hardware flaws.
>> 
>> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
>
> Thank you very much.
>
> I wonder how we could reference this from the man page and
> qemu-doc.html without saying "look at the QEMU source tree".

Same way as the other contents there.

> (I'm not willing to rewrite this using texinfo to make that
> happen.)

Texinfo is simple.

If all else fails, ask for my help after soft freeze.

Re: [Qemu-devel] [PATCH] docs: add guidance on configuring CPU models for x86
Posted by Kashyap Chamarthy 5 years, 9 months ago
On Mon, Jun 18, 2018 at 08:03:32AM +0200, Markus Armbruster wrote:
> Eduardo Habkost <ehabkost@redhat.com> writes:
> 
> > On Fri, Jun 15, 2018 at 03:16:09PM +0100, Daniel P. Berrangé wrote:
> >> With the recent set of CPU hardware vulnerabilities on x86, it is
> >> increasingly difficult to understand which CPU configurations are
> >> good to use and what flaws they might be vulnerable to.
> >> 
> >> This doc attempts to help management applications and administrators in
> >> picking sensible CPU configuration on x86 hosts. It outlines which of
> >> the named CPU models are good choices, and describes which extra CPU
> >> flags should be enabled to allow the guest to mitigate hardware flaws.
> >> 
> >> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> >
> > Thank you very much.
> >
> > I wonder how we could reference this from the man page and
> > qemu-doc.html without saying "look at the QEMU source tree".
> 
> Same way as the other contents there.
> 
> > (I'm not willing to rewrite this using texinfo to make that
> > happen.)
> 
> Texinfo is simple.
> 
> If all else fails, ask for my help after soft freeze.

If someone already hasn't done it, I can help rewrite it.  (It'll let me
try out 'Texinfo' in real and I have to deal with CPU modelling aspects
elsewhere in the higher-level tools. :-))

-- 
/kashyap

Re: [Qemu-devel] [PATCH] docs: add guidance on configuring CPU models for x86
Posted by Kashyap Chamarthy 5 years, 9 months ago
On Mon, Jun 25, 2018 at 10:18:59AM +0200, Kashyap Chamarthy wrote:
> On Mon, Jun 18, 2018 at 08:03:32AM +0200, Markus Armbruster wrote:
> > Eduardo Habkost <ehabkost@redhat.com> writes:

[...]

> > Texinfo is simple.
> > 
> > If all else fails, ask for my help after soft freeze.
> 
> If someone already hasn't done it, I can help rewrite it.  (It'll let me
> try out 'Texinfo' in real and I have to deal with CPU modelling aspects
> elsewhere in the higher-level tools. :-))

Oops, Dan already did it in v2.  Please disregard the above.

(Sorry for the noise.)

-- 
/kashyap