KVM: VMX: reflect broken preemption timer in vmcs_config
[kvmfornfv.git] / kernel / arch / x86 / kvm / vmx.c
index e378975..e554177 100644 (file)
@@ -1101,9 +1101,6 @@ static inline bool cpu_has_broken_vmx_preemption_timer(void)
 
 static inline bool cpu_has_vmx_preemption_timer(void)
 {
-       if (cpu_has_broken_vmx_preemption_timer())
-               return false;
-
        return vmcs_config.pin_based_exec_ctrl &
                PIN_BASED_VMX_PREEMPTION_TIMER;
 }
@@ -3280,6 +3277,9 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf)
                                &_pin_based_exec_control) < 0)
                return -EIO;
 
+       if (cpu_has_broken_vmx_preemption_timer())
+               _pin_based_exec_control &= ~PIN_BASED_VMX_PREEMPTION_TIMER;
+
        if (!(_cpu_based_2nd_exec_control &
                SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY) ||
                !(_vmexit_control & VM_EXIT_ACK_INTR_ON_EXIT))
@@ -10663,9 +10663,9 @@ static inline int u64_shl_div_u64(u64 a, unsigned int shift,
 static int vmx_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc)
 {
        struct vcpu_vmx *vmx = to_vmx(vcpu);
-       u64 tscl = rdtsc(), delta_tsc;
-
-       delta_tsc = guest_deadline_tsc - kvm_read_l1_tsc(vcpu, tscl);
+       u64 tscl = rdtsc();
+       u64 guest_tscl = kvm_read_l1_tsc(vcpu, tscl);
+       u64 delta_tsc = max(guest_deadline_tsc, guest_tscl) - guest_tscl;
 
        /* Convert to host delta tsc if tsc scaling is enabled */
        if (vcpu->arch.tsc_scaling_ratio != kvm_default_tsc_scaling_ratio &&