Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 12 Nov 2015 22:34:06 +0000 (14:34 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 12 Nov 2015 22:34:06 +0000 (14:34 -0800)
Pull second batch of kvm updates from Paolo Bonzini:
 "Four changes:

   - x86: work around two nasty cases where a benign exception occurs
     while another is being delivered.  The endless stream of exceptions
     causes an infinite loop in the processor, which not even NMIs or
     SMIs can interrupt; in the virt case, there is no possibility to
     exit to the host either.

   - x86: support for Skylake per-guest TSC rate.  Long supported by
     AMD, the patches mostly move things from there to common
     arch/x86/kvm/ code.

   - generic: remove local_irq_save/restore from the guest entry and
     exit paths when context tracking is enabled.  The patches are a few
     months old, but we discussed them again at kernel summit.  Andy
     will pick up from here and, in 4.5, try to remove it from the user
     entry/exit paths.

   - PPC: Two bug fixes, see merge commit 370289756becc for details"

* tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (21 commits)
  KVM: x86: rename update_db_bp_intercept to update_bp_intercept
  KVM: svm: unconditionally intercept #DB
  KVM: x86: work around infinite loop in microcode when #AC is delivered
  context_tracking: avoid irq_save/irq_restore on guest entry and exit
  context_tracking: remove duplicate enabled check
  KVM: VMX: Dump TSC multiplier in dump_vmcs()
  KVM: VMX: Use a scaled host TSC for guest readings of MSR_IA32_TSC
  KVM: VMX: Setup TSC scaling ratio when a vcpu is loaded
  KVM: VMX: Enable and initialize VMX TSC scaling
  KVM: x86: Use the correct vcpu's TSC rate to compute time scale
  KVM: x86: Move TSC scaling logic out of call-back read_l1_tsc()
  KVM: x86: Move TSC scaling logic out of call-back adjust_tsc_offset()
  KVM: x86: Replace call-back compute_tsc_offset() with a common function
  KVM: x86: Replace call-back set_tsc_khz() with a common function
  KVM: x86: Add a common TSC scaling function
  KVM: x86: Add a common TSC scaling ratio field in kvm_vcpu_arch
  KVM: x86: Collect information for setting TSC scaling ratio
  KVM: x86: declare a few variables as __read_mostly
  KVM: x86: merge handle_mmio_page_fault and handle_mmio_page_fault_common
  KVM: PPC: Book3S HV: Don't dynamically split core when already split
  ...

1  2 
arch/powerpc/kvm/book3s_hv.c
arch/x86/kvm/x86.c

index 9c26c5a96ea2bc0ea9d2286f4995b2d629be9003,becad3ababe3c5d55008f8a838f0fea164509f81..54b45b73195f912688ec4afe8e9fb4c9c3d5723c
@@@ -36,6 -36,7 +36,6 @@@
  
  #include <asm/reg.h>
  #include <asm/cputable.h>
 -#include <asm/cache.h>
  #include <asm/cacheflush.h>
  #include <asm/tlbflush.h>
  #include <asm/uaccess.h>
  
  static DECLARE_BITMAP(default_enabled_hcalls, MAX_HCALL_OPCODE/4 + 1);
  
 -#if defined(CONFIG_PPC_64K_PAGES)
 -#define MPP_BUFFER_ORDER      0
 -#elif defined(CONFIG_PPC_4K_PAGES)
 -#define MPP_BUFFER_ORDER      3
 -#endif
 -
  static int dynamic_mt_modes = 6;
  module_param(dynamic_mt_modes, int, S_IRUGO | S_IWUSR);
  MODULE_PARM_DESC(dynamic_mt_modes, "Set of allowed dynamic micro-threading modes: 0 (= none), 2, 4, or 6 (= 2 or 4)");
@@@ -1448,6 -1455,13 +1448,6 @@@ static struct kvmppc_vcore *kvmppc_vcor
        vcore->kvm = kvm;
        INIT_LIST_HEAD(&vcore->preempt_list);
  
 -      vcore->mpp_buffer_is_valid = false;
 -
 -      if (cpu_has_feature(CPU_FTR_ARCH_207S))
 -              vcore->mpp_buffer = (void *)__get_free_pages(
 -                      GFP_KERNEL|__GFP_ZERO,
 -                      MPP_BUFFER_ORDER);
 -
        return vcore;
  }
  
@@@ -1880,6 -1894,33 +1880,6 @@@ static int on_primary_thread(void
        return 1;
  }
  
 -static void kvmppc_start_saving_l2_cache(struct kvmppc_vcore *vc)
 -{
 -      phys_addr_t phy_addr, mpp_addr;
 -
 -      phy_addr = (phys_addr_t)virt_to_phys(vc->mpp_buffer);
 -      mpp_addr = phy_addr & PPC_MPPE_ADDRESS_MASK;
 -
 -      mtspr(SPRN_MPPR, mpp_addr | PPC_MPPR_FETCH_ABORT);
 -      logmpp(mpp_addr | PPC_LOGMPP_LOG_L2);
 -
 -      vc->mpp_buffer_is_valid = true;
 -}
 -
 -static void kvmppc_start_restoring_l2_cache(const struct kvmppc_vcore *vc)
 -{
 -      phys_addr_t phy_addr, mpp_addr;
 -
 -      phy_addr = virt_to_phys(vc->mpp_buffer);
 -      mpp_addr = phy_addr & PPC_MPPE_ADDRESS_MASK;
 -
 -      /* We must abort any in-progress save operations to ensure
 -       * the table is valid so that prefetch engine knows when to
 -       * stop prefetching. */
 -      logmpp(mpp_addr | PPC_LOGMPP_LOG_ABORT);
 -      mtspr(SPRN_MPPR, mpp_addr | PPC_MPPR_FETCH_WHOLE_TABLE);
 -}
 -
  /*
   * A list of virtual cores for each physical CPU.
   * These are vcores that could run but their runner VCPU tasks are
@@@ -2019,7 -2060,7 +2019,7 @@@ static bool can_split_piggybacked_subco
                        return false;
                n_subcores += (cip->subcore_threads[sub] - 1) >> 1;
        }
-       if (n_subcores > 3 || large_sub < 0)
+       if (large_sub < 0 || !subcore_config_ok(n_subcores + 1, 2))
                return false;
  
        /*
@@@ -2430,8 -2471,14 +2430,8 @@@ static noinline void kvmppc_run_core(st
  
        srcu_idx = srcu_read_lock(&vc->kvm->srcu);
  
 -      if (vc->mpp_buffer_is_valid)
 -              kvmppc_start_restoring_l2_cache(vc);
 -
        __kvmppc_vcore_entry();
  
 -      if (vc->mpp_buffer)
 -              kvmppc_start_saving_l2_cache(vc);
 -
        srcu_read_unlock(&vc->kvm->srcu, srcu_idx);
  
        spin_lock(&vc->lock);
@@@ -3026,8 -3073,14 +3026,8 @@@ static void kvmppc_free_vcores(struct k
  {
        long int i;
  
 -      for (i = 0; i < KVM_MAX_VCORES; ++i) {
 -              if (kvm->arch.vcores[i] && kvm->arch.vcores[i]->mpp_buffer) {
 -                      struct kvmppc_vcore *vc = kvm->arch.vcores[i];
 -                      free_pages((unsigned long)vc->mpp_buffer,
 -                                 MPP_BUFFER_ORDER);
 -              }
 +      for (i = 0; i < KVM_MAX_VCORES; ++i)
                kfree(kvm->arch.vcores[i]);
 -      }
        kvm->arch.online_vcores = 0;
  }
  
diff --combined arch/x86/kvm/x86.c
index 4a6eff166fc61fa2053141f410260f2667f8a965,aba7f95d7a64c981fb6f88aade5edcac57286117..00462bd63129cfbde2c6b7e7bdf50eb073cc31b8
@@@ -93,10 -93,10 +93,10 @@@ static void update_cr8_intercept(struc
  static void process_nmi(struct kvm_vcpu *vcpu);
  static void __kvm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags);
  
- struct kvm_x86_ops *kvm_x86_ops;
+ struct kvm_x86_ops *kvm_x86_ops __read_mostly;
  EXPORT_SYMBOL_GPL(kvm_x86_ops);
  
- static bool ignore_msrs = 0;
+ static bool __read_mostly ignore_msrs = 0;
  module_param(ignore_msrs, bool, S_IRUGO | S_IWUSR);
  
  unsigned int min_timer_period_us = 500;
@@@ -105,20 -105,25 +105,25 @@@ module_param(min_timer_period_us, uint
  static bool __read_mostly kvmclock_periodic_sync = true;
  module_param(kvmclock_periodic_sync, bool, S_IRUGO);
  
- bool kvm_has_tsc_control;
+ bool __read_mostly kvm_has_tsc_control;
  EXPORT_SYMBOL_GPL(kvm_has_tsc_control);
- u32  kvm_max_guest_tsc_khz;
+ u32  __read_mostly kvm_max_guest_tsc_khz;
  EXPORT_SYMBOL_GPL(kvm_max_guest_tsc_khz);
+ u8   __read_mostly kvm_tsc_scaling_ratio_frac_bits;
+ EXPORT_SYMBOL_GPL(kvm_tsc_scaling_ratio_frac_bits);
+ u64  __read_mostly kvm_max_tsc_scaling_ratio;
+ EXPORT_SYMBOL_GPL(kvm_max_tsc_scaling_ratio);
+ static u64 __read_mostly kvm_default_tsc_scaling_ratio;
  
  /* tsc tolerance in parts per million - default to 1/2 of the NTP threshold */
- static u32 tsc_tolerance_ppm = 250;
+ static u32 __read_mostly tsc_tolerance_ppm = 250;
  module_param(tsc_tolerance_ppm, uint, S_IRUGO | S_IWUSR);
  
  /* lapic timer advance (tscdeadline mode only) in nanoseconds */
- unsigned int lapic_timer_advance_ns = 0;
+ unsigned int __read_mostly lapic_timer_advance_ns = 0;
  module_param(lapic_timer_advance_ns, uint, S_IRUGO | S_IWUSR);
  
- static bool backwards_tsc_observed = false;
+ static bool __read_mostly backwards_tsc_observed = false;
  
  #define KVM_NR_SHARED_MSRS 16
  
@@@ -668,9 -673,9 +673,9 @@@ static int __kvm_set_xcr(struct kvm_vcp
        /* Only support XCR_XFEATURE_ENABLED_MASK(xcr0) now  */
        if (index != XCR_XFEATURE_ENABLED_MASK)
                return 1;
 -      if (!(xcr0 & XSTATE_FP))
 +      if (!(xcr0 & XFEATURE_MASK_FP))
                return 1;
 -      if ((xcr0 & XSTATE_YMM) && !(xcr0 & XSTATE_SSE))
 +      if ((xcr0 & XFEATURE_MASK_YMM) && !(xcr0 & XFEATURE_MASK_SSE))
                return 1;
  
        /*
         * saving.  However, xcr0 bit 0 is always set, even if the
         * emulated CPU does not support XSAVE (see fx_init).
         */
 -      valid_bits = vcpu->arch.guest_supported_xcr0 | XSTATE_FP;
 +      valid_bits = vcpu->arch.guest_supported_xcr0 | XFEATURE_MASK_FP;
        if (xcr0 & ~valid_bits)
                return 1;
  
 -      if ((!(xcr0 & XSTATE_BNDREGS)) != (!(xcr0 & XSTATE_BNDCSR)))
 +      if ((!(xcr0 & XFEATURE_MASK_BNDREGS)) !=
 +          (!(xcr0 & XFEATURE_MASK_BNDCSR)))
                return 1;
  
 -      if (xcr0 & XSTATE_AVX512) {
 -              if (!(xcr0 & XSTATE_YMM))
 +      if (xcr0 & XFEATURE_MASK_AVX512) {
 +              if (!(xcr0 & XFEATURE_MASK_YMM))
                        return 1;
 -              if ((xcr0 & XSTATE_AVX512) != XSTATE_AVX512)
 +              if ((xcr0 & XFEATURE_MASK_AVX512) != XFEATURE_MASK_AVX512)
                        return 1;
        }
        kvm_put_guest_xcr0(vcpu);
        vcpu->arch.xcr0 = xcr0;
  
 -      if ((xcr0 ^ old_xcr0) & XSTATE_EXTEND_MASK)
 +      if ((xcr0 ^ old_xcr0) & XFEATURE_MASK_EXTEND)
                kvm_update_cpuid(vcpu);
        return 0;
  }
@@@ -1249,14 -1253,53 +1254,53 @@@ static u32 adjust_tsc_khz(u32 khz, s32 
        return v;
  }
  
- static void kvm_set_tsc_khz(struct kvm_vcpu *vcpu, u32 this_tsc_khz)
+ static int set_tsc_khz(struct kvm_vcpu *vcpu, u32 user_tsc_khz, bool scale)
+ {
+       u64 ratio;
+       /* Guest TSC same frequency as host TSC? */
+       if (!scale) {
+               vcpu->arch.tsc_scaling_ratio = kvm_default_tsc_scaling_ratio;
+               return 0;
+       }
+       /* TSC scaling supported? */
+       if (!kvm_has_tsc_control) {
+               if (user_tsc_khz > tsc_khz) {
+                       vcpu->arch.tsc_catchup = 1;
+                       vcpu->arch.tsc_always_catchup = 1;
+                       return 0;
+               } else {
+                       WARN(1, "user requested TSC rate below hardware speed\n");
+                       return -1;
+               }
+       }
+       /* TSC scaling required  - calculate ratio */
+       ratio = mul_u64_u32_div(1ULL << kvm_tsc_scaling_ratio_frac_bits,
+                               user_tsc_khz, tsc_khz);
+       if (ratio == 0 || ratio >= kvm_max_tsc_scaling_ratio) {
+               WARN_ONCE(1, "Invalid TSC scaling ratio - virtual-tsc-khz=%u\n",
+                         user_tsc_khz);
+               return -1;
+       }
+       vcpu->arch.tsc_scaling_ratio = ratio;
+       return 0;
+ }
+ static int kvm_set_tsc_khz(struct kvm_vcpu *vcpu, u32 this_tsc_khz)
  {
        u32 thresh_lo, thresh_hi;
        int use_scaling = 0;
  
        /* tsc_khz can be zero if TSC calibration fails */
-       if (this_tsc_khz == 0)
-               return;
+       if (this_tsc_khz == 0) {
+               /* set tsc_scaling_ratio to a safe value */
+               vcpu->arch.tsc_scaling_ratio = kvm_default_tsc_scaling_ratio;
+               return -1;
+       }
  
        /* Compute a scale to convert nanoseconds in TSC cycles */
        kvm_get_time_scale(this_tsc_khz, NSEC_PER_SEC / 1000,
                pr_debug("kvm: requested TSC rate %u falls outside tolerance [%u,%u]\n", this_tsc_khz, thresh_lo, thresh_hi);
                use_scaling = 1;
        }
-       kvm_x86_ops->set_tsc_khz(vcpu, this_tsc_khz, use_scaling);
+       return set_tsc_khz(vcpu, this_tsc_khz, use_scaling);
  }
  
  static u64 compute_guest_tsc(struct kvm_vcpu *vcpu, s64 kernel_ns)
@@@ -1322,6 -1365,48 +1366,48 @@@ static void update_ia32_tsc_adjust_msr(
        vcpu->arch.ia32_tsc_adjust_msr += offset - curr_offset;
  }
  
+ /*
+  * Multiply tsc by a fixed point number represented by ratio.
+  *
+  * The most significant 64-N bits (mult) of ratio represent the
+  * integral part of the fixed point number; the remaining N bits
+  * (frac) represent the fractional part, ie. ratio represents a fixed
+  * point number (mult + frac * 2^(-N)).
+  *
+  * N equals to kvm_tsc_scaling_ratio_frac_bits.
+  */
+ static inline u64 __scale_tsc(u64 ratio, u64 tsc)
+ {
+       return mul_u64_u64_shr(tsc, ratio, kvm_tsc_scaling_ratio_frac_bits);
+ }
+ u64 kvm_scale_tsc(struct kvm_vcpu *vcpu, u64 tsc)
+ {
+       u64 _tsc = tsc;
+       u64 ratio = vcpu->arch.tsc_scaling_ratio;
+       if (ratio != kvm_default_tsc_scaling_ratio)
+               _tsc = __scale_tsc(ratio, tsc);
+       return _tsc;
+ }
+ EXPORT_SYMBOL_GPL(kvm_scale_tsc);
+ static u64 kvm_compute_tsc_offset(struct kvm_vcpu *vcpu, u64 target_tsc)
+ {
+       u64 tsc;
+       tsc = kvm_scale_tsc(vcpu, rdtsc());
+       return target_tsc - tsc;
+ }
+ u64 kvm_read_l1_tsc(struct kvm_vcpu *vcpu, u64 host_tsc)
+ {
+       return kvm_x86_ops->read_l1_tsc(vcpu, kvm_scale_tsc(vcpu, host_tsc));
+ }
+ EXPORT_SYMBOL_GPL(kvm_read_l1_tsc);
  void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr)
  {
        struct kvm *kvm = vcpu->kvm;
        u64 data = msr->data;
  
        raw_spin_lock_irqsave(&kvm->arch.tsc_write_lock, flags);
-       offset = kvm_x86_ops->compute_tsc_offset(vcpu, data);
+       offset = kvm_compute_tsc_offset(vcpu, data);
        ns = get_kernel_ns();
        elapsed = ns - kvm->arch.last_tsc_nsec;
  
                } else {
                        u64 delta = nsec_to_cycles(vcpu, elapsed);
                        data += delta;
-                       offset = kvm_x86_ops->compute_tsc_offset(vcpu, data);
+                       offset = kvm_compute_tsc_offset(vcpu, data);
                        pr_debug("kvm: adjusted tsc offset by %llu\n", delta);
                }
                matched = true;
  
  EXPORT_SYMBOL_GPL(kvm_write_tsc);
  
+ static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu,
+                                          s64 adjustment)
+ {
+       kvm_x86_ops->adjust_tsc_offset_guest(vcpu, adjustment);
+ }
+ static inline void adjust_tsc_offset_host(struct kvm_vcpu *vcpu, s64 adjustment)
+ {
+       if (vcpu->arch.tsc_scaling_ratio != kvm_default_tsc_scaling_ratio)
+               WARN_ON(adjustment < 0);
+       adjustment = kvm_scale_tsc(vcpu, (u64) adjustment);
+       kvm_x86_ops->adjust_tsc_offset_guest(vcpu, adjustment);
+ }
  #ifdef CONFIG_X86_64
  
  static cycle_t read_tsc(void)
@@@ -1608,7 -1707,7 +1708,7 @@@ static void kvm_gen_update_masterclock(
  
  static int kvm_guest_time_update(struct kvm_vcpu *v)
  {
-       unsigned long flags, this_tsc_khz;
+       unsigned long flags, this_tsc_khz, tgt_tsc_khz;
        struct kvm_vcpu_arch *vcpu = &v->arch;
        struct kvm_arch *ka = &v->kvm->arch;
        s64 kernel_ns;
                kernel_ns = get_kernel_ns();
        }
  
-       tsc_timestamp = kvm_x86_ops->read_l1_tsc(v, host_tsc);
+       tsc_timestamp = kvm_read_l1_tsc(v, host_tsc);
  
        /*
         * We may have to catch up the TSC to match elapsed wall clock
                return 0;
  
        if (unlikely(vcpu->hw_tsc_khz != this_tsc_khz)) {
-               kvm_get_time_scale(NSEC_PER_SEC / 1000, this_tsc_khz,
+               tgt_tsc_khz = kvm_has_tsc_control ?
+                       vcpu->virtual_tsc_khz : this_tsc_khz;
+               kvm_get_time_scale(NSEC_PER_SEC / 1000, tgt_tsc_khz,
                                   &vcpu->hv_clock.tsc_shift,
                                   &vcpu->hv_clock.tsc_to_system_mul);
                vcpu->hw_tsc_khz = this_tsc_khz;
@@@ -2617,7 -2718,7 +2719,7 @@@ void kvm_arch_vcpu_load(struct kvm_vcp
                if (tsc_delta < 0)
                        mark_tsc_unstable("KVM discovered backwards TSC");
                if (check_tsc_unstable()) {
-                       u64 offset = kvm_x86_ops->compute_tsc_offset(vcpu,
+                       u64 offset = kvm_compute_tsc_offset(vcpu,
                                                vcpu->arch.last_guest_tsc);
                        kvm_x86_ops->write_tsc_offset(vcpu, offset);
                        vcpu->arch.tsc_catchup = 1;
@@@ -2922,7 -3023,7 +3024,7 @@@ static void fill_xsave(u8 *dest, struc
         * Copy each region from the possibly compacted offset to the
         * non-compacted offset.
         */
 -      valid = xstate_bv & ~XSTATE_FPSSE;
 +      valid = xstate_bv & ~XFEATURE_MASK_FPSSE;
        while (valid) {
                u64 feature = valid & -valid;
                int index = fls64(feature) - 1;
@@@ -2960,7 -3061,7 +3062,7 @@@ static void load_xsave(struct kvm_vcpu 
         * Copy each region from the non-compacted offset to the
         * possibly compacted offset.
         */
 -      valid = xstate_bv & ~XSTATE_FPSSE;
 +      valid = xstate_bv & ~XFEATURE_MASK_FPSSE;
        while (valid) {
                u64 feature = valid & -valid;
                int index = fls64(feature) - 1;
@@@ -2988,7 -3089,7 +3090,7 @@@ static void kvm_vcpu_ioctl_x86_get_xsav
                        &vcpu->arch.guest_fpu.state.fxsave,
                        sizeof(struct fxregs_state));
                *(u64 *)&guest_xsave->region[XSAVE_HDR_OFFSET / sizeof(u32)] =
 -                      XSTATE_FPSSE;
 +                      XFEATURE_MASK_FPSSE;
        }
  }
  
@@@ -3008,7 -3109,7 +3110,7 @@@ static int kvm_vcpu_ioctl_x86_set_xsave
                        return -EINVAL;
                load_xsave(vcpu, (u8 *)guest_xsave->region);
        } else {
 -              if (xstate_bv & ~XSTATE_FPSSE)
 +              if (xstate_bv & ~XFEATURE_MASK_FPSSE)
                        return -EINVAL;
                memcpy(&vcpu->arch.guest_fpu.state.fxsave,
                        guest_xsave->region, sizeof(struct fxregs_state));
@@@ -3319,9 -3420,9 +3421,9 @@@ long kvm_arch_vcpu_ioctl(struct file *f
                if (user_tsc_khz == 0)
                        user_tsc_khz = tsc_khz;
  
-               kvm_set_tsc_khz(vcpu, user_tsc_khz);
+               if (!kvm_set_tsc_khz(vcpu, user_tsc_khz))
+                       r = 0;
  
-               r = 0;
                goto out;
        }
        case KVM_GET_TSC_KHZ: {
@@@ -6452,8 -6553,7 +6554,7 @@@ static int vcpu_enter_guest(struct kvm_
        if (hw_breakpoint_active())
                hw_breakpoint_restore();
  
-       vcpu->arch.last_guest_tsc = kvm_x86_ops->read_l1_tsc(vcpu,
-                                                          rdtsc());
+       vcpu->arch.last_guest_tsc = kvm_read_l1_tsc(vcpu, rdtsc());
  
        vcpu->mode = OUTSIDE_GUEST_MODE;
        smp_wmb();
@@@ -7015,7 -7115,7 +7116,7 @@@ int kvm_arch_vcpu_ioctl_set_guest_debug
         */
        kvm_set_rflags(vcpu, rflags);
  
-       kvm_x86_ops->update_db_bp_intercept(vcpu);
+       kvm_x86_ops->update_bp_intercept(vcpu);
  
        r = 0;
  
@@@ -7089,7 -7189,7 +7190,7 @@@ static void fx_init(struct kvm_vcpu *vc
        /*
         * Ensure guest xcr0 is valid for loading
         */
 -      vcpu->arch.xcr0 = XSTATE_FP;
 +      vcpu->arch.xcr0 = XFEATURE_MASK_FP;
  
        vcpu->arch.cr0 |= X86_CR0_ET;
  }
@@@ -7364,6 -7464,20 +7465,20 @@@ int kvm_arch_hardware_setup(void
        if (r != 0)
                return r;
  
+       if (kvm_has_tsc_control) {
+               /*
+                * Make sure the user can only configure tsc_khz values that
+                * fit into a signed integer.
+                * A min value is not calculated needed because it will always
+                * be 1 on all machines.
+                */
+               u64 max = min(0x7fffffffULL,
+                             __scale_tsc(kvm_max_tsc_scaling_ratio, tsc_khz));
+               kvm_max_guest_tsc_khz = max;
+               kvm_default_tsc_scaling_ratio = 1ULL << kvm_tsc_scaling_ratio_frac_bits;
+       }
        kvm_init_msr_list();
        return 0;
  }