Skip to contentSkip to conversation

x86/EFI: Fix FPU state handling around runtime calls

PATCH In review Andrew Cooper 2 participants 3 messages Jun 21, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/EFI: Fix FPU state handling around runtime calls

From: Jan Beulich <[email protected]>

There are two issues. First, the nonlazy xstates were never restored after returning from the runtime call.

Secondly, with the fully_eager_fpu mitigation for XSA-267 / LazyFPU, the unilateral stts() is no longer correct, and hits an assertion later when a lazy state restore tries to occur for a fully eager vcpu.

Fix both of these issues by calling vcpu_restore_fpu_eager(). As EFI runtime services can be used in the idle context, the idle assertion needs to move until after the fully_eager_fpu check.

Introduce a "curr" local variable and replace other uses of "current" at the same time.

---
Only compile tested at this point. Should unblock staging.

---
 xen/arch/x86/i387.c      | 4 ++--
 xen/common/efi/runtime.c | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)
xen/arch/x86/i387.c +2 -2
index dbdf1b4..9c75273 100644
@@ -208,12 +208,12 @@ static inline void fpu_fxsave(struct vcpu *v)
 /* Restore FPU state whenever VCPU is schduled in. */
 void vcpu_restore_fpu_eager(struct vcpu *v)
 {
-    ASSERT(!is_idle_vcpu(v));
-    
     /* Restore nonlazy extended state (i.e. parts not tracked by CR0.TS). */
     if ( !v->arch.fully_eager_fpu && !v->arch.nonlazy_xstate_used )
         return;
 
+    ASSERT(!is_idle_vcpu(v));
+
     /* Avoid recursion */
     clts();
 
xen/common/efi/runtime.c +5 -3
index 070a70d..aad3ab5 100644
@@ -118,14 +118,16 @@ struct efi_rs_state efi_rs_enter(void)
 
 void efi_rs_leave(struct efi_rs_state *state)
 {
+    struct vcpu *curr = current;
+
     if ( !state->cr3 )
         return;
     switch_cr3_cr4(state->cr3, read_cr4());
-    if ( is_pv_vcpu(current) && !is_idle_vcpu(current) )
+    if ( is_pv_vcpu(curr) && !is_idle_vcpu(curr) )
     {
         struct desc_ptr gdt_desc = {
             .limit = LAST_RESERVED_GDT_BYTE,
-            .base  = GDT_VIRT_START(current)
+            .base  = GDT_VIRT_START(curr)
         };
 
         lgdt(&gdt_desc);
@@ -133,7 +135,7 @@ void efi_rs_leave(struct efi_rs_state *state)
     irq_exit();
     efi_rs_on_cpu = NR_CPUS;
     spin_unlock(&efi_rs_lock);
-    stts();
+    vcpu_restore_fpu_eager(curr);
 }
 
 bool efi_rs_using_pgtables(void)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 13 lines · Andrew Cooper

From: Jan Beulich <[email protected]>

There are two issues. First, the nonlazy xstates were never restored after returning from the runtime call.

Secondly, with the fully_eager_fpu mitigation for XSA-267 / LazyFPU, the unilateral stts() is no longer correct, and hits an assertion later when a lazy state restore tries to occur for a fully eager vcpu.

Fix both of these issues by calling vcpu_restore_fpu_eager(). As EFI runtime services can be used in the idle context, the idle assertion needs to move until after the fully_eager_fpu check.

Quoted 6 lines

Introduce a "curr" local variable and replace other uses of "current" at the same time.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Tested-by
#2 lore raw
Quoted 14 lines · Juergen Gross
Quoted 13 lines · Andrew Cooper

From: Jan Beulich <[email protected]>

There are two issues. First, the nonlazy xstates were never restored after returning from the runtime call.

Secondly, with the fully_eager_fpu mitigation for XSA-267 / LazyFPU, the unilateral stts() is no longer correct, and hits an assertion later when a lazy state restore tries to occur for a fully eager vcpu.

Fix both of these issues by calling vcpu_restore_fpu_eager(). As EFI runtime services can be used in the idle context, the idle assertion needs to move until after the fully_eager_fpu check.

Quoted 8 lines
Quoted 6 lines

Introduce a "curr" local variable and replace other uses of "current" at the same time.

I've tested this patch on an EFI machine: without the patch Xen crashed while booting Dom0, with the patch the system came up. So you can add:

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel