18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci==============
48c2ecf20Sopenharmony_ciKVM CPUID bits
58c2ecf20Sopenharmony_ci==============
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci:Author: Glauber Costa <glommer@gmail.com>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciA guest running on a kvm host, can check some of its features using
108c2ecf20Sopenharmony_cicpuid. This is not always guaranteed to work, since userspace can
118c2ecf20Sopenharmony_cimask-out some, or even all KVM-related cpuid features before launching
128c2ecf20Sopenharmony_cia guest.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciKVM cpuid functions are:
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cifunction: KVM_CPUID_SIGNATURE (0x40000000)
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cireturns::
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci   eax = 0x40000001
218c2ecf20Sopenharmony_ci   ebx = 0x4b4d564b
228c2ecf20Sopenharmony_ci   ecx = 0x564b4d56
238c2ecf20Sopenharmony_ci   edx = 0x4d
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciNote that this value in ebx, ecx and edx corresponds to the string "KVMKVMKVM".
268c2ecf20Sopenharmony_ciThe value in eax corresponds to the maximum cpuid function present in this leaf,
278c2ecf20Sopenharmony_ciand will be updated if more functions are added in the future.
288c2ecf20Sopenharmony_ciNote also that old hosts set eax value to 0x0. This should
298c2ecf20Sopenharmony_cibe interpreted as if the value was 0x40000001.
308c2ecf20Sopenharmony_ciThis function queries the presence of KVM cpuid leafs.
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cifunction: define KVM_CPUID_FEATURES (0x40000001)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cireturns::
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci          ebx, ecx
378c2ecf20Sopenharmony_ci          eax = an OR'ed group of (1 << flag)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciwhere ``flag`` is defined as below:
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci================================== =========== ================================
428c2ecf20Sopenharmony_ciflag                               value       meaning
438c2ecf20Sopenharmony_ci================================== =========== ================================
448c2ecf20Sopenharmony_ciKVM_FEATURE_CLOCKSOURCE            0           kvmclock available at msrs
458c2ecf20Sopenharmony_ci                                               0x11 and 0x12
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciKVM_FEATURE_NOP_IO_DELAY           1           not necessary to perform delays
488c2ecf20Sopenharmony_ci                                               on PIO operations
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciKVM_FEATURE_MMU_OP                 2           deprecated
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciKVM_FEATURE_CLOCKSOURCE2           3           kvmclock available at msrs
538c2ecf20Sopenharmony_ci                                               0x4b564d00 and 0x4b564d01
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciKVM_FEATURE_ASYNC_PF               4           async pf can be enabled by
568c2ecf20Sopenharmony_ci                                               writing to msr 0x4b564d02
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciKVM_FEATURE_STEAL_TIME             5           steal time can be enabled by
598c2ecf20Sopenharmony_ci                                               writing to msr 0x4b564d03
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ciKVM_FEATURE_PV_EOI                 6           paravirtualized end of interrupt
628c2ecf20Sopenharmony_ci                                               handler can be enabled by
638c2ecf20Sopenharmony_ci                                               writing to msr 0x4b564d04
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciKVM_FEATURE_PV_UNHALT              7           guest checks this feature bit
668c2ecf20Sopenharmony_ci                                               before enabling paravirtualized
678c2ecf20Sopenharmony_ci                                               spinlock support
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciKVM_FEATURE_PV_TLB_FLUSH           9           guest checks this feature bit
708c2ecf20Sopenharmony_ci                                               before enabling paravirtualized
718c2ecf20Sopenharmony_ci                                               tlb flush
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciKVM_FEATURE_ASYNC_PF_VMEXIT        10          paravirtualized async PF VM EXIT
748c2ecf20Sopenharmony_ci                                               can be enabled by setting bit 2
758c2ecf20Sopenharmony_ci                                               when writing to msr 0x4b564d02
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciKVM_FEATURE_PV_SEND_IPI            11          guest checks this feature bit
788c2ecf20Sopenharmony_ci                                               before enabling paravirtualized
798c2ecf20Sopenharmony_ci                                               send IPIs
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ciKVM_FEATURE_POLL_CONTROL           12          host-side polling on HLT can
828c2ecf20Sopenharmony_ci                                               be disabled by writing
838c2ecf20Sopenharmony_ci                                               to msr 0x4b564d05.
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciKVM_FEATURE_PV_SCHED_YIELD         13          guest checks this feature bit
868c2ecf20Sopenharmony_ci                                               before using paravirtualized
878c2ecf20Sopenharmony_ci                                               sched yield.
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciKVM_FEATURE_ASYNC_PF_INT           14          guest checks this feature bit
908c2ecf20Sopenharmony_ci                                               before using the second async
918c2ecf20Sopenharmony_ci                                               pf control msr 0x4b564d06 and
928c2ecf20Sopenharmony_ci                                               async pf acknowledgment msr
938c2ecf20Sopenharmony_ci                                               0x4b564d07.
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciKVM_FEATURE_MSI_EXT_DEST_ID        15          guest checks this feature bit
968c2ecf20Sopenharmony_ci                                               before using extended destination
978c2ecf20Sopenharmony_ci                                               ID bits in MSI address bits 11-5.
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ciKVM_FEATURE_CLOCKSOURCE_STABLE_BIT 24          host will warn if no guest-side
1008c2ecf20Sopenharmony_ci                                               per-cpu warps are expected in
1018c2ecf20Sopenharmony_ci                                               kvmclock
1028c2ecf20Sopenharmony_ci================================== =========== ================================
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci::
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci      edx = an OR'ed group of (1 << flag)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ciWhere ``flag`` here is defined as below:
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci================== ============ =================================
1118c2ecf20Sopenharmony_ciflag               value        meaning
1128c2ecf20Sopenharmony_ci================== ============ =================================
1138c2ecf20Sopenharmony_ciKVM_HINTS_REALTIME 0            guest checks this feature bit to
1148c2ecf20Sopenharmony_ci                                determine that vCPUs are never
1158c2ecf20Sopenharmony_ci                                preempted for an unlimited time
1168c2ecf20Sopenharmony_ci                                allowing optimizations
1178c2ecf20Sopenharmony_ci================== ============ =================================
118