Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754574AbbFPHkx (ORCPT ); Tue, 16 Jun 2015 03:40:53 -0400 Received: from mga14.intel.com ([192.55.52.115]:12419 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751928AbbFPHkp (ORCPT ); Tue, 16 Jun 2015 03:40:45 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,624,1427785200"; d="scan'208";a="508991692" From: Lan Tianyu To: gleb@kernel.org, pbonzini@redhat.com Cc: Lan Tianyu , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] KVM: Avoid warning "user requested TSC rate below hardware speed" when create VM. Date: Tue, 16 Jun 2015 15:34:27 +0800 Message-Id: <1434440067-26305-1-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3842 Lines: 85 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] [] dump_stack+0x45/0x57 [ 94.994020] [] warn_slowpath_common+0x8a/0xc0 [ 95.000772] [] warn_slowpath_fmt+0x46/0x50 [ 95.007222] [] vmx_set_tsc_khz+0x3e/0x50 [ 95.013488] [] kvm_set_tsc_khz.part.106+0xa7/0xe0 [ 95.020618] [] kvm_arch_vcpu_init+0x208/0x230 [ 95.027373] [] kvm_vcpu_init+0xc9/0x110 [ 95.033540] [] vmx_create_vcpu+0x70/0xc30 [ 95.039911] [] ? vmx_create_vcpu+0x20/0xc30 [ 95.046476] [] kvm_arch_vcpu_create+0x3e/0x60 [ 95.053233] [] kvm_vm_ioctl+0x1a0/0x770 [ 95.059400] [] ? __fget+0x5/0x200 [ 95.064991] [] ? rcu_irq_exit+0x7f/0xd0 [ 95.071157] [] do_vfs_ioctl+0x308/0x540 [ 95.077323] [] ? expand_files+0x1f1/0x280 [ 95.083684] [] ? selinux_file_ioctl+0x5b/0x100 [ 95.090538] [] SyS_ioctl+0x81/0xa0 [ 95.096218] [] 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 --- arch/x86/kvm/x86.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 43f0df7..6c7fefe 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -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); -- 1.8.4.rc0.1.g8f6a3e5.dirty -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/