All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Jing Liu <jing2.liu@linux.intel.com>
Cc: pbonzini@redhat.com, Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] KVM: x86: Revise guest_fpu xcomp_bv field
Date: Mon, 1 Mar 2021 15:59:59 -0800	[thread overview]
Message-ID: <YD1//+O57mr2D2Ne@google.com> (raw)
In-Reply-To: <20210225104955.3553-1-jing2.liu@linux.intel.com>

On Thu, Feb 25, 2021, Jing Liu wrote:
> XCOMP_BV[63] field indicates that the save area is in the compacted
> format and XCOMP_BV[62:0] indicates the states that have space allocated
> in the save area, including both XCR0 and XSS bits enabled by the host
> kernel. Use xfeatures_mask_all for calculating xcomp_bv and reuse
> XCOMP_BV_COMPACTED_FORMAT defined by kernel.
> 
> Signed-off-by: Jing Liu <jing2.liu@linux.intel.com>
> ---
>  arch/x86/kvm/x86.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 1b404e4d7dd8..f115493f577d 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -4435,8 +4435,6 @@ static int kvm_vcpu_ioctl_x86_set_debugregs(struct kvm_vcpu *vcpu,
>  	return 0;
>  }
>  
> -#define XSTATE_COMPACTION_ENABLED (1ULL << 63)
> -
>  static void fill_xsave(u8 *dest, struct kvm_vcpu *vcpu)
>  {
>  	struct xregs_state *xsave = &vcpu->arch.guest_fpu->state.xsave;
> @@ -4494,7 +4492,8 @@ static void load_xsave(struct kvm_vcpu *vcpu, u8 *src)
>  	/* Set XSTATE_BV and possibly XCOMP_BV.  */
>  	xsave->header.xfeatures = xstate_bv;
>  	if (boot_cpu_has(X86_FEATURE_XSAVES))
> -		xsave->header.xcomp_bv = host_xcr0 | XSTATE_COMPACTION_ENABLED;
> +		xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT |
> +					 xfeatures_mask_all;

Doesn't fill_xsave also need to be updated?  Not with xfeatures_mask_all, but
to account for arch.ia32_xss?  I believe it's a nop with the current code, since
supported_xss is zero, but it should be fixed, no?

>  
>  	/*
>  	 * Copy each region from the non-compacted offset to the
> @@ -9912,9 +9911,6 @@ static void fx_init(struct kvm_vcpu *vcpu)
>  		return;
>  
>  	fpstate_init(&vcpu->arch.guest_fpu->state);
> -	if (boot_cpu_has(X86_FEATURE_XSAVES))
> -		vcpu->arch.guest_fpu->state.xsave.header.xcomp_bv =
> -			host_xcr0 | XSTATE_COMPACTION_ENABLED;

Ugh, this _really_ needs a comment in the changelog.  It took me a while to
realize fpstate_init() does exactly what the new fill_xave() is doing.

And isn't the code in load_xsave() redundant and can be removed?  Any code that
uses get_xsave_addr() would be have a dependency on load_xsave() if it's not
redundant, and I can't see how that would work.

>  
>  	/*
>  	 * Ensure guest xcr0 is valid for loading
> -- 
> 2.18.4
> 

  reply	other threads:[~2021-03-02 15:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-25 10:49 [PATCH v2] KVM: x86: Revise guest_fpu xcomp_bv field Jing Liu
2021-03-01 23:59 ` Sean Christopherson [this message]
2021-03-09  5:31   ` Liu, Jing2

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=YD1//+O57mr2D2Ne@google.com \
    --to=seanjc@google.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=jing2.liu@linux.intel.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@kernel.org \
    /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.