1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun============== 4*4882a593SmuzhiyunKVM CPUID bits 5*4882a593Smuzhiyun============== 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun:Author: Glauber Costa <glommer@gmail.com> 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunA guest running on a kvm host, can check some of its features using 10*4882a593Smuzhiyuncpuid. This is not always guaranteed to work, since userspace can 11*4882a593Smuzhiyunmask-out some, or even all KVM-related cpuid features before launching 12*4882a593Smuzhiyuna guest. 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunKVM cpuid functions are: 15*4882a593Smuzhiyun 16*4882a593Smuzhiyunfunction: KVM_CPUID_SIGNATURE (0x40000000) 17*4882a593Smuzhiyun 18*4882a593Smuzhiyunreturns:: 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun eax = 0x40000001 21*4882a593Smuzhiyun ebx = 0x4b4d564b 22*4882a593Smuzhiyun ecx = 0x564b4d56 23*4882a593Smuzhiyun edx = 0x4d 24*4882a593Smuzhiyun 25*4882a593SmuzhiyunNote that this value in ebx, ecx and edx corresponds to the string "KVMKVMKVM". 26*4882a593SmuzhiyunThe value in eax corresponds to the maximum cpuid function present in this leaf, 27*4882a593Smuzhiyunand will be updated if more functions are added in the future. 28*4882a593SmuzhiyunNote also that old hosts set eax value to 0x0. This should 29*4882a593Smuzhiyunbe interpreted as if the value was 0x40000001. 30*4882a593SmuzhiyunThis function queries the presence of KVM cpuid leafs. 31*4882a593Smuzhiyun 32*4882a593Smuzhiyunfunction: define KVM_CPUID_FEATURES (0x40000001) 33*4882a593Smuzhiyun 34*4882a593Smuzhiyunreturns:: 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun ebx, ecx 37*4882a593Smuzhiyun eax = an OR'ed group of (1 << flag) 38*4882a593Smuzhiyun 39*4882a593Smuzhiyunwhere ``flag`` is defined as below: 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun================================== =========== ================================ 42*4882a593Smuzhiyunflag value meaning 43*4882a593Smuzhiyun================================== =========== ================================ 44*4882a593SmuzhiyunKVM_FEATURE_CLOCKSOURCE 0 kvmclock available at msrs 45*4882a593Smuzhiyun 0x11 and 0x12 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunKVM_FEATURE_NOP_IO_DELAY 1 not necessary to perform delays 48*4882a593Smuzhiyun on PIO operations 49*4882a593Smuzhiyun 50*4882a593SmuzhiyunKVM_FEATURE_MMU_OP 2 deprecated 51*4882a593Smuzhiyun 52*4882a593SmuzhiyunKVM_FEATURE_CLOCKSOURCE2 3 kvmclock available at msrs 53*4882a593Smuzhiyun 0x4b564d00 and 0x4b564d01 54*4882a593Smuzhiyun 55*4882a593SmuzhiyunKVM_FEATURE_ASYNC_PF 4 async pf can be enabled by 56*4882a593Smuzhiyun writing to msr 0x4b564d02 57*4882a593Smuzhiyun 58*4882a593SmuzhiyunKVM_FEATURE_STEAL_TIME 5 steal time can be enabled by 59*4882a593Smuzhiyun writing to msr 0x4b564d03 60*4882a593Smuzhiyun 61*4882a593SmuzhiyunKVM_FEATURE_PV_EOI 6 paravirtualized end of interrupt 62*4882a593Smuzhiyun handler can be enabled by 63*4882a593Smuzhiyun writing to msr 0x4b564d04 64*4882a593Smuzhiyun 65*4882a593SmuzhiyunKVM_FEATURE_PV_UNHALT 7 guest checks this feature bit 66*4882a593Smuzhiyun before enabling paravirtualized 67*4882a593Smuzhiyun spinlock support 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunKVM_FEATURE_PV_TLB_FLUSH 9 guest checks this feature bit 70*4882a593Smuzhiyun before enabling paravirtualized 71*4882a593Smuzhiyun tlb flush 72*4882a593Smuzhiyun 73*4882a593SmuzhiyunKVM_FEATURE_ASYNC_PF_VMEXIT 10 paravirtualized async PF VM EXIT 74*4882a593Smuzhiyun can be enabled by setting bit 2 75*4882a593Smuzhiyun when writing to msr 0x4b564d02 76*4882a593Smuzhiyun 77*4882a593SmuzhiyunKVM_FEATURE_PV_SEND_IPI 11 guest checks this feature bit 78*4882a593Smuzhiyun before enabling paravirtualized 79*4882a593Smuzhiyun send IPIs 80*4882a593Smuzhiyun 81*4882a593SmuzhiyunKVM_FEATURE_POLL_CONTROL 12 host-side polling on HLT can 82*4882a593Smuzhiyun be disabled by writing 83*4882a593Smuzhiyun to msr 0x4b564d05. 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunKVM_FEATURE_PV_SCHED_YIELD 13 guest checks this feature bit 86*4882a593Smuzhiyun before using paravirtualized 87*4882a593Smuzhiyun sched yield. 88*4882a593Smuzhiyun 89*4882a593SmuzhiyunKVM_FEATURE_ASYNC_PF_INT 14 guest checks this feature bit 90*4882a593Smuzhiyun before using the second async 91*4882a593Smuzhiyun pf control msr 0x4b564d06 and 92*4882a593Smuzhiyun async pf acknowledgment msr 93*4882a593Smuzhiyun 0x4b564d07. 94*4882a593Smuzhiyun 95*4882a593SmuzhiyunKVM_FEATURE_MSI_EXT_DEST_ID 15 guest checks this feature bit 96*4882a593Smuzhiyun before using extended destination 97*4882a593Smuzhiyun ID bits in MSI address bits 11-5. 98*4882a593Smuzhiyun 99*4882a593SmuzhiyunKVM_FEATURE_CLOCKSOURCE_STABLE_BIT 24 host will warn if no guest-side 100*4882a593Smuzhiyun per-cpu warps are expected in 101*4882a593Smuzhiyun kvmclock 102*4882a593Smuzhiyun================================== =========== ================================ 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun:: 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun edx = an OR'ed group of (1 << flag) 107*4882a593Smuzhiyun 108*4882a593SmuzhiyunWhere ``flag`` here is defined as below: 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun================== ============ ================================= 111*4882a593Smuzhiyunflag value meaning 112*4882a593Smuzhiyun================== ============ ================================= 113*4882a593SmuzhiyunKVM_HINTS_REALTIME 0 guest checks this feature bit to 114*4882a593Smuzhiyun determine that vCPUs are never 115*4882a593Smuzhiyun preempted for an unlimited time 116*4882a593Smuzhiyun allowing optimizations 117*4882a593Smuzhiyun================== ============ ================================= 118