KVM: x86: introduce kvm_can_use_hv_timer
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 5 May 2020 10:45:35 +0000 (06:45 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 15 May 2020 16:26:21 +0000 (12:26 -0400)
Replace the ad hoc test in vmx_set_hv_timer with a test in the caller,
start_hv_timer.  This test is not Intel-specific and would be duplicated
when introducing the fast path for the TSC deadline MSR.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/lapic.c
arch/x86/kvm/lapic.h
arch/x86/kvm/vmx/vmx.c

index 42cd2e3..73e51ab 100644 (file)
@@ -110,11 +110,18 @@ static inline u32 kvm_x2apic_id(struct kvm_lapic *apic)
        return apic->vcpu->vcpu_id;
 }
 
-bool kvm_can_post_timer_interrupt(struct kvm_vcpu *vcpu)
+static bool kvm_can_post_timer_interrupt(struct kvm_vcpu *vcpu)
 {
        return pi_inject_timer && kvm_vcpu_apicv_active(vcpu);
 }
-EXPORT_SYMBOL_GPL(kvm_can_post_timer_interrupt);
+
+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));
+}
+EXPORT_SYMBOL_GPL(kvm_can_use_hv_timer);
 
 static bool kvm_use_posted_timer_interrupt(struct kvm_vcpu *vcpu)
 {
@@ -1788,7 +1795,7 @@ static bool start_hv_timer(struct kvm_lapic *apic)
        bool expired;
 
        WARN_ON(preemptible());
-       if (!kvm_x86_ops.set_hv_timer)
+       if (!kvm_can_use_hv_timer(vcpu))
                return false;
 
        if (!ktimer->tscdeadline)
index 7f15f9e..754f29b 100644 (file)
@@ -250,7 +250,7 @@ void kvm_lapic_switch_to_hv_timer(struct kvm_vcpu *vcpu);
 void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu);
 bool kvm_lapic_hv_timer_in_use(struct kvm_vcpu *vcpu);
 void kvm_lapic_restart_hv_timer(struct kvm_vcpu *vcpu);
-bool kvm_can_post_timer_interrupt(struct kvm_vcpu *vcpu);
+bool kvm_can_use_hv_timer(struct kvm_vcpu *vcpu);
 
 static inline enum lapic_mode kvm_apic_mode(u64 apic_base)
 {
index 8d881fc..d267807 100644 (file)
@@ -7405,10 +7405,6 @@ static int vmx_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc,
        u64 tscl, guest_tscl, delta_tsc, lapic_timer_advance_cycles;
        struct kvm_timer *ktimer = &vcpu->arch.apic->lapic_timer;
 
-       if (kvm_mwait_in_guest(vcpu->kvm) ||
-               kvm_can_post_timer_interrupt(vcpu))
-               return -EOPNOTSUPP;
-
        vmx = to_vmx(vcpu);
        tscl = rdtsc();
        guest_tscl = kvm_read_l1_tsc(vcpu, tscl);