Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Call fpu_eagerswitch a little later, after we make ...



details:   https://anonhg.NetBSD.org/src/rev/5efb1ba0ef39
branches:  trunk
changeset: 320268:5efb1ba0ef39
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Jun 29 19:21:43 2018 +0000

description:
Call fpu_eagerswitch a little later, after we make sure newlwp is not
pinned.

Because if it is, the fpu state of the lwp we are context-switching to
is already installed on the current cpu, so no point re-installing it.
Or, it isn't, and in this case we don't want to install it.

This wrong re-installation can occur when we leave a softint.

It may fix bugs in places that call fpusave_lwp with spl != IPL_HIGH,
and that expect the fpu state to stay in memory. As far as I can tell
only cpu_lwp_free meets these conditions, and as far as I can tell
again, there it's harmless.

Should help PR/53399.

diffstat:

 sys/arch/amd64/amd64/locore.S |  26 +++++++++++++-------------
 sys/arch/i386/i386/locore.S   |  30 +++++++++++++++---------------
 2 files changed, 28 insertions(+), 28 deletions(-)

diffs (105 lines):

diff -r 1355602082a7 -r 5efb1ba0ef39 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Fri Jun 29 19:13:19 2018 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Fri Jun 29 19:21:43 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.166 2018/06/14 14:36:46 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.167 2018/06/29 19:21:43 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -1106,18 +1106,6 @@
        pushq   %rdx
        callq   _C_LABEL(speculation_barrier)
        popq    %rdx
-
-       /* RDI/RSI got clobbered. */
-       movq    %r13,%rdi
-       movq    %r12,%rsi
-
-       pushq   %rdx
-       movb    _C_LABEL(x86_fpu_eager),%dl
-       testb   %dl,%dl
-       jz      .Lno_eagerfpu
-       callq   _C_LABEL(fpu_eagerswitch)
-.Lno_eagerfpu:
-       popq    %rdx
 #endif
 
        /* Switch to newlwp's stack. */
@@ -1160,6 +1148,18 @@
 #endif
 .Lring0_switched:
 
+#ifndef XEN
+       pushq   %rdx
+       movb    _C_LABEL(x86_fpu_eager),%dl
+       testb   %dl,%dl
+       jz      .Lno_eagerfpu
+       movq    %r13,%rdi
+       movq    %r12,%rsi
+       callq   _C_LABEL(fpu_eagerswitch)
+.Lno_eagerfpu:
+       popq    %rdx
+#endif
+
        /* Don't bother with the rest if switching to a system process. */
        testl   $LW_SYSTEM,L_FLAG(%r12)
        jnz     .Lswitch_return
diff -r 1355602082a7 -r 5efb1ba0ef39 sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S       Fri Jun 29 19:13:19 2018 +0000
+++ b/sys/arch/i386/i386/locore.S       Fri Jun 29 19:21:43 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.157 2018/06/14 17:58:22 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.158 2018/06/29 19:21:43 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.157 2018/06/14 17:58:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.158 2018/06/29 19:21:43 maxv Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -1089,19 +1089,6 @@
        movl    %ebp,PCB_EBP(%eax)
 skip_save:
 
-#ifndef XEN
-       pushl   %edx
-       movb    _C_LABEL(x86_fpu_eager),%dl
-       testb   %dl,%dl
-       jz      .Lno_eagerfpu
-       pushl   %edi
-       pushl   %esi
-       call    _C_LABEL(fpu_eagerswitch)
-       addl    $8,%esp
-.Lno_eagerfpu:
-       popl    %edx
-#endif
-
        /* Switch to newlwp's stack. */
        movl    L_PCB(%edi),%ebx
        movl    PCB_EBP(%ebx),%ebp
@@ -1129,6 +1116,19 @@
        movl    %eax,TSS_ESP0(%ecx)
 #endif
 
+#ifndef XEN
+       pushl   %edx
+       movb    _C_LABEL(x86_fpu_eager),%dl
+       testb   %dl,%dl
+       jz      .Lno_eagerfpu
+       pushl   %edi
+       pushl   %esi
+       call    _C_LABEL(fpu_eagerswitch)
+       addl    $8,%esp
+.Lno_eagerfpu:
+       popl    %edx
+#endif
+
        /* Don't bother with the rest if switching to a system process. */
        testl   $LW_SYSTEM,L_FLAG(%edi)
        jnz     switch_return



Home | Main Index | Thread Index | Old Index