[PATCH v3 0/3] target-i386: save/restore vcpu's TSC rate during migration

2015-11-02 Thread Haozhong Zhang
m_cpu_synchronize_post_init(). Changes in v2: * Add a pair of cpu options 'save-tsc-freq' and 'load-tsc-freq' to control the migration of vcpu's TSC rate. * Move all logic of setting TSC rate to target-i386. * Remove the duplicated TSC setup in kvm_arch_init_vcpu(

[PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-02 Thread Haozhong Zhang
C rate from KVM (returned by KVM_GET_TSC_KHZ). 3. Otherwise, we will use the migrated TSC rate. Signed-off-by: Haozhong Zhang --- include/sysemu/kvm.h | 2 ++ kvm-all.c| 1 + target-arm/kvm.c | 5 + target-i386/kvm.c| 33 + target-mip

[PATCH v3 1/3] target-i386: add a subsection for migrating vcpu's TSC rate

2015-11-02 Thread Haozhong Zhang
A new subsection 'vmstate_tsc_khz' is added to migrate vcpu's TSC rate. For the backwards compatibility, this subsection is not migrated on pc-*-2.4 and older machine types. Signed-off-by: Haozhong Zhang --- hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 1 + hw/i386/pc_

[PATCH v3 3/3] target-i386: load the migrated vcpu's TSC rate

2015-11-02 Thread Haozhong Zhang
Set vcpu's TSC rate to the migrated value if the user does not specify a TSC rate by cpu option 'tsc-freq' and a migrated TSC rate does exist. If KVM supports TSC scaling, guest programs will observe TSC increasing in the migrated rate other than the host TSC rate. Signed-off-by:

Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-02 Thread Haozhong Zhang
On Mon, Nov 02, 2015 at 09:40:18AM +, James Hogan wrote: > On Mon, Nov 02, 2015 at 05:26:42PM +0800, Haozhong Zhang wrote: > > The value of the migrated vcpu's TSC rate is determined as below. > > 1. If a TSC rate is specified by the cpu option 'tsc-freq', th

Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-04 Thread Haozhong Zhang
On 11/04/15 19:42, Eduardo Habkost wrote: > On Mon, Nov 02, 2015 at 05:26:42PM +0800, Haozhong Zhang wrote: > > The value of the migrated vcpu's TSC rate is determined as below. > > 1. If a TSC rate is specified by the cpu option 'tsc-freq', then this > >

Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-05 Thread Haozhong Zhang
On 11/05/15 09:05, Christian Borntraeger wrote: > Am 02.11.2015 um 10:40 schrieb James Hogan: > > On Mon, Nov 02, 2015 at 05:26:42PM +0800, Haozhong Zhang wrote: > >> The value of the migrated vcpu's TSC rate is determined as below. > >> 1. If a TSC rate is speci

Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-05 Thread haozhong . zhang
On 11/05/15 14:05, Eduardo Habkost wrote: > On Thu, Nov 05, 2015 at 09:30:51AM +0800, Haozhong Zhang wrote: > > On 11/04/15 19:42, Eduardo Habkost wrote: > > > On Mon, Nov 02, 2015 at 05:26:42PM +0800, Haozhong Zhang wrote: > > > > The value of the migrated vcpu

Re: [PATCH v3 3/3] target-i386: load the migrated vcpu's TSC rate

2015-11-05 Thread Haozhong Zhang
On 11/05/15 14:10, Eduardo Habkost wrote: > On Mon, Nov 02, 2015 at 05:26:43PM +0800, Haozhong Zhang wrote: > > Set vcpu's TSC rate to the migrated value if the user does not specify a > > TSC rate by cpu option 'tsc-freq' and a migrated TSC rate does exist. If >

Re: [PATCH v2 00/12] KVM: x86: add support for VMX TSC scaling

2015-11-06 Thread Haozhong Zhang
On 11/06/15 11:49, Paolo Bonzini wrote: > > > 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:

Re: [PATCH v2 00/12] KVM: x86: add support for VMX TSC scaling

2015-11-08 Thread haozhong . zhang
On 11/06/15 21:40, Paolo Bonzini wrote: > > > On 06/11/2015 13:42, Haozhong Zhang wrote: > > On 11/06/15 11:49, Paolo Bonzini wrote: > >> > >> > >> On 20/10/2015 09:39, Haozhong Zhang wrote: > >>> This patchset adds support for VMX TSC sca

Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-08 Thread haozhong . zhang
On 11/06/15 13:12, Eduardo Habkost wrote: > On Fri, Nov 06, 2015 at 10:32:24AM +0800, haozhong.zh...@intel.com wrote: > > On 11/05/15 14:05, Eduardo Habkost wrote: > > > On Thu, Nov 05, 2015 at 09:30:51AM +0800, Haozhong Zhang wrote: > > > > On 11/04/1

Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-09 Thread Haozhong Zhang
5 14:05, Eduardo Habkost wrote: > > > > > On Thu, Nov 05, 2015 at 09:30:51AM +0800, Haozhong Zhang wrote: > > > > > > On 11/04/15 19:42, Eduardo Habkost wrote: > > > [...] > > > > > > > > +env->tsc_khz_saved = r; > >

Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-10 Thread Haozhong Zhang
5 14:05, Eduardo Habkost wrote: > > > > > On Thu, Nov 05, 2015 at 09:30:51AM +0800, Haozhong Zhang wrote: > > > > > > On 11/04/15 19:42, Eduardo Habkost wrote: > > > [...] > > > > > > > > +env->tsc_khz_saved = r; > >

Re: [Qemu-devel] [PATCH v3 1/3] target-i386: add a subsection for migrating vcpu's TSC rate

2015-11-11 Thread Haozhong Zhang
On 11/11/15 12:16, Eduardo Habkost wrote: > On Mon, Nov 02, 2015 at 05:26:41PM +0800, Haozhong Zhang wrote: > > A new subsection 'vmstate_tsc_khz' is added to migrate vcpu's TSC > > rate. For the backwards compatibility, this subsection is not migrated > >

Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-11 Thread Haozhong Zhang
On 11/11/15 13:23, Eduardo Habkost wrote: > On Wed, Nov 11, 2015 at 12:57:44AM +0800, Haozhong Zhang wrote: > > On 11/09/15 14:01, Eduardo Habkost wrote: > > > On Mon, Nov 09, 2015 at 08:33:55AM +0800, haozhong.zh...@intel.com wrote: > > > > On 11/06/15 13:12, Eduar

Re: [PATCH v3 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-11-11 Thread Haozhong Zhang
On 11/11/15 12:54, Eduardo Habkost wrote: > On Tue, Nov 10, 2015 at 09:08:58AM +0800, Haozhong Zhang wrote: > > On 11/09/15 14:01, Eduardo Habkost wrote: > > > On Mon, Nov 09, 2015 at 08:33:55AM +0800, haozhong.zh...@intel.com wrote: > > > > On 11/06/15 13:12, Eduar

Re: [Qemu-devel] [PATCH v3 1/3] target-i386: add a subsection for migrating vcpu's TSC rate

2015-11-12 Thread Haozhong Zhang
On 11/11/15 22:27, Haozhong Zhang wrote: > On 11/11/15 12:16, Eduardo Habkost wrote: [...] > > > diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c > > > index 2f8f396..858ed69 100644 > > > --- a/hw/i386/pc_q35.c > > > +++ b/hw/i386/pc_q35.

Re: [Qemu-devel] [PATCH v3 1/3] target-i386: add a subsection for migrating vcpu's TSC rate

2015-11-15 Thread Haozhong Zhang
On 11/13/15 13:21, Eduardo Habkost wrote: > On Fri, Nov 13, 2015 at 10:23:54AM +0800, Haozhong Zhang wrote: > > On 11/11/15 22:27, Haozhong Zhang wrote: > > > On 11/11/15 12:16, Eduardo Habkost wrote: > > [...] > > > > > diff --git a/hw/i386/pc_q35.c b/h

[PATCH v4 2/2] target-i386: add support to migrate vcpu's TSC rate

2015-11-16 Thread Haozhong Zhang
te is disabled on pc-*-2.4 and older machine types. Signed-off-by: Haozhong Zhang --- hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/hw/i386/pc.h | 1 + target-i386/cpu.c | 2 +- target-i386/cpu.h | 1 + target-i386/kvm.c | 26

[PATCH v4 0/2] target-i386: save/restore vcpu's TSC rate during migration

2015-11-16 Thread Haozhong Zhang
SC rate as above. * Move the setup of migrated TSC rate back to do_kvm_cpu_synchronize_post_init(). Changes in v2: * Add a pair of cpu options 'save-tsc-freq' and 'load-tsc-freq' to control the migration of vcpu's TSC rate. * Move all logic of setting TSC rate to target-i386.

[PATCH v4 1/2] target-i386: fallback vcpu's TSC rate to value returned by KVM

2015-11-16 Thread Haozhong Zhang
If no user-specified TSC rate is present, we will try to set env->tsc_khz to the value returned by KVM_GET_TSC_KHZ. Signed-off-by: Haozhong Zhang --- target-i386/kvm.c | 25 + 1 file changed, 25 insertions(+) diff --git a/target-i386/kvm.c b/target-i386/kvm.c in

Re: [PATCH v4 2/2] target-i386: add support to migrate vcpu's TSC rate

2015-11-16 Thread Haozhong Zhang
On 11/16/15 11:43, Eduardo Habkost wrote: > On Mon, Nov 16, 2015 at 04:04:08PM +0800, Haozhong Zhang wrote: > > This patch enables migrating vcpu's TSC rate. If KVM on the destination > > machine supports TSC scaling, guest programs will observe a consistent > > TSC

Re: [PATCH v4 1/2] target-i386: fallback vcpu's TSC rate to value returned by KVM

2015-11-16 Thread Haozhong Zhang
On 11/16/15 11:39, Eduardo Habkost wrote: > On Mon, Nov 16, 2015 at 04:04:07PM +0800, Haozhong Zhang wrote: > > If no user-specified TSC rate is present, we will try to set > > env->tsc_khz to the value returned by KVM_GET_TSC_KHZ. > > > > Signed-off-by: Haozhong Z

[PATCH v5 1/3] target-i386: fallback vcpu's TSC rate to value returned by KVM

2015-11-16 Thread Haozhong Zhang
If no user-specified TSC rate is present, we will try to set env->tsc_khz to the value returned by KVM_GET_TSC_KHZ. Signed-off-by: Haozhong Zhang --- target-i386/kvm.c | 12 1 file changed, 12 insertions(+) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 2a9953b..9e4d

[PATCH v5 0/3] target-i386: save/restore vcpu's TSC rate during migration

2015-11-16 Thread Haozhong Zhang
es in v2: * Add a pair of cpu options 'save-tsc-freq' and 'load-tsc-freq' to control the migration of vcpu's TSC rate. * Move all logic of setting TSC rate to target-i386. * Remove the duplicated TSC setup in kvm_arch_init_vcpu(). Haozhong Zhang (3): target-i386: fal

[PATCH v5 2/3] target-i386: reorganize TSC rate setting code

2015-11-16 Thread Haozhong Zhang
-by: Haozhong Zhang --- target-i386/kvm.c | 45 ++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 9e4d27f..6a1acb4 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -524,6 +524,41

[PATCH v5 3/3] target-i386: add support to migrate vcpu's TSC rate

2015-11-16 Thread Haozhong Zhang
te is disabled on pc-*-2.4 and older machine types. Signed-off-by: Haozhong Zhang --- hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/hw/i386/pc.h | 1 + target-i386/cpu.c | 2 +- target-i386/cpu.h | 1 + target-i386/kvm.c | 4 ++

Re: [PATCH v4 2/2] target-i386: add support to migrate vcpu's TSC rate

2015-11-16 Thread Haozhong Zhang
On 11/16/15 13:35, Eduardo Habkost wrote: > On Mon, Nov 16, 2015 at 10:30:08PM +0800, Haozhong Zhang wrote: > > On 11/16/15 11:43, Eduardo Habkost wrote: > > > On Mon, Nov 16, 2015 at 04:04:08PM +0800, Haozhong Zhang wrote: > > > > This patch enables migrating

Re: [PATCH v5 1/3] target-i386: fallback vcpu's TSC rate to value returned by KVM

2015-11-17 Thread Haozhong Zhang
On 11/17/15 11:14, Eduardo Habkost wrote: > On Tue, Nov 17, 2015 at 01:20:37PM +0800, Haozhong Zhang wrote: > > If no user-specified TSC rate is present, we will try to set > > env->tsc_khz to the value returned by KVM_GET_TSC_KHZ. > > > > Signed-off-by: Haozhong Z

Re: [PATCH v5 2/3] target-i386: reorganize TSC rate setting code

2015-11-17 Thread Haozhong Zhang
On 11/17/15 11:32, Eduardo Habkost wrote: > On Tue, Nov 17, 2015 at 01:20:38PM +0800, Haozhong Zhang wrote: > > Following two changes are made to the TSC rate setting code in > > kvm_arch_init_vcpu(): > > * The code is moved to a new function kvm_arch_set_tsc_khz(). &

Re: [PATCH v5 3/3] target-i386: add support to migrate vcpu's TSC rate

2015-11-17 Thread Haozhong Zhang
On 11/17/15 11:40, Eduardo Habkost wrote: > Hi, > > On Tue, Nov 17, 2015 at 01:20:39PM +0800, Haozhong Zhang wrote: > > This patch enables migrating vcpu's TSC rate. If KVM on the destination > > machine supports TSC scaling, guest programs will observe a consiste

[PATCH v6 3/3] target-i386: add support to migrate vcpu's TSC rate

2015-11-23 Thread Haozhong Zhang
te is disabled on pc-*-2.4 and older machine types. Signed-off-by: Haozhong Zhang --- hw/i386/pc.c | 1 + hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/hw/i386/pc.h | 1 + target-i386/cpu.c | 2 +- target-i386/cpu.h | 1 + target-i386/kvm.c | 22 +

[PATCH v6 2/3] target-i386: reorganize TSC rate setting code

2015-11-23 Thread Haozhong Zhang
_vcpu() unconditionally, even though the TSC rate to be set is identical to the value currently used by KVM. Signed-off-by: Haozhong Zhang --- target-i386/kvm.c | 40 +--- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/target-i386/kv

[PATCH v6 1/3] target-i386: fallback vcpu's TSC rate to value returned by KVM

2015-11-23 Thread Haozhong Zhang
If no user-specified TSC rate is present, we will try to set env->tsc_khz to the value returned by KVM_GET_TSC_KHZ. This patch does not change the current functionality of QEMU and just prepares for later patches to enable migrating vcpu's TSC rate. Signed-off-by: Haozhong Zhang --- tar

[PATCH v6 0/3] target-i386: save/restore vcpu's TSC rate during migration

2015-11-23 Thread Haozhong Zhang
pu options 'save-tsc-freq' and 'load-tsc-freq' to control the migration of vcpu's TSC rate. * Move all logic of setting TSC rate to target-i386. * Remove the duplicated TSC setup in kvm_arch_init_vcpu(). Haozhong Zhang (3): target-i386: fallback vcpu's TSC rate to va

[PATCH] KVM: nVMX: remove incorrect vpid check in nested invvpid emulation

2015-11-25 Thread Haozhong Zhang
erence. In practice, it can crash both KVM itself and L1 hypervisors that use invvpid (e.g. Xen). Signed-off-by: Haozhong Zhang --- arch/x86/kvm/vmx.c | 5 - 1 file changed, 5 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 87acc52..af823a3 100644 --- a/arch/x86/kvm/v

Re: [PATCH] KVM: nVMX: remove incorrect vpid check in nested invvpid emulation

2015-11-25 Thread Haozhong Zhang
On 11/25/15 10:45, Bandan Das wrote: > Haozhong Zhang writes: > > > This patch removes the vpid check when emulating nested invvpid > > instruction of type all-contexts invalidation. The existing code is > > incorrect because: > > (1) According to Intel SDM Vol 3,

Re: [PATCH v6 3/3] target-i386: add support to migrate vcpu's TSC rate

2015-11-26 Thread Haozhong Zhang
On 11/26/15 12:19, Eduardo Habkost wrote: > On Tue, Nov 24, 2015 at 11:33:57AM +0800, Haozhong Zhang wrote: > > This patch enables migrating vcpu's TSC rate. If KVM on the destination > > machine supports TSC scaling, guest programs will observe a consistent > > TSC

[PATCH] target-i386: check vcpu features before accessing MSR_TSC_AUX

2015-12-14 Thread Haozhong Zhang
), current KVM will fail the saving and thus all other MSRs following it will fail in kvm_get_msrs(). As a result, from KVM commit 9dbe6cf that exposes MSR_TSC_AUX, VM can not successfully reboot. This patch fixes this bug by adding the missing rdtscp feature checks. Signed-off-by: Haozhong Zhang

Re: [PATCH] target-i386: check vcpu features before accessing MSR_TSC_AUX

2015-12-14 Thread Haozhong Zhang
On 12/14/15 12:51, Paolo Bonzini wrote: > > > On 14/12/2015 12:07, Haozhong Zhang wrote: > > This patch fix a bug that prevents VM rebooting on recent versions of > > KVM (from commit 9dbe6cf). > > > > kvm_get_msrs() is called to save guest MSR_TSC_AUX and ot

[PATCH] KVM: VMX: Fix host initiated access to guest MSR_TSC_AUX

2015-12-14 Thread Haozhong Zhang
handling instead. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/vmx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 1a8bfaa..50f2b78 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2802,7 +2802,7 @@ static int

nvdimm: fix header pointer in nvdimm_build_nfit()

2015-12-24 Thread Haozhong Zhang
#x27;header' afterwards may be illegal. This patch fixes this issue by storing an offset within table_data->data[] (rather than an address) in 'header'. Signed-off-by: Haozhong Zhang Reviewed-by: Xiao Guangrong --- hw/acpi/nvdimm.c | 8 +--- 1 file changed, 5 insertions(+

[PATCH] KVM: x86: Use adjustment in guest cycles when handling MSR_IA32_TSC_ADJUST

2015-08-06 Thread Haozhong Zhang
, the current kvm_set_msr_common() uses it as a value in host TSC cycles (by using true as the 3rd parameter of adjust_tsc_offset()), which can result in an incorrect adjustment of TSC offset if SVM TSC scaling is enabled. This patch fixes this problem. Signed-off-by: Haozhong Zhang --- arch/x8

[PATCH 3/3] kvm-all: notice KVM of vcpu's TSC rate after migration

2015-09-27 Thread Haozhong Zhang
t KVM on the target machine supports TSC scaling, guest programs running on the migrated vcpu will observe the same TSC rate before and after the migration. Signed-off-by: Haozhong Zhang --- kvm-all.c | 13 + 1 file changed, 13 insertions(+) diff --git a/kvm-all.c b/kvm-all.c index 0b

[PATCH 1/3] target-i386: add a subsection of vcpu's TSC rate in vmstate_x86_cpu

2015-09-27 Thread Haozhong Zhang
The newly added subsection 'vmstate_tsc_khz' in this patch results in vcpu's TSC rate being saved on the source machine and loaded on the target machine during the migration. Signed-off-by: Haozhong Zhang --- target-i386/machine.c | 20 1 file changed

[PATCH 2/3] target-i386: initialize vcpu's TSC rate to the value from KVM

2015-09-27 Thread Haozhong Zhang
When creating a vcpu, we initialize its TSC rate to the value from KVM (through ioctl KVM_GET_TSC_KHZ). Signed-off-by: Haozhong Zhang --- target-i386/kvm.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 7b0ba17..c2b161a 100644 --- a/target

[PATCH 11/12] KVM: VMX: Use a scaled host TSC for guest readings of MSR_IA32_TSC

2015-09-27 Thread Haozhong Zhang
This patch makes kvm-intel to return a scaled host TSC plus the TSC offset when handling guest readings to MSR_IA32_TSC. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/vmx.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index

[PATCH 12/12] KVM: VMX: Dump TSC multiplier in dump_vmcs()

2015-09-27 Thread Haozhong Zhang
This patch enhances dump_vmcs() to dump the value of TSC multiplier field in VMCS. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/vmx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index d0a2928..b19cdbe 100644 --- a/arch/x86/kvm/vmx.c +++ b

[PATCH 07/12] KVM: x86: Move TSC scaling logic out of call-back read_l1_tsc()

2015-09-27 Thread Haozhong Zhang
Both VMX and SVM scales the host TSC in the same way in call-back read_l1_tsc(), so this patch moves the scaling logic from call-back read_l1_tsc() to a common function kvm_read_l1_tsc(). Signed-off-by: Haozhong Zhang --- arch/x86/kvm/lapic.c | 5 ++--- arch/x86/kvm/svm.c | 3

[PATCH 10/12] KVM: VMX: Setup TSC scaling ratio when a vcpu is loaded

2015-09-27 Thread Haozhong Zhang
This patch makes kvm-intel module to load TSC scaling ratio into TSC multiplier field of VMCS when a vcpu is loaded, so that TSC scaling ratio can take effect if VMX TSC scaling is enabled. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/vmx.c | 6 ++ 1 file changed, 6 insertions(+) diff

[PATCH 09/12] KVM: VMX: Enable and initialize VMX TSC scaling

2015-09-27 Thread Haozhong Zhang
This patch exhances kvm-intel module to enable VMX TSC scaling and collects information of TSC scaling ratio during initialization. Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/vmx.h | 4 +++- arch/x86/kvm/vmx.c | 20 +++- 2 files changed, 22 insertions(+), 2

[PATCH 05/12] KVM: x86: Replace call-back compute_tsc_offset() with a common function

2015-09-27 Thread Haozhong Zhang
Both VMX and SVM calculate the tsc-offset in the same way, so this patch removes the call-back compute_tsc_offset() and replaces it with a common function kvm_compute_tsc_offset(). Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/svm.c | 10

[PATCH 03/12] KVM: x86: Add a common TSC scaling function

2015-09-27 Thread Haozhong Zhang
VMX and SVM calculate the TSC scaling ratio in a similar logic, so this patch generalizes it to a common TSC scaling function. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/svm.c | 48 +++-- arch/x86/kvm/x86.c | 70

[PATCH 04/12] KVM: x86: Replace call-back set_tsc_khz() with a common function

2015-09-27 Thread Haozhong Zhang
Both VMX and SVM propagate virtual_tsc_khz in the same way, so this patch removes the call-back set_tsc_khz() and replaces it with a common function. Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/svm.c | 36

[PATCH 0/3] target-i386: save/restore vcpu's TSC rate during migration

2015-09-27 Thread Haozhong Zhang
This patchset enables QEMU to save/restore vcpu's TSC rate during the migration. When cooperating with KVM which supports TSC scaling, guest programs can observe a consistent guest TSC rate even though they are migrated among machines with different host TSC rates. Haozhong Zhang (3): t

[PATCH 08/12] KVM: x86: Use the correct vcpu's TSC rate to compute time scale

2015-09-27 Thread Haozhong Zhang
This patch makes KVM use virtual_tsc_khz rather than the host TSC rate as vcpu's TSC rate to compute the time scale if TSC scaling is enabled. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/x86.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b

[PATCH 06/12] KVM: x86: Move TSC scaling logic out of call-back adjust_tsc_offset()

2015-09-27 Thread Haozhong Zhang
For both VMX and SVM, if the 2nd argument of call-back adjust_tsc_offset() is the host TSC, then adjust_tsc_offset() will scale it first. This patch moves this common TSC scaling logic to its caller adjust_tsc_offset_host(). Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 13

[PATCH 01/12] KVM: x86: Collect information for setting TSC scaling ratio

2015-09-27 Thread Haozhong Zhang
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

[PATCH 02/12] KVM: x86: Add a common TSC scaling ratio field in kvm_vcpu_arch

2015-09-27 Thread Haozhong Zhang
This patch moves the field of TSC scaling ratio from the architecture struct vcpu_svm to the common struct kvm_vcpu_arch. Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 23 +-- arch/x86/kvm/x86.c | 3

[PATCH 00/12] KVM: x86: add support for VMX TSC scaling

2015-09-27 Thread Haozhong Zhang
logics from SVM code to the common code. Upon them, patch 9 ~ 12 add VMX-specific support for VMX TSC scaling. 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 scalin

Re: [PATCH 2/3] target-i386: initialize vcpu's TSC rate to the value from KVM

2015-09-28 Thread Haozhong Zhang
On Mon, Sep 28, 2015 at 01:17:44PM -0300, Eduardo Habkost wrote: > On Mon, Sep 28, 2015 at 01:38:30PM +0800, Haozhong Zhang wrote: > > When creating a vcpu, we initialize its TSC rate to the value from > > KVM (through ioctl KVM_GET_TSC_KHZ). > > > > Si

Re: [PATCH 2/3] target-i386: initialize vcpu's TSC rate to the value from KVM

2015-09-28 Thread Haozhong Zhang
On Tue, Sep 29, 2015 at 09:23:39AM +0800, Haozhong Zhang wrote: > On Mon, Sep 28, 2015 at 01:17:44PM -0300, Eduardo Habkost wrote: > > On Mon, Sep 28, 2015 at 01:38:30PM +0800, Haozhong Zhang wrote: > > > When creating a vcpu, we initialize its TSC rate to the value from > &

Re: [PATCH 06/12] KVM: x86: Move TSC scaling logic out of call-back adjust_tsc_offset()

2015-09-28 Thread Haozhong Zhang
On Mon, Sep 28, 2015 at 10:14:19PM +0200, Paolo Bonzini wrote: > > > On 28/09/2015 07:38, Haozhong Zhang wrote: > > + > > +static inline void adjust_tsc_offset_guest(struct kvm_vcpu *vcpu, > > + s64 adjustment) > > +{ >

Re: [PATCH 03/12] KVM: x86: Add a common TSC scaling function

2015-09-28 Thread Haozhong Zhang
On Mon, Sep 28, 2015 at 10:12:37PM +0200, Paolo Bonzini wrote: > > > On 28/09/2015 07:38, Haozhong Zhang wrote: > > > > -static u64 __scale_tsc(u64 ratio, u64 tsc) > > -{ > > - u64 mult, frac, _tsc; > > - > > - mult = ratio >

Re: [PATCH 3/3] kvm-all: notice KVM of vcpu's TSC rate after migration

2015-09-28 Thread Haozhong Zhang
On Mon, Sep 28, 2015 at 01:37:34PM -0300, Eduardo Habkost wrote: > On Mon, Sep 28, 2015 at 01:38:31PM +0800, Haozhong Zhang wrote: > > When a vcpu is created in KVM, its TSC rate is initially identical to > > the host TSC rate. If its state is migrated to a vcpu on another >

Re: [PATCH 04/12] KVM: x86: Replace call-back set_tsc_khz() with a common function

2015-09-28 Thread Haozhong Zhang
On Mon, Sep 28, 2015 at 08:27:02PM -0700, Eric Northup wrote: > On Sun, Sep 27, 2015 at 10:38 PM, Haozhong Zhang > wrote: > > > Both VMX and SVM propagate virtual_tsc_khz in the same way, so this > > patch removes the call-back set_tsc_khz() and replaces it with

Re: [PATCH 01/12] KVM: x86: Collect information for setting TSC scaling ratio

2015-09-28 Thread Haozhong Zhang
On Mon, Sep 28, 2015 at 08:28:57PM -0700, Eric Northup wrote: > On Sun, Sep 27, 2015 at 10:38 PM, Haozhong Zhang > wrote: > > > > 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

Re: [PATCH 00/12] KVM: x86: add support for VMX TSC scaling

2015-09-28 Thread Haozhong Zhang
On Mon, Sep 28, 2015 at 09:00:39PM -0700, Eric Northup wrote: > On Sun, Sep 27, 2015 at 10:37 PM, 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 > >

Re: [PATCH 3/3] kvm-all: notice KVM of vcpu's TSC rate after migration

2015-09-29 Thread Haozhong Zhang
On Tue, Sep 29, 2015 at 03:02:07PM -0300, Eduardo Habkost wrote: > On Tue, Sep 29, 2015 at 11:43:34AM +0800, Haozhong Zhang wrote: > > On Mon, Sep 28, 2015 at 01:37:34PM -0300, Eduardo Habkost wrote: > > > On Mon, Sep 28, 2015 at 01:38:31PM +0800, Haozhong Zhang wrote: > [...]

Re: [Qemu-devel] [PATCH 1/3] target-i386: add a subsection of vcpu's TSC rate in vmstate_x86_cpu

2015-09-29 Thread Haozhong Zhang
On Tue, Sep 29, 2015 at 08:00:13PM +0100, Dr. David Alan Gilbert wrote: > * Haozhong Zhang (haozhong.zh...@intel.com) wrote: > > The newly added subsection 'vmstate_tsc_khz' in this patch results in > > vcpu's TSC rate being saved on the source machine and loaded on

Re: [PATCH 3/3] kvm-all: notice KVM of vcpu's TSC rate after migration

2015-10-05 Thread Haozhong Zhang
On Wed, Sep 30, 2015 at 05:36:11PM -0300, Eduardo Habkost wrote: > On Wed, Sep 30, 2015 at 08:32:26AM +0800, Haozhong Zhang wrote: > > > [...] > > > > > Or maybe we shouldn't treat this as VM state, but as configuration, > > > > > and >

Re: [Qemu-devel] [PATCH 1/3] target-i386: add a subsection of vcpu's TSC rate in vmstate_x86_cpu

2015-10-05 Thread Haozhong Zhang
On Wed, Sep 30, 2015 at 09:07:08AM +0100, Dr. David Alan Gilbert wrote: > * Haozhong Zhang (haozhong.zh...@intel.com) wrote: > > On Tue, Sep 29, 2015 at 08:00:13PM +0100, Dr. David Alan Gilbert wrote: > > > * Haozhong Zhang (haozhong.zh...@intel.com) wrote: > > > &

Re: [PATCH 02/12] KVM: x86: Add a common TSC scaling ratio field in kvm_vcpu_arch

2015-10-05 Thread Haozhong Zhang
On Mon, Oct 05, 2015 at 09:26:30PM +0200, Radim Krčmář wrote: > 2015-09-28 13:38+0800, Haozhong Zhang: > > This patch moves the field of TSC scaling ratio from the architecture > > struct vcpu_svm to the common struct kvm_vcpu_arch. > > > > Signed-off-by: Haozhong Zhan

Re: [PATCH 04/12] KVM: x86: Replace call-back set_tsc_khz() with a common function

2015-10-05 Thread Haozhong Zhang
On Mon, Oct 05, 2015 at 09:53:26PM +0200, Radim Krčmář wrote: > 2015-09-28 13:38+0800, Haozhong Zhang: > > Both VMX and SVM propagate virtual_tsc_khz in the same way, so this > > patch removes the call-back set_tsc_khz() and replaces it with a common > > function. > >

Re: [PATCH 04/12] KVM: x86: Replace call-back set_tsc_khz() with a common function

2015-10-06 Thread Haozhong Zhang
On Tue, Oct 06, 2015 at 12:40:49PM +0200, Paolo Bonzini wrote: > > > On 06/10/2015 06:06, Haozhong Zhang wrote: > > Alternatively, it's also possible to follow David's comment to use > > divq on x86_64 to keep both precision and safety. On i386, it just >

[PATCH v2 3/3] target-i386: load the migrated vcpu's TSC rate

2015-10-20 Thread Haozhong Zhang
enabled and the migrated vcpu's TSC rate will override the value specified by the cpu option 'tsc-freq'. Otherwise, the loading will be disabled. The setting of vcpu's TSC rate in this patch duplicates the code in kvm_arch_init_vcpu(), so we remove the latter one. Signed-off-b

[PATCH v2 2/3] target-i386: calculate vcpu's TSC rate to be migrated

2015-10-20 Thread Haozhong Zhang
If vcpu's TSC rate is not specified by the cpu option 'tsc-freq', we will use the value returned by KVM_GET_TSC_KHZ; otherwise, we use the user-specified value. Signed-off-by: Haozhong Zhang --- target-i386/kvm.c | 33 + 1 file changed, 33 inse

[PATCH v2 1/3] target-i386: add a subsection for migrating vcpu's TSC rate

2015-10-20 Thread Haozhong Zhang
types, they can enable it by giving a new cpu option 'save-tsc-freq'. Signed-off-by: Haozhong Zhang --- include/hw/i386/pc.h | 5 + target-i386/cpu.c | 1 + target-i386/cpu.h | 2 ++ target-i386/machine.c | 19 +++ 4 files changed, 27 insertions(+) dif

[PATCH v2 0/3] target-i386: save/restore vcpu's TSC rate during migration

2015-10-20 Thread Haozhong Zhang
SC rate and override the TSC rate given by the cpu option 'tsc-freq'. Changes in v2: * Add a pair of cpu options 'save-tsc-freq' and 'load-tsc-freq' to control the migration of vcpu's TSC rate. * Move all logic of setting TSC rate to target-i386.

[PATCH v2 12/12] KVM: VMX: Dump TSC multiplier in dump_vmcs()

2015-10-20 Thread Haozhong Zhang
This patch enhances dump_vmcs() to dump the value of TSC multiplier field in VMCS. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/vmx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index a02b59c..66d25be 100644 --- a/arch/x86/kvm/vmx.c +++ b

[PATCH v2 10/12] KVM: VMX: Setup TSC scaling ratio when a vcpu is loaded

2015-10-20 Thread Haozhong Zhang
This patch makes kvm-intel module to load TSC scaling ratio into TSC multiplier field of VMCS when a vcpu is loaded, so that TSC scaling ratio can take effect if VMX TSC scaling is enabled. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/vmx.c | 6 ++ 1 file changed, 6 insertions(+) diff

[PATCH v2 07/12] KVM: x86: Move TSC scaling logic out of call-back read_l1_tsc()

2015-10-20 Thread Haozhong Zhang
Both VMX and SVM scales the host TSC in the same way in call-back read_l1_tsc(), so this patch moves the scaling logic from call-back read_l1_tsc() to a common function kvm_read_l1_tsc(). Signed-off-by: Haozhong Zhang --- arch/x86/kvm/lapic.c | 4 ++-- arch/x86/kvm/svm.c | 3

[PATCH v2 05/12] KVM: x86: Replace call-back compute_tsc_offset() with a common function

2015-10-20 Thread Haozhong Zhang
Both VMX and SVM calculate the tsc-offset in the same way, so this patch removes the call-back compute_tsc_offset() and replaces it with a common function kvm_compute_tsc_offset(). Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/svm.c | 10

[PATCH v2 08/12] KVM: x86: Use the correct vcpu's TSC rate to compute time scale

2015-10-20 Thread Haozhong Zhang
This patch makes KVM use virtual_tsc_khz rather than the host TSC rate as vcpu's TSC rate to compute the time scale if TSC scaling is enabled. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/x86.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b

[PATCH v2 00/12] KVM: x86: add support for VMX TSC scaling

2015-10-20 Thread Haozhong Zhang
s 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 Haozhong Zhang (12): KVM: x86: Collect information for setting TSC scaling ratio KVM: x86: Add a common TSC scaling ratio field in

[PATCH v2 01/12] KVM: x86: Collect information for setting TSC scaling ratio

2015-10-20 Thread Haozhong Zhang
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

[PATCH v2 03/12] KVM: x86: Add a common TSC scaling function

2015-10-20 Thread Haozhong Zhang
VMX and SVM calculate the TSC scaling ratio in a similar logic, so this patch generalizes it to a common TSC scaling function. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/svm.c | 48 +++-- arch/x86/kvm/x86.c | 45

[PATCH v2 04/12] KVM: x86: Replace call-back set_tsc_khz() with a common function

2015-10-20 Thread Haozhong Zhang
Both VMX and SVM propagate virtual_tsc_khz in the same way, so this patch removes the call-back set_tsc_khz() and replaces it with a common function. Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/svm.c | 36

[PATCH v2 06/12] KVM: x86: Move TSC scaling logic out of call-back adjust_tsc_offset()

2015-10-20 Thread Haozhong Zhang
(). Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 15 +-- arch/x86/kvm/svm.c | 10 ++ arch/x86/kvm/vmx.c | 4 ++-- include/linux/kvm_host.h| 16 4 files changed, 21 insertions(+), 24 deletions(-) diff

[PATCH v2 09/12] KVM: VMX: Enable and initialize VMX TSC scaling

2015-10-20 Thread Haozhong Zhang
This patch exhances kvm-intel module to enable VMX TSC scaling and collects information of TSC scaling ratio during initialization. Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/vmx.h | 3 +++ arch/x86/kvm/vmx.c | 19 ++- 2 files changed, 21 insertions(+), 1

[PATCH v2 11/12] KVM: VMX: Use a scaled host TSC for guest readings of MSR_IA32_TSC

2015-10-20 Thread Haozhong Zhang
This patch makes kvm-intel to return a scaled host TSC plus the TSC offset when handling guest readings to MSR_IA32_TSC. Signed-off-by: Haozhong Zhang --- arch/x86/kvm/vmx.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c

[PATCH v2 02/12] KVM: x86: Add a common TSC scaling ratio field in kvm_vcpu_arch

2015-10-20 Thread Haozhong Zhang
This patch moves the field of TSC scaling ratio from the architecture struct vcpu_svm to the common struct kvm_vcpu_arch. Signed-off-by: Haozhong Zhang --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 23 +-- arch/x86/kvm/x86.c | 5

Re: [PATCH v2 0/3] target-i386: save/restore vcpu's TSC rate during migration

2015-10-22 Thread Haozhong Zhang
On Thu, Oct 22, 2015 at 04:45:21PM -0200, Eduardo Habkost wrote: > On Tue, Oct 20, 2015 at 03:22:51PM +0800, Haozhong Zhang wrote: > > This patchset enables QEMU to save/restore vcpu's TSC rate during the > > migration. When cooperating with KVM which supports TSC scaling, gu

Re: [PATCH v2 3/3] target-i386: load the migrated vcpu's TSC rate

2015-10-22 Thread Haozhong Zhang
On Thu, Oct 22, 2015 at 04:11:37PM -0200, Eduardo Habkost wrote: > On Tue, Oct 20, 2015 at 03:22:54PM +0800, Haozhong Zhang wrote: > > Set vcpu's TSC rate to the migrated value (if any). If KVM supports TSC > > scaling, guest programs will observe TSC increasing in the migrated

Re: [PATCH v2 3/3] target-i386: load the migrated vcpu's TSC rate

2015-10-22 Thread Haozhong Zhang
On Thu, Oct 22, 2015 at 04:11:37PM -0200, Eduardo Habkost wrote: > On Tue, Oct 20, 2015 at 03:22:54PM +0800, Haozhong Zhang wrote: > > Set vcpu's TSC rate to the migrated value (if any). If KVM supports TSC > > scaling, guest programs will observe TSC increasing in the migrated

Re: [PATCH v2 00/12] KVM: x86: add support for VMX TSC scaling

2015-10-23 Thread Haozhong Zhang
On Fri, Oct 23, 2015 at 12:06:50PM +0200, Joerg Roedel wrote: > On Tue, Oct 20, 2015 at 03:39:00PM +0800, Haozhong Zhang wrote: > > 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 >

Re: [Qemu-devel] [PATCH v2 0/3] target-i386: save/restore vcpu's TSC rate during migration

2015-10-23 Thread Haozhong Zhang
On Fri, Oct 23, 2015 at 08:35:20AM -0200, Marcelo Tosatti wrote: > On Thu, Oct 22, 2015 at 04:45:21PM -0200, Eduardo Habkost wrote: > > On Tue, Oct 20, 2015 at 03:22:51PM +0800, Haozhong Zhang wrote: > > > This patchset enables QEMU to save/restore vcpu's TSC rate during th

Re: [PATCH v2 00/12] KVM: x86: add support for VMX TSC scaling

2015-10-23 Thread Haozhong Zhang
On Fri, Oct 23, 2015 at 02:46:19PM +0200, Joerg Roedel wrote: > On Fri, Oct 23, 2015 at 08:32:28PM +0800, Haozhong Zhang wrote: > > No, since I don't have AMD machines at hand. The modifications to SVM > > code are mostly lifting common code with VMX TSC scaling code, so it &

Re: [PATCH v2 00/12] KVM: x86: add support for VMX TSC scaling

2015-10-23 Thread Haozhong Zhang
Following is how I test this patchset. It should also apply to AMD machines by replacing Intel with AMD and VMX TSC scaling with SVM TSC ratio. * Hardware Requirements 1) Two machines with Intel CPUs, called M_A and M_B below. 2) TSC frequency of CPUs on M_A is different from CPUs on M_B.

  1   2   >