29
KVM and CPU feature enablement Eduardo Habkost <[email protected]> Developer Conference 2014

KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost Developer Conference 2014. Agenda • Basic concepts • Existing

  • Upload
    others

  • View
    23

  • Download
    0

Embed Size (px)

Citation preview

Page 1: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

KVM and CPU feature enablement

Eduardo Habkost <[email protected]> Developer Conference 2014

Page 2: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Agenda

• Basic concepts

• Existing mechanisms and current challenges

• Current work and future plans

!2

Page 3: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Basics

Page 4: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Introduction: Basics

!4

Host CPU

(management)

Kernel

QEMU

KVM

VM

Guest OS

libvirt

Page 5: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Introduction: Basics

!4

command-line, monitor (QMP)

Host CPU

(management)

Kernel

QEMU

KVM

VM

Guest OS

libvirt

Page 6: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Introduction: Stable guest ABI

• Guest OS should see the “same” machine, even if the host system has changed

• Hard requirement for live migration

• Soft requirement for non-live migration

• Host system may change a lot, but VM should look the same

!5

Page 7: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

x86 CPUID instruction• Returns information about the running CPU

• Most information shown on /proc/cpuinfo

• Feature flags indicating a feature is present

• Other more complex data

• e.g.: cache and topology information

• CPUID data is part of guest ABI

!6

Page 8: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Existing Mechanisms

Page 9: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

CPUID handling

!8

HOST CPU

QEMU Guest OS

Kernel

Page 10: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

CPUID handling

!8

HOST CPU

QEMU Guest OS

Kernel

GET_SUPPORTED_CPUID

Host CPUID

instruction

Page 11: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

CPUID handling

!8

HOST CPU

QEMU Guest OS

CPUID table

SET_CPUID

Kernel

GET_SUPPORTED_CPUID

Host CPUID

instruction

Page 12: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

CPUID handling

!8

HOST CPU

QEMU Guest OS

CPUID table

SET_CPUID

Kernel

GET_SUPPORTED_CPUID

Host CPUID

instruction emulate CPUID

Guest CPUID

instruction

Page 13: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Host CPU

(management)

Kernel

QEMU

KVM

VM

Guest OS

libvirt

The Stack

!9

Decision to enable a feature (should be) taken

in the upper layers

Lower layers affect the ability to enable a feature

Page 14: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Enabling new features

• We can't silently enable or disable a feature:

• It breaks guest ABI

• May unexpectedly prevent migration to other (less powerful) hosts

!10

Page 15: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

CPU models• CPU model table, different CPUID data on each entry

• qemu-system-x86_64 -cpu SandyBridge

• qemu-system-x86_64 -cpu Haswell

• Controlling individual features. e.g.: -cpu Nehalem,+aes

• CPU model entries may change, machine-types keep compatibility

• qemu-system-x86_64 -machine pc-1.6 -cpu SandyBridge

• qemu-system-x86_64 -machine pc-1.7 -cpu SandyBridge

• enforce flag. e.g.: -cpu SandyBridge,enforce

• Required to ensure predictable results

!11

Page 16: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

CPU models

• Special CPU model: -cpu host

• Will enable everything that’s supported by the host

• No stable guest ABI

!12

Page 17: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Management requirements

• Ensuring that the resulting CPUID data is what was asked for

• Knowing which CPU models can be enabled in a host

• Knowing which features are available in a host

• Knowing to which hosts a VM can be migrated

!13

Page 18: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Issues

Page 19: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Host CPU

(management)

Kernel

QEMU

KVM

VM

Guest OS

libvirt

Problem: querying CPU model information

• libvirt has its own list of CPU models

• libvirt doesn't know QEMU CPU models can change over time

• QEMU's fault, there's no good API for that (yet!)

!15

CPU model list

QEMUCPU model list

Page 20: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Host CPU

(management)

Kernel

QEMU

KVM

VM

Guest OS

libvirt

Problem: no “enforce” mode

• libvirt doesn’t use the enforce flag

• Error reporting not machine-friendly

• Most serious issue so far

• Fix involves implementing CPU model and host capability APIs

!16

X, Z

-cpu …,+X,+Y,+Z

X!(no Y)!(no Z)X, Y

Page 21: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Host CPU

(management)

Kernel

QEMU

KVM

VM

Guest OS

libvirt

Problem: querying host capabilities

• libvirt queries host CPU features directly using CPUID instruction

• Ignores KVM capabilities

• Ignores QEMU capabilities

• Ignores features that require extra CPU capabilities

• QEMU’s fault, there’s no good API for that (yet!)

!17

Page 22: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Solutions

Page 23: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Solutions

• Existing interfaces: CPU-specific options and commands

• -cpu, cpu-add, query-cpu-definitions

• New interfaces: based on common infrastructure (QDev, QOM)

!19

Page 24: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

QDev• QDev = QEMU Device Model

• QOM = QEMU Object Model

• QDev devices are QOM objects

• -device command-line option

• QMP commands:

• Adding devices/objects (device_add, object-add)

• Removing devices/objects (device_del, object-del)

• Getting/setting devices properties (qom-get, qom-set)

• Listing objects and object classes (qom-list, qom-list-types)

!20

Page 25: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

QDev-based solution• CPUs are QDev devices (done)

• CPU devices and its properties visible through QMP

• feature-words property (done)

• Query CPU model info

• Query host capabilities (“host” CPU model)

• Incomplete: no machine-type-specific data

• filtered-features property (done)

• Used to emulate “enforce" mode with better error reporting

• Not used by libvirt yet

!21

Page 26: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

What’s missing (1/2)• Querying CPU model information without re-running

QEMU

• Solution: separate QOM types for each CPU model

• Exposing machine-type-specific data

• No defined solution yet

• Use QOM properties to control all feature flags

• Changing libvirt to use the new stuff

!22

Page 27: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

What’s missing (2/2)

• Long term plans:

• Deprecate -cpu, cpu-add and use only QDev commands(-device, device_add)

• Better interfaces to specify CPU topology (NUMA nodes, sockets, cores, threads)

!23

Page 28: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

Future

• Reporting capabilities reliably ⇒ smarter management systems

• Usability (automatically choosing good defaults)

• Smarter VM scheduling

• May require extending libvirt API

!24

Page 29: KVM and CPU feature enablement - QEMU€¦ · KVM and CPU feature enablement Eduardo Habkost  Developer Conference 2014. Agenda • Basic concepts • Existing

ThanksFeedback:

http://devconf.cz/f/34

!

Additional info / pointers:

http://wiki.qemu.org/Features/CPUModels

[email protected]

!

Questions?

!25