All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arun Sharma <arun.sharma@intel.com>
To: Ian Pratt <Ian.Pratt@cl.cam.ac.uk>,
	Keir Fraser <Keir.Fraser@cl.cam.ac.uk>
Cc: xen-devel@lists.xensource.com
Subject: [PATCH] vmx_fpu.patch
Date: Wed, 11 May 2005 11:23:35 -0700	[thread overview]
Message-ID: <20050511182335.GA29157@intel.com> (raw)

Implement a eager save/lazy restore algorithm for dealing with the FP state of a VMX guest.

Signed-off-by: Xin B Li <xin.b.li@intel.com>
Signed-off-by: Asit Mallick <asit.k.mallick@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@intel.com>

--- 1.171/xen/arch/x86/traps.c	2005-05-10 03:53:31 -07:00
+++ edited/xen/arch/x86/traps.c	2005-05-11 11:09:00 -07:00
@@ -917,15 +917,7 @@
 asmlinkage int math_state_restore(struct cpu_user_regs *regs)
 {
     /* Prevent recursion. */
-    clts();
-
-    if ( !test_and_set_bit(EDF_USEDFPU, &current->flags) )
-    {
-        if ( test_bit(EDF_DONEFPUINIT, &current->flags) )
-            restore_fpu(current);
-        else
-            init_fpu();
-    }
+    do_clts();
 
     if ( test_and_clear_bit(EDF_GUEST_STTS, &current->flags) )
     {
===== xen/arch/x86/vmx.c 1.48 vs edited =====
--- 1.48/xen/arch/x86/vmx.c	2005-05-09 07:33:15 -07:00
+++ edited/xen/arch/x86/vmx.c	2005-05-11 11:09:28 -07:00
@@ -154,6 +154,20 @@
     return result;
 }
 
+static void vmx_do_no_device_fault() 
+{
+    unsigned long cr0;
+        
+    do_clts();
+    __vmread(CR0_READ_SHADOW, &cr0);
+    if (!(cr0 & X86_CR0_TS)) {
+        __vmread(GUEST_CR0, &cr0);
+        cr0 &= ~X86_CR0_TS;
+        __vmwrite(GUEST_CR0, cr0);
+    }
+    __vmwrite(EXCEPTION_BITMAP, MONITOR_DEFAULT_EXCEPTION_BITMAP);
+}
+
 static void vmx_do_general_protection_fault(struct cpu_user_regs *regs) 
 {
     unsigned long eip, error_code;
@@ -894,6 +908,8 @@
         mov_from_cr(cr, gp, regs);
         break;
     case TYPE_CLTS:
+        do_clts();
+
         __vmread(GUEST_CR0, &value);
         value &= ~X86_CR0_TS; /* clear TS */
         __vmwrite(GUEST_CR0, value);
@@ -1093,6 +1109,11 @@
             break;
         }
 #endif
+        case TRAP_no_device:
+        {
+            vmx_do_no_device_fault();
+            break;  
+        }
         case TRAP_gp_fault:
         {
             vmx_do_general_protection_fault(&regs);
===== xen/arch/x86/vmx_io.c 1.22 vs edited =====
--- 1.22/xen/arch/x86/vmx_io.c	2005-04-28 07:04:10 -07:00
+++ edited/xen/arch/x86/vmx_io.c	2005-05-11 11:02:52 -07:00
@@ -429,6 +429,7 @@
 
 void vmx_do_resume(struct exec_domain *d) 
 {
+    vmx_stts();
     if ( test_bit(VMX_CPU_STATE_PG_ENABLED, &d->arch.arch_vmx.cpu_state) )
         __vmwrite(GUEST_CR3, pagetable_val(d->arch.shadow_table));
     else
===== xen/arch/x86/vmx_vmcs.c 1.21 vs edited =====
--- 1.21/xen/arch/x86/vmx_vmcs.c	2005-04-28 07:04:10 -07:00
+++ edited/xen/arch/x86/vmx_vmcs.c	2005-05-11 11:05:12 -07:00
@@ -164,6 +164,9 @@
     struct pfn_info *page;
     struct cpu_user_regs *regs = get_cpu_user_regs();
 
+    vmx_stts();
+    set_bit(EDF_GUEST_STTS, &ed->flags);
+
     cpu = smp_processor_id();
 
     page = (struct pfn_info *) alloc_domheap_page(NULL);
===== xen/include/asm-x86/i387.h 1.9 vs edited =====
--- 1.9/xen/include/asm-x86/i387.h	2005-05-08 05:06:08 -07:00
+++ edited/xen/include/asm-x86/i387.h	2005-05-11 11:16:26 -07:00
@@ -28,4 +28,17 @@
     __asm__ __volatile__ ( "ldmxcsr %0" : : "m" (__mxcsr) ); \
 } while ( 0 )
 
+/* Make current domain the FPU owner */
+static inline void do_clts()
+{
+    clts();
+    if ( !test_and_set_bit(EDF_USEDFPU, &current->flags) )
+    {
+        if ( test_bit(EDF_DONEFPUINIT, &current->flags) )
+            restore_fpu(current);
+        else
+            init_fpu();
+    }
+}
+
 #endif /* __ASM_I386_I387_H */
===== xen/include/asm-x86/vmx.h 1.6 vs edited =====
--- 1.6/xen/include/asm-x86/vmx.h	2005-04-28 07:04:11 -07:00
+++ edited/xen/include/asm-x86/vmx.h	2005-05-11 11:13:28 -07:00
@@ -24,6 +24,7 @@
 #include <asm/regs.h>
 #include <asm/processor.h>
 #include <asm/vmx_vmcs.h>
+#include <asm/i387.h>
 
 extern void vmx_asm_vmexit_handler(struct cpu_user_regs);
 extern void vmx_asm_do_resume(void);
@@ -251,4 +252,19 @@
     return 0;
 }
 
+/* Make sure that xen intercepts any FP accesses from current */
+static inline void vmx_stts()
+{
+    unsigned long cr0;
+
+    __vmread(GUEST_CR0, &cr0);
+    if (!(cr0 & X86_CR0_TS))
+        __vmwrite(GUEST_CR0, cr0 | X86_CR0_TS);
+
+    __vmread(CR0_READ_SHADOW, &cr0);
+    if (!(cr0 & X86_CR0_TS))
+       __vmwrite(EXCEPTION_BITMAP, MONITOR_DEFAULT_EXCEPTION_BITMAP | 
+                                   EXCEPTION_BITMAP_NM);
+}
+ 
 #endif /* __ASM_X86_VMX_H__ */

                 reply	other threads:[~2005-05-11 18:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20050511182335.GA29157@intel.com \
    --to=arun.sharma@intel.com \
    --cc=Ian.Pratt@cl.cam.ac.uk \
    --cc=Keir.Fraser@cl.cam.ac.uk \
    --cc=xen-devel@lists.xensource.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.