[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 haozhong.zh

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
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 fr

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:51:06PM +0200, Paolo Bonzini wrote: > > > On 23/10/2015 14:46, Joerg Roedel 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 > >> > should still work on AMD

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.

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 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:

[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 <haozhong.zh...@intel.com> --- 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 inse

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/vmx.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm

[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 <haozhong.zh...@intel.com> --- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/svm.c

[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 <haozhong.zh...@intel.com> --- arch/x86/include/asm/kvm_host.h | 1 - arch/x

[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 <haozhong.zh...@intel.com> --- 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

[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 <haozhong.zh...@intel.com> --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 23 +-- ar

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/vmx.c | 6 ++ 1 file c

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/lapic.c | 4 ++-- ar

[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 <haozhong.zh...@intel.com> --- arch/x86/include/asm/vmx.h | 3 +++ arch/x86/kvm/vmx.c | 19 ++- 2

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/svm.c | 48 +++-- arch/x86/kvm/x86.c

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

2015-10-20 Thread Haozhong Zhang
y 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 <digitale...@google.com> Haozhong Zhang (12): KVM: x86: Collect information for setting TSC scaling ratio KVM: x86: Add a common T

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/x86.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff

[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

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 > <haozhong.zh...@intel.com> wrote: > > > > The number of bits of the fractional part of the 64-bit TSC scaling > > ratio in VMX and SVM is different. Thi

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 <haozhong.zh...@intel.com> > wrote: > > > Both VMX and SVM propagate virtual_tsc_khz in the same way, so this > > patch removes the call-back

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 > <haozhong.zh...@intel.com> wrote: > > This patchset adds support for VMX TSC scaling feature which is > > available on Intel Skylake CPU. The specification of

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/vmx.c | 6 ++ 1 file c

[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 <haozhong.zh...@intel.com> --- arch/x86/include/asm/kvm_host.h | 1 - arch/x

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/svm.c | 48 +++-- arch/x86/kvm/x86.c

[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 <haozhong.zh...@intel.com> --- arch/x86/include/asm/kvm_host.h | 1 - arch/x86/kvm/svm.c

[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 <haozhong.zh...@intel.com> --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 23 +-- ar

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/x86.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) 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 <haozhong.zh...@intel.com> --- arch/x86/include/asm/vmx.h | 4 +++- arch/x86/kvm/vmx.c | 20 +++- 2

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/vmx.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm

[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 <haozhong.zh...@intel.com> --- arch/x86/kvm/lapic.c | 5 ++--- ar

[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 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 <haozhong.zh...@intel.com> --- ar

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

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

[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 <haozhong.zh...@intel.com> --- 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

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 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 > > fal

[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 <haozhong.zh...@intel.com> --- 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 @@ -

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 <haozhong.zh...@intel.com> writes: > > > This patch removes the vpid check when emulating nested invvpid > > instruction of type all-contexts invalidation. The existing code is > > incorrect because: > &g

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

2015-11-25 Thread Haozhong Zhang
ereference. In practice, it can crash both KVM itself and L1 hypervisors that use invvpid (e.g. Xen). Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.com> --- 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

Re: [PATCH v1] KVM: VMX: enable guest access to LMCE related MSRs

2016-06-05 Thread Haozhong Zhang
On 06/04/16 13:01, Boris Petkov wrote: > Haozhong Zhang <haozhong.zh...@intel.com> wrote: > > >On Intel platforms, this patch adds LMCE to KVM MCE supported > >capabilities and handles guest access to LMCE related MSRs. > > > >Signed-off-by: Ashok Raj

Re: [PATCH v1] KVM: VMX: enable guest access to LMCE related MSRs

2016-06-05 Thread Haozhong Zhang
On 06/03/16 17:34, Radim Krčmář wrote: > 2016-06-03 14:08+0800, Haozhong Zhang: > > On Intel platforms, this patch adds LMCE to KVM MCE supported > > capabilities and handles guest access to LMCE related MSRs. > > > > Signed-off-by: Ashok Raj <ashok@intel.co

[PATCH v1] Add KVM support for Intel local MCE

2016-06-03 Thread Haozhong Zhang
CE feature for guest. This KVM patch handles guest access to LMCE-related MSR (MSR_IA32_MCG_EXT_CTL and MSR_IA32_FEATURE_CONTROL). Haozhong Zhang (1): KVM: VMX: enable guest access to LMCE related MSRs arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/kvm/vmx.c

[PATCH v1] KVM: VMX: enable guest access to LMCE related MSRs

2016-06-03 Thread Haozhong Zhang
On Intel platforms, this patch adds LMCE to KVM MCE supported capabilities and handles guest access to LMCE related MSRs. Signed-off-by: Ashok Raj <ashok@intel.com> Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.com> --- arch/x86/include/asm/kvm_host.h | 3 +++ arch/x

Re: [PATCH v1] KVM: VMX: enable guest access to LMCE related MSRs

2016-06-05 Thread Haozhong Zhang
On 06/05/16 21:43, Borislav Petkov wrote: > On Sun, Jun 05, 2016 at 11:14:56PM +0800, Haozhong Zhang wrote: > > Ashok was also involved in the development of v1 patch and it's based > > on his v0 patch, so I think I should take his SOB? > > You have at least three options: &

[PATCH v3 2/3] KVM: VMX: validate individual bits of guest MSR_IA32_FEATURE_CONTROL

2016-06-22 Thread Haozhong Zhang
KVM currently does not check the value written to guest MSR_IA32_FEATURE_CONTROL, though bits corresponding to disabled features may be set. This patch makes KVM to validate individual bits written to guest MSR_IA32_FEATURE_CONTROL according to enabled features. Signed-off-by: Haozhong Zhang

[PATCH v3 0/3] Add KVM support for Intel local MCE

2016-06-22 Thread Haozhong Zhang
pport for Intel local MCE") enables Intel local MCE feature for guest. This KVM patch handles guest access to LMCE-related MSR (MSR_IA32_MCG_EXT_CTL and MSR_IA32_FEATURE_CONTROL). Ashok Raj (1): KVM: VMX: enable guest access to LMCE related MSRs Haozhong Zhang (2): KVM:

[PATCH v3 1/3] KVM: VMX: move msr_ia32_feature_control to vcpu_vmx

2016-06-22 Thread Haozhong Zhang
msr_ia32_feature_control will be used for LMCE and not depend only on nested anymore, so move it from struct nested_vmx to struct vcpu_vmx. Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.com> --- arch/x86/kvm/vmx.c | 13 ++--- 1 file changed, 6 insertions(+), 7 deletions(-)

[PATCH v3 3/3] KVM: VMX: enable guest access to LMCE related MSRs

2016-06-22 Thread Haozhong Zhang
Only enable LMCE on Intel platform Check MSR_IA32_FEATURE_CONTROL when handling guest access to MSR_IA32_MCG_EXT_CTL] Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.com> --- arch/x86/include/asm/kvm_host.h | 5 + arch/x86/kvm/vm

Re: [PATCH v2 2/3] KVM: VMX: validate individual bits of guest MSR_IA32_FEATURE_CONTROL

2016-06-16 Thread Haozhong Zhang
On 06/16/16 12:01, Paolo Bonzini wrote: > > > On 16/06/2016 08:05, Haozhong Zhang wrote: > > +/* > > + * FEATURE_CONTROL_LOCKED is added/removed automatically by > > + * feature_control_valid_bits_add/del(), so it's not included here. > > + */ > >

Re: [PATCH v2 3/3] KVM: VMX: enable guest access to LMCE related MSRs

2016-06-16 Thread Haozhong Zhang
On 06/16/16 12:04, Paolo Bonzini wrote: > > > On 16/06/2016 08:05, Haozhong Zhang wrote: > > From: Ashok Raj <ashok@intel.com> > > > > On Intel platforms, this patch adds LMCE to KVM MCE supported > > capabilities and handles guest access to LMCE rela

Re: [PATCH v2 1/3] KVM: VMX: move msr_ia32_feature_control to vcpu_vmx

2016-06-16 Thread Haozhong Zhang
On 06/16/16 13:49, Borislav Petkov wrote: > On Thu, Jun 16, 2016 at 02:05:29PM +0800, Haozhong Zhang wrote: > > msr_ia32_feature_control will be used for LMCE and not depend only on > > nested anymore, so move it from struct nested_vmx to struct vcpu_vmx. > > > > Si

Re: [PATCH v2 2/3] KVM: VMX: validate individual bits of guest MSR_IA32_FEATURE_CONTROL

2016-06-16 Thread Haozhong Zhang
On 06/16/16 13:19, Paolo Bonzini wrote: > > > On 16/06/2016 13:16, Haozhong Zhang wrote: > >> However, I think FEATURE_CONTROL_LOCKED should always be writable. If > >> you change that, it's simpler to just do |= and &= in the caller. > > > > T

Re: [PATCH v2 2/3] KVM: VMX: validate individual bits of guest MSR_IA32_FEATURE_CONTROL

2016-06-16 Thread Haozhong Zhang
On 06/16/16 11:55, Paolo Bonzini wrote: > > > On 16/06/2016 08:05, Haozhong Zhang wrote: > > + /* > > +* Only bits masked by msr_ia32_feature_control_valid_bits can be set in > > +* msr_ia32_feature_control. > > +* > > +* msr_ia32_featur

Re: [PATCH v2 3/3] KVM: VMX: enable guest access to LMCE related MSRs

2016-06-16 Thread Haozhong Zhang
On 06/16/16 11:55, Eduardo Habkost wrote: > On Thu, Jun 16, 2016 at 12:04:50PM +0200, Paolo Bonzini wrote: > > On 16/06/2016 08:05, Haozhong Zhang wrote: > > > From: Ashok Raj <ashok@intel.com> > > > > > > On Intel platforms, this patch adds LM

[PATCH v2 0/3] Add KVM support for Intel local MCE

2016-06-16 Thread Haozhong Zhang
hok Raj (1): KVM: VMX: enable guest access to LMCE related MSRs Haozhong Zhang (2): KVM: VMX: move msr_ia32_feature_control to vcpu_vmx KVM: VMX: validate individual bits of guest MSR_IA32_FEATURE_CONTROL arch/x86/include/asm/kvm_host.h | 5 +++ arch/x86/kvm/vmx.c

[PATCH v2 2/3] KVM: VMX: validate individual bits of guest MSR_IA32_FEATURE_CONTROL

2016-06-16 Thread Haozhong Zhang
KVM currently does not check the value written to guest MSR_IA32_FEATURE_CONTROL, though bits corresponding to disabled features may be set. This patch makes KVM to validate individual bits written to guest MSR_IA32_FEATURE_CONTROL according to enabled features. Signed-off-by: Haozhong Zhang

[PATCH v2 3/3] KVM: VMX: enable guest access to LMCE related MSRs

2016-06-16 Thread Haozhong Zhang
Only enable LMCE on Intel platform Check MSR_IA32_FEATURE_CONTROL when handling guest access to MSR_IA32_MCG_EXT_CTL] Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.com> --- arch/x86/include/asm/kvm_host.h | 5 + arch/x86/kvm/vm

[PATCH v2 1/3] KVM: VMX: move msr_ia32_feature_control to vcpu_vmx

2016-06-16 Thread Haozhong Zhang
msr_ia32_feature_control will be used for LMCE and not depend only on nested anymore, so move it from struct nested_vmx to struct vcpu_vmx. Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.com> --- arch/x86/kvm/vmx.c | 11 ++- 1 file changed, 6 insertions(+), 5 deletions(-)

Re: [PATCH v3] KVM: nVMX: Fix incorrect preemption timer vmexit in nested guest

2016-07-06 Thread Haozhong Zhang
vmexit, incurr a nested vmexit dereference NULL pointer. > > This patch fix it by depending on check_nested_events to capture L2 > preemption > timer(emulated hrtimer) expire and nested vmexit. > > Cc: Paolo Bonzini <pbonz...@redhat.com> > Cc: Radim Krčmář <rkrc...@r

Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when L2 guest is running

2016-07-06 Thread Haozhong Zhang
On 07/06/16 13:37, Wanpeng Li wrote: > Cc Jan, > 2016-07-06 13:10 GMT+08:00 Haozhong Zhang <haozhong.zh...@intel.com>: > > A different VMCS is loaded when L2 guest is running, so it's incorrect > > to use the VMX preemption timer for L1 TSC deadline timer. This patch > &

Re: [PATCH 1/2] KVM: x86: move MSR_IA32_FEATURE_CONTROL handling to x86.c

2016-07-08 Thread Haozhong Zhang
On 07/08/16 14:01, Paolo Bonzini wrote: > Because the MSR is listed in msrs_to_save, it is exported to userspace > for both AMD and Intel processors. However, on AMD currently getting > it will fail. > Is MSR_IA32_FEATURE_CONTROL already be excluded from msrs_to_save[] by kvm_init_msr_list() on

Re: [PATCH 2/2] KVM: x86: zero MSR_IA32_FEATURE_CONTROL on reset

2016-07-08 Thread Haozhong Zhang
On 07/08/16 14:01, Paolo Bonzini wrote: > Reported-by: Laszlo Ersek > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/x86.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index

Re: [PATCH v3] KVM: nVMX: Fix incorrect preemption timer vmexit in nested guest

2016-07-06 Thread Haozhong Zhang
On 07/06/16 15:32, Paolo Bonzini wrote: > > > On 06/07/2016 15:26, Haozhong Zhang wrote: > > On 07/06/16 19:42, Wanpeng Li wrote: > >> From: Wanpeng Li <wanpeng...@hotmail.com> > >> > >> BUG: unable to handle kernel NULL pointer dereferenc

Re: [PATCH v3 1/2] KVM: nVMX: Fix incorrect preemption timer vmexit in nested guest

2016-07-07 Thread Haozhong Zhang
urr a nested vmexit dereference NULL pointer. > > This patch fix it by depending on check_nested_events to capture L2 preemption > timer(emulated hrtimer) expire and nested vmexit. > > Tested-by: Haozhong Zhang <haozhong.zh...@intel.com> > Cc: Paolo Bonzini <pbonz..

Re: [PATCH v3 1/2] KVM: nVMX: Fix incorrect preemption timer vmexit in nested guest

2016-07-07 Thread Haozhong Zhang
On 07/07/16 14:56, Wanpeng Li wrote: > 2016-07-07 14:48 GMT+08:00 Haozhong Zhang <haozhong.zh...@intel.com>: > > On 07/07/16 11:46, Wanpeng Li wrote: > >> From: Wanpeng Li <wanpeng...@hotmail.com> > >> > >> BUG: unable to handle kernel NULL

Re: [PATCH v3 1/2] KVM: nVMX: Fix incorrect preemption timer vmexit in nested guest

2016-07-07 Thread Haozhong Zhang
On 07/07/16 15:07, Wanpeng Li wrote: > 2016-07-07 15:02 GMT+08:00 Haozhong Zhang <haozhong.zh...@intel.com>: > > On 07/07/16 14:56, Wanpeng Li wrote: > >> 2016-07-07 14:48 GMT+08:00 Haozhong Zhang <haozhong.zh...@intel.com>: > >> > On 07/07/16 11:46,

Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when L2 guest is running

2016-07-06 Thread Haozhong Zhang
On 07/06/16 09:46, Paolo Bonzini wrote: > > > On 06/07/2016 08:05, Haozhong Zhang wrote: > >> > > >> > Nested preemption timer is emulated by hrtimer, so it doesn't > >> > influence vmcs02, why this is needed? > > Nested (L2) preemp

Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when L2 guest is running

2016-07-06 Thread Haozhong Zhang
On 07/06/16 16:01, Haozhong Zhang wrote: > On 07/06/16 09:46, Paolo Bonzini wrote: > > > > > > On 06/07/2016 08:05, Haozhong Zhang wrote: > > >> > > > >> > Nested preemption timer is emulated by hrtimer, so it doesn't > > >> >

Re: [PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when L2 guest is running

2016-07-06 Thread Haozhong Zhang
On 07/06/16 04:14, Paolo Bonzini wrote: > > On 07/06/16 16:01, Haozhong Zhang wrote: > > > On 07/06/16 09:46, Paolo Bonzini wrote: > > > > On 06/07/2016 08:05, Haozhong Zhang wrote: > > > > >> > Nested preemption timer is emulated by hrtimer,

[PATCH] KVM: VMX: switch to hrtimer for TSC deadline timer when L2 guest is running

2016-07-05 Thread Haozhong Zhang
-by: Haozhong Zhang <haozhong.zh...@intel.com> --- arch/x86/kvm/vmx.c | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 85e2f0a..cc29c2a 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -10203,6 +10203,9 @@ static int nested_v

Re: [PATCH v2 3/3] KVM: VMX: enable guest access to LMCE related MSRs

2016-06-19 Thread Haozhong Zhang
On 06/17/16 14:15, Eduardo Habkost wrote: > On Fri, Jun 17, 2016 at 09:11:16AM +0800, Haozhong Zhang wrote: > > On 06/16/16 11:55, Eduardo Habkost wrote: > > > On Thu, Jun 16, 2016 at 12:04:50PM +0200, Paolo Bonzini wrote: > > > > On 16/06/2016 08:05, Haozhong Zhan

Re: [Xen-devel] [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-20 Thread Haozhong Zhang
On 10/14/16 04:16 -0600, Jan Beulich wrote: On 13.10.16 at 17:46, wrote: On 10/13/16 03:08 -0600, Jan Beulich wrote: On 13.10.16 at 10:53, wrote: On 10/13/16 02:34 -0600, Jan Beulich wrote: On 12.10.16 at 18:19,

Re: [Xen-devel] [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-20 Thread Haozhong Zhang
On 10/14/16 13:18 +0100, Andrew Cooper wrote: On 14/10/16 08:08, Haozhong Zhang wrote: On 10/13/16 20:33 +0100, Andrew Cooper wrote: On 13/10/16 19:59, Dan Williams wrote: On Thu, Oct 13, 2016 at 9:01 AM, Andrew Cooper <andrew.coop...@citrix.com> wrote: On 13/10/16 16:40, Dan Williams

Re: [Xen-devel] [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-13 Thread Haozhong Zhang
On 10/13/16 03:08 -0600, Jan Beulich wrote: On 13.10.16 at 10:53, wrote: On 10/13/16 02:34 -0600, Jan Beulich wrote: On 12.10.16 at 18:19, wrote: On Wed, Oct 12, 2016 at 9:01 AM, Jan Beulich wrote: On 12.10.16 at

Re: [Xen-devel] [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-12 Thread Haozhong Zhang
On 10/11/16 13:17 -0700, Dan Williams wrote: On Tue, Oct 11, 2016 at 12:48 PM, Konrad Rzeszutek Wilk wrote: On Tue, Oct 11, 2016 at 12:28:56PM -0700, Dan Williams wrote: On Tue, Oct 11, 2016 at 11:33 AM, Konrad Rzeszutek Wilk wrote: > On Tue,

Re: [Xen-devel] [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-14 Thread Haozhong Zhang
On 10/13/16 20:33 +0100, Andrew Cooper wrote: On 13/10/16 19:59, Dan Williams wrote: On Thu, Oct 13, 2016 at 9:01 AM, Andrew Cooper wrote: On 13/10/16 16:40, Dan Williams wrote: On Thu, Oct 13, 2016 at 2:08 AM, Jan Beulich wrote: [..] I think

Re: [Xen-devel] [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-12 Thread Haozhong Zhang
On 10/12/16 05:32 -0600, Jan Beulich wrote: On 12.10.16 at 12:33, wrote: The layout is shown as the following diagram. +---+---+---+--+--+ | whatever used | Partition | Super | Reserved | /dev/pmem0p1 | | by kernel|

Re: [Xen-devel] [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-13 Thread Haozhong Zhang
On 10/13/16 02:34 -0600, Jan Beulich wrote: On 12.10.16 at 18:19, wrote: On Wed, Oct 12, 2016 at 9:01 AM, Jan Beulich wrote: On 12.10.16 at 17:42, wrote: On Wed, Oct 12, 2016 at 8:39 AM, Jan Beulich

Re: [Xen-devel] [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-13 Thread Haozhong Zhang
+Dan Williams I accidentally dropped him in my last reply. Add him back. On 10/13/16 16:53 +0800, Haozhong Zhang wrote: On 10/13/16 02:34 -0600, Jan Beulich wrote: On 12.10.16 at 18:19, <dan.j.willi...@intel.com> wrote: On Wed, Oct 12, 2016 at 9:01 AM, Jan Beulich <jbeul...@suse.c

[RFC KERNEL PATCH 1/2] nvdimm: add PFN_MODE_XEN to pfn device for Xen usage

2016-10-09 Thread Haozhong Zhang
pfn device in PFN_MODE_XEN reserves an area for Xen hypervisor to place its own pmem management data structures (i.e. frame table and M2P table). The reserved area is not used and not mapped by Linux kernel, and only the data area is mapped. Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.

[RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-09 Thread Haozhong Zhang
00/16] Add vNVDIMM support to HVM domains". Haozhong Zhang (2): nvdimm: add PFN_MODE_XEN to pfn device for Xen usage xen, nvdimm: report pfn devices in PFN_MODE_XEN to Xen hypervisor drivers/nvdimm/namespace_devs.c | 2 ++ drivers/nvdimm/nd.h | 7 + drivers/nvdimm/

[RFC KERNEL PATCH 2/2] xen, nvdimm: report pfn devices in PFN_MODE_XEN to Xen hypervisor

2016-10-09 Thread Haozhong Zhang
Xen hypervisor does not include NVDIMM driver and relies on the driver in Dom0 Linux to probe pfn devices in PFN_MODE_XEN. Whenever such a pfn device is probed, Dom0 Linux reports pages of the entire device, its reserved area and data area to Xen hypervisor. Signed-off-by: Haozhong Zhang

Re: [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-10 Thread Haozhong Zhang
On 10/09/16 20:45, Dan Williams wrote: > On Sun, Oct 9, 2016 at 5:35 PM, Haozhong Zhang <haozhong.zh...@intel.com> > wrote: > > Overview > > > > This RFC kernel patch series along with corresponding patch series of > > Xen, QEMU and ndctl implements

Re: [Xen-devel] [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-10 Thread Haozhong Zhang
On 10/10/16 17:43, Andrew Cooper wrote: > On 10/10/16 01:35, Haozhong Zhang wrote: > > Overview > > > > This RFC kernel patch series along with corresponding patch series of > > Xen, QEMU and ndctl implements Xen vNVDIMM, which can map the host > &g

Re: [RFC KERNEL PATCH 0/2] Add Dom0 NVDIMM support for Xen

2016-10-11 Thread Haozhong Zhang
On 10/10/16 09:24, Dan Williams wrote: > On Sun, Oct 9, 2016 at 11:32 PM, Haozhong Zhang > <haozhong.zh...@intel.com> wrote: > > On 10/09/16 20:45, Dan Williams wrote: > >> On Sun, Oct 9, 2016 at 5:35 PM, Haozhong Zhang <haozhong.zh...@intel.com

[PATCH v6 0/2] KVM: MMU: fix kvm_is_mmio_pfn()

2017-12-19 Thread Haozhong Zhang
. Changes in v3: * Move cache mode check to pat.c as pat_pfn_is_uc() * Reintroduce converters between kvm_pfn_t and pfn_t. Changes in v2: * Switch to lookup_memtype() to get host memory type. * Rewrite the comment in KVM MMU patch. * Remove v1 patch 2, which is not necessary in v2. Haozhong Zhang (2

[PATCH v6 1/2] x86/mm: add a function to check if a pfn is UC/UC-/WCee

2017-12-19 Thread Haozhong Zhang
Check whether the PAT memory type of a pfn cannot be overridden by MTRR UC memory type, i.e. the PAT memory type is UC, UC- or WC. This function will be used by KVM to determine whether it needs to map a host pfn to guest with UC memory type. Signed-off-by: Haozhong Zhang <haozhong

[PATCH v6 2/2] KVM: MMU: consider host cache mode in MMIO page check

2017-12-19 Thread Haozhong Zhang
pages would be harmed. Therefore, we check the host memory type in addition and only treat UC/UC-/WC pages as MMIO. Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.com> Reported-by: Cuevas Escareno, Ivan D <ivan.d.cuevas.escar...@intel.com> Reported-by: Kumar, Karthik <karthik.

Re: [PATCH v5 1/2] x86/mm: add a function to check if a pfn is UC/UC-

2017-12-18 Thread Haozhong Zhang
On 12/18/17 13:55 +0100, Paolo Bonzini wrote: > On 08/11/2017 08:56, Haozhong Zhang wrote: > > +bool pat_pfn_is_uc_or_uc_minus(unsigned long pfn) > > +{ > > + enum page_cache_mode cm = lookup_memtype(PFN_PHYS(pfn)); > > + > > + retur

Re: [PATCH v5 1/2] x86/mm: add a function to check if a pfn is UC/UC-

2017-11-15 Thread Haozhong Zhang
On 11/15/17 07:17 -0800, Dan Williams wrote: > On Tue, Nov 7, 2017 at 11:56 PM, Haozhong Zhang > <haozhong.zh...@intel.com> wrote: > > It will be used by KVM to check whether a pfn should be > > mapped to guest as UC. > > > > Signed-off-by: Haoz

Re: [PATCH v5 1/2] x86/mm: add a function to check if a pfn is UC/UC-

2017-11-15 Thread Haozhong Zhang
On 11/15/17 11:44 +0100, David Hildenbrand wrote: > On 08.11.2017 08:56, Haozhong Zhang wrote: > > It will be used by KVM to check whether a pfn should be > > mapped to guest as UC. > > > > Signed-off-by: Haozhong Zhang <haozhong.zh...@intel.com> > > -

Re: [PATCH v4 3/3] KVM: MMU: consider host cache mode in MMIO page check

2017-11-03 Thread Haozhong Zhang
On 11/03/17 16:51 +0800, Haozhong Zhang wrote: > On 11/03/17 14:54 +0800, Xiao Guangrong wrote: > > > > > > On 11/03/2017 01:53 PM, Haozhong Zhang wrote: > > > Some reserved pages, such as those from NVDIMM DAX devices, are > > > not for MMIO, and can be ma

Re: [PATCH v4 3/3] KVM: MMU: consider host cache mode in MMIO page check

2017-11-03 Thread Haozhong Zhang
On 11/03/17 17:10 +0800, Xiao Guangrong wrote: > > > On 11/03/2017 04:51 PM, Haozhong Zhang wrote: > > On 11/03/17 14:54 +0800, Xiao Guangrong wrote: > > > > > > > > > On 11/03/2017 01:53 PM, Haozhong Zhang wrote: > > > > Some

Re: [PATCH v4 3/3] KVM: MMU: consider host cache mode in MMIO page check

2017-11-03 Thread Haozhong Zhang
On 11/03/17 17:24 +0800, Xiao Guangrong wrote: > > > On 11/03/2017 05:02 PM, Haozhong Zhang wrote: > > On 11/03/17 16:51 +0800, Haozhong Zhang wrote: > > > On 11/03/17 14:54 +0800, Xiao Guangrong wrote: > > > > > > > > > > > >

Re: [PATCH v4 3/3] KVM: MMU: consider host cache mode in MMIO page check

2017-11-03 Thread Haozhong Zhang
On 11/03/17 14:54 +0800, Xiao Guangrong wrote: > > > On 11/03/2017 01:53 PM, Haozhong Zhang wrote: > > Some reserved pages, such as those from NVDIMM DAX devices, are > > not for MMIO, and can be mapped with cached memory type for better > > performance. However, t

  1   2   >