Re: [PATCH v3 1/2] KVM: X86: Processor States following Reset or INIT

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2017-10-09 15:51-0700, Wanpeng Li:
> From: Wanpeng Li <wanpeng.li@xxxxxxxxxxx>
> 
> - 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@xxxxxxxxxx>
> Cc: Radim Krčmář <rkrcmar@xxxxxxxxxx>
> Cc: Jim Mattson <jmattson@xxxxxxxxxx>
> Signed-off-by: Wanpeng Li <wanpeng.li@xxxxxxxxxxx>
> ---
> 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.



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux