[RFC 08/33] KVM: x86: Don't use hv_timer if CAP_HYPERV_VSM enabled

From: Nicolas Saenz Julienne
Date: Wed Nov 08 2023 - 06:20:04 EST


VSM's VTLs are modeled by using a distinct vCPU per VTL. While one VTL
is running the rest of vCPUs are left idle. This doesn't play well with
the approach of tracking emulated timer expiration by using the VMX
preemption timer. Inactive VTL's timers are still meant to run and
inject interrupts regardless of their runstate.

Signed-off-by: Nicolas Saenz Julienne <nsaenz@xxxxxxxxxx>
---
arch/x86/kvm/lapic.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index f55d216cb2a0..8cc75b24381b 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -152,9 +152,10 @@ static bool kvm_can_post_timer_interrupt(struct kvm_vcpu *vcpu)

bool kvm_can_use_hv_timer(struct kvm_vcpu *vcpu)
{
- return kvm_x86_ops.set_hv_timer
- && !(kvm_mwait_in_guest(vcpu->kvm) ||
- kvm_can_post_timer_interrupt(vcpu));
+ return kvm_x86_ops.set_hv_timer &&
+ !(kvm_mwait_in_guest(vcpu->kvm) ||
+ kvm_can_post_timer_interrupt(vcpu)) &&
+ !(kvm_hv_vsm_enabled(vcpu->kvm));
}

static bool kvm_use_posted_timer_interrupt(struct kvm_vcpu *vcpu)
--
2.40.1