kvm and cpu feature enablement

Upload: eduardo-habkost

Post on 06-Jul-2018

227 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/17/2019 KVM and CPU feature enablement

    1/29

    KVM and CPU feature

    enablementEduardo Habkost Developer Conference 2014

    mailto:[email protected]

  • 8/17/2019 KVM and CPU feature enablement

    2/29

    Agenda

    • Basic concepts

    • Existing mechanisms and current challenges

    • Current work and future plans

     2

  • 8/17/2019 KVM and CPU feature enablement

    3/29

    Basics

  • 8/17/2019 KVM and CPU feature enablement

    4/29

    Introduction: Basics

     4

    Host CPU

    (management)

    Kernel

    QEMU

    KVM

    VM

    Guest OS

    libvirt

  • 8/17/2019 KVM and CPU feature enablement

    5/29

    Introduction: Basics

     4

    command-line, monitor (QMP)

    Host CPU

    (management)

    Kernel

    QEMU

    KVM

    VM

    Guest OS

    libvirt

  • 8/17/2019 KVM and CPU feature enablement

    6/29

    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 shouldlook the same

     5

  • 8/17/2019 KVM and CPU feature enablement

    7/29

    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

  • 8/17/2019 KVM and CPU feature enablement

    8/29

    Existing Mechanisms

  • 8/17/2019 KVM and CPU feature enablement

    9/29

    CPUID handling

     8

    HOST CPU

    QEMU Guest OS

    Kernel

  • 8/17/2019 KVM and CPU feature enablement

    10/29

  • 8/17/2019 KVM and CPU feature enablement

    11/29

    CPUID handling

     8

    HOST CPU

    QEMU Guest OS

    CPUID table

    SET_CPUID

    Kernel

    GET_SUPPORTED_CPUID

    HostCPUID

    instruction

  • 8/17/2019 KVM and CPU feature enablement

    12/29

    CPUID handling

     8

    HOST CPU

    QEMU Guest OS

    CPUID table

    SET_CPUID

    Kernel

    GET_SUPPORTED_CPUID

    HostCPUID

    instruction emulateCPUID

    GuestCPUID

    instruction

  • 8/17/2019 KVM and CPU feature enablement

    13/29

    Host CPU

    (management)

    Kernel

    QEMU

    KVM

    VM

    Guest OS

    libvirt

    The Stack

     9

    Decision to enable afeature (should be) taken

    in the upper layers

    Lower layers affect the

    ability to enable a feature

  • 8/17/2019 KVM and CPU feature enablement

    14/29

    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

  • 8/17/2019 KVM and CPU feature enablement

    15/29

    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

  • 8/17/2019 KVM and CPU feature enablement

    16/29

    CPU models

    Special CPU model: -cpu host 

    • Will enable everything that’s supported by the

    host

    • No stable guest ABI

     12

  • 8/17/2019 KVM and CPU feature enablement

    17/29

    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

  • 8/17/2019 KVM and CPU feature enablement

    18/29

    Issues

  • 8/17/2019 KVM and CPU feature enablement

    19/29

    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

    QEMU

    CPU model list

  • 8/17/2019 KVM and CPU feature enablement

    20/29

    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 implementingCPU model and host

    capability APIs

     16

    X, Z

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

    (no Y) 

    (no Z)X, Y

  • 8/17/2019 KVM and CPU feature enablement

    21/29

    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

  • 8/17/2019 KVM and CPU feature enablement

    22/29

    Solutions

  • 8/17/2019 KVM and CPU feature enablement

    23/29

    Solutions

    • Existing interfaces: CPU-specific options and

    commands

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

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

     19

  • 8/17/2019 KVM and CPU feature enablement

    24/29

    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

  • 8/17/2019 KVM and CPU feature enablement

    25/29

    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

  • 8/17/2019 KVM and CPU feature enablement

    26/29

    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

  • 8/17/2019 KVM and CPU feature enablement

    27/29

    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

  • 8/17/2019 KVM and CPU feature enablement

    28/29

    Future

    • Reporting capabilities reliably smarter

    management systems

    • Usability (automatically choosing good defaults)

    Smarter VM scheduling

    • May require extending libvirt API

     24

  • 8/17/2019 KVM and CPU feature enablement

    29/29

    ThanksFeedback:

    http://devconf.cz/f/34

    Additional info / pointers:

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

    CPUModels

    [email protected]

    Questions?

    25

    http://wiki.qemu.org/Features/CPUModelshttp://devconf.cz/f/34