]> xenbits.xensource.com Git - xen.git/commitdiff
x86: Support fully eager FPU context switching
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 7 Jun 2018 16:00:37 +0000 (17:00 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 13 Jun 2018 21:01:37 +0000 (22:01 +0100)
This is controlled on a per-vcpu bases for flexibility.

This is part of XSA-267 / CVE-2018-3665

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
(cherry picked from commit 146dfe9277c2b4a8c399b229e00d819065e3167b)

xen/arch/x86/i387.c
xen/include/asm-x86/domain.h

index 55845353d6bd9b06dc3a7a388e67cc0c373471de..f9cf05969d42d2ba14af3e2649923a3eaf9466db 100644 (file)
@@ -215,8 +215,25 @@ void vcpu_restore_fpu_eager(struct vcpu *v)
 {
     ASSERT(!is_idle_vcpu(v));
     
+    if ( v->arch.fully_eager_fpu )
+    {
+        /* Avoid recursion */
+        clts();
+
+        if ( cpu_has_xsave )
+            fpu_xrstor(v, XSTATE_ALL);
+        else
+            fpu_fxrstor(v);
+
+        v->fpu_initialised = 1;
+        v->fpu_dirtied = 1;
+
+        /* Xen doesn't need TS set, but the guest might. */
+        if ( is_pv_vcpu(v) && (v->arch.pv_vcpu.ctrlreg[0] & X86_CR0_TS) )
+            stts();
+    }
     /* save the nonlazy extended state which is not tracked by CR0.TS bit */
-    if ( v->arch.nonlazy_xstate_used )
+    else if ( v->arch.nonlazy_xstate_used )
     {
         /* Avoid recursion */
         clts();        
@@ -238,6 +255,8 @@ void vcpu_restore_fpu_lazy(struct vcpu *v)
     if ( v->fpu_dirtied )
         return;
 
+    ASSERT(!v->arch.fully_eager_fpu);
+
     if ( cpu_has_xsave )
         fpu_xrstor(v, XSTATE_LAZY);
     else
index f917b46d4b145229fc54e08da5071cbe0206f1bb..20715e3207aeacfc2c76a569ab4d7bd03d8124b9 100644 (file)
@@ -574,6 +574,9 @@ struct arch_vcpu
      * and thus should be saved/restored. */
     bool_t nonlazy_xstate_used;
 
+    /* Restore all FPU state (lazy and non-lazy state) on context switch? */
+    bool_t fully_eager_fpu;
+
     /*
      * The SMAP check policy when updating runstate_guest(v) and the
      * secondary system time.