All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Liu, Jinsong" <jinsong.liu@intel.com>
Cc: "gleb@redhat.com" <gleb@redhat.com>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Ren, Qiaowei" <qiaowei.ren@intel.com>
Subject: Re: [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug
Date: Wed, 22 Jan 2014 12:05:01 +0100	[thread overview]
Message-ID: <52DFA5DD.7000602@redhat.com> (raw)
In-Reply-To: <DE8DF0795D48FD4CA783C40EC82923350149E30B@SHSMSX101.ccr.corp.intel.com>

Il 21/01/2014 19:59, Liu, Jinsong ha scritto:
> From 3155a190ce6ebb213e6c724240f4e6620ba67a9d Mon Sep 17 00:00:00 2001
> From: Liu Jinsong <jinsong.liu@intel.com>
> Date: Fri, 13 Dec 2013 02:32:03 +0800
> Subject: [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug
>
> EBX of cpuid(0xD, 0) is dynamic per XCR0 features enable/disable.
> Bit 63 of XCR0 is reserved for future expansion.
>
> Signed-off-by: Liu Jinsong <jinsong.liu@intel.com>
> ---
>  arch/x86/include/asm/xsave.h |    2 ++
>  arch/x86/kvm/cpuid.c         |    6 +++---
>  arch/x86/kvm/x86.c           |    7 +++++--
>  3 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
> index 5547389..f6c4e85 100644
> --- a/arch/x86/include/asm/xsave.h
> +++ b/arch/x86/include/asm/xsave.h
> @@ -13,6 +13,8 @@
>  #define XSTATE_BNDCSR	0x10
>
>  #define XSTATE_FPSSE	(XSTATE_FP | XSTATE_SSE)
> +/* Bit 63 of XCR0 is reserved for future expansion */
> +#define XSTATE_EXTEND_MASK	(~(XSTATE_FPSSE | (1 << 63)))

This should be 1ULL, not 1.  The compiler should have warned you.

Paolo

>
>  #define FXSAVE_SIZE	512
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index c697625..2d661e6 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -28,7 +28,7 @@ static u32 xstate_required_size(u64 xstate_bv)
>  	int feature_bit = 0;
>  	u32 ret = XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET;
>
> -	xstate_bv &= ~XSTATE_FPSSE;
> +	xstate_bv &= XSTATE_EXTEND_MASK;
>  	while (xstate_bv) {
>  		if (xstate_bv & 0x1) {
>  		        u32 eax, ebx, ecx, edx;
> @@ -74,8 +74,8 @@ void kvm_update_cpuid(struct kvm_vcpu *vcpu)
>  		vcpu->arch.guest_supported_xcr0 =
>  			(best->eax | ((u64)best->edx << 32)) &
>  			host_xcr0 & KVM_SUPPORTED_XCR0;
> -		vcpu->arch.guest_xstate_size =
> -			xstate_required_size(vcpu->arch.guest_supported_xcr0);
> +		vcpu->arch.guest_xstate_size = best->ebx =
> +			xstate_required_size(vcpu->arch.xcr0);
>  	}
>
>  	kvm_pmu_cpuid_update(vcpu);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 21ef1ba..1657ca2 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -576,13 +576,13 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu)
>
>  int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
>  {
> -	u64 xcr0;
> +	u64 xcr0 = xcr;
> +	u64 old_xcr0 = vcpu->arch.xcr0;
>  	u64 valid_bits;
>
>  	/* Only support XCR_XFEATURE_ENABLED_MASK(xcr0) now  */
>  	if (index != XCR_XFEATURE_ENABLED_MASK)
>  		return 1;
> -	xcr0 = xcr;
>  	if (!(xcr0 & XSTATE_FP))
>  		return 1;
>  	if ((xcr0 & XSTATE_YMM) && !(xcr0 & XSTATE_SSE))
> @@ -599,6 +599,9 @@ int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
>
>  	kvm_put_guest_xcr0(vcpu);
>  	vcpu->arch.xcr0 = xcr0;
> +
> +	if ((xcr0 ^ old_xcr0) & XSTATE_EXTEND_MASK)
> +		kvm_update_cpuid(vcpu);
>  	return 0;
>  }
>
>


WARNING: multiple messages have this Message-ID (diff)
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Liu, Jinsong" <jinsong.liu@intel.com>
Cc: "gleb@redhat.com" <gleb@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"Ren, Qiaowei" <qiaowei.ren@intel.com>
Subject: Re: [Qemu-devel] [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug
Date: Wed, 22 Jan 2014 12:05:01 +0100	[thread overview]
Message-ID: <52DFA5DD.7000602@redhat.com> (raw)
In-Reply-To: <DE8DF0795D48FD4CA783C40EC82923350149E30B@SHSMSX101.ccr.corp.intel.com>

Il 21/01/2014 19:59, Liu, Jinsong ha scritto:
> From 3155a190ce6ebb213e6c724240f4e6620ba67a9d Mon Sep 17 00:00:00 2001
> From: Liu Jinsong <jinsong.liu@intel.com>
> Date: Fri, 13 Dec 2013 02:32:03 +0800
> Subject: [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug
>
> EBX of cpuid(0xD, 0) is dynamic per XCR0 features enable/disable.
> Bit 63 of XCR0 is reserved for future expansion.
>
> Signed-off-by: Liu Jinsong <jinsong.liu@intel.com>
> ---
>  arch/x86/include/asm/xsave.h |    2 ++
>  arch/x86/kvm/cpuid.c         |    6 +++---
>  arch/x86/kvm/x86.c           |    7 +++++--
>  3 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
> index 5547389..f6c4e85 100644
> --- a/arch/x86/include/asm/xsave.h
> +++ b/arch/x86/include/asm/xsave.h
> @@ -13,6 +13,8 @@
>  #define XSTATE_BNDCSR	0x10
>
>  #define XSTATE_FPSSE	(XSTATE_FP | XSTATE_SSE)
> +/* Bit 63 of XCR0 is reserved for future expansion */
> +#define XSTATE_EXTEND_MASK	(~(XSTATE_FPSSE | (1 << 63)))

This should be 1ULL, not 1.  The compiler should have warned you.

Paolo

>
>  #define FXSAVE_SIZE	512
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index c697625..2d661e6 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -28,7 +28,7 @@ static u32 xstate_required_size(u64 xstate_bv)
>  	int feature_bit = 0;
>  	u32 ret = XSAVE_HDR_SIZE + XSAVE_HDR_OFFSET;
>
> -	xstate_bv &= ~XSTATE_FPSSE;
> +	xstate_bv &= XSTATE_EXTEND_MASK;
>  	while (xstate_bv) {
>  		if (xstate_bv & 0x1) {
>  		        u32 eax, ebx, ecx, edx;
> @@ -74,8 +74,8 @@ void kvm_update_cpuid(struct kvm_vcpu *vcpu)
>  		vcpu->arch.guest_supported_xcr0 =
>  			(best->eax | ((u64)best->edx << 32)) &
>  			host_xcr0 & KVM_SUPPORTED_XCR0;
> -		vcpu->arch.guest_xstate_size =
> -			xstate_required_size(vcpu->arch.guest_supported_xcr0);
> +		vcpu->arch.guest_xstate_size = best->ebx =
> +			xstate_required_size(vcpu->arch.xcr0);
>  	}
>
>  	kvm_pmu_cpuid_update(vcpu);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 21ef1ba..1657ca2 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -576,13 +576,13 @@ static void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu)
>
>  int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
>  {
> -	u64 xcr0;
> +	u64 xcr0 = xcr;
> +	u64 old_xcr0 = vcpu->arch.xcr0;
>  	u64 valid_bits;
>
>  	/* Only support XCR_XFEATURE_ENABLED_MASK(xcr0) now  */
>  	if (index != XCR_XFEATURE_ENABLED_MASK)
>  		return 1;
> -	xcr0 = xcr;
>  	if (!(xcr0 & XSTATE_FP))
>  		return 1;
>  	if ((xcr0 & XSTATE_YMM) && !(xcr0 & XSTATE_SSE))
> @@ -599,6 +599,9 @@ int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
>
>  	kvm_put_guest_xcr0(vcpu);
>  	vcpu->arch.xcr0 = xcr0;
> +
> +	if ((xcr0 ^ old_xcr0) & XSTATE_EXTEND_MASK)
> +		kvm_update_cpuid(vcpu);
>  	return 0;
>  }
>
>

  parent reply	other threads:[~2014-01-22 11:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-21 18:59 [PATCH v3 1/4] KVM/X86: Fix xsave cpuid exposing bug Liu, Jinsong
2014-01-21 18:59 ` [Qemu-devel] " Liu, Jinsong
2014-01-22 10:21 ` Paolo Bonzini
2014-01-22 10:21   ` [Qemu-devel] " Paolo Bonzini
2014-01-22 10:31   ` H. Peter Anvin
2014-01-22 10:31     ` [Qemu-devel] " H. Peter Anvin
2014-01-22 11:05 ` Paolo Bonzini [this message]
2014-01-22 11:05   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52DFA5DD.7000602@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=gleb@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jinsong.liu@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qiaowei.ren@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.