Source-Changes-HG archive

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

[src-draft/trunk]: src/sys/arch/x86/x86 Call clts/stts in fpu_kern_enter/leav...



details:   https://anonhg.NetBSD.org/src-all/rev/5ef7b9960203
branches:  trunk
changeset: 933725:5ef7b9960203
user:      Taylor R Campbell <riastradh%NetBSD.org@localhost>
date:      Fri May 29 14:02:07 2020 +0000

description:
Call clts/stts in fpu_kern_enter/leave so they work.

diffstat:

 sys/arch/x86/x86/fpu.c |  15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diffs (32 lines):

diff -r 9c1370fde50d -r 5ef7b9960203 sys/arch/x86/x86/fpu.c
--- a/sys/arch/x86/x86/fpu.c    Thu May 28 17:07:27 2020 +0000
+++ b/sys/arch/x86/x86/fpu.c    Fri May 29 14:02:07 2020 +0000
@@ -365,6 +365,14 @@
        } else {
                fpu_save_lwp(l);
        }
+
+       /*
+        * Clear CR0_TS, which fpu_save_lwp set if it saved anything --
+        * otherwise the CPU will trap if we try to use the FPU under
+        * the false impression that there has been a task switch since
+        * the last FPU usage requiring that we save the FPU state.
+        */
+       clts();
 }
 
 void
@@ -375,6 +383,13 @@
 
        KASSERT(ci->ci_ilevel == IPL_HIGH);
        KASSERT(ci->ci_kfpu_spl != -1);
+
+       /*
+        * Set CR0_TS again so that the kernel can't accidentally use
+        * the FPU.
+        */
+       stts();
+
        s = ci->ci_kfpu_spl;
        ci->ci_kfpu_spl = -1;
        splx(s);



Home | Main Index | Thread Index | Old Index