Kashyap Chamarthy - Effective Virtual CPU Configuration OSS EU2018
Kashyap Chamarthy - Effective Virtual CPU Configuration OSS EU2018
and libvirt
1 / 38
Timeline of recent CPU flaws, 2018 (a)
... • ?
3 / 38
What this talk is not about
4 / 38
What this talk is not about
Out of scope:
Internals of various side-channel attacks
How to exploit Meltdown & Spectre variants
Details of performance implications
4 / 38
What this talk is not about
Out of scope:
Internals of various side-channel attacks
How to exploit Meltdown & Spectre variants
Details of performance implications
4 / 38
KVM-based virtualization components
QEMU QEMU
VM1 VM2
Disk1 Disk2 ioctl()
libvirtd
P QM
QM P
QEMU QEMU
VM1 VM2
Disk1 Disk2 ioctl()
libvirtd
P QM
QM P
QEMU QEMU
VM1 VM2
Disk1 Disk2 ioctl()
QEMU QEMU
VM1 VM2
Custom
Disk1 Disk2 ioctl()
Appliance
vCPU-1 vCPU-2
ioctl()→/dev/kvm
vCPU-1 vCPU-2
To inspect, use
ioctl()→/dev/kvm
QEMU issues
ioctl(KVM_RUN) Perform in-kernel
emulation
Execute natively
VMEXIT
in Guest Mode.
(CPU with VMX)
QEMU emulates Yes
hardware
Emulate
in-kernel?
No
7 / 38
Part I
Interfaces to configure vCPUs
8 / 38
x86: QEMU’s default CPU models (a)
9 / 38
x86: QEMU’s default CPU models (a)
9 / 38
x86: QEMU’s default CPU models (a)
9 / 38
x86: QEMU’s default CPU models (b)
$ cd /sys/devices/system/cpu/vulnerabilities/
$ grep . *
l1tf:Mitigation: PTE Inversion
meltdown:Mitigation: PTI
spec_store_bypass:Vulnerable
spectre_v1:Mitigation: __user pointer sanitization
spectre_v2:Mitigation: Full generic retpoline
10 / 38
x86: QEMU’s default CPU models (b)
$ cd /sys/devices/system/cpu/vulnerabilities/
$ grep . * On a guest running with qemu64
l1tf:Mitigation: PTE Inversion
meltdown:Mitigation: PTI
spec_store_bypass:Vulnerable
spectre_v1:Mitigation: __user pointer sanitization
spectre_v2:Mitigation: Full generic retpoline
10 / 38
x86: QEMU’s default CPU models (b)
$ cd /sys/devices/system/cpu/vulnerabilities/
$ grep . *
l1tf:Mitigation: PTE Inversion
meltdown:Mitigation: PTI
spec_store_bypass:Vulnerable
spectre_v1:Mitigation:
Spectre-NG __user pointer sanitization
spectre_v2:Mitigation: Full generic retpoline
10 / 38
x86: QEMU’s default CPU models (b)
$ cd /sys/devices/system/cpu/vulnerabilities/
$ grep . *
l1tf:Mitigation: PTE Inversion
meltdown:Mitigation: PTI
spec_store_bypass:Vulnerable
spectre_v1:Mitigation: __user pointer sanitization
spectre_v2:Mitigation: Full generic retpoline
11 / 38
Defaults of other architectures
11 / 38
Defaults of other architectures
11 / 38
Configure CPU on the command-line
12 / 38
Configure CPU on the command-line
12 / 38
Configure CPU on the command-line
12 / 38
Control guest CPU features
13 / 38
Control guest CPU features
13 / 38
Control guest CPU features
13 / 38
Control guest CPU features
13 / 38
QEMU’s CPU-related run-time interfaces
16 / 38
Host passthrough
17 / 38
Host passthrough
Caveats:
No guarantee of a stable CPU for the guest
17 / 38
Host passthrough
Caveats:
No guarantee of a stable CPU for the guest
Live migration is a no go with mixed host CPUs
17 / 38
Host passthrough
Caveats:
No guarantee of a stable CPU for the guest
Live migration is a no go with mixed host CPUs
18 / 38
Host passthrough – when else to use it?
19 / 38
QEMU’s named CPU models (a)
Virtual CPUs typically model physical CPUs
21 / 38
‘host-model’ – a libvirt abstraction
21 / 38
‘host-model’ – a libvirt abstraction
21 / 38
‘host-model’ – example libvirt config
22 / 38
‘host-model’ and live migration
As done by libvirt:
Source vCPU definition is transferred as-is to the target
On target: Migrated guest sees the same vCPU model
23 / 38
‘host-model’ and live migration
As done by libvirt:
Source vCPU definition is transferred as-is to the target
On target: Migrated guest sees the same vCPU model
But: When the guest ‘cold boots’, it may pick up extra
CPU features—prevents migrating back to the source
23 / 38
OpenStack Nova and CPU models
Provides relevant config attributes:
cpu_mode
Can be: custom, host-passthrough; or host-model
cpu_model & cpu_model_extra_flags
Refer to libvirt’s /usr/share/libvirt/cpu_map/*.xml
Or QEMU’s: qemu-system-x86_64 -cpu help
24 / 38
Part III
Choosing CPU models & features
25 / 38
Finding compatible CPU models
26 / 38
Finding compatible CPU models
27 / 38
Finding compatible CPU models
27 / 38
Intersection between these two host CPUs?
$ cat Multiple-Host-CPUs.xml
<cpu mode=’custom’ match=’exact’>
<model fallback=’forbid’>Haswell-noTSX-IBRS</model>
<vendor>Intel</vendor>
<feature policy=’require’ name=’vmx’/>
<feature policy=’require’ name=’rdrand’/>
</cpu>
<!–- Second CPU –->
<cpu mode=’custom’ match=’exact’>
<model fallback=’forbid’>Skylake-Client-IBRS</model>
<vendor>Intel</vendor>
<feature policy=’disable’ name=’pdpe1gb’/>
<feature policy=’disable’ name=’pcid’/>
</cpu>
28 / 38
Intersection between these two host CPUs?
$ cat Multiple-Host-CPUs.xml
<cpu mode=’custom’ match=’exact’>
Haswell-noTSX-IBRS</model>
<model fallback=’forbid’>Haswell-noTSX-IBRS
<vendor>Intel</vendor>
<feature policy=’require’ name=’vmx’/>
<feature policy=’require’ name=’rdrand’/> Two CPU
</cpu> models
<!–- Second CPU –->
<cpu mode=’custom’ match=’exact’>
<model fallback=’forbid’>Skylake-Client-IBRS
Skylake-Client-IBRS</model>
<vendor>Intel</vendor>
<feature policy=’disable’ name=’pdpe1gb’/>
<feature policy=’disable’ name=’pcid’/>
</cpu>
28 / 38
Use baselineHypervisorCPU() to determine it
29 / 38
Use baselineHypervisorCPU() to determine it
29 / 38
Use baselineHypervisorCPU() to determine it
29 / 38
x86: QEMU’s “machine types”
30 / 38
x86: QEMU’s “machine types”
30 / 38
x86: QEMU’s “machine types”
30 / 38
x86: QEMU’s “machine types” – versioned
$ qemu-system-x86_64 -machine help
...
pc Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-3.0)
pc-i440fx-3.0 Standard PC (i440FX + PIIX, 1996) (default)
pc-i440fx-2.9 Standard PC (i440FX + PIIX, 1996)
...
q35 Standard PC (Q35 + ICH9, 2009) (alias of pc-q35-3.0)
pc-q35-3.0 Standard PC (Q35 + ICH9, 2009)
pc-q35-2.9 Standard PC (Q35 + ICH9, 2009)
pc-q35-2.8 Standard PC (Q35 + ICH9, 2009)
...
31 / 38
x86: QEMU’s “machine types” – versioned
$ qemu-system-x86_64 -machine help
...
pc Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-3.0)
pc-i440fx-3.0 Standard PC (i440FX + PIIX, 1996) (default)
pc-i440fx-2.9 Standard PC (i440FX + PIIX, 1996)
Traditional
...
q35 Standard PC (Q35 + ICH9, 2009) (alias of pc-q35-3.0)
pc-q35-3.0 Standard PC (Q35 + ICH9, 2009)
pc-q35-2.9 Standard PC (Q35 + ICH9, 2009)
pc-q35-2.8 Standard PC (Q35 + ICH9, 2009)
...
31 / 38
x86: QEMU’s “machine types” – versioned
$ qemu-system-x86_64 -machine help
...
pc Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-3.0)
pc-i440fx-3.0 Standard PC (i440FX + PIIX, 1996) (default)
pc-i440fx-2.9 Standard PC (i440FX + PIIX, 1996)
...
q35 Standard PC (Q35 + ICH9, 2009) (alias of pc-q35-3.0)
pc-q35-3.0 Standard PC (Q35 + ICH9, 2009)
Recommended Standard PC (Q35 + ICH9, 2009)
pc-q35-2.9
pc-q35-2.8 Standard PC (Q35 + ICH9, 2009)
...
32 / 38
Machine types and CPU features
Changing machine types is guest-visible
33 / 38
x86: Recommended guest CPU models
33 / 38
x86: Recommended guest CPU models
Guidance: qemu/docs/qemu-cpu-models.texi
(Thanks, Daniel Berrangé)
33 / 38
x86: Important CPU flags
34 / 38
x86: Important CPU flags
34 / 38
Future ‘expectations’ from applications?
36 / 38
Questions?
E-mail: [email protected]
IRC: kashyap – Freenode & OFTC
37 / 38
Related talks at the KVM Forum
38 / 38