Module Name: src
Committed By: maxv
Date: Fri Jun 29 19:21:43 UTC 2018
Modified Files:
src/sys/arch/amd64/amd64: locore.S
src/sys/arch/i386/i386: locore.S
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.157 -r1.158 src/sys/arch/i386/i386/locore.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.166 src/sys/arch/amd64/amd64/locore.S:1.167
--- src/sys/arch/amd64/amd64/locore.S:1.166 Thu Jun 14 14:36:46 2018
+++ src/sys/arch/amd64/amd64/locore.S Fri Jun 29 19:21:43 2018
@@ -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 @@ ENTRY(cpu_switchto)
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 @@ ENTRY(cpu_switchto)
#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
Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.157 src/sys/arch/i386/i386/locore.S:1.158
--- src/sys/arch/i386/i386/locore.S:1.157 Thu Jun 14 17:58:22 2018
+++ src/sys/arch/i386/i386/locore.S Fri Jun 29 19:21:43 2018
@@ -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 @@ ENTRY(cpu_switchto)
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 @@ skip_save:
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