@@ -7814,6 +7814,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
{
struct page *page;
struct kvm *kvm;
+ int cpu;
int r;
BUG_ON(vcpu->kvm == NULL);
@@ -7833,6 +7834,21 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
}
vcpu->arch.pio_data = page_address(page);
+ /*
+ * max_tsc_khz records tsc_khz at arch init stage on the constant tsc
+ * machine. However, tsc_khz maybe changed during tsc clocksource driver
+ * refines calibration. This will cause to create VM with slow tsc
+ * and produce warning. To avoid such case, check whether tsc_khz
+ * has been changed here and update max_tsc_khz with new value of
+ * tsc_khz if changed.
+ */
+ if (boot_cpu_has(X86_FEATURE_CONSTANT_TSC) && max_tsc_khz != tsc_khz) {
+ max_tsc_khz = tsc_khz;
+ pr_debug("kvm: max_tsc_khz is changed to %ld\n", max_tsc_khz);
+ for_each_online_cpu(cpu)
+ smp_call_function_single(cpu, tsc_khz_changed, NULL, 1);
+ }
+
kvm_set_tsc_khz(vcpu, max_tsc_khz);
r = kvm_mmu_create(vcpu);
KVM populates max_tsc_khz with tsc_khz at arch init stage on the constant tsc machine and creates VM with max_tsc_khz as tsc. However, tsc_khz maybe changed during tsc clocksource driver refines calibration. This will cause to create VM with slow tsc and produce the following warning. To fix the issue, compare max_tsc_khz with tsc_khz and update max_tsc_khz with new value of tsc_khz if it has been changed when create a VM. [ 94.916906] ------------[ cut here ]------------ [ 94.922127] WARNING: CPU: 0 PID: 824 at arch/x86/kvm/vmx.c:2272 vmx_set_tsc_khz+0x3e/0x50() [ 94.931503] user requested TSC rate below hardware speed [ 94.937470] Modules linked in: [ 94.940923] CPU: 0 PID: 824 Comm: qemu-system-x86 Tainted: G D W 4.1.0-rc3+ #4 [ 94.960350] ffffffff81f453f8 ffff88027e9f3bc8 ffffffff81b5eb8a 0000000000000000 [ 94.968721] ffff88027e9f3c18 ffff88027e9f3c08 ffffffff810e6f8a ffff880200000000 [ 94.977103] 00000000001d3300 ffff88027e980000 0000000000000001 ffff88027e980000 [ 94.985476] Call Trace: [ 94.988242] [<ffffffff81b5eb8a>] dump_stack+0x45/0x57 [ 94.994020] [<ffffffff810e6f8a>] warn_slowpath_common+0x8a/0xc0 [ 95.000772] [<ffffffff810e7006>] warn_slowpath_fmt+0x46/0x50 [ 95.007222] [<ffffffff8104676e>] vmx_set_tsc_khz+0x3e/0x50 [ 95.013488] [<ffffffff810112f7>] kvm_set_tsc_khz.part.106+0xa7/0xe0 [ 95.020618] [<ffffffff8101e628>] kvm_arch_vcpu_init+0x208/0x230 [ 95.027373] [<ffffffff81003bf9>] kvm_vcpu_init+0xc9/0x110 [ 95.033540] [<ffffffff81049fd0>] vmx_create_vcpu+0x70/0xc30 [ 95.039911] [<ffffffff81049f80>] ? vmx_create_vcpu+0x20/0xc30 [ 95.046476] [<ffffffff8101dc9e>] kvm_arch_vcpu_create+0x3e/0x60 [ 95.053233] [<ffffffff81009f00>] kvm_vm_ioctl+0x1a0/0x770 [ 95.059400] [<ffffffff8129f395>] ? __fget+0x5/0x200 [ 95.064991] [<ffffffff8115b85f>] ? rcu_irq_exit+0x7f/0xd0 [ 95.071157] [<ffffffff81293448>] do_vfs_ioctl+0x308/0x540 [ 95.077323] [<ffffffff8129f301>] ? expand_files+0x1f1/0x280 [ 95.083684] [<ffffffff8147836b>] ? selinux_file_ioctl+0x5b/0x100 [ 95.090538] [<ffffffff81293701>] SyS_ioctl+0x81/0xa0 [ 95.096218] [<ffffffff81b6a72e>] system_call_fastpath+0x12/0x76 [ 95.102974] ---[ end trace 08ade884081d9dd7 ]--- Link: https://bugzilla.kernel.org/show_bug.cgi?id=99861 Signed-off-by: Lan Tianyu <tianyu.lan@intel.com> --- arch/x86/kvm/x86.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)