From patchwork Mon Sep 28 05:38:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 7275421 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 5D0D19F36A for ; Mon, 28 Sep 2015 05:43:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7C6E0206E6 for ; Mon, 28 Sep 2015 05:43:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7CD04206DF for ; Mon, 28 Sep 2015 05:43:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754266AbbI1Fim (ORCPT ); Mon, 28 Sep 2015 01:38:42 -0400 Received: from mga03.intel.com ([134.134.136.65]:54350 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751962AbbI1Fik (ORCPT ); Mon, 28 Sep 2015 01:38:40 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 27 Sep 2015 22:38:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,601,1437462000"; d="scan'208";a="814258244" Received: from hzzhang-optiplex-9020.sh.intel.com (HELO localhost) ([10.239.12.62]) by fmsmga002.fm.intel.com with ESMTP; 27 Sep 2015 22:38:33 -0700 From: Haozhong Zhang To: kvm@vger.kernel.org Cc: Gleb Natapov , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Joerg Roedel , Wanpeng Li , Xiao Guangrong , =?UTF-8?q?Mihai=20Don=C8=9Bu?= , Andy Lutomirski , Kai Huang , linux-kernel@vger.kernel.org, Haozhong Zhang Subject: [PATCH 01/12] KVM: x86: Collect information for setting TSC scaling ratio Date: Mon, 28 Sep 2015 13:38:00 +0800 Message-Id: <1443418691-24050-2-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 In-Reply-To: <1443418691-24050-1-git-send-email-haozhong.zhang@intel.com> References: <1443418691-24050-1-git-send-email-haozhong.zhang@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 The number of bits of the fractional part of the 64-bit TSC scaling ratio in VMX and SVM is different. This patch makes the architecture code to collect the number of fractional bits and other related information into variables that can be accessed in the common code. Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 8 ++++++++ arch/x86/kvm/svm.c | 5 +++++ arch/x86/kvm/x86.c | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 2beee03..5b9b86e 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -965,6 +965,14 @@ extern bool kvm_has_tsc_control; extern u32 kvm_min_guest_tsc_khz; /* maximum supported tsc_khz for guests */ extern u32 kvm_max_guest_tsc_khz; +/* number of bits of the fractional part of the TSC scaling ratio */ +extern u8 kvm_tsc_scaling_ratio_frac_bits; +/* reserved bits of TSC scaling ratio (SBZ) */ +extern u64 kvm_tsc_scaling_ratio_rsvd; +/* default TSC scaling ratio (= 1.0) */ +extern u64 kvm_default_tsc_scaling_ratio; +/* maximum allowed value of TSC scaling ratio */ +extern u64 kvm_max_tsc_scaling_ratio; enum emulation_result { EMULATE_DONE, /* no further processing */ diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 94b7d15..eff7db7 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -963,7 +963,12 @@ static __init int svm_hardware_setup(void) max = min(0x7fffffffULL, __scale_tsc(tsc_khz, TSC_RATIO_MAX)); kvm_max_guest_tsc_khz = max; + + kvm_max_tsc_scaling_ratio = TSC_RATIO_MAX; + kvm_tsc_scaling_ratio_frac_bits = 32; + kvm_tsc_scaling_ratio_rsvd = TSC_RATIO_RSVD; } + kvm_default_tsc_scaling_ratio = TSC_RATIO_DEFAULT; if (nested) { printk(KERN_INFO "kvm: Nested Virtualization enabled\n"); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 991466b..f888225 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -106,6 +106,14 @@ bool kvm_has_tsc_control; EXPORT_SYMBOL_GPL(kvm_has_tsc_control); u32 kvm_max_guest_tsc_khz; EXPORT_SYMBOL_GPL(kvm_max_guest_tsc_khz); +u8 kvm_tsc_scaling_ratio_frac_bits; +EXPORT_SYMBOL_GPL(kvm_tsc_scaling_ratio_frac_bits); +u64 kvm_tsc_scaling_ratio_rsvd; +EXPORT_SYMBOL_GPL(kvm_tsc_scaling_ratio_rsvd); +u64 kvm_default_tsc_scaling_ratio; +EXPORT_SYMBOL_GPL(kvm_default_tsc_scaling_ratio); +u64 kvm_max_tsc_scaling_ratio; +EXPORT_SYMBOL_GPL(kvm_max_tsc_scaling_ratio); /* tsc tolerance in parts per million - default to 1/2 of the NTP threshold */ static u32 tsc_tolerance_ppm = 250;