Skip to content

Commit 9be4ec3

Browse files
committed
KVM: x86: Advertise TSC_DEADLINE_TIMER in KVM_GET_SUPPORTED_CPUID
Unconditionally advertise TSC_DEADLINE_TIMER via KVM_GET_SUPPORTED_CPUID, as KVM always emulates deadline mode, *if* the VM has an in-kernel local APIC. The odds of a VMM emulating the local APIC in userspace, not emulating the TSC deadline timer, _and_ reflecting KVM_GET_SUPPORTED_CPUID back into KVM_SET_CPUID2, i.e. the risk of over-advertising and breaking any setups, is extremely low. KVM has _unconditionally_ advertised X2APIC via CPUID since commit 0d1de2d ("KVM: Always report x2apic as supported feature"), and it is completely impossible for userspace to emulate X2APIC as KVM doesn't support forwarding the MSR accesses to userspace. I.e. KVM has relied on userspace VMMs to not misreport local APIC capabilities for nearly 13 years. Reviewed-by: Maxim Levitsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 136d605 commit 9be4ec3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,15 +1825,18 @@ emulate them efficiently. The fields in each entry are defined as follows:
18251825
the values returned by the cpuid instruction for
18261826
this function/index combination
18271827

1828-
The TSC deadline timer feature (CPUID leaf 1, ecx[24]) is always returned
1829-
as false, since the feature depends on KVM_CREATE_IRQCHIP for local APIC
1830-
support. Instead it is reported via::
1828+
x2APIC (CPUID leaf 1, ecx[21) and TSC deadline timer (CPUID leaf 1, ecx[24])
1829+
may be returned as true, but they depend on KVM_CREATE_IRQCHIP for in-kernel
1830+
emulation of the local APIC. TSC deadline timer support is also reported via::
18311831

18321832
ioctl(KVM_CHECK_EXTENSION, KVM_CAP_TSC_DEADLINE_TIMER)
18331833

18341834
if that returns true and you use KVM_CREATE_IRQCHIP, or if you emulate the
18351835
feature in userspace, then you can enable the feature for KVM_SET_CPUID2.
18361836

1837+
Enabling x2APIC in KVM_SET_CPUID2 requires KVM_CREATE_IRQCHIP as KVM doesn't
1838+
support forwarding x2APIC MSR accesses to userspace, i.e. KVM does not support
1839+
emulating x2APIC in userspace.
18371840

18381841
4.47 KVM_PPC_GET_PVINFO
18391842
-----------------------

arch/x86/kvm/cpuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ void kvm_set_cpu_caps(void)
737737
EMULATED_F(X2APIC) |
738738
F(MOVBE) |
739739
F(POPCNT) |
740-
0 /* Reserved*/ |
740+
EMULATED_F(TSC_DEADLINE_TIMER) |
741741
F(AES) |
742742
F(XSAVE) |
743743
0 /* OSXSAVE */ |

0 commit comments

Comments
 (0)