kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Nadav Amit <namit@cs.technion.ac.il>
Cc: kvm@vger.kernel.org, nadav.amit@gmail.com
Subject: Re: [PATCH 08/21] KVM: x86: Reset FPU state during reset
Date: Wed, 05 Nov 2014 13:04:52 +0100	[thread overview]
Message-ID: <545A1264.5030002@redhat.com> (raw)
In-Reply-To: <1414922101-17626-9-git-send-email-namit@cs.technion.ac.il>



On 02/11/2014 10:54, Nadav Amit wrote:
> When resetting the VCPU, the FPU should be reset as well (e.g., XCR0 state).
> Call fx_init during reset as well.

Actually it shouldn't be after INIT.  XCR0 is not mentioned explicitly 
in Table 9-1 of the SDM (IA-32 Processor States Following Power-up, 
Reset, or INIT), but since MSR_IA32_XSS is not specified, I think XCR0 
should fall under "All other MSRs".

> Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
> ---
>  arch/x86/kvm/x86.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 773c17e..9b90ea7 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -7020,6 +7020,9 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu)
>  	vcpu->arch.regs_avail = ~0;
>  	vcpu->arch.regs_dirty = ~0;
>  
> +	/* should never fail, since fpu_alloc already done */
> +	fx_init(vcpu);
> +
>  	kvm_x86_ops->vcpu_reset(vcpu);
>  }
>  
> 

Even then, I think this patch is not really nice...  The call sequence 
leading to kvm_vcpu_reset is:

kvm_vm_ioctl_create_vcpu
        kvm_arch_vcpu_create
                kvm_vcpu_init
                        kvm_arch_vcpu_init
                                fx_init (does fpu_alloc)
        kvm_arch_vcpu_setup
                kvm_vcpu_reset
                        fx_init (no fpu_alloc)

The FPU state is not needed between kvm_arch_vcpu_init and 
kvm_arch_vcpu_setup.  So we could simply move the reset from 
kvm_vcpu_init to kvm_vcpu_reset, like this:

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 904535fe825e..eaa3be26dfdc 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -914,8 +914,6 @@ void kvm_pic_clear_all(struct kvm_pic *pic, int irq_source_id);
 
 void kvm_inject_nmi(struct kvm_vcpu *vcpu);
 
-int fx_init(struct kvm_vcpu *vcpu);
-
 void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
 		       const u8 *new, int bytes);
 int kvm_mmu_unprotect_page(struct kvm *kvm, gfn_t gfn);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 773c17ec42dd..a0566efbb77f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6863,26 +6863,10 @@ int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
 	return 0;
 }
 
-int fx_init(struct kvm_vcpu *vcpu)
+static int fx_init(struct kvm_vcpu *vcpu)
 {
-	int err;
-
-	err = fpu_alloc(&vcpu->arch.guest_fpu);
-	if (err)
-		return err;
-
-	fpu_finit(&vcpu->arch.guest_fpu);
-
-	/*
-	 * Ensure guest xcr0 is valid for loading
-	 */
-	vcpu->arch.xcr0 = XSTATE_FP;
-
-	vcpu->arch.cr0 |= X86_CR0_ET;
-
-	return 0;
+	return fpu_alloc(&vcpu->arch.guest_fpu);
 }
-EXPORT_SYMBOL_GPL(fx_init);
 
 static void fx_free(struct kvm_vcpu *vcpu)
 {
@@ -7020,6 +7004,15 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu)
 	vcpu->arch.regs_avail = ~0;
 	vcpu->arch.regs_dirty = ~0;
 
+	fpu_finit(&vcpu->arch.guest_fpu);
+
+	/*
+	 * Ensure guest xcr0 is valid for loading
+	 */
+	vcpu->arch.xcr0 = XSTATE_FP;
+
+	vcpu->arch.cr0 |= X86_CR0_ET;
+
 	kvm_x86_ops->vcpu_reset(vcpu);
 }
 

However, as said above I'm not applying either patch, at least for now.

Paolo

  reply	other threads:[~2014-11-05 12:05 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-02  9:54 [PATCH 00/21] Fixes for various KVM bugs Nadav Amit
2014-11-02  9:54 ` [PATCH 01/21] KVM: x86: decode_modrm does not regard modrm correctly Nadav Amit
2014-11-05 11:14   ` Paolo Bonzini
2014-11-02  9:54 ` [PATCH 02/21] KVM: x86: No error-code on real-mode exceptions Nadav Amit
2014-11-02  9:54 ` [PATCH 03/21] KVM: x86: Emulator should set DR6 upon GD like real CPU Nadav Amit
2014-11-02  9:54 ` [PATCH 04/21] KVM: x86: Clear DR6[0:3] on #DB during handle_dr Nadav Amit
2014-11-02  9:54 ` [PATCH 05/21] KVM: x86: Breakpoints do not consider CS.base Nadav Amit
2014-11-02  9:54 ` [PATCH 06/21] KVM: x86: Emulator MOV-sreg uses incorrect size Nadav Amit
2014-11-05 11:28   ` Paolo Bonzini
2014-11-02  9:54 ` [PATCH 07/21] KVM: x86: Emulator considers imm as memory operand Nadav Amit
2014-11-05 11:36   ` Paolo Bonzini
2014-11-02  9:54 ` [PATCH 08/21] KVM: x86: Reset FPU state during reset Nadav Amit
2014-11-05 12:04   ` Paolo Bonzini [this message]
2014-11-05 13:20     ` Nadav Amit
2014-11-05 14:55       ` Paolo Bonzini
2014-11-05 20:31         ` Nadav Amit
2014-11-06  8:58           ` Paolo Bonzini
2014-11-06  9:13             ` Nadav Amit
2014-11-06  9:44               ` Paolo Bonzini
2014-11-06  9:56                 ` Nadav Amit
2014-11-06 10:44                   ` Paolo Bonzini
2014-11-06 17:38                 ` Radim Krčmář
2014-11-02  9:54 ` [PATCH 09/21] KVM: x86: SYSCALL cannot clear eflags[1] Nadav Amit
2014-11-02  9:54 ` [PATCH 10/21] KVM: x86: Wrong flags on CMPS and SCAS emulation Nadav Amit
2014-11-02  9:54 ` [PATCH 11/21] KVM: x86: Emulate push sreg as done in Core Nadav Amit
2014-11-02  9:54 ` [PATCH 12/21] KVM: x86: MOV to CR3 can set bit 63 Nadav Amit
2015-02-10 16:15   ` Jan Kiszka
2015-02-10 16:18     ` Paolo Bonzini
2015-02-10 16:34       ` Jan Kiszka
2015-02-10 16:42         ` Paolo Bonzini
2014-11-02  9:54 ` [PATCH 13/21] KVM: x86: Do not update EFLAGS on faulting emulation Nadav Amit
2014-11-02  9:54 ` [PATCH 14/21] KVM: x86: Software disabled APIC should still deliver NMIs Nadav Amit
2014-11-05 12:30   ` Paolo Bonzini
2014-11-05 20:45     ` Nadav Amit
2014-11-06  9:34       ` Paolo Bonzini
2014-11-06 16:45         ` Radim Krčmář
2014-11-10 17:35           ` Paolo Bonzini
2014-11-10 18:06             ` Radim Krčmář
2014-11-14 15:00           ` Paolo Bonzini
2014-11-26 17:01             ` Nadav Amit
2014-11-26 18:00               ` Paolo Bonzini
2014-11-27 13:39               ` Radim Krčmář
2014-11-27 21:45                 ` Nadav Amit
2014-11-27 22:26                   ` Radim Krčmář
2014-12-01 16:30                     ` Paolo Bonzini
2014-12-01 17:49                       ` Radim Krčmář
2014-11-02  9:54 ` [PATCH 15/21] KVM: x86: Combine the lgdt and lidt emulation logic Nadav Amit
2014-11-02  9:54 ` [PATCH 16/21] KVM: x86: Inject #GP when loading system segments with non-canonical base Nadav Amit
2014-11-02  9:54 ` [PATCH 17/21] KVM: x86: Remove redundant and incorrect cpl check on task-switch Nadav Amit
2014-11-02  9:54 ` [PATCH 18/21] KVM: x86: Emulator mis-decodes VEX instructions on real-mode Nadav Amit
2014-11-08  7:25   ` Paolo Bonzini
2014-11-02  9:54 ` [PATCH 19/21] KVM: x86: Warn on APIC base relocation Nadav Amit
2014-11-02  9:55 ` [PATCH 20/21] KVM: x86: MOVNTI emulation min opsize is not respected Nadav Amit
2014-11-05 12:18   ` Paolo Bonzini
2014-11-05 19:58     ` Nadav Amit
2014-11-05 19:58     ` Nadav Amit
2014-11-06  9:23   ` Paolo Bonzini
2014-11-02  9:55 ` [PATCH 21/21] KVM: x86: Return UNHANDLABLE on unsupported SYSENTER Nadav Amit
2014-11-05 12:31 ` [PATCH 00/21] Fixes for various KVM bugs 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=545A1264.5030002@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=nadav.amit@gmail.com \
    --cc=namit@cs.technion.ac.il \
    /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;
as well as URLs for NNTP newsgroup(s).