KVM CPUID bits

Author:Glauber Costa <glommer@gmail.com>

A guest running on a kvm host, can check some of its features usingcpuid. This is not always guaranteed to work, since userspace canmask-out some, or even all KVM-related cpuid features before launchinga guest.

KVM cpuid functions are:

function: KVM_CPUID_SIGNATURE (0x40000000)

returns:

eax = 0x40000001ebx = 0x4b4d564becx = 0x564b4d56edx = 0x4d

Note that this value in ebx, ecx and edx corresponds to the string “KVMKVMKVM”.The value in eax corresponds to the maximum cpuid function present in this leaf,and will be updated if more functions are added in the future.Note also that old hosts set eax value to 0x0. This shouldbe interpreted as if the value was 0x40000001.This function queries the presence of KVM cpuid leafs.

function: define KVM_CPUID_FEATURES (0x40000001)

returns:

ebx, ecxeax = an OR'ed group of (1 << flag)

whereflag is defined as below:

flagvaluemeaning
KVM_FEATURE_CLOCKSOURCE0kvmclock available at msrs0x11 and 0x12
KVM_FEATURE_NOP_IO_DELAY1not necessary to perform delayson PIO operations
KVM_FEATURE_MMU_OP2deprecated
KVM_FEATURE_CLOCKSOURCE23kvmclock available at msrs0x4b564d00 and 0x4b564d01
KVM_FEATURE_ASYNC_PF4async pf can be enabled bywriting to msr 0x4b564d02
KVM_FEATURE_STEAL_TIME5steal time can be enabled bywriting to msr 0x4b564d03
KVM_FEATURE_PV_EOI6paravirtualized end of interrupthandler can be enabled bywriting to msr 0x4b564d04
KVM_FEATURE_PV_UNHAULT7guest checks this feature bitbefore enabling paravirtualizedspinlock support
KVM_FEATURE_PV_TLB_FLUSH9guest checks this feature bitbefore enabling paravirtualizedtlb flush
KVM_FEATURE_ASYNC_PF_VMEXIT10paravirtualized async PF VM EXITcan be enabled by setting bit 2when writing to msr 0x4b564d02
KVM_FEATURE_PV_SEND_IPI11guest checks this feature bitbefore enabling paravirtualizedsebd IPIs
KVM_FEATURE_PV_POLL_CONTROL12host-side polling on HLT canbe disabled by writingto msr 0x4b564d05.
KVM_FEATURE_PV_SCHED_YIELD13guest checks this feature bitbefore using paravirtualizedsched yield.
KVM_FEATURE_ASYNC_PF_INT14guest checks this feature bitbefore using the second asyncpf control msr 0x4b564d06 andasync pf acknowledgment msr0x4b564d07.
KVM_FEATURE_CLOCSOURCE_STABLE_BIT24host will warn if no guest-sideper-cpu warps are expeced inkvmclock
edx = an OR'ed group of (1 << flag)

Whereflag here is defined as below:

flagvaluemeaning
KVM_HINTS_REALTIME0guest checks this feature bit todetermine that vCPUs are neverpreempted for an unlimited timeallowing optimizations