All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Wanpeng Li <kernellwp@gmail.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	Wanpeng Li <wanpeng.li@hotmail.com>,
	Jim Mattson <jmattson@google.com>
Subject: Re: [PATCH v3 1/2] KVM: X86: Processor States following Reset or INIT
Date: Tue, 10 Oct 2017 20:55:12 +0200	[thread overview]
Message-ID: <20171010185512.GA28763@flask> (raw)
In-Reply-To: <1507589513-125748-1-git-send-email-wanpeng.li@hotmail.com>

2017-10-09 15:51-0700, Wanpeng Li:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
> 
> - XCR0 is reset to 1 by RESET but not INIT
> - XSS is zeroed by both RESET and INIT
> - BNDCFGU, BND0-BND3, BNDCFGS are zeroed by both RESET and INIT
> 
> This patch does this according to SDM.
> 
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Jim Mattson <jmattson@google.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> v2 -> v3:
>  * fix null pointer deference
>  * fix patch description
> v1 -> v2:
>  * XCR0 is not zeroed by INIT
>  * XSS, BNDCFGU, BND0-BND3, BNDCFGS are zeroed by both RESET and INIT
> 
>  arch/x86/kvm/vmx.c |  2 ++
>  arch/x86/kvm/x86.c | 15 +++++++++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> @@ -7804,18 +7804,33 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
>  	kvm_async_pf_hash_reset(vcpu);
>  	vcpu->arch.apf.halted = false;
>  
> +	if (kvm_mpx_supported()) {
> +		void *mpx_state_buffer;
> +
> +		mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu.state.xsave, XFEATURE_MASK_BNDREGS);
> +		if (mpx_state_buffer)
> +			memset(mpx_state_buffer, 0, sizeof(struct mpx_bndreg_state));

I think we should call kvm_put_guest_fpu() before doing this.
The register might be loaded in CPU and XSAVE instruction from
vcpu_put() would overwrite any changes we did.

> +		mpx_state_buffer = get_xsave_addr(&vcpu->arch.guest_fpu.state.xsave, XFEATURE_MASK_BNDCSR);
> +		if (mpx_state_buffer)
> +			memset(mpx_state_buffer, 0, sizeof(u64));

XFEATURE_MASK_BNDCSR is actually

  struct mpx_bndcsr {
  	u64 bndcfgu;
  	u64 bndstatus;
  } __packed;

So clearing two u64 would be correct, thanks.

  parent reply	other threads:[~2017-10-10 18:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-09 22:51 [PATCH v3 1/2] KVM: X86: Processor States following Reset or INIT Wanpeng Li
2017-10-09 22:51 ` [PATCH v3 2/2] KVM: VMX: Don't expose unrestricted_guest is enabled if ept is disabled Wanpeng Li
2017-10-10 17:07   ` Jim Mattson
2017-10-10 18:55 ` Radim Krčmář [this message]
2017-10-11  0:39   ` [PATCH v3 1/2] KVM: X86: Processor States following Reset or INIT Wanpeng Li
2017-10-11 11:36     ` Radim Krčmář
2017-10-11 12:11       ` Wanpeng Li

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=20171010185512.GA28763@flask \
    --to=rkrcmar@redhat.com \
    --cc=jmattson@google.com \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=wanpeng.li@hotmail.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.