From patchwork Tue Jun 16 07:34:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 6614011 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 04E479F1C1 for ; Tue, 16 Jun 2015 07:40:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 036DC207C7 for ; Tue, 16 Jun 2015 07:40:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ECA2220797 for ; Tue, 16 Jun 2015 07:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752824AbbFPHkr (ORCPT ); Tue, 16 Jun 2015 03:40:47 -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 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 16 Jun 2015 00:40:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,624,1427785200"; d="scan'208";a="508991692" Received: from lantianyu-ws.sh.intel.com (HELO localhost) ([10.239.159.40]) by FMSMGA003.fm.intel.com with ESMTP; 16 Jun 2015 00:40:19 -0700 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: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);