Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033181AbbKFKtQ (ORCPT ); Fri, 6 Nov 2015 05:49:16 -0500 Received: from mail-wm0-f43.google.com ([74.125.82.43]:34519 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031997AbbKFKtO (ORCPT ); Fri, 6 Nov 2015 05:49:14 -0500 Subject: Re: [PATCH v2 00/12] KVM: x86: add support for VMX TSC scaling To: Haozhong Zhang , kvm@vger.kernel.org References: <1445326752-8926-1-git-send-email-haozhong.zhang@intel.com> Cc: Gleb Natapov , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Joerg Roedel , Wanpeng Li , Xiao Guangrong , mdontu@bitdefender.com, Kai Huang , Andy Lutomirski , linux-kernel@vger.kernel.org From: Paolo Bonzini Message-ID: <563C85A4.1080006@redhat.com> Date: Fri, 6 Nov 2015 11:49:08 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1445326752-8926-1-git-send-email-haozhong.zhang@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3745 Lines: 80 On 20/10/2015 09:39, Haozhong Zhang wrote: > This patchset adds support for VMX TSC scaling feature which is > available on Intel Skylake CPU. The specification of VMX TSC scaling > can be found at > http://www.intel.com/content/www/us/en/processors/timestamp-counter-scaling-virtualization-white-paper.html > > VMX TSC scaling allows guest TSC which is read by guest rdtsc(p) > instructions increases in a rate that is customized by the hypervisor > and can be different than the host TSC rate. Basically, VMX TSC > scaling adds a 64-bit field called TSC multiplier in VMCS so that, if > VMX TSC scaling is enabled, TSC read by guest rdtsc(p) instructions > will be calculated by the following formula: > > guest EDX:EAX = (Host TSC * TSC multiplier) >> 48 + VMX TSC Offset > > where, Host TSC = Host MSR_IA32_TSC + Host MSR_IA32_TSC_ADJUST. > > This patchset, when cooperating with another QEMU patchset (sent in > another email "target-i386: save/restore vcpu's TSC rate during > migration"), allows guest programs observe a consistent TSC rate even > though they are migrated among machines with different host TSC rates. > > VMX TSC scaling shares some common logics with SVM TSC ratio which > is already supported by KVM. Patch 1 ~ 8 move those common logics from > SVM code to the common code. Upon them, patch 9 ~ 12 add VMX-specific > support for VMX TSC scaling. > > Changes in v2: > * Remove the duplicated variable 'kvm_tsc_scaling_ratio_rsvd'. > * Remove an unnecessary error check in original patch 2. > * Do 64-bit arithmetic by functions recommended by Paolo. > * Make kvm_set_tsc_khz() returns an error number so that ioctl > KVM_SET_TSC_KHZ does not return 0 if errors happen. > > Reviewed-by: Eric Northup Thanks for the patches. There are a couple changes that I can do myself: 1) kvm_default_tsc_scaling_ratio can be initialized in kvm_arch_hardware_setup, since it's just 1ULL << kvm_tsc_scaling_ratio_frac_bits 2) things that you are adding to include/linux/kvm_host.h should instead go in arch/x86/include/linux/kvm_host.h That's it. I'll commit it as soon as I test on AMD (today hopefully). Paolo > Haozhong Zhang (12): > KVM: x86: Collect information for setting TSC scaling ratio > KVM: x86: Add a common TSC scaling ratio field in kvm_vcpu_arch > KVM: x86: Add a common TSC scaling function > KVM: x86: Replace call-back set_tsc_khz() with a common function > KVM: x86: Replace call-back compute_tsc_offset() with a common function > KVM: x86: Move TSC scaling logic out of call-back adjust_tsc_offset() > KVM: x86: Move TSC scaling logic out of call-back read_l1_tsc() > KVM: x86: Use the correct vcpu's TSC rate to compute time scale > KVM: VMX: Enable and initialize VMX TSC scaling > KVM: VMX: Setup TSC scaling ratio when a vcpu is loaded > KVM: VMX: Use a scaled host TSC for guest readings of MSR_IA32_TSC > KVM: VMX: Dump TSC multiplier in dump_vmcs() > > arch/x86/include/asm/kvm_host.h | 24 +++---- > arch/x86/include/asm/vmx.h | 3 + > arch/x86/kvm/lapic.c | 4 +- > arch/x86/kvm/svm.c | 116 ++++------------------------------ > arch/x86/kvm/vmx.c | 64 ++++++++++--------- > arch/x86/kvm/x86.c | 134 +++++++++++++++++++++++++++++++++++----- > include/linux/kvm_host.h | 20 ++++++ > include/linux/math64.h | 99 +++++++++++++++++++++++++++++ > 8 files changed, 297 insertions(+), 167 deletions(-) > -- 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/