public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Justinien Bouron <justinien.bouron@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: x86: Handle MXCSR in kvm_arch_vcpu_ioctl_{get,set}_fpu.
Date: Tue, 20 Sep 2022 21:33:03 +0000	[thread overview]
Message-ID: <YyoxjwuCVTsbmpYv@google.com> (raw)
In-Reply-To: <20220917000928.118-1-justinien.bouron@gmail.com>

On Sat, Sep 17, 2022, Justinien Bouron wrote:
> kvm_arch_vcpu_ioctl_get_fpu does not set the mxcsr in the kvm_fpu
> struct; conversely kvm_arch_vcpu_ioctl_set_fpu does not set the mxcsr
> value in the fxregs_state struct of the vcpu.
> This leads to the KVM_GET_FPU ioctl returning 0 as the mxcsr value,
> regardless of the actual value on the vcpu; while KVM_SET_FPU leaves the
> MXCSR on the vcpu untouched.
> 
> Fix kvm_arch_vcpu_ioctl_{get,set}_fpu to properly handle MXCSR.
> 
> Signed-off-by: Justinien Bouron <justinien.bouron@gmail.com>
> ---
>  arch/x86/kvm/x86.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 43a6a7efc6ec..c33a2599a497 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -11462,6 +11462,7 @@ int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
>  	fpu->last_ip = fxsave->rip;
>  	fpu->last_dp = fxsave->rdp;
>  	memcpy(fpu->xmm, fxsave->xmm_space, sizeof(fxsave->xmm_space));
> +	fpu->mxcsr = fxsave->mxcsr;
>  
>  	vcpu_put(vcpu);
>  	return 0;
> @@ -11486,6 +11487,7 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
>  	fxsave->rip = fpu->last_ip;
>  	fxsave->rdp = fpu->last_dp;
>  	memcpy(fxsave->xmm_space, fpu->xmm, sizeof(fxsave->xmm_space));
> +	fxsave->mxcsr = fpu->mxcsr;

The incoming MXCSR needs to be vetted, e.g. see fpu_copy_uabi_to_guest_fpstate().

That said, this code is incredibly ancient and has been obsolete for years.  I
wonder if we can get away with deprecating KVM_{G,S}ET_FPU on x86 and leaving the
broken behavior as-is.

      reply	other threads:[~2022-09-20 21:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-17  0:09 [PATCH] KVM: x86: Handle MXCSR in kvm_arch_vcpu_ioctl_{get,set}_fpu Justinien Bouron
2022-09-20 21:33 ` Sean Christopherson [this message]

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=YyoxjwuCVTsbmpYv@google.com \
    --to=seanjc@google.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=justinien.bouron@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=tglx@linutronix.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox