public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [GIT PULL] KVM fix for 2.6.22
@ 2007-06-15  9:43 Avi Kivity
       [not found] ` <11819006133865-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Avi Kivity @ 2007-06-15  9:43 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Linus,

Please pull from the repository and branch at

  git://git.kernel.org/pub/scm/linux/kernel/git/avi/kvm.git for-linus

to get a fix for a fairly critical bug which allows, under certain conditions,
guest fpu state to find its way into the host fpu.

Avi Kivity (1):
      KVM: Prevent guest fpu state from leaking into the host

 drivers/kvm/kvm.h      |    3 +++
 drivers/kvm/kvm_main.c |   22 ++++++++++++++++++++++
 drivers/kvm/vmx.c      |   12 +++---------
 3 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 1c040d8..152312c 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -304,6 +304,7 @@ struct kvm_vcpu {
 	char *host_fx_image;
 	char *guest_fx_image;
 	int fpu_active;
+	int guest_fpu_loaded;
 
 	int mmio_needed;
 	int mmio_read_completed;
@@ -508,6 +509,8 @@ void fx_init(struct kvm_vcpu *vcpu);
 void load_msrs(struct vmx_msr_entry *e, int n);
 void save_msrs(struct vmx_msr_entry *e, int n);
 void kvm_resched(struct kvm_vcpu *vcpu);
+void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);
+void kvm_put_guest_fpu(struct kvm_vcpu *vcpu);
 
 int kvm_read_guest(struct kvm_vcpu *vcpu,
 	       gva_t addr,
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index da985b3..8f1f07a 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -253,6 +253,28 @@ int kvm_write_guest(struct kvm_vcpu *vcpu, gva_t addr, unsigned long size,
 }
 EXPORT_SYMBOL_GPL(kvm_write_guest);
 
+void kvm_load_guest_fpu(struct kvm_vcpu *vcpu)
+{
+	if (!vcpu->fpu_active || vcpu->guest_fpu_loaded)
+		return;
+
+	vcpu->guest_fpu_loaded = 1;
+	fx_save(vcpu->host_fx_image);
+	fx_restore(vcpu->guest_fx_image);
+}
+EXPORT_SYMBOL_GPL(kvm_load_guest_fpu);
+
+void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
+{
+	if (!vcpu->guest_fpu_loaded)
+		return;
+
+	vcpu->guest_fpu_loaded = 0;
+	fx_save(vcpu->guest_fx_image);
+	fx_restore(vcpu->host_fx_image);
+}
+EXPORT_SYMBOL_GPL(kvm_put_guest_fpu);
+
 /*
  * Switches to specified vcpu, until a matching vcpu_put()
  */
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 184238e..c1ac106 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -280,6 +280,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu)
 
 static void vmx_vcpu_put(struct kvm_vcpu *vcpu)
 {
+	kvm_put_guest_fpu(vcpu);
 	put_cpu();
 }
 
@@ -1847,10 +1848,8 @@ again:
 	if (vcpu->guest_debug.enabled)
 		kvm_guest_debug_pre(vcpu);
 
-	if (vcpu->fpu_active) {
-		fx_save(vcpu->host_fx_image);
-		fx_restore(vcpu->guest_fx_image);
-	}
+	kvm_load_guest_fpu(vcpu);
+
 	/*
 	 * Loading guest fpu may have cleared host cr0.ts
 	 */
@@ -2012,11 +2011,6 @@ again:
 	}
 #endif
 
-	if (vcpu->fpu_active) {
-		fx_save(vcpu->guest_fx_image);
-		fx_restore(vcpu->host_fx_image);
-	}
-
 	vcpu->interrupt_window_open = (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0;
 
 	asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [GIT PULL] KVM fix for 2.6.22
       [not found] ` <11819006133865-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
@ 2007-06-15 14:36   ` David Brown
       [not found]     ` <9c21eeae0706150736o6c581222oca883161e8062ed2-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: David Brown @ 2007-06-15 14:36 UTC (permalink / raw)
  To: Avi Kivity
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Linus Torvalds,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

On 6/15/07, Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org> wrote:
> Linus,
>
> Please pull from the repository and branch at
>
>   git://git.kernel.org/pub/scm/linux/kernel/git/avi/kvm.git for-linus
>
> to get a fix for a fairly critical bug which allows, under certain conditions,
> guest fpu state to find its way into the host fpu.
>
> Avi Kivity (1):
>       KVM: Prevent guest fpu state from leaking into the host
>
>  drivers/kvm/kvm.h      |    3 +++
>  drivers/kvm/kvm_main.c |   22 ++++++++++++++++++++++
>  drivers/kvm/vmx.c      |   12 +++---------
>  3 files changed, 28 insertions(+), 9 deletions(-)
>

Yes thank you for the fix Avi. btw what version of kvm is in 2.6.22?
the kvm wiki doesn't say.

Thanks,
- David Brown

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [GIT PULL] KVM fix for 2.6.22
       [not found]     ` <9c21eeae0706150736o6c581222oca883161e8062ed2-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2007-06-16  7:47       ` Avi Kivity
  0 siblings, 0 replies; 3+ messages in thread
From: Avi Kivity @ 2007-06-16  7:47 UTC (permalink / raw)
  To: David Brown
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Linus Torvalds,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

David Brown wrote:
>
> Yes thank you for the fix Avi. btw what version of kvm is in 2.6.22?
> the kvm wiki doesn't say.
>

It's somewhere between kvm-21 and kvm-22.  Any recent version of the
userspace can be used to drive it (i.e. starting with 2.6.22, there is
no need to match kernel and userspace versions).

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-16  7:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-15  9:43 [GIT PULL] KVM fix for 2.6.22 Avi Kivity
     [not found] ` <11819006133865-git-send-email-avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-06-15 14:36   ` David Brown
     [not found]     ` <9c21eeae0706150736o6c581222oca883161e8062ed2-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-06-16  7:47       ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox